30#ifndef PXFOUNDATION_PXFLAGS_H
31#define PXFOUNDATION_PXFLAGS_H
37#include "foundation/Px.h"
72template <
typename enumtype,
typename storagetype = u
int32_t>
76 typedef storagetype InternalType;
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);
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;
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);
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;
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;
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;
112 PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype> operator~(
void)
const;
114 PX_CUDA_CALLABLE
PX_INLINE operator bool(
void)
const;
119 PX_CUDA_CALLABLE
PX_INLINE void clear(enumtype e);
122 friend PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype a, PxFlags<enumtype, storagetype>& b)
124 PxFlags<enumtype, storagetype> out;
125 out.mBits = a & b.mBits;
135#define PX_FLAGS_OPERATORS(enumtype, storagetype) \
136 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator|(enumtype a, enumtype b) \
138 PxFlags<enumtype, storagetype> r(a); \
142 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype a, enumtype b) \
144 PxFlags<enumtype, storagetype> r(a); \
148 PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator~(enumtype a) \
150 return ~PxFlags<enumtype, storagetype>(a); \
153#define PX_FLAGS_TYPEDEF(x, y) \
154 typedef PxFlags<x::Enum, y> x##s; \
155 PX_FLAGS_OPERATORS(x::Enum, y)
157template <
typename enumtype,
typename storagetype>
158PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(
void)
163template <
typename enumtype,
typename storagetype>
164PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(enumtype e)
166 mBits =
static_cast<storagetype
>(e);
169template <
typename enumtype,
typename storagetype>
170PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(
const PxFlags<enumtype, storagetype>& f)
175template <
typename enumtype,
typename storagetype>
176PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(storagetype b)
181template <
typename enumtype,
typename storagetype>
182PX_CUDA_CALLABLE
PX_INLINE bool PxFlags<enumtype, storagetype>::isSet(enumtype e)
const
184 return (mBits &
static_cast<storagetype
>(e)) ==
static_cast<storagetype
>(e);
187template <
typename enumtype,
typename storagetype>
188PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::set(enumtype e)
190 mBits =
static_cast<storagetype
>(e);
194template <
typename enumtype,
typename storagetype>
195PX_CUDA_CALLABLE
PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(enumtype e)
const
197 return mBits ==
static_cast<storagetype
>(e);
200template <
typename enumtype,
typename storagetype>
201PX_CUDA_CALLABLE
PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(
const PxFlags<enumtype, storagetype>& f)
const
203 return mBits == f.mBits;
206template <
typename enumtype,
typename storagetype>
207PX_CUDA_CALLABLE
PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(
bool b)
const
209 return bool(*
this) == b;
212template <
typename enumtype,
typename storagetype>
213PX_CUDA_CALLABLE
PX_INLINE bool PxFlags<enumtype, storagetype>::operator!=(enumtype e)
const
215 return mBits !=
static_cast<storagetype
>(e);
218template <
typename enumtype,
typename storagetype>
219PX_CUDA_CALLABLE
PX_INLINE bool PxFlags<enumtype, storagetype>::operator!=(
const PxFlags<enumtype, storagetype>& f)
const
221 return mBits != f.mBits;
224template <
typename enumtype,
typename storagetype>
225PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator=(enumtype e)
227 mBits =
static_cast<storagetype
>(e);
231template <
typename enumtype,
typename storagetype>
232PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator=(
const PxFlags<enumtype, storagetype>& f)
238template <
typename enumtype,
typename storagetype>
239PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator|=(enumtype e)
241 mBits |=
static_cast<storagetype
>(e);
245template <
typename enumtype,
typename storagetype>
246PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
247operator|=(
const PxFlags<enumtype, storagetype>& f)
253template <
typename enumtype,
typename storagetype>
254PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator|(enumtype e)
const
256 PxFlags<enumtype, storagetype> out(*
this);
261template <
typename enumtype,
typename storagetype>
262PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
263operator|(
const PxFlags<enumtype, storagetype>& f)
const
265 PxFlags<enumtype, storagetype> out(*
this);
270template <
typename enumtype,
typename storagetype>
271PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator&=(enumtype e)
273 mBits &=
static_cast<storagetype
>(e);
277template <
typename enumtype,
typename storagetype>
278PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
279operator&=(
const PxFlags<enumtype, storagetype>& f)
285template <
typename enumtype,
typename storagetype>
286PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator&(enumtype e)
const
288 PxFlags<enumtype, storagetype> out = *
this;
289 out.mBits &=
static_cast<storagetype
>(e);
293template <
typename enumtype,
typename storagetype>
294PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
295operator&(
const PxFlags<enumtype, storagetype>& f)
const
297 PxFlags<enumtype, storagetype> out = *
this;
298 out.mBits &= f.mBits;
302template <
typename enumtype,
typename storagetype>
303PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator^=(enumtype e)
305 mBits ^=
static_cast<storagetype
>(e);
309template <
typename enumtype,
typename storagetype>
310PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
311operator^=(
const PxFlags<enumtype, storagetype>& f)
317template <
typename enumtype,
typename storagetype>
318PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator^(enumtype e)
const
320 PxFlags<enumtype, storagetype> out = *
this;
321 out.mBits ^=
static_cast<storagetype
>(e);
325template <
typename enumtype,
typename storagetype>
326PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
327operator^(
const PxFlags<enumtype, storagetype>& f)
const
329 PxFlags<enumtype, storagetype> out = *
this;
330 out.mBits ^= f.mBits;
334template <
typename enumtype,
typename storagetype>
335PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator~(
void)
const
337 PxFlags<enumtype, storagetype> out;
338 out.mBits = storagetype(~mBits);
342template <
typename enumtype,
typename storagetype>
343PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>::operator bool(
void)
const
345 return mBits ? true :
false;
348template <
typename enumtype,
typename storagetype>
349PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>::operator
uint8_t(
void)
const
351 return static_cast<uint8_t>(mBits);
354template <
typename enumtype,
typename storagetype>
355PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>::operator
uint16_t(
void)
const
357 return static_cast<uint16_t>(mBits);
360template <
typename enumtype,
typename storagetype>
361PX_CUDA_CALLABLE
PX_INLINE PxFlags<enumtype, storagetype>::operator
uint32_t(
void)
const
363 return static_cast<uint32_t>(mBits);
366template <
typename enumtype,
typename storagetype>
367PX_CUDA_CALLABLE
PX_INLINE void PxFlags<enumtype, storagetype>::clear(enumtype e)
369 mBits &= ~static_cast<storagetype>(e);
#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