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 <stdlib.h>
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  {if (!(condition)) {Json::throwLogicError( "assert json failed" );}}
25 
26 # define JSON_FAIL_MESSAGE(message) \
27  { \
28  JSONCPP_OSTRINGSTREAM oss; oss << message; \
29  Json::throwLogicError(oss.str()); \
30  abort(); \
31  }
32 
33 #else // JSON_USE_EXCEPTION
34 
35 # define JSON_ASSERT(condition) assert(condition)
36 
37 // The call to assert() will show the failure message in debug builds. In
38 // release builds we abort, for a core-dump or debugger.
39 # define JSON_FAIL_MESSAGE(message) \
40  { \
41  JSONCPP_OSTRINGSTREAM oss; oss << message; \
42  assert(false && oss.str().c_str()); \
43  abort(); \
44  }
45 
46 
47 #endif
48 
49 #define JSON_ASSERT_MESSAGE(condition, message) \
50  if (!(condition)) { \
51  JSON_FAIL_MESSAGE(message); \
52  }
53 
54 #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED