32#ifndef OPM_PARAMETER_SYSTEM_HPP
33#define OPM_PARAMETER_SYSTEM_HPP
35#include <dune/common/classname.hh>
45namespace Opm::Parameters {
49template <
typename,
class =
void>
53struct has_name<T, std::void_t<decltype(std::declval<T>().name)>>
54:
public std::true_type {};
57template<
class Parameter>
61 return Parameter::name;
63 std::string paramName = Dune::className<Parameter>();
64 paramName.replace(0, std::strlen(
"Opm::Parameters::"),
"");
65 const auto pos = paramName.find_first_of(
'<');
66 if (pos != std::string::npos) {
74template<
class ParamType>
75ParamType Get_(
const std::string& paramName, ParamType defaultValue,
76 bool errorIfNotRegistered);
79void Hide_(
const std::string& paramName);
82bool IsSet_(
const std::string& paramName,
bool errorIfNotRegistered);
85void Register_(
const std::string& paramName,
86 const std::string& paramTypeName,
87 const std::string& defaultValue,
88 const char* usageString);
91void SetDefault_(
const std::string& paramName,
92 const std::string& paramValue);
108void printUsage(
const std::string& helpPreamble,
110 const std::string& errorMsg =
"",
111 const bool showAll =
false);
115 const std::string&)>,
116 std::set<std::string>&,
143 const std::string& helpPreamble =
"");
186template <
class Param>
187auto Get(
bool errorIfNotRegistered =
true)
189 using ParamType = std::conditional_t<std::is_same_v<
decltype(Param::value),
190 const char*
const>, std::string,
191 std::remove_const_t<
decltype(Param::value)>>;
192 ParamType defaultValue = Param::value;
194 defaultValue, errorIfNotRegistered);
211template <
class Param>
215 std::ostringstream oss;
225 Parameter(
const std::string& k,
const std::string& v)
229 friend std::ostream& operator<<(std::ostream& os,
const Parameter& param)
231 os << param.key <<
"=\"" << param.value <<
'"';
235 bool operator==(
const Parameter& setting)
const
237 return setting.key == key
238 && setting.value == value;
241 bool operator !=(
const Parameter& setting)
const
243 return !(*
this == setting);
246 std::string key, value;
255void getLists(std::vector<Parameter>& usedParams,
256 std::vector<Parameter>& unusedParams);
269template <
class Param>
270bool IsSet(
bool errorIfNotRegistered =
true)
291template <
class Param>
295 const auto defaultValue = Param::value;
296 using ParamType = std::conditional_t<std::is_same_v<
decltype(defaultValue),
297 const char*
const>, std::string,
298 std::remove_const_t<
decltype(defaultValue)>>;
300 std::ostringstream oss;
302 detail::Register_(paramName, Dune::className<ParamType>(), oss.str(), usageString);
310template <
class Param>
320bool IsRegistrationOpen();
329void endRegistration();
std::string parseCommandLineOptions(int argc, const char **argv, const PositionalArgumentCallback &posArgCallback, const std::string &helpPreamble)
Parse the parameters provided on the command line.
Definition parametersystem.cpp:636
void printValues(std::ostream &os)
Print values of the run-time parameters.
Definition parametersystem.cpp:741
bool IsSet_(const std::string ¶mName, bool errorIfNotRegistered)
Private implementation.
Definition parametersystem.cpp:426
bool parseParameterFile(const std::string &fileName, bool overwrite)
Read the parameters from an INI-style file.
Definition parametersystem.cpp:563
ParamType Get_(const std::string ¶mName, ParamType defaultValue, bool errorIfNotRegistered)
Private implementation.
Definition parametersystem.cpp:363
void getLists(std::vector< Parameter > &usedParams, std::vector< Parameter > &unusedParams)
Retrieves the lists of parameters specified at runtime and their values.
Definition parametersystem.cpp:505
void reset()
Reset parameter system.
Definition parametersystem.cpp:485
void Register_(const std::string ¶mName, const std::string ¶mTypeName, const std::string &defaultValue, const char *usageString)
Private implementation.
Definition parametersystem.cpp:444
bool printUnused(std::ostream &os)
Print the list of unused run-time parameters.
Definition parametersystem.cpp:790
void SetDefault_(const std::string ¶mName, const std::string ¶mValue)
Private implementation.
Definition parametersystem.cpp:473
void Hide_(const std::string ¶mName)
Private implementation.
Definition parametersystem.cpp:409
void SetDefault(decltype(Param::value) new_value)
Set a runtime parameter.
Definition parametersystem.hpp:212
bool IsSet(bool errorIfNotRegistered=true)
Returns true if a parameter has been specified at runtime, false otherwise.
Definition parametersystem.hpp:270
void Register(const char *usageString)
Register a run-time parameter.
Definition parametersystem.hpp:292
std::function< int(std::function< void(const std::string &, const std::string &)>, std::set< std::string > &, std::string &, int, const char **, int, int)> PositionalArgumentCallback
Callback function for command line parsing.
Definition parametersystem.hpp:114
auto getParamName()
get the name data member of a parameter
Definition parametersystem.hpp:58
void Hide()
Indicate that a given parameter should not be mentioned in the help message.
Definition parametersystem.hpp:311
auto Get(bool errorIfNotRegistered=true)
Retrieve a runtime parameter.
Definition parametersystem.hpp:187
Definition parametersystem.hpp:50