| 42 | 
  | 
#ifndef IO_PARAMCONSTRAINT_HPP | 
| 43 | 
  | 
#define IO_PARAMCONSTRAINT_HPP | 
| 44 | 
  | 
#include <sstream> | 
| 45 | 
+ | 
#include "utils/CaseConversion.hpp" | 
| 46 | 
+ | 
#include "utils/StringTokenizer.hpp" | 
| 47 | 
  | 
 | 
| 48 | 
  | 
/** | 
| 49 | 
  | 
  * This class allows to recognize constraint predicates, so that they can be combined using | 
| 66 | 
  | 
 | 
| 67 | 
  | 
struct ZeroConstraint : public ParamConstraintFacade<ZeroConstraint>{ | 
| 68 | 
  | 
     | 
| 69 | 
< | 
    ZeroConstraint() {description_ = "zero";} | 
| 69 | 
> | 
    ZeroConstraint() {this->description_ = "zero";} | 
| 70 | 
  | 
    template<typename DataType> | 
| 71 | 
  | 
    bool operator()( DataType data ) const { | 
| 72 | 
  | 
        return data == 0; | 
| 74 | 
  | 
}; | 
| 75 | 
  | 
 | 
| 76 | 
  | 
struct NonZeroConstraint : public ParamConstraintFacade<NonZeroConstraint>{ | 
| 77 | 
< | 
    NonZeroConstraint() {description_ = "nonzero";} | 
| 77 | 
> | 
    NonZeroConstraint() {this->description_ = "nonzero";} | 
| 78 | 
  | 
 | 
| 79 | 
  | 
    template<typename DataType> | 
| 80 | 
  | 
    bool operator()( DataType data ) const { | 
| 83 | 
  | 
}; | 
| 84 | 
  | 
 | 
| 85 | 
  | 
struct PositiveConstraint : public ParamConstraintFacade<PositiveConstraint>{ | 
| 86 | 
< | 
    PositiveConstraint() {description_ = "positive";} | 
| 86 | 
> | 
    PositiveConstraint() {this->description_ = "positive";} | 
| 87 | 
  | 
    template<typename DataType> | 
| 88 | 
  | 
    bool operator()( DataType data ) const | 
| 89 | 
  | 
    { | 
| 92 | 
  | 
}; | 
| 93 | 
  | 
 | 
| 94 | 
  | 
struct NonPositiveConstraint : public ParamConstraintFacade<NonPositiveConstraint>{ | 
| 95 | 
< | 
    NonPositiveConstraint() {description_ = "nonpositive";} | 
| 95 | 
> | 
    NonPositiveConstraint() {this->description_ = "nonpositive";} | 
| 96 | 
  | 
    template<typename DataType> | 
| 97 | 
  | 
    bool operator()( DataType data ) const | 
| 98 | 
  | 
    { | 
| 101 | 
  | 
}; | 
| 102 | 
  | 
 | 
| 103 | 
  | 
struct NegativeConstraint : public ParamConstraintFacade<NegativeConstraint>{ | 
| 104 | 
< | 
    NegativeConstraint() {description_ = "negative";} | 
| 104 | 
> | 
    NegativeConstraint() {this->description_ = "negative";} | 
| 105 | 
  | 
    template<typename DataType> | 
| 106 | 
  | 
    bool operator()( DataType data ) const | 
| 107 | 
  | 
    { | 
| 110 | 
  | 
}; | 
| 111 | 
  | 
 | 
| 112 | 
  | 
struct NonNegativeConstraint : public ParamConstraintFacade<NonNegativeConstraint>{ | 
| 113 | 
< | 
    NonNegativeConstraint() {description_ = "nonnegative";} | 
| 113 | 
> | 
    NonNegativeConstraint() {this->description_ = "nonnegative";} | 
| 114 | 
  | 
    template<typename DataType> | 
| 115 | 
  | 
    bool operator()( DataType data ) const | 
| 116 | 
  | 
    { | 
| 124 | 
  | 
    LessThanConstraint(T rhs) : rhs_(rhs){ | 
| 125 | 
  | 
        std::stringstream iss; | 
| 126 | 
  | 
        iss << "less than " << rhs; | 
| 127 | 
< | 
        description_ = iss.str(); | 
| 127 | 
> | 
        this->description_ = iss.str(); | 
| 128 | 
  | 
    } | 
| 129 | 
  | 
    template<typename DataType> | 
| 130 | 
  | 
    bool operator()( DataType data ) const { | 
| 140 | 
  | 
    LessThanOrEqualToConstraint(T rhs) : rhs_(rhs) { | 
| 141 | 
  | 
        std::stringstream iss; | 
| 142 | 
  | 
        iss << "less than or equal to" << rhs; | 
| 143 | 
< | 
        description_ = iss.str(); | 
| 143 | 
> | 
        this->description_ = iss.str(); | 
| 144 | 
  | 
    } | 
| 145 | 
  | 
     | 
| 146 | 
  | 
    template<typename DataType> | 
| 158 | 
  | 
    EqualConstraint(T rhs) : rhs_(rhs){ | 
| 159 | 
  | 
        std::stringstream iss; | 
| 160 | 
  | 
        iss << "equal to" << rhs; | 
| 161 | 
< | 
        description_ = iss.str(); | 
| 161 | 
> | 
        this->description_ = iss.str(); | 
| 162 | 
  | 
 | 
| 163 | 
  | 
    } | 
| 164 | 
  | 
    template<typename DataType> | 
| 171 | 
  | 
 | 
| 172 | 
  | 
struct EqualIgnoreCaseConstraint : public ParamConstraintFacade<EqualIgnoreCaseConstraint> { | 
| 173 | 
  | 
     | 
| 174 | 
< | 
    EqualIgnoreCaseConstraint(std::string rhs) : rhs_(rhs){ | 
| 174 | 
> | 
    EqualIgnoreCaseConstraint(std::string rhs) : rhs_(oopse::toUpperCopy(rhs)){ | 
| 175 | 
  | 
        std::stringstream iss; | 
| 176 | 
  | 
        iss << "equal to (case insensitive) " << rhs; | 
| 177 | 
< | 
        description_ = iss.str(); | 
| 177 | 
> | 
        this->description_ = iss.str(); | 
| 178 | 
  | 
    } | 
| 179 | 
  | 
     | 
| 180 | 
  | 
    bool operator()( std::string data ) const { | 
| 181 | 
< | 
        return data == rhs_;  | 
| 181 | 
> | 
        return oopse::toUpperCopy(data) == rhs_;  | 
| 182 | 
> | 
    } | 
| 183 | 
> | 
     | 
| 184 | 
> | 
    private: | 
| 185 | 
> | 
       std::string rhs_;         | 
| 186 | 
> | 
}; | 
| 187 | 
> | 
 | 
| 188 | 
> | 
struct ContainsConstraint :  public ParamConstraintFacade<EqualIgnoreCaseConstraint> { | 
| 189 | 
> | 
    ContainsConstraint(std::string rhs) : rhs_(oopse::toUpperCopy(rhs)){ | 
| 190 | 
> | 
        std::stringstream iss; | 
| 191 | 
> | 
        iss << "contains " << rhs; | 
| 192 | 
> | 
        this->description_ = iss.str(); | 
| 193 | 
  | 
    } | 
| 194 | 
  | 
     | 
| 195 | 
+ | 
    bool operator()( std::string data ) const { | 
| 196 | 
+ | 
        oopse::StringTokenizer tokenizer(oopse::toUpperCopy(data),  " ,;|\t\n\r"); | 
| 197 | 
+ | 
        while (tokenizer.hasMoreTokens()) { | 
| 198 | 
+ | 
            if (tokenizer.nextToken() == rhs_) { | 
| 199 | 
+ | 
                return true; | 
| 200 | 
+ | 
            } | 
| 201 | 
+ | 
        } | 
| 202 | 
+ | 
         | 
| 203 | 
+ | 
        return  false;  | 
| 204 | 
+ | 
    } | 
| 205 | 
+ | 
     | 
| 206 | 
  | 
    private: | 
| 207 | 
  | 
       std::string rhs_;         | 
| 208 | 
+ | 
 | 
| 209 | 
  | 
}; | 
| 210 | 
  | 
 | 
| 211 | 
  | 
template<typename T> | 
| 214 | 
  | 
    GreaterThanConstraint(T rhs) : rhs_(rhs){ | 
| 215 | 
  | 
        std::stringstream iss; | 
| 216 | 
  | 
        iss << "greater than" << rhs; | 
| 217 | 
< | 
        description_ = iss.str(); | 
| 217 | 
> | 
        this->description_ = iss.str(); | 
| 218 | 
  | 
    } | 
| 219 | 
  | 
    template<typename DataType> | 
| 220 | 
  | 
    bool operator()( DataType data ) const { | 
| 230 | 
  | 
    GreaterThanOrEqualTo(T rhs) : rhs_(rhs){ | 
| 231 | 
  | 
        std::stringstream iss; | 
| 232 | 
  | 
        iss << "greater than or equal to" << rhs; | 
| 233 | 
< | 
        description_ = iss.str(); | 
| 233 | 
> | 
        this->description_ = iss.str(); | 
| 234 | 
  | 
    } | 
| 235 | 
  | 
    template<typename DataType> | 
| 236 | 
  | 
    bool operator()( DataType data ) const { | 
| 248 | 
  | 
    AndParamConstraint( Cons1T cons1, Cons2T cons2 ) : cons1_(cons1), cons2_(cons2) { | 
| 249 | 
  | 
        std::stringstream iss; | 
| 250 | 
  | 
        iss << "(" << cons1_.getConstraintDescription() << " and " << cons2_.getConstraintDescription() << ")";  | 
| 251 | 
< | 
        description_ = iss.str();         | 
| 251 | 
> | 
        this->description_ = iss.str();         | 
| 252 | 
  | 
    } | 
| 253 | 
  | 
 | 
| 254 | 
  | 
    template<typename DataType> | 
| 267 | 
  | 
struct OrParamConstraint: public ParamConstraintFacade< OrParamConstraint<Cons1T,Cons2T> > { | 
| 268 | 
  | 
public: | 
| 269 | 
  | 
 | 
| 245 | 
– | 
 | 
| 270 | 
  | 
    OrParamConstraint( Cons1T cons1, Cons2T cons2 ) : cons1_(cons1), cons2_(cons2) { | 
| 271 | 
  | 
        std::stringstream iss; | 
| 272 | 
  | 
        iss << cons1_.getConstraintDescription() << " or " << cons2_.getConstraintDescription() << "";  | 
| 273 | 
< | 
        description_ = iss.str();  | 
| 273 | 
> | 
        this->description_ = iss.str();  | 
| 274 | 
  | 
     } | 
| 275 | 
  | 
 | 
| 276 | 
  | 
    template<typename DataType> | 
| 291 | 
  | 
    NotParamConstraint( ConsT cons) : cons_(cons) { | 
| 292 | 
  | 
        std::stringstream iss; | 
| 293 | 
  | 
        iss << "(not" << cons1_.getConstraintDescription() << ")";  | 
| 294 | 
< | 
        description_ = iss.str();  | 
| 294 | 
> | 
        this->description_ = iss.str();  | 
| 295 | 
  | 
    } | 
| 296 | 
  | 
 | 
| 297 | 
  | 
    template<typename DataType> |