Commit 59f28dba authored by Maxime Perrotin's avatar Maxime Perrotin

Start working on sequence iterator

parent b32f46b5
......@@ -11,6 +11,11 @@ MyEnum ::= ENUMERATED { hello, world, how-are-you }
MySeqOfEnum ::= SEQUENCE (SIZE (3)) OF MyEnum
MySeq ::= SEQUENCE {
a MyInteger,
b MyEnum
--MyChoice ::= CHOICE {
-- choice-a MyInteger,
-- choice-b MySeqOf
with Ada.Unchecked_Conversion;
package body ASN1_Iterators.MySeq is
procedure Initialize (Self: in out ASN1_MySeq) is
-- Self.Value.a :=
-- Self.Value.b :=
function Has_Element_MySeq (Ptr: Cursor) return Boolean is
function Iterate (Self : ASN1_MySeq)
return ASN1_MySeq'Class is --Iterators_MySeq.Forward_Iterator'Class is
return I: ASN1_MySeq do
I.Ptr := Self'Unrestricted_Access;
end return;
function First (Item : ASN1_MySeq) return Cursor is
Ptr_Elem : P.Iterator_Ptr := P.Ptr (Item.Ptr.FirstIt);
-- 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,
if Item.Ptr.Length > 1 then
Item.Ptr.Value.Data (2 .. Item.Ptr.Length) :=
Item.Ptr.RestIt.Ptr.Value.Data (1 .. Item.Ptr.RestIt.Ptr.Length);
end if;
return Item.Ptr;
function Next (Item : ASN1_MySeq;
Ptr : Cursor) return Cursor is
pragma Unreferenced (Item);
Ptr_elem : P.Iterator_Ptr := P.Ptr (Ptr.FirstIt);
if Ptr.Length > 1 then
Ptr.RestIt.Ptr := Ptr.RestIt.Next (Ptr.RestIt.Ptr);
if Has_Element_MySeq (Ptr.RestIt.Ptr) then
Ptr.Value.Data (2 .. Ptr.Length) :=
Ptr.RestIt.Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Value.Length);
Ptr.RestIt.Ptr := Ptr.RestIt.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.RestIt.Ptr.Value.Data (1 .. Ptr.RestIt.Ptr.Length);
end if;
end if;
-- 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;
with Ada.Iterator_Interfaces;
with Ada.Finalization;
use Ada.Finalization;
with ASN1_Iterators.Generic_Basic;
with ASN1_Iterators.SimpleTypes;
with ASN1_Ada_Iterators.Iterators;
use ASN1_Ada_Iterators.Iterators;
with TASTE_DataView;
package ASN1_Iterators.MySeq is
package a_Pkg renames MyInteger.Pkg;
package b_Pkg renames MyEnum_Pkg;
type ASN1_MySeq_Ptr;
type ASN1_MySeq_It;
type ASN1_MySeq is new Controlled
with record
a_val : a_Pkg.It.Basic_ASN1_Iterator;
a_it : a_Pkg.It.Iterator;
b_val : b_Pkg.It.Basic_ASN1_Iterator;
b_i : B_Pkg.It.Iterator;
Value : asn1SccMySeq;
-- First value
-- FirstVal : P.Basic_ASN1_Iterator;
--FirstIt : P.Iterator;
end record
with Default_Iterator => Iterate,
Iterator_Element => asn1SccMySeq,
Constant_Indexing => Element_MySeq_Value;
type Cursor is access all ASN1_MySeq;
-- Constructor (called automatically)
procedure Initialize (Self : in out ASN1_MySeq);
function Has_Element_MySeq (Ptr : Cursor) return Boolean;
package Iterators_MySeq is
new Ada.Iterator_Interfaces (Cursor, Has_Element_MySeq);
type ASN1_MySeq_It is new Iterators_MySeq.Forward_Iterator with record
Ptr : Cursor;
end record;
overriding function First (Item : ASN1_MySeq_It) return Cursor;
overriding function Next (Item : ASN1_MySeq_It;
Ptr : Cursor) return Cursor;
function Iterate (self : ASN1_MySeq)
return ASN1_MySeq_It'Class; -- Iterators_SeqOf.Forward_Iterator'Class;
function Element_MySeq_Value (Self : ASN1_MySeq;
Ptr : Cursor)
return asn1SccMySeq is (self.Value);
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