Leosac  0.8.0
Open Source Access Control
Leosac::Tools::PropertyTreeExtractor Class Reference

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 >
get (const std::string &node_name)
 Extract a mandatory property from the tree. More...
 
template<typename 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_
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PropertyTreeExtractor()

PropertyTreeExtractor::PropertyTreeExtractor ( const boost::property_tree::ptree &  tree,
const std::string &  config_for 
)

Construct the extract.

Parameters
treeA reference to the tree from which we'll be extracting property.
config_forA custom string that will be appended to the error message in case the extraction fails.

Definition at line 28 of file PropertyTreeExtractor.cpp.

Member Function Documentation

◆ get() [1/2]

template<typename T >
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.

◆ get() [2/2]

template<typename T >
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.

Member Data Documentation

◆ text_

std::string Leosac::Tools::PropertyTreeExtractor::text_
private

Definition at line 70 of file PropertyTreeExtractor.hpp.

◆ tree_

const boost::property_tree::ptree& Leosac::Tools::PropertyTreeExtractor::tree_
private

Definition at line 69 of file PropertyTreeExtractor.hpp.


The documentation for this class was generated from the following files: