Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core/src/util/MultiTypePrimitive.h @ 834

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

added convert-operators

File size: 11.5 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 *   Inspiration: MultiType by Benjamin Grauer
27 */
28
29#ifndef _MultiTypePrimitive_H__
30#define _MultiTypePrimitive_H__
31
32#include <ostream>
33
34#include "UtilPrereqs.h"
35
36#include "MultiType.h"
37
38class _UtilExport MultiTypePrimitive
39{
40    public:
41        MultiTypePrimitive(MultiType      type = MT_null);
42        inline MultiTypePrimitive(int            value) { this->setValue(value); }
43        inline MultiTypePrimitive(unsigned int   value) { this->setValue(value); }
44        inline MultiTypePrimitive(char           value) { this->setValue(value); }
45        inline MultiTypePrimitive(unsigned char  value) { this->setValue(value); }
46        inline MultiTypePrimitive(short          value) { this->setValue(value); }
47        inline MultiTypePrimitive(unsigned short value) { this->setValue(value); }
48        inline MultiTypePrimitive(long           value) { this->setValue(value); }
49        inline MultiTypePrimitive(unsigned long  value) { this->setValue(value); }
50        inline MultiTypePrimitive(float          value) { this->setValue(value); }
51        inline MultiTypePrimitive(double         value) { this->setValue(value); }
52        inline MultiTypePrimitive(long double    value) { this->setValue(value); }
53        inline MultiTypePrimitive(bool           value) { this->setValue(value); }
54        MultiTypePrimitive(const MultiTypePrimitive& mtp);
55
56        inline MultiTypePrimitive& operator=(MultiType      value) { this->type_ = MT_null; return *this; }
57        inline MultiTypePrimitive& operator=(int            value) { this->setValue(value); return *this; }
58        inline MultiTypePrimitive& operator=(unsigned int   value) { this->setValue(value); return *this; }
59        inline MultiTypePrimitive& operator=(char           value) { this->setValue(value); return *this; }
60        inline MultiTypePrimitive& operator=(unsigned char  value) { this->setValue(value); return *this; }
61        inline MultiTypePrimitive& operator=(short          value) { this->setValue(value); return *this; }
62        inline MultiTypePrimitive& operator=(unsigned short value) { this->setValue(value); return *this; }
63        inline MultiTypePrimitive& operator=(long           value) { this->setValue(value); return *this; }
64        inline MultiTypePrimitive& operator=(unsigned long  value) { this->setValue(value); return *this; }
65        inline MultiTypePrimitive& operator=(float          value) { this->setValue(value); return *this; }
66        inline MultiTypePrimitive& operator=(double         value) { this->setValue(value); return *this; }
67        inline MultiTypePrimitive& operator=(long double    value) { this->setValue(value); return *this; }
68        inline MultiTypePrimitive& operator=(bool           value) { this->setValue(value); return *this; }
69        MultiTypePrimitive& operator=(const MultiTypePrimitive& mtp);
70
71        inline bool operator==(int            value) const { return (this->value_.int_        == value); }
72        inline bool operator==(unsigned int   value) const { return (this->value_.uint_       == value); }
73        inline bool operator==(char           value) const { return (this->value_.char_       == value); }
74        inline bool operator==(unsigned char  value) const { return (this->value_.uchar_      == value); }
75        inline bool operator==(short          value) const { return (this->value_.short_      == value); }
76        inline bool operator==(unsigned short value) const { return (this->value_.ushort_     == value); }
77        inline bool operator==(long           value) const { return (this->value_.long_       == value); }
78        inline bool operator==(unsigned long  value) const { return (this->value_.ulong_      == value); }
79        inline bool operator==(float          value) const { return (this->value_.float_      == value); }
80        inline bool operator==(double         value) const { return (this->value_.double_     == value); }
81        inline bool operator==(long double    value) const { return (this->value_.longdouble_ == value); }
82        inline bool operator==(bool           value) const { return (this->value_.bool_       == value); }
83        bool operator==(const MultiTypePrimitive& mtp) const;
84
85        inline bool operator!=(int            value) const { return (this->value_.int_        != value); }
86        inline bool operator!=(unsigned int   value) const { return (this->value_.uint_       != value); }
87        inline bool operator!=(char           value) const { return (this->value_.char_       != value); }
88        inline bool operator!=(unsigned char  value) const { return (this->value_.uchar_      != value); }
89        inline bool operator!=(short          value) const { return (this->value_.short_      != value); }
90        inline bool operator!=(unsigned short value) const { return (this->value_.ushort_     != value); }
91        inline bool operator!=(long           value) const { return (this->value_.long_       != value); }
92        inline bool operator!=(unsigned long  value) const { return (this->value_.ulong_      != value); }
93        inline bool operator!=(float          value) const { return (this->value_.float_      != value); }
94        inline bool operator!=(double         value) const { return (this->value_.double_     != value); }
95        inline bool operator!=(long double    value) const { return (this->value_.longdouble_ != value); }
96        inline bool operator!=(bool           value) const { return (this->value_.bool_       != value); }
97        bool operator!=(const MultiTypePrimitive& mtp) const;
98
99        inline operator int()            const { return this->value_.int_;        }
100        inline operator unsigned int()   const { return this->value_.uint_;       }
101        inline operator char()           const { return this->value_.char_;       }
102        inline operator unsigned char()  const { return this->value_.uchar_;      }
103        inline operator short()          const { return this->value_.short_;      }
104        inline operator unsigned short() const { return this->value_.ushort_;     }
105        inline operator long()           const { return this->value_.long_;       }
106        inline operator unsigned long()  const { return this->value_.ulong_;      }
107        inline operator float ()         const { return this->value_.float_;      }
108        inline operator double ()        const { return this->value_.double_;     }
109        inline operator long double()    const { return this->value_.longdouble_; }
110        inline operator bool()           const { return this->value_.bool_;       }
111
112        inline void setValue(int            value) { this->type_ = MT_int;        this->value_.int_        = value; }
113        inline void setValue(unsigned int   value) { this->type_ = MT_uint;       this->value_.uint_       = value; }
114        inline void setValue(char           value) { this->type_ = MT_char;       this->value_.char_       = value; }
115        inline void setValue(unsigned char  value) { this->type_ = MT_uchar;      this->value_.uchar_      = value; }
116        inline void setValue(short          value) { this->type_ = MT_short;      this->value_.short_      = value; }
117        inline void setValue(unsigned short value) { this->type_ = MT_ushort;     this->value_.ushort_     = value; }
118        inline void setValue(long           value) { this->type_ = MT_long;       this->value_.long_       = value; }
119        inline void setValue(unsigned long  value) { this->type_ = MT_ulong;      this->value_.ulong_      = value; }
120        inline void setValue(float          value) { this->type_ = MT_float;      this->value_.float_      = value; }
121        inline void setValue(double         value) { this->type_ = MT_double;     this->value_.double_     = value; }
122        inline void setValue(long double    value) { this->type_ = MT_longdouble; this->value_.longdouble_ = value; }
123        inline void setValue(bool           value) { this->type_ = MT_bool;       this->value_.bool_       = value; }
124        void setValue(const MultiTypePrimitive& mtp);
125
126        inline int            getInt()           const { return this->value_.int_;        }
127        inline unsigned int   getUnsignedInt()   const { return this->value_.uint_;       }
128        inline char           getChar()          const { return this->value_.char_;       }
129        inline unsigned char  getUnsignedChar()  const { return this->value_.uchar_;      }
130        inline short          getShort()         const { return this->value_.short_;      }
131        inline unsigned short getUnsignedShort() const { return this->value_.ushort_;     }
132        inline long           getLong()          const { return this->value_.long_;       }
133        inline unsigned long  getUnsignedLong()  const { return this->value_.ulong_;      }
134        inline float          getFloat()         const { return this->value_.float_;      }
135        inline double         getDouble()        const { return this->value_.double_;     }
136        inline long double    getLongDouble()    const { return this->value_.longdouble_; }
137        inline bool           getBool()          const { return this->value_.bool_;       }
138
139        inline void getValue(int*            variable) const { (*variable) = this->value_.int_;        }
140        inline void getValue(unsigned int*   variable) const { (*variable) = this->value_.uint_;       }
141        inline void getValue(char*           variable) const { (*variable) = this->value_.char_;       }
142        inline void getValue(unsigned char*  variable) const { (*variable) = this->value_.uchar_;      }
143        inline void getValue(short*          variable) const { (*variable) = this->value_.short_;      }
144        inline void getValue(unsigned short* variable) const { (*variable) = this->value_.ushort_;     }
145        inline void getValue(long*           variable) const { (*variable) = this->value_.long_;       }
146        inline void getValue(unsigned long*  variable) const { (*variable) = this->value_.ulong_;      }
147        inline void getValue(float*          variable) const { (*variable) = this->value_.float_;      }
148        inline void getValue(double*         variable) const { (*variable) = this->value_.double_;     }
149        inline void getValue(long double*    variable) const { (*variable) = this->value_.longdouble_; }
150        inline void getValue(bool*           variable) const { (*variable) = this->value_.bool_;       }
151
152        inline MultiType getType()           const { return this->type_; }
153        inline bool      isA(MultiType type) const { return (this->type_ == type); }
154
155    protected:
156        MultiTypeValue  value_;
157        MultiType       type_;
158};
159
160std::ostream& operator<<(std::ostream& out, const MultiTypePrimitive& mtp);
161
162#endif /* _MultiTypePrimitive_H__ */
Note: See TracBrowser for help on using the repository browser.