adayaml_0.3.0_ab19e387/src/interface/yaml-dom-sequence_data.ads

  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
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
--  part of AdaYaml, (c) 2017 Felix Krause
--  released under the terms of the MIT license, see the file "copying.txt"

private with Ada.Containers.Indefinite_Vectors;
with Ada.Iterator_Interfaces;

package Yaml.Dom.Sequence_Data is
   type Instance is tagged limited private
     with Default_Iterator => Iterate,
     Iterator_Element => Node_Reference,
     Constant_Indexing => Element;

   type Cursor is private;

   function "=" (Left, Right : Instance) return Boolean;

   function Capacity (Container : Instance) return Count_Type;

   procedure Reserve_Capacity (Container : in out Instance;
                               Capacity  : in     Count_Type);

   function Length (Object : Instance) return Count_Type;

   function Is_Empty (Container : Instance) return Boolean;

   procedure Clear (Container : in out Instance);

   function To_Cursor (Container : Instance;
                       Index     : Natural) return Cursor;

   function To_Index (Position  : Cursor) return Natural;

   function Has_Element (Position : Cursor) return Boolean;

   package Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element);

   procedure Iterate (Object : Instance;
                      Process : not null access procedure
                        (Item : not null access Node.Instance));

   function Iterate (Object : Instance)
                     return Iterators.Forward_Iterator'Class;

   function Element (Object : Instance; Index : Positive) return Node_Reference;
   function Element (Object : Instance; Position : Cursor) return Node_Reference
     with Pre => Has_Element (Position);

   procedure Replace_Element (Container : in out Instance;
                              Index     : in     Positive;
                              New_Item  : in     Node_Reference);

   procedure Replace_Element (Container : in out Instance;
                              Position  : in     Cursor;
                              New_Item  : in     Node_Reference);

   procedure Insert (Container : in out Instance;
                     Before    : in     Positive;
                     New_Item  : in     Node_Reference);

   procedure Insert (Container : in out Instance;
                     Before    : in     Cursor;
                     New_Item  : in     Node_Reference);

   procedure Insert (Container : in out Instance;
                     Before    : in     Cursor;
                     New_Item  : in     Node_Reference;
                     Position  :    out Cursor);

   procedure Prepend (Container : in out Instance;
                      New_Item  : in     Node_Reference);

   procedure Append (Container : in out Instance;
                     New_Item  : in     Node_Reference);

   procedure Delete (Container : in out Instance;
                     Index     : in     Positive;
                     Count     : in     Count_Type := 1);

   procedure Delete (Container : in out Instance;
                     Position  : in out Cursor;
                     Count     : in     Count_Type := 1);

   procedure Delete_First (Container : in out Instance;
                           Count     : in     Count_Type := 1);

   procedure Delete_Last (Container : in out Instance;
                          Count     : in     Count_Type := 1);

   procedure Reverse_Elements (Container : in out Instance);

   procedure Swap (Container : in out Instance;
                   I, J      : in     Positive);

   procedure Swap (Container : in out Instance;
                   I, J      : in     Cursor);

   function First_Index (Container : Instance) return Positive;

   function First (Container : Instance) return Cursor;

   function First_Element (Container : Instance) return Node_Reference;

   function Last_Index (Container : Instance) return Natural;

   function Last (Container : Instance) return Cursor;

   function Last_Element (Container : Instance) return Node_Reference;

   function Next (Position : Cursor) return Cursor;

   procedure Next (Position : in out Cursor);

   function Previous (Position : Cursor) return Cursor;

   procedure Previous (Position : in out Cursor);

   No_Element : constant Cursor;
private
   package Node_Vectors is new Ada.Containers.Indefinite_Vectors
     (Index_Type   => Positive,
      Element_Type => Node_Pointer);

   type Instance is tagged limited record
      Document : not null access Document_Instance;
      Data     : Node_Vectors.Vector;
   end record;

   type Cursor is record
      Container : access constant Instance;
      Index : Natural;
   end record;

   No_Element : constant Cursor := (Container => null, Index => 0);

   package Friend_Interface is
      --  these subprograms are used by other child packages of Yaml.Dom. Since
      --  they are not memory safe, they are hidden here from the library user,
      --  but made available via importing.

      function For_Document (Document : not null access Document_Instance)
                             return Instance with Export, Convention => Ada,
        Link_Name => "AdaYaml__Sequence_Data__For_Document";

      procedure Raw_Append (Container : in out Instance;
                            New_Item  : not null access Node.Instance)
        with Export, Convention => Ada,
        Link_Name => "AdaYaml__Sequence_Data__Raw_Append";
   end Friend_Interface;
end Yaml.Dom.Sequence_Data;