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>
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>
79void Hide_(
const std::string& paramName);
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,
107void printUsage(
const std::string& helpPreamble,
114 const std::string&)>,
115 std::set<std::string>&,
141 const std::string& helpPreamble =
"");
184template <
class Param>
187 using ParamType = std::conditional_t<std::is_same_v<
decltype(Param::value),
188 const char*
const>, std::string,
189 std::remove_const_t<
decltype(Param::value)>>;
191 return detail::Get_(detail::getParamName<Param>(),
209template <
class Param>
212 const std::string paramName = detail::getParamName<Param>();
213 std::ostringstream
oss;
215 detail::SetDefault_(paramName,
oss.str());
223 Parameter(
const std::string&
k,
const std::string&
v)
227 friend std::ostream& operator<<(std::ostream&
os,
const Parameter& param)
229 os << param.key <<
"=\"" << param.value <<
'"';
244 std::string key, value;
267template <
class Param>
289template <
class Param>
292 const std::string paramName = detail::getParamName<Param>();
293 const auto defaultValue = Param::value;
294 using ParamType = std::conditional_t<std::is_same_v<
decltype(defaultValue),
295 const char*
const>, std::string,
296 std::remove_const_t<
decltype(defaultValue)>>;
298 std::ostringstream
oss;
300 detail::Register_(paramName, Dune::className<ParamType>(),
oss.str(), usageString);
308template <
class Param>
311 detail::Hide_(detail::getParamName<Param>());
318bool IsRegistrationOpen();
327void endRegistration();
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
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:635
void printValues(std::ostream &os)
Print values of the run-time parameters.
Definition parametersystem.cpp:742
bool parseParameterFile(const std::string &fileName, bool overwrite)
Read the parameters from an INI-style file.
Definition parametersystem.cpp:562
void getLists(std::vector< Parameter > &usedParams, std::vector< Parameter > &unusedParams)
Retrieves the lists of parameters specified at runtime and their values.
Definition parametersystem.cpp:504
void reset()
Reset parameter system.
Definition parametersystem.cpp:484
bool printUnused(std::ostream &os)
Print the list of unused run-time parameters.
Definition parametersystem.cpp:791
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:120
void SetDefault(decltype(Param::value) new_value)
Set a runtime parameter.
Definition parametersystem.hpp:210
bool IsSet(bool errorIfNotRegistered=true)
Returns true if a parameter has been specified at runtime, false otherwise.
Definition parametersystem.hpp:268
void Register(const char *usageString)
Register a run-time parameter.
Definition parametersystem.hpp:290
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:309
auto Get(bool errorIfNotRegistered=true)
Retrieve a runtime parameter.
Definition parametersystem.hpp:185
A struct holding the key-value pair for a parameter.
Definition parametersystem.hpp:222
Definition parametersystem.hpp:50