1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
19 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
20 #error "Only <glib-object.h> can be included directly."
26 #include <gobject/gtype.h>
30 /* --- type macros --- */
35 * Checks whether @type "is a" %G_TYPE_ENUM.
37 * Returns: %TRUE if @type "is a" %G_TYPE_ENUM.
39 #define G_TYPE_IS_ENUM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM)
42 * @class: a valid #GEnumClass
44 * Casts a derived #GEnumClass structure into a #GEnumClass structure.
46 #define G_ENUM_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_ENUM, GEnumClass))
49 * @class: a #GEnumClass
51 * Checks whether @class "is a" valid #GEnumClass structure of type %G_TYPE_ENUM
54 #define G_IS_ENUM_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_ENUM))
57 * @class: a #GEnumClass
59 * Get the type identifier from a given #GEnumClass structure.
63 #define G_ENUM_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
65 * G_ENUM_CLASS_TYPE_NAME:
66 * @class: a #GEnumClass
68 * Get the static type name from a given #GEnumClass structure.
70 * Returns: the type name.
72 #define G_ENUM_CLASS_TYPE_NAME(class) (g_type_name (G_ENUM_CLASS_TYPE (class)))
79 * Checks whether @type "is a" %G_TYPE_FLAGS.
81 * Returns: %TRUE if @type "is a" %G_TYPE_FLAGS.
83 #define G_TYPE_IS_FLAGS(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS)
86 * @class: a valid #GFlagsClass
88 * Casts a derived #GFlagsClass structure into a #GFlagsClass structure.
90 #define G_FLAGS_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_FLAGS, GFlagsClass))
93 * @class: a #GFlagsClass
95 * Checks whether @class "is a" valid #GFlagsClass structure of type %G_TYPE_FLAGS
98 #define G_IS_FLAGS_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_FLAGS))
100 * G_FLAGS_CLASS_TYPE:
101 * @class: a #GFlagsClass
103 * Get the type identifier from a given #GFlagsClass structure.
105 * Returns: the #GType
107 #define G_FLAGS_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
109 * G_FLAGS_CLASS_TYPE_NAME:
110 * @class: a #GFlagsClass
112 * Get the static type name from a given #GFlagsClass structure.
114 * Returns: the type name.
116 #define G_FLAGS_CLASS_TYPE_NAME(class) (g_type_name (G_FLAGS_CLASS_TYPE (class)))
120 * G_VALUE_HOLDS_ENUM:
121 * @value: a valid #GValue structure
123 * Checks whether the given #GValue can hold values derived from type %G_TYPE_ENUM.
125 * Returns: %TRUE on success.
127 #define G_VALUE_HOLDS_ENUM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ENUM))
129 * G_VALUE_HOLDS_FLAGS:
130 * @value: a valid #GValue structure
132 * Checks whether the given #GValue can hold values derived from type %G_TYPE_FLAGS.
134 * Returns: %TRUE on success.
136 #define G_VALUE_HOLDS_FLAGS(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLAGS))
139 /* --- enum/flag values & classes --- */
140 typedef struct _GEnumClass GEnumClass;
141 typedef struct _GFlagsClass GFlagsClass;
142 typedef struct _GEnumValue GEnumValue;
143 typedef struct _GFlagsValue GFlagsValue;
147 * @g_type_class: the parent class
148 * @minimum: the smallest possible value.
149 * @maximum: the largest possible value.
150 * @n_values: the number of possible values.
151 * @values: an array of #GEnumValue structs describing the
154 * The class of an enumeration type holds information about its
159 GTypeClass g_type_class;
169 * @g_type_class: the parent class
170 * @mask: a mask covering all possible values.
171 * @n_values: the number of possible values.
172 * @values: an array of #GFlagsValue structs describing the
175 * The class of a flags type holds information about its
180 GTypeClass g_type_class;
189 * @value: the enum value
190 * @value_name: the name of the value
191 * @value_nick: the nickname of the value
193 * A structure which contains a single enum value, its name, and its
199 const gchar *value_name;
200 const gchar *value_nick;
204 * @value: the flags value
205 * @value_name: the name of the value
206 * @value_nick: the nickname of the value
208 * A structure which contains a single flags value, its name, and its
214 const gchar *value_name;
215 const gchar *value_nick;
219 /* --- prototypes --- */
220 GEnumValue* g_enum_get_value (GEnumClass *enum_class,
222 GEnumValue* g_enum_get_value_by_name (GEnumClass *enum_class,
224 GEnumValue* g_enum_get_value_by_nick (GEnumClass *enum_class,
226 GFlagsValue* g_flags_get_first_value (GFlagsClass *flags_class,
228 GFlagsValue* g_flags_get_value_by_name (GFlagsClass *flags_class,
230 GFlagsValue* g_flags_get_value_by_nick (GFlagsClass *flags_class,
232 void g_value_set_enum (GValue *value,
234 gint g_value_get_enum (const GValue *value);
235 void g_value_set_flags (GValue *value,
237 guint g_value_get_flags (const GValue *value);
241 /* --- registration functions --- */
242 /* const_static_values is a NULL terminated array of enum/flags
243 * values that is taken over!
245 GType g_enum_register_static (const gchar *name,
246 const GEnumValue *const_static_values);
247 GType g_flags_register_static (const gchar *name,
248 const GFlagsValue *const_static_values);
249 /* functions to complete the type information
250 * for enums/flags implemented by plugins
252 void g_enum_complete_type_info (GType g_enum_type,
254 const GEnumValue *const_values);
255 void g_flags_complete_type_info (GType g_flags_type,
257 const GFlagsValue *const_values);
261 #endif /* __G_ENUMS_H__ */