Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 457


Ignore:
Timestamp:
Dec 10, 2007, 8:34:48 PM (16 years ago)
Author:
landauf
Message:

changed the class-hierarchy creation: call Factory::createClassHierarchy() to create the hierarchy.
until now it was automatically created at the program-start, but that could have been a problem in the future when classes depend on ogre, because ogre isn't already initialized at that program-start, so i've changed it.

Location:
code/branches/objecthierarchy/src/orxonox
Files:
7 edited

Legend:

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

    r453 r457  
    1010
    1111#include "Identifier.h"
    12 #include "Debug.h"
    1312
    1413namespace orxonox
     
    2221    {
    2322        public:
    24             static bool create();
     23            static bool create(const std::string& name);
    2524            BaseObject* fabricate();
    2625
     
    3433
    3534    /**
    36         @brief Adds the ClassFactory to the Identifier of the same type and creates a new object to retrieve the parents.
     35        @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory.
    3736        @return Always true (this is needed because the compiler only allows assignments before main())
    3837    */
    3938    template <class T>
    40     bool ClassFactory<T>::create()
     39    bool ClassFactory<T>::create(const std::string& name)
    4140    {
    42         // Add the ClassFactory to the Classidentifier of type T
    4341        ClassIdentifier<T>::getIdentifier()->addFactory(new ClassFactory<T>);
    44 
    45         // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
    46         ClassIdentifier<T>::getIdentifier()->startCreatingHierarchy();
    47         COUT(4) << "*** Create Factory -> Create Class\n";
    48         BaseObject* temp = ClassIdentifier<T>::getIdentifier()->fabricate();
    49         delete temp;
    50         ClassIdentifier<T>::getIdentifier()->stopCreatingHierarchy();
     42        Factory::add(name, ClassIdentifier<T>::getIdentifier());
    5143
    5244        return true;
  • code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.cc

    r456 r457  
    421421        if (!ConfigValueContainer::readConfigFile_s)
    422422            ConfigValueContainer::readConfigFile(CONFIGFILEPATH);
    423 
    424423
    425424        // The string of the section we're searching
  • code/branches/objecthierarchy/src/orxonox/core/CoreIncludes.h

    r453 r457  
    8181*/
    8282#define CreateFactory(ClassName) \
    83     bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create()
     83    bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create(#ClassName)
    8484
    8585/**
  • code/branches/objecthierarchy/src/orxonox/core/Factory.cc

    r447 r457  
    66#include "Factory.h"
    77#include "Identifier.h"
     8#include "Debug.h"
     9#include "../objects/BaseObject.h"
    810
    911namespace orxonox
     
    6062        pointer_s->identifierNetworkIDMap_[newID] = identifier;
    6163    }
     64
     65    /**
     66        @brief Creates the class-hierarchy by creating and destroying one object of each type.
     67    */
     68    void Factory::createClassHierarchy()
     69    {
     70        if (!pointer_s)
     71            pointer_s = new Factory;
     72
     73        COUT(4) << "*** Factory -> Create class-hierarchy\n";
     74        std::map<std::string, Identifier*>::iterator it;
     75        it = pointer_s->identifierStringMap_.begin();
     76        (*pointer_s->identifierStringMap_.begin()).second->startCreatingHierarchy();
     77        for (it = pointer_s->identifierStringMap_.begin(); it != pointer_s->identifierStringMap_.end(); ++it)
     78        {
     79            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     80            BaseObject* temp = (*it).second->fabricate();
     81            delete temp;
     82        }
     83        (*pointer_s->identifierStringMap_.begin()).second->stopCreatingHierarchy();
     84        COUT(4) << "*** Factory -> Finished class-hierarchy creation\n";
     85    }
    6286}
  • code/branches/objecthierarchy/src/orxonox/core/Factory.h

    r447 r457  
    3636            static void add(const std::string& name, Identifier* identifier);
    3737            static void changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID);
     38            static void createClassHierarchy();
    3839
    3940        private:
  • code/branches/objecthierarchy/src/orxonox/core/Identifier.h

    r453 r457  
    6464        friend class SubclassIdentifier; // Forward declaration
    6565
    66         template <class T>
    67         friend class ClassFactory; // Forward declaration
     66        friend class Factory; // Forward declaration
    6867
    6968        public:
     
    216215            COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton.\n";
    217216            pointer_s->name_ = name;
    218             Factory::add(name, pointer_s); // Add the Identifier to the Factory
     217//            Factory::add(name, pointer_s); // Add the Identifier to the Factory
    219218
    220219            if (bRootClass)
  • code/branches/objecthierarchy/src/orxonox/orxonox.cc

    r454 r457  
    119119        setupCEGUI();
    120120        createFrameListener();
    121 
     121        Factory::createClassHierarchy();
    122122
    123123        #define testandcout(code) \
Note: See TracChangeset for help on using the changeset viewer.