JSONDebug.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef LIBJSON_GUARD_DEBUG_H
  2. #define LIBJSON_GUARD_DEBUG_H
  3. #include "JSONDefs.h"
  4. #include "JSONStats.h"
  5. #ifdef JSON_DEBUG
  6. #ifdef JSON_SAFE
  7. #define JSON_ASSERT_SAFE(condition, msg, code)\
  8. {\
  9. if (json_unlikely(!(condition))){\
  10. JSON_FAIL(msg);\
  11. code\
  12. }\
  13. }
  14. #define JSON_FAIL_SAFE(msg, code)\
  15. {\
  16. JSON_FAIL(msg);\
  17. code\
  18. }
  19. #else
  20. #define JSON_ASSERT_SAFE(condition, msg, code) JSON_ASSERT(condition, msg)
  21. #define JSON_FAIL_SAFE(msg, code) JSON_FAIL(msg)
  22. #endif
  23. #define JSON_FAIL(msg) JSONDebug::_JSON_FAIL(msg)
  24. #define JSON_ASSERT(bo, msg) JSONDebug::_JSON_ASSERT(bo, msg)
  25. class JSONDebug {
  26. public:
  27. #ifndef JSON_STDERROR
  28. static json_error_callback_t register_callback(json_error_callback_t callback) json_nothrow json_cold;
  29. #endif
  30. static void _JSON_FAIL(const json_string & msg) json_nothrow json_cold;
  31. static void _JSON_ASSERT(bool condition, const json_string & msg) json_nothrow json_cold;
  32. };
  33. #else
  34. #ifdef JSON_SAFE
  35. #define JSON_ASSERT_SAFE(condition, msg, code)\
  36. {\
  37. if (json_unlikely(!(condition))){\
  38. code\
  39. }\
  40. }
  41. #define JSON_FAIL_SAFE(msg, code)\
  42. {\
  43. code\
  44. }
  45. #else
  46. #define JSON_ASSERT_SAFE(condition, msg, code)
  47. #define JSON_FAIL_SAFE(msg, code)
  48. #endif
  49. #define JSON_ASSERT(condition, msg)
  50. #define JSON_FAIL(msg)
  51. #endif
  52. #endif