STXXL  1.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
verbose.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/verbose.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2005-2006 Roman Dementiev <[email protected]>
7  * Copyright (C) 2007-2010 Andreas Beckmann <[email protected]>
8  * Copyright (C) 2013 Timo Bingmann <[email protected]>
9  *
10  * Distributed under the Boost Software License, Version 1.0.
11  * (See accompanying file LICENSE_1_0.txt or copy at
12  * http://www.boost.org/LICENSE_1_0.txt)
13  **************************************************************************/
14 
15 #ifndef STXXL_VERBOSE_HEADER
16 #define STXXL_VERBOSE_HEADER
17 
18 #include <cstdlib>
19 #include <iostream>
20 #include <sstream>
21 #include <string>
22 #include <stxxl/bits/unused.h>
23 
24 #define _STXXL_PRNT_COUT (1 << 0)
25 #define _STXXL_PRNT_CERR (1 << 1)
26 #define _STXXL_PRNT_LOG (1 << 2)
27 #define _STXXL_PRNT_ERRLOG (1 << 3)
28 #define _STXXL_PRNT_ADDNEWLINE (1 << 16)
29 #define _STXXL_PRNT_TIMESTAMP (1 << 17)
30 #define _STXXL_PRNT_THREAD_ID (1 << 18)
31 
32 #define _STXXL_PRINT_FLAGS_DEFAULT (_STXXL_PRNT_COUT | _STXXL_PRNT_LOG)
33 #define _STXXL_PRINT_FLAGS_ERROR (_STXXL_PRNT_CERR | _STXXL_PRNT_ERRLOG)
34 #define _STXXL_PRINT_FLAGS_VERBOSE (_STXXL_PRINT_FLAGS_DEFAULT | _STXXL_PRNT_TIMESTAMP | _STXXL_PRNT_THREAD_ID)
35 
37 
38 void print_msg(const char* label, const std::string& msg, unsigned flags);
39 
41 
42 #define _STXXL_PRINT(label, message, flags) \
43  do { \
44  std::ostringstream str_; \
45  str_ << message; \
46  stxxl::print_msg(label, str_.str(), flags | _STXXL_PRNT_ADDNEWLINE); \
47  } while (false)
48 
49 #define _STXXL_NOT_VERBOSE(message) \
50  do { \
51  if (0) { \
52  std::ostringstream str_; \
53  str_ << message; \
54  } \
55  } while (false)
56 
57 #ifdef STXXL_FORCE_VERBOSE_LEVEL
58 #undef STXXL_VERBOSE_LEVEL
59 #define STXXL_VERBOSE_LEVEL STXXL_FORCE_VERBOSE_LEVEL
60 #endif
61 
62 #ifdef STXXL_DEFAULT_VERBOSE_LEVEL
63 #ifndef STXXL_VERBOSE_LEVEL
64 #define STXXL_VERBOSE_LEVEL STXXL_DEFAULT_VERBOSE_LEVEL
65 #endif
66 #endif
67 
68 #ifndef STXXL_VERBOSE_LEVEL
69 #define STXXL_VERBOSE_LEVEL -1
70 #endif
71 
72 #if STXXL_VERBOSE_LEVEL > -10
73  #define STXXL_MSG(x) _STXXL_PRINT("STXXL-MSG", x, _STXXL_PRINT_FLAGS_DEFAULT)
74 #else
75 // Please do not report STXXL problems with STXXL_MSG disabled!
76  #define STXXL_MSG(x) _STXXL_NOT_VERBOSE(x)
77 #endif
78 
79 #if STXXL_VERBOSE_LEVEL > -100
80  #define STXXL_ERRMSG(x) _STXXL_PRINT("STXXL-ERRMSG", x, _STXXL_PRINT_FLAGS_ERROR)
81 #else
82 // Please do not report STXXL problems with STXXL_ERRMSG disabled!
83  #define STXXL_ERRMSG(x) _STXXL_NOT_VERBOSE(x)
84 #endif
85 
86 // STXXL_VERBOSE0 should be used for current debugging activity only,
87 // and afterwards be replaced by STXXL_VERBOSE1 or higher.
88 // Code that actively uses STXXL_VERBOSE0 should never get into a release.
89 
90 #if STXXL_VERBOSE_LEVEL > -1
91  #define STXXL_VERBOSE0(x) _STXXL_PRINT("STXXL-VERBOSE0", x, _STXXL_PRINT_FLAGS_VERBOSE)
92 #else
93  #define STXXL_VERBOSE0(x) _STXXL_NOT_VERBOSE(x)
94 #endif
95 
96 #if STXXL_VERBOSE_LEVEL > 0
97  #define STXXL_VERBOSE1(x) _STXXL_PRINT("STXXL-VERBOSE1", x, _STXXL_PRINT_FLAGS_VERBOSE)
98 #else
99  #define STXXL_VERBOSE1(x) _STXXL_NOT_VERBOSE(x)
100 #endif
101 
102 #define STXXL_VERBOSE(x) STXXL_VERBOSE1(x)
103 
104 #if STXXL_VERBOSE_LEVEL > 1
105  #define STXXL_VERBOSE2(x) _STXXL_PRINT("STXXL-VERBOSE2", x, _STXXL_PRINT_FLAGS_VERBOSE)
106 #else
107  #define STXXL_VERBOSE2(x) _STXXL_NOT_VERBOSE(x)
108 #endif
109 
110 #if STXXL_VERBOSE_LEVEL > 2
111  #define STXXL_VERBOSE3(x) _STXXL_PRINT("STXXL-VERBOSE3", x, _STXXL_PRINT_FLAGS_VERBOSE)
112 #else
113  #define STXXL_VERBOSE3(x) _STXXL_NOT_VERBOSE(x)
114 #endif
115 
116 // STXXL_VERBOSE[0123]_THIS prefixes "[0xaddress]" and then calls the version
117 // without _THIS.
118 
119 #define STXXL_VERBOSE0_THIS(x) \
120  STXXL_VERBOSE0("[" << static_cast<void*>(this) << "] " << x)
121 
122 #define STXXL_VERBOSE1_THIS(x) \
123  STXXL_VERBOSE1("[" << static_cast<void*>(this) << "] " << x)
124 
125 #define STXXL_VERBOSE2_THIS(x) \
126  STXXL_VERBOSE2("[" << static_cast<void*>(this) << "] " << x)
127 
128 #define STXXL_VERBOSE3_THIS(x) \
129  STXXL_VERBOSE3("[" << static_cast<void*>(this) << "] " << x)
130 
131 // STXXL_CHECK is an assertion macro for unit tests, which contrarily to
132 // assert() also works in release builds. These macros should ONLY be used in
133 // UNIT TESTS, not in the library source. Use usual assert() there.
134 
135 #define STXXL_CHECK(condition) \
136  do { \
137  if (!(condition)) { \
138  _STXXL_PRINT("STXXL-CHECK", \
139  #condition " - FAILED @ " __FILE__ ":" << __LINE__, \
140  _STXXL_PRINT_FLAGS_ERROR); abort(); \
141  } \
142  } while (0)
143 
144 #define STXXL_CHECK2(condition, text) \
145  do { \
146  if (!(condition)) { \
147  _STXXL_PRINT("STXXL-CHECK", \
148  text << " - " #condition " - FAILED @ " __FILE__ ":" << __LINE__, \
149  _STXXL_PRINT_FLAGS_ERROR); abort(); \
150  } \
151  } while (0)
152 
153 // STXXL_ASSERT is an assertion macro almost identical to assert(). The only
154 // difference is that with NDEBUG defined, the _code_ itself still exists. This
155 // silences warnings about unused variables and typedefs in release builds.
156 
157 #ifdef NDEBUG
158 
159 #define STXXL_ASSERT(condition) \
160  do { if (0) { \
161  if (!(condition)) { \
162  _STXXL_PRINT("STXXL-ASSERT", \
163  #condition " - FAILED @ " __FILE__ ":" << __LINE__, \
164  _STXXL_PRINT_FLAGS_ERROR); abort(); \
165  } \
166  } \
167  } while (0)
168 
169 #else
170 
171 #define STXXL_ASSERT(condition) \
172  do { if (1) { \
173  if (!(condition)) { \
174  _STXXL_PRINT("STXXL-ASSERT", \
175  #condition " - FAILED @ " __FILE__ ":" << __LINE__, \
176  _STXXL_PRINT_FLAGS_ERROR); abort(); \
177  } \
178  } \
179  } while (0)
180 
181 #endif
182 
183 // STXXL_CHECK_THROW is an assertion macro for unit tests, which checks that
184 // the enclosed code throws an exception.
185 
186 #define STXXL_CHECK_THROW(code, exception_type) \
187  do { \
188  bool t_ = false; try { code; } \
189  catch (const exception_type&) { t_ = true; } \
190  if (t_) break; \
191  _STXXL_PRINT("STXXL-CHECK-THROW", \
192  #code " - NO EXCEPTION " #exception_type \
193  " @ " __FILE__ ":" << __LINE__, \
194  _STXXL_PRINT_FLAGS_ERROR); \
195  abort(); \
196  } while (0)
197 
198 ////////////////////////////////////////////////////////////////////////////
199 
200 #endif // !STXXL_VERBOSE_HEADER
201 // vim: et:ts=4:sw=4
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
void print_msg(const char *label, const std::string &msg, unsigned flags)
Definition: verbose.cpp:33
#define STXXL_END_NAMESPACE
Definition: namespace.h:17