~ubuntu-branches/ubuntu/intrepid/libgtkada2/intrepid

« back to all changes in this revision

Viewing changes to src/gtkada-c.ads

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-08-11 09:46:51 UTC
  • mfrom: (6.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20080811094651-9mjd6acwa98ffw5c
Tags: 2.12.0-2ubuntu1
Add lpia to supported architectures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-----------------------------------------------------------------------
 
2
--          GtkAda - Ada95 binding for the Gimp Toolkit              --
 
3
--                                                                   --
 
4
--                     Copyright (C) 2006, AdaCore                   --
 
5
--                                                                   --
 
6
-- This library is free software; you can redistribute it and/or     --
 
7
-- modify it under the terms of the GNU General Public               --
 
8
-- License as published by the Free Software Foundation; either      --
 
9
-- version 2 of the License, or (at your option) any later version.  --
 
10
--                                                                   --
 
11
-- This library is distributed in the hope that it will be useful,   --
 
12
-- but WITHOUT ANY WARRANTY; without even the implied warranty of    --
 
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU --
 
14
-- General Public License for more details.                          --
 
15
--                                                                   --
 
16
-- You should have received a copy of the GNU General Public         --
 
17
-- License along with this library; if not, write to the             --
 
18
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      --
 
19
-- Boston, MA 02111-1307, USA.                                       --
 
20
--                                                                   --
 
21
-----------------------------------------------------------------------
 
22
 
 
23
--  This package is purely internal to GtkAda.
 
24
--  It was moved out of Gtkada.Bindings for elaboration circularity issues
 
25
 
 
26
with Ada.Unchecked_Conversion;
 
27
with System;
 
28
 
 
29
package Gtkada.C is
 
30
 
 
31
   -------------
 
32
   --  Arrays --
 
33
   -------------
 
34
   --  The following functions ease bindings: when a C function returns an
 
35
   --  array or a pointer to an array, it returns a C array, ie which doesn't
 
36
   --  contain bounds. The size of the array is generally reported separately.
 
37
   --  The following definitions are suitable for use internally in the
 
38
   --  binding, but should not, when possible, be made visble to the user,
 
39
   --  since they don't behave like usual Ada arrays ('Last is irrelevant for
 
40
   --  instance).
 
41
   --
 
42
   --  For instance, if a C function has the following profile:
 
43
   --      gint* get_sizes (GtkIconTheme* theme);  --  0 terminated array
 
44
   --  when the binding is:
 
45
   --      function Internal (Theme) return Unbounded_Gint_Array_Access;
 
46
   --  and you need to compute for yourself the number of elements, and
 
47
   --  return a Glib.Gint_Array to the user.
 
48
   --
 
49
   --  If the C function has the following profile:
 
50
   --      gboolean get_attach_points (theme, GdkPoint** p, gint* n);
 
51
   --  then the binding is:
 
52
   --      function Internal (Theme  : System.Address;
 
53
   --                         Points : out Unbounded_Points_Array_Access;
 
54
   --                         N      : access Gint) return Gboolean;
 
55
   --  and you do the following:
 
56
   --      R : aliased Unbounded_Points_Array_Access;
 
57
   --      N : aliased Gint;
 
58
   --      Tmp : constant Gboolean :=
 
59
   --         Internal (.., R'Unchecked_Access, N'Unchecked_Access);
 
60
   --      Result : Gdk_Points_Array (1 .. Natural (N)) :=
 
61
   --         To_Gint_Array (R, Natural (N));
 
62
   --      Free (R);
 
63
   --      return Result;
 
64
 
 
65
   generic
 
66
      type T is private;
 
67
      Null_T : T;
 
68
      type Index is (<>);
 
69
      type T_Array is array (Index range <>) of T;
 
70
   package Unbounded_Arrays is
 
71
      type Unbounded_Array
 
72
        is array (Index range Index'Val (1) .. Index'Last) of T;
 
73
      pragma Convention (C, Unbounded_Array);
 
74
      type Unbounded_Array_Access is access Unbounded_Array;
 
75
 
 
76
      procedure G_Free (Arr : Unbounded_Array_Access);
 
77
 
 
78
      function To_Array
 
79
        (Arr : Unbounded_Array_Access; N : Index) return T_Array;
 
80
 
 
81
      function Convert is new Ada.Unchecked_Conversion
 
82
        (System.Address, Unbounded_Array_Access);
 
83
 
 
84
   private
 
85
      pragma Import (C, G_Free, "g_free");
 
86
   end Unbounded_Arrays;
 
87
 
 
88
end Gtkada.C;