Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1505 was 1505, checked in by rgrieder, 16 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

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