assert.h - Engine C API Reference

assert.h
  1. #pragma once
  2. #include <assert.h>
  3. #include "../engine_plugin_api/plugin_api.h"
  4. #if defined(DEVELOPMENT)
  5. namespace stingray_plugin_foundation {
  6. inline struct ErrorApi *&error_api()
  7. {
  8. static struct ErrorApi *api = nullptr;
  9. return api;
  10. }
  11. inline void set_error_api(struct ErrorApi *api)
  12. {
  13. error_api() = api;
  14. }
  15. }
  16. #define XASSERT_BASE(test, test_msg, msg, ...) \
  17. do {if (!(test)) { \
  18. struct ErrorApi *api = stingray_plugin_foundation::error_api(); \
  19. if (api && api->report_assert_failure) \
  20. api->report_assert_failure(__LINE__, __FILE__, test_msg, api->eprintf(msg, ## __VA_ARGS__)); \
  21. else \
  22. assert(test); \
  23. }} while (0)
  24. #define XASSERT(test, msg, ...) do {XASSERT_BASE(test, #test, msg, ## __VA_ARGS__);} while(0)
  25. #define XENSURE(test) do {XASSERT_BASE(test, #test, "Assertion failed");} while(0)
  26. #define XERROR(msg, ...) do {XASSERT_BASE(false, nullptr, msg, ## __VA_ARGS__);} while(0)
  27. #else
  28. #define XASSERT(test, msg, ...) ((void)0)
  29. #define XENSURE(test) ((void)0)
  30. #define XERROR(msg, ...) ((void)0)
  31. namespace stingray_plugin_foundation {
  32. inline void set_error_api(struct ErrorApi *api) {}
  33. }
  34. #endif