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