blob: 2a22cc402296c2e0d7dde4d36874b94b0cf834d4 [file] [log] [blame]
Aaron Jacobse3d0eca2011-05-24 01:03:22 +00001// Copyright 2007-2010 Baptiste Lepilleur
2// Distributed under MIT license, or public domain if desired and
3// recognized in your jurisdiction.
4// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
5
6#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
7# define CPPTL_JSON_ASSERTIONS_H_INCLUDED
8
Aaron Jacobsa7615302011-05-24 06:27:36 +00009#include <stdlib.h>
Aaron Jacobsa7615302011-05-24 06:27:36 +000010
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000011#if !defined(JSON_IS_AMALGAMATION)
12# include <json/config.h>
13#endif // if !defined(JSON_IS_AMALGAMATION)
14
Aaron Jacobs7c507d72011-09-14 08:41:37 +000015#if JSON_USE_EXCEPTION
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000016#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw
17#define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message );
Aaron Jacobs7c507d72011-09-14 08:41:37 +000018#else // JSON_USE_EXCEPTION
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000019#define JSON_ASSERT( condition ) assert( condition );
Aaron Jacobs2b853c42011-12-22 03:18:24 +000020
21// The call to assert() will show the failure message in debug builds. In
22// release bugs we write to invalid memory in order to crash hard instead of
23// calling exit(), so that a debugger or crash reporter gets the chance to take
24// over.
25#define JSON_FAIL_MESSAGE( message ) { assert(false && message); strcpy(reinterpret_cast<char*>(666), message); }
26
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000027#endif
28
29#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) { JSON_FAIL_MESSAGE( message ) }
30
31#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED