assert.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #else
  22. #include <stdexcept>
  23. #include <sstream>
  24. #include <opencv2/gapi/util/throw.hpp>
  25. namespace detail
  26. {
  27. [[noreturn]] inline void assert_abort(const char* str, int line, const char* file, const char* func)
  28. {
  29. std::stringstream ss;
  30. ss << file << ":" << line << ": Assertion " << str << " in function " << func << " failed\n";
  31. cv::util::throw_error(std::logic_error(ss.str()));
  32. }
  33. }
  34. #define GAPI_Assert(expr) \
  35. { if (!(expr)) ::detail::assert_abort(#expr, __LINE__, __FILE__, __func__); }
  36. #ifdef NDEBUG
  37. # define GAPI_DbgAssert(expr) GAPI_DbgAssertNoOp(expr)
  38. #else
  39. # define GAPI_DbgAssert(expr) GAPI_Assert(expr)
  40. #endif
  41. #endif // GAPI_STANDALONE
  42. #endif // OPENCV_GAPI_OWN_ASSERT_HPP