My Project
Loading...
Searching...
No Matches
Opm::PropertyTree Class Reference

Hierarchical collection of key/value pairs. More...

#include <PropertyTree.hpp>

Public Member Functions

 PropertyTree ()
 Default constructor.
 
 PropertyTree (const std::string &jsonFile)
 Constructor.
 
 PropertyTree (const PropertyTree &tree)
 Copy constructor.
 
 ~PropertyTree ()
 Destructor.
 
PropertyTreeoperator= (const PropertyTree &tree)
 Assignment operator.
 
template<class T >
void put (const std::string &key, const T &data)
 Insert key/value pair into property tree.
 
template<class T >
get (const std::string &key) const
 Retrieve property value given hierarchical property key.
 
template<class T >
get (const std::string &key, const T &defValue) const
 Retrieve property value given hierarchical property key.
 
PropertyTree get_child (const std::string &key) const
 Retrieve copy of sub tree rooted at node.
 
std::optional< PropertyTreeget_child_optional (const std::string &key) const
 Retrieve copy of sub tree rooted at node.
 
template<typename T >
std::optional< std::vector< T > > get_child_items_as_vector (const std::string &child) const
 Retrieve node items as linearised vector.
 
void write_json (std::ostream &os, bool pretty) const
 Emit a textual representation of the property tree in JSON form.
 

Protected Member Functions

 PropertyTree (const boost::property_tree::ptree &tree)
 Converting constructor.
 

Protected Attributes

std::unique_ptr< boost::property_tree::ptreetree_
 Internal representation of the property tree.
 

Detailed Description

Hierarchical collection of key/value pairs.

Constructor & Destructor Documentation

◆ PropertyTree() [1/4]

Opm::PropertyTree::PropertyTree ( )

Default constructor.

Should typically be populated in put() before use.

◆ PropertyTree() [2/4]

Opm::PropertyTree::PropertyTree ( const std::string &  jsonFile)
explicit

Constructor.

Loads a property tree from an external source expected to be a text file in JSON.

Parameters
[in]jsonFileName of file containing external property tree, linearised into JSON format.

◆ PropertyTree() [3/4]

Opm::PropertyTree::PropertyTree ( const PropertyTree tree)

Copy constructor.

Parameters
[in]treeSource object.

◆ PropertyTree() [4/4]

Opm::PropertyTree::PropertyTree ( const boost::property_tree::ptree tree)
protected

Converting constructor.

Forms a property tree object from a Boost ptree.

Parameters
[in]treeSource object represented as a Boost ptree.

Member Function Documentation

◆ get() [1/2]

template<class T >
template bool Opm::PropertyTree::get ( const std::string &  key) const

Retrieve property value given hierarchical property key.

Template Parameters
TValue type
Parameters
[in]keyProperty key. Expected to be in hierarchical notation for subtrees–i.e., using periods ('.') to separate hierarchy levels.
Returns
Copy of internal property value for key.

◆ get() [2/2]

template<class T >
T Opm::PropertyTree::get ( const std::string &  key,
const T &  defValue 
) const

Retrieve property value given hierarchical property key.

Template Parameters
TValue type
Parameters
[in]keyProperty key. Expected to be in hierarchical notation for subtrees–i.e., using periods ('.') to separate hierarchy levels.
[in]defValueDefault value for when key is not in the property tree.
Returns
Copy of internal property value for key, or a copy of defValue if the key is not in the property tree.

◆ get_child()

PropertyTree Opm::PropertyTree::get_child ( const std::string &  key) const

Retrieve copy of sub tree rooted at node.

Throws an exception if no sub tree exists at given root.

Parameters
[in]Propertykey. Expected to be in hierarchical notation for subtrees–i.e., using periods ('.') to separate hierarchy levels.
Returns
Copy of property sub tree rooted at key.

◆ get_child_items_as_vector()

template<typename T >
template std::optional< std::vector< double > > Opm::PropertyTree::get_child_items_as_vector ( const std::string &  child) const

Retrieve node items as linearised vector.

Assumes that the node's child is an array type of homongeneous elements.

Template Parameters
TArray element type.
Parameters
[in]childProperty key. Expected to be in hierarchical notation for subtrees–i.e., using periods ('.') to separate hierarchy levels.
Returns
Array of property values. Nullopt if no node named by child exists.

◆ get_child_optional()

std::optional< PropertyTree > Opm::PropertyTree::get_child_optional ( const std::string &  key) const

Retrieve copy of sub tree rooted at node.

Parameters
[in]Propertykey. Expected to be in hierarchical notation for subtrees–i.e., using periods ('.') to separate hierarchy levels.
Returns
Copy of property sub tree rooted at key. Nullopt if no sub tree exists that is rooted at key.

◆ operator=()

PropertyTree & Opm::PropertyTree::operator= ( const PropertyTree tree)

Assignment operator.

Parameters
[in]treeSource object.
Returns
*this
.

◆ put()

template<class T >
template void Opm::PropertyTree::put ( const std::string &  key,
const T &  data 
)

Insert key/value pair into property tree.

Template Parameters
TValue type
Parameters
[in]keyProperty key. Expected to be in hierarchical notation for subtrees–i.e., using periods ('.') to separate hierarchy levels.
[in]dataProperty value corresponding to key.

◆ write_json()

void Opm::PropertyTree::write_json ( std::ostream &  os,
bool  pretty 
) const

Emit a textual representation of the property tree in JSON form.

Parameters
[in,out]osOutput stream. Typically a stream opened on a file.
[in]prettyWhether or not to pretty-print the JSON output–i.e., whether or not to insert new lines and spaces for human readability.

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