Changeset 7401 for code/trunk/src/libraries/core/ClassTreeMask.h
- Timestamp:
- Sep 11, 2010, 12:34:00 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/doc (added) merged: 7290-7292,7296-7300,7302-7304,7306-7312,7315-7318,7323,7325,7327,7331-7332,7334-7335,7345-7347,7352-7353,7356-7357,7361,7363-7367,7371-7375,7388
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/ClassTreeMask.h
r7268 r7401 29 29 /** 30 30 @file 31 @brief Definition of the ClassTreeMask, ClassTreeMaskNode and ClassTreeMaskIterator classes. 32 33 ClassTreeMask is a class to define a mask of the class-tree beginning with BaseObject. 31 @ingroup Class 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. 34 35 You can include or exclude classes by calling the corresponding functions with the 35 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. 36 41 37 42 You can work with a ClassTreeMask in the sense of the set-theory, meaning that you can create 38 43 unions, intersections, complements and differences by using overloaded operators. 39 44 40 45 @par Tree structure 41 46 42 47 The ClassTreeMask is internally represented by a tree. The nodes in the tree are … … 45 50 nodes changing the mask. By adding new rules, the tree gets reordered dynamically. 46 51 47 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> 48 53 if you don't like this feature. Useless rules that don't change the information of the mask 49 aren't saved in the internal tree. Use clean = false if you wan't to save them. 50 51 With overwrite = false and clean = false it doesn't matter in which way you create the mask. 52 You can manually drop useless rules from the tree by calling clean(). 53 54 55 56 Because of the complicated shape of the internal tree, there is an iterator to iterate 57 through all ClassTreeMaskNodes of a mask. It starts with the BaseObject and moves on to 58 the first subclass until it reaches a leaf of the tree. Then the iterator moves one step 59 back and iterates to the second subclass. If there are no more subclasses, it steps another 60 step back, and so on. 61 62 Example: A and B are children of BaseObject, A1 and A2 are children of A, B1 and B2 are children of B. 63 The ClassTreeMaskIterator would move trough the tree in the following order: 64 BaseObject, A, A1, A2, B, B1, B2. 65 66 Note that the iterator doesn't move trough the whole class-tree, but only through the 67 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. 68 65 */ 69 66 … … 83 80 // ### ClassTreeMaskNode ### 84 81 // ################################### 85 //! The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of the mask.86 82 /** 83 @brief The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of the mask. 84 87 85 The ClassTreeMaskNode is used to store the rule (included or excluded) for a given 88 86 class (described by the corresponding Identifier). The nodes are used in the internal … … 105 103 void addSubnode(ClassTreeMaskNode* subnode); 106 104 107 / ** @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. 108 106 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 */107 /// Tells if the rule is "excluded" or not. 110 108 inline bool isExcluded() const { return (!this->bIncluded_); } 111 109 112 / ** @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. 113 111 inline const Identifier* getClass() const { return this->subclass_; } 114 112 115 / ** @brief Returns true if the Node has some subnodes. */113 /// Returns true if the node has some subnodes. 116 114 inline bool hasSubnodes() const { return !this->subnodes_.empty(); } 117 115 … … 119 117 void deleteAllSubnodes(); 120 118 121 const Identifier* subclass_; // !< The Identifier of the subclass the rule refers to122 bool bIncluded_; // !< The rule: included or excluded123 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 124 122 }; 125 123 … … 128 126 // ### ClassTreeMaskIterator ### 129 127 // ################################### 130 //! The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMask, containing the rules.131 128 /** 129 @brief The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMask which contains the rules. 130 132 131 Because of the complicated shape of the internal rule-tree of ClassTreeMask, an 133 132 iterator is used to move through all nodes of the tree. It starts with the BaseObject … … 135 134 iterator moves one step back and iterates to the second subclass. If there are no more 136 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. 137 143 */ 138 144 class _CoreExport ClassTreeMaskIterator … … 150 156 151 157 private: 152 std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_; // !< A stack to store list-iterators153 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) 154 160 }; 155 161 … … 158 164 // ### ClassTreeMask ### 159 165 // ################################### 160 //! The ClassTreeMask is a set of rules, containing the information for each class whether it's included or not.161 166 /** 167 @brief The ClassTreeMask is a set of rules, containing the information for each class whether it's included or not. 168 162 169 With a ClassTreeMask, you can include or exclude subtrees of the class-tree, starting 163 170 with a given subclass, described by the corresponding Identifier. To minimize the size 164 171 of the mask, the mask saves only relevant rules. But you can manually add rules that 165 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 166 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. 167 185 */ 168 186 class _CoreExport ClassTreeMask … … 189 207 bool isExcluded(const Identifier* subclass) const; 190 208 191 / ** @brief Begin of the ClassTreeMaskObjectIterator. */209 /// Begin of the ClassTreeMaskObjectIterator. 192 210 inline const ClassTreeMask& begin() const { return (*this); } 193 / ** @brief End of the ClassTreeMaskObjectIterator. */211 /// End of the ClassTreeMaskObjectIterator. 194 212 inline BaseObject* end() const { return 0; } 195 213 … … 228 246 bool nodeExists(const Identifier* subclass); 229 247 230 ClassTreeMaskNode* root_; // !< The root-node of the internal rule-tree, usually BaseObject248 ClassTreeMaskNode* root_; ///< The root-node of the internal rule-tree, usually BaseObject 231 249 }; 232 250 … … 235 253 // ### ClassTreeMaskObjectIterator ### 236 254 // ################################### 237 //! The ClassTreeMaskObjectIterator iterates through all objects of all classes, included by a ClassTreeMask.238 255 /** 239 The ClassTreeMaskObjectIterator iterates through all objects of all classes, 240 included by a ClassTreeMask. This is done the following way: 241 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 242 260 ClassTreeMask mask; 243 261 for (ClassTreeMaskObjectIterator it = mask.begin(); it != mask.end(); ++it) 244 262 it->doSomething(); 245 246 Note: The ClassTreeMaskObjectIterator handles all objects as BaseObjects. If 263 @endcode 264 265 @note The ClassTreeMaskObjectIterator handles all objects as BaseObjects. If 247 266 you want to use another class, you should use a dynamic_cast. 248 267 249 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 250 269 subclasses of included classes. Of course you can still exlucde subclasses, but 251 270 if this is done more often, we need a new implementation using a second ObjectList … … 255 274 { 256 275 public: 257 / ** @brief Defaultconstructor: Does nothing. */276 /// Default-constructor: Does nothing. 258 277 inline ClassTreeMaskObjectIterator() {} 259 / ** @brief Constructor: Initializes the iterator from a given ClassTreeMask. @param mask The mask */278 /// Copy-Constructor: Initializes the iterator from another ClassTreeMask. 260 279 inline ClassTreeMaskObjectIterator(const ClassTreeMask& mask) { (*this) = mask; } 261 280 … … 264 283 const ClassTreeMaskObjectIterator& operator++(); 265 284 266 / ** @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. 267 286 inline bool operator==(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) == pointer) || (!this->objectIterator_ && pointer == 0); } 268 / ** @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. 269 288 inline bool operator!=(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) != pointer) || (!this->objectIterator_ && pointer != 0); } 270 / ** @brief Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end. */289 /// Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end. 271 290 inline operator bool() const { return (this->objectIterator_); } 272 / ** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */291 /// Returns the object the ClassTreeMaskObjectIterator currently points at. 273 292 inline BaseObject* operator*() const { return (*this->objectIterator_); } 274 / ** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */293 /// Returns the object the ClassTreeMaskObjectIterator currently points at. 275 294 inline BaseObject* operator->() const { return (*this->objectIterator_); } 276 295 … … 278 297 void create(ClassTreeMaskNode* node); 279 298 280 std::list<std::pair<const Identifier*, bool> > subclasses_; // !< A list of all Identifiers through which objects the iterator should iterate281 std::list<std::pair<const Identifier*, bool> >::iterator subclassIterator_; // !< The current class of the iterator282 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 283 302 }; 284 303 }
Note: See TracChangeset
for help on using the changeset viewer.