libamxc  1.10.3
C Generic Data Containers
variant
Collaboration diagram for variant:

Modules

 variant type ids
 
 variant flags
 
 variant utils
 
 variant type helper functions
 Variant type specific helper functions.
 

Data Structures

struct  _amxc_var
 The variant struct definition. More...
 

Macros

#define amxc_var_set(type, var, data)   amxc_var_set_ ## type(var, data)
 Convenience macro for setting a value in a variant. More...
 
#define amxc_var_add(type, var, data)   amxc_var_add_new_ ## type(var, data)
 Convenience macro for adding a variant to composite variant type. More...
 
#define amxc_var_add_key(type, var, key, data)   amxc_var_add_new_key_ ## type(var, key, data)
 Convenience macro for adding a variant to composite variant type. More...
 
#define amxc_var_dyncast(type, var)   amxc_var_get_ ## type(var)
 Dynamic cast a variant to a certain type. More...
 
#define amxc_var_constcast(type, var)   amxc_var_get_const_ ## type(var)
 Takes the content from a variant. More...
 
#define amxc_var_take(type, var)   amxc_var_take_ ## type(var)
 Takes the content from a variant. More...
 
#define amxc_var_push(type, var, val)   amxc_var_push_ ## type(var, val)
 Pushes a value into the variant. More...
 
#define amxc_var_for_each(var, var_list)
 When the variant is a htable or list variant, iterates over the variants in the htable or list. More...
 
#define amxc_var_for_each_reverse(var, var_list)
 When the variant is a htable or list variant, iterates over the variants in reverse order. More...
 

Typedefs

typedef struct _amxc_var amxc_var_t
 The variant struct definition. More...
 

Functions

int amxc_var_new (amxc_var_t **var)
 Allocates a variant and initializes it to the null variant type. More...
 
void amxc_var_delete (amxc_var_t **var)
 Frees the previously allocated variant. More...
 
int amxc_var_init (amxc_var_t *const var)
 Initializes a variant. More...
 
void amxc_var_clean (amxc_var_t *const var)
 Clean-up and reset variant. More...
 
int amxc_var_set_type (amxc_var_t *const var, const uint32_t type)
 Change the variant data type. More...
 
int amxc_var_copy (amxc_var_t *const dest, const amxc_var_t *const src)
 Copy the type and data from one variant (source) in another variant (destination). More...
 
int amxc_var_move (amxc_var_t *const dest, amxc_var_t *const src)
 Moves the type and data from one variant (source) in another variant (destination). More...
 
int amxc_var_convert (amxc_var_t *const dest, const amxc_var_t *src, const uint32_t type_id)
 Converts one variant (source) to another variant(destination) using the specified variant type id. More...
 
int amxc_var_cast (amxc_var_t *const var, const uint32_t type_id)
 Casts the variant to another variant type id. More...
 
int amxc_var_compare (const amxc_var_t *const var1, const amxc_var_t *const var2, int *const result)
 Compares two variants. More...
 
AMXC_INLINE void amxc_var_take_it (amxc_var_t *const var)
 Removes the variant for a llist and/or a htable. More...
 
amxc_var_tamxc_var_get_key (const amxc_var_t *const var, const char *const key, const int flags)
 Get a reference to a part of composed variant using a key. More...
 
int amxc_var_set_key (amxc_var_t *const var, const char *const key, amxc_var_t *data, const int flags)
 Sets a part of composed variant using a key. More...
 
AMXC_INLINE amxc_var_tamxc_var_take_key (amxc_var_t *const var, const char *const key)
 Get a reference to a part of composed variant using a key and removes it from the composed variant. More...
 
amxc_var_tamxc_var_get_index (const amxc_var_t *const var, const int64_t index, const int flags)
 Get a reference to a part of composed variant using an index. More...
 
int amxc_var_set_index (amxc_var_t *const var, const int64_t index, amxc_var_t *data, const int flags)
 Set a part of composed variant using an index. More...
 
AMXC_INLINE amxc_var_tamxc_var_take_index (amxc_var_t *const var, const int64_t index)
 Get a reference to a part of composed variant using an index and removes it from the composed variant. More...
 
amxc_var_tamxc_var_add_new_key (amxc_var_t *const var, const char *key)
 Adds a new variant with a key to a composite variant. More...
 
amxc_var_tamxc_var_add_new (amxc_var_t *const var)
 Adds a new variant to a composite variant. More...
 
amxc_var_tamxc_var_get_path (const amxc_var_t *const var, const char *const path, const int flags)
 Retrieves the variant at the given path of a composite variant. More...
 
