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

#include <PropertyTree.hpp>

Public Member Functions

 PropertyTree ()
 
 PropertyTree (const std::string &jsonFile)
 
 PropertyTree (const PropertyTree &tree)
 
 ~PropertyTree ()
 Destructor. More...
 
PropertyTreeoperator= (const PropertyTree &tree)
 
template<class T >
void put (const std::string &key, const T &data)
 
template<class T >
get (const std::string &key) const
 
template<class T >
get (const std::string &key, const T &defValue) const
 
PropertyTree get_child (const std::string &key) const
 
std::optional< PropertyTreeget_child_optional (const std::string &key) const
 
template<typename T >
std::optional< std::vector< T > > get_child_items_as_vector (const std::string &child) const
 
void write_json (std::ostream &os, bool pretty) const
 

Protected Member Functions

 PropertyTree (const boost::property_tree::ptree &tree)
 

Protected Attributes

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

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()

Opm::PropertyTree::~PropertyTree ( )

Destructor.

◆ 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]

◆ 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 >
std::optional< std::vector< T > > 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 >
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.

Referenced by Opm::GenericTracerModel< Grid, GridView, DofMapper, Stencil, FluidSystem, Scalar >::linearSolve_(), and Opm::GenericTracerModel< Grid, GridView, DofMapper, Stencil, FluidSystem, Scalar >::linearSolveBatchwise_().

◆ 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.

Referenced by Opm::detail::writeJsonToStream().

Member Data Documentation

◆ tree_

std::unique_ptr<boost::property_tree::ptree> Opm::PropertyTree::tree_
protected

Internal representation of the property tree.


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