opengm.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_HXX
00003 #define OPENGM_HXX
00004 
00005 #include <stdexcept>
00006 #include <sstream>
00007 
00008 #include "opengm/config.hxx"
00009 #include "opengm/utilities/metaprogramming.hxx"
00010 
00011 
00012 
00013 
00014 // as runtime assertion but cefined even if NDEBUG
00015 
00016 #define OPENGM_CHECK_OP(a,op,b,message) \
00017     if(!  static_cast<bool>( a op b )   ) { \
00018        std::stringstream s; \
00019        s << "OpenGM Error: "<< message <<"\n";\
00020        s << "OpenGM check :  " << #a <<#op <<#b<< "  failed:\n"; \
00021        s << #a " = "<<a<<"\n"; \
00022        s << #b " = "<<b<<"\n"; \
00023        s << "in file " << __FILE__ << ", line " << __LINE__ << "\n"; \
00024        throw std::runtime_error(s.str()); \
00025     }
00026 
00027 #define OPENGM_CHECK(expression,message) if(!(expression)) { \
00028    std::stringstream s; \
00029    s << message <<"\n";\
00030    s << "OpenGM assertion " << #expression \
00031    << " failed in file " << __FILE__ \
00032    << ", line " << __LINE__ << std::endl; \
00033    throw std::runtime_error(s.str()); \
00034  }
00035 
00036 
00038 #ifdef NDEBUG
00039    #ifndef OPENGM_DEBUG 
00040       #define OPENGM_ASSERT_OP(a,op,b) { }
00041    #else
00042       #define OPENGM_ASSERT_OP(a,op,b) \
00043       if(!  static_cast<bool>( a op b )   ) { \
00044          std::stringstream s; \
00045          s << "OpenGM assertion :  " << #a <<#op <<#b<< "  failed:\n"; \
00046          s << #a " = "<<a<<"\n"; \
00047          s << #b " = "<<b<<"\n"; \
00048          s << "in file " << __FILE__ << ", line " << __LINE__ << "\n"; \
00049          throw std::runtime_error(s.str()); \
00050       }
00051    #endif
00052 #else
00053    #define OPENGM_ASSERT_OP(a,op,b) \
00054    if(!  static_cast<bool>( a op b )   ) { \
00055       std::stringstream s; \
00056       s << "OpenGM assertion :  " << #a <<#op <<#b<< "  failed:\n"; \
00057       s << #a " = "<<a<<"\n"; \
00058       s << #b " = "<<b<<"\n"; \
00059       s << "in file " << __FILE__ << ", line " << __LINE__ << "\n"; \
00060       throw std::runtime_error(s.str()); \
00061    }
00062 #endif
00063 
00064 #ifdef NDEBUG
00065    #ifndef OPENGM_DEBUG
00066       #define OPENGM_ASSERT(expression) {}
00067    #else
00068       #define OPENGM_ASSERT(expression) if(!(expression)) { \
00069          std::stringstream s; \
00070          s << "OpenGM assertion " << #expression \
00071          << " failed in file " << __FILE__ \
00072          << ", line " << __LINE__ << std::endl; \
00073          throw std::runtime_error(s.str()); \
00074       }
00075    #endif
00076 #else
00077       #define OPENGM_ASSERT(expression) if(!(expression)) { \
00078          std::stringstream s; \
00079          s << "OpenGM assertion " << #expression \
00080          << " failed in file " << __FILE__ \
00081          << ", line " << __LINE__ << std::endl; \
00082          throw std::runtime_error(s.str()); \
00083       }
00084 #endif
00085 
00087 #define OPENGM_META_ASSERT(assertion, msg) { \
00088    meta::Assert<   meta::Compare< meta::Bool<(assertion)> , meta::Bool<true> >::value    >  \
00089    OPENGM_COMPILE_TIME_ASSERTION_FAILED_____REASON_____##msg; \
00090    (void) OPENGM_COMPILE_TIME_ASSERTION_FAILED_____REASON_____##msg; \
00091 }
00092 
00094 namespace opengm {
00095 
00096 typedef double DefaultTimingType;
00097 typedef opengm::UIntType SerializationIndexType;
00098 
00100 struct RuntimeError
00101 : public std::runtime_error
00102 {
00103    typedef std::runtime_error base;
00104 
00105    RuntimeError(const std::string& message)
00106    :  base(std::string("OpenGM error: ") + message) {}
00107 };
00108 
00109 // abs function
00110 template<class T>
00111 inline T abs(const T& x) { 
00112    return x > 0 ? x : -x; 
00113 }
00114 
00115 template<class T>
00116 inline T opengmMax(const T& x, const T& y) {
00117    return x >= y ? x : y;
00118 }
00119 
00120 template<class T>
00121 inline T opengmMin(const T& x, const T& y) {
00122    return x <= y ? x : y;
00123 }
00124 
00125 } // namespace opengm
00126 
00127 #endif // #ifndef OPENGM_HXX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:05 2013 for OpenGM by  doxygen 1.6.3