Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/util/MultiTypeValue.h @ 1722

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

moved type_ from MultiType into MT_Value to avoid a possible desynchronization

  • Property svn:eol-style set to native
File size: 7.1 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#ifndef _MultiTypeValue_H__
30#define _MultiTypeValue_H__
31
32#include "UtilPrereqs.h"
33#include "Convert.h"
34#include "MultiType.h"
35
36template <typename T>
37struct MT_Value : public MultiType::MT_ValueBase
38{
39    MT_Value(const T& value, MT_Type type) : MT_ValueBase(type), value_(value) {}
40
41    inline MT_ValueBase* clone() const { return new MT_Value<T>(this->value_, this->type_); }
42
43    inline void setValue(const char& value)                 { this->value_ = getConvertedValue<char,                 T>(value); }
44    inline void setValue(const unsigned char& value)        { this->value_ = getConvertedValue<unsigned char,        T>(value); }
45    inline void setValue(const short& value)                { this->value_ = getConvertedValue<short,                T>(value); }
46    inline void setValue(const unsigned short& value)       { this->value_ = getConvertedValue<unsigned short,       T>(value); }
47    inline void setValue(const int& value)                  { this->value_ = getConvertedValue<int,                  T>(value); }
48    inline void setValue(const unsigned int& value)         { this->value_ = getConvertedValue<unsigned int,         T>(value); }
49    inline void setValue(const long& value)                 { this->value_ = getConvertedValue<long,                 T>(value); }
50    inline void setValue(const unsigned long& value)        { this->value_ = getConvertedValue<unsigned long,        T>(value); }
51    inline void setValue(const long long& value)            { this->value_ = getConvertedValue<long long,            T>(value); }
52    inline void setValue(const unsigned long long& value)   { this->value_ = getConvertedValue<unsigned long long,   T>(value); }
53    inline void setValue(const float& value)                { this->value_ = getConvertedValue<float,                T>(value); }
54    inline void setValue(const double& value)               { this->value_ = getConvertedValue<double,               T>(value); }
55    inline void setValue(const long double& value)          { this->value_ = getConvertedValue<long double,          T>(value); }
56    inline void setValue(const bool& value)                 { this->value_ = getConvertedValue<bool,                 T>(value); }
57    inline void setValue(      void* const& value)          { this->value_ = getConvertedValue<void*,                T>(value); }
58    inline void setValue(const std::string& value)          { this->value_ = getConvertedValue<std::string,          T>(value); }
59    inline void setValue(const orxonox::Vector2& value)     { this->value_ = getConvertedValue<orxonox::Vector2,     T>(value); }
60    inline void setValue(const orxonox::Vector3& value)     { this->value_ = getConvertedValue<orxonox::Vector3,     T>(value); }
61    inline void setValue(const orxonox::Vector4& value)     { this->value_ = getConvertedValue<orxonox::Vector4,     T>(value); }
62    inline void setValue(const orxonox::ColourValue& value) { this->value_ = getConvertedValue<orxonox::ColourValue, T>(value); }
63    inline void setValue(const orxonox::Quaternion& value)  { this->value_ = getConvertedValue<orxonox::Quaternion,  T>(value); }
64    inline void setValue(const orxonox::Radian& value)      { this->value_ = getConvertedValue<orxonox::Radian,      T>(value); }
65    inline void setValue(const orxonox::Degree& value)      { this->value_ = getConvertedValue<orxonox::Degree,      T>(value); }
66
67    inline operator char()                 const { return getConvertedValue<T, char>                (this->value_, 0); }
68    inline operator unsigned char()        const { return getConvertedValue<T, unsigned char>       (this->value_, 0); }
69    inline operator short()                const { return getConvertedValue<T, short>               (this->value_, 0); }
70    inline operator unsigned short()       const { return getConvertedValue<T, unsigned short>      (this->value_, 0); }
71    inline operator int()                  const { return getConvertedValue<T, int>                 (this->value_, 0); }
72    inline operator unsigned int()         const { return getConvertedValue<T, unsigned int>        (this->value_, 0); }
73    inline operator long()                 const { return getConvertedValue<T, long>                (this->value_, 0); }
74    inline operator unsigned long()        const { return getConvertedValue<T, unsigned long>       (this->value_, 0); }
75    inline operator long long()            const { return getConvertedValue<T, long long>           (this->value_, 0); }
76    inline operator unsigned long long()   const { return getConvertedValue<T, unsigned long long>  (this->value_, 0); }
77    inline operator float()                const { return getConvertedValue<T, float>               (this->value_, 0); }
78    inline operator double()               const { return getConvertedValue<T, double>              (this->value_, 0); }
79    inline operator long double()          const { return getConvertedValue<T, long double>         (this->value_, 0); }
80    inline operator bool()                 const { return getConvertedValue<T, bool>                (this->value_, false); }
81    inline operator void*()                const { return getConvertedValue<T, void*>               (this->value_, 0); }
82    inline operator std::string()          const { return getConvertedValue<T, std::string>         (this->value_); }
83    inline operator orxonox::Vector2()     const { return getConvertedValue<T, orxonox::Vector2>    (this->value_); }
84    inline operator orxonox::Vector3()     const { return getConvertedValue<T, orxonox::Vector3>    (this->value_); }
85    inline operator orxonox::Vector4()     const { return getConvertedValue<T, orxonox::Vector4>    (this->value_); }
86    inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_); }
87    inline operator orxonox::Quaternion()  const { return getConvertedValue<T, orxonox::Quaternion> (this->value_); }
88    inline operator orxonox::Radian()      const { return getConvertedValue<T, orxonox::Radian>     (this->value_); }
89    inline operator orxonox::Degree()      const { return getConvertedValue<T, orxonox::Degree>     (this->value_); }
90
91    inline void toString(std::ostream& outstream) const { outstream << this->value_; }
92
93    T value_;
94};
95
96#endif /* _MultiTypeValue_H__ */
Note: See TracBrowser for help on using the repository browser.