Inspirel banner

Programming Distributed Systems with YAMI4

3.9.1 Ada

Iteration support is provided by an additional utility type called Parameter_Cursor, defined in the YAMI.Parameters package. Together with standard operations First, Has_Element, Next and additional Get_Entry for extracting the Parameter_Entry proxy, the cursor allows complete traversal over the whole collection.

A typical usage pattern could be similar to the following code that prints the names of all entries in the given parameters object:

declare
   C : Parameter_Cursor;
   E : Parameter_Entry;
begin
   C := Params.First;
   while Has_Element (C) loop
      E := Get_Element (C);

      Put_Line (Entry_Name (E));

      Next (C);
   end loop;
end;

An alternative way to discover the end of iteration is to compare the cursor value with the predefined No_Parameter value:

   C := Params.First;
   while C /= No_Parameter loop
      --  ...

      Next (C);
   end loop;

Note:

Individual entries can be modified during the iteration, but they should not be added nor removed from the collection while the iteration is in progress.

The size of the whole collection can be always obtained with the Length function of the parameters object.