 |
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),
73 const char*
getFile()
const {
return file_dp; }
79 std::string toString()
const;
80 std::string toUserString()
const;
83 std::string mess_d, expr_d, prefix_d;
85 const char*
const file_dp;
90 const Invariant& inv);
93 #define ASSERT_INVARIANT(expr, mess) assert(expr)
99 #if INVARIANT_EXCEPTION_METHOD
101 #define CHECK_INVARIANT(expr, mess) \
103 Invar::Invariant inv("Invariant Violation", mess, #expr, __FILE__, \
105 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
109 #define PRECONDITION(expr, mess) \
111 Invar::Invariant inv("Pre-condition Violation", mess, #expr, __FILE__, \
113 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
117 #define POSTCONDITION(expr, mess) \
119 Invar::Invariant inv("Post-condition Violation", mess, #expr, __FILE__, \
121 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
125 #define UNDER_CONSTRUCTION(fn) \
126 Invar::Invariant inv("Incomplete Code", \
127 "This routine is still under development", fn, \
128 __FILE__, __LINE__); \
129 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
132 #define RANGE_CHECK(lo, x, hi) \
133 if ((lo) > (hi) || (x) < (lo) || (x) > (hi)) { \
134 std::stringstream errstr; \
135 errstr << lo << " <= " << x << " <= " << hi; \
136 Invar::Invariant inv("Range Error", #x, errstr.str().c_str(), __FILE__, \
138 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
142 #define URANGE_CHECK(x, hi) \
144 std::stringstream errstr; \
145 errstr << x << " < " << hi; \
146 Invar::Invariant inv("Range Error", #x, errstr.str().c_str(), __FILE__, \
148 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
152 #define TEST_ASSERT(expr) \
154 Invar::Invariant inv("Test Assert", "Expression Failed: ", #expr, \
155 __FILE__, __LINE__); \
156 BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
160 #elif INVARIANT_ASSERT_METHOD
162 #define CHECK_INVARIANT(expr, mess) assert(expr);
163 #define PRECONDITION(expr, mess) assert(expr);
164 #define POSTCONDITION(expr, mess) assert(expr);
165 #define UNDER_CONSTRUCTION(fn) assert(0);
166 #define RANGE_CHECK(lo, x, hi) \
167 assert((lo) <= (hi) && (x) >= (lo) && (x) <= (hi));
168 #define URANGE_CHECK(lo, x, hi) assert((hi > 0) && (x < hi));
169 #define TEST_ASSERT(expr) assert(expr);
171 #elif INVARIANT_SILENT_METHOD
173 #define CHECK_INVARIANT(expr, mess)
174 #define PRECONDITION(expr, mess)
175 #define POSTCONDITION(expr, mess)
176 #define UNDER_CONSTRUCTION(fn)
177 #define RANGE_CHECK(lo, x, hi)
178 #define URANGE_CHECK(x, hi)
179 #define TEST_ASSERT(expr)
189 #define rdcast boost::numeric_cast
191 #define rdcast static_cast
196 #define RDUNUSED_PARAM(x) (void)x;
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
std::string getMessage() const
#define RDKIT_RDGENERAL_EXPORT
Invariant(const char *prefix, const std::string &mess, const char *expr, const char *const file, int line)