diff --git a/src/Nazara/Core/Error.cpp b/src/Nazara/Core/Error.cpp index 805e60190..59a8b72fb 100644 --- a/src/Nazara/Core/Error.cpp +++ b/src/Nazara/Core/Error.cpp @@ -18,11 +18,30 @@ namespace Nz { + /*! + * \class Nz::Error + * \brief Core class that represents an error + */ + + /*! + * \brief Gets the flags of the error + * \return Flag + */ + UInt32 Error::GetFlags() { return s_flags; } + /*! + * \brief Gets the last error + * \return Last error + * + * \param file Optional argument to set last error file + * \param line Optional argument to set last error line + * \param function Optional argument to set last error function + */ + String Error::GetLastError(const char** file, unsigned int* line, const char** function) { if (file) @@ -37,6 +56,11 @@ namespace Nz return s_lastError; } + /*! + * \brief Gets the last system error code + * \return "errno" + */ + unsigned int Error::GetLastSystemErrorCode() { #if defined(NAZARA_PLATFORM_WINDOWS) @@ -49,6 +73,13 @@ namespace Nz #endif } + /*! + * \brief Gets the string representation of the last system error code + * \return Message of the error + * + * \param code Code of the error + */ + String Error::GetLastSystemError(unsigned int code) { #if defined(NAZARA_PLATFORM_WINDOWS) @@ -65,7 +96,7 @@ namespace Nz String error(String::Unicode(buffer)); LocalFree(buffer); - error.Trim(); // Pour une raison inconnue, Windows met deux-trois retours à la ligne après le message + error.Trim(); // For an unknown reason, Windows put two-three line return after the message return error; #elif defined(NAZARA_PLATFORM_POSIX) @@ -77,11 +108,27 @@ namespace Nz #endif } + /*! + * \brief Sets the flags + * + * \param flags Flags for the error + */ + void Error::SetFlags(UInt32 flags) { s_flags = flags; } + /*! + * \brief Checks if the error should trigger + * + * \param type ErrorType of the error + * \param error Message of the error + * + * \remark Produces a std::abort on AssertFailed with NAZARA_CORE_EXIT_ON_ASSERT_FAILURE defined + * \remark Produces a std::runtime_error on AssertFailed or throwing exception + */ + void Error::Trigger(ErrorType type, const String& error) { if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0) @@ -102,6 +149,19 @@ namespace Nz throw std::runtime_error(error); } + /*! + * \brief Checks if the error should trigger + * + * \param type ErrorType of the error + * \param error Message of the error + * \param line Line of the error + * \param file File of the error + * \param function Function of the error + * + * \remark Produces a std::abort on AssertFailed with NAZARA_CORE_EXIT_ON_ASSERT_FAILURE defined + * \remark Produces a std::runtime_error on AssertFailed or throwing exception + */ + void Error::Trigger(ErrorType type, const String& error, unsigned int line, const char* file, const char* function) { if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0) diff --git a/src/Nazara/Core/ErrorFlags.cpp b/src/Nazara/Core/ErrorFlags.cpp index 08c1d3e19..d29efbc5a 100644 --- a/src/Nazara/Core/ErrorFlags.cpp +++ b/src/Nazara/Core/ErrorFlags.cpp @@ -8,22 +8,50 @@ namespace Nz { + /*! + * \class Nz::ErrorFlags + * \brief Core class that represents flags for error + */ + + /*! + * \brief Constructs a ErrorFlags object with flags + * + * \param flags Flags for the error + * \param replace Replace the entirely the old flag if true, else do a "OR" + */ + ErrorFlags::ErrorFlags(UInt32 flags, bool replace) : m_previousFlags(Error::GetFlags()) { SetFlags(flags, replace); } + /*! + * \brief Destructs the object and sets the old flag + */ + ErrorFlags::~ErrorFlags() { Error::SetFlags(m_previousFlags); } + /*! + * \brief Gets the previous flag + * \return Previous flag + */ + UInt32 ErrorFlags::GetPreviousFlags() const { return m_previousFlags; } + /*! + * \brief Sets the flags + * + * \param flags Flags for the error + * \param replace Replace the entirely the old flag if true, else do a "OR" + */ + void ErrorFlags::SetFlags(UInt32 flags, bool replace) { if (!replace)