|
lib45d
45Drives C++ Library API Documentation
|
Main configuration parser class to inherit from in your code. More...
#include <45d/config/ConfigParser.hpp>
Public Member Functions | |
| ConfigParser (std::string path) | |
| Construct a new Config Parser object. More... | |
| std::string | dump_str (void) const |
| Dump config to stdout as a string. More... | |
| template<class T > | |
| T | get (const std::string &key) const |
| Get value from config map using ffd::get(). This can throw. Use this in a try...catch block. More... | |
| template<class T > | |
| T | get (const std::string &key, const T &fallback) const noexcept |
| Try to get value from config, default to fallback if fails. Guaranteed no-throw. More... | |
| template<class T > | |
| T | get (const std::string &key, bool *fail_flag) const noexcept |
| Try to get value from config. If ffd::get fails, return T() or 0 and set fail_flag. Guaranteed no-throw. Prints message to std::cerr to explain error. More... | |
| template<class T > | |
| T | get_from (const std::string §ion, const std::string &key) |
| Adapter for ffd::get(). Sets config_map_ptr_ to address of sub config with name section. This can throw. More... | |
| template<class T > | |
| T | get_from (const std::string §ion, const std::string &key, const T &fallback) noexcept |
| Get value from config subsection using ConfigParser::get(const std::string&,const T&) const noexcept, return fallback if the subsection DNE. More... | |
| template<class T > | |
| T | get_from (const std::string §ion, const std::string &key, bool *fail_flag) noexcept |
| Get value from config subsection using ConfigParser::get(const std::string&,bool*) const noexcept, set fail_flag if the subsection DNE. More... | |
| Quota | get_quota (const std::string &key, const Bytes &max) const |
| Get quota from config map using ffd::get(). This can throw. Use this in a try...catch block. More... | |
| Quota | get_quota (const std::string &key, const Bytes &max, const Quota &fallback) const noexcept |
| Try to get Quota from config, default to fallback if fails. Guaranteed no-throw. More... | |
| Quota | get_quota (const std::string &key, const Bytes &max, bool *fail_flag) const noexcept |
| Try to get Quota from config. If ffd::get fails, return Quota(void) and set fail_flag. Guaranteed no-throw. Prints message to std::cerr to explain error. More... | |
| Quota | get_quota_from (const std::string §ion, const std::string &key, const Bytes &max) |
| Adapter for ffd::get(). Sets config_map_ptr_ to address of sub config with name section. This can throw. More... | |
| Quota | get_quota_from (const std::string §ion, const std::string &key, const Bytes &max, const Quota &fallback) noexcept |
| Get value from config subsection using ConfigParser::get(const std::string&,const T&) const noexcept, return fallback if the subsection DNE. More... | |
| Quota | get_quota_from (const std::string §ion, const std::string &key, const Bytes &max, bool *fail_flag) noexcept |
| Get value from config subsection using ConfigParser::get(const std::string&,bool*) const noexcept, set fail_flag if the subsection DNE. More... | |
Protected Attributes | |
| std::vector< ConfigNode * > | sub_confs_ |
| Vector of config subsections. | |
| std::string | current_section_ |
| Name of current section, set by set_subsection() | |
Friends | |
| class | ConfigSubsectionGuard |
| Guard to change config subsection within a scope: ConfigSubsectionGuard. | |
Main configuration parser class to inherit from in your code.
Example usage:
| ffd::ConfigParser::ConfigParser | ( | std::string | path | ) |
Construct a new Config Parser object.
Opens file at path as an std::ifstream and calls ConfigParser::parse()
| path | Path to config file |
| std::string ffd::ConfigParser::dump_str | ( | void | ) | const |
Dump config to stdout as a string.
|
inline |
Get value from config map using ffd::get(). This can throw. Use this in a try...catch block.
| T | Type of variable to get |
| key | Key to index config_map_ |
|
inlinenoexcept |
Try to get value from config. If ffd::get fails, return T() or 0 and set fail_flag. Guaranteed no-throw. Prints message to std::cerr to explain error.
Example:
| T | Type of variable to return |
| key | Key to index config_map_ |
| fail_flag | Pointer to flag to set if ffd::get() fails |
|
inlinenoexcept |
Try to get value from config, default to fallback if fails. Guaranteed no-throw.
Example:
| T | Type of variable to return |
| key | Key to index config_map_ |
| fallback | Default value to return if ffd::get() fails. |
|
inline |
Adapter for ffd::get(). Sets config_map_ptr_ to address of sub config with name section. This can throw.
| T | Type of variable to get |
| section | Subsection heading from config |
| key | Key to index config_map_ |
|
inlinenoexcept |
Get value from config subsection using ConfigParser::get(const std::string&,bool*) const noexcept, set fail_flag if the subsection DNE.
| T | Type to return |
| section | Config section name to get value from |
| key | Key identifying value in config |
| fail_flag | Pointer to flag to be set if error or DNE |
|
inlinenoexcept |
Get value from config subsection using ConfigParser::get(const std::string&,const T&) const noexcept, return fallback if the subsection DNE.
Example:
| T | Type to return |
| section | Config section name to get value from |
| key | Key identifying value in config |
| fallback | Returned if error or DNE |
Get quota from config map using ffd::get(). This can throw. Use this in a try...catch block.
| key | Key to index config_map_ |
| max | Maximum number of bytes |
|
inlinenoexcept |
Try to get Quota from config. If ffd::get fails, return Quota(void) and set fail_flag. Guaranteed no-throw. Prints message to std::cerr to explain error.
| key | Key to index config_map_ |
| max | Maximum number of bytes |
| fail_flag | Pointer to flag to set if ffd::get() fails |
|
inlinenoexcept |
Try to get Quota from config, default to fallback if fails. Guaranteed no-throw.
| key | Key to index config_map_ |
| max | Maximum number of bytes |
| fallback | Default value to return if ffd::get() fails. |
|
inline |
Adapter for ffd::get(). Sets config_map_ptr_ to address of sub config with name section. This can throw.
| section | Subsection heading from config |
| key | Key to index config_map_ |
| max | Maximum number of bytes |
|
inlinenoexcept |
Get value from config subsection using ConfigParser::get(const std::string&,bool*) const noexcept, set fail_flag if the subsection DNE.
| section | Config section name to get value from |
| key | Key identifying value in config |
| max | Maximum number of bytes |
| fail_flag | Pointer to flag to be set if error or DNE |
|
inlinenoexcept |
Get value from config subsection using ConfigParser::get(const std::string&,const T&) const noexcept, return fallback if the subsection DNE.
Example:
| section | Config section name to get value from |
| key | Key identifying value in config |
| max | Maximum number of bytes |
| fallback | Returned if error or DNE |
1.8.17