gdcmTrace.h
Go to the documentation of this file.
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef GDCMTRACE_H
#define GDCMTRACE_H
#include "gdcmTypes.h"
#include "gdcmSystem.h"
#include <iosfwd>
#include <cassert>
namespace gdcm
{
class GDCM_EXPORT Trace
{
public :
Trace();
~Trace();
static void SetStream(std::ostream &os);
static std::ostream &GetStream();
static void SetDebugStream(std::ostream &os);
static std::ostream &GetDebugStream();
static void SetWarningStream(std::ostream &os);
static std::ostream &GetWarningStream();
static void SetErrorStream(std::ostream &os);
static std::ostream &GetErrorStream();
static void SetStreamToFile( const char *filename );
static void SetDebug(bool debug);
static void DebugOn();
static void DebugOff();
static bool GetDebugFlag();
static void SetWarning(bool debug);
static void WarningOn();
static void WarningOff();
static bool GetWarningFlag();
static void SetError(bool debug);
static void ErrorOn();
static void ErrorOff();
static bool GetErrorFlag();
protected:
private:
};
// Here we define function this is the only way to be able to pass
// stuff with indirection like:
// gdcmDebug( "my message:" << i << '\t' );
// You cannot use function unless you use vnsprintf ...
// __FUNCTION is not always defined by preprocessor
// In c++ we should use __PRETTY_FUNCTION__ instead...
#ifdef GDCM_CXX_HAS_FUNCTION
// Handle particular case for GNU C++ which also defines __PRETTY_FUNCTION__
// which is a lot nice in C++
#ifdef __BORLANDC__
# define __FUNCTION__ __FUNC__
#endif
#ifdef __GNUC__
# define GDCM_FUNCTION __PRETTY_FUNCTION__
#else
# define GDCM_FUNCTION __FUNCTION__
#endif //__GNUC__
#else
# define GDCM_FUNCTION "<unknown>"
#endif //GDCM_CXX_HAS_FUNCTION
#if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
#define gdcmDebugMacro(msg) GDCM_NOOP_STATEMENT
#else
#define gdcmDebugMacro(msg) \
{ \
if( gdcm::Trace::GetDebugFlag() ) \
{ \
std::ostringstream osmacro; \
osmacro << "Debug: In " __FILE__ ", line " << __LINE__ \
<< ", function " << GDCM_FUNCTION << '\n' \
<< "Last system error was: " \
<< gdcm::System::GetLastSystemError() << '\n' << msg; \
std::ostream &_os = gdcm::Trace::GetDebugStream(); \
_os << osmacro.str() << "\n\n" << std::endl; \
} \
} \
GDCM_NOOP_STATEMENT
#endif //NDEBUG
#if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
#define gdcmWarningMacro(msg) GDCM_NOOP_STATEMENT
#else
#define gdcmWarningMacro(msg) \
{ \
if( gdcm::Trace::GetWarningFlag() ) \
{ \
std::ostringstream osmacro; \
osmacro << "Warning: In " __FILE__ ", line " << __LINE__ \
<< ", function " << GDCM_FUNCTION << "\n" \
<< msg << "\n\n"; \
std::ostream &_os = gdcm::Trace::GetWarningStream(); \
_os << osmacro.str() << std::endl; \
} \
} \
GDCM_NOOP_STATEMENT
#endif //NDEBUG
#if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
#define gdcmErrorMacro(msg) GDCM_NOOP_STATEMENT
#else
#define gdcmErrorMacro(msg) \
{ \
if( gdcm::Trace::GetErrorFlag() ) \
{ \
std::ostringstream osmacro; \
osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
<< ", function " << GDCM_FUNCTION << '\n' \
<< msg << "\n\n"; \
std::ostream &_os = gdcm::Trace::GetErrorStream(); \
_os << osmacro.str() << std::endl; \
} \
} \
GDCM_NOOP_STATEMENT
#endif //NDEBUG
#if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
#define gdcmAssertMacro(arg) GDCM_NOOP_STATEMENT
#else
#define gdcmAssertMacro(arg) \
{ \
if( !(arg) ) \
{ \
std::ostringstream osmacro; \
osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
<< ", function " << GDCM_FUNCTION \
<< "\n\n"; \
std::ostream &_os = gdcm::Trace::GetErrorStream(); \
_os << osmacro.str() << std::endl; \
assert ( arg ); \
} \
} \
GDCM_NOOP_STATEMENT
#endif //NDEBUG
#if defined(NDEBUG)
// User asked for release compilation, but still need to report
// if grave issue.
#define gdcmAssertAlwaysMacro(arg) \
{ \
if( !(arg) ) \
{ \
std::ostringstream osmacro; \
osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
<< ", function " << GDCM_FUNCTION \
<< "\n\n"; \
throw osmacro.str(); \
} \
} \
GDCM_NOOP_STATEMENT
#else
// Simply reproduce gdcmAssertMacro behavior:
#define gdcmAssertAlwaysMacro(arg) gdcmAssertMacro(arg)
#endif //NDEBUG
} // end namespace gdcm
//-----------------------------------------------------------------------------
#endif //GDCMTRACE_H
gdcm::Trace::SetError
static void SetError(bool debug)
Turn error messages on (default: true).
gdcm::Trace::ErrorOn
static void ErrorOn()
gdcm::Trace::WarningOff
static void WarningOff()
gdcm::Trace::SetDebug
static void SetDebug(bool debug)
Turn debug messages on (default: false).
gdcm::Trace::SetDebugStream
static void SetDebugStream(std::ostream &os)
Explicitly set the stream which receive Debug messages:
gdcm::Trace::GetErrorStream
static std::ostream & GetErrorStream()
gdcm::Trace::WarningOn
static void WarningOn()
gdcm::Trace::SetStreamToFile
static void SetStreamToFile(const char *filename)
gdcm::Trace::SetWarningStream
static void SetWarningStream(std::ostream &os)
Explicitly set the stream which receive Warning messages:
gdcm::Trace::SetWarning
static void SetWarning(bool debug)
Turn warning messages on (default: true).
gdcm::Trace::ErrorOff
static void ErrorOff()
gdcm::Trace::GetDebugStream
static std::ostream & GetDebugStream()
gdcm::Trace::GetStream
static std::ostream & GetStream()
gdcm::Trace::DebugOn
static void DebugOn()
gdcm::Trace::~Trace
~Trace()
gdcm::Trace::SetStream
static void SetStream(std::ostream &os)
gdcm::Trace::GetDebugFlag
static bool GetDebugFlag()
gdcm::Trace::SetErrorStream
static void SetErrorStream(std::ostream &os)
Explicitly set the stream which receive Error messages:
gdcm::Trace::GetWarningFlag
static bool GetWarningFlag()
gdcm::Trace::Trace
Trace()
gdcm::Trace::DebugOff
static void DebugOff()
gdcm::Trace::GetWarningStream
static std::ostream & GetWarningStream()
gdcm::Trace::GetErrorFlag
static bool GetErrorFlag()
gdcmSystem.h
gdcmTypes.h
GDCM_EXPORT
#define GDCM_EXPORT
Definition gdcmWin32.h:34
gdcm
Definition gdcmASN1.h:21