Newer
Older
#ifndef DUNE_STUFF_DEBUG_HH
#define DUNE_STUFF_DEBUG_HH
#include <boost/assert.hpp>
#include <boost/format.hpp>
#define SEGFAULT \
{ \
int* J = 0; \
*J = 9; \
}
const char* rightPathLimiter(const char* path, int depth = 2)
{
char* c = new char[255];
strcpy(c, path);
const char* p = strtok(c, "/");
int i = 0;
while (p && i < depth) {
p = strtok(NULL, "/");
}
p = strtok(NULL, "\0");
return p;
#ifndef NDEBUG
#ifndef LOGIC_ERROR
#include <stdexcept>
#include <sstream>
#define LOGIC_ERROR \
{ \
std::stringstream ss; \
ss << __FILE__ << ":" << __LINE__ << " should never be called"; \
throw std::logic_error(ss.str()); \
}
for (size_t i = 0; i < l; i++) {
#define __CLASS__ strtok(copy(__PRETTY_FUNCTION__), "<(")
#ifndef NDEBUG
#define NEEDS_IMPLEMENTATION \
{ \
std::stringstream ss; \
ss << " implementation missing: " << __CLASS__ << " -- " << rightPathLimiter(__FILE__) << ":" << __LINE__; \
std::cerr << ss.str() << std::endl; \
}
#define NEEDS_IMPLEMENTATION
#endif // NDEBUG
class assert_exception : public std::runtime_error
{
public:
assert_exception(std::string msg)
class singlerun_abort_exception : public std::runtime_error
{
public:
singlerun_abort_exception(std::string msg)
#ifndef NDEBUG
#define ASSERT_EXCEPTION(cond, msg) \
if (!(cond)) { \
std::string rmsg(std::string(__FILE__) + std::string(":") + Stuff::Common::toString(__LINE__) + std::string("\n") \
+ std::string(msg)); \
throw assert_exception(rmsg); \
}
#define UNUSED(identifier) /* identifier */
/* some arguments are only used in debug mode, but unused in release one */
#ifndef NDEBUG
#define UNUSED_UNLESS_DEBUG(param) param
#else
#define UNUSED_UNLESS_DEBUG(param) UNUSED(param)
#define ASSERT_LT(expt, actual) \
BOOST_ASSERT_MSG( \
(expt < actual), \
(boost::format("assertion %1% < %2% failed: %3% >= %4%") % #expt % #actual % expt % actual).str().c_str())
#define ASSERT_EQ(expt, actual) \
BOOST_ASSERT_MSG( \
(expt == actual), \
(boost::format("assertion %1% == %2% failed: %3% != %4%") % #expt % #actual % expt % actual).str().c_str())
/** Copyright (c) 2012, Rene Milk
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the FreeBSD Project.
**/