diff --git a/CMakeLists.txt b/CMakeLists.txt index edbe2783..bf8f0c6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,6 @@ add_library(sead OBJECT include/devenv/seadGameConfig.h include/devenv/seadStackTrace.h modules/src/devenv/seadAssertConfig.cpp - modules/src/devenv/seadFontMgr.cpp modules/src/devenv/seadGameConfig.cpp modules/src/devenv/seadStackTrace.cpp diff --git a/include/devenv/seadFontMgr.h b/include/devenv/seadFontMgr.h index 217546d6..ad502ff1 100644 --- a/include/devenv/seadFontMgr.h +++ b/include/devenv/seadFontMgr.h @@ -34,7 +34,7 @@ class UniformBlockBuffer class FontBase { public: - virtual ~FontBase(); + virtual ~FontBase() = default; virtual float getHeight() const = 0; virtual float getWidth() const = 0; diff --git a/include/gfx/seadFrameBuffer.h b/include/gfx/seadFrameBuffer.h index a4337630..728db6b5 100644 --- a/include/gfx/seadFrameBuffer.h +++ b/include/gfx/seadFrameBuffer.h @@ -31,7 +31,7 @@ class LogicalFrameBuffer mPhysicalArea(physical_x, physical_y, physical_x + physical_w, physical_y + physical_h) { } - virtual ~LogicalFrameBuffer(); + virtual ~LogicalFrameBuffer() = default; const Vector2f& getVirtualSize() const { return mVirtualSize; } const BoundBox2f& getPhysicalArea() const { return mPhysicalArea; } diff --git a/include/gfx/seadProjection.h b/include/gfx/seadProjection.h index f3d64fa7..addef964 100644 --- a/include/gfx/seadProjection.h +++ b/include/gfx/seadProjection.h @@ -21,7 +21,7 @@ class Projection public: Projection(); - virtual ~Projection() = default; + virtual ~Projection(); virtual f32 getNear() const = 0; virtual f32 getFar() const = 0; @@ -72,7 +72,7 @@ class PerspectiveProjection : public Projection public: PerspectiveProjection(); PerspectiveProjection(f32 near, f32 far, f32 fovy_rad, f32 aspect); - ~PerspectiveProjection() override; + ~PerspectiveProjection() override = default; f32 getNear() const override; f32 getFar() const override; diff --git a/include/prim/seadStringBuilder.h b/include/prim/seadStringBuilder.h index 786c9ca8..9f3513f5 100644 --- a/include/prim/seadStringBuilder.h +++ b/include/prim/seadStringBuilder.h @@ -180,6 +180,32 @@ class StringBuilderBase template s32 convertFromOtherType_(const OtherType* src, s32 src_size); + s32 copyImpl_(const T* src, s32 copy_length); + bool endsWithImpl_(const T* suffix) const; + s32 copyAtImpl_(s32 at, const T* src, s32 copy_length); + s32 cutOffCopyImpl_(const T* src, s32 copy_length); + s32 cutOffCopyAtImpl_(s32 at, const T* src, s32 copy_length); + s32 copyAtWithTerminateImpl_(s32 at, const T* src, s32 copy_length); + s32 appendImpl_(const T* str, s32 append_length); + s32 appendImpl_(T* buffer, s32* length_, const s32 buffer_size, T c, s32 num); + s32 chopImpl_(s32 chop_num); + s32 chopMatchedCharImpl_(T c); + s32 chopMatchedCharImpl_(const T* characters); + s32 chopUnprintableAsciiCharImpl_(); + s32 rstripImpl_(const T* characters); + s32 rstripUnprintableAsciiCharsImpl_(); + s32 trimImpl_(s32 trim_length); + s32 trimMatchedStringImpl_(const T* str); + s32 replaceCharImpl_(T old_char, T new_char); + inline s32 replaceCharListImpl_(const SafeStringBase& old_chars, + const SafeStringBase& new_chars); + s32 convertFromMultiByteStringImpl_(const char* str, s32 str_length); + s32 convertFromWideCharStringImpl_(const char16* str, s32 str_length); + s32 cutOffAppendImpl_(const T* str, s32 append_length); + s32 cutOffAppendImpl_(T c, s32 num); + s32 prependImpl_(const T* str, s32 prepend_length); + s32 prependImpl_(T c, s32 num); + T* getMutableStringTop_() const { return mBuffer; } T* mBuffer; diff --git a/include/resource/seadResource.h b/include/resource/seadResource.h index fc2e4e02..9267d6a0 100644 --- a/include/resource/seadResource.h +++ b/include/resource/seadResource.h @@ -58,6 +58,7 @@ class IndirectResource : public Resource public: IndirectResource(); + ~IndirectResource() override; void create(sead::ReadStream* stream, u32 size, sead::Heap* heap); diff --git a/modules/src/devenv/seadFontMgr.cpp b/modules/src/devenv/seadFontMgr.cpp deleted file mode 100644 index 4c64df75..00000000 --- a/modules/src/devenv/seadFontMgr.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "devenv/seadFontMgr.h" - -namespace sead -{ -FontBase::~FontBase() = default; -} // namespace sead diff --git a/modules/src/gfx/seadFrameBuffer.cpp b/modules/src/gfx/seadFrameBuffer.cpp index de45507f..acf30486 100644 --- a/modules/src/gfx/seadFrameBuffer.cpp +++ b/modules/src/gfx/seadFrameBuffer.cpp @@ -2,8 +2,6 @@ namespace sead { -LogicalFrameBuffer::~LogicalFrameBuffer() = default; - FrameBuffer::~FrameBuffer() = default; void FrameBuffer::clearMRT(DrawContext*, u32, const Color4f&) const {} diff --git a/modules/src/gfx/seadProjection.cpp b/modules/src/gfx/seadProjection.cpp index 9cd07d2d..622b0425 100644 --- a/modules/src/gfx/seadProjection.cpp +++ b/modules/src/gfx/seadProjection.cpp @@ -12,6 +12,8 @@ Projection::Projection() mDeviceZOffset = Graphics::sDefaultDeviceZOffset; } +Projection::~Projection() = default; + void Projection::updateAttributesForDirectProjection() {} const Matrix44f& Projection::getProjectionMatrix() const diff --git a/modules/src/math/seadMathCalcCommon.cpp b/modules/src/math/seadMathCalcCommon.cpp index 557ffc59..61690a75 100644 --- a/modules/src/math/seadMathCalcCommon.cpp +++ b/modules/src/math/seadMathCalcCommon.cpp @@ -608,9 +608,8 @@ const MathCalcCommon::LogSample MathCalcCommon::cLogTbl[256 + 1]{ {0.6911921501159668, 0.0019550349097698927}, {0.6931471824645996, 0.0019512200960889459}, }; - template -T MathCalcCommon::gcd(T x, T y) +T gcdImpl_(T x, T y) { if (x == 0 || y == 0) return 0; @@ -627,17 +626,36 @@ T MathCalcCommon::gcd(T x, T y) } template -T MathCalcCommon::lcm(T x, T y) +T lcmImpl_(T x, T y) { if (x == 0 || y == 0) return 0; - return x / gcd(x, y) * y; + return x / gcdImpl_(x, y) * y; +} + +template <> +s32 MathCalcCommon::gcd(s32 x, s32 y) +{ + return gcdImpl_(x, y); +} + +template <> +s32 MathCalcCommon::lcm(s32 x, s32 y) +{ + return lcmImpl_(x, y); +} + +template <> +u32 MathCalcCommon::gcd(u32 x, u32 y) +{ + return gcdImpl_(x, y); } -template s32 MathCalcCommon::gcd(s32 x, s32 y); -template s32 MathCalcCommon::lcm(s32 x, s32 y); -template u32 MathCalcCommon::gcd(u32 x, u32 y); -template u32 MathCalcCommon::lcm(u32 x, u32 y); +template <> +u32 MathCalcCommon::lcm(u32 x, u32 y) +{ + return lcmImpl_(x, y); +} template <> u32 MathCalcCommon::atanIdx_(f32 t) @@ -684,9 +702,28 @@ f32 MathCalcCommon::logTable(f32 x) return cLogTbl[index].log_val + (cLogTbl[index].log_delta * rest) + (more * ln2()); } -template s64 MathCalcCommon::gcd(s64 x, s64 y); -template s64 MathCalcCommon::lcm(s64 x, s64 y); -template u64 MathCalcCommon::gcd(u64 x, u64 y); -template u64 MathCalcCommon::lcm(u64 x, u64 y); +template <> +s64 MathCalcCommon::gcd(s64 x, s64 y) +{ + return gcdImpl_(x, y); +} + +template <> +s64 MathCalcCommon::lcm(s64 x, s64 y) +{ + return lcmImpl_(x, y); +} + +template <> +u64 MathCalcCommon::gcd(u64 x, u64 y) +{ + return gcdImpl_(x, y); +} + +template <> +u64 MathCalcCommon::lcm(u64 x, u64 y) +{ + return lcmImpl_(x, y); +} } // namespace sead diff --git a/modules/src/prim/seadStringBuilder.cpp b/modules/src/prim/seadStringBuilder.cpp index e02bb842..cb89b2a0 100644 --- a/modules/src/prim/seadStringBuilder.cpp +++ b/modules/src/prim/seadStringBuilder.cpp @@ -6,6 +6,52 @@ namespace sead { +template +s32 StringBuilderBase::copyImpl_(const T* src, s32 copy_length) +{ + T* dst = mBuffer; + const s32 buffer_size = mBufferSize; + SEAD_ASSERT_MSG(src, "str must not be null"); + if (dst == src) + return 0; + + if (copy_length == -1) + copy_length = calcStrLength_(src); + + if (copy_length >= buffer_size) + { + SEAD_ASSERT_MSG(false, "Buffer overflow. (Buffer Size: %d, Copy Size: %d)", buffer_size, + copy_length); + copy_length = buffer_size - 1; + } + + if (copy_length >= 1) + { + MemUtil::copy(dst, src, copy_length * sizeof(T)); + dst[copy_length] = SafeStringBase::cNullChar; + } + else + { + copy_length = 0; + *dst = SafeStringBase::cNullChar; + } + + mLength = copy_length; + return copy_length; +} + +template <> +s32 StringBuilder::copy(const char* src, s32 copy_length) +{ + return copyImpl_(src, copy_length); +} + +template <> +s32 WStringBuilder::copy(const char16* src, s32 copy_length) +{ + return copyImpl_(src, copy_length); +} + template <> StringBuilder* StringBuilder::create(s32 buffer_size, Heap* heap, s32 alignment) { @@ -18,8 +64,8 @@ WStringBuilder* WStringBuilder::create(s32 buffer_size, Heap* heap, s32 alignmen return createImpl_(buffer_size, heap, alignment); } -template -StringBuilderBase* StringBuilderBase::create(const T* str, Heap* heap, s32 alignment) +template <> +StringBuilder* StringBuilder::create(const char* str, Heap* heap, s32 alignment) { const s32 len = calcStrLength_(str); auto* builder = createImpl_(len + 1, heap, alignment); @@ -27,8 +73,14 @@ StringBuilderBase* StringBuilderBase::create(const T* str, Heap* heap, s32 return builder; } -template StringBuilder* StringBuilder::create(const char* str, Heap* heap, s32 alignment); -template WStringBuilder* WStringBuilder::create(const char16* str, Heap* heap, s32 alignment); +template <> +WStringBuilder* WStringBuilder::create(const char16* str, Heap* heap, s32 alignment) +{ + const s32 len = calcStrLength_(str); + auto* builder = createImpl_(len + 1, heap, alignment); + builder->copy(str, len); + return builder; +} template StringBuilderBase* StringBuilderBase::createImpl_(s32 buffer_size, Heap* heap, s32 alignment) @@ -59,7 +111,7 @@ StringBuilderBase* StringBuilderBase::createImpl_(s32 buffer_size, Heap* h } template -bool StringBuilderBase::endsWith(const T* suffix) const +bool StringBuilderBase::endsWithImpl_(const T* suffix) const { const s32 sub_str_len = calcStrLength_(suffix); if (sub_str_len == 0) @@ -79,48 +131,20 @@ bool StringBuilderBase::endsWith(const T* suffix) const return true; } -template bool StringBuilder::endsWith(const char* suffix) const; -template bool WStringBuilder::endsWith(const char16* suffix) const; - -template -s32 StringBuilderBase::copy(const T* src, s32 copy_length) +template <> +bool StringBuilder::endsWith(const char* suffix) const { - T* dst = mBuffer; - const s32 buffer_size = mBufferSize; - SEAD_ASSERT_MSG(src, "str must not be null"); - if (dst == src) - return 0; - - if (copy_length == -1) - copy_length = calcStrLength_(src); - - if (copy_length >= buffer_size) - { - SEAD_ASSERT_MSG(false, "Buffer overflow. (Buffer Size: %d, Copy Size: %d)", buffer_size, - copy_length); - copy_length = buffer_size - 1; - } - - if (copy_length >= 1) - { - MemUtil::copy(dst, src, copy_length * sizeof(T)); - dst[copy_length] = SafeStringBase::cNullChar; - } - else - { - copy_length = 0; - *dst = SafeStringBase::cNullChar; - } - - mLength = copy_length; - return copy_length; + return endsWithImpl_(suffix); } -template s32 StringBuilder::copy(const char* src, s32 copy_length); -template s32 WStringBuilder::copy(const char16* src, s32 copy_length); +template <> +bool WStringBuilder::endsWith(const char16* suffix) const +{ + return endsWithImpl_(suffix); +} template -s32 StringBuilderBase::copyAt(s32 at_, const T* src, s32 copy_length) +s32 StringBuilderBase::copyAtImpl_(s32 at, const T* src, s32 copy_length) { T* dst = getMutableStringTop_(); const s32 buffer_size = mBufferSize; @@ -131,13 +155,12 @@ s32 StringBuilderBase::copyAt(s32 at_, const T* src, s32 copy_length) copy_length = calcStrLength_(src); s32 len = this->calcLength(); - s32 at = at_; - if (at_ < 0) + if (at < 0) { - const s32 at_new = len + at_ + 1; + const s32 at_new = len + at + 1; if (at_new < 0) { - SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at_, -len - 1, len); + SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at, -len - 1, len); at = 0; goto check_buffer_overflow; } @@ -146,7 +169,7 @@ s32 StringBuilderBase::copyAt(s32 at_, const T* src, s32 copy_length) if (len < at) { - SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at_, -len - 1, len); + SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at, -len - 1, len); copy_length = 0; return copy_length; } @@ -171,11 +194,20 @@ s32 StringBuilderBase::copyAt(s32 at_, const T* src, s32 copy_length) return copy_length; } -template s32 StringBuilder::copyAt(s32 at, const char* src, s32 copy_length); -template s32 WStringBuilder::copyAt(s32 at, const char16* src, s32 copy_length); +template <> +s32 StringBuilder::copyAt(s32 at, const char* src, s32 copy_length) +{ + return copyAtImpl_(at, src, copy_length); +} + +template <> +s32 WStringBuilder::copyAt(s32 at, const char16* src, s32 copy_length) +{ + return copyAtImpl_(at, src, copy_length); +} template -s32 StringBuilderBase::cutOffCopy(const T* src, s32 copy_length) +s32 StringBuilderBase::cutOffCopyImpl_(const T* src, s32 copy_length) { T* dst = mBuffer; const s32 buffer_size = mBufferSize; @@ -204,11 +236,20 @@ s32 StringBuilderBase::cutOffCopy(const T* src, s32 copy_length) return copy_length; } -template s32 StringBuilder::cutOffCopy(const char* src, s32 copy_length); -template s32 WStringBuilder::cutOffCopy(const char16* src, s32 copy_length); +template <> +s32 StringBuilder::cutOffCopy(const char* src, s32 copy_length) +{ + return cutOffCopyImpl_(src, copy_length); +} + +template <> +s32 WStringBuilder::cutOffCopy(const char16* src, s32 copy_length) +{ + return cutOffCopyImpl_(src, copy_length); +} template -s32 StringBuilderBase::cutOffCopyAt(s32 at_, const T* src, s32 copy_length) +s32 StringBuilderBase::cutOffCopyAtImpl_(s32 at, const T* src, s32 copy_length) { T* dst = getMutableStringTop_(); const s32 buffer_size = mBufferSize; @@ -219,13 +260,12 @@ s32 StringBuilderBase::cutOffCopyAt(s32 at_, const T* src, s32 copy_length) copy_length = calcStrLength_(src); s32 len = this->calcLength(); - s32 at = at_; - if (at_ < 0) + if (at < 0) { - const s32 at_new = len + at_ + 1; + const s32 at_new = len + at + 1; if (at_new < 0) { - SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at_, -len - 1, len); + SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at, -len - 1, len); at = 0; goto check_buffer_overflow; } @@ -234,7 +274,7 @@ s32 StringBuilderBase::cutOffCopyAt(s32 at_, const T* src, s32 copy_length) if (len < at) { - SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at_, -len - 1, len); + SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at, -len - 1, len); copy_length = 0; return copy_length; } @@ -255,11 +295,20 @@ s32 StringBuilderBase::cutOffCopyAt(s32 at_, const T* src, s32 copy_length) return copy_length; } -template s32 StringBuilder::cutOffCopyAt(s32 at, const char* src, s32 copy_length); -template s32 WStringBuilder::cutOffCopyAt(s32 at, const char16* src, s32 copy_length); +template <> +s32 StringBuilder::cutOffCopyAt(s32 at, const char* src, s32 copy_length) +{ + return cutOffCopyAtImpl_(at, src, copy_length); +} + +template <> +s32 WStringBuilder::cutOffCopyAt(s32 at, const char16* src, s32 copy_length) +{ + return cutOffCopyAtImpl_(at, src, copy_length); +} template -s32 StringBuilderBase::copyAtWithTerminate(s32 at_, const T* src, s32 copy_length) +s32 StringBuilderBase::copyAtWithTerminateImpl_(s32 at, const T* src, s32 copy_length) { T* dst = getMutableStringTop_(); const s32 buffer_size = mBufferSize; @@ -270,13 +319,12 @@ s32 StringBuilderBase::copyAtWithTerminate(s32 at_, const T* src, s32 copy_le copy_length = calcStrLength_(src); s32 len = this->calcLength(); - s32 at = at_; - if (at_ < 0) + if (at < 0) { - const s32 at_new = len + at_ + 1; + const s32 at_new = len + at + 1; if (at_new < 0) { - SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at_, -len - 1, len); + SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at, -len - 1, len); at = 0; goto check_buffer_overflow; } @@ -285,7 +333,7 @@ s32 StringBuilderBase::copyAtWithTerminate(s32 at_, const T* src, s32 copy_le if (len < at) { - SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at_, -len - 1, len); + SEAD_ASSERT_MSG(false, "at(%d) out of range[%d, %d]", at, -len - 1, len); copy_length = 0; return copy_length; } @@ -309,11 +357,20 @@ s32 StringBuilderBase::copyAtWithTerminate(s32 at_, const T* src, s32 copy_le return copy_length; } -template s32 StringBuilder::copyAtWithTerminate(s32 at, const char* src, s32 copy_length); -template s32 WStringBuilder::copyAtWithTerminate(s32 at, const char16* src, s32 copy_length); +template <> +s32 StringBuilder::copyAtWithTerminate(s32 at, const char* src, s32 copy_length) +{ + return copyAtWithTerminateImpl_(at, src, copy_length); +} -template -s32 StringBuilderBase::format(const T* format, ...) +template <> +s32 WStringBuilder::copyAtWithTerminate(s32 at, const char16* src, s32 copy_length) +{ + return copyAtWithTerminateImpl_(at, src, copy_length); +} + +template <> +s32 StringBuilder::format(const char* format, ...) { std::va_list args; va_start(args, format); @@ -322,8 +379,15 @@ s32 StringBuilderBase::format(const T* format, ...) return ret; } -template s32 StringBuilder::format(const char* format, ...); -template s32 WStringBuilder::format(const char16* format, ...); +template <> +s32 WStringBuilder::format(const char16* format, ...) +{ + std::va_list args; + va_start(args, format); + s32 ret = formatV(format, args); + va_end(args); + return ret; +} template <> s32 StringBuilder::formatImpl_(char* s, s32 n, const char* format, va_list args) @@ -342,8 +406,8 @@ s32 WStringBuilder::formatImpl_(char16* s, s32 n, const char16* format, va_list return n - 1; } -template -s32 StringBuilderBase::appendWithFormat(const T* format, ...) +template <> +s32 StringBuilder::appendWithFormat(const char* format, ...) { std::va_list args; va_start(args, format); @@ -352,11 +416,18 @@ s32 StringBuilderBase::appendWithFormat(const T* format, ...) return ret; } -template s32 StringBuilder::appendWithFormat(const char* format, ...); -template s32 WStringBuilder::appendWithFormat(const char16* format, ...); +template <> +s32 WStringBuilder::appendWithFormat(const char16* format, ...) +{ + std::va_list args; + va_start(args, format); + const s32 ret = appendWithFormatV(format, args); + va_end(args); + return ret; +} template -s32 StringBuilderBase::append(const T* str, s32 append_length) +s32 StringBuilderBase::appendImpl_(const T* str, s32 append_length) { T* dst = getMutableStringTop_(); const s32 buffer_size = mBufferSize; @@ -385,50 +456,62 @@ s32 StringBuilderBase::append(const T* str, s32 append_length) return append_length; } -template s32 StringBuilder::append(const char* str, s32 append_length); -template s32 WStringBuilder::append(const char16* str, s32 append_length); +template <> +s32 StringBuilder::append(const char* str, s32 append_length) +{ + return appendImpl_(str, append_length); +} + +template <> +s32 WStringBuilder::append(const char16* str, s32 append_length) +{ + return appendImpl_(str, append_length); +} // NON_MATCHING: regalloc differences template -s32 appendImpl_(T* buffer_, s32* length_, const s32 buffer_size_, T c, s32 num) +s32 StringBuilderBase::appendImpl_(T* buffer, s32* length_, const s32 buffer_size, T c, s32 num) { + if (num < 0) + { + SEAD_ASSERT_MSG(false, "append error. num < 0, num = %d", num); + return 0; + } + + if (num == 0) + return 0; + const s32 length = *length_; - if (buffer_size_ <= num + length) + if (buffer_size <= num + length) { SEAD_ASSERT_MSG(false, "Buffer overflow. (Buffer Size: %d, Length: %d, Num: %d)", - buffer_size_, length, num); - num = buffer_size_ - length - 1; + buffer_size, length, num); + num = buffer_size - length - 1; } for (s32 i = 0; i < num; ++i) - buffer_[length + i] = c; + buffer[length + i] = c; - buffer_[length + num] = SafeStringBase::cNullChar; + buffer[length + num] = SafeStringBase::cNullChar; *length_ = length + num; return num; } -template -s32 StringBuilderBase::append(T c, s32 num) +template <> +s32 StringBuilder::append(char c, s32 num) { - if (num < 0) - { - SEAD_ASSERT_MSG(false, "append error. num < 0, num = %d", num); - return 0; - } - - if (num == 0) - return 0; - return appendImpl_(mBuffer, &mLength, mBufferSize, c, num); } -template s32 StringBuilder::append(char c, s32 n); -template s32 WStringBuilder::append(char16 c, s32 n); +template <> +s32 WStringBuilder::append(char16 c, s32 num) +{ + return appendImpl_(mBuffer, &mLength, mBufferSize, c, num); +} template -s32 StringBuilderBase::chop(s32 chop_num) +s32 StringBuilderBase::chopImpl_(s32 chop_num) { s32 length = this->calcLength(); T* buffer = getMutableStringTop_(); @@ -455,11 +538,20 @@ s32 StringBuilderBase::chop(s32 chop_num) return chop_num; } -template s32 StringBuilder::chop(s32 chop_num); -template s32 WStringBuilder::chop(s32 chop_num); +template <> +s32 StringBuilder::chop(s32 chop_num) +{ + return chopImpl_(chop_num); +} + +template <> +s32 WStringBuilder::chop(s32 chop_num) +{ + return chopImpl_(chop_num); +} template -s32 StringBuilderBase::chopMatchedChar(T c) +s32 StringBuilderBase::chopMatchedCharImpl_(T c) { const s32 length = this->calcLength(); if (length < 1) @@ -476,11 +568,20 @@ s32 StringBuilderBase::chopMatchedChar(T c) return 0; } -template s32 StringBuilder::chopMatchedChar(char c); -template s32 WStringBuilder::chopMatchedChar(char16 c); +template <> +s32 StringBuilder::chopMatchedChar(char c) +{ + return chopMatchedCharImpl_(c); +} + +template <> +s32 WStringBuilder::chopMatchedChar(char16 c) +{ + return chopMatchedCharImpl_(c); +} template -s32 StringBuilderBase::chopMatchedChar(const T* characters) +s32 StringBuilderBase::chopMatchedCharImpl_(const T* characters) { const s32 length = this->calcLength(); if (length < 1) @@ -500,11 +601,20 @@ s32 StringBuilderBase::chopMatchedChar(const T* characters) return 0; } -template s32 StringBuilder::chopMatchedChar(const char* characters); -template s32 WStringBuilder::chopMatchedChar(const char16* characters); +template <> +s32 StringBuilder::chopMatchedChar(const char* characters) +{ + return chopMatchedCharImpl_(characters); +} + +template <> +s32 WStringBuilder::chopMatchedChar(const char16* characters) +{ + return chopMatchedCharImpl_(characters); +} template -s32 StringBuilderBase::chopUnprintableAsciiChar() +s32 StringBuilderBase::chopUnprintableAsciiCharImpl_() { const s32 length = this->calcLength(); if (length < 1) @@ -521,11 +631,20 @@ s32 StringBuilderBase::chopUnprintableAsciiChar() return 0; } -template s32 StringBuilder::chopUnprintableAsciiChar(); -template s32 WStringBuilder::chopUnprintableAsciiChar(); +template <> +s32 StringBuilder::chopUnprintableAsciiChar() +{ + return chopUnprintableAsciiCharImpl_(); +} + +template <> +s32 WStringBuilder::chopUnprintableAsciiChar() +{ + return chopUnprintableAsciiCharImpl_(); +} template -s32 StringBuilderBase::rstrip(const T* characters) +s32 StringBuilderBase::rstripImpl_(const T* characters) { const s32 length = this->calcLength(); if (length <= 0) @@ -552,12 +671,20 @@ s32 StringBuilderBase::rstrip(const T* characters) return length - new_length; } -template s32 StringBuilder::rstrip(const char* characters); -template s32 WStringBuilder::rstrip(const char16* characters); +template <> +s32 StringBuilder::rstrip(const char* characters) +{ + return rstripImpl_(characters); +} + +template <> +s32 WStringBuilder::rstrip(const char16* characters) +{ + return rstripImpl_(characters); +} -// NON_MATCHING: equivalent, two instruction reorders template -s32 StringBuilderBase::rstripUnprintableAsciiChars() +s32 StringBuilderBase::rstripUnprintableAsciiCharsImpl_() { const s32 length = this->calcLength(); if (length <= 0) @@ -577,11 +704,19 @@ s32 StringBuilderBase::rstripUnprintableAsciiChars() return ret; } -template s32 StringBuilder::rstripUnprintableAsciiChars(); -template s32 WStringBuilder::rstripUnprintableAsciiChars(); +template <> +s32 StringBuilder::rstripUnprintableAsciiChars() +{ + return rstripUnprintableAsciiCharsImpl_(); +} +template <> +s32 WStringBuilder::rstripUnprintableAsciiChars() +{ + return rstripUnprintableAsciiCharsImpl_(); +} template -s32 StringBuilderBase::trim(s32 trim_length) +s32 StringBuilderBase::trimImpl_(s32 trim_length) { T* mutableString = getMutableStringTop_(); @@ -603,11 +738,20 @@ s32 StringBuilderBase::trim(s32 trim_length) return trim_length; } -template s32 StringBuilder::trim(s32 trim_length); -template s32 WStringBuilder::trim(s32 trim_length); +template <> +s32 StringBuilder::trim(s32 trim_length) +{ + return trimImpl_(trim_length); +} + +template <> +s32 WStringBuilder::trim(s32 trim_length) +{ + return trimImpl_(trim_length); +} template -s32 StringBuilderBase::trimMatchedString(const T* str) +s32 StringBuilderBase::trimMatchedStringImpl_(const T* str) { T* buffer = getMutableStringTop_(); const s32 length = this->calcLength(); @@ -630,11 +774,20 @@ s32 StringBuilderBase::trimMatchedString(const T* str) return new_length; } -template s32 StringBuilder::trimMatchedString(const char* str); -template s32 WStringBuilder::trimMatchedString(const char16* str); +template <> +s32 StringBuilder::trimMatchedString(const char* str) +{ + return trimMatchedStringImpl_(str); +} + +template <> +s32 WStringBuilder::trimMatchedString(const char16* str) +{ + return trimMatchedStringImpl_(str); +} template -s32 StringBuilderBase::replaceChar(T old_char, T new_char) +s32 StringBuilderBase::replaceCharImpl_(T old_char, T new_char) { const s32 length = this->calcLength(); T* buffer = getMutableStringTop_(); @@ -651,12 +804,21 @@ s32 StringBuilderBase::replaceChar(T old_char, T new_char) return replaced_count; } -template s32 StringBuilder::replaceChar(char old_char, char new_char); -template s32 WStringBuilder::replaceChar(char16 old_char, char16 new_char); +template <> +s32 StringBuilder::replaceChar(char old_char, char new_char) +{ + return replaceCharImpl_(old_char, new_char); +} + +template <> +s32 WStringBuilder::replaceChar(char16 old_char, char16 new_char) +{ + return replaceCharImpl_(old_char, new_char); +} template -s32 StringBuilderBase::replaceCharList(const SafeStringBase& old_chars, - const SafeStringBase& new_chars) +s32 StringBuilderBase::replaceCharListImpl_(const SafeStringBase& old_chars, + const SafeStringBase& new_chars) { T* buffer = getMutableStringTop_(); const s32 length = this->calcLength(); @@ -705,10 +867,17 @@ s32 StringBuilderBase::replaceCharList(const SafeStringBase& old_chars, return replaced_count; } -template s32 StringBuilder::replaceCharList(const SafeString& old_chars, - const SafeString& new_chars); -template s32 WStringBuilder::replaceCharList(const WSafeString& old_chars, - const WSafeString& new_chars); +template <> +s32 StringBuilder::replaceCharList(const SafeString& old_chars, const SafeString& new_chars) +{ + return replaceCharListImpl_(old_chars, new_chars); +} + +template <> +s32 WStringBuilder::replaceCharList(const WSafeString& old_chars, const WSafeString& new_chars) +{ + return replaceCharListImpl_(old_chars, new_chars); +} template template @@ -745,7 +914,7 @@ s32 StringBuilderBase::convertFromOtherType_(const OtherType* src, s32 src_si } template -s32 StringBuilderBase::convertFromMultiByteString(const char* str, s32 str_length) +s32 StringBuilderBase::convertFromMultiByteStringImpl_(const char* str, s32 str_length) { if constexpr (std::is_same()) return copy(str, str_length); @@ -754,7 +923,7 @@ s32 StringBuilderBase::convertFromMultiByteString(const char* str, s32 str_le } template -s32 StringBuilderBase::convertFromWideCharString(const char16* str, s32 str_length) +s32 StringBuilderBase::convertFromWideCharStringImpl_(const char16* str, s32 str_length) { if constexpr (std::is_same()) return copy(str, str_length); @@ -762,13 +931,29 @@ s32 StringBuilderBase::convertFromWideCharString(const char16* str, s32 str_l return convertFromOtherType_(str, str_length); } -template s32 StringBuilder::convertFromMultiByteString(const char* str, s32 str_length); -template s32 StringBuilder::convertFromWideCharString(const char16* str, s32 str_length); -template s32 WStringBuilder::convertFromMultiByteString(const char* str, s32 str_length); -template s32 WStringBuilder::convertFromWideCharString(const char16* str, s32 str_length); +template <> +s32 StringBuilder::convertFromMultiByteString(const char* str, s32 str_length) +{ + return convertFromMultiByteStringImpl_(str, str_length); +} +template <> +s32 StringBuilder::convertFromWideCharString(const char16* str, s32 str_length) +{ + return convertFromWideCharStringImpl_(str, str_length); +} +template <> +s32 WStringBuilder::convertFromMultiByteString(const char* str, s32 str_length) +{ + return convertFromMultiByteStringImpl_(str, str_length); +} +template <> +s32 WStringBuilder::convertFromWideCharString(const char16* str, s32 str_length) +{ + return convertFromWideCharStringImpl_(str, str_length); +} template -s32 StringBuilderBase::cutOffAppend(const T* str, s32 append_length) +s32 StringBuilderBase::cutOffAppendImpl_(const T* str, s32 append_length) { T* dst = getMutableStringTop_(); const s32 buffer_size = mBufferSize; @@ -793,11 +978,20 @@ s32 StringBuilderBase::cutOffAppend(const T* str, s32 append_length) return append_length; } -template s32 StringBuilder::cutOffAppend(const char* str, s32 append_length); -template s32 WStringBuilder::cutOffAppend(const char16* str, s32 append_length); +template <> +s32 StringBuilder::cutOffAppend(const char* str, s32 append_length) +{ + return cutOffAppendImpl_(str, append_length); +} + +template <> +s32 WStringBuilder::cutOffAppend(const char16* str, s32 append_length) +{ + return cutOffAppendImpl_(str, append_length); +} template -s32 StringBuilderBase::cutOffAppend(T c, s32 num) +s32 StringBuilderBase::cutOffAppendImpl_(T c, s32 num) { if (num < 0) { @@ -826,12 +1020,21 @@ s32 StringBuilderBase::cutOffAppend(T c, s32 num) return num; } -template s32 StringBuilder::cutOffAppend(char c, s32 num); -template s32 WStringBuilder::cutOffAppend(char16 c, s32 num); +template <> +s32 StringBuilder::cutOffAppend(char c, s32 num) +{ + return cutOffAppendImpl_(c, num); +} + +template <> +s32 WStringBuilder::cutOffAppend(char16 c, s32 num) +{ + return cutOffAppendImpl_(c, num); +} // NON_MATCHING: operands to some `add` instructions are swapped template -s32 StringBuilderBase::prepend(const T* str, s32 prepend_length) +s32 StringBuilderBase::prependImpl_(const T* str, s32 prepend_length) { T* buffer = getMutableStringTop_(); const s32 buffer_size = mBufferSize; @@ -867,12 +1070,21 @@ s32 StringBuilderBase::prepend(const T* str, s32 prepend_length) return move_length + prepend_length - length; } -template s32 StringBuilder::prepend(const char* str, s32 prepend_length); -template s32 WStringBuilder::prepend(const char16* str, s32 prepend_length); +template <> +s32 StringBuilder::prepend(const char* str, s32 prepend_length) +{ + return prependImpl_(str, prepend_length); +} + +template <> +s32 WStringBuilder::prepend(const char16* str, s32 prepend_length) +{ + return prependImpl_(str, prepend_length); +} // NON_MATCHING: same regalloc issue as append() template -s32 StringBuilderBase::prepend(T c, s32 num) +s32 StringBuilderBase::prependImpl_(T c, s32 num) { if (num < 0) { @@ -907,6 +1119,15 @@ s32 StringBuilderBase::prepend(T c, s32 num) return num + move_length - length; } -template s32 StringBuilder::prepend(char c, s32 length); -template s32 WStringBuilder::prepend(char16_t c, s32 length); +template <> +s32 StringBuilder::prepend(char c, s32 length) +{ + return prependImpl_(c, length); +} + +template <> +s32 WStringBuilder::prepend(char16_t c, s32 length) +{ + return prependImpl_(c, length); +} } // namespace sead diff --git a/modules/src/resource/seadResource.cpp b/modules/src/resource/seadResource.cpp index 29806131..b874fd80 100644 --- a/modules/src/resource/seadResource.cpp +++ b/modules/src/resource/seadResource.cpp @@ -38,6 +38,7 @@ void DirectResource::create(u8* buffer, u32 bufferSize, u32 allocSize, bool allo } IndirectResource::IndirectResource() = default; +IndirectResource::~IndirectResource() = default; void IndirectResource::create(sead::ReadStream* stream, u32 size, sead::Heap* heap) {