company logo

Iterator element

Iterator elements are property references followed by an empty parameter list: Iterator elements are used to indicate the iteration level:

persons.children().children()

This path will iterate through all grand children of the person selected in the persons property. It will not iterate through the persons collection, since persons does not define the selector operator. When, however, defining the path as follows:

persons().children().children()

The path provides all grand children for all persons. Iterator elements in a path are just an abbreviation. Instead using iteration path, one could always write a nested loop, e.g.

while ( persons.Next )

while ( persons.children.Next )

while ( persons.children.children.Next )

In many cases, it is, however, much easier to refer to a path.

//prints name and first name for all grand children

//duplicates may appear, since a person may be grand

//child of maximum four grand parents.

// using path property

  Property          grand_children(obh, "Person::Persons().children().children()", PI_Read);

  while ( grand_children.Next() )

    printf("Name: %s, first name: %s",

           grand_children.GetString("name"),

           grand_children.GetString("first_name"));

// using property references

// produces the same same result as the example above

  Property          persons(obh, "Person::Persons", PI_Read);

  Property          children(&persons, "children");

  Property          grand_children(&children, "children");

  while ( persons.next() )

    while ( children.next() )

      while ( grand_children.next() )

        printf("Name: %s, first name: %s",

               grand_children.value("name").toString(),

               grand_children.value("first_name").toString());

// OSI expression

void Person::Test()

{

VARIABLES

  set<Person>  &grand_children &= Person::Persons().children().children();

PROCESS

  while ( grand_children.Next )

    ::Message("Name: " + name + ", first name: " + first_name);

}