blob: a88ac0a8772447bd754e8c42bfe8bb34abd1a1b6 [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>
Christopher Dunn7956ccd2015-01-20 16:18:15 -060010#include <sstream>
Aaron Jacobsa7615302011-05-24 06:27:36 +000011
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000012#if !defined(JSON_IS_AMALGAMATION)
Christopher Dunn60f778b2014-07-09 21:37:23 -070013#include "config.h"
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000014#endif // if !defined(JSON_IS_AMALGAMATION)
15
Aaron Jacobs7c507d72011-09-14 08:41:37 +000016#if JSON_USE_EXCEPTION
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100017#include <stdexcept>
18#define JSON_ASSERT(condition) \
Christopher Dunn0c919272015-03-03 09:45:33 -060019 if (!(condition)) {throw std::logic_error( "assert json failed" );} // @todo <= add detail about condition in exception
20#define JSON_FAIL_MESSAGE(message) do{std::ostringstream oss; oss << message; throw std::logic_error(oss.str());}while(0)
21//#define JSON_FAIL_MESSAGE(message) throw std::logic_error(message)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100022#else // JSON_USE_EXCEPTION
23#define JSON_ASSERT(condition) assert(condition);
Aaron Jacobs2b853c42011-12-22 03:18:24 +000024
25// The call to assert() will show the failure message in debug builds. In
Christopher Dunn7956ccd2015-01-20 16:18:15 -060026// release bugs we abort, for a core-dump or debugger.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100027#define JSON_FAIL_MESSAGE(message) \
28 { \
Christopher Dunn7956ccd2015-01-20 16:18:15 -060029 std::ostringstream oss; oss << message; \
30 assert(false && oss.str().c_str()); \
31 abort(); \
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100032 }
Aaron Jacobs2b853c42011-12-22 03:18:24 +000033
Christopher Dunn7956ccd2015-01-20 16:18:15 -060034
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000035#endif
36
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100037#define JSON_ASSERT_MESSAGE(condition, message) \
38 if (!(condition)) { \
Christopher Dunn7956ccd2015-01-20 16:18:15 -060039 JSON_FAIL_MESSAGE(message); \
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100040 }
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000041
42#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED