diff --git a/lib/hkStubs/CMakeLists.txt b/lib/hkStubs/CMakeLists.txt index 111b289a..bc285121 100644 --- a/lib/hkStubs/CMakeLists.txt +++ b/lib/hkStubs/CMakeLists.txt @@ -7,6 +7,7 @@ add_library(hkStubs OBJECT Havok/Common/Base/Container/Array/hkArray.h Havok/Common/Base/Container/Array/hkArrayUtil.h Havok/Common/Base/Container/Array/hkSmallArray.h + Havok/Common/Base/Container/String/hkString.h Havok/Common/Base/Container/String/hkStringPtr.h Havok/Common/Base/DebugUtil/MultiThreadCheck/hkMultiThreadCheck.h diff --git a/lib/hkStubs/Havok/Common/Base/Container/String/hkString.h b/lib/hkStubs/Havok/Common/Base/Container/String/hkString.h new file mode 100644 index 00000000..e40484d3 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Container/String/hkString.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace hkString { + +int strCmp(const char* s1, const char* s2); +hkBool beginsWith(const char* str, const char* prefix); +hkBool endsWith(const char* str, const char* suffix); + +} // namespace hkString diff --git a/lib/hkStubs/Havok/Common/Base/Container/String/hkStringPtr.h b/lib/hkStubs/Havok/Common/Base/Container/String/hkStringPtr.h index 35fabb72..153df4b3 100644 --- a/lib/hkStubs/Havok/Common/Base/Container/String/hkStringPtr.h +++ b/lib/hkStubs/Havok/Common/Base/Container/String/hkStringPtr.h @@ -1,5 +1,6 @@ #pragma once +#include #include class hkStringPtr { @@ -11,12 +12,32 @@ public: }; hkStringPtr(); + hkStringPtr(const char* string); // NOLINT(google-explicit-constructor) + hkStringPtr(const char* string, int len); + hkStringPtr(const hkStringPtr& strRef); explicit hkStringPtr(hkFinishLoadedObjectFlag f); + ~hkStringPtr(); + inline const char* cString() const; - inline operator const char*() const; + inline operator const char*() const; // NOLINT(google-explicit-constructor) hkStringPtr& operator=(const char* s); + hkStringPtr& operator=(const hkStringPtr& s); + + int getLength() const; + + inline char operator[](int idx) const; + + void printf(const char* fmt, ...); + void set(const char* s, int len = -1); + void setPointerAligned(const char* s); + + inline hkBool32 operator==(const char* s) const; + inline hkBool32 operator!=(const char* s) const; + inline hkBool32 startsWith(const char* s) const; + inline hkBool32 endsWith(const char* s) const; + inline int compareTo(const char* rhs) const; private: const char* m_stringAndFlag; @@ -29,3 +50,34 @@ inline const char* hkStringPtr::cString() const { inline hkStringPtr::operator const char*() const { return cString(); } + +inline char hkStringPtr::operator[](int idx) const { + return cString()[idx]; +} + +inline hkBool32 hkStringPtr::operator==(const char* s) const { + return compareTo(s) == 0; +} + +inline hkBool32 hkStringPtr::operator!=(const char* s) const { + return compareTo(s) != 0; +} + +inline hkBool32 hkStringPtr::startsWith(const char* s) const { + return hkString::beginsWith(cString(), s); +} + +inline hkBool32 hkStringPtr::endsWith(const char* s) const { + return hkString::endsWith(cString(), s); +} + +inline int hkStringPtr::compareTo(const char* rhs) const { + const char* lhs = cString(); + if (lhs && rhs) + return hkString::strCmp(lhs, rhs); + if (lhs != nullptr) + return 1; + if (rhs != nullptr) + return -1; + return 0; +} diff --git a/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h b/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h index 8b4ab3c6..71638a1d 100644 --- a/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h +++ b/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h @@ -75,6 +75,9 @@ private: hkInt16 m_value; }; +using hkBool32 = hkUint32; +using hkBoolLL = hkUint64; + class hkBool { public: HK_ALWAYS_INLINE hkBool() = default; @@ -82,6 +85,8 @@ public: HK_FORCE_INLINE constexpr hkBool(bool b) : m_bool(static_cast(b)) {} HK_FORCE_INLINE constexpr explicit operator bool() const { return m_bool != 0; } + // NOLINTNEXTLINE(google-explicit-constructor) + HK_FORCE_INLINE constexpr operator hkBool32() const { return m_bool != 0; } HK_FORCE_INLINE constexpr hkBool& operator=(bool e) { m_bool = static_cast(e); @@ -95,9 +100,6 @@ private: char m_bool; }; -using hkBool32 = hkUint32; -using hkBoolLL = hkUint64; - /// For storing an enum with a particular storage size when specifying the underlying type of the /// enum is not an option. template