RavEngine
Loading...
Searching...
No Matches
PxFlags.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_FLAGS_H
30#define PX_FLAGS_H
31
36#include "foundation/Px.h"
37
38#if !PX_DOXYGEN
39namespace physx
40{
41#endif
71template <typename enumtype, typename storagetype = uint32_t>
73{
74 public:
75 typedef storagetype InternalType;
76
77 PX_CUDA_CALLABLE PX_INLINE explicit PxFlags(const PxEMPTY)
78 {
79 }
80 PX_CUDA_CALLABLE PX_INLINE PxFlags(void);
81 PX_CUDA_CALLABLE PX_INLINE PxFlags(enumtype e);
82 PX_CUDA_CALLABLE PX_INLINE PxFlags(const PxFlags<enumtype, storagetype>& f);
83 PX_CUDA_CALLABLE PX_INLINE explicit PxFlags(storagetype b);
84
85 PX_CUDA_CALLABLE PX_INLINE bool operator==(enumtype e) const;
86 PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxFlags<enumtype, storagetype>& f) const;
87 PX_CUDA_CALLABLE PX_INLINE bool operator==(bool b) 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
92 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator=(enumtype e);
93
94 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator|=(enumtype e);
95 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator|=(const PxFlags<enumtype, storagetype>& f);
96 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator|(enumtype e) const;
97 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator|(const PxFlags<enumtype, storagetype>& f) const;
98
99 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator&=(enumtype e);
100 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator&=(const PxFlags<enumtype, storagetype>& f);
101 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype e) const;
102 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator&(const PxFlags<enumtype, storagetype>& f) const;
103
104 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator^=(enumtype e);
105 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator^=(const PxFlags<enumtype, storagetype>& f);
106 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator^(enumtype e) const;
107 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator^(const PxFlags<enumtype, storagetype>& f) const;
108
109 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator~(void) const;
110
111 PX_CUDA_CALLABLE PX_INLINE operator bool(void) const;
112 PX_CUDA_CALLABLE PX_INLINE operator uint8_t(void) const;
113 PX_CUDA_CALLABLE PX_INLINE operator uint16_t(void) const;
114 PX_CUDA_CALLABLE PX_INLINE operator uint32_t(void) const;
115
116 PX_CUDA_CALLABLE PX_INLINE void clear(enumtype e);
117 PX_CUDA_CALLABLE PX_INLINE void raise(enumtype e);
118 PX_CUDA_CALLABLE PX_INLINE bool isSet(enumtype e) const;
119 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& setAll(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
157template <typename enumtype, typename storagetype>
159{
160 mBits = 0;
161}
162
163template <typename enumtype, typename storagetype>
164PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(enumtype e)
165{
166 mBits = static_cast<storagetype>(e);
167}
168
169template <typename enumtype, typename storagetype>
170PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(const PxFlags<enumtype, storagetype>& f)
171{
172 mBits = f.mBits;
173}
174
175template <typename enumtype, typename storagetype>
176PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(storagetype b)
177{
178 mBits = b;
179}
180
181template <typename enumtype, typename storagetype>
182PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(enumtype e) const
183{
184 return mBits == static_cast<storagetype>(e);
185}
186
187template <typename enumtype, typename storagetype>
188PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(const PxFlags<enumtype, storagetype>& f) const
189{
190 return mBits == f.mBits;
191}
192
193template <typename enumtype, typename storagetype>
194PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(bool b) const
195{
196 return bool(*this) == b;
197}
198
199template <typename enumtype, typename storagetype>
200PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::operator!=(enumtype e) const
201{
202 return mBits != static_cast<storagetype>(e);
203}
204
205template <typename enumtype, typename storagetype>
206PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::operator!=(const PxFlags<enumtype, storagetype>& f) const
207{
208 return mBits != f.mBits;
209}
210
211template <typename enumtype, typename storagetype>
212PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator=(enumtype e)
213{
214 mBits = static_cast<storagetype>(e);
215 return *this;
216}
217
218template <typename enumtype, typename storagetype>
219PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator=(const PxFlags<enumtype, storagetype>& f)
220{
221 mBits = f.mBits;
222 return *this;
223}
224
225template <typename enumtype, typename storagetype>
226PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator|=(enumtype e)
227{
228 mBits |= static_cast<storagetype>(e);
229 return *this;
230}
231
232template <typename enumtype, typename storagetype>
233PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
234operator|=(const PxFlags<enumtype, storagetype>& f)
235{
236 mBits |= f.mBits;
237 return *this;
238}
239
240template <typename enumtype, typename storagetype>
241PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator|(enumtype e) const
242{
243 PxFlags<enumtype, storagetype> out(*this);
244 out |= e;
245 return out;
246}
247
248template <typename enumtype, typename storagetype>
249PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
250operator|(const PxFlags<enumtype, storagetype>& f) const
251{
252 PxFlags<enumtype, storagetype> out(*this);
253 out |= f;
254 return out;
255}
256
257template <typename enumtype, typename storagetype>
258PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator&=(enumtype e)
259{
260 mBits &= static_cast<storagetype>(e);
261 return *this;
262}
263
264template <typename enumtype, typename storagetype>
265PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
266operator&=(const PxFlags<enumtype, storagetype>& f)
267{
268 mBits &= f.mBits;
269 return *this;
270}
271
272template <typename enumtype, typename storagetype>
273PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator&(enumtype e) const
274{
275 PxFlags<enumtype, storagetype> out = *this;
276 out.mBits &= static_cast<storagetype>(e);
277 return out;
278}
279
280template <typename enumtype, typename storagetype>
281PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
282operator&(const PxFlags<enumtype, storagetype>& f) const
283{
284 PxFlags<enumtype, storagetype> out = *this;
285 out.mBits &= f.mBits;
286 return out;
287}
288
289template <typename enumtype, typename storagetype>
290PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator^=(enumtype e)
291{
292 mBits ^= static_cast<storagetype>(e);
293 return *this;
294}
295
296template <typename enumtype, typename storagetype>
297PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
298operator^=(const PxFlags<enumtype, storagetype>& f)
299{
300 mBits ^= f.mBits;
301 return *this;
302}
303
304template <typename enumtype, typename storagetype>
305PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator^(enumtype e) const
306{
307 PxFlags<enumtype, storagetype> out = *this;
308 out.mBits ^= static_cast<storagetype>(e);
309 return out;
310}
311
312template <typename enumtype, typename storagetype>
313PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
314operator^(const PxFlags<enumtype, storagetype>& f) const
315{
316 PxFlags<enumtype, storagetype> out = *this;
317 out.mBits ^= f.mBits;
318 return out;
319}
320
321template <typename enumtype, typename storagetype>
322PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator~(void) const
323{
324 PxFlags<enumtype, storagetype> out;
325 out.mBits = storagetype(~mBits);
326 return out;
327}
328
329template <typename enumtype, typename storagetype>
330PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::operator bool(void) const
331{
332 return mBits ? true : false;
333}
334
335template <typename enumtype, typename storagetype>
336PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::operator uint8_t(void) const
337{
338 return static_cast<uint8_t>(mBits);
339}
340
341template <typename enumtype, typename storagetype>
342PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::operator uint16_t(void) const
343{
344 return static_cast<uint16_t>(mBits);
345}
346
347template <typename enumtype, typename storagetype>
348PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::operator uint32_t(void) const
349{
350 return static_cast<uint32_t>(mBits);
351}
352
353template <typename enumtype, typename storagetype>
354PX_CUDA_CALLABLE PX_INLINE void PxFlags<enumtype, storagetype>::clear(enumtype e)
355{
356 mBits &= ~static_cast<storagetype>(e);
357}
358
359template <typename enumtype, typename storagetype>
360PX_CUDA_CALLABLE PX_INLINE void PxFlags<enumtype, storagetype>::raise(enumtype e)
361{
362 mBits |= static_cast<storagetype>(e);
363}
364
365template <typename enumtype, typename storagetype>
366PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::isSet(enumtype e) const
367{
368 return (mBits & static_cast<storagetype>(e)) == static_cast<storagetype>(e);
369}
370
371template <typename enumtype, typename storagetype>
372PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::setAll(enumtype e)
373{
374 mBits = static_cast<storagetype>(e);
375 return *this;
376}
377
378} // namespace physx
379#endif
380
382#endif
383
Container for bitfield flag variables associated with a specific enum type.
Definition PxFlags.h:73
#define PX_INLINE
Definition PxPreprocessor.h:320
uint32 uint32_t
Definition fwd.hpp:131
uint8 uint8_t
Definition fwd.hpp:103
uint16 uint16_t
Definition fwd.hpp:117
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxEMPTY
Definition Px.h:87