#ifndef PX_PHYSICS_PX_BASE
#define PX_PHYSICS_PX_BASE
#include "foundation/PxFlags.h"
#include "common/PxSerialFramework.h"
#include "common/PxCollection.h"
#include "common/PxTypeInfo.h"
#include <string.h>
#if !PX_DOXYGEN
namespace physx
{
#endif
typedef PxU16 PxType;
struct PxBaseFlag
{
enum Enum
{
eOWNS_MEMORY = (1<<0),
eIS_RELEASABLE = (1<<1)
};
};
typedef PxFlags<PxBaseFlag::Enum, PxU16> PxBaseFlags;
PX_FLAGS_OPERATORS(PxBaseFlag::Enum, PxU16)
class PxBase
{
public:
virtual void release() = 0;
virtual const char* getConcreteTypeName() const = 0;
template<class T> T* is() { return typeMatch<T>() ? static_cast<T*>(this) : NULL; }
template<class T> const T* is() const { return typeMatch<T>() ? static_cast<const T*>(this) : NULL; }
PX_FORCE_INLINE PxType getConcreteType() const { return mConcreteType; }
PX_FORCE_INLINE void setBaseFlag(PxBaseFlag::Enum flag, bool value) { mBaseFlags = value ? mBaseFlags|flag : mBaseFlags&~flag; }
PX_FORCE_INLINE void setBaseFlags(PxBaseFlags inFlags) { mBaseFlags = inFlags; }
PX_FORCE_INLINE PxBaseFlags getBaseFlags() const { return mBaseFlags; }
virtual bool isReleasable() const { return mBaseFlags & PxBaseFlag::eIS_RELEASABLE; }
protected:
PX_INLINE PxBase(PxType concreteType, PxBaseFlags baseFlags)
: mConcreteType(concreteType), mBaseFlags(baseFlags) {}
PX_INLINE PxBase(PxBaseFlags baseFlags) : mBaseFlags(baseFlags) {}
virtual ~PxBase() {}
virtual bool isKindOf(const char* superClass) const { return !::strcmp(superClass, "PxBase"); }
template<class T> bool typeMatch() const
{
return PxU32(PxTypeInfo<T>::eFastTypeId)!=PxU32(PxConcreteType::eUNDEFINED) ?
PxU32(getConcreteType()) == PxU32(PxTypeInfo<T>::eFastTypeId) : isKindOf(PxTypeInfo<T>::name());
}
private:
friend void getBinaryMetaData_PxBase(PxOutputStream& stream);
protected:
PxType mConcreteType; PxBaseFlags mBaseFlags;
};
#if !PX_DOXYGEN
} #endif
#endif