114 Commits

Author SHA1 Message Date
1722f61250 negative_bloom 2023-05-11 02:12:05 +02:00
0abb860185 update tracy to v0.9.1 2023-03-05 00:11:16 +01:00
22dc949cc5 update stb to latest, reenable perlin noise 2023-03-05 00:04:31 +01:00
196ea7b93b update imgui to v1.89.3 2023-03-04 23:47:18 +01:00
f655da82d5 silence more conversion warnings 2023-03-04 19:38:13 +01:00
d672f8a52c update github ci emscripten to 3.1.32 2023-03-04 19:14:26 +01:00
6df865de3e fix warning for release builds for opengl es / webgl 2023-03-04 18:57:44 +01:00
e9c62f9201 add small helper to scalar range 2023-03-04 02:35:06 +01:00
7bce78167b mark data const in net interface 2022-12-07 18:42:11 +01:00
a45da5c2b0 remove questionable assert in s6zer 2022-12-07 18:40:12 +01:00
4ab1d99529 add color component as s6zer, will do more later 2022-12-07 00:35:25 +01:00
f27300a8fa add new serializer based on bitpacking
it has the important stuff, but still misses conviniences like buffers
and optimizations like varints.
only works for little endian but theoretically only needs endian
detection to be able to support bigendian
2022-12-07 00:35:25 +01:00
8d24976a13 entt update to v3.11.1 2022-12-03 20:26:24 +01:00
8036fdf2a9 constexpr range 2022-12-02 00:59:09 +01:00
5148ea7217 componets json with defaults, minor formatting 2022-11-26 13:48:52 +01:00
ab0e5afb94 add ordered_json variants for reading files 2022-11-24 20:50:02 +01:00
191e9f6b44 ico for exe 2022-11-24 20:44:13 +01:00
86c52c4fac add sound sfxr loaders 2022-11-18 22:32:10 +01:00
0c1a98cfd5 fix opengl shader mismatch when linking on intel 2022-11-15 20:22:41 +01:00
a9e56b9e25 fix logging 2022-11-08 18:26:24 +01:00
eeb8be6a8e update spdlog to v1.11.0 2022-11-08 17:47:58 +01:00
c4bd4fd678 merge test into main workflow 2022-11-07 01:54:45 +01:00
9f6e9defb0 make tests auto terminate 2022-11-07 01:54:45 +01:00
5ed71690c7 run tests using headless X 2022-11-07 01:54:45 +01:00
e108d14e1d forgot imgui cmake version 2022-11-06 15:34:13 +01:00
20dd451cd0 fix linker warning and add lto example as comment 2022-11-06 15:31:38 +01:00
3f03bbbd49 windows ci timed out 2022-11-01 19:01:09 +01:00
9af3df5550 fix SDL_main windows thingy 2022-11-01 18:44:34 +01:00
8e5471480c fix vcpkg sdl package not properly exposing linkage flags 2022-11-01 15:41:41 +01:00
8ace6e51f9 fix msvc complaining 2022-11-01 00:15:05 +01:00
2b6a6b3e0c enable windows ci 2022-11-01 00:15:05 +01:00
dffbad65d2 fix cmake sdl finding, find_package for each cmake scope 2022-11-01 00:15:05 +01:00
4d0f731d8d better cmake for emscripten flags 2022-10-30 18:18:20 +01:00
c13dff8eb3 add some more c++17 2022-10-30 18:18:20 +01:00
8cc473b9fc fix emscripten + tracy wrong include path 2022-10-30 18:18:20 +01:00
53c7bc1477 add emscripten to the ci 2022-10-30 18:18:20 +01:00
7d983244b2 update nlohmann::json to v3.11.2 2022-10-30 02:36:30 +02:00
26a1f4b101 fix: use newer action/checkout 2022-10-27 17:29:21 +02:00
5004e30e18 update tracy to v0.9 and adopt 2022-10-27 16:36:40 +02:00
cc40740cf1 update physfs to latest (v3.2.0) 2022-10-01 22:44:29 +02:00
3d03881002 add simple tracy build to github ci 2022-08-11 16:00:43 +02:00
3b2cd5c62b update Tracy to v0.8.2.1 2022-08-11 16:00:43 +02:00
ee16ca5356 update soloud to latest 2022-08-08 14:54:54 +02:00
4b707a7adb update physfs to latest 2022-08-08 13:22:01 +02:00
e1bf5fefc0 fix imgui now requiring atleast c++11 2022-08-03 16:09:22 +02:00
e65878509e update dear ImGui to v1.88 2022-08-03 01:58:55 +02:00
5ed74d956d update googletest to v1.12.1 2022-08-03 01:49:04 +02:00
989e3f7dda change default bloom factor to a more reasonable 0.8 2022-08-02 14:53:21 +02:00
95b9a17af4 update nlohmann::json to v3.11.1 2022-08-02 14:28:39 +02:00
aa81118c40 update EnTT to v3.10.3 2022-08-02 14:25:56 +02:00
62c8b10131 fix: rename file to interface 2022-08-01 18:49:55 +02:00
c1f87aceda rich presence interface draft 2022-07-02 23:36:25 +02:00
2ee17a63ea allow setting target fbo for imgui rendertask 2022-06-29 23:11:34 +02:00
9aa6618e0f replace high_resolution_clock for steady_clock 2022-06-11 11:48:11 +02:00
0f361f6505 add mushmachine ascii art 2022-05-16 18:25:41 +02:00
6b06d5cb99 update all cmake files to version 3.9
other misc cmake fixes

version 3.9 allows for ipo (lto)
2022-05-03 19:33:19 +02:00
052bdb45ec update entt to v3.10.1 2022-04-28 16:12:51 +02:00
a6950b9de7 add more related repos to the README 2022-04-26 15:44:00 +02:00
5023a658e7 allow changing particle buffer size 2022-04-26 15:27:15 +02:00
5cc6aa8c74 fix liteparticles2d being named hdr_bloom 2022-04-26 01:01:21 +02:00
563dd80a52 fix liteparticles shaders not compiling on windows firefox webgl d3d 2022-04-25 23:53:47 +02:00
1ae43457ed lite_particles2d 2022-04-18 17:24:01 +02:00
5f066faa28 fix tracy for emscripten 2022-04-16 20:33:35 +02:00
bbbbc655e7 update tracy to v0.8 2022-04-15 18:19:45 +02:00
410b373fda update spdlog to v1.10.0 2022-04-15 18:09:53 +02:00
72add20751 update EnTT to v3.10.0 2022-04-15 16:37:53 +02:00
4dd5a69dee port to EnTT v3.10.0 2022-04-15 16:37:53 +02:00
e0f503728d add glsl noise lib 2022-04-14 18:05:15 +02:00
b520811e72 add missing 4 comp hash variants 2022-04-13 23:35:56 +02:00
69a04cbd7e refactor ogl buffer 2022-04-13 01:23:39 +02:00
ab169927fe improve resouce iteration 2022-04-12 16:44:28 +02:00
a98098af91 add dither noise to comp 2022-04-05 22:48:01 +02:00
631b9433c2 adding David Hoskins's hasing functions to shader builtins
https://www.shadertoy.com/view/4djSRW (hash without sine)
2022-04-02 16:12:20 +02:00
15ab73909f fix scene tools 2022-03-30 23:01:39 +02:00
3dc66de3bc change bloom render texture format, and make gles/webgl work properly 2022-03-29 15:32:33 +02:00
5e58a61c93 new bloom render tasks, setup util and hdr bloom code example 2022-03-28 14:22:46 +02:00
8f44e09f32 add trim 2022-03-10 19:10:29 +01:00
0408f771b7 fix builtins test vertex shader 2022-02-22 01:46:39 +01:00
4029dcd50c add builtin shaders 2022-02-21 00:42:18 +01:00
338fbf70d0 add gles build to github 2022-02-19 00:59:07 +01:00
e39b23ac72 better fbo building error printing 2022-02-19 00:56:16 +01:00
c48ae81238 disable ms for gles 2022-02-18 17:21:53 +01:00
7a461111e1 change blur to allow output to a different buffer then input 2022-02-18 00:41:34 +01:00
9ff0b17a5e [tilemap] add bias to verts to avoid cracks 2022-02-17 18:54:11 +01:00
60aca24ec6 add multisampled fbo support + multisampled fixes 2022-02-17 16:28:54 +01:00
4304701e5e fix camera, broken since f5eb0e0dfa 2022-02-17 00:53:21 +01:00
601e1ca99d add multisampled textures 2022-02-16 19:22:25 +01:00
f5eb0e0dfa add camera view dir helper 2022-02-15 17:21:45 +01:00
49ed05dfd6 lil fixes in readme 2022-02-12 17:14:52 +01:00
71486b2550 macos github workflow 2022-02-11 18:14:27 +01:00
5089fd91aa replace physfs 2022-02-11 18:05:20 +01:00
bfe09374bb make timer cleaner 2022-02-09 11:23:23 +01:00
a2b056f385 change scene engine from pointer to reference 2022-02-08 21:06:22 +01:00
a8b3b25e7d disable shader validation, as i misunderstood its use 2022-02-08 20:33:55 +01:00
170b21089f force c++11 on text editor 2022-02-08 19:36:31 +01:00
cec80fd492 reduce backends soloud builds 2022-02-08 19:24:59 +01:00
b3d700e910 update imgui to v1.87 2022-02-07 22:45:50 +01:00
592138845c little sound json thingy 2022-02-07 22:43:37 +01:00
6aa7e3899e add screen to world to camera 2022-02-01 15:28:15 +01:00
e64c68d942 fix error in mm_logo_screen 2022-01-27 17:42:16 +01:00
513ac12e30 fix aa causing gaps 2022-01-22 01:42:37 +01:00
597a98c3b5 more trace logging in filesystem 2022-01-11 18:55:02 +01:00
12b0a90ad0 remove old transform and velocity components and replace with new decomposed components
focus on 2D for now
2022-01-09 18:32:59 +01:00
c36fa30cbc update copyright year 2022-01-04 20:43:00 +01:00
0dbe049a00 hacking on the experimental net interface 2021-12-23 15:57:40 +01:00
81043264d2 update to entt v3.9.0 2021-12-21 14:04:02 +01:00
494912ce8a wip gh workflows
TODO: windows is broken
2021-12-14 17:02:17 +01:00
edcecba2eb port everything over to organizer 2021-12-12 22:56:16 +01:00
edec5e51d3 update tracy to v0.7.8 2021-12-12 00:23:02 +01:00
2091d3f97c update stb (temporarily removes stb_perlin bc of patent) 2021-12-11 23:55:08 +01:00
c046bd7663 update spdlog to 1.9.2 2021-12-11 23:46:26 +01:00
42ff7c8099 update nlohmann::json to 3.10.4 2021-12-11 23:32:21 +01:00
4a1dde26ce update imgui to v1.85 2021-12-11 23:22:58 +01:00
0ad504e5d4 remove simple scene and disable most stuff that used it. TODO: replace with organizer 2021-12-11 23:21:09 +01:00
273 changed files with 19941 additions and 15910 deletions

163
.github/workflows/cmake.yml vendored Normal file
View File

@ -0,0 +1,163 @@
name: CMake
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug
EM_VERSION: 3.1.32
EM_CACHE_FOLDER: 'emsdk-cache'
jobs:
linux:
timeout-minutes: 10
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Dependencies
run: sudo apt update && sudo apt -y install libsdl2-dev xserver-xorg-video-dummy
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
#run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
# TODO: look into xinit
env:
DISPLAY: :0
run: |
sudo Xorg :0 -config ${{github.workspace}}/.github/workflows/x/dummy-1920x1080.conf -noautoBindGPU &
sleep 20s
ctest --output-on-failure --timeout 20
sudo pkill -15 Xorg
linux_gles:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Dependencies
run: sudo apt update && sudo apt -y install libsdl2-dev
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DMM_OPENGL_3_GLES=ON
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
linux_tracy:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Dependencies
run: sudo apt update && sudo apt -y install libsdl2-dev
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTRACY_ENABLE=ON
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
emscripten:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
with:
# Make sure to set a version number!
version: ${{env.EM_VERSION}}
# This is the name of the cache folder.
# The cache folder will be placed in the build directory,
# so make sure it doesn't conflict with anything!
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
- name: Verify
run: emcc --check
- name: Configure CMake
run: emcmake cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DMM_OPENGL_3_GLES=ON
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
macos:
timeout-minutes: 10
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Dependencies
run: brew install sdl2
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
windows:
timeout-minutes: 15 # TODO: caching
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
# TODO: cache
- name: Install Dependencies
run: vcpkg install sdl2[core,vulkan]:x64-windows
# setup vs env
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64
- name: Configure CMake
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4

View File

@ -0,0 +1,21 @@
# https://wiki.archlinux.org/title/Xorg
Section "Monitor"
Identifier "dummy_monitor"
HorizSync 28.0-80.0
VertRefresh 48.0-75.0
Modeline "1920x1080" 172.80 1920 2040 2248 2576 1080 1081 1084 1118
EndSection
Section "Device"
Identifier "dummy_card"
VideoRam 256000
Driver "dummy"
EndSection
Section "Screen"
Identifier "dummy_screen"
Device "dummy_card"
Monitor "dummy_monitor"
SubSection "Display"
EndSubSection
EndSection

8
.gitmodules vendored
View File

@ -19,10 +19,6 @@
[submodule "external/ImGuiColorTextEdit"] [submodule "external/ImGuiColorTextEdit"]
path = external/ImGuiColorTextEdit path = external/ImGuiColorTextEdit
url = https://github.com/BalazsJako/ImGuiColorTextEdit.git url = https://github.com/BalazsJako/ImGuiColorTextEdit.git
[submodule "external/physfs"]
path = external/physfs
url = https://github.com/Green-Sky/physfs.git
shallow = true
[submodule "external/soloud/soloud"] [submodule "external/soloud/soloud"]
path = external/soloud/soloud path = external/soloud/soloud
url = https://github.com/jarikomppa/soloud.git url = https://github.com/jarikomppa/soloud.git
@ -37,3 +33,7 @@
path = external/tracy/tracy path = external/tracy/tracy
url = https://github.com/wolfpld/tracy.git url = https://github.com/wolfpld/tracy.git
shallow = true shallow = true
[submodule "external/physfs/physfs"]
path = external/physfs/physfs
url = https://github.com/icculus/physfs.git
branch = main

28
.vimspector.json Normal file
View File

@ -0,0 +1,28 @@
{
"configurations": {
"run_ctest_native": {
"default": true,
"adapter": "CodeLLDB",
"configuration": {
"request": "launch",
"stopOnEntry": true,
"console": "integratedTerminal",
"program": "ctest",
"cwd": "${workspaceRoot}/build"
}
},
"run_native": {
"adapter": "CodeLLDB",
"variables": {
"Executable": "s6zer_test"
},
"configuration": {
"request": "launch",
"stopOnEntry": true,
"console": "integratedTerminal",
"program": "${workspaceRoot}/build/bin/${Executable}",
"cwd": "${workspaceRoot}/build"
}
}
}
}

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
# cmake setup begin # cmake setup begin
project(MushMachine C CXX) project(MushMachine C CXX)
@ -19,6 +19,18 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
# add this to your projects cmake to enable ipo
#if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
#include(CheckIPOSupported)
#check_ipo_supported(RESULT HAVE_LTO)
#if(HAVE_LTO)
#set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
#message(STATUS "Enabled LTO")
#else()
#message(STATUS "LTO not supported")
#endif()
#endif()
# enable test # enable test
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest) include(CTest)

View File

@ -3,7 +3,7 @@ The Code is under the following License, if not stated otherwise:
MIT License MIT License
Copyright (c) 2018-2019 Felix Richter Copyright (c) 2018-2019 Felix Richter
Copyright (c) 2018-2021 Erik Scholz Copyright (c) 2018-2022 Erik Scholz
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,7 +1,7 @@
![mm](res/mm_card.png) ![mm](res/mm_card.png)
# MushMachine # MushMachine
This is a Game Engine/Framework, originally developed for GH**deducted** (a 2D game), but has since expanded its scope to be more generic. For example it also includes 3D stuff, instead of just 2D. Furthermore it got stripped of some dependency heavy dependencies (yea that's a thing). This is a Game Engine/Framework, originally developed for GH**deducted** (a 2D game), but has since expanded it's scope to be more generic. For example it also includes 3D stuff, instead of just 2D. Furthermore it got stripped of some dependency heavy dependencies (yea that's a thing).
The initial Developers are Erik Scholz and Felix Richter. The initial Developers are Erik Scholz and Felix Richter.
Currently developed and maintained by Erik Scholz. Currently developed and maintained by Erik Scholz.
@ -13,10 +13,18 @@ The private repo had over 900 commits, before the first public release.
- [Github](https://github.com/MadeOfJelly/MushMachine) - [Github](https://github.com/MadeOfJelly/MushMachine)
- [Setup](docs/setup.md) - [Setup](docs/setup.md)
- [Example Game Setup](docs/basic_game.md) - [Example Game Setup](docs/basic_game.md)
- The [Docs Directory](docs/) contains Documentation loosly based on the Source structure. - [mm_template](https://github.com/MadeOfJelly/mm_template) (a GitHub Template for quick starting MM game dev)
- The [Docs Directory](docs/) contains Documentation loosely based on the Source structure.
- Engine Extensions:
- [Box2D integration](https://github.com/Green-Sky/mushmachine_box2d)
- [fx_draw (simple line drawing rendertask)](https://github.com/Green-Sky/fx_draw)
- Projects using the Engine:
- [miniTD](https://github.com/Green-Sky/miniTD)
- [LiteParticles2DDemo](https://github.com/MadeOfJelly/mm_lite_particles2d_demo)
- [mm_fireworks](https://github.com/Green-Sky/mm_fireworks)
## Platforms ## Platforms
- PC (Linux, Windows and maybe APPLE(untested)) - PC (Linux, Windows and maybe APPLE(compiles))
- Android (untested) - Android (untested)
- Web (huh? yea! via Emscripten, wasm and WebGL2) - Web (huh? yea! via Emscripten, wasm and WebGL2)
- anything if you put your mind to it.... - anything if you put your mind to it....
@ -24,7 +32,7 @@ The private repo had over 900 commits, before the first public release.
## Roadmap ## Roadmap
- Rewrite the Input service (the code was ported in and is older than the Engine (2017)) - Rewrite the Input service (the code was ported in and is older than the Engine (2017))
- Extend the SDL service with Vulkan support (it's 2020 so yea) - Extend the SDL service with Vulkan support (it's 2020 so yea)(man it's 2022 and not done)
- Filesystem refactor (like a proper file type, with destructor and stuff) - Filesystem refactor (like a proper file type, with destructor and stuff)
- l10n support - l10n support
- ImGui integration refactor (for making it usable as a game ui, not just for debugging) - ImGui integration refactor (for making it usable as a game ui, not just for debugging)

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
# external libs # external libs
@ -26,6 +26,7 @@ add_subdirectory("physfs")
if(NOT MM_HEADLESS) if(NOT MM_HEADLESS)
if(NOT EMSCRIPTEN) if(NOT EMSCRIPTEN)
# TODO: move into imgui and soload, since they are the one requireing this
if(VCPKG_TARGET_TRIPLET) if(VCPKG_TARGET_TRIPLET)
find_package(SDL2 CONFIG REQUIRED) find_package(SDL2 CONFIG REQUIRED)
else() # HACK: fix sdl find module else() # HACK: fix sdl find module

View File

@ -1,9 +1,10 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
add_library(imgui_color_text_edit add_library(imgui_color_text_edit
"${CMAKE_CURRENT_LIST_DIR}/ImGuiColorTextEdit/TextEditor.h" "${CMAKE_CURRENT_LIST_DIR}/ImGuiColorTextEdit/TextEditor.h"
"${CMAKE_CURRENT_LIST_DIR}/ImGuiColorTextEdit/TextEditor.cpp" "${CMAKE_CURRENT_LIST_DIR}/ImGuiColorTextEdit/TextEditor.cpp"
) )
target_compile_features(imgui_color_text_edit PUBLIC cxx_std_11)
target_include_directories(imgui_color_text_edit PUBLIC "${CMAKE_CURRENT_LIST_DIR}/ImGuiColorTextEdit") target_include_directories(imgui_color_text_edit PUBLIC "${CMAKE_CURRENT_LIST_DIR}/ImGuiColorTextEdit")
target_link_libraries(imgui_color_text_edit target_link_libraries(imgui_color_text_edit
imgui imgui

View File

@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.2) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(SquirrelNoise) project(SquirrelNoise)
add_library(squirrel_noise add_library(squirrel_noise

2
external/entt vendored

2
external/entt.cmake vendored
View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
add_library(entt INTERFACE) add_library(entt INTERFACE)
target_include_directories(entt INTERFACE "${CMAKE_CURRENT_LIST_DIR}/entt/src") target_include_directories(entt INTERFACE "${CMAKE_CURRENT_LIST_DIR}/entt/src")
target_compile_features(entt INTERFACE cxx_std_17) target_compile_features(entt INTERFACE cxx_std_17)

View File

@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.2) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(glad C) project(glad C)
set(C_FILES set(C_FILES
@ -15,8 +16,6 @@ add_library(glad ${C_FILES} ${H_FILES})
target_include_directories(glad PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_include_directories(glad PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
if(UNIX) if(UNIX)
target_link_libraries(glad target_link_libraries(glad dl)
dl
)
endif() endif()

3
external/glm.cmake vendored
View File

@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
add_library(glm INTERFACE) add_library(glm INTERFACE)
target_include_directories(glm INTERFACE "${CMAKE_CURRENT_LIST_DIR}/glm") target_include_directories(glm INTERFACE "${CMAKE_CURRENT_LIST_DIR}/glm")
target_compile_definitions(glm INTERFACE GLM_ENABLE_EXPERIMENTAL)

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
add_library(icon_font_cpp_headers INTERFACE) add_library(icon_font_cpp_headers INTERFACE)
target_include_directories(icon_font_cpp_headers INTERFACE "${CMAKE_CURRENT_LIST_DIR}/IconFontCppHeaders/") target_include_directories(icon_font_cpp_headers INTERFACE "${CMAKE_CURRENT_LIST_DIR}/IconFontCppHeaders/")

View File

@ -1,50 +1,40 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(imgui C CXX) project(imgui C CXX)
set(CPP_FILES add_library(imgui
"imgui/imgui.h"
"imgui/imgui.cpp" "imgui/imgui.cpp"
"imgui/imgui_draw.cpp" "imgui/imgui_draw.cpp"
"imgui/imgui_widgets.cpp" "imgui/imgui_widgets.cpp"
"imgui/imgui_tables.cpp" "imgui/imgui_tables.cpp"
"imgui/imgui_demo.cpp" "imgui/imgui_demo.cpp"
"imgui/misc/cpp/imgui_stdlib.cpp"
"imgui_plot_var.cpp"
#"imgui_impl_sdl_gl3.cpp" # very old
#"imgui_impl_sdl.cpp" # old
#"imgui_impl_opengl3.cpp" # old
"imgui/backends/imgui_impl_sdl.cpp"
"imgui/backends/imgui_impl_opengl3.cpp"
)
set(HPP_FILES
"imgui/imgui.h"
"imgui/imstb_rectpack.h" "imgui/imstb_rectpack.h"
"imgui/imstb_textedit.h" "imgui/imstb_textedit.h"
"imgui/imstb_truetype.h" "imgui/imstb_truetype.h"
"imgui/misc/cpp/imgui_stdlib.h" "imgui/misc/cpp/imgui_stdlib.h"
"imgui/misc/cpp/imgui_stdlib.cpp"
"imgui_plot_var.hpp" "imgui_plot_var.hpp"
"imgui_plot_var.cpp"
#"imgui_impl_sdl_gl3.h" # very old # TODO: seperate backends into libs
#"imgui_impl_sdl.h" # old "imgui/backends/imgui_impl_sdl2.h"
#"imgui_impl_opengl3.h" # old "imgui/backends/imgui_impl_sdl2.cpp"
"imgui/backends/imgui_impl_sdl.h"
"imgui/backends/imgui_impl_opengl3.h" "imgui/backends/imgui_impl_opengl3.h"
"imgui/backends/imgui_impl_opengl3.cpp"
) )
add_library(imgui ${CPP_FILES} ${HPP_FILES}) target_compile_features(imgui PUBLIC cxx_std_11)
if(MM_OPENGL_3_GLES) if(MM_OPENGL_3_GLES)
target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_ES3) target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_ES3)
target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM) # bug? target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM) # bug?
else() else()
target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_LOADER_GLAD) target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_LOADER_GLAD)
target_link_libraries(imgui glad) target_link_libraries(imgui PUBLIC glad)
endif() endif()
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
@ -54,15 +44,21 @@ target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui") # i
target_compile_definitions(imgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1) target_compile_definitions(imgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1)
if(EMSCRIPTEN) if(EMSCRIPTEN)
set_target_properties(imgui PROPERTIES COMPILE_FLAGS "-s USE_SDL=2 -s USE_WEBGL2=1 -s FULL_ES2=1 -s FULL_ES3=1") target_compile_options(imgui PUBLIC -sUSE_SDL=2)
set_target_properties(imgui PROPERTIES LINK_FLAGS "-s USE_SDL=2 -s USE_WEBGL2=1 -s FULL_ES2=1 -s FULL_ES3=1") target_link_libraries(imgui PUBLIC -sUSE_SDL=2 -sUSE_WEBGL2=1 -sFULL_ES3=1)
elseif(ANDROID) elseif(ANDROID)
target_link_libraries(imgui SDL) target_link_libraries(imgui PUBLIC SDL)
elseif(VCPKG_TARGET_TRIPLET) elseif(VCPKG_TARGET_TRIPLET)
target_link_libraries(imgui SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static) target_link_libraries(imgui
PUBLIC
SDL2::SDL2
#PRIVATE
#SDL2::SDL2main
#SDL2::SDL2-static
)
else() else()
target_include_directories(imgui PUBLIC "${SDL2_INCLUDE_DIR}") target_include_directories(imgui PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(imgui ${SDL2_LIBRARY}) target_link_libraries(imgui PUBLIC ${SDL2_LIBRARY})
endif() endif()
target_compile_definitions(imgui PUBLIC ImTextureID=unsigned\ long) target_compile_definitions(imgui PUBLIC ImTextureID=unsigned\ long)

View File

@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
## ##
## PROJECT ## PROJECT
## name and version ## name and version
## ##
project(nlohmann_json VERSION 3.8.0 LANGUAGES CXX) project(nlohmann_json VERSION 3.10.4 LANGUAGES CXX)
## ##

21
external/json/LICENSE.MIT vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2013-2022 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.

View File

@ -1,49 +1,55 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <utility> #include <utility>
#include <nlohmann/detail/abi_macros.hpp>
#include <nlohmann/detail/conversions/from_json.hpp> #include <nlohmann/detail/conversions/from_json.hpp>
#include <nlohmann/detail/conversions/to_json.hpp> #include <nlohmann/detail/conversions/to_json.hpp>
#include <nlohmann/detail/meta/identity_tag.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
template<typename, typename> /// @sa https://json.nlohmann.me/api/adl_serializer/
template<typename ValueType, typename>
struct adl_serializer struct adl_serializer
{ {
/*! /// @brief convert a JSON value to any value type
@brief convert a JSON value to any value type /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
template<typename BasicJsonType, typename TargetType = ValueType>
This function is usually called by the `get()` function of the static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
@ref basic_json class (either explicit or via conversion operators).
@param[in] j JSON value to read from
@param[in,out] val value to write to
*/
template<typename BasicJsonType, typename ValueType>
static auto from_json(BasicJsonType&& j, ValueType& val) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val))) noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void()) -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
{ {
::nlohmann::from_json(std::forward<BasicJsonType>(j), val); ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
} }
/*! /// @brief convert a JSON value to any value type
@brief convert any value type to a JSON value /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
template<typename BasicJsonType, typename TargetType = ValueType>
This function is usually called by the constructors of the @ref basic_json static auto from_json(BasicJsonType && j) noexcept(
class. noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
@param[in,out] j JSON value to write to
@param[in] val value to read from
*/
template<typename BasicJsonType, typename ValueType>
static auto to_json(BasicJsonType& j, ValueType&& val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)), void())
{ {
::nlohmann::to_json(j, std::forward<ValueType>(val)); return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
}
/// @brief convert any value type to a JSON value
/// @sa https://json.nlohmann.me/api/adl_serializer/to_json/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
{
::nlohmann::to_json(j, std::forward<TargetType>(val));
} }
}; };
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,53 +1,56 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <cstdint> // uint8_t #include <cstdint> // uint8_t, uint64_t
#include <tuple> // tie #include <tuple> // tie
#include <utility> // move #include <utility> // move
namespace nlohmann #include <nlohmann/detail/abi_macros.hpp>
{
/*! NLOHMANN_JSON_NAMESPACE_BEGIN
@brief an internal type for a backed binary type
This type extends the template parameter @a BinaryType provided to `basic_json` /// @brief an internal type for a backed binary type
with a subtype used by BSON and MessagePack. This type exists so that the user /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/
does not have to specify a type themselves with a specific naming scheme in
order to override the binary type.
@tparam BinaryType container to store bytes (`std::vector<std::uint8_t>` by
default)
@since version 3.8.0
*/
template<typename BinaryType> template<typename BinaryType>
class byte_container_with_subtype : public BinaryType class byte_container_with_subtype : public BinaryType
{ {
public: public:
/// the type of the underlying container
using container_type = BinaryType; using container_type = BinaryType;
using subtype_type = std::uint64_t;
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype() noexcept(noexcept(container_type())) byte_container_with_subtype() noexcept(noexcept(container_type()))
: container_type() : container_type()
{} {}
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b))) byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b)))
: container_type(b) : container_type(b)
{} {}
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b)))) byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
: container_type(std::move(b)) : container_type(std::move(b))
{} {}
byte_container_with_subtype(const container_type& b, std::uint8_t subtype) noexcept(noexcept(container_type(b))) /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
: container_type(b) : container_type(b)
, m_subtype(subtype) , m_subtype(subtype_)
, m_has_subtype(true) , m_has_subtype(true)
{} {}
byte_container_with_subtype(container_type&& b, std::uint8_t subtype) noexcept(noexcept(container_type(std::move(b)))) /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
: container_type(std::move(b)) : container_type(std::move(b))
, m_subtype(subtype) , m_subtype(subtype_)
, m_has_subtype(true) , m_has_subtype(true)
{} {}
@ -62,96 +65,30 @@ class byte_container_with_subtype : public BinaryType
return !(rhs == *this); return !(rhs == *this);
} }
/*! /// @brief sets the binary subtype
@brief sets the binary subtype /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/set_subtype/
void set_subtype(subtype_type subtype_) noexcept
Sets the binary subtype of the value, also flags a binary JSON value as
having a subtype, which has implications for serialization.
@complexity Constant.
@exceptionsafety No-throw guarantee: this member function never throws
exceptions.
@sa @ref subtype() -- return the binary subtype
@sa @ref clear_subtype() -- clears the binary subtype
@sa @ref has_subtype() -- returns whether or not the binary value has a
subtype
@since version 3.8.0
*/
void set_subtype(std::uint8_t subtype) noexcept
{ {
m_subtype = subtype; m_subtype = subtype_;
m_has_subtype = true; m_has_subtype = true;
} }
/*! /// @brief return the binary subtype
@brief return the binary subtype /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/subtype/
constexpr subtype_type subtype() const noexcept
Returns the numerical subtype of the value if it has a subtype. If it does
not have a subtype, this function will return size_t(-1) as a sentinel
value.
@return the numerical subtype of the binary value
@complexity Constant.
@exceptionsafety No-throw guarantee: this member function never throws
exceptions.
@sa @ref set_subtype() -- sets the binary subtype
@sa @ref clear_subtype() -- clears the binary subtype
@sa @ref has_subtype() -- returns whether or not the binary value has a
subtype
@since version 3.8.0
*/
constexpr std::uint8_t subtype() const noexcept
{ {
return m_subtype; return m_has_subtype ? m_subtype : static_cast<subtype_type>(-1);
} }
/*! /// @brief return whether the value has a subtype
@brief return whether the value has a subtype /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/has_subtype/
@return whether the value has a subtype
@complexity Constant.
@exceptionsafety No-throw guarantee: this member function never throws
exceptions.
@sa @ref subtype() -- return the binary subtype
@sa @ref set_subtype() -- sets the binary subtype
@sa @ref clear_subtype() -- clears the binary subtype
@since version 3.8.0
*/
constexpr bool has_subtype() const noexcept constexpr bool has_subtype() const noexcept
{ {
return m_has_subtype; return m_has_subtype;
} }
/*! /// @brief clears the binary subtype
@brief clears the binary subtype /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/clear_subtype/
Clears the binary subtype and flags the value as not having a subtype, which
has implications for serialization; for instance MessagePack will prefer the
bin family over the ext family.
@complexity Constant.
@exceptionsafety No-throw guarantee: this member function never throws
exceptions.
@sa @ref subtype() -- return the binary subtype
@sa @ref set_subtype() -- sets the binary subtype
@sa @ref has_subtype() -- returns whether or not the binary value has a
subtype
@since version 3.8.0
*/
void clear_subtype() noexcept void clear_subtype() noexcept
{ {
m_subtype = 0; m_subtype = 0;
@ -159,8 +96,8 @@ class byte_container_with_subtype : public BinaryType
} }
private: private:
std::uint8_t m_subtype = 0; subtype_type m_subtype = 0;
bool m_has_subtype = false; bool m_has_subtype = false;
}; };
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -0,0 +1,100 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once
// This file contains all macro definitions affecting or depending on the ABI
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
#if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
#if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 2
#warning "Already included a different version of the library!"
#endif
#endif
#endif
#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_PATCH 2 // NOLINT(modernize-macro-to-enum)
#ifndef JSON_DIAGNOSTICS
#define JSON_DIAGNOSTICS 0
#endif
#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
#endif
#if JSON_DIAGNOSTICS
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag
#else
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS
#endif
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp
#else
#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
#endif
#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
#endif
// Construct the namespace ABI tags component
#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b
#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \
NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)
#define NLOHMANN_JSON_ABI_TAGS \
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)
// Construct the namespace version component
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
_v ## major ## _ ## minor ## _ ## patch
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
#define NLOHMANN_JSON_NAMESPACE_VERSION
#else
#define NLOHMANN_JSON_NAMESPACE_VERSION \
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
NLOHMANN_JSON_VERSION_MINOR, \
NLOHMANN_JSON_VERSION_PATCH)
#endif
// Combine namespace components
#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
#ifndef NLOHMANN_JSON_NAMESPACE
#define NLOHMANN_JSON_NAMESPACE \
nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
NLOHMANN_JSON_ABI_TAGS, \
NLOHMANN_JSON_NAMESPACE_VERSION)
#endif
#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
#define NLOHMANN_JSON_NAMESPACE_BEGIN \
namespace nlohmann \
{ \
inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
NLOHMANN_JSON_ABI_TAGS, \
NLOHMANN_JSON_NAMESPACE_VERSION) \
{
#endif
#ifndef NLOHMANN_JSON_NAMESPACE_END
#define NLOHMANN_JSON_NAMESPACE_END \
} /* namespace (inline namespace) NOLINT(readability/namespace) */ \
} // namespace nlohmann
#endif

