|
Leosac
0.7.0
OpenSourceAccessControl
|
This class is a simpler helper to extract value from a property tree. More...
#include <PropertyTreeExtractor.hpp>
Collaboration diagram for Leosac::Tools::PropertyTreeExtractor:Public Member Functions | |
| PropertyTreeExtractor (const boost::property_tree::ptree &tree, const std::string &config_for) | |
| Construct the extract. More... | |
| template<typename T > | |
| T | get (const std::string &node_name) |
| Extract a mandatory property from the tree. More... | |
| template<typename T > | |
| T | get (const std::string &node_name, const T &default_value) |
| Extract an optional property from the tree. More... | |
Private Attributes | |
| const boost::property_tree::ptree & | tree_ |
| std::string | text_ |
This class is a simpler helper to extract value from a property tree.
It is convenient because it can catch boost exception and rethrow application-level exception with more context for the end-user.
The object is configured in its constructor and can then be used to extract properties from the tree.
Definition at line 38 of file PropertyTreeExtractor.hpp.
| PropertyTreeExtractor::PropertyTreeExtractor | ( | const boost::property_tree::ptree & | tree, |
| const std::string & | config_for | ||
| ) |
Construct the extract.
| tree | A reference to the tree from which we'll be extracting property. |
| config_for | A custom string that will be appended to the error message in case the extraction fails. |
Definition at line 28 of file PropertyTreeExtractor.cpp.
| T PropertyTreeExtractor::get | ( | const std::string & | node_name | ) |
Extract a mandatory property from the tree.
Throws a ex::Configuration exception if the key cannot be found, or if it cannot be converted to the excepted type.
Definition at line 36 of file PropertyTreeExtractor.cpp.
| T PropertyTreeExtractor::get | ( | const std::string & | node_name, |
| const T & | default_value | ||
| ) |
Extract an optional property from the tree.
It uses the default in case none is provided in the tree.
Definition at line 58 of file PropertyTreeExtractor.cpp.
|
private |
Definition at line 70 of file PropertyTreeExtractor.hpp.
|
private |
Definition at line 69 of file PropertyTreeExtractor.hpp.