Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 811


Ignore:
Timestamp:
Feb 13, 2008, 6:39:53 PM (16 years ago)
Author:
landauf
Message:
  • Changed the ClassManager/IdentifierDistributor: ClassIdentifiers are now saved with the name returned by typeid(class).name() because this is a simple way getting the name without creating an object (which might be impossible because of non-public constructors or abstract functions).
  • Changed some debug outputs
Location:
code/branches/core/src/orxonox
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core/src/orxonox/Orxonox.cc

    r808 r811  
    754754        std::cout << "2\n";
    755755*/
     756
    756757        std::cout << "Test 13\n";
    757758
     
    833834        std::cout << "Mask 2:\n";
    834835        TestClassTreeMask(test13_2);
    835 
     836/*
    836837        ClassTreeMask test13_3;
    837838        test13_3.include(Class(A1));
     
    967968
    968969        std::cout << "9\n";
     970*/
     971
     972        std::cout << "Test 14\n";
     973        std::cout << "1\n";
     974
     975        SubclassIdentifier<A1> test14_1;
     976        test14_1 = Class(A1B1C1);
     977        std::cout << test14_1.getIdentifier()->getName() << std::endl;
     978
     979        SubclassIdentifier<A1> test14_2 = Class(A1B1C2);
     980        std::cout << test14_2.getIdentifier()->getName() << std::endl;
     981
     982        SubclassIdentifier<Interface1> test14_3;
     983        test14_3 = Class(A2B2C1);
     984        std::cout << test14_3.getIdentifier()->getName() << std::endl;
     985
     986        SubclassIdentifier<A1B2> test14_4;
     987        test14_4 = Class(A1B2C1);
     988        std::cout << test14_4.getIdentifier()->getName() << std::endl;
     989
     990        SubclassIdentifier<BaseObject> test14_5 = Class(Test1);
     991        std::cout << test14_5.getIdentifier()->getName() << std::endl;
    969992
    970993//    startRenderLoop();
  • code/branches/core/src/orxonox/core/ClassFactory.h

    r805 r811  
    7272    bool ClassFactory<T>::create(const std::string& name)
    7373    {
    74         COUT(4) << "*** Create entry for " << name << " in Factory." << std::endl;
    75         ClassManager<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
    76         Factory::add(name, ClassManager<T>::getIdentifier(name));
     74        COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
     75        ClassManager<T>::getIdentifier()->addFactory(new ClassFactory<T>);
     76        Factory::add(name, ClassManager<T>::getIdentifier());
    7777
    7878        return true;
  • code/branches/core/src/orxonox/core/ClassManager.h

    r810 r811  
    6363        public:
    6464            static ClassManager<T>* getSingleton();
    65             static ClassIdentifier<T>* getIdentifier(const std::string& name);
     65            static ClassIdentifier<T>* getIdentifier();
    6666            static const std::string& getName();
    6767
     
    9696
    9797    /**
    98         @brief Creates the only instance of this class for the template class T and retrieves a unique Identifier.
     98        @brief Creates the only instance of this class for the template class T and retrieves a unique Identifier for the given name.
    9999        @return The unique Identifier
    100100    */
    101101    template <class T>
    102     ClassIdentifier<T>* ClassManager<T>::getIdentifier(const std::string& name)
     102    ClassIdentifier<T>* ClassManager<T>::getIdentifier()
    103103    {
    104104        // Check if the ClassManager is already initialized
    105105        if (!ClassManager<T>::getSingleton()->bInitialized_)
    106106        {
     107            // Get the name of the class
     108            std::string name = typeid(T).name();
     109
    107110            // It's not -> retrieve the ClassIdentifier through IdentifierDistributor
    108             COUT(4) << "*** Create Identifier Singleton." << std::endl;
     111            COUT(4) << "*** ClassManager: Request Identifier Singleton for " << name << "." << std::endl;
    109112
    110113            // First create a ClassIdentifier in case there's no instance existing yet
     
    116119            // If the retrieved Identifier differs from our proposal, we don't need the proposal any more
    117120            if (temp != ClassManager<T>::getSingleton()->identifier_)
     121            {
     122                COUT(4) << "*** ClassManager: Requested Identifier for " << name << " was already existing and got assigned." << std::endl;
     123
     124                // Delete the unnecessary proposal
    118125                delete temp;
     126            }
     127            else
     128            {
     129                COUT(4) << "*** ClassManager: Requested Identifier for " << name << " was not yet existing and got created." << std::endl;
     130            }
    119131
    120132            ClassManager<T>::getSingleton()->bInitialized_ = true;
  • code/branches/core/src/orxonox/core/ClassTreeMask.cc

    r809 r811  
    247247    ClassTreeMask::ClassTreeMask()
    248248    {
    249         this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier("BaseObject"), true);
     249        this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier(), true);
    250250    }
    251251
     
    256256    ClassTreeMask::ClassTreeMask(const ClassTreeMask& other)
    257257    {
    258         this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier("BaseObject"), true);
     258        this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier(), true);
    259259        for (ClassTreeMaskIterator it = other.root_; it; ++it)
    260260            this->add(it->getClass(), it->isIncluded());
     
    354354    {
    355355        delete this->root_;
    356         this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier("BaseObject"), true);
     356        this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier(), true);
    357357    }
    358358
  • code/branches/core/src/orxonox/core/ConfigValueContainer.cc

    r797 r811  
    870870        if (!file.is_open())
    871871        {
     872            COUT(1) << "An error occurred in ConfigValueContainer:" << std::endl;
    872873            COUT(1) << "Error: Couldn't open config-file " << filename << " to read the config values!" << std::endl;
    873874            return;
     
    916917        if (!file.is_open())
    917918        {
     919            COUT(1) << "An error occurred in ConfigValueContainer:" << std::endl;
    918920            COUT(1) << "Error: Couldn't open config-file " << filename << " to write the config values!" << std::endl;
    919921            return;
  • code/branches/core/src/orxonox/core/CoreIncludes.h

    r805 r811  
    5858*/
    5959#define InternRegisterObject(ClassName, bRootClass) \
    60     this->setIdentifier(orxonox::ClassManager<ClassName>::getIdentifier(#ClassName)->registerClass(this->getParents(), #ClassName, bRootClass)); \
     60    this->setIdentifier(orxonox::ClassManager<ClassName>::getIdentifier()->registerClass(this->getParents(), #ClassName, bRootClass)); \
    6161    if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \
    6262        this->getParents()->add(this->getIdentifier()); \
    63     orxonox::ClassManager<ClassName>::getIdentifier(#ClassName)->addObject(this)
     63    orxonox::ClassManager<ClassName>::getIdentifier()->addObject(this)
    6464
    6565/**
     
    112112*/
    113113#define Class(ClassName) \
    114     ClassManager<ClassName>::getIdentifier(#ClassName)
     114    ClassManager<ClassName>::getIdentifier()
    115115
    116116/**
  • code/branches/core/src/orxonox/core/Factory.cc

    r790 r811  
    8484    void Factory::createClassHierarchy()
    8585    {
    86         COUT(3) << "*** Factory -> Create class-hierarchy" << std::endl;
     86        COUT(3) << "*** Factory: Create class-hierarchy" << std::endl;
    8787        std::map<std::string, Identifier*>::iterator it;
    8888        it = getFactoryPointer()->identifierStringMap_.begin();
     
    9595        }
    9696        (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy();
    97         COUT(3) << "*** Factory -> Finished class-hierarchy creation" << std::endl;
     97        COUT(3) << "*** Factory: Finished class-hierarchy creation" << std::endl;
    9898    }
    9999
  • code/branches/core/src/orxonox/core/Identifier.cc

    r806 r811  
    7070    void Identifier::initialize(const IdentifierList* parents)
    7171    {
    72         COUT(4) << "*** Initialize " << this->name_ << "-Singleton." << std::endl;
     72        COUT(4) << "*** Identifier: Initialize " << this->name_ << "-Singleton." << std::endl;
    7373        this->bCreatedOneObject_ = true;
    7474
     
    9999        {
    100100            // Abstract classes don't have a factory and therefore can't create new objects
     101            COUT(1) << "An error occurred in Identifier:" << std::endl;
    101102            COUT(1) << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract." << std::endl;
    102103            COUT(1) << "Aborting..." << std::endl;
  • code/branches/core/src/orxonox/core/Identifier.h

    r810 r811  
    147147            {
    148148                hierarchyCreatingCounter_s++;
    149                 COUT(4) << "*** Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
     149                COUT(4) << "*** Identifier: Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
    150150            }
    151151
     
    156156            {
    157157                hierarchyCreatingCounter_s--;
    158                 COUT(4) << "*** Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
     158                COUT(4) << "*** Identifier: Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
    159159            }
    160160
     
    228228    ClassIdentifier<T>* ClassIdentifier<T>::registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass)
    229229    {
    230         COUT(4) << "*** Register Class in " << name << "-Singleton." << std::endl;
     230        COUT(4) << "*** ClassIdentifier: Register Class in " << name << "-Singleton." << std::endl;
    231231
    232232        // Check if at least one object of the given type was created
     
    236236            this->setName(name);
    237237
    238             COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
     238            COUT(4) << "*** ClassIdentifier: Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
    239239            if (bRootClass)
    240240                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.
     
    267267    void ClassIdentifier<T>::addObject(T* object)
    268268    {
    269         COUT(4) << "*** Added object to " << this->getName() << "-list." << std::endl;
     269        COUT(4) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
    270270        object->getMetaList().add(this->objects_, this->objects_->add(object));
    271271    }
     
    299299            SubclassIdentifier()
    300300            {
    301                 std::string name = ClassManager<T>::getName();
    302 
    303                 if (name != "unknown")
    304                     this->subclassIdentifier_ = ClassManager<T>::getIdentifier(name);
    305                 else
    306                     this->subclassIdentifier_ = 0;
    307 
    308                 this->identifier_ = this->subclassIdentifier_;
     301                this->identifier_ = ClassManager<T>::getIdentifier();
    309302            }
    310303
     
    315308            SubclassIdentifier(Identifier* identifier)
    316309            {
    317                 std::string name = ClassManager<T>::getName();
    318 
    319                 if (name != "unknown")
    320                     this->subclassIdentifier_ = ClassManager<T>::getIdentifier(name);
    321                 else
    322                     this->subclassIdentifier_ = 0;
    323 
    324310                this->identifier_ = identifier;
    325311            }
     
    332318            SubclassIdentifier<T>& operator=(Identifier* identifier)
    333319            {
    334                 if (!identifier->isA(this->subclassIdentifier_))
     320                if (!identifier->isA(ClassManager<T>::getIdentifier()))
    335321                {
    336                     COUT(1) << "Error: Class " << identifier->getName() << " is not a " << this->subclassIdentifier_->getName() << "!" << std::endl;
    337                     COUT(1) << "Error: SubclassIdentifier<" << this->subclassIdentifier_->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
     322                    COUT(1) << "An error occurred in SubclassIdentifier:" << std::endl;
     323                    COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassManager<T>::getIdentifier()->getName() << "!" << std::endl;
     324                    COUT(1) << "Error: SubclassIdentifier<" << ClassManager<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
    338325                    COUT(1) << "Aborting..." << std::endl;
    339326                    abort();
     
    380367                    if (this->identifier_)
    381368                    {
    382                         COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << this->subclassIdentifier_->getName() << "!" << std::endl;
     369                        COUT(1) << "An error occurred in SubclassIdentifier:" << std::endl;
     370                        COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassManager<T>::getIdentifier()->getName() << "!" << std::endl;
    383371                        COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl;
    384372                        COUT(1) << "Aborting..." << std::endl;
     
    386374                    else
    387375                    {
     376                        COUT(1) << "An error occurred in SubclassIdentifier:" << std::endl;
    388377                        COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined." << std::endl;
    389378                        COUT(1) << "Aborting..." << std::endl;
     
    416405        private:
    417406            Identifier* identifier_;            //!< The assigned identifier
    418             Identifier* subclassIdentifier_;    //!< The identifier of the subclass
    419407    };
    420408}
  • code/branches/core/src/orxonox/core/Language.cc

    r790 r811  
    161161    void Language::addEntry(const LanguageEntryName& name, const std::string& entry)
    162162    {
    163         COUT(5) << "Called addEntry with\n  name: " << name << "\n  entry: " <<  entry << std::endl;
     163        COUT(5) << "Language: Called addEntry with\n  name: " << name << "\n  entry: " <<  entry << std::endl;
    164164        std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find(name);
    165165        if (it == this->languageEntries_.end())
     
    197197        {
    198198            // Uh, oh, an undefined entry was requested: return the default string
    199             COUT(2) << "Error: Language entry \"" << name << "\" not found!" << std::endl;
     199            COUT(2) << "Warning: Language entry \"" << name << "\" not found!" << std::endl;
    200200            return this->defaultTranslation_;
    201201        }
     
    230230        if (!file.is_open())
    231231        {
     232            COUT(1) << "An error occurred in Language:" << std::endl;
    232233            COUT(1) << "Error: Couldn't open file " << getFileName(this->defaultLanguage_) << " to read the default language entries!" << std::endl;
    233234            return;
     
    271272        if (!file.is_open())
    272273        {
     274            COUT(1) << "An error occurred in Language:" << std::endl;
    273275            COUT(1) << "Error: Couldn't open file " << getFileName(this->language_) << " to read the translated language entries!" << std::endl;
    274276            ResetConfigValue(language_);
     
    314316    void Language::writeDefaultLanguageFile() const
    315317    {
    316         COUT(4) << "Write default language file." << std::endl;
     318        COUT(4) << "Language: Write default language file." << std::endl;
    317319
    318320        // Open the file
     
    322324        if (!file.is_open())
    323325        {
     326            COUT(1) << "An error occurred in Language:" << std::endl;
    324327            COUT(1) << "Error: Couldn't open file " << getFileName(this->defaultLanguage_) << " to write the default language entries!" << std::endl;
    325328            return;
  • code/branches/core/src/orxonox/core/MetaObjectList.h

    r805 r811  
    9999
    100100
    101         COUT(4) << "*** Removing Object from " << this->element_->object_->getIdentifier()->getName() << "-list." << std::endl;
     101        COUT(4) << "*** MetaObjectList: Removing Object from " << this->element_->object_->getIdentifier()->getName() << "-list." << std::endl;
    102102        delete this->element_;
    103103    }
  • code/branches/core/src/orxonox/objects/Test.h

    r790 r811  
    7474        public:
    7575            A1B2() { RegisterObject(A1B2); }
     76            virtual void test() = 0;
    7677    };
    7778
     
    116117        public:
    117118            A1B2C1() { RegisterObject(A1B2C1); }
     119            void test() { std::cout << "test!\n"; }
    118120    };
    119121
     
    158160    CreateFactory(A3);
    159161    CreateFactory(A1B1);
    160     CreateFactory(A1B2);
     162//    CreateFactory(A1B2);
    161163    CreateFactory(A2B1);
    162164    CreateFactory(A2B2);
Note: See TracChangeset for help on using the changeset viewer.