DGtal  0.9.3beta
Assert.h
1 
17 #pragma once
18 
30 #if defined(Assert_RECURSES)
31 #error Recursive header files inclusion detected in Assert.h
32 #else // defined(Assert_RECURSES)
33 
34 #define Assert_RECURSES
35 
36 #if !defined Assert_h
37 
38 #define Assert_h
39 
41 // Inclusions
43 #include "DGtal/base/Trace.h"
44 #include <boost/current_function.hpp>
45 #include <string>
46 
47 namespace DGtal
48 {
49 
58  extern Trace trace;
59 
60 #if defined(NDEBUG)
61  #define ASSERT(expr) ((void)0)
62 #else
63  inline
64  void
65  assert_failed(const std::string& expr, const std::string& function, const std::string& file, long int line)
66  {
67  trace.error()
68  << " Assertion Error - assertion (" << expr << ") failed in " << function << ": "
69  << file << '(' << line << ")" << std::endl;
70  std::abort();
71  }
72  #define ASSERT(expr) ((expr) ? ((void)0) : ::DGtal::assert_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
73 #endif
74 
75 
76 #if defined(NDEBUG)
77  #define ASSERT_MSG(expr, msg) ((void)0)
78 #else
79  inline
80  void
81  assert_failed_message(const std::string& expr, const std::string& message, const std::string& function, const std::string& file, long int line)
82  {
83  trace.error()
84  << " Assertion Error - assertion (" << expr << ") failed in " << function << ": "
85  << file << '(' << line << "): " << std::endl << message << std::endl;
86  std::abort();
87  }
88  #define ASSERT_MSG(expr,msg) ((expr) ? ((void)0) : ::DGtal::assert_failed_message(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
89 #endif
90 
91  inline
92  void
93  fatal_error_failed(const std::string& expr, const std::string& function, const std::string& file, long int line)
94  {
95  trace.error()
96  << " Fatal Error - assertion (" << expr << ") failed in " << function << ": "
97  << file << '(' << line << ")" << std::endl;
98  std::abort();
99  }
100 #define FATAL_ERROR(expr) ((expr) ? ((void)0) : ::DGtal::fatal_error_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
101 
102  inline
103  void
104  fatal_error_failed_message(const std::string& expr, const std::string& message, const std::string& function, const std::string& file, long int line)
105  {
106  trace.error()
107  << " Fatal Error - assertion (" << expr << ") failed in " << function << ": "
108  << file << '(' << line << "): " << std::endl << message << std::endl;
109  std::abort();
110  }
111 #define FATAL_ERROR_MSG(expr,msg) ((expr) ? ((void)0) : ::DGtal::fatal_error_failed_message(#expr,msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
112 
113 } // namespace DGtal
114 
115 #endif // !defined Assert_h
116 
117 #undef Assert_RECURSES
118 #endif // else defined(Assert_RECURSES)
Trace trace
Definition: Common.h:137
void fatal_error_failed(const std::string &expr, const std::string &function, const std::string &file, long int line)
Definition: Assert.h:93
void fatal_error_failed_message(const std::string &expr, const std::string &message, const std::string &function, const std::string &file, long int line)
Definition: Assert.h:104
DGtal is the top-level namespace which contains all DGtal functions and types.
void assert_failed_message(const std::string &expr, const std::string &message, const std::string &function, const std::string &file, long int line)
Definition: Assert.h:81
void assert_failed(const std::string &expr, const std::string &function, const std::string &file, long int line)
Definition: Assert.h:65