values_constraint.hpp
Go to the documentation of this file.
00001 
00011 /*****************************************************************************
00012 ** Ifdefs
00013 *****************************************************************************/
00014 
00015 #ifndef TCLAP_VALUESCONSTRAINT_H
00016 #define TCLAP_VALUESCONSTRAINT_H
00017 
00018 #include <string>
00019 #include <vector>
00020 #include "constraint.hpp"
00021 
00022 #define HAVE_SSTREAM
00023 
00024 #if defined(HAVE_SSTREAM)
00025 #include <sstream>
00026 #elif defined(HAVE_STRSTREAM)
00027 #include <strstream>
00028 #else
00029 #error "Need a stringstream (sstream or strstream) to compile!"
00030 #endif
00031 
00032 namespace ecl {
00033 
00038 template<class T>
00039 class ValuesConstraint : public Constraint<T>
00040 {
00041 
00042         public:
00043 
00048                 ValuesConstraint(std::vector<T>& allowed);
00049 
00053                 virtual ~ValuesConstraint() {}
00054 
00058                 virtual std::string description() const;
00059 
00063                 virtual std::string shortID() const;
00064 
00070                 virtual bool check(const T& value) const;
00071 
00072         protected:
00073 
00077                 std::vector<T> _allowed;
00078 
00082                 std::string _typeDesc;
00083 
00084 };
00085 
00086 template<class T>
00087 ValuesConstraint<T>::ValuesConstraint(std::vector<T>& allowed)
00088 : _allowed(allowed)
00089 {
00090     for ( unsigned int i = 0; i < _allowed.size(); i++ )
00091     {
00092 
00093 #if defined(HAVE_SSTREAM)
00094         std::ostringstream os;
00095 #elif defined(HAVE_STRSTREAM)
00096         std::ostrstream os;
00097 #else
00098 #error "Need a stringstream (sstream or strstream) to compile!"
00099 #endif
00100 
00101         os << _allowed[i];
00102 
00103         std::string temp( os.str() );
00104 
00105         if ( i > 0 )
00106                         _typeDesc += "|";
00107         _typeDesc += temp;
00108     }
00109 }
00110 
00111 template<class T>
00112 bool ValuesConstraint<T>::check( const T& val ) const
00113 {
00114         if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() )
00115                 return false;
00116         else
00117                 return true;
00118 }
00119 
00120 template<class T>
00121 std::string ValuesConstraint<T>::shortID() const
00122 {
00123     return _typeDesc;
00124 }
00125 
00126 template<class T>
00127 std::string ValuesConstraint<T>::description() const
00128 {
00129     return _typeDesc;
00130 }
00131 
00132 }; // namespace ecl
00133 
00134 #endif
00135 


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:07