aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'app/source/Cplt/Utils')
-rw-r--r--app/source/Cplt/Utils/Color.hpp66
-rw-r--r--app/source/Cplt/Utils/Hash.hpp3
-rw-r--r--app/source/Cplt/Utils/IO/Archive.cpp9
-rw-r--r--app/source/Cplt/Utils/IO/Archive.hpp3
-rw-r--r--app/source/Cplt/Utils/IO/CstdioFile.cpp6
-rw-r--r--app/source/Cplt/Utils/IO/CstdioFile.hpp3
-rw-r--r--app/source/Cplt/Utils/IO/DataStream.cpp108
-rw-r--r--app/source/Cplt/Utils/IO/DataStream.hpp69
-rw-r--r--app/source/Cplt/Utils/IO/FileStream.hpp15
-rw-r--r--app/source/Cplt/Utils/IO/Helper.hpp6
-rw-r--r--app/source/Cplt/Utils/IO/StringIntegration.hpp15
-rw-r--r--app/source/Cplt/Utils/IO/TslArrayIntegration.hpp9
-rw-r--r--app/source/Cplt/Utils/IO/TslRobinIntegration.hpp18
-rw-r--r--app/source/Cplt/Utils/IO/UuidIntegration.hpp9
-rw-r--r--app/source/Cplt/Utils/IO/VectorIntegration.hpp9
-rw-r--r--app/source/Cplt/Utils/Math.hpp3
-rw-r--r--app/source/Cplt/Utils/RTTI.hpp15
-rw-r--r--app/source/Cplt/Utils/ScopeGuard.hpp12
-rw-r--r--app/source/Cplt/Utils/Sigslot.cpp57
-rw-r--r--app/source/Cplt/Utils/Sigslot.hpp45
-rw-r--r--app/source/Cplt/Utils/Size.hpp12
-rw-r--r--app/source/Cplt/Utils/StandardDirectories.cpp12
-rw-r--r--app/source/Cplt/Utils/Time.cpp6
-rw-r--r--app/source/Cplt/Utils/Variant.hpp12
-rw-r--r--app/source/Cplt/Utils/Vector.hpp36
-rw-r--r--app/source/Cplt/Utils/VectorHash.hpp18
26 files changed, 192 insertions, 384 deletions
diff --git a/app/source/Cplt/Utils/Color.hpp b/app/source/Cplt/Utils/Color.hpp
index 15fe6a1..6d56951 100644
--- a/app/source/Cplt/Utils/Color.hpp
+++ b/app/source/Cplt/Utils/Color.hpp
@@ -9,8 +9,7 @@
#include <cstdint>
#include <limits>
-class RgbaColor
-{
+class RgbaColor {
public:
uint8_t r;
uint8_t g;
@@ -22,36 +21,31 @@ public:
: r{ 255 }
, g{ 255 }
, b{ 255 }
- , a{ 255 }
- {
+ , a{ 255 } {
}
constexpr RgbaColor(float r, float g, float b, float a = 1.0f) noexcept
: r{ static_cast<uint8_t>(r * 255.0f) }
, g{ static_cast<uint8_t>(g * 255.0f) }
, b{ static_cast<uint8_t>(b * 255.0f) }
- , a{ static_cast<uint8_t>(a * 255.0f) }
- {
+ , a{ static_cast<uint8_t>(a * 255.0f) } {
}
constexpr RgbaColor(int r, int g, int b, int a = 255) noexcept
: r{ static_cast<uint8_t>(r & 0xFF) }
, g{ static_cast<uint8_t>(g & 0xFF) }
, b{ static_cast<uint8_t>(b & 0xFF) }
- , a{ static_cast<uint8_t>(a & 0xFF) }
- {
+ , a{ static_cast<uint8_t>(a & 0xFF) } {
}
constexpr RgbaColor(uint32_t rgba) noexcept
: r{ static_cast<uint8_t>((rgba >> 0) & 0xFF) }
, g{ static_cast<uint8_t>((rgba >> 8) & 0xFF) }
, b{ static_cast<uint8_t>((rgba >> 16) & 0xFF) }
- , a{ static_cast<uint8_t>((rgba >> 24) & 0xFF) }
- {
+ , a{ static_cast<uint8_t>((rgba >> 24) & 0xFF) } {
}
- constexpr uint32_t GetScalar() const noexcept
- {
+ constexpr uint32_t GetScalar() const noexcept {
uint32_t res = 0;
res |= r << 24;
res |= g << 16;
@@ -60,41 +54,34 @@ public:
return res;
}
- constexpr void SetScalar(uint32_t scalar) noexcept
- {
+ constexpr void SetScalar(uint32_t scalar) noexcept {
r = (scalar >> 0) & 0xFF;
g = (scalar >> 8) & 0xFF;
b = (scalar >> 16) & 0xFF;
a = (scalar >> 24) & 0xFF;
}
- constexpr float GetNormalizedRed() const noexcept
- {
+ constexpr float GetNormalizedRed() const noexcept {
return r / 255.0f;
}
- constexpr float GetNormalizedGreen() const noexcept
- {
+ constexpr float GetNormalizedGreen() const noexcept {
return g / 255.0f;
}
- constexpr float GetNormalizedBlue() const noexcept
- {
+ constexpr float GetNormalizedBlue() const noexcept {
return b / 255.0f;
}
- constexpr float GetNormalizedAlpha() const noexcept
- {
+ constexpr float GetNormalizedAlpha() const noexcept {
return a / 255.0f;
}
- constexpr Vec4i AsVec4i() const noexcept
- {
+ constexpr Vec4i AsVec4i() const noexcept {
return Vec4i{ r, g, b, a };
}
- constexpr Vec4f AsVec4f() const noexcept
- {
+ constexpr Vec4f AsVec4f() const noexcept {
return Vec4f{
GetNormalizedRed(),
GetNormalizedGreen(),
@@ -103,20 +90,17 @@ public:
};
}
- ImVec4 AsImVec() const
- {
+ ImVec4 AsImVec() const {
auto v = AsVec4f();
return ImVec4{ v.x, v.y, v.z, v.w };
}
- ImColor AsImColor() const
- {
+ ImColor AsImColor() const {
auto v = AsVec4f();
return ImColor{ v.x, v.y, v.z, v.w };
}
- ImU32 AsImU32() const
- {
+ ImU32 AsImU32() const {
ImU32 res;
res |= r << IM_COL32_R_SHIFT;
res |= g << IM_COL32_G_SHIFT;
@@ -125,8 +109,7 @@ public:
return res;
}
- constexpr void SetVec(const Vec4f& vec) noexcept
- {
+ constexpr void SetVec(const Vec4f& vec) noexcept {
r = (uint8_t)(vec.x * 255.0f);
g = (uint8_t)(vec.y * 255.0f);
b = (uint8_t)(vec.z * 255.0f);
@@ -139,8 +122,7 @@ public:
friend constexpr bool operator==(const RgbaColor&, const RgbaColor&) noexcept = default;
};
-class HsvColor
-{
+class HsvColor {
public:
float h;
float s;
@@ -152,24 +134,21 @@ public:
: h{ 0.0f }
, s{ 0.0f }
, v{ 1.0f }
- , a{ 1.0f }
- {
+ , a{ 1.0f } {
}
constexpr HsvColor(float h, float s, float v, float a) noexcept
: h{ h }
, s{ s }
, v{ v }
- , a{ a }
- {
+ , a{ a } {
}
// Forward declaring because cyclic reference between RgbaColor and HsvColor
constexpr RgbaColor ToRgba() const noexcept;
};
-constexpr HsvColor RgbaColor::ToHsv() const noexcept
-{
+constexpr HsvColor RgbaColor::ToHsv() const noexcept {
float fr = GetNormalizedRed();
float fg = GetNormalizedBlue();
float fb = GetNormalizedGreen();
@@ -185,8 +164,7 @@ constexpr HsvColor RgbaColor::ToHsv() const noexcept
return HsvColor(hcv.x, s, hcv.z, fa);
}
-constexpr RgbaColor HsvColor::ToRgba() const noexcept
-{
+constexpr RgbaColor HsvColor::ToRgba() const noexcept {
float r = MathUtils::Abs(h * 6 - 3) - 1;
float g = 2 - MathUtils::Abs(h * 6 - 2);
float b = 2 - MathUtils::Abs(h * 6 - 4);
diff --git a/app/source/Cplt/Utils/Hash.hpp b/app/source/Cplt/Utils/Hash.hpp
index cf7713a..de8e63b 100644
--- a/app/source/Cplt/Utils/Hash.hpp
+++ b/app/source/Cplt/Utils/Hash.hpp
@@ -6,8 +6,7 @@
namespace HashUtils {
template <class T>
-void Combine(size_t& seed, const T& v)
-{
+void Combine(size_t& seed, const T& v) {
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
diff --git a/app/source/Cplt/Utils/IO/Archive.cpp b/app/source/Cplt/Utils/IO/Archive.cpp
index f6e7b27..2be18bc 100644
--- a/app/source/Cplt/Utils/IO/Archive.cpp
+++ b/app/source/Cplt/Utils/IO/Archive.cpp
@@ -10,13 +10,11 @@ constexpr uint8_t kByteOrderMark = []() {
}
}();
-std::span<const uint8_t, 8> DataArchive::GetMagicNumbers()
-{
+std::span<const uint8_t, 8> DataArchive::GetMagicNumbers() {
return std::span<const uint8_t, 8>{ kMagicNumbers };
}
-std::optional<InputDataStream> DataArchive::LoadFile(const std::filesystem::path& path)
-{
+std::optional<InputDataStream> DataArchive::LoadFile(const std::filesystem::path& path) {
InputFileStream fileStream(path);
fileStream.SetReadInSize(1024);
InputDataStream stream(std::move(fileStream));
@@ -42,8 +40,7 @@ std::optional<InputDataStream> DataArchive::LoadFile(const std::filesystem::path
return stream;
}
-std::optional<OutputDataStream> DataArchive::SaveFile(const std::filesystem::path& path)
-{
+std::optional<OutputDataStream> DataArchive::SaveFile(const std::filesystem::path& path) {
OutputFileStream fileStream(path, OutputFileStream::TruncateFile);
fileStream.SetMaxBufferSize(1024);
OutputDataStream stream(std::move(fileStream));
diff --git a/app/source/Cplt/Utils/IO/Archive.hpp b/app/source/Cplt/Utils/IO/Archive.hpp
index 7632f3b..179db25 100644
--- a/app/source/Cplt/Utils/IO/Archive.hpp
+++ b/app/source/Cplt/Utils/IO/Archive.hpp
@@ -7,8 +7,7 @@
#include <optional>
#include <span>
-class DataArchive
-{
+class DataArchive {
public:
static std::span<const uint8_t, 8> GetMagicNumbers();
diff --git a/app/source/Cplt/Utils/IO/CstdioFile.cpp b/app/source/Cplt/Utils/IO/CstdioFile.cpp
index c414dfb..0496fa1 100644
--- a/app/source/Cplt/Utils/IO/CstdioFile.cpp
+++ b/app/source/Cplt/Utils/IO/CstdioFile.cpp
@@ -12,8 +12,7 @@
#endif
namespace CPLT_UNITY_ID {
-auto GetModeString(FileUtils::IoMode mode)
-{
+auto GetModeString(FileUtils::IoMode mode) {
switch (mode) {
case FileUtils::IM_Read: return MODE_STRING("rb");
case FileUtils::IM_WriteAppend: return MODE_STRING("ab");
@@ -25,8 +24,7 @@ auto GetModeString(FileUtils::IoMode mode)
#pragma pop_macro("MODE_STRING")
-FILE* FileUtils::OpenCstdioFile(const std::filesystem::path& path, IoMode mode)
-{
+FILE* FileUtils::OpenCstdioFile(const std::filesystem::path& path, IoMode mode) {
#ifdef _WIN32
// std::filesystem::path::c_str() returns `const wchar_t*` under Windows, because NT uses UTF-16 natively
return _wfopen(path.c_str(), ::GetModeString(mode));
diff --git a/app/source/Cplt/Utils/IO/CstdioFile.hpp b/app/source/Cplt/Utils/IO/CstdioFile.hpp
index e863dd5..32957a2 100644
--- a/app/source/Cplt/Utils/IO/CstdioFile.hpp
+++ b/app/source/Cplt/Utils/IO/CstdioFile.hpp
@@ -5,8 +5,7 @@
namespace FileUtils {
-enum IoMode
-{
+enum IoMode {
IM_Read,
IM_WriteAppend,
IM_WriteTruncate,
diff --git a/app/source/Cplt/Utils/IO/DataStream.cpp b/app/source/Cplt/Utils/IO/DataStream.cpp
index c0797e3..14afa04 100644
--- a/app/source/Cplt/Utils/IO/DataStream.cpp
+++ b/app/source/Cplt/Utils/IO/DataStream.cpp
@@ -11,15 +11,13 @@ static_assert(std::endian::native == std::endian::little || std::endian::native
// Reading/writing signed integer byte-by-byte is fine, since the representation got fixed to 2's complements in C++20
-static uint16_t ByteSwap(uint16_t n)
-{
+static uint16_t ByteSwap(uint16_t n) {
auto bytes = reinterpret_cast<std::byte*>(n);
std::swap(bytes[0], bytes[1]);
return n;
}
-static uint32_t ByteSwap(uint32_t n)
-{
+static uint32_t ByteSwap(uint32_t n) {
#ifdef _MSC_VER
return _byteswap_ulong(n);
#else
@@ -27,8 +25,7 @@ static uint32_t ByteSwap(uint32_t n)
#endif
}
-static uint64_t ByteSwap(uint64_t n)
-{
+static uint64_t ByteSwap(uint64_t n) {
#ifdef _MSC_VER
return _byteswap_uint64(n);
#else
@@ -37,57 +34,47 @@ static uint64_t ByteSwap(uint64_t n)
}
template <class TSigned>
-static TSigned ByteSwap(TSigned n)
-{
+static TSigned ByteSwap(TSigned n) {
using Unsigned = std::make_unsigned_t<TSigned>;
auto swapped = ::ByteSwap(std::bit_cast<Unsigned>(n));
return std::bit_cast<TSigned>(swapped);
}
-std::endian BaseDataStream::GetEndianness() const
-{
+std::endian BaseDataStream::GetEndianness() const {
return mEndian;
}
-void BaseDataStream::SetEndianness(std::endian endianness)
-{
+void BaseDataStream::SetEndianness(std::endian endianness) {
mEndian = endianness;
}
InputDataStream::InputDataStream(InputFileStream stream)
- : mBackend{ std::move(stream) }
-{
+ : mBackend{ std::move(stream) } {
}
-void InputDataStream::ReadBytes(size_t byteCount, std::byte* buffer)
-{
+void InputDataStream::ReadBytes(size_t byteCount, std::byte* buffer) {
mBackend.ReadBytes(static_cast<std::streamsize>(byteCount), reinterpret_cast<std::byte*>(buffer));
}
-void InputDataStream::ReadBytes(size_t byteCount, char* buffer)
-{
+void InputDataStream::ReadBytes(size_t byteCount, char* buffer) {
mBackend.ReadBytes(static_cast<std::streamsize>(byteCount), reinterpret_cast<std::byte*>(buffer));
}
-void InputDataStream::ReadBytes(size_t byteCount, signed char* buffer)
-{
+void InputDataStream::ReadBytes(size_t byteCount, signed char* buffer) {
mBackend.ReadBytes(static_cast<std::streamsize>(byteCount), reinterpret_cast<std::byte*>(buffer));
}
-void InputDataStream::ReadBytes(size_t byteCount, unsigned char* buffer)
-{
+void InputDataStream::ReadBytes(size_t byteCount, unsigned char* buffer) {
mBackend.ReadBytes(static_cast<std::streamsize>(byteCount), reinterpret_cast<std::byte*>(buffer));
}
-void InputDataStream::Read(int8_t& n)
-{
+void InputDataStream::Read(int8_t& n) {
// sizeof() of a reference type yields the size of the reference
mBackend.ReadBytes(sizeof(n), reinterpret_cast<std::byte*>(&n));
}
-void InputDataStream::Read(int16_t& n)
-{
+void InputDataStream::Read(int16_t& n) {
int16_t tmp;
mBackend.ReadBytes(sizeof(tmp), reinterpret_cast<std::byte*>(&tmp));
if (GetEndianness() != std::endian::native) {
@@ -97,8 +84,7 @@ void InputDataStream::Read(int16_t& n)
}
}
-void InputDataStream::Read(int32_t& n)
-{
+void InputDataStream::Read(int32_t& n) {
int32_t tmp;
mBackend.ReadBytes(sizeof(tmp), reinterpret_cast<std::byte*>(&tmp));
if (GetEndianness() != std::endian::native) {
@@ -108,8 +94,7 @@ void InputDataStream::Read(int32_t& n)
}
}
-void InputDataStream::Read(int64_t& n)
-{
+void InputDataStream::Read(int64_t& n) {
int64_t tmp;
mBackend.ReadBytes(sizeof(tmp), reinterpret_cast<std::byte*>(&tmp));
if (GetEndianness() != std::endian::native) {
@@ -119,13 +104,11 @@ void InputDataStream::Read(int64_t& n)
}
}
-void InputDataStream::Read(uint8_t& n)
-{
+void InputDataStream::Read(uint8_t& n) {
mBackend.ReadBytes(sizeof(n), reinterpret_cast<std::byte*>(&n));
}
-void InputDataStream::Read(uint16_t& n)
-{
+void InputDataStream::Read(uint16_t& n) {
uint16_t tmp;
mBackend.ReadBytes(sizeof(tmp), reinterpret_cast<std::byte*>(&tmp));
if (GetEndianness() != std::endian::native) {
@@ -135,8 +118,7 @@ void InputDataStream::Read(uint16_t& n)
}
}
-void InputDataStream::Read(uint32_t& n)
-{
+void InputDataStream::Read(uint32_t& n) {
uint32_t tmp;
mBackend.ReadBytes(sizeof(tmp), reinterpret_cast<std::byte*>(&tmp));
if (GetEndianness() != std::endian::native) {
@@ -146,8 +128,7 @@ void InputDataStream::Read(uint32_t& n)
}
}
-void InputDataStream::Read(uint64_t& n)
-{
+void InputDataStream::Read(uint64_t& n) {
uint64_t tmp;
mBackend.ReadBytes(sizeof(tmp), reinterpret_cast<std::byte*>(&tmp));
if (GetEndianness() != std::endian::native) {
@@ -157,8 +138,7 @@ void InputDataStream::Read(uint64_t& n)
}
}
-void InputDataStream::Read(float& n)
-{
+void InputDataStream::Read(float& n) {
uint32_t buffer;
Read(buffer);
@@ -169,8 +149,7 @@ void InputDataStream::Read(float& n)
n = std::bit_cast<float>(buffer);
}
-void InputDataStream::Read(double& n)
-{
+void InputDataStream::Read(double& n) {
uint64_t buffer;
Read(buffer);
@@ -182,90 +161,76 @@ void InputDataStream::Read(double& n)
}
OutputDataStream::OutputDataStream(OutputFileStream stream)
- : mBackend{ std::move(stream) }
-{
+ : mBackend{ std::move(stream) } {
}
-void OutputDataStream::WriteBytes(size_t byteCount, const std::byte* buffer)
-{
+void OutputDataStream::WriteBytes(size_t byteCount, const std::byte* buffer) {
mBackend.WriteBytes(static_cast<std::streamsize>(byteCount), reinterpret_cast<const std::byte*>(buffer));
}
-void OutputDataStream::WriteBytes(size_t byteCount, const char* buffer)
-{
+void OutputDataStream::WriteBytes(size_t byteCount, const char* buffer) {
mBackend.WriteBytes(static_cast<std::streamsize>(byteCount), reinterpret_cast<const std::byte*>(buffer));
}
-void OutputDataStream::WriteBytes(size_t byteCount, const signed char* buffer)
-{
+void OutputDataStream::WriteBytes(size_t byteCount, const signed char* buffer) {
mBackend.WriteBytes(static_cast<std::streamsize>(byteCount), reinterpret_cast<const std::byte*>(buffer));
}
-void OutputDataStream::WriteBytes(size_t byteCount, const unsigned char* buffer)
-{
+void OutputDataStream::WriteBytes(size_t byteCount, const unsigned char* buffer) {
mBackend.WriteBytes(static_cast<std::streamsize>(byteCount), reinterpret_cast<const std::byte*>(buffer));
}
-void OutputDataStream::Write(int8_t n)
-{
+void OutputDataStream::Write(int8_t n) {
mBackend.WriteBytes(sizeof(n), reinterpret_cast<const std::byte*>(&n));
}
-void OutputDataStream::Write(int16_t n)
-{
+void OutputDataStream::Write(int16_t n) {
if (GetEndianness() != std::endian::native) {
n = ::ByteSwap(n);
}
mBackend.WriteBytes(sizeof(n), reinterpret_cast<const std::byte*>(&n));
}
-void OutputDataStream::Write(int32_t n)
-{
+void OutputDataStream::Write(int32_t n) {
if (GetEndianness() != std::endian::native) {
n = ::ByteSwap(n);
}
mBackend.WriteBytes(sizeof(n), reinterpret_cast<const std::byte*>(&n));
}
-void OutputDataStream::Write(int64_t n)
-{
+void OutputDataStream::Write(int64_t n) {
if (GetEndianness() != std::endian::native) {
n = ::ByteSwap(n);
}
mBackend.WriteBytes(sizeof(n), reinterpret_cast<const std::byte*>(&n));
}
-void OutputDataStream::Write(uint8_t n)
-{
+void OutputDataStream::Write(uint8_t n) {
mBackend.WriteBytes(sizeof(n), reinterpret_cast<const std::byte*>(&n));
}
-void OutputDataStream::Write(uint16_t n)
-{
+void OutputDataStream::Write(uint16_t n) {
if (GetEndianness() != std::endian::native) {
n = ::ByteSwap(n);
}
mBackend.WriteBytes(sizeof(n), reinterpret_cast<const std::byte*>(&n));
}
-void OutputDataStream::Write(uint32_t n)
-{
+void OutputDataStream::Write(uint32_t n) {
if (GetEndianness() != std::endian::native) {
n = ::ByteSwap(n);
}
mBackend.WriteBytes(sizeof(n), reinterpret_cast<const std::byte*>(&n));
}
-void OutputDataStream::Write(uint64_t n)
-{
+void OutputDataStream::Write(uint64_t n) {
if (GetEndianness() != std::endian::native) {
n = ::ByteSwap(n);
}
mBackend.WriteBytes(sizeof(n), reinterpret_cast<const std::byte*>(&n));
}
-void OutputDataStream::Write(float n)
-{
+void OutputDataStream::Write(float n) {
auto buffer = std::bit_cast<uint32_t>(n);
if (GetEndianness() != std::endian::native) {
buffer = ::ByteSwap(buffer);
@@ -273,8 +238,7 @@ void OutputDataStream::Write(float n)
mBackend.WriteBytes(sizeof(buffer), reinterpret_cast<const std::byte*>(&buffer));
}
-void OutputDataStream::Write(double n)
-{
+void OutputDataStream::Write(double n) {
auto buffer = std::bit_cast<uint64_t>(n);
if (GetEndianness() != std::endian::native) {
buffer = ::ByteSwap(buffer);
diff --git a/app/source/Cplt/Utils/IO/DataStream.hpp b/app/source/Cplt/Utils/IO/DataStream.hpp
index 133adc2..770cebc 100644
--- a/app/source/Cplt/Utils/IO/DataStream.hpp
+++ b/app/source/Cplt/Utils/IO/DataStream.hpp
@@ -8,8 +8,7 @@
#include <cstdint>
#include <span>
-class BaseDataStream
-{
+class BaseDataStream {
private:
std::endian mEndian = std::endian::big;
@@ -18,14 +17,12 @@ public:
void SetEndianness(std::endian endianness);
};
-class InputDataStream : public BaseDataStream
-{
+class InputDataStream : public BaseDataStream {
private:
InputFileStream mBackend;
public:
- static constexpr bool IsSerializer()
- {
+ static constexpr bool IsSerializer() {
return false;
}
@@ -37,8 +34,7 @@ public:
void ReadBytes(size_t byteCount, unsigned char* buffer);
template <class TInserter>
- void ReadBytes(size_t byteCount, TInserter&& inserter)
- {
+ void ReadBytes(size_t byteCount, TInserter&& inserter) {
for (size_t i = 0; i < byteCount; ++i) {
uint8_t byte;
Read(byte);
@@ -62,22 +58,19 @@ public:
template <class TEnum>
requires std::is_enum_v<TEnum>
- void ReadEnum(TEnum& e)
- {
+ void ReadEnum(TEnum& e) {
std::underlying_type_t<TEnum> n;
Read(n);
e = static_cast<TEnum>(e);
}
template <class TObject>
- void ReadObject(TObject& obj)
- {
+ void ReadObject(TObject& obj) {
obj.ReadFromDataStream(*this);
}
template <class TAdapter, class TObject>
- void ReadObjectAdapted(TObject& obj)
- {
+ void ReadObjectAdapted(TObject& obj) {
TAdapter::ReadFromDataStream(*this, obj);
}
@@ -85,44 +78,37 @@ public:
// Proxy functions for writing templated IO functions
template <class T>
- void Bytes(size_t byteCount, T* buffer)
- {
+ void Bytes(size_t byteCount, T* buffer) {
ReadBytes(byteCount, buffer);
}
template <class T>
- void Value(T& t)
- {
+ void Value(T& t) {
Read(t);
}
template <class T>
- void Enum(T& t)
- {
+ void Enum(T& t) {
ReadEnum(t);
}
template <class T>
- void Object(T& obj)
- {
+ void Object(T& obj) {
ReadObject(obj);
}
template <class TAdapter, class TObject>
- void ObjectAdapted(TObject& obj)
- {
+ void ObjectAdapted(TObject& obj) {
ReadObjectAdapted<TAdapter>(obj);
}
};
-class OutputDataStream : public BaseDataStream
-{
+class OutputDataStream : public BaseDataStream {
private:
OutputFileStream mBackend;
public:
- static constexpr bool IsSerializer()
- {
+ static constexpr bool IsSerializer() {
return true;
}
@@ -134,8 +120,7 @@ public:
void WriteBytes(size_t byteCount, const unsigned char* buffer);
template <class TIterator>
- void WriteBytes(TIterator&& begin, TIterator&& end)
- {
+ void WriteBytes(TIterator&& begin, TIterator&& end) {
for (; begin != end; ++begin) {
uint8_t byte = *begin;
Write(byte);
@@ -157,21 +142,18 @@ public:
template <class TEnum>
requires std::is_enum_v<TEnum>
- void WriteEnum(TEnum e)
- {
+ void WriteEnum(TEnum e) {
auto n = static_cast<std::underlying_type_t<TEnum>>(e);
Write(n);
}
template <class TObject>
- void WriteObject(const TObject& obj)
- {
+ void WriteObject(const TObject& obj) {
obj.WriteToDataStream(*this);
}
template <class TAdapter, class TObject>
- void WriteObjectAdapted(const TObject& obj)
- {
+ void WriteObjectAdapted(const TObject& obj) {
TAdapter::WriteToDataStream(*this, obj);
}
@@ -179,32 +161,27 @@ public:
// Proxy functions for writing templated IO functions
template <class T>
- void Bytes(size_t byteCount, T* buffer)
- {
+ void Bytes(size_t byteCount, T* buffer) {
WriteBytes(byteCount, buffer);
}
template <class T>
- void Value(T t)
- {
+ void Value(T t) {
Write(t);
}
template <class T>
- void Enum(T t)
- {
+ void Enum(T t) {
WriteEnum(t);
}
template <class T>
- void Object(T& obj)
- {
+ void Object(T& obj) {
WriteObject(obj);
}
template <class TAdapter, class TObject>
- void ObjectAdapted(TObject& obj)
- {
+ void ObjectAdapted(TObject& obj) {
WriteObjectAdapted<TAdapter>(obj);
}
};
diff --git a/app/source/Cplt/Utils/IO/FileStream.hpp b/app/source/Cplt/Utils/IO/FileStream.hpp
index 453ddbe..37b2a36 100644
--- a/app/source/Cplt/Utils/IO/FileStream.hpp
+++ b/app/source/Cplt/Utils/IO/FileStream.hpp
@@ -8,10 +8,8 @@
// TODO switch to custom when unit tests are ready and bugs are fixed
#define CPLT_FILESTREAM_USE_CSTDIO
-struct IoResult
-{
- enum ErrorKind
- {
+struct IoResult {
+ enum ErrorKind {
ERR_None,
ERR_PermissionDenied,
ERR_UnexpectedEof,
@@ -25,8 +23,7 @@ struct IoResult
size_t BytesMoved;
};
-class InputFileStream
-{
+class InputFileStream {
private:
#if defined(CPLT_FILESTREAM_USE_CSTDIO)
FILE* mFile;
@@ -60,11 +57,9 @@ public:
IoResult ReadBytes(size_t bufferLength, std::byte* buffer);
};
-class OutputFileStream
-{
+class OutputFileStream {
public:
- enum WriteMode
- {
+ enum WriteMode {
AppendFile,
TruncateFile,
};
diff --git a/app/source/Cplt/Utils/IO/Helper.hpp b/app/source/Cplt/Utils/IO/Helper.hpp
index 7a84103..b8f4e6f 100644
--- a/app/source/Cplt/Utils/IO/Helper.hpp
+++ b/app/source/Cplt/Utils/IO/Helper.hpp
@@ -7,8 +7,7 @@ namespace DataStreamAdapters {
/// Helper to invoke either Read() or ReadObject().
/// This is intended for writing IO adapters, users that's writing IO logic shouldn't using this - it increases compile time while reducing readability.
template <class TAdapter, class T>
-void ReadHelper(InputDataStream& stream, T& t)
-{
+void ReadHelper(InputDataStream& stream, T& t) {
if constexpr (!std::is_same_v<TAdapter, void>) {
stream.ReadObjectAdapted<TAdapter>(t);
} else if constexpr (requires(T tt, InputDataStream ss) { ss.Read(tt); }) {
@@ -25,8 +24,7 @@ void ReadHelper(InputDataStream& stream, T& t)
/// Helper to invoke either Write() or WriteObject().
/// This is intended for writing IO adapters, users that's writing IO logic shouldn't using this - it increases compile time while reducing readability.
template <class TAdapter, class T>
-void WriteHelper(OutputDataStream& stream, T& t)
-{
+void WriteHelper(OutputDataStream& stream, T& t) {
if constexpr (!std::is_same_v<TAdapter, void>) {
stream.WriteObjectAdapted<TAdapter>(t);
} else if constexpr (requires(T tt, OutputDataStream ss) { ss.Write(tt); }) {
diff --git a/app/source/Cplt/Utils/IO/StringIntegration.hpp b/app/source/Cplt/Utils/IO/StringIntegration.hpp
index 66f42b0..3ff715a 100644
--- a/app/source/Cplt/Utils/IO/StringIntegration.hpp
+++ b/app/source/Cplt/Utils/IO/StringIntegration.hpp
@@ -7,10 +7,8 @@
#include <string_view>
namespace DataStreamAdapters {
-struct String
-{
- static void ReadFromDataStream(InputDataStream& stream, std::string& str)
- {
+struct String {
+ static void ReadFromDataStream(InputDataStream& stream, std::string& str) {
uint64_t size;
stream.Read(size);
@@ -19,17 +17,14 @@ struct String
stream.ReadBytes(size, std::back_inserter(str));
}
- static void WriteToDataStream(OutputDataStream& stream, const std::string& str)
- {
+ static void WriteToDataStream(OutputDataStream& stream, const std::string& str) {
stream.Write((uint64_t)str.size());
stream.WriteBytes(str.size(), str.data());
}
};
-struct StringView
-{
- static void WriteToDataStream(OutputDataStream& stream, const std::string_view& str)
- {
+struct StringView {
+ static void WriteToDataStream(OutputDataStream& stream, const std::string_view& str) {
stream.Write((uint64_t)str.size());
stream.WriteBytes(str.size(), str.data());
}
diff --git a/app/source/Cplt/Utils/IO/TslArrayIntegration.hpp b/app/source/Cplt/Utils/IO/TslArrayIntegration.hpp
index b585bee..1215c3b 100644
--- a/app/source/Cplt/Utils/IO/TslArrayIntegration.hpp
+++ b/app/source/Cplt/Utils/IO/TslArrayIntegration.hpp
@@ -13,11 +13,9 @@
namespace DataStreamAdapters {
template <class TAdapter = void>
-struct TslArrayMap
-{
+struct TslArrayMap {
template <class TValue>
- static void ReadFromDataStream(InputDataStream& stream, tsl::array_map<char, TValue>& map)
- {
+ static void ReadFromDataStream(InputDataStream& stream, tsl::array_map<char, TValue>& map) {
static_assert(std::is_default_constructible_v<TValue>);
static_assert(std::is_move_constructible_v<TValue>);
@@ -37,8 +35,7 @@ struct TslArrayMap
}
template <class TValue>
- static void WriteToDataStream(OutputDataStream& stream, const tsl::array_map<char, TValue>& map)
- {
+ static void WriteToDataStream(OutputDataStream& stream, const tsl::array_map<char, TValue>& map) {
stream.Write((uint64_t)map.size());
for (auto it = map.begin(); it != map.end(); ++it) {
diff --git a/app/source/Cplt/Utils/IO/TslRobinIntegration.hpp b/app/source/Cplt/Utils/IO/TslRobinIntegration.hpp
index bdea505..a19a4f1 100644
--- a/app/source/Cplt/Utils/IO/TslRobinIntegration.hpp
+++ b/app/source/Cplt/Utils/IO/TslRobinIntegration.hpp
@@ -9,11 +9,9 @@
namespace DataStreamAdapters {
template <class TKeyAdapter = void, class TValueAdapter = void>
-struct TslRobinMap
-{
+struct TslRobinMap {
template <class TKey, class TValue>
- static void ReadFromDataStream(InputDataStream& stream, tsl::robin_map<TKey, TValue>& map)
- {
+ static void ReadFromDataStream(InputDataStream& stream, tsl::robin_map<TKey, TValue>& map) {
static_assert(std::is_default_constructible_v<TValue>);
static_assert(std::is_move_constructible_v<TValue>);
@@ -33,8 +31,7 @@ struct TslRobinMap
}
template <class TKey, class TValue>
- static void WriteToDataStream(OutputDataStream& stream, const tsl::robin_map<TKey, TValue>& map)
- {
+ static void WriteToDataStream(OutputDataStream& stream, const tsl::robin_map<TKey, TValue>& map) {
stream.Write((uint64_t)map.size());
for (auto it = map.begin(); it != map.end(); ++it) {
@@ -45,11 +42,9 @@ struct TslRobinMap
};
template <class TAdapter = void>
-struct TslRobinSet
-{
+struct TslRobinSet {
template <class TElement>
- static void ReadFromDataStream(InputDataStream& stream, tsl::robin_set<TElement>& set)
- {
+ static void ReadFromDataStream(InputDataStream& stream, tsl::robin_set<TElement>& set) {
static_assert(std::is_default_constructible_v<TElement>);
static_assert(std::is_move_constructible_v<TElement>);
@@ -66,8 +61,7 @@ struct TslRobinSet
}
template <class TElement>
- static void WriteToDataStream(OutputDataStream& stream, const tsl::robin_set<TElement>& set)
- {
+ static void WriteToDataStream(OutputDataStream& stream, const tsl::robin_set<TElement>& set) {
stream.Write((uint64_t)set.size());
for (auto& element : set) {
diff --git a/app/source/Cplt/Utils/IO/UuidIntegration.hpp b/app/source/Cplt/Utils/IO/UuidIntegration.hpp
index 20c1e7e..49afd19 100644
--- a/app/source/Cplt/Utils/IO/UuidIntegration.hpp
+++ b/app/source/Cplt/Utils/IO/UuidIntegration.hpp
@@ -8,18 +8,15 @@
#include <iterator>
namespace DataStreamAdapters {
-struct Uuid
-{
- static void ReadFromDataStream(InputDataStream& stream, uuids::uuid& uuid)
- {
+struct Uuid {
+ static void ReadFromDataStream(InputDataStream& stream, uuids::uuid& uuid) {
uint8_t buffer[16];
stream.ReadBytes(16, buffer);
uuid = uuids::uuid(gsl::span<uint8_t, 16>{ buffer });
}
- static void WriteToDataStream(OutputDataStream& stream, const uuids::uuid& uuid)
- {
+ static void WriteToDataStream(OutputDataStream& stream, const uuids::uuid& uuid) {
auto gslSpan = uuid.as_bytes();
stream.WriteBytes(gslSpan.size(), gslSpan.data());
}
diff --git a/app/source/Cplt/Utils/IO/VectorIntegration.hpp b/app/source/Cplt/Utils/IO/VectorIntegration.hpp
index 93967f6..e1a6108 100644
--- a/app/source/Cplt/Utils/IO/VectorIntegration.hpp
+++ b/app/source/Cplt/Utils/IO/VectorIntegration.hpp
@@ -8,11 +8,9 @@
namespace DataStreamAdapters {
template <class TAdapter = void>
-struct Vector
-{
+struct Vector {
template <class TElement>
- static void ReadFromDataStream(InputDataStream& stream, std::vector<TElement>& vec)
- {
+ static void ReadFromDataStream(InputDataStream& stream, std::vector<TElement>& vec) {
static_assert(std::is_default_constructible_v<TElement>);
static_assert(std::is_move_constructible_v<TElement>);
@@ -31,8 +29,7 @@ struct Vector
}
template <class TElement>
- static void WriteToDataStream(OutputDataStream& stream, const std::vector<TElement>& vec)
- {
+ static void WriteToDataStream(OutputDataStream& stream, const std::vector<TElement>& vec) {
stream.Write((uint64_t)vec.size());
for (auto& element : vec) {
WriteHelper<TAdapter>(stream, element);
diff --git a/app/source/Cplt/Utils/Math.hpp b/app/source/Cplt/Utils/Math.hpp
index da53da2..0e760c1 100644
--- a/app/source/Cplt/Utils/Math.hpp
+++ b/app/source/Cplt/Utils/Math.hpp
@@ -3,8 +3,7 @@
namespace MathUtils {
template <class T>
-constexpr T Abs(T t)
-{
+constexpr T Abs(T t) {
return t < 0 ? -t : t;
}
diff --git a/app/source/Cplt/Utils/RTTI.hpp b/app/source/Cplt/Utils/RTTI.hpp
index 86b1e2c..bc0d289 100644
--- a/app/source/Cplt/Utils/RTTI.hpp
+++ b/app/source/Cplt/Utils/RTTI.hpp
@@ -3,15 +3,13 @@
#include <cassert>
template <class T, class TBase>
-bool is_a(TBase* t)
-{
+bool is_a(TBase* t) {
assert(t != nullptr);
return T::IsInstance(t);
}
template <class T, class TBase>
-bool is_a_nullable(TBase* t)
-{
+bool is_a_nullable(TBase* t) {
if (t) {
return is_a<T, TBase>(t);
} else {
@@ -20,8 +18,7 @@ bool is_a_nullable(TBase* t)
}
template <class T, class TBase>
-T* dyn_cast(TBase* t)
-{
+T* dyn_cast(TBase* t) {
assert(t != nullptr);
if (T::IsInstance(t)) {
return static_cast<T*>(t);
@@ -31,8 +28,7 @@ T* dyn_cast(TBase* t)
}
template <class T, class TBase>
-const T* dyn_cast(const TBase* t)
-{
+const T* dyn_cast(const TBase* t) {
assert(t != nullptr);
if (T::IsInstance(t)) {
return static_cast<const T*>(t);
@@ -42,8 +38,7 @@ const T* dyn_cast(const TBase* t)
}
template <class T, class TBase>
-T* dyn_cast_nullable(TBase* t)
-{
+T* dyn_cast_nullable(TBase* t) {
if (!t) return nullptr;
return dyn_cast<T, TBase>(t);
}
diff --git a/app/source/Cplt/Utils/ScopeGuard.hpp b/app/source/Cplt/Utils/ScopeGuard.hpp
index f2b7f46..e7db2a4 100644
--- a/app/source/Cplt/Utils/ScopeGuard.hpp
+++ b/app/source/Cplt/Utils/ScopeGuard.hpp
@@ -5,8 +5,7 @@
#include <utility>
template <class TCleanupFunc>
-class ScopeGuard
-{
+class ScopeGuard {
private:
TCleanupFunc mFunc;
bool mDismissed = false;
@@ -19,19 +18,16 @@ public:
/// would work. It is highly discourage and unlikely that one would want to use ScopeGuard as a function
/// parameter, so the normal argument that implicit conversion are harmful doesn't really apply here.
ScopeGuard(TCleanupFunc func)
- : mFunc{ std::move(func) }
- {
+ : mFunc{ std::move(func) } {
}
- ~ScopeGuard()
- {
+ ~ScopeGuard() {
if (!mDismissed) {
mFunc();
}
}
- void Dismiss() noexcept
- {
+ void Dismiss() noexcept {
mDismissed = true;
}
};
diff --git a/app/source/Cplt/Utils/Sigslot.cpp b/app/source/Cplt/Utils/Sigslot.cpp
index 1132dfb..14deece 100644
--- a/app/source/Cplt/Utils/Sigslot.cpp
+++ b/app/source/Cplt/Utils/Sigslot.cpp
@@ -2,28 +2,23 @@
#include <doctest/doctest.h>
-bool SignalStub::Connection::IsOccupied() const
-{
+bool SignalStub::Connection::IsOccupied() const {
return id != InvalidId;
}
SignalStub::SignalStub(IWrapper& wrapper)
- : mWrapper{ &wrapper }
-{
+ : mWrapper{ &wrapper } {
}
-SignalStub::~SignalStub()
-{
+SignalStub::~SignalStub() {
RemoveAllConnections();
}
-std::span<const SignalStub::Connection> SignalStub::GetConnections() const
-{
+std::span<const SignalStub::Connection> SignalStub::GetConnections() const {
return mConnections;
}
-SignalStub::Connection& SignalStub::InsertConnection(SlotGuard* guard)
-{
+SignalStub::Connection& SignalStub::InsertConnection(SlotGuard* guard) {
Connection* result;
int size = static_cast<int>(mConnections.size());
for (int i = 0; i < size; ++i) {
@@ -47,8 +42,7 @@ setup:
return *result;
}
-void SignalStub::RemoveConnection(int id)
-{
+void SignalStub::RemoveConnection(int id) {
if (id >= 0 && id < mConnections.size()) {
auto& conn = mConnections[id];
if (conn.IsOccupied()) {
@@ -64,29 +58,24 @@ void SignalStub::RemoveConnection(int id)
}
}
-void SignalStub::RemoveConnectionFor(SlotGuard& guard)
-{
+void SignalStub::RemoveConnectionFor(SlotGuard& guard) {
guard.RemoveConnectionFor(*this);
}
-void SignalStub::RemoveAllConnections()
-{
+void SignalStub::RemoveAllConnections() {
for (size_t i = 0; i < mConnections.size(); ++i) {
RemoveConnection(i);
}
}
-SlotGuard::SlotGuard()
-{
+SlotGuard::SlotGuard() {
}
-SlotGuard::~SlotGuard()
-{
+SlotGuard::~SlotGuard() {
DisconnectAll();
}
-void SlotGuard::DisconnectAll()
-{
+void SlotGuard::DisconnectAll() {
for (auto& conn : mConnections) {
if (conn.stub) {
// Also calls SlotGuard::removeConnection, our copy of the data will be cleared in it
@@ -95,8 +84,7 @@ void SlotGuard::DisconnectAll()
}
}
-int SlotGuard::InsertConnection(SignalStub& stub, int stubId)
-{
+int SlotGuard::InsertConnection(SignalStub& stub, int stubId) {
int size = static_cast<int>(mConnections.size());
for (int i = 0; i < size; ++i) {
auto& conn = mConnections[i];
@@ -114,8 +102,7 @@ int SlotGuard::InsertConnection(SignalStub& stub, int stubId)
return size;
}
-void SlotGuard::RemoveConnectionFor(SignalStub& stub)
-{
+void SlotGuard::RemoveConnectionFor(SignalStub& stub) {
for (auto& conn : mConnections) {
if (conn.stub == &stub) {
conn.stub->RemoveConnection(conn.stubId);
@@ -123,13 +110,11 @@ void SlotGuard::RemoveConnectionFor(SignalStub& stub)
}
}
-void SlotGuard::RemoveConnection(int slotId)
-{
+void SlotGuard::RemoveConnection(int slotId) {
mConnections[slotId] = {};
}
-TEST_CASE("Signal connect and disconnect")
-{
+TEST_CASE("Signal connect and disconnect") {
Signal<> sig;
int counter = 0;
@@ -146,8 +131,7 @@ TEST_CASE("Signal connect and disconnect")
CHECK(counter == 2);
}
-TEST_CASE("Signal with parameters")
-{
+TEST_CASE("Signal with parameters") {
Signal<int> sig;
int counter = 0;
@@ -167,8 +151,7 @@ TEST_CASE("Signal with parameters")
CHECK(counter == 5);
}
-TEST_CASE("Signal disconnectAll()")
-{
+TEST_CASE("Signal disconnectAll()") {
Signal<> sig;
int counter1 = 0;
@@ -190,8 +173,7 @@ TEST_CASE("Signal disconnectAll()")
CHECK(counter2 == 2);
}
-TEST_CASE("SlotGuard auto-disconnection")
-{
+TEST_CASE("SlotGuard auto-disconnection") {
int counter1 = 0;
int counter2 = 0;
Signal<> sig;
@@ -215,8 +197,7 @@ TEST_CASE("SlotGuard auto-disconnection")
CHECK(counter2 == 2);
}
-TEST_CASE("Signal destruct before SlotGuard")
-{
+TEST_CASE("Signal destruct before SlotGuard") {
int counter = 0;
SlotGuard guard;
diff --git a/app/source/Cplt/Utils/Sigslot.hpp b/app/source/Cplt/Utils/Sigslot.hpp
index a4ab94e..92c8bcc 100644
--- a/app/source/Cplt/Utils/Sigslot.hpp
+++ b/app/source/Cplt/Utils/Sigslot.hpp
@@ -8,25 +8,21 @@
#include <utility>
#include <vector>
-class SignalStub
-{
+class SignalStub {
public:
/// Non-template interface for Signal<T...> to implement (a barrier to stop template
/// arguments propagation).
- class IWrapper
- {
+ class IWrapper {
public:
virtual ~IWrapper() = default;
virtual void RemoveFunction(int id) = 0;
};
- enum
- {
+ enum {
InvalidId = -1,
};
- struct Connection
- {
+ struct Connection {
SlotGuard* guard;
int slotId;
int id = InvalidId; // If `InvalidId`, then this "spot" is unused
@@ -59,8 +55,7 @@ private:
};
template <class... TArgs>
-class Signal : public SignalStub::IWrapper
-{
+class Signal : public SignalStub::IWrapper {
private:
// Must be in this order so that mFunctions is still intact when mStub's destructor runs
std::vector<std::function<void(TArgs...)>> mFunctions;
@@ -68,8 +63,7 @@ private:
public:
Signal()
- : mStub(*this)
- {
+ : mStub(*this) {
}
virtual ~Signal() = default;
@@ -79,8 +73,7 @@ public:
Signal(Signal&&) = default;
Signal& operator=(Signal&&) = default;
- void operator()(TArgs... args)
- {
+ void operator()(TArgs... args) {
for (auto& conn : mStub.GetConnections()) {
if (conn.IsOccupied()) {
mFunctions[conn.id](std::forward<TArgs>(args)...);
@@ -89,8 +82,7 @@ public:
}
template <class TFunction>
- int Connect(TFunction slot)
- {
+ int Connect(TFunction slot) {
auto& conn = mStub.InsertConnection();
mFunctions.resize(std::max(mFunctions.size(), (size_t)conn.id + 1));
mFunctions[conn.id] = std::move(slot);
@@ -98,31 +90,26 @@ public:
}
template <class TFunction>
- int Connect(SlotGuard& guard, TFunction slot)
- {
+ int Connect(SlotGuard& guard, TFunction slot) {
auto& conn = mStub.InsertConnection(&guard);
mFunctions.resize(std::max(mFunctions.size(), (size_t)conn.id + 1));
mFunctions[conn.id] = std::move(slot);
return conn.id;
}
- void Disconnect(int id)
- {
+ void Disconnect(int id) {
mStub.RemoveConnection(id);
}
- void DisconnectFor(SlotGuard& guard)
- {
+ void DisconnectFor(SlotGuard& guard) {
mStub.RemoveConnectionFor(guard);
}
- void DisconnectAll()
- {
+ void DisconnectAll() {
mStub.RemoveAllConnections();
}
- virtual void RemoveFunction(int id)
- {
+ virtual void RemoveFunction(int id) {
mFunctions[id] = {};
}
};
@@ -130,11 +117,9 @@ public:
/// Automatic disconnection mechanism for Signal<>.
/// Bind connection to this guard by using the Connect(SlotGuard&, TFunction) overload.
/// Either DisconnectAll() or the destructor disconnects all connections bound to this guard.
-class SlotGuard
-{
+class SlotGuard {
private:
- struct Connection
- {
+ struct Connection {
SignalStub* stub = nullptr;
int stubId = SignalStub::InvalidId;
};
diff --git a/app/source/Cplt/Utils/Size.hpp b/app/source/Cplt/Utils/Size.hpp
index ae38e8a..bcad488 100644
--- a/app/source/Cplt/Utils/Size.hpp
+++ b/app/source/Cplt/Utils/Size.hpp
@@ -18,25 +18,21 @@ public:
}
Size2(Vec2<T> vec)
- : width{ vec.x }, height{ vec.y }
- {
+ : width{ vec.x }, height{ vec.y } {
}
- operator Vec2<T>() const
- {
+ operator Vec2<T>() const {
return { width, height };
}
- Vec2<T> AsVec() const
- {
+ Vec2<T> AsVec() const {
return { width, height };
}
friend bool operator==(const Size2<T>&, const Size2<T>&) = default;
template <class TTarget>
- Size2<TTarget> Cast() const
- {
+ Size2<TTarget> Cast() const {
return {
static_cast<TTarget>(width),
static_cast<TTarget>(height),
diff --git a/app/source/Cplt/Utils/StandardDirectories.cpp b/app/source/Cplt/Utils/StandardDirectories.cpp
index 2202f51..ff2c911 100644
--- a/app/source/Cplt/Utils/StandardDirectories.cpp
+++ b/app/source/Cplt/Utils/StandardDirectories.cpp
@@ -12,8 +12,7 @@ namespace fs = std::filesystem;
# pragma comment(lib, "shell32.lib")
# pragma comment(lib, "ole32.lib")
-static fs::path GetAppDataRoaming()
-{
+static fs::path GetAppDataRoaming() {
PWSTR path = nullptr;
HRESULT hr = SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE, nullptr, &path);
if (SUCCEEDED(hr)) {
@@ -34,8 +33,7 @@ static fs::path GetAppDataRoaming()
#elif defined(__linux__)
# include <cstdlib>
-static fs::path GetEnvVar(const char* name, const char* backup)
-{
+static fs::path GetEnvVar(const char* name, const char* backup) {
if (const char* path = std::getenv(name)) {
fs::path dataDir(path);
fs::create_directories(dataDir);
@@ -49,8 +47,7 @@ static fs::path GetEnvVar(const char* name, const char* backup)
#endif
-const std::filesystem::path& StandardDirectories::UserData()
-{
+const std::filesystem::path& StandardDirectories::UserData() {
static auto userDataDir = []() -> fs::path {
#if defined(_WIN32)
return GetAppDataRoaming();
@@ -63,8 +60,7 @@ const std::filesystem::path& StandardDirectories::UserData()
return userDataDir;
}
-const std::filesystem::path& StandardDirectories::UserConfig()
-{
+const std::filesystem::path& StandardDirectories::UserConfig() {
static auto userConfigDir = []() -> fs::path {
#if defined(_WIN32)
return GetAppDataRoaming();
diff --git a/app/source/Cplt/Utils/Time.cpp b/app/source/Cplt/Utils/Time.cpp
index 4e79ffa..423f6bd 100644
--- a/app/source/Cplt/Utils/Time.cpp
+++ b/app/source/Cplt/Utils/Time.cpp
@@ -2,8 +2,7 @@
#include <ctime>
-std::string TimeUtils::StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock> tp)
-{
+std::string TimeUtils::StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock> tp) {
auto t = std::chrono::system_clock::to_time_t(tp);
char data[32];
@@ -15,8 +14,7 @@ std::string TimeUtils::StringifyTimePoint(std::chrono::time_point<std::chrono::s
return std::string(data);
}
-std::string TimeUtils::StringifyTimeStamp(int64_t timeStamp)
-{
+std::string TimeUtils::StringifyTimeStamp(int64_t timeStamp) {
if (timeStamp == 0) {
return "";
}
diff --git a/app/source/Cplt/Utils/Variant.hpp b/app/source/Cplt/Utils/Variant.hpp
index df2f882..b601811 100644
--- a/app/source/Cplt/Utils/Variant.hpp
+++ b/app/source/Cplt/Utils/Variant.hpp
@@ -4,21 +4,18 @@
#include <variant>
template <class... Ts>
-struct Overloaded : Ts...
-{
+struct Overloaded : Ts... {
using Ts::operator()...;
};
template <class... Ts>
Overloaded(Ts...) -> Overloaded<Ts...>;
template <class... Args>
-struct VariantCastProxy
-{
+struct VariantCastProxy {
std::variant<Args...> v;
template <class... ToArgs>
- operator std::variant<ToArgs...>() const
- {
+ operator std::variant<ToArgs...>() const {
return std::visit(
[](auto&& arg) -> std::variant<ToArgs...> { return arg; },
v);
@@ -27,7 +24,6 @@ struct VariantCastProxy
/// Use snake_case naming to align with `static_cast`, `dynamic_cast`, etc..
template <class... Args>
-auto variant_cast(std::variant<Args...> v) -> VariantCastProxy<Args...>
-{
+auto variant_cast(std::variant<Args...> v) -> VariantCastProxy<Args...> {
return { std::move(v) };
}
diff --git a/app/source/Cplt/Utils/Vector.hpp b/app/source/Cplt/Utils/Vector.hpp
index 79f4ea2..5fdfab2 100644
--- a/app/source/Cplt/Utils/Vector.hpp
+++ b/app/source/Cplt/Utils/Vector.hpp
@@ -3,28 +3,24 @@
#include <Cplt/Utils/IO/DataStream.hpp>
template <class T>
-struct Vec2
-{
+struct Vec2 {
T x = 0;
T y = 0;
template <class TTarget>
- Vec2<TTarget> Cast() const
- {
+ Vec2<TTarget> Cast() const {
return {
static_cast<TTarget>(x),
static_cast<TTarget>(y),
};
}
- void ReadFromDataStream(InputDataStream& stream)
- {
+ void ReadFromDataStream(InputDataStream& stream) {
stream.Value(x);
stream.Value(y);
}
- void WriteToDataStream(OutputDataStream& stream) const
- {
+ void WriteToDataStream(OutputDataStream& stream) const {
stream.Value(x);
stream.Value(y);
}
@@ -46,15 +42,13 @@ using Vec2i = Vec2<int>;
using Vec2f = Vec2<float>;
template <class T>
-struct Vec3
-{
+struct Vec3 {
T x = 0;
T y = 0;
T z = 0;
template <class TTarget>
- Vec3<TTarget> Cast() const
- {
+ Vec3<TTarget> Cast() const {
return {
static_cast<TTarget>(x),
static_cast<TTarget>(y),
@@ -62,15 +56,13 @@ struct Vec3
};
}
- void ReadFromDataStream(InputDataStream& stream)
- {
+ void ReadFromDataStream(InputDataStream& stream) {
stream.Value(x);
stream.Value(y);
stream.Value(z);
}
- void WriteToDataStream(OutputDataStream& stream) const
- {
+ void WriteToDataStream(OutputDataStream& stream) const {
stream.Value(x);
stream.Value(y);
stream.Value(z);
@@ -93,16 +85,14 @@ using Vec3i = Vec3<int>;
using Vec3f = Vec3<float>;
template <class T>
-struct Vec4
-{
+struct Vec4 {
T x = 0;
T y = 0;
T z = 0;
T w = 0;
template <class TTarget>
- Vec4<TTarget> Cast() const
- {
+ Vec4<TTarget> Cast() const {
return {
static_cast<TTarget>(x),
static_cast<TTarget>(y),
@@ -111,16 +101,14 @@ struct Vec4
};
}
- void ReadFromDataStream(InputDataStream& stream)
- {
+ void ReadFromDataStream(InputDataStream& stream) {
stream.Value(x);
stream.Value(y);
stream.Value(z);
stream.Value(w);
}
- void WriteToDataStream(OutputDataStream& stream) const
- {
+ void WriteToDataStream(OutputDataStream& stream) const {
stream.Value(x);
stream.Value(y);
stream.Value(z);
diff --git a/app/source/Cplt/Utils/VectorHash.hpp b/app/source/Cplt/Utils/VectorHash.hpp
index f649367..80a92fb 100644
--- a/app/source/Cplt/Utils/VectorHash.hpp
+++ b/app/source/Cplt/Utils/VectorHash.hpp
@@ -7,10 +7,8 @@
#include <functional>
template <class T>
-struct std::hash<Vec2<T>>
-{
- size_t operator()(const Vec2<T>& vec) const
- {
+struct std::hash<Vec2<T>> {
+ size_t operator()(const Vec2<T>& vec) const {
size_t result;
HashUtils::Combine(result, vec.x);
HashUtils::Combine(result, vec.y);
@@ -19,10 +17,8 @@ struct std::hash<Vec2<T>>
};
template <class T>
-struct std::hash<Vec3<T>>
-{
- size_t operator()(const Vec3<T>& vec) const
- {
+struct std::hash<Vec3<T>> {
+ size_t operator()(const Vec3<T>& vec) const {
size_t result;
HashUtils::Combine(result, vec.x);
HashUtils::Combine(result, vec.y);
@@ -32,10 +28,8 @@ struct std::hash<Vec3<T>>
};
template <class T>
-struct std::hash<Vec4<T>>
-{
- size_t operator()(const Vec4<T>& vec) const
- {
+struct std::hash<Vec4<T>> {
+ size_t operator()(const Vec4<T>& vec) const {
size_t result;
HashUtils::Combine(result, vec.x);
HashUtils::Combine(result, vec.y);