No-op: whitespace.
[libdcp.git] / src / 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 #ifndef LIBDCP_EXCEPTIONS_H
21 #define LIBDCP_EXCEPTIONS_H
22
23 #include <boost/filesystem.hpp>
24
25 /** @file  src/exceptions.h
26  *  @brief Exceptions thrown by libdcp.
27  */
28
29 namespace dcp
30 {
31
32 /** @class StringError
33  *  @brief An exception that uses a std::string to store its error message.
34  */
35 class StringError : public std::exception
36 {
37 public:
38         StringError () {}
39         StringError (std::string message)
40                 : _message (message)
41         {}
42
43         ~StringError () throw () {}
44
45         /** @return error message */
46         char const * what () const throw () {
47                 return _message.c_str ();
48         }
49
50 protected:
51         std::string _message;
52 };
53
54 /** @class FileError
55  *  @brief An exception related to a file
56  */
57 class FileError : public StringError
58 {
59 public:
60         FileError (std::string message, boost::filesystem::path filename, int number);
61         ~FileError () throw () {}
62
63         /** @return filename of file that was involved */
64         boost::filesystem::path filename () const {
65                 return _filename;
66         }
67
68         /** @return error number of the error */
69         int number () const {
70                 return _number;
71         }
72
73 private:
74         /** filename of file that was involved */
75         boost::filesystem::path _filename;
76         int _number;
77 };
78
79 /** @class MXFFileError
80  *  @brief An exception related to an MXF file
81  */
82 class MXFFileError : public FileError
83 {
84 public:
85         MXFFileError (std::string message, boost::filesystem::path filename, int number)
86                 : FileError (message, filename, number)
87         {}
88 };
89
90 /** @class MiscError
91  *  @brief A miscellaneous exception
92  */
93 class MiscError : public StringError
94 {
95 public:
96         MiscError (std::string message)
97                 : StringError (message)
98         {}
99 };
100
101 /** @class DCPReadError
102  *  @brief A DCP read exception
103  */
104 class DCPReadError : public StringError
105 {
106 public:
107         DCPReadError (std::string message)
108                 : StringError (message)
109         {}
110
111 protected:
112         DCPReadError () {}
113 };
114
115 /** @class MissingAssetError
116  *  @brief An error of a missing asset.
117  */
118 class MissingAssetError : public DCPReadError
119 {
120 public:
121         enum AssetType {
122                 MAIN_PICTURE,  //< main picture is missing
123                 MAIN_SOUND,    //< main sound is missing
124                 MAIN_SUBTITLE, //< main subtitle is missing
125                 UNKNOWN        //< something is missing but we don't know what
126         };
127
128         MissingAssetError (boost::filesystem::path, AssetType = UNKNOWN);
129         ~MissingAssetError () throw () {}
130
131 private:
132         boost::filesystem::path _path;
133         AssetType _type;
134 };
135
136 /** @class XMLError
137  *  @brief An XML error
138  */
139 class XMLError : public StringError
140 {
141 public:
142         XMLError (std::string message)
143                 : StringError (message)
144         {}
145 };
146
147 /** @class UnresolvedRefError
148  *  @brief An exception caused by a reference (by UUID) to something which is not known
149  */
150 class UnresolvedRefError : public StringError
151 {
152 public:
153         UnresolvedRefError (std::string id);
154 };
155
156 /** @class TimeFormatError
157  *  @brief A an error with a string passed to LocalTime.
158  */
159 class TimeFormatError : public StringError
160 {
161 public:
162         TimeFormatError (std::string bad_time);
163 };
164
165 /** @class NotEncryptedError
166  *  @brief An error raised when creating a DecryptedKDM object for assets that are not
167  *  encrypted.
168  */
169 class NotEncryptedError : public StringError
170 {
171 public:
172         NotEncryptedError (std::string const & what);
173         ~NotEncryptedError () throw () {}
174 };
175
176 /** @class ProgrammingError
177  *  @brief An exception thrown when a DCP_ASSERT fails; something that should not happen.
178  */
179 class ProgrammingError : public StringError
180 {
181 public:
182         ProgrammingError (std::string file, int line);
183 };
184
185 }
186
187 #endif