libfoedus-core
FOEDUS Core Library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
assert_nd.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_ASSERT_ND_HPP_
19 #define FOEDUS_ASSERT_ND_HPP_
20 
21 #include <string>
22 
44 namespace foedus {
46  std::string print_assert(const char* file, const char* func, int line, const char* description);
48  std::string print_backtrace();
49 
55  const char* file,
56  const char* func,
57  int line,
58  const char* description);
59 
61  std::string get_recent_assert_backtrace();
62 } // namespace foedus
63 
64 #ifdef NDEBUG
65 #define ASSERT_ND(x) do { (void) sizeof(x); } while (0)
66 #define UNUSED_ND(var) ASSERT_ND(var)
67 #else // NDEBUG
68 #include <cassert>
69 #ifndef ASSERT_ND_NOBACKTRACE
70 #define ASSERT_QUOTE(str) #str
71 #define ASSERT_EXPAND_AND_QUOTE(str) ASSERT_QUOTE(str)
72 #define ASSERT_ND(x) do { if (!(x)) { \
73  foedus::print_assert_backtrace(__FILE__, __FUNCTION__, __LINE__, ASSERT_QUOTE(x)); \
74  assert(x); \
75  } } while (0)
76 #else // ASSERT_ND_NOBACKTRACE
77 #define ASSERT_ND(x) assert(x)
78 #endif // ASSERT_ND_NOBACKTRACE
79 #define UNUSED_ND(var)
80 #endif // NDEBUG
81 
82 #endif // FOEDUS_ASSERT_ND_HPP_
std::string get_recent_assert_backtrace()
Retrieves the info left by print_assert_backtrace().
Definition: assert_nd.cpp:60
std::string print_assert(const char *file, const char *func, int line, const char *description)
Helper function to report what assertion failed.
Definition: assert_nd.cpp:28
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
void print_assert_backtrace(const char *file, const char *func, int line, const char *description)
print_assert() + print_backtrace().
Definition: assert_nd.cpp:52
std::string print_backtrace()
Prints out backtrace.
Definition: assert_nd.cpp:37