Parse config file and return its configurations in a versatile manner. More...
#include <utils.h>
Public Member Functions | |
| ConfigParser (const std::string_view config_file) | |
| Open the config file. More... | |
| bool | succeed () const |
| Return whether the parsing succeeds. More... | |
| void | setWorkingNode (const std::string_view path="") |
| Set the working node in the config file. More... | |
| template<typename T > | |
| bool | parseConfig (T &arg, const std::string_view arg_name, const bool error_logging=true) const |
| Get the configuration and store it directly into the object. More... | |
Parse config file and return its configurations in a versatile manner.
| OmniSketch::Util::ConfigParser::ConfigParser | ( | const std::string_view | config_file | ) |
Open the config file.
| config_file | path to the config file |
|
inline |
Get the configuration and store it directly into the object.
| T | supported types:
|
| arg | the object to be written to |
| arg_name | the name in config file |
| error_logging | Enable / disable error logging when parsing fails (by default enabled) |
true on success; false otherwise. Possible reasons for a false return:arg is a vector or an toml::array, and an error be logged. To disable error logging, which might be particularly useful when the config is meant to be optional, set logging_error to false. | void OmniSketch::Util::ConfigParser::setWorkingNode | ( | const std::string_view | path = "" | ) |
Set the working node in the config file.
The data about to read should always locate in the working node. See example below for a better understanding. An argument of "" (or void) means the root. This method can be invoked upon a single instances multiple times.
| path | path to the working node |
Suppose the toml file is
and you want to fetch the value for key. This code snippet works for you.
| bool OmniSketch::Util::ConfigParser::succeed | ( | ) | const |
Return whether the parsing succeeds.