Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 5, 2007, 12:52:26 AM (17 years ago)
Author:
landauf
Message:

it starts to work, but there is still much to do.

@bensch: thanks for you mail, but i can't tell you much at the moment - i'm still changing lots of things and i have no idea if everything will work as intendet, so i'll write you as soon as i have reliable informations :)
</abuse log for pms>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchie/src/ClassHierarchy.h

    r150 r162  
    33
    44#include <string>
     5#include <iostream>
    56
    67// DONE:
     
    1819namespace orxonox
    1920{
     21    // ##### ClassHierarchy #####
     22    class ClassHierarchy
     23    {
     24        public:
     25            static ClassHierarchy* getSingleton();
     26            bool isCreatingHierarchy() { return this->bCreatingHierarchy_; }
     27            void createHierarchy(bool bCreatingHierarchy) { this->bCreatingHierarchy_ = bCreatingHierarchy; std::cout << "*** Switched Hierarchy-Creating-Mode to" << bCreatingHierarchy << "\n"; }
     28
     29        private:
     30            ClassHierarchy();
     31
     32            static ClassHierarchy* pointer_;
     33            bool bCreatingHierarchy_;
     34    };
     35
    2036    // ##### Identifier #####
    2137    class IdentifierList;
    2238    class ObjectList;
    23     class BaseObject;
     39    class OrxonoxClass;
    2440    template <class T>
    2541    class ClassIdentifier;
     
    3147
    3248        public:
    33             void addObject(BaseObject* object);
    34             void removeObject(BaseObject* object);
     49            void addObject(OrxonoxClass* object);
     50            void removeObject(OrxonoxClass* object);
    3551
    3652            bool isA(Identifier* identifier);
     
    6076    {
    6177        public:
    62             static ClassIdentifier<T>* registerClass(IdentifierList* parents);
     78            static ClassIdentifier<T>* registerClass(IdentifierList* parents, std::string name, bool bRootClass);
    6379            static ClassIdentifier<T>* getIdentifier();
    6480            static T* create();
     
    7187    };
    7288
    73     #define getStringFromClassName(ClassName) \
    74         #ClassName
    75 
    7689    template <class T>
    7790    ClassIdentifier<T>* ClassIdentifier<T>::pointer_ = NULL;
     
    8396
    8497    template <class T>
    85     ClassIdentifier<T>* ClassIdentifier<T>::registerClass(IdentifierList* parents)
    86     {
     98    ClassIdentifier<T>* ClassIdentifier<T>::registerClass(IdentifierList* parents, std::string name, bool bRootClass)
     99    {
     100        std::cout << "*** Register Class in " << name << "-Singleton.\n";
    87101        if (!pointer_)
    88102        {
    89             pointer_ = new ClassIdentifier();
    90             pointer_->name_ = getStringFromClassName(T);
    91             pointer_->initialize(parents);
     103            std::cout << "*** Register Class in " << name << "-Singleton -> Create Singleton.\n";
     104            if (parents || bRootClass)
     105            {
     106                pointer_ = new ClassIdentifier();
     107                pointer_->name_ = name;
     108                pointer_->initialize(parents);
     109            }
     110            else
     111            {
     112                pointer_ = getIdentifier();
     113            }
    92114        }
    93115
     
    98120    ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
    99121    {
     122        std::cout << "*** Get Identifier.\n";
    100123        if (!pointer_)
    101124        {
     125            std::cout << "*** Get Identifier -> Create Class\n";
     126            ClassHierarchy::getSingleton()->createHierarchy(true);
    102127            T* temp = new T();
     128            ClassHierarchy::getSingleton()->createHierarchy(false);
    103129            delete temp;
    104130        }
     
    147173            ObjectList();
    148174            ~ObjectList();
    149             void add(BaseObject* object);
    150             void remove(BaseObject* object);
     175            void add(OrxonoxClass* object);
     176            void remove(OrxonoxClass* object);
    151177
    152178            ObjectListElement* first_;
     
    156182    {
    157183        public:
    158             ObjectListElement(BaseObject* object);
    159 
    160             BaseObject* object_;
     184            ObjectListElement(OrxonoxClass* object);
     185
     186            OrxonoxClass* object_;
    161187            ObjectListElement* next_;
    162188    };
    163 
    164189
    165190    // ##### Macros #####
    166191    #define registerRootObject(ClassName) \
    167         this->parents_ = new IdentifierList(); \
    168         this->identifier_ = ClassIdentifier<ClassName>::registerClass(this->parents_); \
    169         this->parents_->add(this->identifier_); \
    170         this->identifier_->addObject(this)
     192        std::cout << "*** Register Root-Object: " << #ClassName << "\n"; \
     193        if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && !this->getParents()) \
     194            this->setParents(new IdentifierList()); \
     195        if (this->getIdentifier()) \
     196            this->getIdentifier()->removeObject(this); \
     197        this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, true)); \
     198        if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \
     199            this->getParents()->add(this->getIdentifier()); \
     200        this->getIdentifier()->addObject(this)
    171201
    172202    #define registerObject(ClassName) \
    173         this->identifier_->removeObject(this); \
    174         this->identifier_ = ClassIdentifier<ClassName>::registerClass(this->parents_); \
    175         this->parents_->add(this->identifier_); \
    176         this->identifier_->addObject(this)
     203        std::cout << "*** Register Object: " << #ClassName << "\n"; \
     204        this->getIdentifier()->removeObject(this); \
     205        this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, false)); \
     206        if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \
     207            this->getParents()->add(this->getIdentifier()); \
     208        this->getIdentifier()->addObject(this)
    177209
    178210    #define unregisterObject() \
    179         delete this->parents_; \
    180         this->identifier_->removeObject(this)
     211        this->getIdentifier()->removeObject(this)
    181212
    182213    #define Class(ClassName) \
Note: See TracChangeset for help on using the changeset viewer.