AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
Initfile.hpp
1#pragma once
2
3#include <optional>
4#include <string>
5
6#include <dune/common/parametertree.hh>
7
8
9namespace AMDiS
10{
12 {
13 public:
15 static void init(std::string const& in);
16
18
24 template <class T>
25 static std::optional<T> get(std::string const& key)
26 {
27 if (pt().hasKey(key))
28 return pt().get<T>(key);
29 else
30 return {};
31 }
32
34
41 template <class T>
42 static void get(std::string const& key, T& value)
43 {
44 value = pt().get(key, value);
45 }
46
47 template <class T>
48 static void set(std::string const& key, T const& value)
49 {
50 pt()[key] = value;
51 }
52
54 static int getMsgInfo()
55 {
56 return singlett().msgInfo_;
57 }
58
60 static void printParameters();
61
62 static void clearData() {}
63
64 protected:
65 Initfile() = default;
66
69 {
70 static Initfile initfile;
71 return initfile;
72 }
73
75 static Dune::ParameterTree& pt()
76 {
77 return singlett().pt_;
78 }
79
81 void read(std::string const& fn, bool force = false);
82 void write(std::string const& fn);
83
86
87 int msgInfo_ = 0;
88 int paramInfo_ = 1;
89 bool breakOnMissingTag_ = false;
90
92 Dune::ParameterTree pt_;
93 };
94
95 using Parameters = Initfile;
96
97} // end namespace AMDiS
Definition: Initfile.hpp:12
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
void read(std::string const &fn, bool force=false)
Fill an parametr-tree from a file with filename fn.
Definition: Initfile.cpp:32
void getInternalParameters()
read standard values for output and information of parameter-values
Definition: Initfile.cpp:38
static void get(std::string const &key, T &value)
Get parameter-values from parameter-tree with default value.
Definition: Initfile.hpp:42
static int getMsgInfo()
Returns specified info level.
Definition: Initfile.hpp:54
static void printParameters()
print all data in singleton to std::cout
Definition: Initfile.cpp:49
Dune::ParameterTree pt_
ParameterTree to read/store parameter values.
Definition: Initfile.hpp:92
static Initfile & singlett()
Return the singleton that contains the data.
Definition: Initfile.hpp:68
static Dune::ParameterTree & pt()
Return the parameter-tree.
Definition: Initfile.hpp:75
static void init(std::string const &in)
initialize singleton object and global parameters
Definition: Initfile.cpp:25