21 #ifndef mia_core_cmdparamlineparser_hh
22 #define mia_core_cmdparamlineparser_hh
66 virtual bool do_set_value(
const char *str_value);
67 virtual size_t do_get_needed_args()
const;
68 virtual void do_write_value(std::ostream& os)
const;
69 virtual const std::string do_get_value_as_string()
const;
110 virtual bool do_set_value(
const char *str_value);
111 virtual size_t do_get_needed_args()
const;
112 virtual void do_write_value(std::ostream& os)
const;
113 virtual const std::string do_get_value_as_string()
const;
114 std::vector<T>& m_value;
132 template <
typename T>
133 struct __dispatch_opt {
137 static void init(T& ){
145 static bool apply(
const char *svalue, T& value) {
146 std::istringstream sval(svalue);
149 while (isspace(sval.peek())) {
156 static size_t size(
const T ) {
165 static void apply(std::ostream& os,
const T& value,
bool ) {
166 os <<
"=" << value <<
" ";
174 static const std::string get_as_string(
const T& value) {
175 std::ostringstream os;
186 template <
typename T>
187 struct __dispatch_opt<
std::vector<T> > {
188 static void init(std::vector<T>& ){
191 static bool apply(
const char *svalue, std::vector<T>& value) {
192 std::string h(svalue);
194 for(std::string::iterator hb = h.begin(); hb != h.end(); ++hb)
201 if (!value.empty()) {
202 if (n > value.size()) {
203 throw create_exception<std::invalid_argument>(
"Expect only ", value.size(),
204 " coma separated values, but '",
205 svalue,
"' provides ", n);
211 std::istringstream sval(h);
212 auto i = value.begin();
213 while (!sval.eof()) {
220 static size_t size(
const std::vector<T>& ) {
224 static void apply(std::ostream& os,
const std::vector<T>& value,
bool required) {
230 for (
auto i = value.begin(); i != value.end(); ++i) {
231 if (i != value.begin())
239 static const std::string get_as_string(
const std::vector<T>& value) {
240 std::ostringstream os;
241 for (
auto i = value.begin(); i != value.end(); ++i) {
242 if (i != value.begin())
259 struct __dispatch_opt<bool> {
260 static void init(
bool& value) {
263 static bool apply(
const char *,
bool& value) {
267 static size_t size(
bool ) {
270 static void apply(std::ostream& ,
bool ,
bool ) {
272 static const std::string get_as_string(
const bool& value) {
273 return value ?
"true" :
"false";
287 struct __dispatch_opt<
std::string> {
288 static void init(std::string& ) {
290 static bool apply(
const char *svalue, std::string& value) {
291 value = std::string(svalue);
294 static size_t size(std::string ) {
297 static void apply(std::ostream& os,
const std::string& value,
bool required) {
306 static const std::string get_as_string(
const std::string& value) {
316 template <
typename T>
318 const char *long_help,
const char *short_help,
320 CCmdOption(short_opt, long_opt, long_help, short_help, flags),
323 __dispatch_opt<T>::init(m_value);
326 template <
typename T>
329 return __dispatch_opt<T>::apply(svalue, m_value);
332 template <
typename T>
335 return __dispatch_opt<T>::size(m_value);
338 template <
typename T>
341 __dispatch_opt<T>::apply( os, m_value, is_required());
344 template <
typename T>
348 do_get_long_help(os);
349 xmlhelp_set_attribute(parent,
"type", __type_descr<T>::value);
352 template <
typename T>
355 return __dispatch_opt<T>::get_as_string(m_value);
359 template <
typename T>
361 const char *long_help,
362 const char *short_help,
364 CCmdOption(short_opt, long_opt, long_help, short_help, flags),
367 __dispatch_opt<std::vector<T>>::init(m_value);
370 template <
typename T>
374 do_get_long_help(os);
375 xmlhelp_set_attribute(parent,
"type", __type_descr<T>::value);
376 xmlhelp_set_attribute(parent,
"repeatable",
"1");
379 template <
typename T>
383 bool good = __dispatch_opt<T>::apply(str_value, value);
385 m_value.push_back(value);
392 template <
typename T>
398 template <
typename T>
401 __dispatch_opt<std::vector<T>>::apply( os, m_value, is_required());
404 template <
typename T>
407 return __dispatch_opt<std::vector<T>>::get_as_string(m_value);
428 template <
typename T>
453 template <
typename T>