View File

@ -1,3 +1,11 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <algorithm> // transform #include <algorithm> // transform
@ -15,19 +23,22 @@
#include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp> #include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/identity_tag.hpp>
#include <nlohmann/detail/meta/std_fs.hpp>
#include <nlohmann/detail/meta/type_traits.hpp> #include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/string_concat.hpp>
#include <nlohmann/detail/value_t.hpp> #include <nlohmann/detail/value_t.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename std::nullptr_t& n) inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_null())) if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
{ {
JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be null, but is ", j.type_name()), &j));
} }
n = nullptr; n = nullptr;
} }
@ -57,83 +68,92 @@ void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
break; break;
} }
case value_t::null:
case value_t::object:
case value_t::array:
case value_t::string:
case value_t::boolean:
case value_t::binary:
case value_t::discarded:
default: default:
JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be number, but is ", j.type_name()), &j));
} }
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) inline void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_boolean())) if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
{ {
JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be boolean, but is ", j.type_name()), &j));
} }
b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>(); b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s) inline void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_string())) if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
{ {
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
} }
s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
} }
template < template <
typename BasicJsonType, typename ConstructibleStringType, typename BasicJsonType, typename StringType,
enable_if_t < enable_if_t <
is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value&& std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
!std::is_same<typename BasicJsonType::string_t, && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
ConstructibleStringType>::value, && !std::is_same<typename BasicJsonType::string_t, StringType>::value
int > = 0 > && !is_json_ref<StringType>::value, int > = 0 >
void from_json(const BasicJsonType& j, ConstructibleStringType& s) inline void from_json(const BasicJsonType& j, StringType& s)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_string())) if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
{ {
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
} }
s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val) inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val)
{ {
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::number_unsigned_t& val) inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_unsigned_t& val)
{ {
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& val) inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& val)
{ {
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
} }
#if !JSON_DISABLE_ENUM_SERIALIZATION
template<typename BasicJsonType, typename EnumType, template<typename BasicJsonType, typename EnumType,
enable_if_t<std::is_enum<EnumType>::value, int> = 0> enable_if_t<std::is_enum<EnumType>::value, int> = 0>
void from_json(const BasicJsonType& j, EnumType& e) inline void from_json(const BasicJsonType& j, EnumType& e)
{ {
typename std::underlying_type<EnumType>::type val; typename std::underlying_type<EnumType>::type val;
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
e = static_cast<EnumType>(val); e = static_cast<EnumType>(val);
} }
#endif // JSON_DISABLE_ENUM_SERIALIZATION
// forward_list doesn't have an insert method // forward_list doesn't have an insert method
template<typename BasicJsonType, typename T, typename Allocator, template<typename BasicJsonType, typename T, typename Allocator,
enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l) inline void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
} }
l.clear(); l.clear();
std::transform(j.rbegin(), j.rend(), std::transform(j.rbegin(), j.rend(),
@ -146,11 +166,11 @@ void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
// valarray doesn't have an insert method // valarray doesn't have an insert method
template<typename BasicJsonType, typename T, template<typename BasicJsonType, typename T,
enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
void from_json(const BasicJsonType& j, std::valarray<T>& l) inline void from_json(const BasicJsonType& j, std::valarray<T>& l)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
} }
l.resize(j.size()); l.resize(j.size());
std::transform(j.begin(), j.end(), std::begin(l), std::transform(j.begin(), j.end(), std::begin(l),
@ -161,7 +181,7 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
} }
template<typename BasicJsonType, typename T, std::size_t N> template<typename BasicJsonType, typename T, std::size_t N>
auto from_json(const BasicJsonType& j, T (&arr)[N]) auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
-> decltype(j.template get<T>(), void()) -> decltype(j.template get<T>(), void())
{ {
for (std::size_t i = 0; i < N; ++i) for (std::size_t i = 0; i < N; ++i)
@ -171,7 +191,7 @@ auto from_json(const BasicJsonType& j, T (&arr)[N])
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/) inline void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/)
{ {
arr = *j.template get_ptr<const typename BasicJsonType::array_t*>(); arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
} }
@ -187,7 +207,10 @@ auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
} }
} }
template<typename BasicJsonType, typename ConstructibleArrayType> template<typename BasicJsonType, typename ConstructibleArrayType,
enable_if_t<
std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
int> = 0>
auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/) auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/)
-> decltype( -> decltype(
arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()), arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
@ -208,9 +231,12 @@ auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p
arr = std::move(ret); arr = std::move(ret);
} }
template<typename BasicJsonType, typename ConstructibleArrayType> template<typename BasicJsonType, typename ConstructibleArrayType,
void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, enable_if_t<
priority_tag<0> /*unused*/) std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
int> = 0>
inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr,
priority_tag<0> /*unused*/)
{ {
using std::end; using std::end;
@ -241,19 +267,37 @@ void())
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
std::string(j.type_name())));
} }
from_json_array_impl(j, arr, priority_tag<3> {}); from_json_array_impl(j, arr, priority_tag<3> {});
} }
template < typename BasicJsonType, typename T, std::size_t... Idx >
std::array<T, sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/)
{
return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
}
template < typename BasicJsonType, typename T, std::size_t N >
auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
-> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
{
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
}
return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
}
template<typename BasicJsonType> template<typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin) inline void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_binary())) if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
{ {
JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be binary, but is ", j.type_name()), &j));
} }
bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>(); bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
@ -261,15 +305,15 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
template<typename BasicJsonType, typename ConstructibleObjectType, template<typename BasicJsonType, typename ConstructibleObjectType,
enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0> enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_object())) if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
{ {
JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be object, but is ", j.type_name()), &j));
} }
ConstructibleObjectType ret; ConstructibleObjectType ret;
auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>(); const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
using value_type = typename ConstructibleObjectType::value_type; using value_type = typename ConstructibleObjectType::value_type;
std::transform( std::transform(
inner_object->begin(), inner_object->end(), inner_object->begin(), inner_object->end(),
@ -293,7 +337,7 @@ template < typename BasicJsonType, typename ArithmeticType,
!std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&& !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
!std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
int > = 0 > int > = 0 >
void from_json(const BasicJsonType& j, ArithmeticType& val) inline void from_json(const BasicJsonType& j, ArithmeticType& val)
{ {
switch (static_cast<value_t>(j)) switch (static_cast<value_t>(j))
{ {
@ -318,44 +362,75 @@ void from_json(const BasicJsonType& j, ArithmeticType& val)
break; break;
} }
case value_t::null:
case value_t::object:
case value_t::array:
case value_t::string:
case value_t::binary:
case value_t::discarded:
default: default:
JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be number, but is ", j.type_name()), &j));
} }
} }
template<typename BasicJsonType, typename A1, typename A2> template<typename BasicJsonType, typename... Args, std::size_t... Idx>
void from_json(const BasicJsonType& j, std::pair<A1, A2>& p) std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> /*unused*/)
{ {
p = {j.at(0).template get<A1>(), j.at(1).template get<A2>()}; return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).template get<Args>()...);
} }
template<typename BasicJsonType, typename Tuple, std::size_t... Idx> template < typename BasicJsonType, class A1, class A2 >
void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence<Idx...> /*unused*/) std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/)
{ {
t = std::make_tuple(j.at(Idx).template get<typename std::tuple_element<Idx, Tuple>::type>()...); return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
std::forward<BasicJsonType>(j).at(1).template get<A2>()};
}
template<typename BasicJsonType, typename A1, typename A2>
inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> /*unused*/)
{
p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
} }
template<typename BasicJsonType, typename... Args> template<typename BasicJsonType, typename... Args>
void from_json(const BasicJsonType& j, std::tuple<Args...>& t) std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> /*unused*/, priority_tag<2> /*unused*/)
{ {
from_json_tuple_impl(j, t, index_sequence_for<Args...> {}); return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
}
template<typename BasicJsonType, typename... Args>
inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> /*unused*/)
{
t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
}
template<typename BasicJsonType, typename TupleRelated>
auto from_json(BasicJsonType&& j, TupleRelated&& t)
-> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
{
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
}
return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
} }
template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator, template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator,
typename = enable_if_t < !std::is_constructible < typename = enable_if_t < !std::is_constructible <
typename BasicJsonType::string_t, Key >::value >> typename BasicJsonType::string_t, Key >::value >>
void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m) inline void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
} }
m.clear(); m.clear();
for (const auto& p : j) for (const auto& p : j)
{ {
if (JSON_HEDLEY_UNLIKELY(!p.is_array())) if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()))); JSON_THROW(type_error::create(302, concat("type must be array, but is ", p.type_name()), &j));
} }
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>()); m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
} }
@ -364,40 +439,59 @@ void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>&
template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator, template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator,
typename = enable_if_t < !std::is_constructible < typename = enable_if_t < !std::is_constructible <
typename BasicJsonType::string_t, Key >::value >> typename BasicJsonType::string_t, Key >::value >>
void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m) inline void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
} }
m.clear(); m.clear();
for (const auto& p : j) for (const auto& p : j)
{ {
if (JSON_HEDLEY_UNLIKELY(!p.is_array())) if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()))); JSON_THROW(type_error::create(302, concat("type must be array, but is ", p.type_name()), &j));
} }
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>()); m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
} }
} }
#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
template<typename BasicJsonType>
inline void from_json(const BasicJsonType& j, std_fs::path& p)
{
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
{
JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
}
p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
}
#endif
struct from_json_fn struct from_json_fn
{ {
template<typename BasicJsonType, typename T> template<typename BasicJsonType, typename T>
auto operator()(const BasicJsonType& j, T& val) const auto operator()(const BasicJsonType& j, T&& val) const
noexcept(noexcept(from_json(j, val))) noexcept(noexcept(from_json(j, std::forward<T>(val))))
-> decltype(from_json(j, val), void()) -> decltype(from_json(j, std::forward<T>(val)))
{ {
return from_json(j, val); return from_json(j, std::forward<T>(val));
} }
}; };
} // namespace detail } // namespace detail
#ifndef JSON_HAS_CPP_17
/// namespace to hold default `from_json` function /// namespace to hold default `from_json` function
/// to see why this is required: /// to see why this is required:
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html /// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
namespace namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces)
{ {
constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value; #endif
} // namespace JSON_INLINE_VARIABLE constexpr const auto& from_json = // NOLINT(misc-definitions-in-headers)
} // namespace nlohmann detail::static_const<detail::from_json_fn>::value;
#ifndef JSON_HAS_CPP_17
} // namespace
#endif
NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,3 +1,12 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2009 Florian Loitsch <https://florian.loitsch.com/>
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <array> // array #include <array> // array
@ -9,8 +18,7 @@
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
@ -200,7 +208,7 @@ boundaries compute_boundaries(FloatType value)
using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type; using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
const std::uint64_t bits = reinterpret_bits<bits_type>(value); const auto bits = static_cast<std::uint64_t>(reinterpret_bits<bits_type>(value));
const std::uint64_t E = bits >> (kPrecision - 1); const std::uint64_t E = bits >> (kPrecision - 1);
const std::uint64_t F = bits & (kHiddenBit - 1); const std::uint64_t F = bits & (kHiddenBit - 1);
@ -490,51 +498,49 @@ inline int find_largest_pow10(const std::uint32_t n, std::uint32_t& pow10)
return 10; return 10;
} }
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
else if (n >= 100000000) if (n >= 100000000)
{ {
pow10 = 100000000; pow10 = 100000000;
return 9; return 9;
} }
else if (n >= 10000000) if (n >= 10000000)
{ {
pow10 = 10000000; pow10 = 10000000;
return 8; return 8;
} }
else if (n >= 1000000) if (n >= 1000000)
{ {
pow10 = 1000000; pow10 = 1000000;
return 7; return 7;
} }
else if (n >= 100000) if (n >= 100000)
{ {
pow10 = 100000; pow10 = 100000;
return 6; return 6;
} }
else if (n >= 10000) if (n >= 10000)
{ {
pow10 = 10000; pow10 = 10000;
return 5; return 5;
} }
else if (n >= 1000) if (n >= 1000)
{ {
pow10 = 1000; pow10 = 1000;
return 4; return 4;
} }
else if (n >= 100) if (n >= 100)
{ {
pow10 = 100; pow10 = 100;
return 3; return 3;
} }
else if (n >= 10) if (n >= 10)
{ {
pow10 = 10; pow10 = 10;
return 2; return 2;
} }
else
{ pow10 = 1;
pow10 = 1; return 1;
return 1;
}
} }
inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta, inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta,
@ -620,7 +626,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent,
JSON_ASSERT(p1 > 0); JSON_ASSERT(p1 > 0);
std::uint32_t pow10; std::uint32_t pow10{};
const int k = find_largest_pow10(p1, pow10); const int k = find_largest_pow10(p1, pow10);
// 10^(k-1) <= p1 < 10^k, pow10 = 10^(k-1) // 10^(k-1) <= p1 < 10^k, pow10 = 10^(k-1)
@ -893,7 +899,7 @@ void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value)
// //
// The documentation for 'std::to_chars' (https://en.cppreference.com/w/cpp/utility/to_chars) // The documentation for 'std::to_chars' (https://en.cppreference.com/w/cpp/utility/to_chars)
// says "value is converted to a string as if by std::sprintf in the default ("C") locale" // says "value is converted to a string as if by std::sprintf in the default ("C") locale"
// and since sprintf promotes float's to double's, I think this is exactly what 'std::to_chars' // and since sprintf promotes floats to doubles, I think this is exactly what 'std::to_chars'
// does. // does.
// On the other hand, the documentation for 'std::to_chars' requires that "parsing the // On the other hand, the documentation for 'std::to_chars' requires that "parsing the
// representation using the corresponding std::from_chars function recovers value exactly". That // representation using the corresponding std::from_chars function recovers value exactly". That
@ -1041,7 +1047,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent,
return append_exponent(buf, n - 1); return append_exponent(buf, n - 1);
} }
} // namespace dtoa_impl } // namespace dtoa_impl
/*! /*!
@brief generates a decimal representation of the floating-point number value in [first, last). @brief generates a decimal representation of the floating-point number value in [first, last).
@ -1068,6 +1074,10 @@ char* to_chars(char* first, const char* last, FloatType value)
*first++ = '-'; *first++ = '-';
} }
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if (value == 0) // +-0 if (value == 0) // +-0
{ {
*first++ = '0'; *first++ = '0';
@ -1076,6 +1086,9 @@ char* to_chars(char* first, const char* last, FloatType value)
*first++ = '0'; *first++ = '0';
return first; return first;
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10); JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
@ -1101,5 +1114,5 @@ char* to_chars(char* first, const char* last, FloatType value)
return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp); return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
} }
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,3 +1,11 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <algorithm> // copy #include <algorithm> // copy
@ -10,18 +18,27 @@
#include <vector> // vector #include <vector> // vector
#include <nlohmann/detail/iterators/iteration_proxy.hpp> #include <nlohmann/detail/iterators/iteration_proxy.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp> #include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/std_fs.hpp>
#include <nlohmann/detail/meta/type_traits.hpp> #include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp> #include <nlohmann/detail/value_t.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
////////////////// //////////////////
// constructors // // constructors //
////////////////// //////////////////
/*
* Note all external_constructor<>::construct functions need to call
* j.m_value.destroy(j.m_type) to avoid a memory leak in case j contains an
* allocated value (e.g., a string). See bug issue
* https://github.com/nlohmann/json/issues/2865 for more information.
*/
template<value_t> struct external_constructor; template<value_t> struct external_constructor;
template<> template<>
@ -30,6 +47,7 @@ struct external_constructor<value_t::boolean>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::boolean; j.m_type = value_t::boolean;
j.m_value = b; j.m_value = b;
j.assert_invariant(); j.assert_invariant();
@ -42,6 +60,7 @@ struct external_constructor<value_t::string>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s) static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value = s; j.m_value = s;
j.assert_invariant(); j.assert_invariant();
@ -50,6 +69,7 @@ struct external_constructor<value_t::string>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s) static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value = std::move(s); j.m_value = std::move(s);
j.assert_invariant(); j.assert_invariant();
@ -60,6 +80,7 @@ struct external_constructor<value_t::string>
int > = 0 > int > = 0 >
static void construct(BasicJsonType& j, const CompatibleStringType& str) static void construct(BasicJsonType& j, const CompatibleStringType& str)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value.string = j.template create<typename BasicJsonType::string_t>(str); j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
j.assert_invariant(); j.assert_invariant();
@ -72,18 +93,18 @@ struct external_constructor<value_t::binary>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b) static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::binary; j.m_type = value_t::binary;
typename BasicJsonType::binary_t value{b}; j.m_value = typename BasicJsonType::binary_t(b);
j.m_value = value;
j.assert_invariant(); j.assert_invariant();
} }
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b) static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::binary; j.m_type = value_t::binary;
typename BasicJsonType::binary_t value{std::move(b)}; j.m_value = typename BasicJsonType::binary_t(std::move(b));
j.m_value = value;
j.assert_invariant(); j.assert_invariant();
} }
}; };
@ -94,6 +115,7 @@ struct external_constructor<value_t::number_float>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::number_float; j.m_type = value_t::number_float;
j.m_value = val; j.m_value = val;
j.assert_invariant(); j.assert_invariant();
@ -106,6 +128,7 @@ struct external_constructor<value_t::number_unsigned>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::number_unsigned; j.m_type = value_t::number_unsigned;
j.m_value = val; j.m_value = val;
j.assert_invariant(); j.assert_invariant();
@ -118,6 +141,7 @@ struct external_constructor<value_t::number_integer>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::number_integer; j.m_type = value_t::number_integer;
j.m_value = val; j.m_value = val;
j.assert_invariant(); j.assert_invariant();
@ -130,16 +154,20 @@ struct external_constructor<value_t::array>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr) static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = arr; j.m_value = arr;
j.set_parents();
j.assert_invariant(); j.assert_invariant();
} }
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr) static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = std::move(arr); j.m_value = std::move(arr);
j.set_parents();
j.assert_invariant(); j.assert_invariant();
} }
@ -150,20 +178,25 @@ struct external_constructor<value_t::array>
{ {
using std::begin; using std::begin;
using std::end; using std::end;
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr)); j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
j.set_parents();
j.assert_invariant(); j.assert_invariant();
} }
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const std::vector<bool>& arr) static void construct(BasicJsonType& j, const std::vector<bool>& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = value_t::array; j.m_value = value_t::array;
j.m_value.array->reserve(arr.size()); j.m_value.array->reserve(arr.size());
for (const bool x : arr) for (const bool x : arr)
{ {
j.m_value.array->push_back(x); j.m_value.array->push_back(x);
j.set_parent(j.m_value.array->back());
} }
j.assert_invariant(); j.assert_invariant();
} }
@ -172,6 +205,7 @@ struct external_constructor<value_t::array>
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
static void construct(BasicJsonType& j, const std::valarray<T>& arr) static void construct(BasicJsonType& j, const std::valarray<T>& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = value_t::array; j.m_value = value_t::array;
j.m_value.array->resize(arr.size()); j.m_value.array->resize(arr.size());
@ -179,6 +213,7 @@ struct external_constructor<value_t::array>
{ {
std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin()); std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
} }
j.set_parents();
j.assert_invariant(); j.assert_invariant();
} }
}; };
@ -189,16 +224,20 @@ struct external_constructor<value_t::object>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj) static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value = obj; j.m_value = obj;
j.set_parents();
j.assert_invariant(); j.assert_invariant();
} }
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj) static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value = std::move(obj); j.m_value = std::move(obj);
j.set_parents();
j.assert_invariant(); j.assert_invariant();
} }
@ -209,8 +248,10 @@ struct external_constructor<value_t::object>
using std::begin; using std::begin;
using std::end; using std::end;
j.m_value.destroy(j.m_type);
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj)); j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
j.set_parents();
j.assert_invariant(); j.assert_invariant();
} }
}; };
@ -221,55 +262,70 @@ struct external_constructor<value_t::object>
template<typename BasicJsonType, typename T, template<typename BasicJsonType, typename T,
enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0> enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0>
void to_json(BasicJsonType& j, T b) noexcept inline void to_json(BasicJsonType& j, T b) noexcept
{ {
external_constructor<value_t::boolean>::construct(j, b); external_constructor<value_t::boolean>::construct(j, b);
} }
template < typename BasicJsonType, typename BoolRef,
enable_if_t <
((std::is_same<std::vector<bool>::reference, BoolRef>::value
&& !std::is_same <std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value)
|| (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
&& !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,
typename BasicJsonType::boolean_t >::value))
&& std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int > = 0 >
inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept
{
external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b));
}
template<typename BasicJsonType, typename CompatibleString, template<typename BasicJsonType, typename CompatibleString,
enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0> enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
void to_json(BasicJsonType& j, const CompatibleString& s) inline void to_json(BasicJsonType& j, const CompatibleString& s)
{ {
external_constructor<value_t::string>::construct(j, s); external_constructor<value_t::string>::construct(j, s);
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s) inline void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s)
{ {
external_constructor<value_t::string>::construct(j, std::move(s)); external_constructor<value_t::string>::construct(j, std::move(s));
} }
template<typename BasicJsonType, typename FloatType, template<typename BasicJsonType, typename FloatType,
enable_if_t<std::is_floating_point<FloatType>::value, int> = 0> enable_if_t<std::is_floating_point<FloatType>::value, int> = 0>
void to_json(BasicJsonType& j, FloatType val) noexcept inline void to_json(BasicJsonType& j, FloatType val) noexcept
{ {
external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val)); external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val));
} }
template<typename BasicJsonType, typename CompatibleNumberUnsignedType, template<typename BasicJsonType, typename CompatibleNumberUnsignedType,
enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0> enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0>
void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
{ {
external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val)); external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val));
} }
template<typename BasicJsonType, typename CompatibleNumberIntegerType, template<typename BasicJsonType, typename CompatibleNumberIntegerType,
enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0> enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0>
void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
{ {
external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val)); external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val));
} }
#if !JSON_DISABLE_ENUM_SERIALIZATION
template<typename BasicJsonType, typename EnumType, template<typename BasicJsonType, typename EnumType,
enable_if_t<std::is_enum<EnumType>::value, int> = 0> enable_if_t<std::is_enum<EnumType>::value, int> = 0>
void to_json(BasicJsonType& j, EnumType e) noexcept inline void to_json(BasicJsonType& j, EnumType e) noexcept
{ {
using underlying_type = typename std::underlying_type<EnumType>::type; using underlying_type = typename std::underlying_type<EnumType>::type;
external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e)); external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e));
} }
#endif // JSON_DISABLE_ENUM_SERIALIZATION
template<typename BasicJsonType> template<typename BasicJsonType>
void to_json(BasicJsonType& j, const std::vector<bool>& e) inline void to_json(BasicJsonType& j, const std::vector<bool>& e)
{ {
external_constructor<value_t::array>::construct(j, e); external_constructor<value_t::array>::construct(j, e);
} }
@ -282,39 +338,39 @@ template < typename BasicJsonType, typename CompatibleArrayType,
!std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&& !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
!is_basic_json<CompatibleArrayType>::value, !is_basic_json<CompatibleArrayType>::value,
int > = 0 > int > = 0 >
void to_json(BasicJsonType& j, const CompatibleArrayType& arr) inline void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
{ {
external_constructor<value_t::array>::construct(j, arr); external_constructor<value_t::array>::construct(j, arr);
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin) inline void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin)
{ {
external_constructor<value_t::binary>::construct(j, bin); external_constructor<value_t::binary>::construct(j, bin);
} }
template<typename BasicJsonType, typename T, template<typename BasicJsonType, typename T,
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
void to_json(BasicJsonType& j, const std::valarray<T>& arr) inline void to_json(BasicJsonType& j, const std::valarray<T>& arr)
{ {
external_constructor<value_t::array>::construct(j, std::move(arr)); external_constructor<value_t::array>::construct(j, std::move(arr));
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr) inline void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
{ {
external_constructor<value_t::array>::construct(j, std::move(arr)); external_constructor<value_t::array>::construct(j, std::move(arr));
} }
template < typename BasicJsonType, typename CompatibleObjectType, template < typename BasicJsonType, typename CompatibleObjectType,
enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value, int > = 0 > enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value, int > = 0 >
void to_json(BasicJsonType& j, const CompatibleObjectType& obj) inline void to_json(BasicJsonType& j, const CompatibleObjectType& obj)
{ {
external_constructor<value_t::object>::construct(j, obj); external_constructor<value_t::object>::construct(j, obj);
} }
template<typename BasicJsonType> template<typename BasicJsonType>
void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj) inline void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
{ {
external_constructor<value_t::object>::construct(j, std::move(obj)); external_constructor<value_t::object>::construct(j, std::move(obj));
} }
@ -322,15 +378,15 @@ void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
template < template <
typename BasicJsonType, typename T, std::size_t N, typename BasicJsonType, typename T, std::size_t N,
enable_if_t < !std::is_constructible<typename BasicJsonType::string_t, enable_if_t < !std::is_constructible<typename BasicJsonType::string_t,
const T(&)[N]>::value, const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
int > = 0 > int > = 0 >
void to_json(BasicJsonType& j, const T(&arr)[N]) inline void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
{ {
external_constructor<value_t::array>::construct(j, arr); external_constructor<value_t::array>::construct(j, arr);
} }
template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value, int > = 0 > template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value, int > = 0 >
void to_json(BasicJsonType& j, const std::pair<T1, T2>& p) inline void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
{ {
j = { p.first, p.second }; j = { p.first, p.second };
} }
@ -338,23 +394,31 @@ void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
// for https://github.com/nlohmann/json/pull/1134 // for https://github.com/nlohmann/json/pull/1134
template<typename BasicJsonType, typename T, template<typename BasicJsonType, typename T,
enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0> enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
void to_json(BasicJsonType& j, const T& b) inline void to_json(BasicJsonType& j, const T& b)
{ {
j = { {b.key(), b.value()} }; j = { {b.key(), b.value()} };
} }
template<typename BasicJsonType, typename Tuple, std::size_t... Idx> template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/) inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
{ {
j = { std::get<Idx>(t)... }; j = { std::get<Idx>(t)... };
} }
template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int > = 0> template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int > = 0>
void to_json(BasicJsonType& j, const T& t) inline void to_json(BasicJsonType& j, const T& t)
{ {
to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {}); to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
} }
#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
template<typename BasicJsonType>
inline void to_json(BasicJsonType& j, const std_fs::path& p)
{
j = p.string();
}
#endif
struct to_json_fn struct to_json_fn
{ {
template<typename BasicJsonType, typename T> template<typename BasicJsonType, typename T>
@ -366,9 +430,17 @@ struct to_json_fn
}; };
} // namespace detail } // namespace detail
#ifndef JSON_HAS_CPP_17
/// namespace to hold default `to_json` function /// namespace to hold default `to_json` function
namespace /// to see why this is required:
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces)
{ {
constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value; #endif
} // namespace JSON_INLINE_VARIABLE constexpr const auto& to_json = // NOLINT(misc-definitions-in-headers)
} // namespace nlohmann detail::static_const<detail::to_json_fn>::value;
#ifndef JSON_HAS_CPP_17
} // namespace
#endif
NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,68 +1,127 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <cstddef> // nullptr_t
#include <exception> // exception #include <exception> // exception
#include <stdexcept> // runtime_error #include <stdexcept> // runtime_error
#include <string> // to_string #include <string> // to_string
#include <vector> // vector
#include <nlohmann/detail/value_t.hpp>
#include <nlohmann/detail/string_escape.hpp>
#include <nlohmann/detail/input/position_t.hpp> #include <nlohmann/detail/input/position_t.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/string_concat.hpp>
namespace nlohmann
{ NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail namespace detail
{ {
//////////////// ////////////////
// exceptions // // exceptions //
//////////////// ////////////////
/*! /// @brief general exception of the @ref basic_json class
@brief general exception of the @ref basic_json class /// @sa https://json.nlohmann.me/api/basic_json/exception/
This class is an extension of `std::exception` objects with a member @a id for
exception ids. It is used as the base class for all exceptions thrown by the
@ref basic_json class. This class can hence be used as "wildcard" to catch
exceptions.
Subclasses:
- @ref parse_error for exceptions indicating a parse error
- @ref invalid_iterator for exceptions indicating errors with iterators
- @ref type_error for exceptions indicating executing a member function with
a wrong type
- @ref out_of_range for exceptions indicating access out of the defined range
- @ref other_error for exceptions indicating other library errors
@internal
@note To have nothrow-copy-constructible exceptions, we internally use
`std::runtime_error` which can cope with arbitrary-length error messages.
Intermediate strings are built with static functions and then passed to
the actual constructor.
@endinternal
@liveexample{The following code shows how arbitrary library exceptions can be
caught.,exception}
@since version 3.0.0
*/
class exception : public std::exception class exception : public std::exception
{ {
public: public:
/// returns the explanatory string /// returns the explanatory string
JSON_HEDLEY_RETURNS_NON_NULL
const char* what() const noexcept override const char* what() const noexcept override
{ {
return m.what(); return m.what();
} }
/// the id of the exception /// the id of the exception
const int id; const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
protected: protected:
JSON_HEDLEY_NON_NULL(3) JSON_HEDLEY_NON_NULL(3)
exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} // NOLINT(bugprone-throw-keyword-missing)
static std::string name(const std::string& ename, int id_) static std::string name(const std::string& ename, int id_)
{ {
return "[json.exception." + ename + "." + std::to_string(id_) + "] "; return concat("[json.exception.", ename, '.', std::to_string(id_), "] ");
}
static std::string diagnostics(std::nullptr_t /*leaf_element*/)
{
return "";
}
template<typename BasicJsonType>
static std::string diagnostics(const BasicJsonType* leaf_element)
{
#if JSON_DIAGNOSTICS
std::vector<std::string> tokens;
for (const auto* current = leaf_element; current != nullptr && current->m_parent != nullptr; current = current->m_parent)
{
switch (current->m_parent->type())
{
case value_t::array:
{
for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
{
if (&current->m_parent->m_value.array->operator[](i) == current)
{
tokens.emplace_back(std::to_string(i));
break;
}
}
break;
}
case value_t::object:
{
for (const auto& element : *current->m_parent->m_value.object)
{
if (&element.second == current)
{
tokens.emplace_back(element.first.c_str());
break;
}
}
break;
}
case value_t::null: // LCOV_EXCL_LINE
case value_t::string: // LCOV_EXCL_LINE
case value_t::boolean: // LCOV_EXCL_LINE
case value_t::number_integer: // LCOV_EXCL_LINE
case value_t::number_unsigned: // LCOV_EXCL_LINE
case value_t::number_float: // LCOV_EXCL_LINE
case value_t::binary: // LCOV_EXCL_LINE
case value_t::discarded: // LCOV_EXCL_LINE
default: // LCOV_EXCL_LINE
break; // LCOV_EXCL_LINE
}
}
if (tokens.empty())
{
return "";
}
auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
[](const std::string & a, const std::string & b)
{
return concat(a, '/', detail::escape(b));
});
return concat('(', str, ") ");
#else
static_cast<void>(leaf_element);
return "";
#endif
} }
private: private:
@ -70,51 +129,8 @@ class exception : public std::exception
std::runtime_error m; std::runtime_error m;
}; };
/*! /// @brief exception indicating a parse error
@brief exception indicating a parse error /// @sa https://json.nlohmann.me/api/basic_json/parse_error/
This exception is thrown by the library when a parse error occurs. Parse errors
can occur during the deserialization of JSON text, CBOR, MessagePack, as well
as when using JSON Patch.
Member @a byte holds the byte index of the last read character in the input
file.
Exceptions have ids 1xx.
name / id | example message | description
------------------------------ | --------------- | -------------------------
json.exception.parse_error.101 | parse error at 2: unexpected end of input; expected string literal | This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member @a byte indicates the error position.
json.exception.parse_error.102 | parse error at 14: missing or wrong low surrogate | JSON uses the `\uxxxx` format to describe Unicode characters. Code points above above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point.
json.exception.parse_error.103 | parse error: code points above 0x10FFFF are invalid | Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid.
json.exception.parse_error.104 | parse error: JSON patch must be an array of objects | [RFC 6902](https://tools.ietf.org/html/rfc6902) requires a JSON Patch document to be a JSON document that represents an array of objects.
json.exception.parse_error.105 | parse error: operation must have string member 'op' | An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors.
json.exception.parse_error.106 | parse error: array index '01' must not begin with '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) may be `0` or any number without a leading `0`.
json.exception.parse_error.107 | parse error: JSON pointer must be empty or begin with '/' - was: 'foo' | A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a `/` character.
json.exception.parse_error.108 | parse error: escape character '~' must be followed with '0' or '1' | In a JSON Pointer, only `~0` and `~1` are valid escape sequences.
json.exception.parse_error.109 | parse error: array index 'one' is not a number | A JSON Pointer array index must be a number.
json.exception.parse_error.110 | parse error at 1: cannot read 2 bytes from vector | When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read.
json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte: 0xF8 | Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read.
json.exception.parse_error.113 | parse error at 2: expected a CBOR string; last byte: 0x98 | While parsing a map key, a value that is not a string has been read.
json.exception.parse_error.114 | parse error: Unsupported BSON record type 0x0F | The parsing of the corresponding BSON record type is not implemented (yet).
json.exception.parse_error.115 | parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A | A UBJSON high-precision number could not be parsed.
@note For an input with n bytes, 1 is the index of the first character and n+1
is the index of the terminating null byte or the end of file. This also
holds true when reading a byte vector (CBOR or MessagePack).
@liveexample{The following code shows how a `parse_error` exception can be
caught.,parse_error}
@sa - @ref exception for the base class of the library exceptions
@sa - @ref invalid_iterator for exceptions indicating errors with iterators
@sa - @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa - @ref out_of_range for exceptions indicating access out of the defined range
@sa - @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class parse_error : public exception class parse_error : public exception
{ {
public: public:
@ -127,19 +143,21 @@ class parse_error : public exception
@param[in] what_arg the explanatory string @param[in] what_arg the explanatory string
@return parse_error object @return parse_error object
*/ */
static parse_error create(int id_, const position_t& pos, const std::string& what_arg) template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context)
{ {
std::string w = exception::name("parse_error", id_) + "parse error" + std::string w = concat(exception::name("parse_error", id_), "parse error",
position_string(pos) + ": " + what_arg; position_string(pos), ": ", exception::diagnostics(context), what_arg);
return parse_error(id_, pos.chars_read_total, w.c_str()); return {id_, pos.chars_read_total, w.c_str()};
} }
static parse_error create(int id_, std::size_t byte_, const std::string& what_arg) template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context)
{ {
std::string w = exception::name("parse_error", id_) + "parse error" + std::string w = concat(exception::name("parse_error", id_), "parse error",
(byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""),
": " + what_arg; ": ", exception::diagnostics(context), what_arg);
return parse_error(id_, byte_, w.c_str()); return {id_, byte_, w.c_str()};
} }
/*! /*!
@ -159,55 +177,21 @@ class parse_error : public exception
static std::string position_string(const position_t& pos) static std::string position_string(const position_t& pos)
{ {
return " at line " + std::to_string(pos.lines_read + 1) + return concat(" at line ", std::to_string(pos.lines_read + 1),
", column " + std::to_string(pos.chars_read_current_line); ", column ", std::to_string(pos.chars_read_current_line));
} }
}; };
/*! /// @brief exception indicating errors with iterators
@brief exception indicating errors with iterators /// @sa https://json.nlohmann.me/api/basic_json/invalid_iterator/
This exception is thrown if iterators passed to a library function do not match
the expected semantics.
Exceptions have ids 2xx.
name / id | example message | description
----------------------------------- | --------------- | -------------------------
json.exception.invalid_iterator.201 | iterators are not compatible | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid.
json.exception.invalid_iterator.202 | iterator does not fit current value | In an erase or insert function, the passed iterator @a pos does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion.
json.exception.invalid_iterator.203 | iterators do not fit current value | Either iterator passed to function @ref erase(IteratorType first, IteratorType last) does not belong to the JSON value from which values shall be erased. It hence does not define a valid range to delete values from.
json.exception.invalid_iterator.204 | iterators out of range | When an iterator range for a primitive type (number, boolean, or string) is passed to a constructor or an erase function, this range has to be exactly (@ref begin(), @ref end()), because this is the only way the single stored value is expressed. All other ranges are invalid.
json.exception.invalid_iterator.205 | iterator out of range | When an iterator for a primitive type (number, boolean, or string) is passed to an erase function, the iterator has to be the @ref begin() iterator, because it is the only way to address the stored value. All other iterators are invalid.
json.exception.invalid_iterator.206 | cannot construct with iterators from null | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) belong to a JSON null value and hence to not define a valid range.
json.exception.invalid_iterator.207 | cannot use key() for non-object iterators | The key() member function can only be used on iterators belonging to a JSON object, because other types do not have a concept of a key.
json.exception.invalid_iterator.208 | cannot use operator[] for object iterators | The operator[] to specify a concrete offset cannot be used on iterators belonging to a JSON object, because JSON objects are unordered.
json.exception.invalid_iterator.209 | cannot use offsets with object iterators | The offset operators (+, -, +=, -=) cannot be used on iterators belonging to a JSON object, because JSON objects are unordered.
json.exception.invalid_iterator.210 | iterators do not fit | The iterator range passed to the insert function are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid.
json.exception.invalid_iterator.211 | passed iterators may not belong to container | The iterator range passed to the insert function must not be a subrange of the container to insert to.
json.exception.invalid_iterator.212 | cannot compare iterators of different containers | When two iterators are compared, they must belong to the same container.
json.exception.invalid_iterator.213 | cannot compare order of object iterators | The order of object iterators cannot be compared, because JSON objects are unordered.
json.exception.invalid_iterator.214 | cannot get value | Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to @ref begin().
@liveexample{The following code shows how an `invalid_iterator` exception can be
caught.,invalid_iterator}
@sa - @ref exception for the base class of the library exceptions
@sa - @ref parse_error for exceptions indicating a parse error
@sa - @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa - @ref out_of_range for exceptions indicating access out of the defined range
@sa - @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class invalid_iterator : public exception class invalid_iterator : public exception
{ {
public: public:
static invalid_iterator create(int id_, const std::string& what_arg) template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context)
{ {
std::string w = exception::name("invalid_iterator", id_) + what_arg; std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg);
return invalid_iterator(id_, w.c_str()); return {id_, w.c_str()};
} }
private: private:
@ -216,52 +200,16 @@ class invalid_iterator : public exception
: exception(id_, what_arg) {} : exception(id_, what_arg) {}
}; };
/*! /// @brief exception indicating executing a member function with a wrong type
@brief exception indicating executing a member function with a wrong type /// @sa https://json.nlohmann.me/api/basic_json/type_error/
This exception is thrown in case of a type error; that is, a library function is
executed on a JSON value whose type does not match the expected semantics.
Exceptions have ids 3xx.
name / id | example message | description
----------------------------- | --------------- | -------------------------
json.exception.type_error.301 | cannot create object from initializer list | To create an object from an initializer list, the initializer list must consist only of a list of pairs whose first element is a string. When this constraint is violated, an array is created instead.
json.exception.type_error.302 | type must be object, but is array | During implicit or explicit value conversion, the JSON type must be compatible to the target type. For instance, a JSON string can only be converted into string types, but not into numbers or boolean types.
json.exception.type_error.303 | incompatible ReferenceType for get_ref, actual type is object | To retrieve a reference to a value stored in a @ref basic_json object with @ref get_ref, the type of the reference must match the value type. For instance, for a JSON array, the @a ReferenceType must be @ref array_t &.
json.exception.type_error.304 | cannot use at() with string | The @ref at() member functions can only be executed for certain JSON types.
json.exception.type_error.305 | cannot use operator[] with string | The @ref operator[] member functions can only be executed for certain JSON types.
json.exception.type_error.306 | cannot use value() with string | The @ref value() member functions can only be executed for certain JSON types.
json.exception.type_error.307 | cannot use erase() with string | The @ref erase() member functions can only be executed for certain JSON types.
json.exception.type_error.308 | cannot use push_back() with string | The @ref push_back() and @ref operator+= member functions can only be executed for certain JSON types.
json.exception.type_error.309 | cannot use insert() with | The @ref insert() member functions can only be executed for certain JSON types.
json.exception.type_error.310 | cannot use swap() with number | The @ref swap() member functions can only be executed for certain JSON types.
json.exception.type_error.311 | cannot use emplace_back() with string | The @ref emplace_back() member function can only be executed for certain JSON types.
json.exception.type_error.312 | cannot use update() with string | The @ref update() member functions can only be executed for certain JSON types.
json.exception.type_error.313 | invalid value to unflatten | The @ref unflatten function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well defined.
json.exception.type_error.314 | only objects can be unflattened | The @ref unflatten function only works for an object whose keys are JSON Pointers.
json.exception.type_error.315 | values in object must be primitive | The @ref unflatten function only works for an object whose keys are JSON Pointers and whose values are primitive.
json.exception.type_error.316 | invalid UTF-8 byte at index 10: 0x7E | The @ref dump function only works with UTF-8 encoded strings; that is, if you assign a `std::string` to a JSON value, make sure it is UTF-8 encoded. |
json.exception.type_error.317 | JSON value cannot be serialized to requested format | The dynamic type of the object cannot be represented in the requested serialization format (e.g. a raw `true` or `null` JSON object cannot be serialized to BSON) |
@liveexample{The following code shows how a `type_error` exception can be
caught.,type_error}
@sa - @ref exception for the base class of the library exceptions
@sa - @ref parse_error for exceptions indicating a parse error
@sa - @ref invalid_iterator for exceptions indicating errors with iterators
@sa - @ref out_of_range for exceptions indicating access out of the defined range
@sa - @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class type_error : public exception class type_error : public exception
{ {
public: public:
static type_error create(int id_, const std::string& what_arg) template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
static type_error create(int id_, const std::string& what_arg, BasicJsonContext context)
{ {
std::string w = exception::name("type_error", id_) + what_arg; std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg);
return type_error(id_, w.c_str()); return {id_, w.c_str()};
} }
private: private:
@ -269,46 +217,16 @@ class type_error : public exception
type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} type_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
}; };
/*! /// @brief exception indicating access out of the defined range
@brief exception indicating access out of the defined range /// @sa https://json.nlohmann.me/api/basic_json/out_of_range/
This exception is thrown in case a library function is called on an input
parameter that exceeds the expected range, for instance in case of array
indices or nonexisting object keys.
Exceptions have ids 4xx.
name / id | example message | description
------------------------------- | --------------- | -------------------------
json.exception.out_of_range.401 | array index 3 is out of range | The provided array index @a i is larger than @a size-1.
json.exception.out_of_range.402 | array index '-' (3) is out of range | The special array index `-` in a JSON Pointer never describes a valid element of the array, but the index past the end. That is, it can only be used to add elements at this position, but not to read it.
json.exception.out_of_range.403 | key 'foo' not found | The provided key was not found in the JSON object.
json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference token in a JSON Pointer could not be resolved.
json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value.
json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed number could not be stored as without changing it to NaN or INF.
json.exception.out_of_range.407 | number overflow serializing '9223372036854775808' | UBJSON and BSON only support integer numbers up to 9223372036854775807. (until version 3.8.0) |
json.exception.out_of_range.408 | excessive array size: 8658170730974374167 | The size (following `#`) of an UBJSON array or object exceeds the maximal capacity. |
json.exception.out_of_range.409 | BSON key cannot contain code point U+0000 (at byte 2) | Key identifiers to be serialized to BSON cannot contain code point U+0000, since the key is stored as zero-terminated c-string |
@liveexample{The following code shows how an `out_of_range` exception can be
caught.,out_of_range}
@sa - @ref exception for the base class of the library exceptions
@sa - @ref parse_error for exceptions indicating a parse error
@sa - @ref invalid_iterator for exceptions indicating errors with iterators
@sa - @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa - @ref other_error for exceptions indicating other library errors
@since version 3.0.0
*/
class out_of_range : public exception class out_of_range : public exception
{ {
public: public:
static out_of_range create(int id_, const std::string& what_arg) template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context)
{ {
std::string w = exception::name("out_of_range", id_) + what_arg; std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg);
return out_of_range(id_, w.c_str()); return {id_, w.c_str()};
} }
private: private:
@ -316,42 +234,22 @@ class out_of_range : public exception
out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {}
}; };
/*! /// @brief exception indicating other library errors
@brief exception indicating other library errors /// @sa https://json.nlohmann.me/api/basic_json/other_error/
This exception is thrown in case of errors that cannot be classified with the
other exception types.
Exceptions have ids 5xx.
name / id | example message | description
------------------------------ | --------------- | -------------------------
json.exception.other_error.501 | unsuccessful: {"op":"test","path":"/baz", "value":"bar"} | A JSON Patch operation 'test' failed. The unsuccessful operation is also printed.
@sa - @ref exception for the base class of the library exceptions
@sa - @ref parse_error for exceptions indicating a parse error
@sa - @ref invalid_iterator for exceptions indicating errors with iterators
@sa - @ref type_error for exceptions indicating executing a member function with
a wrong type
@sa - @ref out_of_range for exceptions indicating access out of the defined range
@liveexample{The following code shows how an `other_error` exception can be
caught.,other_error}
@since version 3.0.0
*/
class other_error : public exception class other_error : public exception
{ {
public: public:
static other_error create(int id_, const std::string& what_arg) template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
static other_error create(int id_, const std::string& what_arg, BasicJsonContext context)
{ {
std::string w = exception::name("other_error", id_) + what_arg; std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg);
return other_error(id_, w.c_str()); return {id_, w.c_str()};
} }
private: private:
JSON_HEDLEY_NON_NULL(3) JSON_HEDLEY_NON_NULL(3)
other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,10 +1,21 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <cstddef> // size_t, uint8_t #include <cstdint> // uint8_t
#include <cstddef> // size_t
#include <functional> // hash #include <functional> // hash
namespace nlohmann #include <nlohmann/detail/abi_macros.hpp>
{ #include <nlohmann/detail/value_t.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail namespace detail
{ {
@ -83,24 +94,24 @@ std::size_t hash(const BasicJsonType& j)
return combine(type, h); return combine(type, h);
} }
case nlohmann::detail::value_t::number_unsigned: case BasicJsonType::value_t::number_unsigned:
{ {
const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>()); const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
return combine(type, h); return combine(type, h);
} }
case nlohmann::detail::value_t::number_float: case BasicJsonType::value_t::number_float:
{ {
const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>()); const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
return combine(type, h); return combine(type, h);
} }
case nlohmann::detail::value_t::binary: case BasicJsonType::value_t::binary:
{ {
auto seed = combine(type, j.get_binary().size()); auto seed = combine(type, j.get_binary().size());
const auto h = std::hash<bool> {}(j.get_binary().has_subtype()); const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
seed = combine(seed, h); seed = combine(seed, h);
seed = combine(seed, j.get_binary().subtype()); seed = combine(seed, static_cast<std::size_t>(j.get_binary().subtype()));
for (const auto byte : j.get_binary()) for (const auto byte : j.get_binary())
{ {
seed = combine(seed, std::hash<std::uint8_t> {}(byte)); seed = combine(seed, std::hash<std::uint8_t> {}(byte));
@ -108,10 +119,11 @@ std::size_t hash(const BasicJsonType& j)
return seed; return seed;
} }
default: // LCOV_EXCL_LINE default: // LCOV_EXCL_LINE
JSON_ASSERT(false); // LCOV_EXCL_LINE JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
return 0; // LCOV_EXCL_LINE
} }
} }
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,16 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <array> // array #include <array> // array
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdio> //FILE *
#include <cstring> // strlen #include <cstring> // strlen
#include <istream> // istream
#include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next #include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next
#include <memory> // shared_ptr, make_shared, addressof #include <memory> // shared_ptr, make_shared, addressof
#include <numeric> // accumulate #include <numeric> // accumulate
@ -12,20 +18,26 @@
#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer #include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer
#include <utility> // pair, declval #include <utility> // pair, declval
#ifndef JSON_NO_IO
#include <cstdio> // FILE *
#include <istream> // istream
#endif // JSON_NO_IO
#include <nlohmann/detail/iterators/iterator_traits.hpp> #include <nlohmann/detail/iterators/iterator_traits.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
/// the supported input formats /// the supported input formats
enum class input_format_t { json, cbor, msgpack, ubjson, bson }; enum class input_format_t { json, cbor, msgpack, ubjson, bson, bjdata };
//////////////////// ////////////////////
// input adapters // // input adapters //
//////////////////// ////////////////////
#ifndef JSON_NO_IO
/*! /*!
Input adapter for stdio file access. This adapter read only 1 byte and do not use any Input adapter for stdio file access. This adapter read only 1 byte and do not use any
buffer. This adapter is a very low level adapter. buffer. This adapter is a very low level adapter.
@ -38,13 +50,16 @@ class file_input_adapter
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
explicit file_input_adapter(std::FILE* f) noexcept explicit file_input_adapter(std::FILE* f) noexcept
: m_file(f) : m_file(f)
{} {
JSON_ASSERT(m_file != nullptr);
}
// make class move-only // make class move-only
file_input_adapter(const file_input_adapter&) = delete; file_input_adapter(const file_input_adapter&) = delete;
file_input_adapter(file_input_adapter&&) = default; file_input_adapter(file_input_adapter&&) noexcept = default;
file_input_adapter& operator=(const file_input_adapter&) = delete; file_input_adapter& operator=(const file_input_adapter&) = delete;
file_input_adapter& operator=(file_input_adapter&&) = delete; file_input_adapter& operator=(file_input_adapter&&) = delete;
~file_input_adapter() = default;
std::char_traits<char>::int_type get_character() noexcept std::char_traits<char>::int_type get_character() noexcept
{ {
@ -88,9 +103,10 @@ class input_stream_adapter
// delete because of pointer members // delete because of pointer members
input_stream_adapter(const input_stream_adapter&) = delete; input_stream_adapter(const input_stream_adapter&) = delete;
input_stream_adapter& operator=(input_stream_adapter&) = delete; input_stream_adapter& operator=(input_stream_adapter&) = delete;
input_stream_adapter& operator=(input_stream_adapter&& rhs) = delete; input_stream_adapter& operator=(input_stream_adapter&&) = delete;
input_stream_adapter(input_stream_adapter&& rhs) noexcept : is(rhs.is), sb(rhs.sb) input_stream_adapter(input_stream_adapter&& rhs) noexcept
: is(rhs.is), sb(rhs.sb)
{ {
rhs.is = nullptr; rhs.is = nullptr;
rhs.sb = nullptr; rhs.sb = nullptr;
@ -98,12 +114,12 @@ class input_stream_adapter
// std::istream/std::streambuf use std::char_traits<char>::to_int_type, to // std::istream/std::streambuf use std::char_traits<char>::to_int_type, to
// ensure that std::char_traits<char>::eof() and the character 0xFF do not // ensure that std::char_traits<char>::eof() and the character 0xFF do not
// end up as the same value, eg. 0xFFFFFFFF. // end up as the same value, e.g. 0xFFFFFFFF.
std::char_traits<char>::int_type get_character() std::char_traits<char>::int_type get_character()
{ {
auto res = sb->sbumpc(); auto res = sb->sbumpc();
// set eof manually, as we don't use the istream interface. // set eof manually, as we don't use the istream interface.
if (JSON_HEDLEY_UNLIKELY(res == EOF)) if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
{ {
is->clear(is->rdstate() | std::ios::eofbit); is->clear(is->rdstate() | std::ios::eofbit);
} }
@ -115,6 +131,7 @@ class input_stream_adapter
std::istream* is = nullptr; std::istream* is = nullptr;
std::streambuf* sb = nullptr; std::streambuf* sb = nullptr;
}; };
#endif // JSON_NO_IO
// General-purpose iterator-based adapter. It might not be as fast as // General-purpose iterator-based adapter. It might not be as fast as
// theoretically possible for some containers, but it is extremely versatile. // theoretically possible for some containers, but it is extremely versatile.
@ -125,7 +142,8 @@ class iterator_input_adapter
using char_type = typename std::iterator_traits<IteratorType>::value_type; using char_type = typename std::iterator_traits<IteratorType>::value_type;
iterator_input_adapter(IteratorType first, IteratorType last) iterator_input_adapter(IteratorType first, IteratorType last)
: current(std::move(first)), end(std::move(last)) {} : current(std::move(first)), end(std::move(last))
{}
typename std::char_traits<char_type>::int_type get_character() typename std::char_traits<char_type>::int_type get_character()
{ {
@ -135,10 +153,8 @@ class iterator_input_adapter
std::advance(current, 1); std::advance(current, 1);
return result; return result;
} }
else
{ return std::char_traits<char_type>::eof();
return std::char_traits<char_type>::eof();
}
} }
private: private:
@ -152,7 +168,6 @@ class iterator_input_adapter
{ {
return current == end; return current == end;
} }
}; };
@ -371,16 +386,39 @@ typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapte
} }
// Convenience shorthand from container to iterator // Convenience shorthand from container to iterator
template<typename ContainerType> // Enables ADL on begin(container) and end(container)
auto input_adapter(const ContainerType& container) -> decltype(input_adapter(begin(container), end(container))) // Encloses the using declarations in namespace for not to leak them to outside scope
{
// Enable ADL
using std::begin;
using std::end;
namespace container_input_adapter_factory_impl
{
using std::begin;
using std::end;
template<typename ContainerType, typename Enable = void>
struct container_input_adapter_factory {};
template<typename ContainerType>
struct container_input_adapter_factory< ContainerType,
void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
{
using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
static adapter_type create(const ContainerType& container)
{
return input_adapter(begin(container), end(container)); return input_adapter(begin(container), end(container));
} }
};
} // namespace container_input_adapter_factory_impl
template<typename ContainerType>
typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(const ContainerType& container)
{
return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
}
#ifndef JSON_NO_IO
// Special cases with fast paths // Special cases with fast paths
inline file_input_adapter input_adapter(std::FILE* file) inline file_input_adapter input_adapter(std::FILE* file)
{ {
@ -396,6 +434,7 @@ inline input_stream_adapter input_adapter(std::istream&& stream)
{ {
return input_stream_adapter(stream); return input_stream_adapter(stream);
} }
#endif // JSON_NO_IO
using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>())); using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
@ -415,13 +454,13 @@ contiguous_bytes_input_adapter input_adapter(CharT b)
} }
template<typename T, std::size_t N> template<typename T, std::size_t N>
auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
{ {
return input_adapter(array, array + N); return input_adapter(array, array + N);
} }
// This class only handles inputs of input_buffer_adapter type. // This class only handles inputs of input_buffer_adapter type.
// It's required so that expressions like {ptr, len} can be implicitely casted // It's required so that expressions like {ptr, len} can be implicitly cast
// to the correct adapter. // to the correct adapter.
class span_input_adapter class span_input_adapter
{ {
@ -444,11 +483,12 @@ class span_input_adapter
contiguous_bytes_input_adapter&& get() contiguous_bytes_input_adapter&& get()
{ {
return std::move(ia); return std::move(ia); // NOLINT(hicpp-move-const-arg,performance-move-const-arg)
} }
private: private:
contiguous_bytes_input_adapter ia; contiguous_bytes_input_adapter ia;
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,3 +1,11 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <cstddef> #include <cstddef>
@ -7,9 +15,9 @@
#include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/string_concat.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
/*! /*!
@brief SAX interface @brief SAX interface
@ -56,7 +64,7 @@ struct json_sax
virtual bool number_unsigned(number_unsigned_t val) = 0; virtual bool number_unsigned(number_unsigned_t val) = 0;
/*! /*!
@brief an floating-point number was read @brief a floating-point number was read
@param[in] val floating-point value @param[in] val floating-point value
@param[in] s raw token value @param[in] s raw token value
@return whether parsing should proceed @return whether parsing should proceed
@ -64,18 +72,18 @@ struct json_sax
virtual bool number_float(number_float_t val, const string_t& s) = 0; virtual bool number_float(number_float_t val, const string_t& s) = 0;
/*! /*!
@brief a string was read @brief a string value was read
@param[in] val string value @param[in] val string value
@return whether parsing should proceed @return whether parsing should proceed
@note It is safe to move the passed string. @note It is safe to move the passed string value.
*/ */
virtual bool string(string_t& val) = 0; virtual bool string(string_t& val) = 0;
/*! /*!
@brief a binary string was read @brief a binary value was read
@param[in] val binary value @param[in] val binary value
@return whether parsing should proceed @return whether parsing should proceed
@note It is safe to move the passed binary. @note It is safe to move the passed binary value.
*/ */
virtual bool binary(binary_t& val) = 0; virtual bool binary(binary_t& val) = 0;
@ -126,6 +134,11 @@ struct json_sax
const std::string& last_token, const std::string& last_token,
const detail::exception& ex) = 0; const detail::exception& ex) = 0;
json_sax() = default;
json_sax(const json_sax&) = default;
json_sax(json_sax&&) noexcept = default;
json_sax& operator=(const json_sax&) = default;
json_sax& operator=(json_sax&&) noexcept = default;
virtual ~json_sax() = default; virtual ~json_sax() = default;
}; };
@ -156,7 +169,7 @@ class json_sax_dom_parser
using binary_t = typename BasicJsonType::binary_t; using binary_t = typename BasicJsonType::binary_t;
/*! /*!
@param[in, out] r reference to a JSON value that is manipulated while @param[in,out] r reference to a JSON value that is manipulated while
parsing parsing
@param[in] allow_exceptions_ whether parse errors yield exceptions @param[in] allow_exceptions_ whether parse errors yield exceptions
*/ */
@ -166,9 +179,9 @@ class json_sax_dom_parser
// make class move-only // make class move-only
json_sax_dom_parser(const json_sax_dom_parser&) = delete; json_sax_dom_parser(const json_sax_dom_parser&) = delete;
json_sax_dom_parser(json_sax_dom_parser&&) = default; json_sax_dom_parser(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete; json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete;
json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
~json_sax_dom_parser() = default; ~json_sax_dom_parser() = default;
bool null() bool null()
@ -217,10 +230,9 @@ class json_sax_dom_parser
{ {
ref_stack.push_back(handle_value(BasicJsonType::value_t::object)); ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, JSON_THROW(out_of_range::create(408, concat("excessive object size: ", std::to_string(len)), ref_stack.back()));
"excessive object size: " + std::to_string(len)));
} }
return true; return true;
@ -228,6 +240,9 @@ class json_sax_dom_parser
bool key(string_t& val) bool key(string_t& val)
{ {
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_object());
// add null at given key and store the reference for later // add null at given key and store the reference for later
object_element = &(ref_stack.back()->m_value.object->operator[](val)); object_element = &(ref_stack.back()->m_value.object->operator[](val));
return true; return true;
@ -235,6 +250,10 @@ class json_sax_dom_parser
bool end_object() bool end_object()
{ {
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_object());
ref_stack.back()->set_parents();
ref_stack.pop_back(); ref_stack.pop_back();
return true; return true;
} }
@ -243,10 +262,9 @@ class json_sax_dom_parser
{ {
ref_stack.push_back(handle_value(BasicJsonType::value_t::array)); ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, JSON_THROW(out_of_range::create(408, concat("excessive array size: ", std::to_string(len)), ref_stack.back()));
"excessive array size: " + std::to_string(len)));
} }
return true; return true;
@ -254,6 +272,10 @@ class json_sax_dom_parser
bool end_array() bool end_array()
{ {
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_array());
ref_stack.back()->set_parents();
ref_stack.pop_back(); ref_stack.pop_back();
return true; return true;
} }
@ -341,9 +363,9 @@ class json_sax_dom_callback_parser
// make class move-only // make class move-only
json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete; json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete;
json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete; json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete;
json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
~json_sax_dom_callback_parser() = default; ~json_sax_dom_callback_parser() = default;
bool null() bool null()
@ -398,9 +420,9 @@ class json_sax_dom_callback_parser
ref_stack.push_back(val.second); ref_stack.push_back(val.second);
// check object limit // check object limit
if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len))); JSON_THROW(out_of_range::create(408, concat("excessive object size: ", std::to_string(len)), ref_stack.back()));
} }
return true; return true;
@ -425,10 +447,17 @@ class json_sax_dom_callback_parser
bool end_object() bool end_object()
{ {
if (ref_stack.back() && !callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back())) if (ref_stack.back())
{ {
// discard object if (!callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
*ref_stack.back() = discarded; {
// discard object
*ref_stack.back() = discarded;
}
else
{
ref_stack.back()->set_parents();
}
} }
JSON_ASSERT(!ref_stack.empty()); JSON_ASSERT(!ref_stack.empty());
@ -461,9 +490,9 @@ class json_sax_dom_callback_parser
ref_stack.push_back(val.second); ref_stack.push_back(val.second);
// check array limit // check array limit
if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len))); JSON_THROW(out_of_range::create(408, concat("excessive array size: ", std::to_string(len)), ref_stack.back()));
} }
return true; return true;
@ -476,7 +505,11 @@ class json_sax_dom_callback_parser
if (ref_stack.back()) if (ref_stack.back())
{ {
keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back()); keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
if (!keep) if (keep)
{
ref_stack.back()->set_parents();
}
else
{ {
// discard array // discard array
*ref_stack.back() = discarded; *ref_stack.back() = discarded;
@ -574,7 +607,7 @@ class json_sax_dom_callback_parser
// array // array
if (ref_stack.back()->is_array()) if (ref_stack.back()->is_array())
{ {
ref_stack.back()->m_value.array->push_back(std::move(value)); ref_stack.back()->m_value.array->emplace_back(std::move(value));
return {true, &(ref_stack.back()->m_value.array->back())}; return {true, &(ref_stack.back()->m_value.array->back())};
} }
@ -660,7 +693,7 @@ class json_sax_acceptor
return true; return true;
} }
bool start_object(std::size_t /*unused*/ = std::size_t(-1)) bool start_object(std::size_t /*unused*/ = static_cast<std::size_t>(-1))
{ {
return true; return true;
} }
@ -675,7 +708,7 @@ class json_sax_acceptor
return true; return true;
} }
bool start_array(std::size_t /*unused*/ = std::size_t(-1)) bool start_array(std::size_t /*unused*/ = static_cast<std::size_t>(-1))
{ {
return true; return true;
} }
@ -690,6 +723,6 @@ class json_sax_acceptor
return false; return false;
} }
}; };
} // namespace detail
} // namespace nlohmann } // namespace detail
NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,3 +1,11 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <array> // array #include <array> // array
@ -14,10 +22,10 @@
#include <nlohmann/detail/input/position_t.hpp> #include <nlohmann/detail/input/position_t.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
/////////// ///////////
// lexer // // lexer //
/////////// ///////////
@ -112,7 +120,7 @@ class lexer : public lexer_base<BasicJsonType>
public: public:
using token_type = typename lexer_base<BasicJsonType>::token_type; using token_type = typename lexer_base<BasicJsonType>::token_type;
explicit lexer(InputAdapterType&& adapter, bool ignore_comments_ = false) explicit lexer(InputAdapterType&& adapter, bool ignore_comments_ = false) noexcept
: ia(std::move(adapter)) : ia(std::move(adapter))
, ignore_comments(ignore_comments_) , ignore_comments(ignore_comments_)
, decimal_point_char(static_cast<char_int_type>(get_decimal_point())) , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
@ -120,9 +128,9 @@ class lexer : public lexer_base<BasicJsonType>
// delete because of pointer members // delete because of pointer members
lexer(const lexer&) = delete; lexer(const lexer&) = delete;
lexer(lexer&&) = default; lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
lexer& operator=(lexer&) = delete; lexer& operator=(lexer&) = delete;
lexer& operator=(lexer&&) = default; lexer& operator=(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
~lexer() = default; ~lexer() = default;
private: private:
@ -231,7 +239,7 @@ class lexer : public lexer_base<BasicJsonType>
/*! /*!
@brief scan a string literal @brief scan a string literal
This function scans a string according to Sect. 7 of RFC 7159. While This function scans a string according to Sect. 7 of RFC 8259. While
scanning, bytes are escaped and copied into buffer token_buffer. Then the scanning, bytes are escaped and copied into buffer token_buffer. Then the
function returns successfully, token_buffer is *not* null-terminated (as it function returns successfully, token_buffer is *not* null-terminated (as it
may contain \0 bytes), and token_buffer.size() is the number of bytes in the may contain \0 bytes), and token_buffer.size() is the number of bytes in the
@ -343,7 +351,7 @@ class lexer : public lexer_base<BasicJsonType>
// low surrogate occupies the least significant 15 bits // low surrogate occupies the least significant 15 bits
+ static_cast<unsigned int>(codepoint2) + static_cast<unsigned int>(codepoint2)
// there is still the 0xD800, 0xDC00 and 0x10000 noise // there is still the 0xD800, 0xDC00 and 0x10000 noise
// in the result so we have to subtract with: // in the result, so we have to subtract with:
// (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
- 0x35FDC00u); - 0x35FDC00u);
} }
@ -921,10 +929,10 @@ class lexer : public lexer_base<BasicJsonType>
/*! /*!
@brief scan a number literal @brief scan a number literal
This function scans a string according to Sect. 6 of RFC 7159. This function scans a string according to Sect. 6 of RFC 8259.
The function is realized with a deterministic finite state machine derived The function is realized with a deterministic finite state machine derived
from the grammar described in RFC 7159. Starting in state "init", the from the grammar described in RFC 8259. Starting in state "init", the
input is read and used to determined the next state. Only state "done" input is read and used to determined the next state. Only state "done"
accepts the number. State "error" is a trap state to model errors. In the accepts the number. State "error" is a trap state to model errors. In the
table below, "anything" means any character but the ones listed before. table below, "anything" means any character but the ones listed before.
@ -998,7 +1006,7 @@ class lexer : public lexer_base<BasicJsonType>
// all other characters are rejected outside scan_number() // all other characters are rejected outside scan_number()
default: // LCOV_EXCL_LINE default: // LCOV_EXCL_LINE
JSON_ASSERT(false); // LCOV_EXCL_LINE JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
} }
scan_number_minus: scan_number_minus:
@ -1236,7 +1244,7 @@ scan_number_done:
// we are done scanning a number) // we are done scanning a number)
unget(); unget();
char* endptr = nullptr; char* endptr = nullptr; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
errno = 0; errno = 0;
// try to parse integers first and fall back to floats // try to parse integers first and fall back to floats
@ -1447,7 +1455,7 @@ scan_number_done:
{ {
// escape control characters // escape control characters
std::array<char, 9> cs{{}}; std::array<char, 9> cs{{}};
(std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c)); static_cast<void>((std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
result += cs.data(); result += cs.data();
} }
else else
@ -1541,17 +1549,17 @@ scan_number_done:
// literals // literals
case 't': case 't':
{ {
std::array<char_type, 4> true_literal = {{'t', 'r', 'u', 'e'}}; std::array<char_type, 4> true_literal = {{static_cast<char_type>('t'), static_cast<char_type>('r'), static_cast<char_type>('u'), static_cast<char_type>('e')}};
return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true); return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
} }
case 'f': case 'f':
{ {
std::array<char_type, 5> false_literal = {{'f', 'a', 'l', 's', 'e'}}; std::array<char_type, 5> false_literal = {{static_cast<char_type>('f'), static_cast<char_type>('a'), static_cast<char_type>('l'), static_cast<char_type>('s'), static_cast<char_type>('e')}};
return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false); return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
} }
case 'n': case 'n':
{ {
std::array<char_type, 4> null_literal = {{'n', 'u', 'l', 'l'}}; std::array<char_type, 4> null_literal = {{static_cast<char_type>('n'), static_cast<char_type>('u'), static_cast<char_type>('l'), static_cast<char_type>('l')}};
return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null); return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
} }
@ -1619,5 +1627,6 @@ scan_number_done:
/// the decimal point /// the decimal point
const char_int_type decimal_point_char = '.'; const char_int_type decimal_point_char = '.';
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,3 +1,11 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <cmath> // isfinite #include <cmath> // isfinite
@ -13,17 +21,17 @@
#include <nlohmann/detail/input/lexer.hpp> #include <nlohmann/detail/input/lexer.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/is_sax.hpp> #include <nlohmann/detail/meta/is_sax.hpp>
#include <nlohmann/detail/string_concat.hpp>
#include <nlohmann/detail/value_t.hpp> #include <nlohmann/detail/value_t.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
//////////// ////////////
// parser // // parser //
//////////// ////////////
enum class parse_event_t : uint8_t enum class parse_event_t : std::uint8_t
{ {
/// the parser read `{` and started to process a JSON object /// the parser read `{` and started to process a JSON object
object_start, object_start,
@ -41,7 +49,7 @@ enum class parse_event_t : uint8_t
template<typename BasicJsonType> template<typename BasicJsonType>
using parser_callback_t = using parser_callback_t =
std::function<bool(int depth, parse_event_t event, BasicJsonType& parsed)>; std::function<bool(int /*depth*/, parse_event_t /*event*/, BasicJsonType& /*parsed*/)>;
/*! /*!
@brief syntax analysis @brief syntax analysis
@ -88,7 +96,6 @@ class parser
{ {
json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions); json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
sax_parse_internal(&sdp); sax_parse_internal(&sdp);
result.assert_invariant();
// in strict mode, input must be completely read // in strict mode, input must be completely read
if (strict && (get_token() != token_type::end_of_input)) if (strict && (get_token() != token_type::end_of_input))
@ -96,7 +103,7 @@ class parser
sdp.parse_error(m_lexer.get_position(), sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_of_input, "value"))); exception_message(token_type::end_of_input, "value"), nullptr));
} }
// in case of an error, return discarded value // in case of an error, return discarded value
@ -117,15 +124,13 @@ class parser
{ {
json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions); json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
sax_parse_internal(&sdp); sax_parse_internal(&sdp);
result.assert_invariant();
// in strict mode, input must be completely read // in strict mode, input must be completely read
if (strict && (get_token() != token_type::end_of_input)) if (strict && (get_token() != token_type::end_of_input))
{ {
sdp.parse_error(m_lexer.get_position(), sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr));
exception_message(token_type::end_of_input, "value")));
} }
// in case of an error, return discarded value // in case of an error, return discarded value
@ -135,6 +140,8 @@ class parser
return; return;
} }
} }
result.assert_invariant();
} }
/*! /*!
@ -161,8 +168,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr));
exception_message(token_type::end_of_input, "value")));
} }
return result; return result;
@ -188,7 +194,7 @@ class parser
{ {
case token_type::begin_object: case token_type::begin_object:
{ {
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1)))) if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))
{ {
return false; return false;
} }
@ -208,8 +214,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr));
exception_message(token_type::value_string, "object key")));
} }
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{ {
@ -221,8 +226,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr));
exception_message(token_type::name_separator, "object separator")));
} }
// remember we are now inside an object // remember we are now inside an object
@ -235,7 +239,7 @@ class parser
case token_type::begin_array: case token_type::begin_array:
{ {
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1)))) if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1))))
{ {
return false; return false;
} }
@ -265,7 +269,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'")); out_of_range::create(406, concat("number overflow parsing '", m_lexer.get_token_string(), '\''), nullptr));
} }
if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string()))) if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
@ -335,16 +339,21 @@ class parser
// using "uninitialized" to avoid "expected" message // using "uninitialized" to avoid "expected" message
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), nullptr));
exception_message(token_type::uninitialized, "value")));
} }
case token_type::uninitialized:
case token_type::end_array:
case token_type::end_object:
case token_type::name_separator:
case token_type::value_separator:
case token_type::end_of_input:
case token_type::literal_or_value:
default: // the last token was unexpected default: // the last token was unexpected
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), nullptr));
exception_message(token_type::literal_or_value, "value")));
} }
} }
} }
@ -390,65 +399,61 @@ class parser
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array, "array"), nullptr));
exception_message(token_type::end_array, "array")));
} }
else // object
// states.back() is false -> object
// comma -> next value
if (get_token() == token_type::value_separator)
{ {
// comma -> next value // parse key
if (get_token() == token_type::value_separator) if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
{ {
// parse key return sax->parse_error(m_lexer.get_position(),
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string)) m_lexer.get_token_string(),
{ parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr));
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::value_string, "object key")));
}
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}
// parse separator (:)
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::name_separator, "object separator")));
}
// parse values
get_token();
continue;
} }
// closing } if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
{ {
if (JSON_HEDLEY_UNLIKELY(!sax->end_object())) return false;
{
return false;
}
// We are done with this object. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
} }
return sax->parse_error(m_lexer.get_position(), // parse separator (:)
m_lexer.get_token_string(), if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
parse_error::create(101, m_lexer.get_position(), {
exception_message(token_type::end_object, "object"))); return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr));
}
// parse values
get_token();
continue;
} }
// closing }
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
{
if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
{
return false;
}
// We are done with this object. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
}
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object, "object"), nullptr));
} }
} }
@ -464,24 +469,24 @@ class parser
if (!context.empty()) if (!context.empty())
{ {
error_msg += "while parsing " + context + " "; error_msg += concat("while parsing ", context, ' ');
} }
error_msg += "- "; error_msg += "- ";
if (last_token == token_type::parse_error) if (last_token == token_type::parse_error)
{ {
error_msg += std::string(m_lexer.get_error_message()) + "; last read: '" + error_msg += concat(m_lexer.get_error_message(), "; last read: '",
m_lexer.get_token_string() + "'"; m_lexer.get_token_string(), '\'');
} }
else else
{ {
error_msg += "unexpected " + std::string(lexer_t::token_type_name(last_token)); error_msg += concat("unexpected ", lexer_t::token_type_name(last_token));
} }
if (expected != token_type::uninitialized) if (expected != token_type::uninitialized)
{ {
error_msg += "; expected " + std::string(lexer_t::token_type_name(expected)); error_msg += concat("; expected ", lexer_t::token_type_name(expected));
} }
return error_msg; return error_msg;
@ -497,5 +502,6 @@ class parser
/// whether to throw exceptions in case of errors /// whether to throw exceptions in case of errors
const bool allow_exceptions = true; const bool allow_exceptions = true;
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,11 +1,21 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <cstddef> // size_t #include <cstddef> // size_t
namespace nlohmann #include <nlohmann/detail/abi_macros.hpp>
{
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail namespace detail
{ {
/// struct to capture the start position of the current token /// struct to capture the start position of the current token
struct position_t struct position_t
{ {
@ -23,5 +33,5 @@ struct position_t
} }
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,11 +1,20 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <nlohmann/detail/abi_macros.hpp>
#include <nlohmann/detail/iterators/primitive_iterator.hpp> #include <nlohmann/detail/iterators/primitive_iterator.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
/*! /*!
@brief an iterator value @brief an iterator value
@ -21,5 +30,6 @@ template<typename BasicJsonType> struct internal_iterator
/// generic iterator for all other types /// generic iterator for all other types
primitive_iterator_t primitive_iterator {}; primitive_iterator_t primitive_iterator {};
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,3 +1,11 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next #include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next
@ -11,10 +19,10 @@
#include <nlohmann/detail/meta/type_traits.hpp> #include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp> #include <nlohmann/detail/value_t.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
// forward declare, to be able to friend it later on // forward declare, to be able to friend it later on
template<typename IteratorType> class iteration_proxy; template<typename IteratorType> class iteration_proxy;
template<typename IteratorType> class iteration_proxy_value; template<typename IteratorType> class iteration_proxy_value;
@ -36,10 +44,12 @@ This class implements a both iterators (iterator and const_iterator) for the
iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593) iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593)
*/ */
template<typename BasicJsonType> template<typename BasicJsonType>
class iter_impl class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
{ {
/// the iterator with BasicJsonType of different const-ness
using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;
/// allow basic_json to access private members /// allow basic_json to access private members
friend iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>; friend other_iter_impl;
friend BasicJsonType; friend BasicJsonType;
friend iteration_proxy<iter_impl>; friend iteration_proxy<iter_impl>;
friend iteration_proxy_value<iter_impl>; friend iteration_proxy_value<iter_impl>;
@ -49,9 +59,12 @@ class iter_impl
// make sure BasicJsonType is basic_json or const basic_json // make sure BasicJsonType is basic_json or const basic_json
static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value, static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value,
"iter_impl only accepts (const) basic_json"); "iter_impl only accepts (const) basic_json");
// superficial check for the LegacyBidirectionalIterator named requirement
static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value
&& std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value,
"basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.");
public: public:
/// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. /// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17.
/// The C++ Standard has never required user-defined iterators to derive from std::iterator. /// The C++ Standard has never required user-defined iterators to derive from std::iterator.
/// A user-defined iterator should provide publicly accessible typedefs named /// A user-defined iterator should provide publicly accessible typedefs named
@ -73,8 +86,10 @@ class iter_impl
typename BasicJsonType::const_reference, typename BasicJsonType::const_reference,
typename BasicJsonType::reference>::type; typename BasicJsonType::reference>::type;
/// default constructor
iter_impl() = default; iter_impl() = default;
~iter_impl() = default;
iter_impl(iter_impl&&) noexcept = default;
iter_impl& operator=(iter_impl&&) noexcept = default;
/*! /*!
@brief constructor for a given JSON instance @brief constructor for a given JSON instance
@ -100,6 +115,14 @@ class iter_impl
break; break;
} }
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
{ {
m_it.primitive_iterator = primitive_iterator_t(); m_it.primitive_iterator = primitive_iterator_t();
@ -136,8 +159,11 @@ class iter_impl
*/ */
iter_impl& operator=(const iter_impl<const BasicJsonType>& other) noexcept iter_impl& operator=(const iter_impl<const BasicJsonType>& other) noexcept
{ {
m_object = other.m_object; if (&other != this)
m_it = other.m_it; {
m_object = other.m_object;
m_it = other.m_it;
}
return *this; return *this;
} }
@ -156,14 +182,14 @@ class iter_impl
@return const/non-const iterator @return const/non-const iterator
@note It is not checked whether @a other is initialized. @note It is not checked whether @a other is initialized.
*/ */
iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept // NOLINT(cert-oop54-cpp)
{ {
m_object = other.m_object; m_object = other.m_object;
m_it = other.m_it; m_it = other.m_it;
return *this; return *this;
} }
private: JSON_PRIVATE_UNLESS_TESTED:
/*! /*!
@brief set the iterator to the first value @brief set the iterator to the first value
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
@ -193,6 +219,13 @@ class iter_impl
break; break;
} }
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
{ {
m_it.primitive_iterator.set_begin(); m_it.primitive_iterator.set_begin();
@ -223,6 +256,14 @@ class iter_impl
break; break;
} }
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
{ {
m_it.primitive_iterator.set_end(); m_it.primitive_iterator.set_end();
@ -255,8 +296,15 @@ class iter_impl
} }
case value_t::null: case value_t::null:
JSON_THROW(invalid_iterator::create(214, "cannot get value")); JSON_THROW(invalid_iterator::create(214, "cannot get value", m_object));
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
{ {
if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin())) if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
@ -264,7 +312,7 @@ class iter_impl
return *m_object; return *m_object;
} }
JSON_THROW(invalid_iterator::create(214, "cannot get value")); JSON_THROW(invalid_iterator::create(214, "cannot get value", m_object));
} }
} }
} }
@ -291,6 +339,14 @@ class iter_impl
return &*m_it.array_iterator; return &*m_it.array_iterator;
} }
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
{ {
if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin())) if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
@ -298,7 +354,7 @@ class iter_impl
return m_object; return m_object;
} }
JSON_THROW(invalid_iterator::create(214, "cannot get value")); JSON_THROW(invalid_iterator::create(214, "cannot get value", m_object));
} }
} }
} }
@ -307,7 +363,7 @@ class iter_impl
@brief post-increment (it++) @brief post-increment (it++)
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
iter_impl const operator++(int) iter_impl operator++(int)& // NOLINT(cert-dcl21-cpp)
{ {
auto result = *this; auto result = *this;
++(*this); ++(*this);
@ -336,6 +392,14 @@ class iter_impl
break; break;
} }
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
{ {
++m_it.primitive_iterator; ++m_it.primitive_iterator;
@ -350,7 +414,7 @@ class iter_impl
@brief post-decrement (it--) @brief post-decrement (it--)
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
iter_impl const operator--(int) iter_impl operator--(int)& // NOLINT(cert-dcl21-cpp)
{ {
auto result = *this; auto result = *this;
--(*this); --(*this);
@ -379,6 +443,14 @@ class iter_impl
break; break;
} }
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
{ {
--m_it.primitive_iterator; --m_it.primitive_iterator;
@ -390,15 +462,16 @@ class iter_impl
} }
/*! /*!
@brief comparison: equal @brief comparison: equal
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
bool operator==(const iter_impl& other) const template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr >
bool operator==(const IterImpl& other) const
{ {
// if objects are not the same, the comparison is undefined // if objects are not the same, the comparison is undefined
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
{ {
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers")); JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", m_object));
} }
JSON_ASSERT(m_object != nullptr); JSON_ASSERT(m_object != nullptr);
@ -411,22 +484,31 @@ class iter_impl
case value_t::array: case value_t::array:
return (m_it.array_iterator == other.m_it.array_iterator); return (m_it.array_iterator == other.m_it.array_iterator);
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
return (m_it.primitive_iterator == other.m_it.primitive_iterator); return (m_it.primitive_iterator == other.m_it.primitive_iterator);
} }
} }
/*! /*!
@brief comparison: not equal @brief comparison: not equal
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
bool operator!=(const iter_impl& other) const template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr >
bool operator!=(const IterImpl& other) const
{ {
return !operator==(other); return !operator==(other);
} }
/*! /*!
@brief comparison: smaller @brief comparison: smaller
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
bool operator<(const iter_impl& other) const bool operator<(const iter_impl& other) const
@ -434,7 +516,7 @@ class iter_impl
// if objects are not the same, the comparison is undefined // if objects are not the same, the comparison is undefined
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
{ {
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers")); JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", m_object));
} }
JSON_ASSERT(m_object != nullptr); JSON_ASSERT(m_object != nullptr);
@ -442,18 +524,26 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators")); JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators", m_object));
case value_t::array: case value_t::array:
return (m_it.array_iterator < other.m_it.array_iterator); return (m_it.array_iterator < other.m_it.array_iterator);
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
return (m_it.primitive_iterator < other.m_it.primitive_iterator); return (m_it.primitive_iterator < other.m_it.primitive_iterator);
} }
} }
/*! /*!
@brief comparison: less than or equal @brief comparison: less than or equal
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
bool operator<=(const iter_impl& other) const bool operator<=(const iter_impl& other) const
@ -462,7 +552,7 @@ class iter_impl
} }
/*! /*!
@brief comparison: greater than @brief comparison: greater than
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
bool operator>(const iter_impl& other) const bool operator>(const iter_impl& other) const
@ -471,7 +561,7 @@ class iter_impl
} }
/*! /*!
@brief comparison: greater than or equal @brief comparison: greater than or equal
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
bool operator>=(const iter_impl& other) const bool operator>=(const iter_impl& other) const
@ -480,7 +570,7 @@ class iter_impl
} }
/*! /*!
@brief add to iterator @brief add to iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
iter_impl& operator+=(difference_type i) iter_impl& operator+=(difference_type i)
@ -490,7 +580,7 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators")); JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", m_object));
case value_t::array: case value_t::array:
{ {
@ -498,6 +588,14 @@ class iter_impl
break; break;
} }
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
{ {
m_it.primitive_iterator += i; m_it.primitive_iterator += i;
@ -509,7 +607,7 @@ class iter_impl
} }
/*! /*!
@brief subtract from iterator @brief subtract from iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
iter_impl& operator-=(difference_type i) iter_impl& operator-=(difference_type i)
@ -518,7 +616,7 @@ class iter_impl
} }
/*! /*!
@brief add to iterator @brief add to iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
iter_impl operator+(difference_type i) const iter_impl operator+(difference_type i) const
@ -529,7 +627,7 @@ class iter_impl
} }
/*! /*!
@brief addition of distance and iterator @brief addition of distance and iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
friend iter_impl operator+(difference_type i, const iter_impl& it) friend iter_impl operator+(difference_type i, const iter_impl& it)
@ -540,7 +638,7 @@ class iter_impl
} }
/*! /*!
@brief subtract from iterator @brief subtract from iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
iter_impl operator-(difference_type i) const iter_impl operator-(difference_type i) const
@ -551,7 +649,7 @@ class iter_impl
} }
/*! /*!
@brief return difference @brief return difference
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
difference_type operator-(const iter_impl& other) const difference_type operator-(const iter_impl& other) const
@ -561,18 +659,26 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators")); JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", m_object));
case value_t::array: case value_t::array:
return m_it.array_iterator - other.m_it.array_iterator; return m_it.array_iterator - other.m_it.array_iterator;
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
return m_it.primitive_iterator - other.m_it.primitive_iterator; return m_it.primitive_iterator - other.m_it.primitive_iterator;
} }
} }
/*! /*!
@brief access to successor @brief access to successor
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
reference operator[](difference_type n) const reference operator[](difference_type n) const
@ -582,14 +688,21 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators")); JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators", m_object));
case value_t::array: case value_t::array:
return *std::next(m_it.array_iterator, n); return *std::next(m_it.array_iterator, n);
case value_t::null: case value_t::null:
JSON_THROW(invalid_iterator::create(214, "cannot get value")); JSON_THROW(invalid_iterator::create(214, "cannot get value", m_object));
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
{ {
if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n)) if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
@ -597,13 +710,13 @@ class iter_impl
return *m_object; return *m_object;
} }
JSON_THROW(invalid_iterator::create(214, "cannot get value")); JSON_THROW(invalid_iterator::create(214, "cannot get value", m_object));
} }
} }
} }
/*! /*!
@brief return the key of an object iterator @brief return the key of an object iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
const typename object_t::key_type& key() const const typename object_t::key_type& key() const
@ -615,11 +728,11 @@ class iter_impl
return m_it.object_iterator->first; return m_it.object_iterator->first;
} }
JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators")); JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators", m_object));
} }
/*! /*!
@brief return the value of an iterator @brief return the value of an iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`. @pre The iterator is initialized; i.e. `m_object != nullptr`.
*/ */
reference value() const reference value() const
@ -627,11 +740,12 @@ class iter_impl
return operator*(); return operator*();
} }
private: JSON_PRIVATE_UNLESS_TESTED:
/// associated JSON instance /// associated JSON instance
pointer m_object = nullptr; pointer m_object = nullptr;
/// the actual iterator of the associated instance /// the actual iterator of the associated instance
internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {}; internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {};
}; };
} // namespace detail
} // namespace nlohmann } // namespace detail
NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,17 +1,31 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <cstddef> // size_t #include <cstddef> // size_t
#include <iterator> // input_iterator_tag #include <iterator> // input_iterator_tag
#include <string> // string, to_string #include <string> // string, to_string
#include <tuple> // tuple_size, get, tuple_element #include <tuple> // tuple_size, get, tuple_element
#include <utility> // move
#if JSON_HAS_RANGES
#include <ranges> // enable_borrowed_range
#endif
#include <nlohmann/detail/abi_macros.hpp>
#include <nlohmann/detail/meta/type_traits.hpp> #include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp> #include <nlohmann/detail/value_t.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
template<typename string_type> template<typename string_type>
void int_to_string( string_type& target, std::size_t value ) void int_to_string( string_type& target, std::size_t value )
{ {
@ -24,14 +38,14 @@ template<typename IteratorType> class iteration_proxy_value
public: public:
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
using value_type = iteration_proxy_value; using value_type = iteration_proxy_value;
using pointer = value_type * ; using pointer = value_type *;
using reference = value_type & ; using reference = value_type &;
using iterator_category = std::input_iterator_tag; using iterator_category = std::input_iterator_tag;
using string_type = typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type; using string_type = typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
private: private:
/// the iterator /// the iterator
IteratorType anchor; IteratorType anchor{};
/// an index for arrays (used to create key names) /// an index for arrays (used to create key names)
std::size_t array_index = 0; std::size_t array_index = 0;
/// last stringified array index /// last stringified array index
@ -39,13 +53,30 @@ template<typename IteratorType> class iteration_proxy_value
/// a string representation of the array index /// a string representation of the array index
mutable string_type array_index_str = "0"; mutable string_type array_index_str = "0";
/// an empty string (to return a reference for primitive values) /// an empty string (to return a reference for primitive values)
const string_type empty_str = ""; string_type empty_str{};
public: public:
explicit iteration_proxy_value(IteratorType it) noexcept : anchor(it) {} explicit iteration_proxy_value() = default;
explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0)
noexcept(std::is_nothrow_move_constructible<IteratorType>::value
&& std::is_nothrow_default_constructible<string_type>::value)
: anchor(std::move(it))
, array_index(array_index_)
{}
iteration_proxy_value(iteration_proxy_value const&) = default;
iteration_proxy_value& operator=(iteration_proxy_value const&) = default;
// older GCCs are a bit fussy and require explicit noexcept specifiers on defaulted functions
iteration_proxy_value(iteration_proxy_value&&)
noexcept(std::is_nothrow_move_constructible<IteratorType>::value
&& std::is_nothrow_move_constructible<string_type>::value) = default;
iteration_proxy_value& operator=(iteration_proxy_value&&)
noexcept(std::is_nothrow_move_assignable<IteratorType>::value
&& std::is_nothrow_move_assignable<string_type>::value) = default;
~iteration_proxy_value() = default;
/// dereference operator (needed for range-based for) /// dereference operator (needed for range-based for)
iteration_proxy_value& operator*() const iteration_proxy_value& operator*() const
{ {
return *this; return *this;
} }
@ -59,6 +90,14 @@ template<typename IteratorType> class iteration_proxy_value
return *this; return *this;
} }
iteration_proxy_value operator++(int)& // NOLINT(cert-dcl21-cpp)
{
auto tmp = iteration_proxy_value(anchor, array_index);
++anchor;
++array_index;
return tmp;
}
/// equality operator (needed for InputIterator) /// equality operator (needed for InputIterator)
bool operator==(const iteration_proxy_value& o) const bool operator==(const iteration_proxy_value& o) const
{ {
@ -94,6 +133,14 @@ template<typename IteratorType> class iteration_proxy_value
return anchor.key(); return anchor.key();
// use an empty key for all primitive types // use an empty key for all primitive types
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
return empty_str; return empty_str;
} }
@ -111,25 +158,34 @@ template<typename IteratorType> class iteration_proxy
{ {
private: private:
/// the container to iterate /// the container to iterate
typename IteratorType::reference container; typename IteratorType::pointer container = nullptr;
public: public:
explicit iteration_proxy() = default;
/// construct iteration proxy from a container /// construct iteration proxy from a container
explicit iteration_proxy(typename IteratorType::reference cont) noexcept explicit iteration_proxy(typename IteratorType::reference cont) noexcept
: container(cont) {} : container(&cont) {}
iteration_proxy(iteration_proxy const&) = default;
iteration_proxy& operator=(iteration_proxy const&) = default;
iteration_proxy(iteration_proxy&&) noexcept = default;
iteration_proxy& operator=(iteration_proxy&&) noexcept = default;
~iteration_proxy() = default;
/// return iterator begin (needed for range-based for) /// return iterator begin (needed for range-based for)
iteration_proxy_value<IteratorType> begin() noexcept iteration_proxy_value<IteratorType> begin() const noexcept
{ {
return iteration_proxy_value<IteratorType>(container.begin()); return iteration_proxy_value<IteratorType>(container->begin());
} }
/// return iterator end (needed for range-based for) /// return iterator end (needed for range-based for)
iteration_proxy_value<IteratorType> end() noexcept iteration_proxy_value<IteratorType> end() const noexcept
{ {
return iteration_proxy_value<IteratorType>(container.end()); return iteration_proxy_value<IteratorType>(container->end());
} }
}; };
// Structured Bindings Support // Structured Bindings Support
// For further reference see https://blog.tartanllama.xyz/structured-bindings/ // For further reference see https://blog.tartanllama.xyz/structured-bindings/
// And see https://github.com/nlohmann/json/pull/1391 // And see https://github.com/nlohmann/json/pull/1391
@ -146,8 +202,9 @@ auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decl
{ {
return i.value(); return i.value();
} }
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END
// The Addition to the STD Namespace is required to add // The Addition to the STD Namespace is required to add
// Structured Bindings Support to the iteration_proxy_value class // Structured Bindings Support to the iteration_proxy_value class
@ -155,6 +212,7 @@ auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decl
// And see https://github.com/nlohmann/json/pull/1391 // And see https://github.com/nlohmann/json/pull/1391
namespace std namespace std
{ {
#if defined(__clang__) #if defined(__clang__)
// Fix: https://github.com/nlohmann/json/issues/1401 // Fix: https://github.com/nlohmann/json/issues/1401
#pragma clang diagnostic push #pragma clang diagnostic push
@ -175,4 +233,10 @@ class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif #endif
} // namespace std
} // namespace std
#if JSON_HAS_RANGES
template <typename IteratorType>
inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> = true;
#endif

