81 lines
2.4 KiB
C++
81 lines
2.4 KiB
C++
#pragma once
|
|
|
|
// MassBuilderSaveTool
|
|
// Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
|
|
#include <Corrade/Containers/Containers.h>
|
|
#include <Corrade/Containers/StaticArray.h>
|
|
#include <Corrade/Containers/StringView.h>
|
|
|
|
using namespace Corrade;
|
|
|
|
namespace BinaryIo {
|
|
|
|
class Reader {
|
|
public:
|
|
explicit Reader(Containers::StringView filename);
|
|
~Reader();
|
|
|
|
Reader(const Reader& other) = delete;
|
|
Reader& operator=(const Reader& other) = delete;
|
|
|
|
Reader(Reader&& other) = default;
|
|
Reader& operator=(Reader&& other) = default;
|
|
|
|
bool open();
|
|
bool eof();
|
|
auto position() -> std::int64_t;
|
|
|
|
bool seek(std::int64_t position);
|
|
|
|
void closeFile();
|
|
|
|
bool readChar(char& value);
|
|
bool readInt8(std::int8_t& value);
|
|
bool readUint8(std::uint8_t& value);
|
|
bool readInt16(std::int16_t& value);
|
|
bool readUint16(std::uint16_t& value);
|
|
bool readInt32(std::int32_t& value);
|
|
bool readUint32(std::uint32_t& value);
|
|
bool readInt64(std::int64_t& value);
|
|
bool readUint64(std::uint64_t& value);
|
|
bool readFloat(float& value);
|
|
bool readDouble(double& value);
|
|
bool readArray(Containers::Array<char>& array, std::size_t count);
|
|
|
|
template<typename T>
|
|
bool readValue(T& value) {
|
|
return fread(&value, sizeof(T), 1, _file) == 1;
|
|
}
|
|
|
|
template<std::size_t S>
|
|
bool readStaticArray(Containers::StaticArray<S, char>& array) {
|
|
return std::fread(array.data(), sizeof(char), S, _file) == S;
|
|
}
|
|
|
|
bool readUEString(Containers::String& str);
|
|
|
|
auto peekChar() -> std::int32_t;
|
|
|
|
private:
|
|
std::FILE* _file = nullptr;
|
|
};
|
|
|
|
}
|