X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=docs%2Freference%2Fgobject%2Ftmpl%2Fgtype.sgml;h=9ca599caacdc4dc426608002cf8d8a9354fdbb1b;hb=82395be2142e4c7702a19ddd2991a54c9add4eff;hp=76c9d4b6fc189c9f60aa7cacf576398a3688b6de;hpb=4abd166025f336f8b427e1e0a6faac103d96f87d;p=platform%2Fupstream%2Fglib.git diff --git a/docs/reference/gobject/tmpl/gtype.sgml b/docs/reference/gobject/tmpl/gtype.sgml index 76c9d4b..9ca599c 100644 --- a/docs/reference/gobject/tmpl/gtype.sgml +++ b/docs/reference/gobject/tmpl/gtype.sgml @@ -20,7 +20,7 @@ with g_type_register_static() that gets type specific information passed in via a #GTypeInfo structure. Dynamic types are created with g_type_register_dynamic() which takes a #GTypePlugin structure instead. The remaining type information (the -#GTypeInfo structure) is retrived during runtime through #GTypePlugin +#GTypeInfo structure) is retrieved during runtime through #GTypePlugin and the g_type_plugin_*() API. These registration functions are usually called only once from a function whose only purpose is to return the type identifier for a @@ -29,15 +29,25 @@ it may be instantiated, inherited, or implemented depending on exactly what sort of type it is. There is also a third registration function for registering fundamental types called g_type_register_fundamental() which requires both a #GTypeInfo -structure and a GTypeFundamentalInfo structure but it is seldom used +structure and a #GTypeFundamentalInfo structure but it is seldom used since most fundamental types are predefined rather than user-defined. + +A final word about type names. +Such an identifier needs to be at least three characters long. There is no +upper length limit. The first character needs to be a letter (a-z or A-Z) +or an underscore '_'. Subsequent characters can be letters, numbers or +any of '-_+'. + + + + A numerical value which represents the unique identifier of a registered @@ -47,9 +57,9 @@ type. -Returns #TRUE if @type is a fundamental data type such as #G_TYPE_INT or -#G_TYPE_POINTER. Fundamental types are types that serve as fundaments for -the derived types, thus they are the roots of distinct inheritance hierarchies. +Returns the fundamental type which is the ancestor of @type. +Fundamental types are types that serve as fundaments for the derived types, +thus they are the roots of distinct inheritance hierarchies. @type: A #GType value. @@ -63,36 +73,19 @@ for types that are assigned at compile-time. - + - - - -@ptype: -@branch_seqno: - - - - - - - -@type: - - - - -An integer that currently represents the highest value of all -fundamental type identifiers. This is of interest for dynamic -introduction of new fundamental types (a -rarely needed feature). +Returns the type ID for the fundamental type number @x. +Use g_type_fundamental_next() instead of this macro to create new fundamental +types. +@x: the fundamental type number. -Returns #TRUE if @type is an abstract type. An abstract type can not be +Returns %TRUE if @type is an abstract type. An abstract type can not be instantiated and is normally used as an abstract base class for derived classes. @@ -102,7 +95,7 @@ derived classes. -Returns #TRUE if @type is derived (or in object-oriented terminology: +Returns %TRUE if @type is derived (or in object-oriented terminology: inherited) from another type (this holds true for all non-fundamental types). @@ -112,7 +105,7 @@ types). -Returns #TRUE if @type is a fundamental type. +Returns %TRUE if @type is a fundamental type. @type: A #GType value. @@ -120,7 +113,16 @@ Returns #TRUE if @type is a fundamental type. +Returns %TRUE if @type is a value type which can be used for +g_value_init(). + + +@type: A #GType value. + + + +Returns %TRUE if @type has a #GTypeValueTable. @type: A #GType value. @@ -128,7 +130,7 @@ Returns #TRUE if @type is a fundamental type. -Returns #TRUE if @type is a classed type. +Returns %TRUE if @type is a classed type. @type: A #GType value. @@ -136,7 +138,7 @@ Returns #TRUE if @type is a classed type. -Returns #TRUE if @type can be instantiated. Instantiation is the +Returns %TRUE if @type can be instantiated. Instantiation is the process of creating an instance (object) of this type. @@ -145,7 +147,7 @@ process of creating an instance (object) of this type. -Returns #TRUE if @type is a derivable type. A derivable type can +Returns %TRUE if @type is a derivable type. A derivable type can be used as the base class of a flat (single-level) class hierarchy. @@ -154,7 +156,7 @@ be used as the base class of a flat (single-level) class hierarchy. -Returns #TRUE if @type is a deep derivable type. A deep derivable type +Returns %TRUE 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. @@ -163,71 +165,18 @@ can be used as the base class of a deep (multi-level) class hierarchy. -Returns #TRUE if @type is an interface type. +Returns %TRUE if @type is an interface type. Interface types are types that provide pure APIs, 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. +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). @type: A #GType value. - - -The predefined identifiers of the reserved fundamental types. - - -@G_TYPE_INVALID: Usually a return value indicating an error. -@G_TYPE_NONE: A synonym for the "void" type in C. -@G_TYPE_INTERFACE: Root type of all interface types. -@G_TYPE_CHAR: Identifier for the built-in type "gchar". -@G_TYPE_UCHAR: Identifier for the built-in type "guchar". -@G_TYPE_BOOLEAN: Identifier for the built-in type "gboolean". -@G_TYPE_INT: Identifier for the built-in type "gint". -@G_TYPE_UINT: Identifier for the built-in type "guint". -@G_TYPE_LONG: Identifier for the built-in type "glong". -@G_TYPE_ULONG: Identifier for the built-in type "gulong". -@G_TYPE_INT64: -@G_TYPE_UINT64: -@G_TYPE_ENUM: Identifier for the "#GEnum" type. -@G_TYPE_FLAGS: Identifier for the "#GFlags" type. -@G_TYPE_FLOAT: Identifier for the built-in type "gfloat". -@G_TYPE_DOUBLE: Identifier for the built-in type "gdouble". -@G_TYPE_STRING: Identifier for a pointer to a null-terminated string "gchar*". -@G_TYPE_POINTER: Identifier for anonymous pointers "void*". -@G_TYPE_BOXED: Identifier for the "#GBoxed" type. -@G_TYPE_PARAM: Identifier for the "#GParam" type. -@G_TYPE_OBJECT: Identifier for the "#GObject" type. -@G_TYPE_RESERVED_BSE_FIRST: First fundamental type ID reserved for BSE. -@G_TYPE_RESERVED_BSE_LAST: Last fundamental type ID reserved for BSE. -@G_TYPE_RESERVED_LAST_FUNDAMENTAL: Last reserved fundamental type ID. -@G_TYPE_CLOSURE: -@G_TYPE_VALUE: -@G_TYPE_VALUE_ARRAY: -@G_TYPE_GSTRING: -@G_TYPE_PARAM_CHAR: Identifier for the "#GParamSpecChar" type. -@G_TYPE_PARAM_UCHAR: Identifier for the "#GParamSpecUChar" type. -@G_TYPE_PARAM_BOOLEAN: Identifier for the "#GParamSpecBoolean" type. -@G_TYPE_PARAM_INT: Identifier for the "#GParamSpecInt" type. -@G_TYPE_PARAM_UINT: Identifier for the "#GParamSpecUInt" type. -@G_TYPE_PARAM_LONG: Identifier for the "#GParamSpecLong" type. -@G_TYPE_PARAM_ULONG: Identifier for the "#GParamSpecULong" type. -@G_TYPE_PARAM_INT64: -@G_TYPE_PARAM_UINT64: -@G_TYPE_PARAM_UNICHAR: -@G_TYPE_PARAM_ENUM: Identifier for the "#GParamSpecEnum" type. -@G_TYPE_PARAM_FLAGS: Identifier for the "#GParamSpecFlags" type. -@G_TYPE_PARAM_FLOAT: Identifier for the "#GParamSpecFloat" type. -@G_TYPE_PARAM_DOUBLE: Identifier for the "#GParamSpecDouble" type. -@G_TYPE_PARAM_STRING: Identifier for the "#GParamSpecString" type. -@G_TYPE_PARAM_PARAM: Identifier for the "#GParamSpecParam" type. -@G_TYPE_PARAM_BOXED: Identifier for the "#GParamSpecBoxed" type. -@G_TYPE_PARAM_POINTER: Identifier for the "#GParamSpecPointer" type. -@G_TYPE_PARAM_VALUE_ARRAY: Identifier for the "#GParamSpecValueArray" type. -@G_TYPE_PARAM_CLOSURE: Identifier for the "#GParamClosure" type. -@G_TYPE_PARAM_OBJECT: Identifier for the "#GParamSpecObject" type. - An opaque structure used as the base of all interface types. @@ -240,6 +189,12 @@ An opaque structure used as the base of all type instances. + + +An opaque structure used as the base of all classes. + + + This structure is used to provide the type system with the information @@ -255,13 +210,20 @@ across invocation of g_type_register_static(). @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 (optional, for classed and instantiatable types only). -@class_finalize: Location of the class finalization function (optional). +@class_init: Location of the class initialization function for + classed and 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 types. Location fo 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: Number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching). +@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 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 (usualy only +@value_table: A #GTypeValueTable function table for generic handling of GValues of this type (usually only useful for fundamental types). @@ -270,7 +232,7 @@ A structure that provides information to the type system which is used specifically for managing fundamental types. -@type_flags: +@type_flags: #GTypeFundamentalFlags describing the characteristics of the fundamental type @@ -292,26 +254,27 @@ to serve as a container for values of a type. @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 + 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 + value that may never be %NULL, the implementation might look like: - + { 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: - + { /* only free strings without a specific flag for static storage */ - if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) + 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. @@ -319,24 +282,24 @@ to serve as a container for values of a type. @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: - + { 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: - + { 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, the characters themselves indicate the type of the argument. Currently supported arguments are: - + 'i' - Integers. passed as collect_values[].v_int. @@ -349,7 +312,7 @@ to serve as a container for values of a type. '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' @@ -358,10 +321,10 @@ to serve as a container for values of a type. 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, + 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 + 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 @@ -370,15 +333,15 @@ to serve as a container for values of a type. @collect_flags is an argument provided as a hint by the caller, which 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. + 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: - + { if (!collect_values[0].v_pointer) value->data[0].v_pointer = g_strdup (""); - else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) + 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 */ @@ -389,15 +352,15 @@ to serve as a container for values of a type. 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 GSignal code, reference counts should always be incremented + by the #GSignal 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: - + { if (collect_values[0].v_pointer) { @@ -410,13 +373,13 @@ to serve as a container for values of a type. 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 + Upon success, collect_value() needs to return %NULL, if however a malicious condition occurred, collect_value() may spew an - error by returning a newly allocated non-NULL string, giving + 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 @@ -424,7 +387,7 @@ to serve as a container for values of a type. 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 + 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 @@ -439,23 +402,23 @@ to serve as a container for values of a type. Similar to collect_value() the function may prematurely abort by returning a newly allocated string describing an error condition. To complete the string example: - + { 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) + 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 exemplary version of lcopy_value() for reference-counted types: - + { GObject **object_p = collect_values[0].v_pointer; @@ -463,17 +426,20 @@ to serve as a container for values of a type. 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 */ + 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; } - + -Returns the type identifier from a given @instance structure. +Returns the type identifier from a given @instance structure. + + +This macro should only be used in type implementations. @instance: Location of a valid #GTypeInstance structure. @@ -482,6 +448,9 @@ Returns the type identifier from a given @instance structure. Returns the type identifier from a given @class structure. + + +This macro should only be used in type implementations. @g_class: Location of a valid #GTypeClass structure. @@ -490,6 +459,9 @@ Returns the type identifier from a given @class structure. Returns the type identifier from a given @interface structure. + + +This macro should only be used in type implementations. @g_iface: Location of a valid #GTypeInterface structure. @@ -498,90 +470,145 @@ Returns the type identifier from a given @interface structure. Returns the class structure of a given @instance, casted -to a specified anchestor type @g_type of the instance. +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. @instance: Location of the #GTypeInstance structure. @g_type: The anchestor type of the class to be returned. -@c_type: The corresponding C type of @g_Type. +@c_type: The corresponding C type of @g_type. +Returns the interface structure for interface @g_type of a given @instance. + + +This macro should only be used in type implementations. + + +@instance: Location of the #GTypeInstance structure. +@g_type: The interface type to be returned. +@c_type: The corresponding C type of @g_type. + + + +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. -@instance: -@g_type: -@c_type: +@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. - +Returns %TRUE if @instance is a valid #GTypeInstance structure, +otherwise emits a warning and returns %FALSE. + + +This macro should only be used in type implementations. -@instance: +@instance: Location of a #GTypeInstance structure. - +Checks that @instance is an instance of the type identified by @g_type +and emits a warning if this is not the case. Returns @instance casted +to a pointer to @c_type. + + +This macro should only be used in type implementations. -@instance: -@g_type: -@c_type: +@instance: Location of a #GTypeInstance structure. +@g_type: The type to be returned. +@c_type: The corresponding C type of @g_type. - +Returns %TRUE if @instance is an instance of the type identified by @g_type. +Otherwise emits a warning and returns %FALSE. + + +This macro should only be used in type implementations. -@instance: -@g_type: +@instance: Location of a #GTypeInstance structure. +@g_type: The type to be checked - +Checks that @g_class is a class structure of the type identified by @g_type +and emits a warning if this is not the case. Returns @g_class casted +to a pointer to @c_type. + + +This macro should only be used in type implementations. -@g_class: -@g_type: -@c_type: +@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. - +Returns %TRUE if @g_class is a class structure of the type identified by +@g_type. Otherwise emits a warning and returns %FALSE. + + +This macro should only be used in type implementations. -@g_class: -@g_type: +@g_class: Location of a #GTypeClass structure. +@g_type: The type to be checked. - +Returns %TRUE if @value has been initialized to hold values +of a value type. + + +This macro should only be used in type implementations. -@value: +@value: a #GValue - +Returns %TRUE if @value has been initialized to hold values +of type @g_type. + + +This macro should only be used in type implementations. -@value: -@g_type: +@value: a #GValue +@g_type: The type to be checked. - +A bit in the type number that's supposed to be left untouched. @@ -593,26 +620,39 @@ the type system and assorted other code portions (such as the various fundamenta type implementations or the signal system). - -@debug_flags: Bitwise combination of #GTypeDebugFlags values for debugging purposes. - + +The GTypeDebugFlags enumeration values can be passed to +g_type_init_with_debug_flags() to trigger debugging messages during runtime. +Note that the messages can also be triggered by setting the +GOBJECT_DEBUG environment variable to a ':'-separated list of +"objects" and "signals". -@debug_flags: +@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. + + + +Similar to g_type_init(), but additionally sets debug flags. + + +@debug_flags: Bitwise combination of #GTypeDebugFlags values for debugging purposes. -Return the unique name that is assigned to a type ID (this is the preferred method +Returns the unique name that is assigned to a type ID (this is the preferred method to find out whether a specific type has been registered for the passed in ID yet). @type: Type to return name for. -@Returns: Static type name or NULL. +@Returns: Static type name or %NULL. @@ -646,11 +686,12 @@ If the passed in type has no parent, i.e. is a fundamental type, 0 is returned. - +Returns the length of the ancestry of the passed in type. This includes the +type itself, so that e.g. a fundamental type has depth 1. -@type: -@Returns: +@type: A #GType value. +@Returns: The depth of @type. @@ -670,23 +711,15 @@ the leaf type is descended from the root type. -Check whether @type is a descendant of @is_a_type. +If @is_a_type is a derivable type, check whether @type is a descendant of @is_a_type. +If @is_a_type is an interface, check whether @type conforms to it. @type: Type to check anchestry for. -@is_a_type: Possible anchestor of @type. +@is_a_type: Possible anchestor of @type or interface @type could conform to. @Returns: %TRUE if @type is_a @is_a_type holds true. - - - - - -@type: -@Returns: - - Increments the reference count of the class structure belonging to @@ -702,15 +735,27 @@ exist already. This function is essentially the same as g_type_class_ref(), except that the classes reference count isn't incremented. Therefore, this function -may return NULL if the class of the type passed in does not currently +may return %NULL if the class of the type passed in does not currently exist (hasn't been referenced before). @type: Type ID of a classed type. -@Returns: The #GTypeClass structure for the given type ID or NULL +@Returns: The #GTypeClass structure for the given type ID or %NULL if the class does not currently exist. + + +A more efficient version of g_type_class_peek() which works only for +static types. + + +@type: Type ID of a classed type. +@Returns: The #GTypeClass structure for the given type ID or %NULL + if the class does not currently exist or is dynamically loaded. +@Since: 2.4 + + Decrements the reference count of the class structure being passed in. @@ -724,16 +769,16 @@ class pointer after g_type_class_unref() are invalid. -This is a convenience function, often needed in class intializers. +This is a convenience function, often needed in class initializers. It essentially takes the immediate parent type of the class passed in, and returns the class structure thereof. Since derived classes hold a reference count on their parent classes as long as they are instantiated, the returned class will always exist. This function is essentially equivalent to: - + g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class))); - + @@ -741,76 +786,205 @@ g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class))); @Returns: The parent class of @g_class. - + +Registers a private structure for a instantiatable type; +when an object is allocated, the private structures for +the type and and all of its parent types are allocated +sequentially in the same memory block as the public +structures. This function should be called in the +type's class_init() function. The private structure can +be retrieved using the G_TYPE_INSTANCE_GET_PRIVATE() macro. +The following example shows attaching a private structure +MyObjectPrivate to an object +MyObject defined in the standard GObject +fashion. + + +typedef struct _MyObjectPrivate MyObjectPrivate; +struct _MyObjectPrivate { + int some_field; +}; + +#define MY_OBJECT_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), MY_TYPE_OBJECT, MyObjectPrivate)) + +static void +my_object_class_init (MyObjectClass *klass) +{ + g_type_class_add_private (klass, sizeof (MyObjectPrivate)); +} + +static int +my_object_get_some_field (MyObject *my_object) +{ + MyObjectPrivate *priv = MY_OBJECT_GET_PRIVATE (my_object); + + return priv->some_field; +} + + +@g_class: class structure for an instantiatable type +@private_size: size of private structure. + + + + +Returns the #GTypeInterface structure of an interface to which the passed in +class conforms. -@instance_class: -@iface_type: -@Returns: +@instance_class: A #GTypeClass structure. +@iface_type: An interface ID which this class conforms to. +@Returns: The #GTypeInterface structure of @iface_type, or %NULL if the + class is not instantiated. +Returns the corresponding #GTypeInterface structure of the parent type +of the instance type to which @g_iface belongs. This is useful when +deriving the implementation of an interface from the parent type and +then possibly overriding some methods. + + +@g_iface: A #GTypeInterface structure. +@Returns: The corresponding #GTypeInterface structure of the parent type + of the instance type to which @g_iface belongs, or %NULL if the parent type + doesn't conform to the interface. + + + + +Increments the reference count for the interface type @g_type, +and returns the default interface vtable for the type. + + +If the type is not currently in use, then the default vtable +for the type will be created and initalized by calling +the base interface init and default vtable init functions for +the type (the @base_init +and class_init members of #GTypeInfo). +Calling g_type_default_interface_ref() is useful when you +want to make sure that signals and properties for an interface +have been installed. + +@g_type: an interface type +@Returns: the default vtable for the interface; call + g_type_default_interface_unref() when you are done using + the interface. +@Since: 2.4 + + + + +If the interface type @g_type is currently in use, returns +its default interface vtable. -@g_iface: -@Returns: +@g_type: an interface type +@Returns: the default vtable for the interface; or %NULL + if the type is not currently in use. +@Since: 2.4 + + + + +Decrements the reference count for the type corresponding to the +interface default vtable @g_iface. If the type is dynamic, then +when no one is using the interface and all references have +been released, the finalize function for the interface's default +vtable (the class_finalize member of +#GTypeInfo) will be called. + + +@g_iface: the default vtable structure for a interface, as + returned by g_type_default_interface_ref() +@Since: 2.4 -Return a newly allocated and 0 terminated array of type IDs, listing the +Return a newly allocated and 0-terminated array of type IDs, listing the child types of @type. The return value has to be g_free()ed after use. @type: The parent type. @n_children: Optional #guint pointer to contain the number of child types. -@Returns: Newly allocated and 0 terminated array of child types. +@Returns: Newly allocated and 0-terminated array of child types. -Return a newly allocated and 0 terminated array of type IDs, listing the +Return a newly allocated and 0-terminated array of type IDs, listing the interface types that @type conforms to. The return value has to be g_free()ed after use. @type: The type to list interface types for. @n_interfaces: Optional #guint pointer to contain the number of interface types. -@Returns: Newly allocated and 0 terminated array of interface types. +@Returns: Newly allocated and 0-terminated array of interface types. - + +Returns the prerequisites of an interfaces type. + +@interface_type: an interface type +@n_prerequisites: location to return the number of prerequisites, or %NULL +@Returns: a newly-allocated zero-terminated array of #GType containing + the prerequisites of @interface_type +@Since: 2.2 + + + + +Attaches arbitrary data to a type. -@type: -@quark: -@data: +@type: a #GType +@quark: a #GQuark id to identify the data +@data: the data - +Obtains data which has previously been attached to @type +with g_type_set_qdata(). -@type: -@quark: -@Returns: +@type: a #GType +@quark: a #GQuark id to identify the data +@Returns: the data, or %NULL if no data was found - +Queries the type system for information about a specific type. +This function will fill in a user-provided structure to hold type-specific +information. If an invalid #GType is passed in, the @type member of the +#GTypeQuery is 0. All members filled into the #GTypeQuery structure should +be considered constant and have to be left untouched. -@type: -@query: +@type: the #GType value of a static, classed type. +@query: A user provided structure that is filled in with constant values + upon success. + + + + +A structure holding information for a specific type. It is +filled in by the g_type_query() function. + +@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. @@ -855,11 +1029,11 @@ The initialization process of a class involves: over from the parent class. - 3 - Invocation of the GBaseInitFunc initializers of all parent + 3 - Invocation of the GBaseInitFunc() initializers of all parent types and the class' type. - 4 - Invocation of the class' GClassInitFunc initializer. + 4 - Invocation of the class' GClassInitFunc() initializer. Since derived classes are partially initialized through a memory copy @@ -867,15 +1041,15 @@ 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 intializing static +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 -are performed for class intialization of derived types as well. +is performed for class initialization of derived types as well. An example may help to correspond the intend of the different class initializers: - + typedef struct { GObjectClass parent_class; gint static_integer; @@ -905,7 +1079,7 @@ typedef struct { static void type_b_base_class_init (TypeBClass *class) { - class->dynamic_gstring = g_string_new ("some other string); + class->dynamic_gstring = g_string_new ("some other string"); } static void type_b_base_class_finalize (TypeBClass *class) @@ -917,7 +1091,7 @@ 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). @@ -950,7 +1124,7 @@ time. 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 +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). @@ -999,12 +1173,22 @@ allocated by the corresponding GInterfaceInitFunc() function. - +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. -@cache_data: -@g_class: -@Returns: +@cache_data: data that was given to the g_type_add_class_cache_func() call +@g_class: The #GTypeClass structure which is unreferenced +@Returns: %TRUE to stop further #GTypeClassCacheFuncs from being +called, %FALSE to continue. @@ -1014,7 +1198,9 @@ Bit masks used to check or determine characteristics of a type. @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be created for an abstract type. -@G_TYPE_FLAG_VALUE_ABSTRACT: +@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(). @@ -1024,7 +1210,7 @@ fundamental type. @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_DERIVABLE: Indicates a flat derivable type. @G_TYPE_FLAG_DEEP_DERIVABLE: Indicates a deep derivable type (implies derivable). @@ -1037,7 +1223,7 @@ instances (if not abstract). The value of @flags determines the nature @parent_type: Type which this type will be derived from. -@type_name: Null-terminated string used as the name of the new type. +@type_name: 0-terminated string used as the name of the new type. @info: The #GTypeInfo structure for this type. @flags: Bitwise combination of #GTypeFlags values. @Returns: The new type identifier. @@ -1053,12 +1239,10 @@ instances (if not abstract). The value of @flags determines the nature @parent_type: Type which this type will be derived from. -@type_name: Null-terminated string used as the name of the new type. -@plugin: The #GTypePlugin structure to retrive the #GTypeInfo from. +@type_name: 0-terminated string used as the name of the new type. +@plugin: The #GTypePlugin structure to retrieve the #GTypeInfo from. @flags: Bitwise combination of #GTypeFlags values. -@Returns: The new type identifier. - -@Returns: #G_TYPE_INVALID if registration failed or the new type identifier. +@Returns: The new type identifier or #G_TYPE_INVALID if registration failed. @@ -1072,7 +1256,7 @@ characteristics of the fundamental type. @type_id: A predefined #GTypeFundamentals value. -@type_name: Null-terminated string used as the name of the new type. +@type_name: 0-terminated string used as the name of the new type. @info: The #GTypeInfo structure for this type. @finfo: The #GTypeFundamentalInfo structure for this type. @flags: Bitwise combination of #GTypeFlags values. @@ -1094,49 +1278,75 @@ is used to manage the relationship. +Adds the dynamic @interface_type to @instantiable_type. The information +contained in the #GTypePlugin structure pointed to by @plugin +is used to manage the relationship. -@instance_type: -@interface_type: -@plugin: +@instance_type: the #GType value of an instantiable type. +@interface_type: the #GType value of an interface type. +@plugin: the #GTypePlugin structure to retrieve the #GInterfaceInfo from. - +Adds @prerequisite_type to the list of prerequisites of @interface_type. +This means that any type implementing @interface_type must also implement +@prerequisite_type. Prerequisites can be thought of as an alternative to +interface derivation (which GType doesn't support). An interface can have +at most one instantiatable prerequisite type. -@interface_type: -@prerequisite_type: +@interface_type: #GType value of an interface type. +@prerequisite_type: #GType value of an interface or instantiatable type. -Returns the the #GTypePlugin structure for @type or -#NULL if @type does not have a #GTypePlugin structure. +Returns the #GTypePlugin structure for @type or +%NULL if @type does not have a #GTypePlugin structure. -@type: The #GType to retrive the plugin for. +@type: The #GType to retrieve the plugin for. @Returns: The corresponding plugin if @type is a dynamic type, - NULL otherwise. + %NULL otherwise. +Returns the #GTypePlugin structure for the dynamic interface +@interface_type which has been added to @instance_type, or +%NULL if @interface_type has not been added to @instance_type or does +not have a #GTypePlugin structure. See g_type_add_interface_dynamic(). + + +@instance_type: the #GType value of an instantiatable type. +@interface_type: the #GType value of an interface type. +@Returns: the #GTypePlugin for the dynamic interface @interface_type + of @instance_type. + + + + +Returns the next free fundamental type id which can be used to +register a new fundamental type with g_type_register_fundamental(). +The returned type ID represents the highest currently registered +fundamental type identifier. + -@instance_type: -@implementation_type: -@Returns: +@Returns: The nextmost fundamental type ID to be registered, + or 0 if the type system ran out of fundamental type IDs. - + -Returns the last fundamental type which is registered plus one, -i.e. the next fundamental type ID that may be registered. +Internal function, used to extract the fundamental type ID portion. +use G_TYPE_FUNDAMENTAL() instead. -@Returns: The nextmost not registered fundamental type ID. +@type_id: valid type ID +@Returns: fundamental type ID @@ -1144,7 +1354,7 @@ i.e. the next fundamental type ID that may be registered. Creates and initializes an instance of @type if @type is valid and can be instantiated. The type system only performs basic allocation and structure setups for instances, actual instance creation should happen -through functions supplied by the types fundamental type implementation. +through functions supplied by the type's fundamental type implementation. So use of g_type_create_instance() is reserved for implementators of fundamental types only. E.g. instances of the #GObject hierarchy should be created via g_object_new() and never @@ -1155,42 +1365,100 @@ implementing a fundamental type. Also language bindings should not -@type: An instantiabtable type to create an instance for. +@type: An instantiatable type to create an instance for. @Returns: An allocated and initialized instance, subject to further treatment by the fundamental type implementation. +Frees an instance of a type, returning it to the instance pool for the type, +if there is one. + + +Like g_type_create_instance(), this function is reserved for implementors of +fundamental types. -@instance: +@instance: an instance of a type. - +Adds a #GTypeClassCacheFunc to be called before the reference count of a class +goes from one to zero. This can be used to prevent premature class destruction. +All installed #GTypeClassCacheFunc functions will be chained until one of them +returns %TRUE. 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. -@cache_data: -@cache_func: +@cache_data: data to be passed to @cache_func +@cache_func: a #GTypeClassCacheFunc - +Removes a previously installed #GTypeClassCacheFunc. The cache maintained +by @cache_func has to be empty when calling g_type_remove_class_cache_func() +to avoid leaks. -@cache_data: -@cache_func: +@cache_data: data that was given when adding @cache_func +@cache_func: a #GTypeClassCacheFunc +A variant of g_type_class_unref() for use in #GTypeClassCacheFunc +implementations. It unreferences a class without consulting the chain +of #GTypeClassCacheFuncs, avoiding the recursion which would occur +otherwise. + + +@g_class: The #GTypeClass structure to unreference. + + + + +Adds a function to be called after an interface vtable is +initialized for any class. That is, after the @interface_init +member of #GInterfaceInfo has been called. + + +This function is useful when you want to check an invariant +that depends on the interfaces of a class. For instance, +the implementation of #GObject uses this facility to check +that an object implements all of the properties that are +defined on its interfaces. + + +@check_data: data to pass to @check_func +@check_func: function to be called after each interface + is initialized. +@Since: 2.4 + + + + +Removes an interface check function added with +g_type_add_interface_check(). + + +@check_data: callback data passed to g_type_add_interface_check() +@check_func: callback function passed to g_type_add_interface_check() +@Since: 2.4 + + + +A callback called after an interface vtable is initialized. +See g_type_add_interface_check(). -@g_class: +@check_data: data passed to g_type_add_interface_check(). +@g_iface: the interface that has been initialized +@Since: 2.4 @@ -1203,6 +1471,342 @@ that implements or has internal knowledge of the implementation of @type: A #GType value. @Returns: Location of the #GTypeValueTable associated with @type or - #NULL if there is no #GTypeValueTable associated with @type. + %NULL if there is no #GTypeValueTable associated with @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. + + +@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. +@Since: 2.4 + + + + +A convenience macro for type implementations. +Similar to G_DEFINE_TYPE(), but allows 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. + + +@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. +@Since: 2.4 + + + + +A convenience macro for type implementations. +Similar to G_DEFINE_TYPE(), but defines an abstract type. +See G_DEFINE_TYPE_EXTENDED() for an example. + + +@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. +@Since: 2.4 + + + + +A convenience macro for type implementations. +Similar to G_DEFINE_TYPE_WITH_CODE(), but defines an abstract type and allows 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. + + +@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. +@Since: 2.4 + + + + +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. + + +@TYPE_IFACE: The #GType of the interface to add +@iface_init: The interface init function +@Since: 2.4 + + + + +The most general convenience macro for type implementations, on which +G_DEFINE_TYPE(), etc are based. + + +G_DEFINE_TYPE_EXTENDED (GtkGadget, + gtk_gadget, + GTK_TYPE_WIDGET, + 0, + G_IMPLEMENT_INTERFACE (TYPE_GIZMO, + gtk_gadget_gizmo_init)); + +expands to + +static void gtk_gadget_init (GtkGadget *self); +static void gtk_gadget_class_init (GtkGadgetClass *klass); +static gpointer gtk_gadget_parent_class = NULL; +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) +{ + static GType g_define_type_id = 0; + if (G_UNLIKELY (g_define_type_id == 0)) + { + static const GTypeInfo g_define_type_info = { + sizeof (GtkGadgetClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gtk_gadget_class_intern_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (GtkGadget), + 0, /* n_preallocs */ + (GInstanceInitFunc) gtk_gadget_init, + }; + g_define_type_id = g_type_register_static (GTK_TYPE_WIDGET, "GtkGadget", &g_define_type_info, 0); + { + static 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); + } + } + return g_define_type_id; +} + +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. + + +@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_register_static() +@CODE: Custom code that gets inserted in the *_get_type() function. +@Since: 2.4 + + + + +An invalid #GType, used as error return value in some functions which return +a #GType. + + + + + + +A fundamental type which is used as a replacement for the C +void return type. + + + + + + +The fundamental type from which all interfaces are derived. + + + + + + +The fundamental type corresponding to #gchar. + + + + + + +The fundamental type corresponding to #guchar. + + + + + + +The fundamental type corresponding to #gboolean. + + + + + + +The fundamental type corresponding to #gint. + + + + + + +The fundamental type corresponding to #guint. + + + + + + +The fundamental type corresponding to #glong. + + + + + + +The fundamental type corresponding to #gulong. + + + + + + +The fundamental type corresponding to #gint64. + + + + + + +The fundamental type corresponding to #guint64. + + + + + + +The fundamental type from which all enumeration types are derived. + + + + + + +The fundamental type from which all flags types are derived. + + + + + + +The fundamental type corresponding to #gfloat. + + + + + + +The fundamental type corresponding to #gdouble. + + + + + + +The fundamental type corresponding to nul-terminated C strings. + + + + + + +The fundamental type corresponding to #gpointer. + + + + + + +The fundamental type from which all boxed types are derived. + + + + + + +The fundamental type from which all #GParamSpec types are derived. + + + + + + +The fundamental type for #GObject. + + + + + + +First fundamental type number to create a new fundamental type id with +G_TYPE_MAKE_FUNDAMENTAL() reserved for GLib. + + + + + + +Last fundamental type number reserved for GLib. + + + + + + +First fundamental type number to create a new fundamental type id with +G_TYPE_MAKE_FUNDAMENTAL() reserved for BSE. + + + + + + +Last fundamental type number reserved for BSE. + + + + + + +First available fundamental type number to create new fundamental +type id with G_TYPE_MAKE_FUNDAMENTAL(). + + + +