OpenMoHAA 0.82.0
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 {
38private:
39 short3_data_t data;
40
41protected:
42 int get() const { return data.highmid | (data.low << 16); }
43 void set( int value ) { data.highmid = value & 0xFFFF; data.low = value >> 16; }
44
45public :
46 operator int( void ) const { return get(); }
47
48 short3() {}
49 short3( int value ) { set( value ); }
50
51 short3 operator-( void ) const;
52 short3 operator~( void ) const;
53
54 short3 operator+( int b ) const;
55 short3 operator-( int b ) const;
56 short3 operator*( int b ) const;
57 short3 operator/( int b ) const;
58 short3 operator%( int b ) const;
59 short3 operator|( int b ) const;
60 short3 operator&( int b ) const;
61 short3 operator^( int b ) const;
62 short3 operator<<( int b ) const;
63 short3 operator>>( int b ) const;
64
65 short3 operator++( int );
66 short3 operator--( int );
67
68 short3& operator++( );
69 short3& operator--( );
70
71 short3& operator=( int b );
72 short3& operator+=( int b );
73 short3& operator-=( int b );
74 short3& operator*=( int b );
75 short3& operator/=( int b );
76 short3& operator%=( int b );
77
78 short3& operator|=( int b );
79 short3& operator&=( int b );
80 short3& operator^=( int b );
81
82 short3& operator<<=( int b );
83 short3& operator>>=( int b );
84
85 bool operator!( void ) { return !get(); };
86
87 bool operator==( int b ) { return get() == b; };
88 bool operator!=( int b ) { return get() != b; };
89 bool operator<=( int b ) { return get() <= b; };
90 bool operator>=( int b ) { return get() >= b; };
91 bool operator<( int b ) { return get() < b; };
92 bool operator>( int b ) { return get() > b; };
93
94 bool operator==( short3 &b ) { return get() == b.get(); };
95 bool operator!=( short3 &b ) { return get() != b.get(); };
96 bool operator<=( short3 &b ) { return get() <= b.get(); };
97 bool operator>=( short3 &b ) { return get() >= b.get(); };
98 bool operator<( short3 &b ) { return get() < b.get(); };
99 bool operator>( short3 &b ) { return get() > b.get(); };
100};
101
102class unsigned_short3 : public short3 {
103public:
104 operator unsigned int( void ) const { return get(); }
105};
106
107inline short3 short3::operator-( ) const
108{
109 return short3( -get() );
110}
111
112inline short3 short3::operator~( ) const
113{
114 return short3( ~get() );
115}
116
117inline short3 short3::operator+( int b ) const
118{
119 return short3( get() + b );
120}
121
122inline short3 short3::operator-( int b ) const
123{
124 return short3( get() - b );
125}
126
127inline short3 short3::operator*( int b ) const
128{
129 return short3( get() * b );
130}
131
132inline short3 short3::operator/( int b ) const
133{
134 return short3( get() / b );
135}
136
137inline short3 short3::operator%( int b ) const
138{
139 return short3( get() % b );
140}
141
142inline short3 short3::operator|( int b ) const
143{
144 return short3( get() | b );
145}
146
147inline short3 short3::operator&( int b ) const
148{
149 return short3( get() & b );
150}
151
152inline short3 short3::operator^( int b ) const
153{
154 return short3( get() ^ b );
155}
156
157inline short3 short3::operator<<( int b ) const
158{
159 return short3( get() << b );
160}
161
162inline short3 short3::operator>>( int b ) const
163{
164 return short3( get() >> b );
165}
166
167inline short3 short3::operator++( int )
168{
169 short3 result = *this;
170 set( get() + 1 );
171 return result;
172}
173
174inline short3 short3::operator--( int )
175{
176 short3 result = *this;
177 set( get() - 1 );
178 return result;
179}
180
181inline short3& short3::operator++( )
182{
183 set( get() + 1 );
184 return *this;
185}
186
187inline short3& short3::operator--( )
188{
189 set( get() - 1 );
190 return *this;
191}
192
193inline short3& short3::operator=( int b )
194{
195 set( b );
196 return *this;
197}
198
199inline short3& short3::operator+=( int b )
200{
201 set( get() + b );
202 return *this;
203}
204
205inline short3& short3::operator-=( int b )
206{
207 set( get() - b );
208 return *this;
209}
210
211inline short3& short3::operator/=( int b )
212{
213 set( get() / 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
259#endif /* __Q_MATH_H__ */
Definition short3.h:37
Definition short3.h:102
Definition short3.h:30