1. ------------------------------------------------------------------------------ 
  2. --               GtkAda - Ada95 binding for the Gimp Toolkit                -- 
  3. --                                                                          -- 
  4. --                     Copyright (C) 2006-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  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;