Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/util/MultiType.cc @ 1720

Last change on this file since 1720 was 1720, checked in by landauf, 16 years ago

bugfix + cleanup

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