summaryrefslogtreecommitdiff
path: root/2005/i/robert
diff options
context:
space:
mode:
authorschodet2005-03-13 20:15:19 +0000
committerschodet2005-03-13 20:15:19 +0000
commit681ed261c49d38f35f70e6c49dc19b1c5c1fc48d (patch)
tree2920254843815d7410b9d01c9519a6a72ae3e73a /2005/i/robert
parentd77b1324361f5d598d52baaac09e93236d020198 (diff)
Ajout de commentaires.
changeemnt de any_cast pour retourner un const &.
Diffstat (limited to '2005/i/robert')
-rw-r--r--2005/i/robert/src/utils/any.hh15
-rw-r--r--2005/i/robert/src/utils/any.tcc12
2 files changed, 24 insertions, 3 deletions
diff --git a/2005/i/robert/src/utils/any.hh b/2005/i/robert/src/utils/any.hh
index 1c36875..8a24a06 100644
--- a/2005/i/robert/src/utils/any.hh
+++ b/2005/i/robert/src/utils/any.hh
@@ -28,7 +28,7 @@
#include <exception>
#include <iostream>
-/// Class containing anything.
+/// This class can contain a data of any type.
class any
{
class AbstractHolder;
@@ -43,11 +43,16 @@ class any
any (const any &other);
/// Destructor.
~any (void);
+ /// Swap content between two any objects.
any &swap (any &other);
+ /// Copy another any object.
any &operator= (const any &other);
+ /// Copy another object into this any.
template<typename T>
any &operator= (const T &value);
+ /// Test if the any object is empty.
bool empty (void) const;
+ /// Return the std::type_info of the contained object.
const std::type_info &type (void) const;
private:
template<typename T>
@@ -77,6 +82,7 @@ class any
};
};
+/// Object throw if a any_cast returning a reference fail.
class bad_any_cast : public std::bad_cast
{
public:
@@ -86,18 +92,23 @@ class bad_any_cast : public std::bad_cast
}
};
+/// Return a pointer to the contained object or 0 on faillure.
template<typename T>
T *
any_cast (any *rhs);
+/// Return a const pointer to the contained object or 0 on faillure.
template<typename T>
const T *
any_cast (const any *rhs);
+/// Return a const reference to the contained object or throw a bad_any_cast
+/// on faillure.
template<typename T>
-T
+const T &
any_cast (const any &rhs);
+/// Print the contained object.
std::ostream &
operator<< (std::ostream &os, const any &rhs);
diff --git a/2005/i/robert/src/utils/any.tcc b/2005/i/robert/src/utils/any.tcc
index c7fd4a0..57ee848 100644
--- a/2005/i/robert/src/utils/any.tcc
+++ b/2005/i/robert/src/utils/any.tcc
@@ -52,6 +52,7 @@ any::~any (void)
delete holder_;
}
+/// Swap content between two any objects.
inline
any &
any::swap (any &other)
@@ -60,6 +61,7 @@ any::swap (any &other)
return *this;
}
+/// Copy another any object.
inline
any &
any::operator= (const any &other)
@@ -68,6 +70,7 @@ any::operator= (const any &other)
return *this;
}
+/// Copy another object into this any.
template<typename T>
any &
any::operator= (const T &value)
@@ -76,6 +79,7 @@ any::operator= (const T &value)
return *this;
}
+/// Test if the any object is empty.
inline
bool
any::empty (void) const
@@ -83,6 +87,7 @@ any::empty (void) const
return !holder_;
}
+/// Return the std::type_info of the contained object.
inline
const std::type_info &
any::type (void) const
@@ -123,6 +128,7 @@ any::Holder<T>::print (std::ostream &os) const
return os << value_;
}
+/// Return a pointer to the contained object or 0 on faillure.
template<typename T>
T *
any_cast (any *rhs)
@@ -132,6 +138,7 @@ any_cast (any *rhs)
: 0;
}
+/// Return a const pointer to the contained object or 0 on faillure.
template<typename T>
const T *
any_cast (const any *rhs)
@@ -139,8 +146,10 @@ any_cast (const any *rhs)
return any_cast<T> (const_cast<any *> (rhs));
}
+/// Return a const reference to the contained object or throw a bad_any_cast
+/// on faillure.
template<typename T>
-T
+const T &
any_cast (const any &rhs)
{
const T *value = any_cast<T> (&rhs);
@@ -149,6 +158,7 @@ any_cast (const any &rhs)
return *value;
}
+/// Print the contained object.
inline
std::ostream &
operator<< (std::ostream &os, const any &rhs)