OpenMoHAA 0.82.1
Loading...
Searching...
No Matches
short3.h
1/*
2===========================================================================
3Copyright (C) 2015 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// short3.h : 3-byte sized integer
24
25#ifndef __Q_MATH_H__
26#define __Q_MATH_H__
27
28#pragma pack(1)
29
30typedef struct short3_data {
31 unsigned short highmid;
32 unsigned char low;
33} short3_data_t;
34
35#pragma pack()
36
37class short3
38{
39private:
40 short3_data_t data;
41
42protected:
43 int get() const { return data.highmid | (data.low << 16); }
44
45 void set(int value)
46 {
47 data.highmid = value & 0xFFFF;
48 data.low = value >> 16;
49 }
50
51public:
52 operator int(void) const { return get(); }
53
54 short3() {}
55
56 short3(int value) { set(value); }
57
58 short3 operator-(void) const;
59 short3 operator~(void) const;
60
61 short3 operator+(int b) const;
62 short3 operator-(int b) const;
63 short3 operator*(int b) const;
64 short3 operator/(int b) const;
65 short3 operator%(int b) const;
66 short3 operator|(int b) const;
67 short3 operator&(int b) const;
68 short3 operator^(int b) const;
69 short3 operator<<(int b) const;
70 short3 operator>>(int b) const;
71
72 short3 operator++(int);
73 short3 operator--(int);
74
75 short3& operator++();
76 short3& operator--();
77
78 short3& operator=(int b);
79 short3& operator+=(int b);
80 short3& operator-=(int b);
81 short3& operator*=(int b);
82 short3& operator/=(int b);
83 short3& operator%=(int b);
84
85 short3& operator|=(int b);
86 short3& operator&=(int b);
87 short3& operator^=(int b);
88
89 short3& operator<<=(int b);
90 short3& operator>>=(int b);
91
92 bool operator!(void) { return !get(); };
93
94 bool operator==(int b) { return get() == b; };
95
96 bool operator!=(int b) { return get() != b; };
97
98 bool operator<=(int b) { return get() <= b; };
99
100 bool operator>=(int b) { return get() >= b; };
101
102 bool operator<(int b) { return get() < b; };
103
104 bool operator>(int b) { return get() > b; };
105
106 bool operator==(short3& b) { return get() == b.get(); };
107
108 bool operator!=(short3& b) { return get() != b.get(); };
109
110 bool operator<=(short3& b) { return get() <= b.get(); };
111
112 bool operator>=(short3& b) { return get() >= b.get(); };
113
114 bool operator<(short3& b) { return get() < b.get(); };
115
116 bool operator>(short3& b) { return get() > b.get(); };
117};
118
119class unsigned_short3 : public short3
120{
121public:
122 operator unsigned int(void) const { return get(); }
123};
124
125inline short3 short3::operator-() const
126{
127 return short3(-get());
128}
129
130inline short3 short3::operator~() const
131{
132 return short3(~get());
133}
134
135inline short3 short3::operator+(int b) const
136{
137 return short3(get() + b);
138}
139
140inline short3 short3::operator-(int b) const
141{
142 return short3(get() - b);
143}
144
145inline short3 short3::operator*(int b) const
146{
147 return short3(get() * b);
148}
149
150inline short3 short3::operator/(int b) const
151{
152 return short3(get() / b);
153}
154
155inline short3 short3::operator%(int b) const
156{
157 return short3(get() % b);
158}
159
160inline short3 short3::operator|(int b) const
161{
162 return short3(get() | b);
163}
164
165inline short3 short3::operator&(int b) const
166{
167 return short3(get() & b);
168}
169
170inline short3 short3::operator^(int b) const
171{
172 return short3(get() ^ b);
173}
174
175inline short3 short3::operator<<(int b) const
176{
177 return short3(get() << b);
178}
179
180inline short3 short3::operator>>(int b) const
181{
182 return short3(get() >> b);
183}
184
185inline short3 short3::operator++(int)
186{
187 short3 result = *this;
188 set(get() + 1);
189 return result;
190}
191
192inline short3 short3::operator--(int)
193{
194 short3 result = *this;
195 set(get() - 1);
196 return result;
197}
198
199inline short3& short3::operator++()
200{
201 set(get() + 1);
202 return *this;
203}
204
205inline short3& short3::operator--()
206{
207 set(get() - 1);
208 return *this;
209}
210
211inline short3& short3::operator=(int b)
212{
213 set(b);
214 return *this;
215}
216
217inline short3& short3::operator+=(int b)
218{
219 set(get() + b);
220 return *this;
221}
222
223inline short3& short3::operator-=(int b)
224{
225 set(get() - b);
226 return *this;
227}
228
229inline short3& short3::operator/=(int b)
230{
231 set(get() / b);
232 return *this;
233}
234
235inline short3& short3::operator*=(int b)
236{
237 set(get() * b);
238 return *this;
239}
240
241inline short3& short3::operator%=(int b)
242{
243 set(get() % b);
244 return *this;
245}
246
247inline short3& short3::operator|=(int b)
248{
249 set(get() | b);
250 return *this;
251}
252
253inline short3& short3::operator&=(int b)
254{
255 set(get() % b);
256 return *this;
257}
258
259inline short3& short3::operator^=(int b)
260{
261 set(get() ^ b);
262 return *this;
263}
264
265inline short3& short3::operator<<=(int b)
266{
267 set(get() << b);
268 return *this;
269}
270
271inline short3& short3::operator>>=(int b)
272{
273 set(get() >> b);
274 return *this;
275}
276
277#endif /* __Q_MATH_H__ */
Definition short3.h:38
Definition short3.h:120
Definition short3.h:30