amxc_var_tamxc_var_get_pathf (const amxc_var_t *const var, const int flags, const char *const fmt,...) __attribute__((format(printf
 Retrieves the variant at the given path of a composite variant. More...
 
amxc_var_t int amxc_var_set_path (amxc_var_t *const var, const char *const path, amxc_var_t *data, const int flags)
 Sets the variant at the given path of a composite variant. More...
 
int amxc_var_set_pathf (amxc_var_t *const var, amxc_var_t *data, const int flags, const char *const fmt,...) __attribute__((format(printf
 Sets the variant at the given path of a composite variant. More...
 
int amxc_var_tamxc_var_get_first (const amxc_var_t *const var)
 Gets the first variant in a htable or list variant. More...
 
amxc_var_tamxc_var_get_last (const amxc_var_t *const var)
 Gets the last variant in a htable or list variant. More...
 
amxc_var_tamxc_var_get_next (const amxc_var_t *const var)
 Gets the next variant. More...
 
amxc_var_tamxc_var_get_previous (const amxc_var_t *const var)
 Gets the previous variant. More...
 
amxc_var_tamxc_var_get_parent (const amxc_var_t *const var)
 Gets the containing variant. More...
 
const char * amxc_var_key (const amxc_var_t *const var)
 Gets the key, with which the variant is stored in a htable variant. More...
 
uint32_t amxc_var_type_of (const amxc_var_t *const var)
 Gets the variant type id of a variant. More...
 
const char * amxc_var_type_name_of (const amxc_var_t *const var)
 Gets the variant type name of a variant. More...
 
AMXC_INLINE bool amxc_var_is_null (const amxc_var_t *const var)
 Checks if the given variant is of the "null" type. More...
 

Detailed Description

A variant is a generic data container and can contain primitive types or composite types.

Variant Primitive Types

Variant Composite Types

Macro Definition Documentation

◆ amxc_var_add

#define amxc_var_add (   type,
  var,
  data 
)    amxc_var_add_new_ ## type(var, data)

Convenience macro for adding a variant to composite variant type.

Macro expands to amxc_var_add_new_<TYPE>>(var, data)

Definition at line 618 of file amxc_variant.h.

◆ amxc_var_add_key

#define amxc_var_add_key (   type,
  var,
  key,
  data 
)    amxc_var_add_new_key_ ## type(var, key, data)

Convenience macro for adding a variant to composite variant type.

Macro expands to amxc_var_add_new_key_<TYPE>>(var, key, data)

Definition at line 627 of file amxc_variant.h.

◆ amxc_var_constcast

#define amxc_var_constcast (   type,
  var 
)    amxc_var_get_const_ ## type(var)

Takes the content from a variant.

If the given variant is not of the type specified, it will return a default value, NULL for pointers, 0 for integers or double, false for boolean. Only works on variants containing pointer types.

The type of the variant can be queried using amxc_var_type_of

Warning
No conversions are done using this macro. If the returned value is not what you expect, you can try amxc_var_dyncast. If this works, the original variant type is different from your requested type in amxc_var_constcast.
Note
When pointers are returned, the pointers are refering to the data in the variant and must not be freed.
This macro expands to amxc_var_get_const_<TYPE>(var) The default variant type implementation provides these functions:

Custom variant type implementations may implement a amxc_var_get_const_<CUSTOM_TYPE> function, see the documentation of the custom types for more information.

Definition at line 722 of file amxc_variant.h.

◆ amxc_var_dyncast

#define amxc_var_dyncast (   type,
  var 
)    amxc_var_get_ ## type(var)

Dynamic cast a variant to a certain type.

Conversion is applied and a copy is given. If a pointer is returned, the allocated memory must be freed. If a value is returned, there is no memory allocation.

When the requested type is not the same type as the type of the variant the value in the variant is converted to the requested type. If the conversion is not possible or fails, a default value is returned.

It is possible that memory is allocated to be able to store the requested type, this is only the case when a pointer is returned. For primitive types like uint32_t, bool, double, ... no memory is allocated, the value is returned.

When a pointer is returned it must be freed.

Note
This macro expands to amxc_var_get_<TYPE>(var) The default variant type implementation provides these functions:

Custom variant type implementations may implement a amxc_var_get_<CUSTOM_TYPE> function, see the documentation of the custom types for more information.

Definition at line 678 of file amxc_variant.h.

◆ amxc_var_for_each

#define amxc_var_for_each (   var,
  var_list 
)
Value:
for(amxc_var_t* var = amxc_var_get_first(var_list), \
* var ## _next = amxc_var_get_next(var); \
var; \
var = var ## _next, \
var ## _next = amxc_var_get_next(var))
amxc_var_t * amxc_var_get_next(const amxc_var_t *const var)
Gets the next variant.
Definition: amxc_variant.c:764
int amxc_var_t * amxc_var_get_first(const amxc_var_t *const var)
Gets the first variant in a htable or list variant.
Definition: amxc_variant.c:712
The variant struct definition.
Definition: amxc_variant.h:861
static amxc_var_t * var
Definition: test_issue_58.c:77

When the variant is a htable or list variant, iterates over the variants in the htable or list.

When the variant is not of a htable or list type, this macro will do nothing

It is save to delete the current variant in the loop.

Warning
When a variant is contained in a list and in a htable, the next variant will be the next in the htable. If you want to iterate over all variants in a variant list and all or some of variants are also in a htable, it is better to cast the container variant to a llist using amxc_var_constcast and use amxc_llist_for_each to iterate over all variants in the list.

Definition at line 819 of file amxc_variant.h.

◆ amxc_var_for_each_reverse

#define amxc_var_for_each_reverse (   var,
  var_list 
)
Value:
for(amxc_var_t* var = amxc_var_get_last(var_list), \
* var ## _prev = amxc_var_get_previous(var); \
var; \
var = var ## _prev, \
var ## _prev = amxc_var_get_previous(var))
amxc_var_t * amxc_var_get_last(const amxc_var_t *const var)
Gets the last variant in a htable or list variant.
Definition: amxc_variant.c:738
amxc_var_t * amxc_var_get_previous(const amxc_var_t *const var)
Gets the previous variant.
Definition: amxc_variant.c:783

When the variant is a htable or list variant, iterates over the variants in reverse order.

When the variant is not of a htable or list type, this macro will do nothing

It is save to delete the current variant in the loop.

Warning
When a variant is contained in a list and in a htable, the previous variant will be the previous in the htable. If you want to iterate over all variants in a variant list and all or some of variants are also in a htable, it is better to cast the container variant to a llist using amxc_var_constcast and use amxc_llist_for_each_reverse to iterate over all variants in the list.

Definition at line 843 of file amxc_variant.h.

◆ amxc_var_push

#define amxc_var_push (   type,
  var,
  val 
)    amxc_var_push_ ## type(var, val)

Pushes a value into the variant.

Only works on variants containing pointer types.

No conversions are applied, no copies are done. The ownership of the pointer is transferred to the variant.

Note
Macro expands to amxc_var_push_<TYPE>(var, val) The default variant type implementation provides these functions:

Custom variant type implementations may implement a amxc_var_push_<CUSTOM_TYPE> function, see the documentation of the custom types for more information.

Definition at line 780 of file amxc_variant.h.

◆ amxc_var_set

#define amxc_var_set (   type,
  var,
  data 
)    amxc_var_set_ ## type(var, data)

Convenience macro for setting a value in a variant.

Macro expands to amxc_var_set_<TYPE>>(var, data)

Definition at line 609 of file amxc_variant.h.

◆ amxc_var_take

#define amxc_var_take (   type,
  var 
)    amxc_var_take_ ## type(var)

Takes the content from a variant.

If the given variant is not of the type specified, it will return NULL. Only works on variants containing pointer types.

No conversions are applied, no copies are done. The pointer returned is the pointer in the variant. The variant is reset to the "null" variant.

Ownership of the pointer is transferred to the caller. When not needed anymore the memory must be freed.

Note
This macro expands to amxc_var_take_<TYPE>(var) The default variant type implementation provides these functions:

Custom variant type implementations may implement a amxc_var_take_<CUSTOM_TYPE> function, see the documentation of the custom types for more information.

Definition at line 757 of file amxc_variant.h.

Typedef Documentation

◆ amxc_var_t

typedef struct _amxc_var amxc_var_t

The variant struct definition.

A variant is a tagged union, which can be added to a linked list or to a hash table as value.

Which field of the union is valid is depending of the type id field in the struct.

Function Documentation

◆ amxc_var_add_new()

amxc_var_t* amxc_var_add_new ( amxc_var_t *const  var)

Adds a new variant to a composite variant.

The type of the given variant must be of a composite type and must at least support the get_index and set_index functions. A new variant object is added to the composite variant. The new variant is of the null-type.

Parameters
varpointer to a variant struct
Returns
Pointer to the new added variant or NULL when it was not possible to add a new key to the variant.

Definition at line 551 of file amxc_variant.c.

