Some comments.
[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 FileError
33  *  @brief An exception related to a file
34  */
35 class FileError : public std::exception
36 {
37 public:
38         FileError (std::string message, boost::filesystem::path filename, int number);
39         ~FileError () throw () {}
40
41         /** @return error message */
42         char const * what () const throw () {
43                 return _message.c_str ();
44         }
45         
46         /** @return filename of file that was involved */
47         boost::filesystem::path filename () const {
48                 return _filename;
49         }
50
51         /** @return error number of the error */
52         int number () const {
53                 return _number;
54         }
55
56 private:
57         /** message part */
58         std::string _message;
59         /** filename of file that was involved */
60         boost::filesystem::path _filename;
61         int _number;
62 };
63
64 /** @class MXFFileError
65  *  @brief An exception related to an MXF file
66  */
67 class MXFFileError : public FileError
68 {
69 public:
70         MXFFileError (std::string message, boost::filesystem::path filename, int number)
71                 : FileError (message, filename, number)
72         {}
73 };
74         
75 /** @class MiscError
76  *  @brief A miscellaneous exception
77  */
78 class MiscError : public std::exception
79 {
80 public:
81         MiscError (std::string message) : _message (message) {}
82         ~MiscError () throw () {}
83
84         /** @return error message */
85         char const * what () const throw () {
86                 return _message.c_str ();
87         }
88
89 private:
90         /** error message */
91         std::string _message;
92 };
93
94 /** @class DCPReadError
95  *  @brief A DCP read exception
96  */
97 class DCPReadError : public std::exception
98 {
99 public:
100         DCPReadError (std::string message) : _message (message) {}
101         ~DCPReadError () throw () {}
102
103         /** @return error message */
104         char const * what () const throw () {
105                 return _message.c_str ();
106         }
107
108 protected:
109         DCPReadError () {}
110         
111         /** error message */
112         std::string _message;
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 std::exception
140 {
141 public:
142         XMLError (std::string message) : _message (message) {}
143         ~XMLError () throw () {}
144
145         /** @return error message */
146         char const * what () const throw () {
147                 return _message.c_str ();
148         }
149
150 private:
151         /** error message */
152         std::string _message;
153 };
154
155 /** @class UnresolvedRefError
156  *  @brief An exception caused by a reference (by UUID) to something which is not known
157  */
158 class UnresolvedRefError : public std::exception
159 {
160 public:
161         UnresolvedRefError (std::string id);
162         ~UnresolvedRefError () throw () {}
163
164         /** @return error message */
165         char const * what () const throw () {
166                 return _message.c_str ();
167         }
168
169 private:
170         std::string _message;
171 };
172
173 /** @class TimeFormatError
174  *  @brief A an error with a string passed to LocalTime.
175  */
176 class TimeFormatError : public std::exception
177 {
178 public:
179         TimeFormatError (std::string bad_time);
180         ~TimeFormatError () throw () {}
181
182         /** @return error message */
183         char const * what () const throw () {
184                 return _message.c_str ();
185         }
186
187 private:
188         std::string _message;
189 };
190
191 }
192
193 #endif