Aaron Jacobs | e3d0eca | 2011-05-24 01:03:22 +0000 | [diff] [blame] | 1 | // 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 Jacobs | a761530 | 2011-05-24 06:27:36 +0000 | [diff] [blame] | 9 | #include <stdlib.h> |
Aaron Jacobs | a761530 | 2011-05-24 06:27:36 +0000 | [diff] [blame] | 10 | |
Aaron Jacobs | e3d0eca | 2011-05-24 01:03:22 +0000 | [diff] [blame] | 11 | #if !defined(JSON_IS_AMALGAMATION) |
| 12 | # include <json/config.h> |
| 13 | #endif // if !defined(JSON_IS_AMALGAMATION) |
| 14 | |
Aaron Jacobs | 7c507d7 | 2011-09-14 08:41:37 +0000 | [diff] [blame] | 15 | #if JSON_USE_EXCEPTION |
Christopher Dunn | 6764059 | 2014-05-13 09:49:25 +0000 | [diff] [blame] | 16 | # include <stdexcept> |
Aaron Jacobs | e3d0eca | 2011-05-24 01:03:22 +0000 | [diff] [blame] | 17 | #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 Jacobs | 7c507d7 | 2011-09-14 08:41:37 +0000 | [diff] [blame] | 19 | #else // JSON_USE_EXCEPTION |
Aaron Jacobs | e3d0eca | 2011-05-24 01:03:22 +0000 | [diff] [blame] | 20 | #define JSON_ASSERT( condition ) assert( condition ); |
Aaron Jacobs | 2b853c4 | 2011-12-22 03:18:24 +0000 | [diff] [blame] | 21 | |
| 22 | // The call to assert() will show the failure message in debug builds. In |
Aaron Jacobs | f572e8e | 2012-01-08 23:49:55 +0000 | [diff] [blame] | 23 | // 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 Jacobs | 2b853c4 | 2011-12-22 03:18:24 +0000 | [diff] [blame] | 27 | |
Aaron Jacobs | e3d0eca | 2011-05-24 01:03:22 +0000 | [diff] [blame] | 28 | #endif |
| 29 | |
| 30 | #define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) { JSON_FAIL_MESSAGE( message ) } |
| 31 | |
| 32 | #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED |