Antkeeper  0.0.1
physfs-deserialize-context.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_RESOURCES_PHYSFS_DESERIALIZE_CONTEXT_HPP
21 #define ANTKEEPER_RESOURCES_PHYSFS_DESERIALIZE_CONTEXT_HPP
22 
24 #include <physfs.h>
25 #include <filesystem>
26 
31 {
32 public:
40  explicit physfs_deserialize_context(const std::filesystem::path& path) noexcept(false);
41 
45  physfs_deserialize_context() noexcept = default;
46 
50  virtual ~physfs_deserialize_context();
51 
59  void open(const std::filesystem::path& path) noexcept(false);
60 
64  void close() noexcept;
65 
69  [[nodiscard]] bool is_open() const noexcept;
70 
71  [[nodiscard]] const std::filesystem::path& path() const noexcept override;
72  [[nodiscard]] bool error() const noexcept override;
73  [[nodiscard]] bool eof() const noexcept override;
74  [[nodiscard]] std::size_t size() const noexcept override;
75  [[nodiscard]] std::size_t tell() const override;
76  void seek(std::size_t offset) override;
77  std::size_t read8(std::byte* data, std::size_t count) noexcept(false) override;
78  std::size_t read16_le(std::byte* data, std::size_t count) noexcept(false) override;
79  std::size_t read16_be(std::byte* data, std::size_t count) noexcept(false) override;
80  std::size_t read32_le(std::byte* data, std::size_t count) noexcept(false) override;
81  std::size_t read32_be(std::byte* data, std::size_t count) noexcept(false) override;
82  std::size_t read64_le(std::byte* data, std::size_t count) noexcept(false) override;
83  std::size_t read64_be(std::byte* data, std::size_t count) noexcept(false) override;
84 
85 private:
86  PHYSFS_File* m_file{nullptr};
87  std::filesystem::path m_path;
88  bool m_eof{true};
89  bool m_error{false};
90 };
91 
92 #endif // ANTKEEPER_RESOURCES_PHYSFS_DESERIALIZE_CONTEXT_HPP
Deserialize context implementation using PhysicsFS.
physfs_deserialize_context() noexcept=default
Constructs a PhysicsFS deserialize context.
std::size_t read16_be(std::byte *data, std::size_t count) noexcept(false) override
Reads 16-bit (word) big-endian data.
void close() noexcept
Closes the associated file using PhysicsFS.
std::size_t read32_be(std::byte *data, std::size_t count) noexcept(false) override
Reads 32-bit (double word) big-endian data.
void open(const std::filesystem::path &path) noexcept(false)
Opens a file using PhysicsFS and associates it with the deserialize context.
const std::filesystem::path & path() const noexcept override
Returns the path associated with this deserialize context.
void seek(std::size_t offset) override
Seeks to a position in the file.
std::size_t tell() const override
Returns the offsets from the start of the file to the current position, in bytes.
std::size_t read8(std::byte *data, std::size_t count) noexcept(false) override
Reads 8-bit (byte) data.
std::size_t read32_le(std::byte *data, std::size_t count) noexcept(false) override
Reads 32-bit (double word) little-endian data.
std::size_t read64_le(std::byte *data, std::size_t count) noexcept(false) override
Reads 64-bit (quad word) little-endian data.
bool error() const noexcept override
Returns true if an error occured during a read operation or initialization, false otherwise.
bool eof() const noexcept override
Returns true if the end of a file was reached.
std::size_t size() const noexcept override
Returns the size of the file, in bytes.
std::size_t read16_le(std::byte *data, std::size_t count) noexcept(false) override
Reads 16-bit (word) little-endian data.
std::size_t read64_be(std::byte *data, std::size_t count) noexcept(false) override
Reads 64-bit (quad word) big-endian data.
bool is_open() const noexcept
Returns true if the PhysicsFS file associated with this deserialize context is open,...
constexpr int count(T x) noexcept
Returns the number of set bits in a value, known as a population count or Hamming weight.
Definition: bit-math.hpp:211
T offset(T longitude)
Calculates the UTC offset at a given longitude.
Definition: utc.hpp:38
Provides access to a deserialization state.