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