Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved the HTTP examples to contrib/http_examples; moved libs/network/…

…doc to doc.
  • Loading branch information...
commit 0e7cd26247fd90c8cd9f4ade139606222e89c97a 1 parent 5b571ad
@glynos glynos authored
Showing with 2,659 additions and 15,230 deletions.
  1. +4 −1 CMakeLists.txt
  2. +40 −34 {libs/network/example → contrib/http_examples}/CMakeLists.txt
  3. 0  {libs/network/example → contrib/http_examples}/Jamfile.v2
  4. 0  {libs/network/example → contrib/http_examples}/atom/atom.cpp
  5. 0  {libs/network/example → contrib/http_examples}/atom/atom.hpp
  6. 0  {libs/network/example → contrib/http_examples}/atom/main.cpp
  7. 0  {libs/network/example → contrib/http_examples}/http/fileserver.cpp
  8. 0  {libs/network/example → contrib/http_examples}/http/hello_world_client.cpp
  9. 0  {libs/network/example → contrib/http_examples}/http/hello_world_server.cpp
  10. 0  {libs/network/example → contrib/http_examples}/http/one_liner.cpp
  11. 0  {libs/network/example → contrib/http_examples}/rapidxml/license.txt
  12. 0  {libs/network/example → contrib/http_examples}/rapidxml/manual.html
  13. 0  {libs/network/example → contrib/http_examples}/rapidxml/rapidxml.hpp
  14. 0  {libs/network/example → contrib/http_examples}/rapidxml/rapidxml_iterators.hpp
  15. 0  {libs/network/example → contrib/http_examples}/rapidxml/rapidxml_print.hpp
  16. 0  {libs/network/example → contrib/http_examples}/rapidxml/rapidxml_utils.hpp
  17. 0  {libs/network/example → contrib/http_examples}/rss/main.cpp
  18. 0  {libs/network/example → contrib/http_examples}/rss/rss.cpp
  19. 0  {libs/network/example → contrib/http_examples}/rss/rss.hpp
  20. 0  {libs/network/example → contrib/http_examples}/simple_wget.cpp
  21. +806 −806 {libs/network/example → contrib/http_examples}/twitter/rapidjson/document.h
  22. +46 −46 {libs/network/example → contrib/http_examples}/twitter/rapidjson/filestream.h
  23. +54 −54 {libs/network/example → contrib/http_examples}/twitter/rapidjson/internal/pow10.h
  24. +82 −82 {libs/network/example → contrib/http_examples}/twitter/rapidjson/internal/stack.h
  25. +24 −24 {libs/network/example → contrib/http_examples}/twitter/rapidjson/internal/strfunc.h
  26. +152 −152 {libs/network/example → contrib/http_examples}/twitter/rapidjson/prettywriter.h
  27. +512 −512 {libs/network/example → contrib/http_examples}/twitter/rapidjson/rapidjson.h
  28. +664 −664 {libs/network/example → contrib/http_examples}/twitter/rapidjson/reader.h
  29. +49 −49 {libs/network/example → contrib/http_examples}/twitter/rapidjson/stringbuffer.h
  30. +224 −224 {libs/network/example → contrib/http_examples}/twitter/rapidjson/writer.h
  31. 0  {libs/network/example → contrib/http_examples}/twitter/search.cpp
  32. 0  {libs/network → }/doc/.gitignore
  33. 0  {libs/network → }/doc/_ext/adjusts.py
  34. 0  {libs/network/doc/html → doc}/_static/Button-Info-icon.png
  35. 0  {libs/network/doc/html → doc}/_static/Button-Warning-icon.png
  36. 0  {libs/network/doc/html → doc}/_static/boost.png
  37. 0  {libs/network/doc/html → doc}/_static/ftp_uri.png
  38. 0  {libs/network/doc/html → doc}/_static/http_uri.png
  39. 0  {libs/network/doc/html → doc}/_static/mailto_uri.png
  40. 0  {libs/network/doc/html → doc}/_static/orange-background.jpg
  41. 0  {libs/network/doc/html → doc}/_static/pygments.css
  42. 0  {libs/network/doc/html → doc}/_static/reset-fonts-grids.css
  43. 0  {libs/network/doc/html → doc}/_static/uri.svg
  44. 0  {libs/network → }/doc/_templates/genindex.html
  45. 0  {libs/network → }/doc/_templates/layout.html
  46. 0  {libs/network → }/doc/_templates/modindex.html
  47. 0  {libs/network → }/doc/_templates/search.html
  48. 0  {libs/network → }/doc/conf.py
  49. 0  {libs/network → }/doc/contents.rst
  50. 0  {libs/network → }/doc/examples.rst
  51. 0  {libs/network → }/doc/examples/http/atom_reader.rst
  52. 0  {libs/network → }/doc/examples/http/hello_world_client.rst
  53. 0  {libs/network → }/doc/examples/http/hello_world_server.rst
  54. 0  {libs/network → }/doc/examples/http/http_client.rst
  55. 0  {libs/network → }/doc/examples/http/simple_wget.rst
  56. 0  {libs/network → }/doc/examples/http/twitter_search.rst
  57. 0  {libs/network → }/doc/getting_started.rst
  58. 0  {libs/network → }/doc/history.rst
  59. 0  {libs/network → }/doc/html/.buildinfo
  60. 0  {libs/network → }/doc/html/_images/boost.png
  61. 0  {libs/network → }/doc/html/_images/ftp_uri.png
  62. 0  {libs/network → }/doc/html/_images/http_uri.png
  63. 0  {libs/network → }/doc/html/_images/mailto_uri.png
  64. 0  {libs/network → }/doc/html/_sources/contents.txt
  65. 0  {libs/network → }/doc/html/_sources/examples.txt
  66. 0  {libs/network → }/doc/html/_sources/examples/http/atom_reader.txt
  67. 0  {libs/network → }/doc/html/_sources/examples/http/hello_world_client.txt
  68. 0  {libs/network → }/doc/html/_sources/examples/http/hello_world_server.txt
  69. 0  {libs/network → }/doc/html/_sources/examples/http/http_client.txt
  70. 0  {libs/network → }/doc/html/_sources/examples/http/simple_wget.txt
  71. 0  {libs/network → }/doc/html/_sources/examples/http/twitter_search.txt
  72. 0  {libs/network → }/doc/html/_sources/getting_started.txt
  73. 0  {libs/network → }/doc/html/_sources/history.txt
  74. 0  {libs/network → }/doc/html/_sources/in_depth.txt
  75. 0  {libs/network → }/doc/html/_sources/in_depth/http.txt
  76. 0  {libs/network → }/doc/html/_sources/in_depth/http_client_tags.txt
  77. 0  {libs/network → }/doc/html/_sources/in_depth/message.txt
  78. 0  {libs/network → }/doc/html/_sources/in_depth/uri.txt
  79. 0  {libs/network → }/doc/html/_sources/index.txt
  80. 0  {libs/network → }/doc/html/_sources/reference.txt
  81. 0  {libs/network → }/doc/html/_sources/reference/http_client.txt
  82. 0  {libs/network → }/doc/html/_sources/reference/http_request.txt
  83. 0  {libs/network → }/doc/html/_sources/reference/http_response.txt
  84. 0  {libs/network → }/doc/html/_sources/reference/http_server.txt
  85. 0  {libs/network → }/doc/html/_sources/references.txt
  86. 0  {libs/network → }/doc/html/_sources/techniques.txt
  87. 0  {libs/network → }/doc/html/_sources/techniques/directives.txt
  88. 0  {libs/network → }/doc/html/_sources/techniques/polymorphism.txt
  89. 0  {libs/network → }/doc/html/_sources/techniques/tag_metafunctions.txt
  90. 0  {libs/network → }/doc/html/_sources/whats_new.txt
  91. 0  {libs/network/doc → doc/html}/_static/Button-Info-icon.png
  92. 0  {libs/network/doc → doc/html}/_static/Button-Warning-icon.png
  93. 0  {libs/network → }/doc/html/_static/basic.css
  94. 0  {libs/network/doc → doc/html}/_static/boost.png
  95. 0  {libs/network → }/doc/html/_static/default.css
  96. 0  {libs/network → }/doc/html/_static/doctools.js
  97. 0  {libs/network → }/doc/html/_static/file.png
  98. 0  {libs/network/doc → doc/html}/_static/ftp_uri.png
  99. 0  {libs/network/doc → doc/html}/_static/http_uri.png
  100. 0  {libs/network → }/doc/html/_static/jquery.js
  101. 0  {libs/network/doc → doc/html}/_static/mailto_uri.png
  102. 0  {libs/network → }/doc/html/_static/minus.png
  103. 0  {libs/network/doc → doc/html}/_static/orange-background.jpg
  104. 0  {libs/network → }/doc/html/_static/plus.png
  105. 0  {libs/network/doc → doc/html}/_static/pygments.css
  106. 0  {libs/network/doc → doc/html}/_static/reset-fonts-grids.css
  107. 0  {libs/network → }/doc/html/_static/searchtools.js
  108. 0  {libs/network → }/doc/html/_static/sidebar.js
  109. 0  {libs/network → }/doc/html/_static/underscore.js
  110. 0  {libs/network/doc → doc/html}/_static/uri.svg
  111. 0  {libs/network → }/doc/html/contents.html
  112. 0  {libs/network → }/doc/html/examples.html
  113. 0  {libs/network → }/doc/html/examples/http/atom_reader.html
  114. 0  {libs/network → }/doc/html/examples/http/hello_world_client.html
  115. 0  {libs/network → }/doc/html/examples/http/hello_world_server.html
  116. 0  {libs/network → }/doc/html/examples/http/http_client.html
  117. 0  {libs/network → }/doc/html/examples/http/simple_wget.html
  118. 0  {libs/network → }/doc/html/examples/http/twitter_search.html
  119. 0  {libs/network → }/doc/html/genindex.html
  120. 0  {libs/network → }/doc/html/getting_started.html
  121. 0  {libs/network → }/doc/html/history.html
  122. 0  {libs/network → }/doc/html/in_depth.html
  123. 0  {libs/network → }/doc/html/in_depth/http.html
  124. 0  {libs/network → }/doc/html/in_depth/http_client_tags.html
  125. 0  {libs/network → }/doc/html/in_depth/message.html
  126. 0  {libs/network → }/doc/html/in_depth/uri.html
  127. 0  {libs/network → }/doc/html/index.html
  128. 0  {libs/network → }/doc/html/objects.inv
  129. 0  {libs/network → }/doc/html/reference.html
  130. 0  {libs/network → }/doc/html/reference/http_client.html
  131. 0  {libs/network → }/doc/html/reference/http_request.html
  132. 0  {libs/network → }/doc/html/reference/http_response.html
  133. 0  {libs/network → }/doc/html/reference/http_server.html
  134. 0  {libs/network → }/doc/html/references.html
  135. 0  {libs/network → }/doc/html/search.html
  136. 0  {libs/network → }/doc/html/searchindex.js
  137. 0  {libs/network → }/doc/html/techniques.html
  138. 0  {libs/network → }/doc/html/techniques/directives.html
  139. 0  {libs/network → }/doc/html/techniques/polymorphism.html
  140. 0  {libs/network → }/doc/html/techniques/tag_metafunctions.html
  141. 0  {libs/network → }/doc/html/whats_new.html
  142. 0  {libs/network → }/doc/in_depth.rst
  143. 0  {libs/network → }/doc/in_depth/http.rst
  144. 0  {libs/network → }/doc/in_depth/http_client_tags.rst
  145. 0  {libs/network → }/doc/in_depth/message.rst
  146. 0  {libs/network → }/doc/in_depth/uri.rst
  147. 0  {libs/network → }/doc/index.rst
  148. 0  {libs/network → }/doc/make.bat
  149. 0  {libs/network → }/doc/reference.rst
  150. 0  {libs/network → }/doc/reference/http_client.rst
  151. 0  {libs/network → }/doc/reference/http_request.rst
  152. 0  {libs/network → }/doc/reference/http_response.rst
  153. 0  {libs/network → }/doc/reference/http_server.rst
  154. 0  {libs/network → }/doc/references.rst
  155. 0  {libs/network → }/doc/techniques.rst
  156. 0  {libs/network → }/doc/techniques/directives.rst
  157. 0  {libs/network → }/doc/techniques/polymorphism.rst
  158. 0  {libs/network → }/doc/techniques/tag_metafunctions.rst
  159. 0  {libs/network → }/doc/whats_new.rst
  160. +1 −1  http/src/CMakeLists.txt
  161. +1 −2  http/test/CMakeLists.txt
  162. +0 −19 include/network.hpp
  163. +0 −40 include/network/constants.hpp
  164. +0 −128 include/network/constants.ipp
  165. +0 −16 include/network/http/client.hpp
  166. +0 −11 include/network/http/errors.hpp
  167. +0 −11 include/network/http/request.hpp
  168. +0 −11 include/network/http/response.hpp
  169. +0 −21 include/network/include/http/client.hpp
  170. +0 −17 include/network/include/http/server.hpp
  171. +0 −15 include/network/include/message.hpp
  172. +0 −16 include/network/protocol.hpp
  173. +0 −19 include/network/protocol/http.hpp
  174. +0 −163 include/network/protocol/http/algorithms/linearize.hpp
  175. +0 −46 include/network/protocol/http/client.hpp
  176. +0 −30 include/network/protocol/http/client.ipp
  177. +0 −45 include/network/protocol/http/client/base.hpp
  178. +0 −131 include/network/protocol/http/client/base.ipp
  179. +0 −40 include/network/protocol/http/client/client_connection.hpp
  180. +0 −33 include/network/protocol/http/client/client_connection.ipp
  181. +0 −54 include/network/protocol/http/client/connection/async_normal.hpp
  182. +0 −887 include/network/protocol/http/client/connection/async_normal.ipp
  183. +0 −375 include/network/protocol/http/client/connection/async_protocol_handler.hpp
  184. +0 −38 include/network/protocol/http/client/connection/async_resolver.hpp
  185. +0 −135 include/network/protocol/http/client/connection/async_resolver.ipp
  186. +0 −31 include/network/protocol/http/client/connection/connection_delegate.hpp
  187. +0 −39 include/network/protocol/http/client/connection/connection_delegate_factory.hpp
  188. +0 −53 include/network/protocol/http/client/connection/connection_delegate_factory.ipp
  189. +0 −34 include/network/protocol/http/client/connection/connection_factory.hpp
  190. +0 −19 include/network/protocol/http/client/connection/connection_factory.ipp
  191. +0 −47 include/network/protocol/http/client/connection/normal_delegate.hpp
  192. +0 −46 include/network/protocol/http/client/connection/normal_delegate.ipp
  193. +0 −33 include/network/protocol/http/client/connection/resolver_delegate.hpp
  194. +0 −21 include/network/protocol/http/client/connection/resolver_delegate.ipp
  195. +0 −30 include/network/protocol/http/client/connection/resolver_delegate_factory.hpp
  196. +0 −35 include/network/protocol/http/client/connection/resolver_delegate_factory.ipp
  197. +0 −37 include/network/protocol/http/client/connection/simple_connection_factory.hpp
  198. +0 −88 include/network/protocol/http/client/connection/simple_connection_factory.ipp
  199. +0 −54 include/network/protocol/http/client/connection/ssl_delegate.hpp
  200. +0 −102 include/network/protocol/http/client/connection/ssl_delegate.ipp
  201. +0 −249 include/network/protocol/http/client/connection/sync_base.hpp
  202. +0 −86 include/network/protocol/http/client/connection/sync_normal.hpp
  203. +0 −106 include/network/protocol/http/client/connection/sync_ssl.hpp
  204. +0 −37 include/network/protocol/http/client/connection_manager.hpp
  205. +0 −23 include/network/protocol/http/client/connection_manager.ipp
  206. +0 −51 include/network/protocol/http/client/facade.hpp
  207. +0 −117 include/network/protocol/http/client/facade.ipp
  208. +0 −19 include/network/protocol/http/client/macros.hpp
  209. +0 −149 include/network/protocol/http/client/options.hpp
  210. +0 −285 include/network/protocol/http/client/options.ipp
  211. +0 −30 include/network/protocol/http/client/parameters.hpp
  212. +0 −85 include/network/protocol/http/client/pimpl.hpp
  213. +0 −88 include/network/protocol/http/client/simple_connection_manager.hpp
  214. +0 −90 include/network/protocol/http/client/simple_connection_manager.ipp
  215. +0 −74 include/network/protocol/http/client/sync_impl.hpp
  216. +0 −25 include/network/protocol/http/client_fwd.hpp
  217. +0 −26 include/network/protocol/http/errors.hpp
  218. +0 −37 include/network/protocol/http/impl/access.hpp
  219. +0 −44 include/network/protocol/http/impl/access.ipp
  220. +0 −268 include/network/protocol/http/impl/message.ipp
  221. +0 −780 include/network/protocol/http/impl/parser.ipp
  222. +0 −255 include/network/protocol/http/impl/request.hpp
  223. +0 −330 include/network/protocol/http/impl/request_parser.ipp
  224. +0 −320 include/network/protocol/http/impl/response.ipp
  225. +0 −163 include/network/protocol/http/message/async_message.hpp
  226. +0 −16 include/network/protocol/http/message/directives.hpp
  227. +0 −28 include/network/protocol/http/message/directives/major_version.hpp
  228. +0 −18 include/network/protocol/http/message/directives/method.hpp
  229. +0 −39 include/network/protocol/http/message/directives/minor_version.hpp
  230. +0 −34 include/network/protocol/http/message/directives/status.hpp
  231. +0 −21 include/network/protocol/http/message/directives/status_message.hpp
  232. +0 −21 include/network/protocol/http/message/directives/uri.hpp
  233. +0 −21 include/network/protocol/http/message/directives/version.hpp
  234. +0 −61 include/network/protocol/http/message/header.hpp
  235. +0 −35 include/network/protocol/http/message/header/name.hpp
  236. +0 −37 include/network/protocol/http/message/header/value.hpp
  237. +0 −36 include/network/protocol/http/message/header_concept.hpp
  238. +0 −16 include/network/protocol/http/message/modifiers.hpp
  239. +0 −29 include/network/protocol/http/message/modifiers/major_version.hpp
  240. +0 −21 include/network/protocol/http/message/modifiers/method.hpp
  241. +0 −29 include/network/protocol/http/message/modifiers/minor_version.hpp
  242. +0 −22 include/network/protocol/http/message/modifiers/status.hpp
  243. +0 −23 include/network/protocol/http/message/modifiers/status_message.hpp
  244. +0 −26 include/network/protocol/http/message/modifiers/uri.hpp
  245. +0 −23 include/network/protocol/http/message/modifiers/version.hpp
  246. +0 −23 include/network/protocol/http/message/wrappers.hpp
  247. +0 −31 include/network/protocol/http/message/wrappers/anchor.hpp
  248. +0 −29 include/network/protocol/http/message/wrappers/anchor.ipp
  249. +0 −73 include/network/protocol/http/message/wrappers/helper.hpp
  250. +0 −31 include/network/protocol/http/message/wrappers/host.hpp
  251. +0 −27 include/network/protocol/http/message/wrappers/host.ipp
  252. +0 −39 include/network/protocol/http/message/wrappers/major_version.hpp
  253. +0 −30 include/network/protocol/http/message/wrappers/method.hpp
  254. +0 −39 include/network/protocol/http/message/wrappers/minor_version.hpp
  255. +0 −31 include/network/protocol/http/message/wrappers/path.hpp
  256. +0 −27 include/network/protocol/http/message/wrappers/path.ipp
  257. +0 −32 include/network/protocol/http/message/wrappers/port.hpp
  258. +0 −43 include/network/protocol/http/message/wrappers/port.ipp
  259. +0 −31 include/network/protocol/http/message/wrappers/protocol.hpp
  260. +0 −31 include/network/protocol/http/message/wrappers/query.hpp
  261. +0 −27 include/network/protocol/http/message/wrappers/query.ipp
  262. +0 −43 include/network/protocol/http/message/wrappers/ready.hpp
  263. +0 −31 include/network/protocol/http/message/wrappers/status.hpp
  264. +0 −27 include/network/protocol/http/message/wrappers/status.ipp
  265. +0 −39 include/network/protocol/http/message/wrappers/status_message.hpp
  266. +0 −29 include/network/protocol/http/message/wrappers/status_message.ipp
  267. +0 −34 include/network/protocol/http/message/wrappers/uri.hpp
  268. +0 −35 include/network/protocol/http/message/wrappers/uri.ipp
  269. +0 −38 include/network/protocol/http/message/wrappers/version.hpp
  270. +0 −29 include/network/protocol/http/message/wrappers/version.ipp
  271. +0 −312 include/network/protocol/http/parser.hpp
  272. +0 −285 include/network/protocol/http/parser/incremental.hpp
  273. +0 −76 include/network/protocol/http/policies/async_connection.hpp
  274. +0 −170 include/network/protocol/http/policies/async_connection.ipp
  275. +0 −13 include/network/protocol/http/request.hpp
  276. +0 −111 include/network/protocol/http/request/request.hpp
  277. +0 −313 include/network/protocol/http/request/request.ipp
  278. +0 −65 include/network/protocol/http/request/request_base.hpp
  279. +0 −209 include/network/protocol/http/request/request_base.ipp
  280. +0 −104 include/network/protocol/http/request/request_concept.hpp
  281. +0 −105 include/network/protocol/http/request_parser.hpp
  282. +0 −31 include/network/protocol/http/response.hpp
  283. +0 −96 include/network/protocol/http/response/response.hpp
  284. +0 −436 include/network/protocol/http/response/response.ipp
  285. +0 −28 include/network/protocol/http/response/response_base.hpp
  286. +0 −21 include/network/protocol/http/response/response_base.ipp
  287. +0 −56 include/network/protocol/http/response/response_concept.hpp
  288. +0 −76 include/network/protocol/http/server.hpp
  289. +0 −58 include/network/protocol/http/server/async_impl.hpp
  290. +0 −153 include/network/protocol/http/server/async_impl.ipp
  291. +0 −172 include/network/protocol/http/server/async_server.hpp
  292. +0 −648 include/network/protocol/http/server/connection/async.hpp
  293. +0 −340 include/network/protocol/http/server/connection/sync.hpp
  294. +0 −58 include/network/protocol/http/server/impl/parsers.ipp
  295. +0 −25 include/network/protocol/http/server/impl/socket_options_setter.hpp
  296. +0 −53 include/network/protocol/http/server/impl/socket_options_setter.ipp
  297. +0 −82 include/network/protocol/http/server/options.hpp
  298. +0 −290 include/network/protocol/http/server/options.ipp
  299. +0 −32 include/network/protocol/http/server/parameters.hpp
  300. +0 −49 include/network/protocol/http/server/request.hpp
