assert.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 Intel Corporation
  6. #ifndef OPENCV_GAPI_OWN_ASSERT_HPP
  7. #define OPENCV_GAPI_OWN_ASSERT_HPP
  8. #if !defined(GAPI_STANDALONE)
  9. #include <opencv2/core/base.hpp>
  10. #define GAPI_Assert CV_Assert
  11. #define GAPI_DbgAssert CV_DbgAssert
  12. #else
  13. #include <stdexcept>
  14. #include <sstream>
  15. #include "opencv2/gapi/util/throw.hpp"
  16. namespace detail
  17. {
  18. inline void assert_abort(const char* str, int line, const char* file, const char* func)
  19. {
  20. std::stringstream ss;
  21. ss << file << ":" << line << ": Assertion " << str << " in function " << func << " failed\n";
  22. cv::util::throw_error(std::logic_error(ss.str()));
  23. }
  24. }
  25. #define GAPI_Assert(expr) \
  26. { if (!(expr)) ::detail::assert_abort(#expr, __LINE__, __FILE__, __func__); }
  27. #ifdef NDEBUG
  28. # define GAPI_DbgAssert(expr)
  29. #else
  30. # define GAPI_DbgAssert(expr) GAPI_Assert(expr)
  31. #endif
  32. #endif // GAPI_STANDALONE
  33. #endif // OPENCV_GAPI_OWN_ASSERT_HPP