source: git/factory/cf_assert.h @ 362fc67

fieker-DuValspielwiese
Last change on this file since 362fc67 was 362fc67, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: remove $Id$
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/* emacs edit mode for this file is -*- C -*- */
2
3/* This is for compatibility with standard cf_assert.h */
4#if defined (NDEBUG) && ! defined (NOASSERT)
5#define NOASSERT
6#endif
7
8/* It should be possible to include this file multiple times for different */
9/* settings of NOASSERT */
10
11/* {{{ undefines */
12#undef __ASSERT
13#undef __ASSERT1
14#undef STICKYASSERT
15#undef STICKYASSERT1
16#undef ASSERT
17#undef ASSERT1
18
19#undef __WARN
20#undef STICKYWARN
21#undef WARN
22
23#undef PVIRT_VOID
24#undef PVIRT_INTCF
25#undef PVIRT_BOOL
26#undef PVIRT_INT
27#undef PVIRT_CHARCC
28/* }}} */
29
30#ifdef __cplusplus
31#ifndef NOSTREAMIO
32#ifdef HAVE_CSTDIO
33#include <cstdio>
34#else
35extern "C" {
36#include <stdio.h>
37#include <stdlib.h>
38}
39#endif
40#else
41#include <stdio.h>
42#include <stdlib.h>
43#endif
44#endif
45
46/* {{{ permanent macro definitions */
47#ifndef __GNUC__
48#define __ASSERT(expression, message, file, line) \
49(fprintf( stderr, "error: " message "\n%s:%u: failed assertion `%s'\n", \
50 file, line, expression ), abort(), 0 )
51#define __ASSERT1(expression, message, parameter1, file, line)  \
52(fprintf( stderr, "error: " message "\n%s:%u: failed assertion `%s'\n", \
53 parameter1, file, line, expression ), abort(), 0 )
54
55#define STICKYASSERT(expression, message) \
56((void)((expression) ? 0 : __ASSERT(#expression, message, __FILE__, __LINE__)))
57#define STICKYASSERT1(expression, message, parameter1) \
58((void)((expression) ? 0 : __ASSERT1(#expression, message, parameter1, __FILE__, __LINE__)))
59
60#define __WARN(expression, message, file, line)  \
61(fprintf( stderr, "warning: " message "\n%s:%u: failed assertion `%s'\n", \
62 file, line, expression ), 0 )
63#define STICKYWARN(expression, message) \
64((void)((expression) ? 0 : __WARN(#expression, message, __FILE__, __LINE__)))
65#else /* __GNUCC__ */
66/* use preprocessor macro __PRETTY_FUNCTION__ for more informative output */
67#define __ASSERT(expression, message, file, line, function) \
68(fprintf( stderr, "error: " message "\n%s:%u: In function `%s':\nfailed assertion `%s'\n", \
69 file, line, function, expression ), abort(), 0 )
70#define __ASSERT1(expression, message, parameter1, file, line, function)  \
71(fprintf( stderr, "error: " message "\n%s:%u: In function `%s':\nfailed assertion `%s'\n", \
72 parameter1, file, line, function, expression ), abort(), 0 )
73
74#define STICKYASSERT(expression, message) \
75((void)((expression) ? 0 : __ASSERT(#expression, message, __FILE__, __LINE__, __PRETTY_FUNCTION__)))
76#define STICKYASSERT1(expression, message, parameter1) \
77((void)((expression) ? 0 : __ASSERT1(#expression, message, parameter1, __FILE__, __LINE__, __PRETTY_FUNCTION__)))
78
79#define __WARN(expression, message, file, line, function)  \
80(fprintf( stderr, "warning: " message "\n%s:%u: In function `%s':\nfailed assertion `%s'\n", \
81 file, line, function, expression ), 0 )
82#define STICKYWARN(expression, message) \
83((void)((expression) ? 0 : __WARN(#expression, message, __FILE__, __LINE__, __PRETTY_FUNCTION__)))
84#endif /* __GNUCC__ */
85/* }}} */
86
87/* {{{ macro definitions dependent on NOASSERT */
88#ifndef NOASSERT
89#ifndef __GNUC__
90#define ASSERT(expression, message) \
91((void)((expression) ? 0 : __ASSERT(#expression, message, __FILE__, __LINE__)))
92#define ASSERT1(expression, message, parameter1) \
93((void)((expression) ? 0 : __ASSERT1(#expression, message, parameter1, __FILE__, __LINE__)))
94
95#define WARN(expression, message) \
96((void)((expression) ? 0 : __WARN(#expression, message, __FILE__, __LINE__)))
97#else /* __GNUCC__ */
98/* use preprocessor macro __PRETTY_FUNCTION__ for more informative output */
99#define ASSERT(expression, message) \
100((void)((expression) ? 0 : __ASSERT(#expression, message, __FILE__, __LINE__, __PRETTY_FUNCTION__)))
101#define ASSERT1(expression, message, parameter1) \
102((void)((expression) ? 0 : __ASSERT1(#expression, message, parameter1, __FILE__, __LINE__, __PRETTY_FUNCTION__)))
103
104#define WARN(expression, message) \
105((void)((expression) ? 0 : __WARN(#expression, message, __FILE__, __LINE__, __PRETTY_FUNCTION__)))
106#endif /* __GNUCC__ */
107
108#define PVIRT_VOID(msg) \
109{ fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); }
110#define PVIRT_INTCF(msg) \
111{ fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return 0; }
112#define PVIRT_BOOL(msg) \
113{ fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return false; }
114#define PVIRT_INT(msg) \
115{ fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return 0; }
116#define PVIRT_CHARCC(msg) \
117{ fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return 0; }
118#else /* NOASSERT */
119#define ASSERT(expression, message) ((void) 0)
120#define ASSERT1(expression, message, parameter1) ((void) 0)
121
122#define WARN(expression, message) ((void) 0)
123
124#define PVIRT_VOID(msg) = 0
125#define PVIRT_INTCF(msg) = 0
126#define PVIRT_BOOL(msg) = 0
127#define PVIRT_INT(msg) = 0
128#define PVIRT_CHARCC(msg) = 0
129#endif /* NOASSERT */
130/* }}} */
Note: See TracBrowser for help on using the repository browser.