Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 805


Ignore:
Timestamp:
Feb 12, 2008, 4:24:14 PM (17 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.

Location:
code/branches/core/src/orxonox/core
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core/src/orxonox/core/CMakeLists.txt

    r802 r805  
    1414  Language.cc
    1515  ClassTreeMask.cc
     16  IdentifierDistributor.cc
    1617)
    1718
  • code/branches/core/src/orxonox/core/ClassFactory.h

    r790 r805  
    7373    {
    7474        COUT(4) << "*** Create entry for " << name << " in Factory." << std::endl;
    75         ClassIdentifier<T>::getIdentifier()->addFactory(new ClassFactory<T>);
    76         Factory::add(name, ClassIdentifier<T>::getIdentifier());
     75        ClassManager<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
     76        Factory::add(name, ClassManager<T>::getIdentifier(name));
    7777
    7878        return true;
  • code/branches/core/src/orxonox/core/ClassTreeMask.cc

    r804 r805  
    156156    ClassTreeMask::ClassTreeMask()
    157157    {
    158         this->root_ = new ClassTreeMaskNode(ClassIdentifier<BaseObject>::getIdentifier(), true);
     158        this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier("BaseObject"), true);
    159159    }
    160160
     
    227227    {
    228228        delete this->root_;
    229         this->root_ = new ClassTreeMaskNode(ClassIdentifier<BaseObject>::getIdentifier(), true);
     229        this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier("BaseObject"), true);
    230230    }
    231231
     
    237237    bool ClassTreeMask::isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const
    238238    {
    239 std::cout << "1_0: " << ClassIdentifier<BaseObject>::getIdentifier() << std::endl;
    240239std::cout << "1_1: " << subclass->getName() << " (" << subclass << ") / " << node->getClass()->getName() << " (" << node->getClass() << ")" << std::endl;
    241240        // Check if the searched subclass is of the same type as the class in the current node or a derivative
  • code/branches/core/src/orxonox/core/CoreIncludes.h

    r792 r805  
    4444// All needed header-files
    4545#include "Identifier.h"
     46#include "ClassManager.h"
    4647#include "Factory.h"
    4748#include "ClassFactory.h"
     
    5758*/
    5859#define InternRegisterObject(ClassName, bRootClass) \
    59     this->setIdentifier(orxonox::ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, bRootClass)); \
     60    this->setIdentifier(orxonox::ClassManager<ClassName>::getIdentifier(#ClassName)->registerClass(this->getParents(), #ClassName, bRootClass)); \
    6061    if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \
    6162        this->getParents()->add(this->getIdentifier()); \
    62     orxonox::ClassIdentifier<ClassName>::addObject(this)
     63    orxonox::ClassManager<ClassName>::getIdentifier(#ClassName)->addObject(this)
    6364
    6465/**
     
    111112*/
    112113#define Class(ClassName) \
    113     ClassIdentifier<ClassName>::getIdentifier()
     114    ClassManager<ClassName>::getIdentifier(#ClassName)
    114115
    115116/**
  • code/branches/core/src/orxonox/core/CorePrereqs.h

    r801 r805  
    7070  template <class T>
    7171  class ClassIdentifier;
     72  template <class T>
     73  class ClassManager;
    7274  class ConfigValueContainer;
    7375  class DebugLevel;
     
    7577  class Factory;
    7678  class Identifier;
     79  class IdentifierDistributor;
    7780  class IdentifierList;
    7881  class IdentifierListElement;
  • code/branches/core/src/orxonox/core/Identifier.cc

    r790 r805  
    118118    /**
    119119        @returns a reference to the Identifier map, containing all Identifiers.
    120     */
     120    *//*
    121121    std::map<std::string, Identifier*>& Identifier::getIdentifierMap()
    122122    {
    123123        static std::map<std::string, Identifier*> identifierMapStaticReference = std::map<std::string, Identifier*>();
    124124        return identifierMapStaticReference;
    125     }
     125    }*/
    126126
    127127    /**
  • 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}
  • code/branches/core/src/orxonox/core/Iterator.h

    r790 r805  
    150150                @return True if the iterator points to an existing object.
    151151            */
    152             bool operator!=(int compare)
     152            bool operator!=(ObjectListElement<T>* compare)
    153153            {
    154                 // Comparing with anything except zero makes no sense
    155                 if (compare != 0)
    156                     COUT(2) << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works." << std::endl;
    157 
    158                 return (this->element_ != 0);
     154                return (this->element_ != compare);
    159155            }
    160156
  • code/branches/core/src/orxonox/core/MetaObjectList.h

    r790 r805  
    9999
    100100
    101         COUT(4) << "*** Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list." << std::endl;
     101        COUT(4) << "*** Removing Object from " << this->element_->object_->getIdentifier()->getName() << "-list." << std::endl;
    102102        delete this->element_;
    103103    }
Note: See TracChangeset for help on using the changeset viewer.