root/library/bdm/bdmerror.h @ 565

Revision 565, 1.8 kB (checked in by vbarta, 15 years ago)

using own error macros (basically copied from IT++, but never aborting)

Line 
1/*!
2  \file
3  \brief BDM's exception-throwing macros.
4  \author Vaclav Barta.
5
6  -----------------------------------
7  BDM++ - C++ library for Bayesian Decision Making under Uncertainty
8
9  Using IT++ for numerical operations
10  -----------------------------------
11*/
12
13#ifndef bdmerror_h
14#define bdmerror_h
15
16// modelled after IT++ assert macros, somewhat simplified
17
18#include <sstream>
19#include <string>
20
21namespace bdm {
22
23//! Helper function for the \c bdm_assert and \c bdm_assert_debug macros
24void bdm_assert_f(const std::string &ass, const std::string &msg, const std::string &file, int line);
25
26//! Helper function for the \c bdm_error macro
27void bdm_error_f(const std::string &msg, const std::string &file, int line);
28
29//! Helper function for the \c bdm_warning macro
30void bdm_warning_f(const std::string &msg, const std::string &file, int line);
31
32}
33
34//! Throw std::runtime_exception if \c t is not true
35#define bdm_assert(t, s) \
36        if (!(t)) { \
37                std::ostringstream bdm_out; \
38                bdm_out << s; \
39                bdm::bdm_assert_f(#t, bdm_out.str(), __FILE__, __LINE__); \
40        } else ((void) 0)
41
42#if defined(NDEBUG)
43//! Throw std::runtime_exception if \c t is not true and NDEBUG is not defined
44#define bdm_assert_debug(t, s) ((void) 0)
45#else
46//! Throw std::runtime_exception if \c t is not true and NDEBUG is not defined
47#define bdm_assert_debug(t, s) bdm_assert(t, s)
48#endif // if defined(NDEBUG)
49
50//! Unconditionally throw std::runtime_error
51#define bdm_error(s) \
52        if (true) { \
53                std::ostringstream bdm_out; \
54                bdm_out << s; \
55                bdm::bdm_error_f(bdm_out.str(), __FILE__, __LINE__); \
56        } else ((void) 0)
57
58//! Display a warning message
59#define bdm_warning(s) \
60        if (true) { \
61                std::ostringstream bdm_out; \
62                bdm_out << s; \
63                bdm::bdm_warning_f(bdm_out.str(), __FILE__, __LINE__); \
64        } else ((void) 0)
65
66#endif
Note: See TracBrowser for help on using the browser.