agpl_1.0.0_b5da3320/src/tests/t020_bag.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
with Agpl.Containers.Bags;
with Text_Io; use Text_Io;
with Ada.Exceptions; use Ada.Exceptions;

procedure T020_Bag is
   package Char_Bag is new Agpl.Containers.Bags (Character, Integer, Initial_Size => 2);
   use Char_Bag;

   B : Object (First => 1);

   procedure Print (This : in Object) is
   begin
      for I in This.First .. This.Last loop
         Put (I'Img & ":" & This.Vector (I));
      end loop;
      New_Line;
   end Print;

   Flag : Boolean := True;

   procedure Moving (C        : in out Character;
                     Context  : in out Integer;
                     From, To : in Integer)
   is
      pragma Unreferenced (Context);
   begin
      Put_Line (C & ":" & From'Img & " ->" & To'Img);
      if Flag then
         B.Append ('f');
         B.Append ('g');
         B.Append ('h');
         Flag := False;
      end if;
   end Moving;

begin
   B.Append ('a'); B.Append ('b'); B.Append ('c'); B.Append ('d'); B.Append ('e');
   Print (B);
   B.Delete (2, Moving'Access);
   Print (B);
   B.Insert ('i', 2, Moving'Access);
   Print (B);
exception
   when E : others =>
      Put_Line ("Exception: " & Exception_Information (E));
end T020_Bag;