1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME Utils : general SALOME's definitions and tools
24 // Author : Antoine YESSAYAN, Paul RASCLE, EDF
28 /* --- Definition macros file to print informations if _DEBUG_ is defined --- */
38 #include "LocalTraceBufferPool.hxx"
41 * For each message to put in the trace, a specific ostingstream object is
42 * created and destroyed automatically at the end of the message macro.
43 * The insert function of LocalTraceBufferPool class gets a buffer in a
44 * buffer pool (unique with the help of mutexes and semaphores) and copy the
45 * message in the buffer.
46 * This buffer is read later by a specific thread in charge of trace print.
47 * Order of trace entries is globally respected. Nevertheless, if there are
48 * several threads waiting for a free buffer to trace, the order of
49 * thread waken up is not garanteed (no fifo or priority rules in Linux Kernel)
52 #define MESS_INIT(deb) std::ostringstream os; os<<deb
53 #define MESS_BEGIN(deb) MESS_INIT(deb)<<__FILE__ <<" ["<<__LINE__<<"] : "
54 #define MESS_END std::endl; LocalTraceBufferPool::instance()->insert(NORMAL_MESS, os.str().c_str());
55 #define MESS_ABORT std::endl; LocalTraceBufferPool::instance()->insert(ABORT_MESS, os.str().c_str());
57 // Macroses for messages with separated structure in c++ file in _DUBUG mode
58 #define MESSAGE_BEGIN(msg) {std::ostringstream ss; ss <<__FILE__ <<" ["<<__LINE__<<"] : "<< msg; LocalTraceBufferPool::instance()->insert(NORMAL_MESS, ss.str().c_str());}
59 #define MESSAGE_ADD(msg) {std::ostringstream ss; ss << msg; LocalTraceBufferPool::instance()->insert(NORMAL_MESS, ss.str().c_str());}
60 #define MESSAGE_END(msg) {std::ostringstream ss; ss << msg << std::endl; LocalTraceBufferPool::instance()->insert(NORMAL_MESS, ss.str().c_str());}
62 // --- Some macros are always defined (without _DEBUG_): for use with release version
64 #define INFOS(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
65 #define PYSCRIPT(msg) {MESS_INIT("---PYSCRIPT--- ") << msg << MESS_END}
66 #define INTERRUPTION(msg) {MESS_BEGIN("- INTERRUPTION: ")<< msg << MESS_ABORT}
69 #define IMMEDIATE_ABORT(code) {std::cout <<std::flush; \
70 std::cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << flush; \
71 std::cerr << "ABORT return code= "<< code << std::endl; \
74 #define IMMEDIATE_ABORT(code) {std::cout <<std::flush; \
75 std::cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << flush; \
76 std::cerr << "ABORT return code= "<< code << std::endl; \
80 /* --- To print date and time of compilation of current source --- */
82 #if defined ( __GNUC__ )
83 #define COMPILER "g++"
84 #elif defined ( __sun )
86 #elif defined ( __KCC )
87 #define COMPILER "KCC"
88 #elif defined ( __PGI )
89 #define COMPILER "pgCC"
90 #elif defined ( __alpha )
91 #define COMPILER "cxx"
93 #define COMPILER "undefined"
96 #ifdef INFOS_COMPILATION
97 #error INFOS_COMPILATION already defined
100 #if defined(_DEBUG_) || defined(_DEBUG)
102 // --- the following MACROS are useful at debug time
104 #define INFOS_COMPILATION { MESS_BEGIN("COMPILED with ") << COMPILER \
105 << ", " << __DATE__ \
106 << " at " << __TIME__ << MESS_END }
108 #define MESSAGE(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
109 #define SCRUTE(var) {MESS_BEGIN("- Trace ") << #var << "=" << var <<MESS_END}
111 #define REPERE ("------- ")
112 #define BEGIN_OF(msg) {MESS_BEGIN(REPERE) << "Begin of: " << msg << MESS_END}
113 #define END_OF(msg) {MESS_BEGIN(REPERE) << "Normal end of: " << msg << MESS_END}
116 #define ASSERT(condition) \
117 if (!(condition)){INTERRUPTION("CONDITION "<<#condition<<" NOT VERIFIED")}
121 #else /* ifdef _DEBUG_*/
123 #define INFOS_COMPILATION
124 #define MESSAGE(msg) {}
125 #define SCRUTE(var) {}
127 #define BEGIN_OF(msg) {}
128 #define END_OF(msg) {}
131 #define ASSERT(condition) {}
134 #endif /* ifdef _DEBUG_*/
136 #endif /* ifndef UTILITIES_H */