[Orxonox-commit 4895] r9564 - in code/branches/core6/src/libraries: core core/class core/config network/packet network/synchronisable

landauf at orxonox.net landauf at orxonox.net
Sun Mar 24 18:08:42 CET 2013


Author: landauf
Date: 2013-03-24 18:08:42 +0100 (Sun, 24 Mar 2013)
New Revision: 9564

Added:
   code/branches/core6/src/libraries/core/class/IdentifierManager.cc
   code/branches/core6/src/libraries/core/class/IdentifierManager.h
Modified:
   code/branches/core6/src/libraries/core/Core.cc
   code/branches/core6/src/libraries/core/CoreIncludes.h
   code/branches/core6/src/libraries/core/Template.cc
   code/branches/core6/src/libraries/core/XMLPort.cc
   code/branches/core6/src/libraries/core/class/CMakeLists.txt
   code/branches/core6/src/libraries/core/class/Identifier.cc
   code/branches/core6/src/libraries/core/class/Identifier.h
   code/branches/core6/src/libraries/core/config/ConfigValueContainer.h
   code/branches/core6/src/libraries/network/packet/ClassID.cc
   code/branches/core6/src/libraries/network/synchronisable/Synchronisable.cc
Log:
moved static functions from Identifier.cc/h to IdentifierManager.cc/h (still static though)

Modified: code/branches/core6/src/libraries/core/Core.cc
===================================================================
--- code/branches/core6/src/libraries/core/Core.cc	2013-03-24 16:33:43 UTC (rev 9563)
+++ code/branches/core6/src/libraries/core/Core.cc	2013-03-24 17:08:42 UTC (rev 9564)
@@ -197,7 +197,7 @@
 
         // creates the class hierarchy for all classes with factories
         orxout(internal_info) << "creating class hierarchy" << endl;
-        Identifier::createClassHierarchy();
+        IdentifierManager::createClassHierarchy();
 
         // Load OGRE excluding the renderer and the render window
         orxout(internal_info) << "creating GraphicsManager:" << endl;
@@ -247,7 +247,7 @@
         safeObjectDelete(&languageInstance_);
         safeObjectDelete(&configFileManager_);
         ConsoleCommand::destroyAll();
-        Identifier::destroyAllIdentifiers();
+        IdentifierManager::destroyAllIdentifiers();
         safeObjectDelete(&signalHandler_);
         safeObjectDelete(&dynLibManager_);
         safeObjectDelete(&pathConfig_);

Modified: code/branches/core6/src/libraries/core/CoreIncludes.h
===================================================================
--- code/branches/core6/src/libraries/core/CoreIncludes.h	2013-03-24 16:33:43 UTC (rev 9563)
+++ code/branches/core6/src/libraries/core/CoreIncludes.h	2013-03-24 17:08:42 UTC (rev 9564)
@@ -78,7 +78,7 @@
 #include "CorePrereqs.h"
 
 #include "util/Output.h"
-#include "class/Identifier.h"
+#include "class/IdentifierManager.h"
 #include "object/ClassFactory.h"
 #include "object/ObjectList.h"
 
