[Orxonox-commit 5700] r10360 - in code/branches/core7: src/libraries/core test/core/class
landauf at orxonox.net
landauf at orxonox.net
Sun Apr 12 21:41:22 CEST 2015
Author: landauf
Date: 2015-04-12 21:41:22 +0200 (Sun, 12 Apr 2015)
New Revision: 10360
Modified:
code/branches/core7/src/libraries/core/CoreIncludes.h
code/branches/core7/test/core/class/IdentifierClassHierarchyTest.cc
code/branches/core7/test/core/class/IdentifierExternalClassHierarchyTest.cc
code/branches/core7/test/core/class/IdentifierSimpleClassHierarchyTest.cc
Log:
wrap Identifiers in a StaticallyInitializedInstance. doesn't do a lot at the moment
Modified: code/branches/core7/src/libraries/core/CoreIncludes.h
===================================================================
--- code/branches/core7/src/libraries/core/CoreIncludes.h 2015-04-12 13:28:15 UTC (rev 10359)
+++ code/branches/core7/src/libraries/core/CoreIncludes.h 2015-04-12 19:41:22 UTC (rev 10360)
@@ -83,6 +83,7 @@
#include "class/IdentifierManager.h"
#include "object/ClassFactory.h"
#include "object/ObjectList.h"
+#include "module/StaticallyInitializedInstance.h"
// resolve macro conflict on windows
#if defined(ORXONOX_PLATFORM_WINDOWS)
@@ -125,7 +126,7 @@
@param ClassName The name of the class
*/
#define RegisterClassWithFactory(ClassName, FactoryInstance, bLoadable) \
- Identifier& _##ClassName##Identifier = orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)
+ Identifier& _##ClassName##Identifier = (new orxonox::SI_I(orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)))->getIdentifier()
/**
@brief Registers a newly created object in the framework. Has to be called at the beginning of the constructor of @a ClassName.
@@ -151,7 +152,7 @@
* @brief Overload of registerClass() which determines T implicitly by the template argument of the ClassFactory.
*/
template <class T>
- inline Identifier& registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true)
+ inline Identifier* registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true)
{
return registerClass<T>(name, static_cast<Factory*>(factory), bLoadable);
}
@@ -163,13 +164,13 @@
* @param bLoadable Whether the class is allowed to be loaded through XML
*/
template <class T>
- inline Identifier& registerClass(const std::string& name, Factory* factory, bool bLoadable = true)
+ inline Identifier* registerClass(const std::string& name, Factory* factory, bool bLoadable = true)
{
orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;
Identifier* identifier = ClassIdentifier<T>::getIdentifier(name);
identifier->setFactory(factory);
identifier->setLoadable(bLoadable);
- return *identifier;
+ return identifier;
}
/**
@@ -210,6 +211,22 @@
{
return ClassIdentifier<T>::getIdentifier();
}
+
+ class _CoreExport StaticallyInitializedIdentifier : public StaticallyInitializedInstance
+ {
+ public:
+ StaticallyInitializedIdentifier(Identifier* identifier) : identifier_(identifier) {}
+
+ virtual void load() {}
+
+ inline Identifier& getIdentifier()
+ { return *this->identifier_; }
+
+ private:
+ Identifier* identifier_;
+ };
+
+ typedef StaticallyInitializedIdentifier SI_I;
}
#endif /* _CoreIncludes_H__ */
Modified: code/branches/core7/test/core/class/IdentifierClassHierarchyTest.cc
===================================================================
--- code/branches/core7/test/core/class/IdentifierClassHierarchyTest.cc 2015-04-12 13:28:15 UTC (rev 10359)
+++ code/branches/core7/test/core/class/IdentifierClassHierarchyTest.cc 2015-04-12 19:41:22 UTC (rev 10360)
@@ -12,9 +12,9 @@
// +---------------------+-+- Class2b
// +-+-+-- Class3 | |
// | | | |
- // BaseInterface1 <--+---- Interface1 <--´ |
+ // BaseInterface1 <--+---- Interface1 <--´ |
// | |
- // BaseInterface2 <----+-- Interface2 <----´
+ // BaseInterface2 <----+-- Interface2 <----´
namespace
{
@@ -134,10 +134,10 @@
registerClass("Configurable", new ClassFactoryNoArgs<Configurable>());
registerClass("OrxonoxInterface", new ClassFactoryNoArgs<OrxonoxInterface>());
registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>());
- registerClass("BaseInterface1", static_cast<ClassFactory<BaseInterface1>*>(NULL), false).inheritsFrom(Class(OrxonoxInterface));
- registerClass("BaseInterface2", static_cast<ClassFactory<BaseInterface2>*>(NULL), false).inheritsFrom(Class(OrxonoxInterface));
- registerClass("Interface1", static_cast<ClassFactory<Interface1>*>(NULL), false).inheritsFrom(Class(BaseInterface1));
- registerClass("Interface2", static_cast<ClassFactory<Interface2>*>(NULL), false).inheritsFrom(Class(BaseInterface2));
+ registerClass("BaseInterface1", static_cast<ClassFactory<BaseInterface1>*>(NULL), false)->inheritsFrom(Class(OrxonoxInterface));
+ registerClass("BaseInterface2", static_cast<ClassFactory<BaseInterface2>*>(NULL), false)->inheritsFrom(Class(OrxonoxInterface));
+ registerClass("Interface1", static_cast<ClassFactory<Interface1>*>(NULL), false)->inheritsFrom(Class(BaseInterface1));
+ registerClass("Interface2", static_cast<ClassFactory<Interface2>*>(NULL), false)->inheritsFrom(Class(BaseInterface2));
registerClass("BaseClass", new ClassFactoryNoArgs<BaseClass>());
registerClass("Class0", new ClassFactoryNoArgs<Class0>());
registerClass("Class1", new ClassFactoryNoArgs<Class1>());
Modified: code/branches/core7/test/core/class/IdentifierExternalClassHierarchyTest.cc
===================================================================
--- code/branches/core7/test/core/class/IdentifierExternalClassHierarchyTest.cc 2015-04-12 13:28:15 UTC (rev 10359)
+++ code/branches/core7/test/core/class/IdentifierExternalClassHierarchyTest.cc 2015-04-12 19:41:22 UTC (rev 10360)
@@ -45,7 +45,7 @@
{
registerClass("Context", new ClassFactoryWithContext<Context>());
registerClass("Listable", new ClassFactoryWithContext<Listable>());
- registerClass("Interface", static_cast<ClassFactory<Interface>*>(NULL), false).inheritsFrom(Class(Identifiable));
+ registerClass("Interface", static_cast<ClassFactory<Interface>*>(NULL), false)->inheritsFrom(Class(Identifiable));
registerClass("BaseClass", new ClassFactoryNoArgs<BaseClass>());
registerClass("RealClass", new ClassFactoryNoArgs<RealClass>());
Modified: code/branches/core7/test/core/class/IdentifierSimpleClassHierarchyTest.cc
===================================================================
--- code/branches/core7/test/core/class/IdentifierSimpleClassHierarchyTest.cc 2015-04-12 13:28:15 UTC (rev 10359)
+++ code/branches/core7/test/core/class/IdentifierSimpleClassHierarchyTest.cc 2015-04-12 19:41:22 UTC (rev 10360)
@@ -50,7 +50,7 @@
registerClass("Configurable", new ClassFactoryNoArgs<Configurable>());
registerClass("OrxonoxInterface", new ClassFactoryNoArgs<OrxonoxInterface>());
registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>());
- registerClass("Interface", static_cast<ClassFactory<Interface>*>(NULL), false).inheritsFrom(Class(OrxonoxInterface));
+ registerClass("Interface", static_cast<ClassFactory<Interface>*>(NULL), false)->inheritsFrom(Class(OrxonoxInterface));
registerClass("BaseClass", new ClassFactoryNoArgs<BaseClass>());
registerClass("RealClass", new ClassFactoryNoArgs<RealClass>());
More information about the Orxonox-commit
mailing list