Details
GType
A numerical value which represents the unique identifier of a registered
type.
G_TYPE_FUNDAMENTAL()
#define G_TYPE_FUNDAMENTAL(type) ((type) & 0xff) |
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.
G_TYPE_FUNDAMENTAL_MAX
#define G_TYPE_FUNDAMENTAL_MAX (0xff) |
An integer constant that represents the number of identifiers reserved
for types that are assigned at compile-time.
G_TYPE_DERIVE_ID()
#define G_TYPE_DERIVE_ID(ptype, branch_seqno) (G_TYPE_FUNDAMENTAL (ptype) | ((branch_seqno) << 8)) |
G_TYPE_BRANCH_SEQNO()
#define G_TYPE_BRANCH_SEQNO(type) ((type) >> 8) |
G_TYPE_FUNDAMENTAL_LAST
#define G_TYPE_FUNDAMENTAL_LAST ((GType) g_type_fundamental_last ()) |
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).
G_TYPE_IS_ABSTRACT()
#define G_TYPE_IS_ABSTRACT(type) (g_type_check_flags ((type), G_TYPE_FLAG_ABSTRACT)) |
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.
G_TYPE_IS_DERIVED()
#define G_TYPE_IS_DERIVED(type) (G_TYPE_BRANCH_SEQNO (type) > 0) |
Returns TRUE if type is derived (or in object-oriented terminology:
inherited) from another type (this holds true for all non-fundamental
types).
G_TYPE_IS_FUNDAMENTAL()
#define G_TYPE_IS_FUNDAMENTAL(type) (G_TYPE_BRANCH_SEQNO (type) == 0) |
Returns TRUE if type is a fundamental type.
G_TYPE_IS_VALUE_TYPE()
#define G_TYPE_IS_VALUE_TYPE(type) (g_type_check_is_value_type (type)) |
G_TYPE_IS_CLASSED()
#define G_TYPE_IS_CLASSED(type) (g_type_check_flags ((type), G_TYPE_FLAG_CLASSED)) |
Returns TRUE if type is a classed type.
G_TYPE_IS_INSTANTIATABLE()
#define G_TYPE_IS_INSTANTIATABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_INSTANTIATABLE)) |
Returns TRUE if type can be instantiated. Instantiation is the
process of creating an instance (object) of this type.
G_TYPE_IS_DERIVABLE()
#define G_TYPE_IS_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DERIVABLE)) |
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.
G_TYPE_IS_DEEP_DERIVABLE()
#define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE)) |
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.
G_TYPE_IS_INTERFACE()
#define G_TYPE_IS_INTERFACE(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE) |
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.
enum GTypeFundamentals
typedef enum /*< skip >*/
{
/* standard types, introduced by g_type_init() */
G_TYPE_INVALID,
G_TYPE_NONE,
G_TYPE_INTERFACE,
/* GLib type ids */
G_TYPE_CHAR,
G_TYPE_UCHAR,
G_TYPE_BOOLEAN,
G_TYPE_INT,
G_TYPE_UINT,
G_TYPE_LONG,
G_TYPE_ULONG,
G_TYPE_INT64,
G_TYPE_UINT64,
G_TYPE_ENUM,
G_TYPE_FLAGS,
G_TYPE_FLOAT,
G_TYPE_DOUBLE,
G_TYPE_STRING,
G_TYPE_POINTER,
G_TYPE_BOXED,
G_TYPE_PARAM,
G_TYPE_OBJECT,
/* reserved fundamental type ids,
* mail gtk-devel-list@redhat.com for reservations
*/
G_TYPE_RESERVED_BSE_FIRST,
G_TYPE_RESERVED_BSE_LAST = G_TYPE_RESERVED_BSE_FIRST + 15,
G_TYPE_RESERVED_LAST_FUNDAMENTAL,
/* derived type ids */
G_TYPE_CLOSURE = G_TYPE_DERIVE_ID (G_TYPE_BOXED, 1),
G_TYPE_VALUE = G_TYPE_DERIVE_ID (G_TYPE_BOXED, 2),
G_TYPE_VALUE_ARRAY = G_TYPE_DERIVE_ID (G_TYPE_BOXED, 3),
G_TYPE_GSTRING = G_TYPE_DERIVE_ID (G_TYPE_BOXED, 4),
G_TYPE_PARAM_CHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 1),
G_TYPE_PARAM_UCHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 2),
G_TYPE_PARAM_BOOLEAN = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 3),
G_TYPE_PARAM_INT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 4),
G_TYPE_PARAM_UINT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 5),
G_TYPE_PARAM_LONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 6),
G_TYPE_PARAM_ULONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 7),
G_TYPE_PARAM_INT64 = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 8),
G_TYPE_PARAM_UINT64 = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 9),
G_TYPE_PARAM_UNICHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 10),
G_TYPE_PARAM_ENUM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 11),
G_TYPE_PARAM_FLAGS = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 12),
G_TYPE_PARAM_FLOAT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 13),
G_TYPE_PARAM_DOUBLE = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 14),
G_TYPE_PARAM_STRING = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 15),
G_TYPE_PARAM_PARAM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 16),
G_TYPE_PARAM_BOXED = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 17),
G_TYPE_PARAM_POINTER = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 18),
G_TYPE_PARAM_VALUE_ARRAY = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 19),
G_TYPE_PARAM_CLOSURE = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 20),
G_TYPE_PARAM_OBJECT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 21)
} GTypeFundamentals; |
The predefined identifiers of the reserved fundamental types.
struct GTypeInterface
struct GTypeInterface
{
/*< private >*/
GType g_type; /* iface type */
GType g_instance_type;
}; |
An opaque structure used as the base of all interface types.
struct GTypeInstance
struct GTypeInstance
{
/*< private >*/
GTypeClass *g_class;
}; |
An opaque structure used as the base of all type instances.
struct GTypeInfo
struct GTypeInfo
{
/* interface types, classed types, instantiated types */
guint16 class_size;
GBaseInitFunc base_init;
GBaseFinalizeFunc base_finalize;
/* 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;
}; |
This structure is used to provide the type system with the information
required to initialize and destruct (finalize) a type's class and
instances thereof.
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 it's memory does not need to be persistent
across invocation of g_type_register_static().
struct GTypeFundamentalInfo
struct GTypeFundamentalInfo
{
GTypeFundamentalFlags type_flags;
}; |
A structure that provides information to the type system which is
used specifically for managing fundamental types.
struct GInterfaceInfo
struct GInterfaceInfo
{
GInterfaceInitFunc interface_init;
GInterfaceFinalizeFunc interface_finalize;
gpointer interface_data;
}; |
A structure that provides information to the type system which is
used specifically for managing interface types.
G_TYPE_FROM_INSTANCE()
#define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class)) |
Returns the type identifier from a given instance structure.
G_TYPE_FROM_CLASS()
#define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type) |
Returns the type identifier from a given class structure.
G_TYPE_FROM_INTERFACE()
#define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type) |
Returns the type identifier from a given interface structure.
G_TYPE_INSTANCE_GET_CLASS()
#define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), (g_type), c_type)) |
Returns the class structure of a given instance, casted
to a specified anchestor type g_type of the instance.
G_TYPE_INSTANCE_GET_INTERFACE()
#define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type)) |
G_TYPE_CHECK_INSTANCE()
#define G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI ((GTypeInstance*) (instance))) |
G_TYPE_CHECK_INSTANCE_CAST()
#define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type)) |
G_TYPE_CHECK_INSTANCE_TYPE()
#define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type))) |
G_TYPE_CHECK_CLASS_CAST()
#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()
#define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type))) |
G_TYPE_CHECK_VALUE()
#define G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV ((value))) |
G_TYPE_CHECK_VALUE_TYPE()
#define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVH ((value), (g_type))) |
G_TYPE_FLAG_RESERVED_ID_BIT
#define G_TYPE_FLAG_RESERVED_ID_BIT (1 << 30) |
g_type_init ()
Prior to any use of the type system, g_type_init() has to be called to initialize
the type system and assorted other code portions (such as the various fundamental
type implementations or the signal system).
g_type_init_with_debug_flags ()
void g_type_init_with_debug_flags (GTypeDebugFlags debug_flags); |
g_type_name ()
Return 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).
g_type_qname ()
Return the corresponding quark of the type IDs name.
g_type_from_name ()
Lookup the type ID from a given type name, returns 0 if no type has been registered under this name
(this is the preferred method to find out by name whether a specific type has been registered yet).
g_type_parent ()
Return the direct parent type of the passed in type.
If the passed in type has no parent, i.e. is a fundamental type, 0 is returned.
g_type_next_base ()
Given a leaf_type and a root_type which is contained in its anchestry, return
the type that root_type is the immediate parent of.
In other words, this function determines the type that is derived directly from
root_type which is also a base class of leaf_type. Given a root type and a
leaf type, this function can be used to determine the types and order in which
the leaf type is descended from the root type.
g_type_is_a ()
Check whether type is a descendant of is_a_type.
g_type_fundamental_branch_last ()
guint g_type_fundamental_branch_last (GType type); |
g_type_class_ref ()
Increments the reference count of the class structure belonging to
type. This function will demand-create the class if it doesn't
exist already.
g_type_class_peek ()
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
exist (hasn't been referenced before).
g_type_class_unref ()
void g_type_class_unref (gpointer g_class); |
Decrements the reference count of the class structure being passed in.
Once the last reference count of a class has been released, classes
may be finalized by the type system, so further dereferencing of a
class pointer after g_type_class_unref() are invalid.
g_type_class_peek_parent ()
This is a convenience function, often needed in class intializers.
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))); |
g_type_children ()
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.
g_type_interfaces ()
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.
g_type_query ()
void g_type_query (GType type,
GTypeQuery *query); |
GBaseInitFunc ()
void (*GBaseInitFunc) (gpointer g_class); |
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.
Therefore class members, e.g. 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
intialization process.
GBaseFinalizeFunc ()
void (*GBaseFinalizeFunc) (gpointer g_class); |
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 intialization is performed.
See GClassInitFunc() for a discussion of the class intialization process.
GClassInitFunc ()
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:
1 - Copying common members from the parent class over to the
derived class structure.
2 - Zero initialization of the remaining members not copied
over from the parent class.
3 - Invocation of the GBaseInitFunc initializers of all parent
types and the class' type.
4 - 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 intializing 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.
An example may help to correspond the intend of the different class
initializers:
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() that allocates
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.
GClassFinalizeFunc ()
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).
GInstanceInitFunc ()
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, therefore 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.
GInterfaceInitFunc ()
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.
GInterfaceFinalizeFunc ()
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.
enum GTypeFlags
typedef enum /*< skip >*/
{
G_TYPE_FLAG_ABSTRACT = (1 << 4),
G_TYPE_FLAG_VALUE_ABSTRACT = (1 << 5)
} GTypeFlags; |
Bit masks used to check or determine characteristics of a type.
enum GTypeFundamentalFlags
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; |
Bit masks used to check or determine specific characteristics of a
fundamental type.
g_type_register_static ()
Registers type_name as the name of a new static type derived from
parent_type. The type system uses the information contained in the
GTypeInfo structure pointed to by info to manage the type and its
instances (if not abstract). The value of flags determines the nature
(e.g. abstract or not) of the type.
g_type_register_dynamic ()
Registers type_name as the name of a new dynamic type derived from
parent_type. The type system uses the information contained in the
GTypePlugin structure pointed to by plugin to manage the type and its
instances (if not abstract). The value of flags determines the nature
(e.g. abstract or not) of the type.
g_type_register_fundamental ()
Registers type_id as the predefined identifier and type_name as the
name of a fundamental type. The type system uses the information
contained in the GTypeInfo structure pointed to by info and the
GTypeFundamentalInfo structure pointed to by finfo to manage the
type and its instances. The value of flags determines additional
characteristics of the fundamental type.
g_type_add_interface_static ()
Adds the static interface_type to instantiable_type. The information
contained in the GTypeInterfaceInfo structure pointed to by info
is used to manage the relationship.
g_type_add_interface_dynamic ()
g_type_interface_add_prerequisite ()
void g_type_interface_add_prerequisite
(GType interface_type,
GType prerequisite_type); |
g_type_interface_get_plugin ()
g_type_fundamental_last ()
GType g_type_fundamental_last (void); |
Returns the last fundamental type which is registered plus one,
i.e. the next fundamental type ID that may be registered.
g_type_create_instance ()
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.
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
directly through g_type_create_instance() which doesn't handle
things like singleton objects or object construction.
g_type_add_class_cache_func ()
g_type_remove_class_cache_func ()
g_type_class_unref_uncached ()
void g_type_class_unref_uncached (gpointer g_class); |
g_type_check_instance ()
Private helper function to aid implementation of the G_TYPE_CHECK_INSTANCE()
macro.
g_type_check_instance_cast ()
g_type_instance_is_a ()
Determines if instance adheres to the interface exported
by iface_type. iface_type is either a type that instance
is derived from, or an interface type that is supported by
the anchestry of instance.
g_type_check_class_cast ()
GTypeClass* g_type_check_class_cast (GTypeClass *g_class,
GType is_a_type); |
g_type_class_is_a ()
gboolean g_type_class_is_a (GTypeClass *g_class,
GType is_a_type); |
g_type_value_table_peek ()
Returns the location of the GTypeValueTable associated with type.
Note, this function should only be used from source code
that implements or has internal knowledge of the implementation of
type.