@@ -141,7 +141,7 @@
     */
     inline Identifier* ClassByString(const std::string& name)
     {
-        return Identifier::getIdentifierByString(name);
+        return IdentifierManager::getIdentifierByString(name);
     }
 
     /**
@@ -150,7 +150,7 @@
     */
     inline Identifier* ClassByLowercaseString(const std::string& name)
     {
-        return Identifier::getIdentifierByLowercaseString(name);
+        return IdentifierManager::getIdentifierByLowercaseString(name);
     }
 
     /**
@@ -159,7 +159,7 @@
     */
     inline Identifier* ClassByID(uint32_t id)
     {
-        return Identifier::getIdentifierByID(id);
+        return IdentifierManager::getIdentifierByID(id);
     }
 
     /**

Modified: code/branches/core6/src/libraries/core/Template.cc
===================================================================
--- code/branches/core6/src/libraries/core/Template.cc	2013-03-24 16:33:43 UTC (rev 9563)
+++ code/branches/core6/src/libraries/core/Template.cc	2013-03-24 17:08:42 UTC (rev 9564)
@@ -149,7 +149,7 @@
         orxout(verbose, context::templates) << object->getLoaderIndentation() << " aplying Template \"" << this->getName() << "\"..." << endl;
 
         // check if the template is applied on an object of the right type
-        Identifier* identifier = Identifier::getIdentifierByString(this->getXMLElement().Value());
+        Identifier* identifier = IdentifierManager::getIdentifierByString(this->getXMLElement().Value());
         if (!object->getIdentifier()->isA(identifier))
             orxout(internal_warning, context::templates) << "Template was defined for " << identifier->getName() << " but the object is of type " << object->getIdentifier()->getName() << endl;
 

Modified: code/branches/core6/src/libraries/core/XMLPort.cc
===================================================================
--- code/branches/core6/src/libraries/core/XMLPort.cc	2013-03-24 16:33:43 UTC (rev 9563)
+++ code/branches/core6/src/libraries/core/XMLPort.cc	2013-03-24 17:08:42 UTC (rev 9564)
@@ -58,7 +58,7 @@
 
                 for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++)
                 {
-                    Identifier* identifier = Identifier::getIdentifierByString(child->Value());
+                    Identifier* identifier = IdentifierManager::getIdentifierByString(child->Value());
                     if (!identifier)
                     {
                         if (!this->sectionname_.empty())

Modified: code/branches/core6/src/libraries/core/class/CMakeLists.txt
===================================================================
--- code/branches/core6/src/libraries/core/class/CMakeLists.txt	2013-03-24 16:33:43 UTC (rev 9563)
+++ code/branches/core6/src/libraries/core/class/CMakeLists.txt	2013-03-24 17:08:42 UTC (rev 9564)
@@ -1,4 +1,5 @@
 ADD_SOURCE_FILES(CORE_SRC_FILES
   Identifier.cc
+  IdentifierManager.cc
   OrxonoxClass.cc
 )

Modified: code/branches/core6/src/libraries/core/class/Identifier.cc
===================================================================
--- code/branches/core6/src/libraries/core/class/Identifier.cc	2013-03-24 16:33:43 UTC (rev 9563)
+++ code/branches/core6/src/libraries/core/class/Identifier.cc	2013-03-24 17:08:42 UTC (rev 9564)
@@ -45,14 +45,11 @@
     // ###############################
     // ###       Identifier        ###
     // ###############################
-    int Identifier::hierarchyCreatingCounter_s = 0;
-    unsigned int Identifier::classIDCounter_s = 0;
-
     /**
         @brief Constructor: No factory, no object created, new ObjectList and a unique networkID.
     */
     Identifier::Identifier()
