mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added ErrorScope name.
This commit is contained in:
@@ -8,22 +8,22 @@
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#define BX_ERROR_SET(_ptr, _result, _msg) \
|
||||
BX_MACRO_BLOCK_BEGIN \
|
||||
(_ptr)->setError(_result, "" _msg); \
|
||||
BX_MACRO_BLOCK_END
|
||||
#define BX_ERROR_SET(_ptr, _result, _msg) \
|
||||
BX_MACRO_BLOCK_BEGIN \
|
||||
(_ptr)->setError(_result, "" _msg); \
|
||||
BX_MACRO_BLOCK_END
|
||||
|
||||
#define BX_ERROR_USE_TEMP_WHEN_NULL(_ptr) \
|
||||
const bx::Error tmpError; /* It should not be used directly! */ \
|
||||
_ptr = NULL == _ptr ? const_cast<bx::Error*>(&tmpError) : _ptr
|
||||
#define BX_ERROR_USE_TEMP_WHEN_NULL(_ptr) \
|
||||
const bx::Error tmpError; /* It should not be used directly! */ \
|
||||
_ptr = NULL == _ptr ? const_cast<bx::Error*>(&tmpError) : _ptr
|
||||
|
||||
#define BX_ERROR_SCOPE(_ptr) \
|
||||
BX_ERROR_USE_TEMP_WHEN_NULL(_ptr); \
|
||||
bx::ErrorScope bxErrorScope(const_cast<bx::Error*>(&tmpError) )
|
||||
#define BX_ERROR_SCOPE(_ptr, ...) \
|
||||
BX_ERROR_USE_TEMP_WHEN_NULL(_ptr); \
|
||||
bx::ErrorScope bxErrorScope(const_cast<bx::Error*>(&tmpError), "" __VA_ARGS__)
|
||||
|
||||
#define BX_ERROR_RESULT(_err, _code) \
|
||||
BX_STATIC_ASSERT(_code != 0, "ErrorCode 0 is reserved!"); \
|
||||
static constexpr bx::ErrorResult _err = { _code }
|
||||
#define BX_ERROR_RESULT(_err, _code) \
|
||||
BX_STATIC_ASSERT(_code != 0, "ErrorCode 0 is reserved!"); \
|
||||
static constexpr bx::ErrorResult _err = { _code }
|
||||
|
||||
namespace bx
|
||||
{
|
||||
@@ -81,13 +81,17 @@ namespace bx
|
||||
|
||||
public:
|
||||
///
|
||||
ErrorScope(Error* _err);
|
||||
ErrorScope(Error* _err, const StringView& _name);
|
||||
|
||||
///
|
||||
~ErrorScope();
|
||||
|
||||
///
|
||||
const StringView& getName() const;
|
||||
|
||||
private:
|
||||
Error* m_err;
|
||||
const StringView m_name;
|
||||
};
|
||||
|
||||
} // namespace bx
|
||||
|
||||
@@ -59,15 +59,38 @@ namespace bx
|
||||
return _rhs.code != m_code;
|
||||
}
|
||||
|
||||
inline ErrorScope::ErrorScope(Error* _err)
|
||||
inline ErrorScope::ErrorScope(Error* _err, const StringView& _name)
|
||||
: m_err(_err)
|
||||
, m_name(_name)
|
||||
{
|
||||
BX_ASSERT(NULL != _err, "_err can't be NULL");
|
||||
}
|
||||
|
||||
inline ErrorScope::~ErrorScope()
|
||||
{
|
||||
BX_ASSERT(m_err->isOk(), "Error: %d", m_err->get().code);
|
||||
if (m_name.isEmpty() )
|
||||
{
|
||||
BX_ASSERT(m_err->isOk(), "Error: 0x%08x `%.*s`"
|
||||
, m_err->get().code
|
||||
, m_err->getMessage().getLength()
|
||||
, m_err->getMessage().getPtr()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
BX_ASSERT(m_err->isOk(), "Error: %.*s - 0x%08x `%.*s`"
|
||||
, m_name.getLength()
|
||||
, m_name.getPtr()
|
||||
, m_err->get().code
|
||||
, m_err->getMessage().getLength()
|
||||
, m_err->getMessage().getPtr()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
inline const StringView& ErrorScope::getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
} // namespace bx
|
||||
|
||||
Reference in New Issue
Block a user