SALOME - SMESH
|
00001 // SALOME Utils : general SALOME's definitions and tools 00002 // 00003 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, 00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 // 00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00021 // 00022 // 00023 // 00024 // File : utilities.h 00025 // Author : Antoine YESSAYAN, Paul RASCLE, EDF 00026 // Module : SALOME 00027 // $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/SALOMELocalTrace/utilities.h,v 1.6.2.1 2007/01/22 13:51:27 prascle Exp $ 00028 00029 /* --- Definition macros file to print informations if _DEBUG_ or _DEBUG is defined --- */ 00030 00031 #ifndef UTILITIES_H 00032 #define UTILITIES_H 00033 00034 #include <iostream> 00035 #include <sstream> 00036 #include <cstdlib> 00037 00038 //Can be redefined to reflect another buffer such as log, cerr or a custom one 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 // --- Some macros are always defined (without _DEBUG_): for use with release version 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 /* --- To print date and time of compilation of current source --- */ 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 // --- the following MACROS are useful at debug time 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 /* ASSERT */ 00114 00115 00116 #elif !defined(_NOMSG_) /* ifdef _DEBUG_*/ 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 /* ASSERT */ 00128 00129 #else /* ifdef _DEBUG_*/ 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 /* ASSERT */ 00141 00142 #endif /* ifdef _DEBUG_*/ 00143 00144 #endif /* ifndef UTILITIES_H */