-        : classID_(classIDCounter_s++)
+        : classID_(IdentifierManager::classIDCounter_s++)
     {
         this->objects_ = new ObjectListBase(this);
 
@@ -86,39 +83,6 @@
     }
 
     /**
-        @brief Returns the identifier map with the names as received by typeid(). This is only used internally.
-    */
-    std::map<std::string, Identifier*>& Identifier::getTypeIDIdentifierMap()
-    {
-        static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
-        return identifiers;
-    }
-
-    /**
-        @brief Returns an identifier by name and adds it if not available
-        @param name The name of the identifier as typeid().name() suggests
-        @param proposal A pointer to a newly created identifier for the case of non existence in the map
-        @return The identifier (unique instance)
-    */
-    Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal)
-    {
-        std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
-
-        if (it != getTypeIDIdentifierMap().end())
-        {
-            // There is already an entry: return it and delete the proposal
-            delete proposal;
-            return it->second;
-        }
-        else
-        {
-            // There is no entry: put the proposal into the map and return it
-            getTypeIDIdentifierMap()[name] = proposal;
-            return proposal;
-        }
-    }
-
-    /**
         @brief Registers a class, which means that the name and the parents get stored.
         @param parents A list, containing the Identifiers of all parents of the class
         @param bRootClass True if the class is either an Interface or the BaseObject itself
@@ -126,7 +90,7 @@
     void Identifier::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass)
     {
         // Check if at least one object of the given type was created
-        if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
+        if (!this->bCreatedOneObject_ && IdentifierManager::isCreatingHierarchy())
         {
             // If no: We have to store the information and initialize the Identifier
             orxout(verbose, context::identifier) << "Register Class in ClassIdentifier<" << this->getName() << ">-Singleton -> Initialize Singleton." << endl;
@@ -186,35 +150,6 @@
     }
 
     /**
-        @brief Creates the class-hierarchy by creating and destroying one object of each type.
-    */
-    void Identifier::createClassHierarchy()
-    {
-        orxout(internal_status) << "Create class-hierarchy" << endl;
-        Identifier::startCreatingHierarchy();
-        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMap().begin(); it != Identifier::getStringIdentifierMap().end(); ++it)
-        {
-            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
-            if (it->second->hasFactory())
-            {
-                OrxonoxClass* temp = it->second->fabricate(0);
-                temp->destroy();
-            }
-        }
-        Identifier::stopCreatingHierarchy();
-        orxout(internal_status) << "Finished class-hierarchy creation" << endl;
-    }
-
-    /**
-        @brief Destroys all Identifiers. Called when exiting the program.
-    */
-    void Identifier::destroyAllIdentifiers()
-    {
-        for (std::map<std::string, Identifier*>::iterator it = Identifier::getTypeIDIdentifierMap().begin(); it != Identifier::getTypeIDIdentifierMap().end(); ++it)
-            delete (it->second);
-    }
-
-    /**
         @brief Sets the name of the class.
     */
     void Identifier::setName(const std::string& name)
@@ -223,9 +158,9 @@
         {
             this->name_ = name;
             this->bSetName_ = true;
-            Identifier::getStringIdentifierMapIntern()[name] = this;
-            Identifier::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
-            Identifier::getIDIdentifierMapIntern()[this->networkID_] = this;
+            IdentifierManager::getStringIdentifierMapIntern()[name] = this;
+            IdentifierManager::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
+            IdentifierManager::getIDIdentifierMapIntern()[this->networkID_] = this;
         }
     }
 
@@ -255,7 +190,7 @@
     void Identifier::setNetworkID(uint32_t id)
     {
 //        Identifier::getIDIdentifierMapIntern().erase(this->networkID_);
-        Identifier::getIDIdentifierMapIntern()[id] = this;
+        IdentifierManager::getIDIdentifierMapIntern()[id] = this;
         this->networkID_ = id;
     }
 
