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-2012 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 00031 #ifndef PX_FOUNDATION_PX_FLAGS_H 00032 #define PX_FOUNDATION_PX_FLAGS_H 00033 00038 #include "foundation/Px.h" 00039 00040 #ifndef PX_DOXYGEN 00041 namespace physx 00042 { 00043 #endif 00044 00072 template<typename enumtype, typename storagetype=PxU32> 00073 class PxFlags 00074 { 00075 public: 00076 PX_INLINE explicit PxFlags(const PxEmpty&) {} 00077 PX_INLINE PxFlags(void); 00078 PX_INLINE PxFlags(enumtype e); 00079 PX_INLINE PxFlags(const PxFlags<enumtype,storagetype> &f); 00080 PX_INLINE explicit PxFlags(storagetype b); 00081 00082 PX_INLINE bool operator==(enumtype e) const; 00083 PX_INLINE bool operator==(const PxFlags<enumtype,storagetype> &f) const; 00084 PX_INLINE bool operator==(bool b) const; 00085 PX_INLINE bool operator!=(enumtype e) const; 00086 PX_INLINE bool operator!=(const PxFlags<enumtype,storagetype> &f) const; 00087 00088 PX_INLINE PxFlags<enumtype,storagetype> &operator =(enumtype e); 00089 00090 PX_INLINE PxFlags<enumtype,storagetype> &operator|=(enumtype e); 00091 PX_INLINE PxFlags<enumtype,storagetype> &operator|=(const PxFlags<enumtype,storagetype> &f); 00092 PX_INLINE PxFlags<enumtype,storagetype> operator| (enumtype e) const; 00093 PX_INLINE PxFlags<enumtype,storagetype> operator| (const PxFlags<enumtype,storagetype> &f) const; 00094 00095 PX_INLINE PxFlags<enumtype,storagetype> &operator&=(enumtype e); 00096 PX_INLINE PxFlags<enumtype,storagetype> &operator&=(const PxFlags<enumtype,storagetype> &f); 00097 PX_INLINE PxFlags<enumtype,storagetype> operator& (enumtype e) const; 00098 PX_INLINE PxFlags<enumtype,storagetype> operator& (const PxFlags<enumtype,storagetype> &f) const; 00099 00100 PX_INLINE PxFlags<enumtype,storagetype> &operator^=(enumtype e); 00101 PX_INLINE PxFlags<enumtype,storagetype> &operator^=(const PxFlags<enumtype,storagetype> &f); 00102 PX_INLINE PxFlags<enumtype,storagetype> operator^ (enumtype e) const; 00103 PX_INLINE PxFlags<enumtype,storagetype> operator^ (const PxFlags<enumtype,storagetype> &f) const; 00104 00105 PX_INLINE PxFlags<enumtype,storagetype> operator~ (void) const; 00106 00107 PX_INLINE operator bool(void) const; 00108 PX_INLINE operator PxU8(void) const; 00109 PX_INLINE operator PxU16(void) const; 00110 PX_INLINE operator PxU32(void) const; 00111 00112 PX_INLINE void clear(enumtype e); 00113 00114 public: 00115 friend PX_INLINE PxFlags<enumtype,storagetype> operator&(enumtype a, PxFlags<enumtype,storagetype> &b) 00116 { 00117 PxFlags<enumtype,storagetype> out; 00118 out.mBits = a & b.mBits; 00119 return out; 00120 } 00121 00122 private: 00123 storagetype mBits; 00124 }; 00125 00126 #define PX_FLAGS_OPERATORS(enumtype, storagetype) \ 00127 PX_INLINE PxFlags<enumtype, storagetype> operator|(enumtype a, enumtype b) { PxFlags<enumtype, storagetype> r(a); r |= b; return r; } \ 00128 PX_INLINE PxFlags<enumtype, storagetype> operator&(enumtype a, enumtype b) { PxFlags<enumtype, storagetype> r(a); r &= b; return r; } \ 00129 PX_INLINE PxFlags<enumtype, storagetype> operator~(enumtype a) { return ~PxFlags<enumtype, storagetype>(a); } 00130 00131 00132 00133 00134 template<typename enumtype, typename storagetype> 00135 PX_INLINE PxFlags<enumtype,storagetype>::PxFlags(void) 00136 { 00137 mBits = 0; 00138 } 00139 00140 template<typename enumtype, typename storagetype> 00141 PX_INLINE PxFlags<enumtype,storagetype>::PxFlags(enumtype e) 00142 { 00143 mBits = static_cast<storagetype>(e); 00144 } 00145 00146 template<typename enumtype, typename storagetype> 00147 PX_INLINE PxFlags<enumtype,storagetype>::PxFlags(const PxFlags<enumtype,storagetype> &f) 00148 { 00149 mBits = f.mBits; 00150 } 00151 00152 template<typename enumtype, typename storagetype> 00153 PX_INLINE PxFlags<enumtype,storagetype>::PxFlags(storagetype b) 00154 { 00155 mBits = b; 00156 } 00157 00158 template<typename enumtype, typename storagetype> 00159 PX_INLINE bool PxFlags<enumtype,storagetype>::operator==(enumtype e) const 00160 { 00161 return mBits == static_cast<storagetype>(e); 00162 } 00163 00164 template<typename enumtype, typename storagetype> 00165 PX_INLINE bool PxFlags<enumtype,storagetype>::operator==(const PxFlags<enumtype,storagetype>& f) const 00166 { 00167 return mBits == f.mBits; 00168 } 00169 00170 template<typename enumtype, typename storagetype> 00171 PX_INLINE bool PxFlags<enumtype,storagetype>::operator==(bool b) const 00172 { 00173 return ((bool)*this) == b; 00174 } 00175 00176 template<typename enumtype, typename storagetype> 00177 PX_INLINE bool PxFlags<enumtype,storagetype>::operator!=(enumtype e) const 00178 { 00179 return mBits != static_cast<storagetype>(e); 00180 } 00181 00182 template<typename enumtype, typename storagetype> 00183 PX_INLINE bool PxFlags<enumtype,storagetype>::operator!=(const PxFlags<enumtype,storagetype> &f) const 00184 { 00185 return mBits != f.mBits; 00186 } 00187 00188 template<typename enumtype, typename storagetype> 00189 PX_INLINE PxFlags<enumtype,storagetype> &PxFlags<enumtype,storagetype>::operator =(enumtype e) 00190 { 00191 mBits = static_cast<storagetype>(e); 00192 return *this; 00193 } 00194 00195 template<typename enumtype, typename storagetype> 00196 PX_INLINE PxFlags<enumtype,storagetype> &PxFlags<enumtype,storagetype>::operator|=(enumtype e) 00197 { 00198 mBits |= static_cast<storagetype>(e); 00199 return *this; 00200 } 00201 00202 template<typename enumtype, typename storagetype> 00203 PX_INLINE PxFlags<enumtype,storagetype> &PxFlags<enumtype,storagetype>::operator|=(const PxFlags<enumtype,storagetype> &f) 00204 { 00205 mBits |= f.mBits; 00206 return *this; 00207 } 00208 00209 template<typename enumtype, typename storagetype> 00210 PX_INLINE PxFlags<enumtype,storagetype> PxFlags<enumtype,storagetype>::operator| (enumtype e) const 00211 { 00212 PxFlags<enumtype,storagetype> out(*this); 00213 out |= e; 00214 return out; 00215 } 00216 00217 template<typename enumtype, typename storagetype> 00218 PX_INLINE PxFlags<enumtype,storagetype> PxFlags<enumtype,storagetype>::operator| (const PxFlags<enumtype,storagetype> &f) const 00219 { 00220 PxFlags<enumtype,storagetype> out(*this); 00221 out |= f; 00222 return out; 00223 } 00224 00225 template<typename enumtype, typename storagetype> 00226 PX_INLINE PxFlags<enumtype,storagetype> &PxFlags<enumtype,storagetype>::operator&=(enumtype e) 00227 { 00228 mBits &= static_cast<storagetype>(e); 00229 return *this; 00230 } 00231 00232 template<typename enumtype, typename storagetype> 00233 PX_INLINE PxFlags<enumtype,storagetype> &PxFlags<enumtype,storagetype>::operator&=(const PxFlags<enumtype,storagetype> &f) 00234 { 00235 mBits &= f.mBits; 00236 return *this; 00237 } 00238 00239 template<typename enumtype, typename storagetype> 00240 PX_INLINE PxFlags<enumtype,storagetype> PxFlags<enumtype,storagetype>::operator&(enumtype e) const 00241 { 00242 PxFlags<enumtype,storagetype> out = *this; 00243 out.mBits &= static_cast<storagetype>(e); 00244 return out; 00245 } 00246 00247 template<typename enumtype, typename storagetype> 00248 PX_INLINE PxFlags<enumtype,storagetype> PxFlags<enumtype,storagetype>::operator& (const PxFlags<enumtype,storagetype> &f) const 00249 { 00250 PxFlags<enumtype,storagetype> out = *this; 00251 out.mBits &= f.mBits; 00252 return out; 00253 } 00254 00255 template<typename enumtype, typename storagetype> 00256 PX_INLINE PxFlags<enumtype,storagetype> &PxFlags<enumtype,storagetype>::operator^=(enumtype e) 00257 { 00258 mBits ^= static_cast<storagetype>(e); 00259 return *this; 00260 } 00261 00262 template<typename enumtype, typename storagetype> 00263 PX_INLINE PxFlags<enumtype,storagetype> &PxFlags<enumtype,storagetype>::operator^=(const PxFlags<enumtype,storagetype> &f) 00264 { 00265 mBits ^= f.mBits; 00266 return *this; 00267 } 00268 00269 template<typename enumtype, typename storagetype> 00270 PX_INLINE PxFlags<enumtype,storagetype> PxFlags<enumtype,storagetype>::operator^ (enumtype e) const 00271 { 00272 PxFlags<enumtype,storagetype> out = *this; 00273 out.mBits ^= static_cast<storagetype>(e); 00274 return out; 00275 } 00276 00277 template<typename enumtype, typename storagetype> 00278 PX_INLINE PxFlags<enumtype,storagetype> PxFlags<enumtype,storagetype>::operator^ (const PxFlags<enumtype,storagetype> &f) const 00279 { 00280 PxFlags<enumtype,storagetype> out = *this; 00281 out.mBits ^= f.mBits; 00282 return out; 00283 } 00284 00285 template<typename enumtype, typename storagetype> 00286 PX_INLINE PxFlags<enumtype,storagetype> PxFlags<enumtype,storagetype>::operator~ (void) const 00287 { 00288 PxFlags<enumtype,storagetype> out; 00289 out.mBits = ~mBits; 00290 return out; 00291 } 00292 00293 template<typename enumtype, typename storagetype> 00294 PX_INLINE PxFlags<enumtype,storagetype>::operator bool(void) const 00295 { 00296 return mBits ? true : false; 00297 } 00298 00299 template<typename enumtype, typename storagetype> 00300 PX_INLINE PxFlags<enumtype,storagetype>::operator PxU8(void) const 00301 { 00302 return static_cast<PxU8>(mBits); 00303 } 00304 00305 template<typename enumtype, typename storagetype> 00306 PX_INLINE PxFlags<enumtype,storagetype>::operator PxU16(void) const 00307 { 00308 return static_cast<PxU16>(mBits); 00309 } 00310 00311 template<typename enumtype, typename storagetype> 00312 PX_INLINE PxFlags<enumtype,storagetype>::operator PxU32(void) const 00313 { 00314 return static_cast<PxU32>(mBits); 00315 } 00316 00317 template<typename enumtype, typename storagetype> 00318 PX_INLINE void PxFlags<enumtype,storagetype>::clear(enumtype e) 00319 { 00320 mBits &= ~static_cast<storagetype>(e); 00321 } 00322 00323 #ifndef PX_DOXYGEN 00324 } // namespace physx 00325 #endif 00326 00328 #endif // #ifndef PX_FOUNDATION_PX_FLAGS_H
Copyright © 2008-2012 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com