Core/ErrorFlags: Turn this class into an inline class
This commit is contained in:
parent
ab8bac2575
commit
f2fc02cbd4
|
|
@ -31,13 +31,15 @@ namespace Nz
|
||||||
Error() = delete;
|
Error() = delete;
|
||||||
~Error() = delete;
|
~Error() = delete;
|
||||||
|
|
||||||
|
static ErrorModeFlags ApplyFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags);
|
||||||
|
|
||||||
static constexpr std::string_view GetCurrentFileRelativeToEngine(std::string_view file);
|
static constexpr std::string_view GetCurrentFileRelativeToEngine(std::string_view file);
|
||||||
static ErrorModeFlags GetFlags();
|
static ErrorModeFlags GetFlags();
|
||||||
static std::string GetLastError(std::string_view* file = nullptr, unsigned int* line = nullptr, std::string_view* function = nullptr);
|
static std::string GetLastError(std::string_view* file = nullptr, unsigned int* line = nullptr, std::string_view* function = nullptr);
|
||||||
static unsigned int GetLastSystemErrorCode();
|
static unsigned int GetLastSystemErrorCode();
|
||||||
static std::string GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
|
static std::string GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
|
||||||
|
|
||||||
static void SetFlags(ErrorModeFlags flags);
|
static ErrorModeFlags SetFlags(ErrorModeFlags flags);
|
||||||
|
|
||||||
template<typename... Args> static void Trigger(ErrorType type, std::string_view error, Args&&... args);
|
template<typename... Args> static void Trigger(ErrorType type, std::string_view error, Args&&... args);
|
||||||
template<typename... Args> static void Trigger(ErrorType type, unsigned int line, std::string_view file, std::string_view function, std::string_view error, Args&&... args);
|
template<typename... Args> static void Trigger(ErrorType type, unsigned int line, std::string_view file, std::string_view function, std::string_view error, Args&&... args);
|
||||||
|
|
|
||||||
|
|
@ -8,22 +8,21 @@
|
||||||
#define NAZARA_CORE_ERRORFLAGS_HPP
|
#define NAZARA_CORE_ERRORFLAGS_HPP
|
||||||
|
|
||||||
#include <NazaraUtils/Prerequisites.hpp>
|
#include <NazaraUtils/Prerequisites.hpp>
|
||||||
#include <Nazara/Core/Config.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Core/Enums.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class NAZARA_CORE_API ErrorFlags
|
class ErrorFlags
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ErrorFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags = {});
|
inline ErrorFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags = {});
|
||||||
ErrorFlags(const ErrorFlags&) = delete;
|
ErrorFlags(const ErrorFlags&) = delete;
|
||||||
ErrorFlags(ErrorFlags&&) = delete;
|
ErrorFlags(ErrorFlags&&) = delete;
|
||||||
~ErrorFlags();
|
inline ~ErrorFlags();
|
||||||
|
|
||||||
ErrorModeFlags GetPreviousFlags() const;
|
inline ErrorModeFlags GetPreviousFlags() const;
|
||||||
|
|
||||||
void SetFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags = {});
|
inline void SetFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags = {});
|
||||||
|
|
||||||
ErrorFlags& operator=(const ErrorFlags&) = delete;
|
ErrorFlags& operator=(const ErrorFlags&) = delete;
|
||||||
ErrorFlags& operator=(ErrorFlags&&) = delete;
|
ErrorFlags& operator=(ErrorFlags&&) = delete;
|
||||||
|
|
@ -33,4 +32,6 @@ namespace Nz
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/ErrorFlags.inl>
|
||||||
|
|
||||||
#endif // NAZARA_CORE_ERRORFLAGS_HPP
|
#endif // NAZARA_CORE_ERRORFLAGS_HPP
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Core/Debug.hpp>
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
|
|
@ -21,17 +19,15 @@ namespace Nz
|
||||||
* \param replace Replace the entirely the old flag if true, else do a "OR"
|
* \param replace Replace the entirely the old flag if true, else do a "OR"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ErrorFlags::ErrorFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags) :
|
inline ErrorFlags::ErrorFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags) :
|
||||||
m_previousFlags(Error::GetFlags())
|
m_previousFlags(Error::ApplyFlags(orFlags, andFlags))
|
||||||
{
|
{
|
||||||
SetFlags(orFlags, andFlags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Destructs the object and sets the old flag
|
* \brief Destructs the object and sets the old flag
|
||||||
*/
|
*/
|
||||||
|
inline ErrorFlags::~ErrorFlags()
|
||||||
ErrorFlags::~ErrorFlags()
|
|
||||||
{
|
{
|
||||||
Error::SetFlags(m_previousFlags);
|
Error::SetFlags(m_previousFlags);
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +36,7 @@ namespace Nz
|
||||||
* \brief Gets the previous flag
|
* \brief Gets the previous flag
|
||||||
* \return Previous flag
|
* \return Previous flag
|
||||||
*/
|
*/
|
||||||
ErrorModeFlags ErrorFlags::GetPreviousFlags() const
|
inline ErrorModeFlags ErrorFlags::GetPreviousFlags() const
|
||||||
{
|
{
|
||||||
return m_previousFlags;
|
return m_previousFlags;
|
||||||
}
|
}
|
||||||
|
|
@ -51,7 +47,7 @@ namespace Nz
|
||||||
* \param flags Flags for the error
|
* \param flags Flags for the error
|
||||||
* \param replace Replace the entirely the old flag if true, else do a "OR"
|
* \param replace Replace the entirely the old flag if true, else do a "OR"
|
||||||
*/
|
*/
|
||||||
void ErrorFlags::SetFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags)
|
inline void ErrorFlags::SetFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags)
|
||||||
{
|
{
|
||||||
ErrorModeFlags newFlags = m_previousFlags;
|
ErrorModeFlags newFlags = m_previousFlags;
|
||||||
newFlags |= orFlags;
|
newFlags |= orFlags;
|
||||||
|
|
@ -60,3 +56,5 @@ namespace Nz
|
||||||
Error::SetFlags(newFlags);
|
Error::SetFlags(newFlags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/DebugOff.hpp>
|
||||||
|
|
@ -42,12 +42,24 @@ namespace Nz
|
||||||
* \class Nz::Error
|
* \class Nz::Error
|
||||||
* \brief Core class that represents an error
|
* \brief Core class that represents an error
|
||||||
*/
|
*/
|
||||||
|
ErrorModeFlags Error::ApplyFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags)
|
||||||
|
{
|
||||||
|
NAZARA_USE_ANONYMOUS_NAMESPACE
|
||||||
|
|
||||||
|
ErrorModeFlags& flags = s_flags;
|
||||||
|
|
||||||
|
ErrorModeFlags previousFlags = flags;
|
||||||
|
|
||||||
|
flags |= orFlags;
|
||||||
|
flags &= andFlags;
|
||||||
|
|
||||||
|
return previousFlags;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Gets the flags of the error
|
* \brief Gets the flags of the error
|
||||||
* \return Flag
|
* \return Flag
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ErrorModeFlags Error::GetFlags()
|
ErrorModeFlags Error::GetFlags()
|
||||||
{
|
{
|
||||||
NAZARA_USE_ANONYMOUS_NAMESPACE
|
NAZARA_USE_ANONYMOUS_NAMESPACE
|
||||||
|
|
@ -63,7 +75,6 @@ namespace Nz
|
||||||
* \param line Optional argument to set last error line
|
* \param line Optional argument to set last error line
|
||||||
* \param function Optional argument to set last error function
|
* \param function Optional argument to set last error function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::string Error::GetLastError(std::string_view* file, unsigned int* line, std::string_view* function)
|
std::string Error::GetLastError(std::string_view* file, unsigned int* line, std::string_view* function)
|
||||||
{
|
{
|
||||||
NAZARA_USE_ANONYMOUS_NAMESPACE
|
NAZARA_USE_ANONYMOUS_NAMESPACE
|
||||||
|
|
@ -84,7 +95,6 @@ namespace Nz
|
||||||
* \brief Gets the last system error code
|
* \brief Gets the last system error code
|
||||||
* \return "errno"
|
* \return "errno"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int Error::GetLastSystemErrorCode()
|
unsigned int Error::GetLastSystemErrorCode()
|
||||||
{
|
{
|
||||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||||
|
|
@ -137,18 +147,23 @@ namespace Nz
|
||||||
* \param flags Flags for the error
|
* \param flags Flags for the error
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Error::SetFlags(ErrorModeFlags flags)
|
ErrorModeFlags Error::SetFlags(ErrorModeFlags flags)
|
||||||
{
|
{
|
||||||
NAZARA_USE_ANONYMOUS_NAMESPACE
|
NAZARA_USE_ANONYMOUS_NAMESPACE
|
||||||
|
|
||||||
|
ErrorModeFlags previousFlags = s_flags;
|
||||||
s_flags = flags;
|
s_flags = flags;
|
||||||
|
|
||||||
|
return previousFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Error::TriggerInternal(ErrorType type, std::string error, unsigned int line, std::string_view file, std::string_view function)
|
void Error::TriggerInternal(ErrorType type, std::string error, unsigned int line, std::string_view file, std::string_view function)
|
||||||
{
|
{
|
||||||
NAZARA_USE_ANONYMOUS_NAMESPACE
|
NAZARA_USE_ANONYMOUS_NAMESPACE
|
||||||
|
|
||||||
if (type == ErrorType::AssertFailed || (s_flags & ErrorMode::Silent) == 0)
|
ErrorModeFlags& flags = s_flags;
|
||||||
|
|
||||||
|
if (type == ErrorType::AssertFailed || (flags & ErrorMode::Silent) == 0)
|
||||||
{
|
{
|
||||||
if (line == 0 && file.empty())
|
if (line == 0 && file.empty())
|
||||||
Log::Write("{}{}", s_errorTypes[type], error);
|
Log::Write("{}{}", s_errorTypes[type], error);
|
||||||
|
|
@ -169,7 +184,7 @@ namespace Nz
|
||||||
std::abort();
|
std::abort();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (type == ErrorType::AssertFailed || (type != ErrorType::Warning && s_flags.Test(ErrorMode::ThrowException)))
|
if (type == ErrorType::AssertFailed || (type != ErrorType::Warning && flags.Test(ErrorMode::ThrowException)))
|
||||||
throw std::runtime_error(s_lastError);
|
throw std::runtime_error(s_lastError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue