msgstream.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CVERB_HH
#define CVERB_HH 1
//#pragma interface
#include <vector>
#include <cassert>
#include <ostream>
#include <boost/call_traits.hpp>
#include <boost/ref.hpp>
#include <miaconfig.h>
#include <mia/core/defines.hh>
#include <mia/core/dictmap.hh>
#include <mia/core/svector.hh>
NS_MIA_BEGIN
#ifndef VSTREAM_DOMAIN
#define VSTREAM_DOMAIN "**"
#endif
class EXPORT_CORE vstream
{
public:
enum Level {
ml_trace,
ml_debug,
ml_info,
ml_message,
ml_warning,
ml_fail,
ml_error,
ml_fatal,
ml_undefined
};
static vstream& instance();
void set_verbosity(Level l);
vstream::Level get_level() const;
std::ostream& set_stream(std::ostream& os);
void flush();
bool shows(Level l)const;
bool show_debug() const;
vstream& operator << (Level const l);
template <class T>
vstream& operator << (const T& text)
{
if (m_message_level >= m_output_level)
*m_output << text;
return *this;
}
vstream& operator<<(std::ostream & (*f)(std::ostream&));
static void set_output_target(std::ostream *os);
operator std::ostream& ()
{
return *m_output;
}
private:
vstream(std::ostream& output, Level l);
static std::ostream *m_output_target;
static __thread std::ostream *m_output;
Level m_output_level;
static __thread Level m_message_level;
};
extern EXPORT_CORE const TDictMap<vstream::Level> g_verbose_dict;
void set_verbose(bool verbose);
inline bool vstream::shows(Level l)const
{
return l >= m_output_level;
}
class EXPORT_CORE CTrace
{
public:
CTrace(const char *domain):
m_domain(domain),
m_fill(m_depth, ' ')
{
vstream::instance() << vstream::ml_trace
<< m_fill << "enter " << m_domain << "\n";
++m_depth;
};
~CTrace()
{
vstream::instance() << vstream::ml_trace
<< m_fill << "leave " << m_domain << "\n";
--m_depth;
}
private:
const char *m_domain;
std::string m_fill;
// should be thread local, or at least protected by a mutex
static __thread size_t m_depth;
};
#ifndef ENABLE_DEBUG_MESSAGES
#define TRACE(DOMAIN)
#define TRACE_FUNCTION
#define FUNCTION_NOT_TESTED
class CDebugSink
{
public:
template <class T>
CDebugSink& operator << (const T& MIA_PARAM_UNUSED(val))
{
return *this;
}
CDebugSink& operator<<(std::ostream & ( * /*f*/)(std::ostream&))
{
return *this;
}
};
inline CDebugSink& cvdebug()
{
static CDebugSink sink;
vstream::instance() << vstream::ml_debug;
return sink;
}
#else
inline vstream& cvdebug()
{
vstream::instance() << vstream::ml_debug << VSTREAM_DOMAIN << ":";
return vstream::instance();
}
#define TRACE(DOMAIN) ::mia::CTrace _xxx_trace(DOMAIN)
#define TRACE_FUNCTION ::mia::CTrace _xxx_trace(__PRETTY_FUNCTION__)
#define FUNCTION_NOT_TESTED ::mia::cvwarn() << __PRETTY_FUNCTION__ << ":not tested\n"
#endif
inline vstream& cvinfo()
{
vstream::instance() << vstream::ml_info << VSTREAM_DOMAIN << ":";
return vstream::instance();
}
inline bool vstream::show_debug() const
{
return shows(ml_debug);
}
inline vstream::Level vstream::get_level() const
{
return m_output_level;
}
inline void vstream::flush()
{
m_output->flush();
}
// some inlines
inline vstream& cvfatal()
{
vstream::instance() << vstream::ml_fatal << VSTREAM_DOMAIN << ":";
return vstream::instance();
}
inline vstream& cvfail()
{
vstream::instance() << vstream::ml_fail << VSTREAM_DOMAIN << ":";
return vstream::instance();
}
inline vstream& cverr()
{
vstream::instance() << vstream::ml_error << VSTREAM_DOMAIN << ":";
return vstream::instance();
}
inline vstream& cvwarn()
{
vstream::instance() << vstream::ml_warning << VSTREAM_DOMAIN << ":";
return vstream::instance();
}
inline vstream& cvmsg()
{
vstream::instance() << vstream::ml_message << VSTREAM_DOMAIN << ":";
return vstream::instance();
}
#define cverb ::mia::vstream::instance()
NS_MIA_END
#endif /* !CVERB_HH */
operator<<
std::ostream & operator<<(std::ostream &os, const CAttribute &attr)
Definition attributes.hh:89
CDebugSink
Definition msgstream.hh:212
CDebugSink::operator<<
CDebugSink & operator<<(const T &val)
Definition msgstream.hh:215
CDebugSink::operator<<
CDebugSink & operator<<(std::ostream &(*)(std::ostream &))
Definition msgstream.hh:220
CTrace::CTrace
CTrace(const char *domain)
Definition msgstream.hh:185
CTrace::~CTrace
~CTrace()
Definition msgstream.hh:193
TDictMap
A mapper from emums to string values. - usefull for names flags.
Definition dictmap.hh:46
vstream
A output stream to enable certain levels of verbosity.
Definition msgstream.hh:56
vstream::show_debug
bool show_debug() const
Definition msgstream.hh:268
vstream::set_output_target
static void set_output_target(std::ostream *os)
vstream::set_verbosity
void set_verbosity(Level l)
vstream::operator<<
vstream & operator<<(std::ostream &(*f)(std::ostream &))
vstream::Level
Level
Definition msgstream.hh:63
vstream::ml_message
@ ml_message
Definition msgstream.hh:67
vstream::ml_error
@ ml_error
Definition msgstream.hh:70
vstream::ml_trace
@ ml_trace
Definition msgstream.hh:64
vstream::ml_warning
@ ml_warning
Definition msgstream.hh:68
vstream::ml_debug
@ ml_debug
Definition msgstream.hh:65
vstream::ml_undefined
@ ml_undefined
Definition msgstream.hh:72
vstream::ml_info
@ ml_info
Definition msgstream.hh:66
vstream::ml_fatal
@ ml_fatal
Definition msgstream.hh:71
vstream::ml_fail
@ ml_fail
Definition msgstream.hh:69
vstream::get_level
vstream::Level get_level() const
Definition msgstream.hh:275
vstream::instance
static vstream & instance()
vstream::flush
void flush()
write pending output
Definition msgstream.hh:280
vstream::shows
bool shows(Level l) const
Definition msgstream.hh:176
vstream::set_stream
std::ostream & set_stream(std::ostream &os)
CCmdOptionFlags::output
@ output
Definition cmdoptionflags.hh:32
defines.hh
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
EXPORT_CORE
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition defines.hh:101
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
dictmap.hh
cverr
vstream & cverr()
send errors to this stream adapter
Definition msgstream.hh:311
g_verbose_dict
EXPORT_CORE const TDictMap< vstream::Level > g_verbose_dict
Dictonary for the verbosity of the logging as used by –verbose comand line option.
cvfail
vstream & cvfail()
direct output to this stream adapter to print out failtures in tests beyond BOOST_FAIL
Definition msgstream.hh:301
cvmsg
vstream & cvmsg()
send messages to this stream adapter
Definition msgstream.hh:331
cvwarn
vstream & cvwarn()
send warnings to this stream adapter
Definition msgstream.hh:321
cvinfo
vstream & cvinfo()
informal output that may be of interest to understand problems with a program and are of higher prior...
Definition msgstream.hh:262
set_verbose
void set_verbose(bool verbose)
cvfatal
vstream & cvfatal()
direct output to this stream adapter to print out fatalities in the code
Definition msgstream.hh:291
cvdebug
CDebugSink & cvdebug()
Definition msgstream.hh:226
VSTREAM_DOMAIN
#define VSTREAM_DOMAIN
Definition msgstream.hh:39
svector.hh