1 /*****************************************************************************/ 2 // Copyright 2006-2019 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 /** \file 10 * Conditionally compiled assertion check support. 11 */ 12 13 /*****************************************************************************/ 14 15 #ifndef __dng_assertions__ 16 #define __dng_assertions__ 17 18 /*****************************************************************************/ 19 20 #include "dng_exceptions.h" 21 #include "dng_flags.h" 22 23 /*****************************************************************************/ 24 25 #if qDNGDebug 26 27 /// Platform-specific function to display an assert. 28 29 void dng_show_message (const char *s); 30 31 /// Show a formatted error message. 32 33 void dng_show_message_f (const char *fmt, ...); 34 35 #endif 36 37 /*****************************************************************************/ 38 39 #ifndef DNG_ASSERT 40 41 #if qDNGDebug 42 43 /// Conditionally compiled macro to check an assertion and display a message if 44 /// it fails and assertions are compiled in via qDNGDebug 45 /// \param x Predicate which must be true. 46 /// \param y String to display if x is not true. 47 48 #define DNG_ASSERT(x,y) { if (!(x)) dng_show_message (y); } 49 50 #else 51 52 /// Conditionally compiled macro to check an assertion and display a message if 53 /// it fails and assertions are compiled in via qDNGDebug 54 /// \param x Predicate which must be true. 55 /// \param y String to display if x is not true. 56 57 #define DNG_ASSERT(x,y) 58 59 #endif 60 #endif 61 62 /*****************************************************************************/ 63 64 #ifndef DNG_REQUIRE 65 66 #if qDNGDebug 67 68 /// Conditionally compiled macro to check an assertion, display a message, and throw 69 /// an exception if it fails and assertions are compiled in via qDNGDebug 70 /// \param condition Predicate which must be true. 71 /// \param msg String to display if condition is not true. 72 73 #define DNG_REQUIRE(condition,msg) \ 74 do \ 75 { \ 76 \ 77 if (!(condition)) \ 78 { \ 79 \ 80 DNG_ASSERT(condition, msg); \ 81 \ 82 ThrowProgramError (msg); \ 83 \ 84 } \ 85 \ 86 } \ 87 while (0) 88 89 #else 90 91 /// Conditionally compiled macro to check an assertion, display a message, and throw 92 /// an exception if it fails and assertions are compiled in via qDNGDebug 93 /// \param condition Predicate which must be true. 94 /// \param msg String to display if condition is not true. 95 96 #define DNG_REQUIRE(condition,msg) \ 97 do \ 98 { \ 99 \ 100 if (!(condition)) \ 101 { \ 102 \ 103 ThrowProgramError (msg); \ 104 \ 105 } \ 106 \ 107 } \ 108 while (0) 109 110 #endif 111 #endif 112 113 /*****************************************************************************/ 114 115 #ifndef DNG_REPORT 116 117 /// Macro to display an informational message 118 /// \param x String to display. 119 120 #define DNG_REPORT(x) DNG_ASSERT (false, x) 121 122 #endif 123 124 /*****************************************************************************/ 125 126 #endif 127 128 /*****************************************************************************/ 129