PageRenderTime 17ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/src/wrappers/gobject/library/g_enum.e

http://github.com/tybor/Liberty
Specman e | 124 lines | 46 code | 22 blank | 56 comment | 5 complexity | 938bfd7ebe01370fc609ecb4e12e3ad1 MD5 | raw file
  1indexing
  2	description: "Enumeration type."
  3	copyright: "[
  4					Copyright (C) 2006 eiffel-libraries team, GTK+ team
  5					
  6					This library is free software; you can redistribute it and/or
  7					modify it under the terms of the GNU Lesser General Public License
  8					as published by the Free Software Foundation; either version 2.1 of
  9					the License, or (at your option) any later version.
 10					
 11					This library is distributed in the hope that it will be useful, but
 12					WITHOUT ANY WARRANTY; without even the implied warranty of
 13					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14					Lesser General Public License for more details.
 15
 16					You should have received a copy of the GNU Lesser General Public
 17					License along with this library; if not, write to the Free Software
 18					Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 19					02110-1301 USA
 20				]"
 21
 22deferred class G_ENUM
 23	-- TODO: unfinished
 24
 25	-- The GLib type system provides fundamental types for enumeration
 26	-- and flags types. (Flags types are like enumerations, but allow
 27	-- their values to be combined by bitwise or). A registered
 28	-- enumeration or flags type associates a name and a nickname with
 29	-- each allowed value, and the methods g_enum_get_value_by_name(),
 30	-- g_enum_get_value_by_nick(), g_flags_get_value_by_name() and
 31	-- g_flags_get_value_by_nick() can look up values by their name or
 32	-- nickname. When an enumeration or flags type is registered with
 33	-- the GLib type system, it can be used as value type for object
 34	-- properties, using g_param_spec_enum() or g_param_spec_flags().
 35							
 36	-- GObject ships with a utility called glib-mkenums that can
 37	-- construct suitable type registration functions from C
 38	-- enumeration definitions.
 39	
 40inherit C_STRUCT
 41	
 42insert G_ENUM_EXTERNALS
 43	
 44-- creation from_external_pointer
 45
 46feature -- size
 47	struct_size: INTEGER is
 48		external "C inline use <gtk/gtk.h>"
 49		alias "sizeof(GEnum)"
 50		end
 51
 52feature -- TODO: typedef struct {
 53--   GTypeClass  g_type_class;
 54
 55--   gint	      minimum;
 56--   gint	      maximum;
 57--   guint	      n_values;
 58--   GEnumValue *values;
 59-- } GEnumClass;
 60
 61-- The class of an enumeration type holds information about its possible values.
 62-- GTypeClass g_type_class; 	the parent class
 63-- gint minimum; 	the smallest possible value.
 64-- gint maximum; 	the largest possible value.
 65-- guint n_values; 	the number of possible values.
 66-- GEnumValue *values; 	an array of GEnumValue structs describing the individual values.
 67feature
 68	value (an_index: INTEGER): G_ENUM_VALUE is
 69			-- the GEnumValue for `an_index' value. Void if `an_index' 
 70			-- is not a member of the enumeration
 71		local ptr: POINTER
 72		do
 73			ptr := g_enum_get_value (handle,an_index)
 74			if ptr.is_not_null then create Result.from_external_pointer (ptr) end
 75		end
 76
 77	value_by_name (a_name: STRING): G_ENUM_VALUE is
 78			-- the GEnumValue with `a_name', or Void if the enumeration
 79			-- doesn' t have a member with that name
 80		local ptr: POINTER
 81		do
 82			ptr := g_enum_get_value_by_name (handle, a_name.to_external)
 83			if ptr.is_not_null then create Result.from_external_pointer (ptr) end
 84		end
 85
 86	value_by_nick (a_name: STRING): G_ENUM_VALUE is
 87			-- the GEnumValue with nickname `a_nick', or Void if the
 88			-- enumeration doesn' t have a member with that nickname.
 89		local ptr: POINTER
 90do
 91			ptr := g_enum_get_value_by_nick (handle, a_name.to_external)
 92			if ptr.is_not_null then create Result.from_external_pointer (ptr) end
 93		end
 94 
 95	-- TODO: Eiffelize g_enum_register_static and glib_mkenums 
 96	-- related tools.
 97
 98	-- TODO: wrap g_enum_complete_type_info ()
 99
100	-- void        g_enum_complete_type_info       (GType g_enum_type,
101	-- 															GTypeInfo *info,
102	-- 															const GEnumValue *const_values);
103
104	-- This function is meant to be called from the complete_type_info() function of a GTypePlugin implementation, as in the following example:
105
106	-- static void
107	-- my_enum_complete_type_info (GTypePlugin     *plugin,
108	-- 									 GType            g_type,
109	-- 									 GTypeInfo       *info,
110	-- 									 GTypeValueTable *value_table)
111	-- {
112	--   static const GEnumValue values[] = {
113	-- 	{ MY_ENUM_FOO, "MY_ENUM_FOO", "foo" },
114	-- 	{ MY_ENUM_BAR, "MY_ENUM_BAR", "bar" },
115	-- 	{ 0, NULL, NULL }
116	--   };  
117	
118	--   g_enum_complete_type_info (type, info, values);  
119	-- }
120
121	-- g_enum_type : 	the type identifier of the type being completed
122	-- info : 	the GTypeInfo struct to be filled in
123	-- const_values : 	An array of GEnumValue structs for the possible enumeration values. The array is terminated by a struct with all members being 0.
124end