ValueArg.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * file: ValueArg.h
4  *
5  * Copyright (c) 2003, Michael E. Smoot .
6  * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno.
7  * All rights reverved.
8  *
9  * See the file COPYING in the top directory of this distribution for
10  * more information.
11  *
12  * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
13  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18  * DEALINGS IN THE SOFTWARE.
19  *
20  *****************************************************************************/
21 
22 
23 #ifndef TCLAP_VALUE_ARGUMENT_H
24 #define TCLAP_VALUE_ARGUMENT_H
25 
26 #include <string>
27 #include <vector>
28 
29 #include <tclap/Arg.h>
30 #include <tclap/Constraint.h>
31 
32 namespace TCLAP {
33 
42 template<class T>
43 class ValueArg : public Arg
44 {
45  protected:
46 
53 
59 
68 
73 
80  void _extractValue( const std::string& val );
81 
82  public:
83 
107  ValueArg( const std::string& flag,
108  const std::string& name,
109  const std::string& desc,
110  bool req,
111  T value,
112  const std::string& typeDesc,
113  Visitor* v = NULL);
114 
115 
140  ValueArg( const std::string& flag,
141  const std::string& name,
142  const std::string& desc,
143  bool req,
144  T value,
145  const std::string& typeDesc,
147  Visitor* v = NULL );
148 
171  ValueArg( const std::string& flag,
172  const std::string& name,
173  const std::string& desc,
174  bool req,
175  T value,
176  Constraint<T>* constraint,
178  Visitor* v = NULL );
179 
201  ValueArg( const std::string& flag,
202  const std::string& name,
203  const std::string& desc,
204  bool req,
205  T value,
206  Constraint<T>* constraint,
207  Visitor* v = NULL );
208 
218  virtual bool processArg(int* i, std::vector<std::string>& args);
219 
223  T& getValue() ;
224 
229  virtual std::string shortID(const std::string& val = "val") const;
230 
235  virtual std::string longID(const std::string& val = "val") const;
236 
237  virtual void reset() ;
238 
239 private:
243  ValueArg<T>(const ValueArg<T>& rhs);
244  ValueArg<T>& operator=(const ValueArg<T>& rhs);
245 };
246 
247 
251 template<class T>
253  const std::string& name,
254  const std::string& desc,
255  bool req,
256  T val,
257  const std::string& typeDesc,
258  Visitor* v)
259 : Arg(flag, name, desc, req, true, v),
260  _value( val ),
261  _default( val ),
262  _typeDesc( typeDesc ),
263  _constraint( NULL )
264 { }
265 
266 template<class T>
268  const std::string& name,
269  const std::string& desc,
270  bool req,
271  T val,
272  const std::string& typeDesc,
274  Visitor* v)
275 : Arg(flag, name, desc, req, true, v),
276  _value( val ),
277  _default( val ),
278  _typeDesc( typeDesc ),
279  _constraint( NULL )
280 {
281  parser.add( this );
282 }
283 
284 template<class T>
286  const std::string& name,
287  const std::string& desc,
288  bool req,
289  T val,
290  Constraint<T>* constraint,
291  Visitor* v)
292 : Arg(flag, name, desc, req, true, v),
293  _value( val ),
294  _default( val ),
295  _typeDesc( constraint->shortID() ),
296  _constraint( constraint )
297 { }
298 
299 template<class T>
301  const std::string& name,
302  const std::string& desc,
303  bool req,
304  T val,
305  Constraint<T>* constraint,
307  Visitor* v)
308 : Arg(flag, name, desc, req, true, v),
309  _value( val ),
310  _default( val ),
311  _typeDesc( constraint->shortID() ),
312  _constraint( constraint )
313 {
314  parser.add( this );
315 }
316 
317 
321 template<class T>
323 
327 template<class T>
328 bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args)
329 {
330  if ( _ignoreable && Arg::ignoreRest() )
331  return false;
332 
333  if ( _hasBlanks( args[*i] ) )
334  return false;
335 
336  std::string flag = args[*i];
337 
338  std::string value = "";
339  trimFlag( flag, value );
340 
341  if ( argMatches( flag ) )
342  {
343  if ( _alreadySet )
344  {
345  if ( _xorSet )
346  throw( CmdLineParseException(
347  "Mutually exclusive argument already set!",
348  toString()) );
349  else
350  throw( CmdLineParseException("Argument already set!",
351  toString()) );
352  }
353 
354  if ( Arg::delimiter() != ' ' && value == "" )
355  throw( ArgParseException(
356  "Couldn't find delimiter for this argument!",
357  toString() ) );
358 
359  if ( value == "" )
360  {
361  (*i)++;
362  if ( static_cast<unsigned int>(*i) < args.size() )
363  _extractValue( args[*i] );
364  else
365  throw( ArgParseException("Missing a value for this argument!",
366  toString() ) );
367  }
368  else
369  _extractValue( value );
370 
371  _alreadySet = true;
373  return true;
374  }
375  else
376  return false;
377 }
378 
382 template<class T>
384 {
385  static_cast<void>(val); // Ignore input, don't warn
386  return Arg::shortID( _typeDesc );
387 }
388 
392 template<class T>
394 {
395  static_cast<void>(val); // Ignore input, don't warn
396  return Arg::longID( _typeDesc );
397 }
398 
399 template<class T>
401 {
402  try {
404  } catch( ArgParseException &e) {
405  throw ArgParseException(e.error(), toString());
406  }
407 
408  if ( _constraint != NULL )
409  if ( ! _constraint->check( _value ) )
410  throw( CmdLineParseException( "Value '" + val +
411  + "' does not meet constraint: "
412  + _constraint->description(),
413  toString() ) );
414 }
415 
416 template<class T>
418 {
419  Arg::reset();
420  _value = _default;
421 }
422 
423 } // namespace TCLAP
424 
425 #endif
bool _alreadySet
Definition: Arg.h:137
virtual std::string longID(const std::string &val="val") const
Definition: ValueArg.h:393
void _extractValue(const std::string &val)
Definition: ValueArg.h:400
Definition: Arg.h:64
GLuint const GLchar * name
virtual void trimFlag(std::string &flag, std::string &value) const
Definition: Arg.h:620
virtual std::string longID(const std::string &valueId="val") const
Definition: Arg.h:523
bool _hasBlanks(const std::string &s) const
Definition: Arg.h:641
GLfloat value
virtual std::string shortID(const std::string &val="val") const
Definition: ValueArg.h:383
parser
Definition: enums.py:61
GLsizei const GLchar *const * string
void _checkWithVisitor() const
Definition: Arg.h:611
virtual void reset()
Definition: Arg.h:679
bool _xorSet
Definition: Arg.h:156
e
Definition: rmse.py:177
static char delimiter()
Definition: Arg.h:211
GLuint GLfloat * val
std::string error() const
Definition: ArgException.h:64
virtual std::string shortID(const std::string &valueId="val") const
Definition: Arg.h:505
Constraint< T > * _constraint
Definition: ValueArg.h:72
T & getValue()
Definition: ValueArg.h:322
virtual void add(Arg &a)=0
bool _ignoreable
Definition: Arg.h:150
std::string _typeDesc
Definition: ValueArg.h:67
static bool ignoreRest()
Definition: Arg.h:205
T::ValueCategory ValueCategory
Definition: ArgTraits.h:80
void ExtractValue(T &destVal, const std::string &strVal, ValueLike vl)
Definition: Arg.h:415
virtual bool argMatches(const std::string &s) const
Definition: Arg.h:590
#define NULL
Definition: tinycthread.c:47
int i
ValueArg< T > & operator=(const ValueArg< T > &rhs)
virtual bool processArg(int *i, std::vector< std::string > &args)
Definition: ValueArg.h:328
Definition: Arg.h:57
virtual std::string toString() const
Definition: Arg.h:599
virtual void reset()
Definition: ValueArg.h:417
GLdouble v
ValueArg(const std::string &flag, const std::string &name, const std::string &desc, bool req, T value, const std::string &typeDesc, Visitor *v=NULL)
Definition: ValueArg.h:252


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:14