#pragma once // MassBuilderSaveTool // Copyright (C) 2021-2022 Guillaume Jacquemin // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include #include #include #include #include using namespace Corrade; using namespace Magnum; class BinaryReader { public: explicit BinaryReader(Containers::StringView filename); ~BinaryReader(); auto open() -> bool; auto eof() -> bool; auto position() -> Long; auto seek(Long position) -> bool; void closeFile(); auto readChar(char& value) -> bool; auto readByte(Byte& value) -> bool; auto readUnsignedByte(UnsignedByte& value) -> bool; auto readShort(Short& value) -> bool; auto readUnsignedShort(UnsignedShort& value) -> bool; auto readInt(Int& value) -> bool; auto readUnsignedInt(UnsignedInt& value) -> bool; auto readLong(Long& value) -> bool; auto readUnsignedLong(UnsignedLong& value) -> bool; auto readFloat(Float& value) -> bool; auto readDouble(Double& value) -> bool; auto readArray(Containers::Array& array, std::size_t count) -> bool; template auto readValue(T& value) -> bool { return fread(&value, sizeof(T), 1, _file) == sizeof(T); } template auto readStaticArray(Containers::StaticArray& array) -> bool { return std::fread(array.data(), sizeof(char), S, _file) == S; } auto readUEString(Containers::String& str) -> bool; auto peekChar() -> Int; private: std::FILE* _file = nullptr; };