Changeset 1757 for code/trunk/src/core/ClassTreeMask.h
- Timestamp:
- Sep 10, 2008, 2:30:36 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.