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

Macros

#define GET_ARG(a, n)   amxc_var_get_key(a, n, AMXC_VAR_FLAG_DEFAULT)
 Convenience macro for getting variant out of a composite variant by key. More...
 
#define GET_BOOL(a, n)   amxc_var_dyncast(bool, n == NULL ? a : GET_ARG(a, n))
 Convenience macro for getting a bool out of a composite variant by key. More...
 
#define GET_CHAR(a, n)   amxc_var_constcast(cstring_t, n == NULL ? a : GET_ARG(a, n))
 Convenience macro for getting a char* out of a composite variant by key. More...
 
#define GET_UINT32(a, n)   amxc_var_dyncast(uint32_t, n == NULL ? a : GET_ARG(a, n))
 Convenience macro for getting a uint32_t out of a composite variant by key. More...
 
#define GET_INT32(a, n)   amxc_var_dyncast(int32_t, n == NULL ? a : GET_ARG(a, n))
 Convenience macro for getting a int32_t out of a composite variant by key. More...
 
#define GETI_ARG(a, i)   amxc_var_get_index(a, i, AMXC_VAR_FLAG_DEFAULT)
 Convenience macro for getting variant out of a composite variant by index. More...
 
#define GETI_BOOL(a, i)   amxc_var_dyncast(bool, GETI_ARG(a, i))
 Convenience macro for getting a bool out of a composite variant by index. More...
 
#define GETI_CHAR(a, i)   amxc_var_constcast(cstring_t, GETI_ARG(a, i))
 Convenience macro for getting a char* out of a composite variant by index. More...
 
#define GETI_UINT32(a, i)   amxc_var_dyncast(uint32_t, GETI_ARG(a, i))
 Convenience macro for getting a uint32_t out of a composite variant by index. More...
 
#define GETI_INT32(a, i)   amxc_var_dyncast(int32_t, GETI_ARG(a, i))
 Convenience macro for getting a int32_t out of a composite variant by index. More...
 
#define GETP_ARG(a, p)   amxc_var_get_path(a, p, AMXC_VAR_FLAG_DEFAULT)
 Convenience macro for getting variant out of a composite variant by path. More...
 
#define GETP_BOOL(a, p)   amxc_var_dyncast(bool, p == NULL ? a : GETP_ARG(a, p))
 Convenience macro for getting a bool out of a composite variant by path. More...
 
#define GETP_CHAR(a, p)   amxc_var_constcast(cstring_t, p == NULL ? a : GETP_ARG(a, p))
 Convenience macro for getting a string out of a composite variant by path. More...
 
#define GETP_UINT32(a, p)   amxc_var_dyncast(uint32_t, p == NULL ? a : GETP_ARG(a, p))
 Convenience macro for getting a uint32 out of a composite variant by path. More...
 
#define GETP_INT32(a, p)   amxc_var_dyncast(int32_t, p == NULL ? a : GETP_ARG(a, p))
 Convenience macro for getting a int32 out of a composite variant by path. More...
 

Functions

int amxc_var_dump (const amxc_var_t *const var, int fd)
 Dumps the content of the variant in a human readable manner. More...
 
int amxc_var_dump_stream (const amxc_var_t *const var, FILE *stream)
 Dumps the content of the variant in a human readable manner. More...
 
int amxc_var_log (const amxc_var_t *const var)
 Logs the content of the variant in a human readable manner to syslog. More...
 

Detailed Description

A list of utility functions and macro's that make common variant tasks easier.

Macro Definition Documentation

◆ GET_ARG

#define GET_ARG (   a,
 
)    amxc_var_get_key(a, n, AMXC_VAR_FLAG_DEFAULT)

Convenience macro for getting variant out of a composite variant by key.

Macro expands to amxc_var_get_key(a, n, AMXC_VAR_FLAG_DEFAULT)

See also
amxc_var_get_key

Definition at line 436 of file amxc_variant.h.

◆ GET_BOOL

#define GET_BOOL (   a,
 
)    amxc_var_dyncast(bool, n == NULL ? a : GET_ARG(a, n))

Convenience macro for getting a bool out of a composite variant by key.

Macro expands to amxc_var_dyncast(bool, n == NULL?a:amxc_var_get_key(a, n, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_key, amxc_var_dyncast

Definition at line 446 of file amxc_variant.h.

◆ GET_CHAR

#define GET_CHAR (   a,
 
)    amxc_var_constcast(cstring_t, n == NULL ? a : GET_ARG(a, n))

Convenience macro for getting a char* out of a composite variant by key.

Macro expands to amxc_var_constcast(cstring_t, n == NULL?a:amxc_var_get_key(a, n, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_key, amxc_var_constcast

Definition at line 456 of file amxc_variant.h.

◆ GET_INT32

#define GET_INT32 (   a,
 
)    amxc_var_dyncast(int32_t, n == NULL ? a : GET_ARG(a, n))

Convenience macro for getting a int32_t out of a composite variant by key.

Macro expands to amxc_var_dyncast(int32_t, n == NULL?a:amxc_var_get_key(a, n, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_key, amxc_var_dyncast

Definition at line 476 of file amxc_variant.h.

◆ GET_UINT32

#define GET_UINT32 (   a,
 
)    amxc_var_dyncast(uint32_t, n == NULL ? a : GET_ARG(a, n))

Convenience macro for getting a uint32_t out of a composite variant by key.

Macro expands to amxc_var_dyncast(uint32_t, n == NULL?a:amxc_var_get_key(a, n, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_key, amxc_var_dyncast

Definition at line 466 of file amxc_variant.h.

◆ GETI_ARG

#define GETI_ARG (   a,
 
)    amxc_var_get_index(a, i, AMXC_VAR_FLAG_DEFAULT)

Convenience macro for getting variant out of a composite variant by index.

Macro expands to amxc_var_get_index(a, i, AMXC_VAR_FLAG_DEFAULT)

See also
amxc_var_get_index

Definition at line 487 of file amxc_variant.h.

◆ GETI_BOOL

#define GETI_BOOL (   a,
 
)    amxc_var_dyncast(bool, GETI_ARG(a, i))

Convenience macro for getting a bool out of a composite variant by index.

Macro expands to amxc_var_dyncast(bool, amxc_var_get_index(a, i, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_index, amxc_var_dyncast

Definition at line 497 of file amxc_variant.h.

◆ GETI_CHAR

#define GETI_CHAR (   a,
 
)    amxc_var_constcast(cstring_t, GETI_ARG(a, i))

Convenience macro for getting a char* out of a composite variant by index.

Macro expands to amxc_var_constcast(cstring_t, amxc_var_get_index(a, i, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_index, amxc_var_constcast

Definition at line 507 of file amxc_variant.h.

◆ GETI_INT32

#define GETI_INT32 (   a,
 
)    amxc_var_dyncast(int32_t, GETI_ARG(a, i))

Convenience macro for getting a int32_t out of a composite variant by index.

Macro expands to amxc_var_dyncast(int32_t, amxc_var_get_index(a, i, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_index, amxc_var_dyncast

Definition at line 527 of file amxc_variant.h.

◆ GETI_UINT32

#define GETI_UINT32 (   a,
 
)    amxc_var_dyncast(uint32_t, GETI_ARG(a, i))

Convenience macro for getting a uint32_t out of a composite variant by index.

Macro expands to amxc_var_dyncast(uint32_t, amxc_var_get_index(a, i, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_index, amxc_var_dyncast

Definition at line 517 of file amxc_variant.h.

◆ GETP_ARG

#define GETP_ARG (   a,
 
)    amxc_var_get_path(a, p, AMXC_VAR_FLAG_DEFAULT)

Convenience macro for getting variant out of a composite variant by path.

Macro expands to amxc_var_get_path(a, p, AMXC_VAR_FLAG_DEFAULT)

See also
amxc_var_get_path

Definition at line 538 of file amxc_variant.h.

◆ GETP_BOOL

#define GETP_BOOL (   a,
 
)    amxc_var_dyncast(bool, p == NULL ? a : GETP_ARG(a, p))

Convenience macro for getting a bool out of a composite variant by path.

Macro expands to amxc_var_dyncast(bool, p == NULL?a:amxc_var_get_path(a, p, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_path, amxc_var_dyncast

Definition at line 548 of file amxc_variant.h.

◆ GETP_CHAR

#define GETP_CHAR (   a,
 
)    amxc_var_constcast(cstring_t, p == NULL ? a : GETP_ARG(a, p))

Convenience macro for getting a string out of a composite variant by path.

Macro expands to amxc_var_constcast(cstring_t, p == NULL?a:amxc_var_get_path(a, p, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_path, amxc_var_constcast

Definition at line 558 of file amxc_variant.h.

◆ GETP_INT32

#define GETP_INT32 (   a,
 
)    amxc_var_dyncast(int32_t, p == NULL ? a : GETP_ARG(a, p))

Convenience macro for getting a int32 out of a composite variant by path.

Macro expands to amxc_var_dyncast(int32_t, p == NULL?a:amxc_var_get_path(a, p, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_path, amxc_var_dyncast

Definition at line 578 of file amxc_variant.h.

◆ GETP_UINT32

#define GETP_UINT32 (   a,
 
)    amxc_var_dyncast(uint32_t, p == NULL ? a : GETP_ARG(a, p))

Convenience macro for getting a uint32 out of a composite variant by path.

Macro expands to amxc_var_dyncast(uint32_t, p == NULL?a:amxc_var_get_path(a, p, AMXC_VAR_FLAG_DEFAULT))

See also
amxc_var_get_path, amxc_var_dyncast

Definition at line 568 of file amxc_variant.h.

Function Documentation

◆ amxc_var_dump()

int amxc_var_dump ( const amxc_var_t *const  var,
int  fd 
)

Dumps the content of the variant in a human readable manner.

Writes the content of the variant in a human readable and structured manner to the provided file descriptor.

This function is useful for debugging purposes.

Parameters
varpointer to a variant struct
fdthe file descriptor
Returns
0 when writing the content was successful.

Definition at line 340 of file amxc_variant_dump.c.

340  {
341  return amxc_var_dump_impl(var, fd, NULL);
342 }
static int amxc_var_dump_impl(const amxc_var_t *const var, int fd, FILE *stream)
static amxc_var_t * var
Definition: test_issue_58.c:77

◆ amxc_var_dump_stream()

int amxc_var_dump_stream ( const amxc_var_t *const  var,
FILE *  stream 
)

Dumps the content of the variant in a human readable manner.

Writes the content of the variant in a human readable and structured manner to the provided file pointer.

This function is useful for debugging purposes.

Parameters
varpointer to a variant struct
streamthe file pointer
Returns
0 when writing the content was successful.

Definition at line 344 of file amxc_variant_dump.c.

344  {
345  return amxc_var_dump_impl(var, -1, stream);
346 }

◆ amxc_var_log()

int amxc_var_log ( const amxc_var_t *const  var)

Logs the content of the variant in a human readable manner to syslog.

Writes the content of the variant in a human readable and structured manner to the syslog, providing the system log service was opened.

This function is usefull for debugging purposes.

Parameters
varpointer to a variant struct
Returns
0 when writing the content was successful.

Definition at line 348 of file amxc_variant_dump.c.

348  {
349  amxc_log_var_t log;
350  int retval = 0;
351 
352  amxc_var_log_init(&log, -1, NULL, 1024);
353 
354  if(var == NULL) {
355  syslog(LOG_DAEMON | LOG_DEBUG, "NULL");
356  goto exit;
357  }
358 
359  retval = amxc_var_dump_internal(var, 0, &log);
360  if(!amxc_string_is_empty(&log.message)) {
361  syslog(LOG_DAEMON | LOG_DEBUG, "%s", amxc_string_get(&log.message, 0));
362  }
363 
364 exit:
366  return retval;
367 }
static void amxc_var_log_init(amxc_log_var_t *log, int fd, FILE *stream, size_t msg_length)
static int amxc_var_dump_internal(const amxc_var_t *const var, int indent, amxc_log_var_t *log)
const char * amxc_string_get(const amxc_string_t *const string, const size_t offset)
Gets the content of the string buffer.
Definition: amxc_string.c:339
AMXC_INLINE bool amxc_string_is_empty(const amxc_string_t *const string)
Checks if the string is empty.
Definition: amxc_string.h:1015
void amxc_string_clean(amxc_string_t *const string)
Frees the string buffer and reset length attributes.
Definition: amxc_string.c:189
amxc_string_t message