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 | #ifndef _MultiTypeValue_H__ |
---|
30 | #define _MultiTypeValue_H__ |
---|
31 | |
---|
32 | #include "UtilPrereqs.h" |
---|
33 | #include "Convert.h" |
---|
34 | |
---|
35 | template <typename T> |
---|
36 | struct MT_Value : public MultiType::MT_ValueBase |
---|
37 | { |
---|
38 | /* |
---|
39 | template <class A, class B, class Btest = B> |
---|
40 | class StaticConversion |
---|
41 | { |
---|
42 | private: |
---|
43 | template <class V, bool convertable> struct Convert |
---|
44 | { static inline A convert(const V& value) { return A(); } }; |
---|
45 | template <class V> struct Convert<V, true> |
---|
46 | { static inline A convert(const V& value) { return ((A)value); } }; |
---|
47 | |
---|
48 | template <typename V, bool convertable> struct Compare |
---|
49 | { |
---|
50 | static inline bool compare_equal (const A& value, const V& other) { return false; } |
---|
51 | static inline bool compare_notequal (const A& value, const V& other) { return true; } |
---|
52 | static inline bool compare_smaller (const A& value, const V& other) { return false; } |
---|
53 | static inline bool compare_smallerequal(const A& value, const V& other) { return false; } |
---|
54 | static inline bool compare_greater (const A& value, const V& other) { return false; } |
---|
55 | static inline bool compare_greaterequal(const A& value, const V& other) { return false; } |
---|
56 | }; |
---|
57 | template <typename V> struct Compare<V, true> |
---|
58 | { |
---|
59 | static inline bool compare_equal (const A& value, const V& other) { return (value == other); } |
---|
60 | static inline bool compare_notequal (const A& value, const V& other) { return (value != other); } |
---|
61 | static inline bool compare_smaller (const A& value, const V& other) { return (value < other); } |
---|
62 | static inline bool compare_smallerequal(const A& value, const V& other) { return (value <= other); } |
---|
63 | static inline bool compare_greater (const A& value, const V& other) { return (value > other); } |
---|
64 | static inline bool compare_greaterequal(const A& value, const V& other) { return (value >= other); } |
---|
65 | }; |
---|
66 | |
---|
67 | class Small { char dummy[1]; }; |
---|
68 | class Big { char dummy[1024]; }; |
---|
69 | static Small Test(A); |
---|
70 | static Big Test(...); |
---|
71 | static Btest MakeB(); |
---|
72 | enum { exists = sizeof(Test(MakeB())) == sizeof(Small) }; |
---|
73 | |
---|
74 | public: |
---|
75 | static inline A convert(const B& value) { return Convert<B, exists>::convert(value); } |
---|
76 | static inline bool compare_equal (const B& value, const A& other) { return Compare<B, exists>::compare_equal (value, other); } |
---|
77 | static inline bool compare_notequal (const B& value, const A& other) { return Compare<B, exists>::compare_notequal (value, other); } |
---|
78 | static inline bool compare_smaller (const B& value, const A& other) { return Compare<B, exists>::compare_smaller (value, other); } |
---|
79 | static inline bool compare_smallerequal(const B& value, const A& other) { return Compare<B, exists>::compare_smallerequal(value, other); } |
---|
80 | static inline bool compare_greater (const B& value, const A& other) { return Compare<B, exists>::compare_greater (value, other); } |
---|
81 | static inline bool compare_greaterequal(const B& value, const A& other) { return Compare<B, exists>::compare_greaterequal(value, other); } |
---|
82 | }; |
---|
83 | */ |
---|
84 | MT_Value() {} |
---|
85 | MT_Value(const T& value) : value_(value) {} |
---|
86 | |
---|
87 | inline MT_ValueBase* clone() const { return new MT_Value<T>(this->value_); } |
---|
88 | /* |
---|
89 | inline void setValue(const char& value) { this->value_ = StaticConversion<T, char>::convert(value); } |
---|
90 | inline void setValue(const unsigned char& value) { this->value_ = StaticConversion<T, unsigned char>::convert(value); } |
---|
91 | inline void setValue(const short& value) { this->value_ = StaticConversion<T, short>::convert(value); } |
---|
92 | inline void setValue(const unsigned short& value) { this->value_ = StaticConversion<T, unsigned short>::convert(value); } |
---|
93 | inline void setValue(const int& value) { this->value_ = StaticConversion<T, int>::convert(value); } |
---|
94 | inline void setValue(const unsigned int& value) { this->value_ = StaticConversion<T, unsigned int>::convert(value); } |
---|
95 | inline void setValue(const long& value) { this->value_ = StaticConversion<T, long>::convert(value); } |
---|
96 | inline void setValue(const unsigned long& value) { this->value_ = StaticConversion<T, unsigned long>::convert(value); } |
---|
97 | inline void setValue(const long long& value) { this->value_ = StaticConversion<T, long long>::convert(value); } |
---|
98 | inline void setValue(const unsigned long long& value) { this->value_ = StaticConversion<T, unsigned long long>::convert(value); } |
---|
99 | inline void setValue(const float& value) { this->value_ = StaticConversion<T, float, int>::convert(value); } |
---|
100 | inline void setValue(const double& value) { this->value_ = StaticConversion<T, double, int>::convert(value); } |
---|
101 | inline void setValue(const long double& value) { this->value_ = StaticConversion<T, long double, int>::convert(value); } |
---|
102 | inline void setValue(const bool& value) { this->value_ = StaticConversion<T, bool>::convert(value); } |
---|
103 | inline void setValue( void* const& value) { this->value_ = StaticConversion<T, void*>::convert(value); } |
---|
104 | inline void setValue(const std::string& value) { this->value_ = StaticConversion<T, std::string>::convert(value); } |
---|
105 | inline void setValue(const orxonox::Vector2& value) { this->value_ = StaticConversion<T, orxonox::Vector2>::convert(value); } |
---|
106 | inline void setValue(const orxonox::Vector3& value) { this->value_ = StaticConversion<T, orxonox::Vector3>::convert(value); } |
---|
107 | inline void setValue(const orxonox::Vector4& value) { this->value_ = StaticConversion<T, orxonox::Vector4>::convert(value); } |
---|
108 | inline void setValue(const orxonox::ColourValue& value) { this->value_ = StaticConversion<T, orxonox::ColourValue>::convert(value); } |
---|
109 | inline void setValue(const orxonox::Quaternion& value) { this->value_ = StaticConversion<T, orxonox::Quaternion>::convert(value); } |
---|
110 | inline void setValue(const orxonox::Radian& value) { this->value_ = StaticConversion<T, orxonox::Radian>::convert(value); } |
---|
111 | inline void setValue(const orxonox::Degree& value) { this->value_ = StaticConversion<T, orxonox::Degree>::convert(value); } |
---|
112 | */ |
---|
113 | inline void setValue(const char& value) { this->value_ = getConvertedValue<char, T>(value); } |
---|
114 | inline void setValue(const unsigned char& value) { this->value_ = getConvertedValue<unsigned char, T>(value); } |
---|
115 | inline void setValue(const short& value) { this->value_ = getConvertedValue<short, T>(value); } |
---|
116 | inline void setValue(const unsigned short& value) { this->value_ = getConvertedValue<unsigned short, T>(value); } |
---|
117 | inline void setValue(const int& value) { this->value_ = getConvertedValue<int, T>(value); } |
---|
118 | inline void setValue(const unsigned int& value) { this->value_ = getConvertedValue<unsigned int, T>(value); } |
---|
119 | inline void setValue(const long& value) { this->value_ = getConvertedValue<long, T>(value); } |
---|
120 | inline void setValue(const unsigned long& value) { this->value_ = getConvertedValue<unsigned long, T>(value); } |
---|
121 | inline void setValue(const long long& value) { this->value_ = getConvertedValue<long long, T>(value); } |
---|
122 | inline void setValue(const unsigned long long& value) { this->value_ = getConvertedValue<unsigned long long, T>(value); } |
---|
123 | inline void setValue(const float& value) { this->value_ = getConvertedValue<float, T>(value); } |
---|
124 | inline void setValue(const double& value) { this->value_ = getConvertedValue<double, T>(value); } |
---|
125 | inline void setValue(const long double& value) { this->value_ = getConvertedValue<long double, T>(value); } |
---|
126 | inline void setValue(const bool& value) { this->value_ = getConvertedValue<bool, T>(value); } |
---|
127 | inline void setValue( void* const& value) { this->value_ = getConvertedValue<void*, T>(value); } |
---|
128 | inline void setValue(const std::string& value) { this->value_ = getConvertedValue<std::string, T>(value); } |
---|
129 | inline void setValue(const orxonox::Vector2& value) { this->value_ = getConvertedValue<orxonox::Vector2, T>(value); } |
---|
130 | inline void setValue(const orxonox::Vector3& value) { this->value_ = getConvertedValue<orxonox::Vector3, T>(value); } |
---|
131 | inline void setValue(const orxonox::Vector4& value) { this->value_ = getConvertedValue<orxonox::Vector4, T>(value); } |
---|
132 | inline void setValue(const orxonox::ColourValue& value) { this->value_ = getConvertedValue<orxonox::ColourValue, T>(value); } |
---|
133 | inline void setValue(const orxonox::Quaternion& value) { this->value_ = getConvertedValue<orxonox::Quaternion, T>(value); } |
---|
134 | inline void setValue(const orxonox::Radian& value) { this->value_ = getConvertedValue<orxonox::Radian, T>(value); } |
---|
135 | inline void setValue(const orxonox::Degree& value) { this->value_ = getConvertedValue<orxonox::Degree, T>(value); } |
---|
136 | |
---|
137 | inline operator char() const { return getConvertedValue<T, char> (this->value_, 0); } |
---|
138 | inline operator unsigned char() const { return getConvertedValue<T, unsigned char> (this->value_, 0); } |
---|
139 | inline operator short() const { return getConvertedValue<T, short> (this->value_, 0); } |
---|
140 | inline operator unsigned short() const { return getConvertedValue<T, unsigned short> (this->value_, 0); } |
---|
141 | inline operator int() const { return getConvertedValue<T, int> (this->value_, 0); } |
---|
142 | inline operator unsigned int() const { return getConvertedValue<T, unsigned int> (this->value_, 0); } |
---|
143 | inline operator long() const { return getConvertedValue<T, long> (this->value_, 0); } |
---|
144 | inline operator unsigned long() const { return getConvertedValue<T, unsigned long> (this->value_, 0); } |
---|
145 | inline operator long long() const { return getConvertedValue<T, long long> (this->value_, 0); } |
---|
146 | inline operator unsigned long long() const { return getConvertedValue<T, unsigned long long> (this->value_, 0); } |
---|
147 | inline operator float() const { return getConvertedValue<T, float> (this->value_, 0); } |
---|
148 | inline operator double() const { return getConvertedValue<T, double> (this->value_, 0); } |
---|
149 | inline operator long double() const { return getConvertedValue<T, long double> (this->value_, 0); } |
---|
150 | inline operator bool() const { return getConvertedValue<T, bool> (this->value_, false); } |
---|
151 | inline operator void*() const { return getConvertedValue<T, void*> (this->value_, 0); } |
---|
152 | inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_); } |
---|
153 | inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_); } |
---|
154 | inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_); } |
---|
155 | inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_); } |
---|
156 | inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_); } |
---|
157 | inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_); } |
---|
158 | inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_); } |
---|
159 | inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_); } |
---|
160 | |
---|
161 | inline void toString(std::ostream& outstream) const { outstream << this->value_; } |
---|
162 | |
---|
163 | T value_; |
---|
164 | }; |
---|
165 | |
---|
166 | #endif /* _MultiTypeValue_H__ */ |
---|