@@ -314,86 +249,6 @@
     }
 
     /**
-        @brief Returns the map that stores all Identifiers with their names.
-        @return The map
-    */
-    std::map<std::string, Identifier*>& Identifier::getStringIdentifierMapIntern()
-    {
-        static std::map<std::string, Identifier*> identifierMap;
-        return identifierMap;
-    }
-
-    /**
-        @brief Returns the map that stores all Identifiers with their names in lowercase.
-        @return The map
-    */
-    std::map<std::string, Identifier*>& Identifier::getLowercaseStringIdentifierMapIntern()
-    {
-        static std::map<std::string, Identifier*> lowercaseIdentifierMap;
-        return lowercaseIdentifierMap;
-    }
-
-    /**
-        @brief Returns the map that stores all Identifiers with their network IDs.
-        @return The map
-    */
-    std::map<uint32_t, Identifier*>& Identifier::getIDIdentifierMapIntern()
-    {
-        static std::map<uint32_t, Identifier*> identifierMap;
-        return identifierMap;
-    }
-
-    /**
-        @brief Returns the Identifier with a given name.
-        @param name The name of the wanted Identifier
-        @return The Identifier
-    */
-    Identifier* Identifier::getIdentifierByString(const std::string& name)
-    {
-        std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapIntern().find(name);
-        if (it != Identifier::getStringIdentifierMapIntern().end())
-            return it->second;
-        else
-            return 0;
-    }
-
-    /**
-        @brief Returns the Identifier with a given name in lowercase.
-        @param name The name of the wanted Identifier
-        @return The Identifier
-    */
-    Identifier* Identifier::getIdentifierByLowercaseString(const std::string& name)
-    {
-        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapIntern().find(name);
-        if (it != Identifier::getLowercaseStringIdentifierMapIntern().end())
-            return it->second;
-        else
-            return 0;
-    }
-
-    /**
-        @brief Returns the Identifier with a given network ID.
-        @param id The network ID of the wanted Identifier
-        @return The Identifier
-    */
-    Identifier* Identifier::getIdentifierByID(const uint32_t id)
-    {
-        std::map<uint32_t, Identifier*>::const_iterator it = Identifier::getIDIdentifierMapIntern().find(id);
-        if (it != Identifier::getIDIdentifierMapIntern().end())
-            return it->second;
-        else
-            return 0;
-    }
-
-    /**
-        @brief Cleans the NetworkID map (needed on clients for correct initialization)
-    */
-    void Identifier::clearNetworkIDs()
-    {
-        Identifier::getIDIdentifierMapIntern().clear();
-    }
-
-    /**
         @brief Adds the ConfigValueContainer of a variable, given by the string of its name.
         @param varname The name of the variablee
         @param container The container

Modified: code/branches/core6/src/libraries/core/class/Identifier.h
===================================================================
--- code/branches/core6/src/libraries/core/class/Identifier.h	2013-03-24 16:33:43 UTC (rev 9563)
+++ code/branches/core6/src/libraries/core/class/Identifier.h	2013-03-24 17:08:42 UTC (rev 9564)
@@ -92,6 +92,7 @@
 #include "core/object/MetaObjectList.h"
 #include "core/object/ObjectList.h"
 #include "core/object/ObjectListBase.h"
+#include "IdentifierManager.h"
 #include "Super.h"
 
 namespace orxonox
@@ -112,6 +113,8 @@
     */
     class _CoreExport Identifier
     {
+        friend class IdentifierManager;
+
         public:
             /// Returns the name of the class the Identifier belongs to.
             inline const std::string& getName() const { return this->name_; }
@@ -150,11 +153,6 @@
             /////////////////////////////
             ////// Class Hierarchy //////
             /////////////////////////////
-            static void createClassHierarchy();
-
-            /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents.
-            inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
-
             /// Returns the parents of the class the Identifier belongs to.
             inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
             /// Returns the begin-iterator of the parents-list.
@@ -184,39 +182,6 @@
             inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_.end(); }
 
 
-            //////////////////////////
-            ///// Identifier Map /////
-            //////////////////////////
-            static void destroyAllIdentifiers();
-
-            static Identifier* getIdentifierByString(const std::string& name);
-            static Identifier* getIdentifierByLowercaseString(const std::string& name);
-            static Identifier* getIdentifierByID(uint32_t id);
-
-            static void clearNetworkIDs();
-
-            /// Returns the map that stores all Identifiers with their names.
-            static inline const std::map<std::string, Identifier*>& getStringIdentifierMap() { return Identifier::getStringIdentifierMapIntern(); }
-            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names.
-            static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() { return Identifier::getStringIdentifierMap().begin(); }
-            /// Returns a const_iterator to the end of the map that stores all Identifiers with their names.
-            static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() { return Identifier::getStringIdentifierMap().end(); }
-
-            /// Returns the map that stores all Identifiers with their names in lowercase.
-            static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() { return Identifier::getLowercaseStringIdentifierMapIntern(); }
-            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase.
-            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() { return Identifier::getLowercaseStringIdentifierMap().begin(); }
-            /// Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase.
-            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() { return Identifier::getLowercaseStringIdentifierMap().end(); }
-
-            /// Returns the map that stores all Identifiers with their IDs.
-            static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() { return Identifier::getIDIdentifierMapIntern(); }
-            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs.
-            static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() { return Identifier::getIDIdentifierMap().begin(); }
-            /// Returns a const_iterator to the end of the map that stores all Identifiers with their IDs.
-            static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() { return Identifier::getIDIdentifierMap().end(); }
-
-
             /////////////////////////
             ///// Config Values /////
             /////////////////////////
