2017-07-21 03:44:36 -07:00
|
|
|
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
|
2011-05-24 01:03:22 +00:00
|
|
|
// Distributed under MIT license, or public domain if desired and
|
|
|
|
// recognized in your jurisdiction.
|
|
|
|
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
|
|
|
|
|
|
|
#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
|
2014-07-01 08:48:54 +10:00
|
|
|
#define CPPTL_JSON_ASSERTIONS_H_INCLUDED
|
2011-05-24 01:03:22 +00:00
|
|
|
|
2018-12-12 13:34:37 -06:00
|
|
|
#include <cstdlib>
|
2019-01-17 11:07:53 -05:00
|
|
|
#include <sstream>
|
2011-05-24 06:27:36 +00:00
|
|
|
|
2011-05-24 01:03:22 +00:00
|
|
|
#if !defined(JSON_IS_AMALGAMATION)
|
2014-07-09 21:37:23 -07:00
|
|
|
#include "config.h"
|
2011-05-24 01:03:22 +00:00
|
|
|
#endif // if !defined(JSON_IS_AMALGAMATION)
|
|
|
|
|
2015-03-08 12:05:28 -05:00
|
|
|
/** It should not be possible for a maliciously designed file to
|
|
|
|
* cause an abort() or seg-fault, so these macros are used only
|
|
|
|
* for pre-condition violations and internal logic errors.
|
|
|
|
*/
|
2011-09-14 08:41:37 +00:00
|
|
|
#if JSON_USE_EXCEPTION
|
2015-03-08 12:39:27 -05:00
|
|
|
|
|
|
|
// @todo <= add detail about condition in exception
|
2018-05-20 16:55:27 -04:00
|
|
|
#define JSON_ASSERT(condition) \
|
|
|
|
{ \
|
|
|
|
if (!(condition)) { \
|
|
|
|
Json::throwLogicError("assert json failed"); \
|
|
|
|
} \
|
|
|
|
}
|
2015-03-08 12:39:27 -05:00
|
|
|
|
2018-05-20 16:55:27 -04:00
|
|
|
#define JSON_FAIL_MESSAGE(message) \
|
2015-03-05 15:19:43 -06:00
|
|
|
{ \
|
2019-01-17 16:35:29 -05:00
|
|
|
OStringStream oss; \
|
2018-05-20 16:55:27 -04:00
|
|
|
oss << message; \
|
2015-03-08 12:39:27 -05:00
|
|
|
Json::throwLogicError(oss.str()); \
|
|
|
|
abort(); \
|
2015-03-05 15:19:43 -06:00
|
|
|
}
|
2015-03-08 12:39:27 -05:00
|
|
|
|
2014-07-01 08:48:54 +10:00
|
|
|
#else // JSON_USE_EXCEPTION
|
2015-03-08 12:39:27 -05:00
|
|
|
|
2018-05-20 16:55:27 -04:00
|
|
|
#define JSON_ASSERT(condition) assert(condition)
|
2011-12-22 03:18:24 +00:00
|
|
|
|
|
|
|
// The call to assert() will show the failure message in debug builds. In
|
2015-03-08 12:05:28 -05:00
|
|
|
// release builds we abort, for a core-dump or debugger.
|
2018-05-20 16:55:27 -04:00
|
|
|
#define JSON_FAIL_MESSAGE(message) \
|
2014-07-01 08:48:54 +10:00
|
|
|
{ \
|
2019-01-17 16:35:29 -05:00
|
|
|
OStringStream oss; \
|
2018-05-20 16:55:27 -04:00
|
|
|
oss << message; \
|
2015-01-20 16:18:15 -06:00
|
|
|
assert(false && oss.str().c_str()); \
|
|
|
|
abort(); \
|
2014-07-01 08:48:54 +10:00
|
|
|
}
|
2011-12-22 03:18:24 +00:00
|
|
|
|
2011-05-24 01:03:22 +00:00
|
|
|
#endif
|
|
|
|
|
2014-07-01 08:48:54 +10:00
|
|
|
#define JSON_ASSERT_MESSAGE(condition, message) \
|
|
|
|
if (!(condition)) { \
|
2015-01-20 16:18:15 -06:00
|
|
|
JSON_FAIL_MESSAGE(message); \
|
2014-07-01 08:48:54 +10:00
|
|
|
}
|
2011-05-24 01:03:22 +00:00
|
|
|
|
|
|
|
#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
|