View File

@ -1,14 +1,23 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <iterator> // random_access_iterator_tag #include <iterator> // random_access_iterator_tag
#include <nlohmann/detail/abi_macros.hpp>
#include <nlohmann/detail/meta/void_t.hpp> #include <nlohmann/detail/meta/void_t.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp> #include <nlohmann/detail/meta/cpp_future.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
template<typename It, typename = void> template<typename It, typename = void>
struct iterator_types {}; struct iterator_types {};
@ -47,5 +56,6 @@ struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
using pointer = T*; using pointer = T*;
using reference = T&; using reference = T&;
}; };
} // namespace detail
} // namespace nlohmann } // namespace detail
NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,13 +1,23 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <cstddef> // ptrdiff_t #include <cstddef> // ptrdiff_t
#include <iterator> // reverse_iterator #include <iterator> // reverse_iterator
#include <utility> // declval #include <utility> // declval
namespace nlohmann #include <nlohmann/detail/abi_macros.hpp>
{
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail namespace detail
{ {
////////////////////// //////////////////////
// reverse_iterator // // reverse_iterator //
////////////////////// //////////////////////
@ -48,7 +58,7 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {} explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {}
/// post-increment (it++) /// post-increment (it++)
json_reverse_iterator const operator++(int) json_reverse_iterator operator++(int)& // NOLINT(cert-dcl21-cpp)
{ {
return static_cast<json_reverse_iterator>(base_iterator::operator++(1)); return static_cast<json_reverse_iterator>(base_iterator::operator++(1));
} }
@ -60,7 +70,7 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
} }
/// post-decrement (it--) /// post-decrement (it--)
json_reverse_iterator const operator--(int) json_reverse_iterator operator--(int)& // NOLINT(cert-dcl21-cpp)
{ {
return static_cast<json_reverse_iterator>(base_iterator::operator--(1)); return static_cast<json_reverse_iterator>(base_iterator::operator--(1));
} }
@ -115,5 +125,6 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
return it.operator * (); return it.operator * ();
} }
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,12 +1,22 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <cstddef> // ptrdiff_t #include <cstddef> // ptrdiff_t
#include <limits> // numeric_limits #include <limits> // numeric_limits
namespace nlohmann #include <nlohmann/detail/macro_scope.hpp>
{
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail namespace detail
{ {
/* /*
@brief an iterator for primitive JSON types @brief an iterator for primitive JSON types
@ -23,6 +33,7 @@ class primitive_iterator_t
static constexpr difference_type begin_value = 0; static constexpr difference_type begin_value = 0;
static constexpr difference_type end_value = begin_value + 1; static constexpr difference_type end_value = begin_value + 1;
JSON_PRIVATE_UNLESS_TESTED:
/// iterator as signed integer type /// iterator as signed integer type
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)(); difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
@ -84,7 +95,7 @@ class primitive_iterator_t
return *this; return *this;
} }
primitive_iterator_t const operator++(int) noexcept primitive_iterator_t operator++(int)& noexcept // NOLINT(cert-dcl21-cpp)
{ {
auto result = *this; auto result = *this;
++m_it; ++m_it;
@ -97,7 +108,7 @@ class primitive_iterator_t
return *this; return *this;
} }
primitive_iterator_t const operator--(int) noexcept primitive_iterator_t operator--(int)& noexcept // NOLINT(cert-dcl21-cpp)
{ {
auto result = *this; auto result = *this;
--m_it; --m_it;
@ -116,5 +127,6 @@ class primitive_iterator_t
return *this; return *this;
} }
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,23 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <initializer_list> #include <initializer_list>
#include <utility> #include <utility>
#include <nlohmann/detail/abi_macros.hpp>
#include <nlohmann/detail/meta/type_traits.hpp> #include <nlohmann/detail/meta/type_traits.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
template<typename BasicJsonType> template<typename BasicJsonType>
class json_ref class json_ref
{ {
@ -17,19 +26,14 @@ class json_ref
json_ref(value_type&& value) json_ref(value_type&& value)
: owned_value(std::move(value)) : owned_value(std::move(value))
, value_ref(&owned_value)
, is_rvalue(true)
{} {}
json_ref(const value_type& value) json_ref(const value_type& value)
: value_ref(const_cast<value_type*>(&value)) : value_ref(&value)
, is_rvalue(false)
{} {}
json_ref(std::initializer_list<json_ref> init) json_ref(std::initializer_list<json_ref> init)
: owned_value(init) : owned_value(init)
, value_ref(&owned_value)
, is_rvalue(true)
{} {}
template < template <
@ -37,12 +41,10 @@ class json_ref
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 > enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
json_ref(Args && ... args) json_ref(Args && ... args)
: owned_value(std::forward<Args>(args)...) : owned_value(std::forward<Args>(args)...)
, value_ref(&owned_value)
, is_rvalue(true)
{} {}
// class should be movable only // class should be movable only
json_ref(json_ref&&) = default; json_ref(json_ref&&) noexcept = default;
json_ref(const json_ref&) = delete; json_ref(const json_ref&) = delete;
json_ref& operator=(const json_ref&) = delete; json_ref& operator=(const json_ref&) = delete;
json_ref& operator=(json_ref&&) = delete; json_ref& operator=(json_ref&&) = delete;
@ -50,27 +52,27 @@ class json_ref
value_type moved_or_copied() const value_type moved_or_copied() const
{ {
if (is_rvalue) if (value_ref == nullptr)
{ {
return std::move(*value_ref); return std::move(owned_value);
} }
return *value_ref; return *value_ref;
} }
value_type const& operator*() const value_type const& operator*() const
{ {
return *static_cast<value_type const*>(value_ref); return value_ref ? *value_ref : owned_value;
} }
value_type const* operator->() const value_type const* operator->() const
{ {
return static_cast<value_type const*>(value_ref); return &** this;
} }
private: private:
mutable value_type owned_value = nullptr; mutable value_type owned_value = nullptr;
value_type* value_ref = nullptr; value_type const* value_ref = nullptr;
const bool is_rvalue = true;
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,11 +1,22 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <utility> // pair #include <utility> // declval, pair
#include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/thirdparty/hedley/hedley.hpp> #include <nlohmann/thirdparty/hedley/hedley.hpp>
// This file contains all internal macro definitions // This file contains all internal macro definitions (except those affecting ABI)
// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them
#include <nlohmann/detail/abi_macros.hpp>
// exclude unsupported compilers // exclude unsupported compilers
#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
#if defined(__clang__) #if defined(__clang__)
@ -20,30 +31,128 @@
#endif #endif
// C++ language standard detection // C++ language standard detection
#if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) // if the user manually specified the used c++ version this is skipped
#define JSON_HAS_CPP_20 #if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
#define JSON_HAS_CPP_17 #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
#define JSON_HAS_CPP_14 #define JSON_HAS_CPP_20
#elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 #define JSON_HAS_CPP_17
#define JSON_HAS_CPP_17 #define JSON_HAS_CPP_14
#define JSON_HAS_CPP_14 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) #define JSON_HAS_CPP_17
#define JSON_HAS_CPP_14 #define JSON_HAS_CPP_14
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
#define JSON_HAS_CPP_14
#endif
// the cpp 11 flag is always specified because it is the minimal required version
#define JSON_HAS_CPP_11
#endif #endif
// disable float-equal warnings on GCC/clang #ifdef __has_include
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) #if __has_include(<version>)
#pragma GCC diagnostic push #include <version>
#pragma GCC diagnostic ignored "-Wfloat-equal" #endif
#endif
#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM)
#ifdef JSON_HAS_CPP_17
#if defined(__cpp_lib_filesystem)
#define JSON_HAS_FILESYSTEM 1
#elif defined(__cpp_lib_experimental_filesystem)
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
#elif !defined(__has_include)
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
#elif __has_include(<filesystem>)
#define JSON_HAS_FILESYSTEM 1
#elif __has_include(<experimental/filesystem>)
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
#endif
// std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/
#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
#undef JSON_HAS_FILESYSTEM
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#endif
// no filesystem support before GCC 8: https://en.cppreference.com/w/cpp/compiler_support
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8
#undef JSON_HAS_FILESYSTEM
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#endif
// no filesystem support before Clang 7: https://en.cppreference.com/w/cpp/compiler_support
#if defined(__clang_major__) && __clang_major__ < 7
#undef JSON_HAS_FILESYSTEM
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#endif
// no filesystem support before MSVC 19.14: https://en.cppreference.com/w/cpp/compiler_support
#if defined(_MSC_VER) && _MSC_VER < 1914
#undef JSON_HAS_FILESYSTEM
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#endif
// no filesystem support before iOS 13
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000
#undef JSON_HAS_FILESYSTEM
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#endif
// no filesystem support before macOS Catalina
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
#undef JSON_HAS_FILESYSTEM
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#endif
#endif
#endif
#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0
#endif
#ifndef JSON_HAS_FILESYSTEM
#define JSON_HAS_FILESYSTEM 0
#endif
#ifndef JSON_HAS_THREE_WAY_COMPARISON
#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \
&& defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L
#define JSON_HAS_THREE_WAY_COMPARISON 1
#else
#define JSON_HAS_THREE_WAY_COMPARISON 0
#endif
#endif
#ifndef JSON_HAS_RANGES
// ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error
#if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
#define JSON_HAS_RANGES 0
#elif defined(__cpp_lib_ranges)
#define JSON_HAS_RANGES 1
#else
#define JSON_HAS_RANGES 0
#endif
#endif
#ifdef JSON_HAS_CPP_17
#define JSON_INLINE_VARIABLE inline
#else
#define JSON_INLINE_VARIABLE
#endif
#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
#define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
#else
#define JSON_NO_UNIQUE_ADDRESS
#endif #endif
// disable documentation warnings on clang // disable documentation warnings on clang
#if defined(__clang__) #if defined(__clang__)
#pragma GCC diagnostic push #pragma clang diagnostic push
#pragma GCC diagnostic ignored "-Wdocumentation" #pragma clang diagnostic ignored "-Wdocumentation"
#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
#endif #endif
// allow to disable exceptions // allow disabling exceptions
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
#define JSON_THROW(exception) throw exception #define JSON_THROW(exception) throw exception
#define JSON_TRY try #define JSON_TRY try
@ -77,12 +186,19 @@
#define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
#endif #endif
// allow to override assert // allow overriding assert
#if !defined(JSON_ASSERT) #if !defined(JSON_ASSERT)
#include <cassert> // assert #include <cassert> // assert
#define JSON_ASSERT(x) assert(x) #define JSON_ASSERT(x) assert(x)
#endif #endif
// allow to access some private functions (needed by the test suite)
#if defined(JSON_TESTS_PRIVATE)
#define JSON_PRIVATE_UNLESS_TESTED public
#else
#define JSON_PRIVATE_UNLESS_TESTED private
#endif
/*! /*!
@brief macro to briefly define a mapping between an enum and JSON @brief macro to briefly define a mapping between an enum and JSON
@def NLOHMANN_JSON_SERIALIZE_ENUM @def NLOHMANN_JSON_SERIALIZE_ENUM
@ -266,6 +382,7 @@
#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1; #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1);
/*! /*!
@brief macro @brief macro
@ -276,6 +393,10 @@
friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
/*! /*!
@brief macro @brief macro
@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE @def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
@ -285,6 +406,49 @@
inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
// inspired from https://stackoverflow.com/a/26745591
// allows to call any std function as if (e.g. with begin):
// using std::begin; begin(x);
//
// it allows using the detected idiom to retrieve the return type
// of such an expression
#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
namespace detail { \
using std::std_name; \
\
template<typename... T> \
using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
} \
\
namespace detail2 { \
struct std_name##_tag \
{ \
}; \
\
template<typename... T> \
std_name##_tag std_name(T&&...); \
\
template<typename... T> \
using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
\
template<typename... T> \
struct would_call_std_##std_name \
{ \
static constexpr auto const value = ::nlohmann::detail:: \
is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
}; \
} /* namespace detail2 */ \
\
template<typename... T> \
struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \
{ \
}
#ifndef JSON_USE_IMPLICIT_CONVERSIONS #ifndef JSON_USE_IMPLICIT_CONVERSIONS
#define JSON_USE_IMPLICIT_CONVERSIONS 1 #define JSON_USE_IMPLICIT_CONVERSIONS 1
#endif #endif
@ -294,3 +458,11 @@
#else #else
#define JSON_EXPLICIT explicit #define JSON_EXPLICIT explicit
#endif #endif
#ifndef JSON_DISABLE_ENUM_SERIALIZATION
#define JSON_DISABLE_ENUM_SERIALIZATION 0
#endif
#ifndef JSON_USE_GLOBAL_UDLS
#define JSON_USE_GLOBAL_UDLS 1
#endif

View File

@ -1,23 +1,44 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
// restore GCC/clang diagnostic settings // restore clang diagnostic settings
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
#pragma GCC diagnostic pop
#endif
#if defined(__clang__) #if defined(__clang__)
#pragma GCC diagnostic pop #pragma clang diagnostic pop
#endif #endif
// clean up // clean up
#undef JSON_ASSERT #undef JSON_ASSERT
#undef JSON_INTERNAL_CATCH #undef JSON_INTERNAL_CATCH
#undef JSON_CATCH
#undef JSON_THROW #undef JSON_THROW
#undef JSON_TRY #undef JSON_PRIVATE_UNLESS_TESTED
#undef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_17
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
#undef NLOHMANN_BASIC_JSON_TPL #undef NLOHMANN_BASIC_JSON_TPL
#undef JSON_EXPLICIT #undef JSON_EXPLICIT
#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
#undef JSON_INLINE_VARIABLE
#undef JSON_NO_UNIQUE_ADDRESS
#undef JSON_DISABLE_ENUM_SERIALIZATION
#undef JSON_USE_GLOBAL_UDLS
#ifndef JSON_TEST_KEEP_MACROS
#undef JSON_CATCH
#undef JSON_TRY
#undef JSON_HAS_CPP_11
#undef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_17
#undef JSON_HAS_CPP_20
#undef JSON_HAS_FILESYSTEM
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#undef JSON_HAS_THREE_WAY_COMPARISON
#undef JSON_HAS_RANGES
#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#endif
#include <nlohmann/thirdparty/hedley/hedley_undef.hpp> #include <nlohmann/thirdparty/hedley/hedley_undef.hpp>

View File

@ -0,0 +1,17 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once
#include <nlohmann/detail/macro_scope.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);
NLOHMANN_JSON_NAMESPACE_END

View File

@ -0,0 +1,17 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once
#include <nlohmann/detail/macro_scope.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);
NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,50 +1,150 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-FileCopyrightText: 2018 The Abseil Authors
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <array> // array
#include <cstddef> // size_t #include <cstddef> // size_t
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type #include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
#include <utility> // index_sequence, make_index_sequence, index_sequence_for
namespace nlohmann #include <nlohmann/detail/macro_scope.hpp>
{
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail namespace detail
{ {
// alias templates to reduce boilerplate
template<bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;
template<typename T> template<typename T>
using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type; using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
// implementation of C++14 index_sequence and affiliates #ifdef JSON_HAS_CPP_14
// source: https://stackoverflow.com/a/32223343
template<std::size_t... Ints> // the following utilities are natively available in C++14
struct index_sequence using std::enable_if_t;
using std::index_sequence;
using std::make_index_sequence;
using std::index_sequence_for;
#else
// alias templates to reduce boilerplate
template<bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;
// The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h
// which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0.
//// START OF CODE FROM GOOGLE ABSEIL
// integer_sequence
//
// Class template representing a compile-time integer sequence. An instantiation
// of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its
// type through its template arguments (which is a common need when
// working with C++11 variadic templates). `absl::integer_sequence` is designed
// to be a drop-in replacement for C++14's `std::integer_sequence`.
//
// Example:
//
// template< class T, T... Ints >
// void user_function(integer_sequence<T, Ints...>);
//
// int main()
// {
// // user_function's `T` will be deduced to `int` and `Ints...`
// // will be deduced to `0, 1, 2, 3, 4`.
// user_function(make_integer_sequence<int, 5>());
// }
template <typename T, T... Ints>
struct integer_sequence
{ {
using type = index_sequence; using value_type = T;
using value_type = std::size_t;
static constexpr std::size_t size() noexcept static constexpr std::size_t size() noexcept
{ {
return sizeof...(Ints); return sizeof...(Ints);
} }
}; };
template<class Sequence1, class Sequence2> // index_sequence
struct merge_and_renumber; //
// A helper template for an `integer_sequence` of `size_t`,
// `absl::index_sequence` is designed to be a drop-in replacement for C++14's
// `std::index_sequence`.
template <size_t... Ints>
using index_sequence = integer_sequence<size_t, Ints...>;
template<std::size_t... I1, std::size_t... I2> namespace utility_internal
struct merge_and_renumber<index_sequence<I1...>, index_sequence<I2...>> {
: index_sequence < I1..., (sizeof...(I1) + I2)... > {};
template<std::size_t N> template <typename Seq, size_t SeqSize, size_t Rem>
struct make_index_sequence struct Extend;
: merge_and_renumber < typename make_index_sequence < N / 2 >::type,
typename make_index_sequence < N - N / 2 >::type > {};
template<> struct make_index_sequence<0> : index_sequence<> {}; // Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency.
template<> struct make_index_sequence<1> : index_sequence<0> {}; template <typename T, T... Ints, size_t SeqSize>
struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
{
using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
};
template<typename... Ts> template <typename T, T... Ints, size_t SeqSize>
struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
{
using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
};
// Recursion helper for 'make_integer_sequence<T, N>'.
// 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'.
template <typename T, size_t N>
struct Gen
{
using type =
typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
};
template <typename T>
struct Gen<T, 0>
{
using type = integer_sequence<T>;
};
} // namespace utility_internal
// Compile-time sequences of integers
// make_integer_sequence
//
// This template alias is equivalent to
// `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in
// replacement for C++14's `std::make_integer_sequence`.
template <typename T, T N>
using make_integer_sequence = typename utility_internal::Gen<T, N>::type;
// make_index_sequence
//
// This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`,
// and is designed to be a drop-in replacement for C++14's
// `std::make_index_sequence`.
template <size_t N>
using make_index_sequence = make_integer_sequence<size_t, N>;
// index_sequence_for
//
// Converts a typename pack into an index sequence of the same length, and
// is designed to be a drop-in replacement for C++14's
// `std::index_sequence_for()`
template <typename... Ts>
using index_sequence_for = make_index_sequence<sizeof...(Ts)>; using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
//// END OF CODE FROM GOOGLE ABSEIL
#endif
// dispatch utility (taken from ranges-v3) // dispatch utility (taken from ranges-v3)
template<unsigned N> struct priority_tag : priority_tag < N - 1 > {}; template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
template<> struct priority_tag<0> {}; template<> struct priority_tag<0> {};
@ -53,10 +153,19 @@ template<> struct priority_tag<0> {};
template<typename T> template<typename T>
struct static_const struct static_const
{ {
static constexpr T value{}; static JSON_INLINE_VARIABLE constexpr T value{};
}; };
template<typename T> #ifndef JSON_HAS_CPP_17
constexpr T static_const<T>::value; template<typename T>
constexpr T static_const<T>::value;
#endif
template<typename T, typename... Args>
inline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)
{
return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}};
}
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,14 +1,22 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <type_traits> #include <type_traits>
#include <nlohmann/detail/meta/void_t.hpp> #include <nlohmann/detail/meta/void_t.hpp>
// https://en.cppreference.com/w/cpp/experimental/is_detected NLOHMANN_JSON_NAMESPACE_BEGIN
namespace nlohmann
{
namespace detail namespace detail
{ {
// https://en.cppreference.com/w/cpp/experimental/is_detected
struct nonesuch struct nonesuch
{ {
nonesuch() = delete; nonesuch() = delete;
@ -39,6 +47,9 @@ struct detector<Default, void_t<Op<Args...>>, Op, Args...>
template<template<class...> class Op, class... Args> template<template<class...> class Op, class... Args>
using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t; using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
template<template<class...> class Op, class... Args>
struct is_detected_lazy : is_detected<Op, Args...> { };
template<template<class...> class Op, class... Args> template<template<class...> class Op, class... Args>
using detected_t = typename detector<nonesuch, void, Op, Args...>::type; using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
@ -54,5 +65,6 @@ using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
template<class To, template<class...> class Op, class... Args> template<class To, template<class...> class Op, class... Args>
using is_detected_convertible = using is_detected_convertible =
std::is_convertible<detected_t<Op, Args...>, To>; std::is_convertible<detected_t<Op, Args...>, To>;
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -0,0 +1,21 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once
#include <nlohmann/detail/abi_macros.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
// dispatching helper struct
template <class T> struct identity_tag {};
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,16 +1,25 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <cstdint> // size_t #include <cstdint> // size_t
#include <utility> // declval #include <utility> // declval
#include <string> // string #include <string> // string
#include <nlohmann/detail/abi_macros.hpp>
#include <nlohmann/detail/meta/detected.hpp> #include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/detail/meta/type_traits.hpp> #include <nlohmann/detail/meta/type_traits.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
template<typename T> template<typename T>
using null_function_t = decltype(std::declval<T&>().null()); using null_function_t = decltype(std::declval<T&>().null());
@ -145,5 +154,6 @@ struct is_sax_static_asserts
"Missing/invalid function: bool parse_error(std::size_t, const " "Missing/invalid function: bool parse_error(std::size_t, const "
"std::string&, const exception&)"); "std::string&, const exception&)");
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -0,0 +1,29 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once
#include <nlohmann/detail/macro_scope.hpp>
#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
#include <experimental/filesystem>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
namespace std_fs = std::experimental::filesystem;
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END
#elif JSON_HAS_FILESYSTEM
#include <filesystem>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
namespace std_fs = std::filesystem;
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END
#endif

View File

@ -1,17 +1,27 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <limits> // numeric_limits #include <limits> // numeric_limits
#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type #include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
#include <utility> // declval #include <utility> // declval
#include <tuple> // tuple
#include <nlohmann/detail/iterators/iterator_traits.hpp> #include <nlohmann/detail/iterators/iterator_traits.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/call_std/begin.hpp>
#include <nlohmann/detail/meta/call_std/end.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp> #include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/detected.hpp> #include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/json_fwd.hpp> #include <nlohmann/json_fwd.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
/*! /*!
@brief detail namespace with internal helper functions @brief detail namespace with internal helper functions
@ -22,6 +32,7 @@ implementations of some @ref basic_json methods, and meta-programming helpers.
*/ */
namespace detail namespace detail
{ {
///////////// /////////////
// helpers // // helpers //
///////////// /////////////
@ -40,6 +51,16 @@ template<typename> struct is_basic_json : std::false_type {};
NLOHMANN_BASIC_JSON_TPL_DECLARATION NLOHMANN_BASIC_JSON_TPL_DECLARATION
struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {}; struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
// used by exceptions create() member functions
// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t
// false_type otherwise
template<typename BasicJsonContext>
struct is_basic_json_context :
std::integral_constant < bool,
is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
|| std::is_same<BasicJsonContext, std::nullptr_t>::value >
{};
////////////////////// //////////////////////
// json_ref helpers // // json_ref helpers //
////////////////////// //////////////////////
@ -78,9 +99,6 @@ using reference_t = typename T::reference;
template<typename T> template<typename T>
using iterator_category_t = typename T::iterator_category; using iterator_category_t = typename T::iterator_category;
template<typename T>
using iterator_t = typename T::iterator;
template<typename T, typename... Args> template<typename T, typename... Args>
using to_json_function = decltype(T::to_json(std::declval<Args>()...)); using to_json_function = decltype(T::to_json(std::declval<Args>()...));
@ -105,8 +123,7 @@ struct is_getable
}; };
template<typename BasicJsonType, typename T> template<typename BasicJsonType, typename T>
struct has_from_json < BasicJsonType, T, struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
enable_if_t < !is_basic_json<T>::value >>
{ {
using serializer = typename BasicJsonType::template json_serializer<T, void>; using serializer = typename BasicJsonType::template json_serializer<T, void>;
@ -145,11 +162,78 @@ struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
T>::value; T>::value;
}; };
template<typename T>
using detect_key_compare = typename T::key_compare;
template<typename T>
struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};
// obtains the actual object key comparator
template<typename BasicJsonType>
struct actual_object_comparator
{
using object_t = typename BasicJsonType::object_t;
using object_comparator_t = typename BasicJsonType::default_object_comparator_t;
using type = typename std::conditional < has_key_compare<object_t>::value,
typename object_t::key_compare, object_comparator_t>::type;
};
template<typename BasicJsonType>
using actual_object_comparator_t = typename actual_object_comparator<BasicJsonType>::type;
/////////////////// ///////////////////
// is_ functions // // is_ functions //
/////////////////// ///////////////////
// https://en.cppreference.com/w/cpp/types/conjunction
template<class...> struct conjunction : std::true_type { };
template<class B> struct conjunction<B> : B { };
template<class B, class... Bn>
struct conjunction<B, Bn...>
: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
// https://en.cppreference.com/w/cpp/types/negation
template<class B> struct negation : std::integral_constant < bool, !B::value > { };
// Reimplementation of is_constructible and is_default_constructible, due to them being broken for
// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367).
// This causes compile errors in e.g. clang 3.5 or gcc 4.9.
template <typename T>
struct is_default_constructible : std::is_default_constructible<T> {};
template <typename T1, typename T2>
struct is_default_constructible<std::pair<T1, T2>>
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
template <typename T1, typename T2>
struct is_default_constructible<const std::pair<T1, T2>>
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
template <typename... Ts>
struct is_default_constructible<std::tuple<Ts...>>
: conjunction<is_default_constructible<Ts>...> {};
template <typename... Ts>
struct is_default_constructible<const std::tuple<Ts...>>
: conjunction<is_default_constructible<Ts>...> {};
template <typename T, typename... Args>
struct is_constructible : std::is_constructible<T, Args...> {};
template <typename T1, typename T2>
struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {};
template <typename T1, typename T2>
struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {};
template <typename... Ts>
struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {};
template <typename... Ts>
struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {};
template<typename T, typename = void> template<typename T, typename = void>
struct is_iterator_traits : std::false_type {}; struct is_iterator_traits : std::false_type {};
@ -168,7 +252,34 @@ struct is_iterator_traits<iterator_traits<T>>
is_detected<reference_t, traits>::value; is_detected<reference_t, traits>::value;
}; };
// source: https://stackoverflow.com/a/37193089/4116453 template<typename T>
struct is_range
{
private:
using t_ref = typename std::add_lvalue_reference<T>::type;
using iterator = detected_t<result_of_begin, t_ref>;
using sentinel = detected_t<result_of_end, t_ref>;
// to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator
// and https://en.cppreference.com/w/cpp/iterator/sentinel_for
// but reimplementing these would be too much work, as a lot of other concepts are used underneath
static constexpr auto is_iterator_begin =
is_iterator_traits<iterator_traits<iterator>>::value;
public:
static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
};
template<typename R>
using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
template<typename T>
using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
// The following implementation of is_complete_type is taken from
// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/
// and is written by Xiang Fan who agreed to using it in this library.
template<typename T, typename = void> template<typename T, typename = void>
struct is_complete_type : std::false_type {}; struct is_complete_type : std::false_type {};
@ -186,14 +297,13 @@ struct is_compatible_object_type_impl <
enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&& enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
is_detected<key_type_t, CompatibleObjectType>::value >> is_detected<key_type_t, CompatibleObjectType>::value >>
{ {
using object_t = typename BasicJsonType::object_t; using object_t = typename BasicJsonType::object_t;
// macOS's is_constructible does not play well with nonesuch... // macOS's is_constructible does not play well with nonesuch...
static constexpr bool value = static constexpr bool value =
std::is_constructible<typename object_t::key_type, is_constructible<typename object_t::key_type,
typename CompatibleObjectType::key_type>::value && typename CompatibleObjectType::key_type>::value &&
std::is_constructible<typename object_t::mapped_type, is_constructible<typename object_t::mapped_type,
typename CompatibleObjectType::mapped_type>::value; typename CompatibleObjectType::mapped_type>::value;
}; };
@ -214,10 +324,10 @@ struct is_constructible_object_type_impl <
using object_t = typename BasicJsonType::object_t; using object_t = typename BasicJsonType::object_t;
static constexpr bool value = static constexpr bool value =
(std::is_default_constructible<ConstructibleObjectType>::value && (is_default_constructible<ConstructibleObjectType>::value &&
(std::is_move_assignable<ConstructibleObjectType>::value || (std::is_move_assignable<ConstructibleObjectType>::value ||
std::is_copy_assignable<ConstructibleObjectType>::value) && std::is_copy_assignable<ConstructibleObjectType>::value) &&
(std::is_constructible<typename ConstructibleObjectType::key_type, (is_constructible<typename ConstructibleObjectType::key_type,
typename object_t::key_type>::value && typename object_t::key_type>::value &&
std::is_same < std::is_same <
typename object_t::mapped_type, typename object_t::mapped_type,
@ -234,42 +344,29 @@ struct is_constructible_object_type
: is_constructible_object_type_impl<BasicJsonType, : is_constructible_object_type_impl<BasicJsonType,
ConstructibleObjectType> {}; ConstructibleObjectType> {};
template<typename BasicJsonType, typename CompatibleStringType,
typename = void>
struct is_compatible_string_type_impl : std::false_type {};
template<typename BasicJsonType, typename CompatibleStringType> template<typename BasicJsonType, typename CompatibleStringType>
struct is_compatible_string_type_impl <
BasicJsonType, CompatibleStringType,
enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
value_type_t, CompatibleStringType>::value >>
{
static constexpr auto value =
std::is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
};
template<typename BasicJsonType, typename ConstructibleStringType>
struct is_compatible_string_type struct is_compatible_string_type
: is_compatible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
template<typename BasicJsonType, typename ConstructibleStringType,
typename = void>
struct is_constructible_string_type_impl : std::false_type {};
template<typename BasicJsonType, typename ConstructibleStringType>
struct is_constructible_string_type_impl <
BasicJsonType, ConstructibleStringType,
enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
value_type_t, ConstructibleStringType>::value >>
{ {
static constexpr auto value = static constexpr auto value =
std::is_constructible<ConstructibleStringType, is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
typename BasicJsonType::string_t>::value;
}; };
template<typename BasicJsonType, typename ConstructibleStringType> template<typename BasicJsonType, typename ConstructibleStringType>
struct is_constructible_string_type struct is_constructible_string_type
: is_constructible_string_type_impl<BasicJsonType, ConstructibleStringType> {}; {
// launder type through decltype() to fix compilation failure on ICPC
#ifdef __INTEL_COMPILER
using laundered_type = decltype(std::declval<ConstructibleStringType>());
#else
using laundered_type = ConstructibleStringType;
#endif
static constexpr auto value =
conjunction <
is_constructible<laundered_type, typename BasicJsonType::string_t>,
is_detected_exact<typename BasicJsonType::string_t::value_type,
value_type_t, laundered_type >>::value;
};
template<typename BasicJsonType, typename CompatibleArrayType, typename = void> template<typename BasicJsonType, typename CompatibleArrayType, typename = void>
struct is_compatible_array_type_impl : std::false_type {}; struct is_compatible_array_type_impl : std::false_type {};
@ -277,17 +374,16 @@ struct is_compatible_array_type_impl : std::false_type {};
template<typename BasicJsonType, typename CompatibleArrayType> template<typename BasicJsonType, typename CompatibleArrayType>
struct is_compatible_array_type_impl < struct is_compatible_array_type_impl <
BasicJsonType, CompatibleArrayType, BasicJsonType, CompatibleArrayType,
enable_if_t < is_detected<value_type_t, CompatibleArrayType>::value&& enable_if_t <
is_detected<iterator_t, CompatibleArrayType>::value&& is_detected<iterator_t, CompatibleArrayType>::value&&
// This is needed because json_reverse_iterator has a ::iterator type... is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&&
// Therefore it is detected as a CompatibleArrayType. // special case for types like std::filesystem::path whose iterator's value_type are themselves
// The real fix would be to have an Iterable concept. // c.f. https://github.com/nlohmann/json/pull/3073
!is_iterator_traits < !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >>
iterator_traits<CompatibleArrayType >>::value >>
{ {
static constexpr bool value = static constexpr bool value =
std::is_constructible<BasicJsonType, is_constructible<BasicJsonType,
typename CompatibleArrayType::value_type>::value; range_value_t<CompatibleArrayType>>::value;
}; };
template<typename BasicJsonType, typename CompatibleArrayType> template<typename BasicJsonType, typename CompatibleArrayType>
@ -309,28 +405,29 @@ struct is_constructible_array_type_impl <
BasicJsonType, ConstructibleArrayType, BasicJsonType, ConstructibleArrayType,
enable_if_t < !std::is_same<ConstructibleArrayType, enable_if_t < !std::is_same<ConstructibleArrayType,
typename BasicJsonType::value_type>::value&& typename BasicJsonType::value_type>::value&&
std::is_default_constructible<ConstructibleArrayType>::value&& !is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
is_default_constructible<ConstructibleArrayType>::value&&
(std::is_move_assignable<ConstructibleArrayType>::value || (std::is_move_assignable<ConstructibleArrayType>::value ||
std::is_copy_assignable<ConstructibleArrayType>::value)&& std::is_copy_assignable<ConstructibleArrayType>::value)&&
is_detected<value_type_t, ConstructibleArrayType>::value&&
is_detected<iterator_t, ConstructibleArrayType>::value&& is_detected<iterator_t, ConstructibleArrayType>::value&&
is_complete_type < is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&
detected_t<value_type_t, ConstructibleArrayType >>::value >> is_detected<range_value_t, ConstructibleArrayType>::value&&
// special case for types like std::filesystem::path whose iterator's value_type are themselves
// c.f. https://github.com/nlohmann/json/pull/3073
!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&&
is_complete_type <
detected_t<range_value_t, ConstructibleArrayType >>::value >>
{ {
static constexpr bool value = using value_type = range_value_t<ConstructibleArrayType>;
// This is needed because json_reverse_iterator has a ::iterator type,
// furthermore, std::back_insert_iterator (and other iterators) have a
// base class `iterator`... Therefore it is detected as a
// ConstructibleArrayType. The real fix would be to have an Iterable
// concept.
!is_iterator_traits<iterator_traits<ConstructibleArrayType>>::value &&
(std::is_same<typename ConstructibleArrayType::value_type, static constexpr bool value =
typename BasicJsonType::array_t::value_type>::value || std::is_same<value_type,
has_from_json<BasicJsonType, typename BasicJsonType::array_t::value_type>::value ||
typename ConstructibleArrayType::value_type>::value || has_from_json<BasicJsonType,
has_non_default_from_json < value_type>::value ||
BasicJsonType, typename ConstructibleArrayType::value_type >::value); has_non_default_from_json <
BasicJsonType,
value_type >::value;
}; };
template<typename BasicJsonType, typename ConstructibleArrayType> template<typename BasicJsonType, typename ConstructibleArrayType>
@ -353,7 +450,7 @@ struct is_compatible_integer_type_impl <
using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>; using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
static constexpr auto value = static constexpr auto value =
std::is_constructible<RealIntegerType, is_constructible<RealIntegerType,
CompatibleNumberIntegerType>::value && CompatibleNumberIntegerType>::value &&
CompatibleLimits::is_integer && CompatibleLimits::is_integer &&
RealLimits::is_signed == CompatibleLimits::is_signed; RealLimits::is_signed == CompatibleLimits::is_signed;
@ -380,17 +477,264 @@ template<typename BasicJsonType, typename CompatibleType>
struct is_compatible_type struct is_compatible_type
: is_compatible_type_impl<BasicJsonType, CompatibleType> {}; : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
// https://en.cppreference.com/w/cpp/types/conjunction
template<class...> struct conjunction : std::true_type { };
template<class B1> struct conjunction<B1> : B1 { };
template<class B1, class... Bn>
struct conjunction<B1, Bn...>
: std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
template<typename T1, typename T2> template<typename T1, typename T2>
struct is_constructible_tuple : std::false_type {}; struct is_constructible_tuple : std::false_type {};
template<typename T1, typename... Args> template<typename T1, typename... Args>
struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<std::is_constructible<T1, Args>...> {}; struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
template<typename BasicJsonType, typename T>
struct is_json_iterator_of : std::false_type {};
template<typename BasicJsonType>
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : std::true_type {};
template<typename BasicJsonType>
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type
{};
// checks if a given type T is a template specialization of Primary
template<template <typename...> class Primary, typename T>
struct is_specialization_of : std::false_type {};
template<template <typename...> class Primary, typename... Args>
struct is_specialization_of<Primary, Primary<Args...>> : std::true_type {};
template<typename T>
using is_json_pointer = is_specialization_of<::nlohmann::json_pointer, uncvref_t<T>>;
// checks if A and B are comparable using Compare functor
template<typename Compare, typename A, typename B, typename = void>
struct is_comparable : std::false_type {};
template<typename Compare, typename A, typename B>
struct is_comparable<Compare, A, B, void_t<
decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
>> : std::true_type {};
template<typename T>
using detect_is_transparent = typename T::is_transparent;
// type trait to check if KeyType can be used as object key (without a BasicJsonType)
// see is_usable_as_basic_json_key_type below
template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true,
bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
using is_usable_as_key_type = typename std::conditional <
is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value
&& !(ExcludeObjectKeyType && std::is_same<KeyType,
ObjectKeyType>::value)
&& (!RequireTransparentComparator
|| is_detected <detect_is_transparent, Comparator>::value)
&& !is_json_pointer<KeyType>::value,
std::true_type,
std::false_type >::type;
// type trait to check if KeyType can be used as object key
// true if:
// - KeyType is comparable with BasicJsonType::object_t::key_type
// - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type
// - the comparator is transparent or RequireTransparentComparator is false
// - KeyType is not a JSON iterator or json_pointer
template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true,
bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
using is_usable_as_basic_json_key_type = typename std::conditional <
is_usable_as_key_type<typename BasicJsonType::object_comparator_t,
typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
RequireTransparentComparator, ExcludeObjectKeyType>::value
&& !is_json_iterator_of<BasicJsonType, KeyType>::value,
std::true_type,
std::false_type >::type;
template<typename ObjectType, typename KeyType>
using detect_erase_with_key_type = decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));
// type trait to check if object_t has an erase() member functions accepting KeyType
template<typename BasicJsonType, typename KeyType>
using has_erase_with_key_type = typename std::conditional <
is_detected <
detect_erase_with_key_type,
typename BasicJsonType::object_t, KeyType >::value,
std::true_type,
std::false_type >::type;
// a naive helper to check if a type is an ordered_map (exploits the fact that
// ordered_map inherits capacity() from std::vector)
template <typename T>
struct is_ordered_map
{
using one = char;
struct two
{
char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
};
template <typename C> static one test( decltype(&C::capacity) ) ;
template <typename C> static two test(...);
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
};
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 >
T conditional_static_cast(U value)
{
return static_cast<T>(value);
}
template<typename T, typename U, enable_if_t<std::is_same<T, U>::value, int> = 0>
T conditional_static_cast(U value)
{
return value;
}
template<typename... Types>
using all_integral = conjunction<std::is_integral<Types>...>;
template<typename... Types>
using all_signed = conjunction<std::is_signed<Types>...>;
template<typename... Types>
using all_unsigned = conjunction<std::is_unsigned<Types>...>;
// there's a disjunction trait in another PR; replace when merged
template<typename... Types>
using same_sign = std::integral_constant < bool,
all_signed<Types...>::value || all_unsigned<Types...>::value >;
template<typename OfType, typename T>
using never_out_of_range = std::integral_constant < bool,
(std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType)))
|| (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T)) >;
template<typename OfType, typename T,
bool OfTypeSigned = std::is_signed<OfType>::value,
bool TSigned = std::is_signed<T>::value>
struct value_in_range_of_impl2;
template<typename OfType, typename T>
struct value_in_range_of_impl2<OfType, T, false, false>
{
static constexpr bool test(T val)
{
using CommonType = typename std::common_type<OfType, T>::type;
return static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
}
};
template<typename OfType, typename T>
struct value_in_range_of_impl2<OfType, T, true, false>
{
static constexpr bool test(T val)
{
using CommonType = typename std::common_type<OfType, T>::type;
return static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
}
};
template<typename OfType, typename T>
struct value_in_range_of_impl2<OfType, T, false, true>
{
static constexpr bool test(T val)
{
using CommonType = typename std::common_type<OfType, T>::type;
return val >= 0 && static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
}
};
template<typename OfType, typename T>
struct value_in_range_of_impl2<OfType, T, true, true>
{
static constexpr bool test(T val)
{
using CommonType = typename std::common_type<OfType, T>::type;
return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)())
&& static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
}
};
template<typename OfType, typename T,
bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
typename = detail::enable_if_t<all_integral<OfType, T>::value>>
struct value_in_range_of_impl1;
template<typename OfType, typename T>
struct value_in_range_of_impl1<OfType, T, false>
{
static constexpr bool test(T val)
{
return value_in_range_of_impl2<OfType, T>::test(val);
}
};
template<typename OfType, typename T>
struct value_in_range_of_impl1<OfType, T, true>
{
static constexpr bool test(T /*val*/)
{
return true;
}
};
template<typename OfType, typename T>
inline constexpr bool value_in_range_of(T val)
{
return value_in_range_of_impl1<OfType, T>::test(val);
}
template<bool Value>
using bool_constant = std::integral_constant<bool, Value>;
///////////////////////////////////////////////////////////////////////////////
// is_c_string
///////////////////////////////////////////////////////////////////////////////
namespace impl
{
template<typename T>
inline constexpr bool is_c_string()
{
using TUnExt = typename std::remove_extent<T>::type;
using TUnCVExt = typename std::remove_cv<TUnExt>::type;
using TUnPtr = typename std::remove_pointer<T>::type;
using TUnCVPtr = typename std::remove_cv<TUnPtr>::type;
return
(std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
|| (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
}
} // namespace impl
// checks whether T is a [cv] char */[cv] char[] C string
template<typename T>
struct is_c_string : bool_constant<impl::is_c_string<T>()> {};
template<typename T>
using is_c_string_uncvref = is_c_string<uncvref_t<T>>;
///////////////////////////////////////////////////////////////////////////////
// is_transparent
///////////////////////////////////////////////////////////////////////////////
namespace impl
{
template<typename T>
inline constexpr bool is_transparent()
{
return is_detected<detect_is_transparent, T>::value;
}
} // namespace impl
// checks whether T has a member named is_transparent
template<typename T>
struct is_transparent : bool_constant<impl::is_transparent<T>()> {};
///////////////////////////////////////////////////////////////////////////////
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,13 +1,24 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
namespace nlohmann #include <nlohmann/detail/abi_macros.hpp>
{
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail namespace detail
{ {
template<typename ...Ts> struct make_void template<typename ...Ts> struct make_void
{ {
using type = void; using type = void;
}; };
template<typename ...Ts> using void_t = typename make_void<Ts...>::type; template<typename ...Ts> using void_t = typename make_void<Ts...>::type;
} // namespace detail
} // namespace nlohmann } // namespace detail
NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,21 +1,33 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <algorithm> // reverse #include <algorithm> // reverse
#include <array> // array #include <array> // array
#include <map> // map
#include <cmath> // isnan, isinf
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t #include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
#include <cstring> // memcpy #include <cstring> // memcpy
#include <limits> // numeric_limits #include <limits> // numeric_limits
#include <string> // string #include <string> // string
#include <cmath> // isnan, isinf #include <utility> // move
#include <vector> // vector
#include <nlohmann/detail/input/binary_reader.hpp> #include <nlohmann/detail/input/binary_reader.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/output/output_adapters.hpp> #include <nlohmann/detail/output/output_adapters.hpp>
#include <nlohmann/detail/string_concat.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
/////////////////// ///////////////////
// binary writer // // binary writer //
/////////////////// ///////////////////
@ -36,7 +48,7 @@ class binary_writer
@param[in] adapter output adapter to write to @param[in] adapter output adapter to write to
*/ */
explicit binary_writer(output_adapter_t<CharType> adapter) : oa(adapter) explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
{ {
JSON_ASSERT(oa); JSON_ASSERT(oa);
} }
@ -55,9 +67,18 @@ class binary_writer
break; break;
} }
case value_t::null:
case value_t::array:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
case value_t::discarded:
default: default:
{ {
JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()))); JSON_THROW(type_error::create(317, concat("to serialize to BSON, top-level type must be object, but is ", j.type_name()), &j));
} }
} }
} }
@ -281,8 +302,26 @@ class binary_writer
{ {
if (j.m_value.binary->has_subtype()) if (j.m_value.binary->has_subtype())
{ {
write_number(static_cast<std::uint8_t>(0xd8)); if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
write_number(j.m_value.binary->subtype()); {
write_number(static_cast<std::uint8_t>(0xd8));
write_number(static_cast<std::uint8_t>(j.m_value.binary->subtype()));
}
else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
{
write_number(static_cast<std::uint8_t>(0xd9));
write_number(static_cast<std::uint16_t>(j.m_value.binary->subtype()));
}
else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
{
write_number(static_cast<std::uint8_t>(0xda));
write_number(static_cast<std::uint32_t>(j.m_value.binary->subtype()));
}
else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
{
write_number(static_cast<std::uint8_t>(0xdb));
write_number(static_cast<std::uint64_t>(j.m_value.binary->subtype()));
}
} }
// step 1: write control byte and the binary array size // step 1: write control byte and the binary array size
@ -362,6 +401,7 @@ class binary_writer
break; break;
} }
case value_t::discarded:
default: default:
break; break;
} }
@ -683,6 +723,7 @@ class binary_writer
break; break;
} }
case value_t::discarded:
default: default:
break; break;
} }
@ -693,9 +734,11 @@ class binary_writer
@param[in] use_count whether to use '#' prefixes (optimized format) @param[in] use_count whether to use '#' prefixes (optimized format)
@param[in] use_type whether to use '$' prefixes (optimized format) @param[in] use_type whether to use '$' prefixes (optimized format)
@param[in] add_prefix whether prefixes need to be used for this value @param[in] add_prefix whether prefixes need to be used for this value
@param[in] use_bjdata whether write in BJData format, default is false
*/ */
void write_ubjson(const BasicJsonType& j, const bool use_count, void write_ubjson(const BasicJsonType& j, const bool use_count,
const bool use_type, const bool add_prefix = true) const bool use_type, const bool add_prefix = true,
const bool use_bjdata = false)
{ {
switch (j.type()) switch (j.type())
{ {
@ -721,19 +764,19 @@ class binary_writer
case value_t::number_integer: case value_t::number_integer:
{ {
write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix); write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix, use_bjdata);
break; break;
} }
case value_t::number_unsigned: case value_t::number_unsigned:
{ {
write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix); write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix, use_bjdata);
break; break;
} }
case value_t::number_float: case value_t::number_float:
{ {
write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix); write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix, use_bjdata);
break; break;
} }
@ -743,7 +786,7 @@ class binary_writer
{ {
oa->write_character(to_char_type('S')); oa->write_character(to_char_type('S'));
} }
write_number_with_ubjson_prefix(j.m_value.string->size(), true); write_number_with_ubjson_prefix(j.m_value.string->size(), true, use_bjdata);
oa->write_characters( oa->write_characters(
reinterpret_cast<const CharType*>(j.m_value.string->c_str()), reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
j.m_value.string->size()); j.m_value.string->size());
@ -761,14 +804,16 @@ class binary_writer
if (use_type && !j.m_value.array->empty()) if (use_type && !j.m_value.array->empty())
{ {
JSON_ASSERT(use_count); JSON_ASSERT(use_count);
const CharType first_prefix = ubjson_prefix(j.front()); const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
const bool same_prefix = std::all_of(j.begin() + 1, j.end(), const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
[this, first_prefix](const BasicJsonType & v) [this, first_prefix, use_bjdata](const BasicJsonType & v)
{ {
return ubjson_prefix(v) == first_prefix; return ubjson_prefix(v, use_bjdata) == first_prefix;
}); });
if (same_prefix) std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type
if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
{ {
prefix_required = false; prefix_required = false;
oa->write_character(to_char_type('$')); oa->write_character(to_char_type('$'));
@ -779,12 +824,12 @@ class binary_writer
if (use_count) if (use_count)
{ {
oa->write_character(to_char_type('#')); oa->write_character(to_char_type('#'));
write_number_with_ubjson_prefix(j.m_value.array->size(), true); write_number_with_ubjson_prefix(j.m_value.array->size(), true, use_bjdata);
} }
for (const auto& el : *j.m_value.array) for (const auto& el : *j.m_value.array)
{ {
write_ubjson(el, use_count, use_type, prefix_required); write_ubjson(el, use_count, use_type, prefix_required, use_bjdata);
} }
if (!use_count) if (!use_count)
@ -812,7 +857,7 @@ class binary_writer
if (use_count) if (use_count)
{ {
oa->write_character(to_char_type('#')); oa->write_character(to_char_type('#'));
write_number_with_ubjson_prefix(j.m_value.binary->size(), true); write_number_with_ubjson_prefix(j.m_value.binary->size(), true, use_bjdata);
} }
if (use_type) if (use_type)
@ -840,6 +885,14 @@ class binary_writer
case value_t::object: case value_t::object:
{ {
if (use_bjdata && j.m_value.object->size() == 3 && j.m_value.object->find("_ArrayType_") != j.m_value.object->end() && j.m_value.object->find("_ArraySize_") != j.m_value.object->end() && j.m_value.object->find("_ArrayData_") != j.m_value.object->end())
{
if (!write_bjdata_ndarray(*j.m_value.object, use_count, use_type)) // decode bjdata ndarray in the JData format (https://github.com/NeuroJSON/jdata)
{
break;
}
}
if (add_prefix) if (add_prefix)
{ {
oa->write_character(to_char_type('{')); oa->write_character(to_char_type('{'));
@ -849,14 +902,16 @@ class binary_writer
if (use_type && !j.m_value.object->empty()) if (use_type && !j.m_value.object->empty())
{ {
JSON_ASSERT(use_count); JSON_ASSERT(use_count);
const CharType first_prefix = ubjson_prefix(j.front()); const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
const bool same_prefix = std::all_of(j.begin(), j.end(), const bool same_prefix = std::all_of(j.begin(), j.end(),
[this, first_prefix](const BasicJsonType & v) [this, first_prefix, use_bjdata](const BasicJsonType & v)
{ {
return ubjson_prefix(v) == first_prefix; return ubjson_prefix(v, use_bjdata) == first_prefix;
}); });
if (same_prefix) std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type
if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
{ {
prefix_required = false; prefix_required = false;
oa->write_character(to_char_type('$')); oa->write_character(to_char_type('$'));
@ -867,16 +922,16 @@ class binary_writer
if (use_count) if (use_count)
{ {
oa->write_character(to_char_type('#')); oa->write_character(to_char_type('#'));
write_number_with_ubjson_prefix(j.m_value.object->size(), true); write_number_with_ubjson_prefix(j.m_value.object->size(), true, use_bjdata);
} }
for (const auto& el : *j.m_value.object) for (const auto& el : *j.m_value.object)
{ {
write_number_with_ubjson_prefix(el.first.size(), true); write_number_with_ubjson_prefix(el.first.size(), true, use_bjdata);
oa->write_characters( oa->write_characters(
reinterpret_cast<const CharType*>(el.first.c_str()), reinterpret_cast<const CharType*>(el.first.c_str()),
el.first.size()); el.first.size());
write_ubjson(el.second, use_count, use_type, prefix_required); write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata);
} }
if (!use_count) if (!use_count)
@ -887,6 +942,7 @@ class binary_writer
break; break;
} }
case value_t::discarded:
default: default:
break; break;
} }
@ -901,13 +957,13 @@ class binary_writer
@return The size of a BSON document entry header, including the id marker @return The size of a BSON document entry header, including the id marker
and the entry name size (and its null-terminator). and the entry name size (and its null-terminator).
*/ */
static std::size_t calc_bson_entry_header_size(const string_t& name) static std::size_t calc_bson_entry_header_size(const string_t& name, const BasicJsonType& j)
{ {
const auto it = name.find(static_cast<typename string_t::value_type>(0)); const auto it = name.find(static_cast<typename string_t::value_type>(0));
if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos)) if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
{ {
JSON_THROW(out_of_range::create(409, JSON_THROW(out_of_range::create(409, concat("BSON key cannot contain code point U+0000 (at byte ", std::to_string(it), ")"), &j));
"BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")")); static_cast<void>(j);
} }
return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; return /*id*/ 1ul + name.size() + /*zero-terminator*/1u;
@ -942,7 +998,7 @@ class binary_writer
const double value) const double value)
{ {
write_bson_entry_header(name, 0x01); write_bson_entry_header(name, 0x01);
write_number<double, true>(value); write_number<double>(value, true);
} }
/*! /*!
@ -961,7 +1017,7 @@ class binary_writer
{ {
write_bson_entry_header(name, 0x02); write_bson_entry_header(name, 0x02);
write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size() + 1ul)); write_number<std::int32_t>(static_cast<std::int32_t>(value.size() + 1ul), true);
oa->write_characters( oa->write_characters(
reinterpret_cast<const CharType*>(value.c_str()), reinterpret_cast<const CharType*>(value.c_str()),
value.size() + 1); value.size() + 1);
@ -994,12 +1050,12 @@ class binary_writer
if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()) if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
{ {
write_bson_entry_header(name, 0x10); // int32 write_bson_entry_header(name, 0x10); // int32
write_number<std::int32_t, true>(static_cast<std::int32_t>(value)); write_number<std::int32_t>(static_cast<std::int32_t>(value), true);
} }
else else
{ {
write_bson_entry_header(name, 0x12); // int64 write_bson_entry_header(name, 0x12); // int64
write_number<std::int64_t, true>(static_cast<std::int64_t>(value)); write_number<std::int64_t>(static_cast<std::int64_t>(value), true);
} }
} }
@ -1017,21 +1073,21 @@ class binary_writer
@brief Writes a BSON element with key @a name and unsigned @a value @brief Writes a BSON element with key @a name and unsigned @a value
*/ */
void write_bson_unsigned(const string_t& name, void write_bson_unsigned(const string_t& name,
const std::uint64_t value) const BasicJsonType& j)
{ {
if (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
{ {
write_bson_entry_header(name, 0x10 /* int32 */); write_bson_entry_header(name, 0x10 /* int32 */);
write_number<std::int32_t, true>(static_cast<std::int32_t>(value)); write_number<std::int32_t>(static_cast<std::int32_t>(j.m_value.number_unsigned), true);
} }
else if (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)())) else if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
{ {
write_bson_entry_header(name, 0x12 /* int64 */); write_bson_entry_header(name, 0x12 /* int64 */);
write_number<std::int64_t, true>(static_cast<std::int64_t>(value)); write_number<std::int64_t>(static_cast<std::int64_t>(j.m_value.number_unsigned), true);
} }
else else
{ {
JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(value) + " cannot be represented by BSON as it does not fit int64")); JSON_THROW(out_of_range::create(407, concat("integer number ", std::to_string(j.m_value.number_unsigned), " cannot be represented by BSON as it does not fit int64"), &j));
} }
} }
@ -1052,7 +1108,7 @@ class binary_writer
{ {
std::size_t array_index = 0ul; std::size_t array_index = 0ul;
const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), std::size_t(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el) const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast<std::size_t>(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el)
{ {
return result + calc_bson_element_size(std::to_string(array_index++), el); return result + calc_bson_element_size(std::to_string(array_index++), el);
}); });
@ -1075,7 +1131,7 @@ class binary_writer
const typename BasicJsonType::array_t& value) const typename BasicJsonType::array_t& value)
{ {
write_bson_entry_header(name, 0x04); // array write_bson_entry_header(name, 0x04); // array
write_number<std::int32_t, true>(static_cast<std::int32_t>(calc_bson_array_size(value))); write_number<std::int32_t>(static_cast<std::int32_t>(calc_bson_array_size(value)), true);
std::size_t array_index = 0ul; std::size_t array_index = 0ul;
@ -1095,8 +1151,8 @@ class binary_writer
{ {
write_bson_entry_header(name, 0x05); write_bson_entry_header(name, 0x05);
write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size())); write_number<std::int32_t>(static_cast<std::int32_t>(value.size()), true);
write_number(value.has_subtype() ? value.subtype() : std::uint8_t(0x00)); write_number(value.has_subtype() ? static_cast<std::uint8_t>(value.subtype()) : static_cast<std::uint8_t>(0x00));
oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size()); oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
} }
@ -1108,7 +1164,7 @@ class binary_writer
static std::size_t calc_bson_element_size(const string_t& name, static std::size_t calc_bson_element_size(const string_t& name,
const BasicJsonType& j) const BasicJsonType& j)
{ {
const auto header_size = calc_bson_entry_header_size(name); const auto header_size = calc_bson_entry_header_size(name, j);
switch (j.type()) switch (j.type())
{ {
case value_t::object: case value_t::object:
@ -1139,8 +1195,9 @@ class binary_writer
return header_size + 0ul; return header_size + 0ul;
// LCOV_EXCL_START // LCOV_EXCL_START
case value_t::discarded:
default: default:
JSON_ASSERT(false); JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
return 0ul; return 0ul;
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
} }
@ -1151,7 +1208,6 @@ class binary_writer
key @a name. key @a name.
@param name The name to associate with the JSON entity @a j within the @param name The name to associate with the JSON entity @a j within the
current BSON document current BSON document
@return The size of the BSON entry
*/ */
void write_bson_element(const string_t& name, void write_bson_element(const string_t& name,
const BasicJsonType& j) const BasicJsonType& j)
@ -1177,7 +1233,7 @@ class binary_writer
return write_bson_integer(name, j.m_value.number_integer); return write_bson_integer(name, j.m_value.number_integer);
case value_t::number_unsigned: case value_t::number_unsigned:
return write_bson_unsigned(name, j.m_value.number_unsigned); return write_bson_unsigned(name, j);
case value_t::string: case value_t::string:
return write_bson_string(name, *j.m_value.string); return write_bson_string(name, *j.m_value.string);
@ -1186,8 +1242,9 @@ class binary_writer
return write_bson_null(name); return write_bson_null(name);
// LCOV_EXCL_START // LCOV_EXCL_START
case value_t::discarded:
default: default:
JSON_ASSERT(false); JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert)
return; return;
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
} }
@ -1196,12 +1253,12 @@ class binary_writer
/*! /*!
@brief Calculates the size of the BSON serialization of the given @brief Calculates the size of the BSON serialization of the given
JSON-object @a j. JSON-object @a j.
@param[in] j JSON value to serialize @param[in] value JSON value to serialize
@pre j.type() == value_t::object @pre value.type() == value_t::object
*/ */
static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value) static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value)
{ {
std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0), std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0),
[](size_t result, const typename BasicJsonType::object_t::value_type & el) [](size_t result, const typename BasicJsonType::object_t::value_type & el)
{ {
return result += calc_bson_element_size(el.first, el.second); return result += calc_bson_element_size(el.first, el.second);
@ -1211,12 +1268,12 @@ class binary_writer
} }
/*! /*!
@param[in] j JSON value to serialize @param[in] value JSON value to serialize
@pre j.type() == value_t::object @pre value.type() == value_t::object
*/ */
void write_bson_object(const typename BasicJsonType::object_t& value) void write_bson_object(const typename BasicJsonType::object_t& value)
{ {
write_number<std::int32_t, true>(static_cast<std::int32_t>(calc_bson_object_size(value))); write_number<std::int32_t>(static_cast<std::int32_t>(calc_bson_object_size(value)), true);
for (const auto& el : value) for (const auto& el : value)
{ {
@ -1262,20 +1319,22 @@ class binary_writer
template<typename NumberType, typename std::enable_if< template<typename NumberType, typename std::enable_if<
std::is_floating_point<NumberType>::value, int>::type = 0> std::is_floating_point<NumberType>::value, int>::type = 0>
void write_number_with_ubjson_prefix(const NumberType n, void write_number_with_ubjson_prefix(const NumberType n,
const bool add_prefix) const bool add_prefix,
const bool use_bjdata)
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(get_ubjson_float_prefix(n)); oa->write_character(get_ubjson_float_prefix(n));
} }
write_number(n); write_number(n, use_bjdata);
} }
// UBJSON: write number (unsigned integer) // UBJSON: write number (unsigned integer)
template<typename NumberType, typename std::enable_if< template<typename NumberType, typename std::enable_if<
std::is_unsigned<NumberType>::value, int>::type = 0> std::is_unsigned<NumberType>::value, int>::type = 0>
void write_number_with_ubjson_prefix(const NumberType n, void write_number_with_ubjson_prefix(const NumberType n,
const bool add_prefix) const bool add_prefix,
const bool use_bjdata)
{ {
if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)())) if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
{ {
@ -1283,7 +1342,7 @@ class binary_writer
{ {
oa->write_character(to_char_type('i')); // int8 oa->write_character(to_char_type('i')); // int8
} }
write_number(static_cast<std::uint8_t>(n)); write_number(static_cast<std::uint8_t>(n), use_bjdata);
} }
else if (n <= (std::numeric_limits<std::uint8_t>::max)()) else if (n <= (std::numeric_limits<std::uint8_t>::max)())
{ {
@ -1291,7 +1350,7 @@ class binary_writer
{ {
oa->write_character(to_char_type('U')); // uint8 oa->write_character(to_char_type('U')); // uint8
} }
write_number(static_cast<std::uint8_t>(n)); write_number(static_cast<std::uint8_t>(n), use_bjdata);
} }
else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)())) else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
{ {
@ -1299,7 +1358,15 @@ class binary_writer
{ {
oa->write_character(to_char_type('I')); // int16 oa->write_character(to_char_type('I')); // int16
} }
write_number(static_cast<std::int16_t>(n)); write_number(static_cast<std::int16_t>(n), use_bjdata);
}
else if (use_bjdata && n <= static_cast<uint64_t>((std::numeric_limits<uint16_t>::max)()))
{
if (add_prefix)
{
oa->write_character(to_char_type('u')); // uint16 - bjdata only
}
write_number(static_cast<std::uint16_t>(n), use_bjdata);
} }
else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
{ {
@ -1307,7 +1374,15 @@ class binary_writer
{ {
oa->write_character(to_char_type('l')); // int32 oa->write_character(to_char_type('l')); // int32
} }
write_number(static_cast<std::int32_t>(n)); write_number(static_cast<std::int32_t>(n), use_bjdata);
}
else if (use_bjdata && n <= static_cast<uint64_t>((std::numeric_limits<uint32_t>::max)()))
{
if (add_prefix)
{
oa->write_character(to_char_type('m')); // uint32 - bjdata only
}
write_number(static_cast<std::uint32_t>(n), use_bjdata);
} }
else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)())) else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
{ {
@ -1315,7 +1390,15 @@ class binary_writer
{ {
oa->write_character(to_char_type('L')); // int64 oa->write_character(to_char_type('L')); // int64
} }
write_number(static_cast<std::int64_t>(n)); write_number(static_cast<std::int64_t>(n), use_bjdata);
}
else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)())
{
if (add_prefix)
{
oa->write_character(to_char_type('M')); // uint64 - bjdata only
}
write_number(static_cast<std::uint64_t>(n), use_bjdata);
} }
else else
{ {
@ -1325,7 +1408,7 @@ class binary_writer
} }
const auto number = BasicJsonType(n).dump(); const auto number = BasicJsonType(n).dump();
write_number_with_ubjson_prefix(number.size(), true); write_number_with_ubjson_prefix(number.size(), true, use_bjdata);
for (std::size_t i = 0; i < number.size(); ++i) for (std::size_t i = 0; i < number.size(); ++i)
{ {
oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i]))); oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i])));
@ -1338,7 +1421,8 @@ class binary_writer
std::is_signed<NumberType>::value&& std::is_signed<NumberType>::value&&
!std::is_floating_point<NumberType>::value, int >::type = 0 > !std::is_floating_point<NumberType>::value, int >::type = 0 >
void write_number_with_ubjson_prefix(const NumberType n, void write_number_with_ubjson_prefix(const NumberType n,
const bool add_prefix) const bool add_prefix,
const bool use_bjdata)
{ {
if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)()) if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
{ {
@ -1346,7 +1430,7 @@ class binary_writer
{ {
oa->write_character(to_char_type('i')); // int8 oa->write_character(to_char_type('i')); // int8
} }
write_number(static_cast<std::int8_t>(n)); write_number(static_cast<std::int8_t>(n), use_bjdata);
} }
else if (static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::max)())) else if (static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::max)()))
{ {
@ -1354,7 +1438,7 @@ class binary_writer
{ {
oa->write_character(to_char_type('U')); // uint8 oa->write_character(to_char_type('U')); // uint8
} }
write_number(static_cast<std::uint8_t>(n)); write_number(static_cast<std::uint8_t>(n), use_bjdata);
} }
else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)()) else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
{ {
@ -1362,7 +1446,15 @@ class binary_writer
{ {
oa->write_character(to_char_type('I')); // int16 oa->write_character(to_char_type('I')); // int16
} }
write_number(static_cast<std::int16_t>(n)); write_number(static_cast<std::int16_t>(n), use_bjdata);
}
else if (use_bjdata && (static_cast<std::int64_t>((std::numeric_limits<std::uint16_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint16_t>::max)())))
{
if (add_prefix)
{
oa->write_character(to_char_type('u')); // uint16 - bjdata only
}
write_number(static_cast<uint16_t>(n), use_bjdata);
} }
else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)()) else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
{ {
@ -1370,7 +1462,15 @@ class binary_writer
{ {
oa->write_character(to_char_type('l')); // int32 oa->write_character(to_char_type('l')); // int32
} }
write_number(static_cast<std::int32_t>(n)); write_number(static_cast<std::int32_t>(n), use_bjdata);
}
else if (use_bjdata && (static_cast<std::int64_t>((std::numeric_limits<std::uint32_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint32_t>::max)())))
{
if (add_prefix)
{
oa->write_character(to_char_type('m')); // uint32 - bjdata only
}
write_number(static_cast<uint32_t>(n), use_bjdata);
} }
else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)()) else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
{ {
@ -1378,7 +1478,7 @@ class binary_writer
{ {
oa->write_character(to_char_type('L')); // int64 oa->write_character(to_char_type('L')); // int64
} }
write_number(static_cast<std::int64_t>(n)); write_number(static_cast<std::int64_t>(n), use_bjdata);
} }
// LCOV_EXCL_START // LCOV_EXCL_START
else else
@ -1389,7 +1489,7 @@ class binary_writer
} }
const auto number = BasicJsonType(n).dump(); const auto number = BasicJsonType(n).dump();
write_number_with_ubjson_prefix(number.size(), true); write_number_with_ubjson_prefix(number.size(), true, use_bjdata);
for (std::size_t i = 0; i < number.size(); ++i) for (std::size_t i = 0; i < number.size(); ++i)
{ {
oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i]))); oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i])));
@ -1401,7 +1501,7 @@ class binary_writer
/*! /*!
@brief determine the type prefix of container values @brief determine the type prefix of container values
*/ */
CharType ubjson_prefix(const BasicJsonType& j) const noexcept CharType ubjson_prefix(const BasicJsonType& j, const bool use_bjdata) const noexcept
{ {
switch (j.type()) switch (j.type())
{ {
@ -1425,10 +1525,18 @@ class binary_writer
{ {
return 'I'; return 'I';
} }
if (use_bjdata && ((std::numeric_limits<std::uint16_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)()))
{
return 'u';
}
if ((std::numeric_limits<std::int32_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)()) if ((std::numeric_limits<std::int32_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
{ {
return 'l'; return 'l';
} }
if (use_bjdata && ((std::numeric_limits<std::uint32_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)()))
{
return 'm';
}
if ((std::numeric_limits<std::int64_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)()) if ((std::numeric_limits<std::int64_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
{ {
return 'L'; return 'L';
@ -1451,14 +1559,26 @@ class binary_writer
{ {
return 'I'; return 'I';
} }
if (use_bjdata && j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint16_t>::max)()))
{
return 'u';
}
if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
{ {
return 'l'; return 'l';
} }
if (use_bjdata && j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint32_t>::max)()))
{
return 'm';
}
if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)())) if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
{ {
return 'L'; return 'L';
} }
if (use_bjdata && j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
{
return 'M';
}
// anything else is treated as high-precision number // anything else is treated as high-precision number
return 'H'; // LCOV_EXCL_LINE return 'H'; // LCOV_EXCL_LINE
} }
@ -1476,6 +1596,7 @@ class binary_writer
case value_t::object: case value_t::object:
return '{'; return '{';
case value_t::discarded:
default: // discarded values default: // discarded values
return 'N'; return 'N';
} }
@ -1491,6 +1612,118 @@ class binary_writer
return 'D'; // float 64 return 'D'; // float 64
} }
/*!
@return false if the object is successfully converted to a bjdata ndarray, true if the type or size is invalid
*/
bool write_bjdata_ndarray(const typename BasicJsonType::object_t& value, const bool use_count, const bool use_type)
{
std::map<string_t, CharType> bjdtype = {{"uint8", 'U'}, {"int8", 'i'}, {"uint16", 'u'}, {"int16", 'I'},
{"uint32", 'm'}, {"int32", 'l'}, {"uint64", 'M'}, {"int64", 'L'}, {"single", 'd'}, {"double", 'D'}, {"char", 'C'}
};
string_t key = "_ArrayType_";
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
if (it == bjdtype.end())
{
return true;
}
CharType dtype = it->second;
key = "_ArraySize_";
std::size_t len = (value.at(key).empty() ? 0 : 1);
for (const auto& el : value.at(key))
{
len *= static_cast<std::size_t>(el.m_value.number_unsigned);
}
key = "_ArrayData_";
if (value.at(key).size() != len)
{
return true;
}
oa->write_character('[');
oa->write_character('$');
oa->write_character(dtype);
oa->write_character('#');
key = "_ArraySize_";
write_ubjson(value.at(key), use_count, use_type, true, true);
key = "_ArrayData_";
if (dtype == 'U' || dtype == 'C')
{
for (const auto& el : value.at(key))
{
write_number(static_cast<std::uint8_t>(el.m_value.number_unsigned), true);
}
}
else if (dtype == 'i')
{
for (const auto& el : value.at(key))
{
write_number(static_cast<std::int8_t>(el.m_value.number_integer), true);
}
}
else if (dtype == 'u')
{
for (const auto& el : value.at(key))
{
write_number(static_cast<std::uint16_t>(el.m_value.number_unsigned), true);
}
}
else if (dtype == 'I')
{
for (const auto& el : value.at(key))
{
write_number(static_cast<std::int16_t>(el.m_value.number_integer), true);
}
}
else if (dtype == 'm')
{
for (const auto& el : value.at(key))
{
write_number(static_cast<std::uint32_t>(el.m_value.number_unsigned), true);
}
}
else if (dtype == 'l')
{
for (const auto& el : value.at(key))
{
write_number(static_cast<std::int32_t>(el.m_value.number_integer), true);
}
}
else if (dtype == 'M')
{
for (const auto& el : value.at(key))
{
write_number(static_cast<std::uint64_t>(el.m_value.number_unsigned), true);
}
}
else if (dtype == 'L')
{
for (const auto& el : value.at(key))
{
write_number(static_cast<std::int64_t>(el.m_value.number_integer), true);
}
}
else if (dtype == 'd')
{
for (const auto& el : value.at(key))
{
write_number(static_cast<float>(el.m_value.number_float), true);
}
}
else if (dtype == 'D')
{
for (const auto& el : value.at(key))
{
write_number(static_cast<double>(el.m_value.number_float), true);
}
}
return false;
}
/////////////////////// ///////////////////////
// Utility functions // // Utility functions //
/////////////////////// ///////////////////////
@ -1498,19 +1731,21 @@ class binary_writer
/* /*
@brief write a number to output input @brief write a number to output input
@param[in] n number of type @a NumberType @param[in] n number of type @a NumberType
@tparam NumberType the type of the number @param[in] OutputIsLittleEndian Set to true if output data is
@tparam OutputIsLittleEndian Set to true if output data is
required to be little endian required to be little endian
@tparam NumberType the type of the number
@note This function needs to respect the system's endianess, because bytes @note This function needs to respect the system's endianness, because bytes
in CBOR, MessagePack, and UBJSON are stored in network order (big in CBOR, MessagePack, and UBJSON are stored in network order (big
endian) and therefore need reordering on little endian systems. endian) and therefore need reordering on little endian systems.
On the other hand, BSON and BJData use little endian and should reorder
on big endian systems.
*/ */
template<typename NumberType, bool OutputIsLittleEndian = false> template<typename NumberType>
void write_number(const NumberType n) void write_number(const NumberType n, const bool OutputIsLittleEndian = false)
{ {
// step 1: write number to array of length NumberType // step 1: write number to array of length NumberType
std::array<CharType, sizeof(NumberType)> vec; std::array<CharType, sizeof(NumberType)> vec{};
std::memcpy(vec.data(), &n, sizeof(NumberType)); std::memcpy(vec.data(), &n, sizeof(NumberType));
// step 2: write array to output (with possible reordering) // step 2: write array to output (with possible reordering)
@ -1525,6 +1760,10 @@ class binary_writer
void write_compact_float(const number_float_t n, detail::input_format_t format) void write_compact_float(const number_float_t n, detail::input_format_t format)
{ {
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) && if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) &&
static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) && static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) &&
static_cast<double>(static_cast<float>(n)) == static_cast<double>(n)) static_cast<double>(static_cast<float>(n)) == static_cast<double>(n))
@ -1541,6 +1780,9 @@ class binary_writer
: get_msgpack_float_prefix(n)); : get_msgpack_float_prefix(n));
write_number(n); write_number(n);
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
} }
public: public:
@ -1585,11 +1827,12 @@ class binary_writer
} }
private: private:
/// whether we can assume little endianess /// whether we can assume little endianness
const bool is_little_endian = little_endianess(); const bool is_little_endian = little_endianness();
/// the output /// the output
output_adapter_t<CharType> oa = nullptr; output_adapter_t<CharType> oa = nullptr;
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,25 +1,43 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <algorithm> // copy #include <algorithm> // copy
#include <cstddef> // size_t #include <cstddef> // size_t
#include <ios> // streamsize
#include <iterator> // back_inserter #include <iterator> // back_inserter
#include <memory> // shared_ptr, make_shared #include <memory> // shared_ptr, make_shared
#include <ostream> // basic_ostream
#include <string> // basic_string #include <string> // basic_string
#include <vector> // vector #include <vector> // vector
#ifndef JSON_NO_IO
#include <ios> // streamsize
#include <ostream> // basic_ostream
#endif // JSON_NO_IO
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
/// abstract output adapter interface /// abstract output adapter interface
template<typename CharType> struct output_adapter_protocol template<typename CharType> struct output_adapter_protocol
{ {
virtual void write_character(CharType c) = 0; virtual void write_character(CharType c) = 0;
virtual void write_characters(const CharType* s, std::size_t length) = 0; virtual void write_characters(const CharType* s, std::size_t length) = 0;
virtual ~output_adapter_protocol() = default; virtual ~output_adapter_protocol() = default;
output_adapter_protocol() = default;
output_adapter_protocol(const output_adapter_protocol&) = default;
output_adapter_protocol(output_adapter_protocol&&) noexcept = default;
output_adapter_protocol& operator=(const output_adapter_protocol&) = default;
output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
}; };
/// a type to simplify interfaces /// a type to simplify interfaces
@ -27,11 +45,11 @@ template<typename CharType>
using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>; using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;
/// output adapter for byte vectors /// output adapter for byte vectors
template<typename CharType> template<typename CharType, typename AllocatorType = std::allocator<CharType>>
class output_vector_adapter : public output_adapter_protocol<CharType> class output_vector_adapter : public output_adapter_protocol<CharType>
{ {
public: public:
explicit output_vector_adapter(std::vector<CharType>& vec) noexcept explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept
: v(vec) : v(vec)
{} {}
@ -43,13 +61,14 @@ class output_vector_adapter : public output_adapter_protocol<CharType>
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
void write_characters(const CharType* s, std::size_t length) override void write_characters(const CharType* s, std::size_t length) override
{ {
std::copy(s, s + length, std::back_inserter(v)); v.insert(v.end(), s, s + length);
} }
private: private:
std::vector<CharType>& v; std::vector<CharType, AllocatorType>& v;
}; };
#ifndef JSON_NO_IO
/// output adapter for output streams /// output adapter for output streams
template<typename CharType> template<typename CharType>
class output_stream_adapter : public output_adapter_protocol<CharType> class output_stream_adapter : public output_adapter_protocol<CharType>
@ -73,6 +92,7 @@ class output_stream_adapter : public output_adapter_protocol<CharType>
private: private:
std::basic_ostream<CharType>& stream; std::basic_ostream<CharType>& stream;
}; };
#endif // JSON_NO_IO
/// output adapter for basic_string /// output adapter for basic_string
template<typename CharType, typename StringType = std::basic_string<CharType>> template<typename CharType, typename StringType = std::basic_string<CharType>>
@ -102,11 +122,14 @@ template<typename CharType, typename StringType = std::basic_string<CharType>>
class output_adapter class output_adapter
{ {
public: public:
output_adapter(std::vector<CharType>& vec) template<typename AllocatorType = std::allocator<CharType>>
: oa(std::make_shared<output_vector_adapter<CharType>>(vec)) {} output_adapter(std::vector<CharType, AllocatorType>& vec)
: oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {}
#ifndef JSON_NO_IO
output_adapter(std::basic_ostream<CharType>& s) output_adapter(std::basic_ostream<CharType>& s)
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {} : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
#endif // JSON_NO_IO
output_adapter(StringType& s) output_adapter(StringType& s)
: oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {} : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
@ -119,5 +142,6 @@ class output_adapter
private: private:
output_adapter_t<CharType> oa = nullptr; output_adapter_t<CharType> oa = nullptr;
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,3 +1,12 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2008-2009 Björn Hoehrmann <bjoern@hoehrmann.de>
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <algorithm> // reverse, remove, fill, find, none_of #include <algorithm> // reverse, remove, fill, find, none_of
@ -9,6 +18,7 @@
#include <cstdio> // snprintf #include <cstdio> // snprintf
#include <limits> // numeric_limits #include <limits> // numeric_limits
#include <string> // string, char_traits #include <string> // string, char_traits
#include <iomanip> // setfill, setw
#include <type_traits> // is_same #include <type_traits> // is_same
#include <utility> // move #include <utility> // move
@ -18,12 +28,13 @@
#include <nlohmann/detail/meta/cpp_future.hpp> #include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/output/binary_writer.hpp> #include <nlohmann/detail/output/binary_writer.hpp>
#include <nlohmann/detail/output/output_adapters.hpp> #include <nlohmann/detail/output/output_adapters.hpp>
#include <nlohmann/detail/string_concat.hpp>
#include <nlohmann/detail/value_t.hpp> #include <nlohmann/detail/value_t.hpp>
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
namespace detail namespace detail
{ {
/////////////////// ///////////////////
// serialization // // serialization //
/////////////////// ///////////////////
@ -358,11 +369,11 @@ class serializer
} }
default: // LCOV_EXCL_LINE default: // LCOV_EXCL_LINE
JSON_ASSERT(false); // LCOV_EXCL_LINE JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
} }
} }
private: JSON_PRIVATE_UNLESS_TESTED:
/*! /*!
@brief dump escaped string @brief dump escaped string
@ -379,7 +390,7 @@ class serializer
*/ */
void dump_escaped(const string_t& s, const bool ensure_ascii) void dump_escaped(const string_t& s, const bool ensure_ascii)
{ {
std::uint32_t codepoint; std::uint32_t codepoint{};
std::uint8_t state = UTF8_ACCEPT; std::uint8_t state = UTF8_ACCEPT;
std::size_t bytes = 0; // number of bytes written to string_buffer std::size_t bytes = 0; // number of bytes written to string_buffer
@ -389,7 +400,7 @@ class serializer
for (std::size_t i = 0; i < s.size(); ++i) for (std::size_t i = 0; i < s.size(); ++i)
{ {
const auto byte = static_cast<uint8_t>(s[i]); const auto byte = static_cast<std::uint8_t>(s[i]);
switch (decode(state, codepoint, byte)) switch (decode(state, codepoint, byte))
{ {
@ -454,15 +465,17 @@ class serializer
{ {
if (codepoint <= 0xFFFF) if (codepoint <= 0xFFFF)
{ {
(std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
static_cast<std::uint16_t>(codepoint)); static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x",
static_cast<std::uint16_t>(codepoint)));
bytes += 6; bytes += 6;
} }
else else
{ {
(std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)), static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x",
static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu))); static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)),
static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu))));
bytes += 12; bytes += 12;
} }
} }
@ -497,9 +510,7 @@ class serializer
{ {
case error_handler_t::strict: case error_handler_t::strict:
{ {
std::string sn(3, '\0'); JSON_THROW(type_error::create(316, concat("invalid UTF-8 byte at index ", std::to_string(i), ": 0x", hex_bytes(byte | 0)), nullptr));
(std::snprintf)(&sn[0], sn.size(), "%.2X", byte);
JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn));
} }
case error_handler_t::ignore: case error_handler_t::ignore:
@ -557,7 +568,7 @@ class serializer
} }
default: // LCOV_EXCL_LINE default: // LCOV_EXCL_LINE
JSON_ASSERT(false); // LCOV_EXCL_LINE JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
} }
break; break;
} }
@ -591,9 +602,7 @@ class serializer
{ {
case error_handler_t::strict: case error_handler_t::strict:
{ {
std::string sn(3, '\0'); JSON_THROW(type_error::create(316, concat("incomplete UTF-8 string; last byte: 0x", hex_bytes(static_cast<std::uint8_t>(s.back() | 0))), nullptr));
(std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast<std::uint8_t>(s.back()));
JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn));
} }
case error_handler_t::ignore: case error_handler_t::ignore:
@ -620,11 +629,12 @@ class serializer
} }
default: // LCOV_EXCL_LINE default: // LCOV_EXCL_LINE
JSON_ASSERT(false); // LCOV_EXCL_LINE JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
} }
} }
} }
private:
/*! /*!
@brief count digits @brief count digits
@ -659,6 +669,33 @@ class serializer
} }
} }
/*!
* @brief convert a byte to a uppercase hex representation
* @param[in] byte byte to represent
* @return representation ("00".."FF")
*/
static std::string hex_bytes(std::uint8_t byte)
{
std::string result = "FF";
constexpr const char* nibble_to_hex = "0123456789ABCDEF";
result[0] = nibble_to_hex[byte / 16];
result[1] = nibble_to_hex[byte % 16];
return result;
}
// templates to avoid warnings about useless casts
template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value, int> = 0>
bool is_negative_number(NumberType x)
{
return x < 0;
}
template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value, int > = 0 >
bool is_negative_number(NumberType /*unused*/)
{
return false;
}
/*! /*!
@brief dump an integer @brief dump an integer
@ -669,6 +706,7 @@ class serializer
@tparam NumberType either @a number_integer_t or @a number_unsigned_t @tparam NumberType either @a number_integer_t or @a number_unsigned_t
*/ */
template < typename NumberType, detail::enable_if_t < template < typename NumberType, detail::enable_if_t <
std::is_integral<NumberType>::value ||
std::is_same<NumberType, number_unsigned_t>::value || std::is_same<NumberType, number_unsigned_t>::value ||
std::is_same<NumberType, number_integer_t>::value || std::is_same<NumberType, number_integer_t>::value ||
std::is_same<NumberType, binary_char_t>::value, std::is_same<NumberType, binary_char_t>::value,
@ -699,14 +737,13 @@ class serializer
} }
// use a pointer to fill the buffer // use a pointer to fill the buffer
auto buffer_ptr = number_buffer.begin(); auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg)
const bool is_negative = std::is_same<NumberType, number_integer_t>::value && !(x >= 0); // see issue #755
number_unsigned_t abs_value; number_unsigned_t abs_value;
unsigned int n_chars; unsigned int n_chars{};
if (is_negative) if (is_negative_number(x))
{ {
*buffer_ptr = '-'; *buffer_ptr = '-';
abs_value = remove_sign(static_cast<number_integer_t>(x)); abs_value = remove_sign(static_cast<number_integer_t>(x));
@ -723,7 +760,7 @@ class serializer
// spare 1 byte for '\0' // spare 1 byte for '\0'
JSON_ASSERT(n_chars < number_buffer.size() - 1); JSON_ASSERT(n_chars < number_buffer.size() - 1);
// jump to the end to generate the string from backward // jump to the end to generate the string from backward,
// so we later avoid reversing the result // so we later avoid reversing the result
buffer_ptr += n_chars; buffer_ptr += n_chars;
@ -782,8 +819,8 @@ class serializer
void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/) void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/)
{ {
char* begin = number_buffer.data(); auto* begin = number_buffer.data();
char* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x); auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
o->write_characters(begin, static_cast<size_t>(end - begin)); o->write_characters(begin, static_cast<size_t>(end - begin));
} }
@ -794,6 +831,7 @@ class serializer
static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10; static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
// the actual conversion // the actual conversion
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x); std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
// negative value indicates an error // negative value indicates an error
@ -804,8 +842,8 @@ class serializer
// erase thousands separator // erase thousands separator
if (thousands_sep != '\0') if (thousands_sep != '\0')
{ {
const auto end = std::remove(number_buffer.begin(), // NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::remove returns an iterator, see https://github.com/nlohmann/json/issues/3081
number_buffer.begin() + len, thousands_sep); const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);
std::fill(end, number_buffer.end(), '\0'); std::fill(end, number_buffer.end(), '\0');
JSON_ASSERT((end - number_buffer.begin()) <= len); JSON_ASSERT((end - number_buffer.begin()) <= len);
len = (end - number_buffer.begin()); len = (end - number_buffer.begin());
@ -814,6 +852,7 @@ class serializer
// convert decimal point to '.' // convert decimal point to '.'
if (decimal_point != '\0' && decimal_point != '.') if (decimal_point != '\0' && decimal_point != '.')
{ {
// NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::find returns an iterator, see https://github.com/nlohmann/json/issues/3081
const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point); const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
if (dec_pos != number_buffer.end()) if (dec_pos != number_buffer.end())
{ {
@ -823,7 +862,7 @@ class serializer
o->write_characters(number_buffer.data(), static_cast<std::size_t>(len)); o->write_characters(number_buffer.data(), static_cast<std::size_t>(len));
// determine if need to append ".0" // determine if we need to append ".0"
const bool value_is_int_like = const bool value_is_int_like =
std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
[](char c) [](char c)
@ -880,6 +919,7 @@ class serializer
} }
}; };
JSON_ASSERT(byte < utf8d.size());
const std::uint8_t type = utf8d[byte]; const std::uint8_t type = utf8d[byte];
codep = (state != UTF8_ACCEPT) codep = (state != UTF8_ACCEPT)
@ -899,7 +939,7 @@ class serializer
*/ */
number_unsigned_t remove_sign(number_unsigned_t x) number_unsigned_t remove_sign(number_unsigned_t x)
{ {
JSON_ASSERT(false); // LCOV_EXCL_LINE JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
return x; // LCOV_EXCL_LINE return x; // LCOV_EXCL_LINE
} }
@ -914,7 +954,7 @@ class serializer
*/ */
inline number_unsigned_t remove_sign(number_integer_t x) noexcept inline number_unsigned_t remove_sign(number_integer_t x) noexcept
{ {
JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression)
return static_cast<number_unsigned_t>(-(x + 1)) + 1; return static_cast<number_unsigned_t>(-(x + 1)) + 1;
} }
@ -943,5 +983,6 @@ class serializer
/// error_handler how to react on decoding errors /// error_handler how to react on decoding errors
const error_handler_t error_handler; const error_handler_t error_handler;
}; };
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -0,0 +1,146 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once
#include <cstring> // strlen
#include <string> // string
#include <utility> // forward
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/detected.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
inline std::size_t concat_length()
{
return 0;
}
template<typename... Args>
inline std::size_t concat_length(const char* cstr, Args&& ... rest);
template<typename StringType, typename... Args>
inline std::size_t concat_length(const StringType& str, Args&& ... rest);
template<typename... Args>
inline std::size_t concat_length(const char /*c*/, Args&& ... rest)
{
return 1 + concat_length(std::forward<Args>(rest)...);
}
template<typename... Args>
inline std::size_t concat_length(const char* cstr, Args&& ... rest)
{
// cppcheck-suppress ignoredReturnValue
return ::strlen(cstr) + concat_length(std::forward<Args>(rest)...);
}
template<typename StringType, typename... Args>
inline std::size_t concat_length(const StringType& str, Args&& ... rest)
{
return str.size() + concat_length(std::forward<Args>(rest)...);
}
template<typename OutStringType>
inline void concat_into(OutStringType& /*out*/)
{}
template<typename StringType, typename Arg>
using string_can_append = decltype(std::declval<StringType&>().append(std::declval < Arg && > ()));
template<typename StringType, typename Arg>
using detect_string_can_append = is_detected<string_can_append, StringType, Arg>;
template<typename StringType, typename Arg>
using string_can_append_op = decltype(std::declval<StringType&>() += std::declval < Arg && > ());
template<typename StringType, typename Arg>
using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>;
template<typename StringType, typename Arg>
using string_can_append_iter = decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));
template<typename StringType, typename Arg>
using detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>;
template<typename StringType, typename Arg>
using string_can_append_data = decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));
template<typename StringType, typename Arg>
using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
template < typename OutStringType, typename Arg, typename... Args,
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
&& detect_string_can_append_op<OutStringType, Arg>::value, int > = 0 >
inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest);
template < typename OutStringType, typename Arg, typename... Args,
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
&& !detect_string_can_append_op<OutStringType, Arg>::value
&& detect_string_can_append_iter<OutStringType, Arg>::value, int > = 0 >
inline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest);
template < typename OutStringType, typename Arg, typename... Args,
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
&& !detect_string_can_append_op<OutStringType, Arg>::value
&& !detect_string_can_append_iter<OutStringType, Arg>::value
&& detect_string_can_append_data<OutStringType, Arg>::value, int > = 0 >
inline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest);
template<typename OutStringType, typename Arg, typename... Args,
enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0>
inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest)
{
out.append(std::forward<Arg>(arg));
concat_into(out, std::forward<Args>(rest)...);
}
template < typename OutStringType, typename Arg, typename... Args,
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
&& detect_string_can_append_op<OutStringType, Arg>::value, int > >
inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest)
{
out += std::forward<Arg>(arg);
concat_into(out, std::forward<Args>(rest)...);
}
template < typename OutStringType, typename Arg, typename... Args,
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
&& !detect_string_can_append_op<OutStringType, Arg>::value
&& detect_string_can_append_iter<OutStringType, Arg>::value, int > >
inline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest)
{
out.append(arg.begin(), arg.end());
concat_into(out, std::forward<Args>(rest)...);
}
template < typename OutStringType, typename Arg, typename... Args,
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
&& !detect_string_can_append_op<OutStringType, Arg>::value
&& !detect_string_can_append_iter<OutStringType, Arg>::value
&& detect_string_can_append_data<OutStringType, Arg>::value, int > >
inline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest)
{
out.append(arg.data(), arg.size());
concat_into(out, std::forward<Args>(rest)...);
}
template<typename OutStringType = std::string, typename... Args>
inline OutStringType concat(Args && ... args)
{
OutStringType str;
str.reserve(concat_length(std::forward<Args>(args)...));
concat_into(str, std::forward<Args>(args)...);
return str;
}
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END

