00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
#ifndef UFO_DEBUG_HPP
00029 
#define UFO_DEBUG_HPP
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
#ifndef UFO_ASSERT
00041 
#ifdef UFO_CHECK_ASSERT
00042 
#define UFO_ASSERT(x)  ((x) ? (void)0 : uWarning() << "ASSERT: " << #x << " in " << UFO_LINE_INFO;
00043 
#else
00044 
#define UFO_ASSERT(x)
00045 
#endif // UFO_CHECK_ASSERT
00046 
#endif // UFO_ASSERT
00047 
00048 
00049 
00050 
#define UFO_LINE_INFO "[" << __FILE__ << ":" << __LINE__ << "] "
00051 
00052 
00053 
#include <iostream>
00054 
#include <vector>
00055 
00056 
#include "usharedptr.hpp"
00057 
00058 
namespace ufo {
00059 
00066 class UDebugStream {
00067 
public: 
00068     
00069     
typedef std::ostream ostream_type;
00070     
USharedPtr<ostream_type> m_stream;
00071 
public:
00072     
UDebugStream(std::streambuf * buf) : m_stream(
new ostream_type(buf)) {}
00073 
00074 
#ifdef UFO_DEBUG
00075 
    UDebugStream &
00076     operator<<(ostream_type & (*pf)(ostream_type &)) {
00077             *m_stream << (pf);
00078         
return *
this;
00079     }
00080 
#else
00081 
    UDebugStream &
00082     operator<<(ostream_type & (* )(ostream_type &)) {
00083         
return *
this;
00084     }
00085 
#endif
00086 
00087     
template<
typename T>
00088     
UDebugStream &
00089     operator<<(
const T & t) {
00090 
#ifdef UFO_DEBUG
00091 
            *m_stream << (t);
00092 
#endif
00093 
        return *
this;
00094     }
00095 
00102     UFO_EXPORT 
UDebugStream &
00103     
printf(
const char *format, ...);
00104 };
00105 
00110 class UPrintStream {
00111 
public: 
00112     
typedef std::ostream ostream_type;
00113     
USharedPtr<ostream_type> m_stream;
00114 
public:
00115     
UPrintStream(std::streambuf * buf) : m_stream(
new ostream_type(buf)) {}
00116 
00117     
UPrintStream &
00118     operator<<(ostream_type & (*pf)(ostream_type &)) {
00119         *m_stream << (pf);
00120         
return *
this;
00121     }
00122 
00123     
template<
typename T>
00124     
UPrintStream &
00125     operator<<(
const T & t) {
00126         *m_stream << (t);
00127         
return *
this;
00128     }
00129 
00130     UFO_EXPORT 
UPrintStream &
00131     printf(
const char *format, ...);
00132 };
00133 
00134 
00135 
00136 
00137 
00139 
extern UFO_EXPORT 
UDebugStream uDebug();
00140 
00141 
00142 
00143 
00144 
extern UFO_EXPORT 
UPrintStream uError();
00145 
extern UFO_EXPORT 
UPrintStream uWarning();
00146 
extern UFO_EXPORT 
UPrintStream uFatal();
00147 
00148 
00149 
00150 
00151 
00152 
extern UFO_EXPORT std::string uBacktrace(
int levels);
00153 
extern UFO_EXPORT std::string uBacktrace();
00154 
00155 
00156 
00157 
00158 
00162 
extern UFO_EXPORT 
void initUFODebug(std::streambuf * debug, std::streambuf * warning,
00163     std::streambuf * error, std::streambuf * fatal);
00164 
00165 
00166 } 
00167 
00168 
00169 
#endif // UFO_DEBUG_HPP