Specializable GType System

Specializable GType System — Specialized GTypes

Stability Level

Unstable, unless otherwise indicated

Synopsis




void                (*DBusGTypeSpecializedCollectionIterator)
                                                        (const GValue *value,
                                                         gpointer user_data);
void                (*DBusGTypeSpecializedMapIterator)  (const GValue *key_val,
                                                         const GValue *value_val,
                                                         gpointer user_data);
                    DBusGTypeSpecializedAppendContext;
gpointer            (*DBusGTypeSpecializedConstructor)  (GType type);
void                (*DBusGTypeSpecializedFreeFunc)     (GType type,
                                                         gpointer val);
gpointer            (*DBusGTypeSpecializedCopyFunc)     (GType type,
                                                         gpointer src);
                    DBusGTypeSpecializedVtable;
gboolean            (*DBusGTypeSpecializedCollectionFixedAccessorFunc)
                                                        (GType type,
                                                         gpointer instance,
                                                         gpointer *values,
                                                         guint *len);
void                (*DBusGTypeSpecializedCollectionIteratorFunc)
                                                        (GType type,
                                                         gpointer instance,
                                                         DBusGTypeSpecializedCollectionIterator iterator,
                                                         gpointer user_data);
void                (*DBusGTypeSpecializedCollectionAppendFunc)
                                                        (DBusGTypeSpecializedAppendContext *ctx,
                                                         GValue *val);
void                (*DBusGTypeSpecializedCollectionEndAppendFunc)
                                                        (DBusGTypeSpecializedAppendContext *ctx);
                    DBusGTypeSpecializedCollectionVtable;
void                (*DBusGTypeSpecializedMapIteratorFunc)
                                                        (GType type,
                                                         gpointer instance,
                                                         DBusGTypeSpecializedMapIterator iterator,
                                                         gpointer user_data);
void                (*DBusGTypeSpecializedMapAppendFunc)
                                                        (DBusGTypeSpecializedAppendContext *ctx,
                                                         GValue *key,
                                                         GValue *val);
                    DBusGTypeSpecializedMapVtable;
gboolean            (*DBusGTypeSpecializedStructGetMember)
                                                        (GType type,
                                                         gpointer instance,
                                                         guint member,
                                                         GValue *ret_value);
gboolean            (*DBusGTypeSpecializedStructSetMember)
                                                        (GType type,
                                                         gpointer instance,
                                                         guint member,
                                                         const GValue *new_value);
                    DBusGTypeSpecializedStructVtable;
GType               dbus_g_type_get_collection          (const char *container,
                                                         GType specialization);
GType               dbus_g_type_get_map                 (const char *container,
                                                         GType key_specialization,
                                                         GType value_specialization);
GType               dbus_g_type_get_structv             (const char *container,
                                                         guint num_members,
                                                         GType *types);
GType               dbus_g_type_get_struct              (const char *container,
                                                         GType first_type,
                                                         ...);
gboolean            dbus_g_type_is_collection           (GType gtype);
gboolean            dbus_g_type_is_map                  (GType gtype);
gboolean            dbus_g_type_is_struct               (GType gtype);
GType               dbus_g_type_get_collection_specialization
                                                        (GType gtype);
GType               dbus_g_type_get_map_key_specialization
                                                        (GType gtype);
GType               dbus_g_type_get_map_value_specialization
                                                        (GType gtype);
GType               dbus_g_type_get_struct_member_type  (GType gtype,
                                                         guint member);
guint               dbus_g_type_get_struct_size         (GType gtype);
gpointer            dbus_g_type_specialized_construct   (GType gtype);
void                dbus_g_type_specialized_init_append (GValue *value,
                                                         DBusGTypeSpecializedAppendContext *ctx);
void                dbus_g_type_specialized_collection_append
                                                        (DBusGTypeSpecializedAppendContext *ctx,
                                                         GValue *elt);
void                dbus_g_type_specialized_collection_end_append
                                                        (DBusGTypeSpecializedAppendContext *ctx);
void                dbus_g_type_specialized_map_append  (DBusGTypeSpecializedAppendContext *ctx,
                                                         GValue *key,
                                                         GValue *val);
gboolean            dbus_g_type_collection_get_fixed    (GValue *value,
                                                         gpointer *data,
                                                         guint *len);
