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 | */ |
---|
28 | |
---|
29 | #include "MultiType.h" |
---|
30 | #include "MultiTypeValue.h" |
---|
31 | |
---|
32 | void MultiType::convert(MT_Type type) |
---|
33 | { |
---|
34 | switch (type) |
---|
35 | { |
---|
36 | case MT_char: |
---|
37 | this->convert<char>(); break; |
---|
38 | case MT_uchar: |
---|
39 | this->convert<unsigned char>(); break; |
---|
40 | case MT_short: |
---|
41 | this->convert<short>(); break; |
---|
42 | case MT_ushort: |
---|
43 | this->convert<unsigned short>(); break; |
---|
44 | case MT_int: |
---|
45 | this->convert<int>(); break; |
---|
46 | case MT_uint: |
---|
47 | this->convert<unsigned int>(); break; |
---|
48 | case MT_long: |
---|
49 | this->convert<long>(); break; |
---|
50 | case MT_ulong: |
---|
51 | this->convert<unsigned long>(); break; |
---|
52 | case MT_longlong: |
---|
53 | this->convert<long long>(); break; |
---|
54 | case MT_ulonglong: |
---|
55 | this->convert<unsigned long long>(); break; |
---|
56 | case MT_float: |
---|
57 | this->convert<float>(); break; |
---|
58 | case MT_double: |
---|
59 | this->convert<double>(); break; |
---|
60 | case MT_longdouble: |
---|
61 | this->convert<long double>(); break; |
---|
62 | case MT_bool: |
---|
63 | this->convert<bool>(); break; |
---|
64 | case MT_void: |
---|
65 | this->convert<void*>(); break; |
---|
66 | case MT_string: |
---|
67 | this->convert<std::string>(); break; |
---|
68 | case MT_vector2: |
---|
69 | this->convert<orxonox::Vector2>(); break; |
---|
70 | case MT_vector3: |
---|
71 | this->convert<orxonox::Vector3>(); break; |
---|
72 | case MT_vector4: |
---|
73 | this->convert<orxonox::Vector4>(); break; |
---|
74 | case MT_colourvalue: |
---|
75 | this->convert<orxonox::ColourValue>(); break; |
---|
76 | case MT_quaternion: |
---|
77 | this->convert<orxonox::Quaternion>(); break; |
---|
78 | case MT_radian: |
---|
79 | this->convert<orxonox::Radian>(); break; |
---|
80 | case MT_degree: |
---|
81 | this->convert<orxonox::Degree>(); break; |
---|
82 | default: |
---|
83 | this->reset(); break; |
---|
84 | }; |
---|
85 | } |
---|
86 | |
---|
87 | std::string MultiType::getTypename() const |
---|
88 | { |
---|
89 | MT_Type type = (this->value_) ? this->value_->type_ : MT_null; |
---|
90 | |
---|
91 | switch (type) |
---|
92 | { |
---|
93 | case MT_char: |
---|
94 | return "char"; break; |
---|
95 | case MT_uchar: |
---|
96 | return "unsigned char"; break; |
---|
97 | case MT_short: |
---|
98 | return "short"; break; |
---|
99 | case MT_ushort: |
---|
100 | return "unsigned short"; break; |
---|
101 | case MT_int: |
---|
102 | return "int"; break; |
---|
103 | case MT_uint: |
---|
104 | return "unsigned int"; break; |
---|
105 | case MT_long: |
---|
106 | return "long"; break; |
---|
107 | case MT_ulong: |
---|
108 | return "unsigned long"; break; |
---|
109 | case MT_longlong: |
---|
110 | return "long long"; break; |
---|
111 | case MT_ulonglong: |
---|
112 | return "unsigned long long"; break; |
---|
113 | case MT_float: |
---|
114 | return "float"; break; |
---|
115 | case MT_double: |
---|
116 | return "double"; break; |
---|
117 | case MT_longdouble: |
---|
118 | return "long double"; break; |
---|
119 | case MT_bool: |
---|
120 | return "bool"; break; |
---|
121 | case MT_void: |
---|
122 | return "void*"; break; |
---|
123 | case MT_string: |
---|
124 | return "std::string"; break; |
---|
125 | case MT_vector2: |
---|
126 | return "orxonox::Vector2"; break; |
---|
127 | case MT_vector3: |
---|
128 | return "orxonox::Vector3"; break; |
---|
129 | case MT_vector4: |
---|
130 | return "orxonox::Vector4"; break; |
---|
131 | case MT_colourvalue: |
---|
132 | return "orxonox::ColourValue"; break; |
---|
133 | case MT_quaternion: |
---|
134 | return "orxonox::Quaternion"; break; |
---|
135 | case MT_radian: |
---|
136 | return "orxonox::Radian"; break; |
---|
137 | case MT_degree: |
---|
138 | return "orxonox::Degree"; break; |
---|
139 | default: |
---|
140 | return "unknown"; break; |
---|
141 | }; |
---|
142 | } |
---|
143 | |
---|
144 | MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_char ) ? ((MT_Value<char> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
145 | MultiType::operator unsigned char() const { return (this->value_) ? ((this->value_->type_ == MT_uchar ) ? ((MT_Value<unsigned char> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
146 | MultiType::operator short() const { return (this->value_) ? ((this->value_->type_ == MT_short ) ? ((MT_Value<short> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
147 | MultiType::operator unsigned short() const { return (this->value_) ? ((this->value_->type_ == MT_ushort ) ? ((MT_Value<unsigned short> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
148 | MultiType::operator int() const { return (this->value_) ? ((this->value_->type_ == MT_int ) ? ((MT_Value<int> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
149 | MultiType::operator unsigned int() const { return (this->value_) ? ((this->value_->type_ == MT_uint ) ? ((MT_Value<unsigned int> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
150 | MultiType::operator long() const { return (this->value_) ? ((this->value_->type_ == MT_long ) ? ((MT_Value<long> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
151 | MultiType::operator unsigned long() const { return (this->value_) ? ((this->value_->type_ == MT_ulong ) ? ((MT_Value<unsigned long> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
152 | MultiType::operator long long() const { return (this->value_) ? ((this->value_->type_ == MT_longlong ) ? ((MT_Value<long long> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
153 | MultiType::operator unsigned long long() const { return (this->value_) ? ((this->value_->type_ == MT_ulonglong ) ? ((MT_Value<unsigned long long> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
154 | MultiType::operator float() const { return (this->value_) ? ((this->value_->type_ == MT_float ) ? ((MT_Value<float> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
155 | MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_double ) ? ((MT_Value<double> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
156 | MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_longdouble ) ? ((MT_Value<long double> *)this->value_)->value_ : (*this->value_)) : 0; } |
---|
157 | MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_bool ) ? ((MT_Value<bool> *)this->value_)->value_ : (*this->value_)) : false; } |
---|
158 | MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_void ) ? ((MT_Value<void*> *)this->value_)->value_ : (*this->value_)) : (void*)0; } |
---|
159 | MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_string ) ? ((MT_Value<std::string> *)this->value_)->value_ : (*this->value_)) : std::string(); } |
---|
160 | MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_vector2 ) ? ((MT_Value<orxonox::Vector2> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector2(); } |
---|
161 | MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_vector3 ) ? ((MT_Value<orxonox::Vector3> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector3(); } |
---|
162 | MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_vector4 ) ? ((MT_Value<orxonox::Vector4> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector4(); } |
---|
163 | MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_colourvalue) ? ((MT_Value<orxonox::ColourValue>*)this->value_)->value_ : (*this->value_)) : orxonox::ColourValue(); } |
---|
164 | MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_quaternion ) ? ((MT_Value<orxonox::Quaternion> *)this->value_)->value_ : (*this->value_)) : orxonox::Quaternion(); } |
---|
165 | MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_radian ) ? ((MT_Value<orxonox::Radian> *)this->value_)->value_ : (*this->value_)) : orxonox::Radian(); } |
---|
166 | MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_degree ) ? ((MT_Value<orxonox::Degree> *)this->value_)->value_ : (*this->value_)) : orxonox::Degree(); } |
---|
167 | |
---|
168 | template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_char ); } |
---|
169 | template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value, MT_uchar ); } |
---|
170 | template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value, MT_short ); } |
---|
171 | template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value, MT_ushort ); } |
---|
172 | template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value, MT_int ); } |
---|
173 | template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value, MT_uint ); } |
---|
174 | template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value, MT_long ); } |
---|
175 | template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value, MT_ulong ); } |
---|
176 | template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value, MT_longlong ); } |
---|
177 | template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value, MT_ulonglong ); } |
---|
178 | template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value, MT_float ); } |
---|
179 | template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value, MT_double ); } |
---|
180 | template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value, MT_longdouble ); } |
---|
181 | template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value, MT_bool ); } |
---|
182 | template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value, MT_void ); } |
---|
183 | template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value, MT_string ); } |
---|
184 | template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value, MT_vector2 ); } |
---|
185 | template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value, MT_vector3 ); } |
---|
186 | template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value, MT_vector4 ); } |
---|
187 | template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, MT_colourvalue); } |
---|
188 | template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value, MT_quaternion ); } |
---|
189 | template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value, MT_radian ); } |
---|
190 | template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value, MT_degree ); } |
---|