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.
PropertyTree & | operator= (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>
T | get (const std::string &key) const
| Retrieve property value given hierarchical property key.
template<class T>
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< PropertyTree > | get_child_optional (const std::string &key) const
| Retrieve copy of sub tree rooted at node.
std::vector< std::string > | get_child_keys () const
| Retrieve all child keys of this property tree 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::ptree > | tree_
| 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] | jsonFile | Name of file containing external property tree, linearised into JSON format.

## PropertyTree() [3/4]

Opm::PropertyTree::PropertyTree | ( | const PropertyTree & | tree | ) |

Copy constructor.

Parameters

  [in] | tree | Source 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] | tree | Source 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

  T | Value type

Parameters

  [in] | key | Property 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

  T | Value type

Parameters

  [in] | key | Property key. Expected to be in hierarchical notation for subtrees–i.e., using periods ('.') to separate hierarchy levels.
  [in] | defValue | Default 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] | key | Property key. 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

  T | Array element type.

Parameters

  [in] | child | Property 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_keys()

std::vector< std::string > Opm::PropertyTree::get_child_keys | ( |  | ) | const

Retrieve all child keys of this property tree node.

Returns
  Vector of strings containing the names of all immediate children

## 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] | key | Property key. 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] | tree | Source 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

  T | Value type

Parameters

  [in] | key | Property key. Expected to be in hierarchical notation for subtrees–i.e., using periods ('.') to separate hierarchy levels.
  [in] | data | Property 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] | os | Output stream. Typically a stream opened on a file.
  [in] | pretty | Whether 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:

- opm/simulators/linalg/PropertyTree.hpp
- opm/simulators/linalg/PropertyTree.cpp