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
150 | with Yaml.Dom.Node;
package body Yaml.Dom.Mapping_Data is
function Hash (Object : Node_Pointer) return Ada.Containers.Hash_Type is
(Node.Hash (Object.all));
function Length (Object : Instance) return Count_Type is
(Object.Data.Length);
function Is_Empty (Container : Instance) return Boolean is
(Container.Data.Is_Empty);
procedure Clear (Container : in out Instance) is
begin
Container.Data.Clear;
end Clear;
function Has_Element (Position : Cursor) return Boolean is
(Position.Container /= null and then
Node_Maps.Has_Element (Position.Position));
function First (Object : Instance) return Cursor is
((Container => Object'Unrestricted_Access,
Position => Object.Data.First));
function Next (Position : Cursor) return Cursor is
((Container => Position.Container,
Position => Node_Maps.Next (Position.Position)));
procedure Iterate (Object : Instance;
Process : not null access procedure
(Key, Value : not null access Node.Instance)) is
Cur : Node_Maps.Cursor := Object.Data.First;
begin
while Node_Maps.Has_Element (Cur) loop
Process.all (Node_Maps.Key (Cur), Node_Maps.Element (Cur));
Cur := Node_Maps.Next (Cur);
end loop;
end Iterate;
function Key (Position : Cursor) return Node_Reference is
begin
Increase_Refcount (Position.Container.Document);
return ((Ada.Finalization.Controlled with
Data => Node_Maps.Key (Position.Position),
Document => Position.Container.Document));
end Key;
function Value (Position : Cursor) return Node_Reference is
begin
Increase_Refcount (Position.Container.Document);
return ((Ada.Finalization.Controlled with
Data => Node_Maps.Element (Position.Position),
Document => Position.Container.Document));
end Value;
function Find (Object : Instance; Key : Node_Reference) return Cursor is
Found : constant Node_Maps.Cursor := Object.Data.Find (Key.Value.Data);
begin
return (Container => Object'Unrestricted_Access, Position => Found);
end Find;
function Element (Object : Instance; Key : Node_Reference)
return Node_Reference is
Found : constant Node_Maps.Cursor := Object.Data.Find (Key.Value.Data);
begin
if Node_Maps.Has_Element (Found) then
Increase_Refcount (Object.Document);
return (Ada.Finalization.Controlled with
Data => Node_Maps.Element (Found),
Document => Object.Document);
else
raise Constraint_Error with "No such key";
end if;
end Element;
function Element (Object : Instance; Key : String) return Node_Reference is
Holder : constant Text.Constant_Instance := Text.Hold (Key);
As_Node : aliased Node.Instance := (Kind => Scalar, Tag => Tags.String,
Content => Text.Held (Holder),
Scalar_Style => Any);
begin
Increase_Refcount (Object.Document);
return Object.Element (Node_Reference'(Ada.Finalization.Controlled with
Data => As_Node'Unrestricted_Access,
Document => Object.Document));
end Element;
procedure Insert (Container : in out Instance;
Key : in Node_Reference;
New_Item : in Node_Reference;
Position : out Cursor;
Inserted : out Boolean) is
begin
Position.Container := Container'Unrestricted_Access;
Container.Data.Insert (Key.Data, New_Item.Data, Position.Position,
Inserted);
end Insert;
procedure Insert (Container : in out Instance;
Key : in Node_Reference;
New_Item : in Node_Reference) is
begin
Container.Data.Insert (Key.Data, New_Item.Data);
end Insert;
procedure Include (Container : in out Instance;
Key : in Node_Reference;
New_Item : in Node_Reference) is
begin
Container.Data.Include (Key.Data, New_Item.Data);
end Include;
procedure Replace (Container : in out Instance;
Key : in Node_Reference;
New_Item : in Node_Reference) is
begin
Container.Data.Replace (Key.Data, New_Item.Data);
end Replace;
procedure Exclude (Container : in out Instance;
Key : in Node_Reference) is
begin
Container.Data.Exclude (Key.Data);
end Exclude;
procedure Delete (Container : in out Instance;
Key : in Node_Reference) is
begin
Container.Data.Delete (Key.Data);
end Delete;
procedure Delete (Container : in out Instance;
Position : in out Cursor) is
begin
Container.Data.Delete (Position.Position);
end Delete;
package body Friend_Interface is
function For_Document (Document : not null access Document_Instance)
return Instance is
(Document => Document, Data => <>);
procedure Raw_Insert (Container : in out Instance;
Key, Value : not null access Node.Instance) is
begin
Container.Data.Insert (Key, Value);
end Raw_Insert;
end Friend_Interface;
end Yaml.Dom.Mapping_Data;
|