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