00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef UTILITIES_H
00032 #define UTILITIES_H
00033
00034 #include <iostream>
00035 #include <sstream>
00036 #include <cstdlib>
00037
00038
00039 #define DEF_MSG_BUFFER std::cout
00040
00047 #define MESS_INIT(deb) std::ostringstream os; os<<deb
00048 #define MESS_BEGIN(deb) MESS_INIT(deb)<<__FILE__<<" ["<<__LINE__<<"] : "
00049
00050 #define MESS_END std::endl; \
00051 DEF_MSG_BUFFER << os.str() << std::endl;
00052
00053 #define MESS_ABORT std::endl; \
00054 DEF_MSG_BUFFER << os.str() << std::endl;
00055
00056
00057
00058 #define INFOS(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
00059 #define PYSCRIPT(msg) {MESS_INIT("---PYSCRIPT--- ") << msg << MESS_END}
00060 #define INTERRUPTION(msg) {MESS_BEGIN("- INTERRUPTION: ")<< msg << MESS_ABORT}
00061 #ifdef WNT
00062 #define IMMEDIATE_ABORT(code) {std::cout <<std::flush; \
00063 std::cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << flush; \
00064 std::cerr << "ABORT return code= "<< code << std::endl; \
00065 exit(code);}
00066 #else
00067 #define IMMEDIATE_ABORT(code) {std::cout <<std::flush; \
00068 std::cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << flush; \
00069 std::cerr << "ABORT return code= "<< code << std::endl; \
00070 std::exit(code);}
00071 #endif
00072
00073
00074
00075 #if defined ( __GNUC__ )
00076 #define COMPILER "g++"
00077 #elif defined ( __sun )
00078 #define COMPILER "CC"
00079 #elif defined ( __KCC )
00080 #define COMPILER "KCC"
00081 #elif defined ( __PGI )
00082 #define COMPILER "pgCC"
00083 #elif defined ( __alpha )
00084 #define COMPILER "cxx"
00085 #elif defined ( __BORLAND__ )
00086 #define COMPILER "bcc32"
00087 #else
00088 #define COMPILER "undefined"
00089 #endif
00090
00091 #ifdef INFOS_COMPILATION
00092 #error INFOS_COMPILATION already defined
00093 #endif
00094
00095 #if defined(_DEBUG_) || defined (_DEBUG)
00096
00097
00098
00099 #define INFOS_COMPILATION { MESS_BEGIN("COMPILED with ") << COMPILER \
00100 << ", " << __DATE__ \
00101 << " at " << __TIME__ << MESS_END }
00102
00103 #define MESSAGE(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
00104 #define SCRUTE(var) {MESS_BEGIN("- Trace ") << #var << "=" << var <<MESS_END}
00105
00106 #define REPERE ("------- ")
00107 #define BEGIN_OF(msg) {MESS_BEGIN(REPERE) << "Begin of: " << msg << MESS_END}
00108 #define END_OF(msg) {MESS_BEGIN(REPERE) << "Normal end of: " << msg << MESS_END}
00109
00110 #ifndef ASSERT
00111 #define ASSERT(condition) \
00112 if (!(condition)){INTERRUPTION("CONDITION "<<#condition<<" NOT VERIFIED")}
00113 #endif
00114
00115
00116 #elif !defined(_NOMSG_)
00117
00118 #define INFOS_COMPILATION
00119 #define MESSAGE(msg) {MESS_BEGIN("MSG:") << msg << MESS_END}
00120 #define SCRUTE(var) {MESS_BEGIN("SCRUTE:") << #var << " = " << var << MESS_END}
00121 #define REPERE ("-------")
00122 #define BEGIN_OF(msg) {MESS_BEGIN("MSG BEGIN:") << msg << MESS_END}
00123 #define END_OF(msg) {MESS_BEGIN("MSG END:") << msg << MESS_END}
00124
00125 #ifndef ASSERT
00126 #define ASSERT(condition) {}
00127 #endif
00128
00129 #else
00130
00131 #define INFOS_COMPILATION
00132 #define MESSAGE(msg)
00133 #define SCRUTE(var)
00134 #define REPERE
00135 #define BEGIN_OF(msg)
00136 #define END_OF(msg)
00137
00138 #ifndef ASSERT
00139 #define ASSERT(condition) {}
00140 #endif
00141
00142 #endif
00143
00144 #endif