void                dbus_g_type_collection_value_iterate
                                                        (const GValue *value,
                                                         DBusGTypeSpecializedCollectionIterator iterator,
                                                         gpointer user_data);
void                dbus_g_type_map_value_iterate       (const GValue *value,
                                                         DBusGTypeSpecializedMapIterator iterator,
                                                         gpointer user_data);
gboolean            dbus_g_type_struct_get_member       (const GValue *value,
                                                         guint member,
                                                         GValue *dest);
gboolean            dbus_g_type_struct_set_member       (GValue *value,
                                                         guint member,
                                                         const GValue *src);
gboolean            dbus_g_type_struct_get              (const GValue *value,
                                                         guint member,
                                                         ...);
gboolean            dbus_g_type_struct_set              (GValue *value,
                                                         guint member,
                                                         ...);
void                dbus_g_type_specialized_init        (void);
void                dbus_g_type_register_collection     (const char *name,
                                                         const DBusGTypeSpecializedCollectionVtable *vtable,
                                                         guint flags);
void                dbus_g_type_register_map            (const char *name,
                                                         const DBusGTypeSpecializedMapVtable *vtable,
                                                         guint flags);
const DBusGTypeSpecializedMapVtable* dbus_g_type_map_peek_vtable
                                                        (GType map_type);
const DBusGTypeSpecializedCollectionVtable* dbus_g_type_collection_peek_vtable
                                                        (GType collection_type);
void                dbus_g_type_register_struct         (const char *name,
                                                         const DBusGTypeSpecializedStructVtable *vtable,
                                                         guint flags);

Description

Specialized gtypes are basically a way to allow the definition of recursive GTypes. It allows the definition of 'containers' which is basically a user defined structure capabale of holding other data and a set of functions defining how to access that structure. Containers come in 3 flavors: collections, maps and structs.

A collection is a container that holds an ordered set of items, all of which must be the same type.

A map is a container that holds a set of key/value pairs. The keys have one type, and the values another.

A struct is a container that holds a fixed number of members, each member having a predefined type.

A specialization is a GType detailing a particular container with particular types (a type specialization).

Functions are provided for constructing and manipulating specializations.

This documentation needs splitting into two pages, one for defining new containers and using existing containers. I expect most users to only do the latter. I also need to add some examples.

Details

DBusGTypeSpecializedCollectionIterator ()

void                (*DBusGTypeSpecializedCollectionIterator)
                                                        (const GValue *value,
                                                         gpointer user_data);

value :

user_data :


DBusGTypeSpecializedMapIterator ()

void                (*DBusGTypeSpecializedMapIterator)  (const GValue *key_val,
                                                         const GValue *value_val,
                                                         gpointer user_data);

key_val :

value_val :

user_data :


DBusGTypeSpecializedAppendContext

typedef struct {
  /* public */
  GValue *val;
  GType specialization_type;
  /* padding */
  gpointer b;
  guint c;
  gpointer d;
} DBusGTypeSpecializedAppendContext;


DBusGTypeSpecializedConstructor ()

gpointer            (*DBusGTypeSpecializedConstructor)  (GType type);

type :

Returns :


DBusGTypeSpecializedFreeFunc ()

void                (*DBusGTypeSpecializedFreeFunc)     (GType type,
                                                         gpointer val);

type :

val :


DBusGTypeSpecializedCopyFunc ()

gpointer            (*DBusGTypeSpecializedCopyFunc)     (GType type,
                                                         gpointer src);

type :

src :

Returns :


DBusGTypeSpecializedVtable

typedef struct {
  DBusGTypeSpecializedConstructor    constructor;
  DBusGTypeSpecializedFreeFunc       free_func;
  DBusGTypeSpecializedCopyFunc       copy_func;
  GDestroyNotify                     simple_free_func; /* for type-independent freeing if possible */
  gpointer                           padding2;
  gpointer                           padding3;
} DBusGTypeSpecializedVtable;


DBusGTypeSpecializedCollectionFixedAccessorFunc ()

gboolean            (*DBusGTypeSpecializedCollectionFixedAccessorFunc)
                                                        (GType type,
                                                         gpointer instance,
                                                         gpointer *values,
                                                         guint *len);

type :

instance :

values :

len :

Returns :


DBusGTypeSpecializedCollectionIteratorFunc ()

