Orxonox  0.0.5 Codename: Arcturus
Classes | Namespaces | Macros | Typedefs | Functions

Defines several very important macros used to register objects, register classes, and to work with identifiers. More...

#include "CorePrereqs.h"
#include "util/Output.h"
#include "class/IdentifierManager.h"
#include "object/ClassFactory.h"
#include "object/ObjectList.h"
#include "module/StaticallyInitializedInstance.h"

Go to the source code of this file.

Classes

class  orxonox::StaticallyInitializedIdentifier
 The static initializer stores the parent classes of this identifier. More...
 
struct  orxonox::StaticallyInitializedIdentifier::InheritsFromClass< T >
 

Namespaces

 orxonox
 Die Wagnis Klasse hat die folgenden Aufgaben:
 

Macros

#define Class(ClassName)   orxonox::ClassIdentifier<ClassName>::getIdentifier()
 Returns the Identifier of the given class. More...
 
#define RegisterAbstractClass(ClassName)   RegisterClassWithFactory(ClassName, static_cast<ClassFactory<ClassName>*>(nullptr), false)
 Registers an abstract class in the framework. More...
 
#define RegisterClass(ClassName)   RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), true)
 Registers the class in the framework. More...
 
#define RegisterClassNoArgs(ClassName)   RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryNoArgs<ClassName>(), true)
 Registers the class in the framework (for classes without arguments in their constructor). More...
 
#define RegisterClassWithFactory(ClassName, FactoryInstance, bLoadable)   orxonox::SI_I& _##ClassName##Identifier = (*new orxonox::SI_I(orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)))
 Registers the class in the framework with a given Factory. More...
 
#define RegisterObject(ClassName)
 Registers a newly created object in the framework. More...
 
#define RegisterUnloadableClass(ClassName)   RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), false)
 Registers the class in the framework (for classes which should not be loaded through XML). More...
 

Typedefs

typedef StaticallyInitializedIdentifier orxonox::SI_I
 

Functions

Identifier * orxonox::ClassByID (uint32_t id)
 Returns the Identifier with a given network ID. More...
 
Identifier * orxonox::ClassByLowercaseString (const std::string &name)
 Returns the Identifier with a given lowercase name. More...
 
template<class T >
Identifier * orxonox::ClassByObjectType (const T *p)
 Returns the Identifier with a given 'this' pointer. More...
 
Identifier * orxonox::ClassByString (const std::string &name)
 Returns the Identifier with a given name. More...
 
template<class T >
Identifier * orxonox::registerClass (const std::string &name, ClassFactory< T > *factory, bool bLoadable=true)
 Overload of registerClass() which determines T implicitly by the template argument of the ClassFactory. More...
 
template<class T >
Identifier * orxonox::registerClass (const std::string &name, Factory *factory, bool bLoadable=true)
 Registers a class in the framework. More...
 

Detailed Description

Defines several very important macros used to register objects, register classes, and to work with identifiers.

Every class needs the RegisterObject(class) macro in its constructor.

To register class in the class-hierarchy, use the RegisterClass(class) macro outside of the class implementation, so it gets executed statically before main(). If you don't want class to be loadable, but still register it, call RegisterUnloadableClass(class).

Abstract classes are registered with RegisterAbstractClass(class). For abstract classes, the inheritance must be defined manually with RegisterAbstractClass(class).inheritsFrom(Class(parent)). Multiple parent classes can be defined by chaining the above command.

Example:

// register MyClass
RegisterClass(MyClass);
// Constructor:
MyClass::MyClass()
{
// Register the object in the Identifier of MyClass
RegisterObject(MyClass);
}

This file also defines a number of other useful macros, like, for example, Class(class) which returns the Identifier of class, or ClassByString("class") which returns the Identifier of a class with name "class".

Example:

// Assigns the Identifier of MyClass
Identifier* identifier = Class(MyClass);
// Assigns the Identifier of a class named "MyClass"
Identifier* identifier = ClassByString("MyClass");

Macro Definition Documentation

#define Class (   ClassName)    orxonox::ClassIdentifier<ClassName>::getIdentifier()

Returns the Identifier of the given class.

Parameters
ClassNameThe name of the class
#define RegisterAbstractClass (   ClassName)    RegisterClassWithFactory(ClassName, static_cast<ClassFactory<ClassName>*>(nullptr), false)

Registers an abstract class in the framework.

Should be used in combination with inheritsFrom(base-class-identifier).

Parameters
ClassNameThe name of the class
#define RegisterClass (   ClassName)    RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), true)

Registers the class in the framework.

Parameters
ClassNameThe name of the class
#define RegisterClassNoArgs (   ClassName)    RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryNoArgs<ClassName>(), true)

Registers the class in the framework (for classes without arguments in their constructor).

Parameters
ClassNameThe name of the class
#define RegisterClassWithFactory (   ClassName,
  FactoryInstance,
  bLoadable 
)    orxonox::SI_I& _##ClassName##Identifier = (*new orxonox::SI_I(orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)))

Registers the class in the framework with a given Factory.

Parameters
ClassNameThe name of the class
FactoryInstanceAn instance of a factory that can create the class
bLoadableWhether the class is allowed to be loaded through XML
#define RegisterObject (   ClassName)
Value:
if (ClassIdentifier<ClassName>::getIdentifier()->initializeObject(this)) \
return; \
else \
((void)0)
typedef void(ENET_CALLBACK *ENetPacketFreeCallback)(struct _ENetPacket *)

Registers a newly created object in the framework.

Has to be called at the beginning of the constructor of ClassName.

Parameters
ClassNameThe name of the class
#define RegisterUnloadableClass (   ClassName)    RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), false)

Registers the class in the framework (for classes which should not be loaded through XML).

Parameters
ClassNameThe name of the class