#pragma once #include #include namespace ctrff { class BinFile { public: BinFile() = default; ~BinFile() = default; virtual void Write(std::fstream& s) const = 0; virtual void Read(std::fstream& s) = 0; }; class CTRFF_API BinUtil { public: BinUtil(std::fstream& f, bool big = false) : m_file(f), m_big(big) {} ~BinUtil() = default; void SetEndianess(bool big) { m_big = big; } template void Read(T& v); template void Write(const T& v); /** Note that this func ignores Endianness */ template void ReadEx(T& v) { static_assert(std::is_trivially_copyable_v, "Cannot Read type T"); m_file.read(reinterpret_cast(&v), sizeof(T)); } /** Note that this func ignores Endianness */ template void WriteEx(T& v) { m_file.write(reinterpret_cast(&v), sizeof(T)); } private: std::fstream& m_file; bool m_big; }; } // namespace ctrff