PropertyTree.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019 SINTEF Digital, Mathematics and Cybernetics.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_PROPERTYTREE_HEADER_INCLUDED
21#define OPM_PROPERTYTREE_HEADER_INCLUDED
22
23#include <functional>
24#include <iosfwd>
25#include <memory>
26#include <optional>
27#include <string>
28#include <vector>
29
31 template<class T1, class T2, class T3> class basic_ptree;
33} // namespace boost::property_tree
34
35namespace Opm {
36
39{
40public:
45
53 explicit PropertyTree(const std::string& jsonFile);
54
59
62
69
79 template<class T>
80 void put(const std::string& key, const T& data);
81
91 template<class T>
92 T get(const std::string& key) const;
93
107 template<class T>
108 T get(const std::string& key, const T& defValue) const;
109
119 PropertyTree get_child(const std::string& key) const;
120
129 std::optional<PropertyTree>
130 get_child_optional(const std::string& key) const;
131
145 template <typename T>
146 std::optional<std::vector<T>>
147 get_child_items_as_vector(const std::string& child) const;
148
157 void write_json(std::ostream& os, bool pretty) const;
158
159protected:
166
168 std::unique_ptr<boost::property_tree::ptree> tree_;
169};
170
171} // namespace Opm
172
173#endif // OPM_PROPERTYTREE_HEADER_INCLUDED
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:39
PropertyTree & operator=(const PropertyTree &tree)
~PropertyTree()
Destructor.
T get(const std::string &key, const T &defValue) const
std::unique_ptr< boost::property_tree::ptree > tree_
Internal representation of the property tree.
Definition: PropertyTree.hpp:168
void write_json(std::ostream &os, bool pretty) const
T get(const std::string &key) const
PropertyTree(const boost::property_tree::ptree &tree)
std::optional< std::vector< T > > get_child_items_as_vector(const std::string &child) const
PropertyTree(const PropertyTree &tree)
std::optional< PropertyTree > get_child_optional(const std::string &key) const
void put(const std::string &key, const T &data)
PropertyTree get_child(const std::string &key) const
PropertyTree(const std::string &jsonFile)
Definition: PropertyTree.hpp:31
Definition: blackoilboundaryratevector.hh:39
Definition: PropertyTree.hpp:30