00001 #ifndef GUARDS_GROUP
00002 #define GUARDS_GROUP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "definitions.h"
00019
00021
00027 namespace guards {
00028
00029
00030
00032 template <class contents>
00033 inline bool in_range(const contents &value, const contents &low,
00034 const contents &high)
00035 { return !( (high < low) || (value < low) || (value > high) ); }
00036
00038
00042 #define bounds_return(value, low, high, to_return) \
00043 { if (((value) < (low)) || ((value) > (high))) return to_return; }
00044
00046 #ifdef __UNIX__
00047 #define CAUSE_BREAKPOINT
00048
00049 #elif defined(__WIN32__)
00050 #ifdef __MINGW32__
00051 extern "C" {
00052
00053
00054 }
00055 #define CAUSE_BREAKPOINT
00056
00057 #else
00058 #define CAUSE_BREAKPOINT __debugbreak()
00059 #endif
00060 #endif
00061
00063
00066 #ifdef ERRORS_ARE_FATAL
00067 #define REQUIRE(check) if (!check) CAUSE_BREAKPOINT;
00068 #else
00069 #define REQUIRE(check)
00070 #endif
00071
00072
00073
00075 void write_to_console(const char *message);
00076
00078
00080 void alert_message(const char *info, const char *title = "Alert Message");
00081 void alert_message(const istring &info);
00082 void alert_message(const istring &info, const istring &title);
00083
00084
00085
00087 #ifndef EMBEDDED_BUILD
00088 #define BH_ERROR_ADDITION ((istring(" in ") + __argv[0]).s())
00089 #else
00090 #define BH_ERROR_ADDITION ""
00091 #endif
00092
00094
00099 #ifdef CATCH_ERRORS
00100 #define bounds_halt(value, low, high, to_return) { \
00101 if (((value) < (low)) || ((value) > (high))) { \
00102 guards::implement_bounds_halt(static_class_name(), func, #value, #low, \
00103 #high, BH_ERROR_ADDITION); \
00104 return to_return; \
00105 } \
00106 }
00107 #else
00108 #define bounds_halt(a, b, c, d) bounds_return(a, b, c, d)
00109 #endif
00110
00112
00114
00116 #define non_continuable_error(c, f, i) \
00117 guards::FL_non_continuable_error(__FILE__, __LINE__, c, f, i, \
00118 "A Non-Continuable Runtime Problem Has Occurred")
00119 #define continuable_error(c, f, i) \
00120 guards::FL_continuable_error(__FILE__, __LINE__, c, f, i, \
00121 "Runtime Problem Information")
00122 #define console_error(c, f, i) \
00123 guards::FL_console_error(__FILE__, __LINE__, c, f, i)
00124 #define deadly_error(c, f, i) \
00125 guards::FL_deadly_error(__FILE__, __LINE__, c, f, i)
00126 #define out_of_memory_now(c, f) \
00127 guards::FL_out_of_memory_now(__FILE__, __LINE__, c, f)
00128
00130
00131
00132
00134
00140 void FL_deadly_error(const char *file, int line, const char *classname,
00141 const char *function_name, const char *info);
00143 void FL_deadly_error(const istring &file, int line,
00144 const istring &classname, const istring &function_name,
00145 const istring &info);
00146
00148 void FL_continuable_error(const char *file, int line,
00149 const char *classname, const char *function_name, const char *info,
00150 const char *title);
00151
00153 void FL_continuable_error(const istring &file, int line,
00154 const istring &classname, const istring &function_name,
00155 const istring &info, const istring &title);
00156
00158
00162 void FL_non_continuable_error(const char *file, int line,
00163 const char *classname, const char *function_name, const char *info,
00164 const char *title);
00165
00167 void FL_non_continuable_error(const istring &file, int line,
00168 const istring &classname, const istring &function_name,
00169 const istring &info, const istring &title);
00170
00172 void FL_out_of_memory_now(const char *file, int line,
00173 const char *classname, const char *function_name);
00174
00176 void FL_console_error(const char *file, int line, const char *error_class,
00177 const char *error_function, const char *info);
00178
00180
00182 void make_error_message(const char *file, int line,
00183 const char *error_class, const char *error_function,
00184 const char *info, char *guards_message_space);
00185
00187 void implement_bounds_halt(const char *the_class_name, const char *func,
00188 const char *value, const char *low, const char *high,
00189 const char *error_addition);
00190
00191 }
00192
00193 #endif
00194