adayaml_0.3.0_ab19e387/src/implementation/yaml-dom-node_memory.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
--  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_Sets;
private with System.Storage_Elements;
with Yaml.Dom.Node;

private package Yaml.Dom.Node_Memory is
   type Instance is tagged limited private;

   procedure Visit (Object : in out Instance;
                    Value  : not null access constant Node.Instance;
                    Previously_Visited : out Boolean);

   procedure Forget (Object : in out Instance;
                     Value  : not null access constant Node.Instance);

   function Pop_First (Object : in out Instance)
                       return not null access Node.Instance;

   function Is_Empty (Object : Instance) return Boolean;

   type Pair_Instance is tagged limited private;

   procedure Visit (Object : in out Pair_Instance;
                    Left, Right : not null access Node.Instance;
                    Previously_Visited : out Boolean);
private
   function Hash (Value : Node_Pointer) return Ada.Containers.Hash_Type is
     (Ada.Containers.Hash_Type'Mod (System.Storage_Elements.To_Integer (Value.all'Address)));

   package Pointer_Sets is new Ada.Containers.Indefinite_Hashed_Sets
     (Node_Pointer, Hash, Dom."=");

   type Instance is tagged limited record
      Data : Pointer_Sets.Set;
   end record;

   type Pointer_Pair is record
      Left, Right : not null access Node.Instance;
   end record;

   use type Ada.Containers.Hash_Type;

   function Hash (Value : Pointer_Pair) return Ada.Containers.Hash_Type is
     (Hash (Value.Left) xor Hash (Value.Right));

   function Equal_Nodes (Left, Right : Node_Pointer) return Boolean is
     (Left = Right or else Node."=" (Left.all, Right.all));

   function "=" (Left, Right : Pointer_Pair) return Boolean is
     (Equal_Nodes (Left.Left, Right.Left) and then
      Equal_Nodes (Left.Right, Right.Right));

   package Pair_Sets is new Ada.Containers.Indefinite_Hashed_Sets
     (Pointer_Pair, Hash, Node_Memory."=", Node_Memory."=");

   type Pair_Instance is tagged limited record
      Data : Pair_Sets.Set;
   end record;
end Yaml.Dom.Node_Memory;