RCFProto
 All Classes Functions Typedefs
Assert.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 2.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_UTIL_ASSERT_HPP
20 #define INCLUDE_UTIL_ASSERT_HPP
21 
22 #include <cassert>
23 #include <cstdio>
24 #include <exception>
25 
26 #include <boost/current_function.hpp>
27 
28 #include "VariableArgMacro.hpp"
29 
30 #if defined(_MSC_VER) && !defined(NDEBUG)
31 #include <crtdbg.h>
32 #endif
33 
34 #include <RCF/Export.hpp>
35 
36 namespace RCF {
37 
38  class RCF_EXPORT AssertFunctor : public VariableArgMacroFunctor
39  {
40  public:
41 
42  AssertFunctor();
43  AssertFunctor(const char * expr);
44  ~AssertFunctor();
45 
46  const char * mExpr;
47  };
48 
49  class VarArgAbort
50  {
51  public:
52  VarArgAbort();
53 
54  template<typename T>
55  VarArgAbort &operator()(const T &)
56  {
57  return *this;
58  }
59  };
60 
61 
62 #if 0
63 #define UTIL_ASSERT_DEBUG(cond, e, logName, logLevel) \
64  if (cond) ; \
65  else RCF::VarArgAssert(__FILE__, __LINE__, #cond)
66 #endif
67 
68 #ifdef _MSC_VER
69 #pragma warning( push )
70 #pragma warning( disable : 4355 ) // warning C4355: 'this' : used in base member initializer list
71 #endif
72 
73 #if defined(__GNUC__) && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4))
74 #define UTIL_ASSERT_DEBUG_GCC_33_HACK (const RCF::VariableArgMacro<RCF::ThrowFunctor> &)
75 #else
76 #define UTIL_ASSERT_DEBUG_GCC_33_HACK
77 #endif
78 
79  DECLARE_VARIABLE_ARG_MACRO( UTIL_ASSERT_DEBUG, RCF::AssertFunctor );
80  #define UTIL_ASSERT_DEBUG(expr, e, logName, logLevel) \
81  if (expr); \
82  else\
83  UTIL_ASSERT_DEBUG_GCC_33_HACK \
84  RCF::VariableArgMacro<RCF::AssertFunctor>(#expr) \
85  .init( \
86  "", \
87  "", \
88  __FILE__, \
89  __LINE__, \
90  BOOST_CURRENT_FUNCTION) \
91  .cast( (RCF::VariableArgMacro<RCF::AssertFunctor> *) NULL) \
92  .UTIL_ASSERT_DEBUG_A
93 
94 
95 
96  #define UTIL_ASSERT_DEBUG_A(x) UTIL_ASSERT_DEBUG_OP(x, B)
97  #define UTIL_ASSERT_DEBUG_B(x) UTIL_ASSERT_DEBUG_OP(x, A)
98  #define UTIL_ASSERT_DEBUG_OP(x, next) UTIL_ASSERT_DEBUG_A.notify_((x), #x).UTIL_ASSERT_DEBUG_ ## next
99 
100 #ifdef _MSC_VER
101 #pragma warning( pop )
102 #endif
103 
104 
105 
106 
107  #ifdef RCF_ALWAYS_ABORT_ON_ASSERT
108 
109  #define UTIL_ASSERT_RELEASE(cond, e, logName, logLevel) \
110  if (cond) ; \
111  else RCF::VarArgAbort()
112 
113  #else
114 
115  #define UTIL_ASSERT_RELEASE(cond, e, logName, logLevel) \
116  if (cond) ; \
117  else UTIL_THROW(e, logName, logLevel)(cond)
118 
119  #endif
120 
121  #define UTIL_ASSERT_NULL(cond, E) \
122  DUMMY_VARIABLE_ARG_MACRO()
123 
124  #ifdef NDEBUG
125  #define UTIL_ASSERT UTIL_ASSERT_RELEASE
126  #else
127  #define UTIL_ASSERT UTIL_ASSERT_DEBUG
128  #endif
129 
130 } // namespace RCF
131 
132 #endif