A few encryption-related fixes and comments.
[libdcp.git] / src / exceptions.h
1 /*
2     Copyright (C) 2012 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 libdcp
30 {
31
32 /** @brief An exception related to a file */
33 class FileError : public std::exception
34 {
35 public:
36         FileError (std::string const & message, boost::filesystem::path filename)
37                 : _message (message)
38                 , _filename (filename)
39         {}
40                             
41         ~FileError () throw () {}
42
43         /** @return error message */
44         char const * what () const throw () {
45                 return _message.c_str ();
46         }
47         
48         /** @return filename of file that was involved */
49         boost::filesystem::path filename () const {
50                 return _filename;
51         }
52
53 private:
54         /** error message */
55         std::string _message;
56         /** filename of file that was involved */
57         boost::filesystem::path _filename;
58 };
59
60 /** @brief An exception related to an MXF file */
61 class MXFFileError : public FileError
62 {
63 public:
64         MXFFileError (std::string const & message, boost::filesystem::path filename)
65                 : FileError (message, filename)
66         {}
67 };
68         
69 /** @brief A miscellaneous exception */
70 class MiscError : public std::exception
71 {
72 public:
73         MiscError (std::string const & message) : _message (message) {}
74         ~MiscError () throw () {}
75
76         /** @return error message */
77         char const * what () const throw () {
78                 return _message.c_str ();
79         }
80
81 private:
82         /** error message */
83         std::string _message;
84 };
85
86 /** @brief A DCP read exception */
87 class DCPReadError : public std::exception
88 {
89 public:
90         DCPReadError (std::string const & message) : _message (message) {}
91         ~DCPReadError () throw () {}
92
93         /** @return error message */
94         char const * what () const throw () {
95                 return _message.c_str ();
96         }
97
98 private:
99         /** error message */
100         std::string _message;
101 };
102
103 /** @brief An XML error */
104 class XMLError : public std::exception
105 {
106 public:
107         XMLError (std::string const & message) : _message (message) {}
108         ~XMLError () throw () {}
109
110         /** @return error message */
111         char const * what () const throw () {
112                 return _message.c_str ();
113         }
114
115 private:
116         /** error message */
117         std::string _message;
118 };
119         
120 }
121
122 #endif