23 #ifndef DtCmdLine_MULTIPLE_ARGUMENT_H
24 #define DtCmdLine_MULTIPLE_ARGUMENT_H
44 #if defined(HAVE_SSTREAM)
46 #elif defined(HAVE_STRSTREAM)
49 #error "Need a stringstream (sstream or strstream) to compile!"
52 #ifdef DtUSE_UTILITIES_NAMESPACE
53 namespace DtUSE_UTILITIES_NAMESPACE
59 template<
class T>
class MultiArg;
61 namespace MULTI_ARG_HELPER {
99 int extractValue(
const std::string& val )
103 #if defined(HAVE_SSTREAM)
104 std::istringstream is(val);
105 #elif defined(HAVE_STRSTREAM)
106 std::istrstream is(val.c_str());
108 #error "Need a stringstream (sstream or strstream) to compile!"
115 if ( is.peek() != EOF )
126 if ( valuesRead > 1 )
129 _values.push_back(temp);
151 std::vector<std::string> &_values;
164 int extractValue(
const std::string& val )
166 _values.push_back( val );
208 void _extractValue(
const std::string& val );
214 void _checkAllowed(
const std::string& val );
236 const std::string& name,
237 const std::string& desc,
239 const std::string& typeDesc,
261 const std::string& name,
262 const std::string& desc,
264 const std::string& typeDesc,
284 const std::string& name,
285 const std::string& desc,
287 const std::vector<T>& allowed,
307 const std::string& name,
308 const std::string& desc,
310 const std::vector<T>& allowed,
322 virtual bool processArg(
int* i, std::vector<std::string>& args);
328 const std::vector<T>& getValue()
const;
334 virtual std::string shortID(
const std::string& val=
"val")
const;
340 virtual std::string longID(
const std::string& val=
"val")
const;
346 virtual bool isRequired()
const;
362 for (
unsigned int i = 0; i < _allowed.size(); i++ )
365 #if defined(HAVE_SSTREAM)
366 std::ostringstream os;
367 #elif defined(HAVE_STRSTREAM)
370 #error "Need a stringstream (sstream or strstream) to compile!"
375 std::string temp( os.str() );
389 const std::string& name,
390 const std::string& desc,
392 const std::string& typeDesc,
394 :
Arg( flag, name, desc, req, true, v ),
395 _typeDesc( typeDesc )
400 const std::string& name,
401 const std::string& desc,
403 const std::string& typeDesc,
406 :
Arg( flag, name, desc, req, true, v ),
407 _typeDesc( typeDesc )
417 const std::string& name,
418 const std::string& desc,
420 const std::vector<T>& allowed,
422 :
Arg( flag, name, desc, req, true, v ),
430 const std::string& name,
431 const std::string& desc,
433 const std::vector<T>& allowed,
436 :
Arg( flag, name, desc, req, true, v ),
458 if ( _hasBlanks( args[*i] ) )
461 std::string flag = args[*i];
462 std::string value =
"";
464 trimFlag( flag, value );
466 if ( argMatches( flag ) )
470 "Couldn't find delimiter for this argument!",
476 if ( (
unsigned int)*i < args.size() )
477 _extractValue( args[*i] );
483 _extractValue( value );
499 if ( _allowed.size() > 0 )
500 if ( std::find(_allowed.begin(),_allowed.end(),_values.back())
503 "' in allowed list.", toString() ) );
523 std::string
id =
Arg::longID(_typeDesc) +
" (accepted multiple times)";
537 if ( _values.size() > 1 )
556 "from string '" + val +
"'", toString() ) );
560 "parsed from string '" + val +
"'",
562 _checkAllowed( val );
568 #ifdef DtUSE_UTILITIES_NAMESPACE