asn1_iterators-generic_fixed_seqof.ads 1.77 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
with Ada.Iterator_Interfaces;

with Ada.Finalization;
use Ada.Finalization;

with ASN1_Iterators.Generic_Basic;

generic
    with package P is new Generic_Basic (<>);
package ASN1_Iterators.Generic_Fixed_SeqOf is

    type DataArray is array(natural range <>) of P.Element;
    type SeqOf (Max: Natural) is record
      Length : Integer;
      Data   : DataArray(1..Max);
    end record;

    type ASN1_SeqOf_Ptr;
    type ASN1_SeqOf_It;
    type ASN1_SeqOf (Size: Natural) is new Controlled
    with record
      Length   : Natural := Size;
      Value    : SeqOf (Size);
      -- First value
      FirstVal : P.Basic_ASN1_Iterator;
      FirstIt  : P.Iterator;
      -- The rest (recursive)
      Rest     : access ASN1_SeqOf;
      RestIt   : access ASN1_SeqOf_It;
    end record
      with Default_Iterator  => Iterate,
           Iterator_Element  => SeqOf,
           Constant_Indexing => Element_SeqOf_Value;

    type ASN1_SeqOf_Ptr is access all ASN1_SeqOf;

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

    function Has_Element_SeqOf (Ptr : ASN1_SeqOf_Ptr) return Boolean;

    package Iterators_SeqOf is
      new Ada.Iterator_Interfaces (ASN1_SeqOf_Ptr, Has_Element_SeqOf);

    type ASN1_SeqOf_It is new Iterators_SeqOf.Forward_Iterator with record
      Ptr : ASN1_SeqOf_Ptr;
    end record;

    overriding function First (Item : ASN1_SeqOf_It)  return ASN1_SeqOf_Ptr;
    overriding function Next  (Item : ASN1_SeqOf_It;
                               Ptr  : ASN1_SeqOf_Ptr) return ASN1_SeqOf_Ptr;

    function Iterate (self : ASN1_SeqOf)
      return Iterators_SeqOf.Forward_Iterator'Class;

    function Element_SeqOf_Value (self : ASN1_SeqOf;
                                  Ptr  : ASN1_SeqOf_Ptr)
      return SeqOf is (self.Value);


end;