PxBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12 
13 
14 #ifndef PX_PHYSICS_PX_BASE
15 #define PX_PHYSICS_PX_BASE
16 
21 #include "PxSerialFramework.h"
22 #include "PxCollection.h"
23 
24 #ifndef PX_DOXYGEN
25 namespace physx
26 {
27 #endif
28 
29 typedef PxU16 PxType;
30 
34 struct PxBaseFlag
35 {
36  enum Enum
37  {
38  eOWNS_MEMORY = (1<<0),
39  eIS_RELEASABLE = (1<<1)
40  };
41 };
42 
45 
46 
53 class PxBase
54 {
55 //= ATTENTION! =====================================================================================
56 // Changing the data layout of this class breaks the binary serialization format. See comments for
57 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
58 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
59 // accordingly.
60 //==================================================================================================
61 public:
65  virtual void release() = 0;
66 
71  virtual const char* getConcreteTypeName() const { return NULL; }
72 
73  /* brief Implements dynamic cast functionality.
74 
75  Example use:
76 
77  if(actor->is<PxRigidDynamic>()) {...}
78 
79  \return A pointer to the specified type if object matches, otherwise NULL
80  */
81  template<class T> T* is() { return typeMatch<T>() ? static_cast<T*>(this) : NULL; }
82 
83  /* brief Implements dynamic cast functionality for const objects.
84 
85  Example use:
86 
87  if(actor->is<PxRigidDynamic>()) {...}
88 
89  \return A pointer to the specified type if object matches, otherwise NULL
90  */
91  template<class T> const T* is() const { return typeMatch<T>() ? static_cast<const T*>(this) : NULL; }
92 
99  PX_INLINE PxType getConcreteType() const { return mConcreteType; }
100 
107  PX_INLINE void setBaseFlag(PxBaseFlag::Enum flag, bool value) { mBaseFlags = value ? mBaseFlags|flag : mBaseFlags&~flag; }
108 
116  PX_INLINE void setBaseFlags(PxBaseFlags inFlags ) { mBaseFlags = inFlags; }
117 
125  PX_INLINE PxBaseFlags getBaseFlags() const { return mBaseFlags; }
126 
136  virtual bool isReleasable() const { return mBaseFlags & PxBaseFlag::eIS_RELEASABLE; }
137 
138 protected:
142  PX_INLINE PxBase(PxType concreteType, PxBaseFlags baseFlags)
143  : mConcreteType(concreteType), mBaseFlags(baseFlags) {}
144 
148  PX_INLINE PxBase(PxBaseFlags baseFlags) : mBaseFlags(baseFlags) {}
149 
153  virtual ~PxBase() {}
154 
158  virtual bool isKindOf(const char* superClass) const { return !strcmp(superClass, "PxBase"); }
159 
160  template<class T> bool typeMatch() const
161  {
163  PxU32(getConcreteType()) == PxU32(PxTypeInfo<T>::eFastTypeId) : isKindOf(PxTypeInfo<T>::name());
164  }
165 
166 
167 private:
168  friend void getBinaryMetaData_PxBase(PxOutputStream& stream);
169 
170 protected:
171  PxType mConcreteType; // concrete type identifier - see PxConcreteType.
172  PxBaseFlags mBaseFlags; // internal flags
173 
174 };
175 
176 #ifndef PX_DOXYGEN
177 } // namespace physx
178 #endif
179 
181 #endif


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