All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
ParameterRequirement.hpp
1 //===========================================================================
2 //
3 // File: ParameterRequirement.hpp
4 //
5 // Created: Tue Jun 2 19:05:02 2009
6 //
7 // Author(s): Bård Skaflestad <bard.skaflestad@sintef.no>
8 // Atgeirr F Rasmussen <atgeirr@sintef.no>
9 //
10 // $Date$
11 //
12 // $Revision$
13 //
14 //===========================================================================
15 
16 /*
17  Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
18  Copyright 2009, 2010 Statoil ASA.
19 
20  This file is part of the Open Porous Media project (OPM).
21 
22  OPM is free software: you can redistribute it and/or modify
23  it under the terms of the GNU General Public License as published by
24  the Free Software Foundation, either version 3 of the License, or
25  (at your option) any later version.
26 
27  OPM is distributed in the hope that it will be useful,
28  but WITHOUT ANY WARRANTY; without even the implied warranty of
29  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  GNU General Public License for more details.
31 
32  You should have received a copy of the GNU General Public License
33  along with OPM. If not, see <http://www.gnu.org/licenses/>.
34 */
35 
36 #ifndef OPM_PARAMETERREQUIREMENT_HEADER
37 #define OPM_PARAMETERREQUIREMENT_HEADER
38 
39 #include <algorithm>
40 #include <cassert>
41 #include <sstream>
42 #include <string>
43 #include <vector>
44 
45 namespace Opm {
52  template<typename T>
53  std::string operator()(const T&) const {
54  return "";
55  }
56  };
57 
63  std::string operator()(double x) const {
64  if ( (x < 0.0) || (x > 1.0) ) {
65  std::ostringstream stream;
66  stream << "The value '" << x
67  << "' is not in the interval [0, 1].";
68  return stream.str();
69  } else {
70  return "";
71  }
72  }
73  };
74 
81  template<typename T>
82  std::string operator()(const T& x) const {
83  if (x > 0) {
84  return "";
85  } else {
86  std::ostringstream stream;
87  stream << "The value '" << x << "' is not positive.";
88  return stream.str();
89  }
90  }
91  };
92 
99  template<typename T>
100  std::string operator()(const T& x) const {
101  if (x < 0) {
102  return "";
103  } else {
104  std::ostringstream stream;
105  stream << "The value '" << x << "' is not negative.";
106  return stream.str();
107  }
108  }
109  };
110 
117  template<typename T>
118  std::string operator()(const T& x) const {
119  if (x > 0) {
120  std::ostringstream stream;
121  stream << "The value '" << x << "' is positive.";
122  return stream.str();
123  } else {
124  return "";
125  }
126  }
127  };
128 
135  template<typename T>
136  std::string operator()(const T& x) const {
137  if (x < 0) {
138  std::ostringstream stream;
139  stream << "The value '" << x << "' is negative.";
140  return stream.str();
141  } else {
142  return "";
143  }
144  }
145  };
146 
153  template<typename T>
154  std::string operator()(const T& x) const {
155  if (x != 0) {
156  return "";
157  } else {
158  return "The value was zero.";
159  }
160  }
161  };
162 
168  std::string operator()(const std::string& x) const {
169  if (x != "") {
170  return "The string was empty.";
171  } else {
172  return "";
173  }
174  }
175  };
176 
182  template<class Requirement1, class Requirement2>
184  ParameterRequirementAnd(const Requirement1& r1, const Requirement2& r2) :
185  r1_(r1), r2_(r2) { }
186 
187  template<typename T>
188  std::string operator()(const T& t) const {
189  std::string e1 = r1_(t);
190  std::string e2 = r2_(t);
191  if (e1 == "") {
192  return e2;
193  } else if (e2 == "") {
194  return e1;
195  } else {
196  return e1 + " AND " + e2;
197  }
198  }
199  private:
200  const Requirement1 r1_;
201  const Requirement2 r2_;
202  };
203 
208  ParameterRequirementMemberOf(const std::vector<std::string>& elements)
209  : elements_(elements) {
210  assert(elements_.size() > 0);
211  }
212 
217  std::string operator()(const std::string& x) const {
218  if (std::find(elements_.begin(), elements_.end(), x) == elements_.end()) {
219  if (elements_.size() == 1) {
220  return "The string '" + x + "' is not '" + elements_[0] + "'.";
221  }
222  std::ostringstream stream;
223  stream << "The string '" << x << "' is not among '";
224  for (int i = 0; i < int(elements_.size()) - 2; ++i) {
225  stream << elements_[i] << "', '";
226  }
227  stream << elements_[elements_.size() - 2]
228  << "' and '"
229  << elements_[elements_.size() - 1]
230  << "'.";
231  return stream.str();
232  } else {
233  return "";
234  }
235  }
236  private:
237  const std::vector<std::string> elements_;
238  };
239 } // namespace Opm
240 
241 #endif // OPM_PARAMETERREQUIREMENT_HEADER
Definition: ParameterRequirement.hpp:167
Definition: ParameterRequirement.hpp:152
Definition: ParameterRequirement.hpp:51
Definition: ParameterRequirement.hpp:116
Definition: ParameterRequirement.hpp:207
Definition: ParameterRequirement.hpp:62
Definition: ParameterRequirement.hpp:80
std::string operator()(const std::string &x) const
Definition: ParameterRequirement.hpp:217
Definition: ParameterRequirement.hpp:98
Definition: ParameterRequirement.hpp:183
Definition: ParameterRequirement.hpp:134