12#ifndef BELFEM_ASSERT_HPP
13#define BELFEM_ASSERT_HPP
28#if !defined( NDEBUG ) || defined( DEBUG )
29#define BELFEM_ASSERTIONS_ACTIVE 1
31#define BELFEM_ASSERTIONS_ACTIVE 0
43 std::vector<std::string>
44 wrap_lines(std::size_t aMaxWidth,
const std::string & aLine);
54 print_line(
const std::vector<std::string> & aDragon, std::size_t & aCounter );
59 print_line(
const std::vector<std::string> & aDragon,
60 const string & aLine, std::size_t & aCounter );
70 get_lines(
const string & aWhat, std::vector< std::string > & aLines );
76 const std::string & aLocation,
77 const std::string & aTask,
78 const std::string & aCheck,
79 const std::vector< std::string > & aMessage ) ;
152 const std::string & aLocation,
153 const std::string & aCheck,
154 const std::vector< std::string > & aMessage );
158 template<
typename Exception >
161 const std::string & aLocation,
162 const std::string & aTask,
163 const std::string & aCheck,
164 const Exception & aException = Exception()
168 std::istringstream tExceptionMessage( aException.what() );
169 std::string tExceptionLine ;
172 std::vector< std::string > tMessage ;
173 while ( std::getline( tExceptionMessage, tExceptionLine) )
175 tMessage.push_back( tExceptionLine );
205 template <
typename ... Args >
208 const std::string & aFile,
209 const std::size_t & aLine,
210 const std::string & aFunction,
211 const std::string & aCheck,
212 const Args ... aArgs )
214 std::stringstream tLocation;
218 tLocation << aFile.substr( aFile.find_last_of(
"/\\") + 1 ) <<
" (line " << aLine <<
")";
220 std::stringstream tTask;
223 std::stringstream tReason;
224 tReason <<
"Assertion " << aCheck <<
" failed.";
233 std::runtime_error( tMessage.c_str() ) );
243#if BELFEM_ASSERTIONS_ACTIVE
244#define BELFEM_ASSERT( aCheck, ... ) \
247 if ( ! ( aCheck ) ) \
249 belfem::assert::belfem_assert( \
252 __PRETTY_FUNCTION__, \
259#define BELFEM_ASSERT( aCheck, ... )
264#define BELFEM_ERROR( aCheck, ... ) \
267 if ( ! ( aCheck ) ) \
269 belfem::assert::belfem_assert( \
272 __PRETTY_FUNCTION__, \
void error(const std::string &aLocation, const std::string &aTask, const std::string &aCheck, const Exception &aException=Exception())
Definition assert.hpp:160
void get_lines(const string &aWhat, std::vector< std::string > &aLines)
Definition assert.cpp:222
bool syslog_on_error()
Whether a failed check also writes its message to the system log ( syslog, identity "belfem",...
Definition assert.cpp:338
void print_line(const std::vector< std::string > &aDragon, std::size_t &aCounter)
Definition assert.cpp:174
void error_abort()
Definition assert.cpp:295
std::string extract_function_name(const std::string &aPrettyFunction)
Definition assert.cpp:36
void set_throw_on_error(const bool aValue)
Definition assert.cpp:325
void belfem_assert(const std::string &aFile, const std::size_t &aLine, const std::string &aFunction, const std::string &aCheck, const Args ... aArgs)
Definition assert.hpp:207
void print_errorbox(const std::string &aLocation, const std::string &aTask, const std::string &aCheck, const std::vector< std::string > &aMessage)
Definition assert.cpp:237
std::vector< std::string > wrap_lines(std::size_t aMaxWidth, const std::string &aLine)
Definition assert.cpp:78
void log_to_syslog(const std::string &aLocation, const std::string &aCheck, const std::vector< std::string > &aMessage)
Definition assert.cpp:354
void set_syslog_on_error(const bool aValue)
Definition assert.cpp:346
void hatch_dragon(std::vector< std::string > &aDragon)
Definition assert.cpp:148
bool throw_on_error()
How a failed check reacts: true throws the exception, false calls error_abort().
Definition assert.cpp:317
USER GUIDES:
Definition cl_Capacitor.cpp:16
std::string sprint(const char *aFormat, const Args ... aArgs)
A format script similar to write( , ) in fortran.
Definition fn_sprint.hpp:44