# debug.h

    00001 /*
    00002     Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
    00003
    00004     This program is free software; you can redistribute it and/or modify
    00005     it under the terms of the GNU General Public License as published by
    00006     the Free Software Foundation; either version 2 of the License, or
    00007     (at your option) any later version.
    00008
    00009     This program is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00012
    00013     See the GNU General Public License in the COPYING file at the
    00014     root directory of this project for more details.
    00015 */
    00016
    00017 #include <iostream>             // debugging only
    00018 #include <iomanip>
    00019 #include "common.h"
    00020 #include "log.h"
    00021
    00022 #ifndef __BARRY_DEBUG_H__       // only protect the non-macro portion, in order
    00023 #define __BARRY_DEBUG_H__       // to allow re-inclusion of debug.h with
    00024                                 // different __DEBUG_MODE__ settings
    00025
    00026 namespace Barry {
    00027 extern bool __data_dump_mode__;
    00028 extern std::ostream *LogStream;
    00029 }
    00030
    00031 #endif // __BARRY_DEBUG_H__
    00032
    00033 // data dump output - controlled by command line -v switch
    00034 #define ddout(x)        if(::Barry::__data_dump_mode__) { ::Barry::LogLock lock; (*::Barry::LogStream) << x << std::endl; }
    00035
    00036 #ifdef __DEBUG_MODE__
    00037         // debugging on
    00038         #undef dout
    00039         #undef eout
    00040
    00041         // low level debug output
    00042         #define dout(x)         if(::Barry::__data_dump_mode__) { ::Barry::LogLock lock; (*::Barry::LogStream) << x << std::endl; }
    00043 //      #define dout(x)
    00044
    00045         // exception output
    00046         #define eout(x)         { ::Barry::LogLock lock; (*::Barry::LogStream) << x << std::endl; }
    00047
    00048         // easy exception output
    00049         #define eeout(c, r)     { ::Barry::LogLock lock; (*::Barry::LogStream) << "Sent packet:\n" << c << "\n" << "Response packet:\n" << r << "\n"; }
    00050
    00051         // handle assert()
    00052         #undef NDEBUG
    00053 #else
    00054
    00055         // debugging off
    00056         #undef dout
    00057         #undef eout
    00058
    00059         #define dout(x)
    00060         #define eout(x)         { ::Barry::LogLock lock; (*::Barry::LogStream) << x << std::endl; }
    00061         #define eeout(c, r)     { ::Barry::LogLock lock; (*::Barry::LogStream) << "Sent packet:\n" << c << "\n" << "Response packet:\n" << r << "\n"; }
    00062
    00063         // handle assert() as well
    00064         #define NDEBUG
    00065 #endif
    00066
    00067 #include <assert.h>
    00068