Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/util/MultiTypeMath.h @ 1319

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

added support for Vector4 to MultiTypeMath and added a new function called 'assimilate' that converts the stored value of a given MultiType to it's own type and assigns it.

File size: 11.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::Vector4&     value) { this->setValue(value); }
66        inline MultiTypeMath(const orxonox::ColourValue& value) { this->setValue(value); }
67        inline MultiTypeMath(const orxonox::Quaternion&  value) { this->setValue(value); }
68        inline MultiTypeMath(const orxonox::Radian&      value) { this->setValue(value); }
69        inline MultiTypeMath(const orxonox::Degree&      value) { this->setValue(value); }
70        inline MultiTypeMath(const MultiTypeMath& mtm)          { this->setValue(mtm);   }
71        virtual inline ~MultiTypeMath() {}
72
73        using MultiTypeString::operator=;
74        inline MultiTypeMath& operator=(const orxonox::Vector2&     value) { this->setValue(value); return *this; }
75        inline MultiTypeMath& operator=(const orxonox::Vector3&     value) { this->setValue(value); return *this; }
76        inline MultiTypeMath& operator=(const orxonox::Vector4&     value) { this->setValue(value); return *this; }
77        inline MultiTypeMath& operator=(const orxonox::ColourValue& value) { this->setValue(value); return *this; }
78        inline MultiTypeMath& operator=(const orxonox::Quaternion&  value) { this->setValue(value); return *this; }
79        inline MultiTypeMath& operator=(const orxonox::Radian&      value) { this->setValue(value); return *this; }
80        inline MultiTypeMath& operator=(const orxonox::Degree&      value) { this->setValue(value); return *this; }
81        inline MultiTypeMath& operator=(const MultiTypeMath& mtm)          { this->setValue(mtm);   return *this; }
82
83        using MultiTypeString::operator==;
84        inline bool operator==(const orxonox::Vector2&     value) const { return (this->vector2_     == value); }
85        inline bool operator==(const orxonox::Vector3&     value) const { return (this->vector3_     == value); }
86        inline bool operator==(const orxonox::Vector4&     value) const { return (this->vector4_     == value); }
87        inline bool operator==(const orxonox::ColourValue& value) const { return (this->colourvalue_ == value); }
88        inline bool operator==(const orxonox::Quaternion&  value) const { return (this->quaternion_  == value); }
89        inline bool operator==(const orxonox::Radian&      value) const { return (this->radian_      == value); }
90        inline bool operator==(const orxonox::Degree&      value) const { return (this->degree_      == value); }
91        bool operator==(const MultiTypeMath& mtm) const;
92
93        using MultiTypeString::operator!=;
94        inline bool operator!=(const orxonox::Vector2&     value) const { return (this->vector2_     != value); }
95        inline bool operator!=(const orxonox::Vector3&     value) const { return (this->vector3_     != value); }
96        inline bool operator!=(const orxonox::Vector4&     value) const { return (this->vector4_     != value); }
97        inline bool operator!=(const orxonox::ColourValue& value) const { return (this->colourvalue_ != value); }
98        inline bool operator!=(const orxonox::Quaternion&  value) const { return (this->quaternion_  != value); }
99        inline bool operator!=(const orxonox::Radian&      value) const { return (this->radian_      != value); }
100        inline bool operator!=(const orxonox::Degree&      value) const { return (this->degree_      != value); }
101        bool operator!=(const MultiTypeMath& mtm) const;
102
103        virtual operator void*()                const;
104        virtual operator int()                  const;
105        virtual operator unsigned int()         const;
106        virtual operator char()                 const;
107        virtual operator unsigned char()        const;
108        virtual operator short()                const;
109        virtual operator unsigned short()       const;
110        virtual operator long()                 const;
111        virtual operator unsigned long()        const;
112        virtual operator float ()               const;
113        virtual operator double ()              const;
114        virtual operator long double()          const;
115        virtual operator bool()                 const;
116        virtual operator std::string()          const;
117        virtual operator const char*()          const;
118        virtual operator orxonox::Vector2()     const;
119        virtual operator orxonox::Vector3()     const;
120        virtual operator orxonox::Vector4()     const;
121        virtual operator orxonox::ColourValue() const;
122        virtual operator orxonox::Quaternion()  const;
123        virtual operator orxonox::Radian()      const;
124        virtual operator orxonox::Degree()      const;
125
126        using MultiTypeString::setValue;
127        inline void setValue(const orxonox::Vector2&     value) { this->type_ = MT_vector2;     this->vector2_     = value; }
128        inline void setValue(const orxonox::Vector3&     value) { this->type_ = MT_vector3;     this->vector3_     = value; }
129        inline void setValue(const orxonox::Vector4&     value) { this->type_ = MT_vector4;     this->vector4_     = value; }
130        inline void setValue(const orxonox::ColourValue& value) { this->type_ = MT_colourvalue; this->colourvalue_ = value; }
131        inline void setValue(const orxonox::Quaternion&  value) { this->type_ = MT_quaternion;  this->quaternion_  = value; }
132        inline void setValue(const orxonox::Radian&      value) { this->type_ = MT_radian;      this->radian_      = value; }
133        inline void setValue(const orxonox::Degree&      value) { this->type_ = MT_degree;      this->degree_      = value; }
134        void setValue(const MultiTypeMath& mtm);
135
136        inline orxonox::Vector2     getVector2()     const { return this->vector2_;     }
137        inline orxonox::Vector3     getVector3()     const { return this->vector3_;     }
138        inline orxonox::Vector4     getVector4()     const { return this->vector4_;     }
139        inline orxonox::ColourValue getColourValue() const { return this->colourvalue_; }
140        inline orxonox::Quaternion  getQuaternion()  const { return this->quaternion_;  }
141        inline orxonox::Radian      getRadian()      const { return this->radian_;      }
142        inline orxonox::Degree      getDegree()      const { return this->degree_;      }
143
144        inline orxonox::Vector2&     getVector2()     { return this->vector2_;     }
145        inline orxonox::Vector3&     getVector3()     { return this->vector3_;     }
146        inline orxonox::Vector4&     getVector4()     { return this->vector4_;     }
147        inline orxonox::ColourValue& getColourValue() { return this->colourvalue_; }
148        inline orxonox::Quaternion&  getQuaternion()  { return this->quaternion_;  }
149        inline orxonox::Radian&      getRadian()      { return this->radian_;      }
150        inline orxonox::Degree&      getDegree()      { return this->degree_;      }
151
152        using MultiTypeString::getValue;
153        inline void getValue(orxonox::Vector2*     variable) const { (*variable) = orxonox::Vector2     (this->vector2_);     }
154        inline void getValue(orxonox::Vector3*     variable) const { (*variable) = orxonox::Vector3     (this->vector3_);     }
155        inline void getValue(orxonox::Vector4*     variable) const { (*variable) = orxonox::Vector4     (this->vector4_);     }
156        inline void getValue(orxonox::ColourValue* variable) const { (*variable) = orxonox::ColourValue (this->colourvalue_); }
157        inline void getValue(orxonox::Quaternion*  variable) const { (*variable) = orxonox::Quaternion  (this->quaternion_);  }
158        inline void getValue(orxonox::Radian*      variable) const { (*variable) = orxonox::Radian      (this->radian_);      }
159        inline void getValue(orxonox::Degree*      variable) const { (*variable) = orxonox::Degree      (this->degree_);      }
160
161        virtual std::string getTypename() const;
162
163        virtual std::string toString() const;
164        virtual bool fromString(const std::string value);
165
166        virtual void assimilate(const MultiTypeMath& mtm);
167
168    protected:
169        orxonox::Vector2      vector2_;
170        orxonox::Vector3      vector3_;
171        orxonox::Vector4      vector4_;
172        orxonox::ColourValue  colourvalue_;
173        orxonox::Quaternion   quaternion_;
174        orxonox::Radian       radian_;
175        orxonox::Degree       degree_;
176};
177
178_UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm);
179
180#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
181#pragma warning(pop)
182#endif
183
184#endif /* _MultiTypeMath_H__ */
Note: See TracBrowser for help on using the repository browser.