INIParser.h

class Cubism::Util::INIParser

INI config file parser.

Simple configuration file parser for use on the application level. CubismNova does not depend on this parser. The .ini file format is explained in more detail on Wikipedia for example. The python configparser module supports this format for convenient simulation case setup using python.

Public Functions

explicit INIParser(const std::string &filename)

Construct INIParser and parse given filename.

Parameters
  • filename: Configuration file path

explicit INIParser(const char *buffer, size_t buffer_size)

Construct INIParser and parse given buffer.

Parameters
  • buffer: Configuration character buffer

  • buffer_size: Number of bytes in buffer

bool parseError() const

Return the global result of ini_parse() for all files.

Return

False if no errors occurred during parsing

std::map<std::string, int> fileErrors() const

Return the result of ini_parse()

For each key in the map: 0 on success, line number of first error or -1 on file open error.

Return

Map for each INI file found in the main configuration

std::string get(const std::string &section, const std::string &name) const

Get a raw string value from INI file.

Throws a runtime error if not found.

Return

String value related to section and name

Parameters
  • section: Section name

  • name: Key name

std::string getString(const std::string &section, const std::string &name) const

Get a parsed string value from INI file.

Throws a runtime error if not found.

Return

Parsed string key value

Parameters
  • section: Section name

  • name: Key name

std::vector<std::string> getStringArray(const std::string &section, const std::string &name) const

Get a parsed array of string values from INI file.

Throws a runtime error if not found.

Return

Parsed array of strings

Parameters
  • section: Section name

  • name: Key name

long getInteger(const std::string &section, const std::string &name) const

Get a parsed integer (long) value from INI file.

Valid integers are decimal 1234, -1234, or hex 0x4d2. Throws a runtime error if not found.

Return

Parsed integer key value

Parameters
  • section: Section name

  • name: Key name

std::vector<long> getIntegerArray(const std::string &section, const std::string &name) const

Get a parsed array of integer values (long) from INI file.

Valid integers are decimal 1234, -1234, or hex 0x4d2. Throws a runtime error if not found.

Return

Parsed array of integers

Parameters
  • section: Section name

  • name: Key name

double getReal(const std::string &section, const std::string &name) const

Get a parsed real (double) value from INI file.

Valid floating point values according to strtod(). Throws a runtime error if not found.

Return

Parsed floating point key value

Parameters
  • section: Section name

  • name: Key name

std::vector<double> getRealArray(const std::string &section, const std::string &name) const

Get a parsed array of real (double) values from INI file.

Valid floating point values according to strtod(). Throws a runtime error if not found.

Return

Parsed array of floating point values

Parameters
  • section: Section name

  • name: Key name

bool getBoolean(const std::string &section, const std::string &name) const

Get a parsed boolean (bool) value from INI file.

Valid true values are true, yes, on, 1, and valid false values are false, no, off, 0 (not case sensitive). Throws a runtime error if not found.

Return

Parsed boolean value

Parameters
  • section: Section name

  • name: Key name

std::vector<bool> getBooleanArray(const std::string &section, const std::string &name) const

Get a parsed array of boolean (bool) values from INI file.

Valid true values are true, yes, on, 1, and valid false values are false, no, off, 0 (not case sensitive). Throws a runtime error if not found.

Return

Parsed array of boolean values

Parameters
  • section: Section name

  • name: Key name

bool hasSection(const std::string &section) const

Return true if the given section exists.

The section must contain at least one name=value pair.

Parameters
  • section: Section name

bool hasValue(const std::string &section, const std::string &name) const

Return true if a value exists.

Parameters
  • section: Section name

  • name: Key name

void write(const std::string &filename = "runtime.ini") const

Write currently loaded configuration to INI file format.

Parameters
  • filename: Output file path

Friends

friend friend std::ostream & operator<< (std::ostream &os, const INIParser &p)

Redirection to std::ostream

Parameters
  • os: Output stream

  • p: INI parser instance