Бранимир Караџић 1 рік тому
батько
коміт
9063c0c968
4 змінених файлів з 51 додано та 17 видалено
  1. 11 7
      include/bx/error.h
  2. 22 10
      include/bx/inline/error.inl
  3. 11 0
      include/bx/inline/string.inl
  4. 7 0
      include/bx/string.h

+ 11 - 7
include/bx/error.h

@@ -48,7 +48,7 @@ namespace bx
 		void reset();
 		void reset();
 
 
 		///
 		///
-		void setError(ErrorResult _errorResult, const StringView& _msg);
+		void setError(ErrorResult _errorResult, const StringLiteral& _msg, const Location& _location = Location::current() );
 
 
 		///
 		///
 		bool isOk() const;
 		bool isOk() const;
@@ -57,7 +57,10 @@ namespace bx
 		ErrorResult get() const;
 		ErrorResult get() const;
 
 
 		///
 		///
-		const StringView& getMessage() const;
+		const StringLiteral& getMessage() const;
+
+		///
+		const Location& getLocation() const;
 
 
 		///
 		///
 		bool operator==(const ErrorResult& _rhs) const;
 		bool operator==(const ErrorResult& _rhs) const;
@@ -66,8 +69,9 @@ namespace bx
 		bool operator!=(const ErrorResult& _rhs) const;
 		bool operator!=(const ErrorResult& _rhs) const;
 
 
 	private:
 	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.
 	/// Do nothing even if error is set.
@@ -110,17 +114,17 @@ namespace bx
 
 
 	public:
 	public:
 		///
 		///
-		ErrorScope(Error* _err, const StringView& _name);
+		ErrorScope(Error* _err, const StringLiteral& _name);
 
 
 		///
 		///
 		~ErrorScope();
 		~ErrorScope();
 
 
 		///
 		///
-		const StringView& getName() const;
+		const StringLiteral& getName() const;
 
 
 	private:
 	private:
 		Error* m_err;
 		Error* m_err;
-		const StringView m_name;
+		const StringLiteral m_name;
 	};
 	};
 
 
 } // namespace bx
 } // namespace bx

+ 22 - 10
include/bx/inline/error.inl

@@ -22,7 +22,7 @@ namespace bx
 		m_msg.clear();
 		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!");
 		BX_ASSERT(0 != _errorResult.code, "Invalid ErrorResult passed to setError!");
 
 
@@ -31,8 +31,9 @@ namespace bx
 			return;
 			return;
 		}
 		}
 
 
-		m_code = _errorResult.code;
-		m_msg  = _msg;
+		m_location = _location;
+		m_code     = _errorResult.code;
+		m_msg      = _msg;
 	}
 	}
 
 
 	inline bool Error::isOk() const
 	inline bool Error::isOk() const
@@ -46,11 +47,16 @@ namespace bx
 		return result;
 		return result;
 	}
 	}
 
 
-	inline const StringView& Error::getMessage() const
+	inline const StringLiteral& Error::getMessage() const
 	{
 	{
 		return m_msg;
 		return m_msg;
 	}
 	}
 
 
+	inline const Location& Error::getLocation() const
+	{
+		return m_location;
+	}
+
 	inline bool Error::operator==(const ErrorResult& _rhs) const
 	inline bool Error::operator==(const ErrorResult& _rhs) const
 	{
 	{
 		return _rhs.code == m_code;
 		return _rhs.code == m_code;
@@ -68,7 +74,7 @@ namespace bx
 
 
 	inline ErrorAssert::~ErrorAssert()
 	inline ErrorAssert::~ErrorAssert()
 	{
 	{
-		BX_ASSERT(isOk(), "ErrorAssert: 0x%08x `%S`"
+		BX_ASSERT_LOC(getLocation(), isOk(), "ErrorAssert: 0x%08x `%S`"
 			, get().code
 			, get().code
 			, &getMessage()
 			, &getMessage()
 			);
 			);
@@ -81,7 +87,7 @@ namespace bx
 
 
 	inline ErrorFatal::~ErrorFatal()
 	inline ErrorFatal::~ErrorFatal()
 	{
 	{
-		_BX_ASSERT(isOk(), "ErrorFatal: 0x%08x `%S`"
+		_BX_ASSERT_LOC(getLocation(), isOk(), "ErrorFatal: 0x%08x `%S`"
 			, get().code
 			, get().code
 			, &getMessage()
 			, &getMessage()
 			);
 			);
@@ -92,7 +98,7 @@ namespace bx
 		return this;
 		return this;
 	}
 	}
 
 
-	inline ErrorScope::ErrorScope(Error* _err, const StringView& _name)
+	inline ErrorScope::ErrorScope(Error* _err, const StringLiteral& _name)
 		: m_err(_err)
 		: m_err(_err)
 		, m_name(_name)
 		, m_name(_name)
 	{
 	{
@@ -104,14 +110,20 @@ namespace bx
 	{
 	{
 		if (m_name.isEmpty() )
 		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->get().code
 				, &m_err->getMessage()
 				, &m_err->getMessage()
 				);
 				);
 		}
 		}
 		else
 		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_name
 				, m_err->get().code
 				, m_err->get().code
 				, &m_err->getMessage()
 				, &m_err->getMessage()
@@ -119,7 +131,7 @@ namespace bx
 		}
 		}
 	}
 	}
 
 
-	inline const StringView& ErrorScope::getName() const
+	inline const StringLiteral& ErrorScope::getName() const
 	{
 	{
 		return m_name;
 		return m_name;
 	}
 	}

+ 11 - 0
include/bx/inline/string.inl

@@ -61,6 +61,17 @@ namespace bx
 		return m_ptr;
 		return m_ptr;
 	}
 	}
 
 
+	inline void StringLiteral::clear()
+	{
+		m_ptr = "";
+		m_len = 0;
+	}
+
+	inline bool StringLiteral::isEmpty() const
+	{
+		return 0 == m_len;
+	}
+
 	inline StringView::StringView()
 	inline StringView::StringView()
 	{
 	{
 		clear();
 		clear();

+ 7 - 0
include/bx/string.h

@@ -42,6 +42,13 @@ namespace bx
 		///
 		///
 		constexpr const char* getCPtr() const;
 		constexpr const char* getCPtr() const;
 
 
+		///
+		void clear();
+
+		/// Returns `true` if string is empty.
+		///
+		bool isEmpty() const;
+
 	private:
 	private:
 		const char* m_ptr;
 		const char* m_ptr;
 		int32_t     m_len;
 		int32_t     m_len;