@@ -258,18 +223,10 @@
             Identifier(const Identifier& identifier); // don't copy
             virtual ~Identifier();
 
-            static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
             virtual void createSuperFunctionCaller() const = 0;
 
             void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
 
-            /// Returns the map that stores all Identifiers with their names.
-            static std::map<std::string, Identifier*>& getStringIdentifierMapIntern();
-            /// Returns the map that stores all Identifiers with their names in lowercase.
-            static std::map<std::string, Identifier*>& getLowercaseStringIdentifierMapIntern();
-            /// Returns the map that stores all Identifiers with their network IDs.
-            static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern();
-
             /// Returns the children of the class the Identifier belongs to.
             inline std::set<const Identifier*>& getChildrenIntern() const { return this->children_; }
             /// Returns the direct children of the class the Identifier belongs to.
@@ -278,13 +235,6 @@
             ObjectListBase* objects_;                                      //!< The list of all objects of this class
 
         private:
-            /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
-            inline static void startCreatingHierarchy() { hierarchyCreatingCounter_s++; }
-            /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
-            inline static void stopCreatingHierarchy()  { hierarchyCreatingCounter_s--; }
-
-            static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
-
             void initialize(std::set<const Identifier*>* parents);
 
             std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
@@ -298,10 +248,8 @@
             bool bLoadable_;                                               //!< False = it's not permitted to load the object through XML
             std::string name_;                                             //!< The name of the class the Identifier belongs to
             Factory* factory_;                                             //!< The Factory, able to create new objects of the given class (if available)
-            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)
             uint32_t networkID_;                                           //!< The network ID to identify a class through the network
             const unsigned int classID_;                                   //!< Uniquely identifies a class (might not be the same as the networkID_)
-            static unsigned int classIDCounter_s;                          //!< Static counter for the unique classIDs
 
             bool bHasConfigValues_;                                        //!< True if this class has at least one assigned config value
             std::map<std::string, ConfigValueContainer*> configValues_;    //!< A map to link the string of configurable variables with their ConfigValueContainer
@@ -400,7 +348,7 @@
         ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
 
         // Get the entry from the map
