Nebula
Loading...
Searching...
No Matches
Core::Factory Class Reference

#include <factory.h>

Detailed Description

Provides the central object factory mechanism for Nebula.

Classes which are derived from RefCounted register themselves automatically to the central Factory object through the __DeclareClass and __ImplementClass macros.

Public Member Functions

void Register (const Rtti *rtti, const Util::String &className, const Util::FourCC &classFourCC)
 register a RTTI object with the factory (with class name and class fourcc code)
 
void Register (const Rtti *rtti, const Util::String &className)
 register a RTTI object with the factory (without fourcc code)
 
bool ClassExists (const Util::String &className) const
 check if a class exists by class name
 
bool ClassExists (const Util::FourCC classFourCC) const
 check if a class exists by FourCC code
 
const RttiGetClassRtti (const Util::String &className) const
 get class rtti object by name
 
const RttiGetClassRtti (const Util::FourCC &classFourCC) const
 get class rtti object by fourcc code
 
void * Create (const Util::String &className) const
 create an object by class name
 
void * Create (const Util::FourCC classFourCC) const
 create an object by FourCC code
 
void * CreateArray (const Util::String &className, SizeT num) const
 create an array of objects by class name
 
void * CreateArray (const Util::FourCC classFourCC, SizeT num) const
 create an array object by FourCC code
 

Static Public Member Functions

static FactoryInstance ()
 get pointer to singleton instance (cannot use singleton.h!)
 
static void Destroy ()
 static instance destruction method
 

Private Member Functions

 Factory ()
 constructor is private
 
 ~Factory ()
 destructor is private
 

Private Attributes

Util::HashTable< Util::String, const Rtti *, 1024 > nameTable
 
Util::Dictionary< Util::FourCC, const Rtti * > fourccTable
 

Static Private Attributes

static FactorySingleton = 0
 

Constructor & Destructor Documentation

◆ Factory()

Core::Factory::Factory ( )
private

constructor is private

The factory's constructor is private so that it may only be called by Factory::Instance().

◆ ~Factory()

Core::Factory::~Factory ( )
private

destructor is private

The factory's destructor is private so that it may only be called by Factory::Destroy().

Member Function Documentation

◆ ClassExists() [1/2]

bool Core::Factory::ClassExists ( const Util::FourCC classFourCC) const

check if a class exists by FourCC code

This method checks if a class with the given fourcc code has been registered.

◆ ClassExists() [2/2]

bool Core::Factory::ClassExists ( const Util::String & className) const

check if a class exists by class name

This method checks if a class with the given name has been registered.

◆ Create() [1/2]

void * Core::Factory::Create ( const Util::FourCC classFourCC) const

create an object by FourCC code

Create an object by FourCC code.

◆ Create() [2/2]

void * Core::Factory::Create ( const Util::String & className) const

create an object by class name

Create an object by class name.

◆ CreateArray() [1/2]

void * Core::Factory::CreateArray ( const Util::FourCC classFourCC,
SizeT num ) const

create an array object by FourCC code

Create an object by FourCC code.

◆ CreateArray() [2/2]

void * Core::Factory::CreateArray ( const Util::String & className,
SizeT num ) const

create an array of objects by class name

Create an object by string name.

◆ Destroy()

void Core::Factory::Destroy ( )
static

static instance destruction method

This static method is used to destroy the factory object and should be called right before the main function exits.

It will make sure that no accidential memory leaks are reported by the debug heap.

◆ GetClassRtti() [1/2]

const Rtti * Core::Factory::GetClassRtti ( const Util::FourCC & classFourCC) const

get class rtti object by fourcc code

◆ GetClassRtti() [2/2]

const Rtti * Core::Factory::GetClassRtti ( const Util::String & className) const

get class rtti object by name

◆ Instance()

Factory * Core::Factory::Instance ( )
static

get pointer to singleton instance (cannot use singleton.h!)

The factory's constructor is called by the Instance() method, and nobody else.

◆ Register() [1/2]

void Core::Factory::Register ( const Rtti * rtti,
const Util::String & className )

register a RTTI object with the factory (without fourcc code)

Legacy version of Register() which doesn't require a class fourcc code.

This is for compatibility with old Mangalore applications.

◆ Register() [2/2]

void Core::Factory::Register ( const Rtti * rtti,
const Util::String & className,
const Util::FourCC & classFourCC )

register a RTTI object with the factory (with class name and class fourcc code)

This registers an Rtti object with the factory and is called from an Rtti object's constructor.

The function will fail with an error message box if a class with an identical class name or fourcc code has already been registered.

NOTE: we cannot use the class name of fourcc from the RTTI object, because it may be that the RTTI object hasn't been initialized yet when this method is called (initialization order of global variables is undefined).

Member Data Documentation

◆ fourccTable

Util::Dictionary<Util::FourCC, const Rtti*> Core::Factory::fourccTable
private

◆ nameTable

Util::HashTable<Util::String, const Rtti*, 1024> Core::Factory::nameTable
private

◆ Singleton

Factory * Core::Factory::Singleton = 0
staticprivate

The documentation for this class was generated from the following files: