GpCoreTools/Variant.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of GpCoreTools.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created: 2009-12-02
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef VARIANT_H
00028 #define VARIANT_H
00029 
00030 #include <string>
00031 
00032 #include "GpCoreToolsDLLExport.h"
00033 
00034 namespace GpCoreTools {
00035 
00036 class GPCORETOOLS_EXPORT Variant
00037 {
00038 public:
00039   inline Variant();
00040   inline Variant(std::string& s);
00041   inline Variant(const char * s);
00042   inline Variant(int v);
00043   inline Variant(long v);
00044   inline Variant(const void * p);
00045   inline Variant(double v);
00046   Variant(const Variant& o);
00047   ~Variant();
00048 
00049   void operator=(const Variant& o);
00050   bool isValid() const {return _data;}
00051   std::string toString() const;
00052 private:
00053   inline void assignInternal(const Variant& o);
00054   inline void clearInternal();
00055 
00056   enum Type {Unknown, String, Int, Long, Double};
00057 
00058   void * _data;
00059   Type _type;
00060 };
00061 
00062 inline Variant::Variant()
00063 {
00064   _type=Unknown;
00065   _data=0;
00066 }
00067 
00068 inline Variant::Variant(std::string& s)
00069 {
00070   _type=String;
00071   _data=new std::string(s);
00072 }
00073 
00074 inline Variant::Variant(const char * s)
00075 {
00076   _type=String;
00077   _data=new std::string(s);
00078 }
00079 
00080 inline Variant::Variant(int v)
00081 {
00082   _type=Int;
00083   _data=new int(v);
00084 }
00085 
00086 inline Variant::Variant(long v)
00087 {
00088   _type=Long;
00089   _data=new long(v);
00090 }
00091 
00092 inline Variant::Variant(const void * p)
00093 {
00094   _type=Long;
00095   _data=new long((long)p);
00096 }
00097 
00098 inline Variant::Variant(double v)
00099 {
00100   _type=Double;
00101   _data=new double(v);
00102 }
00103 
00104 } // namespace GpCoreTools
00105 
00106 #endif // VARIANT_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines