Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaradzic committed Jul 20, 2024
1 parent bb481c0 commit 9063c0c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
18 changes: 11 additions & 7 deletions include/bx/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace bx
void reset();

///
void setError(ErrorResult _errorResult, const StringView& _msg);
void setError(ErrorResult _errorResult, const StringLiteral& _msg, const Location& _location = Location::current() );

///
bool isOk() const;
Expand All @@ -57,7 +57,10 @@ namespace bx
ErrorResult get() const;

///
const StringView& getMessage() const;
const StringLiteral& getMessage() const;

///
const Location& getLocation() const;

///
bool operator==(const ErrorResult& _rhs) const;
Expand All @@ -66,8 +69,9 @@ namespace bx
bool operator!=(const ErrorResult& _rhs) const;

private:
StringView m_msg;
uint32_t m_code;
Location m_location;
StringLiteral m_msg;
uint32_t m_code;
};

/// Do nothing even if error is set.
Expand Down Expand Up @@ -110,17 +114,17 @@ namespace bx

public:
///
ErrorScope(Error* _err, const StringView& _name);
ErrorScope(Error* _err, const StringLiteral& _name);

///
~ErrorScope();

///
const StringView& getName() const;
const StringLiteral& getName() const;

private:
Error* m_err;
const StringView m_name;
const StringLiteral m_name;
};

} // namespace bx
Expand Down
32 changes: 22 additions & 10 deletions include/bx/inline/error.inl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace bx
m_msg.clear();
}

inline void Error::setError(ErrorResult _errorResult, const StringView& _msg)
inline void Error::setError(ErrorResult _errorResult, const StringLiteral& _msg, const Location& _location)
{
BX_ASSERT(0 != _errorResult.code, "Invalid ErrorResult passed to setError!");

Expand All @@ -31,8 +31,9 @@ namespace bx
return;
}

m_code = _errorResult.code;
m_msg = _msg;
m_location = _location;
m_code = _errorResult.code;
m_msg = _msg;
}

inline bool Error::isOk() const
Expand All @@ -46,11 +47,16 @@ namespace bx
return result;
}

inline const StringView& Error::getMessage() const
inline const StringLiteral& Error::getMessage() const
{
return m_msg;
}

inline const Location& Error::getLocation() const
{
return m_location;
}

inline bool Error::operator==(const ErrorResult& _rhs) const
{
return _rhs.code == m_code;
Expand All @@ -68,7 +74,7 @@ namespace bx

inline ErrorAssert::~ErrorAssert()
{
BX_ASSERT(isOk(), "ErrorAssert: 0x%08x `%S`"
BX_ASSERT_LOC(getLocation(), isOk(), "ErrorAssert: 0x%08x `%S`"
, get().code
, &getMessage()
);
Expand All @@ -81,7 +87,7 @@ namespace bx

inline ErrorFatal::~ErrorFatal()
{
_BX_ASSERT(isOk(), "ErrorFatal: 0x%08x `%S`"
_BX_ASSERT_LOC(getLocation(), isOk(), "ErrorFatal: 0x%08x `%S`"
, get().code
, &getMessage()
);
Expand All @@ -92,7 +98,7 @@ namespace bx
return this;
}

inline ErrorScope::ErrorScope(Error* _err, const StringView& _name)
inline ErrorScope::ErrorScope(Error* _err, const StringLiteral& _name)
: m_err(_err)
, m_name(_name)
{
Expand All @@ -104,22 +110,28 @@ namespace bx
{
if (m_name.isEmpty() )
{
BX_ASSERT(m_err->isOk(), "Error: 0x%08x `%S`"
BX_ASSERT_LOC(
m_err->getLocation()
, m_err->isOk()
, "ErrorScope: 0x%08x `%S`"
, m_err->get().code
, &m_err->getMessage()
);
}
else
{
BX_ASSERT(m_err->isOk(), "Error: %S - 0x%08x `%S`"
BX_ASSERT_LOC(
m_err->getLocation()
, m_err->isOk()
, "ErrorScope: %S - 0x%08x `%S`"
, &m_name
, m_err->get().code
, &m_err->getMessage()
);
}
}

inline const StringView& ErrorScope::getName() const
inline const StringLiteral& ErrorScope::getName() const
{
return m_name;
}
Expand Down
11 changes: 11 additions & 0 deletions include/bx/inline/string.inl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ namespace bx
return m_ptr;
}

inline void StringLiteral::clear()
{
m_ptr = "";
m_len = 0;
}

inline bool StringLiteral::isEmpty() const
{
return 0 == m_len;
}

inline StringView::StringView()
{
clear();
Expand Down
7 changes: 7 additions & 0 deletions include/bx/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ namespace bx
///
constexpr const char* getCPtr() const;

///
void clear();

/// Returns `true` if string is empty.
///
bool isEmpty() const;

private:
const char* m_ptr;
int32_t m_len;
Expand Down

0 comments on commit 9063c0c

Please sign in to comment.