From 681ed261c49d38f35f70e6c49dc19b1c5c1fc48d Mon Sep 17 00:00:00 2001 From: schodet Date: Sun, 13 Mar 2005 20:15:19 +0000 Subject: Ajout de commentaires. changeemnt de any_cast pour retourner un const &. --- 2005/i/robert/src/utils/any.hh | 15 +++++++++++++-- 2005/i/robert/src/utils/any.tcc | 12 +++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to '2005/i/robert/src/utils') 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 #include -/// 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 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 @@ -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 T * any_cast (any *rhs); +/// Return a const pointer to the contained object or 0 on faillure. template const T * any_cast (const any *rhs); +/// Return a const reference to the contained object or throw a bad_any_cast +/// on faillure. template -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 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::print (std::ostream &os) const return os << value_; } +/// Return a pointer to the contained object or 0 on faillure. template 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 const T * any_cast (const any *rhs) @@ -139,8 +146,10 @@ any_cast (const any *rhs) return any_cast (const_cast (rhs)); } +/// Return a const reference to the contained object or throw a bad_any_cast +/// on faillure. template -T +const T & any_cast (const any &rhs) { const T *value = any_cast (&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) -- cgit v1.2.3