View File

@ -0,0 +1,72 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once
#include <nlohmann/detail/abi_macros.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
/*!
@brief replace all occurrences of a substring by another string
@param[in,out] s the string to manipulate; changed so that all
occurrences of @a f are replaced with @a t
@param[in] f the substring to replace with @a t
@param[in] t the string to replace @a f
@pre The search string @a f must not be empty. **This precondition is
enforced with an assertion.**
@since version 2.0.0
*/
template<typename StringType>
inline void replace_substring(StringType& s, const StringType& f,
const StringType& t)
{
JSON_ASSERT(!f.empty());
for (auto pos = s.find(f); // find first occurrence of f
pos != StringType::npos; // make sure f was found
s.replace(pos, f.size(), t), // replace with t, and
pos = s.find(f, pos + t.size())) // find next occurrence of f
{}
}
/*!
* @brief string escaping as described in RFC 6901 (Sect. 4)
* @param[in] s string to escape
* @return escaped string
*
* Note the order of escaping "~" to "~0" and "/" to "~1" is important.
*/
template<typename StringType>
inline StringType escape(StringType s)
{
replace_substring(s, StringType{"~"}, StringType{"~0"});
replace_substring(s, StringType{"/"}, StringType{"~1"});
return s;
}
/*!
* @brief string unescaping as described in RFC 6901 (Sect. 4)
* @param[in] s string to unescape
* @return unescaped string
*
* Note the order of escaping "~1" to "/" and "~0" to "~" is important.
*/
template<typename StringType>
static void unescape(StringType& s)
{
replace_substring(s, StringType{"~1"}, StringType{"/"});
replace_substring(s, StringType{"~0"}, StringType{"~"});
}
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,3 +1,11 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <array> // array #include <array> // array
@ -5,10 +13,15 @@
#include <cstdint> // uint8_t #include <cstdint> // uint8_t
#include <string> // string #include <string> // string
namespace nlohmann #include <nlohmann/detail/macro_scope.hpp>
{ #if JSON_HAS_THREE_WAY_COMPARISON
#include <compare> // partial_ordering
#endif
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail namespace detail
{ {
/////////////////////////// ///////////////////////////
// JSON type enumeration // // JSON type enumeration //
/////////////////////////// ///////////////////////////
@ -32,7 +45,7 @@ number_float), because the library distinguishes these three types for numbers:
@ref basic_json::number_float_t is used for floating-point numbers or to @ref basic_json::number_float_t is used for floating-point numbers or to
approximate integers which do not fit in the limits of their respective type. approximate integers which do not fit in the limits of their respective type.
@sa @ref basic_json::basic_json(const value_t value_type) -- create a JSON @sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON
value with the default value for a given type value with the default value for a given type
@since version 1.0.0 @since version 1.0.0
@ -64,7 +77,11 @@ Returns an ordering that is similar to Python:
@since version 1.0.0 @since version 1.0.0
*/ */
inline bool operator<(const value_t lhs, const value_t rhs) noexcept #if JSON_HAS_THREE_WAY_COMPARISON
inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD*
#else
inline bool operator<(const value_t lhs, const value_t rhs) noexcept
#endif
{ {
static constexpr std::array<std::uint8_t, 9> order = {{ static constexpr std::array<std::uint8_t, 9> order = {{
0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */,
@ -75,7 +92,27 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept
const auto l_index = static_cast<std::size_t>(lhs); const auto l_index = static_cast<std::size_t>(lhs);
const auto r_index = static_cast<std::size_t>(rhs); const auto r_index = static_cast<std::size_t>(rhs);
#if JSON_HAS_THREE_WAY_COMPARISON
if (l_index < order.size() && r_index < order.size())
{
return order[l_index] <=> order[r_index]; // *NOPAD*
}
return std::partial_ordering::unordered;
#else
return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
#endif
} }
// GCC selects the built-in operator< over an operator rewritten from
// a user-defined spaceship operator
// Clang, MSVC, and ICC select the rewritten candidate
// (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200)
#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)
inline bool operator<(const value_t lhs, const value_t rhs) noexcept
{
return std::is_lt(lhs <=> rhs); // *NOPAD*
}
#endif
} // namespace detail } // namespace detail
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,11 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_ #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
@ -7,13 +15,15 @@
#include <string> // string #include <string> // string
#include <vector> // vector #include <vector> // vector
#include <nlohmann/detail/abi_macros.hpp>
/*! /*!
@brief namespace for Niels Lohmann @brief namespace for Niels Lohmann
@see https://github.com/nlohmann @see https://github.com/nlohmann
@since version 1.0.0 @since version 1.0.0
*/ */
namespace nlohmann NLOHMANN_JSON_NAMESPACE_BEGIN
{
/*! /*!
@brief default JSONSerializer template argument @brief default JSONSerializer template argument
@ -24,6 +34,8 @@ for serialization.
template<typename T = void, typename SFINAE = void> template<typename T = void, typename SFINAE = void>
struct adl_serializer; struct adl_serializer;
/// a class to store JSON values
/// @sa https://json.nlohmann.me/api/basic_json/
template<template<typename U, typename V, typename... Args> class ObjectType = template<template<typename U, typename V, typename... Args> class ObjectType =
std::map, std::map,
template<typename U, typename... Args> class ArrayType = std::vector, template<typename U, typename... Args> class ArrayType = std::vector,
@ -37,42 +49,26 @@ template<template<typename U, typename V, typename... Args> class ObjectType =
class BinaryType = std::vector<std::uint8_t>> class BinaryType = std::vector<std::uint8_t>>
class basic_json; class basic_json;
/*! /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
@brief JSON Pointer /// @sa https://json.nlohmann.me/api/json_pointer/
template<typename RefStringType>
A JSON pointer defines a string syntax for identifying a specific value
within a JSON document. It can be used with functions `at` and
`operator[]`. Furthermore, JSON pointers are the base for JSON patches.
@sa [RFC 6901](https://tools.ietf.org/html/rfc6901)
@since version 2.0.0
*/
template<typename BasicJsonType>
class json_pointer; class json_pointer;
/*! /*!
@brief default JSON class @brief default specialization
@sa https://json.nlohmann.me/api/json/
This type is the default specialization of the @ref basic_json class which
uses the standard template types.
@since version 1.0.0
*/ */
using json = basic_json<>; using json = basic_json<>;
/// @brief a minimal map-like container that preserves insertion order
/// @sa https://json.nlohmann.me/api/ordered_map/
template<class Key, class T, class IgnoredLess, class Allocator> template<class Key, class T, class IgnoredLess, class Allocator>
struct ordered_map; struct ordered_map;
/*! /// @brief specialization that maintains the insertion order of object keys
@brief ordered JSON class /// @sa https://json.nlohmann.me/api/ordered_json/
This type preserves the insertion order of object keys.
@since version 3.9.0
*/
using ordered_json = basic_json<nlohmann::ordered_map>; using ordered_json = basic_json<nlohmann::ordered_map>;
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_

View File

@ -1,12 +1,26 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <functional> // less #include <functional> // equal_to, less
#include <initializer_list> // initializer_list
#include <iterator> // input_iterator_tag, iterator_traits
#include <memory> // allocator #include <memory> // allocator
#include <stdexcept> // for out_of_range
#include <type_traits> // enable_if, is_convertible
#include <utility> // pair #include <utility> // pair
#include <vector> // vector #include <vector> // vector
namespace nlohmann #include <nlohmann/detail/macro_scope.hpp>
{ #include <nlohmann/detail/meta/type_traits.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
/// ordered_map: a minimal map-like container that preserves insertion order /// ordered_map: a minimal map-like container that preserves insertion order
/// for use within nlohmann::basic_json<ordered_map> /// for use within nlohmann::basic_json<ordered_map>
@ -17,74 +31,160 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
using key_type = Key; using key_type = Key;
using mapped_type = T; using mapped_type = T;
using Container = std::vector<std::pair<const Key, T>, Allocator>; using Container = std::vector<std::pair<const Key, T>, Allocator>;
using typename Container::iterator; using iterator = typename Container::iterator;
using typename Container::const_iterator; using const_iterator = typename Container::const_iterator;
using typename Container::size_type; using size_type = typename Container::size_type;
using typename Container::value_type; using value_type = typename Container::value_type;
#ifdef JSON_HAS_CPP_14
using key_compare = std::equal_to<>;
#else
using key_compare = std::equal_to<Key>;
#endif
// Explicit constructors instead of `using Container::Container` // Explicit constructors instead of `using Container::Container`
// otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4)
ordered_map(const Allocator& alloc = Allocator()) : Container{alloc} {} ordered_map() noexcept(noexcept(Container())) : Container{} {}
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {}
template <class It> template <class It>
ordered_map(It first, It last, const Allocator& alloc = Allocator()) ordered_map(It first, It last, const Allocator& alloc = Allocator())
: Container{first, last, alloc} {} : Container{first, last, alloc} {}
ordered_map(std::initializer_list<T> init, const Allocator& alloc = Allocator() ) ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator() )
: Container{init, alloc} {} : Container{init, alloc} {}
std::pair<iterator, bool> emplace(const key_type& key, T&& t) std::pair<iterator, bool> emplace(const key_type& key, T&& t)
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return {it, false}; return {it, false};
} }
} }
Container::emplace_back(key, t); Container::emplace_back(key, std::forward<T>(t));
return {--this->end(), true}; return {std::prev(this->end()), true};
} }
T& operator[](const Key& key) template<class KeyType, detail::enable_if_t<
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
std::pair<iterator, bool> emplace(KeyType && key, T && t)
{
for (auto it = this->begin(); it != this->end(); ++it)
{
if (m_compare(it->first, key))
{
return {it, false};
}
}
Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
return {std::prev(this->end()), true};
}
T& operator[](const key_type& key)
{ {
return emplace(key, T{}).first->second; return emplace(key, T{}).first->second;
} }
const T& operator[](const Key& key) const template<class KeyType, detail::enable_if_t<
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
T & operator[](KeyType && key)
{
return emplace(std::forward<KeyType>(key), T{}).first->second;
}
const T& operator[](const key_type& key) const
{ {
return at(key); return at(key);
} }
T& at(const Key& key) template<class KeyType, detail::enable_if_t<
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
const T & operator[](KeyType && key) const
{
return at(std::forward<KeyType>(key));
}
T& at(const key_type& key)
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return it->second; return it->second;
} }
} }
throw std::out_of_range("key not found"); JSON_THROW(std::out_of_range("key not found"));
} }
const T& at(const Key& key) const template<class KeyType, detail::enable_if_t<
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
T & at(KeyType && key)
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return it->second; return it->second;
} }
} }
throw std::out_of_range("key not found"); JSON_THROW(std::out_of_range("key not found"));
} }
size_type erase(const Key& key) const T& at(const key_type& key) const
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{
return it->second;
}
}
JSON_THROW(std::out_of_range("key not found"));
}
template<class KeyType, detail::enable_if_t<
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
const T & at(KeyType && key) const
{
for (auto it = this->begin(); it != this->end(); ++it)
{
if (m_compare(it->first, key))
{
return it->second;
}
}
JSON_THROW(std::out_of_range("key not found"));
}
size_type erase(const key_type& key)
{
for (auto it = this->begin(); it != this->end(); ++it)
{
if (m_compare(it->first, key))
{
// Since we cannot move const Keys, re-construct them in place
for (auto next = it; ++next != this->end(); ++it)
{
it->~value_type(); // Destroy but keep allocation
new (&*it) value_type{std::move(*next)};
}
Container::pop_back();
return 1;
}
}
return 0;
}
template<class KeyType, detail::enable_if_t<
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
size_type erase(KeyType && key)
{
for (auto it = this->begin(); it != this->end(); ++it)
{
if (m_compare(it->first, key))
{ {
// Since we cannot move const Keys, re-construct them in place // Since we cannot move const Keys, re-construct them in place
for (auto next = it; ++next != this->end(); ++it) for (auto next = it; ++next != this->end(); ++it)
@ -101,23 +201,67 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
iterator erase(iterator pos) iterator erase(iterator pos)
{ {
auto it = pos; return erase(pos, std::next(pos));
// Since we cannot move const Keys, re-construct them in place
for (auto next = it; ++next != this->end(); ++it)
{
it->~value_type(); // Destroy but keep allocation
new (&*it) value_type{std::move(*next)};
}
Container::pop_back();
return pos;
} }
size_type count(const Key& key) const iterator erase(iterator first, iterator last)
{
if (first == last)
{
return first;
}
const auto elements_affected = std::distance(first, last);
const auto offset = std::distance(Container::begin(), first);
// This is the start situation. We need to delete elements_affected
// elements (3 in this example: e, f, g), and need to return an
// iterator past the last deleted element (h in this example).
// Note that offset is the distance from the start of the vector
// to first. We will need this later.
// [ a, b, c, d, e, f, g, h, i, j ]
// ^ ^
// first last
// Since we cannot move const Keys, we re-construct them in place.
// We start at first and re-construct (viz. copy) the elements from
// the back of the vector. Example for first iteration:
// ,--------.
// v | destroy e and re-construct with h
// [ a, b, c, d, e, f, g, h, i, j ]
// ^ ^
// it it + elements_affected
for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
{
it->~value_type(); // destroy but keep allocation
new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it
}
// [ a, b, c, d, h, i, j, h, i, j ]
// ^ ^
// first last
// remove the unneeded elements at the end of the vector
Container::resize(this->size() - static_cast<size_type>(elements_affected));
// [ a, b, c, d, h, i, j ]
// ^ ^
// first last
// first is now pointing past the last deleted element, but we cannot
// use this iterator, because it may have been invalidated by the
// resize call. Instead, we can return begin() + offset.
return Container::begin() + offset;
}
size_type count(const key_type& key) const
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return 1; return 1;
} }
@ -125,11 +269,25 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
return 0; return 0;
} }
iterator find(const Key& key) template<class KeyType, detail::enable_if_t<
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
size_type count(KeyType && key) const
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{
return 1;
}
}
return 0;
}
iterator find(const key_type& key)
{
for (auto it = this->begin(); it != this->end(); ++it)
{
if (m_compare(it->first, key))
{ {
return it; return it;
} }
@ -137,11 +295,25 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
return Container::end(); return Container::end();
} }
const_iterator find(const Key& key) const template<class KeyType, detail::enable_if_t<
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
iterator find(KeyType && key)
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{
return it;
}
}
return Container::end();
}
const_iterator find(const key_type& key) const
{
for (auto it = this->begin(); it != this->end(); ++it)
{
if (m_compare(it->first, key))
{ {
return it; return it;
} }
@ -158,7 +330,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == value.first) if (m_compare(it->first, value.first))
{ {
return {it, false}; return {it, false};
} }
@ -166,6 +338,22 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
Container::push_back(value); Container::push_back(value);
return {--this->end(), true}; return {--this->end(), true};
} }
template<typename InputIt>
using require_input_iter = typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
std::input_iterator_tag>::value>::type;
template<typename InputIt, typename = require_input_iter<InputIt>>
void insert(InputIt first, InputIt last)
{
for (auto it = first; it != last; ++it)
{
insert(*it);
}
}
private:
JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();
}; };
} // namespace nlohmann NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,20 +1,23 @@
#pragma once
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-FileCopyrightText: 2016-2021 Evan Nemerson <evan@nemerson.com>
// SPDX-License-Identifier: MIT
/* Hedley - https://nemequ.github.io/hedley /* Hedley - https://nemequ.github.io/hedley
* Created by Evan Nemerson <evan@nemerson.com> * Created by Evan Nemerson <evan@nemerson.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to
* the public domain worldwide. This software is distributed without
* any warranty.
*
* For details, see <http://creativecommons.org/publicdomain/zero/1.0/>.
* SPDX-License-Identifier: CC0-1.0
*/ */
#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 13) #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
#if defined(JSON_HEDLEY_VERSION) #if defined(JSON_HEDLEY_VERSION)
#undef JSON_HEDLEY_VERSION #undef JSON_HEDLEY_VERSION
#endif #endif
#define JSON_HEDLEY_VERSION 13 #define JSON_HEDLEY_VERSION 15
#if defined(JSON_HEDLEY_STRINGIFY_EX) #if defined(JSON_HEDLEY_STRINGIFY_EX)
#undef JSON_HEDLEY_STRINGIFY_EX #undef JSON_HEDLEY_STRINGIFY_EX
@ -87,18 +90,18 @@
#if defined(JSON_HEDLEY_MSVC_VERSION) #if defined(JSON_HEDLEY_MSVC_VERSION)
#undef JSON_HEDLEY_MSVC_VERSION #undef JSON_HEDLEY_MSVC_VERSION
#endif #endif
#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
#elif defined(_MSC_FULL_VER) #elif defined(_MSC_FULL_VER) && !defined(__ICL)
#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
#elif defined(_MSC_VER) #elif defined(_MSC_VER) && !defined(__ICL)
#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
#endif #endif
#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
#undef JSON_HEDLEY_MSVC_VERSION_CHECK #undef JSON_HEDLEY_MSVC_VERSION_CHECK
#endif #endif
#if !defined(_MSC_VER) #if !defined(JSON_HEDLEY_MSVC_VERSION)
#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0) #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
#elif defined(_MSC_VER) && (_MSC_VER >= 1400) #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
@ -111,9 +114,9 @@
#if defined(JSON_HEDLEY_INTEL_VERSION) #if defined(JSON_HEDLEY_INTEL_VERSION)
#undef JSON_HEDLEY_INTEL_VERSION #undef JSON_HEDLEY_INTEL_VERSION
#endif #endif
#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
#define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
#elif defined(__INTEL_COMPILER) #elif defined(__INTEL_COMPILER) && !defined(__ICL)
#define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
#endif #endif
@ -126,6 +129,22 @@
#define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0) #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
#endif #endif
#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
#undef JSON_HEDLEY_INTEL_CL_VERSION
#endif
#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
#define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
#endif
#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
#define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_PGI_VERSION) #if defined(JSON_HEDLEY_PGI_VERSION)
#undef JSON_HEDLEY_PGI_VERSION #undef JSON_HEDLEY_PGI_VERSION
#endif #endif
@ -365,7 +384,7 @@
#if __VER__ > 1000 #if __VER__ > 1000
#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
#else #else
#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(VER / 100, __VER__ % 100, 0) #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
#endif #endif
#endif #endif
@ -442,6 +461,22 @@
#define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0) #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
#endif #endif
#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
#undef JSON_HEDLEY_MCST_LCC_VERSION
#endif
#if defined(__LCC__) && defined(__LCC_MINOR__)
#define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
#endif
#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
#endif
#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
#define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
#else
#define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
#endif
#if defined(JSON_HEDLEY_GCC_VERSION) #if defined(JSON_HEDLEY_GCC_VERSION)
#undef JSON_HEDLEY_GCC_VERSION #undef JSON_HEDLEY_GCC_VERSION
#endif #endif
@ -451,6 +486,7 @@
!defined(JSON_HEDLEY_INTEL_VERSION) && \ !defined(JSON_HEDLEY_INTEL_VERSION) && \
!defined(JSON_HEDLEY_PGI_VERSION) && \ !defined(JSON_HEDLEY_PGI_VERSION) && \
!defined(JSON_HEDLEY_ARM_VERSION) && \ !defined(JSON_HEDLEY_ARM_VERSION) && \
!defined(JSON_HEDLEY_CRAY_VERSION) && \
!defined(JSON_HEDLEY_TI_VERSION) && \ !defined(JSON_HEDLEY_TI_VERSION) && \
!defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \ !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
!defined(JSON_HEDLEY_TI_CL430_VERSION) && \ !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
@ -458,7 +494,8 @@
!defined(JSON_HEDLEY_TI_CL6X_VERSION) && \ !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
!defined(JSON_HEDLEY_TI_CL7X_VERSION) && \ !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
!defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \ !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
!defined(__COMPCERT__) !defined(__COMPCERT__) && \
!defined(JSON_HEDLEY_MCST_LCC_VERSION)
#define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
#endif #endif
@ -474,17 +511,21 @@
#if defined(JSON_HEDLEY_HAS_ATTRIBUTE) #if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
#undef JSON_HEDLEY_HAS_ATTRIBUTE #undef JSON_HEDLEY_HAS_ATTRIBUTE
#endif #endif
#if defined(__has_attribute) #if \
#define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) defined(__has_attribute) && \
( \
(!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
)
# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
#else #else
#define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
#endif #endif
#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
#endif #endif
#if defined(__has_attribute) #if defined(__has_attribute)
#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute) #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
#else #else
#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
#endif #endif
@ -493,7 +534,7 @@
#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
#endif #endif
#if defined(__has_attribute) #if defined(__has_attribute)
#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute) #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
#else #else
#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
#endif #endif
@ -678,6 +719,72 @@
#define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
#endif #endif
#if \
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
defined(__clang__) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
#define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
#define JSON_HEDLEY_PRAGMA(value) __pragma(value)
#else
#define JSON_HEDLEY_PRAGMA(value)
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
#undef JSON_HEDLEY_DIAGNOSTIC_POP
#endif
#if defined(__clang__)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
#define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
#elif \
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
#else
#define JSON_HEDLEY_DIAGNOSTIC_PUSH
#define JSON_HEDLEY_DIAGNOSTIC_POP
#endif
/* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for /* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for
HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ HEDLEY INTERNAL USE ONLY. API subject to change without notice. */
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
@ -686,12 +793,22 @@
#if defined(__cplusplus) #if defined(__cplusplus)
# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") # if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions") # if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ # if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
JSON_HEDLEY_DIAGNOSTIC_PUSH \
_Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
_Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
_Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
xpr \
JSON_HEDLEY_DIAGNOSTIC_POP
# else
# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
JSON_HEDLEY_DIAGNOSTIC_PUSH \ JSON_HEDLEY_DIAGNOSTIC_PUSH \
_Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
_Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
xpr \ xpr \
JSON_HEDLEY_DIAGNOSTIC_POP JSON_HEDLEY_DIAGNOSTIC_POP
# endif
# else # else
# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
JSON_HEDLEY_DIAGNOSTIC_PUSH \ JSON_HEDLEY_DIAGNOSTIC_PUSH \
@ -756,7 +873,7 @@
# define JSON_HEDLEY_CPP_CAST(T, expr) \ # define JSON_HEDLEY_CPP_CAST(T, expr) \
JSON_HEDLEY_DIAGNOSTIC_PUSH \ JSON_HEDLEY_DIAGNOSTIC_PUSH \
_Pragma("diag_suppress=Pe137") \ _Pragma("diag_suppress=Pe137") \
JSON_HEDLEY_DIAGNOSTIC_POP \ JSON_HEDLEY_DIAGNOSTIC_POP
# else # else
# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr)) # define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
# endif # endif
@ -764,70 +881,6 @@
# define JSON_HEDLEY_CPP_CAST(T, expr) (expr) # define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
#endif #endif
#if \
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
defined(__clang__) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
(JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
#define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
#define JSON_HEDLEY_PRAGMA(value) __pragma(value)
#else
#define JSON_HEDLEY_PRAGMA(value)
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
#undef JSON_HEDLEY_DIAGNOSTIC_POP
#endif
#if defined(__clang__)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
#define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
#elif \
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
#else
#define JSON_HEDLEY_DIAGNOSTIC_PUSH
#define JSON_HEDLEY_DIAGNOSTIC_POP
#endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
#endif #endif
@ -835,12 +888,18 @@
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996)) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
#elif \ #elif \
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
@ -873,6 +932,8 @@
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
@ -889,6 +950,8 @@
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
#else #else
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
#endif #endif
@ -902,8 +965,12 @@
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0) #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030)) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus) #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
@ -915,6 +982,8 @@
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
#else #else
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
#endif #endif
@ -932,20 +1001,34 @@
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
#endif #endif
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
#endif
#if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
#else
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
#endif
#if defined(JSON_HEDLEY_DEPRECATED) #if defined(JSON_HEDLEY_DEPRECATED)
#undef JSON_HEDLEY_DEPRECATED #undef JSON_HEDLEY_DEPRECATED
#endif #endif
#if defined(JSON_HEDLEY_DEPRECATED_FOR) #if defined(JSON_HEDLEY_DEPRECATED_FOR)
#undef JSON_HEDLEY_DEPRECATED_FOR #undef JSON_HEDLEY_DEPRECATED_FOR
#endif #endif
#if JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) #if \
JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since)) #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
#elif defined(__cplusplus) && (__cplusplus >= 201402L)
#define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
#elif \ #elif \
JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) || \ (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
@ -955,9 +1038,13 @@
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
#elif defined(__cplusplus) && (__cplusplus >= 201402L)
#define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
#elif \ #elif \
JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
@ -972,12 +1059,15 @@
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
#elif \ #elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
@ -994,7 +1084,8 @@
#if \ #if \
JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
#else #else
#define JSON_HEDLEY_UNAVAILABLE(available_since) #define JSON_HEDLEY_UNAVAILABLE(available_since)
@ -1006,13 +1097,7 @@
#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG) #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
#endif #endif
#if (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L) #if \
#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
#elif \
JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
@ -1028,9 +1113,16 @@
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__)) #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
#elif defined(_Check_return_) /* SAL */ #elif defined(_Check_return_) /* SAL */
#define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_ #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
@ -1046,7 +1138,8 @@
JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
#else #else
#define JSON_HEDLEY_SENTINEL(position) #define JSON_HEDLEY_SENTINEL(position)
@ -1057,7 +1150,9 @@
#endif #endif
#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) #if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
#define JSON_HEDLEY_NO_RETURN __noreturn #define JSON_HEDLEY_NO_RETURN __noreturn
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) #elif \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define JSON_HEDLEY_NO_RETURN _Noreturn #define JSON_HEDLEY_NO_RETURN _Noreturn
@ -1079,11 +1174,14 @@
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
#define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) #elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_NO_RETURN __declspec(noreturn) #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
#define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
@ -1115,7 +1213,8 @@
#endif #endif
#if \ #if \
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_ASSUME(expr) __assume(expr) #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
#define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
@ -1133,7 +1232,9 @@
JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \ JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
#elif defined(JSON_HEDLEY_ASSUME) #elif defined(JSON_HEDLEY_ASSUME)
#define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
@ -1211,7 +1312,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0) #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check)) #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
@ -1247,15 +1349,16 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr)) #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
#endif #endif
#if \ #if \
JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) || \ (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability)) # define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability)) # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability)) # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 ) # define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 ) # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
#elif \ #elif \
JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) || \ (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
@ -1269,7 +1372,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \ JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
# define JSON_HEDLEY_PREDICT(expr, expected, probability) \ # define JSON_HEDLEY_PREDICT(expr, expected, probability) \
(((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))) (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
@ -1315,11 +1419,14 @@ JSON_HEDLEY_DIAGNOSTIC_POP
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
#define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) #elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_MALLOC __declspec(restrict) #define JSON_HEDLEY_MALLOC __declspec(restrict)
#else #else
#define JSON_HEDLEY_MALLOC #define JSON_HEDLEY_MALLOC
@ -1346,7 +1453,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
# define JSON_HEDLEY_PURE __attribute__((__pure__)) # define JSON_HEDLEY_PURE __attribute__((__pure__))
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") # define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
@ -1382,7 +1490,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_CONST __attribute__((__const__)) #define JSON_HEDLEY_CONST __attribute__((__const__))
#elif \ #elif \
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
@ -1400,6 +1509,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
@ -1409,7 +1519,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \ (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
defined(__clang__) defined(__clang__) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_RESTRICT __restrict #define JSON_HEDLEY_RESTRICT __restrict
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus) #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
#define JSON_HEDLEY_RESTRICT _Restrict #define JSON_HEDLEY_RESTRICT _Restrict
@ -1430,13 +1541,15 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#define JSON_HEDLEY_INLINE __inline__ #define JSON_HEDLEY_INLINE __inline__
#elif \ #elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_INLINE __inline #define JSON_HEDLEY_INLINE __inline
#else #else
#define JSON_HEDLEY_INLINE #define JSON_HEDLEY_INLINE
@ -1462,9 +1575,13 @@ JSON_HEDLEY_DIAGNOSTIC_POP
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE # define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) #elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
# define JSON_HEDLEY_ALWAYS_INLINE __forceinline # define JSON_HEDLEY_ALWAYS_INLINE __forceinline
#elif defined(__cplusplus) && \ #elif defined(__cplusplus) && \
( \ ( \
@ -1502,9 +1619,13 @@ JSON_HEDLEY_DIAGNOSTIC_POP
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
#define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) #elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0) #elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
#define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
@ -1547,7 +1668,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
) \ ) \
) ) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) # define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) # define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
# else # else
@ -1563,10 +1685,12 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#if \ #if \
JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
#elif \ #elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \ JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
#define JSON_HEDLEY_NO_THROW __declspec(nothrow) #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
#else #else
@ -1578,7 +1702,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#endif #endif
#if \ #if \
JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \ JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough) #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
#define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
@ -1595,7 +1720,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#endif #endif
#if \ #if \
JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
#elif defined(_Ret_notnull_) /* SAL */ #elif defined(_Ret_notnull_) /* SAL */
#define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
@ -1637,7 +1763,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \ (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
#define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
#endif #endif
#if !defined(__cplusplus) #if !defined(__cplusplus)
@ -1661,7 +1788,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
!defined(JSON_HEDLEY_SUNPRO_VERSION) && \ !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
!defined(JSON_HEDLEY_PGI_VERSION) && \ !defined(JSON_HEDLEY_PGI_VERSION) && \
!defined(JSON_HEDLEY_IAR_VERSION)) || \ !defined(JSON_HEDLEY_IAR_VERSION)) || \
JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) || \ (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
@ -1731,7 +1858,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#if \ #if \
!defined(__cplusplus) && ( \ !defined(__cplusplus) && ( \
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
JSON_HEDLEY_HAS_FEATURE(c_static_assert) || \ (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \ JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
defined(_Static_assert) \ defined(_Static_assert) \
@ -1739,7 +1866,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP
# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) # define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
#elif \ #elif \
(defined(__cplusplus) && (__cplusplus >= 201103L)) || \ (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) # define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
#else #else
# define JSON_HEDLEY_STATIC_ASSERT(expr, message) # define JSON_HEDLEY_STATIC_ASSERT(expr, message)
@ -1799,7 +1927,9 @@ JSON_HEDLEY_DIAGNOSTIC_POP
JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) #elif \
JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
#else #else
# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
@ -1835,8 +1965,10 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#if defined(JSON_HEDLEY_FLAGS) #if defined(JSON_HEDLEY_FLAGS)
#undef JSON_HEDLEY_FLAGS #undef JSON_HEDLEY_FLAGS
#endif #endif
#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
#define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
#else
#define JSON_HEDLEY_FLAGS
#endif #endif
#if defined(JSON_HEDLEY_FLAGS_CAST) #if defined(JSON_HEDLEY_FLAGS_CAST)
@ -1856,7 +1988,9 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#if defined(JSON_HEDLEY_EMPTY_BASES) #if defined(JSON_HEDLEY_EMPTY_BASES)
#undef JSON_HEDLEY_EMPTY_BASES #undef JSON_HEDLEY_EMPTY_BASES
#endif #endif
#if JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0) #if \
(JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
#define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
#else #else
#define JSON_HEDLEY_EMPTY_BASES #define JSON_HEDLEY_EMPTY_BASES

View File

@ -1,3 +1,13 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once
#undef JSON_HEDLEY_ALWAYS_INLINE #undef JSON_HEDLEY_ALWAYS_INLINE
#undef JSON_HEDLEY_ARM_VERSION #undef JSON_HEDLEY_ARM_VERSION
#undef JSON_HEDLEY_ARM_VERSION_CHECK #undef JSON_HEDLEY_ARM_VERSION_CHECK
@ -31,6 +41,7 @@
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
#undef JSON_HEDLEY_DIAGNOSTIC_POP #undef JSON_HEDLEY_DIAGNOSTIC_POP
#undef JSON_HEDLEY_DIAGNOSTIC_PUSH #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
#undef JSON_HEDLEY_DMC_VERSION #undef JSON_HEDLEY_DMC_VERSION
@ -74,12 +85,16 @@
#undef JSON_HEDLEY_IBM_VERSION_CHECK #undef JSON_HEDLEY_IBM_VERSION_CHECK
#undef JSON_HEDLEY_IMPORT #undef JSON_HEDLEY_IMPORT
#undef JSON_HEDLEY_INLINE #undef JSON_HEDLEY_INLINE
#undef JSON_HEDLEY_INTEL_CL_VERSION
#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
#undef JSON_HEDLEY_INTEL_VERSION #undef JSON_HEDLEY_INTEL_VERSION
#undef JSON_HEDLEY_INTEL_VERSION_CHECK #undef JSON_HEDLEY_INTEL_VERSION_CHECK
#undef JSON_HEDLEY_IS_CONSTANT #undef JSON_HEDLEY_IS_CONSTANT
#undef JSON_HEDLEY_IS_CONSTEXPR_ #undef JSON_HEDLEY_IS_CONSTEXPR_
#undef JSON_HEDLEY_LIKELY #undef JSON_HEDLEY_LIKELY
#undef JSON_HEDLEY_MALLOC #undef JSON_HEDLEY_MALLOC
#undef JSON_HEDLEY_MCST_LCC_VERSION
#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
#undef JSON_HEDLEY_MESSAGE #undef JSON_HEDLEY_MESSAGE
#undef JSON_HEDLEY_MSVC_VERSION #undef JSON_HEDLEY_MSVC_VERSION
#undef JSON_HEDLEY_MSVC_VERSION_CHECK #undef JSON_HEDLEY_MSVC_VERSION_CHECK

View File

@ -1,6 +1,6 @@
project('nlohmann_json', project('nlohmann_json',
'cpp', 'cpp',
version : '3.9.1', version : '3.11.2',
license : 'MIT', license : 'MIT',
) )
@ -14,6 +14,7 @@ nlohmann_json_multiple_headers = declare_dependency(
if not meson.is_subproject() if not meson.is_subproject()
install_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann') install_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann')
install_headers('single_include/nlohmann/json_fwd.hpp', subdir: 'nlohmann')
pkgc = import('pkgconfig') pkgc = import('pkgconfig')
pkgc.generate(name: 'nlohmann_json', pkgc.generate(name: 'nlohmann_json',

File diff suppressed because it is too large Load Diff

1
external/physfs vendored

Submodule external/physfs deleted from 2ba973b677

235
external/physfs/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,235 @@
# file taken from offical physfs repo and modified
# PhysicsFS; a portable, flexible file i/o abstraction.
#
# Please see the file LICENSE.txt in the source's root directory.
# The CMake project file is meant to get this compiling on all sorts of
# platforms quickly, and serve as the way Unix platforms and Linux distros
# package up official builds, but you don't _need_ to use this; we have
# built PhysicsFS to (hopefully) be able to drop into your project and
# compile, using preprocessor checks for platform-specific bits instead of
# testing in here.
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(PhysicsFS)
set(PHYSFS_VERSION 3.1.0)
# Increment this if/when we break backwards compatibility.
set(PHYSFS_SOVERSION 1)
# I hate that they define "WIN32" ... we're about to move to Win64...I hope!
if(WIN32 AND NOT WINDOWS)
set(WINDOWS TRUE)
endif()
if(APPLE)
set(PHYSFS_M_SRCS physfs/src/physfs_platform_apple.m)
endif()
if(CMAKE_COMPILER_IS_GNUCC)
# Don't use -rpath.
set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
add_definitions(-erroff=E_EMPTY_TRANSLATION_UNIT)
add_definitions(-xldscope=hidden)
endif()
if(HAIKU)
# We add this explicitly, since we don't want CMake to think this
# is a C++ project unless we're on Haiku.
set(PHYSFS_CPP_SRCS physfs/src/physfs_platform_haiku.cpp)
find_library(BE_LIBRARY be)
find_library(ROOT_LIBRARY root)
set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${BE_LIBRARY} ${ROOT_LIBRARY})
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
set(WINRT TRUE)
endif()
if(WINRT)
set(PHYSFS_CPP_SRCS physfs/src/physfs_platform_winrt.cpp)
endif()
if(UNIX AND NOT WINDOWS AND NOT APPLE) # (MingW and such might be UNIX _and_ WINDOWS!)
find_library(PTHREAD_LIBRARY pthread)
if(PTHREAD_LIBRARY)
set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${PTHREAD_LIBRARY})
endif()
endif()
# Almost everything is "compiled" here, but things that don't apply to the
# build are #ifdef'd out. This is to make it easy to embed PhysicsFS into
# another project or bring up a new build system: just compile all the source
# code and #define the things you want.
set(PHYSFS_SRCS
physfs/src/physfs.c
physfs/src/physfs_byteorder.c
physfs/src/physfs_unicode.c
physfs/src/physfs_platform_posix.c
physfs/src/physfs_platform_unix.c
physfs/src/physfs_platform_windows.c
physfs/src/physfs_platform_os2.c
physfs/src/physfs_platform_qnx.c
physfs/src/physfs_platform_android.c
physfs/src/physfs_archiver_dir.c
physfs/src/physfs_archiver_unpacked.c
physfs/src/physfs_archiver_grp.c
physfs/src/physfs_archiver_hog.c
physfs/src/physfs_archiver_7z.c
physfs/src/physfs_archiver_mvl.c
physfs/src/physfs_archiver_qpak.c
physfs/src/physfs_archiver_wad.c
physfs/src/physfs_archiver_zip.c
physfs/src/physfs_archiver_slb.c
physfs/src/physfs_archiver_iso9660.c
physfs/src/physfs_archiver_vdf.c
physfs/src/physfs.h
physfs/src/physfs_casefolding.h
physfs/src/physfs_internal.h
physfs/src/physfs_lzmasdk.h
physfs/src/physfs_miniz.h
physfs/src/physfs_platforms.h
${PHYSFS_CPP_SRCS}
${PHYSFS_M_SRCS}
)
# Archivers ...
# These are (mostly) on by default now, so these options are only useful for
# disabling them.
option(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
if(NOT PHYSFS_ARCHIVE_ZIP)
add_definitions(-DPHYSFS_SUPPORTS_ZIP=0)
endif()
option(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE)
if(NOT PHYSFS_ARCHIVE_7Z)
add_definitions(-DPHYSFS_SUPPORTS_7Z=0)
endif()
option(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
if(NOT PHYSFS_ARCHIVE_GRP)
add_definitions(-DPHYSFS_SUPPORTS_GRP=0)
endif()
option(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
if(NOT PHYSFS_ARCHIVE_WAD)
add_definitions(-DPHYSFS_SUPPORTS_WAD=0)
endif()
option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
if(NOT PHYSFS_ARCHIVE_HOG)
add_definitions(-DPHYSFS_SUPPORTS_HOG=0)
endif()
option(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
if(NOT PHYSFS_ARCHIVE_MVL)
add_definitions(-DPHYSFS_SUPPORTS_MVL=0)
endif()
option(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
if(NOT PHYSFS_ARCHIVE_QPAK)
add_definitions(-DPHYSFS_SUPPORTS_QPAK=0)
endif()
option(PHYSFS_ARCHIVE_SLB "Enable I-War / Independence War SLB support" TRUE)
if(NOT PHYSFS_ARCHIVE_SLB)
add_definitions(-DPHYSFS_SUPPORTS_SLB=0)
endif()
option(PHYSFS_ARCHIVE_ISO9660 "Enable ISO9660 support" TRUE)
if(NOT PHYSFS_ARCHIVE_ISO9660)
add_definitions(-DPHYSFS_SUPPORTS_ISO9660=0)
endif()
option(PHYSFS_ARCHIVE_VDF "Enable Gothic I/II VDF archive support" TRUE)
if(NOT PHYSFS_ARCHIVE_VDF)
add_definitions(-DPHYSFS_SUPPORTS_VDF=0)
endif()
option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
if(PHYSFS_BUILD_STATIC)
add_library(physfs-static STATIC ${PHYSFS_SRCS})
# Don't rename this on Windows, since DLLs will also produce an import
# library named "physfs.lib" which would conflict; Unix tend to like the
# same library name with a different extension for static libs, but
# Windows can just have a separate name.
if(NOT MSVC)
set_target_properties(physfs-static PROPERTIES OUTPUT_NAME "physfs")
endif()
if(WINRT)
# Ignore LNK4264 warnings; we don't author any WinRT components, just consume them, so we're okay in a static library.
set_target_properties(physfs-static PROPERTIES VS_WINRT_COMPONENT True)
set_target_properties(physfs-static PROPERTIES STATIC_LIBRARY_FLAGS "/ignore:4264")
endif()
if(APPLE)
target_link_libraries(physfs-static PUBLIC "-framework IOKit")
target_link_libraries(physfs-static PUBLIC "-framework Foundation") # do i need this?
endif()
target_include_directories(physfs-static PUBLIC "physfs/src")
set(PHYSFS_LIB_TARGET physfs-static)
set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs-static")
endif()
if(NOT PHYSFS_BUILD_STATIC)
message(FATAL "static libraries are disabled!")
endif()
# CMake FAQ says I need this...
if(PHYSFS_BUILD_STATIC AND NOT WINDOWS)
set_target_properties(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
endif()
if(NOT MSVC)
configure_file(
"physfs/extras/physfs.pc.in"
"physfs/extras/physfs.pc"
@ONLY
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc"
DESTINATION "lib${LIB_SUFFIX}/pkgconfig"
)
endif()
macro(message_bool_option _NAME _VALUE)
if(${_VALUE})
message(STATUS " ${_NAME}: enabled")
else()
message(STATUS " ${_NAME}: disabled")
endif()
endmacro()
message(STATUS "PhysicsFS will build with the following options:")
message_bool_option("ZIP support" PHYSFS_ARCHIVE_ZIP)
message_bool_option("7zip support" PHYSFS_ARCHIVE_7Z)
message_bool_option("GRP support" PHYSFS_ARCHIVE_GRP)
message_bool_option("WAD support" PHYSFS_ARCHIVE_WAD)
message_bool_option("HOG support" PHYSFS_ARCHIVE_HOG)
message_bool_option("MVL support" PHYSFS_ARCHIVE_MVL)
message_bool_option("QPAK support" PHYSFS_ARCHIVE_QPAK)
message_bool_option("SLB support" PHYSFS_ARCHIVE_SLB)
message_bool_option("VDF support" PHYSFS_ARCHIVE_VDF)
message_bool_option("ISO9660 support" PHYSFS_ARCHIVE_ISO9660)
message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)
if(PHYSFS_BUILD_TEST)
message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE)
endif()
# end of CMakeLists.txt ...

1
external/physfs/physfs vendored Submodule

Submodule external/physfs/physfs added at fdd38a3f8a

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(soloud CXX) project(soloud CXX)
@ -29,12 +29,13 @@ set(CPP_FILES
soloud/src/backend/alsa/soloud_alsa.cpp soloud/src/backend/alsa/soloud_alsa.cpp
soloud/src/backend/coreaudio/soloud_coreaudio.cpp soloud/src/backend/coreaudio/soloud_coreaudio.cpp
soloud/src/backend/null/soloud_null.cpp soloud/src/backend/null/soloud_null.cpp
soloud/src/backend/nosound/soloud_nosound.cpp
#soloud/src/backend/openal/soloud_openal.cpp #soloud/src/backend/openal/soloud_openal.cpp
#soloud/src/backend/openal/soloud_openal_dll.c #soloud/src/backend/openal/soloud_openal_dll.c
soloud/src/backend/opensles/soloud_opensles.cpp soloud/src/backend/opensles/soloud_opensles.cpp
soloud/src/backend/oss/soloud_oss.cpp #soloud/src/backend/oss/soloud_oss.cpp
soloud/src/backend/portaudio/soloud_portaudio.cpp #soloud/src/backend/portaudio/soloud_portaudio.cpp
soloud/src/backend/portaudio/soloud_portaudio_dll.c #soloud/src/backend/portaudio/soloud_portaudio_dll.c
#soloud/src/backend/sdl/soloud_sdl1.cpp #soloud/src/backend/sdl/soloud_sdl1.cpp
#soloud/src/backend/sdl/soloud_sdl1_dll.c #soloud/src/backend/sdl/soloud_sdl1_dll.c
#soloud/src/backend/sdl/soloud_sdl2.cpp #soloud/src/backend/sdl/soloud_sdl2.cpp
@ -156,33 +157,38 @@ set(HPP_FILES
add_library(soloud ${CPP_FILES} ${HPP_FILES}) add_library(soloud ${CPP_FILES} ${HPP_FILES})
target_compile_definitions(soloud PRIVATE WITH_NULL) target_compile_definitions(soloud PRIVATE WITH_NULL)
target_compile_definitions(soloud PRIVATE WITH_NOSOUND)
#target_compile_definitions(soloud PRIVATE WITH_SDL2) #target_compile_definitions(soloud PRIVATE WITH_SDL2)
target_compile_definitions(soloud PRIVATE WITH_SDL2_STATIC) target_compile_definitions(soloud PRIVATE WITH_SDL2_STATIC)
target_include_directories(soloud SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/soloud/include") target_include_directories(soloud SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/soloud/include")
#target_include_directories(soloud PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/imgui")
#if not android or emscripten if(EMSCRIPTEN)
if(VCPKG_TARGET_TRIPLET) target_compile_options(soloud PUBLIC -sUSE_SDL=2)
target_link_libraries(soloud SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static) target_link_libraries(soloud PUBLIC -sUSE_SDL=2)
elseif(VCPKG_TARGET_TRIPLET)
target_link_libraries(soloud
PUBLIC
SDL2::SDL2
#PRIVATE
#SDL2::SDL2main
#SDL2::SDL2-static
)
else() else()
target_include_directories(soloud PUBLIC "${SDL2_INCLUDE_DIR}") target_include_directories(soloud PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(soloud ${SDL2_LIBRARY}) target_link_libraries(soloud PUBLIC ${SDL2_LIBRARY})
endif() endif()
#if not android or emscripten
#if android #if android
#target_link_libraries(soloud SDL) #target_link_libraries(soloud SDL)
#endif #endif
if(EMSCRIPTEN)
set_target_properties(soloud PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(soloud PROPERTIES LINK_FLAGS "-s USE_SDL=2")
endif()
# TODO: remove # TODO: remove
if(UNIX) if(UNIX)
target_link_libraries(soloud target_link_libraries(soloud PUBLIC
-ldl -ldl
) )
endif() endif()

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(stb CXX) project(stb CXX)

View File

@ -1,29 +1,40 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
add_library(tracy_client if(NOT EMSCRIPTEN)
"${CMAKE_CURRENT_LIST_DIR}/tracy/Tracy.hpp" add_library(tracy_client
"${CMAKE_CURRENT_LIST_DIR}/tracy/TracyLua.hpp" "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/Tracy.hpp"
"${CMAKE_CURRENT_LIST_DIR}/tracy/TracyVulkan.hpp" "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/TracyLua.hpp"
"${CMAKE_CURRENT_LIST_DIR}/tracy/TracyOpenGL.hpp" "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/TracyVulkan.hpp"
"${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/TracyOpenGL.hpp"
"${CMAKE_CURRENT_LIST_DIR}/tracy/TracyClient.cpp" "${CMAKE_CURRENT_LIST_DIR}/tracy/public/TracyClient.cpp"
) )
target_compile_features(tracy_client PUBLIC cxx_std_17) option(TRACY_ENABLE "Enable tracy profiling" OFF)
if(TRACY_ENABLE) if(TRACY_ENABLE)
target_compile_definitions(tracy_client PUBLIC TRACY_ENABLE) target_compile_definitions(tracy_client PUBLIC TRACY_ENABLE)
#target_compile_definitions(tracy_client PUBLIC TRACY_NO_SYSTEM_TRACING) #target_compile_definitions(tracy_client PUBLIC TRACY_NO_SYSTEM_TRACING)
message("Enabled TRACY") message("Enabled TRACY")
endif()
target_compile_features(tracy_client PUBLIC cxx_std_17)
target_include_directories(tracy_client PUBLIC "${CMAKE_CURRENT_LIST_DIR}/tracy/public")
if(UNIX)
target_link_libraries(tracy_client dl)
endif()
if(WIN32)
target_link_libraries(tracy_client ws2_32 dbghelp)
endif()
else() # EMSCRIPTEN
add_library(tracy_client INTERFACE)
target_compile_features(tracy_client INTERFACE cxx_std_17)
target_include_directories(tracy_client INTERFACE "${CMAKE_CURRENT_LIST_DIR}/tracy/public")
endif() endif()
target_include_directories(tracy_client PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
if(UNIX)
target_link_libraries(tracy_client dl)
endif()
if(WIN32)
target_link_libraries(tracy_client ws2_32 dbghelp)
endif()

View File

@ -1,15 +1,16 @@
cmake_minimum_required(VERSION 3.2) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(framework CXX)
project(framework)
add_subdirectory(engine) add_subdirectory(engine)
add_subdirectory(logger) add_subdirectory(logger)
add_subdirectory(resource_manager) add_subdirectory(resource_manager)
add_subdirectory(s6zer)
add_subdirectory(common_components) add_subdirectory(common_components)
add_subdirectory(std_utils) add_subdirectory(std_utils)
add_subdirectory(random) add_subdirectory(random)
add_subdirectory(screen_director) add_subdirectory(screen_director)
add_subdirectory(filesystem) add_subdirectory(filesystem)
add_subdirectory(simple_scene)
add_subdirectory(organizer_scene) add_subdirectory(organizer_scene)
if(NOT MM_HEADLESS) if(NOT MM_HEADLESS)

View File

@ -1,8 +1,11 @@
cmake_minimum_required(VERSION 3.2) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(common_components CXX) project(common_components CXX)
add_library(common_components INTERFACE) add_library(common_components INTERFACE)
add_library(MM::common_components ALIAS common_components)
target_include_directories(common_components INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") target_include_directories(common_components INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(common_components INTERFACE target_link_libraries(common_components INTERFACE
@ -12,8 +15,23 @@ target_link_libraries(common_components INTERFACE
########################## ##########################
add_library(common_components_serialize_s6zer INTERFACE)
add_library(MM::common_components_serialize_s6zer ALIAS common_components_serialize_s6zer)
target_include_directories(common_components_serialize_s6zer INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(common_components_serialize_s6zer INTERFACE
common_components
s6zer
)
##########################
add_library(common_components_serialize_json INTERFACE) add_library(common_components_serialize_json INTERFACE)
add_library(MM::common_components_serialize_json ALIAS common_components_serialize_json)
target_include_directories(common_components_serialize_json INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") target_include_directories(common_components_serialize_json INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(common_components_serialize_json INTERFACE target_link_libraries(common_components_serialize_json INTERFACE

View File

@ -4,7 +4,7 @@
namespace MM::Components { namespace MM::Components {
struct Name { struct Name {
static const size_t max_str_len = 64; static const size_t max_str_len {64u};
std::string str; std::string str;
}; };
} }

View File

@ -0,0 +1,12 @@
#pragma once
#include <glm/vec2.hpp>
namespace MM::Components {
struct Position2D {
glm::vec2 pos {0.f, 0.f};
};
} // MM::Components

View File

@ -0,0 +1,11 @@
#pragma once
namespace MM::Components {
// used to lift 2D into 3D space. like a z-index in css/svg
struct Position2D_ZOffset {
float z_offset {500.f}; // default camera allows values to be between 0 and 1000
};
} // MM::Components

View File

@ -0,0 +1,12 @@
#pragma once
#include <glm/vec3.hpp>
namespace MM::Components {
struct Position3D {
glm::vec3 pos {0.f, 0.f, 0.f};
};
} // MM::Components

View File

@ -0,0 +1,10 @@
#pragma once
namespace MM::Components {
struct Rotation2D {
float rot {0.f};
};
} // MM::Components

View File

@ -0,0 +1,12 @@
#pragma once
#include <glm/vec2.hpp>
namespace MM::Components {
struct Scale2D {
glm::vec2 scale {1.f, 1.f};
};
} // MM::Components

View File

@ -7,6 +7,6 @@
#include "./json_glm.hpp" #include "./json_glm.hpp"
namespace MM::Components { namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Color, color) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Color, color)
} // MM::Components } // MM::Components

View File

@ -3,14 +3,36 @@
#include <glm/vec2.hpp> #include <glm/vec2.hpp>
#include <glm/vec3.hpp> #include <glm/vec3.hpp>
#include <glm/vec4.hpp> #include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
namespace glm { namespace glm {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec2, x, y) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec2, x, y)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec3, x, y, z) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec3, x, y, z)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec4, x, y, z, w) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec4, x, y, z, w)
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(mat4x4, [0], y, z, w)
inline void to_json(nlohmann::json& nlohmann_json_j, const mat4x4& nlohmann_json_t) {
// TODO: make 2d array?
nlohmann_json_j = nlohmann::json::array_t{};
nlohmann_json_j[0] = nlohmann_json_t[0];
nlohmann_json_j[1] = nlohmann_json_t[1];
nlohmann_json_j[2] = nlohmann_json_t[2];
nlohmann_json_j[3] = nlohmann_json_t[3];
}
inline void from_json(const nlohmann::json& nlohmann_json_j, mat4x4& nlohmann_json_t) {
if (!nlohmann_json_j.is_array()) {
//throw nlohmann::json::type_error::create(0, "", nlohmann_json_j);
assert(false && "expected array");
return; // TODO: dont fail silently
}
nlohmann_json_j.at(0).get_to(nlohmann_json_t[0]);
nlohmann_json_j.at(1).get_to(nlohmann_json_t[1]);
nlohmann_json_j.at(2).get_to(nlohmann_json_t[2]);
nlohmann_json_j.at(3).get_to(nlohmann_json_t[3]);
}
} }

View File

@ -5,6 +5,7 @@
#include <mm/components/name.hpp> #include <mm/components/name.hpp>
namespace MM::Components { namespace MM::Components {
// TODO: manual with str len limit
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Name, str) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Name, str)
} // MM::Components } // MM::Components

View File

@ -2,11 +2,11 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <mm/components/velocity3d.hpp> #include <mm/components/position2d.hpp>
#include "./json_glm.hpp" #include "./json_glm.hpp"
namespace MM::Components { namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity3D, velocity, rotation) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position2D, pos)
} // MM::Components } // MM::Components

View File

@ -0,0 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
#include <mm/components/position2d_zoffset.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position2D_ZOffset, z_offset)
} // MM::Components

View File

@ -2,11 +2,11 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <mm/components/velocity2d.hpp> #include <mm/components/position3d.hpp>
#include "./json_glm.hpp" #include "./json_glm.hpp"
namespace MM::Components { namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2D, velocity, rotation) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position3D, pos)
} // MM::Components } // MM::Components

View File

@ -2,11 +2,11 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <mm/components/transform2d.hpp> #include <mm/components/rotation2d.hpp>
#include "./json_glm.hpp" #include "./json_glm.hpp"
namespace MM::Components { namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform2D, position, scale, rotation) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Rotation2D, rot)
} // MM::Components } // MM::Components

View File

@ -2,11 +2,11 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <mm/components/transform3d.hpp> #include <mm/components/scale2d.hpp>
#include "./json_glm.hpp" #include "./json_glm.hpp"
namespace MM::Components { namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform3D, position, scale, rotation) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Scale2D, scale)
} // MM::Components } // MM::Components

View File

@ -0,0 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
#include <mm/components/transform4x4.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Transform4x4, trans)
} // MM::Components

View File

@ -0,0 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
#include <mm/components/velocity2d_position.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DPosition, pos_vel)
} // MM::Components

View File

@ -0,0 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
#include <mm/components/velocity2d_position_intent.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DPositionIntent, intent)
} // MM::Components

View File

@ -0,0 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
#include <mm/components/velocity2d_rotation.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DRotation, rot_vel)
} // MM::Components

View File

@ -5,6 +5,6 @@
#include <mm/components/view_dir2d.hpp> #include <mm/components/view_dir2d.hpp>
namespace MM::Components { namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ViewDir2D, dir) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ViewDir2D, dir)
} // MM::Components } // MM::Components

View File

@ -5,6 +5,6 @@
#include <mm/components/view_dir3d.hpp> #include <mm/components/view_dir3d.hpp>
namespace MM::Components { namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ViewDir3D, yaw, pitch, roll) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ViewDir3D, yaw, pitch, roll)
} // MM::Components } // MM::Components

View File

@ -0,0 +1,17 @@
#pragma once
#include <mm/s6zer/serialize.hpp>
#include <mm/components/color.hpp>
namespace MM::Components {
MM_DEFINE_SERIALIZE(Color,
MM_S6ZER_BAIL(stream.serializeFloat(data.color.r))
MM_S6ZER_BAIL(stream.serializeFloat(data.color.g))
MM_S6ZER_BAIL(stream.serializeFloat(data.color.b))
MM_S6ZER_BAIL(stream.serializeFloat(data.color.a))
)
} // MM::Components

