API Documentation

namespace ConfigParser

ConfigParser namespace.

Typedefs

typedef std::unordered_map<std::string, ConfigSection> SectionMap
typedef std::vector<ConfigLine> LineVector
typedef std::map<std::string, ConfigValue> ValueMap
typedef std::vector<std::string> StringVector
using KeysIter = typename StringVector::iterator
using ConstKeysIter = typename StringVector::const_iterator

Enums

enum class ConfigError

Defined error types used for file error checking.

Enum class

Values:

enumerator FILE_NOT_FOUND
enumerator FILE_OPEN_ERROR
enumerator FILE_READ_ERROR
enumerator NO_ERROR
enum class ConfigType

Config data types.

enum

Values:

enumerator CONFIG_EMPTY_LINE
enumerator CONFIG_COMMENT
enumerator CONFIG_SECTION
enumerator CONFIG_VALUE

Functions

template<typename element_t>
static inline int find(const std::vector<element_t> &vectorContainer, const element_t &value)
template<typename element_t>
static inline void removeElement(std::vector<element_t> &vectorContainer, const element_t &value)
class CfgParser : public ConfigParser::Parser

CFG file type Parser, inherits from Parser class. Provides functionality for and removing sections. Each section is a ConfigSection class which provides acces to it’s values. It is also possibel to loop through class sections as with values.

Public Functions

inline CfgParser(std::string _path = "")

Constructor.

Parameters:

_path – Path to the configuration file.

inline ~CfgParser()

Destructor.

inline void addSection(std::string sectionName)

Adds a new section.

Parameters:

sectionName – Name of the section to add.

inline void removeSection(const std::string &sectionName)

Removes a section.

Parameters:

sectionName – Name of the section to remove.

inline ConfigSection &section(const std::string &sectionName)

Retrieves a section.

Parameters:

sectionName – Name of the section to retrieve.

Throws:

std::out_of_range – if section not found.

Returns:

Reference to the ConfigSection.

inline const StringVector &sections()

Gets all section names.

Returns:

Vector of section names.

inline void clear()

Clears all sections and parser data.

struct ConfigLine

Stores config data for reading/writing config files.

class ConfigSection

Represents a configuration section with key-value pairs.

Subclassed by ConfigParser::IniParser

Public Functions

template<typename value_type>
inline void insert(std::string key, value_type value)

Inserts a key-value pair if the key doesn’t exist.

Parameters:
  • key – The key to insert.

  • value – The value to associate with the key.

inline virtual ConfigValue pop(const std::string &key)

Removes and returns the value associated with the key.

Parameters:

key – The key to remove.

Returns:

The value associated with the key.

inline virtual void remove(const std::string &key)

Removes a key-value pair.

Parameters:

key – The key to remove.

template<typename value_type>
inline void update(const std::string &key, value_type value)

Updates the value of an existing key.

Parameters:
  • key – The key to update.

  • value – The new value.

inline bool exists(const std::string &key)

Checks if a key exists.

Parameters:

key – The key to check.

Returns:

True if the key exists, false otherwise.

inline virtual void clear()

Clears all key-value pairs.

inline ConfigValue &get(const std::string &key)

Gets the value associated with a key.

Parameters:

key – The key to look up.

Throws:

std::out_of_range – if the key doesn’t exist.

Returns:

The value associated with the key.

class ConfigValue
#include <ConfigParser.hpp>

Base class for managing value data, handles different DataTypes and uses std::string to store them.

class IniParser : public ConfigParser::Parser, public ConfigParser::ConfigSection
#include <ConfigParser.hpp>

Ini config file type parser, inherits from both ConfigSection and Parser classes.

IniParser class

Public Functions

template<typename value_type>
inline void insert(std::string key, value_type value)

Function override from the ConfigSection class to handle line addition.

inline virtual ConfigValue pop(const std::string &key) override

Function override from the ConfigSection class to handle line removal.

inline virtual void remove(const std::string &key) override

Function override from the ConfigSection class to handle line removal.

inline virtual void clear() override

erases all keys and values.

class Parser

Base class for existing parsers. Contains methods which must be overwriten to implement functionality.

Subclassed by ConfigParser::CfgParser, ConfigParser::IniParser

Public Functions

inline const std::string &getPath() const

Get the current path to the config file.

Returns:

REturns a constant std string for file path.

inline const ConfigError getError() const

Retrieves currently imitted error code.

Returns:

Returns a Config error enum state.

inline void flush()

Clears current eror state.

inline virtual void load(std::string _path)

Loads a config file.

Parameters:

String, file – path.

inline virtual void reload()

Reloads an opened config file.

inline virtual void save(std::string _path = "")

Writes config data to the file path.

Parameters:

String, path – file, where file must be saved.