Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

made IdentifierManager a self-initializing singleton

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.