My Project
DeckTree.hpp
1 /*
2  Copyright 2021 Statoil ASA.
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 DECK_TREE_HPP
21 #define DECK_TREE_HPP
22 
23 #include <string>
24 #include <unordered_map>
25 #include <unordered_set>
26 #include <optional>
27 
28 
29 namespace Opm {
30 
31 
32 /*
33  The purpose of the DeckTree class is to maintain a minimal relationship
34  between the include files in the deck; the sole purpose of this class is to
35  support writing of decks with the keywords in the correct files.
36 */
37 
38 class DeckTree {
39 public:
40  DeckTree() = default;
41  DeckTree(const std::string&);
42 
43  const std::string& parent(const std::string& fname) const;
44  bool includes(const std::string& parent_file, const std::string& include_file) const;
45  void add_include(std::string parent_file, std::string include_file);
46  void add_root(const std::string& fname);
47  bool has_include(const std::string& fname) const;
48  const std::string& root() const;
49 
50 private:
51  class TreeNode {
52  public:
53  explicit TreeNode(const std::string& fn);
54  TreeNode(const std::string& pn, const std::string& fn);
55  void add_include(const std::string& include_file);
56  bool includes(const std::string& include_file) const;
57 
58  std::string fname;
59  std::optional<std::string> parent;
60  std::unordered_set<std::string> include_files;
61  };
62 
63  std::string add_node(const std::string& fname);
64 
65  std::optional<std::string> root_file;
66  std::unordered_map<std::string, TreeNode> nodes;
67 };
68 
69 
70 }
71 #endif /* DECKRECORD_HPP */
72 
Definition: DeckTree.hpp:38
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29