Commit 49aaae94 authored by Maxime Perrotin's avatar Maxime Perrotin

Skeleton of new seqof iterables

parent d4bc42b8
......@@ -2,6 +2,7 @@ package body ASN1_Iterators.Generic_Iterator is
procedure Initialize (Self: in out Generic_Iterator_Type) is
begin
Self.Item.Initialize;
Self.Item.Value := ASN1_Iterable.First(ASN1_Iterable.Iterable'Class(Self.Item));
end;
......
......@@ -4,7 +4,7 @@ with Ada.Iterator_Interfaces,
use Ada.Finalization;
generic
type ASN1_Type is (<>);
type ASN1_Type is private;
with package ASN1_Iterable is new ASN1_Iterators.Iterable_Type (ASN1_Type);
type Actual_Iterable is new ASN1_Iterable.Iterable with private;
package ASN1_Iterators.Generic_Iterator is
......
......@@ -7,8 +7,11 @@ with ASN1_Iterators.Generic_Iterator;
generic
Min, Max: Integer_64;
package ASN1_Iterators.Iterable_Integer is
package Integer_Pkg is new ASN1_Iterators.Iterable_type (Integer_64);
type ASN1_Integer is new Integer_Pkg.Iterable with null record;
package Pkg is new ASN1_Iterators.Iterable_type (Integer_64);
type ASN1_Integer is new Pkg.Iterable with null record;
overriding
procedure Initialize (It: in out ASN1_Integer) is null;
overriding
function Has_Element (It: ASN1_Integer) return Boolean is
......@@ -24,7 +27,7 @@ package ASN1_Iterators.Iterable_Integer is
package Custom_Iterator is new ASN1_Iterators.Generic_Iterator
(ASN1_Type => Integer_64,
ASN1_Iterable => Integer_Pkg,
ASN1_Iterable => Pkg,
Actual_Iterable => ASN1_Integer);
subtype Instance is Custom_Iterator.Generic_Iterator_Type;
......
with Ada.Text_IO;
use Ada.Text_IO;
package body ASN1_Iterators.Iterable_SeqOF is
procedure Initialize (It: in out ASN1_SequenceOf) is
-- Rest_Init : Instance;
begin
Put_Line ("Initialize Iterable_SeqOF length " & It.Length'Img);
-- It.Value.Length := It.Length;
-- if It.Length > 1 then
-- Rest_Init.Item.Length := It.Length - 1;
-- It.Rest := new Instance'(Rest_Init);
-- It.Rest_It := new Cust_Iterator'(Cust_Iterator(It.Rest.Iterate));
-- It.Rest_It.Ptr := It.Rest_It.First;
-- end if;
end;
function Has_Element (It: ASN1_SequenceOf) return Boolean is
-- (P.Has_Element(P.Ptr(Ptr.FirstIt)));
begin
return False;
end;
function First (It: ASN1_SequenceOf) return Generic_SeqOf is
-- Ptr_elem : P.Iterator_Ptr := P.Ptr(Item.Ptr.FirstIt);
Temp : constant Generic_SeqOf := It.Value;
begin
-- Initialize the iterator (Compute first value)
-- Item.Ptr.FirstIt := P.Iterator(Item.Ptr.FirstVal.Iterate);
-- Ptr_elem := P.First(Item.Ptr.FirstIt);
-- Item.Ptr.Value.Data(1) := P.Elem_Value(Item.Ptr.FirstVal,
-- Ptr_elem);
-- if Item.Ptr.Length > 1 then
-- Item.Ptr.Value.Data(2 .. Item.Ptr.Length) :=
-- Item.Ptr.Rest_It.Ptr.Value.Data(1..Item.Ptr.Rest_It.Ptr.Length);
-- end if;
-- return Item.Ptr;
return Temp;
end;
function Next (It: ASN1_SequenceOf) return Generic_SeqOf is
--Ptr_elem : P.Iterator_Ptr := P.Ptr(Ptr.FirstIt);
Temp : constant Generic_SeqOf := It.Value;
begin
-- if Ptr.Length > 1 then
-- Ptr.Rest_It.Ptr := Ptr.Rest_It.Next (Ptr.Rest_It.Ptr);
-- if Has_Element_SeqOf (Ptr.Rest_It.Ptr) then
-- Ptr.Value.Data (2..Ptr.Length) :=
-- Ptr.Rest_It.Ptr.Value.Data (1..Ptr.Rest_It.Ptr.Value.Length);
-- else
-- Ptr.Rest_It.Ptr := Ptr.Rest_It.First;
-- -- Exhausted "rest": iterate on the first item
-- Ptr_elem := P.Next(Ptr.FirstIt, Ptr_elem);
-- if P.Has_Element (Ptr_elem) then
-- Ptr.Value.Data(1) := P.Elem_Value(Ptr.FirstVal, Ptr_elem);
-- Ptr.Value.Data(2..Ptr.Length) := Ptr.Rest_It.Ptr.Value.Data (1..Ptr.Rest_It.Ptr.Length);
-- end if;
-- end if;
-- else
-- -- Size is 0 or 1
-- Ptr_elem := P.Next(Ptr.FirstIt, Ptr_elem);
-- if P.Has_Element (Ptr_elem) then
-- Ptr.Value.Data(1) := P.Elem_Value(Ptr.FirstVal, Ptr_elem);
-- end if;
-- end if;
-- return Ptr;
return Temp;
end;
end;
with ASN1_Iterators.Iterable_Type;
use ASN1_Iterators.Iterable_Type;
with ASN1_Iterators.Iterable_Type,
ASN1_Iterators.Iterable_Integer,
ASN1_Iterators.Generic_Iterator,
Interfaces;
use Interfaces;
generic
Min, Max: Natural;
type Element_Iterable is new ASN1_Iterators.Iterable_type (<>);
Min, Max: Integer_64;
with package Element_Pkg is new ASN1_Iterators.Generic_Iterator (<>);
package ASN1_Iterators.Iterable_SeqOF is
type DataArray is array(natural range <>) of Element_Iterable;
type Generic_SeqOf (Max: Natural) is record
Length : Natural;
type DataArray is array(Integer_64 range <>) of Element_Pkg.ASN1_Type;
type Generic_SeqOf is record
Length : Integer_64;
Data : DataArray (1..Max);
end record;
package SeqOf_Pkg is new ASN1_Iterators.Iterable_type (Generic_SeqOf);
package Len_Iterator is new ASN1_Iterators.Iterable_Integer (Min, Max);
type Instance;
type Cust_Iterator;
type ASN1_SequenceOf is new SeqOf_Pkg.Iterable
with record
Length : Natural := Min;
Length : Integer_64 := Min;
-- Iterate on the length
-- LenVal : Length_ty.Instance;
-- LenIt : Length_Pkg.Iterator;
LenVal : Len_Iterator.Instance;
LenIt : access Len_Iterator.Iterator;
-- And on the value
-- RestVal : access P.ASN1_SeqOf;
-- RestIt : access P.ASN1_SeqOf_It;
Rest : access Instance;
Rest_It : access Cust_Iterator;
end record;
overriding
......@@ -42,6 +49,14 @@ package ASN1_Iterators.Iterable_SeqOF is
ASN1_Iterable => SeqOf_Pkg,
Actual_Iterable => ASN1_SequenceOf);
subtype SeqOf_Iterator is Custom_Iterator.Generic_Iterator_Type;
-- If it is needed to iterate manually, provide Cursor and Iterator:
subtype Cursor is Custom_Iterator.Cursor;
type Instance is new Custom_Iterator.Generic_Iterator_Type with null record;
subtype Iterator is Custom_Iterator.Iterators.Forward_Iterator'Class;
type Cust_Iterator is new Custom_Iterator.Iterator with null record;
function Has_Element (Ptr: Cursor) return Boolean
renames Custom_Iterator.Has_Element;
end;
with Ada.Finalization;
use Ada.Finalization;
-- Set up a generic type that has a Value field, and member functions
-- Element, Has_Element, First, and Next
-- Initialize, Element, Has_Element, First, and Next
generic
type Element_Type is (<>);
type Element_Type is private; --(<>);
package ASN1_Iterators.Iterable_Type is
type Iterable is abstract new Controlled
with record
type Iterable is abstract tagged -- Controlled
--with record
record
Value: Element_Type;
end record;
type Iterable_Cursor is access all Iterable;
procedure Initialize (It: in out Iterable) is abstract;
function Element (It : Iterable) return Element_Type
is (It.Value);
......
with ASN1_Iterators.Iterable_Integer,
ASN1_Iterators.Iterable_SeqOF,
Ada.Text_IO;
use ASN1_Iterators,
......@@ -9,6 +10,10 @@ procedure test_new_iterators is
It: MyInt.Instance;
Iter: MyInt.Iterator := It.Iterate;
C: MyInt.Cursor;
-- SEQUENCE OF
package MySeqOf is new ASN1_Iterators.Iterable_SeqOF (1, 3, MyInt.Custom_Iterator);
ItSO : MySeqOf.Instance;
begin
Put_Line ("Hello");
Put_Line ("With 'for each of':");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment