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

with Ada.Containers;
with Text.Pool;
with Yaml.Tags;

limited with Yaml.Dom.Node;

package Yaml.Dom is
   type Document_Reference is tagged private;

   type Node_Kind is (Scalar, Sequence, Mapping);

   type Node_Reference is tagged private;
   type Optional_Node_Reference is tagged private;
   type Accessor (Data : not null access Node.Instance) is limited private
     with Implicit_Dereference => Data;

   subtype Count_Type is Ada.Containers.Count_Type;

   No_Document : constant Document_Reference;
   No_Node     : constant Optional_Node_Reference;

   -----------------------------------------------------------------------------
   --                      constructors and comparators                       --
   -----------------------------------------------------------------------------

   --  uses the given pool for all text content
   function New_Document (Pool : Text.Pool.Reference :=
                            Text.Pool.With_Capacity (Text.Pool.Default_Size);
                          Implicit_Start, Implicit_End : Boolean := True)
                          return Document_Reference;

   function New_Scalar (Parent : Document_Reference'Class;
                        Content : String := "";
                        Tag : Text.Reference := Yaml.Tags.Question_Mark;
                        Style : Scalar_Style_Type := Any) return Node_Reference;

   function New_Scalar (Parent : Document_Reference'Class;
                        Content : Text.Reference;
                        Tag : Text.Reference := Yaml.Tags.Question_Mark;
                        Style : Scalar_Style_Type := Any) return Node_Reference;

   function New_Sequence (Parent : Document_Reference'Class;
                          Tag : Text.Reference := Yaml.Tags.Question_Mark;
                          Style : Collection_Style_Type := Any)
                          return Node_Reference;

   function New_Mapping (Parent : Document_Reference'Class;
                         Tag : Text.Reference := Yaml.Tags.Question_Mark;
                         Style : Collection_Style_Type := Any)
                         return Node_Reference;

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

   --  checks whether the content of two nodes is identical
   function "=" (Left, Right : Node_Reference) return Boolean;

   --  checks whether the two references reference the same node
   function Same_Node (Left, Right : Node_Reference) return Boolean;

   -----------------------------------------------------------------------------
   --                              data access                                --
   -----------------------------------------------------------------------------

   function Is_Empty (Object : Document_Reference) return Boolean;
   function Root (Object : Document_Reference'Class) return Node_Reference
     with Pre => not Is_Empty (Object);
   procedure Set_Root (Object : Document_Reference;
                       Value : Node_Reference'Class);
   procedure Set_Root (Object : Document_Reference;
                       Value : Optional_Node_Reference'Class);

   function Starts_Implicitly (Object : Document_Reference) return Boolean;
   function Ends_Implicitly (Object : Document_Reference) return Boolean;
   procedure Set_Representation_Hints (Object : Document_Reference;
                                       Implicit_Start, Implicit_End : Boolean);

   function Value (Object : Node_Reference) return Accessor;
   function Value (Object : Optional_Node_Reference) return Accessor;

   function Required (Object : Optional_Node_Reference'Class) return Node_Reference;
   function Optional (Object : Node_Reference'Class) return Optional_Node_Reference;

private
   type Node_Pointer is not null access all Node.Instance;

   function Nodes_Equal (Left, Right : access Node.Instance) return Boolean;

   type Document_Instance is new Refcount_Base with record
      Root_Node : access Node.Instance;
      Pool      : Text.Pool.Reference;
      Implicit_Start, Implicit_End : Boolean;
   end record;

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

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

   type Node_Reference is new Ada.Finalization.Controlled with record
      Data : Node_Pointer;
      Document : not null access Document_Instance;
   end record;

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

   type Optional_Node_Reference is new Ada.Finalization.Controlled with record
      Data : access Node.Instance;
      Document : access Document_Instance;
   end record;

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

   type Accessor (Data : not null access Node.Instance) is limited null record;

   No_Document : constant Document_Reference :=
     (Ada.Finalization.Controlled with Data =>
         new Document_Instance'(Refcount_Base with
        Root_Node =>  null, Pool => <>, Implicit_Start => True,
        Implicit_End => True));

   No_Node : constant Optional_Node_Reference :=
     (Ada.Finalization.Controlled with Data => null, Document => null);
end Yaml.Dom;