OpenImageIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dassert.h
Go to the documentation of this file.
1 /*
2  Copyright 2008 Larry Gritz and the other authors and contributors.
3  All Rights Reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the software's owners nor the names of its
14  contributors may be used to endorse or promote products derived from
15  this software without specific prior written permission.
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28  (This is the Modified BSD License)
29 */
30 
31 
32 #ifndef OPENIMAGEIO_DASSERT_H
33 #define OPENIMAGEIO_DASSERT_H
34 
35 #include <cstdio>
36 #include <cstdlib>
37 
38 
61 
62 
66 
67 #ifndef ASSERT
68 # define ASSERT(x) \
69  ((x) ? ((void)0) \
70  : (fprintf (stderr, "%s:%u: failed assertion '%s'\n", \
71  __FILE__, __LINE__, #x), abort()))
72 #endif
73 
76 #ifndef ASSERT_MSG
77 # define ASSERT_MSG(x,msg,...) \
78  ((x) ? ((void)0) \
79  : (fprintf (stderr, "%s:%u: failed assertion '%s': " msg "\n", \
80  __FILE__, __LINE__, #x, __VA_ARGS__), abort()))
81 #endif
82 
83 #ifndef ASSERTMSG
84 #define ASSERTMSG ASSERT_MSG
85 #endif
86 
87 
91 #ifndef NDEBUG
92 # define DASSERT(x) ASSERT(x)
93 #else
94  /* DASSERT does nothing when not debugging; sizeof trick prevents warnings */
95 # define DASSERT(x) ((void)sizeof(x))
96 #endif
97 
101 #ifndef NDEBUG
102 # define DASSERT_MSG ASSERT_MSG
103 #else
104 # define DASSERT_MSG(x,...) ((void)sizeof(x)) /* does nothing when not debugging */
105 #endif
106 
107 #ifndef DASSERTMSG
108 #define DASSERTMSG DASSERT_MSG
109 #endif
110 
111 
112 
113 #endif // OPENIMAGEIO_DASSERT_H