Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/util/MultiTypePrimitive.h @ 925

Last change on this file since 925 was 925, checked in by landauf, 16 years ago
  • the MultiTypes can now handle pointers and xml-elements
  • added a const keyword in the ticpp.h file (TinyXML++)
File size: 13.1 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        virtual operator orxonox::BaseObject*()    const;
108        virtual operator void*()          const;
109        virtual operator int()            const;
110        virtual operator unsigned int()   const;
111        virtual operator char()           const;
112        virtual operator unsigned char()  const;
113        virtual operator short()          const;
114        virtual operator unsigned short() const;
115        virtual operator long()           const;
116        virtual operator unsigned long()  const;
117        virtual operator float ()         const;
118        virtual operator double ()        const;
119        virtual operator long double()    const;
120        virtual operator bool()           const;
121
122        inline void setValue(void*          value) { this->type_ = MT_void;       this->value_.void_       = value; }
123        inline void setValue(int            value) { this->type_ = MT_int;        this->value_.int_        = value; }
124        inline void setValue(unsigned int   value) { this->type_ = MT_uint;       this->value_.uint_       = value; }
125        inline void setValue(char           value) { this->type_ = MT_char;       this->value_.char_       = value; }
126        inline void setValue(unsigned char  value) { this->type_ = MT_uchar;      this->value_.uchar_      = value; }
127        inline void setValue(short          value) { this->type_ = MT_short;      this->value_.short_      = value; }
128        inline void setValue(unsigned short value) { this->type_ = MT_ushort;     this->value_.ushort_     = value; }
129        inline void setValue(long           value) { this->type_ = MT_long;       this->value_.long_       = value; }
130        inline void setValue(unsigned long  value) { this->type_ = MT_ulong;      this->value_.ulong_      = value; }
131        inline void setValue(float          value) { this->type_ = MT_float;      this->value_.float_      = value; }
132        inline void setValue(double         value) { this->type_ = MT_double;     this->value_.double_     = value; }
133        inline void setValue(long double    value) { this->type_ = MT_longdouble; this->value_.longdouble_ = value; }
134        inline void setValue(bool           value) { this->type_ = MT_bool;       this->value_.bool_       = value; }
135        void setValue(const MultiTypePrimitive& mtp);
136
137        inline void*          getVoid()          const { return this->value_.void_;        }
138        inline int            getInt()           const { return this->value_.int_;        }
139        inline unsigned int   getUnsignedInt()   const { return this->value_.uint_;       }
140        inline char           getChar()          const { return this->value_.char_;       }
141        inline unsigned char  getUnsignedChar()  const { return this->value_.uchar_;      }
142        inline short          getShort()         const { return this->value_.short_;      }
143        inline unsigned short getUnsignedShort() const { return this->value_.ushort_;     }
144        inline long           getLong()          const { return this->value_.long_;       }
145        inline unsigned long  getUnsignedLong()  const { return this->value_.ulong_;      }
146        inline float          getFloat()         const { return this->value_.float_;      }
147        inline double         getDouble()        const { return this->value_.double_;     }
148        inline long double    getLongDouble()    const { return this->value_.longdouble_; }
149        inline bool           getBool()          const { return this->value_.bool_;       }
150
151        inline int&            getInt()           { return this->value_.int_;        }
152        inline unsigned int&   getUnsignedInt()   { return this->value_.uint_;       }
153        inline char&           getChar()          { return this->value_.char_;       }
154        inline unsigned char&  getUnsignedChar()  { return this->value_.uchar_;      }
155        inline short&          getShort()         { return this->value_.short_;      }
156        inline unsigned short& getUnsignedShort() { return this->value_.ushort_;     }
157        inline long&           getLong()          { return this->value_.long_;       }
158        inline unsigned long&  getUnsignedLong()  { return this->value_.ulong_;      }
159        inline float&          getFloat()         { return this->value_.float_;      }
160        inline double&         getDouble()        { return this->value_.double_;     }
161        inline long double&    getLongDouble()    { return this->value_.longdouble_; }
162        inline bool&           getBool()          { return this->value_.bool_;       }
163
164        inline void getValue(void*           variable) const { variable    = this->value_.void_;       }
165        inline void getValue(int*            variable) const { (*variable) = this->value_.int_;        }
166        inline void getValue(unsigned int*   variable) const { (*variable) = this->value_.uint_;       }
167        inline void getValue(char*           variable) const { (*variable) = this->value_.char_;       }
168        inline void getValue(unsigned char*  variable) const { (*variable) = this->value_.uchar_;      }
169        inline void getValue(short*          variable) const { (*variable) = this->value_.short_;      }
170        inline void getValue(unsigned short* variable) const { (*variable) = this->value_.ushort_;     }
171        inline void getValue(long*           variable) const { (*variable) = this->value_.long_;       }
172        inline void getValue(unsigned long*  variable) const { (*variable) = this->value_.ulong_;      }
173        inline void getValue(float*          variable) const { (*variable) = this->value_.float_;      }
174        inline void getValue(double*         variable) const { (*variable) = this->value_.double_;     }
175        inline void getValue(long double*    variable) const { (*variable) = this->value_.longdouble_; }
176        inline void getValue(bool*           variable) const { (*variable) = this->value_.bool_;       }
177
178        inline MultiType getType()           const { return this->type_; }
179        inline bool      isA(MultiType type) const { return (this->type_ == type); }
180
181        virtual std::string toString() const;
182        virtual bool fromString(const std::string value);
183
184    protected:
185        MultiTypeValue  value_;
186        MultiType       type_;
187};
188
189std::ostream& operator<<(std::ostream& out, const MultiTypePrimitive& mtp);
190
191#endif /* _MultiTypePrimitive_H__ */
Note: See TracBrowser for help on using the repository browser.