Debian Codegraph @

test/Bullet2/vectormath/neon/boolInVec.h

raw symbols SCIP
1 /*
2 Copyright (C) 2009 Sony Computer Entertainment Inc.
3 All rights reserved.
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14
15 */
16
17 #ifndef _BOOLINVEC_H
18 #define _BOOLINVEC_H
19
20 #include <math.h>
21 namespace Vectormath
22 {
23 class floatInVec;
24
25 //--------------------------------------------------------------------------------------------------
26 // boolInVec class
27 //
28
29 class boolInVec
30 {
31 private:
32 unsigned int mData;
33
34 public:
35 // Default constructor; does no initialization
36 //
37 inline boolInVec(){};
38
39 // Construct from a value converted from float
40 //
41 inline boolInVec(floatInVec vec);
42
43 // Explicit cast from bool
44 //
45 explicit inline boolInVec(bool scalar);
46
47 // Explicit cast to bool
48 //
49 inline bool getAsBool() const;
50
51 #ifndef _VECTORMATH_NO_SCALAR_CAST
52 // Implicit cast to bool
53 //
54 inline operator bool() const;
55 #endif
56
57 // Boolean negation operator
58 //
59 inline const boolInVec operator!() const;
60
61 // Assignment operator
62 //
63 inline boolInVec& operator=(boolInVec vec);
64
65 // Boolean and assignment operator
66 //
67 inline boolInVec& operator&=(boolInVec vec);
68
69 // Boolean exclusive or assignment operator
70 //
71 inline boolInVec& operator^=(boolInVec vec);
72
73 // Boolean or assignment operator
74 //
75 inline boolInVec& operator|=(boolInVec vec);
76 };
77
78 // Equal operator
79 //
80 inline const boolInVec operator==(boolInVec vec0, boolInVec vec1);
81
82 // Not equal operator
83 //
84 inline const boolInVec operator!=(boolInVec vec0, boolInVec vec1);
85
86 // And operator
87 //
88 inline const boolInVec operator&(boolInVec vec0, boolInVec vec1);
89
90 // Exclusive or operator
91 //
92 inline const boolInVec operator^(boolInVec vec0, boolInVec vec1);
93
94 // Or operator
95 //
96 inline const boolInVec operator|(boolInVec vec0, boolInVec vec1);
97
98 // Conditionally select between two values
99 //
100 inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1);
101
102 } // namespace Vectormath
103
104 //--------------------------------------------------------------------------------------------------
105 // boolInVec implementation
106 //
107
108 #include "floatInVec.h"
109
110 namespace Vectormath
111 {
112 inline boolInVec::boolInVec(floatInVec vec)
113 {
114 *this = (vec != floatInVec(0.0f));
115 }
116
117 inline boolInVec::boolInVec(bool scalar)
118 {
119 mData = -(int)scalar;
120 }
121
122 inline bool
123 boolInVec::getAsBool() const
124 {
125 return (mData > 0);
126 }
127
128 #ifndef _VECTORMATH_NO_SCALAR_CAST
129 inline boolInVec::operator bool() const
130 {
131 return getAsBool();
132 }
133 #endif
134
135 inline const boolInVec
136 boolInVec::operator!() const
137 {
138 return boolInVec(!mData);
139 }
140
141 inline boolInVec&
142 boolInVec::operator=(boolInVec vec)
143 {
144 mData = vec.mData;
145 return *this;
146 }
147
148 inline boolInVec&
149 boolInVec::operator&=(boolInVec vec)
150 {
151 *this = *this & vec;
152 return *this;
153 }
154
155 inline boolInVec&
156 boolInVec::operator^=(boolInVec vec)
157 {
158 *this = *this ^ vec;
159 return *this;
160 }
161
162 inline boolInVec&
163 boolInVec::operator|=(boolInVec vec)
164 {
165 *this = *this | vec;
166 return *this;
167 }
168
169 inline const boolInVec
170 operator==(boolInVec vec0, boolInVec vec1)
171 {
172 return boolInVec(vec0.getAsBool() == vec1.getAsBool());
173 }
174
175 inline const boolInVec
176 operator!=(boolInVec vec0, boolInVec vec1)
177 {
178 return !(vec0 == vec1);
179 }
180
181 inline const boolInVec
182 operator&(boolInVec vec0, boolInVec vec1)
183 {
184 return boolInVec(vec0.getAsBool() & vec1.getAsBool());
185 }
186
187 inline const boolInVec
188 operator|(boolInVec vec0, boolInVec vec1)
189 {
190 return boolInVec(vec0.getAsBool() | vec1.getAsBool());
191 }
192
193 inline const boolInVec
194 operator^(boolInVec vec0, boolInVec vec1)
195 {
196 return boolInVec(vec0.getAsBool() ^ vec1.getAsBool());
197 }
198
199 inline const boolInVec
200 select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1)
201 {
202 return (select_vec1.getAsBool() == 0) ? vec0 : vec1;
203 }
204
205 } // namespace Vectormath
206
207 #endif // boolInVec_h