From c43c45f8f9975a329f60cfa5155d0821d8dc0718 Mon Sep 17 00:00:00 2001 From: weefuzzy Date: Fri, 25 Feb 2022 13:29:04 +0000 Subject: [PATCH] Wrapper: add choices param --- include/FluidCLIWrapper.hpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/include/FluidCLIWrapper.hpp b/include/FluidCLIWrapper.hpp index 449cc26..6869f0f 100644 --- a/include/FluidCLIWrapper.hpp +++ b/include/FluidCLIWrapper.hpp @@ -21,12 +21,13 @@ under the European Union’s Horizon 2020 research and innovation programme #include #include #include +#include #include #include #include #include #include - +#include namespace fluid { namespace client { @@ -245,6 +246,7 @@ class CLIWrapper } bool testString(ConstString s, BufferT::type) { return s[0] != '-'; } bool testString(ConstString s, InputBufferT::type) { return s[0] != '-'; } + bool testString(ConstString s, ChoicesT::type) { return s[0] != '-'; } template ErrorType checkValues(index& i, index argc, const char* argv[], index nArgs, @@ -319,6 +321,31 @@ class CLIWrapper return paramDescriptor().defaultValue; } + + auto fromString(ConstString s,ChoicesT::type) + { + // vector choices; + std::istringstream c(s); + c >> std::ws; + std::string tmp; + size_t choices{0}; + auto desc = paramDescriptor(); + while(std::getline(c,tmp,' ')) + { + index idx = desc.lookup(tmp); + + if( idx > -1) + { + choices = choices | 1 << idx; + continue; + } + std::cerr << "Warning: unrecognised option " << tmp << std::endl; + } + + return ChoicesT::type(choices); + + } + }; template