Autonomous Space Robotics Lab

Speeded Up SURF

UTIAS ASRL

assert_macros.hpp File Reference

Handy assert macros that throw exceptions when something goes awry. More...

#include <stdexcept>
#include <sstream>

Go to the source code of this file.

Namespaces

namespace  asrl
namespace  asrl::detail

Defines

#define ASRL_TRACE   std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "()" << std::endl;
#define ASRL_THROW(message)
#define ASRL_ASSERT(condition, message)
#define ASRL_ASSERT_GE_LT(value, lowerBound, upperBound, message)
#define ASRL_ASSERT_LT(value, upperBound, message)
#define ASRL_ASSERT_GE(value, lowerBound, message)
#define ASRL_ASSERT_LE(value, upperBound, message)
#define ASRL_ASSERT_GT(value, lowerBound, message)
#define ASRL_ASSERT_EQ(value, testValue, message)
#define ASRL_ASSERT_NE(value, testValue, message)
#define ASRL_CHECK_CUDA_ERROR(errorMessage)
#define ASRL_ASSERT_EQ_TOL(value, testValue, tolerance, message)
#define ASRL_THROW_DBG(message)
#define ASRL_ASSERT_DBG(condition, message)
#define ASRL_ASSERT_GE_LT_DBG(value, lowerBound, upperBound, message)
#define ASRL_ASSERT_LT_DBG(value, upperBound, message)
#define ASRL_ASSERT_GE_DBG(value, lowerBound, message)
#define ASRL_ASSERT_LE_DBG(value, upperBound, message)
#define ASRL_ASSERT_GT_DBG(value, lowerBound, message)
#define ASRL_ASSERT_EQ_DBG(value, testValue, message)
#define ASRL_ASSERT_NE_DBG(value, testValue, message)
#define ASRL_CHECK_CUDA_ERROR_DBG(errorMessage)

Functions

void asrl::detail::throw_runtime_error (std::string function, std::string file, int line, std::string message)

Detailed Description

Handy assert macros that throw exceptions when something goes awry.

Authors:
Paul Furgale and Chi Hay Tong
Date:
Thu Feb 18 18:18:47 2010

These handy macros will build and throw standard exceptions that include the current file, function name, and line number.

Definition in file assert_macros.hpp.


Define Documentation

#define ASRL_ASSERT ( condition,
message   ) 
Value:
if(!(condition))                                                        \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "assert " << #condition << " failed: " << message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__, asrl_assert_stringstream.str()); \
    }

A macro to check if "condition" is true. If it isn't a runtime error is thrown.

Parameters:
condition A runtime error is thrown if this condition evaluates to false
message An informative message to be included in the exception

Definition at line 94 of file assert_macros.hpp.

#define ASRL_ASSERT_DBG ( condition,
message   ) 
Value:
if(!(condition))                                                        \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "debug assert " << #condition << " failed: " << message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__, asrl_assert_stringstream.str()); \
    }

Throws a runtime error including the function, file, and line number. The exception is only thrown in debug mode.

Parameters:
message An informative message to be included in the exception

Definition at line 259 of file assert_macros.hpp.

#define ASRL_ASSERT_EQ ( value,
testValue,
message   ) 
Value:
if(value != testValue)                                          \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "assert " << #value << " == " << #testValue << " failed [" << value << " == " << testValue << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value == testValue$ If it is not, a runtime error is thrown

Parameters:
message An informative message included in the exception

Definition at line 184 of file assert_macros.hpp.

#define ASRL_ASSERT_EQ_DBG ( value,
testValue,
message   ) 
Value:
if(value != testValue)                                          \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "debug assert " << #value << " == " << #testValue << " failed [" << value << " == " << testValue << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value == testValue$ If it is not, a runtime error is thrown The exception is only thrown in debug mode.

Parameters:
message An informative message included in the exception

Definition at line 360 of file assert_macros.hpp.

