Remove join function; the code is long and I don't think anybody
[dcpomatic.git] / src / lib / exceptions.h
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file  src/lib/exceptions.h
22  *  @brief Our exceptions.
23  */
24
25 #ifndef DCPOMATIC_EXCEPTIONS_H
26 #define DCPOMATIC_EXCEPTIONS_H
27
28 extern "C" {
29 #include <libavutil/pixfmt.h>
30 }
31 #include <boost/filesystem.hpp>
32 #include <stdexcept>
33 #include <cstring>
34
35 /** @class DecodeError
36  *  @brief A low-level problem with the decoder (possibly due to the nature
37  *  of a source file).
38  */
39 class DecodeError : public std::runtime_error
40 {
41 public:
42         explicit DecodeError (std::string s)
43                 : std::runtime_error (s)
44         {}
45 };
46
47 /** @class EncodeError
48  *  @brief A low-level problem with an encoder.
49  */
50 class EncodeError : public std::runtime_error
51 {
52 public:
53         explicit EncodeError (std::string s)
54                 : std::runtime_error (s)
55         {}
56 };
57
58 /** @class FileError.
59  *  @brief Parent class for file-related errors.
60  */
61 class FileError : public std::runtime_error
62 {
63 public:
64         /** @param m Error message.
65          *  @param f Name of the file that this exception concerns.
66          */
67         FileError (std::string m, boost::filesystem::path f)
68                 : std::runtime_error (m)
69                 , _file (f)
70         {}
71
72         virtual ~FileError () throw () {}
73
74         /** @return name of the file that this exception concerns */
75         boost::filesystem::path file () const {
76                 return _file;
77         }
78
79 private:
80         /** name of the file that this exception concerns */
81         boost::filesystem::path _file;
82 };
83
84 /** @class OpenFileError.
85  *  @brief Indicates that some error occurred when trying to open a file.
86  */
87 class OpenFileError : public FileError
88 {
89 public:
90         /** @param f File that we were trying to open.
91          *  @param error Code of error that occurred.
92          *  @param reading true if we were opening to read, false if opening to write.
93          */
94         OpenFileError (boost::filesystem::path f, int error, bool reading);
95 };
96
97 /** @class ReadFileError.
98  *  @brief Indicates that some error occurred when trying to read from a file
99  */
100 class ReadFileError : public FileError
101 {
102 public:
103         /** @param f File that we were trying to read from.
104          *  @param e errno value, or 0.
105          */
106         ReadFileError (boost::filesystem::path f, int e = 0);
107 };
108
109 /** @class WriteFileError.
110  *  @brief Indicates that some error occurred when trying to write to a file
111  */
112 class WriteFileError : public FileError
113 {
114 public:
115         /** @param f File that we were trying to write to.
116          *  @param e errno value, or 0.
117          */
118         WriteFileError (boost::filesystem::path f, int e);
119 };
120
121 /** @class SettingError.
122  *  @brief Indicates that something is wrong with a setting.
123  */
124 class SettingError : public std::runtime_error
125 {
126 public:
127         /** @param s Name of setting that was required.
128          *  @param m Message.
129          */
130         SettingError (std::string s, std::string m)
131                 : std::runtime_error (m)
132                 , _setting (s)
133         {}
134
135         virtual ~SettingError () throw () {}
136
137         /** @return name of setting in question */
138         std::string setting () const {
139                 return _setting;
140         }
141
142 private:
143         std::string _setting;
144 };
145
146 /** @class MissingSettingError.
147  *  @brief Indicates that a Film is missing a setting that is required for some operation.
148  */
149 class MissingSettingError : public SettingError
150 {
151 public:
152         /** @param s Name of setting that was required */
153         explicit MissingSettingError (std::string s);
154 };
155
156 /** @class BadSettingError
157  *  @brief Indicates that a setting is bad in some way.
158  */
159 class BadSettingError : public SettingError
160 {
161 public:
162         /** @param s Name of setting that is bad.
163          *  @param m Error message.
164          */
165         BadSettingError (std::string s, std::string m)
166                 : SettingError (s, m)
167         {}
168 };
169
170 /** @class NetworkError
171  *  @brief Indicates some problem with communication on the network.
172  */
173 class NetworkError : public std::runtime_error
174 {
175 public:
176         explicit NetworkError (std::string s)
177                 : std::runtime_error (s)
178         {}
179 };
180
181 /** @class KDMError
182  *  @brief A problem with a KDM.
183  */
184 class KDMError : public std::runtime_error
185 {
186 public:
187         KDMError (std::string s, std::string d);
188         ~KDMError () throw() {}
189
190         std::string summary () const {
191                 return _summary;
192         }
193
194         std::string detail () const {
195                 return _detail;
196         }
197
198 private:
199         std::string _summary;
200         std::string _detail;
201 };
202
203 /** @class PixelFormatError
204  *  @brief A problem with an unsupported pixel format.
205  */
206 class PixelFormatError : public std::runtime_error
207 {
208 public:
209         PixelFormatError (std::string o, AVPixelFormat f);
210 };
211
212 /** @class TextSubtitleError
213  *  @brief An error that occurs while parsing a TextSubtitleError file.
214  */
215 class TextSubtitleError : public FileError
216 {
217 public:
218         TextSubtitleError (std::string, std::string, boost::filesystem::path);
219 };
220
221 class DCPError : public std::runtime_error
222 {
223 public:
224         explicit DCPError (std::string s)
225                 : std::runtime_error (s)
226         {}
227 };
228
229 class InvalidSignerError : public std::runtime_error
230 {
231 public:
232         InvalidSignerError ();
233         explicit InvalidSignerError (std::string reason);
234 };
235
236 class ProgrammingError : public std::runtime_error
237 {
238 public:
239         ProgrammingError (std::string file, int line, std::string message = "");
240 };
241
242 class TextEncodingError : public std::runtime_error
243 {
244 public:
245         explicit TextEncodingError (std::string s)
246                 : std::runtime_error (s)
247         {}
248 };
249
250 class MetadataError : public std::runtime_error
251 {
252 public:
253         explicit MetadataError (std::string s)
254                 : std::runtime_error (s)
255         {}
256 };
257
258 class OldFormatError : public std::runtime_error
259 {
260 public:
261         explicit OldFormatError (std::string s)
262                 : std::runtime_error (s)
263         {}
264 };
265
266 class KDMAsContentError : public std::runtime_error
267 {
268 public:
269         KDMAsContentError ();
270 };
271
272 #endif