10 #include "tb_linklist.h"
14 typedef void* TB_TYPE_ID;
27 template<
class T>
static TB_TYPE_ID
GetTypeId() {
static char type_id;
return &type_id; }
30 virtual bool IsOfTypeId(
const TB_TYPE_ID type_id)
const {
return type_id == GetTypeId<TBTypedObject>(); }
36 template<
class T>
bool IsOfType()
const {
return SafeCastTo<T>() ?
true :
false; }
39 virtual const char *
GetClassName()
const {
return "TBTypedObject"; }
55 #define TBOBJECT_SUBCLASS(clazz, baseclazz) \
56 virtual const char *GetClassName() const { return #clazz; } \
57 virtual bool IsOfTypeId(const tb::TB_TYPE_ID type_id) const \
58 { return GetTypeId<clazz>() == type_id ? true : baseclazz::IsOfTypeId(type_id); }
bool IsOfType() const
Return true if this object can safely be casted to the given type.
Definition: tb_object.h:36
Definition: tb_object.h:21
virtual bool IsOfTypeId(const TB_TYPE_ID type_id) const
Returns true if the class or the base class matches the type id.
Definition: tb_object.h:30
T * SafeCastTo() const
Returns this object as the given type or nullptr if it's not that type.
Definition: tb_object.h:33
T * TBSafeCast(TBTypedObject *obj)
Returns the given object as the given type, or nullptr if it's not that type or if the object is null...
Definition: tb_object.h:44
virtual const char * GetClassName() const
Get the classname of the object.
Definition: tb_object.h:39
static TB_TYPE_ID GetTypeId()
A static template method that returns a unique id for each type.
Definition: tb_object.h:27