]> SALOME platform Git repositories - modules/kernel.git/blob - src/Utils/utilities.h
Salome HOME
PR: mergefrom_PAL_OCC_21Oct04
[modules/kernel.git] / src / Utils / 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 <string>
35 #include <iostream>
36 #include "SALOME_Log.hxx"
37
38 /* ---  INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */
39
40 #define INFOS(msg)    {SLog.putMessage(SLog<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::ends);}
41 #define PYSCRIPT(msg) {SLog.putMessage(SLog<<"---PYSCRIPT--- "<<msg<<std::endl<<std::ends);}
42
43 /* --- To print date and time of compilation of current source --- */
44
45 #if defined ( __GNUC__ )
46 #define COMPILER                "g++" 
47 #elif defined ( __sun )
48 #define COMPILER                "CC" 
49 #elif defined ( __KCC )
50 #define COMPILER                "KCC" 
51 #elif defined ( __PGI )
52 #define COMPILER                "pgCC" 
53 #else
54 #define COMPILER                "undefined" 
55 #endif
56
57 #ifdef INFOS_COMPILATION
58 #error INFOS_COMPILATION already defined
59 #endif
60
61 #define INFOS_COMPILATION { \
62                            SLog.putMessage(\
63                                            SLog<<__FILE__<<" ["<< __LINE__<<"] : "\
64                                            << "COMPILED with " << COMPILER \
65                                            << ", " << __DATE__ \
66                                            << " at " << __TIME__ <<std::endl<<std::ends); }
67
68 #ifdef _DEBUG_
69
70 /* --- the following MACROS are useful at debug time --- */
71
72 #define MYTRACE SLog<<"- Trace "<<__FILE__<<" ["<<__LINE__<<"] : " 
73
74 #define MESSAGE(msg) {SLog.putMessage(MYTRACE<<msg<<std::endl<<std::ends);}
75 #define SCRUTE(var)  {SLog.putMessage(MYTRACE<<#var<<"="<<var<<std::endl<<std::ends);}
76
77 #define BEGIN_OF(msg) {SLog.putMessage(MYTRACE<<"Begin of: "<<msg<<"\n\n"<<std::ends);} 
78 #define END_OF(msg)   {SLog.putMessage(SLog<<"\n"<<std::ends); \
79                        SLog.putMessage(MYTRACE<<"Normal end of: "<<msg<<"\n"<<std::ends);}
80
81 #define HERE {std::cout<<std::flush ;std::cerr<<"- Trace "<<__FILE__<<" ["<<__LINE__<<"] : "<<std::flush;}
82
83 #define INTERRUPTION(code) {HERE; \
84                             cerr<<"INTERRUPTION return code= "<<code<<std::endl; \
85                             std::exit(code);}
86
87 #ifndef ASSERT
88 #define ASSERT(condition) \
89         if(!(condition)){ \
90           HERE; \
91           std::cerr<<"CONDITION "<<#condition<<" NOT VERIFIED"<<std::endl; \
92           INTERRUPTION(1); \
93         }
94
95 #endif /* ASSERT */
96
97
98 #else /* ifdef _DEBUG_*/
99
100 #define HERE 
101 #define SCRUTE(var) {}
102 #define MESSAGE(msg) {}
103 #define BEGIN_OF(msg) {}
104 #define END_OF(msg) {}
105
106 #define INTERRUPTION(code) {}
107
108 #ifndef ASSERT
109 #define ASSERT(condition) {}
110 #endif /* ASSERT */
111
112
113 #endif /* ifdef _DEBUG_*/
114
115 #endif /* ifndef UTILITIES_H */