OKVIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Namespaces | Macros | Functions
assert_macros.hpp File Reference

This file contains some useful assert macros. More...

#include <stdexcept>
#include <sstream>
#include <typeinfo>
#include "okvis/source_file_pos.hpp"

Go to the source code of this file.

Namespaces

 okvis
 okvis Main namespace of this package.
 
 okvis::detail
 

Macros

#define OKVIS_DEFINE_EXCEPTION(exceptionName, exceptionParent)
 Macro for defining an exception with a given parent. More...
 
#define OKVIS_THROW(exceptionType, message)
 
#define OKVIS_THROW_SFP(exceptionType, SourceFilePos, message)
 
#define OKVIS_ASSERT_TRUE(exceptionType, condition, message)
 
#define OKVIS_ASSERT_FALSE(exceptionType, condition, message)
 
#define OKVIS_ASSERT_GE_LT(exceptionType, value, lowerBound, upperBound, message)
 
#define OKVIS_ASSERT_LT(exceptionType, value, upperBound, message)
 
#define OKVIS_ASSERT_GE(exceptionType, value, lowerBound, message)
 
#define OKVIS_ASSERT_LE(exceptionType, value, upperBound, message)
 
#define OKVIS_ASSERT_GT(exceptionType, value, lowerBound, message)
 
#define OKVIS_ASSERT_EQ(exceptionType, value, testValue, message)
 
#define OKVIS_ASSERT_NE(exceptionType, value, testValue, message)
 
#define OKVIS_ASSERT_NEAR(exceptionType, value, testValue, abs_error, message)
 
#define OKVIS_THROW_DBG(exceptionType, message)
 
#define OKVIS_ASSERT_TRUE_DBG(exceptionType, condition, message)
 
#define OKVIS_ASSERT_FALSE_DBG(exceptionType, condition, message)
 
#define OKVIS_ASSERT_DBG_RE(condition, message)   OKVIS_ASSERT_DBG(std::runtime_error, condition, message)
 
#define OKVIS_ASSERT_GE_LT_DBG(exceptionType, value, lowerBound, upperBound, message)
 
#define OKVIS_ASSERT_LT_DBG(exceptionType, value, upperBound, message)
 
#define OKVIS_ASSERT_GE_DBG(exceptionType, value, lowerBound, message)
 
#define OKVIS_ASSERT_LE_DBG(exceptionType, value, upperBound, message)
 
#define OKVIS_ASSERT_GT_DBG(exceptionType, value, lowerBound, message)
 
#define OKVIS_ASSERT_EQ_DBG(exceptionType, value, testValue, message)
 
#define OKVIS_ASSERT_NE_DBG(exceptionType, value, testValue, message)
 
#define OKVIS_ASSERT_NEAR_DBG(exceptionType, value, testValue, abs_error, message)
 
#define OKVIS_OUT(X)   std::cout << #X << ": " << (X) << std::endl
 

Functions

template<typename OKVIS_EXCEPTION_T >
void okvis::detail::OKVIS_throw_exception (std::string const &exceptionType, okvis::source_file_pos sfp, std::string const &message)
 
template<typename OKVIS_EXCEPTION_T >
void okvis::detail::OKVIS_throw_exception (std::string const &exceptionType, std::string const &function, std::string const &file, int line, std::string const &message)
 
template<typename OKVIS_EXCEPTION_T >
void okvis::okvis_assert_throw (bool assert_condition, std::string message, okvis::source_file_pos sfp)
 

Detailed Description

This file contains some useful assert macros.

Author
Paul Furgale
Stefan Leutenegger

Macro Definition Documentation

#define OKVIS_ASSERT_DBG_RE (   condition,
  message 
)    OKVIS_ASSERT_DBG(std::runtime_error, condition, message)
#define OKVIS_ASSERT_EQ (   exceptionType,
  value,
  testValue,
  message 
)
Value:
if((value) != (testValue)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "assert(" << #value << " == " << #testValue << ") failed [" << (value) << " == " << (testValue) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_EQ_DBG (   exceptionType,
  value,
  testValue,
  message 
)
Value:
if((value) != (testValue)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "debug assert(" << #value << " == " << #testValue << ") failed [" << (value) << " == " << (testValue) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_FALSE (   exceptionType,
  condition,
  message 
)
Value:
if((condition)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "assert( not " << #condition << ") failed: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__, okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_FALSE_DBG (   exceptionType,
  condition,
  message 
)
Value:
if((condition)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "debug assert( not " << #condition << ") failed: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__, okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_GE (   exceptionType,
  value,
  lowerBound,
  message 
)
Value:
if((value) < (lowerBound)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "assert(" << #value << " >= " << #lowerBound << ") failed [" << (value) << " >= " << (lowerBound) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_GE_DBG (   exceptionType,
  value,
  lowerBound,
  message 
)
Value:
if((value) < (lowerBound)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "debug assert(" << #value << " >= " << #lowerBound << ") failed [" << (value) << " >= " << (lowerBound) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_GE_LT (   exceptionType,
  value,
  lowerBound,
  upperBound,
  message 
)
Value:
if((value) < (lowerBound) || (value) >= (upperBound)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "assert(" << #lowerBound << " <= " << #value << " < " << #upperBound << ") failed [" << (lowerBound) << " <= " << (value) << " < " << (upperBound) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_GE_LT_DBG (   exceptionType,
  value,
  lowerBound,
  upperBound,
  message 
)
Value:
if((value) < (lowerBound) || (value) >= (upperBound)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "debug assert(" << #lowerBound << " <= " << #value << " < " << #upperBound << ") failed [" << (lowerBound) << " <= " << (value) << " < " << (upperBound) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_GT (   exceptionType,
  value,
  lowerBound,
  message 
)
Value:
if((value) <= (lowerBound)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "assert(" << #value << " > " << #lowerBound << ") failed [" << (value) << " > " << (lowerBound) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_GT_DBG (   exceptionType,
  value,
  lowerBound,
  message 
)
Value:
if((value) <= (lowerBound)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "debug assert(" << #value << " > " << #lowerBound << ") failed [" << (value) << " > " << (lowerBound) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_LE (   exceptionType,
  value,
  upperBound,
  message 
)
Value:
if((value) > (upperBound)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "assert(" << #value << " <= " << #upperBound << ") failed [" << (value) << " <= " << (upperBound) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_LE_DBG (   exceptionType,
  value,
  upperBound,
  message 
)
Value:
if((value) > (upperBound)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "debug assert(" << #value << " <= " << #upperBound << ") failed [" << (value) << " <= " << (upperBound) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_LT (   exceptionType,
  value,
  upperBound,
  message 
)
Value:
if((value) >= (upperBound)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "assert(" << #value << " < " << #upperBound << ") failed [" << (value) << " < " << (upperBound) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_LT_DBG (   exceptionType,
  value,
  upperBound,
  message 
)
Value:
if((value) >= (upperBound)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "debug assert(" << #value << " < " << #upperBound << ") failed [" << (value) << " < " << (upperBound) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_NE (   exceptionType,
  value,
  testValue,
  message 
)
Value:
if((value) == (testValue)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "assert(" << #value << " != " << #testValue << ") failed [" << (value) << " != " << (testValue) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_NE_DBG (   exceptionType,
  value,
  testValue,
  message 
)
Value:
if((value) == (testValue)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "debug assert(" << #value << " != " << #testValue << ") failed [" << (value) << " != " << (testValue) << "]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_NEAR (   exceptionType,
  value,
  testValue,
  abs_error,
  message 
)
Value:
if(!(fabs((testValue) - (value)) <= fabs(abs_error))) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "assert(" << #value << " == " << #testValue << ") failed [" << (value) << " == " << (testValue) << " (" << fabs((testValue) - (value)) << " > " << fabs(abs_error) << ")]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_NEAR_DBG (   exceptionType,
  value,
  testValue,
  abs_error,
  message 
)
Value:
if(!(fabs((testValue) - (value)) <= fabs(abs_error))) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "debug assert(" << #value << " == " << #testValue << ") failed [" << (value) << " == " << (testValue) << " (" << fabs((testValue) - (value)) << " > " << fabs(abs_error) << ")]: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__,okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_TRUE (   exceptionType,
  condition,
  message 
)
Value:
if(!(condition)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "assert(" << #condition << ") failed: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__, okvis_assert_stringstream.str()); \
}
#define OKVIS_ASSERT_TRUE_DBG (   exceptionType,
  condition,
  message 
)
Value:
if(!(condition)) \
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << "debug assert(" << #condition << ") failed: " << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__, okvis_assert_stringstream.str()); \
}
#define OKVIS_DEFINE_EXCEPTION (   exceptionName,
  exceptionParent 
)
Value:
class exceptionName : public exceptionParent { \
public: \
exceptionName(const char * message) : exceptionParent(message) {} \
exceptionName(std::string const & message) : exceptionParent(message) {} \
virtual ~exceptionName() throw() {} \
};

Macro for defining an exception with a given parent.

#define OKVIS_OUT (   X)    std::cout << #X << ": " << (X) << std::endl
#define OKVIS_THROW (   exceptionType,
  message 
)
Value:
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__, okvis_assert_stringstream.str()); \
}
#define OKVIS_THROW_DBG (   exceptionType,
  message 
)
Value:
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", __FUNCTION__,__FILE__,__LINE__, okvis_assert_stringstream.str()); \
}
#define OKVIS_THROW_SFP (   exceptionType,
  SourceFilePos,
  message 
)
Value:
{ \
std::stringstream okvis_assert_stringstream; \
okvis_assert_stringstream << message; \
okvis::detail::OKVIS_throw_exception<exceptionType>("[" #exceptionType "] ", SourceFilePos, okvis_assert_stringstream.str()); \
}