Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 25, 2013, 9:08:42 PM (11 years ago)
Author:
landauf
Message:

merged core6 back to trunk

Location:
code/trunk
Files:
25 deleted
74 edited
7 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/BaseObject.cc

    r8858 r9667  
    3939#include "Event.h"
    4040#include "EventIncludes.h"
    41 #include "Iterator.h"
    4241#include "Template.h"
    4342#include "XMLFile.h"
     
    4544#include "XMLPort.h"
    4645#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...
    4749
    4850namespace orxonox
    4951{
    50     CreateFactory(BaseObject);
     52    RegisterClass(BaseObject);
    5153
    5254    /**
    5355        @brief Constructor: Registers the object in the BaseObject-list.
    5456    */
    55     BaseObject::BaseObject(BaseObject* creator) : bInitialized_(false)
    56     {
    57         RegisterRootObject(BaseObject);
     57    BaseObject::BaseObject(Context* context) : bInitialized_(false)
     58    {
     59        RegisterObject(BaseObject);
    5860
    5961        this->bInitialized_ = true;
     
    6870        this->mainStateFunctor_ = 0;
    6971
     72        if (context)
     73            this->setContext(context);
     74
     75        BaseObject* creator = orxonox_cast<BaseObject*>(context);
    7076        this->setCreator(creator);
    7177        if (this->creator_)
     
    199205        {
    200206            this->networkTemplateNames_.insert(temp->getLink());
    201            
     207
    202208            Template* link;
    203209            assert(!(link = Template::getTemplate(temp->getLink())) || !link->isLink());
  • code/trunk/src/libraries/core/BaseObject.h

    r7401 r9667  
    4949
    5050#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"
    5454
    5555namespace orxonox
     
    6060
    6161    /// The BaseObject is the parent of all classes representing an instance in the game.
    62     class _CoreExport BaseObject : virtual public OrxonoxClass
     62    class _CoreExport BaseObject : public OrxonoxClass
    6363    {
    6464        template <class T> friend class XMLPortClassParamContainer;
    6565
    6666        public:
    67             BaseObject(BaseObject* creator);
     67            BaseObject(Context* context);
    6868            virtual ~BaseObject();
    6969            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
  • code/trunk/src/libraries/core/CMakeLists.txt

    r8858 r9667  
    2222#BUILD_UNIT CoreStableBuildUnit.cc
    2323  ClassTreeMask.cc
    24   CommandLineParser.cc
    25   ConfigValueContainer.cc
    2624  DynLib.cc
    2725  DynLibManager.cc
     
    3028  GameMode.cc
    3129  GameState.cc
    32   Identifier.cc
    3330  Language.cc
    3431  Loader.cc
    3532  LuaState.cc
    36   MetaObjectList.cc
    3733  Namespace.cc
    3834  NamespaceNode.cc
    39   ObjectListBase.cc
    40   OrxonoxClass.cc
    4135  Template.cc
    4236  ViewportEventListener.cc
     
    5751BUILD_UNIT FilesystemBuildUnit.cc
    5852  command/ArgumentCompletionFunctions.cc
    59   ConfigFileManager.cc
     53  config/ConfigFile.cc
    6054  PathConfig.cc
    6155END_BUILD_UNIT
     
    6862)
    6963
     64ADD_SUBDIRECTORY(class)
    7065ADD_SUBDIRECTORY(command)
     66ADD_SUBDIRECTORY(config)
    7167ADD_SUBDIRECTORY(input)
     68ADD_SUBDIRECTORY(object)
    7269
    7370ORXONOX_ADD_LIBRARY(core
     
    7572  TOLUA_FILES
    7673    command/CommandExecutor.h
    77     ConfigFileManager.h
     74    config/SettingsConfigFile.h
    7875    Game.h
    7976    GameMode.h
  • code/trunk/src/libraries/core/ClassTreeMask.cc

    r7401 r9667  
    3333
    3434#include "ClassTreeMask.h"
    35 #include "Identifier.h"
     35#include "class/Identifier.h"
    3636
    3737namespace orxonox
     
    849849        // If there is a first subclass, move the object-iterator to the first object of this class. Else go to the end
    850850        if (this->subclassIterator_ != this->subclasses_.end())
    851             this->objectIterator_ = this->subclassIterator_->first->getObjects()->begin();
     851            this->objectIterator_ = Context::getRootContext()->getObjectList(this->subclassIterator_->first)->begin();
    852852        else
    853853            this->objectIterator_ = ObjectList<BaseObject>::end();
     
    881881                    // Check if there really is a next class. If yes, move the object-iterator to the first object
    882882                    if (this->subclassIterator_ != this->subclasses_.end())
    883                         this->objectIterator_ = this->subclassIterator_->first->getObjects()->begin();
     883                        this->objectIterator_ = Context::getRootContext()->getObjectList(this->subclassIterator_->first)->begin();
    884884                    else
    885885                        return (*this);
  • code/trunk/src/libraries/core/ClassTreeMask.h

    r7401 r9667  
    7373#include <stack>
    7474#include "BaseObject.h"
    75 #include "Iterator.h"
     75#include "object/Iterator.h"
    7676
    7777namespace orxonox
  • code/trunk/src/libraries/core/Core.cc

    r9550 r9667  
    6060#include "util/SignalHandler.h"
    6161#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"
    6565#include "CoreIncludes.h"
    6666#include "DynLibManager.h"
     
    6868#include "GraphicsManager.h"
    6969#include "GUIManager.h"
    70 #include "Identifier.h"
     70#include "class/Identifier.h"
    7171#include "Language.h"
    7272#include "LuaState.h"
    73 #include "ObjectList.h"
    7473#include "command/ConsoleCommand.h"
    7574#include "command/IOConsole.h"
     
    7776#include "command/TclThreadManager.h"
    7877#include "input/InputManager.h"
     78#include "object/ObjectList.h"
    7979
    8080namespace orxonox
     
    9191    SetCommandLineArgument(limitToCPU, 0).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is off = 0.");
    9292#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));
    9396
    9497    Core::Core(const std::string& cmdLine)
     
    176179        // Do this soon after the ConfigFileManager has been created to open up the
    177180        // possibility to configure everything below here
    178         RegisterRootObject(Core);
     181        RegisterObject(Core);
    179182        orxout(internal_info) << "configuring Core" << endl;
    180183        this->setConfigValues();
     
    198201        // creates the class hierarchy for all classes with factories
    199202        orxout(internal_info) << "creating class hierarchy" << endl;
    200         Identifier::createClassHierarchy();
     203        IdentifierManager::getInstance().createClassHierarchy();
    201204
    202205        // Load OGRE excluding the renderer and the render window
     
    248251        safeObjectDelete(&configFileManager_);
    249252        ConsoleCommand::destroyAll();
    250         Identifier::destroyAllIdentifiers();
     253        Context::setRootContext(NULL);
     254        IdentifierManager::getInstance().destroyAllIdentifiers();
    251255        safeObjectDelete(&signalHandler_);
    252256        safeObjectDelete(&dynLibManager_);
     
    508512
    509513
     514    RegisterAbstractClass(DevModeListener).inheritsFrom(Class(Listable));
     515
    510516    DevModeListener::DevModeListener()
    511517    {
    512         RegisterRootObject(DevModeListener);
     518        RegisterObject(DevModeListener);
    513519    }
    514520}
  • code/trunk/src/libraries/core/Core.h

    r8858 r9667  
    4747#include "util/DestructionHelper.h"
    4848#include "util/Singleton.h"
    49 #include "OrxonoxClass.h"
     49#include "config/Configurable.h"
    5050
    5151namespace orxonox
    5252{
    5353    //! Informs about changes in the Development Mode.
    54     class DevModeListener : virtual public OrxonoxClass
     54    class DevModeListener : virtual public Listable
    5555    {
    5656    public:
     
    6666        You should only create this singleton once because it destroys the identifiers!
    6767    */
    68     class _CoreExport Core : public Singleton<Core>, public OrxonoxClass
     68    class _CoreExport Core : public Singleton<Core>, public Configurable
    6969    {
    7070        friend class Singleton<Core>;
  • code/trunk/src/libraries/core/CoreIncludes.h

    r8858 r9667  
    2828
    2929/**
    30     @defgroup Factory RegisterObject() and CreateFactory()
     30    @defgroup Factory RegisterObject() and RegisterClass()
    3131    @ingroup Object
    3232*/
     
    3535    @file
    3636    @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.
    4648
    4749    Example:
    4850    @code
    49     // Create the factory for MyClass
    50     CreateFactory(MyClass);
     51    // register MyClass
     52    RegisterClass(MyClass);
    5153
    5254    // Constructor:
     
    7981
    8082#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)) \
    93135        return; \
    94136    else \
     
    96138
    97139/**
    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 class
    100 */
    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 class
    107 
    108     In contrast to RegisterObject, this is used for classes that inherit directly from
    109     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 class
    117 */
    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 class
    124 */
    125 #define CreateUnloadableFactory(ClassName) \
    126     Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, false)
    127 
    128 /**
    129140    @brief Returns the Identifier of the given class.
    130141    @param ClassName The name of the class
     
    137148{
    138149    /**
     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    /**
    139175        @brief Returns the Identifier with a given name.
    140176        @param name The name of the class
     
    142178    inline Identifier* ClassByString(const std::string& name)
    143179    {
    144         return Identifier::getIdentifierByString(name);
     180        return IdentifierManager::getInstance().getIdentifierByString(name);
    145181    }
    146182
     
    151187    inline Identifier* ClassByLowercaseString(const std::string& name)
    152188    {
    153         return Identifier::getIdentifierByLowercaseString(name);
     189        return IdentifierManager::getInstance().getIdentifierByLowercaseString(name);
    154190    }
    155191
     
    160196    inline Identifier* ClassByID(uint32_t id)
    161197    {
    162         return Identifier::getIdentifierByID(id);
     198        return IdentifierManager::getInstance().getIdentifierByID(id);
    163199    }
    164200
    165201    /**
    166202        @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.
    168204              The only use is in conjunction with macros that don't know the class type.
    169         @param object Pointer to an OrxonoxClass
     205        @param object Pointer to an Identifiable
    170206    */
    171207    template <class T>
  • code/trunk/src/libraries/core/CorePrereqs.h

    r8351 r9667  
    127127    class ClassFactory;
    128128    template <class T>
     129    class ClassFactoryWithContext;
     130    template <class T>
    129131    class ClassIdentifier;
    130132    class ClassTreeMask;
     
    140142    class ConfigFileManager;
    141143    class ConfigFileSection;
     144    class Configurable;
    142145    class ConfigValueContainer;
     146    class Context;
    143147    class Core;
     148    class Destroyable;
    144149    class DestructionListener;
    145150    class DynLib;
     
    154159    class GraphicsManager;
    155160    class GUIManager;
     161    class Identifiable;
    156162    class Identifier;
    157163    template <class T>
    158164    class Iterator;
    159165    class Language;
     166    class Listable;
    160167    class LuaFunctor;
    161168    class LuaState;
    162169    class MemoryArchive;
    163170    class MemoryArchiveFactory;
    164     class MetaObjectList;
    165     class MetaObjectListElement;
    166171    class Namespace;
    167172    class NamespaceNode;
     
    176181    class OgreWindowEventListener;
    177182    class OrxonoxClass;
     183    class OrxonoxInterface;
    178184    class PathConfig;
    179185    struct ResourceInfo;
  • code/trunk/src/libraries/core/Event.cc

    r8858 r9667  
    3535
    3636#include "BaseObject.h"
    37 #include "Identifier.h"
     37#include "class/Identifier.h"
    3838
    3939namespace orxonox
  • code/trunk/src/libraries/core/GUIManager.cc

    r9576 r9667  
    7878#include "util/OrxAssert.h"
    7979#include "util/output/BaseWriter.h"
    80 #include "ConfigValueIncludes.h"
     80#include "config/ConfigValueIncludes.h"
    8181#include "Core.h"
    8282#include "CoreIncludes.h"
     
    256256        , destructionHelper_(this)
    257257    {
    258         RegisterRootObject(GUIManager);
     258        RegisterObject(GUIManager);
    259259
    260260        orxout(internal_status) << "initializing GUIManager..." << endl;
  • code/trunk/src/libraries/core/GUIManager.h

    r8862 r9667  
    4949#include "util/Singleton.h"
    5050#include "input/InputHandler.h"
    51 #include "OrxonoxClass.h"
    5251#include "WindowEventListener.h"
    5352
  • code/trunk/src/libraries/core/Game.cc

    r8861 r9667  
    4444#include "util/Sleep.h"
    4545#include "util/SubString.h"
    46 #include "CommandLineParser.h"
    4746#include "Core.h"
    4847#include "CoreIncludes.h"
    49 #include "ConfigValueIncludes.h"
     48#include "config/CommandLineParser.h"
     49#include "config/ConfigValueIncludes.h"
    5050#include "GameMode.h"
    5151#include "GameState.h"
     
    112112
    113113        // Do this after the Core creation!
    114         RegisterRootObject(Game);
     114        RegisterObject(Game);
    115115        this->setConfigValues();
    116116
  • code/trunk/src/libraries/core/Game.h

    r8858 r9667  
    5050#include "util/DestructionHelper.h"
    5151#include "util/Singleton.h"
    52 #include "OrxonoxClass.h"
     52#include "config/Configurable.h"
    5353
    5454/**
     
    8282    class _CoreExport Game
    8383// tolua_end
    84         : public Singleton<Game>, public OrxonoxClass
     84        : public Singleton<Game>, public Configurable
    8585    { // tolua_export
    8686        friend class Singleton<Game>;
  • code/trunk/src/libraries/core/GraphicsManager.cc

    r8861 r9667  
    5252#include "util/StringUtils.h"
    5353#include "util/SubString.h"
    54 #include "ConfigValueIncludes.h"
     54#include "config/ConfigValueIncludes.h"
    5555#include "CoreIncludes.h"
    5656#include "Core.h"
  • code/trunk/src/libraries/core/GraphicsManager.h

    r8858 r9667  
    5252#include "util/DestructionHelper.h"
    5353#include "util/Singleton.h"
    54 #include "OrxonoxClass.h"
     54#include "config/Configurable.h"
    5555
    5656// tolua_begin
     
    6363    class _CoreExport GraphicsManager
    6464// tolua_end
    65         : public Singleton<GraphicsManager>, public OrxonoxClass, public Ogre::LogListener
     65        : public Singleton<GraphicsManager>, public Configurable, public Ogre::LogListener
    6666    { // tolua_export
    6767        friend class Singleton<GraphicsManager>;
  • code/trunk/src/libraries/core/Loader.cc

    r8858 r9667  
    3737#include "util/StringUtils.h"
    3838#include "BaseObject.h"
    39 #include "Iterator.h"
    40 #include "ObjectList.h"
    4139#include "LuaState.h"
    4240#include "Namespace.h"
    4341#include "Resource.h"
    4442#include "XMLFile.h"
     43#include "object/Iterator.h"
     44#include "object/ObjectList.h"
    4545
    4646namespace orxonox
     
    209209
    210210            orxout(verbose, context::loader) << "  creating root-namespace..." << endl;
    211             Namespace* rootNamespace = new Namespace(0);
     211            Namespace* rootNamespace = new Namespace(Context::getRootContext());
    212212            rootNamespace->setLoaderIndentation("    ");
    213213            rootNamespace->setFile(file);
  • code/trunk/src/libraries/core/Namespace.cc

    r7401 r9667  
    3838namespace orxonox
    3939{
    40     CreateFactory(Namespace);
     40    RegisterClass(Namespace);
    4141
    42     Namespace::Namespace(BaseObject* creator) : BaseObject(creator),
     42    Namespace::Namespace(Context* context) : BaseObject(context), Context(context),
    4343      bAutogeneratedFileRootNamespace_(false),
    4444      bRoot_(false),
  • code/trunk/src/libraries/core/Namespace.h

    r7401 r9667  
    4040#include <string>
    4141#include "BaseObject.h"
     42#include "object/Context.h"
    4243
    4344namespace orxonox
    4445{
    45     class Namespace : public BaseObject
     46    class Namespace : public BaseObject, public Context
    4647    {
    4748        public:
    48             Namespace(BaseObject* creator);
     49            Namespace(Context* context);
    4950            virtual ~Namespace();
    5051
  • code/trunk/src/libraries/core/PathConfig.cc

    r9550 r9667  
    5353#include "util/Output.h"
    5454#include "util/Exception.h"
    55 #include "CommandLineParser.h"
     55#include "config/CommandLineParser.h"
    5656
    5757// Differentiate Boost Filesystem v2 and v3
  • code/trunk/src/libraries/core/Template.cc

    r9348 r9667  
    3838namespace orxonox
    3939{
    40     CreateFactory(Template);
     40    RegisterClass(Template);
    4141
    42     Template::Template(BaseObject* creator) : BaseObject(creator)
     42    Template::Template(Context* context) : BaseObject(context)
    4343    {
    4444        this->xmlelement_ = new TiXmlElement("");
     
    150150
    151151        // 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());
    153153        if (!object->getIdentifier()->isA(identifier))
    154154            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  
    5151    {
    5252        public:
    53             Template(BaseObject* creator);
     53            Template(Context* context);
    5454            virtual ~Template();
    5555
  • code/trunk/src/libraries/core/ViewportEventListener.cc

    r8079 r9667  
    3232namespace orxonox
    3333{
     34    RegisterAbstractClass(ViewportEventListener).inheritsFrom(Class(Listable));
     35
    3436    ViewportEventListener::ViewportEventListener()
    3537    {
    36         RegisterRootObject(ViewportEventListener);
     38        RegisterObject(ViewportEventListener);
    3739    }
    3840}
  • code/trunk/src/libraries/core/ViewportEventListener.h

    r8729 r9667  
    3333
    3434#include "util/OgreForwardRefs.h"
    35 #include "OrxonoxClass.h"
     35#include "object/Listable.h"
    3636
    3737namespace orxonox
    3838{
    39     class _CoreExport ViewportEventListener : virtual public OrxonoxClass
     39    class _CoreExport ViewportEventListener : virtual public Listable
    4040    {
    4141        public:
  • code/trunk/src/libraries/core/WindowEventListener.cc

    r7874 r9667  
    3535    unsigned int WindowEventListener::windowHeight_s = 0;
    3636
     37    RegisterAbstractClass(WindowEventListener).inheritsFrom(Class(Listable));
     38
    3739    WindowEventListener::WindowEventListener()
    3840    {
    39         RegisterRootObject(WindowEventListener);
     41        RegisterObject(WindowEventListener);
    4042    }
    4143
  • code/trunk/src/libraries/core/WindowEventListener.h

    r7874 r9667  
    3636
    3737#include "CorePrereqs.h"
    38 #include "OrxonoxClass.h"
     38#include "object/Listable.h"
    3939
    4040namespace orxonox
    4141{
    4242    //! Interface for receiving window events like resize, moved and focusChanged
    43     class _CoreExport WindowEventListener : virtual public OrxonoxClass
     43    class _CoreExport WindowEventListener : virtual public Listable
    4444    {
    4545        friend class OgreWindowEventListener;
  • code/trunk/src/libraries/core/XMLNameListener.cc

    r5781 r9667  
    3232namespace orxonox
    3333{
     34    RegisterAbstractClass(XMLNameListener).inheritsFrom(Class(Listable));
     35
    3436    XMLNameListener::XMLNameListener()
    3537    {
    36         RegisterRootObject(XMLNameListener);
     38        RegisterObject(XMLNameListener);
    3739    }
    3840}
  • code/trunk/src/libraries/core/XMLNameListener.h

    r7401 r9667  
    3636
    3737#include "CorePrereqs.h"
    38 #include "OrxonoxClass.h"
     38#include "object/Listable.h"
    3939
    4040namespace orxonox
    4141{
    42     class _CoreExport XMLNameListener : virtual public OrxonoxClass
     42    class _CoreExport XMLNameListener : virtual public Listable
    4343    {
    4444        public:
  • code/trunk/src/libraries/core/XMLPort.cc

    r8858 r9667  
    2929#include "XMLPort.h"
    3030
     31#include "CoreIncludes.h"
    3132#include "Loader.h"
    3233#include "Namespace.h"
     
    5960                for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++)
    6061                {
    61                     Identifier* identifier = Identifier::getIdentifierByString(child->Value());
     62                    Identifier* identifier = ClassByString(child->Value());
    6263                    if (!identifier)
    6364                    {
     
    8990                        orxout(verbose, context::xml) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << endl;
    9091
    91                         BaseObject* newObject = identifier->fabricate(object);
     92                        BaseObject* newObject = orxonox_cast<BaseObject*>(identifier->fabricate(object->getContext()));
    9293                        newObject->setLoaderIndentation(object->getLoaderIndentation() + "  ");
    9394
  • code/trunk/src/libraries/core/XMLPort.h

    r9348 r9667  
    5858#include "util/OrxAssert.h"
    5959#include "util/StringUtils.h"
    60 #include "Identifier.h"
     60#include "class/Identifier.h"
    6161#include "BaseObject.h"
    6262#include "command/Executor.h"
  • code/trunk/src/libraries/core/class/CMakeLists.txt

    r9577 r9667  
    33  Identifier.cc
    44  IdentifierManager.cc
     5  OrxonoxClass.cc
     6  OrxonoxInterface.cc
    57)
  • code/trunk/src/libraries/core/class/Identifiable.cc

    r9574 r9667  
    3535
    3636#include <cassert>
     37#include "core/CoreIncludes.h"
    3738#include "core/object/Context.h"
    3839#include "Identifier.h"
     
    4041namespace orxonox
    4142{
     43    RegisterClassNoArgs(Identifiable);
     44
    4245    /**
    4346        @brief Constructor: Sets the default values.
     
    4649    {
    4750        this->identifier_ = 0;
    48         this->parents_ = 0;
    49         // Optimisation
    50         this->objectPointers_.reserve(6);
    51     }
     51        this->objectPointers_.reserve(6); // Optimisation
    5252
    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);
    6154    }
    6255
  • code/trunk/src/libraries/core/class/Identifiable.h

    r9574 r9667  
    5555        public:
    5656            Identifiable();
    57             virtual ~Identifiable();
     57            virtual ~Identifiable() {}
    5858
    5959            /// Returns the Identifier of the object.
     
    119119        private:
    120120            Identifier* identifier_;               //!< The Identifier of the object
    121             std::set<const Identifier*>* parents_; //!< List of all parents of the object
    122121
    123122            /// 'Fast map' that holds this-pointers of all derived types
  • code/trunk/src/libraries/core/class/Identifier.cc

    r9593 r9667  
    3737
    3838#include "util/StringUtils.h"
     39#include "core/CoreIncludes.h"
    3940#include "core/config/ConfigValueContainer.h"
    4041#include "core/XMLPort.h"
     
    5051    */
    5152    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    {
    5855        this->factory_ = 0;
     56        this->bInitialized_ = false;
    5957        this->bLoadable_ = false;
    6058
     
    7068    Identifier::~Identifier()
    7169    {
    72         delete this->objects_;
    73 
    7470        if (this->factory_)
    7571            delete this->factory_;
     
    8480
    8581    /**
    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 class
    88         @param bRootClass True if the class is either an Interface or the BaseObject itself
    89     */
    90     void Identifier::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass)
    91     {
    92         // Check if at least one object of the given type was created
    93         if (!this->bCreatedOneObject_ && IdentifierManager::isCreatingHierarchy())
    94         {
    95             // If no: We have to store the information and initialize the Identifier
    96             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             else
    100                 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 parents
    107     */
    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 parents
    119             for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)
    120             {
    121                 // Tell the parent we're one of it's children
    122                 (*it)->children_.insert((*it)->children_.end(), this);
    123 
    124                 // Erase all parents of our parent from our direct-parent-list
    125                 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-list
    128                     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 it
    133                             this->directParents_.erase(it2);
    134                             break;
    135                         }
    136                     }
    137                 }
    138             }
    139 
    140             // Now iterate through all direct parents
    141             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 children
    144                 (*it)->directChildren_.insert((*it)->directChildren_.end(), this);
    145 
    146                 // Create the super-function dependencies
    147                 (*it)->createSuperFunctionCaller();
    148             }
    149         }
    150     }
    151 
    152     /**
    15382        @brief Sets the name of the class.
    15483    */
    15584    void Identifier::setName(const std::string& name)
    15685    {
    157         if (!this->bSetName_)
     86        if (name != this->name_)
    15887        {
    15988            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
    166101
    167102    /**
     
    169104        @return The new object
    170105    */
    171     OrxonoxClass* Identifier::fabricate(BaseObject* creator)
     106    Identifiable* Identifier::fabricate(Context* context)
    172107    {
    173108        if (this->factory_)
    174109        {
    175             return this->factory_->fabricate(creator);
     110            return this->factory_->fabricate(context);
    176111        }
    177112        else
     
    190125    void Identifier::setNetworkID(uint32_t id)
    191126    {
    192 //        Identifier::getIDIdentifierMapIntern().erase(this->networkID_);
    193         IdentifierManager::getIDIdentifierMapIntern()[id] = this;
    194127        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;
    195227    }
    196228
  • code/trunk/src/libraries/core/class/Identifier.h

    r9593 r9667  
    5656    object->getIdentifier()->getName();                                         // returns "MyClass"
    5757
    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
    6759
    6860
     
    9082
    9183#include "util/Output.h"
    92 #include "core/object/MetaObjectList.h"
    9384#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"
    9589#include "IdentifierManager.h"
    9690#include "Super.h"
     
    112106        @note You can't directly create an Identifier, it's just the base-class of ClassIdentifier<T>.
    113107    */
    114     class _CoreExport Identifier
    115     {
    116         friend class IdentifierManager;
    117 
     108    class _CoreExport Identifier : public Destroyable
     109    {
    118110        public:
     111            Identifier();
     112            Identifier(const Identifier& identifier); // don't copy
     113            virtual ~Identifier();
     114
    119115            /// Returns the name of the class the Identifier belongs to.
    120116            inline const std::string& getName() const { return this->name_; }
    121117            void setName(const std::string& name);
    122118
     119            /// Returns the name of the class as it is returned by typeid(T).name()
     120            virtual const std::string& getTypeidName() = 0;
     121
    123122            /// Returns the network ID to identify a class through the network.
    124123            inline uint32_t getNetworkID() const { return this->networkID_; }
     
    128127            ORX_FORCEINLINE unsigned int getClassID() const { return this->classID_; }
    129128
    130             /// Returns the list of all existing objects of this class.
    131             inline ObjectListBase* getObjects() const { return this->objects_; }
    132 
    133129            /// Sets the Factory.
    134             inline void addFactory(Factory* factory) { this->factory_ = factory; }
     130            void setFactory(Factory* factory);
    135131            /// Returns true if the Identifier has a Factory.
    136132            inline bool hasFactory() const { return (this->factory_ != 0); }
    137133
    138             OrxonoxClass* fabricate(BaseObject* creator);
     134            Identifiable* fabricate(Context* context);
    139135
    140136            /// Returns true if the class can be loaded through XML.
     
    142138            /// Set the class to be loadable through XML or not.
    143139            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();
    144153
    145154            bool isA(const Identifier* identifier) const;
     
    150159            bool isDirectParentOf(const Identifier* identifier) const;
    151160
    152 
    153             /////////////////////////////
    154             ////// Class Hierarchy //////
    155             /////////////////////////////
    156161            /// Returns the parents of the class the Identifier belongs to.
    157162            inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
     
    220225
    221226        protected:
    222             Identifier();
    223             Identifier(const Identifier& identifier); // don't copy
    224             virtual ~Identifier();
    225 
    226227            virtual void createSuperFunctionCaller() const = 0;
    227228
    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 class
    236 
    237229        private:
    238             void initialize(std::set<const Identifier*>* parents);
    239 
    240230            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 to
     231            std::set<const Identifier*> children_;                         //!< The children of the class the Identifier belongs to
    242232
    243233            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
    248237            bool bLoadable_;                                               //!< False = it's not permitted to load the object through XML
    249238            std::string name_;                                             //!< The name of the class the Identifier belongs to
     
    287276            static ClassIdentifier<T>* getIdentifier(const std::string& name);
    288277
    289             bool initialiseObject(T* object, const std::string& className, bool bRootClass);
     278            bool initializeObject(T* object);
    290279
    291280            void setConfigValues(T* object, Configurable*) const;
     
    295284            void addObjectToList(T* object, Identifiable*);
    296285
    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_; }
    298290
    299291        private:
    300             static void initialiseIdentifier();
     292            static void initializeIdentifier();
     293
    301294            ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    302295            ClassIdentifier()
    303296            {
     297                this->typeidName_ = typeid(T).name();
    304298                SuperFunctionInitialization<0, T>::initialize(this);
    305299            }
     
    309303            }
    310304
    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;
    312310    };
    313311
    314312    template <class T>
    315     ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s = 0;
     313    WeakPtr<ClassIdentifier<T> > ClassIdentifier<T>::classIdentifier_s;
    316314
    317315    /**
     
    324322        // check if the Identifier already exists
    325323        if (!ClassIdentifier<T>::classIdentifier_s)
    326             ClassIdentifier<T>::initialiseIdentifier();
     324            ClassIdentifier<T>::initializeIdentifier();
    327325
    328326        return ClassIdentifier<T>::classIdentifier_s;
     
    346344    */
    347345    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.
    354349        ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
    355350
    356351        // Get the entry from the map
    357         ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getIdentifierSingleton(name, proposal);
     352        ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getGloballyUniqueIdentifier(proposal);
    358353
    359354        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;
    363356        else
    364357        {
    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)
    366360        }
    367361    }
     
    370364        @brief Adds an object of the given type to the ObjectList.
    371365        @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;
    382371
    383372        object->identifier_ = this;
    384         if (IdentifierManager::isCreatingHierarchy())
     373        if (IdentifierManager::getInstance().isCreatingHierarchy())
    385374        {
    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);
    394376
    395377            this->setConfigValues(object, object);
     
    425407     */
    426408    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);
    431413    }
    432414
     
    442424    template <class T>
    443425    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
    444432    {
    445433        if (!this->hasConfigValues())
     
    452440            for (std::set<const Identifier*>::const_iterator it = this->getChildrenBegin(); it != this->getChildrenEnd(); ++it)
    453441                (*it)->updateConfigValues(false);
     442    }
     443
     444    template <class T>
     445    void ClassIdentifier<T>::updateConfigValues(bool updateChildren, Identifiable*) const
     446    {
     447        // no action
    454448    }
    455449
  • code/trunk/src/libraries/core/class/IdentifierManager.cc

    r9564 r9667  
    3737
    3838#include "util/StringUtils.h"
     39#include "core/CoreIncludes.h"
    3940#include "core/config/ConfigValueContainer.h"
    4041#include "core/XMLPort.h"
     
    4344namespace orxonox
    4445{
    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;
    5556    }
    5657
    5758    /**
    5859        @brief Returns an identifier by name and adds it if not available
    59         @param name The name of the identifier as typeid().name() suggests
    6060        @param proposal A pointer to a newly created identifier for the case of non existence in the map
    6161        @return The identifier (unique instance)
    6262    */
    63     Identifier* IdentifierManager::getIdentifierSingleton(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 proposal
    70             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
    7171            return it->second;
    7272        }
     
    7474        {
    7575            // There is no entry: put the proposal into the map and return it
    76             getTypeIDIdentifierMap()[name] = proposal;
     76            this->identifierByTypeidName_[typeidName] = proposal;
    7777            return proposal;
    7878        }
     
    8080
    8181    /**
     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    /**
    8298        @brief Creates the class-hierarchy by creating and destroying one object of each type.
    8399    */
     
    85101    {
    86102        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)
    92115            {
    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);
    95132            }
    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();
    98149        orxout(internal_status) << "Finished class-hierarchy creation" << endl;
    99150    }
     
    104155    void IdentifierManager::destroyAllIdentifiers()
    105156    {
    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)
    107158            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;
    138175    }
    139176
     
    145182    Identifier* IdentifierManager::getIdentifierByString(const std::string& name)
    146183    {
    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())
    149186            return it->second;
    150187        else
     
    159196    Identifier* IdentifierManager::getIdentifierByLowercaseString(const std::string& name)
    160197    {
    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())
    163200            return it->second;
    164201        else
     
    173210    Identifier* IdentifierManager::getIdentifierByID(const uint32_t id)
    174211    {
    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())
    177214            return it->second;
    178215        else
     
    185222    void IdentifierManager::clearNetworkIDs()
    186223    {
    187         IdentifierManager::getIDIdentifierMapIntern().clear();
     224        this->identifierByNetworkId_.clear();
    188225    }
    189226}
  • code/trunk/src/libraries/core/class/IdentifierManager.h

    r9564 r9667  
    3838
    3939#include <map>
     40#include <set>
    4041#include <string>
    4142
     
    4445    class _CoreExport IdentifierManager
    4546    {
    46         friend class Identifier;
    47         template <class T> friend class ClassIdentifier;
     47        public:
     48            static IdentifierManager& getInstance();
    4849
    49         public:
     50            Identifier* getGloballyUniqueIdentifier(Identifier* proposal);
     51            void addIdentifierToLookupMaps(Identifier* identifier);
     52
     53            unsigned int getUniqueClassId()
     54                { return this->classIDCounter_s++; }
     55
     56
    5057            /////////////////////////////
    5158            ////// Class Hierarchy //////
    5259            /////////////////////////////
    53             static void createClassHierarchy();
     60            void createClassHierarchy();
     61            void destroyAllIdentifiers();
     62
     63            void createdObject(Identifiable* identifiable);
    5464
    5565            /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents.
    56             inline static bool isCreatingHierarchy()
     66            inline bool isCreatingHierarchy()
    5767                { return (hierarchyCreatingCounter_s > 0); }
    5868
     
    6171            ///// Identifier Map /////
    6272            //////////////////////////
    63             static void destroyAllIdentifiers();
     73            Identifier* getIdentifierByString(const std::string& name);
     74            Identifier* getIdentifierByLowercaseString(const std::string& name);
     75            Identifier* getIdentifierByID(uint32_t id);
    6476
    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();
    7078
    7179            /// 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_; }
    8182            /// 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_; }
    9185            /// 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_; }
    11088
    11189        private:
     90            IdentifierManager();
     91            IdentifierManager(const IdentifierManager&);
     92            ~IdentifierManager() {}
     93
    11294            /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
    113             inline static void startCreatingHierarchy()
     95            inline void startCreatingHierarchy()
    11496                { hierarchyCreatingCounter_s++; }
    11597            /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
    116             inline static void stopCreatingHierarchy()
     98            inline void stopCreatingHierarchy()
    11799                { hierarchyCreatingCounter_s--; }
    118100
    119             static 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.
    120102
    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
    123110    };
    124111}
  • code/trunk/src/libraries/core/class/OrxonoxClass.h

    r9585 r9667  
    5050    /**
    5151        @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.
    5452    */
    5553    class _CoreExport OrxonoxClass : virtual public Configurable, virtual public Destroyable
    5654    {
     55        public:
     56            OrxonoxClass();
    5757    };
    5858}
  • code/trunk/src/libraries/core/class/OrxonoxInterface.h

    r9585 r9667  
    5050    class _CoreExport OrxonoxInterface : virtual public Configurable, virtual public Destroyable
    5151    {
     52        public:
     53            OrxonoxInterface();
    5254    };
    5355}
  • code/trunk/src/libraries/core/class/SubclassIdentifier.h

    r9563 r9667  
    163163
    164164            /// 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) const
    166             {
    167                 OrxonoxClass* newObject = this->identifier_->fabricate(creator);
     165            T* fabricate(Context* context) const
     166            {
     167                Identifiable* newObject = this->identifier_->fabricate(context);
    168168
    169169                // Check if the creation was successful
  • code/trunk/src/libraries/core/class/Super.h

    r9568 r9667  
    103103            { \
    104104                ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier(); \
    105                 for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it) \
     105                for (std::set<const Identifier*>::iterator it = identifier->getDirectChildren().begin(); it != identifier->getDirectChildren().end(); ++it) \
    106106                { \
    107107                    if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \
     
    171171
    172172                // Iterate through all children
    173                 for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it)
     173                for (std::set<const Identifier*>::iterator it = identifier->getDirectChildren().begin(); it != identifier->getDirectChildren().end(); ++it)
    174174                {
    175175                    // Check if the caller is a fallback-caller
  • code/trunk/src/libraries/core/command/ArgumentCompletionFunctions.cc

    r8858 r9667  
    3939#include "util/Convert.h"
    4040#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"
    4444#include "CommandExecutor.h"
    4545#include "ConsoleCommand.h"
  • code/trunk/src/libraries/core/command/Functor.h

    r9550 r9667  
    120120#include "util/Output.h"
    121121#include "util/MultiType.h"
    122 #include "core/OrxonoxClass.h"
     122#include "core/object/Destroyable.h"
    123123#include "FunctorPtr.h"
    124124
     
    303303            /// Casts the object and registers as destruction listener.
    304304            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); } }
    306306            /// Casts the object and unregisters as destruction listener.
    307307            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.
    311311            inline void objectDeleted()
    312312                { this->object_ = 0; }
  • code/trunk/src/libraries/core/command/IOConsolePOSIX.cc

    r9550 r9667  
    9999
    100100        resetTerminalMode();
    101         this->shell_->destroy();
     101        delete this->shell_;
    102102
    103103        // Restore this->cout_ redirection
  • code/trunk/src/libraries/core/command/IOConsoleWindows.cc

    r9550 r9667  
    113113
    114114        resetTerminalMode();
    115         this->shell_->destroy();
     115        delete this->shell_;
    116116    }
    117117
  • code/trunk/src/libraries/core/command/Shell.cc

    r9550 r9667  
    4040#include "util/output/MemoryWriter.h"
    4141#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"
    4444#include "core/PathConfig.h"
    4545#include "core/input/InputBuffer.h"
     
    5555        const OutputLevel User = level::user_info;
    5656    }
     57
     58    RegisterClassNoArgs(Shell);
    5759
    5860    /**
     
    6668        , bScrollable_(bScrollable)
    6769    {
    68         RegisterRootObject(Shell);
     70        RegisterObject(Shell);
    6971
    7072        OutputManager::getInstance().registerListener(this);
     
    9698    Shell::~Shell()
    9799    {
    98         this->inputBuffer_->destroy();
     100        delete this->inputBuffer_;
    99101
    100102        OutputManager::getInstance().unregisterListener(this);
  • code/trunk/src/libraries/core/command/Shell.h

    r8858 r9667  
    5050#include "util/output/BaseWriter.h"
    5151#include "core/Core.h"
    52 #include "core/OrxonoxClass.h"
    5352
    5453namespace orxonox
     
    110109            };
    111110
    112             Shell(const std::string& consoleName, bool bScrollable);
     111            Shell(const std::string& consoleName = "", bool bScrollable = true);
    113112            ~Shell();
    114113
     
    200199            unsigned int              historyOffset_;       ///< The command history is a circular buffer, this variable defines the current write-offset
    201200            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 OrxonoxClass
     201            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
    203202    };
    204203}
  • code/trunk/src/libraries/core/config/CMakeLists.txt

    r9560 r9667  
    66  ConfigFileManager.cc
    77  ConfigFileSection.cc
     8  Configurable.cc
    89  ConfigValueContainer.cc
    910  SettingsConfigFile.cc
  • code/trunk/src/libraries/core/config/ConfigValueContainer.h

    r9564 r9667  
    7070            inline virtual void call(void* object)
    7171            {
    72                 if (!IdentifierManager::isCreatingHierarchy())
     72                if (!IdentifierManager::getInstance().isCreatingHierarchy())
    7373                    (static_cast<T*>(object)->*this->function_)();
    7474            }
  • code/trunk/src/libraries/core/config/Configurable.h

    r9577 r9667  
    4848    {
    4949        public:
     50            Configurable();
     51
    5052            /// Function to collect the SetConfigValue-macro calls.
    5153            void setConfigValues() {};
  • code/trunk/src/libraries/core/input/Button.cc

    r8858 r9667  
    4242#include "core/command/CommandEvaluation.h"
    4343#include "core/command/CommandExecutor.h"
    44 #include "core/ConfigFileManager.h"
     44#include "core/config/ConfigFile.h"
    4545
    4646namespace orxonox
  • code/trunk/src/libraries/core/input/InputBuffer.cc

    r6417 r9667  
    3131#include "util/Clipboard.h"
    3232#include "core/CoreIncludes.h"
    33 #include "core/ConfigValueIncludes.h"
     33#include "core/config/ConfigValueIncludes.h"
    3434
    3535namespace orxonox
    3636{
     37    RegisterClassNoArgs(InputBuffer);
     38
    3739    InputBuffer::InputBuffer()
    3840    {
    39         RegisterRootObject(InputBuffer);
     41        RegisterObject(InputBuffer);
    4042
    4143        this->cursor_ = 0;
     
    5759    InputBuffer::InputBuffer(const std::string& allowedChars)
    5860    {
    59         RegisterRootObject(InputBuffer);
     61        RegisterObject(InputBuffer);
    6062
    6163        this->maxLength_ = 1024;
  • code/trunk/src/libraries/core/input/InputBuffer.h

    r6417 r9667  
    3434#include <list>
    3535#include <string>
    36 #include "core/OrxonoxClass.h"
     36#include "core/config/Configurable.h"
    3737#include "InputHandler.h"
    3838
     
    7474    };
    7575
    76     class _CoreExport InputBuffer : public InputHandler, public OrxonoxClass
     76    class _CoreExport InputBuffer : public InputHandler, public Configurable
    7777    {
    7878        public:
  • code/trunk/src/libraries/core/input/InputManager.cc

    r9550 r9667  
    4646#include "util/Exception.h"
    4747#include "core/CoreIncludes.h"
    48 #include "core/ConfigValueIncludes.h"
    49 #include "core/CommandLineParser.h"
    5048#include "core/GraphicsManager.h"
     49#include "core/config/ConfigValueIncludes.h"
     50#include "core/config/CommandLineParser.h"
    5151#include "core/command/ConsoleCommand.h"
    5252#include "core/command/Functor.h"
     
    9898        , calibratorCallbackHandler_(0)
    9999    {
    100         RegisterRootObject(InputManager);
     100        RegisterObject(InputManager);
    101101
    102102        orxout(internal_status, context::input) << "InputManager: Constructing..." << endl;
     
    280280        this->destroyState("calibrator");
    281281        // Destroy KeyDetector and state
    282         calibratorCallbackHandler_->destroy();
     282        delete calibratorCallbackHandler_;
    283283        // Destroy the empty InputState
    284284        this->destroyStateInternal(this->emptyState_);
     
    642642        assert(state && this->activeStates_.find(state->getPriority()) == this->activeStates_.end());
    643643        statesByName_.erase(state->getName());
    644         state->destroy();
     644        delete state;
    645645    }
    646646
  • code/trunk/src/libraries/core/input/JoyStick.cc

    r8858 r9667  
    3434
    3535#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"
    3839#include "core/CoreIncludes.h"
    3940#include "util/Convert.h"
     
    5051        : super(id, oisInputManager)
    5152    {
    52         RegisterRootObject(JoyStick);
     53        RegisterObject(JoyStick);
    5354        this->setConfigValues();
    5455        // Initialise POV and Slider states
  • code/trunk/src/libraries/core/input/JoyStick.h

    r8729 r9667  
    3636#include <ois/OISJoyStick.h>
    3737#include "InputDevice.h"
     38#include "core/config/Configurable.h"
    3839
    3940namespace orxonox
     
    5859    */
    5960    class _CoreExport JoyStick
    60         : public OrxonoxClass
     61        : public Configurable
    6162        , public InputDeviceTemplated<JoyStickTraits>
    6263        , public OIS::JoyStickListener
  • code/trunk/src/libraries/core/input/JoyStickQuantityListener.cc

    r5781 r9667  
    3030
    3131#include "core/CoreIncludes.h"
    32 #include "core/ObjectList.h"
     32#include "core/object/ObjectList.h"
    3333
    3434namespace orxonox
  • code/trunk/src/libraries/core/input/JoyStickQuantityListener.h

    r8729 r9667  
    3838
    3939#include <vector>
    40 #include "core/OrxonoxClass.h"
     40#include "core/object/Listable.h"
    4141
    4242namespace orxonox
    4343{
    4444    //! Derive from this class to get informed when joy sticks get added/removed
    45     class _CoreExport JoyStickQuantityListener : virtual public OrxonoxClass
     45    class _CoreExport JoyStickQuantityListener : virtual public Listable
    4646    {
    4747        friend class InputManager;
  • code/trunk/src/libraries/core/input/KeyBinder.cc

    r8858 r9667  
    3434#include "util/Output.h"
    3535#include "util/Exception.h"
    36 #include "core/ConfigValueIncludes.h"
    3736#include "core/CoreIncludes.h"
    38 #include "core/ConfigFileManager.h"
     37#include "core/config/ConfigValueIncludes.h"
     38#include "core/config/ConfigFile.h"
    3939#include "core/PathConfig.h"
    4040#include "InputCommands.h"
     
    5858        mousePosition_[1] = 0.0;
    5959
    60         RegisterRootObject(KeyBinder);
     60        RegisterObject(KeyBinder);
    6161
    6262        // initialise all buttons and half axes to avoid creating everything with 'new'
  • code/trunk/src/libraries/core/input/KeyBinderManager.cc

    r8858 r9667  
    3232#include "util/Exception.h"
    3333#include "util/ScopedSingletonManager.h"
    34 #include "core/ConfigValueIncludes.h"
     34#include "core/config/ConfigValueIncludes.h"
    3535#include "core/CoreIncludes.h"
    3636#include "core/LuaState.h"
  • code/trunk/src/libraries/core/input/KeyBinderManager.h

    r8729 r9667  
    3636
    3737#include "util/Singleton.h"
    38 #include "core/OrxonoxClass.h"
     38#include "core/config/Configurable.h"
    3939
    4040namespace orxonox //tolua_export
     
    5353    */
    5454    class _CoreExport KeyBinderManager //tolua_export
    55         : public Singleton<KeyBinderManager>, public OrxonoxClass
     55        : public Singleton<KeyBinderManager>, public Configurable
    5656    { //tolua_export
    5757        friend class Singleton<KeyBinderManager>;
  • code/trunk/src/libraries/core/input/Mouse.cc

    r8729 r9667  
    5454        : super(id, oisInputManager)
    5555    {
    56         RegisterRootObject(Mouse);
     56        RegisterObject(Mouse);
    5757        this->windowResized(this->getWindowWidth(), this->getWindowHeight());
    5858
  • code/trunk/src/libraries/core/object/CMakeLists.txt

    r9591 r9667  
    33  Destroyable.cc
    44  Listable.cc
    5   MetaObjectList.cc
    65  ObjectListBase.cc
    76)
  • code/trunk/src/libraries/core/object/ClassFactory.h

    r9563 r9667  
    4343
    4444#include "util/Output.h"
    45 #include "core/class/Identifier.h"
    4645
    4746namespace orxonox
     
    5049    // ###       Factory       ###
    5150    // ###########################
    52     /// Base-class of ClassFactory.
     51    /// Base-class of all factories.
    5352    class _CoreExport Factory
    5453    {
    5554        public:
    56             virtual ~Factory() {};
    57             virtual OrxonoxClass* fabricate(BaseObject* creator) = 0;
     55            virtual ~Factory() {}
     56            virtual Identifiable* fabricate(Context* context) = 0;
    5857    };
    5958
     
    6160    // ###      ClassFactory       ###
    6261    // ###############################
    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
    6463    template <class T>
    6564    class ClassFactory : public Factory
    6665    {
     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    {
    6775        public:
    68             /**
    69                 @brief Constructor: Adds the ClassFactory to the Identifier of the same type.
    70                 @param name The name of the class
    71                 @param bLoadable True if the class can be loaded through XML
    72             */
    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 
    8076            /**
    8177                @brief Creates and returns a new object of class T.
    8278                @return The new object
    8379            */
    84             inline OrxonoxClass* fabricate(BaseObject* creator)
     80            inline Identifiable* fabricate(Context* context)
    8581            {
    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));
    87101            }
    88102    };
  • code/trunk/src/libraries/core/object/Context.cc

    r9591 r9667  
    3333
    3434#include "Context.h"
     35#include "core/class/Identifier.h"
     36#include "core/CoreIncludes.h"
    3537
    3638namespace orxonox
    3739{
    38     Context::Context(Context* context) : parentContext_(context)
     40    RegisterClass(Context);
     41
     42    Context* Context::rootContext_s = 0;
     43
     44    Context* getContextForInitializationOfOtherContexts()
    3945    {
     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);
    4066    }
    4167
    4268    Context::~Context()
    4369    {
     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;
    4481    }
    4582
    4683    /*static*/ Context* Context::getRootContext()
    4784    {
    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];
    5098    }
    5199}
  • code/trunk/src/libraries/core/object/Context.h

    r9591 r9667  
    3737#include "core/CorePrereqs.h"
    3838
     39#include <vector>
     40
     41#include "Listable.h"
     42
    3943namespace orxonox
    4044{
    41     class _CoreExport Context
     45    class _CoreExport Context : virtual public Listable
    4246    {
    4347        public:
     48            static void setRootContext(Context* context);
     49            static Context* getRootContext();
     50
    4451            Context(Context* context);
    4552            virtual ~Context();
     
    4855                { return this->parentContext_; }
    4956
    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            }
    5172
    5273        private:
    5374            Context* parentContext_;
     75            std::vector<ObjectListBase*> objectLists_;
     76
     77            static Context* rootContext_s;
    5478    };
    5579}
  • code/trunk/src/libraries/core/object/Iterator.h

    r9573 r9667  
    5656#include "core/CorePrereqs.h"
    5757
    58 #include "core/class/Identifier.h"
    5958#include "ObjectListBase.h"
     59#include "IteratorBase.h"
    6060
    6161namespace orxonox
     
    7070    */
    7171    template <class T>
    72     class Iterator
     72    class Iterator : public IteratorBase<T, Iterator<T> >
    7373    {
    7474        public:
     
    7676                @brief Constructor: Sets the element, whereon the iterator points, to zero.
    7777            */
    78             inline Iterator()
    79             {
    80                 this->element_ = 0;
    81                 this->list_ = 0;
    82             }
     78            inline Iterator() : IteratorBase<T, Iterator<T> >(NULL) {}
    8379
    8480            /**
    85                 @brief Constructor: Sets this element to the exported element.
    86                 @param exp The exported element
     81                @brief Constructor: Sets this element to a given element
     82                @param element The element
    8783            */
    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) {}
    9485
    9586            /**
     
    9788                @param other The other Iterator
    9889            */
    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) {}
    16991
    17092            /**
     
    17294                @param element The element
    17395            */
    174             template <class O>
    175             inline Iterator<T>& operator=(ObjectListElement<O>* element)
     96            inline Iterator<T>& operator=(ObjectListBaseElement* element)
    17697            {
    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);
    18499                return (*this);
    185             }
    186 
    187             /**
    188                 @brief Assigns the element of an ObjectListIterator.
    189                 @param other The ObjectListIterator
    190             */
    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 itself
    207             */
    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 itself
    217             */
    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 itself
    228             */
    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 itself
    238             */
    239             inline Iterator<T> operator--(int i)
    240             {
    241                 Iterator<T> copy = *this;
    242                 this->element_ = this->element_->prev_;
    243                 return copy;
    244100            }
    245101
     
    261117                return orxonox_cast<T*>(this->element_->objectBase_);
    262118            }
    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() const
    269             {
    270                 return (this->element_ != 0);
    271             }
    272 
    273             /**
    274                 @brief Overloading of the == operator to compare with another Iterator.
    275                 @param compare The other Iterator
    276                 @return True if the iterators point to the same element
    277             */
    278             inline bool operator==(const Iterator<T>& compare) const
    279             {
    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 Iterator
    286                 @return True if the iterators point to different elements
    287             */
    288             inline bool operator!=(const Iterator<T>& compare) const
    289             {
    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 with
    296             */
    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 at
    305             ObjectListBase* list_;                 //!< The list wherein the element is
    306119    };
    307120}
  • code/trunk/src/libraries/core/object/Listable.cc

    r9572 r9667  
    3333
    3434#include "Listable.h"
    35 
    36 #include "core/object/MetaObjectList.h"
     35#include "core/CoreIncludes.h"
     36#include "ObjectListBase.h"
     37#include "Context.h"
    3738
    3839namespace orxonox
    3940{
     41    RegisterClass(Listable);
     42
    4043    /**
    41         @brief Constructor: creates the meta-object-list.
     44        @brief Constructor: Allocates space in the element list.
    4245    */
    4346    Listable::Listable()
    4447    {
    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);
    4663    }
    4764
     
    5976    void Listable::unregisterObject()
    6077    {
    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);
    64112    }
    65113}
  • code/trunk/src/libraries/core/object/Listable.h

    r9572 r9667  
    3737
    3838#include "core/CorePrereqs.h"
     39
     40#include <vector>
     41
    3942#include "core/class/Identifiable.h"
    4043
     
    4245{
    4346    /**
    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.
    4548    */
    4649    class _CoreExport Listable : virtual public Identifiable
    4750    {
    48         template <class T>
    49         friend class ClassIdentifier;
     51        friend class Context;
    5052
    5153        public:
    5254            Listable();
     55            Listable(Context* context);
    5356            virtual ~Listable();
    5457
    5558            void unregisterObject();
    5659
     60            void setContext(Context* context);
     61            inline Context* getContext() const
     62                { return this->context_; }
     63
    5764        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
    5978    };
    6079}
  • code/trunk/src/libraries/core/object/ObjectList.h

    r9557 r9667  
    4949#include "ObjectListBase.h"
    5050#include "ObjectListIterator.h"
     51#include "Context.h"
    5152
    5253namespace orxonox
     
    6869            typedef ObjectListIterator<T> iterator;
    6970
     71            /// Returns the size of the list
     72            inline static size_t size()
     73            {
     74                return Context::getRootContext()->getObjectList<T>()->size();
     75            }
     76
    7077            /// Returns an Iterator to the first element in the list.
    7178            inline static ObjectListElement<T>* begin()
    7279            {
    73                 ObjectListBase* list = ClassIdentifier<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());
    7582            }
    7683
     
    7885            inline static ObjectListElement<T>* end()
    7986            {
    80                 ObjectListBase* list = ClassIdentifier<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());
    8289            }
    8390
     
    8592            inline static ObjectListElement<T>* rbegin()
    8693            {
    87                 ObjectListBase* list = ClassIdentifier<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());
    8996            }
    9097
     
    9299            inline static ObjectListElement<T>* rend()
    93100            {
    94                 ObjectListBase* list = ClassIdentifier<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());
    96103            }
    97104    };
  • code/trunk/src/libraries/core/object/ObjectListBase.cc

    r9593 r9667  
    4141namespace orxonox
    4242{
     43    // ###############################
     44    // ###  ObjectListBaseElement  ###
     45    // ###############################
     46    void ObjectListBaseElement::removeFromList()
     47    {
     48        if (this->list_)
     49            this->list_->removeElement(this);
     50    }
     51
     52    // ###############################
     53    // ###     ObjectListBase      ###
     54    // ###############################
    4355    /**
    4456        @brief Constructor: Sets default values.
     
    4860        this->first_ = 0;
    4961        this->last_ = 0;
     62        this->size_ = 0;
    5063    }
    5164
     
    5568    ObjectListBase::~ObjectListBase()
    5669    {
    57         ObjectListBaseElement* temp;
    58         while (this->first_)
     70        ObjectListBaseElement* current = this->first_;
     71        while (current)
    5972        {
    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;
    6380        }
    6481    }
    6582
    6683    /**
    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
    6987    */
    70     void ObjectListBase::notifyIterators(Listable* object) const
     88    void ObjectListBase::notifyRemovalListeners(ObjectListBaseElement* element) const
    7189    {
    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);
    7692    }
    7793
     
    7995        @brief Adds a new object to the end of the list.
    8096        @param element The element to add
    81         @return The pointer to the new ObjectListBaseElement, needed by the MetaObjectList of the added object
    8297    */
    83     ObjectListBaseElement* ObjectListBase::addElement(ObjectListBaseElement* element)
     98    void ObjectListBase::addElement(ObjectListBaseElement* element)
    8499    {
     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
    85109        if (!this->last_)
    86110        {
    87111            // If the list is empty
    88112            this->last_ = element;
    89             this->first_ = this->last_; // There's only one object in the list now
     113            this->first_ = element; // There's only one object in the list now
    90114        }
    91115        else
     
    94118            ObjectListBaseElement* temp = this->last_;
    95119            this->last_ = element;
    96             this->last_->prev_ = temp;
    97             temp->next_ = this->last_;
     120            element->prev_ = temp;
     121            temp->next_ = element;
    98122        }
    99123
    100         return this->last_;
     124        element->list_ = this;
     125        ++this->size_;
    101126    }
    102127
     128    /**
     129     * @brief Removes the element from the list
     130     */
    103131    void ObjectListBase::removeElement(ObjectListBaseElement* element)
    104132    {
    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);
    107142
    108143        if (element->next_)
     
    115150        else
    116151            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_;
    117157    }
    118158}
  • code/trunk/src/libraries/core/object/ObjectListBase.h

    r9593 r9667  
    4242#include "core/CorePrereqs.h"
    4343#include <vector>
     44#include "Context.h"
    4445
    4546namespace orxonox
     
    5657                @param objectBase The object to store
    5758            */
    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;
    5963
    6064            ObjectListBaseElement* next_;       //!< The next element in the list
    6165            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();
    6371    };
    6472
     
    7381        public:
    7482            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
    7595            T* object_;              //!< The object
    7696    };
    7797
     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    };
    78109
    79110    // ###############################
     
    97128            ~ObjectListBase();
    98129
    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);
    104131            void removeElement(ObjectListBaseElement* element);
    105132
    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_; }
    113134
    114135            /// 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_; }
    116137            /// 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; }
    118139            /// 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_; }
    120141            /// 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; }
    122143
    123             inline void registerIterator(void* iterator) { this->iterators_.push_back(iterator); }
    124             inline void unregisterIterator(void* iterator)
     144            inline void registerRemovalListener(ObjectListElementRemovalListener* listener) { this->listeners_.push_back(listener); }
     145            inline void unregisterRemovalListener(ObjectListElementRemovalListener* listener)
    125146            {
    126                 for (unsigned int i = 0; i < this->iterators_.size(); ++i)
     147                for (unsigned int i = 0; i < this->listeners_.size(); ++i)
    127148                {
    128                     if (iterators_[i] == iterator)
     149                    if (listeners_[i] == listener)
    129150                    {
    130                         iterators_.erase(iterators_.begin() + i);
     151                        listeners_.erase(listeners_.begin() + i);
    131152                        break;
    132153                    }
    133154                }
    134155            }
    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;
    148156
    149157        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
    154164    };
    155165}
  • code/trunk/src/libraries/core/object/ObjectListIterator.h

    r9573 r9667  
    5858#include "core/class/Identifier.h"
    5959#include "ObjectList.h"
     60#include "IteratorBase.h"
    6061
    6162namespace orxonox
     
    6768    */
    6869    template <class T>
    69     class ObjectListIterator
     70    class ObjectListIterator : public IteratorBase<T, ObjectListIterator<T> >
    7071    {
    71         template <class I>
    72         friend class Iterator;
    73 
    7472        public:
    7573            /**
    7674                @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero.
    7775            */
    78             inline ObjectListIterator()
    79             {
    80                 this->element_ = 0;
    81                 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
    82             }
     76            inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T> >(NULL) {}
    8377
    8478            /**
     
    8680                @param element The element to start with
    8781            */
    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) {}
    9383
    9484            /**
     
    9686                @param other The other ObjectListIterator
    9787            */
    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) {}
    17389
    17490            /**
     
    17894            inline T* operator*() const
    17995            {
    180                 return this->element_->object_;
     96                return static_cast<ObjectListElement<T>*>(this->element_)->object_;
    18197            }
    18298
     
    187103            inline T* operator->() const
    188104            {
    189                 return this->element_->object_;
     105                return static_cast<ObjectListElement<T>*>(this->element_)->object_;
    190106            }
    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() const
    197             {
    198                 return (this->element_ != 0);
    199             }
    200 
    201             /**
    202                 @brief Overloading of the == operator to compare with another ObjectListIterator.
    203                 @param compare The other ObjectListIterator
    204                 @return True if the ObjectListIterator point to the same element
    205             */
    206             inline bool operator==(const ObjectListIterator<T>& compare) const
    207             {
    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 ObjectListIterator
    214                 @return True if the ObjectListIterator point to different elements
    215             */
    216             inline bool operator!=(const ObjectListIterator<T>& compare) const
    217             {
    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 with
    224             */
    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 at
    233107    };
    234108}
Note: See TracChangeset for help on using the changeset viewer.