Small fix
This commit is contained in:
parent
9339e572a0
commit
9019f9c299
|
@ -6,42 +6,42 @@
|
||||||
class LogType
|
class LogType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void log(std::stringstream& ss) const = 0;
|
virtual void log(std::stringstream &ss) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class DefaultLog : public LogType
|
class DefaultLog : public LogType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void log(std::stringstream& ss) const override
|
void log(std::stringstream &ss) const override
|
||||||
{
|
{
|
||||||
std::cout << ss.str() << "\n";
|
std::cout << ss.str() << "\n";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
class ErrorLog : public LogType
|
class ErrorLog: public LogType
|
||||||
{
|
{
|
||||||
public:
|
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);
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
|
||||||
std::cout << ss.str() << "\n";
|
std::cout << ss.str() << "\n";
|
||||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
|
||||||
#else
|
#else
|
||||||
std::cout << "Error: " << ss << "\n";
|
std::cout << "Error: " << ss << "\n";
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
class LogToAFile : public LogType
|
class LogToAFile: public LogType
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
public:
|
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);
|
std::ofstream f(name);
|
||||||
f << ss.str() << "\n";
|
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);
|
l.log(ss);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class ...T2>
|
template<class T, class ...T2>
|
||||||
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 << " ";
|
ss << t << " ";
|
||||||
llog(l, ss, t2...);
|
llog(l, ss, t2...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class ...T2>
|
template<class T, class ...T2>
|
||||||
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;
|
std::stringstream ss;
|
||||||
ss << t << " ";
|
ss << t << " ";
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
#ifndef TOOLS_H_INCLUDE
|
#ifndef TOOLS_H_INCLUDE
|
||||||
#define 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
|
#define INTERNAL_BUILD 1
|
||||||
//when internal build if false and an asertion is hit, the error is reported and the program
|
|
||||||
//closes
|
|
||||||
|
|
||||||
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
@ -17,14 +15,14 @@
|
||||||
|
|
||||||
#ifdef PLATFORM_WIN32
|
#ifdef PLATFORM_WIN32
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
inline void assertFuncProduction(
|
inline void assertFuncProduction(
|
||||||
const char* expression,
|
const char *expression,
|
||||||
const char* file_name,
|
const char *file_name,
|
||||||
unsigned const line_number,
|
unsigned const line_number,
|
||||||
const char* comment = "---")
|
const char *comment = "---")
|
||||||
{
|
{
|
||||||
|
|
||||||
char c[1024] = {};
|
char c[1024] = {};
|
||||||
|
|
||||||
|
@ -50,15 +48,9 @@ inline void assertFuncProduction(
|
||||||
|
|
||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case IDOK: // Abort the program:
|
case IDOK:
|
||||||
{
|
{
|
||||||
raise(SIGABRT);
|
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);
|
_exit(3);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -67,14 +59,14 @@ inline void assertFuncProduction(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void assertFuncInternal(
|
inline void assertFuncInternal(
|
||||||
const char* expression,
|
const char *expression,
|
||||||
const char* file_name,
|
const char *file_name,
|
||||||
unsigned const line_number,
|
unsigned const line_number,
|
||||||
const char* comment = "---")
|
const char *comment = "---")
|
||||||
{
|
{
|
||||||
|
|
||||||
char c[1024] = {};
|
char c[1024] = {};
|
||||||
|
|
||||||
|
@ -100,83 +92,77 @@ inline void assertFuncInternal(
|
||||||
|
|
||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case IDABORT: // Abort the program:
|
case IDABORT:
|
||||||
{
|
{
|
||||||
raise(SIGABRT);
|
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);
|
_exit(3);
|
||||||
}
|
}
|
||||||
case IDRETRY: // Break into the debugger then return control to caller
|
case IDRETRY:
|
||||||
{
|
{
|
||||||
__debugbreak();
|
__debugbreak();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case IDIGNORE: // Return control to caller
|
case IDIGNORE:
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
default: // This should not happen; treat as fatal error:
|
default:
|
||||||
{
|
{
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if INTERNAL_BUILD == 1
|
#if INTERNAL_BUILD == 1
|
||||||
|
|
||||||
#define permaAssert(expression) (void)( \
|
#define permaAssert(expression) (void)( \
|
||||||
(!!(expression)) || \
|
(!!(expression)) || \
|
||||||
(assertFuncInternal(#expression, __FILE__, (unsigned)(__LINE__)), 0) \
|
(assertFuncInternal(#expression, __FILE__, (unsigned)(__LINE__)), 0) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define permaAssertComment(expression, comment) (void)( \
|
#define permaAssertComment(expression, comment) (void)( \
|
||||||
(!!(expression)) || \
|
(!!(expression)) || \
|
||||||
(assertFuncInternal(#expression, __FILE__, (unsigned)(__LINE__), comment), 1) \
|
(assertFuncInternal(#expression, __FILE__, (unsigned)(__LINE__), comment), 1) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define permaAssert(expression) (void)( \
|
#define permaAssert(expression) (void)( \
|
||||||
(!!(expression)) || \
|
(!!(expression)) || \
|
||||||
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0) \
|
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define permaAssertComment(expression, comment) (void)( \
|
#define permaAssertComment(expression, comment) (void)( \
|
||||||
(!!(expression)) || \
|
(!!(expression)) || \
|
||||||
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__), comment), 1) \
|
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__), comment), 1) \
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#else //linux or others
|
#else
|
||||||
|
|
||||||
inline void assertFuncProduction(
|
inline void assertFuncProduction(
|
||||||
const char* expression,
|
const char *expression,
|
||||||
const char* file_name,
|
const char *file_name,
|
||||||
unsigned const line_number,
|
unsigned const line_number,
|
||||||
const char* comment = "---")
|
const char *comment = "---")
|
||||||
{
|
{
|
||||||
|
|
||||||
raise(SIGABRT);
|
raise(SIGABRT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define permaAssert(expression) (void)( \
|
#define permaAssert(expression) (void)( \
|
||||||
(!!(expression)) || \
|
(!!(expression)) || \
|
||||||
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0) \
|
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define permaAssertComment(expression, comment) (void)( \
|
#define permaAssertComment(expression, comment) (void)( \
|
||||||
(!!(expression)) || \
|
(!!(expression)) || \
|
||||||
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0, comment) \
|
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0, comment) \
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue