Function Macro

GObjectDEFINE_BOXED_TYPE

since: 2.26

Declaration

#define G_DEFINE_BOXED_TYPE (
  TypeName,
  type_name,
  copy_func,
  free_func
)

Description

A convenience macro for defining a new custom boxed type.

Using this macro is the recommended way of defining new custom boxed types, over calling g_boxed_type_register_static() directly. It defines a type_name_get_type() function which will return the newly defined GType, enabling lazy instantiation.

You might start by putting declarations in a header as follows:

#define MY_TYPE_STRUCT my_struct_get_type ()
GType my_struct_get_type (void) G_GNUC_CONST;

MyStruct *    my_struct_new (void);
void          my_struct_free (MyStruct *self);
MyStruct *    my_struct_copy (MyStruct *self);

And then use this macro and define your implementation in the source file as follows:

MyStruct *
my_struct_new (void)
{
  // ... your code to allocate a new MyStruct ...
}

void
my_struct_free (MyStruct *self)
{
  // ... your code to free a MyStruct ...
}

MyStruct *
my_struct_copy (MyStruct *self)
{
  // ... your code return a newly allocated copy of a MyStruct ...
}

G_DEFINE_BOXED_TYPE (MyStruct, my_struct, my_struct_copy, my_struct_free)

void
foo ()
{
  MyStruct *ms;

  ms = my_struct_new ();
  // ... your code ...
  my_struct_free (ms);
}

Available since: 2.26

This function is not directly available to language bindings.

Parameters

TypeName

Type: -

The name of the new type, in Camel case.

type_name

Type: -

The name of the new type, in lowercase, with words separated by _

copy_func

Type: -

The GBoxedCopyFunc for the new type.

free_func

Type: -

The GBoxedFreeFunc for the new type.