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

with Ada.Finalization;
use Ada.Finalization;

with ASN1_Iterators.Generic_Basic;
7
with ASN1_Iterators.SimpleTypes;
8 9

generic
Maxime Perrotin's avatar
Maxime Perrotin committed
10
   with package P is new Generic_Basic (<>);
11 12
package ASN1_Iterators.Generic_Fixed_SeqOf is

Maxime Perrotin's avatar
Maxime Perrotin committed
13 14 15 16 17 18 19
   type DataArray is array (natural range <>) of P.Sort;

   type SeqOf (Max : Natural) is record
      Length : Integer;
      Data   : DataArray (1 .. Max);
   end record;

20
   type Cursor;
Maxime Perrotin's avatar
Maxime Perrotin committed
21 22 23 24 25 26 27 28 29 30 31 32 33
   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
34 35 36 37
      with Default_Iterator  => Iterate,
           Iterator_Element  => SeqOf,
           Constant_Indexing => Element_SeqOf_Value;

38
   type Cursor is access all ASN1_SeqOf;
39

Maxime Perrotin's avatar
Maxime Perrotin committed
40 41
   --  Constructor (called automatically)
   procedure Initialize (Self : in out ASN1_SeqOf);
42

43
   function Has_Element_SeqOf (Position : Cursor) return Boolean;
44

Maxime Perrotin's avatar
Maxime Perrotin committed
45
   package Iterators_SeqOf is
46
      new Ada.Iterator_Interfaces (Cursor, Has_Element_SeqOf);
47

Maxime Perrotin's avatar
Maxime Perrotin committed
48
   type ASN1_SeqOf_It is new Iterators_SeqOf.Forward_Iterator with record
49
      Position : Cursor;
Maxime Perrotin's avatar
Maxime Perrotin committed
50
   end record;
51

52
   overriding function First (Item : ASN1_SeqOf_It)  return Cursor;
Maxime Perrotin's avatar
Maxime Perrotin committed
53
   overriding function Next  (Item : ASN1_SeqOf_It;
54
                              Position  : Cursor) return Cursor;
55

Maxime Perrotin's avatar
Maxime Perrotin committed
56 57
   function Iterate (self : ASN1_SeqOf)
      return ASN1_SeqOf_It'Class;
58

Maxime Perrotin's avatar
Maxime Perrotin committed
59
   function Element_SeqOf_Value (Self : ASN1_SeqOf;
60
                                 Position  : Cursor)
Maxime Perrotin's avatar
Maxime Perrotin committed
61 62
      return SeqOf is (self.Value);
end ASN1_Iterators.Generic_Fixed_SeqOf;