Cambridge SMT System
custom_assert.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, AdriĆ  de Gispert, William Byrne
14 
21 #ifndef CUSTOM_ASSERT
22 #define CUSTOM_ASSERT
23 
24 #include <fstream>
25 #include <iostream>
26 
27 #ifndef OSR
28 #include "backtrace.hpp"
29 #endif
30 
35 #define USER_CHECK_CONTINUE(exp,comment) (bool)( (exp) || (check (#exp,#comment, __FILE__, __PRETTY_FUNCTION__,__LINE__,false), 0) )
36 
37 #ifdef USER_CHECK_DEBUG
38 extern bool user_check_ok;
39 #define USER_CHECK(exp,comment) (bool)( (exp) || (check (#exp,#comment, __FILE__, __PRETTY_FUNCTION__,__LINE__,false), 0) )
40 #else
41 #define USER_CHECK(exp,comment) (bool)( (exp) || (check (#exp,#comment, __FILE__, __PRETTY_FUNCTION__,__LINE__,true), 0) )
42 #endif
43 
51 inline bool check ( const char * expression, const char * message,
52  const char *filename, const char *function, uint line , bool abort = true) {
53  std::cerr << "==========================================================" <<
54  std::endl;
55  std::cerr << "User check failure at " << filename << ",function=" << function <<
56  ",line=" << line << std::endl;
57  std::cerr << "Reason: " << message << std::endl;
58  std::cerr << "Test: " << expression << std::endl;
59 #ifndef OSR
61 #endif
62  if (abort) {
63  std::cerr << "Aborting!" << std::endl;
64  std::cerr << "==========================================================" <<
65  std::endl;
66  exit ( EXIT_FAILURE );
67  }
68  std::cerr << "==========================================================" <<
69  std::endl;
70 #ifdef USER_CHECK_DEBUG
71  return user_check_ok = false; //we can now get rid of this
72 #endif
73  return false;
74 };
75 
76 #endif
int displayBacktrace(void)
Display backtrace of functions.
Definition: backtrace.hpp:36
bool user_check_ok
Adapted from http://charette.no-ip.com:81/programming/2010-01-25_Backtrace/ Simple example of backtra...
bool check(const char *expression, const char *message, const char *filename, const char *function, uint line, bool abort=true)
Function that reports as many details as possible if the assertion USER_CHECK has failed...