asn1_iterators-iterable_seqof.ads 1.98 KB
Newer Older
1 2 3 4 5
with ASN1_Iterators.Iterable_Type,
     ASN1_Iterators.Iterable_Integer,
     ASN1_Iterators.Generic_Iterator,
     Interfaces;
use Interfaces;
6 7

generic
8 9
    Min, Max: Integer_64;
    with package Element_Pkg is new ASN1_Iterators.Generic_Iterator (<>);
10 11
package ASN1_Iterators.Iterable_SeqOF is

12 13 14
    type DataArray is array(Integer_64 range <>) of Element_Pkg.ASN1_Type;
    type Generic_SeqOf is record
      Length : Integer_64;
15 16 17 18 19
      Data   : DataArray (1..Max);
    end record;

    package SeqOf_Pkg is new ASN1_Iterators.Iterable_type (Generic_SeqOf);

20 21 22 23
    package Len_Iterator is new ASN1_Iterators.Iterable_Integer (Min, Max);

    type Instance;
    type Cust_Iterator;
24 25
    type ASN1_SequenceOf is new SeqOf_Pkg.Iterable
       with record
26
            Length   : Integer_64 := Min;
27
            -- Iterate on the length
28 29
            LenVal   : Len_Iterator.Instance;
            LenIt    : access Len_Iterator.Iterator;
30
            -- And on the value
31 32
            Rest     : access Instance;
            Rest_It  : access Cust_Iterator;
33 34 35 36 37 38 39 40 41
    end record;

    overriding
    procedure Initialize (It: in out ASN1_SequenceOf);

    overriding
    function Has_Element (It: ASN1_SequenceOf) return Boolean;

    overriding
42
    function First (It: in out ASN1_SequenceOf) return Generic_SeqOf;
43 44 45 46 47 48 49 50 51

    overriding
    function Next (It: ASN1_SequenceOf) return Generic_SeqOf;

    package Custom_Iterator is new ASN1_Iterators.Generic_Iterator
        (ASN1_Type       => Generic_SeqOf,
         ASN1_Iterable   => SeqOf_Pkg,
         Actual_Iterable => ASN1_SequenceOf);

52 53 54 55 56 57 58 59 60
    -- If it is needed to iterate manually, provide Cursor and Iterator:
    subtype Cursor   is Custom_Iterator.Cursor;
    type Instance is new Custom_Iterator.Generic_Iterator_Type with null record;
    subtype Iterator is Custom_Iterator.Iterators.Forward_Iterator'Class;
    type Cust_Iterator is new Custom_Iterator.Iterator with null record;

    function Has_Element (Ptr: Cursor) return Boolean
        renames Custom_Iterator.Has_Element;

61 62

end;