37 template <
class contents>
38 bool in_range(
const contents &value,
const contents &low,
const contents &high)
39 {
return !( (high < low) || (value < low) || (value > high) ); }
48 #define bounds_return(value, low, high, to_return) \
49 { if (!basis::in_range(value, low, high)) return to_return; }
60 #define bounds_halt(value, low, high, to_return) { \
61 if (((value) < (low)) || ((value) > (high))) { \
62 throw_error(basis::astring(static_class_name()), basis::astring(func), \
63 basis::astring("value ") + #value \
64 + " was not in range " + #low + " to " + #high \
65 + " at " + __WHERE__); \
70 #define bounds_halt(a, b, c, d) bounds_return(a, b, c, d)
76 void format_error(
const base_string &class_name,
const base_string &func_name,
77 const base_string &error_message, base_string &to_fill);
80 void throw_error(
const base_string &class_name,
const base_string &func_name,
81 const base_string &error_message);
84 void throw_error(
const astring &class_name,
const astring &func_name,
85 const astring &error_message);
The guards collection helps in testing preconditions and reporting errors.
void throw_error(const base_string &class_name, const base_string &func_name, const base_string &error_message)
throws an error that incorporates the class name and function name.
bool in_range(const contents &value, const contents &low, const contents &high)
Returns true if the value is within the range specified.
void format_error(const base_string &class_name, const base_string &func_name, const base_string &error_message, base_string &to_fill)
writes a string "to_fill" in a nicely formatted manner using the class and function names.