1. ----------------------------------------------------------------------- 
  2. --          GtkAda - Ada95 binding for the Gimp Toolkit              -- 
  3. --                                                                   -- 
  4. --                     Copyright (C) 2006-2013, 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. -- As a special exception, if other files instantiate generics from  -- 
  22. -- this unit, or you link this unit with other files to produce an   -- 
  23. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  24. -- executable to be covered by the GNU General Public License. This  -- 
  25. -- exception does not however invalidate any other reasons why the   -- 
  26. -- executable file  might be covered by the  GNU Public License.     -- 
  27. ----------------------------------------------------------------------- 
  28.  
  29. --  This package is purely internal to GtkAda. 
  30. --  It was moved out of Gtkada.Bindings for elaboration circularity issues 
  31.  
  32. with Ada.Unchecked_Conversion; 
  33. with System; 
  34.  
  35. package Gtkada.C is 
  36.  
  37.    ------------- 
  38.    --  Arrays -- 
  39.    ------------- 
  40.    --  The following functions ease bindings: when a C function returns an 
  41.    --  array or a pointer to an array, it returns a C array, ie which doesn't 
  42.    --  contain bounds. The size of the array is generally reported separately. 
  43.    --  The following definitions are suitable for use internally in the 
  44.    --  binding, but should not, when possible, be made visble to the user, 
  45.    --  since they don't behave like usual Ada arrays ('Last is irrelevant for 
  46.    --  instance). 
  47.    -- 
  48.    --  For instance, if a C function has the following profile: 
  49.    --      gint* get_sizes (GtkIconTheme* theme);  --  0 terminated array 
  50.    --  when the binding is: 
  51.    --      function Internal (Theme) return Unbounded_Gint_Array_Access; 
  52.    --  and you need to compute for yourself the number of elements, and 
  53.    --  return a Glib.Gint_Array to the user. 
  54.    -- 
  55.    --  If the C function has the following profile: 
  56.    --      gboolean get_attach_points (theme, GdkPoint** p, gint* n); 
  57.    --  then the binding is: 
  58.    --      function Internal (Theme  : System.Address; 
  59.    --                         Points : out Unbounded_Points_Array_Access; 
  60.    --                         N      : access Gint) return Gboolean; 
  61.    --  and you do the following: 
  62.    --      R : aliased Unbounded_Points_Array_Access; 
  63.    --      N : aliased Gint; 
  64.    --      Tmp : constant Gboolean := 
  65.    --         Internal (.., R'Unchecked_Access, N'Unchecked_Access); 
  66.    --      Result : Gdk_Points_Array (1 .. Natural (N)) := 
  67.    --         To_Gint_Array (R, Natural (N)); 
  68.    --      Free (R); 
  69.    --      return Result; 
  70.  
  71.    generic 
  72.       type T is private; 
  73.       Null_T : T; 
  74.       type Index is (<>); 
  75.       type T_Array is array (Index range <>) of T; 
  76.    package Unbounded_Arrays is 
  77.       type Unbounded_Array 
  78.         is array (Index range Index'Val (1) .. Index'Last) of T; 
  79.       pragma Convention (C, Unbounded_Array); 
  80.       type Unbounded_Array_Access is access Unbounded_Array; 
  81.  
  82.       procedure G_Free (Arr : Unbounded_Array_Access); 
  83.  
  84.       function To_Array 
  85.         (Arr : Unbounded_Array_Access; N : Index) return T_Array; 
  86.  
  87.       function Convert is new Ada.Unchecked_Conversion 
  88.         (System.Address, Unbounded_Array_Access); 
  89.  
  90.    private 
  91.       pragma Import (C, G_Free, "g_free"); 
  92.    end Unbounded_Arrays; 
  93.  
  94. end Gtkada.C;