551  {
552  amxc_var_t* data = NULL;
553  amxc_var_type_t* var_type = NULL;
554  int retval = -1;
555  when_null(var, exit);
556 
557  var_type = amxc_var_get_type(var->type_id);
558  when_null(var_type, exit);
559 
560  when_failed(amxc_var_new(&data), exit);
561  retval = var_type->set_index != NULL ?
562  var_type->set_index(var, data, -1, AMXC_VAR_FLAG_DEFAULT) :
563  -1;
564 
565  if(retval != 0) {
567  }
568 
569 exit:
570  return data;
571 }
#define when_failed(x, l)
Definition: amxc_macros.h:142
#define when_null(x, l)
Definition: amxc_macros.h:126
#define AMXC_VAR_FLAG_DEFAULT
The default flag, do not copy, use variant as is.
Definition: amxc_variant.h:392
amxc_var_type_t * amxc_var_get_type(unsigned int type_id)
Get the type definition structure.
int amxc_var_new(amxc_var_t **var)
Allocates a variant and initializes it to the null variant type.
Definition: amxc_variant.c:194
void amxc_var_delete(amxc_var_t **var)
Frees the previously allocated variant.
Definition: amxc_variant.c:207
A variant type structure.
amxc_var_set_index_fn_t set_index
uint32_t type_id
Definition: amxc_variant.h:864
char data[]

◆ amxc_var_add_new_key()

amxc_var_t* amxc_var_add_new_key ( amxc_var_t *const  var,
const char *  key 
)

Adds a new variant with a key to a composite variant.

The type of the given variant must be of a composite type and must at least support the get_key and set_key functions. A new variant object is added to the composite variant. The new variant is of the null-type.

Parameters
varpointer to a variant struct to which a new variant will be added.
keythe new key that needs to be added
Returns
Pointer to the new added variant or NULL when it was not possible to add a new key to the variant.

Definition at line 526 of file amxc_variant.c.

527  {
528  amxc_var_t* data = NULL;
529  amxc_var_type_t* var_type = NULL;
530  int retval = -1;
531  when_null(var, exit);
532  when_null(key, exit);
533  when_true(*key == 0, exit);
534 
535  var_type = amxc_var_get_type(var->type_id);
536  when_null(var_type, exit);
537 
538  when_failed(amxc_var_new(&data), exit);
539  retval = var_type->set_key != NULL ?
540  var_type->set_key(var, data, key, AMXC_VAR_FLAG_DEFAULT) :
541  -1;
542 
543  if(retval != 0) {
545  }
546 
547 exit:
548  return data;
549 }
#define when_true(x, l)
Definition: amxc_macros.h:134
amxc_var_set_key_fn_t set_key

◆ amxc_var_cast()

int amxc_var_cast ( amxc_var_t *const  var,
const uint32_t  type_id 
)

Casts the variant to another variant type id.

The content of the variant is converted to the requested type. If AMXC_VAR_ID_ANY is given, automatic conversion is applied. Not all types support automatic type conversion.

If no type is found with the given type id, the conversion fails. If no conversion methods are available the conversion fails.

If type conversion fails or is not supported the variant is unchanged

Parameters
varpointer to a variant struct
type_idthe variant type id to which the variant must be converted
Returns
When the conversion fails, this functions returns a none 0 value and the variant is not changed.

Definition at line 372 of file amxc_variant.c.

373  {
374  int retval = -1;
375  amxc_var_t intermediate;
376 
377  amxc_var_init(&intermediate);
378  when_null(var, exit);
379 
380  if(var->type_id == type_id) {
381  retval = 0;
382  goto exit;
383  }
384 
385  retval = amxc_var_convert(&intermediate, var, type_id);
386  when_failed(retval, exit);
387 
388  if(var->type_id != intermediate.type_id) {
389  amxc_var_move(var, &intermediate);
390  }
391 
392 exit:
393  amxc_var_clean(&intermediate);
394  return retval;
395 }
int amxc_var_move(amxc_var_t *const dest, amxc_var_t *const src)
Moves the type and data from one variant (source) in another variant (destination).
Definition: amxc_variant.c:308
int amxc_var_init(amxc_var_t *const var)
Initializes a variant.
Definition: amxc_variant.c:223
void amxc_var_clean(amxc_var_t *const var)
Clean-up and reset variant.
Definition: amxc_variant.c:237
int amxc_var_convert(amxc_var_t *const dest, const amxc_var_t *const src, uint32_t type_id)
Converts one variant (source) to another variant(destination) using the specified variant type id.
Definition: amxc_variant.c:333

◆ amxc_var_clean()

void amxc_var_clean ( amxc_var_t *const  var)

Clean-up and reset variant.

If memory was allocated to contain the data for the variant, it will be freed. The variant is reset to the null variant.

Parameters
varpointer to a variant structure.

Definition at line 237 of file amxc_variant.c.

237  {
238  amxc_var_type_t* var_type = NULL;
239  when_null(var, exit);
240 
241  var_type = amxc_var_get_type(var->type_id);
242  // ISSUE: No type available anymore, probably unregister,
243  // dangling variant !!
244  if(var_type == NULL) {
245  goto clean;
246  }
247 
248  if((var_type != NULL) &&
249  (var_type->del != NULL)) {
250  var_type->del(var);
251  }
252 
253 clean:
254  var->type_id = 0;
255  var->data.data = NULL;
256 
257 exit:
258  return;
259 }
amxc_var_free_fn_t del
void * data
Definition: amxc_variant.h:883

◆ amxc_var_compare()

int amxc_var_compare ( const amxc_var_t *const  var1,
const amxc_var_t *const  var2,
int *const  result 
)

Compares two variants.

Tries to compare the data of two variants. If it is not possible to compare the two variants, the function fails and returns a non 0 value.

The comparison result is put in result:

  • when 0: var1 == var2
  • when > 0: var1 > var2
  • when < 0: var1 < var2
Parameters
var1pointer to variant structure, the left value
var2pointer to variant structure, the right value
resultpointer to integer, will contain comparison result
Returns
if it is not possible to compare the variants (depends on the types), this function returns none 0.

Definition at line 397 of file amxc_variant.c.

