Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of code/doc/Iterator


Ignore:
Timestamp:
Feb 25, 2008, 1:17:58 AM (17 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/Iterator

    v1 v1  
     1= Iterator =
     2
     3== Description ==
     4
     5The [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
     9The following example uses the class-tree below.
     10
     11{{{
     12#!cpp
     13new A1();
     14new A1();
     15new A1();
     16
     17new A3();
     18new A3B1();
     19new A3B1C1();
     20
     21int count = 0;
     22for (Iterator<BaseObject> it = ObjectList<BaseObject>::begin(); it; ++it)
     23  count++;
     24std::cout << "BaseObject: " << count << std::endl;
     25
     26count = 0;
     27for (Iterator<A1> it = ObjectList<A1>::begin(); it; ++it)
     28  count++;
     29std::cout << "A1:         " << count << std::endl;
     30
     31count = 0;
     32for (Iterator<A3B1> it = ObjectList<A3B1>::begin(); it; ++it)
     33  count++;
     34std::cout << "A3B1:       " << count << std::endl;
     35
     36/*
     37return:
     38BaseObject: 6
     39A1:         3
     40A3B1:       2
     41*/
     42}}}
     43
     44[[Image(Core:testclass_tree.gif)]]