adayaml_0.3.0_ab19e387/src/interface/yaml-dom-mapping_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
--  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_Hashed_Maps;

package Yaml.Dom.Mapping_Data is
   type Instance is tagged limited private
     with Constant_Indexing => Element;

   type Cursor is private;

   function Length (Object : Instance) return Count_Type;

   function Is_Empty (Container : Instance) return Boolean;

   procedure Clear (Container : in out Instance);

   function Has_Element (Position : Cursor) return Boolean;

   function First (Object : Instance) return Cursor;

   function Next (Position : Cursor) return Cursor;

   procedure Iterate (Object : Instance;
                      Process : not null access procedure
                        (Key, Value : not null access Node.Instance));

   function Key (Position : Cursor) return Node_Reference
     with Pre => Has_Element (Position);

   function Value (Position : Cursor) return Node_Reference
     with Pre => Has_Element (Position);

   function Find (Object : Instance; Key : Node_Reference) return Cursor;

   function Element (Object : Instance; Key : Node_Reference)
                     return Node_Reference;

   --  convenience method for retrieving values of keys that are !!str scalars.
   --  the key value is given as String.
   function Element (Object : Instance; Key : String) return Node_Reference;

   procedure Insert (Container : in out Instance;
                     Key       : in     Node_Reference;
                     New_Item  : in     Node_Reference;
                     Position  :    out Cursor;
                     Inserted  :    out Boolean);

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

   procedure Include (Container : in out Instance;
                      Key       : in     Node_Reference;
                      New_Item  : in     Node_Reference);

   procedure Replace (Container : in out Instance;
                      Key       : in     Node_Reference;
                      New_Item  : in     Node_Reference);

   procedure Exclude (Container : in out Instance;
                      Key       : in     Node_Reference);

   procedure Delete (Container : in out Instance;
                     Key       : in     Node_Reference);

   procedure Delete (Container : in out Instance;
                     Position  : in out Cursor);

   No_Element : constant Cursor;
private
   function Hash (Object : Node_Pointer) return Ada.Containers.Hash_Type;

   package Node_Maps is new Ada.Containers.Indefinite_Hashed_Maps
     (Node_Pointer, Node_Pointer, Hash, Dom."=", Dom."=");

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

   type Cursor is record
      Container : access Instance;
      Position  : Node_Maps.Cursor;
   end record;

   No_Element : constant Cursor := (Container => null,
                                    Position => Node_Maps.No_Element);

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

      procedure Raw_Insert (Container  : in out Instance;
                            Key, Value : not null access Node.Instance)
        with Export, Convention => Ada,
        Link_Name => "AdaYaml__Mapping_Data__Raw_Insert";
   end Friend_Interface;
end Yaml.Dom.Mapping_Data;