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 MultiTypeValue.h |
---|
31 | @brief Declaration and Implementation of the MT_Value<T> class. |
---|
32 | |
---|
33 | The MT_Value<T> class is used to hold a value of type T within a MultiType. |
---|
34 | */ |
---|
35 | |
---|
36 | #ifndef _MultiTypeValue_H__ |
---|
37 | #define _MultiTypeValue_H__ |
---|
38 | |
---|
39 | #include "UtilPrereqs.h" |
---|
40 | #include "Convert.h" |
---|
41 | #include "MultiType.h" |
---|
42 | |
---|
43 | /** |
---|
44 | @brief The MT_Value<T> class is used to hold a value of type T within a MultiType. |
---|
45 | */ |
---|
46 | template <typename T> |
---|
47 | struct MT_Value : public MultiType::MT_ValueBase |
---|
48 | { |
---|
49 | /** @brief Constructor: Assigns the value and the type identifier. */ |
---|
50 | MT_Value(const T& value, MT_Type type) : MT_ValueBase(type), value_(value) {} |
---|
51 | |
---|
52 | /** @brief Creates a copy of itself. */ |
---|
53 | inline MT_ValueBase* clone() const { return new MT_Value<T>(this->value_, this->type_); } |
---|
54 | |
---|
55 | /** @brief Resets the current value to the default. */ |
---|
56 | inline void reset() { this->value_ = T(); } |
---|
57 | |
---|
58 | /** @brief Assigns the value of the other MultiType, converted to T. @param other The other MultiType */ |
---|
59 | inline void assimilate(const MultiType& other) { if (other.value_) { T temp; other.getValue(&temp); this->value_ = temp; } else { this->value_ = T(); } } |
---|
60 | |
---|
61 | inline void setValue(const char& value) { this->value_ = getConvertedValue<char, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
62 | inline void setValue(const unsigned char& value) { this->value_ = getConvertedValue<unsigned char, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
63 | inline void setValue(const short& value) { this->value_ = getConvertedValue<short, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
64 | inline void setValue(const unsigned short& value) { this->value_ = getConvertedValue<unsigned short, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
65 | inline void setValue(const int& value) { this->value_ = getConvertedValue<int, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
66 | inline void setValue(const unsigned int& value) { this->value_ = getConvertedValue<unsigned int, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
67 | inline void setValue(const long& value) { this->value_ = getConvertedValue<long, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
68 | inline void setValue(const unsigned long& value) { this->value_ = getConvertedValue<unsigned long, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
69 | inline void setValue(const long long& value) { this->value_ = getConvertedValue<long long, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
70 | inline void setValue(const unsigned long long& value) { this->value_ = getConvertedValue<unsigned long long, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
71 | inline void setValue(const float& value) { this->value_ = getConvertedValue<float, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
72 | inline void setValue(const double& value) { this->value_ = getConvertedValue<double, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
73 | inline void setValue(const long double& value) { this->value_ = getConvertedValue<long double, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
74 | inline void setValue(const bool& value) { this->value_ = getConvertedValue<bool, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
75 | inline void setValue( void* const& value) { this->value_ = getConvertedValue<void*, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
76 | inline void setValue(const std::string& value) { this->value_ = getConvertedValue<std::string, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
77 | inline void setValue(const orxonox::Vector2& value) { this->value_ = getConvertedValue<orxonox::Vector2, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
78 | inline void setValue(const orxonox::Vector3& value) { this->value_ = getConvertedValue<orxonox::Vector3, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
79 | inline void setValue(const orxonox::Vector4& value) { this->value_ = getConvertedValue<orxonox::Vector4, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
80 | inline void setValue(const orxonox::ColourValue& value) { this->value_ = getConvertedValue<orxonox::ColourValue, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
81 | inline void setValue(const orxonox::Quaternion& value) { this->value_ = getConvertedValue<orxonox::Quaternion, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
82 | inline void setValue(const orxonox::Radian& value) { this->value_ = getConvertedValue<orxonox::Radian, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
83 | inline void setValue(const orxonox::Degree& value) { this->value_ = getConvertedValue<orxonox::Degree, T>(value); } /** @brief Assigns the value by converting it to T. */ |
---|
84 | |
---|
85 | inline operator char() const { return getConvertedValue<T, char> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
86 | inline operator unsigned char() const { return getConvertedValue<T, unsigned char> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
87 | inline operator short() const { return getConvertedValue<T, short> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
88 | inline operator unsigned short() const { return getConvertedValue<T, unsigned short> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
89 | inline operator int() const { return getConvertedValue<T, int> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
90 | inline operator unsigned int() const { return getConvertedValue<T, unsigned int> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
91 | inline operator long() const { return getConvertedValue<T, long> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
92 | inline operator unsigned long() const { return getConvertedValue<T, unsigned long> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
93 | inline operator long long() const { return getConvertedValue<T, long long> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
94 | inline operator unsigned long long() const { return getConvertedValue<T, unsigned long long> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
95 | inline operator float() const { return getConvertedValue<T, float> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
96 | inline operator double() const { return getConvertedValue<T, double> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
97 | inline operator long double() const { return getConvertedValue<T, long double> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
98 | inline operator bool() const { return getConvertedValue<T, bool> (this->value_, false); } /** @brief Returns the current value, converted to the requested type. */ |
---|
99 | inline operator void*() const { return getConvertedValue<T, void*> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ |
---|
100 | inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_); } /** @brief Returns the current value, converted to the requested type. */ |
---|
101 | inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_); } /** @brief Returns the current value, converted to the requested type. */ |
---|
102 | inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_); } /** @brief Returns the current value, converted to the requested type. */ |
---|
103 | inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_); } /** @brief Returns the current value, converted to the requested type. */ |
---|
104 | inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_); } /** @brief Returns the current value, converted to the requested type. */ |
---|
105 | inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_); } /** @brief Returns the current value, converted to the requested type. */ |
---|
106 | inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_); } /** @brief Returns the current value, converted to the requested type. */ |
---|
107 | inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_); } /** @brief Returns the current value, converted to the requested type. */ |
---|
108 | |
---|
109 | /** @brief Puts the current value on the stream */ |
---|
110 | inline void toString(std::ostream& outstream) const { outstream << this->value_; } |
---|
111 | |
---|
112 | T value_; //! The stored value |
---|
113 | }; |
---|
114 | |
---|
115 | #endif /* _MultiTypeValue_H__ */ |
---|