SALOME - SMESH
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
utilities.h
Go to the documentation of this file.
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 : webmaster.salome@opencascade.com
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 
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 #if defined ( __GNUC__ )
79 #define COMPILER "g++"
80 #elif defined ( __sun )
81 #define COMPILER "CC"
82 #elif defined ( __KCC )
83 #define COMPILER "KCC"
84 #elif defined ( __PGI )
85 #define COMPILER "pgCC"
86 #elif defined ( __alpha )
87 #define COMPILER "cxx"
88 #elif defined ( __BORLAND__ )
89 #define COMPILER "bcc32"
90 #else
91 #define COMPILER "undefined"
92 #endif
93 
94 #ifdef INFOS_COMPILATION
95 #error INFOS_COMPILATION already defined
96 #endif
97 
98 #if defined(_DEBUG_) || defined (_DEBUG)
99 
100 // --- the following MACROS are useful at debug time
101 
102 #define INFOS_COMPILATION { MESS_BEGIN("COMPILED with ") << COMPILER \
103  << ", " << __DATE__ \
104  << " at " << __TIME__ << MESS_END }
105 
106 #define MESSAGE(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
107 #define SCRUTE(var) {MESS_BEGIN("- Trace ") << #var << "=" << var <<MESS_END}
108 
109 #define REPERE ("------- ")
110 #define BEGIN_OF(msg) {MESS_BEGIN(REPERE) << "Begin of: " << msg << MESS_END}
111 #define END_OF(msg) {MESS_BEGIN(REPERE) << "Normal end of: " << msg << MESS_END}
112 
113 #ifndef ASSERT
114 #define ASSERT(condition) \
115  if (!(condition)){INTERRUPTION("CONDITION "<<#condition<<" NOT VERIFIED")}
116 #endif /* ASSERT */
117 
118 
119 #elif !defined(_NOMSG_) /* ifdef _DEBUG_*/
120 
121 #define INFOS_COMPILATION
122 #define MESSAGE(msg) {MESS_BEGIN("MSG:") << msg << MESS_END}
123 #define SCRUTE(var) {MESS_BEGIN("SCRUTE:") << #var << " = " << var << MESS_END}
124 #define REPERE ("-------")
125 #define BEGIN_OF(msg) {MESS_BEGIN("MSG BEGIN:") << msg << MESS_END}
126 #define END_OF(msg) {MESS_BEGIN("MSG END:") << msg << MESS_END}
127 
128 #ifndef ASSERT
129 #define ASSERT(condition) {}
130 #endif /* ASSERT */
131 
132 #else /* ifdef _DEBUG_*/
133 
134 #define INFOS_COMPILATION
135 #define MESSAGE(msg)
136 #define SCRUTE(var)
137 #define REPERE
138 #define BEGIN_OF(msg)
139 #define END_OF(msg)
140 
141 #ifndef ASSERT
142 #define ASSERT(condition) {}
143 #endif /* ASSERT */
144 
145 #endif /* ifdef _DEBUG_*/
146 
147 #endif /* ifndef UTILITIES_H */