World Builder  0.1.0-pre
A geodyanmic initial conditions generator
assert.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 by the authors of the World Builder code.
3 
4  This file is part of the World Builder.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19 
20 #include <iostream>
21 #include <string>
22 #include <sstream>
23 #include <stdexcept>
24 
25 namespace WorldBuilder
26 {
27 #ifndef NDEBUG
28 # define WBAssert(condition, message) \
29  do { \
30  if (! (condition)) { \
31  std::stringstream smessage; \
32  smessage << "Assert `" #condition "` failed in " << __FILE__ \
33  << " at line " << __LINE__ << ": " << message << std::endl; \
34  throw std::runtime_error(smessage.str()); \
35  } \
36  } while (false)
37 #else
38 # define WBAssert(condition, message) do { } while (false)
39 #endif
40 
41 # define WBAssertThrow(condition, message) \
42  do { \
43  if (! (condition)) { \
44  std::stringstream smessage; \
45  smessage << "AssertThrow `" #condition "` failed in " << __FILE__ \
46  << " at line " << __LINE__ << ": " << message << std::endl; \
47  throw std::runtime_error(smessage.str()); \
48  } \
49  } while (false)
50 }