any.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004-2005 by Reality Rift Studios                       *
00003  *   http://www.realityrift.com  -  mattias@realityrift.com                *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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

Generated on Sat Feb 17 20:50:47 2007 for NeoEngine 2 - Evolution by  doxygen 1.5.1