Changeset 7372 for code/branches/doc/src/libraries/core/ClassTreeMask.h
- Timestamp:
- Sep 7, 2010, 12:58:52 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/doc/src/libraries/core/ClassTreeMask.h
r7363 r7372 30 30 @file 31 31 @ingroup Class 32 @brief De finition of the ClassTreeMask, ClassTreeMaskNodeand ClassTreeMaskIterator classes.33 34 ClassTreeMask is a class to define a mask of the class-tree beginning with BaseObject.32 @brief Declaration of the ClassTreeMask, ClassTreeMaskNode, and ClassTreeMaskIterator classes. 33 34 ClassTreeMask is a class to define a mask of the class-tree beginning with orxonox::BaseObject. 35 35 You can include or exclude classes by calling the corresponding functions with the 36 Identifier of the class. 36 orxonox::Identifier of the class. This mask can then be used to filter out objects that 37 are instances of classes which aren't included in the tree, for example when Loading a 38 level file or if a Trigger should be triggered by only a few classes. 39 40 See the description of orxonox::ClassTreeMask for a short example. 37 41 38 42 You can work with a ClassTreeMask in the sense of the set-theory, meaning that you can create 39 43 unions, intersections, complements and differences by using overloaded operators. 40 44 41 45 @par Tree structure 42 46 43 47 The ClassTreeMask is internally represented by a tree. The nodes in the tree are … … 46 50 nodes changing the mask. By adding new rules, the tree gets reordered dynamically. 47 51 48 Adding a new rule overwrites all rules assigned to inherited classes. Use overwrite = false52 Adding a new rule overwrites all rules assigned to inherited classes. Use <tt>overwrite = false</tt> 49 53 if you don't like this feature. Useless rules that don't change the information of the mask 50 aren't saved in the internal tree. Use clean = false if you wan't to save them. 51 52 With overwrite = false and clean = false it doesn't matter in which way you create the mask. 53 You can manually drop useless rules from the tree by calling clean(). 54 55 56 57 Because of the complicated shape of the internal tree, there is an iterator to iterate 58 through all ClassTreeMaskNodes of a mask. It starts with the BaseObject and moves on to 59 the first subclass until it reaches a leaf of the tree. Then the iterator moves one step 60 back and iterates to the second subclass. If there are no more subclasses, it steps another 61 step back, and so on. 62 63 Example: A and B are children of BaseObject, A1 and A2 are children of A, B1 and B2 are children of B. 64 The ClassTreeMaskIterator would move trough the tree in the following order: 65 BaseObject, A, A1, A2, B, B1, B2. 66 67 Note that the iterator doesn't move trough the whole class-tree, but only through the 68 internal tree of the mask, containing the minimal needed set of nodes to describe the mask. 54 aren't saved in the internal tree. Use <tt>clean = false</tt> if you still want to save them. 55 56 With <tt>overwrite = false</tt> and <tt>clean = false</tt> it doesn't matter in which order 57 you create the mask. You can manually drop useless rules from the tree by calling 58 @ref orxonox::ClassTreeMask::clean() "clean()". 59 60 @par Objects 61 62 To iterate through all objects of the classes that were included by a ClassTreeMask, 63 use orxonox::ClassTreeMaskObjectIterator. The description of this class also contains 64 a short example of how to use it. 69 65 */ 70 66 … … 84 80 // ### ClassTreeMaskNode ### 85 81 // ################################### 86 //! The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of the mask.87 82 /** 83 @brief The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of the mask. 84 88 85 The ClassTreeMaskNode is used to store the rule (included or excluded) for a given 89 86 class (described by the corresponding Identifier). The nodes are used in the internal … … 106 103 void addSubnode(ClassTreeMaskNode* subnode); 107 104 108 / ** @brief Tells if the rule is "included" or not. @return The rule: true = included, false = excluded */105 /// Tells if the rule is "included" or not. 109 106 inline bool isIncluded() const { return this->bIncluded_; } 110 / ** @brief Tells if the rule is "excluded" or not. @return The inverted rule: true = excluded, false = included */107 /// Tells if the rule is "excluded" or not. 111 108 inline bool isExcluded() const { return (!this->bIncluded_); } 112 109 113 / ** @brief Returns the Identifier of the class the rule refers to. @return The Identifier representing the class */110 /// Returns the Identifier of the class the rule refers to. 114 111 inline const Identifier* getClass() const { return this->subclass_; } 115 112 116 / ** @brief Returns true if the Node has some subnodes. */113 /// Returns true if the node has some subnodes. 117 114 inline bool hasSubnodes() const { return !this->subnodes_.empty(); } 118 115 … … 120 117 void deleteAllSubnodes(); 121 118 122 const Identifier* subclass_; // !< The Identifier of the subclass the rule refers to123 bool bIncluded_; // !< The rule: included or excluded124 std::list<ClassTreeMaskNode*> subnodes_; // !< A list containing all subnodes in the tree119 const Identifier* subclass_; ///< The Identifier of the subclass the rule refers to 120 bool bIncluded_; ///< The rule: included or excluded 121 std::list<ClassTreeMaskNode*> subnodes_; ///< A list containing all subnodes of this node 125 122 }; 126 123 … … 129 126 // ### ClassTreeMaskIterator ### 130 127 // ################################### 131 //! The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMask, containing the rules.132 128 /** 129 @brief The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMask which contains the rules. 130 133 131 Because of the complicated shape of the internal rule-tree of ClassTreeMask, an 134 132 iterator is used to move through all nodes of the tree. It starts with the BaseObject … … 136 134 iterator moves one step back and iterates to the second subclass. If there are no more 137 135 subclasses, it steps another step back, and so on. 136 137 Example: A and B are children of BaseObject, A1 and A2 are children of A, B1 and B2 are children of B. 138 The ClassTreeMaskIterator would move trough the tree in the following order: 139 BaseObject, A, A1, A2, B, B1, B2. 140 141 Note that the iterator doesn't move trough the whole class-tree, but only through the 142 internal tree of the mask, containing the minimal needed set of nodes to describe the mask. 138 143 */ 139 144 class _CoreExport ClassTreeMaskIterator … … 151 156 152 157 private: 153 std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_; // !< A stack to store list-iterators154 std::list<ClassTreeMaskNode*> rootlist_; // !< A list for internal use (it only stores the root-node)158 std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_; ///< A stack to store list-iterators 159 std::list<ClassTreeMaskNode*> rootlist_; ///< A list for internal use (it only stores the root-node) 155 160 }; 156 161 … … 159 164 // ### ClassTreeMask ### 160 165 // ################################### 161 //! The ClassTreeMask is a set of rules, containing the information for each class whether it's included or not.162 166 /** 167 @brief The ClassTreeMask is a set of rules, containing the information for each class whether it's included or not. 168 163 169 With a ClassTreeMask, you can include or exclude subtrees of the class-tree, starting 164 170 with a given subclass, described by the corresponding Identifier. To minimize the size 165 171 of the mask, the mask saves only relevant rules. But you can manually add rules that 166 don't change the information of the mask by using clean = false. If you want to drop172 don't change the information of the mask by using <tt>clean = false</tt>. If you want to drop 167 173 useless rules, call the clean() function. 174 175 Example: 176 @code 177 ClassTreeMask mymask; 178 mymask.exclude(Class(A)); 179 mymask.exclude(Class(B)); 180 mymask.include(Class(ChildOfA)); 181 @endcode 182 183 In this example, the classes A and B are excluded from the mask, but one of the child 184 classes of A is included again. 168 185 */ 169 186 class _CoreExport ClassTreeMask … … 190 207 bool isExcluded(const Identifier* subclass) const; 191 208 192 / ** @brief Begin of the ClassTreeMaskObjectIterator. */209 /// Begin of the ClassTreeMaskObjectIterator. 193 210 inline const ClassTreeMask& begin() const { return (*this); } 194 / ** @brief End of the ClassTreeMaskObjectIterator. */211 /// End of the ClassTreeMaskObjectIterator. 195 212 inline BaseObject* end() const { return 0; } 196 213 … … 229 246 bool nodeExists(const Identifier* subclass); 230 247 231 ClassTreeMaskNode* root_; // !< The root-node of the internal rule-tree, usually BaseObject248 ClassTreeMaskNode* root_; ///< The root-node of the internal rule-tree, usually BaseObject 232 249 }; 233 250 … … 236 253 // ### ClassTreeMaskObjectIterator ### 237 254 // ################################### 238 //! The ClassTreeMaskObjectIterator iterates through all objects of all classes, included by a ClassTreeMask.239 255 /** 240 The ClassTreeMaskObjectIterator iterates through all objects of all classes, 241 included by a ClassTreeMask. This is done the following way: 242 256 @brief The ClassTreeMaskObjectIterator iterates through all objects of the classes that were included by a ClassTreeMask. 257 258 This is done the following way: 259 @code 243 260 ClassTreeMask mask; 244 261 for (ClassTreeMaskObjectIterator it = mask.begin(); it != mask.end(); ++it) 245 262 it->doSomething(); 246 247 Note: The ClassTreeMaskObjectIterator handles all objects as BaseObjects. If 263 @endcode 264 265 @note The ClassTreeMaskObjectIterator handles all objects as BaseObjects. If 248 266 you want to use another class, you should use a dynamic_cast. 249 267 250 Performance of ClassTreeMaskObjectIterator is good as long as you don't exclude268 The performance of ClassTreeMaskObjectIterator is good as long as you don't exclude 251 269 subclasses of included classes. Of course you can still exlucde subclasses, but 252 270 if this is done more often, we need a new implementation using a second ObjectList … … 256 274 { 257 275 public: 258 / ** @brief Defaultconstructor: Does nothing. */276 /// Default-constructor: Does nothing. 259 277 inline ClassTreeMaskObjectIterator() {} 260 / ** @brief Constructor: Initializes the iterator from a given ClassTreeMask. @param mask The mask */278 /// Copy-Constructor: Initializes the iterator from another ClassTreeMask. 261 279 inline ClassTreeMaskObjectIterator(const ClassTreeMask& mask) { (*this) = mask; } 262 280 … … 265 283 const ClassTreeMaskObjectIterator& operator++(); 266 284 267 / ** @brief Returns true if the ClassTreeMaskObjectIterator points at the given object. @param pointer The pointer of the object */285 /// Returns true if the ClassTreeMaskObjectIterator points at the given object. 268 286 inline bool operator==(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) == pointer) || (!this->objectIterator_ && pointer == 0); } 269 / ** @brief Returns true if the ClassTreeMaskObjectIterator doesn't point at the given object. @param pointer The pointer of the object */287 /// Returns true if the ClassTreeMaskObjectIterator doesn't point at the given object. 270 288 inline bool operator!=(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) != pointer) || (!this->objectIterator_ && pointer != 0); } 271 / ** @brief Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end. */289 /// Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end. 272 290 inline operator bool() const { return (this->objectIterator_); } 273 / ** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */291 /// Returns the object the ClassTreeMaskObjectIterator currently points at. 274 292 inline BaseObject* operator*() const { return (*this->objectIterator_); } 275 / ** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */293 /// Returns the object the ClassTreeMaskObjectIterator currently points at. 276 294 inline BaseObject* operator->() const { return (*this->objectIterator_); } 277 295 … … 279 297 void create(ClassTreeMaskNode* node); 280 298 281 std::list<std::pair<const Identifier*, bool> > subclasses_; // !< A list of all Identifiers through which objects the iterator should iterate282 std::list<std::pair<const Identifier*, bool> >::iterator subclassIterator_; // !< The current class of the iterator283 Iterator<BaseObject> objectIterator_; // !< The current object of the iterator299 std::list<std::pair<const Identifier*, bool> > subclasses_; ///< A list of all Identifiers through which objects the iterator should iterate 300 std::list<std::pair<const Identifier*, bool> >::iterator subclassIterator_; ///< The current class of the iterator 301 Iterator<BaseObject> objectIterator_; ///< The current object of the iterator 284 302 }; 285 303 }
Note: See TracChangeset
for help on using the changeset viewer.