Loading...
Searching...
No Matches
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_static_assert(e)
#define | CYAML_UNUSED(_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_static_assert

#define cyaml_static_assert | ( |  | e | ) |

Value:
{ \
enum { \
cyaml_static_assert_check = 1 / (!!(e)) \
}; \
}

Compile time assertion macro.

## CYAML_UNUSED

#define CYAML_UNUSED | ( |  | _x | ) |

Value:
((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

enum 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()

bool cyaml__flag_check_all | ( | enum cyaml_flag | flags,
|  | enum cyaml_flag | mask )

inline static

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

Parameters

  [in] | flags | The value flags to test.
  [in] | mask | Mask of the bits to test for in flags.

Returns
  true if all bits of mask are set in flags.

## cyaml__host_is_big_endian()

bool cyaml__host_is_big_endian | ( | void |  | ) |

inline static

Check whether the host is big endian.

Returns
  true if host is big endian.

## cyaml__host_is_little_endian()

bool cyaml__host_is_little_endian | ( | void |  | ) |

inline static

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()

bool cyaml__is_case_sensitive | ( | const cyaml_config_t * | config,
|  | const cyaml_schema_value_t * | schema )

inline static

Check if comparason should be case sensitive.

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

Parameters

  [in] | config | Client's CYAML configuration structure.
  [in] | schema | The CYAML schema for the value to be compared.

Returns
  Whether to use case-sensitive comparason.

## cyaml__log()

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

inline static

Log to client's logging function, if provided.

Parameters

  [in] | cfg | CYAML client config structure.
  [in] | level | Log level of message to log.
  [in] | fmt | Format string for message to log.
  [in] | ... | Additional arguments used by fmt.

## cyaml__state_to_str()

const char * cyaml__state_to_str | ( | enum cyaml_state_e | state | ) |

inline static

Convert a CYAML state into a human readable string.

Parameters

  [in] | state | The state to convert.

Returns
  String representing state.

## cyaml__strcmp()

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

inline static

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] | config | Client's CYAML configuration structure.
  [in] | schema | The CYAML schema for the value to be compared.
  [in] | str1 | First string to be compared.
  [in] | str2 | Second string to be compared.

Returns
  0 if and only if strings are equal.

## cyaml__type_to_str()

const char * cyaml__type_to_str | ( | cyaml_type_e | type | ) |

inline static

Convert a CYAML type into a human readable string.

Parameters

  [in] | type | The state to convert.

Returns
  String representing state.