Skip to content

Commit

Permalink
Remove endianness from reader & writer instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Dec 3, 2024
1 parent 9897cc4 commit 1568eae
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 231 deletions.
7 changes: 1 addition & 6 deletions soup/BufferRefWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ NAMESPACE_SOUP
Buffer& buf;

BufferRefWriter(Buffer& buf)
: Writer(ENDIAN_LITTLE), buf(buf)
{
}

[[deprecated]] BufferRefWriter(Buffer& buf, Endian endian)
: Writer(endian), buf(buf)
: Writer(), buf(buf)
{
}

Expand Down
12 changes: 1 addition & 11 deletions soup/BufferWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@ NAMESPACE_SOUP
Buffer buf{};

BufferWriter()
: Writer(ENDIAN_LITTLE)
{
}

[[deprecated]] BufferWriter(Endian endian)
: Writer(endian)
{
}

[[deprecated]] BufferWriter(bool little_endian)
: Writer(little_endian)
: Writer()
{
}

Expand Down
22 changes: 3 additions & 19 deletions soup/FileReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,20 @@ NAMESPACE_SOUP
std::ifstream s;

FileReader(const std::string& path)
: Reader(true), s(path, std::ios::binary)
{
}

[[deprecated]] FileReader(const std::string& path, bool little_endian)
: Reader(little_endian), s(path, std::ios::binary)
: Reader(), s(path, std::ios::binary)
{
}

#if SOUP_WINDOWS && !SOUP_CROSS_COMPILE
FileReader(const std::wstring& path)
: Reader(true), s(path, std::ios::binary)
{
}

[[deprecated]] FileReader(const std::wstring& path, bool little_endian)
: Reader(little_endian), s(path, std::ios::binary)
: Reader(), s(path, std::ios::binary)
{
}
#endif

template <class T, SOUP_RESTRICT(std::is_same_v<T, std::filesystem::path>)>
FileReader(const T& path)
: Reader(true), s(path, std::ios::binary)
{
}

template <class T, SOUP_RESTRICT(std::is_same_v<T, std::filesystem::path>)>
[[deprecated]] FileReader(const T& path, bool little_endian)
: Reader(little_endian), s(path, std::ios::binary)
: Reader(), s(path, std::ios::binary)
{
}

Expand Down
22 changes: 3 additions & 19 deletions soup/FileWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,20 @@ NAMESPACE_SOUP
std::ofstream s;

FileWriter(const std::string& path)
: Writer(true), s(path, std::ios::binary)
{
}

[[deprecated]] FileWriter(const std::string& path, bool little_endian)
: Writer(little_endian), s(path, std::ios::binary)
: Writer(), s(path, std::ios::binary)
{
}

#if SOUP_WINDOWS && !SOUP_CROSS_COMPILE
FileWriter(const std::wstring& path)
: Writer(true), s(path, std::ios::binary)
{
}

[[deprecated]] FileWriter(const std::wstring& path, bool little_endian)
: Writer(little_endian), s(path, std::ios::binary)
: Writer(), s(path, std::ios::binary)
{
}
#endif

template <class T, SOUP_RESTRICT(std::is_same_v<T, std::filesystem::path>)>
FileWriter(const T& path)
: Writer(true), s(path, std::ios::binary)
{
}

template <class T, SOUP_RESTRICT(std::is_same_v<T, std::filesystem::path>)>
[[deprecated]] FileWriter(const T& path, bool little_endian)
: Writer(little_endian), s(path, std::ios::binary)
: Writer(), s(path, std::ios::binary)
{
}

Expand Down
7 changes: 1 addition & 6 deletions soup/IstreamReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ NAMESPACE_SOUP
std::istream& is;

IstreamReader(std::istream& is)
: Reader(ENDIAN_LITTLE), is(is)
{
}

[[deprecated]] IstreamReader(std::istream& is, Endian endian)
: Reader(endian), is(is)
: Reader(), is(is)
{
}

Expand Down
13 changes: 1 addition & 12 deletions soup/MemoryRefReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ NAMESPACE_SOUP
size_t offset = 0;

MemoryRefReader(const void* _data, size_t size)
: Reader(true), data(reinterpret_cast<const uint8_t*>(_data)), size(size)
{
}

[[deprecated]] MemoryRefReader(const void* _data, size_t size, bool little_endian)
: Reader(little_endian), data(reinterpret_cast<const uint8_t*>(_data)), size(size)
: Reader(), data(reinterpret_cast<const uint8_t*>(_data)), size(size)
{
}

Expand All @@ -31,12 +26,6 @@ NAMESPACE_SOUP
{
}

template <typename T, SOUP_RESTRICT(!std::is_pointer_v<T>)>
[[deprecated]] MemoryRefReader(const T& t, bool little_endian)
: Reader(little_endian), data(reinterpret_cast<const uint8_t*>(t.data())), size(t.size())
{
}

~MemoryRefReader() final = default;

bool hasMore() noexcept final
Expand Down
7 changes: 1 addition & 6 deletions soup/OstreamWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ NAMESPACE_SOUP
std::ostream& os;

OstreamWriter(std::ostream& os)
: Writer(ENDIAN_LITTLE), os(os)
{
}

[[deprecated]] OstreamWriter(std::ostream& os, Endian endian)
: Writer(endian), os(os)
: Writer(), os(os)
{
}

Expand Down
19 changes: 2 additions & 17 deletions soup/StringReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,12 @@ NAMESPACE_SOUP
size_t offset = 0;

StringReader() noexcept
: Reader(ENDIAN_LITTLE)
{
}

[[deprecated]] StringReader(Endian endian) noexcept
: Reader(endian)
: Reader()
{
}

StringReader(std::string&& data) noexcept
: Reader(ENDIAN_LITTLE), data(std::move(data))
{
}

[[deprecated]] StringReader(std::string&& data, Endian endian) noexcept
: Reader(endian), data(std::move(data))
{
}

[[deprecated]] StringReader(std::string&& data, bool little_endian) noexcept
: Reader(little_endian), data(std::move(data))
: Reader(), data(std::move(data))
{
}

Expand Down
7 changes: 1 addition & 6 deletions soup/StringRefWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ NAMESPACE_SOUP
std::string& str;

StringRefWriter(std::string& str)
: Writer(true), str(str)
{
}

[[deprecated]] StringRefWriter(std::string& str, bool little_endian)
: Writer(little_endian), str(str)
: Writer(), str(str)
{
}

Expand Down
12 changes: 1 addition & 11 deletions soup/StringWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@ NAMESPACE_SOUP
std::string data{};

StringWriter()
: Writer(ENDIAN_LITTLE)
{
}

[[deprecated]] StringWriter(Endian endian)
: Writer(endian)
{
}

[[deprecated]] StringWriter(bool little_endian)
: Writer(little_endian)
: Writer()
{
}

Expand Down
118 changes: 1 addition & 117 deletions soup/ioBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,11 @@ NAMESPACE_SOUP
class ioVirtualBase
{
protected:
const bool native_endianness;

ioVirtualBase(Endian endian) noexcept
: native_endianness(ENDIAN_NATIVE == endian)
{
}

ioVirtualBase(bool little_endian) noexcept
: ioVirtualBase(little_endian ? ENDIAN_LITTLE : ENDIAN_BIG)
ioVirtualBase() noexcept
{
}

public:
[[deprecated]] bool isBigEndian() const noexcept
{
return (ENDIAN_BIG == ENDIAN_NATIVE) == native_endianness;
}

[[deprecated]] bool isLittleEndian() const noexcept
{
return (ENDIAN_LITTLE == ENDIAN_NATIVE) == native_endianness;
}

virtual ~ioVirtualBase() = default;

virtual bool raw(void* data, size_t len) noexcept = 0;
Expand Down Expand Up @@ -94,11 +76,6 @@ NAMESPACE_SOUP
template <typename T>
bool ser(T& v) noexcept;

[[deprecated]] bool u16(uint16_t& v) noexcept
{
return native_endianness ? u16<true>(v) : u16<false>(v);
}

[[deprecated("Renamed to u16be")]] bool u16_be(uint16_t& v) noexcept { return u16be(v); }
[[deprecated("Renamed to u16le")]] bool u16_le(uint16_t& v) noexcept { return u16le(v); }

Expand Down Expand Up @@ -137,11 +114,6 @@ NAMESPACE_SOUP
}

