1 /*
2 * Assert.hpp
3 *
4 * Copyright (C) 2012 Evidence Srl - www.evidence.eu.com
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef ASSERT_HPP_
22 #define ASSERT_HPP_
23
24 #include <iostream>
25 #include <cstdlib>
26
27 /**
28 * \brief It prints the failed message and aborts the execution.
29 *
30 * This function is not meant to be used directly. Use VERIFY_ASSERTION.
31 * @param expr The expression that has been evaluated.
32 * @param file The file containing the evaluated expression.
33 * @param line The line that contains the evaluated expression.
34 */
36 {
37 std::cerr << "Assertion \"" << expr << "\" failed [" << file << ":"
38 << line << "]" << std::endl;
39 std::abort();
40 }
41
42 /** \brief Macro to evaluate an expression.
43 *
44 * If the expression evaluates to false then the AssertionFailedMsg function is
45 * called.
46 */
47 #define VERIFY_ASSERTION(expr) \
48 (expr ? static_cast<void>(0) : AssertionFailedMsg(#expr, __FILE__,\
49 __LINE__))
50
51 #endif /* ASSERT_HPP_ */