Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 694


Ignore:
Timestamp:
Dec 27, 2007, 2:07:50 AM (16 years ago)
Author:
landauf
Message:

back again - with a new try ;)

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

Legend:

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

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

    r693 r694  
    190190        public:
    191191            static ClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass);
    192             static void createIdentifier(const std::string& name);
    193192            static void addObject(T* object);
    194 
    195             /** @returns the Identifier itself (createIdentifier() has to be called first). */
    196             inline static ClassIdentifier<T>* getIdentifier()
    197             {
    198                 static ClassIdentifier<T> theOneAndOnlyInstance = ClassIdentifier<T>();
    199 
    200                 return &theOneAndOnlyInstance;
    201             }
     193            static ClassIdentifier<T>* getIdentifier();
     194            void setName(const std::string& name);
    202195
    203196        private:
     
    206199            ~ClassIdentifier();
    207200
    208             //static ClassIdentifier<T>* pointer_s;       //!< A pointer to the singleton-object
    209             ObjectList<T>* objects_;                    //!< The ObjectList, containing all objects of type T
     201            ObjectList<T>* objects_;    //!< The ObjectList, containing all objects of type T
     202            bool bSetName_;             //!< True if the name is set
    210203    };
    211204
     
    218211    {
    219212        this->objects_ = new ObjectList<T>;
     213        this->bSetName_ = false;
    220214    }
    221215
     
    241235        COUT(4) << "*** Register Class in " << name << "-Singleton." << std::endl;
    242236
    243         // It's a singleton, so maybe we have to create it first
    244         ClassIdentifier<T>::createIdentifier(name);
    245 
    246237        // Check if at least one object of the given type was created
    247238        if (!getIdentifier()->bCreatedOneObject_)
    248239        {
    249240            // If no: We have to store the informations and initialize the Identifier
     241            getIdentifier()->setName(name);
     242
    250243            COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
    251244            if (bRootClass)
     
    261254        @brief Creates the only instance of this class for the template class T.
    262255        @param name The name of the Class
    263     */
    264     template <class T>
    265     void ClassIdentifier<T>::createIdentifier(const std::string& name)
    266     {
     256        @return The Identifier itself
     257    */
     258    template <class T>
     259    ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
     260    {
     261        static ClassIdentifier<T> theOneAndOnlyInstance = ClassIdentifier<T>();
    267262        static bool bIdentifierCreated = false;
    268263
    269264        if (!bIdentifierCreated)
    270265        {
    271             getIdentifier()->name_ = name;
    272             getIdentifier()->identifierMap_s[name] = getIdentifier();
    273             COUT(4) << "*** Create Identifier Singleton for " << name << "." << std::endl;
     266            COUT(4) << "*** Create Identifier Singleton." << std::endl;
    274267            bIdentifierCreated = true;
     268        }
     269
     270        return &theOneAndOnlyInstance;
     271    }
     272
     273    /**
     274        @brief Sets the name of the class.
     275        @param name The name
     276    */
     277    template <class T>
     278    void ClassIdentifier<T>::setName(const std::string& name)
     279    {
     280        // Make sure we didn't already set the name, to avoid duplicate entries in the Identifier map
     281        if (!this->bSetName_)
     282        {
     283            this->name_ = name;
     284            this->identifierMap_s[name] = this;
     285            this->bSetName_ = true;
    275286        }
    276287    }
Note: See TracChangeset for help on using the changeset viewer.