Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
Debug and Logging stream

The Debug class can act as an output stream for debugging and logging purposes. This is used e.g. for displaying custom messages in a failed DASSERT_MSG statement or for logging data.

There are a number of reasons why this module implements this in a stream-like fashion instead of the 'usual' printf method:

Syntactically the Debug class acts almost like a ostream class:

int n=1;
float f=4;
DLOG( "This is a static string and some other stuff: "
<< n << " " << f << "\n" );
#define DLOG(what)

New types can be added easily, e.g.:

struct Point2D { int x,y; };
inline Debug& operator<<(Debug& debug, const Point2D &pt)
{
debug << "(" << pt.x << ";" << pt.y << ")";
return debug;
}
void test(const Point2D &val)
{
DLOG( "Current point value is " << val << "\n" );
DASSERT_MSG( val.x>=0 && val.y>=0, val << " is invalid");
}
Debug module main class (singleton).
Definition debug_debug.h:45
#define DASSERT_MSG(expr, msg)
Debug & operator<<(Debug &dbg, const DebugStackwalk::Signature &sig)
Dumps a complete signature with symbols.
int test
Definition test6.cpp:32

Please note that all these operators should not be cluttered with any #ifdef _DEBUG or similar conditional compile statements. It is not necessary to remove these operators from the code in release builds (just don't forget to add 'inline' before the operator though).

In addition there are a number of helper classes declared inside of Debug: