values_constraint.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef TCLAP_VALUESCONSTRAINT_H
16 #define TCLAP_VALUESCONSTRAINT_H
17 
18 #include <string>
19 #include <vector>
20 #include "constraint.hpp"
21 
22 #define HAVE_SSTREAM
23 
24 #if defined(HAVE_SSTREAM)
25 #include <sstream>
26 #elif defined(HAVE_STRSTREAM)
27 #include <strstream>
28 #else
29 #error "Need a stringstream (sstream or strstream) to compile!"
30 #endif
31 
32 namespace ecl {
33 
38 template<class T>
39 class ValuesConstraint : public Constraint<T>
40 {
41 
42  public:
43 
48  ValuesConstraint(std::vector<T>& allowed);
49 
53  virtual ~ValuesConstraint() {}
54 
58  virtual std::string description() const;
59 
63  virtual std::string shortID() const;
64 
70  virtual bool check(const T& value) const;
71 
72  protected:
73 
77  std::vector<T> _allowed;
78 
82  std::string _typeDesc;
83 
84 };
85 
86 template<class T>
87 ValuesConstraint<T>::ValuesConstraint(std::vector<T>& allowed)
88 : _allowed(allowed)
89 {
90  for ( unsigned int i = 0; i < _allowed.size(); i++ )
91  {
92 
93 #if defined(HAVE_SSTREAM)
94  std::ostringstream os;
95 #elif defined(HAVE_STRSTREAM)
96  std::ostrstream os;
97 #else
98 #error "Need a stringstream (sstream or strstream) to compile!"
99 #endif
100 
101  os << _allowed[i];
102 
103  std::string temp( os.str() );
104 
105  if ( i > 0 )
106  _typeDesc += "|";
107  _typeDesc += temp;
108  }
109 }
110 
111 template<class T>
112 bool ValuesConstraint<T>::check( const T& val ) const
113 {
114  if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() )
115  return false;
116  else
117  return true;
118 }
119 
120 template<class T>
121 std::string ValuesConstraint<T>::shortID() const
122 {
123  return _typeDesc;
124 }
125 
126 template<class T>
128 {
129  return _typeDesc;
130 }
131 
132 }; // namespace ecl
133 
134 #endif
135 
TCLAP command line argument parser classes.
virtual std::string description() const
Defines the interaction between an argument and a constraint.
Definition: constraint.hpp:34
ValuesConstraint(std::vector< T > &allowed)
virtual bool check(const T &value) const
std::vector< T > _allowed
virtual std::string shortID() const


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:08