Changeset 803
- Timestamp:
- Feb 12, 2008, 1:30:43 AM (17 years ago)
- Location:
- code/branches/core/src/orxonox/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core/src/orxonox/core/ClassTreeMask.cc
r802 r803 80 80 { 81 81 return this->subclass_; 82 } 83 84 85 // ############################### 86 // ### ClassTreeMaskIterator ### 87 // ############################### 88 ClassTreeMaskIterator::ClassTreeMaskIterator(ClassTreeMaskNode* node) 89 { 90 std::list<ClassTreeMaskNode*> templist; 91 std::list<ClassTreeMaskNode*>::iterator tempiterator = templist.insert(templist.end(), node); 92 this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>(tempiterator, templist.end())); 93 } 94 95 ClassTreeMaskIterator::~ClassTreeMaskIterator() 96 { 97 } 98 99 ClassTreeMaskIterator& ClassTreeMaskIterator::operator++() 100 { 101 if ((*this->nodes_.top().first)->subnodes_.begin() != (*this->nodes_.top().first)->subnodes_.end()) 102 this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>((*this->nodes_.top().first)->subnodes_.begin(), (*this->nodes_.top().first)->subnodes_.end())); 103 else 104 { 105 do 106 { 107 ++this->nodes_.top().first; 108 if (this->nodes_.top().first == this->nodes_.top().second) 109 { 110 this->nodes_.pop(); 111 continue; 112 } 113 114 break; 115 } while (!this->nodes_.empty()); 116 } 117 118 return *this; 119 } 120 121 ClassTreeMaskNode* ClassTreeMaskIterator::operator*() const 122 { 123 return (*this->nodes_.top().first); 124 } 125 126 ClassTreeMaskNode* ClassTreeMaskIterator::operator->() const 127 { 128 return (*this->nodes_.top().first); 129 } 130 131 ClassTreeMaskIterator::operator bool() 132 { 133 return (!this->nodes_.empty()); 134 } 135 136 bool ClassTreeMaskIterator::operator==(ClassTreeMaskNode* compare) 137 { 138 if (!this->nodes_.empty()) 139 return ((*this->nodes_.top().first) == compare); 140 else 141 return (compare == 0); 142 } 143 144 bool ClassTreeMaskIterator::operator!=(ClassTreeMaskNode* compare) 145 { 146 if (!this->nodes_.empty()) 147 return ((*this->nodes_.top().first) != compare); 148 else 149 return (compare != 0); 82 150 } 83 151 … … 162 230 } 163 231 164 bool ClassTreeMask::isIncluded(const Identifier* subclass) 232 bool ClassTreeMask::isIncluded(const Identifier* subclass) const 165 233 { 166 234 return this->isIncluded(this->root_, subclass); 167 235 } 168 236 169 bool ClassTreeMask::isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) 237 bool ClassTreeMask::isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const 170 238 { 171 239 // Check if the searched subclass is of the same type as the class in the current node or a derivative … … 191 259 } 192 260 193 bool ClassTreeMask::isExcluded(const Identifier* subclass) 261 bool ClassTreeMask::isExcluded(const Identifier* subclass) const 194 262 { 195 263 return (!this->isIncluded(subclass)); 196 264 } 265 266 void ClassTreeMask::clean() 267 { 268 this->clean(this->root_); 269 } 270 271 void ClassTreeMask::clean(ClassTreeMaskNode* node) 272 { 273 for (std::list<ClassTreeMaskNode*>::iterator it = node->subnodes_.begin(); it != node->subnodes_.end(); ) 274 { 275 if ((*it)->isIncluded() == node->isIncluded()) 276 { 277 node->subnodes_.insert(node->subnodes_.end(), (*it)->subnodes_.begin(), (*it)->subnodes_.end()); 278 (*it)->subnodes_.clear(); 279 node->subnodes_.erase(it++); 280 } 281 else 282 { 283 ++it; 284 } 285 } 286 } 287 288 ClassTreeMask ClassTreeMask::operator+(const ClassTreeMask& other) const 289 { 290 ClassTreeMask newmask; 291 for (ClassTreeMaskIterator it = this->root_; it; ++it) 292 { 293 const Identifier* subclass = it->getClass(); 294 newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass)); 295 } 296 for (ClassTreeMaskIterator it = other.root_; it; ++it) 297 { 298 const Identifier* subclass = it->getClass(); 299 newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass)); 300 } 301 newmask.clean(); 302 303 return newmask; 304 } 305 306 ClassTreeMask ClassTreeMask::operator*(const ClassTreeMask& other) const 307 { 308 ClassTreeMask newmask; 309 for (ClassTreeMaskIterator it = this->root_; it; ++it) 310 { 311 const Identifier* subclass = it->getClass(); 312 newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass)); 313 } 314 for (ClassTreeMaskIterator it = other.root_; it; ++it) 315 { 316 const Identifier* subclass = it->getClass(); 317 newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass)); 318 } 319 newmask.clean(); 320 321 return newmask; 322 } 323 324 ClassTreeMask ClassTreeMask::operator!() const 325 { 326 ClassTreeMask newmask; 327 for (ClassTreeMaskIterator it = this->root_; it; ++it) 328 { 329 const Identifier* subclass = it->getClass(); 330 newmask.add(subclass, !this->isIncluded(subclass)); 331 } 332 333 return newmask; 334 } 335 336 ClassTreeMask ClassTreeMask::operator-(const ClassTreeMask& other) const 337 { 338 return ((*this) * (!other)); 339 } 340 341 ClassTreeMask ClassTreeMask::operator&(const ClassTreeMask& other) const 342 { 343 return ((*this) * other); 344 } 345 346 ClassTreeMask ClassTreeMask::operator|(const ClassTreeMask& other) const 347 { 348 return ((*this) + other); 349 } 350 351 ClassTreeMask ClassTreeMask::operator^(const ClassTreeMask& other) const 352 { 353 ClassTreeMask newmask; 354 for (ClassTreeMaskIterator it = this->root_; it; ++it) 355 { 356 const Identifier* subclass = it->getClass(); 357 newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass)); 358 } 359 for (ClassTreeMaskIterator it = other.root_; it; ++it) 360 { 361 const Identifier* subclass = it->getClass(); 362 newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass)); 363 } 364 newmask.clean(); 365 366 return newmask; 367 } 368 369 ClassTreeMask ClassTreeMask::operator~() const 370 { 371 return (!(*this)); 372 } 197 373 } -
code/branches/core/src/orxonox/core/ClassTreeMask.h
r802 r803 30 30 31 31 #include <list> 32 #include <stack> 32 33 33 34 #include "CorePrereqs.h" … … 38 39 { 39 40 friend class ClassTreeMask; 41 friend class ClassTreeMaskIterator; 40 42 41 43 public: … … 60 62 }; 61 63 64 class ClassTreeMaskIterator 65 { 66 public: 67 ClassTreeMaskIterator(ClassTreeMaskNode* node); 68 ~ClassTreeMaskIterator(); 69 70 ClassTreeMaskIterator& operator++(); 71 ClassTreeMaskNode* operator*() const; 72 ClassTreeMaskNode* operator->() const; 73 operator bool(); 74 bool operator==(ClassTreeMaskNode* compare); 75 bool operator!=(ClassTreeMaskNode* compare); 76 77 private: 78 std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_; 79 }; 80 62 81 class ClassTreeMask 63 82 { … … 70 89 void add(const Identifier* subclass, bool bInclude); 71 90 void reset(); 91 void clean(); 72 92 73 bool isIncluded(const Identifier* subclass); 74 bool isExcluded(const Identifier* subclass); 93 bool isIncluded(const Identifier* subclass) const; 94 bool isExcluded(const Identifier* subclass) const; 95 96 ClassTreeMask operator+(const ClassTreeMask& other) const; 97 ClassTreeMask operator*(const ClassTreeMask& other) const; 98 ClassTreeMask operator!() const; 99 ClassTreeMask operator-(const ClassTreeMask& other) const; 100 101 ClassTreeMask operator&(const ClassTreeMask& other) const; 102 ClassTreeMask operator|(const ClassTreeMask& other) const; 103 ClassTreeMask operator^(const ClassTreeMask& other) const; 104 ClassTreeMask operator~() const; 75 105 76 106 private: 77 107 void add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude); 78 bool isIncluded(ClassTreeMaskNode* node, const Identifier* subclass); 108 bool isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const; 109 void clean(ClassTreeMaskNode* node); 79 110 80 111 ClassTreeMaskNode* root_;
Note: See TracChangeset
for help on using the changeset viewer.