Nebula
Loading...
Searching...
No Matches
rttimacros.h File Reference

Detailed Description

This defines the macros for Nebula's RTTI mechanism (__DeclareClass, __ImplementClass, etc...).

Go to the source code of this file.

Macros

#define __DeclareClass(type)
 Declaration macro.
 
#define __DeclareTemplateClass(type, temp)
 
#define __DeclareAbstractClass(class_name)
 
#define __RegisterClass(type)    static const bool type##_registered = type::RegisterWithFactory(); \
 Register a class with the factory.
 
#define __ImplementClass(type, fourcc, baseType)
 Implementation macros for RTTI managed classes.
 
#define __ImplementClassTemplate(type, baseType)
 
#define __ImplementClassVariadicTemplate(type, baseType)
 
#define __ImplementWeakClass(type, fourcc, baseType)
 
#define __ImplementWeakRootClass(type, fourcc)
 
#define __ImplementAbstractClass(type, fourcc, baseType)
 
#define __ImplementAbstractRootClass(type, fourcc)
 
#define __ImplementRootClass(type, fourcc)
 Type implementation of topmost type in inheritance hierarchy (source file).
 
#define __SetupExternalAttributes()
 
#define __ImplementEnumBitOperators(type)
 Neat macro to make enums act as bit flags, be able to check if bits are set, and convert to integers.
 
#define __ImplementEnumComparisonOperators(type)
 
#define __ImplementEnumMutableOperators(type)
 

Macro Definition Documentation

◆ __DeclareAbstractClass

#define __DeclareAbstractClass ( class_name)
Value:
public: \
static Core::Rtti RTTI; \
virtual Core::Rtti* GetRtti() const; \
private:
Nebula's runtime type information for one class.
Definition rtti.h:27

◆ __DeclareClass

#define __DeclareClass ( type)
Value:
public: \
void* operator new(size_t size) \
{ \
return RTTI.AllocInstanceMemory(); \
}; \
void* operator new[](size_t num) \
{ \
return RTTI.AllocInstanceMemoryArray(num); \
}; \
void operator delete(void* p) \
{ \
RTTI.FreeInstanceMemory(p); \
}; \
void operator delete(void* p, void*) \
{ \
}; \
void operator delete[](void* p) \
{ \
RTTI.FreeInstanceMemory(p); \
}; \
static Core::Rtti RTTI; \
static void* FactoryCreator(); \
static void* FactoryArrayCreator(SizeT num); \
static type* Create(); \
static type* CreateArray(SizeT num); \
static bool RegisterWithFactory(); \
virtual Core::Rtti* GetRtti() const; \
private:
Game::ManagerAPI Create()
create the singleton
Definition timemanager.cc:68
int SizeT
Definition types.h:49

Declaration macro.

Put this into the class declaration.

◆ __DeclareTemplateClass

#define __DeclareTemplateClass ( type,
temp )
Value:
public: \
void* operator new(size_t size) \
{ \
}; \
void operator delete(void* p) \
{ \
Memory::Free(Memory::ObjectHeap, p); \
}; \
static type<temp>* Create(); \
static type<temp>* CreateArray(SizeT num); \
private:
void * Alloc(HeapType heapType, size_t size, size_t alignment)
Allocate a block of memory from one of the global heaps.
Definition osxmemory.cc:56
@ ObjectHeap
Definition osxmemoryconfig.h:27

◆ __ImplementAbstractClass

