2011-05-24 01:03:22 +00:00
|
|
|
// Copyright 2007-2010 Baptiste Lepilleur
|
|
|
|
// 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
|
|
|
|
2011-05-24 06:27:36 +00:00
|
|
|
#include <stdlib.h>
|
2015-01-20 16:18:15 -06: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)
|
|
|
|
|
2011-09-14 08:41:37 +00:00
|
|
|
#if JSON_USE_EXCEPTION
|
2014-07-01 08:48:54 +10:00
|
|
|
#include <stdexcept>
|
|
|
|
#define JSON_ASSERT(condition) \
|
|
|
|
assert(condition); // @todo <= change this into an exception throw
|
2015-01-20 16:18:15 -06:00
|
|
|
#define JSON_FAIL_MESSAGE(message) do{std::ostringstream oss; oss << message; throw std::runtime_error(oss.str());}while(0)
|
|
|
|
//#define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message)
|
2014-07-01 08:48:54 +10:00
|
|
|
#else // JSON_USE_EXCEPTION
|
|
|
|
#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-01-20 16:18:15 -06:00
|
|
|
// release bugs we abort, for a core-dump or debugger.
|
2014-07-01 08:48:54 +10:00
|
|
|
#define JSON_FAIL_MESSAGE(message) \
|
|
|
|
{ \
|
2015-01-20 16:18:15 -06:00
|
|
|
std::ostringstream oss; oss << message; \
|
|
|
|
assert(false && oss.str().c_str()); \
|
|
|
|
abort(); \
|
2014-07-01 08:48:54 +10:00
|
|
|
}
|
2011-12-22 03:18:24 +00:00
|
|
|
|
2015-01-20 16:18:15 -06: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
|