Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 693 for code/branches/FICN/src


Ignore:
Timestamp:
Dec 26, 2007, 11:59:27 PM (17 years ago)
Author:
rgrieder
Message:
  • new approach to pointer_s problem
File:
1 edited

Legend:

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

    r692 r693  
    194194
    195195            /** @returns the Identifier itself (createIdentifier() has to be called first). */
    196             inline static ClassIdentifier<T>* getIdentifier() { return pointer_s; }
     196            inline static ClassIdentifier<T>* getIdentifier()
     197            {
     198                static ClassIdentifier<T> theOneAndOnlyInstance = ClassIdentifier<T>();
     199
     200                return &theOneAndOnlyInstance;
     201            }
    197202
    198203        private:
    199             ClassIdentifier(const std::string& name);
     204            ClassIdentifier();
    200205            ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy
    201206            ~ClassIdentifier();
    202207
    203             static ClassIdentifier<T>* pointer_s;       //!< A pointer to the singleton-object
     208            //static ClassIdentifier<T>* pointer_s;       //!< A pointer to the singleton-object
    204209            ObjectList<T>* objects_;                    //!< The ObjectList, containing all objects of type T
    205210    };
    206211
    207     template <class T>
    208     ClassIdentifier<T>* ClassIdentifier<T>::pointer_s;
    209 
    210212    /**
    211213        @brief Constructor: Creates the ObjectList.
     
    213215    */
    214216    template <class T>
    215     ClassIdentifier<T>::ClassIdentifier(const std::string& name)
     217    ClassIdentifier<T>::ClassIdentifier()
    216218    {
    217219        this->objects_ = new ObjectList<T>;
    218         this->name_ = name;
    219         this->identifierMap_s[name] = this;
    220220    }
    221221
     
    227227    {
    228228        delete this->objects_;
    229         this->pointer_s = NULL;
    230229    }
    231230
     
    246245
    247246        // Check if at least one object of the given type was created
    248         if (!pointer_s->bCreatedOneObject_)
     247        if (!getIdentifier()->bCreatedOneObject_)
    249248        {
    250249            // If no: We have to store the informations and initialize the Identifier
    251250            COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
    252251            if (bRootClass)
    253                 pointer_s->initialize(NULL); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case.
     252                getIdentifier()->initialize(NULL); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case.
    254253            else
    255                 pointer_s->initialize(parents);
     254                getIdentifier()->initialize(parents);
    256255        }
    257256
    258         return pointer_s;
     257        return getIdentifier();
    259258    }
    260259
     
    266265    void ClassIdentifier<T>::createIdentifier(const std::string& name)
    267266    {
    268         static bool bFirstCeateIdentifierFunctionCall = true;
    269         static ClassIdentifier<T> classIdentifierObject = ClassIdentifier<T>(name);
    270 
    271         if (bFirstCeateIdentifierFunctionCall)
     267        static bool bIdentifierCreated = false;
     268
     269        if (!bIdentifierCreated)
    272270        {
     271            getIdentifier()->name_ = name;
     272            getIdentifier()->identifierMap_s[name] = getIdentifier();
    273273            COUT(4) << "*** Create Identifier Singleton for " << name << "." << std::endl;
    274             pointer_s = &classIdentifierObject;
    275             bFirstCeateIdentifierFunctionCall = false;
     274            bIdentifierCreated = true;
    276275        }
    277276    }
Note: See TracChangeset for help on using the changeset viewer.