|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
2 |
/* |
3 |
* Copyright (c) 2008 INRIA |
3 |
* Copyright (c) 2008 INRIA, 2010 NICTA |
4 |
* |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License version 2 as |
6 |
* it under the terms of the GNU General Public License version 2 as |
|
15 |
* along with this program; if not, write to the Free Software |
15 |
* along with this program; if not, write to the Free Software |
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 |
* |
17 |
* |
|
|
18 |
* Author: Original author unknown |
19 |
* Quincy Tse <quincy.tse@nicta.com.au> |
18 |
*/ |
20 |
*/ |
19 |
#ifndef NS3_ABORT_H |
21 |
#ifndef NS3_ABORT_H |
20 |
#define NS3_ABORT_H |
22 |
#define NS3_ABORT_H |
21 |
|
23 |
|
22 |
#include "fatal-error.h" |
24 |
#include "fatal-error.h" |
23 |
|
25 |
|
|
|
26 |
/** |
27 |
* \ingroup debugging |
28 |
* \brief Abnormal program termination |
29 |
* |
30 |
* \param msg message to output when this macro is hit. |
31 |
* |
32 |
* This macro is essentially equivalent to NS_FATAL_ERROR, |
33 |
* excepts it prepends the error message with the string |
34 |
* "aborted. ". When this macro is hit a runtime, the |
35 |
* program will be halted using std::terminate, which |
36 |
* triggers clean up code regestered by std::set_terminate. |
37 |
* |
38 |
* This macro is enable unconditionally in all builds, |
39 |
* including debug and optimized builds. |
40 |
* |
41 |
* \see NS_FATAL_ERROR |
42 |
*/ |
24 |
#define NS_ABORT_MSG(msg) \ |
43 |
#define NS_ABORT_MSG(msg) \ |
25 |
do { \ |
44 |
do { \ |
26 |
std::cerr << "file=" << __FILE__ << \ |
45 |
std::cerr << "aborted. "; \ |
27 |
", line=" << __LINE__ << ", abort, msg=\"" << \ |
46 |
NS_FATAL_ERROR (msg); \ |
28 |
msg << "\"" << std::endl; \ |
|
|
29 |
int *a = 0; \ |
30 |
*a = 0; \ |
31 |
} while (false) |
47 |
} while (false) |
32 |
|
48 |
|
33 |
|
49 |
|
34 |
#define NS_ABORT_IF(cond) \ |
50 |
/** |
35 |
do { \ |
51 |
* \ingroup debugging |
36 |
if (cond) \ |
52 |
* \brief Abnormal program termination if cond is true. |
37 |
{ \ |
53 |
* |
38 |
std::cerr << "file=" << __FILE__ << \ |
54 |
* \param cond condition to be evaluated. |
39 |
", line=" << __LINE__ << ", abort on=\""#cond << \ |
55 |
* |
40 |
"\"" << std::endl; \ |
56 |
* This is similar to NS_ASSERT(!(cond)), except this check |
41 |
int *a = 0; \ |
57 |
* is enabled in all builds. If cond is evaluated to true, |
42 |
*a = 0; \ |
58 |
* the espression evaluating to true is printed to stderr, |
43 |
} \ |
59 |
* followed by a call to the NS_FATAL_ERROR_NO_MSG() macro |
|
|
60 |
* which prints the details of filename and line number to |
61 |
* stderr. The program will be halted by calling |
62 |
* std::terminate(), triggering any clean up code registered |
63 |
* by std::set_terminate (NS3 default is a stream-flushing |
64 |
* code, but may be overridden). |
65 |
* |
66 |
* This macro is enable unconditionally in all builds, |
67 |
* including debug and optimized builds. |
68 |
*/ |
69 |
#define NS_ABORT_IF(cond) \ |
70 |
do { \ |
71 |
if (cond) \ |
72 |
{ \ |
73 |
std::cerr << "aborted. cond=\"" << #cond << ", "; \ |
74 |
NS_FATAL_ERROR_NO_MSG (); \ |
75 |
} \ |
44 |
} while (false) |
76 |
} while (false) |
45 |
|
77 |
|
46 |
#define NS_ABORT_MSG_IF(cond, msg) \ |
78 |
/** |
47 |
do { \ |
79 |
* \ingroup debugging |
48 |
if (cond) \ |
80 |
* \brief Abnormal program termination if cond is true. |
49 |
{ \ |
81 |
* |
50 |
std::cerr << "file=" << __FILE__ << \ |
82 |
* \param cond condition to be evaluated. |
51 |
", line=" << __LINE__ << ", abort on=\""#cond << \ |
83 |
* \param msg message to output when cond is true. |
52 |
"\", msg=\"" << msg << "\"" << std::endl; \ |
84 |
* |
53 |
int *a = 0; \ |
85 |
* This is similar to NS_ASSERT_MSG(!(cond)), except this |
54 |
*a = 0; \ |
86 |
* check is enabled in all builds. If cond is evaluated to |
55 |
} \ |
87 |
* true, the espression evaluating to true is printed to |
|
|
88 |
* stderr, followed by a call to the NS_FATAL_ERROR() macro |
89 |
* which prints the user-specified error message, and details |
90 |
* of filename and line number to stderr. The program will |
91 |
* be halted by calling std::terminate(), triggering any |
92 |
* clean up code registered by std::set_terminate (NS3 |
93 |
* default is a stream-flushing code, but may be overridden). |
94 |
* |
95 |
* This macro is enable unconditionally in all builds, |
96 |
* including debug and optimized builds. |
97 |
*/ |
98 |
#define NS_ABORT_MSG_IF(cond, msg) \ |
99 |
do { \ |
100 |
if (cond) \ |
101 |
{ \ |
102 |
std::cerr << "aborted. cond=\"" << #cond << "\", "; \ |
103 |
NS_FATAL_ERROR (msg); \ |
104 |
} \ |
56 |
} while (false) |
105 |
} while (false) |
57 |
|
106 |
|
58 |
#define NS_ABORT_UNLESS(cond) \ |
107 |
/** |
|
|
108 |
* \ingroup debugging |
109 |
* \brief Abnormal program termination if cond is false. |
110 |
* |
111 |
* \param cond condition to be evaluated. |
112 |
* |
113 |
* This is an alias for NS_ABORT_IF(!(cond)) |
114 |
* |
115 |
* \see NS_ABORT_IF |
116 |
*/ |
117 |
#define NS_ABORT_UNLESS(cond) \ |
59 |
NS_ABORT_IF(!(cond)) |
118 |
NS_ABORT_IF(!(cond)) |
60 |
|
119 |
|
61 |
#define NS_ABORT_MSG_UNLESS(cond, msg) \ |
120 |
/** |
|
|
121 |
* \ingroup debugging |
122 |
* \brief Abnormal program termination if cond is false. |
123 |
* |
124 |
* \param cond condition to be evaluated. |
125 |
* \param msg message to output if cond is false. |
126 |
* |
127 |
* This is an alias for NS_ABORT_MSG_IF(!(cond)) |
128 |
* |
129 |
* \see NS_ABORT_MSG_IF |
130 |
*/ |
131 |
#define NS_ABORT_MSG_UNLESS(cond, msg) \ |
62 |
NS_ABORT_MSG_IF(!(cond),msg) |
132 |
NS_ABORT_MSG_IF(!(cond),msg) |
63 |
|
133 |
|
64 |
#endif /* NS3_ABORT_H */ |
134 |
#endif /* NS3_ABORT_H */ |