File indexing completed on 2025-01-19 03:54:56

0001 /*****************************************************************************/
0002 // Copyright 2006-2019 Adobe Systems Incorporated
0003 // All Rights Reserved.
0004 //
0005 // NOTICE:  Adobe permits you to use, modify, and distribute this file in
0006 // accordance with the terms of the Adobe license agreement accompanying it.
0007 /*****************************************************************************/
0008 
0009 /** \file
0010  * C++ exception support for DNG SDK.
0011 */
0012 
0013 /*****************************************************************************/
0014 
0015 #ifndef __dng_exceptions__
0016 #define __dng_exceptions__
0017 
0018 /*****************************************************************************/
0019 
0020 #include "dng_errors.h"
0021 #include "dng_flags.h"
0022 
0023 /*****************************************************************************/
0024 
0025 #ifndef DNG_NO_RETURN
0026 #ifdef __GNUC__
0027 #define DNG_NO_RETURN __attribute__((noreturn))
0028 #else
0029 #define DNG_NO_RETURN
0030 #endif
0031 #endif
0032 
0033 /*****************************************************************************/
0034 
0035 /// Display a warning message. Note that this may just eat the message.
0036 
0037 void ReportWarning (const char *message,
0038                     const char *sub_message = NULL);
0039 
0040 /*****************************************************************************/
0041 
0042 /// Display an error message. Note that this may just eat the message.
0043 
0044 void ReportError (const char *message,
0045                   const char *sub_message = NULL);
0046 
0047 /*****************************************************************************/
0048 
0049 /// \brief All exceptions thrown by the DNG SDK use this exception class.
0050 
0051 class dng_exception
0052     {
0053 
0054     private:
0055 
0056         dng_error_code fErrorCode;
0057 
0058     public:
0059 
0060         /// Construct an exception representing the given error code.
0061         /// \param code Error code this exception is for.
0062 
0063         dng_exception (dng_error_code code)
0064 
0065             : fErrorCode (code)
0066 
0067             {
0068             }
0069 
0070         virtual ~dng_exception ()
0071             {
0072             }
0073 
0074         /// Getter for error code of this exception
0075         /// \retval The error code of this exception.
0076 
0077         dng_error_code ErrorCode () const
0078             {
0079             return fErrorCode;
0080             }
0081 
0082     };
0083 
0084 /******************************************************************************/
0085 
0086 /// \brief Throw an exception based on an arbitrary error code.
0087 
0088 void Throw_dng_error (dng_error_code err,
0089                       const char * message = NULL,
0090                       const char * sub_message = NULL,
0091                       bool silent = false) DNG_NO_RETURN;
0092 
0093 /******************************************************************************/
0094 
0095 /// \brief Convenience function to throw dng_exception with error code if
0096 /// error_code is not dng_error_none .
0097 
0098 inline void Fail_dng_error (dng_error_code err)
0099     {
0100 
0101     if (err != dng_error_none)
0102         {
0103 
0104         Throw_dng_error (err);
0105 
0106         }
0107 
0108     }
0109 
0110 /*****************************************************************************/
0111 
0112 /// \brief Convenience function to throw dng_exception with error code
0113 /// dng_error_unknown .
0114 
0115 inline void ThrowProgramError (const char * sub_message = NULL)
0116     {
0117 
0118     Throw_dng_error (dng_error_unknown, NULL, sub_message);
0119 
0120     }
0121 
0122 /*****************************************************************************/
0123 
0124 /// \brief Convenience function to throw dng_exception with error code
0125 /// dng_error_overflow.
0126 
0127 inline void ThrowOverflow (const char * sub_message = NULL)
0128     {
0129 
0130     Throw_dng_error (dng_error_overflow, NULL, sub_message);
0131 
0132     }
0133 
0134 /*****************************************************************************/
0135 
0136 /// \brief Convenience function to throw dng_exception with error code
0137 /// dng_error_not_yet_implemented .
0138 
0139 inline void ThrowNotYetImplemented (const char * sub_message = NULL)
0140     {
0141 
0142     Throw_dng_error (dng_error_not_yet_implemented, NULL, sub_message);
0143 
0144     }
0145 
0146 /*****************************************************************************/
0147 
0148 /// \brief Convenience function to throw dng_exception with error code
0149 /// dng_error_silent .
0150 
0151 inline void ThrowSilentError ()
0152     {
0153 
0154     Throw_dng_error (dng_error_silent);
0155 
0156     }
0157 
0158 /*****************************************************************************/
0159 
0160 /// \brief Convenience function to throw dng_exception with error code
0161 /// dng_error_user_canceled .
0162 
0163 inline void ThrowUserCanceled ()
0164     {
0165 
0166     Throw_dng_error (dng_error_user_canceled);
0167 
0168     }
0169 
0170 /*****************************************************************************/
0171 
0172 /// \brief Convenience function to throw dng_exception with error code
0173 /// dng_error_host_insufficient .
0174 
0175 inline void ThrowHostInsufficient (const char * sub_message = NULL,
0176                                    bool silent = false)
0177     {
0178 
0179     Throw_dng_error (dng_error_host_insufficient, NULL, sub_message, silent);
0180 
0181     }
0182 
0183 /*****************************************************************************/
0184 
0185 /// \brief Convenience function to throw dng_exception with error code
0186 /// dng_error_memory .
0187 
0188 inline void ThrowMemoryFull (const char * sub_message = NULL)
0189     {
0190 
0191     Throw_dng_error (dng_error_memory, NULL, sub_message);
0192 
0193     }
0194 
0195 /*****************************************************************************/
0196 
0197 /// \brief Convenience function to throw dng_exception with error code
0198 /// dng_error_bad_format .
0199 
0200 inline void ThrowBadFormat (const char * sub_message = NULL)
0201     {
0202 
0203     Throw_dng_error (dng_error_bad_format, NULL, sub_message);
0204 
0205     }
0206 
0207 /*****************************************************************************/
0208 
0209 /// \brief Convenience function to throw dng_exception with error code
0210 /// dng_error_matrix_math .
0211 
0212 inline void ThrowMatrixMath (const char * sub_message = NULL)
0213     {
0214 
0215     Throw_dng_error (dng_error_matrix_math, NULL, sub_message);
0216 
0217     }
0218 
0219 /*****************************************************************************/
0220 
0221 /// \brief Convenience function to throw dng_exception with error code
0222 /// dng_error_open_file .
0223 
0224 inline void ThrowOpenFile (const char * sub_message = NULL, bool silent = false)
0225     {
0226 
0227     Throw_dng_error (dng_error_open_file, NULL, sub_message, silent);
0228 
0229     }
0230 
0231 /*****************************************************************************/
0232 
0233 /// \brief Convenience function to throw dng_exception with error code
0234 /// dng_error_read_file .
0235 
0236 inline void ThrowReadFile (const char *sub_message = NULL)
0237     {
0238 
0239     Throw_dng_error (dng_error_read_file, NULL, sub_message);
0240 
0241     }
0242 
0243 /*****************************************************************************/
0244 
0245 /// \brief Convenience function to throw dng_exception with error code
0246 /// dng_error_write_file .
0247 
0248 inline void ThrowWriteFile (const char *sub_message = NULL)
0249     {
0250 
0251     Throw_dng_error (dng_error_write_file, NULL, sub_message);
0252 
0253     }
0254 
0255 /*****************************************************************************/
0256 
0257 /// \brief Convenience function to throw dng_exception with error code
0258 /// dng_error_end_of_file .
0259 
0260 inline void ThrowEndOfFile (const char *sub_message = NULL)
0261     {
0262 
0263     Throw_dng_error (dng_error_end_of_file, NULL, sub_message);
0264 
0265     }
0266 
0267 /*****************************************************************************/
0268 
0269 /// \brief Convenience function to throw dng_exception with error code
0270 /// dng_error_file_is_damaged .
0271 
0272 inline void ThrowFileIsDamaged ()
0273     {
0274 
0275     Throw_dng_error (dng_error_file_is_damaged);
0276 
0277     }
0278 
0279 /*****************************************************************************/
0280 
0281 /// \brief Convenience function to throw dng_exception with error code
0282 /// dng_error_image_too_big_dng .
0283 
0284 inline void ThrowImageTooBigDNG ()
0285     {
0286 
0287     Throw_dng_error (dng_error_image_too_big_dng);
0288 
0289     }
0290 
0291 /*****************************************************************************/
0292 
0293 /// \brief Convenience function to throw dng_exception with error code
0294 /// dng_error_image_too_big_tiff .
0295 
0296 inline void ThrowImageTooBigTIFF ()
0297     {
0298 
0299     Throw_dng_error (dng_error_image_too_big_tiff);
0300 
0301     }
0302 
0303 /*****************************************************************************/
0304 
0305 /// \brief Convenience function to throw dng_exception with error code
0306 /// dng_error_unsupported_dng .
0307 
0308 inline void ThrowUnsupportedDNG ()
0309     {
0310 
0311     Throw_dng_error (dng_error_unsupported_dng);
0312 
0313     }
0314 
0315 /*****************************************************************************/
0316 
0317 #endif
0318 
0319 /*****************************************************************************/