Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 25, 2013, 9:08:42 PM (11 years ago)
Author:
landauf
Message:

merged core6 back to trunk

Location:
code/trunk
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/class/Identifier.h

    r9593 r9667  
    5656    object->getIdentifier()->getName();                                         // returns "MyClass"
    5757
    58     OrxonoxClass* other = object->getIdentifier()->fabricate(0);                // fabricates a new instance of MyClass
    59 
    60 
    61     // iterate through all objects of type MyClass:
    62     ObjectListBase* objects = object->getIdentifier()->getObjects();            // get a pointer to the object-list
    63     int count;
    64     for (Iterator<MyClass> it = objects.begin(); it != objects.end(); ++it)     // iterate through the objects
    65         ++count;
    66     orxout() << count << endl;                                                  // prints "2" because we created 2 instances of MyClass so far
     58    Identifiable* other = object->getIdentifier()->fabricate(0);                // fabricates a new instance of MyClass
    6759
    6860
     
    9082
    9183#include "util/Output.h"
    92 #include "core/object/MetaObjectList.h"
    9384#include "core/object/ObjectList.h"
    94 #include "core/object/ObjectListBase.h"
     85#include "core/object/Listable.h"
     86#include "core/object/Context.h"
     87#include "core/object/Destroyable.h"
     88#include "core/object/WeakPtr.h"
    9589#include "IdentifierManager.h"
    9690#include "Super.h"
     
    112106        @note You can't directly create an Identifier, it's just the base-class of ClassIdentifier<T>.
    113107    */
    114     class _CoreExport Identifier
    115     {
    116         friend class IdentifierManager;
    117 
     108    class _CoreExport Identifier : public Destroyable
     109    {
    118110        public:
     111            Identifier();
     112            Identifier(const Identifier& identifier); // don't copy
     113            virtual ~Identifier();
     114
    119115            /// Returns the name of the class the Identifier belongs to.
    120116            inline const std::string& getName() const { return this->name_; }
    121117            void setName(const std::string& name);
    122118
     119            /// Returns the name of the class as it is returned by typeid(T).name()
     120            virtual const std::string& getTypeidName() = 0;
     121
    123122            /// Returns the network ID to identify a class through the network.
    124123            inline uint32_t getNetworkID() const { return this->networkID_; }
     
    128127            ORX_FORCEINLINE unsigned int getClassID() const { return this->classID_; }
    129128
    130             /// Returns the list of all existing objects of this class.
    131             inline ObjectListBase* getObjects() const { return this->objects_; }
    132 
    133129            /// Sets the Factory.
    134             inline void addFactory(Factory* factory) { this->factory_ = factory; }
     130            void setFactory(Factory* factory);
    135131            /// Returns true if the Identifier has a Factory.
    136132            inline bool hasFactory() const { return (this->factory_ != 0); }
    137133
    138             OrxonoxClass* fabricate(BaseObject* creator);
     134            Identifiable* fabricate(Context* context);
    139135
    140136            /// Returns true if the class can be loaded through XML.
     
    142138            /// Set the class to be loadable through XML or not.
    143139            inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; }
     140
     141            /// Returns true if the Identifier was completely initialized.
     142            inline bool isInitialized() const { return this->bInitialized_; }
     143
     144
     145            /////////////////////////////
     146            ////// Class Hierarchy //////
     147            /////////////////////////////
     148            Identifier& inheritsFrom(Identifier* directParent);
     149
     150            void initializeParents(const std::set<const Identifier*>& identifiers);
     151            void initializeDirectParentsOfAbstractClass();
     152            void finishInitialization();
    144153
    145154            bool isA(const Identifier* identifier) const;
     
    150159            bool isDirectParentOf(const Identifier* identifier) const;
    151160
    152 
    153             /////////////////////////////
    154             ////// Class Hierarchy //////
    155             /////////////////////////////
    156161            /// Returns the parents of the class the Identifier belongs to.
    157162            inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
     
    220225
    221226        protected:
    222             Identifier();
    223             Identifier(const Identifier& identifier); // don't copy
    224             virtual ~Identifier();
    225 
    226227            virtual void createSuperFunctionCaller() const = 0;
    227228
    228             void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
    229 
    230             /// Returns the children of the class the Identifier belongs to.
    231             inline std::set<const Identifier*>& getChildrenIntern() const { return this->children_; }
    232             /// Returns the direct children of the class the Identifier belongs to.
    233             inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; }
    234 
    235             ObjectListBase* objects_;                                      //!< The list of all objects of this class
    236 
    237229        private:
    238             void initialize(std::set<const Identifier*>* parents);
    239 
    240230            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
    241             mutable std::set<const Identifier*> children_;                 //!< The children of the class the Identifier belongs to
     231            std::set<const Identifier*> children_;                         //!< The children of the class the Identifier belongs to
    242232
    243233            std::set<const Identifier*> directParents_;                    //!< The direct parents of the class the Identifier belongs to
    244             mutable std::set<const Identifier*> directChildren_;           //!< The direct children of the class the Identifier belongs to
    245 
    246             bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    247             bool bSetName_;                                                //!< True if the name is set
     234            std::set<const Identifier*> directChildren_;                   //!< The direct children of the class the Identifier belongs to
     235
     236            bool bInitialized_;                                            //!< Is true if the Identifier was completely initialized
    248237            bool bLoadable_;                                               //!< False = it's not permitted to load the object through XML
    249238            std::string name_;                                             //!< The name of the class the Identifier belongs to
     
    287276            static ClassIdentifier<T>* getIdentifier(const std::string& name);
    288277
    289             bool initialiseObject(T* object, const std::string& className, bool bRootClass);
     278            bool initializeObject(T* object);
    290279
    291280            void setConfigValues(T* object, Configurable*) const;
     
    295284            void addObjectToList(T* object, Identifiable*);
    296285
    297             void updateConfigValues(bool updateChildren = true) const;
     286            virtual void updateConfigValues(bool updateChildren = true) const;
     287
     288            virtual const std::string& getTypeidName()
     289                { return this->typeidName_; }
    298290
    299291        private:
    300             static void initialiseIdentifier();
     292            static void initializeIdentifier();
     293
    301294            ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    302295            ClassIdentifier()
    303296            {
     297                this->typeidName_ = typeid(T).name();
    304298                SuperFunctionInitialization<0, T>::initialize(this);
    305299            }
     
    309303            }
    310304
    311             static ClassIdentifier<T>* classIdentifier_s;
     305            void updateConfigValues(bool updateChildren, Listable*) const;
     306            void updateConfigValues(bool updateChildren, Identifiable*) const;
     307
     308            std::string typeidName_;
     309            static WeakPtr<ClassIdentifier<T> > classIdentifier_s;
    312310    };
    313311
    314312    template <class T>
    315     ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s = 0;
     313    WeakPtr<ClassIdentifier<T> > ClassIdentifier<T>::classIdentifier_s;
    316314
    317315    /**
     
    324322        // check if the Identifier already exists
    325323        if (!ClassIdentifier<T>::classIdentifier_s)
    326             ClassIdentifier<T>::initialiseIdentifier();
     324            ClassIdentifier<T>::initializeIdentifier();
    327325
    328326        return ClassIdentifier<T>::classIdentifier_s;
     
    346344    */
    347345    template <class T>
    348     void ClassIdentifier<T>::initialiseIdentifier()
    349     {
    350         // Get the name of the class
    351         std::string name = typeid(T).name();
    352 
    353         // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
     346    /*static */ void ClassIdentifier<T>::initializeIdentifier()
     347    {
     348        // create a new identifier anyway. Will be deleted if not used.
    354349        ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
    355350
    356351        // Get the entry from the map
    357         ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getIdentifierSingleton(name, proposal);
     352        ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getGloballyUniqueIdentifier(proposal);
    358353
    359354        if (ClassIdentifier<T>::classIdentifier_s == proposal)
    360         {
    361             orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was not yet existing and got created." << endl;
    362         }
     355            orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was not yet existing and got created." << endl;
    363356        else
    364357        {
    365             orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was already existing and got assigned." << endl;
     358            orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was already existing and got assigned." << endl;
     359            delete proposal; // delete proposal (it is not used anymore)
    366360        }
    367361    }
     
    370364        @brief Adds an object of the given type to the ObjectList.
    371365        @param object The object to add
    372         @param className The name of the class T
    373         @param bRootClass True if this is a root class (i.e. it inherits directly from OrxonoxClass)
    374     */
    375     template <class T>
    376     bool ClassIdentifier<T>::initialiseObject(T* object, const std::string& className, bool bRootClass)
    377     {
    378         if (bRootClass)
    379             orxout(verbose, context::object_list) << "Register Root-Object: " << className << endl;
    380         else
    381             orxout(verbose, context::object_list) << "Register Object: " << className << endl;
     366    */
     367    template <class T>
     368    bool ClassIdentifier<T>::initializeObject(T* object)
     369    {
     370        orxout(verbose, context::object_list) << "Register Object: " << this->getName() << endl;
    382371
    383372        object->identifier_ = this;
    384         if (IdentifierManager::isCreatingHierarchy())
     373        if (IdentifierManager::getInstance().isCreatingHierarchy())
    385374        {
    386             if (bRootClass && !object->parents_)
    387                 object->parents_ = new std::set<const Identifier*>();
    388 
    389             if (object->parents_)
    390             {
    391                 this->initializeClassHierarchy(object->parents_, bRootClass);
    392                 object->parents_->insert(object->parents_->end(), this);
    393             }
     375            IdentifierManager::getInstance().createdObject(object);
    394376
    395377            this->setConfigValues(object, object);
     
    425407     */
    426408    template <class T>
    427     void ClassIdentifier<T>::addObjectToList(T* object, Listable*)
    428     {
    429         orxout(verbose, context::object_list) << "Added object to " << this->getName() << "-list." << endl;
    430         object->metaList_->add(this->objects_, this->objects_->add(object));
     409    void ClassIdentifier<T>::addObjectToList(T* object, Listable* listable)
     410    {
     411        if (listable->getContext())
     412            listable->getContext()->addObject(object);
    431413    }
    432414
     
    442424    template <class T>
    443425    void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const
     426    {
     427        this->updateConfigValues(updateChildren, static_cast<T*>(NULL));
     428    }
     429
     430    template <class T>
     431    void ClassIdentifier<T>::updateConfigValues(bool updateChildren, Listable*) const
    444432    {
    445433        if (!this->hasConfigValues())
     
    452440            for (std::set<const Identifier*>::const_iterator it = this->getChildrenBegin(); it != this->getChildrenEnd(); ++it)
    453441                (*it)->updateConfigValues(false);
     442    }
     443
     444    template <class T>
     445    void ClassIdentifier<T>::updateConfigValues(bool updateChildren, Identifiable*) const
     446    {
     447        // no action
    454448    }
    455449
Note: See TracChangeset for help on using the changeset viewer.