libamxc
1.10.3
C Generic Data Containers
|
Data Structures | |
struct | _amxc_var_type |
A variant type structure. More... | |
Typedefs | |
typedef int(* | amxc_var_new_fn_t) (amxc_var_t *const var) |
Variant type callback function prototype for initializing a variant of a certain type. More... | |
typedef void(* | amxc_var_free_fn_t) (amxc_var_t *const var) |
Variant type callback function prototype for freeing previous allocated memory. More... | |
typedef int(* | amxc_var_copy_fn_t) (amxc_var_t *const dst, const amxc_var_t *const src) |
Variant type callback function prototype for creating a copy. More... | |
typedef int(* | amxc_var_move_fn_t) (amxc_var_t *const dst, amxc_var_t *const src) |
Variant type callback function prototype for moving the content. More... | |
typedef int(* | amxc_var_convert_fn_t) (amxc_var_t *const dest, const amxc_var_t *const src) |
Variant type callback function prototype for dynamically converting one type to another. More... | |
typedef int(* | amxc_var_compare_fn_t) (const amxc_var_t *const var1, const amxc_var_t *const var2, int *const result) |
Variant type callback function prototype comparing two variants of the same type. More... | |
typedef amxc_var_t *(* | amxc_var_get_key_fn_t) (const amxc_var_t *const src, const char *const key, int flags) |
Variant type callback function prototype fetch part of variant by key. More... | |
typedef int(* | amxc_var_set_key_fn_t) (amxc_var_t *const dest, amxc_var_t *const src, const char *const key, int flags) |
Variant type callback function prototype set part of variant by key. More... | |
typedef amxc_var_t *(* | amxc_var_get_index_fn_t) (const amxc_var_t *const src, const int64_t index, int flags) |
Variant type callback function prototype fetch part of variant by index. More... | |
typedef int(* | amxc_var_set_index_fn_t) (amxc_var_t *const dest, amxc_var_t *const src, const int64_t index, int flags) |
Variant type callback function prototype set part of variant by index. More... | |
typedef struct _amxc_var_type | amxc_var_type_t |
A variant type structure. More... | |
Functions | |
uint32_t | amxc_var_register_type (amxc_var_type_t *const type) |
Register a new variant type. More... | |
int | amxc_var_unregister_type (amxc_var_type_t *const type) |
Unregisters an already registered variant type. More... | |
const char * | amxc_var_get_type_name_from_id (const uint32_t type_id) |
Get the type name. More... | |
uint32_t | amxc_var_get_type_id_from_name (const char *const name) |
Get the type id. More... | |
amxc_var_type_t * | amxc_var_get_type (unsigned int type_id) |
Get the type definition structure. More... | |
typedef int(* amxc_var_compare_fn_t) (const amxc_var_t *const var1, const amxc_var_t *const var2, int *const result) |
Variant type callback function prototype comparing two variants of the same type.
Definition at line 127 of file amxc_variant_type.h.
typedef int(* amxc_var_convert_fn_t) (amxc_var_t *const dest, const amxc_var_t *const src) |
Variant type callback function prototype for dynamically converting one type to another.
Definition at line 118 of file amxc_variant_type.h.
typedef int(* amxc_var_copy_fn_t) (amxc_var_t *const dst, const amxc_var_t *const src) |
Variant type callback function prototype for creating a copy.
Definition at line 101 of file amxc_variant_type.h.
typedef void(* amxc_var_free_fn_t) (amxc_var_t *const var) |
Variant type callback function prototype for freeing previous allocated memory.
Definition at line 94 of file amxc_variant_type.h.
typedef amxc_var_t*(* amxc_var_get_index_fn_t) (const amxc_var_t *const src, const int64_t index, int flags) |
Variant type callback function prototype fetch part of variant by index.
Definition at line 155 of file amxc_variant_type.h.
typedef amxc_var_t*(* amxc_var_get_key_fn_t) (const amxc_var_t *const src, const char *const key, int flags) |
Variant type callback function prototype fetch part of variant by key.
Definition at line 136 of file amxc_variant_type.h.
typedef int(* amxc_var_move_fn_t) (amxc_var_t *const dst, amxc_var_t *const src) |
Variant type callback function prototype for moving the content.
Definition at line 109 of file amxc_variant_type.h.
typedef int(* amxc_var_new_fn_t) (amxc_var_t *const var) |
Variant type callback function prototype for initializing a variant of a certain type.
Allocating memory to store the data is allowed, but a callback function for freeing the data must be provided, see amxc_var_free_fn_t
Definition at line 87 of file amxc_variant_type.h.
typedef int(* amxc_var_set_index_fn_t) (amxc_var_t *const dest, amxc_var_t *const src, const int64_t index, int flags) |
Variant type callback function prototype set part of variant by index.
Definition at line 164 of file amxc_variant_type.h.
typedef int(* amxc_var_set_key_fn_t) (amxc_var_t *const dest, amxc_var_t *const src, const char *const key, int flags) |
Variant type callback function prototype set part of variant by key.
Definition at line 145 of file amxc_variant_type.h.
typedef struct _amxc_var_type amxc_var_type_t |
A variant type structure.
New or application specific variants can be defined and registered. All function pointers are optional.
The member type_id and hit will be filled during registration and must never be changed.
A unique name must be provided.
The init function is called when the type of the variant is set see amxc_var_set_type. When the initialization is ok, return 0, otherwise return an error code.
The del function is called when the content of the variant must be cleared.
The copy function is called when a copy needs to be made.
The convert functions convert_from, convert_to are called when conversion from one type to another type is needed. These functions take two arguments, the destination variant and the source variant. These functions are used by amxc_var_convert. If the source variant type has a convert_to function, it will be called. If that conversion fails or the source variant type does not have a convert_to function, the convert_from function of the destination variant type is called. When conversion was successful, these functions must return 0, if conversion was impossible (not supported) or fails for any other reason an error code must be returned.
The compare function is called to compare two variants. Before calling the compare function, one of the variants will be converted to the same type as the other one. If none of the variants can be converted to the type of the other variant, the compare fails. The compare functions must set the result to a number < 0 if the left variant is smaller then the right variant, to a number > 0 if the left variant is bigger then the right variant, or to 0 if they are the same.
amxc_var_type_t* amxc_var_get_type | ( | unsigned int | type_id | ) |
Get the type definition structure.
Get the type definition structure.
type_id | the type id |
uint32_t amxc_var_get_type_id_from_name | ( | const char *const | name | ) |
Get the type id.
Using the type name look-up the type id and return it.
name | the name of the type |
Definition at line 234 of file amxc_variant_type.c.
const char* amxc_var_get_type_name_from_id | ( | const uint32_t | type_id | ) |
Get the type name.
Using the type id look-up the type name and return it.
type_id | the type id |
Definition at line 220 of file amxc_variant_type.c.
uint32_t amxc_var_register_type | ( | amxc_var_type_t *const | type | ) |
Register a new variant type.
After the type has been registered the fields type_id and hit will be filled. These values should not be changed.
The type can be used after registration.
Typically the registration is done in a constructor function.
type | pointer to a struct defining this type |
Definition at line 199 of file amxc_variant_type.c.
int amxc_var_unregister_type | ( | amxc_var_type_t *const | type | ) |
Unregisters an already registered variant type.
Only registered types can be unregistered.
After unregistering a type it can not be used again until it is registered again using amxc_var_register_type.
Typically unregistration is done in a destructor function.
type | pointer to a struct defining this type |
Definition at line 209 of file amxc_variant_type.c.