Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapon_system_fw/src/class_hierarchy/ClassHierarchy.h @ 413

Last change on this file since 413 was 270, checked in by rgrieder, 17 years ago
  • added old version of class hierarchy in order to make things work (is not actually needed, but will be later anyway)
  • added the hud wrapper and the media files required
File size: 3.9 KB
Line 
1#ifndef _ClassHierarchy_H__
2#define _ClassHierarchy_H__
3
4#include <string>
5#include <iostream>
6
7// DONE AND TESTED:
8// - build class hierarchy
9// - isA, isChildOf, ...
10// - insert into class-lists
11// - ClassIdentifier
12// - BaseIdentifier
13
14// IN WORK:
15// - Factory
16
17// TO DO:
18// - iterate through lists
19// - searchtree for classname-strings
20
21
22namespace orxonox
23{
24    // ##### ClassHierarchy #####
25    template <class T>
26    class ClassIdentifier;
27
28    class ClassHierarchy
29    {
30        template <class T>
31        friend class ClassIdentifier;
32
33        public:
34            static ClassHierarchy* getSingleton();
35            bool isCreatingHierarchy() { return (this->hierarchyCreatingCounter_ > 0); }
36
37        private:
38            ClassHierarchy();
39            ~ClassHierarchy();
40            void startCreatingHierarchy() { this->hierarchyCreatingCounter_++; std::cout << "*** Increased Hierarchy-Creating-Counter to " << this->hierarchyCreatingCounter_ << "\n"; }
41            void stopCreatingHierarchy() { this->hierarchyCreatingCounter_--; std::cout << "*** Decreased Hierarchy-Creating-Counter to " << this->hierarchyCreatingCounter_ << "\n"; }
42
43            static ClassHierarchy* pointer_;
44            int hierarchyCreatingCounter_;
45    };
46
47
48    // ##### Macros #####
49    #define registerRootObject(ClassName) \
50        std::cout << "*** Register Root-Object: " << #ClassName << "\n"; \
51        if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && !this->getParents()) \
52            this->setParents(new IdentifierList()); \
53        if (this->getIdentifier()) \
54            this->getIdentifier()->removeObject(this); \
55        this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, true, false)); \
56        if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \
57            this->getParents()->add(this->getIdentifier()); \
58        this->getIdentifier()->addObject(this)
59
60    #define registerAbstractRootObject(ClassName) \
61        std::cout << "*** Register Root-Object: " << #ClassName << "\n"; \
62        if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && !this->getParents()) \
63            this->setParents(new IdentifierList()); \
64        if (this->getIdentifier()) \
65            this->getIdentifier()->removeObject(this); \
66        this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, true, true)); \
67        if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \
68            this->getParents()->add(this->getIdentifier()); \
69        this->getIdentifier()->addObject(this)
70
71    #define registerObject(ClassName) \
72        std::cout << "*** Register Object: " << #ClassName << "\n"; \
73        this->getIdentifier()->removeObject(this); \
74        this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, false, false)); \
75        if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \
76            this->getParents()->add(this->getIdentifier()); \
77        this->getIdentifier()->addObject(this)
78
79    #define registerAbstractObject(ClassName) \
80        std::cout << "*** Register Object: " << #ClassName << "\n"; \
81        this->getIdentifier()->removeObject(this); \
82        this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, false, true)); \
83        if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \
84            this->getParents()->add(this->getIdentifier()); \
85        this->getIdentifier()->addObject(this)
86
87    #define unregisterObject() \
88        this->getIdentifier()->removeObject(this)
89
90    #define Class(ClassName) \
91        ClassIdentifier<ClassName>::getIdentifier()
92
93    #define Factory(ClassName) \
94        ClassIdentifier<ClassName>::create()
95}
96
97#endif
Note: See TracBrowser for help on using the repository browser.