diff --git a/openVulkanoCpp/Data/Containers/String.hpp b/openVulkanoCpp/Data/Containers/String.hpp new file mode 100644 index 0000000..1440915 --- /dev/null +++ b/openVulkanoCpp/Data/Containers/String.hpp @@ -0,0 +1,71 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include + +namespace OpenVulkano +{ + class String final + { + public: + String() = default; + String(const char* str) : m_string(str) {} + String(const std::string& str) : m_string(str) {} + String(const String& other) : m_string(other.m_string) {} + String(String&& other) noexcept : m_string(std::move(other.m_string)) {} + ~String() = default; + + template String& operator=(const T& other) + { + m_string = other; + return *this; + } + template String& operator=(T&& other) + { + m_string = std::move(other); + return *this; + } + + template String& operator+=(const T& other) + { + m_string += other; + return *this; + } + template String operator+(const T& other) const { return m_string + other; } + String operator+(const String& other) const { return m_string + other.m_string; } + + template bool operator==(const T& other) const { return m_string == other; } + template bool operator!=(const T& other) const { return m_string != other; } + + operator std::string() const { return m_string; } + const char* CStr() const { return m_string.c_str(); } + const char* Data() { return m_string.data(); } + size_t Length() const { return m_string.length(); } + size_t Size() const { return m_string.size(); } + + char& Front() { return m_string.front(); } + char& Back() { return m_string.back(); } + void PopBack() { m_string.pop_back(); } + void Clear() { m_string.clear(); } + + size_t FindStartIndexOf(const String& str) const { return m_string.find(str); } + + String& Trim() noexcept + { + size_t start = m_string.find_first_not_of(" \t\n"); + size_t end = m_string.find_last_not_of(" \t\n"); + m_string = m_string.substr(start, end - start + 1); + return *this; + } + + private: + std::string m_string; + }; + + template String operator+(const T& lhs, const String& rhs) noexcept { return lhs + rhs; } +} diff --git a/openVulkanoCpp/Host/GraphicsAppManager.cpp b/openVulkanoCpp/Host/GraphicsAppManager.cpp index 918a361..e49123b 100644 --- a/openVulkanoCpp/Host/GraphicsAppManager.cpp +++ b/openVulkanoCpp/Host/GraphicsAppManager.cpp @@ -87,7 +87,7 @@ namespace OpenVulkano void GraphicsAppManager::UpdateCappedFpsInfo(int32_t newFpsCap) { - if (newFpsCap < 0) + if (newFpsCap <= 0) { cappedFrameTime = std::chrono::microseconds(0); } diff --git a/tests/StringTest.cpp b/tests/StringTest.cpp new file mode 100644 index 0000000..717ff4c --- /dev/null +++ b/tests/StringTest.cpp @@ -0,0 +1,89 @@ +/* +* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#include + +#include "Data/Containers/String.hpp" + +using namespace OpenVulkano; + +TEST_CASE("String") +{ + SECTION("Constructors") + { + String str1; + REQUIRE(str1 == ""); + + String str2("Hello"); + REQUIRE(str2 == "Hello"); + + String str3(std::string("World")); + REQUIRE(str3 == "World"); + + String str4(str2); + REQUIRE(str4 == "Hello"); + + String str5(std::move(str3)); + REQUIRE(str5 == "World"); + } + + SECTION("Assignment") + { + String str1; + str1 = "Hello"; + REQUIRE(str1 == "Hello"); + + String str2; + str2 = std::string("World"); + REQUIRE(str2 == "World"); + + String str3; + str3 = str1; + REQUIRE(str3 == "Hello"); + + String str4; + str4 = std::move(str2); + REQUIRE(str4 == "World"); + } + + SECTION("Concatenation") + { + String str1("Hello"); + str1 += " World"; + REQUIRE(str1 == "Hello World"); + + String str2("Hello"); + String str3 = str2 + " World"; + REQUIRE(str3 == "Hello World"); + + String str4("Hello"); + str4 += std::string(" World"); + REQUIRE(str4 == "Hello World"); + + String str5("Hello"); + String str6 = str5 + std::string(" World"); + REQUIRE(str6 == "Hello World"); + + String str7("Hello"); + str7 += String(" World"); + REQUIRE(str7 == "Hello World"); + + String str8("Hello"); + String str9 = str8 + String(" World"); + REQUIRE(str9 == "Hello World"); + } + + SECTION("Comparison") + { + String str1("Hello"); + REQUIRE(str1 == "Hello"); + REQUIRE(str1 != "World"); + + String str2("World"); + REQUIRE(str2 == "World"); + REQUIRE(str2 != "Hello"); + } +} \ No newline at end of file