JSONDefs.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #ifndef JSONDEFS_H
  2. #define JSONDEFS_H
  3. /*
  4. Defines all of the types of functions and various other definitions
  5. that are used in C applications, this is very useful if dynamically loading
  6. the library instead of linking.
  7. */
  8. #include "../../JSONOptions.h"
  9. #include "JSONDefs/Unknown_C.h"
  10. #include "JSONDefs/GNU_C.h"
  11. #include "JSONDefs/Visual_C.h"
  12. #include "JSONDefs/Strings_Defs.h"
  13. #define __LIBJSON_MAJOR__ 7
  14. #define __LIBJSON_MINOR__ 6
  15. #define __LIBJSON_PATCH__ 1
  16. #define __LIBJSON_VERSION__ (__LIBJSON_MAJOR__ * 10000 + __LIBJSON_MINOR__ * 100 + __LIBJSON_PATCH__)
  17. #define JSON_NULL '\0'
  18. #define JSON_STRING '\1'
  19. #define JSON_NUMBER '\2'
  20. #define JSON_BOOL '\3'
  21. #define JSON_ARRAY '\4'
  22. #define JSON_NODE '\5'
  23. #ifdef __cplusplus
  24. #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL)
  25. #include "JSONAllocator.h"
  26. #else
  27. #define json_allocator std::allocator
  28. #endif
  29. #ifdef JSON_STRING_HEADER
  30. #include JSON_STRING_HEADER
  31. #else
  32. typedef std::basic_string<json_char, std::char_traits<json_char>, json_allocator<json_char> > json_string;
  33. #endif
  34. #endif
  35. #define JSON_MAP(x, y) std::map<x, y, std::less<x>, json_allocator<std::pair<const x, y> > >
  36. #ifdef JSON_NO_EXCEPTIONS
  37. #define json_throw(x)
  38. #define json_try
  39. #define json_catch(exception, code)
  40. #else
  41. #define json_throw(x) throw(x)
  42. #define json_try try
  43. #define json_catch(exception, code) catch(exception){ code }
  44. #endif
  45. #ifdef JSON_STRICT
  46. #ifndef JSON_UNICODE
  47. #error, JSON_UNICODE is required for JSON_STRICT
  48. #endif
  49. #ifdef JSON_COMMENTS
  50. #error, JSON_COMMENTS is required to be off for JSON_STRICT
  51. #endif
  52. #endif
  53. #ifdef JSON_ISO_STRICT
  54. #ifdef JSON_UNICODE
  55. #error, You can not use unicode under ANSI Strict C++
  56. #endif
  57. #else
  58. #ifdef __GNUC__
  59. #ifdef __STRICT_ANSI__
  60. //#warning, Using -ansi GCC option, but JSON_ISO_STRICT not on, turning it on for you
  61. #define JSON_ISO_STRICT
  62. #endif
  63. #endif
  64. #endif
  65. #ifdef JSON_NUMBER_TYPE
  66. typedef JSON_NUMBER_TYPE json_number;
  67. #define JSON_FLOAT_THRESHHOLD 0.00001
  68. #else
  69. #ifdef JSON_LESS_MEMORY
  70. typedef float json_number;
  71. #define JSON_FLOAT_THRESHHOLD 0.00001f
  72. #else
  73. typedef double json_number;
  74. #define JSON_FLOAT_THRESHHOLD 0.00001
  75. #endif
  76. #endif
  77. #ifdef JSON_LESS_MEMORY
  78. /* PACKED and BITS stored in compiler specific headers */
  79. #define START_MEM_SCOPE {
  80. #define END_MEM_SCOPE }
  81. #else
  82. #define PACKED(x)
  83. #define BITS(x)
  84. #define START_MEM_SCOPE
  85. #define END_MEM_SCOPE
  86. #endif
  87. #if defined JSON_DEBUG || defined JSON_SAFE
  88. #ifdef JSON_LIBRARY
  89. typedef void (*json_error_callback_t)(const json_char *);
  90. #else
  91. typedef void (*json_error_callback_t)(const json_string &);
  92. #endif
  93. #endif
  94. #ifdef JSON_INDEX_TYPE
  95. typedef JSON_INDEX_TYPE json_index_t;
  96. #else
  97. typedef unsigned int json_index_t;
  98. #endif
  99. #ifdef JSON_BOOL_TYPE
  100. typedef JSON_BOOL_TYPE json_bool_t;
  101. #else
  102. typedef int json_bool_t;
  103. #endif
  104. #ifdef JSON_INT_TYPE
  105. typedef JSON_INT_TYPE json_int_t;
  106. #else
  107. typedef long json_int_t;
  108. #endif
  109. #define JSONSTREAM_SELF (void*)-1
  110. typedef void (*json_stream_e_callback_t)(void * identifier);
  111. typedef void (*json_mutex_callback_t)(void *);
  112. typedef void (*json_free_t)(void *);
  113. #ifndef JSON_LIBRARY
  114. typedef void * (*json_malloc_t)(size_t);
  115. typedef void * (*json_realloc_t)(void *, size_t);
  116. #else
  117. #define JSONNODE void /* so that JSONNODE* is void* */
  118. typedef JSONNODE** JSONNODE_ITERATOR;
  119. #ifdef JSON_STREAM
  120. #define JSONSTREAM void
  121. typedef void (*json_stream_callback_t)(JSONNODE *, void * identifier);
  122. #endif
  123. typedef void * (*json_malloc_t)(unsigned long);
  124. typedef void * (*json_realloc_t)(void *, unsigned long);
  125. #endif
  126. #ifdef JSON_DEBUG
  127. #ifdef NDEBUG
  128. #ifdef __GNUC__
  129. #warning, Have JSON_DEBUG on in a release build
  130. #else
  131. #error, Have JSON_DEBUG on in a release build
  132. #endif
  133. #endif
  134. /*
  135. #else
  136. #ifndef NDEBUG
  137. #ifdef __GNUC__
  138. #warning, Release build of libjson, but NDEBUG is not on
  139. #else
  140. #error, Release build of libjson, but NDEBUG is not on
  141. #endif
  142. #endif
  143. */
  144. #endif
  145. #ifdef JSON_UNIT_TEST
  146. #define JSON_PRIVATE public:
  147. #define JSON_PROTECTED public:
  148. #else
  149. #define JSON_PRIVATE private:
  150. #define JSON_PROTECTED protected:
  151. #endif
  152. #ifdef JSON_STREAM
  153. #ifndef JSON_READ_PRIORITY
  154. #error, JSON_STREAM also requires JSON_READ_PRIORITY
  155. #endif
  156. #endif
  157. #ifdef JSON_VALIDATE
  158. #ifndef JSON_READ_PRIORITY
  159. #error, JSON_VALIDATE also requires JSON_READ_PRIORITY
  160. #endif
  161. #endif
  162. #define JSON_TEMP_COMMENT_IDENTIFIER JSON_TEXT('#')
  163. #endif