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

private with Ada.Containers.Hashed_Maps;

package Yaml.Events.Store is
   type Instance is limited new Refcount_Base with private;
   type Reference is tagged private;
   type Optional_Reference is tagged private;

   type Accessor (Data : not null access Instance) is limited null record with
     Implicit_Dereference => Data;

   type Anchor_Cursor is private;
   type Element_Cursor is private;

   function New_Store return Reference;
   function Value (Object : Reference) return Accessor;

   Null_Reference : constant Optional_Reference;

   function Value (Object : Optional_Reference) return Accessor with
     Pre => Object /= Null_Reference;

   function Optional (Object : Reference'Class) return Optional_Reference;
   function Required (Object : Optional_Reference'Class) return Reference;

   procedure Memorize (Object : in out Instance; Item : Event);
   procedure Force_Memorize (Object : in out Instance; Item : Event;
                             Position : out Element_Cursor);

   function Find (Object : Instance; Alias : Text.Reference)
                  return Anchor_Cursor;
   function Exists_In_Output (Position : Anchor_Cursor) return Boolean;
   procedure Set_Exists_In_Output (Object : in out Instance;
                                   Position : Anchor_Cursor);
   procedure Advance (Position : in out Element_Cursor);
   procedure Advance_At_Same_Level (Object : Instance;
                                    Position : in out Element_Cursor);

   No_Anchor : constant Anchor_Cursor;
   No_Element : constant Element_Cursor;

   procedure Clear (Object : in out Instance);
   procedure Copy (Source : in Instance; Target : in out Instance);

   type Stream_Instance is limited new Refcount_Base with private;
   type Stream_Reference is tagged private;
   type Optional_Stream_Reference is tagged private;
   type Stream_Accessor (Data : not null access Stream_Instance) is limited
     null record with Implicit_Dereference => Data;

   function Value (Object : Stream_Reference) return Stream_Accessor;
   function Next (Object : in out Stream_Instance) return Event;

   function Exists (Object : Optional_Stream_Reference) return Boolean;
   function Value (Object : Optional_Stream_Reference) return Stream_Accessor
     with Pre => Object.Exists;

   function Optional (Object : Stream_Reference'Class)
                      return Optional_Stream_Reference with
     Post => Optional'Result.Exists;

   procedure Clear (Object : in out Optional_Stream_Reference) with
     Post => not Object.Exists;

   function First (Object : Instance; Position : Anchor_Cursor) return Event;

   function Element (Object : Instance;
                     Position : Element_Cursor) return Event;

   function Retrieve (Object : Reference'Class;
                      Position : Anchor_Cursor) return Stream_Reference
     with Pre => Position /= No_Anchor;
   function Retrieve (Object : Reference'Class;
                      Position : Element_Cursor) return Stream_Reference
     with Pre => Position /= No_Element;

   function To_Element_Cursor (Position : Anchor_Cursor) return Element_Cursor;
private
   type Anchor_Info is record
      Position : Positive;
      Has_Been_Output : Boolean;
   end record;

   package Anchor_To_Index is new Ada.Containers.Hashed_Maps
     (Text.Reference, Anchor_Info, Text.Hash, Text."=");

   type Anchor_Cursor is new Anchor_To_Index.Cursor;
   type Element_Cursor is new Natural;
   subtype Depth_Type is Integer with Static_Predicate =>
     Depth_Type = Integer'First or Depth_Type >= 0;

   After_Annotation_End : constant Depth_Type := Integer'First;

   type Instance is limited new Event_Holder with record
      Anchor_Map : Anchor_To_Index.Map;
      Stream_Count : Natural := 0;
      Depth : Depth_Type := 0;
   end record;

   type Reference is new Ada.Finalization.Controlled with record
      Data : not null access Instance;
   end record;

   overriding procedure Adjust (Object : in out Reference);
   overriding procedure Finalize (Object : in out Reference);

   type Optional_Reference is new Ada.Finalization.Controlled with record
      Data : access Instance;
   end record;

   overriding procedure Adjust (Object : in out Optional_Reference);
   overriding procedure Finalize (Object : in out Optional_Reference);

   Null_Reference : constant Optional_Reference :=
     (Ada.Finalization.Controlled with Data => null);

   No_Anchor : constant Anchor_Cursor :=
     Anchor_Cursor (Anchor_To_Index.No_Element);
   No_Element : constant Element_Cursor := 0;

   type Stream_Instance is limited new Refcount_Base with record
      Object  : Reference;
      Depth   : Natural;
      Current : Positive;
   end record;

   overriding procedure Finalize (Object : in out Stream_Instance);

   type Stream_Reference is new Ada.Finalization.Controlled with record
      Data : not null access Stream_Instance;
   end record;

   overriding procedure Adjust (Object : in out Stream_Reference);
   overriding procedure Finalize (Object : in out Stream_Reference);

   type Optional_Stream_Reference is new Ada.Finalization.Controlled with record
      Data : access Stream_Instance;
   end record;

   overriding procedure Adjust (Object : in out Optional_Stream_Reference);
   overriding procedure Finalize (Object : in out Optional_Stream_Reference);
end Yaml.Events.Store;