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 | -----------------------------------------------------------------------
-- gen-model-list -- List bean interface for model objects
-- Copyright (C) 2009, 2010, 2011, 2012, 2018, 2021, 2022 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Beans.Basic;
with Ada.Containers.Vectors;
with Ada.Iterator_Interfaces;
generic
type T is new Gen.Model.Definition with private;
type T_Access is access all T'Class;
package Gen.Model.List is
-- Compare the two definitions.
function "<" (Left, Right : in T_Access) return Boolean;
package Vectors is
new Ada.Containers.Vectors (Index_Type => Natural,
Element_Type => T_Access,
"=" => "=");
package Sorting is new Vectors.Generic_Sorting;
subtype Cursor is Vectors.Cursor;
subtype Vector is Vectors.Vector;
function Has_Element (Position : Cursor) return Boolean
renames Vectors.Has_Element;
function Element (Position : Cursor) return T_Access
renames Vectors.Element;
procedure Next (Position : in out Cursor)
renames Vectors.Next;
type List_Definition is limited new Util.Beans.Basic.List_Bean with private
with Default_Iterator => Iterate,
Iterator_Element => T_Access,
Constant_Indexing => Element_Value;
package List_Iterator is
new Ada.Iterator_Interfaces (Cursor, Has_Element);
-- Make an iterator for the list.
function Iterate (Container : in List_Definition)
return List_Iterator.Forward_Iterator'Class;
-- Get the iterator element.
function Element_Value (Container : in List_Definition;
Pos : in Cursor) return T_Access;
-- Get the first item of the list
function First (Def : List_Definition) return Cursor;
-- Get the number of elements in the list.
overriding
function Get_Count (From : List_Definition) return Natural;
-- Set the current row index. Valid row indexes start at 1.
overriding
procedure Set_Row_Index (From : in out List_Definition;
Index : in Natural);
-- Get the element at the current row index.
overriding
function Get_Row (From : List_Definition) return UBO.Object;
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
overriding
function Get_Value (From : List_Definition;
Name : String) return UBO.Object;
-- Append the item in the list
procedure Append (Def : in out List_Definition;
Item : in T_Access);
-- Sort the list of items on their names.
procedure Sort (List : in out List_Definition);
generic
with function "<" (Left, Right : T_Access) return Boolean is <>;
procedure Sort_On (List : in out List_Definition);
-- Find a definition given the name.
-- Returns the definition object or null.
function Find (Def : in List_Definition;
Name : in String) return T_Access;
-- Iterate over the elements of the list executing the <tt>Process</tt> procedure.
procedure Iterate (Def : in List_Definition;
Process : not null access procedure (Item : in T_Access));
private
type List_Definition_Access is access all List_Definition;
type List_Definition is limited new Util.Beans.Basic.List_Bean with record
Self : List_Definition_Access := List_Definition'Unchecked_Access;
Nodes : Vectors.Vector;
Row : Natural := 0;
Value_Bean : UBO.Object;
end record;
type Iterator is limited new List_Iterator.Forward_Iterator with record
List : List_Definition_Access;
end record;
overriding
function First (Object : Iterator) return Cursor;
overriding
function Next (Object : Iterator;
Pos : Cursor) return Cursor;
end Gen.Model.List;
|