Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 12, 2008, 4:24:14 PM (16 years ago)
Author:
landauf
Message:

Added two new classes:

  • ClassManager, a helper class for ClassIdentifier
  • IdentifierDistributor, a class that hopefully allows unique ClassIdentifiers even with several libraries

In a first try it seemed to work, but it needs more testing. At least it solved a problem I discovered yesterday with multiple Identifiers for the type "BaseObject" on windows.

File:
1 edited

Legend:

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

    r790 r805  
    8989    {
    9090        template <class T>
    91         friend class ClassIdentifier; // Forward declaration
     91        friend class ClassIdentifier;
    9292
    9393        template <class T>
    94         friend class SubclassIdentifier; // Forward declaration
    95 
    96         friend class Factory; // Forward declaration
     94        friend class SubclassIdentifier;
     95
     96        friend class Factory;
    9797
    9898        public:
     
    106106            bool isParentOf(const Identifier* identifier) const;
    107107
    108             static std::map<std::string, Identifier*>& getIdentifierMap();
     108//            static std::map<std::string, Identifier*>& getIdentifierMap();
    109109
    110110            /** @brief Removes all objects of the corresponding class. */
     
    186186    class ClassIdentifier : public Identifier
    187187    {
     188        template <class TT>
     189        friend class ClassManager;
     190
    188191        public:
    189             static ClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass);
    190             static void addObject(T* object);
    191             static ClassIdentifier<T>* getIdentifier();
     192            ClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass);
     193            void addObject(T* object);
     194//            static ClassIdentifier<T>* getIdentifier();
    192195            void removeObjects() const;
    193196            void setName(const std::string& name);
     
    225228
    226229        // Check if at least one object of the given type was created
    227         if (!getIdentifier()->bCreatedOneObject_)
     230        if (!this->bCreatedOneObject_)
    228231        {
    229232            // If no: We have to store the informations and initialize the Identifier
    230             getIdentifier()->setName(name);
     233            this->setName(name);
    231234
    232235            COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
    233236            if (bRootClass)
    234                 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.
     237                this->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.
    235238            else
    236                 getIdentifier()->initialize(parents);
     239                this->initialize(parents);
    237240        }
    238241
    239         return getIdentifier();
     242        return this;
    240243    }
    241244
     
    243246        @brief Creates the only instance of this class for the template class T.
    244247        @return The Identifier itself
    245     */
     248    *//*
    246249    template <class T>
    247250    ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
     
    258261        return &theOneAndOnlyInstance;
    259262    }
    260 
     263*/
    261264    /**
    262265        @brief Sets the name of the class.
     
    266269    void ClassIdentifier<T>::setName(const std::string& name)
    267270    {
    268         // Make sure we didn't already set the name, to avoid duplicate entries in the Identifier map
     271//        // Make sure we didn't already set the name, to avoid duplicate entries in the Identifier map
    269272        if (!this->bSetName_)
    270273        {
    271274            this->name_ = name;
    272             this->getIdentifierMap().insert(std::pair<std::string, Identifier*>(name, this));
     275//            this->getIdentifierMap().insert(std::pair<std::string, Identifier*>(name, this));
    273276            this->bSetName_ = true;
    274277        }
     
    282285    void ClassIdentifier<T>::addObject(T* object)
    283286    {
    284         COUT(4) << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list." << std::endl;
    285         object->getMetaList().add(ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object));
     287        COUT(4) << "*** Added object to " << this->getName() << "-list." << std::endl;
     288        object->getMetaList().add(this->objects_, this->objects_->add(object));
    286289    }
    287290
     
    314317            SubclassIdentifier()
    315318            {
    316                 this->identifier_ = ClassIdentifier<T>::getIdentifier();
     319                T* temp = new T;
     320                this->subclassIdentifier_ = temp->getIdentifier();
     321                delete temp;
     322
     323                this->identifier_ = this->subclassIdentifier_;
    317324            }
    318325
     
    324331            SubclassIdentifier<T>& operator=(Identifier* identifier)
    325332            {
    326                 if (!identifier->isA(ClassIdentifier<T>::getIdentifier()))
     333                if (!identifier->isA(this->subclassIdentifier_))
    327334                {
    328                     COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
    329                     COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
     335                    COUT(1) << "Error: Class " << identifier->getName() << " is not a " << this->subclassIdentifier_->getName() << "!" << std::endl;
     336                    COUT(1) << "Error: SubclassIdentifier<" << this->subclassIdentifier_->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
    330337                    COUT(1) << "Aborting..." << std::endl;
    331338                    abort();
     
    372379                    if (this->identifier_)
    373380                    {
    374                         COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
     381                        COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << this->subclassIdentifier_->getName() << "!" << std::endl;
    375382                        COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl;
    376383                        COUT(1) << "Aborting..." << std::endl;
     
    407414
    408415        private:
    409             Identifier* identifier_;        //!< The assigned identifier
     416            Identifier* identifier_;            //!< The assigned identifier
     417            Identifier* subclassIdentifier_;    //!< The identifier of the subclass
    410418    };
    411419}
Note: See TracChangeset for help on using the changeset viewer.