DiaDes  0.1
DIAgnosis of Discrete-Event System
Assertion.hh
Go to the documentation of this file.
1 #ifndef __DIADES__UTILS__ASSERTION__HH
2 #define __DIADES__UTILS__ASSERTION__HH
3 
4 
5 
6 #include <string>
7 #include <stdexcept>
8 #include <boost/format.hpp>
11 
12 using std::string;
13 using std::runtime_error;
14 using std::domain_error;
15 
28 template<class X, class A> inline void Require(A assertion,const string & s) {
29  if (!assertion) throw X(s + ": requirement failed");
30 }
31 
38 template<class X, class A> inline void Require(A assertion,const Diades::Utils::Msg & fmt) {
39  if (!assertion) throw X(fmt.str() + ": requirement failed");
40 }
41 
48 template<class X, class A> inline void Ensure(A assertion,const string & s) {
49  if (!assertion) throw X(s + ": ensurement failed");
50 }
51 
52 
53 
60 template<class X, class A> inline void Ensure(A assertion,const Diades::Utils::Msg & fmt) {
61  if (!assertion) throw X(fmt.str() + ": requirement failed");
62 }
63 
64 
71 template<class X, class A> inline void Assertion(A assertion,const string & s) {
72  if (!assertion) throw X(s + ": assertion failed");
73 }
74 
81 template<class X, class A> inline void Assertion(A assertion,const Diades::Utils::Msg & fmt) {
82  if (!assertion) throw X(fmt.str() + ": requirement failed");
83 }
84 
85 
86 #ifdef __REQUIRE
87 #define require(Exception,expr,message) \
88  Require<Exception>(expr,message)
89 #else
90 #define require(Exception,expr,message) \
91  ;
92 #endif
93 
94 #ifdef __ENSURE
95 #define ensure(Exception,expr,message) \
96  Ensure<Exception>(expr,message)
97 #else
98 #define ensure(Exception,expr,message) \
99  ;
100 #endif
101 
102 #ifdef __ASSERT
103 #define assertion(Exception, expr, message) \
104  Assertion<Exception>(expr,message)
105 #else
106 #define assertion(Exception, expr, message) \
107  ;
108 #endif
109 
110 
111 #ifdef __DEBUG
112 #define debug(x) \
113  do \
114  { \
115  x; \
116  } while(0)
117 #else
118 #define debug(x) \
119  ;
120 #endif
121 
122 #define always_require(Exception, expr, message) Require<Exception>(expr,message)
123 #define always_ensure(Exception, expr, message) Ensure<Exception>(expr,message)
124 #define always_assertion(Exception, expr, message) Assertion<Exception>(expr,message)
125 
126 
127 
128 
129 
130 #endif
131 
132 
void Ensure(A assertion, const string &s)
Definition: Assertion.hh:48
void Require(A assertion, const string &s)
Definition: Assertion.hh:28
void Assertion(A assertion, const string &s)
Definition: Assertion.hh:71
boost::format Msg
Definition: Verbose.hh:42
#define assertion(Exception, expr, message)
Definition: Assertion.hh:106