Bullet Collision Detection & Physics Library
neon/boolInVec.h
Go to the documentation of this file.
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 
79 // Equal operator
80 //
81 inline const boolInVec operator == (boolInVec vec0, boolInVec vec1);
82 
83 // Not equal operator
84 //
85 inline const boolInVec operator != (boolInVec vec0, boolInVec vec1);
86 
87 // And operator
88 //
89 inline const boolInVec operator & (boolInVec vec0, boolInVec vec1);
90 
91 // Exclusive or operator
92 //
93 inline const boolInVec operator ^ (boolInVec vec0, boolInVec vec1);
94 
95 // Or operator
96 //
97 inline const boolInVec operator | (boolInVec vec0, boolInVec vec1);
98 
99 // Conditionally select between two values
100 //
101 inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1);
102 
103 
104 } // namespace Vectormath
105 
106 
107 //--------------------------------------------------------------------------------------------------
108 // boolInVec implementation
109 //
110 
111 #include "floatInVec.h"
112 
113 namespace Vectormath {
114 
115 inline
117 {
118  *this = (vec != floatInVec(0.0f));
119 }
120 
121 inline
123 {
124  mData = -(int)scalar;
125 }
126 
127 inline
128 bool
130 {
131  return (mData > 0);
132 }
133 
134 #ifndef _VECTORMATH_NO_SCALAR_CAST
135 inline
136 boolInVec::operator bool() const
137 {
138  return getAsBool();
139 }
140 #endif
141 
142 inline
143 const boolInVec
145 {
146  return boolInVec(!mData);
147 }
148 
149 inline
150 boolInVec&
152 {
153  mData = vec.mData;
154  return *this;
155 }
156 
157 inline
158 boolInVec&
160 {
161  *this = *this & vec;
162  return *this;
163 }
164 
165 inline
166 boolInVec&
168 {
169  *this = *this ^ vec;
170  return *this;
171 }
172 
173 inline
174 boolInVec&
176 {
177  *this = *this | vec;
178  return *this;
179 }
180 
181 inline
182 const boolInVec
184 {
185  return boolInVec(vec0.getAsBool() == vec1.getAsBool());
186 }
187 
188 inline
189 const boolInVec
191 {
192  return !(vec0 == vec1);
193 }
194 
195 inline
196 const boolInVec
198 {
199  return boolInVec(vec0.getAsBool() & vec1.getAsBool());
200 }
201 
202 inline
203 const boolInVec
205 {
206  return boolInVec(vec0.getAsBool() | vec1.getAsBool());
207 }
208 
209 inline
210 const boolInVec
212 {
213  return boolInVec(vec0.getAsBool() ^ vec1.getAsBool());
214 }
215 
216 inline
217 const boolInVec
218 select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1)
219 {
220  return (select_vec1.getAsBool() == 0) ? vec0 : vec1;
221 }
222 
223 } // namespace Vectormath
224 
225 #endif // boolInVec_h
226 
const boolInVec operator!=(boolInVec vec0, boolInVec vec1)
boolInVec & operator&=(boolInVec vec)
boolInVec & operator=(boolInVec vec)
boolInVec & operator^=(boolInVec vec)
const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1)
const boolInVec operator|(boolInVec vec0, boolInVec vec1)
const boolInVec operator&(boolInVec vec0, boolInVec vec1)
boolInVec & operator|=(boolInVec vec)
const boolInVec operator==(boolInVec vec0, boolInVec vec1)
bool getAsBool() const
const boolInVec operator!() const
const boolInVec operator^(boolInVec vec0, boolInVec vec1)