Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

debug.cpp

Go to the documentation of this file.
00001 #include "headers.h"
00002 
00003 /* debugging turned on via the gcc command line, do not hard code it here */
00004 #ifdef DEBUG_ON
00005 static std::ostream* out = &cout;
00006 static ofstream fileout;
00007 
00008 static Mutex debugMutex;
00009 //static bool debugMutexInitialized = false;
00010 
00011 #define MAX_DEBUG_LINE_LENGTH 1024
00012 
00016 void 
00017 debugSetFile(const char* fileName) {
00018     fileout.open(fileName);
00019     out = &fileout;
00020 }
00021 
00022 
00026 void 
00027 debugSetOutputStream(std::ostream* theOutput) {
00028     out = theOutput;
00029 }
00030 
00031 
00038 void 
00039 debug(char *file, int line, int enabled, char* fmt, ...) {
00040         va_list valist;
00041     char tmpbuf[MAX_DEBUG_LINE_LENGTH];
00042 
00043     if(enabled) {
00044         debugMutex.lock();
00045         *out << file << ", line " << line << ": ";
00046         va_start(valist, fmt);
00047         vsprintf(tmpbuf, fmt, valist);
00048         va_end(valist);
00049         *out << tmpbuf << "\n" << std::flush;
00050         debugMutex.unlock();
00051     }
00052 } // fn debug 
00053 
00054 #else
00055 
00056 void 
00057 debugSetFile(const char* fileName) {}
00058 
00059 void 
00060 debug(char *file, int line, int enabled, char* fmt, ...) {}
00061 
00062 #endif
00063 
00064 void 
00065 MEMCHECK(void* checkPtr) {
00066         if (checkPtr == NULL) {
00067                 printf("MEMCHECK: error - out of memory\n");
00068                 exit(1);
00069         }
00070 }

Generated at Thu Jul 11 13:31:50 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001