asn1_iterators-generic_seqof.ads 2.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
with Ada.Iterator_Interfaces;

with Ada.Finalization;
use Ada.Finalization;

with ASN1_Iterators.Generic_Fixed_SeqOF,
     ASN1_Iterators.Generic_Integer,
     ASN1_Iterators.Generic_Basic;

with Interfaces;
use Interfaces;

-- Iterator for a variable-size array of basic type
generic
    Min : Natural;
    Max : Natural;
    with package Basic is new Generic_Basic (<>);
package ASN1_Iterators.Generic_SeqOf is

    Package P is new Generic_Fixed_SeqOF (P => Basic);
    -- Create an integer type with a range constraint to iterate on
    package Length_ty is new Generic_Integer (Integer_64(Min),
                                              Integer_64(Max));
    -- Instantiate the package to iterate on the integer for the length
    package Length_Pkg renames Length_ty.It;

    type ASN1_Variable_SeqOf_Ptr is private;
    subtype MySeqOf is P.SeqOf(Max);
    type ASN1_Variable_SeqOf is new Controlled
    with record
        Length   : Natural := Min;
        Value    : MySeqOf; -- P.SeqOf(Max);
        -- Iterate on the length
        LenVal   : Length_ty.Instance;
        LenIt    : Length_Pkg.Iterator;
        -- And on the value
        RestVal  : access P.ASN1_SeqOf;
        RestIt   : access P.ASN1_SeqOf_It;
    end record
        with Default_Iterator  => Iterate,
             Iterator_Element  => MySeqOf, --P.SeqOf,
             Constant_Indexing => Element_Variable_SeqOf_Value;

    --  Constructor (called automatically)
    procedure Initialize(self: in out ASN1_Variable_SeqOf);

    function Has_Element_Variable_SeqOf (Ptr : ASN1_Variable_SeqOf_Ptr)
     return Boolean;

    package Iterators_Variable_SeqOf is
     new Ada.Iterator_Interfaces (ASN1_Variable_SeqOf_Ptr,
                                  Has_Element_Variable_SeqOf);

    type ASN1_Variable_SeqOf_It
     is new Iterators_Variable_SeqOf.Forward_Iterator with record
        Ptr : ASN1_Variable_SeqOf_Ptr;
    end record;

    overriding
    function First (Item : ASN1_Variable_SeqOf_It)
     return ASN1_Variable_SeqOf_Ptr;

    overriding
    function Next  (Item : ASN1_Variable_SeqOf_It;
                    Ptr  : ASN1_Variable_SeqOf_Ptr)
     return ASN1_Variable_SeqOf_Ptr;

    function Iterate (self : ASN1_Variable_SeqOf)
     return Iterators_Variable_SeqOf.Forward_Iterator'Class;

    function Element_Variable_SeqOf_Value (Self : ASN1_Variable_SeqOf;
                                           Ptr  : ASN1_Variable_SeqOf_Ptr)
     --return P.SeqOf is (Self.Value);
     return MySeqOf is (Self.Value);

    subtype Instance is ASN1_Variable_SeqOf;

    private
    type ASN1_Variable_SeqOf_Ptr is access all ASN1_Variable_SeqOf;

end;