399  {
400  int retval = -1;
401  amxc_var_type_t* var1_type = NULL;
402  amxc_var_type_t* var2_type = NULL;
403  amxc_var_t converted_var;
404  amxc_var_init(&converted_var);
405  when_null(result, exit);
406 
407  *result = 0;
408 
409  if((var1 == NULL) && (var2 == NULL)) {
410  retval = 0;
411  goto exit;
412  }
413 
414  if((var1 != NULL) && (var2 == NULL)) {
415  retval = 0;
416  *result = 1;
417  goto exit;
418  }
419 
420  if(var1 == NULL) {
421  retval = 0;
422  *result = -1;
423  goto exit;
424  }
425 
426  var1_type = amxc_var_get_type(var1->type_id);
427  var2_type = amxc_var_get_type(var2->type_id);
428 
429  when_null(var1_type, exit);
430  when_null(var2_type, exit);
431 
432  if((var1_type->compare != NULL) &&
433  ( amxc_var_convert(&converted_var,
434  var2,
435  amxc_var_type_of(var1)) == 0)) {
436  retval = var1_type->compare(var1, &converted_var, result);
437  } else if((var2_type->compare != NULL) &&
438  ( amxc_var_convert(&converted_var,
439  var1,
440  amxc_var_type_of(var2)) == 0)) {
441  retval = var2_type->compare(&converted_var, var2, result);
442  }
443 
444 exit:
445  amxc_var_clean(&converted_var);
446  return retval;
447 }
uint32_t amxc_var_type_of(const amxc_var_t *const var)
Gets the variant type id of a variant.
Definition: amxc_variant.c:668
amxc_var_compare_fn_t compare

◆ amxc_var_convert()

int amxc_var_convert ( amxc_var_t *const  dest,
const amxc_var_t src,
const uint32_t  type_id 
)

Converts one variant (source) to another variant(destination) using the specified variant type id.

If no type is found with the given type id, the conversion fails. If no conversion methods are available the conversion fails.

If the source variant type has a convert to method, this is called first. If that function fails to convert, the convert from method of the destination variant type is called.

If conversion fails or is not supported the destination variant is reset to the null variant.

Parameters
destpointer to a variant struct, the destination
srcpointer to a variant struct, the source
type_idthe variant type id to which the source data needs to be converted to
Returns
When the conversion fails, this functions returns a none 0 value and the destination variant is reset to a null variant.

Definition at line 333 of file amxc_variant.c.

335  {
336  int retval = -1;
337  amxc_var_type_t* src_type = NULL;
338  amxc_var_type_t* dst_type = NULL;
339  when_null(dest, exit);
340  when_null(src, exit);
341 
342  src_type = amxc_var_get_type(src->type_id);
343  when_null(src_type, exit);
344 
345  if(type_id != AMXC_VAR_ID_ANY) {
346  dst_type = amxc_var_get_type(type_id);
347  when_null(dst_type, exit);
348  when_failed(amxc_var_set_type(dest, type_id), exit);
349  } else {
351  dest->type_id = AMXC_VAR_ID_ANY;
352  }
353 
354  // try to convert src to dst using covert_to function from src type
355  retval = src_type->convert_to != NULL ?
356  src_type->convert_to(dest, src) : -1;
357  when_true(retval == 0, exit);
358 
359  if(type_id != AMXC_VAR_ID_ANY) {
360  // try to convert src to dst using covert_from function from dest type
361  retval = dst_type->convert_from != NULL ?
362  dst_type->convert_from(dest, src) : -1;
363  }
364 
365 exit:
366  if(retval != 0) {
367  amxc_var_clean(dest);
368  }
369  return retval;
370 }
#define AMXC_VAR_ID_NULL
Null variant type id (aka void)
Definition: amxc_variant.h:128
#define AMXC_VAR_ID_ANY
Special variant id, typically used in cast or conversion functions.
Definition: amxc_variant.h:247
int amxc_var_set_type(amxc_var_t *const var, const uint32_t type)
Change the variant data type.
Definition: amxc_variant.c:261
amxc_var_convert_fn_t convert_from
amxc_var_convert_fn_t convert_to

◆ amxc_var_copy()

int amxc_var_copy ( amxc_var_t *const  dest,
const amxc_var_t *const  src 
)

Copy the type and data from one variant (source) in another variant (destination).

The destination variant is first set to the same type as the source variant using amxc_var_set_type and then the data is copied.

The content of both variants after a copy is identical. If the copy fails, the destination variant is a null variant.

The list and htable iterators are not copied.

Parameters
destpointer to variant struct, the destination
srcpointer to variant struct, the source
Returns
When the copy fails, this functions returns a none 0 value and the destination variant is reset to a null variant.

Definition at line 285 of file amxc_variant.c.

285  {
286  int retval = -1;
287  amxc_var_type_t* type = NULL;
288  when_null(dest, exit);
289  when_null(src, exit);
290 
291  // reset destinationn variant
292  amxc_var_clean(dest);
293  // get the type function pointers of the src
294  type = amxc_var_get_type(src->type_id);
295  when_null(type, exit);
296  when_null(type->copy, exit);
297 
298  when_failed(amxc_var_set_type(dest, src->type_id), exit);
299  retval = type->copy(dest, src);
300  if(retval != 0) {
301  amxc_var_clean(dest);
302  }
303 
304 exit:
305  return retval;
306 }
amxc_var_copy_fn_t copy

◆ amxc_var_delete()

void amxc_var_delete ( amxc_var_t **  var)

Frees the previously allocated variant.

Frees the allocated memory and sets the pointer to NULL.

Note
Only call this function for variants that are allocated on the heap using amxc_var_new
Parameters
vara pointer to the location where the pointer to the variant is stored

Definition at line 207 of file amxc_variant.c.

207  {
208  when_null(var, exit);
209 
210  if(*var != NULL) {
212  amxc_llist_it_clean(&((*var)->lit), NULL);
213  amxc_htable_it_clean(&((*var)->hit), NULL);
214  }
215 
216  free(*var);
217  *var = NULL;
218 
219 exit:
220  return;
221 }
void amxc_htable_it_clean(amxc_htable_it_t *const it, amxc_htable_it_delete_t func)
Removes the iterator from the htable and frees allocated memory.
void amxc_llist_it_clean(amxc_llist_it_t *const it, amxc_llist_it_delete_t func)
Removes the iterator from the list and frees allocated memory.

◆ amxc_var_get_first()

int amxc_var_t* amxc_var_get_first ( const amxc_var_t *const  var)

Gets the first variant in a htable or list variant.

Returns the first variant contained in composite htable or list variant.

If the provided variant pointer is not of a htable or list type, this function will return NULL.

If the provided htable or list variant is empty a NULL pointer is returned.

Parameters
varpointer to a variant struct
Returns
The first variant in the htable or list variant or NULL.

Definition at line 712 of file amxc_variant.c.