#define ASRL_ASSERT_EQ_TOL ( value,
testValue,
tolerance,
message   ) 
Value:
if(fabs((double)value - (double)testValue) > (double)tolerance) \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "assert " << #value << " == " << #testValue << " (tolerance " << #tolerance ") failed [" << value << " != " << testValue << ", " << tolerance << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value = testValue$ to within some tolerance If it is not, a runtime error is thrown

Parameters:
message An informative message included in the exception

Definition at line 229 of file assert_macros.hpp.

#define ASRL_ASSERT_GE ( value,
lowerBound,
message   ) 
Value:
if(value < lowerBound)                                          \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "assert " << #value << " >= " << #lowerBound << " failed [" << value << " >= " << lowerBound << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value >= lowerBound$ If it is not, a runtime error is thrown

Parameters:
message An informative message included in the exception

Definition at line 139 of file assert_macros.hpp.

#define ASRL_ASSERT_GE_DBG ( value,
lowerBound,
message   ) 
Value:
if(value < lowerBound)                                          \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "debug assert " << #value << " >= " << #lowerBound << " failed [" << value << " >= " << lowerBound << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value >= lowerBound$ If it is not, a runtime error is thrown The exception is only thrown in debug mode.

Parameters:
message An informative message included in the exception

Definition at line 309 of file assert_macros.hpp.

#define ASRL_ASSERT_GE_LT ( value,
lowerBound,
upperBound,
message   ) 
Value:
if(value < lowerBound || value >= upperBound)                           \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "assert " << #lowerBound << " <= " << #value << " < " << #upperBound << " failed [" << lowerBound << " <= " << value << " < " << upperBound << "]: " << message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $lowerBound <= value < upperBound$ If it is not, a runtime error is thrown

Parameters:
message An informative message included in the exception

Definition at line 109 of file assert_macros.hpp.

#define ASRL_ASSERT_GE_LT_DBG ( value,
lowerBound,
upperBound,
message   ) 
Value:
if(value < lowerBound || value >= upperBound)                           \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "debug assert " << #lowerBound << " <= " << #value << " < " << #upperBound << " failed [" << lowerBound << " <= " << value << " < " << upperBound << "]: " << message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $lowerBound <= value < upperBound$ If it is not, a runtime error is thrown The exception is only thrown in debug mode.

Parameters:
message An informative message included in the exception

Definition at line 275 of file assert_macros.hpp.

#define ASRL_ASSERT_GT ( value,
lowerBound,
message   ) 
Value:
if(value <= lowerBound)                                         \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "assert " << #value << " > " << #lowerBound << " failed [" << value << " > " << lowerBound << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value > lowerBound$ If it is not, a runtime error is thrown

Parameters:
message An informative message included in the exception

Definition at line 169 of file assert_macros.hpp.

#define ASRL_ASSERT_GT_DBG ( value,
lowerBound,
message   ) 
Value:
if(value <= lowerBound)                                         \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "debug assert " << #value << " > " << #lowerBound << " failed [" << value << " > " << lowerBound << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value > lowerBound$ If it is not, a runtime error is thrown The exception is only thrown in debug mode.

Parameters:
message An informative message included in the exception

Definition at line 343 of file assert_macros.hpp.

#define ASRL_ASSERT_LE ( value,
upperBound,
message   ) 
Value:
if(value > upperBound)                                          \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "assert " << #value << " <= " << #upperBound << " failed [" << value << " <= " << upperBound << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value <= upperBound$ If it is not, a runtime error is thrown

Parameters:
message An informative message included in the exception

Definition at line 154 of file assert_macros.hpp.

#define ASRL_ASSERT_LE_DBG ( value,
upperBound,
message   ) 
Value:
if(value > upperBound)                                          \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "debug assert " << #value << " <= " << #upperBound << " failed [" << value << " <= " << upperBound << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value < upperBound$ If it is not, a runtime error is thrown The exception is only thrown in debug mode.

Parameters:
message An informative message included in the exception

