queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
asserts.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2017 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library 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 GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 //
26 // nick (nicholas.malaya) providing a direct port of the antioch assertions
27 // to queso (see: https://github.com/libantioch/antioch/blob/master/src/utilities/include/antioch/antioch_asserts.h)
28 //
29 // adding MPI-friendly exits
30 //
31 
32 #ifndef QUESO_ASSERTS_H
33 #define QUESO_ASSERTS_H
34 
35 #include "exceptions.h"
36 #include "queso/config_queso.h" // for QUESO_HAVE_CXX11
37 
38 // C++
39 #include <iostream>
40 #include <iomanip>
41 
42 #define queso_here() do { std::cerr << __FILE__ << ", line " << __LINE__ << ", compiled " << __DATE__ << " at " << __TIME__ << std::endl; } while (0)
43 
44 // queso_error and kin throw exceptions to indicate various possible
45 // errors
46 
47 #define queso_error_msg(msg) do { queso_here(); std::cerr << msg << std::endl; QUESO_THROW(QUESO::LogicError()); } while(0)
48 
49 #define queso_not_implemented_msg(msg) do { queso_here(); std::cerr << msg << std::endl; QUESO_THROW(QUESO::NotImplemented()); } while(0)
50 
51 #define queso_file_error_msg(filename, msg) do { queso_here(); std::cerr << msg << std::endl; QUESO_THROW(QUESO::FileError(filename)); } while(0)
52 
53 #define queso_error() \
54  queso_error_msg("")
55 
56 #define queso_not_implemented() \
57  queso_not_implemented_msg("")
58 
59 #define queso_file_error(filename) \
60  queso_file_error_msg(filename, "")
61 
62 // The queso_assert() macro acts like C's assert(), but throws a
63 // queso_error() (enabling exception handling, stack trace, etc)
64 // instead of just exiting.
65 
66 // The queso_require() macro does the same, but remains active even
67 // when NDEBUG is not defined
68 
69 #define queso_require_msg(asserted, msg) do { if (!(asserted)) { std::cerr << "Assertion `" #asserted "' failed.\n" << msg << std::endl; queso_error(); } } while(0)
70 
71 // We can get more descriptive error messages if we're testing a
72 // simple standard binary operation.
73 #define queso_require_equal_to_msg(expr1,expr2,msg) do { if (!(expr1 == expr2)) { std::cerr << "Assertion `" #expr1 " == " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; queso_error(); } } while(0)
74 #define queso_require_not_equal_to_msg(expr1,expr2,msg) do { if (!(expr1 != expr2)) { std::cerr << "Assertion `" #expr1 " != " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; queso_error(); } } while(0)
75 #define queso_require_less_msg(expr1,expr2,msg) do { if (!(expr1 < expr2)) { std::cerr << "Assertion `" #expr1 " < " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; queso_error(); } } while(0)
76 #define queso_require_greater_msg(expr1,expr2,msg) do { if (!(expr1 > expr2)) { std::cerr << "Assertion `" #expr1 " > " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; queso_error(); } } while(0)
77 #define queso_require_less_equal_msg(expr1,expr2,msg) do { if (!(expr1 <= expr2)) { std::cerr << "Assertion `" #expr1 " <= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; queso_error(); } } while(0)
78 #define queso_require_greater_equal_msg(expr1,expr2,msg) do { if (!(expr1 >= expr2)) { std::cerr << "Assertion `" #expr1 " >= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; queso_error(); } } while(0)
79 
80 // When not debugging, we don't test any asserts
81 #ifdef NDEBUG
82 
83 #define queso_assert_msg(asserted,msg) ((void) 0)
84 #define queso_assert_equal_to_msg(expr1,expr2,msg) ((void) 0)
85 #define queso_assert_not_equal_to_msg(expr1,expr2,msg) ((void) 0)
86 #define queso_assert_less_msg(expr1,expr2,msg) ((void) 0)
87 #define queso_assert_greater_msg(expr1,expr2,msg) ((void) 0)
88 #define queso_assert_less_equal_msg(expr1,expr2,msg) ((void) 0)
89 #define queso_assert_greater_equal_msg(expr1,expr2,msg) ((void) 0)
90 
91 #else
92 
93 #define queso_assert_msg(asserted,msg) \
94  queso_require_msg(asserted,msg)
95 #define queso_assert_equal_to_msg(expr1,expr2,msg) \
96  queso_require_equal_to_msg(expr1,expr2,msg)
97 #define queso_assert_not_equal_to_msg(expr1,expr2,msg) \
98  queso_require_not_equal_to_msg(expr1,expr2,msg)
99 #define queso_assert_less_msg(expr1,expr2,msg) \
100  queso_require_less_msg(expr1,expr2,msg)
101 #define queso_assert_greater_msg(expr1,expr2,msg) \
102  queso_require_greater_msg(expr1,expr2,msg)
103 #define queso_assert_less_equal_msg(expr1,expr2,msg) \
104  queso_require_less_equal_msg(expr1,expr2,msg)
105 #define queso_assert_greater_equal_msg(expr1,expr2,msg) \
106  queso_require_greater_equal_msg(expr1,expr2,msg)
107 
108 #endif // NDEBUG
109 
110 #define queso_require(asserted) \
111  queso_require_msg(asserted, "")
112 
113 #define queso_require_equal_to(expr1,expr2) \
114  queso_require_equal_to_msg(expr1,expr2,"")
115 
116 #define queso_require_not_equal_to(expr1,expr2) \
117  queso_require_not_equal_to_msg(expr1,expr2,"") \
118 
119 #define queso_require_less(expr1,expr2) \
120  queso_require_less_msg(expr1,expr2,"")
121 
122 #define queso_require_greater(expr1,expr2) \
123  queso_require_greater_msg(expr1,expr2,"")
124 
125 #define queso_require_less_equal(expr1,expr2) \
126  queso_require_less_equal_msg(expr1,expr2,"")
127 
128 #define queso_require_greater_equal(expr1,expr2) \
129  queso_require_greater_equal_msg(expr1,expr2,"")
130 
131 
132 #define queso_assert(asserted) \
133  queso_assert_msg(asserted, "")
134 
135 #define queso_assert_equal_to(expr1,expr2) \
136  queso_assert_equal_to_msg(expr1,expr2,"")
137 
138 #define queso_assert_not_equal_to(expr1,expr2) \
139  queso_assert_not_equal_to_msg(expr1,expr2,"") \
140 
141 #define queso_assert_less(expr1,expr2) \
142  queso_assert_less_msg(expr1,expr2,"")
143 
144 #define queso_assert_greater(expr1,expr2) \
145  queso_assert_greater_msg(expr1,expr2,"")
146 
147 #define queso_assert_less_equal(expr1,expr2) \
148  queso_assert_less_equal_msg(expr1,expr2,"")
149 
150 #define queso_assert_greater_equal(expr1,expr2) \
151  queso_assert_greater_equal_msg(expr1,expr2,"")
152 
153 
154 
155 #endif // QUESO_ASSERTS_H

Generated on Tue Jun 5 2018 19:48:54 for queso-0.57.1 by  doxygen 1.8.5