-        ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal);
+        ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getIdentifierSingleton(name, proposal);
 
         if (ClassIdentifier<T>::classIdentifier_s == proposal)
         {
@@ -427,7 +375,7 @@
             orxout(verbose, context::object_list) << "Register Object: " << className << endl;
 
         object->identifier_ = this;
-        if (Identifier::isCreatingHierarchy())
+        if (IdentifierManager::isCreatingHierarchy())
         {
             if (bRootClass && !object->parents_)
                 object->parents_ = new std::set<const Identifier*>();

Copied: code/branches/core6/src/libraries/core/class/IdentifierManager.cc (from rev 9563, code/branches/core6/src/libraries/core/class/Identifier.cc)
===================================================================
--- code/branches/core6/src/libraries/core/class/IdentifierManager.cc	                        (rev 0)
+++ code/branches/core6/src/libraries/core/class/IdentifierManager.cc	2013-03-24 17:08:42 UTC (rev 9564)
@@ -0,0 +1,189 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @brief Implementation of the Identifier class.
+*/
+
+#include "IdentifierManager.h"
+
+#include <ostream>
+
+#include "util/StringUtils.h"
+#include "core/config/ConfigValueContainer.h"
+#include "core/XMLPort.h"
+#include "core/object/ClassFactory.h"
+
+namespace orxonox
+{
+    int IdentifierManager::hierarchyCreatingCounter_s = 0;
+    unsigned int IdentifierManager::classIDCounter_s = 0;
+
+    /**
+        @brief Returns the identifier map with the names as received by typeid(). This is only used internally.
+    */
+    std::map<std::string, Identifier*>& IdentifierManager::getTypeIDIdentifierMap()
+    {
+        static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
+        return identifiers;
+    }
+
+    /**
+        @brief Returns an identifier by name and adds it if not available
+        @param name The name of the identifier as typeid().name() suggests
+        @param proposal A pointer to a newly created identifier for the case of non existence in the map
+        @return The identifier (unique instance)
+    */
+    Identifier* IdentifierManager::getIdentifierSingleton(const std::string& name, Identifier* proposal)
+    {
+        std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
+
+        if (it != getTypeIDIdentifierMap().end())
+        {
+            // There is already an entry: return it and delete the proposal
+            delete proposal;
+            return it->second;
+        }
+        else
+        {
+            // There is no entry: put the proposal into the map and return it
+            getTypeIDIdentifierMap()[name] = proposal;
+            return proposal;
+        }
+    }
+
+    /**
+        @brief Creates the class-hierarchy by creating and destroying one object of each type.
+    */
+    void IdentifierManager::createClassHierarchy()
+    {
+        orxout(internal_status) << "Create class-hierarchy" << endl;
+        IdentifierManager::startCreatingHierarchy();
+        for (std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMap().begin(); it != IdentifierManager::getStringIdentifierMap().end(); ++it)
+        {
+            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
+            if (it->second->hasFactory())
+            {
+                OrxonoxClass* temp = it->second->fabricate(0);
+                temp->destroy();
+            }
+        }
+        IdentifierManager::stopCreatingHierarchy();
+        orxout(internal_status) << "Finished class-hierarchy creation" << endl;
+    }
+
+    /**
+        @brief Destroys all Identifiers. Called when exiting the program.
+    */
+    void IdentifierManager::destroyAllIdentifiers()
+    {
+        for (std::map<std::string, Identifier*>::iterator it = IdentifierManager::getTypeIDIdentifierMap().begin(); it != IdentifierManager::getTypeIDIdentifierMap().end(); ++it)
+            delete (it->second);
+    }
+
+    /**
+        @brief Returns the map that stores all Identifiers with their names.
+        @return The map
+    */
+    std::map<std::string, Identifier*>& IdentifierManager::getStringIdentifierMapIntern()
+    {
+        static std::map<std::string, Identifier*> identifierMap;
+        return identifierMap;
+    }
+
+    /**
+        @brief Returns the map that stores all Identifiers with their names in lowercase.
+        @return The map
+    */
+    std::map<std::string, Identifier*>& IdentifierManager::getLowercaseStringIdentifierMapIntern()
+    {
+        static std::map<std::string, Identifier*> lowercaseIdentifierMap;
+        return lowercaseIdentifierMap;
+    }
+
+    /**
+        @brief Returns the map that stores all Identifiers with their network IDs.
+        @return The map
+    */
+    std::map<uint32_t, Identifier*>& IdentifierManager::getIDIdentifierMapIntern()
+    {
+        static std::map<uint32_t, Identifier*> identifierMap;
+        return identifierMap;
+    }
+
+    /**
+        @brief Returns the Identifier with a given name.
+        @param name The name of the wanted Identifier
+        @return The Identifier
+    */
+    Identifier* IdentifierManager::getIdentifierByString(const std::string& name)
+    {
+        std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMapIntern().find(name);
+        if (it != IdentifierManager::getStringIdentifierMapIntern().end())
+            return it->second;
+        else
+            return 0;
+    }
+
+    /**
+        @brief Returns the Identifier with a given name in lowercase.
+        @param name The name of the wanted Identifier
+        @return The Identifier
+    */
+    Identifier* IdentifierManager::getIdentifierByLowercaseString(const std::string& name)
+    {
+        std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getLowercaseStringIdentifierMapIntern().find(name);
+        if (it != IdentifierManager::getLowercaseStringIdentifierMapIntern().end())
+            return it->second;
+        else
+            return 0;
+    }
+
+    /**
+        @brief Returns the Identifier with a given network ID.
+        @param id The network ID of the wanted Identifier
+        @return The Identifier
+    */
+    Identifier* IdentifierManager::getIdentifierByID(const uint32_t id)
+    {
+        std::map<uint32_t, Identifier*>::const_iterator it = IdentifierManager::getIDIdentifierMapIntern().find(id);
+        if (it != IdentifierManager::getIDIdentifierMapIntern().end())
+            return it->second;
+        else
+            return 0;
+    }
+
+    /**
+        @brief Cleans the NetworkID map (needed on clients for correct initialization)
+    */
+    void IdentifierManager::clearNetworkIDs()
+    {
+        IdentifierManager::getIDIdentifierMapIntern().clear();
+    }
+}

Copied: code/branches/core6/src/libraries/core/class/IdentifierManager.h (from rev 9563, code/branches/core6/src/libraries/core/class/Identifier.h)
===================================================================
--- code/branches/core6/src/libraries/core/class/IdentifierManager.h	                        (rev 0)
+++ code/branches/core6/src/libraries/core/class/IdentifierManager.h	2013-03-24 17:08:42 UTC (rev 9564)
@@ -0,0 +1,126 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @ingroup Class Identifier
+*/
+
+#ifndef _IdentifierManager_H__
+#define _IdentifierManager_H__
+
+#include "core/CorePrereqs.h"
+
+#include <map>
+#include <string>
+
+namespace orxonox
+{
+    class _CoreExport IdentifierManager
+    {
+        friend class Identifier;
+        template <class T> friend class ClassIdentifier;
+
+        public:
+            /////////////////////////////
+            ////// Class Hierarchy //////
+            /////////////////////////////
+            static void createClassHierarchy();
+
+            /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents.
+            inline static bool isCreatingHierarchy()
+                { return (hierarchyCreatingCounter_s > 0); }
+
+
+            //////////////////////////
+            ///// Identifier Map /////
+            //////////////////////////
+            static void destroyAllIdentifiers();
+
+            static Identifier* getIdentifierByString(const std::string& name);
+            static Identifier* getIdentifierByLowercaseString(const std::string& name);
+            static Identifier* getIdentifierByID(uint32_t id);
+
+            static void clearNetworkIDs();
+
+            /// Returns the map that stores all Identifiers with their names.
+            static inline const std::map<std::string, Identifier*>& getStringIdentifierMap()
+                { return IdentifierManager::getStringIdentifierMapIntern(); }
+            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names.
+            static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin()
+                { return IdentifierManager::getStringIdentifierMap().begin(); }
+            /// Returns a const_iterator to the end of the map that stores all Identifiers with their names.
+            static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd()
+                { return IdentifierManager::getStringIdentifierMap().end(); }
+
+            /// Returns the map that stores all Identifiers with their names in lowercase.
+            static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap()
+                { return IdentifierManager::getLowercaseStringIdentifierMapIntern(); }
+            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase.
+            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin()
+                { return IdentifierManager::getLowercaseStringIdentifierMap().begin(); }
+            /// Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase.
+            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd()
+                { return IdentifierManager::getLowercaseStringIdentifierMap().end(); }
+
+            /// Returns the map that stores all Identifiers with their IDs.
+            static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap()
+                { return IdentifierManager::getIDIdentifierMapIntern(); }
+            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs.
+            static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin()
+                { return IdentifierManager::getIDIdentifierMap().begin(); }
+            /// Returns a const_iterator to the end of the map that stores all Identifiers with their IDs.
+            static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd()
+                { return IdentifierManager::getIDIdentifierMap().end(); }
+
+        protected:
+            static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
+
+            /// Returns the map that stores all Identifiers with their names.
+            static std::map<std::string, Identifier*>& getStringIdentifierMapIntern();
+            /// Returns the map that stores all Identifiers with their names in lowercase.
+            static std::map<std::string, Identifier*>& getLowercaseStringIdentifierMapIntern();
+            /// Returns the map that stores all Identifiers with their network IDs.
+            static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern();
+
+        private:
+            /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
+            inline static void startCreatingHierarchy()
+                { hierarchyCreatingCounter_s++; }
+            /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
+            inline static void stopCreatingHierarchy()
+                { hierarchyCreatingCounter_s--; }
+
+            static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
+
+            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)
+            static unsigned int classIDCounter_s;                          //!< Static counter for the unique classIDs
+    };
+}
+
+#endif /* _IdentifierManager_H__ */

Modified: code/branches/core6/src/libraries/core/config/ConfigValueContainer.h
===================================================================
--- code/branches/core6/src/libraries/core/config/ConfigValueContainer.h	2013-03-24 16:33:43 UTC (rev 9563)
+++ code/branches/core6/src/libraries/core/config/ConfigValueContainer.h	2013-03-24 17:08:42 UTC (rev 9564)
@@ -69,7 +69,7 @@
             inline virtual ~ConfigValueCallback() {}
             inline virtual void call(void* object)
             {
-                if (!Identifier::isCreatingHierarchy())
+                if (!IdentifierManager::isCreatingHierarchy())
                     (static_cast<T*>(object)->*this->function_)();
             }
 

Modified: code/branches/core6/src/libraries/network/packet/ClassID.cc
===================================================================
--- code/branches/core6/src/libraries/network/packet/ClassID.cc	2013-03-24 16:33:43 UTC (rev 9563)
+++ code/branches/core6/src/libraries/network/packet/ClassID.cc	2013-03-24 17:08:42 UTC (rev 9564)
@@ -54,8 +54,8 @@
   std::queue<std::pair<uint32_t, std::string> > tempQueue;
 
   //calculate total needed size (for all strings and integers)
-  std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin();
-  for(;it != Identifier::getStringIdentifierMapEnd();++it){
+  std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMapBegin();
+  for(;it != IdentifierManager::getStringIdentifierMapEnd();++it){
     id = it->second;
     if(id == NULL || !id->hasFactory())
       continue;
@@ -128,7 +128,7 @@
 
 
   //clear the map of network ids
-  Identifier::clearNetworkIDs();
+  IdentifierManager::clearNetworkIDs();
 
   orxout(verbose, context::packets) << "=== processing classids: " << endl;
   std::pair<uint32_t, std::string> tempPair;

Modified: code/branches/core6/src/libraries/network/synchronisable/Synchronisable.cc
===================================================================
--- code/branches/core6/src/libraries/network/synchronisable/Synchronisable.cc	2013-03-24 16:33:43 UTC (rev 9563)
+++ code/branches/core6/src/libraries/network/synchronisable/Synchronisable.cc	2013-03-24 17:08:42 UTC (rev 9564)
@@ -82,7 +82,7 @@
   Synchronisable::~Synchronisable()
   {
     // delete callback function objects
-    if(!Identifier::isCreatingHierarchy()){
+    if(!IdentifierManager::isCreatingHierarchy()){
       // remove object from the static objectMap
       if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
         deletedObjects_.push(objectID_);




More information about the Orxonox-commit mailing list