Go to the source code of this file.
Namespaces | |
| namespace | basis |
The guards collection helps in testing preconditions and reporting errors. | |
Defines | |
| #define | bounds_return(value, low, high, to_return) { if (!basis::in_range(value, low, high)) return to_return; } |
| Verifies that "value" is between "low" and "high", inclusive. | |
| #define | bounds_halt(value, low, high, to_return) |
| Verifies that "value" is between "low" and "high", inclusive. | |
Functions | |
| template<class contents > | |
| bool | basis::in_range (const contents &value, const contents &low, const contents &high) |
| Returns true if the value is within the range specified. | |
| void | basis::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. | |
| void | basis::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. | |
| void | basis::throw_error (const astring &class_name, const astring &func_name, const astring &error_message) |
| synonym method using astrings for easier char * handling. | |
| #define bounds_halt | ( | value, | |||
| low, | |||||
| high, | |||||
| to_return | ) |
{ \
if (((value) < (low)) || ((value) > (high))) { \
throw_error(basis::astring(static_class_name()), basis::astring(func), \
basis::astring("value ") + #value \
+ " was not in range " + #low + " to " + #high \
+ " at " + __WHERE__); \
return to_return; \
} \
}
Verifies that "value" is between "low" and "high", inclusive.
"Value" must be an object for which greater than and less than are defined. The static_class_name() method and func definition are used to tag the complaint that is emitted when problems are detected. Note that if CATCH_ERRORS is defined, then the program is _halted_ if the value is out of bounds. Otherwise, the "to_return" value is returned.
Definition at line 60 of file guards.h.
Referenced by structures::matrix< contents >::insert_column(), structures::matrix< contents >::insert_row(), structures::matrix< contents >::zap_column(), and structures::matrix< contents >::zap_row().
| #define bounds_return | ( | value, | |||
| low, | |||||
| high, | |||||
| to_return | ) | { if (!basis::in_range(value, low, high)) return to_return; } |
Verifies that "value" is between "low" and "high", inclusive.
When the number is not in bounds, the function that is currently executing returns the "to_return" default provided. "to_return" can be empty for functions that return void. Note: it is also considered a failure for high to be less than low.
Definition at line 48 of file guards.h.
Referenced by geometric::angle< contents >::arccosine(), geometric::angle< contents >::arcsine(), mathematics::averager< contents >::average(), nodes::tree::branch(), structures::bit_vector::clear(), basis::astring::compare(), menu_base::enable_item(), menu_base::enable_submenu(), structures::amorph< contents >::find(), configuration::system_values::get(), basis::array< contents >::get(), application::command_line::get(), structures::version::get_component(), menu_base::get_item(), nodes::node::get_link(), menu_base::get_submenu(), basis::astring::insert(), structures::bit_vector::light(), structures::symbol_table< contents >::name(), structures::symbol_table< contents >::operator[](), structures::bit_vector::operator[](), structures::bit_vector::overwrite(), basis::array< contents >::overwrite(), nodes::tree::prune_index(), basis::array< contents >::put(), structures::symbol_table< contents >::retrieve(), structures::bit_vector::set(), structures::bit_vector::set_bit(), basis::array< contents >::subarray(), basis::astring::substring(), structures::bit_vector::subvector(), basis::array< contents >::use(), basis::astring::zap(), basis::array< contents >::zap(), application::command_line::zap(), menu_base::zap_item(), and menu_base::zap_submenu().
1.6.3