blob: d5fd661c46de18df2c2a2bf89ea5ccbd4e34cf38 [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 Dunnb3e6f3d2015-03-05 15:19:43 -060019 {if (!(condition)) {throw std::logic_error( "assert json failed" );}} // @todo <= add detail about condition in exception
20#define JSON_FAIL_MESSAGE(message) \
21 { \
22 std::ostringstream oss; oss << message; \
23 throw std::logic_error(oss.str()); \
24 }
Christopher Dunn0c919272015-03-03 09:45:33 -060025//#define JSON_FAIL_MESSAGE(message) throw std::logic_error(message)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100026#else // JSON_USE_EXCEPTION
Christopher Dunnb3e6f3d2015-03-05 15:19:43 -060027#define JSON_ASSERT(condition) assert(condition)
Aaron Jacobs2b853c42011-12-22 03:18:24 +000028
29// The call to assert() will show the failure message in debug builds. In
Christopher Dunn7956ccd2015-01-20 16:18:15 -060030// release bugs we abort, for a core-dump or debugger.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100031#define JSON_FAIL_MESSAGE(message) \
32 { \
Christopher Dunn7956ccd2015-01-20 16:18:15 -060033 std::ostringstream oss; oss << message; \
34 assert(false && oss.str().c_str()); \
35 abort(); \
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100036 }
Aaron Jacobs2b853c42011-12-22 03:18:24 +000037
Christopher Dunn7956ccd2015-01-20 16:18:15 -060038
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000039#endif
40
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100041#define JSON_ASSERT_MESSAGE(condition, message) \
42 if (!(condition)) { \
Christopher Dunn7956ccd2015-01-20 16:18:15 -060043 JSON_FAIL_MESSAGE(message); \
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100044 }
Aaron Jacobse3d0eca2011-05-24 01:03:22 +000045
46#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED