Merge branch 'develop' into feature/cubiquity-version
This commit is contained in:
@ -23,49 +23,135 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "PolyVoxCore/Impl/ErrorHandling.h"
|
||||
|
||||
#ifndef POLYVOX_THROW_ENABLED
|
||||
namespace PolyVox
|
||||
namespace PolyVox
|
||||
{
|
||||
void defaultLogHandler(const std::string& message, LogLevel logLevel)
|
||||
{
|
||||
void defaultThrowHandler(std::exception& e, const char* file, int line)
|
||||
switch(logLevel)
|
||||
{
|
||||
std::cerr << std::endl << std::endl; \
|
||||
std::cerr << " PolyVox exception thrown!" << std::endl; \
|
||||
std::cerr << " =========================" << std::endl; \
|
||||
std::cerr << " PolyVox has tried to throw an exception but it was built without support" << std::endl; \
|
||||
std::cerr << " for exceptions. In this scenario PolyVox will call a 'throw handler'" << std::endl; \
|
||||
std::cerr << " and this message is being printed by the default throw handler." << std::endl << std::endl; \
|
||||
|
||||
std::cerr << " If you don't want to enable exceptions then you should try to determine why" << std::endl; \
|
||||
std::cerr << " this exception was thrown and make sure it doesn't happen again. If it was" << std::endl; \
|
||||
std::cerr << " due to something like an invalid argument to a function then you should be" << std::endl; \
|
||||
std::cerr << " able to fix it quite easily by validating parameters as appropriate. More" << std::endl; \
|
||||
std::cerr << " complex exception scenarios (out of memory, etc) might be harder to fix and" << std::endl; \
|
||||
std::cerr << " you should replace this default handler with something which is more" << std::endl; \
|
||||
std::cerr << " meaningful to your users." << std::endl << std::endl; \
|
||||
|
||||
std::cerr << " Exception details" << std::endl; \
|
||||
std::cerr << " -----------------" << std::endl; \
|
||||
std::cerr << " Line: " << line << std::endl; \
|
||||
std::cerr << " File: " << file << std::endl; \
|
||||
std::cerr << " Message: " << e.what() << std::endl << std::endl; \
|
||||
|
||||
POLYVOX_HALT(); \
|
||||
}
|
||||
|
||||
ThrowHandler& getThrowHandlerInstance()
|
||||
{
|
||||
static ThrowHandler s_fThrowHandler = &defaultThrowHandler;
|
||||
return s_fThrowHandler;
|
||||
}
|
||||
|
||||
ThrowHandler getThrowHandler()
|
||||
{
|
||||
return getThrowHandlerInstance();
|
||||
}
|
||||
|
||||
void setThrowHandler(ThrowHandler fNewHandler)
|
||||
{
|
||||
getThrowHandlerInstance() = fNewHandler;
|
||||
case LogLevels::Debug:
|
||||
{
|
||||
// Debug messages are not output by this default log handler.
|
||||
// Provide a custom handler if you want to process them.
|
||||
break;
|
||||
}
|
||||
case LogLevels::Info:
|
||||
{
|
||||
std::cout << "Info: " << message.c_str() << std::endl;
|
||||
break;
|
||||
}
|
||||
case LogLevels::Warning:
|
||||
{
|
||||
std::cerr << "Warning: " << message.c_str() << std::endl;
|
||||
break;
|
||||
}
|
||||
case LogLevels::Error:
|
||||
{
|
||||
std::cerr << "Error: " << message.c_str() << std::endl;
|
||||
break;
|
||||
}
|
||||
case LogLevels::Fatal:
|
||||
{
|
||||
std::cerr << "Fatal: " << message.c_str() << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LogHandler& getLogHandlerInstance()
|
||||
{
|
||||
static LogHandler s_fLogHandler = &defaultLogHandler;
|
||||
return s_fLogHandler;
|
||||
}
|
||||
|
||||
LogHandler getLogHandler()
|
||||
{
|
||||
return getLogHandlerInstance();
|
||||
}
|
||||
|
||||
void setLogHandler(LogHandler fNewHandler)
|
||||
{
|
||||
getLogHandlerInstance() = fNewHandler;
|
||||
}
|
||||
|
||||
void log(const std::string& message, LogLevel logLevel)
|
||||
{
|
||||
LogHandler logHandler = getLogHandler();
|
||||
if(logHandler)
|
||||
{
|
||||
logHandler(message, logLevel);
|
||||
}
|
||||
}
|
||||
|
||||
// Some handy wrappers
|
||||
void logDebug(const std::string& message)
|
||||
{
|
||||
log(message, LogLevels::Debug );
|
||||
}
|
||||
|
||||
void logInfo(const std::string& message)
|
||||
{
|
||||
log(message, LogLevels::Info);
|
||||
}
|
||||
|
||||
void logWarning(const std::string& message)
|
||||
{
|
||||
log(message, LogLevels::Warning);
|
||||
}
|
||||
|
||||
void logError(const std::string& message)
|
||||
{
|
||||
log(message, LogLevels::Error);
|
||||
}
|
||||
|
||||
void logFatal(const std::string& message)
|
||||
{
|
||||
log(message, LogLevels::Fatal);
|
||||
}
|
||||
|
||||
#ifndef POLYVOX_THROW_ENABLED
|
||||
void defaultThrowHandler(std::exception& e, const char* file, int line)
|
||||
{
|
||||
std::stringstream ss; \
|
||||
ss << std::endl << std::endl; \
|
||||
ss << " PolyVox exception thrown!" << std::endl; \
|
||||
ss << " =========================" << std::endl; \
|
||||
ss << " PolyVox has tried to throw an exception but it was built without support" << std::endl; \
|
||||
ss << " for exceptions. In this scenario PolyVox will call a 'throw handler'" << std::endl; \
|
||||
ss << " and this message is being printed by the default throw handler." << std::endl << std::endl; \
|
||||
|
||||
ss << " If you don't want to enable exceptions then you should try to determine why" << std::endl; \
|
||||
ss << " this exception was thrown and make sure it doesn't happen again. If it was" << std::endl; \
|
||||
ss << " due to something like an invalid argument to a function then you should be" << std::endl; \
|
||||
ss << " able to fix it quite easily by validating parameters as appropriate. More" << std::endl; \
|
||||
ss << " complex exception scenarios (out of memory, etc) might be harder to fix and" << std::endl; \
|
||||
ss << " you should replace this default handler with something which is more" << std::endl; \
|
||||
ss << " meaningful to your users." << std::endl << std::endl; \
|
||||
|
||||
ss << " Exception details" << std::endl; \
|
||||
ss << " -----------------" << std::endl; \
|
||||
ss << " Line: " << line << std::endl; \
|
||||
ss << " File: " << file << std::endl; \
|
||||
ss << " Message: " << e.what() << std::endl << std::endl; \
|
||||
logFatal(ss.str()); \
|
||||
|
||||
POLYVOX_HALT(); \
|
||||
}
|
||||
|
||||
ThrowHandler& getThrowHandlerInstance()
|
||||
{
|
||||
static ThrowHandler s_fThrowHandler = &defaultThrowHandler;
|
||||
return s_fThrowHandler;
|
||||
}
|
||||
|
||||
ThrowHandler getThrowHandler()
|
||||
{
|
||||
return getThrowHandlerInstance();
|
||||
}
|
||||
|
||||
void setThrowHandler(ThrowHandler fNewHandler)
|
||||
{
|
||||
getThrowHandlerInstance() = fNewHandler;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -30,10 +30,6 @@ namespace PolyVox
|
||||
//If this is not the case then the output is undefined.
|
||||
uint8_t logBase2(uint32_t uInput)
|
||||
{
|
||||
//Debug mode validation
|
||||
POLYVOX_ASSERT(uInput != 0, "Cannot compute the log of zero.");
|
||||
POLYVOX_ASSERT(isPowerOf2(uInput), "Input must be a power of two in order to compute the log.");
|
||||
|
||||
//Release mode validation
|
||||
if(uInput == 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user