JsonCpp project page | Classes | Namespace | JsonCpp home page

assertions.h
Go to the documentation of this file.
1 // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
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
9 #include <cstdlib>
10 #include <sstream>
11
12 #if !defined(JSON_IS_AMALGAMATION)
13 #include "config.h"
14 #endif // if !defined(JSON_IS_AMALGAMATION)
15
20 #if JSON_USE_EXCEPTION
21
22 // @todo <= add detail about condition in exception
23 #define JSON_ASSERT(condition) \
24 { \
25 if (!(condition)) { \
26 Json::throwLogicError("assert json failed"); \
27 } \
28 }
29
30 #define JSON_FAIL_MESSAGE(message) \
31 { \
32 OStringStream oss; \
33 oss << message; \
34 Json::throwLogicError(oss.str()); \
35 abort(); \
36 }
37
38 #else // JSON_USE_EXCEPTION
39
40 #define JSON_ASSERT(condition) assert(condition)
41
42 // The call to assert() will show the failure message in debug builds. In
43 // release builds we abort, for a core-dump or debugger.
44 #define JSON_FAIL_MESSAGE(message) \
45 { \
46 OStringStream oss; \
47 oss << message; \
48 assert(false && oss.str().c_str()); \
49 abort(); \
50 }
51
52 #endif
53
54 #define JSON_ASSERT_MESSAGE(condition, message) \
55 if (!(condition)) { \
56 JSON_FAIL_MESSAGE(message); \
57 }
58
59 #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
config.h