Jamoma API  0.6.0.a19
JSONGlobals.h
1 #ifndef JSON_GLOBALS_H
2 #define JSON_GLOBALS_H
3 
4 #include "JSONDefs.h"
5 
6 /*
7  * The use of singletons for globals makes globals not
8  * actually be initialized until it is first needed, this
9  * makes the library faster to load, and have a smaller
10  * memory footprint
11  */
12 
13 #define json_global_decl(TYPE, NAME, VALUE) \
14 class jsonSingleton ## NAME { \
15 public: \
16  inline static TYPE & getValue() json_nothrow { \
17  static jsonSingleton ## NAME single; \
18  return single.val; \
19  } \
20 protected: \
21  inline jsonSingleton ## NAME() json_nothrow : val(VALUE) {} \
22  TYPE val; \
23 }
24 
25 #define json_global_decl_strconfig(TYPE, NAME, VALUE) \
26 class jsonSingleton ## NAME { \
27 public: \
28  inline static TYPE & getValue() json_nothrow { \
29  static jsonSingleton ## NAME single; \
30  return single.val; \
31  } \
32 protected: \
33  inline jsonSingleton ## NAME() json_nothrow { \
34  const std::string tmp = std::string(VALUE); \
35  val = json_string(tmp.begin(), tmp.end()); \
36  } \
37  TYPE val; \
38 }
39 
40 #define json_global(NAME) jsonSingleton ## NAME::getValue()
41 
42 #include <string>
43 json_global_decl(json_string, EMPTY_JSON_STRING, );
44 json_global_decl(std::string, EMPTY_STD_STRING, );
45 
46 json_global_decl(json_string, CONST_TRUE, JSON_TEXT("true"));
47 json_global_decl(json_string, CONST_FALSE, JSON_TEXT("false"));
48 json_global_decl(json_string, CONST_NULL, JSON_TEXT("null"));
49 
50 #ifndef JSON_NEWLINE
51  json_global_decl(json_string, NEW_LINE, JSON_TEXT("\n"));
52 #else
53  json_global_decl_strconfig(json_string, NEW_LINE, JSON_NEWLINE);
54 #endif
55 
56 #ifdef JSON_WRITE_BASH_COMMENTS
57  json_global_decl(json_string, SINGLELINE_COMMENT, JSON_TEXT("#"));
58 #else
59  json_global_decl(json_string, SINGLELINE_COMMENT, JSON_TEXT("//"));
60 #endif
61 
62 #ifdef JSON_INDENT
63  json_global_decl_strconfig(json_string, INDENT, JSON_INDENT);
64 #endif
65 
66 #ifdef JSON_MUTEX_CALLBACKS
67  #include <map>
68  json_global_decl(JSON_MAP(void *, unsigned int), MUTEX_MANAGER, );
69  json_global_decl(JSON_MAP(int, JSON_MAP(void *, unsigned int) ), THREAD_LOCKS, );
70 #endif
71 
72 #ifdef JSON_LIBRARY
73  #ifdef JSON_MEMORY_MANAGE
74  #include "JSONMemory.h"
75  json_global_decl(auto_expand, STRING_HANDLER, );
76  json_global_decl(auto_expand_node, NODE_HANDLER, );
77  #ifdef JSON_STREAM
78  json_global_decl(auto_expand_stream, STREAM_HANDLER, );
79  #endif
80  #endif
81 #endif
82 
83 //These are common error responses
84 json_global_decl(json_string, ERROR_TOO_LONG, JSON_TEXT("Exceeding JSON_SECURITY_MAX_STRING_LENGTH"));
85 json_global_decl(json_string, ERROR_UNKNOWN_LITERAL, JSON_TEXT("Unknown JSON literal: "));
86 json_global_decl(json_string, ERROR_NON_CONTAINER, JSON_TEXT("Calling container method on non-container: "));
87 json_global_decl(json_string, ERROR_NON_ITERATABLE, JSON_TEXT("Calling iterator method on non-iteratable: "));
88 json_global_decl(json_string, ERROR_NULL_IN_CHILDREN, JSON_TEXT("a null pointer within the children"));
89 json_global_decl(json_string, ERROR_UNDEFINED, JSON_TEXT("Undefined results: "));
90 json_global_decl(json_string, ERROR_LOWER_RANGE, JSON_TEXT(" is outside the lower range of "));
91 json_global_decl(json_string, ERROR_UPPER_RANGE, JSON_TEXT(" is outside the upper range of "));
92 json_global_decl(json_string, ERROR_NOT_BASE64, JSON_TEXT("Not base64"));
93 json_global_decl(json_string, ERROR_OUT_OF_MEMORY, JSON_TEXT("Out of memory"));
94 
95 #endif