涂 桂旺
/
mbed-os-example-cj
json test
jsoncpp/include/json/assertions.h@0:2ee762ea11b3, 2018-01-26 (annotated)
- Committer:
- tgw
- Date:
- Fri Jan 26 06:05:31 2018 +0000
- Revision:
- 0:2ee762ea11b3
json
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tgw | 0:2ee762ea11b3 | 1 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors |
tgw | 0:2ee762ea11b3 | 2 | // Distributed under MIT license, or public domain if desired and |
tgw | 0:2ee762ea11b3 | 3 | // recognized in your jurisdiction. |
tgw | 0:2ee762ea11b3 | 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE |
tgw | 0:2ee762ea11b3 | 5 | |
tgw | 0:2ee762ea11b3 | 6 | #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED |
tgw | 0:2ee762ea11b3 | 7 | #define CPPTL_JSON_ASSERTIONS_H_INCLUDED |
tgw | 0:2ee762ea11b3 | 8 | |
tgw | 0:2ee762ea11b3 | 9 | #include <stdlib.h> |
tgw | 0:2ee762ea11b3 | 10 | #include <sstream> |
tgw | 0:2ee762ea11b3 | 11 | |
tgw | 0:2ee762ea11b3 | 12 | #if !defined(JSON_IS_AMALGAMATION) |
tgw | 0:2ee762ea11b3 | 13 | #include "config.h" |
tgw | 0:2ee762ea11b3 | 14 | #endif // if !defined(JSON_IS_AMALGAMATION) |
tgw | 0:2ee762ea11b3 | 15 | |
tgw | 0:2ee762ea11b3 | 16 | /** It should not be possible for a maliciously designed file to |
tgw | 0:2ee762ea11b3 | 17 | * cause an abort() or seg-fault, so these macros are used only |
tgw | 0:2ee762ea11b3 | 18 | * for pre-condition violations and internal logic errors. |
tgw | 0:2ee762ea11b3 | 19 | */ |
tgw | 0:2ee762ea11b3 | 20 | #if JSON_USE_EXCEPTION |
tgw | 0:2ee762ea11b3 | 21 | |
tgw | 0:2ee762ea11b3 | 22 | // @todo <= add detail about condition in exception |
tgw | 0:2ee762ea11b3 | 23 | # define JSON_ASSERT(condition) \ |
tgw | 0:2ee762ea11b3 | 24 | {if (!(condition)) {Json::throwLogicError( "assert json failed" );}} |
tgw | 0:2ee762ea11b3 | 25 | |
tgw | 0:2ee762ea11b3 | 26 | # define JSON_FAIL_MESSAGE(message) \ |
tgw | 0:2ee762ea11b3 | 27 | { \ |
tgw | 0:2ee762ea11b3 | 28 | JSONCPP_OSTRINGSTREAM oss; oss << message; \ |
tgw | 0:2ee762ea11b3 | 29 | Json::throwLogicError(oss.str()); \ |
tgw | 0:2ee762ea11b3 | 30 | abort(); \ |
tgw | 0:2ee762ea11b3 | 31 | } |
tgw | 0:2ee762ea11b3 | 32 | |
tgw | 0:2ee762ea11b3 | 33 | #else // JSON_USE_EXCEPTION |
tgw | 0:2ee762ea11b3 | 34 | |
tgw | 0:2ee762ea11b3 | 35 | # define JSON_ASSERT(condition) assert(condition) |
tgw | 0:2ee762ea11b3 | 36 | |
tgw | 0:2ee762ea11b3 | 37 | // The call to assert() will show the failure message in debug builds. In |
tgw | 0:2ee762ea11b3 | 38 | // release builds we abort, for a core-dump or debugger. |
tgw | 0:2ee762ea11b3 | 39 | # define JSON_FAIL_MESSAGE(message) \ |
tgw | 0:2ee762ea11b3 | 40 | { \ |
tgw | 0:2ee762ea11b3 | 41 | JSONCPP_OSTRINGSTREAM oss; oss << message; \ |
tgw | 0:2ee762ea11b3 | 42 | assert(false && oss.str().c_str()); \ |
tgw | 0:2ee762ea11b3 | 43 | abort(); \ |
tgw | 0:2ee762ea11b3 | 44 | } |
tgw | 0:2ee762ea11b3 | 45 | |
tgw | 0:2ee762ea11b3 | 46 | |
tgw | 0:2ee762ea11b3 | 47 | #endif |
tgw | 0:2ee762ea11b3 | 48 | |
tgw | 0:2ee762ea11b3 | 49 | #define JSON_ASSERT_MESSAGE(condition, message) \ |
tgw | 0:2ee762ea11b3 | 50 | if (!(condition)) { \ |
tgw | 0:2ee762ea11b3 | 51 | JSON_FAIL_MESSAGE(message); \ |
tgw | 0:2ee762ea11b3 | 52 | } |
tgw | 0:2ee762ea11b3 | 53 | |
tgw | 0:2ee762ea11b3 | 54 | #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED |