Type system

Type system — Type system.

Synopsis


#include <libhrel/types.h>


            HTypeInfo;
gpointer    (*HCloneFunc)                   (gconstpointer value);
gchar*      (*HStrFunc)                     (gconstpointer value);
void        h_type_init                     (void);
gboolean    h_type_known                    (GType type);
HTypeInfo*  h_type_get_info                 (GType type);
gboolean    h_type_add                      (GType type,
                                             const HTypeInfo *info);
gboolean    h_type_remove                   (GType type);
GCompareFunc h_type_compare_func            (GType type);
GHashFunc   h_type_hash_func                (GType type);
GEqualFunc  h_type_equal_func               (GType type);
GDestroyNotify h_type_free_func             (GType type);
gpointer    h_value_clone                   (GType type,
                                             gconstpointer value);
gchar*      h_value_str                     (GType type,
                                             gconstpointer value);
void        h_value_free                    (GType type,
                                             gpointer value);
gint        h_value_compare                 (GType type,
                                             gconstpointer value1,
                                             gconstpointer value2);
void        h_dummy                         (gconstpointer value);
gpointer    h_identity                      (gconstpointer value);

Description

Details

HTypeInfo

typedef struct {
  gsize          size;
  HCloneFunc     clone;
  GCompareFunc   compare;
  GEqualFunc     equal;
  GHashFunc      hash;
  GDestroyNotify free;
  HStrFunc       str;
} HTypeInfo;

gsize size; size in bytes
HCloneFunc clone; clone function
GCompareFunc compare; comparator
GEqualFunc equal; equality function
GHashFunc hash; hash function
GDestroyNotify free; destructor
HStrFunc str; string function

HCloneFunc ()

gpointer    (*HCloneFunc)                   (gconstpointer value);

Returns a copy of value

value : value
Returns : copy

HStrFunc ()

gchar*      (*HStrFunc)                     (gconstpointer value);

Returns the pretty string representation of value.

value : value
Returns : pretty string

h_type_init ()

void        h_type_init                     (void);

Initializes the type system. It is safe to call this multiple times.


h_type_known ()

gboolean    h_type_known                    (GType type);

Checks whether type is known to the type system.

type : type ID
Returns : TRUE if yes, FALSE if no

h_type_get_info ()

HTypeInfo*  h_type_get_info                 (GType type);

Returns information on type.

type : type ID
Returns : type information

h_type_add ()

gboolean    h_type_add                      (GType type,
                                             const HTypeInfo *info);

Adds a new type to the system.

type : type ID
info : information for type
Returns : TRUE if successful, FALSE if type is already known

h_type_remove ()

gboolean    h_type_remove                   (GType type);

Removes type from the system.

type : type ID
Returns :

h_type_compare_func ()

GCompareFunc h_type_compare_func            (GType type);

Returns the comparator for type.

type : type ID
Returns : comparator, or NULL if type is unknown

h_type_hash_func ()

GHashFunc   h_type_hash_func                (GType type);

Returns the hash function for type.

type : type ID
Returns : hash function, or NULL if type is unknown

h_type_equal_func ()

GEqualFunc  h_type_equal_func               (GType type);

Returns the equality function for type.

type : type ID
Returns : equality function, or NULL if type is unknown

h_type_free_func ()

GDestroyNotify h_type_free_func             (GType type);

Returns the destructor for type.

type : type ID
Returns : destructor, or NULL if type is unknown

h_value_clone ()

gpointer    h_value_clone                   (GType type,
                                             gconstpointer value);

Returns a copy of value.

type : type of value
value : a value
Returns : copy

h_value_str ()

gchar*      h_value_str                     (GType type,
                                             gconstpointer value);

Returns the pretty string representation of value.

type : type of value
value : a value
Returns : pretty string representation

h_value_free ()

void        h_value_free                    (GType type,
                                             gpointer value);

Frees the memory allocated to value.

type : type of value
value : a value

h_value_compare ()

gint        h_value_compare                 (GType type,
                                             gconstpointer value1,
                                             gconstpointer value2);

Compares value1 and value2.

type : type of value1 and value2
value1 : left operand
value2 : right operand
Returns : -1 if value1 is greater, 1 if value2 is greater, 0 if equal

h_dummy ()

void        h_dummy                         (gconstpointer value);

A dummy function that does nothing.

value : value

h_identity ()

gpointer    h_identity                      (gconstpointer value);

Returns value.

value : value
Returns : value