~zorba-coders/zorba/trunk

« back to all changes in this revision

Viewing changes to src/diagnostics/assert.h

  • Committer: Tarmac
  • Author(s): David Graf
  • Date: 2012-04-13 09:17:58 UTC
  • mfrom: (10744.4.4 ordpathmsgs)
  • Revision ID: tarmac-20120413091758-j8svpeqfzais0ycy
Bug #980600.
Introduced ZORBA_ASSERT_WITH_MSG macro to give additional debugging information in case an assertion fails. Currently used in Ordpath functions. Approved: Till Westmann, Markos Zaharioudakis

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 * @param condition The string representation of the condition that failed.
30
30
 * @param file The C++ source-code file name where the assertion failed.
31
31
 * @param line The C++ source-code line number where the assertion failed.
 
32
 * @param msg An optional message that is output if the assertion fails.
32
33
 * @throws ZXQP0002_ASSERT_FAILED
33
34
 */
34
 
void assertion_failed( char const *condition, char const *file, int line );
 
35
void assertion_failed( char const *condition,
 
36
                       char const *file, 
 
37
                       int line, 
 
38
                       char const *msg = 0);
35
39
 
36
40
/**
37
41
 * Zorba version of the standard assert(3) macro.
 
42
 * Is checked in RELEASE mode as well. And outputs a special
 
43
 * error code with the failing condition.
38
44
 */
39
45
#define ZORBA_ASSERT(COND)                                  \
40
46
  do {                                                      \
44
50
    }                                                       \
45
51
  } while (0)
46
52
 
 
53
/**
 
54
 * Zorba version of the standard assert(3) macro.
 
55
 * Is checked in RELEASE mode as well. And outputs a special
 
56
 * error code with the failing condition as well as potentially
 
57
 * useful information for further debugging.
 
58
 */
 
59
#define ZORBA_ASSERT_WITH_MSG(COND,MSG)                                        \
 
60
  do {                                                                         \
 
61
    if ( !(COND) ) {                                                           \
 
62
      std::ostringstream oss;                                                  \
 
63
      oss << MSG;                                                              \
 
64
      zorba::assertion_failed( #COND, __FILE__, __LINE__, oss.str().c_str() ); \
 
65
      throw 0; /* never gets here but suppresses warning */                    \
 
66
    }                                                                          \
 
67
  } while (0)
 
68
 
47
69
} // namespace zorba
48
70
#endif /* ZORBA_ASSERT_H */
49
71
/* vim:set et sw=2 ts=2: */