1. ----------------------------------------------------------------------- 
  2. --          GtkAda - Ada95 binding for the Gimp Toolkit              -- 
  3. --                                                                   -- 
  4. --                     Copyright (C) 1998-2000                       -- 
  5. --        Emmanuel Briot, Joel Brobecker and Arnaud Charlet          -- 
  6. --                                                                   -- 
  7. -- This library is free software; you can redistribute it and/or     -- 
  8. -- modify it under the terms of the GNU General Public               -- 
  9. -- License as published by the Free Software Foundation; either      -- 
  10. -- version 2 of the License, or (at your option) any later version.  -- 
  11. --                                                                   -- 
  12. -- This library is distributed in the hope that it will be useful,   -- 
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  15. -- General Public License for more details.                          -- 
  16. --                                                                   -- 
  17. -- You should have received a copy of the GNU General Public         -- 
  18. -- License along with this library; if not, write to the             -- 
  19. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  20. -- Boston, MA 02111-1307, USA.                                       -- 
  21. --                                                                   -- 
  22. -- -- -- -- -- -- -- -- -- -- -- --
  23. ----------------------------------------------------------------------- 
  24.  
  25. --  <description> 
  26. -- 
  27. --  This package provides GtkAda specific types and their associated functions. 
  28. -- 
  29. --  </description> 
  30.  
  31. with Interfaces.C.Strings; 
  32.  
  33. package Gtkada.Types is 
  34.  
  35.    pragma Preelaborate; 
  36.  
  37.    Data_Error : exception; 
  38.  
  39.    subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr; 
  40.    subtype Chars_Ptr_Array is Interfaces.C.Strings.chars_ptr_array; 
  41.  
  42.    procedure g_free (Mem : Chars_Ptr); 
  43.    --  Free a C string returned from Gtk 
  44.  
  45.    Null_Ptr : Chars_Ptr renames Interfaces.C.Strings.Null_Ptr; 
  46.  
  47.    function Null_Array return Chars_Ptr_Array; 
  48.    --  Return a null array. 
  49.    pragma Inline (Null_Array); 
  50.  
  51.    ------------------------------------- 
  52.    --  Handling of arrays of Strings  -- 
  53.    ------------------------------------- 
  54.    --  The following functions provide a very convenient way to create 
  55.    --  C arrays of null terminated strings in Ada. 
  56.    -- 
  57.    --  You can either create such a String on the fly, or declare a variable: 
  58.    -- 
  59.    --     Signals : Chars_Ptr_Array := "clicked" + "missed" + "new signal"; 
  60.    -- 
  61.    --  which corresponds to the C declaration: 
  62.    -- 
  63.    --     char *signals[] = @{"clicked", "missed", "new signal"@}; 
  64.    -- 
  65.    --  Note that you still need to manually call Free (Signals) if you want to 
  66.    --  release the memory dynamically allocated by the "+" functions. 
  67.  
  68.    function "+" (S1, S2 : String) return Chars_Ptr_Array; 
  69.    --  Create an array containing S1 and S2. 
  70.    --  Note that this function allocates memory to store S1 and S2 as null 
  71.    --  terminated Strings. The user is responsible for calling Free on the 
  72.    --  resulting array. 
  73.  
  74.    function "+" (S1 : Chars_Ptr_Array; S2 : String) return Chars_Ptr_Array; 
  75.    --  Append S2 to S1. 
  76.    --  Note that this function allocates memory to store S2 as a null 
  77.    --  terminated Strings. The user is responsible for calling Free on the 
  78.    --  resulting array. 
  79.  
  80.    function "+" (S1 : Chars_Ptr_Array; S2 : Chars_Ptr) return Chars_Ptr_Array; 
  81.    --  Append S2 to S1. 
  82.    --  Note that this function allocates memory to store S2 as a null 
  83.    --  terminated Strings. The user is responsible for calling Free on the 
  84.    --  resulting array. 
  85.  
  86.    function "+" (S1 : Chars_Ptr; S2 : String) return Chars_Ptr_Array; 
  87.    --  Create an array containing S1 and S2. 
  88.    --  Note that this function allocates memory to store S2 as a null 
  89.    --  terminated string. The user is responsible for calling Free on the 
  90.    --  resulting array. 
  91.  
  92.    procedure Free (A : in out Chars_Ptr_Array); 
  93.    --  Free all the strings in A. 
  94.  
  95. private 
  96.    pragma Import (C, g_free, "g_free"); 
  97. end Gtkada.Types;