utilities.h
Go to the documentation of this file.
1 //=============================================================================
2 // File : utilities.h
3 // Created : mar jun 19 13:18:14 CEST 2001
4 // Author : Antoine YESSAYAN, Paul RASCLE, EDF
5 // Project : SALOME
6 // Copyright : EDF 2001
7 // $Header$
8 //=============================================================================
9 
10 /* --- Definition macros file to print information if _DEBUG_ is defined --- */
11 
12 #ifndef UTILITIES_H
13 #define UTILITIES_H
14 
15 #include <stdlib.h>
16 // # include <iostream> ok for gcc3.01
17 #include <iostream>
18 
19 /* --- INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */
20 
21 #define HEREWEARE \
22  cout << flush; \
23  cerr << __FILE__ << " [" << __LINE__ << "] : " << flush;
24 #define INFOS(chain) \
25  { \
26  HEREWEARE; \
27  cerr << chain << endl; \
28  }
29 #define PYSCRIPT(chain) \
30  { \
31  cout << flush; \
32  cerr << "---PYSCRIPT--- " << chain << endl; \
33  }
34 
35 /* --- To print date and time of compilation of current source on stdout --- */
36 
37 #if defined(__GNUC__)
38 #define COMPILER "g++";
39 #elif defined(__sun)
40 #define COMPILER "CC";
41 #elif defined(__KCC)
42 #define COMPILER "KCC";
43 #elif defined(__PGI)
44 #define COMPILER "pgCC";
45 #else
46 #define COMPILER "undefined";
47 #endif
48 
49 #ifdef INFOS_COMPILATION
50 #error INFOS_COMPILATION already defined
51 #endif
52 #define INFOS_COMPILATION \
53  { \
54  cerr << flush; \
55  cout << __FILE__; \
56  cout << " [" << __LINE__ << "] : "; \
57  cout << "COMPILED with " << COMPILER; \
58  cout << ", " << __DATE__; \
59  cout << " at " << __TIME__ << endl; \
60  cout << "\n\n"; \
61  cout << flush; \
62  }
63 
64 #ifdef _DEBUG_
65 
66 /* --- the following MACROS are useful at debug time --- */
67 
68 #define HERE \
69  cout << flush; \
70  cerr << "- Trace " << __FILE__ << " [" << __LINE__ << "] : " << flush;
71 #define SCRUTE(var) \
72  HERE; \
73  cerr << #var << "=" << var << endl;
74 #define MESSAGE(chain) \
75  { \
76  HERE; \
77  cerr << chain << endl; \
78  }
79 #define INTERRUPTION(code) \
80  HERE; \
81  cerr << "INTERRUPTION return code= " << code << endl; \
82  exit(code);
83 
84 #ifndef ASSERT
85 #define ASSERT(condition) \
86  if (!(condition)) { \
87  HERE; \
88  cerr << "CONDITION " << #condition << " NOT VERIFIED" << endl; \
89  INTERRUPTION(1); \
90  }
91 #endif /* ASSERT */
92 
93 #define REPERE \
94  cout << flush; \
95  cerr << " --------------" << endl << flush;
96 #define BEGIN_OF(chain) \
97  { \
98  REPERE; \
99  HERE; \
100  cerr << "Begin of: " << chain << endl; \
101  REPERE; \
102  }
103 #define END_OF(chain) \
104  { \
105  REPERE; \
106  HERE; \
107  cerr << "Normal end of: " << chain << endl; \
108  REPERE; \
109  }
110 
111 #else /* ifdef _DEBUG_*/
112 
113 #define HERE
114 #define SCRUTE(var)
115 #define MESSAGE(chain)
116 #define INTERRUPTION(code)
117 
118 #ifndef ASSERT
119 #define ASSERT(condition)
120 #endif /* ASSERT */
121 
122 #define REPERE
123 #define BEGIN_OF(chain)
124 #define END_OF(chain)
125 
126 #endif /* ifdef _DEBUG_*/
127 
128 #endif /* ifndef UTILITIES_H */