updated build system

This commit is contained in:
2024-08-07 10:38:34 -05:00
parent 9d3e4b8767
commit eddc6bb67c
51 changed files with 2142 additions and 1748 deletions

View File

@@ -27,75 +27,103 @@
namespace repertory::utils::file {
class file final {
public:
[[nodiscard]] static auto open_file(std::filesystem::path path) -> file;
[[nodiscard]] static auto open_file(std::filesystem::path path,
bool read_only = false) -> file;
[[nodiscard]] static auto
open_or_create_file(std::filesystem::path path) -> file;
[[nodiscard]] static auto open_or_create_file(std::filesystem::path path,
bool read_only = false) -> file;
file() noexcept = default;
protected:
file(std::fstream stream, std::filesystem::path path)
: path_(std::move(path)), stream_(std::move(stream)) {}
file() = default;
file(file_t file_ptr, std::filesystem::path path)
: file_(std::move(file_ptr)), path_(std::move(path)) {}
public:
file(const file &) = delete;
file(file &&file_) noexcept = default;
file(file &&move_file) noexcept
: file_(std::move(move_file.file_)),
path_(std::move(move_file.path_))
#if defined(_WIN32)
,
mtx_()
#endif // defined(_WIN32)
{
}
~file() { close(); }
auto operator=(const file &) noexcept -> file & = delete;
auto operator=(file &&file_) noexcept -> file & = default;
auto operator=(file &&move_file) noexcept -> file & {
if (&move_file != this) {
file_ = std::move(move_file.file_);
path_ = std::move(move_file.path_);
}
return *this;
}
private:
std::error_code error_{};
file_t file_{nullptr};
std::filesystem::path path_;
std::fstream stream_;
#if defined(_WIN32)
mutable std::recursive_mutex mtx_{};
#endif // defined(_WIN32)
public:
void close();
[[nodiscard]] auto get_error_code() const -> std::error_code {
return error_;
}
void flush();
[[nodiscard]] auto get_handle() const -> native_handle;
[[nodiscard]] auto get_path() const -> std::filesystem::path { return path_; }
[[nodiscard]] auto move_to(std::filesystem::path new_path) -> bool;
[[nodiscard]] auto read(data_buffer &data, std::uint64_t offset,
std::size_t *total_read = nullptr) -> bool {
return read_(reinterpret_cast<unsigned char *>(data.data()), data.size(),
offset, total_read);
}
std::size_t *total_read = nullptr) -> bool;
[[nodiscard]] auto read(unsigned char *data, std::size_t to_read,
std::uint64_t offset,
std::size_t *total_read = nullptr) -> bool;
[[nodiscard]] auto read_all(data_buffer &data, std::uint64_t offset,
std::size_t *total_read = nullptr) -> bool;
[[nodiscard]] auto remove() -> bool;
[[nodiscard]] auto size() const -> std::uint64_t;
[[nodiscard]] auto truncate() -> bool { return truncate(0U); }
[[nodiscard]] auto truncate(std::size_t size) -> bool;
[[nodiscard]] auto write(const data_buffer &data, std::uint64_t offset,
std::size_t *total_written = nullptr) -> bool {
return write_(reinterpret_cast<const unsigned char *>(data.data()),
data.size() * sizeof(data_buffer::value_type), offset,
total_written);
}
[[nodiscard]] auto write(std::string_view data, std::uint64_t offset,
std::size_t *total_written = nullptr) -> bool {
return write_(reinterpret_cast<const unsigned char *>(data.data()),
data.size(), offset, total_written);
}
#if defined(PROJECT_ENABLE_JSON)
[[nodiscard]] auto write_json(const nlohmann::json &data,
std::size_t *total_written = nullptr) -> bool {
auto str_data = data.dump();
return write_(reinterpret_cast<const unsigned char *>(str_data.c_str()),
str_data.size(), 0U, total_written);
[[nodiscard]] auto write(std::wstring_view data, std::uint64_t offset,
std::size_t *total_written = nullptr) -> bool {
return write_(reinterpret_cast<const unsigned char *>(data.data()),
data.size() * sizeof(wchar_t), offset, total_written);
}
#endif // defined(PROJECT_ENABLE_JSON)
[[nodiscard]] operator bool() const { return stream_.is_open(); }
public:
[[nodiscard]] operator bool() const { return file_ != nullptr; }
private:
[[nodiscard]] auto read_(unsigned char *data, std::size_t to_read,
std::uint64_t offset,
std::size_t *total_read) -> bool;
[[nodiscard]] auto write_(const unsigned char *data, std::size_t to_write,
std::size_t offset,
std::size_t *total_written) -> bool;