A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
abort.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA, 2010 NICTA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Original author unknown
18 * Quincy Tse <quincy.tse@nicta.com.au>
19 */
20#ifndef NS3_ABORT_H
21#define NS3_ABORT_H
22
23#include "fatal-error.h"
24
25/**
26 * \file
27 * \ingroup fatal
28 * \brief \c NS_ABORT_x macro definitions.
29 */
30
31/**
32 * \ingroup fatal
33 *
34 * \brief Unconditional abnormal program termination with a message.
35 *
36 * \param [in] msg The message to output when this macro is hit.
37 *
38 * This macro is essentially equivalent to NS_FATAL_ERROR,
39 * except it prepends the error message with the string
40 * "aborted. ". When this macro is hit at runtime, the
41 * program will be halted using \c std::terminate, which
42 * triggers clean up code registered by \c std::set_terminate.
43 *
44 * This macro is enabled unconditionally in all builds,
45 * including debug and optimized builds.
46 *
47 * \see NS_FATAL_ERROR
48 */
49#define NS_ABORT_MSG(msg) \
50 do \
51 { \
52 std::cerr << "aborted. "; \
53 NS_FATAL_ERROR(msg); \
54 } while (false)
55
56/**
57 * \ingroup fatal
58 *
59 * \brief Abnormal program termination if a condition is \c true.
60 *
61 * \param [in] cond The condition to be evaluated.
62 *
63 * This is similar to \c NS_ASSERT(!(cond)), except this check
64 * is enabled in all builds. If \c cond is evaluated to \c true,
65 * the expression for \c cond is printed to \c stderr,
66 * followed by a call to the NS_FATAL_ERROR_NO_MSG() macro
67 * which prints the details of filename and line number to
68 * \c stderr. The program will be halted by calling
69 * \c std::terminate(), triggering any clean up code registered
70 * by \c std::set_terminate. The ns-3 default is a stream-flushing
71 * code, but may be overridden.
72 *
73 * This macro is enabled unconditionally in all builds,
74 * including debug and optimized builds.
75 */
76#define NS_ABORT_IF(cond) \
77 do \
78 { \
79 if (cond) \
80 { \
81 std::cerr << "aborted. cond=\"" << #cond << ", "; \
82 NS_FATAL_ERROR_NO_MSG(); \
83 } \
84 } while (false)
85
86/**
87 * \ingroup fatal
88 *
89 * \brief Abnormal program termination if a condition is \c true,
90 * with a message.
91 *
92 * \param [in] cond The condition to be evaluated.
93 * \param [in] msg The message to output when cond is \c true.
94 *
95 * This is similar to NS_ASSERT_MSG(!(cond)), except this
96 * check is enabled in all builds. If \c cond is evaluated to
97 * \c true, the expression for \c cond is printed to
98 * \c stderr, followed by a call to the NS_FATAL_ERROR() macro
99 * which prints the user-specified error message, and details
100 * of filename and line number to \c stderr. The program will
101 * be halted by calling \c std::terminate(), triggering any
102 * clean up code registered by \c std::set_terminate. The ns-3
103 * default is a stream-flushing code, but may be overridden.
104 *
105 * This macro is enabled unconditionally in all builds,
106 * including debug and optimized builds.
107 */
108#define NS_ABORT_MSG_IF(cond, msg) \
109 do \
110 { \
111 if (cond) \
112 { \
113 std::cerr << "aborted. cond=\"" << #cond << "\", "; \
114 NS_FATAL_ERROR(msg); \
115 } \
116 } while (false)
117
118/**
119 * \ingroup fatal
120 *
121 * \brief Abnormal program termination if a condition is \c false.
122 *
123 * \param [in] cond The condition to be evaluated.
124 *
125 * This is an alias for NS_ABORT_IF(!(cond))
126 *
127 * \see NS_ABORT_IF
128 */
129#define NS_ABORT_UNLESS(cond) NS_ABORT_IF(!(cond))
130
131/**
132 * \ingroup fatal
133 *
134 * \brief Abnormal program termination if a condition is \c false,
135 * with a message.
136 *
137 * \param [in] cond The condition to be evaluated.
138 * \param [in] msg The message to output if cond is false.
139 *
140 * This is an alias for NS_ABORT_MSG_IF(!(cond))
141 *
142 * \see NS_ABORT_MSG_IF
143 */
144#define NS_ABORT_MSG_UNLESS(cond, msg) NS_ABORT_MSG_IF(!(cond), msg)
145
146#endif /* NS3_ABORT_H */
NS_FATAL_x macro definitions.