712  {
713  amxc_var_t* first = NULL;
714 
715  when_null(var, exit);
716 
717  switch(amxc_var_type_of(var)) {
718  case AMXC_VAR_ID_HTABLE: {
720  when_null(it, exit);
722  }
723  break;
724  case AMXC_VAR_ID_LIST: {
726  when_null(it, exit);
728  }
729  break;
730  default:
731  break;
732  }
733 
734 exit:
735  return first;
736 }
#define amxc_var_from_htable_it(ht_it)
Get the variant pointer from an amxc htable iterator.
Definition: amxc_variant.h:790
#define amxc_var_from_llist_it(ll_it)
Get the variant pointer from an amxc linked list iterator.
Definition: amxc_variant.h:799
amxc_htable_it_t * amxc_htable_get_first(const amxc_htable_t *const htable)
Gets the first item stored in the table.
Definition: amxc_htable.c:313
AMXC_INLINE amxc_llist_it_t * amxc_llist_get_first(const amxc_llist_t *const llist)
Gets the first item of the linked list.
Definition: amxc_llist.h:713
#define AMXC_VAR_ID_LIST
Ambiorix Linked List variant id.
Definition: amxc_variant.h:206
#define AMXC_VAR_ID_HTABLE
Ambiorix Hash Table variant id.
Definition: amxc_variant.h:212
The hash table iterator structure.
Definition: amxc_htable.h:138
The linked list iterator structure.
Definition: amxc_llist.h:215
static amxc_htable_it_t it[2000]
static amxc_var_t * first
Definition: test_issue_59.c:81

◆ amxc_var_get_index()

amxc_var_t* amxc_var_get_index ( const amxc_var_t *const  var,
const int64_t  index,
const int  flags 
)

Get a reference to a part of composed variant using an index.

If the data contained in the variant is composed of different parts and some or all parts can be identified with an index, a reference to such part can be retrieved with this function.

Parameters
varpointer to variant structure, containing the composed data
indexthe index
flagscan be one of AMXC_VAR_FLAG_DEFAULT, AMXC_VAR_FLAG_COPY
Returns
When no part is found with the given key a null pointer is returned. The pointer returned is pointing to a real part.

Definition at line 489 of file amxc_variant.c.

491  {
492 
493  amxc_var_t* retval = NULL;
494  amxc_var_type_t* var_type = NULL;
495  when_null(var, exit);
496 
497  var_type = amxc_var_get_type(var->type_id);
498  when_null(var_type, exit);
499 
500  retval = var_type->get_index != NULL ?
501  var_type->get_index(var, index, flags) : NULL;
502 
503 exit:
504  return retval;
505 }
amxc_var_get_index_fn_t get_index

◆ amxc_var_get_key()

amxc_var_t* amxc_var_get_key ( const amxc_var_t *const  var,
const char *const  key,
const int  flags 
)

Get a reference to a part of composed variant using a key.

If the data contained in the variant is composed of different parts and some or all parts can be identified with a key, a reference to such part can be retrieved with this function.

Parameters
varpointer to variant structure, containing the composed data
keystring containing the key
flagscan be one of AMXC_VAR_FLAG_DEFAULT, AMXC_VAR_FLAG_COPY
Returns
When no part is found with the given key a null pointer is returned. The pointer returned is pointing to a real part and should not be freed unless the variant part must be removed from the composed variant.

Definition at line 449 of file amxc_variant.c.

451  {
452  amxc_var_t* retval = NULL;
453  amxc_var_type_t* var_type = NULL;
454  when_null(var, exit);
455  when_null(key, exit);
456  when_true(*key == 0, exit);
457 
458  var_type = amxc_var_get_type(var->type_id);
459  when_null(var_type, exit);
460 
461  retval = var_type->get_key != NULL ?
462  var_type->get_key(var, key, flags) : NULL;
463 
464 exit:
465  return retval;
466 }
amxc_var_get_key_fn_t get_key

◆ amxc_var_get_last()

amxc_var_t* amxc_var_get_last ( const amxc_var_t *const  var)

Gets the last variant in a htable or list variant.

Returns the last variant contained in composite htable or list variant.

If the provided variant pointer is not of a htable or list type, this function will return NULL.

If the provided htable or list variant is empty a NULL pointer is returned.

Parameters
varpointer to a variant struct
Returns
The first variant in the htable or list variant or NULL.

Definition at line 738 of file amxc_variant.c.

738  {
739  amxc_var_t* last = NULL;
740 
741  when_null(var, exit);
742 
743  switch(amxc_var_type_of(var)) {
744  case AMXC_VAR_ID_HTABLE: {
746  when_null(it, exit);
747  last = amxc_var_from_htable_it(it);
748  }
749  break;
750  case AMXC_VAR_ID_LIST: {
752  when_null(it, exit);
753  last = amxc_var_from_llist_it(it);
754  }
755  break;
756  default:
757  break;
758  }
759 
760 exit:
761  return last;
762 }
amxc_htable_it_t * amxc_htable_get_last(const amxc_htable_t *const htable)
Gets the last item stored in the table.
Definition: amxc_htable.c:326
AMXC_INLINE amxc_llist_it_t * amxc_llist_get_last(const amxc_llist_t *const llist)
Gets the last item of the linked list.
Definition: amxc_llist.h:732

◆ amxc_var_get_next()

amxc_var_t* amxc_var_get_next ( const amxc_var_t *const  var)

Gets the next variant.

If the variant is contained in a htable or list variant fetches the pointer to the next variant.

If the provided variant pointer is not in a htable or list variant, this function will return NULL.

If the provided variant is the last in the htable or list a NULL pointer is returned.

If the provided variant is in a list and in a htable, the next variant in the htable will be returned.

Parameters
varpointer to a variant struct
Returns
The next variant in the htable or list variant or NULL

Definition at line 764 of file amxc_variant.c.

764  {
765  amxc_var_t* next = NULL;
766 
767  when_null(var, exit);
768 
769  if(var->hit.ait != NULL) {
771  when_null(it, exit);
772  next = amxc_var_from_htable_it(it);
773  } else if(var->lit.llist != NULL) {
775  when_null(it, exit);
776  next = amxc_var_from_llist_it(it);
777  }
778 
779 exit:
780  return next;
781 }
amxc_htable_it_t * amxc_htable_it_get_next(const amxc_htable_it_t *const reference)
Gets the next iterator in the hash table.
AMXC_INLINE amxc_llist_it_t * amxc_llist_it_get_next(const amxc_llist_it_t *const reference)
Gets the next iterator in the list.
Definition: amxc_llist.h:824
amxc_array_it_t * ait
Definition: amxc_htable.h:139
struct _amxc_llist * llist
Definition: amxc_llist.h:220
amxc_llist_it_t lit
Definition: amxc_variant.h:862
amxc_htable_it_t hit
Definition: amxc_variant.h:863

◆ amxc_var_get_parent()

amxc_var_t* amxc_var_get_parent ( const amxc_var_t *const  var)

Gets the containing variant.

If the variant is contained in a htable or list variant fetches the pointer to the container variant.

If the provided variant pointer is not in a htable or list variant, this function will return NULL.

If the provided variant is contained in a htable and in a list variant, the pointer to the containing htable variant is returned.

Parameters
varpointer to a variant struct
Returns
The pointer to the containing variant or NULL

Definition at line 802 of file amxc_variant.c.

802  {
803  amxc_var_t* parent = NULL;
804 
805  when_null(var, exit);
806 
807  if(var->hit.ait != NULL) {
808  if(var->hit.ait->array != NULL) {
810  parent = amxc_container_of(ptable, amxc_var_t, data);
811  }
812  } else if(var->lit.llist != NULL) {
813  amxc_llist_t* plist = var->lit.llist;
814  parent = amxc_container_of(plist, amxc_var_t, data);
815  }
816 
817 exit:
818  return parent;
819 }
#define amxc_container_of(addr, type, member)
Calculates the address of the containing structure.
Definition: amxc_common.h:83
amxc_array_t * array
Definition: amxc_array.h:175
The hash table structure.
Definition: amxc_htable.h:175
The linked list structure.
Definition: amxc_llist.h:228

◆ amxc_var_get_path()

amxc_var_t* amxc_var_get_path ( const amxc_var_t *const  var,
const char *const  path,
const int  flags 
)

Retrieves the variant at the given path of a composite variant.

The type of the given variant is a composite type and some of the parts are composite variants as well, this function makes it easy to retrieve a variant deep down in the composite variant structure. The path consists of a sequence of keys and/or indexes separated by a '.'. If the path exists, the pointer to the variant at that position is returned.

When a key contains a '.' the key should be put between quotes (single or double)

Parameters
varpointer to a variant struct, the variant type should be a composite type
pathpath to a variant in the composite variant structure, a path is a sequence of indexes and/or keys separated by a '.'
flagsbitmap, see AMXC_VAR_FLAG_DEFAULT, AMXC_VAR_FLAG_COPY, AMXC_VAR_FLAG_NO_INDEX
Returns
Pointer to the variant at the given path or NULL if the path does not exist.

Definition at line 573 of file amxc_variant.c.

575  {
576  amxc_var_t* retval = NULL;
577 
578  retval = amxc_var_find((amxc_var_t*) var, path, flags & ~AMXC_VAR_FLAG_AUTO_ADD);
579  when_null(retval, exit);
580 
581  if((flags & AMXC_VAR_FLAG_COPY) == AMXC_VAR_FLAG_COPY) {
582  amxc_var_t* copy = NULL;
583  if(amxc_var_new(&copy) != 0) {
584  retval = NULL;
585  goto exit;
586  }
587  if(amxc_var_copy(copy, retval) != 0) {
588  retval = NULL;
589  free(copy);
590  goto exit;
591  }
592  retval = copy;
593  }
594 
595 exit:
596  return retval;
597 }
static amxc_var_t * amxc_var_find(amxc_var_t *const var, const char *const path, const int flags)
Definition: amxc_variant.c:67
#define AMXC_VAR_FLAG_COPY
Copy the variant, creates a new variant, leaves the source variant untouched.
Definition: amxc_variant.h:398
#define AMXC_VAR_FLAG_AUTO_ADD
Add none existing variants to composite variants. This flag can be used with amxc_var_set_path and am...
Definition: amxc_variant.h:418
int amxc_var_copy(amxc_var_t *const dest, const amxc_var_t *const src)
Copy the type and data from one variant (source) in another variant (destination).
Definition: amxc_variant.c:285

◆ amxc_var_get_pathf()

amxc_var_t* amxc_var_get_pathf ( const amxc_var_t *const  var,
const int  flags,
const char *const  fmt,
  ... 
)

Retrieves the variant at the given path of a composite variant.

The type of the given variant is a composite type and some of the parts are composite variants as well, this function makes it easy to retrieve a variant deep down in the composite variant structure. The path consists of a sequence of keys and/or indexes separated by a '.'. If the path exists, the pointer to the variant at that position is returned.

When a key contains a '.' the key should be put between quotes (single or double)

Parameters
varpointer to a variant struct, the variant type should be a composite type
flagsbitmap, see AMXC_VAR_FLAG_DEFAULT, AMXC_VAR_FLAG_COPY, AMXC_VAR_FLAG_UPDATE
fmtpath to a variant in the composite variant structure, a path is a sequence of indexes and/or keys seperated by a '.'. Does support printf format.
Returns
Pointer to the variant at the given path or NULL if the path does not exist.

◆ amxc_var_get_previous()

amxc_var_t* amxc_var_get_previous ( const amxc_var_t *const  var)

Gets the previous variant.

If the variant is contained in a htable or list variant fetches the pointer to the previous variant.

If the provided variant pointer is not in a htable or list variant, this function will return NULL.

If the provided variant is the first in the htable or list a NULL pointer is returned.

If the provided variant is in a list and in a htable, the previous variant in the htable will be returned.

Parameters
varpointer to a variant struct
Returns
The previous variant in the htable or list variant or NULL

Definition at line 783 of file amxc_variant.c.

783  {
784  amxc_var_t* prev = NULL;
785 
786  when_null(var, exit);
787 
788  if(var->hit.ait != NULL) {
790  when_null(it, exit);
791  prev = amxc_var_from_htable_it(it);
792  } else if(var->lit.llist != NULL) {
794  when_null(it, exit);
795  prev = amxc_var_from_llist_it(it);
796  }
797 
798 exit:
799  return prev;
800 }
amxc_htable_it_t * amxc_htable_it_get_previous(const amxc_htable_it_t *const reference)
Gets the previous iterator in the hash table.
AMXC_INLINE amxc_llist_it_t * amxc_llist_it_get_previous(const amxc_llist_it_t *const reference)
Gets the previous iterator in the list.
Definition: amxc_llist.h:842

◆ amxc_var_init()

int amxc_var_init ( amxc_var_t *const  var)

Initializes a variant.

Call this to initialize variants structures (amxc_var_t) allocated on the stack.

When the variant is not needed anymore call amxc_var_clean to make sure that all allocated memory to store the data is freed. Failing to do so could lead to a memory leak.

The variant will be initialized as a null variant. To change the variant type use amxc_var_set_type.

Do not re-initialize an already initialized or used variant. The data contained in the variant is lost, no memory is freed if needed. To reset the variant back to a null variant use amxc_var_clean.

Parameters
varpointer to a variant structure.
Returns
When initialization is successful, this functions returns 0.

Definition at line 223 of file amxc_variant.c.

223  {
224  int retval = -1;
225  when_null(var, exit);
226 
227  var->type_id = 0;
228  var->data.data = NULL;
231  retval = 0;
232 
233 exit:
234  return retval;
235 }
int amxc_htable_it_init(amxc_htable_it_t *const it)
Initializes a hash table.iterator.
int amxc_llist_it_init(amxc_llist_it_t *const it)
Initializes a linked list iterator.
Definition: amxc_llist_it.c:89

◆ amxc_var_is_null()

