ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/io/ParamConstraint.hpp
(Generate patch)

Comparing trunk/OOPSE-4/src/io/ParamConstraint.hpp (file contents):
Revision 2372 by tim, Mon Oct 17 00:51:16 2005 UTC vs.
Revision 2376 by tim, Mon Oct 17 19:22:31 2005 UTC

# Line 43 | Line 43
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
50    * composition operators. Every constraint predicate must be derived from this class
# Line 64 | Line 66 | struct ZeroConstraint : public ParamConstraintFacade<Z
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;
# Line 72 | Line 74 | struct NonZeroConstraint : public ParamConstraintFacad
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 {
# Line 81 | Line 83 | struct PositiveConstraint : public ParamConstraintFaca
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      {
# Line 90 | Line 92 | struct NonPositiveConstraint : public ParamConstraintF
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      {
# Line 99 | Line 101 | struct NegativeConstraint : public ParamConstraintFaca
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      {
# Line 108 | Line 110 | struct NonNegativeConstraint : public ParamConstraintF
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      {
# Line 122 | Line 124 | struct LessThanConstraint : public ParamConstraintFaca
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 {
# Line 138 | Line 140 | struct LessThanOrEqualToConstraint : public ParamConst
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>
# Line 156 | Line 158 | struct EqualConstraint : public ParamConstraintFacade<
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>
# Line 172 | Line 174 | struct EqualIgnoreCaseConstraint : public ParamConstra
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 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>
# Line 189 | Line 214 | struct GreaterThanConstraint : public ParamConstraintF
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 {
# Line 205 | Line 230 | struct GreaterThanOrEqualTo : public ParamConstraintFa
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 {
# Line 223 | Line 248 | struct AndParamConstraint: public ParamConstraintFacad
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>
# Line 242 | Line 267 | struct OrParamConstraint: public ParamConstraintFacade
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>
# Line 267 | Line 291 | struct NotParamConstraint: public ParamConstraintFacad
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>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines