Make WvStreams compile with gcc 4.4.
[wvstreams.git] / include / wvassert.h
blob2a5eb0a7717224978cbff2a0418246daf78ac95f
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 2005 Net Integration Technologies, Inc.
5 * Helper classes and functions to add more information to WvCrashes.
6 */
7 #ifndef __WVASSERT_H
8 #define __WVASSERT_H
10 #include <assert.h>
12 #include "wvcrash.h"
13 #include "wvstring.h"
15 // WvCrash allows you to print a programme's last will and testament.
16 // That is, a little note about what it was hoping to do before it
17 // died.
19 // This helper class lets you write a will, and when it gets
20 // destroyed, it will restore the old will from before. This lets you
21 // safely nest them.
22 class WvCrashWill
24 public:
25 // Leave a will behind.
26 WvCrashWill(const char *will);
27 WvCrashWill(WVSTRING_FORMAT_DECL);
29 // Restore the will that was there before you created this object.
30 ~WvCrashWill();
32 // Rewrite the will you're leaving behind.
33 void rewrite(const char *will);
34 void rewrite(WVSTRING_FORMAT_DECL);
35 private:
36 WvString old_will;
39 #if !defined(__GLIBC__)
41 # define wvassert(expr, args...) assert(expr)
42 # define wvassert_perror(errnum) perror(errnum)
44 #elif defined(NDEBUG)
46 # define wvassert(expr, args...) (__ASSERT_VOID_CAST (0))
47 # define wvassert_perror(errnum) (__ASSERT_VOID_CAST (0))
49 #else // Not NDEBUG
51 static inline void __wvcrash_leave_will()
55 static inline void __wvcrash_leave_will(const char *will)
57 wvcrash_leave_will(will);
60 static inline void __wvcrash_leave_will(WVSTRING_FORMAT_DECL)
62 wvcrash_leave_will(WvFastString(WVSTRING_FORMAT_CALL));
65 // Use this function instead of assert(). You may also leave parameters
66 // at the end, which allow you to log messages. For instance:
68 // wvassert(a == b, "a: '%s'\n b: '%s'", a, b);
69 # define wvassert(expr, args...) \
70 (__ASSERT_VOID_CAST ((expr) ? 0 : \
71 (__wvcrash_leave_will (args), \
72 (__assert_fail (__STRING(expr), __FILE__, __LINE__, \
73 __ASSERT_FUNCTION), 0))))
75 // Use this function instead of assert_perror(). You may also leave
76 // parameters at the end, which allow you to log messages. For instance:
78 // wvassert(errno, "Error trying to read file: '%s'", filename);
79 # define wvassert_perror(errnum, args...) \
80 (__ASSERT_VOID_CAST (!(errnum) ? 0 : \
81 (__wvcrash_leave_will (args), \
82 (__assert_perror_fail ((errnum), __FILE__, __LINE__, \
83 __ASSERT_FUNCTION), 0))))
85 #endif // NDEBUG
87 #endif // WVASSERT_H