AMXC_INLINE bool amxc_var_is_null ( const amxc_var_t *const  var)

Checks if the given variant is of the "null" type.

Parameters
varpointer to a variant struct
Returns
true when variant pointer is NULL or the variant is of the "null" type.

Definition at line 1594 of file amxc_variant.h.

1594  {
1595  return var == NULL ? true : (var->type_id == AMXC_VAR_ID_NULL);
1596 }

◆ amxc_var_key()

const char* amxc_var_key ( const amxc_var_t *const  var)

Gets the key, with which the variant is stored in a htable variant.

If the variant is contained in a htable variant fetches the key with which the variant is stored in the htable

If the provided variant pointer is not in a htable, this function will return NULL.

Parameters
varpointer to a variant struct
Returns
The key or NULL

Definition at line 821 of file amxc_variant.c.

821  {
822  const char* key = NULL;
823 
824  when_null(var, exit);
825 
826  if(var->hit.ait != NULL) {
827  key = amxc_htable_it_get_key(&var->hit);
828  }
829 
830 exit:
831  return key;
832 }
AMXC_INLINE const char * amxc_htable_it_get_key(const amxc_htable_it_t *const it)
Gets the key from the iterator.
Definition: amxc_htable.h:672

◆ amxc_var_move()

int amxc_var_move ( amxc_var_t *const  dest,
amxc_var_t *const  src 
)

Moves the type and data from one variant (source) in another variant (destination).

The destination variant is first set to the same type as the source variant using amxc_var_set_type and then the data is moved.

After the move the destination variant is identical to the source variant and the source variant is reset to the null variant type.

The iterators (linked list and htable) of the source variant are not moved.

Parameters
destpointer to variant struct, the destination
srcpointer to variant struct, the source
Returns
When the move fails, this functions returns a none 0 value and the destination variant is reset to a null variant.

Definition at line 308 of file amxc_variant.c.

308  {
309  int retval = -1;
310  amxc_var_type_t* type = NULL;
311  when_null(dest, exit);
312  when_null(src, exit);
313 
314  // reset destinationn variant
315  amxc_var_clean(dest);
316  // get the type function pointers of the src
317  type = amxc_var_get_type(src->type_id);
318  when_null(type, exit);
319  when_null(type->move, exit);
320 
321  when_failed(amxc_var_set_type(dest, src->type_id), exit);
322  retval = type->move(dest, src);
323  if(retval != 0) {
324  amxc_var_clean(dest);
325  } else {
326  amxc_var_clean(src);
327  }
328 
329 exit:
330  return retval;
331 }
amxc_var_move_fn_t move

◆ amxc_var_new()

int amxc_var_new ( amxc_var_t **  var)

Allocates a variant and initializes it to the null variant type.

A variant is a container that can hold any type.

Note
The allocated memory must be freed when not used anymore, use amxc_var_delete to free the memory
Parameters
varpointer to a pointer that points to the new allocated variant
Returns
When allocation is successfull, this functions returns 0.

Definition at line 194 of file amxc_variant.c.

194  {
195  int retval = -1;
196  when_null(var, exit);
197 
198  *var = (amxc_var_t*) calloc(1, sizeof(amxc_var_t));
199  when_null(*var, exit);
200 
201  retval = amxc_var_init(*var);
202 
203 exit:
204  return retval;
205 }

◆ amxc_var_set_index()

int amxc_var_set_index ( amxc_var_t *const  var,
const int64_t  index,
amxc_var_t data,
const int  flags 
)

Set a part of composed variant using an index.

If the data contained in the variant is composed of different parts and some or all parts can be identified with an index, the data of such a part can be changed with this function.

As a convention, when using as the index -1, the data is added to the end.

Example: if the variant is containing a list of variants, adding a new data variant using index -1, will add it to the end of the list.

Parameters
varpointer to variant structure, containing the composed data
indexthe index
dataa variant containing the data the will be set
flagsbitmap, see AMXC_VAR_FLAG_DEFAULT, AMXC_VAR_FLAG_COPY, AMXC_VAR_FLAG_UPDATE
Returns
When the data has been set this function returns 0, when failed, the function returns a non-zero value.

Definition at line 507 of file amxc_variant.c.

510  {
511  int retval = -1;
512  amxc_var_type_t* var_type = NULL;
513  when_null(var, exit);
514  when_null(data, exit);
515 
516  var_type = amxc_var_get_type(var->type_id);
517  when_null(var_type, exit);
518 
519  retval = var_type->set_index != NULL ?
520  var_type->set_index(var, data, index, flags) : -1;
521 
522 exit:
523  return retval;
524 }

◆ amxc_var_set_key()

int amxc_var_set_key ( amxc_var_t *const  var,
const char *const  key,
amxc_var_t data,
const int  flags 
)

Sets a part of composed variant using a key.

If the data contained in the variant is composed of different parts and some or all parts can be identified with a key, the data of such a part can be changed with this function.

The default behaviour is not to copy anything, just store the given variant. Using AMXC_VAR_FLAG_COPY this behavior can be changed into copy the variant and the variant data.

Note
The behaviour depends on the variant type of the destination variant (var parameter). Please read the documentation of the destination variant type.
Parameters
varpointer to variant structure, containing the composed data
keystring containing the key
dataa variant containing the data the will be set
flagsbitmap, see AMXC_VAR_FLAG_DEFAULT, AMXC_VAR_FLAG_COPY, AMXC_VAR_FLAG_UPDATE
Returns
When the data has been set this function returns 0, when failed, the function returns a non-zero value.

Definition at line 468 of file amxc_variant.c.

471  {
472  int retval = -1;
473  amxc_var_type_t* var_type = NULL;
474  when_null(var, exit);
475  when_null(key, exit);
476  when_true(*key == 0, exit);
477  when_null(data, exit);
478 
479  var_type = amxc_var_get_type(var->type_id);
480  when_null(var_type, exit);
481 
482  retval = var_type->set_key != NULL ?
483  var_type->set_key(var, data, key, flags) : -1;
484 
485 exit:
486  return retval;
487 }

◆ amxc_var_set_path()

amxc_var_t int amxc_var_set_path ( amxc_var_t *const  var,
const char *const  path,
amxc_var_t data,
const int  flags 
)

Sets the variant at the given path of a composite variant.

The type of the given variant is a composite type and some of the parts are composite variants as well, this function makes it easy to set a variant deep down in the composite variant structure. The path consists of a sequence of keys and/or indexes separated by a '.'.

If the path exists, the value of the variant at that position is changed.

If the path doesn't exist and the flag AMXC_VAR_FLAG_AUTO_ADD is set the variants on that path are added.

When a key contains a '.' the key should be put between quotes (single or double)

