ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame^] | 1 | /* -*- c++ -*- */ |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 2 | /* |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame^] | 3 | * @file |
| 4 | * @author Piotr Krysik <ptrkrysik@gmail.com> |
| 5 | * @section LICENSE |
| 6 | * |
| 7 | * Gr-gsm 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, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * Gr-gsm 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 gr-gsm; see the file COPYING. If not, write to |
| 19 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | */ |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 22 | |
| 23 | |
| 24 | #ifndef ASSERT_H |
| 25 | #define ASSERT_H |
| 26 | |
| 27 | #include "stdio.h" |
| 28 | #include <iostream> |
| 29 | |
| 30 | //#define NDEBUG |
| 31 | |
| 32 | /**@name Macros for standard messages. */ |
| 33 | //@{ |
| 34 | #define COUT(text) { std::cout << text << std::endl; } |
| 35 | #define CERR(text) { std::cerr << __FILE__ << ":" << __LINE__ << ": " << text; } |
| 36 | #ifdef NDEBUG |
| 37 | #define DCOUT(text) {} |
| 38 | #define OBJDCOUT(text) {} |
| 39 | #else |
ptrkrysik | a25bb70 | 2014-10-30 09:01:13 +0100 | [diff] [blame] | 40 | #define DCOUT(text) { CERR(text); } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 41 | #define OBJDCOUT(text) { DCOUT(this << " " << text); } |
| 42 | #endif |
| 43 | //@} |
| 44 | |
| 45 | |
| 46 | /** This is thrown by assert() so that gdb can catch it. */ |
| 47 | |
| 48 | class assertion |
| 49 | { |
| 50 | |
| 51 | public: |
| 52 | |
| 53 | assertion() { |
| 54 | fprintf( stderr,"Try setting a breakpoint @ %s:%u.\n",__FILE__,__LINE__ ); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | }; |
| 59 | |
| 60 | #ifdef NDEBUG |
| 61 | #define assert(EXPR) {}; |
| 62 | #else |
| 63 | /** This replaces the regular assert() with a C++ exception. */ |
| 64 | #include "stdio.h" |
| 65 | #define assert(E) { if (!(E)) { fprintf(stderr,"%s:%u failed assertion '%s'\n",__FILE__,__LINE__,#E); throw Assertion(); } } |
| 66 | #endif |
| 67 | |
| 68 | #endif |