gravatar
ladanyi@tmit.bme.hu
ladanyi@tmit.bme.hu
Improved LEMON_FUNCTION_NAME macro. It should work fine with GCC and the MS C++ compilers. Otherwise it reverts to using the __func__ variable which is C99, but I couldn't find a better alternative.
0 1 0
default
1 file changed with 7 insertions and 1 deletions:
↑ Collapse diff ↑
Ignore white space 96 line context
... ...
@@ -58,97 +58,103 @@
58 58
      return str;
59 59
    }    
60 60
  }
61 61
}
62 62

	
63 63
#endif // LEMON_ASSERT_H
64 64

	
65 65
#undef LEMON_ASSERT
66 66
#undef LEMON_FIXME
67 67
#undef LEMON_DEBUG
68 68

	
69 69
#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) +		\
70 70
  (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +		\
71 71
  (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1
72 72
#error "LEMON assertion system is not set properly"
73 73
#endif
74 74

	
75 75
#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) +		\
76 76
     (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +		\
77 77
     (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 ||	\
78 78
     defined(LEMON_ENABLE_ASSERTS)) &&			\
79 79
  (defined(LEMON_DISABLE_ASSERTS) ||			\
80 80
   defined(NDEBUG))
81 81
#error "LEMON assertion system is not set properly"
82 82
#endif
83 83

	
84 84

	
85 85
#if defined LEMON_ASSERT_LOG
86 86
#  undef LEMON_ASSERT_HANDLER
87 87
#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_log
88 88
#elif defined LEMON_ASSERT_ABORT
89 89
#  undef LEMON_ASSERT_HANDLER
90 90
#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
91 91
#elif defined LEMON_ASSERT_CUSTOM
92 92
#  undef LEMON_ASSERT_HANDLER
93 93
#  ifndef LEMON_CUSTOM_ASSERT_HANDLER
94 94
#    error "LEMON_CUSTOM_ASSERT_HANDLER is not set"
95 95
#  endif
96 96
#  define LEMON_ASSERT_HANDLER LEMON_CUSTOM_ASSERT_HANDLER
97 97
#elif defined LEMON_DISABLE_ASSERTS
98 98
#  undef LEMON_ASSERT_HANDLER
99 99
#elif defined NDEBUG
100 100
#  undef LEMON_ASSERT_HANDLER
101 101
#else
102 102
#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
103 103
#endif
104 104

	
105 105
#ifndef LEMON_FUNCTION_NAME
106
#  define LEMON_FUNCTION_NAME (__PRETTY_FUNCTION__)
106
#  if defined __GNUC__
107
#    define LEMON_FUNCTION_NAME (__PRETTY_FUNCTION__)
108
#  elif defined _MSC_VER
109
#    define LEMON_FUNCTION_NAME (__FUNCSIG__)
110
#  else
111
#    define LEMON_FUNCTION_NAME (__func__)
112
#  endif
107 113
#endif
108 114

	
109 115
#ifdef DOXYGEN
110 116

	
111 117
/// \ingroup exceptions
112 118
///
113 119
/// \brief Macro for assertion with customizable message
114 120
///
115 121
/// Macro for assertion with customizable message.  \param exp An
116 122
/// expression that must be convertible to \c bool.  If it is \c
117 123
/// false, then an assertion is raised. The concrete behaviour depends
118 124
/// on the settings of the assertion system.  \param msg A <tt>const
119 125
/// char*</tt> parameter, which can be used to provide information
120 126
/// about the circumstances of the failed assertion.
121 127
///
122 128
/// The assertions are enabled in the default behaviour.
123 129
/// You can disable them with the following code:
124 130
/// \code
125 131
/// #define LEMON_DISABLE_ASSERTS
126 132
/// \endcode
127 133
/// or with compilation parameters:
128 134
/// \code
129 135
/// g++ -DLEMON_DISABLE_ASSERTS
130 136
/// make CXXFLAGS='-DLEMON_DISABLE_ASSERTS'
131 137
/// \endcode
132 138
/// The checking is also disabled when the standard macro \c NDEBUG is defined.
133 139
/// 
134 140
/// The LEMON assertion system has a wide range of customization
135 141
/// properties. As a default behaviour the failed assertion prints a
136 142
/// short log message to the standard error and aborts the execution.
137 143
///
138 144
/// The following modes can be used in the assertion system: 
139 145
///
140 146
/// - \c LEMON_ASSERT_LOG The failed assertion prints a short log
141 147
///   message to the standard error and continues the execution.
142 148
/// - \c LEMON_ASSERT_ABORT This mode is similar to the \c
143 149
///   LEMON_ASSERT_LOG, but it aborts the program. It is the default
144 150
///   behaviour.
145 151
/// - \c LEMON_ASSERT_CUSTOM The user can define own assertion handler
146 152
///   function.
147 153
///   \code
148 154
///     void custom_assert_handler(const char* file, int line, const char* function,
149 155
///                                const char* message, const char* assertion);
150 156
///   \endcode
151 157
///   The name of the function should be defined as the \c
152 158
///   LEMON_CUSTOM_ASSERT_HANDLER macro name. 
153 159
///   \code
154 160
///     #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler
0 comments (0 inline)