62 lines
2.8 KiB
C
Raw Normal View History

2018-01-26 17:06:56 +01:00
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
2015-04-27 22:25:09 +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
2021-11-20 13:41:27 +01:00
#ifndef JSON_ASSERTIONS_H_INCLUDED
#define JSON_ASSERTIONS_H_INCLUDED
2015-04-27 22:25:09 +02:00
#if !defined(JSON_IS_AMALGAMATION)
#include "config.h"
#endif // if !defined(JSON_IS_AMALGAMATION)
2021-11-20 13:41:27 +01:00
#include <cstdlib>
2018-01-26 17:06:56 +01:00
#include <sstream>
2015-04-27 22:25:09 +02:00
2018-01-26 17:06:56 +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.
*/
2015-04-27 22:25:09 +02:00
#if JSON_USE_EXCEPTION
2018-01-26 17:06:56 +01:00
// @todo <= add detail about condition in exception
2021-11-20 13:41:27 +01:00
#define JSON_ASSERT(condition) \
do { \
if (!(condition)) { \
Json::throwLogicError("assert json failed"); \
} \
} while (0)
#define JSON_FAIL_MESSAGE(message) \
do { \
OStringStream oss; \
oss << message; \
2018-01-26 17:06:56 +01:00
Json::throwLogicError(oss.str()); \
abort(); \
2021-11-20 13:41:27 +01:00
} while (0)
2018-01-26 17:06:56 +01:00
2015-04-27 22:25:09 +02:00
#else // JSON_USE_EXCEPTION
2018-01-26 17:06:56 +01:00
2021-11-20 13:41:27 +01:00
#define JSON_ASSERT(condition) assert(condition)
2015-04-27 22:25:09 +02:00
// The call to assert() will show the failure message in debug builds. In
2018-01-26 17:06:56 +01:00
// release builds we abort, for a core-dump or debugger.
2021-11-20 13:41:27 +01:00
#define JSON_FAIL_MESSAGE(message) \
2015-04-27 22:25:09 +02:00
{ \
2021-11-20 13:41:27 +01:00
OStringStream oss; \
oss << message; \
2018-01-26 17:06:56 +01:00
assert(false && oss.str().c_str()); \
abort(); \
2015-04-27 22:25:09 +02:00
}
#endif
#define JSON_ASSERT_MESSAGE(condition, message) \
2021-11-20 13:41:27 +01:00
do { \
if (!(condition)) { \
JSON_FAIL_MESSAGE(message); \
} \
} while (0)
2015-04-27 22:25:09 +02:00
2021-11-20 13:41:27 +01:00
#endif // JSON_ASSERTIONS_H_INCLUDED