omega_h
Reliable mesh adaptation
Omega_h_input.hpp
1 #ifndef OMEGA_H_INPUT_HPP
2 #define OMEGA_H_INPUT_HPP
3 
4 #include <Omega_h_defines.hpp>
5 #include <Omega_h_filesystem.hpp>
6 #include <Omega_h_mesh.hpp>
7 #include <iosfwd>
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12 
13 namespace Omega_h {
14 
15 struct Input {
16  Input* parent;
17  bool used;
18  virtual ~Input() = default;
19  Input(Input const&) = default;
20  Input(Input&&) = default;
21  Input();
22  virtual void out_of_line_virtual_method();
23 };
24 
25 std::string get_full_name(Input const& input);
26 
27 template <class InputType>
28 bool is_type(Input& input);
29 
30 template <class InputType>
31 InputType& as_type(Input& input);
32 
33 struct InputScalar : public Input {
34  std::string str;
35  InputScalar(std::string const& str_in);
36  InputScalar(InputScalar const&) = default;
37  InputScalar(InputScalar&&) = default;
38  bool as(std::string& out) const;
39  bool as(bool& out) const;
40  bool as(double& out) const;
41  bool as(int& out) const;
42  bool as(long long& out) const;
43  template <class T>
44  T get() const;
45  virtual void out_of_line_virtual_method();
46 };
47 
48 struct InputList;
49 
51  std::map<std::string, std::shared_ptr<Input>>::const_iterator impl;
52 
53  public:
54  InputMapIterator(decltype(impl) impl_in);
55  using value_type = std::string;
56  using difference_type = typename decltype(impl)::difference_type;
57  using reference = std::string const&;
58  using pointer = std::string const*;
59  using iterator_category = std::bidirectional_iterator_tag;
60  InputMapIterator() = default;
61  bool operator==(InputMapIterator const& other) const noexcept;
62  bool operator!=(InputMapIterator const& other) const noexcept;
63  reference operator*() const noexcept;
64  pointer operator->() const noexcept;
65  InputMapIterator& operator++() noexcept;
66  InputMapIterator operator++(int) noexcept;
67  InputMapIterator& operator--() noexcept;
68  InputMapIterator operator--(int) noexcept;
69 };
70 
71 struct InputMap : public Input {
72  std::map<std::string, std::shared_ptr<Input>> map;
73  InputMap() = default;
74  [[noreturn]] InputMap(InputMap const&);
75  InputMap(InputMap&&);
76  void add(std::string const& name, std::shared_ptr<Input>&& input);
77  template <class InputType>
78  bool is_input(std::string const& name);
79  template <class ScalarType>
80  bool is(std::string const& name);
81  bool is_map(std::string const& name);
82  bool is_list(std::string const& name);
83  Input& find_named_input(std::string const& name);
84  template <class InputType>
85  InputType& use_input(std::string const& name);
86  template <class ScalarType>
87  ScalarType get(std::string const& name);
88  void set(std::string const& name, char const* value);
89  InputMap& get_map(std::string const& name);
90  InputList& get_list(std::string const& name);
91  template <class ScalarType>
92  ScalarType get(std::string const& name, char const* default_value);
93  std::string const& name(Input const& input);
94  virtual void out_of_line_virtual_method();
95  InputMapIterator begin() const noexcept;
96  InputMapIterator end() const noexcept;
97  void remove(std::string const& name);
98 };
99 
100 struct InputList : public Input {
101  std::vector<std::shared_ptr<Input>> entries;
102  InputList() = default;
103  [[noreturn]] InputList(InputList const&);
104  InputList(InputList&&);
105  void add(std::shared_ptr<Input>&& input);
106  LO position(Input const& input);
107  LO size();
108  Input& at(LO i);
109  template <class InputType>
110  bool is_input(LO i);
111  template <class InputType>
112  InputType& use_input(LO i);
113  template <class ScalarType>
114  bool is(LO i);
115  bool is_map(LO i);
116  bool is_list(LO i);
117  template <class ScalarType>
118  ScalarType get(LO i);
119  InputMap& get_map(LO i);
120  InputList& get_list(LO i);
121  virtual void out_of_line_virtual_method();
122 };
123 
124 InputMap read_input(Omega_h::filesystem::path const& path);
125 
126 void update_class_sets(ClassSets* p_sets, InputMap& pl);
127 
128 void echo_input(std::ostream& stream, Input& input);
129 
130 void check_unused(Input& input);
131 
132 #define OMEGA_H_EXPL_INST(InputType) \
133  extern template bool is_type<InputType>(Input&); \
134  extern template InputType& as_type<InputType>(Input&); \
135  extern template bool InputMap::is_input<InputType>(std::string const& name); \
136  extern template InputType& InputMap::use_input<InputType>( \
137  std::string const& name); \
138  extern template bool InputList::is_input<InputType>(LO i); \
139  extern template InputType& InputList::use_input(LO i);
140 OMEGA_H_EXPL_INST(InputScalar)
141 OMEGA_H_EXPL_INST(InputMap)
142 OMEGA_H_EXPL_INST(InputList)
143 #undef OMEGA_H_EXPL_INST
144 
145 #define OMEGA_H_EXPL_INST(ScalarType) \
146  extern template ScalarType InputScalar::get<ScalarType>() const; \
147  extern template bool InputMap::is<ScalarType>(std::string const& name); \
148  extern template ScalarType InputMap::get<ScalarType>( \
149  std::string const& name); \
150  extern template ScalarType InputMap::get<ScalarType>( \
151  std::string const& name, char const* default_value); \
152  extern template bool InputList::is<ScalarType>(LO i); \
153  extern template ScalarType InputList::get<ScalarType>(LO i);
154 OMEGA_H_EXPL_INST(std::string)
155 OMEGA_H_EXPL_INST(bool)
156 OMEGA_H_EXPL_INST(double)
157 OMEGA_H_EXPL_INST(int)
158 OMEGA_H_EXPL_INST(long long)
159 #undef OMEGA_H_EXPL_INST
160 
161 } // namespace Omega_h
162 
163 #endif
Definition: Omega_h_input.hpp:50
Definition: Omega_h_filesystem.hpp:22
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_input.hpp:100
Definition: Omega_h_input.hpp:71
Definition: Omega_h_input.hpp:33
Definition: Omega_h_input.hpp:15
Definition: Omega_h_rbtree.hpp:1039
Definition: Omega_h_rbtree.hpp:1013