Salome HOME
94543b9f2972456619193df7a5ac5a120731aa47
[modules/kernel.git] / src / SALOMELocalTrace / utilities.h
1 //  SALOME Utils : general SALOME's definitions and tools
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : utilities.h
25 //  Author : Antoine YESSAYAN, Paul RASCLE, EDF
26 //  Module : SALOME
27 //  $Header$
28
29 /* ---  Definition macros file to print informations if _DEBUG_ is defined --- */
30
31 #ifndef UTILITIES_H
32 #define UTILITIES_H
33
34 #include <strstream>
35 #include <iostream>
36 #include <sstream>
37 #include <cstdlib>
38
39 using namespace std;
40
41 #include "LocalTraceBufferPool.hxx"
42
43 /*!
44  * For each message to put in the trace, a specific ostingstream object is
45  * created and destroyed automatically at the end of the message macro.
46  * The insert function of LocalTraceBufferPool class gets a buffer in a
47  * buffer pool (unique with the help of mutexes and semaphores) and copy the
48  * message in the buffer.
49  * This buffer is read later by a specific thread in charge of trace print.
50  * Order of trace entries is globally respected. Nevertheless, if there are
51  * several threads waiting for a free buffer to trace, the order of
52  * thread waken up is not garanteed (no fifo or priority rules in Linux Kernel)
53  */
54
55 #define MESS_INIT(deb) ostringstream os; os<<deb
56 #define MESS_BEGIN(deb) MESS_INIT(deb)<<__FILE__ <<" ["<<__LINE__<<"] : "
57 #define MESS_END endl; LocalTraceBufferPool::instance()->insert(NORMAL_MESS, os.str().c_str());
58 #define MESS_ABORT endl; LocalTraceBufferPool::instance()->insert(ABORT_MESS, os.str().c_str());
59
60 // --- Some macros are always defined (without _DEBUG_): for use with release version
61
62 #define INFOS(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
63 #define PYSCRIPT(msg) {MESS_INIT("---PYSCRIPT--- ") << msg << MESS_END}
64 #define INTERRUPTION(msg) {MESS_BEGIN("- INTERRUPTION: ")<< msg << MESS_ABORT}
65 #define IMMEDIATE_ABORT(code) {cout <<flush; \
66                                cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << flush; \
67                                cerr << "ABORT return code= "<< code << endl; \
68                                std::exit(code);}
69
70 /* --- To print date and time of compilation of current source --- */
71
72 #if defined ( __GNUC__ )
73 #define COMPILER                "g++" 
74 #elif defined ( __sun )
75 #define COMPILER                "CC" 
76 #elif defined ( __KCC )
77 #define COMPILER                "KCC" 
78 #elif defined ( __PGI )
79 #define COMPILER                "pgCC" 
80 #elif defined ( __alpha )
81 #define COMPILER                "cxx" 
82 #else
83 #define COMPILER                "undefined" 
84 #endif
85
86 #ifdef INFOS_COMPILATION
87 #error INFOS_COMPILATION already defined
88 #endif
89
90 #define INFOS_COMPILATION { MESS_BEGIN("COMPILED with ") << COMPILER \
91                                        << ", " << __DATE__ \
92                                        << " at " << __TIME__ << MESS_END }
93 #ifdef _DEBUG_
94
95 // --- the following MACROS are useful at debug time
96
97 #define MESSAGE(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
98 #define SCRUTE(var)  {MESS_BEGIN("- Trace ") << #var << "=" << var <<MESS_END}
99
100 #define REPERE ("------- ")
101 #define BEGIN_OF(msg) {MESS_BEGIN(REPERE) << "Begin of: "      << msg << MESS_END} 
102 #define END_OF(msg)   {MESS_BEGIN(REPERE) << "Normal end of: " << msg << MESS_END} 
103
104 #ifndef ASSERT
105 #define ASSERT(condition) \
106         if (!(condition)){INTERRUPTION("CONDITION "<<#condition<<" NOT VERIFIED")}
107 #endif /* ASSERT */
108
109
110 #else /* ifdef _DEBUG_*/
111
112 #define MESSAGE(msg) {}
113 #define SCRUTE(var) {}
114 #define REPERE
115 #define BEGIN_OF(msg) {}
116 #define END_OF(msg) {}
117
118 #ifndef ASSERT
119 #define ASSERT(condition) {}
120 #endif /* ASSERT */
121
122 #endif /* ifdef _DEBUG_*/
123
124 #endif /* ifndef UTILITIES_H */