Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/util/MultiTypeMath.h @ 1064

Last change on this file since 1064 was 1064, checked in by rgrieder, 16 years ago
  • replaced all String2Number with ConvertValue
  • replaced all tokenize with SubString
  • dealt with warnings under msvc
  • removed some warnings by placing casts
  • bugfix in audio: local variable pushed into member variable std::vector
  • updated StableHeaders.h
File size: 10.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 *   Inspiration: MultiType by Benjamin Grauer
28 */
29
30#ifndef _MultiTypeMath_H__
31#define _MultiTypeMath_H__
32
33#include "UtilPrereqs.h"
34
35#include "MultiTypeString.h"
36#include "Math.h"
37
38// disable annoying warning about multiple assignment operators
39#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
40#pragma warning(push)
41#pragma warning(disable:4522)
42#endif
43
44class _UtilExport MultiTypeMath : public MultiTypeString
45{
46    public:
47        MultiTypeMath(MultiType type = MT_null);
48        inline MultiTypeMath(void*          value) : MultiTypeString(value) {}
49        inline MultiTypeMath(int            value) : MultiTypeString(value) {}
50        inline MultiTypeMath(unsigned int   value) : MultiTypeString(value) {}
51        inline MultiTypeMath(char           value) : MultiTypeString(value) {}
52        inline MultiTypeMath(unsigned char  value) : MultiTypeString(value) {}
53        inline MultiTypeMath(short          value) : MultiTypeString(value) {}
54        inline MultiTypeMath(unsigned short value) : MultiTypeString(value) {}
55        inline MultiTypeMath(long           value) : MultiTypeString(value) {}
56        inline MultiTypeMath(unsigned long  value) : MultiTypeString(value) {}
57        inline MultiTypeMath(float          value) : MultiTypeString(value) {}
58        inline MultiTypeMath(double         value) : MultiTypeString(value) {}
59        inline MultiTypeMath(long double    value) : MultiTypeString(value) {}
60        inline MultiTypeMath(bool           value) : MultiTypeString(value) {}
61        inline MultiTypeMath(const char*             value) : MultiTypeString(value) {}
62        inline MultiTypeMath(const std::string&      value) : MultiTypeString(value) {}
63        inline MultiTypeMath(const orxonox::Vector2&     value) { this->setValue(value); }
64        inline MultiTypeMath(const orxonox::Vector3&     value) { this->setValue(value); }
65        inline MultiTypeMath(const orxonox::ColourValue& value) { this->setValue(value); }
66        inline MultiTypeMath(const orxonox::Quaternion&  value) { this->setValue(value); }
67        inline MultiTypeMath(const orxonox::Radian&      value) { this->setValue(value); }
68        inline MultiTypeMath(const orxonox::Degree&      value) { this->setValue(value); }
69        inline MultiTypeMath(const MultiTypeMath& mtm)          { this->setValue(mtm);   }
70        virtual inline ~MultiTypeMath() {}
71
72        using MultiTypeString::operator=;
73        inline MultiTypeMath& operator=(const orxonox::Vector2&     value) { this->setValue(value); return *this; }
74        inline MultiTypeMath& operator=(const orxonox::Vector3&     value) { this->setValue(value); return *this; }
75        inline MultiTypeMath& operator=(const orxonox::ColourValue& value) { this->setValue(value); return *this; }
76        inline MultiTypeMath& operator=(const orxonox::Quaternion&  value) { this->setValue(value); return *this; }
77        inline MultiTypeMath& operator=(const orxonox::Radian&      value) { this->setValue(value); return *this; }
78        inline MultiTypeMath& operator=(const orxonox::Degree&      value) { this->setValue(value); return *this; }
79        inline MultiTypeMath& operator=(const MultiTypeMath& mtm)          { this->setValue(mtm);   return *this; }
80
81        using MultiTypeString::operator==;
82        inline bool operator==(const orxonox::Vector2&     value) const { return (this->vector2_     == value); }
83        inline bool operator==(const orxonox::Vector3&     value) const { return (this->vector3_     == value); }
84        inline bool operator==(const orxonox::ColourValue& value) const { return (this->colourvalue_ == value); }
85        inline bool operator==(const orxonox::Quaternion&  value) const { return (this->quaternion_  == value); }
86        inline bool operator==(const orxonox::Radian&      value) const { return (this->radian_      == value); }
87        inline bool operator==(const orxonox::Degree&      value) const { return (this->degree_      == value); }
88        bool operator==(const MultiTypeMath& mtm) const;
89
90        using MultiTypeString::operator!=;
91        inline bool operator!=(const orxonox::Vector2&     value) const { return (this->vector2_     != value); }
92        inline bool operator!=(const orxonox::Vector3&     value) const { return (this->vector3_     != value); }
93        inline bool operator!=(const orxonox::ColourValue& value) const { return (this->colourvalue_ != value); }
94        inline bool operator!=(const orxonox::Quaternion&  value) const { return (this->quaternion_  != value); }
95        inline bool operator!=(const orxonox::Radian&      value) const { return (this->radian_      != value); }
96        inline bool operator!=(const orxonox::Degree&      value) const { return (this->degree_      != value); }
97        bool operator!=(const MultiTypeMath& mtm) const;
98
99        virtual operator void*()                const;
100        virtual operator int()                  const;
101        virtual operator unsigned int()         const;
102        virtual operator char()                 const;
103        virtual operator unsigned char()        const;
104        virtual operator short()                const;
105        virtual operator unsigned short()       const;
106        virtual operator long()                 const;
107        virtual operator unsigned long()        const;
108        virtual operator float ()               const;
109        virtual operator double ()              const;
110        virtual operator long double()          const;
111        virtual operator bool()                 const;
112        virtual operator std::string()          const;
113        virtual operator const char*()          const;
114        virtual operator orxonox::Vector2()     const;
115        virtual operator orxonox::Vector3()     const;
116        virtual operator orxonox::ColourValue() const;
117        virtual operator orxonox::Quaternion()  const;
118        virtual operator orxonox::Radian()      const;
119        virtual operator orxonox::Degree()      const;
120
121        using MultiTypeString::setValue;
122        inline void setValue(const orxonox::Vector2&     value) { this->type_ = MT_vector2;     this->vector2_     = value; }
123        inline void setValue(const orxonox::Vector3&     value) { this->type_ = MT_vector3;     this->vector3_     = value; }
124        inline void setValue(const orxonox::ColourValue& value) { this->type_ = MT_colourvalue; this->colourvalue_ = value; }
125        inline void setValue(const orxonox::Quaternion&  value) { this->type_ = MT_quaternion;  this->quaternion_  = value; }
126        inline void setValue(const orxonox::Radian&      value) { this->type_ = MT_radian;      this->radian_      = value; }
127        inline void setValue(const orxonox::Degree&      value) { this->type_ = MT_degree;      this->degree_      = value; }
128        void setValue(const MultiTypeMath& mtm);
129
130        inline orxonox::Vector2     getVector2()     const { return this->vector2_;     }
131        inline orxonox::Vector3     getVector3()     const { return this->vector3_;     }
132        inline orxonox::ColourValue getColourValue() const { return this->colourvalue_; }
133        inline orxonox::Quaternion  getQuaternion()  const { return this->quaternion_;  }
134        inline orxonox::Radian      getRadian()      const { return this->radian_;      }
135        inline orxonox::Degree      getDegree()      const { return this->degree_;      }
136
137        inline orxonox::Vector2&     getVector2()     { return this->vector2_;     }
138        inline orxonox::Vector3&     getVector3()     { return this->vector3_;     }
139        inline orxonox::ColourValue& getColourValue() { return this->colourvalue_; }
140        inline orxonox::Quaternion&  getQuaternion()  { return this->quaternion_;  }
141        inline orxonox::Radian&      getRadian()      { return this->radian_;      }
142        inline orxonox::Degree&      getDegree()      { return this->degree_;      }
143
144        using MultiTypeString::getValue;
145        inline void getValue(orxonox::Vector2*     variable) const { (*variable) = orxonox::Vector2     (this->vector2_);     }
146        inline void getValue(orxonox::Vector3*     variable) const { (*variable) = orxonox::Vector3     (this->vector3_);     }
147        inline void getValue(orxonox::ColourValue* variable) const { (*variable) = orxonox::ColourValue (this->colourvalue_); }
148        inline void getValue(orxonox::Quaternion*  variable) const { (*variable) = orxonox::Quaternion  (this->quaternion_);  }
149        inline void getValue(orxonox::Radian*      variable) const { (*variable) = orxonox::Radian      (this->radian_);      }
150        inline void getValue(orxonox::Degree*      variable) const { (*variable) = orxonox::Degree      (this->degree_);      }
151
152        virtual std::string getTypename() const;
153
154        virtual std::string toString() const;
155        virtual bool fromString(const std::string value);
156
157    protected:
158        orxonox::Vector2      vector2_;
159        orxonox::Vector3      vector3_;
160        orxonox::ColourValue  colourvalue_;
161        orxonox::Quaternion   quaternion_;
162        orxonox::Radian       radian_;
163        orxonox::Degree       degree_;
164};
165
166_UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm);
167
168#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
169#pragma warning(pop)
170#endif
171
172#endif /* _MultiTypeMath_H__ */
Note: See TracBrowser for help on using the repository browser.