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