Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 162


Ignore:
Timestamp:
Nov 5, 2007, 12:52:26 AM (16 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>

Location:
code/branches/objecthierarchie/src
Files:
3 added
5 edited

Legend:

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

    r150 r162  
    33
    44#include "ClassHierarchy.h"
     5#include "OrxonoxClass.h"
    56
    67namespace orxonox
    78{
    8     class BaseObject
     9    class BaseObject : virtual public OrxonoxClass
    910    {
    1011        public:
     
    1314
    1415            inline bool isA(Identifier* identifier)
    15                 { this->identifier_->isA(identifier); }
     16                { this->getIdentifier()->isA(identifier); }
    1617            inline bool isDirectA(Identifier* identifier)
    17                 { this->identifier_->isDirectA(identifier); }
     18                { this->getIdentifier()->isDirectA(identifier); }
    1819            inline bool isChildOf(Identifier* identifier)
    19                 { this->identifier_->isChildOf(identifier); }
     20                { this->getIdentifier()->isChildOf(identifier); }
    2021            inline bool isDirectChildOf(Identifier* identifier)
    21                 { this->identifier_->isDirectChildOf(identifier); }
     22                { this->getIdentifier()->isDirectChildOf(identifier); }
    2223            inline bool isParentOf(Identifier* identifier)
    23                 { this->identifier_->isParentOf(identifier); }
     24                { this->getIdentifier()->isParentOf(identifier); }
    2425            inline bool isDirectParentOf(Identifier* identifier)
    25                 { this->identifier_->isDirectParentOf(identifier); }
     26                { this->getIdentifier()->isDirectParentOf(identifier); }
    2627
    27             ClassIdentifier<class BaseObject>* identifier_;
     28//            Identifier* identifier_;
    2829
    29         protected:
    30             IdentifierList* parents_; // INTERN! Don't touch this!
    31 
    32         private:
     30//        protected:
     31//            IdentifierList* parents_; // INTERN! Don't touch this!
    3332
    3433    };
  • code/branches/objecthierarchie/src/CMakeLists.txt

    r131 r162  
    22
    33# create a few variables to simplify life
    4 SET(SRC_FILES orxonox.cc BaseObject.cc ClassHierarchy.cc)
    5 SET(INC_FILES BaseObject.h ClassHierarchy.h)
     4SET(SRC_FILES orxonox.cc ClassHierarchy.cc OrxonoxClass.cc BaseObject.cc)
     5SET(INC_FILES ClassHierarchy.h OrxonoxClass.h BaseObject.h Test.h)
    66
    77#Creates an executable
  • code/branches/objecthierarchie/src/ClassHierarchy.cc

    r150 r162  
    3131    void Identifier::initialize(IdentifierList* parents)
    3232    {
     33        std::cout << "*** Initialize " << this->name_ << "-Singleton.\n";
    3334        if (parents)
    3435        {
     
    7677    }
    7778
    78     void Identifier::addObject(BaseObject* object)
    79     {
     79    void Identifier::addObject(OrxonoxClass* object)
     80    {
     81        std::cout << "*** Added " << this->name_ << " to list.\n";
    8082        this->objects_->add(object);
    8183    }
    8284
    83     void Identifier::removeObject(BaseObject* object)
    84     {
     85    void Identifier::removeObject(OrxonoxClass* object)
     86    {
     87        std::cout << "*** Removed " << this->name_ << " from list.\n";
    8588        this->objects_->remove(object);
    8689    }
     
    218221    }
    219222
    220     void ObjectList::add(BaseObject* object)
     223    void ObjectList::add(OrxonoxClass* object)
    221224    {
    222225        ObjectListElement* temp = this->first_;
     
    225228    }
    226229
    227     void ObjectList::remove(BaseObject* object)
     230    void ObjectList::remove(OrxonoxClass* object)
    228231    {
    229232        if (!object)
     
    259262    // ###    ObjectListElement    ###
    260263    // ###############################
    261     ObjectListElement::ObjectListElement(BaseObject* object)
     264    ObjectListElement::ObjectListElement(OrxonoxClass* object)
    262265    {
    263266        this->object_ = object;
    264267        this->next_ = NULL;
    265268    }
     269
     270
     271    // ###############################
     272    // ###     ClassHierarchy      ###
     273    // ###############################
     274    ClassHierarchy* ClassHierarchy::pointer_ = NULL;
     275
     276    ClassHierarchy* ClassHierarchy::getSingleton()
     277    {
     278        if (!pointer_)
     279            pointer_ = new ClassHierarchy();
     280
     281        return pointer_;
     282    }
     283
     284    ClassHierarchy::ClassHierarchy()
     285    {
     286        this->bCreatingHierarchy_ = false;
     287    }
    266288}
  • 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) \
  • code/branches/objecthierarchie/src/orxonox.cc

    r116 r162  
    3131#include <OgreCEGUIRenderer.h>
    3232
     33#include "BaseObject.h"
     34#include "Test.h"
     35
    3336#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    3437#include <CoreFoundation/CoreFoundation.h>
     
    8386    void go()
    8487    {
    85       createRoot();
     88/*      createRoot();
    8689      defineResources();
    8790      setupRenderSystem();
     
    9396      createFrameListener();
    9497      startRenderLoop();
     98*/
     99      std::cout << "Test 1\n";
     100      orxonox::BaseObject* test1;
     101      test1 = new orxonox::BaseObject();
     102      test1 = new orxonox::BaseObject();
     103      test1 = new orxonox::BaseObject();
     104
     105      std::cout << "Test 2\n";
     106      orxonox::A1* test2;
     107      test2 = new orxonox::A1();
     108      test2 = new orxonox::A1();
     109      test2 = new orxonox::A1();
     110
     111      std::cout << "Test 3\n";
     112      orxonox::BaseObject* test3;
     113      test3 = new orxonox::BaseObject();
     114      test3 = new orxonox::BaseObject();
     115      test3 = new orxonox::BaseObject();
     116
     117      std::cout << "Test 4\n";
     118      orxonox::A3* test4;
     119      test4 = new orxonox::A3();
     120      test4 = new orxonox::A3();
     121      test4 = new orxonox::A3();
     122
    95123    }
    96124
Note: See TracChangeset for help on using the changeset viewer.