Changeset 1757 for code/trunk
- Timestamp:
- Sep 10, 2008, 2:30:36 AM (16 years ago)
- Location:
- code/trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/ClassTreeMask.cc
r1543 r1757 102 102 103 103 /** 104 @brief Tells if the rule is "included" or not.105 @return The rule: true = included, false = excluded106 */107 bool ClassTreeMaskNode::isIncluded() const108 {109 return this->bIncluded_;110 }111 112 /**113 @brief Tells if the rule is "excluded" or not.114 @return The inverted rule: true = excluded, false = included115 */116 bool ClassTreeMaskNode::isExcluded() const117 {118 return (!this->bIncluded_);119 }120 121 /**122 @brief Returns the Identifier of the class the rule refers to.123 @return The Identifier representing the class124 */125 const Identifier* ClassTreeMaskNode::getClass() const126 {127 return this->subclass_;128 }129 130 /**131 104 @brief Deletes all subnodes of this node. 132 105 */ … … 169 142 @return A reference to the iterator itself 170 143 */ 171 ClassTreeMaskIterator& ClassTreeMaskIterator::operator++()144 const ClassTreeMaskIterator& ClassTreeMaskIterator::operator++() 172 145 { 173 146 // Check if the actual node has subnodes … … 226 199 @return True if we've reached the end of the tree 227 200 */ 228 ClassTreeMaskIterator::operator bool() 201 ClassTreeMaskIterator::operator bool() const 229 202 { 230 203 return (!this->nodes_.empty()); … … 236 209 @return The result of the comparison (true if they match) 237 210 */ 238 bool ClassTreeMaskIterator::operator==(ClassTreeMaskNode* compare) 211 bool ClassTreeMaskIterator::operator==(ClassTreeMaskNode* compare) const 239 212 { 240 213 if (!this->nodes_.empty()) … … 249 222 @return The result of the comparison (true if they don't match) 250 223 */ 251 bool ClassTreeMaskIterator::operator!=(ClassTreeMaskNode* compare) 224 bool ClassTreeMaskIterator::operator!=(ClassTreeMaskNode* compare) const 252 225 { 253 226 if (!this->nodes_.empty()) … … 545 518 @return A reference to the mask itself 546 519 */ 547 ClassTreeMask& ClassTreeMask::operator=(const ClassTreeMask& other)520 const ClassTreeMask& ClassTreeMask::operator=(const ClassTreeMask& other) 548 521 { 549 522 // Make a copy to avoid troubles with self-assignments (like A = A). … … 598 571 @return A reference to the mask itself 599 572 */ 600 ClassTreeMask& ClassTreeMask::operator+()573 const ClassTreeMask& ClassTreeMask::operator+() const 601 574 { 602 575 return (*this); … … 709 682 @return A reference to the mask itself 710 683 */ 711 ClassTreeMask& ClassTreeMask::operator+=(const ClassTreeMask& other)684 const ClassTreeMask& ClassTreeMask::operator+=(const ClassTreeMask& other) 712 685 { 713 686 (*this) = (*this) + other; … … 720 693 @return A reference to the mask itself 721 694 */ 722 ClassTreeMask& ClassTreeMask::operator*=(const ClassTreeMask& other)695 const ClassTreeMask& ClassTreeMask::operator*=(const ClassTreeMask& other) 723 696 { 724 697 (*this) = (*this) * other; … … 731 704 @return A reference to the mask itself 732 705 */ 733 ClassTreeMask& ClassTreeMask::operator-=(const ClassTreeMask& other)706 const ClassTreeMask& ClassTreeMask::operator-=(const ClassTreeMask& other) 734 707 { 735 708 (*this) = (*this) - other; … … 802 775 @return A reference to the mask itself 803 776 */ 804 ClassTreeMask& ClassTreeMask::operator&=(const ClassTreeMask& other)777 const ClassTreeMask& ClassTreeMask::operator&=(const ClassTreeMask& other) 805 778 { 806 779 (*this) = (*this) & other; … … 813 786 @return A reference to the mask itself 814 787 */ 815 ClassTreeMask& ClassTreeMask::operator|=(const ClassTreeMask& other)788 const ClassTreeMask& ClassTreeMask::operator|=(const ClassTreeMask& other) 816 789 { 817 790 (*this) = (*this) | other; … … 824 797 @return A reference to the mask itself 825 798 */ 826 ClassTreeMask& ClassTreeMask::operator^=(const ClassTreeMask& other)799 const ClassTreeMask& ClassTreeMask::operator^=(const ClassTreeMask& other) 827 800 { 828 801 (*this) = (*this) ^ other; … … 853 826 return out; 854 827 } 828 829 830 // ################################### 831 // ### ClassTreeMaskObjectIterator ### 832 // ################################### 833 /** 834 @brief Initializes the iterator from a given ClassTreeMask. 835 @param mask The mask 836 */ 837 const ClassTreeMaskObjectIterator& ClassTreeMaskObjectIterator::operator=(const ClassTreeMask& mask) 838 { 839 // Clear everything, use a cleaned copy of the mask 840 this->subclasses_.clear(); 841 ClassTreeMask temp = mask; 842 temp.clean(); 843 844 // Create the subclass-list by going through the mask-tree, starting with the root-node 845 this->create(temp.root_); 846 847 // Move the subclass-iterator to the beginning of the subclass-list 848 this->subclassIterator_ = this->subclasses_.begin(); 849 850 // If there is a first subclass, move the object-iterator to the first object of this class. Else go to the end 851 if (this->subclassIterator_ != this->subclasses_.end()) 852 this->objectIterator_ = (*this->subclassIterator_).first->getObjects()->begin(); 853 else 854 this->objectIterator_ = ObjectList<BaseObject>::end(); 855 856 // Check if the iterator points on a valid object. If not, go to the next object by calling ++ 857 if (!this->objectIterator_ || ((*this->subclassIterator_).second && !this->objectIterator_->isExactlyA((*this->subclassIterator_).first))) 858 this->operator++(); 859 860 return (*this); 861 } 862 863 /** 864 @brief Iterate to the next object (if any). 865 @return The iterator itself 866 */ 867 const ClassTreeMaskObjectIterator& ClassTreeMaskObjectIterator::operator++() 868 { 869 if (this->objectIterator_) 870 { 871 // The iterator points on a valid object, therefore we also have a valid subclass-iterator at the moment 872 do 873 { 874 // Go to the next object 875 ++this->objectIterator_; 876 877 while (!this->objectIterator_) 878 { 879 // We reached the end of the current objectlist - go to the next class 880 ++this->subclassIterator_; 881 882 // Check if there really is a next class. If yes, move the object-iterator to the first object 883 if (this->subclassIterator_ != this->subclasses_.end()) 884 this->objectIterator_ = (*this->subclassIterator_).first->getObjects()->begin(); 885 else 886 return (*this); 887 } 888 889 // Repeat this until we reach a valid object or the end 890 } while ((*this->subclassIterator_).second && !this->objectIterator_->isExactlyA((*this->subclassIterator_).first)); 891 } 892 return (*this); 893 } 894 895 /** 896 @brief Recursive function to create the Iterators subclass-list by going through the node-tree of the mask. 897 @param node The current node 898 */ 899 void ClassTreeMaskObjectIterator::create(ClassTreeMaskNode* node) 900 { 901 // Add the class of this node to the list, if the class is included 902 if (node->isIncluded()) 903 { 904 // If there are some subnodes, the bool is "true", meaning we have to check for the exact clss when iterating 905 if (node->hasSubnodes()) 906 this->subclasses_.insert(this->subclasses_.end(), std::pair<const Identifier*, bool>(node->getClass(), true)); 907 else 908 this->subclasses_.insert(this->subclasses_.end(), std::pair<const Identifier*, bool>(node->getClass(), false)); 909 } 910 911 // Now check if the node has subnodes 912 if (node->hasSubnodes()) 913 { 914 // Get all _direct_ children of the nodes class 915 std::set<const Identifier*> directChildren = node->getClass()->getDirectChildren(); 916 917 // Iterate through all subnodes 918 for (std::list<ClassTreeMaskNode*>::iterator it1 = node->subnodes_.begin(); it1 != node->subnodes_.end(); ++it1) 919 { 920 // Recursive call to this function with the subnode 921 this->create(*it1); 922 923 // Only execute the following code if the current node is included, meaning some of the subnodes might be included too 924 if (node->isIncluded()) 925 { 926 scanChildren: // This is a label for goto 927 928 // Iterate through all direct children 929 for (std::set<const Identifier*>::iterator it2 = directChildren.begin(); it2 != directChildren.end(); ++it2) 930 { 931 // Check if the subnode (it1) is a child of the directChild (it2) 932 if ((*it1)->getClass()->isA(*it2)) 933 { 934 // Yes it is - remove the directChild (it2) from the list, because it will already be handled by a recursive call to the create() function 935 directChildren.erase(it2); 936 937 // Check if the removed directChild was exactly the subnode 938 if (!(*it1)->getClass()->isExactlyA(*it2)) 939 { 940 // No, it wasn't exactly the subnode - therefore there are some classes between 941 942 // Add the previously removed directChild (it2) to the subclass-list 943 this->subclasses_.insert(this->subclasses_.end(), std::pair<const Identifier*, bool>(*it2, true)); 944 945 // Insert all directChildren of the directChild 946 directChildren.insert((*it2)->getDirectChildrenBegin(), (*it2)->getDirectChildrenEnd()); 947 948 // Restart the scan with the expanded set of directChildren 949 goto scanChildren; 950 } 951 break; 952 } 953 } 954 } 955 } 956 957 // Now add all directChildren which don't have subnodes on their own to the subclass-list 958 // The bool is "false", meaning they have no subnodes and therefore need no further checks 959 if (node->isIncluded()) 960 for (std::set<const Identifier*>::iterator it = directChildren.begin(); it != directChildren.end(); ++it) 961 this->subclasses_.insert(this->subclasses_.end(), std::pair<const Identifier*, bool>(*it, false)); 962 } 963 } 855 964 } -
code/trunk/src/core/ClassTreeMask.h
r1755 r1757 76 76 #include <stack> 77 77 78 #include "Iterator.h" 79 78 80 namespace orxonox 79 81 { … … 91 93 friend class ClassTreeMask; 92 94 friend class ClassTreeMaskIterator; 95 friend class ClassTreeMaskObjectIterator; 93 96 94 97 public: … … 102 105 void addSubnode(ClassTreeMaskNode* subnode); 103 106 104 bool isIncluded() const; 105 bool isExcluded() const; 106 107 const Identifier* getClass() const; 107 /** @brief Tells if the rule is "included" or not. @return The rule: true = included, false = excluded */ 108 inline bool isIncluded() const { return this->bIncluded_; } 109 /** @brief Tells if the rule is "excluded" or not. @return The inverted rule: true = excluded, false = included */ 110 inline bool isExcluded() const { return (!this->bIncluded_); } 111 112 /** @brief Returns the Identifier of the class the rule refers to. @return The Identifier representing the class */ 113 inline const Identifier* getClass() const { return this->subclass_; } 114 115 /** @brief Returns true if the Node has some subnodes. */ 116 inline bool hasSubnodes() const { return !this->subnodes_.empty(); } 108 117 109 118 private: … … 133 142 ~ClassTreeMaskIterator(); 134 143 135 ClassTreeMaskIterator& operator++();144 const ClassTreeMaskIterator& operator++(); 136 145 ClassTreeMaskNode* operator*() const; 137 146 ClassTreeMaskNode* operator->() const; 138 operator bool() ;139 bool operator==(ClassTreeMaskNode* compare) ;140 bool operator!=(ClassTreeMaskNode* compare) ;147 operator bool() const; 148 bool operator==(ClassTreeMaskNode* compare) const; 149 bool operator!=(ClassTreeMaskNode* compare) const; 141 150 142 151 private: … … 159 168 class _CoreExport ClassTreeMask 160 169 { 170 friend class ClassTreeMaskObjectIterator; 171 161 172 public: 162 173 ClassTreeMask(); … … 178 189 bool isExcluded(const Identifier* subclass) const; 179 190 180 ClassTreeMask& operator=(const ClassTreeMask& other); 191 /** @brief Begin of the ClassTreeMaskObjectIterator. */ 192 inline const ClassTreeMask& begin() const { return (*this); } 193 /** @brief End of the ClassTreeMaskObjectIterator. */ 194 inline BaseObject* end() const { return 0; } 195 196 const ClassTreeMask& operator=(const ClassTreeMask& other); 181 197 182 198 bool operator==(const ClassTreeMask& other) const; 183 199 bool operator!=(const ClassTreeMask& other) const; 184 200 185 ClassTreeMask& operator+();201 const ClassTreeMask& operator+() const; 186 202 ClassTreeMask operator-() const; 187 203 … … 191 207 ClassTreeMask operator!() const; 192 208 193 ClassTreeMask& operator+=(const ClassTreeMask& other);194 ClassTreeMask& operator*=(const ClassTreeMask& other);195 ClassTreeMask& operator-=(const ClassTreeMask& other);209 const ClassTreeMask& operator+=(const ClassTreeMask& other); 210 const ClassTreeMask& operator*=(const ClassTreeMask& other); 211 const ClassTreeMask& operator-=(const ClassTreeMask& other); 196 212 197 213 ClassTreeMask operator&(const ClassTreeMask& other) const; … … 200 216 ClassTreeMask operator~() const; 201 217 202 ClassTreeMask& operator&=(const ClassTreeMask& other);203 ClassTreeMask& operator|=(const ClassTreeMask& other);204 ClassTreeMask& operator^=(const ClassTreeMask& other);218 const ClassTreeMask& operator&=(const ClassTreeMask& other); 219 const ClassTreeMask& operator|=(const ClassTreeMask& other); 220 const ClassTreeMask& operator^=(const ClassTreeMask& other); 205 221 206 222 friend std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask); … … 219 235 // ### ClassTreeMaskObjectIterator ### 220 236 // ################################### 221 //! ... 222 /** 223 ... 237 //! The ClassTreeMaskObjectIterator iterates through all objects of all classes, included by a ClassTreeMask. 238 /** 239 The ClassTreeMaskObjectIterator iterates through all objects of all classes, 240 included by a ClassTreeMask. This is done the following way: 241 242 ClassTreeMask mask; 243 for (ClassTreeMaskObjectIterator it = mask.begin(); it != mask.end(); ++it) 244 it->doSomething(); 245 246 Note: The ClassTreeMaskObjectIterator handles all objects as BaseObjects. If 247 you want to use another class, you should use a dynamic_cast. 248 249 Performance of ClassTreeMaskObjectIterator is good as long as you don't exclude 250 subclasses of included classes. Of course you can still exlucde subclasses, but 251 if this is done more often, we need a new implementation using a second ObjectList 252 in the Identifier, containing all objects of exactly one class. 224 253 */ 225 254 class _CoreExport ClassTreeMaskObjectIterator 226 255 { 256 public: 257 /** @brief Defaultconstructor: Does nothing. */ 258 inline ClassTreeMaskObjectIterator() {} 259 /** @brief Constructor: Initializes the iterator from a given ClassTreeMask. @param mask The mask */ 260 inline ClassTreeMaskObjectIterator(const ClassTreeMask& mask) { (*this) = mask; } 261 262 const ClassTreeMaskObjectIterator& operator=(const ClassTreeMask& mask); 263 264 const ClassTreeMaskObjectIterator& operator++(); 265 266 /** @brief Returns true if the ClassTreeMaskObjectIterator points at the given object. @param pointer The pointer of the object */ 267 inline bool operator==(BaseObject* pointer) const { return ((*this->objectIterator_) == pointer); } 268 /** @brief Returns true if the ClassTreeMaskObjectIterator doesn't point at the given object. @param pointer The pointer of the object */ 269 inline bool operator!=(BaseObject* pointer) const { return ((*this->objectIterator_) != pointer); } 270 /** @brief Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end. */ 271 inline operator bool() const { return (this->objectIterator_); } 272 /** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */ 273 inline BaseObject* operator*() const { return (*this->objectIterator_); } 274 /** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */ 275 inline BaseObject* operator->() const { return (*this->objectIterator_); } 276 277 private: 278 void create(ClassTreeMaskNode* node); 279 280 std::list<std::pair<const Identifier*, bool> > subclasses_; //!< A list of all Identifiers through which objects the iterator should iterate 281 std::list<std::pair<const Identifier*, bool> >::iterator subclassIterator_; //!< The current class of the iterator 282 Iterator<BaseObject> objectIterator_; //!< The current object of the iterator 227 283 }; 228 284 } -
code/trunk/src/core/CorePrereqs.h
r1755 r1757 98 98 class ClassTreeMaskIterator; 99 99 class ClassTreeMaskNode; 100 class ClassTreeMaskObjectIterator; 100 101 class Clock; 101 102 class CommandEvaluation; -
code/trunk/src/util/MultiType.h
r1747 r1757 164 164 inline ~MultiType() { if (this->value_) { delete this->value_; } } 165 165 166 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); }167 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); }168 inline MultiType& operator=(MT_Type type) { this->setType(type); return (*this); }166 template <typename V> inline const MultiType& operator=(const V& value) { this->setValue(value); return (*this); } 167 inline const MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } 168 inline const MultiType& operator=(MT_Type type) { this->setType(type); return (*this); } 169 169 170 170 inline void setValue(const char& value);
Note: See TracChangeset
for help on using the changeset viewer.