[mrpt-config]

Overview

C++ library for configuration files in the “INI” file format.

For YAML format, see mrpt::containers::yaml. For generic serialization to schema-based files, see [mrpt-serialization]

Library mrpt-config

This library is part of MRPT and can be installed in Debian-based systems with:

sudo apt install libmrpt-config-dev

See: mrpt_from_cmake

See: Configuration file format in MRPT

Overview

Most MRPT algorithms (maps, SLAM, localization, navigation, sensor drivers) read their parameters from INI-like files with [sections] and key = value lines. This module implements reading and writing those files, including the MRPT extensions to the format: @define variables, $eval{...} math expressions and $env{...} environment variables (see Configuration file format in MRPT).

Key classes

Example

#include <mrpt/config/CConfigFileMemory.h>

// A CConfigFile would read the same contents from a file on disk:
mrpt::config::CConfigFileMemory cfg(R"(
[robot]
name      = rover1
max_speed = 0.8   // m/s
)");

const double v = cfg.read_double("robot", "max_speed", 0.5);
const int n = cfg.read_int("robot", "num_wheels", 4);  // not present: 4
const std::string name = cfg.read_string("robot", "name", "", true /*fail if not found*/);

cfg.write("robot", "max_accel", 1.2);
std::cout << cfg.getContent();

Examples

Library contents

// classes

class mrpt::config::CConfigFile;
class mrpt::config::CConfigFileBase;
class mrpt::config::CConfigFileMemory;
class mrpt::config::CConfigFilePrefixer;
class mrpt::config::CLoadableOptions;
class mrpt::config::OptionsCapable;

// global functions

std::string mrpt::config::config_parser(const std::string& input);
void mrpt::config::registerAllClasses_mrpt_config();

Global Functions

std::string mrpt::config::config_parser(const std::string& input)

Parses a document and replaces all formulas, variables, etc.

as defined in Configuration file format in MRPT

void mrpt::config::registerAllClasses_mrpt_config()

Forces manual RTTI registration of all serializable classes in this namespace.

Should never be required to be explicitly called by users, except if building MRPT as a static library.