assert.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2018-2020 Intel Corporation
  6. #ifndef OPENCV_GAPI_OWN_ASSERT_HPP
  7. #define OPENCV_GAPI_OWN_ASSERT_HPP
  8. #include <opencv2/gapi/util/compiler_hints.hpp>
  9. #define GAPI_DbgAssertNoOp(expr) { \
  10. constexpr bool _assert_tmp = false && (expr); \
  11. cv::util::suppress_unused_warning(_assert_tmp); \
  12. }
  13. #if !defined(GAPI_STANDALONE)
  14. #include <opencv2/core/base.hpp>
  15. #define GAPI_Assert CV_Assert
  16. #if defined _DEBUG || defined CV_STATIC_ANALYSIS
  17. # define GAPI_DbgAssert CV_DbgAssert
  18. #else
  19. # define GAPI_DbgAssert(expr) GAPI_DbgAssertNoOp(expr)
  20. #endif
  21. #define GAPI_Error(msg) CV_Error(cv::Error::StsError, msg)
  22. #else
  23. #include <stdexcept>
  24. #include <sstream>
  25. #include <opencv2/gapi/util/throw.hpp>
  26. namespace detail
  27. {
  28. [[noreturn]] inline void assert_abort(const char* str, int line, const char* file, const char* func)
  29. {
  30. std::stringstream ss;
  31. ss << file << ":" << line << ": Assertion " << str << " in function " << func << " failed\n";
  32. cv::util::throw_error(std::logic_error(ss.str()));
  33. }
  34. }
  35. #define GAPI_Assert(expr) \
  36. { if (!(expr)) ::detail::assert_abort(#expr, __LINE__, __FILE__, __func__); }
  37. #ifdef NDEBUG
  38. # define GAPI_DbgAssert(expr) GAPI_DbgAssertNoOp(expr)
  39. #else
  40. # define GAPI_DbgAssert(expr) GAPI_Assert(expr)
  41. #endif
  42. #define GAPI_Error(msg) { \
  43. ::detail::assert_abort(msg, __LINE__, __FILE__, __func__); \
  44. }
  45. #endif // GAPI_STANDALONE
  46. #endif // OPENCV_GAPI_OWN_ASSERT_HPP