34 #ifndef SOMAIO_GETOPT_GETOPT_H 35 #define SOMAIO_GETOPT_GETOPT_H 59 std::runtime_error( message ) {}
73 std::runtime_error( message ) {}
86 const std::string &value );
88 std::runtime_error( message ) {}
106 virtual bool recognizeName(
const std::string & ) = 0;
107 virtual bool feed(
const std::string & ) = 0;
108 virtual void check() = 0;
111 OptionBase(
const std::string &name,
const std::string &info );
114 inline void addName(
const std::string &name );
115 inline const std::string &name()
const;
116 std::string names()
const;
117 inline bool _nameInList(
const std::string &name )
const;
121 virtual std::string info()
const = 0;
129 _names.push_back( name );
135 return *_names.begin();
141 return find( _names.begin(), _names.end(), name ) != _names.end();
149 template <
typename T>
154 OptionSeries( T &serie,
const std::string &name,
const std::string &info,
155 unsigned numMin,
unsigned numMax );
158 virtual bool recognizeName(
const std::string & );
159 virtual bool feed(
const std::string & );
160 virtual void check();
161 virtual std::string info()
const;
164 unsigned _numMin, _numMax;
165 typename T::iterator _storeNextValue;
166 unsigned _numValuesStored;
170 template <
typename T>
174 template <
typename T>
inline 176 const std::string &info,
177 unsigned numMin,
unsigned numMax ) :
182 _storeNextValue( _values.begin() ),
183 _numValuesStored( 0 )
188 template <
typename T>
inline 192 if ( _numMax && _numValuesStored >= _numMax ) {
201 template <
typename T>
inline 204 if ( _numMax == 0 || _numValuesStored < _numMax ) {
205 if ( _storeNextValue == _values.end() ) {
206 _values.push_back(
typename T::value_type() );
207 stringTo< typename T::value_type >( value, *(_values.rbegin()) );
208 _storeNextValue = _values.end();
210 stringTo< typename T::value_type >( value, *_storeNextValue );
220 template <
typename T>
inline 227 template <
typename T>
inline 233 return std::string(
"[ " ) +
names() +
" <" 246 template <
typename T>
258 const std::string &info,
bool optional );
261 virtual bool recognizeName(
const std::string & );
262 virtual bool feed(
const std::string & );
263 virtual void check();
264 std::string info()
const;
268 template <
typename T>
272 template <
typename T>
274 const std::string &info,
278 _optional( optional ),
284 template <
typename T>
287 if( _nameInList( n ) ) {
297 template <
typename T>
303 stringTo< T >( value, _value );
310 template <
typename T>
inline 313 if ( ! _optional && ! _valueRead ) {
319 template <
typename T>
inline 323 return std::string(
"[ " ) + names() +
" <" 351 template <
class NumberType>
366 template <
class NumberType>
374 const std::string &name,
375 const std::string &info,
bool optional );
378 virtual bool recognizeName(
const std::string & );
379 virtual bool feed(
const std::string & );
380 std::string info()
const;
384 template <
typename NumberType>
387 const std::string &name,
388 const std::string &info,
bool optional ) :
389 SingleOption<NumberType>( value.value, name, info, optional ) {}
392 template <
typename NumberType>
396 template <
typename NumberType>
404 this->
_value = NumberType( 1 );
412 template <
typename NumberType>
419 stringTo< NumberType >( value, this->
_value );
430 template <
class NumberType>
inline 433 return std::string(
"[ " ) + this->
names() +
" [ <" 435 +
"> ] ]\n" + this->
_info;
508 template <
typename T>
509 void addOption( T & param,
const std::string & token,
510 const std::string & description,
511 bool optional =
false );
531 template <
typename T>
532 void addOptionSeries( T & param,
const std::string & token,
533 const std::string & description,
unsigned minnum = 0,
534 unsigned maxnum = 0 );
536 void alias(
const std::string &to,
const std::string &from );
549 template <
typename T>
inline 551 const std::string &
info,
bool optional )
557 template <
typename T>
inline 559 const std::string &
info,
560 unsigned numMin,
unsigned numMax )
562 pushOption(
new OptionSeries<T>( values, name, info, numMin, numMax ) );
583 std::string _documentation;
589 const std::string &documentation );
596 virtual void initialize();
614 std::runtime_error( message ) {}
620 #endif // ifndef CARTO_GETOPT_GETOPT_H
unexpected_option(const std::string &message, bool)
std::vector< OptionBase *> OptionList
virtual bool recognizeName(const std::string &)
void addOptionSeries(T ¶m, const std::string &token, const std::string &description, unsigned minnum=0, unsigned maxnum=0)
Adds a series of parameters to be parsed on the commandline.
SingleOption(T &value, const std::string &name, const std::string &info, bool optional)
Cartograph options parser.
std::vector< std::string > _names
void addOption(T ¶m, const std::string &token, const std::string &description, bool optional=false)
Adds a single parameter to be parsed on the commandline.
unexpected_option_value(const std::string &message, bool)
void addName(const std::string &name)
bool _nameInList(const std::string &name) const
virtual bool feed(const std::string &)
missing_option(const std::string &optionName)
BoolOrNumber(NumberType &v)
friend class OptionsParser
Commandline options parser.
std::string names() const
std::vector< std::string > CommandLineArguments
const std::string & name() const
user_interruption(const std::string &message)
missing_option(const std::string &message, bool)
A special exception which is thrown after a command help is requested and displayed in a CartoApplica...