Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2013, 9:07:38 PM (11 years ago)
Author:
landauf
Message:

made IdentifierManager a self-initializing singleton

Location:
code/branches/core6/src/libraries
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core6/src/libraries/core/Core.cc

    r9564 r9640  
    198198        // creates the class hierarchy for all classes with factories
    199199        orxout(internal_info) << "creating class hierarchy" << endl;
    200         IdentifierManager::createClassHierarchy();
     200        IdentifierManager::getInstance().createClassHierarchy();
    201201
    202202        // Load OGRE excluding the renderer and the render window
     
    248248        safeObjectDelete(&configFileManager_);
    249249        ConsoleCommand::destroyAll();
    250         IdentifierManager::destroyAllIdentifiers();
     250        IdentifierManager::getInstance().destroyAllIdentifiers();
    251251        safeObjectDelete(&signalHandler_);
    252252        safeObjectDelete(&dynLibManager_);
  • code/branches/core6/src/libraries/core/CoreIncludes.h

    r9638 r9640  
    179179    inline Identifier* ClassByString(const std::string& name)
    180180    {
    181         return IdentifierManager::getIdentifierByString(name);
     181        return IdentifierManager::getInstance().getIdentifierByString(name);
    182182    }
    183183
     
    188188    inline Identifier* ClassByLowercaseString(const std::string& name)
    189189    {
    190         return IdentifierManager::getIdentifierByLowercaseString(name);
     190        return IdentifierManager::getInstance().getIdentifierByLowercaseString(name);
    191191    }
    192192
     
    197197    inline Identifier* ClassByID(uint32_t id)
    198198    {
    199         return IdentifierManager::getIdentifierByID(id);
     199        return IdentifierManager::getInstance().getIdentifierByID(id);
    200200    }
    201201
  • code/branches/core6/src/libraries/core/Template.cc

    r9638 r9640  
    150150
    151151        // check if the template is applied on an object of the right type
    152         Identifier* identifier = IdentifierManager::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/branches/core6/src/libraries/core/XMLPort.cc

    r9629 r9640  
    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 = IdentifierManager::getIdentifierByString(child->Value());
     62                    Identifier* identifier = ClassByString(child->Value());
    6263                    if (!identifier)
    6364                    {
  • code/branches/core6/src/libraries/core/class/Identifier.cc

    r9632 r9640  
    5050    */
    5151    Identifier::Identifier()
    52         : classID_(IdentifierManager::classIDCounter_s++)
     52        : classID_(IdentifierManager::getInstance().classIDCounter_s++)
    5353    {
    5454        this->bCreatedOneObject_ = false;
     
    8787    {
    8888        // Check if at least one object of the given type was created
    89         if (!this->bCreatedOneObject_ && IdentifierManager::isCreatingHierarchy())
     89        if (!this->bCreatedOneObject_ && IdentifierManager::getInstance().isCreatingHierarchy())
    9090        {
    9191            // If no: We have to store the information and initialize the Identifier
     
    155155            this->name_ = name;
    156156            this->bSetName_ = true;
    157             IdentifierManager::getStringIdentifierMapIntern()[name] = this;
    158             IdentifierManager::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
    159             IdentifierManager::getIDIdentifierMapIntern()[this->networkID_] = this;
     157            IdentifierManager::getInstance().identifierByString_[name] = this;
     158            IdentifierManager::getInstance().identifierByLowercaseString_[getLowercase(name)] = this;
     159            IdentifierManager::getInstance().identifierByNetworkId_[this->networkID_] = this;
    160160        }
    161161    }
     
    196196    {
    197197//        Identifier::getIDIdentifierMapIntern().erase(this->networkID_);
    198         IdentifierManager::getIDIdentifierMapIntern()[id] = this;
     198        IdentifierManager::getInstance().identifierByNetworkId_[id] = this;
    199199        this->networkID_ = id;
    200200    }
  • code/branches/core6/src/libraries/core/class/Identifier.h

    r9634 r9640  
    346346
    347347        // Get the entry from the map
    348         ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getIdentifierSingleton(name, proposal);
     348        ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getIdentifierSingleton(name, proposal);
    349349
    350350        if (ClassIdentifier<T>::classIdentifier_s == proposal)
     
    373373
    374374        object->identifier_ = this;
    375         if (IdentifierManager::isCreatingHierarchy())
     375        if (IdentifierManager::getInstance().isCreatingHierarchy())
    376376        {
    377377            if (bRootClass && !object->parents_)
  • code/branches/core6/src/libraries/core/class/IdentifierManager.cc

    r9634 r9640  
    4343namespace orxonox
    4444{
    45     int IdentifierManager::hierarchyCreatingCounter_s = 0;
    46     unsigned int IdentifierManager::classIDCounter_s = 0;
     45    /* static */ IdentifierManager& IdentifierManager::getInstance()
     46    {
     47        static IdentifierManager instance;
     48        return instance;
     49    }
    4750
    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()
     51    IdentifierManager::IdentifierManager()
    5252    {
    53         static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
    54         return identifiers;
     53        this->hierarchyCreatingCounter_s = 0;
     54        this->classIDCounter_s = 0;
    5555    }
    5656
     
    6363    Identifier* IdentifierManager::getIdentifierSingleton(const std::string& name, Identifier* proposal)
    6464    {
    65         std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
     65        std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeId_.find(name);
    6666
    67         if (it != getTypeIDIdentifierMap().end())
     67        if (it != this->identifierByTypeId_.end())
    6868        {
    6969            // There is already an entry: return it and delete the proposal
     
    7474        {
    7575            // There is no entry: put the proposal into the map and return it
    76             getTypeIDIdentifierMap()[name] = proposal;
     76            this->identifierByTypeId_[name] = proposal;
    7777            return proposal;
    7878        }
     
    8585    {
    8686        orxout(internal_status) << "Create class-hierarchy" << endl;
    87         IdentifierManager::startCreatingHierarchy();
    88         for (std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getTypeIDIdentifierMap().begin(); it != IdentifierManager::getTypeIDIdentifierMap().end(); ++it)
     87        this->startCreatingHierarchy();
     88        for (std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeId_.begin(); it != this->identifierByTypeId_.end(); ++it)
    8989        {
    9090            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     
    9595            }
    9696        }
    97         IdentifierManager::stopCreatingHierarchy();
     97        this->stopCreatingHierarchy();
    9898        orxout(internal_status) << "Finished class-hierarchy creation" << endl;
    9999    }
     
    104104    void IdentifierManager::destroyAllIdentifiers()
    105105    {
    106         for (std::map<std::string, Identifier*>::iterator it = IdentifierManager::getTypeIDIdentifierMap().begin(); it != IdentifierManager::getTypeIDIdentifierMap().end(); ++it)
     106        for (std::map<std::string, Identifier*>::iterator it = this->identifierByTypeId_.begin(); it != this->identifierByTypeId_.end(); ++it)
    107107            delete (it->second);
    108108
    109         IdentifierManager::getTypeIDIdentifierMap().clear();
    110         IdentifierManager::getStringIdentifierMapIntern().clear();
    111         IdentifierManager::getLowercaseStringIdentifierMapIntern().clear();
    112         IdentifierManager::getIDIdentifierMapIntern().clear();
    113     }
    114 
    115     /**
    116         @brief Returns the map that stores all Identifiers with their names.
    117         @return The map
    118     */
    119     std::map<std::string, Identifier*>& IdentifierManager::getStringIdentifierMapIntern()
    120     {
    121         static std::map<std::string, Identifier*> identifierMap;
    122         return identifierMap;
    123     }
    124 
    125     /**
    126         @brief Returns the map that stores all Identifiers with their names in lowercase.
    127         @return The map
    128     */
    129     std::map<std::string, Identifier*>& IdentifierManager::getLowercaseStringIdentifierMapIntern()
    130     {
    131         static std::map<std::string, Identifier*> lowercaseIdentifierMap;
    132         return lowercaseIdentifierMap;
    133     }
    134 
    135     /**
    136         @brief Returns the map that stores all Identifiers with their network IDs.
    137         @return The map
    138     */
    139     std::map<uint32_t, Identifier*>& IdentifierManager::getIDIdentifierMapIntern()
    140     {
    141         static std::map<uint32_t, Identifier*> identifierMap;
    142         return identifierMap;
     109        this->identifierByTypeId_.clear();
     110        this->identifierByString_.clear();
     111        this->identifierByLowercaseString_.clear();
     112        this->identifierByNetworkId_.clear();
    143113    }
    144114
     
    150120    Identifier* IdentifierManager::getIdentifierByString(const std::string& name)
    151121    {
    152         std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMapIntern().find(name);
    153         if (it != IdentifierManager::getStringIdentifierMapIntern().end())
     122        std::map<std::string, Identifier*>::const_iterator it = this->identifierByString_.find(name);
     123        if (it != this->identifierByString_.end())
    154124            return it->second;
    155125        else
     
    164134    Identifier* IdentifierManager::getIdentifierByLowercaseString(const std::string& name)
    165135    {
    166         std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getLowercaseStringIdentifierMapIntern().find(name);
    167         if (it != IdentifierManager::getLowercaseStringIdentifierMapIntern().end())
     136        std::map<std::string, Identifier*>::const_iterator it = this->identifierByLowercaseString_.find(name);
     137        if (it != this->identifierByLowercaseString_.end())
    168138            return it->second;
    169139        else
     
    178148    Identifier* IdentifierManager::getIdentifierByID(const uint32_t id)
    179149    {
    180         std::map<uint32_t, Identifier*>::const_iterator it = IdentifierManager::getIDIdentifierMapIntern().find(id);
    181         if (it != IdentifierManager::getIDIdentifierMapIntern().end())
     150        std::map<uint32_t, Identifier*>::const_iterator it = this->identifierByNetworkId_.find(id);
     151        if (it != this->identifierByNetworkId_.end())
    182152            return it->second;
    183153        else
     
    190160    void IdentifierManager::clearNetworkIDs()
    191161    {
    192         IdentifierManager::getIDIdentifierMapIntern().clear();
     162        this->identifierByNetworkId_.clear();
    193163    }
    194164}
  • code/branches/core6/src/libraries/core/class/IdentifierManager.h

    r9564 r9640  
    4848
    4949        public:
     50            static IdentifierManager& getInstance();
     51
    5052            /////////////////////////////
    5153            ////// Class Hierarchy //////
    5254            /////////////////////////////
    53             static void createClassHierarchy();
     55            void createClassHierarchy();
    5456
    5557            /// 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()
     58            inline bool isCreatingHierarchy()
    5759                { return (hierarchyCreatingCounter_s > 0); }
    5860
     
    6163            ///// Identifier Map /////
    6264            //////////////////////////
    63             static void destroyAllIdentifiers();
     65            void destroyAllIdentifiers();
    6466
    65             static Identifier* getIdentifierByString(const std::string& name);
    66             static Identifier* getIdentifierByLowercaseString(const std::string& name);
    67             static Identifier* getIdentifierByID(uint32_t id);
     67            Identifier* getIdentifierByString(const std::string& name);
     68            Identifier* getIdentifierByLowercaseString(const std::string& name);
     69            Identifier* getIdentifierByID(uint32_t id);
    6870
    69             static void clearNetworkIDs();
     71            void clearNetworkIDs();
    7072
    7173            /// 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            inline const std::map<std::string, Identifier*>& getStringIdentifierMap()
     75                { return this->identifierByString_; }
    7476            /// 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            inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin()
     78                { return this->identifierByString_.begin(); }
    7779            /// 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            inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd()
     81                { return this->identifierByString_.end(); }
    8082
    8183            /// 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            inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap()
     85                { return this->identifierByLowercaseString_; }
    8486            /// 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            inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin()
     88                { return this->identifierByLowercaseString_.begin(); }
    8789            /// 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            inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd()
     91                { return this->identifierByLowercaseString_.end(); }
    9092
    9193            /// 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            inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap()
     95                { return this->identifierByNetworkId_; }
    9496            /// 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            inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin()
     98                { return this->identifierByNetworkId_.begin(); }
    9799            /// 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            inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd()
     101                { return this->identifierByNetworkId_.end(); }
    100102
    101103        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();
     104            Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
    110105
    111106        private:
     107            IdentifierManager();
     108            IdentifierManager(const IdentifierManager&);
     109            ~IdentifierManager() {}
     110
    112111            /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
    113             inline static void startCreatingHierarchy()
     112            inline void startCreatingHierarchy()
    114113                { hierarchyCreatingCounter_s++; }
    115114            /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
    116             inline static void stopCreatingHierarchy()
     115            inline void stopCreatingHierarchy()
    117116                { hierarchyCreatingCounter_s--; }
    118117
    119             static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
     118            std::map<std::string, Identifier*> identifierByTypeId_;          //!< Map with the names as received by typeid(). This is only used internally.
    120119
    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
     120            std::map<std::string, Identifier*> identifierByString_;          //!< Map that stores all Identifiers with their names.
     121            std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase.
     122            std::map<uint32_t, Identifier*> identifierByNetworkId_;          //!< Returns the map that stores all Identifiers with their network IDs.
     123
     124            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)
     125            unsigned int classIDCounter_s;                          //!< counter for the unique classIDs
    123126    };
    124127}
  • code/branches/core6/src/libraries/core/config/ConfigValueContainer.h

    r9564 r9640  
    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/branches/core6/src/libraries/network/packet/ClassID.cc

    r9564 r9640  
    5555
    5656  //calculate total needed size (for all strings and integers)
    57   std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMapBegin();
    58   for(;it != IdentifierManager::getStringIdentifierMapEnd();++it){
     57  std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getInstance().getStringIdentifierMapBegin();
     58  for(;it != IdentifierManager::getInstance().getStringIdentifierMapEnd();++it){
    5959    id = it->second;
    6060    if(id == NULL || !id->hasFactory())
     
    129129
    130130  //clear the map of network ids
    131   IdentifierManager::clearNetworkIDs();
     131  IdentifierManager::getInstance().clearNetworkIDs();
    132132
    133133  orxout(verbose, context::packets) << "=== processing classids: " << endl;
  • code/branches/core6/src/libraries/network/synchronisable/Synchronisable.cc

    r9631 r9640  
    8080  {
    8181    // delete callback function objects
    82     if(!IdentifierManager::isCreatingHierarchy()){
     82    if(!IdentifierManager::getInstance().isCreatingHierarchy()){
    8383      // remove object from the static objectMap
    8484      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
Note: See TracChangeset for help on using the changeset viewer.