Changeset 9667 for code/trunk/src/libraries/core
- Timestamp:
- Aug 25, 2013, 9:08:42 PM (11 years ago)
- Location:
- code/trunk
- Files:
-
- 25 deleted
- 74 edited
- 7 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core6 merged: 9552-9554,9556-9574,9577-9579,9585-9593,9596-9612,9626-9662
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/BaseObject.cc
r8858 r9667 39 39 #include "Event.h" 40 40 #include "EventIncludes.h" 41 #include "Iterator.h"42 41 #include "Template.h" 43 42 #include "XMLFile.h" … … 45 44 #include "XMLPort.h" 46 45 #include "command/Functor.h" 46 #include "object/Iterator.h" 47 48 #include "class/OrxonoxInterface.h" // we include this only to include OrxonoxInterface.h at least once in core to keep MSVC happy... 47 49 48 50 namespace orxonox 49 51 { 50 CreateFactory(BaseObject);52 RegisterClass(BaseObject); 51 53 52 54 /** 53 55 @brief Constructor: Registers the object in the BaseObject-list. 54 56 */ 55 BaseObject::BaseObject( BaseObject* creator) : bInitialized_(false)56 { 57 Register RootObject(BaseObject);57 BaseObject::BaseObject(Context* context) : bInitialized_(false) 58 { 59 RegisterObject(BaseObject); 58 60 59 61 this->bInitialized_ = true; … … 68 70 this->mainStateFunctor_ = 0; 69 71 72 if (context) 73 this->setContext(context); 74 75 BaseObject* creator = orxonox_cast<BaseObject*>(context); 70 76 this->setCreator(creator); 71 77 if (this->creator_) … … 199 205 { 200 206 this->networkTemplateNames_.insert(temp->getLink()); 201 207 202 208 Template* link; 203 209 assert(!(link = Template::getTemplate(temp->getLink())) || !link->isLink()); -
code/trunk/src/libraries/core/BaseObject.h
r7401 r9667 49 49 50 50 #include "util/mbool.h" 51 #include " OrxonoxClass.h"52 #include " Super.h"53 #include " SmartPtr.h"51 #include "class/OrxonoxClass.h" 52 #include "class/Super.h" 53 #include "object/SmartPtr.h" 54 54 55 55 namespace orxonox … … 60 60 61 61 /// The BaseObject is the parent of all classes representing an instance in the game. 62 class _CoreExport BaseObject : virtualpublic OrxonoxClass62 class _CoreExport BaseObject : public OrxonoxClass 63 63 { 64 64 template <class T> friend class XMLPortClassParamContainer; 65 65 66 66 public: 67 BaseObject( BaseObject* creator);67 BaseObject(Context* context); 68 68 virtual ~BaseObject(); 69 69 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); -
code/trunk/src/libraries/core/CMakeLists.txt
r8858 r9667 22 22 #BUILD_UNIT CoreStableBuildUnit.cc 23 23 ClassTreeMask.cc 24 CommandLineParser.cc25 ConfigValueContainer.cc26 24 DynLib.cc 27 25 DynLibManager.cc … … 30 28 GameMode.cc 31 29 GameState.cc 32 Identifier.cc33 30 Language.cc 34 31 Loader.cc 35 32 LuaState.cc 36 MetaObjectList.cc37 33 Namespace.cc 38 34 NamespaceNode.cc 39 ObjectListBase.cc40 OrxonoxClass.cc41 35 Template.cc 42 36 ViewportEventListener.cc … … 57 51 BUILD_UNIT FilesystemBuildUnit.cc 58 52 command/ArgumentCompletionFunctions.cc 59 ConfigFileManager.cc53 config/ConfigFile.cc 60 54 PathConfig.cc 61 55 END_BUILD_UNIT … … 68 62 ) 69 63 64 ADD_SUBDIRECTORY(class) 70 65 ADD_SUBDIRECTORY(command) 66 ADD_SUBDIRECTORY(config) 71 67 ADD_SUBDIRECTORY(input) 68 ADD_SUBDIRECTORY(object) 72 69 73 70 ORXONOX_ADD_LIBRARY(core … … 75 72 TOLUA_FILES 76 73 command/CommandExecutor.h 77 ConfigFileManager.h74 config/SettingsConfigFile.h 78 75 Game.h 79 76 GameMode.h -
code/trunk/src/libraries/core/ClassTreeMask.cc
r7401 r9667 33 33 34 34 #include "ClassTreeMask.h" 35 #include " Identifier.h"35 #include "class/Identifier.h" 36 36 37 37 namespace orxonox … … 849 849 // If there is a first subclass, move the object-iterator to the first object of this class. Else go to the end 850 850 if (this->subclassIterator_ != this->subclasses_.end()) 851 this->objectIterator_ = this->subclassIterator_->first->getObjects()->begin();851 this->objectIterator_ = Context::getRootContext()->getObjectList(this->subclassIterator_->first)->begin(); 852 852 else 853 853 this->objectIterator_ = ObjectList<BaseObject>::end(); … … 881 881 // Check if there really is a next class. If yes, move the object-iterator to the first object 882 882 if (this->subclassIterator_ != this->subclasses_.end()) 883 this->objectIterator_ = this->subclassIterator_->first->getObjects()->begin();883 this->objectIterator_ = Context::getRootContext()->getObjectList(this->subclassIterator_->first)->begin(); 884 884 else 885 885 return (*this); -
code/trunk/src/libraries/core/ClassTreeMask.h
r7401 r9667 73 73 #include <stack> 74 74 #include "BaseObject.h" 75 #include " Iterator.h"75 #include "object/Iterator.h" 76 76 77 77 namespace orxonox -
code/trunk/src/libraries/core/Core.cc
r9550 r9667 60 60 #include "util/SignalHandler.h" 61 61 #include "PathConfig.h" 62 #include " CommandLineParser.h"63 #include " ConfigFileManager.h"64 #include " ConfigValueIncludes.h"62 #include "config/CommandLineParser.h" 63 #include "config/ConfigFileManager.h" 64 #include "config/ConfigValueIncludes.h" 65 65 #include "CoreIncludes.h" 66 66 #include "DynLibManager.h" … … 68 68 #include "GraphicsManager.h" 69 69 #include "GUIManager.h" 70 #include " Identifier.h"70 #include "class/Identifier.h" 71 71 #include "Language.h" 72 72 #include "LuaState.h" 73 #include "ObjectList.h"74 73 #include "command/ConsoleCommand.h" 75 74 #include "command/IOConsole.h" … … 77 76 #include "command/TclThreadManager.h" 78 77 #include "input/InputManager.h" 78 #include "object/ObjectList.h" 79 79 80 80 namespace orxonox … … 91 91 SetCommandLineArgument(limitToCPU, 0).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is off = 0."); 92 92 #endif 93 94 // register Core as an abstract class to avoid problems if the class hierarchy is created within Core-constructor 95 RegisterAbstractClass(Core).inheritsFrom(Class(Configurable)); 93 96 94 97 Core::Core(const std::string& cmdLine) … … 176 179 // Do this soon after the ConfigFileManager has been created to open up the 177 180 // possibility to configure everything below here 178 Register RootObject(Core);181 RegisterObject(Core); 179 182 orxout(internal_info) << "configuring Core" << endl; 180 183 this->setConfigValues(); … … 198 201 // creates the class hierarchy for all classes with factories 199 202 orxout(internal_info) << "creating class hierarchy" << endl; 200 Identifier ::createClassHierarchy();203 IdentifierManager::getInstance().createClassHierarchy(); 201 204 202 205 // Load OGRE excluding the renderer and the render window … … 248 251 safeObjectDelete(&configFileManager_); 249 252 ConsoleCommand::destroyAll(); 250 Identifier::destroyAllIdentifiers(); 253 Context::setRootContext(NULL); 254 IdentifierManager::getInstance().destroyAllIdentifiers(); 251 255 safeObjectDelete(&signalHandler_); 252 256 safeObjectDelete(&dynLibManager_); … … 508 512 509 513 514 RegisterAbstractClass(DevModeListener).inheritsFrom(Class(Listable)); 515 510 516 DevModeListener::DevModeListener() 511 517 { 512 Register RootObject(DevModeListener);518 RegisterObject(DevModeListener); 513 519 } 514 520 } -
code/trunk/src/libraries/core/Core.h
r8858 r9667 47 47 #include "util/DestructionHelper.h" 48 48 #include "util/Singleton.h" 49 #include " OrxonoxClass.h"49 #include "config/Configurable.h" 50 50 51 51 namespace orxonox 52 52 { 53 53 //! Informs about changes in the Development Mode. 54 class DevModeListener : virtual public OrxonoxClass54 class DevModeListener : virtual public Listable 55 55 { 56 56 public: … … 66 66 You should only create this singleton once because it destroys the identifiers! 67 67 */ 68 class _CoreExport Core : public Singleton<Core>, public OrxonoxClass68 class _CoreExport Core : public Singleton<Core>, public Configurable 69 69 { 70 70 friend class Singleton<Core>; -
code/trunk/src/libraries/core/CoreIncludes.h
r8858 r9667 28 28 29 29 /** 30 @defgroup Factory RegisterObject() and CreateFactory()30 @defgroup Factory RegisterObject() and RegisterClass() 31 31 @ingroup Object 32 32 */ … … 35 35 @file 36 36 @ingroup Object Factory Class Identifier 37 @brief Defines several very important macros used to register objects, create factories, and to work with identifiers. 38 39 Every class needs the @c RegisterObject(class) macro in its constructor. If the class is an interface 40 or the @c BaseObject itself, it needs the macro @c RegisterRootObject(class) instead. 41 42 To allow the object being created through the factory, use the @c CreateFactory(class) macro outside 43 of the class implementation, so it gets executed statically before @c main(). This will at the same time 44 register @a class in the class-hierarchy. If you don't want @a class to be loadable, but still 45 register it, call @c CreateUnloadableFactory(class). 37 @brief Defines several very important macros used to register objects, register classes, and to work with identifiers. 38 39 Every class needs the @c RegisterObject(class) macro in its constructor. 40 41 To register @a class in the class-hierarchy, use the @c RegisterClass(class) macro outside of the class implementation, 42 so it gets executed statically before @c main(). If you don't want @a class to be loadable, but still register it, call 43 @c RegisterUnloadableClass(class). 44 45 Abstract classes are registered with @c RegisterAbstractClass(class). For abstract classes, the inheritance must be 46 defined manually with @c RegisterAbstractClass(class).inheritsFrom(Class(parent)). Multiple parent classes can be defined 47 by chaining the above command. 46 48 47 49 Example: 48 50 @code 49 // Create the factory for MyClass50 CreateFactory(MyClass);51 // register MyClass 52 RegisterClass(MyClass); 51 53 52 54 // Constructor: … … 79 81 80 82 #include "util/Output.h" 81 #include "Identifier.h" 82 #include "ClassFactory.h" 83 #include "ObjectList.h" 84 85 86 /** 87 @brief Intern macro, containing the common parts of @c RegisterObject and @c RegisterRootObject. 88 @param ClassName The name of the class 89 @param bRootClass True if the class is directly derived from orxonox::OrxonoxClass 90 */ 91 #define InternRegisterObject(ClassName, bRootClass) \ 92 if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initialiseObject(this, #ClassName, bRootClass)) \ 83 #include "class/IdentifierManager.h" 84 #include "object/ClassFactory.h" 85 #include "object/ObjectList.h" 86 87 // resolve macro conflict on windows 88 #if defined(ORXONOX_PLATFORM_WINDOWS) 89 # include <windows.h> 90 # undef RegisterClass 91 #endif 92 93 94 /** 95 @brief Registers the class in the framework. 96 @param ClassName The name of the class 97 */ 98 #define RegisterClass(ClassName) \ 99 RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), true) 100 101 /** 102 @brief Registers the class in the framework (for classes without arguments in their constructor). 103 @param ClassName The name of the class 104 */ 105 #define RegisterClassNoArgs(ClassName) \ 106 RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryNoArgs<ClassName>(), true) 107 108 /** 109 @brief Registers the class in the framework (for classes which should not be loaded through XML). 110 @param ClassName The name of the class 111 */ 112 #define RegisterUnloadableClass(ClassName) \ 113 RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), false) 114 115 /** 116 @brief Registers an abstract class in the framework. 117 @param ClassName The name of the class 118 */ 119 #define RegisterAbstractClass(ClassName) \ 120 RegisterClassWithFactory(ClassName, static_cast<ClassFactory<ClassName>*>(NULL), false) 121 122 /** 123 @brief Registers the class in the framework with a given Factory. 124 @param ClassName The name of the class 125 */ 126 #define RegisterClassWithFactory(ClassName, FactoryInstance, bLoadable) \ 127 Identifier& _##ClassName##Identifier = orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable) 128 129 /** 130 @brief Registers a newly created object in the framework. Has to be called at the beginning of the constructor of @a ClassName. 131 @param ClassName The name of the class 132 */ 133 #define RegisterObject(ClassName) \ 134 if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeObject(this)) \ 93 135 return; \ 94 136 else \ … … 96 138 97 139 /** 98 @brief Registers a newly created object in the core. Has to be called at the beginning of the constructor of @a ClassName.99 @param ClassName The name of the class100 */101 #define RegisterObject(ClassName) \102 InternRegisterObject(ClassName, false)103 104 /**105 @brief Registers a newly created object in the core. Has to be called at the beginning of the constructor of @a ClassName.106 @param ClassName The name of the class107 108 In contrast to RegisterObject, this is used for classes that inherit directly from109 orxonox::OrxonoxClass, namely all interfaces and orxonox::BaseObject.110 */111 #define RegisterRootObject(ClassName) \112 InternRegisterObject(ClassName, true)113 114 /**115 @brief Creates the Factory.116 @param ClassName The name of the class117 */118 #define CreateFactory(ClassName) \119 Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, true)120 121 /**122 @brief Creates the Factory for classes which should not be loaded through XML.123 @param ClassName The name of the class124 */125 #define CreateUnloadableFactory(ClassName) \126 Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, false)127 128 /**129 140 @brief Returns the Identifier of the given class. 130 141 @param ClassName The name of the class … … 137 148 { 138 149 /** 150 * @brief Overload of registerClass() which determines T implicitly by the template argument of the ClassFactory. 151 */ 152 template <class T> 153 inline Identifier& registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true) 154 { 155 return registerClass<T>(name, static_cast<Factory*>(factory), bLoadable); 156 } 157 158 /** 159 * @brief Registers a class in the framework. 160 * @param name The name of the class 161 * @param factory The factory which is able to create new instances of this class 162 * @param bLoadable Whether the class is allowed to be loaded through XML 163 */ 164 template <class T> 165 inline Identifier& registerClass(const std::string& name, Factory* factory, bool bLoadable = true) 166 { 167 orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl; 168 Identifier* identifier = ClassIdentifier<T>::getIdentifier(name); 169 identifier->setFactory(factory); 170 identifier->setLoadable(bLoadable); 171 return *identifier; 172 } 173 174 /** 139 175 @brief Returns the Identifier with a given name. 140 176 @param name The name of the class … … 142 178 inline Identifier* ClassByString(const std::string& name) 143 179 { 144 return Identifier ::getIdentifierByString(name);180 return IdentifierManager::getInstance().getIdentifierByString(name); 145 181 } 146 182 … … 151 187 inline Identifier* ClassByLowercaseString(const std::string& name) 152 188 { 153 return Identifier ::getIdentifierByLowercaseString(name);189 return IdentifierManager::getInstance().getIdentifierByLowercaseString(name); 154 190 } 155 191 … … 160 196 inline Identifier* ClassByID(uint32_t id) 161 197 { 162 return Identifier ::getIdentifierByID(id);198 return IdentifierManager::getInstance().getIdentifierByID(id); 163 199 } 164 200 165 201 /** 166 202 @brief Returns the Identifier with a given 'this' pointer. 167 @note This of course only works with OrxonoxClasses.203 @note This of course only works with Identifiables. 168 204 The only use is in conjunction with macros that don't know the class type. 169 @param object Pointer to an OrxonoxClass205 @param object Pointer to an Identifiable 170 206 */ 171 207 template <class T> -
code/trunk/src/libraries/core/CorePrereqs.h
r8351 r9667 127 127 class ClassFactory; 128 128 template <class T> 129 class ClassFactoryWithContext; 130 template <class T> 129 131 class ClassIdentifier; 130 132 class ClassTreeMask; … … 140 142 class ConfigFileManager; 141 143 class ConfigFileSection; 144 class Configurable; 142 145 class ConfigValueContainer; 146 class Context; 143 147 class Core; 148 class Destroyable; 144 149 class DestructionListener; 145 150 class DynLib; … … 154 159 class GraphicsManager; 155 160 class GUIManager; 161 class Identifiable; 156 162 class Identifier; 157 163 template <class T> 158 164 class Iterator; 159 165 class Language; 166 class Listable; 160 167 class LuaFunctor; 161 168 class LuaState; 162 169 class MemoryArchive; 163 170 class MemoryArchiveFactory; 164 class MetaObjectList;165 class MetaObjectListElement;166 171 class Namespace; 167 172 class NamespaceNode; … … 176 181 class OgreWindowEventListener; 177 182 class OrxonoxClass; 183 class OrxonoxInterface; 178 184 class PathConfig; 179 185 struct ResourceInfo; -
code/trunk/src/libraries/core/Event.cc
r8858 r9667 35 35 36 36 #include "BaseObject.h" 37 #include " Identifier.h"37 #include "class/Identifier.h" 38 38 39 39 namespace orxonox -
code/trunk/src/libraries/core/GUIManager.cc
r9576 r9667 78 78 #include "util/OrxAssert.h" 79 79 #include "util/output/BaseWriter.h" 80 #include " ConfigValueIncludes.h"80 #include "config/ConfigValueIncludes.h" 81 81 #include "Core.h" 82 82 #include "CoreIncludes.h" … … 256 256 , destructionHelper_(this) 257 257 { 258 Register RootObject(GUIManager);258 RegisterObject(GUIManager); 259 259 260 260 orxout(internal_status) << "initializing GUIManager..." << endl; -
code/trunk/src/libraries/core/GUIManager.h
r8862 r9667 49 49 #include "util/Singleton.h" 50 50 #include "input/InputHandler.h" 51 #include "OrxonoxClass.h"52 51 #include "WindowEventListener.h" 53 52 -
code/trunk/src/libraries/core/Game.cc
r8861 r9667 44 44 #include "util/Sleep.h" 45 45 #include "util/SubString.h" 46 #include "CommandLineParser.h"47 46 #include "Core.h" 48 47 #include "CoreIncludes.h" 49 #include "ConfigValueIncludes.h" 48 #include "config/CommandLineParser.h" 49 #include "config/ConfigValueIncludes.h" 50 50 #include "GameMode.h" 51 51 #include "GameState.h" … … 112 112 113 113 // Do this after the Core creation! 114 Register RootObject(Game);114 RegisterObject(Game); 115 115 this->setConfigValues(); 116 116 -
code/trunk/src/libraries/core/Game.h
r8858 r9667 50 50 #include "util/DestructionHelper.h" 51 51 #include "util/Singleton.h" 52 #include " OrxonoxClass.h"52 #include "config/Configurable.h" 53 53 54 54 /** … … 82 82 class _CoreExport Game 83 83 // tolua_end 84 : public Singleton<Game>, public OrxonoxClass84 : public Singleton<Game>, public Configurable 85 85 { // tolua_export 86 86 friend class Singleton<Game>; -
code/trunk/src/libraries/core/GraphicsManager.cc
r8861 r9667 52 52 #include "util/StringUtils.h" 53 53 #include "util/SubString.h" 54 #include " ConfigValueIncludes.h"54 #include "config/ConfigValueIncludes.h" 55 55 #include "CoreIncludes.h" 56 56 #include "Core.h" -
code/trunk/src/libraries/core/GraphicsManager.h
r8858 r9667 52 52 #include "util/DestructionHelper.h" 53 53 #include "util/Singleton.h" 54 #include " OrxonoxClass.h"54 #include "config/Configurable.h" 55 55 56 56 // tolua_begin … … 63 63 class _CoreExport GraphicsManager 64 64 // tolua_end 65 : public Singleton<GraphicsManager>, public OrxonoxClass, public Ogre::LogListener65 : public Singleton<GraphicsManager>, public Configurable, public Ogre::LogListener 66 66 { // tolua_export 67 67 friend class Singleton<GraphicsManager>; -
code/trunk/src/libraries/core/Loader.cc
r8858 r9667 37 37 #include "util/StringUtils.h" 38 38 #include "BaseObject.h" 39 #include "Iterator.h"40 #include "ObjectList.h"41 39 #include "LuaState.h" 42 40 #include "Namespace.h" 43 41 #include "Resource.h" 44 42 #include "XMLFile.h" 43 #include "object/Iterator.h" 44 #include "object/ObjectList.h" 45 45 46 46 namespace orxonox … … 209 209 210 210 orxout(verbose, context::loader) << " creating root-namespace..." << endl; 211 Namespace* rootNamespace = new Namespace( 0);211 Namespace* rootNamespace = new Namespace(Context::getRootContext()); 212 212 rootNamespace->setLoaderIndentation(" "); 213 213 rootNamespace->setFile(file); -
code/trunk/src/libraries/core/Namespace.cc
r7401 r9667 38 38 namespace orxonox 39 39 { 40 CreateFactory(Namespace);40 RegisterClass(Namespace); 41 41 42 Namespace::Namespace( BaseObject* creator) : BaseObject(creator),42 Namespace::Namespace(Context* context) : BaseObject(context), Context(context), 43 43 bAutogeneratedFileRootNamespace_(false), 44 44 bRoot_(false), -
code/trunk/src/libraries/core/Namespace.h
r7401 r9667 40 40 #include <string> 41 41 #include "BaseObject.h" 42 #include "object/Context.h" 42 43 43 44 namespace orxonox 44 45 { 45 class Namespace : public BaseObject 46 class Namespace : public BaseObject, public Context 46 47 { 47 48 public: 48 Namespace( BaseObject* creator);49 Namespace(Context* context); 49 50 virtual ~Namespace(); 50 51 -
code/trunk/src/libraries/core/PathConfig.cc
r9550 r9667 53 53 #include "util/Output.h" 54 54 #include "util/Exception.h" 55 #include " CommandLineParser.h"55 #include "config/CommandLineParser.h" 56 56 57 57 // Differentiate Boost Filesystem v2 and v3 -
code/trunk/src/libraries/core/Template.cc
r9348 r9667 38 38 namespace orxonox 39 39 { 40 CreateFactory(Template);40 RegisterClass(Template); 41 41 42 Template::Template( BaseObject* creator) : BaseObject(creator)42 Template::Template(Context* context) : BaseObject(context) 43 43 { 44 44 this->xmlelement_ = new TiXmlElement(""); … … 150 150 151 151 // check if the template is applied on an object of the right type 152 Identifier* identifier = Identifier::getIdentifierByString(this->getXMLElement().Value());152 Identifier* identifier = ClassByString(this->getXMLElement().Value()); 153 153 if (!object->getIdentifier()->isA(identifier)) 154 154 orxout(internal_warning, context::templates) << "Template was defined for " << identifier->getName() << " but the object is of type " << object->getIdentifier()->getName() << endl; -
code/trunk/src/libraries/core/Template.h
r7401 r9667 51 51 { 52 52 public: 53 Template( BaseObject* creator);53 Template(Context* context); 54 54 virtual ~Template(); 55 55 -
code/trunk/src/libraries/core/ViewportEventListener.cc
r8079 r9667 32 32 namespace orxonox 33 33 { 34 RegisterAbstractClass(ViewportEventListener).inheritsFrom(Class(Listable)); 35 34 36 ViewportEventListener::ViewportEventListener() 35 37 { 36 Register RootObject(ViewportEventListener);38 RegisterObject(ViewportEventListener); 37 39 } 38 40 } -
code/trunk/src/libraries/core/ViewportEventListener.h
r8729 r9667 33 33 34 34 #include "util/OgreForwardRefs.h" 35 #include " OrxonoxClass.h"35 #include "object/Listable.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _CoreExport ViewportEventListener : virtual public OrxonoxClass39 class _CoreExport ViewportEventListener : virtual public Listable 40 40 { 41 41 public: -
code/trunk/src/libraries/core/WindowEventListener.cc
r7874 r9667 35 35 unsigned int WindowEventListener::windowHeight_s = 0; 36 36 37 RegisterAbstractClass(WindowEventListener).inheritsFrom(Class(Listable)); 38 37 39 WindowEventListener::WindowEventListener() 38 40 { 39 Register RootObject(WindowEventListener);41 RegisterObject(WindowEventListener); 40 42 } 41 43 -
code/trunk/src/libraries/core/WindowEventListener.h
r7874 r9667 36 36 37 37 #include "CorePrereqs.h" 38 #include " OrxonoxClass.h"38 #include "object/Listable.h" 39 39 40 40 namespace orxonox 41 41 { 42 42 //! Interface for receiving window events like resize, moved and focusChanged 43 class _CoreExport WindowEventListener : virtual public OrxonoxClass43 class _CoreExport WindowEventListener : virtual public Listable 44 44 { 45 45 friend class OgreWindowEventListener; -
code/trunk/src/libraries/core/XMLNameListener.cc
r5781 r9667 32 32 namespace orxonox 33 33 { 34 RegisterAbstractClass(XMLNameListener).inheritsFrom(Class(Listable)); 35 34 36 XMLNameListener::XMLNameListener() 35 37 { 36 Register RootObject(XMLNameListener);38 RegisterObject(XMLNameListener); 37 39 } 38 40 } -
code/trunk/src/libraries/core/XMLNameListener.h
r7401 r9667 36 36 37 37 #include "CorePrereqs.h" 38 #include " OrxonoxClass.h"38 #include "object/Listable.h" 39 39 40 40 namespace orxonox 41 41 { 42 class _CoreExport XMLNameListener : virtual public OrxonoxClass42 class _CoreExport XMLNameListener : virtual public Listable 43 43 { 44 44 public: -
code/trunk/src/libraries/core/XMLPort.cc
r8858 r9667 29 29 #include "XMLPort.h" 30 30 31 #include "CoreIncludes.h" 31 32 #include "Loader.h" 32 33 #include "Namespace.h" … … 59 60 for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++) 60 61 { 61 Identifier* identifier = Identifier::getIdentifierByString(child->Value());62 Identifier* identifier = ClassByString(child->Value()); 62 63 if (!identifier) 63 64 { … … 89 90 orxout(verbose, context::xml) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << endl; 90 91 91 BaseObject* newObject = identifier->fabricate(object);92 BaseObject* newObject = orxonox_cast<BaseObject*>(identifier->fabricate(object->getContext())); 92 93 newObject->setLoaderIndentation(object->getLoaderIndentation() + " "); 93 94 -
code/trunk/src/libraries/core/XMLPort.h
r9348 r9667 58 58 #include "util/OrxAssert.h" 59 59 #include "util/StringUtils.h" 60 #include " Identifier.h"60 #include "class/Identifier.h" 61 61 #include "BaseObject.h" 62 62 #include "command/Executor.h" -
code/trunk/src/libraries/core/class/CMakeLists.txt
r9577 r9667 3 3 Identifier.cc 4 4 IdentifierManager.cc 5 OrxonoxClass.cc 6 OrxonoxInterface.cc 5 7 ) -
code/trunk/src/libraries/core/class/Identifiable.cc
r9574 r9667 35 35 36 36 #include <cassert> 37 #include "core/CoreIncludes.h" 37 38 #include "core/object/Context.h" 38 39 #include "Identifier.h" … … 40 41 namespace orxonox 41 42 { 43 RegisterClassNoArgs(Identifiable); 44 42 45 /** 43 46 @brief Constructor: Sets the default values. … … 46 49 { 47 50 this->identifier_ = 0; 48 this->parents_ = 0; 49 // Optimisation 50 this->objectPointers_.reserve(6); 51 } 51 this->objectPointers_.reserve(6); // Optimisation 52 52 53 /** 54 @brief Destructor: Removes the object from the object-lists 55 */ 56 Identifiable::~Identifiable() 57 { 58 // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class 59 if (this->parents_) 60 delete this->parents_; 53 RegisterObject(Identifiable); 61 54 } 62 55 -
code/trunk/src/libraries/core/class/Identifiable.h
r9574 r9667 55 55 public: 56 56 Identifiable(); 57 virtual ~Identifiable() ;57 virtual ~Identifiable() {} 58 58 59 59 /// Returns the Identifier of the object. … … 119 119 private: 120 120 Identifier* identifier_; //!< The Identifier of the object 121 std::set<const Identifier*>* parents_; //!< List of all parents of the object122 121 123 122 /// 'Fast map' that holds this-pointers of all derived types -
code/trunk/src/libraries/core/class/Identifier.cc
r9593 r9667 37 37 38 38 #include "util/StringUtils.h" 39 #include "core/CoreIncludes.h" 39 40 #include "core/config/ConfigValueContainer.h" 40 41 #include "core/XMLPort.h" … … 50 51 */ 51 52 Identifier::Identifier() 52 : classID_(IdentifierManager::classIDCounter_s++) 53 { 54 this->objects_ = new ObjectListBase(); 55 56 this->bCreatedOneObject_ = false; 57 this->bSetName_ = false; 53 : classID_(IdentifierManager::getInstance().getUniqueClassId()) 54 { 58 55 this->factory_ = 0; 56 this->bInitialized_ = false; 59 57 this->bLoadable_ = false; 60 58 … … 70 68 Identifier::~Identifier() 71 69 { 72 delete this->objects_;73 74 70 if (this->factory_) 75 71 delete this->factory_; … … 84 80 85 81 /** 86 @brief Registers a class, which means that the name and the parents get stored.87 @param parents A list, containing the Identifiers of all parents of the class88 @param bRootClass True if the class is either an Interface or the BaseObject itself89 */90 void Identifier::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass)91 {92 // Check if at least one object of the given type was created93 if (!this->bCreatedOneObject_ && IdentifierManager::isCreatingHierarchy())94 {95 // If no: We have to store the information and initialize the Identifier96 orxout(verbose, context::identifier) << "Register Class in ClassIdentifier<" << this->getName() << ">-Singleton -> Initialize Singleton." << endl;97 if (bRootClass)98 this->initialize(0); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case.99 else100 this->initialize(parents);101 }102 }103 104 /**105 @brief Initializes the Identifier with a list containing all parents of the class the Identifier belongs to.106 @param parents A list containing all parents107 */108 void Identifier::initialize(std::set<const Identifier*>* parents)109 {110 orxout(verbose, context::identifier) << "Initialize ClassIdentifier<" << this->name_ << ">-Singleton." << endl;111 this->bCreatedOneObject_ = true;112 113 if (parents)114 {115 this->parents_ = (*parents);116 this->directParents_ = (*parents);117 118 // Iterate through all parents119 for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)120 {121 // Tell the parent we're one of it's children122 (*it)->children_.insert((*it)->children_.end(), this);123 124 // Erase all parents of our parent from our direct-parent-list125 for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)126 {127 // Search for the parent's parent in our direct-parent-list128 for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)129 {130 if ((*it1) == (*it2))131 {132 // We've found a non-direct parent in our list: Erase it133 this->directParents_.erase(it2);134 break;135 }136 }137 }138 }139 140 // Now iterate through all direct parents141 for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)142 {143 // Tell the parent we're one of it's direct children144 (*it)->directChildren_.insert((*it)->directChildren_.end(), this);145 146 // Create the super-function dependencies147 (*it)->createSuperFunctionCaller();148 }149 }150 }151 152 /**153 82 @brief Sets the name of the class. 154 83 */ 155 84 void Identifier::setName(const std::string& name) 156 85 { 157 if ( !this->bSetName_)86 if (name != this->name_) 158 87 { 159 88 this->name_ = name; 160 this->bSetName_ = true; 161 IdentifierManager::getStringIdentifierMapIntern()[name] = this; 162 IdentifierManager::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this; 163 IdentifierManager::getIDIdentifierMapIntern()[this->networkID_] = this; 164 } 165 } 89 IdentifierManager::getInstance().addIdentifierToLookupMaps(this); 90 } 91 } 92 93 void Identifier::setFactory(Factory* factory) 94 { 95 if (this->factory_) 96 delete this->factory_; 97 98 this->factory_ = factory; 99 } 100 166 101 167 102 /** … … 169 104 @return The new object 170 105 */ 171 OrxonoxClass* Identifier::fabricate(BaseObject* creator)106 Identifiable* Identifier::fabricate(Context* context) 172 107 { 173 108 if (this->factory_) 174 109 { 175 return this->factory_->fabricate(c reator);110 return this->factory_->fabricate(context); 176 111 } 177 112 else … … 190 125 void Identifier::setNetworkID(uint32_t id) 191 126 { 192 // Identifier::getIDIdentifierMapIntern().erase(this->networkID_);193 IdentifierManager::getIDIdentifierMapIntern()[id] = this;194 127 this->networkID_ = id; 128 IdentifierManager::getInstance().addIdentifierToLookupMaps(this); 129 } 130 131 /** 132 * @brief Used to define the direct parents of an Identifier of an abstract class. 133 */ 134 Identifier& Identifier::inheritsFrom(Identifier* directParent) 135 { 136 if (this->parents_.empty()) 137 this->directParents_.insert(directParent); 138 else 139 orxout(internal_error) << "Trying to add " << directParent->getName() << " as a direct parent of " << this->getName() << " after the latter was already initialized" << endl; 140 141 return *this; 142 } 143 144 /** 145 * @brief Initializes the parents of this Identifier while creating the class hierarchy. 146 * @param identifiers All identifiers that were used to create an instance of this class (including this identifier itself) 147 */ 148 void Identifier::initializeParents(const std::set<const Identifier*>& identifiers) 149 { 150 if (!IdentifierManager::getInstance().isCreatingHierarchy()) 151 { 152 orxout(internal_warning) << "Identifier::initializeParents() created outside of class hierarchy creation" << endl; 153 return; 154 } 155 156 for (std::set<const Identifier*>::const_iterator it = identifiers.begin(); it != identifiers.end(); ++it) 157 if (*it != this) 158 this->parents_.insert(*it); 159 } 160 161 /** 162 * @brief Initializes the direct parents of this Identifier while creating the class hierarchy. This is only intended for abstract classes. 163 */ 164 void Identifier::initializeDirectParentsOfAbstractClass() 165 { 166 if (!IdentifierManager::getInstance().isCreatingHierarchy()) 167 { 168 orxout(internal_warning) << "Identifier::initializeDirectParentsOfAbstractClass() created outside of class hierarchy creation" << endl; 169 return; 170 } 171 172 // only Identifiable is allowed to have no parents (even tough it's currently not abstract) 173 if (this->directParents_.empty() && !this->isExactlyA(Class(Identifiable))) 174 { 175 orxout(internal_error) << "Identifier " << this->getName() << " / " << this->getTypeidName() << " is marked as abstract but has no direct parents defined" << endl; 176 orxout(internal_error) << " If this class is not abstract, use RegisterClass(ThisClass);" << endl; 177 orxout(internal_error) << " If this class is abstract, use RegisterAbstractClass(ThisClass).inheritsFrom(Class(BaseClass));" << endl; 178 } 179 } 180 181 /** 182 * @brief Finishes the initialization of this Identifier after creating the class hierarchy by wiring the (direct) parent/child references correctly. 183 */ 184 void Identifier::finishInitialization() 185 { 186 if (!IdentifierManager::getInstance().isCreatingHierarchy()) 187 { 188 orxout(internal_warning) << "Identifier::finishInitialization() created outside of class hierarchy creation" << endl; 189 return; 190 } 191 192 if (this->isInitialized()) 193 return; 194 195 // if no direct parents were defined, initialize them with the set of all parents 196 if (this->directParents_.empty()) 197 this->directParents_ = this->parents_; 198 199 // initialize all parents before continuing to initialize this identifier 200 for (std::set<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) 201 { 202 Identifier* directParent = const_cast<Identifier*>(*it); 203 directParent->finishInitialization(); // initialize parent 204 this->parents_.insert(directParent); // direct parent is also a parent 205 this->parents_.insert(directParent->parents_.begin(), directParent->parents_.end()); // parents of direct parent are also parents 206 } 207 208 // parents of parents are no direct parents of this identifier 209 for (std::set<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent) 210 for (std::set<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent) 211 this->directParents_.erase(*it_parent_parent); 212 213 // tell all parents that this identifier is a child 214 for (std::set<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it) 215 const_cast<Identifier*>(*it)->children_.insert(this); 216 217 // tell all direct parents that this identifier is a direct child 218 for (std::set<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) 219 { 220 const_cast<Identifier*>(*it)->directChildren_.insert(this); 221 222 // Create the super-function dependencies 223 (*it)->createSuperFunctionCaller(); 224 } 225 226 this->bInitialized_ = true; 195 227 } 196 228 -
code/trunk/src/libraries/core/class/Identifier.h
r9593 r9667 56 56 object->getIdentifier()->getName(); // returns "MyClass" 57 57 58 OrxonoxClass* other = object->getIdentifier()->fabricate(0); // fabricates a new instance of MyClass 59 60 61 // iterate through all objects of type MyClass: 62 ObjectListBase* objects = object->getIdentifier()->getObjects(); // get a pointer to the object-list 63 int count; 64 for (Iterator<MyClass> it = objects.begin(); it != objects.end(); ++it) // iterate through the objects 65 ++count; 66 orxout() << count << endl; // prints "2" because we created 2 instances of MyClass so far 58 Identifiable* other = object->getIdentifier()->fabricate(0); // fabricates a new instance of MyClass 67 59 68 60 … … 90 82 91 83 #include "util/Output.h" 92 #include "core/object/MetaObjectList.h"93 84 #include "core/object/ObjectList.h" 94 #include "core/object/ObjectListBase.h" 85 #include "core/object/Listable.h" 86 #include "core/object/Context.h" 87 #include "core/object/Destroyable.h" 88 #include "core/object/WeakPtr.h" 95 89 #include "IdentifierManager.h" 96 90 #include "Super.h" … … 112 106 @note You can't directly create an Identifier, it's just the base-class of ClassIdentifier<T>. 113 107 */ 114 class _CoreExport Identifier 115 { 116 friend class IdentifierManager; 117 108 class _CoreExport Identifier : public Destroyable 109 { 118 110 public: 111 Identifier(); 112 Identifier(const Identifier& identifier); // don't copy 113 virtual ~Identifier(); 114 119 115 /// Returns the name of the class the Identifier belongs to. 120 116 inline const std::string& getName() const { return this->name_; } 121 117 void setName(const std::string& name); 122 118 119 /// Returns the name of the class as it is returned by typeid(T).name() 120 virtual const std::string& getTypeidName() = 0; 121 123 122 /// Returns the network ID to identify a class through the network. 124 123 inline uint32_t getNetworkID() const { return this->networkID_; } … … 128 127 ORX_FORCEINLINE unsigned int getClassID() const { return this->classID_; } 129 128 130 /// Returns the list of all existing objects of this class.131 inline ObjectListBase* getObjects() const { return this->objects_; }132 133 129 /// Sets the Factory. 134 inline void addFactory(Factory* factory) { this->factory_ = factory; }130 void setFactory(Factory* factory); 135 131 /// Returns true if the Identifier has a Factory. 136 132 inline bool hasFactory() const { return (this->factory_ != 0); } 137 133 138 OrxonoxClass* fabricate(BaseObject* creator);134 Identifiable* fabricate(Context* context); 139 135 140 136 /// Returns true if the class can be loaded through XML. … … 142 138 /// Set the class to be loadable through XML or not. 143 139 inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; } 140 141 /// Returns true if the Identifier was completely initialized. 142 inline bool isInitialized() const { return this->bInitialized_; } 143 144 145 ///////////////////////////// 146 ////// Class Hierarchy ////// 147 ///////////////////////////// 148 Identifier& inheritsFrom(Identifier* directParent); 149 150 void initializeParents(const std::set<const Identifier*>& identifiers); 151 void initializeDirectParentsOfAbstractClass(); 152 void finishInitialization(); 144 153 145 154 bool isA(const Identifier* identifier) const; … … 150 159 bool isDirectParentOf(const Identifier* identifier) const; 151 160 152 153 /////////////////////////////154 ////// Class Hierarchy //////155 /////////////////////////////156 161 /// Returns the parents of the class the Identifier belongs to. 157 162 inline const std::set<const Identifier*>& getParents() const { return this->parents_; } … … 220 225 221 226 protected: 222 Identifier();223 Identifier(const Identifier& identifier); // don't copy224 virtual ~Identifier();225 226 227 virtual void createSuperFunctionCaller() const = 0; 227 228 228 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);229 230 /// Returns the children of the class the Identifier belongs to.231 inline std::set<const Identifier*>& getChildrenIntern() const { return this->children_; }232 /// Returns the direct children of the class the Identifier belongs to.233 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; }234 235 ObjectListBase* objects_; //!< The list of all objects of this class236 237 229 private: 238 void initialize(std::set<const Identifier*>* parents);239 240 230 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to 241 mutable std::set<const Identifier*> children_;//!< The children of the class the Identifier belongs to231 std::set<const Identifier*> children_; //!< The children of the class the Identifier belongs to 242 232 243 233 std::set<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to 244 mutable std::set<const Identifier*> directChildren_; //!< The direct children of the class the Identifier belongs to 245 246 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 247 bool bSetName_; //!< True if the name is set 234 std::set<const Identifier*> directChildren_; //!< The direct children of the class the Identifier belongs to 235 236 bool bInitialized_; //!< Is true if the Identifier was completely initialized 248 237 bool bLoadable_; //!< False = it's not permitted to load the object through XML 249 238 std::string name_; //!< The name of the class the Identifier belongs to … … 287 276 static ClassIdentifier<T>* getIdentifier(const std::string& name); 288 277 289 bool initiali seObject(T* object, const std::string& className, bool bRootClass);278 bool initializeObject(T* object); 290 279 291 280 void setConfigValues(T* object, Configurable*) const; … … 295 284 void addObjectToList(T* object, Identifiable*); 296 285 297 void updateConfigValues(bool updateChildren = true) const; 286 virtual void updateConfigValues(bool updateChildren = true) const; 287 288 virtual const std::string& getTypeidName() 289 { return this->typeidName_; } 298 290 299 291 private: 300 static void initialiseIdentifier(); 292 static void initializeIdentifier(); 293 301 294 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 302 295 ClassIdentifier() 303 296 { 297 this->typeidName_ = typeid(T).name(); 304 298 SuperFunctionInitialization<0, T>::initialize(this); 305 299 } … … 309 303 } 310 304 311 static ClassIdentifier<T>* classIdentifier_s; 305 void updateConfigValues(bool updateChildren, Listable*) const; 306 void updateConfigValues(bool updateChildren, Identifiable*) const; 307 308 std::string typeidName_; 309 static WeakPtr<ClassIdentifier<T> > classIdentifier_s; 312 310 }; 313 311 314 312 template <class T> 315 ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s = 0;313 WeakPtr<ClassIdentifier<T> > ClassIdentifier<T>::classIdentifier_s; 316 314 317 315 /** … … 324 322 // check if the Identifier already exists 325 323 if (!ClassIdentifier<T>::classIdentifier_s) 326 ClassIdentifier<T>::initiali seIdentifier();324 ClassIdentifier<T>::initializeIdentifier(); 327 325 328 326 return ClassIdentifier<T>::classIdentifier_s; … … 346 344 */ 347 345 template <class T> 348 void ClassIdentifier<T>::initialiseIdentifier() 349 { 350 // Get the name of the class 351 std::string name = typeid(T).name(); 352 353 // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used. 346 /*static */ void ClassIdentifier<T>::initializeIdentifier() 347 { 348 // create a new identifier anyway. Will be deleted if not used. 354 349 ClassIdentifier<T>* proposal = new ClassIdentifier<T>(); 355 350 356 351 // Get the entry from the map 357 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getI dentifierSingleton(name,proposal);352 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getGloballyUniqueIdentifier(proposal); 358 353 359 354 if (ClassIdentifier<T>::classIdentifier_s == proposal) 360 { 361 orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was not yet existing and got created." << endl; 362 } 355 orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was not yet existing and got created." << endl; 363 356 else 364 357 { 365 orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was already existing and got assigned." << endl; 358 orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was already existing and got assigned." << endl; 359 delete proposal; // delete proposal (it is not used anymore) 366 360 } 367 361 } … … 370 364 @brief Adds an object of the given type to the ObjectList. 371 365 @param object The object to add 372 @param className The name of the class T 373 @param bRootClass True if this is a root class (i.e. it inherits directly from OrxonoxClass) 374 */ 375 template <class T> 376 bool ClassIdentifier<T>::initialiseObject(T* object, const std::string& className, bool bRootClass) 377 { 378 if (bRootClass) 379 orxout(verbose, context::object_list) << "Register Root-Object: " << className << endl; 380 else 381 orxout(verbose, context::object_list) << "Register Object: " << className << endl; 366 */ 367 template <class T> 368 bool ClassIdentifier<T>::initializeObject(T* object) 369 { 370 orxout(verbose, context::object_list) << "Register Object: " << this->getName() << endl; 382 371 383 372 object->identifier_ = this; 384 if (IdentifierManager:: isCreatingHierarchy())373 if (IdentifierManager::getInstance().isCreatingHierarchy()) 385 374 { 386 if (bRootClass && !object->parents_) 387 object->parents_ = new std::set<const Identifier*>(); 388 389 if (object->parents_) 390 { 391 this->initializeClassHierarchy(object->parents_, bRootClass); 392 object->parents_->insert(object->parents_->end(), this); 393 } 375 IdentifierManager::getInstance().createdObject(object); 394 376 395 377 this->setConfigValues(object, object); … … 425 407 */ 426 408 template <class T> 427 void ClassIdentifier<T>::addObjectToList(T* object, Listable* )428 { 429 orxout(verbose, context::object_list) << "Added object to " << this->getName() << "-list." << endl;430 object->metaList_->add(this->objects_, this->objects_->add(object));409 void ClassIdentifier<T>::addObjectToList(T* object, Listable* listable) 410 { 411 if (listable->getContext()) 412 listable->getContext()->addObject(object); 431 413 } 432 414 … … 442 424 template <class T> 443 425 void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const 426 { 427 this->updateConfigValues(updateChildren, static_cast<T*>(NULL)); 428 } 429 430 template <class T> 431 void ClassIdentifier<T>::updateConfigValues(bool updateChildren, Listable*) const 444 432 { 445 433 if (!this->hasConfigValues()) … … 452 440 for (std::set<const Identifier*>::const_iterator it = this->getChildrenBegin(); it != this->getChildrenEnd(); ++it) 453 441 (*it)->updateConfigValues(false); 442 } 443 444 template <class T> 445 void ClassIdentifier<T>::updateConfigValues(bool updateChildren, Identifiable*) const 446 { 447 // no action 454 448 } 455 449 -
code/trunk/src/libraries/core/class/IdentifierManager.cc
r9564 r9667 37 37 38 38 #include "util/StringUtils.h" 39 #include "core/CoreIncludes.h" 39 40 #include "core/config/ConfigValueContainer.h" 40 41 #include "core/XMLPort.h" … … 43 44 namespace orxonox 44 45 { 45 int IdentifierManager::hierarchyCreatingCounter_s = 0;46 unsigned int IdentifierManager::classIDCounter_s = 0;47 48 /**49 @brief Returns the identifier map with the names as received by typeid(). This is only used internally.50 */ 51 std::map<std::string, Identifier*>& IdentifierManager::getTypeIDIdentifierMap()52 { 53 static std::map<std::string, Identifier*> identifiers; //!< The map to store all Identifiers.54 return identifiers;46 /* static */ IdentifierManager& IdentifierManager::getInstance() 47 { 48 static IdentifierManager instance; 49 return instance; 50 } 51 52 IdentifierManager::IdentifierManager() 53 { 54 this->hierarchyCreatingCounter_s = 0; 55 this->classIDCounter_s = 0; 55 56 } 56 57 57 58 /** 58 59 @brief Returns an identifier by name and adds it if not available 59 @param name The name of the identifier as typeid().name() suggests60 60 @param proposal A pointer to a newly created identifier for the case of non existence in the map 61 61 @return The identifier (unique instance) 62 62 */ 63 Identifier* IdentifierManager::get IdentifierSingleton(const std::string& name,Identifier* proposal)64 { 65 std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);66 67 if (it != getTypeIDIdentifierMap().end()) 68 {69 // There is already an entry: return it and delete the proposal70 delete proposal;63 Identifier* IdentifierManager::getGloballyUniqueIdentifier(Identifier* proposal) 64 { 65 const std::string& typeidName = proposal->getTypeidName(); 66 std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.find(typeidName); 67 68 if (it != this->identifierByTypeidName_.end()) 69 { 70 // There is already an entry: return it 71 71 return it->second; 72 72 } … … 74 74 { 75 75 // There is no entry: put the proposal into the map and return it 76 getTypeIDIdentifierMap()[name] = proposal;76 this->identifierByTypeidName_[typeidName] = proposal; 77 77 return proposal; 78 78 } … … 80 80 81 81 /** 82 * Registers the identifier in all maps of the IdentifierManager. 83 */ 84 void IdentifierManager::addIdentifierToLookupMaps(Identifier* identifier) 85 { 86 const std::string& typeidName = identifier->getTypeidName(); 87 if (this->identifierByTypeidName_.find(typeidName) != this->identifierByTypeidName_.end()) 88 { 89 this->identifierByString_[identifier->getName()] = identifier; 90 this->identifierByLowercaseString_[getLowercase(identifier->getName())] = identifier; 91 this->identifierByNetworkId_[identifier->getNetworkID()] = identifier; 92 } 93 else 94 orxout(internal_warning) << "Trying to add an identifier to lookup maps which is not known to IdentifierManager" << endl; 95 } 96 97 /** 82 98 @brief Creates the class-hierarchy by creating and destroying one object of each type. 83 99 */ … … 85 101 { 86 102 orxout(internal_status) << "Create class-hierarchy" << endl; 87 IdentifierManager::startCreatingHierarchy(); 88 for (std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMap().begin(); it != IdentifierManager::getStringIdentifierMap().end(); ++it) 89 { 90 // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards. 91 if (it->second->hasFactory()) 103 this->startCreatingHierarchy(); 104 105 std::set<Identifier*> initializedIdentifiers; 106 107 // ensure root context exists before starting to create objects. if the root context is dynamically created while creating the class hierarchy, we 108 // would mistakenly assume the class of the currently created object inherits from Context 109 Context::getRootContext(); 110 111 // iterate over all identifiers, create one instance of each class and initialize the identifiers 112 { 113 Context temporaryContext(NULL); 114 for (std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.begin(); it != this->identifierByTypeidName_.end(); ++it) 92 115 { 93 OrxonoxClass* temp = it->second->fabricate(0); 94 temp->destroy(); 116 orxout(verbose, context::identifier) << "Initialize ClassIdentifier<" << it->second->getName() << ">-Singleton." << endl; 117 // To initialize the identifier, we create a new object and delete it afterwards. 118 if (it->second->hasFactory()) 119 { 120 this->identifiersOfNewObject_.clear(); 121 Identifiable* temp = it->second->fabricate(&temporaryContext); 122 if (temp->getIdentifier() != it->second) 123 orxout(internal_error) << "Newly created object of type " << it->second->getName() << " has unexpected identifier. Did you forget to use RegisterObject(classname)?" << endl; 124 delete temp; 125 126 it->second->initializeParents(this->identifiersOfNewObject_); 127 } 128 else 129 it->second->initializeDirectParentsOfAbstractClass(); 130 131 initializedIdentifiers.insert(it->second); 95 132 } 96 } 97 IdentifierManager::stopCreatingHierarchy(); 133 134 size_t numberOfObjects = temporaryContext.getObjectList<Listable>()->size(); 135 if (numberOfObjects > 0) 136 orxout(internal_warning) << "There are still " << numberOfObjects << " listables left after creating the class hierarchy" << endl; 137 } 138 139 // finish the initialization of all identifiers 140 for (std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.begin(); it != this->identifierByTypeidName_.end(); ++it) 141 { 142 if (initializedIdentifiers.find(it->second) != initializedIdentifiers.end()) 143 it->second->finishInitialization(); 144 else 145 orxout(internal_error) << "Identifier was registered late and is not initialized: " << it->second->getName() << " / " << it->second->getTypeidName() << endl; 146 } 147 148 this->stopCreatingHierarchy(); 98 149 orxout(internal_status) << "Finished class-hierarchy creation" << endl; 99 150 } … … 104 155 void IdentifierManager::destroyAllIdentifiers() 105 156 { 106 for (std::map<std::string, Identifier*>::iterator it = IdentifierManager::getTypeIDIdentifierMap().begin(); it != IdentifierManager::getTypeIDIdentifierMap().end(); ++it)157 for (std::map<std::string, Identifier*>::iterator it = this->identifierByTypeidName_.begin(); it != this->identifierByTypeidName_.end(); ++it) 107 158 delete (it->second); 108 } 109 110 /** 111 @brief Returns the map that stores all Identifiers with their names. 112 @return The map 113 */ 114 std::map<std::string, Identifier*>& IdentifierManager::getStringIdentifierMapIntern() 115 { 116 static std::map<std::string, Identifier*> identifierMap; 117 return identifierMap; 118 } 119 120 /** 121 @brief Returns the map that stores all Identifiers with their names in lowercase. 122 @return The map 123 */ 124 std::map<std::string, Identifier*>& IdentifierManager::getLowercaseStringIdentifierMapIntern() 125 { 126 static std::map<std::string, Identifier*> lowercaseIdentifierMap; 127 return lowercaseIdentifierMap; 128 } 129 130 /** 131 @brief Returns the map that stores all Identifiers with their network IDs. 132 @return The map 133 */ 134 std::map<uint32_t, Identifier*>& IdentifierManager::getIDIdentifierMapIntern() 135 { 136 static std::map<uint32_t, Identifier*> identifierMap; 137 return identifierMap; 159 160 this->identifierByTypeidName_.clear(); 161 this->identifierByString_.clear(); 162 this->identifierByLowercaseString_.clear(); 163 this->identifierByNetworkId_.clear(); 164 } 165 166 /** 167 * @brief Notifies the IdentifierManager about a newly created object while creating the class hierarchy. 168 */ 169 void IdentifierManager::createdObject(Identifiable* identifiable) 170 { 171 if (this->isCreatingHierarchy()) 172 this->identifiersOfNewObject_.insert(identifiable->getIdentifier()); 173 else 174 orxout(internal_warning) << "createdObject() called outside of class hierarchy creation" << endl; 138 175 } 139 176 … … 145 182 Identifier* IdentifierManager::getIdentifierByString(const std::string& name) 146 183 { 147 std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMapIntern().find(name);148 if (it != IdentifierManager::getStringIdentifierMapIntern().end())184 std::map<std::string, Identifier*>::const_iterator it = this->identifierByString_.find(name); 185 if (it != this->identifierByString_.end()) 149 186 return it->second; 150 187 else … … 159 196 Identifier* IdentifierManager::getIdentifierByLowercaseString(const std::string& name) 160 197 { 161 std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getLowercaseStringIdentifierMapIntern().find(name);162 if (it != IdentifierManager::getLowercaseStringIdentifierMapIntern().end())198 std::map<std::string, Identifier*>::const_iterator it = this->identifierByLowercaseString_.find(name); 199 if (it != this->identifierByLowercaseString_.end()) 163 200 return it->second; 164 201 else … … 173 210 Identifier* IdentifierManager::getIdentifierByID(const uint32_t id) 174 211 { 175 std::map<uint32_t, Identifier*>::const_iterator it = IdentifierManager::getIDIdentifierMapIntern().find(id);176 if (it != IdentifierManager::getIDIdentifierMapIntern().end())212 std::map<uint32_t, Identifier*>::const_iterator it = this->identifierByNetworkId_.find(id); 213 if (it != this->identifierByNetworkId_.end()) 177 214 return it->second; 178 215 else … … 185 222 void IdentifierManager::clearNetworkIDs() 186 223 { 187 IdentifierManager::getIDIdentifierMapIntern().clear();224 this->identifierByNetworkId_.clear(); 188 225 } 189 226 } -
code/trunk/src/libraries/core/class/IdentifierManager.h
r9564 r9667 38 38 39 39 #include <map> 40 #include <set> 40 41 #include <string> 41 42 … … 44 45 class _CoreExport IdentifierManager 45 46 { 46 friend class Identifier;47 template <class T> friend class ClassIdentifier;47 public: 48 static IdentifierManager& getInstance(); 48 49 49 public: 50 Identifier* getGloballyUniqueIdentifier(Identifier* proposal); 51 void addIdentifierToLookupMaps(Identifier* identifier); 52 53 unsigned int getUniqueClassId() 54 { return this->classIDCounter_s++; } 55 56 50 57 ///////////////////////////// 51 58 ////// Class Hierarchy ////// 52 59 ///////////////////////////// 53 static void createClassHierarchy(); 60 void createClassHierarchy(); 61 void destroyAllIdentifiers(); 62 63 void createdObject(Identifiable* identifiable); 54 64 55 65 /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. 56 inline staticbool isCreatingHierarchy()66 inline bool isCreatingHierarchy() 57 67 { return (hierarchyCreatingCounter_s > 0); } 58 68 … … 61 71 ///// Identifier Map ///// 62 72 ////////////////////////// 63 static void destroyAllIdentifiers(); 73 Identifier* getIdentifierByString(const std::string& name); 74 Identifier* getIdentifierByLowercaseString(const std::string& name); 75 Identifier* getIdentifierByID(uint32_t id); 64 76 65 static Identifier* getIdentifierByString(const std::string& name); 66 static Identifier* getIdentifierByLowercaseString(const std::string& name); 67 static Identifier* getIdentifierByID(uint32_t id); 68 69 static void clearNetworkIDs(); 77 void clearNetworkIDs(); 70 78 71 79 /// Returns the map that stores all Identifiers with their names. 72 static inline const std::map<std::string, Identifier*>& getStringIdentifierMap() 73 { return IdentifierManager::getStringIdentifierMapIntern(); } 74 /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names. 75 static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() 76 { return IdentifierManager::getStringIdentifierMap().begin(); } 77 /// Returns a const_iterator to the end of the map that stores all Identifiers with their names. 78 static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() 79 { return IdentifierManager::getStringIdentifierMap().end(); } 80 80 inline const std::map<std::string, Identifier*>& getIdentifierByStringMap() 81 { return this->identifierByString_; } 81 82 /// Returns the map that stores all Identifiers with their names in lowercase. 82 static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() 83 { return IdentifierManager::getLowercaseStringIdentifierMapIntern(); } 84 /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. 85 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() 86 { return IdentifierManager::getLowercaseStringIdentifierMap().begin(); } 87 /// Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. 88 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() 89 { return IdentifierManager::getLowercaseStringIdentifierMap().end(); } 90 83 inline const std::map<std::string, Identifier*>& getIdentifierByLowercaseStringMap() 84 { return this->identifierByLowercaseString_; } 91 85 /// Returns the map that stores all Identifiers with their IDs. 92 static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() 93 { return IdentifierManager::getIDIdentifierMapIntern(); } 94 /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs. 95 static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() 96 { return IdentifierManager::getIDIdentifierMap().begin(); } 97 /// Returns a const_iterator to the end of the map that stores all Identifiers with their IDs. 98 static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() 99 { return IdentifierManager::getIDIdentifierMap().end(); } 100 101 protected: 102 static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal); 103 104 /// Returns the map that stores all Identifiers with their names. 105 static std::map<std::string, Identifier*>& getStringIdentifierMapIntern(); 106 /// Returns the map that stores all Identifiers with their names in lowercase. 107 static std::map<std::string, Identifier*>& getLowercaseStringIdentifierMapIntern(); 108 /// Returns the map that stores all Identifiers with their network IDs. 109 static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern(); 86 inline const std::map<uint32_t, Identifier*>& getIdentifierByNetworkIdMap() 87 { return this->identifierByNetworkId_; } 110 88 111 89 private: 90 IdentifierManager(); 91 IdentifierManager(const IdentifierManager&); 92 ~IdentifierManager() {} 93 112 94 /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. 113 inline staticvoid startCreatingHierarchy()95 inline void startCreatingHierarchy() 114 96 { hierarchyCreatingCounter_s++; } 115 97 /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. 116 inline staticvoid stopCreatingHierarchy()98 inline void stopCreatingHierarchy() 117 99 { hierarchyCreatingCounter_s--; } 118 100 119 st atic std::map<std::string, Identifier*>& getTypeIDIdentifierMap();101 std::map<std::string, Identifier*> identifierByTypeidName_; //!< Map with the names as received by typeid(). This is only used internally. 120 102 121 static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) 122 static unsigned int classIDCounter_s; //!< Static counter for the unique classIDs 103 std::map<std::string, Identifier*> identifierByString_; //!< Map that stores all Identifiers with their names. 104 std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase. 105 std::map<uint32_t, Identifier*> identifierByNetworkId_; //!< Returns the map that stores all Identifiers with their network IDs. 106 107 int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) 108 std::set<const Identifier*> identifiersOfNewObject_; //!< Used while creating the object hierarchy to keep track of the identifiers of a newly created object 109 unsigned int classIDCounter_s; //!< counter for the unique classIDs 123 110 }; 124 111 } -
code/trunk/src/libraries/core/class/OrxonoxClass.h
r9585 r9667 50 50 /** 51 51 @brief This is the class from which all objects of the game-logic (not the engine) are derived from. 52 53 The BaseObject and other classes are derived with @c virtual @c public @c OrxonoxClass from OrxonoxClass.54 52 */ 55 53 class _CoreExport OrxonoxClass : virtual public Configurable, virtual public Destroyable 56 54 { 55 public: 56 OrxonoxClass(); 57 57 }; 58 58 } -
code/trunk/src/libraries/core/class/OrxonoxInterface.h
r9585 r9667 50 50 class _CoreExport OrxonoxInterface : virtual public Configurable, virtual public Destroyable 51 51 { 52 public: 53 OrxonoxInterface(); 52 54 }; 53 55 } -
code/trunk/src/libraries/core/class/SubclassIdentifier.h
r9563 r9667 163 163 164 164 /// Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T. 165 T* fabricate( BaseObject* creator) const166 { 167 OrxonoxClass* newObject = this->identifier_->fabricate(creator);165 T* fabricate(Context* context) const 166 { 167 Identifiable* newObject = this->identifier_->fabricate(context); 168 168 169 169 // Check if the creation was successful -
code/trunk/src/libraries/core/class/Super.h
r9568 r9667 103 103 { \ 104 104 ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier(); \ 105 for (std::set<const Identifier*>::iterator it = identifier->getDirectChildren Intern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it) \105 for (std::set<const Identifier*>::iterator it = identifier->getDirectChildren().begin(); it != identifier->getDirectChildren().end(); ++it) \ 106 106 { \ 107 107 if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \ … … 171 171 172 172 // Iterate through all children 173 for (std::set<const Identifier*>::iterator it = identifier->getDirectChildren Intern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it)173 for (std::set<const Identifier*>::iterator it = identifier->getDirectChildren().begin(); it != identifier->getDirectChildren().end(); ++it) 174 174 { 175 175 // Check if the caller is a fallback-caller -
code/trunk/src/libraries/core/command/ArgumentCompletionFunctions.cc
r8858 r9667 39 39 #include "util/Convert.h" 40 40 #include "util/StringUtils.h" 41 #include "core/ Identifier.h"42 #include "core/ ConfigFileManager.h"43 #include "core/ ConfigValueContainer.h"41 #include "core/class/Identifier.h" 42 #include "core/config/SettingsConfigFile.h" 43 #include "core/config/ConfigValueContainer.h" 44 44 #include "CommandExecutor.h" 45 45 #include "ConsoleCommand.h" -
code/trunk/src/libraries/core/command/Functor.h
r9550 r9667 120 120 #include "util/Output.h" 121 121 #include "util/MultiType.h" 122 #include "core/ OrxonoxClass.h"122 #include "core/object/Destroyable.h" 123 123 #include "FunctorPtr.h" 124 124 … … 303 303 /// Casts the object and registers as destruction listener. 304 304 inline void registerObject(O* object) 305 { OrxonoxClass* base = dynamic_cast<OrxonoxClass*>(object); if (base) { this->registerAsDestructionListener(base); } }305 { Destroyable* base = dynamic_cast<Destroyable*>(object); if (base) { this->registerAsDestructionListener(base); } } 306 306 /// Casts the object and unregisters as destruction listener. 307 307 inline void unregisterObject(O* object) 308 { OrxonoxClass* base = dynamic_cast<OrxonoxClass*>(object); if (base) { this->unregisterAsDestructionListener(base); } }309 310 /// Will be called by OrxonoxClass::~OrxonoxClass() if the stored object is deleted and the Functor is in safe mode.308 { Destroyable* base = dynamic_cast<Destroyable*>(object); if (base) { this->unregisterAsDestructionListener(base); } } 309 310 /// Will be called by Destroyable::~Destroyable() if the stored object is deleted and the Functor is in safe mode. 311 311 inline void objectDeleted() 312 312 { this->object_ = 0; } -
code/trunk/src/libraries/core/command/IOConsolePOSIX.cc
r9550 r9667 99 99 100 100 resetTerminalMode(); 101 this->shell_->destroy();101 delete this->shell_; 102 102 103 103 // Restore this->cout_ redirection -
code/trunk/src/libraries/core/command/IOConsoleWindows.cc
r9550 r9667 113 113 114 114 resetTerminalMode(); 115 this->shell_->destroy();115 delete this->shell_; 116 116 } 117 117 -
code/trunk/src/libraries/core/command/Shell.cc
r9550 r9667 40 40 #include "util/output/MemoryWriter.h" 41 41 #include "core/CoreIncludes.h" 42 #include "core/ ConfigFileManager.h"43 #include "core/ ConfigValueIncludes.h"42 #include "core/config/ConfigFileManager.h" 43 #include "core/config/ConfigValueIncludes.h" 44 44 #include "core/PathConfig.h" 45 45 #include "core/input/InputBuffer.h" … … 55 55 const OutputLevel User = level::user_info; 56 56 } 57 58 RegisterClassNoArgs(Shell); 57 59 58 60 /** … … 66 68 , bScrollable_(bScrollable) 67 69 { 68 Register RootObject(Shell);70 RegisterObject(Shell); 69 71 70 72 OutputManager::getInstance().registerListener(this); … … 96 98 Shell::~Shell() 97 99 { 98 this->inputBuffer_->destroy();100 delete this->inputBuffer_; 99 101 100 102 OutputManager::getInstance().unregisterListener(this); -
code/trunk/src/libraries/core/command/Shell.h
r8858 r9667 50 50 #include "util/output/BaseWriter.h" 51 51 #include "core/Core.h" 52 #include "core/OrxonoxClass.h"53 52 54 53 namespace orxonox … … 110 109 }; 111 110 112 Shell(const std::string& consoleName , bool bScrollable);111 Shell(const std::string& consoleName = "", bool bScrollable = true); 113 112 ~Shell(); 114 113 … … 200 199 unsigned int historyOffset_; ///< The command history is a circular buffer, this variable defines the current write-offset 201 200 std::vector<std::string> commandHistory_; ///< The history of commands that were entered by the user 202 static unsigned int cacheSize_s; ///< The maximum cache size of the CommandExecutor - this is stored here for better readability of the config file and because CommandExecutor is no OrxonoxClass201 static unsigned int cacheSize_s; ///< The maximum cache size of the CommandExecutor - this is stored here for better readability of the config file and because CommandExecutor is not configurable 203 202 }; 204 203 } -
code/trunk/src/libraries/core/config/CMakeLists.txt
r9560 r9667 6 6 ConfigFileManager.cc 7 7 ConfigFileSection.cc 8 Configurable.cc 8 9 ConfigValueContainer.cc 9 10 SettingsConfigFile.cc -
code/trunk/src/libraries/core/config/ConfigValueContainer.h
r9564 r9667 70 70 inline virtual void call(void* object) 71 71 { 72 if (!IdentifierManager:: isCreatingHierarchy())72 if (!IdentifierManager::getInstance().isCreatingHierarchy()) 73 73 (static_cast<T*>(object)->*this->function_)(); 74 74 } -
code/trunk/src/libraries/core/config/Configurable.h
r9577 r9667 48 48 { 49 49 public: 50 Configurable(); 51 50 52 /// Function to collect the SetConfigValue-macro calls. 51 53 void setConfigValues() {}; -
code/trunk/src/libraries/core/input/Button.cc
r8858 r9667 42 42 #include "core/command/CommandEvaluation.h" 43 43 #include "core/command/CommandExecutor.h" 44 #include "core/ ConfigFileManager.h"44 #include "core/config/ConfigFile.h" 45 45 46 46 namespace orxonox -
code/trunk/src/libraries/core/input/InputBuffer.cc
r6417 r9667 31 31 #include "util/Clipboard.h" 32 32 #include "core/CoreIncludes.h" 33 #include "core/ ConfigValueIncludes.h"33 #include "core/config/ConfigValueIncludes.h" 34 34 35 35 namespace orxonox 36 36 { 37 RegisterClassNoArgs(InputBuffer); 38 37 39 InputBuffer::InputBuffer() 38 40 { 39 Register RootObject(InputBuffer);41 RegisterObject(InputBuffer); 40 42 41 43 this->cursor_ = 0; … … 57 59 InputBuffer::InputBuffer(const std::string& allowedChars) 58 60 { 59 Register RootObject(InputBuffer);61 RegisterObject(InputBuffer); 60 62 61 63 this->maxLength_ = 1024; -
code/trunk/src/libraries/core/input/InputBuffer.h
r6417 r9667 34 34 #include <list> 35 35 #include <string> 36 #include "core/ OrxonoxClass.h"36 #include "core/config/Configurable.h" 37 37 #include "InputHandler.h" 38 38 … … 74 74 }; 75 75 76 class _CoreExport InputBuffer : public InputHandler, public OrxonoxClass76 class _CoreExport InputBuffer : public InputHandler, public Configurable 77 77 { 78 78 public: -
code/trunk/src/libraries/core/input/InputManager.cc
r9550 r9667 46 46 #include "util/Exception.h" 47 47 #include "core/CoreIncludes.h" 48 #include "core/ConfigValueIncludes.h"49 #include "core/CommandLineParser.h"50 48 #include "core/GraphicsManager.h" 49 #include "core/config/ConfigValueIncludes.h" 50 #include "core/config/CommandLineParser.h" 51 51 #include "core/command/ConsoleCommand.h" 52 52 #include "core/command/Functor.h" … … 98 98 , calibratorCallbackHandler_(0) 99 99 { 100 Register RootObject(InputManager);100 RegisterObject(InputManager); 101 101 102 102 orxout(internal_status, context::input) << "InputManager: Constructing..." << endl; … … 280 280 this->destroyState("calibrator"); 281 281 // Destroy KeyDetector and state 282 calibratorCallbackHandler_->destroy();282 delete calibratorCallbackHandler_; 283 283 // Destroy the empty InputState 284 284 this->destroyStateInternal(this->emptyState_); … … 642 642 assert(state && this->activeStates_.find(state->getPriority()) == this->activeStates_.end()); 643 643 statesByName_.erase(state->getName()); 644 state->destroy();644 delete state; 645 645 } 646 646 -
code/trunk/src/libraries/core/input/JoyStick.cc
r8858 r9667 34 34 35 35 #include "util/StringUtils.h" 36 #include "core/ConfigFileManager.h" 37 #include "core/ConfigValueIncludes.h" 36 #include "core/config/ConfigFile.h" 37 #include "core/config/ConfigFileManager.h" 38 #include "core/config/ConfigValueIncludes.h" 38 39 #include "core/CoreIncludes.h" 39 40 #include "util/Convert.h" … … 50 51 : super(id, oisInputManager) 51 52 { 52 Register RootObject(JoyStick);53 RegisterObject(JoyStick); 53 54 this->setConfigValues(); 54 55 // Initialise POV and Slider states -
code/trunk/src/libraries/core/input/JoyStick.h
r8729 r9667 36 36 #include <ois/OISJoyStick.h> 37 37 #include "InputDevice.h" 38 #include "core/config/Configurable.h" 38 39 39 40 namespace orxonox … … 58 59 */ 59 60 class _CoreExport JoyStick 60 : public OrxonoxClass61 : public Configurable 61 62 , public InputDeviceTemplated<JoyStickTraits> 62 63 , public OIS::JoyStickListener -
code/trunk/src/libraries/core/input/JoyStickQuantityListener.cc
r5781 r9667 30 30 31 31 #include "core/CoreIncludes.h" 32 #include "core/ ObjectList.h"32 #include "core/object/ObjectList.h" 33 33 34 34 namespace orxonox -
code/trunk/src/libraries/core/input/JoyStickQuantityListener.h
r8729 r9667 38 38 39 39 #include <vector> 40 #include "core/ OrxonoxClass.h"40 #include "core/object/Listable.h" 41 41 42 42 namespace orxonox 43 43 { 44 44 //! Derive from this class to get informed when joy sticks get added/removed 45 class _CoreExport JoyStickQuantityListener : virtual public OrxonoxClass45 class _CoreExport JoyStickQuantityListener : virtual public Listable 46 46 { 47 47 friend class InputManager; -
code/trunk/src/libraries/core/input/KeyBinder.cc
r8858 r9667 34 34 #include "util/Output.h" 35 35 #include "util/Exception.h" 36 #include "core/ConfigValueIncludes.h"37 36 #include "core/CoreIncludes.h" 38 #include "core/ConfigFileManager.h" 37 #include "core/config/ConfigValueIncludes.h" 38 #include "core/config/ConfigFile.h" 39 39 #include "core/PathConfig.h" 40 40 #include "InputCommands.h" … … 58 58 mousePosition_[1] = 0.0; 59 59 60 Register RootObject(KeyBinder);60 RegisterObject(KeyBinder); 61 61 62 62 // initialise all buttons and half axes to avoid creating everything with 'new' -
code/trunk/src/libraries/core/input/KeyBinderManager.cc
r8858 r9667 32 32 #include "util/Exception.h" 33 33 #include "util/ScopedSingletonManager.h" 34 #include "core/ ConfigValueIncludes.h"34 #include "core/config/ConfigValueIncludes.h" 35 35 #include "core/CoreIncludes.h" 36 36 #include "core/LuaState.h" -
code/trunk/src/libraries/core/input/KeyBinderManager.h
r8729 r9667 36 36 37 37 #include "util/Singleton.h" 38 #include "core/ OrxonoxClass.h"38 #include "core/config/Configurable.h" 39 39 40 40 namespace orxonox //tolua_export … … 53 53 */ 54 54 class _CoreExport KeyBinderManager //tolua_export 55 : public Singleton<KeyBinderManager>, public OrxonoxClass55 : public Singleton<KeyBinderManager>, public Configurable 56 56 { //tolua_export 57 57 friend class Singleton<KeyBinderManager>; -
code/trunk/src/libraries/core/input/Mouse.cc
r8729 r9667 54 54 : super(id, oisInputManager) 55 55 { 56 Register RootObject(Mouse);56 RegisterObject(Mouse); 57 57 this->windowResized(this->getWindowWidth(), this->getWindowHeight()); 58 58 -
code/trunk/src/libraries/core/object/CMakeLists.txt
r9591 r9667 3 3 Destroyable.cc 4 4 Listable.cc 5 MetaObjectList.cc6 5 ObjectListBase.cc 7 6 ) -
code/trunk/src/libraries/core/object/ClassFactory.h
r9563 r9667 43 43 44 44 #include "util/Output.h" 45 #include "core/class/Identifier.h"46 45 47 46 namespace orxonox … … 50 49 // ### Factory ### 51 50 // ########################### 52 /// Base-class of ClassFactory.51 /// Base-class of all factories. 53 52 class _CoreExport Factory 54 53 { 55 54 public: 56 virtual ~Factory() {} ;57 virtual OrxonoxClass* fabricate(BaseObject* creator) = 0;55 virtual ~Factory() {} 56 virtual Identifiable* fabricate(Context* context) = 0; 58 57 }; 59 58 … … 61 60 // ### ClassFactory ### 62 61 // ############################### 63 /// The ClassFactory is able to create new objects of a specific class.62 /// The ClassFactory is the base-class of all class-spezific factories 64 63 template <class T> 65 64 class ClassFactory : public Factory 66 65 { 66 }; 67 68 // ############################### 69 // ### ClassFactoryNoArgs ### 70 // ############################### 71 /// The ClassFactoryNoArgs is able to create new objects of a specific class that require no constructor arguments. 72 template <class T> 73 class ClassFactoryNoArgs : public ClassFactory<T> 74 { 67 75 public: 68 /**69 @brief Constructor: Adds the ClassFactory to the Identifier of the same type.70 @param name The name of the class71 @param bLoadable True if the class can be loaded through XML72 */73 ClassFactory(const std::string& name, bool bLoadable = true)74 {75 orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;76 ClassIdentifier<T>::getIdentifier(name)->addFactory(this);77 ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);78 }79 80 76 /** 81 77 @brief Creates and returns a new object of class T. 82 78 @return The new object 83 79 */ 84 inline OrxonoxClass* fabricate(BaseObject* creator)80 inline Identifiable* fabricate(Context* context) 85 81 { 86 return static_cast<OrxonoxClass*>(new T(creator)); 82 return static_cast<Identifiable*>(new T()); 83 } 84 }; 85 86 // ############################### 87 // ### ClassFactoryWithContext ### 88 // ############################### 89 /// The ClassFactoryWithContext is able to create new objects of a specific class that require a context as constructor argument 90 template <class T> 91 class ClassFactoryWithContext : public ClassFactory<T> 92 { 93 public: 94 /** 95 @brief Creates and returns a new object of class T. 96 @return The new object 97 */ 98 inline Identifiable* fabricate(Context* context) 99 { 100 return static_cast<Identifiable*>(new T(context)); 87 101 } 88 102 }; -
code/trunk/src/libraries/core/object/Context.cc
r9591 r9667 33 33 34 34 #include "Context.h" 35 #include "core/class/Identifier.h" 36 #include "core/CoreIncludes.h" 35 37 36 38 namespace orxonox 37 39 { 38 Context::Context(Context* context) : parentContext_(context) 40 RegisterClass(Context); 41 42 Context* Context::rootContext_s = 0; 43 44 Context* getContextForInitializationOfOtherContexts() 39 45 { 46 static size_t count = 0; 47 // the first time this is called, ++count returns 1 and the context is created 48 // the second time this is called, ++count returns 2 and NULL is returned because we're in the constructor of the context itself 49 // for each future call the context (now completely created) is returned 50 if (++count == 2) 51 return NULL; 52 else 53 { 54 static Context context(NULL); 55 return &context; 56 } 57 } 58 59 // Initialize Listable(*) with a special context, only used to initialize other contexts. Later in the constructor we change the context 60 Context::Context(Context* context) : Listable(getContextForInitializationOfOtherContexts()), parentContext_(context) 61 { 62 RegisterObject(Context); 63 64 // the context is its own context 65 this->setContext(this); 40 66 } 41 67 42 68 Context::~Context() 43 69 { 70 // unregister context from object lists before object lists are destroyed 71 this->unregisterObject(); 72 for (size_t i = 0; i < this->objectLists_.size(); ++i) 73 delete this->objectLists_[i]; 74 } 75 76 /*static*/ void Context::setRootContext(Context* context) 77 { 78 if (Context::rootContext_s) 79 delete Context::rootContext_s; 80 Context::rootContext_s = context; 44 81 } 45 82 46 83 /*static*/ Context* Context::getRootContext() 47 84 { 48 static Context rootContext(NULL); 49 return &rootContext; 85 if (!Context::rootContext_s) 86 Context::rootContext_s = new Context(NULL); 87 return Context::rootContext_s; 88 } 89 90 ObjectListBase* Context::getObjectList(const Identifier* identifier) 91 { 92 unsigned int classID = identifier->getClassID(); 93 if (classID >= this->objectLists_.size()) 94 this->objectLists_.resize(classID + 1); 95 if (!this->objectLists_[classID]) 96 this->objectLists_[classID] = new ObjectListBase(); 97 return this->objectLists_[classID]; 50 98 } 51 99 } -
code/trunk/src/libraries/core/object/Context.h
r9591 r9667 37 37 #include "core/CorePrereqs.h" 38 38 39 #include <vector> 40 41 #include "Listable.h" 42 39 43 namespace orxonox 40 44 { 41 class _CoreExport Context 45 class _CoreExport Context : virtual public Listable 42 46 { 43 47 public: 48 static void setRootContext(Context* context); 49 static Context* getRootContext(); 50 44 51 Context(Context* context); 45 52 virtual ~Context(); … … 48 55 { return this->parentContext_; } 49 56 50 static Context* getRootContext(); 57 ObjectListBase* getObjectList(const Identifier* identifier); 58 59 template <class T> 60 inline ObjectListBase* getObjectList() 61 { return this->getObjectList(ClassIdentifier<T>::getIdentifier()); } 62 63 template <class T> 64 inline void addObject(T* object) 65 { 66 ObjectListBaseElement* element = Listable::createObjectListElement(object); 67 this->getObjectList<T>()->addElement(element); 68 object->elements_.push_back(element); 69 if (this->getParentContext()) 70 this->getParentContext()->addObject(object); 71 } 51 72 52 73 private: 53 74 Context* parentContext_; 75 std::vector<ObjectListBase*> objectLists_; 76 77 static Context* rootContext_s; 54 78 }; 55 79 } -
code/trunk/src/libraries/core/object/Iterator.h
r9573 r9667 56 56 #include "core/CorePrereqs.h" 57 57 58 #include "core/class/Identifier.h"59 58 #include "ObjectListBase.h" 59 #include "IteratorBase.h" 60 60 61 61 namespace orxonox … … 70 70 */ 71 71 template <class T> 72 class Iterator 72 class Iterator : public IteratorBase<T, Iterator<T> > 73 73 { 74 74 public: … … 76 76 @brief Constructor: Sets the element, whereon the iterator points, to zero. 77 77 */ 78 inline Iterator() 79 { 80 this->element_ = 0; 81 this->list_ = 0; 82 } 78 inline Iterator() : IteratorBase<T, Iterator<T> >(NULL) {} 83 79 84 80 /** 85 @brief Constructor: Sets this element to the exported element.86 @param e xp The exportedelement81 @brief Constructor: Sets this element to a given element 82 @param element The element 87 83 */ 88 inline Iterator(const ObjectListBase::Export& exp) 89 { 90 this->element_ = exp.element_; 91 this->list_ = exp.list_; 92 this->list_->registerIterator(this); 93 } 84 inline Iterator(ObjectListBaseElement* element) : IteratorBase<T, Iterator<T> >(element) {} 94 85 95 86 /** … … 97 88 @param other The other Iterator 98 89 */ 99 inline Iterator(const Iterator<T>& other) 100 { 101 this->element_ = other.element_; 102 this->list_ = other.list_; 103 this->list_->registerIterator(this); 104 } 105 106 /** 107 @brief Constructor: Sets this element to a given element 108 @param element The element 109 */ 110 template <class O> 111 inline Iterator(ObjectListElement<O>* element) 112 { 113 this->element_ = element; 114 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 115 this->list_->registerIterator(this); 116 } 117 118 /** 119 @brief Constructor: Sets this element to the element an ObjectListIterator. 120 @param other The ObjectListIterator 121 */ 122 template <class O> 123 inline Iterator(const ObjectListIterator<O>& other) 124 { 125 this->element_ = other.element_; 126 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 127 this->list_->registerIterator(this); 128 } 129 130 /** 131 @brief Unregisters the Iterator from the ObjectList. 132 */ 133 inline ~Iterator() 134 { 135 this->list_->unregisterIterator(this); 136 } 137 138 /** 139 @brief Assigns an exported element. 140 @param exp The exported element 141 */ 142 inline Iterator<T>& operator=(const ObjectListBase::Export& exp) 143 { 144 if (this->list_) 145 this->list_->unregisterIterator(this); 146 147 this->element_ = exp.element_; 148 this->list_ = exp.list_; 149 this->list_->registerIterator(this); 150 151 return (*this); 152 } 153 154 /** 155 @brief Assigns the element of another Iterator. 156 @param other The other Iterator 157 */ 158 inline Iterator<T>& operator=(const Iterator<T>& other) 159 { 160 if (this->list_) 161 this->list_->unregisterIterator(this); 162 163 this->element_ = other.element_; 164 this->list_ = other.list_; 165 this->list_->registerIterator(this); 166 167 return (*this); 168 } 90 inline Iterator(const Iterator<T>& other) : IteratorBase<T, Iterator<T> >(other) {} 169 91 170 92 /** … … 172 94 @param element The element 173 95 */ 174 template <class O> 175 inline Iterator<T>& operator=(ObjectListElement<O>* element) 96 inline Iterator<T>& operator=(ObjectListBaseElement* element) 176 97 { 177 if (this->list_) 178 this->list_->unregisterIterator(this); 179 180 this->element_ = element; 181 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 182 this->list_->registerIterator(this); 183 98 this->setElement(element); 184 99 return (*this); 185 }186 187 /**188 @brief Assigns the element of an ObjectListIterator.189 @param other The ObjectListIterator190 */191 template <class O>192 inline Iterator<T>& operator=(const ObjectListIterator<O>& other)193 {194 if (this->list_)195 this->list_->unregisterIterator(this);196 197 this->element_ = other.element_;198 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();199 this->list_->registerIterator(this);200 201 return (*this);202 }203 204 /**205 @brief Overloading of the ++it operator: Iterator points to the next object in the list.206 @return The Iterator itself207 */208 inline const Iterator<T>& operator++()209 {210 this->element_ = this->element_->next_;211 return *this;212 }213 214 /**215 @brief Overloading of the it++ operator: Iterator points to the next object in the list.216 @return The Iterator itself217 */218 inline Iterator<T> operator++(int)219 {220 Iterator<T> copy = *this;221 this->element_ = this->element_->next_;222 return copy;223 }224 225 /**226 @brief Overloading of the --it operator: Iterator points to the previous object in the list.227 @return The Iterator itself228 */229 inline const Iterator<T>& operator--()230 {231 this->element_ = this->element_->prev_;232 return *this;233 }234 235 /**236 @brief Overloading of the it-- operator: Iterator points to the previous object in the list.237 @return The Iterator itself238 */239 inline Iterator<T> operator--(int i)240 {241 Iterator<T> copy = *this;242 this->element_ = this->element_->prev_;243 return copy;244 100 } 245 101 … … 261 117 return orxonox_cast<T*>(this->element_->objectBase_); 262 118 } 263 264 /**265 @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object.266 @return True if the Iterator points to an existing object.267 */268 inline operator bool() const269 {270 return (this->element_ != 0);271 }272 273 /**274 @brief Overloading of the == operator to compare with another Iterator.275 @param compare The other Iterator276 @return True if the iterators point to the same element277 */278 inline bool operator==(const Iterator<T>& compare) const279 {280 return (this->element_ == compare.element_);281 }282 283 /**284 @brief Overloading of the != operator to compare with another Iterator.285 @param compare The other Iterator286 @return True if the iterators point to different elements287 */288 inline bool operator!=(const Iterator<T>& compare) const289 {290 return (this->element_ != compare.element_);291 }292 293 /**294 @brief Increments the Iterator if it points at the given object.295 @param object The object to compare with296 */297 inline void incrementIfEqual(Listable* object)298 {299 if (this->element_ && this->element_->objectBase_ == object)300 this->operator++();301 }302 303 protected:304 ObjectListBaseElement* element_; //!< The element the Iterator points at305 ObjectListBase* list_; //!< The list wherein the element is306 119 }; 307 120 } -
code/trunk/src/libraries/core/object/Listable.cc
r9572 r9667 33 33 34 34 #include "Listable.h" 35 36 #include "core/object/MetaObjectList.h" 35 #include "core/CoreIncludes.h" 36 #include "ObjectListBase.h" 37 #include "Context.h" 37 38 38 39 namespace orxonox 39 40 { 41 RegisterClass(Listable); 42 40 43 /** 41 @brief Constructor: creates the meta-object-list.44 @brief Constructor: Allocates space in the element list. 42 45 */ 43 46 Listable::Listable() 44 47 { 45 this->metaList_ = new MetaObjectList(); 48 this->context_ = Context::getRootContext(); 49 this->elements_.reserve(6); 50 51 RegisterObject(Listable); 52 } 53 54 /** 55 @brief Constructor: Allocates space in the element list and assigns the context 56 */ 57 Listable::Listable(Context* context) 58 { 59 this->context_ = context; 60 this->elements_.reserve(6); 61 62 RegisterObject(Listable); 46 63 } 47 64 … … 59 76 void Listable::unregisterObject() 60 77 { 61 if (this->metaList_) 62 delete this->metaList_; 63 this->metaList_ = 0; 78 for (size_t i = 0; i < this->elements_.size(); ++i) 79 Listable::deleteObjectListElement(this->elements_[i]); 80 this->elements_.clear(); 81 } 82 83 /** 84 * @brief Changes the context. 85 * The object is removed from the current context and added to the new one. This also applies to all object lists the object is registered in. 86 */ 87 void Listable::setContext(Context* context) 88 { 89 assert(context); 90 std::vector<ObjectListBaseElement*> copy = this->elements_; 91 this->elements_.clear(); 92 93 for (size_t i = 0; i < copy.size(); ++i) 94 { 95 copy[i]->changeContext(this->context_, context); 96 Listable::deleteObjectListElement(copy[i]); 97 } 98 99 this->context_ = context; 100 } 101 102 /* static */ SmallObjectAllocator& Listable::getObjectListElementAllocator() 103 { 104 static SmallObjectAllocator allocator(sizeof(ObjectListElement<Listable>), 1024); 105 return allocator; 106 } 107 108 /* static */ void Listable::deleteObjectListElement(ObjectListBaseElement* element) 109 { 110 element->~ObjectListBaseElement(); 111 Listable::getObjectListElementAllocator().free(element); 64 112 } 65 113 } -
code/trunk/src/libraries/core/object/Listable.h
r9572 r9667 37 37 38 38 #include "core/CorePrereqs.h" 39 40 #include <vector> 41 39 42 #include "core/class/Identifiable.h" 40 43 … … 42 45 { 43 46 /** 44 @brief Listable stores the MetaObjectList which is used when storing instances in object lists.47 @brief Listable stores the entries of all object lists pointing to this instance. 45 48 */ 46 49 class _CoreExport Listable : virtual public Identifiable 47 50 { 48 template <class T> 49 friend class ClassIdentifier; 51 friend class Context; 50 52 51 53 public: 52 54 Listable(); 55 Listable(Context* context); 53 56 virtual ~Listable(); 54 57 55 58 void unregisterObject(); 56 59 60 void setContext(Context* context); 61 inline Context* getContext() const 62 { return this->context_; } 63 57 64 private: 58 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 65 static SmallObjectAllocator& getObjectListElementAllocator(); 66 67 template <class T> 68 static ObjectListElement<T>* createObjectListElement(T* object) 69 { 70 void* chunk = Listable::getObjectListElementAllocator().alloc(); 71 return new (chunk) ObjectListElement<T>(object); 72 } 73 74 static void deleteObjectListElement(ObjectListBaseElement* element); 75 76 Context* context_; //!< The object will register itself in the object lists of this context 77 std::vector<ObjectListBaseElement*> elements_; //!< The corresponding ObjectListElements in all object lists the object is registered in 59 78 }; 60 79 } -
code/trunk/src/libraries/core/object/ObjectList.h
r9557 r9667 49 49 #include "ObjectListBase.h" 50 50 #include "ObjectListIterator.h" 51 #include "Context.h" 51 52 52 53 namespace orxonox … … 68 69 typedef ObjectListIterator<T> iterator; 69 70 71 /// Returns the size of the list 72 inline static size_t size() 73 { 74 return Context::getRootContext()->getObjectList<T>()->size(); 75 } 76 70 77 /// Returns an Iterator to the first element in the list. 71 78 inline static ObjectListElement<T>* begin() 72 79 { 73 ObjectListBase* list = C lassIdentifier<T>::getIdentifier()->getObjects();74 return static_cast<ObjectListElement<T>*>(list->begin() .element_);80 ObjectListBase* list = Context::getRootContext()->getObjectList<T>(); 81 return static_cast<ObjectListElement<T>*>(list->begin()); 75 82 } 76 83 … … 78 85 inline static ObjectListElement<T>* end() 79 86 { 80 ObjectListBase* list = C lassIdentifier<T>::getIdentifier()->getObjects();81 return static_cast<ObjectListElement<T>*>(list->end() .element_);87 ObjectListBase* list = Context::getRootContext()->getObjectList<T>(); 88 return static_cast<ObjectListElement<T>*>(list->end()); 82 89 } 83 90 … … 85 92 inline static ObjectListElement<T>* rbegin() 86 93 { 87 ObjectListBase* list = C lassIdentifier<T>::getIdentifier()->getObjects();88 return static_cast<ObjectListElement<T>*>(list->rbegin() .element_);94 ObjectListBase* list = Context::getRootContext()->getObjectList<T>(); 95 return static_cast<ObjectListElement<T>*>(list->rbegin()); 89 96 } 90 97 … … 92 99 inline static ObjectListElement<T>* rend() 93 100 { 94 ObjectListBase* list = C lassIdentifier<T>::getIdentifier()->getObjects();95 return static_cast<ObjectListElement<T>*>(list->rend() .element_);101 ObjectListBase* list = Context::getRootContext()->getObjectList<T>(); 102 return static_cast<ObjectListElement<T>*>(list->rend()); 96 103 } 97 104 }; -
code/trunk/src/libraries/core/object/ObjectListBase.cc
r9593 r9667 41 41 namespace orxonox 42 42 { 43 // ############################### 44 // ### ObjectListBaseElement ### 45 // ############################### 46 void ObjectListBaseElement::removeFromList() 47 { 48 if (this->list_) 49 this->list_->removeElement(this); 50 } 51 52 // ############################### 53 // ### ObjectListBase ### 54 // ############################### 43 55 /** 44 56 @brief Constructor: Sets default values. … … 48 60 this->first_ = 0; 49 61 this->last_ = 0; 62 this->size_ = 0; 50 63 } 51 64 … … 55 68 ObjectListBase::~ObjectListBase() 56 69 { 57 ObjectListBaseElement* temp;58 while ( this->first_)70 ObjectListBaseElement* current = this->first_; 71 while (current) 59 72 { 60 temp = this->first_->next_; 61 delete this->first_; 62 this->first_ = temp; 73 ObjectListBaseElement* next = current->next_; 74 75 current->list_ = 0; 76 current->next_ = 0; 77 current->prev_ = 0; 78 79 current = next; 63 80 } 64 81 } 65 82 66 83 /** 67 @brief Increases all Iterators that currently point on the given element (because it gets removed). 68 @param object The object that gets removed 84 @brief Notifies all listeners that the given element is about to get removed. 85 @param element The element that gets removed 86 This is mainly used for iterators which point at the removed element 69 87 */ 70 void ObjectListBase::notify Iterators(Listable* object) const88 void ObjectListBase::notifyRemovalListeners(ObjectListBaseElement* element) const 71 89 { 72 for (std::vector<void*>::const_iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it) 73 ((Iterator<Listable>*)(*it))->incrementIfEqual(object); 74 for (std::vector<void*>::const_iterator it = this->objectListIterators_.begin(); it != this->objectListIterators_.end(); ++it) 75 ((ObjectListIterator<Listable>*)(*it))->incrementIfEqual(object); 90 for (std::vector<ObjectListElementRemovalListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 91 (*it)->removedElement(element); 76 92 } 77 93 … … 79 95 @brief Adds a new object to the end of the list. 80 96 @param element The element to add 81 @return The pointer to the new ObjectListBaseElement, needed by the MetaObjectList of the added object82 97 */ 83 ObjectListBaseElement*ObjectListBase::addElement(ObjectListBaseElement* element)98 void ObjectListBase::addElement(ObjectListBaseElement* element) 84 99 { 100 if (element->list_) 101 { 102 orxout(internal_error) << "Element is already registered in another list" << endl; 103 return; 104 } 105 106 if (element->objectBase_) 107 orxout(verbose, context::object_list) << "Added object to " << element->objectBase_->getIdentifier()->getName() << "-list." << endl; 108 85 109 if (!this->last_) 86 110 { 87 111 // If the list is empty 88 112 this->last_ = element; 89 this->first_ = this->last_; // There's only one object in the list now113 this->first_ = element; // There's only one object in the list now 90 114 } 91 115 else … … 94 118 ObjectListBaseElement* temp = this->last_; 95 119 this->last_ = element; 96 this->last_->prev_ = temp;97 temp->next_ = this->last_;120 element->prev_ = temp; 121 temp->next_ = element; 98 122 } 99 123 100 return this->last_; 124 element->list_ = this; 125 ++this->size_; 101 126 } 102 127 128 /** 129 * @brief Removes the element from the list 130 */ 103 131 void ObjectListBase::removeElement(ObjectListBaseElement* element) 104 132 { 105 orxout(verbose, context::object_list) << "Removing Object from " << element->objectBase_->getIdentifier()->getName() << "-list." << endl; 106 this->notifyIterators(element->objectBase_); 133 if (element->list_ != this) 134 { 135 orxout(internal_error) << "Element is not registered in this list" << endl; 136 return; 137 } 138 139 if (element->objectBase_) 140 orxout(verbose, context::object_list) << "Removing Object from " << element->objectBase_->getIdentifier()->getName() << "-list." << endl; 141 this->notifyRemovalListeners(element); 107 142 108 143 if (element->next_) … … 115 150 else 116 151 this->first_ = element->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list 152 153 element->list_ = 0; 154 element->next_ = 0; 155 element->prev_ = 0; 156 --this->size_; 117 157 } 118 158 } -
code/trunk/src/libraries/core/object/ObjectListBase.h
r9593 r9667 42 42 #include "core/CorePrereqs.h" 43 43 #include <vector> 44 #include "Context.h" 44 45 45 46 namespace orxonox … … 56 57 @param objectBase The object to store 57 58 */ 58 ObjectListBaseElement(Listable* objectBase) : next_(0), prev_(0), objectBase_(objectBase) {} 59 ObjectListBaseElement(Listable* object) : next_(0), prev_(0), objectBase_(object), list_(0) {} 60 virtual ~ObjectListBaseElement() { this->removeFromList(); } 61 62 virtual void changeContext(Context* oldContext, Context* newContext) = 0; 59 63 60 64 ObjectListBaseElement* next_; //!< The next element in the list 61 65 ObjectListBaseElement* prev_; //!< The previous element in the list 62 Listable* objectBase_; 66 Listable* objectBase_; //!< The object 67 ObjectListBase* list_; //!< The list 68 69 protected: 70 void removeFromList(); 63 71 }; 64 72 … … 73 81 public: 74 82 ObjectListElement(T* object) : ObjectListBaseElement(static_cast<Listable*>(object)), object_(object) {} 83 84 virtual void changeContext(Context* oldContext, Context* newContext) 85 { 86 // add object to new context, but only if this element belongs exactly to the old context (and not to a sub-context to avoid re-adding objects 87 // multiple times if they are in multiple contexts) 88 if (oldContext->getObjectList<T>() == this->list_) 89 newContext->addObject(this->object_); 90 91 // remove from old list 92 this->removeFromList(); 93 } 94 75 95 T* object_; //!< The object 76 96 }; 77 97 98 99 // ######################################## 100 // ### ObjectListElementRemovalListener ### 101 // ######################################## 102 /// Gets called by the object list if an element is removed 103 class _CoreExport ObjectListElementRemovalListener 104 { 105 public: 106 virtual ~ObjectListElementRemovalListener() {} 107 virtual void removedElement(ObjectListBaseElement* element) = 0; 108 }; 78 109 79 110 // ############################### … … 97 128 ~ObjectListBase(); 98 129 99 template <class T> 100 inline ObjectListBaseElement* add(T* object) 101 { return this->addElement(new ObjectListElement<T>(object)); } 102 103 ObjectListBaseElement* addElement(ObjectListBaseElement* element); 130 void addElement(ObjectListBaseElement* element); 104 131 void removeElement(ObjectListBaseElement* element); 105 132 106 /// Helper struct, used to export an element and the list to an instance of Iterator. 107 struct Export 108 { 109 Export(ObjectListBase* list, ObjectListBaseElement* element) : list_(list), element_(element) {} 110 ObjectListBase* list_; 111 ObjectListBaseElement* element_; 112 }; 133 size_t size() const { return this->size_; } 113 134 114 135 /// Returns a pointer to the first element in the list. Works only with Iterator. 115 inline Export begin() { return ObjectListBase::Export(this, this->first_); }136 inline ObjectListBaseElement* begin() const { return this->first_; } 116 137 /// Returns a pointer to the element after the last element in the list. Works only with Iterator. 117 inline Export end() { return ObjectListBase::Export(this, 0); }138 inline ObjectListBaseElement* end() const { return 0; } 118 139 /// Returns a pointer to the last element in the list. Works only with Iterator. 119 inline Export rbegin() { return ObjectListBase::Export(this, this->last_); }140 inline ObjectListBaseElement* rbegin() const { return this->last_; } 120 141 /// Returns a pointer to the element in front of the first element in the list. Works only with Iterator. 121 inline Export rend() { return ObjectListBase::Export(this, 0); }142 inline ObjectListBaseElement* rend() const { return 0; } 122 143 123 inline void register Iterator(void* iterator) { this->iterators_.push_back(iterator); }124 inline void unregister Iterator(void* iterator)144 inline void registerRemovalListener(ObjectListElementRemovalListener* listener) { this->listeners_.push_back(listener); } 145 inline void unregisterRemovalListener(ObjectListElementRemovalListener* listener) 125 146 { 126 for (unsigned int i = 0; i < this-> iterators_.size(); ++i)147 for (unsigned int i = 0; i < this->listeners_.size(); ++i) 127 148 { 128 if ( iterators_[i] == iterator)149 if (listeners_[i] == listener) 129 150 { 130 iterators_.erase(iterators_.begin() + i);151 listeners_.erase(listeners_.begin() + i); 131 152 break; 132 153 } 133 154 } 134 155 } 135 inline void registerObjectListIterator(void* iterator) { this->objectListIterators_.push_back(iterator); }136 inline void unregisterObjectListIterator(void* iterator)137 {138 for (unsigned int i = 0; i < this->objectListIterators_.size(); ++i)139 {140 if (objectListIterators_[i] == iterator)141 {142 objectListIterators_.erase(objectListIterators_.begin() + i);143 break;144 }145 }146 }147 void notifyIterators(Listable* object) const;148 156 149 157 private: 150 ObjectListBaseElement* first_; //!< The first element in the list 151 ObjectListBaseElement* last_; //!< The last element in the list 152 std::vector<void*> iterators_; //!< A list of Iterators pointing on an element in this list 153 std::vector<void*> objectListIterators_; //!< A list of ObjectListIterators pointing on an element in this list 158 void notifyRemovalListeners(ObjectListBaseElement* element) const; 159 160 ObjectListBaseElement* first_; //!< The first element in the list 161 ObjectListBaseElement* last_; //!< The last element in the list 162 size_t size_; //!< The number of elements in the list 163 std::vector<ObjectListElementRemovalListener*> listeners_; //!< A list of Iterators pointing on an element in this list 154 164 }; 155 165 } -
code/trunk/src/libraries/core/object/ObjectListIterator.h
r9573 r9667 58 58 #include "core/class/Identifier.h" 59 59 #include "ObjectList.h" 60 #include "IteratorBase.h" 60 61 61 62 namespace orxonox … … 67 68 */ 68 69 template <class T> 69 class ObjectListIterator 70 class ObjectListIterator : public IteratorBase<T, ObjectListIterator<T> > 70 71 { 71 template <class I>72 friend class Iterator;73 74 72 public: 75 73 /** 76 74 @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero. 77 75 */ 78 inline ObjectListIterator() 79 { 80 this->element_ = 0; 81 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this); 82 } 76 inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T> >(NULL) {} 83 77 84 78 /** … … 86 80 @param element The element to start with 87 81 */ 88 inline ObjectListIterator(ObjectListElement<T>* element) 89 { 90 this->element_ = element; 91 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this); 92 } 82 inline ObjectListIterator(ObjectListElement<T>* element) : IteratorBase<T, ObjectListIterator<T> >(element) {} 93 83 94 84 /** … … 96 86 @param other The other ObjectListIterator 97 87 */ 98 inline ObjectListIterator(const ObjectListIterator<T>& other) 99 { 100 this->element_ = other.element_; 101 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this); 102 } 103 104 /** 105 @brief Unregisters the ObjectListIterator from the ObjectList. 106 */ 107 inline ~ObjectListIterator() 108 { 109 ClassIdentifier<T>::getIdentifier()->getObjects()->unregisterObjectListIterator(this); 110 } 111 112 /** 113 @brief Assigns an ObjectListElement. 114 @param element The ObjectListElement 115 */ 116 inline ObjectListIterator<T>& operator=(ObjectListElement<T>* element) 117 { 118 this->element_ = element; 119 return (*this); 120 } 121 122 /** 123 @brief Assigns the element of another ObjectListIterator. 124 @param other The other ObjectListIterator 125 */ 126 inline ObjectListIterator<T>& operator=(const ObjectListIterator<T>& other) 127 { 128 this->element_ = other.element_; 129 return (*this); 130 } 131 132 /** 133 @brief Overloading of the ++it operator: ObjectListIterator points to the next object in the list. 134 @return The ObjectListIterator itself 135 */ 136 inline const ObjectListIterator<T>& operator++() 137 { 138 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_); 139 return *this; 140 } 141 142 /** 143 @brief Overloading of the it++ operator: ObjectListIterator points to the next object in the list. 144 @return The ObjectListIterator itself 145 */ 146 inline ObjectListIterator<T> operator++(int) 147 { 148 ObjectListIterator<T> copy = *this; 149 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_); 150 return copy; 151 } 152 153 /** 154 @brief Overloading of the --it operator: ObjectListIterator points to the previous object in the list. 155 @return The ObjectListIterator itself 156 */ 157 inline const ObjectListIterator<T>& operator--() 158 { 159 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_); 160 return *this; 161 } 162 163 /** 164 @brief Overloading of the it-- operator: ObjectListIterator points to the previous object in the list. 165 @return The ObjectListIterator itself 166 */ 167 inline ObjectListIterator<T> operator--(int i) 168 { 169 ObjectListIterator<T> copy = *this; 170 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_); 171 return copy; 172 } 88 inline ObjectListIterator(const IteratorBase<T, ObjectListIterator<T> >& other) : IteratorBase<T, ObjectListIterator<T> >(other) {} 173 89 174 90 /** … … 178 94 inline T* operator*() const 179 95 { 180 return this->element_->object_;96 return static_cast<ObjectListElement<T>*>(this->element_)->object_; 181 97 } 182 98 … … 187 103 inline T* operator->() const 188 104 { 189 return this->element_->object_;105 return static_cast<ObjectListElement<T>*>(this->element_)->object_; 190 106 } 191 192 /**193 @brief Overloading of the typecast-operator to bool: returns true if the ObjectListIterator points to an existing object.194 @return True if the ObjectListIterator points to an existing object.195 */196 inline operator bool() const197 {198 return (this->element_ != 0);199 }200 201 /**202 @brief Overloading of the == operator to compare with another ObjectListIterator.203 @param compare The other ObjectListIterator204 @return True if the ObjectListIterator point to the same element205 */206 inline bool operator==(const ObjectListIterator<T>& compare) const207 {208 return (this->element_ == compare.element_);209 }210 211 /**212 @brief Overloading of the != operator to compare with another ObjectListIterator.213 @param compare The other ObjectListIterator214 @return True if the ObjectListIterator point to different elements215 */216 inline bool operator!=(const ObjectListIterator<T>& compare) const217 {218 return (this->element_ != compare.element_);219 }220 221 /**222 @brief Increments the ObjectListIterator if it points at the given object.223 @param object The object to compare with224 */225 inline void incrementIfEqual(Listable* object)226 {227 if (this->element_ && this->element_->objectBase_ == object)228 this->operator++();229 }230 231 private:232 ObjectListElement<T>* element_; //!< The element the iterator points at233 107 }; 234 108 }
Note: See TracChangeset
for help on using the changeset viewer.