BSMPT 3.1.3
BSMPT - Beyond the Standard Model Phase Transitions : A C++ package for the computation of the EWPT in BSM models
Loading...
Searching...
No Matches
parser.h
1// Copyright (C) 2020 Philipp Basler, Margarete Mühlleitner and Jonas Müller
2// SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas
3// Müller
4//
5// SPDX-License-Identifier: GPL-3.0-or-later
6
7#ifndef PARSER_H
8#define PARSER_H
9
11#include <optional>
12#include <string>
13#include <unordered_map>
14#include <vector>
15
16namespace BSMPT
17{
18
22void ShowInputError();
23
24class parserException : public std::exception
25{
26public:
27 virtual const char *what() const noexcept;
28 parserException(const std::string &msg);
29
30private:
31 std::string message;
32};
33
38class parser
39{
40public:
41 parser();
42 parser(const bool &enable_column_output);
55 void add_argument_only_display(const std::string &argument,
56 const std::string &description,
57 const std::string &default_val);
64 void add_argument(const std::string &argument, bool required);
72 void add_argument(const std::string &argument,
73 const std::string &description,
74 bool required);
83 void add_argument(const std::string &argument,
84 const std::string &description,
85 const std::string &default_val,
86 bool required);
91 void add_subtext(const std::string &subtext);
98 void add_input(const std::vector<std::string> &input);
103 void print_help() const;
111 template <typename T = std::string>
112 T get_value(const std::string &argument) const
113 {
114 auto value = get_value_as_string(argument);
115 if constexpr (std::is_same<T, std::string>::value)
116 {
117 return value;
118 }
119 else if constexpr (std::is_same<T, int>::value)
120 {
121 return std::stoi(value);
122 }
123 else if constexpr (std::is_same<T, unsigned int>::value)
124 {
125 return std::stoul(value);
126 }
127 else if constexpr (std::is_same<T, double>::value)
128 {
129 return std::stod(value);
130 }
131 else if constexpr (std::is_same<T, bool>::value)
132 {
133 auto lower = to_lower(value);
134 return lower == "true";
135 }
136 else
137 {
138 return static_cast<T>(value);
139 }
140 }
141
146 bool all_required_set() const;
152 void check_required_parameters() const;
157 void set_help_header(const std::string &header);
158
159private:
160 struct Options
161 {
162 std::string argument;
163 std::string description;
164 std::optional<std::string> value;
165 std::string default_val = "";
166 };
167 struct KeyValue
168 {
169 std::string key;
170 std::string value;
171 KeyValue() = default;
172 KeyValue(const std::string &Key, const std::string &Value)
173 : key{Key}
174 , value{Value}
175 {
176 }
177 };
178
179 std::vector<std::pair<std::string, Options>> mOrderedArguments;
180 std::unordered_map<std::string, Options> mRequiredArguments;
181 std::unordered_map<std::string, Options> mOptionalArguments;
182
183 bool extra_column_output = false;
184
192 std::string get_value_as_string(const std::string &argument) const;
197 void add_json_input(const std::string &filename);
202 void add_input(const std::vector<KeyValue> &input);
210 std::string to_lower(const std::string &input) const;
211
212 KeyValue get_key_value(const std::string &input);
213 std::string mHeader;
214
218 mutable bool mHelpAlreadyPrinted{false};
219};
220} // namespace BSMPT
221#endif // PARSER_H
Definition parser.h:25
The parser class provides the argument parser for the CLI and JSON methods. This is case insensitive.
Definition parser.h:39
void add_input(const std::vector< std::string > &input)
add_input Add the vector with each input as it is given in the CLI in the form "--argument=value".
Definition parser.cpp:213
bool all_required_set() const
all_required_set Check ifs all required parameter are set.
Definition parser.cpp:244
std::string get_value_as_string(const std::string &argument) const
get_value Get the value for the required parameter.
Definition parser.cpp:351
T get_value(const std::string &argument) const
get_value Get the value for the required parameter.
Definition parser.h:112
void print_help() const
print_help Prints the header and the arguments with their description.
Definition parser.cpp:268
std::string to_lower(const std::string &input) const
get_key_value Converts the CLI input in the form "--argName=value" into a key value pair.
Definition parser.cpp:458
void set_help_header(const std::string &header)
set_help_header Sets the header which is printed in print_help()
Definition parser.cpp:407
bool mHelpAlreadyPrinted
Helper to avoid multiple prints of the help output.
Definition parser.h:218
void check_required_parameters() const
check_required_parameters Calls all_required_set() and throws a parserException if not all required p...
Definition parser.cpp:259
void add_subtext(const std::string &subtext)
add_subtext add subtext to description column
Definition parser.cpp:205
void add_json_input(const std::string &filename)
add_json_input Add the input parameters with a json file.
Definition parser.cpp:383
void enable_minimizer_options()
enable_minimizer_options Enables the options regarding the minimizer.
Definition parser.cpp:113
void add_argument_only_display(const std::string &argument, const std::string &description, const std::string &default_val)
add_argument Silently adds a new argument for the parser options.
Definition parser.cpp:129
void add_argument(const std::string &argument, bool required)
add_argument Silently adds a new argument for the parser options.
Definition parser.cpp:142
This classes calculates the Bounce action of the potential with a set temperature.
Definition CalculateEtaInterface.h:24
void ShowInputError()
ShowInputError shows all the available models in the terminal.
Definition parser.cpp:23
Definition parser.h:168
Definition parser.h:161