Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/util/MultiTypePrimitive.h @ 1052

Last change on this file since 1052 was 1052, checked in by landauf, 16 years ago

merged core2 back to trunk
there might be some errors, wasn't able to test it yet due to some strange g++ and linker behaviour.

File size: 13.2 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 *   Inspiration: MultiType by Benjamin Grauer
27 */
28
29#ifndef _MultiTypePrimitive_H__
30#define _MultiTypePrimitive_H__
31
32#include <ostream>
33
34#include "UtilPrereqs.h"
35
36#include "MultiType.h"
37
38namespace orxonox
39{
40    class BaseObject;
41}
42class _UtilExport MultiTypePrimitive
43{
44    public:
45        MultiTypePrimitive(MultiType type = MT_null);
46        inline MultiTypePrimitive(void*          value) { this->setValue(value); }
47        inline MultiTypePrimitive(int            value) { this->setValue(value); }
48        inline MultiTypePrimitive(unsigned int   value) { this->setValue(value); }
49        inline MultiTypePrimitive(char           value) { this->setValue(value); }
50        inline MultiTypePrimitive(unsigned char  value) { this->setValue(value); }
51        inline MultiTypePrimitive(short          value) { this->setValue(value); }
52        inline MultiTypePrimitive(unsigned short value) { this->setValue(value); }
53        inline MultiTypePrimitive(long           value) { this->setValue(value); }
54        inline MultiTypePrimitive(unsigned long  value) { this->setValue(value); }
55        inline MultiTypePrimitive(float          value) { this->setValue(value); }
56        inline MultiTypePrimitive(double         value) { this->setValue(value); }
57        inline MultiTypePrimitive(long double    value) { this->setValue(value); }
58        inline MultiTypePrimitive(bool           value) { this->setValue(value); }
59        inline MultiTypePrimitive(const MultiTypePrimitive& mtp) { this->setValue(mtp); }
60        virtual inline ~MultiTypePrimitive() {}
61
62        inline MultiTypePrimitive& operator=(MultiType      value) { this->type_ = MT_null; return *this; }
63        inline MultiTypePrimitive& operator=(void*          value) { this->setValue(value); return *this; }
64        inline MultiTypePrimitive& operator=(int            value) { this->setValue(value); return *this; }
65        inline MultiTypePrimitive& operator=(unsigned int   value) { this->setValue(value); return *this; }
66        inline MultiTypePrimitive& operator=(char           value) { this->setValue(value); return *this; }
67        inline MultiTypePrimitive& operator=(unsigned char  value) { this->setValue(value); return *this; }
68        inline MultiTypePrimitive& operator=(short          value) { this->setValue(value); return *this; }
69        inline MultiTypePrimitive& operator=(unsigned short value) { this->setValue(value); return *this; }
70        inline MultiTypePrimitive& operator=(long           value) { this->setValue(value); return *this; }
71        inline MultiTypePrimitive& operator=(unsigned long  value) { this->setValue(value); return *this; }
72        inline MultiTypePrimitive& operator=(float          value) { this->setValue(value); return *this; }
73        inline MultiTypePrimitive& operator=(double         value) { this->setValue(value); return *this; }
74        inline MultiTypePrimitive& operator=(long double    value) { this->setValue(value); return *this; }
75        inline MultiTypePrimitive& operator=(bool           value) { this->setValue(value); return *this; }
76        inline MultiTypePrimitive& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; }
77
78        inline bool operator==(void*          value) const { return (this->value_.void_       == value); }
79        inline bool operator==(int            value) const { return (this->value_.int_        == value); }
80        inline bool operator==(unsigned int   value) const { return (this->value_.uint_       == value); }
81        inline bool operator==(char           value) const { return (this->value_.char_       == value); }
82        inline bool operator==(unsigned char  value) const { return (this->value_.uchar_      == value); }
83        inline bool operator==(short          value) const { return (this->value_.short_      == value); }
84        inline bool operator==(unsigned short value) const { return (this->value_.ushort_     == value); }
85        inline bool operator==(long           value) const { return (this->value_.long_       == value); }
86        inline bool operator==(unsigned long  value) const { return (this->value_.ulong_      == value); }
87        inline bool operator==(float          value) const { return (this->value_.float_      == value); }
88        inline bool operator==(double         value) const { return (this->value_.double_     == value); }
89        inline bool operator==(long double    value) const { return (this->value_.longdouble_ == value); }
90        inline bool operator==(bool           value) const { return (this->value_.bool_       == value); }
91        bool operator==(const MultiTypePrimitive& mtp) const;
92
93        inline bool operator!=(void*          value) const { return (this->value_.void_       != value); }
94        inline bool operator!=(unsigned int   value) const { return (this->value_.uint_       != value); }
95        inline bool operator!=(char           value) const { return (this->value_.char_       != value); }
96        inline bool operator!=(unsigned char  value) const { return (this->value_.uchar_      != value); }
97        inline bool operator!=(short          value) const { return (this->value_.short_      != value); }
98        inline bool operator!=(unsigned short value) const { return (this->value_.ushort_     != value); }
99        inline bool operator!=(long           value) const { return (this->value_.long_       != value); }
100        inline bool operator!=(unsigned long  value) const { return (this->value_.ulong_      != value); }
101        inline bool operator!=(float          value) const { return (this->value_.float_      != value); }
102        inline bool operator!=(double         value) const { return (this->value_.double_     != value); }
103        inline bool operator!=(long double    value) const { return (this->value_.longdouble_ != value); }
104        inline bool operator!=(bool           value) const { return (this->value_.bool_       != value); }
105        bool operator!=(const MultiTypePrimitive& mtp) const;
106
107        template <class T>
108        operator T*()                     const
109        { return ((T*)this->value_.void_); }
110        virtual operator void*()          const;
111        virtual operator int()            const;
112        virtual operator unsigned int()   const;
113        virtual operator char()           const;
114        virtual operator unsigned char()  const;
115        virtual operator short()          const;
116        virtual operator unsigned short() const;
117        virtual operator long()           const;
118        virtual operator unsigned long()  const;
119        virtual operator float ()         const;
120        virtual operator double ()        const;
121        virtual operator long double()    const;
122        virtual operator bool()           const;
123
124        inline void setValue(void*          value) { this->type_ = MT_void;       this->value_.void_       = value; }
125        inline void setValue(int            value) { this->type_ = MT_int;        this->value_.int_        = value; }
126        inline void setValue(unsigned int   value) { this->type_ = MT_uint;       this->value_.uint_       = value; }
127        inline void setValue(char           value) { this->type_ = MT_char;       this->value_.char_       = value; }
128        inline void setValue(unsigned char  value) { this->type_ = MT_uchar;      this->value_.uchar_      = value; }
129        inline void setValue(short          value) { this->type_ = MT_short;      this->value_.short_      = value; }
130        inline void setValue(unsigned short value) { this->type_ = MT_ushort;     this->value_.ushort_     = value; }
131        inline void setValue(long           value) { this->type_ = MT_long;       this->value_.long_       = value; }
132        inline void setValue(unsigned long  value) { this->type_ = MT_ulong;      this->value_.ulong_      = value; }
133        inline void setValue(float          value) { this->type_ = MT_float;      this->value_.float_      = value; }
134        inline void setValue(double         value) { this->type_ = MT_double;     this->value_.double_     = value; }
135        inline void setValue(long double    value) { this->type_ = MT_longdouble; this->value_.longdouble_ = value; }
136        inline void setValue(bool           value) { this->type_ = MT_bool;       this->value_.bool_       = value; }
137        void setValue(const MultiTypePrimitive& mtp);
138
139        inline void*          getVoid()          const { return this->value_.void_;        }
140        inline int            getInt()           const { return this->value_.int_;        }
141        inline unsigned int   getUnsignedInt()   const { return this->value_.uint_;       }
142        inline char           getChar()          const { return this->value_.char_;       }
143        inline unsigned char  getUnsignedChar()  const { return this->value_.uchar_;      }
144        inline short          getShort()         const { return this->value_.short_;      }
145        inline unsigned short getUnsignedShort() const { return this->value_.ushort_;     }
146        inline long           getLong()          const { return this->value_.long_;       }
147        inline unsigned long  getUnsignedLong()  const { return this->value_.ulong_;      }
148        inline float          getFloat()         const { return this->value_.float_;      }
149        inline double         getDouble()        const { return this->value_.double_;     }
150        inline long double    getLongDouble()    const { return this->value_.longdouble_; }
151        inline bool           getBool()          const { return this->value_.bool_;       }
152
153        inline int&            getInt()           { return this->value_.int_;        }
154        inline unsigned int&   getUnsignedInt()   { return this->value_.uint_;       }
155        inline char&           getChar()          { return this->value_.char_;       }
156        inline unsigned char&  getUnsignedChar()  { return this->value_.uchar_;      }
157        inline short&          getShort()         { return this->value_.short_;      }
158        inline unsigned short& getUnsignedShort() { return this->value_.ushort_;     }
159        inline long&           getLong()          { return this->value_.long_;       }
160        inline unsigned long&  getUnsignedLong()  { return this->value_.ulong_;      }
161        inline float&          getFloat()         { return this->value_.float_;      }
162        inline double&         getDouble()        { return this->value_.double_;     }
163        inline long double&    getLongDouble()    { return this->value_.longdouble_; }
164        inline bool&           getBool()          { return this->value_.bool_;       }
165
166        inline void getValue(void*           variable) const { variable    = this->value_.void_;       }
167        inline void getValue(int*            variable) const { (*variable) = this->value_.int_;        }
168        inline void getValue(unsigned int*   variable) const { (*variable) = this->value_.uint_;       }
169        inline void getValue(char*           variable) const { (*variable) = this->value_.char_;       }
170        inline void getValue(unsigned char*  variable) const { (*variable) = this->value_.uchar_;      }
171        inline void getValue(short*          variable) const { (*variable) = this->value_.short_;      }
172        inline void getValue(unsigned short* variable) const { (*variable) = this->value_.ushort_;     }
173        inline void getValue(long*           variable) const { (*variable) = this->value_.long_;       }
174        inline void getValue(unsigned long*  variable) const { (*variable) = this->value_.ulong_;      }
175        inline void getValue(float*          variable) const { (*variable) = this->value_.float_;      }
176        inline void getValue(double*         variable) const { (*variable) = this->value_.double_;     }
177        inline void getValue(long double*    variable) const { (*variable) = this->value_.longdouble_; }
178        inline void getValue(bool*           variable) const { (*variable) = this->value_.bool_;       }
179
180        inline MultiType getType()           const { return this->type_; }
181        inline bool      isA(MultiType type) const { return (this->type_ == type); }
182
183        virtual std::string getTypename() const;
184
185        virtual std::string toString() const;
186        virtual bool fromString(const std::string value);
187
188    protected:
189        MultiTypeValue  value_;
190        MultiType       type_;
191};
192
193_UtilExport std::ostream& operator<<(std::ostream& out, const MultiTypePrimitive& mtp);
194
195#endif /* _MultiTypePrimitive_H__ */
Note: See TracBrowser for help on using the repository browser.