Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 690


Ignore:
Timestamp:
Dec 26, 2007, 11:28:31 PM (16 years ago)
Author:
landauf
Message:

some changes in the ClassIdentifier (inspired by retos suggestion)

Location:
code/branches/FICN/src/orxonox/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/orxonox/core/ClassFactory.h

    r682 r690  
    7373    {
    7474        COUT(4) << "*** Create entry for " << name << " in Factory." << std::endl;
     75        ClassIdentifier<T>::createIdentifier(name);
    7576        ClassIdentifier<T>::getIdentifier()->addFactory(new ClassFactory<T>);
    7677        Factory::add(name, ClassIdentifier<T>::getIdentifier());
  • code/branches/FICN/src/orxonox/core/Identifier.cc

    r677 r690  
    4040    int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero
    4141    unsigned int Identifier::classIDcounter_s = 0;  // Set the static member variable classIDcounter_s to zero
     42    std::map<std::string, Identifier*> Identifier::identifierMap_s;
    4243
    4344    /**
  • code/branches/FICN/src/orxonox/core/Identifier.h

    r682 r690  
    172172            unsigned int classID_;                                      //!< The network ID to identify a class through the network
    173173            std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer
     174            static std::map<std::string, Identifier*> identifierMap_s;  //!< A map, containing all existing ClassIdentifiers
    174175    };
    175176
     
    189190        public:
    190191            static ClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass);
    191             static ClassIdentifier<T>* getIdentifier();
     192            static void createIdentifier(const std::string& name);
    192193            static void addObject(T* object);
    193194
     195            /** @returns the Identifier itself (createIdentifier() has to be called first). */
     196            inline static ClassIdentifier<T>* getIdentifier() { return pointer_s; }
     197
    194198        private:
    195             ClassIdentifier();
     199            ClassIdentifier(const std::string& name);
    196200            ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy
    197201            ~ClassIdentifier();
     
    206210    /**
    207211        @brief Constructor: Creates the ObjectList.
    208     */
    209     template <class T>
    210     ClassIdentifier<T>::ClassIdentifier()
     212        @param name The name of the Class
     213    */
     214    template <class T>
     215    ClassIdentifier<T>::ClassIdentifier(const std::string& name)
    211216    {
    212217        this->objects_ = new ObjectList<T>;
     218        this->name_ = name;
     219        this->identifierMap_s[name] = this;
    213220    }
    214221
     
    236243
    237244        // It's a singleton, so maybe we have to create it first
    238         if (!pointer_s)
    239         {
    240             COUT(4) << "*** Register Class in " << name << "-Singleton -> Create Singleton." << std::endl;
    241             pointer_s = new ClassIdentifier();
    242         }
     245        ClassIdentifier<T>::createIdentifier(name);
    243246
    244247        // Check if at least one object of the given type was created
     
    258261
    259262    /**
    260         @returns the Identifier itself.
    261     */
    262     template <class T>
    263     ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
    264     {
    265         if (!pointer_s)
     263        @brief Creates the only instance of this class for the template class T.
     264        @param name The name of the Class
     265    */
     266    template <class T>
     267    void ClassIdentifier<T>::createIdentifier(const std::string& name)
     268    {
     269        static bool bFirstCeateIdentifierFunctionCall = true;
     270        static ClassIdentifier<T> classIdentifierObject = ClassIdentifier<T>(name);
     271
     272        if (bFirstCeateIdentifierFunctionCall)
    266273        {
    267             COUT(4) << "*** Create Singleton." << std::endl;
    268             pointer_s = new ClassIdentifier();
     274            COUT(4) << "*** Create Identifier Singleton for " << name << "." << std::endl;
     275            pointer_s = &classIdentifierObject;
     276            bFirstCeateIdentifierFunctionCall = false;
    269277        }
    270 
    271         return pointer_s;
    272278    }
    273279
Note: See TracChangeset for help on using the changeset viewer.