Sorry, we could not display the entire diff because too many files (319) changed.
View
5 CMakeLists.txt
@@ -112,4 +112,7 @@ add_subdirectory(message)
add_subdirectory(logging)
add_subdirectory(concurrency)
add_subdirectory(http)
-add_subdirectory(mime)
+#add_subdirectory(mime)
+if(CPP-NETLIB_BUILD_EXAMPLES)
+ add_subdirectory(contrib/http_examples)
+endif()
View
74 libs/network/example/CMakeLists.txt → contrib/http_examples/CMakeLists.txt
@@ -3,40 +3,42 @@
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
-include_directories(${CPP-NETLIB_SOURCE_DIR}/include)
-include_directories(${CPP-NETLIB_SOURCE_DIR})
+include_directories(
+ ${CPP-NETLIB_SOURCE_DIR}/uri/src
+ ${CPP-NETLIB_SOURCE_DIR}/message/src
+ ${CPP-NETLIB_SOURCE_DIR}/logging/src
+ ${CPP-NETLIB_SOURCE_DIR}/http/src
+ ${CPP-NETLIB_SOURCE_DIR})
if (OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIR})
endif (OPENSSL_FOUND)
-add_executable(uri_builder uri_builder.cpp)
+if( NOT CPP-NETLIB_DISABLE_LOGGING )
+ set( CPP-NETLIB_LOGGING_LIB cppnetlib-logging )
+endif()
+
add_executable(simple_wget simple_wget.cpp)
add_executable(atom_reader atom/atom.cpp atom/main.cpp)
add_executable(rss_reader rss/rss.cpp rss/main.cpp)
add_executable(twitter_search twitter/search.cpp)
-add_executable(hello_world_server http/hello_world_server.cpp)
+#add_executable(hello_world_server http/hello_world_server.cpp)
add_executable(hello_world_client http/hello_world_client.cpp)
#if (UNIX)
# add_executable(fileserver http/fileserver.cpp)
#endif (UNIX)
set(BOOST_CLIENT_LIBS
- ${Boost_DATE_TIME_LIBRARY}
- ${Boost_SYSTEM_LIBRARY}
- ${Boost_FILESYSTEM_LIBRARY}
- ${Boost_PROGRAM_OPTIONS_LIBRARY}
- ${Boost_REGEX_LIBRARY}
- )
+ ${Boost_DATE_TIME_LIBRARY}
+ ${Boost_SYSTEM_LIBRARY}
+ ${Boost_FILESYSTEM_LIBRARY}
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${Boost_REGEX_LIBRARY}
+ )
set(BOOST_SERVER_LIBS
- ${Boost_DATE_TIME_LIBRARY}
- ${Boost_SYSTEM_LIBRARY}
- ${Boost_FILESYSTEM_LIBRARY}
- ${Boost_PROGRAM_OPTIONS_LIBRARY}
- )
-
-target_link_libraries(uri_builder
- ${BOOST_CLIENT_LIBS}
- ${CMAKE_THREAD_LIBS_INIT}
- cppnetlib-uri)
+ ${Boost_DATE_TIME_LIBRARY}
+ ${Boost_SYSTEM_LIBRARY}
+ ${Boost_FILESYSTEM_LIBRARY}
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ )
target_link_libraries(simple_wget
${BOOST_CLIENT_LIBS}
@@ -49,7 +51,8 @@ target_link_libraries(simple_wget
cppnetlib-http-message
cppnetlib-constants
cppnetlib-http-client
- cppnetlib-http-client-connections)
+ cppnetlib-http-client-connections
+ ${CPP-NETLIB_LOGGING_LIB})
target_link_libraries(atom_reader
${BOOST_CLIENT_LIBS}
@@ -62,7 +65,8 @@ target_link_libraries(atom_reader
cppnetlib-http-message-wrappers
cppnetlib-constants
cppnetlib-http-client
- cppnetlib-http-client-connections)
+ cppnetlib-http-client-connections
+ ${CPP-NETLIB_LOGGING_LIB})
target_link_libraries(rss_reader
${BOOST_CLIENT_LIBS}
@@ -74,7 +78,8 @@ target_link_libraries(rss_reader
cppnetlib-http-message
cppnetlib-constants
cppnetlib-http-client
- cppnetlib-http-client-connections)
+ cppnetlib-http-client-connections
+ ${CPP-NETLIB_LOGGING_LIB})
target_link_libraries(twitter_search
${BOOST_CLIENT_LIBS}
@@ -87,13 +92,15 @@ target_link_libraries(twitter_search
cppnetlib-http-message
cppnetlib-constants
cppnetlib-http-client
- cppnetlib-http-client-connections)
+ cppnetlib-http-client-connections
+ ${CPP-NETLIB_LOGGING_LIB})
-target_link_libraries(hello_world_server
- ${BOOST_SERVER_LIBS}
- ${CMAKE_THREAD_LIBS_INIT}
- cppnetlib-http-server-parsers
- cppnetlib-http-server)
+#target_link_libraries(hello_world_server
+# ${BOOST_SERVER_LIBS}
+# ${CMAKE_THREAD_LIBS_INIT}
+# cppnetlib-http-server-parsers
+# cppnetlib-http-server
+# ${CPP-NETLIB_LOGGING_LIB})
target_link_libraries(hello_world_client
${BOOST_CLIENT_LIBS}
@@ -106,15 +113,15 @@ target_link_libraries(hello_world_client
cppnetlib-http-message
cppnetlib-constants
cppnetlib-http-client
- cppnetlib-http-client-connections)
+ cppnetlib-http-client-connections
+ ${CPP-NETLIB_LOGGING_LIB})
if (OPENSSL_FOUND)
- target_link_libraries(uri_builder ${OPENSSL_LIBRARIES})
target_link_libraries(simple_wget ${OPENSSL_LIBRARIES})
target_link_libraries(atom_reader ${OPENSSL_LIBRARIES})
target_link_libraries(rss_reader ${OPENSSL_LIBRARIES})
target_link_libraries(twitter_search ${OPENSSL_LIBRARIES})
- target_link_libraries(hello_world_server ${OPENSSL_LIBRARIES})
+ #target_link_libraries(hello_world_server ${OPENSSL_LIBRARIES})
target_link_libraries(hello_world_client ${OPENSSL_LIBRARIES})
endif (OPENSSL_FOUND)
@@ -126,12 +133,11 @@ endif (OPENSSL_FOUND)
# cppnetlib-server-parsers)
#endif (UNIX)
-set_target_properties(uri_builder PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
set_target_properties(simple_wget PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
set_target_properties(atom_reader PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
set_target_properties(rss_reader PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
set_target_properties(twitter_search PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
-set_target_properties(hello_world_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
+#set_target_properties(hello_world_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
set_target_properties(hello_world_client PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
#if (UNIX)
# set_target_properties(fileserver PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
View
0  libs/network/example/Jamfile.v2 → contrib/http_examples/Jamfile.v2
File renamed without changes
View
0  libs/network/example/atom/atom.cpp → contrib/http_examples/atom/atom.cpp
File renamed without changes
View
0  libs/network/example/atom/atom.hpp → contrib/http_examples/atom/atom.hpp
File renamed without changes
View
0  libs/network/example/atom/main.cpp → contrib/http_examples/atom/main.cpp
File renamed without changes
View
0  libs/network/example/http/fileserver.cpp → contrib/http_examples/http/fileserver.cpp
File renamed without changes
View
0  libs/network/example/http/hello_world_client.cpp → contrib/http_examples/http/hello_world_client.cpp
File renamed without changes
View
0  libs/network/example/http/hello_world_server.cpp → contrib/http_examples/http/hello_world_server.cpp
File renamed without changes
View
0  libs/network/example/http/one_liner.cpp → contrib/http_examples/http/one_liner.cpp
File renamed without changes
View
0  libs/network/example/rapidxml/license.txt → contrib/http_examples/rapidxml/license.txt
File renamed without changes
View
0  libs/network/example/rapidxml/manual.html → contrib/http_examples/rapidxml/manual.html
File renamed without changes
View
0  libs/network/example/rapidxml/rapidxml.hpp → contrib/http_examples/rapidxml/rapidxml.hpp
File renamed without changes
View
0  libs/network/example/rapidxml/rapidxml_iterators.hpp → ...rib/http_examples/rapidxml/rapidxml_iterators.hpp
File renamed without changes
View
0  libs/network/example/rapidxml/rapidxml_print.hpp → contrib/http_examples/rapidxml/rapidxml_print.hpp
File renamed without changes
View
0  libs/network/example/rapidxml/rapidxml_utils.hpp → contrib/http_examples/rapidxml/rapidxml_utils.hpp
File renamed without changes
View
0  libs/network/example/rss/main.cpp → contrib/http_examples/rss/main.cpp
File renamed without changes
View
0  libs/network/example/rss/rss.cpp → contrib/http_examples/rss/rss.cpp
File renamed without changes
View
0  libs/network/example/rss/rss.hpp → contrib/http_examples/rss/rss.hpp
File renamed without changes
View
0  libs/network/example/simple_wget.cpp → contrib/http_examples/simple_wget.cpp
File renamed without changes
View
1,612 libs/network/example/twitter/rapidjson/document.h → contrib/http_examples/twitter/rapidjson/document.h
@@ -1,806 +1,806 @@
-#ifndef RAPIDJSON_DOCUMENT_H_
-#define RAPIDJSON_DOCUMENT_H_
-
-#include "reader.h"
-#include "internal/strfunc.h"
-
-namespace rapidjson {
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericValue
-
-//! Represents a JSON value. Use Value for UTF8 encoding and default allocator.
-/*!
- A JSON value can be one of 7 types. This class is a variant type supporting
- these types.
-
- Use the Value if UTF8 and default allocator
-
- \tparam Encoding Encoding of the value. (Even non-string values need to have the same encoding in a document)
- \tparam Allocator Allocator type for allocating memory of object, array and string.
-*/
-#pragma pack (push, 4)
-template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
-class GenericValue {
-public:
- //! Name-value pair in an object.
- struct Member {
- GenericValue<Encoding, Allocator> name; //!< name of member (must be a string)
- GenericValue<Encoding, Allocator> value; //!< value of member.
- };
-
- typedef Encoding EncodingType; //!< Encoding type from template parameter.
- typedef Allocator AllocatorType; //!< Allocator type from template parameter.
- typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
- typedef Member* MemberIterator; //!< Member iterator for iterating in object.
- typedef const Member* ConstMemberIterator; //!< Constant member iterator for iterating in object.
- typedef GenericValue* ValueIterator; //!< Value iterator for iterating in array.
- typedef const GenericValue* ConstValueIterator; //!< Constant value iterator for iterating in array.
-
- //!@name Constructors and destructor.
- //@{
-
- //! Default constructor creates a null value.
- GenericValue() : flags_(kNullFlag) {}
-
- //! Copy constructor is not permitted.
-private:
- GenericValue(const GenericValue& rhs);
-
-public:
-
- //! Constructor with JSON value type.
- /*! This creates a Value of specified type with default content.
- \param type Type of the value.
- \note Default content for number is zero.
- */
- GenericValue(Type type) {
- static const unsigned defaultFlags[7] = {
- kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kConstStringFlag,
- kNumberFlag | kIntFlag | kUintFlag | kInt64Flag | kUint64Flag | kDoubleFlag
- };
- RAPIDJSON_ASSERT(type <= kNumberType);
- flags_ = defaultFlags[type];
- memset(&data_, 0, sizeof(data_));
- }
-
- //! Constructor for boolean value.
- GenericValue(bool b) : flags_(b ? kTrueFlag : kFalseFlag) {}
-
- //! Constructor for int value.
- GenericValue(int i) : flags_(kNumberIntFlag) {
- data_.n.i64 = i;
- if (i >= 0)
- flags_ |= kUintFlag | kUint64Flag;
- }
-
- //! Constructor for unsigned value.
- GenericValue(unsigned u) : flags_(kNumberUintFlag) {
- data_.n.u64 = u;
- if (!(u & 0x80000000))
- flags_ |= kIntFlag | kInt64Flag;
- }
-
- //! Constructor for int64_t value.
- GenericValue(int64_t i64) : flags_(kNumberInt64Flag) {
- data_.n.i64 = i64;
- if (i64 >= 0) {
- flags_ |= kNumberUint64Flag;
- if (!(i64 & 0xFFFFFFFF00000000LL))
- flags_ |= kUintFlag;
- if (!(i64 & 0xFFFFFFFF80000000LL))
- flags_ |= kIntFlag;
- }
- else if (i64 >= -2147483648LL)
- flags_ |= kIntFlag;
- }
-
- //! Constructor for uint64_t value.
- GenericValue(uint64_t u64) : flags_(kNumberUint64Flag) {
- data_.n.u64 = u64;
- if (!(u64 & 0x8000000000000000L))
- flags_ |= kInt64Flag;
- if (!(u64 & 0xFFFFFFFF00000000L))
- flags_ |= kUintFlag;
- if (!(u64 & 0xFFFFFFFF80000000L))
- flags_ |= kIntFlag;
- }
-
- //! Constructor for double value.
- GenericValue(double d) : flags_(kNumberDoubleFlag) { data_.n.d = d; }
-
- //! Constructor for constant string (i.e. do not make a copy of string)
- GenericValue(const Ch* s, SizeType length) {
- RAPIDJSON_ASSERT(s != NULL);
- flags_ = kConstStringFlag;
- data_.s.str = s;
- data_.s.length = length;
- }
-
- //! Constructor for constant string (i.e. do not make a copy of string)
- GenericValue(const Ch* s) { SetStringRaw(s, internal::StrLen(s)); }
-
- //! Constructor for copy-string (i.e. do make a copy of string)
- GenericValue(const Ch* s, SizeType length, Allocator& allocator) { SetStringRaw(s, length, allocator); }
-
- //! Constructor for copy-string (i.e. do make a copy of string)
- GenericValue(const Ch*s, Allocator& allocator) { SetStringRaw(s, internal::StrLen(s), allocator); }
-
- //! Destructor.
- /*! Need to destruct elements of array, members of object, or copy-string.
- */
- ~GenericValue() {
- if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
- switch(flags_) {
- case kArrayFlag:
- for (GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
- v->~GenericValue();
- Allocator::Free(data_.a.elements);
- break;
-
- case kObjectFlag:
- for (Member* m = data_.o.members; m != data_.o.members + data_.o.size; ++m) {
- m->name.~GenericValue();
- m->value.~GenericValue();
- }
- Allocator::Free(data_.o.members);
- break;
-
- case kCopyStringFlag:
- Allocator::Free((void*)data_.s.str);
- break;
- }
- }
- }
-
- //@}
-
- //!@name Assignment operators
- //@{
-
- //! Assignment with move semantics.
- /*! \param rhs Source of the assignment. It will become a null value after assignment.
- */
- GenericValue& operator=(GenericValue& rhs) {
- RAPIDJSON_ASSERT(this != &rhs);
- this->~GenericValue();
- memcpy(this, &rhs, sizeof(GenericValue));
- rhs.flags_ = kNullFlag;
- return *this;
- }
-
- //! Assignment with primitive types.
- /*! \tparam T Either Type, int, unsigned, int64_t, uint64_t, const Ch*
- \param value The value to be assigned.
- */
- template <typename T>
- GenericValue& operator=(T value) {
- this->~GenericValue();
- new (this) GenericValue(value);
- return *this;
- }
- //@}
-
- //!@name Type
- //@{
-
- Type GetType() const { return static_cast<Type>(flags_ & kTypeMask); }
- bool IsNull() const { return flags_ == kNullFlag; }
- bool IsFalse() const { return flags_ == kFalseFlag; }
- bool IsTrue() const { return flags_ == kTrueFlag; }
- bool IsBool() const { return (flags_ & kBoolFlag) != 0; }
- bool IsObject() const { return flags_ == kObjectFlag; }
- bool IsArray() const { return flags_ == kArrayFlag; }
- bool IsNumber() const { return (flags_ & kNumberFlag) != 0; }
- bool IsInt() const { return (flags_ & kIntFlag) != 0; }
- bool IsUint() const { return (flags_ & kUintFlag) != 0; }
- bool IsInt64() const { return (flags_ & kInt64Flag) != 0; }
- bool IsUint64() const { return (flags_ & kUint64Flag) != 0; }
- bool IsDouble() const { return (flags_ & kDoubleFlag) != 0; }
- bool IsString() const { return (flags_ & kStringFlag) != 0; }
-
- //@}
-
- //!@name Null
- //@{
-
- GenericValue& SetNull() { this->~GenericValue(); new (this) GenericValue(); return *this; }
-
- //@}
-
- //!@name Bool
- //@{
-
- bool GetBool() const { RAPIDJSON_ASSERT(IsBool()); return flags_ == kTrueFlag; }
- GenericValue& SetBool(bool b) { this->~GenericValue(); new (this) GenericValue(b); return *this; }
-
- //@}
-
- //!@name Object
- //@{
-
- //! Set this value as an empty object.
- GenericValue& SetObject() { this->~GenericValue(); new (this) GenericValue(kObjectType); return *this; }
-
- //! Get the value associated with the object's name.
- GenericValue& operator[](const Ch* name) {
- if (Member* member = FindMember(name))
- return member->value;
- else {
- static GenericValue NullValue;
- return NullValue;
- }
- }
- const GenericValue& operator[](const Ch* name) const { return const_cast<GenericValue&>(*this)[name]; }
-
- //! Member iterators.
- ConstMemberIterator MemberBegin() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.members; }
- ConstMemberIterator MemberEnd() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.members + data_.o.size; }
- MemberIterator MemberBegin() { RAPIDJSON_ASSERT(IsObject()); return data_.o.members; }
- MemberIterator MemberEnd() { RAPIDJSON_ASSERT(IsObject()); return data_.o.members + data_.o.size; }
-
- //! Check whether a member exists in the object.
- bool HasMember(const Ch* name) const { return FindMember(name) != 0; }
-
- //! Add a member (name-value pair) to the object.
- /*! \param name A string value as name of member.
- \param value Value of any type.
- \param allocator Allocator for reallocating memory.
- \return The value itself for fluent API.
- \note The ownership of name and value will be transfered to this object if success.
- */
- GenericValue& AddMember(GenericValue& name, GenericValue& value, Allocator& allocator) {
- RAPIDJSON_ASSERT(IsObject());
- RAPIDJSON_ASSERT(name.IsString());
- Object& o = data_.o;
- if (o.size >= o.capacity) {
- if (o.capacity == 0) {
- o.capacity = kDefaultObjectCapacity;
- o.members = (Member*)allocator.Malloc(o.capacity * sizeof(Member));
- }
- else {
- SizeType oldCapacity = o.capacity;
- o.capacity *= 2;
- o.members = (Member*)allocator.Realloc(o.members, oldCapacity * sizeof(Member), o.capacity * sizeof(Member));
- }
- }
- o.members[o.size].name = name;
- o.members[o.size].value = value;
- o.size++;
- return *this;
- }
-
- GenericValue& AddMember(const char* name, Allocator& nameAllocator, GenericValue& value, Allocator& allocator) {
- GenericValue n(name, internal::StrLen(name), nameAllocator);
- return AddMember(n, value, allocator);
- }
-
- GenericValue& AddMember(const char* name, GenericValue& value, Allocator& allocator) {
- GenericValue n(name, internal::StrLen(name));
- return AddMember(n, value, allocator);
- }
-
- template <typename T>
- GenericValue& AddMember(const char* name, T value, Allocator& allocator) {
- GenericValue n(name, internal::StrLen(name));
- GenericValue v(value);
- return AddMember(n, v, allocator);
- }
-
- //! Remove a member in object by its name.
- /*! \param name Name of member to be removed.
- \return Whether the member existed.
- \note Removing member is implemented by moving the last member. So the ordering of members is changed.
- */
- bool RemoveMember(const Ch* name) {
- RAPIDJSON_ASSERT(IsObject());
- if (Member* m = FindMember(name)) {
- RAPIDJSON_ASSERT(data_.o.size > 0);
- RAPIDJSON_ASSERT(data_.o.members != 0);
-
- if (data_.o.size > 1) {
- // Move the last one to this place
- Member* last = data_.o.members + (data_.o.size - 1);
- m->name = last->name;
- m->value = last->value;
- }
- else {
- // Only one left, just destroy
- m->name.~GenericValue();
- m->value.~GenericValue();
- }
- --data_.o.size;
- return true;
- }
- return false;
- }
-
- //@}
-
- //!@name Array
- //@{
-
- //! Set this value as an empty array.
- GenericValue& SetArray() { this->~GenericValue(); new (this) GenericValue(kArrayType); return *this; }
-
- //! Get the number of elements in array.
- SizeType Size() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size; }
-
- //! Get the capacity of array.
- SizeType Capacity() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.capacity; }
-
- //! Check whether the array is empty.
- bool Empty() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size == 0; }
-
- //! Remove all elements in the array.
- /*! This function do not deallocate memory in the array, i.e. the capacity is unchanged.
- */
- void Clear() {
- RAPIDJSON_ASSERT(IsArray());
- for (SizeType i = 0; i < data_.a.size; ++i)
- data_.a.elements[i].~GenericValue();
- data_.a.size = 0;
- }
-
- //! Get an element from array by index.
- /*! \param index Zero-based index of element.
- \note
-\code
-Value a(kArrayType);
-a.PushBack(123);
-int x = a[0].GetInt(); // Error: operator[ is ambiguous, as 0 also mean a null pointer of const char* type.
-int y = a[SizeType(0)].GetInt(); // Cast to SizeType will work.
-int z = a[0u].GetInt(); // This works too.
-\endcode
- */
- GenericValue& operator[](SizeType index) {
- RAPIDJSON_ASSERT(IsArray());
- RAPIDJSON_ASSERT(index < data_.a.size);
- return data_.a.elements[index];
- }
- const GenericValue& operator[](SizeType index) const { return const_cast<GenericValue&>(*this)[index]; }
-
- //! Element iterator
- ValueIterator Begin() { RAPIDJSON_ASSERT(IsArray()); return data_.a.elements; }
- ValueIterator End() { RAPIDJSON_ASSERT(IsArray()); return data_.a.elements + data_.a.size; }
- ConstValueIterator Begin() const { return const_cast<GenericValue&>(*this).Begin(); }
- ConstValueIterator End() const { return const_cast<GenericValue&>(*this).End(); }
-
- //! Request the array to have enough capacity to store elements.
- /*! \param newCapacity The capacity that the array at least need to have.
- \param allocator The allocator for allocating memory. It must be the same one use previously.
- \return The value itself for fluent API.
- */
- GenericValue& Reserve(SizeType newCapacity, Allocator &allocator) {
- RAPIDJSON_ASSERT(IsArray());
- if (newCapacity > data_.a.capacity) {
- data_.a.elements = (GenericValue*)allocator.Realloc(data_.a.elements, data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue));
- data_.a.capacity = newCapacity;
- }
- return *this;
- }
-
- //! Append a value at the end of the array.
- /*! \param value The value to be appended.
- \param allocator The allocator for allocating memory. It must be the same one use previously.
- \return The value itself for fluent API.
- \note The ownership of the value will be transfered to this object if success.
- \note If the number of elements to be appended is known, calls Reserve() once first may be more efficient.
- */
- GenericValue& PushBack(GenericValue& value, Allocator& allocator) {
- RAPIDJSON_ASSERT(IsArray());
- if (data_.a.size >= data_.a.capacity)
- Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : data_.a.capacity * 2, allocator);
- data_.a.elements[data_.a.size++] = value;
- return *this;
- }
-
- template <typename T>
- GenericValue& PushBack(T value, Allocator& allocator) {
- GenericValue v(value);
- return PushBack(v, allocator);
- }
-
- //! Remove the last element in the array.
- GenericValue& PopBack() {
- RAPIDJSON_ASSERT(IsArray());
- RAPIDJSON_ASSERT(!Empty());
- data_.a.elements[--data_.a.size].~GenericValue();
- return *this;
- }
- //@}
-
- //!@name Number
- //@{
-
- int GetInt() const { RAPIDJSON_ASSERT(flags_ & kIntFlag); return data_.n.i; }
- unsigned GetUint() const { RAPIDJSON_ASSERT(flags_ & kUintFlag); return data_.n.u; }
- int64_t GetInt64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.i64; }
- int64_t GetUint64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.u64; }
-
- double GetDouble() const {
- RAPIDJSON_ASSERT(IsNumber());
- if ((flags_ & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion.
- if ((flags_ & kIntFlag) != 0) return data_.n.i; // int -> double
- if ((flags_ & kUintFlag) != 0) return data_.n.u; // unsigned -> double
- if ((flags_ & kInt64Flag) != 0) return (double)data_.n.i64; // int64_t -> double (may lose precision)
- RAPIDJSON_ASSERT((flags_ & kUint64Flag) != 0); return (double)data_.n.u64; // uint64_t -> double (may lose precision)
- }
-
- GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; }
- GenericValue& SetUint(unsigned u) { this->~GenericValue(); new (this) GenericValue(u); return *this; }
- GenericValue& SetInt64(int64_t i64) { this->~GenericValue(); new (this) GenericValue(i64); return *this; }
- GenericValue& SetUint64(uint64_t u64) { this->~GenericValue(); new (this) GenericValue(u64); return *this; }
- GenericValue& SetDouble(double d) { this->~GenericValue(); new (this) GenericValue(d); return *this; }
-
- //@}
-
- //!@name String
- //@{
-
- const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return data_.s.str; }
-
- //! Get the length of string.
- /*! Since rapidjson permits "\u0000" in the json string, strlen(v.GetString()) may not equal to v.GetStringLength().
- */
- SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return data_.s.length; }
-
- //! Set this value as a string without copying source string.
- /*! This version has better performance with supplied length, and also support string containing null character.
- \param s source string pointer.
- \param length The length of source string, excluding the trailing null terminator.
- \return The value itself for fluent API.
- */
- GenericValue& SetString(const Ch* s, SizeType length) { this->~GenericValue(); SetStringRaw(s, length); return *this; }
-
- //! Set this value as a string without copying source string.
- /*! \param s source string pointer.
- \return The value itself for fluent API.
- */
- GenericValue& SetString(const Ch* s) { return SetString(s, internal::StrLen(s)); }
-
- //! Set this value as a string by copying from source string.
- /*! This version has better performance with supplied length, and also support string containing null character.
- \param s source string.
- \param length The length of source string, excluding the trailing null terminator.
- \param allocator Allocator for allocating copied buffer. Commonly use document.GetAllocator().
- \return The value itself for fluent API.
- */
- GenericValue& SetString(const Ch* s, SizeType length, Allocator& allocator) { this->~GenericValue(); SetStringRaw(s, length, allocator); return *this; }
-
- //! Set this value as a string by copying from source string.
- /*! \param s source string.
- \param allocator Allocator for allocating copied buffer. Commonly use document.GetAllocator().
- \return The value itself for fluent API.
- */
- GenericValue& SetString(const Ch* s, Allocator& allocator) { SetString(s, internal::StrLen(s), allocator); return *this; }
-
- //@}
-
- //! Generate events of this value to a Handler.
- /*! This function adopts the GoF visitor pattern.
- Typical usage is to output this JSON value as JSON text via Writer, which is a Handler.
- It can also be used to deep clone this value via GenericDocument, which is also a Handler.
- \tparam Handler type of handler.
- \param handler An object implementing concept Handler.
- */
- template <typename Handler>
- GenericValue& Accept(Handler& handler) {
- switch(GetType()) {
- case kNullType: handler.Null(); break;
- case kFalseType: handler.Bool(false); break;
- case kTrueType: handler.Bool(true); break;
-
- case kObjectType:
- handler.StartObject();
- for (Member* m = data_.o.members; m != data_.o.members + data_.o.size; ++m) {
- handler.String(m->name.data_.s.str, m->name.data_.s.length, false);
- m->value.Accept(handler);
- }
- handler.EndObject(data_.o.size);
- break;
-
- case kArrayType:
- handler.StartArray();
- for (GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
- v->Accept(handler);
- handler.EndArray(data_.a.size);
- break;
-
- case kStringType:
- handler.String(data_.s.str, data_.s.length, false);
- break;
-
- case kNumberType:
- if (IsInt()) handler.Int(data_.n.i);
- else if (IsUint()) handler.Uint(data_.n.u);
- else if (IsInt64()) handler.Int64(data_.n.i64);
- else if (IsUint64()) handler.Uint64(data_.n.i64);
- else handler.Double(data_.n.d);
- break;
- }
- return *this;
- }
-
-private:
- template <typename, typename>
- friend class GenericDocument;
-
- enum {
- kBoolFlag = 0x100,
- kNumberFlag = 0x200,
- kIntFlag = 0x400,
- kUintFlag = 0x800,
- kInt64Flag = 0x1000,
- kUint64Flag = 0x2000,
- kDoubleFlag = 0x4000,
- kStringFlag = 0x100000,
- kCopyFlag = 0x200000,
-
- // Initial flags of different types.
- kNullFlag = kNullType,
- kTrueFlag = kTrueType | kBoolFlag,
- kFalseFlag = kFalseType | kBoolFlag,
- kNumberIntFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
- kNumberUintFlag = kNumberType | kNumberFlag | kUintFlag | kUint64Flag,
- kNumberInt64Flag = kNumberType | kNumberFlag | kInt64Flag,
- kNumberUint64Flag = kNumberType | kNumberFlag | kUint64Flag,
- kNumberDoubleFlag = kNumberType | kNumberFlag | kDoubleFlag,
- kConstStringFlag = kStringType | kStringFlag,
- kCopyStringFlag = kStringType | kStringFlag | kCopyFlag,
- kObjectFlag = kObjectType,
- kArrayFlag = kArrayType,
-
- kTypeMask = 0xFF // bitwise-and with mask of 0xFF can be optimized by compiler
- };
-
- static const SizeType kDefaultArrayCapacity = 16;
- static const SizeType kDefaultObjectCapacity = 16;
-
- struct String {
- const Ch* str;
- SizeType length;
- unsigned hashcode; //!< reserved
- }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
-
- // By using proper binary layout, retrieval of different integer types do not need conversions.
- union Number {
-#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
- struct {
- int i;
- char padding[4];
- };
- struct {
- unsigned u;
- char padding2[4];
- };
-#else
- struct {
- char padding[4];
- int i;
- };
- struct {
- char padding2[4];
- unsigned u;
- };
-#endif
- int64_t i64;
- uint64_t u64;
- double d;
- }; // 8 bytes
-
- struct Object {
- Member* members;
- SizeType size;
- SizeType capacity;
- }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
-
- struct Array {
- GenericValue<Encoding, Allocator>* elements;
- SizeType size;
- SizeType capacity;
- }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
-
- union Data {
- String s;
- Number n;
- Object o;
- Array a;
- }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
-
- //! Find member by name.
- Member* FindMember(const Ch* name) {
- RAPIDJSON_ASSERT(name);
- RAPIDJSON_ASSERT(IsObject());
-
- Object& o = data_.o;
- for (Member* member = o.members; member != data_.o.members + data_.o.size; ++member)
- if (name[member->name.data_.s.length] == '\0' && memcmp(member->name.data_.s.str, name, member->name.data_.s.length * sizeof(Ch)) == 0)
- return member;
-
- return 0;
- }
- const Member* FindMember(const Ch* name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
-
- // Initialize this value as array with initial data, without calling destructor.
- void SetArrayRaw(GenericValue* values, SizeType count, Allocator& alloctaor) {
- flags_ = kArrayFlag;
- data_.a.elements = (GenericValue*)alloctaor.Malloc(count * sizeof(GenericValue));
- memcpy(data_.a.elements, values, count * sizeof(GenericValue));
- data_.a.size = data_.a.capacity = count;
- }
-
- //! Initialize this value as object with initial data, without calling destructor.
- void SetObjectRaw(Member* members, SizeType count, Allocator& alloctaor) {
- flags_ = kObjectFlag;
- data_.o.members = (Member*)alloctaor.Malloc(count * sizeof(Member));
- memcpy(data_.o.members, members, count * sizeof(Member));
- data_.o.size = data_.o.capacity = count;
- }
-
- //! Initialize this value as constant string, without calling destructor.
- void SetStringRaw(const Ch* s, SizeType length) {
- RAPIDJSON_ASSERT(s != NULL);
- flags_ = kConstStringFlag;
- data_.s.str = s;
- data_.s.length = length;
- }
-
- //! Initialize this value as copy string with initial data, without calling destructor.
- void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) {
- RAPIDJSON_ASSERT(s != NULL);
- flags_ = kCopyStringFlag;
- data_.s.str = (char *)allocator.Malloc(length + 1);
- data_.s.length = length;
- memcpy((void*)data_.s.str, s, length);
- ((char*)data_.s.str)[length] = '\0';
- }
-
- //! Assignment without calling destructor
- void RawAssign(GenericValue& rhs) {
- memcpy(this, &rhs, sizeof(GenericValue));
- rhs.flags_ = kNullFlag;
- }
-
- Data data_;
- unsigned flags_;
-};
-#pragma pack (pop)
-
-//! Value with UTF8 encoding.
-typedef GenericValue<UTF8<> > Value;
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericDocument
-
-//! A document for parsing JSON text as DOM.
-/*!
- \implements Handler
- \tparam Encoding encoding for both parsing and string storage.
- \tparam Alloactor allocator for allocating memory for the DOM, and the stack during parsing.
-*/
-template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
-class GenericDocument : public GenericValue<Encoding, Allocator> {
-public:
- typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
- typedef GenericValue<Encoding, Allocator> ValueType; //!< Value type of the document.
- typedef Allocator AllocatorType; //!< Allocator type from template parameter.
-
- //! Constructor
- /*! \param allocator Optional allocator for allocating stack memory.
- \param stackCapacity Initial capacity of stack in bytes.
- */
- GenericDocument(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity) : stack_(allocator, stackCapacity), parseError_(0), errorOffset_(0) {}
-
- //! Parse JSON text from an input stream.
- /*! \tparam parseFlags Combination of ParseFlag.
- \param stream Input stream to be parsed.
- \return The document itself for fluent API.
- */
- template <unsigned parseFlags, typename Stream>
- GenericDocument& ParseStream(Stream& stream) {
- ValueType::SetNull(); // Remove existing root if exist
- GenericReader<Encoding> reader;
- if (reader.template Parse<parseFlags>(stream, *this)) {
- RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
- this->RawAssign(*stack_.template Pop<ValueType>(1));
- parseError_ = 0;
- errorOffset_ = 0;
- }
- else {
- parseError_ = reader.GetParseError();
- errorOffset_ = reader.GetErrorOffset();
- ClearStack();
- }
- return *this;
- }
-
- //! Parse JSON text from a mutable string.
- /*! \tparam parseFlags Combination of ParseFlag.
- \param str Mutable zero-terminated string to be parsed.
- \return The document itself for fluent API.
- */
- template <unsigned parseFlags>
- GenericDocument& ParseInsitu(Ch* str) {
- GenericInsituStringStream<Encoding> s(str);
- return ParseStream<parseFlags | kParseInsituFlag>(s);
- }
-
- //! Parse JSON text from a read-only string.
- /*! \tparam parseFlags Combination of ParseFlag (must not contain kParseInsituFlag).
- \param str Read-only zero-terminated string to be parsed.
- */
- template <unsigned parseFlags>
- GenericDocument& Parse(const Ch* str) {
- RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
- GenericStringStream<Encoding> s(str);
- return ParseStream<parseFlags>(s);
- }
-
- //! Whether a parse error was occured in the last parsing.
- bool HasParseError() const { return parseError_ != 0; }
-
- //! Get the message of parsing error.
- const char* GetParseError() const { return parseError_; }
-
- //! Get the offset in character of the parsing error.
- size_t GetErrorOffset() const { return errorOffset_; }
-
- //! Get the allocator of this document.
- Allocator& GetAllocator() { return stack_.GetAllocator(); }
-
- //! Get the capacity of stack in bytes.
- size_t GetStackCapacity() const { return stack_.GetCapacity(); }
-
-private:
- friend class GenericReader<Encoding>; // for Reader to call the following private handler functions
-
- // Implementation of Handler
- void Null() { new (stack_.template Push<ValueType>()) ValueType(); }
- void Bool(bool b) { new (stack_.template Push<ValueType>()) ValueType(b); }
- void Int(int i) { new (stack_.template Push<ValueType>()) ValueType(i); }
- void Uint(unsigned i) { new (stack_.template Push<ValueType>()) ValueType(i); }
- void Int64(int64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); }
- void Uint64(uint64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); }
- void Double(double d) { new (stack_.template Push<ValueType>()) ValueType(d); }
-
- void String(const Ch* str, SizeType length, bool copy) {
- if (copy)
- new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
- else
- new (stack_.template Push<ValueType>()) ValueType(str, length);
- }
-
- void StartObject() { new (stack_.template Push<ValueType>()) ValueType(kObjectType); }
-
- void EndObject(SizeType memberCount) {
- typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
- stack_.template Top<ValueType>()->SetObjectRaw(members, (SizeType)memberCount, GetAllocator());
- }
-
- void StartArray() { new (stack_.template Push<ValueType>()) ValueType(kArrayType); }
-
- void EndArray(SizeType elementCount) {
- ValueType* elements = stack_.template Pop<ValueType>(elementCount);
- stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
- }
-
- void ClearStack() {
- if (Allocator::kNeedFree)
- while (stack_.GetSize() > 0) // Here assumes all elements in stack array are GenericValue (Member is actually 2 GenericValue objects)
- (stack_.template Pop<ValueType>(1))->~ValueType();
- else
- stack_.Clear();
- }
-
- static const size_t kDefaultStackCapacity = 1024;
- internal::Stack<Allocator> stack_;
- const char* parseError_;
- size_t errorOffset_;
-};
-
-typedef GenericDocument<UTF8<> > Document;
-
-} // namespace rapidjson
-
-#endif // RAPIDJSON_DOCUMENT_H_
+#ifndef RAPIDJSON_DOCUMENT_H_
+#define RAPIDJSON_DOCUMENT_H_
+
+#include "reader.h"
+#include "internal/strfunc.h"
+
+namespace rapidjson {
+
+///////////////////////////////////////////////////////////////////////////////
+// GenericValue
+
+//! Represents a JSON value. Use Value for UTF8 encoding and default allocator.
+/*!
+ A JSON value can be one of 7 types. This class is a variant type supporting
+ these types.
+
+ Use the Value if UTF8 and default allocator
+
+ \tparam Encoding Encoding of the value. (Even non-string values need to have the same encoding in a document)
+ \tparam Allocator Allocator type for allocating memory of object, array and string.
+*/
+#pragma pack (push, 4)
+template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
+class GenericValue {
+public:
+ //! Name-value pair in an object.
+ struct Member {
+ GenericValue<Encoding, Allocator> name; //!< name of member (must be a string)
+ GenericValue<Encoding, Allocator> value; //!< value of member.
+ };
+
+ typedef Encoding EncodingType; //!< Encoding type from template parameter.
+ typedef Allocator AllocatorType; //!< Allocator type from template parameter.
+ typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
+ typedef Member* MemberIterator; //!< Member iterator for iterating in object.
+ typedef const Member* ConstMemberIterator; //!< Constant member iterator for iterating in object.
+ typedef GenericValue* ValueIterator; //!< Value iterator for iterating in array.
+ typedef const GenericValue* ConstValueIterator; //!< Constant value iterator for iterating in array.
+
+ //!@name Constructors and destructor.
+ //@{
+
+ //! Default constructor creates a null value.
+ GenericValue() : flags_(kNullFlag) {}
+
+ //! Copy constructor is not permitted.
+private:
+ GenericValue(const GenericValue& rhs);
+
+public:
+
+ //! Constructor with JSON value type.
+ /*! This creates a Value of specified type with default content.
+ \param type Type of the value.
+ \note Default content for number is zero.
+ */
+ GenericValue(Type type) {
+ static const unsigned defaultFlags[7] = {
+ kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kConstStringFlag,
+ kNumberFlag | kIntFlag | kUintFlag | kInt64Flag | kUint64Flag | kDoubleFlag
+ };
+ RAPIDJSON_ASSERT(type <= kNumberType);
+ flags_ = defaultFlags[type];
+ memset(&data_, 0, sizeof(data_));
+ }
+
+ //! Constructor for boolean value.
+ GenericValue(bool b) : flags_(b ? kTrueFlag : kFalseFlag) {}
+
+ //! Constructor for int value.
+ GenericValue(int i) : flags_(kNumberIntFlag) {
+ data_.n.i64 = i;
+ if (i >= 0)
+ flags_ |= kUintFlag | kUint64Flag;
+ }
+
+ //! Constructor for unsigned value.
+ GenericValue(unsigned u) : flags_(kNumberUintFlag) {
+ data_.n.u64 = u;
+ if (!(u & 0x80000000))
+ flags_ |= kIntFlag | kInt64Flag;
+ }
+
+ //! Constructor for int64_t value.
+ GenericValue(int64_t i64) : flags_(kNumberInt64Flag) {
+ data_.n.i64 = i64;
+ if (i64 >= 0) {
+ flags_ |= kNumberUint64Flag;
+ if (!(i64 & 0xFFFFFFFF00000000LL))
+ flags_ |= kUintFlag;
+ if (!(i64 & 0xFFFFFFFF80000000LL))
+ flags_ |= kIntFlag;
+ }
+ else if (i64 >= -2147483648LL)
+ flags_ |= kIntFlag;
+ }
+
+ //! Constructor for uint64_t value.
+ GenericValue(uint64_t u64) : flags_(kNumberUint64Flag) {
+ data_.n.u64 = u64;
+ if (!(u64 & 0x8000000000000000L))
+ flags_ |= kInt64Flag;
+ if (!(u64 & 0xFFFFFFFF00000000L))
+ flags_ |= kUintFlag;
+ if (!(u64 & 0xFFFFFFFF80000000L))
+ flags_ |= kIntFlag;
+ }
+
+ //! Constructor for double value.
+ GenericValue(double d) : flags_(kNumberDoubleFlag) { data_.n.d = d; }
+
+ //! Constructor for constant string (i.e. do not make a copy of string)
+ GenericValue(const Ch* s, SizeType length) {
+ RAPIDJSON_ASSERT(s != NULL);
+ flags_ = kConstStringFlag;
+ data_.s.str = s;
+ data_.s.length = length;
+ }
+
+ //! Constructor for constant string (i.e. do not make a copy of string)
+ GenericValue(const Ch* s) { SetStringRaw(s, internal::StrLen(s)); }
+
+ //! Constructor for copy-string (i.e. do make a copy of string)
+ GenericValue(const Ch* s, SizeType length, Allocator& allocator) { SetStringRaw(s, length, allocator); }
+
+ //! Constructor for copy-string (i.e. do make a copy of string)
+ GenericValue(const Ch*s, Allocator& allocator) { SetStringRaw(s, internal::StrLen(s), allocator); }
+
+ //! Destructor.
+ /*! Need to destruct elements of array, members of object, or copy-string.
+ */
+ ~GenericValue() {
+ if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
+ switch(flags_) {
+ case kArrayFlag:
+ for (GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
+ v->~GenericValue();
+ Allocator::Free(data_.a.elements);
+ break;
+
+ case kObjectFlag:
+ for (Member* m = data_.o.members; m != data_.o.members + data_.o.size; ++m) {
+ m->name.~GenericValue();
+ m->value.~GenericValue();
+ }
+ Allocator::Free(data_.o.members);
+ break;
+
+ case kCopyStringFlag:
+ Allocator::Free((void*)data_.s.str);
+ break;
+ }
+ }
+ }
+
+ //@}
+
+ //!@name Assignment operators
+ //@{
+
+ //! Assignment with move semantics.
+ /*! \param rhs Source of the assignment. It will become a null value after assignment.
+ */
+ GenericValue& operator=(GenericValue& rhs) {
+ RAPIDJSON_ASSERT(this != &rhs);
+ this->~GenericValue();
+ memcpy(this, &rhs, sizeof(GenericValue));
+ rhs.flags_ = kNullFlag;
+ return *this;
+ }
+
+ //! Assignment with primitive types.
+ /*! \tparam T Either Type, int, unsigned, int64_t, uint64_t, const Ch*
+ \param value The value to be assigned.
+ */
+ template <typename T>
+ GenericValue& operator=(T value) {
+ this->~GenericValue();
+ new (this) GenericValue(value);
+ return *this;
+ }
+ //@}
+
+ //!@name Type
+ //@{
+
+ Type GetType() const { return static_cast<Type>(flags_ & kTypeMask); }
+ bool IsNull() const { return flags_ == kNullFlag; }
+ bool IsFalse() const { return flags_ == kFalseFlag; }
+ bool IsTrue() const { return flags_ == kTrueFlag; }
+ bool IsBool() const { return (flags_ & kBoolFlag) != 0; }
+ bool IsObject() const { return flags_ == kObjectFlag; }
+ bool IsArray() const { return flags_ == kArrayFlag; }
+ bool IsNumber() const { return (flags_ & kNumberFlag) != 0; }
+ bool IsInt() const { return (flags_ & kIntFlag) != 0; }
+ bool IsUint() const { return (flags_ & kUintFlag) != 0; }
+ bool IsInt64() const { return (flags_ & kInt64Flag) != 0; }
+ bool IsUint64() const { return (flags_ & kUint64Flag) != 0; }
+ bool IsDouble() const { return (flags_ & kDoubleFlag) != 0; }
+ bool IsString() const { return (flags_ & kStringFlag) != 0; }
+
+ //@}
+
+ //!@name Null
+ //@{
+
+ GenericValue& SetNull() { this->~GenericValue(); new (this) GenericValue(); return *this; }
+
+ //@}
+
+ //!@name Bool
+ //@{
+
+ bool GetBool() const { RAPIDJSON_ASSERT(IsBool()); return flags_ == kTrueFlag; }
+ GenericValue& SetBool(bool b) { this->~GenericValue(); new (this) GenericValue(b); return *this; }
+
+ //@}
+
+ //!@name Object
+ //@{
+
+ //! Set this value as an empty object.
+ GenericValue& SetObject() { this->~GenericValue(); new (this) GenericValue(kObjectType); return *this; }
+
+ //! Get the value associated with the object's name.
+ GenericValue& operator[](const Ch* name) {
+ if (Member* member = FindMember(name))
+ return member->value;
+ else {
+ static GenericValue NullValue;
+ return NullValue;
+ }
+ }
+ const GenericValue& operator[](const Ch* name) const { return const_cast<GenericValue&>(*this)[name]; }
+
+ //! Member iterators.
+ ConstMemberIterator MemberBegin() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.members; }
+ ConstMemberIterator MemberEnd() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.members + data_.o.size; }
+ MemberIterator MemberBegin() { RAPIDJSON_ASSERT(IsObject()); return data_.o.members; }
+ MemberIterator MemberEnd() { RAPIDJSON_ASSERT(IsObject()); return data_.o.members + data_.o.size; }
+
+ //! Check whether a member exists in the object.
+ bool HasMember(const Ch* name) const { return FindMember(name) != 0; }
+
+ //! Add a member (name-value pair) to the object.
+ /*! \param name A string value as name of member.
+ \param value Value of any type.
+ \param allocator Allocator for reallocating memory.
+ \return The value itself for fluent API.
+ \note The ownership of name and value will be transfered to this object if success.
+ */
+ GenericValue& AddMember(GenericValue& name, GenericValue& value, Allocator& allocator) {
+ RAPIDJSON_ASSERT(IsObject());
+ RAPIDJSON_ASSERT(name.IsString());
+ Object& o = data_.o;
+ if (o.size >= o.capacity) {
+ if (o.capacity == 0) {
+ o.capacity = kDefaultObjectCapacity;
+ o.members = (Member*)allocator.Malloc(o.capacity * sizeof(Member));
+ }
+ else {
+ SizeType oldCapacity = o.capacity;
+ o.capacity *= 2;
+ o.members = (Member*)allocator.Realloc(o.members, oldCapacity * sizeof(Member), o.capacity * sizeof(Member));
+ }
+ }
+ o.members[o.size].name = name;
+ o.members[o.size].value = value;
+ o.size++;
+ return *this;
+ }
+
+ GenericValue& AddMember(const char* name, Allocator& nameAllocator, GenericValue& value, Allocator& allocator) {
+ GenericValue n(name, internal::StrLen(name), nameAllocator);
+ return AddMember(n, value, allocator);
+ }
+
+ GenericValue& AddMember(const char* name, GenericValue& value, Allocator& allocator) {
+ GenericValue n(name, internal::StrLen(name));
+ return AddMember(n, value, allocator);
+ }
+
+ template <typename T>
+ GenericValue& AddMember(const char* name, T value, Allocator& allocator) {
+ GenericValue n(name, internal::StrLen(name));
+ GenericValue v(value);
+ return AddMember(n, v, allocator);
+ }
+
+ //! Remove a member in object by its name.
+ /*! \param name Name of member to be removed.
+ \return Whether the member existed.
+ \note Removing member is implemented by moving the last member. So the ordering of members is changed.
+ */
+ bool RemoveMember(const Ch* name) {
+ RAPIDJSON_ASSERT(IsObject());
+ if (Member* m = FindMember(name)) {
+ RAPIDJSON_ASSERT(data_.o.size > 0);
+ RAPIDJSON_ASSERT(data_.o.members != 0);
+
+ if (data_.o.size > 1) {
+ // Move the last one to this place
+ Member* last = data_.o.members + (data_.o.size - 1);
+ m->name = last->name;
+ m->value = last->value;
+ }
+ else {
+ // Only one left, just destroy
+ m->name.~GenericValue();
+ m->value.~GenericValue();
+ }
+ --data_.o.size;
+ return true;
+ }
+ return false;
+ }
+
+ //@}
+
+ //!@name Array
+ //@{
+
+ //! Set this value as an empty array.
+ GenericValue& SetArray() { this->~GenericValue(); new (this) GenericValue(kArrayType); return *this; }
+
+ //! Get the number of elements in array.
+ SizeType Size() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size; }
+
+ //! Get the capacity of array.
+ SizeType Capacity() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.capacity; }
+
+ //! Check whether the array is empty.
+ bool Empty() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size == 0; }
+
+ //! Remove all elements in the array.
+ /*! This function do not deallocate memory in the array, i.e. the capacity is unchanged.
+ */
+ void Clear() {
+ RAPIDJSON_ASSERT(IsArray());
+ for (SizeType i = 0; i < data_.a.size; ++i)
+ data_.a.elements[i].~GenericValue();
+ data_.a.size = 0;
+ }
+
+ //! Get an element from array by index.
+ /*! \param index Zero-based index of element.
+ \note
+\code
+Value a(kArrayType);
+a.PushBack(123);
+int x = a[0].GetInt(); // Error: operator[ is ambiguous, as 0 also mean a null pointer of const char* type.
+int y = a[SizeType(0)].GetInt(); // Cast to SizeType will work.
+int z = a[0u].GetInt(); // This works too.
+\endcode
+ */
+ GenericValue& operator[](SizeType index) {
+ RAPIDJSON_ASSERT(IsArray());
+ RAPIDJSON_ASSERT(index < data_.a.size);
+ return data_.a.elements[index];
+ }
+ const GenericValue& operator[](SizeType index) const { return const_cast<GenericValue&>(*this)[index]; }
+
+ //! Element iterator
+ ValueIterator Begin() { RAPIDJSON_ASSERT(IsArray()); return data_.a.elements; }
+ ValueIterator End() { RAPIDJSON_ASSERT(IsArray()); return data_.a.elements + data_.a.size; }
+ ConstValueIterator Begin() const { return const_cast<GenericValue&>(*this).Begin(); }
+ ConstValueIterator End() const { return const_cast<GenericValue&>(*this).End(); }
+
+ //! Request the array to have enough capacity to store elements.
+ /*! \param newCapacity The capacity that the array at least need to have.
+ \param allocator The allocator for allocating memory. It must be the same one use previously.
+ \return The value itself for fluent API.
+ */
+ GenericValue& Reserve(SizeType newCapacity, Allocator &allocator) {
+ RAPIDJSON_ASSERT(IsArray());
+ if (newCapacity > data_.a.capacity) {
+ data_.a.elements = (GenericValue*)allocator.Realloc(data_.a.elements, data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue));
+ data_.a.capacity = newCapacity;
+ }
+ return *this;
+ }
+
+ //! Append a value at the end of the array.
+ /*! \param value The value to be appended.
+ \param allocator The allocator for allocating memory. It must be the same one use previously.
+ \return The value itself for fluent API.
+ \note The ownership of the value will be transfered to this object if success.
+ \note If the number of elements to be appended is known, calls Reserve() once first may be more efficient.
+ */
+ GenericValue& PushBack(GenericValue& value, Allocator& allocator) {
+ RAPIDJSON_ASSERT(IsArray());
+ if (data_.a.size >= data_.a.capacity)
+ Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : data_.a.capacity * 2, allocator);
+ data_.a.elements[data_.a.size++] = value;
+ return *this;
+ }
+
+ template <typename T>
+ GenericValue& PushBack(T value, Allocator& allocator) {
+ GenericValue v(value);
+ return PushBack(v, allocator);
+ }
+
+ //! Remove the last element in the array.
+ GenericValue& PopBack() {
+ RAPIDJSON_ASSERT(IsArray());
+ RAPIDJSON_ASSERT(!Empty());
+ data_.a.elements[--data_.a.size].~GenericValue();
+ return *this;
+ }
+ //@}
+
+ //!@name Number
+ //@{
+
+ int GetInt() const { RAPIDJSON_ASSERT(flags_ & kIntFlag); return data_.n.i; }
+ unsigned GetUint() const { RAPIDJSON_ASSERT(flags_ & kUintFlag); return data_.n.u; }
+ int64_t GetInt64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.i64; }
+ int64_t GetUint64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.u64; }
+
+ double GetDouble() const {
+ RAPIDJSON_ASSERT(IsNumber());
+ if ((flags_ & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion.
+ if ((flags_ & kIntFlag) != 0) return data_.n.i; // int -> double
+ if ((flags_ & kUintFlag) != 0) return data_.n.u; // unsigned -> double
+ if ((flags_ & kInt64Flag) != 0) return (double)data_.n.i64; // int64_t -> double (may lose precision)
+ RAPIDJSON_ASSERT((flags_ & kUint64Flag) != 0); return (double)data_.n.u64; // uint64_t -> double (may lose precision)
+ }
+
+ GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; }
+ GenericValue& SetUint(unsigned u) { this->~GenericValue(); new (this) GenericValue(u); return *this; }
+ GenericValue& SetInt64(int64_t i64) { this->~GenericValue(); new (this) GenericValue(i64); return *this; }
+ GenericValue& SetUint64(uint64_t u64) { this->~GenericValue(); new (this) GenericValue(u64); return *this; }
+ GenericValue& SetDouble(double d) { this->~GenericValue(); new (this) GenericValue(d); return *this; }
+
+ //@}
+
+ //!@name String
+ //@{
+
+ const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return data_.s.str; }
+
+ //! Get the length of string.
+ /*! Since rapidjson permits "\u0000" in the json string, strlen(v.GetString()) may not equal to v.GetStringLength().
+ */
+ SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return data_.s.length; }
+
+ //! Set this value as a string without copying source string.
+ /*! This version has better performance with supplied length, and also support string containing null character.
+ \param s source string pointer.
+ \param length The length of source string, excluding the trailing null terminator.
+ \return The value itself for fluent API.
+ */
+ GenericValue& SetString(const Ch* s, SizeType length) { this->~GenericValue(); SetStringRaw(s, length); return *this; }
+
+ //! Set this value as a string without copying source string.
+ /*! \param s source string pointer.
+ \return The value itself for fluent API.
+ */
+ GenericValue& SetString(const Ch* s) { return SetString(s, internal::StrLen(s)); }
+
+ //! Set this value as a string by copying from source string.
+ /*! This version has better performance with supplied length, and also support string containing null character.
+ \param s source string.
+ \param length The length of source string, excluding the trailing null terminator.
+ \param allocator Allocator for allocating copied buffer. Commonly use document.GetAllocator().
+ \return The value itself for fluent API.
+ */
+ GenericValue& SetString(const Ch* s, SizeType length, Allocator& allocator) { this->~GenericValue(); SetStringRaw(s, length, allocator); return *this; }
+
+ //! Set this value as a string by copying from source string.
+ /*! \param s source string.
+ \param allocator Allocator for allocating copied buffer. Commonly use document.GetAllocator().
+ \return The value itself for fluent API.
+ */
+ GenericValue& SetString(const Ch* s, Allocator& allocator) { SetString(s, internal::StrLen(s), allocator); return *this; }
+
+ //@}
+
+ //! Generate events of this value to a Handler.
+ /*! This function adopts the GoF visitor pattern.
+ Typical usage is to output this JSON value as JSON text via Writer, which is a Handler.
+ It can also be used to deep clone this value via GenericDocument, which is also a Handler.
+ \tparam Handler type of handler.
+ \param handler An object implementing concept Handler.
+ */
+ template <typename Handler>
+ GenericValue& Accept(Handler& handler) {
+ switch(GetType()) {
+ case kNullType: handler.Null(); break;
+ case kFalseType: handler.Bool(false); break;
+ case kTrueType: handler.Bool(true); break;
+
+ case kObjectType:
+ handler.StartObject();
+ for (Member* m = data_.o.members; m != data_.o.members + data_.o.size; ++m) {
+ handler.String(m->name.data_.s.str, m->name.data_.s.length, false);
+ m->value.Accept(handler);
+ }
+ handler.EndObject(data_.o.size);
+ break;
+
+ case kArrayType:
+ handler.StartArray();
+ for (GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
+ v->Accept(handler);
+ handler.EndArray(data_.a.size);
+ break;
+
+ case kStringType:
+ handler.String(data_.s.str, data_.s.length, false);
+ break;
+
+ case kNumberType:
+ if (IsInt()) handler.Int(data_.n.i);
+ else if (IsUint()) handler.Uint(data_.n.u);
+ else if (IsInt64()) handler.Int64(data_.n.i64);
+ else if (IsUint64()) handler.Uint64(data_.n.i64);
+ else handler.Double(data_.n.d);
+ break;
+ }
+ return *this;
+ }
+
+private:
+ template <typename, typename>
+ friend class GenericDocument;
+
+ enum {
+ kBoolFlag = 0x100,
+ kNumberFlag = 0x200,
+ kIntFlag = 0x400,
+ kUintFlag = 0x800,
+ kInt64Flag = 0x1000,
+ kUint64Flag = 0x2000,
+ kDoubleFlag = 0x4000,
+ kStringFlag = 0x100000,
+ kCopyFlag = 0x200000,
+
+ // Initial flags of different types.
+ kNullFlag = kNullType,
+ kTrueFlag = kTrueType | kBoolFlag,
+ kFalseFlag = kFalseType | kBoolFlag,
+ kNumberIntFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
+ kNumberUintFlag = kNumberType | kNumberFlag | kUintFlag | kUint64Flag,
+ kNumberInt64Flag = kNumberType | kNumberFlag | kInt64Flag,
+ kNumberUint64Flag = kNumberType | kNumberFlag | kUint64Flag,
+ kNumberDoubleFlag = kNumberType | kNumberFlag | kDoubleFlag,
+ kConstStringFlag = kStringType | kStringFlag,
+ kCopyStringFlag = kStringType | kStringFlag | kCopyFlag,
+ kObjectFlag = kObjectType,
+ kArrayFlag = kArrayType,
+
+ kTypeMask = 0xFF // bitwise-and with mask of 0xFF can be optimized by compiler
+ };
+
+ static const SizeType kDefaultArrayCapacity = 16;
+ static const SizeType kDefaultObjectCapacity = 16;
+
+ struct String {
+ const Ch* str;
+ SizeType length;
+ unsigned hashcode; //!< reserved
+ }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
+
+ // By using proper binary layout, retrieval of different integer types do not need conversions.
+ union Number {
+#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
+ struct {
+ int i;
+ char padding[4];
+ };
+ struct {
+ unsigned u;
+ char padding2[4];
+ };
+#else
+ struct {
+ char padding[4];
+ int i;
+ };
+ struct {
+ char padding2[4];
+ unsigned u;
+ };
+#endif
+ int64_t i64;
+ uint64_t u64;
+ double d;
+ }; // 8 bytes
+
+ struct Object {
+ Member* members;
+ SizeType size;
+ SizeType capacity;
+ }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
+
+ struct Array {
+ GenericValue<Encoding, Allocator>* elements;
+ SizeType size;
+ SizeType capacity;
+ }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
+
+ union Data {
+ String s;
+ Number n;
+ Object o;
+ Array a;
+ }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
+
+ //! Find member by name.
+ Member* FindMember(const Ch* name) {
+ RAPIDJSON_ASSERT(name);
+ RAPIDJSON_ASSERT(IsObject());
+
+ Object& o = data_.o;
+ for (Member* member = o.members; member != data_.o.members + data_.o.size; ++member)
+ if (name[member->name.data_.s.length] == '\0' && memcmp(member->name.data_.s.str, name, member->name.data_.s.length * sizeof(Ch)) == 0)
+ return member;
+
+ return 0;
+ }
+ const Member* FindMember(const Ch* name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
+
+ // Initialize this value as array with initial data, without calling destructor.
+ void SetArrayRaw(GenericValue* values, SizeType count, Allocator& alloctaor) {
+ flags_ = kArrayFlag;
+ data_.a.elements = (GenericValue*)alloctaor.Malloc(count * sizeof(GenericValue));
+ memcpy(data_.a.elements, values, count * sizeof(GenericValue));
+ data_.a.size = data_.a.capacity = count;
+ }
+
+ //! Initialize this value as object with initial data, without calling destructor.
+ void SetObjectRaw(Member* members, SizeType count, Allocator& alloctaor) {
+ flags_ = kObjectFlag;
+ data_.o.members = (Member*)alloctaor.Malloc(count * sizeof(Member));
+ memcpy(data_.o.members, members, count * sizeof(Member));
+ data_.o.size = data_.o.capacity = count;
+ }
+
+ //! Initialize this value as constant string, without calling destructor.
+ void SetStringRaw(const Ch* s, SizeType length) {
+ RAPIDJSON_ASSERT(s != NULL);
+ flags_ = kConstStringFlag;
+ data_.s.str = s;
+ data_.s.length = length;
+ }
+
+ //! Initialize this value as copy string with initial data, without calling destructor.
+ void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) {
+ RAPIDJSON_ASSERT(s != NULL);
+ flags_ = kCopyStringFlag;
+ data_.s.str = (char *)allocator.Malloc(length + 1);
+ data_.s.length = length;
+ memcpy((void*)data_.s.str, s, length);
+ ((char*)data_.s.str)[length] = '\0';
+ }
+
+ //! Assignment without calling destructor
+ void RawAssign(GenericValue& rhs) {
+ memcpy(this, &rhs, sizeof(GenericValue));
+ rhs.flags_ = kNullFlag;
+ }
+
+ Data data_;
+ unsigned flags_;
+};
+#pragma pack (pop)
+
+//! Value with UTF8 encoding.
+typedef GenericValue<UTF8<> > Value;
+
+///////////////////////////////////////////////////////////////////////////////
+// GenericDocument
+
+//! A document for parsing JSON text as DOM.
+/*!
+ \implements Handler
+ \tparam Encoding encoding for both parsing and string storage.
+ \tparam Alloactor allocator for allocating memory for the DOM, and the stack during parsing.
+*/
+template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
+class GenericDocument : public GenericValue<Encoding, Allocator> {
+public:
+ typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
+ typedef GenericValue<Encoding, Allocator> ValueType; //!< Value type of the document.
+ typedef Allocator AllocatorType; //!< Allocator type from template parameter.
+
+ //! Constructor
+ /*! \param allocator Optional allocator for allocating stack memory.
+ \param stackCapacity Initial capacity of stack in bytes.
+ */
+ GenericDocument(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity) : stack_(allocator, stackCapacity), parseError_(0), errorOffset_(0) {}
+
+ //! Parse JSON text from an input stream.
+ /*! \tparam parseFlags Combination of ParseFlag.
+ \param stream Input stream to be parsed.
+ \return The document itself for fluent API.
+ */
+ template <unsigned parseFlags, typename Stream>
+ GenericDocument& ParseStream(Stream& stream) {
+ ValueType::SetNull(); // Remove existing root if exist
+ GenericReader<Encoding> reader;
+ if (reader.template Parse<parseFlags>(stream, *this)) {
+ RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
+ this->RawAssign(*stack_.template Pop<ValueType>(1));
+ parseError_ = 0;
+ errorOffset_ = 0;
+ }
+ else {
+ parseError_ = reader.GetParseError();
+ errorOffset_ = reader.GetErrorOffset();
+ ClearStack();
+ }
+ return *this;
+ }
+
+ //! Parse JSON text from a mutable string.
+ /*! \tparam parseFlags Combination of ParseFlag.
+ \param str Mutable zero-terminated string to be parsed.
+ \return The document itself for fluent API.
+ */
+ template <unsigned parseFlags>
+ GenericDocument& ParseInsitu(Ch* str) {
+ GenericInsituStringStream<Encoding> s(str);
+ return ParseStream<parseFlags | kParseInsituFlag>(s);
+ }
+
+ //! Parse JSON text from a read-only string.
+ /*! \tparam parseFlags Combination of ParseFlag (must not contain kParseInsituFlag).
+ \param str Read-only zero-terminated string to be parsed.
+ */
+ template <unsigned parseFlags>
+ GenericDocument& Parse(const Ch* str) {
+ RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
+ GenericStringStream<Encoding> s(str);
+ return ParseStream<parseFlags>(s);
+ }
+
+ //! Whether a parse error was occured in the last parsing.
+ bool HasParseError() const { return parseError_ != 0; }
+
+ //! Get the message of parsing error.
+ const char* GetParseError() const { return parseError_; }
+
+ //! Get the offset in character of the parsing error.
+ size_t GetErrorOffset() const { return errorOffset_; }
+
+ //! Get the allocator of this document.
+ Allocator& GetAllocator() { return stack_.GetAllocator(); }
+
+ //! Get the capacity of stack in bytes.
+ size_t GetStackCapacity() const { return stack_.GetCapacity(); }
+
+private:
+ friend class GenericReader<Encoding>; // for Reader to call the following private handler functions
+
+ // Implementation of Handler
+ void Null() { new (stack_.template Push<ValueType>()) ValueType(); }
+ void Bool(bool b) { new (stack_.template Push<ValueType>()) ValueType(b); }
+ void Int(int i) { new (stack_.template Push<ValueType>()) ValueType(i); }
+ void Uint(unsigned i) { new (stack_.template Push<ValueType>()) ValueType(i); }
+ void Int64(int64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); }
+ void Uint64(uint64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); }
+ void Double(double d) { new (stack_.template Push<ValueType>()) ValueType(d); }
+
+ void String(const Ch* str, SizeType length, bool copy) {
+ if (copy)
+ new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
+ else
+ new (stack_.template Push<ValueType>()) ValueType(str, length);
+ }
+
+ void StartObject() { new (stack_.template Push<ValueType>()) ValueType(kObjectType); }
+
+ void EndObject(SizeType memberCount) {
+ typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
+ stack_.template Top<ValueType>()->SetObjectRaw(members, (SizeType)memberCount, GetAllocator());
+ }
+
+ void StartArray() { new (stack_.template Push<ValueType>()) ValueType(kArrayType); }
+
+ void EndArray(SizeType elementCount) {
+ ValueType* elements = stack_.template Pop<ValueType>(elementCount);
+ stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
+ }
+
+ void ClearStack() {
+ if (Allocator::kNeedFree)
+ while (stack_.GetSize() > 0) // Here assumes all elements in stack array are GenericValue (Member is actually 2 GenericValue objects)
+ (stack_.template Pop<ValueType>(1))->~ValueType();
+ else
+ stack_.Clear();
+ }
+
+ static const size_t kDefaultStackCapacity = 1024;
+ internal::Stack<Allocator> stack_;
+ const char* parseError_;
+ size_t errorOffset_;
+};
+
+typedef GenericDocument<UTF8<> > Document;
+
+} // namespace rapidjson
+
+#endif // RAPIDJSON_DOCUMENT_H_
View
92 libs/network/example/twitter/rapidjson/filestream.h → contrib/http_examples/twitter/rapidjson/filestream.h
@@ -1,46 +1,46 @@
-#ifndef RAPIDJSON_FILESTREAM_H_
-#define RAPIDJSON_FILESTREAM_H_
-
-#include <cstdio>
-
-namespace rapidjson {
-
-//! Wrapper of C file stream for input or output.
-/*!
- This simple wrapper does not check the validity of the stream.
- \implements Stream
-*/
-class FileStream {
-public:
- typedef char Ch; //!< Character type. Only support char.
-
- FileStream(FILE* fp) : fp_(fp), count_(0) { Read(); }
- char Peek() const { return current_; }
- char Take() { char c = current_; Read(); return c; }
- size_t Tell() const { return count_; }
- void Put(char c) { fputc(c, fp_); }
-
- // Not implemented
- char* PutBegin() { return 0; }
- size_t PutEnd(char*) { return 0; }
-
-private:
- void Read() {
- RAPIDJSON_ASSERT(fp_ != 0);
- int c = fgetc(fp_);
- if (c != EOF) {
- current_ = (char)c;
- count_++;
- }
- else
- current_ = '\0';
- }
-
- FILE* fp_;
- char current_;
- size_t count_;
-};
-
-} // namespace rapidjson
-
-#endif // RAPIDJSON_FILESTREAM_H_
+#ifndef RAPIDJSON_FILESTREAM_H_
+#define RAPIDJSON_FILESTREAM_H_
+
+#include <cstdio>
+
+namespace rapidjson {
+
+//! Wrapper of C file stream for input or output.
+/*!
+ This simple wrapper does not check the validity of the stream.
+ \implements Stream
+*/
+class FileStream {
+public:
+ typedef char Ch; //!< Character type. Only support char.
+
+ FileStream(FILE* fp) : fp_(fp), count_(0) { Read(); }
+ char Peek() const { return current_; }
+ char Take() { char c = current_; Read(); return c; }
+ size_t Tell() const { return count_; }
+ void Put(char c) { fputc(c, fp_); }
+
+ // Not implemented
+ char* PutBegin() { return 0; }
+ size_t PutEnd(char*) { return 0; }
+
+private:
+ void Read() {
+ RAPIDJSON_ASSERT(fp_ != 0);
+ int c = fgetc(fp_);
+ if (c != EOF) {
+ current_ = (char)c;
+ count_++;
+ }
+ else
+ current_ = '\0';
+ }
+
+ FILE* fp_;
+ char current_;
+ size_t count_;
+};
+
+} // namespace rapidjson
+
+#endif // RAPIDJSON_FILESTREAM_H_
View
108 ...etwork/example/twitter/rapidjson/internal/pow10.h → .../http_examples/twitter/rapidjson/internal/pow10.h
@@ -1,54 +1,54 @@
-#ifndef RAPIDJSON_POW10_
-#define RAPIDJSON_POW10_
-
-namespace rapidjson {
-namespace internal {
-
-//! Computes integer powers of 10 in double (10.0^n).
-/*! This function uses lookup table for fast and accurate results.
- \param n positive/negative exponent. Must <= 308.
- \return 10.0^n
-*/
-inline double Pow10(int n) {
- static const double e[] = { // 1e-308...1e308: 617 * 8 bytes = 4936 bytes
- 1e-308,1e-307,1e-306,1e-305,1e-304,1e-303,1e-302,1e-301,1e-300,
- 1e-299,1e-298,1e-297,1e-296,1e-295,1e-294,1e-293,1e-292,1e-291,1e-290,1e-289,1e-288,1e-287,1e-286,1e-285,1e-284,1e-283,1e-282,1e-281,1e-280,
- 1e-279,1e-278,1e-277,1e-276,1e-275,1e-274,1e-273,1e-272,1e-271,1e-270,1e-269,1e-268,1e-267,1e-266,1e-265,1e-264,1e-263,1e-262,1e-261,1e-260,
- 1e-259,1e-258,1e-257,1e-256,1e-255,1e-254,1e-253,1e-252,1e-251,1e-250,1e-249,1e-248,1e-247,1e-246,1e-245,1e-244,1e-243,1e-242,1e-241,1e-240,
- 1e-239,1e-238,1e-237,1e-236,1e-235,1e-234,1e-233,1e-232,1e-231,1e-230,1e-229,1e-228,1e-227,1e-226,1e-225,1e-224,1e-223,1e-222,1e-221,1e-220,
- 1e-219,1e-218,1e-217,1e-216,1e-215,1e-214,1e-213,1e-212,1e-211,1e-210,1e-209,1e-208,1e-207,1e-206,1e-205,1e-204,1e-203,1e-202,1e-201,1e-200,
- 1e-199,1e-198,1e-197,1e-196,1e-195,1e-194,1e-193,1e-192,1e-191,1e-190,1e-189,1e-188,1e-187,1e-186,1e-185,1e-184,1e-183,1e-182,1e-181,1e-180,
- 1e-179,1e-178,1e-177,1e-176,1e-175,1e-174,1e-173,1e-172,1e-171,1e-170,1e-169,1e-168,1e-167,1e-166,1e-165,1e-164,1e-163,1e-162,1e-161,1e-160,
- 1e-159,1e-158,1e-157,1e-156,1e-155,1e-154,1e-153,1e-152,1e-151,1e-150,1e-149,1e-148,1e-147,1e-146,1e-145,1e-144,1e-143,1e-142,1e-141,1e-140,
- 1e-139,1e-138,