Actually it really isnt that big of a deal, but i was just wondering if anyone happen to see a problem or insecurity with my assert setup. I don't like the regular assert.
Well thanks, and maybe someone else will be able to use this as well.Code://required for MessageBoxA() functions #include <windows.h> //required to use std::stringstream #include <sstream> //Check if program is debug build #ifndef NDEBUG //Assign the asert macro #ifdef assert #undef assert #endif #if defined(BOX) #define assert Wassert #elif defined(CONSOLE) #define assert Cassert #else #define assert assert #endif #if defined(BOX) #define createBox \ struct create \ {\ create(const int& line, const char* file, const char* message)\ {\ std::stringstream ss;\ const char* title = "Assertion Error!!!";\ ss << "!!!Assertion Error!!!\nFile: " << file << "\nLine: " << line << "\n\n" << message;\ MessageBoxA(NULL,ss.str().c_str(),title, 0);\ };\ } myboxmaker = create #endif // #ifdef CONSOLE #define Cassert \ if ( false ) {} else struct LocalAssert { \ int mLine; \ LocalAssert(int line=__LINE__) : mLine(line) {} \ LocalAssert(bool isOK, char const *message="", bool quit = false) { \ if ( !isOK ) { \ (void)printf("ERROR!! Assert failed on " \ "line %d in file\n-->%s\n%s\n", \ LocalAssert().mLine, __FILE__, message); \ if (quit) \ abort();\ else\ __asm { int 3 } \ } \ }\ }myAsserter = LocalAssert #endif //checks if Wassert is to be used #ifdef BOX #define Wassert \ if ( false ) {} else struct LocalAssert { \ int mLine; \ LocalAssert(int line=__LINE__) : mLine(line) {} \ LocalAssert(bool isOK, char const *message="", bool quit = false) { \ if ( !isOK ) { \ createBox(LocalAssert().mLine, __FILE__, message);\ if (quit) \ abort();\ else\ __asm { int 3 } \ } \ }\ }myAsserter = LocalAssert #endif #ifndef BOX #ifndef CONSOLE #define assert \ if ( true ) {} else struct NoAssert { \ NoAssert(bool isOK, char const *message="", bool quit = false) {} \ } myAsserter = NoAssert #endif #endif #endif



LinkBack URL
About LinkBacks




CornedBee