Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 25, 2015, 10:49:34 PM (9 years ago)
Author:
landauf
Message:

create and initialize Identifiers explicitly via registerClass(). registerClass() must be called before using an Identifier of this type.
(some tests will currently fail)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/class/Identifier.h

    r10381 r10395  
    8282
    8383#include "util/Output.h"
     84#include "util/OrxAssert.h"
    8485#include "core/object/ObjectList.h"
    8586#include "core/object/Listable.h"
     
    109110    {
    110111        public:
    111             Identifier();
     112            Identifier(const std::string& name, Factory* factory, bool bLoadable);
    112113            Identifier(const Identifier& identifier); // don't copy
    113114            virtual ~Identifier();
     
    115116            /// Returns the name of the class the Identifier belongs to.
    116117            inline const std::string& getName() const { return this->name_; }
    117             void setName(const std::string& name);
    118118
    119119            /// Returns the name of the class as it is returned by typeid(T).name()
     
    127127            ORX_FORCEINLINE unsigned int getClassID() const { return this->classID_; }
    128128
    129             /// Sets the Factory.
    130             void setFactory(Factory* factory);
    131129            /// Returns true if the Identifier has a Factory.
    132130            inline bool hasFactory() const { return (this->factory_ != 0); }
     
    136134            /// Returns true if the class can be loaded through XML.
    137135            inline bool isLoadable() const { return this->bLoadable_; }
    138             /// Set the class to be loadable through XML or not.
    139             inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; }
    140136
    141137            /// Returns true if child classes should inherit virtually from this class.
     
    264260
    265261        public:
    266             static ClassIdentifier<T>* getIdentifier();
    267             static ClassIdentifier<T>* getIdentifier(const std::string& name);
    268 
    269             bool initializeObject(T* object);
    270 
    271             void setConfigValues(T* object, Configurable*) const;
    272             void setConfigValues(T* object, Identifiable*) const;
    273 
    274             void addObjectToList(T* object, Listable*);
    275             void addObjectToList(T* object, Identifiable*);
    276 
    277             virtual void updateConfigValues(bool updateChildren = true) const;
    278 
    279             virtual const std::string& getTypeidName()
    280                 { return this->typeidName_; }
    281 
    282             virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const
    283                 { return dynamic_cast<T*>(object) != 0; }
    284 
    285         private:
    286             static void initializeIdentifier();
    287 
    288             ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    289             ClassIdentifier()
     262            ClassIdentifier(const std::string& name, Factory* factory, bool bLoadable) : Identifier(name, factory, bLoadable)
    290263            {
     264                OrxVerify(ClassIdentifier<T>::classIdentifier_s == NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name());
     265                ClassIdentifier<T>::classIdentifier_s = this;
     266
    291267                this->typeidName_ = typeid(T).name();
    292268                SuperFunctionInitialization<0, T>::initialize(this);
     
    297273            }
    298274
     275            bool initializeObject(T* object);
     276
     277            void setConfigValues(T* object, Configurable*) const;
     278            void setConfigValues(T* object, Identifiable*) const;
     279
     280            void addObjectToList(T* object, Listable*);
     281            void addObjectToList(T* object, Identifiable*);
     282
     283            virtual void updateConfigValues(bool updateChildren = true) const;
     284
     285            virtual const std::string& getTypeidName()
     286                { return this->typeidName_; }
     287
     288            virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const
     289                { return dynamic_cast<T*>(object) != 0; }
     290
     291            static ClassIdentifier<T>* getIdentifier();
     292
     293        private:
     294            ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
     295
    299296            void updateConfigValues(bool updateChildren, Listable*) const;
    300297            void updateConfigValues(bool updateChildren, Identifiable*) const;
     
    312309    */
    313310    template <class T>
    314     inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
    315     {
    316         // check if the Identifier already exists
    317         if (!ClassIdentifier<T>::classIdentifier_s)
    318             ClassIdentifier<T>::initializeIdentifier();
    319 
     311    /*static*/ inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
     312    {
     313        if (ClassIdentifier<T>::classIdentifier_s == NULL)
     314            ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*) IdentifierManager::getInstance().getIdentifierByTypeidName(typeid(T).name());
     315
     316        OrxVerify(ClassIdentifier<T>::classIdentifier_s != NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name());
    320317        return ClassIdentifier<T>::classIdentifier_s;
    321     }
    322 
    323     /**
    324         @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.
    325         @param name The name of this Identifier
    326         @return The Identifier
    327     */
    328     template <class T>
    329     inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)
    330     {
    331         ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
    332         identifier->setName(name);
    333         return identifier;
    334     }
    335 
    336     /**
    337         @brief Assigns the static field for the identifier singleton.
    338     */
    339     template <class T>
    340     /*static */ void ClassIdentifier<T>::initializeIdentifier()
    341     {
    342         // create a new identifier anyway. Will be deleted if not used.
    343         ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
    344 
    345         // Get the entry from the map
    346         ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getGloballyUniqueIdentifier(proposal);
    347 
    348         if (ClassIdentifier<T>::classIdentifier_s == proposal)
    349             orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was not yet existing and got created." << endl;
    350         else
    351         {
    352             orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was already existing and got assigned." << endl;
    353             delete proposal; // delete proposal (it is not used anymore)
    354         }
    355318    }
    356319
Note: See TracChangeset for help on using the changeset viewer.