/* Copyright (C) 1997, 1998, 1999, 2000 by Alex Pfaffe (Digital Dawn Graphics Inc) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef _ddgError_Class_ #define _ddgError_Class_ #include "util/ddgstr.h" typedef unsigned int ddgErrorCode; class WEXP ddgError { static ddgError *gError; ddgErrorCode _error; ddgStr _code; int _line; ddgStr _file; ddgStr _msg; static void (*_errorHandler)(ddgError*); public: ddgError(void); ~ddgError(void); enum codes { Success = 0, Failure = 1, Memory = 2, InitializationError = 3, FileAccess = 10, FileRead = 11, FileWrite = 12, FileContent = 13, CommandArgUnknownOption = 20, CommandArgMissingParameter = 21, Render = 98, Unknown = 998, Warning = 999 }; static void exitHandler( void ); static bool set(ddgErrorCode code, const char *msg, const char* filename, int line, const char *codeMsg = NULL); static bool isError(void); #ifdef DDG static int report(void); #define ddgErrorSet(errorNo,errorStr) ddgError::set(ddgError##::errorNo,(errorStr),__FILE__,__LINE__, #errorNo) #ifdef DDGSTREAM static ostrstream &errorStream(void); #define ddgErrorSetStr(errorNo, errorStr) { \ ddgError::errorStream() << errorStr; \ ddgError::set(ddgError##::errorNo,NULL,__FILE__,__LINE__, #errorNo); } #endif #else // No DDGSTREAM static int report(void) {} #define ddgErrorSet(errorNo, errorStr) #define ddgErrorSetStr(errorNo, errorStr) #endif // DDGSTREAM #if defined(_DEBUG) && defined(DDG) #define ddgAssertw(a) if (!(a)) {ddgErrorSet(Warning,"Assert failed!\n" #a);ddgError::report(); } #define ddgAssertws(a,s) if (!(a)) {ddgErrorSet(Warning,"Assert failed!\n" s "\n" #a);ddgError::report();} #define ddgAssert(a) if (!(a)) {ddgErrorSet(Failure,"Assert failed!\n" #a);ddgError::exitHandler();} #define ddgAsserts(a,s) if (!(a)) {ddgErrorSet(Failure,"Assert failed!\n" s "\n" #a);ddgError::exitHandler();} #else #define ddgAssertw(a) #define ddgAssert(a) #define ddgAsserts(a,s) #define ddgAssertws(a,s) #endif static void memory( const char * file, unsigned int line, long size, long count, const char *type); #ifdef DDG #define ddgMemorySet(a,b) ddgError::memory(__FILE__,__LINE__, sizeof(a),b,#a) #define ddgMemoryFree(a,b) ddgError::memory(__FILE__,__LINE__, sizeof(a),-1*(b),#a) #else #define ddgMemorySet(a,b) #define ddgMemoryFree(a,b) #endif static bool reportMemory( ddgStr *filename = NULL, char *s = NULL ); static unsigned long reportTotalInUse(void); static unsigned long reportMaxInUse(void); #define ddgSuccess false #define ddgFailure true static void errorHandler( void (*s)(ddgError *e)); }; class WEXP ddgLogFile { static ddgLogFile *gLogFile; char * _logMessage; bool _enabled; public: ddgLogFile(void); ~ddgLogFile(); static bool log(const char *msg); static bool logClose(void); static void enabled(bool active); static bool enabled(void); static char *logMessage(void); #ifdef DDGSTREAM static ostrstream &logStream(void); #define ddgLog(msg) { \ if (ddgLogFile::enabled()) \ { \ ddgLogFile::logStream() << msg; \ ddgLogFile::log(ddgLogFile::logMessage());} \ } #else // !DDGSTREAM #define ddgLog(msg) #endif // DDGSTREAM }; #endif