void                (*DBusGTypeSpecializedCollectionIteratorFunc)
                                                        (GType type,
                                                         gpointer instance,
                                                         DBusGTypeSpecializedCollectionIterator iterator,
                                                         gpointer user_data);

type :

instance :

iterator :

user_data :


DBusGTypeSpecializedCollectionAppendFunc ()

void                (*DBusGTypeSpecializedCollectionAppendFunc)
                                                        (DBusGTypeSpecializedAppendContext *ctx,
                                                         GValue *val);

ctx :

val :


DBusGTypeSpecializedCollectionEndAppendFunc ()

void                (*DBusGTypeSpecializedCollectionEndAppendFunc)
                                                        (DBusGTypeSpecializedAppendContext *ctx);

ctx :


DBusGTypeSpecializedCollectionVtable

typedef struct {
  DBusGTypeSpecializedVtable                        base_vtable;
  DBusGTypeSpecializedCollectionFixedAccessorFunc   fixed_accessor;
  DBusGTypeSpecializedCollectionIteratorFunc        iterator;
  DBusGTypeSpecializedCollectionAppendFunc          append_func;
  DBusGTypeSpecializedCollectionEndAppendFunc       end_append_func;
} DBusGTypeSpecializedCollectionVtable;


DBusGTypeSpecializedMapIteratorFunc ()

void                (*DBusGTypeSpecializedMapIteratorFunc)
                                                        (GType type,
                                                         gpointer instance,
                                                         DBusGTypeSpecializedMapIterator iterator,
                                                         gpointer user_data);

type :

instance :

iterator :

user_data :


DBusGTypeSpecializedMapAppendFunc ()

void                (*DBusGTypeSpecializedMapAppendFunc)
                                                        (DBusGTypeSpecializedAppendContext *ctx,
                                                         GValue *key,
                                                         GValue *val);

ctx :

key :

val :


DBusGTypeSpecializedMapVtable

typedef struct {
  DBusGTypeSpecializedVtable                        base_vtable;
  DBusGTypeSpecializedMapIteratorFunc               iterator;
  DBusGTypeSpecializedMapAppendFunc                 append_func;
} DBusGTypeSpecializedMapVtable;


DBusGTypeSpecializedStructGetMember ()

gboolean            (*DBusGTypeSpecializedStructGetMember)
                                                        (GType type,
                                                         gpointer instance,
                                                         guint member,
                                                         GValue *ret_value);

type :

instance :

member :

ret_value :

Returns :


DBusGTypeSpecializedStructSetMember ()

gboolean            (*DBusGTypeSpecializedStructSetMember)
                                                        (GType type,
                                                         gpointer instance,
                                                         guint member,
                                                         const GValue *new_value);

type :

instance :

member :

new_value :

Returns :


DBusGTypeSpecializedStructVtable

typedef struct {
  DBusGTypeSpecializedVtable                        base_vtable;
  DBusGTypeSpecializedStructGetMember               get_member;
  DBusGTypeSpecializedStructSetMember               set_member;
} DBusGTypeSpecializedStructVtable;


dbus_g_type_get_collection ()

GType               dbus_g_type_get_collection          (const char *container,
                                                         GType specialization);

Gets a GType for a particular collection instance, creating the type if not already created.

container :

a string specifying a registered collection type

specialization :

GType of collection elements

Returns :

the GType of that instance

dbus_g_type_get_map ()

GType               dbus_g_type_get_map                 (const char *container,
                                                         GType key_specialization,
                                                         GType value_specialization);

Gets a GType for a particular map instance, creating the type if not already created.

container :

a string specifying a registered map type

key_specialization :

GType of keys

value_specialization :

GType of values

Returns :

the GType of that instance

dbus_g_type_get_structv ()

GType               dbus_g_type_get_structv             (const char *container,
                                                         guint num_members,
                                                         GType *types);

Gets a GType for a particular struct instance, creating the type if not already created.

container :

a string specifying a registered struct type

num_members :

number of members in the struct

types :

an array specufying a GType for each struct element

Returns :

the GType of that instance

dbus_g_type_get_struct ()

GType               dbus_g_type_get_struct              (const char *container,
                                                         GType first_type,
                                                         ...);

Varags methsod to get a GType for a particular struct instance, creating the type if not already created.

container :

a string specifying a registered struct type

first_type :

GType for the struct's first member

... :

more GTypes for the struct's members, terminated by G_TYPE_INVALID

Returns :

the GType of that instance

dbus_g_type_is_collection ()

gboolean            dbus_g_type_is_collection           (GType gtype);

Tests if a given GType is a collection.

gtype :

a GType to test

Returns :

true if the given GType is a collection

dbus_g_type_is_map ()

gboolean            dbus_g_type_is_map                  (GType gtype);

Tests if a given GType is a map, i.e. it was created with dbus_g_type_get_map.

gtype :

a GType to test

Returns :

true if the given GType is a map

dbus_g_type_is_struct ()

gboolean            dbus_g_type_is_struct               (GType gtype);

Tests if a given GType is a struct, i.e. it was created with dbus_g_type_get_struct

gtype :

a GType to test

Returns :

true if the given GType is a struct

dbus_g_type_get_collection_specialization ()

GType               dbus_g_type_get_collection_specialization
                                                        (GType gtype);

gtype :

a collection GType, as created by dbus_g_type_get_collection.

Returns :

the element type for a given collection GType. Returns G_TYPE_INVALID if not a collection GType

dbus_g_type_get_map_key_specialization ()

GType               dbus_g_type_get_map_key_specialization
                                                        (GType gtype);

gtype :

a map GType, as created by dbus_g_type_get_map.

Returns :

the key type for a given map GType. Returns G_TYPE_INVALID if not a map GType

dbus_g_type_get_map_value_specialization ()

GType               dbus_g_type_get_map_value_specialization
                                                        (GType gtype);

gtype :

a map GType, as created by dbus_g_type_get_map.

Returns :

the value type for a given map GType. Returns G_TYPE_INVALID if not a map GType

dbus_g_type_get_struct_member_type ()

GType               dbus_g_type_get_struct_member_type  (GType gtype,
                                                         guint member);

gtype :

a struct GType, as created with dbus_g_type_get_struct

member :

the index of a struct member

Returns :

the type for a given member of a struct GType. Returns G_TYPE_INVALID if not a struct GType

dbus_g_type_get_struct_size ()

guint               dbus_g_type_get_struct_size         (GType gtype);

gtype :

a struct GType, as created with dbus_g_type_get_struct.

Returns :

the number of members in a given struct GType. Returns G_TYPE_INVALID if not a struct GType

dbus_g_type_specialized_construct ()

gpointer            dbus_g_type_specialized_construct   (GType gtype);

Create an instance of a given specialized type. The structure created and returned will depend on the container type of the GType. E.g. If the given type was created by dbus_g_type_get_collection("GArray", G_TYPE_INT), then this will return a GArray with element_size of sizeof(int)

gtype :

a specialized GType, as created by dbus_g_type_get_collection, dbus_g_type_get_map or dbus_g_type_get_struct.

Returns :

a pointer to a newly constructed instance of the given type.

dbus_g_type_specialized_init_append ()

void                dbus_g_type_specialized_init_append (GValue *value,
                                                         DBusGTypeSpecializedAppendContext *ctx);

Create a new context for adding elements to a collection or key/value pairs to a map. You generally don't need or want to use this..

value :

a GValue containing an instance of specialized type

ctx :

a DBusGTypeSpecializedAppendContext in which to return a new appending context.

dbus_g_type_specialized_collection_append ()

void                dbus_g_type_specialized_collection_append
                                                        (DBusGTypeSpecializedAppendContext *ctx,
                                                         GValue *elt);

Appends a given element to the end of a collection.

ctx :

a context created by dbus_g_type_specialized_init_append

elt :

a GValue containing an element to append to the collection.

dbus_g_type_specialized_collection_end_append ()

void                dbus_g_type_specialized_collection_end_append
                                                        (DBusGTypeSpecializedAppendContext *ctx);

Finish appending elements to a given collection

ctx :

a context created by dbus_g_type_specialized_init_append

dbus_g_type_specialized_map_append ()

void                dbus_g_type_specialized_map_append  (DBusGTypeSpecializedAppendContext *ctx,
                                                         GValue *key,
                                                         GValue *val);

Inserts the given key/value pair into the map instance.

ctx :

a context created by dbus_g_type_specialized_init_append

key :

a GValue containing a key

val :

a GValue containing a value

dbus_g_type_collection_get_fixed ()

gboolean            dbus_g_type_collection_get_fixed    (GValue *value,
                                                         gpointer *data,
                                                         guint *len);

if the collection has elements of fixed size (i.e. a fundamental type), return the contents of the array. Its pretty obscure and I don't think anyone uses it.

value :

data :

len :

Returns :


dbus_g_type_collection_value_iterate ()

void                dbus_g_type_collection_value_iterate
                                                        (const GValue *value,
                                                         DBusGTypeSpecializedCollectionIterator iterator,
                                                         gpointer user_data);

Calls the given function for each element of the collection. The function is passed a GValue containing the element and the given user_data parameter. The collection may not be modified while iterating over it.

value :

a GValue holding a collection type.

iterator :

a function to call for each element

user_data :

user data to pass to the iterator

dbus_g_type_map_value_iterate ()

void                dbus_g_type_map_value_iterate       (const GValue *value,
                                                         DBusGTypeSpecializedMapIterator iterator,
                                                         gpointer user_data);

Calls the given function for each key/value pair of the map. The function is passed two GValues containing the key/value pair and the given user_data parameter. The map may not be modified while iterating over it.

value :

a GValue holding a collection type.

iterator :

a function to call for each element

user_data :

user data to pass to the iterator

dbus_g_type_struct_get_member ()

gboolean            dbus_g_type_struct_get_member       (const GValue *value,
                                                         guint member,
                                                         GValue *dest);

Fetches a given member of a given struct instance. dest must be initialised was the correct type for that member, e.g. as returned by dbus_g_type_get_struct_member_type

value :

a GValue containing a struct instance

member :

the index of a given member

dest :

an initialised GValue in which to return the struct member

Returns :

TRUE if sucessful

dbus_g_type_struct_set_member ()

gboolean            dbus_g_type_struct_set_member       (GValue *value,
                                                         guint member,
                                                         const GValue *src);

Sets a given member of a struct to a new value. The type of src must match the exiting type of member member of the struct.

value :

a GValue containing a struct instance

member :

the index of a given member

src :

an GValue containing the new value for that struct member

Returns :

TRUE if sucessful

dbus_g_type_struct_get ()

gboolean            dbus_g_type_struct_get              (const GValue *value,
                                                         guint member,
                                                         ...);

Collects the selected values of this struct into the return locations provided.

value :

a GValue containing a DBusGTypeStruct type

member :

struct member to get

... :

location in which to return the value of this member, followed optionally by more member/return locations pairs, followed by by G_MAXUINT

Returns :

FALSE on failure

dbus_g_type_struct_set ()

gboolean            dbus_g_type_struct_set              (GValue *value,
                                                         guint member,
                                                         ...);

Sets the selected members of the struct in value.

value :

a GValue containing a DBusGTypeStruct type

member :

struct member to set

... :

value for the first member, followed optionally by more member/value pairs, followed by G_MAXUINT

Returns :

FALSE on failure

dbus_g_type_specialized_init ()

void                dbus_g_type_specialized_init        (void);


dbus_g_type_register_collection ()

void                dbus_g_type_register_collection     (const char *name,
                                                         const DBusGTypeSpecializedCollectionVtable *vtable,
                                                         guint flags);

Defines a new collection container.

name :

The name of a new collection container

vtable :

the vtable defining the new container

flags :

As yet unused.

dbus_g_type_register_map ()

void                dbus_g_type_register_map            (const char *name,
                                                         const DBusGTypeSpecializedMapVtable *vtable,
                                                         guint flags);

Defines a new map container.

name :

The name of a new map container

vtable :

the vtable defining the new container

flags :

As yet unused.

dbus_g_type_map_peek_vtable ()

const DBusGTypeSpecializedMapVtable* dbus_g_type_map_peek_vtable
                                                        (GType map_type);

Peek the vtable for a given map specialization

map_type :

a gtype of a map specialization

Returns :


dbus_g_type_collection_peek_vtable ()

const DBusGTypeSpecializedCollectionVtable* dbus_g_type_collection_peek_vtable
                                                        (GType collection_type);

Peek the vtable for a given collection specialization

collection_type :

a gtype of a collection specialization

Returns :


dbus_g_type_register_struct ()

void                dbus_g_type_register_struct         (const char *name,
                                                         const DBusGTypeSpecializedStructVtable *vtable,
                                                         guint flags);

Defines a new struct container.

name :

The name of a new struct container

vtable :

the vtable defining the new container

flags :

As yet unused.