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