1 /*****************************************************************************/
2 // Copyright 2006-2007 Adobe Systems Incorporated
3 // All Rights Reserved.
4 //
5 // NOTICE:  Adobe permits you to use, modify, and distribute this file in
6 // accordance with the terms of the Adobe license agreement accompanying it.
7 /*****************************************************************************/
8 
9 /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_exceptions.h#1 $ */
10 /* $DateTime: 2012/05/30 13:28:51 $ */
11 /* $Change: 832332 $ */
12 /* $Author: tknoll $ */
13 
14 /** \file
15  * C++ exception support for DNG SDK.
16 */
17 
18 /*****************************************************************************/
19 
20 #ifndef __dng_exceptions__
21 #define __dng_exceptions__
22 
23 /*****************************************************************************/
24 
25 #include "dng_errors.h"
26 #include "dng_flags.h"
27 
28 /*****************************************************************************/
29 
30 /// Display a warning message. Note that this may just eat the message.
31 
32 void ReportWarning (const char *message,
33 				    const char *sub_message = NULL);
34 
35 /*****************************************************************************/
36 
37 /// Display an error message. Note that this may just eat the message.
38 
39 void ReportError (const char *message,
40 				  const char *sub_message = NULL);
41 
42 /*****************************************************************************/
43 
44 /// \brief All exceptions thrown by the DNG SDK use this exception class.
45 
46 class dng_exception
47 	{
48 
49 	private:
50 
51 		dng_error_code fErrorCode;
52 
53 	public:
54 
55 		/// Construct an exception representing the given error code.
56 		/// \param code Error code this exception is for.
57 
dng_exception(dng_error_code code)58 		dng_exception (dng_error_code code)
59 
60 			: fErrorCode (code)
61 
62 			{
63 			}
64 
~dng_exception()65 		virtual ~dng_exception ()
66 			{
67 			}
68 
69 		/// Getter for error code of this exception
70 		/// \retval The error code of this exception.
71 
ErrorCode()72 		dng_error_code ErrorCode () const
73 			{
74 			return fErrorCode;
75 			}
76 
77 	};
78 
79 /******************************************************************************/
80 
81 /// \brief Throw an exception based on an arbitrary error code.
82 
83 void Throw_dng_error (dng_error_code err,
84 					  const char * message = NULL,
85 					  const char * sub_message = NULL,
86 					  bool silent = false);
87 
88 /******************************************************************************/
89 
90 /// \brief Convenience function to throw dng_exception with error code if
91 /// error_code is not dng_error_none .
92 
Fail_dng_error(dng_error_code err)93 inline void Fail_dng_error (dng_error_code err)
94 	{
95 
96 	if (err != dng_error_none)
97 		{
98 
99 		Throw_dng_error (err);
100 
101 		}
102 
103 	}
104 
105 /*****************************************************************************/
106 
107 /// \brief Convenience function to throw dng_exception with error code
108 /// dng_error_unknown .
109 
110 inline void ThrowProgramError (const char * sub_message = NULL)
111 	{
112 
113 	Throw_dng_error (dng_error_unknown, NULL, sub_message);
114 
115 	}
116 
117 /*****************************************************************************/
118 
119 /// \brief Convenience function to throw dng_exception with error code
120 /// dng_error_not_yet_implemented .
121 
122 inline void ThrowNotYetImplemented (const char * sub_message = NULL)
123 	{
124 
125 	Throw_dng_error (dng_error_not_yet_implemented, NULL, sub_message);
126 
127 	}
128 
129 /*****************************************************************************/
130 
131 /// \brief Convenience function to throw dng_exception with error code
132 /// dng_error_silent .
133 
ThrowSilentError()134 inline void ThrowSilentError ()
135 	{
136 
137 	Throw_dng_error (dng_error_silent);
138 
139 	}
140 
141 /*****************************************************************************/
142 
143 /// \brief Convenience function to throw dng_exception with error code
144 /// dng_error_user_canceled .
145 
ThrowUserCanceled()146 inline void ThrowUserCanceled ()
147 	{
148 
149 	Throw_dng_error (dng_error_user_canceled);
150 
151 	}
152 
153 /*****************************************************************************/
154 
155 /// \brief Convenience function to throw dng_exception with error code
156 /// dng_error_host_insufficient .
157 
158 inline void ThrowHostInsufficient (const char * sub_message = NULL)
159 	{
160 
161 	Throw_dng_error (dng_error_host_insufficient, NULL, sub_message);
162 
163 	}
164 
165 /*****************************************************************************/
166 
167 /// \brief Convenience function to throw dng_exception with error code
168 /// dng_error_memory .
169 
170 inline void ThrowMemoryFull (const char * sub_message = NULL)
171 	{
172 
173 	Throw_dng_error (dng_error_memory, NULL, sub_message);
174 
175 	}
176 
177 /*****************************************************************************/
178 
179 /// \brief Convenience function to throw dng_exception with error code
180 /// dng_error_bad_format .
181 
182 inline void ThrowBadFormat (const char * sub_message = NULL)
183 	{
184 
185 	Throw_dng_error (dng_error_bad_format, NULL, sub_message);
186 
187 	}
188 
189 /*****************************************************************************/
190 
191 /// \brief Convenience function to throw dng_exception with error code
192 /// dng_error_matrix_math .
193 
194 inline void ThrowMatrixMath (const char * sub_message = NULL)
195 	{
196 
197 	Throw_dng_error (dng_error_matrix_math, NULL, sub_message);
198 
199 	}
200 
201 /*****************************************************************************/
202 
203 /// \brief Convenience function to throw dng_exception with error code
204 /// dng_error_open_file .
205 
206 inline void ThrowOpenFile (const char * sub_message = NULL, bool silent = false)
207 	{
208 
209 	Throw_dng_error (dng_error_open_file, NULL, sub_message, silent);
210 
211 	}
212 
213 /*****************************************************************************/
214 
215 /// \brief Convenience function to throw dng_exception with error code
216 /// dng_error_read_file .
217 
218 inline void ThrowReadFile (const char *sub_message = NULL)
219 	{
220 
221 	Throw_dng_error (dng_error_read_file, NULL, sub_message);
222 
223 	}
224 
225 /*****************************************************************************/
226 
227 /// \brief Convenience function to throw dng_exception with error code
228 /// dng_error_write_file .
229 
230 inline void ThrowWriteFile (const char *sub_message = NULL)
231 	{
232 
233 	Throw_dng_error (dng_error_write_file, NULL, sub_message);
234 
235 	}
236 
237 /*****************************************************************************/
238 
239 /// \brief Convenience function to throw dng_exception with error code
240 /// dng_error_end_of_file .
241 
242 inline void ThrowEndOfFile (const char *sub_message = NULL)
243 	{
244 
245 	Throw_dng_error (dng_error_end_of_file, NULL, sub_message);
246 
247 	}
248 
249 /*****************************************************************************/
250 
251 /// \brief Convenience function to throw dng_exception with error code
252 /// dng_error_file_is_damaged .
253 
ThrowFileIsDamaged()254 inline void ThrowFileIsDamaged ()
255 	{
256 
257 	Throw_dng_error (dng_error_file_is_damaged);
258 
259 	}
260 
261 /*****************************************************************************/
262 
263 /// \brief Convenience function to throw dng_exception with error code
264 /// dng_error_image_too_big_dng .
265 
ThrowImageTooBigDNG()266 inline void ThrowImageTooBigDNG ()
267 	{
268 
269 	Throw_dng_error (dng_error_image_too_big_dng);
270 
271 	}
272 
273 /*****************************************************************************/
274 
275 /// \brief Convenience function to throw dng_exception with error code
276 /// dng_error_image_too_big_tiff .
277 
ThrowImageTooBigTIFF()278 inline void ThrowImageTooBigTIFF ()
279 	{
280 
281 	Throw_dng_error (dng_error_image_too_big_tiff);
282 
283 	}
284 
285 /*****************************************************************************/
286 
287 /// \brief Convenience function to throw dng_exception with error code
288 /// dng_error_unsupported_dng .
289 
ThrowUnsupportedDNG()290 inline void ThrowUnsupportedDNG ()
291 	{
292 
293 	Throw_dng_error (dng_error_unsupported_dng);
294 
295 	}
296 
297 /*****************************************************************************/
298 
299 #endif
300 
301 /*****************************************************************************/
302