26#include "platform.hpp"
34using namespace std::literals;
72 return { .name =
name, .value = std::move(value) };
124 template<
typename ValueT>
128 for (
const auto& obj :
values)
129 if (obj.name == name)
131 if (value.
name ==
"")
133 output::error(
"ParameterMap::getItem"s,
"Name {0} not found."s, { name });
136 return std::any_cast<ValueT>(value.
value);
146 template<
typename ValueT>
147 ValueT
getItem(
const std::string& name,
const ValueT& fallback)
150 for (
const auto& obj :
values)
151 if (obj.name == name)
153 if (value.
name ==
"")
155 return std::any_cast<ValueT>(value.
value);
174 template<
typename... Params>
177 return { std::vector{ params... } };
182#define PARAM_GET(map, type, name) \
186 (name) = (map).template getItem<type>(#name); \
190#define PARAM_GET_FALLBACK(map, type, name, fallback) \
194 (name) = (map).template getItem<type>(#name, fallback); \
Contains the parameter utilities to allow named parameters to be passed into functions.
Definition parameter.cpp:26
ParameterMap processParams(Params... params)
Process parameters passed into a function.
Definition parameter.hpp:175
std::vector< ValuedParameter > ValueMap
A type containing all the parameters of a function, in calling order.
Definition parameter.hpp:53
void programSafeExit(const int status)
Exit the program safely.
Definition platform.hpp:61
void error(const std::string &name, const std::basic_string< T > &msg, const std::vector< std::string > &args={})
Prints an error message.
Definition output.hpp:80
An object containing all parameters and their values passed into a function.
Definition parameter.hpp:90
ValueMap values
All ValuedParameter objects passed to a function.
Definition parameter.hpp:91
ValueT getItem(const std::string &name, const ValueT &fallback)
Gets an item from the current parameter map. Returns the fallback the matching parameter if not found...
Definition parameter.hpp:147
ValueT getItem(const std::string &name)
Gets an item from the current parameter map.
Definition parameter.hpp:125
void checkParameterNameUnordered(const std::vector< std::string > &names)
Checks the presence of all the arguments, no matter which order they are specified....
Definition parameter.cpp:45
void checkParameterOrder(const std::vector< std::string > &names)
Checks the presence of all the arguments, in the order which they should be specified....
Definition parameter.cpp:27
ParameterMap(ValueMap values)
Initializes a new ParameterMap object.
Definition parameter.hpp:98
Stores the name of a parameter.
Definition parameter.hpp:60
ValuedParameter operator=(T value)
Shorthand function to facilitate setting values of parameters.
Definition parameter.hpp:70
Parameter & operator=(const Parameter &)=delete
std::string name
The name of the parameter.
Definition parameter.hpp:61
Parameter(std::string name)
Initializes a new Parameter object.
Definition parameter.hpp:82
A parameter with a name and value.
Definition parameter.hpp:47
std::string name
The name of the parameter.
Definition parameter.hpp:48
std::any value
The value of the parameter.
Definition parameter.hpp:49