Debian Codegraph @

BambooTracker/io/file_io_error.hpp

raw
1 /*
2 * Copyright (C) 2018-2020 Rerrah
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #pragma once
27
28 #include <stdexcept>
29 #include <cstdint>
30 #include <string>
31 #include "io_file_type.hpp"
32
33 namespace io
34 {
35 class FileIOError : public std::runtime_error
36 {
37 protected:
38 const FileType ftype_;
39
40 FileIOError(const std::string& text, const FileType ftype)
41 : std::runtime_error(text), ftype_(ftype) {}
42
43 public:
44 inline FileType fileType() const { return ftype_; }
45 };
46
47 class FileNotExistError : public FileIOError
48 {
49 FileNotExistError(const FileType type)
50 : FileIOError("File not exist error", type) {}
51 };
52
53 class FileUnsupportedError : public FileIOError
54 {
55 public:
56 FileUnsupportedError(const FileType type)
57 : FileIOError("File unsupported error", type) {}
58 };
59
60 class FileVersionError : public FileIOError
61 {
62 public:
63 FileVersionError(const FileType type)
64 : FileIOError("File version error", type) {}
65 };
66
67 class FileCorruptionError : public FileIOError
68 {
69 private:
70 size_t pos_;
71
72 public:
73 FileCorruptionError(const FileType type, size_t pos, const std::string& desc = "File corruption error")
74 : FileIOError(desc, type), pos_(pos) {}
75 inline size_t position() const { return pos_; }
76 };
77 }