00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 #ifndef __EXCEPTION_HPP
00014 #define __EXCEPTION_HPP
00015 #include <basix/syntactic.hpp>
00016 
00018 
00019 namespace mmx {
00020 
00021 
00022 
00023 
00024 
00025 class exception {
00026 MMX_ALLOCATORS
00027   generic rep;
00028 public:
00029   inline generic operator * () const { return rep; }
00030   inline exception (): rep (generic ("empty exception")) {}
00031   inline exception (const generic& g): rep (g) {}
00032   inline exception (const exception& e): rep (e.rep) {}
00033   exception (const string& msg, const generic& where);
00034 };
00035 
00036 inline nat hash (const exception& e) { return hash (*e); }
00037 inline nat exact_hash (const exception& e) { return exact_hash (*e); }
00038 inline nat hard_hash (const exception& e) { return hard_hash (*e); }
00039 inline bool operator == (const exception& e1, const exception& e2) {
00040   return (*e1) == (*e2); }
00041 inline bool operator != (const exception& e1, const exception& e2) {
00042   return (*e1) != (*e2); }
00043 inline bool exact_eq (const exception& e1, const exception& e2) {
00044   return exact_eq (*e1, *e2); }
00045 inline bool exact_neq (const exception& e1, const exception& e2) {
00046   return exact_neq (*e1, *e2); }
00047 inline bool hard_eq (const exception& e1, const exception& e2) {
00048   return hard_eq (*e1, *e2); }
00049 inline bool hard_neq (const exception& e1, const exception& e2) {
00050   return hard_neq (*e1, *e2); }
00051 
00052 inline syntactic flatten (const exception& e) { return flatten (*e); }
00053 
00054 generic std_exception (const string& msg, const generic& where);
00055 generic std_exception (const string& msg, const generic& a, const generic& w);
00056 generic user_exception (const vector<generic>& msg, const generic& where);
00057 generic wrong_nr_args (const generic& where);
00058 generic type_mismatch (const generic& expect, const generic& where);
00059 generic trace_push (const generic& exc, const generic& where);
00060 generic trace_pull (const generic& exc);
00061 generic trace_top (const generic& exc);
00062 generic trace_bottom (const generic& exc, nat n= 1);
00063 bool    has_trace (const generic& exc);
00064 
00065 
00066 
00067 
00068 
00069 #ifdef BASIX_ENABLE_EXCEPTIONS
00071 exception as_exception (const generic& x);
00072 
00073 
00074 exception error_message (const char* msg);
00075 exception error_message (const string& msg);
00077 #define STRINGIFY(x) #x
00078 #define TOSTRING(x) STRINGIFY(x)
00079 #define ERROR(msg) \
00080   throw mmx::error_message (__FILE__ ":" TOSTRING(__LINE__) ": " msg);
00081 #define ASSERT(expr,msg)                                         \
00082   if (!(expr)) ERROR (msg);
00083 #else // disable exceptions
00084 #define ERROR(msg) assert(false);
00085 #define ASSERT(expr,msg) assert(expr);
00086 #endif
00087 
00088 #ifdef BASIX_ENABLE_VERIFY
00089 #define VERIFY(expr,msg) ASSERT(expr,msg)
00090 #define XVERIFY(expr,msg,x) \
00091   if (!(expr)) mmerr << "failed for instance " << x << "\n";    \
00092   ASSERT(expr,msg)
00093 #else // disable verifications
00094 #define VERIFY(expr,msg)
00095 #define XVERIFY(expr,msg,x)
00096 #endif
00097 
00099 volatile void fatal_error (char* message, char* routine, char* file);
00100 
00101 
00102 
00103 
00104 
00105 string cpp_demangle (const char* name);
00106 
00107 } 
00108 #endif // __EXCEPTION_HPP