Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2013, 10:42:57 PM (11 years ago)
Author:
landauf
Message:

small refactoring

Location:
code/branches/core6/src/libraries/core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core6/src/libraries/core/CoreIncludes.h

    r9640 r9644  
    9595*/
    9696#define InternRegisterObject(ClassName, bRootClass) \
    97     if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initialiseObject(this, #ClassName, bRootClass)) \
     97    if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeObject(this, #ClassName, bRootClass)) \
    9898        return; \
    9999    else \
  • code/branches/core6/src/libraries/core/class/Identifier.h

    r9643 r9644  
    114114            inline const std::string& getName() const { return this->name_; }
    115115            void setName(const std::string& name);
     116
     117            /// Returns the name of the class as it is returned by typeid(T).name()
     118            virtual const std::string& getTypeidName() = 0;
    116119
    117120            /// Returns the network ID to identify a class through the network.
     
    272275            static ClassIdentifier<T>* getIdentifier(const std::string& name);
    273276
    274             bool initialiseObject(T* object, const std::string& className, bool bRootClass);
     277            bool initializeObject(T* object, const std::string& className, bool bRootClass);
    275278
    276279            void setConfigValues(T* object, Configurable*) const;
     
    280283            void addObjectToList(T* object, Identifiable*);
    281284
    282             void updateConfigValues(bool updateChildren = true) const;
     285            virtual void updateConfigValues(bool updateChildren = true) const;
     286
     287            virtual const std::string& getTypeidName()
     288                { return this->typeidName_; }
    283289
    284290        private:
    285             static void initialiseIdentifier();
     291            static void initializeIdentifier();
     292
    286293            ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    287294            ClassIdentifier()
    288295            {
     296                this->typeidName_ = typeid(T).name();
    289297                SuperFunctionInitialization<0, T>::initialize(this);
    290298            }
     
    299307            void updateConfigValues(bool updateChildren, Identifiable*) const;
    300308
     309            std::string typeidName_;
    301310            static ClassIdentifier<T>* classIdentifier_s;
    302311    };
     
    314323        // check if the Identifier already exists
    315324        if (!ClassIdentifier<T>::classIdentifier_s)
    316             ClassIdentifier<T>::initialiseIdentifier();
     325            ClassIdentifier<T>::initializeIdentifier();
    317326
    318327        return ClassIdentifier<T>::classIdentifier_s;
     
    336345    */
    337346    template <class T>
    338     void ClassIdentifier<T>::initialiseIdentifier()
    339     {
    340         // Get the name of the class
    341         std::string name = typeid(T).name();
    342 
    343         // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
     347    /*static */ void ClassIdentifier<T>::initializeIdentifier()
     348    {
     349        // create a new identifier anyway. Will be deleted if not used.
    344350        ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
    345351
    346352        // Get the entry from the map
    347         ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getIdentifierSingleton(name, proposal);
     353        ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getIdentifierSingleton(proposal);
    348354
    349355        if (ClassIdentifier<T>::classIdentifier_s == proposal)
    350         {
    351             orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was not yet existing and got created." << endl;
    352         }
     356            orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was not yet existing and got created." << endl;
    353357        else
    354358        {
    355             orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was already existing and got assigned." << endl;
     359            orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was already existing and got assigned." << endl;
     360            delete proposal; // delete proposal (it is not used anymore)
    356361        }
    357362    }
     
    364369    */
    365370    template <class T>
    366     bool ClassIdentifier<T>::initialiseObject(T* object, const std::string& className, bool bRootClass)
     371    bool ClassIdentifier<T>::initializeObject(T* object, const std::string& className, bool bRootClass)
    367372    {
    368373        if (bRootClass)
  • code/branches/core6/src/libraries/core/class/IdentifierManager.cc

    r9641 r9644  
    5757    /**
    5858        @brief Returns an identifier by name and adds it if not available
    59         @param name The name of the identifier as typeid().name() suggests
    6059        @param proposal A pointer to a newly created identifier for the case of non existence in the map
    6160        @return The identifier (unique instance)
    6261    */
    63     Identifier* IdentifierManager::getIdentifierSingleton(const std::string& name, Identifier* proposal)
     62    Identifier* IdentifierManager::getIdentifierSingleton(Identifier* proposal)
    6463    {
    65         std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeId_.find(name);
     64        const std::string& typeidName = proposal->getTypeidName();
     65        std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.find(typeidName);
    6666
    67         if (it != this->identifierByTypeId_.end())
     67        if (it != this->identifierByTypeidName_.end())
    6868        {
    69             // There is already an entry: return it and delete the proposal
    70             delete proposal;
     69            // There is already an entry: return it
    7170            return it->second;
    7271        }
     
    7473        {
    7574            // There is no entry: put the proposal into the map and return it
    76             this->identifierByTypeId_[name] = proposal;
     75            this->identifierByTypeidName_[typeidName] = proposal;
    7776            return proposal;
    7877        }
     
    9695        orxout(internal_status) << "Create class-hierarchy" << endl;
    9796        this->startCreatingHierarchy();
    98         for (std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeId_.begin(); it != this->identifierByTypeId_.end(); ++it)
     97        for (std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.begin(); it != this->identifierByTypeidName_.end(); ++it)
    9998        {
    10099            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     
    114113    void IdentifierManager::destroyAllIdentifiers()
    115114    {
    116         for (std::map<std::string, Identifier*>::iterator it = this->identifierByTypeId_.begin(); it != this->identifierByTypeId_.end(); ++it)
     115        for (std::map<std::string, Identifier*>::iterator it = this->identifierByTypeidName_.begin(); it != this->identifierByTypeidName_.end(); ++it)
    117116            delete (it->second);
    118117
    119         this->identifierByTypeId_.clear();
     118        this->identifierByTypeidName_.clear();
    120119        this->identifierByString_.clear();
    121120        this->identifierByLowercaseString_.clear();
  • code/branches/core6/src/libraries/core/class/IdentifierManager.h

    r9642 r9644  
    4747            static IdentifierManager& getInstance();
    4848
    49             Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
     49            Identifier* getIdentifierSingleton(Identifier* proposal);
    5050            void registerIdentifier(Identifier* identifier);
    5151
     
    9696                { hierarchyCreatingCounter_s--; }
    9797
    98             std::map<std::string, Identifier*> identifierByTypeId_;          //!< Map with the names as received by typeid(). This is only used internally.
     98            std::map<std::string, Identifier*> identifierByTypeidName_;      //!< Map with the names as received by typeid(). This is only used internally.
    9999
    100100            std::map<std::string, Identifier*> identifierByString_;          //!< Map that stores all Identifiers with their names.
Note: See TracChangeset for help on using the changeset viewer.