7 | | The !ClassTreeMask defines a mask that includes or excludes branches and single classes in the [wiki:Identifier class-tree]. You can think of the !ClassTreeMask like a mask in computer graphics: A mask is a black/white picture where black means invisible and white means fully visible. That way you can show some parts of an image and hide others. The !ClassTreeMask does the same with the class-tree, but ''show'' means ''include'' and ''hide'' means ''exclude''. An unmodified mask shows everything / is white / includes the [wiki:BaseObject] (those statements are equivalent). '''Notation: Including or excluding a class is denoted as "adding a new rule".''' |
| 7 | The !ClassTreeMask defines a mask that includes or excludes branches and single classes in the [wiki:Identifier class-tree]. You can think of the !ClassTreeMask like a mask in computer graphics: A mask is a black/white picture where black means invisible and white means fully visible. That way you can show some parts of an image and hide others. The !ClassTreeMask does the same with the class-tree, but ''show'' means ''include'' and ''hide'' means ''exclude''. An unmodified mask shows everything / is white / includes the [wiki:BaseObject] (those statements are equivalent). |
| 8 | |
| 9 | == Creating the mask == |
| 10 | === Include and exclude === |
| 11 | You can include and exclude classes in the mask by calling the corresponding functions. Including/Excluding a class usually applies not only to the specified class but to all subclasses too. |
| 12 | |
| 13 | '''Notation: Including or excluding a class is denoted as "adding a new rule".''' |
13 | | After including/excluding a class, the !ClassTreeMask is scanned for useless rules. If you include the [wiki:BaseObject] and include a subclass of [wiki:BaseObject] too, this brings no new information, so the inclusion-rule of the subclass can be discarded. Only rules that change the state are saved. You can turn of this cleanup by setting the ''clean'' flag to false. '''Warning''': This could change the meaning of your mask when you add further rules with ''overwrite'' set to false. If, in our example, the subclass of [wiki:BaseObject] was included without ''clean'' and afterward you exclude the [wiki:BaseObject] without ''overwrite'', the subclass stays included. You'll find some examples for this in the corresponding section of this page. |
14 | | |
| 20 | === The ''clean'' flag === |
| 21 | After including/excluding a class, the !ClassTreeMask is scanned for useless rules. If you include the [wiki:BaseObject] and include a subclass of [wiki:BaseObject] too, this brings no new information, so the inclusion-rule of the subclass can be discarded. Only rules that change the state are saved. You can turn this cleanup off by setting the ''clean'' flag to false. '''Warning''': This could change the meaning of your mask when you add further rules with ''overwrite'' set to false. If, in our example, the subclass of [wiki:BaseObject] was included without ''clean'' and afterward you exclude the [wiki:BaseObject] without ''overwrite'', the subclass stays included. You'll find some examples for this in the corresponding section of this page. |
| 22 | |
| 23 | === Rules for single classes === |
22 | | * '''include('''''class''''', '''''overwrite''''', '''''clean''''')''': Includes ''class'' and all following classes. If ''overwrite'' is false, only classes that weren't explicitly excluded previously are included (default is true). If ''clean'' is true, only relevant rules stay in the branch (default is true). |
23 | | * '''exclude('''''class''''', '''''overwrite''''', '''''clean''''')''': Excludes ''class'' and all following classes. If ''overwrite'' is false, only classes that weren't explicitly included previously are excluded (default is true). If ''clean'' is true, only relevant rules stay in the branch (default is true). |
| 32 | * '''include('''''class'' [''', '''''overwrite''''', '''''clean'']''')''': Includes ''class'' and all following classes. If ''overwrite'' is false, only classes that weren't explicitly excluded previously are included (default is true). If ''clean'' is true, only relevant rules stay in the branch (default is true). |
| 33 | * '''exclude('''''class'' [''', '''''overwrite''''', '''''clean'']''')''': Excludes ''class'' and all following classes. If ''overwrite'' is false, only classes that weren't explicitly included previously are excluded (default is true). If ''clean'' is true, only relevant rules stay in the branch (default is true). |
26 | | * '''includeSingle('''''class''''', '''''clean''''')''': Includes ''class'' without changing the rule for following classes. If ''clean'' is true, only relevant rules stay in the branch (default is true). |
27 | | * '''excludeSingle('''''class''''', '''''clean''''')''': Excludes ''class'' without changing the rule for following classes. If ''clean'' is true, only relevant rules stay in the branch (default is true). |
| 36 | * '''includeSingle('''''class'' [''', '''''clean'']''')''': Includes ''class'' without changing the rule for following classes. If ''clean'' is true, only relevant rules stay in the branch (default is true). |
| 37 | * '''excludeSingle('''''class'' [''', '''''clean'']''')''': Excludes ''class'' without changing the rule for following classes. If ''clean'' is true, only relevant rules stay in the branch (default is true). |
| 58 | == Iterator == |
| 59 | Sometimes you want to iterate through all existing objects which are instances of classes included in a !ClassTreeMask. This can be achieved by using an !ClassTreeMaskObjectIterator. |
| 60 | |
| 61 | This is done the following way: |
| 62 | {{{ |
| 63 | for (ClassTreeMaskObjectIterator it = mask.begin(); it != mask.end(); ++it) |
| 64 | it->doSomething(); |
| 65 | }}} |
| 66 | |
| 67 | '''Note''': The ClassTreeMaskObjectIterator handles all objects as BaseObjects. If you want to use another class, you should use a dynamic_cast: |
| 68 | {{{ |
| 69 | for (ClassTreeMaskObjectIterator it = mask.begin(); it != mask.end(); ++it) |
| 70 | (dynamic_cast<SomeClass*>(*it))->doSomethingAdvanced(); |
| 71 | }}} |
| 72 | |
| 73 | Performance of ClassTreeMaskObjectIterator is good as long as you don't exclude subclasses of included classes. Of course you can still exlucde subclasses, but if this is done more often, we need a new implementation using a second ObjectList in the Identifier, containing all objects of exactly one class. Including subclasses of excluded classes however is really fast. |
| 74 | |