Conf v1.5.0
reader.h File Reference

Conf file reader. More...

#include "conf/common.h"
#include <stddef.h>
#include <stdbool.h>

Typedefs

typedef struct ConfReader_T ConfReader_T
 Conf reader structure.
 
typedef ConfReader_TConfReader
 Conf reader instance.
 

Functions

ConfResult createFileConfReader (const char *filePath, ConfReader *confReader, size_t *errorLine)
 Creates a new Conf file reader instance.
 
ConfResult createDataConfReader (const char *data, ConfReader *confReader, size_t *errorLine)
 Create a new Conf data reader instance.
 
void destroyConfReader (ConfReader confReader)
 Destroys Conf reader instance.
 
bool getConfReaderType (ConfReader confReader, const char *key, ConfDataType *type)
 Returns the type of value by key.
 
bool getConfReaderInt (ConfReader confReader, const char *key, int64_t *value)
 Returns the integer value by key.
 
bool getConfReaderFloat (ConfReader confReader, const char *key, double *value)
 Returns the floating value by key.
 
bool getConfReaderBool (ConfReader confReader, const char *key, bool *value)
 Returns the boolean value by key.
 
bool getConfReaderString (ConfReader confReader, const char *key, const char **value, uint64_t *length)
 Returns the string value by key.
 

Detailed Description

Conf file reader.

Used to read Conf files. Reads all data from a file and organizes it into a list optimized for fast retrieval of values by key.

Function Documentation

◆ createFileConfReader()

ConfResult createFileConfReader ( const char * filePath,
ConfReader * confReader,
size_t * errorLine )

Creates a new Conf file reader instance.

The main function for reading Conf files.

Note
You should destroy created Conf instance manually.
Parameters
[in]filePathtarget Conf file path string
[out]confReaderpointer to the Conf reader instance
[out]errorLinepointer to the error line or NULL
Returns
The ConfResult code and writes reader instance on success.
Return values
SUCCESS_CONF_RESULTon success
FAILED_TO_ALLOCATE_CONF_RESULTif out of memory
FAILED_TO_OPEN_FILE_CONF_RESULTif file doesn't exist
BAD_KEY_CONF_RESULTif config has invalid key
BAD_VALUE_CONF_RESULTif config has invalid value
BAD_ITEM_CONF_RESULTif config has invalid key / value pair
REPEATING_KEYS_CONF_RESULTif config has duplicate keys

◆ createDataConfReader()

ConfResult createDataConfReader ( const char * data,
ConfReader * confReader,
size_t * errorLine )

Create a new Conf data reader instance.

The main function for reading Conf data from strings.

Note
You should destroy created Conf instance manually.
Parameters
[in]datatarget Conf data string
[out]confReaderpointer to the Conf reader instance
[out]errorLinepointer to the error line or NULL
Returns
The ConfResult code and writes reader instance on success.
Return values
SUCCESS_CONF_RESULTon success
FAILED_TO_ALLOCATE_CONF_RESULTif out of memory
FAILED_TO_OPEN_FILE_CONF_RESULTif file doesn't exist
BAD_KEY_CONF_RESULTif config has invalid key
BAD_VALUE_CONF_RESULTif config has invalid value
BAD_ITEM_CONF_RESULTif config has invalid key / value pair
REPEATING_KEYS_CONF_RESULTif config has duplicate keys

◆ destroyConfReader()

void destroyConfReader ( ConfReader confReader)

Destroys Conf reader instance.

Parameters
confReaderconf reader instance or NULL

◆ getConfReaderType()

bool getConfReaderType ( ConfReader confReader,
const char * key,
ConfDataType * type )

Returns the type of value by key.

Useful if we are reading a config we don't know anything about.

Parameters
confReaderconf reader instance
[in]keytarget item key string
[out]typepointer to the value type
Returns
True on succes, false if item is not found.

◆ getConfReaderInt()

bool getConfReaderInt ( ConfReader confReader,
const char * key,
int64_t * value )

Returns the integer value by key.

Parameters
confReaderconf reader instance
[in]keytarget item key string
[out]valuepointer to the integer value
Returns
True on succes, false if item is not found or has a different type.

◆ getConfReaderFloat()

bool getConfReaderFloat ( ConfReader confReader,
const char * key,
double * value )

Returns the floating value by key.

Parameters
confReaderconf reader instance
[in]keytarget item key string
[out]valuepointer to the floating value
Returns
True on succes, false if item is not found or has a different type.

◆ getConfReaderBool()

bool getConfReaderBool ( ConfReader confReader,
const char * key,
bool * value )

Returns the boolean value by key.

Parameters
confReaderconf reader instance
[in]keytarget item key string
[out]valuepointer to the boolean value
Returns
True on succes, false if item is not found or has a different type.

◆ getConfReaderString()

bool getConfReaderString ( ConfReader confReader,
const char * key,
const char ** value,
uint64_t * length )

Returns the string value by key.

Warning
Yous should not free the returned string.
Parameters
confReaderconf reader instance
[in]keytarget item key string
[out]valuepointer to the string value
[out]lengthpointer to the string length or NULL
Returns
True on succes, false if item is not found or has a different type.