STXXL  1.4.0
 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 
25 #define _STXXL_PRNT_COUT (1 << 0)
26 #define _STXXL_PRNT_CERR (1 << 1)
27 #define _STXXL_PRNT_LOG (1 << 2)
28 #define _STXXL_PRNT_ERRLOG (1 << 3)
29 #define _STXXL_PRNT_ADDNEWLINE (1 << 16)
30 #define _STXXL_PRNT_TIMESTAMP (1 << 17)
31 #define _STXXL_PRNT_THREAD_ID (1 << 18)
32 
33 #define _STXXL_PRINT_FLAGS_DEFAULT (_STXXL_PRNT_COUT | _STXXL_PRNT_LOG)
34 #define _STXXL_PRINT_FLAGS_ERROR (_STXXL_PRNT_CERR | _STXXL_PRNT_ERRLOG)
35 #define _STXXL_PRINT_FLAGS_VERBOSE (_STXXL_PRINT_FLAGS_DEFAULT | _STXXL_PRNT_TIMESTAMP | _STXXL_PRNT_THREAD_ID)
36 
37 
39 
40 void print_msg(const char* label, const std::string& msg, unsigned flags);
41 
43 
44 
45 #define _STXXL_PRINT(label, message, flags) \
46  do { \
47  std::ostringstream str_; \
48  str_ << message; \
49  stxxl::print_msg(label, str_.str(), flags | _STXXL_PRNT_ADDNEWLINE); \
50  } while (false)
51 
52 #define _STXXL_NOT_VERBOSE do { } while (false)
53 
54 
55 #ifdef STXXL_FORCE_VERBOSE_LEVEL
56 #undef STXXL_VERBOSE_LEVEL
57 #define STXXL_VERBOSE_LEVEL STXXL_FORCE_VERBOSE_LEVEL
58 #endif
59 
60 #ifdef STXXL_DEFAULT_VERBOSE_LEVEL
61 #ifndef STXXL_VERBOSE_LEVEL
62 #define STXXL_VERBOSE_LEVEL STXXL_DEFAULT_VERBOSE_LEVEL
63 #endif
64 #endif
65 
66 #ifndef STXXL_VERBOSE_LEVEL
67 #define STXXL_VERBOSE_LEVEL -1
68 #endif
69 
70 
71 #if STXXL_VERBOSE_LEVEL > -10
72  #define STXXL_MSG(x) _STXXL_PRINT("STXXL-MSG", x, _STXXL_PRINT_FLAGS_DEFAULT)
73 #else
74 // Please do not report STXXL problems with STXXL_MSG disabled!
75  #define STXXL_MSG(x) _STXXL_NOT_VERBOSE
76 #endif
77 
78 #if STXXL_VERBOSE_LEVEL > -100
79  #define STXXL_ERRMSG(x) _STXXL_PRINT("STXXL-ERRMSG", x, _STXXL_PRINT_FLAGS_ERROR)
80 #else
81 // Please do not report STXXL problems with STXXL_ERRMSG disabled!
82  #define STXXL_ERRMSG(x) _STXXL_NOT_VERBOSE
83 #endif
84 
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
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
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
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
114 #endif
115 
116 
117 // STXXL_CHECK is an assertion macro for unit tests, which contrarily to
118 // assert() also works in release builds. These macros should ONLY be used in
119 // UNIT TESTS, not in the library source. Use usual assert() there.
120 
121 #define STXXL_CHECK(condition) \
122  do { \
123  if (!(condition)) { \
124  _STXXL_PRINT("STXXL-CHECK", \
125  #condition " - FAILED @ " __FILE__ ":" << __LINE__, \
126  _STXXL_PRINT_FLAGS_ERROR); abort(); \
127  } \
128  } while (0)
129 
130 #define STXXL_CHECK2(condition, text) \
131  do { \
132  if (!(condition)) { \
133  _STXXL_PRINT("STXXL-CHECK", \
134  text << " - " #condition " - FAILED @ " __FILE__ ":" << __LINE__, \
135  _STXXL_PRINT_FLAGS_ERROR); abort(); \
136  } \
137  } while (0)
138 
139 // STXXL_ASSERT is an assertion macro almost identical to assert(). The only
140 // difference is that with NDEBUG defined, the _code_ itself still exists. This
141 // silences warnings about unused variables and typedefs in release builds.
142 
143 #ifdef NDEBUG
144 
145 #define STXXL_ASSERT(condition) \
146  do { if (0) { \
147  if (!(condition)) { \
148  _STXXL_PRINT("STXXL-ASSERT", \
149  #condition " - FAILED @ " __FILE__ ":" << __LINE__, \
150  _STXXL_PRINT_FLAGS_ERROR); abort(); \
151  } \
152  } \
153  } while (0)
154 
155 #else
156 
157 #define STXXL_ASSERT(condition) \
158  do { if (1) { \
159  if (!(condition)) { \
160  _STXXL_PRINT("STXXL-ASSERT", \
161  #condition " - FAILED @ " __FILE__ ":" << __LINE__, \
162  _STXXL_PRINT_FLAGS_ERROR); abort(); \
163  } \
164  } \
165  } while (0)
166 
167 #endif
168 
169 // STXXL_CHECK_THROW is an assertion macro for unit tests, which checks that
170 // the enclosed code throws an exception.
171 
172 #define STXXL_CHECK_THROW(code, exception_type) \
173  do { \
174  bool t_ = false; try { code; } \
175  catch (const exception_type&) { t_ = true; } \
176  if (t_) break; \
177  _STXXL_PRINT("STXXL-CHECK-THROW", \
178  #code " - NO EXCEPTION " #exception_type \
179  " @ " __FILE__ ":" << __LINE__, \
180  _STXXL_PRINT_FLAGS_ERROR); \
181  abort(); \
182  } while (0)
183 
184 ////////////////////////////////////////////////////////////////////////////
185 
186 #endif // !STXXL_VERBOSE_HEADER
187 // 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:35
#define STXXL_END_NAMESPACE
Definition: namespace.h:17