blob: 9c17461361de83eb4c5be9ef8757946a41eef9ef [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
Christopher Dunn67640592014-05-13 09:49:25 +000016# include <stdexcept>
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000017#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw
18#define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message );
Aaron Jacobs7c507d72011-09-14 08:41:37 +000019#else // JSON_USE_EXCEPTION
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000020#define JSON_ASSERT( condition ) assert( condition );
Aaron Jacobs2b853c42011-12-22 03:18:24 +000021
22// The call to assert() will show the failure message in debug builds. In
Aaron Jacobsf572e8e2012-01-08 23:49:55 +000023// release bugs we write to invalid memory in order to crash hard, so that a
24// debugger or crash reporter gets the chance to take over. We still call exit()
25// afterward in order to tell the compiler that this macro doesn't return.
26#define JSON_FAIL_MESSAGE( message ) { assert(false && message); strcpy(reinterpret_cast<char*>(666), message); exit(123); }
Aaron Jacobs2b853c42011-12-22 03:18:24 +000027
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000028#endif
29
30#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) { JSON_FAIL_MESSAGE( message ) }
31
32#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED