sjunges
9 years ago
433 changed files with 122595 additions and 0 deletions
-
52resources/3rdparty/modernjson/CMakeLists.txt
-
207resources/3rdparty/modernjson/ChangeLog.md
-
22resources/3rdparty/modernjson/LICENSE.MIT
-
98resources/3rdparty/modernjson/Makefile
-
456resources/3rdparty/modernjson/README.md
-
11resources/3rdparty/modernjson/appveyor.yml
-
77resources/3rdparty/modernjson/benchmarks/benchmarks.cpp
-
401resources/3rdparty/modernjson/benchmarks/benchpress.hpp
-
1312resources/3rdparty/modernjson/benchmarks/cxxopts.hpp
-
1resources/3rdparty/modernjson/benchmarks/files/jeopardy/jeopardy.json.REMOVED.git-id
-
9resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/canada.json
-
50469resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/citm_catalog.json
-
15482resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/twitter.json
-
6resources/3rdparty/modernjson/cmake/config.cmake.in
-
317resources/3rdparty/modernjson/doc/Doxyfile
-
82resources/3rdparty/modernjson/doc/Makefile
-
26resources/3rdparty/modernjson/doc/css/mylayout.css
-
27resources/3rdparty/modernjson/doc/css/mylayout_docset.css
-
36resources/3rdparty/modernjson/doc/examples/README.cpp
-
1resources/3rdparty/modernjson/doc/examples/README.link
-
27resources/3rdparty/modernjson/doc/examples/README.output
-
18resources/3rdparty/modernjson/doc/examples/array.cpp
-
1resources/3rdparty/modernjson/doc/examples/array.link
-
4resources/3rdparty/modernjson/doc/examples/array.output
-
33resources/3rdparty/modernjson/doc/examples/at__object_t_key_type.cpp
-
1resources/3rdparty/modernjson/doc/examples/at__object_t_key_type.link
-
3resources/3rdparty/modernjson/doc/examples/at__object_t_key_type.output
-
27resources/3rdparty/modernjson/doc/examples/at__object_t_key_type_const.cpp
-
1resources/3rdparty/modernjson/doc/examples/at__object_t_key_type_const.link
-
2resources/3rdparty/modernjson/doc/examples/at__object_t_key_type_const.output
-
28resources/3rdparty/modernjson/doc/examples/at__size_type.cpp
-
1resources/3rdparty/modernjson/doc/examples/at__size_type.link
-
3resources/3rdparty/modernjson/doc/examples/at__size_type.output
-
22resources/3rdparty/modernjson/doc/examples/at__size_type_const.cpp
-
1resources/3rdparty/modernjson/doc/examples/at__size_type_const.link
-
2resources/3rdparty/modernjson/doc/examples/at__size_type_const.output
-
35resources/3rdparty/modernjson/doc/examples/at_json_pointer.cpp
-
1resources/3rdparty/modernjson/doc/examples/at_json_pointer.link
-
6resources/3rdparty/modernjson/doc/examples/at_json_pointer.output
-
23resources/3rdparty/modernjson/doc/examples/at_json_pointer_const.cpp
-
1resources/3rdparty/modernjson/doc/examples/at_json_pointer_const.link
-
4resources/3rdparty/modernjson/doc/examples/at_json_pointer_const.output
-
28resources/3rdparty/modernjson/doc/examples/back.cpp
-
1resources/3rdparty/modernjson/doc/examples/back.link
-
6resources/3rdparty/modernjson/doc/examples/back.output
-
12resources/3rdparty/modernjson/doc/examples/basic_json.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json.output
-
58resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleArrayType.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleArrayType.link
-
9resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleArrayType.output
-
27resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleIntegerNumberType.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleIntegerNumberType.link
-
5resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleIntegerNumberType.output
-
21resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleNumberFloatType.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleNumberFloatType.link
-
3resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleNumberFloatType.output
-
41resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleObjectType.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleObjectType.link
-
4resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleObjectType.output
-
15resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleStringType.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleStringType.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleStringType.output
-
21resources/3rdparty/modernjson/doc/examples/basic_json__InputIt_InputIt.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__InputIt_InputIt.link
-
3resources/3rdparty/modernjson/doc/examples/basic_json__InputIt_InputIt.output
-
15resources/3rdparty/modernjson/doc/examples/basic_json__array_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__array_t.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json__array_t.output
-
16resources/3rdparty/modernjson/doc/examples/basic_json__basic_json.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__basic_json.link
-
2resources/3rdparty/modernjson/doc/examples/basic_json__basic_json.output
-
14resources/3rdparty/modernjson/doc/examples/basic_json__boolean_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__boolean_t.link
-
2resources/3rdparty/modernjson/doc/examples/basic_json__boolean_t.output
-
15resources/3rdparty/modernjson/doc/examples/basic_json__const_int.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__const_int.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json__const_int.output
-
17resources/3rdparty/modernjson/doc/examples/basic_json__copyassignment.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__copyassignment.link
-
2resources/3rdparty/modernjson/doc/examples/basic_json__copyassignment.output
-
55resources/3rdparty/modernjson/doc/examples/basic_json__istream.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__istream.link
-
34resources/3rdparty/modernjson/doc/examples/basic_json__istream.output
-
20resources/3rdparty/modernjson/doc/examples/basic_json__list_init_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__list_init_t.link
-
5resources/3rdparty/modernjson/doc/examples/basic_json__list_init_t.output
-
16resources/3rdparty/modernjson/doc/examples/basic_json__moveconstructor.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__moveconstructor.link
-
2resources/3rdparty/modernjson/doc/examples/basic_json__moveconstructor.output
-
12resources/3rdparty/modernjson/doc/examples/basic_json__nullptr_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__nullptr_t.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json__nullptr_t.output
-
21resources/3rdparty/modernjson/doc/examples/basic_json__number_float_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__number_float_t.link
-
3resources/3rdparty/modernjson/doc/examples/basic_json__number_float_t.output
-
14resources/3rdparty/modernjson/doc/examples/basic_json__number_integer_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__number_integer_t.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json__number_integer_t.output
-
15resources/3rdparty/modernjson/doc/examples/basic_json__object_t.cpp
@ -0,0 +1,52 @@ |
|||
cmake_minimum_required(VERSION 3.0) |
|||
|
|||
# define the project |
|||
project(nlohmann_json VERSION 2.0.0 LANGUAGES CXX) |
|||
|
|||
option(BuildTests "Build the unit tests" ON) |
|||
|
|||
# define project variables |
|||
set(JSON_TARGET_NAME ${PROJECT_NAME}) |
|||
set(JSON_PACKAGE_NAME ${JSON_TARGET_NAME}) |
|||
set(JSON_TARGETS_FILENAME "${JSON_PACKAGE_NAME}Targets.cmake") |
|||
set(JSON_CONFIG_FILENAME "${JSON_PACKAGE_NAME}Config.cmake") |
|||
set(JSON_CONFIGVERSION_FILENAME "${JSON_PACKAGE_NAME}ConfigVersion.cmake") |
|||
set(JSON_CONFIG_DESTINATION "cmake") |
|||
set(JSON_INCLUDE_DESTINATION "include/nlohmann") |
|||
|
|||
# create and configure the library target |
|||
add_library(${JSON_TARGET_NAME} INTERFACE) |
|||
target_include_directories(${JSON_TARGET_NAME} INTERFACE |
|||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> |
|||
$<INSTALL_INTERFACE:${JSON_INCLUDE_DESTINATION}>) |
|||
|
|||
# create and configure the unit test target |
|||
if (BuildTests) |
|||
add_subdirectory(test) |
|||
endif() |
|||
|
|||
# generate a config and config version file for the package |
|||
include(CMakePackageConfigHelpers) |
|||
configure_package_config_file("cmake/config.cmake.in" |
|||
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}" |
|||
INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION}) |
|||
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}" |
|||
VERSION ${PROJECT_VERSION} |
|||
COMPATIBILITY SameMajorVersion) |
|||
|
|||
# export the library target and store build directory in package registry |
|||
export(TARGETS ${JSON_TARGET_NAME} |
|||
FILE "${CMAKE_CURRENT_BINARY_DIR}/${JSON_TARGETS_FILENAME}") |
|||
export(PACKAGE ${JSON_PACKAGE_NAME}) |
|||
|
|||
# install library target and config files |
|||
install(TARGETS ${JSON_TARGET_NAME} |
|||
EXPORT ${JSON_PACKAGE_NAME}) |
|||
install(FILES "src/json.hpp" |
|||
DESTINATION ${JSON_INCLUDE_DESTINATION}) |
|||
install(EXPORT ${JSON_PACKAGE_NAME} |
|||
FILE ${JSON_TARGETS_FILENAME} |
|||
DESTINATION ${JSON_CONFIG_DESTINATION}) |
|||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}" |
|||
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}" |
|||
DESTINATION ${JSON_CONFIG_DESTINATION}) |
@ -0,0 +1,207 @@ |
|||
# Change Log |
|||
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). |
|||
|
|||
## [Unreleased](https://github.com/nlohmann/json/tree/HEAD) |
|||
|
|||
[Full Changelog](https://github.com/nlohmann/json/compare/v1.1.0...HEAD) |
|||
|
|||
- Unit test fails when doing a CMake out-of-tree build [\#241](https://github.com/nlohmann/json/issues/241) |
|||
- Additional integration options [\#237](https://github.com/nlohmann/json/issues/237) |
|||
- Can't use basic\_json::iterator as a base iterator for std::move\_iterator [\#233](https://github.com/nlohmann/json/issues/233) |
|||
- Provide a FAQ [\#163](https://github.com/nlohmann/json/issues/163) |
|||
- Create PULL\_REQUEST\_TEMPLATE.md [\#213](https://github.com/nlohmann/json/pull/213) ([whackashoe](https://github.com/whackashoe)) |
|||
- fixed noexcept; added constexpr [\#208](https://github.com/nlohmann/json/pull/208) ([nlohmann](https://github.com/nlohmann)) |
|||
- Add support for afl-fuzz testing [\#207](https://github.com/nlohmann/json/pull/207) ([mykter](https://github.com/mykter)) |
|||
- Issue \#178 - Extending support to full uint64\_t/int64\_t range and unsigned type \(updated\) [\#193](https://github.com/nlohmann/json/pull/193) ([twelsby](https://github.com/twelsby)) |
|||
|
|||
- -Wconversion warnings [\#239](https://github.com/nlohmann/json/issues/239) |
|||
- ambiguous overload for 'push\_back' and 'operator+=' [\#235](https://github.com/nlohmann/json/issues/235) |
|||
- double values are serialized with commas as decimal points [\#228](https://github.com/nlohmann/json/issues/228) |
|||
- Move semantics with std::initializer\_list [\#225](https://github.com/nlohmann/json/issues/225) |
|||
- abort during getline in yyfill [\#223](https://github.com/nlohmann/json/issues/223) |
|||
- Wrong link in the README.md [\#217](https://github.com/nlohmann/json/issues/217) |
|||
- Small bugs in json.hpp \(get\_number\) and unit.cpp \(non-standard integer type test\) [\#199](https://github.com/nlohmann/json/issues/199) |
|||
- GCC/clang floating point parsing bug in strtod\(\) [\#195](https://github.com/nlohmann/json/issues/195) |
|||
- Bugs in miloyip/nativejson-benchmark: roundtrips [\#187](https://github.com/nlohmann/json/issues/187) |
|||
- Floating point exceptions [\#181](https://github.com/nlohmann/json/issues/181) |
|||
- In basic\_json::basic\_json\(const CompatibleArrayType& val\), the requirement of CompatibleArrayType is not strict enough. [\#174](https://github.com/nlohmann/json/issues/174) |
|||
- Implicit assignment to std::string fails [\#144](https://github.com/nlohmann/json/issues/144) |
|||
- Issue \#195 - update Travis to Trusty due to gcc/clang strtod\(\) bug [\#196](https://github.com/nlohmann/json/pull/196) ([twelsby](https://github.com/twelsby)) |
|||
|
|||
- Conflicting typedef of ssize\_t on Windows 32 bit when using Boost.Python [\#204](https://github.com/nlohmann/json/issues/204) |
|||
- Integer conversion to unsigned [\#178](https://github.com/nlohmann/json/issues/178) |
|||
|
|||
- Out of tree builds and a few other miscellaneous CMake cleanups. [\#242](https://github.com/nlohmann/json/pull/242) ([ChrisKitching](https://github.com/ChrisKitching)) |
|||
- Implement additional integration options [\#238](https://github.com/nlohmann/json/pull/238) ([robertmrk](https://github.com/robertmrk)) |
|||
- make serialization locale-independent [\#232](https://github.com/nlohmann/json/pull/232) ([nlohmann](https://github.com/nlohmann)) |
|||
- fixes \#223 by updating README.md [\#227](https://github.com/nlohmann/json/pull/227) ([kevin--](https://github.com/kevin--)) |
|||
- Use namespace std for int64\_t and uint64\_t [\#226](https://github.com/nlohmann/json/pull/226) ([lv-zheng](https://github.com/lv-zheng)) |
|||
- Added missing cerrno header to fix ERANGE compile error on android [\#222](https://github.com/nlohmann/json/pull/222) ([Teemperor](https://github.com/Teemperor)) |
|||
- Corrected readme [\#218](https://github.com/nlohmann/json/pull/218) ([Annihil](https://github.com/Annihil)) |
|||
- replaced ssize\_t occurrences with auto \(addresses \#204\) [\#205](https://github.com/nlohmann/json/pull/205) ([nlohmann](https://github.com/nlohmann)) |
|||
- Fixed issue \#199 - Small bugs in json.hpp \(get\_number\) and unit.cpp \(non-standard integer type test\) [\#200](https://github.com/nlohmann/json/pull/200) ([twelsby](https://github.com/twelsby)) |
|||
- Fix broken link [\#197](https://github.com/nlohmann/json/pull/197) ([vog](https://github.com/vog)) |
|||
|
|||
## [v1.1.0](https://github.com/nlohmann/json/releases/tag/v1.1.0) (2016-01-24) |
|||
[Full Changelog](https://github.com/nlohmann/json/compare/v1.0.0...v1.1.0) |
|||
|
|||
- JSON performance benchmark comparision [\#177](https://github.com/nlohmann/json/issues/177) |
|||
- Since re2c is often ignored in pull requests, it may make sense to make a contributing.md file [\#175](https://github.com/nlohmann/json/issues/175) |
|||
- Add assertions [\#168](https://github.com/nlohmann/json/issues/168) |
|||
- range based for loop for objects [\#83](https://github.com/nlohmann/json/issues/83) |
|||
- Implementation of get\_ref\(\) [\#184](https://github.com/nlohmann/json/pull/184) ([dariomt](https://github.com/dariomt)) |
|||
|
|||
- Small error in pull \#185 [\#194](https://github.com/nlohmann/json/issues/194) |
|||
- Bugs in miloyip/nativejson-benchmark: floating-point parsing [\#186](https://github.com/nlohmann/json/issues/186) |
|||
- Cannot index by key of type static constexpr const char\* [\#171](https://github.com/nlohmann/json/issues/171) |
|||
- Fixed Issue \#171 - added two extra template overloads of operator\[\] for T\* arguments [\#189](https://github.com/nlohmann/json/pull/189) ([twelsby](https://github.com/twelsby)) |
|||
- Fixed issue \#167 - removed operator ValueType\(\) condition for VS2015 [\#188](https://github.com/nlohmann/json/pull/188) ([twelsby](https://github.com/twelsby)) |
|||
|
|||
- Floating point equality [\#185](https://github.com/nlohmann/json/issues/185) |
|||
- Unused variables in catch [\#180](https://github.com/nlohmann/json/issues/180) |
|||
- Typo in documentation [\#179](https://github.com/nlohmann/json/issues/179) |
|||
- Android? [\#172](https://github.com/nlohmann/json/issues/172) |
|||
- MSVC 2015 build fails when attempting to compare object\_t [\#167](https://github.com/nlohmann/json/issues/167) |
|||
- Member detector is not portable [\#166](https://github.com/nlohmann/json/issues/166) |
|||
- Unnecessary const\_cast [\#162](https://github.com/nlohmann/json/issues/162) |
|||
- Consider submitting this to the Boost Library Incubator [\#66](https://github.com/nlohmann/json/issues/66) |
|||
|
|||
- Fixed Issue \#186 - add strto\(f|d|ld\) overload wrappers, "-0.0" special case and FP trailing zero [\#191](https://github.com/nlohmann/json/pull/191) ([twelsby](https://github.com/twelsby)) |
|||
- Issue \#185 - remove approx\(\) and use \#pragma to kill warnings [\#190](https://github.com/nlohmann/json/pull/190) ([twelsby](https://github.com/twelsby)) |
|||
- Fixed some typos in CONTRIBUTING.md [\#182](https://github.com/nlohmann/json/pull/182) ([nibroc](https://github.com/nibroc)) |
|||
|
|||
## [v1.0.0](https://github.com/nlohmann/json/releases/tag/v1.0.0) (2015-12-27) |
|||
[Full Changelog](https://github.com/nlohmann/json/compare/v1.0.0-rc1...v1.0.0) |
|||
|
|||
- add key name to exception [\#160](https://github.com/nlohmann/json/issues/160) |
|||
- prevent json.hpp from emitting compiler warnings [\#154](https://github.com/nlohmann/json/issues/154) |
|||
- json::parse\(string\) does not check utf8 bom [\#152](https://github.com/nlohmann/json/issues/152) |
|||
- unsigned 64bit values output as signed [\#151](https://github.com/nlohmann/json/issues/151) |
|||
- Wish feature: json5 [\#150](https://github.com/nlohmann/json/issues/150) |
|||
- overload of at\(\) with default value [\#133](https://github.com/nlohmann/json/issues/133) |
|||
- Memory leak in face of exceptions [\#118](https://github.com/nlohmann/json/issues/118) |
|||
- Find and Count for arrays [\#117](https://github.com/nlohmann/json/issues/117) |
|||
- dynamically constructing an arbitrarily nested object [\#114](https://github.com/nlohmann/json/issues/114) |
|||
- object field accessors [\#103](https://github.com/nlohmann/json/issues/103) |
|||
- v8pp and json [\#95](https://github.com/nlohmann/json/issues/95) |
|||
- Wishlist [\#65](https://github.com/nlohmann/json/issues/65) |
|||
- Windows/Visual Studio \(through 2013\) is unsupported [\#62](https://github.com/nlohmann/json/issues/62) |
|||
|
|||
- Bug in basic\_json::operator\[\] const overload [\#135](https://github.com/nlohmann/json/issues/135) |
|||
- wrong enable\_if for const pointer \(instead of pointer-to-const\) [\#134](https://github.com/nlohmann/json/issues/134) |
|||
- Visual Studio 14 Debug assertion failed [\#125](https://github.com/nlohmann/json/issues/125) |
|||
- Compile error with g++ 4.9.3 cygwin 64-bit [\#112](https://github.com/nlohmann/json/issues/112) |
|||
- error: unterminated raw string [\#109](https://github.com/nlohmann/json/issues/109) |
|||
- \[clang-3.6.2\] string/sstream with number to json issue [\#107](https://github.com/nlohmann/json/issues/107) |
|||
|
|||
- Getting member discarding qualifyer [\#159](https://github.com/nlohmann/json/issues/159) |
|||
- basic\_json::iterator::value\(\) output includes quotes while basic\_json::iterator::key\(\) doesn't [\#158](https://github.com/nlohmann/json/issues/158) |
|||
- Indexing `const basic\_json\<\>` with `const basic\_string\<char\>` [\#157](https://github.com/nlohmann/json/issues/157) |
|||
- token\_type\_name\(token\_type t\): not all control paths return a value [\#156](https://github.com/nlohmann/json/issues/156) |
|||
- Unable to compile on MSVC 2015 with SDL checking enabled: This function or variable may be unsafe. [\#149](https://github.com/nlohmann/json/issues/149) |
|||
- dump\(\) convert strings encoded by utf-8 to shift-jis on windows 10. [\#147](https://github.com/nlohmann/json/issues/147) |
|||
- Unable to get field names in a json object [\#145](https://github.com/nlohmann/json/issues/145) |
|||
- json.hpp:5746:32: error: 'to\_string' is not a member of 'std' [\#136](https://github.com/nlohmann/json/issues/136) |
|||
- Returning any data type [\#113](https://github.com/nlohmann/json/issues/113) |
|||
- vector\<json\> copy constructor really weird [\#108](https://github.com/nlohmann/json/issues/108) |
|||
- maintaining order of keys during iteration [\#106](https://github.com/nlohmann/json/issues/106) |
|||
|
|||
- Replace sprintf with hex function, this fixes \#149 [\#153](https://github.com/nlohmann/json/pull/153) ([whackashoe](https://github.com/whackashoe)) |
|||
- Fix character skipping after a surrogate pair [\#146](https://github.com/nlohmann/json/pull/146) ([robertmrk](https://github.com/robertmrk)) |
|||
- Detect correctly pointer-to-const [\#137](https://github.com/nlohmann/json/pull/137) ([dariomt](https://github.com/dariomt)) |
|||
- disabled "CopyAssignable" test for MSVC in Debug mode, see \#125 [\#131](https://github.com/nlohmann/json/pull/131) ([dariomt](https://github.com/dariomt)) |
|||
- removed stream operator for iterator, resolution for \#125 [\#130](https://github.com/nlohmann/json/pull/130) ([dariomt](https://github.com/dariomt)) |
|||
- fixed typos in comments for examples [\#129](https://github.com/nlohmann/json/pull/129) ([dariomt](https://github.com/dariomt)) |
|||
- Remove superfluous inefficiency [\#126](https://github.com/nlohmann/json/pull/126) ([d-frey](https://github.com/d-frey)) |
|||
- remove invalid parameter '-stdlib=libc++' in CMakeLists.txt [\#124](https://github.com/nlohmann/json/pull/124) ([emvivre](https://github.com/emvivre)) |
|||
- exception-safe object creation, fixes \#118 [\#122](https://github.com/nlohmann/json/pull/122) ([d-frey](https://github.com/d-frey)) |
|||
- Fix small oversight. [\#121](https://github.com/nlohmann/json/pull/121) ([ColinH](https://github.com/ColinH)) |
|||
- Overload parse\(\) to accept an rvalue reference [\#120](https://github.com/nlohmann/json/pull/120) ([silverweed](https://github.com/silverweed)) |
|||
- Use the right variable name in doc string [\#115](https://github.com/nlohmann/json/pull/115) ([whoshuu](https://github.com/whoshuu)) |
|||
|
|||
## [v1.0.0-rc1](https://github.com/nlohmann/json/releases/tag/v1.0.0-rc1) (2015-07-26) |
|||
- Adjust wording to JSON RFC [\#97](https://github.com/nlohmann/json/issues/97) |
|||
- access by \(const\) reference [\#91](https://github.com/nlohmann/json/issues/91) |
|||
- is\_integer and is\_float tests [\#90](https://github.com/nlohmann/json/issues/90) |
|||
- MinGW have no std::to\_string [\#80](https://github.com/nlohmann/json/issues/80) |
|||
- erase elements using iterators [\#57](https://github.com/nlohmann/json/issues/57) |
|||
- Removing item from array [\#56](https://github.com/nlohmann/json/issues/56) |
|||
- Serialize/Deserialize like PHP? [\#55](https://github.com/nlohmann/json/issues/55) |
|||
- Document erase, count, and iterators key and value [\#52](https://github.com/nlohmann/json/issues/52) |
|||
- Supported compilers [\#50](https://github.com/nlohmann/json/issues/50) |
|||
- Use non-member begin/end [\#48](https://github.com/nlohmann/json/issues/48) |
|||
- Erase key [\#47](https://github.com/nlohmann/json/issues/47) |
|||
- Key iterator [\#46](https://github.com/nlohmann/json/issues/46) |
|||
- Add count member function [\#45](https://github.com/nlohmann/json/issues/45) |
|||
- Printing attribute names [\#39](https://github.com/nlohmann/json/issues/39) |
|||
- Avoid using spaces when encoding without pretty print [\#31](https://github.com/nlohmann/json/issues/31) |
|||
- Cannot encode long numbers [\#30](https://github.com/nlohmann/json/issues/30) |
|||
- Creating an empty array [\#27](https://github.com/nlohmann/json/issues/27) |
|||
- Custom allocator support [\#25](https://github.com/nlohmann/json/issues/25) |
|||
- create a header-only version [\#16](https://github.com/nlohmann/json/issues/16) |
|||
- Add to\_string overload for indentation [\#13](https://github.com/nlohmann/json/issues/13) |
|||
- move code into namespace [\#9](https://github.com/nlohmann/json/issues/9) |
|||
- free functions for explicit objects and arrays in initializer lists [\#8](https://github.com/nlohmann/json/issues/8) |
|||
- Test case coverage [\#2](https://github.com/nlohmann/json/issues/2) |
|||
- Parse streams incrementally. [\#40](https://github.com/nlohmann/json/pull/40) ([aburgh](https://github.com/aburgh)) |
|||
|
|||
- Binary string causes numbers to be dumped as hex [\#101](https://github.com/nlohmann/json/issues/101) |
|||
- failed to iterator json object with reverse\_iterator [\#100](https://github.com/nlohmann/json/issues/100) |
|||
- static analysis warnings [\#94](https://github.com/nlohmann/json/issues/94) |
|||
- reverse\_iterator operator inheritance problem [\#93](https://github.com/nlohmann/json/issues/93) |
|||
- Nonstandard integer type [\#89](https://github.com/nlohmann/json/issues/89) |
|||
- lexer::get\_number return NAN [\#82](https://github.com/nlohmann/json/issues/82) |
|||
- Handle infinity and NaN cases [\#70](https://github.com/nlohmann/json/issues/70) |
|||
- errors in g++-4.8.1 [\#68](https://github.com/nlohmann/json/issues/68) |
|||
- Double quotation mark is not parsed correctly [\#60](https://github.com/nlohmann/json/issues/60) |
|||
- Do not use std::to\_string [\#51](https://github.com/nlohmann/json/issues/51) |
|||
- Confused about iterating through json objects [\#49](https://github.com/nlohmann/json/issues/49) |
|||
- Problem getting vector \(array\) of strings [\#44](https://github.com/nlohmann/json/issues/44) |
|||
- Compilation error due to assuming that private=public [\#43](https://github.com/nlohmann/json/issues/43) |
|||
- Use of deprecated implicit copy constructor [\#42](https://github.com/nlohmann/json/issues/42) |
|||
- dumping a small number\_float just outputs 0.000000 [\#37](https://github.com/nlohmann/json/issues/37) |
|||
- Avoid using spaces when encoding without pretty print [\#31](https://github.com/nlohmann/json/issues/31) |
|||
- Cannot encode long numbers [\#30](https://github.com/nlohmann/json/issues/30) |
|||
- segmentation fault when iterating over empty arrays/objects [\#28](https://github.com/nlohmann/json/issues/28) |
|||
- Improper parsing of JSON string "\\" [\#17](https://github.com/nlohmann/json/issues/17) |
|||
- Don't return "const values" [\#15](https://github.com/nlohmann/json/issues/15) |
|||
- string parser does not recognize uncompliant strings [\#12](https://github.com/nlohmann/json/issues/12) |
|||
- free functions for explicit objects and arrays in initializer lists [\#8](https://github.com/nlohmann/json/issues/8) |
|||
- Runtime error in Travis job [\#1](https://github.com/nlohmann/json/issues/1) |
|||
- Fix compilation of json\_unit with GCC 5 [\#59](https://github.com/nlohmann/json/pull/59) ([dkopecek](https://github.com/dkopecek)) |
|||
|
|||
- Finish documenting the public interface in Doxygen [\#102](https://github.com/nlohmann/json/issues/102) |
|||
- 'noexcept' : unknown override specifier [\#99](https://github.com/nlohmann/json/issues/99) |
|||
- Keys when iterating over objects [\#67](https://github.com/nlohmann/json/issues/67) |
|||
- Complete brief documentation [\#61](https://github.com/nlohmann/json/issues/61) |
|||
- Get coverage back to 100% [\#58](https://github.com/nlohmann/json/issues/58) |
|||
- possible double-free in find function [\#11](https://github.com/nlohmann/json/issues/11) |
|||
- UTF-8 encoding/deconding/testing [\#10](https://github.com/nlohmann/json/issues/10) |
|||
- Add unit tests [\#4](https://github.com/nlohmann/json/issues/4) |
|||
- Drop C++98 support [\#3](https://github.com/nlohmann/json/issues/3) |
|||
|
|||
- Keyword 'inline' is useless when member functions are defined in headers [\#87](https://github.com/nlohmann/json/pull/87) ([ahamez](https://github.com/ahamez)) |
|||
- Remove useless typename [\#86](https://github.com/nlohmann/json/pull/86) ([ahamez](https://github.com/ahamez)) |
|||
- Avoid warning with Xcode's clang [\#85](https://github.com/nlohmann/json/pull/85) ([ahamez](https://github.com/ahamez)) |
|||
- Fix typos [\#73](https://github.com/nlohmann/json/pull/73) ([aqnouch](https://github.com/aqnouch)) |
|||
- Replace `default\_callback` function with `nullptr` and check for null… [\#72](https://github.com/nlohmann/json/pull/72) ([aburgh](https://github.com/aburgh)) |
|||
- support enum [\#71](https://github.com/nlohmann/json/pull/71) ([likebeta](https://github.com/likebeta)) |
|||
- Fix performance regression introduced with the parsing callback feature. [\#69](https://github.com/nlohmann/json/pull/69) ([aburgh](https://github.com/aburgh)) |
|||
- Improve the implementations of the comparission-operators [\#63](https://github.com/nlohmann/json/pull/63) ([Florianjw](https://github.com/Florianjw)) |
|||
- Feature/small float serialization [\#38](https://github.com/nlohmann/json/pull/38) ([jrandall](https://github.com/jrandall)) |
|||
- template version with re2c scanner [\#36](https://github.com/nlohmann/json/pull/36) ([nlohmann](https://github.com/nlohmann)) |
|||
- more descriptive documentation in example [\#33](https://github.com/nlohmann/json/pull/33) ([luxe](https://github.com/luxe)) |
|||
- Fix string conversion under Clang [\#26](https://github.com/nlohmann/json/pull/26) ([wancw](https://github.com/wancw)) |
|||
- Fixed dumping of strings [\#24](https://github.com/nlohmann/json/pull/24) ([Teemperor](https://github.com/Teemperor)) |
|||
- Added a remark to the readme that coverage is GCC only for now [\#23](https://github.com/nlohmann/json/pull/23) ([Teemperor](https://github.com/Teemperor)) |
|||
- Unicode escaping [\#22](https://github.com/nlohmann/json/pull/22) ([Teemperor](https://github.com/Teemperor)) |
|||
- Implemented the JSON spec for string parsing for everything but the \uXXXX escaping [\#21](https://github.com/nlohmann/json/pull/21) ([Teemperor](https://github.com/Teemperor)) |
|||
- add the std iterator typedefs to iterator and const\_iterator [\#19](https://github.com/nlohmann/json/pull/19) ([kirkshoop](https://github.com/kirkshoop)) |
|||
- Fixed escaped quotes [\#18](https://github.com/nlohmann/json/pull/18) ([Teemperor](https://github.com/Teemperor)) |
|||
- Fix double delete on std::bad\_alloc exception [\#14](https://github.com/nlohmann/json/pull/14) ([elliotgoodrich](https://github.com/elliotgoodrich)) |
|||
- Added CMake and lcov [\#6](https://github.com/nlohmann/json/pull/6) ([Teemperor](https://github.com/Teemperor)) |
|||
- Version 2.0 [\#5](https://github.com/nlohmann/json/pull/5) ([nlohmann](https://github.com/nlohmann)) |
|||
|
|||
|
|||
|
|||
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* |
@ -0,0 +1,22 @@ |
|||
The library is licensed under the MIT License |
|||
<http://opensource.org/licenses/MIT>: |
|||
|
|||
Copyright (c) 2013-2016 Niels Lohmann |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy of |
|||
this software and associated documentation files (the "Software"), to deal in |
|||
the Software without restriction, including without limitation the rights to |
|||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
|||
of the Software, and to permit persons to whom the Software is furnished to do |
|||
so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
@ -0,0 +1,98 @@ |
|||
.PHONY: pretty clean ChangeLog.md |
|||
|
|||
# used programs
|
|||
RE2C = re2c |
|||
SED = sed |
|||
|
|||
# main target
|
|||
all: json_unit |
|||
|
|||
# clean up
|
|||
clean: |
|||
rm -fr json_unit json_benchmarks fuzz fuzz-testing *.dSYM |
|||
|
|||
|
|||
##########################################################################
|
|||
# unit tests
|
|||
##########################################################################
|
|||
|
|||
# additional flags
|
|||
FLAGS = -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder -Wdeprecated -Wfloat-equal |
|||
|
|||
# build unit tests (TODO: Does this want its own makefile?)
|
|||
json_unit: test/src/unit.cpp src/json.hpp test/src/catch.hpp |
|||
$(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src -I test $< $(LDFLAGS) -o $@ |
|||
|
|||
|
|||
##########################################################################
|
|||
# documentation tests
|
|||
##########################################################################
|
|||
|
|||
# compile example files and check output
|
|||
doctest: |
|||
make check_output -C doc |
|||
|
|||
|
|||
##########################################################################
|
|||
# fuzzing
|
|||
##########################################################################
|
|||
|
|||
# the overall fuzz testing target
|
|||
fuzz_testing: |
|||
rm -fr fuzz-testing |
|||
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out |
|||
$(MAKE) fuzz CXX=afl-clang++ |
|||
mv fuzz fuzz-testing |
|||
find test/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases |
|||
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzz" |
|||
|
|||
# the fuzzer binary
|
|||
fuzz: test/src/fuzz.cpp src/json.hpp |
|||
$(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src $< $(LDFLAGS) -o $@ |
|||
|
|||
|
|||
##########################################################################
|
|||
# static analyzer
|
|||
##########################################################################
|
|||
|
|||
# call cppcheck on the main header file
|
|||
cppcheck: |
|||
cppcheck --enable=all --inconclusive --std=c++11 src/json.hpp |
|||
|
|||
|
|||
##########################################################################
|
|||
# maintainer targets
|
|||
##########################################################################
|
|||
|
|||
# create scanner with re2c
|
|||
re2c: src/json.hpp.re2c |
|||
$(RE2C) --bit-vectors --nested-ifs --no-debug-info $< | $(SED) '1d' > src/json.hpp |
|||
|
|||
# pretty printer
|
|||
pretty: |
|||
astyle --style=allman --indent=spaces=4 --indent-modifiers \
|
|||
--indent-switches --indent-preproc-block --indent-preproc-define \
|
|||
--indent-col1-comments --pad-oper --pad-header --align-pointer=type \
|
|||
--align-reference=type --add-brackets --convert-tabs --close-templates \
|
|||
--lineend=linux --preserve-date --suffix=none --formatted \
|
|||
src/json.hpp src/json.hpp.re2c test/src/unit.cpp test/src/fuzz.cpp benchmarks/benchmarks.cpp doc/examples/*.cpp |
|||
|
|||
|
|||
##########################################################################
|
|||
# benchmarks
|
|||
##########################################################################
|
|||
|
|||
# benchmarks
|
|||
json_benchmarks: benchmarks/benchmarks.cpp benchmarks/benchpress.hpp benchmarks/cxxopts.hpp src/json.hpp |
|||
$(CXX) -std=c++11 $(CXXFLAGS) -O3 -flto -I src -I benchmarks $< $(LDFLAGS) -o $@ |
|||
./json_benchmarks |
|||
|
|||
|
|||
##########################################################################
|
|||
# changelog
|
|||
##########################################################################
|
|||
|
|||
ChangeLog.md: |
|||
github_changelog_generator -o ChangeLog.md --simple-list --release-url https://github.com/nlohmann/json/releases/tag/%s |
|||
gsed -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md |
|||
gsed -i '2i All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).' ChangeLog.md |
@ -0,0 +1,456 @@ |
|||
![JSON for Modern C++](https://raw.githubusercontent.com/nlohmann/json/master/doc/json.gif) |
|||
|
|||
[![Build Status](https://travis-ci.org/nlohmann/json.svg?branch=master)](https://travis-ci.org/nlohmann/json) |
|||
[![Build Status](https://ci.appveyor.com/api/projects/status/1acb366xfyg3qybk?svg=true)](https://ci.appveyor.com/project/nlohmann/json) |
|||
[![Coverage Status](https://img.shields.io/coveralls/nlohmann/json.svg)](https://coveralls.io/r/nlohmann/json) |
|||
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](http://melpon.org/wandbox/permlink/wuiuqYiYqRTdI3rG) |
|||
[![Documentation Status](https://img.shields.io/badge/docs-doxygen-blue.svg)](http://nlohmann.github.io/json) |
|||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT) |
|||
[![Github Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases) |
|||
[![Github Issues](https://img.shields.io/github/issues/nlohmann/json.svg)](http://github.com/nlohmann/json/issues) |
|||
|
|||
## Design goals |
|||
|
|||
There are myriads of [JSON](http://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals: |
|||
|
|||
- **Intuitive syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you know, what I mean. |
|||
|
|||
- **Trivial integration**. Our whole code consists of a single header file `json.hpp`. That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings. |
|||
|
|||
- **Serious testing**. Our class is heavily [unit-tested](https://github.com/nlohmann/json/blob/master/test/src/unit.cpp) and covers [100%](https://coveralls.io/r/nlohmann/json) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](http://valgrind.org) that there are no memory leaks. |
|||
|
|||
Other aspects were not so important to us: |
|||
|
|||
- **Memory efficiency**. Each JSON object has an overhead of one pointer (the maximal size of a union) and one enumeration element (1 byte). The default generalization uses the following C++ data types: `std::string` for strings, `int64_t`, `uint64_t` or `double` for numbers, `std::map` for objects, `std::vector` for arrays, and `bool` for Booleans. However, you can template the generalized class `basic_json` to your needs. |
|||
|
|||
- **Speed**. We currently implement the parser as naive [recursive descent parser](http://en.wikipedia.org/wiki/Recursive_descent_parser) with hand coded string handling. It is fast enough, but a [LALR-parser](http://en.wikipedia.org/wiki/LALR_parser) with a decent regular expression processor should be even faster (but would consist of more files which makes the integration harder). |
|||
|
|||
See the [contribution guidelines](https://github.com/nlohmann/json/blob/master/.github/CONTRIBUTING.md#please-dont) for more information. |
|||
|
|||
## Integration |
|||
|
|||
The single required source, file `json.hpp` is in the `src` directory or [released here](https://github.com/nlohmann/json/releases). All you need to do is add |
|||
|
|||
```cpp |
|||
#include "json.hpp" |
|||
|
|||
// for convenience |
|||
using json = nlohmann::json; |
|||
``` |
|||
|
|||
to the files you want to use JSON objects. That's it. Do not forget to set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang). |
|||
|
|||
## Supported compilers |
|||
|
|||
Though it's 2016 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work: |
|||
|
|||
- GCC 4.9 - 6.0 (and possibly later) |
|||
- Clang 3.4 - 3.9 (and possibly later) |
|||
- Microsoft Visual C++ 14.0 RC (and possibly later) |
|||
|
|||
The code is currently checked with Travis for GCC 4.9, GCC |
|||
|
|||
I would be happy to learn about other compilers/versions. |
|||
|
|||
Please note: |
|||
|
|||
- GCC 4.8 does not work because of two bugs ([55817](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55817) and [57824](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57824)) in the C++11 support. Note there is a [pull request](https://github.com/nlohmann/json/pull/212) to fix some of the issues. |
|||
- Android defaults to using very old compilers and C++ libraries. To fix this, add the following to your `Application.mk`. This will switch to the LLVM C++ library, the Clang compiler, and enable C++11 and other features disabled by default. |
|||
|
|||
``` |
|||
APP_STL := c++_shared |
|||
NDK_TOOLCHAIN_VERSION := clang3.6 |
|||
APP_CPPFLAGS += -frtti -fexceptions |
|||
``` |
|||
|
|||
- For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MinGW, please refer to [this site](http://tehsausage.com/mingw-to-string) and [this discussion](https://github.com/nlohmann/json/issues/136) for information on how to fix this bug. |
|||
|
|||
The following compilers are currently used in [continuous integration](https://travis-ci.org/nlohmann/json): |
|||
|
|||
| Compiler | Operating System | Version String | |
|||
|-----------------|------------------------------|----------------| |
|||
| GCC 4.9.3 | Ubuntu 14.04.3 LTS | g++-4.9 (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3 | |
|||
| GCC 5.3.0 | Ubuntu 14.04.3 LTS | g++-5 (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204 | |
|||
| Clang 3.6.2 | Ubuntu 14.04.3 LTS | Ubuntu clang version 3.6.2-svn240577-1~exp1 (branches/release_36) (based on LLVM 3.6.2) | |
|||
| Clang 3.7.1 | Ubuntu 14.04.3 LTS | Ubuntu clang version 3.7.1-svn253571-1~exp1 (branches/release_37) (based on LLVM 3.7.1) | |
|||
| Clang 3.8.1 | Ubuntu 14.04.3 LTS | clang version 3.8.1-svn265380-1~exp1 (branches/release_38) | |
|||
| Clang 3.9.0 | Ubuntu 14.04.3 LTS | clang version 3.9.0-svn267478-1~exp1 (trunk) | |
|||
| Clang Xcode 6.1 | Darwin Kernel Version 13.4.0 | Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) | |
|||
| Clang Xcode 6.2 | Darwin Kernel Version 13.4.0 | Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn) | |
|||
| Clang Xcode 6.3 | Darwin Kernel Version 14.3.0 | Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn) | |
|||
| Clang Xcode 6.4 | Darwin Kernel Version 14.3.0 | Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) | |
|||
| Clang Xcode 7.1 | Darwin Kernel Version 14.5.0 | Apple LLVM version 7.0.0 (clang-700.1.76) | |
|||
| Clang Xcode 7.2 | Darwin Kernel Version 15.0.0 | Apple LLVM version 7.0.2 (clang-700.1.81) | |
|||
| Clang Xcode 7.3 | Darwin Kernel Version 14.5.0 | Apple LLVM version 7.3.0 (clang-703.0.29) | |
|||
| Visual Studio 14 2015 | Windows Server 2012 R2 (x64) | Microsoft (R) Build Engine version 14.0.25123.0 | |
|||
|
|||
## Examples |
|||
|
|||
Here are some examples to give you an idea how to use the class. |
|||
|
|||
Assume you want to create the JSON object |
|||
|
|||
```json |
|||
{ |
|||
"pi": 3.141, |
|||
"happy": true, |
|||
"name": "Niels", |
|||
"nothing": null, |
|||
"answer": { |
|||
"everything": 42 |
|||
}, |
|||
"list": [1, 0, 2], |
|||
"object": { |
|||
"currency": "USD", |
|||
"value": 42.99 |
|||
} |
|||
} |
|||
``` |
|||
|
|||
With the JSON class, you could write: |
|||
|
|||
```cpp |
|||
// create an empty structure (null) |
|||
json j; |
|||
|
|||
// add a number that is stored as double (note the implicit conversion of j to an object) |
|||
j["pi"] = 3.141; |
|||
|
|||
// add a Boolean that is stored as bool |
|||
j["happy"] = true; |
|||
|
|||
// add a string that is stored as std::string |
|||
j["name"] = "Niels"; |
|||
|
|||
// add another null object by passing nullptr |
|||
j["nothing"] = nullptr; |
|||
|
|||
// add an object inside the object |
|||
j["answer"]["everything"] = 42; |
|||
|
|||
// add an array that is stored as std::vector (using an initializer list) |
|||
j["list"] = { 1, 0, 2 }; |
|||
|
|||
// add another object (using an initializer list of pairs) |
|||
j["object"] = { {"currency", "USD"}, {"value", 42.99} }; |
|||
|
|||
// instead, you could also write (which looks very similar to the JSON above) |
|||
json j2 = { |
|||
{"pi", 3.141}, |
|||
{"happy", true}, |
|||
{"name", "Niels"}, |
|||
{"nothing", nullptr}, |
|||
{"answer", { |
|||
{"everything", 42} |
|||
}}, |
|||
{"list", {1, 0, 2}}, |
|||
{"object", { |
|||
{"currency", "USD"}, |
|||
{"value", 42.99} |
|||
}} |
|||
}; |
|||
``` |
|||
|
|||
Note that in all these cases, you never need to "tell" the compiler which JSON value you want to use. If you want to be explicit or express some edge cases, the functions `json::array` and `json::object` will help: |
|||
|
|||
```cpp |
|||
// a way to express the empty array [] |
|||
json empty_array_explicit = json::array(); |
|||
|
|||
// ways to express the empty object {} |
|||
json empty_object_implicit = json({}); |
|||
json empty_object_explicit = json::object(); |
|||
|
|||
// a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]] |
|||
json array_not_object = { json::array({"currency", "USD"}), json::array({"value", 42.99}) }; |
|||
``` |
|||
|
|||
### Serialization / Deserialization |
|||
|
|||
You can create an object (deserialization) by appending `_json` to a string literal: |
|||
|
|||
```cpp |
|||
// create object from string literal |
|||
json j = "{ \"happy\": true, \"pi\": 3.141 }"_json; |
|||
|
|||
// or even nicer (thanks http://isocpp.org/blog/2015/01/json-for-modern-cpp) |
|||
auto j2 = R"( |
|||
{ |
|||
"happy": true, |
|||
"pi": 3.141 |
|||
} |
|||
)"_json; |
|||
|
|||
// or explicitly |
|||
auto j3 = json::parse("{ \"happy\": true, \"pi\": 3.141 }"); |
|||
``` |
|||
|
|||
You can also get a string representation (serialize): |
|||
|
|||
```cpp |
|||
// explicit conversion to string |
|||
std::string s = j.dump(); // {\"happy\":true,\"pi\":3.141} |
|||
|
|||
// serialization with pretty printing |
|||
// pass in the amount of spaces to indent |
|||
std::cout << j.dump(4) << std::endl; |
|||
// { |
|||
// "happy": true, |
|||
// "pi": 3.141 |
|||
// } |
|||
``` |
|||
|
|||
You can also use streams to serialize and deserialize: |
|||
|
|||
```cpp |
|||
// deserialize from standard input |
|||
json j; |
|||
std::cin >> j; |
|||
|
|||
// serialize to standard output |
|||
std::cout << j; |
|||
|
|||
// the setw manipulator was overloaded to set the indentation for pretty printing |
|||
std::cout << std::setw(4) << j << std::endl; |
|||
``` |
|||
|
|||
These operators work for any subclasses of `std::istream` or `std::ostream`. |
|||
|
|||
Please note that setting the exception bit for `failbit` is inappropriate for this use case. It will result in program termination due to the `noexcept` specifier in use. |
|||
|
|||
### STL-like access |
|||
|
|||
We designed the JSON class to behave just like an STL container. In fact, it satisfies the [**ReversibleContainer**](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) requirement. |
|||
|
|||
```cpp |
|||
// create an array using push_back |
|||
json j; |
|||
j.push_back("foo"); |
|||
j.push_back(1); |
|||
j.push_back(true); |
|||
|
|||
// iterate the array |
|||
for (json::iterator it = j.begin(); it != j.end(); ++it) { |
|||
std::cout << *it << '\n'; |
|||
} |
|||
|
|||
// range-based for |
|||
for (auto& element : j) { |
|||
std::cout << element << '\n'; |
|||
} |
|||
|
|||
// getter/setter |
|||
const std::string tmp = j[0]; |
|||
j[1] = 42; |
|||
bool foo = j.at(2); |
|||
|
|||
// other stuff |
|||
j.size(); // 3 entries |
|||
j.empty(); // false |
|||
j.type(); // json::value_t::array |
|||
j.clear(); // the array is empty again |
|||
|
|||
// convenience type checkers |
|||
j.is_null(); |
|||
j.is_boolean(); |
|||
j.is_number(); |
|||
j.is_object(); |
|||
j.is_array(); |
|||
j.is_string(); |
|||
|
|||
// comparison |
|||
j == "[\"foo\", 1, true]"_json; // true |
|||
|
|||
// create an object |
|||
json o; |
|||
o["foo"] = 23; |
|||
o["bar"] = false; |
|||
o["baz"] = 3.141; |
|||
|
|||
// special iterator member functions for objects |
|||
for (json::iterator it = o.begin(); it != o.end(); ++it) { |
|||
std::cout << it.key() << " : " << it.value() << "\n"; |
|||
} |
|||
|
|||
// find an entry |
|||
if (o.find("foo") != o.end()) { |
|||
// there is an entry with key "foo" |
|||
} |
|||
|
|||
// or simpler using count() |
|||
int foo_present = o.count("foo"); // 1 |
|||
int fob_present = o.count("fob"); // 0 |
|||
|
|||
// delete an entry |
|||
o.erase("foo"); |
|||
``` |
|||
|
|||
### Conversion from STL containers |
|||
|
|||
Any sequence container (`std::array`, `std::vector`, `std::deque`, `std::forward_list`, `std::list`) whose values can be used to construct JSON types (e.g., integers, floating point numbers, Booleans, string types, or again STL containers described in this section) can be used to create a JSON array. The same holds for similar associative containers (`std::set`, `std::multiset`, `std::unordered_set`, `std::unordered_multiset`), but in these cases the order of the elements of the array depends how the elements are ordered in the respective STL container. |
|||
|
|||
```cpp |
|||
std::vector<int> c_vector {1, 2, 3, 4}; |
|||
json j_vec(c_vector); |
|||
// [1, 2, 3, 4] |
|||
|
|||
std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6}; |
|||
json j_deque(c_deque); |
|||
// [1.2, 2.3, 3.4, 5.6] |
|||
|
|||
std::list<bool> c_list {true, true, false, true}; |
|||
json j_list(c_list); |
|||
// [true, true, false, true] |
|||
|
|||
std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543}; |
|||
json j_flist(c_flist); |
|||
// [12345678909876, 23456789098765, 34567890987654, 45678909876543] |
|||
|
|||
std::array<unsigned long, 4> c_array {{1, 2, 3, 4}}; |
|||
json j_array(c_array); |
|||
// [1, 2, 3, 4] |
|||
|
|||
std::set<std::string> c_set {"one", "two", "three", "four", "one"}; |
|||
json j_set(c_set); // only one entry for "one" is used |
|||
// ["four", "one", "three", "two"] |
|||
|
|||
std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"}; |
|||
json j_uset(c_uset); // only one entry for "one" is used |
|||
// maybe ["two", "three", "four", "one"] |
|||
|
|||
std::multiset<std::string> c_mset {"one", "two", "one", "four"}; |
|||
json j_mset(c_mset); // only one entry for "one" is used |
|||
// maybe ["one", "two", "four"] |
|||
|
|||
std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"}; |
|||
json j_umset(c_umset); // both entries for "one" are used |
|||
// maybe ["one", "two", "one", "four"] |
|||
``` |
|||
|
|||
Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys are can construct an `std::string` and whose values can be used to construct JSON types (see examples above) can be used to to create a JSON object. Note that in case of multimaps only one key is used in the JSON object and the value depends on the internal order of the STL container. |
|||
|
|||
```cpp |
|||
std::map<std::string, int> c_map { {"one", 1}, {"two", 2}, {"three", 3} }; |
|||
json j_map(c_map); |
|||
// {"one": 1, "three": 3, "two": 2 } |
|||
|
|||
std::unordered_map<const char*, double> c_umap { {"one", 1.2}, {"two", 2.3}, {"three", 3.4} }; |
|||
json j_umap(c_umap); |
|||
// {"one": 1.2, "two": 2.3, "three": 3.4} |
|||
|
|||
std::multimap<std::string, bool> c_mmap { {"one", true}, {"two", true}, {"three", false}, {"three", true} }; |
|||
json j_mmap(c_mmap); // only one entry for key "three" is used |
|||
// maybe {"one": true, "two": true, "three": true} |
|||
|
|||
std::unordered_multimap<std::string, bool> c_ummap { {"one", true}, {"two", true}, {"three", false}, {"three", true} }; |
|||
json j_ummap(c_ummap); // only one entry for key "three" is used |
|||
// maybe {"one": true, "two": true, "three": true} |
|||
``` |
|||
|
|||
### Implicit conversions |
|||
|
|||
The type of the JSON object is determined automatically by the expression to store. Likewise, the stored value is implicitly converted. |
|||
|
|||
```cpp |
|||
/// strings |
|||
std::string s1 = "Hello, world!"; |
|||
json js = s1; |
|||
std::string s2 = js; |
|||
|
|||
// Booleans |
|||
bool b1 = true; |
|||
json jb = b1; |
|||
bool b2 = jb; |
|||
|
|||
// numbers |
|||
int i = 42; |
|||
json jn = i; |
|||
double f = jn; |
|||
|
|||
// etc. |
|||
``` |
|||
|
|||
You can also explicitly ask for the value: |
|||
|
|||
```cpp |
|||
std::string vs = js.get<std::string>(); |
|||
bool vb = jb.get<bool>(); |
|||
int vi = jn.get<int>(); |
|||
|
|||
// etc. |
|||
``` |
|||
|
|||
## License |
|||
|
|||
<img align="right" src="http://opensource.org/trademarks/opensource/OSI-Approved-License-100x137.png"> |
|||
|
|||
The class is licensed under the [MIT License](http://opensource.org/licenses/MIT): |
|||
|
|||
Copyright © 2013-2016 [Niels Lohmann](http://nlohmann.me) |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
|
|||
## Thanks |
|||
|
|||
I deeply appreciate the help of the following people. |
|||
|
|||
- [Teemperor](https://github.com/Teemperor) implemented CMake support and lcov integration, realized escape and Unicode handling in the string parser, and fixed the JSON serialization. |
|||
- [elliotgoodrich](https://github.com/elliotgoodrich) fixed an issue with double deletion in the iterator classes. |
|||
- [kirkshoop](https://github.com/kirkshoop) made the iterators of the class composable to other libraries. |
|||
- [wancw](https://github.com/wanwc) fixed a bug that hindered the class to compile with Clang. |
|||
- Tomas Åblad found a bug in the iterator implementation. |
|||
- [Joshua C. Randall](https://github.com/jrandall) fixed a bug in the floating-point serialization. |
|||
- [Aaron Burghardt](https://github.com/aburgh) implemented code to parse streams incrementally. Furthermore, he greatly improved the parser class by allowing the definition of a filter function to discard undesired elements while parsing. |
|||
- [Daniel Kopeček](https://github.com/dkopecek) fixed a bug in the compilation with GCC 5.0. |
|||
- [Florian Weber](https://github.com/Florianjw) fixed a bug in and improved the performance of the comparison operators. |
|||
- [Eric Cornelius](https://github.com/EricMCornelius) pointed out a bug in the handling with NaN and infinity values. He also improved the performance of the string escaping. |
|||
- [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums. |
|||
- [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual studio. |
|||
- [gregmarr](https://github.com/gregmarr) simplified the implementation of reverse iterators and helped with numerous hints and improvements. |
|||
- [Caio Luppi](https://github.com/caiovlp) fixed a bug in the Unicode handling. |
|||
- [dariomt](https://github.com/dariomt) fixed some typos in the examples. |
|||
- [Daniel Frey](https://github.com/d-frey) cleaned up some pointers and implemented exception-safe memory allocation. |
|||
- [Colin Hirsch](https://github.com/ColinH) took care of a small namespace issue. |
|||
- [Huu Nguyen](https://github.com/whoshuu) correct a variable name in the documentation. |
|||
- [Silverweed](https://github.com/silverweed) overloaded `parse()` to accept an rvalue reference. |
|||
- [dariomt](https://github.com/dariomt) fixed a subtlety in MSVC type support and implemented the `get_ref()` function to get a reference to stored values. |
|||
- [ZahlGraf](https://github.com/ZahlGraf) added a workaround that allows compilation using Android NDK. |
|||
- [whackashoe](https://github.com/whackashoe) replaced a function that was marked as unsafe by Visual Studio. |
|||
- [406345](https://github.com/406345) fixed two small warnings. |
|||
- [Glen Fernandes](https://github.com/glenfe) noted a potential portability problem in the `has_mapped_type` function. |
|||
- [Corbin Hughes](https://github.com/nibroc) fixed some typos in the contribution guidelines. |
|||
- [twelsby](https://github.com/twelsby) fixed the array subscript operator, an issue that failed the MSVC build, and floating-point parsing/dumping. He further added support for unsigned integer numbers and implemented better roundtrip support for parsed numbers. |
|||
- [Volker Diels-Grabsch](https://github.com/vog) fixed a link in the README file. |
|||
- [msm-](https://github.com/msm-) added support for american fuzzy lop. |
|||
- [Annihil](https://github.com/Annihil) fixed an example in the README file. |
|||
- [Themercee](https://github.com/Themercee) noted a wrong URL in the README file. |
|||
- [Lv Zheng](https://github.com/lv-zheng) fixed a namespace issue with `int64_t` and `uint64_t`. |
|||
- [abc100m](https://github.com/abc100m) analyzed the issues with GCC 4.8 and proposed a [partial solution](https://github.com/nlohmann/json/pull/212). |
|||
- [zewt](https://github.com/zewt) added useful notes to the README file about Android. |
|||
- [Róbert Márki](https://github.com/robertmrk) added a fix to use move iterators and improved the integration via CMake. |
|||
- [Chris Kitching](https://github.com/ChrisKitching) cleaned up the CMake files. |
|||
|
|||
Thanks a lot for helping out! |
|||
|
|||
## Notes |
|||
|
|||
- The code contains numerous debug **assertions** which can be switched off by defining the preprocessor macro `NDEBUG`, see the [documentation of `assert`](http://en.cppreference.com/w/cpp/error/assert). |
|||
- As the exact type of a number is not defined in the [JSON specification](http://rfc7159.net/rfc7159), this library tries to choose the best fitting C++ number type automatically. As a result, the type `double` may be used to store numbers which may yield [**floating-point exceptions**](https://github.com/nlohmann/json/issues/181) in certain rare situations if floating-point exceptions have been unmasked in the calling code. These exceptions are not caused by the library and need to be fixed in the calling code, such as by re-masking the exceptions prior to calling library functions. |
|||
|
|||
## Execute unit tests |
|||
|
|||
To compile and run the tests, you need to execute |
|||
|
|||
```sh |
|||
$ make |
|||
$ ./json_unit "*" |
|||
|
|||
=============================================================================== |
|||
All tests passed (5568705 assertions in 31 test cases) |
|||
``` |
|||
|
|||
For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml). |
@ -0,0 +1,11 @@ |
|||
version: '{build}' |
|||
os: Visual Studio 2015 |
|||
init: [] |
|||
install: [] |
|||
build_script: |
|||
- set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH% |
|||
- cmake . -G "Visual Studio 14 2015" |
|||
- cmake --build . --config Release |
|||
test_script: |
|||
- test\Release\json_unit.exe |
|||
- test\Release\json_unit.exe "*" |
@ -0,0 +1,77 @@ |
|||
#define BENCHPRESS_CONFIG_MAIN
|
|||
|
|||
#include <fstream>
|
|||
#include <benchpress.hpp>
|
|||
#include <json.hpp>
|
|||
|
|||
BENCHMARK("parse jeopardy.json", [](benchpress::context* ctx) |
|||
{ |
|||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|||
{ |
|||
std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json"); |
|||
nlohmann::json j; |
|||
j << input_file; |
|||
} |
|||
}) |
|||
|
|||
BENCHMARK("parse canada.json", [](benchpress::context* ctx) |
|||
{ |
|||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|||
{ |
|||
std::ifstream input_file("benchmarks/files/nativejson-benchmark/canada.json"); |
|||
nlohmann::json j; |
|||
j << input_file; |
|||
} |
|||
}) |
|||
|
|||
BENCHMARK("parse citm_catalog.json", [](benchpress::context* ctx) |
|||
{ |
|||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|||
{ |
|||
std::ifstream input_file("benchmarks/files/nativejson-benchmark/citm_catalog.json"); |
|||
nlohmann::json j; |
|||
j << input_file; |
|||
} |
|||
}) |
|||
|
|||
BENCHMARK("parse twitter.json", [](benchpress::context* ctx) |
|||
{ |
|||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|||
{ |
|||
std::ifstream input_file("benchmarks/files/nativejson-benchmark/twitter.json"); |
|||
nlohmann::json j; |
|||
j << input_file; |
|||
} |
|||
}) |
|||
|
|||
BENCHMARK("dump jeopardy.json", [](benchpress::context* ctx) |
|||
{ |
|||
std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json"); |
|||
nlohmann::json j; |
|||
j << input_file; |
|||
std::ofstream output_file("jeopardy.dump.json"); |
|||
|
|||
ctx->reset_timer(); |
|||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|||
{ |
|||
output_file << j; |
|||
} |
|||
|
|||
std::remove("jeopardy.dump.json"); |
|||
}) |
|||
|
|||
BENCHMARK("dump jeopardy.json with indent", [](benchpress::context* ctx) |
|||
{ |
|||
std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json"); |
|||
nlohmann::json j; |
|||
j << input_file; |
|||
std::ofstream output_file("jeopardy.dump.json"); |
|||
|
|||
ctx->reset_timer(); |
|||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|||
{ |
|||
output_file << std::setw(4) << j; |
|||
} |
|||
|
|||
std::remove("jeopardy.dump.json"); |
|||
}) |
@ -0,0 +1,401 @@ |
|||
/*
|
|||
* Copyright (C) 2015 Christopher Gilbert. |
|||
* |
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to deal |
|||
* in the Software without restriction, including without limitation the rights |
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
* copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in all |
|||
* copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
* SOFTWARE. |
|||
*/ |
|||
#ifndef BENCHPRESS_HPP
|
|||
#define BENCHPRESS_HPP
|
|||
|
|||
#include <algorithm> // max, min
|
|||
#include <atomic> // atomic_intmax_t
|
|||
#include <chrono> // high_resolution_timer, duration
|
|||
#include <functional> // function
|
|||
#include <iomanip> // setw
|
|||
#include <iostream> // cout
|
|||
#include <regex> // regex, regex_match
|
|||
#include <sstream> // stringstream
|
|||
#include <string> // string
|
|||
#include <thread> // thread
|
|||
#include <vector> // vector
|
|||
|
|||
namespace benchpress { |
|||
|
|||
/*
|
|||
* The options class encapsulates all options for running benchmarks. |
|||
* |
|||
* When including benchpress, a main function can be emitted which includes a command-line parser for building an |
|||
* options object. However from time-to-time it may be necessary for the developer to have to build their own main |
|||
* stub and construct the options object manually. |
|||
* |
|||
* options opts; |
|||
* opts |
|||
* .bench(".*") |
|||
* .benchtime(1) |
|||
* .cpu(4); |
|||
*/ |
|||
class options { |
|||
std::string d_bench; |
|||
size_t d_benchtime; |
|||
size_t d_cpu; |
|||
public: |
|||
options() |
|||
: d_bench(".*") |
|||
, d_benchtime(1) |
|||
, d_cpu(std::thread::hardware_concurrency()) |
|||
{} |
|||
options& bench(const std::string& bench) { |
|||
d_bench = bench; |
|||
return *this; |
|||
} |
|||
options& benchtime(size_t benchtime) { |
|||
d_benchtime = benchtime; |
|||
return *this; |
|||
} |
|||
options& cpu(size_t cpu) { |
|||
d_cpu = cpu; |
|||
return *this; |
|||
} |
|||
std::string get_bench() const { |
|||
return d_bench; |
|||
} |
|||
size_t get_benchtime() const { |
|||
return d_benchtime; |
|||
} |
|||
size_t get_cpu() const { |
|||
return d_cpu; |
|||
} |
|||
}; |
|||
|
|||
class context; |
|||
|
|||
/*
|
|||
* The benchmark_info class is used to store a function name / pointer pair. |
|||
* |
|||
* benchmark_info bi("example", [](benchpress::context* b) { |
|||
* // benchmark function
|
|||
* }); |
|||
*/ |
|||
class benchmark_info { |
|||
std::string d_name; |
|||
std::function<void(context*)> d_func; |
|||
|
|||
public: |
|||
benchmark_info(std::string name, std::function<void(context*)> func) |
|||
: d_name(name) |
|||
, d_func(func) |
|||
{} |
|||
|
|||
std::string get_name() const { return d_name; } |
|||
std::function<void(context*)> get_func() const { return d_func; } |
|||
}; |
|||
|
|||
/*
|
|||
* The registration class is responsible for providing a single global point of reference for registering |
|||
* benchmark functions. |
|||
* |
|||
* registration::get_ptr()->register_benchmark(info); |
|||
*/ |
|||
class registration { |
|||
static registration* d_this; |
|||
std::vector<benchmark_info> d_benchmarks; |
|||
|
|||
public: |
|||
static registration* get_ptr() { |
|||
if (nullptr == d_this) { |
|||
d_this = new registration(); |
|||
} |
|||
return d_this; |
|||
} |
|||
|
|||
void register_benchmark(benchmark_info& info) { |
|||
d_benchmarks.push_back(info); |
|||
} |
|||
|
|||
std::vector<benchmark_info> get_benchmarks() { return d_benchmarks; } |
|||
}; |
|||
|
|||
/*
|
|||
* The auto_register class is a helper used to register benchmarks. |
|||
*/ |
|||
class auto_register { |
|||
public: |
|||
auto_register(const std::string& name, std::function<void(context*)> func) { |
|||
benchmark_info info(name, func); |
|||
registration::get_ptr()->register_benchmark(info); |
|||
} |
|||
}; |
|||
|
|||
#define CONCAT(x, y) x ## y
|
|||
#define CONCAT2(x, y) CONCAT(x, y)
|
|||
|
|||
// The BENCHMARK macro is a helper for creating benchmark functions and automatically registering them with the
|
|||
// registration class.
|
|||
#define BENCHMARK(x, f) benchpress::auto_register CONCAT2(register_, __LINE__)((x), (f));
|
|||
|
|||
// This macro will prevent the compiler from removing a redundant code path which has no side-effects.
|
|||
#define DISABLE_REDUNDANT_CODE_OPT() { asm(""); }
|
|||
|
|||
/*
|
|||
* The result class is responsible for producing a printable string representation of a benchmark run. |
|||
*/ |
|||
class result { |
|||
size_t d_num_iterations; |
|||
std::chrono::nanoseconds d_duration; |
|||
size_t d_num_bytes; |
|||
|
|||
public: |
|||
result(size_t num_iterations, std::chrono::nanoseconds duration, size_t num_bytes) |
|||
: d_num_iterations(num_iterations) |
|||
, d_duration(duration) |
|||
, d_num_bytes(num_bytes) |
|||
{} |
|||
|
|||
size_t get_ns_per_op() const { |
|||
if (d_num_iterations <= 0) { |
|||
return 0; |
|||
} |
|||
return d_duration.count() / d_num_iterations; |
|||
} |
|||
|
|||
double get_mb_per_s() const { |
|||
if (d_num_iterations <= 0 || d_duration.count() <= 0 || d_num_bytes <= 0) { |
|||
return 0; |
|||
} |
|||
return ((double(d_num_bytes) * double(d_num_iterations) / double(1e6)) / |
|||
double(std::chrono::duration_cast<std::chrono::seconds>(d_duration).count())); |
|||
} |
|||
|
|||
std::string to_string() const { |
|||
std::stringstream tmp; |
|||
tmp << std::setw(12) << std::right << d_num_iterations; |
|||
size_t npo = get_ns_per_op(); |
|||
tmp << std::setw(12) << std::right << npo << std::setw(0) << " ns/op"; |
|||
double mbs = get_mb_per_s(); |
|||
if (mbs > 0.0) { |
|||
tmp << std::setw(12) << std::right << mbs << std::setw(0) << " MB/s"; |
|||
} |
|||
return std::string(tmp.str()); |
|||
} |
|||
}; |
|||
|
|||
/*
|
|||
* The parallel_context class is responsible for providing a thread-safe context for parallel benchmark code. |
|||
*/ |
|||
class parallel_context { |
|||
std::atomic_intmax_t d_num_iterations; |
|||
public: |
|||
parallel_context(size_t num_iterations) |
|||
: d_num_iterations(num_iterations) |
|||
{} |
|||
|
|||
bool next() { |
|||
return (d_num_iterations.fetch_sub(1) > 0); |
|||
} |
|||
}; |
|||
|
|||
/*
|
|||
* The context class is responsible for providing an interface for capturing benchmark metrics to benchmark functions. |
|||
*/ |
|||
class context { |
|||
bool d_timer_on; |
|||
std::chrono::high_resolution_clock::time_point d_start; |
|||
std::chrono::nanoseconds d_duration; |
|||
std::chrono::seconds d_benchtime; |
|||
size_t d_num_iterations; |
|||
size_t d_num_threads; |
|||
size_t d_num_bytes; |
|||
benchmark_info d_benchmark; |
|||
|
|||
public: |
|||
context(const benchmark_info& info, const options& opts) |
|||
: d_timer_on(false) |
|||
, d_start() |
|||
, d_duration() |
|||
, d_benchtime(std::chrono::seconds(opts.get_benchtime())) |
|||
, d_num_iterations(1) |
|||
, d_num_threads(opts.get_cpu()) |
|||
, d_num_bytes(0) |
|||
, d_benchmark(info) |
|||
{} |
|||
|
|||
size_t num_iterations() const { return d_num_iterations; } |
|||
|
|||
void set_num_threads(size_t n) { d_num_threads = n; } |
|||
size_t num_threads() const { return d_num_threads; } |
|||
|
|||
void start_timer() { |
|||
if (!d_timer_on) { |
|||
d_start = std::chrono::high_resolution_clock::now(); |
|||
d_timer_on = true; |
|||
} |
|||
} |
|||
void stop_timer() { |
|||
if (d_timer_on) { |
|||
d_duration += std::chrono::high_resolution_clock::now() - d_start; |
|||
d_timer_on = false; |
|||
} |
|||
} |
|||
void reset_timer() { |
|||
if (d_timer_on) { |
|||
d_start = std::chrono::high_resolution_clock::now(); |
|||
} |
|||
d_duration = std::chrono::nanoseconds::zero(); |
|||
} |
|||
|
|||
void set_bytes(int64_t bytes) { d_num_bytes = bytes; } |
|||
|
|||
size_t get_ns_per_op() { |
|||
if (d_num_iterations <= 0) { |
|||
return 0; |
|||
} |
|||
return d_duration.count() / d_num_iterations; |
|||
} |
|||
|
|||
void run_n(size_t n) { |
|||
d_num_iterations = n; |
|||
reset_timer(); |
|||
start_timer(); |
|||
d_benchmark.get_func()(this); |
|||
stop_timer(); |
|||
} |
|||
|
|||
void run_parallel(std::function<void(parallel_context*)> f) { |
|||
parallel_context pc(d_num_iterations); |
|||
std::vector<std::thread> threads; |
|||
for (size_t i = 0; i < d_num_threads; ++i) { |
|||
threads.push_back(std::thread([&pc,&f]() -> void { |
|||
f(&pc); |
|||
})); |
|||
} |
|||
for(auto& thread : threads){ |
|||
thread.join(); |
|||
} |
|||
} |
|||
|
|||
result run() { |
|||
size_t n = 1; |
|||
run_n(n); |
|||
while (d_duration < d_benchtime && n < 1e9) { |
|||
size_t last = n; |
|||
if (get_ns_per_op() == 0) { |
|||
n = 1e9; |
|||
} else { |
|||
n = d_duration.count() / get_ns_per_op(); |
|||
} |
|||
n = std::max(std::min(n+n/2, 100*last), last+1); |
|||
n = round_up(n); |
|||
run_n(n); |
|||
} |
|||
return result(n, d_duration, d_num_bytes); |
|||
} |
|||
|
|||
private: |
|||
template<typename T> |
|||
T round_down_10(T n) { |
|||
int tens = 0; |
|||
while (n > 10) { |
|||
n /= 10; |
|||
tens++; |
|||
} |
|||
int result = 1; |
|||
for (int i = 0; i < tens; ++i) { |
|||
result *= 10; |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
template<typename T> |
|||
T round_up(T n) { |
|||
T base = round_down_10(n); |
|||
if (n < (2 * base)) { |
|||
return 2 * base; |
|||
} |
|||
if (n < (5 * base)) { |
|||
return 5 * base; |
|||
} |
|||
return 10 * base; |
|||
} |
|||
}; |
|||
|
|||
/*
|
|||
* The run_benchmarks function will run the registered benchmarks. |
|||
*/ |
|||
void run_benchmarks(const options& opts) { |
|||
std::regex match_r(opts.get_bench()); |
|||
auto benchmarks = registration::get_ptr()->get_benchmarks(); |
|||
for (auto& info : benchmarks) { |
|||
if (std::regex_match(info.get_name(), match_r)) { |
|||
context c(info, opts); |
|||
auto r = c.run(); |
|||
std::cout << std::setw(35) << std::left << info.get_name() << r.to_string() << std::endl; |
|||
} |
|||
} |
|||
} |
|||
|
|||
} // namespace benchpress
|
|||
|
|||
/*
|
|||
* If BENCHPRESS_CONFIG_MAIN is defined when the file is included then a main function will be emitted which provides a |
|||
* command-line parser and then executes run_benchmarks. |
|||
*/ |
|||
#ifdef BENCHPRESS_CONFIG_MAIN
|
|||
#include "cxxopts.hpp"
|
|||
benchpress::registration* benchpress::registration::d_this; |
|||
int main(int argc, char** argv) { |
|||
std::chrono::high_resolution_clock::time_point bp_start = std::chrono::high_resolution_clock::now(); |
|||
benchpress::options bench_opts; |
|||
try { |
|||
cxxopts::Options cmd_opts(argv[0], " - command line options"); |
|||
cmd_opts.add_options() |
|||
("bench", "run benchmarks matching the regular expression", cxxopts::value<std::string>() |
|||
->default_value(".*")) |
|||
("benchtime", "run enough iterations of each benchmark to take t seconds", cxxopts::value<size_t>() |
|||
->default_value("1")) |
|||
("cpu", "specify the number of threads to use for parallel benchmarks", cxxopts::value<size_t>() |
|||
->default_value(std::to_string(std::thread::hardware_concurrency()))) |
|||
("help", "print help") |
|||
; |
|||
cmd_opts.parse(argc, argv); |
|||
if (cmd_opts.count("help")) { |
|||
std::cout << cmd_opts.help({""}) << std::endl; |
|||
exit(0); |
|||
} |
|||
if (cmd_opts.count("bench")) { |
|||
bench_opts.bench(cmd_opts["bench"].as<std::string>()); |
|||
} |
|||
if (cmd_opts.count("benchtime")) { |
|||
bench_opts.benchtime(cmd_opts["benchtime"].as<size_t>()); |
|||
} |
|||
if (cmd_opts.count("cpu")) { |
|||
bench_opts.cpu(cmd_opts["cpu"].as<size_t>()); |
|||
} |
|||
} catch (const cxxopts::OptionException& e) { |
|||
std::cout << "error parsing options: " << e.what() << std::endl; |
|||
exit(1); |
|||
} |
|||
benchpress::run_benchmarks(bench_opts); |
|||
float duration = std::chrono::duration_cast<std::chrono::milliseconds>( |
|||
std::chrono::high_resolution_clock::now() - bp_start |
|||
).count() / 1000.f; |
|||
std::cout << argv[0] << " " << duration << "s" << std::endl; |
|||
return 0; |
|||
} |
|||
#endif
|
|||
|
|||
#endif // BENCHPRESS_HPP
|
1312
resources/3rdparty/modernjson/benchmarks/cxxopts.hpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1 @@ |
|||
a533fde78ce50a11f6189907f9e0392095222fe2 |
9
resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/canada.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
50469
resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/citm_catalog.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
15482
resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/twitter.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,6 @@ |
|||
@PACKAGE_INIT@ |
|||
|
|||
cmake_policy(PUSH) |
|||
cmake_policy(SET CMP0024 OLD) |
|||
include(${CMAKE_CURRENT_LIST_DIR}/@JSON_TARGETS_FILENAME@) |
|||
cmake_policy(POP) |
@ -0,0 +1,317 @@ |
|||
# Doxyfile 1.8.9.1 |
|||
|
|||
#--------------------------------------------------------------------------- |
|||
# Project related configuration options |
|||
#--------------------------------------------------------------------------- |
|||
DOXYFILE_ENCODING = UTF-8 |
|||
PROJECT_NAME = "JSON for Modern C++" |
|||
PROJECT_NUMBER = 2.0.0 |
|||
PROJECT_BRIEF = |
|||
PROJECT_LOGO = |
|||
OUTPUT_DIRECTORY = . |
|||
CREATE_SUBDIRS = NO |
|||
ALLOW_UNICODE_NAMES = NO |
|||
OUTPUT_LANGUAGE = English |
|||
BRIEF_MEMBER_DESC = YES |
|||
REPEAT_BRIEF = NO |
|||
ABBREVIATE_BRIEF = |
|||
ALWAYS_DETAILED_SEC = YES |
|||
INLINE_INHERITED_MEMB = NO |
|||
FULL_PATH_NAMES = YES |
|||
STRIP_FROM_PATH = |
|||
STRIP_FROM_INC_PATH = |
|||
SHORT_NAMES = NO |
|||
JAVADOC_AUTOBRIEF = NO |
|||
QT_AUTOBRIEF = NO |
|||
MULTILINE_CPP_IS_BRIEF = NO |
|||
INHERIT_DOCS = YES |
|||
SEPARATE_MEMBER_PAGES = YES |
|||
TAB_SIZE = 4 |
|||
ALIASES = "complexity=@par Complexity\n" |
|||
ALIASES += liveexample{2}="@par Example\n \1 \n @includelineno \2.cpp \n Output (play with this example @htmlinclude \2.link):\n @verbinclude \2.output \n The example code above can be translated with @verbatim g++ -std=c++11 -Isrc doc/examples/\2.cpp -o \2 @endverbatim" |
|||
ALIASES += requirement="@par Requirements\n" |
|||
ALIASES += exceptionsafety="@par Exception safety\n" |
|||
TCL_SUBST = |
|||
OPTIMIZE_OUTPUT_FOR_C = NO |
|||
OPTIMIZE_OUTPUT_JAVA = NO |
|||
OPTIMIZE_FOR_FORTRAN = NO |
|||
OPTIMIZE_OUTPUT_VHDL = NO |
|||
EXTENSION_MAPPING = |
|||
MARKDOWN_SUPPORT = YES |
|||
AUTOLINK_SUPPORT = NO |
|||
BUILTIN_STL_SUPPORT = YES |
|||
CPP_CLI_SUPPORT = NO |
|||
SIP_SUPPORT = NO |
|||
IDL_PROPERTY_SUPPORT = YES |
|||
DISTRIBUTE_GROUP_DOC = NO |
|||
SUBGROUPING = YES |
|||
INLINE_GROUPED_CLASSES = NO |
|||
INLINE_SIMPLE_STRUCTS = NO |
|||
TYPEDEF_HIDES_STRUCT = NO |
|||
LOOKUP_CACHE_SIZE = 0 |
|||
#--------------------------------------------------------------------------- |
|||
# Build related configuration options |
|||
#--------------------------------------------------------------------------- |
|||
EXTRACT_ALL = YES |
|||
EXTRACT_PRIVATE = NO |
|||
EXTRACT_PACKAGE = YES |
|||
EXTRACT_STATIC = YES |
|||
EXTRACT_LOCAL_CLASSES = YES |
|||
EXTRACT_LOCAL_METHODS = YES |
|||
EXTRACT_ANON_NSPACES = YES |
|||
HIDE_UNDOC_MEMBERS = NO |
|||
HIDE_UNDOC_CLASSES = NO |
|||
HIDE_FRIEND_COMPOUNDS = NO |
|||
HIDE_IN_BODY_DOCS = NO |
|||
INTERNAL_DOCS = NO |
|||
CASE_SENSE_NAMES = NO |
|||
HIDE_SCOPE_NAMES = NO |
|||
HIDE_COMPOUND_REFERENCE= NO |
|||
SHOW_INCLUDE_FILES = YES |
|||
SHOW_GROUPED_MEMB_INC = NO |
|||
FORCE_LOCAL_INCLUDES = NO |
|||
INLINE_INFO = YES |
|||
SORT_MEMBER_DOCS = YES |
|||
SORT_BRIEF_DOCS = YES |
|||
SORT_MEMBERS_CTORS_1ST = YES |
|||
SORT_GROUP_NAMES = NO |
|||
SORT_BY_SCOPE_NAME = NO |
|||
STRICT_PROTO_MATCHING = NO |
|||
GENERATE_TODOLIST = YES |
|||
GENERATE_TESTLIST = YES |
|||
GENERATE_BUGLIST = YES |
|||
GENERATE_DEPRECATEDLIST= YES |
|||
ENABLED_SECTIONS = |
|||
MAX_INITIALIZER_LINES = 30 |
|||
SHOW_USED_FILES = NO |
|||
SHOW_FILES = NO |
|||
SHOW_NAMESPACES = NO |
|||
FILE_VERSION_FILTER = |
|||
LAYOUT_FILE = |
|||
CITE_BIB_FILES = |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to warning and progress messages |
|||
#--------------------------------------------------------------------------- |
|||
QUIET = YES |
|||
WARNINGS = YES |
|||
WARN_IF_UNDOCUMENTED = YES |
|||
WARN_IF_DOC_ERROR = YES |
|||
WARN_NO_PARAMDOC = YES |
|||
WARN_FORMAT = "$file:$line: $text" |
|||
WARN_LOGFILE = |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the input files |
|||
#--------------------------------------------------------------------------- |
|||
INPUT = ../src/json.hpp index.md |
|||
INPUT_ENCODING = UTF-8 |
|||
FILE_PATTERNS = |
|||
RECURSIVE = NO |
|||
EXCLUDE = |
|||
EXCLUDE_SYMLINKS = NO |
|||
EXCLUDE_PATTERNS = |
|||
EXCLUDE_SYMBOLS = nlohmann::anonymous_namespace |
|||
EXAMPLE_PATH = examples |
|||
EXAMPLE_PATTERNS = |
|||
EXAMPLE_RECURSIVE = NO |
|||
IMAGE_PATH = images |
|||
INPUT_FILTER = |
|||
FILTER_PATTERNS = |
|||
FILTER_SOURCE_FILES = NO |
|||
FILTER_SOURCE_PATTERNS = |
|||
USE_MDFILE_AS_MAINPAGE = index.md |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to source browsing |
|||
#--------------------------------------------------------------------------- |
|||
SOURCE_BROWSER = YES |
|||
INLINE_SOURCES = NO |
|||
STRIP_CODE_COMMENTS = YES |
|||
REFERENCED_BY_RELATION = NO |
|||
REFERENCES_RELATION = NO |
|||
REFERENCES_LINK_SOURCE = NO |
|||
SOURCE_TOOLTIPS = YES |
|||
USE_HTAGS = NO |
|||
VERBATIM_HEADERS = NO |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the alphabetical class index |
|||
#--------------------------------------------------------------------------- |
|||
ALPHABETICAL_INDEX = YES |
|||
COLS_IN_ALPHA_INDEX = 5 |
|||
IGNORE_PREFIX = |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the HTML output |
|||
#--------------------------------------------------------------------------- |
|||
GENERATE_HTML = YES |
|||
HTML_OUTPUT = html |
|||
HTML_FILE_EXTENSION = .html |
|||
HTML_HEADER = |
|||
HTML_FOOTER = |
|||
HTML_STYLESHEET = |
|||
HTML_EXTRA_STYLESHEET = css/mylayout.css |
|||
HTML_EXTRA_FILES = |
|||
HTML_COLORSTYLE_HUE = 220 |
|||
HTML_COLORSTYLE_SAT = 100 |
|||
HTML_COLORSTYLE_GAMMA = 80 |
|||
HTML_TIMESTAMP = YES |
|||
HTML_DYNAMIC_SECTIONS = YES |
|||
HTML_INDEX_NUM_ENTRIES = 100 |
|||
GENERATE_DOCSET = YES |
|||
DOCSET_FEEDNAME = "Doxygen generated docs" |
|||
DOCSET_BUNDLE_ID = me.nlohmann.json |
|||
DOCSET_PUBLISHER_ID = me.nlohmann |
|||
DOCSET_PUBLISHER_NAME = Niels Lohmann |
|||
GENERATE_HTMLHELP = NO |
|||
CHM_FILE = |
|||
HHC_LOCATION = |
|||
GENERATE_CHI = NO |
|||
CHM_INDEX_ENCODING = |
|||
BINARY_TOC = NO |
|||
TOC_EXPAND = NO |
|||
GENERATE_QHP = NO |
|||
QCH_FILE = |
|||
QHP_NAMESPACE = org.doxygen.Project |
|||
QHP_VIRTUAL_FOLDER = doc |
|||
QHP_CUST_FILTER_NAME = |
|||
QHP_CUST_FILTER_ATTRS = |
|||
QHP_SECT_FILTER_ATTRS = |
|||
QHG_LOCATION = |
|||
GENERATE_ECLIPSEHELP = NO |
|||
ECLIPSE_DOC_ID = org.doxygen.Project |
|||
DISABLE_INDEX = NO |
|||
GENERATE_TREEVIEW = NO |
|||
ENUM_VALUES_PER_LINE = 4 |
|||
TREEVIEW_WIDTH = 250 |
|||
EXT_LINKS_IN_WINDOW = NO |
|||
FORMULA_FONTSIZE = 10 |
|||
FORMULA_TRANSPARENT = YES |
|||
USE_MATHJAX = NO |
|||
MATHJAX_FORMAT = HTML-CSS |
|||
MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest |
|||
MATHJAX_EXTENSIONS = |
|||
MATHJAX_CODEFILE = |
|||
SEARCHENGINE = YES |
|||
SERVER_BASED_SEARCH = NO |
|||
EXTERNAL_SEARCH = NO |
|||
SEARCHENGINE_URL = |
|||
SEARCHDATA_FILE = searchdata.xml |
|||
EXTERNAL_SEARCH_ID = |
|||
EXTRA_SEARCH_MAPPINGS = |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the LaTeX output |
|||
#--------------------------------------------------------------------------- |
|||
GENERATE_LATEX = NO |
|||
LATEX_OUTPUT = latex |
|||
LATEX_CMD_NAME = latex |
|||
MAKEINDEX_CMD_NAME = makeindex |
|||
COMPACT_LATEX = NO |
|||
PAPER_TYPE = a4 |
|||
EXTRA_PACKAGES = |
|||
LATEX_HEADER = |
|||
LATEX_FOOTER = |
|||
LATEX_EXTRA_STYLESHEET = |
|||
LATEX_EXTRA_FILES = |
|||
PDF_HYPERLINKS = YES |
|||
USE_PDFLATEX = YES |
|||
LATEX_BATCHMODE = NO |
|||
LATEX_HIDE_INDICES = NO |
|||
LATEX_SOURCE_CODE = NO |
|||
LATEX_BIB_STYLE = plain |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the RTF output |
|||
#--------------------------------------------------------------------------- |
|||
GENERATE_RTF = NO |
|||
RTF_OUTPUT = rtf |
|||
COMPACT_RTF = NO |
|||
RTF_HYPERLINKS = NO |
|||
RTF_STYLESHEET_FILE = |
|||
RTF_EXTENSIONS_FILE = |
|||
RTF_SOURCE_CODE = NO |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the man page output |
|||
#--------------------------------------------------------------------------- |
|||
GENERATE_MAN = NO |
|||
MAN_OUTPUT = man |
|||
MAN_EXTENSION = .3 |
|||
MAN_SUBDIR = |
|||
MAN_LINKS = NO |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the XML output |
|||
#--------------------------------------------------------------------------- |
|||
GENERATE_XML = NO |
|||
XML_OUTPUT = xml |
|||
XML_PROGRAMLISTING = YES |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the DOCBOOK output |
|||
#--------------------------------------------------------------------------- |
|||
GENERATE_DOCBOOK = NO |
|||
DOCBOOK_OUTPUT = docbook |
|||
DOCBOOK_PROGRAMLISTING = NO |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options for the AutoGen Definitions output |
|||
#--------------------------------------------------------------------------- |
|||
GENERATE_AUTOGEN_DEF = NO |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the Perl module output |
|||
#--------------------------------------------------------------------------- |
|||
GENERATE_PERLMOD = NO |
|||
PERLMOD_LATEX = NO |
|||
PERLMOD_PRETTY = YES |
|||
PERLMOD_MAKEVAR_PREFIX = |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the preprocessor |
|||
#--------------------------------------------------------------------------- |
|||
ENABLE_PREPROCESSING = YES |
|||
MACRO_EXPANSION = NO |
|||
EXPAND_ONLY_PREDEF = NO |
|||
SEARCH_INCLUDES = YES |
|||
INCLUDE_PATH = |
|||
INCLUDE_FILE_PATTERNS = |
|||
PREDEFINED = |
|||
EXPAND_AS_DEFINED = |
|||
SKIP_FUNCTION_MACROS = YES |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to external references |
|||
#--------------------------------------------------------------------------- |
|||
TAGFILES = |
|||
GENERATE_TAGFILE = |
|||
ALLEXTERNALS = NO |
|||
EXTERNAL_GROUPS = YES |
|||
EXTERNAL_PAGES = YES |
|||
PERL_PATH = /usr/bin/perl |
|||
#--------------------------------------------------------------------------- |
|||
# Configuration options related to the dot tool |
|||
#--------------------------------------------------------------------------- |
|||
CLASS_DIAGRAMS = NO |
|||
MSCGEN_PATH = |
|||
DIA_PATH = |
|||
HIDE_UNDOC_RELATIONS = YES |
|||
HAVE_DOT = YES |
|||
DOT_NUM_THREADS = 0 |
|||
DOT_FONTNAME = Helvetica |
|||
DOT_FONTSIZE = 10 |
|||
DOT_FONTPATH = |
|||
CLASS_GRAPH = NO |
|||
COLLABORATION_GRAPH = NO |
|||
GROUP_GRAPHS = YES |
|||
UML_LOOK = YES |
|||
UML_LIMIT_NUM_FIELDS = 10 |
|||
TEMPLATE_RELATIONS = NO |
|||
INCLUDE_GRAPH = NO |
|||
INCLUDED_BY_GRAPH = NO |
|||
CALL_GRAPH = NO |
|||
CALLER_GRAPH = NO |
|||
GRAPHICAL_HIERARCHY = NO |
|||
DIRECTORY_GRAPH = NO |
|||
DOT_IMAGE_FORMAT = svg |
|||
INTERACTIVE_SVG = YES |
|||
DOT_PATH = |
|||
DOTFILE_DIRS = |
|||
MSCFILE_DIRS = |
|||
DIAFILE_DIRS = |
|||
PLANTUML_JAR_PATH = |
|||
PLANTUML_INCLUDE_PATH = |
|||
DOT_GRAPH_MAX_NODES = 50 |
|||
MAX_DOT_GRAPH_DEPTH = 0 |
|||
DOT_TRANSPARENT = NO |
|||
DOT_MULTI_TARGETS = NO |
|||
GENERATE_LEGEND = YES |
|||
DOT_CLEANUP = YES |
@ -0,0 +1,82 @@ |
|||
SRCDIR = ../src |
|||
|
|||
all: doxygen |
|||
|
|||
clean: |
|||
rm -fr me.nlohmann.json.docset html |
|||
|
|||
|
|||
##########################################################################
|
|||
# example files
|
|||
##########################################################################
|
|||
|
|||
# where are the example cpp files
|
|||
EXAMPLES = $(wildcard examples/*.cpp) |
|||
|
|||
# create output from a stand-alone example file
|
|||
%.output: %.cpp |
|||
make $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11" |
|||
./$(<:.cpp=) > $@ |
|||
rm $(<:.cpp=) |
|||
|
|||
# compare created output with current output of the example files
|
|||
%.test: %.cpp |
|||
make $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11" |
|||
./$(<:.cpp=) > $@ |
|||
diff $@ $(<:.cpp=.output) |
|||
rm $(<:.cpp=) $@ |
|||
|
|||
# create links to try the code online
|
|||
%.link: %.cpp |
|||
rm -fr tmp |
|||
mkdir tmp |
|||
cp $(SRCDIR)/json.hpp tmp |
|||
scripts/send_to_wandbox.py tmp $< > $@.tmp |
|||
/bin/echo -n "<a target=\"_blank\" href=\"`cat $@.tmp`\"><b>online</b></a>" > $@ |
|||
rm -fr tmp $@.tmp |
|||
|
|||
# create output from all stand-alone example files
|
|||
create_output: $(EXAMPLES:.cpp=.output) |
|||
|
|||
create_links: $(EXAMPLES:.cpp=.link) |
|||
|
|||
# check output of all stand-alone example files
|
|||
check_output: $(EXAMPLES:.cpp=.test) |
|||
|
|||
|
|||
##########################################################################
|
|||
# Doxygen HTML documentation
|
|||
##########################################################################
|
|||
|
|||
# create Doxygen documentation
|
|||
doxygen: create_output create_links |
|||
doxygen |
|||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html |
|||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html |
|||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >@@g' html/*.html |
|||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >@@g' html/*.html |
|||
|
|||
upload: clean doxygen check_output |
|||
cd html ; ../scripts/git-update-ghpages nlohmann/json |
|||
rm -fr html |
|||
open http://nlohmann.github.io/json/ |
|||
|
|||
|
|||
##########################################################################
|
|||
# docset
|
|||
##########################################################################
|
|||
|
|||
# create docset for Dash
|
|||
docset: create_output |
|||
cp Doxyfile Doxyfile_docset |
|||
gsed -i 's/DISABLE_INDEX = NO/DISABLE_INDEX = YES/' Doxyfile_docset |
|||
gsed -i 's/SEARCHENGINE = YES/SEARCHENGINE = NO/' Doxyfile_docset |
|||
gsed -i 's@HTML_EXTRA_STYLESHEET = css/mylayout.css@HTML_EXTRA_STYLESHEET = css/mylayout_docset.css@' Doxyfile_docset |
|||
rm -fr html *.docset |
|||
doxygen Doxyfile_docset |
|||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html |
|||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html |
|||
make -C html |
|||
mv html/*.docset . |
|||
gsed -i 's@<string>doxygen</string>@<string>json</string>@' me.nlohmann.json.docset/Contents/Info.plist |
|||
rm -fr Doxyfile_docset html |
@ -0,0 +1,26 @@ |
|||
/* hide lengthy template information */ |
|||
.memtemplate, .memTemplParams { |
|||
display: none; |
|||
} |
|||
|
|||
/* allow compiler information to wrap */ |
|||
/* https://css-tricks.com/snippets/css/make-pre-text-wrap/ */ |
|||
pre.fragment { |
|||
white-space: pre-wrap; /* css-3 */ |
|||
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ |
|||
white-space: -pre-wrap; /* Opera 4-6 */ |
|||
white-space: -o-pre-wrap; /* Opera 7 */ |
|||
word-wrap: break-word; /* Internet Explorer 5.5+ */ |
|||
} |
|||
|
|||
td.paramname { |
|||
vertical-align: top; |
|||
} |
|||
|
|||
.ok_green { |
|||
background-color: #89C35C; |
|||
} |
|||
|
|||
.nok_throws { |
|||
background-color: #ffa500; |
|||
} |
@ -0,0 +1,27 @@ |
|||
.memtemplate { |
|||
display: none; |
|||
} |
|||
|
|||
.memTemplParams { |
|||
display: none; |
|||
} |
|||
|
|||
.navtab { |
|||
display: none; |
|||
} |
|||
|
|||
#top, .footer { |
|||
display: none; |
|||
} |
|||
|
|||
td.paramname { |
|||
vertical-align: top; |
|||
} |
|||
|
|||
.ok_green { |
|||
background-color: #89C35C; |
|||
} |
|||
|
|||
.nok_throws { |
|||
background-color: #ffa500; |
|||
} |
@ -0,0 +1,36 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create a JSON object
|
|||
json j = |
|||
{ |
|||
{"pi", 3.141}, |
|||
{"happy", true}, |
|||
{"name", "Niels"}, |
|||
{"nothing", nullptr}, |
|||
{ |
|||
"answer", { |
|||
{"everything", 42} |
|||
} |
|||
}, |
|||
{"list", {1, 0, 2}}, |
|||
{ |
|||
"object", { |
|||
{"currency", "USD"}, |
|||
{"value", 42.99} |
|||
} |
|||
} |
|||
}; |
|||
|
|||
// add new values
|
|||
j["new"]["key"]["value"] = {"another", "list"}; |
|||
|
|||
// count elements
|
|||
j["size"] = j.size(); |
|||
|
|||
// pretty print with indent of 4 spaces
|
|||
std::cout << std::setw(4) << j << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/fYyscqrsQFtgUePA"><b>online</b></a> |
@ -0,0 +1,27 @@ |
|||
{ |
|||
"answer": { |
|||
"everything": 42 |
|||
}, |
|||
"happy": true, |
|||
"list": [ |
|||
1, |
|||
0, |
|||
2 |
|||
], |
|||
"name": "Niels", |
|||
"new": { |
|||
"key": { |
|||
"value": [ |
|||
"another", |
|||
"list" |
|||
] |
|||
} |
|||
}, |
|||
"nothing": null, |
|||
"object": { |
|||
"currency": "USD", |
|||
"value": 42.99 |
|||
}, |
|||
"pi": 3.141, |
|||
"size": 9 |
|||
} |
@ -0,0 +1,18 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create JSON arrays
|
|||
json j_no_init_list = json::array(); |
|||
json j_empty_init_list = json::array({}); |
|||
json j_nonempty_init_list = json::array({1, 2, 3, 4}); |
|||
json j_list_of_pairs = json::array({ {"one", 1}, {"two", 2} }); |
|||
|
|||
// serialize the JSON arrays
|
|||
std::cout << j_no_init_list << '\n'; |
|||
std::cout << j_empty_init_list << '\n'; |
|||
std::cout << j_nonempty_init_list << '\n'; |
|||
std::cout << j_list_of_pairs << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/TTykAqoDgbLzKxt3"><b>online</b></a> |
@ -0,0 +1,4 @@ |
|||
[] |
|||
[] |
|||
[1,2,3,4] |
|||
[["one",1],["two",2]] |
@ -0,0 +1,33 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create JSON object
|
|||
json object = |
|||
{ |
|||
{"the good", "il buono"}, |
|||
{"the bad", "il cativo"}, |
|||
{"the ugly", "il brutto"} |
|||
}; |
|||
|
|||
// output element with key "the ugly"
|
|||
std::cout << object.at("the ugly") << '\n'; |
|||
|
|||
// change element with key "the bad"
|
|||
object.at("the bad") = "il cattivo"; |
|||
|
|||
// output changed array
|
|||
std::cout << object << '\n'; |
|||
|
|||
// try to write at a nonexisting key
|
|||
try |
|||
{ |
|||
object.at("the fast") = "il rapido"; |
|||
} |
|||
catch (std::out_of_range& e) |
|||
{ |
|||
std::cout << "out of range: " << e.what() << '\n'; |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/wjOUJUwo2SO7q5u8"><b>online</b></a> |
@ -0,0 +1,3 @@ |
|||
"il brutto" |
|||
{"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"} |
|||
out of range: key 'the fast' not found |
@ -0,0 +1,27 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create JSON object
|
|||
json object = |
|||
{ |
|||
{"the good", "il buono"}, |
|||
{"the bad", "il cativo"}, |
|||
{"the ugly", "il brutto"} |
|||
}; |
|||
|
|||
// output element with key "the ugly"
|
|||
std::cout << object.at("the ugly") << '\n'; |
|||
|
|||
// try to read from a nonexisting key
|
|||
try |
|||
{ |
|||
std::cout << object.at("the fast") << '\n'; |
|||
} |
|||
catch (std::out_of_range) |
|||
{ |
|||
std::cout << "out of range" << '\n'; |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/7gGtalpuoF4xE7VN"><b>online</b></a> |
@ -0,0 +1,2 @@ |
|||
"il brutto" |
|||
out of range |
@ -0,0 +1,28 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create JSON array
|
|||
json array = {"first", "2nd", "third", "fourth"}; |
|||
|
|||
// output element at index 2 (third element)
|
|||
std::cout << array.at(2) << '\n'; |
|||
|
|||
// change element at index 1 (second element) to "second"
|
|||
array.at(1) = "second"; |
|||
|
|||
// output changed array
|
|||
std::cout << array << '\n'; |
|||
|
|||
// try to write beyond the array limit
|
|||
try |
|||
{ |
|||
array.at(5) = "sixth"; |
|||
} |
|||
catch (std::out_of_range& e) |
|||
{ |
|||
std::cout << "out of range: " << e.what() << '\n'; |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Sa6XYQS7TJ5sGG8a"><b>online</b></a> |
@ -0,0 +1,3 @@ |
|||
"third" |
|||
["first","second","third","fourth"] |
|||
out of range: array index 5 is out of range |
@ -0,0 +1,22 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create JSON array
|
|||
json array = {"first", "2nd", "third", "fourth"}; |
|||
|
|||
// output element at index 2 (third element)
|
|||
std::cout << array.at(2) << '\n'; |
|||
|
|||
// try to read beyond the array limit
|
|||
try |
|||
{ |
|||
std::cout << array.at(5) << '\n'; |
|||
} |
|||
catch (std::out_of_range) |
|||
{ |
|||
std::cout << "out of range" << '\n'; |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/PGQOjyIV7s5YnsQM"><b>online</b></a> |
@ -0,0 +1,2 @@ |
|||
"third" |
|||
out of range |
@ -0,0 +1,35 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create a JSON value
|
|||
json j = |
|||
{ |
|||
{"number", 1}, {"string", "foo"}, {"array", {1, 2}} |
|||
}; |
|||
|
|||
// read-only access
|
|||
|
|||
// output element with JSON pointer "/number"
|
|||
std::cout << j.at("/number"_json_pointer) << '\n'; |
|||
// output element with JSON pointer "/string"
|
|||
std::cout << j.at("/string"_json_pointer) << '\n'; |
|||
// output element with JSON pointer "/array"
|
|||
std::cout << j.at("/array"_json_pointer) << '\n'; |
|||
// output element with JSON pointer "/array/1"
|
|||
std::cout << j.at("/array/1"_json_pointer) << '\n'; |
|||
|
|||
// writing access
|
|||
|
|||
// change the string
|
|||
j.at("/string"_json_pointer) = "bar"; |
|||
// output the changed string
|
|||
std::cout << j["string"] << '\n'; |
|||
|
|||
// change an array element
|
|||
j.at("/array/1"_json_pointer) = 21; |
|||
// output the changed array
|
|||
std::cout << j["array"] << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/NDSjglHZIjIZ0Uxg"><b>online</b></a> |
@ -0,0 +1,6 @@ |
|||
1 |
|||
"foo" |
|||
[1,2] |
|||
2 |
|||
"bar" |
|||
[1,21] |
@ -0,0 +1,23 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create a JSON value
|
|||
json j = |
|||
{ |
|||
{"number", 1}, {"string", "foo"}, {"array", {1, 2}} |
|||
}; |
|||
|
|||
// read-only access
|
|||
|
|||
// output element with JSON pointer "/number"
|
|||
std::cout << j.at("/number"_json_pointer) << '\n'; |
|||
// output element with JSON pointer "/string"
|
|||
std::cout << j.at("/string"_json_pointer) << '\n'; |
|||
// output element with JSON pointer "/array"
|
|||
std::cout << j.at("/array"_json_pointer) << '\n'; |
|||
// output element with JSON pointer "/array/1"
|
|||
std::cout << j.at("/array/1"_json_pointer) << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/OuLYiMJ3pgyOHupb"><b>online</b></a> |
@ -0,0 +1,4 @@ |
|||
1 |
|||
"foo" |
|||
[1,2] |
|||
2 |
@ -0,0 +1,28 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create JSON values
|
|||
json j_null; |
|||
json j_boolean = true; |
|||
json j_number_integer = 17; |
|||
json j_number_float = 23.42; |
|||
json j_object = {{"one", 1}, {"two", 2}}; |
|||
json j_object_empty(json::value_t::object); |
|||
json j_array = {1, 2, 4, 8, 16}; |
|||
json j_array_empty(json::value_t::array); |
|||
json j_string = "Hello, world"; |
|||
|
|||
// call back()
|
|||
//std::cout << j_null.back() << '\n'; // would throw
|
|||
std::cout << j_boolean.back() << '\n'; |
|||
std::cout << j_number_integer.back() << '\n'; |
|||
std::cout << j_number_float.back() << '\n'; |
|||
std::cout << j_object.back() << '\n'; |
|||
//std::cout << j_object_empty.back() << '\n'; // undefined behavior
|
|||
std::cout << j_array.back() << '\n'; |
|||
//std::cout << j_array_empty.back() << '\n'; // undefined behavior
|
|||
std::cout << j_string.back() << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/V7lUsd6LyndZDGoM"><b>online</b></a> |
@ -0,0 +1,6 @@ |
|||
true |
|||
17 |
|||
23.42 |
|||
2 |
|||
16 |
|||
"Hello, world" |
@ -0,0 +1,12 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create a JSON value with default null value
|
|||
json j; |
|||
|
|||
// serialize the JSON null value
|
|||
std::cout << j << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/mSAAr3GATT6ciVjV"><b>online</b></a> |
@ -0,0 +1 @@ |
|||
null |
@ -0,0 +1,58 @@ |
|||
#include <json.hpp>
|
|||
#include <deque>
|
|||
#include <list>
|
|||
#include <forward_list>
|
|||
#include <set>
|
|||
#include <unordered_set>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create an array from std::vector
|
|||
std::vector<int> c_vector {1, 2, 3, 4}; |
|||
json j_vec(c_vector); |
|||
|
|||
// create an array from std::deque
|
|||
std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6}; |
|||
json j_deque(c_deque); |
|||
|
|||
// create an array from std::list
|
|||
std::list<bool> c_list {true, true, false, true}; |
|||
json j_list(c_list); |
|||
|
|||
// create an array from std::forward_list
|
|||
std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543}; |
|||
json j_flist(c_flist); |
|||
|
|||
// create an array from std::array
|
|||
std::array<unsigned long, 4> c_array {{1, 2, 3, 4}}; |
|||
json j_array(c_array); |
|||
|
|||
// create an array from std::set
|
|||
std::set<std::string> c_set {"one", "two", "three", "four", "one"}; |
|||
json j_set(c_set); // only one entry for "one" is used
|
|||
|
|||
// create an array from std::unordered_set
|
|||
std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"}; |
|||
json j_uset(c_uset); // only one entry for "one" is used
|
|||
|
|||
// create an array from std::multiset
|
|||
std::multiset<std::string> c_mset {"one", "two", "one", "four"}; |
|||
json j_mset(c_mset); // only one entry for "one" is used
|
|||
|
|||
// create an array from std::unordered_multiset
|
|||
std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"}; |
|||
json j_umset(c_umset); // both entries for "one" are used
|
|||
|
|||
// serialize the JSON arrays
|
|||
std::cout << j_vec << '\n'; |
|||
std::cout << j_deque << '\n'; |
|||
std::cout << j_list << '\n'; |
|||
std::cout << j_flist << '\n'; |
|||
std::cout << j_array << '\n'; |
|||
std::cout << j_set << '\n'; |
|||
std::cout << j_uset << '\n'; |
|||
std::cout << j_mset << '\n'; |
|||
std::cout << j_umset << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/InYach9gNBDvA8QR"><b>online</b></a> |
@ -0,0 +1,9 @@ |
|||
[1,2,3,4] |
|||
[1.2,2.3,3.4,5.6] |
|||
[true,true,false,true] |
|||
[12345678909876,23456789098765,34567890987654,45678909876543] |
|||
[1,2,3,4] |
|||
["four","one","three","two"] |
|||
["four","three","two","one"] |
|||
["four","one","one","two"] |
|||
["four","two","one","one"] |
@ -0,0 +1,27 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create values of different integer types
|
|||
short n42 = 42; |
|||
int n23 = 23; |
|||
long n1024 = 1024; |
|||
int_least32_t n17 = 17; |
|||
uint8_t n8 = 8; |
|||
|
|||
// create JSON numbers
|
|||
json j42(n42); |
|||
json j23(n23); |
|||
json j1024(n1024); |
|||
json j17(n17); |
|||
json j8(n8); |
|||
|
|||
// serialize the JSON numbers
|
|||
std::cout << j42 << '\n'; |
|||
std::cout << j23 << '\n'; |
|||
std::cout << j1024 << '\n'; |
|||
std::cout << j17 << '\n'; |
|||
std::cout << j8 << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/VDu3HkQPf0Rv5dzH"><b>online</b></a> |
@ -0,0 +1,5 @@ |
|||
42 |
|||
23 |
|||
1024 |
|||
17 |
|||
8 |
@ -0,0 +1,21 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create values of different floating-point types
|
|||
float f42 = 42.23; |
|||
float f_nan = 1.0f / 0.0f; |
|||
double f23 = 23.42; |
|||
|
|||
// create JSON numbers
|
|||
json j42(f42); |
|||
json j_nan(f_nan); |
|||
json j23(f23); |
|||
|
|||
// serialize the JSON numbers
|
|||
std::cout << j42 << '\n'; |
|||
std::cout << j_nan << '\n'; |
|||
std::cout << j23 << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/BjDrTHvJMwFC3iLr"><b>online</b></a> |
@ -0,0 +1,3 @@ |
|||
42.2299995422363 |
|||
null |
|||
23.42 |
@ -0,0 +1,41 @@ |
|||
#include <json.hpp>
|
|||
#include <unordered_map>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create an object from std::map
|
|||
std::map<std::string, int> c_map |
|||
{ |
|||
{"one", 1}, {"two", 2}, {"three", 3} |
|||
}; |
|||
json j_map(c_map); |
|||
|
|||
// create an object from std::unordered_map
|
|||
std::unordered_map<const char*, double> c_umap |
|||
{ |
|||
{"one", 1.2}, {"two", 2.3}, {"three", 3.4} |
|||
}; |
|||
json j_umap(c_umap); |
|||
|
|||
// create an object from std::multimap
|
|||
std::multimap<std::string, bool> c_mmap |
|||
{ |
|||
{"one", true}, {"two", true}, {"three", false}, {"three", true} |
|||
}; |
|||
json j_mmap(c_mmap); // only one entry for key "three" is used
|
|||
|
|||
// create an object from std::unordered_multimap
|
|||
std::unordered_multimap<std::string, bool> c_ummap |
|||
{ |
|||
{"one", true}, {"two", true}, {"three", false}, {"three", true} |
|||
}; |
|||
json j_ummap(c_ummap); // only one entry for key "three" is used
|
|||
|
|||
// serialize the JSON objects
|
|||
std::cout << j_map << '\n'; |
|||
std::cout << j_umap << '\n'; |
|||
std::cout << j_mmap << '\n'; |
|||
std::cout << j_ummap << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/ZJz4SFD4Iuy8OS4T"><b>online</b></a> |
@ -0,0 +1,4 @@ |
|||
{"one":1,"three":3,"two":2} |
|||
{"one":1.2,"three":3.4,"two":2.3} |
|||
{"one":true,"three":false,"two":true} |
|||
{"one":true,"three":false,"two":true} |
@ -0,0 +1,15 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create a string value
|
|||
std::string s = "The quick brown fox jumps over the lazy dog."; |
|||
|
|||
// create a JSON string value
|
|||
json j = s; |
|||
|
|||
// serialize the JSON string
|
|||
std::cout << j << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Fe1WNG7eJRaWYMM4"><b>online</b></a> |
@ -0,0 +1 @@ |
|||
"The quick brown fox jumps over the lazy dog." |
@ -0,0 +1,21 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create JSON values
|
|||
json j_array = {"alpha", "bravo", "charly", "delta", "easy"}; |
|||
json j_number = 42; |
|||
json j_object = {{"one", "eins"}, {"two", "zwei"}}; |
|||
|
|||
// create copies using iterators
|
|||
json j_array_range(j_array.begin() + 1, j_array.end() - 2); |
|||
json j_number_range(j_number.begin(), j_number.end()); |
|||
json j_object_range(j_object.begin(), j_object.find("two")); |
|||
|
|||
// serialize the values
|
|||
std::cout << j_array_range << '\n'; |
|||
std::cout << j_number_range << '\n'; |
|||
std::cout << j_object_range << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Ulv0RYN6QoJ6ECVR"><b>online</b></a> |
@ -0,0 +1,3 @@ |
|||
["bravo","charly"] |
|||
42 |
|||
{"one":"eins"} |
@ -0,0 +1,15 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create an array_t value
|
|||
json::array_t value = {"one", "two", 3, 4.5, false}; |
|||
|
|||
// create a JSON array from the value
|
|||
json j(value); |
|||
|
|||
// serialize the JSON array
|
|||
std::cout << j << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/T5FlYwVpQ1oXBuBH"><b>online</b></a> |
@ -0,0 +1 @@ |
|||
["one","two",3,4.5,false] |
@ -0,0 +1,16 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create a JSON array
|
|||
json j1 = {"one", "two", 3, 4.5, false}; |
|||
|
|||
// create a copy
|
|||
json j2(j1); |
|||
|
|||
// serialize the JSON array
|
|||
std::cout << j1 << " = " << j2 << '\n'; |
|||
std::cout << std::boolalpha << (j1 == j2) << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/vPBv5smAPKUko4Qo"><b>online</b></a> |
@ -0,0 +1,2 @@ |
|||
["one","two",3,4.5,false] = ["one","two",3,4.5,false] |
|||
true |
@ -0,0 +1,14 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create boolean values
|
|||
json j_truth = true; |
|||
json j_falsity = false; |
|||
|
|||
// serialize the JSON booleans
|
|||
std::cout << j_truth << '\n'; |
|||
std::cout << j_falsity << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/saCwetmQZaB8tQ24"><b>online</b></a> |
@ -0,0 +1,2 @@ |
|||
true |
|||
false |
@ -0,0 +1,15 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// an anonymous enum
|
|||
enum { t = 17 }; |
|||
|
|||
// create a JSON number from the enum
|
|||
json j(t); |
|||
|
|||
// serialize the JSON numbers
|
|||
std::cout << j << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/BzGFT02b2KTR6z2B"><b>online</b></a> |
@ -0,0 +1 @@ |
|||
17 |
@ -0,0 +1,17 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create JSON values
|
|||
json a = 23; |
|||
json b = 42; |
|||
|
|||
// copy-assign a to b
|
|||
b = a; |
|||
|
|||
// serialize the JSON arrays
|
|||
std::cout << a << '\n'; |
|||
std::cout << b << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Ib1A0jrFXwYhf0eA"><b>online</b></a> |
@ -0,0 +1,2 @@ |
|||
23 |
|||
23 |
@ -0,0 +1,55 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// a JSON text
|
|||
auto text = R"( |
|||
{ |
|||
"Image": { |
|||
"Width": 800, |
|||
"Height": 600, |
|||
"Title": "View from 15th Floor", |
|||
"Thumbnail": { |
|||
"Url": "http://www.example.com/image/481989943", |
|||
"Height": 125, |
|||
"Width": 100 |
|||
}, |
|||
"Animated" : false, |
|||
"IDs": [116, 943, 234, 38793] |
|||
} |
|||
} |
|||
)"; |
|||
|
|||
// fill a stream with JSON text
|
|||
std::stringstream ss; |
|||
ss << text; |
|||
|
|||
// create JSON from stream
|
|||
json j_complete(ss); |
|||
std::cout << std::setw(4) << j_complete << "\n\n"; |
|||
|
|||
|
|||
// define parser callback
|
|||
json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed) |
|||
{ |
|||
// skip object elements with key "Thumbnail"
|
|||
if (event == json::parse_event_t::key and parsed == json("Thumbnail")) |
|||
{ |
|||
return false; |
|||
} |
|||
else |
|||
{ |
|||
return true; |
|||
} |
|||
}; |
|||
|
|||
// fill a stream with JSON text
|
|||
ss.clear(); |
|||
ss << text; |
|||
|
|||
// create JSON from stream (with callback)
|
|||
json j_filtered(ss, cb); |
|||
std::cout << std::setw(4) << j_filtered << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/VzSqLszbnoWE92dD"><b>online</b></a> |
@ -0,0 +1,34 @@ |
|||
{ |
|||
"Image": { |
|||
"Animated": false, |
|||
"Height": 600, |
|||
"IDs": [ |
|||
116, |
|||
943, |
|||
234, |
|||
38793 |
|||
], |
|||
"Thumbnail": { |
|||
"Height": 125, |
|||
"Url": "http://www.example.com/image/481989943", |
|||
"Width": 100 |
|||
}, |
|||
"Title": "View from 15th Floor", |
|||
"Width": 800 |
|||
} |
|||
} |
|||
|
|||
{ |
|||
"Image": { |
|||
"Animated": false, |
|||
"Height": 600, |
|||
"IDs": [ |
|||
116, |
|||
943, |
|||
234, |
|||
38793 |
|||
], |
|||
"Title": "View from 15th Floor", |
|||
"Width": 800 |
|||
} |
|||
} |
@ -0,0 +1,20 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create JSON values
|
|||
json j_empty_init_list = json({}); |
|||
json j_object = { {"one", 1}, {"two", 2} }; |
|||
json j_array = {1, 2, 3, 4}; |
|||
json j_nested_object = { {"one", {1}}, {"two", {1, 2}} }; |
|||
json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} }; |
|||
|
|||
// serialize the JSON value
|
|||
std::cout << j_empty_init_list << '\n'; |
|||
std::cout << j_object << '\n'; |
|||
std::cout << j_array << '\n'; |
|||
std::cout << j_nested_object << '\n'; |
|||
std::cout << j_nested_array << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/r7SIosyJCePZZvqh"><b>online</b></a> |
@ -0,0 +1,5 @@ |
|||
{} |
|||
{"one":1,"two":2} |
|||
[1,2,3,4] |
|||
{"one":[1],"two":[1,2]} |
|||
[[[1],"one"],[[1,2],"two"]] |
@ -0,0 +1,16 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create a JSON value
|
|||
json a = 23; |
|||
|
|||
// move contents of a to b
|
|||
json b(std::move(a)); |
|||
|
|||
// serialize the JSON arrays
|
|||
std::cout << a << '\n'; |
|||
std::cout << b << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/y7ngrkT74SN0fFWG"><b>online</b></a> |
@ -0,0 +1,2 @@ |
|||
null |
|||
23 |
@ -0,0 +1,12 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create a JSON null value
|
|||
json j(nullptr); |
|||
|
|||
// serialize the JSON null value
|
|||
std::cout << j << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Y7B27Mtrcp64PI9l"><b>online</b></a> |
@ -0,0 +1 @@ |
|||
null |
@ -0,0 +1,21 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create values of different floating-point types
|
|||
json::number_float_t v_ok = 3.141592653589793; |
|||
json::number_float_t v_nan = NAN; |
|||
json::number_float_t v_infinity = INFINITY; |
|||
|
|||
// create JSON numbers
|
|||
json j_ok(v_ok); |
|||
json j_nan(v_nan); |
|||
json j_infinity(v_infinity); |
|||
|
|||
// serialize the JSON numbers
|
|||
std::cout << j_ok << '\n'; |
|||
std::cout << j_nan << '\n'; |
|||
std::cout << j_infinity << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/rsIsQEvaeJEaJx9c"><b>online</b></a> |
@ -0,0 +1,3 @@ |
|||
3.14159265358979 |
|||
null |
|||
null |
@ -0,0 +1,14 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create a JSON number from number_integer_t
|
|||
json::number_integer_t value = 42; |
|||
|
|||
json j(value); |
|||
|
|||
// serialize the JSON numbers
|
|||
std::cout << j << '\n'; |
|||
} |
@ -0,0 +1 @@ |
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/3aV9OONj8OfHPXBV"><b>online</b></a> |
@ -0,0 +1 @@ |
|||
42 |
@ -0,0 +1,15 @@ |
|||
#include <json.hpp>
|
|||
|
|||
using json = nlohmann::json; |
|||
|
|||
int main() |
|||
{ |
|||
// create an object_t value
|
|||
json::object_t value = { {"one", 1}, {"two", 2} }; |
|||
|
|||
// create a JSON object from the value
|
|||
json j(value); |
|||
|
|||
// serialize the JSON object
|
|||
std::cout << j << '\n'; |
|||
} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue