Tidy up KDM generation from CPLs a bit.
[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 : public std::exception
33 {
34 public:
35         StringError () {}
36         StringError (std::string message)
37                 : _message (message)
38         {}
39                             
40         ~StringError () throw () {}
41
42         /** @return error message */
43         char const * what () const throw () {
44                 return _message.c_str ();
45         }
46
47 protected:
48         std::string _message;
49 };
50
51 /** @class FileError
52  *  @brief An exception related to a file
53  */
54 class FileError : public StringError
55 {
56 public:
57         FileError (std::string message, boost::filesystem::path filename, int number);
58         ~FileError () throw () {}
59
60         /** @return filename of file that was involved */
61         boost::filesystem::path filename () const {
62                 return _filename;
63         }
64
65         /** @return error number of the error */
66         int number () const {
67                 return _number;
68         }
69
70 private:
71         /** filename of file that was involved */
72         boost::filesystem::path _filename;
73         int _number;
74 };
75
76 /** @class MXFFileError
77  *  @brief An exception related to an MXF file
78  */
79 class MXFFileError : public FileError
80 {
81 public:
82         MXFFileError (std::string message, boost::filesystem::path filename, int number)
83                 : FileError (message, filename, number)
84         {}
85 };
86         
87 /** @class MiscError
88  *  @brief A miscellaneous exception
89  */
90 class MiscError : public StringError
91 {
92 public:
93         MiscError (std::string message)
94                 : StringError (message)
95         {}
96 };
97
98 /** @class DCPReadError
99  *  @brief A DCP read exception
100  */
101 class DCPReadError : public StringError
102 {
103 public:
104         DCPReadError (std::string message)
105                 : StringError (message)
106         {}
107
108 protected:
109         DCPReadError () {}
110 };
111
112 /** @class MissingAssetError
113  *  @brief An error of a missing asset.
114  */
115 class MissingAssetError : public DCPReadError
116 {
117 public:
118         enum AssetType {
119                 MAIN_PICTURE,  //< main picture is missing
120                 MAIN_SOUND,    //< main sound is missing
121                 MAIN_SUBTITLE, //< main subtitle is missing
122                 UNKNOWN        //< something is missing but we don't know what
123         };
124         
125         MissingAssetError (boost::filesystem::path, AssetType = UNKNOWN);
126         ~MissingAssetError () throw () {}
127
128 private:
129         boost::filesystem::path _path;
130         AssetType _type;
131 };
132
133 /** @class XMLError
134  *  @brief An XML error
135  */
136 class XMLError : public StringError
137 {
138 public:
139         XMLError (std::string message)
140                 : StringError (message)
141         {}
142 };
143
144 /** @class UnresolvedRefError
145  *  @brief An exception caused by a reference (by UUID) to something which is not known
146  */
147 class UnresolvedRefError : public StringError
148 {
149 public:
150         UnresolvedRefError (std::string id);
151 };
152
153 /** @class TimeFormatError
154  *  @brief A an error with a string passed to LocalTime.
155  */
156 class TimeFormatError : public StringError
157 {
158 public:
159         TimeFormatError (std::string bad_time);
160 };
161
162 class NotEncryptedError : public StringError
163 {
164 public:
165         NotEncryptedError (std::string const & what);
166         ~NotEncryptedError () throw () {}
167 };
168         
169 }
170
171 #endif