PxFlags.h
Go to the documentation of this file.
1 //
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions
4 // are met:
5 // * Redistributions of source code must retain the above copyright
6 // notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright
8 // notice, this list of conditions and the following disclaimer in the
9 // documentation and/or other materials provided with the distribution.
10 // * Neither the name of NVIDIA CORPORATION nor the names of its
11 // contributors may be used to endorse or promote products derived
12 // from this software without specific prior written permission.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
27 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29 
30 #ifndef PXFOUNDATION_PXFLAGS_H
31 #define PXFOUNDATION_PXFLAGS_H
32 
37 #include "foundation/Px.h"
38 
39 #if !PX_DOXYGEN
40 namespace physx
41 {
42 #endif
43 
72 template <typename enumtype, typename storagetype = uint32_t>
73 class PxFlags
74 {
75  public:
76  typedef storagetype InternalType;
77 
79  {
80  }
84  PX_CUDA_CALLABLE PX_INLINE explicit PxFlags(storagetype b);
85 
86  PX_CUDA_CALLABLE PX_INLINE bool isSet(enumtype e) const;
88  PX_CUDA_CALLABLE PX_INLINE bool operator==(enumtype e) const;
89  PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxFlags<enumtype, storagetype>& f) const;
90  PX_CUDA_CALLABLE PX_INLINE bool operator==(bool b) const;
91  PX_CUDA_CALLABLE PX_INLINE bool operator!=(enumtype e) const;
92  PX_CUDA_CALLABLE PX_INLINE bool operator!=(const PxFlags<enumtype, storagetype>& f) const;
93 
96 
99  PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator|(enumtype e) const;
101 
104  PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype e) const;
106 
109  PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator^(enumtype e) const;
111 
113 
114  PX_CUDA_CALLABLE PX_INLINE operator bool(void) const;
115  PX_CUDA_CALLABLE PX_INLINE operator uint8_t(void) const;
116  PX_CUDA_CALLABLE PX_INLINE operator uint16_t(void) const;
117  PX_CUDA_CALLABLE PX_INLINE operator uint32_t(void) const;
118 
119  PX_CUDA_CALLABLE PX_INLINE void clear(enumtype e);
120 
121  public:
123  {
125  out.mBits = a & b.mBits;
126  return out;
127  }
128 
129  private:
130  storagetype mBits;
131 };
132 
133 #if !PX_DOXYGEN
134 
135 #define PX_FLAGS_OPERATORS(enumtype, storagetype) \
136  PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator|(enumtype a, enumtype b) \
137  { \
138  PxFlags<enumtype, storagetype> r(a); \
139  r |= b; \
140  return r; \
141  } \
142  PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype a, enumtype b) \
143  { \
144  PxFlags<enumtype, storagetype> r(a); \
145  r &= b; \
146  return r; \
147  } \
148  PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator~(enumtype a) \
149  { \
150  return ~PxFlags<enumtype, storagetype>(a); \
151  }
152 
153 #define PX_FLAGS_TYPEDEF(x, y) \
154  typedef PxFlags<x::Enum, y> x##s; \
155  PX_FLAGS_OPERATORS(x::Enum, y)
156 
157 template <typename enumtype, typename storagetype>
159 {
160  mBits = 0;
161 }
162 
163 template <typename enumtype, typename storagetype>
165 {
166  mBits = static_cast<storagetype>(e);
167 }
168 
169 template <typename enumtype, typename storagetype>
171 {
172  mBits = f.mBits;
173 }
174 
175 template <typename enumtype, typename storagetype>
177 {
178  mBits = b;
179 }
180 
181 template <typename enumtype, typename storagetype>
183 {
184  return (mBits & static_cast<storagetype>(e)) == static_cast<storagetype>(e);
185 }
186 
187 template <typename enumtype, typename storagetype>
189 {
190  mBits = static_cast<storagetype>(e);
191  return *this;
192 }
193 
194 template <typename enumtype, typename storagetype>
196 {
197  return mBits == static_cast<storagetype>(e);
198 }
199 
200 template <typename enumtype, typename storagetype>
202 {
203  return mBits == f.mBits;
204 }
205 
206 template <typename enumtype, typename storagetype>
208 {
209  return bool(*this) == b;
210 }
211 
212 template <typename enumtype, typename storagetype>
214 {
215  return mBits != static_cast<storagetype>(e);
216 }
217 
218 template <typename enumtype, typename storagetype>
220 {
221  return mBits != f.mBits;
222 }
223 
224 template <typename enumtype, typename storagetype>
226 {
227  mBits = static_cast<storagetype>(e);
228  return *this;
229 }
230 
231 template <typename enumtype, typename storagetype>
233 {
234  mBits = f.mBits;
235  return *this;
236 }
237 
238 template <typename enumtype, typename storagetype>
240 {
241  mBits |= static_cast<storagetype>(e);
242  return *this;
243 }
244 
245 template <typename enumtype, typename storagetype>
248 {
249  mBits |= f.mBits;
250  return *this;
251 }
252 
253 template <typename enumtype, typename storagetype>
255 {
257  out |= e;
258  return out;
259 }
260 
261 template <typename enumtype, typename storagetype>
264 {
266  out |= f;
267  return out;
268 }
269 
270 template <typename enumtype, typename storagetype>
272 {
273  mBits &= static_cast<storagetype>(e);
274  return *this;
275 }
276 
277 template <typename enumtype, typename storagetype>
280 {
281  mBits &= f.mBits;
282  return *this;
283 }
284 
285 template <typename enumtype, typename storagetype>
287 {
288  PxFlags<enumtype, storagetype> out = *this;
289  out.mBits &= static_cast<storagetype>(e);
290  return out;
291 }
292 
293 template <typename enumtype, typename storagetype>
296 {
297  PxFlags<enumtype, storagetype> out = *this;
298  out.mBits &= f.mBits;
299  return out;
300 }
301 
302 template <typename enumtype, typename storagetype>
304 {
305  mBits ^= static_cast<storagetype>(e);
306  return *this;
307 }
308 
309 template <typename enumtype, typename storagetype>
312 {
313  mBits ^= f.mBits;
314  return *this;
315 }
316 
317 template <typename enumtype, typename storagetype>
319 {
320  PxFlags<enumtype, storagetype> out = *this;
321  out.mBits ^= static_cast<storagetype>(e);
322  return out;
323 }
324 
325 template <typename enumtype, typename storagetype>
328 {
329  PxFlags<enumtype, storagetype> out = *this;
330  out.mBits ^= f.mBits;
331  return out;
332 }
333 
334 template <typename enumtype, typename storagetype>
336 {
338  out.mBits = storagetype(~mBits);
339  return out;
340 }
341 
342 template <typename enumtype, typename storagetype>
344 {
345  return mBits ? true : false;
346 }
347 
348 template <typename enumtype, typename storagetype>
350 {
351  return static_cast<uint8_t>(mBits);
352 }
353 
354 template <typename enumtype, typename storagetype>
356 {
357  return static_cast<uint16_t>(mBits);
358 }
359 
360 template <typename enumtype, typename storagetype>
362 {
363  return static_cast<uint32_t>(mBits);
364 }
365 
366 template <typename enumtype, typename storagetype>
368 {
369  mBits &= ~static_cast<storagetype>(e);
370 }
371 
372 } // namespace physx
373 #endif
374 
375 
376 #endif // #ifndef PXFOUNDATION_PXFLAGS_H
Definition: GuContactBuffer.h:37
PX_CUDA_CALLABLE PX_INLINE bool operator!=(enumtype e) const
PX_CUDA_CALLABLE PX_INLINE bool operator==(enumtype e) const
PX_CUDA_CALLABLE PX_INLINE PxFlags(const PxEMPTY)
Definition: PxFlags.h:78
storagetype mBits
Definition: PxFlags.h:130
PX_CUDA_CALLABLE PX_INLINE bool isSet(enumtype e) const
PX_CUDA_CALLABLE PX_INLINE PxFlags(void)
PX_CUDA_CALLABLE PX_INLINE PxFlags< enumtype, storagetype > operator~(void) const
PX_CUDA_CALLABLE PX_INLINE PxFlags< enumtype, storagetype > & operator^=(enumtype e)
PX_CUDA_CALLABLE PX_INLINE PxFlags< enumtype, storagetype > operator|(enumtype e) const
PX_CUDA_CALLABLE PX_INLINE PxFlags< enumtype, storagetype > operator &(enumtype e) const
storagetype InternalType
Definition: PxFlags.h:76
PX_CUDA_CALLABLE PX_INLINE PxFlags< enumtype, storagetype > & operator &=(enumtype e)
PX_CUDA_CALLABLE PX_INLINE PxFlags< enumtype, storagetype > & operator=(const PxFlags< enumtype, storagetype > &f)
PxEMPTY
Definition: Px.h:70
PX_CUDA_CALLABLE PX_INLINE PxFlags< enumtype, storagetype > & set(enumtype e)
PX_CUDA_CALLABLE PX_INLINE PxFlags< enumtype, storagetype > & operator|=(enumtype e)
PX_CUDA_CALLABLE PX_INLINE void clear(enumtype e)
friend PX_INLINE PxFlags< enumtype, storagetype > operator &(enumtype a, PxFlags< enumtype, storagetype > &b)
Definition: PxFlags.h:122
Container for bitfield flag variables associated with a specific enum type.
Definition: PxFlags.h:73
#define PX_INLINE
Definition: PxPreprocessor.h:349
#define PX_CUDA_CALLABLE
Definition: PxPreprocessor.h:473
PX_CUDA_CALLABLE PX_INLINE PxFlags< enumtype, storagetype > operator^(enumtype e) const