DataReelDataReelC++ Toolkit Documentation

Configuration File Class

gxConfig reads and changes name=value configuration files.

Contents

Overview
Functions

Overview

Lines are name, the parameter ID string (= by default) and value. Lines starting with the comment character (#) are skipped, and a comment after a space at the end of a value is removed, so values such as file names can contain spaces. Lookups match whole names by default, or any name containing the text with full_name false.

gxConfig cfg("server.cfg");
cfg.Load();
int port = cfg.GetIntValue("port");
std::string dir = cfg.GetString("data_dir", "/var/lib/myapp");
cfg.ChangeConfigValue("port", 8443);        // Changes the file and the loaded values

Functions

bool gxConfig::Load() / Load(const std::string &fname) / ReLoad()

Reads the file. Returns true if successful.

const char *gxConfig::GetStrValue(std::string_view name, bool full_name = true) const

Value or a null pointer.

std::string gxConfig::GetString(std::string_view name, const std::string &default_value = "", bool full_name = true) const

Value or the default.

int GetIntValue / long GetLongValue / double GetFloatValue (std::string_view name, bool full_name = true) const

Numeric values; 0 if not found.

bool gxConfig::HasValue(std::string_view name, bool full_name = true) const

True if the name is present.

const std::vector<std::pair<std::string, std::string>> &gxConfig::Entries() const

Every name/value pair in file order.

int gxConfig::ChangeConfigValue(std::string_view parm, value)

Changes the parameter in the file (or appends it). value can be a string or a number. Returns the number of lines changed, 1 for an append, 0 on error.

bool gxConfig::WriteConfigLine / WriteCommentLine / WriteLine

Append lines to the file.

void SetParmID(const std::string &s) / SetCommentChar(char c) / FilterComments() / ReadComments()

Format settings.