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 | --
-- Copyright (C) 2019-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--
with Ada.Iterator_Interfaces;
with GPR2.Containers;
private with Ada.Containers.Ordered_Sets;
package GPR2.Project.Source.Set is
type Object is tagged private
with Constant_Indexing => Constant_Reference,
Default_Iterator => Iterate,
Iterator_Element => Project.Source.Object;
type Cursor is private;
No_Element : constant Cursor;
function Is_Empty (Self : Object) return Boolean with Inline;
procedure Clear (Self : in out Object) with Inline;
function Length (Self : Object) return Containers.Count_Type with Inline;
procedure Include (Self : in out Object; Source : Project.Source.Object)
with Pre => Source.Is_Defined, Inline;
procedure Insert (Self : in out Object; Source : Project.Source.Object)
with Pre => Source.Is_Defined, Inline;
procedure Insert
(Self : in out Object;
Source : Project.Source.Object;
Position : out Cursor;
Inserted : out Boolean)
with Pre => Source.Is_Defined, Inline;
-- Checks if an element equivalent to Source is already present in Self.
-- If a match is found, Inserted is set to False and Position designates
-- the matching element. Otherwise, Insert adds Source to Container;
-- Inserted is set to True and Position designates the newly-inserted
-- element.
procedure Union (Self : in out Object; Sources : Object) with Inline;
-- Inserts into Self the elements of Source that are not equivalent to some
-- element already in Self.
function Contains
(Self : Object;
Source : Project.Source.Object) return Boolean
with Pre => Source.Is_Defined, Inline;
-- Returns True if Self contains Source
procedure Delete
(Self : in out Object; Source : Project.Source.Object)
with Pre => Source.Is_Defined, Inline;
-- Deletes source from set
procedure Replace
(Self : in out Object;
Source : Project.Source.Object)
with Pre => Source.Is_Defined and then Self.Contains (Source), Inline;
-- Replaces Source in Self
procedure Replace
(Self : in out Object;
Position : Cursor;
Source : Project.Source.Object)
with Pre => Source.Is_Defined, Inline;
-- Replaces Source in Self at the given Position
function First_Element (Self : Object) return Project.Source.Object;
function Find
(Self : Object; Source : Project.Source.Object) return Cursor
with Pre => Source.Is_Defined, Inline;
function Element (Position : Cursor) return Project.Source.Object
with Inline;
function Has_Element (Position : Cursor) return Boolean
with Inline;
package Source_Iterator is
new Ada.Iterator_Interfaces (Cursor, Has_Element);
type Constant_Reference_Type
(Source : not null access constant Project.Source.Object) is private
with Implicit_Dereference => Source;
function Constant_Reference
(Self : aliased Object;
Position : Cursor) return Constant_Reference_Type with Inline;
function Iterate
(Self : Object) return Source_Iterator.Forward_Iterator'Class;
private
package Set is new Ada.Containers.Ordered_Sets (Project.Source.Object);
type Object is tagged record
S : aliased Set.Set;
end record;
type Cursor is record
Current : Set.Cursor;
end record;
No_Element : constant Cursor := (Current => Set.No_Element);
type Constant_Reference_Type
(Source : not null access constant Project.Source.Object) is record
Ref : Set.Constant_Reference_Type (Source);
end record;
-- We keep the ref in the object as well to keep the busy state of
-- the set.
Empty_Set : constant Object := Object'(S => Set.Empty_Set);
function Find
(Self : Object; Source : Project.Source.Object) return Cursor
is (Current => Self.S.Find (Source));
function Length (Self : Object) return Containers.Count_Type is
(Self.S.Length);
function Is_Empty (Self : Object) return Boolean is
(Self.S.Is_Empty);
end GPR2.Project.Source.Set;
|