From 927e065f9829045247be7c0b3296408b6f577c1f Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 12 Jun 2022 13:44:58 +0200 Subject: feat: add reading RLE files --- src/errors/RLE_reader.hpp | 19 ++++++++++++++++ src/errors/io.hpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/errors/RLE_reader.hpp create mode 100644 src/errors/io.hpp (limited to 'src/errors') diff --git a/src/errors/RLE_reader.hpp b/src/errors/RLE_reader.hpp new file mode 100644 index 0000000..39b4ddb --- /dev/null +++ b/src/errors/RLE_reader.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include +#include +#include + +class InvalidRLEFileError : public std::runtime_error +{ +public: + explicit InvalidRLEFileError( + const std::filesystem::path &path, + const std::string_view &reason) noexcept + : std::runtime_error( + fmt::format("Invalid RLE file '{}'. {}", path.string(), reason)) + { + } +}; diff --git a/src/errors/io.hpp b/src/errors/io.hpp new file mode 100644 index 0000000..1d0aec3 --- /dev/null +++ b/src/errors/io.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include "util/fs.hpp" + +#include + +#include +#include +#include + +class IOError : public std::runtime_error +{ +public: + IOError() noexcept : std::runtime_error("Unknown IO error") {} + + explicit IOError(const std::string &error_message) noexcept + : std::runtime_error(error_message) + { + } +}; + +class NoSuchFileOrDirectoryError : public IOError +{ +public: + explicit NoSuchFileOrDirectoryError(const std::filesystem::path &path) noexcept + : IOError( + fmt::format("No file or directory exists with path '{}'", path.string())) + { + } +}; + +class WrongFileTypeError : public IOError +{ +public: + explicit WrongFileTypeError( + const std::filesystem::path &path, + std::filesystem::file_type expected_file_type, + std::filesystem::file_type actual_file_type) noexcept + : IOError(fmt::format( + "Wrong file type of file with path '{}'. Expected {}, is {}", + path.string(), + file_type_names.at(expected_file_type), + file_type_names.at(actual_file_type))) + { + } +}; + +class FileNotOpenError : public IOError +{ +public: + explicit FileNotOpenError(const std::filesystem::path &path) noexcept + : IOError(fmt::format("Failed to open file with path '{}'", path.string())) + { + } +}; -- cgit v1.2.3-18-g5258