NVIDIA(R) PhysX(R) SDK 3.4 API Reference: PxFlags.h Source File

NVIDIA PhysX SDK 3.4 API

PxFlags.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
00029 
00030 #ifndef PXFOUNDATION_PXFLAGS_H
00031 #define PXFOUNDATION_PXFLAGS_H
00032 
00037 #include "foundation/Px.h"
00038 
00039 #if !PX_DOXYGEN
00040 namespace physx
00041 {
00042 #endif
00043 
00072 template <typename enumtype, typename storagetype = uint32_t>
00073 class PxFlags
00074 {
00075   public:
00076     typedef storagetype InternalType;
00077 
00078     PX_CUDA_CALLABLE PX_INLINE explicit PxFlags(const PxEMPTY)
00079     {
00080     }
00081     PX_CUDA_CALLABLE PX_INLINE PxFlags(void);
00082     PX_CUDA_CALLABLE PX_INLINE PxFlags(enumtype e);
00083     PX_CUDA_CALLABLE PX_INLINE PxFlags(const PxFlags<enumtype, storagetype>& f);
00084     PX_CUDA_CALLABLE PX_INLINE explicit PxFlags(storagetype b);
00085 
00086     PX_CUDA_CALLABLE PX_INLINE bool isSet(enumtype e) const;
00087     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& set(enumtype e);
00088     PX_CUDA_CALLABLE PX_INLINE bool operator==(enumtype e) const;
00089     PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxFlags<enumtype, storagetype>& f) const;
00090     PX_CUDA_CALLABLE PX_INLINE bool operator==(bool b) const;
00091     PX_CUDA_CALLABLE PX_INLINE bool operator!=(enumtype e) const;
00092     PX_CUDA_CALLABLE PX_INLINE bool operator!=(const PxFlags<enumtype, storagetype>& f) const;
00093 
00094     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator=(const PxFlags<enumtype, storagetype>& f);
00095     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator=(enumtype e);
00096 
00097     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator|=(enumtype e);
00098     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator|=(const PxFlags<enumtype, storagetype>& f);
00099     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator|(enumtype e) const;
00100     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator|(const PxFlags<enumtype, storagetype>& f) const;
00101 
00102     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator&=(enumtype e);
00103     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator&=(const PxFlags<enumtype, storagetype>& f);
00104     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype e) const;
00105     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator&(const PxFlags<enumtype, storagetype>& f) const;
00106 
00107     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator^=(enumtype e);
00108     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype>& operator^=(const PxFlags<enumtype, storagetype>& f);
00109     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator^(enumtype e) const;
00110     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator^(const PxFlags<enumtype, storagetype>& f) const;
00111 
00112     PX_CUDA_CALLABLE PX_INLINE PxFlags<enumtype, storagetype> operator~(void) const;
00113 
00114     PX_CUDA_CALLABLE PX_INLINE operator bool(void) const;
00115     PX_CUDA_CALLABLE PX_INLINE operator uint8_t(void) const;
00116     PX_CUDA_CALLABLE PX_INLINE operator uint16_t(void) const;
00117     PX_CUDA_CALLABLE PX_INLINE operator uint32_t(void) const;
00118 
00119     PX_CUDA_CALLABLE PX_INLINE void clear(enumtype e);
00120 
00121   public:
00122     friend PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype a, PxFlags<enumtype, storagetype>& b)
00123     {
00124         PxFlags<enumtype, storagetype> out;
00125         out.mBits = a & b.mBits;
00126         return out;
00127     }
00128 
00129   private:
00130     storagetype mBits;
00131 };
00132 
00133 #define PX_FLAGS_OPERATORS(enumtype, storagetype)                                                                      \
00134     PX_INLINE PxFlags<enumtype, storagetype> operator|(enumtype a, enumtype b)                                         \
00135     {                                                                                                                  \
00136         PxFlags<enumtype, storagetype> r(a);                                                                           \
00137         r |= b;                                                                                                        \
00138         return r;                                                                                                      \
00139     }                                                                                                                  \
00140     PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype a, enumtype b)                                         \
00141     {                                                                                                                  \
00142         PxFlags<enumtype, storagetype> r(a);                                                                           \
00143         r &= b;                                                                                                        \
00144         return r;                                                                                                      \
00145     }                                                                                                                  \
00146     PX_INLINE PxFlags<enumtype, storagetype> operator~(enumtype a)                                                     \
00147     {                                                                                                                  \
00148         return ~PxFlags<enumtype, storagetype>(a);                                                                     \
00149     }
00150 
00151 #define PX_FLAGS_TYPEDEF(x, y)                                                                                         \
00152     typedef PxFlags<x::Enum, y> x##s;                                                                                  \
00153     PX_FLAGS_OPERATORS(x::Enum, y)
00154 
00155 template <typename enumtype, typename storagetype>
00156 PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(void)
00157 {
00158     mBits = 0;
00159 }
00160 
00161 template <typename enumtype, typename storagetype>
00162 PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(enumtype e)
00163 {
00164     mBits = static_cast<storagetype>(e);
00165 }
00166 
00167 template <typename enumtype, typename storagetype>
00168 PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(const PxFlags<enumtype, storagetype>& f)
00169 {
00170     mBits = f.mBits;
00171 }
00172 
00173 template <typename enumtype, typename storagetype>
00174 PX_INLINE PxFlags<enumtype, storagetype>::PxFlags(storagetype b)
00175 {
00176     mBits = b;
00177 }
00178 
00179 template <typename enumtype, typename storagetype>
00180 PX_INLINE bool PxFlags<enumtype, storagetype>::isSet(enumtype e) const
00181 {
00182     return (mBits & static_cast<storagetype>(e)) == static_cast<storagetype>(e);
00183 }
00184 
00185 template <typename enumtype, typename storagetype>
00186 PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::set(enumtype e)
00187 {
00188     mBits = static_cast<storagetype>(e);
00189     return *this;
00190 }
00191 
00192 template <typename enumtype, typename storagetype>
00193 PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(enumtype e) const
00194 {
00195     return mBits == static_cast<storagetype>(e);
00196 }
00197 
00198 template <typename enumtype, typename storagetype>
00199 PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(const PxFlags<enumtype, storagetype>& f) const
00200 {
00201     return mBits == f.mBits;
00202 }
00203 
00204 template <typename enumtype, typename storagetype>
00205 PX_INLINE bool PxFlags<enumtype, storagetype>::operator==(bool b) const
00206 {
00207     return bool(*this) == b;
00208 }
00209 
00210 template <typename enumtype, typename storagetype>
00211 PX_INLINE bool PxFlags<enumtype, storagetype>::operator!=(enumtype e) const
00212 {
00213     return mBits != static_cast<storagetype>(e);
00214 }
00215 
00216 template <typename enumtype, typename storagetype>
00217 PX_INLINE bool PxFlags<enumtype, storagetype>::operator!=(const PxFlags<enumtype, storagetype>& f) const
00218 {
00219     return mBits != f.mBits;
00220 }
00221 
00222 template <typename enumtype, typename storagetype>
00223 PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator=(enumtype e)
00224 {
00225     mBits = static_cast<storagetype>(e);
00226     return *this;
00227 }
00228 
00229 template <typename enumtype, typename storagetype>
00230 PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator=(const PxFlags<enumtype, storagetype>& f)
00231 {
00232     mBits = f.mBits;
00233     return *this;
00234 }
00235 
00236 template <typename enumtype, typename storagetype>
00237 PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator|=(enumtype e)
00238 {
00239     mBits |= static_cast<storagetype>(e);
00240     return *this;
00241 }
00242 
00243 template <typename enumtype, typename storagetype>
00244 PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
00245 operator|=(const PxFlags<enumtype, storagetype>& f)
00246 {
00247     mBits |= f.mBits;
00248     return *this;
00249 }
00250 
00251 template <typename enumtype, typename storagetype>
00252 PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator|(enumtype e) const
00253 {
00254     PxFlags<enumtype, storagetype> out(*this);
00255     out |= e;
00256     return out;
00257 }
00258 
00259 template <typename enumtype, typename storagetype>
00260 PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
00261 operator|(const PxFlags<enumtype, storagetype>& f) const
00262 {
00263     PxFlags<enumtype, storagetype> out(*this);
00264     out |= f;
00265     return out;
00266 }
00267 
00268 template <typename enumtype, typename storagetype>
00269 PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator&=(enumtype e)
00270 {
00271     mBits &= static_cast<storagetype>(e);
00272     return *this;
00273 }
00274 
00275 template <typename enumtype, typename storagetype>
00276 PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
00277 operator&=(const PxFlags<enumtype, storagetype>& f)
00278 {
00279     mBits &= f.mBits;
00280     return *this;
00281 }
00282 
00283 template <typename enumtype, typename storagetype>
00284 PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator&(enumtype e) const
00285 {
00286     PxFlags<enumtype, storagetype> out = *this;
00287     out.mBits &= static_cast<storagetype>(e);
00288     return out;
00289 }
00290 
00291 template <typename enumtype, typename storagetype>
00292 PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
00293 operator&(const PxFlags<enumtype, storagetype>& f) const
00294 {
00295     PxFlags<enumtype, storagetype> out = *this;
00296     out.mBits &= f.mBits;
00297     return out;
00298 }
00299 
00300 template <typename enumtype, typename storagetype>
00301 PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::operator^=(enumtype e)
00302 {
00303     mBits ^= static_cast<storagetype>(e);
00304     return *this;
00305 }
00306 
00307 template <typename enumtype, typename storagetype>
00308 PX_INLINE PxFlags<enumtype, storagetype>& PxFlags<enumtype, storagetype>::
00309 operator^=(const PxFlags<enumtype, storagetype>& f)
00310 {
00311     mBits ^= f.mBits;
00312     return *this;
00313 }
00314 
00315 template <typename enumtype, typename storagetype>
00316 PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator^(enumtype e) const
00317 {
00318     PxFlags<enumtype, storagetype> out = *this;
00319     out.mBits ^= static_cast<storagetype>(e);
00320     return out;
00321 }
00322 
00323 template <typename enumtype, typename storagetype>
00324 PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::
00325 operator^(const PxFlags<enumtype, storagetype>& f) const
00326 {
00327     PxFlags<enumtype, storagetype> out = *this;
00328     out.mBits ^= f.mBits;
00329     return out;
00330 }
00331 
00332 template <typename enumtype, typename storagetype>
00333 PX_INLINE PxFlags<enumtype, storagetype> PxFlags<enumtype, storagetype>::operator~(void) const
00334 {
00335     PxFlags<enumtype, storagetype> out;
00336     out.mBits = storagetype(~mBits);
00337     return out;
00338 }
00339 
00340 template <typename enumtype, typename storagetype>
00341 PX_INLINE PxFlags<enumtype, storagetype>::operator bool(void) const
00342 {
00343     return mBits ? true : false;
00344 }
00345 
00346 template <typename enumtype, typename storagetype>
00347 PX_INLINE PxFlags<enumtype, storagetype>::operator uint8_t(void) const
00348 {
00349     return static_cast<uint8_t>(mBits);
00350 }
00351 
00352 template <typename enumtype, typename storagetype>
00353 PX_INLINE PxFlags<enumtype, storagetype>::operator uint16_t(void) const
00354 {
00355     return static_cast<uint16_t>(mBits);
00356 }
00357 
00358 template <typename enumtype, typename storagetype>
00359 PX_INLINE PxFlags<enumtype, storagetype>::operator uint32_t(void) const
00360 {
00361     return static_cast<uint32_t>(mBits);
00362 }
00363 
00364 template <typename enumtype, typename storagetype>
00365 PX_INLINE void PxFlags<enumtype, storagetype>::clear(enumtype e)
00366 {
00367     mBits &= ~static_cast<storagetype>(e);
00368 }
00369 
00370 #if !PX_DOXYGEN
00371 } // namespace physx
00372 #endif
00373 
00375 #endif // #ifndef PXFOUNDATION_PXFLAGS_H


Copyright © 2008-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com