blob: a480585a0a06e77d5a2323762318b920f72a6b83 [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
Aaron Jacobsf572e8e2012-01-08 23:49:55 +000022// release bugs we write to invalid memory in order to crash hard, so that a
23// debugger or crash reporter gets the chance to take over. We still call exit()
24// afterward in order to tell the compiler that this macro doesn't return.
25#define JSON_FAIL_MESSAGE( message ) { assert(false && message); strcpy(reinterpret_cast<char*>(666), message); exit(123); }
Aaron Jacobs2b853c42011-12-22 03:18:24 +000026
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