Conf v1.5.0
writer.h File Reference

Conf file writer. More...

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

Typedefs

typedef struct ConfWriter_T ConfWriter_T
 Conf writer structure.
 
typedef ConfWriter_TConfWriter
 Conf writer instance.
 

Functions

ConfResult createFileConfWriter (const char *filePath, ConfWriter *confWriter)
 Creates a new Conf file writer instance.
 
void destroyConfWriter (ConfWriter confWriter)
 Destroys Conf writer instance.
 
bool writeConfComment (ConfWriter confWriter, const char *comment)
 Writes a comment to the config.
 
bool writeConfNewLine (ConfWriter confWriter)
 Writes a new line to the config. ('\n')
 
bool writeConfInt (ConfWriter confWriter, const char *key, int64_t value)
 Writes an integer value to the config.
 
bool writeConfFloat (ConfWriter confWriter, const char *key, double value, uint8_t precision)
 Writes a floating value to the config.
 
bool writeConfBool (ConfWriter confWriter, const char *key, bool value)
 Writes a boolean value to the config.
 
bool writeConfString (ConfWriter confWriter, const char *key, const char *value, size_t length)
 Writes a string value to the config.
 

Detailed Description

Conf file writer.

Used to write Conf files. It opens a new file stream and writes the key / value pairs to it. After destroying the Conf writer instance, it closes the file stream.

Function Documentation

◆ createFileConfWriter()

ConfResult createFileConfWriter ( const char * filePath,
ConfWriter * confWriter )

Creates a new Conf file writer instance.

The main function for writing Conf files.

Note
You should destroy created Conf instance manually.
Parameters
[in]filePathtarget file path string
[out]confWriterpointer to the Conf writer instance
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 failed to create a new file

◆ destroyConfWriter()

void destroyConfWriter ( ConfWriter confWriter)

Destroys Conf writer instance.

Parameters
confWriterconf writer instance or NULL

◆ writeConfComment()

bool writeConfComment ( ConfWriter confWriter,
const char * comment )

Writes a comment to the config.

Parameters
confWriterconf writer instance
[in]commenttarget comment string

◆ writeConfNewLine()

bool writeConfNewLine ( ConfWriter confWriter)

Writes a new line to the config. ('\n')

Parameters
confWriterconf writer instance
Returns
True on success, otherwise false.

◆ writeConfInt()

bool writeConfInt ( ConfWriter confWriter,
const char * key,
int64_t value )

Writes an integer value to the config.

Parameters
confWriterconf writer instance
[in]keytarget item key string
valueinteger item value
Returns
True on success, otherwise false.

◆ writeConfFloat()

bool writeConfFloat ( ConfWriter confWriter,
const char * key,
double value,
uint8_t precision )

Writes a floating value to the config.

Parameters
confWriterconf writer instance
[in]keytarget item key string
valuefloating item value
precisionnumber of digits after the decimal point, or 0 (auto detect)
Returns
True on success, otherwise false.

◆ writeConfBool()

bool writeConfBool ( ConfWriter confWriter,
const char * key,
bool value )

Writes a boolean value to the config.

Parameters
confWriterconf writer instance
[in]keytarget item key string
valueboolean item value
Returns
True on success, otherwise false.

◆ writeConfString()

bool writeConfString ( ConfWriter confWriter,
const char * key,
const char * value,
size_t length )

Writes a string value to the config.

Parameters
confWriterconf writer instance
[in]keytarget item key string
[in]valuestring item value
lengthstring value length, or 0 (auto detect)
Returns
True on success, otherwise false.