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 | |
---|
38 | class _UtilExport MultiTypePrimitive |
---|
39 | { |
---|
40 | public: |
---|
41 | MultiTypePrimitive(MultiType type = MT_null); |
---|
42 | inline MultiTypePrimitive(int value) { this->setValue(value); } |
---|
43 | inline MultiTypePrimitive(unsigned int value) { this->setValue(value); } |
---|
44 | inline MultiTypePrimitive(char value) { this->setValue(value); } |
---|
45 | inline MultiTypePrimitive(unsigned char value) { this->setValue(value); } |
---|
46 | inline MultiTypePrimitive(short value) { this->setValue(value); } |
---|
47 | inline MultiTypePrimitive(unsigned short value) { this->setValue(value); } |
---|
48 | inline MultiTypePrimitive(long value) { this->setValue(value); } |
---|
49 | inline MultiTypePrimitive(unsigned long value) { this->setValue(value); } |
---|
50 | inline MultiTypePrimitive(float value) { this->setValue(value); } |
---|
51 | inline MultiTypePrimitive(double value) { this->setValue(value); } |
---|
52 | inline MultiTypePrimitive(long double value) { this->setValue(value); } |
---|
53 | inline MultiTypePrimitive(bool value) { this->setValue(value); } |
---|
54 | inline MultiTypePrimitive(const MultiTypePrimitive& mtp) { this->setValue(mtp); } |
---|
55 | virtual inline ~MultiTypePrimitive() {} |
---|
56 | |
---|
57 | inline MultiTypePrimitive& operator=(MultiType value) { this->type_ = MT_null; return *this; } |
---|
58 | inline MultiTypePrimitive& operator=(int value) { this->setValue(value); return *this; } |
---|
59 | inline MultiTypePrimitive& operator=(unsigned int value) { this->setValue(value); return *this; } |
---|
60 | inline MultiTypePrimitive& operator=(char value) { this->setValue(value); return *this; } |
---|
61 | inline MultiTypePrimitive& operator=(unsigned char value) { this->setValue(value); return *this; } |
---|
62 | inline MultiTypePrimitive& operator=(short value) { this->setValue(value); return *this; } |
---|
63 | inline MultiTypePrimitive& operator=(unsigned short value) { this->setValue(value); return *this; } |
---|
64 | inline MultiTypePrimitive& operator=(long value) { this->setValue(value); return *this; } |
---|
65 | inline MultiTypePrimitive& operator=(unsigned long value) { this->setValue(value); return *this; } |
---|
66 | inline MultiTypePrimitive& operator=(float value) { this->setValue(value); return *this; } |
---|
67 | inline MultiTypePrimitive& operator=(double value) { this->setValue(value); return *this; } |
---|
68 | inline MultiTypePrimitive& operator=(long double value) { this->setValue(value); return *this; } |
---|
69 | inline MultiTypePrimitive& operator=(bool value) { this->setValue(value); return *this; } |
---|
70 | inline MultiTypePrimitive& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; } |
---|
71 | |
---|
72 | inline bool operator==(int value) const { return (this->value_.int_ == value); } |
---|
73 | inline bool operator==(unsigned int value) const { return (this->value_.uint_ == value); } |
---|
74 | inline bool operator==(char value) const { return (this->value_.char_ == value); } |
---|
75 | inline bool operator==(unsigned char value) const { return (this->value_.uchar_ == value); } |
---|
76 | inline bool operator==(short value) const { return (this->value_.short_ == value); } |
---|
77 | inline bool operator==(unsigned short value) const { return (this->value_.ushort_ == value); } |
---|
78 | inline bool operator==(long value) const { return (this->value_.long_ == value); } |
---|
79 | inline bool operator==(unsigned long value) const { return (this->value_.ulong_ == value); } |
---|
80 | inline bool operator==(float value) const { return (this->value_.float_ == value); } |
---|
81 | inline bool operator==(double value) const { return (this->value_.double_ == value); } |
---|
82 | inline bool operator==(long double value) const { return (this->value_.longdouble_ == value); } |
---|
83 | inline bool operator==(bool value) const { return (this->value_.bool_ == value); } |
---|
84 | bool operator==(const MultiTypePrimitive& mtp) const; |
---|
85 | |
---|
86 | inline bool operator!=(int value) const { return (this->value_.int_ != value); } |
---|
87 | inline bool operator!=(unsigned int value) const { return (this->value_.uint_ != value); } |
---|
88 | inline bool operator!=(char value) const { return (this->value_.char_ != value); } |
---|
89 | inline bool operator!=(unsigned char value) const { return (this->value_.uchar_ != value); } |
---|
90 | inline bool operator!=(short value) const { return (this->value_.short_ != value); } |
---|
91 | inline bool operator!=(unsigned short value) const { return (this->value_.ushort_ != value); } |
---|
92 | inline bool operator!=(long value) const { return (this->value_.long_ != value); } |
---|
93 | inline bool operator!=(unsigned long value) const { return (this->value_.ulong_ != value); } |
---|
94 | inline bool operator!=(float value) const { return (this->value_.float_ != value); } |
---|
95 | inline bool operator!=(double value) const { return (this->value_.double_ != value); } |
---|
96 | inline bool operator!=(long double value) const { return (this->value_.longdouble_ != value); } |
---|
97 | inline bool operator!=(bool value) const { return (this->value_.bool_ != value); } |
---|
98 | bool operator!=(const MultiTypePrimitive& mtp) const; |
---|
99 | |
---|
100 | virtual operator int() const; |
---|
101 | virtual operator unsigned int() const; |
---|
102 | virtual operator char() const; |
---|
103 | virtual operator unsigned char() const; |
---|
104 | virtual operator short() const; |
---|
105 | virtual operator unsigned short() const; |
---|
106 | virtual operator long() const; |
---|
107 | virtual operator unsigned long() const; |
---|
108 | virtual operator float () const; |
---|
109 | virtual operator double () const; |
---|
110 | virtual operator long double() const; |
---|
111 | virtual operator bool() const; |
---|
112 | |
---|
113 | inline void setValue(int value) { this->type_ = MT_int; this->value_.int_ = value; } |
---|
114 | inline void setValue(unsigned int value) { this->type_ = MT_uint; this->value_.uint_ = value; } |
---|
115 | inline void setValue(char value) { this->type_ = MT_char; this->value_.char_ = value; } |
---|
116 | inline void setValue(unsigned char value) { this->type_ = MT_uchar; this->value_.uchar_ = value; } |
---|
117 | inline void setValue(short value) { this->type_ = MT_short; this->value_.short_ = value; } |
---|
118 | inline void setValue(unsigned short value) { this->type_ = MT_ushort; this->value_.ushort_ = value; } |
---|
119 | inline void setValue(long value) { this->type_ = MT_long; this->value_.long_ = value; } |
---|
120 | inline void setValue(unsigned long value) { this->type_ = MT_ulong; this->value_.ulong_ = value; } |
---|
121 | inline void setValue(float value) { this->type_ = MT_float; this->value_.float_ = value; } |
---|
122 | inline void setValue(double value) { this->type_ = MT_double; this->value_.double_ = value; } |
---|
123 | inline void setValue(long double value) { this->type_ = MT_longdouble; this->value_.longdouble_ = value; } |
---|
124 | inline void setValue(bool value) { this->type_ = MT_bool; this->value_.bool_ = value; } |
---|
125 | void setValue(const MultiTypePrimitive& mtp); |
---|
126 | |
---|
127 | inline int getInt() const { return this->value_.int_; } |
---|
128 | inline unsigned int getUnsignedInt() const { return this->value_.uint_; } |
---|
129 | inline char getChar() const { return this->value_.char_; } |
---|
130 | inline unsigned char getUnsignedChar() const { return this->value_.uchar_; } |
---|
131 | inline short getShort() const { return this->value_.short_; } |
---|
132 | inline unsigned short getUnsignedShort() const { return this->value_.ushort_; } |
---|
133 | inline long getLong() const { return this->value_.long_; } |
---|
134 | inline unsigned long getUnsignedLong() const { return this->value_.ulong_; } |
---|
135 | inline float getFloat() const { return this->value_.float_; } |
---|
136 | inline double getDouble() const { return this->value_.double_; } |
---|
137 | inline long double getLongDouble() const { return this->value_.longdouble_; } |
---|
138 | inline bool getBool() const { return this->value_.bool_; } |
---|
139 | |
---|
140 | inline int& getInt() { return this->value_.int_; } |
---|
141 | inline unsigned int& getUnsignedInt() { return this->value_.uint_; } |
---|
142 | inline char& getChar() { return this->value_.char_; } |
---|
143 | inline unsigned char& getUnsignedChar() { return this->value_.uchar_; } |
---|
144 | inline short& getShort() { return this->value_.short_; } |
---|
145 | inline unsigned short& getUnsignedShort() { return this->value_.ushort_; } |
---|
146 | inline long& getLong() { return this->value_.long_; } |
---|
147 | inline unsigned long& getUnsignedLong() { return this->value_.ulong_; } |
---|
148 | inline float& getFloat() { return this->value_.float_; } |
---|
149 | inline double& getDouble() { return this->value_.double_; } |
---|
150 | inline long double& getLongDouble() { return this->value_.longdouble_; } |
---|
151 | inline bool& getBool() { return this->value_.bool_; } |
---|
152 | |
---|
153 | inline void getValue(int* variable) const { (*variable) = this->value_.int_; } |
---|
154 | inline void getValue(unsigned int* variable) const { (*variable) = this->value_.uint_; } |
---|
155 | inline void getValue(char* variable) const { (*variable) = this->value_.char_; } |
---|
156 | inline void getValue(unsigned char* variable) const { (*variable) = this->value_.uchar_; } |
---|
157 | inline void getValue(short* variable) const { (*variable) = this->value_.short_; } |
---|
158 | inline void getValue(unsigned short* variable) const { (*variable) = this->value_.ushort_; } |
---|
159 | inline void getValue(long* variable) const { (*variable) = this->value_.long_; } |
---|
160 | inline void getValue(unsigned long* variable) const { (*variable) = this->value_.ulong_; } |
---|
161 | inline void getValue(float* variable) const { (*variable) = this->value_.float_; } |
---|
162 | inline void getValue(double* variable) const { (*variable) = this->value_.double_; } |
---|
163 | inline void getValue(long double* variable) const { (*variable) = this->value_.longdouble_; } |
---|
164 | inline void getValue(bool* variable) const { (*variable) = this->value_.bool_; } |
---|
165 | |
---|
166 | inline MultiType getType() const { return this->type_; } |
---|
167 | inline bool isA(MultiType type) const { return (this->type_ == type); } |
---|
168 | |
---|
169 | virtual std::string toString() const; |
---|
170 | virtual bool fromString(const std::string value); |
---|
171 | |
---|
172 | protected: |
---|
173 | MultiTypeValue value_; |
---|
174 | MultiType type_; |
---|
175 | }; |
---|
176 | |
---|
177 | _UtilExport std::ostream& operator<<(std::ostream& out, const MultiTypePrimitive& mtp); |
---|
178 | |
---|
179 | #endif /* _MultiTypePrimitive_H__ */ |
---|