asn1_iterators-generic_iterator.ads 1.44 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 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
        record
            Item: Actual_Iterable;
        end record
        with Default_Iterator  => Iterate,
             Iterator_Element  => ASN1_Type,
             Constant_Indexing => Element;

    type Cursor is access all Generic_Iterator_Type;

    function Element (Self : Generic_Iterator_Type;
                      Ptr  : Cursor) return ASN1_Type is (Ptr.Item.Element);

    function Has_Element (Ptr : Cursor) return Boolean is
        (ASN1_Iterable.Has_Element(ASN1_Iterable.Iterable'Class(Ptr.all.Item)));

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

    type Iterator is new Iterators.Forward_Iterator with record
        Ptr : Cursor;
    end record;

34 35
    --overriding
    --procedure Initialize (Self: in out Generic_Iterator_Type);
36 37 38 39 40 41 42 43 44 45 46 47 48

    overriding
    function First (Item : Iterator) return Cursor;

    overriding
    function Next  (Item : Iterator;
                    Ptr  : Cursor)
    return Cursor;

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

end;