SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Settings.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <carl-common/memory/Singleton.h>
4 #include <carl-settings/Settings.h>
5 
6 #include <any>
7 #include <cassert>
8 #include <functional>
9 #include <map>
10 #include <sstream>
11 #include <string>
12 
13 namespace smtrat {
14 namespace settings {
15 
16 struct CoreSettings {
17  bool show_help;
18  bool show_info;
24  std::string config_file;
25 };
26 
30  bool preprocess;
34 };
35 
37  std::vector<std::string> parameters;
38 
39 private:
40  std::function<bool(const std::string&)> has_option;
41  std::function<std::string(const std::string&)> get_option;
42 
43 public:
45  : has_option([](const std::string&) { return false; }), get_option([](const std::string&) { return ""; }) {
46  }
47 
48  void set_callbacks(std::function<bool(const std::string&)> callback_has, std::function<std::string(const std::string&)> callback_get) {
49  has_option = callback_has;
50  get_option = callback_get;
51  }
52 
53  template<typename T>
54  T get(const std::string& key, T default_value) const {
55  if (has_option(key)) {
56  if constexpr ((std::is_same_v<T, std::string>)) {
57  return get_option(key);
58  } else {
59  std::istringstream iss(get_option(key));
60  T value;
61  iss >> value;
62  return value;
63  }
64  } else {
65  for (const auto& param : parameters) {
66  std::string p_key = param.substr(0, param.find("="));
67  if (p_key == key) {
68  if constexpr ((std::is_same_v<T, std::string>)) {
69  return param.substr(param.find("=") + 1);
70  } else {
71  std::istringstream iss(param.substr(param.find("=") + 1));
72  T value;
73  iss >> value;
74  return value;
75  }
76  }
77  }
78  }
79  return default_value;
80  }
81 };
82 
83 struct Settings : public carl::Singleton<Settings>, public carl::settings::Settings {
84  friend carl::Singleton<Settings>;
85 
86 private:
88  get<CoreSettings>("core");
89  get<SolverSettings>("solver");
90  get<ModuleSettings>("module");
91  }
92 };
93 
94 } // namespace settings
95 
96 inline const settings::Settings& Settings() {
97  return settings::Settings::getInstance();
98 }
99 
100 inline const auto& settings_core() {
101  static const auto& s = settings::Settings::getInstance().get<settings::CoreSettings>("core");
102  return s;
103 }
104 inline const auto& settings_solver() {
105  static const auto& s = settings::Settings::getInstance().get<settings::SolverSettings>("solver");
106  return s;
107 }
108 inline const auto& settings_module() {
109  static const auto& s = settings::Settings::getInstance().get<settings::ModuleSettings>("module");
110  return s;
111 }
112 
113 } // namespace smtrat
Class to create the formulas for axioms.
const auto & settings_module()
Definition: Settings.h:108
const settings::Settings & Settings()
Definition: Settings.h:96
const auto & settings_core()
Definition: Settings.h:100
const auto & settings_solver()
Definition: Settings.h:104
T get(const std::string &key, T default_value) const
Definition: Settings.h:54
void set_callbacks(std::function< bool(const std::string &)> callback_has, std::function< std::string(const std::string &)> callback_get)
Definition: Settings.h:48
std::vector< std::string > parameters
Definition: Settings.h:37
std::function< bool(const std::string &)> has_option
Definition: Settings.h:40
std::function< std::string(const std::string &)> get_option
Definition: Settings.h:41
std::string preprocess_output_file
Definition: Settings.h:31