File: glib-glist.adb

package info (click to toggle)
libgtkada2 2.8.1-6lenny3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,496 kB
  • ctags: 3,886
  • sloc: ada: 103,189; ansic: 45,411; perl: 5,500; sh: 2,812; makefile: 1,169; xml: 19
file content (376 lines) | stat: -rw-r--r-- 11,390 bytes parent folder | download | duplicates (5)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
-----------------------------------------------------------------------
--          GtkAda - Ada95 binding for the Gimp Toolkit              --
--                                                                   --
--                     Copyright (C) 1998-2000                       --
--        Emmanuel Briot, Joel Brobecker and Arnaud Charlet          --
--                                                                   --
-- This library is free software; you can redistribute it and/or     --
-- modify it under the terms of the GNU General Public               --
-- License as published by the Free Software Foundation; either      --
-- version 2 of the License, or (at your option) any later version.  --
--                                                                   --
-- This library is distributed in the hope that it will be useful,   --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of    --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU --
-- General Public License for more details.                          --
--                                                                   --
-- You should have received a copy of the GNU General Public         --
-- License along with this library; if not, write to the             --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      --
-- Boston, MA 02111-1307, USA.                                       --
--                                                                   --
-----------------------------------------------------------------------

package body Glib.Glist is

   use type System.Address;

   package body Generic_List is
      -----------
      -- Alloc --
      -----------

      procedure Alloc (List : out Glist) is
         function Internal return System.Address;
         pragma Import (C, Internal, "g_list_alloc");
      begin
         Set_Object (List, Internal);
      end Alloc;

      ------------
      -- Append --
      ------------

      procedure Append
        (List : in out Glist;
         Data : in Gpointer)
      is
         function Internal (List : System.Address;
                            Data : System.Address)
                            return System.Address;
         pragma Import (C, Internal, "g_list_append");
      begin
         Set_Object (List, Internal (Get_Object (List),
                                     Convert (Data)));
      end Append;

      ------------
      -- Concat --
      ------------

      function Concat
        (List1 : in Glist;
         List2 : in Glist)
         return Glist
      is
         function Internal (List1 : System.Address;
                            List2 : System.Address)
                            return System.Address;
         pragma Import (C, Internal, "g_list_append");
         Tmp : Glist;
      begin
         Set_Object (Tmp, Internal (Get_Object (List1),
                                    Get_Object (List2)));
         return Tmp;
      end Concat;

      ------------
      -- Insert --
      ------------

      procedure Insert
        (List     : in out Glist;
         Data     : in     Gpointer;
         Position : in     Gint)
      is
         function Internal (List : System.Address;
                            Data : System.Address;
                            Pos  : Gint)
                            return System.Address;
         pragma Import (C, Internal, "g_list_insert");
      begin
         Set_Object (List, Internal (Get_Object (List),
                                     Convert (Data), Position));
      end Insert;

      ----------
      -- Find --
      ----------

      function Find
        (List : in Glist;
         Data : in Gpointer) return Glist
      is
         function Internal
           (List : System.Address;
            Data : System.Address) return System.Address;
         pragma Import (C, Internal, "g_list_find");
         Tmp : Glist;

      begin
         Set_Object (Tmp, Internal (Get_Object (List), Convert (Data)));
         return Tmp;
      end Find;

      -----------
      -- First --
      -----------

      function First (List : in Glist) return Glist is
         function Internal (List : System.Address) return System.Address;
         pragma Import (C, Internal, "g_list_first");
         Tmp : Glist;

      begin
         Set_Object (Tmp, Internal (Get_Object (List)));
         return Tmp;
      end First;

      ----------
      -- Free --
      ----------

      procedure Free (List : in out Glist) is
         procedure Internal (List : System.Address);
         pragma Import (C, Internal, "g_list_free");
      begin
         Internal (Get_Object (List));
         List := Null_List;
      end Free;

      --------------
      -- Get_Data --
      --------------

      function Get_Data (List : in Glist) return Gpointer is
         function Internal (List : in System.Address)
                            return System.Address;
         pragma Import (C, Internal, "ada_list_get_data");
      begin
         return Convert (Internal (Get_Object (List)));
      end Get_Data;

      --------------
      -- Get_Data --
      --------------

      function Get_Data_Address (List : in Glist) return System.Address is
         function Internal (List : in System.Address)
                            return System.Address;
         pragma Import (C, Internal, "ada_list_get_data");
      begin
         return Internal (Get_Object (List));
      end Get_Data_Address;

      --------------------
      --  Get_Gpointer  --
      --------------------

      function Get_Gpointer (List : in Glist) return Gpointer is
      begin
         return Convert (Get_Object (List));
      end Get_Gpointer;

      ----------------
      -- Get_Object --
      ----------------

      function Get_Object (Obj : in Glist) return System.Address is
      begin
         return Obj.Ptr;
      end Get_Object;

      -----------
      -- Index --
      -----------

      function Index (List : in Glist; Data : in Gpointer) return Gint is
         function Internal
           (List : System.Address;
            Data : System.Address) return Gint;
         pragma Import (C, Internal, "g_list_index");

      begin
         return Internal (Get_Object (List), Convert (Data));
      end Index;

      ------------------
      --  Is_Created  --
      ------------------

      function Is_Created (List : in Glist) return Boolean is
      begin
         return Get_Object (List) /= System.Null_Address;
      end Is_Created;

      ----------
      -- Last --
      ----------

      function Last (List : in Glist) return Glist is
         function Internal (List : System.Address) return System.Address;
         pragma Import (C, Internal, "g_list_last");
         Tmp : Glist;
      begin
         Set_Object (Tmp, Internal (Get_Object (List)));
         return Tmp;
      end Last;

      ------------
      -- Length --
      ------------

      function Length (List : in Glist) return Guint is
         function Internal (List : System.Address) return Guint;
         pragma Import (C, Internal, "g_list_length");
      begin
         return Internal (Get_Object (List));
      end Length;

      ------------------
      -- List_Reverse --
      ------------------

      procedure List_Reverse (List : in out Glist) is
         function Internal (List : System.Address) return System.Address;
         pragma Import (C, Internal, "g_list_reverse");
      begin
         Set_Object (List, Internal (Get_Object (List)));
      end List_Reverse;

      ----------
      -- Next --
      ----------

      function Next (List : in Glist) return Glist is
         function Internal (List : System.Address) return System.Address;
         pragma Import (C, Internal, "ada_list_next");
         Tmp : Glist;
      begin
         Set_Object (Tmp, Internal (Get_Object (List)));
         return Tmp;
      end Next;

      ---------
      -- Nth --
      ---------

      function Nth (List : in Glist; N    : in Guint) return Glist is
         function Internal
           (List : System.Address; N : Guint) return System.Address;
         pragma Import (C, Internal, "g_list_nth");
         Tmp : Glist;

      begin
         Set_Object (Tmp, Internal (Get_Object (List), N));
         return Tmp;
      end Nth;

      --------------
      -- Nth_Data --
      --------------

      function Nth_Data
        (List : in Glist;
         N    : in Guint) return Gpointer
      is
         function Internal
           (List : System.Address; N : Guint) return System.Address;
         pragma Import (C, Internal, "g_list_nth_data");

      begin
         return Convert (Internal (Get_Object (List), N));
      end Nth_Data;

      --------------
      -- Position --
      --------------

      function Position
        (List : in Glist;
         Link : in Glist) return Gint
      is
         function Internal (List : System.Address;
                            Link : System.Address) return Gint;
         pragma Import (C, Internal, "g_list_position");
      begin
         return Internal (Get_Object (List), Get_Object (Link));
      end Position;

      -------------
      -- Prepend --
      -------------

      procedure Prepend
        (List : in out Glist;
         Data : in Gpointer)
      is
         function Internal (List : System.Address;
                            Data : System.Address)
                            return System.Address;
         pragma Import (C, Internal, "g_list_prepend");
      begin
         Set_Object (List, Internal (Get_Object (List),
                                     Convert (Data)));
      end Prepend;

      ----------
      -- Prev --
      ----------

      function Prev (List : in Glist) return Glist is
         function Internal (List : System.Address)
                            return System.Address;
         pragma Import (C, Internal, "ada_list_prev");
         Tmp : Glist;
      begin
         Set_Object (Tmp, Internal (Get_Object (List)));
         return Tmp;
      end Prev;

      ------------
      -- Remove --
      ------------

      procedure Remove
        (List : in out Glist;
         Data : in Gpointer)
      is
         function Internal (List : System.Address;
                            Data : System.Address)
                            return System.Address;
         pragma Import (C, Internal, "g_list_remove");
      begin
         Set_Object (List, Internal (Get_Object (List),
                                     Convert (Data)));
      end Remove;

      -----------------
      -- Remove_Link --
      -----------------

      procedure Remove_Link
        (List : in out Glist;
         Link : in Glist)
      is
         function Internal (List : System.Address;
                            Link : System.Address)
                            return System.Address;
         pragma Import (C, Internal, "g_list_remove_link");
      begin
         Set_Object (List, Internal (Get_Object (List),
                                     Get_Object (Link)));
      end Remove_Link;

      ----------------
      -- Set_Object --
      ----------------

      procedure Set_Object (Obj   : in out Glist;
                            Value : in     System.Address) is
      begin
         Obj.Ptr := Value;
      end Set_Object;

   end Generic_List;
end Glib.Glist;