36 #if !defined(LIBEVOCOSM_VALIDATOR_H)
37 #define LIBEVOCOSM_VALIDATOR_H
45 using std::stringstream;
47 using std::runtime_error;
58 template <
typename Type>
62 static string build_error_string(
const Type &
object,
63 const string & details)
67 message <<
"validation error: "
68 <<
typeid(object).name() <<
" " <<
object
88 const string & details =
string())
89 : runtime_error(build_error_string(object,details))
104 template <
typename Type>
106 const Type & constraint,
107 const string & message =
string())
109 if (
object != constraint)
111 stringstream details;
112 details <<
" must equal " << constraint <<
" " << message;
126 template <
typename Type>
128 const Type & constraint,
129 const string & message =
string())
131 if (
object == constraint)
133 stringstream details;
134 details <<
" must not equal " << constraint <<
" " << message;
148 template <
typename Type>
150 const Type & constraint,
151 const string & message =
string())
153 if (
object >= constraint)
155 stringstream details;
156 details <<
" must be less than " << constraint <<
" " << message;
170 template <
typename Type>
172 const Type & constraint,
173 const string & message =
string())
175 if (
object > constraint)
177 stringstream details;
178 details <<
" must be less than " << constraint <<
" " << message;
192 template <
typename Type>
194 const Type & constraint,
195 const string & message =
string())
197 if (
object <= constraint)
199 stringstream details;
200 details <<
" must be greater than " << constraint <<
" " << message;
214 template <
typename Type>
216 const Type & constraint,
217 const string & message =
string())
219 if (
object < constraint)
221 stringstream details;
222 details <<
" must be greater than " << constraint <<
" " << message;
239 template <
typename Type>
241 const Type & low_bound,
242 const Type & high_bound,
243 const string & message =
string())
245 if ((
object < low_bound) || (
object > high_bound))
247 stringstream details;
248 details <<
" must be between " << low_bound <<
" and "
249 << high_bound <<
" " << message;
266 template <
typename Type,
typename Predicate>
268 const Predicate & constraint,
269 const string & message =
string())
271 if (!constraint(
object))
273 stringstream details;
274 details <<
" failed test " <<
typeid(constraint).name() <<
" " << message;
286 template <
typename Type>
288 const Type & low_value)
290 if (
object < low_value)
301 template <
typename Type>
303 const Type & high_value)
305 if (
object > high_value)
319 template <
typename Type>
321 const Type & low_value,
322 const Type & high_value)
324 if (
object < low_value)
326 else if (
object > high_value)
343 text <<
"in " << filename <<
", line " << line_no;
350 #if defined(_DEBUG) && !defined(NDEBUG)
351 #define LIBEVOCOSM_VALIDATE_EQUALS(object,constraint,details) libevocosm::validate_equals(object,constraint,details)
352 #define LIBEVOCOSM_VALIDATE_NOT(object,constraint,details) libevocosm::validate_not(object,constraint,details)
353 #define LIBEVOCOSM_VALIDATE_LESS(object,constraint,details) libevocosm::validate_less(object,constraint,details)
354 #define LIBEVOCOSM_VALIDATE_LESS_EQ(object,constraint,details) libevocosm::validate_less_eq(object,constraint,details)
355 #define LIBEVOCOSM_VALIDATE_GREATER(object,constraint,details) libevocosm::validate_greater(object,constraint,details)
356 #define LIBEVOCOSM_VALIDATE_GREATER_EQ(object,constraint,details) libevocosm::validate_greater_eq(object,constraint,details)
357 #define LIBEVOCOSM_VALIDATE_RANGE(object,low_bound,high_bound,details) libevocosm::validate_range(object,low_bound,high_bound,details)
358 #define LIBEVOCOSM_VALIDATE_WITH(object,constraint,details) libevocosm::validate_with(object,constraint,details)
359 #define LIBEVOCOSM_LOCATION libevocosm::build_location_string(__FILE__,__LINE__)
361 #define LIBEVOCOSM_VALIDATE_EQUALS(object,constraint,details)
362 #define LIBEVOCOSM_VALIDATE_NOT(object,constraint,details)
363 #define LIBEVOCOSM_VALIDATE_LESS(object,constraint,details)
364 #define LIBEVOCOSM_VALIDATE_LESS_EQ(object,constraint,details)
365 #define LIBEVOCOSM_VALIDATE_GREATER(object,constraint,details)
366 #define LIBEVOCOSM_VALIDATE_GREATER_EQ(object,constraint,details)
367 #define LIBEVOCOSM_VALIDATE_RANGE(object,low_bound,high_bound,details)
368 #define LIBEVOCOSM_VALIDATE_WITH(object,constraint,details)
369 #define LIBEVOCOSM_LOCATION std::string()
void validate_greater(const Type &object, const Type &constraint, const string &message=string())
Validates that an object is greater than constraint.
Definition: validator.h:193
void validate_greater_eq(const Type &object, const Type &constraint, const string &message=string())
Validates that an object is greater than or equal to constraint.
Definition: validator.h:215
void enforce_upper_limit(Type &object, const Type &high_value)
Enforce an upper limit on the value of an object.
Definition: validator.h:302
Standard validation exception.
Definition: validator.h:59
string build_location_string(const char *filename, long line_no)
Utility function to create a location string.
Definition: validator.h:340
void validate_not(const Type &object, const Type &constraint, const string &message=string())
Validates that an object does not have a specific value.
Definition: validator.h:127
void validate_range(const Type &object, const Type &low_bound, const Type &high_bound, const string &message=string())
Validates that an object has a value in a specified range.
Definition: validator.h:240
void validate_less(const Type &object, const Type &constraint, const string &message=string())
Validates that an object is less than constraint.
Definition: validator.h:149
validation_error(const Type &object, const string &details=string())
Constructor.
Definition: validator.h:87
A toolkit and framework for implementing evolutionary algorithms.
Definition: evocommon.h:60
void enforce_range(Type &object, const Type &low_value, const Type &high_value)
Enforce an range limit on the value of an object.
Definition: validator.h:320
void validate_less_eq(const Type &object, const Type &constraint, const string &message=string())
Validates that an object is less than or equal to constraint.
Definition: validator.h:171
void validate_equals(const Type &object, const Type &constraint, const string &message=string())
Validates that an object has a specific value.
Definition: validator.h:105
void enforce_lower_limit(Type &object, const Type &low_value)
Enforce a lower limit on the value of an object.
Definition: validator.h:287
void validate_with(const Type &object, const Predicate &constraint, const string &message=string())
Validates an object with a given predicate.
Definition: validator.h:267