Parameters
varpointer to a variant struct, the variant type should be a composite type
pathpath to a variant in the composite variant structure, a path is a sequence of indexes and/or keys separated by a '.'
datathe new value
flagsbitmap, see AMXC_VAR_FLAG_DEFAULT, AMXC_VAR_FLAG_COPY, AMXC_VAR_FLAG_NO_INDEX, AMXC_VAR_FLAG_AUTO_ADD
Returns
0 when the value was set, any other value indicates an error.

Definition at line 623 of file amxc_variant.c.

626  {
627  amxc_var_t* variant = NULL;
628  int retval = -1;
629 
630  variant = amxc_var_find(var, path, flags);
631  when_null(variant, exit);
632 
633  if((flags & AMXC_VAR_FLAG_COPY) == AMXC_VAR_FLAG_COPY) {
634  retval = amxc_var_copy(variant, data);
635  } else {
636  retval = amxc_var_move(variant, data);
637  }
638 
639 exit:
640  return retval;
641 }

◆ amxc_var_set_pathf()

int amxc_var_set_pathf ( amxc_var_t *const  var,
amxc_var_t data,
const int  flags,
const char *const  fmt,
  ... 
)

Sets the variant at the given path of a composite variant.

The type of the given variant is a composite type and some of the parts are composite variants as well, this function makes it easy to set a variant deep down in the composite variant structure. The path consists of a sequence of keys and/or indexes separated by a '.'.

If the path exists, the value of the variant at that position is changed.

If the path doesn't exist and the flag AMXC_VAR_FLAG_AUTO_ADD is set the variants on that path are added.

When a key contains a '.' the key should be put between quotes (single or double)

Parameters
varpointer to a variant struct, the variant type should be a composite type
datathe new value
flagsbitmap, see AMXC_VAR_FLAG_DEFAULT, AMXC_VAR_FLAG_COPY, AMXC_VAR_FLAG_NO_INDEX, AMXC_VAR_FLAG_AUTO_ADD
fmtpath to a variant in the composite variant structure, a path is a sequence of indexes and/or keys separated by a '.'. Does support printf format.
Returns
0 when the value was set, any other value indicates an error.

◆ amxc_var_set_type()

int amxc_var_set_type ( amxc_var_t *const  var,
const uint32_t  type 
)

Change the variant data type.

If the variant was already containing data, this will be cleaned up. The type is changed and the data part reset to default value. (0, NULL, false, ...)

Parameters
varpointer to variant struct
typethe variant type id
Returns
When the type is set, this functions returns 0, any other value in case of failure.

Definition at line 261 of file amxc_variant.c.

261  {
262  int retval = -1;
263  amxc_var_type_t* var_type = NULL;
264  when_null(var, exit);
265 
266  var_type = amxc_var_get_type(type);
267  when_null(var_type, exit);
268 
269  // first clean the variant
270  // this to make sure all allocated memory for the content of the variant
271  // is freed
273 
274  var->type_id = type;
275  if(var_type->init != NULL) {
276  retval = var_type->init(var);
277  } else {
278  retval = 0;
279  }
280 
281 exit:
282  return retval;
283 }
amxc_var_new_fn_t init

◆ amxc_var_take_index()

AMXC_INLINE amxc_var_t* amxc_var_take_index ( amxc_var_t *const  var,
const int64_t  index 
)

Get a reference to a part of composed variant using an index and removes it from the composed variant.

If the data contained in the variant is composed of different parts and some or all parts can be identified with an index, a reference to such part can be retrieved with this function.

The variant referenced by the index is removed from the composed variant.

The returned variant must be freed using amxc_var_delete

Parameters
varpointer to variant structure, containing the composed data
indexthe index
Returns
When no part is found with the given index a null pointer is returned. The pointer returned is pointing to a real part.

Definition at line 1268 of file amxc_variant.h.

1269  {
1271  amxc_var_take_it(rv);
1272  return rv;
1273 }
amxc_var_t * amxc_var_get_index(const amxc_var_t *const var, const int64_t index, const int flags)
Get a reference to a part of composed variant using an index.
Definition: amxc_variant.c:489
AMXC_INLINE void amxc_var_take_it(amxc_var_t *const var)
Removes the variant for a llist and/or a htable.

◆ amxc_var_take_it()

AMXC_INLINE void amxc_var_take_it ( amxc_var_t *const  var)

Removes the variant for a llist and/or a htable.

When the variant is stored in a linked list and/or a hash table, it is removed from these. The variant itself is not deleted.

Parameters
varpointer to a variant struct

Definition at line 1107 of file amxc_variant.h.

1107  {
1108  if(var != NULL) {
1111  }
1112 }
void amxc_htable_it_take(amxc_htable_it_t *const it)
Removes the iterator from the hash table.
void amxc_llist_it_take(amxc_llist_it_t *const it)
Removes the iterator from the list.

◆ amxc_var_take_key()

AMXC_INLINE amxc_var_t* amxc_var_take_key ( amxc_var_t *const  var,
const char *const  key 
)

Get a reference to a part of composed variant using a key and removes it from the composed variant.

If the data contained in the variant is composed of different parts and some or all parts can be identified with a key, a reference to such part can be retrieved with this function.

The variant referenced by the key is removed from the composed variant.

The returned variant must be freed using amxc_var_delete

Parameters
varpointer to variant structure, containing the composed data
keystring containing the key
Returns
When no part is found with the given key a null pointer is returned. The pointer returned is pointing to a real part.

Definition at line 1189 of file amxc_variant.h.

1190  {
1192  amxc_var_take_it(rv);
1193  return rv;
1194 }
amxc_var_t * amxc_var_get_key(const amxc_var_t *const var, const char *const key, const int flags)
Get a reference to a part of composed variant using a key.
Definition: amxc_variant.c:449

◆ amxc_var_type_name_of()

const char* amxc_var_type_name_of ( const amxc_var_t *const  var)

Gets the variant type name of a variant.

Parameters
varpointer to a variant struct
Returns
A constant string containing the name of the variant type. Or a null pointer when the type does not exists or it is an invalid variant.

Definition at line 672 of file amxc_variant.c.

672  {
673  return var != NULL ? amxc_var_get_type_name_from_id(var->type_id) : NULL;
674 }
const char * amxc_var_get_type_name_from_id(const uint32_t type_id)
Get the type name.

◆ amxc_var_type_of()

uint32_t amxc_var_type_of ( const amxc_var_t *const  var)

Gets the variant type id of a variant.

Parameters
varpointer to a variant struct
Returns
The variant type id, or -1 if the type does not exists or if it is an invalid variant.

Definition at line 668 of file amxc_variant.c.

668  {
669  return var != NULL ? var->type_id : AMXC_VAR_ID_INVALID;
670 }
#define AMXC_VAR_ID_INVALID
Invalid variant type id.
Definition: amxc_variant.h:122