Changeset 809
- Timestamp:
- Feb 13, 2008, 2:47:10 AM (17 years ago)
- Location:
- code/branches/core/src/orxonox/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core/src/orxonox/core/ClassManager.h
r806 r809 26 26 */ 27 27 28 /*! 29 @file ClassManager.h 30 @brief Definition and Implementation of the ClassManager template. 31 32 The ClassManager is a helper-class for ClassIdentifier. Because ClassIdentifiers must 33 be unique, they are created through the IdentifierDistributor-class to assure the 34 uniqueness of the ClassIdentifier. But accessing Identifiers through IdentifierDistributor 35 is slow, because it uses strings and a map. Thats why we use the ClassManager-template: It's 36 a singleton like ClassIdentifier, but it doesn't hurt if there are multiple instances in 37 different libraries, because they all store the same pointer to the unique ClassIdentifier 38 which they've retrieved through IdentifierDistributor. 39 */ 40 28 41 #ifndef _ClassManager_H__ 29 42 #define _ClassManager_H__ … … 38 51 namespace orxonox 39 52 { 53 //! ClassManager is a helper class to allow faster access on the ClassIdentifiers. 54 /** 55 Because accessing the IdentifierDistributor is slow, the ClassManager accesses it once 56 and stores the result in a member-variable. IdentifierDistributor assures the uniqueness 57 of the ClassIdentifier, even if there are multiple instances of the ClassManager-template 58 in different libraries. 59 */ 40 60 template <class T> 41 61 class ClassManager … … 51 71 ~ClassManager() {} // don't delete 52 72 53 bool bInitialized_; 54 ClassIdentifier<T>* identifier_; 73 bool bInitialized_; //!< This is false until the ClassIdentifier gets assigned 74 ClassIdentifier<T>* identifier_; //!< The unique ClassIdentifier for the class T 55 75 }; 56 76 … … 82 102 ClassIdentifier<T>* ClassManager<T>::getIdentifier(const std::string& name) 83 103 { 104 // Check if the ClassManager is already initialized 84 105 if (!ClassManager<T>::getSingleton()->bInitialized_) 85 106 { 107 // It's not -> retrieve the ClassIdentifier through IdentifierDistributor 108 COUT(4) << "*** Create Identifier Singleton." << std::endl; 86 109 87 COUT(4) << "*** Create Identifier Singleton." << std::endl;110 // First create a ClassIdentifier in case there's no instance existing yet 88 111 ClassIdentifier<T>* temp = new ClassIdentifier<T>(); 112 113 // Ask the IdentifierDistributor for the unique ClassIdentifier 89 114 ClassManager<T>::getSingleton()->identifier_ = (ClassIdentifier<T>*)IdentifierDistributor::getIdentifier(name, temp); 115 116 // If the retrieved Identifier differs from our proposal, we don't need the proposal any more 90 117 if (temp != ClassManager<T>::getSingleton()->identifier_) 91 118 delete temp; 119 92 120 ClassManager<T>::getSingleton()->bInitialized_ = true; 93 121 } 94 122 123 // Finally return the unique ClassIdentifier 95 124 return ClassManager<T>::getSingleton()->identifier_; 96 125 } -
code/branches/core/src/orxonox/core/ClassTreeMask.cc
r808 r809 26 26 */ 27 27 28 /*! 29 @file ClassTreeMask.cc 30 @brief Implementation of the ClassTreeMask, ClassTreeMaskNode and ClassTreeMaskIterator classes. 31 */ 32 28 33 #include "ClassTreeMask.h" 29 34 #include "Identifier.h" … … 35 40 // ### ClassTreeMaskNode ### 36 41 // ############################### 42 /** 43 @brief Constructor: Creates the node, sets the subclass and the rule. 44 @param subclass The subclass the rule refers to 45 @param bIncluded The rule: included (true) or excluded (false) 46 */ 37 47 ClassTreeMaskNode::ClassTreeMaskNode(const Identifier* subclass, bool bIncluded) 38 48 { … … 41 51 } 42 52 53 /** 54 @brief Destructor: Deletes all subnodes. 55 */ 43 56 ClassTreeMaskNode::~ClassTreeMaskNode() 44 57 { 58 // Go through the list of all subnodes and delete them 45 59 for (std::list<ClassTreeMaskNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ) 46 60 delete (*(it++)); 47 61 } 48 62 63 /** 64 @brief Sets the rule for the node to "included". 65 */ 49 66 void ClassTreeMaskNode::include() 50 67 { … … 52 69 } 53 70 71 /** 72 @brief Sets the rule for the node to "excluded". 73 */ 54 74 void ClassTreeMaskNode::exclude() 55 75 { … … 57 77 } 58 78 79 /** 80 @brief Sets the rule for the node to a given value. 81 @param bIncluded The rule: included (true) or excluded (false) 82 */ 59 83 void ClassTreeMaskNode::setIncluded(bool bIncluded) 60 84 { … … 62 86 } 63 87 88 /** 89 @brief Adds a new subnode to the list of subnodes. 90 @param subnode The new subnode 91 */ 64 92 void ClassTreeMaskNode::addSubnode(ClassTreeMaskNode* subnode) 65 93 { … … 67 95 } 68 96 97 /** 98 @brief Tells if the rule is "included" or not. 99 @return The rule: true = included, false = excluded 100 */ 69 101 bool ClassTreeMaskNode::isIncluded() const 70 102 { … … 72 104 } 73 105 106 /** 107 @brief Tells if the rule is "excluded" or not. 108 @return The inverted rule: true = excluded, false = included 109 */ 74 110 bool ClassTreeMaskNode::isExcluded() const 75 111 { … … 77 113 } 78 114 115 /** 116 @brief Returns the Identifier of the class the rule refers to. 117 @return The Identifier representing the class 118 */ 79 119 const Identifier* ClassTreeMaskNode::getClass() const 80 120 { … … 86 126 // ### ClassTreeMaskIterator ### 87 127 // ############################### 128 /** 129 @brief Constructor: Initializes the iterator by creating a helper-list with the root-node and putting it to the stack. 130 @param node The root-node 131 */ 88 132 ClassTreeMaskIterator::ClassTreeMaskIterator(ClassTreeMaskNode* node) 89 133 { 134 // Create a list and put the root-note into it 90 135 std::list<ClassTreeMaskNode*>::iterator it = this->rootlist_.insert(this->rootlist_.end(), node); 136 137 // Put the iterator to the only element of the list and the corresponding end()-iterator on the stack 91 138 this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>(it, this->rootlist_.end())); 92 139 } 93 140 141 /** 142 @brief Destructor: Does nothing. 143 */ 94 144 ClassTreeMaskIterator::~ClassTreeMaskIterator() 95 145 { 96 146 } 97 147 148 /** 149 @brief Iterates through the rule-tree. 150 @return A reference to the iterator itself 151 */ 98 152 ClassTreeMaskIterator& ClassTreeMaskIterator::operator++() 99 153 { 154 // Check if the actual node has subnodes 100 155 if ((*this->nodes_.top().first)->subnodes_.begin() != (*this->nodes_.top().first)->subnodes_.end()) 156 { 157 // Yes it has: Push an iterator, pointing at the first subnode, on the stack 101 158 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())); 159 } 102 160 else 103 161 { 162 // No subnodes, meaning we reached a leaf: Go to the next node 104 163 do 105 164 { 165 // Iterate one step in the current list 106 166 ++this->nodes_.top().first; 167 168 // Check if we reached the end of the list (the second item in the stored pair always represents the end) 107 169 if (this->nodes_.top().first == this->nodes_.top().second) 108 170 { 171 // Yes we've reached the end: Pop the list-iterator from the stack 109 172 this->nodes_.pop(); 173 174 // Continue with the loop, meaning: Try to iterate through the previous list 110 175 continue; 111 176 } 112 177 178 // If we reached this point, we aren't yet at the end of the list: Leave the loop 113 179 break; 114 } while (!this->nodes_.empty()); 115 } 116 180 } while (!this->nodes_.empty()); // Stop looping if the stack is empty, meaning: We've iterated to the end 181 } 182 183 // Finally return a reference to the iterator itself 117 184 return *this; 118 185 } 119 186 187 /** 188 @brief Returns a pointer to the ClassTreeMaskNode whereon the iterator points. 189 @return The pointer to the node 190 */ 120 191 ClassTreeMaskNode* ClassTreeMaskIterator::operator*() const 121 192 { … … 123 194 } 124 195 196 /** 197 @brief Returns a pointer to the ClassTreeMaskNode whereon the iterator points. 198 @return The pointer to the node 199 */ 125 200 ClassTreeMaskNode* ClassTreeMaskIterator::operator->() const 126 201 { … … 128 203 } 129 204 205 /** 206 @brief Returns true if the stack is empty, meaning we've reached the end of the tree. 207 @return True if we've reached the end of the tree 208 */ 130 209 ClassTreeMaskIterator::operator bool() 131 210 { … … 133 212 } 134 213 214 /** 215 @brief Compares the current node with the given one and returns true if they match. 216 @param compare The node to compare with 217 @return The result of the comparison (true if they match) 218 */ 135 219 bool ClassTreeMaskIterator::operator==(ClassTreeMaskNode* compare) 136 220 { … … 141 225 } 142 226 227 /** 228 @brief Compares the current node with the given one and returns true if they don't match. 229 @param compare The node to compare with 230 @return The result of the comparison (true if they don't match) 231 */ 143 232 bool ClassTreeMaskIterator::operator!=(ClassTreeMaskNode* compare) 144 233 { … … 153 242 // ### ClassTreeMask ### 154 243 // ############################### 244 /** 245 @brief Constructor: Adds the root-node of the tree with the first rule ("include everything"). 246 */ 155 247 ClassTreeMask::ClassTreeMask() 156 248 { … … 158 250 } 159 251 252 /** 253 @brief Copyconstructor: Adds the root-node of the tree with the first rule ("include everything") and adds all rules from the other mask. 254 @param other The other mask 255 */ 160 256 ClassTreeMask::ClassTreeMask(const ClassTreeMask& other) 161 257 { … … 165 261 } 166 262 263 /** 264 @brief Destructor: Deletes the root node (which will delete all subnodes too). 265 */ 167 266 ClassTreeMask::~ClassTreeMask() 168 267 { … … 170 269 } 171 270 271 /** 272 @brief Adds a new "include" rule for a given subclass to the mask. 273 @param subclass The subclass 274 */ 172 275 void ClassTreeMask::include(const Identifier* subclass) 173 276 { … … 175 278 } 176 279 280 /** 281 @brief Adds a new "exclude" rule for a given subclass to the mask. 282 @param subclass The subclass 283 */ 177 284 void ClassTreeMask::exclude(const Identifier* subclass) 178 285 { … … 180 287 } 181 288 289 /** 290 @brief Adds a new rule for a given subclass to the mask. 291 @param subclass The subclass 292 @param bInclude The rule: include (true) or exclude (false) 293 */ 182 294 void ClassTreeMask::add(const Identifier* subclass, bool bInclude) 183 295 { … … 185 297 } 186 298 299 /** 300 @brief Adds a new rule for a given subclass to a node of the internal rule-tree (recursive function). 301 @param node The node 302 @param subclass The subclass 303 @param bInclude The rule: include (true) or exclude (false) 304 */ 187 305 void ClassTreeMask::add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude) 188 306 { … … 201 319 if (subclass->isA((*it)->getClass())) 202 320 { 203 // We've found an existing node -> delegate the work and return321 // We've found an existing node -> delegate the work with a recursive function-call and return 204 322 this->add(*it, subclass, bInclude); 205 323 return; … … 230 348 } 231 349 350 /** 351 @brief Resets the mask to "include everything". 352 */ 232 353 void ClassTreeMask::reset() 233 354 { … … 236 357 } 237 358 359 /** 360 @brief Tells if a given subclass is included or not. 361 @param subclass The subclass 362 @return Included (true) or excluded (false) 363 */ 238 364 bool ClassTreeMask::isIncluded(const Identifier* subclass) const 239 365 { … … 241 367 } 242 368 369 /** 370 @brief Tells if a given subclass of a node in the rule-tree is included or not (recursive function). 371 @param node The node 372 @param subclass The subclass 373 @return Included (true) or excluded (false) 374 */ 243 375 bool ClassTreeMask::isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const 244 376 { 245 //std::cout << "1_1: " << subclass->getName() << " (" << subclass << ") / " << node->getClass()->getName() << " (" << node->getClass() << ")" << std::endl;246 377 // Check if the searched subclass is of the same type as the class in the current node or a derivative 247 378 if (subclass->isA(node->getClass())) … … 251 382 return node->isIncluded(); 252 383 253 // Go through the list of subnodes and look for a node containing the searched subclass 384 // Go through the list of subnodes and look for a node containing the searched subclass and delegate the request by a recursive function-call. 254 385 for (std::list<ClassTreeMaskNode*>::iterator it = node->subnodes_.begin(); it != node->subnodes_.end(); ++it) 255 386 if (subclass->isA((*it)->getClass())) … … 266 397 } 267 398 399 /** 400 @brief Tells if a given subclass is excluded or not. 401 @param subclass The subclass 402 @return The inverted rule: Excluded (true) or included (false) 403 */ 268 404 bool ClassTreeMask::isExcluded(const Identifier* subclass) const 269 405 { … … 271 407 } 272 408 409 /** 410 @brief Removes all unneeded rules that don't change the information of the mask. 411 */ 273 412 void ClassTreeMask::clean() 274 413 { … … 276 415 } 277 416 417 /** 418 @brief Removes all unneded rules that don't change the information of a node of a mask (recursive function). 419 @param node The node 420 */ 278 421 void ClassTreeMask::clean(ClassTreeMaskNode* node) 279 422 { 280 //std::cout << "4_1: " << node->getClass()->getName() << ": " << node->isIncluded() << "\n"; 423 // Iterate through all subnodes of the given node 281 424 for (std::list<ClassTreeMaskNode*>::iterator it = node->subnodes_.begin(); it != node->subnodes_.end(); ) 282 425 { 283 //std::cout << "4_2: " << (*it)->getClass()->getName() << ": " << (*it)->isIncluded() << "\n"; 426 // Recursive function-call: Clean the subnode 284 427 this->clean(*it); 285 //std::cout << "4_3\n"; 428 429 // Now check if the subnode contains the same rule as the current node 286 430 if ((*it)->isIncluded() == node->isIncluded()) 287 431 { 288 //std::cout << "4_4\n"; 432 // It does: Move all subnodes of the redundant subnode to the current node 289 433 node->subnodes_.insert(node->subnodes_.end(), (*it)->subnodes_.begin(), (*it)->subnodes_.end()); 290 434 (*it)->subnodes_.clear(); 291 node->subnodes_.erase(it); 292 it = node->subnodes_.begin();293 //std::cout << "4_5\n";435 436 // Remove the redundant subnode from the current node 437 node->subnodes_.erase(it++); 294 438 } 295 439 else 296 440 { 297 //std::cout << "4_6\n"; 441 // The subnode is necessary: Move on to the next subnode 298 442 ++it; 299 443 } 300 444 } 301 //std::cout << "4_7\n"; 302 } 303 445 } 446 447 /** 448 @brief Assignment operator: Adds all rules of the other mask. 449 @param other The other mask 450 @return A reference to the mask itself 451 */ 304 452 ClassTreeMask& ClassTreeMask::operator=(const ClassTreeMask& other) 305 453 { 454 // Make a copy to avoid troubles with self-assignments (like A = A). 306 455 ClassTreeMask temp(other); 307 456 457 // Removes all current rules 308 458 this->reset(); 309 459 460 // Copy all rules from the other mask 310 461 for (ClassTreeMaskIterator it = temp.root_; it; ++it) 311 462 this->add(it->getClass(), it->isIncluded()); 312 463 464 // Return a reference to the mask itself 313 465 return (*this); 314 466 } 315 467 468 /** 469 @brief Prefix operator + does nothing. 470 @return A reference to the mask itself 471 */ 316 472 ClassTreeMask& ClassTreeMask::operator+() 317 473 { … … 319 475 } 320 476 477 /** 478 @brief Prefix operator - inverts the mask. 479 @return The inverted mask 480 */ 321 481 ClassTreeMask ClassTreeMask::operator-() const 322 482 { … … 324 484 } 325 485 486 /** 487 @brief Adds two masks in the sense of a union (all classes that are included in at least one of the masks will be included in the resulting mask too). 488 @param other The mask to unite with 489 @return The union 490 */ 326 491 ClassTreeMask ClassTreeMask::operator+(const ClassTreeMask& other) const 327 492 { 493 // Create a new mask 328 494 ClassTreeMask newmask; 495 496 // Add all nodes from the first mask, calculate the rule with the or-operation 329 497 for (ClassTreeMaskIterator it = this->root_; it; ++it) 330 498 { … … 332 500 newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass)); 333 501 } 502 503 // Add all nodes from the second mask, calculate the rule with the or-operation 334 504 for (ClassTreeMaskIterator it = other.root_; it; ++it) 335 505 { … … 337 507 newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass)); 338 508 } 509 510 // Drop all redundant rules 339 511 newmask.clean(); 340 512 513 // Return the new mask 341 514 return newmask; 342 515 } 343 516 517 /** 518 @brief Intersects two masks (only classes that are included in both masks will be included in the resulting mask too). 519 @param other The mask to intersect with 520 @return The intersection 521 */ 344 522 ClassTreeMask ClassTreeMask::operator*(const ClassTreeMask& other) const 345 523 { 524 // Create a new mask 346 525 ClassTreeMask newmask; 526 527 // Add all nodes from the first mask, calculate the rule with the and-operation 347 528 for (ClassTreeMaskIterator it = this->root_; it; ++it) 348 529 { … … 350 531 newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass)); 351 532 } 533 534 // Add all nodes from the second mask, calculate the rule with the and-operation 352 535 for (ClassTreeMaskIterator it = other.root_; it; ++it) 353 536 { … … 355 538 newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass)); 356 539 } 540 541 // Drop all redundant rules 357 542 newmask.clean(); 358 543 544 // Return the new mask 359 545 return newmask; 360 546 } 361 547 548 /** 549 @brief Removes all elements of the second mask from the first mask (all classes that are included in the first mask stay included, except those that are included in the second mask too). 550 @param other The mask to subtract. 551 @return The difference 552 */ 362 553 ClassTreeMask ClassTreeMask::operator-(const ClassTreeMask& other) const 363 554 { … … 365 556 } 366 557 558 /** 559 @brief Inverts the mask (all included classes are now excluded and vice versa). 560 @return The complement 561 */ 367 562 ClassTreeMask ClassTreeMask::operator!() const 368 563 { 564 // Create a new mask 369 565 ClassTreeMask newmask; 566 567 // Add all nodes from the other mask, inverting the rules 370 568 for (ClassTreeMaskIterator it = this->root_; it; ++it) 371 569 { … … 373 571 newmask.add(subclass, !this->isIncluded(subclass)); 374 572 } 573 574 // Return the new mask 375 575 return newmask; 376 576 } 377 577 578 /** 579 @brief Unites this mask with another mask. 580 @param other The other mask 581 @return A reference to the mask itself 582 */ 378 583 ClassTreeMask& ClassTreeMask::operator+=(const ClassTreeMask& other) 379 584 { … … 382 587 } 383 588 589 /** 590 @brief Intersects this mask with another mask. 591 @param other The other mask 592 @return A reference to the mask itself 593 */ 384 594 ClassTreeMask& ClassTreeMask::operator*=(const ClassTreeMask& other) 385 595 { … … 388 598 } 389 599 600 /** 601 @brief Subtracts another mask from this mask. 602 @param other The other mask 603 @return A reference to the mask itself 604 */ 390 605 ClassTreeMask& ClassTreeMask::operator-=(const ClassTreeMask& other) 391 606 { … … 394 609 } 395 610 611 /** 612 @brief Intersects two masks (only classes that are included in both masks will be included in the resulting mask too). 613 @param other The mask to intersect with 614 @return The intersection 615 */ 396 616 ClassTreeMask ClassTreeMask::operator&(const ClassTreeMask& other) const 397 617 { … … 399 619 } 400 620 621 /** 622 @brief Adds two masks in the sense of a union (all classes that are included in at least one of the masks will be included in the resulting mask too). 623 @param other The mask to unite with 624 @return The union 625 */ 401 626 ClassTreeMask ClassTreeMask::operator|(const ClassTreeMask& other) const 402 627 { … … 404 629 } 405 630 631 /** 632 @brief Joins two masks in the sense of a xor (exclusivity) operation (all classes that are included in exactly one of the masks, but not in both, will be included in the resulting mask too). 633 @param other The mask to join with 634 @return The result 635 */ 406 636 ClassTreeMask ClassTreeMask::operator^(const ClassTreeMask& other) const 407 637 { 638 // Create a new mask 408 639 ClassTreeMask newmask; 640 641 // Add all nodes from the first mask, calculate the rule with the xor-operation 409 642 for (ClassTreeMaskIterator it = this->root_; it; ++it) 410 643 { … … 412 645 newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass)); 413 646 } 647 648 // Add all nodes from the second mask, calculate the rule with the xor-operation 414 649 for (ClassTreeMaskIterator it = other.root_; it; ++it) 415 650 { … … 417 652 newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass)); 418 653 } 654 655 // Drop all redundant rules 419 656 newmask.clean(); 420 657 658 // Return the new mask 421 659 return newmask; 422 660 } 423 661 662 /** 663 @brief Inverts the mask (all included classes are now excluded and vice versa). 664 @return The complement 665 */ 424 666 ClassTreeMask ClassTreeMask::operator~() const 425 667 { … … 427 669 } 428 670 671 /** 672 @brief Intersects this mask with another mask (and-operation) 673 @param other The other mask 674 @return A reference to the mask itself 675 */ 429 676 ClassTreeMask& ClassTreeMask::operator&=(const ClassTreeMask& other) 430 677 { … … 433 680 } 434 681 682 /** 683 @brief Unites this mask with another mask (or-operation). 684 @param other The other mask 685 @return A reference to the mask itself 686 */ 435 687 ClassTreeMask& ClassTreeMask::operator|=(const ClassTreeMask& other) 436 688 { … … 439 691 } 440 692 693 /** 694 @brief Joins this mask with another mask with a xor-operation. 695 @param other The other mask 696 @return A reference to the mask itself 697 */ 441 698 ClassTreeMask& ClassTreeMask::operator^=(const ClassTreeMask& other) 442 699 { … … 445 702 } 446 703 704 /** 705 @brief Converts the content of a mask into a human readable string and puts it on the ostream. 706 @param out The ostream 707 @param mask The mask 708 @return A reference to the ostream 709 */ 447 710 std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask) 448 711 { 712 // Iterate through all rules 449 713 for (ClassTreeMaskIterator it = mask.root_; it; ++it) 450 714 { 715 // Calculate the prefix: + means included, - means excluded 451 716 if (it->isIncluded()) 452 717 out << "+"; … … 454 719 out << "-"; 455 720 721 // Put the name of the corresponding class on the stream 456 722 out << it->getClass()->getName() << " "; 457 723 } -
code/branches/core/src/orxonox/core/ClassTreeMask.h
r807 r809 26 26 */ 27 27 28 /*! 29 @file ClassTreeMask.h 30 @brief Definition of the ClassTreeMask, ClassTreeMaskNode and ClassTreeMaskIterator classes. 31 32 ClassTreeMask is a class to define a mask of the class-tree beginning with BaseObject. 33 You can include or exclude classes by calling the corresponding functions with the 34 Identifier of the class. 35 36 You can work with a ClassTreeMask in the sense of the set theory, meaning that you can create 37 unions, intersections, complements and differences by using overloaded operators. 38 39 The ClassTreeMask is internally represented by a tree. The nodes in the tree are 40 ClassTreeMaskNodes, containing the rule (included or excluded) for this class and all 41 subclasses and a list of all subnodes. To minimize the size, the tree contains only 42 nodes changing the mask. By adding new rules, the tree gets reordered dynamically. 43 44 You can manually add useless rules and they stay in the tree. That way you can add rules in 45 any order without changing information of the resulting mask. Example: A new mask includes all 46 classes. Now you explicitly include a subclass. This seems to be useless. But if you exclude a 47 baseclass of the formerly included subclass, the subclass stays included. You could create the 48 same mask by first excluding the baseclass and then including the subclass. You can drop 49 useless rules from the tree by calling clean(). 50 51 Because of the complicated shape of the internal tree, there is an iterator to iterate 52 through all ClassTreeMaskNodes of a mask. It starts with the BaseObject and moves on to 53 the first subclass until it reaches a leaf of the tree. Then the iterator moves one step 54 back and iterates to the second subclass. If there are no more subclasses, it steps another 55 step back, and so on. 56 57 Example: A and B are childs of BaseObject, A1 and A2 are childs of A, B1 and B2 are childs of B. 58 The ClassTreeMaskIterator would move trough the tree in the following order: 59 BaseObject, A, A1, A2, B, B1, B2. 60 61 Note that the iterator doesn't move trough the whole class-tree, but only through the 62 internal tree of the mask, containing the minimal needed set of nodes to describe the mask. 63 */ 64 28 65 #ifndef _ClassTreeMask_H__ 29 66 #define _ClassTreeMask_H__ … … 36 73 namespace orxonox 37 74 { 75 // ############################### 76 // ### ClassTreeMaskNode ### 77 // ############################### 78 //! The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of the mask. 79 /** 80 The ClassTreeMaskNode is used to store the rule (included or excluded) for a given 81 class (described by the corresponding Identifier). The nodes are used in the internal 82 tree of ClassTreeMask. To build a tree, they store a list of all subnodes. 83 */ 38 84 class ClassTreeMaskNode 39 85 { … … 57 103 58 104 private: 59 const Identifier* subclass_; 60 bool bIncluded_; 61 std::list<ClassTreeMaskNode*> subnodes_; 105 const Identifier* subclass_; //!< The Identifier of the subclass the rule refers to 106 bool bIncluded_; //!< The rule: included or excluded 107 std::list<ClassTreeMaskNode*> subnodes_; //!< A list containing all subnodes in the tree 62 108 }; 63 109 110 111 // ############################### 112 // ### ClassTreeMaskIterator ### 113 // ############################### 114 //! The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMask, containing the rules. 115 /** 116 Because of the complicated shape of the internal rule-tree of ClassTreeMask, an 117 iterator is used to move through all nodes of the tree. It starts with the BaseObject 118 and moves on to the first subclass until it reaches a leaf of the tree. Then the 119 iterator moves one step back and iterates to the second subclass. If there are no more 120 subclasses, it steps another step back, and so on. 121 */ 64 122 class ClassTreeMaskIterator 65 123 { … … 76 134 77 135 private: 78 std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_; 79 std::list<ClassTreeMaskNode*> rootlist_; 136 std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_; //!< A stack to store list-iterators 137 std::list<ClassTreeMaskNode*> rootlist_; //!< A list for internal use (it only stores the root-node) 80 138 }; 81 139 140 141 // ############################### 142 // ### ClassTreeMask ### 143 // ############################### 144 //! The ClassTreeMask is a set of rules, containing the information for each class whether it's included or not. 145 /** 146 With a ClassTreeMask, you can include or exclude subtrees of the class-tree, starting 147 with a given subclass, described by the corresponding Identifier. To minimize the size 148 of the mask, the mask saves only relevant rules. But you are allowed to manually add 149 rules that don't change the information of the mask. This way you can create the same 150 mask by adding the same rules in a different way without changing the information. If 151 you want to drop useless rules, call the clean() function. 152 */ 82 153 class ClassTreeMask 83 154 { … … 126 197 void clean(ClassTreeMaskNode* node); 127 198 128 ClassTreeMaskNode* root_; 199 ClassTreeMaskNode* root_; //!< The root-node of the internal rule-tree, usually BaseObject 129 200 }; 130 201 } -
code/branches/core/src/orxonox/core/Identifier.h
r806 r809 180 180 This makes it possible to store informations about a class, sharing them with all 181 181 objects of that class without defining static variables in every class. 182 183 To be really sure that not more than exactly one object exists (even with libraries), 184 ClassIdentifiers are only created by IdentifierDistributor. 185 186 You can access the ClassIdentifiers created by IdentifierDistributor through the 187 ClassManager singletons. 182 188 */ 183 189 template <class T> -
code/branches/core/src/orxonox/core/IdentifierDistributor.cc
r805 r809 26 26 */ 27 27 28 /*! 29 @file IdentifierDistributor.cc 30 @brief Implementation of the IdentifierDistributor class. 31 */ 32 28 33 #include "IdentifierDistributor.h" 29 34 #include "Identifier.h" … … 31 36 namespace orxonox 32 37 { 38 /** 39 @brief Returns the only instance of a ClassIdentifier for a given class. 40 @param name The name of the class 41 @param proposal A proposal for the ClassIdentifier in case there is no entry yet. 42 @return The unique ClassIdentifier 43 */ 33 44 Identifier* IdentifierDistributor::getIdentifier(const std::string& name, Identifier* proposal) 34 45 { 46 // Create the only instance of the IdentifierDistributor-singleton 35 47 static IdentifierDistributor theOneAndOnlyInstance = IdentifierDistributor(); 36 48 49 // Look for an entry in the map 37 50 std::map<std::string, Identifier*>::const_iterator it = theOneAndOnlyInstance.identifiers_.find(name); 38 51 if (it != theOneAndOnlyInstance.identifiers_.end()) 39 52 { 53 // There is already an entry: return it 40 54 return (*it).second; 41 55 } 42 56 else 43 57 { 58 // There is no entry: put the proposal into the map and return it 44 59 theOneAndOnlyInstance.identifiers_[name] = proposal; 45 60 return proposal; -
code/branches/core/src/orxonox/core/IdentifierDistributor.h
r805 r809 26 26 */ 27 27 28 /*! 29 @file IdentifierDistributor.h 30 @brief Definition of the IdentifierDistributor class 31 32 The IdentifierDistributor makes sure that only one instance of ClassIdentifier for each 33 template parameter T exists. All Identifiers are stored in a map with their name. 34 IdentifierDistributor is a singleton class, it can't be created or deleted directly. 35 */ 36 28 37 #ifndef _IdentifierDistributor_H__ 29 38 #define _IdentifierDistributor_H__ … … 35 44 namespace orxonox 36 45 { 46 //! The Identifier Distributor stores all Identifiers and makes sure there are no ambiguities. 37 47 class IdentifierDistributor 38 48 { … … 41 51 42 52 private: 43 IdentifierDistributor() {}; 44 IdentifierDistributor(const IdentifierDistributor& distributor) {} 45 ~IdentifierDistributor() {} 53 IdentifierDistributor() {}; // Don't create 54 IdentifierDistributor(const IdentifierDistributor& distributor) {} // Don't copy 55 ~IdentifierDistributor() {} // Don't delete 46 56 47 std::map<std::string, Identifier*> identifiers_; 57 std::map<std::string, Identifier*> identifiers_; //!< The map to store all Identifiers. 48 58 }; 49 59 }
Note: See TracChangeset
for help on using the changeset viewer.