Nebula
Loading...
Searching...
No Matches
rtti.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
16#include "core/types.h"
17#include "core/factory.h"
18#include "core/sysfunc.h"
19#include "util/string.h"
20#include "util/fourcc.h"
21
22//------------------------------------------------------------------------------
23namespace Core
24{
25class RefCounted;
26class Rtti
27{
28public:
30 typedef void* (*Creator)();
31 typedef void* (*ArrayCreator)(SizeT);
32
34 Rtti(const char* className, Util::FourCC fcc, Creator creatorFunc, ArrayCreator arrayCreatorFunc, const Core::Rtti* parentClass, SizeT instSize);
36 Rtti(const char* className, Creator creatorFunc, ArrayCreator arrayCreatorFunc, const Core::Rtti* parentClass, SizeT instSize);
38 bool operator==(const Rtti& rhs) const;
40 bool operator!=(const Rtti& rhs) const;
42 const Util::String& GetName() const;
44 Util::FourCC GetFourCC() const;
46 const Core::Rtti* GetParent() const;
48 SizeT GetInstanceSize() const;
50 void* Create() const;
52 void* CreateArray(SizeT num) const;
54 bool IsDerivedFrom(const Rtti& other) const;
56 bool IsDerivedFrom(const Util::String& otherClassName) const;
58 bool IsDerivedFrom(const Util::FourCC& otherClassFourCC) const;
60 void* AllocInstanceMemory();
62 void* AllocInstanceMemoryArray(size_t num);
64 void FreeInstanceMemory(void* ptr);
65
66private:
68 void Construct(const char* className, Util::FourCC fcc, Creator creatorFunc, ArrayCreator arrayCreatorFunc, const Core::Rtti* parentClass, SizeT instSize);
69
76};
77
78//------------------------------------------------------------------------------
81inline bool
82Rtti::operator==(const Rtti& rhs) const
83{
84 return this == &rhs;
85}
86
87//------------------------------------------------------------------------------
90inline bool
91Rtti::operator!=(const Rtti& rhs) const
92{
93 return this != &rhs;
94}
95
96//------------------------------------------------------------------------------
99inline const Util::String&
101{
102 return this->name;
103}
104
105//------------------------------------------------------------------------------
108inline Util::FourCC
110{
111 return this->fourCC;
112}
113
114//------------------------------------------------------------------------------
117inline const Core::Rtti*
119{
120 return this->parent;
121}
122
123//------------------------------------------------------------------------------
126inline SizeT
128{
129 return this->instanceSize;
130}
131
132#include "core/rttimacros.h"
133
134} // namespace Core
135//------------------------------------------------------------------------------
Nebula's runtime type information for one class.
Definition rtti.h:27
Creator creator
Definition rtti.h:74
void * AllocInstanceMemoryArray(size_t num)
allocate instance memory array block (called by class new operator)
Definition rtti.cc:196
Util::FourCC GetFourCC() const
get four character code of class
Definition rtti.h:109
void *(*) ArrayCreator(SizeT)
Definition rtti.h:31
void Construct(const char *className, Util::FourCC fcc, Creator creatorFunc, ArrayCreator arrayCreatorFunc, const Core::Rtti *parentClass, SizeT instSize)
constructor method, called from the various constructors
Definition rtti.cc:18
void *(*) Creator()
define a creation callback function prototype
Definition rtti.h:30
SizeT instanceSize
Definition rtti.h:73
Util::FourCC fourCC
Definition rtti.h:72
SizeT GetInstanceSize() const
get instance size in bytes
Definition rtti.h:127
const Core::Rtti * GetParent() const
get pointer to parent class
Definition rtti.h:118
bool IsDerivedFrom(const Rtti &other) const
return true if this rtti is equal or derived from to other rtti
Definition rtti.cc:135
Rtti(const char *className, Util::FourCC fcc, Creator creatorFunc, ArrayCreator arrayCreatorFunc, const Core::Rtti *parentClass, SizeT instSize)
constructor
Definition rtti.cc:84
void FreeInstanceMemory(void *ptr)
free instance memory block (called by class delete operator)
Definition rtti.cc:206
bool operator==(const Rtti &rhs) const
equality operator
Definition rtti.h:82
Util::String name
Definition rtti.h:70
const Util::String & GetName() const
get class name
Definition rtti.h:100
void * CreateArray(SizeT num) const
create an array of objects of this class
Definition rtti.cc:118
ArrayCreator arrayCreator
Definition rtti.h:75
bool operator!=(const Rtti &rhs) const
inequality operator
Definition rtti.h:91
const Core::Rtti * parent
Definition rtti.h:71
void * AllocInstanceMemory()
allocate instance memory block (called by class new operator)
Definition rtti.cc:186
void * Create() const
create an object of this class
Definition rtti.cc:101
A four-character-code is a quasi-human-readable 32-bit-id.
Definition fourcc.h:19
Definition coreserver.cc:11
This defines the macros for Nebula's RTTI mechanism (__DeclareClass, __ImplementClass,...
Nebula's universal string class.
Definition string.h:50
int SizeT
Definition types.h:49