GObject.TypeClass

Fields

Name

Type

Access

Description

g_type

GObject.GType

r

Methods

class

adjust_private_offset (g_class, private_size_or_offset)

class

peek (type)

class

peek_static (type)

class

ref (type)

add_private (private_size)

get_private (private_type)

peek_parent ()

unref ()

Details

class GObject.TypeClass

An opaque structure used as the base of all classes.

classmethod adjust_private_offset(g_class, private_size_or_offset)
Parameters:
classmethod peek(type)
Parameters:

type (GObject.GType) – type ID of a classed type

Returns:

the GObject.TypeClass structure for the given type ID or None if the class does not currently exist

Return type:

GObject.TypeClass

This function is essentially the same as GObject.TypeClass.ref(), except that the classes reference count isn’t incremented. As a consequence, this function may return None if the class of the type passed in does not currently exist (hasn’t been referenced before).

classmethod peek_static(type)
Parameters:

type (GObject.GType) – type ID of a classed type

Returns:

the GObject.TypeClass structure for the given type ID or None if the class does not currently exist or is dynamically loaded

Return type:

GObject.TypeClass

A more efficient version of GObject.TypeClass.peek() which works only for static types.

New in version 2.4.

classmethod ref(type)
Parameters:

type (GObject.GType) – type ID of a classed type

Returns:

the GObject.TypeClass structure for the given type ID

Return type:

GObject.TypeClass

Increments the reference count of the class structure belonging to type. This function will demand-create the class if it doesn’t exist already.

add_private(private_size)
Parameters:

private_size (int) – size of private structure

Registers a private structure for an instantiatable type.

When an object is allocated, the private structures for the type and all of its parent types are allocated sequentially in the same memory block as the public structures, and are zero-filled.

Note that the accumulated size of the private structures of a type and all its parent types cannot exceed 64 KiB.

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.Object fashion in the type’s class_init() function.

Note the use of a structure member “priv” to avoid the overhead of repeatedly calling MY_OBJECT_GET_PRIVATE().

typedef struct _MyObject        MyObject;
typedef struct _MyObjectPrivate MyObjectPrivate;

struct _MyObject {
 GObject parent;

 MyObjectPrivate *priv;
};

struct _MyObjectPrivate {
  int some_field;
};

static void
my_object_class_init (MyObjectClass *klass)
{
  g_type_class_add_private (klass, sizeof (MyObjectPrivate));
}

static void
my_object_init (MyObject *my_object)
{
  my_object->priv = G_TYPE_INSTANCE_GET_PRIVATE (my_object,
                                                 MY_TYPE_OBJECT,
                                                 MyObjectPrivate);
  // my_object->priv->some_field will be automatically initialised to 0
}

static int
my_object_get_some_field (MyObject *my_object)
{
  MyObjectPrivate *priv;

  g_return_val_if_fail (MY_IS_OBJECT (my_object), 0);

  priv = my_object->priv;

  return priv->some_field;
}

New in version 2.4.

Deprecated since version 2.58: Use the G_ADD_PRIVATE() macro with the G_DEFINE_* family of macros to add instance private data to a type

get_private(private_type)
Parameters:

private_type (GObject.GType) –

Return type:

object or None

peek_parent()
Returns:

the parent class of self

Return type:

GObject.TypeClass

This is a convenience function often needed in class initializers. It returns the class structure of the immediate parent type of the class passed in. 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: GObject.TypeClass.peek (GObject.type_parent (G_TYPE_FROM_CLASS (g_class)))

unref()

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 GObject.TypeClass.unref() are invalid.