2017-07-21 18:44:36 +08:00
|
|
|
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
|
2011-05-24 09:03:22 +08: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 06:48:54 +08:00
|
|
|
#define CPPTL_JSON_ASSERTIONS_H_INCLUDED
|
2011-05-24 09:03:22 +08:00
|
|
|
|
2015-01-21 06:18:15 +08:00
|
|
|
#include <sstream>
|
2018-12-13 03:34:37 +08:00
|
|
|
#include <cstdlib>
|
2011-05-24 14:27:36 +08:00
|
|
|
|
2011-05-24 09:03:22 +08:00
|
|
|
#if !defined(JSON_IS_AMALGAMATION)
|
2014-07-10 12:37:23 +08:00
|
|
|
#include "config.h"
|
2011-05-24 09:03:22 +08:00
|
|
|
#endif // if !defined(JSON_IS_AMALGAMATION)
|
|
|
|
|
2015-03-09 01:05:28 +08: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 16:41:37 +08:00
|
|
|
#if JSON_USE_EXCEPTION
|
2015-03-09 01:39:27 +08:00
|
|
|
|
|
|
|
// @todo <= add detail about condition in exception
|
2018-05-21 04:55:27 +08:00
|
|
|
#define JSON_ASSERT(condition) \
|
|
|
|
{ \
|
|
|
|
if (!(condition)) { \
|
|
|
|
Json::throwLogicError("assert json failed"); \
|
|
|
|
} \
|
|
|
|
}
|
2015-03-09 01:39:27 +08:00
|
|
|
|
2018-05-21 04:55:27 +08:00
|
|
|
#define JSON_FAIL_MESSAGE(message) \
|
2015-03-06 05:19:43 +08:00
|
|
|
{ \
|
2018-05-21 04:55:27 +08:00
|
|
|
JSONCPP_OSTRINGSTREAM oss; \
|
|
|
|
oss << message; \
|
2015-03-09 01:39:27 +08:00
|
|
|
Json::throwLogicError(oss.str()); \
|
|
|
|
abort(); \
|
2015-03-06 05:19:43 +08:00
|
|
|
}
|
2015-03-09 01:39:27 +08:00
|
|
|
|
2014-07-01 06:48:54 +08:00
|
|
|
#else // JSON_USE_EXCEPTION
|
2015-03-09 01:39:27 +08:00
|
|
|
|
2018-05-21 04:55:27 +08:00
|
|
|
#define JSON_ASSERT(condition) assert(condition)
|
2011-12-22 11:18:24 +08:00
|
|
|
|
|
|
|
// The call to assert() will show the failure message in debug builds. In
|
2015-03-09 01:05:28 +08:00
|
|
|
// release builds we abort, for a core-dump or debugger.
|
2018-05-21 04:55:27 +08:00
|
|
|
#define JSON_FAIL_MESSAGE(message) \
|
2014-07-01 06:48:54 +08:00
|
|
|
{ \
|
2018-05-21 04:55:27 +08:00
|
|
|
JSONCPP_OSTRINGSTREAM oss; \
|
|
|
|
oss << message; \
|
2015-01-21 06:18:15 +08:00
|
|
|
assert(false && oss.str().c_str()); \
|
|
|
|
abort(); \
|
2014-07-01 06:48:54 +08:00
|
|
|
}
|
2011-12-22 11:18:24 +08:00
|
|
|
|
2011-05-24 09:03:22 +08:00
|
|
|
#endif
|
|
|
|
|
2014-07-01 06:48:54 +08:00
|
|
|
#define JSON_ASSERT_MESSAGE(condition, message) \
|
|
|
|
if (!(condition)) { \
|
2015-01-21 06:18:15 +08:00
|
|
|
JSON_FAIL_MESSAGE(message); \
|
2014-07-01 06:48:54 +08:00
|
|
|
}
|
2011-05-24 09:03:22 +08:00
|
|
|
|
|
|
|
#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
|