HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dassert.h File Reference
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <OpenImageIO/platform.h>
+ Include dependency graph for dassert.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define OIIO_ABORT_IF_DEBUG   abort()
 
#define OIIO_ASSERT(x)
 
#define OIIO_ASSERT_MSG(x, msg,...)
 
#define OIIO_DASSERT   OIIO_ASSERT
 
#define OIIO_DASSERT_MSG   OIIO_ASSERT_MSG
 
#define ASSERT(x)
 
#define ASSERT_MSG(x, msg,...)
 
#define ASSERTMSG   ASSERT_MSG
 
#define DASSERT(x)   assert(x)
 
#define DASSERT_MSG   ASSERT_MSG
 
#define DASSERTMSG   DASSERT_MSG
 
#define OIIO_STATIC_ASSERT(cond)   static_assert(cond, "")
 
#define OIIO_STATIC_ASSERT_MSG(cond, msg)   static_assert(cond, msg)
 Deprecated synonym: More...
 

Macro Definition Documentation

#define ASSERT (   x)
Value:
? ((void)0) \
: (std::fprintf(stderr, "%s:%u: %s: Assertion '%s' failed.\n", \
__FILE__, __LINE__, OIIO_PRETTY_FUNCTION, #x), \
abort()))
#define OIIO_LIKELY(x)
Definition: platform.h:342
void
Definition: png.h:1083
GLint GLenum GLint x
Definition: glcorearb.h:408
#define OIIO_PRETTY_FUNCTION
Definition: platform.h:483
int fprintf(std::FILE *f, const S &format, const Args &...args)
Definition: printf.h:681

ASSERT and ASSERT_MSG (and, ugh, ASSERTMSG) are deprecated assertion macros. They are deprecated for two reasons: (1) terrible names pollute the global namespace and might conflict with other packages; and (2) the fully unconditional nature of aborting even for release builds is unkind to applications. Consider these all to be deprecated and avoid using these macros.

DASSERT and DASSERT_MSG also are considered deprecated for the namespace reasons.

Definition at line 73 of file dassert.h.

#define ASSERT_MSG (   x,
  msg,
  ... 
)
Value:
? ((void)0) \
: (std::fprintf(stderr, \
"%s:%u: %s: Assertion '%s' failed: " msg "\n", \
__FILE__, __LINE__, OIIO_PRETTY_FUNCTION, #x, \
__VA_ARGS__), \
abort()))
#define OIIO_LIKELY(x)
Definition: platform.h:342
void
Definition: png.h:1083
GLint GLenum GLint x
Definition: glcorearb.h:408
#define OIIO_PRETTY_FUNCTION
Definition: platform.h:483
int fprintf(std::FILE *f, const S &format, const Args &...args)
Definition: printf.h:681

Definition at line 82 of file dassert.h.

#define ASSERTMSG   ASSERT_MSG

Definition at line 93 of file dassert.h.

#define DASSERT (   x)    assert(x)

DASSERT(condition) is just an alias for the usual assert() macro. It does nothing when in a non-DEBUG (optimized, shipping) build.

Definition at line 100 of file dassert.h.

#define DASSERT_MSG   ASSERT_MSG

DASSERT_MSG(condition,msg,...) is just like ASSERT_MSG, except that it only is functional in DEBUG mode, but does nothing when in a non-DEBUG (optimized, shipping) build.

Definition at line 110 of file dassert.h.

#define DASSERTMSG   DASSERT_MSG

Definition at line 117 of file dassert.h.

#define OIIO_ABORT_IF_DEBUG   abort()

OIIO_ABORT_IF_DEBUG is a call to abort() for debug builds, but does nothing for release builds.

Definition at line 18 of file dassert.h.

#define OIIO_ASSERT (   x)
Value:
? ((void)0) \
: (std::fprintf(stderr, "%s:%u: %s: Assertion '%s' failed.\n", \
__FILE__, __LINE__, OIIO_PRETTY_FUNCTION, #x), \
#define OIIO_LIKELY(x)
Definition: platform.h:342
void
Definition: png.h:1083
GLint GLenum GLint x
Definition: glcorearb.h:408
#define OIIO_PRETTY_FUNCTION
Definition: platform.h:483
int fprintf(std::FILE *f, const S &format, const Args &...args)
Definition: printf.h:681
#define OIIO_ABORT_IF_DEBUG
Definition: dassert.h:18

OIIO_ASSERT(condition) checks if the condition is met, and if not, prints an error message indicating the module and line where the error occurred, and additionally aborts if in debug mode. When in release mode, it prints the error message if the condition fails, but does not abort.

OIIO_ASSERT_MSG(condition,msg,...) lets you add formatted output (a la printf) to the failure message.

Definition at line 32 of file dassert.h.

#define OIIO_ASSERT_MSG (   x,
  msg,
  ... 
)
Value:
? ((void)0) \
: (std::fprintf(stderr, "%s:%u: %s: Assertion '%s' failed: " msg "\n", \
__FILE__, __LINE__, OIIO_PRETTY_FUNCTION, #x, \
__VA_ARGS__), \
#define OIIO_LIKELY(x)
Definition: platform.h:342
void
Definition: png.h:1083
GLint GLenum GLint x
Definition: glcorearb.h:408
#define OIIO_PRETTY_FUNCTION
Definition: platform.h:483
int fprintf(std::FILE *f, const S &format, const Args &...args)
Definition: printf.h:681
#define OIIO_ABORT_IF_DEBUG
Definition: dassert.h:18

Definition at line 38 of file dassert.h.

#define OIIO_DASSERT   OIIO_ASSERT

OIIO_DASSERT and OIIO_DASSERT_MSG are the same as OIIO_ASSERT for debug builds (test, print error, abort), but do nothing at all in release builds (not even perform the test). This is similar to C/C++ assert(), but gives us flexibility in improving our error messages. It is also ok to use regular assert() for this purpose if you need to eliminate the dependency on this header from a particular place (and don't mind that assert won't format identically on all platforms).

Definition at line 55 of file dassert.h.

#define OIIO_DASSERT_MSG   OIIO_ASSERT_MSG

Definition at line 56 of file dassert.h.

#define OIIO_STATIC_ASSERT (   cond)    static_assert(cond, "")

Define OIIO_STATIC_ASSERT(cond) as a wrapper around static_assert(cond), with appropriate fallbacks for older C++ standards.

Definition at line 126 of file dassert.h.

#define OIIO_STATIC_ASSERT_MSG (   cond,
  msg 
)    static_assert(cond, msg)

Deprecated synonym:

Definition at line 130 of file dassert.h.