[132] | 1 | #include "ClassHierarchy.h" |
---|
| 2 | |
---|
[149] | 3 | namespace orxonox |
---|
| 4 | { |
---|
| 5 | // ############################### |
---|
| 6 | // ### Identifier ### |
---|
| 7 | // ############################### |
---|
[150] | 8 | // Identifier* Identifier::pointer_ = NULL; |
---|
[149] | 9 | /* |
---|
| 10 | Identifier* Identifier::registerClass(IdentifierList* parents) |
---|
[132] | 11 | { |
---|
[149] | 12 | if (!pointer_) |
---|
| 13 | { |
---|
| 14 | pointer_ = new Identifier(); |
---|
| 15 | pointer_->initialize(parents); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | return pointer_; |
---|
[132] | 19 | } |
---|
[149] | 20 | */ |
---|
| 21 | Identifier::Identifier() |
---|
| 22 | { |
---|
| 23 | this->bCreatedOneObject_ = false; |
---|
| 24 | this->directParents_ = new IdentifierList(); |
---|
| 25 | this->allParents_ = new IdentifierList(); |
---|
| 26 | this->directChildren_ = new IdentifierList(); |
---|
| 27 | this->allChildren_ = new IdentifierList(); |
---|
| 28 | this->objects_ = new ObjectList(); |
---|
| 29 | } |
---|
[132] | 30 | |
---|
[149] | 31 | void Identifier::initialize(IdentifierList* parents) |
---|
[132] | 32 | { |
---|
[149] | 33 | if (parents) |
---|
| 34 | { |
---|
| 35 | this->bCreatedOneObject_ = true; |
---|
| 36 | |
---|
| 37 | IdentifierListElement* temp1; |
---|
| 38 | IdentifierListElement* temp2; |
---|
| 39 | IdentifierListElement* temp3; |
---|
| 40 | |
---|
| 41 | temp1 = parents->first_; |
---|
| 42 | while (temp1) |
---|
| 43 | { |
---|
| 44 | temp2 = temp1->identifier_->directParents_->first_; |
---|
| 45 | while (temp2) |
---|
| 46 | { |
---|
| 47 | temp3 = parents->first_; |
---|
| 48 | while(temp3) |
---|
| 49 | { |
---|
| 50 | if (temp3->identifier_ == temp2->identifier_) |
---|
| 51 | temp3->bDirect_ = false; |
---|
| 52 | |
---|
| 53 | temp3 = temp3->next_; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | temp2 = temp2->next_; |
---|
| 57 | } |
---|
| 58 | temp1 = temp1->next_; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | temp1 = parents->first_; |
---|
| 62 | while (temp1) |
---|
| 63 | { |
---|
| 64 | if (temp1->bDirect_) |
---|
| 65 | { |
---|
| 66 | this->directParents_->add(temp1->identifier_); |
---|
[150] | 67 | temp1->identifier_->directChildren_->add(this); |
---|
[149] | 68 | } |
---|
| 69 | |
---|
| 70 | this->allParents_->add(temp1->identifier_); |
---|
[150] | 71 | temp1->identifier_->allChildren_->add(this); |
---|
[149] | 72 | |
---|
| 73 | temp1 = temp1->next_; |
---|
| 74 | } |
---|
| 75 | } |
---|
[132] | 76 | } |
---|
| 77 | |
---|
[149] | 78 | void Identifier::addObject(BaseObject* object) |
---|
[132] | 79 | { |
---|
[149] | 80 | this->objects_->add(object); |
---|
[132] | 81 | } |
---|
| 82 | |
---|
[149] | 83 | void Identifier::removeObject(BaseObject* object) |
---|
[132] | 84 | { |
---|
[149] | 85 | this->objects_->remove(object); |
---|
[132] | 86 | } |
---|
| 87 | |
---|
[149] | 88 | bool Identifier::isA(Identifier* identifier) |
---|
[132] | 89 | { |
---|
[150] | 90 | return (identifier == this || this->allParents_->isInList(identifier)); |
---|
[132] | 91 | } |
---|
| 92 | |
---|
[149] | 93 | bool Identifier::isDirectA(Identifier* identifier) |
---|
[132] | 94 | { |
---|
[150] | 95 | return (identifier == this); |
---|
[132] | 96 | } |
---|
| 97 | |
---|
[149] | 98 | bool Identifier::isChildOf(Identifier* identifier) |
---|
[132] | 99 | { |
---|
[149] | 100 | return this->allParents_->isInList(identifier); |
---|
[132] | 101 | } |
---|
| 102 | |
---|
[149] | 103 | bool Identifier::isDirectChildOf(Identifier* identifier) |
---|
[132] | 104 | { |
---|
[149] | 105 | return this->directParents_->isInList(identifier); |
---|
[132] | 106 | } |
---|
| 107 | |
---|
[149] | 108 | bool Identifier::isParentOf(Identifier* identifier) |
---|
[132] | 109 | { |
---|
[149] | 110 | return this->allChildren_->isInList(identifier); |
---|
[132] | 111 | } |
---|
| 112 | |
---|
[149] | 113 | bool Identifier::isDirectParentOf(Identifier* identifier) |
---|
[132] | 114 | { |
---|
[149] | 115 | return this->directChildren_->isInList(identifier); |
---|
[132] | 116 | } |
---|
| 117 | |
---|
[149] | 118 | |
---|
| 119 | // ############################### |
---|
| 120 | // ### IdentifierList ### |
---|
| 121 | // ############################### |
---|
| 122 | IdentifierList::IdentifierList() |
---|
[132] | 123 | { |
---|
[149] | 124 | this->first_ = NULL; |
---|
[132] | 125 | } |
---|
| 126 | |
---|
[149] | 127 | IdentifierList::~IdentifierList() |
---|
[132] | 128 | { |
---|
[149] | 129 | IdentifierListElement* temp; |
---|
| 130 | while (this->first_) |
---|
[132] | 131 | { |
---|
[149] | 132 | temp = this->first_->next_; |
---|
| 133 | delete this->first_; |
---|
| 134 | this->first_ = temp; |
---|
[132] | 135 | } |
---|
[149] | 136 | } |
---|
[132] | 137 | |
---|
[149] | 138 | void IdentifierList::add(Identifier* identifier) |
---|
| 139 | { |
---|
| 140 | IdentifierListElement* temp = this->first_; |
---|
| 141 | this->first_ = new IdentifierListElement(identifier); |
---|
| 142 | this->first_->next_ = temp; |
---|
[132] | 143 | } |
---|
| 144 | |
---|
[149] | 145 | void IdentifierList::remove(Identifier* identifier) |
---|
[132] | 146 | { |
---|
[149] | 147 | if (!identifier) |
---|
[132] | 148 | return; |
---|
| 149 | |
---|
[149] | 150 | if (this->first_->identifier_ == identifier) |
---|
[132] | 151 | { |
---|
[149] | 152 | IdentifierListElement* temp = this->first_->next_; |
---|
| 153 | delete this->first_; |
---|
| 154 | this->first_ = temp; |
---|
[132] | 155 | |
---|
| 156 | return; |
---|
| 157 | } |
---|
| 158 | |
---|
[149] | 159 | IdentifierListElement* temp = this->first_; |
---|
| 160 | while (temp->next_) |
---|
[132] | 161 | { |
---|
[149] | 162 | if (temp->next_->identifier_ == identifier) |
---|
[132] | 163 | { |
---|
[149] | 164 | IdentifierListElement* temp2 = temp->next_->next_; |
---|
| 165 | delete temp->next_; |
---|
| 166 | temp->next_ = temp2; |
---|
[132] | 167 | |
---|
| 168 | return; |
---|
| 169 | } |
---|
| 170 | |
---|
[149] | 171 | temp = temp->next_; |
---|
[132] | 172 | } |
---|
| 173 | } |
---|
| 174 | |
---|
[149] | 175 | bool IdentifierList::isInList(Identifier* identifier) |
---|
| 176 | { |
---|
| 177 | IdentifierListElement* temp = this->first_; |
---|
| 178 | while (temp) |
---|
| 179 | { |
---|
| 180 | if (temp->identifier_ == identifier) |
---|
| 181 | return true; |
---|
[132] | 182 | |
---|
[149] | 183 | temp = temp->next_; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | return false; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | // ############################### |
---|
| 191 | // ### IdentifierListElement ### |
---|
| 192 | // ############################### |
---|
| 193 | IdentifierListElement::IdentifierListElement(Identifier* identifier) |
---|
[132] | 194 | { |
---|
[149] | 195 | this->identifier_ = identifier; |
---|
| 196 | this->next_ = NULL; |
---|
| 197 | this->bDirect_ = true; |
---|
[132] | 198 | } |
---|
| 199 | |
---|
[149] | 200 | |
---|
| 201 | // ############################### |
---|
| 202 | // ### ObjectList ### |
---|
| 203 | // ############################### |
---|
| 204 | ObjectList::ObjectList() |
---|
[132] | 205 | { |
---|
[149] | 206 | this->first_ = NULL; |
---|
[132] | 207 | } |
---|
| 208 | |
---|
[149] | 209 | ObjectList::~ObjectList() |
---|
[132] | 210 | { |
---|
[149] | 211 | ObjectListElement* temp; |
---|
| 212 | while (this->first_) |
---|
[132] | 213 | { |
---|
[149] | 214 | temp = this->first_->next_; |
---|
| 215 | delete this->first_; |
---|
| 216 | this->first_ = temp; |
---|
[132] | 217 | } |
---|
| 218 | } |
---|
| 219 | |
---|
[149] | 220 | void ObjectList::add(BaseObject* object) |
---|
[132] | 221 | { |
---|
[149] | 222 | ObjectListElement* temp = this->first_; |
---|
| 223 | this->first_ = new ObjectListElement(object); |
---|
| 224 | this->first_->next_ = temp; |
---|
[132] | 225 | } |
---|
| 226 | |
---|
[149] | 227 | void ObjectList::remove(BaseObject* object) |
---|
[132] | 228 | { |
---|
[149] | 229 | if (!object) |
---|
| 230 | return; |
---|
[132] | 231 | |
---|
[149] | 232 | if (this->first_->object_ == object) |
---|
[132] | 233 | { |
---|
[149] | 234 | ObjectListElement* temp = this->first_->next_; |
---|
| 235 | delete this->first_; |
---|
| 236 | this->first_ = temp; |
---|
[132] | 237 | |
---|
[149] | 238 | return; |
---|
[132] | 239 | } |
---|
| 240 | |
---|
[149] | 241 | ObjectListElement* temp = this->first_; |
---|
| 242 | while (temp->next_) |
---|
[132] | 243 | { |
---|
[149] | 244 | if (temp->next_->object_ == object) |
---|
| 245 | { |
---|
| 246 | ObjectListElement* temp2 = temp->next_->next_; |
---|
| 247 | delete temp->next_; |
---|
| 248 | temp->next_ = temp2; |
---|
[132] | 249 | |
---|
[149] | 250 | return; |
---|
[132] | 251 | } |
---|
| 252 | |
---|
[149] | 253 | temp = temp->next_; |
---|
[132] | 254 | } |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | |
---|
[149] | 258 | // ############################### |
---|
| 259 | // ### ObjectListElement ### |
---|
| 260 | // ############################### |
---|
| 261 | ObjectListElement::ObjectListElement(BaseObject* object) |
---|
[132] | 262 | { |
---|
[149] | 263 | this->object_ = object; |
---|
| 264 | this->next_ = NULL; |
---|
[132] | 265 | } |
---|
[149] | 266 | } |
---|