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. -- As a special exception, if other files instantiate generics from  -- 
  23. -- this unit, or you link this unit with other files to produce an   -- 
  24. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  25. -- executable to be covered by the GNU General Public License. This  -- 
  26. -- exception does not however invalidate any other reasons why the   -- 
  27. -- executable file  might be covered by the  GNU Public License.     -- 
  28. ----------------------------------------------------------------------- 
  29.  
  30. --  <description> 
  31. -- 
  32. --  This package provides GtkAda specific types and their associated functions. 
  33. -- 
  34. --  </description> 
  35.  
  36. with Interfaces.C.Strings; 
  37.  
  38. package Gtkada.Types is 
  39.  
  40.    pragma Preelaborate; 
  41.  
  42.    Data_Error : exception; 
  43.  
  44.    subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr; 
  45.    subtype Chars_Ptr_Array is Interfaces.C.Strings.chars_ptr_array; 
  46.  
  47.    procedure g_free (Mem : Chars_Ptr); 
  48.    --  Free a C string returned from Gtk 
  49.  
  50.    Null_Ptr : Chars_Ptr renames Interfaces.C.Strings.Null_Ptr; 
  51.  
  52.    function Null_Array return Chars_Ptr_Array; 
  53.    --  Return a null array. 
  54.    pragma Inline (Null_Array); 
  55.  
  56.    ------------------------------------- 
  57.    --  Handling of arrays of Strings  -- 
  58.    ------------------------------------- 
  59.    --  The following functions provide a very convenient way to create 
  60.    --  C arrays of null terminated strings in Ada. 
  61.    -- 
  62.    --  You can either create such a String on the fly, or declare a variable: 
  63.    -- 
  64.    --     Signals : Chars_Ptr_Array := "clicked" + "missed" + "new signal"; 
  65.    -- 
  66.    --  which corresponds to the C declaration: 
  67.    -- 
  68.    --     char *signals[] = @{"clicked", "missed", "new signal"@}; 
  69.    -- 
  70.    --  Note that you still need to manually call Free (Signals) if you want to 
  71.    --  release the memory dynamically allocated by the "+" functions. 
  72.  
  73.    function "+" (S1, S2 : String) return Chars_Ptr_Array; 
  74.    --  Create an array containing S1 and S2. 
  75.    --  Note that this function allocates memory to store S1 and S2 as null 
  76.    --  terminated Strings. The user is responsible for calling Free on the 
  77.    --  resulting array. 
  78.  
  79.    function "+" (S1 : Chars_Ptr_Array; S2 : String) return Chars_Ptr_Array; 
  80.    --  Append S2 to S1. 
  81.    --  Note that this function allocates memory to store S2 as a null 
  82.    --  terminated Strings. The user is responsible for calling Free on the 
  83.    --  resulting array. 
  84.  
  85.    function "+" (S1 : Chars_Ptr_Array; S2 : Chars_Ptr) return Chars_Ptr_Array; 
  86.    --  Append S2 to S1. 
  87.    --  Note that this function allocates memory to store S2 as a null 
  88.    --  terminated Strings. The user is responsible for calling Free on the 
  89.    --  resulting array. 
  90.  
  91.    function "+" (S1 : Chars_Ptr; S2 : String) return Chars_Ptr_Array; 
  92.    --  Create an array containing S1 and S2. 
  93.    --  Note that this function allocates memory to store S2 as a null 
  94.    --  terminated string. The user is responsible for calling Free on the 
  95.    --  resulting array. 
  96.  
  97.    procedure Free (A : in out Chars_Ptr_Array); 
  98.    --  Free all the strings in A. 
  99.  
  100. private 
  101.    pragma Import (C, g_free, "g_free"); 
  102. end Gtkada.Types;