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