[132] | 1 | #include "ClassHierarchy.h" |
---|
[172] | 2 | #include "OrxonoxClass.h" |
---|
[132] | 3 | |
---|
[149] | 4 | namespace orxonox |
---|
| 5 | { |
---|
| 6 | // ############################### |
---|
| 7 | // ### Identifier ### |
---|
| 8 | // ############################### |
---|
[150] | 9 | // Identifier* Identifier::pointer_ = NULL; |
---|
[149] | 10 | /* |
---|
| 11 | Identifier* Identifier::registerClass(IdentifierList* parents) |
---|
[132] | 12 | { |
---|
[149] | 13 | if (!pointer_) |
---|
| 14 | { |
---|
| 15 | pointer_ = new Identifier(); |
---|
| 16 | pointer_->initialize(parents); |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | return pointer_; |
---|
[132] | 20 | } |
---|
[149] | 21 | */ |
---|
| 22 | Identifier::Identifier() |
---|
| 23 | { |
---|
| 24 | this->bCreatedOneObject_ = false; |
---|
| 25 | this->directParents_ = new IdentifierList(); |
---|
| 26 | this->allParents_ = new IdentifierList(); |
---|
| 27 | this->directChildren_ = new IdentifierList(); |
---|
| 28 | this->allChildren_ = new IdentifierList(); |
---|
| 29 | this->objects_ = new ObjectList(); |
---|
| 30 | } |
---|
[132] | 31 | |
---|
[172] | 32 | Identifier::~Identifier() |
---|
| 33 | { |
---|
| 34 | delete this->directParents_; |
---|
| 35 | delete this->allParents_; |
---|
| 36 | delete this->directChildren_; |
---|
| 37 | delete this->allChildren_; |
---|
| 38 | delete this->objects_; |
---|
| 39 | delete &this->name_; |
---|
| 40 | } |
---|
| 41 | |
---|
[149] | 42 | void Identifier::initialize(IdentifierList* parents) |
---|
[132] | 43 | { |
---|
[162] | 44 | std::cout << "*** Initialize " << this->name_ << "-Singleton.\n"; |
---|
[149] | 45 | if (parents) |
---|
| 46 | { |
---|
| 47 | this->bCreatedOneObject_ = true; |
---|
| 48 | |
---|
| 49 | IdentifierListElement* temp1; |
---|
| 50 | IdentifierListElement* temp2; |
---|
| 51 | IdentifierListElement* temp3; |
---|
| 52 | |
---|
| 53 | temp1 = parents->first_; |
---|
| 54 | while (temp1) |
---|
| 55 | { |
---|
| 56 | temp2 = temp1->identifier_->directParents_->first_; |
---|
| 57 | while (temp2) |
---|
| 58 | { |
---|
| 59 | temp3 = parents->first_; |
---|
| 60 | while(temp3) |
---|
| 61 | { |
---|
| 62 | if (temp3->identifier_ == temp2->identifier_) |
---|
| 63 | temp3->bDirect_ = false; |
---|
| 64 | |
---|
| 65 | temp3 = temp3->next_; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | temp2 = temp2->next_; |
---|
| 69 | } |
---|
| 70 | temp1 = temp1->next_; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | temp1 = parents->first_; |
---|
| 74 | while (temp1) |
---|
| 75 | { |
---|
| 76 | if (temp1->bDirect_) |
---|
| 77 | { |
---|
| 78 | this->directParents_->add(temp1->identifier_); |
---|
[150] | 79 | temp1->identifier_->directChildren_->add(this); |
---|
[149] | 80 | } |
---|
| 81 | |
---|
| 82 | this->allParents_->add(temp1->identifier_); |
---|
[150] | 83 | temp1->identifier_->allChildren_->add(this); |
---|
[149] | 84 | |
---|
| 85 | temp1 = temp1->next_; |
---|
| 86 | } |
---|
| 87 | } |
---|
[132] | 88 | } |
---|
| 89 | |
---|
[162] | 90 | void Identifier::addObject(OrxonoxClass* object) |
---|
[132] | 91 | { |
---|
[162] | 92 | std::cout << "*** Added " << this->name_ << " to list.\n"; |
---|
[149] | 93 | this->objects_->add(object); |
---|
[132] | 94 | } |
---|
| 95 | |
---|
[162] | 96 | void Identifier::removeObject(OrxonoxClass* object) |
---|
[132] | 97 | { |
---|
[162] | 98 | std::cout << "*** Removed " << this->name_ << " from list.\n"; |
---|
[149] | 99 | this->objects_->remove(object); |
---|
[132] | 100 | } |
---|
| 101 | |
---|
[149] | 102 | bool Identifier::isA(Identifier* identifier) |
---|
[132] | 103 | { |
---|
[150] | 104 | return (identifier == this || this->allParents_->isInList(identifier)); |
---|
[132] | 105 | } |
---|
| 106 | |
---|
[172] | 107 | bool Identifier::isDirectlyA(Identifier* identifier) |
---|
[132] | 108 | { |
---|
[150] | 109 | return (identifier == this); |
---|
[132] | 110 | } |
---|
| 111 | |
---|
[149] | 112 | bool Identifier::isChildOf(Identifier* identifier) |
---|
[132] | 113 | { |
---|
[149] | 114 | return this->allParents_->isInList(identifier); |
---|
[132] | 115 | } |
---|
| 116 | |
---|
[149] | 117 | bool Identifier::isDirectChildOf(Identifier* identifier) |
---|
[132] | 118 | { |
---|
[149] | 119 | return this->directParents_->isInList(identifier); |
---|
[132] | 120 | } |
---|
| 121 | |
---|
[149] | 122 | bool Identifier::isParentOf(Identifier* identifier) |
---|
[132] | 123 | { |
---|
[149] | 124 | return this->allChildren_->isInList(identifier); |
---|
[132] | 125 | } |
---|
| 126 | |
---|
[149] | 127 | bool Identifier::isDirectParentOf(Identifier* identifier) |
---|
[132] | 128 | { |
---|
[149] | 129 | return this->directChildren_->isInList(identifier); |
---|
[132] | 130 | } |
---|
| 131 | |
---|
[149] | 132 | |
---|
| 133 | // ############################### |
---|
| 134 | // ### IdentifierList ### |
---|
| 135 | // ############################### |
---|
| 136 | IdentifierList::IdentifierList() |
---|
[132] | 137 | { |
---|
[149] | 138 | this->first_ = NULL; |
---|
[132] | 139 | } |
---|
| 140 | |
---|
[149] | 141 | IdentifierList::~IdentifierList() |
---|
[132] | 142 | { |
---|
[149] | 143 | IdentifierListElement* temp; |
---|
| 144 | while (this->first_) |
---|
[132] | 145 | { |
---|
[149] | 146 | temp = this->first_->next_; |
---|
| 147 | delete this->first_; |
---|
| 148 | this->first_ = temp; |
---|
[132] | 149 | } |
---|
[149] | 150 | } |
---|
[132] | 151 | |
---|
[149] | 152 | void IdentifierList::add(Identifier* identifier) |
---|
| 153 | { |
---|
| 154 | IdentifierListElement* temp = this->first_; |
---|
| 155 | this->first_ = new IdentifierListElement(identifier); |
---|
| 156 | this->first_->next_ = temp; |
---|
[132] | 157 | } |
---|
| 158 | |
---|
[149] | 159 | void IdentifierList::remove(Identifier* identifier) |
---|
[132] | 160 | { |
---|
[149] | 161 | if (!identifier) |
---|
[132] | 162 | return; |
---|
| 163 | |
---|
[149] | 164 | if (this->first_->identifier_ == identifier) |
---|
[132] | 165 | { |
---|
[149] | 166 | IdentifierListElement* temp = this->first_->next_; |
---|
| 167 | delete this->first_; |
---|
| 168 | this->first_ = temp; |
---|
[132] | 169 | |
---|
| 170 | return; |
---|
| 171 | } |
---|
| 172 | |
---|
[149] | 173 | IdentifierListElement* temp = this->first_; |
---|
| 174 | while (temp->next_) |
---|
[132] | 175 | { |
---|
[149] | 176 | if (temp->next_->identifier_ == identifier) |
---|
[132] | 177 | { |
---|
[149] | 178 | IdentifierListElement* temp2 = temp->next_->next_; |
---|
| 179 | delete temp->next_; |
---|
| 180 | temp->next_ = temp2; |
---|
[132] | 181 | |
---|
| 182 | return; |
---|
| 183 | } |
---|
| 184 | |
---|
[149] | 185 | temp = temp->next_; |
---|
[132] | 186 | } |
---|
| 187 | } |
---|
| 188 | |
---|
[149] | 189 | bool IdentifierList::isInList(Identifier* identifier) |
---|
| 190 | { |
---|
| 191 | IdentifierListElement* temp = this->first_; |
---|
| 192 | while (temp) |
---|
| 193 | { |
---|
| 194 | if (temp->identifier_ == identifier) |
---|
| 195 | return true; |
---|
[132] | 196 | |
---|
[149] | 197 | temp = temp->next_; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | return false; |
---|
| 201 | } |
---|
| 202 | |
---|
[172] | 203 | std::string IdentifierList::toString() |
---|
| 204 | { |
---|
| 205 | IdentifierListElement* temp = this->first_; |
---|
| 206 | std::string output = ""; |
---|
[149] | 207 | |
---|
[172] | 208 | while (temp) |
---|
| 209 | { |
---|
| 210 | output += temp->identifier_->getName(); |
---|
| 211 | output += " "; |
---|
| 212 | |
---|
| 213 | temp = temp->next_; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | return output; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | |
---|
[149] | 220 | // ############################### |
---|
| 221 | // ### IdentifierListElement ### |
---|
| 222 | // ############################### |
---|
| 223 | IdentifierListElement::IdentifierListElement(Identifier* identifier) |
---|
[132] | 224 | { |
---|
[149] | 225 | this->identifier_ = identifier; |
---|
| 226 | this->next_ = NULL; |
---|
| 227 | this->bDirect_ = true; |
---|
[132] | 228 | } |
---|
| 229 | |
---|
[172] | 230 | IdentifierListElement::~IdentifierListElement() |
---|
| 231 | { |
---|
| 232 | } |
---|
[149] | 233 | |
---|
[172] | 234 | |
---|
[149] | 235 | // ############################### |
---|
| 236 | // ### ObjectList ### |
---|
| 237 | // ############################### |
---|
| 238 | ObjectList::ObjectList() |
---|
[132] | 239 | { |
---|
[149] | 240 | this->first_ = NULL; |
---|
[132] | 241 | } |
---|
| 242 | |
---|
[149] | 243 | ObjectList::~ObjectList() |
---|
[132] | 244 | { |
---|
[149] | 245 | ObjectListElement* temp; |
---|
| 246 | while (this->first_) |
---|
[132] | 247 | { |
---|
[149] | 248 | temp = this->first_->next_; |
---|
| 249 | delete this->first_; |
---|
| 250 | this->first_ = temp; |
---|
[132] | 251 | } |
---|
| 252 | } |
---|
| 253 | |
---|
[162] | 254 | void ObjectList::add(OrxonoxClass* object) |
---|
[132] | 255 | { |
---|
[149] | 256 | ObjectListElement* temp = this->first_; |
---|
| 257 | this->first_ = new ObjectListElement(object); |
---|
| 258 | this->first_->next_ = temp; |
---|
[132] | 259 | } |
---|
| 260 | |
---|
[162] | 261 | void ObjectList::remove(OrxonoxClass* object) |
---|
[132] | 262 | { |
---|
[149] | 263 | if (!object) |
---|
| 264 | return; |
---|
[132] | 265 | |
---|
[149] | 266 | if (this->first_->object_ == object) |
---|
[132] | 267 | { |
---|
[149] | 268 | ObjectListElement* temp = this->first_->next_; |
---|
| 269 | delete this->first_; |
---|
| 270 | this->first_ = temp; |
---|
[132] | 271 | |
---|
[149] | 272 | return; |
---|
[132] | 273 | } |
---|
| 274 | |
---|
[149] | 275 | ObjectListElement* temp = this->first_; |
---|
| 276 | while (temp->next_) |
---|
[132] | 277 | { |
---|
[149] | 278 | if (temp->next_->object_ == object) |
---|
| 279 | { |
---|
| 280 | ObjectListElement* temp2 = temp->next_->next_; |
---|
| 281 | delete temp->next_; |
---|
| 282 | temp->next_ = temp2; |
---|
[132] | 283 | |
---|
[149] | 284 | return; |
---|
[132] | 285 | } |
---|
| 286 | |
---|
[149] | 287 | temp = temp->next_; |
---|
[132] | 288 | } |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | |
---|
[149] | 292 | // ############################### |
---|
| 293 | // ### ObjectListElement ### |
---|
| 294 | // ############################### |
---|
[162] | 295 | ObjectListElement::ObjectListElement(OrxonoxClass* object) |
---|
[132] | 296 | { |
---|
[149] | 297 | this->object_ = object; |
---|
| 298 | this->next_ = NULL; |
---|
[132] | 299 | } |
---|
[162] | 300 | |
---|
[172] | 301 | ObjectListElement::~ObjectListElement() |
---|
| 302 | { |
---|
| 303 | } |
---|
[162] | 304 | |
---|
[172] | 305 | |
---|
[162] | 306 | // ############################### |
---|
| 307 | // ### ClassHierarchy ### |
---|
| 308 | // ############################### |
---|
| 309 | ClassHierarchy* ClassHierarchy::pointer_ = NULL; |
---|
| 310 | |
---|
| 311 | ClassHierarchy* ClassHierarchy::getSingleton() |
---|
| 312 | { |
---|
| 313 | if (!pointer_) |
---|
| 314 | pointer_ = new ClassHierarchy(); |
---|
| 315 | |
---|
| 316 | return pointer_; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | ClassHierarchy::ClassHierarchy() |
---|
| 320 | { |
---|
[172] | 321 | this->hierarchyCreatingCounter_ = 0; |
---|
[162] | 322 | } |
---|
[172] | 323 | |
---|
| 324 | ClassHierarchy::~ClassHierarchy() |
---|
| 325 | { |
---|
| 326 | this->pointer_ = NULL; |
---|
| 327 | } |
---|
[149] | 328 | } |
---|