blob: a80ae73588d0960c34cadf0e3654a46ae3e6a240 [file] [log] [blame]
piotr437f5462014-02-04 17:57:25 +01001/*
2* Copyright 2007 Free Software Foundation, Inc.
3*
4* This software is distributed under the terms of the GNU Public License.
5* See the COPYING file in the main directory for details.
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20*/
21
22
23#ifndef ASSERT_H
24#define ASSERT_H
25
26#include "stdio.h"
27#include <iostream>
28
29//#define NDEBUG
30
31/**@name Macros for standard messages. */
32//@{
33#define COUT(text) { std::cout << text << std::endl; }
34#define CERR(text) { std::cerr << __FILE__ << ":" << __LINE__ << ": " << text; }
35#ifdef NDEBUG
36#define DCOUT(text) {}
37#define OBJDCOUT(text) {}
38#else
39#define DCOUT(text) { COUT(__FILE__ << ":" << __LINE__ << " " << text); }
40#define OBJDCOUT(text) { DCOUT(this << " " << text); }
41#endif
42//@}
43
44
45/** This is thrown by assert() so that gdb can catch it. */
46
47class assertion
48{
49
50 public:
51
52 assertion() {
53 fprintf( stderr,"Try setting a breakpoint @ %s:%u.\n",__FILE__,__LINE__ );
54 return;
55 }
56
57};
58
59#ifdef NDEBUG
60#define assert(EXPR) {};
61#else
62/** This replaces the regular assert() with a C++ exception. */
63#include "stdio.h"
64#define assert(E) { if (!(E)) { fprintf(stderr,"%s:%u failed assertion '%s'\n",__FILE__,__LINE__,#E); throw Assertion(); } }
65#endif
66
67#endif