// // EuropaTools // // (C) 2021-2022 modeco80 // // SPDX-License-Identifier: GPL-3.0-or-later // #ifndef EUROPA_IO_PAKFILE_H #define EUROPA_IO_PAKFILE_H #include #include #include namespace europa::io { struct PakReader; struct PakWriter; struct PakFile { using DataType = std::vector; template void InitAs(const T& value) { toc = value; } void InitAs(structs::PakVersion version) { switch(version) { case structs::PakVersion::Ver3: toc = structs::PakHeader_V3::TocEntry{}; break; case structs::PakVersion::Ver4: toc = structs::PakHeader_V4::TocEntry{}; break; case structs::PakVersion::Ver5: toc = structs::PakHeader_V5::TocEntry{}; break; } } /** * Get the file data. */ [[nodiscard]] const DataType& GetData() const { return data; } /** * Get the TOC entry responsible. */ template [[nodiscard]] const T& GetTOCEntry() const { return std::get(toc); } void SetData(DataType&& data) { this->data = std::move(data); } std::uint32_t GetOffset() const { std::uint32_t size{}; std::visit([&](auto& entry) { size = entry.offset; }, toc); return size; } std::uint32_t GetSize() const { std::uint32_t size{}; std::visit([&](auto& entry) { size = entry.size; }, toc); return size; } void FillTOCEntry() { std::visit([&](auto& entry) { entry.size = static_cast(data.size()); }, toc); } template void Visit(const Cb& cb) { std::visit(cb, toc); } private: friend PakReader; friend PakWriter; std::vector data; structs::PakTocEntryVariant toc; }; } // namespace europa::io #endif // EUROPA_IO_PAKFILE_H