public:
[[deprecated]] bool u32(uint32_t& v) noexcept
{
return native_endianness ? u32<true>(v) : u32<false>(v);
}

[[deprecated("Renamed to u32be")]] bool u32_be(uint32_t& v) noexcept { return u32be(v); }
[[deprecated("Renamed to u32le")]] bool u32_le(uint32_t& v) noexcept { return u32le(v); }

Expand Down Expand Up @@ -180,11 +152,6 @@ NAMESPACE_SOUP
}

public:
[[deprecated]] bool u64(uint64_t& v) noexcept
{
return native_endianness ? u64<true>(v) : u64<false>(v);
}

[[deprecated("Renamed to u64be")]] bool u64_be(uint64_t& v) noexcept { return u64be(v); }
[[deprecated("Renamed to u64le")]] bool u64_le(uint64_t& v) noexcept { return u64le(v); }

Expand Down Expand Up @@ -240,11 +207,6 @@ NAMESPACE_SOUP
bool i64le(int64_t& v) noexcept { return u64le(*(uint64_t*)&v); }
bool i64be(int64_t& v) noexcept { return u64be(*(uint64_t*)&v); }

bool u24(uint32_t& v) noexcept
{
return native_endianness ? u24<true>(v) : u24<false>(v);
}

[[deprecated("Renamed to u24be")]] bool u24_be(uint32_t& v) noexcept { return u24be(v); }
[[deprecated("Renamed to u24le")]] bool u24_le(uint32_t& v) noexcept { return u24le(v); }

Expand Down Expand Up @@ -281,84 +243,6 @@ NAMESPACE_SOUP
}

public:
[[deprecated]] bool u40(uint64_t& v) noexcept
{
if constexpr (is_read)
{
v = 0;
}
if (native_endianness)
{
return u8(((uint8_t*)&v)[0])
&& u8(((uint8_t*)&v)[1])
&& u8(((uint8_t*)&v)[2])
&& u8(((uint8_t*)&v)[3])
&& u8(((uint8_t*)&v)[4]);
}
else
{
return u8(((uint8_t*)&v)[4])
&& u8(((uint8_t*)&v)[3])
&& u8(((uint8_t*)&v)[2])
&& u8(((uint8_t*)&v)[1])
&& u8(((uint8_t*)&v)[0]);
}
}

[[deprecated]] bool u48(uint64_t& v) noexcept
{
if constexpr (is_read)
{
v = 0;
}
if (native_endianness)
{
return u8(((uint8_t*)&v)[0])
&& u8(((uint8_t*)&v)[1])
&& u8(((uint8_t*)&v)[2])
&& u8(((uint8_t*)&v)[3])
&& u8(((uint8_t*)&v)[4])
&& u8(((uint8_t*)&v)[5]);
}
else
{
return u8(((uint8_t*)&v)[5])
&& u8(((uint8_t*)&v)[4])
&& u8(((uint8_t*)&v)[3])
&& u8(((uint8_t*)&v)[2])
&& u8(((uint8_t*)&v)[1])
&& u8(((uint8_t*)&v)[0]);
}
}

[[deprecated]] bool u56(uint64_t& v) noexcept
{
if constexpr (is_read)
{
v = 0;
}
if (native_endianness)
{
return u8(((uint8_t*)&v)[0])
&& u8(((uint8_t*)&v)[1])
&& u8(((uint8_t*)&v)[2])
&& u8(((uint8_t*)&v)[3])
&& u8(((uint8_t*)&v)[4])
&& u8(((uint8_t*)&v)[5])
&& u8(((uint8_t*)&v)[6]);
}
else
{
return u8(((uint8_t*)&v)[6])
&& u8(((uint8_t*)&v)[5])
&& u8(((uint8_t*)&v)[4])
&& u8(((uint8_t*)&v)[3])
&& u8(((uint8_t*)&v)[2])
&& u8(((uint8_t*)&v)[1])
&& u8(((uint8_t*)&v)[0]);
}
}

bool f32(float& v) noexcept
{
return u32le(*reinterpret_cast<uint32_t*>(&v));
Expand Down
Loading

0 comments on commit 1568eae

Please sign in to comment.