[365] | 1 | /** |
---|
| 2 | @file IDentifierIncludes.h |
---|
| 3 | @brief Definition of macros for the class-hierarchy and the factory. |
---|
| 4 | |
---|
| 5 | Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface |
---|
| 6 | or the BaseObject itself, it needs the macro RegisterRootObject(class) instead. |
---|
| 7 | |
---|
| 8 | To allow the object being created through the factory, use the CreateFactory(class) macro outside |
---|
| 9 | the of the class implementation, so it gets executed before main(). |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | // All needed header-files |
---|
[197] | 13 | #include "Identifier.h" |
---|
[218] | 14 | #include "Factory.h" |
---|
[244] | 15 | #include "ClassFactory.h" |
---|
[221] | 16 | #include "Iterator.h" |
---|
[197] | 17 | #include "OrxonoxClass.h" |
---|
[434] | 18 | #include "ConfigValueContainer.h" |
---|
[219] | 19 | |
---|
[434] | 20 | #include "OgreVector3.h" |
---|
| 21 | #include "OgreColourValue.h" |
---|
[219] | 22 | |
---|
[434] | 23 | namespace orxonox |
---|
| 24 | { |
---|
| 25 | typedef Ogre::Vector3 Vector3; |
---|
| 26 | typedef Ogre::ColourValue ColourValue; |
---|
| 27 | } |
---|
| 28 | |
---|
[365] | 29 | // Intern macro, containing the common parts of RegisterObject and RegisterRootObject |
---|
[244] | 30 | #define InternRegisterObject(ClassName, bRootClass) \ |
---|
| 31 | this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, bRootClass)); \ |
---|
[219] | 32 | if (Identifier::isCreatingHierarchy() && this->getParents()) \ |
---|
| 33 | this->getParents()->add(this->getIdentifier()); \ |
---|
[224] | 34 | ClassIdentifier<ClassName>::addObject(this) |
---|
[219] | 35 | |
---|
[365] | 36 | // Intern macro, containing the specific part of RegisterRootObject |
---|
[244] | 37 | #define InternRegisterRootObject(ClassName) \ |
---|
| 38 | if (Identifier::isCreatingHierarchy() && !this->getParents()) \ |
---|
| 39 | this->setParents(new IdentifierList()); \ |
---|
| 40 | InternRegisterObject(ClassName, true) |
---|
[220] | 41 | |
---|
[365] | 42 | // RegisterObject - with and without debug output |
---|
[231] | 43 | #if HIERARCHY_VERBOSE |
---|
[244] | 44 | #define RegisterObject(ClassName) \ |
---|
[219] | 45 | std::cout << "*** Register Object: " << #ClassName << "\n"; \ |
---|
[244] | 46 | InternRegisterObject(ClassName, false) |
---|
[231] | 47 | #else |
---|
[244] | 48 | #define RegisterObject(ClassName) \ |
---|
| 49 | InternRegisterObject(ClassName, false) |
---|
[231] | 50 | #endif |
---|
[219] | 51 | |
---|
[365] | 52 | // RegisterRootObject - with and without debug output |
---|
[231] | 53 | #if HIERARCHY_VERBOSE |
---|
[244] | 54 | #define RegisterRootObject(ClassName) \ |
---|
| 55 | std::cout << "*** Register Root-Object: " << #ClassName << "\n"; \ |
---|
| 56 | InternRegisterRootObject(ClassName) |
---|
[231] | 57 | #else |
---|
[244] | 58 | #define RegisterRootObject(ClassName) \ |
---|
| 59 | InternRegisterRootObject(ClassName) |
---|
[231] | 60 | #endif |
---|
[219] | 61 | |
---|
[365] | 62 | // Class(ClassName) returns the Identifier of the given class |
---|
[219] | 63 | #define Class(ClassName) \ |
---|
| 64 | ClassIdentifier<ClassName>::getIdentifier() |
---|
| 65 | |
---|
[365] | 66 | // Creates the entry in the Factory |
---|
[219] | 67 | #define CreateFactory(ClassName) \ |
---|
[244] | 68 | bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create() |
---|
[219] | 69 | |
---|
[365] | 70 | // ID(StringOrInt) returns the Identifier with either a given name or a given NetworkID through the factory |
---|
| 71 | #define ID(StringOrInt) \ |
---|
| 72 | Factory::getIdentifier(StringOrInt) |
---|
[434] | 73 | |
---|
| 74 | // bla |
---|
| 75 | #define SetConfigValue(varname, defvalue) \ |
---|
| 76 | ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \ |
---|
| 77 | if (!container##varname) \ |
---|
| 78 | { \ |
---|
| 79 | container##varname = new ConfigValueContainer(this->getIdentifier()->getName(), #varname, defvalue); \ |
---|
| 80 | this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \ |
---|
| 81 | } \ |
---|
| 82 | this->varname = container##varname->getValue(varname) |
---|