1 | #ifndef _MetaObjectList_H__ |
---|
2 | #define _MetaObjectList_H__ |
---|
3 | |
---|
4 | #include "ObjectList.h" |
---|
5 | #include "Identifier.h" |
---|
6 | |
---|
7 | namespace orxonox |
---|
8 | { |
---|
9 | class BaseMetaObjectListElement |
---|
10 | { |
---|
11 | public: |
---|
12 | virtual ~BaseMetaObjectListElement() {}; |
---|
13 | |
---|
14 | BaseMetaObjectListElement* next_; |
---|
15 | }; |
---|
16 | |
---|
17 | // ############################### |
---|
18 | // ### MetaObjectListElement ### |
---|
19 | // ############################### |
---|
20 | template <class T> |
---|
21 | class MetaObjectListElement : public BaseMetaObjectListElement |
---|
22 | { |
---|
23 | public: |
---|
24 | MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element); |
---|
25 | ~MetaObjectListElement(); |
---|
26 | |
---|
27 | ObjectListElement<T>* element_; |
---|
28 | ObjectList<T>* list_; |
---|
29 | }; |
---|
30 | |
---|
31 | template <class T> |
---|
32 | MetaObjectListElement<T>::MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element) |
---|
33 | { |
---|
34 | this->element_ = element; |
---|
35 | this->list_ = list; |
---|
36 | this->next_ = 0; |
---|
37 | } |
---|
38 | |
---|
39 | template <class T> |
---|
40 | MetaObjectListElement<T>::~MetaObjectListElement() |
---|
41 | { |
---|
42 | if (this->element_->next_) |
---|
43 | this->element_->next_->prev_ = this->element_->prev_; |
---|
44 | else |
---|
45 | this->list_->last_ = this->element_->prev_; |
---|
46 | |
---|
47 | if (this->element_->prev_) |
---|
48 | this->element_->prev_->next_ = this->element_->next_; |
---|
49 | else |
---|
50 | this->list_->first_ = this->element_->next_; |
---|
51 | |
---|
52 | |
---|
53 | #if HIERARCHY_VERBOSE |
---|
54 | std::cout << "*** Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n"; |
---|
55 | #endif |
---|
56 | delete this->element_; |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | // ############################### |
---|
61 | // ### ObjectList ### |
---|
62 | // ############################### |
---|
63 | class MetaObjectList |
---|
64 | { |
---|
65 | public: |
---|
66 | MetaObjectList(); |
---|
67 | ~MetaObjectList(); |
---|
68 | template <class T> |
---|
69 | void add(ObjectList<T>* list, ObjectListElement<T>* element); |
---|
70 | |
---|
71 | BaseMetaObjectListElement* first_; |
---|
72 | }; |
---|
73 | |
---|
74 | template <class T> |
---|
75 | void MetaObjectList::add(ObjectList<T>* list, ObjectListElement<T>* element) |
---|
76 | { |
---|
77 | BaseMetaObjectListElement* temp = this->first_; |
---|
78 | this->first_ = new MetaObjectListElement<T>(list, element); |
---|
79 | this->first_->next_ = temp; |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | #endif |
---|