dune-fem  2.4.1-rc
validator.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_VALIDATOR_HH
2 #define DUNE_FEM_VALIDATOR_HH
3 
4 #warning "File 'fem/misc/validator.hh' is deprecated and will be deleted. Use lambdas instead, have a look into the fem/io/test/paramtertest.cc"
5 #include <iostream>
6 
7 namespace Dune
8 {
9 
10  namespace Fem
11  {
12 
13  // Internal Forward Declarations
14  // -----------------------------
15 
16  template< class T, class Impl >
18 
19 
20 
21  // ValidatorInterface
22  // ------------------
23 
24  template< class T, class Impl >
26  {
28 
29  friend class ValidatorDefault< T, Impl >;
30 
31  private:
32  ValidatorInterface () {}
33 
34  ValidatorInterface ( const ThisType & );
35  ThisType &operator= ( const ThisType & );
36 
37  public:
38  bool operator () ( const T &value ) const
39  {
40  return asImp()( value );
41  }
42 
43  void print(std::ostream& s) const
44  {
45  asImp().print( s );
46  }
47 
48  protected:
49  const Impl &asImp () const
50  {
51  return static_cast< const Impl & >( *this );
52  }
53 
54  Impl &asImp ()
55  {
56  return static_cast< Impl & >( *this );
57  }
58  };
59 
60 
61 
62  // ValidatorDefault
63  // ----------------
64 
65  template< class T, class Impl >
66  class ValidatorDefault
67  {
69  typedef ValidatorInterface< T, Impl > BaseType;
70 
71  protected:
73 
74  private:
75  ValidatorDefault ( const ThisType & );
76  ThisType &operator= ( const ThisType & );
77 
78  private:
79  bool operator () ( const T &value ) const;
80  void print ( std::ostream &s ) const;
81  };
82 
83 
84 
85  template< class T >
87  : public ValidatorDefault< T, ValidateGreater< T > >
88  {
91 
92  public:
93  ValidateGreater ( const T &threshold )
94  : threshold_( threshold )
95  {}
96 
97  ValidateGreater ( const ThisType &other )
98  : threshold_( other.threshold_ )
99  {}
100 
101  public:
102  bool operator() ( const T &value ) const
103  {
104  return value > threshold_;
105  }
106 
107  void print(std::ostream& s) const
108  {
109  s << "ValidateLess: valid values are: > " << threshold_ << std::endl << std::endl;
110  }
111 
112  protected:
113  const T threshold_;
114  };
115 
116 
117 
118  template< class T >
120  : public ValidatorDefault< T, ValidateLess< T > >
121  {
122  typedef ValidateLess< T > ThisType;
124 
125  public:
126  ValidateLess ( const T &threshold )
127  : threshold_( threshold )
128  {}
129 
130  ValidateLess ( const ThisType &other )
131  : threshold_( other.threshold_ )
132  {}
133 
134  bool operator() ( const T &value ) const
135  {
136  return value < threshold_;
137  }
138 
139  void print(std::ostream& s) const
140  {
141  s << "ValidateLess: valid values are: < " << threshold_ << std::endl << std::endl;
142  }
143 
144  protected:
145  const T threshold_;
146  };
147 
148 
149 
150  template< class T >
152  : public ValidatorDefault< T, ValidateNotGreater< T > >
153  {
156 
157  public:
158  ValidateNotGreater ( const T &threshold )
159  : threshold_( threshold )
160  {}
161 
162  ValidateNotGreater ( const ThisType &other )
163  : threshold_( other.threshold_ )
164  {}
165 
166  bool operator() ( const T &value ) const
167  {
168  return value <= threshold_;
169  }
170 
171  void print(std::ostream& s) const
172  {
173  s << "ValidateNotGreater: valid values are: <= " << threshold_ << std::endl << std::endl;
174  }
175 
176  protected:
177  const T threshold_;
178  };
179 
180 
181 
182  template< class T >
184  : public ValidatorDefault< T, ValidateNotLess< T > >
185  {
188 
189  public:
190  ValidateNotLess ( const T &threshold )
191  : threshold_( threshold )
192  {}
193 
194  ValidateNotLess ( const ThisType &other )
195  : threshold_( other.threshold_ )
196  {}
197 
198  bool operator() ( const T &value ) const
199  {
200  return value >= threshold_;
201  }
202 
203  void print(std::ostream& s) const
204  {
205  s << "ValidateNotLess: valid values are: >= " << threshold_ << std::endl << std::endl;
206  }
207 
208  protected:
209  const T threshold_;
210  };
211 
212 
213 
214  template< class T, bool leftClosed, bool rightClosed >
216  : public ValidatorDefault< T, ValidateInterval< T, leftClosed, rightClosed > >
217  {
220 
221  public:
222  ValidateInterval ( const T &lThreshold, const T &rThreshold )
223  : lThreshold_( lThreshold ),
224  rThreshold_( rThreshold )
225  {}
226 
227  ValidateInterval ( const ThisType &other )
228  : lThreshold_( other.lThreshold_ ),
229  rThreshold_( other.rThreshold_ )
230  {}
231 
232  bool operator() ( const T &value ) const
233  {
234  bool ret = true;
235  ret &= (leftClosed ? value >= lThreshold_ : value > lThreshold_);
236  ret &= (rightClosed ? value <= rThreshold_ : value < rThreshold_);
237  return ret;
238  }
239 
240  void print(std::ostream& s) const
241  {
242  const char* left = (leftClosed) ? "[" : "(";
243  const char* right = (rightClosed) ? "]" : ")";
244  s << "ValidateInterval: valid values are " << left << lThreshold_ << "," <<
245  rThreshold_ << right << std::endl << std::endl;
246  }
247 
248  protected:
249  const T lThreshold_, rThreshold_;
250  };
251 
252 
253 
254  // NoWhiteSpaceValidator
255  // ---------------------
256 
258  : public ValidatorDefault< std::string, NoWhiteSpaceValidator >
259  {
262 
263  public:
265  {}
266 
267  NoWhiteSpaceValidator ( const ThisType &other )
268  {}
269 
270  bool operator() ( const std::string &value ) const
271  {
272  return (value.find_first_of( " \t" ) == std::string::npos);
273  }
274 
275  void print ( std::ostream &s ) const
276  {
277  s << "NoWhiteSpaceValidator" << std::endl;
278  }
279  };
280 
281  } // namespace Fem
282 
283 } // namespace Dune
284 
285 #endif // #ifndef DUNE_FEM_VALIDATOR_HH
ValidateNotLess(const ThisType &other)
Definition: validator.hh:194
const T threshold_
Definition: validator.hh:177
NoWhiteSpaceValidator()
Definition: validator.hh:264
void print(std::ostream &s) const
Definition: validator.hh:203
Impl & asImp()
Definition: validator.hh:54
Definition: validator.hh:119
const Impl & asImp() const
Definition: validator.hh:49
ValidateNotGreater(const ThisType &other)
Definition: validator.hh:162
ValidateLess(const T &threshold)
Definition: validator.hh:126
const T threshold_
Definition: validator.hh:145
ValidateInterval(const T &lThreshold, const T &rThreshold)
Definition: validator.hh:222
ValidateNotLess(const T &threshold)
Definition: validator.hh:190
bool operator()(const T &value) const
Definition: validator.hh:38
const T rThreshold_
Definition: validator.hh:249
NoWhiteSpaceValidator(const ThisType &other)
Definition: validator.hh:267
ValidateNotGreater(const T &threshold)
Definition: validator.hh:158
void print(std::ostream &s) const
Definition: validator.hh:275
Definition: coordinate.hh:4
ValidateLess(const ThisType &other)
Definition: validator.hh:130
Definition: validator.hh:215
Definition: validator.hh:25
Definition: validator.hh:183
Definition: validator.hh:257
void print(std::ostream &s) const
Definition: validator.hh:171
const T threshold_
Definition: validator.hh:209
ValidateInterval(const ThisType &other)
Definition: validator.hh:227
Definition: validator.hh:17
ValidateGreater(const T &threshold)
Definition: validator.hh:93
void print(std::ostream &s) const
Definition: validator.hh:43
Definition: validator.hh:151
const T threshold_
Definition: validator.hh:113
void print(std::ostream &s) const
Definition: validator.hh:240
Definition: validator.hh:86
ValidateGreater(const ThisType &other)
Definition: validator.hh:97
void print(std::ostream &s) const
Definition: validator.hh:107
ValidatorDefault()
Definition: validator.hh:72
void print(std::ostream &s) const
Definition: validator.hh:139