00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef neo_core_any_h
00022 #define neo_core_any_h
00023
00027 #include "platform.h"
00028 #include "type.h"
00029
00030 namespace neo {
00031 namespace core {
00032
00055 class Any
00056 {
00057 public:
00058
00060 inline Any();
00061
00063
00064 template < typename T > inline Any( const T& data );
00065
00067
00069 inline Any( const Any& any );
00070
00072 inline ~Any();
00073
00075
00078 template < typename T > inline Any& operator = ( const T& rhs );
00079
00081
00084 inline Any& operator = ( const Any& rhs );
00085
00087 inline void clear();
00088
00090
00091 inline bool empty() const;
00092
00094
00097 inline const std::type_info& getType() const;
00098
00100
00103 inline const TypeInfo& getTypeInfo() const;
00104
00106
00111 template < typename T > inline T& get() const;
00112
00114
00117 inline void* getRaw() const;
00118
00120
00121 inline void swap( Any& any );
00122
00123 private:
00124
00125 class StorageBase
00126 {
00127 public:
00128
00129 TypeInfo _type;
00130
00131 inline StorageBase( const TypeInfo& type );
00132 inline virtual ~StorageBase();
00133 virtual const std::type_info& getType() const = 0;
00134 virtual void* getRaw() = 0;
00135 virtual StorageBase* clone() const = 0;
00136 };
00137
00138 template < typename T > class Storage : public StorageBase
00139 {
00140 public:
00141
00142 typedef T* pointer_type;
00143
00144 inline Storage( const T& data );
00145 inline virtual ~Storage();
00146 inline virtual const std::type_info& getType() const;
00147 virtual void* getRaw();
00148 inline virtual StorageBase* clone() const;
00149
00150 T _data;
00151 };
00152
00153 template < typename T > class Storage< T* > : public StorageBase
00154 {
00155 public:
00156
00157 typedef T* pointer_type;
00158
00159 inline Storage( T* const& data );
00160 inline virtual ~Storage();
00161 inline virtual const std::type_info& getType() const;
00162 virtual void* getRaw();
00163 inline virtual StorageBase* clone() const;
00164
00165 T* _data;
00166 };
00167
00169 mutable StorageBase* _p_data;
00170 };
00171
00172 #include "any.inl"
00173
00175
00178 inline void swap( Any& lval, Any& rval ) { lval.swap( rval ); }
00179
00180 }
00181 }
00182
00183 #if !NEO_PYTHON_GENERATOR
00184 namespace std { template <> inline void swap< neo::core::Any >( neo::core::Any& lval, neo::core::Any& rval ) { neo::core::swap( lval, rval ); } }
00185 #endif
00186
00187 #endif