aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Utils/IO/DataStream.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-11-27 12:04:31 -0800
committerrtk0c <[email protected]>2022-11-27 12:04:31 -0800
commit182c8f8357739f905bbd721006480502435b6b43 (patch)
tree082613a474d863182e2ad8f2167f1643f26e67a3 /app/source/Cplt/Utils/IO/DataStream.cpp
parentb01ed99a1cd0c863c8709930658513c04dd70f61 (diff)
Update brace style to match rest of my projectscplt-imgui
Diffstat (limited to 'app/source/Cplt/Utils/IO/DataStream.cpp')
-rw-r--r--app/source/Cplt/Utils/IO/DataStream.cpp108
1 files changed, 36 insertions, 72 deletions
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);