generic_seqof.ads 2.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
with Ada.Iterator_Interfaces;

with Ada.Finalization;
use Ada.Finalization;

with generic_fixed_seqof;
with generic_integer;
with generic_basic;

Maxime Perrotin's avatar
Maxime Perrotin committed
10
11
12
with Interfaces;
use Interfaces;

13
14
-- Iterator for a variable-size array of basic type
generic
Maxime Perrotin's avatar
Maxime Perrotin committed
15
16
    Min : Natural;
    Max : Natural;
17
18
19
20
21
    with package Basic is new Generic_Basic (<>);
package Generic_SeqOf is

    Package P is new Generic_Fixed_SeqOF (P => Basic);
    -- Create an integer type with a range constraint to iterate on
Maxime Perrotin's avatar
Maxime Perrotin committed
22
23
    package Length_ty is new Generic_Integer (Integer_64(Min),
                                              Integer_64(Max));
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
    -- 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;