ALBA
albaDbg.h
Go to the documentation of this file.
1/*=========================================================================
2 Program: Multimod Application Framework RELOADED
3 Module: $RCSfile: albaDbg.h,v $
4 Language: C++
5 Date: $Date: 2009-05-14 11:42:25 $
6 Version: $Revision: 1.1.2.1 $
7 Authors: Josef Kohout (Josef.Kohout *AT* beds.ac.uk)
8 ==========================================================================
9 Copyright (c) 2008 University of Bedfordshire (www.beds.ac.uk)
10 See the COPYINGS file for license details
11 =========================================================================
12 This header files contain some useful ASSERT and VERIFY type checks.
13 Both macros contain condition that must be fullfiled. If the condition
14 (given in an expression)is violated, it is handled in some way.
15 While ASSERT macros are present in the code compiled in _DEBUG mode only (they
16 are removed from code in RELEASE), VERIFY macros work in both modes, although
17 their behaviour might be slightly different (e.g., VERIFY does not display
18 messages into debug window. The behaviour of macros is, indeed, subject
19 to platform under which the code is compiled.
20
21 Macros may have one or more suffices:
22 [_EXPR][_CMD][_RPT][[_RET] or [_RETVAL] or [_THROW]]
23
24 _EXPR - have the expression (message) to be displayed if the condition is violated
25 _CMD - if the condition is violated, a user given command is executed
26 _RTP - if the condition is violated, it is reported but the program is not stopped
27 _RET - if the condition is violated, the call of the current routine is terminated
28 _RETVAL - similar to _RET but specifies the value to be returned
29 _THROW - throws an exception if the condition is violated
30*/
31#ifndef albaDbg_h__
32#define albaDbg_h__
33
34#pragma once
35
36#if defined(_MSC_VER)
37#include <crtdbg.h>
38#endif
39
40#include <assert.h>
41
42//PLATFORM DEPENDENT BASIC MACROS
43#if defined(_MSC_VER) && defined(_DEBUG)
44#define _DBG_RPT(msg) _CrtDbgReport(_CRT_WARN, __FILE__, __LINE__, NULL, msg)
45#define _DBG_BREAK(msg) _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, msg)
46
47#undef _ASSERT
48#define _ASSERT(expr) _ASSERTE(expr)
49#else
50#define _DBG_RPT(msg) fprintf(stderr, "%s at %s(%d)\n", \
51 (msg == NULL ? "Assert " : msg), __FILE__, __LINE__)
52#define _DBG_BREAK(msg) assert(false)
53
54#ifndef _ASSERT_EXPR
55#define _ASSERT_EXPR(expr, msg) assert(expr)
56#endif
57
58#ifndef _ASSERT
59#define _ASSERT(expr) _ASSERT_EXPR((expr), #expr)
60#endif
61
62#ifndef _ASSERTE
63#define _ASSERTE(expr) _ASSERT_EXPR((expr), #expr)
64#endif
65#endif
66
67
68//ALL PLATFORMS
69#ifdef _DEBUG
70
71#define _ASSERT_EXPR_RPT(expr, msg) if (!(expr)) _DBG_RPT(msg)
72#define _ASSERT_RTP(expr) _ASSERT_EXPR_RPT(expr, #expr)
73
74#define _ASSERT_EXPR_CMD(expr, msg, command) if (!(expr)) {_DBG_BREAK(msg); command; }
75#define _ASSERT_CMD(expr, command) _ASSERT_EXPR_CMD(expr, #expr, command)
76#define _ASSERT_EXPR_CMD_RPT(expr, msg, command) if (!(expr)) {_DBG_RPT(msg); command; }
77#define _ASSERT_CMD_RPT(expr, command) _ASSERT_EXPR_CMD_RPT(expr, #expr, command)
78
79#define _ASSERT_EXPR_RET(expr, msg) _ASSERT_EXPR_CMD(expr, msg, return)
80#define _ASSERT_RET(expr) _ASSERT_EXPR_CMD(expr, #expr, return)
81#define _ASSERT_EXPR_RPT_RET(expr, msg) _ASSERT_EXPR_CMD_RPT(expr, msg, return)
82#define _ASSERT_PRT_RET(expr) _ASSERT_EXPR_CMD_RPT(expr, #expr, return)
83
84#define _ASSERT_EXPR_RETVAL(expr, msg, retval) _ASSERT_EXPR_CMD(expr, msg, return (retval))
85#define _ASSERT_RETVAL(expr, retval) _ASSERT_EXPR_CMD(expr, #expr, return (retval))
86#define _ASSERT_EXPR_RPT_RETVAL(expr, msg, retval) _ASSERT_EXPR_CMD_RPT(expr, msg, return (retval))
87#define _ASSERT_PRT_RETVAL(expr, retval) _ASSERT_EXPR_CMD_RPT(expr, #expr, return (retval))
88
89#define _ASSERT_EXPR_THROW(expr, msg, exc) _ASSERT_EXPR_CMD(expr, msg, throw (exc))
90#define _ASSERT_THROW(expr, exc) _ASSERT_EXPR_CMD(expr, #expr, throw (exc))
91#define _ASSERT_EXPR_RPT_THROW(expr, msg, exc) _ASSERT_EXPR_CMD_RPT(expr, msg, throw (exc))
92#define _ASSERT_PRT_THROW(expr, exc) _ASSERT_EXPR_CMD_RPT(expr, #expr, throw (exc))
93
94#define _VERIFY_EXPR(expr, msg) _ASSERT_EXPR(expr, msg)
95#define _VERIFY(expr) _ASSERT(expr)
96
97#define _VERIFY_EXPR_RPT(expr, msg) if (!(expr)) _DBG_RPT(msg)
98#define _VERIFY_RTP(expr) _ASSERT_RTP(expr)
99
100#define _VERIFY_EXPR_CMD(expr, msg, command) if (!(expr)) {_DBG_BREAK(msg); command; }
101#define _VERIFY_CMD(expr, command) _ASSERT_CMD(expr, command)
102#define _VERIFY_EXPR_CMD_RPT(expr, msg, command) if (!(expr)) {_DBG_RPT(msg); command; }
103#define _VERIFY_CMD_RPT(expr, command) _ASSERT_CMD_RPT(expr, command)
104
105#define _VERIFY_EXPR_RET(expr, msg) _ASSERT_EXPR_RET(expr, msg)
106#define _VERIFY_RET(expr) _ASSERT_RET(expr)
107#define _VERIFY_EXPR_RPT_RET(expr, msg) _ASSERT_EXPR_RPT_RET(expr, msg)
108#define _VERIFY_PRT_RET(expr) _ASSERT_PRT_RET(expr)
109
110#define _VERIFY_EXPR_RETVAL(expr, msg, retval) _ASSERT_EXPR_RETVAL(expr, msg, retval)
111#define _VERIFY_RETVAL(expr, retval) _ASSERT_RETVAL(expr, retval)
112#define _VERIFY_EXPR_RPT_RETVAL(expr, msg, retval) _ASSERT_EXPR_RPT_RETVAL(expr, msg, retval)
113#define _VERIFY_PRT_RETVAL(expr, retval) _ASSERT_PRT_RETVAL(expr, retval)
114
115#define _VERIFY_EXPR_THROW(expr, msg, exc) _ASSERT_EXPR_THROW(expr, msg, exc)
116#define _VERIFY_THROW(expr, exc) _ASSERT_THROW(expr, exc)
117#define _VERIFY_EXPR_RPT_THROW(expr, msg, exc) _ASSERT_EXPR_RPT_THROW(expr, msg, exc)
118#define _VERIFY_PRT_THROW(expr, exc) _ASSERT_PRT_THROW(expr, exc)
119#else
120//RELEASE mode
121
122#define _ASSERT_EXPR_RPT(expr, msg) ((void)0)
123#define _ASSERT_RTP(expr) ((void)0)
124
125#define _ASSERT_EXPR_CMD(expr, msg, command) ((void)0)
126#define _ASSERT_CMD(expr, command) ((void)0)
127#define _ASSERT_EXPR_CMD_RPT(expr, msg, command) ((void)0)
128#define _ASSERT_CMD_RPT(expr, command) ((void)0)
129
130#define _ASSERT_EXPR_RET(expr, msg) ((void)0)
131#define _ASSERT_RET(expr) ((void)0)
132#define _ASSERT_EXPR_RPT_RET(expr, msg) ((void)0)
133#define _ASSERT_PRT_RET(expr) ((void)0)
134
135#define _ASSERT_EXPR_RETVAL(expr, msg, retval) ((void)0)
136#define _ASSERT_RETVAL(expr, retval) ((void)0)
137#define _ASSERT_EXPR_RPT_RETVAL(expr, msg, retval) ((void)0)
138#define _ASSERT_PRT_RETVAL(expr, retval) ((void)0)
139
140#define _ASSERT_EXPR_THROW(expr, msg, exc) ((void)0)
141#define _ASSERT_THROW(expr, exc) ((void)0)
142#define _ASSERT_EXPR_RPT_THROW(expr, msg, exc) ((void)0)
143#define _ASSERT_PRT_THROW(expr, exc) _ASSERT_EXPR_CMD_RPT(expr, #expr, throw (exc))
144
145#define _VERIFY_EXPR(expr, msg) expr
146#define _VERIFY(expr) expr
147
148#define _VERIFY_EXPR_RPT(expr, msg) expr
149#define _VERIFY_RTP(expr) expr
150
151#define _VERIFY_EXPR_CMD(expr, msg, command) if (!(expr)) { command; }
152#define _VERIFY_CMD(expr, command) if (!(expr)) { command; }
153#define _VERIFY_EXPR_CMD_RPT(expr, msg, command) if (!(expr)) { command; }
154#define _VERIFY_CMD_RPT(expr, command) if (!(expr)) { command; }
155
156#define _VERIFY_EXPR_RET(expr, msg) _VERIFY_CMD(expr, return)
157#define _VERIFY_RET(expr) _VERIFY_CMD(expr, return)
158#define _VERIFY_EXPR_RPT_RET(expr, msg) _VERIFY_CMD(expr, return)
159#define _VERIFY_PRT_RET(expr) _VERIFY_CMD(expr, return)
160
161#define _VERIFY_EXPR_RETVAL(expr, msg, retval) _VERIFY_CMD(expr, return (retval))
162#define _VERIFY_RETVAL(expr, retval) _VERIFY_CMD(expr, return (retval))
163#define _VERIFY_EXPR_RPT_RETVAL(expr, msg, retval) _VERIFY_CMD(expr, return (retval))
164#define _VERIFY_PRT_RETVAL(expr, retval) _VERIFY_CMD(expr, return (retval))
165
166#define _VERIFY_EXPR_THROW(expr, msg, exc) _VERIFY_CMD(expr, throw (exc))
167#define _VERIFY_THROW(expr, exc) _VERIFY_CMD(expr, throw (exc))
168#define _VERIFY_EXPR_RPT_THROW(expr, msg, exc) _VERIFY_CMD(expr, throw (exc))
169#define _VERIFY_PRT_THROW(expr, exc) _VERIFY_CMD(expr, throw (exc))
170
171#endif
172
173
174#endif // albaDbg_h__