blob: 5ef7e7bb7d497225ffad160651028e4d19ce61bc [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
Aaron Jacobs9fa4e842014-07-01 08:48:54 +10007#define CPPTL_JSON_ASSERTIONS_H_INCLUDED
Aaron Jacobse3d0eca2011-05-24 01:03:22 +00008
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)
Christopher Dunn60f778b2014-07-09 21:37:23 -070012#include "config.h"
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000013#endif // if !defined(JSON_IS_AMALGAMATION)
14
Aaron Jacobs7c507d72011-09-14 08:41:37 +000015#if JSON_USE_EXCEPTION
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100016#include <stdexcept>
17#define JSON_ASSERT(condition) \
18 assert(condition); // @todo <= change this into an exception throw
19#define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message);
20#else // JSON_USE_EXCEPTION
21#define JSON_ASSERT(condition) assert(condition);
Aaron Jacobs2b853c42011-12-22 03:18:24 +000022
23// The call to assert() will show the failure message in debug builds. In
Aaron Jacobsf572e8e2012-01-08 23:49:55 +000024// release bugs we write to invalid memory in order to crash hard, so that a
25// debugger or crash reporter gets the chance to take over. We still call exit()
26// afterward in order to tell the compiler that this macro doesn't return.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100027#define JSON_FAIL_MESSAGE(message) \
28 { \
Aaron Jacobs11086dd2014-09-15 10:15:29 +100029 assert(false&& message); \
30 strcpy(reinterpret_cast<char*>(666), message); \
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100031 exit(123); \
32 }
Aaron Jacobs2b853c42011-12-22 03:18:24 +000033
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000034#endif
35
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100036#define JSON_ASSERT_MESSAGE(condition, message) \
37 if (!(condition)) { \
38 JSON_FAIL_MESSAGE(message) \
39 }
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000040
41#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED