ParameterRequirement.hpp
Go to the documentation of this file.
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 {
46  namespace parameter {
53  template<typename T>
54  std::string operator()(const T&) const {
55  return "";
56  }
57  };
58 
64  std::string operator()(double x) const {
65  if ( (x < 0.0) || (x > 1.0) ) {
66  std::ostringstream stream;
67  stream << "The value '" << x
68  << "' is not in the interval [0, 1].";
69  return stream.str();
70  } else {
71  return "";
72  }
73  }
74  };
75 
82  template<typename T>
83  std::string operator()(const T& x) const {
84  if (x > 0) {
85  return "";
86  } else {
87  std::ostringstream stream;
88  stream << "The value '" << x << "' is not positive.";
89  return stream.str();
90  }
91  }
92  };
93 
100  template<typename T>
101  std::string operator()(const T& x) const {
102  if (x < 0) {
103  return "";
104  } else {
105  std::ostringstream stream;
106  stream << "The value '" << x << "' is not negative.";
107  return stream.str();
108  }
109  }
110  };
111 
118  template<typename T>
119  std::string operator()(const T& x) const {
120  if (x > 0) {
121  std::ostringstream stream;
122  stream << "The value '" << x << "' is positive.";
123  return stream.str();
124  } else {
125  return "";
126  }
127  }
128  };
129 
136  template<typename T>
137  std::string operator()(const T& x) const {
138  if (x < 0) {
139  std::ostringstream stream;
140  stream << "The value '" << x << "' is negative.";
141  return stream.str();
142  } else {
143  return "";
144  }
145  }
146  };
147 
154  template<typename T>
155  std::string operator()(const T& x) const {
156  if (x != 0) {
157  return "";
158  } else {
159  return "The value was zero.";
160  }
161  }
162  };
163 
169  std::string operator()(const std::string& x) const {
170  if (x != "") {
171  return "The string was empty.";
172  } else {
173  return "";
174  }
175  }
176  };
177 
183  template<class Requirement1, class Requirement2>
185  ParameterRequirementAnd(const Requirement1& r1, const Requirement2& r2) :
186  r1_(r1), r2_(r2) { }
187 
188  template<typename T>
189  std::string operator()(const T& t) const {
190  std::string e1 = r1_(t);
191  std::string e2 = r2_(t);
192  if (e1 == "") {
193  return e2;
194  } else if (e2 == "") {
195  return e1;
196  } else {
197  return e1 + " AND " + e2;
198  }
199  }
200  private:
201  const Requirement1 r1_;
202  const Requirement2 r2_;
203  };
204 
209  ParameterRequirementMemberOf(const std::vector<std::string>& elements)
210  : elements_(elements) {
211  assert(elements_.size() > 0);
212  }
213 
218  std::string operator()(const std::string& x) const {
219  if (std::find(elements_.begin(), elements_.end(), x) == elements_.end()) {
220  if (elements_.size() == 1) {
221  return "The string '" + x + "' is not '" + elements_[0] + "'.";
222  }
223  std::ostringstream stream;
224  stream << "The string '" << x << "' is not among '";
225  for (int i = 0; i < int(elements_.size()) - 2; ++i) {
226  stream << elements_[i] << "', '";
227  }
228  stream << elements_[elements_.size() - 2]
229  << "' and '"
230  << elements_[elements_.size() - 1]
231  << "'.";
232  return stream.str();
233  } else {
234  return "";
235  }
236  }
237  private:
238  const std::vector<std::string> elements_;
239  };
240  } // namespace parameter
241 } // namespace Opm
242 
243 #endif // OPM_PARAMETERREQUIREMENT_HEADER
Definition: ParameterRequirement.hpp:52
Definition: ParameterRequirement.hpp:117
std::string operator()(const T &x) const
Definition: ParameterRequirement.hpp:83
Definition: AnisotropicEikonal.hpp:43
std::string operator()(const T &) const
Definition: ParameterRequirement.hpp:54
std::string operator()(const T &t) const
Definition: ParameterRequirement.hpp:189
ParameterRequirementAnd(const Requirement1 &r1, const Requirement2 &r2)
Definition: ParameterRequirement.hpp:185
Definition: ParameterRequirement.hpp:81
std::string operator()(const T &x) const
Definition: ParameterRequirement.hpp:101
Definition: ParameterRequirement.hpp:63
std::string operator()(const T &x) const
Definition: ParameterRequirement.hpp:119
Definition: ParameterRequirement.hpp:168
Definition: ParameterRequirement.hpp:153
Definition: ParameterRequirement.hpp:135
std::string operator()(const T &x) const
Definition: ParameterRequirement.hpp:155
Definition: ParameterRequirement.hpp:99
std::string operator()(const T &x) const
Definition: ParameterRequirement.hpp:137
std::string operator()(double x) const
Definition: ParameterRequirement.hpp:64
Definition: ParameterRequirement.hpp:208
Definition: ParameterRequirement.hpp:184
ParameterRequirementMemberOf(const std::vector< std::string > &elements)
Definition: ParameterRequirement.hpp:209
std::string operator()(const std::string &x) const
Definition: ParameterRequirement.hpp:218
std::string operator()(const std::string &x) const
Definition: ParameterRequirement.hpp:169