root/myassert.hh
| Revision 868b365c127bbf4f0b52f22da03e32a94a4f6653, 1.9 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 3 years ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | /* This file is part of Alue, the multiprotocol Internet discussion daemon |
| 2 | |
| 3 | Copyright © 2009 Antti-Juhani Kaijanaho |
| 4 | |
| 5 | Alue is free software: you can redistribute it and/or modify it |
| 6 | under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | Alue is distributed in the hope that it will be useful, but |
| 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with Alue. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | */ |
| 19 | |
| 20 | #ifndef GUARD_MYASSERT_HH |
| 21 | #define GUARD_MYASSERT_HH |
| 22 | |
| 23 | #include <exception> |
| 24 | |
| 25 | #define myassert(x) myassert_1(x,__LINE__) |
| 26 | #define myassert_1(x,li) myassert_2(x,li) |
| 27 | #define myassert_2(x,li) do { \ |
| 28 | if(!(x)) \ |
| 29 | throw assertion_failure(__FILE__ ":" #li \ |
| 30 | ": myassertion failure: " \ |
| 31 | #x); \ |
| 32 | } while (0) |
| 33 | |
| 34 | #define not_reached not_reached_1(__LINE__) |
| 35 | #define not_reached_1(li) not_reached_2(li) |
| 36 | #define not_reached_2(li) do { \ |
| 37 | throw assertion_failure(__FILE__ ":" #li \ |
| 38 | ": internal error"); \ |
| 39 | } while (0) |
| 40 | |
| 41 | class assertion_failure : public std::exception |
| 42 | { |
| 43 | const char *s; |
| 44 | public: |
| 45 | assertion_failure(const char *s) : s(s) {} |
| 46 | ~assertion_failure() throw () {} |
| 47 | const char *what() const throw() { return s; } |
| 48 | }; |
| 49 | |
| 50 | #endif /* GUARD_MYASSERT_HH */ |
Note: See TracBrowser
for help on using the browser.
