Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / src / lib / exceptions.h
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/lib/exceptions.h
21  *  @brief Our exceptions.
22  */
23
24 #ifndef DCPOMATIC_EXCEPTIONS_H
25 #define DCPOMATIC_EXCEPTIONS_H
26
27 extern "C" {
28 #include <libavutil/pixfmt.h>
29 }
30 #include <boost/filesystem.hpp>
31 #include <stdexcept>
32 #include <cstring>
33
34 /** @class DecodeError
35  *  @brief A low-level problem with the decoder (possibly due to the nature
36  *  of a source file).
37  */
38 class DecodeError : public std::runtime_error
39 {
40 public:
41         DecodeError (std::string s)
42                 : std::runtime_error (s)
43         {}
44 };
45
46 /** @class EncodeError
47  *  @brief A low-level problem with an encoder.
48  */
49 class EncodeError : public std::runtime_error
50 {
51 public:
52         EncodeError (std::string s)
53                 : std::runtime_error (s)
54         {}
55 };
56
57 /** @class FileError.
58  *  @brief Parent class for file-related errors.
59  */
60 class FileError : public std::runtime_error
61 {
62 public:
63         /** @param m Error message.
64          *  @param f Name of the file that this exception concerns.
65          */
66         FileError (std::string m, boost::filesystem::path f)
67                 : std::runtime_error (m)
68                 , _file (f)
69         {}
70
71         virtual ~FileError () throw () {}
72
73         /** @return name of the file that this exception concerns */
74         boost::filesystem::path file () const {
75                 return _file;
76         }
77
78 private:
79         /** name of the file that this exception concerns */
80         boost::filesystem::path _file;
81 };
82
83 class JoinError : public std::runtime_error
84 {
85 public:
86         JoinError (std::string s)
87                 : std::runtime_error (s)
88         {}
89 };
90
91 /** @class OpenFileError.
92  *  @brief Indicates that some error occurred when trying to open a file.
93  */
94 class OpenFileError : public FileError
95 {
96 public:
97         /** @param f File that we were trying to open */
98         OpenFileError (boost::filesystem::path f);
99 };
100
101 /** @class CreateFileError.
102  *  @brief Indicates that some error occurred when trying to create a file.
103  */
104 class CreateFileError : public FileError
105 {
106 public:
107         /** @param f File that we were trying to create */
108         CreateFileError (boost::filesystem::path f);
109 };
110
111
112 /** @class ReadFileError.
113  *  @brief Indicates that some error occurred when trying to read from a file
114  */
115 class ReadFileError : public FileError
116 {
117 public:
118         /** @param f File that we were trying to read from.
119          *  @param e errno value, or 0.
120          */
121         ReadFileError (boost::filesystem::path f, int e = 0);
122 };
123
124 /** @class WriteFileError.
125  *  @brief Indicates that some error occurred when trying to write to a file
126  */
127 class WriteFileError : public FileError
128 {
129 public:
130         /** @param f File that we were trying to write to.
131          *  @param e errno value, or 0.
132          */
133         WriteFileError (boost::filesystem::path f, int e);
134 };
135
136 /** @class SettingError.
137  *  @brief Indicates that something is wrong with a setting.
138  */
139 class SettingError : public std::runtime_error
140 {
141 public:
142         /** @param s Name of setting that was required.
143          *  @param m Message.
144          */
145         SettingError (std::string s, std::string m)
146                 : std::runtime_error (m)
147                 , _setting (s)
148         {}
149
150         virtual ~SettingError () throw () {}
151
152         /** @return name of setting in question */
153         std::string setting () const {
154                 return _setting;
155         }
156
157 private:
158         std::string _setting;
159 };
160
161 /** @class MissingSettingError.
162  *  @brief Indicates that a Film is missing a setting that is required for some operation.
163  */
164 class MissingSettingError : public SettingError
165 {
166 public:
167         /** @param s Name of setting that was required */
168         MissingSettingError (std::string s);
169 };
170
171 /** @class BadSettingError
172  *  @brief Indicates that a setting is bad in some way.
173  */
174 class BadSettingError : public SettingError
175 {
176 public:
177         /** @param s Name of setting that is bad */
178         BadSettingError (std::string s, std::string m)
179                 : SettingError (s, m)
180         {}
181 };
182
183 /** @class NetworkError
184  *  @brief Indicates some problem with communication on the network.
185  */
186 class NetworkError : public std::runtime_error
187 {
188 public:
189         NetworkError (std::string s)
190                 : std::runtime_error (s)
191         {}
192 };
193
194 /** @class KDMError
195  *  @brief A problem with a KDM.
196  */
197 class KDMError : public std::runtime_error
198 {
199 public:
200         KDMError (std::string s)
201                 : std::runtime_error (s)
202         {}
203 };
204
205 /** @class PixelFormatError
206  *  @brief A problem with an unsupported pixel format.
207  */
208 class PixelFormatError : public std::runtime_error
209 {
210 public:
211         PixelFormatError (std::string o, AVPixelFormat f);
212 };
213
214 /** @class SubRipError
215  *  @brief An error that occurs while parsing a SubRip file.
216  */
217 class SubRipError : public FileError
218 {
219 public:
220         SubRipError (std::string, std::string, boost::filesystem::path);
221 };
222
223 class DCPError : public std::runtime_error
224 {
225 public:
226         DCPError (std::string s)
227                 : std::runtime_error (s)
228         {}
229 };
230
231 class InvalidSignerError : public std::runtime_error
232 {
233 public:
234         InvalidSignerError ();
235 };
236
237 class ProgrammingError : public std::runtime_error
238 {
239 public:
240         ProgrammingError (std::string file, int line);
241 };
242
243 class TextEncodingError : public std::runtime_error
244 {
245 public:
246         TextEncodingError (std::string s)
247                 : std::runtime_error (s)
248         {}
249 };
250
251 #endif