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