adayaml_0.3.0_ab19e387/src/implementation/yaml-events.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
--  part of AdaYaml, (c) 2017 Felix Krause
--  released under the terms of the MIT license, see the file "copying.txt"

with Ada.Unchecked_Deallocation;

package body Yaml.Events is
   procedure Free is new Ada.Unchecked_Deallocation
     (Event_Array, Event_Array_Access);

   procedure Finalize (Object : in out Event_Holder) is
      Ptr : Event_Array_Access := Object.Data;
   begin
      Free (Ptr);
   end Finalize;

   procedure Copy_Data (Source : Event_Holder;
                        Target : not null Event_Array_Access) is
   begin
      Target (Target.all'First .. Target.all'First + Source.Data.all'Length - 1)
        := Source.Data.all;
   end Copy_Data;

   procedure Grow (Object : in out Event_Holder'Class) is
      New_Data : constant not null Event_Array_Access := new Event_Array
        (1 .. Object.Data.all'Length * 2);
      Old_Data : Event_Array_Access := Object.Data;
   begin
      Object.Copy_Data (New_Data); --  dispatches
      Object.Data := New_Data;
      Free (Old_Data);
   end Grow;
end Yaml.Events;