CYAML Internals
Macros | Typedefs | Enumerations | Functions
util.h File Reference

CYAML common utility functions. More...

#include "cyaml/cyaml.h"
#include "utf8.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CYAML_UNUSED(_x)   ((void)(_x))
 
#define CYAML_BITFIELD_BITS   (sizeof(cyaml_bitfield_t) * CHAR_BIT)
 

Typedefs

typedef uint32_t cyaml_bitfield_t
 

Enumerations

enum  cyaml_state_e {
  CYAML_STATE_START , CYAML_STATE_IN_STREAM , CYAML_STATE_IN_DOC , CYAML_STATE_IN_MAP_KEY ,
  CYAML_STATE_IN_MAP_VALUE , CYAML_STATE_IN_SEQUENCE , CYAML_STATE__COUNT
}
 

Functions

static bool cyaml__host_is_little_endian (void)
 
static bool cyaml__host_is_big_endian (void)
 
static const char * cyaml__state_to_str (enum cyaml_state_e state)
 
static const char * cyaml__type_to_str (cyaml_type_e type)
 
static void cyaml__log (const cyaml_config_t *cfg, cyaml_log_t level, const char *fmt,...)
 
static bool cyaml__is_case_sensitive (const cyaml_config_t *config, const cyaml_schema_value_t *schema)
 
static int cyaml__strcmp (const cyaml_config_t *config, const cyaml_schema_value_t *schema, const void *const str1, const void *const str2)
 
static bool cyaml__flag_check_all (enum cyaml_flag flags, enum cyaml_flag mask)
 

Detailed Description

CYAML common utility functions.

Macro Definition Documentation

◆ CYAML_BITFIELD_BITS

#define CYAML_BITFIELD_BITS   (sizeof(cyaml_bitfield_t) * CHAR_BIT)

Number of bits in cyaml_bitfield_t.

◆ CYAML_UNUSED

#define CYAML_UNUSED (   _x)    ((void)(_x))

Macro to squash unused variable compiler warnings.

Typedef Documentation

◆ cyaml_bitfield_t

typedef uint32_t cyaml_bitfield_t

CYAML bitfield type.

Enumeration Type Documentation

◆ cyaml_state_e

CYAML state machine states.

Enumerator
CYAML_STATE_START 

Initial state.

CYAML_STATE_IN_STREAM 

In a stream.

CYAML_STATE_IN_DOC 

In a document.

CYAML_STATE_IN_MAP_KEY 

In a mapping.

CYAML_STATE_IN_MAP_VALUE 

In a mapping.

CYAML_STATE_IN_SEQUENCE 

In a sequence.

CYAML_STATE__COUNT 

Count of states, not a valid state itself.

Function Documentation

◆ cyaml__flag_check_all()

static bool cyaml__flag_check_all ( enum cyaml_flag  flags,
enum cyaml_flag  mask 
)
inlinestatic

Check of all the bits of a mask are set in a cyaml value flag word.

Parameters
[in]flagsThe value flags to test.
[in]maskMask of the bits to test for in flags.
Returns
true if all bits of mask are set in flags.

◆ cyaml__host_is_big_endian()

static bool cyaml__host_is_big_endian ( void  )
inlinestatic

Check whether the host is big endian.

Returns
true if host is big endian.

◆ cyaml__host_is_little_endian()

static bool cyaml__host_is_little_endian ( void  )
inlinestatic

Check whether the host is little endian.

Checks whether least significant bit is in the first byte of a uint16_t.

Returns
true if host is little endian.

◆ cyaml__is_case_sensitive()

static bool cyaml__is_case_sensitive ( const cyaml_config_t config,
const cyaml_schema_value_t schema 
)
inlinestatic

Check if comparason should be case sensitive.

As described in the API, schema flags take priority over config flags.

Parameters
[in]configClient's CYAML configuration structure.
[in]schemaThe CYAML schema for the value to be compared.
Returns
Whether to use case-sensitive comparason.

◆ cyaml__log()

static void cyaml__log ( const cyaml_config_t cfg,
cyaml_log_t  level,
const char *  fmt,
  ... 
)
inlinestatic

Log to client's logging function, if provided.

Parameters
[in]cfgCYAML client config structure.
[in]levelLog level of message to log.
[in]fmtFormat string for message to log.
[in]...Additional arguments used by fmt.

◆ cyaml__state_to_str()

static const char* cyaml__state_to_str ( enum cyaml_state_e  state)
inlinestatic

Convert a CYAML state into a human readable string.

Parameters
[in]stateThe state to convert.
Returns
String representing state.

◆ cyaml__strcmp()

static int cyaml__strcmp ( const cyaml_config_t config,
const cyaml_schema_value_t schema,
const void *const  str1,
const void *const  str2 
)
inlinestatic

Compare two strings.

Depending on the client's configuration, and the value's schema, this will do either a case-sensitive or case-insensitive comparason.

Parameters
[in]configClient's CYAML configuration structure.
[in]schemaThe CYAML schema for the value to be compared.
[in]str1First string to be compared.
[in]str2Second string to be compared.
Returns
0 if and only if strings are equal.

◆ cyaml__type_to_str()

static const char* cyaml__type_to_str ( cyaml_type_e  type)
inlinestatic

Convert a CYAML type into a human readable string.

Parameters
[in]typeThe state to convert.
Returns
String representing state.