Debian Codegraph @

src/3rdParty/salomesmesh/inc/utilities.h

raw
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.salome-platform.org/ or email : [email protected]
21 //
22 //
23 //
24 // File : utilities.h
25 // Author : Antoine YESSAYAN, Paul RASCLE, EDF
26 // Module : SALOME
27 // $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/SALOMELocalTrace/utilities.h,v 1.6.2.1 2007/01/22 13:51:27 prascle Exp $
28
29 // switch off massaging in release:
30 #define _NOMSG_
31
32 /* --- Definition macros file to print informations if _DEBUG_ or _DEBUG is defined --- */
33
34 #ifndef UTILITIES_H
35 #define UTILITIES_H
36
37 #include <iostream>
38 #include <sstream>
39 #include <cstdlib>
40
41 //Can be redefined to reflect another buffer such as log, cerr or a custom one
42 #define DEF_MSG_BUFFER std::cout
43
44 /*!
45 * For each message to put in the trace, a specific ostingstream object is
46 * created and destroyed automatically at the end of the message macro.
47 * This message is automatically passed to std::cout
48 */
49
50 #define MESS_INIT(deb) std::ostringstream os; os<<deb
51 #define MESS_BEGIN(deb) MESS_INIT(deb)<<__FILE__<<" ["<<__LINE__<<"] : "
52
53 #define MESS_END std::endl; \
54 DEF_MSG_BUFFER << os.str() << std::endl;
55
56 #define MESS_ABORT std::endl; \
57 DEF_MSG_BUFFER << os.str() << std::endl;
58
59 // --- Some macros are always defined (without _DEBUG_): for use with release version
60
61 #define INFOS(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
62 #define PYSCRIPT(msg) {MESS_INIT("---PYSCRIPT--- ") << msg << MESS_END}
63 #define INTERRUPTION(msg) {MESS_BEGIN("- INTERRUPTION: ")<< msg << MESS_ABORT}
64 #ifdef WNT
65 #define IMMEDIATE_ABORT(code) {std::cout <<std::flush; \
66 std::cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << flush; \
67 std::cerr << "ABORT return code= "<< code << std::endl; \
68 exit(code);}
69 #else
70 #define IMMEDIATE_ABORT(code) {std::cout <<std::flush; \
71 std::cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << flush; \
72 std::cerr << "ABORT return code= "<< code << std::endl; \
73 std::exit(code);}
74 #endif
75
76 /* --- To print date and time of compilation of current source --- */
77
78 #ifndef COMPILER
79 #if defined ( __GNUC__ )
80 #define COMPILER "g++"
81 #elif defined ( __sun )
82 #define COMPILER "CC"
83 #elif defined ( __KCC )
84 #define COMPILER "KCC"
85 #elif defined ( __PGI )
86 #define COMPILER "pgCC"
87 #elif defined ( __alpha )
88 #define COMPILER "cxx"
89 #elif defined ( __BORLAND__ )
90 #define COMPILER "bcc32"
91 #else
92 #define COMPILER "undefined"
93 #endif
94 #endif
95
96 #ifdef INFOS_COMPILATION
97 #error INFOS_COMPILATION already defined
98 #endif
99
100 #if defined(_DEBUG_) || defined (_DEBUG)
101
102 // --- the following MACROS are useful at debug time
103
104 #define INFOS_COMPILATION { MESS_BEGIN("COMPILED with ") << COMPILER \
105 << ", " << __DATE__ \
106 << " at " << __TIME__ << MESS_END }
107
108 #define MESSAGE(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
109 #define SCRUTE(var) {MESS_BEGIN("- Trace ") << #var << "=" << var <<MESS_END}
110
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}
114
115 #ifndef ASSERT
116 #define ASSERT(condition) \
117 if (!(condition)){INTERRUPTION("CONDITION "<<#condition<<" NOT VERIFIED")}
118 #endif /* ASSERT */
119
120
121 #elif !defined(_NOMSG_) /* ifdef _DEBUG_*/
122
123 #define INFOS_COMPILATION
124 #define MESSAGE(msg) {MESS_BEGIN("MSG:") << msg << MESS_END}
125 #define SCRUTE(var) {MESS_BEGIN("SCRUTE:") << #var << " = " << var << MESS_END}
126 #define REPERE ("-------")
127 #define BEGIN_OF(msg) {MESS_BEGIN("MSG BEGIN:") << msg << MESS_END}
128 #define END_OF(msg) {MESS_BEGIN("MSG END:") << msg << MESS_END}
129
130 #ifndef ASSERT
131 #define ASSERT(condition) {}
132 #endif /* ASSERT */
133
134 #else /* ifdef _DEBUG_*/
135
136 #define INFOS_COMPILATION
137 #define MESSAGE(msg) {}
138 #define SCRUTE(var) {}
139 #define REPERE
140 #define BEGIN_OF(msg)
141 #define END_OF(msg)
142
143 #ifndef ASSERT
144 #define ASSERT(condition) {}
145 #endif /* ASSERT */
146
147 #endif /* ifdef _DEBUG_*/
148
149 #endif /* ifndef UTILITIES_H */