View File

@ -1,55 +0,0 @@
//
// Created by FlaXxy on 29.07.2018.
//
#pragma once
#include <glm/vec2.hpp>
#include <glm/mat3x3.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/matrix_transform.hpp>
namespace MM::Components {
struct Transform2D {
glm::vec2 position {0.0f,0.0f};
glm::vec2 scale {1.0f,1.0f};
float rotation {0.0f};
glm::mat3x3 getTransform3(void) const {
//return transformationMatrix(scale, rotation, position);
glm::mat3x3 res(1);
res[2][0] = position.x;
res[2][1] = position.y;
float const s = sinf(rotation);
float const c = cosf(rotation);
res[0][0] = scale.x * c;
res[0][1] = scale.x * s;
res[1][0] = scale.y * -s;
res[1][1] = scale.y * c;
return res;
}
glm::mat4x4 getTransform4(float z = 500.f) const {
//return transformationMatrix(scale, rotation, position);
glm::mat4x4 res{1};
//res[2][0] = position.x;
//res[2][1] = position.y;
res = glm::translate(res, glm::vec3(position, z));
//float const s = sinf(rotation);
//float const c = cosf(rotation);
//res[0][0] = scale.x * c;
//res[0][1] = scale.x * s;
//res[1][0] = scale.y * -s;
//res[1][1] = scale.y * c;
res = glm::rotate(res, rotation, glm::vec3(0.f, 0.f, 1.f));
res = glm::scale(res, glm::vec3(scale, 1.f));
return res;
}
};
} // MM::Components

Some files were not shown because too many files have changed in this diff Show More