GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


A Paste by Anonymous
#ifndef __UNWIND_H__
#define __UNWIND_H__

///////////////////////////////////////////////////////////////////////

#include <iostream>

///////////////////////////////////////////////////////////////////////

class ErrorStr {    
public:
    char    stack[500];
    char    line[10];
    char    file[250];

    ErrorStr( const char* function, const char* infile, int linenum ) {
        sprintf( stack, "->%s", function );
        sprintf( line, "%u", linenum );
        sprintf( file, "%s", infile );
        
    }
    ErrorStr& UnWind( const char* curFunction ) {
        char temp[500];
        sprintf( temp, "->%s", curFunction ); 
        strcat( temp, stack );
        strcpy( stack, temp );
        return *this;
    }
};

///////////////////////////////////////////////////////////////////////


#ifdef _DEBUG

#define FUNCGUARD(name)  {static const char __CALLNAME__[]=#name; try{
#define MASSERT(expr)     if(!(expr)){throw (int)__LINE__;}
// For checking function return values
#define FUNCASSERT(expr) if(!(expr)){throw (int)__LINE__;}
// For Checking DX functions
#define DXASSERT(expr)     if(FAILED((expr))){throw (int)__LINE__;}
#define ENDGUARD         }catch(ErrorStr& err){ throw err.UnWind(__CALLNAME__); }catch(int err){ throw ErrorStr(__CALLNAME__, __FILE__, err);}}

#else

// expand to nothing in release mode
#define FUNCGUARD(name) 
#define MASSERT(expr)
// keeps the function in release mode
#define FUNCASSERT(expr) expr
#define DXASSERT(expr)     expr
#define ENDGUARD

#endif

///////////////////////////////////////////////////////////////////////

#endif