billboard example error fix + string wrapper first implementation
This commit is contained in:
71
openVulkanoCpp/Data/Containers/String.hpp
Normal file
71
openVulkanoCpp/Data/Containers/String.hpp
Normal file
@@ -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 <string>
|
||||
|
||||
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<typename T> String& operator=(const T& other)
|
||||
{
|
||||
m_string = other;
|
||||
return *this;
|
||||
}
|
||||
template<typename T> String& operator=(T&& other)
|
||||
{
|
||||
m_string = std::move(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T> String& operator+=(const T& other)
|
||||
{
|
||||
m_string += other;
|
||||
return *this;
|
||||
}
|
||||
template<typename T> String operator+(const T& other) const { return m_string + other; }
|
||||
String operator+(const String& other) const { return m_string + other.m_string; }
|
||||
|
||||
template<typename T> bool operator==(const T& other) const { return m_string == other; }
|
||||
template<typename T> 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<typename T> String operator+(const T& lhs, const String& rhs) noexcept { return lhs + rhs; }
|
||||
}
|
||||
Reference in New Issue
Block a user