asn1_iterators-generic_seqof.adb 2.73 KB
Newer Older
1 2 3 4 5 6 7
package body ASN1_Iterators.Generic_SeqOf is

    procedure Initialize (self: in out ASN1_Variable_SeqOf) is
    begin
      self.value.length := self.length;
      if self.length >= 1 then
          self.RestVal := new P.ASN1_SeqOf(Self.Length);
8 9
          self.RestIt  :=
             new P.ASN1_SeqOf_It'(P.ASN1_SeqOf_It(Self.RestVal.Iterate));
10
          self.RestIt.Position := self.RestIt.First;
11 12 13
      end if;
    end;

14 15 16 17
   function Has_Element_Variable_SeqOf
       (Position : Cursor)
     return Boolean is
       (Length_Pkg.Has_Element(Length_Pkg.Get_Cursor (Position.LenIt)));
18 19 20 21 22

    function Iterate (self : ASN1_Variable_SeqOf)
      return Iterators_Variable_SeqOf.Forward_Iterator'Class is
    begin
     return I: ASN1_Variable_SeqOf_It do
23
         I.Position := Self'Unrestricted_Access;
24 25 26
     end return;
    end;

27
    function First (Item : ASN1_Variable_SeqOf_It)
28
       return Cursor is
29 30
    begin
      -- Initialize the iterator (Compute first value)
31 32
      Item.Position.LenIt :=
          Length_Pkg.Iterator(Item.Position.LenVal.Iterate);
33 34

      -- Copy only the actual size, since the arrays may be different in size
35 36 37 38
      Item.Position.Value.Data
          (1 .. Item.Position.RestIt.Position.Value.Data'Length) :=
         Item.Position.RestIt.Position.Value.Data;
      return Item.Position;
39 40
    end;

41 42 43 44 45 46 47 48 49 50 51 52 53
   function Next (Item      : ASN1_Variable_SeqOf_It;
                  Position  : Cursor)
      return Cursor
   is
      pragma Unreferenced (Item);
      Position_elem : Length_Pkg.Cursor :=
          Length_Pkg.Get_Cursor (Position.LenIt);
   begin
      Position.RestIt.Position := Position.RestIt.Next (Position.RestIt.Position);
      if P.Has_Element_SeqOf (Position.RestIt.Position) then
         Position.Value.Data
              (1 .. Position.RestIt.Position.Value.Data'Length) :=
             Position.RestIt.Position.Value.Data;
54
      else
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
         Position.RestIt.Position := Position.RestIt.First;
         --  Exhausted "rest": iterate on the first item
         Position_elem := Position.LenIt.Next (Position_elem);
         if Length_Pkg.Has_Element (Position_elem) then
            Position.Value.Length := Integer (Position_Elem.Value.Value);
            Position.Length       := Position.Value.Length;
            Position.RestVal      := new P.ASN1_SeqOf(Position.Value.Length);
            Position.RestIt       :=
               new P.ASN1_SeqOf_It'(P.ASN1_SeqOf_It
                                      (Position.RestVal.Iterate));
            Position.RestIt.Position := Position.RestIt.First;
            Position.Value.Data
               (1 .. Position.RestIt.Position.Value.Data'Length) :=
                  Position.RestIt.Position.Value.Data;
         end if;
      end if;
   return Position;
   end;
end ASN1_Iterators.Generic_SeqOF;
74