mirror of
https://github.com/nlohmann/json.git
synced 2026-10-01 12:10:32 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b15ec08275 | ||
|
|
93fe62fc0b |
+17
@@ -0,0 +1,17 @@
|
|||||||
|
arm_container:
|
||||||
|
image: gcc:latest
|
||||||
|
|
||||||
|
check_task:
|
||||||
|
check_script:
|
||||||
|
# the gcc image ships an outdated CMake, so fetch a recent prebuilt binary
|
||||||
|
# instead of compiling CMake from source
|
||||||
|
- wget -q https://github.com/Kitware/CMake/releases/download/v4.3.4/cmake-4.3.4-linux-aarch64.tar.gz
|
||||||
|
- tar xfz cmake-4.3.4-linux-aarch64.tar.gz
|
||||||
|
- export PATH="$(pwd)/cmake-4.3.4-linux-aarch64/bin:$PATH"
|
||||||
|
- cmake --version
|
||||||
|
- mkdir build
|
||||||
|
- cd build
|
||||||
|
- cmake .. -DJSON_FastTests=ON
|
||||||
|
- make -j4
|
||||||
|
- cd tests
|
||||||
|
- ctest -j4
|
||||||
+5
-10
@@ -1,15 +1,9 @@
|
|||||||
# bugprone-use-after-move (hicpp-invalid-access-moved is its alias) still flags
|
# TODO: The first three checks are only removed to get the CI going. They have to be addressed at some point.
|
||||||
# the basic_json move constructor, which forwards the whole object to its base
|
# TODO: portability-avoid-pragma-once: should be fixed eventually
|
||||||
# class (#5724), and two forwards in the error-message construction of
|
|
||||||
# at(KeyType&&) (json.hpp, both overloads: find(std::forward<KeyType>(key))
|
|
||||||
# followed by string_t(std::forward<KeyType>(key)) in the throw), which #5689
|
|
||||||
# rewrites. Re-enable both checks once those changes have landed.
|
|
||||||
# portability-avoid-pragma-once: kept disabled on purpose. #pragma once is accepted
|
|
||||||
# by every supported compiler, and tools/amalgamate/amalgamate.py strips it from
|
|
||||||
# single_include, so there is nothing left to fix here.
|
|
||||||
|
|
||||||
Checks: '*,
|
Checks: '*,
|
||||||
|
|
||||||
|
-portability-template-virtual-member-function,
|
||||||
-bugprone-use-after-move,
|
-bugprone-use-after-move,
|
||||||
-hicpp-invalid-access-moved,
|
-hicpp-invalid-access-moved,
|
||||||
|
|
||||||
@@ -43,6 +37,7 @@ Checks: '*,
|
|||||||
-google-readability-function-size,
|
-google-readability-function-size,
|
||||||
-google-runtime-float,
|
-google-runtime-float,
|
||||||
-google-runtime-int,
|
-google-runtime-int,
|
||||||
|
-google-runtime-references,
|
||||||
-hicpp-avoid-goto,
|
-hicpp-avoid-goto,
|
||||||
-hicpp-explicit-conversions,
|
-hicpp-explicit-conversions,
|
||||||
-hicpp-function-size,
|
-hicpp-function-size,
|
||||||
@@ -76,7 +71,6 @@ Checks: '*,
|
|||||||
-readability-magic-numbers,
|
-readability-magic-numbers,
|
||||||
-readability-redundant-access-specifiers,
|
-readability-redundant-access-specifiers,
|
||||||
-readability-redundant-parentheses,
|
-readability-redundant-parentheses,
|
||||||
-readability-redundant-typename,
|
|
||||||
-readability-simplify-boolean-expr,
|
-readability-simplify-boolean-expr,
|
||||||
-readability-uppercase-literal-suffix,
|
-readability-uppercase-literal-suffix,
|
||||||
-readability-use-concise-preprocessor-directives'
|
-readability-use-concise-preprocessor-directives'
|
||||||
@@ -87,4 +81,5 @@ CheckOptions:
|
|||||||
|
|
||||||
WarningsAsErrors: '*'
|
WarningsAsErrors: '*'
|
||||||
|
|
||||||
|
#HeaderFilterRegex: '.*nlohmann.*'
|
||||||
HeaderFilterRegex: '.*hpp$'
|
HeaderFilterRegex: '.*hpp$'
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ updates:
|
|||||||
interval: daily
|
interval: daily
|
||||||
cooldown:
|
cooldown:
|
||||||
default-days: 7
|
default-days: 7
|
||||||
ignore:
|
|
||||||
# astyle is deliberately pinned (see tools/astyle/requirements.txt): newer versions
|
|
||||||
# reformat the code, and the pinned version defines the formatting CI enforces
|
|
||||||
- dependency-name: astyle
|
|
||||||
|
|
||||||
- package-ecosystem: pip
|
- package-ecosystem: pip
|
||||||
directory: /tools/generate_natvis
|
directory: /tools/generate_natvis
|
||||||
|
|||||||
@@ -30,6 +30,14 @@ environment:
|
|||||||
CMAKE_OPTIONS: ""
|
CMAKE_OPTIONS: ""
|
||||||
GENERATOR: Visual Studio 14 2015
|
GENERATOR: Visual Studio 14 2015
|
||||||
|
|
||||||
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||||
|
configuration: Release
|
||||||
|
platform: x86
|
||||||
|
name: with_win_header
|
||||||
|
CXX_FLAGS: "/W4 /WX"
|
||||||
|
CMAKE_OPTIONS: ""
|
||||||
|
GENERATOR: Visual Studio 14 2015
|
||||||
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||||
configuration: Release
|
configuration: Release
|
||||||
platform: x86
|
platform: x86
|
||||||
@@ -66,6 +74,9 @@ install:
|
|||||||
- if "%platform%"=="x86" set GENERATOR_PLATFORM=Win32
|
- if "%platform%"=="x86" set GENERATOR_PLATFORM=Win32
|
||||||
|
|
||||||
before_build:
|
before_build:
|
||||||
|
# for with_win_header build, inject the inclusion of Windows.h to the single-header library
|
||||||
|
- ps: if ($env:name -Eq "with_win_header") { $header_path = "single_include\nlohmann\json.hpp" }
|
||||||
|
- ps: if ($env:name -Eq "with_win_header") { "#include <Windows.h>`n" + (Get-Content $header_path | Out-String) | Set-Content $header_path }
|
||||||
- cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On "%CMAKE_OPTIONS%"
|
- cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On "%CMAKE_OPTIONS%"
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
|
|||||||
@@ -45,23 +45,6 @@ labels:
|
|||||||
- label: "aspect: binary formats"
|
- label: "aspect: binary formats"
|
||||||
title: "(?i)(bson|cbor|msgpack|messagepack|ubjson|bjdata|bon8|binary format)"
|
title: "(?i)(bson|cbor|msgpack|messagepack|ubjson|bjdata|bon8|binary format)"
|
||||||
|
|
||||||
- label: "aspect: json_view"
|
|
||||||
files:
|
|
||||||
- "include/nlohmann/json_view\\.hpp"
|
|
||||||
- "include/nlohmann/detail/view/.*"
|
|
||||||
- "single_include/nlohmann/json_view\\.hpp"
|
|
||||||
- "tests/src/unit-json_view.*"
|
|
||||||
- "tests/src/fuzzer-parse_json_view\\.cpp"
|
|
||||||
- "tools/amalgamate/config_json_view\\.json"
|
|
||||||
- "docs/mkdocs/docs/features/json_view\\.md"
|
|
||||||
- "docs/mkdocs/docs/api/basic_json_(document|view)/.*"
|
|
||||||
- "docs/mkdocs/docs/api/(ordered_)?json_(document|view)\\.md"
|
|
||||||
- "docs/mkdocs/docs/examples/(basic_json_(document|view)__|(ordered_)?json_(document|view)).*"
|
|
||||||
- "tests/benchmarks/src/benchmarks_view\\.cpp"
|
|
||||||
|
|
||||||
- label: "aspect: json_view"
|
|
||||||
title: "(?i)(json_view|json_document|zero-copy)"
|
|
||||||
|
|
||||||
- label: "python"
|
- label: "python"
|
||||||
files:
|
files:
|
||||||
- "\\.py$"
|
- "\\.py$"
|
||||||
|
|||||||
@@ -2,23 +2,16 @@ name: "Check amalgamation"
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
# also check develop itself: a PR can be merged before its own run of this
|
|
||||||
# workflow completes (e.g. while it is still queued), leaving single_include
|
|
||||||
# stale on develop without any failing check
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- develop
|
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
cancel-in-progress: true
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
save:
|
save:
|
||||||
if: github.event_name == 'pull_request'
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
@@ -42,7 +35,6 @@ jobs:
|
|||||||
MAIN_DIR: ${{ github.workspace }}/main
|
MAIN_DIR: ${{ github.workspace }}/main
|
||||||
INCLUDE_DIR: ${{ github.workspace }}/main/single_include/nlohmann
|
INCLUDE_DIR: ${{ github.workspace }}/main/single_include/nlohmann
|
||||||
TOOL_DIR: ${{ github.workspace }}/tools/tools/amalgamate
|
TOOL_DIR: ${{ github.workspace }}/tools/tools/amalgamate
|
||||||
NATVIS_TOOL_DIR: ${{ github.workspace }}/tools/tools/generate_natvis
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
@@ -50,11 +42,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout pull request or pushed commit
|
- name: Checkout pull request
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
path: main
|
path: main
|
||||||
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Checkout tools
|
- name: Checkout tools
|
||||||
@@ -69,48 +61,6 @@ jobs:
|
|||||||
python3 -mvenv venv
|
python3 -mvenv venv
|
||||||
venv/bin/pip3 install -r $MAIN_DIR/tools/astyle/requirements.txt
|
venv/bin/pip3 install -r $MAIN_DIR/tools/astyle/requirements.txt
|
||||||
|
|
||||||
- name: Install generate_natvis dependencies
|
|
||||||
run: pip3 install -r $NATVIS_TOOL_DIR/requirements.txt
|
|
||||||
|
|
||||||
- name: Regenerate the tools/macro_builder tables in macro_scope.hpp
|
|
||||||
run: |
|
|
||||||
cd $MAIN_DIR
|
|
||||||
|
|
||||||
# Built from this PR's own tools/macro_builder/main.cpp, not a
|
|
||||||
# develop checkout: unlike amalgamate.py and generate_natvis.py,
|
|
||||||
# this tool has no other source of truth to check against (its
|
|
||||||
# own README documents that it must reproduce macro_scope.hpp
|
|
||||||
# byte for byte), so there is nothing to gain from checking out a
|
|
||||||
# separate copy, and doing so would make this step fail on a PR
|
|
||||||
# that adds support for a new dispatch table until that PR itself
|
|
||||||
# merges to develop, the same way generate_natvis.py's --version
|
|
||||||
# requirement briefly did.
|
|
||||||
TMPDIR=$(mktemp -d ./macro_builder_check.XXXXXX)
|
|
||||||
c++ -std=c++11 tools/macro_builder/main.cpp -o "$TMPDIR/macro_builder"
|
|
||||||
"$TMPDIR/macro_builder" > "$TMPDIR/paste.hpp"
|
|
||||||
"$TMPDIR/macro_builder" type_body > "$TMPDIR/type_body.hpp"
|
|
||||||
|
|
||||||
# Splice the (still unindented) generated blocks back into
|
|
||||||
# macro_scope.hpp; the astyle pass below indents their
|
|
||||||
# continuation lines the same way it does for the rest of
|
|
||||||
# include/, so a correctly regenerated file comes out unchanged.
|
|
||||||
awk -v newfile="$TMPDIR/paste.hpp" '
|
|
||||||
BEGIN { while ((getline line < newfile) > 0) { new = new line "\n" } }
|
|
||||||
/^#define NLOHMANN_JSON_EXPAND\( x \) x$/ { printf "%s", new; skip=1 }
|
|
||||||
skip && /^#define NLOHMANN_JSON_DOUBLE_PASTE63\(/ { skip=0; next }
|
|
||||||
skip { next }
|
|
||||||
{ print }
|
|
||||||
' include/nlohmann/detail/macro_scope.hpp > "$TMPDIR/macro_scope_1.hpp"
|
|
||||||
awk -v newfile="$TMPDIR/type_body.hpp" '
|
|
||||||
BEGIN { while ((getline line < newfile) > 0) { new = new line "\n" } }
|
|
||||||
/^#define NLOHMANN_JSON_TYPE_BODY\(Prefix, \.\.\.\)/ { printf "%s", new; skip=1 }
|
|
||||||
skip && /^[[:space:]]*NLOHMANN_JSON_TYPE_BODY_SENTINEL\)\)$/ { skip=0; next }
|
|
||||||
skip { next }
|
|
||||||
{ print }
|
|
||||||
' "$TMPDIR/macro_scope_1.hpp" > "$TMPDIR/macro_scope_2.hpp"
|
|
||||||
mv "$TMPDIR/macro_scope_2.hpp" include/nlohmann/detail/macro_scope.hpp
|
|
||||||
rm -rf "$TMPDIR"
|
|
||||||
|
|
||||||
- name: Regenerate amalgamation, formatting, and BUILD.bazel
|
- name: Regenerate amalgamation, formatting, and BUILD.bazel
|
||||||
run: |
|
run: |
|
||||||
cd $MAIN_DIR
|
cd $MAIN_DIR
|
||||||
@@ -118,15 +68,12 @@ jobs:
|
|||||||
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json.json -s .
|
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json.json -s .
|
||||||
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json_fwd.json -s .
|
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json_fwd.json -s .
|
||||||
cp include/nlohmann/json_literals.hpp $INCLUDE_DIR/json_literals.hpp
|
cp include/nlohmann/json_literals.hpp $INCLUDE_DIR/json_literals.hpp
|
||||||
# the configuration of json_view.hpp comes with the pull request until
|
|
||||||
# it is on develop; the tool itself is still develop's
|
|
||||||
python3 $TOOL_DIR/amalgamate.py -c $MAIN_DIR/tools/amalgamate/config_json_view.json -s .
|
|
||||||
|
|
||||||
# the header list of the Bazel "json" target must match the files in include/
|
# the header list of the Bazel "json" target must match the files in include/
|
||||||
cmake -P cmake/scripts/gen_bazel_build_file.cmake
|
cmake -P cmake/scripts/gen_bazel_build_file.cmake
|
||||||
|
|
||||||
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
||||||
$INCLUDE_DIR/json.hpp $INCLUDE_DIR/json_fwd.hpp $INCLUDE_DIR/json_view.hpp
|
$INCLUDE_DIR/json.hpp $INCLUDE_DIR/json_fwd.hpp
|
||||||
|
|
||||||
# fail loudly if a directory is renamed or removed: find would only warn
|
# fail loudly if a directory is renamed or removed: find would only warn
|
||||||
# about the missing path and silently drop its files from the check
|
# about the missing path and silently drop its files from the check
|
||||||
@@ -141,19 +88,6 @@ jobs:
|
|||||||
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
||||||
$(find $SOURCE_DIRS -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
|
$(find $SOURCE_DIRS -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
|
||||||
|
|
||||||
- name: Regenerate nlohmann_json.natvis
|
|
||||||
run: |
|
|
||||||
cd $MAIN_DIR
|
|
||||||
# Pass --version explicitly so this step also works with the tool
|
|
||||||
# copy from develop before this repository's own generate_natvis.py
|
|
||||||
# learns to derive the version itself: the older script requires
|
|
||||||
# --version, and the newer one accepts it as an explicit override.
|
|
||||||
ABI_MACROS=include/nlohmann/detail/abi_macros.hpp
|
|
||||||
VERSION_MAJOR=$(grep -m1 'define NLOHMANN_JSON_VERSION_MAJOR' $ABI_MACROS | grep -o '[0-9]\+')
|
|
||||||
VERSION_MINOR=$(grep -m1 'define NLOHMANN_JSON_VERSION_MINOR' $ABI_MACROS | grep -o '[0-9]\+')
|
|
||||||
VERSION_PATCH=$(grep -m1 'define NLOHMANN_JSON_VERSION_PATCH' $ABI_MACROS | grep -o '[0-9]\+')
|
|
||||||
python3 $NATVIS_TOOL_DIR/generate_natvis.py --version "$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" $MAIN_DIR
|
|
||||||
|
|
||||||
- name: Build patch and check for differences
|
- name: Build patch and check for differences
|
||||||
id: diff
|
id: diff
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
comment:
|
comment:
|
||||||
# push runs on develop have no PR to comment on (and no "pr" artifact)
|
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
||||||
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }}
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|||||||
@@ -7,16 +7,6 @@ on:
|
|||||||
- develop
|
- develop
|
||||||
paths:
|
paths:
|
||||||
- docs/mkdocs/**
|
- docs/mkdocs/**
|
||||||
# the site also embeds these files via pymdownx.snippets
|
|
||||||
# (mkdocs.yml sets restrict_base_path: false for this)
|
|
||||||
- .clang-tidy
|
|
||||||
- .github/CODE_OF_CONDUCT.md
|
|
||||||
- .github/CONTRIBUTING.md
|
|
||||||
- .github/SECURITY.md
|
|
||||||
- cmake/clang_flags.cmake
|
|
||||||
- cmake/gcc_flags.cmake
|
|
||||||
- tests/fmt_formatter/project/main.cpp
|
|
||||||
- tools/astyle/.astylerc
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
# we don't want to have concurrent jobs, and we don't want to cancel running jobs to avoid broken publications
|
# we don't want to have concurrent jobs, and we don't want to cancel running jobs to avoid broken publications
|
||||||
@@ -33,7 +23,7 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
if: github.repository == 'nlohmann/json'
|
if: github.repository == 'nlohmann/json'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||||
@@ -41,8 +31,6 @@ jobs:
|
|||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- name: Install virtual environment
|
- name: Install virtual environment
|
||||||
run: make install_venv -C docs/mkdocs
|
run: make install_venv -C docs/mkdocs
|
||||||
|
|||||||
@@ -52,13 +52,6 @@ jobs:
|
|||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --target ci_infer
|
run: cmake --build build --target ci_infer
|
||||||
- name: Archive Infer report
|
|
||||||
if: always()
|
|
||||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
||||||
with:
|
|
||||||
name: infer-report
|
|
||||||
path: ${{ github.workspace }}/build/build_infer/infer-out/report.txt
|
|
||||||
if-no-files-found: ignore
|
|
||||||
|
|
||||||
ci_static_analysis_ubuntu:
|
ci_static_analysis_ubuntu:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -85,7 +78,7 @@ jobs:
|
|||||||
|
|
||||||
ci_static_analysis_clang:
|
ci_static_analysis_clang:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: silkeh/clang:22
|
container: silkeh/clang:dev
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
target: [ci_test_clang, ci_clang_tidy, ci_test_clang_sanitizer, ci_clang_analyze, ci_single_binaries]
|
target: [ci_test_clang, ci_clang_tidy, ci_test_clang_sanitizer, ci_clang_analyze, ci_single_binaries]
|
||||||
@@ -104,13 +97,13 @@ jobs:
|
|||||||
|
|
||||||
ci_cmake_options:
|
ci_cmake_options:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ubuntu:24.04
|
container: ubuntu:focal
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
target: [ci_cmake_flags, ci_test_diagnostics, ci_test_diagnostic_positions, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls, ci_test_disableenumserialization, ci_test_disabletuplereferenceconversion, ci_test_skiplibraryversioncheck, ci_test_simdutf, ci_test_strict_nul_handling, ci_test_no_thread_local]
|
target: [ci_cmake_flags, ci_test_diagnostics, ci_test_diagnostic_positions, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls, ci_test_disableenumserialization, ci_test_skiplibraryversioncheck, ci_test_simdutf, ci_test_strict_nul_handling, ci_test_no_thread_local]
|
||||||
steps:
|
steps:
|
||||||
- name: Install build-essential
|
- name: Install build-essential
|
||||||
run: apt-get update ; apt-get install -y build-essential unzip wget git
|
run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
@@ -353,8 +346,6 @@ jobs:
|
|||||||
container: intel/oneapi-hpckit:latest
|
container: intel/oneapi-hpckit:latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
@@ -367,8 +358,6 @@ jobs:
|
|||||||
container: nvcr.io/nvidia/nvhpc:25.5-devel-cuda12.9-ubuntu22.04
|
container: nvcr.io/nvidia/nvhpc:25.5-devel-cuda12.9-ubuntu22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
@@ -414,21 +403,3 @@ jobs:
|
|||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --target ${{ matrix.target }}
|
run: cmake --build build --target ${{ matrix.target }}
|
||||||
|
|
||||||
# Native Linux ARM64 runner with the latest GCC. The ubuntu-24.04-arm label is
|
|
||||||
# only available for public repositories.
|
|
||||||
ci_test_arm64:
|
|
||||||
runs-on: ubuntu-24.04-arm
|
|
||||||
container: gcc:latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Get latest CMake and ninja
|
|
||||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
|
||||||
- name: Check that the job runs natively on arm64
|
|
||||||
run: uname -m && test "$(uname -m)" = aarch64
|
|
||||||
- name: Run CMake
|
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
|
||||||
- name: Build
|
|
||||||
run: cmake --build build --target ci_test_compiler_default
|
|
||||||
|
|||||||
@@ -87,8 +87,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Set extra CXX_FLAGS for latest std_version
|
- name: Set extra CXX_FLAGS for latest std_version
|
||||||
@@ -125,8 +123,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Run CMake (Release)
|
- name: Run CMake (Release)
|
||||||
run: cmake -S . -B build -G "Visual Studio 18 2026" -A ARM64 -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 18 2026" -A ARM64 -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||||
if: matrix.build_type == 'Release'
|
if: matrix.build_type == 'Release'
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"_comment": "Used by the ci_infer CMake target (#5715 item 4b). fail-on-issue makes CI fail on Infer findings; disable-issue-type is a type-level baseline for the ~174 pre-existing findings (all PULSE_UNNECESSARY_COPY*/PULSE_RESOURCE_LEAK/PULSE_CONST_REFABLE, mostly in test code) triaged in run https://github.com/nlohmann/json/actions/runs/35829411620 on commit 1054b2097, so CI fails only on a NEW issue type. Remove an entry here once its findings have been fixed or explicitly accepted.",
|
|
||||||
"fail-on-issue": true,
|
|
||||||
"disable-issue-type": [
|
|
||||||
"PULSE_UNNECESSARY_COPY_ASSIGNMENT",
|
|
||||||
"PULSE_UNNECESSARY_COPY",
|
|
||||||
"PULSE_UNNECESSARY_COPY_INTERMEDIATE",
|
|
||||||
"PULSE_UNNECESSARY_COPY_OPTIONAL",
|
|
||||||
"PULSE_RESOURCE_LEAK",
|
|
||||||
"PULSE_CONST_REFABLE"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -23,6 +23,10 @@ Files: tests/thirdparty/fifo_map/*
|
|||||||
Copyright: 2015-2017 Niels Lohmann
|
Copyright: 2015-2017 Niels Lohmann
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|
||||||
|
Files: tests/thirdparty/Fuzzer/*
|
||||||
|
Copyright: 2003-2022 LLVM Project.
|
||||||
|
License: Apache-2.0
|
||||||
|
|
||||||
Files: tests/thirdparty/imapdl/*
|
Files: tests/thirdparty/imapdl/*
|
||||||
Copyright: 2017 Georg Sauthoff <mail@gms.tf>
|
Copyright: 2017 Georg Sauthoff <mail@gms.tf>
|
||||||
License: GPL-3.0-only
|
License: GPL-3.0-only
|
||||||
|
|||||||
-14
@@ -20,7 +20,6 @@ cc_library(
|
|||||||
hdrs = [
|
hdrs = [
|
||||||
"include/nlohmann/adl_serializer.hpp",
|
"include/nlohmann/adl_serializer.hpp",
|
||||||
"include/nlohmann/byte_container_with_subtype.hpp",
|
"include/nlohmann/byte_container_with_subtype.hpp",
|
||||||
"include/nlohmann/detail/abi_config.hpp",
|
|
||||||
"include/nlohmann/detail/abi_macros.hpp",
|
"include/nlohmann/detail/abi_macros.hpp",
|
||||||
"include/nlohmann/detail/bit_ops.hpp",
|
"include/nlohmann/detail/bit_ops.hpp",
|
||||||
"include/nlohmann/detail/conversions/from_json.hpp",
|
"include/nlohmann/detail/conversions/from_json.hpp",
|
||||||
@@ -66,21 +65,9 @@ cc_library(
|
|||||||
"include/nlohmann/detail/string_escape.hpp",
|
"include/nlohmann/detail/string_escape.hpp",
|
||||||
"include/nlohmann/detail/string_utils.hpp",
|
"include/nlohmann/detail/string_utils.hpp",
|
||||||
"include/nlohmann/detail/value_t.hpp",
|
"include/nlohmann/detail/value_t.hpp",
|
||||||
"include/nlohmann/detail/view/builder.hpp",
|
|
||||||
"include/nlohmann/detail/view/document_data.hpp",
|
|
||||||
"include/nlohmann/detail/view/errors.hpp",
|
|
||||||
"include/nlohmann/detail/view/input.hpp",
|
|
||||||
"include/nlohmann/detail/view/macro_scope.hpp",
|
|
||||||
"include/nlohmann/detail/view/macro_unscope.hpp",
|
|
||||||
"include/nlohmann/detail/view/materialize.hpp",
|
|
||||||
"include/nlohmann/detail/view/node.hpp",
|
|
||||||
"include/nlohmann/detail/view/number.hpp",
|
|
||||||
"include/nlohmann/detail/view/scan.hpp",
|
|
||||||
"include/nlohmann/detail/view/string_ref.hpp",
|
|
||||||
"include/nlohmann/json.hpp",
|
"include/nlohmann/json.hpp",
|
||||||
"include/nlohmann/json_fwd.hpp",
|
"include/nlohmann/json_fwd.hpp",
|
||||||
"include/nlohmann/json_literals.hpp",
|
"include/nlohmann/json_literals.hpp",
|
||||||
"include/nlohmann/json_view.hpp",
|
|
||||||
"include/nlohmann/ordered_map.hpp",
|
"include/nlohmann/ordered_map.hpp",
|
||||||
"include/nlohmann/thirdparty/hedley/hedley.hpp",
|
"include/nlohmann/thirdparty/hedley/hedley.hpp",
|
||||||
"include/nlohmann/thirdparty/hedley/hedley_undef.hpp",
|
"include/nlohmann/thirdparty/hedley/hedley_undef.hpp",
|
||||||
@@ -93,7 +80,6 @@ cc_library(
|
|||||||
name = "singleheader-json",
|
name = "singleheader-json",
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"single_include/nlohmann/json.hpp",
|
"single_include/nlohmann/json.hpp",
|
||||||
"single_include/nlohmann/json_view.hpp",
|
|
||||||
],
|
],
|
||||||
includes = ["single_include"],
|
includes = ["single_include"],
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ option(JSON_Diagnostic_Positions "Enable diagnostic positions." OFF)
|
|||||||
option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON)
|
option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON)
|
||||||
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
||||||
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
||||||
option(JSON_DisableTupleReferenceConversion "Disable conversion from a one-element tuple of a JSON reference." OFF)
|
|
||||||
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
||||||
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
|
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
|
||||||
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
|
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
|
||||||
@@ -102,10 +101,6 @@ if (JSON_DisableEnumSerialization)
|
|||||||
message(STATUS "Enum integer serialization is disabled (JSON_DISABLE_ENUM_SERIALIZATION=1)")
|
message(STATUS "Enum integer serialization is disabled (JSON_DISABLE_ENUM_SERIALIZATION=1)")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (JSON_DisableTupleReferenceConversion)
|
|
||||||
message(STATUS "Tuple reference conversion is disabled (JSON_DISABLE_TUPLE_REFERENCE_CONVERSION=1)")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (JSON_LegacyDiscardedValueComparison)
|
if (JSON_LegacyDiscardedValueComparison)
|
||||||
message(STATUS "Legacy discarded value comparison enabled (JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1)")
|
message(STATUS "Legacy discarded value comparison enabled (JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1)")
|
||||||
endif()
|
endif()
|
||||||
@@ -148,7 +143,6 @@ target_compile_definitions(
|
|||||||
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0>
|
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0>
|
||||||
$<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0>
|
$<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0>
|
||||||
$<$<BOOL:${JSON_DisableEnumSerialization}>:JSON_DISABLE_ENUM_SERIALIZATION=1>
|
$<$<BOOL:${JSON_DisableEnumSerialization}>:JSON_DISABLE_ENUM_SERIALIZATION=1>
|
||||||
$<$<BOOL:${JSON_DisableTupleReferenceConversion}>:JSON_DISABLE_TUPLE_REFERENCE_CONVERSION=1>
|
|
||||||
$<$<BOOL:${JSON_Diagnostics}>:JSON_DIAGNOSTICS=1>
|
$<$<BOOL:${JSON_Diagnostics}>:JSON_DIAGNOSTICS=1>
|
||||||
$<$<BOOL:${JSON_Diagnostic_Positions}>:JSON_DIAGNOSTIC_POSITIONS=1>
|
$<$<BOOL:${JSON_Diagnostic_Positions}>:JSON_DIAGNOSTIC_POSITIONS=1>
|
||||||
$<$<BOOL:${JSON_LegacyDiscardedValueComparison}>:JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1>
|
$<$<BOOL:${JSON_LegacyDiscardedValueComparison}>:JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1>
|
||||||
|
|||||||
@@ -33,6 +33,17 @@ Further documentation:
|
|||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
> The folder `.github/workflows` is predetermined by GitHub.
|
> The folder `.github/workflows` is predetermined by GitHub.
|
||||||
|
|
||||||
|
### `.cirrus.yml`
|
||||||
|
|
||||||
|
Configuration file for the pipeline at [Cirrus CI](https://cirrus-ci.com/github/nlohmann/json).
|
||||||
|
|
||||||
|
Further documentation:
|
||||||
|
|
||||||
|
- [Writing tasks](https://cirrus-ci.org/guide/writing-tasks/)
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> The filename `.cirrus.yml` and position (root of the repository) are predetermined by Cirrus CI.
|
||||||
|
|
||||||
### `.github/external_ci/appveyor.yml`
|
### `.github/external_ci/appveyor.yml`
|
||||||
|
|
||||||
Configuration for the pipelines at [AppVeyor](https://ci.appveyor.com/project/nlohmann/json).
|
Configuration for the pipelines at [AppVeyor](https://ci.appveyor.com/project/nlohmann/json).
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: pretty clean ChangeLog.md release update_hedley update_hedley_undef BUILD.bazel natvis macro_builder_check
|
.PHONY: pretty clean ChangeLog.md release update_hedley update_hedley_undef BUILD.bazel
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# configuration
|
# configuration
|
||||||
@@ -23,10 +23,6 @@ AMALGAMATED_FILE=single_include/nlohmann/json.hpp
|
|||||||
AMALGAMATED_FWD_FILE=single_include/nlohmann/json_fwd.hpp
|
AMALGAMATED_FWD_FILE=single_include/nlohmann/json_fwd.hpp
|
||||||
# json_literals.hpp only includes <nlohmann/json.hpp>, so it is copied verbatim
|
# json_literals.hpp only includes <nlohmann/json.hpp>, so it is copied verbatim
|
||||||
AMALGAMATED_LITERALS_FILE=single_include/nlohmann/json_literals.hpp
|
AMALGAMATED_LITERALS_FILE=single_include/nlohmann/json_literals.hpp
|
||||||
AMALGAMATED_VIEW_FILE=single_include/nlohmann/json_view.hpp
|
|
||||||
|
|
||||||
# the header with the argument-counting macros generated by tools/macro_builder
|
|
||||||
MACRO_SCOPE_HPP=include/nlohmann/detail/macro_scope.hpp
|
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@@ -35,14 +31,18 @@ MACRO_SCOPE_HPP=include/nlohmann/detail/macro_scope.hpp
|
|||||||
|
|
||||||
# main target
|
# main target
|
||||||
all:
|
all:
|
||||||
@echo "amalgamate - amalgamate files single_include/nlohmann/json{,_fwd,_literals,_view}.hpp from the include/nlohmann sources"
|
@echo "amalgamate - amalgamate files single_include/nlohmann/json{,_fwd,_literals}.hpp from the include/nlohmann sources"
|
||||||
@echo "BUILD.bazel - regenerate the Bazel BUILD file from the include/nlohmann sources"
|
@echo "BUILD.bazel - regenerate the Bazel BUILD file from the include/nlohmann sources"
|
||||||
@echo "ChangeLog.md - generate ChangeLog file"
|
@echo "ChangeLog.md - generate ChangeLog file"
|
||||||
@echo "check-amalgamation - check whether sources have been amalgamated and BUILD.bazel is up to date"
|
@echo "check-amalgamation - check whether sources have been amalgamated and BUILD.bazel is up to date"
|
||||||
@echo "clean - remove built files"
|
@echo "clean - remove built files"
|
||||||
@echo "fuzzing - see tests/fuzzing.md for how to build and run the fuzzers"
|
@echo "doctest - compile example files and check their output"
|
||||||
@echo "macro_builder_check - check that macro_scope.hpp matches tools/macro_builder's output"
|
@echo "fuzz_testing - prepare fuzz testing of the JSON parser"
|
||||||
@echo "natvis - regenerate nlohmann_json.natvis from the current ABI tags and version"
|
@echo "fuzz_testing_bon8 - prepare fuzz testing of the BON8 parser"
|
||||||
|
@echo "fuzz_testing_bson - prepare fuzz testing of the BSON parser"
|
||||||
|
@echo "fuzz_testing_cbor - prepare fuzz testing of the CBOR parser"
|
||||||
|
@echo "fuzz_testing_msgpack - prepare fuzz testing of the MessagePack parser"
|
||||||
|
@echo "fuzz_testing_ubjson - prepare fuzz testing of the UBJSON parser"
|
||||||
@echo "pretty - beautify code with Artistic Style"
|
@echo "pretty - beautify code with Artistic Style"
|
||||||
@echo "run_benchmarks - build and run benchmarks"
|
@echo "run_benchmarks - build and run benchmarks"
|
||||||
@echo "update_hedley - download Hedley and regenerate hedley.hpp / hedley_undef.hpp"
|
@echo "update_hedley - download Hedley and regenerate hedley.hpp / hedley_undef.hpp"
|
||||||
@@ -61,6 +61,74 @@ run_benchmarks:
|
|||||||
cd cmake-build-benchmarks ; ./json_benchmarks
|
cd cmake-build-benchmarks ; ./json_benchmarks
|
||||||
|
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
# fuzzing
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
# the overall fuzz testing target
|
||||||
|
fuzz_testing:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_afl_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_afl_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzz_testing_bon8:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_bon8_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_bon8_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data -size -5k -name *.bon8 | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzz_testing_bson:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_bson_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_bson_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data -size -5k -name *.bson | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzz_testing_cbor:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_cbor_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_cbor_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data -size -5k -name *.cbor | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzz_testing_msgpack:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_msgpack_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_msgpack_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data -size -5k -name *.msgpack | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzz_testing_ubjson:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_ubjson_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_ubjson_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data -size -5k -name *.ubjson | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzzing-start:
|
||||||
|
afl-fuzz -S fuzzer1 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer2 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer3 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer4 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer5 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer6 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer7 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -M fuzzer0 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer
|
||||||
|
|
||||||
|
fuzzing-stop:
|
||||||
|
-killall fuzzer
|
||||||
|
-killall afl-fuzz
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Static analysis
|
# Static analysis
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@@ -88,10 +156,14 @@ install_astyle:
|
|||||||
|
|
||||||
# call the Artistic Style pretty printer on all source files
|
# call the Artistic Style pretty printer on all source files
|
||||||
pretty: install_astyle
|
pretty: install_astyle
|
||||||
$(ASTYLE) --project=tools/astyle/.astylerc $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE) $(AMALGAMATED_VIEW_FILE) docs/mkdocs/docs/examples/*.cpp docs/mkdocs/docs/examples/*.hpp
|
$(ASTYLE) --project=tools/astyle/.astylerc $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE) docs/mkdocs/docs/examples/*.cpp
|
||||||
|
|
||||||
|
# call the Clang-Format on all source files
|
||||||
|
pretty_format:
|
||||||
|
for FILE in $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/mkdocs/docs/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done
|
||||||
|
|
||||||
# create single header files and pretty print
|
# create single header files and pretty print
|
||||||
amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE) $(AMALGAMATED_VIEW_FILE)
|
amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE)
|
||||||
$(MAKE) pretty
|
$(MAKE) pretty
|
||||||
|
|
||||||
# call the amalgamation tool for json.hpp
|
# call the amalgamation tool for json.hpp
|
||||||
@@ -106,52 +178,23 @@ $(AMALGAMATED_FWD_FILE): $(SRCS)
|
|||||||
$(AMALGAMATED_LITERALS_FILE): include/nlohmann/json_literals.hpp
|
$(AMALGAMATED_LITERALS_FILE): include/nlohmann/json_literals.hpp
|
||||||
cp include/nlohmann/json_literals.hpp $(AMALGAMATED_LITERALS_FILE)
|
cp include/nlohmann/json_literals.hpp $(AMALGAMATED_LITERALS_FILE)
|
||||||
|
|
||||||
# call the amalgamation tool for json_view.hpp (keeps including json.hpp)
|
|
||||||
$(AMALGAMATED_VIEW_FILE): $(SRCS)
|
|
||||||
tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json_view.json -s . --verbose=yes
|
|
||||||
# regenerate nlohmann_json.natvis from the ABI tags and version in include/nlohmann/detail/abi_macros.hpp
|
|
||||||
natvis:
|
|
||||||
python3 tools/generate_natvis/generate_natvis.py .
|
|
||||||
|
|
||||||
# regenerate the two tools/macro_builder blocks of $(MACRO_SCOPE_HPP) (see its README.md) and diff against the
|
|
||||||
# checked-in header; phony, because it never writes $(MACRO_SCOPE_HPP) itself
|
|
||||||
macro_builder_check:
|
|
||||||
@set -e; \
|
|
||||||
TMPDIR=$$(mktemp -d ./macro_builder_check.XXXXXX); \
|
|
||||||
trap 'rm -rf "$$TMPDIR"' EXIT; \
|
|
||||||
$(CXX) -std=c++11 tools/macro_builder/main.cpp -o "$$TMPDIR/macro_builder"; \
|
|
||||||
"$$TMPDIR/macro_builder" > "$$TMPDIR/paste.hpp"; \
|
|
||||||
"$$TMPDIR/macro_builder" type_body > "$$TMPDIR/type_body.hpp"; \
|
|
||||||
$(ASTYLE) --project=tools/astyle/.astylerc --suffix=none --quiet "$$TMPDIR/paste.hpp" "$$TMPDIR/type_body.hpp"; \
|
|
||||||
sed -n '/^#define NLOHMANN_JSON_EXPAND( x ) x$$/,/^#define NLOHMANN_JSON_DOUBLE_PASTE63(/p' $(MACRO_SCOPE_HPP) > "$$TMPDIR/paste_actual.hpp"; \
|
|
||||||
sed -n '/^#define NLOHMANN_JSON_TYPE_BODY(Prefix, \.\.\.)/,/^ NLOHMANN_JSON_TYPE_BODY_SENTINEL))$$/p' $(MACRO_SCOPE_HPP) > "$$TMPDIR/type_body_actual.hpp"; \
|
|
||||||
diff "$$TMPDIR/paste.hpp" "$$TMPDIR/paste_actual.hpp" || (echo "===================================================================\n $(MACRO_SCOPE_HPP) (NLOHMANN_JSON_EXPAND..NLOHMANN_JSON_DOUBLE_PASTE63) is out of date!\n Regenerate it, see tools/macro_builder/README.md.\n===================================================================" ; exit 1); \
|
|
||||||
diff "$$TMPDIR/type_body.hpp" "$$TMPDIR/type_body_actual.hpp" || (echo "===================================================================\n $(MACRO_SCOPE_HPP) (NLOHMANN_JSON_TYPE_BODY) is out of date!\n Regenerate it, see tools/macro_builder/README.md.\n===================================================================" ; exit 1)
|
|
||||||
|
|
||||||
# check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources
|
# check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources
|
||||||
|
# Note: this target is called by Travis
|
||||||
check-amalgamation:
|
check-amalgamation:
|
||||||
@mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~
|
@mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~
|
||||||
@mv $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~
|
@mv $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~
|
||||||
@mv $(AMALGAMATED_LITERALS_FILE) $(AMALGAMATED_LITERALS_FILE)~
|
@mv $(AMALGAMATED_LITERALS_FILE) $(AMALGAMATED_LITERALS_FILE)~
|
||||||
@mv $(AMALGAMATED_VIEW_FILE) $(AMALGAMATED_VIEW_FILE)~
|
|
||||||
@$(MAKE) amalgamate
|
@$(MAKE) amalgamate
|
||||||
@diff $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE) ; false)
|
@diff $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE) ; false)
|
||||||
@diff $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE) ; false)
|
@diff $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE) ; false)
|
||||||
@diff $(AMALGAMATED_LITERALS_FILE) $(AMALGAMATED_LITERALS_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_LITERALS_FILE)~ $(AMALGAMATED_LITERALS_FILE) ; false)
|
@diff $(AMALGAMATED_LITERALS_FILE) $(AMALGAMATED_LITERALS_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_LITERALS_FILE)~ $(AMALGAMATED_LITERALS_FILE) ; false)
|
||||||
@diff $(AMALGAMATED_VIEW_FILE) $(AMALGAMATED_VIEW_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_VIEW_FILE)~ $(AMALGAMATED_VIEW_FILE) ; false)
|
|
||||||
@mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE)
|
@mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE)
|
||||||
@mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE)
|
@mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE)
|
||||||
@mv $(AMALGAMATED_LITERALS_FILE)~ $(AMALGAMATED_LITERALS_FILE)
|
@mv $(AMALGAMATED_LITERALS_FILE)~ $(AMALGAMATED_LITERALS_FILE)
|
||||||
@mv $(AMALGAMATED_VIEW_FILE)~ $(AMALGAMATED_VIEW_FILE)
|
|
||||||
@mv BUILD.bazel BUILD.bazel~
|
@mv BUILD.bazel BUILD.bazel~
|
||||||
@$(MAKE) BUILD.bazel
|
@$(MAKE) BUILD.bazel
|
||||||
@diff BUILD.bazel BUILD.bazel~ || (echo "===================================================================\n BUILD.bazel is out of date! Please run 'make BUILD.bazel'.\n===================================================================" ; mv BUILD.bazel~ BUILD.bazel ; false)
|
@diff BUILD.bazel BUILD.bazel~ || (echo "===================================================================\n BUILD.bazel is out of date! Please run 'make BUILD.bazel'.\n===================================================================" ; mv BUILD.bazel~ BUILD.bazel ; false)
|
||||||
@mv BUILD.bazel~ BUILD.bazel
|
@mv BUILD.bazel~ BUILD.bazel
|
||||||
@mv nlohmann_json.natvis nlohmann_json.natvis~
|
|
||||||
@$(MAKE) natvis
|
|
||||||
@diff nlohmann_json.natvis nlohmann_json.natvis~ || (echo "===================================================================\n nlohmann_json.natvis is out of date! Please run 'make natvis'.\n===================================================================" ; mv nlohmann_json.natvis~ nlohmann_json.natvis ; false)
|
|
||||||
@mv nlohmann_json.natvis~ nlohmann_json.natvis
|
|
||||||
@$(MAKE) macro_builder_check
|
|
||||||
|
|
||||||
# generate the Bazel BUILD file; phony, because a removed header would not trigger a rebuild
|
# generate the Bazel BUILD file; phony, because a removed header would not trigger a rebuild
|
||||||
BUILD.bazel:
|
BUILD.bazel:
|
||||||
@@ -188,7 +231,7 @@ json.tar.xz:
|
|||||||
# We use `-X` to make the resulting ZIP file reproducible, see
|
# We use `-X` to make the resulting ZIP file reproducible, see
|
||||||
# <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>.
|
# <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>.
|
||||||
include.zip: BUILD.bazel
|
include.zip: BUILD.bazel
|
||||||
zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE) $(AMALGAMATED_VIEW_FILE) BUILD.bazel MODULE.bazel meson.build LICENSE.MIT
|
zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE) BUILD.bazel MODULE.bazel meson.build LICENSE.MIT
|
||||||
|
|
||||||
# Create the files for a release and add signatures and hashes.
|
# Create the files for a release and add signatures and hashes.
|
||||||
release: include.zip json.tar.xz
|
release: include.zip json.tar.xz
|
||||||
@@ -198,14 +241,12 @@ release: include.zip json.tar.xz
|
|||||||
gpg --armor --detach-sig $(AMALGAMATED_FILE)
|
gpg --armor --detach-sig $(AMALGAMATED_FILE)
|
||||||
gpg --armor --detach-sig $(AMALGAMATED_FWD_FILE)
|
gpg --armor --detach-sig $(AMALGAMATED_FWD_FILE)
|
||||||
gpg --armor --detach-sig $(AMALGAMATED_LITERALS_FILE)
|
gpg --armor --detach-sig $(AMALGAMATED_LITERALS_FILE)
|
||||||
gpg --armor --detach-sig $(AMALGAMATED_VIEW_FILE)
|
|
||||||
gpg --armor --detach-sig json.tar.xz
|
gpg --armor --detach-sig json.tar.xz
|
||||||
cp $(AMALGAMATED_FILE) release_files
|
cp $(AMALGAMATED_FILE) release_files
|
||||||
cp $(AMALGAMATED_FWD_FILE) release_files
|
cp $(AMALGAMATED_FWD_FILE) release_files
|
||||||
cp $(AMALGAMATED_LITERALS_FILE) release_files
|
cp $(AMALGAMATED_LITERALS_FILE) release_files
|
||||||
cp $(AMALGAMATED_VIEW_FILE) release_files
|
mv $(AMALGAMATED_FILE).asc $(AMALGAMATED_FWD_FILE).asc $(AMALGAMATED_LITERALS_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files
|
||||||
mv $(AMALGAMATED_FILE).asc $(AMALGAMATED_FWD_FILE).asc $(AMALGAMATED_LITERALS_FILE).asc $(AMALGAMATED_VIEW_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files
|
cd release_files ; shasum -a 256 json.hpp include.zip json.tar.xz > hashes.txt
|
||||||
cd release_files ; shasum -a 256 $$(find . -type f -not -name '*.asc' | sed 's|^\./||' | sort) > hashes.txt
|
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@@ -215,6 +256,7 @@ release: include.zip json.tar.xz
|
|||||||
# clean up
|
# clean up
|
||||||
clean:
|
clean:
|
||||||
rm -fr fuzz fuzz-testing *.dSYM tests/*.dSYM
|
rm -fr fuzz fuzz-testing *.dSYM tests/*.dSYM
|
||||||
|
rm -fr benchmarks/files/numbers/*.json
|
||||||
rm -fr cmake-build-benchmarks fuzz-testing cmake-build-pvs-studio release_files
|
rm -fr cmake-build-benchmarks fuzz-testing cmake-build-pvs-studio release_files
|
||||||
$(MAKE) clean -Cdocs
|
$(MAKE) clean -Cdocs
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
[](https://coveralls.io/github/nlohmann/json?branch=develop)
|
[](https://coveralls.io/github/nlohmann/json?branch=develop)
|
||||||
[](https://scan.coverity.com/projects/nlohmann-json)
|
[](https://scan.coverity.com/projects/nlohmann-json)
|
||||||
[](https://app.codacy.com/gh/nlohmann/json/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
[](https://app.codacy.com/gh/nlohmann/json/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
||||||
|
[](https://cirrus-ci.com/github/nlohmann/json)
|
||||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:json)
|
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:json)
|
||||||
[](https://wandbox.org/permlink/1mp10JbaANo6FUc7)
|
[](https://wandbox.org/permlink/1mp10JbaANo6FUc7)
|
||||||
[](https://json.nlohmann.me)
|
[](https://json.nlohmann.me)
|
||||||
@@ -1188,14 +1189,6 @@ binary.set_subtype(0x10);
|
|||||||
auto cbor = json::to_msgpack(j); // 0xD5 (fixext2), 0x10, 0xCA, 0xFE
|
auto cbor = json::to_msgpack(j); // 0xD5 (fixext2), 0x10, 0xCA, 0xFE
|
||||||
```
|
```
|
||||||
|
|
||||||
### Zero-copy views
|
|
||||||
|
|
||||||
Header `<nlohmann/json_view.hpp>` adds `json_document`/`json_view`, a read-only, non-owning way to look at a parsed
|
|
||||||
JSON text: parsing builds a flat index (16 bytes per value) instead of a tree, strings and numbers stay in the source
|
|
||||||
text, and `materialize()` builds a `json` value for a subtree only when you actually need one. See
|
|
||||||
[Zero-copy JSON views](https://json.nlohmann.me/features/json_view/) for the details, including which inputs are
|
|
||||||
borrowed and which are copied.
|
|
||||||
|
|
||||||
## Customers
|
## Customers
|
||||||
|
|
||||||
The library is used in multiple projects, applications, operating systems, etc. The list below is not exhaustive, but the result of an internet search. If you know further customers of the library, please let me know, see [contact](#contact).
|
The library is used in multiple projects, applications, operating systems, etc. The list below is not exhaustive, but the result of an internet search. If you know further customers of the library, please let me know, see [contact](#contact).
|
||||||
@@ -1402,8 +1395,7 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
|
|||||||
- The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the [MIT License](https://opensource.org/licenses/MIT) (see above). Copyright © 2009 [Florian Loitsch](https://florian.loitsch.com/)
|
- The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the [MIT License](https://opensource.org/licenses/MIT) (see above). Copyright © 2009 [Florian Loitsch](https://florian.loitsch.com/)
|
||||||
- The class contains a copy of [Hedley](https://nemequ.github.io/hedley/) from Evan Nemerson which is licensed as [CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/).
|
- The class contains a copy of [Hedley](https://nemequ.github.io/hedley/) from Evan Nemerson which is licensed as [CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/).
|
||||||
- The class contains parts of [Google Abseil](https://github.com/abseil/abseil-cpp) which is licensed under the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0).
|
- The class contains parts of [Google Abseil](https://github.com/abseil/abseil-cpp) which is licensed under the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0).
|
||||||
- The class contains an adapted version of the Eisel-Lemire algorithm, its table of powers of five, and its digit comparison for long numbers from [fast_float](https://github.com/fastfloat/fast_float) by Daniel Lemire and contributors, which is available under the [MIT License](https://opensource.org/licenses/MIT) (used here), the Apache 2.0 License, and the Boost Software License. Copyright © 2021 The fast_float authors
|
- The class contains an adapted version of the Eisel-Lemire algorithm and its table of powers of five from [fast_float](https://github.com/fastfloat/fast_float) by Daniel Lemire and contributors, which is available under the [MIT License](https://opensource.org/licenses/MIT) (used here), the Apache 2.0 License, and the Boost Software License. Copyright © 2021 The fast_float authors
|
||||||
- The view's parser (`<nlohmann/json_view.hpp>`) contains techniques and code adapted from [yyjson](https://github.com/ibireme/yyjson) by YaoYuan, which is licensed under the [MIT License](https://opensource.org/licenses/MIT) (see above): table-driven decoding of `\u` escapes and fixed-offset unrolled checks.
|
|
||||||
|
|
||||||
<img align="right" src="https://git.fsfe.org/reuse/reuse-ci/raw/branch/master/reuse-horizontal.png" alt="REUSE Software">
|
<img align="right" src="https://git.fsfe.org/reuse/reuse-ci/raw/branch/master/reuse-horizontal.png" alt="REUSE Software">
|
||||||
|
|
||||||
|
|||||||
+100
-142
@@ -8,24 +8,24 @@ set(N 10)
|
|||||||
include(FindPython3)
|
include(FindPython3)
|
||||||
find_package(Python3 COMPONENTS Interpreter)
|
find_package(Python3 COMPONENTS Interpreter)
|
||||||
|
|
||||||
find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-22 clang++-21 clang++-20 clang++-19 clang++-18 clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
|
find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-20 clang++-19 clang++-18 clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
|
||||||
execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION)
|
execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
|
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
|
||||||
|
|
||||||
find_program(CLANG_TIDY_TOOL NAMES clang-tidy-22 clang-tidy-21 clang-tidy-20 clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy)
|
find_program(CLANG_TIDY_TOOL NAMES clang-tidy-20 clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy)
|
||||||
execute_process(COMMAND ${CLANG_TIDY_TOOL} --version OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION)
|
execute_process(COMMAND ${CLANG_TIDY_TOOL} --version OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Clang-Tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})")
|
message(STATUS "🔖 Clang-Tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})")
|
||||||
|
|
||||||
message(STATUS "🔖 CMake ${CMAKE_VERSION} (${CMAKE_COMMAND})")
|
message(STATUS "🔖 CMake ${CMAKE_VERSION} (${CMAKE_COMMAND})")
|
||||||
|
|
||||||
find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++ g++-16 g++-15 g++-14 g++-13 g++-12 g++-11 g++-10)
|
find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++ g++-15 g++-14 g++-13 g++-12 g++-11 g++-10)
|
||||||
execute_process(COMMAND ${GCC_TOOL} --version OUTPUT_VARIABLE GCC_TOOL_VERSION ERROR_VARIABLE GCC_TOOL_VERSION)
|
execute_process(COMMAND ${GCC_TOOL} --version OUTPUT_VARIABLE GCC_TOOL_VERSION ERROR_VARIABLE GCC_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})")
|
message(STATUS "🔖 GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})")
|
||||||
|
|
||||||
find_program(GCOV_TOOL NAMES gcov-HEAD gcov gcov-16 gcov-15 gcov-14 gcov-13 gcov-12 gcov-11 gcov-10)
|
find_program(GCOV_TOOL NAMES gcov-HEAD gcov gcov-15 gcov-14 gcov-13 gcov-12 gcov-11 gcov-10)
|
||||||
execute_process(COMMAND ${GCOV_TOOL} --version OUTPUT_VARIABLE GCOV_TOOL_VERSION ERROR_VARIABLE GCOV_TOOL_VERSION)
|
execute_process(COMMAND ${GCOV_TOOL} --version OUTPUT_VARIABLE GCOV_TOOL_VERSION ERROR_VARIABLE GCOV_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCOV_TOOL_VERSION "${GCOV_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCOV_TOOL_VERSION "${GCOV_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 GCOV ${GCOV_TOOL_VERSION} (${GCOV_TOOL})")
|
message(STATUS "🔖 GCOV ${GCOV_TOOL_VERSION} (${GCOV_TOOL})")
|
||||||
@@ -40,14 +40,6 @@ execute_process(COMMAND ${IWYU_TOOL} --version OUTPUT_VARIABLE IWYU_TOOL_VERSION
|
|||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" IWYU_TOOL_VERSION "${IWYU_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" IWYU_TOOL_VERSION "${IWYU_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 include-what-you-use ${IWYU_TOOL_VERSION} (${IWYU_TOOL})")
|
message(STATUS "🔖 include-what-you-use ${IWYU_TOOL_VERSION} (${IWYU_TOOL})")
|
||||||
|
|
||||||
# CMake's CXX_INCLUDE_WHAT_YOU_USE launcher runs IWYU during the normal compile step (useful to see
|
|
||||||
# diagnostics inline), but CMake's own __run_co_compile wrapper does not propagate the launched
|
|
||||||
# tool's exit code to the build, so IWYU's own "-Xiwyu --error" cannot fail that step (verified: a
|
|
||||||
# deliberately-unused #include in a header still lets `cmake --build` finish with exit code 0).
|
|
||||||
# iwyu_tool.py, which ships with IWYU, reads compile_commands.json and does return a non-zero exit
|
|
||||||
# code for any analyzed file with findings; ci_single_binaries uses it to actually fail on findings.
|
|
||||||
find_program(IWYU_TOOL_PY NAMES iwyu_tool iwyu_tool.py iwyu-tool)
|
|
||||||
|
|
||||||
find_program(INFER_TOOL NAMES infer)
|
find_program(INFER_TOOL NAMES infer)
|
||||||
execute_process(COMMAND ${INFER_TOOL} --version OUTPUT_VARIABLE INFER_TOOL_VERSION ERROR_VARIABLE INFER_TOOL_VERSION)
|
execute_process(COMMAND ${INFER_TOOL} --version OUTPUT_VARIABLE INFER_TOOL_VERSION ERROR_VARIABLE INFER_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" INFER_TOOL_VERSION "${INFER_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" INFER_TOOL_VERSION "${INFER_TOOL_VERSION}")
|
||||||
@@ -63,6 +55,12 @@ execute_process(COMMAND ${NINJA_TOOL} --version OUTPUT_VARIABLE NINJA_TOOL_VERSI
|
|||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" NINJA_TOOL_VERSION "${NINJA_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" NINJA_TOOL_VERSION "${NINJA_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Ninja ${NINJA_TOOL_VERSION} (${NINJA_TOOL})")
|
message(STATUS "🔖 Ninja ${NINJA_TOOL_VERSION} (${NINJA_TOOL})")
|
||||||
|
|
||||||
|
find_program(OCLINT_TOOL NAMES oclint-json-compilation-database)
|
||||||
|
find_program(OCLINT_VERSION_TOOL NAMES oclint)
|
||||||
|
execute_process(COMMAND ${OCLINT_VERSION_TOOL} --version OUTPUT_VARIABLE OCLINT_TOOL_VERSION ERROR_VARIABLE OCLINT_TOOL_VERSION)
|
||||||
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" OCLINT_TOOL_VERSION "${OCLINT_TOOL_VERSION}")
|
||||||
|
message(STATUS "🔖 OCLint ${OCLINT_TOOL_VERSION} (${OCLINT_TOOL})")
|
||||||
|
|
||||||
find_program(VALGRIND_TOOL NAMES valgrind)
|
find_program(VALGRIND_TOOL NAMES valgrind)
|
||||||
execute_process(COMMAND ${VALGRIND_TOOL} --version OUTPUT_VARIABLE VALGRIND_TOOL_VERSION ERROR_VARIABLE VALGRIND_TOOL_VERSION)
|
execute_process(COMMAND ${VALGRIND_TOOL} --version OUTPUT_VARIABLE VALGRIND_TOOL_VERSION ERROR_VARIABLE VALGRIND_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" VALGRIND_TOOL_VERSION "${VALGRIND_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" VALGRIND_TOOL_VERSION "${VALGRIND_TOOL_VERSION}")
|
||||||
@@ -130,16 +128,16 @@ foreach(CXX_STANDARD 11 14 17 20 23 26)
|
|||||||
COMMENT "Compile and test with Clang for C++${CXX_STANDARD}"
|
COMMENT "Compile and test with Clang for C++${CXX_STANDARD}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# pass -stdlib=libc++ through CXXFLAGS: an explicit -DCMAKE_CXX_FLAGS would make CMake ignore CXXFLAGS
|
|
||||||
add_custom_target(ci_test_clang_libcxx_cxx${CXX_STANDARD}
|
add_custom_target(ci_test_clang_libcxx_cxx${CXX_STANDARD}
|
||||||
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS};-stdlib=libc++" ${CMAKE_COMMAND}
|
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||||
-DJSON_TestStandards=${CXX_STANDARD}
|
-DJSON_TestStandards=${CXX_STANDARD}
|
||||||
|
-DCMAKE_CXX_FLAGS="-stdlib=libc++"
|
||||||
-DCMAKE_EXE_LINKER_FLAGS="-lc++abi"
|
-DCMAKE_EXE_LINKER_FLAGS="-lc++abi"
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD}
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
||||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD}
|
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||||
COMMENT "Compile and test with Clang for C++${CXX_STANDARD} (libc++)"
|
COMMENT "Compile and test with Clang for C++${CXX_STANDARD} (libc++)"
|
||||||
)
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
@@ -278,20 +276,6 @@ add_custom_target(ci_test_disableenumserialization
|
|||||||
COMMENT "Compile and test with enum serialization disabled"
|
COMMENT "Compile and test with enum serialization disabled"
|
||||||
)
|
)
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Disable conversion from a one-element tuple of a JSON reference.
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
add_custom_target(ci_test_disabletuplereferenceconversion
|
|
||||||
COMMAND ${CMAKE_COMMAND}
|
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
|
||||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_DisableTupleReferenceConversion=ON
|
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_disabletuplereferenceconversion
|
|
||||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_disabletuplereferenceconversion
|
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_disabletuplereferenceconversion && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
|
||||||
COMMENT "Compile and test with tuple reference conversion disabled"
|
|
||||||
)
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Skip the multiple-inclusion library version check.
|
# Skip the multiple-inclusion library version check.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -378,30 +362,21 @@ add_custom_target(ci_test_clang_sanitizer
|
|||||||
# Check if header is amalgamated and sources are properly indented.
|
# Check if header is amalgamated and sources are properly indented.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Same file set as .github/workflows/check_amalgamation.yml, so a direct push to develop/master/release/*
|
|
||||||
# (which only this CMake target checks, not the pull_request-only workflow) is held to the same standard.
|
|
||||||
file(GLOB_RECURSE INDENT_FILES
|
file(GLOB_RECURSE INDENT_FILES
|
||||||
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.hpp
|
${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp
|
||||||
|
${PROJECT_SOURCE_DIR}/tests/src/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/tests/src/*.hpp
|
||||||
|
${PROJECT_SOURCE_DIR}/tests/benchmarks/src/benchmarks.cpp
|
||||||
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cpp
|
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cpp
|
||||||
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cu
|
|
||||||
${PROJECT_SOURCE_DIR}/include/*.hpp
|
|
||||||
${PROJECT_SOURCE_DIR}/include/*.cpp
|
|
||||||
${PROJECT_SOURCE_DIR}/include/*.cu
|
|
||||||
${PROJECT_SOURCE_DIR}/tests/*.hpp
|
|
||||||
${PROJECT_SOURCE_DIR}/tests/*.cpp
|
|
||||||
${PROJECT_SOURCE_DIR}/tests/*.cu
|
|
||||||
)
|
)
|
||||||
list(FILTER INDENT_FILES EXCLUDE REGEX "/tests/thirdparty/|/tests/abi/include/nlohmann/")
|
|
||||||
|
|
||||||
set(include_dir ${PROJECT_SOURCE_DIR}/single_include/nlohmann)
|
set(include_dir ${PROJECT_SOURCE_DIR}/single_include/nlohmann)
|
||||||
set(tool_dir ${PROJECT_SOURCE_DIR}/tools/amalgamate)
|
set(tool_dir ${PROJECT_SOURCE_DIR}/tools/amalgamate)
|
||||||
add_custom_target(ci_test_amalgamation
|
add_custom_target(ci_test_amalgamation
|
||||||
COMMAND rm -fr ${include_dir}/json.hpp~ ${include_dir}/json_fwd.hpp~ ${include_dir}/json_literals.hpp~ ${include_dir}/json_view.hpp~
|
COMMAND rm -fr ${include_dir}/json.hpp~ ${include_dir}/json_fwd.hpp~ ${include_dir}/json_literals.hpp~
|
||||||
COMMAND cp ${include_dir}/json.hpp ${include_dir}/json.hpp~
|
COMMAND cp ${include_dir}/json.hpp ${include_dir}/json.hpp~
|
||||||
COMMAND cp ${include_dir}/json_fwd.hpp ${include_dir}/json_fwd.hpp~
|
COMMAND cp ${include_dir}/json_fwd.hpp ${include_dir}/json_fwd.hpp~
|
||||||
COMMAND cp ${include_dir}/json_literals.hpp ${include_dir}/json_literals.hpp~
|
COMMAND cp ${include_dir}/json_literals.hpp ${include_dir}/json_literals.hpp~
|
||||||
COMMAND cp ${include_dir}/json_view.hpp ${include_dir}/json_view.hpp~
|
|
||||||
COMMAND cp ${PROJECT_SOURCE_DIR}/BUILD.bazel ${PROJECT_SOURCE_DIR}/BUILD.bazel~
|
|
||||||
|
|
||||||
COMMAND ${Python3_EXECUTABLE} -mvenv venv_astyle
|
COMMAND ${Python3_EXECUTABLE} -mvenv venv_astyle
|
||||||
COMMAND venv_astyle/bin/pip3 --quiet install -r ${CMAKE_SOURCE_DIR}/tools/astyle/requirements.txt
|
COMMAND venv_astyle/bin/pip3 --quiet install -r ${CMAKE_SOURCE_DIR}/tools/astyle/requirements.txt
|
||||||
@@ -410,21 +385,17 @@ add_custom_target(ci_test_amalgamation
|
|||||||
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json.json -s .
|
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json.json -s .
|
||||||
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_fwd.json -s .
|
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_fwd.json -s .
|
||||||
COMMAND cp ${PROJECT_SOURCE_DIR}/include/nlohmann/json_literals.hpp ${include_dir}/json_literals.hpp
|
COMMAND cp ${PROJECT_SOURCE_DIR}/include/nlohmann/json_literals.hpp ${include_dir}/json_literals.hpp
|
||||||
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_view.json -s .
|
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=none ${include_dir}/json.hpp ${include_dir}/json_fwd.hpp
|
||||||
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=none ${include_dir}/json.hpp ${include_dir}/json_fwd.hpp ${include_dir}/json_view.hpp
|
|
||||||
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/scripts/gen_bazel_build_file.cmake
|
|
||||||
|
|
||||||
COMMAND diff ${include_dir}/json.hpp~ ${include_dir}/json.hpp
|
COMMAND diff ${include_dir}/json.hpp~ ${include_dir}/json.hpp
|
||||||
COMMAND diff ${include_dir}/json_fwd.hpp~ ${include_dir}/json_fwd.hpp
|
COMMAND diff ${include_dir}/json_fwd.hpp~ ${include_dir}/json_fwd.hpp
|
||||||
COMMAND diff ${include_dir}/json_literals.hpp~ ${include_dir}/json_literals.hpp
|
COMMAND diff ${include_dir}/json_literals.hpp~ ${include_dir}/json_literals.hpp
|
||||||
COMMAND diff ${include_dir}/json_view.hpp~ ${include_dir}/json_view.hpp
|
|
||||||
COMMAND diff ${PROJECT_SOURCE_DIR}/BUILD.bazel~ ${PROJECT_SOURCE_DIR}/BUILD.bazel
|
|
||||||
|
|
||||||
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=orig ${INDENT_FILES}
|
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=orig ${INDENT_FILES}
|
||||||
COMMAND for FILE in `find . -name '*.orig'`\; do false \; done
|
COMMAND for FILE in `find . -name '*.orig'`\; do false \; done
|
||||||
|
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
COMMENT "Check amalgamation, formatting, and BUILD.bazel"
|
COMMENT "Check amalgamation and indentation"
|
||||||
)
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -459,14 +430,14 @@ add_custom_target(ci_test_valgrind
|
|||||||
# Check code with Clang Static Analyzer.
|
# Check code with Clang Static Analyzer.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
set(CLANG_ANALYZER_CHECKS "nullability.NullableDereferenced,nullability.NullablePassedToNonnull,nullability.NullableReturnedFromNonnull,optin.cplusplus.UninitializedObject,optin.cplusplus.VirtualCall,optin.performance.Padding,optin.portability.UnixAPI,security.FloatLoopCounter,security.insecureAPI.DeprecatedOrUnsafeBufferHandling,security.insecureAPI.bcmp,security.insecureAPI.bcopy,security.insecureAPI.bzero,security.insecureAPI.rand,security.insecureAPI.strcpy,valist.CopyToSelf,valist.Uninitialized,valist.Unterminated,core.CallAndMessage,core.DivideZero,core.NonNullParamChecker,core.NullDereference,core.StackAddressEscape,core.UndefinedBinaryOperatorResult,core.VLASize,core.uninitialized.ArraySubscript,core.uninitialized.Assign,core.uninitialized.Branch,core.uninitialized.CapturedBlockVariable,core.uninitialized.UndefReturn,cplusplus.InnerPointer,cplusplus.Move,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,cplusplus.PlacementNew,cplusplus.PureVirtualCall,deadcode.DeadStores,nullability.NullPassedToNonnull,nullability.NullReturnedFromNonnull,security.insecureAPI.UncheckedReturn,security.insecureAPI.decodeValueOfObjCType,security.insecureAPI.getpw,security.insecureAPI.gets,security.insecureAPI.mkstemp,security.insecureAPI.mktemp,security.insecureAPI.vfork,unix.API,unix.Malloc,unix.MallocSizeof,unix.MismatchedDeallocator,unix.Vfork,unix.cstring.BadSizeArg,unix.cstring.NullArg")
|
set(CLANG_ANALYZER_CHECKS "fuchsia.HandleChecker,nullability.NullableDereferenced,nullability.NullablePassedToNonnull,nullability.NullableReturnedFromNonnull,optin.cplusplus.UninitializedObject,optin.cplusplus.VirtualCall,optin.mpi.MPI-Checker,optin.osx.OSObjectCStyleCast,optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,optin.osx.cocoa.localizability.NonLocalizedStringChecker,optin.performance.GCDAntipattern,optin.performance.Padding,optin.portability.UnixAPI,security.FloatLoopCounter,security.insecureAPI.DeprecatedOrUnsafeBufferHandling,security.insecureAPI.bcmp,security.insecureAPI.bcopy,security.insecureAPI.bzero,security.insecureAPI.rand,security.insecureAPI.strcpy,valist.CopyToSelf,valist.Uninitialized,valist.Unterminated,webkit.NoUncountedMemberChecker,webkit.RefCntblBaseVirtualDtor,core.CallAndMessage,core.DivideZero,core.NonNullParamChecker,core.NullDereference,core.StackAddressEscape,core.UndefinedBinaryOperatorResult,core.VLASize,core.uninitialized.ArraySubscript,core.uninitialized.Assign,core.uninitialized.Branch,core.uninitialized.CapturedBlockVariable,core.uninitialized.UndefReturn,cplusplus.InnerPointer,cplusplus.Move,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,cplusplus.PlacementNew,cplusplus.PureVirtualCall,deadcode.DeadStores,nullability.NullPassedToNonnull,nullability.NullReturnedFromNonnull,osx.API,osx.MIG,osx.NumberObjectConversion,osx.OSObjectRetainCount,osx.ObjCProperty,osx.SecKeychainAPI,osx.cocoa.AtSync,osx.cocoa.AutoreleaseWrite,osx.cocoa.ClassRelease,osx.cocoa.Dealloc,osx.cocoa.IncompatibleMethodTypes,osx.cocoa.Loops,osx.cocoa.MissingSuperCall,osx.cocoa.NSAutoreleasePool,osx.cocoa.NSError,osx.cocoa.NilArg,osx.cocoa.NonNilReturnValue,osx.cocoa.ObjCGenerics,osx.cocoa.RetainCount,osx.cocoa.RunLoopAutoreleaseLeak,osx.cocoa.SelfInit,osx.cocoa.SuperDealloc,osx.cocoa.UnusedIvars,osx.cocoa.VariadicMethodTypes,osx.coreFoundation.CFError,osx.coreFoundation.CFNumber,osx.coreFoundation.CFRetainRelease,osx.coreFoundation.containers.OutOfBounds,osx.coreFoundation.containers.PointerSizedValues,security.insecureAPI.UncheckedReturn,security.insecureAPI.decodeValueOfObjCType,security.insecureAPI.getpw,security.insecureAPI.gets,security.insecureAPI.mkstemp,security.insecureAPI.mktemp,security.insecureAPI.vfork,unix.API,unix.Malloc,unix.MallocSizeof,unix.MismatchedDeallocator,unix.Vfork,unix.cstring.BadSizeArg,unix.cstring.NullArg")
|
||||||
|
|
||||||
add_custom_target(ci_clang_analyze
|
add_custom_target(ci_clang_analyze
|
||||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON
|
-DJSON_BuildTests=ON
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_analyze
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_analyze
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_analyze && ${SCAN_BUILD_TOOL} -enable-checker ${CLANG_ANALYZER_CHECKS} --use-c++=${CLANG_TOOL} --use-analyzer=${CLANG_TOOL} -analyze-headers --status-bugs -o ${PROJECT_BINARY_DIR}/report ninja
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_analyze && ${SCAN_BUILD_TOOL} -enable-checker ${CLANG_ANALYZER_CHECKS} --use-c++=${CLANG_TOOL} -analyze-headers -o ${PROJECT_BINARY_DIR}/report ninja
|
||||||
COMMENT "Check code with Clang Analyzer"
|
COMMENT "Check code with Clang Analyzer"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -482,7 +453,7 @@ add_custom_target(ci_cppcheck
|
|||||||
COMMAND venv_cppcheck/bin/cppcheck --enable=warning --check-level=exhaustive --inline-suppr --inconclusive --force
|
COMMAND venv_cppcheck/bin/cppcheck --enable=warning --check-level=exhaustive --inline-suppr --inconclusive --force
|
||||||
--std=c++11 ${PROJECT_SOURCE_DIR}/include/nlohmann/json.hpp -I ${CMAKE_SOURCE_DIR}/include
|
--std=c++11 ${PROJECT_SOURCE_DIR}/include/nlohmann/json.hpp -I ${CMAKE_SOURCE_DIR}/include
|
||||||
--error-exitcode=1 --relative-paths=${PROJECT_SOURCE_DIR} -j ${N} --include=default_defines.hpp
|
--error-exitcode=1 --relative-paths=${PROJECT_SOURCE_DIR} -j ${N} --include=default_defines.hpp
|
||||||
--cppcheck-build-dir=cppcheck
|
--cppcheck-build-dir=cppcheck --check-level=exhaustive
|
||||||
-UJSON_CATCH_USER -UJSON_TRY_USER -UJSON_ASSERT -UJSON_INTERNAL_CATCH -UJSON_THROW
|
-UJSON_CATCH_USER -UJSON_TRY_USER -UJSON_ASSERT -UJSON_INTERNAL_CATCH -UJSON_THROW
|
||||||
-DJSON_HAS_CPP_11 -UJSON_HAS_CPP_14 -UJSON_HAS_CPP_17 -UJSON_HAS_CPP_20 -UJSON_HAS_THREE_WAY_COMPARISON
|
-DJSON_HAS_CPP_11 -UJSON_HAS_CPP_14 -UJSON_HAS_CPP_17 -UJSON_HAS_CPP_20 -UJSON_HAS_THREE_WAY_COMPARISON
|
||||||
COMMENT "Check code with Cppcheck"
|
COMMENT "Check code with Cppcheck"
|
||||||
@@ -500,6 +471,34 @@ add_custom_target(ci_cpplint
|
|||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Check code with OCLint.
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
file(COPY ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp DESTINATION ${PROJECT_BINARY_DIR}/src_single)
|
||||||
|
file(RENAME ${PROJECT_BINARY_DIR}/src_single/json.hpp ${PROJECT_BINARY_DIR}/src_single/all.cpp)
|
||||||
|
file(APPEND "${PROJECT_BINARY_DIR}/src_single/all.cpp" "\n\nint main()\n{}\n")
|
||||||
|
|
||||||
|
add_executable(single_all ${PROJECT_BINARY_DIR}/src_single/all.cpp)
|
||||||
|
target_compile_features(single_all PRIVATE cxx_std_11)
|
||||||
|
|
||||||
|
add_custom_target(ci_oclint
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug
|
||||||
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
-DJSON_BuildTests=OFF -DJSON_CI=ON
|
||||||
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_oclint
|
||||||
|
COMMAND ${OCLINT_TOOL} -i ${PROJECT_BINARY_DIR}/build_oclint/src_single/all.cpp -p ${PROJECT_BINARY_DIR}/build_oclint --
|
||||||
|
-report-type html -enable-global-analysis --max-priority-1=0 --max-priority-2=1000 --max-priority-3=2000
|
||||||
|
--disable-rule=MultipleUnaryOperator
|
||||||
|
--disable-rule=DoubleNegative
|
||||||
|
--disable-rule=ShortVariableName
|
||||||
|
--disable-rule=GotoStatement
|
||||||
|
--disable-rule=LongLine
|
||||||
|
-o ${PROJECT_BINARY_DIR}/build_oclint/oclint_report.html
|
||||||
|
COMMENT "Check code with OCLint"
|
||||||
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Check code with Clang-Tidy.
|
# Check code with Clang-Tidy.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -514,16 +513,29 @@ add_custom_target(ci_clang_tidy
|
|||||||
COMMENT "Check code with Clang-Tidy"
|
COMMENT "Check code with Clang-Tidy"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Check code with PVS-Studio Analyzer <https://www.viva64.com/en/pvs-studio/>.
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
add_custom_target(ci_pvs_studio
|
||||||
|
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug
|
||||||
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
-DJSON_BuildTests=ON
|
||||||
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_pvs_studio
|
||||||
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_pvs_studio && ${PVS_STUDIO_ANALYZER_TOOL} analyze -j 10
|
||||||
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_pvs_studio && ${PLOG_CONVERTER_TOOL} -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs
|
||||||
|
COMMENT "Check code with PVS Studio"
|
||||||
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Check code with Infer <https://fbinfer.com> static analyzer.
|
# Check code with Infer <https://fbinfer.com> static analyzer.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# .inferconfig (repository root) pins --fail-on-issue and the currently-triaged issue types that
|
|
||||||
# are disabled until they are addressed separately; see #5715 item 4b.
|
|
||||||
add_custom_target(ci_infer
|
add_custom_target(ci_infer
|
||||||
COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_infer
|
COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_infer
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} compile -- ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_DIR} -DJSON_BuildTests=ON
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} compile -- ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_DIR} -DJSON_BuildTests=ON
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} run --project-root ${PROJECT_SOURCE_DIR} -- make
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} run -- make
|
||||||
COMMENT "Check code with Infer"
|
COMMENT "Check code with Infer"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -579,13 +591,7 @@ add_custom_target(ci_reproducible_tests
|
|||||||
# be compiled individually.
|
# be compiled individually.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
set(iwyu_options -Xiwyu --error -Xiwyu --max_line_length=300)
|
set(iwyu_path_and_options ${IWYU_TOOL} -Xiwyu --max_line_length=300)
|
||||||
set(iwyu_path_and_options ${IWYU_TOOL} ${iwyu_options})
|
|
||||||
|
|
||||||
# CMake needs to know the exact flags used to compile each src_single/*.cpp below to hand them to
|
|
||||||
# iwyu_tool.py; JSON_CI already implies a from-scratch configure, so enabling this project-wide has
|
|
||||||
# no downside here.
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
|
|
||||||
foreach(SRC_FILE ${SRC_FILES})
|
foreach(SRC_FILE ${SRC_FILES})
|
||||||
# get relative path of the header file
|
# get relative path of the header file
|
||||||
@@ -600,34 +606,14 @@ foreach(SRC_FILE ${SRC_FILES})
|
|||||||
target_include_directories(single_${RELATIVE_SRC_FILE} PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
target_include_directories(single_${RELATIVE_SRC_FILE} PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||||
target_compile_features(single_${RELATIVE_SRC_FILE} PRIVATE cxx_std_11)
|
target_compile_features(single_${RELATIVE_SRC_FILE} PRIVATE cxx_std_11)
|
||||||
set_property(TARGET single_${RELATIVE_SRC_FILE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE "${iwyu_path_and_options}")
|
set_property(TARGET single_${RELATIVE_SRC_FILE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE "${iwyu_path_and_options}")
|
||||||
# remember binary for ci_single_binaries
|
# remember binary for ci_single_binaries target
|
||||||
list(APPEND single_binaries single_${RELATIVE_SRC_FILE})
|
list(APPEND single_binaries single_${RELATIVE_SRC_FILE})
|
||||||
# json.hpp pulls together the whole library behind heavily templated, SFINAE-based code, and
|
|
||||||
# IWYU's suggestion for its one truly ambiguous symbol (a container-comparison "swap,
|
|
||||||
# operator!=") is not deterministic between runs (observed <set>, <unordered_map>, and <map>
|
|
||||||
# for the exact same source across otherwise-identical local and containerized builds). Keep
|
|
||||||
# reporting its diagnostics (informational, via CXX_INCLUDE_WHAT_YOU_USE above) but exclude it
|
|
||||||
# from the hard gate below so a fresh IWYU/compiler combination does not fail this target on a
|
|
||||||
# nondeterministic suggestion for a header that already re-exports everything on purpose.
|
|
||||||
if(NOT RELATIVE_SRC_FILE STREQUAL "json")
|
|
||||||
list(APPEND single_binaries_tus src_single/${RELATIVE_SRC_FILE}.cpp)
|
|
||||||
endif()
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if(IWYU_TOOL_PY)
|
add_custom_target(ci_single_binaries
|
||||||
add_custom_target(ci_single_binaries
|
DEPENDS ${single_binaries}
|
||||||
DEPENDS ${single_binaries}
|
COMMENT "Check if headers are self-contained"
|
||||||
COMMAND ${IWYU_TOOL_PY} -p ${PROJECT_BINARY_DIR} ${single_binaries_tus} -- ${iwyu_options}
|
)
|
||||||
COMMENT "Check if headers are self-contained"
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
# iwyu_tool.py (ships with IWYU, e.g. as /usr/bin/iwyu_tool on Debian/Ubuntu) was not found;
|
|
||||||
# fall back to building the self-containment check without enforcing the IWYU findings.
|
|
||||||
add_custom_target(ci_single_binaries
|
|
||||||
DEPENDS ${single_binaries}
|
|
||||||
COMMENT "Check if headers are self-contained"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Benchmarks
|
# Benchmarks
|
||||||
@@ -649,41 +635,21 @@ add_custom_target(ci_benchmarks
|
|||||||
# we test the project with different CMake versions:
|
# we test the project with different CMake versions:
|
||||||
# - CMake 3.5 (the earliest supported)
|
# - CMake 3.5 (the earliest supported)
|
||||||
# - CMake 3.31.6 (the latest 3.x release)
|
# - CMake 3.31.6 (the latest 3.x release)
|
||||||
# - CMake 4.0.0 (the first 4.x release)
|
# - CMake 4.0.0 (the latest release)
|
||||||
# - the CMake version running this build (usually the latest release)
|
|
||||||
|
|
||||||
function(ci_get_cmake version var)
|
function(ci_get_cmake version var)
|
||||||
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}/bin/cmake)
|
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}/bin/cmake)
|
||||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$")
|
add_custom_command(
|
||||||
# Kitware publishes a prebuilt Linux x86_64 archive for every release; unpacking it is far
|
OUTPUT ${${var}}
|
||||||
# cheaper than compiling all of CMake (including its own test helpers) from source.
|
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}.tar.gz
|
||||||
add_custom_command(
|
COMMAND tar xfz cmake-${version}.tar.gz
|
||||||
OUTPUT ${${var}}
|
COMMAND rm cmake-${version}.tar.gz
|
||||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-linux-x86_64.tar.gz
|
# -DCMAKE_POLICY_VERSION_MINIMUM=3.5 required to compile older CMake versions with CMake 4.0.0
|
||||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-SHA-256.txt
|
COMMAND cmake -S cmake-${version} -B cmake-${version} -DCMAKE_POLICY_VERSION_MINIMUM=3.5
|
||||||
# verify the archive against Kitware's published SHA-256 sums before unpacking it
|
COMMAND cmake --build cmake-${version} --parallel 10
|
||||||
COMMAND sh -c "grep ' cmake-${version}-linux-x86_64[.]tar[.]gz$' cmake-${version}-SHA-256.txt | sha256sum -c -"
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||||
COMMAND tar xfz cmake-${version}-linux-x86_64.tar.gz
|
COMMENT "Download CMake ${version}"
|
||||||
COMMAND rm cmake-${version}-linux-x86_64.tar.gz cmake-${version}-SHA-256.txt
|
)
|
||||||
COMMAND ${CMAKE_COMMAND} -E rm -rf cmake-${version}
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E rename cmake-${version}-linux-x86_64 cmake-${version}
|
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
||||||
COMMENT "Download prebuilt CMake ${version}"
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
# no prebuilt archive for this platform (e.g. macOS or Linux aarch64): build from source
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${${var}}
|
|
||||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}.tar.gz
|
|
||||||
COMMAND tar xfz cmake-${version}.tar.gz
|
|
||||||
COMMAND rm cmake-${version}.tar.gz
|
|
||||||
# -DCMAKE_POLICY_VERSION_MINIMUM=3.5 required to compile older CMake versions with CMake 4.0.0
|
|
||||||
COMMAND cmake -S cmake-${version} -B cmake-${version} -DCMAKE_POLICY_VERSION_MINIMUM=3.5
|
|
||||||
COMMAND cmake --build cmake-${version} --parallel 10
|
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
||||||
COMMENT "Download and build CMake ${version} from source"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
set(${var} ${${var}} PARENT_SCOPE)
|
set(${var} ${${var}} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
@@ -693,24 +659,30 @@ ci_get_cmake(4.0.0 CMAKE_4_0_0_BINARY)
|
|||||||
|
|
||||||
# the tests require CMake 3.13 or later, so they are excluded for CMake 3.5.0
|
# the tests require CMake 3.13 or later, so they are excluded for CMake 3.5.0
|
||||||
set(JSON_CMAKE_FLAGS_3_5_0 JSON_Diagnostics JSON_Diagnostic_Positions JSON_GlobalUDLs JSON_ImplicitConversions JSON_DisableEnumSerialization
|
set(JSON_CMAKE_FLAGS_3_5_0 JSON_Diagnostics JSON_Diagnostic_Positions JSON_GlobalUDLs JSON_ImplicitConversions JSON_DisableEnumSerialization
|
||||||
JSON_LegacyDiscardedValueComparison JSON_Install JSON_MultipleHeaders JSON_SystemInclude JSON_Valgrind
|
JSON_LegacyDiscardedValueComparison JSON_Install JSON_MultipleHeaders JSON_SystemInclude JSON_Valgrind)
|
||||||
JSON_StrictNulHandling)
|
set(JSON_CMAKE_FLAGS_3_31_6 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_31_6})
|
||||||
set(JSON_CMAKE_FLAGS_3_31_6 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_5_0})
|
|
||||||
set(JSON_CMAKE_FLAGS_4_0_0 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_5_0})
|
set(JSON_CMAKE_FLAGS_4_0_0 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_5_0})
|
||||||
|
|
||||||
function(ci_add_cmake_flags_targets flag min_version)
|
function(ci_add_cmake_flags_targets flag min_version)
|
||||||
string(TOLOWER "ci_cmake_flag_${flag}" flag_target)
|
string(TOLOWER "ci_cmake_flag_${flag}" flag_target)
|
||||||
string(REPLACE . _ min_version_var ${min_version})
|
string(REPLACE . _ min_version_var ${min_version})
|
||||||
set(cmake_binary ${CMAKE_${min_version_var}_BINARY})
|
set(cmake_binary ${CMAKE_${min_version_var}_BINARY})
|
||||||
|
add_custom_target(${flag_target}_${min_version}_2
|
||||||
|
COMMENT "Check CMake flag ${flag} (CMake ${CMAKE_VERSION})"
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-Werror=dev
|
||||||
|
-D${flag}=ON
|
||||||
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_${flag_target}
|
||||||
|
)
|
||||||
add_custom_target(${flag_target}_${min_version_var}
|
add_custom_target(${flag_target}_${min_version_var}
|
||||||
COMMENT "Check CMake flag ${flag} (CMake ${min_version})"
|
COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake ${min_version})"
|
||||||
COMMAND mkdir -pv ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
COMMAND mkdir -pv ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
||||||
&& ${cmake_binary} -Werror=dev ${PROJECT_SOURCE_DIR} -D${flag}=ON
|
&& ${cmake_binary} -Werror=dev ${PROJECT_SOURCE_DIR} -D${flag}=ON
|
||||||
DEPENDS ${cmake_binary}
|
DEPENDS ${cmake_binary}
|
||||||
)
|
)
|
||||||
list(APPEND JSON_CMAKE_FLAG_TARGETS ${flag_target}_${min_version_var})
|
list(APPEND JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGET} ${flag_target}_${min_version_var})
|
||||||
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var})
|
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target} ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var})
|
||||||
set(JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGETS} PARENT_SCOPE)
|
set(JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGETS} PARENT_SCOPE)
|
||||||
set(JSON_CMAKE_FLAG_BUILD_DIRS ${JSON_CMAKE_FLAG_BUILD_DIRS} PARENT_SCOPE)
|
set(JSON_CMAKE_FLAG_BUILD_DIRS ${JSON_CMAKE_FLAG_BUILD_DIRS} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
@@ -727,20 +699,6 @@ foreach(JSON_CMAKE_FLAG ${JSON_CMAKE_FLAGS_4_0_0})
|
|||||||
ci_add_cmake_flags_targets(${JSON_CMAKE_FLAG} 4.0.0)
|
ci_add_cmake_flags_targets(${JSON_CMAKE_FLAG} 4.0.0)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# check the same flags with the CMake version running this build
|
|
||||||
foreach(JSON_CMAKE_FLAG ${JSON_CMAKE_FLAGS_4_0_0})
|
|
||||||
string(TOLOWER "ci_cmake_flag_${JSON_CMAKE_FLAG}" flag_target)
|
|
||||||
add_custom_target(${flag_target}
|
|
||||||
COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake ${CMAKE_VERSION})"
|
|
||||||
COMMAND ${CMAKE_COMMAND}
|
|
||||||
-Werror=dev
|
|
||||||
-D${JSON_CMAKE_FLAG}=ON
|
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_${flag_target}
|
|
||||||
)
|
|
||||||
list(APPEND JSON_CMAKE_FLAG_TARGETS ${flag_target})
|
|
||||||
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
add_custom_target(ci_cmake_flags
|
add_custom_target(ci_cmake_flags
|
||||||
DEPENDS ${JSON_CMAKE_FLAG_TARGETS}
|
DEPENDS ${JSON_CMAKE_FLAG_TARGETS}
|
||||||
COMMENT "Check CMake flags"
|
COMMENT "Check CMake flags"
|
||||||
@@ -899,6 +857,6 @@ add_custom_target(ci_test_build_documentation
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
add_custom_target(ci_clean
|
add_custom_target(ci_clean
|
||||||
COMMAND rm -fr ${PROJECT_BINARY_DIR}/build_* ${PROJECT_BINARY_DIR}/cmake-3.5.0 ${PROJECT_BINARY_DIR}/cmake-3.31.6 ${PROJECT_BINARY_DIR}/cmake-4.0.0 ${JSON_CMAKE_FLAG_BUILD_DIRS} ${single_binaries}
|
COMMAND rm -fr ${PROJECT_BINARY_DIR}/build_* cmake-3.5.0-Darwin64 ${JSON_CMAKE_FLAG_BUILD_DIRS} ${single_binaries}
|
||||||
COMMENT "Clean generated directories"
|
COMMENT "Clean generated directories"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# -Wno-c++98-compat The library targets C++11.
|
# -Wno-c++98-compat The library targets C++11.
|
||||||
# -Wno-c++98-compat-pedantic The library targets C++11.
|
# -Wno-c++98-compat-pedantic The library targets C++11.
|
||||||
# -Wno-deprecated-declarations The library contains annotations for deprecated functions.
|
# -Wno-deprecated-declarations The library contains annotations for deprecated functions.
|
||||||
|
# -Wno-extra-semi-stmt The library uses assert which triggers this warning.
|
||||||
# -Wno-padded We do not care about padding warnings.
|
# -Wno-padded We do not care about padding warnings.
|
||||||
# -Wno-covered-switch-default All switches list all cases and a default case.
|
# -Wno-covered-switch-default All switches list all cases and a default case.
|
||||||
# -Wno-c2y-extensions Clang 22.1 diagnoses __COUNTER__ as a C2y extension, also in
|
# -Wno-c2y-extensions Clang 22.1 diagnoses __COUNTER__ as a C2y extension, also in
|
||||||
@@ -19,6 +20,7 @@ set(CLANG_CXXFLAGS
|
|||||||
-Wno-c++98-compat
|
-Wno-c++98-compat
|
||||||
-Wno-c++98-compat-pedantic
|
-Wno-c++98-compat-pedantic
|
||||||
-Wno-deprecated-declarations
|
-Wno-deprecated-declarations
|
||||||
|
-Wno-extra-semi-stmt
|
||||||
-Wno-padded
|
-Wno-padded
|
||||||
-Wno-covered-switch-default
|
-Wno-covered-switch-default
|
||||||
-Wno-c2y-extensions
|
-Wno-c2y-extensions
|
||||||
|
|||||||
+13
-24
@@ -1,4 +1,4 @@
|
|||||||
# Warning flags determined for GCC 16.2.0 with https://github.com/nlohmann/gcc_flags:
|
# Warning flags determined for GCC 15.1.0 with https://github.com/nlohmann/gcc_flags:
|
||||||
# Ignored GCC warnings:
|
# Ignored GCC warnings:
|
||||||
# -Wno-abi-tag We do not care about ABI tags.
|
# -Wno-abi-tag We do not care about ABI tags.
|
||||||
# -Wno-aggregate-return The library uses aggregate returns.
|
# -Wno-aggregate-return The library uses aggregate returns.
|
||||||
@@ -16,8 +16,6 @@ set(GCC_CXXFLAGS
|
|||||||
--extra-warnings
|
--extra-warnings
|
||||||
-W
|
-W
|
||||||
-WNSObject-attribute
|
-WNSObject-attribute
|
||||||
-Wabbreviated-auto-in-template-arg
|
|
||||||
-Wabi
|
|
||||||
-Wno-abi-tag
|
-Wno-abi-tag
|
||||||
-Waddress
|
-Waddress
|
||||||
-Waddress-of-packed-member
|
-Waddress-of-packed-member
|
||||||
@@ -66,7 +64,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wanalyzer-tainted-divisor
|
-Wanalyzer-tainted-divisor
|
||||||
-Wanalyzer-tainted-offset
|
-Wanalyzer-tainted-offset
|
||||||
-Wanalyzer-tainted-size
|
-Wanalyzer-tainted-size
|
||||||
-Wanalyzer-throw-of-unexpected-type
|
|
||||||
-Wanalyzer-too-complex
|
-Wanalyzer-too-complex
|
||||||
-Wanalyzer-undefined-behavior-ptrdiff
|
-Wanalyzer-undefined-behavior-ptrdiff
|
||||||
-Wanalyzer-undefined-behavior-strtok
|
-Wanalyzer-undefined-behavior-strtok
|
||||||
@@ -83,13 +80,10 @@ set(GCC_CXXFLAGS
|
|||||||
-Warith-conversion
|
-Warith-conversion
|
||||||
-Warray-bounds=2
|
-Warray-bounds=2
|
||||||
-Warray-compare
|
-Warray-compare
|
||||||
-Warray-parameter
|
|
||||||
-Warray-parameter=2
|
-Warray-parameter=2
|
||||||
-Wattribute-alias=2
|
-Wattribute-alias=2
|
||||||
-Wattribute-warning
|
-Wattribute-warning
|
||||||
-Wattributes
|
-Wattributes
|
||||||
-Wauto-profile
|
|
||||||
-Wbidi-chars=any
|
|
||||||
-Wbool-compare
|
-Wbool-compare
|
||||||
-Wbool-operation
|
-Wbool-operation
|
||||||
-Wbuiltin-declaration-mismatch
|
-Wbuiltin-declaration-mismatch
|
||||||
@@ -105,7 +99,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wc++20-compat
|
-Wc++20-compat
|
||||||
-Wc++20-extensions
|
-Wc++20-extensions
|
||||||
-Wc++23-extensions
|
-Wc++23-extensions
|
||||||
-Wc++26-compat
|
|
||||||
-Wc++26-extensions
|
-Wc++26-extensions
|
||||||
-Wc++2a-compat
|
-Wc++2a-compat
|
||||||
-Wcalloc-transposed-args
|
-Wcalloc-transposed-args
|
||||||
@@ -149,7 +142,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wdeprecated-enum-enum-conversion
|
-Wdeprecated-enum-enum-conversion
|
||||||
-Wdeprecated-enum-float-conversion
|
-Wdeprecated-enum-float-conversion
|
||||||
-Wdeprecated-literal-operator
|
-Wdeprecated-literal-operator
|
||||||
-Wdeprecated-openmp
|
|
||||||
-Wdeprecated-variadic-comma-omission
|
-Wdeprecated-variadic-comma-omission
|
||||||
-Wdisabled-optimization
|
-Wdisabled-optimization
|
||||||
-Wdiv-by-zero
|
-Wdiv-by-zero
|
||||||
@@ -164,18 +156,21 @@ set(GCC_CXXFLAGS
|
|||||||
-Wenum-conversion
|
-Wenum-conversion
|
||||||
-Wexceptions
|
-Wexceptions
|
||||||
-Wexpansion-to-defined
|
-Wexpansion-to-defined
|
||||||
-Wexperimental-fmv-target
|
|
||||||
-Wexpose-global-module-tu-local
|
|
||||||
-Wexternal-tu-local
|
|
||||||
-Wextra
|
-Wextra
|
||||||
-Wextra-semi
|
-Wextra-semi
|
||||||
-Wflex-array-member-not-at-end
|
-Wflex-array-member-not-at-end
|
||||||
-Wfloat-conversion
|
-Wfloat-conversion
|
||||||
-Wfloat-equal
|
-Wfloat-equal
|
||||||
-Wformat-diag
|
-Wformat -Wformat-contains-nul
|
||||||
-Wformat-overflow=2
|
-Wformat -Wformat-diag
|
||||||
-Wformat-signedness
|
-Wformat -Wformat-extra-args
|
||||||
-Wformat-truncation=2
|
-Wformat -Wformat-nonliteral
|
||||||
|
-Wformat -Wformat-overflow=2
|
||||||
|
-Wformat -Wformat-security
|
||||||
|
-Wformat -Wformat-signedness
|
||||||
|
-Wformat -Wformat-truncation=2
|
||||||
|
-Wformat -Wformat-y2k
|
||||||
|
-Wformat -Wformat-zero-length
|
||||||
-Wformat=2
|
-Wformat=2
|
||||||
-Wframe-address
|
-Wframe-address
|
||||||
-Wfree-nonheap-object
|
-Wfree-nonheap-object
|
||||||
@@ -202,8 +197,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Winvalid-offsetof
|
-Winvalid-offsetof
|
||||||
-Winvalid-pch
|
-Winvalid-pch
|
||||||
-Winvalid-utf8
|
-Winvalid-utf8
|
||||||
-Wkeyword-macro
|
|
||||||
-Wleading-whitespace=spaces
|
|
||||||
-Wliteral-suffix
|
-Wliteral-suffix
|
||||||
-Wlogical-not-parentheses
|
-Wlogical-not-parentheses
|
||||||
-Wlogical-op
|
-Wlogical-op
|
||||||
@@ -234,7 +227,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wnarrowing
|
-Wnarrowing
|
||||||
-Wnoexcept
|
-Wnoexcept
|
||||||
-Wnoexcept-type
|
-Wnoexcept-type
|
||||||
-Wnon-c-typedef-for-linkage
|
|
||||||
-Wnon-template-friend
|
-Wnon-template-friend
|
||||||
-Wnon-virtual-dtor
|
-Wnon-virtual-dtor
|
||||||
-Wnonnull
|
-Wnonnull
|
||||||
@@ -277,8 +269,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wscalar-storage-order
|
-Wscalar-storage-order
|
||||||
-Wself-move
|
-Wself-move
|
||||||
-Wsequence-point
|
-Wsequence-point
|
||||||
-Wsfinae-incomplete
|
|
||||||
-Wsfinae-incomplete=2
|
|
||||||
-Wshadow=compatible-local
|
-Wshadow=compatible-local
|
||||||
-Wshadow=global
|
-Wshadow=global
|
||||||
-Wshadow=local
|
-Wshadow=local
|
||||||
@@ -299,7 +289,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wstrict-aliasing=3
|
-Wstrict-aliasing=3
|
||||||
-Wstrict-null-sentinel
|
-Wstrict-null-sentinel
|
||||||
-Wstrict-overflow
|
-Wstrict-overflow
|
||||||
-Wstrict-overflow=5
|
|
||||||
-Wstring-compare
|
-Wstring-compare
|
||||||
-Wstringop-overflow
|
-Wstringop-overflow
|
||||||
-Wstringop-overflow=4
|
-Wstringop-overflow=4
|
||||||
@@ -344,8 +333,8 @@ set(GCC_CXXFLAGS
|
|||||||
-Wunreachable-code
|
-Wunreachable-code
|
||||||
-Wunsafe-loop-optimizations
|
-Wunsafe-loop-optimizations
|
||||||
-Wunused
|
-Wunused
|
||||||
-Wunused-but-set-parameter=3
|
-Wunused-but-set-parameter
|
||||||
-Wunused-but-set-variable=3
|
-Wunused-but-set-variable
|
||||||
-Wunused-const-variable=2
|
-Wunused-const-variable=2
|
||||||
-Wunused-function
|
-Wunused-function
|
||||||
-Wunused-label
|
-Wunused-label
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ cc_library(
|
|||||||
name = "singleheader-json",
|
name = "singleheader-json",
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"single_include/nlohmann/json.hpp",
|
"single_include/nlohmann/json.hpp",
|
||||||
"single_include/nlohmann/json_view.hpp",
|
|
||||||
],
|
],
|
||||||
includes = ["single_include"],
|
includes = ["single_include"],
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
|
|||||||
+5
-16
@@ -11,31 +11,20 @@ EXAMPLES = $(wildcard mkdocs/docs/examples/*.cpp)
|
|||||||
|
|
||||||
cxx_standard = $(lastword c++11 $(filter c++%, $(subst ., ,$1)))
|
cxx_standard = $(lastword c++11 $(filter c++%, $(subst ., ,$1)))
|
||||||
|
|
||||||
# common compile flags for the stand-alone example files
|
|
||||||
EXAMPLE_CPPFLAGS = -I $(SRCDIR) -DJSON_USE_GLOBAL_UDLS=0
|
|
||||||
EXAMPLE_WARNFLAGS = -Werror=deprecated-declarations
|
|
||||||
|
|
||||||
# examples that document deprecated API and are allowed to use it
|
|
||||||
DEPRECATED_EXAMPLES = $(addprefix mkdocs/docs/examples/, \
|
|
||||||
json_pointer__operator__equal_stringtype \
|
|
||||||
json_pointer__operator__notequal_stringtype \
|
|
||||||
json_pointer__operator_string_t)
|
|
||||||
$(DEPRECATED_EXAMPLES:=.output) $(DEPRECATED_EXAMPLES:=.test): EXAMPLE_WARNFLAGS = -Wno-deprecated-declarations
|
|
||||||
|
|
||||||
# create output from a stand-alone example file
|
# create output from a stand-alone example file
|
||||||
%.output: %.cpp
|
%.output: %.cpp
|
||||||
@echo "standard $(call cxx_standard,$(<:.cpp=))"
|
@echo "standard $(call cxx_standard $(<:.cpp=))"
|
||||||
$(MAKE) $(<:.cpp=) \
|
$(MAKE) $(<:.cpp=) \
|
||||||
CPPFLAGS="$(EXAMPLE_CPPFLAGS)" \
|
CPPFLAGS="-I $(SRCDIR) -DJSON_USE_GLOBAL_UDLS=0" \
|
||||||
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) $(EXAMPLE_WARNFLAGS)"
|
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) -Wno-deprecated-declarations"
|
||||||
./$(<:.cpp=) > $@
|
./$(<:.cpp=) > $@
|
||||||
rm $(<:.cpp=)
|
rm $(<:.cpp=)
|
||||||
|
|
||||||
# compare created output with current output of the example files
|
# compare created output with current output of the example files
|
||||||
%.test: %.cpp
|
%.test: %.cpp
|
||||||
$(MAKE) $(<:.cpp=) \
|
$(MAKE) $(<:.cpp=) \
|
||||||
CPPFLAGS="$(EXAMPLE_CPPFLAGS)" \
|
CPPFLAGS="-I $(SRCDIR) -DJSON_USE_GLOBAL_UDLS=0" \
|
||||||
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) $(EXAMPLE_WARNFLAGS)"
|
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) -Wno-deprecated-declarations"
|
||||||
./$(<:.cpp=) > $@
|
./$(<:.cpp=) > $@
|
||||||
diff $@ $(<:.cpp=.output)
|
diff $@ $(<:.cpp=.output)
|
||||||
rm $(<:.cpp=) $@
|
rm $(<:.cpp=) $@
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<key>dashIndexFilePath</key>
|
<key>dashIndexFilePath</key>
|
||||||
<string>index.html</string>
|
<string>index.html</string>
|
||||||
<key>DashDocSetFallbackURL</key>
|
<key>DashDocSetFallbackURL</key>
|
||||||
<string>https://json.nlohmann.me/</string>
|
<string>https://nlohmann.github.io/json/</string>
|
||||||
<key>isJavaScriptEnabled</key>
|
<key>isJavaScriptEnabled</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
|
|||||||
+22
-12
@@ -52,25 +52,35 @@ install_docset_zeal: JSON_for_Modern_C++.docset
|
|||||||
mkdir -p $$docset_root; \
|
mkdir -p $$docset_root; \
|
||||||
cp -r JSON_for_Modern_C++.docset $$docset_root/
|
cp -r JSON_for_Modern_C++.docset $$docset_root/
|
||||||
|
|
||||||
# both targets below compare the docset search index with the mkdocs page
|
|
||||||
# set. They share the same normalization (docs/foo/index.md and
|
|
||||||
# docs/foo.md both become foo/index.html, the URL mkdocs itself would
|
|
||||||
# give the page; the top-level index.md is excluded, as it is not part
|
|
||||||
# of the hand-curated docSet.sql) and use comm(1) on two sorted lists
|
|
||||||
# instead of running a sqlite3 query, or an O(n*m) nested shell loop,
|
|
||||||
# once per page.
|
|
||||||
DOCSET_INDEX_PATHS=$(shell sqlite3 docSet.dsidx "SELECT DISTINCT path FROM searchIndex" | sort)
|
|
||||||
DOCSET_PAGE_PATHS=$(shell echo '$(MKDOCS_PAGES)' | tr ' ' '\n' | grep -v '^index\.md$$' | $(SED) -E 's@/index\.md$$@/index.html@; s@\.md$$@/index.html@' | sort)
|
|
||||||
|
|
||||||
# list mkdocs pages missing from the docset index
|
# list mkdocs pages missing from the docset index
|
||||||
.PHONY: list_missing_pages
|
.PHONY: list_missing_pages
|
||||||
list_missing_pages: docSet.dsidx
|
list_missing_pages: docSet.dsidx
|
||||||
@comm -23 <(echo '$(DOCSET_PAGE_PATHS)' | tr ' ' '\n') <(echo '$(DOCSET_INDEX_PATHS)' | tr ' ' '\n')
|
@for page in $(MKDOCS_PAGES); do \
|
||||||
|
case "$$page" in \
|
||||||
|
*/index.md) path=$${page/\/index.md/} ;; \
|
||||||
|
*) path=$${page/.md/} ;; \
|
||||||
|
esac; \
|
||||||
|
if [ "x$$page" != "xindex.md" -a "x$$(sqlite3 docSet.dsidx "SELECT COUNT(*) FROM searchIndex WHERE path='$$path/index.html'")" = "x0" ]; then \
|
||||||
|
echo $$page; \
|
||||||
|
fi \
|
||||||
|
done
|
||||||
|
|
||||||
# list paths in the docset index without a corresponding mkdocs page
|
# list paths in the docset index without a corresponding mkdocs page
|
||||||
.PHONY: list_removed_paths
|
.PHONY: list_removed_paths
|
||||||
list_removed_paths: docSet.dsidx
|
list_removed_paths: docSet.dsidx
|
||||||
@comm -13 <(echo '$(DOCSET_PAGE_PATHS)' | tr ' ' '\n') <(echo '$(DOCSET_INDEX_PATHS)' | tr ' ' '\n')
|
@for path in $$(sqlite3 docSet.dsidx "SELECT path FROM searchIndex"); do \
|
||||||
|
page=$${path/\/index.html/.md}; \
|
||||||
|
page_index=$${path/index.html/index.md}; \
|
||||||
|
page_found=0; \
|
||||||
|
for p in $(MKDOCS_PAGES); do \
|
||||||
|
if [ "x$$p" = "x$$page" -o "x$$p" = "x$$page_index" ]; then \
|
||||||
|
page_found=1; \
|
||||||
|
fi \
|
||||||
|
done; \
|
||||||
|
if [ "x$$page_found" = "x0" ]; then \
|
||||||
|
echo $$path; \
|
||||||
|
fi \
|
||||||
|
done
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@@ -7,11 +7,10 @@ documentation browsers like [Dash](https://kapeli.com/dash), [Velocity](https://
|
|||||||
The docset can be created with
|
The docset can be created with
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make JSON_for_Modern_C++.docset
|
make nlohmann_json.docset
|
||||||
```
|
```
|
||||||
|
|
||||||
The generated folder `JSON_for_Modern_C++.docset` can then be opened in the documentation browser. `make all` builds a
|
The generated folder `nlohmann_json.docset` can then be opened in the documentation browser.
|
||||||
`JSON_for_Modern_C++.tgz` archive instead, and `make install_docset_zeal` installs the docset for Zeal directly.
|
|
||||||
|
|
||||||
A recent version is also part of the [Dash user contributions](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B).
|
A recent version is also part of the [Dash user contributions](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B).
|
||||||
|
|
||||||
|
|||||||
@@ -128,43 +128,7 @@ INSERT INTO searchIndex(name, type, path) VALUES ('basic_json::to_ubjson', 'Func
|
|||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json::value', 'Method', 'api/basic_json/value/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json::value', 'Method', 'api/basic_json/value/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json::value_t', 'Enum', 'api/basic_json/value_t/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json::value_t', 'Enum', 'api/basic_json/value_t/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json::~basic_json', 'Method', 'api/basic_json/~basic_json/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json::~basic_json', 'Method', 'api/basic_json/~basic_json/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document', 'Class', 'api/basic_json_document/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::basic_json_document', 'Constructor', 'api/basic_json_document/basic_json_document/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::accept', 'Function', 'api/basic_json_document/accept/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::is_discarded', 'Method', 'api/basic_json_document/is_discarded/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::memory_usage', 'Method', 'api/basic_json_document/memory_usage/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::node_count', 'Method', 'api/basic_json_document/node_count/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::owns_source', 'Method', 'api/basic_json_document/owns_source/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::parse', 'Function', 'api/basic_json_document/parse/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::parse_copy', 'Function', 'api/basic_json_document/parse_copy/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::read', 'Method', 'api/basic_json_document/read/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::root', 'Method', 'api/basic_json_document/root/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::shrink_to_fit', 'Method', 'api/basic_json_document/shrink_to_fit/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_document::source', 'Method', 'api/basic_json_document/source/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view', 'Class', 'api/basic_json_view/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::basic_json_view', 'Constructor', 'api/basic_json_view/basic_json_view/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::empty', 'Method', 'api/basic_json_view/empty/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_array', 'Method', 'api/basic_json_view/is_array/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_binary', 'Method', 'api/basic_json_view/is_binary/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_boolean', 'Method', 'api/basic_json_view/is_boolean/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_discarded', 'Method', 'api/basic_json_view/is_discarded/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_null', 'Method', 'api/basic_json_view/is_null/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_number', 'Method', 'api/basic_json_view/is_number/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_number_float', 'Method', 'api/basic_json_view/is_number_float/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_number_integer', 'Method', 'api/basic_json_view/is_number_integer/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_number_unsigned', 'Method', 'api/basic_json_view/is_number_unsigned/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_object', 'Method', 'api/basic_json_view/is_object/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_primitive', 'Method', 'api/basic_json_view/is_primitive/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_string', 'Method', 'api/basic_json_view/is_string/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::is_structured', 'Method', 'api/basic_json_view/is_structured/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::materialize', 'Method', 'api/basic_json_view/materialize/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::operator bool', 'Method', 'api/basic_json_view/operator_bool/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::size', 'Method', 'api/basic_json_view/size/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::source_offset', 'Method', 'api/basic_json_view/source_offset/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json_view::type', 'Method', 'api/basic_json_view/type/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('json', 'Class', 'api/json/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('json', 'Class', 'api/json/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_document', 'Class', 'api/json_document/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_view', 'Class', 'api/json_view/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer', 'Class', 'api/json_pointer/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer', 'Class', 'api/json_pointer/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::back', 'Method', 'api/json_pointer/back/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::back', 'Method', 'api/json_pointer/back/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::empty', 'Method', 'api/json_pointer/empty/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::empty', 'Method', 'api/json_pointer/empty/index.html');
|
||||||
@@ -198,8 +162,6 @@ INSERT INTO searchIndex(name, type, path) VALUES ('operator""_json_pointer', 'Li
|
|||||||
INSERT INTO searchIndex(name, type, path) VALUES ('operator<<', 'Operator', 'api/operator_ltlt/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('operator<<', 'Operator', 'api/operator_ltlt/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('operator>>', 'Operator', 'api/operator_gtgt/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('operator>>', 'Operator', 'api/operator_gtgt/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('ordered_json', 'Class', 'api/ordered_json/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('ordered_json', 'Class', 'api/ordered_json/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('ordered_json_document', 'Class', 'api/ordered_json_document/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('ordered_json_view', 'Class', 'api/ordered_json_view/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('ordered_map', 'Class', 'api/ordered_map/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('ordered_map', 'Class', 'api/ordered_map/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('std::hash<basic_json>', 'Class', 'api/basic_json/std_hash/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('std::hash<basic_json>', 'Class', 'api/basic_json/std_hash/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('std::swap<basic_json>', 'Function', 'api/basic_json/std_swap/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('std::swap<basic_json>', 'Function', 'api/basic_json/std_swap/index.html');
|
||||||
@@ -229,7 +191,6 @@ INSERT INTO searchIndex(name, type, path) VALUES ('Iterators', 'Guide', 'feature
|
|||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON Merge Patch', 'Guide', 'features/merge_patch/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON Merge Patch', 'Guide', 'features/merge_patch/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON Patch and Diff', 'Guide', 'features/json_patch/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON Patch and Diff', 'Guide', 'features/json_patch/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON Pointer', 'Guide', 'features/json_pointer/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON Pointer', 'Guide', 'features/json_pointer/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('Zero-copy JSON views', 'Guide', 'features/json_view/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('nlohmann Namespace', 'Guide', 'features/namespace/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('nlohmann Namespace', 'Guide', 'features/namespace/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('Types', 'Guide', 'features/types/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('Types', 'Guide', 'features/types/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('Types: Number Handling', 'Guide', 'features/types/number_handling/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('Types: Number Handling', 'Guide', 'features/types/number_handling/index.html');
|
||||||
@@ -249,7 +210,6 @@ INSERT INTO searchIndex(name, type, path) VALUES ('JSON_CATCH_USER', 'Macro', 'a
|
|||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DIAGNOSTICS', 'Macro', 'api/macros/json_diagnostics/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DIAGNOSTICS', 'Macro', 'api/macros/json_diagnostics/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DIAGNOSTIC_POSITIONS', 'Macro', 'api/macros/json_diagnostic_positions/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DIAGNOSTIC_POSITIONS', 'Macro', 'api/macros/json_diagnostic_positions/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DISABLE_ENUM_SERIALIZATION', 'Macro', 'api/macros/json_disable_enum_serialization/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DISABLE_ENUM_SERIALIZATION', 'Macro', 'api/macros/json_disable_enum_serialization/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DISABLE_TUPLE_REFERENCE_CONVERSION', 'Macro', 'api/macros/json_disable_tuple_reference_conversion/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_11', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_11', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_14', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_14', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_17', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_17', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||||
|
|||||||
@@ -159,8 +159,6 @@ basic_json(basic_json&& other) noexcept;
|
|||||||
- `CompatibleType` is not `basic_json` (to avoid hijacking copy/move constructors),
|
- `CompatibleType` is not `basic_json` (to avoid hijacking copy/move constructors),
|
||||||
- `CompatibleType` is not a different `basic_json` type (i.e. with different template arguments)
|
- `CompatibleType` is not a different `basic_json` type (i.e. with different template arguments)
|
||||||
- `CompatibleType` is not a `basic_json` nested type (e.g., `json_pointer`, `iterator`, etc.)
|
- `CompatibleType` is not a `basic_json` nested type (e.g., `json_pointer`, `iterator`, etc.)
|
||||||
- if [`JSON_DISABLE_TUPLE_REFERENCE_CONVERSION`](../macros/json_disable_tuple_reference_conversion.md) is defined
|
|
||||||
to `1`: `CompatibleType` is not a one-element `std::tuple` holding a reference to `basic_json`
|
|
||||||
- `json_serializer<U>` (with `U = uncvref_t<CompatibleType>`) has a `to_json(basic_json_t&, CompatibleType&&)`
|
- `json_serializer<U>` (with `U = uncvref_t<CompatibleType>`) has a `to_json(basic_json_t&, CompatibleType&&)`
|
||||||
method
|
method
|
||||||
|
|
||||||
|
|||||||
@@ -60,10 +60,6 @@ itself is empty which is `#!cpp false` in the case of a string.
|
|||||||
--8<-- "examples/empty.output"
|
--8<-- "examples/empty.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [basic_json_view::empty](../basic_json_view/empty.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ Constant.
|
|||||||
--8<-- "examples/is_array.output"
|
--8<-- "examples/is_array.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [basic_json_view::is_array](../basic_json_view/is_array.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ Constant.
|
|||||||
--8<-- "examples/is_binary.output"
|
--8<-- "examples/is_binary.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [basic_json_view::is_binary](../basic_json_view/is_binary.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.8.0.
|
- Added in version 3.8.0.
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ Constant.
|
|||||||
--8<-- "examples/is_boolean.output"
|
--8<-- "examples/is_boolean.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [basic_json_view::is_boolean](../basic_json_view/is_boolean.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@@ -69,11 +69,6 @@ with `allow_exceptions` set to `#!cpp false`: a parse error then yields a discar
|
|||||||
--8<-- "examples/is_discarded.output"
|
--8<-- "examples/is_discarded.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [basic_json_view::is_discarded](../basic_json_view/is_discarded.md) - the corresponding check on a zero-copy view,
|
|
||||||
which is `#!cpp true` if the view refers to no value
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ Constant.
|
|||||||
--8<-- "examples/is_null.output"
|
--8<-- "examples/is_null.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [basic_json_view::is_null](../basic_json_view/is_null.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ constexpr bool is_number() const noexcept
|
|||||||
- [is_number_integer()](is_number_integer.md) check if the value is an integer or unsigned integer number
|
- [is_number_integer()](is_number_integer.md) check if the value is an integer or unsigned integer number
|
||||||
- [is_number_unsigned()](is_number_unsigned.md) check if the value is an unsigned integer number
|
- [is_number_unsigned()](is_number_unsigned.md) check if the value is an unsigned integer number
|
||||||
- [is_number_float()](is_number_float.md) check if the value is a floating-point number
|
- [is_number_float()](is_number_float.md) check if the value is a floating-point number
|
||||||
- [basic_json_view::is_number](../basic_json_view/is_number.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ Constant.
|
|||||||
- [is_number()](is_number.md) check if the value is a number
|
- [is_number()](is_number.md) check if the value is a number
|
||||||
- [is_number_integer()](is_number_integer.md) check if the value is an integer or unsigned integer number
|
- [is_number_integer()](is_number_integer.md) check if the value is an integer or unsigned integer number
|
||||||
- [is_number_unsigned()](is_number_unsigned.md) check if the value is an unsigned integer number
|
- [is_number_unsigned()](is_number_unsigned.md) check if the value is an unsigned integer number
|
||||||
- [basic_json_view::is_number_float](../basic_json_view/is_number_float.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ Constant.
|
|||||||
- [is_number()](is_number.md) check if the value is a number
|
- [is_number()](is_number.md) check if the value is a number
|
||||||
- [is_number_unsigned()](is_number_unsigned.md) check if the value is an unsigned integer number
|
- [is_number_unsigned()](is_number_unsigned.md) check if the value is an unsigned integer number
|
||||||
- [is_number_float()](is_number_float.md) check if the value is a floating-point number
|
- [is_number_float()](is_number_float.md) check if the value is a floating-point number
|
||||||
- [basic_json_view::is_number_integer](../basic_json_view/is_number_integer.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ Constant.
|
|||||||
- [is_number()](is_number.md) check if the value is a number
|
- [is_number()](is_number.md) check if the value is a number
|
||||||
- [is_number_integer()](is_number_integer.md) check if the value is an integer or unsigned integer number
|
- [is_number_integer()](is_number_integer.md) check if the value is an integer or unsigned integer number
|
||||||
- [is_number_float()](is_number_float.md) check if the value is a floating-point number
|
- [is_number_float()](is_number_float.md) check if the value is a floating-point number
|
||||||
- [basic_json_view::is_number_unsigned](../basic_json_view/is_number_unsigned.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ Constant.
|
|||||||
--8<-- "examples/is_object.output"
|
--8<-- "examples/is_object.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [basic_json_view::is_object](../basic_json_view/is_object.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ This library extends primitive types to binary types, because binary types are r
|
|||||||
- [is_boolean()](is_boolean.md) returns whether the JSON value is a boolean
|
- [is_boolean()](is_boolean.md) returns whether the JSON value is a boolean
|
||||||
- [is_number()](is_number.md) returns whether the JSON value is a number
|
- [is_number()](is_number.md) returns whether the JSON value is a number
|
||||||
- [is_binary()](is_binary.md) returns whether the JSON value is a binary array
|
- [is_binary()](is_binary.md) returns whether the JSON value is a binary array
|
||||||
- [basic_json_view::is_primitive](../basic_json_view/is_primitive.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ Constant.
|
|||||||
--8<-- "examples/is_string.output"
|
--8<-- "examples/is_string.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [basic_json_view::is_string](../basic_json_view/is_string.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ Note that though strings are containers in C++, they are treated as primitive va
|
|||||||
- [is_primitive()](is_primitive.md) returns whether JSON value is primitive
|
- [is_primitive()](is_primitive.md) returns whether JSON value is primitive
|
||||||
- [is_array()](is_array.md) returns whether the value is an array
|
- [is_array()](is_array.md) returns whether the value is an array
|
||||||
- [is_object()](is_object.md) returns whether the value is an object
|
- [is_object()](is_object.md) returns whether the value is an object
|
||||||
- [basic_json_view::is_structured](../basic_json_view/is_structured.md) - the same check on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@@ -37,12 +37,6 @@ Thereby, `Target` is the current object; that is, the patch is applied to the cu
|
|||||||
|
|
||||||
Linear in the lengths of `apply_patch`.
|
Linear in the lengths of `apply_patch`.
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
`apply_patch` may be `#!cpp *this` itself or refer to a value contained in `#!cpp *this` (for example, a subobject
|
|
||||||
returned by `#!cpp (*this)[key]`); it is read as it was when `merge_patch()` was called, before any modification of
|
|
||||||
`#!cpp *this`.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
@@ -67,5 +61,3 @@ returned by `#!cpp (*this)[key]`); it is read as it was when `merge_patch()` was
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.0.0.
|
- Added in version 3.0.0.
|
||||||
- Fixed use of freed or relocated memory when `apply_patch` is `#!cpp *this` or refers to a value contained in
|
|
||||||
`#!cpp *this`, in version 3.13.0.
|
|
||||||
|
|||||||
@@ -23,10 +23,9 @@ type to use.
|
|||||||
## Template parameters
|
## Template parameters
|
||||||
|
|
||||||
`NumberFloatType`
|
`NumberFloatType`
|
||||||
: the type to store floating-point numbers. The parser converts `#!cpp float`, `#!cpp double`, and a
|
: the type to store floating-point numbers. Parsing and serialization are implemented in terms of
|
||||||
`#!cpp long double` that is IEEE 754 binary64 itself and other `#!cpp long double` formats with
|
`#!cpp std::strtof`/`#!cpp std::strtod`/`#!cpp std::strtold` and `#!cpp std::snprintf`, so the type must be
|
||||||
`#!cpp std::from_chars` or `#!cpp std::strtold`, and serialization falls back to `#!cpp std::snprintf`, so the
|
`#!cpp float`, `#!cpp double`, or `#!cpp long double`. The
|
||||||
type must be `#!cpp float`, `#!cpp double`, or `#!cpp long double`. The
|
|
||||||
[binary formats](../../features/binary_formats/index.md) additionally require `#!cpp float` or `#!cpp double`,
|
[binary formats](../../features/binary_formats/index.md) additionally require `#!cpp float` or `#!cpp double`,
|
||||||
because they have no encoding for `#!cpp long double`. See
|
because they have no encoding for `#!cpp long double`. See
|
||||||
[Template Parameter Requirements](../../features/types/template_parameters.md#numberfloattype).
|
[Template Parameter Requirements](../../features/types/template_parameters.md#numberfloattype).
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ range will yield over/underflow when used in a constructor. During deserializati
|
|||||||
will automatically be stored as [`number_unsigned_t`](number_unsigned_t.md) or [`number_float_t`](number_float_t.md).
|
will automatically be stored as [`number_unsigned_t`](number_unsigned_t.md) or [`number_float_t`](number_float_t.md).
|
||||||
|
|
||||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
||||||
> Note that when such software is used, numbers that are integers and are in the range [-2<sup>53</sup>+1, 2<sup>53</sup>-1] are
|
> Note that when such software is used, numbers that are integers and are in the range $[-2^{53}+1, 2^{53}-1]$ are
|
||||||
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
||||||
|
|
||||||
As this range is a subrange of the exactly supported range [INT64_MIN, INT64_MAX], this class's integer type is
|
As this range is a subrange of the exactly supported range [INT64_MIN, INT64_MAX], this class's integer type is
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ when used in a constructor. During deserialization, too large or small integer n
|
|||||||
as [`number_integer_t`](number_integer_t.md) or [`number_float_t`](number_float_t.md).
|
as [`number_integer_t`](number_integer_t.md) or [`number_float_t`](number_float_t.md).
|
||||||
|
|
||||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
||||||
> Note that when such software is used, numbers that are integers and are in the range [-2<sup>53</sup>+1, 2<sup>53</sup>-1] are
|
> Note that when such software is used, numbers that are integers and are in the range $[-2^{53}+1, 2^{53}-1]$ are
|
||||||
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
||||||
|
|
||||||
As this range is a subrange (when considered in conjunction with the `number_integer_t` type) of the exactly supported
|
As this range is a subrange (when considered in conjunction with the `number_integer_t` type) of the exactly supported
|
||||||
|
|||||||
@@ -89,6 +89,9 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
- Throws [`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) if an array index in the passed
|
- Throws [`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) if an array index in the passed
|
||||||
JSON pointer `ptr` exceeds the range of `size_type` (e.g., on 32-bit platforms).
|
JSON pointer `ptr` exceeds the range of `size_type` (e.g., on 32-bit platforms).
|
||||||
|
|
||||||
|
For the **const** version, an object key or array index in `ptr` that does not exist is not reported by an
|
||||||
|
exception, but is undefined behavior (see the notes below). Use [`at`](at.md) for checked access.
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
1. Constant if `idx` is in the range of the array. Otherwise, linear in `idx - size()`.
|
1. Constant if `idx` is in the range of the array. Otherwise, linear in `idx - size()`.
|
||||||
@@ -103,9 +106,12 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
The following cases apply to the **const** overloads; the non-const overloads instead insert the missing element
|
The following cases apply to the **const** overloads; the non-const overloads instead insert the missing element
|
||||||
(see the notes below).
|
(see the notes below).
|
||||||
|
|
||||||
1. If the element at index `idx` does not exist, the behavior is undefined.
|
1. If the element at index `idx` does not exist, the behavior is undefined and is **guarded by a
|
||||||
|
[runtime assertion](../../features/assertions.md)**!
|
||||||
2. If the element with key `key` does not exist, the behavior is undefined and is **guarded by a
|
2. If the element with key `key` does not exist, the behavior is undefined and is **guarded by a
|
||||||
[runtime assertion](../../features/assertions.md)**!
|
[runtime assertion](../../features/assertions.md)**!
|
||||||
|
3. If the JSON pointer `ptr` refers to an object key or an array index that does not exist, the behavior is
|
||||||
|
undefined and is **guarded by a [runtime assertion](../../features/assertions.md)**!
|
||||||
|
|
||||||
1. The non-const version may add values: If `idx` is beyond the range of the array (i.e., `idx >= size()`), then the
|
1. The non-const version may add values: If `idx` is beyond the range of the array (i.e., `idx >= size()`), then the
|
||||||
array is silently filled up with `#!json null` values to make `idx` a valid reference to the last stored element. In
|
array is silently filled up with `#!json null` values to make `idx` a valid reference to the last stored element. In
|
||||||
@@ -261,9 +267,11 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Added in version 1.0.0. Fixed in version 3.13.0 to throw `#!cpp std::length_error` instead of emptying the array and
|
1. Added in version 1.0.0. Fixed in version 3.13.0 to throw `#!cpp std::length_error` instead of emptying the array and
|
||||||
accessing it out of bounds when `idx` equals the maximum value of `size_type`.
|
accessing it out of bounds when `idx` equals the maximum value of `size_type`. A missing index in the const version
|
||||||
|
is guarded by a runtime assertion since version 3.13.0.
|
||||||
2. Added in version 1.0.0. Added overloads for `T* key` in version 1.1.0. Removed overloads for `T* key` (replaced by 3)
|
2. Added in version 1.0.0. Added overloads for `T* key` in version 1.1.0. Removed overloads for `T* key` (replaced by 3)
|
||||||
in version 3.11.0.
|
in version 3.11.0.
|
||||||
3. Added in version 3.11.0. Fixed in version 3.13.0 to consistently accept `std::string_view`-convertible keys, as
|
3. Added in version 3.11.0. Fixed in version 3.13.0 to consistently accept `std::string_view`-convertible keys, as
|
||||||
already supported by [`at`](at.md), [`value`](value.md), [`find`](find.md), and other lookup functions.
|
already supported by [`at`](at.md), [`value`](value.md), [`find`](find.md), and other lookup functions.
|
||||||
4. Added in version 2.0.0.
|
4. Added in version 2.0.0. A missing array index in the const version is guarded by a runtime assertion since
|
||||||
|
version 3.13.0.
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ classDiagram
|
|||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
For an input with <i>n</i> bytes, 1 is the index of the first character and <i>n</i>+1 is the index of the terminating null byte
|
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 for binary formats.
|
or the end of file. This also holds true when reading a byte vector for binary formats.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|||||||
@@ -51,10 +51,6 @@ JSON value which is `1` in the case of a string.
|
|||||||
--8<-- "examples/size.output"
|
--8<-- "examples/size.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [basic_json_view::size](../basic_json_view/size.md) - the same function on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@@ -47,10 +47,6 @@ Constant.
|
|||||||
--8<-- "examples/type.output"
|
--8<-- "examples/type.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [basic_json_view::type](../basic_json_view/type.md) - the same function on a zero-copy view
|
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@@ -59,12 +59,6 @@ Basic guarantee: if an exception is thrown during the operation, the JSON value
|
|||||||
1. O(N*log(size() + N)), where N is the number of elements to insert.
|
1. O(N*log(size() + N)), where N is the number of elements to insert.
|
||||||
2. O(N*log(size() + N)), where N is the number of elements to insert.
|
2. O(N*log(size() + N)), where N is the number of elements to insert.
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
The argument `j` (or, for overload (2), the range `[first, last)`) may be `#!cpp *this` itself or refer to a value
|
|
||||||
contained in `#!cpp *this` (for example, a subobject returned by `#!cpp (*this)[key]`); it is read as it was when
|
|
||||||
`update()` was called, before any modification of `#!cpp *this`.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
@@ -161,5 +155,3 @@ contained in `#!cpp *this` (for example, a subobject returned by `#!cpp (*this)[
|
|||||||
|
|
||||||
- Added in version 3.0.0.
|
- Added in version 3.0.0.
|
||||||
- Added `merge_objects` parameter in 3.10.5.
|
- Added `merge_objects` parameter in 3.10.5.
|
||||||
- Fixed use of freed or relocated memory when the argument is `#!cpp *this` or refers to a value contained in
|
|
||||||
`#!cpp *this`, in version 3.13.0.
|
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>accept
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
template<typename InputType>
|
|
||||||
static bool accept(InputType&& input,
|
|
||||||
const bool ignore_comments = false,
|
|
||||||
const bool ignore_trailing_commas = false);
|
|
||||||
```
|
|
||||||
|
|
||||||
Checks whether the input is valid JSON, accepting and rejecting exactly what
|
|
||||||
[`BasicJsonType::accept()`](../basic_json/accept.md) does, with the same options. Unlike [`parse()`](parse.md), this
|
|
||||||
function never throws an exception for invalid input, and the returned `#!cpp bool` is the only result -- no document
|
|
||||||
is returned.
|
|
||||||
|
|
||||||
## Template parameters
|
|
||||||
|
|
||||||
`InputType`
|
|
||||||
: A compatible input; see [`parse`](parse.md#template-parameters).
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
`input` (in)
|
|
||||||
: Input to check.
|
|
||||||
|
|
||||||
`ignore_comments` (in)
|
|
||||||
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
|
||||||
(`#!cpp false`); (optional, `#!cpp false` by default)
|
|
||||||
|
|
||||||
`ignore_trailing_commas` (in)
|
|
||||||
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or
|
|
||||||
yield a parse error (`#!cpp false`); (optional, `#!cpp false` by default)
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
Whether the input is valid JSON.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
Strong guarantee: this function itself never throws for an invalid input; it can only throw what allocating the
|
|
||||||
input's own copy (for inputs that are always read into a buffer) throws.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Linear in the length of the input.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__accept.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__accept.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [parse](parse.md) - deserialize from a compatible input
|
|
||||||
- [`BasicJsonType::accept`](../basic_json/accept.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>basic_json_document
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
// (1)
|
|
||||||
basic_json_document() = default;
|
|
||||||
|
|
||||||
// (2)
|
|
||||||
basic_json_document(basic_json_document&& other) noexcept = default;
|
|
||||||
|
|
||||||
// (3)
|
|
||||||
basic_json_document(const basic_json_document&) = delete;
|
|
||||||
```
|
|
||||||
|
|
||||||
1. Creates an empty (discarded) document: [`root()`](root.md) returns a discarded view, and
|
|
||||||
[`is_discarded()`](is_discarded.md) is `#!cpp true`.
|
|
||||||
2. Move constructor. Takes over `other`'s index and, if owned, its text; `other` is left as an empty document. Views
|
|
||||||
taken from `other` before the move remain valid, because the index is heap-allocated independently of the
|
|
||||||
`basic_json_document` object.
|
|
||||||
3. `basic_json_document` is move-only. Copying is disabled because it would either duplicate a potentially large index
|
|
||||||
and text, or leave two documents claiming to borrow the same buffer.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
`other` (in)
|
|
||||||
: another document to move the index and text from
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: the default and move constructors never throw exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant, for the default and move constructors.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below shows the default constructor and demonstrates that `basic_json_document` is move-only.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__basic_json_document.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__basic_json_document.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [parse](parse.md) - deserialize from a compatible input
|
|
||||||
- [is_discarded](is_discarded.md) - return whether the last parse failed
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
# <small>nlohmann::</small>basic_json_document
|
|
||||||
|
|
||||||
<small>Defined in header `<nlohmann/json_view.hpp>`</small>
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
template<typename BasicJsonType>
|
|
||||||
class basic_json_document;
|
|
||||||
```
|
|
||||||
|
|
||||||
A parsed JSON text, held as a flat index of its values
|
|
||||||
([16 bytes per value](../../home/architecture.md#node-index-of-json-views)) instead of a tree of `BasicJsonType` values.
|
|
||||||
Strings and numbers stay in the source text; only strings that contain escapes are decoded, into one buffer owned by
|
|
||||||
the document. [`basic_json_view`](../basic_json_view/index.md) is a read-only handle to one value of a
|
|
||||||
`basic_json_document`; [`materialize()`](../basic_json_view/materialize.md) turns a subtree back into the
|
|
||||||
`BasicJsonType` value that [`BasicJsonType::parse()`](../basic_json/parse.md) would have produced for it.
|
|
||||||
|
|
||||||
A document may **borrow** the text it was parsed from (the caller's buffer must then outlive the document) or **own**
|
|
||||||
it (a copy, or an rvalue `#!cpp std::string` that was moved in); see [`owns_source`](owns_source.md). `basic_json_document`
|
|
||||||
is move-only: copying a document would either duplicate a potentially large index and text, or leave two documents
|
|
||||||
claiming to borrow the same buffer, so it is disabled.
|
|
||||||
|
|
||||||
## Template parameters
|
|
||||||
|
|
||||||
`BasicJsonType`
|
|
||||||
: a specialization of [`basic_json`](../basic_json/index.md), for instance [`json`](../json.md) or
|
|
||||||
[`ordered_json`](../ordered_json.md). Only 64-bit `number_integer_t`/`number_unsigned_t` types are supported; this
|
|
||||||
is checked with a `static_assert`.
|
|
||||||
|
|
||||||
## Specializations
|
|
||||||
|
|
||||||
- [**json_document**](../json_document.md) - documents of the default specialization [`json`](../json.md)
|
|
||||||
- [**ordered_json_document**](../ordered_json_document.md) - documents of [`ordered_json`](../ordered_json.md)
|
|
||||||
|
|
||||||
## Member types
|
|
||||||
|
|
||||||
- **view_type** - the type of view returned by [`root()`](root.md) (`#!cpp basic_json_view<BasicJsonType>`)
|
|
||||||
- **value_t** - the JSON type enumeration, see [`basic_json::value_t`](../basic_json/value_t.md)
|
|
||||||
|
|
||||||
## Member functions
|
|
||||||
|
|
||||||
- [(constructor)](basic_json_document.md)
|
|
||||||
- [**parse**](parse.md) (_static_) - deserialize from a compatible input, borrowing or owning it as appropriate
|
|
||||||
- [**parse_copy**](parse_copy.md) (_static_) - deserialize a copy of a compatible input
|
|
||||||
- [**accept**](accept.md) (_static_) - check whether the input is valid JSON
|
|
||||||
- [**read**](read.md) - (re-)parse into this document, reusing its memory
|
|
||||||
- [**root**](root.md) - the view of the root value
|
|
||||||
- [**is_discarded**](is_discarded.md) - return whether the last parse failed
|
|
||||||
- [**source**](source.md) - the parsed text
|
|
||||||
- [**owns_source**](owns_source.md) - return whether the document holds its own copy of the text
|
|
||||||
- [**node_count**](node_count.md) - the number of index entries (values plus object keys)
|
|
||||||
- [**memory_usage**](memory_usage.md) - the number of bytes held by the document
|
|
||||||
- [**shrink_to_fit**](shrink_to_fit.md) - release unused index capacity
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>is_discarded
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_discarded() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns whether the document holds no value, either because it was default-constructed or because the last call to
|
|
||||||
[`parse()`](parse.md), [`parse_copy()`](parse_copy.md), or [`read()`](read.md) failed with `allow_exceptions` set to
|
|
||||||
`#!cpp false`.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the document is discarded, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
When the document is discarded, [`root()`](root.md) returns a discarded view (its
|
|
||||||
[`is_discarded()`](../basic_json_view/is_discarded.md) is also `#!cpp true`).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__is_discarded.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__is_discarded.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [parse](parse.md) - deserialize from a compatible input
|
|
||||||
- [is_discarded (basic_json_view)](../basic_json_view/is_discarded.md) - return whether a view is invalid
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>memory_usage
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
std::size_t memory_usage() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns the number of bytes held by the document: the node index, the decoded-string buffer (for strings that
|
|
||||||
contain escapes), and, for an owned document, its copy of the source text.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
The number of bytes the document holds, `0` for a [discarded](is_discarded.md) document.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
The exact value depends on the platform, the allocator, and the library's own layout, and may change between
|
|
||||||
versions; do not rely on it being a specific number, and do not compare it across different builds or platforms.
|
|
||||||
Compare it for the same document over time, or between documents built with the same binary, instead -- for instance
|
|
||||||
to observe the effect of [`shrink_to_fit()`](shrink_to_fit.md).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__memory_usage.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__memory_usage.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [node_count](node_count.md) - the number of index entries
|
|
||||||
- [shrink_to_fit](shrink_to_fit.md) - release unused index capacity
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>node_count
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
std::size_t node_count() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns the number of entries in the document's flat index.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
The number of index entries: one per value (of any type, at any nesting depth) plus one per object key. `0` for a
|
|
||||||
[discarded](is_discarded.md) document.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
Each index entry is [16 bytes](../../home/architecture.md#node-index-of-json-views), so `#!cpp node_count() * 16` is
|
|
||||||
the size of the index itself (part, but not all, of [`memory_usage()`](memory_usage.md), which also counts decoded
|
|
||||||
strings and, for an owned document, the text).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__node_count.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__node_count.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [memory_usage](memory_usage.md) - the number of bytes held by the document
|
|
||||||
- [shrink_to_fit](shrink_to_fit.md) - release unused index capacity
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>owns_source
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool owns_source() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns whether the document holds its own copy of the parsed text, as opposed to borrowing the caller's buffer.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the document owns the text returned by [`source()`](source.md), `#!cpp false` if it borrows it (or if
|
|
||||||
the document is [discarded](is_discarded.md)).
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
See the ownership table on [`parse`](parse.md#notes) for which inputs are borrowed and which are owned. A borrowed
|
|
||||||
document (`#!cpp owns_source() == false`) is only valid while the buffer it was parsed from is still alive.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__owns_source.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__owns_source.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [parse](parse.md) - deserialize from a compatible input
|
|
||||||
- [parse_copy](parse_copy.md) - deserialize a copy of a compatible input, always owned
|
|
||||||
- [source](source.md) - the parsed text
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>parse
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
// (1)
|
|
||||||
template<typename InputType>
|
|
||||||
static basic_json_document parse(InputType&& input,
|
|
||||||
const bool allow_exceptions = true,
|
|
||||||
const bool ignore_comments = false,
|
|
||||||
const bool ignore_trailing_commas = false);
|
|
||||||
|
|
||||||
// (2)
|
|
||||||
template<typename IteratorType>
|
|
||||||
static basic_json_document parse(IteratorType first, IteratorType last,
|
|
||||||
const bool allow_exceptions = true,
|
|
||||||
const bool ignore_comments = false,
|
|
||||||
const bool ignore_trailing_commas = false);
|
|
||||||
```
|
|
||||||
|
|
||||||
1. Deserialize from a compatible input, borrowing or owning it depending on its value category and type (see Notes).
|
|
||||||
2. Deserialize from a pair of input iterators.
|
|
||||||
|
|
||||||
Both overloads accept exactly what [`BasicJsonType::parse()`](../basic_json/parse.md) accepts, with the same
|
|
||||||
`ignore_comments`/`ignore_trailing_commas` options, but build a [`basic_json_document`](index.md) (a flat index into
|
|
||||||
the input) instead of a tree of `BasicJsonType` values.
|
|
||||||
|
|
||||||
## Template parameters
|
|
||||||
|
|
||||||
`InputType`
|
|
||||||
: A compatible input, for instance:
|
|
||||||
|
|
||||||
- a `#!cpp std::string`, `#!cpp std::string_view`, or a C-style array of characters
|
|
||||||
- a pointer to a null-terminated string of single byte characters
|
|
||||||
- a container for which `#!cpp obj.data()` and `#!cpp obj.size()` give contiguous single-byte access, e.g.
|
|
||||||
`#!cpp std::vector<char>` or `#!cpp std::vector<std::uint8_t>`
|
|
||||||
- an `#!cpp std::istream` object, or anything else [`BasicJsonType::parse()`](../basic_json/parse.md) accepts
|
|
||||||
|
|
||||||
`IteratorType`
|
|
||||||
: a compatible iterator type, for instance a pair of pointers such as `ptr` and `ptr + len`, or a pair of
|
|
||||||
`#!cpp std::string::iterator`
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
`input` (in)
|
|
||||||
: Input to parse from.
|
|
||||||
|
|
||||||
`allow_exceptions` (in)
|
|
||||||
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
|
||||||
|
|
||||||
`ignore_comments` (in)
|
|
||||||
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
|
||||||
(`#!cpp false`); (optional, `#!cpp false` by default)
|
|
||||||
|
|
||||||
`ignore_trailing_commas` (in)
|
|
||||||
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or
|
|
||||||
yield a parse error (`#!cpp false`); (optional, `#!cpp false` by default)
|
|
||||||
|
|
||||||
`first` (in)
|
|
||||||
: iterator to the start of a character range
|
|
||||||
|
|
||||||
`last` (in)
|
|
||||||
: iterator to the end of a character range
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
The parsed document. If `allow_exceptions` is `#!cpp false` and the input is not valid JSON, the returned document is
|
|
||||||
discarded; see [`is_discarded`](is_discarded.md).
|
|
||||||
|
|
||||||
## Exceptions
|
|
||||||
|
|
||||||
Throws the same exception [`BasicJsonType::parse()`](../basic_json/parse.md) throws for the same input and options --
|
|
||||||
the same exception id, message, and position -- because on a failing input the library's own parser is run on the
|
|
||||||
same bytes to produce the diagnostic. Additionally throws
|
|
||||||
[`out_of_range.416`](../../home/exceptions.md#jsonexceptionout_of_range416) if the input is 4 GiB or larger, a size
|
|
||||||
[`BasicJsonType::parse()`](../basic_json/parse.md) does not reject.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Linear in the length of the input.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
**Ownership.** Whether the document borrows `input` or owns a copy of it depends on its value category and type:
|
|
||||||
|
|
||||||
| `input` | ownership |
|
|
||||||
|--------------------------------------------------------------------------------------|--------------------------------------------------------------|
|
|
||||||
| lvalue byte container (`std::string`, `std::vector<char>`, ...), `std::string_view`, C string, character array | **borrowed** -- `input` must outlive the document |
|
|
||||||
| rvalue `#!cpp std::string` | **owned**, moved in without a copy |
|
|
||||||
| rvalue byte container other than `#!cpp std::string` | **owned**, copied |
|
|
||||||
| stream, wide string, or anything else read through the general input adapter | **owned**, read into a buffer (a stream is read to its end) |
|
|
||||||
|
|
||||||
For overload (2), a pair of pointers to single-byte integers (e.g. `#!cpp const char*`, `#!cpp std::uint8_t*`) is
|
|
||||||
borrowed. From C++20 on, so is any other contiguous iterator over single bytes, such as
|
|
||||||
`#!cpp std::vector<char>::iterator` or `#!cpp std::string::const_iterator`. Before C++20 these iterators cannot be
|
|
||||||
told apart from other class-type iterators, so their range is read into an owned buffer, as is any non-contiguous
|
|
||||||
range (e.g. of a `#!cpp std::list<char>`).
|
|
||||||
|
|
||||||
See [`owns_source`](owns_source.md) to check which happened after a call, and the
|
|
||||||
[feature page](../../features/json_view.md) for the reasoning.
|
|
||||||
|
|
||||||
**Numbers.** As for [`BasicJsonType::parse()`](../basic_json/parse.md), an integer literal too large for the 64-bit
|
|
||||||
integer type becomes a floating-point value.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example "Example: (1) borrowed vs. owned input, and errors identical to `BasicJsonType::parse()`"
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__parse.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__parse.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
??? example "Example: (2) parse an iterator range (no NUL terminator required)"
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__parse_iterator_pair.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__parse_iterator_pair.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [parse_copy](parse_copy.md) - deserialize a copy of a compatible input
|
|
||||||
- [accept](accept.md) - check whether the input is valid JSON
|
|
||||||
- [read](read.md) - (re-)parse into this document, reusing its memory
|
|
||||||
- [owns_source](owns_source.md) - return whether the document holds its own copy of the text
|
|
||||||
- [`BasicJsonType::parse`](../basic_json/parse.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>parse_copy
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
template<typename InputType>
|
|
||||||
static basic_json_document parse_copy(InputType&& input,
|
|
||||||
const bool allow_exceptions = true,
|
|
||||||
const bool ignore_comments = false,
|
|
||||||
const bool ignore_trailing_commas = false);
|
|
||||||
```
|
|
||||||
|
|
||||||
Deserialize from a compatible input, always taking the document's own copy of it, regardless of the value category or
|
|
||||||
type of `input`. Unlike [`parse()`](parse.md), the returned document never depends on `input` staying alive.
|
|
||||||
|
|
||||||
## Template parameters
|
|
||||||
|
|
||||||
`InputType`
|
|
||||||
: A compatible input; see [`parse`](parse.md#template-parameters).
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
`input` (in)
|
|
||||||
: Input to parse from.
|
|
||||||
|
|
||||||
`allow_exceptions` (in)
|
|
||||||
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
|
||||||
|
|
||||||
`ignore_comments` (in)
|
|
||||||
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
|
||||||
(`#!cpp false`); (optional, `#!cpp false` by default)
|
|
||||||
|
|
||||||
`ignore_trailing_commas` (in)
|
|
||||||
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or
|
|
||||||
yield a parse error (`#!cpp false`); (optional, `#!cpp false` by default)
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
The parsed document, with [`owns_source()`](owns_source.md) `#!cpp true`. If `allow_exceptions` is `#!cpp false` and
|
|
||||||
the input is not valid JSON, the returned document is discarded; see [`is_discarded`](is_discarded.md).
|
|
||||||
|
|
||||||
## Exceptions
|
|
||||||
|
|
||||||
Same as [`parse`](parse.md#exceptions).
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Linear in the length of the input.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
`parse_copy()` accepts and rejects exactly what [`parse()`](parse.md) does, and classifies numbers the same way; it
|
|
||||||
only differs in that the input is always copied rather than sometimes borrowed. Prefer [`parse()`](parse.md) when the
|
|
||||||
input's lifetime already covers the document's, since it avoids the copy for borrowed inputs.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below returns a document from a function whose local buffer would otherwise not outlive it.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__parse_copy.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__parse_copy.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [parse](parse.md) - deserialize from a compatible input, borrowing it where possible
|
|
||||||
- [owns_source](owns_source.md) - return whether the document holds its own copy of the text
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>read
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
template<typename InputType>
|
|
||||||
void read(InputType&& input,
|
|
||||||
const bool allow_exceptions = true,
|
|
||||||
const bool ignore_comments = false,
|
|
||||||
const bool ignore_trailing_commas = false);
|
|
||||||
```
|
|
||||||
|
|
||||||
(Re-)parses `input` into `#!cpp *this`, discarding the document's previous value and reusing its memory (the node
|
|
||||||
index, the decoded-string buffer, and, if applicable, the owned copy of the text) rather than allocating a fresh
|
|
||||||
document. [`parse()`](parse.md) is implemented in terms of this function, applied to a default-constructed document.
|
|
||||||
|
|
||||||
## Template parameters
|
|
||||||
|
|
||||||
`InputType`
|
|
||||||
: A compatible input; see [`parse`](parse.md#template-parameters).
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
`input` (in)
|
|
||||||
: Input to parse from.
|
|
||||||
|
|
||||||
`allow_exceptions` (in)
|
|
||||||
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
|
||||||
|
|
||||||
`ignore_comments` (in)
|
|
||||||
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
|
|
||||||
(`#!cpp false`); (optional, `#!cpp false` by default)
|
|
||||||
|
|
||||||
`ignore_trailing_commas` (in)
|
|
||||||
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or
|
|
||||||
yield a parse error (`#!cpp false`); (optional, `#!cpp false` by default)
|
|
||||||
|
|
||||||
## Exceptions
|
|
||||||
|
|
||||||
Same as [`parse`](parse.md#exceptions).
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Linear in the length of the input.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
Every view taken from `#!cpp *this` before the call -- including the previous [`root()`](root.md) -- is invalidated,
|
|
||||||
whether or not the new parse succeeds; take fresh views from [`root()`](root.md) afterward.
|
|
||||||
|
|
||||||
`input` is borrowed or owned by the same rules as [`parse()`](parse.md#notes); a document can borrow on one call and
|
|
||||||
own on the next, since ownership is decided freshly each time.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below parses a sequence of messages into the same document, reusing its memory instead of allocating
|
|
||||||
a new document for each one.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__read.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__read.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [parse](parse.md) - deserialize from a compatible input
|
|
||||||
- [root](root.md) - the view of the root value
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>root
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
view_type root() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns a view of the root value of the document.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
A [`view_type`](index.md#member-types) (i.e. `#!cpp basic_json_view<BasicJsonType>`) for the root value, or a
|
|
||||||
discarded view if the document is [discarded](is_discarded.md).
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
`root()` is a cheap handle into the document's index, not a copy of anything; call it as often as needed. The
|
|
||||||
returned view is valid under the same conditions as any other view of the document -- see
|
|
||||||
[Object inspection](../basic_json_view/index.md) -- in particular, it is invalidated by the next
|
|
||||||
[`read()`](read.md) or [`shrink_to_fit()`](shrink_to_fit.md) on this document.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__root.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__root.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_discarded](is_discarded.md) - return whether the last parse failed
|
|
||||||
- [materialize](../basic_json_view/materialize.md) - build the `BasicJsonType` value of a subtree
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>shrink_to_fit
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
void shrink_to_fit();
|
|
||||||
```
|
|
||||||
|
|
||||||
Releases capacity that is no longer needed, both of the node index and of the buffer for decoded strings (strings that
|
|
||||||
contained escape sequences), e.g. after [`read()`](read.md) replaced a large document with a much smaller one. Like
|
|
||||||
`#!cpp std::vector::shrink_to_fit()`, this is a non-binding request: the library may keep more capacity than strictly
|
|
||||||
necessary.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
Strong guarantee: if an exception is thrown, there are no changes to the document.
|
|
||||||
|
|
||||||
## Exceptions
|
|
||||||
|
|
||||||
May throw `#!cpp std::bad_alloc` if the reallocation fails; on exception, the document is unchanged.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Linear in [`node_count()`](node_count.md) plus the length of the decoded strings.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
!!! warning "Invalidates views"
|
|
||||||
|
|
||||||
Unlike moving the document, `shrink_to_fit()` **invalidates every view taken from this document before the
|
|
||||||
call**, including a previously obtained [`root()`](root.md): the node index is moved into a new, smaller
|
|
||||||
allocation, and the old one is freed. Take a fresh view from [`root()`](root.md) after calling this function.
|
|
||||||
|
|
||||||
This is unlike `#!cpp std::vector::shrink_to_fit()`, which promises nothing about validity but in practice often
|
|
||||||
leaves iterators alone when it did not need to reallocate; here, an implementation that avoids a reallocation when
|
|
||||||
possible would be an internal optimization only, not a guarantee to rely on.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__shrink_to_fit.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__shrink_to_fit.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [node_count](node_count.md) - the number of index entries
|
|
||||||
- [memory_usage](memory_usage.md) - the number of bytes held by the document
|
|
||||||
- [root](root.md) - the view of the root value
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_document::</small>source
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
view_type::string_view_t source() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns the parsed text, whether it is borrowed from the caller or owned by the document.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
A `#!cpp string_view_t` (`#!cpp std::string_view` on C++17 and newer) over the parsed text, or an empty one if the
|
|
||||||
document is [discarded](is_discarded.md).
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
For a borrowed document, `source()` points directly into the caller's buffer, so it is only valid while that buffer
|
|
||||||
is; see [`owns_source`](owns_source.md).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_document__source.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_document__source.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [owns_source](owns_source.md) - return whether the document holds its own copy of the text
|
|
||||||
- [source_offset](../basic_json_view/source_offset.md) - byte offset of a value in the source text
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>basic_json_view
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
basic_json_view() noexcept = default;
|
|
||||||
```
|
|
||||||
|
|
||||||
Creates an invalid (discarded) view: [`type()`](type.md) is `#!cpp value_t::discarded`,
|
|
||||||
[`is_discarded()`](is_discarded.md) is `#!cpp true`, and `#!cpp explicit operator bool()` is `#!cpp false`.
|
|
||||||
|
|
||||||
This is the only constructor a caller can use directly. Every other view is obtained from a
|
|
||||||
[`basic_json_document`](../basic_json_document/index.md), via [`root()`](../basic_json_document/root.md) or (once
|
|
||||||
element access is added) from navigating into a container.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this constructor never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
`basic_json_view` is trivially copyable (it holds two pointers), so a default-constructed view can be used as a
|
|
||||||
placeholder for "no value yet" and later be assigned a real view.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below shows the default constructor and that a `basic_json_view` is a small, copyable handle.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__basic_json_view.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__basic_json_view.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_discarded](is_discarded.md) - return whether the view is invalid
|
|
||||||
- [operator bool](operator_bool.md) - return whether the view refers to a value
|
|
||||||
- [root](../basic_json_document/root.md) - the view of a document's root value
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>empty
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool empty() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Checks whether [`size()`](size.md) is `0`, as [`BasicJsonType::empty()`](../basic_json/empty.md) would for the same
|
|
||||||
value.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
The return value depends on the type and is defined as follows:
|
|
||||||
|
|
||||||
| Value type | return value |
|
|
||||||
|----------------------|-----------------|
|
|
||||||
| null | `#!cpp true` |
|
|
||||||
| discarded | `#!cpp true` |
|
|
||||||
| boolean | `#!cpp false` |
|
|
||||||
| string | `#!cpp false` |
|
|
||||||
| number | `#!cpp false` |
|
|
||||||
| object | `#!cpp object_t::empty()` |
|
|
||||||
| array | `#!cpp array_t::empty()` |
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
As for [`BasicJsonType::empty()`](../basic_json/empty.md), this does not return whether a string value is empty -- it
|
|
||||||
is `#!cpp false` for any string, regardless of its length.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below uses [`size()`](size.md) and `empty()` to decide whether a parsed message is worth acting on,
|
|
||||||
without materializing it into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__size_empty.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__size_empty.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [size](size.md) - return the number of elements
|
|
||||||
- [`BasicJsonType::empty`](../basic_json/empty.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
# <small>nlohmann::</small>basic_json_view
|
|
||||||
|
|
||||||
<small>Defined in header `<nlohmann/json_view.hpp>`</small>
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
template<typename BasicJsonType>
|
|
||||||
class basic_json_view;
|
|
||||||
```
|
|
||||||
|
|
||||||
A read-only handle to one value of a [`basic_json_document`](../basic_json_document/index.md): two pointers (a pointer
|
|
||||||
to the document and a pointer into its index), trivially copyable. A view is valid as long as
|
|
||||||
|
|
||||||
- the document is alive,
|
|
||||||
- the document has not been re-parsed with [`read()`](../basic_json_document/read.md) (or
|
|
||||||
[`parse()`](../basic_json_document/parse.md) into it) or shrunk with
|
|
||||||
[`shrink_to_fit()`](../basic_json_document/shrink_to_fit.md) since the view was taken, and
|
|
||||||
- if the document borrows its source text, that text is still alive.
|
|
||||||
|
|
||||||
Moving the document itself does not invalidate its views: the index is heap-allocated independently of the
|
|
||||||
`basic_json_document` object.
|
|
||||||
|
|
||||||
`basic_json_view` provides the read-only part of the `BasicJsonType` interface: the type-inspection functions, and
|
|
||||||
[`materialize()`](materialize.md) to build the `BasicJsonType` value of a subtree on demand. It does not (yet) provide
|
|
||||||
element access, iteration, `get<T>()`, JSON Pointer support, `dump()`, or comparison.
|
|
||||||
|
|
||||||
## Template parameters
|
|
||||||
|
|
||||||
`BasicJsonType`
|
|
||||||
: a specialization of [`basic_json`](../basic_json/index.md), matching the
|
|
||||||
[`basic_json_document`](../basic_json_document/index.md) the view was taken from.
|
|
||||||
|
|
||||||
## Specializations
|
|
||||||
|
|
||||||
- [**json_view**](../json_view.md) - views of a [`json_document`](../json_document.md)
|
|
||||||
- [**ordered_json_view**](../ordered_json_view.md) - views of an [`ordered_json_document`](../ordered_json_document.md)
|
|
||||||
|
|
||||||
## Member types
|
|
||||||
|
|
||||||
- **value_t** - the JSON type enumeration, see [`basic_json::value_t`](../basic_json/value_t.md)
|
|
||||||
- **string_t**, **number_integer_t**, **number_unsigned_t**, **number_float_t**, **json_pointer** - the corresponding
|
|
||||||
member types of `BasicJsonType`
|
|
||||||
- **size_type** - `#!cpp std::size_t`
|
|
||||||
- **string_view_t** - `#!cpp std::string_view` on C++17 and newer, a minimal internal substitute otherwise
|
|
||||||
|
|
||||||
## Member functions
|
|
||||||
|
|
||||||
- [(constructor)](basic_json_view.md)
|
|
||||||
|
|
||||||
### Object inspection
|
|
||||||
|
|
||||||
- [**type**](type.md) - return the type of the value
|
|
||||||
- [**is_null**](is_null.md) - return whether the value is null
|
|
||||||
- [**is_boolean**](is_boolean.md) - return whether the value is a boolean
|
|
||||||
- [**is_number**](is_number.md) - return whether the value is a number
|
|
||||||
- [**is_number_integer**](is_number_integer.md) - return whether the value is an integer number
|
|
||||||
- [**is_number_unsigned**](is_number_unsigned.md) - return whether the value is an unsigned integer number
|
|
||||||
- [**is_number_float**](is_number_float.md) - return whether the value is a floating-point number
|
|
||||||
- [**is_string**](is_string.md) - return whether the value is a string
|
|
||||||
- [**is_array**](is_array.md) - return whether the value is an array
|
|
||||||
- [**is_object**](is_object.md) - return whether the value is an object
|
|
||||||
- [**is_binary**](is_binary.md) - return whether the value is a binary array (always `#!cpp false`)
|
|
||||||
- [**is_primitive**](is_primitive.md) - return whether the type is primitive
|
|
||||||
- [**is_structured**](is_structured.md) - return whether the type is structured
|
|
||||||
- [**is_discarded**](is_discarded.md) - return whether the view is invalid
|
|
||||||
- [**operator bool**](operator_bool.md) - return whether the view refers to a value
|
|
||||||
|
|
||||||
### Capacity
|
|
||||||
|
|
||||||
- [**size**](size.md) - return the number of elements
|
|
||||||
- [**empty**](empty.md) - return whether the value has no elements
|
|
||||||
|
|
||||||
### Conversion
|
|
||||||
|
|
||||||
- [**materialize**](materialize.md) - build the `BasicJsonType` value of this subtree
|
|
||||||
|
|
||||||
### Source access
|
|
||||||
|
|
||||||
- [**source_offset**](source_offset.md) - byte offset of this value in the document's source text
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_array
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_array() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is an array.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is an array, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_structured](is_structured.md) - return whether the type is structured
|
|
||||||
- [size](size.md), [empty](empty.md) - the number of elements, and whether there are none
|
|
||||||
- [`BasicJsonType::is_array`](../basic_json/is_array.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_binary
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_binary() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function always returns `#!cpp false`: a JSON text has no binary values, so a view can never refer to one. The
|
|
||||||
function exists for interface parity with [`BasicJsonType::is_binary`](../basic_json/is_binary.md).
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp false`, always.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [type](type.md) - return the type of the value
|
|
||||||
- [`BasicJsonType::is_binary`](../basic_json/is_binary.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_boolean
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_boolean() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is a boolean.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is a boolean, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [type](type.md) - return the type of the value
|
|
||||||
- [`BasicJsonType::is_boolean`](../basic_json/is_boolean.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_discarded
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_discarded() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns whether this view is invalid, i.e. does not refer to a value. This is the case for a default-constructed
|
|
||||||
view (see [(constructor)](basic_json_view.md)), and for [`root()`](../basic_json_document/root.md) of a document
|
|
||||||
that is itself [discarded](../basic_json_document/is_discarded.md) -- in particular, the root of a failed
|
|
||||||
[`parse()`](../basic_json_document/parse.md) with `allow_exceptions` set to `#!cpp false`.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the view is discarded, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
`#!cpp v.is_discarded()` and `#!cpp !static_cast<bool>(v)` are equivalent; use whichever reads better at the call
|
|
||||||
site.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [operator bool](operator_bool.md) - return whether the view refers to a value
|
|
||||||
- [(constructor)](basic_json_view.md) - the default constructor creates a discarded view
|
|
||||||
- [is_discarded (basic_json_document)](../basic_json_document/is_discarded.md) - return whether the last parse failed
|
|
||||||
- [`BasicJsonType::is_discarded`](../basic_json/is_discarded.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_null
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_null() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is `#!json null`.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is `#!json null`, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [type](type.md) - return the type of the value
|
|
||||||
- [`BasicJsonType::is_null`](../basic_json/is_null.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_number
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_number() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is a number, i.e. an integer, unsigned integer, or floating-point value. It is defined as `#!cpp is_number_integer() || is_number_float()`.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is a number, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_number_integer](is_number_integer.md) - return whether the value is an integer or unsigned integer number
|
|
||||||
- [is_number_unsigned](is_number_unsigned.md) - return whether the value is an unsigned integer number
|
|
||||||
- [is_number_float](is_number_float.md) - return whether the value is a floating-point number
|
|
||||||
- [`BasicJsonType::is_number`](../basic_json/is_number.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_number_float
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_number_float() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is a floating-point number.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is `#!cpp value_t::number_float`, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
As for [`BasicJsonType::parse`](../basic_json/parse.md), an integer literal that does not fit into the 64-bit
|
|
||||||
integer type is classified as a floating-point number, so `is_number_float()` can be `#!cpp true` even for an
|
|
||||||
integer-looking token in the source text.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_number](is_number.md) - return whether the value is a number
|
|
||||||
- [`BasicJsonType::is_number_float`](../basic_json/is_number_float.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_number_integer
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_number_integer() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is an integer or unsigned integer number.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is `#!cpp value_t::number_integer` or `#!cpp value_t::number_unsigned`, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
As for [`BasicJsonType::is_number_integer`](../basic_json/is_number_integer.md), this includes unsigned integer
|
|
||||||
values; use [`is_number_unsigned`](is_number_unsigned.md) to test for those specifically.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_number](is_number.md) - return whether the value is a number
|
|
||||||
- [is_number_unsigned](is_number_unsigned.md) - return whether the value is an unsigned integer number
|
|
||||||
- [`BasicJsonType::is_number_integer`](../basic_json/is_number_integer.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_number_unsigned
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_number_unsigned() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is an unsigned integer number.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is `#!cpp value_t::number_unsigned`, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_number_integer](is_number_integer.md) - return whether the value is an integer or unsigned integer number
|
|
||||||
- [`BasicJsonType::is_number_unsigned`](../basic_json/is_number_unsigned.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_object
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_object() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is an object.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is an object, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_structured](is_structured.md) - return whether the type is structured
|
|
||||||
- [size](size.md), [empty](empty.md) - the number of elements, and whether there are none
|
|
||||||
- [`BasicJsonType::is_object`](../basic_json/is_object.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_primitive
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_primitive() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is primitive, i.e. `#!json null`, a boolean, a number, or a string. It is defined as `#!cpp is_null() || is_string() || is_boolean() || is_number()`.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is primitive, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_structured](is_structured.md) - return whether the type is structured (the complement of this function, for a
|
|
||||||
non-discarded view)
|
|
||||||
- [`BasicJsonType::is_primitive`](../basic_json/is_primitive.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_string
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_string() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is a string.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is a string, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [source_offset](source_offset.md) - byte offset of this value in the document's source text
|
|
||||||
- [`BasicJsonType::is_string`](../basic_json/is_string.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>is_structured
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
bool is_structured() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns `#!cpp true` if and only if the value is structured, i.e. an array or an object. It is defined as `#!cpp is_array() || is_object()`.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the type is structured, `#!cpp false` otherwise.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_primitive](is_primitive.md) - return whether the type is primitive
|
|
||||||
- [size](size.md), [empty](empty.md) - the number of elements, and whether there are none
|
|
||||||
- [`BasicJsonType::is_structured`](../basic_json/is_structured.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>materialize
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
BasicJsonType materialize() const;
|
|
||||||
```
|
|
||||||
|
|
||||||
Builds the `BasicJsonType` value of this subtree: the value [`BasicJsonType::parse()`](../basic_json/parse.md) would
|
|
||||||
have produced for the same source text, allocated for the first time by this call.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
The `BasicJsonType` value of this subtree, or a discarded `BasicJsonType` value (`#!cpp BasicJsonType(value_t::discarded)`)
|
|
||||||
if the view is [discarded](is_discarded.md).
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
Strong guarantee: if an exception is thrown, there are no changes to the view or the document it refers to (nothing
|
|
||||||
about either is mutated by this function).
|
|
||||||
|
|
||||||
## Exceptions
|
|
||||||
|
|
||||||
May throw `#!cpp std::bad_alloc` (via `BasicJsonType`'s allocator) if constructing the result fails.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Linear in the size of the subtree.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
`materialize()` replays the subtree through the same SAX builder [`BasicJsonType::parse()`](../basic_json/parse.md)
|
|
||||||
uses internally, so the result matches it exactly -- including, for an object, that a repeated key keeps only its
|
|
||||||
last value. The replay is iterative, so it is not limited by the call stack the way a naive recursive conversion
|
|
||||||
would be; the JSON nesting depth is limited only by available memory, as for `BasicJsonType::parse()` itself.
|
|
||||||
|
|
||||||
Unlike parsing with [`JSON_DIAGNOSTIC_POSITIONS`](../macros/json_diagnostic_positions.md) enabled, the values
|
|
||||||
produced by `materialize()` do not carry source positions: there is no lexer run during the replay to record them.
|
|
||||||
|
|
||||||
Calling `materialize()` on the same view repeatedly builds a new, independent `BasicJsonType` value each time; it
|
|
||||||
never caches the result.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below skips messages that are not useful -- a discarded value, or an empty array -- using only
|
|
||||||
[`is_array()`](is_array.md) and [`empty()`](empty.md), and calls `materialize()` only for the messages that are
|
|
||||||
actually used, so no `BasicJsonType` value (and none of its per-element allocations) is ever built for the
|
|
||||||
skipped ones.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__materialize.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__materialize.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [root](../basic_json_document/root.md) - the view of a document's root value
|
|
||||||
- [`BasicJsonType::parse`](../basic_json/parse.md) - build a `BasicJsonType` value directly from a JSON text
|
|
||||||
- [`JSON_DIAGNOSTIC_POSITIONS`](../macros/json_diagnostic_positions.md) - source positions on parsed values (not
|
|
||||||
produced by `materialize()`)
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>operator bool
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
explicit operator bool() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns whether this view refers to a value, i.e. the negation of [`is_discarded()`](is_discarded.md). Being
|
|
||||||
`#!cpp explicit`, this conversion is only considered in a boolean context (`#!cpp if (v)`, `#!cpp !v`, `#!cpp v &&
|
|
||||||
...`), not for implicit conversions to other types.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
`#!cpp true` if the view refers to a value, `#!cpp false` if it is [discarded](is_discarded.md).
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_discarded](is_discarded.md) - return whether the view is invalid
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>size
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
size_type size() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns the number of elements, as [`BasicJsonType::size()`](../basic_json/size.md) would for the same value.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
The return value depends on the type and is defined as follows:
|
|
||||||
|
|
||||||
| Value type | return value |
|
|
||||||
|----------------------|-----------------------------|
|
|
||||||
| null | `0` |
|
|
||||||
| discarded | `0` |
|
|
||||||
| boolean | `1` |
|
|
||||||
| string | `1` |
|
|
||||||
| number | `1` |
|
|
||||||
| object | number of key/value pairs |
|
|
||||||
| array | number of elements |
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant: for an object or array, the element count is stored in the index, not counted on demand.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
As for [`BasicJsonType::size()`](../basic_json/size.md), this does not return the length of a string value -- it is
|
|
||||||
`1` for a string, regardless of its length.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below uses `size()` and [`empty()`](empty.md) to decide whether a parsed message is worth acting on,
|
|
||||||
without materializing it into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__size_empty.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__size_empty.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [empty](empty.md) - return whether the value has no elements
|
|
||||||
- [`BasicJsonType::size`](../basic_json/size.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>source_offset
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
std::size_t source_offset() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns the byte offset of this value in the document's [`source()`](../basic_json_document/source.md) text, without
|
|
||||||
materializing anything.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
- For a string with no escapes, a number, `#!json true`/`#!json false`/`#!json null`, an array, or an object: the
|
|
||||||
byte offset of the first byte of the value's token (for a string: the first byte after the opening quote) in
|
|
||||||
[`source()`](../basic_json_document/source.md).
|
|
||||||
- `#!cpp static_cast<std::size_t>(-1)` for a [discarded](is_discarded.md) view, and for a string that contains
|
|
||||||
escapes -- such a string was decoded once into the document's own buffer, so there is no single byte range in
|
|
||||||
`source()` left to point at.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
This is a raw offset, not a length: the API does not (yet) expose how many bytes the token occupies in the source
|
|
||||||
text, so `source_offset()` alone is enough to report *where* a value came from (for an error message, for syntax
|
|
||||||
highlighting, ...) but not to slice its exact text back out of [`source()`](../basic_json_document/source.md) for a
|
|
||||||
string, whose token length is not the same as its decoded [`size()`](size.md).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__source_offset.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__source_offset.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [source](../basic_json_document/source.md) - the parsed text
|
|
||||||
- [is_string](is_string.md) - return whether the value is a string
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
# <small>nlohmann::basic_json_view::</small>type
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
value_t type() const noexcept;
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns the type of the value this view refers to, as a value from the [`value_t`](../basic_json/value_t.md)
|
|
||||||
enumeration -- the same enumeration [`BasicJsonType::type()`](../basic_json/type.md) uses.
|
|
||||||
|
|
||||||
## Return value
|
|
||||||
|
|
||||||
The type of the value; `#!cpp value_t::discarded` for a [discarded](is_discarded.md) view.
|
|
||||||
|
|
||||||
## Exception safety
|
|
||||||
|
|
||||||
No-throw guarantee: this function never throws exceptions.
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Constant.
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
Unlike [`BasicJsonType::type()`](../basic_json/type.md), this function can never return `#!cpp value_t::binary`: a
|
|
||||||
JSON text has no binary values, so `type()` only distinguishes the eight ordinary JSON value types (plus
|
|
||||||
`#!cpp discarded`).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below classifies several parsed documents by the type of their root value, without materializing any
|
|
||||||
of them into a `BasicJsonType` value.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/basic_json_view__type_predicates.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [is_null](is_null.md), [is_boolean](is_boolean.md), [is_number](is_number.md), [is_string](is_string.md),
|
|
||||||
[is_array](is_array.md), [is_object](is_object.md) - type-specific predicates built on `type()`
|
|
||||||
- [`BasicJsonType::type`](../basic_json/type.md) - the corresponding function of `basic_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
# <small>nlohmann::</small>json_document
|
|
||||||
|
|
||||||
<small>Defined in header `<nlohmann/json_view.hpp>`</small>
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
using json_document = basic_json_document<json>;
|
|
||||||
```
|
|
||||||
|
|
||||||
This type is a [`basic_json_document`](basic_json_document/index.md) of the default [`json`](json.md)
|
|
||||||
specialization.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below demonstrates how to use the type `nlohmann::json_document`.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/json_document.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/json_document.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [json_view](json_view.md) - a view of a value of a `json_document`
|
|
||||||
- [ordered_json_document](ordered_json_document.md) - the corresponding document for `ordered_json`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
Since version 3.13.0.
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# <small>nlohmann::</small>json_view
|
|
||||||
|
|
||||||
<small>Defined in header `<nlohmann/json_view.hpp>`</small>
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
using json_view = basic_json_view<json>;
|
|
||||||
```
|
|
||||||
|
|
||||||
This type is a [`basic_json_view`](basic_json_view/index.md) of a value of a [`json_document`](json_document.md).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below demonstrates how to use the type `nlohmann::json_view`.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/json_view.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/json_view.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [json_document](json_document.md) - the document type this view refers into
|
|
||||||
- [ordered_json_view](ordered_json_view.md) - the corresponding view for `ordered_json_document`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
Since version 3.13.0.
|
|
||||||
@@ -53,7 +53,6 @@ header. See also the [macro overview page](../../features/macros.md).
|
|||||||
|
|
||||||
- [**JSON_BRACE_INIT_COPY_SEMANTICS**](json_brace_init_copy_semantics.md) - opt in to copy/move semantics for single-element brace initialization
|
- [**JSON_BRACE_INIT_COPY_SEMANTICS**](json_brace_init_copy_semantics.md) - opt in to copy/move semantics for single-element brace initialization
|
||||||
- [**JSON_DISABLE_ENUM_SERIALIZATION**](json_disable_enum_serialization.md) - switch off default serialization/deserialization functions for enums
|
- [**JSON_DISABLE_ENUM_SERIALIZATION**](json_disable_enum_serialization.md) - switch off default serialization/deserialization functions for enums
|
||||||
- [**JSON_DISABLE_TUPLE_REFERENCE_CONVERSION**](json_disable_tuple_reference_conversion.md) - switch off conversion from a one-element tuple of a JSON reference
|
|
||||||
- [**JSON_USE_IMPLICIT_CONVERSIONS**](json_use_implicit_conversions.md) - control implicit conversions
|
- [**JSON_USE_IMPLICIT_CONVERSIONS**](json_use_implicit_conversions.md) - control implicit conversions
|
||||||
|
|
||||||
## Comparison behavior
|
## Comparison behavior
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
# JSON_DISABLE_TUPLE_REFERENCE_CONVERSION
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define JSON_DISABLE_TUPLE_REFERENCE_CONVERSION /* value */
|
|
||||||
```
|
|
||||||
|
|
||||||
When defined to `1`, a `basic_json` value can no longer be constructed from a one-element `std::tuple` whose element is
|
|
||||||
a reference to that `basic_json` type, such as `std::tuple<json&>`, `std::tuple<const json&>`, or `std::tuple<json&&>`.
|
|
||||||
These are the tuples created by `std::forward_as_tuple(j)`.
|
|
||||||
|
|
||||||
## Default definition
|
|
||||||
|
|
||||||
The default value is `0` (disabled — existing behavior is preserved).
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define JSON_DISABLE_TUPLE_REFERENCE_CONVERSION 0
|
|
||||||
```
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
!!! note "Background"
|
|
||||||
|
|
||||||
By default, `basic_json` can be constructed from any `std::tuple` whose elements can be converted to JSON; the result
|
|
||||||
is an array. This includes `std::tuple<json&>`, which becomes a one-element array.
|
|
||||||
|
|
||||||
`std::tuple` only converts another tuple element by element if its element type cannot be constructed from the whole
|
|
||||||
source tuple. Because `json` *can* be constructed from `std::tuple<json&>`, `std::tuple` instead converts the whole
|
|
||||||
tuple into a single `json` value. This has two surprising effects:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
json j = true;
|
|
||||||
|
|
||||||
// rejected by some standard libraries (e.g., libc++); with others, the
|
|
||||||
// reference binds to a temporary that is destroyed right away
|
|
||||||
std::tuple<const json&> t1(std::forward_as_tuple(j));
|
|
||||||
|
|
||||||
// compiles, but std::get<0>(t2) is [true], not true
|
|
||||||
std::tuple<json> t2(std::forward_as_tuple(j));
|
|
||||||
```
|
|
||||||
|
|
||||||
Enabling this macro removes the conversion, so both tuples are converted element by element: `std::get<0>(t1)`
|
|
||||||
refers to `j`, and `std::get<0>(t2)` is a copy of `j` (see [#2226](https://github.com/nlohmann/json/issues/2226)).
|
|
||||||
|
|
||||||
!!! warning "Opt-in only"
|
|
||||||
|
|
||||||
This macro must be defined **before** including `<nlohmann/json.hpp>`. Defining it after the include has no effect.
|
|
||||||
|
|
||||||
!!! note "Affected conversions"
|
|
||||||
|
|
||||||
Only one-element tuples holding a reference to the **same** `basic_json` type are affected. Constructing a JSON value
|
|
||||||
from them no longer compiles:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
json j = true;
|
|
||||||
json a = std::forward_as_tuple(j); // error with the macro enabled
|
|
||||||
json b = json::array({j}); // use this instead: [true]
|
|
||||||
```
|
|
||||||
|
|
||||||
Tuples holding a JSON value (`std::make_tuple(j)`), tuples with more than one element, and tuples holding references
|
|
||||||
to other types (including other `basic_json` specializations) are converted to arrays as before.
|
|
||||||
|
|
||||||
!!! hint "CMake option"
|
|
||||||
|
|
||||||
This behavior can also be controlled with the CMake option
|
|
||||||
[`JSON_DisableTupleReferenceConversion`](../../integration/cmake.md#json_disabletuplereferenceconversion)
|
|
||||||
(`OFF` by default) which defines `JSON_DISABLE_TUPLE_REFERENCE_CONVERSION` accordingly.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example "Default behavior (macro not defined)"
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
json j = true;
|
|
||||||
|
|
||||||
std::tuple<json> t(std::forward_as_tuple(j));
|
|
||||||
// std::get<0>(t) is [true] -- the whole tuple was converted
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
??? example "Conversion disabled (macro defined to 1)"
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define JSON_DISABLE_TUPLE_REFERENCE_CONVERSION 1
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
json j = true;
|
|
||||||
|
|
||||||
std::tuple<json> t(std::forward_as_tuple(j));
|
|
||||||
// std::get<0>(t) is true -- a copy of j
|
|
||||||
|
|
||||||
std::tuple<const json&> r(std::forward_as_tuple(j));
|
|
||||||
// std::get<0>(r) refers to j
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [**basic_json(CompatibleType&&)**](../basic_json/basic_json.md) - the affected constructor
|
|
||||||
- [:simple-cmake: JSON_DisableTupleReferenceConversion](../../integration/cmake.md#json_disabletuplereferenceconversion) -
|
|
||||||
CMake option to control the macro
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
# <small>nlohmann::</small>ordered_json_document
|
|
||||||
|
|
||||||
<small>Defined in header `<nlohmann/json_view.hpp>`</small>
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
using ordered_json_document = basic_json_document<ordered_json>;
|
|
||||||
```
|
|
||||||
|
|
||||||
This type is a [`basic_json_document`](basic_json_document/index.md) of the [`ordered_json`](ordered_json.md)
|
|
||||||
specialization: [`materialize()`](basic_json_view/materialize.md) on one of its views preserves the insertion order
|
|
||||||
of object keys, instead of sorting them like [`json_document`](json_document.md) does.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below demonstrates how `ordered_json_document` preserves the insertion order of object keys when
|
|
||||||
materializing.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/ordered_json_document.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/ordered_json_document.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [ordered_json_view](ordered_json_view.md) - a view of a value of an `ordered_json_document`
|
|
||||||
- [json_document](json_document.md) - the corresponding document for the default `json` specialization
|
|
||||||
- [Object Order](../features/object_order.md)
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
Since version 3.13.0.
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
# <small>nlohmann::</small>ordered_json_view
|
|
||||||
|
|
||||||
<small>Defined in header `<nlohmann/json_view.hpp>`</small>
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
using ordered_json_view = basic_json_view<ordered_json>;
|
|
||||||
```
|
|
||||||
|
|
||||||
This type is a [`basic_json_view`](basic_json_view/index.md) of a value of an
|
|
||||||
[`ordered_json_document`](ordered_json_document.md).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example below demonstrates how to use the type `nlohmann::ordered_json_view`.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/ordered_json_view.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/ordered_json_view.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [ordered_json_document](ordered_json_document.md) - the document type this view refers into
|
|
||||||
- [json_view](json_view.md) - the corresponding view for `json_document`
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
Since version 3.13.0.
|
|
||||||
@@ -90,7 +90,7 @@ Note: Some modern features (like C++20 ranges or filesystem support) may be disa
|
|||||||
| GNU 14.2.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 14.2.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 15.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 15.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 16.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 16.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 16.1.0 | arm64 | Ubuntu 24.04 | GitHub |
|
| GNU 16.1.0 | arm64 | Linux 6.1.100 | Cirrus CI |
|
||||||
| icpc (ICC) 2021.10.0 20230609 | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
| icpc (ICC) 2021.10.0 20230609 | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
||||||
| icpx (Intel oneAPI DPC++/C++) 2025.3.2 | x86_64 | Ubuntu 24.04 LTS | GitHub |
|
| icpx (Intel oneAPI DPC++/C++) 2025.3.2 | x86_64 | Ubuntu 24.04 LTS | GitHub |
|
||||||
| nvc++ (NVIDIA HPC SDK) 25.5-0 | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
| nvc++ (NVIDIA HPC SDK) 25.5-0 | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
||||||
@@ -132,8 +132,7 @@ Note: Some modern features (like C++20 ranges or filesystem support) may be disa
|
|||||||
[libstdc++](https://gcc.gnu.org/onlinedocs/libstdc++/) to detect subtle differences or incompatibilities.
|
[libstdc++](https://gcc.gnu.org/onlinedocs/libstdc++/) to detect subtle differences or incompatibilities.
|
||||||
- [x] The code checked with [Include What You Use (IWYU)](https://include-what-you-use.org) that all required standard
|
- [x] The code checked with [Include What You Use (IWYU)](https://include-what-you-use.org) that all required standard
|
||||||
headers are included.
|
headers are included.
|
||||||
- [x] On Windows, the library is compiled with `<Windows.h>` being included to detect and avoid common bugs (see
|
- [x] On Windows, the library is compiled with `<Windows.h>` being included to detect and avoid common bugs.
|
||||||
[`unit-windows_h.cpp`](https://github.com/nlohmann/json/blob/develop/tests/src/unit-windows_h.cpp)).
|
|
||||||
- [x] The library is compiled with exceptions disabled to support alternative means of error handling.
|
- [x] The library is compiled with exceptions disabled to support alternative means of error handling.
|
||||||
|
|
||||||
## Stable public API
|
## Stable public API
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <nlohmann/json_view.hpp>
|
|
||||||
|
|
||||||
using json_document = nlohmann::json_document;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
std::cout << std::boolalpha;
|
|
||||||
|
|
||||||
// accept() behaves exactly like basic_json::accept(): the same inputs are
|
|
||||||
// accepted or rejected, with the same ignore_comments/ignore_trailing_commas
|
|
||||||
// options
|
|
||||||
std::cout << json_document::accept(R"({"a": 1})") << '\n';
|
|
||||||
std::cout << json_document::accept(R"({"a": 1,})") << '\n'; // trailing comma: rejected by default
|
|
||||||
std::cout << json_document::accept(R"({"a": 1,})", false, true) << '\n'; // ignore_trailing_commas
|
|
||||||
|
|
||||||
std::cout << (json_document::accept(R"({"a": 1})") == nlohmann::json::accept(R"({"a": 1})")) << '\n';
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
true
|
|
||||||
false
|
|
||||||
true
|
|
||||||
true
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <utility>
|
|
||||||
#include <nlohmann/json_view.hpp>
|
|
||||||
|
|
||||||
using json_document = nlohmann::json_document;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
std::cout << std::boolalpha;
|
|
||||||
|
|
||||||
// the default constructor creates an empty (discarded) document
|
|
||||||
json_document empty;
|
|
||||||
std::cout << empty.is_discarded() << '\n';
|
|
||||||
|
|
||||||
// json_document is move-only: parse() itself returns by value (moved out),
|
|
||||||
// and a document can be moved again, e.g. into a container
|
|
||||||
json_document doc = json_document::parse(R"({"a": 1})");
|
|
||||||
json_document moved = std::move(doc);
|
|
||||||
std::cout << moved.root().is_object() << '\n';
|
|
||||||
|
|
||||||
// copying is disabled at compile time:
|
|
||||||
// json_document another = moved; // does not compile
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
true
|
|
||||||
true
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <nlohmann/json_view.hpp>
|
|
||||||
|
|
||||||
using json_document = nlohmann::json_document;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
std::cout << std::boolalpha;
|
|
||||||
|
|
||||||
// with allow_exceptions == false, a parse error produces a discarded
|
|
||||||
// document instead of throwing -- exactly like basic_json::parse()
|
|
||||||
json_document doc = json_document::parse(R"({"a": )", /* allow_exceptions */ false);
|
|
||||||
std::cout << doc.is_discarded() << '\n';
|
|
||||||
std::cout << doc.root().is_discarded() << '\n';
|
|
||||||
|
|
||||||
// a successful parse is never discarded
|
|
||||||
json_document ok = json_document::parse(R"({"a": 1})", false);
|
|
||||||
std::cout << ok.is_discarded() << '\n';
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
true
|
|
||||||
true
|
|
||||||
false
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <nlohmann/json_view.hpp>
|
|
||||||
|
|
||||||
using json_document = nlohmann::json_document;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
std::cout << std::boolalpha;
|
|
||||||
|
|
||||||
// long enough that copying it needs a real (heap) allocation, so the
|
|
||||||
// comparison below does not depend on the standard library's small
|
|
||||||
// string optimization threshold
|
|
||||||
const std::string text = std::string(200, ' ') + "[1, 2, 3, 4, 5]";
|
|
||||||
|
|
||||||
// memory_usage() is not portable across platforms/allocators/compilers, so
|
|
||||||
// compare it relatively instead of printing the raw byte count
|
|
||||||
json_document borrowed = json_document::parse(text);
|
|
||||||
json_document owned = json_document::parse_copy(text);
|
|
||||||
|
|
||||||
// the owned document additionally stores its own copy of the source text
|
|
||||||
std::cout << (owned.memory_usage() > borrowed.memory_usage()) << '\n';
|
|
||||||
|
|
||||||
// a document with more values needs a larger index
|
|
||||||
json_document small = json_document::parse(std::string("[1]"));
|
|
||||||
json_document large = json_document::parse(std::string("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"));
|
|
||||||
std::cout << (large.memory_usage() > small.memory_usage()) << '\n';
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
true
|
|
||||||
true
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <nlohmann/json_view.hpp>
|
|
||||||
|
|
||||||
using json_document = nlohmann::json_document;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// node_count() is the size of the flat index: one 16-byte node per value,
|
|
||||||
// plus one per object key (values and keys are all the index stores)
|
|
||||||
json_document scalar = json_document::parse("42");
|
|
||||||
std::cout << scalar.node_count() << '\n';
|
|
||||||
|
|
||||||
json_document doc = json_document::parse(R"({"a": 1, "b": [1, 2]})");
|
|
||||||
std::cout << doc.node_count() << '\n';
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user