Currently the PARAMETER macro only accepts a regex string. But there are quite some occasions where a custom parameter is nothing more than mapping a string to values. This can for example be used to create a custom parameter based on enums:
// somewhere
enum class State{
connected,
disconnected,
standby,
shutdown
}
namespace{
const std::map<std::string, State> stateMap{
{"connected", State::connected},
{"disconnected", State::disconnected},
{"standby", State::standby},
{"shutdown", State::shutdown},
};
}
PARAMETER_MAP("state", stateMap, true);
// PARAMETER_MAP does the heavy lifting of transforming all the keys from the provided
// map in to a regex that would look like: `(connected|disconnected|standby|shutdown)`
// it also takes care of creating a simple implementation that takes a string
// and uses the .at function on the provided map using the captured argument
// it could potentially look something like this (pseudo-code-ish)
#define PARAMETER_MAP(name, map, snippet) \
PARAMETER(decltype(map)::value_type, (name, transformKeysToRegex(map), snippet), (const std::string& key)) \
{ \
return map.at(key); \
}
Currently the PARAMETER macro only accepts a regex string. But there are quite some occasions where a custom parameter is nothing more than mapping a string to values. This can for example be used to create a custom parameter based on enums: