Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 2, 2007, 1:25:00 AM (16 years ago)
Author:
landauf
Message:

update; dont look at it, its not finished

File:
1 edited

Legend:

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

    r132 r149  
    66// DONE:
    77// - klassenhierarchie aufbauen
     8// - in listen einfügen
     9// - factory
    810// - klassen-identifier
     11// - isA u.ä. vergleiche
    912
    1013// TODO:
    1114// - durch listen iterieren
    12 // - isA usw vergleiche
    13 // - new überladen + objekt in liste eintragen
    1415// - searchtree für classname-strings
    1516
    16 //namespace orxonox
    17 //{
    18     class ClassName;
    19     class ClassList;
     17
     18namespace orxonox
     19{
     20    // ##### Identifier #####
     21    class IdentifierList;
    2022    class ObjectList;
    2123    class BaseObject;
    2224
     25    class Identifier
     26    {
     27        template <class T>
     28        friend class ClassIdentifier;
     29
     30        public:
     31//            static Identifier* registerClass(IdentifierList* parents);
     32            void addObject(BaseObject* object);
     33            void removeObject(BaseObject* object);
     34
     35            bool isA(Identifier* identifier);
     36            bool isDirectA(Identifier* identifier);
     37            bool isChildOf(Identifier* identifier);
     38            bool isDirectChildOf(Identifier* identifier);
     39            bool isParentOf(Identifier* identifier);
     40            bool isDirectParentOf(Identifier* identifier);
     41
     42        protected:
     43            Identifier();
     44            void initialize(IdentifierList* identifier);
     45
     46            static Identifier* pointer_;
     47
     48            IdentifierList* directParents_;
     49            IdentifierList* allParents_;
     50            IdentifierList* directChildren_;
     51            IdentifierList* allChildren_;
     52
     53            ObjectList* objects_;
     54            std::string name_;
     55
     56        private:
     57            bool bCreatedOneObject_;
     58    };
     59
    2360    template <class T>
    24     class ClassNameSingleton
     61    class ClassIdentifier : public Identifier
     62    {
     63//        friend class Identifier;
     64
     65        public:
     66            static Identifier* registerClass(IdentifierList* parents);
     67            static Identifier* getIdentifier();
     68            static T* create();
     69
     70        private:
     71            ClassIdentifier();
     72    };
     73
     74    #define getStringFromClassName(ClassName) \
     75        #ClassName
     76
     77    template <class T>
     78    ClassIdentifier<T>::ClassIdentifier()
     79    {
     80    }
     81
     82    template <class T>
     83    Identifier* ClassIdentifier<T>::registerClass(IdentifierList* parents)
     84    {
     85        if (!pointer_)
     86        {
     87            pointer_ = new ClassIdentifier();
     88            pointer_->name_ = getStringFromClassName(T);
     89            pointer_->initialize(parents);
     90        }
     91
     92        return pointer_;
     93    }
     94
     95    template <class T>
     96    Identifier* ClassIdentifier<T>::getIdentifier()
     97    {
     98        if (!pointer_)
     99        {
     100            T* temp = new T();
     101            delete temp;
     102        }
     103
     104        return pointer_;
     105    }
     106
     107    template <class T>
     108    T* ClassIdentifier<T>::create()
     109    {
     110        return new T();
     111    }
     112
     113    // ##### Identifier List #####
     114    class IdentifierListElement;
     115
     116    class IdentifierList
    25117    {
    26118        public:
    27             static ClassName* getClassName(BaseObject* object, bool bIsRootClass);
    28             static ClassName* getNewClassName();
    29             BaseObject* create();
     119            IdentifierList();
     120            ~IdentifierList();
     121            void add(Identifier* identifier);
     122            void remove(Identifier* identifier);
     123            bool isInList(Identifier* identifier);
    30124
    31         private:
    32             ClassNameSingleton();
    33             ~ClassNameSingleton();
    34             static ClassNameSingleton *pointer;
    35             static ClassName *className;
     125            IdentifierListElement* first_;
    36126    };
    37127
    38     class ClassName
     128    class IdentifierListElement
    39129    {
    40130        public:
    41             ClassName(const std::string& name, ClassNameSingleton<class T>* factory);
    42             ~ClassName();
     131            IdentifierListElement(Identifier* identifier);
    43132
    44             std::string name;
    45             ClassName *parentClass;
    46             ClassList *childClasses;
    47             ObjectList *objects;
    48             ClassNameSingleton<class T> *factory;
     133            Identifier* identifier_;
     134            IdentifierListElement* next_;
     135            bool bDirect_;
    49136    };
    50137
    51     class ClassListItem
    52     {
    53         public:
    54             ClassListItem(ClassName* className);
    55             ~ClassListItem();
    56138
    57             ClassListItem *next;
    58             ClassName *className;
    59     };
    60 
    61     class ClassList
    62     {
    63         public:
    64             ClassList();
    65             ~ClassList();
    66             void add(ClassName* className);
    67 
    68             ClassListItem *first;
    69     };
    70 
    71     class ObjectListItem
    72     {
    73         public:
    74             ObjectListItem(BaseObject* object);
    75             ~ObjectListItem();
    76 
    77             ObjectListItem *next;
    78             BaseObject *object;
    79     };
     139    // ##### Object List #####
     140    class ObjectListElement;
    80141
    81142    class ObjectList
     
    87148            void remove(BaseObject* object);
    88149
    89             ObjectListItem *first;
     150            ObjectListElement* first_;
    90151    };
    91152
    92     class ClassNameTree
     153    class ObjectListElement
    93154    {
    94155        public:
    95             static ClassNameTree* getSingleton();
    96             BaseObject* create(ClassName* className);
    97             BaseObject* create(std::string& name);
    98             ClassName* getClassName(std::string& name);
    99             ClassName* getClassName(std::string& name, ClassName* root);
    100             ClassName* getRootClass() { return this->rootClass; }
    101             void setRootClass(ClassName* className) { this->rootClass = className; }
     156            ObjectListElement(BaseObject* object);
    102157
    103         private:
    104             ClassNameTree();
    105             ~ClassNameTree();
    106             static ClassNameTree *pointer;
    107             ClassName* rootClass;
     158            BaseObject* object_;
     159            ObjectListElement* next_;
    108160    };
    109161
    110162
    111     #define className(ClassName) \
    112         ClassNameSingleton<ClassName>::getNewClassName()
     163    // ##### Macros #####
     164    #define registerRootObject(ClassName) \
     165        this->parents_ = new IdentifierList(); \
     166        this->identifier_ = ClassIdentifier<ClassName>::registerClass(this->parents_); \
     167        this->parents_->add(this->identifier_); \
     168        this->identifier_->addObject(this)
    113169
    114     #define registerObject(ClassName, bIsRootClass) \
    115         this->className = ClassNameSingleton<ClassName>::getClassName(this, bIsRootClass)
     170    #define registerObject(ClassName) \
     171        this->identifier_->removeObject(this); \
     172        this->identifier_ = ClassIdentifier<ClassName>::registerClass(this->parents_); \
     173        this->parents_->add(this->identifier_); \
     174        this->identifier_->addObject(this)
    116175
    117176    #define unregisterObject() \
    118         this->className->objects->remove(this)
     177        delete this->parents_; \
     178        this->identifier_->removeObject(this)
    119179
    120     #define factory(ClassName) \
    121         ClassNameTree::getSingleton()->create(ClassName)
    122 //}
     180    #define Class(ClassName) \
     181        ClassIdentifier<ClassName>::getIdentifier()
     182
     183    #define Factory(ClassName) \
     184        ClassIdentifier<ClassName>::create()
     185}
    123186
    124187#endif
Note: See TracChangeset for help on using the changeset viewer.