Conf v1.5.0
Conf

A library providing API for configuration file reading and writing.

See the documentation.

Features

  • Simple configuration syntax (similar to YAML)
  • Automatic variable parsing (int, float, bool, string)
  • Built-in configuration syntax validation
  • C and C++ implementations

Usage example

void confReaderExampleCPP()
{
conf::Reader confReader("settings.txt");
int64_t someValue = 0;
if (confReader.get("someValue", someValue))
{
// use value...
}
}
void confWriterExampleCPP()
{
conf::Writer confWriter("settings.txt");
confWriter.writeComment("Settings file (v1.0.0)");
confWriter.writeNewLine();
confWriter.write("someValue", 1337);
}
Conf reader instance handle.
Definition reader.hpp:39
Conf writer instance handle.
Definition writer.hpp:39
void confReaderExampleC()
{
ConfReader confReader = NULL;
ConfResult confResult = createFileConfReader("settings.txt", &confReader, NULL);
if (confResult != SUCCESS_CONF_RESULT) abort();
int64_t someValue = 0;
if (getConfReaderInt(confReader, "someValue", &someValue))
{
// use value...
}
destroyConfReader(confReader);
}
void confWriterExampleC()
{
ConfWriter confWriter = NULL;
ConfResult confResult = createFileConfWriter("settings.txt", &confWriter);
if (confResult != SUCCESS_CONF_RESULT) abort();
bool writeResult = writeConfComment(confWriter, "Settings file (v1.0.0)");
writeResult |= writeConfNewLine(confWriter);
writeResult |= writeConfInt(confWriter, "someValue", 1337);
if (!writeResult) abort();
destroyConfWriter(confReader);
}
T abort(T... args)
uint8_t ConfResult
Conf result code type.
Definition common.h:40
void destroyConfReader(ConfReader confReader)
Destroys Conf reader instance.
ConfReader_T * ConfReader
Conf reader instance.
Definition reader.h:37
bool getConfReaderInt(ConfReader confReader, const char *key, int64_t *value)
Returns the integer value by key.
ConfResult createFileConfReader(const char *filePath, ConfReader *confReader, size_t *errorLine)
Creates a new Conf file reader instance.
bool writeConfComment(ConfWriter confWriter, const char *comment)
Writes a comment to the config.
void destroyConfWriter(ConfWriter confWriter)
Destroys Conf writer instance.
bool writeConfInt(ConfWriter confWriter, const char *key, int64_t value)
Writes an integer value to the config.
ConfWriter_T * ConfWriter
Conf writer instance.
Definition writer.h:37
ConfResult createFileConfWriter(const char *filePath, ConfWriter *confWriter)
Creates a new Conf file writer instance.
bool writeConfNewLine(ConfWriter confWriter)
Writes a new line to the config. ('\n')

Configuration file example

# Conf comment syntax example
integerValue: 123
NegativeOne: -1
# Supported floating values
FloatingPI: 3.141
minus Infinity: -INF
Oh nooo: NaN
# Also some booleans
is.planet.round: true
caseSensitive: False
# And everything else is strings
hackingExploit: Hello world!
Not recommended key example? : Yes :)

Supported operating systems

  • Windows (10/11)
  • Ubuntu (22.04/24.04)
  • macOS (14/15)

This list includes only those systems on which functionality testing is conducted. However, you can also compile it under any other Linux distribution or operating system.

Build requirements

Use building instructions to install all required tools and libraries.

CMake options

Name Description Default value
CONF_BUILD_SHARED Build Conf shared library ON
CONF_BUILD_TESTS Build Conf library tests ON

CMake targets

Name Description Windows macOS Linux
conf-static Static Conf library .lib .a .a
conf-shared Dynamic Conf library .dll .dylib .so

Cloning

git clone --recursive https://github.com/cfnptr/conf

Building CI

  • Windows: ./scripts/build-release.bat
  • macOS / Ubuntu: ./scripts/build-release.sh

Third-party

  • mpio (Apache-2.0 License)