| | 1 | = Iterator = |
| | 2 | |
| | 3 | == Description == |
| | 4 | |
| | 5 | The [wiki:Iterator] allows you to easily iterate through all objects in an [wiki:ObjectList]. An [wiki:ObjectList] stores all objects of a given class (and all derivatives). To start iterating, you need the first element in the [wiki:ObjectList]. This gets returned by !ObjectList<!ClassName>::begin(). |
| | 6 | |
| | 7 | == Example == |
| | 8 | |
| | 9 | The following example uses the class-tree below. |
| | 10 | |
| | 11 | {{{ |
| | 12 | #!cpp |
| | 13 | new A1(); |
| | 14 | new A1(); |
| | 15 | new A1(); |
| | 16 | |
| | 17 | new A3(); |
| | 18 | new A3B1(); |
| | 19 | new A3B1C1(); |
| | 20 | |
| | 21 | int count = 0; |
| | 22 | for (Iterator<BaseObject> it = ObjectList<BaseObject>::begin(); it; ++it) |
| | 23 | count++; |
| | 24 | std::cout << "BaseObject: " << count << std::endl; |
| | 25 | |
| | 26 | count = 0; |
| | 27 | for (Iterator<A1> it = ObjectList<A1>::begin(); it; ++it) |
| | 28 | count++; |
| | 29 | std::cout << "A1: " << count << std::endl; |
| | 30 | |
| | 31 | count = 0; |
| | 32 | for (Iterator<A3B1> it = ObjectList<A3B1>::begin(); it; ++it) |
| | 33 | count++; |
| | 34 | std::cout << "A3B1: " << count << std::endl; |
| | 35 | |
| | 36 | /* |
| | 37 | return: |
| | 38 | BaseObject: 6 |
| | 39 | A1: 3 |
| | 40 | A3B1: 2 |
| | 41 | */ |
| | 42 | }}} |
| | 43 | |
| | 44 | [[Image(Core:testclass_tree.gif)]] |