My Project
msgstream.hh
Go to the documentation of this file.
1/* -*- mia-c++ -*-
2 *
3 * This file is part of MIA - a toolbox for medical image analysis
4 * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5 *
6 * MIA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21
22#ifndef CVERB_HH
23#define CVERB_HH 1
24
25//#pragma interface
26#include <vector>
27#include <cassert>
28#include <ostream>
29#include <boost/call_traits.hpp>
30#include <boost/ref.hpp>
31#include <miaconfig.h>
32#include <mia/core/defines.hh>
33#include <mia/core/dictmap.hh>
34#include <mia/core/svector.hh>
35
37
38#ifndef VSTREAM_DOMAIN
39#define VSTREAM_DOMAIN "**"
40#endif
41
42
56{
57public:
74
78 static vstream& instance();
79
80
85
87 vstream::Level get_level() const;
88
94 std::ostream& set_stream(std::ostream& os);
95
97 void flush();
98
102 bool shows(Level l)const;
103
105 bool show_debug() const;
106
107
112
118 template <class T>
119 vstream& operator << (const T& text)
120 {
121 if (m_message_level >= m_output_level)
122 *m_output << text;
123
124 return *this;
125 }
126
131 vstream& operator<<(std::ostream & (*f)(std::ostream&));
132
133
134
139 static void set_output_target(std::ostream *os);
140
144 operator std::ostream& ()
145 {
146 return *m_output;
147 }
148
149private:
150 vstream(std::ostream& output, Level l);
151
152 static std::ostream *m_output_target;
153 static __thread std::ostream *m_output;
154 Level m_output_level;
155 static __thread Level m_message_level;
156
157};
158
164
173void set_verbose(bool verbose);
174
175
176inline bool vstream::shows(Level l)const
177{
178 return l >= m_output_level;
179}
180
181
183{
184public:
185 CTrace(const char *domain):
186 m_domain(domain),
187 m_fill(m_depth, ' ')
188 {
190 << m_fill << "enter " << m_domain << "\n";
191 ++m_depth;
192 };
194 {
196 << m_fill << "leave " << m_domain << "\n";
197 --m_depth;
198 }
199private:
200 const char *m_domain;
201 std::string m_fill;
202 // should be thread local, or at least protected by a mutex
203 static __thread size_t m_depth;
204};
205
206
207#ifndef ENABLE_DEBUG_MESSAGES
208#define TRACE(DOMAIN)
209#define TRACE_FUNCTION
210#define FUNCTION_NOT_TESTED
212{
213public:
214 template <class T>
215 CDebugSink& operator << (const T& MIA_PARAM_UNUSED(val))
216 {
217 return *this;
218 }
219
220 CDebugSink& operator<<(std::ostream & ( * /*f*/)(std::ostream&))
221 {
222 return *this;
223 }
224};
225
227{
228 static CDebugSink sink;
230 return sink;
231}
232
233#else
234
239inline vstream& cvdebug()
240{
242 return vstream::instance();
243}
244
245
247#define TRACE(DOMAIN) ::mia::CTrace _xxx_trace(DOMAIN)
248
250#define TRACE_FUNCTION ::mia::CTrace _xxx_trace(__PRETTY_FUNCTION__)
251
253#define FUNCTION_NOT_TESTED ::mia::cvwarn() << __PRETTY_FUNCTION__ << ":not tested\n"
254
255#endif
256
263{
265 return vstream::instance();
266}
267
268inline bool vstream::show_debug() const
269{
270 return shows(ml_debug);
271}
272
273
276{
277 return m_output_level;
278}
279
280inline void vstream::flush()
281{
282 m_output->flush();
283}
284
285// some inlines
286
292{
294 return vstream::instance();
295}
296
302{
304 return vstream::instance();
305}
306
311inline vstream& cverr()
312{
314 return vstream::instance();
315}
316
322{
324 return vstream::instance();
325}
326
331inline vstream& cvmsg()
332{
334 return vstream::instance();
335}
336
341#define cverb ::mia::vstream::instance()
342
344
345#endif /* !CVERB_HH */
std::ostream & operator<<(std::ostream &os, const CAttribute &attr)
Definition attributes.hh:89
CDebugSink & operator<<(const T &val)
Definition msgstream.hh:215
CDebugSink & operator<<(std::ostream &(*)(std::ostream &))
Definition msgstream.hh:220
CTrace(const char *domain)
Definition msgstream.hh:185
A mapper from emums to string values. - usefull for names flags.
Definition dictmap.hh:46
A output stream to enable certain levels of verbosity.
Definition msgstream.hh:56
bool show_debug() const
Definition msgstream.hh:268
static void set_output_target(std::ostream *os)
void set_verbosity(Level l)
vstream & operator<<(std::ostream &(*f)(std::ostream &))
@ ml_message
Definition msgstream.hh:67
@ ml_warning
Definition msgstream.hh:68
vstream::Level get_level() const
Definition msgstream.hh:275
static vstream & instance()
void flush()
write pending output
Definition msgstream.hh:280
bool shows(Level l) const
Definition msgstream.hh:176
std::ostream & set_stream(std::ostream &os)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition defines.hh:101
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
vstream & cverr()
send errors to this stream adapter
Definition msgstream.hh:311
EXPORT_CORE const TDictMap< vstream::Level > g_verbose_dict
Dictonary for the verbosity of the logging as used by –verbose comand line option.
vstream & cvfail()
direct output to this stream adapter to print out failtures in tests beyond BOOST_FAIL
Definition msgstream.hh:301
vstream & cvmsg()
send messages to this stream adapter
Definition msgstream.hh:331
vstream & cvwarn()
send warnings to this stream adapter
Definition msgstream.hh:321
vstream & cvinfo()
informal output that may be of interest to understand problems with a program and are of higher prior...
Definition msgstream.hh:262
void set_verbose(bool verbose)
vstream & cvfatal()
direct output to this stream adapter to print out fatalities in the code
Definition msgstream.hh:291
CDebugSink & cvdebug()
Definition msgstream.hh:226
#define VSTREAM_DOMAIN
Definition msgstream.hh:39