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-2021 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
33/** \addtogroup foundation
34 @{
35*/
36
37#include "foundation/Px.h"
38
39#if !PX_DOXYGEN
40namespace physx
41{
42#endif
43/**
44\brief Container for bitfield flag variables associated with a specific enum type.
45
46This allows for type safe manipulation for bitfields.
47
48<h3>Example</h3>
49 // enum that defines each bit...
50 struct MyEnum
51 {
52 enum Enum
53 {
54 eMAN = 1,
55 eBEAR = 2,
56 ePIG = 4,
57 };
58 };
59
60 // implements some convenient global operators.
61 PX_FLAGS_OPERATORS(MyEnum::Enum, uint8_t);
62
63 PxFlags<MyEnum::Enum, uint8_t> myFlags;
64 myFlags |= MyEnum::eMAN;
65 myFlags |= MyEnum::eBEAR | MyEnum::ePIG;
66 if(myFlags & MyEnum::eBEAR)
67 {
68 doSomething();
69 }
70*/
71
72template <typename enumtype, typename storagetype = uint32_t>
73class PxFlags
74{
75 public:
76 typedef storagetype InternalType;
77
78 PX_CUDA_CALLABLE PX_INLINE explicit PxFlags(const PxEMPTY)
79 {
80 }
81 PX_CUDA_CALLABLE PX_INLINE PxFlags(void);
82 PX_CUDA_CALLABLE PX_INLINE PxFlags(enumtype e);
83 PX_CUDA_CALLABLE PX_INLINE PxFlags(const PxFlags<enumtype, storagetype>& f);
84 PX_CUDA_CALLABLE PX_INLINE explicit PxFlags(storagetype b);
85
86 PX_CUDA_CALLABLE PX_INLINE bool isSet(enumtype e) const;
87 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& set(enumtype e);
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
94 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator=(const PxFlags<enumtype, storagetype>& f);
95 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator=(enumtype e);
96
97 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator|=(enumtype e);
98 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator|=(const PxFlags<enumtype, storagetype>& f);
99 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator|(enumtype e) const;
100 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator|(const PxFlags<enumtype, storagetype>& f) const;
101
102 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator&=(enumtype e);
103 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator&=(const PxFlags<enumtype, storagetype>& f);
104 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype e) const;
105 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator&(const PxFlags<enumtype, storagetype>& f) const;
106
107 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator^=(enumtype e);
108 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator^=(const PxFlags<enumtype, storagetype>& f);
109 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator^(enumtype e) const;
110 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator^(const PxFlags<enumtype, storagetype>& f) const;
111
112 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator~(void) const;
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:
122 friend PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype a, PxFlags<enumtype, storagetype>& b)
123 {
124 PxFlags<enumtype, storagetype> out;
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>
158PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(void)
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>::isSet(enumtype e) const
183{
184 return (mBits & static_cast<storagetype>(e)) == static_cast<storagetype>(e);
185}
186
187template <typename enumtype, typename storagetype>
188PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::set(enumtype e)
189{
190 mBits = static_cast<storagetype>(e);
191 return *this;
192}
193
194template <typename enumtype, typename storagetype>
195PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(enumtype e) const
196{
197 return mBits == static_cast<storagetype>(e);
198}
199
200template <typename enumtype, typename storagetype>
201PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(const PxFlags<enumtype, storagetype>& f) const
202{
203 return mBits == f.mBits;
204}
205
206template <typename enumtype, typename storagetype>
207PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(bool b) const
208{
209 return bool(*this) == b;
210}
211
212template <typename enumtype, typename storagetype>
213PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::operator!=(enumtype e) const
214{
215 return mBits != static_cast<storagetype>(e);
216}
217
218template <typename enumtype, typename storagetype>
219PX_CUDA_CALLABLE PX_INLINE bool PxFlags<enumtype, storagetype>::operator!=(const PxFlags<enumtype, storagetype>& f) const
220{
221 return mBits != f.mBits;
222}
223
224template <typename enumtype, typename storagetype>
225PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator=(enumtype e)
226{
227 mBits = static_cast<storagetype>(e);
228 return *this;
229}
230
231template <typename enumtype, typename storagetype>
232PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator=(const PxFlags<enumtype, storagetype>& f)
233{
234 mBits = f.mBits;
235 return *this;
236}
237
238template <typename enumtype, typename storagetype>
239PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator|=(enumtype e)
240{
241 mBits |= static_cast<storagetype>(e);
242 return *this;
243}
244
245template <typename enumtype, typename storagetype>
246PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
247operator|=(const PxFlags<enumtype, storagetype>& f)
248{
249 mBits |= f.mBits;
250 return *this;
251}
252
253template <typename enumtype, typename storagetype>
254PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator|(enumtype e) const
255{
256 PxFlags<enumtype, storagetype> out(*this);
257 out |= e;
258 return out;
259}
260
261template <typename enumtype, typename storagetype>
262PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
263operator|(const PxFlags<enumtype, storagetype>& f) const
264{
265 PxFlags<enumtype, storagetype> out(*this);
266 out |= f;
267 return out;
268}
269
270template <typename enumtype, typename storagetype>
271PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator&=(enumtype e)
272{
273 mBits &= static_cast<storagetype>(e);
274 return *this;
275}
276
277template <typename enumtype, typename storagetype>
278PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
279operator&=(const PxFlags<enumtype, storagetype>& f)
280{
281 mBits &= f.mBits;
282 return *this;
283}
284
285template <typename enumtype, typename storagetype>
286PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator&(enumtype e) const
287{
288 PxFlags<enumtype, storagetype> out = *this;
289 out.mBits &= static_cast<storagetype>(e);
290 return out;
291}
292
293template <typename enumtype, typename storagetype>
294PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
295operator&(const PxFlags<enumtype, storagetype>& f) const
296{
297 PxFlags<enumtype, storagetype> out = *this;
298 out.mBits &= f.mBits;
299 return out;
300}
301
302template <typename enumtype, typename storagetype>
303PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator^=(enumtype e)
304{
305 mBits ^= static_cast<storagetype>(e);
306 return *this;
307}
308
309template <typename enumtype, typename storagetype>
310PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
311operator^=(const PxFlags<enumtype, storagetype>& f)
312{
313 mBits ^= f.mBits;
314 return *this;
315}
316
317template <typename enumtype, typename storagetype>
318PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator^(enumtype e) const
319{
320 PxFlags<enumtype, storagetype> out = *this;
321 out.mBits ^= static_cast<storagetype>(e);
322 return out;
323}
324
325template <typename enumtype, typename storagetype>
326PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
327operator^(const PxFlags<enumtype, storagetype>& f) const
328{
329 PxFlags<enumtype, storagetype> out = *this;
330 out.mBits ^= f.mBits;
331 return out;
332}
333
334template <typename enumtype, typename storagetype>
335PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator~(void) const
336{
337 PxFlags<enumtype, storagetype> out;
338 out.mBits = storagetype(~mBits);
339 return out;
340}
341
342template <typename enumtype, typename storagetype>
343PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::operator bool(void) const
344{
345 return mBits ? true : false;
346}
347
348template <typename enumtype, typename storagetype>
349PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::operator uint8_t(void) const
350{
351 return static_cast<uint8_t>(mBits);
352}
353
354template <typename enumtype, typename storagetype>
355PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::operator uint16_t(void) const
356{
357 return static_cast<uint16_t>(mBits);
358}
359
360template <typename enumtype, typename storagetype>
361PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>::operator uint32_t(void) const
362{
363 return static_cast<uint32_t>(mBits);
364}
365
366template <typename enumtype, typename storagetype>
367PX_CUDA_CALLABLE PX_INLINE void PxFlags<enumtype, storagetype>::clear(enumtype e)
368{
369 mBits &= ~static_cast<storagetype>(e);
370}
371
372} // namespace physx
373#endif //!PX_DOXYGEN
374
375/** @} */
376#endif // #ifndef PXFOUNDATION_PXFLAGS_H
377

source code of qtquick3dphysics/src/3rdparty/PhysX/pxshared/include/foundation/PxFlags.h