84 void parse(
const int argc,
char** argv);
94 template <
typename TValue>
95 TValue
getArg(
const std::string& name)
const {
96 throwIfUnknownArg(name);
98 if (value && value->has<TValue>()) {
99 return value->get<TValue>();
101 const std::string message = value ?
"Invalid type of argument -" :
"Missing argument -" + name;
109 template <
typename TValue>
111 throwIfUnknownArg(name);
114 if (!value->has<TValue>()) {
117 return value->get<TValue>();
133 template <
typename TEnum,
typename TConvertor>
135 throwIfUnknownArg(name);
136 auto value = params.
tryGet(name);
139 if (value->has<
Float>()) {
140 settings.
set(idx, conv(value->get<
Float>()));
142 forValue(value.value(), [&settings, idx](
auto& value) { settings.set(idx, value); });
152 template <
typename TEnum>
154 return tryStore(settings, name, idx, [](
Float value) {
return value; });
162 template <
typename TFunctor>
164 for (
auto& e : params) {
165 forValue(e.value, [&e, &functor](
auto& value) { functor(e.key, value); });
171 return params.
size();
176 return params.
empty();
180 void parseValuelessArg(
const ArgDesc& desc);
182 void parseValueArg(
const ArgDesc& desc,
const std::string& value);
184 template <
typename TValue>
185 void insertArg(
const std::string& name,
const std::string& textValue);
187 void throwIfUnknownArg(
const std::string& name)
const;
@ NONE
No collision took place.
Key-value associative container implemented as a sorted array.
Generic wrappers of lambdas, functors and other callables.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Logging routines of the run.
#define NAMESPACE_SPH_END
const NothingType NOTHING
Object capable of storing values of different types.
decltype(auto) INLINE forValue(Variant< TArgs... > &variant, TFunctor &&functor)
Exception thrown if the arguments are invalid.
ArgError(const std::string &message)
Provides functions for parsing command-line arguments.
bool empty() const
Returns true if no arguments have been parsed.
bool tryStore(Settings< TEnum > &settings, const std::string &name, const TEnum idx, TConvertor &&conv)
Stores the value of given argument into an instance of Settings.
void parse(const int argc, char **argv)
Parses the input arguments and stored the parsed values.
TValue getArg(const std::string &name) const
Returns the value of an argument, given its short name (without the dash).
Optional< TValue > tryGetArg(const std::string &name) const
Returns the value of an argument or NOTHING if the argument was not parsed.
void printHelp(ILogger &logger)
Prints the help information into given logger.
bool tryStore(Settings< TEnum > &settings, const std::string &name, const TEnum idx)
Stores the value of given argument into an instance of Settings.
Size size() const
Returns the number of parsed arguments.
ArgParser(ArrayView< const ArgDesc > args)
Creates a parser, given a set of parameter descriptors.
void forEach(const TFunctor &functor)
Enumerates all parsed arguments and executes a generic functor with parsed values.
Object providing safe access to continuous memory of data.
Container of key-value pairs.
INLINE Size empty() const
Returns true if the map contains no elements, false otherwise.
INLINE Optional< TValue & > tryGet(const TKey &key)
Returns a reference to the value matching the given key, or NOTHING if no such value exists.
INLINE Size size() const
Returns the number of elements in the map.
Exception thrown when used passes -h or –help parameter.
HelpException(const std::string &message)
Interface providing generic (text, human readable) output of the program.
Wrapper of type value of which may or may not be present.
Generic object containing various settings and parameters of the run.
Settings & set(const TEnum idx, TValue &&value, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0)
Saves a value into the settings.
Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
Generic storage and input/output routines of settings.
Descriptor of a command-line argument.
std::string shortName
Short name, prefixed by single dash (e.g. -h)
std::string longName
Long name, prefixed by double-dash (e.g. –help)
bool matches(const std::string &name)
Checks if the descriptor matches given argument.
std::string desc
Parameter description, printed in help.
Function< void()> callback
Generic callback executed when the parameter is parsed.
ArgEnum type
Type of the parameter.