 |
RDKit
Open-source cheminformatics and machine learning.
|
Go to the documentation of this file.
13 #ifndef __RD_INVARIANT_H__
14 #define __RD_INVARIANT_H__
29 #include <boost/numeric/conversion/cast.hpp>
35 #if !defined INVARIANT_EXCEPTION_METHOD && !defined INVARIANT_ASSERT_METHOD && \
36 !defined INVARIANT_SILENT_METHOD
37 #define INVARIANT_EXCEPTION_METHOD 1
43 #if !INVARIANT_EXCEPTION_METHOD && !INVARIANT_ASSERT_METHOD && \
44 !INVARIANT_SILENT_METHOD
45 #undef INVARIANT_EXCEPTION_METHOD
46 #define INVARIANT_EXCEPTION_METHOD 1
53 Invariant(
const char* prefix,
const char* mess,
const char* expr,
54 const char*
const file,
int line)
55 : std::runtime_error(prefix),
61 Invariant(
const char* prefix,
const std::string& mess,
const char* expr,
62 const char*
const file,
int line)
63 : std::runtime_error(prefix),
71 const char*
what() const noexcept
override {
return mess_d.c_str(); }
72 std::string
getMessage() const noexcept {
return mess_d; }
74 const char*
getFile()
const {
return file_dp; }
84 std::string mess_d, expr_d, prefix_d;
86 const char*
const file_dp;
94 #define ASSERT_INVARIANT(expr, mess) assert(expr)
100 #if INVARIANT_EXCEPTION_METHOD
102 #define CHECK_INVARIANT(expr, mess) \
104 Invar::Invariant inv("Invariant Violation", mess, #expr, __FILE__, \
106 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
110 #define PRECONDITION(expr, mess) \
112 Invar::Invariant inv("Pre-condition Violation", mess, #expr, __FILE__, \
114 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
118 #define POSTCONDITION(expr, mess) \
120 Invar::Invariant inv("Post-condition Violation", mess, #expr, __FILE__, \
122 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
126 #define UNDER_CONSTRUCTION(fn) \
127 Invar::Invariant inv("Incomplete Code", \
128 "This routine is still under development", fn, \
129 __FILE__, __LINE__); \
130 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
133 #define RANGE_CHECK(lo, x, hi) \
134 if ((lo) > (hi) || (x) < (lo) || (x) > (hi)) { \
135 std::stringstream errstr; \
136 errstr << lo << " <= " << x << " <= " << hi; \
137 Invar::Invariant inv("Range Error", #x, errstr.str().c_str(), __FILE__, \
139 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
143 #define URANGE_CHECK(x, hi) \
145 std::stringstream errstr; \
146 errstr << x << " < " << hi; \
147 Invar::Invariant inv("Range Error", #x, errstr.str().c_str(), __FILE__, \
149 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
153 #define TEST_ASSERT(expr) \
155 Invar::Invariant inv("Test Assert", "Expression Failed: ", #expr, \
156 __FILE__, __LINE__); \
157 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
161 #elif INVARIANT_ASSERT_METHOD
163 #define CHECK_INVARIANT(expr, mess) assert(expr);
164 #define PRECONDITION(expr, mess) assert(expr);
165 #define POSTCONDITION(expr, mess) assert(expr);
166 #define UNDER_CONSTRUCTION(fn) assert(0);
167 #define RANGE_CHECK(lo, x, hi) \
168 assert((lo) <= (hi) && (x) >= (lo) && (x) <= (hi));
169 #define URANGE_CHECK(lo, x, hi) assert((hi > 0) && (x < hi));
170 #define TEST_ASSERT(expr) assert(expr);
172 #elif INVARIANT_SILENT_METHOD
174 #define CHECK_INVARIANT(expr, mess)
175 #define PRECONDITION(expr, mess)
176 #define POSTCONDITION(expr, mess)
177 #define UNDER_CONSTRUCTION(fn)
178 #define RANGE_CHECK(lo, x, hi)
179 #define URANGE_CHECK(x, hi)
180 #define TEST_ASSERT(expr)
190 #define rdcast boost::numeric_cast
192 #define rdcast static_cast
197 #define RDUNUSED_PARAM(x) (void)x;
std::string getMessage() const noexcept
RDKIT_RDGENERAL_EXPORT std::ostream & operator<<(std::ostream &s, const Invariant &inv)
const char * getFile() const
Invariant(const char *prefix, const char *mess, const char *expr, const char *const file, int line)
std::string getExpression() const
const char * what() const noexcept override
std::string toString() const
std::string toUserString() const
#define RDKIT_RDGENERAL_EXPORT
Invariant(const char *prefix, const std::string &mess, const char *expr, const char *const file, int line)