diff --git a/include/log.h b/include/log.h index 58c4243..f8ae353 100644 --- a/include/log.h +++ b/include/log.h @@ -6,42 +6,42 @@ class LogType { public: - virtual void log(std::stringstream& ss) const = 0; + virtual void log(std::stringstream &ss) const = 0; }; class DefaultLog : public LogType { public: - void log(std::stringstream& ss) const override + void log(std::stringstream &ss) const override { std::cout << ss.str() << "\n"; }; }; -class ErrorLog : public LogType +class ErrorLog: public LogType { public: - void log(std::stringstream& ss) const override + void log(std::stringstream &ss) const override { -#ifdef PLATFORM_WIN32 + #ifdef PLATFORM_WIN32 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12); std::cout << ss.str() << "\n"; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15); -#else + #else std::cout << "Error: " << ss << "\n"; -#endif + #endif }; }; -class LogToAFile : public LogType +class LogToAFile: public LogType { std::string name; public: - LogToAFile(std::string name) :name(name) + LogToAFile(std::string name):name(name) {} - void log(std::stringstream& ss) const override + void log(std::stringstream &ss) const override { std::ofstream f(name); f << ss.str() << "\n"; @@ -51,20 +51,20 @@ public: }; -inline void llog(const LogType& l, std::stringstream& ss) +inline void llog(const LogType &l, std::stringstream &ss) { l.log(ss); } template -inline void llog(const LogType& l, std::stringstream& ss, const T& t, const T2 &...t2) +inline void llog(const LogType &l, std::stringstream &ss, const T &t, const T2 &...t2) { ss << t << " "; llog(l, ss, t2...); } template -inline void llog(const LogType& l, const T& t, const T2 &...t2) +inline void llog(const LogType &l, const T &t, const T2 &...t2) { std::stringstream ss; ss << t << " "; diff --git a/include/tools.h b/include/tools.h index 117519a..7167618 100644 --- a/include/tools.h +++ b/include/tools.h @@ -1,9 +1,7 @@ #ifndef TOOLS_H_INCLUDE #define TOOLS_H_INCLUDE -#define INTERNAL_BUILD 1 //when internal build is true and an assertion is hit, you have the option to debug or ignore -//when internal build if false and an asertion is hit, the error is reported and the program -//closes +#define INTERNAL_BUILD 1 #include @@ -17,166 +15,154 @@ #ifdef PLATFORM_WIN32 -#include - -inline void assertFuncProduction( - const char* expression, - const char* file_name, - unsigned const line_number, - const char* comment = "---") -{ - - char c[1024] = {}; - - sprintf(c, - "Assertion failed\n\n" - "File:\n" - "%s\n\n" - "Line:\n" - "%u\n\n" - "Expresion:\n" - "%s\n\n" - "Comment:\n" - "%s" - "\n\nPlease report this error to the developer.", - file_name, - line_number, - expression, - comment - ); - - int const action = MessageBox(0, c, "Platform Layer", MB_TASKMODAL - | MB_ICONHAND | MB_OK | MB_SETFOREGROUND); - - switch (action) + #include + + inline void assertFuncProduction( + const char *expression, + const char *file_name, + unsigned const line_number, + const char *comment = "---") { - case IDOK: // Abort the program: + + char c[1024] = {}; + + sprintf(c, + "Assertion failed\n\n" + "File:\n" + "%s\n\n" + "Line:\n" + "%u\n\n" + "Expresion:\n" + "%s\n\n" + "Comment:\n" + "%s" + "\n\nPlease report this error to the developer.", + file_name, + line_number, + expression, + comment + ); + + int const action = MessageBox(0, c, "Platform Layer", MB_TASKMODAL + | MB_ICONHAND | MB_OK | MB_SETFOREGROUND); + + switch (action) + { + case IDOK: + { + raise(SIGABRT); + _exit(3); + } + default: + { + _exit(3); + } + } + + } + + inline void assertFuncInternal( + const char *expression, + const char *file_name, + unsigned const line_number, + const char *comment = "---") { - raise(SIGABRT); - - // We won't usually get here, but it's possible that a user-registered - // abort handler returns, so exit the program immediately. Note that - // even though we are "aborting," we do not call abort() because we do - // not want to invoke Watson (the user has already had an opportunity - // to debug the error and chose not to). - _exit(3); + + char c[1024] = {}; + + sprintf(c, + "Assertion failed\n\n" + "File:\n" + "%s\n\n" + "Line:\n" + "%u\n\n" + "Expresion:\n" + "%s\n\n" + "Comment:\n" + "%s" + "\n\nPress retry to debug.", + file_name, + line_number, + expression, + comment + ); + + int const action = MessageBox(0, c, "Platform Layer", MB_TASKMODAL + | MB_ICONHAND | MB_ABORTRETRYIGNORE | MB_SETFOREGROUND); + + switch (action) + { + case IDABORT: + { + raise(SIGABRT); + _exit(3); + } + case IDRETRY: + { + __debugbreak(); + return; + } + case IDIGNORE: + { + return; + } + default: + { + abort(); + } + } + } - default: - { - _exit(3); - } - } - -} - -inline void assertFuncInternal( - const char* expression, - const char* file_name, - unsigned const line_number, - const char* comment = "---") -{ - - char c[1024] = {}; - - sprintf(c, - "Assertion failed\n\n" - "File:\n" - "%s\n\n" - "Line:\n" - "%u\n\n" - "Expresion:\n" - "%s\n\n" - "Comment:\n" - "%s" - "\n\nPress retry to debug.", - file_name, - line_number, - expression, - comment - ); - - int const action = MessageBox(0, c, "Platform Layer", MB_TASKMODAL - | MB_ICONHAND | MB_ABORTRETRYIGNORE | MB_SETFOREGROUND); - - switch (action) - { - case IDABORT: // Abort the program: - { - raise(SIGABRT); - - // We won't usually get here, but it's possible that a user-registered - // abort handler returns, so exit the program immediately. Note that - // even though we are "aborting," we do not call abort() because we do - // not want to invoke Watson (the user has already had an opportunity - // to debug the error and chose not to). - _exit(3); - } - case IDRETRY: // Break into the debugger then return control to caller - { - __debugbreak(); - return; - } - case IDIGNORE: // Return control to caller - { - return; - } - default: // This should not happen; treat as fatal error: - { - abort(); - } - } - -} - -#if INTERNAL_BUILD == 1 - -#define permaAssert(expression) (void)( \ + + #if INTERNAL_BUILD == 1 + + #define permaAssert(expression) (void)( \ (!!(expression)) || \ (assertFuncInternal(#expression, __FILE__, (unsigned)(__LINE__)), 0) \ ) - -#define permaAssertComment(expression, comment) (void)( \ + + #define permaAssertComment(expression, comment) (void)( \ (!!(expression)) || \ (assertFuncInternal(#expression, __FILE__, (unsigned)(__LINE__), comment), 1) \ ) - -#else - -#define permaAssert(expression) (void)( \ + + #else + + #define permaAssert(expression) (void)( \ (!!(expression)) || \ (assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0) \ ) - -#define permaAssertComment(expression, comment) (void)( \ + + #define permaAssertComment(expression, comment) (void)( \ (!!(expression)) || \ (assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__), comment), 1) \ -) + ) + + #endif + + -#endif +#else + + inline void assertFuncProduction( + const char *expression, + const char *file_name, + unsigned const line_number, + const char *comment = "---") + { + + raise(SIGABRT); + + } - -#else //linux or others - -inline void assertFuncProduction( - const char* expression, - const char* file_name, - unsigned const line_number, - const char* comment = "---") -{ - - raise(SIGABRT); - -} - - -#define permaAssert(expression) (void)( \ + #define permaAssert(expression) (void)( \ (!!(expression)) || \ (assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0) \ ) -#define permaAssertComment(expression, comment) (void)( \ + #define permaAssertComment(expression, comment) (void)( \ (!!(expression)) || \ (assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0, comment) \ )