asn1_iterators-generic_fixed_seqof.ads 1.75 KB
Newer Older
1 2 3 4 5 6 7 8
with Ada.Iterator_Interfaces;

with Ada.Finalization;
use Ada.Finalization;

with ASN1_Iterators.Generic_Basic;

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

12
   type DataArray is array (natural range <>) of P.Sort;
13

14 15 16 17
   type SeqOf (Max : Natural) is record
      Length : Integer;
      Data   : DataArray (1 .. Max);
   end record;
18

19 20
   type ASN1_SeqOf_Ptr;
   type ASN1_SeqOf_It;
21

22 23
   type ASN1_SeqOf (Size : Natural) is new Controlled
   with record
24 25 26 27 28 29 30 31
      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;
32
   end record
33 34 35 36
      with Default_Iterator  => Iterate,
           Iterator_Element  => SeqOf,
           Constant_Indexing => Element_SeqOf_Value;

37
   type ASN1_SeqOf_Ptr is access all ASN1_SeqOf;
38

39 40
   --  Constructor (called automatically)
   procedure Initialize (Self : in out ASN1_SeqOf);
41

42
   function Has_Element_SeqOf (Ptr : ASN1_SeqOf_Ptr) return Boolean;
43

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

47 48 49
   type ASN1_SeqOf_It is new Iterators_SeqOf.Forward_Iterator with record
      Ptr : ASN1_SeqOf_Ptr;
   end record;
50

51 52
   overriding function First (Item : ASN1_SeqOf_It)  return ASN1_SeqOf_Ptr;
   overriding function Next  (Item : ASN1_SeqOf_It;
53 54
                               Ptr  : ASN1_SeqOf_Ptr) return ASN1_SeqOf_Ptr;

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

58 59 60
   function Element_SeqOf_Value (Self : ASN1_SeqOf;
                                 Ptr  : ASN1_SeqOf_Ptr)
      return SeqOf is (self.Value);
61
end;