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 | #include "MultiTypePrimitive.h" |
---|
30 | |
---|
31 | MultiTypePrimitive::MultiTypePrimitive(MultiType type) |
---|
32 | { |
---|
33 | this->type_ = type; |
---|
34 | |
---|
35 | if (type == MT_int) |
---|
36 | this->value_.int_ = 0; |
---|
37 | else if (type == MT_uint) |
---|
38 | this->value_.uint_ = 0; |
---|
39 | else if (type == MT_char) |
---|
40 | this->value_.char_ = 0; |
---|
41 | else if (type == MT_uchar) |
---|
42 | this->value_.uchar_ = 0; |
---|
43 | else if (type == MT_short) |
---|
44 | this->value_.short_ = 0; |
---|
45 | else if (type == MT_ushort) |
---|
46 | this->value_.ushort_ = 0; |
---|
47 | else if (type == MT_long) |
---|
48 | this->value_.long_ = 0; |
---|
49 | else if (type == MT_ulong) |
---|
50 | this->value_.ulong_ = 0; |
---|
51 | else if (type == MT_float) |
---|
52 | this->value_.float_ = 0.0; |
---|
53 | else if (type == MT_double) |
---|
54 | this->value_.double_ = 0.0; |
---|
55 | else if (type == MT_longdouble) |
---|
56 | this->value_.longdouble_ = 0.0; |
---|
57 | else if (type == MT_bool) |
---|
58 | this->value_.bool_ = false; |
---|
59 | else |
---|
60 | this->value_.int_ = 0; |
---|
61 | } |
---|
62 | |
---|
63 | MultiTypePrimitive::MultiTypePrimitive(const MultiTypePrimitive& mtp) |
---|
64 | { |
---|
65 | this->type_ = mtp.type_; |
---|
66 | this->value_ = mtp.value_; |
---|
67 | } |
---|
68 | |
---|
69 | MultiTypePrimitive& MultiTypePrimitive::operator=(const MultiTypePrimitive& mtp) |
---|
70 | { |
---|
71 | this->type_ = mtp.type_; |
---|
72 | this->value_ = mtp.value_; |
---|
73 | return *this; |
---|
74 | } |
---|
75 | |
---|
76 | bool MultiTypePrimitive::operator==(const MultiTypePrimitive& mtp) const |
---|
77 | { |
---|
78 | if (this->type_ == mtp.type_) |
---|
79 | { |
---|
80 | if (this->type_ == MT_int) |
---|
81 | return (this->value_.int_ == mtp.value_.int_); |
---|
82 | else if (this->type_ == MT_uint) |
---|
83 | return (this->value_.uint_ == mtp.value_.uint_); |
---|
84 | else if (this->type_ == MT_char) |
---|
85 | return (this->value_.char_ == mtp.value_.char_); |
---|
86 | else if (this->type_ == MT_uchar) |
---|
87 | return (this->value_.uchar_ == mtp.value_.uchar_); |
---|
88 | else if (this->type_ == MT_short) |
---|
89 | return (this->value_.short_ == mtp.value_.short_); |
---|
90 | else if (this->type_ == MT_ushort) |
---|
91 | return (this->value_.ushort_ == mtp.value_.ushort_); |
---|
92 | else if (this->type_ == MT_long) |
---|
93 | return (this->value_.long_ == mtp.value_.long_); |
---|
94 | else if (this->type_ == MT_ulong) |
---|
95 | return (this->value_.ulong_ == mtp.value_.ulong_); |
---|
96 | else if (this->type_ == MT_float) |
---|
97 | return (this->value_.float_ == mtp.value_.float_); |
---|
98 | else if (this->type_ == MT_double) |
---|
99 | return (this->value_.double_ == mtp.value_.double_); |
---|
100 | else if (this->type_ == MT_longdouble) |
---|
101 | return (this->value_.longdouble_ == mtp.value_.longdouble_); |
---|
102 | else if (this->type_ == MT_bool) |
---|
103 | return (this->value_.bool_ == mtp.value_.bool_); |
---|
104 | } |
---|
105 | |
---|
106 | return false; |
---|
107 | } |
---|
108 | |
---|
109 | bool MultiTypePrimitive::operator!=(const MultiTypePrimitive& mtp) const |
---|
110 | { |
---|
111 | if (this->type_ == mtp.type_) |
---|
112 | { |
---|
113 | if (this->type_ == MT_int) |
---|
114 | return (this->value_.int_ != mtp.value_.int_); |
---|
115 | else if (this->type_ == MT_uint) |
---|
116 | return (this->value_.uint_ != mtp.value_.uint_); |
---|
117 | else if (this->type_ == MT_char) |
---|
118 | return (this->value_.char_ != mtp.value_.char_); |
---|
119 | else if (this->type_ == MT_uchar) |
---|
120 | return (this->value_.uchar_ != mtp.value_.uchar_); |
---|
121 | else if (this->type_ == MT_short) |
---|
122 | return (this->value_.short_ != mtp.value_.short_); |
---|
123 | else if (this->type_ == MT_ushort) |
---|
124 | return (this->value_.ushort_ != mtp.value_.ushort_); |
---|
125 | else if (this->type_ == MT_long) |
---|
126 | return (this->value_.long_ != mtp.value_.long_); |
---|
127 | else if (this->type_ == MT_ulong) |
---|
128 | return (this->value_.ulong_ != mtp.value_.ulong_); |
---|
129 | else if (this->type_ == MT_float) |
---|
130 | return (this->value_.float_ != mtp.value_.float_); |
---|
131 | else if (this->type_ == MT_double) |
---|
132 | return (this->value_.double_ != mtp.value_.double_); |
---|
133 | else if (this->type_ == MT_longdouble) |
---|
134 | return (this->value_.longdouble_ != mtp.value_.longdouble_); |
---|
135 | else if (this->type_ == MT_bool) |
---|
136 | return (this->value_.bool_ != mtp.value_.bool_); |
---|
137 | } |
---|
138 | |
---|
139 | return true; |
---|
140 | } |
---|
141 | |
---|
142 | void MultiTypePrimitive::setValue(const MultiTypePrimitive& mtp) |
---|
143 | { |
---|
144 | this->type_ = mtp.type_; |
---|
145 | this->value_ = mtp.value_; |
---|
146 | } |
---|