[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 | { |
---|
[162] | 33 | std::cout << "*** Initialize " << this->name_ << "-Singleton.\n"; |
---|
[149] | 34 | if (parents) |
---|
| 35 | { |
---|
| 36 | this->bCreatedOneObject_ = true; |
---|
| 37 | |
---|
| 38 | IdentifierListElement* temp1; |
---|
| 39 | IdentifierListElement* temp2; |
---|
| 40 | IdentifierListElement* temp3; |
---|
| 41 | |
---|
| 42 | temp1 = parents->first_; |
---|
| 43 | while (temp1) |
---|
| 44 | { |
---|
| 45 | temp2 = temp1->identifier_->directParents_->first_; |
---|
| 46 | while (temp2) |
---|
| 47 | { |
---|
| 48 | temp3 = parents->first_; |
---|
| 49 | while(temp3) |
---|
| 50 | { |
---|
| 51 | if (temp3->identifier_ == temp2->identifier_) |
---|
| 52 | temp3->bDirect_ = false; |
---|
| 53 | |
---|
| 54 | temp3 = temp3->next_; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | temp2 = temp2->next_; |
---|
| 58 | } |
---|
| 59 | temp1 = temp1->next_; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | temp1 = parents->first_; |
---|
| 63 | while (temp1) |
---|
| 64 | { |
---|
| 65 | if (temp1->bDirect_) |
---|
| 66 | { |
---|
| 67 | this->directParents_->add(temp1->identifier_); |
---|
[150] | 68 | temp1->identifier_->directChildren_->add(this); |
---|
[149] | 69 | } |
---|
| 70 | |
---|
| 71 | this->allParents_->add(temp1->identifier_); |
---|
[150] | 72 | temp1->identifier_->allChildren_->add(this); |
---|
[149] | 73 | |
---|
| 74 | temp1 = temp1->next_; |
---|
| 75 | } |
---|
| 76 | } |
---|
[132] | 77 | } |
---|
| 78 | |
---|
[162] | 79 | void Identifier::addObject(OrxonoxClass* object) |
---|
[132] | 80 | { |
---|
[162] | 81 | std::cout << "*** Added " << this->name_ << " to list.\n"; |
---|
[149] | 82 | this->objects_->add(object); |
---|
[132] | 83 | } |
---|
| 84 | |
---|
[162] | 85 | void Identifier::removeObject(OrxonoxClass* object) |
---|
[132] | 86 | { |
---|
[162] | 87 | std::cout << "*** Removed " << this->name_ << " from list.\n"; |
---|
[149] | 88 | this->objects_->remove(object); |
---|
[132] | 89 | } |
---|
| 90 | |
---|
[149] | 91 | bool Identifier::isA(Identifier* identifier) |
---|
[132] | 92 | { |
---|
[150] | 93 | return (identifier == this || this->allParents_->isInList(identifier)); |
---|
[132] | 94 | } |
---|
| 95 | |
---|
[149] | 96 | bool Identifier::isDirectA(Identifier* identifier) |
---|
[132] | 97 | { |
---|
[150] | 98 | return (identifier == this); |
---|
[132] | 99 | } |
---|
| 100 | |
---|
[149] | 101 | bool Identifier::isChildOf(Identifier* identifier) |
---|
[132] | 102 | { |
---|
[149] | 103 | return this->allParents_->isInList(identifier); |
---|
[132] | 104 | } |
---|
| 105 | |
---|
[149] | 106 | bool Identifier::isDirectChildOf(Identifier* identifier) |
---|
[132] | 107 | { |
---|
[149] | 108 | return this->directParents_->isInList(identifier); |
---|
[132] | 109 | } |
---|
| 110 | |
---|
[149] | 111 | bool Identifier::isParentOf(Identifier* identifier) |
---|
[132] | 112 | { |
---|
[149] | 113 | return this->allChildren_->isInList(identifier); |
---|
[132] | 114 | } |
---|
| 115 | |
---|
[149] | 116 | bool Identifier::isDirectParentOf(Identifier* identifier) |
---|
[132] | 117 | { |
---|
[149] | 118 | return this->directChildren_->isInList(identifier); |
---|
[132] | 119 | } |
---|
| 120 | |
---|
[149] | 121 | |
---|
| 122 | // ############################### |
---|
| 123 | // ### IdentifierList ### |
---|
| 124 | // ############################### |
---|
| 125 | IdentifierList::IdentifierList() |
---|
[132] | 126 | { |
---|
[149] | 127 | this->first_ = NULL; |
---|
[132] | 128 | } |
---|
| 129 | |
---|
[149] | 130 | IdentifierList::~IdentifierList() |
---|
[132] | 131 | { |
---|
[149] | 132 | IdentifierListElement* temp; |
---|
| 133 | while (this->first_) |
---|
[132] | 134 | { |
---|
[149] | 135 | temp = this->first_->next_; |
---|
| 136 | delete this->first_; |
---|
| 137 | this->first_ = temp; |
---|
[132] | 138 | } |
---|
[149] | 139 | } |
---|
[132] | 140 | |
---|
[149] | 141 | void IdentifierList::add(Identifier* identifier) |
---|
| 142 | { |
---|
| 143 | IdentifierListElement* temp = this->first_; |
---|
| 144 | this->first_ = new IdentifierListElement(identifier); |
---|
| 145 | this->first_->next_ = temp; |
---|
[132] | 146 | } |
---|
| 147 | |
---|
[149] | 148 | void IdentifierList::remove(Identifier* identifier) |
---|
[132] | 149 | { |
---|
[149] | 150 | if (!identifier) |
---|
[132] | 151 | return; |
---|
| 152 | |
---|
[149] | 153 | if (this->first_->identifier_ == identifier) |
---|
[132] | 154 | { |
---|
[149] | 155 | IdentifierListElement* temp = this->first_->next_; |
---|
| 156 | delete this->first_; |
---|
| 157 | this->first_ = temp; |
---|
[132] | 158 | |
---|
| 159 | return; |
---|
| 160 | } |
---|
| 161 | |
---|
[149] | 162 | IdentifierListElement* temp = this->first_; |
---|
| 163 | while (temp->next_) |
---|
[132] | 164 | { |
---|
[149] | 165 | if (temp->next_->identifier_ == identifier) |
---|
[132] | 166 | { |
---|
[149] | 167 | IdentifierListElement* temp2 = temp->next_->next_; |
---|
| 168 | delete temp->next_; |
---|
| 169 | temp->next_ = temp2; |
---|
[132] | 170 | |
---|
| 171 | return; |
---|
| 172 | } |
---|
| 173 | |
---|
[149] | 174 | temp = temp->next_; |
---|
[132] | 175 | } |
---|
| 176 | } |
---|
| 177 | |
---|
[149] | 178 | bool IdentifierList::isInList(Identifier* identifier) |
---|
| 179 | { |
---|
| 180 | IdentifierListElement* temp = this->first_; |
---|
| 181 | while (temp) |
---|
| 182 | { |
---|
| 183 | if (temp->identifier_ == identifier) |
---|
| 184 | return true; |
---|
[132] | 185 | |
---|
[149] | 186 | temp = temp->next_; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | return false; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | // ############################### |
---|
| 194 | // ### IdentifierListElement ### |
---|
| 195 | // ############################### |
---|
| 196 | IdentifierListElement::IdentifierListElement(Identifier* identifier) |
---|
[132] | 197 | { |
---|
[149] | 198 | this->identifier_ = identifier; |
---|
| 199 | this->next_ = NULL; |
---|
| 200 | this->bDirect_ = true; |
---|
[132] | 201 | } |
---|
| 202 | |
---|
[149] | 203 | |
---|
| 204 | // ############################### |
---|
| 205 | // ### ObjectList ### |
---|
| 206 | // ############################### |
---|
| 207 | ObjectList::ObjectList() |
---|
[132] | 208 | { |
---|
[149] | 209 | this->first_ = NULL; |
---|
[132] | 210 | } |
---|
| 211 | |
---|
[149] | 212 | ObjectList::~ObjectList() |
---|
[132] | 213 | { |
---|
[149] | 214 | ObjectListElement* temp; |
---|
| 215 | while (this->first_) |
---|
[132] | 216 | { |
---|
[149] | 217 | temp = this->first_->next_; |
---|
| 218 | delete this->first_; |
---|
| 219 | this->first_ = temp; |
---|
[132] | 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
[162] | 223 | void ObjectList::add(OrxonoxClass* object) |
---|
[132] | 224 | { |
---|
[149] | 225 | ObjectListElement* temp = this->first_; |
---|
| 226 | this->first_ = new ObjectListElement(object); |
---|
| 227 | this->first_->next_ = temp; |
---|
[132] | 228 | } |
---|
| 229 | |
---|
[162] | 230 | void ObjectList::remove(OrxonoxClass* object) |
---|
[132] | 231 | { |
---|
[149] | 232 | if (!object) |
---|
| 233 | return; |
---|
[132] | 234 | |
---|
[149] | 235 | if (this->first_->object_ == object) |
---|
[132] | 236 | { |
---|
[149] | 237 | ObjectListElement* temp = this->first_->next_; |
---|
| 238 | delete this->first_; |
---|
| 239 | this->first_ = temp; |
---|
[132] | 240 | |
---|
[149] | 241 | return; |
---|
[132] | 242 | } |
---|
| 243 | |
---|
[149] | 244 | ObjectListElement* temp = this->first_; |
---|
| 245 | while (temp->next_) |
---|
[132] | 246 | { |
---|
[149] | 247 | if (temp->next_->object_ == object) |
---|
| 248 | { |
---|
| 249 | ObjectListElement* temp2 = temp->next_->next_; |
---|
| 250 | delete temp->next_; |
---|
| 251 | temp->next_ = temp2; |
---|
[132] | 252 | |
---|
[149] | 253 | return; |
---|
[132] | 254 | } |
---|
| 255 | |
---|
[149] | 256 | temp = temp->next_; |
---|
[132] | 257 | } |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | |
---|
[149] | 261 | // ############################### |
---|
| 262 | // ### ObjectListElement ### |
---|
| 263 | // ############################### |
---|
[162] | 264 | ObjectListElement::ObjectListElement(OrxonoxClass* object) |
---|
[132] | 265 | { |
---|
[149] | 266 | this->object_ = object; |
---|
| 267 | this->next_ = NULL; |
---|
[132] | 268 | } |
---|
[162] | 269 | |
---|
| 270 | |
---|
| 271 | // ############################### |
---|
| 272 | // ### ClassHierarchy ### |
---|
| 273 | // ############################### |
---|
| 274 | ClassHierarchy* ClassHierarchy::pointer_ = NULL; |
---|
| 275 | |
---|
| 276 | ClassHierarchy* ClassHierarchy::getSingleton() |
---|
| 277 | { |
---|
| 278 | if (!pointer_) |
---|
| 279 | pointer_ = new ClassHierarchy(); |
---|
| 280 | |
---|
| 281 | return pointer_; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | ClassHierarchy::ClassHierarchy() |
---|
| 285 | { |
---|
| 286 | this->bCreatingHierarchy_ = false; |
---|
| 287 | } |
---|
[149] | 288 | } |
---|