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
56 static PropertyTree fromJsonString(const std::string& json);
57
62
65
72
82 template<class T>
83 void put(const std::string& key, const T& data);
84
94 template<class T>
95 T get(const std::string& key) const;
96
110 template<class T>
111 T get(const std::string& key, const T& defValue) const;
112
122 PropertyTree get_child(const std::string& key) const;
123
132 std::optional<PropertyTree>
133 get_child_optional(const std::string& key) const;
134
138 std::vector<std::string> get_child_keys() const;
139
153 template <typename T>
154 std::optional<std::vector<T>>
155 get_child_items_as_vector(const std::string& child) const;
156
165 void write_json(std::ostream& os, bool pretty) const;
166
167protected:
174
176 std::unique_ptr<boost::property_tree::ptree> tree_;
177};
178
179} // namespace Opm
180
181#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:176
void write_json(std::ostream &os, bool pretty) const
T get(const std::string &key) const
PropertyTree(const boost::property_tree::ptree &tree)
std::vector< std::string > get_child_keys() const
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
static PropertyTree fromJsonString(const std::string &json)
Construct a property tree from a JSON string held in memory.
PropertyTree(const std::string &jsonFile)
Definition: PropertyTree.hpp:31
Definition: blackoilbioeffectsmodules.hh:45
Definition: PropertyTree.hpp:30