diff options
Diffstat (limited to 'core/src/Utils/IO/DataStream.hpp')
-rw-r--r-- | core/src/Utils/IO/DataStream.hpp | 210 |
1 files changed, 0 insertions, 210 deletions
diff --git a/core/src/Utils/IO/DataStream.hpp b/core/src/Utils/IO/DataStream.hpp deleted file mode 100644 index c0891ac..0000000 --- a/core/src/Utils/IO/DataStream.hpp +++ /dev/null @@ -1,210 +0,0 @@ -#pragma once - -#include "FileStream.hpp" -#include "cplt_fwd.hpp" - -#include <bit> -#include <cstddef> -#include <cstdint> -#include <span> - -class BaseDataStream -{ -private: - std::endian mEndian = std::endian::big; - -public: - std::endian GetEndianness() const; - void SetEndianness(std::endian endianness); -}; - -class InputDataStream : public BaseDataStream -{ -private: - InputFileStream mBackend; - -public: - static constexpr bool IsSerializer() - { - return false; - } - - InputDataStream(InputFileStream stream); - - void ReadBytes(size_t byteCount, std::byte* buffer); - void ReadBytes(size_t byteCount, char* buffer); - void ReadBytes(size_t byteCount, signed char* buffer); - void ReadBytes(size_t byteCount, unsigned char* buffer); - - template <class TInserter> - void ReadBytes(size_t byteCount, TInserter&& inserter) - { - for (size_t i = 0; i < byteCount; ++i) { - uint8_t byte; - Read(byte); - - inserter = byte; - } - } - - void Read(int8_t& n); - void Read(int16_t& n); - void Read(int32_t& n); - void Read(int64_t& n); - - void Read(uint8_t& n); - void Read(uint16_t& n); - void Read(uint32_t& n); - void Read(uint64_t& n); - - void Read(float& n); - void Read(double& n); - - template <class TEnum> - requires std::is_enum_v<TEnum> - void ReadEnum(TEnum& e) - { - std::underlying_type_t<TEnum> n; - Read(n); - e = static_cast<TEnum>(e); - } - - template <class TObject> - void ReadObject(TObject& obj) - { - obj.ReadFromDataStream(*this); - } - - template <class TAdapter, class TObject> - void ReadObjectAdapted(TObject& obj) - { - TAdapter::ReadFromDataStream(*this, obj); - } - -public: - // Proxy functions for writing templated IO functions - - template <class T> - void Bytes(size_t byteCount, T* buffer) - { - ReadBytes(byteCount, buffer); - } - - template <class T> - void Value(T& t) - { - Read(t); - } - - template <class T> - void Enum(T& t) - { - ReadEnum(t); - } - - template <class T> - void Object(T& obj) - { - ReadObject(obj); - } - - template <class TAdapter, class TObject> - void ObjectAdapted(TObject& obj) - { - ReadObjectAdapted<TAdapter>(obj); - } -}; - -class OutputDataStream : public BaseDataStream -{ -private: - OutputFileStream mBackend; - -public: - static constexpr bool IsSerializer() - { - return true; - } - - OutputDataStream(OutputFileStream stream); - - void WriteBytes(size_t byteCount, const std::byte* buffer); - void WriteBytes(size_t byteCount, const char* buffer); - void WriteBytes(size_t byteCount, const signed char* buffer); - void WriteBytes(size_t byteCount, const unsigned char* buffer); - - template <class TIterator> - void WriteBytes(TIterator&& begin, TIterator&& end) - { - for (; begin != end; ++begin) { - uint8_t byte = *begin; - Write(byte); - } - } - - void Write(int8_t n); - void Write(int16_t n); - void Write(int32_t n); - void Write(int64_t n); - - void Write(uint8_t n); - void Write(uint16_t n); - void Write(uint32_t n); - void Write(uint64_t n); - - void Write(float n); - void Write(double n); - - template <class TEnum> - requires std::is_enum_v<TEnum> - void WriteEnum(TEnum e) - { - auto n = static_cast<std::underlying_type_t<TEnum>>(e); - Write(n); - } - - template <class TObject> - void WriteObject(const TObject& obj) - { - obj.WriteToDataStream(*this); - } - - template <class TAdapter, class TObject> - void WriteObjectAdapted(const TObject& obj) - { - TAdapter::WriteToDataStream(*this, obj); - } - -public: - // Proxy functions for writing templated IO functions - - template <class T> - void Bytes(size_t byteCount, T* buffer) - { - WriteBytes(byteCount, buffer); - } - - template <class T> - void Value(T t) - { - Write(t); - } - - template <class T> - void Enum(T t) - { - WriteEnum(t); - } - - template <class T> - void Object(T& obj) - { - WriteObject(obj); - } - - template <class TAdapter, class TObject> - void ObjectAdapted(TObject& obj) - { - WriteObjectAdapted<TAdapter>(obj); - } -}; |