summaryrefslogtreecommitdiff
path: root/i/marvin/src/utils/any.hh
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/utils/any.hh')
-rw-r--r--i/marvin/src/utils/any.hh46
1 files changed, 27 insertions, 19 deletions
diff --git a/i/marvin/src/utils/any.hh b/i/marvin/src/utils/any.hh
index eabee96..e61f312 100644
--- a/i/marvin/src/utils/any.hh
+++ b/i/marvin/src/utils/any.hh
@@ -1,9 +1,13 @@
#ifndef any_hh
#define any_hh
// any.hh
-// robert - programme du robot 2005. {{{
+// marvin - programme du robot 2006. {{{
//
-// Copyright (C) 2004 Nicolas Schodet
+// Copyright (C) 2003-2006 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2006.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -19,16 +23,15 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
-// Contact :
-// Web: http://perso.efrei.fr/~schodet/
-// Email: <contact@ni.fr.eu.org>
// }}}
#include <typeinfo>
#include <exception>
#include <iostream>
-/// This class can contain a data of any type.
+/// This class can contain a data of almost any type. This very type must be
+/// CopyConstructible and OutputStreamable. The OutputStreamable restriction
+/// could be removed, but it is so convenient to output an any...
class any
{
class AbstractHolder;
@@ -38,7 +41,7 @@ class any
any (void);
/// Constructor.
template<typename T>
- explicit any (const T &value);
+ explicit any (const T &value);
/// Copy constructor.
explicit any (const any &other);
/// Destructor.
@@ -49,14 +52,14 @@ class any
any &operator= (const any &other);
/// Copy another object into this any.
template<typename T>
- any &operator= (const T &value);
+ 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>
- friend T *any_cast (any *rhs);
+ friend T *any_cast (any *rhs);
friend std::ostream &operator<< (std::ostream &os, const any &rhs);
/// Abstract holder class.
class AbstractHolder
@@ -82,16 +85,6 @@ class any
};
};
-/// Object throw if a any_cast returning a reference fail.
-class bad_any_cast : public std::bad_cast
-{
- public:
- virtual const char * what() const throw()
- {
- return "bad_any_cast: illegal conversion";
- }
-};
-
/// Return a pointer to the contained object or 0 on faillure.
template<typename T>
T *
@@ -108,6 +101,21 @@ template<typename T>
const T &
any_cast (const any &rhs);
+/// Object throw if a any_cast returning a reference fail.
+class bad_any_cast : public std::bad_cast
+{
+ std::string what_;
+ public:
+ /// Constructor.
+ bad_any_cast (const std::type_info &from, const std::type_info &to);
+ /// Destructor which should throw nothing.
+ virtual ~bad_any_cast() throw()
+ { }
+ /// Get the error text.
+ virtual const char *what() const throw()
+ { return what_.c_str (); }
+};
+
/// Print the contained object.
std::ostream &
operator<< (std::ostream &os, const any &rhs);