#define __ImplementAbstractClass ( type,
fourcc,
baseType )
Value:
Core::Rtti type::RTTI(#type, fourcc, nullptr, nullptr, &baseType::RTTI, 0); \
Core::Rtti* type::GetRtti() const { return &this->RTTI; }

◆ __ImplementAbstractRootClass

#define __ImplementAbstractRootClass ( type,
fourcc )
Value:
Core::Rtti type::RTTI(#type, fourcc, nullptr, nullptr, nullptr, 0); \
Core::Rtti* type::GetRtti() const { return &this->RTTI; }

◆ __ImplementClass

#define __ImplementClass ( type,
fourcc,
baseType )
Value:
Core::Rtti type::RTTI(#type, fourcc, type::FactoryCreator, type::FactoryArrayCreator, &baseType::RTTI, sizeof(type)); \
Core::Rtti* type::GetRtti() const { return &this->RTTI; } \
void* type::FactoryCreator() { return type::Create(); } \
void* type::FactoryArrayCreator(SizeT num) { return type::CreateArray(num); } \
type* type::Create() \
{ \
static_assert(std::is_base_of<Core::RefCounted, type>::value, "Class must inherit from Core::RefCounted"); \
return new type; \
}\
type* type::CreateArray(SizeT num) \
{ \
static_assert(std::is_base_of<Core::RefCounted, type>::value, "Class must inherit from Core::RefCounted"); \
return new type[num]; \
}\
bool type::RegisterWithFactory() \
{ \
Core::SysFunc::Setup(); \
if (!Core::Factory::Instance()->ClassExists(#type)) \
{ \
Core::Factory::Instance()->Register(&type::RTTI, #type, fourcc); \
} \
return true; \
}
static Factory * Instance()
get pointer to singleton instance (cannot use singleton.h!)
Definition factory.cc:22

Implementation macros for RTTI managed classes.

__ImplementClass constructs a class which relies on reference counting. Use __DeclareClass in header. __ImplementWeakClass constructs a class which does not support reference counting (no garbage collection). Use __DeclareClass in header. __ImplementTemplateClass constructs a class with template arguments but without FourCC or RTTI. Use __DeclareTemplateClass in header.

◆ __ImplementClassTemplate

#define __ImplementClassTemplate ( type,
baseType )
Value:
template <class TEMP> \
inline type<TEMP>* type<TEMP>::Create() \
{ \
type<TEMP>* newObject = new type<TEMP>; \
return newObject; \
} \
template <class TEMP> \
inline type<TEMP>* type<TEMP>::CreateArray(SizeT num) \
{ \
type<TEMP>* newObject = new type<TEMP>[num]; \
return newObject; \
}

◆ __ImplementClassVariadicTemplate

#define __ImplementClassVariadicTemplate ( type,
baseType )
Value:
template <class ... TEMP> \
inline type<TEMP...>* type<TEMP...>::Create() \
{ \
type<TEMP...>* newObject = new type<TEMP...>; \
return newObject; \
} \
template <class ... TEMP> \
inline type<TEMP...>* type<TEMP...>::CreateArray(SizeT num) \
{ \
type<TEMP...>* newObject = new type<TEMP...>[num]; \
return newObject; \
}

◆ __ImplementEnumBitOperators

#define __ImplementEnumBitOperators ( type)
Value:
inline type operator|(type a, type b) { return static_cast<type>(static_cast<unsigned>(a) | static_cast<unsigned>(b)); }\
inline type operator&(type a, type b) { return static_cast<type>(static_cast<unsigned>(a) & static_cast<unsigned>(b)); }\
inline type& operator|=(type& a, type b) { a = static_cast<type>(static_cast<unsigned>(a) | static_cast<unsigned>(b)); return a; }\
inline type& operator&=(type& a, type b) { a = static_cast<type>(static_cast<unsigned>(a) & static_cast<unsigned>(b)); return a; }\
inline type operator|(type a, unsigned b) { return static_cast<type>(static_cast<unsigned>(a) | b); }\
inline type operator&(type a, unsigned b) { return static_cast<type>(static_cast<unsigned>(a) & b); }\
inline type& operator|=(type& a, unsigned b) { a = static_cast<type>(static_cast<unsigned>(a) | b); return a; }\
inline type& operator&=(type& a, unsigned b) { a = static_cast<type>(static_cast<unsigned>(a) & b); return a; }\
inline type operator~(type a) { return static_cast<type>(~static_cast<unsigned>(a)); }\
inline type operator!(type a) { return static_cast<type>(!static_cast<unsigned>(a)); }\
inline unsigned operator|(unsigned a, type b) { return a | static_cast<unsigned>(b); }\
inline unsigned operator&(unsigned a, type b) { return a & static_cast<unsigned>(b); }\
inline unsigned& operator|=(unsigned& a, type b) { a = a | static_cast<unsigned>(b); return a; }\
inline unsigned& operator&=(unsigned& a, type b) { a = a & static_cast<unsigned>(b); return a; }

Neat macro to make enums act as bit flags, be able to check if bits are set, and convert to integers.

◆ __ImplementEnumComparisonOperators

#define __ImplementEnumComparisonOperators ( type)
Value:
inline bool operator>(type a, unsigned b) { return static_cast<unsigned>(a) > b; }\
inline bool operator>(unsigned a, type b) { return a > static_cast<unsigned>(b); }\
inline bool operator>(type a, int b) { return static_cast<int>(a) > b; }\
inline bool operator>(int a, type b) { return a > static_cast<int>(b); }\
inline bool operator<(type a, unsigned b) { return static_cast<unsigned>(a) < b; }\
inline bool operator<(unsigned a, type b) { return a < static_cast<unsigned>(b); }\
inline bool operator<(type a, int b) { return static_cast<unsigned>(a) < b; }\
inline bool operator<(int a, type b) { return a < static_cast<unsigned>(b); }\
inline bool operator>=(type a, unsigned b) { return static_cast<unsigned>(a) >= b; }\
inline bool operator>=(unsigned a, type b) { return a >= static_cast<unsigned>(b); }\
inline bool operator>=(type a, int b) { return static_cast<unsigned>(a) >= b; }\
inline bool operator>=(int a, type b) { return a >= static_cast<unsigned>(b); }\
inline bool operator<=(type a, unsigned b) { return static_cast<unsigned>(a) <= b; }\
inline bool operator<=(unsigned a, type b) { return a <= static_cast<unsigned>(b); }\
inline bool operator<=(type a, int b) { return static_cast<unsigned>(a) <= b; }\
inline bool operator<=(int a, type b) { return a <= static_cast<unsigned>(b); }\
inline bool operator==(type a, unsigned b) { return static_cast<unsigned>(a) == b; }\
inline bool operator==(unsigned a, type b) { return a == static_cast<unsigned>(b); }\
inline bool operator==(type a, int b) { return static_cast<unsigned>(a) == b; }\
inline bool operator==(int a, type b) { return a == static_cast<unsigned>(b); }\
inline bool operator!=(type a, unsigned b) { return static_cast<unsigned>(a) != b; }\
inline bool operator!=(unsigned a, type b) { return a != static_cast<unsigned>(b); }\
inline bool operator!=(type a, int b) { return static_cast<unsigned>(a) != b; }\
inline bool operator!=(int a, type b) { return a != static_cast<unsigned>(b); }
bool operator>(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:283
bool operator<(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:277
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:272
bool operator<=(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:284
bool operator!=(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:282
bool operator>=(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:285

◆ __ImplementEnumMutableOperators

#define __ImplementEnumMutableOperators ( type)
Value:
inline type operator++(type a) { return static_cast<type>(static_cast<unsigned>(a)++); }\
inline type operator--(type a) { return static_cast<type>(static_cast<unsigned>(a)--); }

◆ __ImplementRootClass

#define __ImplementRootClass ( type,
fourcc )
Value:
Core::Rtti type::RTTI(#type, fourcc, type::FactoryCreator, type::FactoryArrayCreator, nullptr, sizeof(type)); \
Core::Rtti* type::GetRtti() const { return &this->RTTI; } \
void* type::FactoryCreator() { return type::Create(); } \
void* type::FactoryArrayCreator(SizeT num) { return type::CreateArray(num); } \
type* type::Create() \
{ \
static_assert(std::is_base_of<Core::RefCounted, type>::value, "Class must inherit from Core::RefCounted"); \
return new type; \
}\
type* type::CreateArray(SizeT num) \
{ \
static_assert(std::is_base_of<Core::RefCounted, type>::value, "Class must inherit from Core::RefCounted"); \
return new type[num]; \
}\
bool type::RegisterWithFactory() \
{ \
if (!Core::Factory::Instance()->ClassExists(#type)) \
{ \
Core::Factory::Instance()->Register(&type::RTTI, #type, fourcc); \
} \
return true; \
}

Type implementation of topmost type in inheritance hierarchy (source file).

◆ __ImplementWeakClass

#define __ImplementWeakClass ( type,
fourcc,
baseType )
Value:
Core::Rtti type::RTTI(#type, fourcc, type::FactoryCreator, type::FactoryArrayCreator, &baseType::RTTI, sizeof(type)); \
Core::Rtti* type::GetRtti() const { return &this->RTTI; } \
void* type::FactoryCreator() { return type::Create(); } \
void* type::FactoryArrayCreator(SizeT num) { return type::CreateArray(num); } \
type* type::Create() \
{ \
type* newObject = new type; \
return newObject; \
}\
type* type::CreateArray(SizeT num) \
{ \
type* newObject = new type[num]; \
return newObject; \
}\
bool type::RegisterWithFactory() \
{ \
Core::SysFunc::Setup(); \
if (!Core::Factory::Instance()->ClassExists(#type)) \
{ \
Core::Factory::Instance()->Register(&type::RTTI, #type, fourcc); \
} \
return true; \
}

◆ __ImplementWeakRootClass

#define __ImplementWeakRootClass ( type,
fourcc )
Value:
Core::Rtti type::RTTI(#type, fourcc, type::FactoryCreator, type::FactoryArrayCreator, nullptr, sizeof(type)); \
Core::Rtti* type::GetRtti() const { return &this->RTTI; } \
void* type::FactoryCreator() { return type::Create(); } \
void* type::FactoryArrayCreator(SizeT num) { return type::CreateArray(num); } \
type* type::Create() \
{ \
type* newObject = new type; \
return newObject; \
}\
type* type::CreateArray(SizeT num) \
{ \
type* newObject = new type[num]; \
return newObject; \
}\
bool type::RegisterWithFactory() \
{ \
Core::SysFunc::Setup(); \
if (!Core::Factory::Instance()->ClassExists(#type)) \
{ \
Core::Factory::Instance()->Register(&type::RTTI, #type, fourcc); \
} \
return true; \
}

◆ __RegisterClass

#define __RegisterClass ( type)     static const bool type##_registered = type::RegisterWithFactory(); \

Register a class with the factory.

This is only necessary for classes which can create objects by name or fourcc.

◆ __SetupExternalAttributes

#define __SetupExternalAttributes ( )
Value:
public: \
virtual void SetupExternalAttributes(); \
private: