WvStreams
debian/libwvstreams-dev/usr/include/wvstreams/wvassert.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 2005 Net Integration Technologies, Inc.
4 *
5 * Helper classes and functions to add more information to WvCrashes.
6 */
7#ifndef __WVASSERT_H
8#define __WVASSERT_H
9
10#include <assert.h>
11
12#include "wvcrash.h"
13#include "wvstring.h"
14
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.
18//
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.
23{
24public:
25 // Leave a will behind.
26 WvCrashWill(const char *will);
27 WvCrashWill(WVSTRING_FORMAT_DECL);
28
29 // Restore the will that was there before you created this object.
31
32 // Rewrite the will you're leaving behind.
33 void rewrite(const char *will);
34 void rewrite(WVSTRING_FORMAT_DECL);
35private:
36 WvString old_will;
37};
38
39#if !defined(__GLIBC__)
40
41# define wvassert(expr, args...) assert(expr)
42# define wvassert_perror(errnum) perror(errnum)
43
44#elif defined(NDEBUG)
45
46# define wvassert(expr, args...) (__ASSERT_VOID_CAST (0))
47# define wvassert_perror(errnum) (__ASSERT_VOID_CAST (0))
48
49#else // Not NDEBUG
50
51static inline void __wvcrash_leave_will()
52{
53}
54
55static inline void __wvcrash_leave_will(const char *will)
56{
57 wvcrash_leave_will(will);
58}
59
60static inline void __wvcrash_leave_will(WVSTRING_FORMAT_DECL)
61{
62 wvcrash_leave_will(WvFastString(WVSTRING_FORMAT_CALL));
63}
64
65// Use this function instead of assert(). You may also leave parameters
66// at the end, which allow you to log messages. For instance:
67//
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))))
74
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:
77//
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))))
84
85#endif // NDEBUG
86
87#endif // WVASSERT_H
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
WvString is an implementation of a simple and efficient printable-string class.