]> www.ginac.de Git - ginac.git/blob - ginac/polynomial/debug.h
Update copyright notice.
[ginac.git] / ginac / polynomial / debug.h
1 /** @file debug.h
2  *
3  *  Utility macros and functions for debugging. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef GINAC_MOD_GCD_DEBUG_H
24 #define GINAC_MOD_GCD_DEBUG_H
25
26 #include "compiler.h"
27
28 #include <iostream>
29 #include <sstream>
30 #include <stdexcept>
31 #include <string>
32
33 #define DEBUG_PREFIX __func__ << ':' << __LINE__ << ": "
34 #define EXCEPTION_PREFIX std::string(__func__) + std::string(": ") +
35
36 #define Dout2(stream, msg)                                    \
37 do {                                                          \
38         stream << DEBUG_PREFIX << msg << std::endl << std::flush; \
39 } while (0)
40 #define Dout(msg) Dout2(std::cout, msg)
41
42 #define bug3_on(condition, the_exception, msg)  \
43 do {                                            \
44         if (unlikely(condition)) {                  \
45                 std::ostringstream err_stream;          \
46                 Dout2(err_stream, "BUG: " << msg);      \
47                 throw the_exception(err_stream.str());  \
48         }                                           \
49 } while (0)
50
51 #define bug_on(condition, msg) bug3_on(condition, std::logic_error, msg)
52
53 #endif // ndef GINAC_MOD_GCD_DEBUG_H