OpenGM  2.3.x
Discrete Graphical Model Library
opengm.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_HXX
3 #define OPENGM_HXX
4 
5 #include <stdexcept>
6 #include <sstream>
7 
8 #include "opengm/config.hxx"
10 
11 
12 
13 
14 // as runtime assertion but cefined even if NDEBUG
15 
16 #define OPENGM_CHECK_OP(a,op,b,message) \
17  if(! static_cast<bool>( a op b ) ) { \
18  std::stringstream s; \
19  s << "OpenGM Error: "<< message <<"\n";\
20  s << "OpenGM check : " << #a <<#op <<#b<< " failed:\n"; \
21  s << #a " = "<<a<<"\n"; \
22  s << #b " = "<<b<<"\n"; \
23  s << "in file " << __FILE__ << ", line " << __LINE__ << "\n"; \
24  throw std::runtime_error(s.str()); \
25  }
26 
27 #define OPENGM_CHECK(expression,message) if(!(expression)) { \
28  std::stringstream s; \
29  s << message <<"\n";\
30  s << "OpenGM assertion " << #expression \
31  << " failed in file " << __FILE__ \
32  << ", line " << __LINE__ << std::endl; \
33  throw std::runtime_error(s.str()); \
34  }
35 
36 
38 #ifdef NDEBUG
39  #ifndef OPENGM_DEBUG
40  #define OPENGM_ASSERT_OP(a,op,b) { }
41  #else
42  #define OPENGM_ASSERT_OP(a,op,b) \
43  if(! static_cast<bool>( a op b ) ) { \
44  std::stringstream s; \
45  s << "OpenGM assertion : " << #a <<#op <<#b<< " failed:\n"; \
46  s << #a " = "<<a<<"\n"; \
47  s << #b " = "<<b<<"\n"; \
48  s << "in file " << __FILE__ << ", line " << __LINE__ << "\n"; \
49  throw std::runtime_error(s.str()); \
50  }
51  #endif
52 #else
53  #define OPENGM_ASSERT_OP(a,op,b) \
54  if(! static_cast<bool>( a op b ) ) { \
55  std::stringstream s; \
56  s << "OpenGM assertion : " << #a <<#op <<#b<< " failed:\n"; \
57  s << #a " = "<<a<<"\n"; \
58  s << #b " = "<<b<<"\n"; \
59  s << "in file " << __FILE__ << ", line " << __LINE__ << "\n"; \
60  throw std::runtime_error(s.str()); \
61  }
62 #endif
63 
64 #ifdef NDEBUG
65  #ifndef OPENGM_DEBUG
66  #define OPENGM_ASSERT(expression) {}
67  #else
68  #define OPENGM_ASSERT(expression) if(!(expression)) { \
69  std::stringstream s; \
70  s << "OpenGM assertion " << #expression \
71  << " failed in file " << __FILE__ \
72  << ", line " << __LINE__ << std::endl; \
73  throw std::runtime_error(s.str()); \
74  }
75  #endif
76 #else
77  #define OPENGM_ASSERT(expression) if(!(expression)) { \
78  std::stringstream s; \
79  s << "OpenGM assertion " << #expression \
80  << " failed in file " << __FILE__ \
81  << ", line " << __LINE__ << std::endl; \
82  throw std::runtime_error(s.str()); \
83  }
84 #endif
85 
87 #define OPENGM_META_ASSERT(assertion, msg) { \
88  meta::Assert< meta::Compare< meta::Bool<(assertion)> , meta::Bool<true> >::value > \
89  OPENGM_COMPILE_TIME_ASSERTION_FAILED_____REASON_____##msg; \
90  (void) OPENGM_COMPILE_TIME_ASSERTION_FAILED_____REASON_____##msg; \
91 }
92 
94 namespace opengm {
95 
96 typedef double DefaultTimingType;
98 
101 : public std::runtime_error
102 {
103  typedef std::runtime_error base;
104 
105  RuntimeError(const std::string& message)
106  : base(std::string("OpenGM error: ") + message) {}
107 };
108 
109 // abs function
110 template<class T>
111 inline T abs(const T& x) {
112  return x > 0 ? x : -x;
113 }
114 
115 template<class T>
116 inline T opengmMax(const T& x, const T& y) {
117  return x >= y ? x : y;
118 }
119 
120 template<class T>
121 inline T opengmMin(const T& x, const T& y) {
122  return x <= y ? x : y;
123 }
124 
125 } // namespace opengm
126 
127 #endif // #ifndef OPENGM_HXX
The OpenGM namespace.
Definition: config.hxx:43
opengm::UIntType SerializationIndexType
Definition: opengm.hxx:97
double DefaultTimingType
Definition: opengm.hxx:96
STL namespace.
T opengmMax(const T &x, const T &y)
Definition: opengm.hxx:116
BiggestUIntType UIntType
default uint (biggest / longest uint)
Definition: config.hxx:326
std::runtime_error base
Definition: opengm.hxx:103
T opengmMin(const T &x, const T &y)
Definition: opengm.hxx:121
RuntimeError(const std::string &message)
Definition: opengm.hxx:105
OpenGM runtime error.
Definition: opengm.hxx:100
T abs(const T &x)
Definition: opengm.hxx:111