Commit 4c18a8f1 authored by Maxime Perrotin's avatar Maxime Perrotin

Iterate on the iterators (work in progress)

parent e3be2a4d
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;
-- 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;
function First (Item : Iterator) return Cursor is
C: constant Cursor := Item.Ptr;
......
......@@ -9,7 +9,7 @@ generic
type Actual_Iterable is new ASN1_Iterable.Iterable with private;
package ASN1_Iterators.Generic_Iterator is
type Generic_Iterator_Type is new Controlled with
type Generic_Iterator_Type is tagged --new Controlled with
record
Item: Actual_Iterable;
end record
......@@ -31,8 +31,8 @@ package ASN1_Iterators.Generic_Iterator is
Ptr : Cursor;
end record;
overriding
procedure Initialize (Self: in out Generic_Iterator_Type);
--overriding
--procedure Initialize (Self: in out Generic_Iterator_Type);
overriding
function First (Item : Iterator) return Cursor;
......
......@@ -18,7 +18,7 @@ package ASN1_Iterators.Iterable_Integer is
(It.Value <= Max);
overriding
function First (It: ASN1_Integer) return Integer_64 is
function First (It: in out ASN1_Integer) return Integer_64 is
(Min);
overriding
......
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Iterator_Interfaces;
package body ASN1_Iterators.Iterable_SeqOF is
procedure Initialize (It: in out ASN1_SequenceOf) is
begin
Put_Line ("Initialize Iterable_SeqOF length " & It.Length'Img);
It.Value.Length := It.Length;
if It.Length > 1 then
It.Rest := new Instance; -- not initialized
It.Rest.Item.Length := It.Length - 1;
It.Rest_It := new Cust_Iterator'(Cust_Iterator(It.Rest.Iterate));
It.Rest_It.Ptr := It.Rest_It.First;
end if;
null;
-- deprecated
end;
function Has_Element (It: ASN1_SequenceOf) return Boolean is
......@@ -21,13 +16,26 @@ package body ASN1_Iterators.Iterable_SeqOF is
return False;
end;
function First (It: ASN1_SequenceOf) return Generic_SeqOf is
function First (It: in out ASN1_SequenceOf) return Generic_SeqOf is
-- Ptr_elem : P.Iterator_Ptr := P.Ptr(Item.Ptr.FirstIt);
Temp : constant Generic_SeqOf := It.Value;
Ret : constant Generic_SeqOf := It.Value;
begin
It.Value.Length := It.Length;
Put_Line ("Computing first of length " & It.Length'Img);
-- Initialize the recursive structure (once)
if It.Length > 1 and then It.Rest = Null then
Put_Line ("Initialize Length " & It.Length'Img);
It.Rest := new Instance;
It.Rest.Item.Length := It.Length - 1;
It.Rest_It :=
new Cust_Iterator'(Custom_Iterator.Iterator (It.Rest.Iterate)
with others => <>);
It.Rest_It.Ptr := It.Rest_It.First;
end if;
-- 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
......@@ -35,7 +43,7 @@ package body ASN1_Iterators.Iterable_SeqOF is
-- Item.Ptr.Rest_It.Ptr.Value.Data(1..Item.Ptr.Rest_It.Ptr.Length);
-- end if;
-- return Item.Ptr;
return Temp;
return Ret;
end;
function Next (It: ASN1_SequenceOf) return Generic_SeqOf is
......
......@@ -39,7 +39,7 @@ package ASN1_Iterators.Iterable_SeqOF is
function Has_Element (It: ASN1_SequenceOf) return Boolean;
overriding
function First (It: ASN1_SequenceOf) return Generic_SeqOf;
function First (It: in out ASN1_SequenceOf) return Generic_SeqOf;
overriding
function Next (It: ASN1_SequenceOf) return Generic_SeqOf;
......
......@@ -19,7 +19,7 @@ package ASN1_Iterators.Iterable_Type is
function Has_Element (It: Iterable) return boolean is abstract;
function First (It: Iterable) return Element_Type is abstract;
function First (It: in out Iterable) return Element_Type is abstract;
function Next (It: Iterable) return Element_Type is abstract;
end;
......@@ -12,8 +12,10 @@ procedure test_new_iterators is
C: MyInt.Cursor;
-- SEQUENCE OF
package MySeqOf is new ASN1_Iterators.Iterable_SeqOF (1, 3, MyInt.Custom_Iterator);
package MySeqOf is new ASN1_Iterators.Iterable_SeqOF (3, 5, MyInt.Custom_Iterator);
ItSO : MySeqOf.Instance;
IterSO : MySeqOf.Iterator := ItSO.Iterate;
CSO : MySeqOf.Cursor;
begin
Put_Line ("Hello");
Put_Line ("With 'for each of':");
......@@ -31,4 +33,10 @@ begin
Put_Line (It.Element (C)'Img);
C := Iter.Next (C);
end loop;
Put_Line ("SeqOF manual iterators:");
CSO := IterSO.First;
while MySeqOf.Has_Element (CSO) loop
Put_Line ("Element"); -- ItSO.Element (CSO)'Img);
CSO := IterSO.Next (CSO);
end loop;
end;
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