21 #ifndef mia_core_cmdparamlineparser_hh
22 #define mia_core_cmdparamlineparser_hh
67 virtual bool do_set_value(
const char *str_value);
68 virtual size_t do_get_needed_args()
const;
69 virtual void do_write_value(std::ostream& os)
const;
70 virtual const std::string do_get_value_as_string()
const;
112 virtual bool do_set_value(
const char *str_value);
113 virtual size_t do_get_needed_args()
const;
114 virtual void do_write_value(std::ostream& os)
const;
115 virtual const std::string do_get_value_as_string()
const;
116 std::vector<T>& m_value;
134 template <
typename T>
135 struct __dispatch_opt {
139 static void init(T& )
148 static bool apply(
const char *svalue, T& value)
150 std::istringstream sval(svalue);
153 while (isspace(sval.peek())) {
161 static size_t size(
const T )
171 static void apply(std::ostream& os,
const T& value,
bool )
173 os <<
"=" << value <<
" ";
181 static const std::string get_as_string(
const T& value)
183 std::ostringstream os;
194 template <
typename T>
195 struct __dispatch_opt<
std::vector<T>> {
196 static void init(std::vector<T>& )
199 static bool apply(
const char *svalue, std::vector<T>& value)
201 std::string h(svalue);
204 for (std::string::iterator hb = h.begin(); hb != h.end(); ++hb)
210 if (!value.empty()) {
211 if (n > value.size()) {
212 throw create_exception<std::invalid_argument>(
"Expect only ", value.size(),
213 " coma separated values, but '",
214 svalue,
"' provides ", n);
220 std::istringstream sval(h);
221 auto i = value.begin();
223 while (!sval.eof()) {
231 static size_t size(
const std::vector<T>& )
236 static void apply(std::ostream& os,
const std::vector<T>& value,
bool required)
243 for (
auto i = value.begin(); i != value.end(); ++i) {
244 if (i != value.begin())
254 static const std::string get_as_string(
const std::vector<T>& value)
256 std::ostringstream os;
258 for (
auto i = value.begin(); i != value.end(); ++i) {
259 if (i != value.begin())
278 struct __dispatch_opt<bool> {
279 static void init(
bool& value)
283 static bool apply(
const char *,
bool& value)
288 static size_t size(
bool )
292 static void apply(std::ostream& ,
bool ,
bool )
295 static const std::string get_as_string(
const bool& value)
297 return value ?
"true" :
"false";
311 struct __dispatch_opt<
std::string> {
312 static void init(std::string& )
315 static bool apply(
const char *svalue, std::string& value)
317 value = std::string(svalue);
320 static size_t size(std::string )
324 static void apply(std::ostream& os,
const std::string& value,
bool required)
334 static const std::string get_as_string(
const std::string& value)
345 template <
typename T>
347 const char *long_help,
const char *short_help,
349 CCmdOption(short_opt, long_opt, long_help, short_help, flags),
352 __dispatch_opt<T>::init(m_value);
355 template <
typename T>
358 return __dispatch_opt<T>::apply(svalue, m_value);
361 template <
typename T>
364 return __dispatch_opt<T>::size(m_value);
367 template <
typename T>
370 __dispatch_opt<T>::apply( os, m_value, is_required());
373 template <
typename T>
377 do_get_long_help(os);
378 xmlhelp_set_attribute(parent,
"type", __type_descr<T>::value);
381 template <
typename T>
384 return __dispatch_opt<T>::get_as_string(m_value);
388 template <
typename T>
390 const char *long_help,
391 const char *short_help,
393 CCmdOption(short_opt, long_opt, long_help, short_help, flags),
396 __dispatch_opt<std::vector<T>>::init(m_value);
399 template <
typename T>
403 do_get_long_help(os);
404 xmlhelp_set_attribute(parent,
"type", __type_descr<T>::value);
405 xmlhelp_set_attribute(parent,
"repeatable",
"1");
408 template <
typename T>
412 bool good = __dispatch_opt<T>::apply(str_value, value);
415 m_value.push_back(value);
421 template <
typename T>
427 template <
typename T>
430 __dispatch_opt<std::vector<T>>::apply( os, m_value, is_required());
433 template <
typename T>
436 return __dispatch_opt<std::vector<T>>::get_as_string(m_value);
457 template <
typename T>
482 template <
typename T>
The base class for all command line options.
const char * long_help() const
This class implements a facade for the xml Element.
Templated version based on CCmdOptionValue for values that can be converted to and from strings by st...
TCmdOption(T &val, char short_opt, const char *long_opt, const char *long_help, const char *short_help, CCmdOptionFlags flags=CCmdOptionFlags::none)
Templated version based on CCmdOptionValue for values that can be converted to and from strings by st...
TRepeatableCmdOption(std::vector< T > &val, char short_opt, const char *long_opt, const char *long_help, const char *short_help, CCmdOptionFlags flags=CCmdOptionFlags::none)
std::shared_ptr< CCmdOption > PCmdOption
a shared pointer definition of the Option
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
#define NS_MIA_END
conveniance define to end the mia namespace
PCmdOption make_repeatable_opt(std::vector< T > &value, const char *long_opt, char short_opt, const char *help, CCmdOptionFlags flags=CCmdOptionFlags::none)
Create a repeatable option to set a vector of values.
PCmdOption make_opt(std::vector< T > &value, const char *long_opt, char short_opt, const char *help, CCmdOptionFlags flags=CCmdOptionFlags::none)
Create an option to set a vector of values,.
std::map< std::string, const CPluginHandlerBase * > HandlerHelpMap
A map that is used to collect the plug-in handlers used in a program.