asn1_iterators-generic_iterator.ads 1.45 KB
Newer Older
1 2 3 4 5 6
with Ada.Iterator_Interfaces,
     Ada.Finalization,
     ASN1_Iterators.Iterable_Type;
use Ada.Finalization;

generic
7
    type ASN1_Type is private;
8 9 10 11
    with package ASN1_Iterable is new ASN1_Iterators.Iterable_Type (ASN1_Type);
    type Actual_Iterable is new ASN1_Iterable.Iterable with private;
package ASN1_Iterators.Generic_Iterator is

12
    type Generic_Iterator_Type is tagged --new Controlled with
13 14 15 16 17
        record
            Item: Actual_Iterable;
        end record
        with Default_Iterator  => Iterate,
             Iterator_Element  => ASN1_Type,
18
             Constant_Indexing => Elem;
19 20 21

    type Cursor is access all Generic_Iterator_Type;

22 23
    function Elem (Self : Generic_Iterator_Type; Position : Cursor)
       return ASN1_Type is (Position.Item.Element);
24

25 26
    function Has_Element (Position : Cursor) return Boolean is
        (ASN1_Iterable.Has_Element(ASN1_Iterable.Iterable'Class(Position.all.Item)));
27 28 29 30

    package Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element);

    type Iterator is new Iterators.Forward_Iterator with record
31
        Position : Cursor;
32 33
    end record;

34 35
    --overriding
    --procedure Initialize (Self: in out Generic_Iterator_Type);
36 37 38 39 40 41

    overriding
    function First (Item : Iterator) return Cursor;

    overriding
    function Next  (Item : Iterator;
42
                    Position  : Cursor)
43 44 45 46 47 48
    return Cursor;

    function Iterate (self : Generic_Iterator_Type)
    return Iterators.Forward_Iterator'Class;

end;