Definition at line 326 of file assert_macros.hpp.

#define ASRL_ASSERT_LT ( value,
upperBound,
message   ) 
Value:
if(value >= upperBound)                                         \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "assert " << #value << " < " << #upperBound << " failed [" << value << " < " << upperBound << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value < upperBound$ If it is not, a runtime error is thrown

Parameters:
message An informative message included in the exception

Definition at line 124 of file assert_macros.hpp.

#define ASRL_ASSERT_LT_DBG ( value,
upperBound,
message   ) 
Value:
if(value >= upperBound)                                         \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "debug assert " << #value << " < " << #upperBound << " failed [" << value << " < " << upperBound << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value < upperBound$ If it is not, a runtime error is thrown The exception is only thrown in debug mode.

Parameters:
message An informative message included in the exception

Definition at line 292 of file assert_macros.hpp.

#define ASRL_ASSERT_NE ( value,
testValue,
message   ) 
Value:
if(value == testValue)                                          \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "assert " << #value << " != " << #testValue << " failed [" << value << " != " << testValue << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value != testValue$ If it is not, a runtime error is thrown

Parameters:
message An informative message included in the exception

Definition at line 199 of file assert_macros.hpp.

#define ASRL_ASSERT_NE_DBG ( value,
testValue,
message   ) 
Value:
if(value == testValue)                                          \
    {                                                                   \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "debug assert " << #value << " != " << #testValue << " failed [" << value << " != " << testValue << "]: " <<  message; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    }

This macro asserts that $value != testValue$ If it is not, a runtime error is thrown The exception is only thrown in debug mode.

Parameters:
message An informative message included in the exception

Definition at line 376 of file assert_macros.hpp.

#define ASRL_CHECK_CUDA_ERROR ( errorMessage   ) 
Value:
{                       \
    cudaError_t err = cudaGetLastError();                               \
    if( cudaSuccess != err) {                                           \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "CUDA error: " << cudaGetErrorString( err ) << " : " <<  errorMessage; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    } \
  }

This macro checks for a cuda error. If there is one. it throws an error

Parameters:
errorMessage the message to return

Definition at line 213 of file assert_macros.hpp.

#define ASRL_CHECK_CUDA_ERROR_DBG ( errorMessage   ) 
Value:
{                       \
    cudaError_t err = cudaGetLastError();                               \
    if( cudaSuccess != err) {                                           \
      std::ostringstream asrl_assert_stringstream;                      \
      asrl_assert_stringstream << "CUDA error: " << cudaGetErrorString( err ) << " : " <<  errorMessage; \
      asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__,asrl_assert_stringstream.str()); \
    } \
  }

This macro checks for a cuda error. If there is one. it throws an error

Parameters:
errorMessage the message to return

Definition at line 391 of file assert_macros.hpp.

#define ASRL_THROW ( message   ) 
Value:
{                                               \
    std::ostringstream asrl_assert_stringstream;                        \
    asrl_assert_stringstream << message;                                \
    asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__, asrl_assert_stringstream.str()); \
  }

Throws a runtime error including the function, file, and line number.

Parameters:
message An informative message to be included in the exception

Definition at line 81 of file assert_macros.hpp.

#define ASRL_THROW_DBG ( message   ) 
Value:
{                                       \
    std::ostringstream asrl_assert_stringstream;                        \
    asrl_assert_stringstream << message;                                \
    asrl::detail::throw_runtime_error(__FUNCTION__,__FILE__,__LINE__, asrl_assert_stringstream.str()); \
  }

Throws a runtime error including the function, file, and line number. The exception is only thrown in debug mode.

Parameters:
message An informative message to be included in the exception

Definition at line 246 of file assert_macros.hpp.

#define ASRL_TRACE   std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "()" << std::endl;

Definition at line 73 of file assert_macros.hpp.


Generated on Fri Apr 30 20:06:20 2010 for gpusurf by doxygen 1.6.2