diff options
Diffstat (limited to 'include/glib/gobject')
-rw-r--r-- | include/glib/gobject/gbinding.h | 149 | ||||
-rw-r--r-- | include/glib/gobject/gboxed.h | 122 | ||||
-rw-r--r-- | include/glib/gobject/gclosure.h | 317 | ||||
-rw-r--r-- | include/glib/gobject/genums.h | 279 | ||||
-rw-r--r-- | include/glib/gobject/glib-enumtypes.h | 25 | ||||
-rw-r--r-- | include/glib/gobject/glib-types.h | 362 | ||||
-rw-r--r-- | include/glib/gobject/gmarshal.h | 434 | ||||
-rw-r--r-- | include/glib/gobject/gobject-autocleanups.h | 31 | ||||
-rw-r--r-- | include/glib/gobject/gobject.h | 899 | ||||
-rw-r--r-- | include/glib/gobject/gobjectnotifyqueue.c | 197 | ||||
-rw-r--r-- | include/glib/gobject/gparam.h | 452 | ||||
-rw-r--r-- | include/glib/gobject/gparamspecs.h | 1170 | ||||
-rw-r--r-- | include/glib/gobject/gsignal.h | 623 | ||||
-rw-r--r-- | include/glib/gobject/gsourceclosure.h | 38 | ||||
-rw-r--r-- | include/glib/gobject/gtype.h | 2356 | ||||
-rw-r--r-- | include/glib/gobject/gtypemodule.h | 295 | ||||
-rw-r--r-- | include/glib/gobject/gtypeplugin.h | 134 | ||||
-rw-r--r-- | include/glib/gobject/gvalue.h | 196 | ||||
-rw-r--r-- | include/glib/gobject/gvaluearray.h | 104 | ||||
-rw-r--r-- | include/glib/gobject/gvaluecollector.h | 261 | ||||
-rw-r--r-- | include/glib/gobject/gvaluetypes.h | 300 |
21 files changed, 8744 insertions, 0 deletions
diff --git a/include/glib/gobject/gbinding.h b/include/glib/gobject/gbinding.h new file mode 100644 index 0000000000..b4eb233b34 --- /dev/null +++ b/include/glib/gobject/gbinding.h @@ -0,0 +1,149 @@ +/* gbinding.h: Binding for object properties + * + * Copyright (C) 2010 Intel Corp. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + * + * Author: Emmanuele Bassi <ebassi@linux.intel.com> + */ + +#ifndef __G_BINDING_H__ +#define __G_BINDING_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <glib.h> +#include <gobject/gobject.h> + +G_BEGIN_DECLS + +#define G_TYPE_BINDING_FLAGS (g_binding_flags_get_type ()) + +#define G_TYPE_BINDING (g_binding_get_type ()) +#define G_BINDING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_BINDING, GBinding)) +#define G_IS_BINDING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_BINDING)) + +/** + * GBinding: + * + * GBinding is an opaque structure whose members + * cannot be accessed directly. + * + * Since: 2.26 + */ +typedef struct _GBinding GBinding; + +/** + * GBindingTransformFunc: + * @binding: a #GBinding + * @from_value: the #GValue containing the value to transform + * @to_value: the #GValue in which to store the transformed value + * @user_data: data passed to the transform function + * + * A function to be called to transform @from_value to @to_value. If + * this is the @transform_to function of a binding, then @from_value + * is the @source_property on the @source object, and @to_value is the + * @target_property on the @target object. If this is the + * @transform_from function of a %G_BINDING_BIDIRECTIONAL binding, + * then those roles are reversed. + * + * Returns: %TRUE if the transformation was successful, and %FALSE + * otherwise + * + * Since: 2.26 + */ +typedef gboolean (* GBindingTransformFunc) (GBinding *binding, + const GValue *from_value, + GValue *to_value, + gpointer user_data); + +/** + * GBindingFlags: + * @G_BINDING_DEFAULT: The default binding; if the source property + * changes, the target property is updated with its value. + * @G_BINDING_BIDIRECTIONAL: Bidirectional binding; if either the + * property of the source or the property of the target changes, + * the other is updated. + * @G_BINDING_SYNC_CREATE: Synchronize the values of the source and + * target properties when creating the binding; the direction of + * the synchronization is always from the source to the target. + * @G_BINDING_INVERT_BOOLEAN: If the two properties being bound are + * booleans, setting one to %TRUE will result in the other being + * set to %FALSE and vice versa. This flag will only work for + * boolean properties, and cannot be used when passing custom + * transformation functions to g_object_bind_property_full(). + * + * Flags to be passed to g_object_bind_property() or + * g_object_bind_property_full(). + * + * This enumeration can be extended at later date. + * + * Since: 2.26 + */ +typedef enum { /*< prefix=G_BINDING >*/ + G_BINDING_DEFAULT = 0, + + G_BINDING_BIDIRECTIONAL = 1 << 0, + G_BINDING_SYNC_CREATE = 1 << 1, + G_BINDING_INVERT_BOOLEAN = 1 << 2 +} GBindingFlags; + +GLIB_AVAILABLE_IN_ALL +GType g_binding_flags_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_binding_get_type (void) G_GNUC_CONST; + +GLIB_AVAILABLE_IN_ALL +GBindingFlags g_binding_get_flags (GBinding *binding); +GLIB_AVAILABLE_IN_ALL +GObject * g_binding_get_source (GBinding *binding); +GLIB_AVAILABLE_IN_ALL +GObject * g_binding_get_target (GBinding *binding); +GLIB_AVAILABLE_IN_ALL +const gchar * g_binding_get_source_property (GBinding *binding); +GLIB_AVAILABLE_IN_ALL +const gchar * g_binding_get_target_property (GBinding *binding); +GLIB_AVAILABLE_IN_2_38 +void g_binding_unbind (GBinding *binding); + +GLIB_AVAILABLE_IN_ALL +GBinding *g_object_bind_property (gpointer source, + const gchar *source_property, + gpointer target, + const gchar *target_property, + GBindingFlags flags); +GLIB_AVAILABLE_IN_ALL +GBinding *g_object_bind_property_full (gpointer source, + const gchar *source_property, + gpointer target, + const gchar *target_property, + GBindingFlags flags, + GBindingTransformFunc transform_to, + GBindingTransformFunc transform_from, + gpointer user_data, + GDestroyNotify notify); +GLIB_AVAILABLE_IN_ALL +GBinding *g_object_bind_property_with_closures (gpointer source, + const gchar *source_property, + gpointer target, + const gchar *target_property, + GBindingFlags flags, + GClosure *transform_to, + GClosure *transform_from); + +G_END_DECLS + +#endif /* __G_BINDING_H__ */ diff --git a/include/glib/gobject/gboxed.h b/include/glib/gobject/gboxed.h new file mode 100644 index 0000000000..bcaf0b01a2 --- /dev/null +++ b/include/glib/gobject/gboxed.h @@ -0,0 +1,122 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2000-2001 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __G_BOXED_H__ +#define __G_BOXED_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gtype.h> + +#ifndef __GI_SCANNER__ +#include <gobject/glib-types.h> +#endif + +G_BEGIN_DECLS + +/* --- type macros --- */ +#define G_TYPE_IS_BOXED(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED) +/** + * G_VALUE_HOLDS_BOXED: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values derived + * from type %G_TYPE_BOXED. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_BOXED(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_BOXED)) + + +/* --- typedefs --- */ +/** + * GBoxedCopyFunc: + * @boxed: (not nullable): The boxed structure to be copied. + * + * This function is provided by the user and should produce a copy + * of the passed in boxed structure. + * + * Returns: (not nullable): The newly created copy of the boxed structure. + */ +typedef gpointer (*GBoxedCopyFunc) (gpointer boxed); + +/** + * GBoxedFreeFunc: + * @boxed: (not nullable): The boxed structure to be freed. + * + * This function is provided by the user and should free the boxed + * structure passed. + */ +typedef void (*GBoxedFreeFunc) (gpointer boxed); + + +/* --- prototypes --- */ +GLIB_AVAILABLE_IN_ALL +gpointer g_boxed_copy (GType boxed_type, + gconstpointer src_boxed); +GLIB_AVAILABLE_IN_ALL +void g_boxed_free (GType boxed_type, + gpointer boxed); +GLIB_AVAILABLE_IN_ALL +void g_value_set_boxed (GValue *value, + gconstpointer v_boxed); +GLIB_AVAILABLE_IN_ALL +void g_value_set_static_boxed (GValue *value, + gconstpointer v_boxed); +GLIB_AVAILABLE_IN_ALL +void g_value_take_boxed (GValue *value, + gconstpointer v_boxed); +GLIB_DEPRECATED_FOR(g_value_take_boxed) +void g_value_set_boxed_take_ownership (GValue *value, + gconstpointer v_boxed); +GLIB_AVAILABLE_IN_ALL +gpointer g_value_get_boxed (const GValue *value); +GLIB_AVAILABLE_IN_ALL +gpointer g_value_dup_boxed (const GValue *value); + + +/* --- convenience --- */ +GLIB_AVAILABLE_IN_ALL +GType g_boxed_type_register_static (const gchar *name, + GBoxedCopyFunc boxed_copy, + GBoxedFreeFunc boxed_free); + +/* --- GObject boxed types --- */ +/** + * G_TYPE_CLOSURE: + * + * The #GType for #GClosure. + */ +#define G_TYPE_CLOSURE (g_closure_get_type ()) + +/** + * G_TYPE_VALUE: + * + * The type ID of the "GValue" type which is a boxed type, + * used to pass around pointers to GValues. + */ +#define G_TYPE_VALUE (g_value_get_type ()) + +GLIB_AVAILABLE_IN_ALL +GType g_closure_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_value_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* __G_BOXED_H__ */ diff --git a/include/glib/gobject/gclosure.h b/include/glib/gobject/gclosure.h new file mode 100644 index 0000000000..a5c1c3fcb7 --- /dev/null +++ b/include/glib/gobject/gclosure.h @@ -0,0 +1,317 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2000-2001 Red Hat, Inc. + * Copyright (C) 2005 Imendio AB + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __G_CLOSURE_H__ +#define __G_CLOSURE_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gtype.h> + +G_BEGIN_DECLS + +/* --- defines --- */ +/** + * G_CLOSURE_NEEDS_MARSHAL: + * @closure: a #GClosure + * + * Check if the closure still needs a marshaller. See g_closure_set_marshal(). + * + * Returns: %TRUE if a #GClosureMarshal marshaller has not yet been set on + * @closure. + */ +#define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL) +/** + * G_CLOSURE_N_NOTIFIERS: + * @cl: a #GClosure + * + * Get the total number of notifiers connected with the closure @cl. + * The count includes the meta marshaller, the finalize and invalidate notifiers + * and the marshal guards. Note that each guard counts as two notifiers. + * See g_closure_set_meta_marshal(), g_closure_add_finalize_notifier(), + * g_closure_add_invalidate_notifier() and g_closure_add_marshal_guards(). + * + * Returns: number of notifiers + */ +#define G_CLOSURE_N_NOTIFIERS(cl) (((cl)->n_guards << 1L) + \ + (cl)->n_fnotifiers + (cl)->n_inotifiers) +/** + * G_CCLOSURE_SWAP_DATA: + * @cclosure: a #GCClosure + * + * Checks whether the user data of the #GCClosure should be passed as the + * first parameter to the callback. See g_cclosure_new_swap(). + * + * Returns: %TRUE if data has to be swapped. + */ +#define G_CCLOSURE_SWAP_DATA(cclosure) (((GClosure*) (cclosure))->derivative_flag) +/** + * G_CALLBACK: + * @f: a function pointer. + * + * Cast a function pointer to a #GCallback. + */ +#define G_CALLBACK(f) ((GCallback) (f)) + + +/* -- typedefs --- */ +typedef struct _GClosure GClosure; +typedef struct _GClosureNotifyData GClosureNotifyData; + +/** + * GCallback: + * + * The type used for callback functions in structure definitions and function + * signatures. This doesn't mean that all callback functions must take no + * parameters and return void. The required signature of a callback function + * is determined by the context in which is used (e.g. the signal to which it + * is connected). Use G_CALLBACK() to cast the callback function to a #GCallback. + */ +typedef void (*GCallback) (void); +/** + * GClosureNotify: + * @data: data specified when registering the notification callback + * @closure: the #GClosure on which the notification is emitted + * + * The type used for the various notification callbacks which can be registered + * on closures. + */ +typedef void (*GClosureNotify) (gpointer data, + GClosure *closure); +/** + * GClosureMarshal: + * @closure: the #GClosure to which the marshaller belongs + * @return_value: (nullable): a #GValue to store the return + * value. May be %NULL if the callback of @closure doesn't return a + * value. + * @n_param_values: the length of the @param_values array + * @param_values: (array length=n_param_values): an array of + * #GValues holding the arguments on which to invoke the + * callback of @closure + * @invocation_hint: (nullable): the invocation hint given as the + * last argument to g_closure_invoke() + * @marshal_data: (nullable): additional data specified when + * registering the marshaller, see g_closure_set_marshal() and + * g_closure_set_meta_marshal() + * + * The type used for marshaller functions. + */ +typedef void (*GClosureMarshal) (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +/** + * GVaClosureMarshal: + * @closure: the #GClosure to which the marshaller belongs + * @return_value: (nullable): a #GValue to store the return + * value. May be %NULL if the callback of @closure doesn't return a + * value. + * @instance: (type GObject.TypeInstance): the instance on which the closure is + * invoked. + * @args: va_list of arguments to be passed to the closure. + * @marshal_data: (nullable): additional data specified when + * registering the marshaller, see g_closure_set_marshal() and + * g_closure_set_meta_marshal() + * @n_params: the length of the @param_types array + * @param_types: (array length=n_params): the #GType of each argument from + * @args. + * + * This is the signature of va_list marshaller functions, an optional + * marshaller that can be used in some situations to avoid + * marshalling the signal argument into GValues. + */ +typedef void (* GVaClosureMarshal) (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/** + * GCClosure: + * @closure: the #GClosure + * @callback: the callback function + * + * A #GCClosure is a specialization of #GClosure for C function callbacks. + */ +typedef struct _GCClosure GCClosure; + + +/* --- structures --- */ +struct _GClosureNotifyData +{ + gpointer data; + GClosureNotify notify; +}; +/** + * GClosure: + * @in_marshal: Indicates whether the closure is currently being invoked with + * g_closure_invoke() + * @is_invalid: Indicates whether the closure has been invalidated by + * g_closure_invalidate() + * + * A #GClosure represents a callback supplied by the programmer. + */ +struct _GClosure +{ + /*< private >*/ + volatile guint ref_count : 15; + /* meta_marshal is not used anymore but must be zero for historical reasons + as it was exposed in the G_CLOSURE_N_NOTIFIERS macro */ + volatile guint meta_marshal_nouse : 1; + volatile guint n_guards : 1; + volatile guint n_fnotifiers : 2; /* finalization notifiers */ + volatile guint n_inotifiers : 8; /* invalidation notifiers */ + volatile guint in_inotify : 1; + volatile guint floating : 1; + /*< protected >*/ + volatile guint derivative_flag : 1; + /*< public >*/ + volatile guint in_marshal : 1; + volatile guint is_invalid : 1; + + /*< private >*/ void (*marshal) (GClosure *closure, + GValue /*out*/ *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + /*< protected >*/ gpointer data; + + /*< private >*/ GClosureNotifyData *notifiers; + + /* invariants/constraints: + * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE + * - invocation of all inotifiers occours prior to fnotifiers + * - order of inotifiers is random + * inotifiers may _not_ free/invalidate parameter values (e.g. ->data) + * - order of fnotifiers is random + * - each notifier may only be removed before or during its invocation + * - reference counting may only happen prior to fnotify invocation + * (in that sense, fnotifiers are really finalization handlers) + */ +}; +/* closure for C function calls, callback() is the user function + */ +struct _GCClosure +{ + GClosure closure; + gpointer callback; +}; + + +/* --- prototypes --- */ +GLIB_AVAILABLE_IN_ALL +GClosure* g_cclosure_new (GCallback callback_func, + gpointer user_data, + GClosureNotify destroy_data); +GLIB_AVAILABLE_IN_ALL +GClosure* g_cclosure_new_swap (GCallback callback_func, + gpointer user_data, + GClosureNotify destroy_data); +GLIB_AVAILABLE_IN_ALL +GClosure* g_signal_type_cclosure_new (GType itype, + guint struct_offset); + + +/* --- prototypes --- */ +GLIB_AVAILABLE_IN_ALL +GClosure* g_closure_ref (GClosure *closure); +GLIB_AVAILABLE_IN_ALL +void g_closure_sink (GClosure *closure); +GLIB_AVAILABLE_IN_ALL +void g_closure_unref (GClosure *closure); +/* intimidating */ +GLIB_AVAILABLE_IN_ALL +GClosure* g_closure_new_simple (guint sizeof_closure, + gpointer data); +GLIB_AVAILABLE_IN_ALL +void g_closure_add_finalize_notifier (GClosure *closure, + gpointer notify_data, + GClosureNotify notify_func); +GLIB_AVAILABLE_IN_ALL +void g_closure_remove_finalize_notifier (GClosure *closure, + gpointer notify_data, + GClosureNotify notify_func); +GLIB_AVAILABLE_IN_ALL +void g_closure_add_invalidate_notifier (GClosure *closure, + gpointer notify_data, + GClosureNotify notify_func); +GLIB_AVAILABLE_IN_ALL +void g_closure_remove_invalidate_notifier (GClosure *closure, + gpointer notify_data, + GClosureNotify notify_func); +GLIB_AVAILABLE_IN_ALL +void g_closure_add_marshal_guards (GClosure *closure, + gpointer pre_marshal_data, + GClosureNotify pre_marshal_notify, + gpointer post_marshal_data, + GClosureNotify post_marshal_notify); +GLIB_AVAILABLE_IN_ALL +void g_closure_set_marshal (GClosure *closure, + GClosureMarshal marshal); +GLIB_AVAILABLE_IN_ALL +void g_closure_set_meta_marshal (GClosure *closure, + gpointer marshal_data, + GClosureMarshal meta_marshal); +GLIB_AVAILABLE_IN_ALL +void g_closure_invalidate (GClosure *closure); +GLIB_AVAILABLE_IN_ALL +void g_closure_invoke (GClosure *closure, + GValue /*out*/ *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint); + +/* FIXME: + OK: data_object::destroy -> closure_invalidate(); + MIS: closure_invalidate() -> disconnect(closure); + MIS: disconnect(closure) -> (unlink) closure_unref(); + OK: closure_finalize() -> g_free (data_string); + + random remarks: + - need marshaller repo with decent aliasing to base types + - provide marshaller collection, virtually covering anything out there +*/ + +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_generic (GClosure *closure, + GValue *return_gvalue, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_generic_va (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args_list, + gpointer marshal_data, + int n_params, + GType *param_types); + + +G_END_DECLS + +#endif /* __G_CLOSURE_H__ */ diff --git a/include/glib/gobject/genums.h b/include/glib/gobject/genums.h new file mode 100644 index 0000000000..c66ce45c00 --- /dev/null +++ b/include/glib/gobject/genums.h @@ -0,0 +1,279 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __G_ENUMS_H__ +#define __G_ENUMS_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gtype.h> + +G_BEGIN_DECLS + +/* --- type macros --- */ +/** + * G_TYPE_IS_ENUM: + * @type: a #GType ID. + * + * Checks whether @type "is a" %G_TYPE_ENUM. + * + * Returns: %TRUE if @type "is a" %G_TYPE_ENUM. + */ +#define G_TYPE_IS_ENUM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM) +/** + * G_ENUM_CLASS: + * @class: a valid #GEnumClass + * + * Casts a derived #GEnumClass structure into a #GEnumClass structure. + */ +#define G_ENUM_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_ENUM, GEnumClass)) +/** + * G_IS_ENUM_CLASS: + * @class: a #GEnumClass + * + * Checks whether @class "is a" valid #GEnumClass structure of type %G_TYPE_ENUM + * or derived. + */ +#define G_IS_ENUM_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_ENUM)) +/** + * G_ENUM_CLASS_TYPE: + * @class: a #GEnumClass + * + * Get the type identifier from a given #GEnumClass structure. + * + * Returns: the #GType + */ +#define G_ENUM_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class)) +/** + * G_ENUM_CLASS_TYPE_NAME: + * @class: a #GEnumClass + * + * Get the static type name from a given #GEnumClass structure. + * + * Returns: the type name. + */ +#define G_ENUM_CLASS_TYPE_NAME(class) (g_type_name (G_ENUM_CLASS_TYPE (class))) + + +/** + * G_TYPE_IS_FLAGS: + * @type: a #GType ID. + * + * Checks whether @type "is a" %G_TYPE_FLAGS. + * + * Returns: %TRUE if @type "is a" %G_TYPE_FLAGS. + */ +#define G_TYPE_IS_FLAGS(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS) +/** + * G_FLAGS_CLASS: + * @class: a valid #GFlagsClass + * + * Casts a derived #GFlagsClass structure into a #GFlagsClass structure. + */ +#define G_FLAGS_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_FLAGS, GFlagsClass)) +/** + * G_IS_FLAGS_CLASS: + * @class: a #GFlagsClass + * + * Checks whether @class "is a" valid #GFlagsClass structure of type %G_TYPE_FLAGS + * or derived. + */ +#define G_IS_FLAGS_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_FLAGS)) +/** + * G_FLAGS_CLASS_TYPE: + * @class: a #GFlagsClass + * + * Get the type identifier from a given #GFlagsClass structure. + * + * Returns: the #GType + */ +#define G_FLAGS_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class)) +/** + * G_FLAGS_CLASS_TYPE_NAME: + * @class: a #GFlagsClass + * + * Get the static type name from a given #GFlagsClass structure. + * + * Returns: the type name. + */ +#define G_FLAGS_CLASS_TYPE_NAME(class) (g_type_name (G_FLAGS_CLASS_TYPE (class))) + + +/** + * G_VALUE_HOLDS_ENUM: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values derived from type %G_TYPE_ENUM. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_ENUM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ENUM)) +/** + * G_VALUE_HOLDS_FLAGS: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values derived from type %G_TYPE_FLAGS. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_FLAGS(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLAGS)) + + +/* --- enum/flag values & classes --- */ +typedef struct _GEnumClass GEnumClass; +typedef struct _GFlagsClass GFlagsClass; +typedef struct _GEnumValue GEnumValue; +typedef struct _GFlagsValue GFlagsValue; + +/** + * GEnumClass: + * @g_type_class: the parent class + * @minimum: the smallest possible value. + * @maximum: the largest possible value. + * @n_values: the number of possible values. + * @values: an array of #GEnumValue structs describing the + * individual values. + * + * The class of an enumeration type holds information about its + * possible values. + */ +struct _GEnumClass +{ + GTypeClass g_type_class; + + /*< public >*/ + gint minimum; + gint maximum; + guint n_values; + GEnumValue *values; +}; +/** + * GFlagsClass: + * @g_type_class: the parent class + * @mask: a mask covering all possible values. + * @n_values: the number of possible values. + * @values: an array of #GFlagsValue structs describing the + * individual values. + * + * The class of a flags type holds information about its + * possible values. + */ +struct _GFlagsClass +{ + GTypeClass g_type_class; + + /*< public >*/ + guint mask; + guint n_values; + GFlagsValue *values; +}; +/** + * GEnumValue: + * @value: the enum value + * @value_name: the name of the value + * @value_nick: the nickname of the value + * + * A structure which contains a single enum value, its name, and its + * nickname. + */ +struct _GEnumValue +{ + gint value; + const gchar *value_name; + const gchar *value_nick; +}; +/** + * GFlagsValue: + * @value: the flags value + * @value_name: the name of the value + * @value_nick: the nickname of the value + * + * A structure which contains a single flags value, its name, and its + * nickname. + */ +struct _GFlagsValue +{ + guint value; + const gchar *value_name; + const gchar *value_nick; +}; + + +/* --- prototypes --- */ +GLIB_AVAILABLE_IN_ALL +GEnumValue* g_enum_get_value (GEnumClass *enum_class, + gint value); +GLIB_AVAILABLE_IN_ALL +GEnumValue* g_enum_get_value_by_name (GEnumClass *enum_class, + const gchar *name); +GLIB_AVAILABLE_IN_ALL +GEnumValue* g_enum_get_value_by_nick (GEnumClass *enum_class, + const gchar *nick); +GLIB_AVAILABLE_IN_ALL +GFlagsValue* g_flags_get_first_value (GFlagsClass *flags_class, + guint value); +GLIB_AVAILABLE_IN_ALL +GFlagsValue* g_flags_get_value_by_name (GFlagsClass *flags_class, + const gchar *name); +GLIB_AVAILABLE_IN_ALL +GFlagsValue* g_flags_get_value_by_nick (GFlagsClass *flags_class, + const gchar *nick); +GLIB_AVAILABLE_IN_2_54 +gchar *g_enum_to_string (GType g_enum_type, + gint value); +GLIB_AVAILABLE_IN_2_54 +gchar *g_flags_to_string (GType flags_type, + guint value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_enum (GValue *value, + gint v_enum); +GLIB_AVAILABLE_IN_ALL +gint g_value_get_enum (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_flags (GValue *value, + guint v_flags); +GLIB_AVAILABLE_IN_ALL +guint g_value_get_flags (const GValue *value); + + + +/* --- registration functions --- */ +/* const_static_values is a NULL terminated array of enum/flags + * values that is taken over! + */ +GLIB_AVAILABLE_IN_ALL +GType g_enum_register_static (const gchar *name, + const GEnumValue *const_static_values); +GLIB_AVAILABLE_IN_ALL +GType g_flags_register_static (const gchar *name, + const GFlagsValue *const_static_values); +/* functions to complete the type information + * for enums/flags implemented by plugins + */ +GLIB_AVAILABLE_IN_ALL +void g_enum_complete_type_info (GType g_enum_type, + GTypeInfo *info, + const GEnumValue *const_values); +GLIB_AVAILABLE_IN_ALL +void g_flags_complete_type_info (GType g_flags_type, + GTypeInfo *info, + const GFlagsValue *const_values); + +G_END_DECLS + +#endif /* __G_ENUMS_H__ */ diff --git a/include/glib/gobject/glib-enumtypes.h b/include/glib/gobject/glib-enumtypes.h new file mode 100644 index 0000000000..9844954982 --- /dev/null +++ b/include/glib/gobject/glib-enumtypes.h @@ -0,0 +1,25 @@ + +/* This file is generated by glib-mkenums, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */ + +#ifndef __GOBJECT_ENUM_TYPES_H__ +#define __GOBJECT_ENUM_TYPES_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +/* enumerations from "../gobject/../glib/gunicode.h" */ +GLIB_AVAILABLE_IN_2_60 GType g_unicode_type_get_type (void) G_GNUC_CONST; +#define G_TYPE_UNICODE_TYPE (g_unicode_type_get_type ()) +GLIB_AVAILABLE_IN_2_60 GType g_unicode_break_type_get_type (void) G_GNUC_CONST; +#define G_TYPE_UNICODE_BREAK_TYPE (g_unicode_break_type_get_type ()) +GLIB_AVAILABLE_IN_2_60 GType g_unicode_script_get_type (void) G_GNUC_CONST; +#define G_TYPE_UNICODE_SCRIPT (g_unicode_script_get_type ()) +GLIB_AVAILABLE_IN_2_60 GType g_normalize_mode_get_type (void) G_GNUC_CONST; +#define G_TYPE_NORMALIZE_MODE (g_normalize_mode_get_type ()) +G_END_DECLS + +#endif /* __GOBJECT_ENUM_TYPES_H__ */ + +/* Generated data ends here */ + diff --git a/include/glib/gobject/glib-types.h b/include/glib/gobject/glib-types.h new file mode 100644 index 0000000000..78a199d1d1 --- /dev/null +++ b/include/glib/gobject/glib-types.h @@ -0,0 +1,362 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2000-2001 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __GLIB_TYPES_H__ +#define __GLIB_TYPES_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) && !defined(GLIB_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <glib.h> + +G_BEGIN_DECLS + +/* A hack necesssary to preprocess this file with g-ir-scanner */ +#ifdef __GI_SCANNER__ +typedef gsize GType; +#endif + +/* --- GLib boxed types --- */ +/** + * G_TYPE_DATE: + * + * The #GType for #GDate. + */ +#define G_TYPE_DATE (g_date_get_type ()) + +/** + * G_TYPE_STRV: + * + * The #GType for a boxed type holding a %NULL-terminated array of strings. + * + * The code fragments in the following example show the use of a property of + * type #G_TYPE_STRV with g_object_class_install_property(), g_object_set() + * and g_object_get(). + * + * |[ + * g_object_class_install_property (object_class, + * PROP_AUTHORS, + * g_param_spec_boxed ("authors", + * _("Authors"), + * _("List of authors"), + * G_TYPE_STRV, + * G_PARAM_READWRITE)); + * + * gchar *authors[] = { "Owen", "Tim", NULL }; + * g_object_set (obj, "authors", authors, NULL); + * + * gchar *writers[]; + * g_object_get (obj, "authors", &writers, NULL); + * /* do something with writers */ + * g_strfreev (writers); + * ]| + * + * Since: 2.4 + */ +#define G_TYPE_STRV (g_strv_get_type ()) + +/** + * G_TYPE_GSTRING: + * + * The #GType for #GString. + */ +#define G_TYPE_GSTRING (g_gstring_get_type ()) + +/** + * G_TYPE_HASH_TABLE: + * + * The #GType for a boxed type holding a #GHashTable reference. + * + * Since: 2.10 + */ +#define G_TYPE_HASH_TABLE (g_hash_table_get_type ()) + +/** + * G_TYPE_REGEX: + * + * The #GType for a boxed type holding a #GRegex reference. + * + * Since: 2.14 + */ +#define G_TYPE_REGEX (g_regex_get_type ()) + +/** + * G_TYPE_MATCH_INFO: + * + * The #GType for a boxed type holding a #GMatchInfo reference. + * + * Since: 2.30 + */ +#define G_TYPE_MATCH_INFO (g_match_info_get_type ()) + +/** + * G_TYPE_ARRAY: + * + * The #GType for a boxed type holding a #GArray reference. + * + * Since: 2.22 + */ +#define G_TYPE_ARRAY (g_array_get_type ()) + +/** + * G_TYPE_BYTE_ARRAY: + * + * The #GType for a boxed type holding a #GByteArray reference. + * + * Since: 2.22 + */ +#define G_TYPE_BYTE_ARRAY (g_byte_array_get_type ()) + +/** + * G_TYPE_PTR_ARRAY: + * + * The #GType for a boxed type holding a #GPtrArray reference. + * + * Since: 2.22 + */ +#define G_TYPE_PTR_ARRAY (g_ptr_array_get_type ()) + +/** + * G_TYPE_BYTES: + * + * The #GType for #GBytes. + * + * Since: 2.32 + */ +#define G_TYPE_BYTES (g_bytes_get_type ()) + +/** + * G_TYPE_VARIANT_TYPE: + * + * The #GType for a boxed type holding a #GVariantType. + * + * Since: 2.24 + */ +#define G_TYPE_VARIANT_TYPE (g_variant_type_get_gtype ()) + +/** + * G_TYPE_ERROR: + * + * The #GType for a boxed type holding a #GError. + * + * Since: 2.26 + */ +#define G_TYPE_ERROR (g_error_get_type ()) + +/** + * G_TYPE_DATE_TIME: + * + * The #GType for a boxed type holding a #GDateTime. + * + * Since: 2.26 + */ +#define G_TYPE_DATE_TIME (g_date_time_get_type ()) + +/** + * G_TYPE_TIME_ZONE: + * + * The #GType for a boxed type holding a #GTimeZone. + * + * Since: 2.34 + */ +#define G_TYPE_TIME_ZONE (g_time_zone_get_type ()) + +/** + * G_TYPE_IO_CHANNEL: + * + * The #GType for #GIOChannel. + */ +#define G_TYPE_IO_CHANNEL (g_io_channel_get_type ()) + +/** + * G_TYPE_IO_CONDITION: + * + * The #GType for #GIOCondition. + */ +#define G_TYPE_IO_CONDITION (g_io_condition_get_type ()) + +/** + * G_TYPE_VARIANT_BUILDER: + * + * The #GType for a boxed type holding a #GVariantBuilder. + * + * Since: 2.30 + */ +#define G_TYPE_VARIANT_BUILDER (g_variant_builder_get_type ()) + +/** + * G_TYPE_VARIANT_DICT: + * + * The #GType for a boxed type holding a #GVariantDict. + * + * Since: 2.40 + */ +#define G_TYPE_VARIANT_DICT (g_variant_dict_get_type ()) + +/** + * G_TYPE_MAIN_LOOP: + * + * The #GType for a boxed type holding a #GMainLoop. + * + * Since: 2.30 + */ +#define G_TYPE_MAIN_LOOP (g_main_loop_get_type ()) + +/** + * G_TYPE_MAIN_CONTEXT: + * + * The #GType for a boxed type holding a #GMainContext. + * + * Since: 2.30 + */ +#define G_TYPE_MAIN_CONTEXT (g_main_context_get_type ()) + +/** + * G_TYPE_SOURCE: + * + * The #GType for a boxed type holding a #GSource. + * + * Since: 2.30 + */ +#define G_TYPE_SOURCE (g_source_get_type ()) + +/** + * G_TYPE_POLLFD: + * + * The #GType for a boxed type holding a #GPollFD. + * + * Since: 2.36 + */ +#define G_TYPE_POLLFD (g_pollfd_get_type ()) + +/** + * G_TYPE_MARKUP_PARSE_CONTEXT: + * + * The #GType for a boxed type holding a #GMarkupParseContext. + * + * Since: 2.36 + */ +#define G_TYPE_MARKUP_PARSE_CONTEXT (g_markup_parse_context_get_type ()) + +/** + * G_TYPE_KEY_FILE: + * + * The #GType for a boxed type holding a #GKeyFile. + * + * Since: 2.32 + */ +#define G_TYPE_KEY_FILE (g_key_file_get_type ()) + +/** + * G_TYPE_MAPPED_FILE: + * + * The #GType for a boxed type holding a #GMappedFile. + * + * Since: 2.40 + */ +#define G_TYPE_MAPPED_FILE (g_mapped_file_get_type ()) + +/** + * G_TYPE_THREAD: + * + * The #GType for a boxed type holding a #GThread. + * + * Since: 2.36 + */ +#define G_TYPE_THREAD (g_thread_get_type ()) + +/** + * G_TYPE_CHECKSUM: + * + * The #GType for a boxed type holding a #GChecksum. + * + * Since: 2.36 + */ +#define G_TYPE_CHECKSUM (g_checksum_get_type ()) + +/** + * G_TYPE_OPTION_GROUP: + * + * The #GType for a boxed type holding a #GOptionGroup. + * + * Since: 2.44 + */ +#define G_TYPE_OPTION_GROUP (g_option_group_get_type ()) + +GLIB_AVAILABLE_IN_ALL +GType g_date_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_strv_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_gstring_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_hash_table_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_array_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_byte_array_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_ptr_array_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_bytes_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_variant_type_get_gtype (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_regex_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_30 +GType g_match_info_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_error_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_date_time_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_time_zone_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_io_channel_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_io_condition_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_variant_builder_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_40 +GType g_variant_dict_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +GType g_key_file_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_30 +GType g_main_loop_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_30 +GType g_main_context_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_30 +GType g_source_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_36 +GType g_pollfd_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_36 +GType g_thread_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_36 +GType g_checksum_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_36 +GType g_markup_parse_context_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_40 +GType g_mapped_file_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_2_44 +GType g_option_group_get_type (void) G_GNUC_CONST; + +GLIB_DEPRECATED_FOR('G_TYPE_VARIANT') +GType g_variant_get_gtype (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* __GLIB_TYPES_H__ */ diff --git a/include/glib/gobject/gmarshal.h b/include/glib/gobject/gmarshal.h new file mode 100644 index 0000000000..fdd6c042e1 --- /dev/null +++ b/include/glib/gobject/gmarshal.h @@ -0,0 +1,434 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __G_MARSHAL_H__ +#define __G_MARSHAL_H__ + +G_BEGIN_DECLS + +/* VOID:VOID */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__VOID (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__VOIDv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:BOOLEAN */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__BOOLEAN (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__BOOLEANv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:CHAR */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__CHAR (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__CHARv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:UCHAR */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__UCHAR (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__UCHARv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:INT */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__INT (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__INTv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:UINT */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__UINT (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__UINTv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:LONG */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__LONG (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__LONGv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:ULONG */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__ULONG (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__ULONGv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:ENUM */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__ENUM (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__ENUMv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:FLAGS */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__FLAGS (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__FLAGSv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:FLOAT */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__FLOAT (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__FLOATv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:DOUBLE */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__DOUBLE (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__DOUBLEv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:STRING */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__STRING (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__STRINGv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:PARAM */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__PARAM (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__PARAMv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:BOXED */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__BOXED (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__BOXEDv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:POINTER */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__POINTER (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__POINTERv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:OBJECT */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__OBJECT (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__OBJECTv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:VARIANT */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__VARIANT (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__VARIANTv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* VOID:UINT,POINTER */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__UINT_POINTER (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_VOID__UINT_POINTERv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* BOOL:FLAGS */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_BOOLEAN__FLAGS (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_BOOLEAN__FLAGSv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/** + * g_cclosure_marshal_BOOL__FLAGS: + * @closure: A #GClosure. + * @return_value: A #GValue to store the return value. May be %NULL + * if the callback of closure doesn't return a value. + * @n_param_values: The length of the @param_values array. + * @param_values: An array of #GValues holding the arguments + * on which to invoke the callback of closure. + * @invocation_hint: The invocation hint given as the last argument to + * g_closure_invoke(). + * @marshal_data: Additional data specified when registering the + * marshaller, see g_closure_set_marshal() and + * g_closure_set_meta_marshal() + * + * An old alias for g_cclosure_marshal_BOOLEAN__FLAGS(). + */ +#define g_cclosure_marshal_BOOL__FLAGS g_cclosure_marshal_BOOLEAN__FLAGS + +/* STRING:OBJECT,POINTER */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_STRING__OBJECT_POINTER (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_STRING__OBJECT_POINTERv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/* BOOL:BOXED,BOXED */ +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_BOOLEAN__BOXED_BOXED (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +GLIB_AVAILABLE_IN_ALL +void g_cclosure_marshal_BOOLEAN__BOXED_BOXEDv (GClosure *closure, + GValue *return_value, + gpointer instance, + va_list args, + gpointer marshal_data, + int n_params, + GType *param_types); + +/** + * g_cclosure_marshal_BOOL__BOXED_BOXED: + * @closure: A #GClosure. + * @return_value: A #GValue to store the return value. May be %NULL + * if the callback of closure doesn't return a value. + * @n_param_values: The length of the @param_values array. + * @param_values: An array of #GValues holding the arguments + * on which to invoke the callback of closure. + * @invocation_hint: The invocation hint given as the last argument to + * g_closure_invoke(). + * @marshal_data: Additional data specified when registering the + * marshaller, see g_closure_set_marshal() and + * g_closure_set_meta_marshal() + * + * An old alias for g_cclosure_marshal_BOOLEAN__BOXED_BOXED(). + */ +#define g_cclosure_marshal_BOOL__BOXED_BOXED g_cclosure_marshal_BOOLEAN__BOXED_BOXED + +G_END_DECLS + +#endif /* __G_MARSHAL_H__ */ diff --git a/include/glib/gobject/gobject-autocleanups.h b/include/glib/gobject/gobject-autocleanups.h new file mode 100644 index 0000000000..1613857ecd --- /dev/null +++ b/include/glib/gobject/gobject-autocleanups.h @@ -0,0 +1,31 @@ +/* + * Copyright © 2015 Canonical Limited + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <http://www.gnu.org/licenses/>. + * + * Author: Ryan Lortie <desrt@desrt.ca> + */ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GClosure, g_closure_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GEnumClass, g_type_class_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFlagsClass, g_type_class_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GObject, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GInitiallyUnowned, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GParamSpec, g_param_spec_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTypeClass, g_type_class_unref) +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GValue, g_value_unset) diff --git a/include/glib/gobject/gobject.h b/include/glib/gobject/gobject.h new file mode 100644 index 0000000000..91b9f63283 --- /dev/null +++ b/include/glib/gobject/gobject.h @@ -0,0 +1,899 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __G_OBJECT_H__ +#define __G_OBJECT_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gtype.h> +#include <gobject/gvalue.h> +#include <gobject/gparam.h> +#include <gobject/gclosure.h> +#include <gobject/gsignal.h> +#include <gobject/gboxed.h> + +G_BEGIN_DECLS + +/* --- type macros --- */ +/** + * G_TYPE_IS_OBJECT: + * @type: Type id to check + * + * Check if the passed in type id is a %G_TYPE_OBJECT or derived from it. + * + * Returns: %FALSE or %TRUE, indicating whether @type is a %G_TYPE_OBJECT. + */ +#define G_TYPE_IS_OBJECT(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT) +/** + * G_OBJECT: + * @object: Object which is subject to casting. + * + * Casts a #GObject or derived pointer into a (GObject*) pointer. + * Depending on the current debugging level, this function may invoke + * certain runtime checks to identify invalid casts. + */ +#define G_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject)) +/** + * G_OBJECT_CLASS: + * @class: a valid #GObjectClass + * + * Casts a derived #GObjectClass structure into a #GObjectClass structure. + */ +#define G_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass)) +/** + * G_IS_OBJECT: + * @object: Instance to check for being a %G_TYPE_OBJECT. + * + * Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_OBJECT. + */ +#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_42 +#define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE ((object), G_TYPE_OBJECT)) +#else +#define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT)) +#endif +/** + * G_IS_OBJECT_CLASS: + * @class: a #GObjectClass + * + * Checks whether @class "is a" valid #GObjectClass structure of type + * %G_TYPE_OBJECT or derived. + */ +#define G_IS_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT)) +/** + * G_OBJECT_GET_CLASS: + * @object: a #GObject instance. + * + * Get the class structure associated to a #GObject instance. + * + * Returns: pointer to object class structure. + */ +#define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass)) +/** + * G_OBJECT_TYPE: + * @object: Object to return the type id for. + * + * Get the type id of an object. + * + * Returns: Type id of @object. + */ +#define G_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object)) +/** + * G_OBJECT_TYPE_NAME: + * @object: Object to return the type name for. + * + * Get the name of an object's type. + * + * Returns: Type name of @object. The string is owned by the type system and + * should not be freed. + */ +#define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object))) +/** + * G_OBJECT_CLASS_TYPE: + * @class: a valid #GObjectClass + * + * Get the type id of a class structure. + * + * Returns: Type id of @class. + */ +#define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class)) +/** + * G_OBJECT_CLASS_NAME: + * @class: a valid #GObjectClass + * + * Return the name of a class structure's type. + * + * Returns: Type name of @class. The string is owned by the type system and + * should not be freed. + */ +#define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class))) +/** + * G_VALUE_HOLDS_OBJECT: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values derived from type %G_TYPE_OBJECT. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT)) + +/* --- type macros --- */ +/** + * G_TYPE_INITIALLY_UNOWNED: + * + * The type for #GInitiallyUnowned. + */ +#define G_TYPE_INITIALLY_UNOWNED (g_initially_unowned_get_type()) +/** + * G_INITIALLY_UNOWNED: + * @object: Object which is subject to casting. + * + * Casts a #GInitiallyUnowned or derived pointer into a (GInitiallyUnowned*) + * pointer. Depending on the current debugging level, this function may invoke + * certain runtime checks to identify invalid casts. + */ +#define G_INITIALLY_UNOWNED(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnowned)) +/** + * G_INITIALLY_UNOWNED_CLASS: + * @class: a valid #GInitiallyUnownedClass + * + * Casts a derived #GInitiallyUnownedClass structure into a + * #GInitiallyUnownedClass structure. + */ +#define G_INITIALLY_UNOWNED_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass)) +/** + * G_IS_INITIALLY_UNOWNED: + * @object: Instance to check for being a %G_TYPE_INITIALLY_UNOWNED. + * + * Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_INITIALLY_UNOWNED. + */ +#define G_IS_INITIALLY_UNOWNED(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_INITIALLY_UNOWNED)) +/** + * G_IS_INITIALLY_UNOWNED_CLASS: + * @class: a #GInitiallyUnownedClass + * + * Checks whether @class "is a" valid #GInitiallyUnownedClass structure of type + * %G_TYPE_INITIALLY_UNOWNED or derived. + */ +#define G_IS_INITIALLY_UNOWNED_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_INITIALLY_UNOWNED)) +/** + * G_INITIALLY_UNOWNED_GET_CLASS: + * @object: a #GInitiallyUnowned instance. + * + * Get the class structure associated to a #GInitiallyUnowned instance. + * + * Returns: pointer to object class structure. + */ +#define G_INITIALLY_UNOWNED_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass)) +/* GInitiallyUnowned ia a GObject with initially floating reference count */ + + +/* --- typedefs & structures --- */ +typedef struct _GObject GObject; +typedef struct _GObjectClass GObjectClass; +typedef struct _GObject GInitiallyUnowned; +typedef struct _GObjectClass GInitiallyUnownedClass; +typedef struct _GObjectConstructParam GObjectConstructParam; +/** + * GObjectGetPropertyFunc: + * @object: a #GObject + * @property_id: the numeric id under which the property was registered with + * g_object_class_install_property(). + * @value: a #GValue to return the property value in + * @pspec: the #GParamSpec describing the property + * + * The type of the @get_property function of #GObjectClass. + */ +typedef void (*GObjectGetPropertyFunc) (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); +/** + * GObjectSetPropertyFunc: + * @object: a #GObject + * @property_id: the numeric id under which the property was registered with + * g_object_class_install_property(). + * @value: the new value for the property + * @pspec: the #GParamSpec describing the property + * + * The type of the @set_property function of #GObjectClass. + */ +typedef void (*GObjectSetPropertyFunc) (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +/** + * GObjectFinalizeFunc: + * @object: the #GObject being finalized + * + * The type of the @finalize function of #GObjectClass. + */ +typedef void (*GObjectFinalizeFunc) (GObject *object); +/** + * GWeakNotify: + * @data: data that was provided when the weak reference was established + * @where_the_object_was: the object being finalized + * + * A #GWeakNotify function can be added to an object as a callback that gets + * triggered when the object is finalized. Since the object is already being + * finalized when the #GWeakNotify is called, there's not much you could do + * with the object, apart from e.g. using its address as hash-index or the like. + */ +typedef void (*GWeakNotify) (gpointer data, + GObject *where_the_object_was); +/** + * GObject: + * + * All the fields in the GObject structure are private + * to the #GObject implementation and should never be accessed directly. + */ +struct _GObject +{ + GTypeInstance g_type_instance; + + /*< private >*/ + volatile guint ref_count; + GData *qdata; +}; +/** + * GObjectClass: + * @g_type_class: the parent class + * @constructor: the @constructor function is called by g_object_new () to + * complete the object initialization after all the construction properties are + * set. The first thing a @constructor implementation must do is chain up to the + * @constructor of the parent class. Overriding @constructor should be rarely + * needed, e.g. to handle construct properties, or to implement singletons. + * @set_property: the generic setter for all properties of this type. Should be + * overridden for every type with properties. If implementations of + * @set_property don't emit property change notification explicitly, this will + * be done implicitly by the type system. However, if the notify signal is + * emitted explicitly, the type system will not emit it a second time. + * @get_property: the generic getter for all properties of this type. Should be + * overridden for every type with properties. + * @dispose: the @dispose function is supposed to drop all references to other + * objects, but keep the instance otherwise intact, so that client method + * invocations still work. It may be run multiple times (due to reference + * loops). Before returning, @dispose should chain up to the @dispose method + * of the parent class. + * @finalize: instance finalization function, should finish the finalization of + * the instance begun in @dispose and chain up to the @finalize method of the + * parent class. + * @dispatch_properties_changed: emits property change notification for a bunch + * of properties. Overriding @dispatch_properties_changed should be rarely + * needed. + * @notify: the class closure for the notify signal + * @constructed: the @constructed function is called by g_object_new() as the + * final step of the object creation process. At the point of the call, all + * construction properties have been set on the object. The purpose of this + * call is to allow for object initialisation steps that can only be performed + * after construction properties have been set. @constructed implementors + * should chain up to the @constructed call of their parent class to allow it + * to complete its initialisation. + * + * The class structure for the GObject type. + * + * |[<!-- language="C" --> + * // Example of implementing a singleton using a constructor. + * static MySingleton *the_singleton = NULL; + * + * static GObject* + * my_singleton_constructor (GType type, + * guint n_construct_params, + * GObjectConstructParam *construct_params) + * { + * GObject *object; + * + * if (!the_singleton) + * { + * object = G_OBJECT_CLASS (parent_class)->constructor (type, + * n_construct_params, + * construct_params); + * the_singleton = MY_SINGLETON (object); + * } + * else + * object = g_object_ref (G_OBJECT (the_singleton)); + * + * return object; + * } + * ]| + */ +struct _GObjectClass +{ + GTypeClass g_type_class; + + /*< private >*/ + GSList *construct_properties; + + /*< public >*/ + /* seldom overidden */ + GObject* (*constructor) (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties); + /* overridable methods */ + void (*set_property) (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); + void (*get_property) (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + void (*dispose) (GObject *object); + void (*finalize) (GObject *object); + /* seldom overidden */ + void (*dispatch_properties_changed) (GObject *object, + guint n_pspecs, + GParamSpec **pspecs); + /* signals */ + void (*notify) (GObject *object, + GParamSpec *pspec); + + /* called when done constructing */ + void (*constructed) (GObject *object); + + /*< private >*/ + gsize flags; + + /* padding */ + gpointer pdummy[6]; +}; +/** + * GObjectConstructParam: + * @pspec: the #GParamSpec of the construct parameter + * @value: the value to set the parameter to + * + * The GObjectConstructParam struct is an auxiliary + * structure used to hand #GParamSpec/#GValue pairs to the @constructor of + * a #GObjectClass. + */ +struct _GObjectConstructParam +{ + GParamSpec *pspec; + GValue *value; +}; + +/** + * GInitiallyUnowned: + * + * All the fields in the GInitiallyUnowned structure + * are private to the #GInitiallyUnowned implementation and should never be + * accessed directly. + */ +/** + * GInitiallyUnownedClass: + * + * The class structure for the GInitiallyUnowned type. + */ + + +/* --- prototypes --- */ +GLIB_AVAILABLE_IN_ALL +GType g_initially_unowned_get_type (void); +GLIB_AVAILABLE_IN_ALL +void g_object_class_install_property (GObjectClass *oclass, + guint property_id, + GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_object_class_find_property (GObjectClass *oclass, + const gchar *property_name); +GLIB_AVAILABLE_IN_ALL +GParamSpec**g_object_class_list_properties (GObjectClass *oclass, + guint *n_properties); +GLIB_AVAILABLE_IN_ALL +void g_object_class_override_property (GObjectClass *oclass, + guint property_id, + const gchar *name); +GLIB_AVAILABLE_IN_ALL +void g_object_class_install_properties (GObjectClass *oclass, + guint n_pspecs, + GParamSpec **pspecs); + +GLIB_AVAILABLE_IN_ALL +void g_object_interface_install_property (gpointer g_iface, + GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_object_interface_find_property (gpointer g_iface, + const gchar *property_name); +GLIB_AVAILABLE_IN_ALL +GParamSpec**g_object_interface_list_properties (gpointer g_iface, + guint *n_properties_p); + +GLIB_AVAILABLE_IN_ALL +GType g_object_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +gpointer g_object_new (GType object_type, + const gchar *first_property_name, + ...); +GLIB_AVAILABLE_IN_2_54 +GObject* g_object_new_with_properties (GType object_type, + guint n_properties, + const char *names[], + const GValue values[]); + +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + +GLIB_DEPRECATED_IN_2_54_FOR(g_object_new_with_properties) +gpointer g_object_newv (GType object_type, + guint n_parameters, + GParameter *parameters); + +G_GNUC_END_IGNORE_DEPRECATIONS + +GLIB_AVAILABLE_IN_ALL +GObject* g_object_new_valist (GType object_type, + const gchar *first_property_name, + va_list var_args); +GLIB_AVAILABLE_IN_ALL +void g_object_set (gpointer object, + const gchar *first_property_name, + ...) G_GNUC_NULL_TERMINATED; +GLIB_AVAILABLE_IN_ALL +void g_object_get (gpointer object, + const gchar *first_property_name, + ...) G_GNUC_NULL_TERMINATED; +GLIB_AVAILABLE_IN_ALL +gpointer g_object_connect (gpointer object, + const gchar *signal_spec, + ...) G_GNUC_NULL_TERMINATED; +GLIB_AVAILABLE_IN_ALL +void g_object_disconnect (gpointer object, + const gchar *signal_spec, + ...) G_GNUC_NULL_TERMINATED; +GLIB_AVAILABLE_IN_2_54 +void g_object_setv (GObject *object, + guint n_properties, + const gchar *names[], + const GValue values[]); +GLIB_AVAILABLE_IN_ALL +void g_object_set_valist (GObject *object, + const gchar *first_property_name, + va_list var_args); +GLIB_AVAILABLE_IN_2_54 +void g_object_getv (GObject *object, + guint n_properties, + const gchar *names[], + GValue values[]); +GLIB_AVAILABLE_IN_ALL +void g_object_get_valist (GObject *object, + const gchar *first_property_name, + va_list var_args); +GLIB_AVAILABLE_IN_ALL +void g_object_set_property (GObject *object, + const gchar *property_name, + const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_object_get_property (GObject *object, + const gchar *property_name, + GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_object_freeze_notify (GObject *object); +GLIB_AVAILABLE_IN_ALL +void g_object_notify (GObject *object, + const gchar *property_name); +GLIB_AVAILABLE_IN_ALL +void g_object_notify_by_pspec (GObject *object, + GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +void g_object_thaw_notify (GObject *object); +GLIB_AVAILABLE_IN_ALL +gboolean g_object_is_floating (gpointer object); +GLIB_AVAILABLE_IN_ALL +gpointer g_object_ref_sink (gpointer object); +GLIB_AVAILABLE_IN_ALL +gpointer g_object_ref (gpointer object); +GLIB_AVAILABLE_IN_ALL +void g_object_unref (gpointer object); +GLIB_AVAILABLE_IN_ALL +void g_object_weak_ref (GObject *object, + GWeakNotify notify, + gpointer data); +GLIB_AVAILABLE_IN_ALL +void g_object_weak_unref (GObject *object, + GWeakNotify notify, + gpointer data); +GLIB_AVAILABLE_IN_ALL +void g_object_add_weak_pointer (GObject *object, + gpointer *weak_pointer_location); +GLIB_AVAILABLE_IN_ALL +void g_object_remove_weak_pointer (GObject *object, + gpointer *weak_pointer_location); + +#if defined(g_has_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_56 +/* Make reference APIs type safe with macros */ +#define g_object_ref(Obj) ((__typeof__(Obj)) (g_object_ref) (Obj)) +#define g_object_ref_sink(Obj) ((__typeof__(Obj)) (g_object_ref_sink) (Obj)) +#endif + +/** + * GToggleNotify: + * @data: Callback data passed to g_object_add_toggle_ref() + * @object: The object on which g_object_add_toggle_ref() was called. + * @is_last_ref: %TRUE if the toggle reference is now the + * last reference to the object. %FALSE if the toggle + * reference was the last reference and there are now other + * references. + * + * A callback function used for notification when the state + * of a toggle reference changes. See g_object_add_toggle_ref(). + */ +typedef void (*GToggleNotify) (gpointer data, + GObject *object, + gboolean is_last_ref); + +GLIB_AVAILABLE_IN_ALL +void g_object_add_toggle_ref (GObject *object, + GToggleNotify notify, + gpointer data); +GLIB_AVAILABLE_IN_ALL +void g_object_remove_toggle_ref (GObject *object, + GToggleNotify notify, + gpointer data); + +GLIB_AVAILABLE_IN_ALL +gpointer g_object_get_qdata (GObject *object, + GQuark quark); +GLIB_AVAILABLE_IN_ALL +void g_object_set_qdata (GObject *object, + GQuark quark, + gpointer data); +GLIB_AVAILABLE_IN_ALL +void g_object_set_qdata_full (GObject *object, + GQuark quark, + gpointer data, + GDestroyNotify destroy); +GLIB_AVAILABLE_IN_ALL +gpointer g_object_steal_qdata (GObject *object, + GQuark quark); + +GLIB_AVAILABLE_IN_2_34 +gpointer g_object_dup_qdata (GObject *object, + GQuark quark, + GDuplicateFunc dup_func, + gpointer user_data); +GLIB_AVAILABLE_IN_2_34 +gboolean g_object_replace_qdata (GObject *object, + GQuark quark, + gpointer oldval, + gpointer newval, + GDestroyNotify destroy, + GDestroyNotify *old_destroy); + +GLIB_AVAILABLE_IN_ALL +gpointer g_object_get_data (GObject *object, + const gchar *key); +GLIB_AVAILABLE_IN_ALL +void g_object_set_data (GObject *object, + const gchar *key, + gpointer data); +GLIB_AVAILABLE_IN_ALL +void g_object_set_data_full (GObject *object, + const gchar *key, + gpointer data, + GDestroyNotify destroy); +GLIB_AVAILABLE_IN_ALL +gpointer g_object_steal_data (GObject *object, + const gchar *key); + +GLIB_AVAILABLE_IN_2_34 +gpointer g_object_dup_data (GObject *object, + const gchar *key, + GDuplicateFunc dup_func, + gpointer user_data); +GLIB_AVAILABLE_IN_2_34 +gboolean g_object_replace_data (GObject *object, + const gchar *key, + gpointer oldval, + gpointer newval, + GDestroyNotify destroy, + GDestroyNotify *old_destroy); + + +GLIB_AVAILABLE_IN_ALL +void g_object_watch_closure (GObject *object, + GClosure *closure); +GLIB_AVAILABLE_IN_ALL +GClosure* g_cclosure_new_object (GCallback callback_func, + GObject *object); +GLIB_AVAILABLE_IN_ALL +GClosure* g_cclosure_new_object_swap (GCallback callback_func, + GObject *object); +GLIB_AVAILABLE_IN_ALL +GClosure* g_closure_new_object (guint sizeof_closure, + GObject *object); +GLIB_AVAILABLE_IN_ALL +void g_value_set_object (GValue *value, + gpointer v_object); +GLIB_AVAILABLE_IN_ALL +gpointer g_value_get_object (const GValue *value); +GLIB_AVAILABLE_IN_ALL +gpointer g_value_dup_object (const GValue *value); +GLIB_AVAILABLE_IN_ALL +gulong g_signal_connect_object (gpointer instance, + const gchar *detailed_signal, + GCallback c_handler, + gpointer gobject, + GConnectFlags connect_flags); + +/*< protected >*/ +GLIB_AVAILABLE_IN_ALL +void g_object_force_floating (GObject *object); +GLIB_AVAILABLE_IN_ALL +void g_object_run_dispose (GObject *object); + + +GLIB_AVAILABLE_IN_ALL +void g_value_take_object (GValue *value, + gpointer v_object); +GLIB_DEPRECATED_FOR(g_value_take_object) +void g_value_set_object_take_ownership (GValue *value, + gpointer v_object); + +GLIB_DEPRECATED +gsize g_object_compat_control (gsize what, + gpointer data); + +/* --- implementation macros --- */ +#define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \ +G_STMT_START { \ + GObject *_glib__object = (GObject*) (object); \ + GParamSpec *_glib__pspec = (GParamSpec*) (pspec); \ + guint _glib__property_id = (property_id); \ + g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'", \ + __FILE__, __LINE__, \ + (pname), \ + _glib__property_id, \ + _glib__pspec->name, \ + g_type_name (G_PARAM_SPEC_TYPE (_glib__pspec)), \ + G_OBJECT_TYPE_NAME (_glib__object)); \ +} G_STMT_END +/** + * G_OBJECT_WARN_INVALID_PROPERTY_ID: + * @object: the #GObject on which set_property() or get_property() was called + * @property_id: the numeric id of the property + * @pspec: the #GParamSpec of the property + * + * This macro should be used to emit a standard warning about unexpected + * properties in set_property() and get_property() implementations. + */ +#define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \ + G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec)) + +GLIB_AVAILABLE_IN_ALL +void g_clear_object (GObject **object_ptr); +#define g_clear_object(object_ptr) g_clear_pointer ((object_ptr), g_object_unref) + +/** + * g_set_object: (skip) + * @object_ptr: a pointer to a #GObject reference + * @new_object: (nullable) (transfer none): a pointer to the new #GObject to + * assign to it, or %NULL to clear the pointer + * + * Updates a #GObject pointer to refer to @new_object. It increments the + * reference count of @new_object (if non-%NULL), decrements the reference + * count of the current value of @object_ptr (if non-%NULL), and assigns + * @new_object to @object_ptr. The assignment is not atomic. + * + * @object_ptr must not be %NULL. + * + * A macro is also included that allows this function to be used without + * pointer casts. The function itself is static inline, so its address may vary + * between compilation units. + * + * One convenient usage of this function is in implementing property setters: + * |[ + * void + * foo_set_bar (Foo *foo, + * Bar *new_bar) + * { + * g_return_if_fail (IS_FOO (foo)); + * g_return_if_fail (new_bar == NULL || IS_BAR (new_bar)); + * + * if (g_set_object (&foo->bar, new_bar)) + * g_object_notify (foo, "bar"); + * } + * ]| + * + * Returns: %TRUE if the value of @object_ptr changed, %FALSE otherwise + * + * Since: 2.44 + */ +static inline gboolean +(g_set_object) (GObject **object_ptr, + GObject *new_object) +{ + GObject *old_object = *object_ptr; + + /* rely on g_object_[un]ref() to check the pointers are actually GObjects; + * elide a (object_ptr != NULL) check because most of the time we will be + * operating on struct members with a constant offset, so a NULL check would + * not catch bugs + */ + + if (old_object == new_object) + return FALSE; + + if (new_object != NULL) + g_object_ref (new_object); + + *object_ptr = new_object; + + if (old_object != NULL) + g_object_unref (old_object); + + return TRUE; +} + +#define g_set_object(object_ptr, new_object) \ + (/* Check types match. */ \ + 0 ? *(object_ptr) = (new_object), FALSE : \ + (g_set_object) ((GObject **) (object_ptr), (GObject *) (new_object)) \ + ) + +/** + * g_assert_finalize_object: (skip) + * @object: (transfer full) (type GObject.Object): an object + * + * Assert that @object is non-%NULL, then release one reference to it with + * g_object_unref() and assert that it has been finalized (i.e. that there + * are no more references). + * + * If assertions are disabled via `G_DISABLE_ASSERT`, + * this macro just calls g_object_unref() without any further checks. + * + * This macro should only be used in regression tests. + * + * Since: 2.62 + */ +static inline void +(g_assert_finalize_object) (GObject *object) +{ + gpointer weak_pointer = object; + + g_assert_true (G_IS_OBJECT (weak_pointer)); + g_object_add_weak_pointer (object, &weak_pointer); + g_object_unref (weak_pointer); + g_assert_null (weak_pointer); +} + +#ifdef G_DISABLE_ASSERT +#define g_assert_finalize_object(object) g_object_unref (object) +#else +#define g_assert_finalize_object(object) (g_assert_finalize_object ((GObject *) object)) +#endif + +/** + * g_clear_weak_pointer: (skip) + * @weak_pointer_location: The memory address of a pointer + * + * Clears a weak reference to a #GObject. + * + * @weak_pointer_location must not be %NULL. + * + * If the weak reference is %NULL then this function does nothing. + * Otherwise, the weak reference to the object is removed for that location + * and the pointer is set to %NULL. + * + * A macro is also included that allows this function to be used without + * pointer casts. The function itself is static inline, so its address may vary + * between compilation units. + * + * Since: 2.56 + */ +static inline void +(g_clear_weak_pointer) (gpointer *weak_pointer_location) +{ + GObject *object = (GObject *) *weak_pointer_location; + + if (object != NULL) + { + g_object_remove_weak_pointer (object, weak_pointer_location); + *weak_pointer_location = NULL; + } +} + +#define g_clear_weak_pointer(weak_pointer_location) \ + (/* Check types match. */ \ + (g_clear_weak_pointer) ((gpointer *) (weak_pointer_location)) \ + ) + +/** + * g_set_weak_pointer: (skip) + * @weak_pointer_location: the memory address of a pointer + * @new_object: (nullable) (transfer none): a pointer to the new #GObject to + * assign to it, or %NULL to clear the pointer + * + * Updates a pointer to weakly refer to @new_object. It assigns @new_object + * to @weak_pointer_location and ensures that @weak_pointer_location will + * automaticaly be set to %NULL if @new_object gets destroyed. The assignment + * is not atomic. The weak reference is not thread-safe, see + * g_object_add_weak_pointer() for details. + * + * @weak_pointer_location must not be %NULL. + * + * A macro is also included that allows this function to be used without + * pointer casts. The function itself is static inline, so its address may vary + * between compilation units. + * + * One convenient usage of this function is in implementing property setters: + * |[ + * void + * foo_set_bar (Foo *foo, + * Bar *new_bar) + * { + * g_return_if_fail (IS_FOO (foo)); + * g_return_if_fail (new_bar == NULL || IS_BAR (new_bar)); + * + * if (g_set_weak_pointer (&foo->bar, new_bar)) + * g_object_notify (foo, "bar"); + * } + * ]| + * + * Returns: %TRUE if the value of @weak_pointer_location changed, %FALSE otherwise + * + * Since: 2.56 + */ +static inline gboolean +(g_set_weak_pointer) (gpointer *weak_pointer_location, + GObject *new_object) +{ + GObject *old_object = (GObject *) *weak_pointer_location; + + /* elide a (weak_pointer_location != NULL) check because most of the time we + * will be operating on struct members with a constant offset, so a NULL + * check would not catch bugs + */ + + if (old_object == new_object) + return FALSE; + + if (old_object != NULL) + g_object_remove_weak_pointer (old_object, weak_pointer_location); + + *weak_pointer_location = new_object; + + if (new_object != NULL) + g_object_add_weak_pointer (new_object, weak_pointer_location); + + return TRUE; +} + +#define g_set_weak_pointer(weak_pointer_location, new_object) \ + (/* Check types match. */ \ + 0 ? *(weak_pointer_location) = (new_object), FALSE : \ + (g_set_weak_pointer) ((gpointer *) (weak_pointer_location), (GObject *) (new_object)) \ + ) + +typedef struct { + /*<private>*/ + union { gpointer p; } priv; +} GWeakRef; + +GLIB_AVAILABLE_IN_ALL +void g_weak_ref_init (GWeakRef *weak_ref, + gpointer object); +GLIB_AVAILABLE_IN_ALL +void g_weak_ref_clear (GWeakRef *weak_ref); +GLIB_AVAILABLE_IN_ALL +gpointer g_weak_ref_get (GWeakRef *weak_ref); +GLIB_AVAILABLE_IN_ALL +void g_weak_ref_set (GWeakRef *weak_ref, + gpointer object); + +G_END_DECLS + +#endif /* __G_OBJECT_H__ */ diff --git a/include/glib/gobject/gobjectnotifyqueue.c b/include/glib/gobject/gobjectnotifyqueue.c new file mode 100644 index 0000000000..1a7d23f266 --- /dev/null +++ b/include/glib/gobject/gobjectnotifyqueue.c @@ -0,0 +1,197 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ + +/* WARNING: + * + * This file is INSTALLED and other projects (outside of glib) + * #include its contents. + */ + +#ifndef __G_OBJECT_NOTIFY_QUEUE_H__ +#define __G_OBJECT_NOTIFY_QUEUE_H__ + +#include <string.h> /* memset */ + +#include <glib-object.h> + +G_BEGIN_DECLS + + +/* --- typedefs --- */ +typedef struct _GObjectNotifyContext GObjectNotifyContext; +typedef struct _GObjectNotifyQueue GObjectNotifyQueue; +typedef void (*GObjectNotifyQueueDispatcher) (GObject *object, + guint n_pspecs, + GParamSpec **pspecs); + + +/* --- structures --- */ +struct _GObjectNotifyContext +{ + GQuark quark_notify_queue; + GObjectNotifyQueueDispatcher dispatcher; + GTrashStack *_nqueue_trash; /* unused */ +}; +struct _GObjectNotifyQueue +{ + GObjectNotifyContext *context; + GSList *pspecs; + guint16 n_pspecs; + guint16 freeze_count; +}; + +G_LOCK_DEFINE_STATIC(notify_lock); + +/* --- functions --- */ +static void +g_object_notify_queue_free (gpointer data) +{ + GObjectNotifyQueue *nqueue = data; + + g_slist_free (nqueue->pspecs); + g_slice_free (GObjectNotifyQueue, nqueue); +} + +static inline GObjectNotifyQueue* +g_object_notify_queue_freeze (GObject *object, + GObjectNotifyContext *context) +{ + GObjectNotifyQueue *nqueue; + + G_LOCK(notify_lock); + nqueue = g_datalist_id_get_data (&object->qdata, context->quark_notify_queue); + if (!nqueue) + { + nqueue = g_slice_new0 (GObjectNotifyQueue); + nqueue->context = context; + g_datalist_id_set_data_full (&object->qdata, context->quark_notify_queue, + nqueue, g_object_notify_queue_free); + } + + if (nqueue->freeze_count >= 65535) + g_critical("Free queue for %s (%p) is larger than 65535," + " called g_object_freeze_notify() too often." + " Forgot to call g_object_thaw_notify() or infinite loop", + G_OBJECT_TYPE_NAME (object), object); + else + nqueue->freeze_count++; + G_UNLOCK(notify_lock); + + return nqueue; +} + +static inline void +g_object_notify_queue_thaw (GObject *object, + GObjectNotifyQueue *nqueue) +{ + GObjectNotifyContext *context = nqueue->context; + GParamSpec *pspecs_mem[16], **pspecs, **free_me = NULL; + GSList *slist; + guint n_pspecs = 0; + + g_return_if_fail (nqueue->freeze_count > 0); + g_return_if_fail (g_atomic_int_get(&object->ref_count) > 0); + + G_LOCK(notify_lock); + + /* Just make sure we never get into some nasty race condition */ + if (G_UNLIKELY(nqueue->freeze_count == 0)) { + G_UNLOCK(notify_lock); + g_warning ("%s: property-changed notification for %s(%p) is not frozen", + G_STRFUNC, G_OBJECT_TYPE_NAME (object), object); + return; + } + + nqueue->freeze_count--; + if (nqueue->freeze_count) { + G_UNLOCK(notify_lock); + return; + } + + pspecs = nqueue->n_pspecs > 16 ? free_me = g_new (GParamSpec*, nqueue->n_pspecs) : pspecs_mem; + + for (slist = nqueue->pspecs; slist; slist = slist->next) + { + pspecs[n_pspecs++] = slist->data; + } + g_datalist_id_set_data (&object->qdata, context->quark_notify_queue, NULL); + + G_UNLOCK(notify_lock); + + if (n_pspecs) + context->dispatcher (object, n_pspecs, pspecs); + g_free (free_me); +} + +static inline void +g_object_notify_queue_clear (GObject *object, + GObjectNotifyQueue *nqueue) +{ + g_return_if_fail (nqueue->freeze_count > 0); + + G_LOCK(notify_lock); + + g_slist_free (nqueue->pspecs); + nqueue->pspecs = NULL; + nqueue->n_pspecs = 0; + + G_UNLOCK(notify_lock); +} + +static inline void +g_object_notify_queue_add (GObject *object, + GObjectNotifyQueue *nqueue, + GParamSpec *pspec) +{ + if (pspec->flags & G_PARAM_READABLE) + { + GParamSpec *redirect; + + G_LOCK(notify_lock); + + g_return_if_fail (nqueue->n_pspecs < 65535); + + redirect = g_param_spec_get_redirect_target (pspec); + if (redirect) + pspec = redirect; + + /* we do the deduping in _thaw */ + if (g_slist_find (nqueue->pspecs, pspec) == NULL) + { + nqueue->pspecs = g_slist_prepend (nqueue->pspecs, pspec); + nqueue->n_pspecs++; + } + + G_UNLOCK(notify_lock); + } +} + +/* NB: This function is not threadsafe, do not ever use it if + * you need a threadsafe notify queue. + * Use g_object_notify_queue_freeze() to acquire the queue and + * g_object_notify_queue_thaw() after you are done instead. + */ +static inline GObjectNotifyQueue* +g_object_notify_queue_from_object (GObject *object, + GObjectNotifyContext *context) +{ + return g_datalist_id_get_data (&object->qdata, context->quark_notify_queue); +} + +G_END_DECLS + +#endif /* __G_OBJECT_NOTIFY_QUEUE_H__ */ diff --git a/include/glib/gobject/gparam.h b/include/glib/gobject/gparam.h new file mode 100644 index 0000000000..33f95f0c5c --- /dev/null +++ b/include/glib/gobject/gparam.h @@ -0,0 +1,452 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + * + * gparam.h: GParamSpec base class implementation + */ +#ifndef __G_PARAM_H__ +#define __G_PARAM_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gvalue.h> + +G_BEGIN_DECLS + +/* --- standard type macros --- */ +/** + * G_TYPE_IS_PARAM: + * @type: a #GType ID + * + * Checks whether @type "is a" %G_TYPE_PARAM. + */ +#define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM) +/** + * G_PARAM_SPEC: + * @pspec: a valid #GParamSpec + * + * Casts a derived #GParamSpec object (e.g. of type #GParamSpecInt) into + * a #GParamSpec object. + */ +#define G_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM, GParamSpec)) +/** + * G_IS_PARAM_SPEC: + * @pspec: a #GParamSpec + * + * Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM + * or derived. + */ +#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_42 +#define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE ((pspec), G_TYPE_PARAM)) +#else +#define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM)) +#endif +/** + * G_PARAM_SPEC_CLASS: + * @pclass: a valid #GParamSpecClass + * + * Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure. + */ +#define G_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_CAST ((pclass), G_TYPE_PARAM, GParamSpecClass)) +/** + * G_IS_PARAM_SPEC_CLASS: + * @pclass: a #GParamSpecClass + * + * Checks whether @pclass "is a" valid #GParamSpecClass structure of type + * %G_TYPE_PARAM or derived. + */ +#define G_IS_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_TYPE ((pclass), G_TYPE_PARAM)) +/** + * G_PARAM_SPEC_GET_CLASS: + * @pspec: a valid #GParamSpec + * + * Retrieves the #GParamSpecClass of a #GParamSpec. + */ +#define G_PARAM_SPEC_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass)) + + +/* --- convenience macros --- */ +/** + * G_PARAM_SPEC_TYPE: + * @pspec: a valid #GParamSpec + * + * Retrieves the #GType of this @pspec. + */ +#define G_PARAM_SPEC_TYPE(pspec) (G_TYPE_FROM_INSTANCE (pspec)) +/** + * G_PARAM_SPEC_TYPE_NAME: + * @pspec: a valid #GParamSpec + * + * Retrieves the #GType name of this @pspec. + */ +#define G_PARAM_SPEC_TYPE_NAME(pspec) (g_type_name (G_PARAM_SPEC_TYPE (pspec))) +/** + * G_PARAM_SPEC_VALUE_TYPE: + * @pspec: a valid #GParamSpec + * + * Retrieves the #GType to initialize a #GValue for this parameter. + */ +#define G_PARAM_SPEC_VALUE_TYPE(pspec) (G_PARAM_SPEC (pspec)->value_type) +/** + * G_VALUE_HOLDS_PARAM: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values derived from type %G_TYPE_PARAM. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_PARAM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM)) + + +/* --- flags --- */ +/** + * GParamFlags: + * @G_PARAM_READABLE: the parameter is readable + * @G_PARAM_WRITABLE: the parameter is writable + * @G_PARAM_READWRITE: alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE + * @G_PARAM_CONSTRUCT: the parameter will be set upon object construction + * @G_PARAM_CONSTRUCT_ONLY: the parameter can only be set upon object construction + * @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert()) + * strict validation is not required + * @G_PARAM_STATIC_NAME: the string used as name when constructing the + * parameter is guaranteed to remain valid and + * unmodified for the lifetime of the parameter. + * Since 2.8 + * @G_PARAM_STATIC_NICK: the string used as nick when constructing the + * parameter is guaranteed to remain valid and + * unmmodified for the lifetime of the parameter. + * Since 2.8 + * @G_PARAM_STATIC_BLURB: the string used as blurb when constructing the + * parameter is guaranteed to remain valid and + * unmodified for the lifetime of the parameter. + * Since 2.8 + * @G_PARAM_EXPLICIT_NOTIFY: calls to g_object_set_property() for this + * property will not automatically result in a "notify" signal being + * emitted: the implementation must call g_object_notify() themselves + * in case the property actually changes. Since: 2.42. + * @G_PARAM_PRIVATE: internal + * @G_PARAM_DEPRECATED: the parameter is deprecated and will be removed + * in a future version. A warning will be generated if it is used + * while running with G_ENABLE_DIAGNOSTIC=1. + * Since 2.26 + * + * Through the #GParamFlags flag values, certain aspects of parameters + * can be configured. See also #G_PARAM_STATIC_STRINGS. + */ +typedef enum +{ + G_PARAM_READABLE = 1 << 0, + G_PARAM_WRITABLE = 1 << 1, + G_PARAM_READWRITE = (G_PARAM_READABLE | G_PARAM_WRITABLE), + G_PARAM_CONSTRUCT = 1 << 2, + G_PARAM_CONSTRUCT_ONLY = 1 << 3, + G_PARAM_LAX_VALIDATION = 1 << 4, + G_PARAM_STATIC_NAME = 1 << 5, + G_PARAM_PRIVATE GLIB_DEPRECATED_ENUMERATOR_IN_2_26 = G_PARAM_STATIC_NAME, + G_PARAM_STATIC_NICK = 1 << 6, + G_PARAM_STATIC_BLURB = 1 << 7, + /* User defined flags go here */ + G_PARAM_EXPLICIT_NOTIFY = 1 << 30, + /* Avoid warning with -Wpedantic for gcc6 */ + G_PARAM_DEPRECATED = (gint)(1u << 31) +} GParamFlags; + +/** + * G_PARAM_STATIC_STRINGS: + * + * #GParamFlags value alias for %G_PARAM_STATIC_NAME | %G_PARAM_STATIC_NICK | %G_PARAM_STATIC_BLURB. + * + * Since 2.13.0 + */ +#define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB) +/* bits in the range 0xffffff00 are reserved for 3rd party usage */ +/** + * G_PARAM_MASK: + * + * Mask containing the bits of #GParamSpec.flags which are reserved for GLib. + */ +#define G_PARAM_MASK (0x000000ff) +/** + * G_PARAM_USER_SHIFT: + * + * Minimum shift count to be used for user defined flags, to be stored in + * #GParamSpec.flags. The maximum allowed is 10. + */ +#define G_PARAM_USER_SHIFT (8) + +/* --- typedefs & structures --- */ +typedef struct _GParamSpec GParamSpec; +typedef struct _GParamSpecClass GParamSpecClass; +typedef struct _GParameter GParameter GLIB_DEPRECATED_TYPE_IN_2_54; +typedef struct _GParamSpecPool GParamSpecPool; +/** + * GParamSpec: (ref-func g_param_spec_ref_sink) (unref-func g_param_spec_uref) (set-value-func g_value_set_param) (get-value-func g_value_get_param) + * @g_type_instance: private #GTypeInstance portion + * @name: name of this parameter: always an interned string + * @flags: #GParamFlags flags for this parameter + * @value_type: the #GValue type for this parameter + * @owner_type: #GType type that uses (introduces) this parameter + * + * All other fields of the GParamSpec struct are private and + * should not be used directly. + */ +struct _GParamSpec +{ + GTypeInstance g_type_instance; + + const gchar *name; /* interned string */ + GParamFlags flags; + GType value_type; + GType owner_type; /* class or interface using this property */ + + /*< private >*/ + gchar *_nick; + gchar *_blurb; + GData *qdata; + guint ref_count; + guint param_id; /* sort-criteria */ +}; +/** + * GParamSpecClass: + * @g_type_class: the parent class + * @value_type: the #GValue type for this parameter + * @finalize: The instance finalization function (optional), should chain + * up to the finalize method of the parent class. + * @value_set_default: Resets a @value to the default value for this type + * (recommended, the default is g_value_reset()), see + * g_param_value_set_default(). + * @value_validate: Ensures that the contents of @value comply with the + * specifications set out by this type (optional), see + * g_param_value_validate(). + * @values_cmp: Compares @value1 with @value2 according to this type + * (recommended, the default is memcmp()), see g_param_values_cmp(). + * + * The class structure for the GParamSpec type. + * Normally, GParamSpec classes are filled by + * g_param_type_register_static(). + */ +struct _GParamSpecClass +{ + GTypeClass g_type_class; + + GType value_type; + + void (*finalize) (GParamSpec *pspec); + + /* GParam methods */ + void (*value_set_default) (GParamSpec *pspec, + GValue *value); + gboolean (*value_validate) (GParamSpec *pspec, + GValue *value); + gint (*values_cmp) (GParamSpec *pspec, + const GValue *value1, + const GValue *value2); + /*< private >*/ + gpointer dummy[4]; +}; +/** + * GParameter: + * @name: the parameter name + * @value: the parameter value + * + * The GParameter struct is an auxiliary structure used + * to hand parameter name/value pairs to g_object_newv(). + * + * Deprecated: 2.54: This type is not introspectable. + */ +struct _GParameter /* auxiliary structure for _setv() variants */ +{ + const gchar *name; + GValue value; +} GLIB_DEPRECATED_TYPE_IN_2_54; + + +/* --- prototypes --- */ +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_ref (GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +void g_param_spec_unref (GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +void g_param_spec_sink (GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_ref_sink (GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +gpointer g_param_spec_get_qdata (GParamSpec *pspec, + GQuark quark); +GLIB_AVAILABLE_IN_ALL +void g_param_spec_set_qdata (GParamSpec *pspec, + GQuark quark, + gpointer data); +GLIB_AVAILABLE_IN_ALL +void g_param_spec_set_qdata_full (GParamSpec *pspec, + GQuark quark, + gpointer data, + GDestroyNotify destroy); +GLIB_AVAILABLE_IN_ALL +gpointer g_param_spec_steal_qdata (GParamSpec *pspec, + GQuark quark); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_get_redirect_target (GParamSpec *pspec); + +GLIB_AVAILABLE_IN_ALL +void g_param_value_set_default (GParamSpec *pspec, + GValue *value); +GLIB_AVAILABLE_IN_ALL +gboolean g_param_value_defaults (GParamSpec *pspec, + GValue *value); +GLIB_AVAILABLE_IN_ALL +gboolean g_param_value_validate (GParamSpec *pspec, + GValue *value); +GLIB_AVAILABLE_IN_ALL +gboolean g_param_value_convert (GParamSpec *pspec, + const GValue *src_value, + GValue *dest_value, + gboolean strict_validation); +GLIB_AVAILABLE_IN_ALL +gint g_param_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2); +GLIB_AVAILABLE_IN_ALL +const gchar * g_param_spec_get_name (GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +const gchar * g_param_spec_get_nick (GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +const gchar * g_param_spec_get_blurb (GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +void g_value_set_param (GValue *value, + GParamSpec *param); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_value_get_param (const GValue *value); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_value_dup_param (const GValue *value); + + +GLIB_AVAILABLE_IN_ALL +void g_value_take_param (GValue *value, + GParamSpec *param); +GLIB_DEPRECATED_FOR(g_value_take_param) +void g_value_set_param_take_ownership (GValue *value, + GParamSpec *param); +GLIB_AVAILABLE_IN_2_36 +const GValue * g_param_spec_get_default_value (GParamSpec *pspec); + +GLIB_AVAILABLE_IN_2_46 +GQuark g_param_spec_get_name_quark (GParamSpec *pspec); + +/* --- convenience functions --- */ +typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo; +/** + * GParamSpecTypeInfo: + * @instance_size: Size of the instance (object) structure. + * @n_preallocs: Prior to GLib 2.10, it specified the number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching). Since GLib 2.10, it is ignored, since instances are allocated with the [slice allocator][glib-Memory-Slices] now. + * @instance_init: Location of the instance initialization function (optional). + * @value_type: The #GType of values conforming to this #GParamSpec + * @finalize: The instance finalization function (optional). + * @value_set_default: Resets a @value to the default value for @pspec + * (recommended, the default is g_value_reset()), see + * g_param_value_set_default(). + * @value_validate: Ensures that the contents of @value comply with the + * specifications set out by @pspec (optional), see + * g_param_value_validate(). + * @values_cmp: Compares @value1 with @value2 according to @pspec + * (recommended, the default is memcmp()), see g_param_values_cmp(). + * + * This structure is used to provide the type system with the information + * required to initialize and destruct (finalize) a parameter's class and + * instances thereof. + * The initialized structure is passed to the g_param_type_register_static() + * The type system will perform a deep copy of this structure, so its memory + * does not need to be persistent across invocation of + * g_param_type_register_static(). + */ +struct _GParamSpecTypeInfo +{ + /* type system portion */ + guint16 instance_size; /* obligatory */ + guint16 n_preallocs; /* optional */ + void (*instance_init) (GParamSpec *pspec); /* optional */ + + /* class portion */ + GType value_type; /* obligatory */ + void (*finalize) (GParamSpec *pspec); /* optional */ + void (*value_set_default) (GParamSpec *pspec, /* recommended */ + GValue *value); + gboolean (*value_validate) (GParamSpec *pspec, /* optional */ + GValue *value); + gint (*values_cmp) (GParamSpec *pspec, /* recommended */ + const GValue *value1, + const GValue *value2); +}; +GLIB_AVAILABLE_IN_ALL +GType g_param_type_register_static (const gchar *name, + const GParamSpecTypeInfo *pspec_info); + +/* For registering builting types */ +GType _g_param_type_register_static_constant (const gchar *name, + const GParamSpecTypeInfo *pspec_info, + GType opt_type); + + +/* --- protected --- */ +GLIB_AVAILABLE_IN_ALL +gpointer g_param_spec_internal (GType param_type, + const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpecPool* g_param_spec_pool_new (gboolean type_prefixing); +GLIB_AVAILABLE_IN_ALL +void g_param_spec_pool_insert (GParamSpecPool *pool, + GParamSpec *pspec, + GType owner_type); +GLIB_AVAILABLE_IN_ALL +void g_param_spec_pool_remove (GParamSpecPool *pool, + GParamSpec *pspec); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool, + const gchar *param_name, + GType owner_type, + gboolean walk_ancestors); +GLIB_AVAILABLE_IN_ALL +GList* g_param_spec_pool_list_owned (GParamSpecPool *pool, + GType owner_type); +GLIB_AVAILABLE_IN_ALL +GParamSpec** g_param_spec_pool_list (GParamSpecPool *pool, + GType owner_type, + guint *n_pspecs_p); + + +/* contracts: + * + * gboolean value_validate (GParamSpec *pspec, + * GValue *value): + * modify value contents in the least destructive way, so + * that it complies with pspec's requirements (i.e. + * according to minimum/maximum ranges etc...). return + * whether modification was necessary. + * + * gint values_cmp (GParamSpec *pspec, + * const GValue *value1, + * const GValue *value2): + * return value1 - value2, i.e. (-1) if value1 < value2, + * (+1) if value1 > value2, and (0) otherwise (equality) + */ + +G_END_DECLS + +#endif /* __G_PARAM_H__ */ diff --git a/include/glib/gobject/gparamspecs.h b/include/glib/gobject/gparamspecs.h new file mode 100644 index 0000000000..d0e4d5953f --- /dev/null +++ b/include/glib/gobject/gparamspecs.h @@ -0,0 +1,1170 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + * + * gparamspecs.h: GLib default param specs + */ +#ifndef __G_PARAMSPECS_H__ +#define __G_PARAMSPECS_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gvalue.h> +#include <gobject/genums.h> +#include <gobject/gboxed.h> +#include <gobject/gobject.h> + +G_BEGIN_DECLS + +/* --- type macros --- */ +/** + * G_TYPE_PARAM_CHAR: + * + * The #GType of #GParamSpecChar. + */ +#define G_TYPE_PARAM_CHAR (g_param_spec_types[0]) +/** + * G_IS_PARAM_SPEC_CHAR: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_CHAR. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_CHAR(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_CHAR)) +/** + * G_PARAM_SPEC_CHAR: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecChar. + */ +#define G_PARAM_SPEC_CHAR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_CHAR, GParamSpecChar)) + +/** + * G_TYPE_PARAM_UCHAR: + * + * The #GType of #GParamSpecUChar. + */ +#define G_TYPE_PARAM_UCHAR (g_param_spec_types[1]) +/** + * G_IS_PARAM_SPEC_UCHAR: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_UCHAR. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_UCHAR(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_UCHAR)) +/** + * G_PARAM_SPEC_UCHAR: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecUChar. + */ +#define G_PARAM_SPEC_UCHAR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_UCHAR, GParamSpecUChar)) + +/** + * G_TYPE_PARAM_BOOLEAN: + * + * The #GType of #GParamSpecBoolean. + */ +#define G_TYPE_PARAM_BOOLEAN (g_param_spec_types[2]) +/** + * G_IS_PARAM_SPEC_BOOLEAN: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_BOOLEAN. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_BOOLEAN(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_BOOLEAN)) +/** + * G_PARAM_SPEC_BOOLEAN: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecBoolean. + */ +#define G_PARAM_SPEC_BOOLEAN(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_BOOLEAN, GParamSpecBoolean)) + +/** + * G_TYPE_PARAM_INT: + * + * The #GType of #GParamSpecInt. + */ +#define G_TYPE_PARAM_INT (g_param_spec_types[3]) +/** + * G_IS_PARAM_SPEC_INT: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_INT. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_INT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_INT)) +/** + * G_PARAM_SPEC_INT: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecInt. + */ +#define G_PARAM_SPEC_INT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_INT, GParamSpecInt)) + +/** + * G_TYPE_PARAM_UINT: + * + * The #GType of #GParamSpecUInt. + */ +#define G_TYPE_PARAM_UINT (g_param_spec_types[4]) +/** + * G_IS_PARAM_SPEC_UINT: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_UINT. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_UINT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_UINT)) +/** + * G_PARAM_SPEC_UINT: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecUInt. + */ +#define G_PARAM_SPEC_UINT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_UINT, GParamSpecUInt)) + +/** + * G_TYPE_PARAM_LONG: + * + * The #GType of #GParamSpecLong. + */ +#define G_TYPE_PARAM_LONG (g_param_spec_types[5]) +/** + * G_IS_PARAM_SPEC_LONG: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_LONG. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_LONG(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_LONG)) +/** + * G_PARAM_SPEC_LONG: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecLong. + */ +#define G_PARAM_SPEC_LONG(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_LONG, GParamSpecLong)) + +/** + * G_TYPE_PARAM_ULONG: + * + * The #GType of #GParamSpecULong. + */ +#define G_TYPE_PARAM_ULONG (g_param_spec_types[6]) +/** + * G_IS_PARAM_SPEC_ULONG: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_ULONG. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_ULONG(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_ULONG)) +/** + * G_PARAM_SPEC_ULONG: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecULong. + */ +#define G_PARAM_SPEC_ULONG(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_ULONG, GParamSpecULong)) + +/** + * G_TYPE_PARAM_INT64: + * + * The #GType of #GParamSpecInt64. + */ +#define G_TYPE_PARAM_INT64 (g_param_spec_types[7]) +/** + * G_IS_PARAM_SPEC_INT64: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_INT64. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_INT64(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_INT64)) +/** + * G_PARAM_SPEC_INT64: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecInt64. + */ +#define G_PARAM_SPEC_INT64(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_INT64, GParamSpecInt64)) + +/** + * G_TYPE_PARAM_UINT64: + * + * The #GType of #GParamSpecUInt64. + */ +#define G_TYPE_PARAM_UINT64 (g_param_spec_types[8]) +/** + * G_IS_PARAM_SPEC_UINT64: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_UINT64. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_UINT64(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_UINT64)) +/** + * G_PARAM_SPEC_UINT64: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecUInt64. + */ +#define G_PARAM_SPEC_UINT64(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_UINT64, GParamSpecUInt64)) + +/** + * G_TYPE_PARAM_UNICHAR: + * + * The #GType of #GParamSpecUnichar. + */ +#define G_TYPE_PARAM_UNICHAR (g_param_spec_types[9]) +/** + * G_PARAM_SPEC_UNICHAR: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecUnichar. + */ +#define G_PARAM_SPEC_UNICHAR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_UNICHAR, GParamSpecUnichar)) +/** + * G_IS_PARAM_SPEC_UNICHAR: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_UNICHAR. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_UNICHAR(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_UNICHAR)) + +/** + * G_TYPE_PARAM_ENUM: + * + * The #GType of #GParamSpecEnum. + */ +#define G_TYPE_PARAM_ENUM (g_param_spec_types[10]) +/** + * G_IS_PARAM_SPEC_ENUM: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_ENUM. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_ENUM(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_ENUM)) +/** + * G_PARAM_SPEC_ENUM: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecEnum. + */ +#define G_PARAM_SPEC_ENUM(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_ENUM, GParamSpecEnum)) + +/** + * G_TYPE_PARAM_FLAGS: + * + * The #GType of #GParamSpecFlags. + */ +#define G_TYPE_PARAM_FLAGS (g_param_spec_types[11]) +/** + * G_IS_PARAM_SPEC_FLAGS: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_FLAGS. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_FLAGS(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_FLAGS)) +/** + * G_PARAM_SPEC_FLAGS: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecFlags. + */ +#define G_PARAM_SPEC_FLAGS(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_FLAGS, GParamSpecFlags)) + +/** + * G_TYPE_PARAM_FLOAT: + * + * The #GType of #GParamSpecFloat. + */ +#define G_TYPE_PARAM_FLOAT (g_param_spec_types[12]) +/** + * G_IS_PARAM_SPEC_FLOAT: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_FLOAT. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_FLOAT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_FLOAT)) +/** + * G_PARAM_SPEC_FLOAT: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecFloat. + */ +#define G_PARAM_SPEC_FLOAT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_FLOAT, GParamSpecFloat)) + +/** + * G_TYPE_PARAM_DOUBLE: + * + * The #GType of #GParamSpecDouble. + */ +#define G_TYPE_PARAM_DOUBLE (g_param_spec_types[13]) +/** + * G_IS_PARAM_SPEC_DOUBLE: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_DOUBLE. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_DOUBLE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_DOUBLE)) +/** + * G_PARAM_SPEC_DOUBLE: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecDouble. + */ +#define G_PARAM_SPEC_DOUBLE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_DOUBLE, GParamSpecDouble)) + +/** + * G_TYPE_PARAM_STRING: + * + * The #GType of #GParamSpecString. + */ +#define G_TYPE_PARAM_STRING (g_param_spec_types[14]) +/** + * G_IS_PARAM_SPEC_STRING: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_STRING. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_STRING)) +/** + * G_PARAM_SPEC_STRING: + * @pspec: a valid #GParamSpec instance + * + * Casts a #GParamSpec instance into a #GParamSpecString. + */ +#define G_PARAM_SPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_STRING, GParamSpecString)) + +/** + * G_TYPE_PARAM_PARAM: + * + * The #GType of #GParamSpecParam. + */ +#define G_TYPE_PARAM_PARAM (g_param_spec_types[15]) +/** + * G_IS_PARAM_SPEC_PARAM: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_PARAM. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_PARAM(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_PARAM)) +/** + * G_PARAM_SPEC_PARAM: + * @pspec: a valid #GParamSpec instance + * + * Casts a #GParamSpec instance into a #GParamSpecParam. + */ +#define G_PARAM_SPEC_PARAM(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_PARAM, GParamSpecParam)) + +/** + * G_TYPE_PARAM_BOXED: + * + * The #GType of #GParamSpecBoxed. + */ +#define G_TYPE_PARAM_BOXED (g_param_spec_types[16]) +/** + * G_IS_PARAM_SPEC_BOXED: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_BOXED. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_BOXED(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_BOXED)) +/** + * G_PARAM_SPEC_BOXED: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecBoxed. + */ +#define G_PARAM_SPEC_BOXED(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_BOXED, GParamSpecBoxed)) + +/** + * G_TYPE_PARAM_POINTER: + * + * The #GType of #GParamSpecPointer. + */ +#define G_TYPE_PARAM_POINTER (g_param_spec_types[17]) +/** + * G_IS_PARAM_SPEC_POINTER: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_POINTER. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_POINTER(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_POINTER)) +/** + * G_PARAM_SPEC_POINTER: + * @pspec: a valid #GParamSpec instance + * + * Casts a #GParamSpec instance into a #GParamSpecPointer. + */ +#define G_PARAM_SPEC_POINTER(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_POINTER, GParamSpecPointer)) + +/** + * G_TYPE_PARAM_VALUE_ARRAY: + * + * The #GType of #GParamSpecValueArray. + * + * Deprecated: 2.32: Use #GArray instead of #GValueArray + */ +#define G_TYPE_PARAM_VALUE_ARRAY (g_param_spec_types[18]) GLIB_DEPRECATED_MACRO_IN_2_32 +/** + * G_IS_PARAM_SPEC_VALUE_ARRAY: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_VALUE_ARRAY. + * + * Returns: %TRUE on success. + * + * Deprecated: 2.32: Use #GArray instead of #GValueArray + */ +#define G_IS_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_VALUE_ARRAY)) GLIB_DEPRECATED_MACRO_IN_2_32 +/** + * G_PARAM_SPEC_VALUE_ARRAY: + * @pspec: a valid #GParamSpec instance + * + * Cast a #GParamSpec instance into a #GParamSpecValueArray. + * + * Deprecated: 2.32: Use #GArray instead of #GValueArray + */ +#define G_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_VALUE_ARRAY, GParamSpecValueArray)) GLIB_DEPRECATED_MACRO_IN_2_32 + +/** + * G_TYPE_PARAM_OBJECT: + * + * The #GType of #GParamSpecObject. + */ +#define G_TYPE_PARAM_OBJECT (g_param_spec_types[19]) +/** + * G_IS_PARAM_SPEC_OBJECT: + * @pspec: a valid #GParamSpec instance + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_OBJECT. + * + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_OBJECT)) +/** + * G_PARAM_SPEC_OBJECT: + * @pspec: a valid #GParamSpec instance + * + * Casts a #GParamSpec instance into a #GParamSpecObject. + */ +#define G_PARAM_SPEC_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_OBJECT, GParamSpecObject)) + +/** + * G_TYPE_PARAM_OVERRIDE: + * + * The #GType of #GParamSpecOverride. + * + * Since: 2.4 + */ +#define G_TYPE_PARAM_OVERRIDE (g_param_spec_types[20]) +/** + * G_IS_PARAM_SPEC_OVERRIDE: + * @pspec: a #GParamSpec + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_OVERRIDE. + * + * Since: 2.4 + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_OVERRIDE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_OVERRIDE)) +/** + * G_PARAM_SPEC_OVERRIDE: + * @pspec: a #GParamSpec + * + * Casts a #GParamSpec into a #GParamSpecOverride. + * + * Since: 2.4 + */ +#define G_PARAM_SPEC_OVERRIDE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_OVERRIDE, GParamSpecOverride)) + +/** + * G_TYPE_PARAM_GTYPE: + * + * The #GType of #GParamSpecGType. + * + * Since: 2.10 + */ +#define G_TYPE_PARAM_GTYPE (g_param_spec_types[21]) +/** + * G_IS_PARAM_SPEC_GTYPE: + * @pspec: a #GParamSpec + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_GTYPE. + * + * Since: 2.10 + * Returns: %TRUE on success. + */ +#define G_IS_PARAM_SPEC_GTYPE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_GTYPE)) +/** + * G_PARAM_SPEC_GTYPE: + * @pspec: a #GParamSpec + * + * Casts a #GParamSpec into a #GParamSpecGType. + * + * Since: 2.10 + */ +#define G_PARAM_SPEC_GTYPE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_GTYPE, GParamSpecGType)) + +/** + * G_TYPE_PARAM_VARIANT: + * + * The #GType of #GParamSpecVariant. + * + * Since: 2.26 + */ +#define G_TYPE_PARAM_VARIANT (g_param_spec_types[22]) +/** + * G_IS_PARAM_SPEC_VARIANT: + * @pspec: a #GParamSpec + * + * Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_VARIANT. + * + * Returns: %TRUE on success + * + * Since: 2.26 + */ +#define G_IS_PARAM_SPEC_VARIANT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_VARIANT)) +/** + * G_PARAM_SPEC_VARIANT: + * @pspec: a #GParamSpec + * + * Casts a #GParamSpec into a #GParamSpecVariant. + * + * Since: 2.26 + */ +#define G_PARAM_SPEC_VARIANT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_VARIANT, GParamSpecVariant)) + +/* --- typedefs & structures --- */ +typedef struct _GParamSpecChar GParamSpecChar; +typedef struct _GParamSpecUChar GParamSpecUChar; +typedef struct _GParamSpecBoolean GParamSpecBoolean; +typedef struct _GParamSpecInt GParamSpecInt; +typedef struct _GParamSpecUInt GParamSpecUInt; +typedef struct _GParamSpecLong GParamSpecLong; +typedef struct _GParamSpecULong GParamSpecULong; +typedef struct _GParamSpecInt64 GParamSpecInt64; +typedef struct _GParamSpecUInt64 GParamSpecUInt64; +typedef struct _GParamSpecUnichar GParamSpecUnichar; +typedef struct _GParamSpecEnum GParamSpecEnum; +typedef struct _GParamSpecFlags GParamSpecFlags; +typedef struct _GParamSpecFloat GParamSpecFloat; +typedef struct _GParamSpecDouble GParamSpecDouble; +typedef struct _GParamSpecString GParamSpecString; +typedef struct _GParamSpecParam GParamSpecParam; +typedef struct _GParamSpecBoxed GParamSpecBoxed; +typedef struct _GParamSpecPointer GParamSpecPointer; +typedef struct _GParamSpecValueArray GParamSpecValueArray; +typedef struct _GParamSpecObject GParamSpecObject; +typedef struct _GParamSpecOverride GParamSpecOverride; +typedef struct _GParamSpecGType GParamSpecGType; +typedef struct _GParamSpecVariant GParamSpecVariant; + +/** + * GParamSpecChar: + * @parent_instance: private #GParamSpec portion + * @minimum: minimum value for the property specified + * @maximum: maximum value for the property specified + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for character properties. + */ +struct _GParamSpecChar +{ + GParamSpec parent_instance; + + gint8 minimum; + gint8 maximum; + gint8 default_value; +}; +/** + * GParamSpecUChar: + * @parent_instance: private #GParamSpec portion + * @minimum: minimum value for the property specified + * @maximum: maximum value for the property specified + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for unsigned character properties. + */ +struct _GParamSpecUChar +{ + GParamSpec parent_instance; + + guint8 minimum; + guint8 maximum; + guint8 default_value; +}; +/** + * GParamSpecBoolean: + * @parent_instance: private #GParamSpec portion + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for boolean properties. + */ +struct _GParamSpecBoolean +{ + GParamSpec parent_instance; + + gboolean default_value; +}; +/** + * GParamSpecInt: + * @parent_instance: private #GParamSpec portion + * @minimum: minimum value for the property specified + * @maximum: maximum value for the property specified + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for integer properties. + */ +struct _GParamSpecInt +{ + GParamSpec parent_instance; + + gint minimum; + gint maximum; + gint default_value; +}; +/** + * GParamSpecUInt: + * @parent_instance: private #GParamSpec portion + * @minimum: minimum value for the property specified + * @maximum: maximum value for the property specified + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for unsigned integer properties. + */ +struct _GParamSpecUInt +{ + GParamSpec parent_instance; + + guint minimum; + guint maximum; + guint default_value; +}; +/** + * GParamSpecLong: + * @parent_instance: private #GParamSpec portion + * @minimum: minimum value for the property specified + * @maximum: maximum value for the property specified + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for long integer properties. + */ +struct _GParamSpecLong +{ + GParamSpec parent_instance; + + glong minimum; + glong maximum; + glong default_value; +}; +/** + * GParamSpecULong: + * @parent_instance: private #GParamSpec portion + * @minimum: minimum value for the property specified + * @maximum: maximum value for the property specified + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for unsigned long integer properties. + */ +struct _GParamSpecULong +{ + GParamSpec parent_instance; + + gulong minimum; + gulong maximum; + gulong default_value; +}; +/** + * GParamSpecInt64: + * @parent_instance: private #GParamSpec portion + * @minimum: minimum value for the property specified + * @maximum: maximum value for the property specified + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for 64bit integer properties. + */ +struct _GParamSpecInt64 +{ + GParamSpec parent_instance; + + gint64 minimum; + gint64 maximum; + gint64 default_value; +}; +/** + * GParamSpecUInt64: + * @parent_instance: private #GParamSpec portion + * @minimum: minimum value for the property specified + * @maximum: maximum value for the property specified + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for unsigned 64bit integer properties. + */ +struct _GParamSpecUInt64 +{ + GParamSpec parent_instance; + + guint64 minimum; + guint64 maximum; + guint64 default_value; +}; +/** + * GParamSpecUnichar: + * @parent_instance: private #GParamSpec portion + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for unichar (unsigned integer) properties. + */ +struct _GParamSpecUnichar +{ + GParamSpec parent_instance; + + gunichar default_value; +}; +/** + * GParamSpecEnum: + * @parent_instance: private #GParamSpec portion + * @enum_class: the #GEnumClass for the enum + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for enum + * properties. + */ +struct _GParamSpecEnum +{ + GParamSpec parent_instance; + + GEnumClass *enum_class; + gint default_value; +}; +/** + * GParamSpecFlags: + * @parent_instance: private #GParamSpec portion + * @flags_class: the #GFlagsClass for the flags + * @default_value: default value for the property specified + * + * A #GParamSpec derived structure that contains the meta data for flags + * properties. + */ +struct _GParamSpecFlags +{ + GParamSpec parent_instance; + + GFlagsClass *flags_class; + guint default_value; +}; +/** + * GParamSpecFloat: + * @parent_instance: private #GParamSpec portion + * @minimum: minimum value for the property specified + * @maximum: maximum value for the property specified + * @default_value: default value for the property specified + * @epsilon: values closer than @epsilon will be considered identical + * by g_param_values_cmp(); the default value is 1e-30. + * + * A #GParamSpec derived structure that contains the meta data for float properties. + */ +struct _GParamSpecFloat +{ + GParamSpec parent_instance; + + gfloat minimum; + gfloat maximum; + gfloat default_value; + gfloat epsilon; +}; +/** + * GParamSpecDouble: + * @parent_instance: private #GParamSpec portion + * @minimum: minimum value for the property specified + * @maximum: maximum value for the property specified + * @default_value: default value for the property specified + * @epsilon: values closer than @epsilon will be considered identical + * by g_param_values_cmp(); the default value is 1e-90. + * + * A #GParamSpec derived structure that contains the meta data for double properties. + */ +struct _GParamSpecDouble +{ + GParamSpec parent_instance; + + gdouble minimum; + gdouble maximum; + gdouble default_value; + gdouble epsilon; +}; +/** + * GParamSpecString: + * @parent_instance: private #GParamSpec portion + * @default_value: default value for the property specified + * @cset_first: a string containing the allowed values for the first byte + * @cset_nth: a string containing the allowed values for the subsequent bytes + * @substitutor: the replacement byte for bytes which don't match @cset_first or @cset_nth. + * @null_fold_if_empty: replace empty string by %NULL + * @ensure_non_null: replace %NULL strings by an empty string + * + * A #GParamSpec derived structure that contains the meta data for string + * properties. + */ +struct _GParamSpecString +{ + GParamSpec parent_instance; + + gchar *default_value; + gchar *cset_first; + gchar *cset_nth; + gchar substitutor; + guint null_fold_if_empty : 1; + guint ensure_non_null : 1; +}; +/** + * GParamSpecParam: + * @parent_instance: private #GParamSpec portion + * + * A #GParamSpec derived structure that contains the meta data for %G_TYPE_PARAM + * properties. + */ +struct _GParamSpecParam +{ + GParamSpec parent_instance; +}; +/** + * GParamSpecBoxed: + * @parent_instance: private #GParamSpec portion + * + * A #GParamSpec derived structure that contains the meta data for boxed properties. + */ +struct _GParamSpecBoxed +{ + GParamSpec parent_instance; +}; +/** + * GParamSpecPointer: + * @parent_instance: private #GParamSpec portion + * + * A #GParamSpec derived structure that contains the meta data for pointer properties. + */ +struct _GParamSpecPointer +{ + GParamSpec parent_instance; +}; +/** + * GParamSpecValueArray: + * @parent_instance: private #GParamSpec portion + * @element_spec: a #GParamSpec describing the elements contained in arrays of this property, may be %NULL + * @fixed_n_elements: if greater than 0, arrays of this property will always have this many elements + * + * A #GParamSpec derived structure that contains the meta data for #GValueArray properties. + */ +struct _GParamSpecValueArray +{ + GParamSpec parent_instance; + GParamSpec *element_spec; + guint fixed_n_elements; +}; +/** + * GParamSpecObject: + * @parent_instance: private #GParamSpec portion + * + * A #GParamSpec derived structure that contains the meta data for object properties. + */ +struct _GParamSpecObject +{ + GParamSpec parent_instance; +}; +/** + * GParamSpecOverride: + * + * This is a type of #GParamSpec type that simply redirects operations to + * another paramspec. All operations other than getting or + * setting the value are redirected, including accessing the nick and + * blurb, validating a value, and so forth. See + * g_param_spec_get_redirect_target() for retrieving the overidden + * property. #GParamSpecOverride is used in implementing + * g_object_class_override_property(), and will not be directly useful + * unless you are implementing a new base type similar to GObject. + * + * Since: 2.4 + */ +struct _GParamSpecOverride +{ + /*< private >*/ + GParamSpec parent_instance; + GParamSpec *overridden; +}; +/** + * GParamSpecGType: + * @parent_instance: private #GParamSpec portion + * @is_a_type: a #GType whose subtypes can occur as values + * + * A #GParamSpec derived structure that contains the meta data for #GType properties. + * + * Since: 2.10 + */ +struct _GParamSpecGType +{ + GParamSpec parent_instance; + GType is_a_type; +}; +/** + * GParamSpecVariant: + * @parent_instance: private #GParamSpec portion + * @type: a #GVariantType, or %NULL + * @default_value: a #GVariant, or %NULL + * + * A #GParamSpec derived structure that contains the meta data for #GVariant properties. + * + * When comparing values with g_param_values_cmp(), scalar values with the same + * type will be compared with g_variant_compare(). Other non-%NULL variants will + * be checked for equality with g_variant_equal(), and their sort order is + * otherwise undefined. %NULL is ordered before non-%NULL variants. Two %NULL + * values compare equal. + * + * Since: 2.26 + */ +struct _GParamSpecVariant +{ + GParamSpec parent_instance; + GVariantType *type; + GVariant *default_value; + + /*< private >*/ + gpointer padding[4]; +}; + +/* --- GParamSpec prototypes --- */ +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_char (const gchar *name, + const gchar *nick, + const gchar *blurb, + gint8 minimum, + gint8 maximum, + gint8 default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_uchar (const gchar *name, + const gchar *nick, + const gchar *blurb, + guint8 minimum, + guint8 maximum, + guint8 default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_boolean (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_int (const gchar *name, + const gchar *nick, + const gchar *blurb, + gint minimum, + gint maximum, + gint default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_uint (const gchar *name, + const gchar *nick, + const gchar *blurb, + guint minimum, + guint maximum, + guint default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_long (const gchar *name, + const gchar *nick, + const gchar *blurb, + glong minimum, + glong maximum, + glong default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_ulong (const gchar *name, + const gchar *nick, + const gchar *blurb, + gulong minimum, + gulong maximum, + gulong default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_int64 (const gchar *name, + const gchar *nick, + const gchar *blurb, + gint64 minimum, + gint64 maximum, + gint64 default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_uint64 (const gchar *name, + const gchar *nick, + const gchar *blurb, + guint64 minimum, + guint64 maximum, + guint64 default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_unichar (const gchar *name, + const gchar *nick, + const gchar *blurb, + gunichar default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_enum (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType enum_type, + gint default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_flags (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType flags_type, + guint default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_float (const gchar *name, + const gchar *nick, + const gchar *blurb, + gfloat minimum, + gfloat maximum, + gfloat default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_double (const gchar *name, + const gchar *nick, + const gchar *blurb, + gdouble minimum, + gdouble maximum, + gdouble default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_string (const gchar *name, + const gchar *nick, + const gchar *blurb, + const gchar *default_value, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_param (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType param_type, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_boxed (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType boxed_type, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_pointer (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_value_array (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamSpec *element_spec, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_object (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType object_type, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_override (const gchar *name, + GParamSpec *overridden); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_gtype (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType is_a_type, + GParamFlags flags); +GLIB_AVAILABLE_IN_ALL +GParamSpec* g_param_spec_variant (const gchar *name, + const gchar *nick, + const gchar *blurb, + const GVariantType *type, + GVariant *default_value, + GParamFlags flags); + +/* --- internal --- */ +/* We prefix variable declarations so they can + * properly get exported in windows dlls. + */ +#ifndef GOBJECT_VAR +# ifdef G_PLATFORM_WIN32 +# ifdef GOBJECT_STATIC_COMPILATION +# define GOBJECT_VAR extern +# else /* !GOBJECT_STATIC_COMPILATION */ +# ifdef GOBJECT_COMPILATION +# ifdef DLL_EXPORT +# define GOBJECT_VAR extern __declspec(dllexport) +# else /* !DLL_EXPORT */ +# define GOBJECT_VAR extern +# endif /* !DLL_EXPORT */ +# else /* !GOBJECT_COMPILATION */ +# define GOBJECT_VAR extern __declspec(dllimport) +# endif /* !GOBJECT_COMPILATION */ +# endif /* !GOBJECT_STATIC_COMPILATION */ +# else /* !G_PLATFORM_WIN32 */ +# define GOBJECT_VAR _GLIB_EXTERN +# endif /* !G_PLATFORM_WIN32 */ +#endif /* GOBJECT_VAR */ + +GOBJECT_VAR GType *g_param_spec_types; + +G_END_DECLS + +#endif /* __G_PARAMSPECS_H__ */ diff --git a/include/glib/gobject/gsignal.h b/include/glib/gobject/gsignal.h new file mode 100644 index 0000000000..a79b9f662a --- /dev/null +++ b/include/glib/gobject/gsignal.h @@ -0,0 +1,623 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2000-2001 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __G_SIGNAL_H__ +#define __G_SIGNAL_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gclosure.h> +#include <gobject/gvalue.h> +#include <gobject/gparam.h> +#include <gobject/gmarshal.h> + +G_BEGIN_DECLS + +/* --- typedefs --- */ +typedef struct _GSignalQuery GSignalQuery; +typedef struct _GSignalInvocationHint GSignalInvocationHint; +/** + * GSignalCMarshaller: + * + * This is the signature of marshaller functions, required to marshall + * arrays of parameter values to signal emissions into C language callback + * invocations. It is merely an alias to #GClosureMarshal since the #GClosure + * mechanism takes over responsibility of actual function invocation for the + * signal system. + */ +typedef GClosureMarshal GSignalCMarshaller; +/** + * GSignalCVaMarshaller: + * + * This is the signature of va_list marshaller functions, an optional + * marshaller that can be used in some situations to avoid + * marshalling the signal argument into GValues. + */ +typedef GVaClosureMarshal GSignalCVaMarshaller; +/** + * GSignalEmissionHook: + * @ihint: Signal invocation hint, see #GSignalInvocationHint. + * @n_param_values: the number of parameters to the function, including + * the instance on which the signal was emitted. + * @param_values: (array length=n_param_values): the instance on which + * the signal was emitted, followed by the parameters of the emission. + * @data: user data associated with the hook. + * + * A simple function pointer to get invoked when the signal is emitted. This + * allows you to tie a hook to the signal type, so that it will trap all + * emissions of that signal, from any object. + * + * You may not attach these to signals created with the #G_SIGNAL_NO_HOOKS flag. + * + * Returns: whether it wants to stay connected. If it returns %FALSE, the signal + * hook is disconnected (and destroyed). + */ +typedef gboolean (*GSignalEmissionHook) (GSignalInvocationHint *ihint, + guint n_param_values, + const GValue *param_values, + gpointer data); +/** + * GSignalAccumulator: + * @ihint: Signal invocation hint, see #GSignalInvocationHint. + * @return_accu: Accumulator to collect callback return values in, this + * is the return value of the current signal emission. + * @handler_return: A #GValue holding the return value of the signal handler. + * @data: Callback data that was specified when creating the signal. + * + * The signal accumulator is a special callback function that can be used + * to collect return values of the various callbacks that are called + * during a signal emission. The signal accumulator is specified at signal + * creation time, if it is left %NULL, no accumulation of callback return + * values is performed. The return value of signal emissions is then the + * value returned by the last callback. + * + * Returns: The accumulator function returns whether the signal emission + * should be aborted. Returning %FALSE means to abort the + * current emission and %TRUE is returned for continuation. + */ +typedef gboolean (*GSignalAccumulator) (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer data); + + +/* --- run, match and connect types --- */ +/** + * GSignalFlags: + * @G_SIGNAL_RUN_FIRST: Invoke the object method handler in the first emission stage. + * @G_SIGNAL_RUN_LAST: Invoke the object method handler in the third emission stage. + * @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage. + * @G_SIGNAL_NO_RECURSE: Signals being emitted for an object while currently being in + * emission for this very object will not be emitted recursively, + * but instead cause the first emission to be restarted. + * @G_SIGNAL_DETAILED: This signal supports "::detail" appendices to the signal name + * upon handler connections and emissions. + * @G_SIGNAL_ACTION: Action signals are signals that may freely be emitted on alive + * objects from user code via g_signal_emit() and friends, without + * the need of being embedded into extra code that performs pre or + * post emission adjustments on the object. They can also be thought + * of as object methods which can be called generically by + * third-party code. + * @G_SIGNAL_NO_HOOKS: No emissions hooks are supported for this signal. + * @G_SIGNAL_MUST_COLLECT: Varargs signal emission will always collect the + * arguments, even if there are no signal handlers connected. Since 2.30. + * @G_SIGNAL_DEPRECATED: The signal is deprecated and will be removed + * in a future version. A warning will be generated if it is connected while + * running with G_ENABLE_DIAGNOSTIC=1. Since 2.32. + * + * The signal flags are used to specify a signal's behaviour, the overall + * signal description outlines how especially the RUN flags control the + * stages of a signal emission. + */ +typedef enum +{ + G_SIGNAL_RUN_FIRST = 1 << 0, + G_SIGNAL_RUN_LAST = 1 << 1, + G_SIGNAL_RUN_CLEANUP = 1 << 2, + G_SIGNAL_NO_RECURSE = 1 << 3, + G_SIGNAL_DETAILED = 1 << 4, + G_SIGNAL_ACTION = 1 << 5, + G_SIGNAL_NO_HOOKS = 1 << 6, + G_SIGNAL_MUST_COLLECT = 1 << 7, + G_SIGNAL_DEPRECATED = 1 << 8 +} GSignalFlags; +/** + * G_SIGNAL_FLAGS_MASK: + * + * A mask for all #GSignalFlags bits. + */ +#define G_SIGNAL_FLAGS_MASK 0x1ff +/** + * GConnectFlags: + * @G_CONNECT_AFTER: whether the handler should be called before or after the + * default handler of the signal. + * @G_CONNECT_SWAPPED: whether the instance and data should be swapped when + * calling the handler; see g_signal_connect_swapped() for an example. + * + * The connection flags are used to specify the behaviour of a signal's + * connection. + */ +typedef enum +{ + G_CONNECT_AFTER = 1 << 0, + G_CONNECT_SWAPPED = 1 << 1 +} GConnectFlags; +/** + * GSignalMatchType: + * @G_SIGNAL_MATCH_ID: The signal id must be equal. + * @G_SIGNAL_MATCH_DETAIL: The signal detail be equal. + * @G_SIGNAL_MATCH_CLOSURE: The closure must be the same. + * @G_SIGNAL_MATCH_FUNC: The C closure callback must be the same. + * @G_SIGNAL_MATCH_DATA: The closure data must be the same. + * @G_SIGNAL_MATCH_UNBLOCKED: Only unblocked signals may matched. + * + * The match types specify what g_signal_handlers_block_matched(), + * g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched() + * match signals by. + */ +typedef enum +{ + G_SIGNAL_MATCH_ID = 1 << 0, + G_SIGNAL_MATCH_DETAIL = 1 << 1, + G_SIGNAL_MATCH_CLOSURE = 1 << 2, + G_SIGNAL_MATCH_FUNC = 1 << 3, + G_SIGNAL_MATCH_DATA = 1 << 4, + G_SIGNAL_MATCH_UNBLOCKED = 1 << 5 +} GSignalMatchType; +/** + * G_SIGNAL_MATCH_MASK: + * + * A mask for all #GSignalMatchType bits. + */ +#define G_SIGNAL_MATCH_MASK 0x3f +/** + * G_SIGNAL_TYPE_STATIC_SCOPE: + * + * This macro flags signal argument types for which the signal system may + * assume that instances thereof remain persistent across all signal emissions + * they are used in. This is only useful for non ref-counted, value-copy types. + * + * To flag a signal argument in this way, add `| G_SIGNAL_TYPE_STATIC_SCOPE` + * to the corresponding argument of g_signal_new(). + * |[ + * g_signal_new ("size_request", + * G_TYPE_FROM_CLASS (gobject_class), + * G_SIGNAL_RUN_FIRST, + * G_STRUCT_OFFSET (GtkWidgetClass, size_request), + * NULL, NULL, + * _gtk_marshal_VOID__BOXED, + * G_TYPE_NONE, 1, + * GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE); + * ]| + */ +#define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT) + + +/* --- signal information --- */ +/** + * GSignalInvocationHint: + * @signal_id: The signal id of the signal invoking the callback + * @detail: The detail passed on for this emission + * @run_type: The stage the signal emission is currently in, this + * field will contain one of %G_SIGNAL_RUN_FIRST, + * %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP. + * + * The #GSignalInvocationHint structure is used to pass on additional information + * to callbacks during a signal emission. + */ +struct _GSignalInvocationHint +{ + guint signal_id; + GQuark detail; + GSignalFlags run_type; +}; +/** + * GSignalQuery: + * @signal_id: The signal id of the signal being queried, or 0 if the + * signal to be queried was unknown. + * @signal_name: The signal name. + * @itype: The interface/instance type that this signal can be emitted for. + * @signal_flags: The signal flags as passed in to g_signal_new(). + * @return_type: The return type for user callbacks. + * @n_params: The number of parameters that user callbacks take. + * @param_types: (array length=n_params): The individual parameter types for + * user callbacks, note that the effective callback signature is: + * |[<!-- language="C" --> + * @return_type callback (#gpointer data1, + * [param_types param_names,] + * gpointer data2); + * ]| + * + * A structure holding in-depth information for a specific signal. It is + * filled in by the g_signal_query() function. + */ +struct _GSignalQuery +{ + guint signal_id; + const gchar *signal_name; + GType itype; + GSignalFlags signal_flags; + GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */ + guint n_params; + const GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */ +}; + + +/* --- signals --- */ +GLIB_AVAILABLE_IN_ALL +guint g_signal_newv (const gchar *signal_name, + GType itype, + GSignalFlags signal_flags, + GClosure *class_closure, + GSignalAccumulator accumulator, + gpointer accu_data, + GSignalCMarshaller c_marshaller, + GType return_type, + guint n_params, + GType *param_types); +GLIB_AVAILABLE_IN_ALL +guint g_signal_new_valist (const gchar *signal_name, + GType itype, + GSignalFlags signal_flags, + GClosure *class_closure, + GSignalAccumulator accumulator, + gpointer accu_data, + GSignalCMarshaller c_marshaller, + GType return_type, + guint n_params, + va_list args); +GLIB_AVAILABLE_IN_ALL +guint g_signal_new (const gchar *signal_name, + GType itype, + GSignalFlags signal_flags, + guint class_offset, + GSignalAccumulator accumulator, + gpointer accu_data, + GSignalCMarshaller c_marshaller, + GType return_type, + guint n_params, + ...); +GLIB_AVAILABLE_IN_ALL +guint g_signal_new_class_handler (const gchar *signal_name, + GType itype, + GSignalFlags signal_flags, + GCallback class_handler, + GSignalAccumulator accumulator, + gpointer accu_data, + GSignalCMarshaller c_marshaller, + GType return_type, + guint n_params, + ...); +GLIB_AVAILABLE_IN_ALL +void g_signal_set_va_marshaller (guint signal_id, + GType instance_type, + GSignalCVaMarshaller va_marshaller); + +GLIB_AVAILABLE_IN_ALL +void g_signal_emitv (const GValue *instance_and_params, + guint signal_id, + GQuark detail, + GValue *return_value); +GLIB_AVAILABLE_IN_ALL +void g_signal_emit_valist (gpointer instance, + guint signal_id, + GQuark detail, + va_list var_args); +GLIB_AVAILABLE_IN_ALL +void g_signal_emit (gpointer instance, + guint signal_id, + GQuark detail, + ...); +GLIB_AVAILABLE_IN_ALL +void g_signal_emit_by_name (gpointer instance, + const gchar *detailed_signal, + ...); +GLIB_AVAILABLE_IN_ALL +guint g_signal_lookup (const gchar *name, + GType itype); +GLIB_AVAILABLE_IN_ALL +const gchar * g_signal_name (guint signal_id); +GLIB_AVAILABLE_IN_ALL +void g_signal_query (guint signal_id, + GSignalQuery *query); +GLIB_AVAILABLE_IN_ALL +guint* g_signal_list_ids (GType itype, + guint *n_ids); +GLIB_AVAILABLE_IN_ALL +gboolean g_signal_parse_name (const gchar *detailed_signal, + GType itype, + guint *signal_id_p, + GQuark *detail_p, + gboolean force_detail_quark); +GLIB_AVAILABLE_IN_ALL +GSignalInvocationHint* g_signal_get_invocation_hint (gpointer instance); + + +/* --- signal emissions --- */ +GLIB_AVAILABLE_IN_ALL +void g_signal_stop_emission (gpointer instance, + guint signal_id, + GQuark detail); +GLIB_AVAILABLE_IN_ALL +void g_signal_stop_emission_by_name (gpointer instance, + const gchar *detailed_signal); +GLIB_AVAILABLE_IN_ALL +gulong g_signal_add_emission_hook (guint signal_id, + GQuark detail, + GSignalEmissionHook hook_func, + gpointer hook_data, + GDestroyNotify data_destroy); +GLIB_AVAILABLE_IN_ALL +void g_signal_remove_emission_hook (guint signal_id, + gulong hook_id); + + +/* --- signal handlers --- */ +GLIB_AVAILABLE_IN_ALL +gboolean g_signal_has_handler_pending (gpointer instance, + guint signal_id, + GQuark detail, + gboolean may_be_blocked); +GLIB_AVAILABLE_IN_ALL +gulong g_signal_connect_closure_by_id (gpointer instance, + guint signal_id, + GQuark detail, + GClosure *closure, + gboolean after); +GLIB_AVAILABLE_IN_ALL +gulong g_signal_connect_closure (gpointer instance, + const gchar *detailed_signal, + GClosure *closure, + gboolean after); +GLIB_AVAILABLE_IN_ALL +gulong g_signal_connect_data (gpointer instance, + const gchar *detailed_signal, + GCallback c_handler, + gpointer data, + GClosureNotify destroy_data, + GConnectFlags connect_flags); +GLIB_AVAILABLE_IN_ALL +void g_signal_handler_block (gpointer instance, + gulong handler_id); +GLIB_AVAILABLE_IN_ALL +void g_signal_handler_unblock (gpointer instance, + gulong handler_id); +GLIB_AVAILABLE_IN_ALL +void g_signal_handler_disconnect (gpointer instance, + gulong handler_id); +GLIB_AVAILABLE_IN_ALL +gboolean g_signal_handler_is_connected (gpointer instance, + gulong handler_id); +GLIB_AVAILABLE_IN_ALL +gulong g_signal_handler_find (gpointer instance, + GSignalMatchType mask, + guint signal_id, + GQuark detail, + GClosure *closure, + gpointer func, + gpointer data); +GLIB_AVAILABLE_IN_ALL +guint g_signal_handlers_block_matched (gpointer instance, + GSignalMatchType mask, + guint signal_id, + GQuark detail, + GClosure *closure, + gpointer func, + gpointer data); +GLIB_AVAILABLE_IN_ALL +guint g_signal_handlers_unblock_matched (gpointer instance, + GSignalMatchType mask, + guint signal_id, + GQuark detail, + GClosure *closure, + gpointer func, + gpointer data); +GLIB_AVAILABLE_IN_ALL +guint g_signal_handlers_disconnect_matched (gpointer instance, + GSignalMatchType mask, + guint signal_id, + GQuark detail, + GClosure *closure, + gpointer func, + gpointer data); + +GLIB_AVAILABLE_IN_2_62 +void g_clear_signal_handler (gulong *handler_id_ptr, + gpointer instance); + +#define g_clear_signal_handler(handler_id_ptr, instance) \ + G_STMT_START { \ + G_STATIC_ASSERT (sizeof *(handler_id_ptr) == sizeof (gulong)); \ + gulong _handler_id = *(handler_id_ptr); \ + \ + if (_handler_id > 0) \ + { \ + g_signal_handler_disconnect ((instance), _handler_id); \ + *(handler_id_ptr) = 0; \ + } \ + } G_STMT_END \ + GLIB_AVAILABLE_MACRO_IN_2_62 + +/* --- overriding and chaining --- */ +GLIB_AVAILABLE_IN_ALL +void g_signal_override_class_closure (guint signal_id, + GType instance_type, + GClosure *class_closure); +GLIB_AVAILABLE_IN_ALL +void g_signal_override_class_handler (const gchar *signal_name, + GType instance_type, + GCallback class_handler); +GLIB_AVAILABLE_IN_ALL +void g_signal_chain_from_overridden (const GValue *instance_and_params, + GValue *return_value); +GLIB_AVAILABLE_IN_ALL +void g_signal_chain_from_overridden_handler (gpointer instance, + ...); + + +/* --- convenience --- */ +/** + * g_signal_connect: + * @instance: the instance to connect to. + * @detailed_signal: a string of the form "signal-name::detail". + * @c_handler: the #GCallback to connect. + * @data: data to pass to @c_handler calls. + * + * Connects a #GCallback function to a signal for a particular object. + * + * The handler will be called before the default handler of the signal. + * + * See [memory management of signal handlers][signal-memory-management] for + * details on how to handle the return value and memory management of @data. + * + * Returns: the handler ID, of type #gulong (always greater than 0 for successful connections) + */ +#define g_signal_connect(instance, detailed_signal, c_handler, data) \ + g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0) +/** + * g_signal_connect_after: + * @instance: the instance to connect to. + * @detailed_signal: a string of the form "signal-name::detail". + * @c_handler: the #GCallback to connect. + * @data: data to pass to @c_handler calls. + * + * Connects a #GCallback function to a signal for a particular object. + * + * The handler will be called after the default handler of the signal. + * + * Returns: the handler ID, of type #gulong (always greater than 0 for successful connections) + */ +#define g_signal_connect_after(instance, detailed_signal, c_handler, data) \ + g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER) +/** + * g_signal_connect_swapped: + * @instance: the instance to connect to. + * @detailed_signal: a string of the form "signal-name::detail". + * @c_handler: the #GCallback to connect. + * @data: data to pass to @c_handler calls. + * + * Connects a #GCallback function to a signal for a particular object. + * + * The instance on which the signal is emitted and @data will be swapped when + * calling the handler. This is useful when calling pre-existing functions to + * operate purely on the @data, rather than the @instance: swapping the + * parameters avoids the need to write a wrapper function. + * + * For example, this allows the shorter code: + * |[<!-- language="C" --> + * g_signal_connect_swapped (button, "clicked", + * (GCallback) gtk_widget_hide, other_widget); + * ]| + * + * Rather than the cumbersome: + * |[<!-- language="C" --> + * static void + * button_clicked_cb (GtkButton *button, GtkWidget *other_widget) + * { + * gtk_widget_hide (other_widget); + * } + * + * ... + * + * g_signal_connect (button, "clicked", + * (GCallback) button_clicked_cb, other_widget); + * ]| + * + * Returns: the handler ID, of type #gulong (always greater than 0 for successful connections) + */ +#define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \ + g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED) +/** + * g_signal_handlers_disconnect_by_func: + * @instance: The instance to remove handlers from. + * @func: The C closure callback of the handlers (useless for non-C closures). + * @data: The closure data of the handlers' closures. + * + * Disconnects all handlers on an instance that match @func and @data. + * + * Returns: The number of handlers that matched. + */ +#define g_signal_handlers_disconnect_by_func(instance, func, data) \ + g_signal_handlers_disconnect_matched ((instance), \ + (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \ + 0, 0, NULL, (func), (data)) + +/** + * g_signal_handlers_disconnect_by_data: + * @instance: The instance to remove handlers from + * @data: the closure data of the handlers' closures + * + * Disconnects all handlers on an instance that match @data. + * + * Returns: The number of handlers that matched. + * + * Since: 2.32 + */ +#define g_signal_handlers_disconnect_by_data(instance, data) \ + g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, (data)) + +/** + * g_signal_handlers_block_by_func: + * @instance: The instance to block handlers from. + * @func: The C closure callback of the handlers (useless for non-C closures). + * @data: The closure data of the handlers' closures. + * + * Blocks all handlers on an instance that match @func and @data. + * + * Returns: The number of handlers that matched. + */ +#define g_signal_handlers_block_by_func(instance, func, data) \ + g_signal_handlers_block_matched ((instance), \ + (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \ + 0, 0, NULL, (func), (data)) +/** + * g_signal_handlers_unblock_by_func: + * @instance: The instance to unblock handlers from. + * @func: The C closure callback of the handlers (useless for non-C closures). + * @data: The closure data of the handlers' closures. + * + * Unblocks all handlers on an instance that match @func and @data. + * + * Returns: The number of handlers that matched. + */ +#define g_signal_handlers_unblock_by_func(instance, func, data) \ + g_signal_handlers_unblock_matched ((instance), \ + (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \ + 0, 0, NULL, (func), (data)) + + +GLIB_AVAILABLE_IN_ALL +gboolean g_signal_accumulator_true_handled (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy); + +GLIB_AVAILABLE_IN_ALL +gboolean g_signal_accumulator_first_wins (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy); + +/*< private >*/ +GLIB_AVAILABLE_IN_ALL +void g_signal_handlers_destroy (gpointer instance); +void _g_signals_destroy (GType itype); + +G_END_DECLS + +#endif /* __G_SIGNAL_H__ */ diff --git a/include/glib/gobject/gsourceclosure.h b/include/glib/gobject/gsourceclosure.h new file mode 100644 index 0000000000..4847677033 --- /dev/null +++ b/include/glib/gobject/gsourceclosure.h @@ -0,0 +1,38 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2001 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __G_SOURCECLOSURE_H__ +#define __G_SOURCECLOSURE_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gclosure.h> +#include <gobject/glib-types.h> + +G_BEGIN_DECLS + +GLIB_AVAILABLE_IN_ALL +void g_source_set_closure (GSource *source, + GClosure *closure); + +GLIB_AVAILABLE_IN_ALL +void g_source_set_dummy_callback (GSource *source); + +G_END_DECLS + +#endif /* __G_SOURCECLOSURE_H__ */ diff --git a/include/glib/gobject/gtype.h b/include/glib/gobject/gtype.h new file mode 100644 index 0000000000..d9e5d110ce --- /dev/null +++ b/include/glib/gobject/gtype.h @@ -0,0 +1,2356 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __G_TYPE_H__ +#define __G_TYPE_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <glib.h> + +G_BEGIN_DECLS + +/* Basic Type Macros + */ +/** + * G_TYPE_FUNDAMENTAL: + * @type: A #GType value. + * + * The fundamental type which is the ancestor of @type. + * Fundamental types are types that serve as ultimate bases for the derived types, + * thus they are the roots of distinct inheritance hierarchies. + */ +#define G_TYPE_FUNDAMENTAL(type) (g_type_fundamental (type)) +/** + * G_TYPE_FUNDAMENTAL_MAX: + * + * An integer constant that represents the number of identifiers reserved + * for types that are assigned at compile-time. + */ +#define G_TYPE_FUNDAMENTAL_MAX (255 << G_TYPE_FUNDAMENTAL_SHIFT) + +/* Constant fundamental types, + */ +/** + * G_TYPE_INVALID: + * + * An invalid #GType used as error return value in some functions which return + * a #GType. + */ +#define G_TYPE_INVALID G_TYPE_MAKE_FUNDAMENTAL (0) +/** + * G_TYPE_NONE: + * + * A fundamental type which is used as a replacement for the C + * void return type. + */ +#define G_TYPE_NONE G_TYPE_MAKE_FUNDAMENTAL (1) +/** + * G_TYPE_INTERFACE: + * + * The fundamental type from which all interfaces are derived. + */ +#define G_TYPE_INTERFACE G_TYPE_MAKE_FUNDAMENTAL (2) +/** + * G_TYPE_CHAR: + * + * The fundamental type corresponding to #gchar. + * The type designated by G_TYPE_CHAR is unconditionally an 8-bit signed integer. + * This may or may not be the same type a the C type "gchar". + */ +#define G_TYPE_CHAR G_TYPE_MAKE_FUNDAMENTAL (3) +/** + * G_TYPE_UCHAR: + * + * The fundamental type corresponding to #guchar. + */ +#define G_TYPE_UCHAR G_TYPE_MAKE_FUNDAMENTAL (4) +/** + * G_TYPE_BOOLEAN: + * + * The fundamental type corresponding to #gboolean. + */ +#define G_TYPE_BOOLEAN G_TYPE_MAKE_FUNDAMENTAL (5) +/** + * G_TYPE_INT: + * + * The fundamental type corresponding to #gint. + */ +#define G_TYPE_INT G_TYPE_MAKE_FUNDAMENTAL (6) +/** + * G_TYPE_UINT: + * + * The fundamental type corresponding to #guint. + */ +#define G_TYPE_UINT G_TYPE_MAKE_FUNDAMENTAL (7) +/** + * G_TYPE_LONG: + * + * The fundamental type corresponding to #glong. + */ +#define G_TYPE_LONG G_TYPE_MAKE_FUNDAMENTAL (8) +/** + * G_TYPE_ULONG: + * + * The fundamental type corresponding to #gulong. + */ +#define G_TYPE_ULONG G_TYPE_MAKE_FUNDAMENTAL (9) +/** + * G_TYPE_INT64: + * + * The fundamental type corresponding to #gint64. + */ +#define G_TYPE_INT64 G_TYPE_MAKE_FUNDAMENTAL (10) +/** + * G_TYPE_UINT64: + * + * The fundamental type corresponding to #guint64. + */ +#define G_TYPE_UINT64 G_TYPE_MAKE_FUNDAMENTAL (11) +/** + * G_TYPE_ENUM: + * + * The fundamental type from which all enumeration types are derived. + */ +#define G_TYPE_ENUM G_TYPE_MAKE_FUNDAMENTAL (12) +/** + * G_TYPE_FLAGS: + * + * The fundamental type from which all flags types are derived. + */ +#define G_TYPE_FLAGS G_TYPE_MAKE_FUNDAMENTAL (13) +/** + * G_TYPE_FLOAT: + * + * The fundamental type corresponding to #gfloat. + */ +#define G_TYPE_FLOAT G_TYPE_MAKE_FUNDAMENTAL (14) +/** + * G_TYPE_DOUBLE: + * + * The fundamental type corresponding to #gdouble. + */ +#define G_TYPE_DOUBLE G_TYPE_MAKE_FUNDAMENTAL (15) +/** + * G_TYPE_STRING: + * + * The fundamental type corresponding to nul-terminated C strings. + */ +#define G_TYPE_STRING G_TYPE_MAKE_FUNDAMENTAL (16) +/** + * G_TYPE_POINTER: + * + * The fundamental type corresponding to #gpointer. + */ +#define G_TYPE_POINTER G_TYPE_MAKE_FUNDAMENTAL (17) +/** + * G_TYPE_BOXED: + * + * The fundamental type from which all boxed types are derived. + */ +#define G_TYPE_BOXED G_TYPE_MAKE_FUNDAMENTAL (18) +/** + * G_TYPE_PARAM: + * + * The fundamental type from which all #GParamSpec types are derived. + */ +#define G_TYPE_PARAM G_TYPE_MAKE_FUNDAMENTAL (19) +/** + * G_TYPE_OBJECT: + * + * The fundamental type for #GObject. + */ +#define G_TYPE_OBJECT G_TYPE_MAKE_FUNDAMENTAL (20) +/** + * G_TYPE_VARIANT: + * + * The fundamental type corresponding to #GVariant. + * + * All floating #GVariant instances passed through the #GType system are + * consumed. + * + * Note that callbacks in closures, and signal handlers + * for signals of return type %G_TYPE_VARIANT, must never return floating + * variants. + * + * Note: GLib 2.24 did include a boxed type with this name. It was replaced + * with this fundamental type in 2.26. + * + * Since: 2.26 + */ +#define G_TYPE_VARIANT G_TYPE_MAKE_FUNDAMENTAL (21) + + +/* Reserved fundamental type numbers to create new fundamental + * type IDs with G_TYPE_MAKE_FUNDAMENTAL(). + * + * Open an issue on https://gitlab.gnome.org/GNOME/glib/issues/new for + * reservations. + */ +/** + * G_TYPE_FUNDAMENTAL_SHIFT: + * + * Shift value used in converting numbers to type IDs. + */ +#define G_TYPE_FUNDAMENTAL_SHIFT (2) +/** + * G_TYPE_MAKE_FUNDAMENTAL: + * @x: the fundamental type number. + * + * Get the type ID for the fundamental type number @x. + * Use g_type_fundamental_next() instead of this macro to create new fundamental + * types. + * + * Returns: the GType + */ +#define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT)) +/** + * G_TYPE_RESERVED_GLIB_FIRST: + * + * First fundamental type number to create a new fundamental type id with + * G_TYPE_MAKE_FUNDAMENTAL() reserved for GLib. + */ +#define G_TYPE_RESERVED_GLIB_FIRST (22) +/** + * G_TYPE_RESERVED_GLIB_LAST: + * + * Last fundamental type number reserved for GLib. + */ +#define G_TYPE_RESERVED_GLIB_LAST (31) +/** + * G_TYPE_RESERVED_BSE_FIRST: + * + * First fundamental type number to create a new fundamental type id with + * G_TYPE_MAKE_FUNDAMENTAL() reserved for BSE. + */ +#define G_TYPE_RESERVED_BSE_FIRST (32) +/** + * G_TYPE_RESERVED_BSE_LAST: + * + * Last fundamental type number reserved for BSE. + */ +#define G_TYPE_RESERVED_BSE_LAST (48) +/** + * G_TYPE_RESERVED_USER_FIRST: + * + * First available fundamental type number to create new fundamental + * type id with G_TYPE_MAKE_FUNDAMENTAL(). + */ +#define G_TYPE_RESERVED_USER_FIRST (49) + + +/* Type Checking Macros + */ +/** + * G_TYPE_IS_FUNDAMENTAL: + * @type: A #GType value + * + * Checks if @type is a fundamental type. + * + * Returns: %TRUE on success + */ +#define G_TYPE_IS_FUNDAMENTAL(type) ((type) <= G_TYPE_FUNDAMENTAL_MAX) +/** + * G_TYPE_IS_DERIVED: + * @type: A #GType value + * + * Checks if @type is derived (or in object-oriented terminology: + * inherited) from another type (this holds true for all non-fundamental + * types). + * + * Returns: %TRUE on success + */ +#define G_TYPE_IS_DERIVED(type) ((type) > G_TYPE_FUNDAMENTAL_MAX) +/** + * G_TYPE_IS_INTERFACE: + * @type: A #GType value + * + * Checks if @type is an interface type. + * An interface type provides a pure API, the implementation + * of which is provided by another type (which is then said to conform + * to the interface). GLib interfaces are somewhat analogous to Java + * interfaces and C++ classes containing only pure virtual functions, + * with the difference that GType interfaces are not derivable (but see + * g_type_interface_add_prerequisite() for an alternative). + * + * Returns: %TRUE on success + */ +#define G_TYPE_IS_INTERFACE(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE) +/** + * G_TYPE_IS_CLASSED: + * @type: A #GType value + * + * Checks if @type is a classed type. + * + * Returns: %TRUE on success + */ +#define G_TYPE_IS_CLASSED(type) (g_type_test_flags ((type), G_TYPE_FLAG_CLASSED)) +/** + * G_TYPE_IS_INSTANTIATABLE: + * @type: A #GType value + * + * Checks if @type can be instantiated. Instantiation is the + * process of creating an instance (object) of this type. + * + * Returns: %TRUE on success + */ +#define G_TYPE_IS_INSTANTIATABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_INSTANTIATABLE)) +/** + * G_TYPE_IS_DERIVABLE: + * @type: A #GType value + * + * Checks if @type is a derivable type. A derivable type can + * be used as the base class of a flat (single-level) class hierarchy. + * + * Returns: %TRUE on success + */ +#define G_TYPE_IS_DERIVABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_DERIVABLE)) +/** + * G_TYPE_IS_DEEP_DERIVABLE: + * @type: A #GType value + * + * Checks if @type is a deep derivable type. A deep derivable type + * can be used as the base class of a deep (multi-level) class hierarchy. + * + * Returns: %TRUE on success + */ +#define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_test_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE)) +/** + * G_TYPE_IS_ABSTRACT: + * @type: A #GType value + * + * Checks if @type is an abstract type. An abstract type cannot be + * instantiated and is normally used as an abstract base class for + * derived classes. + * + * Returns: %TRUE on success + */ +#define G_TYPE_IS_ABSTRACT(type) (g_type_test_flags ((type), G_TYPE_FLAG_ABSTRACT)) +/** + * G_TYPE_IS_VALUE_ABSTRACT: + * @type: A #GType value + * + * Checks if @type is an abstract value type. An abstract value type introduces + * a value table, but can't be used for g_value_init() and is normally used as + * an abstract base type for derived value types. + * + * Returns: %TRUE on success + */ +#define G_TYPE_IS_VALUE_ABSTRACT(type) (g_type_test_flags ((type), G_TYPE_FLAG_VALUE_ABSTRACT)) +/** + * G_TYPE_IS_VALUE_TYPE: + * @type: A #GType value + * + * Checks if @type is a value type and can be used with g_value_init(). + * + * Returns: %TRUE on success + */ +#define G_TYPE_IS_VALUE_TYPE(type) (g_type_check_is_value_type (type)) +/** + * G_TYPE_HAS_VALUE_TABLE: + * @type: A #GType value + * + * Checks if @type has a #GTypeValueTable. + * + * Returns: %TRUE on success + */ +#define G_TYPE_HAS_VALUE_TABLE(type) (g_type_value_table_peek (type) != NULL) + + +/* Typedefs + */ +/** + * GType: + * + * A numerical value which represents the unique identifier of a registered + * type. + */ +#if GLIB_SIZEOF_SIZE_T != GLIB_SIZEOF_LONG || !defined __cplusplus +typedef gsize GType; +#else /* for historic reasons, C++ links against gulong GTypes */ +typedef gulong GType; +#endif +typedef struct _GValue GValue; +typedef union _GTypeCValue GTypeCValue; +typedef struct _GTypePlugin GTypePlugin; +typedef struct _GTypeClass GTypeClass; +typedef struct _GTypeInterface GTypeInterface; +typedef struct _GTypeInstance GTypeInstance; +typedef struct _GTypeInfo GTypeInfo; +typedef struct _GTypeFundamentalInfo GTypeFundamentalInfo; +typedef struct _GInterfaceInfo GInterfaceInfo; +typedef struct _GTypeValueTable GTypeValueTable; +typedef struct _GTypeQuery GTypeQuery; + + +/* Basic Type Structures + */ +/** + * GTypeClass: + * + * An opaque structure used as the base of all classes. + */ +struct _GTypeClass +{ + /*< private >*/ + GType g_type; +}; +/** + * GTypeInstance: + * + * An opaque structure used as the base of all type instances. + */ +struct _GTypeInstance +{ + /*< private >*/ + GTypeClass *g_class; +}; +/** + * GTypeInterface: + * + * An opaque structure used as the base of all interface types. + */ +struct _GTypeInterface +{ + /*< private >*/ + GType g_type; /* iface type */ + GType g_instance_type; +}; +/** + * GTypeQuery: + * @type: the #GType value of the type + * @type_name: the name of the type + * @class_size: the size of the class structure + * @instance_size: the size of the instance structure + * + * A structure holding information for a specific type. + * It is filled in by the g_type_query() function. + */ +struct _GTypeQuery +{ + GType type; + const gchar *type_name; + guint class_size; + guint instance_size; +}; + + +/* Casts, checks and accessors for structured types + * usage of these macros is reserved to type implementations only + */ +/*< protected >*/ +/** + * G_TYPE_CHECK_INSTANCE: + * @instance: Location of a #GTypeInstance structure + * + * Checks if @instance is a valid #GTypeInstance structure, + * otherwise issues a warning and returns %FALSE. %NULL is not a valid + * #GTypeInstance. + * + * This macro should only be used in type implementations. + * + * Returns: %TRUE on success + */ +#define G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI ((GTypeInstance*) (instance))) +/** + * G_TYPE_CHECK_INSTANCE_CAST: + * @instance: (nullable): Location of a #GTypeInstance structure + * @g_type: The type to be returned + * @c_type: The corresponding C type of @g_type + * + * Checks that @instance is an instance of the type identified by @g_type + * and issues a warning if this is not the case. Returns @instance casted + * to a pointer to @c_type. + * + * No warning will be issued if @instance is %NULL, and %NULL will be returned. + * + * This macro should only be used in type implementations. + */ +#define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type)) +/** + * G_TYPE_CHECK_INSTANCE_TYPE: + * @instance: (nullable): Location of a #GTypeInstance structure. + * @g_type: The type to be checked + * + * Checks if @instance is an instance of the type identified by @g_type. If + * @instance is %NULL, %FALSE will be returned. + * + * This macro should only be used in type implementations. + * + * Returns: %TRUE on success + */ +#define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type))) +/** + * G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE: + * @instance: (nullable): Location of a #GTypeInstance structure. + * @g_type: The fundamental type to be checked + * + * Checks if @instance is an instance of the fundamental type identified by @g_type. + * If @instance is %NULL, %FALSE will be returned. + * + * This macro should only be used in type implementations. + * + * Returns: %TRUE on success + */ +#define G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE(instance, g_type) (_G_TYPE_CIFT ((instance), (g_type))) +/** + * G_TYPE_INSTANCE_GET_CLASS: + * @instance: Location of the #GTypeInstance structure + * @g_type: The #GType of the class to be returned + * @c_type: The C type of the class structure + * + * Get the class structure of a given @instance, casted + * to a specified ancestor type @g_type of the instance. + * + * Note that while calling a GInstanceInitFunc(), the class pointer + * gets modified, so it might not always return the expected pointer. + * + * This macro should only be used in type implementations. + * + * Returns: a pointer to the class structure + */ +#define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), (g_type), c_type)) +/** + * G_TYPE_INSTANCE_GET_INTERFACE: + * @instance: Location of the #GTypeInstance structure + * @g_type: The #GType of the interface to be returned + * @c_type: The C type of the interface structure + * + * Get the interface structure for interface @g_type of a given @instance. + * + * This macro should only be used in type implementations. + * + * Returns: a pointer to the interface structure + */ +#define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type)) +/** + * G_TYPE_CHECK_CLASS_CAST: + * @g_class: Location of a #GTypeClass structure + * @g_type: The type to be returned + * @c_type: The corresponding C type of class structure of @g_type + * + * Checks that @g_class is a class structure of the type identified by @g_type + * and issues a warning if this is not the case. Returns @g_class casted + * to a pointer to @c_type. %NULL is not a valid class structure. + * + * This macro should only be used in type implementations. + */ +#define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type)) +/** + * G_TYPE_CHECK_CLASS_TYPE: + * @g_class: (nullable): Location of a #GTypeClass structure + * @g_type: The type to be checked + * + * Checks if @g_class is a class structure of the type identified by + * @g_type. If @g_class is %NULL, %FALSE will be returned. + * + * This macro should only be used in type implementations. + * + * Returns: %TRUE on success + */ +#define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type))) +/** + * G_TYPE_CHECK_VALUE: + * @value: a #GValue + * + * Checks if @value has been initialized to hold values + * of a value type. + * + * This macro should only be used in type implementations. + * + * Returns: %TRUE on success + */ +#define G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV ((value))) +/** + * G_TYPE_CHECK_VALUE_TYPE: + * @value: a #GValue + * @g_type: The type to be checked + * + * Checks if @value has been initialized to hold values + * of type @g_type. + * + * This macro should only be used in type implementations. + * + * Returns: %TRUE on success + */ +#define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVH ((value), (g_type))) +/** + * G_TYPE_FROM_INSTANCE: + * @instance: Location of a valid #GTypeInstance structure + * + * Get the type identifier from a given @instance structure. + * + * This macro should only be used in type implementations. + * + * Returns: the #GType + */ +#define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class)) +/** + * G_TYPE_FROM_CLASS: + * @g_class: Location of a valid #GTypeClass structure + * + * Get the type identifier from a given @class structure. + * + * This macro should only be used in type implementations. + * + * Returns: the #GType + */ +#define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type) +/** + * G_TYPE_FROM_INTERFACE: + * @g_iface: Location of a valid #GTypeInterface structure + * + * Get the type identifier from a given @interface structure. + * + * This macro should only be used in type implementations. + * + * Returns: the #GType + */ +#define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type) + +/** + * G_TYPE_INSTANCE_GET_PRIVATE: + * @instance: the instance of a type deriving from @private_type + * @g_type: the type identifying which private data to retrieve + * @c_type: The C type for the private structure + * + * Gets the private structure for a particular type. + * The private structure must have been registered in the + * class_init function with g_type_class_add_private(). + * + * This macro should only be used in type implementations. + * + * Since: 2.4 + * Deprecated: 2.58: Use %G_ADD_PRIVATE and the generated + * `your_type_get_instance_private()` function instead + * Returns: (not nullable): a pointer to the private data structure + */ +#define G_TYPE_INSTANCE_GET_PRIVATE(instance, g_type, c_type) ((c_type*) g_type_instance_get_private ((GTypeInstance*) (instance), (g_type))) GLIB_DEPRECATED_MACRO_IN_2_58_FOR(G_ADD_PRIVATE) + +/** + * G_TYPE_CLASS_GET_PRIVATE: + * @klass: the class of a type deriving from @private_type + * @g_type: the type identifying which private data to retrieve + * @c_type: The C type for the private structure + * + * Gets the private class structure for a particular type. + * The private structure must have been registered in the + * get_type() function with g_type_add_class_private(). + * + * This macro should only be used in type implementations. + * + * Since: 2.24 + * Returns: (not nullable): a pointer to the private data structure + */ +#define G_TYPE_CLASS_GET_PRIVATE(klass, g_type, c_type) ((c_type*) g_type_class_get_private ((GTypeClass*) (klass), (g_type))) + +/** + * GTypeDebugFlags: + * @G_TYPE_DEBUG_NONE: Print no messages + * @G_TYPE_DEBUG_OBJECTS: Print messages about object bookkeeping + * @G_TYPE_DEBUG_SIGNALS: Print messages about signal emissions + * @G_TYPE_DEBUG_MASK: Mask covering all debug flags + * @G_TYPE_DEBUG_INSTANCE_COUNT: Keep a count of instances of each type + * + * These flags used to be passed to g_type_init_with_debug_flags() which + * is now deprecated. + * + * If you need to enable debugging features, use the GOBJECT_DEBUG + * environment variable. + * + * Deprecated: 2.36: g_type_init() is now done automatically + */ +typedef enum /*< skip >*/ +{ + G_TYPE_DEBUG_NONE = 0, + G_TYPE_DEBUG_OBJECTS = 1 << 0, + G_TYPE_DEBUG_SIGNALS = 1 << 1, + G_TYPE_DEBUG_INSTANCE_COUNT = 1 << 2, + G_TYPE_DEBUG_MASK = 0x07 +} GTypeDebugFlags GLIB_DEPRECATED_TYPE_IN_2_36; + + +/* --- prototypes --- */ +G_GNUC_BEGIN_IGNORE_DEPRECATIONS +GLIB_DEPRECATED_IN_2_36 +void g_type_init (void); +GLIB_DEPRECATED_IN_2_36 +void g_type_init_with_debug_flags (GTypeDebugFlags debug_flags); +G_GNUC_END_IGNORE_DEPRECATIONS + +GLIB_AVAILABLE_IN_ALL +const gchar * g_type_name (GType type); +GLIB_AVAILABLE_IN_ALL +GQuark g_type_qname (GType type); +GLIB_AVAILABLE_IN_ALL +GType g_type_from_name (const gchar *name); +GLIB_AVAILABLE_IN_ALL +GType g_type_parent (GType type); +GLIB_AVAILABLE_IN_ALL +guint g_type_depth (GType type); +GLIB_AVAILABLE_IN_ALL +GType g_type_next_base (GType leaf_type, + GType root_type); +GLIB_AVAILABLE_IN_ALL +gboolean g_type_is_a (GType type, + GType is_a_type); +GLIB_AVAILABLE_IN_ALL +gpointer g_type_class_ref (GType type); +GLIB_AVAILABLE_IN_ALL +gpointer g_type_class_peek (GType type); +GLIB_AVAILABLE_IN_ALL +gpointer g_type_class_peek_static (GType type); +GLIB_AVAILABLE_IN_ALL +void g_type_class_unref (gpointer g_class); +GLIB_AVAILABLE_IN_ALL +gpointer g_type_class_peek_parent (gpointer g_class); +GLIB_AVAILABLE_IN_ALL +gpointer g_type_interface_peek (gpointer instance_class, + GType iface_type); +GLIB_AVAILABLE_IN_ALL +gpointer g_type_interface_peek_parent (gpointer g_iface); + +GLIB_AVAILABLE_IN_ALL +gpointer g_type_default_interface_ref (GType g_type); +GLIB_AVAILABLE_IN_ALL +gpointer g_type_default_interface_peek (GType g_type); +GLIB_AVAILABLE_IN_ALL +void g_type_default_interface_unref (gpointer g_iface); + +/* g_free() the returned arrays */ +GLIB_AVAILABLE_IN_ALL +GType* g_type_children (GType type, + guint *n_children); +GLIB_AVAILABLE_IN_ALL +GType* g_type_interfaces (GType type, + guint *n_interfaces); + +/* per-type _static_ data */ +GLIB_AVAILABLE_IN_ALL +void g_type_set_qdata (GType type, + GQuark quark, + gpointer data); +GLIB_AVAILABLE_IN_ALL +gpointer g_type_get_qdata (GType type, + GQuark quark); +GLIB_AVAILABLE_IN_ALL +void g_type_query (GType type, + GTypeQuery *query); + +GLIB_AVAILABLE_IN_2_44 +int g_type_get_instance_count (GType type); + +/* --- type registration --- */ +/** + * GBaseInitFunc: + * @g_class: (type GObject.TypeClass): The #GTypeClass structure to initialize + * + * A callback function used by the type system to do base initialization + * of the class structures of derived types. It is called as part of the + * initialization process of all derived classes and should reallocate + * or reset all dynamic class members copied over from the parent class. + * For example, class members (such as strings) that are not sufficiently + * handled by a plain memory copy of the parent class into the derived class + * have to be altered. See GClassInitFunc() for a discussion of the class + * initialization process. + */ +typedef void (*GBaseInitFunc) (gpointer g_class); +/** + * GBaseFinalizeFunc: + * @g_class: (type GObject.TypeClass): The #GTypeClass structure to finalize + * + * A callback function used by the type system to finalize those portions + * of a derived types class structure that were setup from the corresponding + * GBaseInitFunc() function. Class finalization basically works the inverse + * way in which class initialization is performed. + * See GClassInitFunc() for a discussion of the class initialization process. + */ +typedef void (*GBaseFinalizeFunc) (gpointer g_class); +/** + * GClassInitFunc: + * @g_class: (type GObject.TypeClass): The #GTypeClass structure to initialize. + * @class_data: The @class_data member supplied via the #GTypeInfo structure. + * + * A callback function used by the type system to initialize the class + * of a specific type. This function should initialize all static class + * members. + * + * The initialization process of a class involves: + * + * - Copying common members from the parent class over to the + * derived class structure. + * - Zero initialization of the remaining members not copied + * over from the parent class. + * - Invocation of the GBaseInitFunc() initializers of all parent + * types and the class' type. + * - Invocation of the class' GClassInitFunc() initializer. + * + * Since derived classes are partially initialized through a memory copy + * of the parent class, the general rule is that GBaseInitFunc() and + * GBaseFinalizeFunc() should take care of necessary reinitialization + * and release of those class members that were introduced by the type + * that specified these GBaseInitFunc()/GBaseFinalizeFunc(). + * GClassInitFunc() should only care about initializing static + * class members, while dynamic class members (such as allocated strings + * or reference counted resources) are better handled by a GBaseInitFunc() + * for this type, so proper initialization of the dynamic class members + * is performed for class initialization of derived types as well. + * + * An example may help to correspond the intend of the different class + * initializers: + * + * |[<!-- language="C" --> + * typedef struct { + * GObjectClass parent_class; + * gint static_integer; + * gchar *dynamic_string; + * } TypeAClass; + * static void + * type_a_base_class_init (TypeAClass *class) + * { + * class->dynamic_string = g_strdup ("some string"); + * } + * static void + * type_a_base_class_finalize (TypeAClass *class) + * { + * g_free (class->dynamic_string); + * } + * static void + * type_a_class_init (TypeAClass *class) + * { + * class->static_integer = 42; + * } + * + * typedef struct { + * TypeAClass parent_class; + * gfloat static_float; + * GString *dynamic_gstring; + * } TypeBClass; + * static void + * type_b_base_class_init (TypeBClass *class) + * { + * class->dynamic_gstring = g_string_new ("some other string"); + * } + * static void + * type_b_base_class_finalize (TypeBClass *class) + * { + * g_string_free (class->dynamic_gstring); + * } + * static void + * type_b_class_init (TypeBClass *class) + * { + * class->static_float = 3.14159265358979323846; + * } + * ]| + * Initialization of TypeBClass will first cause initialization of + * TypeAClass (derived classes reference their parent classes, see + * g_type_class_ref() on this). + * + * Initialization of TypeAClass roughly involves zero-initializing its fields, + * then calling its GBaseInitFunc() type_a_base_class_init() to allocate + * its dynamic members (dynamic_string), and finally calling its GClassInitFunc() + * type_a_class_init() to initialize its static members (static_integer). + * The first step in the initialization process of TypeBClass is then + * a plain memory copy of the contents of TypeAClass into TypeBClass and + * zero-initialization of the remaining fields in TypeBClass. + * The dynamic members of TypeAClass within TypeBClass now need + * reinitialization which is performed by calling type_a_base_class_init() + * with an argument of TypeBClass. + * + * After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init() + * is called to allocate the dynamic members of TypeBClass (dynamic_gstring), + * and finally the GClassInitFunc() of TypeBClass, type_b_class_init(), + * is called to complete the initialization process with the static members + * (static_float). + * + * Corresponding finalization counter parts to the GBaseInitFunc() functions + * have to be provided to release allocated resources at class finalization + * time. + */ +typedef void (*GClassInitFunc) (gpointer g_class, + gpointer class_data); +/** + * GClassFinalizeFunc: + * @g_class: (type GObject.TypeClass): The #GTypeClass structure to finalize + * @class_data: The @class_data member supplied via the #GTypeInfo structure + * + * A callback function used by the type system to finalize a class. + * This function is rarely needed, as dynamically allocated class resources + * should be handled by GBaseInitFunc() and GBaseFinalizeFunc(). + * Also, specification of a GClassFinalizeFunc() in the #GTypeInfo + * structure of a static type is invalid, because classes of static types + * will never be finalized (they are artificially kept alive when their + * reference count drops to zero). + */ +typedef void (*GClassFinalizeFunc) (gpointer g_class, + gpointer class_data); +/** + * GInstanceInitFunc: + * @instance: The instance to initialize + * @g_class: (type GObject.TypeClass): The class of the type the instance is + * created for + * + * A callback function used by the type system to initialize a new + * instance of a type. This function initializes all instance members and + * allocates any resources required by it. + * + * Initialization of a derived instance involves calling all its parent + * types instance initializers, so the class member of the instance + * is altered during its initialization to always point to the class that + * belongs to the type the current initializer was introduced for. + * + * The extended members of @instance are guaranteed to have been filled with + * zeros before this function is called. + */ +typedef void (*GInstanceInitFunc) (GTypeInstance *instance, + gpointer g_class); +/** + * GInterfaceInitFunc: + * @g_iface: (type GObject.TypeInterface): The interface structure to initialize + * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure + * + * A callback function used by the type system to initialize a new + * interface. This function should initialize all internal data and + * allocate any resources required by the interface. + * + * The members of @iface_data are guaranteed to have been filled with + * zeros before this function is called. + */ +typedef void (*GInterfaceInitFunc) (gpointer g_iface, + gpointer iface_data); +/** + * GInterfaceFinalizeFunc: + * @g_iface: (type GObject.TypeInterface): The interface structure to finalize + * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure + * + * A callback function used by the type system to finalize an interface. + * This function should destroy any internal data and release any resources + * allocated by the corresponding GInterfaceInitFunc() function. + */ +typedef void (*GInterfaceFinalizeFunc) (gpointer g_iface, + gpointer iface_data); +/** + * GTypeClassCacheFunc: + * @cache_data: data that was given to the g_type_add_class_cache_func() call + * @g_class: (type GObject.TypeClass): The #GTypeClass structure which is + * unreferenced + * + * A callback function which is called when the reference count of a class + * drops to zero. It may use g_type_class_ref() to prevent the class from + * being freed. You should not call g_type_class_unref() from a + * #GTypeClassCacheFunc function to prevent infinite recursion, use + * g_type_class_unref_uncached() instead. + * + * The functions have to check the class id passed in to figure + * whether they actually want to cache the class of this type, since all + * classes are routed through the same #GTypeClassCacheFunc chain. + * + * Returns: %TRUE to stop further #GTypeClassCacheFuncs from being + * called, %FALSE to continue + */ +typedef gboolean (*GTypeClassCacheFunc) (gpointer cache_data, + GTypeClass *g_class); +/** + * GTypeInterfaceCheckFunc: + * @check_data: data passed to g_type_add_interface_check() + * @g_iface: (type GObject.TypeInterface): the interface that has been + * initialized + * + * A callback called after an interface vtable is initialized. + * See g_type_add_interface_check(). + * + * Since: 2.4 + */ +typedef void (*GTypeInterfaceCheckFunc) (gpointer check_data, + gpointer g_iface); +/** + * GTypeFundamentalFlags: + * @G_TYPE_FLAG_CLASSED: Indicates a classed type + * @G_TYPE_FLAG_INSTANTIATABLE: Indicates an instantiable type (implies classed) + * @G_TYPE_FLAG_DERIVABLE: Indicates a flat derivable type + * @G_TYPE_FLAG_DEEP_DERIVABLE: Indicates a deep derivable type (implies derivable) + * + * Bit masks used to check or determine specific characteristics of a + * fundamental type. + */ +typedef enum /*< skip >*/ +{ + G_TYPE_FLAG_CLASSED = (1 << 0), + G_TYPE_FLAG_INSTANTIATABLE = (1 << 1), + G_TYPE_FLAG_DERIVABLE = (1 << 2), + G_TYPE_FLAG_DEEP_DERIVABLE = (1 << 3) +} GTypeFundamentalFlags; +/** + * GTypeFlags: + * @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be + * created for an abstract type + * @G_TYPE_FLAG_VALUE_ABSTRACT: Indicates an abstract value type, i.e. a type + * that introduces a value table, but can't be used for + * g_value_init() + * + * Bit masks used to check or determine characteristics of a type. + */ +typedef enum /*< skip >*/ +{ + G_TYPE_FLAG_ABSTRACT = (1 << 4), + G_TYPE_FLAG_VALUE_ABSTRACT = (1 << 5) +} GTypeFlags; +/** + * GTypeInfo: + * @class_size: Size of the class structure (required for interface, classed and instantiatable types) + * @base_init: Location of the base initialization function (optional) + * @base_finalize: Location of the base finalization function (optional) + * @class_init: Location of the class initialization function for + * classed and instantiatable types. Location of the default vtable + * inititalization function for interface types. (optional) This function + * is used both to fill in virtual functions in the class or default vtable, + * and to do type-specific setup such as registering signals and object + * properties. + * @class_finalize: Location of the class finalization function for + * classed and instantiatable types. Location of the default vtable + * finalization function for interface types. (optional) + * @class_data: User-supplied data passed to the class init/finalize functions + * @instance_size: Size of the instance (object) structure (required for instantiatable types only) + * @n_preallocs: Prior to GLib 2.10, it specified the number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching). Since GLib 2.10, it is ignored, since instances are allocated with the [slice allocator][glib-Memory-Slices] now. + * @instance_init: Location of the instance initialization function (optional, for instantiatable types only) + * @value_table: A #GTypeValueTable function table for generic handling of GValues + * of this type (usually only useful for fundamental types) + * + * This structure is used to provide the type system with the information + * required to initialize and destruct (finalize) a type's class and + * its instances. + * + * The initialized structure is passed to the g_type_register_static() function + * (or is copied into the provided #GTypeInfo structure in the + * g_type_plugin_complete_type_info()). The type system will perform a deep + * copy of this structure, so its memory does not need to be persistent + * across invocation of g_type_register_static(). + */ +struct _GTypeInfo +{ + /* interface types, classed types, instantiated types */ + guint16 class_size; + + GBaseInitFunc base_init; + GBaseFinalizeFunc base_finalize; + + /* interface types, classed types, instantiated types */ + GClassInitFunc class_init; + GClassFinalizeFunc class_finalize; + gconstpointer class_data; + + /* instantiated types */ + guint16 instance_size; + guint16 n_preallocs; + GInstanceInitFunc instance_init; + + /* value handling */ + const GTypeValueTable *value_table; +}; +/** + * GTypeFundamentalInfo: + * @type_flags: #GTypeFundamentalFlags describing the characteristics of the fundamental type + * + * A structure that provides information to the type system which is + * used specifically for managing fundamental types. + */ +struct _GTypeFundamentalInfo +{ + GTypeFundamentalFlags type_flags; +}; +/** + * GInterfaceInfo: + * @interface_init: location of the interface initialization function + * @interface_finalize: location of the interface finalization function + * @interface_data: user-supplied data passed to the interface init/finalize functions + * + * A structure that provides information to the type system which is + * used specifically for managing interface types. + */ +struct _GInterfaceInfo +{ + GInterfaceInitFunc interface_init; + GInterfaceFinalizeFunc interface_finalize; + gpointer interface_data; +}; +/** + * GTypeValueTable: + * @value_init: Default initialize @values contents by poking values + * directly into the value->data array. The data array of + * the #GValue passed into this function was zero-filled + * with `memset()`, so no care has to be taken to free any + * old contents. E.g. for the implementation of a string + * value that may never be %NULL, the implementation might + * look like: + * |[<!-- language="C" --> + * value->data[0].v_pointer = g_strdup (""); + * ]| + * @value_free: Free any old contents that might be left in the + * data array of the passed in @value. No resources may + * remain allocated through the #GValue contents after + * this function returns. E.g. for our above string type: + * |[<!-- language="C" --> + * // only free strings without a specific flag for static storage + * if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) + * g_free (value->data[0].v_pointer); + * ]| + * @value_copy: @dest_value is a #GValue with zero-filled data section + * and @src_value is a properly setup #GValue of same or + * derived type. + * The purpose of this function is to copy the contents of + * @src_value into @dest_value in a way, that even after + * @src_value has been freed, the contents of @dest_value + * remain valid. String type example: + * |[<!-- language="C" --> + * dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer); + * ]| + * @value_peek_pointer: If the value contents fit into a pointer, such as objects + * or strings, return this pointer, so the caller can peek at + * the current contents. To extend on our above string example: + * |[<!-- language="C" --> + * return value->data[0].v_pointer; + * ]| + * @collect_format: A string format describing how to collect the contents of + * this value bit-by-bit. Each character in the format represents + * an argument to be collected, and the characters themselves indicate + * the type of the argument. Currently supported arguments are: + * - 'i' - Integers. passed as collect_values[].v_int. + * - 'l' - Longs. passed as collect_values[].v_long. + * - 'd' - Doubles. passed as collect_values[].v_double. + * - 'p' - Pointers. passed as collect_values[].v_pointer. + * It should be noted that for variable argument list construction, + * ANSI C promotes every type smaller than an integer to an int, and + * floats to doubles. So for collection of short int or char, 'i' + * needs to be used, and for collection of floats 'd'. + * @collect_value: The collect_value() function is responsible for converting the + * values collected from a variable argument list into contents + * suitable for storage in a GValue. This function should setup + * @value similar to value_init(); e.g. for a string value that + * does not allow %NULL pointers, it needs to either spew an error, + * or do an implicit conversion by storing an empty string. + * The @value passed in to this function has a zero-filled data + * array, so just like for value_init() it is guaranteed to not + * contain any old contents that might need freeing. + * @n_collect_values is exactly the string length of @collect_format, + * and @collect_values is an array of unions #GTypeCValue with + * length @n_collect_values, containing the collected values + * according to @collect_format. + * @collect_flags is an argument provided as a hint by the caller. + * It may contain the flag %G_VALUE_NOCOPY_CONTENTS indicating, + * that the collected value contents may be considered "static" + * for the duration of the @value lifetime. + * Thus an extra copy of the contents stored in @collect_values is + * not required for assignment to @value. + * For our above string example, we continue with: + * |[<!-- language="C" --> + * if (!collect_values[0].v_pointer) + * value->data[0].v_pointer = g_strdup (""); + * else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) + * { + * value->data[0].v_pointer = collect_values[0].v_pointer; + * // keep a flag for the value_free() implementation to not free this string + * value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS; + * } + * else + * value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer); + * return NULL; + * ]| + * It should be noted, that it is generally a bad idea to follow the + * #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to + * reentrancy requirements and reference count assertions performed + * by the signal emission code, reference counts should always be + * incremented for reference counted contents stored in the value->data + * array. To deviate from our string example for a moment, and taking + * a look at an exemplary implementation for collect_value() of + * #GObject: + * |[<!-- language="C" --> + * if (collect_values[0].v_pointer) + * { + * GObject *object = G_OBJECT (collect_values[0].v_pointer); + * // never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types + * value->data[0].v_pointer = g_object_ref (object); + * return NULL; + * } + * else + * return g_strdup_printf ("Object passed as invalid NULL pointer"); + * } + * ]| + * The reference count for valid objects is always incremented, + * regardless of @collect_flags. For invalid objects, the example + * returns a newly allocated string without altering @value. + * Upon success, collect_value() needs to return %NULL. If, however, + * an error condition occurred, collect_value() may spew an + * error by returning a newly allocated non-%NULL string, giving + * a suitable description of the error condition. + * The calling code makes no assumptions about the @value + * contents being valid upon error returns, @value + * is simply thrown away without further freeing. As such, it is + * a good idea to not allocate #GValue contents, prior to returning + * an error, however, collect_values() is not obliged to return + * a correctly setup @value for error returns, simply because + * any non-%NULL return is considered a fatal condition so further + * program behaviour is undefined. + * @lcopy_format: Format description of the arguments to collect for @lcopy_value, + * analogous to @collect_format. Usually, @lcopy_format string consists + * only of 'p's to provide lcopy_value() with pointers to storage locations. + * @lcopy_value: This function is responsible for storing the @value contents into + * arguments passed through a variable argument list which got + * collected into @collect_values according to @lcopy_format. + * @n_collect_values equals the string length of @lcopy_format, + * and @collect_flags may contain %G_VALUE_NOCOPY_CONTENTS. + * In contrast to collect_value(), lcopy_value() is obliged to + * always properly support %G_VALUE_NOCOPY_CONTENTS. + * Similar to collect_value() the function may prematurely abort + * by returning a newly allocated string describing an error condition. + * To complete the string example: + * |[<!-- language="C" --> + * gchar **string_p = collect_values[0].v_pointer; + * if (!string_p) + * return g_strdup_printf ("string location passed as NULL"); + * if (collect_flags & G_VALUE_NOCOPY_CONTENTS) + * *string_p = value->data[0].v_pointer; + * else + * *string_p = g_strdup (value->data[0].v_pointer); + * ]| + * And an illustrative version of lcopy_value() for + * reference-counted types: + * |[<!-- language="C" --> + * GObject **object_p = collect_values[0].v_pointer; + * if (!object_p) + * return g_strdup_printf ("object location passed as NULL"); + * if (!value->data[0].v_pointer) + * *object_p = NULL; + * else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) // always honour + * *object_p = value->data[0].v_pointer; + * else + * *object_p = g_object_ref (value->data[0].v_pointer); + * return NULL; + * ]| + * + * The #GTypeValueTable provides the functions required by the #GValue + * implementation, to serve as a container for values of a type. + */ + +struct _GTypeValueTable +{ + void (*value_init) (GValue *value); + void (*value_free) (GValue *value); + void (*value_copy) (const GValue *src_value, + GValue *dest_value); + /* varargs functionality (optional) */ + gpointer (*value_peek_pointer) (const GValue *value); + const gchar *collect_format; + gchar* (*collect_value) (GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags); + const gchar *lcopy_format; + gchar* (*lcopy_value) (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags); +}; +GLIB_AVAILABLE_IN_ALL +GType g_type_register_static (GType parent_type, + const gchar *type_name, + const GTypeInfo *info, + GTypeFlags flags); +GLIB_AVAILABLE_IN_ALL +GType g_type_register_static_simple (GType parent_type, + const gchar *type_name, + guint class_size, + GClassInitFunc class_init, + guint instance_size, + GInstanceInitFunc instance_init, + GTypeFlags flags); + +GLIB_AVAILABLE_IN_ALL +GType g_type_register_dynamic (GType parent_type, + const gchar *type_name, + GTypePlugin *plugin, + GTypeFlags flags); +GLIB_AVAILABLE_IN_ALL +GType g_type_register_fundamental (GType type_id, + const gchar *type_name, + const GTypeInfo *info, + const GTypeFundamentalInfo *finfo, + GTypeFlags flags); +GLIB_AVAILABLE_IN_ALL +void g_type_add_interface_static (GType instance_type, + GType interface_type, + const GInterfaceInfo *info); +GLIB_AVAILABLE_IN_ALL +void g_type_add_interface_dynamic (GType instance_type, + GType interface_type, + GTypePlugin *plugin); +GLIB_AVAILABLE_IN_ALL +void g_type_interface_add_prerequisite (GType interface_type, + GType prerequisite_type); +GLIB_AVAILABLE_IN_ALL +GType*g_type_interface_prerequisites (GType interface_type, + guint *n_prerequisites); +GLIB_DEPRECATED_IN_2_58 +void g_type_class_add_private (gpointer g_class, + gsize private_size); +GLIB_AVAILABLE_IN_2_38 +gint g_type_add_instance_private (GType class_type, + gsize private_size); +GLIB_AVAILABLE_IN_ALL +gpointer g_type_instance_get_private (GTypeInstance *instance, + GType private_type); +GLIB_AVAILABLE_IN_2_38 +void g_type_class_adjust_private_offset (gpointer g_class, + gint *private_size_or_offset); + +GLIB_AVAILABLE_IN_ALL +void g_type_add_class_private (GType class_type, + gsize private_size); +GLIB_AVAILABLE_IN_ALL +gpointer g_type_class_get_private (GTypeClass *klass, + GType private_type); +GLIB_AVAILABLE_IN_2_38 +gint g_type_class_get_instance_private_offset (gpointer g_class); + +GLIB_AVAILABLE_IN_2_34 +void g_type_ensure (GType type); +GLIB_AVAILABLE_IN_2_36 +guint g_type_get_type_registration_serial (void); + + +/* --- GType boilerplate --- */ +/** + * G_DECLARE_FINAL_TYPE: + * @ModuleObjName: The name of the new type, in camel case (like GtkWidget) + * @module_obj_name: The name of the new type in lowercase, with words + * separated by '_' (like 'gtk_widget') + * @MODULE: The name of the module, in all caps (like 'GTK') + * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET') + * @ParentName: the name of the parent type, in camel case (like GtkWidget) + * + * A convenience macro for emitting the usual declarations in the header file for a type which is not (at the + * present time) intended to be subclassed. + * + * You might use it in a header as follows: + * + * |[ + * #ifndef _myapp_window_h_ + * #define _myapp_window_h_ + * + * #include <gtk/gtk.h> + * + * #define MY_APP_TYPE_WINDOW my_app_window_get_type () + * G_DECLARE_FINAL_TYPE (MyAppWindow, my_app_window, MY_APP, WINDOW, GtkWindow) + * + * MyAppWindow * my_app_window_new (void); + * + * ... + * + * #endif + * ]| + * + * This results in the following things happening: + * + * - the usual my_app_window_get_type() function is declared with a return type of #GType + * + * - the MyAppWindow types is defined as a typedef of struct _MyAppWindow. The struct itself is not + * defined and should be defined from the .c file before G_DEFINE_TYPE() is used. + * + * - the MY_APP_WINDOW() cast is emitted as static inline function along with the MY_APP_IS_WINDOW() type + * checking function + * + * - the MyAppWindowClass type is defined as a struct containing GtkWindowClass. This is done for the + * convenience of the person defining the type and should not be considered to be part of the ABI. In + * particular, without a firm declaration of the instance structure, it is not possible to subclass the type + * and therefore the fact that the size of the class structure is exposed is not a concern and it can be + * freely changed at any point in the future. + * + * - g_autoptr() support being added for your type, based on the type of your parent class + * + * You can only use this function if your parent type also supports g_autoptr(). + * + * Because the type macro (MY_APP_TYPE_WINDOW in the above example) is not a callable, you must continue to + * manually define this as a macro for yourself. + * + * The declaration of the _get_type() function is the first thing emitted by the macro. This allows this macro + * to be used in the usual way with export control and API versioning macros. + * + * If you want to declare your own class structure, use G_DECLARE_DERIVABLE_TYPE(). + * + * If you are writing a library, it is important to note that it is possible to convert a type from using + * G_DECLARE_FINAL_TYPE() to G_DECLARE_DERIVABLE_TYPE() without breaking API or ABI. As a precaution, you + * should therefore use G_DECLARE_FINAL_TYPE() until you are sure that it makes sense for your class to be + * subclassed. Once a class structure has been exposed it is not possible to change its size or remove or + * reorder items without breaking the API and/or ABI. + * + * Since: 2.44 + **/ +#define G_DECLARE_FINAL_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName) \ + GType module_obj_name##_get_type (void); \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + typedef struct _##ModuleObjName ModuleObjName; \ + typedef struct { ParentName##Class parent_class; } ModuleObjName##Class; \ + \ + _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \ + \ + static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \ + static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); } \ + G_GNUC_END_IGNORE_DEPRECATIONS + +/** + * G_DECLARE_DERIVABLE_TYPE: + * @ModuleObjName: The name of the new type, in camel case (like GtkWidget) + * @module_obj_name: The name of the new type in lowercase, with words + * separated by '_' (like 'gtk_widget') + * @MODULE: The name of the module, in all caps (like 'GTK') + * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET') + * @ParentName: the name of the parent type, in camel case (like GtkWidget) + * + * A convenience macro for emitting the usual declarations in the + * header file for a type which is intended to be subclassed. + * + * You might use it in a header as follows: + * + * |[ + * #ifndef _gtk_frobber_h_ + * #define _gtk_frobber_h_ + * + * #define GTK_TYPE_FROBBER gtk_frobber_get_type () + * GDK_AVAILABLE_IN_3_12 + * G_DECLARE_DERIVABLE_TYPE (GtkFrobber, gtk_frobber, GTK, FROBBER, GtkWidget) + * + * struct _GtkFrobberClass + * { + * GtkWidgetClass parent_class; + * + * void (* handle_frob) (GtkFrobber *frobber, + * guint n_frobs); + * + * gpointer padding[12]; + * }; + * + * GtkWidget * gtk_frobber_new (void); + * + * ... + * + * #endif + * ]| + * + * This results in the following things happening: + * + * - the usual gtk_frobber_get_type() function is declared with a return type of #GType + * + * - the GtkFrobber struct is created with GtkWidget as the first and only item. You are expected to use + * a private structure from your .c file to store your instance variables. + * + * - the GtkFrobberClass type is defined as a typedef to struct _GtkFrobberClass, which is left undefined. + * You should do this from the header file directly after you use the macro. + * + * - the GTK_FROBBER() and GTK_FROBBER_CLASS() casts are emitted as static inline functions along with + * the GTK_IS_FROBBER() and GTK_IS_FROBBER_CLASS() type checking functions and GTK_FROBBER_GET_CLASS() + * function. + * + * - g_autoptr() support being added for your type, based on the type of your parent class + * + * You can only use this function if your parent type also supports g_autoptr(). + * + * Because the type macro (GTK_TYPE_FROBBER in the above example) is not a callable, you must continue to + * manually define this as a macro for yourself. + * + * The declaration of the _get_type() function is the first thing emitted by the macro. This allows this macro + * to be used in the usual way with export control and API versioning macros. + * + * If you are writing a library, it is important to note that it is possible to convert a type from using + * G_DECLARE_FINAL_TYPE() to G_DECLARE_DERIVABLE_TYPE() without breaking API or ABI. As a precaution, you + * should therefore use G_DECLARE_FINAL_TYPE() until you are sure that it makes sense for your class to be + * subclassed. Once a class structure has been exposed it is not possible to change its size or remove or + * reorder items without breaking the API and/or ABI. If you want to declare your own class structure, use + * G_DECLARE_DERIVABLE_TYPE(). If you want to declare a class without exposing the class or instance + * structures, use G_DECLARE_FINAL_TYPE(). + * + * If you must use G_DECLARE_DERIVABLE_TYPE() you should be sure to include some padding at the bottom of your + * class structure to leave space for the addition of future virtual functions. + * + * Since: 2.44 + **/ +#define G_DECLARE_DERIVABLE_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName) \ + GType module_obj_name##_get_type (void); \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + typedef struct _##ModuleObjName ModuleObjName; \ + typedef struct _##ModuleObjName##Class ModuleObjName##Class; \ + struct _##ModuleObjName { ParentName parent_instance; }; \ + \ + _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \ + \ + static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \ + static inline ModuleObjName##Class * MODULE##_##OBJ_NAME##_CLASS (gpointer ptr) { \ + return G_TYPE_CHECK_CLASS_CAST (ptr, module_obj_name##_get_type (), ModuleObjName##Class); } \ + static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); } \ + static inline gboolean MODULE##_IS_##OBJ_NAME##_CLASS (gpointer ptr) { \ + return G_TYPE_CHECK_CLASS_TYPE (ptr, module_obj_name##_get_type ()); } \ + static inline ModuleObjName##Class * MODULE##_##OBJ_NAME##_GET_CLASS (gpointer ptr) { \ + return G_TYPE_INSTANCE_GET_CLASS (ptr, module_obj_name##_get_type (), ModuleObjName##Class); } \ + G_GNUC_END_IGNORE_DEPRECATIONS + +/** + * G_DECLARE_INTERFACE: + * @ModuleObjName: The name of the new type, in camel case (like GtkWidget) + * @module_obj_name: The name of the new type in lowercase, with words + * separated by '_' (like 'gtk_widget') + * @MODULE: The name of the module, in all caps (like 'GTK') + * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET') + * @PrerequisiteName: the name of the prerequisite type, in camel case (like GtkWidget) + * + * A convenience macro for emitting the usual declarations in the header file for a GInterface type. + * + * You might use it in a header as follows: + * + * |[ + * #ifndef _my_model_h_ + * #define _my_model_h_ + * + * #define MY_TYPE_MODEL my_model_get_type () + * GDK_AVAILABLE_IN_3_12 + * G_DECLARE_INTERFACE (MyModel, my_model, MY, MODEL, GObject) + * + * struct _MyModelInterface + * { + * GTypeInterface g_iface; + * + * gpointer (* get_item) (MyModel *model); + * }; + * + * gpointer my_model_get_item (MyModel *model); + * + * ... + * + * #endif + * ]| + * + * This results in the following things happening: + * + * - the usual my_model_get_type() function is declared with a return type of #GType + * + * - the MyModelInterface type is defined as a typedef to struct _MyModelInterface, + * which is left undefined. You should do this from the header file directly after + * you use the macro. + * + * - the MY_MODEL() cast is emitted as static inline functions along with + * the MY_IS_MODEL() type checking function and MY_MODEL_GET_IFACE() function. + * + * - g_autoptr() support being added for your type, based on your prerequisite type. + * + * You can only use this function if your prerequisite type also supports g_autoptr(). + * + * Because the type macro (MY_TYPE_MODEL in the above example) is not a callable, you must continue to + * manually define this as a macro for yourself. + * + * The declaration of the _get_type() function is the first thing emitted by the macro. This allows this macro + * to be used in the usual way with export control and API versioning macros. + * + * Since: 2.44 + **/ +#define G_DECLARE_INTERFACE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, PrerequisiteName) \ + GType module_obj_name##_get_type (void); \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + typedef struct _##ModuleObjName ModuleObjName; \ + typedef struct _##ModuleObjName##Interface ModuleObjName##Interface; \ + \ + _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, PrerequisiteName) \ + \ + static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \ + static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); } \ + static inline ModuleObjName##Interface * MODULE##_##OBJ_NAME##_GET_IFACE (gpointer ptr) { \ + return G_TYPE_INSTANCE_GET_INTERFACE (ptr, module_obj_name##_get_type (), ModuleObjName##Interface); } \ + G_GNUC_END_IGNORE_DEPRECATIONS + +/** + * G_DEFINE_TYPE: + * @TN: The name of the new type, in Camel case. + * @t_n: The name of the new type, in lowercase, with words + * separated by '_'. + * @T_P: The #GType of the parent type. + * + * A convenience macro for type implementations, which declares a class + * initialization function, an instance initialization function (see #GTypeInfo + * for information about these) and a static variable named `t_n_parent_class` + * pointing to the parent class. Furthermore, it defines a *_get_type() function. + * See G_DEFINE_TYPE_EXTENDED() for an example. + * + * Since: 2.4 + */ +#define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {}) +/** + * G_DEFINE_TYPE_WITH_CODE: + * @TN: The name of the new type, in Camel case. + * @t_n: The name of the new type in lowercase, with words separated by '_'. + * @T_P: The #GType of the parent type. + * @_C_: Custom code that gets inserted in the *_get_type() function. + * + * A convenience macro for type implementations. + * Similar to G_DEFINE_TYPE(), but allows you to insert custom code into the + * *_get_type() function, e.g. interface implementations via G_IMPLEMENT_INTERFACE(). + * See G_DEFINE_TYPE_EXTENDED() for an example. + * + * Since: 2.4 + */ +#define G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) {_C_;} _G_DEFINE_TYPE_EXTENDED_END() +/** + * G_DEFINE_TYPE_WITH_PRIVATE: + * @TN: The name of the new type, in Camel case. + * @t_n: The name of the new type, in lowercase, with words + * separated by '_'. + * @T_P: The #GType of the parent type. + * + * A convenience macro for type implementations, which declares a class + * initialization function, an instance initialization function (see #GTypeInfo + * for information about these), a static variable named `t_n_parent_class` + * pointing to the parent class, and adds private instance data to the type. + * Furthermore, it defines a *_get_type() function. See G_DEFINE_TYPE_EXTENDED() + * for an example. + * + * Note that private structs added with this macros must have a struct + * name of the form @TN Private. + * + * The private instance data can be retrieved using the automatically generated + * getter function `t_n_get_instance_private()`. + * + * See also: G_ADD_PRIVATE() + * + * Since: 2.38 + */ +#define G_DEFINE_TYPE_WITH_PRIVATE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, G_ADD_PRIVATE (TN)) +/** + * G_DEFINE_ABSTRACT_TYPE: + * @TN: The name of the new type, in Camel case. + * @t_n: The name of the new type, in lowercase, with words + * separated by '_'. + * @T_P: The #GType of the parent type. + * + * A convenience macro for type implementations. + * Similar to G_DEFINE_TYPE(), but defines an abstract type. + * See G_DEFINE_TYPE_EXTENDED() for an example. + * + * Since: 2.4 + */ +#define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {}) +/** + * G_DEFINE_ABSTRACT_TYPE_WITH_CODE: + * @TN: The name of the new type, in Camel case. + * @t_n: The name of the new type, in lowercase, with words + * separated by '_'. + * @T_P: The #GType of the parent type. + * @_C_: Custom code that gets inserted in the @type_name_get_type() function. + * + * A convenience macro for type implementations. + * Similar to G_DEFINE_TYPE_WITH_CODE(), but defines an abstract type and + * allows you to insert custom code into the *_get_type() function, e.g. + * interface implementations via G_IMPLEMENT_INTERFACE(). + * See G_DEFINE_TYPE_EXTENDED() for an example. + * + * Since: 2.4 + */ +#define G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT) {_C_;} _G_DEFINE_TYPE_EXTENDED_END() +/** + * G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE: + * @TN: The name of the new type, in Camel case. + * @t_n: The name of the new type, in lowercase, with words + * separated by '_'. + * @T_P: The #GType of the parent type. + * + * Similar to G_DEFINE_TYPE_WITH_PRIVATE(), but defines an abstract type. + * See G_DEFINE_TYPE_EXTENDED() for an example. + * + * Since: 2.38 + */ +#define G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, G_ADD_PRIVATE (TN)) +/** + * G_DEFINE_TYPE_EXTENDED: + * @TN: The name of the new type, in Camel case. + * @t_n: The name of the new type, in lowercase, with words + * separated by '_'. + * @T_P: The #GType of the parent type. + * @_f_: #GTypeFlags to pass to g_type_register_static() + * @_C_: Custom code that gets inserted in the *_get_type() function. + * + * The most general convenience macro for type implementations, on which + * G_DEFINE_TYPE(), etc are based. + * + * |[<!-- language="C" --> + * G_DEFINE_TYPE_EXTENDED (GtkGadget, + * gtk_gadget, + * GTK_TYPE_WIDGET, + * 0, + * G_ADD_PRIVATE (GtkGadget) + * G_IMPLEMENT_INTERFACE (TYPE_GIZMO, + * gtk_gadget_gizmo_init)); + * ]| + * expands to + * |[<!-- language="C" --> + * static void gtk_gadget_init (GtkGadget *self); + * static void gtk_gadget_class_init (GtkGadgetClass *klass); + * static gpointer gtk_gadget_parent_class = NULL; + * static gint GtkGadget_private_offset; + * static void gtk_gadget_class_intern_init (gpointer klass) + * { + * gtk_gadget_parent_class = g_type_class_peek_parent (klass); + * if (GtkGadget_private_offset != 0) + * g_type_class_adjust_private_offset (klass, &GtkGadget_private_offset); + * gtk_gadget_class_init ((GtkGadgetClass*) klass); + * } + * static inline gpointer gtk_gadget_get_instance_private (GtkGadget *self) + * { + * return (G_STRUCT_MEMBER_P (self, GtkGadget_private_offset)); + * } + * + * GType + * gtk_gadget_get_type (void) + * { + * static volatile gsize g_define_type_id__volatile = 0; + * if (g_once_init_enter (&g_define_type_id__volatile)) + * { + * GType g_define_type_id = + * g_type_register_static_simple (GTK_TYPE_WIDGET, + * g_intern_static_string ("GtkGadget"), + * sizeof (GtkGadgetClass), + * (GClassInitFunc) gtk_gadget_class_intern_init, + * sizeof (GtkGadget), + * (GInstanceInitFunc) gtk_gadget_init, + * 0); + * { + * GtkGadget_private_offset = + * g_type_add_instance_private (g_define_type_id, sizeof (GtkGadgetPrivate)); + * } + * { + * const GInterfaceInfo g_implement_interface_info = { + * (GInterfaceInitFunc) gtk_gadget_gizmo_init + * }; + * g_type_add_interface_static (g_define_type_id, TYPE_GIZMO, &g_implement_interface_info); + * } + * g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + * } + * return g_define_type_id__volatile; + * } + * ]| + * The only pieces which have to be manually provided are the definitions of + * the instance and class structure and the definitions of the instance and + * class init functions. + * + * Since: 2.4 + */ +#define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) {_C_;} _G_DEFINE_TYPE_EXTENDED_END() + +/** + * G_DEFINE_INTERFACE: + * @TN: The name of the new type, in Camel case. + * @t_n: The name of the new type, in lowercase, with words separated by '_'. + * @T_P: The #GType of the prerequisite type for the interface, or 0 + * (%G_TYPE_INVALID) for no prerequisite type. + * + * A convenience macro for #GTypeInterface definitions, which declares + * a default vtable initialization function and defines a *_get_type() + * function. + * + * The macro expects the interface initialization function to have the + * name `t_n ## _default_init`, and the interface structure to have the + * name `TN ## Interface`. + * + * The initialization function has signature + * `static void t_n ## _default_init (TypeName##Interface *klass);`, rather than + * the full #GInterfaceInitFunc signature, for brevity and convenience. If you + * need to use an initialization function with an `iface_data` argument, you + * must write the #GTypeInterface definitions manually. + * + * Since: 2.24 + */ +#define G_DEFINE_INTERFACE(TN, t_n, T_P) G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, ;) + +/** + * G_DEFINE_INTERFACE_WITH_CODE: + * @TN: The name of the new type, in Camel case. + * @t_n: The name of the new type, in lowercase, with words separated by '_'. + * @T_P: The #GType of the prerequisite type for the interface, or 0 + * (%G_TYPE_INVALID) for no prerequisite type. + * @_C_: Custom code that gets inserted in the *_get_type() function. + * + * A convenience macro for #GTypeInterface definitions. Similar to + * G_DEFINE_INTERFACE(), but allows you to insert custom code into the + * *_get_type() function, e.g. additional interface implementations + * via G_IMPLEMENT_INTERFACE(), or additional prerequisite types. See + * G_DEFINE_TYPE_EXTENDED() for a similar example using + * G_DEFINE_TYPE_WITH_CODE(). + * + * Since: 2.24 + */ +#define G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TN, t_n, T_P) {_C_;} _G_DEFINE_INTERFACE_EXTENDED_END() + +/** + * G_IMPLEMENT_INTERFACE: + * @TYPE_IFACE: The #GType of the interface to add + * @iface_init: (type GInterfaceInitFunc): The interface init function, of type #GInterfaceInitFunc + * + * A convenience macro to ease interface addition in the `_C_` section + * of G_DEFINE_TYPE_WITH_CODE() or G_DEFINE_ABSTRACT_TYPE_WITH_CODE(). + * See G_DEFINE_TYPE_EXTENDED() for an example. + * + * Note that this macro can only be used together with the G_DEFINE_TYPE_* + * macros, since it depends on variable names from those macros. + * + * Since: 2.4 + */ +#define G_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \ + const GInterfaceInfo g_implement_interface_info = { \ + (GInterfaceInitFunc)(void (*)(void)) iface_init, NULL, NULL \ + }; \ + g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \ +} + +/** + * G_ADD_PRIVATE: + * @TypeName: the name of the type in CamelCase + * + * A convenience macro to ease adding private data to instances of a new type + * in the @_C_ section of G_DEFINE_TYPE_WITH_CODE() or + * G_DEFINE_ABSTRACT_TYPE_WITH_CODE(). + * + * For instance: + * + * |[<!-- language="C" --> + * typedef struct _MyObject MyObject; + * typedef struct _MyObjectClass MyObjectClass; + * + * typedef struct { + * gint foo; + * gint bar; + * } MyObjectPrivate; + * + * G_DEFINE_TYPE_WITH_CODE (MyObject, my_object, G_TYPE_OBJECT, + * G_ADD_PRIVATE (MyObject)) + * ]| + * + * Will add MyObjectPrivate as the private data to any instance of the MyObject + * type. + * + * G_DEFINE_TYPE_* macros will automatically create a private function + * based on the arguments to this macro, which can be used to safely + * retrieve the private data from an instance of the type; for instance: + * + * |[<!-- language="C" --> + * gint + * my_object_get_foo (MyObject *obj) + * { + * MyObjectPrivate *priv = my_object_get_instance_private (obj); + * + * g_return_val_if_fail (MY_IS_OBJECT (obj), 0); + * + * return priv->foo; + * } + * + * void + * my_object_set_bar (MyObject *obj, + * gint bar) + * { + * MyObjectPrivate *priv = my_object_get_instance_private (obj); + * + * g_return_if_fail (MY_IS_OBJECT (obj)); + * + * if (priv->bar != bar) + * priv->bar = bar; + * } + * ]| + * + * Note that this macro can only be used together with the G_DEFINE_TYPE_* + * macros, since it depends on variable names from those macros. + * + * Also note that private structs added with these macros must have a struct + * name of the form `TypeNamePrivate`. + * + * It is safe to call the `_get_instance_private` function on %NULL or invalid + * objects since it's only adding an offset to the instance pointer. In that + * case the returned pointer must not be dereferenced. + * + * Since: 2.38 + */ +#define G_ADD_PRIVATE(TypeName) { \ + TypeName##_private_offset = \ + g_type_add_instance_private (g_define_type_id, sizeof (TypeName##Private)); \ +} + +/** + * G_PRIVATE_OFFSET: + * @TypeName: the name of the type in CamelCase + * @field: the name of the field in the private data structure + * + * Evaluates to the offset of the @field inside the instance private data + * structure for @TypeName. + * + * Note that this macro can only be used together with the G_DEFINE_TYPE_* + * and G_ADD_PRIVATE() macros, since it depends on variable names from + * those macros. + * + * Since: 2.38 + */ +#define G_PRIVATE_OFFSET(TypeName, field) \ + (TypeName##_private_offset + (G_STRUCT_OFFSET (TypeName##Private, field))) + +/** + * G_PRIVATE_FIELD_P: + * @TypeName: the name of the type in CamelCase + * @inst: the instance of @TypeName you wish to access + * @field_name: the name of the field in the private data structure + * + * Evaluates to a pointer to the @field_name inside the @inst private data + * structure for @TypeName. + * + * Note that this macro can only be used together with the G_DEFINE_TYPE_* + * and G_ADD_PRIVATE() macros, since it depends on variable names from + * those macros. + * + * Since: 2.38 + */ +#define G_PRIVATE_FIELD_P(TypeName, inst, field_name) \ + G_STRUCT_MEMBER_P (inst, G_PRIVATE_OFFSET (TypeName, field_name)) + +/** + * G_PRIVATE_FIELD: + * @TypeName: the name of the type in CamelCase + * @inst: the instance of @TypeName you wish to access + * @field_type: the type of the field in the private data structure + * @field_name: the name of the field in the private data structure + * + * Evaluates to the @field_name inside the @inst private data + * structure for @TypeName. + * + * Note that this macro can only be used together with the G_DEFINE_TYPE_* + * and G_ADD_PRIVATE() macros, since it depends on variable names from + * those macros. + * + * Since: 2.38 + */ +#define G_PRIVATE_FIELD(TypeName, inst, field_type, field_name) \ + G_STRUCT_MEMBER (field_type, inst, G_PRIVATE_OFFSET (TypeName, field_name)) + +/* we need to have this macro under conditional expansion, as it references + * a function that has been added in 2.38. see bug: + * https://bugzilla.gnome.org/show_bug.cgi?id=703191 + */ +#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 +#define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \ +static void type_name##_class_intern_init (gpointer klass) \ +{ \ + type_name##_parent_class = g_type_class_peek_parent (klass); \ + if (TypeName##_private_offset != 0) \ + g_type_class_adjust_private_offset (klass, &TypeName##_private_offset); \ + type_name##_class_init ((TypeName##Class*) klass); \ +} + +#else +#define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \ +static void type_name##_class_intern_init (gpointer klass) \ +{ \ + type_name##_parent_class = g_type_class_peek_parent (klass); \ + type_name##_class_init ((TypeName##Class*) klass); \ +} +#endif /* GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 */ + +/* Added for _G_DEFINE_TYPE_EXTENDED_WITH_PRELUDE */ +#define _G_DEFINE_TYPE_EXTENDED_BEGIN_PRE(TypeName, type_name, TYPE_PARENT) \ +\ +static void type_name##_init (TypeName *self); \ +static void type_name##_class_init (TypeName##Class *klass); \ +static GType type_name##_get_type_once (void); \ +static gpointer type_name##_parent_class = NULL; \ +static gint TypeName##_private_offset; \ +\ +_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \ +\ +G_GNUC_UNUSED \ +static inline gpointer \ +type_name##_get_instance_private (TypeName *self) \ +{ \ + return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \ +} \ +\ +GType \ +type_name##_get_type (void) \ +{ \ + static volatile gsize g_define_type_id__volatile = 0; + /* Prelude goes here */ + +/* Added for _G_DEFINE_TYPE_EXTENDED_WITH_PRELUDE */ +#define _G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER(TypeName, type_name, TYPE_PARENT, flags) \ + if (g_once_init_enter (&g_define_type_id__volatile)) \ + { \ + GType g_define_type_id = type_name##_get_type_once (); \ + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \ + } \ + return g_define_type_id__volatile; \ +} /* closes type_name##_get_type() */ \ +\ +G_GNUC_NO_INLINE \ +static GType \ +type_name##_get_type_once (void) \ +{ \ + GType g_define_type_id = \ + g_type_register_static_simple (TYPE_PARENT, \ + g_intern_static_string (#TypeName), \ + sizeof (TypeName##Class), \ + (GClassInitFunc)(void (*)(void)) type_name##_class_intern_init, \ + sizeof (TypeName), \ + (GInstanceInitFunc)(void (*)(void)) type_name##_init, \ + (GTypeFlags) flags); \ + { /* custom code follows */ +#define _G_DEFINE_TYPE_EXTENDED_END() \ + /* following custom code */ \ + } \ + return g_define_type_id; \ +} /* closes type_name##_get_type_once() */ + +/* This was defined before we had G_DEFINE_TYPE_WITH_CODE_AND_PRELUDE, it's simplest + * to keep it. + */ +#define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \ + _G_DEFINE_TYPE_EXTENDED_BEGIN_PRE(TypeName, type_name, TYPE_PARENT) \ + _G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER(TypeName, type_name, TYPE_PARENT, flags) \ + +#define _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PREREQ) \ +\ +static void type_name##_default_init (TypeName##Interface *klass); \ +\ +GType \ +type_name##_get_type (void) \ +{ \ + static volatile gsize g_define_type_id__volatile = 0; \ + if (g_once_init_enter (&g_define_type_id__volatile)) \ + { \ + GType g_define_type_id = \ + g_type_register_static_simple (G_TYPE_INTERFACE, \ + g_intern_static_string (#TypeName), \ + sizeof (TypeName##Interface), \ + (GClassInitFunc)(void (*)(void)) type_name##_default_init, \ + 0, \ + (GInstanceInitFunc)NULL, \ + (GTypeFlags) 0); \ + if (TYPE_PREREQ != G_TYPE_INVALID) \ + g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \ + { /* custom code follows */ +#define _G_DEFINE_INTERFACE_EXTENDED_END() \ + /* following custom code */ \ + } \ + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \ + } \ + return g_define_type_id__volatile; \ +} /* closes type_name##_get_type() */ + +/** + * G_DEFINE_BOXED_TYPE: + * @TypeName: The name of the new type, in Camel case + * @type_name: The name of the new type, in lowercase, with words + * separated by '_' + * @copy_func: the #GBoxedCopyFunc for the new type + * @free_func: the #GBoxedFreeFunc for the new type + * + * A convenience macro for boxed type implementations, which defines a + * type_name_get_type() function registering the boxed type. + * + * Since: 2.26 + */ +#define G_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) G_DEFINE_BOXED_TYPE_WITH_CODE (TypeName, type_name, copy_func, free_func, {}) +/** + * G_DEFINE_BOXED_TYPE_WITH_CODE: + * @TypeName: The name of the new type, in Camel case + * @type_name: The name of the new type, in lowercase, with words + * separated by '_' + * @copy_func: the #GBoxedCopyFunc for the new type + * @free_func: the #GBoxedFreeFunc for the new type + * @_C_: Custom code that gets inserted in the *_get_type() function + * + * A convenience macro for boxed type implementations. + * Similar to G_DEFINE_BOXED_TYPE(), but allows to insert custom code into the + * type_name_get_type() function, e.g. to register value transformations with + * g_value_register_transform_func(), for instance: + * + * |[<!-- language="C" --> + * G_DEFINE_BOXED_TYPE_WITH_CODE (GdkRectangle, gdk_rectangle, + * gdk_rectangle_copy, + * gdk_rectangle_free, + * register_rectangle_transform_funcs (g_define_type_id)) + * ]| + * + * Similarly to the %G_DEFINE_TYPE family of macros, the #GType of the newly + * defined boxed type is exposed in the `g_define_type_id` variable. + * + * Since: 2.26 + */ +#define G_DEFINE_BOXED_TYPE_WITH_CODE(TypeName, type_name, copy_func, free_func, _C_) _G_DEFINE_BOXED_TYPE_BEGIN (TypeName, type_name, copy_func, free_func) {_C_;} _G_DEFINE_TYPE_EXTENDED_END() + +/* Only use this in non-C++ on GCC >= 2.7, except for Darwin/ppc64. + * See https://bugzilla.gnome.org/show_bug.cgi?id=647145 + */ +#if !defined (__cplusplus) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !(defined (__APPLE__) && defined (__ppc64__)) +#define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \ +static GType type_name##_get_type_once (void); \ +\ +GType \ +type_name##_get_type (void) \ +{ \ + static volatile gsize g_define_type_id__volatile = 0; \ + if (g_once_init_enter (&g_define_type_id__volatile)) \ + { \ + GType g_define_type_id = type_name##_get_type_once (); \ + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \ + } \ + return g_define_type_id__volatile; \ +} \ +\ +G_GNUC_NO_INLINE \ +static GType \ +type_name##_get_type_once (void) \ +{ \ + GType (* _g_register_boxed) \ + (const gchar *, \ + union \ + { \ + TypeName * (*do_copy_type) (TypeName *); \ + TypeName * (*do_const_copy_type) (const TypeName *); \ + GBoxedCopyFunc do_copy_boxed; \ + } __attribute__((__transparent_union__)), \ + union \ + { \ + void (* do_free_type) (TypeName *); \ + GBoxedFreeFunc do_free_boxed; \ + } __attribute__((__transparent_union__)) \ + ) = g_boxed_type_register_static; \ + GType g_define_type_id = \ + _g_register_boxed (g_intern_static_string (#TypeName), copy_func, free_func); \ + { /* custom code follows */ +#else +#define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \ +static GType type_name##_get_type_once (void); \ +\ +GType \ +type_name##_get_type (void) \ +{ \ + static volatile gsize g_define_type_id__volatile = 0; \ + if (g_once_init_enter (&g_define_type_id__volatile)) \ + { \ + GType g_define_type_id = type_name##_get_type_once (); \ + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \ + } \ + return g_define_type_id__volatile; \ +} \ +\ +G_GNUC_NO_INLINE \ +static GType \ +type_name##_get_type_once (void) \ +{ \ + GType g_define_type_id = \ + g_boxed_type_register_static (g_intern_static_string (#TypeName), \ + (GBoxedCopyFunc) copy_func, \ + (GBoxedFreeFunc) free_func); \ + { /* custom code follows */ +#endif /* __GNUC__ */ + +/** + * G_DEFINE_POINTER_TYPE: + * @TypeName: The name of the new type, in Camel case + * @type_name: The name of the new type, in lowercase, with words + * separated by '_' + * + * A convenience macro for pointer type implementations, which defines a + * type_name_get_type() function registering the pointer type. + * + * Since: 2.26 + */ +#define G_DEFINE_POINTER_TYPE(TypeName, type_name) G_DEFINE_POINTER_TYPE_WITH_CODE (TypeName, type_name, {}) +/** + * G_DEFINE_POINTER_TYPE_WITH_CODE: + * @TypeName: The name of the new type, in Camel case + * @type_name: The name of the new type, in lowercase, with words + * separated by '_' + * @_C_: Custom code that gets inserted in the *_get_type() function + * + * A convenience macro for pointer type implementations. + * Similar to G_DEFINE_POINTER_TYPE(), but allows to insert + * custom code into the type_name_get_type() function. + * + * Since: 2.26 + */ +#define G_DEFINE_POINTER_TYPE_WITH_CODE(TypeName, type_name, _C_) _G_DEFINE_POINTER_TYPE_BEGIN (TypeName, type_name) {_C_;} _G_DEFINE_TYPE_EXTENDED_END() + +#define _G_DEFINE_POINTER_TYPE_BEGIN(TypeName, type_name) \ +static GType type_name##_get_type_once (void); \ +\ +GType \ +type_name##_get_type (void) \ +{ \ + static volatile gsize g_define_type_id__volatile = 0; \ + if (g_once_init_enter (&g_define_type_id__volatile)) \ + { \ + GType g_define_type_id = type_name##_get_type_once (); \ + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \ + } \ + return g_define_type_id__volatile; \ +} \ +\ +G_GNUC_NO_INLINE \ +static GType \ +type_name##_get_type_once (void) \ +{ \ + GType g_define_type_id = \ + g_pointer_type_register_static (g_intern_static_string (#TypeName)); \ + { /* custom code follows */ + +/* --- protected (for fundamental type implementations) --- */ +GLIB_AVAILABLE_IN_ALL +GTypePlugin* g_type_get_plugin (GType type); +GLIB_AVAILABLE_IN_ALL +GTypePlugin* g_type_interface_get_plugin (GType instance_type, + GType interface_type); +GLIB_AVAILABLE_IN_ALL +GType g_type_fundamental_next (void); +GLIB_AVAILABLE_IN_ALL +GType g_type_fundamental (GType type_id); +GLIB_AVAILABLE_IN_ALL +GTypeInstance* g_type_create_instance (GType type); +GLIB_AVAILABLE_IN_ALL +void g_type_free_instance (GTypeInstance *instance); + +GLIB_AVAILABLE_IN_ALL +void g_type_add_class_cache_func (gpointer cache_data, + GTypeClassCacheFunc cache_func); +GLIB_AVAILABLE_IN_ALL +void g_type_remove_class_cache_func (gpointer cache_data, + GTypeClassCacheFunc cache_func); +GLIB_AVAILABLE_IN_ALL +void g_type_class_unref_uncached (gpointer g_class); + +GLIB_AVAILABLE_IN_ALL +void g_type_add_interface_check (gpointer check_data, + GTypeInterfaceCheckFunc check_func); +GLIB_AVAILABLE_IN_ALL +void g_type_remove_interface_check (gpointer check_data, + GTypeInterfaceCheckFunc check_func); + +GLIB_AVAILABLE_IN_ALL +GTypeValueTable* g_type_value_table_peek (GType type); + + +/*< private >*/ +GLIB_AVAILABLE_IN_ALL +gboolean g_type_check_instance (GTypeInstance *instance) G_GNUC_PURE; +GLIB_AVAILABLE_IN_ALL +GTypeInstance* g_type_check_instance_cast (GTypeInstance *instance, + GType iface_type); +GLIB_AVAILABLE_IN_ALL +gboolean g_type_check_instance_is_a (GTypeInstance *instance, + GType iface_type) G_GNUC_PURE; +GLIB_AVAILABLE_IN_2_42 +gboolean g_type_check_instance_is_fundamentally_a (GTypeInstance *instance, + GType fundamental_type) G_GNUC_PURE; +GLIB_AVAILABLE_IN_ALL +GTypeClass* g_type_check_class_cast (GTypeClass *g_class, + GType is_a_type); +GLIB_AVAILABLE_IN_ALL +gboolean g_type_check_class_is_a (GTypeClass *g_class, + GType is_a_type) G_GNUC_PURE; +GLIB_AVAILABLE_IN_ALL +gboolean g_type_check_is_value_type (GType type) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +gboolean g_type_check_value (const GValue *value) G_GNUC_PURE; +GLIB_AVAILABLE_IN_ALL +gboolean g_type_check_value_holds (const GValue *value, + GType type) G_GNUC_PURE; +GLIB_AVAILABLE_IN_ALL +gboolean g_type_test_flags (GType type, + guint flags) G_GNUC_CONST; + + +/* --- debugging functions --- */ +GLIB_AVAILABLE_IN_ALL +const gchar * g_type_name_from_instance (GTypeInstance *instance); +GLIB_AVAILABLE_IN_ALL +const gchar * g_type_name_from_class (GTypeClass *g_class); + + +/* --- implementation bits --- */ +#ifndef G_DISABLE_CAST_CHECKS +# define _G_TYPE_CIC(ip, gt, ct) \ + ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt)) +# define _G_TYPE_CCC(cp, gt, ct) \ + ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt)) +#else /* G_DISABLE_CAST_CHECKS */ +# define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip) +# define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp) +#endif /* G_DISABLE_CAST_CHECKS */ +#define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip)) +#define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl)) +#define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class)) +#define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt)) +#define _G_TYPE_CIFT(ip, ft) (g_type_check_instance_is_fundamentally_a ((GTypeInstance*) ip, ft)) +#ifdef __GNUC__ +# define _G_TYPE_CIT(ip, gt) (G_GNUC_EXTENSION ({ \ + GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \ + if (!__inst) \ + __r = FALSE; \ + else if (__inst->g_class && __inst->g_class->g_type == __t) \ + __r = TRUE; \ + else \ + __r = g_type_check_instance_is_a (__inst, __t); \ + __r; \ +})) +# define _G_TYPE_CCT(cp, gt) (G_GNUC_EXTENSION ({ \ + GTypeClass *__class = (GTypeClass*) cp; GType __t = gt; gboolean __r; \ + if (!__class) \ + __r = FALSE; \ + else if (__class->g_type == __t) \ + __r = TRUE; \ + else \ + __r = g_type_check_class_is_a (__class, __t); \ + __r; \ +})) +# define _G_TYPE_CVH(vl, gt) (G_GNUC_EXTENSION ({ \ + const GValue *__val = (const GValue*) vl; GType __t = gt; gboolean __r; \ + if (!__val) \ + __r = FALSE; \ + else if (__val->g_type == __t) \ + __r = TRUE; \ + else \ + __r = g_type_check_value_holds (__val, __t); \ + __r; \ +})) +#else /* !__GNUC__ */ +# define _G_TYPE_CIT(ip, gt) (g_type_check_instance_is_a ((GTypeInstance*) ip, gt)) +# define _G_TYPE_CCT(cp, gt) (g_type_check_class_is_a ((GTypeClass*) cp, gt)) +# define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((const GValue*) vl, gt)) +#endif /* !__GNUC__ */ +/** + * G_TYPE_FLAG_RESERVED_ID_BIT: + * + * A bit in the type number that's supposed to be left untouched. + */ +#define G_TYPE_FLAG_RESERVED_ID_BIT ((GType) (1 << 0)) + +G_END_DECLS + +#endif /* __G_TYPE_H__ */ diff --git a/include/glib/gobject/gtypemodule.h b/include/glib/gobject/gtypemodule.h new file mode 100644 index 0000000000..5c40250631 --- /dev/null +++ b/include/glib/gobject/gtypemodule.h @@ -0,0 +1,295 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2000 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __G_TYPE_MODULE_H__ +#define __G_TYPE_MODULE_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gobject.h> +#include <gobject/genums.h> + +G_BEGIN_DECLS + +typedef struct _GTypeModule GTypeModule; +typedef struct _GTypeModuleClass GTypeModuleClass; + +#define G_TYPE_TYPE_MODULE (g_type_module_get_type ()) +#define G_TYPE_MODULE(module) (G_TYPE_CHECK_INSTANCE_CAST ((module), G_TYPE_TYPE_MODULE, GTypeModule)) +#define G_TYPE_MODULE_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_TYPE_MODULE, GTypeModuleClass)) +#define G_IS_TYPE_MODULE(module) (G_TYPE_CHECK_INSTANCE_TYPE ((module), G_TYPE_TYPE_MODULE)) +#define G_IS_TYPE_MODULE_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_TYPE_MODULE)) +#define G_TYPE_MODULE_GET_CLASS(module) (G_TYPE_INSTANCE_GET_CLASS ((module), G_TYPE_TYPE_MODULE, GTypeModuleClass)) + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTypeModule, g_object_unref) + +/** + * GTypeModule: + * @name: the name of the module + * + * The members of the GTypeModule structure should not + * be accessed directly, except for the @name field. + */ +struct _GTypeModule +{ + GObject parent_instance; + + guint use_count; + GSList *type_infos; + GSList *interface_infos; + + /*< public >*/ + gchar *name; +}; + +/** + * GTypeModuleClass: + * @parent_class: the parent class + * @load: loads the module and registers one or more types using + * g_type_module_register_type(). + * @unload: unloads the module + * + * In order to implement dynamic loading of types based on #GTypeModule, + * the @load and @unload functions in #GTypeModuleClass must be implemented. + */ +struct _GTypeModuleClass +{ + GObjectClass parent_class; + + /*< public >*/ + gboolean (* load) (GTypeModule *module); + void (* unload) (GTypeModule *module); + + /*< private >*/ + /* Padding for future expansion */ + void (*reserved1) (void); + void (*reserved2) (void); + void (*reserved3) (void); + void (*reserved4) (void); +}; + +/** + * G_DEFINE_DYNAMIC_TYPE: + * @TN: The name of the new type, in Camel case. + * @t_n: The name of the new type, in lowercase, with words + * separated by '_'. + * @T_P: The #GType of the parent type. + * + * A convenience macro for dynamic type implementations, which declares a + * class initialization function, an instance initialization function (see + * #GTypeInfo for information about these) and a static variable named + * `t_n`_parent_class pointing to the parent class. Furthermore, + * it defines a `*_get_type()` and a static `*_register_type()` functions + * for use in your `module_init()`. + * + * See G_DEFINE_DYNAMIC_TYPE_EXTENDED() for an example. + * + * Since: 2.14 + */ +#define G_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P) G_DEFINE_DYNAMIC_TYPE_EXTENDED (TN, t_n, T_P, 0, {}) +/** + * G_DEFINE_DYNAMIC_TYPE_EXTENDED: + * @TypeName: The name of the new type, in Camel case. + * @type_name: The name of the new type, in lowercase, with words + * separated by '_'. + * @TYPE_PARENT: The #GType of the parent type. + * @flags: #GTypeFlags to pass to g_type_module_register_type() + * @CODE: Custom code that gets inserted in the *_get_type() function. + * + * A more general version of G_DEFINE_DYNAMIC_TYPE() which + * allows to specify #GTypeFlags and custom code. + * + * |[ + * G_DEFINE_DYNAMIC_TYPE_EXTENDED (GtkGadget, + * gtk_gadget, + * GTK_TYPE_THING, + * 0, + * G_IMPLEMENT_INTERFACE_DYNAMIC (TYPE_GIZMO, + * gtk_gadget_gizmo_init)); + * ]| + * expands to + * |[ + * static void gtk_gadget_init (GtkGadget *self); + * static void gtk_gadget_class_init (GtkGadgetClass *klass); + * static void gtk_gadget_class_finalize (GtkGadgetClass *klass); + * + * static gpointer gtk_gadget_parent_class = NULL; + * static GType gtk_gadget_type_id = 0; + * + * static void gtk_gadget_class_intern_init (gpointer klass) + * { + * gtk_gadget_parent_class = g_type_class_peek_parent (klass); + * gtk_gadget_class_init ((GtkGadgetClass*) klass); + * } + * + * GType + * gtk_gadget_get_type (void) + * { + * return gtk_gadget_type_id; + * } + * + * static void + * gtk_gadget_register_type (GTypeModule *type_module) + * { + * const GTypeInfo g_define_type_info = { + * sizeof (GtkGadgetClass), + * (GBaseInitFunc) NULL, + * (GBaseFinalizeFunc) NULL, + * (GClassInitFunc) gtk_gadget_class_intern_init, + * (GClassFinalizeFunc) gtk_gadget_class_finalize, + * NULL, // class_data + * sizeof (GtkGadget), + * 0, // n_preallocs + * (GInstanceInitFunc) gtk_gadget_init, + * NULL // value_table + * }; + * gtk_gadget_type_id = g_type_module_register_type (type_module, + * GTK_TYPE_THING, + * "GtkGadget", + * &g_define_type_info, + * (GTypeFlags) flags); + * { + * const GInterfaceInfo g_implement_interface_info = { + * (GInterfaceInitFunc) gtk_gadget_gizmo_init + * }; + * g_type_module_add_interface (type_module, g_define_type_id, TYPE_GIZMO, &g_implement_interface_info); + * } + * } + * ]| + * + * Since: 2.14 + */ +#define G_DEFINE_DYNAMIC_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE) \ +static void type_name##_init (TypeName *self); \ +static void type_name##_class_init (TypeName##Class *klass); \ +static void type_name##_class_finalize (TypeName##Class *klass); \ +static gpointer type_name##_parent_class = NULL; \ +static GType type_name##_type_id = 0; \ +static gint TypeName##_private_offset; \ +\ +_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \ +\ +G_GNUC_UNUSED \ +static inline gpointer \ +type_name##_get_instance_private (TypeName *self) \ +{ \ + return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \ +} \ +\ +GType \ +type_name##_get_type (void) \ +{ \ + return type_name##_type_id; \ +} \ +static void \ +type_name##_register_type (GTypeModule *type_module) \ +{ \ + GType g_define_type_id G_GNUC_UNUSED; \ + const GTypeInfo g_define_type_info = { \ + sizeof (TypeName##Class), \ + (GBaseInitFunc) NULL, \ + (GBaseFinalizeFunc) NULL, \ + (GClassInitFunc)(void (*)(void)) type_name##_class_intern_init, \ + (GClassFinalizeFunc)(void (*)(void)) type_name##_class_finalize, \ + NULL, /* class_data */ \ + sizeof (TypeName), \ + 0, /* n_preallocs */ \ + (GInstanceInitFunc)(void (*)(void)) type_name##_init, \ + NULL /* value_table */ \ + }; \ + type_name##_type_id = g_type_module_register_type (type_module, \ + TYPE_PARENT, \ + #TypeName, \ + &g_define_type_info, \ + (GTypeFlags) flags); \ + g_define_type_id = type_name##_type_id; \ + { CODE ; } \ +} + +/** + * G_IMPLEMENT_INTERFACE_DYNAMIC: + * @TYPE_IFACE: The #GType of the interface to add + * @iface_init: The interface init function + * + * A convenience macro to ease interface addition in the @_C_ section + * of G_DEFINE_DYNAMIC_TYPE_EXTENDED(). See G_DEFINE_DYNAMIC_TYPE_EXTENDED() + * for an example. + * + * Note that this macro can only be used together with the + * G_DEFINE_DYNAMIC_TYPE_EXTENDED macros, since it depends on variable + * names from that macro. + * + * Since: 2.24 + */ +#define G_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init) { \ + const GInterfaceInfo g_implement_interface_info = { \ + (GInterfaceInitFunc)(void (*)(void)) iface_init, NULL, NULL \ + }; \ + g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \ +} + +/** + * G_ADD_PRIVATE_DYNAMIC: + * @TypeName: the name of the type in CamelCase + * + * A convenience macro to ease adding private data to instances of a new dynamic + * type in the @_C_ section of G_DEFINE_DYNAMIC_TYPE_EXTENDED(). See + * G_ADD_PRIVATE() for details, it is similar but for static types. + * + * Note that this macro can only be used together with the + * G_DEFINE_DYNAMIC_TYPE_EXTENDED macros, since it depends on variable + * names from that macro. + * + * Since: 2.38 + */ +#define G_ADD_PRIVATE_DYNAMIC(TypeName) { \ + TypeName##_private_offset = sizeof (TypeName##Private); \ +} + +GLIB_AVAILABLE_IN_ALL +GType g_type_module_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +gboolean g_type_module_use (GTypeModule *module); +GLIB_AVAILABLE_IN_ALL +void g_type_module_unuse (GTypeModule *module); +GLIB_AVAILABLE_IN_ALL +void g_type_module_set_name (GTypeModule *module, + const gchar *name); +GLIB_AVAILABLE_IN_ALL +GType g_type_module_register_type (GTypeModule *module, + GType parent_type, + const gchar *type_name, + const GTypeInfo *type_info, + GTypeFlags flags); +GLIB_AVAILABLE_IN_ALL +void g_type_module_add_interface (GTypeModule *module, + GType instance_type, + GType interface_type, + const GInterfaceInfo *interface_info); +GLIB_AVAILABLE_IN_ALL +GType g_type_module_register_enum (GTypeModule *module, + const gchar *name, + const GEnumValue *const_static_values); +GLIB_AVAILABLE_IN_ALL +GType g_type_module_register_flags (GTypeModule *module, + const gchar *name, + const GFlagsValue *const_static_values); + +G_END_DECLS + +#endif /* __G_TYPE_MODULE_H__ */ diff --git a/include/glib/gobject/gtypeplugin.h b/include/glib/gobject/gtypeplugin.h new file mode 100644 index 0000000000..482f55cae1 --- /dev/null +++ b/include/glib/gobject/gtypeplugin.h @@ -0,0 +1,134 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2000 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __G_TYPE_PLUGIN_H__ +#define __G_TYPE_PLUGIN_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gtype.h> + +G_BEGIN_DECLS + +/* --- type macros --- */ +#define G_TYPE_TYPE_PLUGIN (g_type_plugin_get_type ()) +#define G_TYPE_PLUGIN(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), G_TYPE_TYPE_PLUGIN, GTypePlugin)) +#define G_TYPE_PLUGIN_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), G_TYPE_TYPE_PLUGIN, GTypePluginClass)) +#define G_IS_TYPE_PLUGIN(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_TYPE_PLUGIN)) +#define G_IS_TYPE_PLUGIN_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), G_TYPE_TYPE_PLUGIN)) +#define G_TYPE_PLUGIN_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), G_TYPE_TYPE_PLUGIN, GTypePluginClass)) + + +/* --- typedefs & structures --- */ +typedef struct _GTypePluginClass GTypePluginClass; +/** + * GTypePluginUse: + * @plugin: the #GTypePlugin whose use count should be increased + * + * The type of the @use_plugin function of #GTypePluginClass, which gets called + * to increase the use count of @plugin. + */ +typedef void (*GTypePluginUse) (GTypePlugin *plugin); +/** + * GTypePluginUnuse: + * @plugin: the #GTypePlugin whose use count should be decreased + * + * The type of the @unuse_plugin function of #GTypePluginClass. + */ +typedef void (*GTypePluginUnuse) (GTypePlugin *plugin); +/** + * GTypePluginCompleteTypeInfo: + * @plugin: the #GTypePlugin + * @g_type: the #GType whose info is completed + * @info: the #GTypeInfo struct to fill in + * @value_table: the #GTypeValueTable to fill in + * + * The type of the @complete_type_info function of #GTypePluginClass. + */ +typedef void (*GTypePluginCompleteTypeInfo) (GTypePlugin *plugin, + GType g_type, + GTypeInfo *info, + GTypeValueTable *value_table); +/** + * GTypePluginCompleteInterfaceInfo: + * @plugin: the #GTypePlugin + * @instance_type: the #GType of an instantiable type to which the interface + * is added + * @interface_type: the #GType of the interface whose info is completed + * @info: the #GInterfaceInfo to fill in + * + * The type of the @complete_interface_info function of #GTypePluginClass. + */ +typedef void (*GTypePluginCompleteInterfaceInfo) (GTypePlugin *plugin, + GType instance_type, + GType interface_type, + GInterfaceInfo *info); +/** + * GTypePlugin: + * + * The GTypePlugin typedef is used as a placeholder + * for objects that implement the GTypePlugin interface. + */ +/** + * GTypePluginClass: + * @use_plugin: Increases the use count of the plugin. + * @unuse_plugin: Decreases the use count of the plugin. + * @complete_type_info: Fills in the #GTypeInfo and + * #GTypeValueTable structs for the type. The structs are initialized + * with `memset(s, 0, sizeof (s))` before calling this function. + * @complete_interface_info: Fills in missing parts of the #GInterfaceInfo + * for the interface. The structs is initialized with + * `memset(s, 0, sizeof (s))` before calling this function. + * + * The #GTypePlugin interface is used by the type system in order to handle + * the lifecycle of dynamically loaded types. + */ +struct _GTypePluginClass +{ + /*< private >*/ + GTypeInterface base_iface; + + /*< public >*/ + GTypePluginUse use_plugin; + GTypePluginUnuse unuse_plugin; + GTypePluginCompleteTypeInfo complete_type_info; + GTypePluginCompleteInterfaceInfo complete_interface_info; +}; + + +/* --- prototypes --- */ +GLIB_AVAILABLE_IN_ALL +GType g_type_plugin_get_type (void) G_GNUC_CONST; +GLIB_AVAILABLE_IN_ALL +void g_type_plugin_use (GTypePlugin *plugin); +GLIB_AVAILABLE_IN_ALL +void g_type_plugin_unuse (GTypePlugin *plugin); +GLIB_AVAILABLE_IN_ALL +void g_type_plugin_complete_type_info (GTypePlugin *plugin, + GType g_type, + GTypeInfo *info, + GTypeValueTable *value_table); +GLIB_AVAILABLE_IN_ALL +void g_type_plugin_complete_interface_info (GTypePlugin *plugin, + GType instance_type, + GType interface_type, + GInterfaceInfo *info); + +G_END_DECLS + +#endif /* __G_TYPE_PLUGIN_H__ */ diff --git a/include/glib/gobject/gvalue.h b/include/glib/gobject/gvalue.h new file mode 100644 index 0000000000..9d8f03482a --- /dev/null +++ b/include/glib/gobject/gvalue.h @@ -0,0 +1,196 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + * + * gvalue.h: generic GValue functions + */ +#ifndef __G_VALUE_H__ +#define __G_VALUE_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gtype.h> + +G_BEGIN_DECLS + +/* --- type macros --- */ +/** + * G_TYPE_IS_VALUE: + * @type: A #GType value. + * + * Checks whether the passed in type ID can be used for g_value_init(). + * That is, this macro checks whether this type provides an implementation + * of the #GTypeValueTable functions required for a type to create a #GValue of. + * + * Returns: Whether @type is suitable as a #GValue type. + */ +#define G_TYPE_IS_VALUE(type) (g_type_check_is_value_type (type)) +/** + * G_IS_VALUE: + * @value: A #GValue structure. + * + * Checks if @value is a valid and initialized #GValue structure. + * + * Returns: %TRUE on success. + */ +#define G_IS_VALUE(value) (G_TYPE_CHECK_VALUE (value)) +/** + * G_VALUE_TYPE: + * @value: A #GValue structure. + * + * Get the type identifier of @value. + * + * Returns: the #GType. + */ +#define G_VALUE_TYPE(value) (((GValue*) (value))->g_type) +/** + * G_VALUE_TYPE_NAME: + * @value: A #GValue structure. + * + * Gets the type name of @value. + * + * Returns: the type name. + */ +#define G_VALUE_TYPE_NAME(value) (g_type_name (G_VALUE_TYPE (value))) +/** + * G_VALUE_HOLDS: + * @value: A #GValue structure. + * @type: A #GType value. + * + * Checks if @value holds (or contains) a value of @type. + * This macro will also check for @value != %NULL and issue a + * warning if the check fails. + * + * Returns: %TRUE if @value holds the @type. + */ +#define G_VALUE_HOLDS(value,type) (G_TYPE_CHECK_VALUE_TYPE ((value), (type))) + + +/* --- typedefs & structures --- */ +/** + * GValueTransform: + * @src_value: Source value. + * @dest_value: Target value. + * + * The type of value transformation functions which can be registered with + * g_value_register_transform_func(). + * + * @dest_value will be initialized to the correct destination type. + */ +typedef void (*GValueTransform) (const GValue *src_value, + GValue *dest_value); +/** + * GValue: + * + * An opaque structure used to hold different types of values. + * The data within the structure has protected scope: it is accessible only + * to functions within a #GTypeValueTable structure, or implementations of + * the g_value_*() API. That is, code portions which implement new fundamental + * types. + * #GValue users cannot make any assumptions about how data is stored + * within the 2 element @data union, and the @g_type member should + * only be accessed through the G_VALUE_TYPE() macro. + */ +struct _GValue +{ + /*< private >*/ + GType g_type; + + /* public for GTypeValueTable methods */ + union { + gint v_int; + guint v_uint; + glong v_long; + gulong v_ulong; + gint64 v_int64; + guint64 v_uint64; + gfloat v_float; + gdouble v_double; + gpointer v_pointer; + } data[2]; +}; + + +/* --- prototypes --- */ +GLIB_AVAILABLE_IN_ALL +GValue* g_value_init (GValue *value, + GType g_type); +GLIB_AVAILABLE_IN_ALL +void g_value_copy (const GValue *src_value, + GValue *dest_value); +GLIB_AVAILABLE_IN_ALL +GValue* g_value_reset (GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_unset (GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_instance (GValue *value, + gpointer instance); +GLIB_AVAILABLE_IN_2_42 +void g_value_init_from_instance (GValue *value, + gpointer instance); + + +/* --- private --- */ +GLIB_AVAILABLE_IN_ALL +gboolean g_value_fits_pointer (const GValue *value); +GLIB_AVAILABLE_IN_ALL +gpointer g_value_peek_pointer (const GValue *value); + + +/* --- implementation details --- */ +GLIB_AVAILABLE_IN_ALL +gboolean g_value_type_compatible (GType src_type, + GType dest_type); +GLIB_AVAILABLE_IN_ALL +gboolean g_value_type_transformable (GType src_type, + GType dest_type); +GLIB_AVAILABLE_IN_ALL +gboolean g_value_transform (const GValue *src_value, + GValue *dest_value); +GLIB_AVAILABLE_IN_ALL +void g_value_register_transform_func (GType src_type, + GType dest_type, + GValueTransform transform_func); + +/** + * G_VALUE_NOCOPY_CONTENTS: + * + * If passed to G_VALUE_COLLECT(), allocated data won't be copied + * but used verbatim. This does not affect ref-counted types like + * objects. + */ +#define G_VALUE_NOCOPY_CONTENTS (1 << 27) + +/** + * G_VALUE_INIT: + * + * A #GValue must be initialized before it can be used. This macro can + * be used as initializer instead of an explicit `{ 0 }` when declaring + * a variable, but it cannot be assigned to a variable. + * + * |[ + * GValue value = G_VALUE_INIT; + * ]| + * + * Since: 2.30 + */ +#define G_VALUE_INIT { 0, { { 0 } } } + + +G_END_DECLS + +#endif /* __G_VALUE_H__ */ diff --git a/include/glib/gobject/gvaluearray.h b/include/glib/gobject/gvaluearray.h new file mode 100644 index 0000000000..dbc6be765d --- /dev/null +++ b/include/glib/gobject/gvaluearray.h @@ -0,0 +1,104 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2001 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + * + * gvaluearray.h: GLib array type holding GValues + */ +#ifndef __G_VALUE_ARRAY_H__ +#define __G_VALUE_ARRAY_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gvalue.h> + +G_BEGIN_DECLS + +/** + * G_TYPE_VALUE_ARRAY: + * + * The type ID of the "GValueArray" type which is a boxed type, + * used to pass around pointers to GValueArrays. + * + * Deprecated: 2.32: Use #GArray instead of #GValueArray + */ +#define G_TYPE_VALUE_ARRAY (g_value_array_get_type ()) GLIB_DEPRECATED_MACRO_IN_2_32_FOR(G_TYPE_ARRAY) + +/* --- typedefs & structs --- */ +typedef struct _GValueArray GValueArray; +/** + * GValueArray: + * @n_values: number of values contained in the array + * @values: array of values + * + * A #GValueArray contains an array of #GValue elements. + */ +struct _GValueArray +{ + guint n_values; + GValue *values; + + /*< private >*/ + guint n_prealloced; +}; + +/* --- prototypes --- */ +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +GType g_value_array_get_type (void) G_GNUC_CONST; + +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +GValue* g_value_array_get_nth (GValueArray *value_array, + guint index_); + +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +GValueArray* g_value_array_new (guint n_prealloced); + +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +void g_value_array_free (GValueArray *value_array); + +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +GValueArray* g_value_array_copy (const GValueArray *value_array); + +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +GValueArray* g_value_array_prepend (GValueArray *value_array, + const GValue *value); + +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +GValueArray* g_value_array_append (GValueArray *value_array, + const GValue *value); + +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +GValueArray* g_value_array_insert (GValueArray *value_array, + guint index_, + const GValue *value); + +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +GValueArray* g_value_array_remove (GValueArray *value_array, + guint index_); + +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +GValueArray* g_value_array_sort (GValueArray *value_array, + GCompareFunc compare_func); + +GLIB_DEPRECATED_IN_2_32_FOR(GArray) +GValueArray* g_value_array_sort_with_data (GValueArray *value_array, + GCompareDataFunc compare_func, + gpointer user_data); + + +G_END_DECLS + +#endif /* __G_VALUE_ARRAY_H__ */ diff --git a/include/glib/gobject/gvaluecollector.h b/include/glib/gobject/gvaluecollector.h new file mode 100644 index 0000000000..177aa3dfae --- /dev/null +++ b/include/glib/gobject/gvaluecollector.h @@ -0,0 +1,261 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + * + * gvaluecollector.h: GValue varargs stubs + */ +/** + * SECTION:value_collection + * @Short_description: Converting varargs to generic values + * @Title: Varargs Value Collection + * + * The macros in this section provide the varargs parsing support needed + * in variadic GObject functions such as g_object_new() or g_object_set(). + * They currently support the collection of integral types, floating point + * types and pointers. + */ +#ifndef __G_VALUE_COLLECTOR_H__ +#define __G_VALUE_COLLECTOR_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +/* we may want to add aggregate types here some day, if requested + * by users. the basic C types are covered already, everything + * smaller than an int is promoted to an integer and floats are + * always promoted to doubles for varargs call constructions. + */ +enum /*< skip >*/ +{ + G_VALUE_COLLECT_INT = 'i', + G_VALUE_COLLECT_LONG = 'l', + G_VALUE_COLLECT_INT64 = 'q', + G_VALUE_COLLECT_DOUBLE = 'd', + G_VALUE_COLLECT_POINTER = 'p' +}; + + +/* vararg union holding actual values collected + */ +/** + * GTypeCValue: + * @v_int: the field for holding integer values + * @v_long: the field for holding long integer values + * @v_int64: the field for holding 64 bit integer values + * @v_double: the field for holding floating point values + * @v_pointer: the field for holding pointers + * + * A union holding one collected value. + */ +union _GTypeCValue +{ + gint v_int; + glong v_long; + gint64 v_int64; + gdouble v_double; + gpointer v_pointer; +}; + +/** + * G_VALUE_COLLECT_INIT: + * @value: a #GValue return location. @value must contain only 0 bytes. + * @_value_type: the #GType to use for @value. + * @var_args: the va_list variable; it may be evaluated multiple times + * @flags: flags which are passed on to the collect_value() function of + * the #GTypeValueTable of @value. + * @__error: a #gchar** variable that will be modified to hold a g_new() + * allocated error messages if something fails + * + * Collects a variable argument value from a va_list. We have to + * implement the varargs collection as a macro, because on some systems + * va_list variables cannot be passed by reference. + * + * Since: 2.24 + */ +#define G_VALUE_COLLECT_INIT(value, _value_type, var_args, flags, __error) \ +G_STMT_START { \ + GValue *g_vci_val = (value); \ + guint g_vci_flags = (flags); \ + GTypeValueTable *g_vci_vtab = g_type_value_table_peek (_value_type); \ + const gchar *g_vci_collect_format = g_vci_vtab->collect_format; \ + GTypeCValue g_vci_cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \ + guint g_vci_n_values = 0; \ + \ + g_vci_val->g_type = _value_type; /* value_meminit() from gvalue.c */ \ + while (*g_vci_collect_format) \ + { \ + GTypeCValue *g_vci_cvalue = g_vci_cvalues + g_vci_n_values++; \ + \ + switch (*g_vci_collect_format++) \ + { \ + case G_VALUE_COLLECT_INT: \ + g_vci_cvalue->v_int = va_arg ((var_args), gint); \ + break; \ + case G_VALUE_COLLECT_LONG: \ + g_vci_cvalue->v_long = va_arg ((var_args), glong); \ + break; \ + case G_VALUE_COLLECT_INT64: \ + g_vci_cvalue->v_int64 = va_arg ((var_args), gint64); \ + break; \ + case G_VALUE_COLLECT_DOUBLE: \ + g_vci_cvalue->v_double = va_arg ((var_args), gdouble); \ + break; \ + case G_VALUE_COLLECT_POINTER: \ + g_vci_cvalue->v_pointer = va_arg ((var_args), gpointer); \ + break; \ + default: \ + g_assert_not_reached (); \ + } \ + } \ + *(__error) = g_vci_vtab->collect_value (g_vci_val, \ + g_vci_n_values, \ + g_vci_cvalues, \ + g_vci_flags); \ +} G_STMT_END + +/** + * G_VALUE_COLLECT: + * @value: a #GValue return location. @value is supposed to be initialized + * according to the value type to be collected + * @var_args: the va_list variable; it may be evaluated multiple times + * @flags: flags which are passed on to the collect_value() function of + * the #GTypeValueTable of @value. + * @__error: a #gchar** variable that will be modified to hold a g_new() + * allocated error messages if something fails + * + * Collects a variable argument value from a va_list. We have to + * implement the varargs collection as a macro, because on some systems + * va_list variables cannot be passed by reference. + * + * Note: If you are creating the @value argument just before calling this macro, + * you should use the #G_VALUE_COLLECT_INIT variant and pass the unitialized + * #GValue. That variant is faster than #G_VALUE_COLLECT. + */ +#define G_VALUE_COLLECT(value, var_args, flags, __error) G_STMT_START { \ + GValue *g_vc_value = (value); \ + GType g_vc_value_type = G_VALUE_TYPE (g_vc_value); \ + GTypeValueTable *g_vc_vtable = g_type_value_table_peek (g_vc_value_type); \ + \ + if (g_vc_vtable->value_free) \ + g_vc_vtable->value_free (g_vc_value); \ + memset (g_vc_value->data, 0, sizeof (g_vc_value->data)); \ + \ + G_VALUE_COLLECT_INIT(value, g_vc_value_type, var_args, flags, __error); \ +} G_STMT_END + +/** + * G_VALUE_COLLECT_SKIP: + * @_value_type: the #GType of the value to skip + * @var_args: the va_list variable; it may be evaluated multiple times + * + * Skip an argument of type @_value_type from @var_args. + */ +#define G_VALUE_COLLECT_SKIP(_value_type, var_args) \ +G_STMT_START { \ + GTypeValueTable *g_vcs_vtable = g_type_value_table_peek (_value_type); \ + const gchar *g_vcs_collect_format = g_vcs_vtable->collect_format; \ + \ + while (*g_vcs_collect_format) \ + { \ + switch (*g_vcs_collect_format++) \ + { \ + case G_VALUE_COLLECT_INT: \ + va_arg ((var_args), gint); \ + break; \ + case G_VALUE_COLLECT_LONG: \ + va_arg ((var_args), glong); \ + break; \ + case G_VALUE_COLLECT_INT64: \ + va_arg ((var_args), gint64); \ + break; \ + case G_VALUE_COLLECT_DOUBLE: \ + va_arg ((var_args), gdouble); \ + break; \ + case G_VALUE_COLLECT_POINTER: \ + va_arg ((var_args), gpointer); \ + break; \ + default: \ + g_assert_not_reached (); \ + } \ + } \ +} G_STMT_END + +/** + * G_VALUE_LCOPY: + * @value: a #GValue to store into the @var_args; this must be initialized + * and set + * @var_args: the va_list variable; it may be evaluated multiple times + * @flags: flags which are passed on to the lcopy_value() function of + * the #GTypeValueTable of @value. + * @__error: a #gchar** variable that will be modified to hold a g_new() + * allocated error message if something fails + * + * Stores a value’s value into one or more argument locations from a va_list. + * This is the inverse of G_VALUE_COLLECT(). + */ +#define G_VALUE_LCOPY(value, var_args, flags, __error) \ +G_STMT_START { \ + const GValue *g_vl_value = (value); \ + guint g_vl_flags = (flags); \ + GType g_vl_value_type = G_VALUE_TYPE (g_vl_value); \ + GTypeValueTable *g_vl_vtable = g_type_value_table_peek (g_vl_value_type); \ + const gchar *g_vl_lcopy_format = g_vl_vtable->lcopy_format; \ + GTypeCValue g_vl_cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \ + guint g_vl_n_values = 0; \ + \ + while (*g_vl_lcopy_format) \ + { \ + GTypeCValue *g_vl_cvalue = g_vl_cvalues + g_vl_n_values++; \ + \ + switch (*g_vl_lcopy_format++) \ + { \ + case G_VALUE_COLLECT_INT: \ + g_vl_cvalue->v_int = va_arg ((var_args), gint); \ + break; \ + case G_VALUE_COLLECT_LONG: \ + g_vl_cvalue->v_long = va_arg ((var_args), glong); \ + break; \ + case G_VALUE_COLLECT_INT64: \ + g_vl_cvalue->v_int64 = va_arg ((var_args), gint64); \ + break; \ + case G_VALUE_COLLECT_DOUBLE: \ + g_vl_cvalue->v_double = va_arg ((var_args), gdouble); \ + break; \ + case G_VALUE_COLLECT_POINTER: \ + g_vl_cvalue->v_pointer = va_arg ((var_args), gpointer); \ + break; \ + default: \ + g_assert_not_reached (); \ + } \ + } \ + *(__error) = g_vl_vtable->lcopy_value (g_vl_value, \ + g_vl_n_values, \ + g_vl_cvalues, \ + g_vl_flags); \ +} G_STMT_END + + +/** + * G_VALUE_COLLECT_FORMAT_MAX_LENGTH: + * + * The maximal number of #GTypeCValues which can be collected for a + * single #GValue. + */ +#define G_VALUE_COLLECT_FORMAT_MAX_LENGTH (8) + +G_END_DECLS + +#endif /* __G_VALUE_COLLECTOR_H__ */ diff --git a/include/glib/gobject/gvaluetypes.h b/include/glib/gobject/gvaluetypes.h new file mode 100644 index 0000000000..9274435329 --- /dev/null +++ b/include/glib/gobject/gvaluetypes.h @@ -0,0 +1,300 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. + * + * gvaluetypes.h: GLib default values + */ +#ifndef __G_VALUETYPES_H__ +#define __G_VALUETYPES_H__ + +#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) +#error "Only <glib-object.h> can be included directly." +#endif + +#include <gobject/gvalue.h> + +G_BEGIN_DECLS + +/* --- type macros --- */ +/** + * G_VALUE_HOLDS_CHAR: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_CHAR. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_CHAR(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_CHAR)) +/** + * G_VALUE_HOLDS_UCHAR: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_UCHAR. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_UCHAR(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_UCHAR)) +/** + * G_VALUE_HOLDS_BOOLEAN: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_BOOLEAN. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_BOOLEAN(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_BOOLEAN)) +/** + * G_VALUE_HOLDS_INT: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_INT. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_INT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_INT)) +/** + * G_VALUE_HOLDS_UINT: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_UINT. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_UINT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_UINT)) +/** + * G_VALUE_HOLDS_LONG: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_LONG. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_LONG(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_LONG)) +/** + * G_VALUE_HOLDS_ULONG: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_ULONG. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_ULONG(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ULONG)) +/** + * G_VALUE_HOLDS_INT64: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_INT64. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_INT64(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_INT64)) +/** + * G_VALUE_HOLDS_UINT64: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_UINT64. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_UINT64(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_UINT64)) +/** + * G_VALUE_HOLDS_FLOAT: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_FLOAT. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_FLOAT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLOAT)) +/** + * G_VALUE_HOLDS_DOUBLE: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_DOUBLE. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_DOUBLE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_DOUBLE)) +/** + * G_VALUE_HOLDS_STRING: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_STRING. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_STRING(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_STRING)) +/** + * G_VALUE_HOLDS_POINTER: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_POINTER. + * + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_POINTER(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_POINTER)) +/** + * G_TYPE_GTYPE: + * + * The type for #GType. + */ +#define G_TYPE_GTYPE (g_gtype_get_type()) +/** + * G_VALUE_HOLDS_GTYPE: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_GTYPE. + * + * Since: 2.12 + * Returns: %TRUE on success. + */ +#define G_VALUE_HOLDS_GTYPE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_GTYPE)) +/** + * G_VALUE_HOLDS_VARIANT: + * @value: a valid #GValue structure + * + * Checks whether the given #GValue can hold values of type %G_TYPE_VARIANT. + * + * Returns: %TRUE on success. + * + * Since: 2.26 + */ +#define G_VALUE_HOLDS_VARIANT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_VARIANT)) + + +/* --- prototypes --- */ +GLIB_DEPRECATED_IN_2_32_FOR(g_value_set_schar) +void g_value_set_char (GValue *value, + gchar v_char); +GLIB_DEPRECATED_IN_2_32_FOR(g_value_get_schar) +gchar g_value_get_char (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_schar (GValue *value, + gint8 v_char); +GLIB_AVAILABLE_IN_ALL +gint8 g_value_get_schar (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_uchar (GValue *value, + guchar v_uchar); +GLIB_AVAILABLE_IN_ALL +guchar g_value_get_uchar (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_boolean (GValue *value, + gboolean v_boolean); +GLIB_AVAILABLE_IN_ALL +gboolean g_value_get_boolean (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_int (GValue *value, + gint v_int); +GLIB_AVAILABLE_IN_ALL +gint g_value_get_int (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_uint (GValue *value, + guint v_uint); +GLIB_AVAILABLE_IN_ALL +guint g_value_get_uint (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_long (GValue *value, + glong v_long); +GLIB_AVAILABLE_IN_ALL +glong g_value_get_long (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_ulong (GValue *value, + gulong v_ulong); +GLIB_AVAILABLE_IN_ALL +gulong g_value_get_ulong (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_int64 (GValue *value, + gint64 v_int64); +GLIB_AVAILABLE_IN_ALL +gint64 g_value_get_int64 (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_uint64 (GValue *value, + guint64 v_uint64); +GLIB_AVAILABLE_IN_ALL +guint64 g_value_get_uint64 (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_float (GValue *value, + gfloat v_float); +GLIB_AVAILABLE_IN_ALL +gfloat g_value_get_float (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_double (GValue *value, + gdouble v_double); +GLIB_AVAILABLE_IN_ALL +gdouble g_value_get_double (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_string (GValue *value, + const gchar *v_string); +GLIB_AVAILABLE_IN_ALL +void g_value_set_static_string (GValue *value, + const gchar *v_string); +GLIB_AVAILABLE_IN_ALL +const gchar * g_value_get_string (const GValue *value); +GLIB_AVAILABLE_IN_ALL +gchar* g_value_dup_string (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_pointer (GValue *value, + gpointer v_pointer); +GLIB_AVAILABLE_IN_ALL +gpointer g_value_get_pointer (const GValue *value); +GLIB_AVAILABLE_IN_ALL +GType g_gtype_get_type (void); +GLIB_AVAILABLE_IN_ALL +void g_value_set_gtype (GValue *value, + GType v_gtype); +GLIB_AVAILABLE_IN_ALL +GType g_value_get_gtype (const GValue *value); +GLIB_AVAILABLE_IN_ALL +void g_value_set_variant (GValue *value, + GVariant *variant); +GLIB_AVAILABLE_IN_ALL +void g_value_take_variant (GValue *value, + GVariant *variant); +GLIB_AVAILABLE_IN_ALL +GVariant* g_value_get_variant (const GValue *value); +GLIB_AVAILABLE_IN_ALL +GVariant* g_value_dup_variant (const GValue *value); + + +/* Convenience for registering new pointer types */ +GLIB_AVAILABLE_IN_ALL +GType g_pointer_type_register_static (const gchar *name); + +/* debugging aid, describe value contents as string */ +GLIB_AVAILABLE_IN_ALL +gchar* g_strdup_value_contents (const GValue *value); + + +GLIB_AVAILABLE_IN_ALL +void g_value_take_string (GValue *value, + gchar *v_string); +GLIB_DEPRECATED_FOR(g_value_take_string) +void g_value_set_string_take_ownership (GValue *value, + gchar *v_string); + + +/* humpf, need a C representable type name for G_TYPE_STRING */ +/** + * gchararray: + * + * A C representable type name for #G_TYPE_STRING. + */ +typedef gchar* gchararray; + + +G_END_DECLS + +#endif /* __G_VALUETYPES_H__ */ |