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