summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Mollier <emollier@debian.org>2022-07-03 14:23:31 +0200
committerÉtienne Mollier <emollier@debian.org>2022-07-03 14:23:31 +0200
commit2237ffc27902716bdcb3a608044043aa51dc7728 (patch)
treebaa360e08891b38e5ec5e6e0fd71459a585733eb
Import libvbz-hdf-plugin_1.0.2.orig.tar.gz
[dgit import orig libvbz-hdf-plugin_1.0.2.orig.tar.gz]
-rw-r--r--.gitmodules3
-rw-r--r--CMakeLists.txt254
-rw-r--r--LICENCE.txt374
-rw-r--r--README.md77
-rwxr-xr-xcmake/FindASan.cmake59
-rw-r--r--cmake/FindFuzzer.cmake28
-rw-r--r--cmake/FindGoogleBenchmark.cmake75
-rwxr-xr-xcmake/FindMSan.cmake57
-rwxr-xr-xcmake/FindSanitizers.cmake95
-rwxr-xr-xcmake/FindTSan.cmake65
-rwxr-xr-xcmake/FindUBSan.cmake46
-rw-r--r--cmake/Findzstd.cmake75
-rw-r--r--cmake/ONTFindModuleHelpers.cmake312
-rw-r--r--cmake/SignFile.cmake61
-rw-r--r--cmake/SigningUtils.cmake25
-rwxr-xr-xcmake/asan-wrapper55
-rw-r--r--cmake/conan.cmake574
-rwxr-xr-xcmake/sanitize-helpers.cmake177
-rw-r--r--images/ONT_logo_590x106.pngbin0 -> 35610 bytes
-rw-r--r--images/vbz_compression_ratio.pngbin0 -> 6106 bytes
-rw-r--r--images/vbz_x86_compression.pngbin0 -> 7102 bytes
-rw-r--r--images/vbz_x86_decompression.pngbin0 -> 7156 bytes
-rw-r--r--packaging/hdf_plugin_packaging.cmake107
-rw-r--r--packaging/postinstall.sh.in10
-rw-r--r--packaging/postrm.sh.in4
-rw-r--r--packaging/readme.txt6
-rw-r--r--packaging/wix_extra.wxs.in11
-rw-r--r--packaging/wix_nanopore_background.bmpbin0 -> 615402 bytes
-rw-r--r--packaging/wix_nanopore_banner.bmpbin0 -> 114514 bytes
-rw-r--r--packaging/wix_nanopore_icon.icobin0 -> 299613 bytes
-rw-r--r--packaging/wix_patch.wxs.xml19
-rw-r--r--python/CMakeLists.txt1
-rw-r--r--python/benchmark/benchmark.py99
-rwxr-xr-xpython/fast5compress/fast5vbz.py74
-rw-r--r--python/pyvbz/CMakeLists.txt56
-rw-r--r--python/pyvbz/README.md27
-rw-r--r--python/pyvbz/build_pyvbz.cmake20
-rw-r--r--python/pyvbz/requirements.txt2
-rw-r--r--python/pyvbz/setup.py26
-rwxr-xr-xpython/pyvbz/tests/unit123
-rw-r--r--python/pyvbz/vbz/__init__.py79
-rw-r--r--python/pyvbz/vbz/build.py71
-rw-r--r--python/test/requirements_1.10.txt4
-rw-r--r--python/test/requirements_1.12.txt2
-rw-r--r--python/test/requirements_1.8.txt1
-rw-r--r--python/test/test_repack.py40
-rw-r--r--python/test/test_vbz_filter.py62
-rw-r--r--test_data/multi_fast5_vbz.fast5bin0 -> 1773098 bytes
-rw-r--r--test_data/multi_fast5_vbz_v1.fast5bin0 -> 1354506 bytes
-rw-r--r--test_data/multi_fast5_zip.fast5bin0 -> 2404555 bytes
-rw-r--r--third_party/catch2/catch.hpp17966
-rwxr-xr-xthird_party/catch2/fakeit.hpp9375
-rw-r--r--third_party/gsl-disable-gsl-suppress.patch11
-rw-r--r--third_party/gsl.h27
-rw-r--r--third_party/gsl/gsl29
-rw-r--r--third_party/gsl/gsl-lite-vc6.hpp697
-rw-r--r--third_party/gsl/gsl-lite.h27
-rw-r--r--third_party/gsl/gsl-lite.hpp5197
-rw-r--r--third_party/hdf5/hdf5_plugin_types.h82
-rw-r--r--vbz/CMakeLists.txt55
-rw-r--r--vbz/fuzzing/CMakeLists.txt15
-rw-r--r--vbz/fuzzing/dictionary.txt6
-rw-r--r--vbz/fuzzing/fuzz_corpus/11373950051f7b0300995eccc2291ad06127cd8fbin0 -> 273 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/1bc554b64fa5315576f70da39b286cc131537ae2bin0 -> 703 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/24f78257221ba37aecd033a81647bc69946b5735bin0 -> 1362 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/251aa7eb7d9fe0bd76730c2a2853bd3d265604eabin0 -> 1185 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/29a99aa69faab4036a099ff9d7926324ecaa614abin0 -> 730 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/41b10ad89a5538e3200320ef927cf2005af86143bin0 -> 586 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/5ba93c9db0cff93f52b521d7420e43f6eda2784fbin0 -> 1 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/5fb98815de681bcc796f65f90e44c2836e24449fbin0 -> 1435 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/61cd6ffc64ca7a0b6b1a726f394ef2c51000862abin0 -> 690 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/657c3ab45863ec8d403c7c6959bf142acdbf70941
-rw-r--r--vbz/fuzzing/fuzz_corpus/7722745105e9e02e8f1aaf17f7b3aac5c56cd805bin0 -> 6 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/80f5e802a77d76c6decedf63ae4a3dbaeb2ec8c3bin0 -> 466 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/846.binbin0 -> 2675 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/8ed79960613916571ccfb082453d93037e7906b7bin0 -> 15 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/9069ca78e7450a285173431b3e52c5c25299e473bin0 -> 4 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/92d337489cc9f8e42313a745cbe190aa6c634693bin0 -> 402 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/9322befa32a921e42b72ce55c13451c04a356063bin0 -> 498 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/9b20c06ca1ad1d294400baa692fc97baeb4c9fcabin0 -> 1557 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/9c119958afbf93c6a952d2df3302a088f38244ebbin0 -> 458 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/a02a121e5b3350a7f8e9d1d7dbd367fab677c2aabin0 -> 3 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/c830b27f7a230e60f597313c46fed441e64c0373bin0 -> 55 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/cadf1d00e18837d36406165040faaac6b3ca13c4bin0 -> 9 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/cc5c77470e5a742320cce568cf9425c51815be8ebin0 -> 75 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/d26f4347af1e7892439ae8f1d0e5751706665d9bbin0 -> 41 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/dd426047b595164d7b461446228c6c0818e28297bin0 -> 17 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/e116607af449e9e9227cd27d65ce77c7639f718cbin0 -> 674 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/e70047cba798d17689d2ebc7e32ca793523c205fbin0 -> 503 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/ed6e9aa0874d548f1935b94f27402b553fabc404bin0 -> 93 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/ee987cb071dba7583bedc1fc3b3a75af9901a1c0bin0 -> 5 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/f1a284806d5914ca836ae6f381d66e7331e01aa2bin0 -> 25 bytes
-rw-r--r--vbz/fuzzing/fuzz_corpus/ff8cf611318fced9fa50c27e28e18533f4b5544ebin0 -> 165 bytes
-rw-r--r--vbz/fuzzing/vbz_fuzz.cpp108
-rw-r--r--vbz/perf/CMakeLists.txt20
-rw-r--r--vbz/perf/test_data_generator.h75
-rw-r--r--vbz/perf/vbz_perf.cpp175
-rw-r--r--vbz/test/CMakeLists.txt24
-rw-r--r--vbz/test/main.cpp2
-rw-r--r--vbz/test/streamvbyte_test.cpp239
-rw-r--r--vbz/test/test_data.h6
-rw-r--r--vbz/test/test_utils.h45
-rw-r--r--vbz/test/vbz_test.cpp350
-rw-r--r--vbz/v0/vbz_streamvbyte.cpp108
-rw-r--r--vbz/v0/vbz_streamvbyte.h54
-rw-r--r--vbz/v0/vbz_streamvbyte_impl.h94
-rw-r--r--vbz/v0/vbz_streamvbyte_impl_sse3.h659
-rw-r--r--vbz/v1/vbz_streamvbyte.cpp112
-rw-r--r--vbz/v1/vbz_streamvbyte.h54
-rw-r--r--vbz/v1/vbz_streamvbyte_impl.h258
-rw-r--r--vbz/vbz.cpp343
-rw-r--r--vbz/vbz.h138
-rw-r--r--vbz_plugin/CMakeLists.txt105
-rw-r--r--vbz_plugin/hdf5_dynamic.h145
-rw-r--r--vbz_plugin/hdf_test_utils/CMakeLists.txt17
-rw-r--r--vbz_plugin/hdf_test_utils/hdf_id_helper.cpp83
-rw-r--r--vbz_plugin/hdf_test_utils/hdf_id_helper.h133
-rw-r--r--vbz_plugin/perf/CMakeLists.txt22
-rw-r--r--vbz_plugin/perf/vbz_hdf_perf.cpp175
-rw-r--r--vbz_plugin/test/CMakeLists.txt20
-rw-r--r--vbz_plugin/test/main.cpp2
-rw-r--r--vbz_plugin/test/test_utils.h108
-rw-r--r--vbz_plugin/test/vbz_hdf_plugin_test.cpp137
-rw-r--r--vbz_plugin/vbz_plugin.cpp261
-rw-r--r--vbz_plugin/vbz_plugin.h10
-rw-r--r--vbz_plugin/vbz_plugin_user_utils.h62
126 files changed, 40888 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..3db2bef
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "third_party/streamvbyte"]
+ path = third_party/streamvbyte
+ url = https://github.com/lemire/streamvbyte.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..b9421f8
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,254 @@
+cmake_minimum_required(VERSION 3.11.0)
+
+execute_process(
+ COMMAND git describe --tags
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ OUTPUT_VARIABLE GIT_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+string(REGEX MATCH "v?([0-9.]+)-?.*" _dummy "${GIT_VERSION}")
+set(GIT_VERSION "${CMAKE_MATCH_1}")
+
+message(STATUS "Building version ${GIT_VERSION}")
+project(hdf_plugins
+ VERSION ${GIT_VERSION}
+ LANGUAGES CXX C
+)
+
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+set(CMAKE_CXX_STANDARD 14)
+
+include(ExternalProject)
+include(GenerateExportHeader)
+# If we're including hdf_plugins as a subdir then we might not be able
+# to override BUILD_TESTING from CTest's default ON value.
+if (NOT DEFINED BUILD_TESTING OR BUILD_TESTING)
+ include(CTest)
+endif()
+
+if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
+ message(STATUS "No CMAKE_BUILD_TYPE set - defaulting to Debug")
+ # Default to Debug build
+ get_property(_bt_docstring
+ CACHE CMAKE_BUILD_TYPE
+ PROPERTY HELPSTRING)
+ set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "${_bt_docstring}" FORCE)
+endif()
+
+set(HDF_PLUGIN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
+
+if (NOT DEFINED VBZ_BUILD_ARCHIVE)
+ option(VBZ_BUILD_ARCHIVE "Build vbz release as an single archive" OFF)
+endif()
+
+if (NOT DEFINED ENABLE_PYTHON)
+ option(ENABLE_PYTHON "Build python wheel" ON)
+endif()
+
+if (NOT DEFINED ENABLE_PACKAGING)
+ option(ENABLE_PACKAGING "Enable packaging support" ON)
+endif()
+
+if (NOT DEFINED ENABLE_PERF_TESTING)
+ option(ENABLE_PERF_TESTING "Enable performance tests" ON)
+endif()
+
+if (NOT DEFINED ENABLE_CONAN)
+ option(ENABLE_CONAN "Enable conan for dependency installation" ON)
+endif()
+
+if (NOT DEFINED STANDARD_LIB_INSTALL)
+ set(STD_LIB_INSTALL_DEFAULT OFF)
+ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_DIR)
+ set(STD_LIB_INSTALL_DEFAULT ON)
+ endif()
+ option(STANDARD_LIB_INSTALL
+ "Install library to standard lib / bin paths"
+ ${STD_LIB_INSTALL_DEFAULT}
+ )
+endif()
+
+if (NOT VBZ_BUILD_ARCHIVE)
+ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+endif()
+
+option(BUILD_SHARED_LIBS "Build shared library for VBZ plugin" ON)
+
+if (ENABLE_CONAN)
+ #
+ # Dependencies: Conan
+ #
+
+ if (CONAN_EXPORTED)
+ # we're being run by conan
+ include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
+ else()
+ include(conan)
+
+ set(_requirements
+ "zstd/1.4.8@nanopore/stable")
+ set(_generators
+ cmake
+ json)
+ set(_imports
+ "bin, *.dll -> ../bin"
+ "lib, *.dylib* -> ../bin")
+ set(_extra_args)
+
+ if (ENABLE_PERF_TESTING)
+ list(APPEND _requirements
+ "google-benchmark/1.5@nanopore/stable"
+ )
+ endif()
+ if (CMAKE_BUILD_TYPE)
+ set(_build_type_DEBUG Debug)
+ set(_build_type_RELEASE Release)
+ set(_build_type_RELWITHDEBINFO Release)
+ set(_build_type_MINSIZEREL Release)
+ string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type)
+ if(DEFINED _build_type_${_build_type})
+ list(APPEND _extra_args BUILD_TYPE "${_build_type_${_build_type}}")
+ endif()
+ endif()
+ if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ list(APPEND CONAN_EXTRA_SETTINGS "compiler.cppstd=${CMAKE_CXX_STANDARD}")
+ endif()
+ if (CONAN_EXTRA_SETTINGS)
+ list(APPEND _extra_args
+ SETTINGS
+ ${CONAN_EXTRA_SETTINGS}
+ BUILD missing
+ )
+ endif()
+
+ conan_cmake_run(
+ GENERATORS ${_generators}
+ REQUIRES ${_requirements}
+ IMPORTS ${_imports}
+ ${_extra_args})
+ endif()
+ conan_check_compiler()
+ conan_define_targets()
+ conan_set_find_paths()
+endif()
+
+if (ENABLE_PACKAGING)
+ include(packaging/hdf_plugin_packaging.cmake)
+endif()
+
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party")
+
+find_package(HDF5 1.8.16)
+find_package(zstd 1.3.1 REQUIRED)
+find_package(Sanitizers)
+
+get_filename_component(STREAMVBYTE_SOURCE_DIR
+ third_party/streamvbyte
+ ABSOLUTE
+)
+set(STREAMVBYTE_INSTALL_DIR "${CMAKE_BINARY_DIR}/streamvbyte_lib/")
+set(STREAMVBYTE_PREFIX ${CMAKE_BINARY_DIR}/streamvbyte)
+set(STREAMVBYTE_STATIC_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}streamvbyte_static${CMAKE_STATIC_LIBRARY_SUFFIX})
+set(STREAMVBYTE_STATIC_LIB_SUBDIR ".")
+get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if (is_multi_config)
+ set(STREAMVBYTE_STATIC_LIB_SUBDIR "$<CONFIG>")
+endif()
+ExternalProject_Add(
+ streamvbyte
+ SOURCE_DIR ${STREAMVBYTE_SOURCE_DIR}
+ UPDATE_DISCONNECTED TRUE
+ PREFIX ${STREAMVBYTE_PREFIX}
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${STREAMVBYTE_INSTALL_DIR} -DSTREAMVBYTE_DISABLE_NATIVE=ON -DSTD_FLAGS="-std=c99"
+ # We need to tell CMake about libraries we will link to, otherwise some generators (eg: Ninja)
+ # complain about how knowing how to build libstreamvbyte_static.a, for example.
+ # Ideally, we'd set a hypothetical INSTALL_BYPRODUCTS, and link to the installed file, but that
+ # doesn't seem to be an option.
+ BUILD_BYPRODUCTS "<BINARY_DIR>/${STREAMVBYTE_STATIC_LIB_NAME}"
+)
+ExternalProject_Get_Property(streamvbyte BINARY_DIR)
+set(STREAMVBYTE_STATIC_LIB "${BINARY_DIR}/${STREAMVBYTE_STATIC_LIB_SUBDIR}/${STREAMVBYTE_STATIC_LIB_NAME}")
+
+
+########################################################################
+#
+# Warnings
+#
+########################################################################
+
+if (MSVC)
+ add_compile_options(
+ # Level 3 warnings, as errors
+ /W3 /WX
+
+ ##
+ ## Disable warnings:
+ ##
+
+ # C4251: A base class or structure must be declared with the __declspec(dllexport) keyword
+ # for a function in a derived class to be exported.
+ #
+ # Happens when using STL types as members of a class tagged with WHATEVER_EXPORT. Since we
+ # don't care about our DLLs maintaining compatibility with other versions of the CRT
+ # (Microsoft's C Runtime Library), this is just noise.
+ /wd4251
+
+ # C4275: An exported class was derived from a class that was not exported.
+ #
+ # Very similar to C4251, but for inheritance rather than members. Again, just noise for us.
+ /wd4275
+
+ # C4373: '%$S': virtual function overrides '%$pS', previous versions of the compiler did not
+ # override when parameters only differed by const/volatile qualifiers
+ #
+ # The current behaviour (virtuals are overridden when their arguments differ only in
+ # constness) is what you'd expect - the warning only exists because VS 2008 and earlier had
+ # *different* behaviour. Since we never used VS 2008, this warning isn't useful to us.
+ /wd4373
+
+ ##
+ ## Enable additional warnings:
+ ##
+
+ # C5038: data member 'member1' will be initialized after data member 'member2'
+ #
+ # Enable warning about incorrect order of initialisation in classes.
+ # Matches clang warnings which are enabled on the build server.
+ /w35038
+ )
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
+ # MSVC's standard library warns about a lot of "insecure" code by default (eg: unchecked
+ # iterators). However, the recommended replacements are not cross-platform, so aren't really
+ # an option for us.
+ _SCL_SECURE_NO_WARNINGS
+ )
+elseif (CMAKE_COMPILER_IS_GNUCXX)
+ add_compile_options(
+ # "All" warnings as errors
+ -Wall -Wextra -Werror
+
+ # Unused parameters are too common (and unimportant) to warn about
+ -Wno-unused-parameter
+ # Missing field init warning is too general to be useful in C++ code
+ -Wno-missing-field-initializers
+ # boost::optional triggers this on release builds
+ -Wno-maybe-uninitialized
+ )
+elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # AppleClang and Clang
+ add_compile_options(
+ # "All" warnings as errors
+ -Wall -Werror
+ )
+endif()
+
+include(SigningUtils)
+
+if (ENABLE_PYTHON)
+ add_subdirectory(python)
+endif()
+add_subdirectory(vbz)
+add_subdirectory(vbz_plugin)
diff --git a/LICENCE.txt b/LICENCE.txt
new file mode 100644
index 0000000..2f8ed18
--- /dev/null
+++ b/LICENCE.txt
@@ -0,0 +1,374 @@
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+ means each individual or legal entity that creates, contributes to
+ the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+ means the combination of the Contributions of others (if any) used
+ by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+ means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+ means Source Code Form to which the initial Contributor has attached
+ the notice in Exhibit A, the Executable Form of such Source Code
+ Form, and Modifications of such Source Code Form, in each case
+ including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+ means
+
+ (a) that the initial Contributor has attached the notice described
+ in Exhibit B to the Covered Software; or
+
+ (b) that the Covered Software was made available under the terms of
+ version 1.1 or earlier of the License, but not also under the
+ terms of a Secondary License.
+
+1.6. "Executable Form"
+ means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+ means a work that combines Covered Software with other material, in
+ a separate file or files, that is not Covered Software.
+
+1.8. "License"
+ means this document.
+
+1.9. "Licensable"
+ means having the right to grant, to the maximum extent possible,
+ whether at the time of the initial grant or subsequently, any and
+ all of the rights conveyed by this License.
+
+1.10. "Modifications"
+ means any of the following:
+
+ (a) any file in Source Code Form that results from an addition to,
+ deletion from, or modification of the contents of Covered
+ Software; or
+
+ (b) any new file in Source Code Form that contains any Covered
+ Software.
+
+1.11. "Patent Claims" of a Contributor
+ means any patent claim(s), including without limitation, method,
+ process, and apparatus claims, in any patent Licensable by such
+ Contributor that would be infringed, but for the grant of the
+ License, by the making, using, selling, offering for sale, having
+ made, import, or transfer of either its Contributions or its
+ Contributor Version.
+
+1.12. "Secondary License"
+ means either the GNU General Public License, Version 2.0, the GNU
+ Lesser General Public License, Version 2.1, the GNU Affero General
+ Public License, Version 3.0, or any later versions of those
+ licenses.
+
+1.13. "Source Code Form"
+ means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+ means an individual or a legal entity exercising rights under this
+ License. For legal entities, "You" includes any entity that
+ controls, is controlled by, or is under common control with You. For
+ purposes of this definition, "control" means (a) the power, direct
+ or indirect, to cause the direction or management of such entity,
+ whether by contract or otherwise, or (b) ownership of more than
+ fifty percent (50%) of the outstanding shares or beneficial
+ ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+ Licensable by such Contributor to use, reproduce, make available,
+ modify, display, perform, distribute, and otherwise exploit its
+ Contributions, either on an unmodified basis, with Modifications, or
+ as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+ for sale, have made, import, and otherwise transfer either its
+ Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+ or
+
+(b) for infringements caused by: (i) Your and any other third party's
+ modifications of Covered Software, or (ii) the combination of its
+ Contributions with other software (except as part of its Contributor
+ Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+ its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+ Form, as described in Section 3.1, and You must inform recipients of
+ the Executable Form how they can obtain a copy of such Source Code
+ Form by reasonable means in a timely manner, at a charge no more
+ than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+ License, or sublicense it under different terms, provided that the
+ license for the Executable Form does not attempt to limit or alter
+ the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+* *
+* 6. Disclaimer of Warranty *
+* ------------------------- *
+* *
+* Covered Software is provided under this License on an "as is" *
+* basis, without warranty of any kind, either expressed, implied, or *
+* statutory, including, without limitation, warranties that the *
+* Covered Software is free of defects, merchantable, fit for a *
+* particular purpose or non-infringing. The entire risk as to the *
+* quality and performance of the Covered Software is with You. *
+* Should any Covered Software prove defective in any respect, You *
+* (not any Contributor) assume the cost of any necessary servicing, *
+* repair, or correction. This disclaimer of warranty constitutes an *
+* essential part of this License. No use of any Covered Software is *
+* authorized under this License except under this disclaimer. *
+* *
+************************************************************************
+
+************************************************************************
+* *
+* 7. Limitation of Liability *
+* -------------------------- *
+* *
+* Under no circumstances and under no legal theory, whether tort *
+* (including negligence), contract, or otherwise, shall any *
+* Contributor, or anyone who distributes Covered Software as *
+* permitted above, be liable to You for any direct, indirect, *
+* special, incidental, or consequential damages of any character *
+* including, without limitation, damages for lost profits, loss of *
+* goodwill, work stoppage, computer failure or malfunction, or any *
+* and all other commercial damages or losses, even if such party *
+* shall have been informed of the possibility of such damages. This *
+* limitation of liability shall not apply to liability for death or *
+* personal injury resulting from such party's negligence to the *
+* extent applicable law prohibits such limitation. Some *
+* jurisdictions do not allow the exclusion or limitation of *
+* incidental or consequential damages, so this exclusion and *
+* limitation may not apply to You. *
+* *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+ This Source Code Form is "Incompatible With Secondary Licenses", as
+ defined by the Mozilla Public License, v. 2.0.
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..baadae1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,77 @@
+![Oxford Nanopore Technologies logo](images/ONT_logo_590x106.png)
+
+VBZ Compression
+===============
+
+VBZ Compression uses variable byte integer encoding to compress nanopore signal data and is built using the following libraries:
+
+ - https://github.com/lemire/streamvbyte
+ - https://github.com/facebook/zstd
+
+The performance of VBZ is achieved by taking advantage of the properties of the raw signal and therefore is most effective when applied to the signal dataset. Other datasets you may have in your Fast5 files will not be able to take advantage of the default VBZ settings for compression. VBZ will be used as the default compression scheme in a future release of MinKNOW.
+
+Installation
+------------
+
+See the [release](https://github.com/nanoporetech/vbz_compression/releases) section to find the installers for the hdf5 plugin.
+
+Post installation you can then use `HDFView`, `h5repack` or `h5py` as you normally would:
+
+```bash
+# Invoke h5repack to pack input.fast5 into output.fast5
+#
+# The integer values specify how the data is packed:
+# - 32020: The id of the filter to apply (vbz in this case)
+# - 5: The number of following arguments
+# - 0: Filter flag for configuring filter version
+# - 0: Padding value for configuring filter version
+# - 2: Packing integers of size 2 bytes
+# - 1: Use zig zag encoding
+# - 1: Use zstd compression level 1
+> h5repack -f UD=32020,5,0,0,2,1,1 input.fast5 output.fast5
+
+# To compress 4 byte unsigned integers (no zig zag) with level 3 zstd you could use:
+> h5repack -f UD=32020,5,0,0,4,0,3 input.h5 output.h5
+
+# Invoke h5repack recursively on all reads using 10 processes
+> find . -name "*.fast5" | xargs -P 10 -I % h5repack -f UD=32020,5,0,0,2,1,1 % %.vbz
+
+# Invoke h5repack recursively on all reads storing the results inplace using 10 processes
+> find . -name "*.fast5" | xargs -P 10 -I % sh -c "h5repack -f UD=32020,5,0,0,2,1,1 % %.vbz && mv %.vbz %"
+```
+
+Benchmarks
+----------
+
+VBZ outperforms GZIP in both CPU time (>10X compression, >5X decompression) and compression (>30%).
+
+![Compression Ratio](images/vbz_compression_ratio.png)
+![Compression Performance](images/vbz_x86_compression.png)
+![Decompression Performance](images/vbz_x86_decompression.png)
+
+
+Development
+-----------
+
+To develop the plugin without conan you need the following installed:
+
+- cmake 3.11 (https://cmake.org/)
+
+and the following c++ dependencies
+
+- zstd development libraries available to cmake
+- hdf5 development libraries available to cmake (required for testing)
+
+The following ubuntu packages provide these libraries:
+ - libhdf5-dev
+ - libzstd-dev
+
+Then configure the project using:
+
+```bash
+> git submodule update --init
+> mkdir build
+> cd build
+> cmake -D CMAKE_BUILD_TYPE=Release -D ENABLE_CONAN=OFF -D ENABLE_PERF_TESTING=OFF -D ENABLE_PYTHON=OFF ..
+> make -j
+```
diff --git a/cmake/FindASan.cmake b/cmake/FindASan.cmake
new file mode 100755
index 0000000..98ea7cb
--- /dev/null
+++ b/cmake/FindASan.cmake
@@ -0,0 +1,59 @@
+# The MIT License (MIT)
+#
+# Copyright (c)
+# 2013 Matthew Arsenault
+# 2015-2016 RWTH Aachen University, Federal Republic of Germany
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+option(SANITIZE_ADDRESS "Enable AddressSanitizer for sanitized targets." Off)
+
+set(FLAG_CANDIDATES
+ # Clang 3.2+ use this version. The no-omit-frame-pointer option is optional.
+ "-g -fsanitize=address -fno-omit-frame-pointer"
+ "-g -fsanitize=address"
+
+ # Older deprecated flag for ASan
+ "-g -faddress-sanitizer"
+)
+
+
+if (SANITIZE_ADDRESS AND (SANITIZE_THREAD OR SANITIZE_MEMORY))
+ message(FATAL_ERROR "AddressSanitizer is not compatible with "
+ "ThreadSanitizer or MemorySanitizer.")
+endif ()
+
+
+include(sanitize-helpers)
+
+if (SANITIZE_ADDRESS)
+ sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "AddressSanitizer"
+ "ASan")
+
+ find_program(ASan_WRAPPER "asan-wrapper" PATHS ${CMAKE_MODULE_PATH})
+ mark_as_advanced(ASan_WRAPPER)
+endif ()
+
+function (add_sanitize_address TARGET)
+ if (NOT SANITIZE_ADDRESS)
+ return()
+ endif ()
+
+ sanitizer_add_flags(${TARGET} "AddressSanitizer" "ASan")
+endfunction ()
diff --git a/cmake/FindFuzzer.cmake b/cmake/FindFuzzer.cmake
new file mode 100644
index 0000000..7226a88
--- /dev/null
+++ b/cmake/FindFuzzer.cmake
@@ -0,0 +1,28 @@
+
+option(SANITIZE_FUZZER "Enable Fuzzer for sanitized targets." Off)
+
+include(sanitize-helpers)
+
+if (SANITIZE_FUZZER)
+ set(CMAKE_REQUIRED_FLAGS "-g -fsanitize=fuzzer")
+ check_cxx_source_compiles("#include <cstdint>\n#include <cstddef>\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {}" Fuzz_FLAG_DETECTED)
+
+ get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
+ foreach (LANG ${ENABLED_LANGUAGES})
+ # Sanitizer flags are not dependend on language, but the used compiler.
+ # So instead of searching flags foreach language, search flags foreach
+ # compiler used.
+ set(COMPILER ${CMAKE_${LANG}_COMPILER_ID})
+ if (Fuzz_FLAG_DETECTED)
+ set(Fuzz_${COMPILER}_FLAGS "${CMAKE_REQUIRED_FLAGS}" CACHE STRING "Fuzzer arguments")
+ endif()
+ endforeach()
+endif()
+
+function(add_sanitize_fuzzer TARGET)
+ if (NOT SANITIZE_FUZZER)
+ return()
+ endif ()
+
+ sanitizer_add_flags(${TARGET} "FuzzSanitizer" "Fuzz")
+endfunction ()
diff --git a/cmake/FindGoogleBenchmark.cmake b/cmake/FindGoogleBenchmark.cmake
new file mode 100644
index 0000000..f25c5e6
--- /dev/null
+++ b/cmake/FindGoogleBenchmark.cmake
@@ -0,0 +1,75 @@
+
+find_path(GOOGLE_BENCHMARK_INCLUDE_DIR
+ NAMES benchmark/benchmark.h
+ PATHS ${CONAN_INCLUDE_DIRS_RELEASE}
+)
+
+set(GOOGLE_BENCHMARK benchmark)
+set(GOOGLE_BENCHMARK_DEBUG benchmarkd)
+
+find_library(GOOGLE_BENCHMARK_LIBRARY_RELEASE
+ NAMES ${GOOGLE_BENCHMARK}
+ PATHS ${CONAN_LIB_DIRS_RELEASE}
+)
+find_library(GOOGLE_BENCHMARK_LIBRARY_DEBUG
+ NAMES ${GOOGLE_BENCHMARK_DEBUG}
+ PATHS ${CONAN_LIB_DIRS_DEBUG}
+)
+
+include(SelectLibraryConfigurations)
+select_library_configurations(GOOGLE_BENCHMARK)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(google-benchmark REQUIRED_VARS GOOGLE_BENCHMARK_LIBRARY GOOGLE_BENCHMARK_INCLUDE_DIR)
+
+
+if (GOOGLE_BENCHMARK_FOUND)
+ set(GOOGLE_BENCHMARK_INCLUDE_DIRS ${GOOGLE_BENCHMARK_INCLUDE_DIR})
+
+
+ if (NOT GOOGLE_BENCHMARK_LIBRARIES)
+ set(GOOGLE_BENCHMARK_LIBRARIES ${GOOGLE_BENCHMARK_LIBRARY})
+ endif()
+
+ if (NOT TARGET google::benchmark)
+ add_library(google::benchmark UNKNOWN IMPORTED)
+ set_target_properties(google::benchmark PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${GOOGLE_BENCHMARK_INCLUDE_DIRS}")
+
+ set(EXTRA_LIBRARIES)
+ if (WIN32)
+ set(EXTRA_LIBRARIES shlwapi.lib)
+ endif()
+
+ find_package (Threads)
+ if (CMAKE_THREAD_LIBS_INIT)
+ set(EXTRA_LIBRARIES ${EXTRA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+ endif()
+
+ if (EXTRA_LIBRARIES)
+ set_target_properties(google::benchmark
+ PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES
+ ${EXTRA_LIBRARIES}
+ )
+ endif()
+
+ if(GOOGLE_BENCHMARK_LIBRARY_RELEASE)
+ set_property(TARGET google::benchmark APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties(google::benchmark PROPERTIES
+ IMPORTED_LOCATION_RELEASE "${GOOGLE_BENCHMARK_LIBRARY_RELEASE}")
+ endif()
+
+ if(GOOGLE_BENCHMARK_LIBRARY_DEBUG)
+ set_property(TARGET google::benchmark APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
+ set_target_properties(google::benchmark PROPERTIES
+ IMPORTED_LOCATION_DEBUG "${GOOGLE_BENCHMARK_LIBRARY_DEBUG}")
+ endif()
+
+ if(NOT GOOGLE_BENCHMARK_LIBRARY_RELEASE AND NOT GOOGLE_BENCHMARK_LIBRARY_DEBUG)
+ set_property(TARGET google::benchmark APPEND PROPERTY
+ IMPORTED_LOCATION "${GOOGLE_BENCHMARK_LIBRARY}")
+ endif()
+ endif()
+endif() \ No newline at end of file
diff --git a/cmake/FindMSan.cmake b/cmake/FindMSan.cmake
new file mode 100755
index 0000000..22d0050
--- /dev/null
+++ b/cmake/FindMSan.cmake
@@ -0,0 +1,57 @@
+# The MIT License (MIT)
+#
+# Copyright (c)
+# 2013 Matthew Arsenault
+# 2015-2016 RWTH Aachen University, Federal Republic of Germany
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+option(SANITIZE_MEMORY "Enable MemorySanitizer for sanitized targets." Off)
+
+set(FLAG_CANDIDATES
+ "-g -fsanitize=memory"
+)
+
+
+include(sanitize-helpers)
+
+if (SANITIZE_MEMORY)
+ if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+ message(WARNING "MemorySanitizer disabled for target ${TARGET} because "
+ "MemorySanitizer is supported for Linux systems only.")
+ set(SANITIZE_MEMORY Off CACHE BOOL
+ "Enable MemorySanitizer for sanitized targets." FORCE)
+ elseif (NOT ${CMAKE_SIZEOF_VOID_P} EQUAL 8)
+ message(WARNING "MemorySanitizer disabled for target ${TARGET} because "
+ "MemorySanitizer is supported for 64bit systems only.")
+ set(SANITIZE_MEMORY Off CACHE BOOL
+ "Enable MemorySanitizer for sanitized targets." FORCE)
+ else ()
+ sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "MemorySanitizer"
+ "MSan")
+ endif ()
+endif ()
+
+function (add_sanitize_memory TARGET)
+ if (NOT SANITIZE_MEMORY)
+ return()
+ endif ()
+
+ sanitizer_add_flags(${TARGET} "MemorySanitizer" "MSan")
+endfunction ()
diff --git a/cmake/FindSanitizers.cmake b/cmake/FindSanitizers.cmake
new file mode 100755
index 0000000..1b98ac6
--- /dev/null
+++ b/cmake/FindSanitizers.cmake
@@ -0,0 +1,95 @@
+# The MIT License (MIT)
+#
+# Copyright (c)
+# 2013 Matthew Arsenault
+# 2015-2016 RWTH Aachen University, Federal Republic of Germany
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+# If any of the used compiler is a GNU compiler, add a second option to static
+# link against the sanitizers.
+option(SANITIZE_LINK_STATIC "Try to link static against sanitizers." Off)
+
+
+
+
+set(FIND_QUIETLY_FLAG "")
+if (DEFINED Sanitizers_FIND_QUIETLY)
+ set(FIND_QUIETLY_FLAG "QUIET")
+endif ()
+
+find_package(ASan ${FIND_QUIETLY_FLAG})
+find_package(TSan ${FIND_QUIETLY_FLAG})
+find_package(MSan ${FIND_QUIETLY_FLAG})
+find_package(UBSan ${FIND_QUIETLY_FLAG})
+find_package(Fuzzer ${FIND_QUIETLY_FLAG})
+
+
+
+
+function(sanitizer_add_blacklist_file FILE)
+ if(NOT IS_ABSOLUTE ${FILE})
+ set(FILE "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}")
+ endif()
+ get_filename_component(FILE "${FILE}" REALPATH)
+
+ sanitizer_check_compiler_flags("-fsanitize-blacklist=${FILE}"
+ "SanitizerBlacklist" "SanBlist")
+endfunction()
+
+function(add_sanitizers ...)
+ # If no sanitizer is enabled, return immediately.
+ if (NOT (SANITIZE_ADDRESS OR SANITIZE_MEMORY OR SANITIZE_THREAD OR
+ SANITIZE_UNDEFINED))
+ return()
+ endif ()
+
+ foreach (TARGET ${ARGV})
+ # Check if this target will be compiled by exactly one compiler. Other-
+ # wise sanitizers can't be used and a warning should be printed once.
+ get_target_property(TARGET_TYPE ${TARGET} TYPE)
+ if (TARGET_TYPE STREQUAL "INTERFACE_LIBRARY")
+ message(WARNING "Can't use any sanitizers for target ${TARGET}, "
+ "because it is an interface library and cannot be "
+ "compiled directly.")
+ return()
+ endif ()
+ sanitizer_target_compilers(${TARGET} TARGET_COMPILER)
+ list(LENGTH TARGET_COMPILER NUM_COMPILERS)
+ if (NUM_COMPILERS GREATER 1)
+ message(WARNING "Can't use any sanitizers for target ${TARGET}, "
+ "because it will be compiled by incompatible compilers. "
+ "Target will be compiled without sanitizers.")
+ return()
+
+ # If the target is compiled by no or no known compiler, give a warning.
+ elseif (NUM_COMPILERS EQUAL 0)
+ message(WARNING "Sanitizers for target ${TARGET} may not be"
+ " usable, because it uses no or an unknown compiler. "
+ "This is a false warning for targets using only "
+ "object lib(s) as input.")
+ endif ()
+
+ # Add sanitizers for target.
+ add_sanitize_address(${TARGET})
+ add_sanitize_thread(${TARGET})
+ add_sanitize_memory(${TARGET})
+ add_sanitize_undefined(${TARGET})
+ endforeach ()
+endfunction(add_sanitizers)
diff --git a/cmake/FindTSan.cmake b/cmake/FindTSan.cmake
new file mode 100755
index 0000000..3cba3c0
--- /dev/null
+++ b/cmake/FindTSan.cmake
@@ -0,0 +1,65 @@
+# The MIT License (MIT)
+#
+# Copyright (c)
+# 2013 Matthew Arsenault
+# 2015-2016 RWTH Aachen University, Federal Republic of Germany
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+option(SANITIZE_THREAD "Enable ThreadSanitizer for sanitized targets." Off)
+
+set(FLAG_CANDIDATES
+ "-g -fsanitize=thread"
+)
+
+
+# ThreadSanitizer is not compatible with MemorySanitizer.
+if (SANITIZE_THREAD AND SANITIZE_MEMORY)
+ message(FATAL_ERROR "ThreadSanitizer is not compatible with "
+ "MemorySanitizer.")
+endif ()
+
+
+include(sanitize-helpers)
+
+if (SANITIZE_THREAD)
+ if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND
+ NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+ message(WARNING "ThreadSanitizer disabled for target ${TARGET} because "
+ "ThreadSanitizer is supported for Linux systems and macOS only.")
+ set(SANITIZE_THREAD Off CACHE BOOL
+ "Enable ThreadSanitizer for sanitized targets." FORCE)
+ elseif (NOT ${CMAKE_SIZEOF_VOID_P} EQUAL 8)
+ message(WARNING "ThreadSanitizer disabled for target ${TARGET} because "
+ "ThreadSanitizer is supported for 64bit systems only.")
+ set(SANITIZE_THREAD Off CACHE BOOL
+ "Enable ThreadSanitizer for sanitized targets." FORCE)
+ else ()
+ sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "ThreadSanitizer"
+ "TSan")
+ endif ()
+endif ()
+
+function (add_sanitize_thread TARGET)
+ if (NOT SANITIZE_THREAD)
+ return()
+ endif ()
+
+ sanitizer_add_flags(${TARGET} "ThreadSanitizer" "TSan")
+endfunction ()
diff --git a/cmake/FindUBSan.cmake b/cmake/FindUBSan.cmake
new file mode 100755
index 0000000..ae103f7
--- /dev/null
+++ b/cmake/FindUBSan.cmake
@@ -0,0 +1,46 @@
+# The MIT License (MIT)
+#
+# Copyright (c)
+# 2013 Matthew Arsenault
+# 2015-2016 RWTH Aachen University, Federal Republic of Germany
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+option(SANITIZE_UNDEFINED
+ "Enable UndefinedBehaviorSanitizer for sanitized targets." Off)
+
+set(FLAG_CANDIDATES
+ "-g -fsanitize=undefined"
+)
+
+
+include(sanitize-helpers)
+
+if (SANITIZE_UNDEFINED)
+ sanitizer_check_compiler_flags("${FLAG_CANDIDATES}"
+ "UndefinedBehaviorSanitizer" "UBSan")
+endif ()
+
+function (add_sanitize_undefined TARGET)
+ if (NOT SANITIZE_UNDEFINED)
+ return()
+ endif ()
+
+ sanitizer_add_flags(${TARGET} "UndefinedBehaviorSanitizer" "UBSan")
+endfunction ()
diff --git a/cmake/Findzstd.cmake b/cmake/Findzstd.cmake
new file mode 100644
index 0000000..493a53b
--- /dev/null
+++ b/cmake/Findzstd.cmake
@@ -0,0 +1,75 @@
+find_path(ZSTD_INCLUDE_DIR
+ NAMES zstd.h
+ PATHS
+ ${CONAN_INCLUDE_DIRS_RELEASE}
+ ${CONAN_INCLUDE_DIRS_DEBUG}
+)
+
+set(ZSTD_NAMES zstd zstd_static)
+set(ZSTD_NAMES_DEBUG zstdd zstd_staticd)
+
+find_library(ZSTD_LIBRARY_RELEASE
+ NAMES ${ZSTD_NAMES}
+ PATHS ${CONAN_LIB_DIRS_RELEASE}
+)
+find_library(ZSTD_LIBRARY_DEBUG
+ NAMES
+ ${ZSTD_NAMES_DEBUG}
+ ${ZSTD_NAMES}
+ PATHS ${CONAN_LIB_DIRS_DEBUG}
+)
+
+include(SelectLibraryConfigurations)
+select_library_configurations(ZSTD)
+
+if(ZSTD_INCLUDE_DIR AND EXISTS "${ZSTD_INCLUDE_DIR}/zstd.h")
+ file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" ZSTD_VERSION_MAJOR_LINE REGEX "^#define ZSTD_VERSION_MAJOR.*$")
+ file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" ZSTD_VERSION_MINOR_LINE REGEX "^#define ZSTD_VERSION_MINOR.*$")
+ file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" ZSTD_VERSION_RELEASE_LINE REGEX "^#define ZSTD_VERSION_RELEASE.*$")
+
+ string(REGEX REPLACE "^.*ZSTD_VERSION_MAJOR *([0-9]+)$" "\\1" ZSTD_VERSION_MAJOR "${ZSTD_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^.*ZSTD_VERSION_MINOR *([0-9]+)$" "\\1" ZSTD_VERSION_MINOR "${ZSTD_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^.*ZSTD_VERSION_RELEASE *([0-9]+)$" "\\1" ZSTD_VERSION_RELEASE "${ZSTD_VERSION_RELEASE_LINE}")
+
+ set(ZSTD_VERSION_STRING "${ZSTD_VERSION_MAJOR}.${ZSTD_VERSION_MINOR}.${ZSTD_VERSION_RELEASE}")
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if
+# all listed variables are TRUE
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(zstd REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR
+ VERSION_VAR ZSTD_VERSION_STRING)
+
+
+if (ZSTD_FOUND)
+ set(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR})
+
+ if (NOT ZSTD_LIBRARIES)
+ set(ZSTD_LIBRARIES ${ZSTD_LIBRARY})
+ endif()
+
+ if (NOT TARGET zstd::zstd)
+ add_library(zstd::zstd UNKNOWN IMPORTED)
+ set_target_properties(zstd::zstd PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIRS}")
+
+ if(ZSTD_LIBRARY_RELEASE)
+ set_property(TARGET zstd::zstd APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties(zstd::zstd PROPERTIES
+ IMPORTED_LOCATION_RELEASE "${ZSTD_LIBRARY_RELEASE}")
+ endif()
+
+ if(ZSTD_LIBRARY_DEBUG)
+ set_property(TARGET zstd::zstd APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
+ set_target_properties(zstd::zstd PROPERTIES
+ IMPORTED_LOCATION_DEBUG "${ZSTD_LIBRARY_DEBUG}")
+ endif()
+
+ if(NOT ZSTD_LIBRARY_RELEASE AND NOT ZSTD_LIBRARY_DEBUG)
+ set_property(TARGET zstd::zstd APPEND PROPERTY
+ IMPORTED_LOCATION "${ZSTD_LIBRARY}")
+ endif()
+ endif()
+endif()
diff --git a/cmake/ONTFindModuleHelpers.cmake b/cmake/ONTFindModuleHelpers.cmake
new file mode 100644
index 0000000..bcc987c
--- /dev/null
+++ b/cmake/ONTFindModuleHelpers.cmake
@@ -0,0 +1,312 @@
+#.rst:
+# ONTFindModuleHelpers
+# --------------------
+#
+# Based on ECMFindModuleHelpers from extra-cmake-modules.
+
+include(CMakeParseArguments)
+
+macro(ont_find_package_parse_components module_name)
+ set(_options SKIP_DEPENDENCY_HANDLING)
+ set(_oneValueArgs RESULT_VAR)
+ set(_multiValueArgs KNOWN_COMPONENTS)
+ cmake_parse_arguments(_ECM_FPPC "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
+
+ if(_ECM_FPPC_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unexpected arguments to ecm_find_package_parse_components: ${_ECM_FPPC_UNPARSED_ARGUMENTS}")
+ endif()
+ if(NOT _ECM_FPPC_RESULT_VAR)
+ message(FATAL_ERROR "Missing RESULT_VAR argument to ecm_find_package_parse_components")
+ endif()
+ if(NOT _ECM_FPPC_KNOWN_COMPONENTS)
+ message(FATAL_ERROR "Missing KNOWN_COMPONENTS argument to ecm_find_package_parse_components")
+ endif()
+
+ if(${module_name}_FIND_COMPONENTS)
+ set(_requestedComps ${${module_name}_FIND_COMPONENTS})
+
+ if(NOT _ECM_FPPC_SKIP_DEPENDENCY_HANDLING)
+ # Make sure deps are included
+ set(_new_comps ${_requestedComps})
+ while(_new_comps)
+ set(_working_comps ${_new_comps})
+ set(_new_comps)
+ foreach(_comp ${_working_comps})
+ foreach(_dep_comp ${${module_name}_${_comp}_component_deps})
+ list(FIND _requestedComps "${_dep_comp}" _index)
+ if("${_index}" STREQUAL "-1")
+ if(NOT ${module_name}_FIND_QUIETLY)
+ message(STATUS "${module_name}: ${_comp} requires ${_dep_comp}")
+ endif()
+ list(APPEND _new_comps "${_dep_comp}")
+ list(APPEND _requestedComps "${_dep_comp}")
+ endif()
+ endforeach()
+ endforeach()
+ endwhile()
+ else()
+ message(STATUS "Skipping dependency handling for ${module_name}")
+ endif()
+ list(REMOVE_DUPLICATES _requestedComps)
+
+ # This makes sure components are listed in the same order as
+ # KNOWN_COMPONENTS (potentially important for inter-dependencies)
+ set(${_ECM_FPPC_RESULT_VAR})
+ foreach(_comp ${_ECM_FPPC_KNOWN_COMPONENTS})
+ list(FIND _requestedComps "${_comp}" _index)
+ if(NOT "${_index}" STREQUAL "-1")
+ list(APPEND ${_ECM_FPPC_RESULT_VAR} "${_comp}")
+ list(REMOVE_AT _requestedComps ${_index})
+ endif()
+ endforeach()
+ # if there are any left, they are unknown components
+ if(_requestedComps)
+ set(_msgType STATUS)
+ if(${module_name}_FIND_REQUIRED)
+ set(_msgType FATAL_ERROR)
+ endif()
+ if(NOT ${module_name}_FIND_QUIETLY)
+ message(${_msgType} "${module_name}: requested unknown components ${_requestedComps}")
+ endif()
+ return()
+ endif()
+ else()
+ set(${_ECM_FPPC_RESULT_VAR} ${_ECM_FPPC_KNOWN_COMPONENTS})
+ endif()
+endmacro()
+
+macro(ont_debug_lib_helper outvar debugvar releasevar)
+ if (${releasevar} AND ${debugvar})
+ if (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
+ set(${outvar}
+ optimized ${${releasevar}}
+ debug ${${debugvar}}
+ )
+ else()
+ set(${outvar} ${${releasevar}})
+ endif()
+ elseif (${releasevar} AND NOT ${debugvar})
+ set(${outvar} ${${releasevar}})
+ elseif (${debugvar} AND NOT ${releasevar})
+ set(${outvar} ${${debugvar}})
+ endif()
+endmacro()
+
+function(ont_create_library_target target)
+ if(TARGET ${target})
+ return()
+ endif()
+
+ set(options)
+ set(oneValueArgs DEBUG_LIBRARY RELEASE_LIBRARY LIBRARY)
+ set(multiValueArgs DEPENDENCIES DEBUG_DEPENDENCIES RELEASE_DEPENDENCIES COMPILE_DEFINITIONS COMPILE_OPTIONS INCLUDE_DIRS)
+ cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if (ARG_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unexpected arguments to ont_create_library_target: ${ARG_UNPARSED_ARGUMENTS}")
+ endif()
+ if (ARG_LIBRARY)
+ if (ARG_DEBUG_LIBRARY OR ARG_RELEASE_LIBRARY)
+ message(FATAL_ERROR "Cannot specify LIBRARY as well as DEBUG_LIBRARY or RELEASE_LIBRARY")
+ endif()
+ elseif (NOT ARG_DEBUG_LIBRARY AND NOT ARG_RELEASE_LIBRARY)
+ message(FATAL_ERROR "Must specify LIBRARY, DEBUG_LIBRARY or RELEASE_LIBRARY")
+ endif()
+
+ add_library(${target} UNKNOWN IMPORTED)
+ if (ARG_LIBRARY)
+ set_property(TARGET ${target}
+ PROPERTY
+ IMPORTED_LOCATION "${ARG_LIBRARY}"
+ )
+ else()
+ if (ARG_RELEASE_LIBRARY)
+ set_property(TARGET ${target}
+ APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE
+ )
+ set_property(TARGET ${target}
+ PROPERTY
+ IMPORTED_LOCATION_RELEASE "${ARG_RELEASE_LIBRARY}"
+ )
+ endif()
+ if (ARG_DEBUG_LIBRARY)
+ set_property(TARGET ${target}
+ APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG
+ )
+ set_property(TARGET ${target}
+ PROPERTY
+ IMPORTED_LOCATION_DEBUG "${ARG_DEBUG_LIBRARY}"
+ )
+ endif()
+ if (ARG_DEBUG_DEPENDENCIES)
+ list(APPEND ARG_DEPENDENCIES "$<$<CONFIG:Debug>:${ARG_DEBUG_DEPENDENCIES}>")
+ endif()
+ if (ARG_RELEASE_DEPENDENCIES)
+ list(APPEND ARG_DEPENDENCIES "$<$<NOT:$<CONFIG:Debug>>:${ARG_RELEASE_DEPENDENCIES}>")
+ endif()
+ endif()
+ set_target_properties(${target} PROPERTIES
+ INTERFACE_COMPILE_DEFINITIONS "${ARG_COMPILE_DEFINITIONS}"
+ INTERFACE_COMPILE_OPTIONS "${ARG_COMPILE_OPTIONS}"
+ INTERFACE_INCLUDE_DIRECTORIES "${ARG_INCLUDE_DIRS}"
+ INTERFACE_LINK_LIBRARIES "${ARG_DEPENDENCIES}"
+ )
+endfunction()
+
+macro(ont_find_package_handle_library_components module_name)
+ set(_options SKIP_PKG_CONFIG SKIP_DEPENDENCY_HANDLING DEBUG_AND_RELEASE)
+ set(_oneValueArgs)
+ set(_multiValueArgs COMPONENTS)
+ cmake_parse_arguments(_ONT_FPWC "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
+
+ if(_ONT_FPWC_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unexpected arguments to ecm_find_package_handle_components: ${_ONT_FPWC_UNPARSED_ARGUMENTS}")
+ endif()
+ if(NOT _ONT_FPWC_COMPONENTS)
+ message(FATAL_ERROR "Missing COMPONENTS argument to ecm_find_package_handle_components")
+ endif()
+
+ include(FindPackageHandleStandardArgs)
+ if(NOT _ONT_FPWC_SKIP_PKG_CONFIG)
+ find_package(PkgConfig QUIET)
+ endif()
+ # CMake 3.17+ warns when find_package_handle_standard_args() is called with a name that doesn't
+ # match the find module name; this tells it that we really did mean to do that
+ set(FPHSA_NAME_MISMATCHED TRUE)
+ foreach(_comp ${_ONT_FPWC_COMPONENTS})
+ set(_dep_vars)
+ set(_dep_targets)
+ if(NOT SKIP_DEPENDENCY_HANDLING)
+ foreach(_dep ${${module_name}_${_comp}_component_deps})
+ list(APPEND _dep_vars "${module_name}_${_dep}_FOUND")
+ list(APPEND _dep_targets "${module_name}::${_dep}")
+ endforeach()
+ endif()
+
+ if(NOT _ONT_FPWC_SKIP_PKG_CONFIG AND ${module_name}_${_comp}_pkg_config)
+ pkg_check_modules(PKG_${module_name}_${_comp} QUIET
+ ${${module_name}_${_comp}_pkg_config})
+ endif()
+
+ set(_include_var)
+ if (${module_name}_${_comp}_header_names)
+ set(_include_var ${module_name}_${_comp}_INCLUDE_DIR)
+ find_path(${_include_var}
+ NAMES ${${module_name}_${_comp}_header_names}
+ HINTS ${PKG_${module_name}_${_comp}_INCLUDE_DIRS}
+ PATH_SUFFIXES ${${module_name}_${_comp}_header_path_suffixes}
+ )
+ endif()
+ if (_ONT_FPWC_DEBUG_AND_RELEASE)
+ find_library(${module_name}_${_comp}_LIBRARY_RELEASE
+ NAMES ${${module_name}_${_comp}_lib_names_release}
+ HINTS ${PKG_${module_name}_${_comp}_LIBRARY_DIRS}
+ DOC "The release version of the ${_comp} library from ${module_name}"
+ )
+ find_library(${module_name}_${_comp}_LIBRARY_DEBUG
+ NAMES ${${module_name}_${_comp}_lib_names_debug}
+ HINTS ${PKG_${module_name}_${_comp}_LIBRARY_DIRS}
+ DOC "The debug version of the ${_comp} library from ${module_name}"
+ )
+ ont_debug_lib_helper(
+ ${module_name}_${_comp}_LIBRARY
+ ${module_name}_${_comp}_LIBRARY_DEBUG
+ ${module_name}_${_comp}_LIBRARY_RELEASE
+ )
+ set(${module_name}_${_comp}_LIBRARY
+ "${${module_name}_${_comp}_LIBRARY}"
+ CACHE STRING "The ${_comp} library from ${module_name}" FORCE
+ )
+ else()
+ find_library(${module_name}_${_comp}_LIBRARY
+ NAMES ${${module_name}_${_comp}_lib_names}
+ HINTS ${PKG_${module_name}_${_comp}_LIBRARY_DIRS}
+ DOC "The ${_comp} library from ${module_name}"
+ )
+ endif()
+
+ set(${module_name}_${_comp}_VERSION "${PKG_${module_name}_${_comp}_VERSION}")
+ if(NOT ${module_name}_VERSION)
+ set(${module_name}_VERSION ${${module_name}_${_comp}_VERSION})
+ endif()
+
+ find_package_handle_standard_args(${module_name}_${_comp}
+ FOUND_VAR
+ ${module_name}_${_comp}_FOUND
+ REQUIRED_VARS
+ ${module_name}_${_comp}_LIBRARY
+ ${_include_var}
+ ${_dep_vars}
+ VERSION_VAR
+ ${module_name}_${_comp}_VERSION
+ )
+
+ mark_as_advanced(
+ ${module_name}_${_comp}_LIBRARY
+ ${module_name}_${_comp}_INCLUDE_DIR
+ )
+
+ if(${module_name}_${_comp}_FOUND)
+ set(${module_name}_${_comp}_DEFINITIONS
+ ${PKG_${module_name}_${_comp}_DEFINITIONS}
+ ${${module_name}_${_comp}_compile_opts})
+ ont_create_library_target(${module_name}::${_comp}
+ DEBUG_LIBRARY "${${module_name}_${_comp}_LIBRARY_DEBUG}"
+ RELEASE_LIBRARY "${${module_name}_${_comp}_LIBRARY_RELEASE}"
+ DEPENDENCIES "${_dep_targets}"
+ COMPILE_OPTIONS "${${module_name}_${_comp}_DEFINITIONS}"
+ INCLUDE_DIRS "${${module_name}_${_comp}_INCLUDE_DIR}"
+ )
+ if (NOT ${module_name}_${_comp}_LIBRARY_DEBUG)
+ set(${module_name}_${_comp}_LIBRARY_DEBUG
+ ${module_name}_${_comp}_LIBRARY_RELEASE)
+ elseif (NOT ${module_name}_${_comp}_LIBRARY_RELEASE)
+ set(${module_name}_${_comp}_LIBRARY_RELEASE
+ ${module_name}_${_comp}_LIBRARY_DEBUG)
+ endif()
+ list(APPEND
+ ${module_name}_LIBRARIES
+ "${${module_name}_${_comp}_LIBRARY}")
+ if (_ONT_FPWC_DEBUG_AND_RELEASE)
+ if (${module_name}_${_comp}_LIBRARY_RELEASE)
+ list(APPEND
+ ${module_name}_LIBRARIES_RELEASE
+ "${${module_name}_${_comp}_LIBRARY_RELEASE}")
+ endif()
+ if (${module_name}_${_comp}_LIBRARY_DEBUG)
+ list(APPEND
+ ${module_name}_LIBRARIES_DEBUG
+ "${${module_name}_${_comp}_LIBRARY_DEBUG}")
+ endif()
+ endif()
+ if (${_include_var})
+ list(APPEND
+ ${module_name}_INCLUDE_DIRS
+ "${${_include_var}}")
+ endif()
+ set(${module_name}_DEFINITIONS
+ ${${module_name}_DEFINITIONS}
+ ${${module_name}_${_comp}_DEFINITIONS})
+ list(APPEND ${module_name}_TARGETS
+ "${module_name}::${_comp}")
+ endif()
+ endforeach()
+ # we need to unset it again because this is a macro, not a function
+ unset(FPHSA_NAME_MISMATCHED)
+ if(${module_name}_DEBUG_LIBRARIES)
+ list(REMOVE_DUPLICATES ${module_name}_DEBUG_LIBRARIES)
+ endif()
+ if(${module_name}_INCLUDE_DIRS)
+ list(REMOVE_DUPLICATES ${module_name}_INCLUDE_DIRS)
+ endif()
+ if(${module_name}_DEFINITIONS)
+ list(REMOVE_DUPLICATES ${module_name}_DEFINITIONS)
+ endif()
+ if(${module_name}_TARGETS)
+ list(REMOVE_DUPLICATES ${module_name}_TARGETS)
+ endif()
+endmacro()
+
+
diff --git a/cmake/SignFile.cmake b/cmake/SignFile.cmake
new file mode 100644
index 0000000..286bacc
--- /dev/null
+++ b/cmake/SignFile.cmake
@@ -0,0 +1,61 @@
+set(file_to_sign ${CMAKE_ARGV3})
+
+# Pull from command line by default - otherwise require an environment variable.
+if (NOT MINKNOW_CODE_SIGN_IDENTITY)
+ if ("$ENV{MINKNOW_CODE_SIGN_IDENTITY}" STREQUAL "")
+ message(FATAL_ERROR "Caller must specify code sign identiyy in environment variable 'MINKNOW_CODE_SIGN_IDENTITY'")
+ endif()
+
+ set(MINKNOW_CODE_SIGN_IDENTITY "$ENV{MINKNOW_CODE_SIGN_IDENTITY}")
+endif()
+
+if (APPLE)
+ message("Signing file... ${file_to_sign}${keychain_comment}")
+ set(SIGN_COMMAND
+ codesign -s ${MINKNOW_CODE_SIGN_IDENTITY} ${keychain_arg} --force --deep -vvvv ${file_to_sign})
+elseif(WIN32)
+ find_program(
+ SIGNTOOL_EXE "Signtool.exe"
+ PATHS "C:\\Program Files (x86)\\Windows Kits\\10\\App Certification Kit")
+
+ if (NOT SIGNTOOL_EXE)
+ message(FATAL_ERROR "Failed to find signtool executable")
+ endif()
+
+ message("Signing file... ${file_to_sign}${comment}")
+ set(SIGN_COMMAND ${SIGNTOOL_EXE} sign "/v" "/sha1" "${MINKNOW_CODE_SIGN_IDENTITY}"
+ "/tr" "http://rfc3161timestamp.globalsign.com/advanced"
+ "/td" "SHA256"
+ ${file_to_sign}
+ )
+
+else()
+ message(FATAL_ERROR "Cannot sign code on this platform.")
+endif()
+
+set(retry_count 10)
+foreach(retry_index RANGE ${retry_count})
+ message("Running sign command: ${SIGN_COMMAND}")
+ execute_process(
+ COMMAND ${SIGN_COMMAND}
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE output
+ ERROR_VARIABLE output
+ )
+
+ if (result EQUAL 0)
+ break()
+ endif()
+
+ message(WARN "Signing failed, waiting and retrying (${retry_index}/${retry_count})")
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E sleep 5
+ )
+
+endforeach()
+
+if (NOT result EQUAL 0)
+ message(FATAL_ERROR "Could not sign file: ${result}: ${output}")
+else()
+ message("Signed file: ${output}")
+endif() \ No newline at end of file
diff --git a/cmake/SigningUtils.cmake b/cmake/SigningUtils.cmake
new file mode 100644
index 0000000..196b421
--- /dev/null
+++ b/cmake/SigningUtils.cmake
@@ -0,0 +1,25 @@
+function(hdf_add_signing_command target)
+ set(options)
+ set(oneValArgs FILE)
+ set(multiValArgs)
+ cmake_parse_arguments(ARG "${options}" "${oneValArgs}" "${multiValArgs}" ${ARGN})
+
+ if (ARG_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "Unexpected arguments to hdf_add_signing_command: ${ARG_UNPARSED_ARGUMENTS}")
+ endif()
+
+ if (NOT APPLE AND NOT WIN32)
+ message(FATAL_ERROR "hdf_add_signing_command called on unsupported platform - platform=${CMAKE_SYSTEM_NAME}, target=${target}")
+ endif()
+
+ if (NOT ARG_FILE)
+ set(ARG_FILE $<TARGET_FILE:${target}>)
+ endif()
+
+ add_custom_command(
+ TARGET ${target}
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -P ${HDF_PLUGIN_SOURCE_DIR}/cmake/SignFile.cmake ${ARG_FILE}
+ COMMENT "Signing ${target}"
+ )
+endfunction()
diff --git a/cmake/asan-wrapper b/cmake/asan-wrapper
new file mode 100755
index 0000000..5d54103
--- /dev/null
+++ b/cmake/asan-wrapper
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+# The MIT License (MIT)
+#
+# Copyright (c)
+# 2013 Matthew Arsenault
+# 2015-2016 RWTH Aachen University, Federal Republic of Germany
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+# This script is a wrapper for AddressSanitizer. In some special cases you need
+# to preload AddressSanitizer to avoid error messages - e.g. if you're
+# preloading another library to your application. At the moment this script will
+# only do something, if we're running on a Linux platform. OSX might not be
+# affected.
+
+
+# Exit immediately, if platform is not Linux.
+if [ "$(uname)" != "Linux" ]
+then
+ exec $@
+fi
+
+
+# Get the used libasan of the application ($1). If a libasan was found, it will
+# be prepended to LD_PRELOAD.
+libasan=$(ldd $1 | grep libasan | sed "s/^[[:space:]]//" | cut -d' ' -f1)
+if [ -n "$libasan" ]
+then
+ if [ -n "$LD_PRELOAD" ]
+ then
+ export LD_PRELOAD="$libasan:$LD_PRELOAD"
+ else
+ export LD_PRELOAD="$libasan"
+ fi
+fi
+
+# Execute the application.
+exec $@
diff --git a/cmake/conan.cmake b/cmake/conan.cmake
new file mode 100644
index 0000000..1bd1289
--- /dev/null
+++ b/cmake/conan.cmake
@@ -0,0 +1,574 @@
+# The MIT License (MIT)
+
+# Copyright (c) 2018 JFrog
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+
+
+# This file comes from: https://github.com/conan-io/cmake-conan. Please refer
+# to this repository for issues and documentation.
+
+# Its purpose is to wrap and launch Conan C/C++ Package Manager when cmake is called.
+# It will take CMake current settings (os, compiler, compiler version, architecture)
+# and translate them to conan settings for installing and retrieving dependencies.
+
+# It is intended to facilitate developers building projects that have conan dependencies,
+# but it is only necessary on the end-user side. It is not necessary to create conan
+# packages, in fact it shouldn't be use for that. Check the project documentation.
+
+
+include(CMakeParseArguments)
+
+function(_get_msvc_ide_version result)
+ set(${result} "" PARENT_SCOPE)
+ if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500)
+ set(${result} 8 PARENT_SCOPE)
+ elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600)
+ set(${result} 9 PARENT_SCOPE)
+ elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700)
+ set(${result} 10 PARENT_SCOPE)
+ elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800)
+ set(${result} 11 PARENT_SCOPE)
+ elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900)
+ set(${result} 12 PARENT_SCOPE)
+ elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910)
+ set(${result} 14 PARENT_SCOPE)
+ elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920)
+ set(${result} 15 PARENT_SCOPE)
+ elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930)
+ set(${result} 16 PARENT_SCOPE)
+ else()
+ message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]")
+ endif()
+endfunction()
+
+function(conan_cmake_settings result)
+ #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER})
+ #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER_ID})
+ #message(STATUS "VERSION " ${CMAKE_CXX_COMPILER_VERSION})
+ #message(STATUS "FLAGS " ${CMAKE_LANG_FLAGS})
+ #message(STATUS "LIB ARCH " ${CMAKE_CXX_LIBRARY_ARCHITECTURE})
+ #message(STATUS "BUILD TYPE " ${CMAKE_BUILD_TYPE})
+ #message(STATUS "GENERATOR " ${CMAKE_GENERATOR})
+ #message(STATUS "GENERATOR WIN64 " ${CMAKE_CL_64})
+
+ message(STATUS "Conan: Automatic detection of conan settings from cmake")
+
+ parse_arguments(${ARGV})
+
+ if(ARGUMENTS_BUILD_TYPE)
+ set(_CONAN_SETTING_BUILD_TYPE ${ARGUMENTS_BUILD_TYPE})
+ elseif(CMAKE_BUILD_TYPE)
+ set(_CONAN_SETTING_BUILD_TYPE ${CMAKE_BUILD_TYPE})
+ else()
+ message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)")
+ endif()
+
+ string(TOUPPER ${_CONAN_SETTING_BUILD_TYPE} _CONAN_SETTING_BUILD_TYPE_UPPER)
+ if (_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "DEBUG")
+ set(_CONAN_SETTING_BUILD_TYPE "Debug")
+ elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELEASE")
+ set(_CONAN_SETTING_BUILD_TYPE "Release")
+ elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELWITHDEBINFO")
+ set(_CONAN_SETTING_BUILD_TYPE "RelWithDebInfo")
+ elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "MINSIZEREL")
+ set(_CONAN_SETTING_BUILD_TYPE "MinSizeRel")
+ endif()
+
+ if(ARGUMENTS_ARCH)
+ set(_CONAN_SETTING_ARCH ${ARGUMENTS_ARCH})
+ endif()
+ #handle -s os setting
+ if(CMAKE_SYSTEM_NAME)
+ #use default conan os setting if CMAKE_SYSTEM_NAME is not defined
+ set(CONAN_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
+ if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+ set(CONAN_SYSTEM_NAME Macos)
+ endif()
+ set(CONAN_SUPPORTED_PLATFORMS Windows Linux Macos Android iOS FreeBSD WindowsStore)
+ list (FIND CONAN_SUPPORTED_PLATFORMS "${CONAN_SYSTEM_NAME}" _index)
+ if (${_index} GREATER -1)
+ #check if the cmake system is a conan supported one
+ set(_CONAN_SETTING_OS ${CONAN_SYSTEM_NAME})
+ else()
+ message(FATAL_ERROR "cmake system ${CONAN_SYSTEM_NAME} is not supported by conan. Use one of ${CONAN_SUPPORTED_PLATFORMS}")
+ endif()
+ endif()
+
+ get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
+ if (";${_languages};" MATCHES ";CXX;")
+ set(LANGUAGE CXX)
+ set(USING_CXX 1)
+ elseif (";${_languages};" MATCHES ";C;")
+ set(LANGUAGE C)
+ set(USING_CXX 0)
+ else ()
+ message(FATAL_ERROR "Conan: Neither C or C++ was detected as a language for the project. Unabled to detect compiler version.")
+ endif()
+
+ if (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU)
+ # using GCC
+ # TODO: Handle other params
+ string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION})
+ list(GET VERSION_LIST 0 MAJOR)
+ list(GET VERSION_LIST 1 MINOR)
+ set(COMPILER_VERSION ${MAJOR}.${MINOR})
+ if(${MAJOR} GREATER 4)
+ set(COMPILER_VERSION ${MAJOR})
+ endif()
+ set(_CONAN_SETTING_COMPILER gcc)
+ set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION})
+ if (USING_CXX)
+ conan_cmake_detect_unix_libcxx(_LIBCXX)
+ set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX})
+ endif ()
+ elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang)
+ # using AppleClang
+ string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION})
+ list(GET VERSION_LIST 0 MAJOR)
+ list(GET VERSION_LIST 1 MINOR)
+ set(_CONAN_SETTING_COMPILER apple-clang)
+ set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR})
+ if (USING_CXX)
+ conan_cmake_detect_unix_libcxx(_LIBCXX)
+ set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX})
+ endif ()
+ elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang)
+ string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION})
+ list(GET VERSION_LIST 0 MAJOR)
+ list(GET VERSION_LIST 1 MINOR)
+ set(_CONAN_SETTING_COMPILER clang)
+ set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR})
+ if(APPLE)
+ cmake_policy(GET CMP0025 APPLE_CLANG_POLICY_ENABLED)
+ if(NOT APPLE_CLANG_POLICY_ENABLED)
+ message(STATUS "Conan: APPLE and Clang detected. Assuming apple-clang compiler. Set CMP0025 to avoid it")
+ set(_CONAN_SETTING_COMPILER apple-clang)
+ endif()
+ endif()
+ if(${_CONAN_SETTING_COMPILER} STREQUAL clang AND ${MAJOR} GREATER 7)
+ set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR})
+ endif()
+ if (USING_CXX)
+ conan_cmake_detect_unix_libcxx(_LIBCXX)
+ set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX})
+ endif ()
+ elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL MSVC)
+ set(_VISUAL "Visual Studio")
+ _get_msvc_ide_version(_VISUAL_VERSION)
+ if("${_VISUAL_VERSION}" STREQUAL "")
+ message(FATAL_ERROR "Conan: Visual Studio not recognized")
+ else()
+ set(_CONAN_SETTING_COMPILER ${_VISUAL})
+ set(_CONAN_SETTING_COMPILER_VERSION ${_VISUAL_VERSION})
+ endif()
+
+ if(NOT _CONAN_SETTING_ARCH)
+ if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64")
+ set(_CONAN_SETTING_ARCH x86_64)
+ elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM")
+ message(STATUS "Conan: Using default ARM architecture from MSVC")
+ set(_CONAN_SETTING_ARCH armv6)
+ elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86")
+ set(_CONAN_SETTING_ARCH x86)
+ else ()
+ message(FATAL_ERROR "Conan: Unknown MSVC architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]")
+ endif()
+ endif()
+
+ conan_cmake_detect_vs_runtime(_vs_runtime)
+ message(STATUS "Conan: Detected VS runtime: ${_vs_runtime}")
+ set(_CONAN_SETTING_COMPILER_RUNTIME ${_vs_runtime})
+
+ if (CMAKE_GENERATOR_TOOLSET)
+ set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET})
+ elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja"))
+ set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET})
+ endif()
+ # Temp fix due to https://github.com/conan-io/cmake-conan/issues/166
+ elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Intel)
+ string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION})
+ list(GET VERSION_LIST 0 MAJOR)
+ list(GET VERSION_LIST 1 MINOR)
+ set(COMPILER_VERSION ${MAJOR}.${MINOR})
+ set(_CONAN_SETTING_COMPILER icc)
+ set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION})
+ set(_SETTINGS ${_SETTINGS} -s compiler=icc -s compiler.version=${COMPILER_VERSION})
+ if (USING_CXX)
+ conan_cmake_detect_unix_libcxx(_LIBCXX)
+ set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX})
+ endif ()
+ else()
+ message(FATAL_ERROR "Conan: compiler setup not recognized")
+ endif()
+
+ # If profile is defined it is used
+ if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ARGUMENTS_DEBUG_PROFILE)
+ set(_APPLIED_PROFILES ${ARGUMENTS_DEBUG_PROFILE})
+ elseif(CMAKE_BUILD_TYPE STREQUAL "Release" AND ARGUMENTS_RELEASE_PROFILE)
+ set(_APPLIED_PROFILES ${ARGUMENTS_RELEASE_PROFILE})
+ elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND ARGUMENTS_RELWITHDEBINFO_PROFILE)
+ set(_APPLIED_PROFILES ${ARGUMENTS_RELWITHDEBINFO_PROFILE})
+ elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" AND ARGUMENTS_MINSIZEREL_PROFILE)
+ set(_APPLIED_PROFILES ${ARGUMENTS_MINSIZEREL_PROFILE})
+ elseif(ARGUMENTS_PROFILE)
+ set(_APPLIED_PROFILES ${ARGUMENTS_PROFILE})
+ endif()
+
+ foreach(ARG ${_APPLIED_PROFILES})
+ set(_SETTINGS ${_SETTINGS} -pr ${ARG})
+ endforeach()
+
+ if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL")
+ set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version
+ compiler.runtime compiler.libcxx compiler.toolset)
+ endif()
+
+ # Automatic from CMake
+ foreach(ARG ${ARGUMENTS_PROFILE_AUTO})
+ string(TOUPPER ${ARG} _arg_name)
+ string(REPLACE "." "_" _arg_name ${_arg_name})
+ if(_CONAN_SETTING_${_arg_name})
+ set(_SETTINGS ${_SETTINGS} -s ${ARG}=${_CONAN_SETTING_${_arg_name}})
+ endif()
+ endforeach()
+
+ foreach(ARG ${ARGUMENTS_SETTINGS})
+ set(_SETTINGS ${_SETTINGS} -s ${ARG})
+ endforeach()
+
+ message(STATUS "Conan: Settings= ${_SETTINGS}")
+
+ set(${result} ${_SETTINGS} PARENT_SCOPE)
+endfunction()
+
+
+function(conan_cmake_detect_unix_libcxx result)
+ set(compile_options)
+
+ # Take into account any -stdlib in compile options
+ get_directory_property(options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS)
+ foreach(option ${options})
+ if(option MATCHES "^-std")
+ set(compile_options ${compile_options} "${option}")
+ endif()
+ endforeach()
+
+ # Take into account any _GLIBCXX_USE_CXX11_ABI in compile definitions
+ get_directory_property(defines DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS)
+ foreach(define ${defines})
+ if(define MATCHES "_GLIBCXX_USE_CXX11_ABI")
+ if(define MATCHES "^-D")
+ set(compile_options ${compile_options} "${define}")
+ else()
+ set(compile_options ${compile_options} "-D${define}")
+ endif()
+ endif()
+ endforeach()
+
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
+ COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM -
+ OUTPUT_VARIABLE string_defines
+ )
+
+ if(string_defines MATCHES "#define __GLIBCXX__")
+ # Allow -D_GLIBCXX_USE_CXX11_ABI=ON/OFF as argument to cmake
+ if(DEFINED _GLIBCXX_USE_CXX11_ABI)
+ if(_GLIBCXX_USE_CXX11_ABI)
+ set(${result} libstdc++11 PARENT_SCOPE)
+ return()
+ else()
+ set(${result} libstdc++ PARENT_SCOPE)
+ return()
+ endif()
+ endif()
+
+ if(string_defines MATCHES "#define _GLIBCXX_USE_CXX11_ABI 1\n")
+ set(${result} libstdc++11 PARENT_SCOPE)
+ else()
+ # Either the compiler is missing the define because it is old, and so
+ # it can't use the new abi, or the compiler was configured to use the
+ # old abi by the user or distro (e.g. devtoolset on RHEL/CentOS)
+ set(${result} libstdc++ PARENT_SCOPE)
+ endif()
+ else()
+ set(${result} libc++ PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(conan_cmake_detect_vs_runtime result)
+ string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
+ set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
+ foreach(variable ${variables})
+ string(REPLACE " " ";" flags "${${variable}}")
+ foreach (flag ${flags})
+ if(${flag} STREQUAL "/MD" OR ${flag} STREQUAL "/MDd" OR ${flag} STREQUAL "/MT" OR ${flag} STREQUAL "/MTd")
+ string(SUBSTRING ${flag} 1 -1 runtime)
+ set(${result} ${runtime} PARENT_SCOPE)
+ return()
+ endif()
+ endforeach()
+ endforeach()
+ if(${build_type} STREQUAL "DEBUG")
+ set(${result} "MDd" PARENT_SCOPE)
+ else()
+ set(${result} "MD" PARENT_SCOPE)
+ endif()
+endfunction()
+
+
+macro(parse_arguments)
+ set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS)
+ set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND)
+ set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE
+ PROFILE REQUIRES OPTIONS IMPORTS SETTINGS BUILD ENV GENERATORS PROFILE_AUTO
+ INSTALL_ARGS)
+ cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+endmacro()
+
+function(conan_cmake_install)
+ # Calls "conan install"
+ # Argument BUILD is equivalant to --build={missing, PkgName,...} or
+ # --build when argument is 'BUILD all' (which builds all packages from source)
+ # Argument CONAN_COMMAND, to specify the conan path, e.g. in case of running from source
+ # cmake does not identify conan as command, even if it is +x and it is in the path
+ parse_arguments(${ARGV})
+
+ if(CONAN_CMAKE_MULTI)
+ set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake_multi)
+ else()
+ set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake)
+ endif()
+
+ set(CONAN_BUILD_POLICY "")
+ foreach(ARG ${ARGUMENTS_BUILD})
+ if(${ARG} STREQUAL "all")
+ set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build)
+ break()
+ else()
+ set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build=${ARG})
+ endif()
+ endforeach()
+ if(ARGUMENTS_CONAN_COMMAND)
+ set(conan_command ${ARGUMENTS_CONAN_COMMAND})
+ else()
+ set(conan_command conan)
+ endif()
+ set(CONAN_OPTIONS "")
+ if(ARGUMENTS_CONANFILE)
+ set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE})
+ # A conan file has been specified - apply specified options as well if provided
+ foreach(ARG ${ARGUMENTS_OPTIONS})
+ set(CONAN_OPTIONS ${CONAN_OPTIONS} -o=${ARG})
+ endforeach()
+ else()
+ set(CONANFILE ".")
+ endif()
+ if(ARGUMENTS_UPDATE)
+ set(CONAN_INSTALL_UPDATE --update)
+ endif()
+ if(ARGUMENTS_NO_IMPORTS)
+ set(CONAN_INSTALL_NO_IMPORTS --no-imports)
+ endif()
+ set(CONAN_INSTALL_FOLDER "")
+ if(ARGUMENTS_INSTALL_FOLDER)
+ set(CONAN_INSTALL_FOLDER -if=${ARGUMENTS_INSTALL_FOLDER})
+ endif()
+ foreach(ARG ${ARGUMENTS_GENERATORS})
+ set(CONAN_GENERATORS ${CONAN_GENERATORS} -g=${ARG})
+ endforeach()
+ foreach(ARG ${ARGUMENTS_ENV})
+ set(CONAN_ENV_VARS ${CONAN_ENV_VARS} -e=${ARG})
+ endforeach()
+ set(conan_args install ${CONANFILE} ${settings} ${CONAN_ENV_VARS} ${CONAN_GENERATORS} ${CONAN_BUILD_POLICY} ${CONAN_INSTALL_UPDATE} ${CONAN_INSTALL_NO_IMPORTS} ${CONAN_OPTIONS} ${CONAN_INSTALL_FOLDER} ${ARGUMENTS_INSTALL_ARGS})
+
+ string (REPLACE ";" " " _conan_args "${conan_args}")
+ message(STATUS "Conan executing: ${conan_command} ${_conan_args}")
+
+ if(ARGUMENTS_OUTPUT_QUIET)
+ execute_process(COMMAND ${conan_command} ${conan_args}
+ RESULT_VARIABLE return_code
+ OUTPUT_VARIABLE conan_output
+ ERROR_VARIABLE conan_output
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ else()
+ execute_process(COMMAND ${conan_command} ${conan_args}
+ RESULT_VARIABLE return_code
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ endif()
+
+ if(NOT "${return_code}" STREQUAL "0")
+ message(FATAL_ERROR "Conan install failed='${return_code}'")
+ endif()
+
+endfunction()
+
+
+function(conan_cmake_setup_conanfile)
+ parse_arguments(${ARGV})
+ if(ARGUMENTS_CONANFILE)
+ get_filename_component(_CONANFILE_NAME ${ARGUMENTS_CONANFILE} NAME)
+ # configure_file will make sure cmake re-runs when conanfile is updated
+ configure_file(${ARGUMENTS_CONANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk)
+ file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk)
+ else()
+ conan_cmake_generate_conanfile(${ARGV})
+ endif()
+endfunction()
+
+function(conan_cmake_generate_conanfile)
+ # Generate, writing in disk a conanfile.txt with the requires, options, and imports
+ # specified as arguments
+ # This will be considered as temporary file, generated in CMAKE_CURRENT_BINARY_DIR)
+ parse_arguments(${ARGV})
+ set(_FN "${CMAKE_CURRENT_BINARY_DIR}/conanfile.txt")
+
+ file(WRITE ${_FN} "[generators]\ncmake\n\n[requires]\n")
+ foreach(ARG ${ARGUMENTS_REQUIRES})
+ file(APPEND ${_FN} ${ARG} "\n")
+ endforeach()
+
+ file(APPEND ${_FN} ${ARG} "\n[options]\n")
+ foreach(ARG ${ARGUMENTS_OPTIONS})
+ file(APPEND ${_FN} ${ARG} "\n")
+ endforeach()
+
+ file(APPEND ${_FN} ${ARG} "\n[imports]\n")
+ foreach(ARG ${ARGUMENTS_IMPORTS})
+ file(APPEND ${_FN} ${ARG} "\n")
+ endforeach()
+endfunction()
+
+
+macro(conan_load_buildinfo)
+ if(CONAN_CMAKE_MULTI)
+ set(_CONANBUILDINFO conanbuildinfo_multi.cmake)
+ else()
+ set(_CONANBUILDINFO conanbuildinfo.cmake)
+ endif()
+ if(ARGUMENTS_INSTALL_FOLDER)
+ set(_CONANBUILDINFOFOLDER ${ARGUMENTS_INSTALL_FOLDER})
+ else()
+ set(_CONANBUILDINFOFOLDER ${CMAKE_CURRENT_BINARY_DIR})
+ endif()
+ # Checks for the existence of conanbuildinfo.cmake, and loads it
+ # important that it is macro, so variables defined at parent scope
+ if(EXISTS "${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}")
+ message(STATUS "Conan: Loading ${_CONANBUILDINFO}")
+ include(${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO})
+ else()
+ message(FATAL_ERROR "${_CONANBUILDINFO} doesn't exist in ${CMAKE_CURRENT_BINARY_DIR}")
+ endif()
+endmacro()
+
+
+macro(conan_cmake_run)
+ parse_arguments(${ARGV})
+
+ if(CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE AND NOT CONAN_EXPORTED
+ AND NOT ARGUMENTS_BUILD_TYPE)
+ set(CONAN_CMAKE_MULTI ON)
+ message(STATUS "Conan: Using cmake-multi generator")
+ else()
+ set(CONAN_CMAKE_MULTI OFF)
+ endif()
+
+ if(NOT CONAN_EXPORTED)
+ conan_cmake_setup_conanfile(${ARGV})
+ if(CONAN_CMAKE_MULTI)
+ foreach(CMAKE_BUILD_TYPE "Release" "Debug")
+ set(ENV{CONAN_IMPORT_PATH} ${CMAKE_BUILD_TYPE})
+ conan_cmake_settings(settings ${ARGV})
+ conan_cmake_install(SETTINGS ${settings} ${ARGV})
+ endforeach()
+ set(CMAKE_BUILD_TYPE)
+ else()
+ conan_cmake_settings(settings ${ARGV})
+ conan_cmake_install(SETTINGS ${settings} ${ARGV})
+ endif()
+ endif()
+
+ if (NOT ARGUMENTS_NO_LOAD)
+ conan_load_buildinfo()
+ endif()
+
+ if(ARGUMENTS_BASIC_SETUP)
+ foreach(_option CMAKE_TARGETS KEEP_RPATHS NO_OUTPUT_DIRS)
+ if(ARGUMENTS_${_option})
+ if(${_option} STREQUAL "CMAKE_TARGETS")
+ list(APPEND _setup_options "TARGETS")
+ else()
+ list(APPEND _setup_options ${_option})
+ endif()
+ endif()
+ endforeach()
+ conan_basic_setup(${_setup_options})
+ endif()
+endmacro()
+
+macro(conan_check)
+ # Checks conan availability in PATH
+ # Arguments REQUIRED and VERSION are optional
+ # Example usage:
+ # conan_check(VERSION 1.0.0 REQUIRED)
+ message(STATUS "Conan: checking conan executable in path")
+ set(options REQUIRED)
+ set(oneValueArgs VERSION)
+ cmake_parse_arguments(CONAN "${options}" "${oneValueArgs}" "" ${ARGN})
+
+ find_program(CONAN_CMD conan)
+ if(NOT CONAN_CMD AND CONAN_REQUIRED)
+ message(FATAL_ERROR "Conan executable not found!")
+ endif()
+ message(STATUS "Conan: Found program ${CONAN_CMD}")
+ execute_process(COMMAND ${CONAN_CMD} --version
+ OUTPUT_VARIABLE CONAN_VERSION_OUTPUT
+ ERROR_VARIABLE CONAN_VERSION_OUTPUT)
+ message(STATUS "Conan: Version found ${CONAN_VERSION_OUTPUT}")
+
+ if(DEFINED CONAN_VERSION)
+ string(REGEX MATCH ".*Conan version ([0-9]+\.[0-9]+\.[0-9]+)" FOO
+ "${CONAN_VERSION_OUTPUT}")
+ if(${CMAKE_MATCH_1} VERSION_LESS ${CONAN_VERSION})
+ message(FATAL_ERROR "Conan outdated. Installed: ${CMAKE_MATCH_1}, \
+ required: ${CONAN_VERSION}. Consider updating via 'pip \
+ install conan==${CONAN_VERSION}'.")
+ endif()
+ endif()
+endmacro()
+
+macro(conan_add_remote)
+ # Adds a remote
+ # Arguments URL and NAME are required, INDEX is optional
+ # Example usage:
+ # conan_add_remote(NAME bincrafters INDEX 1
+ # URL https://api.bintray.com/conan/bincrafters/public-conan)
+ set(oneValueArgs URL NAME INDEX)
+ cmake_parse_arguments(CONAN "" "${oneValueArgs}" "" ${ARGN})
+
+ if(DEFINED CONAN_INDEX)
+ set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}")
+ endif()
+
+ message(STATUS "Conan: Adding ${CONAN_NAME} remote repository (${CONAN_URL})")
+ execute_process(COMMAND ${CONAN_CMD} remote add ${CONAN_NAME} ${CONAN_URL}
+ ${CONAN_INDEX_ARG} -f)
+endmacro()
diff --git a/cmake/sanitize-helpers.cmake b/cmake/sanitize-helpers.cmake
new file mode 100755
index 0000000..3649b07
--- /dev/null
+++ b/cmake/sanitize-helpers.cmake
@@ -0,0 +1,177 @@
+# The MIT License (MIT)
+#
+# Copyright (c)
+# 2013 Matthew Arsenault
+# 2015-2016 RWTH Aachen University, Federal Republic of Germany
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+# Helper function to get the language of a source file.
+function (sanitizer_lang_of_source FILE RETURN_VAR)
+ get_filename_component(LONGEST_EXT "${FILE}" EXT)
+ # If extension is empty return. This can happen for extensionless headers
+ if("${LONGEST_EXT}" STREQUAL "")
+ set(${RETURN_VAR} "" PARENT_SCOPE)
+ return()
+ endif()
+ # Get shortest extension as some files can have dot in their names
+ string(REGEX REPLACE "^.*(\\.[^.]+)$" "\\1" FILE_EXT ${LONGEST_EXT})
+ string(TOLOWER "${FILE_EXT}" FILE_EXT)
+ string(SUBSTRING "${FILE_EXT}" 1 -1 FILE_EXT)
+
+ get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
+ foreach (LANG ${ENABLED_LANGUAGES})
+ list(FIND CMAKE_${LANG}_SOURCE_FILE_EXTENSIONS "${FILE_EXT}" TEMP)
+ if (NOT ${TEMP} EQUAL -1)
+ set(${RETURN_VAR} "${LANG}" PARENT_SCOPE)
+ return()
+ endif ()
+ endforeach()
+
+ set(${RETURN_VAR} "" PARENT_SCOPE)
+endfunction ()
+
+
+# Helper function to get compilers used by a target.
+function (sanitizer_target_compilers TARGET RETURN_VAR)
+ # Check if all sources for target use the same compiler. If a target uses
+ # e.g. C and Fortran mixed and uses different compilers (e.g. clang and
+ # gfortran) this can trigger huge problems, because different compilers may
+ # use different implementations for sanitizers.
+ set(BUFFER "")
+ get_target_property(TSOURCES ${TARGET} SOURCES)
+ foreach (FILE ${TSOURCES})
+ # If expression was found, FILE is a generator-expression for an object
+ # library. Object libraries will be ignored.
+ string(REGEX MATCH "TARGET_OBJECTS:([^ >]+)" _file ${FILE})
+ if ("${_file}" STREQUAL "")
+ sanitizer_lang_of_source(${FILE} LANG)
+ if (LANG)
+ list(APPEND BUFFER ${CMAKE_${LANG}_COMPILER_ID})
+ endif ()
+ endif ()
+ endforeach ()
+
+ list(REMOVE_DUPLICATES BUFFER)
+ set(${RETURN_VAR} "${BUFFER}" PARENT_SCOPE)
+endfunction ()
+
+
+# Helper function to check compiler flags for language compiler.
+function (sanitizer_check_compiler_flag FLAG LANG VARIABLE)
+ if (${LANG} STREQUAL "C")
+ include(CheckCCompilerFlag)
+ check_c_compiler_flag("${FLAG}" ${VARIABLE})
+
+ elseif (${LANG} STREQUAL "CXX")
+ include(CheckCXXCompilerFlag)
+ check_cxx_compiler_flag("${FLAG}" ${VARIABLE})
+
+ elseif (${LANG} STREQUAL "Fortran")
+ # CheckFortranCompilerFlag was introduced in CMake 3.x. To be compatible
+ # with older Cmake versions, we will check if this module is present
+ # before we use it. Otherwise we will define Fortran coverage support as
+ # not available.
+ include(CheckFortranCompilerFlag OPTIONAL RESULT_VARIABLE INCLUDED)
+ if (INCLUDED)
+ check_fortran_compiler_flag("${FLAG}" ${VARIABLE})
+ elseif (NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Performing Test ${VARIABLE}")
+ message(STATUS "Performing Test ${VARIABLE}"
+ " - Failed (Check not supported)")
+ endif ()
+ endif()
+endfunction ()
+
+
+# Helper function to test compiler flags.
+function (sanitizer_check_compiler_flags FLAG_CANDIDATES NAME PREFIX)
+ set(CMAKE_REQUIRED_QUIET ${${PREFIX}_FIND_QUIETLY})
+
+ get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
+ foreach (LANG ${ENABLED_LANGUAGES})
+ # Sanitizer flags are not dependend on language, but the used compiler.
+ # So instead of searching flags foreach language, search flags foreach
+ # compiler used.
+ set(COMPILER ${CMAKE_${LANG}_COMPILER_ID})
+ if (NOT DEFINED ${PREFIX}_${COMPILER}_FLAGS)
+ foreach (FLAG ${FLAG_CANDIDATES})
+ if(NOT CMAKE_REQUIRED_QUIET)
+ message(STATUS "Try ${COMPILER} ${NAME} flag = [${FLAG}]")
+ endif()
+
+ set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+ unset(${PREFIX}_FLAG_DETECTED CACHE)
+ sanitizer_check_compiler_flag("${FLAG}" ${LANG}
+ ${PREFIX}_FLAG_DETECTED)
+
+ if (${PREFIX}_FLAG_DETECTED)
+ # If compiler is a GNU compiler, search for static flag, if
+ # SANITIZE_LINK_STATIC is enabled.
+ if (SANITIZE_LINK_STATIC AND (${COMPILER} STREQUAL "GNU"))
+ string(TOLOWER ${PREFIX} PREFIX_lower)
+ sanitizer_check_compiler_flag(
+ "-static-lib${PREFIX_lower}" ${LANG}
+ ${PREFIX}_STATIC_FLAG_DETECTED)
+
+ if (${PREFIX}_STATIC_FLAG_DETECTED)
+ set(FLAG "-static-lib${PREFIX_lower} ${FLAG}")
+ endif ()
+ endif ()
+
+ set(${PREFIX}_${COMPILER}_FLAGS "${FLAG}" CACHE STRING
+ "${NAME} flags for ${COMPILER} compiler.")
+ mark_as_advanced(${PREFIX}_${COMPILER}_FLAGS)
+ break()
+ endif ()
+ endforeach ()
+
+ if (NOT ${PREFIX}_FLAG_DETECTED)
+ set(${PREFIX}_${COMPILER}_FLAGS "" CACHE STRING
+ "${NAME} flags for ${COMPILER} compiler.")
+ mark_as_advanced(${PREFIX}_${COMPILER}_FLAGS)
+
+ message(WARNING "${NAME} is not available for ${COMPILER} "
+ "compiler. Targets using this compiler will be "
+ "compiled without ${NAME}.")
+ endif ()
+ endif ()
+ endforeach ()
+endfunction ()
+
+
+# Helper to assign sanitizer flags for TARGET.
+function (sanitizer_add_flags TARGET NAME PREFIX)
+ # Get list of compilers used by target and check, if sanitizer is available
+ # for this target. Other compiler checks like check for conflicting
+ # compilers will be done in add_sanitizers function.
+ sanitizer_target_compilers(${TARGET} TARGET_COMPILER)
+ list(LENGTH TARGET_COMPILER NUM_COMPILERS)
+ if ("${${PREFIX}_${TARGET_COMPILER}_FLAGS}" STREQUAL "")
+ return()
+ endif()
+
+ # Set compile- and link-flags for target.
+ set_property(TARGET ${TARGET} APPEND_STRING
+ PROPERTY COMPILE_FLAGS " ${${PREFIX}_${TARGET_COMPILER}_FLAGS}")
+ set_property(TARGET ${TARGET} APPEND_STRING
+ PROPERTY COMPILE_FLAGS " ${SanBlist_${TARGET_COMPILER}_FLAGS}")
+ set_property(TARGET ${TARGET} APPEND_STRING
+ PROPERTY LINK_FLAGS " ${${PREFIX}_${TARGET_COMPILER}_FLAGS}")
+endfunction ()
diff --git a/images/ONT_logo_590x106.png b/images/ONT_logo_590x106.png
new file mode 100644
index 0000000..a9989ef
--- /dev/null
+++ b/images/ONT_logo_590x106.png
Binary files differ
diff --git a/images/vbz_compression_ratio.png b/images/vbz_compression_ratio.png
new file mode 100644
index 0000000..ecb69e4
--- /dev/null
+++ b/images/vbz_compression_ratio.png
Binary files differ
diff --git a/images/vbz_x86_compression.png b/images/vbz_x86_compression.png
new file mode 100644
index 0000000..519e230
--- /dev/null
+++ b/images/vbz_x86_compression.png
Binary files differ
diff --git a/images/vbz_x86_decompression.png b/images/vbz_x86_decompression.png
new file mode 100644
index 0000000..247a09d
--- /dev/null
+++ b/images/vbz_x86_decompression.png
Binary files differ
diff --git a/packaging/hdf_plugin_packaging.cmake b/packaging/hdf_plugin_packaging.cmake
new file mode 100644
index 0000000..bfe6d45
--- /dev/null
+++ b/packaging/hdf_plugin_packaging.cmake
@@ -0,0 +1,107 @@
+include(CPackComponent)
+
+set(CPACK_PACKAGE_NAME ont-vbz-hdf-plugin)
+set(CPACK_PACKAGE_VENDOR "nanoporetech")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
+
+if (NOT VBZ_BUILD_ARCHIVE)
+ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/packaging/readme.txt")
+ set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/packaging/readme.txt")
+ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENCE.txt")
+
+ cpack_add_component(
+ hdf_plugin
+ DISPLAYNAME "Hdf5 Plugin"
+ GROUP HDF_PLUGIN)
+
+ set(CPACK_COMPONENTS_ALL hdf_plugin)
+
+ if (NOT HDF5_PLUGIN_PATH)
+ IF (WIN32)
+ set(HDF5_PLUGIN_PATH "C:/ProgramData/hdf5/lib/plugin")
+ else()
+ set(HDF5_PLUGIN_PATH "/usr/local/hdf5/lib/plugin")
+ endif()
+ endif()
+
+endif()
+
+
+
+
+if (VBZ_BUILD_ARCHIVE)
+ set(CPACK_GENERATOR "TGZ")
+elseif (APPLE)
+ set(CPACK_GENERATOR "productbuild")
+ set(CPACK_PACKAGING_INSTALL_PREFIX "/Applications/OxfordNanopore/${CPACK_PACKAGE_NAME}/")
+
+ set(ONT_VBZ_PLUGIN_SOURCE_PATH "${CPACK_PACKAGING_INSTALL_PREFIX}/hdf5/lib/plugin/libvbz_hdf_plugin.dylib")
+ set(ONT_VBZ_PLUGIN_DEST_PATH "${HDF5_PLUGIN_PATH}/libvbz_hdf_plugin.dylib")
+
+ set(POSTFLIGHT_SCRIPT "${CMAKE_BINARY_DIR}/postinstall.sh")
+ configure_file(
+ "${CMAKE_SOURCE_DIR}/packaging/postinstall.sh.in"
+ "${POSTFLIGHT_SCRIPT}"
+ @ONLY
+ )
+
+ set(CPACK_POSTFLIGHT_HDF_PLUGIN_SCRIPT "${POSTFLIGHT_SCRIPT}")
+elseif (WIN32)
+ set(CPACK_GENERATOR "WIX")
+ set(CPACK_PACKAGE_VENDOR "Oxford Nanopore Technologies, Limited")
+ set(CPACK_WIX_PRODUCT_ICON "${CMAKE_SOURCE_DIR}/packaging/wix_nanopore_icon.ico")
+ set(CPACK_WIX_UI_DIALOG "${CMAKE_SOURCE_DIR}/packaging/wix_nanopore_background.bmp")
+ set(CPACK_WIX_UI_BANNER "${CMAKE_SOURCE_DIR}/packaging/wix_nanopore_banner.bmp")
+
+ if(VBZ_MSI_UPGRADE_CODE)
+ set(CPACK_WIX_UPGRADE_GUID "${VBZ_MSI_UPGRADE_CODE}")
+ endif()
+
+ set(WIX_SOURCE_FILE "${CMAKE_SOURCE_DIR}/packaging/wix_extra.wxs.in")
+ set(CPACK_WIX_EXTRA_SOURCES "${CMAKE_BINARY_DIR}/wix_extra.wxs")
+ set(CPACK_WIX_PATCH_FILE "${CMAKE_SOURCE_DIR}/packaging/wix_patch.wxs.xml")
+
+ install(CODE "
+ set(ONT_VBZ_PLUGIN_SOURCE_PATH \"${CMAKE_BINARY_DIR}/bin/\$\{CMAKE_INSTALL_CONFIG_NAME\}/vbz_hdf_plugin.dll\")
+ configure_file(
+ \"${WIX_SOURCE_FILE}\"
+ \"${CPACK_WIX_EXTRA_SOURCES}\"
+ @ONLY
+ )"
+ COMPONENT hdf_plugin
+ )
+
+ set(VBZ_INSTALLATION_PREFIX "OxfordNanopore/${CPACK_PACKAGE_NAME}")
+ set(CPACK_WIX_PROGRAM_MENU_FOLDER "${VBZ_INSTALLATION_PREFIX}")
+ set(CPACK_PACKAGE_INSTALL_DIRECTORY "${VBZ_INSTALLATION_PREFIX}")
+ set(CPACK_WIX_PROPERTY_ALLUSERS 1) # Install to everyone by default
+
+else()
+ set(CPACK_GENERATOR "DEB")
+ set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local/")
+
+ set(CPACK_DEB_PACKAGE_COMPONENT ON)
+ set(CPACK_DEB_COMPONENT_INSTALL ON)
+ find_program(DPKG dpkg)
+ execute_process(
+ COMMAND ${DPKG} --print-architecture # e.g. "amd64" or "arm64"
+ OUTPUT_VARIABLE DPKG_ARCHITECTURE
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+ find_program(LSB_RELEASE lsb_release)
+ execute_process(
+ COMMAND ${LSB_RELEASE} -cs # e.g. "trusty" or "xenial"
+ OUTPUT_VARIABLE LSB_PLATFORM_NAME
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+ set(CPACK_DEBIAN_PACKAGE_VERSION "${PROJECT_VERSION}-1~${LSB_PLATFORM_NAME}")
+
+ set(CPACK_DEBIAN_HDF_PLUGIN_PACKAGE_NAME ${CPACK_PACKAGE_NAME})
+ set(CPACK_DEBIAN_HDF_PLUGIN_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}_${DPKG_ARCHITECTURE}.deb")
+ set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
+ set(CPACK_DEBIAN_PACKAGE_MAINTAINER nanoporetech.com)
+endif()
+
+include(CPack) \ No newline at end of file
diff --git a/packaging/postinstall.sh.in b/packaging/postinstall.sh.in
new file mode 100644
index 0000000..77df8b5
--- /dev/null
+++ b/packaging/postinstall.sh.in
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+
+mkdir -p `dirname @ONT_VBZ_PLUGIN_DEST_PATH@`
+
+# Delete old link
+rm @ONT_VBZ_PLUGIN_DEST_PATH@ || true
+
+# Create new link
+ln -s "@ONT_VBZ_PLUGIN_SOURCE_PATH@" "@ONT_VBZ_PLUGIN_DEST_PATH@" \ No newline at end of file
diff --git a/packaging/postrm.sh.in b/packaging/postrm.sh.in
new file mode 100644
index 0000000..b3f5cf1
--- /dev/null
+++ b/packaging/postrm.sh.in
@@ -0,0 +1,4 @@
+#! /bin/bash
+set -e
+
+rm -f "@ONT_VBZ_PLUGIN_DEST_PATH@"
diff --git a/packaging/readme.txt b/packaging/readme.txt
new file mode 100644
index 0000000..98d1874
--- /dev/null
+++ b/packaging/readme.txt
@@ -0,0 +1,6 @@
+Oxford Nanopore VBZ hdf plugin
+==============================
+
+This package will install an hdf plugin which can read and write the nanopore vbz data format.
+
+Once installed hdf5 tools will automatically read vbz datasets. \ No newline at end of file
diff --git a/packaging/wix_extra.wxs.in b/packaging/wix_extra.wxs.in
new file mode 100644
index 0000000..9d74e6e
--- /dev/null
+++ b/packaging/wix_extra.wxs.in
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+ <Fragment>
+ <DirectoryRef Id="INSTALL_ROOT_PROGRAM_DATA">
+ <Component Id="INSTALL_ROOT_PROGRAM_DATA_PLUGIN" Guid="*">
+ <File Id="INSTALL_ROOT_PROGRAM_DATA_PLUGIN_DLL" Source="@ONT_VBZ_PLUGIN_SOURCE_PATH@" KeyPath="yes"/>
+ </Component>
+ </DirectoryRef>
+ </Fragment>
+</Wix> \ No newline at end of file
diff --git a/packaging/wix_nanopore_background.bmp b/packaging/wix_nanopore_background.bmp
new file mode 100644
index 0000000..30a8bbd
--- /dev/null
+++ b/packaging/wix_nanopore_background.bmp
Binary files differ
diff --git a/packaging/wix_nanopore_banner.bmp b/packaging/wix_nanopore_banner.bmp
new file mode 100644
index 0000000..11456c7
--- /dev/null
+++ b/packaging/wix_nanopore_banner.bmp
Binary files differ
diff --git a/packaging/wix_nanopore_icon.ico b/packaging/wix_nanopore_icon.ico
new file mode 100644
index 0000000..8ab69ab
--- /dev/null
+++ b/packaging/wix_nanopore_icon.ico
Binary files differ
diff --git a/packaging/wix_patch.wxs.xml b/packaging/wix_patch.wxs.xml
new file mode 100644
index 0000000..ab67723
--- /dev/null
+++ b/packaging/wix_patch.wxs.xml
@@ -0,0 +1,19 @@
+<CPackWiXPatch>
+
+ <CPackWiXFragment Id="#PRODUCT">
+ <DirectoryRef Id="TARGETDIR">
+ <Directory Id="CommonAppDataFolder">
+ <Directory Id="PLUGIN_INSTALL_PREFIX_1" Name="hdf5">
+ <Directory Id="PLUGIN_INSTALL_PREFIX_2" Name="lib">
+ <Directory Id="INSTALL_ROOT_PROGRAM_DATA" Name="plugin"/>
+ </Directory>
+ </Directory>
+ </Directory>
+ </DirectoryRef>
+ </CPackWiXFragment>
+
+ <CPackWiXFragment Id="#PRODUCTFEATURE">
+ <ComponentRef Id="INSTALL_ROOT_PROGRAM_DATA_PLUGIN" />
+ </CPackWiXFragment>
+
+</CPackWiXPatch>
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
new file mode 100644
index 0000000..5bf943b
--- /dev/null
+++ b/python/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(pyvbz) \ No newline at end of file
diff --git a/python/benchmark/benchmark.py b/python/benchmark/benchmark.py
new file mode 100644
index 0000000..b102595
--- /dev/null
+++ b/python/benchmark/benchmark.py
@@ -0,0 +1,99 @@
+import h5py
+import matplotlib.pyplot as plt
+import numpy
+import time
+
+import zstd
+
+
+def time_dataset(data, create_fn, target_time=0.1):
+ element_size = data.dtype.itemsize
+ total_time = 0
+ times = []
+ count = 0
+
+ for _ in range(1000):
+
+ begin = time.time()
+ with h5py.File("test_file.h5", "w") as f:
+ create_fn(f, "bar", data, element_size)
+ end = time.time()
+
+ count += 1
+ this_time = (end - begin)
+ times.append(this_time)
+ total_time += this_time
+
+ if total_time > target_time:
+ break
+
+ return sorted(times)[len(times)//2]
+
+def create_uncompressed(f, name, data, element_size):
+ f.create_dataset(name, data=data, chunks=(len(data),),)
+
+def create_vbz_zstd(f, name, data, element_size):
+ use_zig_zag = 1
+ f.create_dataset("bar", compression=32020, compression_opts=(0, element_size, use_zig_zag, 1), data=data, chunks=(len(data),))
+
+def create_vbz(f, name, data, element_size):
+ use_zig_zag = 1
+ f.create_dataset("bar", compression=32020, compression_opts=(0, element_size, use_zig_zag, 0), data=data, chunks=(len(data),))
+
+def create_zlib(f, name, data, element_size):
+ f.create_dataset("bar", compression="gzip", chunks=(len(data),), data=data)
+
+def create_zstd_raw(f, name, data, element_size):
+ zstd_data = numpy.frombuffer(zstd.compress(data), dtype="u1")
+ f.create_dataset("bar", chunks=(len(zstd_data),), data=zstd_data)
+
+
+if __name__ == "__main__":
+ plots = []
+ plot_names = []
+
+ palette = plt.get_cmap('Set1')
+
+ for m_i, method in enumerate([create_zstd_raw, create_vbz, create_vbz_zstd, create_zlib, create_uncompressed]):
+ data_types = ["i1", "i2", "i4"]
+ for d_i, data_type in enumerate(data_types):
+ size_to_times = []
+
+ for i in range(1,20):
+ size = 1000000 * i
+ data = numpy.random.randint(low=-50, high=50, size=size//int(data_type[1:]), dtype=data_type)
+ size_to_times.append((data.nbytes, time_dataset(data, method)))
+
+ print(size_to_times)
+ x = [e[0] for e in size_to_times]
+ y = [e[0]/e[1] for e in size_to_times]
+
+ c_index = m_i
+
+ plt.subplot(1, len(data_types), 1 + d_i)
+ plots.append(plt.plot(x, y, color=palette(c_index))[0])
+ plot_names.append("%s %s" % (method.__name__, data_type))
+
+ #ax = plt.axes()
+ #ax.grid()
+ #ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda v,_: format_size(v, "/s")))
+ #ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda v,_: format_size(v)))
+
+ plt.xlabel("block size (bytes)")
+ if d_i == 0:
+ plt.ylabel("Write speed (bytes/second)")
+ plt.legend(plots, plot_names)
+
+
+ def format_size(val, suffix=""):
+ units = ['bytes', 'KB', 'MB', 'GB']
+ divisor = 1000
+
+ unit_idx = 0
+ while val > divisor and unit_idx < len(units):
+ val /= divisor
+ unit_idx += 1
+
+ return '%.1f %s%s' % (val, units[unit_idx], suffix)
+
+ plt.show() \ No newline at end of file
diff --git a/python/fast5compress/fast5vbz.py b/python/fast5compress/fast5vbz.py
new file mode 100755
index 0000000..e655752
--- /dev/null
+++ b/python/fast5compress/fast5vbz.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+"""
+Fast5 compression filter for demonstrating vbz compression
+"""
+
+import os
+import h5py
+import argparse
+from shutil import copy2
+
+__version__ = "0.1.1"
+
+
+def compress_fast5(filename, output_suffix, vbz_version=0, decompress=False):
+ """
+ (De)compress the raw signal in the fast5
+ """
+ # create a copy of the input file for compressing
+ filename = os.path.abspath(filename)
+ out_filename = filename + output_suffix
+ copy2(filename, out_filename)
+
+ # open the copy and compress the signal datasets only
+ with h5py.File(out_filename, 'r+') as fast5:
+
+ if decompress:
+ compression_opts = {
+ "compression": "gzip", "compression_opts": 1
+ }
+ else:
+ compression_opts = {
+ "compression": 32020,
+ # 2 byte integers with zig zag + level 1 zstd
+ "compression_opts": (vbz_version, 2, 1, 1)
+ }
+
+ # multi read files
+ for read in fast5:
+ if not read.startswith("read_"):
+ continue
+
+ # read the signal dataset
+ group = '%s/Raw/' % read
+ raw = fast5[group]["Signal"][:]
+
+ # remove the dataset
+ del fast5[group]["Signal"]
+
+ # store the dataset with the new compression
+ fast5[group].create_dataset(
+ "Signal",
+ data=raw,
+ **compression_opts,
+ chunks=(len(raw),)
+ )
+
+ return out_filename
+
+
+def main(args, print_help):
+ for filename in args.files:
+ print(compress_fast5(filename, args.output_suffix, args.vbz_version, args.decompress))
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser("fast5compress")
+ parser.add_argument('files', nargs='*', help='input files')
+ parser.add_argument("-d", "--decompress", action="store_true", default=False)
+ parser.add_argument("-s", "--output-suffix", default=".tmp")
+ parser.add_argument('-v', '--version', action='version', version=__version__)
+ parser.add_argument('--vbz-version', type=int, default=1)
+ main(parser.parse_args(), parser.print_help)
diff --git a/python/pyvbz/CMakeLists.txt b/python/pyvbz/CMakeLists.txt
new file mode 100644
index 0000000..8585082
--- /dev/null
+++ b/python/pyvbz/CMakeLists.txt
@@ -0,0 +1,56 @@
+
+set(PYVBZ_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/pyvbz_cffi.touch")
+set(PYVBZ_BUILD_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/build_pyvbz.cmake")
+
+if (NOT PYTHON_EXECUTABLE)
+ find_package(PythonInterp 3)
+endif()
+
+add_custom_command(
+ OUTPUT "${PYVBZ_OUTPUT_PATH}"
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E env
+ PYTHON_EXE="${PYTHON_EXECUTABLE}"
+ PYVBZ_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
+ VBZ_BUILD_DIR="${CMAKE_BINARY_DIR}"
+ VBZ_INCLUDE_PATHS="${CMAKE_SOURCE_DIR}/vbz\;${CMAKE_BINARY_DIR}/vbz/"
+ VBZ_LINK_LIBS="$<TARGET_FILE:vbz>\;${STREAMVBYTE_STATIC_LIB}\;${ZSTD_LIBRARY}"
+ OUTPUT_FILE="${PYVBZ_OUTPUT_PATH}"
+ ${CMAKE_COMMAND}
+ -P "${PYVBZ_BUILD_SCRIPT}"
+ DEPENDS vbz "${PYVBZ_BUILD_SCRIPT}"
+)
+
+set(PYVBZ_ALL)
+if (NOT WIN32)
+ set(PYVBZ_ALL "ALL")
+endif()
+
+add_custom_target(pyvbz "${PYVBZ_ALL}"
+ DEPENDS "${PYVBZ_OUTPUT_PATH}")
+
+if (BUILD_TESTING AND NOT WIN32)
+ set(PYVBZ_VENV_PATH "${CMAKE_CURRENT_BINARY_DIR}/venv")
+ set(PYVBZ_VENV_PYTHON "${PYVBZ_VENV_PATH}/bin/python")
+ add_custom_command(
+ OUTPUT "${PYVBZ_VENV_PYTHON}"
+ COMMAND ${PYTHON_EXECUTABLE} -m venv
+ --system-site-packages "${CMAKE_CURRENT_BINARY_DIR}/venv"
+ COMMAND "${PYVBZ_VENV_PYTHON}" -m pip install -r
+ "${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt"
+ COMMAND ${CMAKE_COMMAND} -E env
+ VBZ_BUILD_DIR="${CMAKE_BINARY_DIR}"
+ VBZ_INCLUDE_PATHS="${CMAKE_SOURCE_DIR}/vbz\;${CMAKE_BINARY_DIR}/vbz/"
+ VBZ_LINK_LIBS="$<TARGET_FILE:vbz>\;${STREAMVBYTE_STATIC_LIB}\;${ZSTD_LIBRARY}"
+ "${PYVBZ_VENV_PYTHON}" setup.py develop
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/setup.py"
+ )
+ add_custom_target(pyvbz_venv ALL DEPENDS "${PYVBZ_VENV_PYTHON}")
+
+ add_test(
+ NAME pyvbz_test
+ COMMAND "${PYVBZ_VENV_PYTHON}" ./tests/unit
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+endif()
diff --git a/python/pyvbz/README.md b/python/pyvbz/README.md
new file mode 100644
index 0000000..f5764b6
--- /dev/null
+++ b/python/pyvbz/README.md
@@ -0,0 +1,27 @@
+# pyvbz
+
+Python bindings for `libvbz`.
+
+## Installation
+
+Python wheels are provided with each [release](https://github.com/nanoporetech/vbz_compression/releases) and can be install with with `pip`.
+
+```
+$ pip install https://github.com/nanoporetech/vbz_compression/releases/download/v1.0.0/pyvbz-1.0.0-cp35-cp35m-linux_x86_64.whl
+```
+
+## Example
+
+```python
+>>> import vbz
+>>> import numpy as np
+>>> signal = np.arange(0, 1000, dtype=np.int16)
+>>> signal.nbytes
+2000
+>>> compressed = vbz.compress(signal)
+>>> compressed.nbytes
+27
+>>> recovered = vbz.decompress(compressed, dtype=np.int16)
+>>> all(signal == recovered)
+True
+```
diff --git a/python/pyvbz/build_pyvbz.cmake b/python/pyvbz/build_pyvbz.cmake
new file mode 100644
index 0000000..dfc8e21
--- /dev/null
+++ b/python/pyvbz/build_pyvbz.cmake
@@ -0,0 +1,20 @@
+set(PYTHON "$ENV{PYTHON_EXE}")
+set(SOURCE_DIR "$ENV{PYVBZ_DIR}")
+
+message("Building pyvbz with ${PYTHON}")
+message("Include paths for pyvbz $ENV{VBZ_INCLUDE_PATHS}")
+message("Linking pyvbz against $ENV{VBZ_LINK_LIBS}")
+
+execute_process(
+ COMMAND "${PYTHON}" setup.py bdist_wheel
+ WORKING_DIRECTORY "${SOURCE_DIR}"
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE output
+ ERROR_VARIABLE output
+)
+
+if (NOT result EQUAL 0)
+ message(FATAL_ERROR "Could not build pyvbz: ${result}: ${output}")
+endif()
+
+execute_process(COMMAND ${CMAKE_COMMAND} -E touch "$ENV{OUTPUT_FILE}")
diff --git a/python/pyvbz/requirements.txt b/python/pyvbz/requirements.txt
new file mode 100644
index 0000000..1aa0964
--- /dev/null
+++ b/python/pyvbz/requirements.txt
@@ -0,0 +1,2 @@
+numpy
+cffi
diff --git a/python/pyvbz/setup.py b/python/pyvbz/setup.py
new file mode 100644
index 0000000..1b9a7dc
--- /dev/null
+++ b/python/pyvbz/setup.py
@@ -0,0 +1,26 @@
+from setuptools import setup, find_packages
+
+setup(
+ name='pyvbz',
+ version='1.0.1',
+ url='https://nanoporetech.com',
+ author='Oxford Nanopore Technologies, Limited',
+ author_email="support@nanoporetech.com",
+ packages=find_packages(),
+ description="Python bindings to libvbz",
+ install_requires=['numpy', 'cffi'],
+ setup_requires=['cffi', 'wheel'],
+ cffi_modules=['vbz/build.py:ffibuilder'],
+ classifiers=[
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Console',
+ 'Intended Audience :: Developers',
+ 'Intended Audience :: Science/Research',
+ 'License :: OSI Approved :: Mozilla Public License 2.0',
+ 'Natural Language :: English',
+ 'Operating System :: POSIX :: Linux',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 3',
+ 'Topic :: Scientific/Engineering :: Bio-Informatics',
+ ]
+)
diff --git a/python/pyvbz/tests/unit b/python/pyvbz/tests/unit
new file mode 100755
index 0000000..292dad8
--- /dev/null
+++ b/python/pyvbz/tests/unit
@@ -0,0 +1,123 @@
+#!/usr/bin/env python3
+
+import numpy as np
+from unittest import TestCase, main
+from vbz import compress, decompress, compression_options
+from numpy.testing import assert_array_equal
+
+
+class Tests:
+ vbz_version = None
+
+ """ Base test functions for all 3 encoding/decoding functions """
+ def test_decode(self):
+ """ S1: simple decode """
+ options = None
+ if self.vbz_version:
+ zigzag = np.issubdtype(self.data.dtype, np.signedinteger)
+ options = compression_options(zigzag, self.data.dtype.itemsize, 1, self.vbz_version)
+
+ res = compress(self.data, options)
+ rec = decompress(res, self.dtype, options)
+ assert_array_equal(self.data, rec)
+
+
+class BasicTest(Tests):
+ """ Base test for encoding and decoding with small simple test case """
+ def setUp(self):
+ self.data = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], dtype=self.dtype)
+
+class RandTest(Tests):
+ """ Base test encoding and decoding with large random array """
+ def setUp(self):
+ self.data = np.random.randint(self.rmin, self.rmax, size=self.size, dtype=self.dtype)
+
+# Default configuration test (default options)
+class BasicTestInt8(BasicTest, TestCase):
+ dtype = np.int8
+
+class BasicTestUInt8(BasicTest, TestCase):
+ dtype = np.uint8
+
+
+class BasicTestInt16(BasicTest, TestCase):
+ dtype = np.int16
+
+class BasicTestUInt16(BasicTest, TestCase):
+ dtype = np.uint16
+
+
+class BasicTestInt32(BasicTest, TestCase):
+ dtype = np.int32
+
+class BasicTestUInt32(BasicTest, TestCase):
+ dtype = np.uint32
+
+
+# Using v1 (half support test)
+class BasicV1TestInt8(BasicTestInt8):
+ vbz_version = 1
+
+class BasicV1TestUInt8(BasicTestUInt8):
+ vbz_version = 1
+
+class BasicV1TestInt16(BasicTestInt16):
+ vbz_version = 1
+
+class BasicV1TestUInt16(BasicTestUInt16):
+ vbz_version = 1
+
+# Default configuration test (default options)
+class RandTestInt8(RandTest, TestCase):
+ dtype = np.int8
+ rmin = -2**7
+ rmax = 2**7 -1
+ size = 200000
+
+class RandTestUInt8(RandTest, TestCase):
+ dtype = np.uint8
+ rmin = 0
+ rmax = 2**7 -1
+ size = 200000
+
+
+class RandTestInt16(RandTest, TestCase):
+ dtype = np.int16
+ rmin = -2**15
+ rmax = 2**15 -1
+ size = 200000
+
+class RandTestUInt16(RandTest, TestCase):
+ dtype = np.uint16
+ rmin = 0
+ rmax = 2**15 - 1
+ size = 200000
+
+
+class RandTestInt32(RandTest, TestCase):
+ dtype = np.int32
+ rmin = -2**31
+ rmax = 2**31 - 1
+ size = 200000
+
+class RandTestIntU32(RandTest, TestCase):
+ dtype = np.uint32
+ rmin = 0
+ rmax = 2**31 - 1
+ size = 200000
+
+# Random tests Using v1 (half support test)
+class RandV1TestInt8(RandTestInt8):
+ vbz_version = 1
+
+class RandV1TestUInt8(RandTestUInt8):
+ vbz_version = 1
+
+class RandV1TestInt16(RandTestUInt16):
+ vbz_version = 1
+
+class RandV1TestUInt16(RandTestUInt16):
+ vbz_version = 1
+
+if __name__ == '__main__':
+ main()
diff --git a/python/pyvbz/vbz/__init__.py b/python/pyvbz/vbz/__init__.py
new file mode 100644
index 0000000..97b3e92
--- /dev/null
+++ b/python/pyvbz/vbz/__init__.py
@@ -0,0 +1,79 @@
+"""
+Python bindings for libvbz
+"""
+
+__version__ = "0.9.3"
+
+
+import numpy as np
+
+from _vbz import lib, ffi
+
+
+def compression_options(zigzag, size, zlevel=1, version=0):
+ options = ffi.new("CompressionOptions *")
+ options.integer_size = size
+ options.perform_delta_zig_zag = zigzag
+ options.zstd_compression_level = zlevel
+ options.vbz_version = version
+ return options
+
+
+def compress(data, options=None):
+
+ if options is None:
+ zigzag = np.issubdtype(data.dtype, np.signedinteger)
+ options = compression_options(zigzag, data.dtype.itemsize)
+
+ output_size = lib.vbz_max_compressed_size(len(data) * options.integer_size, options)
+ output = np.empty(output_size, dtype=np.uint8)
+
+ if lib.vbz_is_error(output_size):
+ raise Exception("Something unexpected went wrong")
+
+ size = lib.vbz_compress_sized(
+ ffi.cast("void const *", ffi.from_buffer(data)),
+ len(data) * options.integer_size,
+ ffi.cast("void *", ffi.from_buffer(output)),
+ output_size,
+ options
+ )
+
+ if lib.vbz_is_error(size):
+ raise Exception("Something unexpected went wrong")
+
+ return output[:size]
+
+
+def decompress(data, dtype, options=None):
+
+ if options is None:
+ zigzag = np.issubdtype(dtype, np.signedinteger)
+ try:
+ options = compression_options(zigzag, dtype.itemsize)
+ except TypeError:
+ options = compression_options(zigzag, dtype().itemsize)
+
+ uncompressed_size = lib.vbz_decompressed_size(
+ ffi.cast("void const *", ffi.from_buffer(data)),
+ len(data),
+ options
+ )
+
+ if lib.vbz_is_error(uncompressed_size):
+ raise Exception("Something unexpected went wrong")
+
+ output = np.empty(uncompressed_size, dtype=dtype)
+
+ size = lib.vbz_decompress_sized(
+ ffi.cast("void const *", ffi.from_buffer(data)),
+ len(data),
+ ffi.cast("void *", ffi.from_buffer(output)),
+ uncompressed_size,
+ options
+ )
+
+ if lib.vbz_is_error(size):
+ raise Exception("Something unexpected went wrong")
+
+ return output[:int(size / options.integer_size)]
diff --git a/python/pyvbz/vbz/build.py b/python/pyvbz/vbz/build.py
new file mode 100644
index 0000000..95ddcd5
--- /dev/null
+++ b/python/pyvbz/vbz/build.py
@@ -0,0 +1,71 @@
+"""
+Builds the C Python wrapper for libvbz
+"""
+
+import os
+from cffi import FFI
+
+
+vbz_include_paths = os.environ["VBZ_INCLUDE_PATHS"].split(";")
+vbz_libs = os.environ["VBZ_LINK_LIBS"].split(";")
+
+
+ffibuilder = FFI()
+
+
+ffibuilder.set_source(
+ "_vbz",
+ """
+ #include <vbz.h>
+ """,
+ include_dirs=vbz_include_paths,
+ extra_objects=vbz_libs,
+ source_extension='.cpp',
+ libraries=['c', 'stdc++'],
+ extra_compile_args=['-std=c++11'],
+)
+
+
+ffibuilder.cdef("""
+typedef uint32_t vbz_size_t;
+
+typedef struct {
+ bool perform_delta_zig_zag;
+ unsigned int integer_size;
+ unsigned int zstd_compression_level;
+ unsigned int vbz_version;
+} CompressionOptions;
+
+bool vbz_is_error(vbz_size_t result_value);
+
+vbz_size_t vbz_max_compressed_size(
+ vbz_size_t source_size,
+ CompressionOptions const* options
+);
+
+vbz_size_t vbz_decompressed_size(
+ void const* source,
+ vbz_size_t source_size,
+ CompressionOptions const* options
+);
+
+vbz_size_t vbz_compress_sized(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ CompressionOptions const* options
+);
+
+vbz_size_t vbz_decompress_sized(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ CompressionOptions const* options
+);
+""")
+
+
+if __name__ == "__main__":
+ ffibuilder.compile()
diff --git a/python/test/requirements_1.10.txt b/python/test/requirements_1.10.txt
new file mode 100644
index 0000000..e1195fe
--- /dev/null
+++ b/python/test/requirements_1.10.txt
@@ -0,0 +1,4 @@
+# h5py 2 support was dropped in Python 3.9
+h5py==2.10.0
+# numpy 1.18.5 is the last version that supports Python 3.5
+numpy==1.18.5
diff --git a/python/test/requirements_1.12.txt b/python/test/requirements_1.12.txt
new file mode 100644
index 0000000..b46db0d
--- /dev/null
+++ b/python/test/requirements_1.12.txt
@@ -0,0 +1,2 @@
+# Originally built against Python 3.9
+h5py==3.6.0
diff --git a/python/test/requirements_1.8.txt b/python/test/requirements_1.8.txt
new file mode 100644
index 0000000..caf50c8
--- /dev/null
+++ b/python/test/requirements_1.8.txt
@@ -0,0 +1 @@
+h5py==2.7.1 \ No newline at end of file
diff --git a/python/test/test_repack.py b/python/test/test_repack.py
new file mode 100644
index 0000000..270bd9d
--- /dev/null
+++ b/python/test/test_repack.py
@@ -0,0 +1,40 @@
+import subprocess
+import os
+import sys
+
+import unittest
+
+TEST_DATA = os.path.join(os.path.dirname(__file__), "..", "..", "test_data")
+
+
+class TestHDFRepack(unittest.TestCase):
+
+ def test_simple_range(self):
+ source_file = os.path.join(TEST_DATA, "multi_fast5_zip.fast5")
+ dest_file_vbz = os.path.join(TEST_DATA, "multi_fast5_zip.fast5.repacked_vbz")
+ dest_file_none = os.path.join(TEST_DATA, "multi_fast5_zip.fast5.repacked_none")
+
+ result = subprocess.run([ 'h5repack', '-f', 'NONE', source_file, dest_file_none ],
+ stdout=sys.stdout,
+ stderr=sys.stderr
+ )
+ self.assertEqual(result.returncode, 0)
+
+ result = subprocess.run([ 'h5repack', '-f', 'UD=32020,5,0,0,2,1,1', source_file, dest_file_vbz ],
+ stdout=sys.stdout,
+ stderr=sys.stderr
+ )
+ self.assertEqual(result.returncode, 0)
+
+ uncompressed_bytes = os.stat(dest_file_none).st_size
+ source_bytes = os.stat(source_file).st_size
+ vbz_bytes = os.stat(dest_file_vbz).st_size
+ print("Uncompressed file is %s bytes"
+ % uncompressed_bytes)
+ print("Source file is %s bytes (%.0f%% of uncompressed)"
+ % (source_bytes, (source_bytes/uncompressed_bytes*100)))
+ print("vbz file is %s bytes (%.0f%% of uncompressed, %.0f%% of source)"
+ % (vbz_bytes, (vbz_bytes/uncompressed_bytes*100), (vbz_bytes/source_bytes*100)))
+
+if __name__ == '__main__':
+ unittest.main() \ No newline at end of file
diff --git a/python/test/test_vbz_filter.py b/python/test/test_vbz_filter.py
new file mode 100644
index 0000000..02aa6fb
--- /dev/null
+++ b/python/test/test_vbz_filter.py
@@ -0,0 +1,62 @@
+import h5py
+import numpy
+import os
+
+import unittest
+
+TEST_DATA = os.path.join(os.path.dirname(__file__), "..", "..", "test_data")
+
+class TestVbzFilter(unittest.TestCase):
+ VBZ_VERISON = 0
+
+ def test_simple_range(self):
+ original_data = numpy.arange(1, 100, dtype="i2")
+
+ with h5py.File("test_file.h5", "w") as f:
+ f.create_dataset("bar", compression=32020, compression_opts=(self.VBZ_VERISON, 2, 1, 1), data=original_data)
+
+ with h5py.File("test_file.h5", "r") as f:
+ numpy.testing.assert_array_equal(f["bar"][:], original_data)
+
+ def test_compressing_real_data(self):
+ zip_file = h5py.File(os.path.join(TEST_DATA, "multi_fast5_zip.fast5"))
+
+ for zip_key in zip_file.keys():
+ original_data = zip_file[zip_key]["Raw/Signal"][:]
+
+ if (zip_key == "read_008468c3-e477-46c4-a6e2-7d021a4ebf0b"):
+ continue
+
+ with h5py.File("test_file.h5", "w") as f:
+ f.create_dataset("bar", compression=32020, compression_opts=(self.VBZ_VERISON, 2, 1, 1), data=original_data, chunks=(len(original_data),))
+
+ with h5py.File("test_file.h5", "r") as f:
+ numpy.testing.assert_array_equal(f["bar"][:], original_data)
+
+class TestVbzFilterV0(TestVbzFilter):
+ VBZ_VERISON = 0
+
+class TestVbzFilterV1(TestVbzFilter):
+ VBZ_VERISON = 1
+
+class TestVbzStoredFiles(unittest.TestCase):
+ def test_stored_files(self):
+ files = [
+ h5py.File(os.path.join(TEST_DATA, "multi_fast5_zip.fast5")),
+ h5py.File(os.path.join(TEST_DATA, "multi_fast5_vbz.fast5")),
+ h5py.File(os.path.join(TEST_DATA, "multi_fast5_vbz_v1.fast5")),
+ ]
+
+ for sorted_keys in zip(*[sorted(file.keys()) for file in files ]):
+ for e in sorted_keys[1:]:
+ self.assertEqual(sorted_keys[0], e)
+
+ key = sorted_keys[0]
+ first_data = files[0][key]["Raw/Signal"][:]
+ for file in files[1:]:
+ data = file[key]["Raw/Signal"][:]
+ numpy.testing.assert_array_equal(first_data, data)
+
+
+if __name__ == '__main__':
+ unittest.main() \ No newline at end of file
diff --git a/test_data/multi_fast5_vbz.fast5 b/test_data/multi_fast5_vbz.fast5
new file mode 100644
index 0000000..bd55f45
--- /dev/null
+++ b/test_data/multi_fast5_vbz.fast5
Binary files differ
diff --git a/test_data/multi_fast5_vbz_v1.fast5 b/test_data/multi_fast5_vbz_v1.fast5
new file mode 100644
index 0000000..34a1092
--- /dev/null
+++ b/test_data/multi_fast5_vbz_v1.fast5
Binary files differ
diff --git a/test_data/multi_fast5_zip.fast5 b/test_data/multi_fast5_zip.fast5
new file mode 100644
index 0000000..12091c5
--- /dev/null
+++ b/test_data/multi_fast5_zip.fast5
Binary files differ
diff --git a/third_party/catch2/catch.hpp b/third_party/catch2/catch.hpp
new file mode 100644
index 0000000..db1fed3
--- /dev/null
+++ b/third_party/catch2/catch.hpp
@@ -0,0 +1,17966 @@
+/*
+ * Catch v2.13.8
+ * Generated: 2022-01-03 21:20:09.589503
+ * ----------------------------------------------------------
+ * This file has been merged from multiple headers. Please don't edit it directly
+ * Copyright (c) 2022 Two Blue Cubes Ltd. All rights reserved.
+ *
+ * Distributed under the Boost Software License, Version 1.0. (See accompanying
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
+#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
+// start catch.hpp
+
+
+#define CATCH_VERSION_MAJOR 2
+#define CATCH_VERSION_MINOR 13
+#define CATCH_VERSION_PATCH 8
+
+#ifdef __clang__
+# pragma clang system_header
+#elif defined __GNUC__
+# pragma GCC system_header
+#endif
+
+// start catch_suppress_warnings.h
+
+#ifdef __clang__
+# ifdef __ICC // icpc defines the __clang__ macro
+# pragma warning(push)
+# pragma warning(disable: 161 1682)
+# else // __ICC
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wpadded"
+# pragma clang diagnostic ignored "-Wswitch-enum"
+# pragma clang diagnostic ignored "-Wcovered-switch-default"
+# endif
+#elif defined __GNUC__
+ // Because REQUIREs trigger GCC's -Wparentheses, and because still
+ // supported version of g++ have only buggy support for _Pragmas,
+ // Wparentheses have to be suppressed globally.
+# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details
+
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wunused-variable"
+# pragma GCC diagnostic ignored "-Wpadded"
+#endif
+// end catch_suppress_warnings.h
+#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
+# define CATCH_IMPL
+# define CATCH_CONFIG_ALL_PARTS
+#endif
+
+// In the impl file, we want to have access to all parts of the headers
+// Can also be used to sanely support PCHs
+#if defined(CATCH_CONFIG_ALL_PARTS)
+# define CATCH_CONFIG_EXTERNAL_INTERFACES
+# if defined(CATCH_CONFIG_DISABLE_MATCHERS)
+# undef CATCH_CONFIG_DISABLE_MATCHERS
+# endif
+# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
+# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
+# endif
+#endif
+
+#if !defined(CATCH_CONFIG_IMPL_ONLY)
+// start catch_platform.h
+
+// See e.g.:
+// https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html
+#ifdef __APPLE__
+# include <TargetConditionals.h>
+# if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \
+ (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1)
+# define CATCH_PLATFORM_MAC
+# elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1)
+# define CATCH_PLATFORM_IPHONE
+# endif
+
+#elif defined(linux) || defined(__linux) || defined(__linux__)
+# define CATCH_PLATFORM_LINUX
+
+#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__)
+# define CATCH_PLATFORM_WINDOWS
+#endif
+
+// end catch_platform.h
+
+#ifdef CATCH_IMPL
+# ifndef CLARA_CONFIG_MAIN
+# define CLARA_CONFIG_MAIN_NOT_DEFINED
+# define CLARA_CONFIG_MAIN
+# endif
+#endif
+
+// start catch_user_interfaces.h
+
+namespace Catch {
+ unsigned int rngSeed();
+}
+
+// end catch_user_interfaces.h
+// start catch_tag_alias_autoregistrar.h
+
+// start catch_common.h
+
+// start catch_compiler_capabilities.h
+
+// Detect a number of compiler features - by compiler
+// The following features are defined:
+//
+// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
+// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
+// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
+// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled?
+// ****************
+// Note to maintainers: if new toggles are added please document them
+// in configuration.md, too
+// ****************
+
+// In general each macro has a _NO_<feature name> form
+// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature.
+// Many features, at point of detection, define an _INTERNAL_ macro, so they
+// can be combined, en-mass, with the _NO_ forms later.
+
+#ifdef __cplusplus
+
+# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
+# define CATCH_CPP14_OR_GREATER
+# endif
+
+# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
+# define CATCH_CPP17_OR_GREATER
+# endif
+
+#endif
+
+// Only GCC compiler should be used in this block, so other compilers trying to
+// mask themselves as GCC should be ignored.
+#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__)
+# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" )
+# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" )
+
+# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__)
+
+#endif
+
+#if defined(__clang__)
+
+# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" )
+# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" )
+
+// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug
+// which results in calls to destructors being emitted for each temporary,
+// without a matching initialization. In practice, this can result in something
+// like `std::string::~string` being called on an uninitialized value.
+//
+// For example, this code will likely segfault under IBM XL:
+// ```
+// REQUIRE(std::string("12") + "34" == "1234")
+// ```
+//
+// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented.
+# if !defined(__ibmxl__) && !defined(__CUDACC__)
+# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */
+# endif
+
+# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
+ _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
+
+# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
+ _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
+
+# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
+ _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" )
+
+# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
+ _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" )
+
+# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
+ _Pragma( "clang diagnostic ignored \"-Wunused-template\"" )
+
+#endif // __clang__
+
+////////////////////////////////////////////////////////////////////////////////
+// Assume that non-Windows platforms support posix signals by default
+#if !defined(CATCH_PLATFORM_WINDOWS)
+ #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// We know some environments not to support full POSIX signals
+#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__)
+ #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
+#endif
+
+#ifdef __OS400__
+# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
+# define CATCH_CONFIG_COLOUR_NONE
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// Android somehow still does not support std::to_string
+#if defined(__ANDROID__)
+# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
+# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// Not all Windows environments support SEH properly
+#if defined(__MINGW32__)
+# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// PS4
+#if defined(__ORBIS__)
+# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// Cygwin
+#ifdef __CYGWIN__
+
+// Required for some versions of Cygwin to declare gettimeofday
+// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
+# define _BSD_SOURCE
+// some versions of cygwin (most) do not support std::to_string. Use the libstd check.
+// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813
+# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
+ && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
+
+# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
+
+# endif
+#endif // __CYGWIN__
+
+////////////////////////////////////////////////////////////////////////////////
+// Visual C++
+#if defined(_MSC_VER)
+
+// Universal Windows platform does not support SEH
+// Or console colours (or console at all...)
+# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
+# define CATCH_CONFIG_COLOUR_NONE
+# else
+# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
+# endif
+
+# if !defined(__clang__) // Handle Clang masquerading for msvc
+
+// MSVC traditional preprocessor needs some workaround for __VA_ARGS__
+// _MSVC_TRADITIONAL == 0 means new conformant preprocessor
+// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor
+# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL)
+# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+# endif // MSVC_TRADITIONAL
+
+// Only do this if we're not using clang on Windows, which uses `diagnostic push` & `diagnostic pop`
+# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) )
+# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) )
+# endif // __clang__
+
+#endif // _MSC_VER
+
+#if defined(_REENTRANT) || defined(_MSC_VER)
+// Enable async processing, as -pthread is specified or no additional linking is required
+# define CATCH_INTERNAL_CONFIG_USE_ASYNC
+#endif // _MSC_VER
+
+////////////////////////////////////////////////////////////////////////////////
+// Check if we are compiled with -fno-exceptions or equivalent
+#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
+# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// DJGPP
+#ifdef __DJGPP__
+# define CATCH_INTERNAL_CONFIG_NO_WCHAR
+#endif // __DJGPP__
+
+////////////////////////////////////////////////////////////////////////////////
+// Embarcadero C++Build
+#if defined(__BORLANDC__)
+ #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+// Use of __COUNTER__ is suppressed during code analysis in
+// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly
+// handled by it.
+// Otherwise all supported compilers support COUNTER macro,
+// but user still might want to turn it off
+#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L )
+ #define CATCH_INTERNAL_CONFIG_COUNTER
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+// RTX is a special version of Windows that is real time.
+// This means that it is detected as Windows, but does not provide
+// the same set of capabilities as real Windows does.
+#if defined(UNDER_RTSS) || defined(RTX64_BUILD)
+ #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
+ #define CATCH_INTERNAL_CONFIG_NO_ASYNC
+ #define CATCH_CONFIG_COLOUR_NONE
+#endif
+
+#if !defined(_GLIBCXX_USE_C99_MATH_TR1)
+#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER
+#endif
+
+// Various stdlib support checks that require __has_include
+#if defined(__has_include)
+ // Check if string_view is available and usable
+ #if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER)
+ # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW
+ #endif
+
+ // Check if optional is available and usable
+ # if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
+ # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL
+ # endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
+
+ // Check if byte is available and usable
+ # if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
+ # include <cstddef>
+ # if defined(__cpp_lib_byte) && (__cpp_lib_byte > 0)
+ # define CATCH_INTERNAL_CONFIG_CPP17_BYTE
+ # endif
+ # endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
+
+ // Check if variant is available and usable
+ # if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
+ # if defined(__clang__) && (__clang_major__ < 8)
+ // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852
+ // fix should be in clang 8, workaround in libstdc++ 8.2
+ # include <ciso646>
+ # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
+ # define CATCH_CONFIG_NO_CPP17_VARIANT
+ # else
+ # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
+ # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
+ # else
+ # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
+ # endif // defined(__clang__) && (__clang_major__ < 8)
+ # endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
+#endif // defined(__has_include)
+
+#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
+# define CATCH_CONFIG_COUNTER
+#endif
+#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH)
+# define CATCH_CONFIG_WINDOWS_SEH
+#endif
+// This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
+#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
+# define CATCH_CONFIG_POSIX_SIGNALS
+#endif
+// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions.
+#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR)
+# define CATCH_CONFIG_WCHAR
+#endif
+
+#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING)
+# define CATCH_CONFIG_CPP11_TO_STRING
+#endif
+
+#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL)
+# define CATCH_CONFIG_CPP17_OPTIONAL
+#endif
+
+#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW)
+# define CATCH_CONFIG_CPP17_STRING_VIEW
+#endif
+
+#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT)
+# define CATCH_CONFIG_CPP17_VARIANT
+#endif
+
+#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE)
+# define CATCH_CONFIG_CPP17_BYTE
+#endif
+
+#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
+# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE
+#endif
+
+#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE)
+# define CATCH_CONFIG_NEW_CAPTURE
+#endif
+
+#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+# define CATCH_CONFIG_DISABLE_EXCEPTIONS
+#endif
+
+#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN)
+# define CATCH_CONFIG_POLYFILL_ISNAN
+#endif
+
+#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC)
+# define CATCH_CONFIG_USE_ASYNC
+#endif
+
+#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE)
+# define CATCH_CONFIG_ANDROID_LOGWRITE
+#endif
+
+#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
+# define CATCH_CONFIG_GLOBAL_NEXTAFTER
+#endif
+
+// Even if we do not think the compiler has that warning, we still have
+// to provide a macro that can be used by the code.
+#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION)
+# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
+#endif
+#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION)
+# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
+#endif
+#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
+# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
+#endif
+#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
+# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
+#endif
+#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS)
+# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS
+#endif
+#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS)
+# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS
+#endif
+
+// The goal of this macro is to avoid evaluation of the arguments, but
+// still have the compiler warn on problems inside...
+#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN)
+# define CATCH_INTERNAL_IGNORE_BUT_WARN(...)
+#endif
+
+#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10)
+# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
+#elif defined(__clang__) && (__clang_major__ < 5)
+# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
+#endif
+
+#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS)
+# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
+#endif
+
+#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+#define CATCH_TRY if ((true))
+#define CATCH_CATCH_ALL if ((false))
+#define CATCH_CATCH_ANON(type) if ((false))
+#else
+#define CATCH_TRY try
+#define CATCH_CATCH_ALL catch (...)
+#define CATCH_CATCH_ANON(type) catch (type)
+#endif
+
+#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR)
+#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+#endif
+
+// end catch_compiler_capabilities.h
+#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
+#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
+#ifdef CATCH_CONFIG_COUNTER
+# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
+#else
+# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
+#endif
+
+#include <iosfwd>
+#include <string>
+#include <cstdint>
+
+// We need a dummy global operator<< so we can bring it into Catch namespace later
+struct Catch_global_namespace_dummy {};
+std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
+
+namespace Catch {
+
+ struct CaseSensitive { enum Choice {
+ Yes,
+ No
+ }; };
+
+ class NonCopyable {
+ NonCopyable( NonCopyable const& ) = delete;
+ NonCopyable( NonCopyable && ) = delete;
+ NonCopyable& operator = ( NonCopyable const& ) = delete;
+ NonCopyable& operator = ( NonCopyable && ) = delete;
+
+ protected:
+ NonCopyable();
+ virtual ~NonCopyable();
+ };
+
+ struct SourceLineInfo {
+
+ SourceLineInfo() = delete;
+ SourceLineInfo( char const* _file, std::size_t _line ) noexcept
+ : file( _file ),
+ line( _line )
+ {}
+
+ SourceLineInfo( SourceLineInfo const& other ) = default;
+ SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
+ SourceLineInfo( SourceLineInfo&& ) noexcept = default;
+ SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default;
+
+ bool empty() const noexcept { return file[0] == '\0'; }
+ bool operator == ( SourceLineInfo const& other ) const noexcept;
+ bool operator < ( SourceLineInfo const& other ) const noexcept;
+
+ char const* file;
+ std::size_t line;
+ };
+
+ std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
+
+ // Bring in operator<< from global namespace into Catch namespace
+ // This is necessary because the overload of operator<< above makes
+ // lookup stop at namespace Catch
+ using ::operator<<;
+
+ // Use this in variadic streaming macros to allow
+ // >> +StreamEndStop
+ // as well as
+ // >> stuff +StreamEndStop
+ struct StreamEndStop {
+ std::string operator+() const;
+ };
+ template<typename T>
+ T const& operator + ( T const& value, StreamEndStop ) {
+ return value;
+ }
+}
+
+#define CATCH_INTERNAL_LINEINFO \
+ ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
+
+// end catch_common.h
+namespace Catch {
+
+ struct RegistrarForTagAliases {
+ RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
+ };
+
+} // end namespace Catch
+
+#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
+
+// end catch_tag_alias_autoregistrar.h
+// start catch_test_registry.h
+
+// start catch_interfaces_testcase.h
+
+#include <vector>
+
+namespace Catch {
+
+ class TestSpec;
+
+ struct ITestInvoker {
+ virtual void invoke () const = 0;
+ virtual ~ITestInvoker();
+ };
+
+ class TestCase;
+ struct IConfig;
+
+ struct ITestCaseRegistry {
+ virtual ~ITestCaseRegistry();
+ virtual std::vector<TestCase> const& getAllTests() const = 0;
+ virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0;
+ };
+
+ bool isThrowSafe( TestCase const& testCase, IConfig const& config );
+ bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
+ std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
+ std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
+
+}
+
+// end catch_interfaces_testcase.h
+// start catch_stringref.h
+
+#include <cstddef>
+#include <string>
+#include <iosfwd>
+#include <cassert>
+
+namespace Catch {
+
+ /// A non-owning string class (similar to the forthcoming std::string_view)
+ /// Note that, because a StringRef may be a substring of another string,
+ /// it may not be null terminated.
+ class StringRef {
+ public:
+ using size_type = std::size_t;
+ using const_iterator = const char*;
+
+ private:
+ static constexpr char const* const s_empty = "";
+
+ char const* m_start = s_empty;
+ size_type m_size = 0;
+
+ public: // construction
+ constexpr StringRef() noexcept = default;
+
+ StringRef( char const* rawChars ) noexcept;
+
+ constexpr StringRef( char const* rawChars, size_type size ) noexcept
+ : m_start( rawChars ),
+ m_size( size )
+ {}
+
+ StringRef( std::string const& stdString ) noexcept
+ : m_start( stdString.c_str() ),
+ m_size( stdString.size() )
+ {}
+
+ explicit operator std::string() const {
+ return std::string(m_start, m_size);
+ }
+
+ public: // operators
+ auto operator == ( StringRef const& other ) const noexcept -> bool;
+ auto operator != (StringRef const& other) const noexcept -> bool {
+ return !(*this == other);
+ }
+
+ auto operator[] ( size_type index ) const noexcept -> char {
+ assert(index < m_size);
+ return m_start[index];
+ }
+
+ public: // named queries
+ constexpr auto empty() const noexcept -> bool {
+ return m_size == 0;
+ }
+ constexpr auto size() const noexcept -> size_type {
+ return m_size;
+ }
+
+ // Returns the current start pointer. If the StringRef is not
+ // null-terminated, throws std::domain_exception
+ auto c_str() const -> char const*;
+
+ public: // substrings and searches
+ // Returns a substring of [start, start + length).
+ // If start + length > size(), then the substring is [start, size()).
+ // If start > size(), then the substring is empty.
+ auto substr( size_type start, size_type length ) const noexcept -> StringRef;
+
+ // Returns the current start pointer. May not be null-terminated.
+ auto data() const noexcept -> char const*;
+
+ constexpr auto isNullTerminated() const noexcept -> bool {
+ return m_start[m_size] == '\0';
+ }
+
+ public: // iterators
+ constexpr const_iterator begin() const { return m_start; }
+ constexpr const_iterator end() const { return m_start + m_size; }
+ };
+
+ auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&;
+ auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
+
+ constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
+ return StringRef( rawChars, size );
+ }
+} // namespace Catch
+
+constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
+ return Catch::StringRef( rawChars, size );
+}
+
+// end catch_stringref.h
+// start catch_preprocessor.hpp
+
+
+#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__
+#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__)))
+#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__)))
+#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__)))
+#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__)))
+#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__)))
+
+#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__
+// MSVC needs more evaluations
+#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__)))
+#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__))
+#else
+#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__)
+#endif
+
+#define CATCH_REC_END(...)
+#define CATCH_REC_OUT
+
+#define CATCH_EMPTY()
+#define CATCH_DEFER(id) id CATCH_EMPTY()
+
+#define CATCH_REC_GET_END2() 0, CATCH_REC_END
+#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2
+#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1
+#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT
+#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0)
+#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next)
+
+#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ )
+#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ )
+#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ )
+
+#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ )
+#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ )
+#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ )
+
+// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results,
+// and passes userdata as the first parameter to each invocation,
+// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c)
+#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
+
+#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
+
+#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param)
+#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__
+#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__
+#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF
+#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__)
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__
+#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param))
+#else
+// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF
+#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__)
+#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__
+#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1)
+#endif
+
+#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__
+#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name)
+
+#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__)
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>())
+#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))
+#else
+#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>()))
+#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)))
+#endif
+
+#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\
+ CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__)
+
+#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0)
+#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1)
+#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2)
+#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3)
+#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4)
+#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5)
+#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6)
+#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7)
+#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8)
+#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9)
+#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10)
+
+#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
+
+#define INTERNAL_CATCH_TYPE_GEN\
+ template<typename...> struct TypeList {};\
+ template<typename...Ts>\
+ constexpr auto get_wrapper() noexcept -> TypeList<Ts...> { return {}; }\
+ template<template<typename...> class...> struct TemplateTypeList{};\
+ template<template<typename...> class...Cs>\
+ constexpr auto get_wrapper() noexcept -> TemplateTypeList<Cs...> { return {}; }\
+ template<typename...>\
+ struct append;\
+ template<typename...>\
+ struct rewrap;\
+ template<template<typename...> class, typename...>\
+ struct create;\
+ template<template<typename...> class, typename>\
+ struct convert;\
+ \
+ template<typename T> \
+ struct append<T> { using type = T; };\
+ template< template<typename...> class L1, typename...E1, template<typename...> class L2, typename...E2, typename...Rest>\
+ struct append<L1<E1...>, L2<E2...>, Rest...> { using type = typename append<L1<E1...,E2...>, Rest...>::type; };\
+ template< template<typename...> class L1, typename...E1, typename...Rest>\
+ struct append<L1<E1...>, TypeList<mpl_::na>, Rest...> { using type = L1<E1...>; };\
+ \
+ template< template<typename...> class Container, template<typename...> class List, typename...elems>\
+ struct rewrap<TemplateTypeList<Container>, List<elems...>> { using type = TypeList<Container<elems...>>; };\
+ template< template<typename...> class Container, template<typename...> class List, class...Elems, typename...Elements>\
+ struct rewrap<TemplateTypeList<Container>, List<Elems...>, Elements...> { using type = typename append<TypeList<Container<Elems...>>, typename rewrap<TemplateTypeList<Container>, Elements...>::type>::type; };\
+ \
+ template<template <typename...> class Final, template< typename...> class...Containers, typename...Types>\
+ struct create<Final, TemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<TemplateTypeList<Containers>, Types...>::type...>::type; };\
+ template<template <typename...> class Final, template <typename...> class List, typename...Ts>\
+ struct convert<Final, List<Ts...>> { using type = typename append<Final<>,TypeList<Ts>...>::type; };
+
+#define INTERNAL_CATCH_NTTP_1(signature, ...)\
+ template<INTERNAL_CATCH_REMOVE_PARENS(signature)> struct Nttp{};\
+ template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
+ constexpr auto get_wrapper() noexcept -> Nttp<__VA_ARGS__> { return {}; } \
+ template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...> struct NttpTemplateTypeList{};\
+ template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Cs>\
+ constexpr auto get_wrapper() noexcept -> NttpTemplateTypeList<Cs...> { return {}; } \
+ \
+ template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature)>\
+ struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>> { using type = TypeList<Container<__VA_ARGS__>>; };\
+ template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature), typename...Elements>\
+ struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>, Elements...> { using type = typename append<TypeList<Container<__VA_ARGS__>>, typename rewrap<NttpTemplateTypeList<Container>, Elements...>::type>::type; };\
+ template<template <typename...> class Final, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Containers, typename...Types>\
+ struct create<Final, NttpTemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<NttpTemplateTypeList<Containers>, Types...>::type...>::type; };
+
+#define INTERNAL_CATCH_DECLARE_SIG_TEST0(TestName)
+#define INTERNAL_CATCH_DECLARE_SIG_TEST1(TestName, signature)\
+ template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
+ static void TestName()
+#define INTERNAL_CATCH_DECLARE_SIG_TEST_X(TestName, signature, ...)\
+ template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
+ static void TestName()
+
+#define INTERNAL_CATCH_DEFINE_SIG_TEST0(TestName)
+#define INTERNAL_CATCH_DEFINE_SIG_TEST1(TestName, signature)\
+ template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
+ static void TestName()
+#define INTERNAL_CATCH_DEFINE_SIG_TEST_X(TestName, signature,...)\
+ template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
+ static void TestName()
+
+#define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature)\
+ template<typename Type>\
+ void reg_test(TypeList<Type>, Catch::NameAndTags nameAndTags)\
+ {\
+ Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<Type>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
+ }
+
+#define INTERNAL_CATCH_NTTP_REGISTER(TestFunc, signature, ...)\
+ template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
+ void reg_test(Nttp<__VA_ARGS__>, Catch::NameAndTags nameAndTags)\
+ {\
+ Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<__VA_ARGS__>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
+ }
+
+#define INTERNAL_CATCH_NTTP_REGISTER_METHOD0(TestName, signature, ...)\
+ template<typename Type>\
+ void reg_test(TypeList<Type>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
+ {\
+ Catch::AutoReg( Catch::makeTestInvoker(&TestName<Type>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
+ }
+
+#define INTERNAL_CATCH_NTTP_REGISTER_METHOD(TestName, signature, ...)\
+ template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
+ void reg_test(Nttp<__VA_ARGS__>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
+ {\
+ Catch::AutoReg( Catch::makeTestInvoker(&TestName<__VA_ARGS__>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
+ }
+
+#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0(TestName, ClassName)
+#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1(TestName, ClassName, signature)\
+ template<typename TestType> \
+ struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<TestType> { \
+ void test();\
+ }
+
+#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X(TestName, ClassName, signature, ...)\
+ template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \
+ struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<__VA_ARGS__> { \
+ void test();\
+ }
+
+#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0(TestName)
+#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1(TestName, signature)\
+ template<typename TestType> \
+ void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<TestType>::test()
+#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X(TestName, signature, ...)\
+ template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \
+ void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<__VA_ARGS__>::test()
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+#define INTERNAL_CATCH_NTTP_0
+#define INTERNAL_CATCH_NTTP_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__),INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_0)
+#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__)
+#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__)
+#define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__)
+#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__)
+#define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__)
+#define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__)
+#define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__)
+#else
+#define INTERNAL_CATCH_NTTP_0(signature)
+#define INTERNAL_CATCH_NTTP_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1,INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_0)( __VA_ARGS__))
+#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__))
+#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__))
+#define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__))
+#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__))
+#define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__))
+#define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__))
+#define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__))
+#endif
+
+// end catch_preprocessor.hpp
+// start catch_meta.hpp
+
+
+#include <type_traits>
+
+namespace Catch {
+ template<typename T>
+ struct always_false : std::false_type {};
+
+ template <typename> struct true_given : std::true_type {};
+ struct is_callable_tester {
+ template <typename Fun, typename... Args>
+ true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
+ template <typename...>
+ std::false_type static test(...);
+ };
+
+ template <typename T>
+ struct is_callable;
+
+ template <typename Fun, typename... Args>
+ struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {};
+
+#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
+ // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is
+ // replaced with std::invoke_result here.
+ template <typename Func, typename... U>
+ using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U...>>>;
+#else
+ // Keep ::type here because we still support C++11
+ template <typename Func, typename... U>
+ using FunctionReturnType = typename std::remove_reference<typename std::remove_cv<typename std::result_of<Func(U...)>::type>::type>::type;
+#endif
+
+} // namespace Catch
+
+namespace mpl_{
+ struct na;
+}
+
+// end catch_meta.hpp
+namespace Catch {
+
+template<typename C>
+class TestInvokerAsMethod : public ITestInvoker {
+ void (C::*m_testAsMethod)();
+public:
+ TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
+
+ void invoke() const override {
+ C obj;
+ (obj.*m_testAsMethod)();
+ }
+};
+
+auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*;
+
+template<typename C>
+auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
+ return new(std::nothrow) TestInvokerAsMethod<C>( testAsMethod );
+}
+
+struct NameAndTags {
+ NameAndTags( StringRef const& name_ = StringRef(), StringRef const& tags_ = StringRef() ) noexcept;
+ StringRef name;
+ StringRef tags;
+};
+
+struct AutoReg : NonCopyable {
+ AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
+ ~AutoReg();
+};
+
+} // end namespace Catch
+
+#if defined(CATCH_CONFIG_DISABLE)
+ #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \
+ static void TestName()
+ #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \
+ namespace{ \
+ struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
+ void test(); \
+ }; \
+ } \
+ void TestName::test()
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( TestName, TestFunc, Name, Tags, Signature, ... ) \
+ INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature))
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
+ namespace{ \
+ namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
+ INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
+ } \
+ } \
+ INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
+
+ #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \
+ INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ )
+ #else
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ ) )
+ #endif
+
+ #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \
+ INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ )
+ #else
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ ) )
+ #endif
+
+ #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \
+ INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ )
+ #else
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) )
+ #endif
+
+ #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \
+ INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ )
+ #else
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) )
+ #endif
+#endif
+
+ ///////////////////////////////////////////////////////////////////////////////
+ #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
+ static void TestName(); \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ static void TestName()
+ #define INTERNAL_CATCH_TESTCASE( ... ) \
+ INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), __VA_ARGS__ )
+
+ ///////////////////////////////////////////////////////////////////////////////
+ #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
+
+ ///////////////////////////////////////////////////////////////////////////////
+ #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ namespace{ \
+ struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
+ void test(); \
+ }; \
+ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
+ } \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ void TestName::test()
+ #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
+ INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), ClassName, __VA_ARGS__ )
+
+ ///////////////////////////////////////////////////////////////////////////////
+ #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
+
+ ///////////////////////////////////////////////////////////////////////////////
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(TestName, TestFunc, Name, Tags, Signature, ... )\
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
+ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
+ INTERNAL_CATCH_DECLARE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
+ namespace {\
+ namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
+ INTERNAL_CATCH_TYPE_GEN\
+ INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
+ INTERNAL_CATCH_NTTP_REG_GEN(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))\
+ template<typename...Types> \
+ struct TestName{\
+ TestName(){\
+ int index = 0; \
+ constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
+ using expander = int[];\
+ (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
+ }\
+ };\
+ static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
+ TestName<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\
+ return 0;\
+ }();\
+ }\
+ }\
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \
+ INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ )
+#else
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ ) )
+#endif
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \
+ INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ )
+#else
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ ) )
+#endif
+
+ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(TestName, TestFuncName, Name, Tags, Signature, TmplTypes, TypesList) \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
+ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
+ template<typename TestType> static void TestFuncName(); \
+ namespace {\
+ namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
+ INTERNAL_CATCH_TYPE_GEN \
+ INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature)) \
+ template<typename... Types> \
+ struct TestName { \
+ void reg_tests() { \
+ int index = 0; \
+ using expander = int[]; \
+ constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
+ constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
+ constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
+ (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++)... };/* NOLINT */\
+ } \
+ }; \
+ static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
+ using TestInit = typename create<TestName, decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>()), TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>>::type; \
+ TestInit t; \
+ t.reg_tests(); \
+ return 0; \
+ }(); \
+ } \
+ } \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ template<typename TestType> \
+ static void TestFuncName()
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\
+ INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename T,__VA_ARGS__)
+#else
+ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename T, __VA_ARGS__ ) )
+#endif
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\
+ INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__)
+#else
+ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ ) )
+#endif
+
+ #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
+ template<typename TestType> static void TestFunc(); \
+ namespace {\
+ namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
+ INTERNAL_CATCH_TYPE_GEN\
+ template<typename... Types> \
+ struct TestName { \
+ void reg_tests() { \
+ int index = 0; \
+ using expander = int[]; \
+ (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */\
+ } \
+ };\
+ static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
+ using TestInit = typename convert<TestName, TmplList>::type; \
+ TestInit t; \
+ t.reg_tests(); \
+ return 0; \
+ }(); \
+ }}\
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ template<typename TestType> \
+ static void TestFunc()
+
+ #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(Name, Tags, TmplList) \
+ INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, TmplList )
+
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
+ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
+ namespace {\
+ namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \
+ INTERNAL_CATCH_TYPE_GEN\
+ INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
+ INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
+ INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))\
+ template<typename...Types> \
+ struct TestNameClass{\
+ TestNameClass(){\
+ int index = 0; \
+ constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
+ using expander = int[];\
+ (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
+ }\
+ };\
+ static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
+ TestNameClass<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\
+ return 0;\
+ }();\
+ }\
+ }\
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \
+ INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ )
+#else
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) )
+#endif
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \
+ INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ )
+#else
+ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) )
+#endif
+
+ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2(TestNameClass, TestName, ClassName, Name, Tags, Signature, TmplTypes, TypesList)\
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
+ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
+ template<typename TestType> \
+ struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \
+ void test();\
+ };\
+ namespace {\
+ namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestNameClass) {\
+ INTERNAL_CATCH_TYPE_GEN \
+ INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
+ template<typename...Types>\
+ struct TestNameClass{\
+ void reg_tests(){\
+ int index = 0;\
+ using expander = int[];\
+ constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
+ constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
+ constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
+ (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++)... };/* NOLINT */ \
+ }\
+ };\
+ static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
+ using TestInit = typename create<TestNameClass, decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>()), TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>>::type;\
+ TestInit t;\
+ t.reg_tests();\
+ return 0;\
+ }(); \
+ }\
+ }\
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ template<typename TestType> \
+ void TestName<TestType>::test()
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\
+ INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), ClassName, Name, Tags, typename T, __VA_ARGS__ )
+#else
+ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), ClassName, Name, Tags, typename T,__VA_ARGS__ ) )
+#endif
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\
+ INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), ClassName, Name, Tags, Signature, __VA_ARGS__ )
+#else
+ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\
+ INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), ClassName, Name, Tags, Signature,__VA_ARGS__ ) )
+#endif
+
+ #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, TmplList) \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
+ template<typename TestType> \
+ struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \
+ void test();\
+ };\
+ namespace {\
+ namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \
+ INTERNAL_CATCH_TYPE_GEN\
+ template<typename...Types>\
+ struct TestNameClass{\
+ void reg_tests(){\
+ int index = 0;\
+ using expander = int[];\
+ (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */ \
+ }\
+ };\
+ static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
+ using TestInit = typename convert<TestNameClass, TmplList>::type;\
+ TestInit t;\
+ t.reg_tests();\
+ return 0;\
+ }(); \
+ }}\
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ template<typename TestType> \
+ void TestName<TestType>::test()
+
+#define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD(ClassName, Name, Tags, TmplList) \
+ INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), ClassName, Name, Tags, TmplList )
+
+// end catch_test_registry.h
+// start catch_capture.hpp
+
+// start catch_assertionhandler.h
+
+// start catch_assertioninfo.h
+
+// start catch_result_type.h
+
+namespace Catch {
+
+ // ResultWas::OfType enum
+ struct ResultWas { enum OfType {
+ Unknown = -1,
+ Ok = 0,
+ Info = 1,
+ Warning = 2,
+
+ FailureBit = 0x10,
+
+ ExpressionFailed = FailureBit | 1,
+ ExplicitFailure = FailureBit | 2,
+
+ Exception = 0x100 | FailureBit,
+
+ ThrewException = Exception | 1,
+ DidntThrowException = Exception | 2,
+
+ FatalErrorCondition = 0x200 | FailureBit
+
+ }; };
+
+ bool isOk( ResultWas::OfType resultType );
+ bool isJustInfo( int flags );
+
+ // ResultDisposition::Flags enum
+ struct ResultDisposition { enum Flags {
+ Normal = 0x01,
+
+ ContinueOnFailure = 0x02, // Failures fail test, but execution continues
+ FalseTest = 0x04, // Prefix expression with !
+ SuppressFail = 0x08 // Failures are reported but do not fail the test
+ }; };
+
+ ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs );
+
+ bool shouldContinueOnFailure( int flags );
+ inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
+ bool shouldSuppressFailure( int flags );
+
+} // end namespace Catch
+
+// end catch_result_type.h
+namespace Catch {
+
+ struct AssertionInfo
+ {
+ StringRef macroName;
+ SourceLineInfo lineInfo;
+ StringRef capturedExpression;
+ ResultDisposition::Flags resultDisposition;
+
+ // We want to delete this constructor but a compiler bug in 4.8 means
+ // the struct is then treated as non-aggregate
+ //AssertionInfo() = delete;
+ };
+
+} // end namespace Catch
+
+// end catch_assertioninfo.h
+// start catch_decomposer.h
+
+// start catch_tostring.h
+
+#include <vector>
+#include <cstddef>
+#include <type_traits>
+#include <string>
+// start catch_stream.h
+
+#include <iosfwd>
+#include <cstddef>
+#include <ostream>
+
+namespace Catch {
+
+ std::ostream& cout();
+ std::ostream& cerr();
+ std::ostream& clog();
+
+ class StringRef;
+
+ struct IStream {
+ virtual ~IStream();
+ virtual std::ostream& stream() const = 0;
+ };
+
+ auto makeStream( StringRef const &filename ) -> IStream const*;
+
+ class ReusableStringStream : NonCopyable {
+ std::size_t m_index;
+ std::ostream* m_oss;
+ public:
+ ReusableStringStream();
+ ~ReusableStringStream();
+
+ auto str() const -> std::string;
+
+ template<typename T>
+ auto operator << ( T const& value ) -> ReusableStringStream& {
+ *m_oss << value;
+ return *this;
+ }
+ auto get() -> std::ostream& { return *m_oss; }
+ };
+}
+
+// end catch_stream.h
+// start catch_interfaces_enum_values_registry.h
+
+#include <vector>
+
+namespace Catch {
+
+ namespace Detail {
+ struct EnumInfo {
+ StringRef m_name;
+ std::vector<std::pair<int, StringRef>> m_values;
+
+ ~EnumInfo();
+
+ StringRef lookup( int value ) const;
+ };
+ } // namespace Detail
+
+ struct IMutableEnumValuesRegistry {
+ virtual ~IMutableEnumValuesRegistry();
+
+ virtual Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values ) = 0;
+
+ template<typename E>
+ Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) {
+ static_assert(sizeof(int) >= sizeof(E), "Cannot serialize enum to int");
+ std::vector<int> intValues;
+ intValues.reserve( values.size() );
+ for( auto enumValue : values )
+ intValues.push_back( static_cast<int>( enumValue ) );
+ return registerEnum( enumName, allEnums, intValues );
+ }
+ };
+
+} // Catch
+
+// end catch_interfaces_enum_values_registry.h
+
+#ifdef CATCH_CONFIG_CPP17_STRING_VIEW
+#include <string_view>
+#endif
+
+#ifdef __OBJC__
+// start catch_objc_arc.hpp
+
+#import <Foundation/Foundation.h>
+
+#ifdef __has_feature
+#define CATCH_ARC_ENABLED __has_feature(objc_arc)
+#else
+#define CATCH_ARC_ENABLED 0
+#endif
+
+void arcSafeRelease( NSObject* obj );
+id performOptionalSelector( id obj, SEL sel );
+
+#if !CATCH_ARC_ENABLED
+inline void arcSafeRelease( NSObject* obj ) {
+ [obj release];
+}
+inline id performOptionalSelector( id obj, SEL sel ) {
+ if( [obj respondsToSelector: sel] )
+ return [obj performSelector: sel];
+ return nil;
+}
+#define CATCH_UNSAFE_UNRETAINED
+#define CATCH_ARC_STRONG
+#else
+inline void arcSafeRelease( NSObject* ){}
+inline id performOptionalSelector( id obj, SEL sel ) {
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+#endif
+ if( [obj respondsToSelector: sel] )
+ return [obj performSelector: sel];
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+ return nil;
+}
+#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
+#define CATCH_ARC_STRONG __strong
+#endif
+
+// end catch_objc_arc.hpp
+#endif
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless
+#endif
+
+namespace Catch {
+ namespace Detail {
+
+ extern const std::string unprintableString;
+
+ std::string rawMemoryToString( const void *object, std::size_t size );
+
+ template<typename T>
+ std::string rawMemoryToString( const T& object ) {
+ return rawMemoryToString( &object, sizeof(object) );
+ }
+
+ template<typename T>
+ class IsStreamInsertable {
+ template<typename Stream, typename U>
+ static auto test(int)
+ -> decltype(std::declval<Stream&>() << std::declval<U>(), std::true_type());
+
+ template<typename, typename>
+ static auto test(...)->std::false_type;
+
+ public:
+ static const bool value = decltype(test<std::ostream, const T&>(0))::value;
+ };
+
+ template<typename E>
+ std::string convertUnknownEnumToString( E e );
+
+ template<typename T>
+ typename std::enable_if<
+ !std::is_enum<T>::value && !std::is_base_of<std::exception, T>::value,
+ std::string>::type convertUnstreamable( T const& ) {
+ return Detail::unprintableString;
+ }
+ template<typename T>
+ typename std::enable_if<
+ !std::is_enum<T>::value && std::is_base_of<std::exception, T>::value,
+ std::string>::type convertUnstreamable(T const& ex) {
+ return ex.what();
+ }
+
+ template<typename T>
+ typename std::enable_if<
+ std::is_enum<T>::value
+ , std::string>::type convertUnstreamable( T const& value ) {
+ return convertUnknownEnumToString( value );
+ }
+
+#if defined(_MANAGED)
+ //! Convert a CLR string to a utf8 std::string
+ template<typename T>
+ std::string clrReferenceToString( T^ ref ) {
+ if (ref == nullptr)
+ return std::string("null");
+ auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString());
+ cli::pin_ptr<System::Byte> p = &bytes[0];
+ return std::string(reinterpret_cast<char const *>(p), bytes->Length);
+ }
+#endif
+
+ } // namespace Detail
+
+ // If we decide for C++14, change these to enable_if_ts
+ template <typename T, typename = void>
+ struct StringMaker {
+ template <typename Fake = T>
+ static
+ typename std::enable_if<::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type
+ convert(const Fake& value) {
+ ReusableStringStream rss;
+ // NB: call using the function-like syntax to avoid ambiguity with
+ // user-defined templated operator<< under clang.
+ rss.operator<<(value);
+ return rss.str();
+ }
+
+ template <typename Fake = T>
+ static
+ typename std::enable_if<!::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type
+ convert( const Fake& value ) {
+#if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER)
+ return Detail::convertUnstreamable(value);
+#else
+ return CATCH_CONFIG_FALLBACK_STRINGIFIER(value);
+#endif
+ }
+ };
+
+ namespace Detail {
+
+ // This function dispatches all stringification requests inside of Catch.
+ // Should be preferably called fully qualified, like ::Catch::Detail::stringify
+ template <typename T>
+ std::string stringify(const T& e) {
+ return ::Catch::StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::convert(e);
+ }
+
+ template<typename E>
+ std::string convertUnknownEnumToString( E e ) {
+ return ::Catch::Detail::stringify(static_cast<typename std::underlying_type<E>::type>(e));
+ }
+
+#if defined(_MANAGED)
+ template <typename T>
+ std::string stringify( T^ e ) {
+ return ::Catch::StringMaker<T^>::convert(e);
+ }
+#endif
+
+ } // namespace Detail
+
+ // Some predefined specializations
+
+ template<>
+ struct StringMaker<std::string> {
+ static std::string convert(const std::string& str);
+ };
+
+#ifdef CATCH_CONFIG_CPP17_STRING_VIEW
+ template<>
+ struct StringMaker<std::string_view> {
+ static std::string convert(std::string_view str);
+ };
+#endif
+
+ template<>
+ struct StringMaker<char const *> {
+ static std::string convert(char const * str);
+ };
+ template<>
+ struct StringMaker<char *> {
+ static std::string convert(char * str);
+ };
+
+#ifdef CATCH_CONFIG_WCHAR
+ template<>
+ struct StringMaker<std::wstring> {
+ static std::string convert(const std::wstring& wstr);
+ };
+
+# ifdef CATCH_CONFIG_CPP17_STRING_VIEW
+ template<>
+ struct StringMaker<std::wstring_view> {
+ static std::string convert(std::wstring_view str);
+ };
+# endif
+
+ template<>
+ struct StringMaker<wchar_t const *> {
+ static std::string convert(wchar_t const * str);
+ };
+ template<>
+ struct StringMaker<wchar_t *> {
+ static std::string convert(wchar_t * str);
+ };
+#endif
+
+ // TBD: Should we use `strnlen` to ensure that we don't go out of the buffer,
+ // while keeping string semantics?
+ template<int SZ>
+ struct StringMaker<char[SZ]> {
+ static std::string convert(char const* str) {
+ return ::Catch::Detail::stringify(std::string{ str });
+ }
+ };
+ template<int SZ>
+ struct StringMaker<signed char[SZ]> {
+ static std::string convert(signed char const* str) {
+ return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
+ }
+ };
+ template<int SZ>
+ struct StringMaker<unsigned char[SZ]> {
+ static std::string convert(unsigned char const* str) {
+ return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
+ }
+ };
+
+#if defined(CATCH_CONFIG_CPP17_BYTE)
+ template<>
+ struct StringMaker<std::byte> {
+ static std::string convert(std::byte value);
+ };
+#endif // defined(CATCH_CONFIG_CPP17_BYTE)
+ template<>
+ struct StringMaker<int> {
+ static std::string convert(int value);
+ };
+ template<>
+ struct StringMaker<long> {
+ static std::string convert(long value);
+ };
+ template<>
+ struct StringMaker<long long> {
+ static std::string convert(long long value);
+ };
+ template<>
+ struct StringMaker<unsigned int> {
+ static std::string convert(unsigned int value);
+ };
+ template<>
+ struct StringMaker<unsigned long> {
+ static std::string convert(unsigned long value);
+ };
+ template<>
+ struct StringMaker<unsigned long long> {
+ static std::string convert(unsigned long long value);
+ };
+
+ template<>
+ struct StringMaker<bool> {
+ static std::string convert(bool b);
+ };
+
+ template<>
+ struct StringMaker<char> {
+ static std::string convert(char c);
+ };
+ template<>
+ struct StringMaker<signed char> {
+ static std::string convert(signed char c);
+ };
+ template<>
+ struct StringMaker<unsigned char> {
+ static std::string convert(unsigned char c);
+ };
+
+ template<>
+ struct StringMaker<std::nullptr_t> {
+ static std::string convert(std::nullptr_t);
+ };
+
+ template<>
+ struct StringMaker<float> {
+ static std::string convert(float value);
+ static int precision;
+ };
+
+ template<>
+ struct StringMaker<double> {
+ static std::string convert(double value);
+ static int precision;
+ };
+
+ template <typename T>
+ struct StringMaker<T*> {
+ template <typename U>
+ static std::string convert(U* p) {
+ if (p) {
+ return ::Catch::Detail::rawMemoryToString(p);
+ } else {
+ return "nullptr";
+ }
+ }
+ };
+
+ template <typename R, typename C>
+ struct StringMaker<R C::*> {
+ static std::string convert(R C::* p) {
+ if (p) {
+ return ::Catch::Detail::rawMemoryToString(p);
+ } else {
+ return "nullptr";
+ }
+ }
+ };
+
+#if defined(_MANAGED)
+ template <typename T>
+ struct StringMaker<T^> {
+ static std::string convert( T^ ref ) {
+ return ::Catch::Detail::clrReferenceToString(ref);
+ }
+ };
+#endif
+
+ namespace Detail {
+ template<typename InputIterator, typename Sentinel = InputIterator>
+ std::string rangeToString(InputIterator first, Sentinel last) {
+ ReusableStringStream rss;
+ rss << "{ ";
+ if (first != last) {
+ rss << ::Catch::Detail::stringify(*first);
+ for (++first; first != last; ++first)
+ rss << ", " << ::Catch::Detail::stringify(*first);
+ }
+ rss << " }";
+ return rss.str();
+ }
+ }
+
+#ifdef __OBJC__
+ template<>
+ struct StringMaker<NSString*> {
+ static std::string convert(NSString * nsstring) {
+ if (!nsstring)
+ return "nil";
+ return std::string("@") + [nsstring UTF8String];
+ }
+ };
+ template<>
+ struct StringMaker<NSObject*> {
+ static std::string convert(NSObject* nsObject) {
+ return ::Catch::Detail::stringify([nsObject description]);
+ }
+
+ };
+ namespace Detail {
+ inline std::string stringify( NSString* nsstring ) {
+ return StringMaker<NSString*>::convert( nsstring );
+ }
+
+ } // namespace Detail
+#endif // __OBJC__
+
+} // namespace Catch
+
+//////////////////////////////////////////////////////
+// Separate std-lib types stringification, so it can be selectively enabled
+// This means that we do not bring in
+
+#if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS)
+# define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
+# define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
+# define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
+# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
+# define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER
+#endif
+
+// Separate std::pair specialization
+#if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER)
+#include <utility>
+namespace Catch {
+ template<typename T1, typename T2>
+ struct StringMaker<std::pair<T1, T2> > {
+ static std::string convert(const std::pair<T1, T2>& pair) {
+ ReusableStringStream rss;
+ rss << "{ "
+ << ::Catch::Detail::stringify(pair.first)
+ << ", "
+ << ::Catch::Detail::stringify(pair.second)
+ << " }";
+ return rss.str();
+ }
+ };
+}
+#endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
+
+#if defined(CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_OPTIONAL)
+#include <optional>
+namespace Catch {
+ template<typename T>
+ struct StringMaker<std::optional<T> > {
+ static std::string convert(const std::optional<T>& optional) {
+ ReusableStringStream rss;
+ if (optional.has_value()) {
+ rss << ::Catch::Detail::stringify(*optional);
+ } else {
+ rss << "{ }";
+ }
+ return rss.str();
+ }
+ };
+}
+#endif // CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER
+
+// Separate std::tuple specialization
+#if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER)
+#include <tuple>
+namespace Catch {
+ namespace Detail {
+ template<
+ typename Tuple,
+ std::size_t N = 0,
+ bool = (N < std::tuple_size<Tuple>::value)
+ >
+ struct TupleElementPrinter {
+ static void print(const Tuple& tuple, std::ostream& os) {
+ os << (N ? ", " : " ")
+ << ::Catch::Detail::stringify(std::get<N>(tuple));
+ TupleElementPrinter<Tuple, N + 1>::print(tuple, os);
+ }
+ };
+
+ template<
+ typename Tuple,
+ std::size_t N
+ >
+ struct TupleElementPrinter<Tuple, N, false> {
+ static void print(const Tuple&, std::ostream&) {}
+ };
+
+ }
+
+ template<typename ...Types>
+ struct StringMaker<std::tuple<Types...>> {
+ static std::string convert(const std::tuple<Types...>& tuple) {
+ ReusableStringStream rss;
+ rss << '{';
+ Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, rss.get());
+ rss << " }";
+ return rss.str();
+ }
+ };
+}
+#endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
+
+#if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT)
+#include <variant>
+namespace Catch {
+ template<>
+ struct StringMaker<std::monostate> {
+ static std::string convert(const std::monostate&) {
+ return "{ }";
+ }
+ };
+
+ template<typename... Elements>
+ struct StringMaker<std::variant<Elements...>> {
+ static std::string convert(const std::variant<Elements...>& variant) {
+ if (variant.valueless_by_exception()) {
+ return "{valueless variant}";
+ } else {
+ return std::visit(
+ [](const auto& value) {
+ return ::Catch::Detail::stringify(value);
+ },
+ variant
+ );
+ }
+ }
+ };
+}
+#endif // CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
+
+namespace Catch {
+ // Import begin/ end from std here
+ using std::begin;
+ using std::end;
+
+ namespace detail {
+ template <typename...>
+ struct void_type {
+ using type = void;
+ };
+
+ template <typename T, typename = void>
+ struct is_range_impl : std::false_type {
+ };
+
+ template <typename T>
+ struct is_range_impl<T, typename void_type<decltype(begin(std::declval<T>()))>::type> : std::true_type {
+ };
+ } // namespace detail
+
+ template <typename T>
+ struct is_range : detail::is_range_impl<T> {
+ };
+
+#if defined(_MANAGED) // Managed types are never ranges
+ template <typename T>
+ struct is_range<T^> {
+ static const bool value = false;
+ };
+#endif
+
+ template<typename Range>
+ std::string rangeToString( Range const& range ) {
+ return ::Catch::Detail::rangeToString( begin( range ), end( range ) );
+ }
+
+ // Handle vector<bool> specially
+ template<typename Allocator>
+ std::string rangeToString( std::vector<bool, Allocator> const& v ) {
+ ReusableStringStream rss;
+ rss << "{ ";
+ bool first = true;
+ for( bool b : v ) {
+ if( first )
+ first = false;
+ else
+ rss << ", ";
+ rss << ::Catch::Detail::stringify( b );
+ }
+ rss << " }";
+ return rss.str();
+ }
+
+ template<typename R>
+ struct StringMaker<R, typename std::enable_if<is_range<R>::value && !::Catch::Detail::IsStreamInsertable<R>::value>::type> {
+ static std::string convert( R const& range ) {
+ return rangeToString( range );
+ }
+ };
+
+ template <typename T, int SZ>
+ struct StringMaker<T[SZ]> {
+ static std::string convert(T const(&arr)[SZ]) {
+ return rangeToString(arr);
+ }
+ };
+
+} // namespace Catch
+
+// Separate std::chrono::duration specialization
+#if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
+#include <ctime>
+#include <ratio>
+#include <chrono>
+
+namespace Catch {
+
+template <class Ratio>
+struct ratio_string {
+ static std::string symbol();
+};
+
+template <class Ratio>
+std::string ratio_string<Ratio>::symbol() {
+ Catch::ReusableStringStream rss;
+ rss << '[' << Ratio::num << '/'
+ << Ratio::den << ']';
+ return rss.str();
+}
+template <>
+struct ratio_string<std::atto> {
+ static std::string symbol();
+};
+template <>
+struct ratio_string<std::femto> {
+ static std::string symbol();
+};
+template <>
+struct ratio_string<std::pico> {
+ static std::string symbol();
+};
+template <>
+struct ratio_string<std::nano> {
+ static std::string symbol();
+};
+template <>
+struct ratio_string<std::micro> {
+ static std::string symbol();
+};
+template <>
+struct ratio_string<std::milli> {
+ static std::string symbol();
+};
+
+ ////////////
+ // std::chrono::duration specializations
+ template<typename Value, typename Ratio>
+ struct StringMaker<std::chrono::duration<Value, Ratio>> {
+ static std::string convert(std::chrono::duration<Value, Ratio> const& duration) {
+ ReusableStringStream rss;
+ rss << duration.count() << ' ' << ratio_string<Ratio>::symbol() << 's';
+ return rss.str();
+ }
+ };
+ template<typename Value>
+ struct StringMaker<std::chrono::duration<Value, std::ratio<1>>> {
+ static std::string convert(std::chrono::duration<Value, std::ratio<1>> const& duration) {
+ ReusableStringStream rss;
+ rss << duration.count() << " s";
+ return rss.str();
+ }
+ };
+ template<typename Value>
+ struct StringMaker<std::chrono::duration<Value, std::ratio<60>>> {
+ static std::string convert(std::chrono::duration<Value, std::ratio<60>> const& duration) {
+ ReusableStringStream rss;
+ rss << duration.count() << " m";
+ return rss.str();
+ }
+ };
+ template<typename Value>
+ struct StringMaker<std::chrono::duration<Value, std::ratio<3600>>> {
+ static std::string convert(std::chrono::duration<Value, std::ratio<3600>> const& duration) {
+ ReusableStringStream rss;
+ rss << duration.count() << " h";
+ return rss.str();
+ }
+ };
+
+ ////////////
+ // std::chrono::time_point specialization
+ // Generic time_point cannot be specialized, only std::chrono::time_point<system_clock>
+ template<typename Clock, typename Duration>
+ struct StringMaker<std::chrono::time_point<Clock, Duration>> {
+ static std::string convert(std::chrono::time_point<Clock, Duration> const& time_point) {
+ return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch";
+ }
+ };
+ // std::chrono::time_point<system_clock> specialization
+ template<typename Duration>
+ struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
+ static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
+ auto converted = std::chrono::system_clock::to_time_t(time_point);
+
+#ifdef _MSC_VER
+ std::tm timeInfo = {};
+ gmtime_s(&timeInfo, &converted);
+#else
+ std::tm* timeInfo = std::gmtime(&converted);
+#endif
+
+ auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
+ char timeStamp[timeStampSize];
+ const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
+
+#ifdef _MSC_VER
+ std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
+#else
+ std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
+#endif
+ return std::string(timeStamp);
+ }
+ };
+}
+#endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
+
+#define INTERNAL_CATCH_REGISTER_ENUM( enumName, ... ) \
+namespace Catch { \
+ template<> struct StringMaker<enumName> { \
+ static std::string convert( enumName value ) { \
+ static const auto& enumInfo = ::Catch::getMutableRegistryHub().getMutableEnumValuesRegistry().registerEnum( #enumName, #__VA_ARGS__, { __VA_ARGS__ } ); \
+ return static_cast<std::string>(enumInfo.lookup( static_cast<int>( value ) )); \
+ } \
+ }; \
+}
+
+#define CATCH_REGISTER_ENUM( enumName, ... ) INTERNAL_CATCH_REGISTER_ENUM( enumName, __VA_ARGS__ )
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+// end catch_tostring.h
+#include <iosfwd>
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4389) // '==' : signed/unsigned mismatch
+#pragma warning(disable:4018) // more "signed/unsigned mismatch"
+#pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform)
+#pragma warning(disable:4180) // qualifier applied to function type has no meaning
+#pragma warning(disable:4800) // Forcing result to true or false
+#endif
+
+namespace Catch {
+
+ struct ITransientExpression {
+ auto isBinaryExpression() const -> bool { return m_isBinaryExpression; }
+ auto getResult() const -> bool { return m_result; }
+ virtual void streamReconstructedExpression( std::ostream &os ) const = 0;
+
+ ITransientExpression( bool isBinaryExpression, bool result )
+ : m_isBinaryExpression( isBinaryExpression ),
+ m_result( result )
+ {}
+
+ // We don't actually need a virtual destructor, but many static analysers
+ // complain if it's not here :-(
+ virtual ~ITransientExpression();
+
+ bool m_isBinaryExpression;
+ bool m_result;
+
+ };
+
+ void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs );
+
+ template<typename LhsT, typename RhsT>
+ class BinaryExpr : public ITransientExpression {
+ LhsT m_lhs;
+ StringRef m_op;
+ RhsT m_rhs;
+
+ void streamReconstructedExpression( std::ostream &os ) const override {
+ formatReconstructedExpression
+ ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) );
+ }
+
+ public:
+ BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs )
+ : ITransientExpression{ true, comparisonResult },
+ m_lhs( lhs ),
+ m_op( op ),
+ m_rhs( rhs )
+ {}
+
+ template<typename T>
+ auto operator && ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
+ static_assert(always_false<T>::value,
+ "chained comparisons are not supported inside assertions, "
+ "wrap the expression inside parentheses, or decompose it");
+ }
+
+ template<typename T>
+ auto operator || ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
+ static_assert(always_false<T>::value,
+ "chained comparisons are not supported inside assertions, "
+ "wrap the expression inside parentheses, or decompose it");
+ }
+
+ template<typename T>
+ auto operator == ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
+ static_assert(always_false<T>::value,
+ "chained comparisons are not supported inside assertions, "
+ "wrap the expression inside parentheses, or decompose it");
+ }
+
+ template<typename T>
+ auto operator != ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
+ static_assert(always_false<T>::value,
+ "chained comparisons are not supported inside assertions, "
+ "wrap the expression inside parentheses, or decompose it");
+ }
+
+ template<typename T>
+ auto operator > ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
+ static_assert(always_false<T>::value,
+ "chained comparisons are not supported inside assertions, "
+ "wrap the expression inside parentheses, or decompose it");
+ }
+
+ template<typename T>
+ auto operator < ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
+ static_assert(always_false<T>::value,
+ "chained comparisons are not supported inside assertions, "
+ "wrap the expression inside parentheses, or decompose it");
+ }
+
+ template<typename T>
+ auto operator >= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
+ static_assert(always_false<T>::value,
+ "chained comparisons are not supported inside assertions, "
+ "wrap the expression inside parentheses, or decompose it");
+ }
+
+ template<typename T>
+ auto operator <= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
+ static_assert(always_false<T>::value,
+ "chained comparisons are not supported inside assertions, "
+ "wrap the expression inside parentheses, or decompose it");
+ }
+ };
+
+ template<typename LhsT>
+ class UnaryExpr : public ITransientExpression {
+ LhsT m_lhs;
+
+ void streamReconstructedExpression( std::ostream &os ) const override {
+ os << Catch::Detail::stringify( m_lhs );
+ }
+
+ public:
+ explicit UnaryExpr( LhsT lhs )
+ : ITransientExpression{ false, static_cast<bool>(lhs) },
+ m_lhs( lhs )
+ {}
+ };
+
+ // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int)
+ template<typename LhsT, typename RhsT>
+ auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast<bool>(lhs == rhs); }
+ template<typename T>
+ auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
+ template<typename T>
+ auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
+ template<typename T>
+ auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
+ template<typename T>
+ auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
+
+ template<typename LhsT, typename RhsT>
+ auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast<bool>(lhs != rhs); }
+ template<typename T>
+ auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
+ template<typename T>
+ auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
+ template<typename T>
+ auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
+ template<typename T>
+ auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
+
+ template<typename LhsT>
+ class ExprLhs {
+ LhsT m_lhs;
+ public:
+ explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {}
+
+ template<typename RhsT>
+ auto operator == ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+ return { compareEqual( m_lhs, rhs ), m_lhs, "==", rhs };
+ }
+ auto operator == ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
+ return { m_lhs == rhs, m_lhs, "==", rhs };
+ }
+
+ template<typename RhsT>
+ auto operator != ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+ return { compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs };
+ }
+ auto operator != ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
+ return { m_lhs != rhs, m_lhs, "!=", rhs };
+ }
+
+ template<typename RhsT>
+ auto operator > ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+ return { static_cast<bool>(m_lhs > rhs), m_lhs, ">", rhs };
+ }
+ template<typename RhsT>
+ auto operator < ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+ return { static_cast<bool>(m_lhs < rhs), m_lhs, "<", rhs };
+ }
+ template<typename RhsT>
+ auto operator >= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+ return { static_cast<bool>(m_lhs >= rhs), m_lhs, ">=", rhs };
+ }
+ template<typename RhsT>
+ auto operator <= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
+ return { static_cast<bool>(m_lhs <= rhs), m_lhs, "<=", rhs };
+ }
+ template <typename RhsT>
+ auto operator | (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
+ return { static_cast<bool>(m_lhs | rhs), m_lhs, "|", rhs };
+ }
+ template <typename RhsT>
+ auto operator & (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
+ return { static_cast<bool>(m_lhs & rhs), m_lhs, "&", rhs };
+ }
+ template <typename RhsT>
+ auto operator ^ (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
+ return { static_cast<bool>(m_lhs ^ rhs), m_lhs, "^", rhs };
+ }
+
+ template<typename RhsT>
+ auto operator && ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const {
+ static_assert(always_false<RhsT>::value,
+ "operator&& is not supported inside assertions, "
+ "wrap the expression inside parentheses, or decompose it");
+ }
+
+ template<typename RhsT>
+ auto operator || ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const {
+ static_assert(always_false<RhsT>::value,
+ "operator|| is not supported inside assertions, "
+ "wrap the expression inside parentheses, or decompose it");
+ }
+
+ auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
+ return UnaryExpr<LhsT>{ m_lhs };
+ }
+ };
+
+ void handleExpression( ITransientExpression const& expr );
+
+ template<typename T>
+ void handleExpression( ExprLhs<T> const& expr ) {
+ handleExpression( expr.makeUnaryExpr() );
+ }
+
+ struct Decomposer {
+ template<typename T>
+ auto operator <= ( T const& lhs ) -> ExprLhs<T const&> {
+ return ExprLhs<T const&>{ lhs };
+ }
+
+ auto operator <=( bool value ) -> ExprLhs<bool> {
+ return ExprLhs<bool>{ value };
+ }
+ };
+
+} // end namespace Catch
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+// end catch_decomposer.h
+// start catch_interfaces_capture.h
+
+#include <string>
+#include <chrono>
+
+namespace Catch {
+
+ class AssertionResult;
+ struct AssertionInfo;
+ struct SectionInfo;
+ struct SectionEndInfo;
+ struct MessageInfo;
+ struct MessageBuilder;
+ struct Counts;
+ struct AssertionReaction;
+ struct SourceLineInfo;
+
+ struct ITransientExpression;
+ struct IGeneratorTracker;
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ struct BenchmarkInfo;
+ template <typename Duration = std::chrono::duration<double, std::nano>>
+ struct BenchmarkStats;
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ struct IResultCapture {
+
+ virtual ~IResultCapture();
+
+ virtual bool sectionStarted( SectionInfo const& sectionInfo,
+ Counts& assertions ) = 0;
+ virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
+ virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
+
+ virtual auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& = 0;
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ virtual void benchmarkPreparing( std::string const& name ) = 0;
+ virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0;
+ virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0;
+ virtual void benchmarkFailed( std::string const& error ) = 0;
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ virtual void pushScopedMessage( MessageInfo const& message ) = 0;
+ virtual void popScopedMessage( MessageInfo const& message ) = 0;
+
+ virtual void emplaceUnscopedMessage( MessageBuilder const& builder ) = 0;
+
+ virtual void handleFatalErrorCondition( StringRef message ) = 0;
+
+ virtual void handleExpr
+ ( AssertionInfo const& info,
+ ITransientExpression const& expr,
+ AssertionReaction& reaction ) = 0;
+ virtual void handleMessage
+ ( AssertionInfo const& info,
+ ResultWas::OfType resultType,
+ StringRef const& message,
+ AssertionReaction& reaction ) = 0;
+ virtual void handleUnexpectedExceptionNotThrown
+ ( AssertionInfo const& info,
+ AssertionReaction& reaction ) = 0;
+ virtual void handleUnexpectedInflightException
+ ( AssertionInfo const& info,
+ std::string const& message,
+ AssertionReaction& reaction ) = 0;
+ virtual void handleIncomplete
+ ( AssertionInfo const& info ) = 0;
+ virtual void handleNonExpr
+ ( AssertionInfo const &info,
+ ResultWas::OfType resultType,
+ AssertionReaction &reaction ) = 0;
+
+ virtual bool lastAssertionPassed() = 0;
+ virtual void assertionPassed() = 0;
+
+ // Deprecated, do not use:
+ virtual std::string getCurrentTestName() const = 0;
+ virtual const AssertionResult* getLastResult() const = 0;
+ virtual void exceptionEarlyReported() = 0;
+ };
+
+ IResultCapture& getResultCapture();
+}
+
+// end catch_interfaces_capture.h
+namespace Catch {
+
+ struct TestFailureException{};
+ struct AssertionResultData;
+ struct IResultCapture;
+ class RunContext;
+
+ class LazyExpression {
+ friend class AssertionHandler;
+ friend struct AssertionStats;
+ friend class RunContext;
+
+ ITransientExpression const* m_transientExpression = nullptr;
+ bool m_isNegated;
+ public:
+ LazyExpression( bool isNegated );
+ LazyExpression( LazyExpression const& other );
+ LazyExpression& operator = ( LazyExpression const& ) = delete;
+
+ explicit operator bool() const;
+
+ friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
+ };
+
+ struct AssertionReaction {
+ bool shouldDebugBreak = false;
+ bool shouldThrow = false;
+ };
+
+ class AssertionHandler {
+ AssertionInfo m_assertionInfo;
+ AssertionReaction m_reaction;
+ bool m_completed = false;
+ IResultCapture& m_resultCapture;
+
+ public:
+ AssertionHandler
+ ( StringRef const& macroName,
+ SourceLineInfo const& lineInfo,
+ StringRef capturedExpression,
+ ResultDisposition::Flags resultDisposition );
+ ~AssertionHandler() {
+ if ( !m_completed ) {
+ m_resultCapture.handleIncomplete( m_assertionInfo );
+ }
+ }
+
+ template<typename T>
+ void handleExpr( ExprLhs<T> const& expr ) {
+ handleExpr( expr.makeUnaryExpr() );
+ }
+ void handleExpr( ITransientExpression const& expr );
+
+ void handleMessage(ResultWas::OfType resultType, StringRef const& message);
+
+ void handleExceptionThrownAsExpected();
+ void handleUnexpectedExceptionNotThrown();
+ void handleExceptionNotThrownAsExpected();
+ void handleThrowingCallSkipped();
+ void handleUnexpectedInflightException();
+
+ void complete();
+ void setCompleted();
+
+ // query
+ auto allowThrows() const -> bool;
+ };
+
+ void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString );
+
+} // namespace Catch
+
+// end catch_assertionhandler.h
+// start catch_message.h
+
+#include <string>
+#include <vector>
+
+namespace Catch {
+
+ struct MessageInfo {
+ MessageInfo( StringRef const& _macroName,
+ SourceLineInfo const& _lineInfo,
+ ResultWas::OfType _type );
+
+ StringRef macroName;
+ std::string message;
+ SourceLineInfo lineInfo;
+ ResultWas::OfType type;
+ unsigned int sequence;
+
+ bool operator == ( MessageInfo const& other ) const;
+ bool operator < ( MessageInfo const& other ) const;
+ private:
+ static unsigned int globalCount;
+ };
+
+ struct MessageStream {
+
+ template<typename T>
+ MessageStream& operator << ( T const& value ) {
+ m_stream << value;
+ return *this;
+ }
+
+ ReusableStringStream m_stream;
+ };
+
+ struct MessageBuilder : MessageStream {
+ MessageBuilder( StringRef const& macroName,
+ SourceLineInfo const& lineInfo,
+ ResultWas::OfType type );
+
+ template<typename T>
+ MessageBuilder& operator << ( T const& value ) {
+ m_stream << value;
+ return *this;
+ }
+
+ MessageInfo m_info;
+ };
+
+ class ScopedMessage {
+ public:
+ explicit ScopedMessage( MessageBuilder const& builder );
+ ScopedMessage( ScopedMessage& duplicate ) = delete;
+ ScopedMessage( ScopedMessage&& old );
+ ~ScopedMessage();
+
+ MessageInfo m_info;
+ bool m_moved;
+ };
+
+ class Capturer {
+ std::vector<MessageInfo> m_messages;
+ IResultCapture& m_resultCapture = getResultCapture();
+ size_t m_captured = 0;
+ public:
+ Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names );
+ ~Capturer();
+
+ void captureValue( size_t index, std::string const& value );
+
+ template<typename T>
+ void captureValues( size_t index, T const& value ) {
+ captureValue( index, Catch::Detail::stringify( value ) );
+ }
+
+ template<typename T, typename... Ts>
+ void captureValues( size_t index, T const& value, Ts const&... values ) {
+ captureValue( index, Catch::Detail::stringify(value) );
+ captureValues( index+1, values... );
+ }
+ };
+
+} // end namespace Catch
+
+// end catch_message.h
+#if !defined(CATCH_CONFIG_DISABLE)
+
+#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
+ #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__
+#else
+ #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
+#endif
+
+#if defined(CATCH_CONFIG_FAST_COMPILE) || defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+
+///////////////////////////////////////////////////////////////////////////////
+// Another way to speed-up compilation is to omit local try-catch for REQUIRE*
+// macros.
+#define INTERNAL_CATCH_TRY
+#define INTERNAL_CATCH_CATCH( capturer )
+
+#else // CATCH_CONFIG_FAST_COMPILE
+
+#define INTERNAL_CATCH_TRY try
+#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); }
+
+#endif
+
+#define INTERNAL_CATCH_REACT( handler ) handler.complete();
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
+ do { \
+ CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \
+ Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
+ INTERNAL_CATCH_TRY { \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
+ catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
+ INTERNAL_CATCH_REACT( catchAssertionHandler ) \
+ } while( (void)0, (false) && static_cast<bool>( !!(__VA_ARGS__) ) )
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
+ INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
+ if( Catch::getResultCapture().lastAssertionPassed() )
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
+ INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
+ if( !Catch::getResultCapture().lastAssertionPassed() )
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
+ do { \
+ Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
+ try { \
+ static_cast<void>(__VA_ARGS__); \
+ catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
+ } \
+ catch( ... ) { \
+ catchAssertionHandler.handleUnexpectedInflightException(); \
+ } \
+ INTERNAL_CATCH_REACT( catchAssertionHandler ) \
+ } while( false )
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
+ do { \
+ Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \
+ if( catchAssertionHandler.allowThrows() ) \
+ try { \
+ static_cast<void>(__VA_ARGS__); \
+ catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
+ } \
+ catch( ... ) { \
+ catchAssertionHandler.handleExceptionThrownAsExpected(); \
+ } \
+ else \
+ catchAssertionHandler.handleThrowingCallSkipped(); \
+ INTERNAL_CATCH_REACT( catchAssertionHandler ) \
+ } while( false )
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
+ do { \
+ Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
+ if( catchAssertionHandler.allowThrows() ) \
+ try { \
+ static_cast<void>(expr); \
+ catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
+ } \
+ catch( exceptionType const& ) { \
+ catchAssertionHandler.handleExceptionThrownAsExpected(); \
+ } \
+ catch( ... ) { \
+ catchAssertionHandler.handleUnexpectedInflightException(); \
+ } \
+ else \
+ catchAssertionHandler.handleThrowingCallSkipped(); \
+ INTERNAL_CATCH_REACT( catchAssertionHandler ) \
+ } while( false )
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
+ do { \
+ Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \
+ catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
+ INTERNAL_CATCH_REACT( catchAssertionHandler ) \
+ } while( false )
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \
+ auto varName = Catch::Capturer( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info, #__VA_ARGS__ ); \
+ varName.captureValues( 0, __VA_ARGS__ )
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_INFO( macroName, log ) \
+ Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log );
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
+ Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
+
+///////////////////////////////////////////////////////////////////////////////
+// Although this is matcher-based, it can be used with just a string
+#define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \
+ do { \
+ Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
+ if( catchAssertionHandler.allowThrows() ) \
+ try { \
+ static_cast<void>(__VA_ARGS__); \
+ catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
+ } \
+ catch( ... ) { \
+ Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher##_catch_sr ); \
+ } \
+ else \
+ catchAssertionHandler.handleThrowingCallSkipped(); \
+ INTERNAL_CATCH_REACT( catchAssertionHandler ) \
+ } while( false )
+
+#endif // CATCH_CONFIG_DISABLE
+
+// end catch_capture.hpp
+// start catch_section.h
+
+// start catch_section_info.h
+
+// start catch_totals.h
+
+#include <cstddef>
+
+namespace Catch {
+
+ struct Counts {
+ Counts operator - ( Counts const& other ) const;
+ Counts& operator += ( Counts const& other );
+
+ std::size_t total() const;
+ bool allPassed() const;
+ bool allOk() const;
+
+ std::size_t passed = 0;
+ std::size_t failed = 0;
+ std::size_t failedButOk = 0;
+ };
+
+ struct Totals {
+
+ Totals operator - ( Totals const& other ) const;
+ Totals& operator += ( Totals const& other );
+
+ Totals delta( Totals const& prevTotals ) const;
+
+ int error = 0;
+ Counts assertions;
+ Counts testCases;
+ };
+}
+
+// end catch_totals.h
+#include <string>
+
+namespace Catch {
+
+ struct SectionInfo {
+ SectionInfo
+ ( SourceLineInfo const& _lineInfo,
+ std::string const& _name );
+
+ // Deprecated
+ SectionInfo
+ ( SourceLineInfo const& _lineInfo,
+ std::string const& _name,
+ std::string const& ) : SectionInfo( _lineInfo, _name ) {}
+
+ std::string name;
+ std::string description; // !Deprecated: this will always be empty
+ SourceLineInfo lineInfo;
+ };
+
+ struct SectionEndInfo {
+ SectionInfo sectionInfo;
+ Counts prevAssertions;
+ double durationInSeconds;
+ };
+
+} // end namespace Catch
+
+// end catch_section_info.h
+// start catch_timer.h
+
+#include <cstdint>
+
+namespace Catch {
+
+ auto getCurrentNanosecondsSinceEpoch() -> uint64_t;
+ auto getEstimatedClockResolution() -> uint64_t;
+
+ class Timer {
+ uint64_t m_nanoseconds = 0;
+ public:
+ void start();
+ auto getElapsedNanoseconds() const -> uint64_t;
+ auto getElapsedMicroseconds() const -> uint64_t;
+ auto getElapsedMilliseconds() const -> unsigned int;
+ auto getElapsedSeconds() const -> double;
+ };
+
+} // namespace Catch
+
+// end catch_timer.h
+#include <string>
+
+namespace Catch {
+
+ class Section : NonCopyable {
+ public:
+ Section( SectionInfo const& info );
+ ~Section();
+
+ // This indicates whether the section should be executed or not
+ explicit operator bool() const;
+
+ private:
+ SectionInfo m_info;
+
+ std::string m_name;
+ Counts m_assertions;
+ bool m_sectionIncluded;
+ Timer m_timer;
+ };
+
+} // end namespace Catch
+
+#define INTERNAL_CATCH_SECTION( ... ) \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
+ if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
+
+#define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
+ if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, (Catch::ReusableStringStream() << __VA_ARGS__).str() ) ) \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
+
+// end catch_section.h
+// start catch_interfaces_exception.h
+
+// start catch_interfaces_registry_hub.h
+
+#include <string>
+#include <memory>
+
+namespace Catch {
+
+ class TestCase;
+ struct ITestCaseRegistry;
+ struct IExceptionTranslatorRegistry;
+ struct IExceptionTranslator;
+ struct IReporterRegistry;
+ struct IReporterFactory;
+ struct ITagAliasRegistry;
+ struct IMutableEnumValuesRegistry;
+
+ class StartupExceptionRegistry;
+
+ using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
+
+ struct IRegistryHub {
+ virtual ~IRegistryHub();
+
+ virtual IReporterRegistry const& getReporterRegistry() const = 0;
+ virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
+ virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
+ virtual IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0;
+
+ virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0;
+ };
+
+ struct IMutableRegistryHub {
+ virtual ~IMutableRegistryHub();
+ virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0;
+ virtual void registerListener( IReporterFactoryPtr const& factory ) = 0;
+ virtual void registerTest( TestCase const& testInfo ) = 0;
+ virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
+ virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
+ virtual void registerStartupException() noexcept = 0;
+ virtual IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() = 0;
+ };
+
+ IRegistryHub const& getRegistryHub();
+ IMutableRegistryHub& getMutableRegistryHub();
+ void cleanUp();
+ std::string translateActiveException();
+
+}
+
+// end catch_interfaces_registry_hub.h
+#if defined(CATCH_CONFIG_DISABLE)
+ #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \
+ static std::string translatorName( signature )
+#endif
+
+#include <exception>
+#include <string>
+#include <vector>
+
+namespace Catch {
+ using exceptionTranslateFunction = std::string(*)();
+
+ struct IExceptionTranslator;
+ using ExceptionTranslators = std::vector<std::unique_ptr<IExceptionTranslator const>>;
+
+ struct IExceptionTranslator {
+ virtual ~IExceptionTranslator();
+ virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
+ };
+
+ struct IExceptionTranslatorRegistry {
+ virtual ~IExceptionTranslatorRegistry();
+
+ virtual std::string translateActiveException() const = 0;
+ };
+
+ class ExceptionTranslatorRegistrar {
+ template<typename T>
+ class ExceptionTranslator : public IExceptionTranslator {
+ public:
+
+ ExceptionTranslator( std::string(*translateFunction)( T& ) )
+ : m_translateFunction( translateFunction )
+ {}
+
+ std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
+#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+ return "";
+#else
+ try {
+ if( it == itEnd )
+ std::rethrow_exception(std::current_exception());
+ else
+ return (*it)->translate( it+1, itEnd );
+ }
+ catch( T& ex ) {
+ return m_translateFunction( ex );
+ }
+#endif
+ }
+
+ protected:
+ std::string(*m_translateFunction)( T& );
+ };
+
+ public:
+ template<typename T>
+ ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
+ getMutableRegistryHub().registerTranslator
+ ( new ExceptionTranslator<T>( translateFunction ) );
+ }
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
+ static std::string translatorName( signature ); \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ static std::string translatorName( signature )
+
+#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
+
+// end catch_interfaces_exception.h
+// start catch_approx.h
+
+#include <type_traits>
+
+namespace Catch {
+namespace Detail {
+
+ class Approx {
+ private:
+ bool equalityComparisonImpl(double other) const;
+ // Validates the new margin (margin >= 0)
+ // out-of-line to avoid including stdexcept in the header
+ void setMargin(double margin);
+ // Validates the new epsilon (0 < epsilon < 1)
+ // out-of-line to avoid including stdexcept in the header
+ void setEpsilon(double epsilon);
+
+ public:
+ explicit Approx ( double value );
+
+ static Approx custom();
+
+ Approx operator-() const;
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ Approx operator()( T const& value ) const {
+ Approx approx( static_cast<double>(value) );
+ approx.m_epsilon = m_epsilon;
+ approx.m_margin = m_margin;
+ approx.m_scale = m_scale;
+ return approx;
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ explicit Approx( T const& value ): Approx(static_cast<double>(value))
+ {}
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator == ( const T& lhs, Approx const& rhs ) {
+ auto lhs_v = static_cast<double>(lhs);
+ return rhs.equalityComparisonImpl(lhs_v);
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator == ( Approx const& lhs, const T& rhs ) {
+ return operator==( rhs, lhs );
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator != ( T const& lhs, Approx const& rhs ) {
+ return !operator==( lhs, rhs );
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator != ( Approx const& lhs, T const& rhs ) {
+ return !operator==( rhs, lhs );
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator <= ( T const& lhs, Approx const& rhs ) {
+ return static_cast<double>(lhs) < rhs.m_value || lhs == rhs;
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator <= ( Approx const& lhs, T const& rhs ) {
+ return lhs.m_value < static_cast<double>(rhs) || lhs == rhs;
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator >= ( T const& lhs, Approx const& rhs ) {
+ return static_cast<double>(lhs) > rhs.m_value || lhs == rhs;
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator >= ( Approx const& lhs, T const& rhs ) {
+ return lhs.m_value > static_cast<double>(rhs) || lhs == rhs;
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ Approx& epsilon( T const& newEpsilon ) {
+ double epsilonAsDouble = static_cast<double>(newEpsilon);
+ setEpsilon(epsilonAsDouble);
+ return *this;
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ Approx& margin( T const& newMargin ) {
+ double marginAsDouble = static_cast<double>(newMargin);
+ setMargin(marginAsDouble);
+ return *this;
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ Approx& scale( T const& newScale ) {
+ m_scale = static_cast<double>(newScale);
+ return *this;
+ }
+
+ std::string toString() const;
+
+ private:
+ double m_epsilon;
+ double m_margin;
+ double m_scale;
+ double m_value;
+ };
+} // end namespace Detail
+
+namespace literals {
+ Detail::Approx operator "" _a(long double val);
+ Detail::Approx operator "" _a(unsigned long long val);
+} // end namespace literals
+
+template<>
+struct StringMaker<Catch::Detail::Approx> {
+ static std::string convert(Catch::Detail::Approx const& value);
+};
+
+} // end namespace Catch
+
+// end catch_approx.h
+// start catch_string_manip.h
+
+#include <string>
+#include <iosfwd>
+#include <vector>
+
+namespace Catch {
+
+ bool startsWith( std::string const& s, std::string const& prefix );
+ bool startsWith( std::string const& s, char prefix );
+ bool endsWith( std::string const& s, std::string const& suffix );
+ bool endsWith( std::string const& s, char suffix );
+ bool contains( std::string const& s, std::string const& infix );
+ void toLowerInPlace( std::string& s );
+ std::string toLower( std::string const& s );
+ //! Returns a new string without whitespace at the start/end
+ std::string trim( std::string const& str );
+ //! Returns a substring of the original ref without whitespace. Beware lifetimes!
+ StringRef trim(StringRef ref);
+
+ // !!! Be aware, returns refs into original string - make sure original string outlives them
+ std::vector<StringRef> splitStringRef( StringRef str, char delimiter );
+ bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
+
+ struct pluralise {
+ pluralise( std::size_t count, std::string const& label );
+
+ friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
+
+ std::size_t m_count;
+ std::string m_label;
+ };
+}
+
+// end catch_string_manip.h
+#ifndef CATCH_CONFIG_DISABLE_MATCHERS
+// start catch_capture_matchers.h
+
+// start catch_matchers.h
+
+#include <string>
+#include <vector>
+
+namespace Catch {
+namespace Matchers {
+ namespace Impl {
+
+ template<typename ArgT> struct MatchAllOf;
+ template<typename ArgT> struct MatchAnyOf;
+ template<typename ArgT> struct MatchNotOf;
+
+ class MatcherUntypedBase {
+ public:
+ MatcherUntypedBase() = default;
+ MatcherUntypedBase ( MatcherUntypedBase const& ) = default;
+ MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete;
+ std::string toString() const;
+
+ protected:
+ virtual ~MatcherUntypedBase();
+ virtual std::string describe() const = 0;
+ mutable std::string m_cachedToString;
+ };
+
+#ifdef __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
+
+ template<typename ObjectT>
+ struct MatcherMethod {
+ virtual bool match( ObjectT const& arg ) const = 0;
+ };
+
+#if defined(__OBJC__)
+ // Hack to fix Catch GH issue #1661. Could use id for generic Object support.
+ // use of const for Object pointers is very uncommon and under ARC it causes some kind of signature mismatch that breaks compilation
+ template<>
+ struct MatcherMethod<NSString*> {
+ virtual bool match( NSString* arg ) const = 0;
+ };
+#endif
+
+#ifdef __clang__
+# pragma clang diagnostic pop
+#endif
+
+ template<typename T>
+ struct MatcherBase : MatcherUntypedBase, MatcherMethod<T> {
+
+ MatchAllOf<T> operator && ( MatcherBase const& other ) const;
+ MatchAnyOf<T> operator || ( MatcherBase const& other ) const;
+ MatchNotOf<T> operator ! () const;
+ };
+
+ template<typename ArgT>
+ struct MatchAllOf : MatcherBase<ArgT> {
+ bool match( ArgT const& arg ) const override {
+ for( auto matcher : m_matchers ) {
+ if (!matcher->match(arg))
+ return false;
+ }
+ return true;
+ }
+ std::string describe() const override {
+ std::string description;
+ description.reserve( 4 + m_matchers.size()*32 );
+ description += "( ";
+ bool first = true;
+ for( auto matcher : m_matchers ) {
+ if( first )
+ first = false;
+ else
+ description += " and ";
+ description += matcher->toString();
+ }
+ description += " )";
+ return description;
+ }
+
+ MatchAllOf<ArgT> operator && ( MatcherBase<ArgT> const& other ) {
+ auto copy(*this);
+ copy.m_matchers.push_back( &other );
+ return copy;
+ }
+
+ std::vector<MatcherBase<ArgT> const*> m_matchers;
+ };
+ template<typename ArgT>
+ struct MatchAnyOf : MatcherBase<ArgT> {
+
+ bool match( ArgT const& arg ) const override {
+ for( auto matcher : m_matchers ) {
+ if (matcher->match(arg))
+ return true;
+ }
+ return false;
+ }
+ std::string describe() const override {
+ std::string description;
+ description.reserve( 4 + m_matchers.size()*32 );
+ description += "( ";
+ bool first = true;
+ for( auto matcher : m_matchers ) {
+ if( first )
+ first = false;
+ else
+ description += " or ";
+ description += matcher->toString();
+ }
+ description += " )";
+ return description;
+ }
+
+ MatchAnyOf<ArgT> operator || ( MatcherBase<ArgT> const& other ) {
+ auto copy(*this);
+ copy.m_matchers.push_back( &other );
+ return copy;
+ }
+
+ std::vector<MatcherBase<ArgT> const*> m_matchers;
+ };
+
+ template<typename ArgT>
+ struct MatchNotOf : MatcherBase<ArgT> {
+
+ MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {}
+
+ bool match( ArgT const& arg ) const override {
+ return !m_underlyingMatcher.match( arg );
+ }
+
+ std::string describe() const override {
+ return "not " + m_underlyingMatcher.toString();
+ }
+ MatcherBase<ArgT> const& m_underlyingMatcher;
+ };
+
+ template<typename T>
+ MatchAllOf<T> MatcherBase<T>::operator && ( MatcherBase const& other ) const {
+ return MatchAllOf<T>() && *this && other;
+ }
+ template<typename T>
+ MatchAnyOf<T> MatcherBase<T>::operator || ( MatcherBase const& other ) const {
+ return MatchAnyOf<T>() || *this || other;
+ }
+ template<typename T>
+ MatchNotOf<T> MatcherBase<T>::operator ! () const {
+ return MatchNotOf<T>( *this );
+ }
+
+ } // namespace Impl
+
+} // namespace Matchers
+
+using namespace Matchers;
+using Matchers::Impl::MatcherBase;
+
+} // namespace Catch
+
+// end catch_matchers.h
+// start catch_matchers_exception.hpp
+
+namespace Catch {
+namespace Matchers {
+namespace Exception {
+
+class ExceptionMessageMatcher : public MatcherBase<std::exception> {
+ std::string m_message;
+public:
+
+ ExceptionMessageMatcher(std::string const& message):
+ m_message(message)
+ {}
+
+ bool match(std::exception const& ex) const override;
+
+ std::string describe() const override;
+};
+
+} // namespace Exception
+
+Exception::ExceptionMessageMatcher Message(std::string const& message);
+
+} // namespace Matchers
+} // namespace Catch
+
+// end catch_matchers_exception.hpp
+// start catch_matchers_floating.h
+
+namespace Catch {
+namespace Matchers {
+
+ namespace Floating {
+
+ enum class FloatingPointKind : uint8_t;
+
+ struct WithinAbsMatcher : MatcherBase<double> {
+ WithinAbsMatcher(double target, double margin);
+ bool match(double const& matchee) const override;
+ std::string describe() const override;
+ private:
+ double m_target;
+ double m_margin;
+ };
+
+ struct WithinUlpsMatcher : MatcherBase<double> {
+ WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType);
+ bool match(double const& matchee) const override;
+ std::string describe() const override;
+ private:
+ double m_target;
+ uint64_t m_ulps;
+ FloatingPointKind m_type;
+ };
+
+ // Given IEEE-754 format for floats and doubles, we can assume
+ // that float -> double promotion is lossless. Given this, we can
+ // assume that if we do the standard relative comparison of
+ // |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get
+ // the same result if we do this for floats, as if we do this for
+ // doubles that were promoted from floats.
+ struct WithinRelMatcher : MatcherBase<double> {
+ WithinRelMatcher(double target, double epsilon);
+ bool match(double const& matchee) const override;
+ std::string describe() const override;
+ private:
+ double m_target;
+ double m_epsilon;
+ };
+
+ } // namespace Floating
+
+ // The following functions create the actual matcher objects.
+ // This allows the types to be inferred
+ Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff);
+ Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff);
+ Floating::WithinAbsMatcher WithinAbs(double target, double margin);
+ Floating::WithinRelMatcher WithinRel(double target, double eps);
+ // defaults epsilon to 100*numeric_limits<double>::epsilon()
+ Floating::WithinRelMatcher WithinRel(double target);
+ Floating::WithinRelMatcher WithinRel(float target, float eps);
+ // defaults epsilon to 100*numeric_limits<float>::epsilon()
+ Floating::WithinRelMatcher WithinRel(float target);
+
+} // namespace Matchers
+} // namespace Catch
+
+// end catch_matchers_floating.h
+// start catch_matchers_generic.hpp
+
+#include <functional>
+#include <string>
+
+namespace Catch {
+namespace Matchers {
+namespace Generic {
+
+namespace Detail {
+ std::string finalizeDescription(const std::string& desc);
+}
+
+template <typename T>
+class PredicateMatcher : public MatcherBase<T> {
+ std::function<bool(T const&)> m_predicate;
+ std::string m_description;
+public:
+
+ PredicateMatcher(std::function<bool(T const&)> const& elem, std::string const& descr)
+ :m_predicate(std::move(elem)),
+ m_description(Detail::finalizeDescription(descr))
+ {}
+
+ bool match( T const& item ) const override {
+ return m_predicate(item);
+ }
+
+ std::string describe() const override {
+ return m_description;
+ }
+};
+
+} // namespace Generic
+
+ // The following functions create the actual matcher objects.
+ // The user has to explicitly specify type to the function, because
+ // inferring std::function<bool(T const&)> is hard (but possible) and
+ // requires a lot of TMP.
+ template<typename T>
+ Generic::PredicateMatcher<T> Predicate(std::function<bool(T const&)> const& predicate, std::string const& description = "") {
+ return Generic::PredicateMatcher<T>(predicate, description);
+ }
+
+} // namespace Matchers
+} // namespace Catch
+
+// end catch_matchers_generic.hpp
+// start catch_matchers_string.h
+
+#include <string>
+
+namespace Catch {
+namespace Matchers {
+
+ namespace StdString {
+
+ struct CasedString
+ {
+ CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity );
+ std::string adjustString( std::string const& str ) const;
+ std::string caseSensitivitySuffix() const;
+
+ CaseSensitive::Choice m_caseSensitivity;
+ std::string m_str;
+ };
+
+ struct StringMatcherBase : MatcherBase<std::string> {
+ StringMatcherBase( std::string const& operation, CasedString const& comparator );
+ std::string describe() const override;
+
+ CasedString m_comparator;
+ std::string m_operation;
+ };
+
+ struct EqualsMatcher : StringMatcherBase {
+ EqualsMatcher( CasedString const& comparator );
+ bool match( std::string const& source ) const override;
+ };
+ struct ContainsMatcher : StringMatcherBase {
+ ContainsMatcher( CasedString const& comparator );
+ bool match( std::string const& source ) const override;
+ };
+ struct StartsWithMatcher : StringMatcherBase {
+ StartsWithMatcher( CasedString const& comparator );
+ bool match( std::string const& source ) const override;
+ };
+ struct EndsWithMatcher : StringMatcherBase {
+ EndsWithMatcher( CasedString const& comparator );
+ bool match( std::string const& source ) const override;
+ };
+
+ struct RegexMatcher : MatcherBase<std::string> {
+ RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity );
+ bool match( std::string const& matchee ) const override;
+ std::string describe() const override;
+
+ private:
+ std::string m_regex;
+ CaseSensitive::Choice m_caseSensitivity;
+ };
+
+ } // namespace StdString
+
+ // The following functions create the actual matcher objects.
+ // This allows the types to be inferred
+
+ StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
+ StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
+ StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
+ StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
+ StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
+
+} // namespace Matchers
+} // namespace Catch
+
+// end catch_matchers_string.h
+// start catch_matchers_vector.h
+
+#include <algorithm>
+
+namespace Catch {
+namespace Matchers {
+
+ namespace Vector {
+ template<typename T, typename Alloc>
+ struct ContainsElementMatcher : MatcherBase<std::vector<T, Alloc>> {
+
+ ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
+
+ bool match(std::vector<T, Alloc> const &v) const override {
+ for (auto const& el : v) {
+ if (el == m_comparator) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ std::string describe() const override {
+ return "Contains: " + ::Catch::Detail::stringify( m_comparator );
+ }
+
+ T const& m_comparator;
+ };
+
+ template<typename T, typename AllocComp, typename AllocMatch>
+ struct ContainsMatcher : MatcherBase<std::vector<T, AllocMatch>> {
+
+ ContainsMatcher(std::vector<T, AllocComp> const &comparator) : m_comparator( comparator ) {}
+
+ bool match(std::vector<T, AllocMatch> const &v) const override {
+ // !TBD: see note in EqualsMatcher
+ if (m_comparator.size() > v.size())
+ return false;
+ for (auto const& comparator : m_comparator) {
+ auto present = false;
+ for (const auto& el : v) {
+ if (el == comparator) {
+ present = true;
+ break;
+ }
+ }
+ if (!present) {
+ return false;
+ }
+ }
+ return true;
+ }
+ std::string describe() const override {
+ return "Contains: " + ::Catch::Detail::stringify( m_comparator );
+ }
+
+ std::vector<T, AllocComp> const& m_comparator;
+ };
+
+ template<typename T, typename AllocComp, typename AllocMatch>
+ struct EqualsMatcher : MatcherBase<std::vector<T, AllocMatch>> {
+
+ EqualsMatcher(std::vector<T, AllocComp> const &comparator) : m_comparator( comparator ) {}
+
+ bool match(std::vector<T, AllocMatch> const &v) const override {
+ // !TBD: This currently works if all elements can be compared using !=
+ // - a more general approach would be via a compare template that defaults
+ // to using !=. but could be specialised for, e.g. std::vector<T, Alloc> etc
+ // - then just call that directly
+ if (m_comparator.size() != v.size())
+ return false;
+ for (std::size_t i = 0; i < v.size(); ++i)
+ if (m_comparator[i] != v[i])
+ return false;
+ return true;
+ }
+ std::string describe() const override {
+ return "Equals: " + ::Catch::Detail::stringify( m_comparator );
+ }
+ std::vector<T, AllocComp> const& m_comparator;
+ };
+
+ template<typename T, typename AllocComp, typename AllocMatch>
+ struct ApproxMatcher : MatcherBase<std::vector<T, AllocMatch>> {
+
+ ApproxMatcher(std::vector<T, AllocComp> const& comparator) : m_comparator( comparator ) {}
+
+ bool match(std::vector<T, AllocMatch> const &v) const override {
+ if (m_comparator.size() != v.size())
+ return false;
+ for (std::size_t i = 0; i < v.size(); ++i)
+ if (m_comparator[i] != approx(v[i]))
+ return false;
+ return true;
+ }
+ std::string describe() const override {
+ return "is approx: " + ::Catch::Detail::stringify( m_comparator );
+ }
+ template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ ApproxMatcher& epsilon( T const& newEpsilon ) {
+ approx.epsilon(newEpsilon);
+ return *this;
+ }
+ template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ ApproxMatcher& margin( T const& newMargin ) {
+ approx.margin(newMargin);
+ return *this;
+ }
+ template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ ApproxMatcher& scale( T const& newScale ) {
+ approx.scale(newScale);
+ return *this;
+ }
+
+ std::vector<T, AllocComp> const& m_comparator;
+ mutable Catch::Detail::Approx approx = Catch::Detail::Approx::custom();
+ };
+
+ template<typename T, typename AllocComp, typename AllocMatch>
+ struct UnorderedEqualsMatcher : MatcherBase<std::vector<T, AllocMatch>> {
+ UnorderedEqualsMatcher(std::vector<T, AllocComp> const& target) : m_target(target) {}
+ bool match(std::vector<T, AllocMatch> const& vec) const override {
+ if (m_target.size() != vec.size()) {
+ return false;
+ }
+ return std::is_permutation(m_target.begin(), m_target.end(), vec.begin());
+ }
+
+ std::string describe() const override {
+ return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target);
+ }
+ private:
+ std::vector<T, AllocComp> const& m_target;
+ };
+
+ } // namespace Vector
+
+ // The following functions create the actual matcher objects.
+ // This allows the types to be inferred
+
+ template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
+ Vector::ContainsMatcher<T, AllocComp, AllocMatch> Contains( std::vector<T, AllocComp> const& comparator ) {
+ return Vector::ContainsMatcher<T, AllocComp, AllocMatch>( comparator );
+ }
+
+ template<typename T, typename Alloc = std::allocator<T>>
+ Vector::ContainsElementMatcher<T, Alloc> VectorContains( T const& comparator ) {
+ return Vector::ContainsElementMatcher<T, Alloc>( comparator );
+ }
+
+ template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
+ Vector::EqualsMatcher<T, AllocComp, AllocMatch> Equals( std::vector<T, AllocComp> const& comparator ) {
+ return Vector::EqualsMatcher<T, AllocComp, AllocMatch>( comparator );
+ }
+
+ template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
+ Vector::ApproxMatcher<T, AllocComp, AllocMatch> Approx( std::vector<T, AllocComp> const& comparator ) {
+ return Vector::ApproxMatcher<T, AllocComp, AllocMatch>( comparator );
+ }
+
+ template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
+ Vector::UnorderedEqualsMatcher<T, AllocComp, AllocMatch> UnorderedEquals(std::vector<T, AllocComp> const& target) {
+ return Vector::UnorderedEqualsMatcher<T, AllocComp, AllocMatch>( target );
+ }
+
+} // namespace Matchers
+} // namespace Catch
+
+// end catch_matchers_vector.h
+namespace Catch {
+
+ template<typename ArgT, typename MatcherT>
+ class MatchExpr : public ITransientExpression {
+ ArgT const& m_arg;
+ MatcherT m_matcher;
+ StringRef m_matcherString;
+ public:
+ MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString )
+ : ITransientExpression{ true, matcher.match( arg ) },
+ m_arg( arg ),
+ m_matcher( matcher ),
+ m_matcherString( matcherString )
+ {}
+
+ void streamReconstructedExpression( std::ostream &os ) const override {
+ auto matcherAsString = m_matcher.toString();
+ os << Catch::Detail::stringify( m_arg ) << ' ';
+ if( matcherAsString == Detail::unprintableString )
+ os << m_matcherString;
+ else
+ os << matcherAsString;
+ }
+ };
+
+ using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
+
+ void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString );
+
+ template<typename ArgT, typename MatcherT>
+ auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr<ArgT, MatcherT> {
+ return MatchExpr<ArgT, MatcherT>( arg, matcher, matcherString );
+ }
+
+} // namespace Catch
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
+ do { \
+ Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
+ INTERNAL_CATCH_TRY { \
+ catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher##_catch_sr ) ); \
+ } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
+ INTERNAL_CATCH_REACT( catchAssertionHandler ) \
+ } while( false )
+
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \
+ do { \
+ Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
+ if( catchAssertionHandler.allowThrows() ) \
+ try { \
+ static_cast<void>(__VA_ARGS__ ); \
+ catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
+ } \
+ catch( exceptionType const& ex ) { \
+ catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher##_catch_sr ) ); \
+ } \
+ catch( ... ) { \
+ catchAssertionHandler.handleUnexpectedInflightException(); \
+ } \
+ else \
+ catchAssertionHandler.handleThrowingCallSkipped(); \
+ INTERNAL_CATCH_REACT( catchAssertionHandler ) \
+ } while( false )
+
+// end catch_capture_matchers.h
+#endif
+// start catch_generators.hpp
+
+// start catch_interfaces_generatortracker.h
+
+
+#include <memory>
+
+namespace Catch {
+
+ namespace Generators {
+ class GeneratorUntypedBase {
+ public:
+ GeneratorUntypedBase() = default;
+ virtual ~GeneratorUntypedBase();
+ // Attempts to move the generator to the next element
+ //
+ // Returns true iff the move succeeded (and a valid element
+ // can be retrieved).
+ virtual bool next() = 0;
+ };
+ using GeneratorBasePtr = std::unique_ptr<GeneratorUntypedBase>;
+
+ } // namespace Generators
+
+ struct IGeneratorTracker {
+ virtual ~IGeneratorTracker();
+ virtual auto hasGenerator() const -> bool = 0;
+ virtual auto getGenerator() const -> Generators::GeneratorBasePtr const& = 0;
+ virtual void setGenerator( Generators::GeneratorBasePtr&& generator ) = 0;
+ };
+
+} // namespace Catch
+
+// end catch_interfaces_generatortracker.h
+// start catch_enforce.h
+
+#include <exception>
+
+namespace Catch {
+#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+ template <typename Ex>
+ [[noreturn]]
+ void throw_exception(Ex const& e) {
+ throw e;
+ }
+#else // ^^ Exceptions are enabled // Exceptions are disabled vv
+ [[noreturn]]
+ void throw_exception(std::exception const& e);
+#endif
+
+ [[noreturn]]
+ void throw_logic_error(std::string const& msg);
+ [[noreturn]]
+ void throw_domain_error(std::string const& msg);
+ [[noreturn]]
+ void throw_runtime_error(std::string const& msg);
+
+} // namespace Catch;
+
+#define CATCH_MAKE_MSG(...) \
+ (Catch::ReusableStringStream() << __VA_ARGS__).str()
+
+#define CATCH_INTERNAL_ERROR(...) \
+ Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__))
+
+#define CATCH_ERROR(...) \
+ Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
+
+#define CATCH_RUNTIME_ERROR(...) \
+ Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
+
+#define CATCH_ENFORCE( condition, ... ) \
+ do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false)
+
+// end catch_enforce.h
+#include <memory>
+#include <vector>
+#include <cassert>
+
+#include <utility>
+#include <exception>
+
+namespace Catch {
+
+class GeneratorException : public std::exception {
+ const char* const m_msg = "";
+
+public:
+ GeneratorException(const char* msg):
+ m_msg(msg)
+ {}
+
+ const char* what() const noexcept override final;
+};
+
+namespace Generators {
+
+ // !TBD move this into its own location?
+ namespace pf{
+ template<typename T, typename... Args>
+ std::unique_ptr<T> make_unique( Args&&... args ) {
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+ }
+ }
+
+ template<typename T>
+ struct IGenerator : GeneratorUntypedBase {
+ virtual ~IGenerator() = default;
+
+ // Returns the current element of the generator
+ //
+ // \Precondition The generator is either freshly constructed,
+ // or the last call to `next()` returned true
+ virtual T const& get() const = 0;
+ using type = T;
+ };
+
+ template<typename T>
+ class SingleValueGenerator final : public IGenerator<T> {
+ T m_value;
+ public:
+ SingleValueGenerator(T&& value) : m_value(std::move(value)) {}
+
+ T const& get() const override {
+ return m_value;
+ }
+ bool next() override {
+ return false;
+ }
+ };
+
+ template<typename T>
+ class FixedValuesGenerator final : public IGenerator<T> {
+ static_assert(!std::is_same<T, bool>::value,
+ "FixedValuesGenerator does not support bools because of std::vector<bool>"
+ "specialization, use SingleValue Generator instead.");
+ std::vector<T> m_values;
+ size_t m_idx = 0;
+ public:
+ FixedValuesGenerator( std::initializer_list<T> values ) : m_values( values ) {}
+
+ T const& get() const override {
+ return m_values[m_idx];
+ }
+ bool next() override {
+ ++m_idx;
+ return m_idx < m_values.size();
+ }
+ };
+
+ template <typename T>
+ class GeneratorWrapper final {
+ std::unique_ptr<IGenerator<T>> m_generator;
+ public:
+ GeneratorWrapper(std::unique_ptr<IGenerator<T>> generator):
+ m_generator(std::move(generator))
+ {}
+ T const& get() const {
+ return m_generator->get();
+ }
+ bool next() {
+ return m_generator->next();
+ }
+ };
+
+ template <typename T>
+ GeneratorWrapper<T> value(T&& value) {
+ return GeneratorWrapper<T>(pf::make_unique<SingleValueGenerator<T>>(std::forward<T>(value)));
+ }
+ template <typename T>
+ GeneratorWrapper<T> values(std::initializer_list<T> values) {
+ return GeneratorWrapper<T>(pf::make_unique<FixedValuesGenerator<T>>(values));
+ }
+
+ template<typename T>
+ class Generators : public IGenerator<T> {
+ std::vector<GeneratorWrapper<T>> m_generators;
+ size_t m_current = 0;
+
+ void populate(GeneratorWrapper<T>&& generator) {
+ m_generators.emplace_back(std::move(generator));
+ }
+ void populate(T&& val) {
+ m_generators.emplace_back(value(std::forward<T>(val)));
+ }
+ template<typename U>
+ void populate(U&& val) {
+ populate(T(std::forward<U>(val)));
+ }
+ template<typename U, typename... Gs>
+ void populate(U&& valueOrGenerator, Gs &&... moreGenerators) {
+ populate(std::forward<U>(valueOrGenerator));
+ populate(std::forward<Gs>(moreGenerators)...);
+ }
+
+ public:
+ template <typename... Gs>
+ Generators(Gs &&... moreGenerators) {
+ m_generators.reserve(sizeof...(Gs));
+ populate(std::forward<Gs>(moreGenerators)...);
+ }
+
+ T const& get() const override {
+ return m_generators[m_current].get();
+ }
+
+ bool next() override {
+ if (m_current >= m_generators.size()) {
+ return false;
+ }
+ const bool current_status = m_generators[m_current].next();
+ if (!current_status) {
+ ++m_current;
+ }
+ return m_current < m_generators.size();
+ }
+ };
+
+ template<typename... Ts>
+ GeneratorWrapper<std::tuple<Ts...>> table( std::initializer_list<std::tuple<typename std::decay<Ts>::type...>> tuples ) {
+ return values<std::tuple<Ts...>>( tuples );
+ }
+
+ // Tag type to signal that a generator sequence should convert arguments to a specific type
+ template <typename T>
+ struct as {};
+
+ template<typename T, typename... Gs>
+ auto makeGenerators( GeneratorWrapper<T>&& generator, Gs &&... moreGenerators ) -> Generators<T> {
+ return Generators<T>(std::move(generator), std::forward<Gs>(moreGenerators)...);
+ }
+ template<typename T>
+ auto makeGenerators( GeneratorWrapper<T>&& generator ) -> Generators<T> {
+ return Generators<T>(std::move(generator));
+ }
+ template<typename T, typename... Gs>
+ auto makeGenerators( T&& val, Gs &&... moreGenerators ) -> Generators<T> {
+ return makeGenerators( value( std::forward<T>( val ) ), std::forward<Gs>( moreGenerators )... );
+ }
+ template<typename T, typename U, typename... Gs>
+ auto makeGenerators( as<T>, U&& val, Gs &&... moreGenerators ) -> Generators<T> {
+ return makeGenerators( value( T( std::forward<U>( val ) ) ), std::forward<Gs>( moreGenerators )... );
+ }
+
+ auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker&;
+
+ template<typename L>
+ // Note: The type after -> is weird, because VS2015 cannot parse
+ // the expression used in the typedef inside, when it is in
+ // return type. Yeah.
+ auto generate( StringRef generatorName, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval<decltype(generatorExpression())>().get()) {
+ using UnderlyingType = typename decltype(generatorExpression())::type;
+
+ IGeneratorTracker& tracker = acquireGeneratorTracker( generatorName, lineInfo );
+ if (!tracker.hasGenerator()) {
+ tracker.setGenerator(pf::make_unique<Generators<UnderlyingType>>(generatorExpression()));
+ }
+
+ auto const& generator = static_cast<IGenerator<UnderlyingType> const&>( *tracker.getGenerator() );
+ return generator.get();
+ }
+
+} // namespace Generators
+} // namespace Catch
+
+#define GENERATE( ... ) \
+ Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
+ CATCH_INTERNAL_LINEINFO, \
+ [ ]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace)
+#define GENERATE_COPY( ... ) \
+ Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
+ CATCH_INTERNAL_LINEINFO, \
+ [=]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace)
+#define GENERATE_REF( ... ) \
+ Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
+ CATCH_INTERNAL_LINEINFO, \
+ [&]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace)
+
+// end catch_generators.hpp
+// start catch_generators_generic.hpp
+
+namespace Catch {
+namespace Generators {
+
+ template <typename T>
+ class TakeGenerator : public IGenerator<T> {
+ GeneratorWrapper<T> m_generator;
+ size_t m_returned = 0;
+ size_t m_target;
+ public:
+ TakeGenerator(size_t target, GeneratorWrapper<T>&& generator):
+ m_generator(std::move(generator)),
+ m_target(target)
+ {
+ assert(target != 0 && "Empty generators are not allowed");
+ }
+ T const& get() const override {
+ return m_generator.get();
+ }
+ bool next() override {
+ ++m_returned;
+ if (m_returned >= m_target) {
+ return false;
+ }
+
+ const auto success = m_generator.next();
+ // If the underlying generator does not contain enough values
+ // then we cut short as well
+ if (!success) {
+ m_returned = m_target;
+ }
+ return success;
+ }
+ };
+
+ template <typename T>
+ GeneratorWrapper<T> take(size_t target, GeneratorWrapper<T>&& generator) {
+ return GeneratorWrapper<T>(pf::make_unique<TakeGenerator<T>>(target, std::move(generator)));
+ }
+
+ template <typename T, typename Predicate>
+ class FilterGenerator : public IGenerator<T> {
+ GeneratorWrapper<T> m_generator;
+ Predicate m_predicate;
+ public:
+ template <typename P = Predicate>
+ FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator):
+ m_generator(std::move(generator)),
+ m_predicate(std::forward<P>(pred))
+ {
+ if (!m_predicate(m_generator.get())) {
+ // It might happen that there are no values that pass the
+ // filter. In that case we throw an exception.
+ auto has_initial_value = nextImpl();
+ if (!has_initial_value) {
+ Catch::throw_exception(GeneratorException("No valid value found in filtered generator"));
+ }
+ }
+ }
+
+ T const& get() const override {
+ return m_generator.get();
+ }
+
+ bool next() override {
+ return nextImpl();
+ }
+
+ private:
+ bool nextImpl() {
+ bool success = m_generator.next();
+ if (!success) {
+ return false;
+ }
+ while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true);
+ return success;
+ }
+ };
+
+ template <typename T, typename Predicate>
+ GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) {
+ return GeneratorWrapper<T>(std::unique_ptr<IGenerator<T>>(pf::make_unique<FilterGenerator<T, Predicate>>(std::forward<Predicate>(pred), std::move(generator))));
+ }
+
+ template <typename T>
+ class RepeatGenerator : public IGenerator<T> {
+ static_assert(!std::is_same<T, bool>::value,
+ "RepeatGenerator currently does not support bools"
+ "because of std::vector<bool> specialization");
+ GeneratorWrapper<T> m_generator;
+ mutable std::vector<T> m_returned;
+ size_t m_target_repeats;
+ size_t m_current_repeat = 0;
+ size_t m_repeat_index = 0;
+ public:
+ RepeatGenerator(size_t repeats, GeneratorWrapper<T>&& generator):
+ m_generator(std::move(generator)),
+ m_target_repeats(repeats)
+ {
+ assert(m_target_repeats > 0 && "Repeat generator must repeat at least once");
+ }
+
+ T const& get() const override {
+ if (m_current_repeat == 0) {
+ m_returned.push_back(m_generator.get());
+ return m_returned.back();
+ }
+ return m_returned[m_repeat_index];
+ }
+
+ bool next() override {
+ // There are 2 basic cases:
+ // 1) We are still reading the generator
+ // 2) We are reading our own cache
+
+ // In the first case, we need to poke the underlying generator.
+ // If it happily moves, we are left in that state, otherwise it is time to start reading from our cache
+ if (m_current_repeat == 0) {
+ const auto success = m_generator.next();
+ if (!success) {
+ ++m_current_repeat;
+ }
+ return m_current_repeat < m_target_repeats;
+ }
+
+ // In the second case, we need to move indices forward and check that we haven't run up against the end
+ ++m_repeat_index;
+ if (m_repeat_index == m_returned.size()) {
+ m_repeat_index = 0;
+ ++m_current_repeat;
+ }
+ return m_current_repeat < m_target_repeats;
+ }
+ };
+
+ template <typename T>
+ GeneratorWrapper<T> repeat(size_t repeats, GeneratorWrapper<T>&& generator) {
+ return GeneratorWrapper<T>(pf::make_unique<RepeatGenerator<T>>(repeats, std::move(generator)));
+ }
+
+ template <typename T, typename U, typename Func>
+ class MapGenerator : public IGenerator<T> {
+ // TBD: provide static assert for mapping function, for friendly error message
+ GeneratorWrapper<U> m_generator;
+ Func m_function;
+ // To avoid returning dangling reference, we have to save the values
+ T m_cache;
+ public:
+ template <typename F2 = Func>
+ MapGenerator(F2&& function, GeneratorWrapper<U>&& generator) :
+ m_generator(std::move(generator)),
+ m_function(std::forward<F2>(function)),
+ m_cache(m_function(m_generator.get()))
+ {}
+
+ T const& get() const override {
+ return m_cache;
+ }
+ bool next() override {
+ const auto success = m_generator.next();
+ if (success) {
+ m_cache = m_function(m_generator.get());
+ }
+ return success;
+ }
+ };
+
+ template <typename Func, typename U, typename T = FunctionReturnType<Func, U>>
+ GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
+ return GeneratorWrapper<T>(
+ pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator))
+ );
+ }
+
+ template <typename T, typename U, typename Func>
+ GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
+ return GeneratorWrapper<T>(
+ pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator))
+ );
+ }
+
+ template <typename T>
+ class ChunkGenerator final : public IGenerator<std::vector<T>> {
+ std::vector<T> m_chunk;
+ size_t m_chunk_size;
+ GeneratorWrapper<T> m_generator;
+ bool m_used_up = false;
+ public:
+ ChunkGenerator(size_t size, GeneratorWrapper<T> generator) :
+ m_chunk_size(size), m_generator(std::move(generator))
+ {
+ m_chunk.reserve(m_chunk_size);
+ if (m_chunk_size != 0) {
+ m_chunk.push_back(m_generator.get());
+ for (size_t i = 1; i < m_chunk_size; ++i) {
+ if (!m_generator.next()) {
+ Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk"));
+ }
+ m_chunk.push_back(m_generator.get());
+ }
+ }
+ }
+ std::vector<T> const& get() const override {
+ return m_chunk;
+ }
+ bool next() override {
+ m_chunk.clear();
+ for (size_t idx = 0; idx < m_chunk_size; ++idx) {
+ if (!m_generator.next()) {
+ return false;
+ }
+ m_chunk.push_back(m_generator.get());
+ }
+ return true;
+ }
+ };
+
+ template <typename T>
+ GeneratorWrapper<std::vector<T>> chunk(size_t size, GeneratorWrapper<T>&& generator) {
+ return GeneratorWrapper<std::vector<T>>(
+ pf::make_unique<ChunkGenerator<T>>(size, std::move(generator))
+ );
+ }
+
+} // namespace Generators
+} // namespace Catch
+
+// end catch_generators_generic.hpp
+// start catch_generators_specific.hpp
+
+// start catch_context.h
+
+#include <memory>
+
+namespace Catch {
+
+ struct IResultCapture;
+ struct IRunner;
+ struct IConfig;
+ struct IMutableContext;
+
+ using IConfigPtr = std::shared_ptr<IConfig const>;
+
+ struct IContext
+ {
+ virtual ~IContext();
+
+ virtual IResultCapture* getResultCapture() = 0;
+ virtual IRunner* getRunner() = 0;
+ virtual IConfigPtr const& getConfig() const = 0;
+ };
+
+ struct IMutableContext : IContext
+ {
+ virtual ~IMutableContext();
+ virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
+ virtual void setRunner( IRunner* runner ) = 0;
+ virtual void setConfig( IConfigPtr const& config ) = 0;
+
+ private:
+ static IMutableContext *currentContext;
+ friend IMutableContext& getCurrentMutableContext();
+ friend void cleanUpContext();
+ static void createContext();
+ };
+
+ inline IMutableContext& getCurrentMutableContext()
+ {
+ if( !IMutableContext::currentContext )
+ IMutableContext::createContext();
+ // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
+ return *IMutableContext::currentContext;
+ }
+
+ inline IContext& getCurrentContext()
+ {
+ return getCurrentMutableContext();
+ }
+
+ void cleanUpContext();
+
+ class SimplePcg32;
+ SimplePcg32& rng();
+}
+
+// end catch_context.h
+// start catch_interfaces_config.h
+
+// start catch_option.hpp
+
+namespace Catch {
+
+ // An optional type
+ template<typename T>
+ class Option {
+ public:
+ Option() : nullableValue( nullptr ) {}
+ Option( T const& _value )
+ : nullableValue( new( storage ) T( _value ) )
+ {}
+ Option( Option const& _other )
+ : nullableValue( _other ? new( storage ) T( *_other ) : nullptr )
+ {}
+
+ ~Option() {
+ reset();
+ }
+
+ Option& operator= ( Option const& _other ) {
+ if( &_other != this ) {
+ reset();
+ if( _other )
+ nullableValue = new( storage ) T( *_other );
+ }
+ return *this;
+ }
+ Option& operator = ( T const& _value ) {
+ reset();
+ nullableValue = new( storage ) T( _value );
+ return *this;
+ }
+
+ void reset() {
+ if( nullableValue )
+ nullableValue->~T();
+ nullableValue = nullptr;
+ }
+
+ T& operator*() { return *nullableValue; }
+ T const& operator*() const { return *nullableValue; }
+ T* operator->() { return nullableValue; }
+ const T* operator->() const { return nullableValue; }
+
+ T valueOr( T const& defaultValue ) const {
+ return nullableValue ? *nullableValue : defaultValue;
+ }
+
+ bool some() const { return nullableValue != nullptr; }
+ bool none() const { return nullableValue == nullptr; }
+
+ bool operator !() const { return nullableValue == nullptr; }
+ explicit operator bool() const {
+ return some();
+ }
+
+ private:
+ T *nullableValue;
+ alignas(alignof(T)) char storage[sizeof(T)];
+ };
+
+} // end namespace Catch
+
+// end catch_option.hpp
+#include <chrono>
+#include <iosfwd>
+#include <string>
+#include <vector>
+#include <memory>
+
+namespace Catch {
+
+ enum class Verbosity {
+ Quiet = 0,
+ Normal,
+ High
+ };
+
+ struct WarnAbout { enum What {
+ Nothing = 0x00,
+ NoAssertions = 0x01,
+ NoTests = 0x02
+ }; };
+
+ struct ShowDurations { enum OrNot {
+ DefaultForReporter,
+ Always,
+ Never
+ }; };
+ struct RunTests { enum InWhatOrder {
+ InDeclarationOrder,
+ InLexicographicalOrder,
+ InRandomOrder
+ }; };
+ struct UseColour { enum YesOrNo {
+ Auto,
+ Yes,
+ No
+ }; };
+ struct WaitForKeypress { enum When {
+ Never,
+ BeforeStart = 1,
+ BeforeExit = 2,
+ BeforeStartAndExit = BeforeStart | BeforeExit
+ }; };
+
+ class TestSpec;
+
+ struct IConfig : NonCopyable {
+
+ virtual ~IConfig();
+
+ virtual bool allowThrows() const = 0;
+ virtual std::ostream& stream() const = 0;
+ virtual std::string name() const = 0;
+ virtual bool includeSuccessfulResults() const = 0;
+ virtual bool shouldDebugBreak() const = 0;
+ virtual bool warnAboutMissingAssertions() const = 0;
+ virtual bool warnAboutNoTests() const = 0;
+ virtual int abortAfter() const = 0;
+ virtual bool showInvisibles() const = 0;
+ virtual ShowDurations::OrNot showDurations() const = 0;
+ virtual double minDuration() const = 0;
+ virtual TestSpec const& testSpec() const = 0;
+ virtual bool hasTestFilters() const = 0;
+ virtual std::vector<std::string> const& getTestsOrTags() const = 0;
+ virtual RunTests::InWhatOrder runOrder() const = 0;
+ virtual unsigned int rngSeed() const = 0;
+ virtual UseColour::YesOrNo useColour() const = 0;
+ virtual std::vector<std::string> const& getSectionsToRun() const = 0;
+ virtual Verbosity verbosity() const = 0;
+
+ virtual bool benchmarkNoAnalysis() const = 0;
+ virtual int benchmarkSamples() const = 0;
+ virtual double benchmarkConfidenceInterval() const = 0;
+ virtual unsigned int benchmarkResamples() const = 0;
+ virtual std::chrono::milliseconds benchmarkWarmupTime() const = 0;
+ };
+
+ using IConfigPtr = std::shared_ptr<IConfig const>;
+}
+
+// end catch_interfaces_config.h
+// start catch_random_number_generator.h
+
+#include <cstdint>
+
+namespace Catch {
+
+ // This is a simple implementation of C++11 Uniform Random Number
+ // Generator. It does not provide all operators, because Catch2
+ // does not use it, but it should behave as expected inside stdlib's
+ // distributions.
+ // The implementation is based on the PCG family (http://pcg-random.org)
+ class SimplePcg32 {
+ using state_type = std::uint64_t;
+ public:
+ using result_type = std::uint32_t;
+ static constexpr result_type (min)() {
+ return 0;
+ }
+ static constexpr result_type (max)() {
+ return static_cast<result_type>(-1);
+ }
+
+ // Provide some default initial state for the default constructor
+ SimplePcg32():SimplePcg32(0xed743cc4U) {}
+
+ explicit SimplePcg32(result_type seed_);
+
+ void seed(result_type seed_);
+ void discard(uint64_t skip);
+
+ result_type operator()();
+
+ private:
+ friend bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs);
+ friend bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs);
+
+ // In theory we also need operator<< and operator>>
+ // In practice we do not use them, so we will skip them for now
+
+ std::uint64_t m_state;
+ // This part of the state determines which "stream" of the numbers
+ // is chosen -- we take it as a constant for Catch2, so we only
+ // need to deal with seeding the main state.
+ // Picked by reading 8 bytes from `/dev/random` :-)
+ static const std::uint64_t s_inc = (0x13ed0cc53f939476ULL << 1ULL) | 1ULL;
+ };
+
+} // end namespace Catch
+
+// end catch_random_number_generator.h
+#include <random>
+
+namespace Catch {
+namespace Generators {
+
+template <typename Float>
+class RandomFloatingGenerator final : public IGenerator<Float> {
+ Catch::SimplePcg32& m_rng;
+ std::uniform_real_distribution<Float> m_dist;
+ Float m_current_number;
+public:
+
+ RandomFloatingGenerator(Float a, Float b):
+ m_rng(rng()),
+ m_dist(a, b) {
+ static_cast<void>(next());
+ }
+
+ Float const& get() const override {
+ return m_current_number;
+ }
+ bool next() override {
+ m_current_number = m_dist(m_rng);
+ return true;
+ }
+};
+
+template <typename Integer>
+class RandomIntegerGenerator final : public IGenerator<Integer> {
+ Catch::SimplePcg32& m_rng;
+ std::uniform_int_distribution<Integer> m_dist;
+ Integer m_current_number;
+public:
+
+ RandomIntegerGenerator(Integer a, Integer b):
+ m_rng(rng()),
+ m_dist(a, b) {
+ static_cast<void>(next());
+ }
+
+ Integer const& get() const override {
+ return m_current_number;
+ }
+ bool next() override {
+ m_current_number = m_dist(m_rng);
+ return true;
+ }
+};
+
+// TODO: Ideally this would be also constrained against the various char types,
+// but I don't expect users to run into that in practice.
+template <typename T>
+typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, bool>::value,
+GeneratorWrapper<T>>::type
+random(T a, T b) {
+ return GeneratorWrapper<T>(
+ pf::make_unique<RandomIntegerGenerator<T>>(a, b)
+ );
+}
+
+template <typename T>
+typename std::enable_if<std::is_floating_point<T>::value,
+GeneratorWrapper<T>>::type
+random(T a, T b) {
+ return GeneratorWrapper<T>(
+ pf::make_unique<RandomFloatingGenerator<T>>(a, b)
+ );
+}
+
+template <typename T>
+class RangeGenerator final : public IGenerator<T> {
+ T m_current;
+ T m_end;
+ T m_step;
+ bool m_positive;
+
+public:
+ RangeGenerator(T const& start, T const& end, T const& step):
+ m_current(start),
+ m_end(end),
+ m_step(step),
+ m_positive(m_step > T(0))
+ {
+ assert(m_current != m_end && "Range start and end cannot be equal");
+ assert(m_step != T(0) && "Step size cannot be zero");
+ assert(((m_positive && m_current <= m_end) || (!m_positive && m_current >= m_end)) && "Step moves away from end");
+ }
+
+ RangeGenerator(T const& start, T const& end):
+ RangeGenerator(start, end, (start < end) ? T(1) : T(-1))
+ {}
+
+ T const& get() const override {
+ return m_current;
+ }
+
+ bool next() override {
+ m_current += m_step;
+ return (m_positive) ? (m_current < m_end) : (m_current > m_end);
+ }
+};
+
+template <typename T>
+GeneratorWrapper<T> range(T const& start, T const& end, T const& step) {
+ static_assert(std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, "Type must be numeric");
+ return GeneratorWrapper<T>(pf::make_unique<RangeGenerator<T>>(start, end, step));
+}
+
+template <typename T>
+GeneratorWrapper<T> range(T const& start, T const& end) {
+ static_assert(std::is_integral<T>::value && !std::is_same<T, bool>::value, "Type must be an integer");
+ return GeneratorWrapper<T>(pf::make_unique<RangeGenerator<T>>(start, end));
+}
+
+template <typename T>
+class IteratorGenerator final : public IGenerator<T> {
+ static_assert(!std::is_same<T, bool>::value,
+ "IteratorGenerator currently does not support bools"
+ "because of std::vector<bool> specialization");
+
+ std::vector<T> m_elems;
+ size_t m_current = 0;
+public:
+ template <typename InputIterator, typename InputSentinel>
+ IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) {
+ if (m_elems.empty()) {
+ Catch::throw_exception(GeneratorException("IteratorGenerator received no valid values"));
+ }
+ }
+
+ T const& get() const override {
+ return m_elems[m_current];
+ }
+
+ bool next() override {
+ ++m_current;
+ return m_current != m_elems.size();
+ }
+};
+
+template <typename InputIterator,
+ typename InputSentinel,
+ typename ResultType = typename std::iterator_traits<InputIterator>::value_type>
+GeneratorWrapper<ResultType> from_range(InputIterator from, InputSentinel to) {
+ return GeneratorWrapper<ResultType>(pf::make_unique<IteratorGenerator<ResultType>>(from, to));
+}
+
+template <typename Container,
+ typename ResultType = typename Container::value_type>
+GeneratorWrapper<ResultType> from_range(Container const& cnt) {
+ return GeneratorWrapper<ResultType>(pf::make_unique<IteratorGenerator<ResultType>>(cnt.begin(), cnt.end()));
+}
+
+} // namespace Generators
+} // namespace Catch
+
+// end catch_generators_specific.hpp
+
+// These files are included here so the single_include script doesn't put them
+// in the conditionally compiled sections
+// start catch_test_case_info.h
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpadded"
+#endif
+
+namespace Catch {
+
+ struct ITestInvoker;
+
+ struct TestCaseInfo {
+ enum SpecialProperties{
+ None = 0,
+ IsHidden = 1 << 1,
+ ShouldFail = 1 << 2,
+ MayFail = 1 << 3,
+ Throws = 1 << 4,
+ NonPortable = 1 << 5,
+ Benchmark = 1 << 6
+ };
+
+ TestCaseInfo( std::string const& _name,
+ std::string const& _className,
+ std::string const& _description,
+ std::vector<std::string> const& _tags,
+ SourceLineInfo const& _lineInfo );
+
+ friend void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags );
+
+ bool isHidden() const;
+ bool throws() const;
+ bool okToFail() const;
+ bool expectedToFail() const;
+
+ std::string tagsAsString() const;
+
+ std::string name;
+ std::string className;
+ std::string description;
+ std::vector<std::string> tags;
+ std::vector<std::string> lcaseTags;
+ SourceLineInfo lineInfo;
+ SpecialProperties properties;
+ };
+
+ class TestCase : public TestCaseInfo {
+ public:
+
+ TestCase( ITestInvoker* testCase, TestCaseInfo&& info );
+
+ TestCase withName( std::string const& _newName ) const;
+
+ void invoke() const;
+
+ TestCaseInfo const& getTestCaseInfo() const;
+
+ bool operator == ( TestCase const& other ) const;
+ bool operator < ( TestCase const& other ) const;
+
+ private:
+ std::shared_ptr<ITestInvoker> test;
+ };
+
+ TestCase makeTestCase( ITestInvoker* testCase,
+ std::string const& className,
+ NameAndTags const& nameAndTags,
+ SourceLineInfo const& lineInfo );
+}
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
+// end catch_test_case_info.h
+// start catch_interfaces_runner.h
+
+namespace Catch {
+
+ struct IRunner {
+ virtual ~IRunner();
+ virtual bool aborting() const = 0;
+ };
+}
+
+// end catch_interfaces_runner.h
+
+#ifdef __OBJC__
+// start catch_objc.hpp
+
+#import <objc/runtime.h>
+
+#include <string>
+
+// NB. Any general catch headers included here must be included
+// in catch.hpp first to make sure they are included by the single
+// header for non obj-usage
+
+///////////////////////////////////////////////////////////////////////////////
+// This protocol is really only here for (self) documenting purposes, since
+// all its methods are optional.
+@protocol OcFixture
+
+@optional
+
+-(void) setUp;
+-(void) tearDown;
+
+@end
+
+namespace Catch {
+
+ class OcMethod : public ITestInvoker {
+
+ public:
+ OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
+
+ virtual void invoke() const {
+ id obj = [[m_cls alloc] init];
+
+ performOptionalSelector( obj, @selector(setUp) );
+ performOptionalSelector( obj, m_sel );
+ performOptionalSelector( obj, @selector(tearDown) );
+
+ arcSafeRelease( obj );
+ }
+ private:
+ virtual ~OcMethod() {}
+
+ Class m_cls;
+ SEL m_sel;
+ };
+
+ namespace Detail{
+
+ inline std::string getAnnotation( Class cls,
+ std::string const& annotationName,
+ std::string const& testCaseName ) {
+ NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
+ SEL sel = NSSelectorFromString( selStr );
+ arcSafeRelease( selStr );
+ id value = performOptionalSelector( cls, sel );
+ if( value )
+ return [(NSString*)value UTF8String];
+ return "";
+ }
+ }
+
+ inline std::size_t registerTestMethods() {
+ std::size_t noTestMethods = 0;
+ int noClasses = objc_getClassList( nullptr, 0 );
+
+ Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
+ objc_getClassList( classes, noClasses );
+
+ for( int c = 0; c < noClasses; c++ ) {
+ Class cls = classes[c];
+ {
+ u_int count;
+ Method* methods = class_copyMethodList( cls, &count );
+ for( u_int m = 0; m < count ; m++ ) {
+ SEL selector = method_getName(methods[m]);
+ std::string methodName = sel_getName(selector);
+ if( startsWith( methodName, "Catch_TestCase_" ) ) {
+ std::string testCaseName = methodName.substr( 15 );
+ std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
+ std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
+ const char* className = class_getName( cls );
+
+ getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, NameAndTags( name.c_str(), desc.c_str() ), SourceLineInfo("",0) ) );
+ noTestMethods++;
+ }
+ }
+ free(methods);
+ }
+ }
+ return noTestMethods;
+ }
+
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+
+ namespace Matchers {
+ namespace Impl {
+ namespace NSStringMatchers {
+
+ struct StringHolder : MatcherBase<NSString*>{
+ StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
+ StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
+ StringHolder() {
+ arcSafeRelease( m_substr );
+ }
+
+ bool match( NSString* str ) const override {
+ return false;
+ }
+
+ NSString* CATCH_ARC_STRONG m_substr;
+ };
+
+ struct Equals : StringHolder {
+ Equals( NSString* substr ) : StringHolder( substr ){}
+
+ bool match( NSString* str ) const override {
+ return (str != nil || m_substr == nil ) &&
+ [str isEqualToString:m_substr];
+ }
+
+ std::string describe() const override {
+ return "equals string: " + Catch::Detail::stringify( m_substr );
+ }
+ };
+
+ struct Contains : StringHolder {
+ Contains( NSString* substr ) : StringHolder( substr ){}
+
+ bool match( NSString* str ) const override {
+ return (str != nil || m_substr == nil ) &&
+ [str rangeOfString:m_substr].location != NSNotFound;
+ }
+
+ std::string describe() const override {
+ return "contains string: " + Catch::Detail::stringify( m_substr );
+ }
+ };
+
+ struct StartsWith : StringHolder {
+ StartsWith( NSString* substr ) : StringHolder( substr ){}
+
+ bool match( NSString* str ) const override {
+ return (str != nil || m_substr == nil ) &&
+ [str rangeOfString:m_substr].location == 0;
+ }
+
+ std::string describe() const override {
+ return "starts with: " + Catch::Detail::stringify( m_substr );
+ }
+ };
+ struct EndsWith : StringHolder {
+ EndsWith( NSString* substr ) : StringHolder( substr ){}
+
+ bool match( NSString* str ) const override {
+ return (str != nil || m_substr == nil ) &&
+ [str rangeOfString:m_substr].location == [str length] - [m_substr length];
+ }
+
+ std::string describe() const override {
+ return "ends with: " + Catch::Detail::stringify( m_substr );
+ }
+ };
+
+ } // namespace NSStringMatchers
+ } // namespace Impl
+
+ inline Impl::NSStringMatchers::Equals
+ Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
+
+ inline Impl::NSStringMatchers::Contains
+ Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
+
+ inline Impl::NSStringMatchers::StartsWith
+ StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
+
+ inline Impl::NSStringMatchers::EndsWith
+ EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
+
+ } // namespace Matchers
+
+ using namespace Matchers;
+
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+
+} // namespace Catch
+
+///////////////////////////////////////////////////////////////////////////////
+#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix
+#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \
++(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \
+{ \
+return @ name; \
+} \
++(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \
+{ \
+return @ desc; \
+} \
+-(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix )
+
+#define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ )
+
+// end catch_objc.hpp
+#endif
+
+// Benchmarking needs the externally-facing parts of reporters to work
+#if defined(CATCH_CONFIG_EXTERNAL_INTERFACES) || defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+// start catch_external_interfaces.h
+
+// start catch_reporter_bases.hpp
+
+// start catch_interfaces_reporter.h
+
+// start catch_config.hpp
+
+// start catch_test_spec_parser.h
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpadded"
+#endif
+
+// start catch_test_spec.h
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpadded"
+#endif
+
+// start catch_wildcard_pattern.h
+
+namespace Catch
+{
+ class WildcardPattern {
+ enum WildcardPosition {
+ NoWildcard = 0,
+ WildcardAtStart = 1,
+ WildcardAtEnd = 2,
+ WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
+ };
+
+ public:
+
+ WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity );
+ virtual ~WildcardPattern() = default;
+ virtual bool matches( std::string const& str ) const;
+
+ private:
+ std::string normaliseString( std::string const& str ) const;
+ CaseSensitive::Choice m_caseSensitivity;
+ WildcardPosition m_wildcard = NoWildcard;
+ std::string m_pattern;
+ };
+}
+
+// end catch_wildcard_pattern.h
+#include <string>
+#include <vector>
+#include <memory>
+
+namespace Catch {
+
+ struct IConfig;
+
+ class TestSpec {
+ class Pattern {
+ public:
+ explicit Pattern( std::string const& name );
+ virtual ~Pattern();
+ virtual bool matches( TestCaseInfo const& testCase ) const = 0;
+ std::string const& name() const;
+ private:
+ std::string const m_name;
+ };
+ using PatternPtr = std::shared_ptr<Pattern>;
+
+ class NamePattern : public Pattern {
+ public:
+ explicit NamePattern( std::string const& name, std::string const& filterString );
+ bool matches( TestCaseInfo const& testCase ) const override;
+ private:
+ WildcardPattern m_wildcardPattern;
+ };
+
+ class TagPattern : public Pattern {
+ public:
+ explicit TagPattern( std::string const& tag, std::string const& filterString );
+ bool matches( TestCaseInfo const& testCase ) const override;
+ private:
+ std::string m_tag;
+ };
+
+ class ExcludedPattern : public Pattern {
+ public:
+ explicit ExcludedPattern( PatternPtr const& underlyingPattern );
+ bool matches( TestCaseInfo const& testCase ) const override;
+ private:
+ PatternPtr m_underlyingPattern;
+ };
+
+ struct Filter {
+ std::vector<PatternPtr> m_patterns;
+
+ bool matches( TestCaseInfo const& testCase ) const;
+ std::string name() const;
+ };
+
+ public:
+ struct FilterMatch {
+ std::string name;
+ std::vector<TestCase const*> tests;
+ };
+ using Matches = std::vector<FilterMatch>;
+ using vectorStrings = std::vector<std::string>;
+
+ bool hasFilters() const;
+ bool matches( TestCaseInfo const& testCase ) const;
+ Matches matchesByFilter( std::vector<TestCase> const& testCases, IConfig const& config ) const;
+ const vectorStrings & getInvalidArgs() const;
+
+ private:
+ std::vector<Filter> m_filters;
+ std::vector<std::string> m_invalidArgs;
+ friend class TestSpecParser;
+ };
+}
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
+// end catch_test_spec.h
+// start catch_interfaces_tag_alias_registry.h
+
+#include <string>
+
+namespace Catch {
+
+ struct TagAlias;
+
+ struct ITagAliasRegistry {
+ virtual ~ITagAliasRegistry();
+ // Nullptr if not present
+ virtual TagAlias const* find( std::string const& alias ) const = 0;
+ virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
+
+ static ITagAliasRegistry const& get();
+ };
+
+} // end namespace Catch
+
+// end catch_interfaces_tag_alias_registry.h
+namespace Catch {
+
+ class TestSpecParser {
+ enum Mode{ None, Name, QuotedName, Tag, EscapedName };
+ Mode m_mode = None;
+ Mode lastMode = None;
+ bool m_exclusion = false;
+ std::size_t m_pos = 0;
+ std::size_t m_realPatternPos = 0;
+ std::string m_arg;
+ std::string m_substring;
+ std::string m_patternName;
+ std::vector<std::size_t> m_escapeChars;
+ TestSpec::Filter m_currentFilter;
+ TestSpec m_testSpec;
+ ITagAliasRegistry const* m_tagAliases = nullptr;
+
+ public:
+ TestSpecParser( ITagAliasRegistry const& tagAliases );
+
+ TestSpecParser& parse( std::string const& arg );
+ TestSpec testSpec();
+
+ private:
+ bool visitChar( char c );
+ void startNewMode( Mode mode );
+ bool processNoneChar( char c );
+ void processNameChar( char c );
+ bool processOtherChar( char c );
+ void endMode();
+ void escape();
+ bool isControlChar( char c ) const;
+ void saveLastMode();
+ void revertBackToLastMode();
+ void addFilter();
+ bool separate();
+
+ // Handles common preprocessing of the pattern for name/tag patterns
+ std::string preprocessPattern();
+ // Adds the current pattern as a test name
+ void addNamePattern();
+ // Adds the current pattern as a tag
+ void addTagPattern();
+
+ inline void addCharToPattern(char c) {
+ m_substring += c;
+ m_patternName += c;
+ m_realPatternPos++;
+ }
+
+ };
+ TestSpec parseTestSpec( std::string const& arg );
+
+} // namespace Catch
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
+// end catch_test_spec_parser.h
+// Libstdc++ doesn't like incomplete classes for unique_ptr
+
+#include <memory>
+#include <vector>
+#include <string>
+
+#ifndef CATCH_CONFIG_CONSOLE_WIDTH
+#define CATCH_CONFIG_CONSOLE_WIDTH 80
+#endif
+
+namespace Catch {
+
+ struct IStream;
+
+ struct ConfigData {
+ bool listTests = false;
+ bool listTags = false;
+ bool listReporters = false;
+ bool listTestNamesOnly = false;
+
+ bool showSuccessfulTests = false;
+ bool shouldDebugBreak = false;
+ bool noThrow = false;
+ bool showHelp = false;
+ bool showInvisibles = false;
+ bool filenamesAsTags = false;
+ bool libIdentify = false;
+
+ int abortAfter = -1;
+ unsigned int rngSeed = 0;
+
+ bool benchmarkNoAnalysis = false;
+ unsigned int benchmarkSamples = 100;
+ double benchmarkConfidenceInterval = 0.95;
+ unsigned int benchmarkResamples = 100000;
+ std::chrono::milliseconds::rep benchmarkWarmupTime = 100;
+
+ Verbosity verbosity = Verbosity::Normal;
+ WarnAbout::What warnings = WarnAbout::Nothing;
+ ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter;
+ double minDuration = -1;
+ RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder;
+ UseColour::YesOrNo useColour = UseColour::Auto;
+ WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
+
+ std::string outputFilename;
+ std::string name;
+ std::string processName;
+#ifndef CATCH_CONFIG_DEFAULT_REPORTER
+#define CATCH_CONFIG_DEFAULT_REPORTER "console"
+#endif
+ std::string reporterName = CATCH_CONFIG_DEFAULT_REPORTER;
+#undef CATCH_CONFIG_DEFAULT_REPORTER
+
+ std::vector<std::string> testsOrTags;
+ std::vector<std::string> sectionsToRun;
+ };
+
+ class Config : public IConfig {
+ public:
+
+ Config() = default;
+ Config( ConfigData const& data );
+ virtual ~Config() = default;
+
+ std::string const& getFilename() const;
+
+ bool listTests() const;
+ bool listTestNamesOnly() const;
+ bool listTags() const;
+ bool listReporters() const;
+
+ std::string getProcessName() const;
+ std::string const& getReporterName() const;
+
+ std::vector<std::string> const& getTestsOrTags() const override;
+ std::vector<std::string> const& getSectionsToRun() const override;
+
+ TestSpec const& testSpec() const override;
+ bool hasTestFilters() const override;
+
+ bool showHelp() const;
+
+ // IConfig interface
+ bool allowThrows() const override;
+ std::ostream& stream() const override;
+ std::string name() const override;
+ bool includeSuccessfulResults() const override;
+ bool warnAboutMissingAssertions() const override;
+ bool warnAboutNoTests() const override;
+ ShowDurations::OrNot showDurations() const override;
+ double minDuration() const override;
+ RunTests::InWhatOrder runOrder() const override;
+ unsigned int rngSeed() const override;
+ UseColour::YesOrNo useColour() const override;
+ bool shouldDebugBreak() const override;
+ int abortAfter() const override;
+ bool showInvisibles() const override;
+ Verbosity verbosity() const override;
+ bool benchmarkNoAnalysis() const override;
+ int benchmarkSamples() const override;
+ double benchmarkConfidenceInterval() const override;
+ unsigned int benchmarkResamples() const override;
+ std::chrono::milliseconds benchmarkWarmupTime() const override;
+
+ private:
+
+ IStream const* openStream();
+ ConfigData m_data;
+
+ std::unique_ptr<IStream const> m_stream;
+ TestSpec m_testSpec;
+ bool m_hasTestFilters = false;
+ };
+
+} // end namespace Catch
+
+// end catch_config.hpp
+// start catch_assertionresult.h
+
+#include <string>
+
+namespace Catch {
+
+ struct AssertionResultData
+ {
+ AssertionResultData() = delete;
+
+ AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression );
+
+ std::string message;
+ mutable std::string reconstructedExpression;
+ LazyExpression lazyExpression;
+ ResultWas::OfType resultType;
+
+ std::string reconstructExpression() const;
+ };
+
+ class AssertionResult {
+ public:
+ AssertionResult() = delete;
+ AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
+
+ bool isOk() const;
+ bool succeeded() const;
+ ResultWas::OfType getResultType() const;
+ bool hasExpression() const;
+ bool hasMessage() const;
+ std::string getExpression() const;
+ std::string getExpressionInMacro() const;
+ bool hasExpandedExpression() const;
+ std::string getExpandedExpression() const;
+ std::string getMessage() const;
+ SourceLineInfo getSourceInfo() const;
+ StringRef getTestMacroName() const;
+
+ //protected:
+ AssertionInfo m_info;
+ AssertionResultData m_resultData;
+ };
+
+} // end namespace Catch
+
+// end catch_assertionresult.h
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+// start catch_estimate.hpp
+
+ // Statistics estimates
+
+
+namespace Catch {
+ namespace Benchmark {
+ template <typename Duration>
+ struct Estimate {
+ Duration point;
+ Duration lower_bound;
+ Duration upper_bound;
+ double confidence_interval;
+
+ template <typename Duration2>
+ operator Estimate<Duration2>() const {
+ return { point, lower_bound, upper_bound, confidence_interval };
+ }
+ };
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_estimate.hpp
+// start catch_outlier_classification.hpp
+
+// Outlier information
+
+namespace Catch {
+ namespace Benchmark {
+ struct OutlierClassification {
+ int samples_seen = 0;
+ int low_severe = 0; // more than 3 times IQR below Q1
+ int low_mild = 0; // 1.5 to 3 times IQR below Q1
+ int high_mild = 0; // 1.5 to 3 times IQR above Q3
+ int high_severe = 0; // more than 3 times IQR above Q3
+
+ int total() const {
+ return low_severe + low_mild + high_mild + high_severe;
+ }
+ };
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_outlier_classification.hpp
+
+#include <iterator>
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+#include <string>
+#include <iosfwd>
+#include <map>
+#include <set>
+#include <memory>
+#include <algorithm>
+
+namespace Catch {
+
+ struct ReporterConfig {
+ explicit ReporterConfig( IConfigPtr const& _fullConfig );
+
+ ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream );
+
+ std::ostream& stream() const;
+ IConfigPtr fullConfig() const;
+
+ private:
+ std::ostream* m_stream;
+ IConfigPtr m_fullConfig;
+ };
+
+ struct ReporterPreferences {
+ bool shouldRedirectStdOut = false;
+ bool shouldReportAllAssertions = false;
+ };
+
+ template<typename T>
+ struct LazyStat : Option<T> {
+ LazyStat& operator=( T const& _value ) {
+ Option<T>::operator=( _value );
+ used = false;
+ return *this;
+ }
+ void reset() {
+ Option<T>::reset();
+ used = false;
+ }
+ bool used = false;
+ };
+
+ struct TestRunInfo {
+ TestRunInfo( std::string const& _name );
+ std::string name;
+ };
+ struct GroupInfo {
+ GroupInfo( std::string const& _name,
+ std::size_t _groupIndex,
+ std::size_t _groupsCount );
+
+ std::string name;
+ std::size_t groupIndex;
+ std::size_t groupsCounts;
+ };
+
+ struct AssertionStats {
+ AssertionStats( AssertionResult const& _assertionResult,
+ std::vector<MessageInfo> const& _infoMessages,
+ Totals const& _totals );
+
+ AssertionStats( AssertionStats const& ) = default;
+ AssertionStats( AssertionStats && ) = default;
+ AssertionStats& operator = ( AssertionStats const& ) = delete;
+ AssertionStats& operator = ( AssertionStats && ) = delete;
+ virtual ~AssertionStats();
+
+ AssertionResult assertionResult;
+ std::vector<MessageInfo> infoMessages;
+ Totals totals;
+ };
+
+ struct SectionStats {
+ SectionStats( SectionInfo const& _sectionInfo,
+ Counts const& _assertions,
+ double _durationInSeconds,
+ bool _missingAssertions );
+ SectionStats( SectionStats const& ) = default;
+ SectionStats( SectionStats && ) = default;
+ SectionStats& operator = ( SectionStats const& ) = default;
+ SectionStats& operator = ( SectionStats && ) = default;
+ virtual ~SectionStats();
+
+ SectionInfo sectionInfo;
+ Counts assertions;
+ double durationInSeconds;
+ bool missingAssertions;
+ };
+
+ struct TestCaseStats {
+ TestCaseStats( TestCaseInfo const& _testInfo,
+ Totals const& _totals,
+ std::string const& _stdOut,
+ std::string const& _stdErr,
+ bool _aborting );
+
+ TestCaseStats( TestCaseStats const& ) = default;
+ TestCaseStats( TestCaseStats && ) = default;
+ TestCaseStats& operator = ( TestCaseStats const& ) = default;
+ TestCaseStats& operator = ( TestCaseStats && ) = default;
+ virtual ~TestCaseStats();
+
+ TestCaseInfo testInfo;
+ Totals totals;
+ std::string stdOut;
+ std::string stdErr;
+ bool aborting;
+ };
+
+ struct TestGroupStats {
+ TestGroupStats( GroupInfo const& _groupInfo,
+ Totals const& _totals,
+ bool _aborting );
+ TestGroupStats( GroupInfo const& _groupInfo );
+
+ TestGroupStats( TestGroupStats const& ) = default;
+ TestGroupStats( TestGroupStats && ) = default;
+ TestGroupStats& operator = ( TestGroupStats const& ) = default;
+ TestGroupStats& operator = ( TestGroupStats && ) = default;
+ virtual ~TestGroupStats();
+
+ GroupInfo groupInfo;
+ Totals totals;
+ bool aborting;
+ };
+
+ struct TestRunStats {
+ TestRunStats( TestRunInfo const& _runInfo,
+ Totals const& _totals,
+ bool _aborting );
+
+ TestRunStats( TestRunStats const& ) = default;
+ TestRunStats( TestRunStats && ) = default;
+ TestRunStats& operator = ( TestRunStats const& ) = default;
+ TestRunStats& operator = ( TestRunStats && ) = default;
+ virtual ~TestRunStats();
+
+ TestRunInfo runInfo;
+ Totals totals;
+ bool aborting;
+ };
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ struct BenchmarkInfo {
+ std::string name;
+ double estimatedDuration;
+ int iterations;
+ int samples;
+ unsigned int resamples;
+ double clockResolution;
+ double clockCost;
+ };
+
+ template <class Duration>
+ struct BenchmarkStats {
+ BenchmarkInfo info;
+
+ std::vector<Duration> samples;
+ Benchmark::Estimate<Duration> mean;
+ Benchmark::Estimate<Duration> standardDeviation;
+ Benchmark::OutlierClassification outliers;
+ double outlierVariance;
+
+ template <typename Duration2>
+ operator BenchmarkStats<Duration2>() const {
+ std::vector<Duration2> samples2;
+ samples2.reserve(samples.size());
+ std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); });
+ return {
+ info,
+ std::move(samples2),
+ mean,
+ standardDeviation,
+ outliers,
+ outlierVariance,
+ };
+ }
+ };
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ struct IStreamingReporter {
+ virtual ~IStreamingReporter() = default;
+
+ // Implementing class must also provide the following static methods:
+ // static std::string getDescription();
+ // static std::set<Verbosity> getSupportedVerbosities()
+
+ virtual ReporterPreferences getPreferences() const = 0;
+
+ virtual void noMatchingTestCases( std::string const& spec ) = 0;
+
+ virtual void reportInvalidArguments(std::string const&) {}
+
+ virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
+ virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
+
+ virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
+ virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ virtual void benchmarkPreparing( std::string const& ) {}
+ virtual void benchmarkStarting( BenchmarkInfo const& ) {}
+ virtual void benchmarkEnded( BenchmarkStats<> const& ) {}
+ virtual void benchmarkFailed( std::string const& ) {}
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
+
+ // The return value indicates if the messages buffer should be cleared:
+ virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
+
+ virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
+ virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
+ virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
+ virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
+
+ virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
+
+ // Default empty implementation provided
+ virtual void fatalErrorEncountered( StringRef name );
+
+ virtual bool isMulti() const;
+ };
+ using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
+
+ struct IReporterFactory {
+ virtual ~IReporterFactory();
+ virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0;
+ virtual std::string getDescription() const = 0;
+ };
+ using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
+
+ struct IReporterRegistry {
+ using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
+ using Listeners = std::vector<IReporterFactoryPtr>;
+
+ virtual ~IReporterRegistry();
+ virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0;
+ virtual FactoryMap const& getFactories() const = 0;
+ virtual Listeners const& getListeners() const = 0;
+ };
+
+} // end namespace Catch
+
+// end catch_interfaces_reporter.h
+#include <algorithm>
+#include <cstring>
+#include <cfloat>
+#include <cstdio>
+#include <cassert>
+#include <memory>
+#include <ostream>
+
+namespace Catch {
+ void prepareExpandedExpression(AssertionResult& result);
+
+ // Returns double formatted as %.3f (format expected on output)
+ std::string getFormattedDuration( double duration );
+
+ //! Should the reporter show
+ bool shouldShowDuration( IConfig const& config, double duration );
+
+ std::string serializeFilters( std::vector<std::string> const& container );
+
+ template<typename DerivedT>
+ struct StreamingReporterBase : IStreamingReporter {
+
+ StreamingReporterBase( ReporterConfig const& _config )
+ : m_config( _config.fullConfig() ),
+ stream( _config.stream() )
+ {
+ m_reporterPrefs.shouldRedirectStdOut = false;
+ if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) )
+ CATCH_ERROR( "Verbosity level not supported by this reporter" );
+ }
+
+ ReporterPreferences getPreferences() const override {
+ return m_reporterPrefs;
+ }
+
+ static std::set<Verbosity> getSupportedVerbosities() {
+ return { Verbosity::Normal };
+ }
+
+ ~StreamingReporterBase() override = default;
+
+ void noMatchingTestCases(std::string const&) override {}
+
+ void reportInvalidArguments(std::string const&) override {}
+
+ void testRunStarting(TestRunInfo const& _testRunInfo) override {
+ currentTestRunInfo = _testRunInfo;
+ }
+
+ void testGroupStarting(GroupInfo const& _groupInfo) override {
+ currentGroupInfo = _groupInfo;
+ }
+
+ void testCaseStarting(TestCaseInfo const& _testInfo) override {
+ currentTestCaseInfo = _testInfo;
+ }
+ void sectionStarting(SectionInfo const& _sectionInfo) override {
+ m_sectionStack.push_back(_sectionInfo);
+ }
+
+ void sectionEnded(SectionStats const& /* _sectionStats */) override {
+ m_sectionStack.pop_back();
+ }
+ void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override {
+ currentTestCaseInfo.reset();
+ }
+ void testGroupEnded(TestGroupStats const& /* _testGroupStats */) override {
+ currentGroupInfo.reset();
+ }
+ void testRunEnded(TestRunStats const& /* _testRunStats */) override {
+ currentTestCaseInfo.reset();
+ currentGroupInfo.reset();
+ currentTestRunInfo.reset();
+ }
+
+ void skipTest(TestCaseInfo const&) override {
+ // Don't do anything with this by default.
+ // It can optionally be overridden in the derived class.
+ }
+
+ IConfigPtr m_config;
+ std::ostream& stream;
+
+ LazyStat<TestRunInfo> currentTestRunInfo;
+ LazyStat<GroupInfo> currentGroupInfo;
+ LazyStat<TestCaseInfo> currentTestCaseInfo;
+
+ std::vector<SectionInfo> m_sectionStack;
+ ReporterPreferences m_reporterPrefs;
+ };
+
+ template<typename DerivedT>
+ struct CumulativeReporterBase : IStreamingReporter {
+ template<typename T, typename ChildNodeT>
+ struct Node {
+ explicit Node( T const& _value ) : value( _value ) {}
+ virtual ~Node() {}
+
+ using ChildNodes = std::vector<std::shared_ptr<ChildNodeT>>;
+ T value;
+ ChildNodes children;
+ };
+ struct SectionNode {
+ explicit SectionNode(SectionStats const& _stats) : stats(_stats) {}
+ virtual ~SectionNode() = default;
+
+ bool operator == (SectionNode const& other) const {
+ return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
+ }
+ bool operator == (std::shared_ptr<SectionNode> const& other) const {
+ return operator==(*other);
+ }
+
+ SectionStats stats;
+ using ChildSections = std::vector<std::shared_ptr<SectionNode>>;
+ using Assertions = std::vector<AssertionStats>;
+ ChildSections childSections;
+ Assertions assertions;
+ std::string stdOut;
+ std::string stdErr;
+ };
+
+ struct BySectionInfo {
+ BySectionInfo( SectionInfo const& other ) : m_other( other ) {}
+ BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {}
+ bool operator() (std::shared_ptr<SectionNode> const& node) const {
+ return ((node->stats.sectionInfo.name == m_other.name) &&
+ (node->stats.sectionInfo.lineInfo == m_other.lineInfo));
+ }
+ void operator=(BySectionInfo const&) = delete;
+
+ private:
+ SectionInfo const& m_other;
+ };
+
+ using TestCaseNode = Node<TestCaseStats, SectionNode>;
+ using TestGroupNode = Node<TestGroupStats, TestCaseNode>;
+ using TestRunNode = Node<TestRunStats, TestGroupNode>;
+
+ CumulativeReporterBase( ReporterConfig const& _config )
+ : m_config( _config.fullConfig() ),
+ stream( _config.stream() )
+ {
+ m_reporterPrefs.shouldRedirectStdOut = false;
+ if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) )
+ CATCH_ERROR( "Verbosity level not supported by this reporter" );
+ }
+ ~CumulativeReporterBase() override = default;
+
+ ReporterPreferences getPreferences() const override {
+ return m_reporterPrefs;
+ }
+
+ static std::set<Verbosity> getSupportedVerbosities() {
+ return { Verbosity::Normal };
+ }
+
+ void testRunStarting( TestRunInfo const& ) override {}
+ void testGroupStarting( GroupInfo const& ) override {}
+
+ void testCaseStarting( TestCaseInfo const& ) override {}
+
+ void sectionStarting( SectionInfo const& sectionInfo ) override {
+ SectionStats incompleteStats( sectionInfo, Counts(), 0, false );
+ std::shared_ptr<SectionNode> node;
+ if( m_sectionStack.empty() ) {
+ if( !m_rootSection )
+ m_rootSection = std::make_shared<SectionNode>( incompleteStats );
+ node = m_rootSection;
+ }
+ else {
+ SectionNode& parentNode = *m_sectionStack.back();
+ auto it =
+ std::find_if( parentNode.childSections.begin(),
+ parentNode.childSections.end(),
+ BySectionInfo( sectionInfo ) );
+ if( it == parentNode.childSections.end() ) {
+ node = std::make_shared<SectionNode>( incompleteStats );
+ parentNode.childSections.push_back( node );
+ }
+ else
+ node = *it;
+ }
+ m_sectionStack.push_back( node );
+ m_deepestSection = std::move(node);
+ }
+
+ void assertionStarting(AssertionInfo const&) override {}
+
+ bool assertionEnded(AssertionStats const& assertionStats) override {
+ assert(!m_sectionStack.empty());
+ // AssertionResult holds a pointer to a temporary DecomposedExpression,
+ // which getExpandedExpression() calls to build the expression string.
+ // Our section stack copy of the assertionResult will likely outlive the
+ // temporary, so it must be expanded or discarded now to avoid calling
+ // a destroyed object later.
+ prepareExpandedExpression(const_cast<AssertionResult&>( assertionStats.assertionResult ) );
+ SectionNode& sectionNode = *m_sectionStack.back();
+ sectionNode.assertions.push_back(assertionStats);
+ return true;
+ }
+ void sectionEnded(SectionStats const& sectionStats) override {
+ assert(!m_sectionStack.empty());
+ SectionNode& node = *m_sectionStack.back();
+ node.stats = sectionStats;
+ m_sectionStack.pop_back();
+ }
+ void testCaseEnded(TestCaseStats const& testCaseStats) override {
+ auto node = std::make_shared<TestCaseNode>(testCaseStats);
+ assert(m_sectionStack.size() == 0);
+ node->children.push_back(m_rootSection);
+ m_testCases.push_back(node);
+ m_rootSection.reset();
+
+ assert(m_deepestSection);
+ m_deepestSection->stdOut = testCaseStats.stdOut;
+ m_deepestSection->stdErr = testCaseStats.stdErr;
+ }
+ void testGroupEnded(TestGroupStats const& testGroupStats) override {
+ auto node = std::make_shared<TestGroupNode>(testGroupStats);
+ node->children.swap(m_testCases);
+ m_testGroups.push_back(node);
+ }
+ void testRunEnded(TestRunStats const& testRunStats) override {
+ auto node = std::make_shared<TestRunNode>(testRunStats);
+ node->children.swap(m_testGroups);
+ m_testRuns.push_back(node);
+ testRunEndedCumulative();
+ }
+ virtual void testRunEndedCumulative() = 0;
+
+ void skipTest(TestCaseInfo const&) override {}
+
+ IConfigPtr m_config;
+ std::ostream& stream;
+ std::vector<AssertionStats> m_assertions;
+ std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections;
+ std::vector<std::shared_ptr<TestCaseNode>> m_testCases;
+ std::vector<std::shared_ptr<TestGroupNode>> m_testGroups;
+
+ std::vector<std::shared_ptr<TestRunNode>> m_testRuns;
+
+ std::shared_ptr<SectionNode> m_rootSection;
+ std::shared_ptr<SectionNode> m_deepestSection;
+ std::vector<std::shared_ptr<SectionNode>> m_sectionStack;
+ ReporterPreferences m_reporterPrefs;
+ };
+
+ template<char C>
+ char const* getLineOfChars() {
+ static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
+ if( !*line ) {
+ std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
+ line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
+ }
+ return line;
+ }
+
+ struct TestEventListenerBase : StreamingReporterBase<TestEventListenerBase> {
+ TestEventListenerBase( ReporterConfig const& _config );
+
+ static std::set<Verbosity> getSupportedVerbosities();
+
+ void assertionStarting(AssertionInfo const&) override;
+ bool assertionEnded(AssertionStats const&) override;
+ };
+
+} // end namespace Catch
+
+// end catch_reporter_bases.hpp
+// start catch_console_colour.h
+
+namespace Catch {
+
+ struct Colour {
+ enum Code {
+ None = 0,
+
+ White,
+ Red,
+ Green,
+ Blue,
+ Cyan,
+ Yellow,
+ Grey,
+
+ Bright = 0x10,
+
+ BrightRed = Bright | Red,
+ BrightGreen = Bright | Green,
+ LightGrey = Bright | Grey,
+ BrightWhite = Bright | White,
+ BrightYellow = Bright | Yellow,
+
+ // By intention
+ FileName = LightGrey,
+ Warning = BrightYellow,
+ ResultError = BrightRed,
+ ResultSuccess = BrightGreen,
+ ResultExpectedFailure = Warning,
+
+ Error = BrightRed,
+ Success = Green,
+
+ OriginalExpression = Cyan,
+ ReconstructedExpression = BrightYellow,
+
+ SecondaryText = LightGrey,
+ Headers = White
+ };
+
+ // Use constructed object for RAII guard
+ Colour( Code _colourCode );
+ Colour( Colour&& other ) noexcept;
+ Colour& operator=( Colour&& other ) noexcept;
+ ~Colour();
+
+ // Use static method for one-shot changes
+ static void use( Code _colourCode );
+
+ private:
+ bool m_moved = false;
+ };
+
+ std::ostream& operator << ( std::ostream& os, Colour const& );
+
+} // end namespace Catch
+
+// end catch_console_colour.h
+// start catch_reporter_registrars.hpp
+
+
+namespace Catch {
+
+ template<typename T>
+ class ReporterRegistrar {
+
+ class ReporterFactory : public IReporterFactory {
+
+ IStreamingReporterPtr create( ReporterConfig const& config ) const override {
+ return std::unique_ptr<T>( new T( config ) );
+ }
+
+ std::string getDescription() const override {
+ return T::getDescription();
+ }
+ };
+
+ public:
+
+ explicit ReporterRegistrar( std::string const& name ) {
+ getMutableRegistryHub().registerReporter( name, std::make_shared<ReporterFactory>() );
+ }
+ };
+
+ template<typename T>
+ class ListenerRegistrar {
+
+ class ListenerFactory : public IReporterFactory {
+
+ IStreamingReporterPtr create( ReporterConfig const& config ) const override {
+ return std::unique_ptr<T>( new T( config ) );
+ }
+ std::string getDescription() const override {
+ return std::string();
+ }
+ };
+
+ public:
+
+ ListenerRegistrar() {
+ getMutableRegistryHub().registerListener( std::make_shared<ListenerFactory>() );
+ }
+ };
+}
+
+#if !defined(CATCH_CONFIG_DISABLE)
+
+#define CATCH_REGISTER_REPORTER( name, reporterType ) \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
+
+#define CATCH_REGISTER_LISTENER( listenerType ) \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
+ namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
+#else // CATCH_CONFIG_DISABLE
+
+#define CATCH_REGISTER_REPORTER(name, reporterType)
+#define CATCH_REGISTER_LISTENER(listenerType)
+
+#endif // CATCH_CONFIG_DISABLE
+
+// end catch_reporter_registrars.hpp
+// Allow users to base their work off existing reporters
+// start catch_reporter_compact.h
+
+namespace Catch {
+
+ struct CompactReporter : StreamingReporterBase<CompactReporter> {
+
+ using StreamingReporterBase::StreamingReporterBase;
+
+ ~CompactReporter() override;
+
+ static std::string getDescription();
+
+ void noMatchingTestCases(std::string const& spec) override;
+
+ void assertionStarting(AssertionInfo const&) override;
+
+ bool assertionEnded(AssertionStats const& _assertionStats) override;
+
+ void sectionEnded(SectionStats const& _sectionStats) override;
+
+ void testRunEnded(TestRunStats const& _testRunStats) override;
+
+ };
+
+} // end namespace Catch
+
+// end catch_reporter_compact.h
+// start catch_reporter_console.h
+
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch
+ // Note that 4062 (not all labels are handled
+ // and default is missing) is enabled
+#endif
+
+namespace Catch {
+ // Fwd decls
+ struct SummaryColumn;
+ class TablePrinter;
+
+ struct ConsoleReporter : StreamingReporterBase<ConsoleReporter> {
+ std::unique_ptr<TablePrinter> m_tablePrinter;
+
+ ConsoleReporter(ReporterConfig const& config);
+ ~ConsoleReporter() override;
+ static std::string getDescription();
+
+ void noMatchingTestCases(std::string const& spec) override;
+
+ void reportInvalidArguments(std::string const&arg) override;
+
+ void assertionStarting(AssertionInfo const&) override;
+
+ bool assertionEnded(AssertionStats const& _assertionStats) override;
+
+ void sectionStarting(SectionInfo const& _sectionInfo) override;
+ void sectionEnded(SectionStats const& _sectionStats) override;
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ void benchmarkPreparing(std::string const& name) override;
+ void benchmarkStarting(BenchmarkInfo const& info) override;
+ void benchmarkEnded(BenchmarkStats<> const& stats) override;
+ void benchmarkFailed(std::string const& error) override;
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ void testCaseEnded(TestCaseStats const& _testCaseStats) override;
+ void testGroupEnded(TestGroupStats const& _testGroupStats) override;
+ void testRunEnded(TestRunStats const& _testRunStats) override;
+ void testRunStarting(TestRunInfo const& _testRunInfo) override;
+ private:
+
+ void lazyPrint();
+
+ void lazyPrintWithoutClosingBenchmarkTable();
+ void lazyPrintRunInfo();
+ void lazyPrintGroupInfo();
+ void printTestCaseAndSectionHeader();
+
+ void printClosedHeader(std::string const& _name);
+ void printOpenHeader(std::string const& _name);
+
+ // if string has a : in first line will set indent to follow it on
+ // subsequent lines
+ void printHeaderString(std::string const& _string, std::size_t indent = 0);
+
+ void printTotals(Totals const& totals);
+ void printSummaryRow(std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row);
+
+ void printTotalsDivider(Totals const& totals);
+ void printSummaryDivider();
+ void printTestFilters();
+
+ private:
+ bool m_headerPrinted = false;
+ };
+
+} // end namespace Catch
+
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
+
+// end catch_reporter_console.h
+// start catch_reporter_junit.h
+
+// start catch_xmlwriter.h
+
+#include <vector>
+
+namespace Catch {
+ enum class XmlFormatting {
+ None = 0x00,
+ Indent = 0x01,
+ Newline = 0x02,
+ };
+
+ XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs);
+ XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs);
+
+ class XmlEncode {
+ public:
+ enum ForWhat { ForTextNodes, ForAttributes };
+
+ XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes );
+
+ void encodeTo( std::ostream& os ) const;
+
+ friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode );
+
+ private:
+ std::string m_str;
+ ForWhat m_forWhat;
+ };
+
+ class XmlWriter {
+ public:
+
+ class ScopedElement {
+ public:
+ ScopedElement( XmlWriter* writer, XmlFormatting fmt );
+
+ ScopedElement( ScopedElement&& other ) noexcept;
+ ScopedElement& operator=( ScopedElement&& other ) noexcept;
+
+ ~ScopedElement();
+
+ ScopedElement& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent );
+
+ template<typename T>
+ ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
+ m_writer->writeAttribute( name, attribute );
+ return *this;
+ }
+
+ private:
+ mutable XmlWriter* m_writer = nullptr;
+ XmlFormatting m_fmt;
+ };
+
+ XmlWriter( std::ostream& os = Catch::cout() );
+ ~XmlWriter();
+
+ XmlWriter( XmlWriter const& ) = delete;
+ XmlWriter& operator=( XmlWriter const& ) = delete;
+
+ XmlWriter& startElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
+
+ ScopedElement scopedElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
+
+ XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
+
+ XmlWriter& writeAttribute( std::string const& name, std::string const& attribute );
+
+ XmlWriter& writeAttribute( std::string const& name, bool attribute );
+
+ template<typename T>
+ XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
+ ReusableStringStream rss;
+ rss << attribute;
+ return writeAttribute( name, rss.str() );
+ }
+
+ XmlWriter& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
+
+ XmlWriter& writeComment(std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
+
+ void writeStylesheetRef( std::string const& url );
+
+ XmlWriter& writeBlankLine();
+
+ void ensureTagClosed();
+
+ private:
+
+ void applyFormatting(XmlFormatting fmt);
+
+ void writeDeclaration();
+
+ void newlineIfNecessary();
+
+ bool m_tagIsOpen = false;
+ bool m_needsNewline = false;
+ std::vector<std::string> m_tags;
+ std::string m_indent;
+ std::ostream& m_os;
+ };
+
+}
+
+// end catch_xmlwriter.h
+namespace Catch {
+
+ class JunitReporter : public CumulativeReporterBase<JunitReporter> {
+ public:
+ JunitReporter(ReporterConfig const& _config);
+
+ ~JunitReporter() override;
+
+ static std::string getDescription();
+
+ void noMatchingTestCases(std::string const& /*spec*/) override;
+
+ void testRunStarting(TestRunInfo const& runInfo) override;
+
+ void testGroupStarting(GroupInfo const& groupInfo) override;
+
+ void testCaseStarting(TestCaseInfo const& testCaseInfo) override;
+ bool assertionEnded(AssertionStats const& assertionStats) override;
+
+ void testCaseEnded(TestCaseStats const& testCaseStats) override;
+
+ void testGroupEnded(TestGroupStats const& testGroupStats) override;
+
+ void testRunEndedCumulative() override;
+
+ void writeGroup(TestGroupNode const& groupNode, double suiteTime);
+
+ void writeTestCase(TestCaseNode const& testCaseNode);
+
+ void writeSection( std::string const& className,
+ std::string const& rootName,
+ SectionNode const& sectionNode,
+ bool testOkToFail );
+
+ void writeAssertions(SectionNode const& sectionNode);
+ void writeAssertion(AssertionStats const& stats);
+
+ XmlWriter xml;
+ Timer suiteTimer;
+ std::string stdOutForSuite;
+ std::string stdErrForSuite;
+ unsigned int unexpectedExceptions = 0;
+ bool m_okToFail = false;
+ };
+
+} // end namespace Catch
+
+// end catch_reporter_junit.h
+// start catch_reporter_xml.h
+
+namespace Catch {
+ class XmlReporter : public StreamingReporterBase<XmlReporter> {
+ public:
+ XmlReporter(ReporterConfig const& _config);
+
+ ~XmlReporter() override;
+
+ static std::string getDescription();
+
+ virtual std::string getStylesheetRef() const;
+
+ void writeSourceInfo(SourceLineInfo const& sourceInfo);
+
+ public: // StreamingReporterBase
+
+ void noMatchingTestCases(std::string const& s) override;
+
+ void testRunStarting(TestRunInfo const& testInfo) override;
+
+ void testGroupStarting(GroupInfo const& groupInfo) override;
+
+ void testCaseStarting(TestCaseInfo const& testInfo) override;
+
+ void sectionStarting(SectionInfo const& sectionInfo) override;
+
+ void assertionStarting(AssertionInfo const&) override;
+
+ bool assertionEnded(AssertionStats const& assertionStats) override;
+
+ void sectionEnded(SectionStats const& sectionStats) override;
+
+ void testCaseEnded(TestCaseStats const& testCaseStats) override;
+
+ void testGroupEnded(TestGroupStats const& testGroupStats) override;
+
+ void testRunEnded(TestRunStats const& testRunStats) override;
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ void benchmarkPreparing(std::string const& name) override;
+ void benchmarkStarting(BenchmarkInfo const&) override;
+ void benchmarkEnded(BenchmarkStats<> const&) override;
+ void benchmarkFailed(std::string const&) override;
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ private:
+ Timer m_testCaseTimer;
+ XmlWriter m_xml;
+ int m_sectionDepth = 0;
+ };
+
+} // end namespace Catch
+
+// end catch_reporter_xml.h
+
+// end catch_external_interfaces.h
+#endif
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+// start catch_benchmarking_all.hpp
+
+// A proxy header that includes all of the benchmarking headers to allow
+// concise include of the benchmarking features. You should prefer the
+// individual includes in standard use.
+
+// start catch_benchmark.hpp
+
+ // Benchmark
+
+// start catch_chronometer.hpp
+
+// User-facing chronometer
+
+
+// start catch_clock.hpp
+
+// Clocks
+
+
+#include <chrono>
+#include <ratio>
+
+namespace Catch {
+ namespace Benchmark {
+ template <typename Clock>
+ using ClockDuration = typename Clock::duration;
+ template <typename Clock>
+ using FloatDuration = std::chrono::duration<double, typename Clock::period>;
+
+ template <typename Clock>
+ using TimePoint = typename Clock::time_point;
+
+ using default_clock = std::chrono::steady_clock;
+
+ template <typename Clock>
+ struct now {
+ TimePoint<Clock> operator()() const {
+ return Clock::now();
+ }
+ };
+
+ using fp_seconds = std::chrono::duration<double, std::ratio<1>>;
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_clock.hpp
+// start catch_optimizer.hpp
+
+ // Hinting the optimizer
+
+
+#if defined(_MSC_VER)
+# include <atomic> // atomic_thread_fence
+#endif
+
+namespace Catch {
+ namespace Benchmark {
+#if defined(__GNUC__) || defined(__clang__)
+ template <typename T>
+ inline void keep_memory(T* p) {
+ asm volatile("" : : "g"(p) : "memory");
+ }
+ inline void keep_memory() {
+ asm volatile("" : : : "memory");
+ }
+
+ namespace Detail {
+ inline void optimizer_barrier() { keep_memory(); }
+ } // namespace Detail
+#elif defined(_MSC_VER)
+
+#pragma optimize("", off)
+ template <typename T>
+ inline void keep_memory(T* p) {
+ // thanks @milleniumbug
+ *reinterpret_cast<char volatile*>(p) = *reinterpret_cast<char const volatile*>(p);
+ }
+ // TODO equivalent keep_memory()
+#pragma optimize("", on)
+
+ namespace Detail {
+ inline void optimizer_barrier() {
+ std::atomic_thread_fence(std::memory_order_seq_cst);
+ }
+ } // namespace Detail
+
+#endif
+
+ template <typename T>
+ inline void deoptimize_value(T&& x) {
+ keep_memory(&x);
+ }
+
+ template <typename Fn, typename... Args>
+ inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<!std::is_same<void, decltype(fn(args...))>::value>::type {
+ deoptimize_value(std::forward<Fn>(fn) (std::forward<Args...>(args...)));
+ }
+
+ template <typename Fn, typename... Args>
+ inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<std::is_same<void, decltype(fn(args...))>::value>::type {
+ std::forward<Fn>(fn) (std::forward<Args...>(args...));
+ }
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_optimizer.hpp
+// start catch_complete_invoke.hpp
+
+// Invoke with a special case for void
+
+
+#include <type_traits>
+#include <utility>
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+ template <typename T>
+ struct CompleteType { using type = T; };
+ template <>
+ struct CompleteType<void> { struct type {}; };
+
+ template <typename T>
+ using CompleteType_t = typename CompleteType<T>::type;
+
+ template <typename Result>
+ struct CompleteInvoker {
+ template <typename Fun, typename... Args>
+ static Result invoke(Fun&& fun, Args&&... args) {
+ return std::forward<Fun>(fun)(std::forward<Args>(args)...);
+ }
+ };
+ template <>
+ struct CompleteInvoker<void> {
+ template <typename Fun, typename... Args>
+ static CompleteType_t<void> invoke(Fun&& fun, Args&&... args) {
+ std::forward<Fun>(fun)(std::forward<Args>(args)...);
+ return {};
+ }
+ };
+
+ // invoke and not return void :(
+ template <typename Fun, typename... Args>
+ CompleteType_t<FunctionReturnType<Fun, Args...>> complete_invoke(Fun&& fun, Args&&... args) {
+ return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...);
+ }
+
+ const std::string benchmarkErrorMsg = "a benchmark failed to run successfully";
+ } // namespace Detail
+
+ template <typename Fun>
+ Detail::CompleteType_t<FunctionReturnType<Fun>> user_code(Fun&& fun) {
+ CATCH_TRY{
+ return Detail::complete_invoke(std::forward<Fun>(fun));
+ } CATCH_CATCH_ALL{
+ getResultCapture().benchmarkFailed(translateActiveException());
+ CATCH_RUNTIME_ERROR(Detail::benchmarkErrorMsg);
+ }
+ }
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_complete_invoke.hpp
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+ struct ChronometerConcept {
+ virtual void start() = 0;
+ virtual void finish() = 0;
+ virtual ~ChronometerConcept() = default;
+ };
+ template <typename Clock>
+ struct ChronometerModel final : public ChronometerConcept {
+ void start() override { started = Clock::now(); }
+ void finish() override { finished = Clock::now(); }
+
+ ClockDuration<Clock> elapsed() const { return finished - started; }
+
+ TimePoint<Clock> started;
+ TimePoint<Clock> finished;
+ };
+ } // namespace Detail
+
+ struct Chronometer {
+ public:
+ template <typename Fun>
+ void measure(Fun&& fun) { measure(std::forward<Fun>(fun), is_callable<Fun(int)>()); }
+
+ int runs() const { return k; }
+
+ Chronometer(Detail::ChronometerConcept& meter, int k)
+ : impl(&meter)
+ , k(k) {}
+
+ private:
+ template <typename Fun>
+ void measure(Fun&& fun, std::false_type) {
+ measure([&fun](int) { return fun(); }, std::true_type());
+ }
+
+ template <typename Fun>
+ void measure(Fun&& fun, std::true_type) {
+ Detail::optimizer_barrier();
+ impl->start();
+ for (int i = 0; i < k; ++i) invoke_deoptimized(fun, i);
+ impl->finish();
+ Detail::optimizer_barrier();
+ }
+
+ Detail::ChronometerConcept* impl;
+ int k;
+ };
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_chronometer.hpp
+// start catch_environment.hpp
+
+// Environment information
+
+
+namespace Catch {
+ namespace Benchmark {
+ template <typename Duration>
+ struct EnvironmentEstimate {
+ Duration mean;
+ OutlierClassification outliers;
+
+ template <typename Duration2>
+ operator EnvironmentEstimate<Duration2>() const {
+ return { mean, outliers };
+ }
+ };
+ template <typename Clock>
+ struct Environment {
+ using clock_type = Clock;
+ EnvironmentEstimate<FloatDuration<Clock>> clock_resolution;
+ EnvironmentEstimate<FloatDuration<Clock>> clock_cost;
+ };
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_environment.hpp
+// start catch_execution_plan.hpp
+
+ // Execution plan
+
+
+// start catch_benchmark_function.hpp
+
+ // Dumb std::function implementation for consistent call overhead
+
+
+#include <cassert>
+#include <type_traits>
+#include <utility>
+#include <memory>
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+ template <typename T>
+ using Decay = typename std::decay<T>::type;
+ template <typename T, typename U>
+ struct is_related
+ : std::is_same<Decay<T>, Decay<U>> {};
+
+ /// We need to reinvent std::function because every piece of code that might add overhead
+ /// in a measurement context needs to have consistent performance characteristics so that we
+ /// can account for it in the measurement.
+ /// Implementations of std::function with optimizations that aren't always applicable, like
+ /// small buffer optimizations, are not uncommon.
+ /// This is effectively an implementation of std::function without any such optimizations;
+ /// it may be slow, but it is consistently slow.
+ struct BenchmarkFunction {
+ private:
+ struct callable {
+ virtual void call(Chronometer meter) const = 0;
+ virtual callable* clone() const = 0;
+ virtual ~callable() = default;
+ };
+ template <typename Fun>
+ struct model : public callable {
+ model(Fun&& fun) : fun(std::move(fun)) {}
+ model(Fun const& fun) : fun(fun) {}
+
+ model<Fun>* clone() const override { return new model<Fun>(*this); }
+
+ void call(Chronometer meter) const override {
+ call(meter, is_callable<Fun(Chronometer)>());
+ }
+ void call(Chronometer meter, std::true_type) const {
+ fun(meter);
+ }
+ void call(Chronometer meter, std::false_type) const {
+ meter.measure(fun);
+ }
+
+ Fun fun;
+ };
+
+ struct do_nothing { void operator()() const {} };
+
+ template <typename T>
+ BenchmarkFunction(model<T>* c) : f(c) {}
+
+ public:
+ BenchmarkFunction()
+ : f(new model<do_nothing>{ {} }) {}
+
+ template <typename Fun,
+ typename std::enable_if<!is_related<Fun, BenchmarkFunction>::value, int>::type = 0>
+ BenchmarkFunction(Fun&& fun)
+ : f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {}
+
+ BenchmarkFunction(BenchmarkFunction&& that)
+ : f(std::move(that.f)) {}
+
+ BenchmarkFunction(BenchmarkFunction const& that)
+ : f(that.f->clone()) {}
+
+ BenchmarkFunction& operator=(BenchmarkFunction&& that) {
+ f = std::move(that.f);
+ return *this;
+ }
+
+ BenchmarkFunction& operator=(BenchmarkFunction const& that) {
+ f.reset(that.f->clone());
+ return *this;
+ }
+
+ void operator()(Chronometer meter) const { f->call(meter); }
+
+ private:
+ std::unique_ptr<callable> f;
+ };
+ } // namespace Detail
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_benchmark_function.hpp
+// start catch_repeat.hpp
+
+// repeat algorithm
+
+
+#include <type_traits>
+#include <utility>
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+ template <typename Fun>
+ struct repeater {
+ void operator()(int k) const {
+ for (int i = 0; i < k; ++i) {
+ fun();
+ }
+ }
+ Fun fun;
+ };
+ template <typename Fun>
+ repeater<typename std::decay<Fun>::type> repeat(Fun&& fun) {
+ return { std::forward<Fun>(fun) };
+ }
+ } // namespace Detail
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_repeat.hpp
+// start catch_run_for_at_least.hpp
+
+// Run a function for a minimum amount of time
+
+
+// start catch_measure.hpp
+
+// Measure
+
+
+// start catch_timing.hpp
+
+// Timing
+
+
+#include <tuple>
+#include <type_traits>
+
+namespace Catch {
+ namespace Benchmark {
+ template <typename Duration, typename Result>
+ struct Timing {
+ Duration elapsed;
+ Result result;
+ int iterations;
+ };
+ template <typename Clock, typename Func, typename... Args>
+ using TimingOf = Timing<ClockDuration<Clock>, Detail::CompleteType_t<FunctionReturnType<Func, Args...>>>;
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_timing.hpp
+#include <utility>
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+ template <typename Clock, typename Fun, typename... Args>
+ TimingOf<Clock, Fun, Args...> measure(Fun&& fun, Args&&... args) {
+ auto start = Clock::now();
+ auto&& r = Detail::complete_invoke(fun, std::forward<Args>(args)...);
+ auto end = Clock::now();
+ auto delta = end - start;
+ return { delta, std::forward<decltype(r)>(r), 1 };
+ }
+ } // namespace Detail
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_measure.hpp
+#include <utility>
+#include <type_traits>
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+ template <typename Clock, typename Fun>
+ TimingOf<Clock, Fun, int> measure_one(Fun&& fun, int iters, std::false_type) {
+ return Detail::measure<Clock>(fun, iters);
+ }
+ template <typename Clock, typename Fun>
+ TimingOf<Clock, Fun, Chronometer> measure_one(Fun&& fun, int iters, std::true_type) {
+ Detail::ChronometerModel<Clock> meter;
+ auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters));
+
+ return { meter.elapsed(), std::move(result), iters };
+ }
+
+ template <typename Clock, typename Fun>
+ using run_for_at_least_argument_t = typename std::conditional<is_callable<Fun(Chronometer)>::value, Chronometer, int>::type;
+
+ struct optimized_away_error : std::exception {
+ const char* what() const noexcept override {
+ return "could not measure benchmark, maybe it was optimized away";
+ }
+ };
+
+ template <typename Clock, typename Fun>
+ TimingOf<Clock, Fun, run_for_at_least_argument_t<Clock, Fun>> run_for_at_least(ClockDuration<Clock> how_long, int seed, Fun&& fun) {
+ auto iters = seed;
+ while (iters < (1 << 30)) {
+ auto&& Timing = measure_one<Clock>(fun, iters, is_callable<Fun(Chronometer)>());
+
+ if (Timing.elapsed >= how_long) {
+ return { Timing.elapsed, std::move(Timing.result), iters };
+ }
+ iters *= 2;
+ }
+ Catch::throw_exception(optimized_away_error{});
+ }
+ } // namespace Detail
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_run_for_at_least.hpp
+#include <algorithm>
+#include <iterator>
+
+namespace Catch {
+ namespace Benchmark {
+ template <typename Duration>
+ struct ExecutionPlan {
+ int iterations_per_sample;
+ Duration estimated_duration;
+ Detail::BenchmarkFunction benchmark;
+ Duration warmup_time;
+ int warmup_iterations;
+
+ template <typename Duration2>
+ operator ExecutionPlan<Duration2>() const {
+ return { iterations_per_sample, estimated_duration, benchmark, warmup_time, warmup_iterations };
+ }
+
+ template <typename Clock>
+ std::vector<FloatDuration<Clock>> run(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const {
+ // warmup a bit
+ Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_iterations, Detail::repeat(now<Clock>{}));
+
+ std::vector<FloatDuration<Clock>> times;
+ times.reserve(cfg.benchmarkSamples());
+ std::generate_n(std::back_inserter(times), cfg.benchmarkSamples(), [this, env] {
+ Detail::ChronometerModel<Clock> model;
+ this->benchmark(Chronometer(model, iterations_per_sample));
+ auto sample_time = model.elapsed() - env.clock_cost.mean;
+ if (sample_time < FloatDuration<Clock>::zero()) sample_time = FloatDuration<Clock>::zero();
+ return sample_time / iterations_per_sample;
+ });
+ return times;
+ }
+ };
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_execution_plan.hpp
+// start catch_estimate_clock.hpp
+
+ // Environment measurement
+
+
+// start catch_stats.hpp
+
+// Statistical analysis tools
+
+
+#include <algorithm>
+#include <functional>
+#include <vector>
+#include <iterator>
+#include <numeric>
+#include <tuple>
+#include <cmath>
+#include <utility>
+#include <cstddef>
+#include <random>
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+ using sample = std::vector<double>;
+
+ double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last);
+
+ template <typename Iterator>
+ OutlierClassification classify_outliers(Iterator first, Iterator last) {
+ std::vector<double> copy(first, last);
+
+ auto q1 = weighted_average_quantile(1, 4, copy.begin(), copy.end());
+ auto q3 = weighted_average_quantile(3, 4, copy.begin(), copy.end());
+ auto iqr = q3 - q1;
+ auto los = q1 - (iqr * 3.);
+ auto lom = q1 - (iqr * 1.5);
+ auto him = q3 + (iqr * 1.5);
+ auto his = q3 + (iqr * 3.);
+
+ OutlierClassification o;
+ for (; first != last; ++first) {
+ auto&& t = *first;
+ if (t < los) ++o.low_severe;
+ else if (t < lom) ++o.low_mild;
+ else if (t > his) ++o.high_severe;
+ else if (t > him) ++o.high_mild;
+ ++o.samples_seen;
+ }
+ return o;
+ }
+
+ template <typename Iterator>
+ double mean(Iterator first, Iterator last) {
+ auto count = last - first;
+ double sum = std::accumulate(first, last, 0.);
+ return sum / count;
+ }
+
+ template <typename URng, typename Iterator, typename Estimator>
+ sample resample(URng& rng, int resamples, Iterator first, Iterator last, Estimator& estimator) {
+ auto n = last - first;
+ std::uniform_int_distribution<decltype(n)> dist(0, n - 1);
+
+ sample out;
+ out.reserve(resamples);
+ std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] {
+ std::vector<double> resampled;
+ resampled.reserve(n);
+ std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[dist(rng)]; });
+ return estimator(resampled.begin(), resampled.end());
+ });
+ std::sort(out.begin(), out.end());
+ return out;
+ }
+
+ template <typename Estimator, typename Iterator>
+ sample jackknife(Estimator&& estimator, Iterator first, Iterator last) {
+ auto n = last - first;
+ auto second = std::next(first);
+ sample results;
+ results.reserve(n);
+
+ for (auto it = first; it != last; ++it) {
+ std::iter_swap(it, first);
+ results.push_back(estimator(second, last));
+ }
+
+ return results;
+ }
+
+ inline double normal_cdf(double x) {
+ return std::erfc(-x / std::sqrt(2.0)) / 2.0;
+ }
+
+ double erfc_inv(double x);
+
+ double normal_quantile(double p);
+
+ template <typename Iterator, typename Estimator>
+ Estimate<double> bootstrap(double confidence_level, Iterator first, Iterator last, sample const& resample, Estimator&& estimator) {
+ auto n_samples = last - first;
+
+ double point = estimator(first, last);
+ // Degenerate case with a single sample
+ if (n_samples == 1) return { point, point, point, confidence_level };
+
+ sample jack = jackknife(estimator, first, last);
+ double jack_mean = mean(jack.begin(), jack.end());
+ double sum_squares, sum_cubes;
+ std::tie(sum_squares, sum_cubes) = std::accumulate(jack.begin(), jack.end(), std::make_pair(0., 0.), [jack_mean](std::pair<double, double> sqcb, double x) -> std::pair<double, double> {
+ auto d = jack_mean - x;
+ auto d2 = d * d;
+ auto d3 = d2 * d;
+ return { sqcb.first + d2, sqcb.second + d3 };
+ });
+
+ double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5));
+ int n = static_cast<int>(resample.size());
+ double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / (double)n;
+ // degenerate case with uniform samples
+ if (prob_n == 0) return { point, point, point, confidence_level };
+
+ double bias = normal_quantile(prob_n);
+ double z1 = normal_quantile((1. - confidence_level) / 2.);
+
+ auto cumn = [n](double x) -> int {
+ return std::lround(normal_cdf(x) * n); };
+ auto a = [bias, accel](double b) { return bias + b / (1. - accel * b); };
+ double b1 = bias + z1;
+ double b2 = bias - z1;
+ double a1 = a(b1);
+ double a2 = a(b2);
+ auto lo = (std::max)(cumn(a1), 0);
+ auto hi = (std::min)(cumn(a2), n - 1);
+
+ return { point, resample[lo], resample[hi], confidence_level };
+ }
+
+ double outlier_variance(Estimate<double> mean, Estimate<double> stddev, int n);
+
+ struct bootstrap_analysis {
+ Estimate<double> mean;
+ Estimate<double> standard_deviation;
+ double outlier_variance;
+ };
+
+ bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last);
+ } // namespace Detail
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_stats.hpp
+#include <algorithm>
+#include <iterator>
+#include <tuple>
+#include <vector>
+#include <cmath>
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+ template <typename Clock>
+ std::vector<double> resolution(int k) {
+ std::vector<TimePoint<Clock>> times;
+ times.reserve(k + 1);
+ std::generate_n(std::back_inserter(times), k + 1, now<Clock>{});
+
+ std::vector<double> deltas;
+ deltas.reserve(k);
+ std::transform(std::next(times.begin()), times.end(), times.begin(),
+ std::back_inserter(deltas),
+ [](TimePoint<Clock> a, TimePoint<Clock> b) { return static_cast<double>((a - b).count()); });
+
+ return deltas;
+ }
+
+ const auto warmup_iterations = 10000;
+ const auto warmup_time = std::chrono::milliseconds(100);
+ const auto minimum_ticks = 1000;
+ const auto warmup_seed = 10000;
+ const auto clock_resolution_estimation_time = std::chrono::milliseconds(500);
+ const auto clock_cost_estimation_time_limit = std::chrono::seconds(1);
+ const auto clock_cost_estimation_tick_limit = 100000;
+ const auto clock_cost_estimation_time = std::chrono::milliseconds(10);
+ const auto clock_cost_estimation_iterations = 10000;
+
+ template <typename Clock>
+ int warmup() {
+ return run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_seed, &resolution<Clock>)
+ .iterations;
+ }
+ template <typename Clock>
+ EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_resolution(int iterations) {
+ auto r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_resolution_estimation_time), iterations, &resolution<Clock>)
+ .result;
+ return {
+ FloatDuration<Clock>(mean(r.begin(), r.end())),
+ classify_outliers(r.begin(), r.end()),
+ };
+ }
+ template <typename Clock>
+ EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_cost(FloatDuration<Clock> resolution) {
+ auto time_limit = (std::min)(
+ resolution * clock_cost_estimation_tick_limit,
+ FloatDuration<Clock>(clock_cost_estimation_time_limit));
+ auto time_clock = [](int k) {
+ return Detail::measure<Clock>([k] {
+ for (int i = 0; i < k; ++i) {
+ volatile auto ignored = Clock::now();
+ (void)ignored;
+ }
+ }).elapsed;
+ };
+ time_clock(1);
+ int iters = clock_cost_estimation_iterations;
+ auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock);
+ std::vector<double> times;
+ int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed));
+ times.reserve(nsamples);
+ std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] {
+ return static_cast<double>((time_clock(r.iterations) / r.iterations).count());
+ });
+ return {
+ FloatDuration<Clock>(mean(times.begin(), times.end())),
+ classify_outliers(times.begin(), times.end()),
+ };
+ }
+
+ template <typename Clock>
+ Environment<FloatDuration<Clock>> measure_environment() {
+ static Environment<FloatDuration<Clock>>* env = nullptr;
+ if (env) {
+ return *env;
+ }
+
+ auto iters = Detail::warmup<Clock>();
+ auto resolution = Detail::estimate_clock_resolution<Clock>(iters);
+ auto cost = Detail::estimate_clock_cost<Clock>(resolution.mean);
+
+ env = new Environment<FloatDuration<Clock>>{ resolution, cost };
+ return *env;
+ }
+ } // namespace Detail
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_estimate_clock.hpp
+// start catch_analyse.hpp
+
+ // Run and analyse one benchmark
+
+
+// start catch_sample_analysis.hpp
+
+// Benchmark results
+
+
+#include <algorithm>
+#include <vector>
+#include <string>
+#include <iterator>
+
+namespace Catch {
+ namespace Benchmark {
+ template <typename Duration>
+ struct SampleAnalysis {
+ std::vector<Duration> samples;
+ Estimate<Duration> mean;
+ Estimate<Duration> standard_deviation;
+ OutlierClassification outliers;
+ double outlier_variance;
+
+ template <typename Duration2>
+ operator SampleAnalysis<Duration2>() const {
+ std::vector<Duration2> samples2;
+ samples2.reserve(samples.size());
+ std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); });
+ return {
+ std::move(samples2),
+ mean,
+ standard_deviation,
+ outliers,
+ outlier_variance,
+ };
+ }
+ };
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_sample_analysis.hpp
+#include <algorithm>
+#include <iterator>
+#include <vector>
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+ template <typename Duration, typename Iterator>
+ SampleAnalysis<Duration> analyse(const IConfig &cfg, Environment<Duration>, Iterator first, Iterator last) {
+ if (!cfg.benchmarkNoAnalysis()) {
+ std::vector<double> samples;
+ samples.reserve(last - first);
+ std::transform(first, last, std::back_inserter(samples), [](Duration d) { return d.count(); });
+
+ auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end());
+ auto outliers = Catch::Benchmark::Detail::classify_outliers(samples.begin(), samples.end());
+
+ auto wrap_estimate = [](Estimate<double> e) {
+ return Estimate<Duration> {
+ Duration(e.point),
+ Duration(e.lower_bound),
+ Duration(e.upper_bound),
+ e.confidence_interval,
+ };
+ };
+ std::vector<Duration> samples2;
+ samples2.reserve(samples.size());
+ std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](double d) { return Duration(d); });
+ return {
+ std::move(samples2),
+ wrap_estimate(analysis.mean),
+ wrap_estimate(analysis.standard_deviation),
+ outliers,
+ analysis.outlier_variance,
+ };
+ } else {
+ std::vector<Duration> samples;
+ samples.reserve(last - first);
+
+ Duration mean = Duration(0);
+ int i = 0;
+ for (auto it = first; it < last; ++it, ++i) {
+ samples.push_back(Duration(*it));
+ mean += Duration(*it);
+ }
+ mean /= i;
+
+ return {
+ std::move(samples),
+ Estimate<Duration>{mean, mean, mean, 0.0},
+ Estimate<Duration>{Duration(0), Duration(0), Duration(0), 0.0},
+ OutlierClassification{},
+ 0.0
+ };
+ }
+ }
+ } // namespace Detail
+ } // namespace Benchmark
+} // namespace Catch
+
+// end catch_analyse.hpp
+#include <algorithm>
+#include <functional>
+#include <string>
+#include <vector>
+#include <cmath>
+
+namespace Catch {
+ namespace Benchmark {
+ struct Benchmark {
+ Benchmark(std::string &&name)
+ : name(std::move(name)) {}
+
+ template <class FUN>
+ Benchmark(std::string &&name, FUN &&func)
+ : fun(std::move(func)), name(std::move(name)) {}
+
+ template <typename Clock>
+ ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const {
+ auto min_time = env.clock_resolution.mean * Detail::minimum_ticks;
+ auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(cfg.benchmarkWarmupTime()));
+ auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(run_time), 1, fun);
+ int new_iters = static_cast<int>(std::ceil(min_time * test.iterations / test.elapsed));
+ return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast<FloatDuration<Clock>>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations };
+ }
+
+ template <typename Clock = default_clock>
+ void run() {
+ IConfigPtr cfg = getCurrentContext().getConfig();
+
+ auto env = Detail::measure_environment<Clock>();
+
+ getResultCapture().benchmarkPreparing(name);
+ CATCH_TRY{
+ auto plan = user_code([&] {
+ return prepare<Clock>(*cfg, env);
+ });
+
+ BenchmarkInfo info {
+ name,
+ plan.estimated_duration.count(),
+ plan.iterations_per_sample,
+ cfg->benchmarkSamples(),
+ cfg->benchmarkResamples(),
+ env.clock_resolution.mean.count(),
+ env.clock_cost.mean.count()
+ };
+
+ getResultCapture().benchmarkStarting(info);
+
+ auto samples = user_code([&] {
+ return plan.template run<Clock>(*cfg, env);
+ });
+
+ auto analysis = Detail::analyse(*cfg, env, samples.begin(), samples.end());
+ BenchmarkStats<FloatDuration<Clock>> stats{ info, analysis.samples, analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance };
+ getResultCapture().benchmarkEnded(stats);
+
+ } CATCH_CATCH_ALL{
+ if (translateActiveException() != Detail::benchmarkErrorMsg) // benchmark errors have been reported, otherwise rethrow.
+ std::rethrow_exception(std::current_exception());
+ }
+ }
+
+ // sets lambda to be used in fun *and* executes benchmark!
+ template <typename Fun,
+ typename std::enable_if<!Detail::is_related<Fun, Benchmark>::value, int>::type = 0>
+ Benchmark & operator=(Fun func) {
+ fun = Detail::BenchmarkFunction(func);
+ run();
+ return *this;
+ }
+
+ explicit operator bool() {
+ return true;
+ }
+
+ private:
+ Detail::BenchmarkFunction fun;
+ std::string name;
+ };
+ }
+} // namespace Catch
+
+#define INTERNAL_CATCH_GET_1_ARG(arg1, arg2, ...) arg1
+#define INTERNAL_CATCH_GET_2_ARG(arg1, arg2, ...) arg2
+
+#define INTERNAL_CATCH_BENCHMARK(BenchmarkName, name, benchmarkIndex)\
+ if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \
+ BenchmarkName = [&](int benchmarkIndex)
+
+#define INTERNAL_CATCH_BENCHMARK_ADVANCED(BenchmarkName, name)\
+ if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \
+ BenchmarkName = [&]
+
+// end catch_benchmark.hpp
+// start catch_constructor.hpp
+
+// Constructor and destructor helpers
+
+
+#include <type_traits>
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+ template <typename T, bool Destruct>
+ struct ObjectStorage
+ {
+ using TStorage = typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type;
+
+ ObjectStorage() : data() {}
+
+ ObjectStorage(const ObjectStorage& other)
+ {
+ new(&data) T(other.stored_object());
+ }
+
+ ObjectStorage(ObjectStorage&& other)
+ {
+ new(&data) T(std::move(other.stored_object()));
+ }
+
+ ~ObjectStorage() { destruct_on_exit<T>(); }
+
+ template <typename... Args>
+ void construct(Args&&... args)
+ {
+ new (&data) T(std::forward<Args>(args)...);
+ }
+
+ template <bool AllowManualDestruction = !Destruct>
+ typename std::enable_if<AllowManualDestruction>::type destruct()
+ {
+ stored_object().~T();
+ }
+
+ private:
+ // If this is a constructor benchmark, destruct the underlying object
+ template <typename U>
+ void destruct_on_exit(typename std::enable_if<Destruct, U>::type* = 0) { destruct<true>(); }
+ // Otherwise, don't
+ template <typename U>
+ void destruct_on_exit(typename std::enable_if<!Destruct, U>::type* = 0) { }
+
+ T& stored_object() {
+ return *static_cast<T*>(static_cast<void*>(&data));
+ }
+
+ T const& stored_object() const {
+ return *static_cast<T*>(static_cast<void*>(&data));
+ }
+
+ TStorage data;
+ };
+ }
+
+ template <typename T>
+ using storage_for = Detail::ObjectStorage<T, true>;
+
+ template <typename T>
+ using destructable_object = Detail::ObjectStorage<T, false>;
+ }
+}
+
+// end catch_constructor.hpp
+// end catch_benchmarking_all.hpp
+#endif
+
+#endif // ! CATCH_CONFIG_IMPL_ONLY
+
+#ifdef CATCH_IMPL
+// start catch_impl.hpp
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wweak-vtables"
+#endif
+
+// Keep these here for external reporters
+// start catch_test_case_tracker.h
+
+#include <string>
+#include <vector>
+#include <memory>
+
+namespace Catch {
+namespace TestCaseTracking {
+
+ struct NameAndLocation {
+ std::string name;
+ SourceLineInfo location;
+
+ NameAndLocation( std::string const& _name, SourceLineInfo const& _location );
+ friend bool operator==(NameAndLocation const& lhs, NameAndLocation const& rhs) {
+ return lhs.name == rhs.name
+ && lhs.location == rhs.location;
+ }
+ };
+
+ class ITracker;
+
+ using ITrackerPtr = std::shared_ptr<ITracker>;
+
+ class ITracker {
+ NameAndLocation m_nameAndLocation;
+
+ public:
+ ITracker(NameAndLocation const& nameAndLoc) :
+ m_nameAndLocation(nameAndLoc)
+ {}
+
+ // static queries
+ NameAndLocation const& nameAndLocation() const {
+ return m_nameAndLocation;
+ }
+
+ virtual ~ITracker();
+
+ // dynamic queries
+ virtual bool isComplete() const = 0; // Successfully completed or failed
+ virtual bool isSuccessfullyCompleted() const = 0;
+ virtual bool isOpen() const = 0; // Started but not complete
+ virtual bool hasChildren() const = 0;
+ virtual bool hasStarted() const = 0;
+
+ virtual ITracker& parent() = 0;
+
+ // actions
+ virtual void close() = 0; // Successfully complete
+ virtual void fail() = 0;
+ virtual void markAsNeedingAnotherRun() = 0;
+
+ virtual void addChild( ITrackerPtr const& child ) = 0;
+ virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0;
+ virtual void openChild() = 0;
+
+ // Debug/ checking
+ virtual bool isSectionTracker() const = 0;
+ virtual bool isGeneratorTracker() const = 0;
+ };
+
+ class TrackerContext {
+
+ enum RunState {
+ NotStarted,
+ Executing,
+ CompletedCycle
+ };
+
+ ITrackerPtr m_rootTracker;
+ ITracker* m_currentTracker = nullptr;
+ RunState m_runState = NotStarted;
+
+ public:
+
+ ITracker& startRun();
+ void endRun();
+
+ void startCycle();
+ void completeCycle();
+
+ bool completedCycle() const;
+ ITracker& currentTracker();
+ void setCurrentTracker( ITracker* tracker );
+ };
+
+ class TrackerBase : public ITracker {
+ protected:
+ enum CycleState {
+ NotStarted,
+ Executing,
+ ExecutingChildren,
+ NeedsAnotherRun,
+ CompletedSuccessfully,
+ Failed
+ };
+
+ using Children = std::vector<ITrackerPtr>;
+ TrackerContext& m_ctx;
+ ITracker* m_parent;
+ Children m_children;
+ CycleState m_runState = NotStarted;
+
+ public:
+ TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
+
+ bool isComplete() const override;
+ bool isSuccessfullyCompleted() const override;
+ bool isOpen() const override;
+ bool hasChildren() const override;
+ bool hasStarted() const override {
+ return m_runState != NotStarted;
+ }
+
+ void addChild( ITrackerPtr const& child ) override;
+
+ ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override;
+ ITracker& parent() override;
+
+ void openChild() override;
+
+ bool isSectionTracker() const override;
+ bool isGeneratorTracker() const override;
+
+ void open();
+
+ void close() override;
+ void fail() override;
+ void markAsNeedingAnotherRun() override;
+
+ private:
+ void moveToParent();
+ void moveToThis();
+ };
+
+ class SectionTracker : public TrackerBase {
+ std::vector<std::string> m_filters;
+ std::string m_trimmed_name;
+ public:
+ SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
+
+ bool isSectionTracker() const override;
+
+ bool isComplete() const override;
+
+ static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation );
+
+ void tryOpen();
+
+ void addInitialFilters( std::vector<std::string> const& filters );
+ void addNextFilters( std::vector<std::string> const& filters );
+ //! Returns filters active in this tracker
+ std::vector<std::string> const& getFilters() const;
+ //! Returns whitespace-trimmed name of the tracked section
+ std::string const& trimmedName() const;
+ };
+
+} // namespace TestCaseTracking
+
+using TestCaseTracking::ITracker;
+using TestCaseTracking::TrackerContext;
+using TestCaseTracking::SectionTracker;
+
+} // namespace Catch
+
+// end catch_test_case_tracker.h
+
+// start catch_leak_detector.h
+
+namespace Catch {
+
+ struct LeakDetector {
+ LeakDetector();
+ ~LeakDetector();
+ };
+
+}
+// end catch_leak_detector.h
+// Cpp files will be included in the single-header file here
+// start catch_stats.cpp
+
+// Statistical analysis tools
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+
+#include <cassert>
+#include <random>
+
+#if defined(CATCH_CONFIG_USE_ASYNC)
+#include <future>
+#endif
+
+namespace {
+ double erf_inv(double x) {
+ // Code accompanying the article "Approximating the erfinv function" in GPU Computing Gems, Volume 2
+ double w, p;
+
+ w = -log((1.0 - x) * (1.0 + x));
+
+ if (w < 6.250000) {
+ w = w - 3.125000;
+ p = -3.6444120640178196996e-21;
+ p = -1.685059138182016589e-19 + p * w;
+ p = 1.2858480715256400167e-18 + p * w;
+ p = 1.115787767802518096e-17 + p * w;
+ p = -1.333171662854620906e-16 + p * w;
+ p = 2.0972767875968561637e-17 + p * w;
+ p = 6.6376381343583238325e-15 + p * w;
+ p = -4.0545662729752068639e-14 + p * w;
+ p = -8.1519341976054721522e-14 + p * w;
+ p = 2.6335093153082322977e-12 + p * w;
+ p = -1.2975133253453532498e-11 + p * w;
+ p = -5.4154120542946279317e-11 + p * w;
+ p = 1.051212273321532285e-09 + p * w;
+ p = -4.1126339803469836976e-09 + p * w;
+ p = -2.9070369957882005086e-08 + p * w;
+ p = 4.2347877827932403518e-07 + p * w;
+ p = -1.3654692000834678645e-06 + p * w;
+ p = -1.3882523362786468719e-05 + p * w;
+ p = 0.0001867342080340571352 + p * w;
+ p = -0.00074070253416626697512 + p * w;
+ p = -0.0060336708714301490533 + p * w;
+ p = 0.24015818242558961693 + p * w;
+ p = 1.6536545626831027356 + p * w;
+ } else if (w < 16.000000) {
+ w = sqrt(w) - 3.250000;
+ p = 2.2137376921775787049e-09;
+ p = 9.0756561938885390979e-08 + p * w;
+ p = -2.7517406297064545428e-07 + p * w;
+ p = 1.8239629214389227755e-08 + p * w;
+ p = 1.5027403968909827627e-06 + p * w;
+ p = -4.013867526981545969e-06 + p * w;
+ p = 2.9234449089955446044e-06 + p * w;
+ p = 1.2475304481671778723e-05 + p * w;
+ p = -4.7318229009055733981e-05 + p * w;
+ p = 6.8284851459573175448e-05 + p * w;
+ p = 2.4031110387097893999e-05 + p * w;
+ p = -0.0003550375203628474796 + p * w;
+ p = 0.00095328937973738049703 + p * w;
+ p = -0.0016882755560235047313 + p * w;
+ p = 0.0024914420961078508066 + p * w;
+ p = -0.0037512085075692412107 + p * w;
+ p = 0.005370914553590063617 + p * w;
+ p = 1.0052589676941592334 + p * w;
+ p = 3.0838856104922207635 + p * w;
+ } else {
+ w = sqrt(w) - 5.000000;
+ p = -2.7109920616438573243e-11;
+ p = -2.5556418169965252055e-10 + p * w;
+ p = 1.5076572693500548083e-09 + p * w;
+ p = -3.7894654401267369937e-09 + p * w;
+ p = 7.6157012080783393804e-09 + p * w;
+ p = -1.4960026627149240478e-08 + p * w;
+ p = 2.9147953450901080826e-08 + p * w;
+ p = -6.7711997758452339498e-08 + p * w;
+ p = 2.2900482228026654717e-07 + p * w;
+ p = -9.9298272942317002539e-07 + p * w;
+ p = 4.5260625972231537039e-06 + p * w;
+ p = -1.9681778105531670567e-05 + p * w;
+ p = 7.5995277030017761139e-05 + p * w;
+ p = -0.00021503011930044477347 + p * w;
+ p = -0.00013871931833623122026 + p * w;
+ p = 1.0103004648645343977 + p * w;
+ p = 4.8499064014085844221 + p * w;
+ }
+ return p * x;
+ }
+
+ double standard_deviation(std::vector<double>::iterator first, std::vector<double>::iterator last) {
+ auto m = Catch::Benchmark::Detail::mean(first, last);
+ double variance = std::accumulate(first, last, 0., [m](double a, double b) {
+ double diff = b - m;
+ return a + diff * diff;
+ }) / (last - first);
+ return std::sqrt(variance);
+ }
+
+}
+
+namespace Catch {
+ namespace Benchmark {
+ namespace Detail {
+
+ double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last) {
+ auto count = last - first;
+ double idx = (count - 1) * k / static_cast<double>(q);
+ int j = static_cast<int>(idx);
+ double g = idx - j;
+ std::nth_element(first, first + j, last);
+ auto xj = first[j];
+ if (g == 0) return xj;
+
+ auto xj1 = *std::min_element(first + (j + 1), last);
+ return xj + g * (xj1 - xj);
+ }
+
+ double erfc_inv(double x) {
+ return erf_inv(1.0 - x);
+ }
+
+ double normal_quantile(double p) {
+ static const double ROOT_TWO = std::sqrt(2.0);
+
+ double result = 0.0;
+ assert(p >= 0 && p <= 1);
+ if (p < 0 || p > 1) {
+ return result;
+ }
+
+ result = -erfc_inv(2.0 * p);
+ // result *= normal distribution standard deviation (1.0) * sqrt(2)
+ result *= /*sd * */ ROOT_TWO;
+ // result += normal disttribution mean (0)
+ return result;
+ }
+
+ double outlier_variance(Estimate<double> mean, Estimate<double> stddev, int n) {
+ double sb = stddev.point;
+ double mn = mean.point / n;
+ double mg_min = mn / 2.;
+ double sg = (std::min)(mg_min / 4., sb / std::sqrt(n));
+ double sg2 = sg * sg;
+ double sb2 = sb * sb;
+
+ auto c_max = [n, mn, sb2, sg2](double x) -> double {
+ double k = mn - x;
+ double d = k * k;
+ double nd = n * d;
+ double k0 = -n * nd;
+ double k1 = sb2 - n * sg2 + nd;
+ double det = k1 * k1 - 4 * sg2 * k0;
+ return (int)(-2. * k0 / (k1 + std::sqrt(det)));
+ };
+
+ auto var_out = [n, sb2, sg2](double c) {
+ double nc = n - c;
+ return (nc / n) * (sb2 - nc * sg2);
+ };
+
+ return (std::min)(var_out(1), var_out((std::min)(c_max(0.), c_max(mg_min)))) / sb2;
+ }
+
+ bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) {
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
+ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
+ static std::random_device entropy;
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
+
+ auto n = static_cast<int>(last - first); // seriously, one can't use integral types without hell in C++
+
+ auto mean = &Detail::mean<std::vector<double>::iterator>;
+ auto stddev = &standard_deviation;
+
+#if defined(CATCH_CONFIG_USE_ASYNC)
+ auto Estimate = [=](double(*f)(std::vector<double>::iterator, std::vector<double>::iterator)) {
+ auto seed = entropy();
+ return std::async(std::launch::async, [=] {
+ std::mt19937 rng(seed);
+ auto resampled = resample(rng, n_resamples, first, last, f);
+ return bootstrap(confidence_level, first, last, resampled, f);
+ });
+ };
+
+ auto mean_future = Estimate(mean);
+ auto stddev_future = Estimate(stddev);
+
+ auto mean_estimate = mean_future.get();
+ auto stddev_estimate = stddev_future.get();
+#else
+ auto Estimate = [=](double(*f)(std::vector<double>::iterator, std::vector<double>::iterator)) {
+ auto seed = entropy();
+ std::mt19937 rng(seed);
+ auto resampled = resample(rng, n_resamples, first, last, f);
+ return bootstrap(confidence_level, first, last, resampled, f);
+ };
+
+ auto mean_estimate = Estimate(mean);
+ auto stddev_estimate = Estimate(stddev);
+#endif // CATCH_USE_ASYNC
+
+ double outlier_variance = Detail::outlier_variance(mean_estimate, stddev_estimate, n);
+
+ return { mean_estimate, stddev_estimate, outlier_variance };
+ }
+ } // namespace Detail
+ } // namespace Benchmark
+} // namespace Catch
+
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+// end catch_stats.cpp
+// start catch_approx.cpp
+
+#include <cmath>
+#include <limits>
+
+namespace {
+
+// Performs equivalent check of std::fabs(lhs - rhs) <= margin
+// But without the subtraction to allow for INFINITY in comparison
+bool marginComparison(double lhs, double rhs, double margin) {
+ return (lhs + margin >= rhs) && (rhs + margin >= lhs);
+}
+
+}
+
+namespace Catch {
+namespace Detail {
+
+ Approx::Approx ( double value )
+ : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
+ m_margin( 0.0 ),
+ m_scale( 0.0 ),
+ m_value( value )
+ {}
+
+ Approx Approx::custom() {
+ return Approx( 0 );
+ }
+
+ Approx Approx::operator-() const {
+ auto temp(*this);
+ temp.m_value = -temp.m_value;
+ return temp;
+ }
+
+ std::string Approx::toString() const {
+ ReusableStringStream rss;
+ rss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )";
+ return rss.str();
+ }
+
+ bool Approx::equalityComparisonImpl(const double other) const {
+ // First try with fixed margin, then compute margin based on epsilon, scale and Approx's value
+ // Thanks to Richard Harris for his help refining the scaled margin value
+ return marginComparison(m_value, other, m_margin)
+ || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(std::isinf(m_value)? 0 : m_value)));
+ }
+
+ void Approx::setMargin(double newMargin) {
+ CATCH_ENFORCE(newMargin >= 0,
+ "Invalid Approx::margin: " << newMargin << '.'
+ << " Approx::Margin has to be non-negative.");
+ m_margin = newMargin;
+ }
+
+ void Approx::setEpsilon(double newEpsilon) {
+ CATCH_ENFORCE(newEpsilon >= 0 && newEpsilon <= 1.0,
+ "Invalid Approx::epsilon: " << newEpsilon << '.'
+ << " Approx::epsilon has to be in [0, 1]");
+ m_epsilon = newEpsilon;
+ }
+
+} // end namespace Detail
+
+namespace literals {
+ Detail::Approx operator "" _a(long double val) {
+ return Detail::Approx(val);
+ }
+ Detail::Approx operator "" _a(unsigned long long val) {
+ return Detail::Approx(val);
+ }
+} // end namespace literals
+
+std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) {
+ return value.toString();
+}
+
+} // end namespace Catch
+// end catch_approx.cpp
+// start catch_assertionhandler.cpp
+
+// start catch_debugger.h
+
+namespace Catch {
+ bool isDebuggerActive();
+}
+
+#ifdef CATCH_PLATFORM_MAC
+
+ #if defined(__i386__) || defined(__x86_64__)
+ #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */
+ #elif defined(__aarch64__)
+ #define CATCH_TRAP() __asm__(".inst 0xd4200000")
+ #endif
+
+#elif defined(CATCH_PLATFORM_IPHONE)
+
+ // use inline assembler
+ #if defined(__i386__) || defined(__x86_64__)
+ #define CATCH_TRAP() __asm__("int $3")
+ #elif defined(__aarch64__)
+ #define CATCH_TRAP() __asm__(".inst 0xd4200000")
+ #elif defined(__arm__) && !defined(__thumb__)
+ #define CATCH_TRAP() __asm__(".inst 0xe7f001f0")
+ #elif defined(__arm__) && defined(__thumb__)
+ #define CATCH_TRAP() __asm__(".inst 0xde01")
+ #endif
+
+#elif defined(CATCH_PLATFORM_LINUX)
+ // If we can use inline assembler, do it because this allows us to break
+ // directly at the location of the failing check instead of breaking inside
+ // raise() called from it, i.e. one stack frame below.
+ #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
+ #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */
+ #else // Fall back to the generic way.
+ #include <signal.h>
+
+ #define CATCH_TRAP() raise(SIGTRAP)
+ #endif
+#elif defined(_MSC_VER)
+ #define CATCH_TRAP() __debugbreak()
+#elif defined(__MINGW32__)
+ extern "C" __declspec(dllimport) void __stdcall DebugBreak();
+ #define CATCH_TRAP() DebugBreak()
+#endif
+
+#ifndef CATCH_BREAK_INTO_DEBUGGER
+ #ifdef CATCH_TRAP
+ #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }()
+ #else
+ #define CATCH_BREAK_INTO_DEBUGGER() []{}()
+ #endif
+#endif
+
+// end catch_debugger.h
+// start catch_run_context.h
+
+// start catch_fatal_condition.h
+
+#include <cassert>
+
+namespace Catch {
+
+ // Wrapper for platform-specific fatal error (signals/SEH) handlers
+ //
+ // Tries to be cooperative with other handlers, and not step over
+ // other handlers. This means that unknown structured exceptions
+ // are passed on, previous signal handlers are called, and so on.
+ //
+ // Can only be instantiated once, and assumes that once a signal
+ // is caught, the binary will end up terminating. Thus, there
+ class FatalConditionHandler {
+ bool m_started = false;
+
+ // Install/disengage implementation for specific platform.
+ // Should be if-defed to work on current platform, can assume
+ // engage-disengage 1:1 pairing.
+ void engage_platform();
+ void disengage_platform();
+ public:
+ // Should also have platform-specific implementations as needed
+ FatalConditionHandler();
+ ~FatalConditionHandler();
+
+ void engage() {
+ assert(!m_started && "Handler cannot be installed twice.");
+ m_started = true;
+ engage_platform();
+ }
+
+ void disengage() {
+ assert(m_started && "Handler cannot be uninstalled without being installed first");
+ m_started = false;
+ disengage_platform();
+ }
+ };
+
+ //! Simple RAII guard for (dis)engaging the FatalConditionHandler
+ class FatalConditionHandlerGuard {
+ FatalConditionHandler* m_handler;
+ public:
+ FatalConditionHandlerGuard(FatalConditionHandler* handler):
+ m_handler(handler) {
+ m_handler->engage();
+ }
+ ~FatalConditionHandlerGuard() {
+ m_handler->disengage();
+ }
+ };
+
+} // end namespace Catch
+
+// end catch_fatal_condition.h
+#include <string>
+
+namespace Catch {
+
+ struct IMutableContext;
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ class RunContext : public IResultCapture, public IRunner {
+
+ public:
+ RunContext( RunContext const& ) = delete;
+ RunContext& operator =( RunContext const& ) = delete;
+
+ explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr&& reporter );
+
+ ~RunContext() override;
+
+ void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount );
+ void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount );
+
+ Totals runTest(TestCase const& testCase);
+
+ IConfigPtr config() const;
+ IStreamingReporter& reporter() const;
+
+ public: // IResultCapture
+
+ // Assertion handlers
+ void handleExpr
+ ( AssertionInfo const& info,
+ ITransientExpression const& expr,
+ AssertionReaction& reaction ) override;
+ void handleMessage
+ ( AssertionInfo const& info,
+ ResultWas::OfType resultType,
+ StringRef const& message,
+ AssertionReaction& reaction ) override;
+ void handleUnexpectedExceptionNotThrown
+ ( AssertionInfo const& info,
+ AssertionReaction& reaction ) override;
+ void handleUnexpectedInflightException
+ ( AssertionInfo const& info,
+ std::string const& message,
+ AssertionReaction& reaction ) override;
+ void handleIncomplete
+ ( AssertionInfo const& info ) override;
+ void handleNonExpr
+ ( AssertionInfo const &info,
+ ResultWas::OfType resultType,
+ AssertionReaction &reaction ) override;
+
+ bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override;
+
+ void sectionEnded( SectionEndInfo const& endInfo ) override;
+ void sectionEndedEarly( SectionEndInfo const& endInfo ) override;
+
+ auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override;
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ void benchmarkPreparing( std::string const& name ) override;
+ void benchmarkStarting( BenchmarkInfo const& info ) override;
+ void benchmarkEnded( BenchmarkStats<> const& stats ) override;
+ void benchmarkFailed( std::string const& error ) override;
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ void pushScopedMessage( MessageInfo const& message ) override;
+ void popScopedMessage( MessageInfo const& message ) override;
+
+ void emplaceUnscopedMessage( MessageBuilder const& builder ) override;
+
+ std::string getCurrentTestName() const override;
+
+ const AssertionResult* getLastResult() const override;
+
+ void exceptionEarlyReported() override;
+
+ void handleFatalErrorCondition( StringRef message ) override;
+
+ bool lastAssertionPassed() override;
+
+ void assertionPassed() override;
+
+ public:
+ // !TBD We need to do this another way!
+ bool aborting() const final;
+
+ private:
+
+ void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr );
+ void invokeActiveTestCase();
+
+ void resetAssertionInfo();
+ bool testForMissingAssertions( Counts& assertions );
+
+ void assertionEnded( AssertionResult const& result );
+ void reportExpr
+ ( AssertionInfo const &info,
+ ResultWas::OfType resultType,
+ ITransientExpression const *expr,
+ bool negated );
+
+ void populateReaction( AssertionReaction& reaction );
+
+ private:
+
+ void handleUnfinishedSections();
+
+ TestRunInfo m_runInfo;
+ IMutableContext& m_context;
+ TestCase const* m_activeTestCase = nullptr;
+ ITracker* m_testCaseTracker = nullptr;
+ Option<AssertionResult> m_lastResult;
+
+ IConfigPtr m_config;
+ Totals m_totals;
+ IStreamingReporterPtr m_reporter;
+ std::vector<MessageInfo> m_messages;
+ std::vector<ScopedMessage> m_messageScopes; /* Keeps owners of so-called unscoped messages. */
+ AssertionInfo m_lastAssertionInfo;
+ std::vector<SectionEndInfo> m_unfinishedSections;
+ std::vector<ITracker*> m_activeSections;
+ TrackerContext m_trackerContext;
+ FatalConditionHandler m_fatalConditionhandler;
+ bool m_lastAssertionPassed = false;
+ bool m_shouldReportUnexpected = true;
+ bool m_includeSuccessfulResults;
+ };
+
+ void seedRng(IConfig const& config);
+ unsigned int rngSeed();
+} // end namespace Catch
+
+// end catch_run_context.h
+namespace Catch {
+
+ namespace {
+ auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
+ expr.streamReconstructedExpression( os );
+ return os;
+ }
+ }
+
+ LazyExpression::LazyExpression( bool isNegated )
+ : m_isNegated( isNegated )
+ {}
+
+ LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {}
+
+ LazyExpression::operator bool() const {
+ return m_transientExpression != nullptr;
+ }
+
+ auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& {
+ if( lazyExpr.m_isNegated )
+ os << "!";
+
+ if( lazyExpr ) {
+ if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() )
+ os << "(" << *lazyExpr.m_transientExpression << ")";
+ else
+ os << *lazyExpr.m_transientExpression;
+ }
+ else {
+ os << "{** error - unchecked empty expression requested **}";
+ }
+ return os;
+ }
+
+ AssertionHandler::AssertionHandler
+ ( StringRef const& macroName,
+ SourceLineInfo const& lineInfo,
+ StringRef capturedExpression,
+ ResultDisposition::Flags resultDisposition )
+ : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition },
+ m_resultCapture( getResultCapture() )
+ {}
+
+ void AssertionHandler::handleExpr( ITransientExpression const& expr ) {
+ m_resultCapture.handleExpr( m_assertionInfo, expr, m_reaction );
+ }
+ void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef const& message) {
+ m_resultCapture.handleMessage( m_assertionInfo, resultType, message, m_reaction );
+ }
+
+ auto AssertionHandler::allowThrows() const -> bool {
+ return getCurrentContext().getConfig()->allowThrows();
+ }
+
+ void AssertionHandler::complete() {
+ setCompleted();
+ if( m_reaction.shouldDebugBreak ) {
+
+ // If you find your debugger stopping you here then go one level up on the
+ // call-stack for the code that caused it (typically a failed assertion)
+
+ // (To go back to the test and change execution, jump over the throw, next)
+ CATCH_BREAK_INTO_DEBUGGER();
+ }
+ if (m_reaction.shouldThrow) {
+#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+ throw Catch::TestFailureException();
+#else
+ CATCH_ERROR( "Test failure requires aborting test!" );
+#endif
+ }
+ }
+ void AssertionHandler::setCompleted() {
+ m_completed = true;
+ }
+
+ void AssertionHandler::handleUnexpectedInflightException() {
+ m_resultCapture.handleUnexpectedInflightException( m_assertionInfo, Catch::translateActiveException(), m_reaction );
+ }
+
+ void AssertionHandler::handleExceptionThrownAsExpected() {
+ m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
+ }
+ void AssertionHandler::handleExceptionNotThrownAsExpected() {
+ m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
+ }
+
+ void AssertionHandler::handleUnexpectedExceptionNotThrown() {
+ m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction );
+ }
+
+ void AssertionHandler::handleThrowingCallSkipped() {
+ m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
+ }
+
+ // This is the overload that takes a string and infers the Equals matcher from it
+ // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp
+ void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString ) {
+ handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString );
+ }
+
+} // namespace Catch
+// end catch_assertionhandler.cpp
+// start catch_assertionresult.cpp
+
+namespace Catch {
+ AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression):
+ lazyExpression(_lazyExpression),
+ resultType(_resultType) {}
+
+ std::string AssertionResultData::reconstructExpression() const {
+
+ if( reconstructedExpression.empty() ) {
+ if( lazyExpression ) {
+ ReusableStringStream rss;
+ rss << lazyExpression;
+ reconstructedExpression = rss.str();
+ }
+ }
+ return reconstructedExpression;
+ }
+
+ AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data )
+ : m_info( info ),
+ m_resultData( data )
+ {}
+
+ // Result was a success
+ bool AssertionResult::succeeded() const {
+ return Catch::isOk( m_resultData.resultType );
+ }
+
+ // Result was a success, or failure is suppressed
+ bool AssertionResult::isOk() const {
+ return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
+ }
+
+ ResultWas::OfType AssertionResult::getResultType() const {
+ return m_resultData.resultType;
+ }
+
+ bool AssertionResult::hasExpression() const {
+ return !m_info.capturedExpression.empty();
+ }
+
+ bool AssertionResult::hasMessage() const {
+ return !m_resultData.message.empty();
+ }
+
+ std::string AssertionResult::getExpression() const {
+ // Possibly overallocating by 3 characters should be basically free
+ std::string expr; expr.reserve(m_info.capturedExpression.size() + 3);
+ if (isFalseTest(m_info.resultDisposition)) {
+ expr += "!(";
+ }
+ expr += m_info.capturedExpression;
+ if (isFalseTest(m_info.resultDisposition)) {
+ expr += ')';
+ }
+ return expr;
+ }
+
+ std::string AssertionResult::getExpressionInMacro() const {
+ std::string expr;
+ if( m_info.macroName.empty() )
+ expr = static_cast<std::string>(m_info.capturedExpression);
+ else {
+ expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 );
+ expr += m_info.macroName;
+ expr += "( ";
+ expr += m_info.capturedExpression;
+ expr += " )";
+ }
+ return expr;
+ }
+
+ bool AssertionResult::hasExpandedExpression() const {
+ return hasExpression() && getExpandedExpression() != getExpression();
+ }
+
+ std::string AssertionResult::getExpandedExpression() const {
+ std::string expr = m_resultData.reconstructExpression();
+ return expr.empty()
+ ? getExpression()
+ : expr;
+ }
+
+ std::string AssertionResult::getMessage() const {
+ return m_resultData.message;
+ }
+ SourceLineInfo AssertionResult::getSourceInfo() const {
+ return m_info.lineInfo;
+ }
+
+ StringRef AssertionResult::getTestMacroName() const {
+ return m_info.macroName;
+ }
+
+} // end namespace Catch
+// end catch_assertionresult.cpp
+// start catch_capture_matchers.cpp
+
+namespace Catch {
+
+ using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
+
+ // This is the general overload that takes a any string matcher
+ // There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers
+ // the Equals matcher (so the header does not mention matchers)
+ void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ) {
+ std::string exceptionMessage = Catch::translateActiveException();
+ MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
+ handler.handleExpr( expr );
+ }
+
+} // namespace Catch
+// end catch_capture_matchers.cpp
+// start catch_commandline.cpp
+
+// start catch_commandline.h
+
+// start catch_clara.h
+
+// Use Catch's value for console width (store Clara's off to the side, if present)
+#ifdef CLARA_CONFIG_CONSOLE_WIDTH
+#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
+#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
+#endif
+#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wweak-vtables"
+#pragma clang diagnostic ignored "-Wexit-time-destructors"
+#pragma clang diagnostic ignored "-Wshadow"
+#endif
+
+// start clara.hpp
+// Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See https://github.com/philsquared/Clara for more details
+
+// Clara v1.1.5
+
+
+#ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH
+#define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80
+#endif
+
+#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
+#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH
+#endif
+
+#ifndef CLARA_CONFIG_OPTIONAL_TYPE
+#ifdef __has_include
+#if __has_include(<optional>) && __cplusplus >= 201703L
+#include <optional>
+#define CLARA_CONFIG_OPTIONAL_TYPE std::optional
+#endif
+#endif
+#endif
+
+// ----------- #included from clara_textflow.hpp -----------
+
+// TextFlowCpp
+//
+// A single-header library for wrapping and laying out basic text, by Phil Nash
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// This project is hosted at https://github.com/philsquared/textflowcpp
+
+
+#include <cassert>
+#include <ostream>
+#include <sstream>
+#include <vector>
+
+#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
+#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80
+#endif
+
+namespace Catch {
+namespace clara {
+namespace TextFlow {
+
+inline auto isWhitespace(char c) -> bool {
+ static std::string chars = " \t\n\r";
+ return chars.find(c) != std::string::npos;
+}
+inline auto isBreakableBefore(char c) -> bool {
+ static std::string chars = "[({<|";
+ return chars.find(c) != std::string::npos;
+}
+inline auto isBreakableAfter(char c) -> bool {
+ static std::string chars = "])}>.,:;*+-=&/\\";
+ return chars.find(c) != std::string::npos;
+}
+
+class Columns;
+
+class Column {
+ std::vector<std::string> m_strings;
+ size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH;
+ size_t m_indent = 0;
+ size_t m_initialIndent = std::string::npos;
+
+public:
+ class iterator {
+ friend Column;
+
+ Column const& m_column;
+ size_t m_stringIndex = 0;
+ size_t m_pos = 0;
+
+ size_t m_len = 0;
+ size_t m_end = 0;
+ bool m_suffix = false;
+
+ iterator(Column const& column, size_t stringIndex)
+ : m_column(column),
+ m_stringIndex(stringIndex) {}
+
+ auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; }
+
+ auto isBoundary(size_t at) const -> bool {
+ assert(at > 0);
+ assert(at <= line().size());
+
+ return at == line().size() ||
+ (isWhitespace(line()[at]) && !isWhitespace(line()[at - 1])) ||
+ isBreakableBefore(line()[at]) ||
+ isBreakableAfter(line()[at - 1]);
+ }
+
+ void calcLength() {
+ assert(m_stringIndex < m_column.m_strings.size());
+
+ m_suffix = false;
+ auto width = m_column.m_width - indent();
+ m_end = m_pos;
+ if (line()[m_pos] == '\n') {
+ ++m_end;
+ }
+ while (m_end < line().size() && line()[m_end] != '\n')
+ ++m_end;
+
+ if (m_end < m_pos + width) {
+ m_len = m_end - m_pos;
+ } else {
+ size_t len = width;
+ while (len > 0 && !isBoundary(m_pos + len))
+ --len;
+ while (len > 0 && isWhitespace(line()[m_pos + len - 1]))
+ --len;
+
+ if (len > 0) {
+ m_len = len;
+ } else {
+ m_suffix = true;
+ m_len = width - 1;
+ }
+ }
+ }
+
+ auto indent() const -> size_t {
+ auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos;
+ return initial == std::string::npos ? m_column.m_indent : initial;
+ }
+
+ auto addIndentAndSuffix(std::string const &plain) const -> std::string {
+ return std::string(indent(), ' ') + (m_suffix ? plain + "-" : plain);
+ }
+
+ public:
+ using difference_type = std::ptrdiff_t;
+ using value_type = std::string;
+ using pointer = value_type * ;
+ using reference = value_type & ;
+ using iterator_category = std::forward_iterator_tag;
+
+ explicit iterator(Column const& column) : m_column(column) {
+ assert(m_column.m_width > m_column.m_indent);
+ assert(m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent);
+ calcLength();
+ if (m_len == 0)
+ m_stringIndex++; // Empty string
+ }
+
+ auto operator *() const -> std::string {
+ assert(m_stringIndex < m_column.m_strings.size());
+ assert(m_pos <= m_end);
+ return addIndentAndSuffix(line().substr(m_pos, m_len));
+ }
+
+ auto operator ++() -> iterator& {
+ m_pos += m_len;
+ if (m_pos < line().size() && line()[m_pos] == '\n')
+ m_pos += 1;
+ else
+ while (m_pos < line().size() && isWhitespace(line()[m_pos]))
+ ++m_pos;
+
+ if (m_pos == line().size()) {
+ m_pos = 0;
+ ++m_stringIndex;
+ }
+ if (m_stringIndex < m_column.m_strings.size())
+ calcLength();
+ return *this;
+ }
+ auto operator ++(int) -> iterator {
+ iterator prev(*this);
+ operator++();
+ return prev;
+ }
+
+ auto operator ==(iterator const& other) const -> bool {
+ return
+ m_pos == other.m_pos &&
+ m_stringIndex == other.m_stringIndex &&
+ &m_column == &other.m_column;
+ }
+ auto operator !=(iterator const& other) const -> bool {
+ return !operator==(other);
+ }
+ };
+ using const_iterator = iterator;
+
+ explicit Column(std::string const& text) { m_strings.push_back(text); }
+
+ auto width(size_t newWidth) -> Column& {
+ assert(newWidth > 0);
+ m_width = newWidth;
+ return *this;
+ }
+ auto indent(size_t newIndent) -> Column& {
+ m_indent = newIndent;
+ return *this;
+ }
+ auto initialIndent(size_t newIndent) -> Column& {
+ m_initialIndent = newIndent;
+ return *this;
+ }
+
+ auto width() const -> size_t { return m_width; }
+ auto begin() const -> iterator { return iterator(*this); }
+ auto end() const -> iterator { return { *this, m_strings.size() }; }
+
+ inline friend std::ostream& operator << (std::ostream& os, Column const& col) {
+ bool first = true;
+ for (auto line : col) {
+ if (first)
+ first = false;
+ else
+ os << "\n";
+ os << line;
+ }
+ return os;
+ }
+
+ auto operator + (Column const& other)->Columns;
+
+ auto toString() const -> std::string {
+ std::ostringstream oss;
+ oss << *this;
+ return oss.str();
+ }
+};
+
+class Spacer : public Column {
+
+public:
+ explicit Spacer(size_t spaceWidth) : Column("") {
+ width(spaceWidth);
+ }
+};
+
+class Columns {
+ std::vector<Column> m_columns;
+
+public:
+
+ class iterator {
+ friend Columns;
+ struct EndTag {};
+
+ std::vector<Column> const& m_columns;
+ std::vector<Column::iterator> m_iterators;
+ size_t m_activeIterators;
+
+ iterator(Columns const& columns, EndTag)
+ : m_columns(columns.m_columns),
+ m_activeIterators(0) {
+ m_iterators.reserve(m_columns.size());
+
+ for (auto const& col : m_columns)
+ m_iterators.push_back(col.end());
+ }
+
+ public:
+ using difference_type = std::ptrdiff_t;
+ using value_type = std::string;
+ using pointer = value_type * ;
+ using reference = value_type & ;
+ using iterator_category = std::forward_iterator_tag;
+
+ explicit iterator(Columns const& columns)
+ : m_columns(columns.m_columns),
+ m_activeIterators(m_columns.size()) {
+ m_iterators.reserve(m_columns.size());
+
+ for (auto const& col : m_columns)
+ m_iterators.push_back(col.begin());
+ }
+
+ auto operator ==(iterator const& other) const -> bool {
+ return m_iterators == other.m_iterators;
+ }
+ auto operator !=(iterator const& other) const -> bool {
+ return m_iterators != other.m_iterators;
+ }
+ auto operator *() const -> std::string {
+ std::string row, padding;
+
+ for (size_t i = 0; i < m_columns.size(); ++i) {
+ auto width = m_columns[i].width();
+ if (m_iterators[i] != m_columns[i].end()) {
+ std::string col = *m_iterators[i];
+ row += padding + col;
+ if (col.size() < width)
+ padding = std::string(width - col.size(), ' ');
+ else
+ padding = "";
+ } else {
+ padding += std::string(width, ' ');
+ }
+ }
+ return row;
+ }
+ auto operator ++() -> iterator& {
+ for (size_t i = 0; i < m_columns.size(); ++i) {
+ if (m_iterators[i] != m_columns[i].end())
+ ++m_iterators[i];
+ }
+ return *this;
+ }
+ auto operator ++(int) -> iterator {
+ iterator prev(*this);
+ operator++();
+ return prev;
+ }
+ };
+ using const_iterator = iterator;
+
+ auto begin() const -> iterator { return iterator(*this); }
+ auto end() const -> iterator { return { *this, iterator::EndTag() }; }
+
+ auto operator += (Column const& col) -> Columns& {
+ m_columns.push_back(col);
+ return *this;
+ }
+ auto operator + (Column const& col) -> Columns {
+ Columns combined = *this;
+ combined += col;
+ return combined;
+ }
+
+ inline friend std::ostream& operator << (std::ostream& os, Columns const& cols) {
+
+ bool first = true;
+ for (auto line : cols) {
+ if (first)
+ first = false;
+ else
+ os << "\n";
+ os << line;
+ }
+ return os;
+ }
+
+ auto toString() const -> std::string {
+ std::ostringstream oss;
+ oss << *this;
+ return oss.str();
+ }
+};
+
+inline auto Column::operator + (Column const& other) -> Columns {
+ Columns cols;
+ cols += *this;
+ cols += other;
+ return cols;
+}
+}
+
+}
+}
+
+// ----------- end of #include from clara_textflow.hpp -----------
+// ........... back in clara.hpp
+
+#include <cctype>
+#include <string>
+#include <memory>
+#include <set>
+#include <algorithm>
+
+#if !defined(CATCH_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) )
+#define CATCH_PLATFORM_WINDOWS
+#endif
+
+namespace Catch { namespace clara {
+namespace detail {
+
+ // Traits for extracting arg and return type of lambdas (for single argument lambdas)
+ template<typename L>
+ struct UnaryLambdaTraits : UnaryLambdaTraits<decltype( &L::operator() )> {};
+
+ template<typename ClassT, typename ReturnT, typename... Args>
+ struct UnaryLambdaTraits<ReturnT( ClassT::* )( Args... ) const> {
+ static const bool isValid = false;
+ };
+
+ template<typename ClassT, typename ReturnT, typename ArgT>
+ struct UnaryLambdaTraits<ReturnT( ClassT::* )( ArgT ) const> {
+ static const bool isValid = true;
+ using ArgType = typename std::remove_const<typename std::remove_reference<ArgT>::type>::type;
+ using ReturnType = ReturnT;
+ };
+
+ class TokenStream;
+
+ // Transport for raw args (copied from main args, or supplied via init list for testing)
+ class Args {
+ friend TokenStream;
+ std::string m_exeName;
+ std::vector<std::string> m_args;
+
+ public:
+ Args( int argc, char const* const* argv )
+ : m_exeName(argv[0]),
+ m_args(argv + 1, argv + argc) {}
+
+ Args( std::initializer_list<std::string> args )
+ : m_exeName( *args.begin() ),
+ m_args( args.begin()+1, args.end() )
+ {}
+
+ auto exeName() const -> std::string {
+ return m_exeName;
+ }
+ };
+
+ // Wraps a token coming from a token stream. These may not directly correspond to strings as a single string
+ // may encode an option + its argument if the : or = form is used
+ enum class TokenType {
+ Option, Argument
+ };
+ struct Token {
+ TokenType type;
+ std::string token;
+ };
+
+ inline auto isOptPrefix( char c ) -> bool {
+ return c == '-'
+#ifdef CATCH_PLATFORM_WINDOWS
+ || c == '/'
+#endif
+ ;
+ }
+
+ // Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled
+ class TokenStream {
+ using Iterator = std::vector<std::string>::const_iterator;
+ Iterator it;
+ Iterator itEnd;
+ std::vector<Token> m_tokenBuffer;
+
+ void loadBuffer() {
+ m_tokenBuffer.resize( 0 );
+
+ // Skip any empty strings
+ while( it != itEnd && it->empty() )
+ ++it;
+
+ if( it != itEnd ) {
+ auto const &next = *it;
+ if( isOptPrefix( next[0] ) ) {
+ auto delimiterPos = next.find_first_of( " :=" );
+ if( delimiterPos != std::string::npos ) {
+ m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } );
+ m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } );
+ } else {
+ if( next[1] != '-' && next.size() > 2 ) {
+ std::string opt = "- ";
+ for( size_t i = 1; i < next.size(); ++i ) {
+ opt[1] = next[i];
+ m_tokenBuffer.push_back( { TokenType::Option, opt } );
+ }
+ } else {
+ m_tokenBuffer.push_back( { TokenType::Option, next } );
+ }
+ }
+ } else {
+ m_tokenBuffer.push_back( { TokenType::Argument, next } );
+ }
+ }
+ }
+
+ public:
+ explicit TokenStream( Args const &args ) : TokenStream( args.m_args.begin(), args.m_args.end() ) {}
+
+ TokenStream( Iterator it, Iterator itEnd ) : it( it ), itEnd( itEnd ) {
+ loadBuffer();
+ }
+
+ explicit operator bool() const {
+ return !m_tokenBuffer.empty() || it != itEnd;
+ }
+
+ auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); }
+
+ auto operator*() const -> Token {
+ assert( !m_tokenBuffer.empty() );
+ return m_tokenBuffer.front();
+ }
+
+ auto operator->() const -> Token const * {
+ assert( !m_tokenBuffer.empty() );
+ return &m_tokenBuffer.front();
+ }
+
+ auto operator++() -> TokenStream & {
+ if( m_tokenBuffer.size() >= 2 ) {
+ m_tokenBuffer.erase( m_tokenBuffer.begin() );
+ } else {
+ if( it != itEnd )
+ ++it;
+ loadBuffer();
+ }
+ return *this;
+ }
+ };
+
+ class ResultBase {
+ public:
+ enum Type {
+ Ok, LogicError, RuntimeError
+ };
+
+ protected:
+ ResultBase( Type type ) : m_type( type ) {}
+ virtual ~ResultBase() = default;
+
+ virtual void enforceOk() const = 0;
+
+ Type m_type;
+ };
+
+ template<typename T>
+ class ResultValueBase : public ResultBase {
+ public:
+ auto value() const -> T const & {
+ enforceOk();
+ return m_value;
+ }
+
+ protected:
+ ResultValueBase( Type type ) : ResultBase( type ) {}
+
+ ResultValueBase( ResultValueBase const &other ) : ResultBase( other ) {
+ if( m_type == ResultBase::Ok )
+ new( &m_value ) T( other.m_value );
+ }
+
+ ResultValueBase( Type, T const &value ) : ResultBase( Ok ) {
+ new( &m_value ) T( value );
+ }
+
+ auto operator=( ResultValueBase const &other ) -> ResultValueBase & {
+ if( m_type == ResultBase::Ok )
+ m_value.~T();
+ ResultBase::operator=(other);
+ if( m_type == ResultBase::Ok )
+ new( &m_value ) T( other.m_value );
+ return *this;
+ }
+
+ ~ResultValueBase() override {
+ if( m_type == Ok )
+ m_value.~T();
+ }
+
+ union {
+ T m_value;
+ };
+ };
+
+ template<>
+ class ResultValueBase<void> : public ResultBase {
+ protected:
+ using ResultBase::ResultBase;
+ };
+
+ template<typename T = void>
+ class BasicResult : public ResultValueBase<T> {
+ public:
+ template<typename U>
+ explicit BasicResult( BasicResult<U> const &other )
+ : ResultValueBase<T>( other.type() ),
+ m_errorMessage( other.errorMessage() )
+ {
+ assert( type() != ResultBase::Ok );
+ }
+
+ template<typename U>
+ static auto ok( U const &value ) -> BasicResult { return { ResultBase::Ok, value }; }
+ static auto ok() -> BasicResult { return { ResultBase::Ok }; }
+ static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; }
+ static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; }
+
+ explicit operator bool() const { return m_type == ResultBase::Ok; }
+ auto type() const -> ResultBase::Type { return m_type; }
+ auto errorMessage() const -> std::string { return m_errorMessage; }
+
+ protected:
+ void enforceOk() const override {
+
+ // Errors shouldn't reach this point, but if they do
+ // the actual error message will be in m_errorMessage
+ assert( m_type != ResultBase::LogicError );
+ assert( m_type != ResultBase::RuntimeError );
+ if( m_type != ResultBase::Ok )
+ std::abort();
+ }
+
+ std::string m_errorMessage; // Only populated if resultType is an error
+
+ BasicResult( ResultBase::Type type, std::string const &message )
+ : ResultValueBase<T>(type),
+ m_errorMessage(message)
+ {
+ assert( m_type != ResultBase::Ok );
+ }
+
+ using ResultValueBase<T>::ResultValueBase;
+ using ResultBase::m_type;
+ };
+
+ enum class ParseResultType {
+ Matched, NoMatch, ShortCircuitAll, ShortCircuitSame
+ };
+
+ class ParseState {
+ public:
+
+ ParseState( ParseResultType type, TokenStream const &remainingTokens )
+ : m_type(type),
+ m_remainingTokens( remainingTokens )
+ {}
+
+ auto type() const -> ParseResultType { return m_type; }
+ auto remainingTokens() const -> TokenStream { return m_remainingTokens; }
+
+ private:
+ ParseResultType m_type;
+ TokenStream m_remainingTokens;
+ };
+
+ using Result = BasicResult<void>;
+ using ParserResult = BasicResult<ParseResultType>;
+ using InternalParseResult = BasicResult<ParseState>;
+
+ struct HelpColumns {
+ std::string left;
+ std::string right;
+ };
+
+ template<typename T>
+ inline auto convertInto( std::string const &source, T& target ) -> ParserResult {
+ std::stringstream ss;
+ ss << source;
+ ss >> target;
+ if( ss.fail() )
+ return ParserResult::runtimeError( "Unable to convert '" + source + "' to destination type" );
+ else
+ return ParserResult::ok( ParseResultType::Matched );
+ }
+ inline auto convertInto( std::string const &source, std::string& target ) -> ParserResult {
+ target = source;
+ return ParserResult::ok( ParseResultType::Matched );
+ }
+ inline auto convertInto( std::string const &source, bool &target ) -> ParserResult {
+ std::string srcLC = source;
+ std::transform( srcLC.begin(), srcLC.end(), srcLC.begin(), []( unsigned char c ) { return static_cast<char>( std::tolower(c) ); } );
+ if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on")
+ target = true;
+ else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off")
+ target = false;
+ else
+ return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" );
+ return ParserResult::ok( ParseResultType::Matched );
+ }
+#ifdef CLARA_CONFIG_OPTIONAL_TYPE
+ template<typename T>
+ inline auto convertInto( std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE<T>& target ) -> ParserResult {
+ T temp;
+ auto result = convertInto( source, temp );
+ if( result )
+ target = std::move(temp);
+ return result;
+ }
+#endif // CLARA_CONFIG_OPTIONAL_TYPE
+
+ struct NonCopyable {
+ NonCopyable() = default;
+ NonCopyable( NonCopyable const & ) = delete;
+ NonCopyable( NonCopyable && ) = delete;
+ NonCopyable &operator=( NonCopyable const & ) = delete;
+ NonCopyable &operator=( NonCopyable && ) = delete;
+ };
+
+ struct BoundRef : NonCopyable {
+ virtual ~BoundRef() = default;
+ virtual auto isContainer() const -> bool { return false; }
+ virtual auto isFlag() const -> bool { return false; }
+ };
+ struct BoundValueRefBase : BoundRef {
+ virtual auto setValue( std::string const &arg ) -> ParserResult = 0;
+ };
+ struct BoundFlagRefBase : BoundRef {
+ virtual auto setFlag( bool flag ) -> ParserResult = 0;
+ virtual auto isFlag() const -> bool { return true; }
+ };
+
+ template<typename T>
+ struct BoundValueRef : BoundValueRefBase {
+ T &m_ref;
+
+ explicit BoundValueRef( T &ref ) : m_ref( ref ) {}
+
+ auto setValue( std::string const &arg ) -> ParserResult override {
+ return convertInto( arg, m_ref );
+ }
+ };
+
+ template<typename T>
+ struct BoundValueRef<std::vector<T>> : BoundValueRefBase {
+ std::vector<T> &m_ref;
+
+ explicit BoundValueRef( std::vector<T> &ref ) : m_ref( ref ) {}
+
+ auto isContainer() const -> bool override { return true; }
+
+ auto setValue( std::string const &arg ) -> ParserResult override {
+ T temp;
+ auto result = convertInto( arg, temp );
+ if( result )
+ m_ref.push_back( temp );
+ return result;
+ }
+ };
+
+ struct BoundFlagRef : BoundFlagRefBase {
+ bool &m_ref;
+
+ explicit BoundFlagRef( bool &ref ) : m_ref( ref ) {}
+
+ auto setFlag( bool flag ) -> ParserResult override {
+ m_ref = flag;
+ return ParserResult::ok( ParseResultType::Matched );
+ }
+ };
+
+ template<typename ReturnType>
+ struct LambdaInvoker {
+ static_assert( std::is_same<ReturnType, ParserResult>::value, "Lambda must return void or clara::ParserResult" );
+
+ template<typename L, typename ArgType>
+ static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult {
+ return lambda( arg );
+ }
+ };
+
+ template<>
+ struct LambdaInvoker<void> {
+ template<typename L, typename ArgType>
+ static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult {
+ lambda( arg );
+ return ParserResult::ok( ParseResultType::Matched );
+ }
+ };
+
+ template<typename ArgType, typename L>
+ inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult {
+ ArgType temp{};
+ auto result = convertInto( arg, temp );
+ return !result
+ ? result
+ : LambdaInvoker<typename UnaryLambdaTraits<L>::ReturnType>::invoke( lambda, temp );
+ }
+
+ template<typename L>
+ struct BoundLambda : BoundValueRefBase {
+ L m_lambda;
+
+ static_assert( UnaryLambdaTraits<L>::isValid, "Supplied lambda must take exactly one argument" );
+ explicit BoundLambda( L const &lambda ) : m_lambda( lambda ) {}
+
+ auto setValue( std::string const &arg ) -> ParserResult override {
+ return invokeLambda<typename UnaryLambdaTraits<L>::ArgType>( m_lambda, arg );
+ }
+ };
+
+ template<typename L>
+ struct BoundFlagLambda : BoundFlagRefBase {
+ L m_lambda;
+
+ static_assert( UnaryLambdaTraits<L>::isValid, "Supplied lambda must take exactly one argument" );
+ static_assert( std::is_same<typename UnaryLambdaTraits<L>::ArgType, bool>::value, "flags must be boolean" );
+
+ explicit BoundFlagLambda( L const &lambda ) : m_lambda( lambda ) {}
+
+ auto setFlag( bool flag ) -> ParserResult override {
+ return LambdaInvoker<typename UnaryLambdaTraits<L>::ReturnType>::invoke( m_lambda, flag );
+ }
+ };
+
+ enum class Optionality { Optional, Required };
+
+ struct Parser;
+
+ class ParserBase {
+ public:
+ virtual ~ParserBase() = default;
+ virtual auto validate() const -> Result { return Result::ok(); }
+ virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0;
+ virtual auto cardinality() const -> size_t { return 1; }
+
+ auto parse( Args const &args ) const -> InternalParseResult {
+ return parse( args.exeName(), TokenStream( args ) );
+ }
+ };
+
+ template<typename DerivedT>
+ class ComposableParserImpl : public ParserBase {
+ public:
+ template<typename T>
+ auto operator|( T const &other ) const -> Parser;
+
+ template<typename T>
+ auto operator+( T const &other ) const -> Parser;
+ };
+
+ // Common code and state for Args and Opts
+ template<typename DerivedT>
+ class ParserRefImpl : public ComposableParserImpl<DerivedT> {
+ protected:
+ Optionality m_optionality = Optionality::Optional;
+ std::shared_ptr<BoundRef> m_ref;
+ std::string m_hint;
+ std::string m_description;
+
+ explicit ParserRefImpl( std::shared_ptr<BoundRef> const &ref ) : m_ref( ref ) {}
+
+ public:
+ template<typename T>
+ ParserRefImpl( T &ref, std::string const &hint )
+ : m_ref( std::make_shared<BoundValueRef<T>>( ref ) ),
+ m_hint( hint )
+ {}
+
+ template<typename LambdaT>
+ ParserRefImpl( LambdaT const &ref, std::string const &hint )
+ : m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ),
+ m_hint(hint)
+ {}
+
+ auto operator()( std::string const &description ) -> DerivedT & {
+ m_description = description;
+ return static_cast<DerivedT &>( *this );
+ }
+
+ auto optional() -> DerivedT & {
+ m_optionality = Optionality::Optional;
+ return static_cast<DerivedT &>( *this );
+ };
+
+ auto required() -> DerivedT & {
+ m_optionality = Optionality::Required;
+ return static_cast<DerivedT &>( *this );
+ };
+
+ auto isOptional() const -> bool {
+ return m_optionality == Optionality::Optional;
+ }
+
+ auto cardinality() const -> size_t override {
+ if( m_ref->isContainer() )
+ return 0;
+ else
+ return 1;
+ }
+
+ auto hint() const -> std::string { return m_hint; }
+ };
+
+ class ExeName : public ComposableParserImpl<ExeName> {
+ std::shared_ptr<std::string> m_name;
+ std::shared_ptr<BoundValueRefBase> m_ref;
+
+ template<typename LambdaT>
+ static auto makeRef(LambdaT const &lambda) -> std::shared_ptr<BoundValueRefBase> {
+ return std::make_shared<BoundLambda<LambdaT>>( lambda) ;
+ }
+
+ public:
+ ExeName() : m_name( std::make_shared<std::string>( "<executable>" ) ) {}
+
+ explicit ExeName( std::string &ref ) : ExeName() {
+ m_ref = std::make_shared<BoundValueRef<std::string>>( ref );
+ }
+
+ template<typename LambdaT>
+ explicit ExeName( LambdaT const& lambda ) : ExeName() {
+ m_ref = std::make_shared<BoundLambda<LambdaT>>( lambda );
+ }
+
+ // The exe name is not parsed out of the normal tokens, but is handled specially
+ auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override {
+ return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) );
+ }
+
+ auto name() const -> std::string { return *m_name; }
+ auto set( std::string const& newName ) -> ParserResult {
+
+ auto lastSlash = newName.find_last_of( "\\/" );
+ auto filename = ( lastSlash == std::string::npos )
+ ? newName
+ : newName.substr( lastSlash+1 );
+
+ *m_name = filename;
+ if( m_ref )
+ return m_ref->setValue( filename );
+ else
+ return ParserResult::ok( ParseResultType::Matched );
+ }
+ };
+
+ class Arg : public ParserRefImpl<Arg> {
+ public:
+ using ParserRefImpl::ParserRefImpl;
+
+ auto parse( std::string const &, TokenStream const &tokens ) const -> InternalParseResult override {
+ auto validationResult = validate();
+ if( !validationResult )
+ return InternalParseResult( validationResult );
+
+ auto remainingTokens = tokens;
+ auto const &token = *remainingTokens;
+ if( token.type != TokenType::Argument )
+ return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) );
+
+ assert( !m_ref->isFlag() );
+ auto valueRef = static_cast<detail::BoundValueRefBase*>( m_ref.get() );
+
+ auto result = valueRef->setValue( remainingTokens->token );
+ if( !result )
+ return InternalParseResult( result );
+ else
+ return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) );
+ }
+ };
+
+ inline auto normaliseOpt( std::string const &optName ) -> std::string {
+#ifdef CATCH_PLATFORM_WINDOWS
+ if( optName[0] == '/' )
+ return "-" + optName.substr( 1 );
+ else
+#endif
+ return optName;
+ }
+
+ class Opt : public ParserRefImpl<Opt> {
+ protected:
+ std::vector<std::string> m_optNames;
+
+ public:
+ template<typename LambdaT>
+ explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared<BoundFlagLambda<LambdaT>>( ref ) ) {}
+
+ explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared<BoundFlagRef>( ref ) ) {}
+
+ template<typename LambdaT>
+ Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {}
+
+ template<typename T>
+ Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {}
+
+ auto operator[]( std::string const &optName ) -> Opt & {
+ m_optNames.push_back( optName );
+ return *this;
+ }
+
+ auto getHelpColumns() const -> std::vector<HelpColumns> {
+ std::ostringstream oss;
+ bool first = true;
+ for( auto const &opt : m_optNames ) {
+ if (first)
+ first = false;
+ else
+ oss << ", ";
+ oss << opt;
+ }
+ if( !m_hint.empty() )
+ oss << " <" << m_hint << ">";
+ return { { oss.str(), m_description } };
+ }
+
+ auto isMatch( std::string const &optToken ) const -> bool {
+ auto normalisedToken = normaliseOpt( optToken );
+ for( auto const &name : m_optNames ) {
+ if( normaliseOpt( name ) == normalisedToken )
+ return true;
+ }
+ return false;
+ }
+
+ using ParserBase::parse;
+
+ auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override {
+ auto validationResult = validate();
+ if( !validationResult )
+ return InternalParseResult( validationResult );
+
+ auto remainingTokens = tokens;
+ if( remainingTokens && remainingTokens->type == TokenType::Option ) {
+ auto const &token = *remainingTokens;
+ if( isMatch(token.token ) ) {
+ if( m_ref->isFlag() ) {
+ auto flagRef = static_cast<detail::BoundFlagRefBase*>( m_ref.get() );
+ auto result = flagRef->setFlag( true );
+ if( !result )
+ return InternalParseResult( result );
+ if( result.value() == ParseResultType::ShortCircuitAll )
+ return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) );
+ } else {
+ auto valueRef = static_cast<detail::BoundValueRefBase*>( m_ref.get() );
+ ++remainingTokens;
+ if( !remainingTokens )
+ return InternalParseResult::runtimeError( "Expected argument following " + token.token );
+ auto const &argToken = *remainingTokens;
+ if( argToken.type != TokenType::Argument )
+ return InternalParseResult::runtimeError( "Expected argument following " + token.token );
+ auto result = valueRef->setValue( argToken.token );
+ if( !result )
+ return InternalParseResult( result );
+ if( result.value() == ParseResultType::ShortCircuitAll )
+ return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) );
+ }
+ return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) );
+ }
+ }
+ return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) );
+ }
+
+ auto validate() const -> Result override {
+ if( m_optNames.empty() )
+ return Result::logicError( "No options supplied to Opt" );
+ for( auto const &name : m_optNames ) {
+ if( name.empty() )
+ return Result::logicError( "Option name cannot be empty" );
+#ifdef CATCH_PLATFORM_WINDOWS
+ if( name[0] != '-' && name[0] != '/' )
+ return Result::logicError( "Option name must begin with '-' or '/'" );
+#else
+ if( name[0] != '-' )
+ return Result::logicError( "Option name must begin with '-'" );
+#endif
+ }
+ return ParserRefImpl::validate();
+ }
+ };
+
+ struct Help : Opt {
+ Help( bool &showHelpFlag )
+ : Opt([&]( bool flag ) {
+ showHelpFlag = flag;
+ return ParserResult::ok( ParseResultType::ShortCircuitAll );
+ })
+ {
+ static_cast<Opt &>( *this )
+ ("display usage information")
+ ["-?"]["-h"]["--help"]
+ .optional();
+ }
+ };
+
+ struct Parser : ParserBase {
+
+ mutable ExeName m_exeName;
+ std::vector<Opt> m_options;
+ std::vector<Arg> m_args;
+
+ auto operator|=( ExeName const &exeName ) -> Parser & {
+ m_exeName = exeName;
+ return *this;
+ }
+
+ auto operator|=( Arg const &arg ) -> Parser & {
+ m_args.push_back(arg);
+ return *this;
+ }
+
+ auto operator|=( Opt const &opt ) -> Parser & {
+ m_options.push_back(opt);
+ return *this;
+ }
+
+ auto operator|=( Parser const &other ) -> Parser & {
+ m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end());
+ m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end());
+ return *this;
+ }
+
+ template<typename T>
+ auto operator|( T const &other ) const -> Parser {
+ return Parser( *this ) |= other;
+ }
+
+ // Forward deprecated interface with '+' instead of '|'
+ template<typename T>
+ auto operator+=( T const &other ) -> Parser & { return operator|=( other ); }
+ template<typename T>
+ auto operator+( T const &other ) const -> Parser { return operator|( other ); }
+
+ auto getHelpColumns() const -> std::vector<HelpColumns> {
+ std::vector<HelpColumns> cols;
+ for (auto const &o : m_options) {
+ auto childCols = o.getHelpColumns();
+ cols.insert( cols.end(), childCols.begin(), childCols.end() );
+ }
+ return cols;
+ }
+
+ void writeToStream( std::ostream &os ) const {
+ if (!m_exeName.name().empty()) {
+ os << "usage:\n" << " " << m_exeName.name() << " ";
+ bool required = true, first = true;
+ for( auto const &arg : m_args ) {
+ if (first)
+ first = false;
+ else
+ os << " ";
+ if( arg.isOptional() && required ) {
+ os << "[";
+ required = false;
+ }
+ os << "<" << arg.hint() << ">";
+ if( arg.cardinality() == 0 )
+ os << " ... ";
+ }
+ if( !required )
+ os << "]";
+ if( !m_options.empty() )
+ os << " options";
+ os << "\n\nwhere options are:" << std::endl;
+ }
+
+ auto rows = getHelpColumns();
+ size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH;
+ size_t optWidth = 0;
+ for( auto const &cols : rows )
+ optWidth = (std::max)(optWidth, cols.left.size() + 2);
+
+ optWidth = (std::min)(optWidth, consoleWidth/2);
+
+ for( auto const &cols : rows ) {
+ auto row =
+ TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) +
+ TextFlow::Spacer(4) +
+ TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth );
+ os << row << std::endl;
+ }
+ }
+
+ friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& {
+ parser.writeToStream( os );
+ return os;
+ }
+
+ auto validate() const -> Result override {
+ for( auto const &opt : m_options ) {
+ auto result = opt.validate();
+ if( !result )
+ return result;
+ }
+ for( auto const &arg : m_args ) {
+ auto result = arg.validate();
+ if( !result )
+ return result;
+ }
+ return Result::ok();
+ }
+
+ using ParserBase::parse;
+
+ auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override {
+
+ struct ParserInfo {
+ ParserBase const* parser = nullptr;
+ size_t count = 0;
+ };
+ const size_t totalParsers = m_options.size() + m_args.size();
+ assert( totalParsers < 512 );
+ // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do
+ ParserInfo parseInfos[512];
+
+ {
+ size_t i = 0;
+ for (auto const &opt : m_options) parseInfos[i++].parser = &opt;
+ for (auto const &arg : m_args) parseInfos[i++].parser = &arg;
+ }
+
+ m_exeName.set( exeName );
+
+ auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) );
+ while( result.value().remainingTokens() ) {
+ bool tokenParsed = false;
+
+ for( size_t i = 0; i < totalParsers; ++i ) {
+ auto& parseInfo = parseInfos[i];
+ if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) {
+ result = parseInfo.parser->parse(exeName, result.value().remainingTokens());
+ if (!result)
+ return result;
+ if (result.value().type() != ParseResultType::NoMatch) {
+ tokenParsed = true;
+ ++parseInfo.count;
+ break;
+ }
+ }
+ }
+
+ if( result.value().type() == ParseResultType::ShortCircuitAll )
+ return result;
+ if( !tokenParsed )
+ return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token );
+ }
+ // !TBD Check missing required options
+ return result;
+ }
+ };
+
+ template<typename DerivedT>
+ template<typename T>
+ auto ComposableParserImpl<DerivedT>::operator|( T const &other ) const -> Parser {
+ return Parser() | static_cast<DerivedT const &>( *this ) | other;
+ }
+} // namespace detail
+
+// A Combined parser
+using detail::Parser;
+
+// A parser for options
+using detail::Opt;
+
+// A parser for arguments
+using detail::Arg;
+
+// Wrapper for argc, argv from main()
+using detail::Args;
+
+// Specifies the name of the executable
+using detail::ExeName;
+
+// Convenience wrapper for option parser that specifies the help option
+using detail::Help;
+
+// enum of result types from a parse
+using detail::ParseResultType;
+
+// Result type for parser operation
+using detail::ParserResult;
+
+}} // namespace Catch::clara
+
+// end clara.hpp
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
+// Restore Clara's value for console width, if present
+#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
+#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
+#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
+#endif
+
+// end catch_clara.h
+namespace Catch {
+
+ clara::Parser makeCommandLineParser( ConfigData& config );
+
+} // end namespace Catch
+
+// end catch_commandline.h
+#include <fstream>
+#include <ctime>
+
+namespace Catch {
+
+ clara::Parser makeCommandLineParser( ConfigData& config ) {
+
+ using namespace clara;
+
+ auto const setWarning = [&]( std::string const& warning ) {
+ auto warningSet = [&]() {
+ if( warning == "NoAssertions" )
+ return WarnAbout::NoAssertions;
+
+ if ( warning == "NoTests" )
+ return WarnAbout::NoTests;
+
+ return WarnAbout::Nothing;
+ }();
+
+ if (warningSet == WarnAbout::Nothing)
+ return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" );
+ config.warnings = static_cast<WarnAbout::What>( config.warnings | warningSet );
+ return ParserResult::ok( ParseResultType::Matched );
+ };
+ auto const loadTestNamesFromFile = [&]( std::string const& filename ) {
+ std::ifstream f( filename.c_str() );
+ if( !f.is_open() )
+ return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" );
+
+ std::string line;
+ while( std::getline( f, line ) ) {
+ line = trim(line);
+ if( !line.empty() && !startsWith( line, '#' ) ) {
+ if( !startsWith( line, '"' ) )
+ line = '"' + line + '"';
+ config.testsOrTags.push_back( line );
+ config.testsOrTags.emplace_back( "," );
+ }
+ }
+ //Remove comma in the end
+ if(!config.testsOrTags.empty())
+ config.testsOrTags.erase( config.testsOrTags.end()-1 );
+
+ return ParserResult::ok( ParseResultType::Matched );
+ };
+ auto const setTestOrder = [&]( std::string const& order ) {
+ if( startsWith( "declared", order ) )
+ config.runOrder = RunTests::InDeclarationOrder;
+ else if( startsWith( "lexical", order ) )
+ config.runOrder = RunTests::InLexicographicalOrder;
+ else if( startsWith( "random", order ) )
+ config.runOrder = RunTests::InRandomOrder;
+ else
+ return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" );
+ return ParserResult::ok( ParseResultType::Matched );
+ };
+ auto const setRngSeed = [&]( std::string const& seed ) {
+ if( seed != "time" )
+ return clara::detail::convertInto( seed, config.rngSeed );
+ config.rngSeed = static_cast<unsigned int>( std::time(nullptr) );
+ return ParserResult::ok( ParseResultType::Matched );
+ };
+ auto const setColourUsage = [&]( std::string const& useColour ) {
+ auto mode = toLower( useColour );
+
+ if( mode == "yes" )
+ config.useColour = UseColour::Yes;
+ else if( mode == "no" )
+ config.useColour = UseColour::No;
+ else if( mode == "auto" )
+ config.useColour = UseColour::Auto;
+ else
+ return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" );
+ return ParserResult::ok( ParseResultType::Matched );
+ };
+ auto const setWaitForKeypress = [&]( std::string const& keypress ) {
+ auto keypressLc = toLower( keypress );
+ if (keypressLc == "never")
+ config.waitForKeypress = WaitForKeypress::Never;
+ else if( keypressLc == "start" )
+ config.waitForKeypress = WaitForKeypress::BeforeStart;
+ else if( keypressLc == "exit" )
+ config.waitForKeypress = WaitForKeypress::BeforeExit;
+ else if( keypressLc == "both" )
+ config.waitForKeypress = WaitForKeypress::BeforeStartAndExit;
+ else
+ return ParserResult::runtimeError( "keypress argument must be one of: never, start, exit or both. '" + keypress + "' not recognised" );
+ return ParserResult::ok( ParseResultType::Matched );
+ };
+ auto const setVerbosity = [&]( std::string const& verbosity ) {
+ auto lcVerbosity = toLower( verbosity );
+ if( lcVerbosity == "quiet" )
+ config.verbosity = Verbosity::Quiet;
+ else if( lcVerbosity == "normal" )
+ config.verbosity = Verbosity::Normal;
+ else if( lcVerbosity == "high" )
+ config.verbosity = Verbosity::High;
+ else
+ return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" );
+ return ParserResult::ok( ParseResultType::Matched );
+ };
+ auto const setReporter = [&]( std::string const& reporter ) {
+ IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
+
+ auto lcReporter = toLower( reporter );
+ auto result = factories.find( lcReporter );
+
+ if( factories.end() != result )
+ config.reporterName = lcReporter;
+ else
+ return ParserResult::runtimeError( "Unrecognized reporter, '" + reporter + "'. Check available with --list-reporters" );
+ return ParserResult::ok( ParseResultType::Matched );
+ };
+
+ auto cli
+ = ExeName( config.processName )
+ | Help( config.showHelp )
+ | Opt( config.listTests )
+ ["-l"]["--list-tests"]
+ ( "list all/matching test cases" )
+ | Opt( config.listTags )
+ ["-t"]["--list-tags"]
+ ( "list all/matching tags" )
+ | Opt( config.showSuccessfulTests )
+ ["-s"]["--success"]
+ ( "include successful tests in output" )
+ | Opt( config.shouldDebugBreak )
+ ["-b"]["--break"]
+ ( "break into debugger on failure" )
+ | Opt( config.noThrow )
+ ["-e"]["--nothrow"]
+ ( "skip exception tests" )
+ | Opt( config.showInvisibles )
+ ["-i"]["--invisibles"]
+ ( "show invisibles (tabs, newlines)" )
+ | Opt( config.outputFilename, "filename" )
+ ["-o"]["--out"]
+ ( "output filename" )
+ | Opt( setReporter, "name" )
+ ["-r"]["--reporter"]
+ ( "reporter to use (defaults to console)" )
+ | Opt( config.name, "name" )
+ ["-n"]["--name"]
+ ( "suite name" )
+ | Opt( [&]( bool ){ config.abortAfter = 1; } )
+ ["-a"]["--abort"]
+ ( "abort at first failure" )
+ | Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" )
+ ["-x"]["--abortx"]
+ ( "abort after x failures" )
+ | Opt( setWarning, "warning name" )
+ ["-w"]["--warn"]
+ ( "enable warnings" )
+ | Opt( [&]( bool flag ) { config.showDurations = flag ? ShowDurations::Always : ShowDurations::Never; }, "yes|no" )
+ ["-d"]["--durations"]
+ ( "show test durations" )
+ | Opt( config.minDuration, "seconds" )
+ ["-D"]["--min-duration"]
+ ( "show test durations for tests taking at least the given number of seconds" )
+ | Opt( loadTestNamesFromFile, "filename" )
+ ["-f"]["--input-file"]
+ ( "load test names to run from a file" )
+ | Opt( config.filenamesAsTags )
+ ["-#"]["--filenames-as-tags"]
+ ( "adds a tag for the filename" )
+ | Opt( config.sectionsToRun, "section name" )
+ ["-c"]["--section"]
+ ( "specify section to run" )
+ | Opt( setVerbosity, "quiet|normal|high" )
+ ["-v"]["--verbosity"]
+ ( "set output verbosity" )
+ | Opt( config.listTestNamesOnly )
+ ["--list-test-names-only"]
+ ( "list all/matching test cases names only" )
+ | Opt( config.listReporters )
+ ["--list-reporters"]
+ ( "list all reporters" )
+ | Opt( setTestOrder, "decl|lex|rand" )
+ ["--order"]
+ ( "test case order (defaults to decl)" )
+ | Opt( setRngSeed, "'time'|number" )
+ ["--rng-seed"]
+ ( "set a specific seed for random numbers" )
+ | Opt( setColourUsage, "yes|no" )
+ ["--use-colour"]
+ ( "should output be colourised" )
+ | Opt( config.libIdentify )
+ ["--libidentify"]
+ ( "report name and version according to libidentify standard" )
+ | Opt( setWaitForKeypress, "never|start|exit|both" )
+ ["--wait-for-keypress"]
+ ( "waits for a keypress before exiting" )
+ | Opt( config.benchmarkSamples, "samples" )
+ ["--benchmark-samples"]
+ ( "number of samples to collect (default: 100)" )
+ | Opt( config.benchmarkResamples, "resamples" )
+ ["--benchmark-resamples"]
+ ( "number of resamples for the bootstrap (default: 100000)" )
+ | Opt( config.benchmarkConfidenceInterval, "confidence interval" )
+ ["--benchmark-confidence-interval"]
+ ( "confidence interval for the bootstrap (between 0 and 1, default: 0.95)" )
+ | Opt( config.benchmarkNoAnalysis )
+ ["--benchmark-no-analysis"]
+ ( "perform only measurements; do not perform any analysis" )
+ | Opt( config.benchmarkWarmupTime, "benchmarkWarmupTime" )
+ ["--benchmark-warmup-time"]
+ ( "amount of time in milliseconds spent on warming up each test (default: 100)" )
+ | Arg( config.testsOrTags, "test name|pattern|tags" )
+ ( "which test or tests to use" );
+
+ return cli;
+ }
+
+} // end namespace Catch
+// end catch_commandline.cpp
+// start catch_common.cpp
+
+#include <cstring>
+#include <ostream>
+
+namespace Catch {
+
+ bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept {
+ return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
+ }
+ bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept {
+ // We can assume that the same file will usually have the same pointer.
+ // Thus, if the pointers are the same, there is no point in calling the strcmp
+ return line < other.line || ( line == other.line && file != other.file && (std::strcmp(file, other.file) < 0));
+ }
+
+ std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
+#ifndef __GNUG__
+ os << info.file << '(' << info.line << ')';
+#else
+ os << info.file << ':' << info.line;
+#endif
+ return os;
+ }
+
+ std::string StreamEndStop::operator+() const {
+ return std::string();
+ }
+
+ NonCopyable::NonCopyable() = default;
+ NonCopyable::~NonCopyable() = default;
+
+}
+// end catch_common.cpp
+// start catch_config.cpp
+
+namespace Catch {
+
+ Config::Config( ConfigData const& data )
+ : m_data( data ),
+ m_stream( openStream() )
+ {
+ // We need to trim filter specs to avoid trouble with superfluous
+ // whitespace (esp. important for bdd macros, as those are manually
+ // aligned with whitespace).
+
+ for (auto& elem : m_data.testsOrTags) {
+ elem = trim(elem);
+ }
+ for (auto& elem : m_data.sectionsToRun) {
+ elem = trim(elem);
+ }
+
+ TestSpecParser parser(ITagAliasRegistry::get());
+ if (!m_data.testsOrTags.empty()) {
+ m_hasTestFilters = true;
+ for (auto const& testOrTags : m_data.testsOrTags) {
+ parser.parse(testOrTags);
+ }
+ }
+ m_testSpec = parser.testSpec();
+ }
+
+ std::string const& Config::getFilename() const {
+ return m_data.outputFilename ;
+ }
+
+ bool Config::listTests() const { return m_data.listTests; }
+ bool Config::listTestNamesOnly() const { return m_data.listTestNamesOnly; }
+ bool Config::listTags() const { return m_data.listTags; }
+ bool Config::listReporters() const { return m_data.listReporters; }
+
+ std::string Config::getProcessName() const { return m_data.processName; }
+ std::string const& Config::getReporterName() const { return m_data.reporterName; }
+
+ std::vector<std::string> const& Config::getTestsOrTags() const { return m_data.testsOrTags; }
+ std::vector<std::string> const& Config::getSectionsToRun() const { return m_data.sectionsToRun; }
+
+ TestSpec const& Config::testSpec() const { return m_testSpec; }
+ bool Config::hasTestFilters() const { return m_hasTestFilters; }
+
+ bool Config::showHelp() const { return m_data.showHelp; }
+
+ // IConfig interface
+ bool Config::allowThrows() const { return !m_data.noThrow; }
+ std::ostream& Config::stream() const { return m_stream->stream(); }
+ std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
+ bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
+ bool Config::warnAboutMissingAssertions() const { return !!(m_data.warnings & WarnAbout::NoAssertions); }
+ bool Config::warnAboutNoTests() const { return !!(m_data.warnings & WarnAbout::NoTests); }
+ ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; }
+ double Config::minDuration() const { return m_data.minDuration; }
+ RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; }
+ unsigned int Config::rngSeed() const { return m_data.rngSeed; }
+ UseColour::YesOrNo Config::useColour() const { return m_data.useColour; }
+ bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; }
+ int Config::abortAfter() const { return m_data.abortAfter; }
+ bool Config::showInvisibles() const { return m_data.showInvisibles; }
+ Verbosity Config::verbosity() const { return m_data.verbosity; }
+
+ bool Config::benchmarkNoAnalysis() const { return m_data.benchmarkNoAnalysis; }
+ int Config::benchmarkSamples() const { return m_data.benchmarkSamples; }
+ double Config::benchmarkConfidenceInterval() const { return m_data.benchmarkConfidenceInterval; }
+ unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; }
+ std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
+
+ IStream const* Config::openStream() {
+ return Catch::makeStream(m_data.outputFilename);
+ }
+
+} // end namespace Catch
+// end catch_config.cpp
+// start catch_console_colour.cpp
+
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wexit-time-destructors"
+#endif
+
+// start catch_errno_guard.h
+
+namespace Catch {
+
+ class ErrnoGuard {
+ public:
+ ErrnoGuard();
+ ~ErrnoGuard();
+ private:
+ int m_oldErrno;
+ };
+
+}
+
+// end catch_errno_guard.h
+// start catch_windows_h_proxy.h
+
+
+#if defined(CATCH_PLATFORM_WINDOWS)
+
+#if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX)
+# define CATCH_DEFINED_NOMINMAX
+# define NOMINMAX
+#endif
+#if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN)
+# define CATCH_DEFINED_WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
+
+#ifdef __AFXDLL
+#include <AfxWin.h>
+#else
+#include <windows.h>
+#endif
+
+#ifdef CATCH_DEFINED_NOMINMAX
+# undef NOMINMAX
+#endif
+#ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN
+# undef WIN32_LEAN_AND_MEAN
+#endif
+
+#endif // defined(CATCH_PLATFORM_WINDOWS)
+
+// end catch_windows_h_proxy.h
+#include <sstream>
+
+namespace Catch {
+ namespace {
+
+ struct IColourImpl {
+ virtual ~IColourImpl() = default;
+ virtual void use( Colour::Code _colourCode ) = 0;
+ };
+
+ struct NoColourImpl : IColourImpl {
+ void use( Colour::Code ) override {}
+
+ static IColourImpl* instance() {
+ static NoColourImpl s_instance;
+ return &s_instance;
+ }
+ };
+
+ } // anon namespace
+} // namespace Catch
+
+#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI )
+# ifdef CATCH_PLATFORM_WINDOWS
+# define CATCH_CONFIG_COLOUR_WINDOWS
+# else
+# define CATCH_CONFIG_COLOUR_ANSI
+# endif
+#endif
+
+#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) /////////////////////////////////////////
+
+namespace Catch {
+namespace {
+
+ class Win32ColourImpl : public IColourImpl {
+ public:
+ Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
+ {
+ CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
+ GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
+ originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
+ originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
+ }
+
+ void use( Colour::Code _colourCode ) override {
+ switch( _colourCode ) {
+ case Colour::None: return setTextAttribute( originalForegroundAttributes );
+ case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
+ case Colour::Red: return setTextAttribute( FOREGROUND_RED );
+ case Colour::Green: return setTextAttribute( FOREGROUND_GREEN );
+ case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE );
+ case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN );
+ case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN );
+ case Colour::Grey: return setTextAttribute( 0 );
+
+ case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY );
+ case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED );
+ case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
+ case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
+ case Colour::BrightYellow: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN );
+
+ case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" );
+
+ default:
+ CATCH_ERROR( "Unknown colour requested" );
+ }
+ }
+
+ private:
+ void setTextAttribute( WORD _textAttribute ) {
+ SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
+ }
+ HANDLE stdoutHandle;
+ WORD originalForegroundAttributes;
+ WORD originalBackgroundAttributes;
+ };
+
+ IColourImpl* platformColourInstance() {
+ static Win32ColourImpl s_instance;
+
+ IConfigPtr config = getCurrentContext().getConfig();
+ UseColour::YesOrNo colourMode = config
+ ? config->useColour()
+ : UseColour::Auto;
+ if( colourMode == UseColour::Auto )
+ colourMode = UseColour::Yes;
+ return colourMode == UseColour::Yes
+ ? &s_instance
+ : NoColourImpl::instance();
+ }
+
+} // end anon namespace
+} // end namespace Catch
+
+#elif defined( CATCH_CONFIG_COLOUR_ANSI ) //////////////////////////////////////
+
+#include <unistd.h>
+
+namespace Catch {
+namespace {
+
+ // use POSIX/ ANSI console terminal codes
+ // Thanks to Adam Strzelecki for original contribution
+ // (http://github.com/nanoant)
+ // https://github.com/philsquared/Catch/pull/131
+ class PosixColourImpl : public IColourImpl {
+ public:
+ void use( Colour::Code _colourCode ) override {
+ switch( _colourCode ) {
+ case Colour::None:
+ case Colour::White: return setColour( "[0m" );
+ case Colour::Red: return setColour( "[0;31m" );
+ case Colour::Green: return setColour( "[0;32m" );
+ case Colour::Blue: return setColour( "[0;34m" );
+ case Colour::Cyan: return setColour( "[0;36m" );
+ case Colour::Yellow: return setColour( "[0;33m" );
+ case Colour::Grey: return setColour( "[1;30m" );
+
+ case Colour::LightGrey: return setColour( "[0;37m" );
+ case Colour::BrightRed: return setColour( "[1;31m" );
+ case Colour::BrightGreen: return setColour( "[1;32m" );
+ case Colour::BrightWhite: return setColour( "[1;37m" );
+ case Colour::BrightYellow: return setColour( "[1;33m" );
+
+ case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" );
+ default: CATCH_INTERNAL_ERROR( "Unknown colour requested" );
+ }
+ }
+ static IColourImpl* instance() {
+ static PosixColourImpl s_instance;
+ return &s_instance;
+ }
+
+ private:
+ void setColour( const char* _escapeCode ) {
+ getCurrentContext().getConfig()->stream()
+ << '\033' << _escapeCode;
+ }
+ };
+
+ bool useColourOnPlatform() {
+ return
+#if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE)
+ !isDebuggerActive() &&
+#endif
+#if !(defined(__DJGPP__) && defined(__STRICT_ANSI__))
+ isatty(STDOUT_FILENO)
+#else
+ false
+#endif
+ ;
+ }
+ IColourImpl* platformColourInstance() {
+ ErrnoGuard guard;
+ IConfigPtr config = getCurrentContext().getConfig();
+ UseColour::YesOrNo colourMode = config
+ ? config->useColour()
+ : UseColour::Auto;
+ if( colourMode == UseColour::Auto )
+ colourMode = useColourOnPlatform()
+ ? UseColour::Yes
+ : UseColour::No;
+ return colourMode == UseColour::Yes
+ ? PosixColourImpl::instance()
+ : NoColourImpl::instance();
+ }
+
+} // end anon namespace
+} // end namespace Catch
+
+#else // not Windows or ANSI ///////////////////////////////////////////////
+
+namespace Catch {
+
+ static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); }
+
+} // end namespace Catch
+
+#endif // Windows/ ANSI/ None
+
+namespace Catch {
+
+ Colour::Colour( Code _colourCode ) { use( _colourCode ); }
+ Colour::Colour( Colour&& other ) noexcept {
+ m_moved = other.m_moved;
+ other.m_moved = true;
+ }
+ Colour& Colour::operator=( Colour&& other ) noexcept {
+ m_moved = other.m_moved;
+ other.m_moved = true;
+ return *this;
+ }
+
+ Colour::~Colour(){ if( !m_moved ) use( None ); }
+
+ void Colour::use( Code _colourCode ) {
+ static IColourImpl* impl = platformColourInstance();
+ // Strictly speaking, this cannot possibly happen.
+ // However, under some conditions it does happen (see #1626),
+ // and this change is small enough that we can let practicality
+ // triumph over purity in this case.
+ if (impl != nullptr) {
+ impl->use( _colourCode );
+ }
+ }
+
+ std::ostream& operator << ( std::ostream& os, Colour const& ) {
+ return os;
+ }
+
+} // end namespace Catch
+
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
+// end catch_console_colour.cpp
+// start catch_context.cpp
+
+namespace Catch {
+
+ class Context : public IMutableContext, NonCopyable {
+
+ public: // IContext
+ IResultCapture* getResultCapture() override {
+ return m_resultCapture;
+ }
+ IRunner* getRunner() override {
+ return m_runner;
+ }
+
+ IConfigPtr const& getConfig() const override {
+ return m_config;
+ }
+
+ ~Context() override;
+
+ public: // IMutableContext
+ void setResultCapture( IResultCapture* resultCapture ) override {
+ m_resultCapture = resultCapture;
+ }
+ void setRunner( IRunner* runner ) override {
+ m_runner = runner;
+ }
+ void setConfig( IConfigPtr const& config ) override {
+ m_config = config;
+ }
+
+ friend IMutableContext& getCurrentMutableContext();
+
+ private:
+ IConfigPtr m_config;
+ IRunner* m_runner = nullptr;
+ IResultCapture* m_resultCapture = nullptr;
+ };
+
+ IMutableContext *IMutableContext::currentContext = nullptr;
+
+ void IMutableContext::createContext()
+ {
+ currentContext = new Context();
+ }
+
+ void cleanUpContext() {
+ delete IMutableContext::currentContext;
+ IMutableContext::currentContext = nullptr;
+ }
+ IContext::~IContext() = default;
+ IMutableContext::~IMutableContext() = default;
+ Context::~Context() = default;
+
+ SimplePcg32& rng() {
+ static SimplePcg32 s_rng;
+ return s_rng;
+ }
+
+}
+// end catch_context.cpp
+// start catch_debug_console.cpp
+
+// start catch_debug_console.h
+
+#include <string>
+
+namespace Catch {
+ void writeToDebugConsole( std::string const& text );
+}
+
+// end catch_debug_console.h
+#if defined(CATCH_CONFIG_ANDROID_LOGWRITE)
+#include <android/log.h>
+
+ namespace Catch {
+ void writeToDebugConsole( std::string const& text ) {
+ __android_log_write( ANDROID_LOG_DEBUG, "Catch", text.c_str() );
+ }
+ }
+
+#elif defined(CATCH_PLATFORM_WINDOWS)
+
+ namespace Catch {
+ void writeToDebugConsole( std::string const& text ) {
+ ::OutputDebugStringA( text.c_str() );
+ }
+ }
+
+#else
+
+ namespace Catch {
+ void writeToDebugConsole( std::string const& text ) {
+ // !TBD: Need a version for Mac/ XCode and other IDEs
+ Catch::cout() << text;
+ }
+ }
+
+#endif // Platform
+// end catch_debug_console.cpp
+// start catch_debugger.cpp
+
+#if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE)
+
+# include <cassert>
+# include <sys/types.h>
+# include <unistd.h>
+# include <cstddef>
+# include <ostream>
+
+#ifdef __apple_build_version__
+ // These headers will only compile with AppleClang (XCode)
+ // For other compilers (Clang, GCC, ... ) we need to exclude them
+# include <sys/sysctl.h>
+#endif
+
+ namespace Catch {
+ #ifdef __apple_build_version__
+ // The following function is taken directly from the following technical note:
+ // https://developer.apple.com/library/archive/qa/qa1361/_index.html
+
+ // Returns true if the current process is being debugged (either
+ // running under the debugger or has a debugger attached post facto).
+ bool isDebuggerActive(){
+ int mib[4];
+ struct kinfo_proc info;
+ std::size_t size;
+
+ // Initialize the flags so that, if sysctl fails for some bizarre
+ // reason, we get a predictable result.
+
+ info.kp_proc.p_flag = 0;
+
+ // Initialize mib, which tells sysctl the info we want, in this case
+ // we're looking for information about a specific process ID.
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_PID;
+ mib[3] = getpid();
+
+ // Call sysctl.
+
+ size = sizeof(info);
+ if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) {
+ Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
+ return false;
+ }
+
+ // We're being debugged if the P_TRACED flag is set.
+
+ return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
+ }
+ #else
+ bool isDebuggerActive() {
+ // We need to find another way to determine this for non-appleclang compilers on macOS
+ return false;
+ }
+ #endif
+ } // namespace Catch
+
+#elif defined(CATCH_PLATFORM_LINUX)
+ #include <fstream>
+ #include <string>
+
+ namespace Catch{
+ // The standard POSIX way of detecting a debugger is to attempt to
+ // ptrace() the process, but this needs to be done from a child and not
+ // this process itself to still allow attaching to this process later
+ // if wanted, so is rather heavy. Under Linux we have the PID of the
+ // "debugger" (which doesn't need to be gdb, of course, it could also
+ // be strace, for example) in /proc/$PID/status, so just get it from
+ // there instead.
+ bool isDebuggerActive(){
+ // Libstdc++ has a bug, where std::ifstream sets errno to 0
+ // This way our users can properly assert over errno values
+ ErrnoGuard guard;
+ std::ifstream in("/proc/self/status");
+ for( std::string line; std::getline(in, line); ) {
+ static const int PREFIX_LEN = 11;
+ if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) {
+ // We're traced if the PID is not 0 and no other PID starts
+ // with 0 digit, so it's enough to check for just a single
+ // character.
+ return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0';
+ }
+ }
+
+ return false;
+ }
+ } // namespace Catch
+#elif defined(_MSC_VER)
+ extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
+ namespace Catch {
+ bool isDebuggerActive() {
+ return IsDebuggerPresent() != 0;
+ }
+ }
+#elif defined(__MINGW32__)
+ extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
+ namespace Catch {
+ bool isDebuggerActive() {
+ return IsDebuggerPresent() != 0;
+ }
+ }
+#else
+ namespace Catch {
+ bool isDebuggerActive() { return false; }
+ }
+#endif // Platform
+// end catch_debugger.cpp
+// start catch_decomposer.cpp
+
+namespace Catch {
+
+ ITransientExpression::~ITransientExpression() = default;
+
+ void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) {
+ if( lhs.size() + rhs.size() < 40 &&
+ lhs.find('\n') == std::string::npos &&
+ rhs.find('\n') == std::string::npos )
+ os << lhs << " " << op << " " << rhs;
+ else
+ os << lhs << "\n" << op << "\n" << rhs;
+ }
+}
+// end catch_decomposer.cpp
+// start catch_enforce.cpp
+
+#include <stdexcept>
+
+namespace Catch {
+#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER)
+ [[noreturn]]
+ void throw_exception(std::exception const& e) {
+ Catch::cerr() << "Catch will terminate because it needed to throw an exception.\n"
+ << "The message was: " << e.what() << '\n';
+ std::terminate();
+ }
+#endif
+
+ [[noreturn]]
+ void throw_logic_error(std::string const& msg) {
+ throw_exception(std::logic_error(msg));
+ }
+
+ [[noreturn]]
+ void throw_domain_error(std::string const& msg) {
+ throw_exception(std::domain_error(msg));
+ }
+
+ [[noreturn]]
+ void throw_runtime_error(std::string const& msg) {
+ throw_exception(std::runtime_error(msg));
+ }
+
+} // namespace Catch;
+// end catch_enforce.cpp
+// start catch_enum_values_registry.cpp
+// start catch_enum_values_registry.h
+
+#include <vector>
+#include <memory>
+
+namespace Catch {
+
+ namespace Detail {
+
+ std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values );
+
+ class EnumValuesRegistry : public IMutableEnumValuesRegistry {
+
+ std::vector<std::unique_ptr<EnumInfo>> m_enumInfos;
+
+ EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values) override;
+ };
+
+ std::vector<StringRef> parseEnums( StringRef enums );
+
+ } // Detail
+
+} // Catch
+
+// end catch_enum_values_registry.h
+
+#include <map>
+#include <cassert>
+
+namespace Catch {
+
+ IMutableEnumValuesRegistry::~IMutableEnumValuesRegistry() {}
+
+ namespace Detail {
+
+ namespace {
+ // Extracts the actual name part of an enum instance
+ // In other words, it returns the Blue part of Bikeshed::Colour::Blue
+ StringRef extractInstanceName(StringRef enumInstance) {
+ // Find last occurrence of ":"
+ size_t name_start = enumInstance.size();
+ while (name_start > 0 && enumInstance[name_start - 1] != ':') {
+ --name_start;
+ }
+ return enumInstance.substr(name_start, enumInstance.size() - name_start);
+ }
+ }
+
+ std::vector<StringRef> parseEnums( StringRef enums ) {
+ auto enumValues = splitStringRef( enums, ',' );
+ std::vector<StringRef> parsed;
+ parsed.reserve( enumValues.size() );
+ for( auto const& enumValue : enumValues ) {
+ parsed.push_back(trim(extractInstanceName(enumValue)));
+ }
+ return parsed;
+ }
+
+ EnumInfo::~EnumInfo() {}
+
+ StringRef EnumInfo::lookup( int value ) const {
+ for( auto const& valueToName : m_values ) {
+ if( valueToName.first == value )
+ return valueToName.second;
+ }
+ return "{** unexpected enum value **}"_sr;
+ }
+
+ std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
+ std::unique_ptr<EnumInfo> enumInfo( new EnumInfo );
+ enumInfo->m_name = enumName;
+ enumInfo->m_values.reserve( values.size() );
+
+ const auto valueNames = Catch::Detail::parseEnums( allValueNames );
+ assert( valueNames.size() == values.size() );
+ std::size_t i = 0;
+ for( auto value : values )
+ enumInfo->m_values.emplace_back(value, valueNames[i++]);
+
+ return enumInfo;
+ }
+
+ EnumInfo const& EnumValuesRegistry::registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
+ m_enumInfos.push_back(makeEnumInfo(enumName, allValueNames, values));
+ return *m_enumInfos.back();
+ }
+
+ } // Detail
+} // Catch
+
+// end catch_enum_values_registry.cpp
+// start catch_errno_guard.cpp
+
+#include <cerrno>
+
+namespace Catch {
+ ErrnoGuard::ErrnoGuard():m_oldErrno(errno){}
+ ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; }
+}
+// end catch_errno_guard.cpp
+// start catch_exception_translator_registry.cpp
+
+// start catch_exception_translator_registry.h
+
+#include <vector>
+#include <string>
+#include <memory>
+
+namespace Catch {
+
+ class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
+ public:
+ ~ExceptionTranslatorRegistry();
+ virtual void registerTranslator( const IExceptionTranslator* translator );
+ std::string translateActiveException() const override;
+ std::string tryTranslators() const;
+
+ private:
+ std::vector<std::unique_ptr<IExceptionTranslator const>> m_translators;
+ };
+}
+
+// end catch_exception_translator_registry.h
+#ifdef __OBJC__
+#import "Foundation/Foundation.h"
+#endif
+
+namespace Catch {
+
+ ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() {
+ }
+
+ void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) {
+ m_translators.push_back( std::unique_ptr<const IExceptionTranslator>( translator ) );
+ }
+
+#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+ std::string ExceptionTranslatorRegistry::translateActiveException() const {
+ try {
+#ifdef __OBJC__
+ // In Objective-C try objective-c exceptions first
+ @try {
+ return tryTranslators();
+ }
+ @catch (NSException *exception) {
+ return Catch::Detail::stringify( [exception description] );
+ }
+#else
+ // Compiling a mixed mode project with MSVC means that CLR
+ // exceptions will be caught in (...) as well. However, these
+ // do not fill-in std::current_exception and thus lead to crash
+ // when attempting rethrow.
+ // /EHa switch also causes structured exceptions to be caught
+ // here, but they fill-in current_exception properly, so
+ // at worst the output should be a little weird, instead of
+ // causing a crash.
+ if (std::current_exception() == nullptr) {
+ return "Non C++ exception. Possibly a CLR exception.";
+ }
+ return tryTranslators();
+#endif
+ }
+ catch( TestFailureException& ) {
+ std::rethrow_exception(std::current_exception());
+ }
+ catch( std::exception& ex ) {
+ return ex.what();
+ }
+ catch( std::string& msg ) {
+ return msg;
+ }
+ catch( const char* msg ) {
+ return msg;
+ }
+ catch(...) {
+ return "Unknown exception";
+ }
+ }
+
+ std::string ExceptionTranslatorRegistry::tryTranslators() const {
+ if (m_translators.empty()) {
+ std::rethrow_exception(std::current_exception());
+ } else {
+ return m_translators[0]->translate(m_translators.begin() + 1, m_translators.end());
+ }
+ }
+
+#else // ^^ Exceptions are enabled // Exceptions are disabled vv
+ std::string ExceptionTranslatorRegistry::translateActiveException() const {
+ CATCH_INTERNAL_ERROR("Attempted to translate active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!");
+ }
+
+ std::string ExceptionTranslatorRegistry::tryTranslators() const {
+ CATCH_INTERNAL_ERROR("Attempted to use exception translators under CATCH_CONFIG_DISABLE_EXCEPTIONS!");
+ }
+#endif
+
+}
+// end catch_exception_translator_registry.cpp
+// start catch_fatal_condition.cpp
+
+#include <algorithm>
+
+#if !defined( CATCH_CONFIG_WINDOWS_SEH ) && !defined( CATCH_CONFIG_POSIX_SIGNALS )
+
+namespace Catch {
+
+ // If neither SEH nor signal handling is required, the handler impls
+ // do not have to do anything, and can be empty.
+ void FatalConditionHandler::engage_platform() {}
+ void FatalConditionHandler::disengage_platform() {}
+ FatalConditionHandler::FatalConditionHandler() = default;
+ FatalConditionHandler::~FatalConditionHandler() = default;
+
+} // end namespace Catch
+
+#endif // !CATCH_CONFIG_WINDOWS_SEH && !CATCH_CONFIG_POSIX_SIGNALS
+
+#if defined( CATCH_CONFIG_WINDOWS_SEH ) && defined( CATCH_CONFIG_POSIX_SIGNALS )
+#error "Inconsistent configuration: Windows' SEH handling and POSIX signals cannot be enabled at the same time"
+#endif // CATCH_CONFIG_WINDOWS_SEH && CATCH_CONFIG_POSIX_SIGNALS
+
+#if defined( CATCH_CONFIG_WINDOWS_SEH ) || defined( CATCH_CONFIG_POSIX_SIGNALS )
+
+namespace {
+ //! Signals fatal error message to the run context
+ void reportFatal( char const * const message ) {
+ Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message );
+ }
+
+ //! Minimal size Catch2 needs for its own fatal error handling.
+ //! Picked anecdotally, so it might not be sufficient on all
+ //! platforms, and for all configurations.
+ constexpr std::size_t minStackSizeForErrors = 32 * 1024;
+} // end unnamed namespace
+
+#endif // CATCH_CONFIG_WINDOWS_SEH || CATCH_CONFIG_POSIX_SIGNALS
+
+#if defined( CATCH_CONFIG_WINDOWS_SEH )
+
+namespace Catch {
+
+ struct SignalDefs { DWORD id; const char* name; };
+
+ // There is no 1-1 mapping between signals and windows exceptions.
+ // Windows can easily distinguish between SO and SigSegV,
+ // but SigInt, SigTerm, etc are handled differently.
+ static SignalDefs signalDefs[] = {
+ { static_cast<DWORD>(EXCEPTION_ILLEGAL_INSTRUCTION), "SIGILL - Illegal instruction signal" },
+ { static_cast<DWORD>(EXCEPTION_STACK_OVERFLOW), "SIGSEGV - Stack overflow" },
+ { static_cast<DWORD>(EXCEPTION_ACCESS_VIOLATION), "SIGSEGV - Segmentation violation signal" },
+ { static_cast<DWORD>(EXCEPTION_INT_DIVIDE_BY_ZERO), "Divide by zero error" },
+ };
+
+ static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
+ for (auto const& def : signalDefs) {
+ if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) {
+ reportFatal(def.name);
+ }
+ }
+ // If its not an exception we care about, pass it along.
+ // This stops us from eating debugger breaks etc.
+ return EXCEPTION_CONTINUE_SEARCH;
+ }
+
+ // Since we do not support multiple instantiations, we put these
+ // into global variables and rely on cleaning them up in outlined
+ // constructors/destructors
+ static PVOID exceptionHandlerHandle = nullptr;
+
+ // For MSVC, we reserve part of the stack memory for handling
+ // memory overflow structured exception.
+ FatalConditionHandler::FatalConditionHandler() {
+ ULONG guaranteeSize = static_cast<ULONG>(minStackSizeForErrors);
+ if (!SetThreadStackGuarantee(&guaranteeSize)) {
+ // We do not want to fully error out, because needing
+ // the stack reserve should be rare enough anyway.
+ Catch::cerr()
+ << "Failed to reserve piece of stack."
+ << " Stack overflows will not be reported successfully.";
+ }
+ }
+
+ // We do not attempt to unset the stack guarantee, because
+ // Windows does not support lowering the stack size guarantee.
+ FatalConditionHandler::~FatalConditionHandler() = default;
+
+ void FatalConditionHandler::engage_platform() {
+ // Register as first handler in current chain
+ exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
+ if (!exceptionHandlerHandle) {
+ CATCH_RUNTIME_ERROR("Could not register vectored exception handler");
+ }
+ }
+
+ void FatalConditionHandler::disengage_platform() {
+ if (!RemoveVectoredExceptionHandler(exceptionHandlerHandle)) {
+ CATCH_RUNTIME_ERROR("Could not unregister vectored exception handler");
+ }
+ exceptionHandlerHandle = nullptr;
+ }
+
+} // end namespace Catch
+
+#endif // CATCH_CONFIG_WINDOWS_SEH
+
+#if defined( CATCH_CONFIG_POSIX_SIGNALS )
+
+#include <signal.h>
+
+namespace Catch {
+
+ struct SignalDefs {
+ int id;
+ const char* name;
+ };
+
+ static SignalDefs signalDefs[] = {
+ { SIGINT, "SIGINT - Terminal interrupt signal" },
+ { SIGILL, "SIGILL - Illegal instruction signal" },
+ { SIGFPE, "SIGFPE - Floating point error signal" },
+ { SIGSEGV, "SIGSEGV - Segmentation violation signal" },
+ { SIGTERM, "SIGTERM - Termination request signal" },
+ { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" }
+ };
+
+// Older GCCs trigger -Wmissing-field-initializers for T foo = {}
+// which is zero initialization, but not explicit. We want to avoid
+// that.
+#if defined(__GNUC__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#endif
+
+ static char* altStackMem = nullptr;
+ static std::size_t altStackSize = 0;
+ static stack_t oldSigStack{};
+ static struct sigaction oldSigActions[sizeof(signalDefs) / sizeof(SignalDefs)]{};
+
+ static void restorePreviousSignalHandlers() {
+ // We set signal handlers back to the previous ones. Hopefully
+ // nobody overwrote them in the meantime, and doesn't expect
+ // their signal handlers to live past ours given that they
+ // installed them after ours..
+ for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
+ sigaction(signalDefs[i].id, &oldSigActions[i], nullptr);
+ }
+ // Return the old stack
+ sigaltstack(&oldSigStack, nullptr);
+ }
+
+ static void handleSignal( int sig ) {
+ char const * name = "<unknown signal>";
+ for (auto const& def : signalDefs) {
+ if (sig == def.id) {
+ name = def.name;
+ break;
+ }
+ }
+ // We need to restore previous signal handlers and let them do
+ // their thing, so that the users can have the debugger break
+ // when a signal is raised, and so on.
+ restorePreviousSignalHandlers();
+ reportFatal( name );
+ raise( sig );
+ }
+
+ FatalConditionHandler::FatalConditionHandler() {
+ assert(!altStackMem && "Cannot initialize POSIX signal handler when one already exists");
+ if (altStackSize == 0) {
+ altStackSize = std::max(static_cast<size_t>(SIGSTKSZ), minStackSizeForErrors);
+ }
+ altStackMem = new char[altStackSize]();
+ }
+
+ FatalConditionHandler::~FatalConditionHandler() {
+ delete[] altStackMem;
+ // We signal that another instance can be constructed by zeroing
+ // out the pointer.
+ altStackMem = nullptr;
+ }
+
+ void FatalConditionHandler::engage_platform() {
+ stack_t sigStack;
+ sigStack.ss_sp = altStackMem;
+ sigStack.ss_size = altStackSize;
+ sigStack.ss_flags = 0;
+ sigaltstack(&sigStack, &oldSigStack);
+ struct sigaction sa = { };
+
+ sa.sa_handler = handleSignal;
+ sa.sa_flags = SA_ONSTACK;
+ for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) {
+ sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
+ }
+ }
+
+#if defined(__GNUC__)
+# pragma GCC diagnostic pop
+#endif
+
+ void FatalConditionHandler::disengage_platform() {
+ restorePreviousSignalHandlers();
+ }
+
+} // end namespace Catch
+
+#endif // CATCH_CONFIG_POSIX_SIGNALS
+// end catch_fatal_condition.cpp
+// start catch_generators.cpp
+
+#include <limits>
+#include <set>
+
+namespace Catch {
+
+IGeneratorTracker::~IGeneratorTracker() {}
+
+const char* GeneratorException::what() const noexcept {
+ return m_msg;
+}
+
+namespace Generators {
+
+ GeneratorUntypedBase::~GeneratorUntypedBase() {}
+
+ auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& {
+ return getResultCapture().acquireGeneratorTracker( generatorName, lineInfo );
+ }
+
+} // namespace Generators
+} // namespace Catch
+// end catch_generators.cpp
+// start catch_interfaces_capture.cpp
+
+namespace Catch {
+ IResultCapture::~IResultCapture() = default;
+}
+// end catch_interfaces_capture.cpp
+// start catch_interfaces_config.cpp
+
+namespace Catch {
+ IConfig::~IConfig() = default;
+}
+// end catch_interfaces_config.cpp
+// start catch_interfaces_exception.cpp
+
+namespace Catch {
+ IExceptionTranslator::~IExceptionTranslator() = default;
+ IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() = default;
+}
+// end catch_interfaces_exception.cpp
+// start catch_interfaces_registry_hub.cpp
+
+namespace Catch {
+ IRegistryHub::~IRegistryHub() = default;
+ IMutableRegistryHub::~IMutableRegistryHub() = default;
+}
+// end catch_interfaces_registry_hub.cpp
+// start catch_interfaces_reporter.cpp
+
+// start catch_reporter_listening.h
+
+namespace Catch {
+
+ class ListeningReporter : public IStreamingReporter {
+ using Reporters = std::vector<IStreamingReporterPtr>;
+ Reporters m_listeners;
+ IStreamingReporterPtr m_reporter = nullptr;
+ ReporterPreferences m_preferences;
+
+ public:
+ ListeningReporter();
+
+ void addListener( IStreamingReporterPtr&& listener );
+ void addReporter( IStreamingReporterPtr&& reporter );
+
+ public: // IStreamingReporter
+
+ ReporterPreferences getPreferences() const override;
+
+ void noMatchingTestCases( std::string const& spec ) override;
+
+ void reportInvalidArguments(std::string const&arg) override;
+
+ static std::set<Verbosity> getSupportedVerbosities();
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ void benchmarkPreparing(std::string const& name) override;
+ void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
+ void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
+ void benchmarkFailed(std::string const&) override;
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ void testRunStarting( TestRunInfo const& testRunInfo ) override;
+ void testGroupStarting( GroupInfo const& groupInfo ) override;
+ void testCaseStarting( TestCaseInfo const& testInfo ) override;
+ void sectionStarting( SectionInfo const& sectionInfo ) override;
+ void assertionStarting( AssertionInfo const& assertionInfo ) override;
+
+ // The return value indicates if the messages buffer should be cleared:
+ bool assertionEnded( AssertionStats const& assertionStats ) override;
+ void sectionEnded( SectionStats const& sectionStats ) override;
+ void testCaseEnded( TestCaseStats const& testCaseStats ) override;
+ void testGroupEnded( TestGroupStats const& testGroupStats ) override;
+ void testRunEnded( TestRunStats const& testRunStats ) override;
+
+ void skipTest( TestCaseInfo const& testInfo ) override;
+ bool isMulti() const override;
+
+ };
+
+} // end namespace Catch
+
+// end catch_reporter_listening.h
+namespace Catch {
+
+ ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig )
+ : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
+
+ ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream )
+ : m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
+
+ std::ostream& ReporterConfig::stream() const { return *m_stream; }
+ IConfigPtr ReporterConfig::fullConfig() const { return m_fullConfig; }
+
+ TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {}
+
+ GroupInfo::GroupInfo( std::string const& _name,
+ std::size_t _groupIndex,
+ std::size_t _groupsCount )
+ : name( _name ),
+ groupIndex( _groupIndex ),
+ groupsCounts( _groupsCount )
+ {}
+
+ AssertionStats::AssertionStats( AssertionResult const& _assertionResult,
+ std::vector<MessageInfo> const& _infoMessages,
+ Totals const& _totals )
+ : assertionResult( _assertionResult ),
+ infoMessages( _infoMessages ),
+ totals( _totals )
+ {
+ assertionResult.m_resultData.lazyExpression.m_transientExpression = _assertionResult.m_resultData.lazyExpression.m_transientExpression;
+
+ if( assertionResult.hasMessage() ) {
+ // Copy message into messages list.
+ // !TBD This should have been done earlier, somewhere
+ MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
+ builder << assertionResult.getMessage();
+ builder.m_info.message = builder.m_stream.str();
+
+ infoMessages.push_back( builder.m_info );
+ }
+ }
+
+ AssertionStats::~AssertionStats() = default;
+
+ SectionStats::SectionStats( SectionInfo const& _sectionInfo,
+ Counts const& _assertions,
+ double _durationInSeconds,
+ bool _missingAssertions )
+ : sectionInfo( _sectionInfo ),
+ assertions( _assertions ),
+ durationInSeconds( _durationInSeconds ),
+ missingAssertions( _missingAssertions )
+ {}
+
+ SectionStats::~SectionStats() = default;
+
+ TestCaseStats::TestCaseStats( TestCaseInfo const& _testInfo,
+ Totals const& _totals,
+ std::string const& _stdOut,
+ std::string const& _stdErr,
+ bool _aborting )
+ : testInfo( _testInfo ),
+ totals( _totals ),
+ stdOut( _stdOut ),
+ stdErr( _stdErr ),
+ aborting( _aborting )
+ {}
+
+ TestCaseStats::~TestCaseStats() = default;
+
+ TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo,
+ Totals const& _totals,
+ bool _aborting )
+ : groupInfo( _groupInfo ),
+ totals( _totals ),
+ aborting( _aborting )
+ {}
+
+ TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo )
+ : groupInfo( _groupInfo ),
+ aborting( false )
+ {}
+
+ TestGroupStats::~TestGroupStats() = default;
+
+ TestRunStats::TestRunStats( TestRunInfo const& _runInfo,
+ Totals const& _totals,
+ bool _aborting )
+ : runInfo( _runInfo ),
+ totals( _totals ),
+ aborting( _aborting )
+ {}
+
+ TestRunStats::~TestRunStats() = default;
+
+ void IStreamingReporter::fatalErrorEncountered( StringRef ) {}
+ bool IStreamingReporter::isMulti() const { return false; }
+
+ IReporterFactory::~IReporterFactory() = default;
+ IReporterRegistry::~IReporterRegistry() = default;
+
+} // end namespace Catch
+// end catch_interfaces_reporter.cpp
+// start catch_interfaces_runner.cpp
+
+namespace Catch {
+ IRunner::~IRunner() = default;
+}
+// end catch_interfaces_runner.cpp
+// start catch_interfaces_testcase.cpp
+
+namespace Catch {
+ ITestInvoker::~ITestInvoker() = default;
+ ITestCaseRegistry::~ITestCaseRegistry() = default;
+}
+// end catch_interfaces_testcase.cpp
+// start catch_leak_detector.cpp
+
+#ifdef CATCH_CONFIG_WINDOWS_CRTDBG
+#include <crtdbg.h>
+
+namespace Catch {
+
+ LeakDetector::LeakDetector() {
+ int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
+ flag |= _CRTDBG_LEAK_CHECK_DF;
+ flag |= _CRTDBG_ALLOC_MEM_DF;
+ _CrtSetDbgFlag(flag);
+ _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
+ _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
+ // Change this to leaking allocation's number to break there
+ _CrtSetBreakAlloc(-1);
+ }
+}
+
+#else
+
+ Catch::LeakDetector::LeakDetector() {}
+
+#endif
+
+Catch::LeakDetector::~LeakDetector() {
+ Catch::cleanUp();
+}
+// end catch_leak_detector.cpp
+// start catch_list.cpp
+
+// start catch_list.h
+
+#include <set>
+
+namespace Catch {
+
+ std::size_t listTests( Config const& config );
+
+ std::size_t listTestsNamesOnly( Config const& config );
+
+ struct TagInfo {
+ void add( std::string const& spelling );
+ std::string all() const;
+
+ std::set<std::string> spellings;
+ std::size_t count = 0;
+ };
+
+ std::size_t listTags( Config const& config );
+
+ std::size_t listReporters();
+
+ Option<std::size_t> list( std::shared_ptr<Config> const& config );
+
+} // end namespace Catch
+
+// end catch_list.h
+// start catch_text.h
+
+namespace Catch {
+ using namespace clara::TextFlow;
+}
+
+// end catch_text.h
+#include <limits>
+#include <algorithm>
+#include <iomanip>
+
+namespace Catch {
+
+ std::size_t listTests( Config const& config ) {
+ TestSpec const& testSpec = config.testSpec();
+ if( config.hasTestFilters() )
+ Catch::cout() << "Matching test cases:\n";
+ else {
+ Catch::cout() << "All available test cases:\n";
+ }
+
+ auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
+ for( auto const& testCaseInfo : matchedTestCases ) {
+ Colour::Code colour = testCaseInfo.isHidden()
+ ? Colour::SecondaryText
+ : Colour::None;
+ Colour colourGuard( colour );
+
+ Catch::cout() << Column( testCaseInfo.name ).initialIndent( 2 ).indent( 4 ) << "\n";
+ if( config.verbosity() >= Verbosity::High ) {
+ Catch::cout() << Column( Catch::Detail::stringify( testCaseInfo.lineInfo ) ).indent(4) << std::endl;
+ std::string description = testCaseInfo.description;
+ if( description.empty() )
+ description = "(NO DESCRIPTION)";
+ Catch::cout() << Column( description ).indent(4) << std::endl;
+ }
+ if( !testCaseInfo.tags.empty() )
+ Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n";
+ }
+
+ if( !config.hasTestFilters() )
+ Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl;
+ else
+ Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl;
+ return matchedTestCases.size();
+ }
+
+ std::size_t listTestsNamesOnly( Config const& config ) {
+ TestSpec const& testSpec = config.testSpec();
+ std::size_t matchedTests = 0;
+ std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
+ for( auto const& testCaseInfo : matchedTestCases ) {
+ matchedTests++;
+ if( startsWith( testCaseInfo.name, '#' ) )
+ Catch::cout() << '"' << testCaseInfo.name << '"';
+ else
+ Catch::cout() << testCaseInfo.name;
+ if ( config.verbosity() >= Verbosity::High )
+ Catch::cout() << "\t@" << testCaseInfo.lineInfo;
+ Catch::cout() << std::endl;
+ }
+ return matchedTests;
+ }
+
+ void TagInfo::add( std::string const& spelling ) {
+ ++count;
+ spellings.insert( spelling );
+ }
+
+ std::string TagInfo::all() const {
+ size_t size = 0;
+ for (auto const& spelling : spellings) {
+ // Add 2 for the brackes
+ size += spelling.size() + 2;
+ }
+
+ std::string out; out.reserve(size);
+ for (auto const& spelling : spellings) {
+ out += '[';
+ out += spelling;
+ out += ']';
+ }
+ return out;
+ }
+
+ std::size_t listTags( Config const& config ) {
+ TestSpec const& testSpec = config.testSpec();
+ if( config.hasTestFilters() )
+ Catch::cout() << "Tags for matching test cases:\n";
+ else {
+ Catch::cout() << "All available tags:\n";
+ }
+
+ std::map<std::string, TagInfo> tagCounts;
+
+ std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
+ for( auto const& testCase : matchedTestCases ) {
+ for( auto const& tagName : testCase.getTestCaseInfo().tags ) {
+ std::string lcaseTagName = toLower( tagName );
+ auto countIt = tagCounts.find( lcaseTagName );
+ if( countIt == tagCounts.end() )
+ countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
+ countIt->second.add( tagName );
+ }
+ }
+
+ for( auto const& tagCount : tagCounts ) {
+ ReusableStringStream rss;
+ rss << " " << std::setw(2) << tagCount.second.count << " ";
+ auto str = rss.str();
+ auto wrapper = Column( tagCount.second.all() )
+ .initialIndent( 0 )
+ .indent( str.size() )
+ .width( CATCH_CONFIG_CONSOLE_WIDTH-10 );
+ Catch::cout() << str << wrapper << '\n';
+ }
+ Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
+ return tagCounts.size();
+ }
+
+ std::size_t listReporters() {
+ Catch::cout() << "Available reporters:\n";
+ IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
+ std::size_t maxNameLen = 0;
+ for( auto const& factoryKvp : factories )
+ maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() );
+
+ for( auto const& factoryKvp : factories ) {
+ Catch::cout()
+ << Column( factoryKvp.first + ":" )
+ .indent(2)
+ .width( 5+maxNameLen )
+ + Column( factoryKvp.second->getDescription() )
+ .initialIndent(0)
+ .indent(2)
+ .width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 )
+ << "\n";
+ }
+ Catch::cout() << std::endl;
+ return factories.size();
+ }
+
+ Option<std::size_t> list( std::shared_ptr<Config> const& config ) {
+ Option<std::size_t> listedCount;
+ getCurrentMutableContext().setConfig( config );
+ if( config->listTests() )
+ listedCount = listedCount.valueOr(0) + listTests( *config );
+ if( config->listTestNamesOnly() )
+ listedCount = listedCount.valueOr(0) + listTestsNamesOnly( *config );
+ if( config->listTags() )
+ listedCount = listedCount.valueOr(0) + listTags( *config );
+ if( config->listReporters() )
+ listedCount = listedCount.valueOr(0) + listReporters();
+ return listedCount;
+ }
+
+} // end namespace Catch
+// end catch_list.cpp
+// start catch_matchers.cpp
+
+namespace Catch {
+namespace Matchers {
+ namespace Impl {
+
+ std::string MatcherUntypedBase::toString() const {
+ if( m_cachedToString.empty() )
+ m_cachedToString = describe();
+ return m_cachedToString;
+ }
+
+ MatcherUntypedBase::~MatcherUntypedBase() = default;
+
+ } // namespace Impl
+} // namespace Matchers
+
+using namespace Matchers;
+using Matchers::Impl::MatcherBase;
+
+} // namespace Catch
+// end catch_matchers.cpp
+// start catch_matchers_exception.cpp
+
+namespace Catch {
+namespace Matchers {
+namespace Exception {
+
+bool ExceptionMessageMatcher::match(std::exception const& ex) const {
+ return ex.what() == m_message;
+}
+
+std::string ExceptionMessageMatcher::describe() const {
+ return "exception message matches \"" + m_message + "\"";
+}
+
+}
+Exception::ExceptionMessageMatcher Message(std::string const& message) {
+ return Exception::ExceptionMessageMatcher(message);
+}
+
+// namespace Exception
+} // namespace Matchers
+} // namespace Catch
+// end catch_matchers_exception.cpp
+// start catch_matchers_floating.cpp
+
+// start catch_polyfills.hpp
+
+namespace Catch {
+ bool isnan(float f);
+ bool isnan(double d);
+}
+
+// end catch_polyfills.hpp
+// start catch_to_string.hpp
+
+#include <string>
+
+namespace Catch {
+ template <typename T>
+ std::string to_string(T const& t) {
+#if defined(CATCH_CONFIG_CPP11_TO_STRING)
+ return std::to_string(t);
+#else
+ ReusableStringStream rss;
+ rss << t;
+ return rss.str();
+#endif
+ }
+} // end namespace Catch
+
+// end catch_to_string.hpp
+#include <algorithm>
+#include <cmath>
+#include <cstdlib>
+#include <cstdint>
+#include <cstring>
+#include <sstream>
+#include <type_traits>
+#include <iomanip>
+#include <limits>
+
+namespace Catch {
+namespace {
+
+ int32_t convert(float f) {
+ static_assert(sizeof(float) == sizeof(int32_t), "Important ULP matcher assumption violated");
+ int32_t i;
+ std::memcpy(&i, &f, sizeof(f));
+ return i;
+ }
+
+ int64_t convert(double d) {
+ static_assert(sizeof(double) == sizeof(int64_t), "Important ULP matcher assumption violated");
+ int64_t i;
+ std::memcpy(&i, &d, sizeof(d));
+ return i;
+ }
+
+ template <typename FP>
+ bool almostEqualUlps(FP lhs, FP rhs, uint64_t maxUlpDiff) {
+ // Comparison with NaN should always be false.
+ // This way we can rule it out before getting into the ugly details
+ if (Catch::isnan(lhs) || Catch::isnan(rhs)) {
+ return false;
+ }
+
+ auto lc = convert(lhs);
+ auto rc = convert(rhs);
+
+ if ((lc < 0) != (rc < 0)) {
+ // Potentially we can have +0 and -0
+ return lhs == rhs;
+ }
+
+ // static cast as a workaround for IBM XLC
+ auto ulpDiff = std::abs(static_cast<FP>(lc - rc));
+ return static_cast<uint64_t>(ulpDiff) <= maxUlpDiff;
+ }
+
+#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
+
+ float nextafter(float x, float y) {
+ return ::nextafterf(x, y);
+ }
+
+ double nextafter(double x, double y) {
+ return ::nextafter(x, y);
+ }
+
+#endif // ^^^ CATCH_CONFIG_GLOBAL_NEXTAFTER ^^^
+
+template <typename FP>
+FP step(FP start, FP direction, uint64_t steps) {
+ for (uint64_t i = 0; i < steps; ++i) {
+#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
+ start = Catch::nextafter(start, direction);
+#else
+ start = std::nextafter(start, direction);
+#endif
+ }
+ return start;
+}
+
+// Performs equivalent check of std::fabs(lhs - rhs) <= margin
+// But without the subtraction to allow for INFINITY in comparison
+bool marginComparison(double lhs, double rhs, double margin) {
+ return (lhs + margin >= rhs) && (rhs + margin >= lhs);
+}
+
+template <typename FloatingPoint>
+void write(std::ostream& out, FloatingPoint num) {
+ out << std::scientific
+ << std::setprecision(std::numeric_limits<FloatingPoint>::max_digits10 - 1)
+ << num;
+}
+
+} // end anonymous namespace
+
+namespace Matchers {
+namespace Floating {
+
+ enum class FloatingPointKind : uint8_t {
+ Float,
+ Double
+ };
+
+ WithinAbsMatcher::WithinAbsMatcher(double target, double margin)
+ :m_target{ target }, m_margin{ margin } {
+ CATCH_ENFORCE(margin >= 0, "Invalid margin: " << margin << '.'
+ << " Margin has to be non-negative.");
+ }
+
+ // Performs equivalent check of std::fabs(lhs - rhs) <= margin
+ // But without the subtraction to allow for INFINITY in comparison
+ bool WithinAbsMatcher::match(double const& matchee) const {
+ return (matchee + m_margin >= m_target) && (m_target + m_margin >= matchee);
+ }
+
+ std::string WithinAbsMatcher::describe() const {
+ return "is within " + ::Catch::Detail::stringify(m_margin) + " of " + ::Catch::Detail::stringify(m_target);
+ }
+
+ WithinUlpsMatcher::WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType)
+ :m_target{ target }, m_ulps{ ulps }, m_type{ baseType } {
+ CATCH_ENFORCE(m_type == FloatingPointKind::Double
+ || m_ulps < (std::numeric_limits<uint32_t>::max)(),
+ "Provided ULP is impossibly large for a float comparison.");
+ }
+
+#if defined(__clang__)
+#pragma clang diagnostic push
+// Clang <3.5 reports on the default branch in the switch below
+#pragma clang diagnostic ignored "-Wunreachable-code"
+#endif
+
+ bool WithinUlpsMatcher::match(double const& matchee) const {
+ switch (m_type) {
+ case FloatingPointKind::Float:
+ return almostEqualUlps<float>(static_cast<float>(matchee), static_cast<float>(m_target), m_ulps);
+ case FloatingPointKind::Double:
+ return almostEqualUlps<double>(matchee, m_target, m_ulps);
+ default:
+ CATCH_INTERNAL_ERROR( "Unknown FloatingPointKind value" );
+ }
+ }
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
+ std::string WithinUlpsMatcher::describe() const {
+ std::stringstream ret;
+
+ ret << "is within " << m_ulps << " ULPs of ";
+
+ if (m_type == FloatingPointKind::Float) {
+ write(ret, static_cast<float>(m_target));
+ ret << 'f';
+ } else {
+ write(ret, m_target);
+ }
+
+ ret << " ([";
+ if (m_type == FloatingPointKind::Double) {
+ write(ret, step(m_target, static_cast<double>(-INFINITY), m_ulps));
+ ret << ", ";
+ write(ret, step(m_target, static_cast<double>( INFINITY), m_ulps));
+ } else {
+ // We have to cast INFINITY to float because of MinGW, see #1782
+ write(ret, step(static_cast<float>(m_target), static_cast<float>(-INFINITY), m_ulps));
+ ret << ", ";
+ write(ret, step(static_cast<float>(m_target), static_cast<float>( INFINITY), m_ulps));
+ }
+ ret << "])";
+
+ return ret.str();
+ }
+
+ WithinRelMatcher::WithinRelMatcher(double target, double epsilon):
+ m_target(target),
+ m_epsilon(epsilon){
+ CATCH_ENFORCE(m_epsilon >= 0., "Relative comparison with epsilon < 0 does not make sense.");
+ CATCH_ENFORCE(m_epsilon < 1., "Relative comparison with epsilon >= 1 does not make sense.");
+ }
+
+ bool WithinRelMatcher::match(double const& matchee) const {
+ const auto relMargin = m_epsilon * (std::max)(std::fabs(matchee), std::fabs(m_target));
+ return marginComparison(matchee, m_target,
+ std::isinf(relMargin)? 0 : relMargin);
+ }
+
+ std::string WithinRelMatcher::describe() const {
+ Catch::ReusableStringStream sstr;
+ sstr << "and " << m_target << " are within " << m_epsilon * 100. << "% of each other";
+ return sstr.str();
+ }
+
+}// namespace Floating
+
+Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff) {
+ return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Double);
+}
+
+Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff) {
+ return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Float);
+}
+
+Floating::WithinAbsMatcher WithinAbs(double target, double margin) {
+ return Floating::WithinAbsMatcher(target, margin);
+}
+
+Floating::WithinRelMatcher WithinRel(double target, double eps) {
+ return Floating::WithinRelMatcher(target, eps);
+}
+
+Floating::WithinRelMatcher WithinRel(double target) {
+ return Floating::WithinRelMatcher(target, std::numeric_limits<double>::epsilon() * 100);
+}
+
+Floating::WithinRelMatcher WithinRel(float target, float eps) {
+ return Floating::WithinRelMatcher(target, eps);
+}
+
+Floating::WithinRelMatcher WithinRel(float target) {
+ return Floating::WithinRelMatcher(target, std::numeric_limits<float>::epsilon() * 100);
+}
+
+} // namespace Matchers
+} // namespace Catch
+// end catch_matchers_floating.cpp
+// start catch_matchers_generic.cpp
+
+std::string Catch::Matchers::Generic::Detail::finalizeDescription(const std::string& desc) {
+ if (desc.empty()) {
+ return "matches undescribed predicate";
+ } else {
+ return "matches predicate: \"" + desc + '"';
+ }
+}
+// end catch_matchers_generic.cpp
+// start catch_matchers_string.cpp
+
+#include <regex>
+
+namespace Catch {
+namespace Matchers {
+
+ namespace StdString {
+
+ CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity )
+ : m_caseSensitivity( caseSensitivity ),
+ m_str( adjustString( str ) )
+ {}
+ std::string CasedString::adjustString( std::string const& str ) const {
+ return m_caseSensitivity == CaseSensitive::No
+ ? toLower( str )
+ : str;
+ }
+ std::string CasedString::caseSensitivitySuffix() const {
+ return m_caseSensitivity == CaseSensitive::No
+ ? " (case insensitive)"
+ : std::string();
+ }
+
+ StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator )
+ : m_comparator( comparator ),
+ m_operation( operation ) {
+ }
+
+ std::string StringMatcherBase::describe() const {
+ std::string description;
+ description.reserve(5 + m_operation.size() + m_comparator.m_str.size() +
+ m_comparator.caseSensitivitySuffix().size());
+ description += m_operation;
+ description += ": \"";
+ description += m_comparator.m_str;
+ description += "\"";
+ description += m_comparator.caseSensitivitySuffix();
+ return description;
+ }
+
+ EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {}
+
+ bool EqualsMatcher::match( std::string const& source ) const {
+ return m_comparator.adjustString( source ) == m_comparator.m_str;
+ }
+
+ ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {}
+
+ bool ContainsMatcher::match( std::string const& source ) const {
+ return contains( m_comparator.adjustString( source ), m_comparator.m_str );
+ }
+
+ StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {}
+
+ bool StartsWithMatcher::match( std::string const& source ) const {
+ return startsWith( m_comparator.adjustString( source ), m_comparator.m_str );
+ }
+
+ EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {}
+
+ bool EndsWithMatcher::match( std::string const& source ) const {
+ return endsWith( m_comparator.adjustString( source ), m_comparator.m_str );
+ }
+
+ RegexMatcher::RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {}
+
+ bool RegexMatcher::match(std::string const& matchee) const {
+ auto flags = std::regex::ECMAScript; // ECMAScript is the default syntax option anyway
+ if (m_caseSensitivity == CaseSensitive::Choice::No) {
+ flags |= std::regex::icase;
+ }
+ auto reg = std::regex(m_regex, flags);
+ return std::regex_match(matchee, reg);
+ }
+
+ std::string RegexMatcher::describe() const {
+ return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Choice::Yes)? " case sensitively" : " case insensitively");
+ }
+
+ } // namespace StdString
+
+ StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
+ return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) );
+ }
+ StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
+ return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) );
+ }
+ StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
+ return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) );
+ }
+ StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
+ return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) );
+ }
+
+ StdString::RegexMatcher Matches(std::string const& regex, CaseSensitive::Choice caseSensitivity) {
+ return StdString::RegexMatcher(regex, caseSensitivity);
+ }
+
+} // namespace Matchers
+} // namespace Catch
+// end catch_matchers_string.cpp
+// start catch_message.cpp
+
+// start catch_uncaught_exceptions.h
+
+namespace Catch {
+ bool uncaught_exceptions();
+} // end namespace Catch
+
+// end catch_uncaught_exceptions.h
+#include <cassert>
+#include <stack>
+
+namespace Catch {
+
+ MessageInfo::MessageInfo( StringRef const& _macroName,
+ SourceLineInfo const& _lineInfo,
+ ResultWas::OfType _type )
+ : macroName( _macroName ),
+ lineInfo( _lineInfo ),
+ type( _type ),
+ sequence( ++globalCount )
+ {}
+
+ bool MessageInfo::operator==( MessageInfo const& other ) const {
+ return sequence == other.sequence;
+ }
+
+ bool MessageInfo::operator<( MessageInfo const& other ) const {
+ return sequence < other.sequence;
+ }
+
+ // This may need protecting if threading support is added
+ unsigned int MessageInfo::globalCount = 0;
+
+ ////////////////////////////////////////////////////////////////////////////
+
+ Catch::MessageBuilder::MessageBuilder( StringRef const& macroName,
+ SourceLineInfo const& lineInfo,
+ ResultWas::OfType type )
+ :m_info(macroName, lineInfo, type) {}
+
+ ////////////////////////////////////////////////////////////////////////////
+
+ ScopedMessage::ScopedMessage( MessageBuilder const& builder )
+ : m_info( builder.m_info ), m_moved()
+ {
+ m_info.message = builder.m_stream.str();
+ getResultCapture().pushScopedMessage( m_info );
+ }
+
+ ScopedMessage::ScopedMessage( ScopedMessage&& old )
+ : m_info( old.m_info ), m_moved()
+ {
+ old.m_moved = true;
+ }
+
+ ScopedMessage::~ScopedMessage() {
+ if ( !uncaught_exceptions() && !m_moved ){
+ getResultCapture().popScopedMessage(m_info);
+ }
+ }
+
+ Capturer::Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ) {
+ auto trimmed = [&] (size_t start, size_t end) {
+ while (names[start] == ',' || isspace(static_cast<unsigned char>(names[start]))) {
+ ++start;
+ }
+ while (names[end] == ',' || isspace(static_cast<unsigned char>(names[end]))) {
+ --end;
+ }
+ return names.substr(start, end - start + 1);
+ };
+ auto skipq = [&] (size_t start, char quote) {
+ for (auto i = start + 1; i < names.size() ; ++i) {
+ if (names[i] == quote)
+ return i;
+ if (names[i] == '\\')
+ ++i;
+ }
+ CATCH_INTERNAL_ERROR("CAPTURE parsing encountered unmatched quote");
+ };
+
+ size_t start = 0;
+ std::stack<char> openings;
+ for (size_t pos = 0; pos < names.size(); ++pos) {
+ char c = names[pos];
+ switch (c) {
+ case '[':
+ case '{':
+ case '(':
+ // It is basically impossible to disambiguate between
+ // comparison and start of template args in this context
+// case '<':
+ openings.push(c);
+ break;
+ case ']':
+ case '}':
+ case ')':
+// case '>':
+ openings.pop();
+ break;
+ case '"':
+ case '\'':
+ pos = skipq(pos, c);
+ break;
+ case ',':
+ if (start != pos && openings.empty()) {
+ m_messages.emplace_back(macroName, lineInfo, resultType);
+ m_messages.back().message = static_cast<std::string>(trimmed(start, pos));
+ m_messages.back().message += " := ";
+ start = pos;
+ }
+ }
+ }
+ assert(openings.empty() && "Mismatched openings");
+ m_messages.emplace_back(macroName, lineInfo, resultType);
+ m_messages.back().message = static_cast<std::string>(trimmed(start, names.size() - 1));
+ m_messages.back().message += " := ";
+ }
+ Capturer::~Capturer() {
+ if ( !uncaught_exceptions() ){
+ assert( m_captured == m_messages.size() );
+ for( size_t i = 0; i < m_captured; ++i )
+ m_resultCapture.popScopedMessage( m_messages[i] );
+ }
+ }
+
+ void Capturer::captureValue( size_t index, std::string const& value ) {
+ assert( index < m_messages.size() );
+ m_messages[index].message += value;
+ m_resultCapture.pushScopedMessage( m_messages[index] );
+ m_captured++;
+ }
+
+} // end namespace Catch
+// end catch_message.cpp
+// start catch_output_redirect.cpp
+
+// start catch_output_redirect.h
+#ifndef TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H
+#define TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H
+
+#include <cstdio>
+#include <iosfwd>
+#include <string>
+
+namespace Catch {
+
+ class RedirectedStream {
+ std::ostream& m_originalStream;
+ std::ostream& m_redirectionStream;
+ std::streambuf* m_prevBuf;
+
+ public:
+ RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream );
+ ~RedirectedStream();
+ };
+
+ class RedirectedStdOut {
+ ReusableStringStream m_rss;
+ RedirectedStream m_cout;
+ public:
+ RedirectedStdOut();
+ auto str() const -> std::string;
+ };
+
+ // StdErr has two constituent streams in C++, std::cerr and std::clog
+ // This means that we need to redirect 2 streams into 1 to keep proper
+ // order of writes
+ class RedirectedStdErr {
+ ReusableStringStream m_rss;
+ RedirectedStream m_cerr;
+ RedirectedStream m_clog;
+ public:
+ RedirectedStdErr();
+ auto str() const -> std::string;
+ };
+
+ class RedirectedStreams {
+ public:
+ RedirectedStreams(RedirectedStreams const&) = delete;
+ RedirectedStreams& operator=(RedirectedStreams const&) = delete;
+ RedirectedStreams(RedirectedStreams&&) = delete;
+ RedirectedStreams& operator=(RedirectedStreams&&) = delete;
+
+ RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr);
+ ~RedirectedStreams();
+ private:
+ std::string& m_redirectedCout;
+ std::string& m_redirectedCerr;
+ RedirectedStdOut m_redirectedStdOut;
+ RedirectedStdErr m_redirectedStdErr;
+ };
+
+#if defined(CATCH_CONFIG_NEW_CAPTURE)
+
+ // Windows's implementation of std::tmpfile is terrible (it tries
+ // to create a file inside system folder, thus requiring elevated
+ // privileges for the binary), so we have to use tmpnam(_s) and
+ // create the file ourselves there.
+ class TempFile {
+ public:
+ TempFile(TempFile const&) = delete;
+ TempFile& operator=(TempFile const&) = delete;
+ TempFile(TempFile&&) = delete;
+ TempFile& operator=(TempFile&&) = delete;
+
+ TempFile();
+ ~TempFile();
+
+ std::FILE* getFile();
+ std::string getContents();
+
+ private:
+ std::FILE* m_file = nullptr;
+ #if defined(_MSC_VER)
+ char m_buffer[L_tmpnam] = { 0 };
+ #endif
+ };
+
+ class OutputRedirect {
+ public:
+ OutputRedirect(OutputRedirect const&) = delete;
+ OutputRedirect& operator=(OutputRedirect const&) = delete;
+ OutputRedirect(OutputRedirect&&) = delete;
+ OutputRedirect& operator=(OutputRedirect&&) = delete;
+
+ OutputRedirect(std::string& stdout_dest, std::string& stderr_dest);
+ ~OutputRedirect();
+
+ private:
+ int m_originalStdout = -1;
+ int m_originalStderr = -1;
+ TempFile m_stdoutFile;
+ TempFile m_stderrFile;
+ std::string& m_stdoutDest;
+ std::string& m_stderrDest;
+ };
+
+#endif
+
+} // end namespace Catch
+
+#endif // TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H
+// end catch_output_redirect.h
+#include <cstdio>
+#include <cstring>
+#include <fstream>
+#include <sstream>
+#include <stdexcept>
+
+#if defined(CATCH_CONFIG_NEW_CAPTURE)
+ #if defined(_MSC_VER)
+ #include <io.h> //_dup and _dup2
+ #define dup _dup
+ #define dup2 _dup2
+ #define fileno _fileno
+ #else
+ #include <unistd.h> // dup and dup2
+ #endif
+#endif
+
+namespace Catch {
+
+ RedirectedStream::RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream )
+ : m_originalStream( originalStream ),
+ m_redirectionStream( redirectionStream ),
+ m_prevBuf( m_originalStream.rdbuf() )
+ {
+ m_originalStream.rdbuf( m_redirectionStream.rdbuf() );
+ }
+
+ RedirectedStream::~RedirectedStream() {
+ m_originalStream.rdbuf( m_prevBuf );
+ }
+
+ RedirectedStdOut::RedirectedStdOut() : m_cout( Catch::cout(), m_rss.get() ) {}
+ auto RedirectedStdOut::str() const -> std::string { return m_rss.str(); }
+
+ RedirectedStdErr::RedirectedStdErr()
+ : m_cerr( Catch::cerr(), m_rss.get() ),
+ m_clog( Catch::clog(), m_rss.get() )
+ {}
+ auto RedirectedStdErr::str() const -> std::string { return m_rss.str(); }
+
+ RedirectedStreams::RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr)
+ : m_redirectedCout(redirectedCout),
+ m_redirectedCerr(redirectedCerr)
+ {}
+
+ RedirectedStreams::~RedirectedStreams() {
+ m_redirectedCout += m_redirectedStdOut.str();
+ m_redirectedCerr += m_redirectedStdErr.str();
+ }
+
+#if defined(CATCH_CONFIG_NEW_CAPTURE)
+
+#if defined(_MSC_VER)
+ TempFile::TempFile() {
+ if (tmpnam_s(m_buffer)) {
+ CATCH_RUNTIME_ERROR("Could not get a temp filename");
+ }
+ if (fopen_s(&m_file, m_buffer, "w+")) {
+ char buffer[100];
+ if (strerror_s(buffer, errno)) {
+ CATCH_RUNTIME_ERROR("Could not translate errno to a string");
+ }
+ CATCH_RUNTIME_ERROR("Could not open the temp file: '" << m_buffer << "' because: " << buffer);
+ }
+ }
+#else
+ TempFile::TempFile() {
+ m_file = std::tmpfile();
+ if (!m_file) {
+ CATCH_RUNTIME_ERROR("Could not create a temp file.");
+ }
+ }
+
+#endif
+
+ TempFile::~TempFile() {
+ // TBD: What to do about errors here?
+ std::fclose(m_file);
+ // We manually create the file on Windows only, on Linux
+ // it will be autodeleted
+#if defined(_MSC_VER)
+ std::remove(m_buffer);
+#endif
+ }
+
+ FILE* TempFile::getFile() {
+ return m_file;
+ }
+
+ std::string TempFile::getContents() {
+ std::stringstream sstr;
+ char buffer[100] = {};
+ std::rewind(m_file);
+ while (std::fgets(buffer, sizeof(buffer), m_file)) {
+ sstr << buffer;
+ }
+ return sstr.str();
+ }
+
+ OutputRedirect::OutputRedirect(std::string& stdout_dest, std::string& stderr_dest) :
+ m_originalStdout(dup(1)),
+ m_originalStderr(dup(2)),
+ m_stdoutDest(stdout_dest),
+ m_stderrDest(stderr_dest) {
+ dup2(fileno(m_stdoutFile.getFile()), 1);
+ dup2(fileno(m_stderrFile.getFile()), 2);
+ }
+
+ OutputRedirect::~OutputRedirect() {
+ Catch::cout() << std::flush;
+ fflush(stdout);
+ // Since we support overriding these streams, we flush cerr
+ // even though std::cerr is unbuffered
+ Catch::cerr() << std::flush;
+ Catch::clog() << std::flush;
+ fflush(stderr);
+
+ dup2(m_originalStdout, 1);
+ dup2(m_originalStderr, 2);
+
+ m_stdoutDest += m_stdoutFile.getContents();
+ m_stderrDest += m_stderrFile.getContents();
+ }
+
+#endif // CATCH_CONFIG_NEW_CAPTURE
+
+} // namespace Catch
+
+#if defined(CATCH_CONFIG_NEW_CAPTURE)
+ #if defined(_MSC_VER)
+ #undef dup
+ #undef dup2
+ #undef fileno
+ #endif
+#endif
+// end catch_output_redirect.cpp
+// start catch_polyfills.cpp
+
+#include <cmath>
+
+namespace Catch {
+
+#if !defined(CATCH_CONFIG_POLYFILL_ISNAN)
+ bool isnan(float f) {
+ return std::isnan(f);
+ }
+ bool isnan(double d) {
+ return std::isnan(d);
+ }
+#else
+ // For now we only use this for embarcadero
+ bool isnan(float f) {
+ return std::_isnan(f);
+ }
+ bool isnan(double d) {
+ return std::_isnan(d);
+ }
+#endif
+
+} // end namespace Catch
+// end catch_polyfills.cpp
+// start catch_random_number_generator.cpp
+
+namespace Catch {
+
+namespace {
+
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable:4146) // we negate uint32 during the rotate
+#endif
+ // Safe rotr implementation thanks to John Regehr
+ uint32_t rotate_right(uint32_t val, uint32_t count) {
+ const uint32_t mask = 31;
+ count &= mask;
+ return (val >> count) | (val << (-count & mask));
+ }
+
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
+
+}
+
+ SimplePcg32::SimplePcg32(result_type seed_) {
+ seed(seed_);
+ }
+
+ void SimplePcg32::seed(result_type seed_) {
+ m_state = 0;
+ (*this)();
+ m_state += seed_;
+ (*this)();
+ }
+
+ void SimplePcg32::discard(uint64_t skip) {
+ // We could implement this to run in O(log n) steps, but this
+ // should suffice for our use case.
+ for (uint64_t s = 0; s < skip; ++s) {
+ static_cast<void>((*this)());
+ }
+ }
+
+ SimplePcg32::result_type SimplePcg32::operator()() {
+ // prepare the output value
+ const uint32_t xorshifted = static_cast<uint32_t>(((m_state >> 18u) ^ m_state) >> 27u);
+ const auto output = rotate_right(xorshifted, m_state >> 59u);
+
+ // advance state
+ m_state = m_state * 6364136223846793005ULL + s_inc;
+
+ return output;
+ }
+
+ bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs) {
+ return lhs.m_state == rhs.m_state;
+ }
+
+ bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs) {
+ return lhs.m_state != rhs.m_state;
+ }
+}
+// end catch_random_number_generator.cpp
+// start catch_registry_hub.cpp
+
+// start catch_test_case_registry_impl.h
+
+#include <vector>
+#include <set>
+#include <algorithm>
+#include <ios>
+
+namespace Catch {
+
+ class TestCase;
+ struct IConfig;
+
+ std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases );
+
+ bool isThrowSafe( TestCase const& testCase, IConfig const& config );
+ bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
+
+ void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions );
+
+ std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
+ std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
+
+ class TestRegistry : public ITestCaseRegistry {
+ public:
+ virtual ~TestRegistry() = default;
+
+ virtual void registerTest( TestCase const& testCase );
+
+ std::vector<TestCase> const& getAllTests() const override;
+ std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const override;
+
+ private:
+ std::vector<TestCase> m_functions;
+ mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder;
+ mutable std::vector<TestCase> m_sortedFunctions;
+ std::size_t m_unnamedCount = 0;
+ std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ class TestInvokerAsFunction : public ITestInvoker {
+ void(*m_testAsFunction)();
+ public:
+ TestInvokerAsFunction( void(*testAsFunction)() ) noexcept;
+
+ void invoke() const override;
+ };
+
+ std::string extractClassName( StringRef const& classOrQualifiedMethodName );
+
+ ///////////////////////////////////////////////////////////////////////////
+
+} // end namespace Catch
+
+// end catch_test_case_registry_impl.h
+// start catch_reporter_registry.h
+
+#include <map>
+
+namespace Catch {
+
+ class ReporterRegistry : public IReporterRegistry {
+
+ public:
+
+ ~ReporterRegistry() override;
+
+ IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override;
+
+ void registerReporter( std::string const& name, IReporterFactoryPtr const& factory );
+ void registerListener( IReporterFactoryPtr const& factory );
+
+ FactoryMap const& getFactories() const override;
+ Listeners const& getListeners() const override;
+
+ private:
+ FactoryMap m_factories;
+ Listeners m_listeners;
+ };
+}
+
+// end catch_reporter_registry.h
+// start catch_tag_alias_registry.h
+
+// start catch_tag_alias.h
+
+#include <string>
+
+namespace Catch {
+
+ struct TagAlias {
+ TagAlias(std::string const& _tag, SourceLineInfo _lineInfo);
+
+ std::string tag;
+ SourceLineInfo lineInfo;
+ };
+
+} // end namespace Catch
+
+// end catch_tag_alias.h
+#include <map>
+
+namespace Catch {
+
+ class TagAliasRegistry : public ITagAliasRegistry {
+ public:
+ ~TagAliasRegistry() override;
+ TagAlias const* find( std::string const& alias ) const override;
+ std::string expandAliases( std::string const& unexpandedTestSpec ) const override;
+ void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo );
+
+ private:
+ std::map<std::string, TagAlias> m_registry;
+ };
+
+} // end namespace Catch
+
+// end catch_tag_alias_registry.h
+// start catch_startup_exception_registry.h
+
+#include <vector>
+#include <exception>
+
+namespace Catch {
+
+ class StartupExceptionRegistry {
+#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+ public:
+ void add(std::exception_ptr const& exception) noexcept;
+ std::vector<std::exception_ptr> const& getExceptions() const noexcept;
+ private:
+ std::vector<std::exception_ptr> m_exceptions;
+#endif
+ };
+
+} // end namespace Catch
+
+// end catch_startup_exception_registry.h
+// start catch_singletons.hpp
+
+namespace Catch {
+
+ struct ISingleton {
+ virtual ~ISingleton();
+ };
+
+ void addSingleton( ISingleton* singleton );
+ void cleanupSingletons();
+
+ template<typename SingletonImplT, typename InterfaceT = SingletonImplT, typename MutableInterfaceT = InterfaceT>
+ class Singleton : SingletonImplT, public ISingleton {
+
+ static auto getInternal() -> Singleton* {
+ static Singleton* s_instance = nullptr;
+ if( !s_instance ) {
+ s_instance = new Singleton;
+ addSingleton( s_instance );
+ }
+ return s_instance;
+ }
+
+ public:
+ static auto get() -> InterfaceT const& {
+ return *getInternal();
+ }
+ static auto getMutable() -> MutableInterfaceT& {
+ return *getInternal();
+ }
+ };
+
+} // namespace Catch
+
+// end catch_singletons.hpp
+namespace Catch {
+
+ namespace {
+
+ class RegistryHub : public IRegistryHub, public IMutableRegistryHub,
+ private NonCopyable {
+
+ public: // IRegistryHub
+ RegistryHub() = default;
+ IReporterRegistry const& getReporterRegistry() const override {
+ return m_reporterRegistry;
+ }
+ ITestCaseRegistry const& getTestCaseRegistry() const override {
+ return m_testCaseRegistry;
+ }
+ IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const override {
+ return m_exceptionTranslatorRegistry;
+ }
+ ITagAliasRegistry const& getTagAliasRegistry() const override {
+ return m_tagAliasRegistry;
+ }
+ StartupExceptionRegistry const& getStartupExceptionRegistry() const override {
+ return m_exceptionRegistry;
+ }
+
+ public: // IMutableRegistryHub
+ void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override {
+ m_reporterRegistry.registerReporter( name, factory );
+ }
+ void registerListener( IReporterFactoryPtr const& factory ) override {
+ m_reporterRegistry.registerListener( factory );
+ }
+ void registerTest( TestCase const& testInfo ) override {
+ m_testCaseRegistry.registerTest( testInfo );
+ }
+ void registerTranslator( const IExceptionTranslator* translator ) override {
+ m_exceptionTranslatorRegistry.registerTranslator( translator );
+ }
+ void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
+ m_tagAliasRegistry.add( alias, tag, lineInfo );
+ }
+ void registerStartupException() noexcept override {
+#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+ m_exceptionRegistry.add(std::current_exception());
+#else
+ CATCH_INTERNAL_ERROR("Attempted to register active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!");
+#endif
+ }
+ IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() override {
+ return m_enumValuesRegistry;
+ }
+
+ private:
+ TestRegistry m_testCaseRegistry;
+ ReporterRegistry m_reporterRegistry;
+ ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
+ TagAliasRegistry m_tagAliasRegistry;
+ StartupExceptionRegistry m_exceptionRegistry;
+ Detail::EnumValuesRegistry m_enumValuesRegistry;
+ };
+ }
+
+ using RegistryHubSingleton = Singleton<RegistryHub, IRegistryHub, IMutableRegistryHub>;
+
+ IRegistryHub const& getRegistryHub() {
+ return RegistryHubSingleton::get();
+ }
+ IMutableRegistryHub& getMutableRegistryHub() {
+ return RegistryHubSingleton::getMutable();
+ }
+ void cleanUp() {
+ cleanupSingletons();
+ cleanUpContext();
+ }
+ std::string translateActiveException() {
+ return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
+ }
+
+} // end namespace Catch
+// end catch_registry_hub.cpp
+// start catch_reporter_registry.cpp
+
+namespace Catch {
+
+ ReporterRegistry::~ReporterRegistry() = default;
+
+ IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const {
+ auto it = m_factories.find( name );
+ if( it == m_factories.end() )
+ return nullptr;
+ return it->second->create( ReporterConfig( config ) );
+ }
+
+ void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) {
+ m_factories.emplace(name, factory);
+ }
+ void ReporterRegistry::registerListener( IReporterFactoryPtr const& factory ) {
+ m_listeners.push_back( factory );
+ }
+
+ IReporterRegistry::FactoryMap const& ReporterRegistry::getFactories() const {
+ return m_factories;
+ }
+ IReporterRegistry::Listeners const& ReporterRegistry::getListeners() const {
+ return m_listeners;
+ }
+
+}
+// end catch_reporter_registry.cpp
+// start catch_result_type.cpp
+
+namespace Catch {
+
+ bool isOk( ResultWas::OfType resultType ) {
+ return ( resultType & ResultWas::FailureBit ) == 0;
+ }
+ bool isJustInfo( int flags ) {
+ return flags == ResultWas::Info;
+ }
+
+ ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) {
+ return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) );
+ }
+
+ bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; }
+ bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; }
+
+} // end namespace Catch
+// end catch_result_type.cpp
+// start catch_run_context.cpp
+
+#include <cassert>
+#include <algorithm>
+#include <sstream>
+
+namespace Catch {
+
+ namespace Generators {
+ struct GeneratorTracker : TestCaseTracking::TrackerBase, IGeneratorTracker {
+ GeneratorBasePtr m_generator;
+
+ GeneratorTracker( TestCaseTracking::NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
+ : TrackerBase( nameAndLocation, ctx, parent )
+ {}
+ ~GeneratorTracker();
+
+ static GeneratorTracker& acquire( TrackerContext& ctx, TestCaseTracking::NameAndLocation const& nameAndLocation ) {
+ std::shared_ptr<GeneratorTracker> tracker;
+
+ ITracker& currentTracker = ctx.currentTracker();
+ // Under specific circumstances, the generator we want
+ // to acquire is also the current tracker. If this is
+ // the case, we have to avoid looking through current
+ // tracker's children, and instead return the current
+ // tracker.
+ // A case where this check is important is e.g.
+ // for (int i = 0; i < 5; ++i) {
+ // int n = GENERATE(1, 2);
+ // }
+ //
+ // without it, the code above creates 5 nested generators.
+ if (currentTracker.nameAndLocation() == nameAndLocation) {
+ auto thisTracker = currentTracker.parent().findChild(nameAndLocation);
+ assert(thisTracker);
+ assert(thisTracker->isGeneratorTracker());
+ tracker = std::static_pointer_cast<GeneratorTracker>(thisTracker);
+ } else if ( TestCaseTracking::ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
+ assert( childTracker );
+ assert( childTracker->isGeneratorTracker() );
+ tracker = std::static_pointer_cast<GeneratorTracker>( childTracker );
+ } else {
+ tracker = std::make_shared<GeneratorTracker>( nameAndLocation, ctx, &currentTracker );
+ currentTracker.addChild( tracker );
+ }
+
+ if( !tracker->isComplete() ) {
+ tracker->open();
+ }
+
+ return *tracker;
+ }
+
+ // TrackerBase interface
+ bool isGeneratorTracker() const override { return true; }
+ auto hasGenerator() const -> bool override {
+ return !!m_generator;
+ }
+ void close() override {
+ TrackerBase::close();
+ // If a generator has a child (it is followed by a section)
+ // and none of its children have started, then we must wait
+ // until later to start consuming its values.
+ // This catches cases where `GENERATE` is placed between two
+ // `SECTION`s.
+ // **The check for m_children.empty cannot be removed**.
+ // doing so would break `GENERATE` _not_ followed by `SECTION`s.
+ const bool should_wait_for_child = [&]() {
+ // No children -> nobody to wait for
+ if ( m_children.empty() ) {
+ return false;
+ }
+ // If at least one child started executing, don't wait
+ if ( std::find_if(
+ m_children.begin(),
+ m_children.end(),
+ []( TestCaseTracking::ITrackerPtr tracker ) {
+ return tracker->hasStarted();
+ } ) != m_children.end() ) {
+ return false;
+ }
+
+ // No children have started. We need to check if they _can_
+ // start, and thus we should wait for them, or they cannot
+ // start (due to filters), and we shouldn't wait for them
+ auto* parent = m_parent;
+ // This is safe: there is always at least one section
+ // tracker in a test case tracking tree
+ while ( !parent->isSectionTracker() ) {
+ parent = &( parent->parent() );
+ }
+ assert( parent &&
+ "Missing root (test case) level section" );
+
+ auto const& parentSection =
+ static_cast<SectionTracker&>( *parent );
+ auto const& filters = parentSection.getFilters();
+ // No filters -> no restrictions on running sections
+ if ( filters.empty() ) {
+ return true;
+ }
+
+ for ( auto const& child : m_children ) {
+ if ( child->isSectionTracker() &&
+ std::find( filters.begin(),
+ filters.end(),
+ static_cast<SectionTracker&>( *child )
+ .trimmedName() ) !=
+ filters.end() ) {
+ return true;
+ }
+ }
+ return false;
+ }();
+
+ // This check is a bit tricky, because m_generator->next()
+ // has a side-effect, where it consumes generator's current
+ // value, but we do not want to invoke the side-effect if
+ // this generator is still waiting for any child to start.
+ if ( should_wait_for_child ||
+ ( m_runState == CompletedSuccessfully &&
+ m_generator->next() ) ) {
+ m_children.clear();
+ m_runState = Executing;
+ }
+ }
+
+ // IGeneratorTracker interface
+ auto getGenerator() const -> GeneratorBasePtr const& override {
+ return m_generator;
+ }
+ void setGenerator( GeneratorBasePtr&& generator ) override {
+ m_generator = std::move( generator );
+ }
+ };
+ GeneratorTracker::~GeneratorTracker() {}
+ }
+
+ RunContext::RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter)
+ : m_runInfo(_config->name()),
+ m_context(getCurrentMutableContext()),
+ m_config(_config),
+ m_reporter(std::move(reporter)),
+ m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal },
+ m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions )
+ {
+ m_context.setRunner(this);
+ m_context.setConfig(m_config);
+ m_context.setResultCapture(this);
+ m_reporter->testRunStarting(m_runInfo);
+ }
+
+ RunContext::~RunContext() {
+ m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting()));
+ }
+
+ void RunContext::testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount) {
+ m_reporter->testGroupStarting(GroupInfo(testSpec, groupIndex, groupsCount));
+ }
+
+ void RunContext::testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount) {
+ m_reporter->testGroupEnded(TestGroupStats(GroupInfo(testSpec, groupIndex, groupsCount), totals, aborting()));
+ }
+
+ Totals RunContext::runTest(TestCase const& testCase) {
+ Totals prevTotals = m_totals;
+
+ std::string redirectedCout;
+ std::string redirectedCerr;
+
+ auto const& testInfo = testCase.getTestCaseInfo();
+
+ m_reporter->testCaseStarting(testInfo);
+
+ m_activeTestCase = &testCase;
+
+ ITracker& rootTracker = m_trackerContext.startRun();
+ assert(rootTracker.isSectionTracker());
+ static_cast<SectionTracker&>(rootTracker).addInitialFilters(m_config->getSectionsToRun());
+ do {
+ m_trackerContext.startCycle();
+ m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(testInfo.name, testInfo.lineInfo));
+ runCurrentTest(redirectedCout, redirectedCerr);
+ } while (!m_testCaseTracker->isSuccessfullyCompleted() && !aborting());
+
+ Totals deltaTotals = m_totals.delta(prevTotals);
+ if (testInfo.expectedToFail() && deltaTotals.testCases.passed > 0) {
+ deltaTotals.assertions.failed++;
+ deltaTotals.testCases.passed--;
+ deltaTotals.testCases.failed++;
+ }
+ m_totals.testCases += deltaTotals.testCases;
+ m_reporter->testCaseEnded(TestCaseStats(testInfo,
+ deltaTotals,
+ redirectedCout,
+ redirectedCerr,
+ aborting()));
+
+ m_activeTestCase = nullptr;
+ m_testCaseTracker = nullptr;
+
+ return deltaTotals;
+ }
+
+ IConfigPtr RunContext::config() const {
+ return m_config;
+ }
+
+ IStreamingReporter& RunContext::reporter() const {
+ return *m_reporter;
+ }
+
+ void RunContext::assertionEnded(AssertionResult const & result) {
+ if (result.getResultType() == ResultWas::Ok) {
+ m_totals.assertions.passed++;
+ m_lastAssertionPassed = true;
+ } else if (!result.isOk()) {
+ m_lastAssertionPassed = false;
+ if( m_activeTestCase->getTestCaseInfo().okToFail() )
+ m_totals.assertions.failedButOk++;
+ else
+ m_totals.assertions.failed++;
+ }
+ else {
+ m_lastAssertionPassed = true;
+ }
+
+ // We have no use for the return value (whether messages should be cleared), because messages were made scoped
+ // and should be let to clear themselves out.
+ static_cast<void>(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals)));
+
+ if (result.getResultType() != ResultWas::Warning)
+ m_messageScopes.clear();
+
+ // Reset working state
+ resetAssertionInfo();
+ m_lastResult = result;
+ }
+ void RunContext::resetAssertionInfo() {
+ m_lastAssertionInfo.macroName = StringRef();
+ m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr;
+ }
+
+ bool RunContext::sectionStarted(SectionInfo const & sectionInfo, Counts & assertions) {
+ ITracker& sectionTracker = SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(sectionInfo.name, sectionInfo.lineInfo));
+ if (!sectionTracker.isOpen())
+ return false;
+ m_activeSections.push_back(&sectionTracker);
+
+ m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
+
+ m_reporter->sectionStarting(sectionInfo);
+
+ assertions = m_totals.assertions;
+
+ return true;
+ }
+ auto RunContext::acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& {
+ using namespace Generators;
+ GeneratorTracker& tracker = GeneratorTracker::acquire(m_trackerContext,
+ TestCaseTracking::NameAndLocation( static_cast<std::string>(generatorName), lineInfo ) );
+ m_lastAssertionInfo.lineInfo = lineInfo;
+ return tracker;
+ }
+
+ bool RunContext::testForMissingAssertions(Counts& assertions) {
+ if (assertions.total() != 0)
+ return false;
+ if (!m_config->warnAboutMissingAssertions())
+ return false;
+ if (m_trackerContext.currentTracker().hasChildren())
+ return false;
+ m_totals.assertions.failed++;
+ assertions.failed++;
+ return true;
+ }
+
+ void RunContext::sectionEnded(SectionEndInfo const & endInfo) {
+ Counts assertions = m_totals.assertions - endInfo.prevAssertions;
+ bool missingAssertions = testForMissingAssertions(assertions);
+
+ if (!m_activeSections.empty()) {
+ m_activeSections.back()->close();
+ m_activeSections.pop_back();
+ }
+
+ m_reporter->sectionEnded(SectionStats(endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions));
+ m_messages.clear();
+ m_messageScopes.clear();
+ }
+
+ void RunContext::sectionEndedEarly(SectionEndInfo const & endInfo) {
+ if (m_unfinishedSections.empty())
+ m_activeSections.back()->fail();
+ else
+ m_activeSections.back()->close();
+ m_activeSections.pop_back();
+
+ m_unfinishedSections.push_back(endInfo);
+ }
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ void RunContext::benchmarkPreparing(std::string const& name) {
+ m_reporter->benchmarkPreparing(name);
+ }
+ void RunContext::benchmarkStarting( BenchmarkInfo const& info ) {
+ m_reporter->benchmarkStarting( info );
+ }
+ void RunContext::benchmarkEnded( BenchmarkStats<> const& stats ) {
+ m_reporter->benchmarkEnded( stats );
+ }
+ void RunContext::benchmarkFailed(std::string const & error) {
+ m_reporter->benchmarkFailed(error);
+ }
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ void RunContext::pushScopedMessage(MessageInfo const & message) {
+ m_messages.push_back(message);
+ }
+
+ void RunContext::popScopedMessage(MessageInfo const & message) {
+ m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end());
+ }
+
+ void RunContext::emplaceUnscopedMessage( MessageBuilder const& builder ) {
+ m_messageScopes.emplace_back( builder );
+ }
+
+ std::string RunContext::getCurrentTestName() const {
+ return m_activeTestCase
+ ? m_activeTestCase->getTestCaseInfo().name
+ : std::string();
+ }
+
+ const AssertionResult * RunContext::getLastResult() const {
+ return &(*m_lastResult);
+ }
+
+ void RunContext::exceptionEarlyReported() {
+ m_shouldReportUnexpected = false;
+ }
+
+ void RunContext::handleFatalErrorCondition( StringRef message ) {
+ // First notify reporter that bad things happened
+ m_reporter->fatalErrorEncountered(message);
+
+ // Don't rebuild the result -- the stringification itself can cause more fatal errors
+ // Instead, fake a result data.
+ AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } );
+ tempResult.message = static_cast<std::string>(message);
+ AssertionResult result(m_lastAssertionInfo, tempResult);
+
+ assertionEnded(result);
+
+ handleUnfinishedSections();
+
+ // Recreate section for test case (as we will lose the one that was in scope)
+ auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
+ SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name);
+
+ Counts assertions;
+ assertions.failed = 1;
+ SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false);
+ m_reporter->sectionEnded(testCaseSectionStats);
+
+ auto const& testInfo = m_activeTestCase->getTestCaseInfo();
+
+ Totals deltaTotals;
+ deltaTotals.testCases.failed = 1;
+ deltaTotals.assertions.failed = 1;
+ m_reporter->testCaseEnded(TestCaseStats(testInfo,
+ deltaTotals,
+ std::string(),
+ std::string(),
+ false));
+ m_totals.testCases.failed++;
+ testGroupEnded(std::string(), m_totals, 1, 1);
+ m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false));
+ }
+
+ bool RunContext::lastAssertionPassed() {
+ return m_lastAssertionPassed;
+ }
+
+ void RunContext::assertionPassed() {
+ m_lastAssertionPassed = true;
+ ++m_totals.assertions.passed;
+ resetAssertionInfo();
+ m_messageScopes.clear();
+ }
+
+ bool RunContext::aborting() const {
+ return m_totals.assertions.failed >= static_cast<std::size_t>(m_config->abortAfter());
+ }
+
+ void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) {
+ auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
+ SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name);
+ m_reporter->sectionStarting(testCaseSection);
+ Counts prevAssertions = m_totals.assertions;
+ double duration = 0;
+ m_shouldReportUnexpected = true;
+ m_lastAssertionInfo = { "TEST_CASE"_sr, testCaseInfo.lineInfo, StringRef(), ResultDisposition::Normal };
+
+ seedRng(*m_config);
+
+ Timer timer;
+ CATCH_TRY {
+ if (m_reporter->getPreferences().shouldRedirectStdOut) {
+#if !defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
+ RedirectedStreams redirectedStreams(redirectedCout, redirectedCerr);
+
+ timer.start();
+ invokeActiveTestCase();
+#else
+ OutputRedirect r(redirectedCout, redirectedCerr);
+ timer.start();
+ invokeActiveTestCase();
+#endif
+ } else {
+ timer.start();
+ invokeActiveTestCase();
+ }
+ duration = timer.getElapsedSeconds();
+ } CATCH_CATCH_ANON (TestFailureException&) {
+ // This just means the test was aborted due to failure
+ } CATCH_CATCH_ALL {
+ // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions
+ // are reported without translation at the point of origin.
+ if( m_shouldReportUnexpected ) {
+ AssertionReaction dummyReaction;
+ handleUnexpectedInflightException( m_lastAssertionInfo, translateActiveException(), dummyReaction );
+ }
+ }
+ Counts assertions = m_totals.assertions - prevAssertions;
+ bool missingAssertions = testForMissingAssertions(assertions);
+
+ m_testCaseTracker->close();
+ handleUnfinishedSections();
+ m_messages.clear();
+ m_messageScopes.clear();
+
+ SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions);
+ m_reporter->sectionEnded(testCaseSectionStats);
+ }
+
+ void RunContext::invokeActiveTestCase() {
+ FatalConditionHandlerGuard _(&m_fatalConditionhandler);
+ m_activeTestCase->invoke();
+ }
+
+ void RunContext::handleUnfinishedSections() {
+ // If sections ended prematurely due to an exception we stored their
+ // infos here so we can tear them down outside the unwind process.
+ for (auto it = m_unfinishedSections.rbegin(),
+ itEnd = m_unfinishedSections.rend();
+ it != itEnd;
+ ++it)
+ sectionEnded(*it);
+ m_unfinishedSections.clear();
+ }
+
+ void RunContext::handleExpr(
+ AssertionInfo const& info,
+ ITransientExpression const& expr,
+ AssertionReaction& reaction
+ ) {
+ m_reporter->assertionStarting( info );
+
+ bool negated = isFalseTest( info.resultDisposition );
+ bool result = expr.getResult() != negated;
+
+ if( result ) {
+ if (!m_includeSuccessfulResults) {
+ assertionPassed();
+ }
+ else {
+ reportExpr(info, ResultWas::Ok, &expr, negated);
+ }
+ }
+ else {
+ reportExpr(info, ResultWas::ExpressionFailed, &expr, negated );
+ populateReaction( reaction );
+ }
+ }
+ void RunContext::reportExpr(
+ AssertionInfo const &info,
+ ResultWas::OfType resultType,
+ ITransientExpression const *expr,
+ bool negated ) {
+
+ m_lastAssertionInfo = info;
+ AssertionResultData data( resultType, LazyExpression( negated ) );
+
+ AssertionResult assertionResult{ info, data };
+ assertionResult.m_resultData.lazyExpression.m_transientExpression = expr;
+
+ assertionEnded( assertionResult );
+ }
+
+ void RunContext::handleMessage(
+ AssertionInfo const& info,
+ ResultWas::OfType resultType,
+ StringRef const& message,
+ AssertionReaction& reaction
+ ) {
+ m_reporter->assertionStarting( info );
+
+ m_lastAssertionInfo = info;
+
+ AssertionResultData data( resultType, LazyExpression( false ) );
+ data.message = static_cast<std::string>(message);
+ AssertionResult assertionResult{ m_lastAssertionInfo, data };
+ assertionEnded( assertionResult );
+ if( !assertionResult.isOk() )
+ populateReaction( reaction );
+ }
+ void RunContext::handleUnexpectedExceptionNotThrown(
+ AssertionInfo const& info,
+ AssertionReaction& reaction
+ ) {
+ handleNonExpr(info, Catch::ResultWas::DidntThrowException, reaction);
+ }
+
+ void RunContext::handleUnexpectedInflightException(
+ AssertionInfo const& info,
+ std::string const& message,
+ AssertionReaction& reaction
+ ) {
+ m_lastAssertionInfo = info;
+
+ AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) );
+ data.message = message;
+ AssertionResult assertionResult{ info, data };
+ assertionEnded( assertionResult );
+ populateReaction( reaction );
+ }
+
+ void RunContext::populateReaction( AssertionReaction& reaction ) {
+ reaction.shouldDebugBreak = m_config->shouldDebugBreak();
+ reaction.shouldThrow = aborting() || (m_lastAssertionInfo.resultDisposition & ResultDisposition::Normal);
+ }
+
+ void RunContext::handleIncomplete(
+ AssertionInfo const& info
+ ) {
+ m_lastAssertionInfo = info;
+
+ AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) );
+ data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
+ AssertionResult assertionResult{ info, data };
+ assertionEnded( assertionResult );
+ }
+ void RunContext::handleNonExpr(
+ AssertionInfo const &info,
+ ResultWas::OfType resultType,
+ AssertionReaction &reaction
+ ) {
+ m_lastAssertionInfo = info;
+
+ AssertionResultData data( resultType, LazyExpression( false ) );
+ AssertionResult assertionResult{ info, data };
+ assertionEnded( assertionResult );
+
+ if( !assertionResult.isOk() )
+ populateReaction( reaction );
+ }
+
+ IResultCapture& getResultCapture() {
+ if (auto* capture = getCurrentContext().getResultCapture())
+ return *capture;
+ else
+ CATCH_INTERNAL_ERROR("No result capture instance");
+ }
+
+ void seedRng(IConfig const& config) {
+ if (config.rngSeed() != 0) {
+ std::srand(config.rngSeed());
+ rng().seed(config.rngSeed());
+ }
+ }
+
+ unsigned int rngSeed() {
+ return getCurrentContext().getConfig()->rngSeed();
+ }
+
+}
+// end catch_run_context.cpp
+// start catch_section.cpp
+
+namespace Catch {
+
+ Section::Section( SectionInfo const& info )
+ : m_info( info ),
+ m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
+ {
+ m_timer.start();
+ }
+
+ Section::~Section() {
+ if( m_sectionIncluded ) {
+ SectionEndInfo endInfo{ m_info, m_assertions, m_timer.getElapsedSeconds() };
+ if( uncaught_exceptions() )
+ getResultCapture().sectionEndedEarly( endInfo );
+ else
+ getResultCapture().sectionEnded( endInfo );
+ }
+ }
+
+ // This indicates whether the section should be executed or not
+ Section::operator bool() const {
+ return m_sectionIncluded;
+ }
+
+} // end namespace Catch
+// end catch_section.cpp
+// start catch_section_info.cpp
+
+namespace Catch {
+
+ SectionInfo::SectionInfo
+ ( SourceLineInfo const& _lineInfo,
+ std::string const& _name )
+ : name( _name ),
+ lineInfo( _lineInfo )
+ {}
+
+} // end namespace Catch
+// end catch_section_info.cpp
+// start catch_session.cpp
+
+// start catch_session.h
+
+#include <memory>
+
+namespace Catch {
+
+ class Session : NonCopyable {
+ public:
+
+ Session();
+ ~Session() override;
+
+ void showHelp() const;
+ void libIdentify();
+
+ int applyCommandLine( int argc, char const * const * argv );
+ #if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE)
+ int applyCommandLine( int argc, wchar_t const * const * argv );
+ #endif
+
+ void useConfigData( ConfigData const& configData );
+
+ template<typename CharT>
+ int run(int argc, CharT const * const argv[]) {
+ if (m_startupExceptions)
+ return 1;
+ int returnCode = applyCommandLine(argc, argv);
+ if (returnCode == 0)
+ returnCode = run();
+ return returnCode;
+ }
+
+ int run();
+
+ clara::Parser const& cli() const;
+ void cli( clara::Parser const& newParser );
+ ConfigData& configData();
+ Config& config();
+ private:
+ int runInternal();
+
+ clara::Parser m_cli;
+ ConfigData m_configData;
+ std::shared_ptr<Config> m_config;
+ bool m_startupExceptions = false;
+ };
+
+} // end namespace Catch
+
+// end catch_session.h
+// start catch_version.h
+
+#include <iosfwd>
+
+namespace Catch {
+
+ // Versioning information
+ struct Version {
+ Version( Version const& ) = delete;
+ Version& operator=( Version const& ) = delete;
+ Version( unsigned int _majorVersion,
+ unsigned int _minorVersion,
+ unsigned int _patchNumber,
+ char const * const _branchName,
+ unsigned int _buildNumber );
+
+ unsigned int const majorVersion;
+ unsigned int const minorVersion;
+ unsigned int const patchNumber;
+
+ // buildNumber is only used if branchName is not null
+ char const * const branchName;
+ unsigned int const buildNumber;
+
+ friend std::ostream& operator << ( std::ostream& os, Version const& version );
+ };
+
+ Version const& libraryVersion();
+}
+
+// end catch_version.h
+#include <cstdlib>
+#include <iomanip>
+#include <set>
+#include <iterator>
+
+namespace Catch {
+
+ namespace {
+ const int MaxExitCode = 255;
+
+ IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) {
+ auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config);
+ CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'");
+
+ return reporter;
+ }
+
+ IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) {
+ if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()) {
+ return createReporter(config->getReporterName(), config);
+ }
+
+ // On older platforms, returning std::unique_ptr<ListeningReporter>
+ // when the return type is std::unique_ptr<IStreamingReporter>
+ // doesn't compile without a std::move call. However, this causes
+ // a warning on newer platforms. Thus, we have to work around
+ // it a bit and downcast the pointer manually.
+ auto ret = std::unique_ptr<IStreamingReporter>(new ListeningReporter);
+ auto& multi = static_cast<ListeningReporter&>(*ret);
+ auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
+ for (auto const& listener : listeners) {
+ multi.addListener(listener->create(Catch::ReporterConfig(config)));
+ }
+ multi.addReporter(createReporter(config->getReporterName(), config));
+ return ret;
+ }
+
+ class TestGroup {
+ public:
+ explicit TestGroup(std::shared_ptr<Config> const& config)
+ : m_config{config}
+ , m_context{config, makeReporter(config)}
+ {
+ auto const& allTestCases = getAllTestCasesSorted(*m_config);
+ m_matches = m_config->testSpec().matchesByFilter(allTestCases, *m_config);
+ auto const& invalidArgs = m_config->testSpec().getInvalidArgs();
+
+ if (m_matches.empty() && invalidArgs.empty()) {
+ for (auto const& test : allTestCases)
+ if (!test.isHidden())
+ m_tests.emplace(&test);
+ } else {
+ for (auto const& match : m_matches)
+ m_tests.insert(match.tests.begin(), match.tests.end());
+ }
+ }
+
+ Totals execute() {
+ auto const& invalidArgs = m_config->testSpec().getInvalidArgs();
+ Totals totals;
+ m_context.testGroupStarting(m_config->name(), 1, 1);
+ for (auto const& testCase : m_tests) {
+ if (!m_context.aborting())
+ totals += m_context.runTest(*testCase);
+ else
+ m_context.reporter().skipTest(*testCase);
+ }
+
+ for (auto const& match : m_matches) {
+ if (match.tests.empty()) {
+ m_context.reporter().noMatchingTestCases(match.name);
+ totals.error = -1;
+ }
+ }
+
+ if (!invalidArgs.empty()) {
+ for (auto const& invalidArg: invalidArgs)
+ m_context.reporter().reportInvalidArguments(invalidArg);
+ }
+
+ m_context.testGroupEnded(m_config->name(), totals, 1, 1);
+ return totals;
+ }
+
+ private:
+ using Tests = std::set<TestCase const*>;
+
+ std::shared_ptr<Config> m_config;
+ RunContext m_context;
+ Tests m_tests;
+ TestSpec::Matches m_matches;
+ };
+
+ void applyFilenamesAsTags(Catch::IConfig const& config) {
+ auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config));
+ for (auto& testCase : tests) {
+ auto tags = testCase.tags;
+
+ std::string filename = testCase.lineInfo.file;
+ auto lastSlash = filename.find_last_of("\\/");
+ if (lastSlash != std::string::npos) {
+ filename.erase(0, lastSlash);
+ filename[0] = '#';
+ }
+
+ auto lastDot = filename.find_last_of('.');
+ if (lastDot != std::string::npos) {
+ filename.erase(lastDot);
+ }
+
+ tags.push_back(std::move(filename));
+ setTags(testCase, tags);
+ }
+ }
+
+ } // anon namespace
+
+ Session::Session() {
+ static bool alreadyInstantiated = false;
+ if( alreadyInstantiated ) {
+ CATCH_TRY { CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); }
+ CATCH_CATCH_ALL { getMutableRegistryHub().registerStartupException(); }
+ }
+
+ // There cannot be exceptions at startup in no-exception mode.
+#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+ const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions();
+ if ( !exceptions.empty() ) {
+ config();
+ getCurrentMutableContext().setConfig(m_config);
+
+ m_startupExceptions = true;
+ Colour colourGuard( Colour::Red );
+ Catch::cerr() << "Errors occurred during startup!" << '\n';
+ // iterate over all exceptions and notify user
+ for ( const auto& ex_ptr : exceptions ) {
+ try {
+ std::rethrow_exception(ex_ptr);
+ } catch ( std::exception const& ex ) {
+ Catch::cerr() << Column( ex.what() ).indent(2) << '\n';
+ }
+ }
+ }
+#endif
+
+ alreadyInstantiated = true;
+ m_cli = makeCommandLineParser( m_configData );
+ }
+ Session::~Session() {
+ Catch::cleanUp();
+ }
+
+ void Session::showHelp() const {
+ Catch::cout()
+ << "\nCatch v" << libraryVersion() << "\n"
+ << m_cli << std::endl
+ << "For more detailed usage please see the project docs\n" << std::endl;
+ }
+ void Session::libIdentify() {
+ Catch::cout()
+ << std::left << std::setw(16) << "description: " << "A Catch2 test executable\n"
+ << std::left << std::setw(16) << "category: " << "testframework\n"
+ << std::left << std::setw(16) << "framework: " << "Catch Test\n"
+ << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl;
+ }
+
+ int Session::applyCommandLine( int argc, char const * const * argv ) {
+ if( m_startupExceptions )
+ return 1;
+
+ auto result = m_cli.parse( clara::Args( argc, argv ) );
+ if( !result ) {
+ config();
+ getCurrentMutableContext().setConfig(m_config);
+ Catch::cerr()
+ << Colour( Colour::Red )
+ << "\nError(s) in input:\n"
+ << Column( result.errorMessage() ).indent( 2 )
+ << "\n\n";
+ Catch::cerr() << "Run with -? for usage\n" << std::endl;
+ return MaxExitCode;
+ }
+
+ if( m_configData.showHelp )
+ showHelp();
+ if( m_configData.libIdentify )
+ libIdentify();
+ m_config.reset();
+ return 0;
+ }
+
+#if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE)
+ int Session::applyCommandLine( int argc, wchar_t const * const * argv ) {
+
+ char **utf8Argv = new char *[ argc ];
+
+ for ( int i = 0; i < argc; ++i ) {
+ int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, nullptr, 0, nullptr, nullptr );
+
+ utf8Argv[ i ] = new char[ bufSize ];
+
+ WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, nullptr, nullptr );
+ }
+
+ int returnCode = applyCommandLine( argc, utf8Argv );
+
+ for ( int i = 0; i < argc; ++i )
+ delete [] utf8Argv[ i ];
+
+ delete [] utf8Argv;
+
+ return returnCode;
+ }
+#endif
+
+ void Session::useConfigData( ConfigData const& configData ) {
+ m_configData = configData;
+ m_config.reset();
+ }
+
+ int Session::run() {
+ if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) {
+ Catch::cout() << "...waiting for enter/ return before starting" << std::endl;
+ static_cast<void>(std::getchar());
+ }
+ int exitCode = runInternal();
+ if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
+ Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
+ static_cast<void>(std::getchar());
+ }
+ return exitCode;
+ }
+
+ clara::Parser const& Session::cli() const {
+ return m_cli;
+ }
+ void Session::cli( clara::Parser const& newParser ) {
+ m_cli = newParser;
+ }
+ ConfigData& Session::configData() {
+ return m_configData;
+ }
+ Config& Session::config() {
+ if( !m_config )
+ m_config = std::make_shared<Config>( m_configData );
+ return *m_config;
+ }
+
+ int Session::runInternal() {
+ if( m_startupExceptions )
+ return 1;
+
+ if (m_configData.showHelp || m_configData.libIdentify) {
+ return 0;
+ }
+
+ CATCH_TRY {
+ config(); // Force config to be constructed
+
+ seedRng( *m_config );
+
+ if( m_configData.filenamesAsTags )
+ applyFilenamesAsTags( *m_config );
+
+ // Handle list request
+ if( Option<std::size_t> listed = list( m_config ) )
+ return static_cast<int>( *listed );
+
+ TestGroup tests { m_config };
+ auto const totals = tests.execute();
+
+ if( m_config->warnAboutNoTests() && totals.error == -1 )
+ return 2;
+
+ // Note that on unices only the lower 8 bits are usually used, clamping
+ // the return value to 255 prevents false negative when some multiple
+ // of 256 tests has failed
+ return (std::min) (MaxExitCode, (std::max) (totals.error, static_cast<int>(totals.assertions.failed)));
+ }
+#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+ catch( std::exception& ex ) {
+ Catch::cerr() << ex.what() << std::endl;
+ return MaxExitCode;
+ }
+#endif
+ }
+
+} // end namespace Catch
+// end catch_session.cpp
+// start catch_singletons.cpp
+
+#include <vector>
+
+namespace Catch {
+
+ namespace {
+ static auto getSingletons() -> std::vector<ISingleton*>*& {
+ static std::vector<ISingleton*>* g_singletons = nullptr;
+ if( !g_singletons )
+ g_singletons = new std::vector<ISingleton*>();
+ return g_singletons;
+ }
+ }
+
+ ISingleton::~ISingleton() {}
+
+ void addSingleton(ISingleton* singleton ) {
+ getSingletons()->push_back( singleton );
+ }
+ void cleanupSingletons() {
+ auto& singletons = getSingletons();
+ for( auto singleton : *singletons )
+ delete singleton;
+ delete singletons;
+ singletons = nullptr;
+ }
+
+} // namespace Catch
+// end catch_singletons.cpp
+// start catch_startup_exception_registry.cpp
+
+#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+namespace Catch {
+void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept {
+ CATCH_TRY {
+ m_exceptions.push_back(exception);
+ } CATCH_CATCH_ALL {
+ // If we run out of memory during start-up there's really not a lot more we can do about it
+ std::terminate();
+ }
+ }
+
+ std::vector<std::exception_ptr> const& StartupExceptionRegistry::getExceptions() const noexcept {
+ return m_exceptions;
+ }
+
+} // end namespace Catch
+#endif
+// end catch_startup_exception_registry.cpp
+// start catch_stream.cpp
+
+#include <cstdio>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <vector>
+#include <memory>
+
+namespace Catch {
+
+ Catch::IStream::~IStream() = default;
+
+ namespace Detail { namespace {
+ template<typename WriterF, std::size_t bufferSize=256>
+ class StreamBufImpl : public std::streambuf {
+ char data[bufferSize];
+ WriterF m_writer;
+
+ public:
+ StreamBufImpl() {
+ setp( data, data + sizeof(data) );
+ }
+
+ ~StreamBufImpl() noexcept {
+ StreamBufImpl::sync();
+ }
+
+ private:
+ int overflow( int c ) override {
+ sync();
+
+ if( c != EOF ) {
+ if( pbase() == epptr() )
+ m_writer( std::string( 1, static_cast<char>( c ) ) );
+ else
+ sputc( static_cast<char>( c ) );
+ }
+ return 0;
+ }
+
+ int sync() override {
+ if( pbase() != pptr() ) {
+ m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
+ setp( pbase(), epptr() );
+ }
+ return 0;
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ struct OutputDebugWriter {
+
+ void operator()( std::string const&str ) {
+ writeToDebugConsole( str );
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ class FileStream : public IStream {
+ mutable std::ofstream m_ofs;
+ public:
+ FileStream( StringRef filename ) {
+ m_ofs.open( filename.c_str() );
+ CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << "'" );
+ }
+ ~FileStream() override = default;
+ public: // IStream
+ std::ostream& stream() const override {
+ return m_ofs;
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ class CoutStream : public IStream {
+ mutable std::ostream m_os;
+ public:
+ // Store the streambuf from cout up-front because
+ // cout may get redirected when running tests
+ CoutStream() : m_os( Catch::cout().rdbuf() ) {}
+ ~CoutStream() override = default;
+
+ public: // IStream
+ std::ostream& stream() const override { return m_os; }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ class DebugOutStream : public IStream {
+ std::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf;
+ mutable std::ostream m_os;
+ public:
+ DebugOutStream()
+ : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ),
+ m_os( m_streamBuf.get() )
+ {}
+
+ ~DebugOutStream() override = default;
+
+ public: // IStream
+ std::ostream& stream() const override { return m_os; }
+ };
+
+ }} // namespace anon::detail
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ auto makeStream( StringRef const &filename ) -> IStream const* {
+ if( filename.empty() )
+ return new Detail::CoutStream();
+ else if( filename[0] == '%' ) {
+ if( filename == "%debug" )
+ return new Detail::DebugOutStream();
+ else
+ CATCH_ERROR( "Unrecognised stream: '" << filename << "'" );
+ }
+ else
+ return new Detail::FileStream( filename );
+ }
+
+ // This class encapsulates the idea of a pool of ostringstreams that can be reused.
+ struct StringStreams {
+ std::vector<std::unique_ptr<std::ostringstream>> m_streams;
+ std::vector<std::size_t> m_unused;
+ std::ostringstream m_referenceStream; // Used for copy state/ flags from
+
+ auto add() -> std::size_t {
+ if( m_unused.empty() ) {
+ m_streams.push_back( std::unique_ptr<std::ostringstream>( new std::ostringstream ) );
+ return m_streams.size()-1;
+ }
+ else {
+ auto index = m_unused.back();
+ m_unused.pop_back();
+ return index;
+ }
+ }
+
+ void release( std::size_t index ) {
+ m_streams[index]->copyfmt( m_referenceStream ); // Restore initial flags and other state
+ m_unused.push_back(index);
+ }
+ };
+
+ ReusableStringStream::ReusableStringStream()
+ : m_index( Singleton<StringStreams>::getMutable().add() ),
+ m_oss( Singleton<StringStreams>::getMutable().m_streams[m_index].get() )
+ {}
+
+ ReusableStringStream::~ReusableStringStream() {
+ static_cast<std::ostringstream*>( m_oss )->str("");
+ m_oss->clear();
+ Singleton<StringStreams>::getMutable().release( m_index );
+ }
+
+ auto ReusableStringStream::str() const -> std::string {
+ return static_cast<std::ostringstream*>( m_oss )->str();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions
+ std::ostream& cout() { return std::cout; }
+ std::ostream& cerr() { return std::cerr; }
+ std::ostream& clog() { return std::clog; }
+#endif
+}
+// end catch_stream.cpp
+// start catch_string_manip.cpp
+
+#include <algorithm>
+#include <ostream>
+#include <cstring>
+#include <cctype>
+#include <vector>
+
+namespace Catch {
+
+ namespace {
+ char toLowerCh(char c) {
+ return static_cast<char>( std::tolower( static_cast<unsigned char>(c) ) );
+ }
+ }
+
+ bool startsWith( std::string const& s, std::string const& prefix ) {
+ return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
+ }
+ bool startsWith( std::string const& s, char prefix ) {
+ return !s.empty() && s[0] == prefix;
+ }
+ bool endsWith( std::string const& s, std::string const& suffix ) {
+ return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin());
+ }
+ bool endsWith( std::string const& s, char suffix ) {
+ return !s.empty() && s[s.size()-1] == suffix;
+ }
+ bool contains( std::string const& s, std::string const& infix ) {
+ return s.find( infix ) != std::string::npos;
+ }
+ void toLowerInPlace( std::string& s ) {
+ std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
+ }
+ std::string toLower( std::string const& s ) {
+ std::string lc = s;
+ toLowerInPlace( lc );
+ return lc;
+ }
+ std::string trim( std::string const& str ) {
+ static char const* whitespaceChars = "\n\r\t ";
+ std::string::size_type start = str.find_first_not_of( whitespaceChars );
+ std::string::size_type end = str.find_last_not_of( whitespaceChars );
+
+ return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
+ }
+
+ StringRef trim(StringRef ref) {
+ const auto is_ws = [](char c) {
+ return c == ' ' || c == '\t' || c == '\n' || c == '\r';
+ };
+ size_t real_begin = 0;
+ while (real_begin < ref.size() && is_ws(ref[real_begin])) { ++real_begin; }
+ size_t real_end = ref.size();
+ while (real_end > real_begin && is_ws(ref[real_end - 1])) { --real_end; }
+
+ return ref.substr(real_begin, real_end - real_begin);
+ }
+
+ bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
+ bool replaced = false;
+ std::size_t i = str.find( replaceThis );
+ while( i != std::string::npos ) {
+ replaced = true;
+ str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
+ if( i < str.size()-withThis.size() )
+ i = str.find( replaceThis, i+withThis.size() );
+ else
+ i = std::string::npos;
+ }
+ return replaced;
+ }
+
+ std::vector<StringRef> splitStringRef( StringRef str, char delimiter ) {
+ std::vector<StringRef> subStrings;
+ std::size_t start = 0;
+ for(std::size_t pos = 0; pos < str.size(); ++pos ) {
+ if( str[pos] == delimiter ) {
+ if( pos - start > 1 )
+ subStrings.push_back( str.substr( start, pos-start ) );
+ start = pos+1;
+ }
+ }
+ if( start < str.size() )
+ subStrings.push_back( str.substr( start, str.size()-start ) );
+ return subStrings;
+ }
+
+ pluralise::pluralise( std::size_t count, std::string const& label )
+ : m_count( count ),
+ m_label( label )
+ {}
+
+ std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) {
+ os << pluraliser.m_count << ' ' << pluraliser.m_label;
+ if( pluraliser.m_count != 1 )
+ os << 's';
+ return os;
+ }
+
+}
+// end catch_string_manip.cpp
+// start catch_stringref.cpp
+
+#include <algorithm>
+#include <ostream>
+#include <cstring>
+#include <cstdint>
+
+namespace Catch {
+ StringRef::StringRef( char const* rawChars ) noexcept
+ : StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
+ {}
+
+ auto StringRef::c_str() const -> char const* {
+ CATCH_ENFORCE(isNullTerminated(), "Called StringRef::c_str() on a non-null-terminated instance");
+ return m_start;
+ }
+ auto StringRef::data() const noexcept -> char const* {
+ return m_start;
+ }
+
+ auto StringRef::substr( size_type start, size_type size ) const noexcept -> StringRef {
+ if (start < m_size) {
+ return StringRef(m_start + start, (std::min)(m_size - start, size));
+ } else {
+ return StringRef();
+ }
+ }
+ auto StringRef::operator == ( StringRef const& other ) const noexcept -> bool {
+ return m_size == other.m_size
+ && (std::memcmp( m_start, other.m_start, m_size ) == 0);
+ }
+
+ auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& {
+ return os.write(str.data(), str.size());
+ }
+
+ auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& {
+ lhs.append(rhs.data(), rhs.size());
+ return lhs;
+ }
+
+} // namespace Catch
+// end catch_stringref.cpp
+// start catch_tag_alias.cpp
+
+namespace Catch {
+ TagAlias::TagAlias(std::string const & _tag, SourceLineInfo _lineInfo): tag(_tag), lineInfo(_lineInfo) {}
+}
+// end catch_tag_alias.cpp
+// start catch_tag_alias_autoregistrar.cpp
+
+namespace Catch {
+
+ RegistrarForTagAliases::RegistrarForTagAliases(char const* alias, char const* tag, SourceLineInfo const& lineInfo) {
+ CATCH_TRY {
+ getMutableRegistryHub().registerTagAlias(alias, tag, lineInfo);
+ } CATCH_CATCH_ALL {
+ // Do not throw when constructing global objects, instead register the exception to be processed later
+ getMutableRegistryHub().registerStartupException();
+ }
+ }
+
+}
+// end catch_tag_alias_autoregistrar.cpp
+// start catch_tag_alias_registry.cpp
+
+#include <sstream>
+
+namespace Catch {
+
+ TagAliasRegistry::~TagAliasRegistry() {}
+
+ TagAlias const* TagAliasRegistry::find( std::string const& alias ) const {
+ auto it = m_registry.find( alias );
+ if( it != m_registry.end() )
+ return &(it->second);
+ else
+ return nullptr;
+ }
+
+ std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
+ std::string expandedTestSpec = unexpandedTestSpec;
+ for( auto const& registryKvp : m_registry ) {
+ std::size_t pos = expandedTestSpec.find( registryKvp.first );
+ if( pos != std::string::npos ) {
+ expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
+ registryKvp.second.tag +
+ expandedTestSpec.substr( pos + registryKvp.first.size() );
+ }
+ }
+ return expandedTestSpec;
+ }
+
+ void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) {
+ CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'),
+ "error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo );
+
+ CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second,
+ "error: tag alias, '" << alias << "' already registered.\n"
+ << "\tFirst seen at: " << find(alias)->lineInfo << "\n"
+ << "\tRedefined at: " << lineInfo );
+ }
+
+ ITagAliasRegistry::~ITagAliasRegistry() {}
+
+ ITagAliasRegistry const& ITagAliasRegistry::get() {
+ return getRegistryHub().getTagAliasRegistry();
+ }
+
+} // end namespace Catch
+// end catch_tag_alias_registry.cpp
+// start catch_test_case_info.cpp
+
+#include <cctype>
+#include <exception>
+#include <algorithm>
+#include <sstream>
+
+namespace Catch {
+
+ namespace {
+ TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) {
+ if( startsWith( tag, '.' ) ||
+ tag == "!hide" )
+ return TestCaseInfo::IsHidden;
+ else if( tag == "!throws" )
+ return TestCaseInfo::Throws;
+ else if( tag == "!shouldfail" )
+ return TestCaseInfo::ShouldFail;
+ else if( tag == "!mayfail" )
+ return TestCaseInfo::MayFail;
+ else if( tag == "!nonportable" )
+ return TestCaseInfo::NonPortable;
+ else if( tag == "!benchmark" )
+ return static_cast<TestCaseInfo::SpecialProperties>( TestCaseInfo::Benchmark | TestCaseInfo::IsHidden );
+ else
+ return TestCaseInfo::None;
+ }
+ bool isReservedTag( std::string const& tag ) {
+ return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( static_cast<unsigned char>(tag[0]) );
+ }
+ void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
+ CATCH_ENFORCE( !isReservedTag(tag),
+ "Tag name: [" << tag << "] is not allowed.\n"
+ << "Tag names starting with non alphanumeric characters are reserved\n"
+ << _lineInfo );
+ }
+ }
+
+ TestCase makeTestCase( ITestInvoker* _testCase,
+ std::string const& _className,
+ NameAndTags const& nameAndTags,
+ SourceLineInfo const& _lineInfo )
+ {
+ bool isHidden = false;
+
+ // Parse out tags
+ std::vector<std::string> tags;
+ std::string desc, tag;
+ bool inTag = false;
+ for (char c : nameAndTags.tags) {
+ if( !inTag ) {
+ if( c == '[' )
+ inTag = true;
+ else
+ desc += c;
+ }
+ else {
+ if( c == ']' ) {
+ TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag );
+ if( ( prop & TestCaseInfo::IsHidden ) != 0 )
+ isHidden = true;
+ else if( prop == TestCaseInfo::None )
+ enforceNotReservedTag( tag, _lineInfo );
+
+ // Merged hide tags like `[.approvals]` should be added as
+ // `[.][approvals]`. The `[.]` is added at later point, so
+ // we only strip the prefix
+ if (startsWith(tag, '.') && tag.size() > 1) {
+ tag.erase(0, 1);
+ }
+ tags.push_back( tag );
+ tag.clear();
+ inTag = false;
+ }
+ else
+ tag += c;
+ }
+ }
+ if( isHidden ) {
+ // Add all "hidden" tags to make them behave identically
+ tags.insert( tags.end(), { ".", "!hide" } );
+ }
+
+ TestCaseInfo info( static_cast<std::string>(nameAndTags.name), _className, desc, tags, _lineInfo );
+ return TestCase( _testCase, std::move(info) );
+ }
+
+ void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ) {
+ std::sort(begin(tags), end(tags));
+ tags.erase(std::unique(begin(tags), end(tags)), end(tags));
+ testCaseInfo.lcaseTags.clear();
+
+ for( auto const& tag : tags ) {
+ std::string lcaseTag = toLower( tag );
+ testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
+ testCaseInfo.lcaseTags.push_back( lcaseTag );
+ }
+ testCaseInfo.tags = std::move(tags);
+ }
+
+ TestCaseInfo::TestCaseInfo( std::string const& _name,
+ std::string const& _className,
+ std::string const& _description,
+ std::vector<std::string> const& _tags,
+ SourceLineInfo const& _lineInfo )
+ : name( _name ),
+ className( _className ),
+ description( _description ),
+ lineInfo( _lineInfo ),
+ properties( None )
+ {
+ setTags( *this, _tags );
+ }
+
+ bool TestCaseInfo::isHidden() const {
+ return ( properties & IsHidden ) != 0;
+ }
+ bool TestCaseInfo::throws() const {
+ return ( properties & Throws ) != 0;
+ }
+ bool TestCaseInfo::okToFail() const {
+ return ( properties & (ShouldFail | MayFail ) ) != 0;
+ }
+ bool TestCaseInfo::expectedToFail() const {
+ return ( properties & (ShouldFail ) ) != 0;
+ }
+
+ std::string TestCaseInfo::tagsAsString() const {
+ std::string ret;
+ // '[' and ']' per tag
+ std::size_t full_size = 2 * tags.size();
+ for (const auto& tag : tags) {
+ full_size += tag.size();
+ }
+ ret.reserve(full_size);
+ for (const auto& tag : tags) {
+ ret.push_back('[');
+ ret.append(tag);
+ ret.push_back(']');
+ }
+
+ return ret;
+ }
+
+ TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(info) ), test( testCase ) {}
+
+ TestCase TestCase::withName( std::string const& _newName ) const {
+ TestCase other( *this );
+ other.name = _newName;
+ return other;
+ }
+
+ void TestCase::invoke() const {
+ test->invoke();
+ }
+
+ bool TestCase::operator == ( TestCase const& other ) const {
+ return test.get() == other.test.get() &&
+ name == other.name &&
+ className == other.className;
+ }
+
+ bool TestCase::operator < ( TestCase const& other ) const {
+ return name < other.name;
+ }
+
+ TestCaseInfo const& TestCase::getTestCaseInfo() const
+ {
+ return *this;
+ }
+
+} // end namespace Catch
+// end catch_test_case_info.cpp
+// start catch_test_case_registry_impl.cpp
+
+#include <algorithm>
+#include <sstream>
+
+namespace Catch {
+
+ namespace {
+ struct TestHasher {
+ using hash_t = uint64_t;
+
+ explicit TestHasher( hash_t hashSuffix ):
+ m_hashSuffix{ hashSuffix } {}
+
+ uint32_t operator()( TestCase const& t ) const {
+ // FNV-1a hash with multiplication fold.
+ const hash_t prime = 1099511628211u;
+ hash_t hash = 14695981039346656037u;
+ for ( const char c : t.name ) {
+ hash ^= c;
+ hash *= prime;
+ }
+ hash ^= m_hashSuffix;
+ hash *= prime;
+ const uint32_t low{ static_cast<uint32_t>( hash ) };
+ const uint32_t high{ static_cast<uint32_t>( hash >> 32 ) };
+ return low * high;
+ }
+
+ private:
+ hash_t m_hashSuffix;
+ };
+ } // end unnamed namespace
+
+ std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
+ switch( config.runOrder() ) {
+ case RunTests::InDeclarationOrder:
+ // already in declaration order
+ break;
+
+ case RunTests::InLexicographicalOrder: {
+ std::vector<TestCase> sorted = unsortedTestCases;
+ std::sort( sorted.begin(), sorted.end() );
+ return sorted;
+ }
+
+ case RunTests::InRandomOrder: {
+ seedRng( config );
+ TestHasher h{ config.rngSeed() };
+
+ using hashedTest = std::pair<TestHasher::hash_t, TestCase const*>;
+ std::vector<hashedTest> indexed_tests;
+ indexed_tests.reserve( unsortedTestCases.size() );
+
+ for (auto const& testCase : unsortedTestCases) {
+ indexed_tests.emplace_back(h(testCase), &testCase);
+ }
+
+ std::sort(indexed_tests.begin(), indexed_tests.end(),
+ [](hashedTest const& lhs, hashedTest const& rhs) {
+ if (lhs.first == rhs.first) {
+ return lhs.second->name < rhs.second->name;
+ }
+ return lhs.first < rhs.first;
+ });
+
+ std::vector<TestCase> sorted;
+ sorted.reserve( indexed_tests.size() );
+
+ for (auto const& hashed : indexed_tests) {
+ sorted.emplace_back(*hashed.second);
+ }
+
+ return sorted;
+ }
+ }
+ return unsortedTestCases;
+ }
+
+ bool isThrowSafe( TestCase const& testCase, IConfig const& config ) {
+ return !testCase.throws() || config.allowThrows();
+ }
+
+ bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) {
+ return testSpec.matches( testCase ) && isThrowSafe( testCase, config );
+ }
+
+ void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
+ std::set<TestCase> seenFunctions;
+ for( auto const& function : functions ) {
+ auto prev = seenFunctions.insert( function );
+ CATCH_ENFORCE( prev.second,
+ "error: TEST_CASE( \"" << function.name << "\" ) already defined.\n"
+ << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n"
+ << "\tRedefined at " << function.getTestCaseInfo().lineInfo );
+ }
+ }
+
+ std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
+ std::vector<TestCase> filtered;
+ filtered.reserve( testCases.size() );
+ for (auto const& testCase : testCases) {
+ if ((!testSpec.hasFilters() && !testCase.isHidden()) ||
+ (testSpec.hasFilters() && matchTest(testCase, testSpec, config))) {
+ filtered.push_back(testCase);
+ }
+ }
+ return filtered;
+ }
+ std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {
+ return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
+ }
+
+ void TestRegistry::registerTest( TestCase const& testCase ) {
+ std::string name = testCase.getTestCaseInfo().name;
+ if( name.empty() ) {
+ ReusableStringStream rss;
+ rss << "Anonymous test case " << ++m_unnamedCount;
+ return registerTest( testCase.withName( rss.str() ) );
+ }
+ m_functions.push_back( testCase );
+ }
+
+ std::vector<TestCase> const& TestRegistry::getAllTests() const {
+ return m_functions;
+ }
+ std::vector<TestCase> const& TestRegistry::getAllTestsSorted( IConfig const& config ) const {
+ if( m_sortedFunctions.empty() )
+ enforceNoDuplicateTestCases( m_functions );
+
+ if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) {
+ m_sortedFunctions = sortTests( config, m_functions );
+ m_currentSortOrder = config.runOrder();
+ }
+ return m_sortedFunctions;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ TestInvokerAsFunction::TestInvokerAsFunction( void(*testAsFunction)() ) noexcept : m_testAsFunction( testAsFunction ) {}
+
+ void TestInvokerAsFunction::invoke() const {
+ m_testAsFunction();
+ }
+
+ std::string extractClassName( StringRef const& classOrQualifiedMethodName ) {
+ std::string className(classOrQualifiedMethodName);
+ if( startsWith( className, '&' ) )
+ {
+ std::size_t lastColons = className.rfind( "::" );
+ std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
+ if( penultimateColons == std::string::npos )
+ penultimateColons = 1;
+ className = className.substr( penultimateColons, lastColons-penultimateColons );
+ }
+ return className;
+ }
+
+} // end namespace Catch
+// end catch_test_case_registry_impl.cpp
+// start catch_test_case_tracker.cpp
+
+#include <algorithm>
+#include <cassert>
+#include <stdexcept>
+#include <memory>
+#include <sstream>
+
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wexit-time-destructors"
+#endif
+
+namespace Catch {
+namespace TestCaseTracking {
+
+ NameAndLocation::NameAndLocation( std::string const& _name, SourceLineInfo const& _location )
+ : name( _name ),
+ location( _location )
+ {}
+
+ ITracker::~ITracker() = default;
+
+ ITracker& TrackerContext::startRun() {
+ m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr );
+ m_currentTracker = nullptr;
+ m_runState = Executing;
+ return *m_rootTracker;
+ }
+
+ void TrackerContext::endRun() {
+ m_rootTracker.reset();
+ m_currentTracker = nullptr;
+ m_runState = NotStarted;
+ }
+
+ void TrackerContext::startCycle() {
+ m_currentTracker = m_rootTracker.get();
+ m_runState = Executing;
+ }
+ void TrackerContext::completeCycle() {
+ m_runState = CompletedCycle;
+ }
+
+ bool TrackerContext::completedCycle() const {
+ return m_runState == CompletedCycle;
+ }
+ ITracker& TrackerContext::currentTracker() {
+ return *m_currentTracker;
+ }
+ void TrackerContext::setCurrentTracker( ITracker* tracker ) {
+ m_currentTracker = tracker;
+ }
+
+ TrackerBase::TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ):
+ ITracker(nameAndLocation),
+ m_ctx( ctx ),
+ m_parent( parent )
+ {}
+
+ bool TrackerBase::isComplete() const {
+ return m_runState == CompletedSuccessfully || m_runState == Failed;
+ }
+ bool TrackerBase::isSuccessfullyCompleted() const {
+ return m_runState == CompletedSuccessfully;
+ }
+ bool TrackerBase::isOpen() const {
+ return m_runState != NotStarted && !isComplete();
+ }
+ bool TrackerBase::hasChildren() const {
+ return !m_children.empty();
+ }
+
+ void TrackerBase::addChild( ITrackerPtr const& child ) {
+ m_children.push_back( child );
+ }
+
+ ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) {
+ auto it = std::find_if( m_children.begin(), m_children.end(),
+ [&nameAndLocation]( ITrackerPtr const& tracker ){
+ return
+ tracker->nameAndLocation().location == nameAndLocation.location &&
+ tracker->nameAndLocation().name == nameAndLocation.name;
+ } );
+ return( it != m_children.end() )
+ ? *it
+ : nullptr;
+ }
+ ITracker& TrackerBase::parent() {
+ assert( m_parent ); // Should always be non-null except for root
+ return *m_parent;
+ }
+
+ void TrackerBase::openChild() {
+ if( m_runState != ExecutingChildren ) {
+ m_runState = ExecutingChildren;
+ if( m_parent )
+ m_parent->openChild();
+ }
+ }
+
+ bool TrackerBase::isSectionTracker() const { return false; }
+ bool TrackerBase::isGeneratorTracker() const { return false; }
+
+ void TrackerBase::open() {
+ m_runState = Executing;
+ moveToThis();
+ if( m_parent )
+ m_parent->openChild();
+ }
+
+ void TrackerBase::close() {
+
+ // Close any still open children (e.g. generators)
+ while( &m_ctx.currentTracker() != this )
+ m_ctx.currentTracker().close();
+
+ switch( m_runState ) {
+ case NeedsAnotherRun:
+ break;
+
+ case Executing:
+ m_runState = CompletedSuccessfully;
+ break;
+ case ExecutingChildren:
+ if( std::all_of(m_children.begin(), m_children.end(), [](ITrackerPtr const& t){ return t->isComplete(); }) )
+ m_runState = CompletedSuccessfully;
+ break;
+
+ case NotStarted:
+ case CompletedSuccessfully:
+ case Failed:
+ CATCH_INTERNAL_ERROR( "Illogical state: " << m_runState );
+
+ default:
+ CATCH_INTERNAL_ERROR( "Unknown state: " << m_runState );
+ }
+ moveToParent();
+ m_ctx.completeCycle();
+ }
+ void TrackerBase::fail() {
+ m_runState = Failed;
+ if( m_parent )
+ m_parent->markAsNeedingAnotherRun();
+ moveToParent();
+ m_ctx.completeCycle();
+ }
+ void TrackerBase::markAsNeedingAnotherRun() {
+ m_runState = NeedsAnotherRun;
+ }
+
+ void TrackerBase::moveToParent() {
+ assert( m_parent );
+ m_ctx.setCurrentTracker( m_parent );
+ }
+ void TrackerBase::moveToThis() {
+ m_ctx.setCurrentTracker( this );
+ }
+
+ SectionTracker::SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
+ : TrackerBase( nameAndLocation, ctx, parent ),
+ m_trimmed_name(trim(nameAndLocation.name))
+ {
+ if( parent ) {
+ while( !parent->isSectionTracker() )
+ parent = &parent->parent();
+
+ SectionTracker& parentSection = static_cast<SectionTracker&>( *parent );
+ addNextFilters( parentSection.m_filters );
+ }
+ }
+
+ bool SectionTracker::isComplete() const {
+ bool complete = true;
+
+ if (m_filters.empty()
+ || m_filters[0] == ""
+ || std::find(m_filters.begin(), m_filters.end(), m_trimmed_name) != m_filters.end()) {
+ complete = TrackerBase::isComplete();
+ }
+ return complete;
+ }
+
+ bool SectionTracker::isSectionTracker() const { return true; }
+
+ SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) {
+ std::shared_ptr<SectionTracker> section;
+
+ ITracker& currentTracker = ctx.currentTracker();
+ if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
+ assert( childTracker );
+ assert( childTracker->isSectionTracker() );
+ section = std::static_pointer_cast<SectionTracker>( childTracker );
+ }
+ else {
+ section = std::make_shared<SectionTracker>( nameAndLocation, ctx, &currentTracker );
+ currentTracker.addChild( section );
+ }
+ if( !ctx.completedCycle() )
+ section->tryOpen();
+ return *section;
+ }
+
+ void SectionTracker::tryOpen() {
+ if( !isComplete() )
+ open();
+ }
+
+ void SectionTracker::addInitialFilters( std::vector<std::string> const& filters ) {
+ if( !filters.empty() ) {
+ m_filters.reserve( m_filters.size() + filters.size() + 2 );
+ m_filters.emplace_back(""); // Root - should never be consulted
+ m_filters.emplace_back(""); // Test Case - not a section filter
+ m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
+ }
+ }
+ void SectionTracker::addNextFilters( std::vector<std::string> const& filters ) {
+ if( filters.size() > 1 )
+ m_filters.insert( m_filters.end(), filters.begin()+1, filters.end() );
+ }
+
+ std::vector<std::string> const& SectionTracker::getFilters() const {
+ return m_filters;
+ }
+
+ std::string const& SectionTracker::trimmedName() const {
+ return m_trimmed_name;
+ }
+
+} // namespace TestCaseTracking
+
+using TestCaseTracking::ITracker;
+using TestCaseTracking::TrackerContext;
+using TestCaseTracking::SectionTracker;
+
+} // namespace Catch
+
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+// end catch_test_case_tracker.cpp
+// start catch_test_registry.cpp
+
+namespace Catch {
+
+ auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker* {
+ return new(std::nothrow) TestInvokerAsFunction( testAsFunction );
+ }
+
+ NameAndTags::NameAndTags( StringRef const& name_ , StringRef const& tags_ ) noexcept : name( name_ ), tags( tags_ ) {}
+
+ AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept {
+ CATCH_TRY {
+ getMutableRegistryHub()
+ .registerTest(
+ makeTestCase(
+ invoker,
+ extractClassName( classOrMethod ),
+ nameAndTags,
+ lineInfo));
+ } CATCH_CATCH_ALL {
+ // Do not throw when constructing global objects, instead register the exception to be processed later
+ getMutableRegistryHub().registerStartupException();
+ }
+ }
+
+ AutoReg::~AutoReg() = default;
+}
+// end catch_test_registry.cpp
+// start catch_test_spec.cpp
+
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <memory>
+
+namespace Catch {
+
+ TestSpec::Pattern::Pattern( std::string const& name )
+ : m_name( name )
+ {}
+
+ TestSpec::Pattern::~Pattern() = default;
+
+ std::string const& TestSpec::Pattern::name() const {
+ return m_name;
+ }
+
+ TestSpec::NamePattern::NamePattern( std::string const& name, std::string const& filterString )
+ : Pattern( filterString )
+ , m_wildcardPattern( toLower( name ), CaseSensitive::No )
+ {}
+
+ bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const {
+ return m_wildcardPattern.matches( testCase.name );
+ }
+
+ TestSpec::TagPattern::TagPattern( std::string const& tag, std::string const& filterString )
+ : Pattern( filterString )
+ , m_tag( toLower( tag ) )
+ {}
+
+ bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const {
+ return std::find(begin(testCase.lcaseTags),
+ end(testCase.lcaseTags),
+ m_tag) != end(testCase.lcaseTags);
+ }
+
+ TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern )
+ : Pattern( underlyingPattern->name() )
+ , m_underlyingPattern( underlyingPattern )
+ {}
+
+ bool TestSpec::ExcludedPattern::matches( TestCaseInfo const& testCase ) const {
+ return !m_underlyingPattern->matches( testCase );
+ }
+
+ bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const {
+ return std::all_of( m_patterns.begin(), m_patterns.end(), [&]( PatternPtr const& p ){ return p->matches( testCase ); } );
+ }
+
+ std::string TestSpec::Filter::name() const {
+ std::string name;
+ for( auto const& p : m_patterns )
+ name += p->name();
+ return name;
+ }
+
+ bool TestSpec::hasFilters() const {
+ return !m_filters.empty();
+ }
+
+ bool TestSpec::matches( TestCaseInfo const& testCase ) const {
+ return std::any_of( m_filters.begin(), m_filters.end(), [&]( Filter const& f ){ return f.matches( testCase ); } );
+ }
+
+ TestSpec::Matches TestSpec::matchesByFilter( std::vector<TestCase> const& testCases, IConfig const& config ) const
+ {
+ Matches matches( m_filters.size() );
+ std::transform( m_filters.begin(), m_filters.end(), matches.begin(), [&]( Filter const& filter ){
+ std::vector<TestCase const*> currentMatches;
+ for( auto const& test : testCases )
+ if( isThrowSafe( test, config ) && filter.matches( test ) )
+ currentMatches.emplace_back( &test );
+ return FilterMatch{ filter.name(), currentMatches };
+ } );
+ return matches;
+ }
+
+ const TestSpec::vectorStrings& TestSpec::getInvalidArgs() const{
+ return (m_invalidArgs);
+ }
+
+}
+// end catch_test_spec.cpp
+// start catch_test_spec_parser.cpp
+
+namespace Catch {
+
+ TestSpecParser::TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {}
+
+ TestSpecParser& TestSpecParser::parse( std::string const& arg ) {
+ m_mode = None;
+ m_exclusion = false;
+ m_arg = m_tagAliases->expandAliases( arg );
+ m_escapeChars.clear();
+ m_substring.reserve(m_arg.size());
+ m_patternName.reserve(m_arg.size());
+ m_realPatternPos = 0;
+
+ for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
+ //if visitChar fails
+ if( !visitChar( m_arg[m_pos] ) ){
+ m_testSpec.m_invalidArgs.push_back(arg);
+ break;
+ }
+ endMode();
+ return *this;
+ }
+ TestSpec TestSpecParser::testSpec() {
+ addFilter();
+ return m_testSpec;
+ }
+ bool TestSpecParser::visitChar( char c ) {
+ if( (m_mode != EscapedName) && (c == '\\') ) {
+ escape();
+ addCharToPattern(c);
+ return true;
+ }else if((m_mode != EscapedName) && (c == ',') ) {
+ return separate();
+ }
+
+ switch( m_mode ) {
+ case None:
+ if( processNoneChar( c ) )
+ return true;
+ break;
+ case Name:
+ processNameChar( c );
+ break;
+ case EscapedName:
+ endMode();
+ addCharToPattern(c);
+ return true;
+ default:
+ case Tag:
+ case QuotedName:
+ if( processOtherChar( c ) )
+ return true;
+ break;
+ }
+
+ m_substring += c;
+ if( !isControlChar( c ) ) {
+ m_patternName += c;
+ m_realPatternPos++;
+ }
+ return true;
+ }
+ // Two of the processing methods return true to signal the caller to return
+ // without adding the given character to the current pattern strings
+ bool TestSpecParser::processNoneChar( char c ) {
+ switch( c ) {
+ case ' ':
+ return true;
+ case '~':
+ m_exclusion = true;
+ return false;
+ case '[':
+ startNewMode( Tag );
+ return false;
+ case '"':
+ startNewMode( QuotedName );
+ return false;
+ default:
+ startNewMode( Name );
+ return false;
+ }
+ }
+ void TestSpecParser::processNameChar( char c ) {
+ if( c == '[' ) {
+ if( m_substring == "exclude:" )
+ m_exclusion = true;
+ else
+ endMode();
+ startNewMode( Tag );
+ }
+ }
+ bool TestSpecParser::processOtherChar( char c ) {
+ if( !isControlChar( c ) )
+ return false;
+ m_substring += c;
+ endMode();
+ return true;
+ }
+ void TestSpecParser::startNewMode( Mode mode ) {
+ m_mode = mode;
+ }
+ void TestSpecParser::endMode() {
+ switch( m_mode ) {
+ case Name:
+ case QuotedName:
+ return addNamePattern();
+ case Tag:
+ return addTagPattern();
+ case EscapedName:
+ revertBackToLastMode();
+ return;
+ case None:
+ default:
+ return startNewMode( None );
+ }
+ }
+ void TestSpecParser::escape() {
+ saveLastMode();
+ m_mode = EscapedName;
+ m_escapeChars.push_back(m_realPatternPos);
+ }
+ bool TestSpecParser::isControlChar( char c ) const {
+ switch( m_mode ) {
+ default:
+ return false;
+ case None:
+ return c == '~';
+ case Name:
+ return c == '[';
+ case EscapedName:
+ return true;
+ case QuotedName:
+ return c == '"';
+ case Tag:
+ return c == '[' || c == ']';
+ }
+ }
+
+ void TestSpecParser::addFilter() {
+ if( !m_currentFilter.m_patterns.empty() ) {
+ m_testSpec.m_filters.push_back( m_currentFilter );
+ m_currentFilter = TestSpec::Filter();
+ }
+ }
+
+ void TestSpecParser::saveLastMode() {
+ lastMode = m_mode;
+ }
+
+ void TestSpecParser::revertBackToLastMode() {
+ m_mode = lastMode;
+ }
+
+ bool TestSpecParser::separate() {
+ if( (m_mode==QuotedName) || (m_mode==Tag) ){
+ //invalid argument, signal failure to previous scope.
+ m_mode = None;
+ m_pos = m_arg.size();
+ m_substring.clear();
+ m_patternName.clear();
+ m_realPatternPos = 0;
+ return false;
+ }
+ endMode();
+ addFilter();
+ return true; //success
+ }
+
+ std::string TestSpecParser::preprocessPattern() {
+ std::string token = m_patternName;
+ for (std::size_t i = 0; i < m_escapeChars.size(); ++i)
+ token = token.substr(0, m_escapeChars[i] - i) + token.substr(m_escapeChars[i] - i + 1);
+ m_escapeChars.clear();
+ if (startsWith(token, "exclude:")) {
+ m_exclusion = true;
+ token = token.substr(8);
+ }
+
+ m_patternName.clear();
+ m_realPatternPos = 0;
+
+ return token;
+ }
+
+ void TestSpecParser::addNamePattern() {
+ auto token = preprocessPattern();
+
+ if (!token.empty()) {
+ TestSpec::PatternPtr pattern = std::make_shared<TestSpec::NamePattern>(token, m_substring);
+ if (m_exclusion)
+ pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
+ m_currentFilter.m_patterns.push_back(pattern);
+ }
+ m_substring.clear();
+ m_exclusion = false;
+ m_mode = None;
+ }
+
+ void TestSpecParser::addTagPattern() {
+ auto token = preprocessPattern();
+
+ if (!token.empty()) {
+ // If the tag pattern is the "hide and tag" shorthand (e.g. [.foo])
+ // we have to create a separate hide tag and shorten the real one
+ if (token.size() > 1 && token[0] == '.') {
+ token.erase(token.begin());
+ TestSpec::PatternPtr pattern = std::make_shared<TestSpec::TagPattern>(".", m_substring);
+ if (m_exclusion) {
+ pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
+ }
+ m_currentFilter.m_patterns.push_back(pattern);
+ }
+
+ TestSpec::PatternPtr pattern = std::make_shared<TestSpec::TagPattern>(token, m_substring);
+
+ if (m_exclusion) {
+ pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
+ }
+ m_currentFilter.m_patterns.push_back(pattern);
+ }
+ m_substring.clear();
+ m_exclusion = false;
+ m_mode = None;
+ }
+
+ TestSpec parseTestSpec( std::string const& arg ) {
+ return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
+ }
+
+} // namespace Catch
+// end catch_test_spec_parser.cpp
+// start catch_timer.cpp
+
+#include <chrono>
+
+static const uint64_t nanosecondsInSecond = 1000000000;
+
+namespace Catch {
+
+ auto getCurrentNanosecondsSinceEpoch() -> uint64_t {
+ return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
+ }
+
+ namespace {
+ auto estimateClockResolution() -> uint64_t {
+ uint64_t sum = 0;
+ static const uint64_t iterations = 1000000;
+
+ auto startTime = getCurrentNanosecondsSinceEpoch();
+
+ for( std::size_t i = 0; i < iterations; ++i ) {
+
+ uint64_t ticks;
+ uint64_t baseTicks = getCurrentNanosecondsSinceEpoch();
+ do {
+ ticks = getCurrentNanosecondsSinceEpoch();
+ } while( ticks == baseTicks );
+
+ auto delta = ticks - baseTicks;
+ sum += delta;
+
+ // If we have been calibrating for over 3 seconds -- the clock
+ // is terrible and we should move on.
+ // TBD: How to signal that the measured resolution is probably wrong?
+ if (ticks > startTime + 3 * nanosecondsInSecond) {
+ return sum / ( i + 1u );
+ }
+ }
+
+ // We're just taking the mean, here. To do better we could take the std. dev and exclude outliers
+ // - and potentially do more iterations if there's a high variance.
+ return sum/iterations;
+ }
+ }
+ auto getEstimatedClockResolution() -> uint64_t {
+ static auto s_resolution = estimateClockResolution();
+ return s_resolution;
+ }
+
+ void Timer::start() {
+ m_nanoseconds = getCurrentNanosecondsSinceEpoch();
+ }
+ auto Timer::getElapsedNanoseconds() const -> uint64_t {
+ return getCurrentNanosecondsSinceEpoch() - m_nanoseconds;
+ }
+ auto Timer::getElapsedMicroseconds() const -> uint64_t {
+ return getElapsedNanoseconds()/1000;
+ }
+ auto Timer::getElapsedMilliseconds() const -> unsigned int {
+ return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
+ }
+ auto Timer::getElapsedSeconds() const -> double {
+ return getElapsedMicroseconds()/1000000.0;
+ }
+
+} // namespace Catch
+// end catch_timer.cpp
+// start catch_tostring.cpp
+
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wexit-time-destructors"
+# pragma clang diagnostic ignored "-Wglobal-constructors"
+#endif
+
+// Enable specific decls locally
+#if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
+#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
+#endif
+
+#include <cmath>
+#include <iomanip>
+
+namespace Catch {
+
+namespace Detail {
+
+ const std::string unprintableString = "{?}";
+
+ namespace {
+ const int hexThreshold = 255;
+
+ struct Endianness {
+ enum Arch { Big, Little };
+
+ static Arch which() {
+ int one = 1;
+ // If the lowest byte we read is non-zero, we can assume
+ // that little endian format is used.
+ auto value = *reinterpret_cast<char*>(&one);
+ return value ? Little : Big;
+ }
+ };
+ }
+
+ std::string rawMemoryToString( const void *object, std::size_t size ) {
+ // Reverse order for little endian architectures
+ int i = 0, end = static_cast<int>( size ), inc = 1;
+ if( Endianness::which() == Endianness::Little ) {
+ i = end-1;
+ end = inc = -1;
+ }
+
+ unsigned char const *bytes = static_cast<unsigned char const *>(object);
+ ReusableStringStream rss;
+ rss << "0x" << std::setfill('0') << std::hex;
+ for( ; i != end; i += inc )
+ rss << std::setw(2) << static_cast<unsigned>(bytes[i]);
+ return rss.str();
+ }
+}
+
+template<typename T>
+std::string fpToString( T value, int precision ) {
+ if (Catch::isnan(value)) {
+ return "nan";
+ }
+
+ ReusableStringStream rss;
+ rss << std::setprecision( precision )
+ << std::fixed
+ << value;
+ std::string d = rss.str();
+ std::size_t i = d.find_last_not_of( '0' );
+ if( i != std::string::npos && i != d.size()-1 ) {
+ if( d[i] == '.' )
+ i++;
+ d = d.substr( 0, i+1 );
+ }
+ return d;
+}
+
+//// ======================================================= ////
+//
+// Out-of-line defs for full specialization of StringMaker
+//
+//// ======================================================= ////
+
+std::string StringMaker<std::string>::convert(const std::string& str) {
+ if (!getCurrentContext().getConfig()->showInvisibles()) {
+ return '"' + str + '"';
+ }
+
+ std::string s("\"");
+ for (char c : str) {
+ switch (c) {
+ case '\n':
+ s.append("\\n");
+ break;
+ case '\t':
+ s.append("\\t");
+ break;
+ default:
+ s.push_back(c);
+ break;
+ }
+ }
+ s.append("\"");
+ return s;
+}
+
+#ifdef CATCH_CONFIG_CPP17_STRING_VIEW
+std::string StringMaker<std::string_view>::convert(std::string_view str) {
+ return ::Catch::Detail::stringify(std::string{ str });
+}
+#endif
+
+std::string StringMaker<char const*>::convert(char const* str) {
+ if (str) {
+ return ::Catch::Detail::stringify(std::string{ str });
+ } else {
+ return{ "{null string}" };
+ }
+}
+std::string StringMaker<char*>::convert(char* str) {
+ if (str) {
+ return ::Catch::Detail::stringify(std::string{ str });
+ } else {
+ return{ "{null string}" };
+ }
+}
+
+#ifdef CATCH_CONFIG_WCHAR
+std::string StringMaker<std::wstring>::convert(const std::wstring& wstr) {
+ std::string s;
+ s.reserve(wstr.size());
+ for (auto c : wstr) {
+ s += (c <= 0xff) ? static_cast<char>(c) : '?';
+ }
+ return ::Catch::Detail::stringify(s);
+}
+
+# ifdef CATCH_CONFIG_CPP17_STRING_VIEW
+std::string StringMaker<std::wstring_view>::convert(std::wstring_view str) {
+ return StringMaker<std::wstring>::convert(std::wstring(str));
+}
+# endif
+
+std::string StringMaker<wchar_t const*>::convert(wchar_t const * str) {
+ if (str) {
+ return ::Catch::Detail::stringify(std::wstring{ str });
+ } else {
+ return{ "{null string}" };
+ }
+}
+std::string StringMaker<wchar_t *>::convert(wchar_t * str) {
+ if (str) {
+ return ::Catch::Detail::stringify(std::wstring{ str });
+ } else {
+ return{ "{null string}" };
+ }
+}
+#endif
+
+#if defined(CATCH_CONFIG_CPP17_BYTE)
+#include <cstddef>
+std::string StringMaker<std::byte>::convert(std::byte value) {
+ return ::Catch::Detail::stringify(std::to_integer<unsigned long long>(value));
+}
+#endif // defined(CATCH_CONFIG_CPP17_BYTE)
+
+std::string StringMaker<int>::convert(int value) {
+ return ::Catch::Detail::stringify(static_cast<long long>(value));
+}
+std::string StringMaker<long>::convert(long value) {
+ return ::Catch::Detail::stringify(static_cast<long long>(value));
+}
+std::string StringMaker<long long>::convert(long long value) {
+ ReusableStringStream rss;
+ rss << value;
+ if (value > Detail::hexThreshold) {
+ rss << " (0x" << std::hex << value << ')';
+ }
+ return rss.str();
+}
+
+std::string StringMaker<unsigned int>::convert(unsigned int value) {
+ return ::Catch::Detail::stringify(static_cast<unsigned long long>(value));
+}
+std::string StringMaker<unsigned long>::convert(unsigned long value) {
+ return ::Catch::Detail::stringify(static_cast<unsigned long long>(value));
+}
+std::string StringMaker<unsigned long long>::convert(unsigned long long value) {
+ ReusableStringStream rss;
+ rss << value;
+ if (value > Detail::hexThreshold) {
+ rss << " (0x" << std::hex << value << ')';
+ }
+ return rss.str();
+}
+
+std::string StringMaker<bool>::convert(bool b) {
+ return b ? "true" : "false";
+}
+
+std::string StringMaker<signed char>::convert(signed char value) {
+ if (value == '\r') {
+ return "'\\r'";
+ } else if (value == '\f') {
+ return "'\\f'";
+ } else if (value == '\n') {
+ return "'\\n'";
+ } else if (value == '\t') {
+ return "'\\t'";
+ } else if ('\0' <= value && value < ' ') {
+ return ::Catch::Detail::stringify(static_cast<unsigned int>(value));
+ } else {
+ char chstr[] = "' '";
+ chstr[1] = value;
+ return chstr;
+ }
+}
+std::string StringMaker<char>::convert(char c) {
+ return ::Catch::Detail::stringify(static_cast<signed char>(c));
+}
+std::string StringMaker<unsigned char>::convert(unsigned char c) {
+ return ::Catch::Detail::stringify(static_cast<char>(c));
+}
+
+std::string StringMaker<std::nullptr_t>::convert(std::nullptr_t) {
+ return "nullptr";
+}
+
+int StringMaker<float>::precision = 5;
+
+std::string StringMaker<float>::convert(float value) {
+ return fpToString(value, precision) + 'f';
+}
+
+int StringMaker<double>::precision = 10;
+
+std::string StringMaker<double>::convert(double value) {
+ return fpToString(value, precision);
+}
+
+std::string ratio_string<std::atto>::symbol() { return "a"; }
+std::string ratio_string<std::femto>::symbol() { return "f"; }
+std::string ratio_string<std::pico>::symbol() { return "p"; }
+std::string ratio_string<std::nano>::symbol() { return "n"; }
+std::string ratio_string<std::micro>::symbol() { return "u"; }
+std::string ratio_string<std::milli>::symbol() { return "m"; }
+
+} // end namespace Catch
+
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
+// end catch_tostring.cpp
+// start catch_totals.cpp
+
+namespace Catch {
+
+ Counts Counts::operator - ( Counts const& other ) const {
+ Counts diff;
+ diff.passed = passed - other.passed;
+ diff.failed = failed - other.failed;
+ diff.failedButOk = failedButOk - other.failedButOk;
+ return diff;
+ }
+
+ Counts& Counts::operator += ( Counts const& other ) {
+ passed += other.passed;
+ failed += other.failed;
+ failedButOk += other.failedButOk;
+ return *this;
+ }
+
+ std::size_t Counts::total() const {
+ return passed + failed + failedButOk;
+ }
+ bool Counts::allPassed() const {
+ return failed == 0 && failedButOk == 0;
+ }
+ bool Counts::allOk() const {
+ return failed == 0;
+ }
+
+ Totals Totals::operator - ( Totals const& other ) const {
+ Totals diff;
+ diff.assertions = assertions - other.assertions;
+ diff.testCases = testCases - other.testCases;
+ return diff;
+ }
+
+ Totals& Totals::operator += ( Totals const& other ) {
+ assertions += other.assertions;
+ testCases += other.testCases;
+ return *this;
+ }
+
+ Totals Totals::delta( Totals const& prevTotals ) const {
+ Totals diff = *this - prevTotals;
+ if( diff.assertions.failed > 0 )
+ ++diff.testCases.failed;
+ else if( diff.assertions.failedButOk > 0 )
+ ++diff.testCases.failedButOk;
+ else
+ ++diff.testCases.passed;
+ return diff;
+ }
+
+}
+// end catch_totals.cpp
+// start catch_uncaught_exceptions.cpp
+
+// start catch_config_uncaught_exceptions.hpp
+
+// Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+
+#ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP
+#define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP
+
+#if defined(_MSC_VER)
+# if _MSC_VER >= 1900 // Visual Studio 2015 or newer
+# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
+# endif
+#endif
+
+#include <exception>
+
+#if defined(__cpp_lib_uncaught_exceptions) \
+ && !defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
+
+# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
+#endif // __cpp_lib_uncaught_exceptions
+
+#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) \
+ && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) \
+ && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
+
+# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
+#endif
+
+#endif // CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP
+// end catch_config_uncaught_exceptions.hpp
+#include <exception>
+
+namespace Catch {
+ bool uncaught_exceptions() {
+#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+ return false;
+#elif defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
+ return std::uncaught_exceptions() > 0;
+#else
+ return std::uncaught_exception();
+#endif
+ }
+} // end namespace Catch
+// end catch_uncaught_exceptions.cpp
+// start catch_version.cpp
+
+#include <ostream>
+
+namespace Catch {
+
+ Version::Version
+ ( unsigned int _majorVersion,
+ unsigned int _minorVersion,
+ unsigned int _patchNumber,
+ char const * const _branchName,
+ unsigned int _buildNumber )
+ : majorVersion( _majorVersion ),
+ minorVersion( _minorVersion ),
+ patchNumber( _patchNumber ),
+ branchName( _branchName ),
+ buildNumber( _buildNumber )
+ {}
+
+ std::ostream& operator << ( std::ostream& os, Version const& version ) {
+ os << version.majorVersion << '.'
+ << version.minorVersion << '.'
+ << version.patchNumber;
+ // branchName is never null -> 0th char is \0 if it is empty
+ if (version.branchName[0]) {
+ os << '-' << version.branchName
+ << '.' << version.buildNumber;
+ }
+ return os;
+ }
+
+ Version const& libraryVersion() {
+ static Version version( 2, 13, 8, "", 0 );
+ return version;
+ }
+
+}
+// end catch_version.cpp
+// start catch_wildcard_pattern.cpp
+
+namespace Catch {
+
+ WildcardPattern::WildcardPattern( std::string const& pattern,
+ CaseSensitive::Choice caseSensitivity )
+ : m_caseSensitivity( caseSensitivity ),
+ m_pattern( normaliseString( pattern ) )
+ {
+ if( startsWith( m_pattern, '*' ) ) {
+ m_pattern = m_pattern.substr( 1 );
+ m_wildcard = WildcardAtStart;
+ }
+ if( endsWith( m_pattern, '*' ) ) {
+ m_pattern = m_pattern.substr( 0, m_pattern.size()-1 );
+ m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd );
+ }
+ }
+
+ bool WildcardPattern::matches( std::string const& str ) const {
+ switch( m_wildcard ) {
+ case NoWildcard:
+ return m_pattern == normaliseString( str );
+ case WildcardAtStart:
+ return endsWith( normaliseString( str ), m_pattern );
+ case WildcardAtEnd:
+ return startsWith( normaliseString( str ), m_pattern );
+ case WildcardAtBothEnds:
+ return contains( normaliseString( str ), m_pattern );
+ default:
+ CATCH_INTERNAL_ERROR( "Unknown enum" );
+ }
+ }
+
+ std::string WildcardPattern::normaliseString( std::string const& str ) const {
+ return trim( m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str );
+ }
+}
+// end catch_wildcard_pattern.cpp
+// start catch_xmlwriter.cpp
+
+#include <iomanip>
+#include <type_traits>
+
+namespace Catch {
+
+namespace {
+
+ size_t trailingBytes(unsigned char c) {
+ if ((c & 0xE0) == 0xC0) {
+ return 2;
+ }
+ if ((c & 0xF0) == 0xE0) {
+ return 3;
+ }
+ if ((c & 0xF8) == 0xF0) {
+ return 4;
+ }
+ CATCH_INTERNAL_ERROR("Invalid multibyte utf-8 start byte encountered");
+ }
+
+ uint32_t headerValue(unsigned char c) {
+ if ((c & 0xE0) == 0xC0) {
+ return c & 0x1F;
+ }
+ if ((c & 0xF0) == 0xE0) {
+ return c & 0x0F;
+ }
+ if ((c & 0xF8) == 0xF0) {
+ return c & 0x07;
+ }
+ CATCH_INTERNAL_ERROR("Invalid multibyte utf-8 start byte encountered");
+ }
+
+ void hexEscapeChar(std::ostream& os, unsigned char c) {
+ std::ios_base::fmtflags f(os.flags());
+ os << "\\x"
+ << std::uppercase << std::hex << std::setfill('0') << std::setw(2)
+ << static_cast<int>(c);
+ os.flags(f);
+ }
+
+ bool shouldNewline(XmlFormatting fmt) {
+ return !!(static_cast<std::underlying_type<XmlFormatting>::type>(fmt & XmlFormatting::Newline));
+ }
+
+ bool shouldIndent(XmlFormatting fmt) {
+ return !!(static_cast<std::underlying_type<XmlFormatting>::type>(fmt & XmlFormatting::Indent));
+ }
+
+} // anonymous namespace
+
+ XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs) {
+ return static_cast<XmlFormatting>(
+ static_cast<std::underlying_type<XmlFormatting>::type>(lhs) |
+ static_cast<std::underlying_type<XmlFormatting>::type>(rhs)
+ );
+ }
+
+ XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs) {
+ return static_cast<XmlFormatting>(
+ static_cast<std::underlying_type<XmlFormatting>::type>(lhs) &
+ static_cast<std::underlying_type<XmlFormatting>::type>(rhs)
+ );
+ }
+
+ XmlEncode::XmlEncode( std::string const& str, ForWhat forWhat )
+ : m_str( str ),
+ m_forWhat( forWhat )
+ {}
+
+ void XmlEncode::encodeTo( std::ostream& os ) const {
+ // Apostrophe escaping not necessary if we always use " to write attributes
+ // (see: http://www.w3.org/TR/xml/#syntax)
+
+ for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) {
+ unsigned char c = m_str[idx];
+ switch (c) {
+ case '<': os << "&lt;"; break;
+ case '&': os << "&amp;"; break;
+
+ case '>':
+ // See: http://www.w3.org/TR/xml/#syntax
+ if (idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']')
+ os << "&gt;";
+ else
+ os << c;
+ break;
+
+ case '\"':
+ if (m_forWhat == ForAttributes)
+ os << "&quot;";
+ else
+ os << c;
+ break;
+
+ default:
+ // Check for control characters and invalid utf-8
+
+ // Escape control characters in standard ascii
+ // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
+ if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) {
+ hexEscapeChar(os, c);
+ break;
+ }
+
+ // Plain ASCII: Write it to stream
+ if (c < 0x7F) {
+ os << c;
+ break;
+ }
+
+ // UTF-8 territory
+ // Check if the encoding is valid and if it is not, hex escape bytes.
+ // Important: We do not check the exact decoded values for validity, only the encoding format
+ // First check that this bytes is a valid lead byte:
+ // This means that it is not encoded as 1111 1XXX
+ // Or as 10XX XXXX
+ if (c < 0xC0 ||
+ c >= 0xF8) {
+ hexEscapeChar(os, c);
+ break;
+ }
+
+ auto encBytes = trailingBytes(c);
+ // Are there enough bytes left to avoid accessing out-of-bounds memory?
+ if (idx + encBytes - 1 >= m_str.size()) {
+ hexEscapeChar(os, c);
+ break;
+ }
+ // The header is valid, check data
+ // The next encBytes bytes must together be a valid utf-8
+ // This means: bitpattern 10XX XXXX and the extracted value is sane (ish)
+ bool valid = true;
+ uint32_t value = headerValue(c);
+ for (std::size_t n = 1; n < encBytes; ++n) {
+ unsigned char nc = m_str[idx + n];
+ valid &= ((nc & 0xC0) == 0x80);
+ value = (value << 6) | (nc & 0x3F);
+ }
+
+ if (
+ // Wrong bit pattern of following bytes
+ (!valid) ||
+ // Overlong encodings
+ (value < 0x80) ||
+ (0x80 <= value && value < 0x800 && encBytes > 2) ||
+ (0x800 < value && value < 0x10000 && encBytes > 3) ||
+ // Encoded value out of range
+ (value >= 0x110000)
+ ) {
+ hexEscapeChar(os, c);
+ break;
+ }
+
+ // If we got here, this is in fact a valid(ish) utf-8 sequence
+ for (std::size_t n = 0; n < encBytes; ++n) {
+ os << m_str[idx + n];
+ }
+ idx += encBytes - 1;
+ break;
+ }
+ }
+ }
+
+ std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) {
+ xmlEncode.encodeTo( os );
+ return os;
+ }
+
+ XmlWriter::ScopedElement::ScopedElement( XmlWriter* writer, XmlFormatting fmt )
+ : m_writer( writer ),
+ m_fmt(fmt)
+ {}
+
+ XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept
+ : m_writer( other.m_writer ),
+ m_fmt(other.m_fmt)
+ {
+ other.m_writer = nullptr;
+ other.m_fmt = XmlFormatting::None;
+ }
+ XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept {
+ if ( m_writer ) {
+ m_writer->endElement();
+ }
+ m_writer = other.m_writer;
+ other.m_writer = nullptr;
+ m_fmt = other.m_fmt;
+ other.m_fmt = XmlFormatting::None;
+ return *this;
+ }
+
+ XmlWriter::ScopedElement::~ScopedElement() {
+ if (m_writer) {
+ m_writer->endElement(m_fmt);
+ }
+ }
+
+ XmlWriter::ScopedElement& XmlWriter::ScopedElement::writeText( std::string const& text, XmlFormatting fmt ) {
+ m_writer->writeText( text, fmt );
+ return *this;
+ }
+
+ XmlWriter::XmlWriter( std::ostream& os ) : m_os( os )
+ {
+ writeDeclaration();
+ }
+
+ XmlWriter::~XmlWriter() {
+ while (!m_tags.empty()) {
+ endElement();
+ }
+ newlineIfNecessary();
+ }
+
+ XmlWriter& XmlWriter::startElement( std::string const& name, XmlFormatting fmt ) {
+ ensureTagClosed();
+ newlineIfNecessary();
+ if (shouldIndent(fmt)) {
+ m_os << m_indent;
+ m_indent += " ";
+ }
+ m_os << '<' << name;
+ m_tags.push_back( name );
+ m_tagIsOpen = true;
+ applyFormatting(fmt);
+ return *this;
+ }
+
+ XmlWriter::ScopedElement XmlWriter::scopedElement( std::string const& name, XmlFormatting fmt ) {
+ ScopedElement scoped( this, fmt );
+ startElement( name, fmt );
+ return scoped;
+ }
+
+ XmlWriter& XmlWriter::endElement(XmlFormatting fmt) {
+ m_indent = m_indent.substr(0, m_indent.size() - 2);
+
+ if( m_tagIsOpen ) {
+ m_os << "/>";
+ m_tagIsOpen = false;
+ } else {
+ newlineIfNecessary();
+ if (shouldIndent(fmt)) {
+ m_os << m_indent;
+ }
+ m_os << "</" << m_tags.back() << ">";
+ }
+ m_os << std::flush;
+ applyFormatting(fmt);
+ m_tags.pop_back();
+ return *this;
+ }
+
+ XmlWriter& XmlWriter::writeAttribute( std::string const& name, std::string const& attribute ) {
+ if( !name.empty() && !attribute.empty() )
+ m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"';
+ return *this;
+ }
+
+ XmlWriter& XmlWriter::writeAttribute( std::string const& name, bool attribute ) {
+ m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"';
+ return *this;
+ }
+
+ XmlWriter& XmlWriter::writeText( std::string const& text, XmlFormatting fmt) {
+ if( !text.empty() ){
+ bool tagWasOpen = m_tagIsOpen;
+ ensureTagClosed();
+ if (tagWasOpen && shouldIndent(fmt)) {
+ m_os << m_indent;
+ }
+ m_os << XmlEncode( text );
+ applyFormatting(fmt);
+ }
+ return *this;
+ }
+
+ XmlWriter& XmlWriter::writeComment( std::string const& text, XmlFormatting fmt) {
+ ensureTagClosed();
+ if (shouldIndent(fmt)) {
+ m_os << m_indent;
+ }
+ m_os << "<!--" << text << "-->";
+ applyFormatting(fmt);
+ return *this;
+ }
+
+ void XmlWriter::writeStylesheetRef( std::string const& url ) {
+ m_os << "<?xml-stylesheet type=\"text/xsl\" href=\"" << url << "\"?>\n";
+ }
+
+ XmlWriter& XmlWriter::writeBlankLine() {
+ ensureTagClosed();
+ m_os << '\n';
+ return *this;
+ }
+
+ void XmlWriter::ensureTagClosed() {
+ if( m_tagIsOpen ) {
+ m_os << '>' << std::flush;
+ newlineIfNecessary();
+ m_tagIsOpen = false;
+ }
+ }
+
+ void XmlWriter::applyFormatting(XmlFormatting fmt) {
+ m_needsNewline = shouldNewline(fmt);
+ }
+
+ void XmlWriter::writeDeclaration() {
+ m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ }
+
+ void XmlWriter::newlineIfNecessary() {
+ if( m_needsNewline ) {
+ m_os << std::endl;
+ m_needsNewline = false;
+ }
+ }
+}
+// end catch_xmlwriter.cpp
+// start catch_reporter_bases.cpp
+
+#include <cstring>
+#include <cfloat>
+#include <cstdio>
+#include <cassert>
+#include <memory>
+
+namespace Catch {
+ void prepareExpandedExpression(AssertionResult& result) {
+ result.getExpandedExpression();
+ }
+
+ // Because formatting using c++ streams is stateful, drop down to C is required
+ // Alternatively we could use stringstream, but its performance is... not good.
+ std::string getFormattedDuration( double duration ) {
+ // Max exponent + 1 is required to represent the whole part
+ // + 1 for decimal point
+ // + 3 for the 3 decimal places
+ // + 1 for null terminator
+ const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
+ char buffer[maxDoubleSize];
+
+ // Save previous errno, to prevent sprintf from overwriting it
+ ErrnoGuard guard;
+#ifdef _MSC_VER
+ sprintf_s(buffer, "%.3f", duration);
+#else
+ std::sprintf(buffer, "%.3f", duration);
+#endif
+ return std::string(buffer);
+ }
+
+ bool shouldShowDuration( IConfig const& config, double duration ) {
+ if ( config.showDurations() == ShowDurations::Always ) {
+ return true;
+ }
+ if ( config.showDurations() == ShowDurations::Never ) {
+ return false;
+ }
+ const double min = config.minDuration();
+ return min >= 0 && duration >= min;
+ }
+
+ std::string serializeFilters( std::vector<std::string> const& container ) {
+ ReusableStringStream oss;
+ bool first = true;
+ for (auto&& filter : container)
+ {
+ if (!first)
+ oss << ' ';
+ else
+ first = false;
+
+ oss << filter;
+ }
+ return oss.str();
+ }
+
+ TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config)
+ :StreamingReporterBase(_config) {}
+
+ std::set<Verbosity> TestEventListenerBase::getSupportedVerbosities() {
+ return { Verbosity::Quiet, Verbosity::Normal, Verbosity::High };
+ }
+
+ void TestEventListenerBase::assertionStarting(AssertionInfo const &) {}
+
+ bool TestEventListenerBase::assertionEnded(AssertionStats const &) {
+ return false;
+ }
+
+} // end namespace Catch
+// end catch_reporter_bases.cpp
+// start catch_reporter_compact.cpp
+
+namespace {
+
+#ifdef CATCH_PLATFORM_MAC
+ const char* failedString() { return "FAILED"; }
+ const char* passedString() { return "PASSED"; }
+#else
+ const char* failedString() { return "failed"; }
+ const char* passedString() { return "passed"; }
+#endif
+
+ // Colour::LightGrey
+ Catch::Colour::Code dimColour() { return Catch::Colour::FileName; }
+
+ std::string bothOrAll( std::size_t count ) {
+ return count == 1 ? std::string() :
+ count == 2 ? "both " : "all " ;
+ }
+
+} // anon namespace
+
+namespace Catch {
+namespace {
+// Colour, message variants:
+// - white: No tests ran.
+// - red: Failed [both/all] N test cases, failed [both/all] M assertions.
+// - white: Passed [both/all] N test cases (no assertions).
+// - red: Failed N tests cases, failed M assertions.
+// - green: Passed [both/all] N tests cases with M assertions.
+void printTotals(std::ostream& out, const Totals& totals) {
+ if (totals.testCases.total() == 0) {
+ out << "No tests ran.";
+ } else if (totals.testCases.failed == totals.testCases.total()) {
+ Colour colour(Colour::ResultError);
+ const std::string qualify_assertions_failed =
+ totals.assertions.failed == totals.assertions.total() ?
+ bothOrAll(totals.assertions.failed) : std::string();
+ out <<
+ "Failed " << bothOrAll(totals.testCases.failed)
+ << pluralise(totals.testCases.failed, "test case") << ", "
+ "failed " << qualify_assertions_failed <<
+ pluralise(totals.assertions.failed, "assertion") << '.';
+ } else if (totals.assertions.total() == 0) {
+ out <<
+ "Passed " << bothOrAll(totals.testCases.total())
+ << pluralise(totals.testCases.total(), "test case")
+ << " (no assertions).";
+ } else if (totals.assertions.failed) {
+ Colour colour(Colour::ResultError);
+ out <<
+ "Failed " << pluralise(totals.testCases.failed, "test case") << ", "
+ "failed " << pluralise(totals.assertions.failed, "assertion") << '.';
+ } else {
+ Colour colour(Colour::ResultSuccess);
+ out <<
+ "Passed " << bothOrAll(totals.testCases.passed)
+ << pluralise(totals.testCases.passed, "test case") <<
+ " with " << pluralise(totals.assertions.passed, "assertion") << '.';
+ }
+}
+
+// Implementation of CompactReporter formatting
+class AssertionPrinter {
+public:
+ AssertionPrinter& operator= (AssertionPrinter const&) = delete;
+ AssertionPrinter(AssertionPrinter const&) = delete;
+ AssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages)
+ : stream(_stream)
+ , result(_stats.assertionResult)
+ , messages(_stats.infoMessages)
+ , itMessage(_stats.infoMessages.begin())
+ , printInfoMessages(_printInfoMessages) {}
+
+ void print() {
+ printSourceInfo();
+
+ itMessage = messages.begin();
+
+ switch (result.getResultType()) {
+ case ResultWas::Ok:
+ printResultType(Colour::ResultSuccess, passedString());
+ printOriginalExpression();
+ printReconstructedExpression();
+ if (!result.hasExpression())
+ printRemainingMessages(Colour::None);
+ else
+ printRemainingMessages();
+ break;
+ case ResultWas::ExpressionFailed:
+ if (result.isOk())
+ printResultType(Colour::ResultSuccess, failedString() + std::string(" - but was ok"));
+ else
+ printResultType(Colour::Error, failedString());
+ printOriginalExpression();
+ printReconstructedExpression();
+ printRemainingMessages();
+ break;
+ case ResultWas::ThrewException:
+ printResultType(Colour::Error, failedString());
+ printIssue("unexpected exception with message:");
+ printMessage();
+ printExpressionWas();
+ printRemainingMessages();
+ break;
+ case ResultWas::FatalErrorCondition:
+ printResultType(Colour::Error, failedString());
+ printIssue("fatal error condition with message:");
+ printMessage();
+ printExpressionWas();
+ printRemainingMessages();
+ break;
+ case ResultWas::DidntThrowException:
+ printResultType(Colour::Error, failedString());
+ printIssue("expected exception, got none");
+ printExpressionWas();
+ printRemainingMessages();
+ break;
+ case ResultWas::Info:
+ printResultType(Colour::None, "info");
+ printMessage();
+ printRemainingMessages();
+ break;
+ case ResultWas::Warning:
+ printResultType(Colour::None, "warning");
+ printMessage();
+ printRemainingMessages();
+ break;
+ case ResultWas::ExplicitFailure:
+ printResultType(Colour::Error, failedString());
+ printIssue("explicitly");
+ printRemainingMessages(Colour::None);
+ break;
+ // These cases are here to prevent compiler warnings
+ case ResultWas::Unknown:
+ case ResultWas::FailureBit:
+ case ResultWas::Exception:
+ printResultType(Colour::Error, "** internal error **");
+ break;
+ }
+ }
+
+private:
+ void printSourceInfo() const {
+ Colour colourGuard(Colour::FileName);
+ stream << result.getSourceInfo() << ':';
+ }
+
+ void printResultType(Colour::Code colour, std::string const& passOrFail) const {
+ if (!passOrFail.empty()) {
+ {
+ Colour colourGuard(colour);
+ stream << ' ' << passOrFail;
+ }
+ stream << ':';
+ }
+ }
+
+ void printIssue(std::string const& issue) const {
+ stream << ' ' << issue;
+ }
+
+ void printExpressionWas() {
+ if (result.hasExpression()) {
+ stream << ';';
+ {
+ Colour colour(dimColour());
+ stream << " expression was:";
+ }
+ printOriginalExpression();
+ }
+ }
+
+ void printOriginalExpression() const {
+ if (result.hasExpression()) {
+ stream << ' ' << result.getExpression();
+ }
+ }
+
+ void printReconstructedExpression() const {
+ if (result.hasExpandedExpression()) {
+ {
+ Colour colour(dimColour());
+ stream << " for: ";
+ }
+ stream << result.getExpandedExpression();
+ }
+ }
+
+ void printMessage() {
+ if (itMessage != messages.end()) {
+ stream << " '" << itMessage->message << '\'';
+ ++itMessage;
+ }
+ }
+
+ void printRemainingMessages(Colour::Code colour = dimColour()) {
+ if (itMessage == messages.end())
+ return;
+
+ const auto itEnd = messages.cend();
+ const auto N = static_cast<std::size_t>(std::distance(itMessage, itEnd));
+
+ {
+ Colour colourGuard(colour);
+ stream << " with " << pluralise(N, "message") << ':';
+ }
+
+ while (itMessage != itEnd) {
+ // If this assertion is a warning ignore any INFO messages
+ if (printInfoMessages || itMessage->type != ResultWas::Info) {
+ printMessage();
+ if (itMessage != itEnd) {
+ Colour colourGuard(dimColour());
+ stream << " and";
+ }
+ continue;
+ }
+ ++itMessage;
+ }
+ }
+
+private:
+ std::ostream& stream;
+ AssertionResult const& result;
+ std::vector<MessageInfo> messages;
+ std::vector<MessageInfo>::const_iterator itMessage;
+ bool printInfoMessages;
+};
+
+} // anon namespace
+
+ std::string CompactReporter::getDescription() {
+ return "Reports test results on a single line, suitable for IDEs";
+ }
+
+ void CompactReporter::noMatchingTestCases( std::string const& spec ) {
+ stream << "No test cases matched '" << spec << '\'' << std::endl;
+ }
+
+ void CompactReporter::assertionStarting( AssertionInfo const& ) {}
+
+ bool CompactReporter::assertionEnded( AssertionStats const& _assertionStats ) {
+ AssertionResult const& result = _assertionStats.assertionResult;
+
+ bool printInfoMessages = true;
+
+ // Drop out if result was successful and we're not printing those
+ if( !m_config->includeSuccessfulResults() && result.isOk() ) {
+ if( result.getResultType() != ResultWas::Warning )
+ return false;
+ printInfoMessages = false;
+ }
+
+ AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
+ printer.print();
+
+ stream << std::endl;
+ return true;
+ }
+
+ void CompactReporter::sectionEnded(SectionStats const& _sectionStats) {
+ double dur = _sectionStats.durationInSeconds;
+ if ( shouldShowDuration( *m_config, dur ) ) {
+ stream << getFormattedDuration( dur ) << " s: " << _sectionStats.sectionInfo.name << std::endl;
+ }
+ }
+
+ void CompactReporter::testRunEnded( TestRunStats const& _testRunStats ) {
+ printTotals( stream, _testRunStats.totals );
+ stream << '\n' << std::endl;
+ StreamingReporterBase::testRunEnded( _testRunStats );
+ }
+
+ CompactReporter::~CompactReporter() {}
+
+ CATCH_REGISTER_REPORTER( "compact", CompactReporter )
+
+} // end namespace Catch
+// end catch_reporter_compact.cpp
+// start catch_reporter_console.cpp
+
+#include <cfloat>
+#include <cstdio>
+
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch
+ // Note that 4062 (not all labels are handled and default is missing) is enabled
+#endif
+
+#if defined(__clang__)
+# pragma clang diagnostic push
+// For simplicity, benchmarking-only helpers are always enabled
+# pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
+namespace Catch {
+
+namespace {
+
+// Formatter impl for ConsoleReporter
+class ConsoleAssertionPrinter {
+public:
+ ConsoleAssertionPrinter& operator= (ConsoleAssertionPrinter const&) = delete;
+ ConsoleAssertionPrinter(ConsoleAssertionPrinter const&) = delete;
+ ConsoleAssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages)
+ : stream(_stream),
+ stats(_stats),
+ result(_stats.assertionResult),
+ colour(Colour::None),
+ message(result.getMessage()),
+ messages(_stats.infoMessages),
+ printInfoMessages(_printInfoMessages) {
+ switch (result.getResultType()) {
+ case ResultWas::Ok:
+ colour = Colour::Success;
+ passOrFail = "PASSED";
+ //if( result.hasMessage() )
+ if (_stats.infoMessages.size() == 1)
+ messageLabel = "with message";
+ if (_stats.infoMessages.size() > 1)
+ messageLabel = "with messages";
+ break;
+ case ResultWas::ExpressionFailed:
+ if (result.isOk()) {
+ colour = Colour::Success;
+ passOrFail = "FAILED - but was ok";
+ } else {
+ colour = Colour::Error;
+ passOrFail = "FAILED";
+ }
+ if (_stats.infoMessages.size() == 1)
+ messageLabel = "with message";
+ if (_stats.infoMessages.size() > 1)
+ messageLabel = "with messages";
+ break;
+ case ResultWas::ThrewException:
+ colour = Colour::Error;
+ passOrFail = "FAILED";
+ messageLabel = "due to unexpected exception with ";
+ if (_stats.infoMessages.size() == 1)
+ messageLabel += "message";
+ if (_stats.infoMessages.size() > 1)
+ messageLabel += "messages";
+ break;
+ case ResultWas::FatalErrorCondition:
+ colour = Colour::Error;
+ passOrFail = "FAILED";
+ messageLabel = "due to a fatal error condition";
+ break;
+ case ResultWas::DidntThrowException:
+ colour = Colour::Error;
+ passOrFail = "FAILED";
+ messageLabel = "because no exception was thrown where one was expected";
+ break;
+ case ResultWas::Info:
+ messageLabel = "info";
+ break;
+ case ResultWas::Warning:
+ messageLabel = "warning";
+ break;
+ case ResultWas::ExplicitFailure:
+ passOrFail = "FAILED";
+ colour = Colour::Error;
+ if (_stats.infoMessages.size() == 1)
+ messageLabel = "explicitly with message";
+ if (_stats.infoMessages.size() > 1)
+ messageLabel = "explicitly with messages";
+ break;
+ // These cases are here to prevent compiler warnings
+ case ResultWas::Unknown:
+ case ResultWas::FailureBit:
+ case ResultWas::Exception:
+ passOrFail = "** internal error **";
+ colour = Colour::Error;
+ break;
+ }
+ }
+
+ void print() const {
+ printSourceInfo();
+ if (stats.totals.assertions.total() > 0) {
+ printResultType();
+ printOriginalExpression();
+ printReconstructedExpression();
+ } else {
+ stream << '\n';
+ }
+ printMessage();
+ }
+
+private:
+ void printResultType() const {
+ if (!passOrFail.empty()) {
+ Colour colourGuard(colour);
+ stream << passOrFail << ":\n";
+ }
+ }
+ void printOriginalExpression() const {
+ if (result.hasExpression()) {
+ Colour colourGuard(Colour::OriginalExpression);
+ stream << " ";
+ stream << result.getExpressionInMacro();
+ stream << '\n';
+ }
+ }
+ void printReconstructedExpression() const {
+ if (result.hasExpandedExpression()) {
+ stream << "with expansion:\n";
+ Colour colourGuard(Colour::ReconstructedExpression);
+ stream << Column(result.getExpandedExpression()).indent(2) << '\n';
+ }
+ }
+ void printMessage() const {
+ if (!messageLabel.empty())
+ stream << messageLabel << ':' << '\n';
+ for (auto const& msg : messages) {
+ // If this assertion is a warning ignore any INFO messages
+ if (printInfoMessages || msg.type != ResultWas::Info)
+ stream << Column(msg.message).indent(2) << '\n';
+ }
+ }
+ void printSourceInfo() const {
+ Colour colourGuard(Colour::FileName);
+ stream << result.getSourceInfo() << ": ";
+ }
+
+ std::ostream& stream;
+ AssertionStats const& stats;
+ AssertionResult const& result;
+ Colour::Code colour;
+ std::string passOrFail;
+ std::string messageLabel;
+ std::string message;
+ std::vector<MessageInfo> messages;
+ bool printInfoMessages;
+};
+
+std::size_t makeRatio(std::size_t number, std::size_t total) {
+ std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0;
+ return (ratio == 0 && number > 0) ? 1 : ratio;
+}
+
+std::size_t& findMax(std::size_t& i, std::size_t& j, std::size_t& k) {
+ if (i > j && i > k)
+ return i;
+ else if (j > k)
+ return j;
+ else
+ return k;
+}
+
+struct ColumnInfo {
+ enum Justification { Left, Right };
+ std::string name;
+ int width;
+ Justification justification;
+};
+struct ColumnBreak {};
+struct RowBreak {};
+
+class Duration {
+ enum class Unit {
+ Auto,
+ Nanoseconds,
+ Microseconds,
+ Milliseconds,
+ Seconds,
+ Minutes
+ };
+ static const uint64_t s_nanosecondsInAMicrosecond = 1000;
+ static const uint64_t s_nanosecondsInAMillisecond = 1000 * s_nanosecondsInAMicrosecond;
+ static const uint64_t s_nanosecondsInASecond = 1000 * s_nanosecondsInAMillisecond;
+ static const uint64_t s_nanosecondsInAMinute = 60 * s_nanosecondsInASecond;
+
+ double m_inNanoseconds;
+ Unit m_units;
+
+public:
+ explicit Duration(double inNanoseconds, Unit units = Unit::Auto)
+ : m_inNanoseconds(inNanoseconds),
+ m_units(units) {
+ if (m_units == Unit::Auto) {
+ if (m_inNanoseconds < s_nanosecondsInAMicrosecond)
+ m_units = Unit::Nanoseconds;
+ else if (m_inNanoseconds < s_nanosecondsInAMillisecond)
+ m_units = Unit::Microseconds;
+ else if (m_inNanoseconds < s_nanosecondsInASecond)
+ m_units = Unit::Milliseconds;
+ else if (m_inNanoseconds < s_nanosecondsInAMinute)
+ m_units = Unit::Seconds;
+ else
+ m_units = Unit::Minutes;
+ }
+
+ }
+
+ auto value() const -> double {
+ switch (m_units) {
+ case Unit::Microseconds:
+ return m_inNanoseconds / static_cast<double>(s_nanosecondsInAMicrosecond);
+ case Unit::Milliseconds:
+ return m_inNanoseconds / static_cast<double>(s_nanosecondsInAMillisecond);
+ case Unit::Seconds:
+ return m_inNanoseconds / static_cast<double>(s_nanosecondsInASecond);
+ case Unit::Minutes:
+ return m_inNanoseconds / static_cast<double>(s_nanosecondsInAMinute);
+ default:
+ return m_inNanoseconds;
+ }
+ }
+ auto unitsAsString() const -> std::string {
+ switch (m_units) {
+ case Unit::Nanoseconds:
+ return "ns";
+ case Unit::Microseconds:
+ return "us";
+ case Unit::Milliseconds:
+ return "ms";
+ case Unit::Seconds:
+ return "s";
+ case Unit::Minutes:
+ return "m";
+ default:
+ return "** internal error **";
+ }
+
+ }
+ friend auto operator << (std::ostream& os, Duration const& duration) -> std::ostream& {
+ return os << duration.value() << ' ' << duration.unitsAsString();
+ }
+};
+} // end anon namespace
+
+class TablePrinter {
+ std::ostream& m_os;
+ std::vector<ColumnInfo> m_columnInfos;
+ std::ostringstream m_oss;
+ int m_currentColumn = -1;
+ bool m_isOpen = false;
+
+public:
+ TablePrinter( std::ostream& os, std::vector<ColumnInfo> columnInfos )
+ : m_os( os ),
+ m_columnInfos( std::move( columnInfos ) ) {}
+
+ auto columnInfos() const -> std::vector<ColumnInfo> const& {
+ return m_columnInfos;
+ }
+
+ void open() {
+ if (!m_isOpen) {
+ m_isOpen = true;
+ *this << RowBreak();
+
+ Columns headerCols;
+ Spacer spacer(2);
+ for (auto const& info : m_columnInfos) {
+ headerCols += Column(info.name).width(static_cast<std::size_t>(info.width - 2));
+ headerCols += spacer;
+ }
+ m_os << headerCols << '\n';
+
+ m_os << Catch::getLineOfChars<'-'>() << '\n';
+ }
+ }
+ void close() {
+ if (m_isOpen) {
+ *this << RowBreak();
+ m_os << std::endl;
+ m_isOpen = false;
+ }
+ }
+
+ template<typename T>
+ friend TablePrinter& operator << (TablePrinter& tp, T const& value) {
+ tp.m_oss << value;
+ return tp;
+ }
+
+ friend TablePrinter& operator << (TablePrinter& tp, ColumnBreak) {
+ auto colStr = tp.m_oss.str();
+ const auto strSize = colStr.size();
+ tp.m_oss.str("");
+ tp.open();
+ if (tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size() - 1)) {
+ tp.m_currentColumn = -1;
+ tp.m_os << '\n';
+ }
+ tp.m_currentColumn++;
+
+ auto colInfo = tp.m_columnInfos[tp.m_currentColumn];
+ auto padding = (strSize + 1 < static_cast<std::size_t>(colInfo.width))
+ ? std::string(colInfo.width - (strSize + 1), ' ')
+ : std::string();
+ if (colInfo.justification == ColumnInfo::Left)
+ tp.m_os << colStr << padding << ' ';
+ else
+ tp.m_os << padding << colStr << ' ';
+ return tp;
+ }
+
+ friend TablePrinter& operator << (TablePrinter& tp, RowBreak) {
+ if (tp.m_currentColumn > 0) {
+ tp.m_os << '\n';
+ tp.m_currentColumn = -1;
+ }
+ return tp;
+ }
+};
+
+ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
+ : StreamingReporterBase(config),
+ m_tablePrinter(new TablePrinter(config.stream(),
+ [&config]() -> std::vector<ColumnInfo> {
+ if (config.fullConfig()->benchmarkNoAnalysis())
+ {
+ return{
+ { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
+ { " samples", 14, ColumnInfo::Right },
+ { " iterations", 14, ColumnInfo::Right },
+ { " mean", 14, ColumnInfo::Right }
+ };
+ }
+ else
+ {
+ return{
+ { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
+ { "samples mean std dev", 14, ColumnInfo::Right },
+ { "iterations low mean low std dev", 14, ColumnInfo::Right },
+ { "estimated high mean high std dev", 14, ColumnInfo::Right }
+ };
+ }
+ }())) {}
+ConsoleReporter::~ConsoleReporter() = default;
+
+std::string ConsoleReporter::getDescription() {
+ return "Reports test results as plain lines of text";
+}
+
+void ConsoleReporter::noMatchingTestCases(std::string const& spec) {
+ stream << "No test cases matched '" << spec << '\'' << std::endl;
+}
+
+void ConsoleReporter::reportInvalidArguments(std::string const&arg){
+ stream << "Invalid Filter: " << arg << std::endl;
+}
+
+void ConsoleReporter::assertionStarting(AssertionInfo const&) {}
+
+bool ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) {
+ AssertionResult const& result = _assertionStats.assertionResult;
+
+ bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
+
+ // Drop out if result was successful but we're not printing them.
+ if (!includeResults && result.getResultType() != ResultWas::Warning)
+ return false;
+
+ lazyPrint();
+
+ ConsoleAssertionPrinter printer(stream, _assertionStats, includeResults);
+ printer.print();
+ stream << std::endl;
+ return true;
+}
+
+void ConsoleReporter::sectionStarting(SectionInfo const& _sectionInfo) {
+ m_tablePrinter->close();
+ m_headerPrinted = false;
+ StreamingReporterBase::sectionStarting(_sectionInfo);
+}
+void ConsoleReporter::sectionEnded(SectionStats const& _sectionStats) {
+ m_tablePrinter->close();
+ if (_sectionStats.missingAssertions) {
+ lazyPrint();
+ Colour colour(Colour::ResultError);
+ if (m_sectionStack.size() > 1)
+ stream << "\nNo assertions in section";
+ else
+ stream << "\nNo assertions in test case";
+ stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
+ }
+ double dur = _sectionStats.durationInSeconds;
+ if (shouldShowDuration(*m_config, dur)) {
+ stream << getFormattedDuration(dur) << " s: " << _sectionStats.sectionInfo.name << std::endl;
+ }
+ if (m_headerPrinted) {
+ m_headerPrinted = false;
+ }
+ StreamingReporterBase::sectionEnded(_sectionStats);
+}
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+void ConsoleReporter::benchmarkPreparing(std::string const& name) {
+ lazyPrintWithoutClosingBenchmarkTable();
+
+ auto nameCol = Column(name).width(static_cast<std::size_t>(m_tablePrinter->columnInfos()[0].width - 2));
+
+ bool firstLine = true;
+ for (auto line : nameCol) {
+ if (!firstLine)
+ (*m_tablePrinter) << ColumnBreak() << ColumnBreak() << ColumnBreak();
+ else
+ firstLine = false;
+
+ (*m_tablePrinter) << line << ColumnBreak();
+ }
+}
+
+void ConsoleReporter::benchmarkStarting(BenchmarkInfo const& info) {
+ (*m_tablePrinter) << info.samples << ColumnBreak()
+ << info.iterations << ColumnBreak();
+ if (!m_config->benchmarkNoAnalysis())
+ (*m_tablePrinter) << Duration(info.estimatedDuration) << ColumnBreak();
+}
+void ConsoleReporter::benchmarkEnded(BenchmarkStats<> const& stats) {
+ if (m_config->benchmarkNoAnalysis())
+ {
+ (*m_tablePrinter) << Duration(stats.mean.point.count()) << ColumnBreak();
+ }
+ else
+ {
+ (*m_tablePrinter) << ColumnBreak()
+ << Duration(stats.mean.point.count()) << ColumnBreak()
+ << Duration(stats.mean.lower_bound.count()) << ColumnBreak()
+ << Duration(stats.mean.upper_bound.count()) << ColumnBreak() << ColumnBreak()
+ << Duration(stats.standardDeviation.point.count()) << ColumnBreak()
+ << Duration(stats.standardDeviation.lower_bound.count()) << ColumnBreak()
+ << Duration(stats.standardDeviation.upper_bound.count()) << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak();
+ }
+}
+
+void ConsoleReporter::benchmarkFailed(std::string const& error) {
+ Colour colour(Colour::Red);
+ (*m_tablePrinter)
+ << "Benchmark failed (" << error << ')'
+ << ColumnBreak() << RowBreak();
+}
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+void ConsoleReporter::testCaseEnded(TestCaseStats const& _testCaseStats) {
+ m_tablePrinter->close();
+ StreamingReporterBase::testCaseEnded(_testCaseStats);
+ m_headerPrinted = false;
+}
+void ConsoleReporter::testGroupEnded(TestGroupStats const& _testGroupStats) {
+ if (currentGroupInfo.used) {
+ printSummaryDivider();
+ stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
+ printTotals(_testGroupStats.totals);
+ stream << '\n' << std::endl;
+ }
+ StreamingReporterBase::testGroupEnded(_testGroupStats);
+}
+void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) {
+ printTotalsDivider(_testRunStats.totals);
+ printTotals(_testRunStats.totals);
+ stream << std::endl;
+ StreamingReporterBase::testRunEnded(_testRunStats);
+}
+void ConsoleReporter::testRunStarting(TestRunInfo const& _testInfo) {
+ StreamingReporterBase::testRunStarting(_testInfo);
+ printTestFilters();
+}
+
+void ConsoleReporter::lazyPrint() {
+
+ m_tablePrinter->close();
+ lazyPrintWithoutClosingBenchmarkTable();
+}
+
+void ConsoleReporter::lazyPrintWithoutClosingBenchmarkTable() {
+
+ if (!currentTestRunInfo.used)
+ lazyPrintRunInfo();
+ if (!currentGroupInfo.used)
+ lazyPrintGroupInfo();
+
+ if (!m_headerPrinted) {
+ printTestCaseAndSectionHeader();
+ m_headerPrinted = true;
+ }
+}
+void ConsoleReporter::lazyPrintRunInfo() {
+ stream << '\n' << getLineOfChars<'~'>() << '\n';
+ Colour colour(Colour::SecondaryText);
+ stream << currentTestRunInfo->name
+ << " is a Catch v" << libraryVersion() << " host application.\n"
+ << "Run with -? for options\n\n";
+
+ if (m_config->rngSeed() != 0)
+ stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
+
+ currentTestRunInfo.used = true;
+}
+void ConsoleReporter::lazyPrintGroupInfo() {
+ if (!currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1) {
+ printClosedHeader("Group: " + currentGroupInfo->name);
+ currentGroupInfo.used = true;
+ }
+}
+void ConsoleReporter::printTestCaseAndSectionHeader() {
+ assert(!m_sectionStack.empty());
+ printOpenHeader(currentTestCaseInfo->name);
+
+ if (m_sectionStack.size() > 1) {
+ Colour colourGuard(Colour::Headers);
+
+ auto
+ it = m_sectionStack.begin() + 1, // Skip first section (test case)
+ itEnd = m_sectionStack.end();
+ for (; it != itEnd; ++it)
+ printHeaderString(it->name, 2);
+ }
+
+ SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
+
+ stream << getLineOfChars<'-'>() << '\n';
+ Colour colourGuard(Colour::FileName);
+ stream << lineInfo << '\n';
+ stream << getLineOfChars<'.'>() << '\n' << std::endl;
+}
+
+void ConsoleReporter::printClosedHeader(std::string const& _name) {
+ printOpenHeader(_name);
+ stream << getLineOfChars<'.'>() << '\n';
+}
+void ConsoleReporter::printOpenHeader(std::string const& _name) {
+ stream << getLineOfChars<'-'>() << '\n';
+ {
+ Colour colourGuard(Colour::Headers);
+ printHeaderString(_name);
+ }
+}
+
+// if string has a : in first line will set indent to follow it on
+// subsequent lines
+void ConsoleReporter::printHeaderString(std::string const& _string, std::size_t indent) {
+ std::size_t i = _string.find(": ");
+ if (i != std::string::npos)
+ i += 2;
+ else
+ i = 0;
+ stream << Column(_string).indent(indent + i).initialIndent(indent) << '\n';
+}
+
+struct SummaryColumn {
+
+ SummaryColumn( std::string _label, Colour::Code _colour )
+ : label( std::move( _label ) ),
+ colour( _colour ) {}
+ SummaryColumn addRow( std::size_t count ) {
+ ReusableStringStream rss;
+ rss << count;
+ std::string row = rss.str();
+ for (auto& oldRow : rows) {
+ while (oldRow.size() < row.size())
+ oldRow = ' ' + oldRow;
+ while (oldRow.size() > row.size())
+ row = ' ' + row;
+ }
+ rows.push_back(row);
+ return *this;
+ }
+
+ std::string label;
+ Colour::Code colour;
+ std::vector<std::string> rows;
+
+};
+
+void ConsoleReporter::printTotals( Totals const& totals ) {
+ if (totals.testCases.total() == 0) {
+ stream << Colour(Colour::Warning) << "No tests ran\n";
+ } else if (totals.assertions.total() > 0 && totals.testCases.allPassed()) {
+ stream << Colour(Colour::ResultSuccess) << "All tests passed";
+ stream << " ("
+ << pluralise(totals.assertions.passed, "assertion") << " in "
+ << pluralise(totals.testCases.passed, "test case") << ')'
+ << '\n';
+ } else {
+
+ std::vector<SummaryColumn> columns;
+ columns.push_back(SummaryColumn("", Colour::None)
+ .addRow(totals.testCases.total())
+ .addRow(totals.assertions.total()));
+ columns.push_back(SummaryColumn("passed", Colour::Success)
+ .addRow(totals.testCases.passed)
+ .addRow(totals.assertions.passed));
+ columns.push_back(SummaryColumn("failed", Colour::ResultError)
+ .addRow(totals.testCases.failed)
+ .addRow(totals.assertions.failed));
+ columns.push_back(SummaryColumn("failed as expected", Colour::ResultExpectedFailure)
+ .addRow(totals.testCases.failedButOk)
+ .addRow(totals.assertions.failedButOk));
+
+ printSummaryRow("test cases", columns, 0);
+ printSummaryRow("assertions", columns, 1);
+ }
+}
+void ConsoleReporter::printSummaryRow(std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row) {
+ for (auto col : cols) {
+ std::string value = col.rows[row];
+ if (col.label.empty()) {
+ stream << label << ": ";
+ if (value != "0")
+ stream << value;
+ else
+ stream << Colour(Colour::Warning) << "- none -";
+ } else if (value != "0") {
+ stream << Colour(Colour::LightGrey) << " | ";
+ stream << Colour(col.colour)
+ << value << ' ' << col.label;
+ }
+ }
+ stream << '\n';
+}
+
+void ConsoleReporter::printTotalsDivider(Totals const& totals) {
+ if (totals.testCases.total() > 0) {
+ std::size_t failedRatio = makeRatio(totals.testCases.failed, totals.testCases.total());
+ std::size_t failedButOkRatio = makeRatio(totals.testCases.failedButOk, totals.testCases.total());
+ std::size_t passedRatio = makeRatio(totals.testCases.passed, totals.testCases.total());
+ while (failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH - 1)
+ findMax(failedRatio, failedButOkRatio, passedRatio)++;
+ while (failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH - 1)
+ findMax(failedRatio, failedButOkRatio, passedRatio)--;
+
+ stream << Colour(Colour::Error) << std::string(failedRatio, '=');
+ stream << Colour(Colour::ResultExpectedFailure) << std::string(failedButOkRatio, '=');
+ if (totals.testCases.allPassed())
+ stream << Colour(Colour::ResultSuccess) << std::string(passedRatio, '=');
+ else
+ stream << Colour(Colour::Success) << std::string(passedRatio, '=');
+ } else {
+ stream << Colour(Colour::Warning) << std::string(CATCH_CONFIG_CONSOLE_WIDTH - 1, '=');
+ }
+ stream << '\n';
+}
+void ConsoleReporter::printSummaryDivider() {
+ stream << getLineOfChars<'-'>() << '\n';
+}
+
+void ConsoleReporter::printTestFilters() {
+ if (m_config->testSpec().hasFilters()) {
+ Colour guard(Colour::BrightYellow);
+ stream << "Filters: " << serializeFilters(m_config->getTestsOrTags()) << '\n';
+ }
+}
+
+CATCH_REGISTER_REPORTER("console", ConsoleReporter)
+
+} // end namespace Catch
+
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
+
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+// end catch_reporter_console.cpp
+// start catch_reporter_junit.cpp
+
+#include <cassert>
+#include <sstream>
+#include <ctime>
+#include <algorithm>
+#include <iomanip>
+
+namespace Catch {
+
+ namespace {
+ std::string getCurrentTimestamp() {
+ // Beware, this is not reentrant because of backward compatibility issues
+ // Also, UTC only, again because of backward compatibility (%z is C++11)
+ time_t rawtime;
+ std::time(&rawtime);
+ auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
+
+#ifdef _MSC_VER
+ std::tm timeInfo = {};
+ gmtime_s(&timeInfo, &rawtime);
+#else
+ std::tm* timeInfo;
+ timeInfo = std::gmtime(&rawtime);
+#endif
+
+ char timeStamp[timeStampSize];
+ const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
+
+#ifdef _MSC_VER
+ std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
+#else
+ std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
+#endif
+ return std::string(timeStamp, timeStampSize-1);
+ }
+
+ std::string fileNameTag(const std::vector<std::string> &tags) {
+ auto it = std::find_if(begin(tags),
+ end(tags),
+ [] (std::string const& tag) {return tag.front() == '#'; });
+ if (it != tags.end())
+ return it->substr(1);
+ return std::string();
+ }
+
+ // Formats the duration in seconds to 3 decimal places.
+ // This is done because some genius defined Maven Surefire schema
+ // in a way that only accepts 3 decimal places, and tools like
+ // Jenkins use that schema for validation JUnit reporter output.
+ std::string formatDuration( double seconds ) {
+ ReusableStringStream rss;
+ rss << std::fixed << std::setprecision( 3 ) << seconds;
+ return rss.str();
+ }
+
+ } // anonymous namespace
+
+ JunitReporter::JunitReporter( ReporterConfig const& _config )
+ : CumulativeReporterBase( _config ),
+ xml( _config.stream() )
+ {
+ m_reporterPrefs.shouldRedirectStdOut = true;
+ m_reporterPrefs.shouldReportAllAssertions = true;
+ }
+
+ JunitReporter::~JunitReporter() {}
+
+ std::string JunitReporter::getDescription() {
+ return "Reports test results in an XML format that looks like Ant's junitreport target";
+ }
+
+ void JunitReporter::noMatchingTestCases( std::string const& /*spec*/ ) {}
+
+ void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) {
+ CumulativeReporterBase::testRunStarting( runInfo );
+ xml.startElement( "testsuites" );
+ }
+
+ void JunitReporter::testGroupStarting( GroupInfo const& groupInfo ) {
+ suiteTimer.start();
+ stdOutForSuite.clear();
+ stdErrForSuite.clear();
+ unexpectedExceptions = 0;
+ CumulativeReporterBase::testGroupStarting( groupInfo );
+ }
+
+ void JunitReporter::testCaseStarting( TestCaseInfo const& testCaseInfo ) {
+ m_okToFail = testCaseInfo.okToFail();
+ }
+
+ bool JunitReporter::assertionEnded( AssertionStats const& assertionStats ) {
+ if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException && !m_okToFail )
+ unexpectedExceptions++;
+ return CumulativeReporterBase::assertionEnded( assertionStats );
+ }
+
+ void JunitReporter::testCaseEnded( TestCaseStats const& testCaseStats ) {
+ stdOutForSuite += testCaseStats.stdOut;
+ stdErrForSuite += testCaseStats.stdErr;
+ CumulativeReporterBase::testCaseEnded( testCaseStats );
+ }
+
+ void JunitReporter::testGroupEnded( TestGroupStats const& testGroupStats ) {
+ double suiteTime = suiteTimer.getElapsedSeconds();
+ CumulativeReporterBase::testGroupEnded( testGroupStats );
+ writeGroup( *m_testGroups.back(), suiteTime );
+ }
+
+ void JunitReporter::testRunEndedCumulative() {
+ xml.endElement();
+ }
+
+ void JunitReporter::writeGroup( TestGroupNode const& groupNode, double suiteTime ) {
+ XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
+
+ TestGroupStats const& stats = groupNode.value;
+ xml.writeAttribute( "name", stats.groupInfo.name );
+ xml.writeAttribute( "errors", unexpectedExceptions );
+ xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions );
+ xml.writeAttribute( "tests", stats.totals.assertions.total() );
+ xml.writeAttribute( "hostname", "tbd" ); // !TBD
+ if( m_config->showDurations() == ShowDurations::Never )
+ xml.writeAttribute( "time", "" );
+ else
+ xml.writeAttribute( "time", formatDuration( suiteTime ) );
+ xml.writeAttribute( "timestamp", getCurrentTimestamp() );
+
+ // Write properties if there are any
+ if (m_config->hasTestFilters() || m_config->rngSeed() != 0) {
+ auto properties = xml.scopedElement("properties");
+ if (m_config->hasTestFilters()) {
+ xml.scopedElement("property")
+ .writeAttribute("name", "filters")
+ .writeAttribute("value", serializeFilters(m_config->getTestsOrTags()));
+ }
+ if (m_config->rngSeed() != 0) {
+ xml.scopedElement("property")
+ .writeAttribute("name", "random-seed")
+ .writeAttribute("value", m_config->rngSeed());
+ }
+ }
+
+ // Write test cases
+ for( auto const& child : groupNode.children )
+ writeTestCase( *child );
+
+ xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite ), XmlFormatting::Newline );
+ xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite ), XmlFormatting::Newline );
+ }
+
+ void JunitReporter::writeTestCase( TestCaseNode const& testCaseNode ) {
+ TestCaseStats const& stats = testCaseNode.value;
+
+ // All test cases have exactly one section - which represents the
+ // test case itself. That section may have 0-n nested sections
+ assert( testCaseNode.children.size() == 1 );
+ SectionNode const& rootSection = *testCaseNode.children.front();
+
+ std::string className = stats.testInfo.className;
+
+ if( className.empty() ) {
+ className = fileNameTag(stats.testInfo.tags);
+ if ( className.empty() )
+ className = "global";
+ }
+
+ if ( !m_config->name().empty() )
+ className = m_config->name() + "." + className;
+
+ writeSection( className, "", rootSection, stats.testInfo.okToFail() );
+ }
+
+ void JunitReporter::writeSection( std::string const& className,
+ std::string const& rootName,
+ SectionNode const& sectionNode,
+ bool testOkToFail) {
+ std::string name = trim( sectionNode.stats.sectionInfo.name );
+ if( !rootName.empty() )
+ name = rootName + '/' + name;
+
+ if( !sectionNode.assertions.empty() ||
+ !sectionNode.stdOut.empty() ||
+ !sectionNode.stdErr.empty() ) {
+ XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
+ if( className.empty() ) {
+ xml.writeAttribute( "classname", name );
+ xml.writeAttribute( "name", "root" );
+ }
+ else {
+ xml.writeAttribute( "classname", className );
+ xml.writeAttribute( "name", name );
+ }
+ xml.writeAttribute( "time", formatDuration( sectionNode.stats.durationInSeconds ) );
+ // This is not ideal, but it should be enough to mimic gtest's
+ // junit output.
+ // Ideally the JUnit reporter would also handle `skipTest`
+ // events and write those out appropriately.
+ xml.writeAttribute( "status", "run" );
+
+ if (sectionNode.stats.assertions.failedButOk) {
+ xml.scopedElement("skipped")
+ .writeAttribute("message", "TEST_CASE tagged with !mayfail");
+ }
+
+ writeAssertions( sectionNode );
+
+ if( !sectionNode.stdOut.empty() )
+ xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), XmlFormatting::Newline );
+ if( !sectionNode.stdErr.empty() )
+ xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), XmlFormatting::Newline );
+ }
+ for( auto const& childNode : sectionNode.childSections )
+ if( className.empty() )
+ writeSection( name, "", *childNode, testOkToFail );
+ else
+ writeSection( className, name, *childNode, testOkToFail );
+ }
+
+ void JunitReporter::writeAssertions( SectionNode const& sectionNode ) {
+ for( auto const& assertion : sectionNode.assertions )
+ writeAssertion( assertion );
+ }
+
+ void JunitReporter::writeAssertion( AssertionStats const& stats ) {
+ AssertionResult const& result = stats.assertionResult;
+ if( !result.isOk() ) {
+ std::string elementName;
+ switch( result.getResultType() ) {
+ case ResultWas::ThrewException:
+ case ResultWas::FatalErrorCondition:
+ elementName = "error";
+ break;
+ case ResultWas::ExplicitFailure:
+ case ResultWas::ExpressionFailed:
+ case ResultWas::DidntThrowException:
+ elementName = "failure";
+ break;
+
+ // We should never see these here:
+ case ResultWas::Info:
+ case ResultWas::Warning:
+ case ResultWas::Ok:
+ case ResultWas::Unknown:
+ case ResultWas::FailureBit:
+ case ResultWas::Exception:
+ elementName = "internalError";
+ break;
+ }
+
+ XmlWriter::ScopedElement e = xml.scopedElement( elementName );
+
+ xml.writeAttribute( "message", result.getExpression() );
+ xml.writeAttribute( "type", result.getTestMacroName() );
+
+ ReusableStringStream rss;
+ if (stats.totals.assertions.total() > 0) {
+ rss << "FAILED" << ":\n";
+ if (result.hasExpression()) {
+ rss << " ";
+ rss << result.getExpressionInMacro();
+ rss << '\n';
+ }
+ if (result.hasExpandedExpression()) {
+ rss << "with expansion:\n";
+ rss << Column(result.getExpandedExpression()).indent(2) << '\n';
+ }
+ } else {
+ rss << '\n';
+ }
+
+ if( !result.getMessage().empty() )
+ rss << result.getMessage() << '\n';
+ for( auto const& msg : stats.infoMessages )
+ if( msg.type == ResultWas::Info )
+ rss << msg.message << '\n';
+
+ rss << "at " << result.getSourceInfo();
+ xml.writeText( rss.str(), XmlFormatting::Newline );
+ }
+ }
+
+ CATCH_REGISTER_REPORTER( "junit", JunitReporter )
+
+} // end namespace Catch
+// end catch_reporter_junit.cpp
+// start catch_reporter_listening.cpp
+
+#include <cassert>
+
+namespace Catch {
+
+ ListeningReporter::ListeningReporter() {
+ // We will assume that listeners will always want all assertions
+ m_preferences.shouldReportAllAssertions = true;
+ }
+
+ void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) {
+ m_listeners.push_back( std::move( listener ) );
+ }
+
+ void ListeningReporter::addReporter(IStreamingReporterPtr&& reporter) {
+ assert(!m_reporter && "Listening reporter can wrap only 1 real reporter");
+ m_reporter = std::move( reporter );
+ m_preferences.shouldRedirectStdOut = m_reporter->getPreferences().shouldRedirectStdOut;
+ }
+
+ ReporterPreferences ListeningReporter::getPreferences() const {
+ return m_preferences;
+ }
+
+ std::set<Verbosity> ListeningReporter::getSupportedVerbosities() {
+ return std::set<Verbosity>{ };
+ }
+
+ void ListeningReporter::noMatchingTestCases( std::string const& spec ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->noMatchingTestCases( spec );
+ }
+ m_reporter->noMatchingTestCases( spec );
+ }
+
+ void ListeningReporter::reportInvalidArguments(std::string const&arg){
+ for ( auto const& listener : m_listeners ) {
+ listener->reportInvalidArguments( arg );
+ }
+ m_reporter->reportInvalidArguments( arg );
+ }
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ void ListeningReporter::benchmarkPreparing( std::string const& name ) {
+ for (auto const& listener : m_listeners) {
+ listener->benchmarkPreparing(name);
+ }
+ m_reporter->benchmarkPreparing(name);
+ }
+ void ListeningReporter::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->benchmarkStarting( benchmarkInfo );
+ }
+ m_reporter->benchmarkStarting( benchmarkInfo );
+ }
+ void ListeningReporter::benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->benchmarkEnded( benchmarkStats );
+ }
+ m_reporter->benchmarkEnded( benchmarkStats );
+ }
+
+ void ListeningReporter::benchmarkFailed( std::string const& error ) {
+ for (auto const& listener : m_listeners) {
+ listener->benchmarkFailed(error);
+ }
+ m_reporter->benchmarkFailed(error);
+ }
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ void ListeningReporter::testRunStarting( TestRunInfo const& testRunInfo ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->testRunStarting( testRunInfo );
+ }
+ m_reporter->testRunStarting( testRunInfo );
+ }
+
+ void ListeningReporter::testGroupStarting( GroupInfo const& groupInfo ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->testGroupStarting( groupInfo );
+ }
+ m_reporter->testGroupStarting( groupInfo );
+ }
+
+ void ListeningReporter::testCaseStarting( TestCaseInfo const& testInfo ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->testCaseStarting( testInfo );
+ }
+ m_reporter->testCaseStarting( testInfo );
+ }
+
+ void ListeningReporter::sectionStarting( SectionInfo const& sectionInfo ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->sectionStarting( sectionInfo );
+ }
+ m_reporter->sectionStarting( sectionInfo );
+ }
+
+ void ListeningReporter::assertionStarting( AssertionInfo const& assertionInfo ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->assertionStarting( assertionInfo );
+ }
+ m_reporter->assertionStarting( assertionInfo );
+ }
+
+ // The return value indicates if the messages buffer should be cleared:
+ bool ListeningReporter::assertionEnded( AssertionStats const& assertionStats ) {
+ for( auto const& listener : m_listeners ) {
+ static_cast<void>( listener->assertionEnded( assertionStats ) );
+ }
+ return m_reporter->assertionEnded( assertionStats );
+ }
+
+ void ListeningReporter::sectionEnded( SectionStats const& sectionStats ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->sectionEnded( sectionStats );
+ }
+ m_reporter->sectionEnded( sectionStats );
+ }
+
+ void ListeningReporter::testCaseEnded( TestCaseStats const& testCaseStats ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->testCaseEnded( testCaseStats );
+ }
+ m_reporter->testCaseEnded( testCaseStats );
+ }
+
+ void ListeningReporter::testGroupEnded( TestGroupStats const& testGroupStats ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->testGroupEnded( testGroupStats );
+ }
+ m_reporter->testGroupEnded( testGroupStats );
+ }
+
+ void ListeningReporter::testRunEnded( TestRunStats const& testRunStats ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->testRunEnded( testRunStats );
+ }
+ m_reporter->testRunEnded( testRunStats );
+ }
+
+ void ListeningReporter::skipTest( TestCaseInfo const& testInfo ) {
+ for ( auto const& listener : m_listeners ) {
+ listener->skipTest( testInfo );
+ }
+ m_reporter->skipTest( testInfo );
+ }
+
+ bool ListeningReporter::isMulti() const {
+ return true;
+ }
+
+} // end namespace Catch
+// end catch_reporter_listening.cpp
+// start catch_reporter_xml.cpp
+
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch
+ // Note that 4062 (not all labels are handled
+ // and default is missing) is enabled
+#endif
+
+namespace Catch {
+ XmlReporter::XmlReporter( ReporterConfig const& _config )
+ : StreamingReporterBase( _config ),
+ m_xml(_config.stream())
+ {
+ m_reporterPrefs.shouldRedirectStdOut = true;
+ m_reporterPrefs.shouldReportAllAssertions = true;
+ }
+
+ XmlReporter::~XmlReporter() = default;
+
+ std::string XmlReporter::getDescription() {
+ return "Reports test results as an XML document";
+ }
+
+ std::string XmlReporter::getStylesheetRef() const {
+ return std::string();
+ }
+
+ void XmlReporter::writeSourceInfo( SourceLineInfo const& sourceInfo ) {
+ m_xml
+ .writeAttribute( "filename", sourceInfo.file )
+ .writeAttribute( "line", sourceInfo.line );
+ }
+
+ void XmlReporter::noMatchingTestCases( std::string const& s ) {
+ StreamingReporterBase::noMatchingTestCases( s );
+ }
+
+ void XmlReporter::testRunStarting( TestRunInfo const& testInfo ) {
+ StreamingReporterBase::testRunStarting( testInfo );
+ std::string stylesheetRef = getStylesheetRef();
+ if( !stylesheetRef.empty() )
+ m_xml.writeStylesheetRef( stylesheetRef );
+ m_xml.startElement( "Catch" );
+ if( !m_config->name().empty() )
+ m_xml.writeAttribute( "name", m_config->name() );
+ if (m_config->testSpec().hasFilters())
+ m_xml.writeAttribute( "filters", serializeFilters( m_config->getTestsOrTags() ) );
+ if( m_config->rngSeed() != 0 )
+ m_xml.scopedElement( "Randomness" )
+ .writeAttribute( "seed", m_config->rngSeed() );
+ }
+
+ void XmlReporter::testGroupStarting( GroupInfo const& groupInfo ) {
+ StreamingReporterBase::testGroupStarting( groupInfo );
+ m_xml.startElement( "Group" )
+ .writeAttribute( "name", groupInfo.name );
+ }
+
+ void XmlReporter::testCaseStarting( TestCaseInfo const& testInfo ) {
+ StreamingReporterBase::testCaseStarting(testInfo);
+ m_xml.startElement( "TestCase" )
+ .writeAttribute( "name", trim( testInfo.name ) )
+ .writeAttribute( "description", testInfo.description )
+ .writeAttribute( "tags", testInfo.tagsAsString() );
+
+ writeSourceInfo( testInfo.lineInfo );
+
+ if ( m_config->showDurations() == ShowDurations::Always )
+ m_testCaseTimer.start();
+ m_xml.ensureTagClosed();
+ }
+
+ void XmlReporter::sectionStarting( SectionInfo const& sectionInfo ) {
+ StreamingReporterBase::sectionStarting( sectionInfo );
+ if( m_sectionDepth++ > 0 ) {
+ m_xml.startElement( "Section" )
+ .writeAttribute( "name", trim( sectionInfo.name ) );
+ writeSourceInfo( sectionInfo.lineInfo );
+ m_xml.ensureTagClosed();
+ }
+ }
+
+ void XmlReporter::assertionStarting( AssertionInfo const& ) { }
+
+ bool XmlReporter::assertionEnded( AssertionStats const& assertionStats ) {
+
+ AssertionResult const& result = assertionStats.assertionResult;
+
+ bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
+
+ if( includeResults || result.getResultType() == ResultWas::Warning ) {
+ // Print any info messages in <Info> tags.
+ for( auto const& msg : assertionStats.infoMessages ) {
+ if( msg.type == ResultWas::Info && includeResults ) {
+ m_xml.scopedElement( "Info" )
+ .writeText( msg.message );
+ } else if ( msg.type == ResultWas::Warning ) {
+ m_xml.scopedElement( "Warning" )
+ .writeText( msg.message );
+ }
+ }
+ }
+
+ // Drop out if result was successful but we're not printing them.
+ if( !includeResults && result.getResultType() != ResultWas::Warning )
+ return true;
+
+ // Print the expression if there is one.
+ if( result.hasExpression() ) {
+ m_xml.startElement( "Expression" )
+ .writeAttribute( "success", result.succeeded() )
+ .writeAttribute( "type", result.getTestMacroName() );
+
+ writeSourceInfo( result.getSourceInfo() );
+
+ m_xml.scopedElement( "Original" )
+ .writeText( result.getExpression() );
+ m_xml.scopedElement( "Expanded" )
+ .writeText( result.getExpandedExpression() );
+ }
+
+ // And... Print a result applicable to each result type.
+ switch( result.getResultType() ) {
+ case ResultWas::ThrewException:
+ m_xml.startElement( "Exception" );
+ writeSourceInfo( result.getSourceInfo() );
+ m_xml.writeText( result.getMessage() );
+ m_xml.endElement();
+ break;
+ case ResultWas::FatalErrorCondition:
+ m_xml.startElement( "FatalErrorCondition" );
+ writeSourceInfo( result.getSourceInfo() );
+ m_xml.writeText( result.getMessage() );
+ m_xml.endElement();
+ break;
+ case ResultWas::Info:
+ m_xml.scopedElement( "Info" )
+ .writeText( result.getMessage() );
+ break;
+ case ResultWas::Warning:
+ // Warning will already have been written
+ break;
+ case ResultWas::ExplicitFailure:
+ m_xml.startElement( "Failure" );
+ writeSourceInfo( result.getSourceInfo() );
+ m_xml.writeText( result.getMessage() );
+ m_xml.endElement();
+ break;
+ default:
+ break;
+ }
+
+ if( result.hasExpression() )
+ m_xml.endElement();
+
+ return true;
+ }
+
+ void XmlReporter::sectionEnded( SectionStats const& sectionStats ) {
+ StreamingReporterBase::sectionEnded( sectionStats );
+ if( --m_sectionDepth > 0 ) {
+ XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" );
+ e.writeAttribute( "successes", sectionStats.assertions.passed );
+ e.writeAttribute( "failures", sectionStats.assertions.failed );
+ e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk );
+
+ if ( m_config->showDurations() == ShowDurations::Always )
+ e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds );
+
+ m_xml.endElement();
+ }
+ }
+
+ void XmlReporter::testCaseEnded( TestCaseStats const& testCaseStats ) {
+ StreamingReporterBase::testCaseEnded( testCaseStats );
+ XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" );
+ e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() );
+
+ if ( m_config->showDurations() == ShowDurations::Always )
+ e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
+
+ if( !testCaseStats.stdOut.empty() )
+ m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), XmlFormatting::Newline );
+ if( !testCaseStats.stdErr.empty() )
+ m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), XmlFormatting::Newline );
+
+ m_xml.endElement();
+ }
+
+ void XmlReporter::testGroupEnded( TestGroupStats const& testGroupStats ) {
+ StreamingReporterBase::testGroupEnded( testGroupStats );
+ // TODO: Check testGroupStats.aborting and act accordingly.
+ m_xml.scopedElement( "OverallResults" )
+ .writeAttribute( "successes", testGroupStats.totals.assertions.passed )
+ .writeAttribute( "failures", testGroupStats.totals.assertions.failed )
+ .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk );
+ m_xml.scopedElement( "OverallResultsCases")
+ .writeAttribute( "successes", testGroupStats.totals.testCases.passed )
+ .writeAttribute( "failures", testGroupStats.totals.testCases.failed )
+ .writeAttribute( "expectedFailures", testGroupStats.totals.testCases.failedButOk );
+ m_xml.endElement();
+ }
+
+ void XmlReporter::testRunEnded( TestRunStats const& testRunStats ) {
+ StreamingReporterBase::testRunEnded( testRunStats );
+ m_xml.scopedElement( "OverallResults" )
+ .writeAttribute( "successes", testRunStats.totals.assertions.passed )
+ .writeAttribute( "failures", testRunStats.totals.assertions.failed )
+ .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk );
+ m_xml.scopedElement( "OverallResultsCases")
+ .writeAttribute( "successes", testRunStats.totals.testCases.passed )
+ .writeAttribute( "failures", testRunStats.totals.testCases.failed )
+ .writeAttribute( "expectedFailures", testRunStats.totals.testCases.failedButOk );
+ m_xml.endElement();
+ }
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+ void XmlReporter::benchmarkPreparing(std::string const& name) {
+ m_xml.startElement("BenchmarkResults")
+ .writeAttribute("name", name);
+ }
+
+ void XmlReporter::benchmarkStarting(BenchmarkInfo const &info) {
+ m_xml.writeAttribute("samples", info.samples)
+ .writeAttribute("resamples", info.resamples)
+ .writeAttribute("iterations", info.iterations)
+ .writeAttribute("clockResolution", info.clockResolution)
+ .writeAttribute("estimatedDuration", info.estimatedDuration)
+ .writeComment("All values in nano seconds");
+ }
+
+ void XmlReporter::benchmarkEnded(BenchmarkStats<> const& benchmarkStats) {
+ m_xml.startElement("mean")
+ .writeAttribute("value", benchmarkStats.mean.point.count())
+ .writeAttribute("lowerBound", benchmarkStats.mean.lower_bound.count())
+ .writeAttribute("upperBound", benchmarkStats.mean.upper_bound.count())
+ .writeAttribute("ci", benchmarkStats.mean.confidence_interval);
+ m_xml.endElement();
+ m_xml.startElement("standardDeviation")
+ .writeAttribute("value", benchmarkStats.standardDeviation.point.count())
+ .writeAttribute("lowerBound", benchmarkStats.standardDeviation.lower_bound.count())
+ .writeAttribute("upperBound", benchmarkStats.standardDeviation.upper_bound.count())
+ .writeAttribute("ci", benchmarkStats.standardDeviation.confidence_interval);
+ m_xml.endElement();
+ m_xml.startElement("outliers")
+ .writeAttribute("variance", benchmarkStats.outlierVariance)
+ .writeAttribute("lowMild", benchmarkStats.outliers.low_mild)
+ .writeAttribute("lowSevere", benchmarkStats.outliers.low_severe)
+ .writeAttribute("highMild", benchmarkStats.outliers.high_mild)
+ .writeAttribute("highSevere", benchmarkStats.outliers.high_severe);
+ m_xml.endElement();
+ m_xml.endElement();
+ }
+
+ void XmlReporter::benchmarkFailed(std::string const &error) {
+ m_xml.scopedElement("failed").
+ writeAttribute("message", error);
+ m_xml.endElement();
+ }
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+ CATCH_REGISTER_REPORTER( "xml", XmlReporter )
+
+} // end namespace Catch
+
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
+// end catch_reporter_xml.cpp
+
+namespace Catch {
+ LeakDetector leakDetector;
+}
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
+// end catch_impl.hpp
+#endif
+
+#ifdef CATCH_CONFIG_MAIN
+// start catch_default_main.hpp
+
+#ifndef __OBJC__
+
+#if defined(CATCH_CONFIG_WCHAR) && defined(CATCH_PLATFORM_WINDOWS) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN)
+// Standard C/C++ Win32 Unicode wmain entry point
+extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) {
+#else
+// Standard C/C++ main entry point
+int main (int argc, char * argv[]) {
+#endif
+
+ return Catch::Session().run( argc, argv );
+}
+
+#else // __OBJC__
+
+// Objective-C entry point
+int main (int argc, char * const argv[]) {
+#if !CATCH_ARC_ENABLED
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+#endif
+
+ Catch::registerTestMethods();
+ int result = Catch::Session().run( argc, (char**)argv );
+
+#if !CATCH_ARC_ENABLED
+ [pool drain];
+#endif
+
+ return result;
+}
+
+#endif // __OBJC__
+
+// end catch_default_main.hpp
+#endif
+
+#if !defined(CATCH_CONFIG_IMPL_ONLY)
+
+#ifdef CLARA_CONFIG_MAIN_NOT_DEFINED
+# undef CLARA_CONFIG_MAIN
+#endif
+
+#if !defined(CATCH_CONFIG_DISABLE)
+//////
+// If this config identifier is defined then all CATCH macros are prefixed with CATCH_
+#ifdef CATCH_CONFIG_PREFIX_ALL
+
+#define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
+#define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
+
+#define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
+#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
+#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
+#endif// CATCH_CONFIG_DISABLE_MATCHERS
+#define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
+
+#define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
+#define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
+
+#define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
+#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+#define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
+
+#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+
+#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
+#define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg )
+#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
+#define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE",__VA_ARGS__ )
+
+#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
+#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
+#define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
+#define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
+#define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ )
+#define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
+#define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+
+#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE()
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
+#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ )
+#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
+#else
+#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) )
+#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) )
+#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
+#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
+#endif
+
+#if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
+#define CATCH_STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ )
+#define CATCH_STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ )
+#else
+#define CATCH_STATIC_REQUIRE( ... ) CATCH_REQUIRE( __VA_ARGS__ )
+#define CATCH_STATIC_REQUIRE_FALSE( ... ) CATCH_REQUIRE_FALSE( __VA_ARGS__ )
+#endif
+
+// "BDD-style" convenience wrappers
+#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
+#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
+#define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
+#define CATCH_AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc )
+#define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
+#define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc )
+#define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
+#define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+#define CATCH_BENCHMARK(...) \
+ INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
+#define CATCH_BENCHMARK_ADVANCED(name) \
+ INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), name)
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
+#else
+
+#define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
+#define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
+
+#define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
+#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
+#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+#define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
+
+#define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
+#define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
+
+#define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
+#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+#define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
+
+#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+
+#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
+#define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg )
+#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
+#define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE",__VA_ARGS__ )
+
+#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
+#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
+#define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
+#define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
+#define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ )
+#define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
+#define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
+#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE()
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
+#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ )
+#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
+#define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__)
+#define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#else
+#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) )
+#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) )
+#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
+#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
+#define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) )
+#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) )
+#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
+#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
+#define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) )
+#define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
+#endif
+
+#if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
+#define STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ )
+#define STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" )
+#else
+#define STATIC_REQUIRE( ... ) REQUIRE( __VA_ARGS__ )
+#define STATIC_REQUIRE_FALSE( ... ) REQUIRE_FALSE( __VA_ARGS__ )
+#endif
+
+#endif
+
+#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
+
+// "BDD-style" convenience wrappers
+#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
+#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
+
+#define GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
+#define AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc )
+#define WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
+#define AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc )
+#define THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
+#define AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
+
+#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
+#define BENCHMARK(...) \
+ INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
+#define BENCHMARK_ADVANCED(name) \
+ INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), name)
+#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
+
+using Catch::Detail::Approx;
+
+#else // CATCH_CONFIG_DISABLE
+
+//////
+// If this config identifier is defined then all CATCH macros are prefixed with CATCH_
+#ifdef CATCH_CONFIG_PREFIX_ALL
+
+#define CATCH_REQUIRE( ... ) (void)(0)
+#define CATCH_REQUIRE_FALSE( ... ) (void)(0)
+
+#define CATCH_REQUIRE_THROWS( ... ) (void)(0)
+#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
+#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
+#endif// CATCH_CONFIG_DISABLE_MATCHERS
+#define CATCH_REQUIRE_NOTHROW( ... ) (void)(0)
+
+#define CATCH_CHECK( ... ) (void)(0)
+#define CATCH_CHECK_FALSE( ... ) (void)(0)
+#define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__)
+#define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
+#define CATCH_CHECK_NOFAIL( ... ) (void)(0)
+
+#define CATCH_CHECK_THROWS( ... ) (void)(0)
+#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
+#define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0)
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+#define CATCH_CHECK_NOTHROW( ... ) (void)(0)
+
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define CATCH_CHECK_THAT( arg, matcher ) (void)(0)
+
+#define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0)
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+
+#define CATCH_INFO( msg ) (void)(0)
+#define CATCH_UNSCOPED_INFO( msg ) (void)(0)
+#define CATCH_WARN( msg ) (void)(0)
+#define CATCH_CAPTURE( msg ) (void)(0)
+
+#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
+#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
+#define CATCH_METHOD_AS_TEST_CASE( method, ... )
+#define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0)
+#define CATCH_SECTION( ... )
+#define CATCH_DYNAMIC_SECTION( ... )
+#define CATCH_FAIL( ... ) (void)(0)
+#define CATCH_FAIL_CHECK( ... ) (void)(0)
+#define CATCH_SUCCEED( ... ) (void)(0)
+
+#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__)
+#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__)
+#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__)
+#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#else
+#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) )
+#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) )
+#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) )
+#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#endif
+
+// "BDD-style" convenience wrappers
+#define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
+#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), className )
+#define CATCH_GIVEN( desc )
+#define CATCH_AND_GIVEN( desc )
+#define CATCH_WHEN( desc )
+#define CATCH_AND_WHEN( desc )
+#define CATCH_THEN( desc )
+#define CATCH_AND_THEN( desc )
+
+#define CATCH_STATIC_REQUIRE( ... ) (void)(0)
+#define CATCH_STATIC_REQUIRE_FALSE( ... ) (void)(0)
+
+// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
+#else
+
+#define REQUIRE( ... ) (void)(0)
+#define REQUIRE_FALSE( ... ) (void)(0)
+
+#define REQUIRE_THROWS( ... ) (void)(0)
+#define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
+#define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+#define REQUIRE_NOTHROW( ... ) (void)(0)
+
+#define CHECK( ... ) (void)(0)
+#define CHECK_FALSE( ... ) (void)(0)
+#define CHECKED_IF( ... ) if (__VA_ARGS__)
+#define CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
+#define CHECK_NOFAIL( ... ) (void)(0)
+
+#define CHECK_THROWS( ... ) (void)(0)
+#define CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
+#define CHECK_THROWS_WITH( expr, matcher ) (void)(0)
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+#define CHECK_NOTHROW( ... ) (void)(0)
+
+#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
+#define CHECK_THAT( arg, matcher ) (void)(0)
+
+#define REQUIRE_THAT( arg, matcher ) (void)(0)
+#endif // CATCH_CONFIG_DISABLE_MATCHERS
+
+#define INFO( msg ) (void)(0)
+#define UNSCOPED_INFO( msg ) (void)(0)
+#define WARN( msg ) (void)(0)
+#define CAPTURE( msg ) (void)(0)
+
+#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
+#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
+#define METHOD_AS_TEST_CASE( method, ... )
+#define REGISTER_TEST_CASE( Function, ... ) (void)(0)
+#define SECTION( ... )
+#define DYNAMIC_SECTION( ... )
+#define FAIL( ... ) (void)(0)
+#define FAIL_CHECK( ... ) (void)(0)
+#define SUCCEED( ... ) (void)(0)
+#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ))
+
+#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
+#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__)
+#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__)
+#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__)
+#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#else
+#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) )
+#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) )
+#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) )
+#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) )
+#define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
+#endif
+
+#define STATIC_REQUIRE( ... ) (void)(0)
+#define STATIC_REQUIRE_FALSE( ... ) (void)(0)
+
+#endif
+
+#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
+
+// "BDD-style" convenience wrappers
+#define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ) )
+#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), className )
+
+#define GIVEN( desc )
+#define AND_GIVEN( desc )
+#define WHEN( desc )
+#define AND_WHEN( desc )
+#define THEN( desc )
+#define AND_THEN( desc )
+
+using Catch::Detail::Approx;
+
+#endif
+
+#endif // ! CATCH_CONFIG_IMPL_ONLY
+
+// start catch_reenable_warnings.h
+
+
+#ifdef __clang__
+# ifdef __ICC // icpc defines the __clang__ macro
+# pragma warning(pop)
+# else
+# pragma clang diagnostic pop
+# endif
+#elif defined __GNUC__
+# pragma GCC diagnostic pop
+#endif
+
+// end catch_reenable_warnings.h
+// end catch.hpp
+#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
+
diff --git a/third_party/catch2/fakeit.hpp b/third_party/catch2/fakeit.hpp
new file mode 100755
index 0000000..2d30552
--- /dev/null
+++ b/third_party/catch2/fakeit.hpp
@@ -0,0 +1,9375 @@
+#pragma once
+/*
+ * FakeIt - A Simplified C++ Mocking Framework
+ * Copyright (c) Eran Pe'er 2013
+ * Generated: 2018-08-17 00:22:40.428924
+ * Distributed under the MIT License. Please refer to the LICENSE file at:
+ * https://github.com/eranpeer/FakeIt
+ */
+
+#ifndef fakeit_h__
+#define fakeit_h__
+
+
+
+#include <functional>
+#include <memory>
+#include <set>
+#include <vector>
+#include <stdexcept>
+#if defined (__GNUG__) || _MSC_VER >= 1900
+#define THROWS noexcept(false)
+#define NO_THROWS noexcept(true)
+#elif defined (_MSC_VER)
+#define THROWS throw(...)
+#define NO_THROWS
+#endif
+#include <typeinfo>
+#include <unordered_set>
+#include <tuple>
+#include <string>
+#include <iosfwd>
+#include <atomic>
+#include <tuple>
+
+
+namespace fakeit {
+
+ template<class C>
+ struct naked_type {
+ typedef typename std::remove_cv<typename std::remove_reference<C>::type>::type type;
+ };
+
+ template< class T > struct tuple_arg { typedef T type; };
+ template< class T > struct tuple_arg < T& > { typedef T& type; };
+ template< class T > struct tuple_arg < T&& > { typedef T&& type; };
+
+
+
+
+ template<typename... arglist>
+ using ArgumentsTuple = std::tuple < arglist... > ;
+
+ template< class T > struct test_arg { typedef T& type; };
+ template< class T > struct test_arg< T& > { typedef T& type; };
+ template< class T > struct test_arg< T&& > { typedef T& type; };
+
+ template< class T > struct production_arg { typedef T& type; };
+ template< class T > struct production_arg< T& > { typedef T& type; };
+ template< class T > struct production_arg< T&& > { typedef T&& type; };
+
+ template <typename T>
+ class is_ostreamable {
+ struct no {};
+#if defined(_MSC_VER) && _MSC_VER < 1900
+ template <typename T1>
+ static decltype(operator<<(std::declval<std::ostream&>(), std::declval<const T1>())) test(std::ostream &s, const T1 &t);
+#else
+ template <typename T1>
+ static auto test(std::ostream &s, const T1 &t) -> decltype(s << t);
+#endif
+ static no test(...);
+ public:
+
+ static const bool value =
+ std::is_arithmetic<T>::value ||
+ std::is_pointer<T>::value ||
+ std::is_same<decltype(test(*(std::ostream *)nullptr,
+ std::declval<T>())), std::ostream &>::value;
+ };
+
+
+ template <>
+ class is_ostreamable<std::ios_base& (*)(std::ios_base&)> {
+ public:
+ static const bool value = true;
+ };
+
+ template <typename CharT, typename Traits>
+ class is_ostreamable<std::basic_ios<CharT,Traits>& (*)(std::basic_ios<CharT,Traits>&)> {
+ public:
+ static const bool value = true;
+ };
+
+ template <typename CharT, typename Traits>
+ class is_ostreamable<std::basic_ostream<CharT,Traits>& (*)(std::basic_ostream<CharT,Traits>&)> {
+ public:
+ static const bool value = true;
+ };
+
+ template<typename R, typename... arglist>
+ struct VTableMethodType {
+#if defined (__GNUG__)
+ typedef R(*type)(void *, arglist...);
+#elif defined (_MSC_VER)
+ typedef R(__thiscall *type)(void *, arglist...);
+#endif
+ };
+}
+#include <typeinfo>
+#include <tuple>
+#include <string>
+#include <iosfwd>
+#include <sstream>
+#include <string>
+
+namespace fakeit {
+
+ struct FakeitContext;
+
+ template<typename C>
+ struct MockObject {
+ virtual ~MockObject() THROWS { };
+
+ virtual C &get() = 0;
+
+ virtual FakeitContext &getFakeIt() = 0;
+ };
+
+ struct MethodInfo {
+
+ static unsigned int nextMethodOrdinal() {
+ static std::atomic_uint ordinal{0};
+ return ++ordinal;
+ }
+
+ MethodInfo(unsigned int anId, std::string aName) :
+ _id(anId), _name(aName) { }
+
+ unsigned int id() const {
+ return _id;
+ }
+
+ std::string name() const {
+ return _name;
+ }
+
+ void setName(const std::string &value) {
+ _name = value;
+ }
+
+ private:
+ unsigned int _id;
+ std::string _name;
+ };
+
+ struct UnknownMethod {
+
+ static MethodInfo &instance() {
+ static MethodInfo instance(MethodInfo::nextMethodOrdinal(), "unknown");
+ return instance;
+ }
+
+ };
+
+}
+namespace fakeit {
+ class Destructible {
+ public:
+ virtual ~Destructible() {}
+ };
+}
+
+namespace fakeit {
+
+ struct Invocation : Destructible {
+
+ static unsigned int nextInvocationOrdinal() {
+ static std::atomic_uint invocationOrdinal{0};
+ return ++invocationOrdinal;
+ }
+
+ struct Matcher {
+
+ virtual ~Matcher() THROWS {
+ }
+
+ virtual bool matches(Invocation &invocation) = 0;
+
+ virtual std::string format() const = 0;
+ };
+
+ Invocation(unsigned int ordinal, MethodInfo &method) :
+ _ordinal(ordinal), _method(method), _isVerified(false) {
+ }
+
+ virtual ~Invocation() override = default;
+
+ unsigned int getOrdinal() const {
+ return _ordinal;
+ }
+
+ MethodInfo &getMethod() const {
+ return _method;
+ }
+
+ void markAsVerified() {
+ _isVerified = true;
+ }
+
+ bool isVerified() const {
+ return _isVerified;
+ }
+
+ virtual std::string format() const = 0;
+
+ private:
+ const unsigned int _ordinal;
+ MethodInfo &_method;
+ bool _isVerified;
+ };
+
+}
+#include <iosfwd>
+#include <tuple>
+#include <string>
+#include <sstream>
+#include <ostream>
+
+namespace fakeit {
+
+ template<typename T, class Enable = void>
+ struct Formatter;
+
+ template <>
+ struct Formatter<bool>
+ {
+ static std::string format(bool const &val)
+ {
+ return val ? "true" : "false";
+ }
+ };
+
+ template <>
+ struct Formatter<char>
+ {
+ static std::string format(char const &val)
+ {
+ std::string s;
+ s += "'";
+ s += val;
+ s += "'";
+ return s;
+ }
+ };
+
+ template <>
+ struct Formatter<char const*>
+ {
+ static std::string format(char const* const &val)
+ {
+ std::string s;
+ if(val != nullptr)
+ {
+ s += '"';
+ s += val;
+ s += '"';
+ }
+ else
+ {
+ s = "[nullptr]";
+ }
+ return s;
+ }
+ };
+
+ template <>
+ struct Formatter<char*>
+ {
+ static std::string format(char* const &val)
+ {
+ return Formatter<char const*>::format( val );
+ }
+ };
+
+ template<class C>
+ struct Formatter<C, typename std::enable_if<!is_ostreamable<C>::value>::type> {
+ static std::string format(C const &)
+ {
+ return "?";
+ }
+ };
+
+ template<class C>
+ struct Formatter<C, typename std::enable_if<is_ostreamable<C>::value>::type> {
+ static std::string format(C const &val)
+ {
+ std::ostringstream os;
+ os << val;
+ return os.str();
+ }
+ };
+
+
+ template <typename T>
+ using TypeFormatter = Formatter<typename fakeit::naked_type<T>::type>;
+}
+
+namespace fakeit {
+
+
+ template<class Tuple, std::size_t N>
+ struct TuplePrinter {
+ static void print(std::ostream &strm, const Tuple &t) {
+ TuplePrinter<Tuple, N - 1>::print(strm, t);
+ strm << ", " << fakeit::TypeFormatter<decltype(std::get<N - 1>(t))>::format(std::get<N - 1>(t));
+ }
+ };
+
+ template<class Tuple>
+ struct TuplePrinter<Tuple, 1> {
+ static void print(std::ostream &strm, const Tuple &t) {
+ strm << fakeit::TypeFormatter<decltype(std::get<0>(t))>::format(std::get<0>(t));
+ }
+ };
+
+ template<class Tuple>
+ struct TuplePrinter<Tuple, 0> {
+ static void print(std::ostream &, const Tuple &) {
+ }
+ };
+
+ template<class ... Args>
+ void print(std::ostream &strm, const std::tuple<Args...> &t) {
+ strm << "(";
+ TuplePrinter<decltype(t), sizeof...(Args)>::print(strm, t);
+ strm << ")";
+ }
+
+ template<class ... Args>
+ std::ostream &operator<<(std::ostream &strm, const std::tuple<Args...> &t) {
+ print(strm, t);
+ return strm;
+ }
+
+}
+
+
+namespace fakeit {
+
+ template<typename ... arglist>
+ struct ActualInvocation : public Invocation {
+
+ struct Matcher : public virtual Destructible {
+ virtual bool matches(ActualInvocation<arglist...> &actualInvocation) = 0;
+
+ virtual std::string format() const = 0;
+ };
+
+ ActualInvocation(unsigned int ordinal, MethodInfo &method, const typename fakeit::production_arg<arglist>::type... args) :
+ Invocation(ordinal, method), _matcher{ nullptr }
+ , actualArguments{ std::forward<arglist>(args)... }
+ {
+ }
+
+ ArgumentsTuple<arglist...> & getActualArguments() {
+ return actualArguments;
+ }
+
+
+ void setActualMatcher(Matcher *matcher) {
+ this->_matcher = matcher;
+ }
+
+ Matcher *getActualMatcher() {
+ return _matcher;
+ }
+
+ virtual std::string format() const override {
+ std::ostringstream out;
+ out << getMethod().name();
+ print(out, actualArguments);
+ return out.str();
+ }
+
+ private:
+
+ Matcher *_matcher;
+ ArgumentsTuple<arglist...> actualArguments;
+ };
+
+ template<typename ... arglist>
+ std::ostream &operator<<(std::ostream &strm, const ActualInvocation<arglist...> &ai) {
+ strm << ai.format();
+ return strm;
+ }
+
+}
+
+
+
+
+
+#include <unordered_set>
+
+namespace fakeit {
+
+ struct ActualInvocationsContainer {
+ virtual void clear() = 0;
+
+ virtual ~ActualInvocationsContainer() NO_THROWS { }
+ };
+
+ struct ActualInvocationsSource {
+ virtual void getActualInvocations(std::unordered_set<fakeit::Invocation *> &into) const = 0;
+
+ virtual ~ActualInvocationsSource() NO_THROWS { }
+ };
+
+ struct InvocationsSourceProxy : public ActualInvocationsSource {
+
+ InvocationsSourceProxy(ActualInvocationsSource *inner) :
+ _inner(inner) {
+ }
+
+ void getActualInvocations(std::unordered_set<fakeit::Invocation *> &into) const override {
+ _inner->getActualInvocations(into);
+ }
+
+ private:
+ std::shared_ptr<ActualInvocationsSource> _inner;
+ };
+
+ struct UnverifiedInvocationsSource : public ActualInvocationsSource {
+
+ UnverifiedInvocationsSource(InvocationsSourceProxy decorated) : _decorated(decorated) {
+ }
+
+ void getActualInvocations(std::unordered_set<fakeit::Invocation *> &into) const override {
+ std::unordered_set<fakeit::Invocation *> all;
+ _decorated.getActualInvocations(all);
+ for (fakeit::Invocation *i : all) {
+ if (!i->isVerified()) {
+ into.insert(i);
+ }
+ }
+ }
+
+ private:
+ InvocationsSourceProxy _decorated;
+ };
+
+ struct AggregateInvocationsSource : public ActualInvocationsSource {
+
+ AggregateInvocationsSource(std::vector<ActualInvocationsSource *> &sources) : _sources(sources) {
+ }
+
+ void getActualInvocations(std::unordered_set<fakeit::Invocation *> &into) const override {
+ std::unordered_set<fakeit::Invocation *> tmp;
+ for (ActualInvocationsSource *source : _sources) {
+ source->getActualInvocations(tmp);
+ }
+ filter(tmp, into);
+ }
+
+ protected:
+ bool shouldInclude(fakeit::Invocation *) const {
+ return true;
+ }
+
+ private:
+ std::vector<ActualInvocationsSource *> _sources;
+
+ void filter(std::unordered_set<Invocation *> &source, std::unordered_set<Invocation *> &target) const {
+ for (Invocation *i:source) {
+ if (shouldInclude(i)) {
+ target.insert(i);
+ }
+ }
+ }
+ };
+}
+
+namespace fakeit {
+
+ class Sequence {
+ private:
+
+ protected:
+
+ Sequence() {
+ }
+
+ virtual ~Sequence() THROWS {
+ }
+
+ public:
+
+
+ virtual void getExpectedSequence(std::vector<Invocation::Matcher *> &into) const = 0;
+
+
+ virtual void getInvolvedMocks(std::vector<ActualInvocationsSource *> &into) const = 0;
+
+ virtual unsigned int size() const = 0;
+
+ friend class VerifyFunctor;
+ };
+
+ class ConcatenatedSequence : public virtual Sequence {
+ private:
+ const Sequence &s1;
+ const Sequence &s2;
+
+ protected:
+ ConcatenatedSequence(const Sequence &seq1, const Sequence &seq2) :
+ s1(seq1), s2(seq2) {
+ }
+
+ public:
+
+ virtual ~ConcatenatedSequence() {
+ }
+
+ unsigned int size() const override {
+ return s1.size() + s2.size();
+ }
+
+ const Sequence &getLeft() const {
+ return s1;
+ }
+
+ const Sequence &getRight() const {
+ return s2;
+ }
+
+ void getExpectedSequence(std::vector<Invocation::Matcher *> &into) const override {
+ s1.getExpectedSequence(into);
+ s2.getExpectedSequence(into);
+ }
+
+ virtual void getInvolvedMocks(std::vector<ActualInvocationsSource *> &into) const override {
+ s1.getInvolvedMocks(into);
+ s2.getInvolvedMocks(into);
+ }
+
+ friend inline ConcatenatedSequence operator+(const Sequence &s1, const Sequence &s2);
+ };
+
+ class RepeatedSequence : public virtual Sequence {
+ private:
+ const Sequence &_s;
+ const int times;
+
+ protected:
+ RepeatedSequence(const Sequence &s, const int t) :
+ _s(s), times(t) {
+ }
+
+ public:
+
+ ~RepeatedSequence() {
+ }
+
+ unsigned int size() const override {
+ return _s.size() * times;
+ }
+
+ friend inline RepeatedSequence operator*(const Sequence &s, int times);
+
+ friend inline RepeatedSequence operator*(int times, const Sequence &s);
+
+ void getInvolvedMocks(std::vector<ActualInvocationsSource *> &into) const override {
+ _s.getInvolvedMocks(into);
+ }
+
+ void getExpectedSequence(std::vector<Invocation::Matcher *> &into) const override {
+ for (int i = 0; i < times; i++)
+ _s.getExpectedSequence(into);
+ }
+
+ int getTimes() const {
+ return times;
+ }
+
+ const Sequence &getSequence() const {
+ return _s;
+ }
+ };
+
+ inline ConcatenatedSequence operator+(const Sequence &s1, const Sequence &s2) {
+ return ConcatenatedSequence(s1, s2);
+ }
+
+ inline RepeatedSequence operator*(const Sequence &s, int times) {
+ if (times <= 0)
+ throw std::invalid_argument("times");
+ return RepeatedSequence(s, times);
+ }
+
+ inline RepeatedSequence operator*(int times, const Sequence &s) {
+ if (times <= 0)
+ throw std::invalid_argument("times");
+ return RepeatedSequence(s, times);
+ }
+
+}
+
+namespace fakeit {
+
+ enum class VerificationType {
+ Exact, AtLeast, NoMoreInvocations
+ };
+
+ enum class UnexpectedType {
+ Unmocked, Unmatched
+ };
+
+ struct VerificationEvent {
+
+ VerificationEvent(VerificationType aVerificationType) :
+ _verificationType(aVerificationType), _line(0) {
+ }
+
+ virtual ~VerificationEvent() = default;
+
+ VerificationType verificationType() const {
+ return _verificationType;
+ }
+
+ void setFileInfo(const char * aFile, int aLine, const char * aCallingMethod) {
+ _file = aFile;
+ _callingMethod = aCallingMethod;
+ _line = aLine;
+ }
+
+ const char * file() const {
+ return _file;
+ }
+
+ int line() const {
+ return _line;
+ }
+
+ const char * callingMethod() const {
+ return _callingMethod;
+ }
+
+ private:
+ VerificationType _verificationType;
+ const char * _file;
+ int _line;
+ const char * _callingMethod;
+ };
+
+ struct NoMoreInvocationsVerificationEvent : public VerificationEvent {
+
+ ~NoMoreInvocationsVerificationEvent() = default;
+
+ NoMoreInvocationsVerificationEvent(
+ std::vector<Invocation *> &allTheIvocations,
+ std::vector<Invocation *> &anUnverifedIvocations) :
+ VerificationEvent(VerificationType::NoMoreInvocations),
+ _allIvocations(allTheIvocations),
+ _unverifedIvocations(anUnverifedIvocations) {
+ }
+
+ const std::vector<Invocation *> &allIvocations() const {
+ return _allIvocations;
+ }
+
+ const std::vector<Invocation *> &unverifedIvocations() const {
+ return _unverifedIvocations;
+ }
+
+ private:
+ const std::vector<Invocation *> _allIvocations;
+ const std::vector<Invocation *> _unverifedIvocations;
+ };
+
+ struct SequenceVerificationEvent : public VerificationEvent {
+
+ ~SequenceVerificationEvent() = default;
+
+ SequenceVerificationEvent(VerificationType aVerificationType,
+ std::vector<Sequence *> &anExpectedPattern,
+ std::vector<Invocation *> &anActualSequence,
+ int anExpectedCount,
+ int anActualCount) :
+ VerificationEvent(aVerificationType),
+ _expectedPattern(anExpectedPattern),
+ _actualSequence(anActualSequence),
+ _expectedCount(anExpectedCount),
+ _actualCount(anActualCount)
+ {
+ }
+
+ const std::vector<Sequence *> &expectedPattern() const {
+ return _expectedPattern;
+ }
+
+ const std::vector<Invocation *> &actualSequence() const {
+ return _actualSequence;
+ }
+
+ int expectedCount() const {
+ return _expectedCount;
+ }
+
+ int actualCount() const {
+ return _actualCount;
+ }
+
+ private:
+ const std::vector<Sequence *> _expectedPattern;
+ const std::vector<Invocation *> _actualSequence;
+ const int _expectedCount;
+ const int _actualCount;
+ };
+
+ struct UnexpectedMethodCallEvent {
+ UnexpectedMethodCallEvent(UnexpectedType unexpectedType, const Invocation &invocation) :
+ _unexpectedType(unexpectedType), _invocation(invocation) {
+ }
+
+ const Invocation &getInvocation() const {
+ return _invocation;
+ }
+
+ UnexpectedType getUnexpectedType() const {
+ return _unexpectedType;
+ }
+
+ const UnexpectedType _unexpectedType;
+ const Invocation &_invocation;
+ };
+
+}
+
+namespace fakeit {
+
+ struct VerificationEventHandler {
+ virtual void handle(const SequenceVerificationEvent &e) = 0;
+
+ virtual void handle(const NoMoreInvocationsVerificationEvent &e) = 0;
+ };
+
+ struct EventHandler : public VerificationEventHandler {
+ using VerificationEventHandler::handle;
+
+ virtual void handle(const UnexpectedMethodCallEvent &e) = 0;
+ };
+
+}
+#include <vector>
+#include <string>
+
+namespace fakeit {
+
+ struct UnexpectedMethodCallEvent;
+ struct SequenceVerificationEvent;
+ struct NoMoreInvocationsVerificationEvent;
+
+ struct EventFormatter {
+
+ virtual std::string format(const fakeit::UnexpectedMethodCallEvent &e) = 0;
+
+ virtual std::string format(const fakeit::SequenceVerificationEvent &e) = 0;
+
+ virtual std::string format(const fakeit::NoMoreInvocationsVerificationEvent &e) = 0;
+
+ };
+
+}
+#ifdef FAKEIT_ASSERT_ON_UNEXPECTED_METHOD_INVOCATION
+#include <cassert>
+#endif
+
+namespace fakeit {
+
+ struct FakeitContext : public EventHandler, protected EventFormatter {
+
+ virtual ~FakeitContext() = default;
+
+ void handle(const UnexpectedMethodCallEvent &e) override {
+ fireEvent(e);
+ auto &eh = getTestingFrameworkAdapter();
+ #ifdef FAKEIT_ASSERT_ON_UNEXPECTED_METHOD_INVOCATION
+ assert(!"Unexpected method invocation");
+ #endif
+ eh.handle(e);
+ }
+
+ void handle(const SequenceVerificationEvent &e) override {
+ fireEvent(e);
+ auto &eh = getTestingFrameworkAdapter();
+ return eh.handle(e);
+ }
+
+ void handle(const NoMoreInvocationsVerificationEvent &e) override {
+ fireEvent(e);
+ auto &eh = getTestingFrameworkAdapter();
+ return eh.handle(e);
+ }
+
+ std::string format(const UnexpectedMethodCallEvent &e) override {
+ auto &eventFormatter = getEventFormatter();
+ return eventFormatter.format(e);
+ }
+
+ std::string format(const SequenceVerificationEvent &e) override {
+ auto &eventFormatter = getEventFormatter();
+ return eventFormatter.format(e);
+ }
+
+ std::string format(const NoMoreInvocationsVerificationEvent &e) override {
+ auto &eventFormatter = getEventFormatter();
+ return eventFormatter.format(e);
+ }
+
+ void addEventHandler(EventHandler &eventListener) {
+ _eventListeners.push_back(&eventListener);
+ }
+
+ void clearEventHandlers() {
+ _eventListeners.clear();
+ }
+
+ protected:
+ virtual EventHandler &getTestingFrameworkAdapter() = 0;
+
+ virtual EventFormatter &getEventFormatter() = 0;
+
+ private:
+ std::vector<EventHandler *> _eventListeners;
+
+ void fireEvent(const NoMoreInvocationsVerificationEvent &evt) {
+ for (auto listener : _eventListeners)
+ listener->handle(evt);
+ }
+
+ void fireEvent(const UnexpectedMethodCallEvent &evt) {
+ for (auto listener : _eventListeners)
+ listener->handle(evt);
+ }
+
+ void fireEvent(const SequenceVerificationEvent &evt) {
+ for (auto listener : _eventListeners)
+ listener->handle(evt);
+ }
+
+ };
+
+}
+#include <iostream>
+#include <iosfwd>
+
+namespace fakeit {
+
+ struct DefaultEventFormatter : public EventFormatter {
+
+ virtual std::string format(const UnexpectedMethodCallEvent &e) override {
+ std::ostringstream out;
+ out << "Unexpected method invocation: ";
+ out << e.getInvocation().format() << std::endl;
+ if (UnexpectedType::Unmatched == e.getUnexpectedType()) {
+ out << " Could not find any recorded behavior to support this method call.";
+ } else {
+ out << " An unmocked method was invoked. All used virtual methods must be stubbed!";
+ }
+ return out.str();
+ }
+
+
+ virtual std::string format(const SequenceVerificationEvent &e) override {
+ std::ostringstream out;
+ out << "Verification error" << std::endl;
+
+ out << "Expected pattern: ";
+ const std::vector<fakeit::Sequence *> expectedPattern = e.expectedPattern();
+ out << formatExpectedPattern(expectedPattern) << std::endl;
+
+ out << "Expected matches: ";
+ formatExpectedCount(out, e.verificationType(), e.expectedCount());
+ out << std::endl;
+
+ out << "Actual matches : " << e.actualCount() << std::endl;
+
+ auto actualSequence = e.actualSequence();
+ out << "Actual sequence : total of " << actualSequence.size() << " actual invocations";
+ if (actualSequence.size() == 0) {
+ out << ".";
+ } else {
+ out << ":" << std::endl;
+ }
+ formatInvocationList(out, actualSequence);
+
+ return out.str();
+ }
+
+ virtual std::string format(const NoMoreInvocationsVerificationEvent &e) override {
+ std::ostringstream out;
+ out << "Verification error" << std::endl;
+ out << "Expected no more invocations!! but the following unverified invocations were found:" << std::endl;
+ formatInvocationList(out, e.unverifedIvocations());
+ return out.str();
+ }
+
+ static std::string formatExpectedPattern(const std::vector<fakeit::Sequence *> &expectedPattern) {
+ std::string expectedPatternStr;
+ for (unsigned int i = 0; i < expectedPattern.size(); i++) {
+ Sequence *s = expectedPattern[i];
+ expectedPatternStr += formatSequence(*s);
+ if (i < expectedPattern.size() - 1)
+ expectedPatternStr += " ... ";
+ }
+ return expectedPatternStr;
+ }
+
+ private:
+
+ static std::string formatSequence(const Sequence &val) {
+ const ConcatenatedSequence *cs = dynamic_cast<const ConcatenatedSequence *>(&val);
+ if (cs) {
+ return format(*cs);
+ }
+ const RepeatedSequence *rs = dynamic_cast<const RepeatedSequence *>(&val);
+ if (rs) {
+ return format(*rs);
+ }
+
+
+ std::vector<Invocation::Matcher *> vec;
+ val.getExpectedSequence(vec);
+ return vec[0]->format();
+ }
+
+ static void formatExpectedCount(std::ostream &out, fakeit::VerificationType verificationType,
+ int expectedCount) {
+ if (verificationType == fakeit::VerificationType::Exact)
+ out << "exactly ";
+
+ if (verificationType == fakeit::VerificationType::AtLeast)
+ out << "at least ";
+
+ out << expectedCount;
+ }
+
+ static void formatInvocationList(std::ostream &out, const std::vector<fakeit::Invocation *> &actualSequence) {
+ size_t max_size = actualSequence.size();
+ if (max_size > 50)
+ max_size = 50;
+
+ for (unsigned int i = 0; i < max_size; i++) {
+ out << " ";
+ auto invocation = actualSequence[i];
+ out << invocation->format();
+ if (i < max_size - 1)
+ out << std::endl;
+ }
+
+ if (actualSequence.size() > max_size)
+ out << std::endl << " ...";
+ }
+
+ static std::string format(const ConcatenatedSequence &val) {
+ std::ostringstream out;
+ out << formatSequence(val.getLeft()) << " + " << formatSequence(val.getRight());
+ return out.str();
+ }
+
+ static std::string format(const RepeatedSequence &val) {
+ std::ostringstream out;
+ const ConcatenatedSequence *cs = dynamic_cast<const ConcatenatedSequence *>(&val.getSequence());
+ const RepeatedSequence *rs = dynamic_cast<const RepeatedSequence *>(&val.getSequence());
+ if (rs || cs)
+ out << '(';
+ out << formatSequence(val.getSequence());
+ if (rs || cs)
+ out << ')';
+
+ out << " * " << val.getTimes();
+ return out.str();
+ }
+ };
+}
+namespace fakeit {
+
+ struct FakeitException {
+ std::exception err;
+
+ virtual ~FakeitException() = default;
+
+ virtual std::string what() const = 0;
+
+ friend std::ostream &operator<<(std::ostream &os, const FakeitException &val) {
+ os << val.what();
+ return os;
+ }
+ };
+
+
+
+
+ struct UnexpectedMethodCallException : public FakeitException {
+
+ UnexpectedMethodCallException(std::string format) :
+ _format(format) {
+ }
+
+ virtual std::string what() const override {
+ return _format;
+ }
+
+ private:
+ std::string _format;
+ };
+
+}
+
+namespace fakeit {
+
+ struct DefaultEventLogger : public fakeit::EventHandler {
+
+ DefaultEventLogger(EventFormatter &formatter) : _formatter(formatter), _out(std::cout) { }
+
+ virtual void handle(const UnexpectedMethodCallEvent &e) override {
+ _out << _formatter.format(e) << std::endl;
+ }
+
+ virtual void handle(const SequenceVerificationEvent &e) override {
+ _out << _formatter.format(e) << std::endl;
+ }
+
+ virtual void handle(const NoMoreInvocationsVerificationEvent &e) override {
+ _out << _formatter.format(e) << std::endl;
+ }
+
+ private:
+ EventFormatter &_formatter;
+ std::ostream &_out;
+ };
+
+}
+
+namespace fakeit {
+
+ class AbstractFakeit : public FakeitContext {
+ public:
+ virtual ~AbstractFakeit() = default;
+
+ protected:
+
+ virtual fakeit::EventHandler &accessTestingFrameworkAdapter() = 0;
+
+ virtual EventFormatter &accessEventFormatter() = 0;
+ };
+
+ class DefaultFakeit : public AbstractFakeit {
+ DefaultEventFormatter _formatter;
+ fakeit::EventFormatter *_customFormatter;
+ fakeit::EventHandler *_testingFrameworkAdapter;
+
+ public:
+
+ DefaultFakeit() : _formatter(),
+ _customFormatter(nullptr),
+ _testingFrameworkAdapter(nullptr) {
+ }
+
+ virtual ~DefaultFakeit() = default;
+
+ void setCustomEventFormatter(fakeit::EventFormatter &customEventFormatter) {
+ _customFormatter = &customEventFormatter;
+ }
+
+ void resetCustomEventFormatter() {
+ _customFormatter = nullptr;
+ }
+
+ void setTestingFrameworkAdapter(fakeit::EventHandler &testingFrameforkAdapter) {
+ _testingFrameworkAdapter = &testingFrameforkAdapter;
+ }
+
+ void resetTestingFrameworkAdapter() {
+ _testingFrameworkAdapter = nullptr;
+ }
+
+ protected:
+
+ fakeit::EventHandler &getTestingFrameworkAdapter() override {
+ if (_testingFrameworkAdapter)
+ return *_testingFrameworkAdapter;
+ return accessTestingFrameworkAdapter();
+ }
+
+ EventFormatter &getEventFormatter() override {
+ if (_customFormatter)
+ return *_customFormatter;
+ return accessEventFormatter();
+ }
+
+ EventFormatter &accessEventFormatter() override {
+ return _formatter;
+ }
+
+ };
+}
+#include <string>
+#include <sstream>
+#include <iomanip>
+
+namespace fakeit {
+
+ template<typename T>
+ static std::string to_string(const T &n) {
+ std::ostringstream stm;
+ stm << n;
+ return stm.str();
+ }
+
+}
+
+namespace fakeit {
+
+ struct VerificationException : public FakeitException {
+ virtual ~VerificationException() = default;
+
+ void setFileInfo(const char *file, int line, const char *callingMethod) {
+ _file = file;
+ _callingMethod = callingMethod;
+ _line = line;
+ }
+
+ const char *file() const {
+ return _file;
+ }
+
+ int line() const {
+ return _line;
+ }
+
+ const char *callingMethod() const {
+ return _callingMethod;
+ }
+
+ private:
+ const char *_file;
+ int _line;
+ const char *_callingMethod;
+ };
+
+ struct NoMoreInvocationsVerificationException : public VerificationException {
+
+ NoMoreInvocationsVerificationException(std::string format) :
+ _format(format) {
+ }
+
+ virtual std::string what() const override {
+ return _format;
+ }
+
+ private:
+ std::string _format;
+ };
+
+ struct SequenceVerificationException : public VerificationException {
+ SequenceVerificationException(const std::string &format) :
+ _format(format)
+ {
+ }
+
+ virtual std::string what() const override {
+ return _format;
+ }
+
+ private:
+ std::string _format;
+ };
+
+ class CatchAdapter : public EventHandler {
+ EventFormatter &_formatter;
+
+ std::string formatLineNumber(std::string file, int num) {
+#ifndef __GNUG__
+ return file + std::string("(") + fakeit::to_string(num) + std::string(")");
+#else
+ return file + std::string(":") + fakeit::to_string(num);
+#endif
+ }
+
+ public:
+
+ virtual ~CatchAdapter() = default;
+
+ CatchAdapter(EventFormatter &formatter)
+ : _formatter(formatter) {}
+
+ void fail(
+ std::string vetificationType,
+ Catch::SourceLineInfo sourceLineInfo,
+ std::string failingExpression,
+ std::string fomattedMessage,
+ Catch::ResultWas::OfType resultWas = Catch::ResultWas::OfType::ExpressionFailed ){
+ Catch::AssertionHandler catchAssertionHandler( vetificationType, sourceLineInfo, failingExpression, Catch::ResultDisposition::Normal );
+ INTERNAL_CATCH_TRY { \
+ CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
+ catchAssertionHandler.handleMessage(resultWas, fomattedMessage); \
+ CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
+ } INTERNAL_CATCH_CATCH(catchAssertionHandler) { \
+ INTERNAL_CATCH_REACT(catchAssertionHandler) \
+ }
+ }
+
+ virtual void handle(const UnexpectedMethodCallEvent &evt) override {
+ std::string format = _formatter.format(evt);
+ fail("UnexpectedMethodCall",::Catch::SourceLineInfo("Unknown file",0),"",format, Catch::ResultWas::OfType::ExplicitFailure);
+ }
+
+ virtual void handle(const SequenceVerificationEvent &evt) override {
+ std::string format(formatLineNumber(evt.file(), evt.line()) + ": " + _formatter.format(evt));
+ std::string expectedPattern {DefaultEventFormatter::formatExpectedPattern(evt.expectedPattern())};
+ fail("Verify",::Catch::SourceLineInfo(evt.file(),evt.line()),expectedPattern,format);
+ }
+
+
+ virtual void handle(const NoMoreInvocationsVerificationEvent &evt) override {
+ std::string format(formatLineNumber(evt.file(), evt.line()) + ": " + _formatter.format(evt));
+ fail("VerifyNoMoreInvocations",::Catch::SourceLineInfo(evt.file(),evt.line()),"",format);
+ }
+
+ };
+
+
+ class CatchFakeit : public DefaultFakeit {
+
+
+ public:
+
+ virtual ~CatchFakeit() = default;
+
+ CatchFakeit() : _formatter(), _catchAdapter(_formatter) {}
+
+ static CatchFakeit &getInstance() {
+ static CatchFakeit instance;
+ return instance;
+ }
+
+ protected:
+
+ fakeit::EventHandler &accessTestingFrameworkAdapter() override {
+ return _catchAdapter;
+ }
+
+ EventFormatter &accessEventFormatter() override {
+ return _formatter;
+ }
+
+ private:
+
+ DefaultEventFormatter _formatter;
+ CatchAdapter _catchAdapter;
+ };
+
+}
+
+static fakeit::DefaultFakeit& Fakeit = fakeit::CatchFakeit::getInstance();
+
+
+#include <type_traits>
+#include <unordered_set>
+
+#include <memory>
+#undef max
+#include <functional>
+#include <type_traits>
+#include <vector>
+#include <array>
+#include <new>
+#include <limits>
+
+#include <functional>
+#include <type_traits>
+namespace fakeit {
+
+ struct VirtualOffsetSelector {
+
+ unsigned int offset;
+
+ virtual unsigned int offset0(int) {
+ return offset = 0;
+ }
+
+ virtual unsigned int offset1(int) {
+ return offset = 1;
+ }
+
+ virtual unsigned int offset2(int) {
+ return offset = 2;
+ }
+
+ virtual unsigned int offset3(int) {
+ return offset = 3;
+ }
+
+ virtual unsigned int offset4(int) {
+ return offset = 4;
+ }
+
+ virtual unsigned int offset5(int) {
+ return offset = 5;
+ }
+
+ virtual unsigned int offset6(int) {
+ return offset = 6;
+ }
+
+ virtual unsigned int offset7(int) {
+ return offset = 7;
+ }
+
+ virtual unsigned int offset8(int) {
+ return offset = 8;
+ }
+
+ virtual unsigned int offset9(int) {
+ return offset = 9;
+ }
+
+ virtual unsigned int offset10(int) {
+ return offset = 10;
+ }
+
+ virtual unsigned int offset11(int) {
+ return offset = 11;
+ }
+
+ virtual unsigned int offset12(int) {
+ return offset = 12;
+ }
+
+ virtual unsigned int offset13(int) {
+ return offset = 13;
+ }
+
+ virtual unsigned int offset14(int) {
+ return offset = 14;
+ }
+
+ virtual unsigned int offset15(int) {
+ return offset = 15;
+ }
+
+ virtual unsigned int offset16(int) {
+ return offset = 16;
+ }
+
+ virtual unsigned int offset17(int) {
+ return offset = 17;
+ }
+
+ virtual unsigned int offset18(int) {
+ return offset = 18;
+ }
+
+ virtual unsigned int offset19(int) {
+ return offset = 19;
+ }
+
+ virtual unsigned int offset20(int) {
+ return offset = 20;
+ }
+
+ virtual unsigned int offset21(int) {
+ return offset = 21;
+ }
+
+ virtual unsigned int offset22(int) {
+ return offset = 22;
+ }
+
+ virtual unsigned int offset23(int) {
+ return offset = 23;
+ }
+
+ virtual unsigned int offset24(int) {
+ return offset = 24;
+ }
+
+ virtual unsigned int offset25(int) {
+ return offset = 25;
+ }
+
+ virtual unsigned int offset26(int) {
+ return offset = 26;
+ }
+
+ virtual unsigned int offset27(int) {
+ return offset = 27;
+ }
+
+ virtual unsigned int offset28(int) {
+ return offset = 28;
+ }
+
+ virtual unsigned int offset29(int) {
+ return offset = 29;
+ }
+
+ virtual unsigned int offset30(int) {
+ return offset = 30;
+ }
+
+ virtual unsigned int offset31(int) {
+ return offset = 31;
+ }
+
+ virtual unsigned int offset32(int) {
+ return offset = 32;
+ }
+
+ virtual unsigned int offset33(int) {
+ return offset = 33;
+ }
+
+ virtual unsigned int offset34(int) {
+ return offset = 34;
+ }
+
+ virtual unsigned int offset35(int) {
+ return offset = 35;
+ }
+
+ virtual unsigned int offset36(int) {
+ return offset = 36;
+ }
+
+ virtual unsigned int offset37(int) {
+ return offset = 37;
+ }
+
+ virtual unsigned int offset38(int) {
+ return offset = 38;
+ }
+
+ virtual unsigned int offset39(int) {
+ return offset = 39;
+ }
+
+ virtual unsigned int offset40(int) {
+ return offset = 40;
+ }
+
+ virtual unsigned int offset41(int) {
+ return offset = 41;
+ }
+
+ virtual unsigned int offset42(int) {
+ return offset = 42;
+ }
+
+ virtual unsigned int offset43(int) {
+ return offset = 43;
+ }
+
+ virtual unsigned int offset44(int) {
+ return offset = 44;
+ }
+
+ virtual unsigned int offset45(int) {
+ return offset = 45;
+ }
+
+ virtual unsigned int offset46(int) {
+ return offset = 46;
+ }
+
+ virtual unsigned int offset47(int) {
+ return offset = 47;
+ }
+
+ virtual unsigned int offset48(int) {
+ return offset = 48;
+ }
+
+ virtual unsigned int offset49(int) {
+ return offset = 49;
+ }
+
+ virtual unsigned int offset50(int) {
+ return offset = 50;
+ }
+
+ virtual unsigned int offset51(int) {
+ return offset = 51;
+ }
+
+ virtual unsigned int offset52(int) {
+ return offset = 52;
+ }
+
+ virtual unsigned int offset53(int) {
+ return offset = 53;
+ }
+
+ virtual unsigned int offset54(int) {
+ return offset = 54;
+ }
+
+ virtual unsigned int offset55(int) {
+ return offset = 55;
+ }
+
+ virtual unsigned int offset56(int) {
+ return offset = 56;
+ }
+
+ virtual unsigned int offset57(int) {
+ return offset = 57;
+ }
+
+ virtual unsigned int offset58(int) {
+ return offset = 58;
+ }
+
+ virtual unsigned int offset59(int) {
+ return offset = 59;
+ }
+
+ virtual unsigned int offset60(int) {
+ return offset = 60;
+ }
+
+ virtual unsigned int offset61(int) {
+ return offset = 61;
+ }
+
+ virtual unsigned int offset62(int) {
+ return offset = 62;
+ }
+
+ virtual unsigned int offset63(int) {
+ return offset = 63;
+ }
+
+ virtual unsigned int offset64(int) {
+ return offset = 64;
+ }
+
+ virtual unsigned int offset65(int) {
+ return offset = 65;
+ }
+
+ virtual unsigned int offset66(int) {
+ return offset = 66;
+ }
+
+ virtual unsigned int offset67(int) {
+ return offset = 67;
+ }
+
+ virtual unsigned int offset68(int) {
+ return offset = 68;
+ }
+
+ virtual unsigned int offset69(int) {
+ return offset = 69;
+ }
+
+ virtual unsigned int offset70(int) {
+ return offset = 70;
+ }
+
+ virtual unsigned int offset71(int) {
+ return offset = 71;
+ }
+
+ virtual unsigned int offset72(int) {
+ return offset = 72;
+ }
+
+ virtual unsigned int offset73(int) {
+ return offset = 73;
+ }
+
+ virtual unsigned int offset74(int) {
+ return offset = 74;
+ }
+
+ virtual unsigned int offset75(int) {
+ return offset = 75;
+ }
+
+ virtual unsigned int offset76(int) {
+ return offset = 76;
+ }
+
+ virtual unsigned int offset77(int) {
+ return offset = 77;
+ }
+
+ virtual unsigned int offset78(int) {
+ return offset = 78;
+ }
+
+ virtual unsigned int offset79(int) {
+ return offset = 79;
+ }
+
+ virtual unsigned int offset80(int) {
+ return offset = 80;
+ }
+
+ virtual unsigned int offset81(int) {
+ return offset = 81;
+ }
+
+ virtual unsigned int offset82(int) {
+ return offset = 82;
+ }
+
+ virtual unsigned int offset83(int) {
+ return offset = 83;
+ }
+
+ virtual unsigned int offset84(int) {
+ return offset = 84;
+ }
+
+ virtual unsigned int offset85(int) {
+ return offset = 85;
+ }
+
+ virtual unsigned int offset86(int) {
+ return offset = 86;
+ }
+
+ virtual unsigned int offset87(int) {
+ return offset = 87;
+ }
+
+ virtual unsigned int offset88(int) {
+ return offset = 88;
+ }
+
+ virtual unsigned int offset89(int) {
+ return offset = 89;
+ }
+
+ virtual unsigned int offset90(int) {
+ return offset = 90;
+ }
+
+ virtual unsigned int offset91(int) {
+ return offset = 91;
+ }
+
+ virtual unsigned int offset92(int) {
+ return offset = 92;
+ }
+
+ virtual unsigned int offset93(int) {
+ return offset = 93;
+ }
+
+ virtual unsigned int offset94(int) {
+ return offset = 94;
+ }
+
+ virtual unsigned int offset95(int) {
+ return offset = 95;
+ }
+
+ virtual unsigned int offset96(int) {
+ return offset = 96;
+ }
+
+ virtual unsigned int offset97(int) {
+ return offset = 97;
+ }
+
+ virtual unsigned int offset98(int) {
+ return offset = 98;
+ }
+
+ virtual unsigned int offset99(int) {
+ return offset = 99;
+ }
+
+ virtual unsigned int offset100(int) {
+ return offset = 100;
+ }
+
+ virtual unsigned int offset101(int) {
+ return offset = 101;
+ }
+
+ virtual unsigned int offset102(int) {
+ return offset = 102;
+ }
+
+ virtual unsigned int offset103(int) {
+ return offset = 103;
+ }
+
+ virtual unsigned int offset104(int) {
+ return offset = 104;
+ }
+
+ virtual unsigned int offset105(int) {
+ return offset = 105;
+ }
+
+ virtual unsigned int offset106(int) {
+ return offset = 106;
+ }
+
+ virtual unsigned int offset107(int) {
+ return offset = 107;
+ }
+
+ virtual unsigned int offset108(int) {
+ return offset = 108;
+ }
+
+ virtual unsigned int offset109(int) {
+ return offset = 109;
+ }
+
+ virtual unsigned int offset110(int) {
+ return offset = 110;
+ }
+
+ virtual unsigned int offset111(int) {
+ return offset = 111;
+ }
+
+ virtual unsigned int offset112(int) {
+ return offset = 112;
+ }
+
+ virtual unsigned int offset113(int) {
+ return offset = 113;
+ }
+
+ virtual unsigned int offset114(int) {
+ return offset = 114;
+ }
+
+ virtual unsigned int offset115(int) {
+ return offset = 115;
+ }
+
+ virtual unsigned int offset116(int) {
+ return offset = 116;
+ }
+
+ virtual unsigned int offset117(int) {
+ return offset = 117;
+ }
+
+ virtual unsigned int offset118(int) {
+ return offset = 118;
+ }
+
+ virtual unsigned int offset119(int) {
+ return offset = 119;
+ }
+
+ virtual unsigned int offset120(int) {
+ return offset = 120;
+ }
+
+ virtual unsigned int offset121(int) {
+ return offset = 121;
+ }
+
+ virtual unsigned int offset122(int) {
+ return offset = 122;
+ }
+
+ virtual unsigned int offset123(int) {
+ return offset = 123;
+ }
+
+ virtual unsigned int offset124(int) {
+ return offset = 124;
+ }
+
+ virtual unsigned int offset125(int) {
+ return offset = 125;
+ }
+
+ virtual unsigned int offset126(int) {
+ return offset = 126;
+ }
+
+ virtual unsigned int offset127(int) {
+ return offset = 127;
+ }
+
+ virtual unsigned int offset128(int) {
+ return offset = 128;
+ }
+
+ virtual unsigned int offset129(int) {
+ return offset = 129;
+ }
+
+ virtual unsigned int offset130(int) {
+ return offset = 130;
+ }
+
+ virtual unsigned int offset131(int) {
+ return offset = 131;
+ }
+
+ virtual unsigned int offset132(int) {
+ return offset = 132;
+ }
+
+ virtual unsigned int offset133(int) {
+ return offset = 133;
+ }
+
+ virtual unsigned int offset134(int) {
+ return offset = 134;
+ }
+
+ virtual unsigned int offset135(int) {
+ return offset = 135;
+ }
+
+ virtual unsigned int offset136(int) {
+ return offset = 136;
+ }
+
+ virtual unsigned int offset137(int) {
+ return offset = 137;
+ }
+
+ virtual unsigned int offset138(int) {
+ return offset = 138;
+ }
+
+ virtual unsigned int offset139(int) {
+ return offset = 139;
+ }
+
+ virtual unsigned int offset140(int) {
+ return offset = 140;
+ }
+
+ virtual unsigned int offset141(int) {
+ return offset = 141;
+ }
+
+ virtual unsigned int offset142(int) {
+ return offset = 142;
+ }
+
+ virtual unsigned int offset143(int) {
+ return offset = 143;
+ }
+
+ virtual unsigned int offset144(int) {
+ return offset = 144;
+ }
+
+ virtual unsigned int offset145(int) {
+ return offset = 145;
+ }
+
+ virtual unsigned int offset146(int) {
+ return offset = 146;
+ }
+
+ virtual unsigned int offset147(int) {
+ return offset = 147;
+ }
+
+ virtual unsigned int offset148(int) {
+ return offset = 148;
+ }
+
+ virtual unsigned int offset149(int) {
+ return offset = 149;
+ }
+
+ virtual unsigned int offset150(int) {
+ return offset = 150;
+ }
+
+ virtual unsigned int offset151(int) {
+ return offset = 151;
+ }
+
+ virtual unsigned int offset152(int) {
+ return offset = 152;
+ }
+
+ virtual unsigned int offset153(int) {
+ return offset = 153;
+ }
+
+ virtual unsigned int offset154(int) {
+ return offset = 154;
+ }
+
+ virtual unsigned int offset155(int) {
+ return offset = 155;
+ }
+
+ virtual unsigned int offset156(int) {
+ return offset = 156;
+ }
+
+ virtual unsigned int offset157(int) {
+ return offset = 157;
+ }
+
+ virtual unsigned int offset158(int) {
+ return offset = 158;
+ }
+
+ virtual unsigned int offset159(int) {
+ return offset = 159;
+ }
+
+ virtual unsigned int offset160(int) {
+ return offset = 160;
+ }
+
+ virtual unsigned int offset161(int) {
+ return offset = 161;
+ }
+
+ virtual unsigned int offset162(int) {
+ return offset = 162;
+ }
+
+ virtual unsigned int offset163(int) {
+ return offset = 163;
+ }
+
+ virtual unsigned int offset164(int) {
+ return offset = 164;
+ }
+
+ virtual unsigned int offset165(int) {
+ return offset = 165;
+ }
+
+ virtual unsigned int offset166(int) {
+ return offset = 166;
+ }
+
+ virtual unsigned int offset167(int) {
+ return offset = 167;
+ }
+
+ virtual unsigned int offset168(int) {
+ return offset = 168;
+ }
+
+ virtual unsigned int offset169(int) {
+ return offset = 169;
+ }
+
+ virtual unsigned int offset170(int) {
+ return offset = 170;
+ }
+
+ virtual unsigned int offset171(int) {
+ return offset = 171;
+ }
+
+ virtual unsigned int offset172(int) {
+ return offset = 172;
+ }
+
+ virtual unsigned int offset173(int) {
+ return offset = 173;
+ }
+
+ virtual unsigned int offset174(int) {
+ return offset = 174;
+ }
+
+ virtual unsigned int offset175(int) {
+ return offset = 175;
+ }
+
+ virtual unsigned int offset176(int) {
+ return offset = 176;
+ }
+
+ virtual unsigned int offset177(int) {
+ return offset = 177;
+ }
+
+ virtual unsigned int offset178(int) {
+ return offset = 178;
+ }
+
+ virtual unsigned int offset179(int) {
+ return offset = 179;
+ }
+
+ virtual unsigned int offset180(int) {
+ return offset = 180;
+ }
+
+ virtual unsigned int offset181(int) {
+ return offset = 181;
+ }
+
+ virtual unsigned int offset182(int) {
+ return offset = 182;
+ }
+
+ virtual unsigned int offset183(int) {
+ return offset = 183;
+ }
+
+ virtual unsigned int offset184(int) {
+ return offset = 184;
+ }
+
+ virtual unsigned int offset185(int) {
+ return offset = 185;
+ }
+
+ virtual unsigned int offset186(int) {
+ return offset = 186;
+ }
+
+ virtual unsigned int offset187(int) {
+ return offset = 187;
+ }
+
+ virtual unsigned int offset188(int) {
+ return offset = 188;
+ }
+
+ virtual unsigned int offset189(int) {
+ return offset = 189;
+ }
+
+ virtual unsigned int offset190(int) {
+ return offset = 190;
+ }
+
+ virtual unsigned int offset191(int) {
+ return offset = 191;
+ }
+
+ virtual unsigned int offset192(int) {
+ return offset = 192;
+ }
+
+ virtual unsigned int offset193(int) {
+ return offset = 193;
+ }
+
+ virtual unsigned int offset194(int) {
+ return offset = 194;
+ }
+
+ virtual unsigned int offset195(int) {
+ return offset = 195;
+ }
+
+ virtual unsigned int offset196(int) {
+ return offset = 196;
+ }
+
+ virtual unsigned int offset197(int) {
+ return offset = 197;
+ }
+
+ virtual unsigned int offset198(int) {
+ return offset = 198;
+ }
+
+ virtual unsigned int offset199(int) {
+ return offset = 199;
+ }
+
+
+ virtual unsigned int offset200(int) {
+ return offset = 200;
+ }
+
+ virtual unsigned int offset201(int) {
+ return offset = 201;
+ }
+
+ virtual unsigned int offset202(int) {
+ return offset = 202;
+ }
+
+ virtual unsigned int offset203(int) {
+ return offset = 203;
+ }
+
+ virtual unsigned int offset204(int) {
+ return offset = 204;
+ }
+
+ virtual unsigned int offset205(int) {
+ return offset = 205;
+ }
+
+ virtual unsigned int offset206(int) {
+ return offset = 206;
+ }
+
+ virtual unsigned int offset207(int) {
+ return offset = 207;
+ }
+
+ virtual unsigned int offset208(int) {
+ return offset = 208;
+ }
+
+ virtual unsigned int offset209(int) {
+ return offset = 209;
+ }
+
+ virtual unsigned int offset210(int) {
+ return offset = 210;
+ }
+
+ virtual unsigned int offset211(int) {
+ return offset = 211;
+ }
+
+ virtual unsigned int offset212(int) {
+ return offset = 212;
+ }
+
+ virtual unsigned int offset213(int) {
+ return offset = 213;
+ }
+
+ virtual unsigned int offset214(int) {
+ return offset = 214;
+ }
+
+ virtual unsigned int offset215(int) {
+ return offset = 215;
+ }
+
+ virtual unsigned int offset216(int) {
+ return offset = 216;
+ }
+
+ virtual unsigned int offset217(int) {
+ return offset = 217;
+ }
+
+ virtual unsigned int offset218(int) {
+ return offset = 218;
+ }
+
+ virtual unsigned int offset219(int) {
+ return offset = 219;
+ }
+
+ virtual unsigned int offset220(int) {
+ return offset = 220;
+ }
+
+ virtual unsigned int offset221(int) {
+ return offset = 221;
+ }
+
+ virtual unsigned int offset222(int) {
+ return offset = 222;
+ }
+
+ virtual unsigned int offset223(int) {
+ return offset = 223;
+ }
+
+ virtual unsigned int offset224(int) {
+ return offset = 224;
+ }
+
+ virtual unsigned int offset225(int) {
+ return offset = 225;
+ }
+
+ virtual unsigned int offset226(int) {
+ return offset = 226;
+ }
+
+ virtual unsigned int offset227(int) {
+ return offset = 227;
+ }
+
+ virtual unsigned int offset228(int) {
+ return offset = 228;
+ }
+
+ virtual unsigned int offset229(int) {
+ return offset = 229;
+ }
+
+ virtual unsigned int offset230(int) {
+ return offset = 230;
+ }
+
+ virtual unsigned int offset231(int) {
+ return offset = 231;
+ }
+
+ virtual unsigned int offset232(int) {
+ return offset = 232;
+ }
+
+ virtual unsigned int offset233(int) {
+ return offset = 233;
+ }
+
+ virtual unsigned int offset234(int) {
+ return offset = 234;
+ }
+
+ virtual unsigned int offset235(int) {
+ return offset = 235;
+ }
+
+ virtual unsigned int offset236(int) {
+ return offset = 236;
+ }
+
+ virtual unsigned int offset237(int) {
+ return offset = 237;
+ }
+
+ virtual unsigned int offset238(int) {
+ return offset = 238;
+ }
+
+ virtual unsigned int offset239(int) {
+ return offset = 239;
+ }
+
+ virtual unsigned int offset240(int) {
+ return offset = 240;
+ }
+
+ virtual unsigned int offset241(int) {
+ return offset = 241;
+ }
+
+ virtual unsigned int offset242(int) {
+ return offset = 242;
+ }
+
+ virtual unsigned int offset243(int) {
+ return offset = 243;
+ }
+
+ virtual unsigned int offset244(int) {
+ return offset = 244;
+ }
+
+ virtual unsigned int offset245(int) {
+ return offset = 245;
+ }
+
+ virtual unsigned int offset246(int) {
+ return offset = 246;
+ }
+
+ virtual unsigned int offset247(int) {
+ return offset = 247;
+ }
+
+ virtual unsigned int offset248(int) {
+ return offset = 248;
+ }
+
+ virtual unsigned int offset249(int) {
+ return offset = 249;
+ }
+
+ virtual unsigned int offset250(int) {
+ return offset = 250;
+ }
+
+ virtual unsigned int offset251(int) {
+ return offset = 251;
+ }
+
+ virtual unsigned int offset252(int) {
+ return offset = 252;
+ }
+
+ virtual unsigned int offset253(int) {
+ return offset = 253;
+ }
+
+ virtual unsigned int offset254(int) {
+ return offset = 254;
+ }
+
+ virtual unsigned int offset255(int) {
+ return offset = 255;
+ }
+
+ virtual unsigned int offset256(int) {
+ return offset = 256;
+ }
+
+ virtual unsigned int offset257(int) {
+ return offset = 257;
+ }
+
+ virtual unsigned int offset258(int) {
+ return offset = 258;
+ }
+
+ virtual unsigned int offset259(int) {
+ return offset = 259;
+ }
+
+ virtual unsigned int offset260(int) {
+ return offset = 260;
+ }
+
+ virtual unsigned int offset261(int) {
+ return offset = 261;
+ }
+
+ virtual unsigned int offset262(int) {
+ return offset = 262;
+ }
+
+ virtual unsigned int offset263(int) {
+ return offset = 263;
+ }
+
+ virtual unsigned int offset264(int) {
+ return offset = 264;
+ }
+
+ virtual unsigned int offset265(int) {
+ return offset = 265;
+ }
+
+ virtual unsigned int offset266(int) {
+ return offset = 266;
+ }
+
+ virtual unsigned int offset267(int) {
+ return offset = 267;
+ }
+
+ virtual unsigned int offset268(int) {
+ return offset = 268;
+ }
+
+ virtual unsigned int offset269(int) {
+ return offset = 269;
+ }
+
+ virtual unsigned int offset270(int) {
+ return offset = 270;
+ }
+
+ virtual unsigned int offset271(int) {
+ return offset = 271;
+ }
+
+ virtual unsigned int offset272(int) {
+ return offset = 272;
+ }
+
+ virtual unsigned int offset273(int) {
+ return offset = 273;
+ }
+
+ virtual unsigned int offset274(int) {
+ return offset = 274;
+ }
+
+ virtual unsigned int offset275(int) {
+ return offset = 275;
+ }
+
+ virtual unsigned int offset276(int) {
+ return offset = 276;
+ }
+
+ virtual unsigned int offset277(int) {
+ return offset = 277;
+ }
+
+ virtual unsigned int offset278(int) {
+ return offset = 278;
+ }
+
+ virtual unsigned int offset279(int) {
+ return offset = 279;
+ }
+
+ virtual unsigned int offset280(int) {
+ return offset = 280;
+ }
+
+ virtual unsigned int offset281(int) {
+ return offset = 281;
+ }
+
+ virtual unsigned int offset282(int) {
+ return offset = 282;
+ }
+
+ virtual unsigned int offset283(int) {
+ return offset = 283;
+ }
+
+ virtual unsigned int offset284(int) {
+ return offset = 284;
+ }
+
+ virtual unsigned int offset285(int) {
+ return offset = 285;
+ }
+
+ virtual unsigned int offset286(int) {
+ return offset = 286;
+ }
+
+ virtual unsigned int offset287(int) {
+ return offset = 287;
+ }
+
+ virtual unsigned int offset288(int) {
+ return offset = 288;
+ }
+
+ virtual unsigned int offset289(int) {
+ return offset = 289;
+ }
+
+ virtual unsigned int offset290(int) {
+ return offset = 290;
+ }
+
+ virtual unsigned int offset291(int) {
+ return offset = 291;
+ }
+
+ virtual unsigned int offset292(int) {
+ return offset = 292;
+ }
+
+ virtual unsigned int offset293(int) {
+ return offset = 293;
+ }
+
+ virtual unsigned int offset294(int) {
+ return offset = 294;
+ }
+
+ virtual unsigned int offset295(int) {
+ return offset = 295;
+ }
+
+ virtual unsigned int offset296(int) {
+ return offset = 296;
+ }
+
+ virtual unsigned int offset297(int) {
+ return offset = 297;
+ }
+
+ virtual unsigned int offset298(int) {
+ return offset = 298;
+ }
+
+ virtual unsigned int offset299(int) {
+ return offset = 299;
+ }
+
+
+ virtual unsigned int offset300(int) {
+ return offset = 300;
+ }
+
+ virtual unsigned int offset301(int) {
+ return offset = 301;
+ }
+
+ virtual unsigned int offset302(int) {
+ return offset = 302;
+ }
+
+ virtual unsigned int offset303(int) {
+ return offset = 303;
+ }
+
+ virtual unsigned int offset304(int) {
+ return offset = 304;
+ }
+
+ virtual unsigned int offset305(int) {
+ return offset = 305;
+ }
+
+ virtual unsigned int offset306(int) {
+ return offset = 306;
+ }
+
+ virtual unsigned int offset307(int) {
+ return offset = 307;
+ }
+
+ virtual unsigned int offset308(int) {
+ return offset = 308;
+ }
+
+ virtual unsigned int offset309(int) {
+ return offset = 309;
+ }
+
+ virtual unsigned int offset310(int) {
+ return offset = 310;
+ }
+
+ virtual unsigned int offset311(int) {
+ return offset = 311;
+ }
+
+ virtual unsigned int offset312(int) {
+ return offset = 312;
+ }
+
+ virtual unsigned int offset313(int) {
+ return offset = 313;
+ }
+
+ virtual unsigned int offset314(int) {
+ return offset = 314;
+ }
+
+ virtual unsigned int offset315(int) {
+ return offset = 315;
+ }
+
+ virtual unsigned int offset316(int) {
+ return offset = 316;
+ }
+
+ virtual unsigned int offset317(int) {
+ return offset = 317;
+ }
+
+ virtual unsigned int offset318(int) {
+ return offset = 318;
+ }
+
+ virtual unsigned int offset319(int) {
+ return offset = 319;
+ }
+
+ virtual unsigned int offset320(int) {
+ return offset = 320;
+ }
+
+ virtual unsigned int offset321(int) {
+ return offset = 321;
+ }
+
+ virtual unsigned int offset322(int) {
+ return offset = 322;
+ }
+
+ virtual unsigned int offset323(int) {
+ return offset = 323;
+ }
+
+ virtual unsigned int offset324(int) {
+ return offset = 324;
+ }
+
+ virtual unsigned int offset325(int) {
+ return offset = 325;
+ }
+
+ virtual unsigned int offset326(int) {
+ return offset = 326;
+ }
+
+ virtual unsigned int offset327(int) {
+ return offset = 327;
+ }
+
+ virtual unsigned int offset328(int) {
+ return offset = 328;
+ }
+
+ virtual unsigned int offset329(int) {
+ return offset = 329;
+ }
+
+ virtual unsigned int offset330(int) {
+ return offset = 330;
+ }
+
+ virtual unsigned int offset331(int) {
+ return offset = 331;
+ }
+
+ virtual unsigned int offset332(int) {
+ return offset = 332;
+ }
+
+ virtual unsigned int offset333(int) {
+ return offset = 333;
+ }
+
+ virtual unsigned int offset334(int) {
+ return offset = 334;
+ }
+
+ virtual unsigned int offset335(int) {
+ return offset = 335;
+ }
+
+ virtual unsigned int offset336(int) {
+ return offset = 336;
+ }
+
+ virtual unsigned int offset337(int) {
+ return offset = 337;
+ }
+
+ virtual unsigned int offset338(int) {
+ return offset = 338;
+ }
+
+ virtual unsigned int offset339(int) {
+ return offset = 339;
+ }
+
+ virtual unsigned int offset340(int) {
+ return offset = 340;
+ }
+
+ virtual unsigned int offset341(int) {
+ return offset = 341;
+ }
+
+ virtual unsigned int offset342(int) {
+ return offset = 342;
+ }
+
+ virtual unsigned int offset343(int) {
+ return offset = 343;
+ }
+
+ virtual unsigned int offset344(int) {
+ return offset = 344;
+ }
+
+ virtual unsigned int offset345(int) {
+ return offset = 345;
+ }
+
+ virtual unsigned int offset346(int) {
+ return offset = 346;
+ }
+
+ virtual unsigned int offset347(int) {
+ return offset = 347;
+ }
+
+ virtual unsigned int offset348(int) {
+ return offset = 348;
+ }
+
+ virtual unsigned int offset349(int) {
+ return offset = 349;
+ }
+
+ virtual unsigned int offset350(int) {
+ return offset = 350;
+ }
+
+ virtual unsigned int offset351(int) {
+ return offset = 351;
+ }
+
+ virtual unsigned int offset352(int) {
+ return offset = 352;
+ }
+
+ virtual unsigned int offset353(int) {
+ return offset = 353;
+ }
+
+ virtual unsigned int offset354(int) {
+ return offset = 354;
+ }
+
+ virtual unsigned int offset355(int) {
+ return offset = 355;
+ }
+
+ virtual unsigned int offset356(int) {
+ return offset = 356;
+ }
+
+ virtual unsigned int offset357(int) {
+ return offset = 357;
+ }
+
+ virtual unsigned int offset358(int) {
+ return offset = 358;
+ }
+
+ virtual unsigned int offset359(int) {
+ return offset = 359;
+ }
+
+ virtual unsigned int offset360(int) {
+ return offset = 360;
+ }
+
+ virtual unsigned int offset361(int) {
+ return offset = 361;
+ }
+
+ virtual unsigned int offset362(int) {
+ return offset = 362;
+ }
+
+ virtual unsigned int offset363(int) {
+ return offset = 363;
+ }
+
+ virtual unsigned int offset364(int) {
+ return offset = 364;
+ }
+
+ virtual unsigned int offset365(int) {
+ return offset = 365;
+ }
+
+ virtual unsigned int offset366(int) {
+ return offset = 366;
+ }
+
+ virtual unsigned int offset367(int) {
+ return offset = 367;
+ }
+
+ virtual unsigned int offset368(int) {
+ return offset = 368;
+ }
+
+ virtual unsigned int offset369(int) {
+ return offset = 369;
+ }
+
+ virtual unsigned int offset370(int) {
+ return offset = 370;
+ }
+
+ virtual unsigned int offset371(int) {
+ return offset = 371;
+ }
+
+ virtual unsigned int offset372(int) {
+ return offset = 372;
+ }
+
+ virtual unsigned int offset373(int) {
+ return offset = 373;
+ }
+
+ virtual unsigned int offset374(int) {
+ return offset = 374;
+ }
+
+ virtual unsigned int offset375(int) {
+ return offset = 375;
+ }
+
+ virtual unsigned int offset376(int) {
+ return offset = 376;
+ }
+
+ virtual unsigned int offset377(int) {
+ return offset = 377;
+ }
+
+ virtual unsigned int offset378(int) {
+ return offset = 378;
+ }
+
+ virtual unsigned int offset379(int) {
+ return offset = 379;
+ }
+
+ virtual unsigned int offset380(int) {
+ return offset = 380;
+ }
+
+ virtual unsigned int offset381(int) {
+ return offset = 381;
+ }
+
+ virtual unsigned int offset382(int) {
+ return offset = 382;
+ }
+
+ virtual unsigned int offset383(int) {
+ return offset = 383;
+ }
+
+ virtual unsigned int offset384(int) {
+ return offset = 384;
+ }
+
+ virtual unsigned int offset385(int) {
+ return offset = 385;
+ }
+
+ virtual unsigned int offset386(int) {
+ return offset = 386;
+ }
+
+ virtual unsigned int offset387(int) {
+ return offset = 387;
+ }
+
+ virtual unsigned int offset388(int) {
+ return offset = 388;
+ }
+
+ virtual unsigned int offset389(int) {
+ return offset = 389;
+ }
+
+ virtual unsigned int offset390(int) {
+ return offset = 390;
+ }
+
+ virtual unsigned int offset391(int) {
+ return offset = 391;
+ }
+
+ virtual unsigned int offset392(int) {
+ return offset = 392;
+ }
+
+ virtual unsigned int offset393(int) {
+ return offset = 393;
+ }
+
+ virtual unsigned int offset394(int) {
+ return offset = 394;
+ }
+
+ virtual unsigned int offset395(int) {
+ return offset = 395;
+ }
+
+ virtual unsigned int offset396(int) {
+ return offset = 396;
+ }
+
+ virtual unsigned int offset397(int) {
+ return offset = 397;
+ }
+
+ virtual unsigned int offset398(int) {
+ return offset = 398;
+ }
+
+ virtual unsigned int offset399(int) {
+ return offset = 399;
+ }
+
+
+ virtual unsigned int offset400(int) {
+ return offset = 400;
+ }
+
+ virtual unsigned int offset401(int) {
+ return offset = 401;
+ }
+
+ virtual unsigned int offset402(int) {
+ return offset = 402;
+ }
+
+ virtual unsigned int offset403(int) {
+ return offset = 403;
+ }
+
+ virtual unsigned int offset404(int) {
+ return offset = 404;
+ }
+
+ virtual unsigned int offset405(int) {
+ return offset = 405;
+ }
+
+ virtual unsigned int offset406(int) {
+ return offset = 406;
+ }
+
+ virtual unsigned int offset407(int) {
+ return offset = 407;
+ }
+
+ virtual unsigned int offset408(int) {
+ return offset = 408;
+ }
+
+ virtual unsigned int offset409(int) {
+ return offset = 409;
+ }
+
+ virtual unsigned int offset410(int) {
+ return offset = 410;
+ }
+
+ virtual unsigned int offset411(int) {
+ return offset = 411;
+ }
+
+ virtual unsigned int offset412(int) {
+ return offset = 412;
+ }
+
+ virtual unsigned int offset413(int) {
+ return offset = 413;
+ }
+
+ virtual unsigned int offset414(int) {
+ return offset = 414;
+ }
+
+ virtual unsigned int offset415(int) {
+ return offset = 415;
+ }
+
+ virtual unsigned int offset416(int) {
+ return offset = 416;
+ }
+
+ virtual unsigned int offset417(int) {
+ return offset = 417;
+ }
+
+ virtual unsigned int offset418(int) {
+ return offset = 418;
+ }
+
+ virtual unsigned int offset419(int) {
+ return offset = 419;
+ }
+
+ virtual unsigned int offset420(int) {
+ return offset = 420;
+ }
+
+ virtual unsigned int offset421(int) {
+ return offset = 421;
+ }
+
+ virtual unsigned int offset422(int) {
+ return offset = 422;
+ }
+
+ virtual unsigned int offset423(int) {
+ return offset = 423;
+ }
+
+ virtual unsigned int offset424(int) {
+ return offset = 424;
+ }
+
+ virtual unsigned int offset425(int) {
+ return offset = 425;
+ }
+
+ virtual unsigned int offset426(int) {
+ return offset = 426;
+ }
+
+ virtual unsigned int offset427(int) {
+ return offset = 427;
+ }
+
+ virtual unsigned int offset428(int) {
+ return offset = 428;
+ }
+
+ virtual unsigned int offset429(int) {
+ return offset = 429;
+ }
+
+ virtual unsigned int offset430(int) {
+ return offset = 430;
+ }
+
+ virtual unsigned int offset431(int) {
+ return offset = 431;
+ }
+
+ virtual unsigned int offset432(int) {
+ return offset = 432;
+ }
+
+ virtual unsigned int offset433(int) {
+ return offset = 433;
+ }
+
+ virtual unsigned int offset434(int) {
+ return offset = 434;
+ }
+
+ virtual unsigned int offset435(int) {
+ return offset = 435;
+ }
+
+ virtual unsigned int offset436(int) {
+ return offset = 436;
+ }
+
+ virtual unsigned int offset437(int) {
+ return offset = 437;
+ }
+
+ virtual unsigned int offset438(int) {
+ return offset = 438;
+ }
+
+ virtual unsigned int offset439(int) {
+ return offset = 439;
+ }
+
+ virtual unsigned int offset440(int) {
+ return offset = 440;
+ }
+
+ virtual unsigned int offset441(int) {
+ return offset = 441;
+ }
+
+ virtual unsigned int offset442(int) {
+ return offset = 442;
+ }
+
+ virtual unsigned int offset443(int) {
+ return offset = 443;
+ }
+
+ virtual unsigned int offset444(int) {
+ return offset = 444;
+ }
+
+ virtual unsigned int offset445(int) {
+ return offset = 445;
+ }
+
+ virtual unsigned int offset446(int) {
+ return offset = 446;
+ }
+
+ virtual unsigned int offset447(int) {
+ return offset = 447;
+ }
+
+ virtual unsigned int offset448(int) {
+ return offset = 448;
+ }
+
+ virtual unsigned int offset449(int) {
+ return offset = 449;
+ }
+
+ virtual unsigned int offset450(int) {
+ return offset = 450;
+ }
+
+ virtual unsigned int offset451(int) {
+ return offset = 451;
+ }
+
+ virtual unsigned int offset452(int) {
+ return offset = 452;
+ }
+
+ virtual unsigned int offset453(int) {
+ return offset = 453;
+ }
+
+ virtual unsigned int offset454(int) {
+ return offset = 454;
+ }
+
+ virtual unsigned int offset455(int) {
+ return offset = 455;
+ }
+
+ virtual unsigned int offset456(int) {
+ return offset = 456;
+ }
+
+ virtual unsigned int offset457(int) {
+ return offset = 457;
+ }
+
+ virtual unsigned int offset458(int) {
+ return offset = 458;
+ }
+
+ virtual unsigned int offset459(int) {
+ return offset = 459;
+ }
+
+ virtual unsigned int offset460(int) {
+ return offset = 460;
+ }
+
+ virtual unsigned int offset461(int) {
+ return offset = 461;
+ }
+
+ virtual unsigned int offset462(int) {
+ return offset = 462;
+ }
+
+ virtual unsigned int offset463(int) {
+ return offset = 463;
+ }
+
+ virtual unsigned int offset464(int) {
+ return offset = 464;
+ }
+
+ virtual unsigned int offset465(int) {
+ return offset = 465;
+ }
+
+ virtual unsigned int offset466(int) {
+ return offset = 466;
+ }
+
+ virtual unsigned int offset467(int) {
+ return offset = 467;
+ }
+
+ virtual unsigned int offset468(int) {
+ return offset = 468;
+ }
+
+ virtual unsigned int offset469(int) {
+ return offset = 469;
+ }
+
+ virtual unsigned int offset470(int) {
+ return offset = 470;
+ }
+
+ virtual unsigned int offset471(int) {
+ return offset = 471;
+ }
+
+ virtual unsigned int offset472(int) {
+ return offset = 472;
+ }
+
+ virtual unsigned int offset473(int) {
+ return offset = 473;
+ }
+
+ virtual unsigned int offset474(int) {
+ return offset = 474;
+ }
+
+ virtual unsigned int offset475(int) {
+ return offset = 475;
+ }
+
+ virtual unsigned int offset476(int) {
+ return offset = 476;
+ }
+
+ virtual unsigned int offset477(int) {
+ return offset = 477;
+ }
+
+ virtual unsigned int offset478(int) {
+ return offset = 478;
+ }
+
+ virtual unsigned int offset479(int) {
+ return offset = 479;
+ }
+
+ virtual unsigned int offset480(int) {
+ return offset = 480;
+ }
+
+ virtual unsigned int offset481(int) {
+ return offset = 481;
+ }
+
+ virtual unsigned int offset482(int) {
+ return offset = 482;
+ }
+
+ virtual unsigned int offset483(int) {
+ return offset = 483;
+ }
+
+ virtual unsigned int offset484(int) {
+ return offset = 484;
+ }
+
+ virtual unsigned int offset485(int) {
+ return offset = 485;
+ }
+
+ virtual unsigned int offset486(int) {
+ return offset = 486;
+ }
+
+ virtual unsigned int offset487(int) {
+ return offset = 487;
+ }
+
+ virtual unsigned int offset488(int) {
+ return offset = 488;
+ }
+
+ virtual unsigned int offset489(int) {
+ return offset = 489;
+ }
+
+ virtual unsigned int offset490(int) {
+ return offset = 490;
+ }
+
+ virtual unsigned int offset491(int) {
+ return offset = 491;
+ }
+
+ virtual unsigned int offset492(int) {
+ return offset = 492;
+ }
+
+ virtual unsigned int offset493(int) {
+ return offset = 493;
+ }
+
+ virtual unsigned int offset494(int) {
+ return offset = 494;
+ }
+
+ virtual unsigned int offset495(int) {
+ return offset = 495;
+ }
+
+ virtual unsigned int offset496(int) {
+ return offset = 496;
+ }
+
+ virtual unsigned int offset497(int) {
+ return offset = 497;
+ }
+
+ virtual unsigned int offset498(int) {
+ return offset = 498;
+ }
+
+ virtual unsigned int offset499(int) {
+ return offset = 499;
+ }
+
+
+ virtual unsigned int offset500(int) {
+ return offset = 500;
+ }
+
+ virtual unsigned int offset501(int) {
+ return offset = 501;
+ }
+
+ virtual unsigned int offset502(int) {
+ return offset = 502;
+ }
+
+ virtual unsigned int offset503(int) {
+ return offset = 503;
+ }
+
+ virtual unsigned int offset504(int) {
+ return offset = 504;
+ }
+
+ virtual unsigned int offset505(int) {
+ return offset = 505;
+ }
+
+ virtual unsigned int offset506(int) {
+ return offset = 506;
+ }
+
+ virtual unsigned int offset507(int) {
+ return offset = 507;
+ }
+
+ virtual unsigned int offset508(int) {
+ return offset = 508;
+ }
+
+ virtual unsigned int offset509(int) {
+ return offset = 509;
+ }
+
+ virtual unsigned int offset510(int) {
+ return offset = 510;
+ }
+
+ virtual unsigned int offset511(int) {
+ return offset = 511;
+ }
+
+ virtual unsigned int offset512(int) {
+ return offset = 512;
+ }
+
+ virtual unsigned int offset513(int) {
+ return offset = 513;
+ }
+
+ virtual unsigned int offset514(int) {
+ return offset = 514;
+ }
+
+ virtual unsigned int offset515(int) {
+ return offset = 515;
+ }
+
+ virtual unsigned int offset516(int) {
+ return offset = 516;
+ }
+
+ virtual unsigned int offset517(int) {
+ return offset = 517;
+ }
+
+ virtual unsigned int offset518(int) {
+ return offset = 518;
+ }
+
+ virtual unsigned int offset519(int) {
+ return offset = 519;
+ }
+
+ virtual unsigned int offset520(int) {
+ return offset = 520;
+ }
+
+ virtual unsigned int offset521(int) {
+ return offset = 521;
+ }
+
+ virtual unsigned int offset522(int) {
+ return offset = 522;
+ }
+
+ virtual unsigned int offset523(int) {
+ return offset = 523;
+ }
+
+ virtual unsigned int offset524(int) {
+ return offset = 524;
+ }
+
+ virtual unsigned int offset525(int) {
+ return offset = 525;
+ }
+
+ virtual unsigned int offset526(int) {
+ return offset = 526;
+ }
+
+ virtual unsigned int offset527(int) {
+ return offset = 527;
+ }
+
+ virtual unsigned int offset528(int) {
+ return offset = 528;
+ }
+
+ virtual unsigned int offset529(int) {
+ return offset = 529;
+ }
+
+ virtual unsigned int offset530(int) {
+ return offset = 530;
+ }
+
+ virtual unsigned int offset531(int) {
+ return offset = 531;
+ }
+
+ virtual unsigned int offset532(int) {
+ return offset = 532;
+ }
+
+ virtual unsigned int offset533(int) {
+ return offset = 533;
+ }
+
+ virtual unsigned int offset534(int) {
+ return offset = 534;
+ }
+
+ virtual unsigned int offset535(int) {
+ return offset = 535;
+ }
+
+ virtual unsigned int offset536(int) {
+ return offset = 536;
+ }
+
+ virtual unsigned int offset537(int) {
+ return offset = 537;
+ }
+
+ virtual unsigned int offset538(int) {
+ return offset = 538;
+ }
+
+ virtual unsigned int offset539(int) {
+ return offset = 539;
+ }
+
+ virtual unsigned int offset540(int) {
+ return offset = 540;
+ }
+
+ virtual unsigned int offset541(int) {
+ return offset = 541;
+ }
+
+ virtual unsigned int offset542(int) {
+ return offset = 542;
+ }
+
+ virtual unsigned int offset543(int) {
+ return offset = 543;
+ }
+
+ virtual unsigned int offset544(int) {
+ return offset = 544;
+ }
+
+ virtual unsigned int offset545(int) {
+ return offset = 545;
+ }
+
+ virtual unsigned int offset546(int) {
+ return offset = 546;
+ }
+
+ virtual unsigned int offset547(int) {
+ return offset = 547;
+ }
+
+ virtual unsigned int offset548(int) {
+ return offset = 548;
+ }
+
+ virtual unsigned int offset549(int) {
+ return offset = 549;
+ }
+
+ virtual unsigned int offset550(int) {
+ return offset = 550;
+ }
+
+ virtual unsigned int offset551(int) {
+ return offset = 551;
+ }
+
+ virtual unsigned int offset552(int) {
+ return offset = 552;
+ }
+
+ virtual unsigned int offset553(int) {
+ return offset = 553;
+ }
+
+ virtual unsigned int offset554(int) {
+ return offset = 554;
+ }
+
+ virtual unsigned int offset555(int) {
+ return offset = 555;
+ }
+
+ virtual unsigned int offset556(int) {
+ return offset = 556;
+ }
+
+ virtual unsigned int offset557(int) {
+ return offset = 557;
+ }
+
+ virtual unsigned int offset558(int) {
+ return offset = 558;
+ }
+
+ virtual unsigned int offset559(int) {
+ return offset = 559;
+ }
+
+ virtual unsigned int offset560(int) {
+ return offset = 560;
+ }
+
+ virtual unsigned int offset561(int) {
+ return offset = 561;
+ }
+
+ virtual unsigned int offset562(int) {
+ return offset = 562;
+ }
+
+ virtual unsigned int offset563(int) {
+ return offset = 563;
+ }
+
+ virtual unsigned int offset564(int) {
+ return offset = 564;
+ }
+
+ virtual unsigned int offset565(int) {
+ return offset = 565;
+ }
+
+ virtual unsigned int offset566(int) {
+ return offset = 566;
+ }
+
+ virtual unsigned int offset567(int) {
+ return offset = 567;
+ }
+
+ virtual unsigned int offset568(int) {
+ return offset = 568;
+ }
+
+ virtual unsigned int offset569(int) {
+ return offset = 569;
+ }
+
+ virtual unsigned int offset570(int) {
+ return offset = 570;
+ }
+
+ virtual unsigned int offset571(int) {
+ return offset = 571;
+ }
+
+ virtual unsigned int offset572(int) {
+ return offset = 572;
+ }
+
+ virtual unsigned int offset573(int) {
+ return offset = 573;
+ }
+
+ virtual unsigned int offset574(int) {
+ return offset = 574;
+ }
+
+ virtual unsigned int offset575(int) {
+ return offset = 575;
+ }
+
+ virtual unsigned int offset576(int) {
+ return offset = 576;
+ }
+
+ virtual unsigned int offset577(int) {
+ return offset = 577;
+ }
+
+ virtual unsigned int offset578(int) {
+ return offset = 578;
+ }
+
+ virtual unsigned int offset579(int) {
+ return offset = 579;
+ }
+
+ virtual unsigned int offset580(int) {
+ return offset = 580;
+ }
+
+ virtual unsigned int offset581(int) {
+ return offset = 581;
+ }
+
+ virtual unsigned int offset582(int) {
+ return offset = 582;
+ }
+
+ virtual unsigned int offset583(int) {
+ return offset = 583;
+ }
+
+ virtual unsigned int offset584(int) {
+ return offset = 584;
+ }
+
+ virtual unsigned int offset585(int) {
+ return offset = 585;
+ }
+
+ virtual unsigned int offset586(int) {
+ return offset = 586;
+ }
+
+ virtual unsigned int offset587(int) {
+ return offset = 587;
+ }
+
+ virtual unsigned int offset588(int) {
+ return offset = 588;
+ }
+
+ virtual unsigned int offset589(int) {
+ return offset = 589;
+ }
+
+ virtual unsigned int offset590(int) {
+ return offset = 590;
+ }
+
+ virtual unsigned int offset591(int) {
+ return offset = 591;
+ }
+
+ virtual unsigned int offset592(int) {
+ return offset = 592;
+ }
+
+ virtual unsigned int offset593(int) {
+ return offset = 593;
+ }
+
+ virtual unsigned int offset594(int) {
+ return offset = 594;
+ }
+
+ virtual unsigned int offset595(int) {
+ return offset = 595;
+ }
+
+ virtual unsigned int offset596(int) {
+ return offset = 596;
+ }
+
+ virtual unsigned int offset597(int) {
+ return offset = 597;
+ }
+
+ virtual unsigned int offset598(int) {
+ return offset = 598;
+ }
+
+ virtual unsigned int offset599(int) {
+ return offset = 599;
+ }
+
+
+ virtual unsigned int offset600(int) {
+ return offset = 600;
+ }
+
+ virtual unsigned int offset601(int) {
+ return offset = 601;
+ }
+
+ virtual unsigned int offset602(int) {
+ return offset = 602;
+ }
+
+ virtual unsigned int offset603(int) {
+ return offset = 603;
+ }
+
+ virtual unsigned int offset604(int) {
+ return offset = 604;
+ }
+
+ virtual unsigned int offset605(int) {
+ return offset = 605;
+ }
+
+ virtual unsigned int offset606(int) {
+ return offset = 606;
+ }
+
+ virtual unsigned int offset607(int) {
+ return offset = 607;
+ }
+
+ virtual unsigned int offset608(int) {
+ return offset = 608;
+ }
+
+ virtual unsigned int offset609(int) {
+ return offset = 609;
+ }
+
+ virtual unsigned int offset610(int) {
+ return offset = 610;
+ }
+
+ virtual unsigned int offset611(int) {
+ return offset = 611;
+ }
+
+ virtual unsigned int offset612(int) {
+ return offset = 612;
+ }
+
+ virtual unsigned int offset613(int) {
+ return offset = 613;
+ }
+
+ virtual unsigned int offset614(int) {
+ return offset = 614;
+ }
+
+ virtual unsigned int offset615(int) {
+ return offset = 615;
+ }
+
+ virtual unsigned int offset616(int) {
+ return offset = 616;
+ }
+
+ virtual unsigned int offset617(int) {
+ return offset = 617;
+ }
+
+ virtual unsigned int offset618(int) {
+ return offset = 618;
+ }
+
+ virtual unsigned int offset619(int) {
+ return offset = 619;
+ }
+
+ virtual unsigned int offset620(int) {
+ return offset = 620;
+ }
+
+ virtual unsigned int offset621(int) {
+ return offset = 621;
+ }
+
+ virtual unsigned int offset622(int) {
+ return offset = 622;
+ }
+
+ virtual unsigned int offset623(int) {
+ return offset = 623;
+ }
+
+ virtual unsigned int offset624(int) {
+ return offset = 624;
+ }
+
+ virtual unsigned int offset625(int) {
+ return offset = 625;
+ }
+
+ virtual unsigned int offset626(int) {
+ return offset = 626;
+ }
+
+ virtual unsigned int offset627(int) {
+ return offset = 627;
+ }
+
+ virtual unsigned int offset628(int) {
+ return offset = 628;
+ }
+
+ virtual unsigned int offset629(int) {
+ return offset = 629;
+ }
+
+ virtual unsigned int offset630(int) {
+ return offset = 630;
+ }
+
+ virtual unsigned int offset631(int) {
+ return offset = 631;
+ }
+
+ virtual unsigned int offset632(int) {
+ return offset = 632;
+ }
+
+ virtual unsigned int offset633(int) {
+ return offset = 633;
+ }
+
+ virtual unsigned int offset634(int) {
+ return offset = 634;
+ }
+
+ virtual unsigned int offset635(int) {
+ return offset = 635;
+ }
+
+ virtual unsigned int offset636(int) {
+ return offset = 636;
+ }
+
+ virtual unsigned int offset637(int) {
+ return offset = 637;
+ }
+
+ virtual unsigned int offset638(int) {
+ return offset = 638;
+ }
+
+ virtual unsigned int offset639(int) {
+ return offset = 639;
+ }
+
+ virtual unsigned int offset640(int) {
+ return offset = 640;
+ }
+
+ virtual unsigned int offset641(int) {
+ return offset = 641;
+ }
+
+ virtual unsigned int offset642(int) {
+ return offset = 642;
+ }
+
+ virtual unsigned int offset643(int) {
+ return offset = 643;
+ }
+
+ virtual unsigned int offset644(int) {
+ return offset = 644;
+ }
+
+ virtual unsigned int offset645(int) {
+ return offset = 645;
+ }
+
+ virtual unsigned int offset646(int) {
+ return offset = 646;
+ }
+
+ virtual unsigned int offset647(int) {
+ return offset = 647;
+ }
+
+ virtual unsigned int offset648(int) {
+ return offset = 648;
+ }
+
+ virtual unsigned int offset649(int) {
+ return offset = 649;
+ }
+
+ virtual unsigned int offset650(int) {
+ return offset = 650;
+ }
+
+ virtual unsigned int offset651(int) {
+ return offset = 651;
+ }
+
+ virtual unsigned int offset652(int) {
+ return offset = 652;
+ }
+
+ virtual unsigned int offset653(int) {
+ return offset = 653;
+ }
+
+ virtual unsigned int offset654(int) {
+ return offset = 654;
+ }
+
+ virtual unsigned int offset655(int) {
+ return offset = 655;
+ }
+
+ virtual unsigned int offset656(int) {
+ return offset = 656;
+ }
+
+ virtual unsigned int offset657(int) {
+ return offset = 657;
+ }
+
+ virtual unsigned int offset658(int) {
+ return offset = 658;
+ }
+
+ virtual unsigned int offset659(int) {
+ return offset = 659;
+ }
+
+ virtual unsigned int offset660(int) {
+ return offset = 660;
+ }
+
+ virtual unsigned int offset661(int) {
+ return offset = 661;
+ }
+
+ virtual unsigned int offset662(int) {
+ return offset = 662;
+ }
+
+ virtual unsigned int offset663(int) {
+ return offset = 663;
+ }
+
+ virtual unsigned int offset664(int) {
+ return offset = 664;
+ }
+
+ virtual unsigned int offset665(int) {
+ return offset = 665;
+ }
+
+ virtual unsigned int offset666(int) {
+ return offset = 666;
+ }
+
+ virtual unsigned int offset667(int) {
+ return offset = 667;
+ }
+
+ virtual unsigned int offset668(int) {
+ return offset = 668;
+ }
+
+ virtual unsigned int offset669(int) {
+ return offset = 669;
+ }
+
+ virtual unsigned int offset670(int) {
+ return offset = 670;
+ }
+
+ virtual unsigned int offset671(int) {
+ return offset = 671;
+ }
+
+ virtual unsigned int offset672(int) {
+ return offset = 672;
+ }
+
+ virtual unsigned int offset673(int) {
+ return offset = 673;
+ }
+
+ virtual unsigned int offset674(int) {
+ return offset = 674;
+ }
+
+ virtual unsigned int offset675(int) {
+ return offset = 675;
+ }
+
+ virtual unsigned int offset676(int) {
+ return offset = 676;
+ }
+
+ virtual unsigned int offset677(int) {
+ return offset = 677;
+ }
+
+ virtual unsigned int offset678(int) {
+ return offset = 678;
+ }
+
+ virtual unsigned int offset679(int) {
+ return offset = 679;
+ }
+
+ virtual unsigned int offset680(int) {
+ return offset = 680;
+ }
+
+ virtual unsigned int offset681(int) {
+ return offset = 681;
+ }
+
+ virtual unsigned int offset682(int) {
+ return offset = 682;
+ }
+
+ virtual unsigned int offset683(int) {
+ return offset = 683;
+ }
+
+ virtual unsigned int offset684(int) {
+ return offset = 684;
+ }
+
+ virtual unsigned int offset685(int) {
+ return offset = 685;
+ }
+
+ virtual unsigned int offset686(int) {
+ return offset = 686;
+ }
+
+ virtual unsigned int offset687(int) {
+ return offset = 687;
+ }
+
+ virtual unsigned int offset688(int) {
+ return offset = 688;
+ }
+
+ virtual unsigned int offset689(int) {
+ return offset = 689;
+ }
+
+ virtual unsigned int offset690(int) {
+ return offset = 690;
+ }
+
+ virtual unsigned int offset691(int) {
+ return offset = 691;
+ }
+
+ virtual unsigned int offset692(int) {
+ return offset = 692;
+ }
+
+ virtual unsigned int offset693(int) {
+ return offset = 693;
+ }
+
+ virtual unsigned int offset694(int) {
+ return offset = 694;
+ }
+
+ virtual unsigned int offset695(int) {
+ return offset = 695;
+ }
+
+ virtual unsigned int offset696(int) {
+ return offset = 696;
+ }
+
+ virtual unsigned int offset697(int) {
+ return offset = 697;
+ }
+
+ virtual unsigned int offset698(int) {
+ return offset = 698;
+ }
+
+ virtual unsigned int offset699(int) {
+ return offset = 699;
+ }
+
+
+ virtual unsigned int offset700(int) {
+ return offset = 700;
+ }
+
+ virtual unsigned int offset701(int) {
+ return offset = 701;
+ }
+
+ virtual unsigned int offset702(int) {
+ return offset = 702;
+ }
+
+ virtual unsigned int offset703(int) {
+ return offset = 703;
+ }
+
+ virtual unsigned int offset704(int) {
+ return offset = 704;
+ }
+
+ virtual unsigned int offset705(int) {
+ return offset = 705;
+ }
+
+ virtual unsigned int offset706(int) {
+ return offset = 706;
+ }
+
+ virtual unsigned int offset707(int) {
+ return offset = 707;
+ }
+
+ virtual unsigned int offset708(int) {
+ return offset = 708;
+ }
+
+ virtual unsigned int offset709(int) {
+ return offset = 709;
+ }
+
+ virtual unsigned int offset710(int) {
+ return offset = 710;
+ }
+
+ virtual unsigned int offset711(int) {
+ return offset = 711;
+ }
+
+ virtual unsigned int offset712(int) {
+ return offset = 712;
+ }
+
+ virtual unsigned int offset713(int) {
+ return offset = 713;
+ }
+
+ virtual unsigned int offset714(int) {
+ return offset = 714;
+ }
+
+ virtual unsigned int offset715(int) {
+ return offset = 715;
+ }
+
+ virtual unsigned int offset716(int) {
+ return offset = 716;
+ }
+
+ virtual unsigned int offset717(int) {
+ return offset = 717;
+ }
+
+ virtual unsigned int offset718(int) {
+ return offset = 718;
+ }
+
+ virtual unsigned int offset719(int) {
+ return offset = 719;
+ }
+
+ virtual unsigned int offset720(int) {
+ return offset = 720;
+ }
+
+ virtual unsigned int offset721(int) {
+ return offset = 721;
+ }
+
+ virtual unsigned int offset722(int) {
+ return offset = 722;
+ }
+
+ virtual unsigned int offset723(int) {
+ return offset = 723;
+ }
+
+ virtual unsigned int offset724(int) {
+ return offset = 724;
+ }
+
+ virtual unsigned int offset725(int) {
+ return offset = 725;
+ }
+
+ virtual unsigned int offset726(int) {
+ return offset = 726;
+ }
+
+ virtual unsigned int offset727(int) {
+ return offset = 727;
+ }
+
+ virtual unsigned int offset728(int) {
+ return offset = 728;
+ }
+
+ virtual unsigned int offset729(int) {
+ return offset = 729;
+ }
+
+ virtual unsigned int offset730(int) {
+ return offset = 730;
+ }
+
+ virtual unsigned int offset731(int) {
+ return offset = 731;
+ }
+
+ virtual unsigned int offset732(int) {
+ return offset = 732;
+ }
+
+ virtual unsigned int offset733(int) {
+ return offset = 733;
+ }
+
+ virtual unsigned int offset734(int) {
+ return offset = 734;
+ }
+
+ virtual unsigned int offset735(int) {
+ return offset = 735;
+ }
+
+ virtual unsigned int offset736(int) {
+ return offset = 736;
+ }
+
+ virtual unsigned int offset737(int) {
+ return offset = 737;
+ }
+
+ virtual unsigned int offset738(int) {
+ return offset = 738;
+ }
+
+ virtual unsigned int offset739(int) {
+ return offset = 739;
+ }
+
+ virtual unsigned int offset740(int) {
+ return offset = 740;
+ }
+
+ virtual unsigned int offset741(int) {
+ return offset = 741;
+ }
+
+ virtual unsigned int offset742(int) {
+ return offset = 742;
+ }
+
+ virtual unsigned int offset743(int) {
+ return offset = 743;
+ }
+
+ virtual unsigned int offset744(int) {
+ return offset = 744;
+ }
+
+ virtual unsigned int offset745(int) {
+ return offset = 745;
+ }
+
+ virtual unsigned int offset746(int) {
+ return offset = 746;
+ }
+
+ virtual unsigned int offset747(int) {
+ return offset = 747;
+ }
+
+ virtual unsigned int offset748(int) {
+ return offset = 748;
+ }
+
+ virtual unsigned int offset749(int) {
+ return offset = 749;
+ }
+
+ virtual unsigned int offset750(int) {
+ return offset = 750;
+ }
+
+ virtual unsigned int offset751(int) {
+ return offset = 751;
+ }
+
+ virtual unsigned int offset752(int) {
+ return offset = 752;
+ }
+
+ virtual unsigned int offset753(int) {
+ return offset = 753;
+ }
+
+ virtual unsigned int offset754(int) {
+ return offset = 754;
+ }
+
+ virtual unsigned int offset755(int) {
+ return offset = 755;
+ }
+
+ virtual unsigned int offset756(int) {
+ return offset = 756;
+ }
+
+ virtual unsigned int offset757(int) {
+ return offset = 757;
+ }
+
+ virtual unsigned int offset758(int) {
+ return offset = 758;
+ }
+
+ virtual unsigned int offset759(int) {
+ return offset = 759;
+ }
+
+ virtual unsigned int offset760(int) {
+ return offset = 760;
+ }
+
+ virtual unsigned int offset761(int) {
+ return offset = 761;
+ }
+
+ virtual unsigned int offset762(int) {
+ return offset = 762;
+ }
+
+ virtual unsigned int offset763(int) {
+ return offset = 763;
+ }
+
+ virtual unsigned int offset764(int) {
+ return offset = 764;
+ }
+
+ virtual unsigned int offset765(int) {
+ return offset = 765;
+ }
+
+ virtual unsigned int offset766(int) {
+ return offset = 766;
+ }
+
+ virtual unsigned int offset767(int) {
+ return offset = 767;
+ }
+
+ virtual unsigned int offset768(int) {
+ return offset = 768;
+ }
+
+ virtual unsigned int offset769(int) {
+ return offset = 769;
+ }
+
+ virtual unsigned int offset770(int) {
+ return offset = 770;
+ }
+
+ virtual unsigned int offset771(int) {
+ return offset = 771;
+ }
+
+ virtual unsigned int offset772(int) {
+ return offset = 772;
+ }
+
+ virtual unsigned int offset773(int) {
+ return offset = 773;
+ }
+
+ virtual unsigned int offset774(int) {
+ return offset = 774;
+ }
+
+ virtual unsigned int offset775(int) {
+ return offset = 775;
+ }
+
+ virtual unsigned int offset776(int) {
+ return offset = 776;
+ }
+
+ virtual unsigned int offset777(int) {
+ return offset = 777;
+ }
+
+ virtual unsigned int offset778(int) {
+ return offset = 778;
+ }
+
+ virtual unsigned int offset779(int) {
+ return offset = 779;
+ }
+
+ virtual unsigned int offset780(int) {
+ return offset = 780;
+ }
+
+ virtual unsigned int offset781(int) {
+ return offset = 781;
+ }
+
+ virtual unsigned int offset782(int) {
+ return offset = 782;
+ }
+
+ virtual unsigned int offset783(int) {
+ return offset = 783;
+ }
+
+ virtual unsigned int offset784(int) {
+ return offset = 784;
+ }
+
+ virtual unsigned int offset785(int) {
+ return offset = 785;
+ }
+
+ virtual unsigned int offset786(int) {
+ return offset = 786;
+ }
+
+ virtual unsigned int offset787(int) {
+ return offset = 787;
+ }
+
+ virtual unsigned int offset788(int) {
+ return offset = 788;
+ }
+
+ virtual unsigned int offset789(int) {
+ return offset = 789;
+ }
+
+ virtual unsigned int offset790(int) {
+ return offset = 790;
+ }
+
+ virtual unsigned int offset791(int) {
+ return offset = 791;
+ }
+
+ virtual unsigned int offset792(int) {
+ return offset = 792;
+ }
+
+ virtual unsigned int offset793(int) {
+ return offset = 793;
+ }
+
+ virtual unsigned int offset794(int) {
+ return offset = 794;
+ }
+
+ virtual unsigned int offset795(int) {
+ return offset = 795;
+ }
+
+ virtual unsigned int offset796(int) {
+ return offset = 796;
+ }
+
+ virtual unsigned int offset797(int) {
+ return offset = 797;
+ }
+
+ virtual unsigned int offset798(int) {
+ return offset = 798;
+ }
+
+ virtual unsigned int offset799(int) {
+ return offset = 799;
+ }
+
+
+ virtual unsigned int offset800(int) {
+ return offset = 800;
+ }
+
+ virtual unsigned int offset801(int) {
+ return offset = 801;
+ }
+
+ virtual unsigned int offset802(int) {
+ return offset = 802;
+ }
+
+ virtual unsigned int offset803(int) {
+ return offset = 803;
+ }
+
+ virtual unsigned int offset804(int) {
+ return offset = 804;
+ }
+
+ virtual unsigned int offset805(int) {
+ return offset = 805;
+ }
+
+ virtual unsigned int offset806(int) {
+ return offset = 806;
+ }
+
+ virtual unsigned int offset807(int) {
+ return offset = 807;
+ }
+
+ virtual unsigned int offset808(int) {
+ return offset = 808;
+ }
+
+ virtual unsigned int offset809(int) {
+ return offset = 809;
+ }
+
+ virtual unsigned int offset810(int) {
+ return offset = 810;
+ }
+
+ virtual unsigned int offset811(int) {
+ return offset = 811;
+ }
+
+ virtual unsigned int offset812(int) {
+ return offset = 812;
+ }
+
+ virtual unsigned int offset813(int) {
+ return offset = 813;
+ }
+
+ virtual unsigned int offset814(int) {
+ return offset = 814;
+ }
+
+ virtual unsigned int offset815(int) {
+ return offset = 815;
+ }
+
+ virtual unsigned int offset816(int) {
+ return offset = 816;
+ }
+
+ virtual unsigned int offset817(int) {
+ return offset = 817;
+ }
+
+ virtual unsigned int offset818(int) {
+ return offset = 818;
+ }
+
+ virtual unsigned int offset819(int) {
+ return offset = 819;
+ }
+
+ virtual unsigned int offset820(int) {
+ return offset = 820;
+ }
+
+ virtual unsigned int offset821(int) {
+ return offset = 821;
+ }
+
+ virtual unsigned int offset822(int) {
+ return offset = 822;
+ }
+
+ virtual unsigned int offset823(int) {
+ return offset = 823;
+ }
+
+ virtual unsigned int offset824(int) {
+ return offset = 824;
+ }
+
+ virtual unsigned int offset825(int) {
+ return offset = 825;
+ }
+
+ virtual unsigned int offset826(int) {
+ return offset = 826;
+ }
+
+ virtual unsigned int offset827(int) {
+ return offset = 827;
+ }
+
+ virtual unsigned int offset828(int) {
+ return offset = 828;
+ }
+
+ virtual unsigned int offset829(int) {
+ return offset = 829;
+ }
+
+ virtual unsigned int offset830(int) {
+ return offset = 830;
+ }
+
+ virtual unsigned int offset831(int) {
+ return offset = 831;
+ }
+
+ virtual unsigned int offset832(int) {
+ return offset = 832;
+ }
+
+ virtual unsigned int offset833(int) {
+ return offset = 833;
+ }
+
+ virtual unsigned int offset834(int) {
+ return offset = 834;
+ }
+
+ virtual unsigned int offset835(int) {
+ return offset = 835;
+ }
+
+ virtual unsigned int offset836(int) {
+ return offset = 836;
+ }
+
+ virtual unsigned int offset837(int) {
+ return offset = 837;
+ }
+
+ virtual unsigned int offset838(int) {
+ return offset = 838;
+ }
+
+ virtual unsigned int offset839(int) {
+ return offset = 839;
+ }
+
+ virtual unsigned int offset840(int) {
+ return offset = 840;
+ }
+
+ virtual unsigned int offset841(int) {
+ return offset = 841;
+ }
+
+ virtual unsigned int offset842(int) {
+ return offset = 842;
+ }
+
+ virtual unsigned int offset843(int) {
+ return offset = 843;
+ }
+
+ virtual unsigned int offset844(int) {
+ return offset = 844;
+ }
+
+ virtual unsigned int offset845(int) {
+ return offset = 845;
+ }
+
+ virtual unsigned int offset846(int) {
+ return offset = 846;
+ }
+
+ virtual unsigned int offset847(int) {
+ return offset = 847;
+ }
+
+ virtual unsigned int offset848(int) {
+ return offset = 848;
+ }
+
+ virtual unsigned int offset849(int) {
+ return offset = 849;
+ }
+
+ virtual unsigned int offset850(int) {
+ return offset = 850;
+ }
+
+ virtual unsigned int offset851(int) {
+ return offset = 851;
+ }
+
+ virtual unsigned int offset852(int) {
+ return offset = 852;
+ }
+
+ virtual unsigned int offset853(int) {
+ return offset = 853;
+ }
+
+ virtual unsigned int offset854(int) {
+ return offset = 854;
+ }
+
+ virtual unsigned int offset855(int) {
+ return offset = 855;
+ }
+
+ virtual unsigned int offset856(int) {
+ return offset = 856;
+ }
+
+ virtual unsigned int offset857(int) {
+ return offset = 857;
+ }
+
+ virtual unsigned int offset858(int) {
+ return offset = 858;
+ }
+
+ virtual unsigned int offset859(int) {
+ return offset = 859;
+ }
+
+ virtual unsigned int offset860(int) {
+ return offset = 860;
+ }
+
+ virtual unsigned int offset861(int) {
+ return offset = 861;
+ }
+
+ virtual unsigned int offset862(int) {
+ return offset = 862;
+ }
+
+ virtual unsigned int offset863(int) {
+ return offset = 863;
+ }
+
+ virtual unsigned int offset864(int) {
+ return offset = 864;
+ }
+
+ virtual unsigned int offset865(int) {
+ return offset = 865;
+ }
+
+ virtual unsigned int offset866(int) {
+ return offset = 866;
+ }
+
+ virtual unsigned int offset867(int) {
+ return offset = 867;
+ }
+
+ virtual unsigned int offset868(int) {
+ return offset = 868;
+ }
+
+ virtual unsigned int offset869(int) {
+ return offset = 869;
+ }
+
+ virtual unsigned int offset870(int) {
+ return offset = 870;
+ }
+
+ virtual unsigned int offset871(int) {
+ return offset = 871;
+ }
+
+ virtual unsigned int offset872(int) {
+ return offset = 872;
+ }
+
+ virtual unsigned int offset873(int) {
+ return offset = 873;
+ }
+
+ virtual unsigned int offset874(int) {
+ return offset = 874;
+ }
+
+ virtual unsigned int offset875(int) {
+ return offset = 875;
+ }
+
+ virtual unsigned int offset876(int) {
+ return offset = 876;
+ }
+
+ virtual unsigned int offset877(int) {
+ return offset = 877;
+ }
+
+ virtual unsigned int offset878(int) {
+ return offset = 878;
+ }
+
+ virtual unsigned int offset879(int) {
+ return offset = 879;
+ }
+
+ virtual unsigned int offset880(int) {
+ return offset = 880;
+ }
+
+ virtual unsigned int offset881(int) {
+ return offset = 881;
+ }
+
+ virtual unsigned int offset882(int) {
+ return offset = 882;
+ }
+
+ virtual unsigned int offset883(int) {
+ return offset = 883;
+ }
+
+ virtual unsigned int offset884(int) {
+ return offset = 884;
+ }
+
+ virtual unsigned int offset885(int) {
+ return offset = 885;
+ }
+
+ virtual unsigned int offset886(int) {
+ return offset = 886;
+ }
+
+ virtual unsigned int offset887(int) {
+ return offset = 887;
+ }
+
+ virtual unsigned int offset888(int) {
+ return offset = 888;
+ }
+
+ virtual unsigned int offset889(int) {
+ return offset = 889;
+ }
+
+ virtual unsigned int offset890(int) {
+ return offset = 890;
+ }
+
+ virtual unsigned int offset891(int) {
+ return offset = 891;
+ }
+
+ virtual unsigned int offset892(int) {
+ return offset = 892;
+ }
+
+ virtual unsigned int offset893(int) {
+ return offset = 893;
+ }
+
+ virtual unsigned int offset894(int) {
+ return offset = 894;
+ }
+
+ virtual unsigned int offset895(int) {
+ return offset = 895;
+ }
+
+ virtual unsigned int offset896(int) {
+ return offset = 896;
+ }
+
+ virtual unsigned int offset897(int) {
+ return offset = 897;
+ }
+
+ virtual unsigned int offset898(int) {
+ return offset = 898;
+ }
+
+ virtual unsigned int offset899(int) {
+ return offset = 899;
+ }
+
+
+ virtual unsigned int offset900(int) {
+ return offset = 900;
+ }
+
+ virtual unsigned int offset901(int) {
+ return offset = 901;
+ }
+
+ virtual unsigned int offset902(int) {
+ return offset = 902;
+ }
+
+ virtual unsigned int offset903(int) {
+ return offset = 903;
+ }
+
+ virtual unsigned int offset904(int) {
+ return offset = 904;
+ }
+
+ virtual unsigned int offset905(int) {
+ return offset = 905;
+ }
+
+ virtual unsigned int offset906(int) {
+ return offset = 906;
+ }
+
+ virtual unsigned int offset907(int) {
+ return offset = 907;
+ }
+
+ virtual unsigned int offset908(int) {
+ return offset = 908;
+ }
+
+ virtual unsigned int offset909(int) {
+ return offset = 909;
+ }
+
+ virtual unsigned int offset910(int) {
+ return offset = 910;
+ }
+
+ virtual unsigned int offset911(int) {
+ return offset = 911;
+ }
+
+ virtual unsigned int offset912(int) {
+ return offset = 912;
+ }
+
+ virtual unsigned int offset913(int) {
+ return offset = 913;
+ }
+
+ virtual unsigned int offset914(int) {
+ return offset = 914;
+ }
+
+ virtual unsigned int offset915(int) {
+ return offset = 915;
+ }
+
+ virtual unsigned int offset916(int) {
+ return offset = 916;
+ }
+
+ virtual unsigned int offset917(int) {
+ return offset = 917;
+ }
+
+ virtual unsigned int offset918(int) {
+ return offset = 918;
+ }
+
+ virtual unsigned int offset919(int) {
+ return offset = 919;
+ }
+
+ virtual unsigned int offset920(int) {
+ return offset = 920;
+ }
+
+ virtual unsigned int offset921(int) {
+ return offset = 921;
+ }
+
+ virtual unsigned int offset922(int) {
+ return offset = 922;
+ }
+
+ virtual unsigned int offset923(int) {
+ return offset = 923;
+ }
+
+ virtual unsigned int offset924(int) {
+ return offset = 924;
+ }
+
+ virtual unsigned int offset925(int) {
+ return offset = 925;
+ }
+
+ virtual unsigned int offset926(int) {
+ return offset = 926;
+ }
+
+ virtual unsigned int offset927(int) {
+ return offset = 927;
+ }
+
+ virtual unsigned int offset928(int) {
+ return offset = 928;
+ }
+
+ virtual unsigned int offset929(int) {
+ return offset = 929;
+ }
+
+ virtual unsigned int offset930(int) {
+ return offset = 930;
+ }
+
+ virtual unsigned int offset931(int) {
+ return offset = 931;
+ }
+
+ virtual unsigned int offset932(int) {
+ return offset = 932;
+ }
+
+ virtual unsigned int offset933(int) {
+ return offset = 933;
+ }
+
+ virtual unsigned int offset934(int) {
+ return offset = 934;
+ }
+
+ virtual unsigned int offset935(int) {
+ return offset = 935;
+ }
+
+ virtual unsigned int offset936(int) {
+ return offset = 936;
+ }
+
+ virtual unsigned int offset937(int) {
+ return offset = 937;
+ }
+
+ virtual unsigned int offset938(int) {
+ return offset = 938;
+ }
+
+ virtual unsigned int offset939(int) {
+ return offset = 939;
+ }
+
+ virtual unsigned int offset940(int) {
+ return offset = 940;
+ }
+
+ virtual unsigned int offset941(int) {
+ return offset = 941;
+ }
+
+ virtual unsigned int offset942(int) {
+ return offset = 942;
+ }
+
+ virtual unsigned int offset943(int) {
+ return offset = 943;
+ }
+
+ virtual unsigned int offset944(int) {
+ return offset = 944;
+ }
+
+ virtual unsigned int offset945(int) {
+ return offset = 945;
+ }
+
+ virtual unsigned int offset946(int) {
+ return offset = 946;
+ }
+
+ virtual unsigned int offset947(int) {
+ return offset = 947;
+ }
+
+ virtual unsigned int offset948(int) {
+ return offset = 948;
+ }
+
+ virtual unsigned int offset949(int) {
+ return offset = 949;
+ }
+
+ virtual unsigned int offset950(int) {
+ return offset = 950;
+ }
+
+ virtual unsigned int offset951(int) {
+ return offset = 951;
+ }
+
+ virtual unsigned int offset952(int) {
+ return offset = 952;
+ }
+
+ virtual unsigned int offset953(int) {
+ return offset = 953;
+ }
+
+ virtual unsigned int offset954(int) {
+ return offset = 954;
+ }
+
+ virtual unsigned int offset955(int) {
+ return offset = 955;
+ }
+
+ virtual unsigned int offset956(int) {
+ return offset = 956;
+ }
+
+ virtual unsigned int offset957(int) {
+ return offset = 957;
+ }
+
+ virtual unsigned int offset958(int) {
+ return offset = 958;
+ }
+
+ virtual unsigned int offset959(int) {
+ return offset = 959;
+ }
+
+ virtual unsigned int offset960(int) {
+ return offset = 960;
+ }
+
+ virtual unsigned int offset961(int) {
+ return offset = 961;
+ }
+
+ virtual unsigned int offset962(int) {
+ return offset = 962;
+ }
+
+ virtual unsigned int offset963(int) {
+ return offset = 963;
+ }
+
+ virtual unsigned int offset964(int) {
+ return offset = 964;
+ }
+
+ virtual unsigned int offset965(int) {
+ return offset = 965;
+ }
+
+ virtual unsigned int offset966(int) {
+ return offset = 966;
+ }
+
+ virtual unsigned int offset967(int) {
+ return offset = 967;
+ }
+
+ virtual unsigned int offset968(int) {
+ return offset = 968;
+ }
+
+ virtual unsigned int offset969(int) {
+ return offset = 969;
+ }
+
+ virtual unsigned int offset970(int) {
+ return offset = 970;
+ }
+
+ virtual unsigned int offset971(int) {
+ return offset = 971;
+ }
+
+ virtual unsigned int offset972(int) {
+ return offset = 972;
+ }
+
+ virtual unsigned int offset973(int) {
+ return offset = 973;
+ }
+
+ virtual unsigned int offset974(int) {
+ return offset = 974;
+ }
+
+ virtual unsigned int offset975(int) {
+ return offset = 975;
+ }
+
+ virtual unsigned int offset976(int) {
+ return offset = 976;
+ }
+
+ virtual unsigned int offset977(int) {
+ return offset = 977;
+ }
+
+ virtual unsigned int offset978(int) {
+ return offset = 978;
+ }
+
+ virtual unsigned int offset979(int) {
+ return offset = 979;
+ }
+
+ virtual unsigned int offset980(int) {
+ return offset = 980;
+ }
+
+ virtual unsigned int offset981(int) {
+ return offset = 981;
+ }
+
+ virtual unsigned int offset982(int) {
+ return offset = 982;
+ }
+
+ virtual unsigned int offset983(int) {
+ return offset = 983;
+ }
+
+ virtual unsigned int offset984(int) {
+ return offset = 984;
+ }
+
+ virtual unsigned int offset985(int) {
+ return offset = 985;
+ }
+
+ virtual unsigned int offset986(int) {
+ return offset = 986;
+ }
+
+ virtual unsigned int offset987(int) {
+ return offset = 987;
+ }
+
+ virtual unsigned int offset988(int) {
+ return offset = 988;
+ }
+
+ virtual unsigned int offset989(int) {
+ return offset = 989;
+ }
+
+ virtual unsigned int offset990(int) {
+ return offset = 990;
+ }
+
+ virtual unsigned int offset991(int) {
+ return offset = 991;
+ }
+
+ virtual unsigned int offset992(int) {
+ return offset = 992;
+ }
+
+ virtual unsigned int offset993(int) {
+ return offset = 993;
+ }
+
+ virtual unsigned int offset994(int) {
+ return offset = 994;
+ }
+
+ virtual unsigned int offset995(int) {
+ return offset = 995;
+ }
+
+ virtual unsigned int offset996(int) {
+ return offset = 996;
+ }
+
+ virtual unsigned int offset997(int) {
+ return offset = 997;
+ }
+
+ virtual unsigned int offset998(int) {
+ return offset = 998;
+ }
+
+ virtual unsigned int offset999(int) {
+ return offset = 999;
+ }
+
+ virtual unsigned int offset1000(int) {
+ return offset = 1000;
+ }
+
+ };
+}
+namespace fakeit {
+
+ template<typename TARGET, typename SOURCE>
+ TARGET union_cast(SOURCE source) {
+
+ union {
+ SOURCE source;
+ TARGET target;
+ } u;
+ u.source = source;
+ return u.target;
+ }
+
+}
+
+namespace fakeit {
+ class NoVirtualDtor : public std::runtime_error {
+ public:
+ NoVirtualDtor() :std::runtime_error("Can't mock the destructor. No virtual destructor was found") {}
+ };
+
+ class VTUtils {
+ public:
+
+ template<typename C, typename R, typename ... arglist>
+ static unsigned int getOffset(R (C::*vMethod)(arglist...)) {
+ auto sMethod = reinterpret_cast<unsigned int (VirtualOffsetSelector::*)(int)>(vMethod);
+ VirtualOffsetSelector offsetSelctor;
+ return (offsetSelctor.*sMethod)(0);
+ }
+
+ template<typename C>
+ static typename std::enable_if<std::has_virtual_destructor<C>::value, unsigned int>::type
+ getDestructorOffset() {
+ VirtualOffsetSelector offsetSelctor;
+ union_cast<C *>(&offsetSelctor)->~C();
+ return offsetSelctor.offset;
+ }
+
+ template<typename C>
+ static typename std::enable_if<!std::has_virtual_destructor<C>::value, unsigned int>::type
+ getDestructorOffset() {
+ throw NoVirtualDtor();
+ }
+
+ template<typename C>
+ static typename std::enable_if<std::has_virtual_destructor<C>::value, bool>::type
+ hasVirtualDestructor() {
+ return true;
+ }
+
+ template<typename C>
+ static typename std::enable_if<!std::has_virtual_destructor<C>::value, bool>::type
+ hasVirtualDestructor() {
+ return false;
+ }
+
+ template<typename C>
+ static unsigned int getVTSize() {
+ struct Derrived : public C {
+ virtual void endOfVt() {
+ }
+ };
+
+ unsigned int vtSize = getOffset(&Derrived::endOfVt);
+ return vtSize;
+ }
+ };
+
+
+}
+#ifdef _MSC_VER
+namespace fakeit {
+
+ typedef unsigned long dword_;
+
+ struct TypeDescriptor {
+ TypeDescriptor() :
+ ptrToVTable(0), spare(0) {
+
+ int **tiVFTPtr = (int **) (&typeid(void));
+ int *i = (int *) tiVFTPtr[0];
+ char *type_info_vft_ptr = (char *) i;
+ ptrToVTable = type_info_vft_ptr;
+ }
+
+ char *ptrToVTable;
+ dword_ spare;
+ char name[8];
+ };
+
+ struct PMD {
+
+
+
+ int mdisp;
+
+ int pdisp;
+ int vdisp;
+
+ PMD() :
+ mdisp(0), pdisp(-1), vdisp(0) {
+ }
+ };
+
+ struct RTTIBaseClassDescriptor {
+ RTTIBaseClassDescriptor() :
+ pTypeDescriptor(nullptr), numContainedBases(0), attributes(0) {
+ }
+
+ const std::type_info *pTypeDescriptor;
+ dword_ numContainedBases;
+ struct PMD where;
+ dword_ attributes;
+ };
+
+ template<typename C, typename... baseclasses>
+ struct RTTIClassHierarchyDescriptor {
+ RTTIClassHierarchyDescriptor() :
+ signature(0),
+ attributes(0),
+ numBaseClasses(0),
+ pBaseClassArray(nullptr) {
+ pBaseClassArray = new RTTIBaseClassDescriptor *[1 + sizeof...(baseclasses)];
+ addBaseClass < C, baseclasses...>();
+ }
+
+ ~RTTIClassHierarchyDescriptor() {
+ for (int i = 0; i < 1 + sizeof...(baseclasses); i++) {
+ RTTIBaseClassDescriptor *desc = pBaseClassArray[i];
+ delete desc;
+ }
+ delete[] pBaseClassArray;
+ }
+
+ dword_ signature;
+ dword_ attributes;
+ dword_ numBaseClasses;
+ RTTIBaseClassDescriptor **pBaseClassArray;
+
+ template<typename BaseType>
+ void addBaseClass() {
+ static_assert(std::is_base_of<BaseType, C>::value, "C must be a derived class of BaseType");
+ RTTIBaseClassDescriptor *desc = new RTTIBaseClassDescriptor();
+ desc->pTypeDescriptor = &typeid(BaseType);
+ pBaseClassArray[numBaseClasses] = desc;
+ for (unsigned int i = 0; i < numBaseClasses; i++) {
+ pBaseClassArray[i]->numContainedBases++;
+ }
+ numBaseClasses++;
+ }
+
+ template<typename head, typename B1, typename... tail>
+ void addBaseClass() {
+ static_assert(std::is_base_of<B1, head>::value, "invalid inheritance list");
+ addBaseClass<head>();
+ addBaseClass<B1, tail...>();
+ }
+
+ };
+
+ template<typename C, typename... baseclasses>
+ struct RTTICompleteObjectLocator {
+#ifdef _WIN64
+ RTTICompleteObjectLocator(const std::type_info &unused) :
+ signature(0), offset(0), cdOffset(0),
+ typeDescriptorOffset(0), classDescriptorOffset(0)
+ {
+ }
+
+ dword_ signature;
+ dword_ offset;
+ dword_ cdOffset;
+ dword_ typeDescriptorOffset;
+ dword_ classDescriptorOffset;
+#else
+ RTTICompleteObjectLocator(const std::type_info &info) :
+ signature(0), offset(0), cdOffset(0),
+ pTypeDescriptor(&info),
+ pClassDescriptor(new RTTIClassHierarchyDescriptor<C, baseclasses...>()) {
+ }
+
+ ~RTTICompleteObjectLocator() {
+ delete pClassDescriptor;
+ }
+
+ dword_ signature;
+ dword_ offset;
+ dword_ cdOffset;
+ const std::type_info *pTypeDescriptor;
+ struct RTTIClassHierarchyDescriptor<C, baseclasses...> *pClassDescriptor;
+#endif
+ };
+
+
+ struct VirtualTableBase {
+
+ static VirtualTableBase &getVTable(void *instance) {
+ fakeit::VirtualTableBase *vt = (fakeit::VirtualTableBase *) (instance);
+ return *vt;
+ }
+
+ VirtualTableBase(void **firstMethod) : _firstMethod(firstMethod) { }
+
+ void *getCookie(int index) {
+ return _firstMethod[-2 - index];
+ }
+
+ void setCookie(int index, void *value) {
+ _firstMethod[-2 - index] = value;
+ }
+
+ void *getMethod(unsigned int index) const {
+ return _firstMethod[index];
+ }
+
+ void setMethod(unsigned int index, void *method) {
+ _firstMethod[index] = method;
+ }
+
+ protected:
+ void **_firstMethod;
+ };
+
+ template<class C, class... baseclasses>
+ struct VirtualTable : public VirtualTableBase {
+
+ class Handle {
+
+ friend struct VirtualTable<C, baseclasses...>;
+
+ void **firstMethod;
+
+ Handle(void **method) : firstMethod(method) { }
+
+ public:
+
+ VirtualTable<C, baseclasses...> &restore() {
+ VirtualTable<C, baseclasses...> *vt = (VirtualTable<C, baseclasses...> *) this;
+ return *vt;
+ }
+ };
+
+ static VirtualTable<C, baseclasses...> &getVTable(C &instance) {
+ fakeit::VirtualTable<C, baseclasses...> *vt = (fakeit::VirtualTable<C, baseclasses...> *) (&instance);
+ return *vt;
+ }
+
+ void copyFrom(VirtualTable<C, baseclasses...> &from) {
+ unsigned int size = VTUtils::getVTSize<C>();
+ for (unsigned int i = 0; i < size; i++) {
+ _firstMethod[i] = from.getMethod(i);
+ }
+ }
+
+ VirtualTable() : VirtualTable(buildVTArray()) {
+ }
+
+ ~VirtualTable() {
+
+ }
+
+ void dispose() {
+ _firstMethod--;
+ RTTICompleteObjectLocator<C, baseclasses...> *locator = (RTTICompleteObjectLocator<C, baseclasses...> *) _firstMethod[0];
+ delete locator;
+ _firstMethod -= numOfCookies;
+ delete[] _firstMethod;
+ }
+
+
+ unsigned int dtor(int) {
+ C *c = (C *) this;
+ C &cRef = *c;
+ auto vt = VirtualTable<C, baseclasses...>::getVTable(cRef);
+ void *dtorPtr = vt.getCookie(numOfCookies - 1);
+ void(*method)(C *) = reinterpret_cast<void (*)(C *)>(dtorPtr);
+ method(c);
+ return 0;
+ }
+
+ void setDtor(void *method) {
+
+
+
+
+
+ void *dtorPtr = union_cast<void *>(&VirtualTable<C, baseclasses...>::dtor);
+ unsigned int index = VTUtils::getDestructorOffset<C>();
+ _firstMethod[index] = dtorPtr;
+ setCookie(numOfCookies - 1, method);
+ }
+
+ unsigned int getSize() {
+ return VTUtils::getVTSize<C>();
+ }
+
+ void initAll(void *value) {
+ auto size = getSize();
+ for (unsigned int i = 0; i < size; i++) {
+ setMethod(i, value);
+ }
+ }
+
+ Handle createHandle() {
+ Handle h(_firstMethod);
+ return h;
+ }
+
+ private:
+
+ class SimpleType {
+ };
+
+ static_assert(sizeof(unsigned int (SimpleType::*)()) == sizeof(unsigned int (C::*)()),
+ "Can't mock a type with multiple inheritance or with non-polymorphic base class");
+ static const unsigned int numOfCookies = 3;
+
+ static void **buildVTArray() {
+ int vtSize = VTUtils::getVTSize<C>();
+ auto array = new void *[vtSize + numOfCookies + 1]{};
+ RTTICompleteObjectLocator<C, baseclasses...> *objectLocator = new RTTICompleteObjectLocator<C, baseclasses...>(
+ typeid(C));
+ array += numOfCookies;
+ array[0] = objectLocator;
+ array++;
+ return array;
+ }
+
+ VirtualTable(void **firstMethod) : VirtualTableBase(firstMethod) {
+ }
+ };
+}
+#else
+#ifndef __clang__
+#include <type_traits>
+#include <tr2/type_traits>
+
+namespace fakeit {
+ template<typename ... T1>
+ class has_one_base {
+ };
+
+ template<typename T1, typename T2, typename ... types>
+ class has_one_base<std::tr2::__reflection_typelist<T1, T2, types...>> : public std::false_type {
+ };
+
+ template<typename T1>
+ class has_one_base<std::tr2::__reflection_typelist<T1>>
+ : public has_one_base<typename std::tr2::direct_bases<T1>::type> {
+ };
+
+ template<>
+ class has_one_base<std::tr2::__reflection_typelist<>> : public std::true_type {
+ };
+
+ template<typename T>
+ class is_simple_inheritance_layout : public has_one_base<typename std::tr2::direct_bases<T>::type> {
+ };
+}
+
+#endif
+
+namespace fakeit {
+
+ struct VirtualTableBase {
+
+ static VirtualTableBase &getVTable(void *instance) {
+ fakeit::VirtualTableBase *vt = (fakeit::VirtualTableBase *) (instance);
+ return *vt;
+ }
+
+ VirtualTableBase(void **firstMethod) : _firstMethod(firstMethod) { }
+
+ void *getCookie(int index) {
+ return _firstMethod[-3 - index];
+ }
+
+ void setCookie(int index, void *value) {
+ _firstMethod[-3 - index] = value;
+ }
+
+ void *getMethod(unsigned int index) const {
+ return _firstMethod[index];
+ }
+
+ void setMethod(unsigned int index, void *method) {
+ _firstMethod[index] = method;
+ }
+
+ protected:
+ void **_firstMethod;
+ };
+
+ template<class C, class ... baseclasses>
+ struct VirtualTable : public VirtualTableBase {
+
+#ifndef __clang__
+ static_assert(is_simple_inheritance_layout<C>::value, "Can't mock a type with multiple inheritance");
+#endif
+
+ class Handle {
+
+ friend struct VirtualTable<C, baseclasses...>;
+ void **firstMethod;
+
+ Handle(void **method) :
+ firstMethod(method) {
+ }
+
+ public:
+
+ VirtualTable<C, baseclasses...> &restore() {
+ VirtualTable<C, baseclasses...> *vt = (VirtualTable<C, baseclasses...> *) this;
+ return *vt;
+ }
+ };
+
+ static VirtualTable<C, baseclasses...> &getVTable(C &instance) {
+ fakeit::VirtualTable<C, baseclasses...> *vt = (fakeit::VirtualTable<C, baseclasses...> *) (&instance);
+ return *vt;
+ }
+
+ void copyFrom(VirtualTable<C, baseclasses...> &from) {
+ unsigned int size = VTUtils::getVTSize<C>();
+
+ for (size_t i = 0; i < size; ++i) {
+ _firstMethod[i] = from.getMethod(i);
+ }
+ }
+
+ VirtualTable() :
+ VirtualTable(buildVTArray()) {
+ }
+
+ void dispose() {
+ _firstMethod--;
+ _firstMethod--;
+ _firstMethod -= numOfCookies;
+ delete[] _firstMethod;
+ }
+
+ unsigned int dtor(int) {
+ C *c = (C *) this;
+ C &cRef = *c;
+ auto vt = VirtualTable<C, baseclasses...>::getVTable(cRef);
+ unsigned int index = VTUtils::getDestructorOffset<C>();
+ void *dtorPtr = vt.getMethod(index);
+ void(*method)(C *) = union_cast<void (*)(C *)>(dtorPtr);
+ method(c);
+ return 0;
+ }
+
+
+ void setDtor(void *method) {
+ unsigned int index = VTUtils::getDestructorOffset<C>();
+ void *dtorPtr = union_cast<void *>(&VirtualTable<C, baseclasses...>::dtor);
+
+
+ _firstMethod[index] = method;
+
+ _firstMethod[index + 1] = dtorPtr;
+ }
+
+
+ unsigned int getSize() {
+ return VTUtils::getVTSize<C>();
+ }
+
+ void initAll(void *value) {
+ unsigned int size = getSize();
+ for (unsigned int i = 0; i < size; i++) {
+ setMethod(i, value);
+ }
+ }
+
+ const std::type_info *getTypeId() {
+ return (const std::type_info *) (_firstMethod[-1]);
+ }
+
+ Handle createHandle() {
+ Handle h(_firstMethod);
+ return h;
+ }
+
+ private:
+ static const unsigned int numOfCookies = 2;
+
+ static void **buildVTArray() {
+ int size = VTUtils::getVTSize<C>();
+ auto array = new void *[size + 2 + numOfCookies]{};
+ array += numOfCookies;
+ array++;
+ array[0] = const_cast<std::type_info *>(&typeid(C));
+ array++;
+ return array;
+ }
+
+ VirtualTable(void **firstMethod) : VirtualTableBase(firstMethod) {
+ }
+
+ };
+}
+#endif
+namespace fakeit {
+
+ struct NoMoreRecordedActionException {
+ };
+
+ template<typename R, typename ... arglist>
+ struct MethodInvocationHandler : Destructible {
+ virtual R handleMethodInvocation(const typename fakeit::production_arg<arglist>::type... args) = 0;
+ };
+
+}
+#include <new>
+
+namespace fakeit {
+
+#ifdef __GNUG__
+#ifndef __clang__
+#pragma GCC diagnostic ignored "-Wpedantic"
+#endif
+#endif
+
+
+#ifdef _MSC_VER
+#pragma warning( push )
+#pragma warning( disable : 4200 )
+#endif
+
+
+ template<typename C, typename ... baseclasses>
+ class FakeObject {
+
+ VirtualTable<C, baseclasses...> vtable;
+
+ static const size_t SIZE = sizeof(C) - sizeof(VirtualTable<C, baseclasses...>);
+ char instanceArea[SIZE ? SIZE : 0];
+
+ FakeObject(FakeObject const &) = delete;
+ FakeObject &operator=(FakeObject const &) = delete;
+
+ public:
+
+ FakeObject() : vtable() {
+ initializeDataMembersArea();
+ }
+
+ ~FakeObject() {
+ vtable.dispose();
+ }
+
+ void initializeDataMembersArea() {
+ for (size_t i = 0; i < SIZE; ++i) instanceArea[i] = (char) 0;
+ }
+
+ void setMethod(unsigned int index, void *method) {
+ vtable.setMethod(index, method);
+ }
+
+ VirtualTable<C, baseclasses...> &getVirtualTable() {
+ return vtable;
+ }
+
+ void setVirtualTable(VirtualTable<C, baseclasses...> &t) {
+ vtable = t;
+ }
+
+ void setDtor(void *dtor) {
+ vtable.setDtor(dtor);
+ }
+ };
+
+#ifdef _MSC_VER
+#pragma warning( pop )
+#endif
+
+#ifdef __GNUG__
+#ifndef __clang__
+#pragma GCC diagnostic pop
+#endif
+#endif
+
+}
+namespace fakeit {
+
+ struct MethodProxy {
+
+ MethodProxy(unsigned int id, unsigned int offset, void *vMethod) :
+ _id(id),
+ _offset(offset),
+ _vMethod(vMethod) {
+ }
+
+ unsigned int getOffset() const {
+ return _offset;
+ }
+
+ unsigned int getId() const {
+ return _id;
+ }
+
+ void *getProxy() const {
+ return union_cast<void *>(_vMethod);
+ }
+
+ private:
+ unsigned int _id;
+ unsigned int _offset;
+ void *_vMethod;
+ };
+}
+#include <utility>
+
+
+namespace fakeit {
+
+ struct InvocationHandlerCollection {
+ static const unsigned int VT_COOKIE_INDEX = 0;
+
+ virtual Destructible *getInvocatoinHandlerPtrById(unsigned int index) = 0;
+
+ static InvocationHandlerCollection *getInvocationHandlerCollection(void *instance) {
+ VirtualTableBase &vt = VirtualTableBase::getVTable(instance);
+ InvocationHandlerCollection *invocationHandlerCollection = (InvocationHandlerCollection *) vt.getCookie(
+ InvocationHandlerCollection::VT_COOKIE_INDEX);
+ return invocationHandlerCollection;
+ }
+ };
+
+
+ template<typename R, typename ... arglist>
+ class MethodProxyCreator {
+
+
+
+ public:
+
+ template<unsigned int id>
+ MethodProxy createMethodProxy(unsigned int offset) {
+ return MethodProxy(id, offset, union_cast<void *>(&MethodProxyCreator::methodProxyX < id > ));
+ }
+
+ protected:
+
+ R methodProxy(unsigned int id, const typename fakeit::production_arg<arglist>::type... args) {
+ InvocationHandlerCollection *invocationHandlerCollection = InvocationHandlerCollection::getInvocationHandlerCollection(
+ this);
+ MethodInvocationHandler<R, arglist...> *invocationHandler =
+ (MethodInvocationHandler<R, arglist...> *) invocationHandlerCollection->getInvocatoinHandlerPtrById(
+ id);
+ return invocationHandler->handleMethodInvocation(std::forward<const typename fakeit::production_arg<arglist>::type>(args)...);
+ }
+
+ template<int id>
+ R methodProxyX(arglist ... args) {
+ return methodProxy(id, std::forward<const typename fakeit::production_arg<arglist>::type>(args)...);
+ }
+ };
+}
+
+namespace fakeit {
+
+ class InvocationHandlers : public InvocationHandlerCollection {
+ std::vector<std::shared_ptr<Destructible>> &_methodMocks;
+ std::vector<unsigned int> &_offsets;
+
+ unsigned int getOffset(unsigned int id) const
+ {
+ unsigned int offset = 0;
+ for (; offset < _offsets.size(); offset++) {
+ if (_offsets[offset] == id) {
+ break;
+ }
+ }
+ return offset;
+ }
+
+ public:
+ InvocationHandlers(
+ std::vector<std::shared_ptr<Destructible>> &methodMocks,
+ std::vector<unsigned int> &offsets) :
+ _methodMocks(methodMocks), _offsets(offsets) {
+ for (std::vector<unsigned int>::iterator it = _offsets.begin(); it != _offsets.end(); ++it)
+ {
+ *it = std::numeric_limits<int>::max();
+ }
+ }
+
+ Destructible *getInvocatoinHandlerPtrById(unsigned int id) override {
+ unsigned int offset = getOffset(id);
+ std::shared_ptr<Destructible> ptr = _methodMocks[offset];
+ return ptr.get();
+ }
+
+ };
+
+ template<typename C, typename ... baseclasses>
+ struct DynamicProxy {
+
+ static_assert(std::is_polymorphic<C>::value, "DynamicProxy requires a polymorphic type");
+
+ DynamicProxy(C &inst) :
+ instance(inst),
+ originalVtHandle(VirtualTable<C, baseclasses...>::getVTable(instance).createHandle()),
+ _methodMocks(VTUtils::getVTSize<C>()),
+ _offsets(VTUtils::getVTSize<C>()),
+ _invocationHandlers(_methodMocks, _offsets) {
+ _cloneVt.copyFrom(originalVtHandle.restore());
+ _cloneVt.setCookie(InvocationHandlerCollection::VT_COOKIE_INDEX, &_invocationHandlers);
+ getFake().setVirtualTable(_cloneVt);
+ }
+
+ void detach() {
+ getFake().setVirtualTable(originalVtHandle.restore());
+ }
+
+ ~DynamicProxy() {
+ _cloneVt.dispose();
+ }
+
+ C &get() {
+ return instance;
+ }
+
+ void Reset() {
+ _methodMocks = {};
+ _methodMocks.resize(VTUtils::getVTSize<C>());
+ _members = {};
+ _offsets = {};
+ _offsets.resize(VTUtils::getVTSize<C>());
+ _cloneVt.copyFrom(originalVtHandle.restore());
+ }
+
+ void Clear()
+ {
+ }
+
+ template<int id, typename R, typename ... arglist>
+ void stubMethod(R(C::*vMethod)(arglist...), MethodInvocationHandler<R, arglist...> *methodInvocationHandler) {
+ auto offset = VTUtils::getOffset(vMethod);
+ MethodProxyCreator<R, arglist...> creator;
+ bind(creator.template createMethodProxy<id + 1>(offset), methodInvocationHandler);
+ }
+
+ void stubDtor(MethodInvocationHandler<void> *methodInvocationHandler) {
+ auto offset = VTUtils::getDestructorOffset<C>();
+ MethodProxyCreator<void> creator;
+ bindDtor(creator.createMethodProxy<0>(offset), methodInvocationHandler);
+ }
+
+ template<typename R, typename ... arglist>
+ bool isMethodStubbed(R(C::*vMethod)(arglist...)) {
+ unsigned int offset = VTUtils::getOffset(vMethod);
+ return isBinded(offset);
+ }
+
+ bool isDtorStubbed() {
+ unsigned int offset = VTUtils::getDestructorOffset<C>();
+ return isBinded(offset);
+ }
+
+ template<typename R, typename ... arglist>
+ Destructible *getMethodMock(R(C::*vMethod)(arglist...)) {
+ auto offset = VTUtils::getOffset(vMethod);
+ std::shared_ptr<Destructible> ptr = _methodMocks[offset];
+ return ptr.get();
+ }
+
+ Destructible *getDtorMock() {
+ auto offset = VTUtils::getDestructorOffset<C>();
+ std::shared_ptr<Destructible> ptr = _methodMocks[offset];
+ return ptr.get();
+ }
+
+ template<typename DATA_TYPE, typename ... arglist>
+ void stubDataMember(DATA_TYPE C::*member, const arglist &... initargs) {
+ DATA_TYPE C::*theMember = (DATA_TYPE C::*) member;
+ C &mock = get();
+ DATA_TYPE *memberPtr = &(mock.*theMember);
+ _members.push_back(
+ std::shared_ptr<DataMemeberWrapper < DATA_TYPE, arglist...> >
+ {new DataMemeberWrapper < DATA_TYPE, arglist...>(memberPtr,
+ initargs...)});
+ }
+
+ template<typename DATA_TYPE>
+ void getMethodMocks(std::vector<DATA_TYPE> &into) const {
+ for (std::shared_ptr<Destructible> ptr : _methodMocks) {
+ DATA_TYPE p = dynamic_cast<DATA_TYPE>(ptr.get());
+ if (p) {
+ into.push_back(p);
+ }
+ }
+ }
+
+ VirtualTable<C, baseclasses...> &getOriginalVT() {
+ VirtualTable<C, baseclasses...> &vt = originalVtHandle.restore();
+ return vt;
+ }
+
+ private:
+
+ template<typename DATA_TYPE, typename ... arglist>
+ class DataMemeberWrapper : public Destructible {
+ private:
+ DATA_TYPE *dataMember;
+ public:
+ DataMemeberWrapper(DATA_TYPE *dataMem, const arglist &... initargs) :
+ dataMember(dataMem) {
+ new(dataMember) DATA_TYPE{initargs ...};
+ }
+
+ ~DataMemeberWrapper() override
+ {
+ dataMember->~DATA_TYPE();
+ }
+ };
+
+ static_assert(sizeof(C) == sizeof(FakeObject<C, baseclasses...>), "This is a problem");
+
+ C &instance;
+ typename VirtualTable<C, baseclasses...>::Handle originalVtHandle;
+ VirtualTable<C, baseclasses...> _cloneVt;
+
+ std::vector<std::shared_ptr<Destructible>> _methodMocks;
+ std::vector<std::shared_ptr<Destructible>> _members;
+ std::vector<unsigned int> _offsets;
+ InvocationHandlers _invocationHandlers;
+
+ FakeObject<C, baseclasses...> &getFake() {
+ return reinterpret_cast<FakeObject<C, baseclasses...> &>(instance);
+ }
+
+ void bind(const MethodProxy &methodProxy, Destructible *invocationHandler) {
+ getFake().setMethod(methodProxy.getOffset(), methodProxy.getProxy());
+ _methodMocks[methodProxy.getOffset()].reset(invocationHandler);
+ _offsets[methodProxy.getOffset()] = methodProxy.getId();
+ }
+
+ void bindDtor(const MethodProxy &methodProxy, Destructible *invocationHandler) {
+ getFake().setDtor(methodProxy.getProxy());
+ _methodMocks[methodProxy.getOffset()].reset(invocationHandler);
+ _offsets[methodProxy.getOffset()] = methodProxy.getId();
+ }
+
+ template<typename DATA_TYPE>
+ DATA_TYPE getMethodMock(unsigned int offset) {
+ std::shared_ptr<Destructible> ptr = _methodMocks[offset];
+ return dynamic_cast<DATA_TYPE>(ptr.get());
+ }
+
+ template<typename BaseClass>
+ void checkMultipleInheritance() {
+ C *ptr = (C *) (unsigned int) 1;
+ BaseClass *basePtr = ptr;
+ int delta = (unsigned long) basePtr - (unsigned long) ptr;
+ if (delta > 0) {
+
+
+ throw std::invalid_argument(std::string("multiple inheritance is not supported"));
+ }
+ }
+
+ bool isBinded(unsigned int offset) {
+ std::shared_ptr<Destructible> ptr = _methodMocks[offset];
+ return ptr.get() != nullptr;
+ }
+
+ };
+}
+#include <functional>
+#include <type_traits>
+#include <memory>
+#include <iosfwd>
+#include <vector>
+#include <functional>
+#include <tuple>
+#include <tuple>
+
+namespace fakeit {
+
+ template<int N>
+ struct apply_func {
+ template<typename R, typename ... ArgsF, typename ... ArgsT, typename ... Args>
+ static R applyTuple(std::function<R(ArgsF &...)> f, std::tuple<ArgsT...> &t, Args &... args) {
+ return apply_func<N - 1>::template applyTuple(f, t, std::get<N - 1>(t), args...);
+ }
+ };
+
+ template<>
+ struct apply_func < 0 > {
+ template<typename R, typename ... ArgsF, typename ... ArgsT, typename ... Args>
+ static R applyTuple(std::function<R(ArgsF &...)> f, std::tuple<ArgsT...> & , Args &... args) {
+ return f(args...);
+ }
+ };
+
+ struct TupleDispatcher {
+
+ template<typename R, typename ... ArgsF, typename ... ArgsT>
+ static R applyTuple(std::function<R(ArgsF &...)> f, std::tuple<ArgsT...> &t) {
+ return apply_func<sizeof...(ArgsT)>::template applyTuple(f, t);
+ }
+
+ template<typename R, typename ...arglist>
+ static R invoke(std::function<R(arglist &...)> func, const std::tuple<arglist...> &arguments) {
+ std::tuple<arglist...> &args = const_cast<std::tuple<arglist...> &>(arguments);
+ return applyTuple(func, args);
+ }
+
+ template<typename TupleType, typename FunctionType>
+ static void for_each(TupleType &&, FunctionType &,
+ std::integral_constant<size_t, std::tuple_size<typename std::remove_reference<TupleType>::type>::value>) {
+ }
+
+ template<std::size_t I, typename TupleType, typename FunctionType, typename = typename std::enable_if<
+ I != std::tuple_size<typename std::remove_reference<TupleType>::type>::value>::type>
+ static void for_each(TupleType &&t, FunctionType &f, std::integral_constant<size_t, I>) {
+ f(I, std::get < I >(t));
+ for_each(std::forward < TupleType >(t), f, std::integral_constant<size_t, I + 1>());
+ }
+
+ template<typename TupleType, typename FunctionType>
+ static void for_each(TupleType &&t, FunctionType &f) {
+ for_each(std::forward < TupleType >(t), f, std::integral_constant<size_t, 0>());
+ }
+
+ template<typename TupleType1, typename TupleType2, typename FunctionType>
+ static void for_each(TupleType1 &&, TupleType2 &&, FunctionType &,
+ std::integral_constant<size_t, std::tuple_size<typename std::remove_reference<TupleType1>::type>::value>) {
+ }
+
+ template<std::size_t I, typename TupleType1, typename TupleType2, typename FunctionType, typename = typename std::enable_if<
+ I != std::tuple_size<typename std::remove_reference<TupleType1>::type>::value>::type>
+ static void for_each(TupleType1 &&t, TupleType2 &&t2, FunctionType &f, std::integral_constant<size_t, I>) {
+ f(I, std::get < I >(t), std::get < I >(t2));
+ for_each(std::forward < TupleType1 >(t), std::forward < TupleType2 >(t2), f, std::integral_constant<size_t, I + 1>());
+ }
+
+ template<typename TupleType1, typename TupleType2, typename FunctionType>
+ static void for_each(TupleType1 &&t, TupleType2 &&t2, FunctionType &f) {
+ for_each(std::forward < TupleType1 >(t), std::forward < TupleType2 >(t2), f, std::integral_constant<size_t, 0>());
+ }
+ };
+}
+namespace fakeit {
+
+ template<typename R, typename ... arglist>
+ struct ActualInvocationHandler : Destructible {
+ virtual R handleMethodInvocation(ArgumentsTuple<arglist...> & args) = 0;
+ };
+
+}
+#include <functional>
+#include <tuple>
+#include <string>
+#include <iosfwd>
+#include <type_traits>
+#include <typeinfo>
+
+namespace fakeit {
+
+ struct DefaultValueInstatiationException {
+ virtual ~DefaultValueInstatiationException() = default;
+
+ virtual std::string what() const = 0;
+ };
+
+
+ template<class C>
+ struct is_constructible_type {
+ static const bool value =
+ std::is_default_constructible<typename naked_type<C>::type>::value
+ && !std::is_abstract<typename naked_type<C>::type>::value;
+ };
+
+ template<class C, class Enable = void>
+ struct DefaultValue;
+
+ template<class C>
+ struct DefaultValue<C, typename std::enable_if<!is_constructible_type<C>::value>::type> {
+ static C &value() {
+ if (std::is_reference<C>::value) {
+ typename naked_type<C>::type *ptr = nullptr;
+ return *ptr;
+ }
+
+ class Exception : public DefaultValueInstatiationException {
+ virtual std::string what() const
+
+ override {
+ return (std::string("Type ") + std::string(typeid(C).name())
+ + std::string(
+ " is not default constructible. Could not instantiate a default return value")).c_str();
+ }
+ };
+
+ throw Exception();
+ }
+ };
+
+ template<class C>
+ struct DefaultValue<C, typename std::enable_if<is_constructible_type<C>::value>::type> {
+ static C &value() {
+ static typename naked_type<C>::type val{};
+ return val;
+ }
+ };
+
+
+ template<>
+ struct DefaultValue<void> {
+ static void value() {
+ return;
+ }
+ };
+
+ template<>
+ struct DefaultValue<bool> {
+ static bool &value() {
+ static bool value{false};
+ return value;
+ }
+ };
+
+ template<>
+ struct DefaultValue<char> {
+ static char &value() {
+ static char value{0};
+ return value;
+ }
+ };
+
+ template<>
+ struct DefaultValue<char16_t> {
+ static char16_t &value() {
+ static char16_t value{0};
+ return value;
+ }
+ };
+
+ template<>
+ struct DefaultValue<char32_t> {
+ static char32_t &value() {
+ static char32_t value{0};
+ return value;
+ }
+ };
+
+ template<>
+ struct DefaultValue<wchar_t> {
+ static wchar_t &value() {
+ static wchar_t value{0};
+ return value;
+ }
+ };
+
+ template<>
+ struct DefaultValue<short> {
+ static short &value() {
+ static short value{0};
+ return value;
+ }
+ };
+
+ template<>
+ struct DefaultValue<int> {
+ static int &value() {
+ static int value{0};
+ return value;
+ }
+ };
+
+ template<>
+ struct DefaultValue<long> {
+ static long &value() {
+ static long value{0};
+ return value;
+ }
+ };
+
+ template<>
+ struct DefaultValue<long long> {
+ static long long &value() {
+ static long long value{0};
+ return value;
+ }
+ };
+
+ template<>
+ struct DefaultValue<std::string> {
+ static std::string &value() {
+ static std::string value{};
+ return value;
+ }
+ };
+
+}
+namespace fakeit {
+
+ struct IMatcher : Destructible {
+ ~IMatcher() = default;
+ virtual std::string format() const = 0;
+ };
+
+ template<typename T>
+ struct TypedMatcher : IMatcher {
+ virtual bool matches(const T &actual) const = 0;
+ };
+
+ template<typename T>
+ struct TypedMatcherCreator {
+
+ virtual ~TypedMatcherCreator() = default;
+
+ virtual TypedMatcher<T> *createMatcher() const = 0;
+ };
+
+ template<typename T>
+ struct ComparisonMatcherCreator : public TypedMatcherCreator<T> {
+
+ virtual ~ComparisonMatcherCreator() = default;
+
+ ComparisonMatcherCreator(const T &arg)
+ : _expected(arg) {
+ }
+
+ struct Matcher : public TypedMatcher<T> {
+ Matcher(const T &expected)
+ : _expected(expected) {
+ }
+
+ const T _expected;
+ };
+
+ const T &_expected;
+ };
+
+ namespace internal {
+ template<typename T>
+ struct TypedAnyMatcher : public TypedMatcherCreator<T> {
+
+ virtual ~TypedAnyMatcher() = default;
+
+ TypedAnyMatcher() {
+ }
+
+ struct Matcher : public TypedMatcher<T> {
+ virtual bool matches(const T &) const override {
+ return true;
+ }
+
+ virtual std::string format() const override {
+ return "Any";
+ }
+ };
+
+ virtual TypedMatcher<T> *createMatcher() const override {
+ return new Matcher();
+ }
+
+ };
+
+ template<typename T>
+ struct EqMatcherCreator : public ComparisonMatcherCreator<T> {
+
+ virtual ~EqMatcherCreator() = default;
+
+ EqMatcherCreator(const T &expected)
+ : ComparisonMatcherCreator<T>(expected) {
+ }
+
+ struct Matcher : public ComparisonMatcherCreator<T>::Matcher {
+ Matcher(const T &expected)
+ : ComparisonMatcherCreator<T>::Matcher(expected) {
+ }
+
+ virtual std::string format() const override {
+ return TypeFormatter<T>::format(this->_expected);
+ }
+
+ virtual bool matches(const T &actual) const override {
+ return actual == this->_expected;
+ }
+ };
+
+ virtual TypedMatcher<T> *createMatcher() const {
+ return new Matcher(this->_expected);
+ }
+
+ };
+
+ template<typename T>
+ struct GtMatcherCreator : public ComparisonMatcherCreator<T> {
+
+ virtual ~GtMatcherCreator() = default;
+
+ GtMatcherCreator(const T &expected)
+ : ComparisonMatcherCreator<T>(expected) {
+ }
+
+ struct Matcher : public ComparisonMatcherCreator<T>::Matcher {
+ Matcher(const T &expected)
+ : ComparisonMatcherCreator<T>::Matcher(expected) {
+ }
+
+ virtual bool matches(const T &actual) const override {
+ return actual > this->_expected;
+ }
+
+ virtual std::string format() const override {
+ return std::string(">") + TypeFormatter<T>::format(this->_expected);
+ }
+ };
+
+ virtual TypedMatcher<T> *createMatcher() const override {
+ return new Matcher(this->_expected);
+ }
+ };
+
+ template<typename T>
+ struct GeMatcherCreator : public ComparisonMatcherCreator<T> {
+
+ virtual ~GeMatcherCreator() = default;
+
+ GeMatcherCreator(const T &expected)
+ : ComparisonMatcherCreator<T>(expected) {
+ }
+
+ struct Matcher : public ComparisonMatcherCreator<T>::Matcher {
+ Matcher(const T &expected)
+ : ComparisonMatcherCreator<T>::Matcher(expected) {
+ }
+
+ virtual bool matches(const T &actual) const override {
+ return actual >= this->_expected;
+ }
+
+ virtual std::string format() const override {
+ return std::string(">=") + TypeFormatter<T>::format(this->_expected);
+ }
+ };
+
+ virtual TypedMatcher<T> *createMatcher() const override {
+ return new Matcher(this->_expected);
+ }
+ };
+
+ template<typename T>
+ struct LtMatcherCreator : public ComparisonMatcherCreator<T> {
+
+ virtual ~LtMatcherCreator() = default;
+
+ LtMatcherCreator(const T &expected)
+ : ComparisonMatcherCreator<T>(expected) {
+ }
+
+ struct Matcher : public ComparisonMatcherCreator<T>::Matcher {
+ Matcher(const T &expected)
+ : ComparisonMatcherCreator<T>::Matcher(expected) {
+ }
+
+ virtual bool matches(const T &actual) const override {
+ return actual < this->_expected;
+ }
+
+ virtual std::string format() const override {
+ return std::string("<") + TypeFormatter<T>::format(this->_expected);
+ }
+ };
+
+ virtual TypedMatcher<T> *createMatcher() const override {
+ return new Matcher(this->_expected);
+ }
+
+ };
+
+ template<typename T>
+ struct LeMatcherCreator : public ComparisonMatcherCreator<T> {
+
+ virtual ~LeMatcherCreator() = default;
+
+ LeMatcherCreator(const T &expected)
+ : ComparisonMatcherCreator<T>(expected) {
+ }
+
+ struct Matcher : public ComparisonMatcherCreator<T>::Matcher {
+ Matcher(const T &expected)
+ : ComparisonMatcherCreator<T>::Matcher(expected) {
+ }
+
+ virtual bool matches(const T &actual) const override {
+ return actual <= this->_expected;
+ }
+
+ virtual std::string format() const override {
+ return std::string("<=") + TypeFormatter<T>::format(this->_expected);
+ }
+ };
+
+ virtual TypedMatcher<T> *createMatcher() const override {
+ return new Matcher(this->_expected);
+ }
+
+ };
+
+ template<typename T>
+ struct NeMatcherCreator : public ComparisonMatcherCreator<T> {
+
+ virtual ~NeMatcherCreator() = default;
+
+ NeMatcherCreator(const T &expected)
+ : ComparisonMatcherCreator<T>(expected) {
+ }
+
+ struct Matcher : public ComparisonMatcherCreator<T>::Matcher {
+ Matcher(const T &expected)
+ : ComparisonMatcherCreator<T>::Matcher(expected) {
+ }
+
+ virtual bool matches(const T &actual) const override {
+ return actual != this->_expected;
+ }
+
+ virtual std::string format() const override {
+ return std::string("!=") + TypeFormatter<T>::format(this->_expected);
+ }
+
+ };
+
+ virtual TypedMatcher<T> *createMatcher() const override {
+ return new Matcher(this->_expected);
+ }
+
+ };
+ }
+
+ struct AnyMatcher {
+ } static _;
+
+ template<typename T>
+ internal::TypedAnyMatcher<T> Any() {
+ internal::TypedAnyMatcher<T> rv;
+ return rv;
+ }
+
+ template<typename T>
+ internal::EqMatcherCreator<T> Eq(const T &arg) {
+ internal::EqMatcherCreator<T> rv(arg);
+ return rv;
+ }
+
+ template<typename T>
+ internal::GtMatcherCreator<T> Gt(const T &arg) {
+ internal::GtMatcherCreator<T> rv(arg);
+ return rv;
+ }
+
+ template<typename T>
+ internal::GeMatcherCreator<T> Ge(const T &arg) {
+ internal::GeMatcherCreator<T> rv(arg);
+ return rv;
+ }
+
+ template<typename T>
+ internal::LtMatcherCreator<T> Lt(const T &arg) {
+ internal::LtMatcherCreator<T> rv(arg);
+ return rv;
+ }
+
+ template<typename T>
+ internal::LeMatcherCreator<T> Le(const T &arg) {
+ internal::LeMatcherCreator<T> rv(arg);
+ return rv;
+ }
+
+ template<typename T>
+ internal::NeMatcherCreator<T> Ne(const T &arg) {
+ internal::NeMatcherCreator<T> rv(arg);
+ return rv;
+ }
+
+}
+
+namespace fakeit {
+
+ template<typename ... arglist>
+ struct ArgumentsMatcherInvocationMatcher : public ActualInvocation<arglist...>::Matcher {
+
+ virtual ~ArgumentsMatcherInvocationMatcher() {
+ for (unsigned int i = 0; i < _matchers.size(); i++)
+ delete _matchers[i];
+ }
+
+ ArgumentsMatcherInvocationMatcher(const std::vector<Destructible *> &args)
+ : _matchers(args) {
+ }
+
+ virtual bool matches(ActualInvocation<arglist...> &invocation) override {
+ if (invocation.getActualMatcher() == this)
+ return true;
+ return matches(invocation.getActualArguments());
+ }
+
+ virtual std::string format() const override {
+ std::ostringstream out;
+ out << "(";
+ for (unsigned int i = 0; i < _matchers.size(); i++) {
+ if (i > 0) out << ", ";
+ IMatcher *m = dynamic_cast<IMatcher *>(_matchers[i]);
+ out << m->format();
+ }
+ out << ")";
+ return out.str();
+ }
+
+ private:
+
+ struct MatchingLambda {
+ MatchingLambda(const std::vector<Destructible *> &matchers)
+ : _matchers(matchers) {
+ }
+
+ template<typename A>
+ void operator()(int index, A &actualArg) {
+ TypedMatcher<typename naked_type<A>::type> *matcher =
+ dynamic_cast<TypedMatcher<typename naked_type<A>::type> *>(_matchers[index]);
+ if (_matching)
+ _matching = matcher->matches(actualArg);
+ }
+
+ bool isMatching() {
+ return _matching;
+ }
+
+ private:
+ bool _matching = true;
+ const std::vector<Destructible *> &_matchers;
+ };
+
+ virtual bool matches(ArgumentsTuple<arglist...>& actualArguments) {
+ MatchingLambda l(_matchers);
+ fakeit::TupleDispatcher::for_each(actualArguments, l);
+ return l.isMatching();
+ }
+
+ const std::vector<Destructible *> _matchers;
+ };
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ template<typename ... arglist>
+ struct UserDefinedInvocationMatcher : ActualInvocation<arglist...>::Matcher {
+ virtual ~UserDefinedInvocationMatcher() = default;
+
+ UserDefinedInvocationMatcher(std::function<bool(arglist &...)> match)
+ : matcher{match} {
+ }
+
+ virtual bool matches(ActualInvocation<arglist...> &invocation) override {
+ if (invocation.getActualMatcher() == this)
+ return true;
+ return matches(invocation.getActualArguments());
+ }
+
+ virtual std::string format() const override {
+ return {"( user defined matcher )"};
+ }
+
+ private:
+ virtual bool matches(ArgumentsTuple<arglist...>& actualArguments) {
+ return TupleDispatcher::invoke<bool, typename tuple_arg<arglist>::type...>(matcher, actualArguments);
+ }
+
+ const std::function<bool(arglist &...)> matcher;
+ };
+
+ template<typename ... arglist>
+ struct DefaultInvocationMatcher : public ActualInvocation<arglist...>::Matcher {
+
+ virtual ~DefaultInvocationMatcher() = default;
+
+ DefaultInvocationMatcher() {
+ }
+
+ virtual bool matches(ActualInvocation<arglist...> &invocation) override {
+ return matches(invocation.getActualArguments());
+ }
+
+ virtual std::string format() const override {
+ return {"( Any arguments )"};
+ }
+
+ private:
+
+ virtual bool matches(const ArgumentsTuple<arglist...>&) {
+ return true;
+ }
+ };
+
+}
+
+namespace fakeit {
+
+
+ template<typename R, typename ... arglist>
+ class RecordedMethodBody : public MethodInvocationHandler<R, arglist...>, public ActualInvocationsSource, public ActualInvocationsContainer {
+
+ struct MatchedInvocationHandler : ActualInvocationHandler<R, arglist...> {
+
+ virtual ~MatchedInvocationHandler() = default;
+
+ MatchedInvocationHandler(typename ActualInvocation<arglist...>::Matcher *matcher,
+ ActualInvocationHandler<R, arglist...> *invocationHandler) :
+ _matcher{matcher}, _invocationHandler{invocationHandler} {
+ }
+
+ virtual R handleMethodInvocation(ArgumentsTuple<arglist...> & args) override
+ {
+ Destructible &destructable = *_invocationHandler;
+ ActualInvocationHandler<R, arglist...> &invocationHandler = dynamic_cast<ActualInvocationHandler<R, arglist...> &>(destructable);
+ return invocationHandler.handleMethodInvocation(args);
+ }
+
+ typename ActualInvocation<arglist...>::Matcher &getMatcher() const {
+ Destructible &destructable = *_matcher;
+ typename ActualInvocation<arglist...>::Matcher &matcher = dynamic_cast<typename ActualInvocation<arglist...>::Matcher &>(destructable);
+ return matcher;
+ }
+
+ private:
+ std::shared_ptr<Destructible> _matcher;
+ std::shared_ptr<Destructible> _invocationHandler;
+ };
+
+
+ FakeitContext &_fakeit;
+ MethodInfo _method;
+
+ std::vector<std::shared_ptr<Destructible>> _invocationHandlers;
+ std::vector<std::shared_ptr<Destructible>> _actualInvocations;
+
+ MatchedInvocationHandler *buildMatchedInvocationHandler(
+ typename ActualInvocation<arglist...>::Matcher *invocationMatcher,
+ ActualInvocationHandler<R, arglist...> *invocationHandler) {
+ return new MatchedInvocationHandler(invocationMatcher, invocationHandler);
+ }
+
+ MatchedInvocationHandler *getInvocationHandlerForActualArgs(ActualInvocation<arglist...> &invocation) {
+ for (auto i = _invocationHandlers.rbegin(); i != _invocationHandlers.rend(); ++i) {
+ std::shared_ptr<Destructible> curr = *i;
+ Destructible &destructable = *curr;
+ MatchedInvocationHandler &im = asMatchedInvocationHandler(destructable);
+ if (im.getMatcher().matches(invocation)) {
+ return &im;
+ }
+ }
+ return nullptr;
+ }
+
+ MatchedInvocationHandler &asMatchedInvocationHandler(Destructible &destructable) {
+ MatchedInvocationHandler &im = dynamic_cast<MatchedInvocationHandler &>(destructable);
+ return im;
+ }
+
+ ActualInvocation<arglist...> &asActualInvocation(Destructible &destructable) const {
+ ActualInvocation<arglist...> &invocation = dynamic_cast<ActualInvocation<arglist...> &>(destructable);
+ return invocation;
+ }
+
+ public:
+
+ RecordedMethodBody(FakeitContext &fakeit, std::string name) :
+ _fakeit(fakeit), _method{MethodInfo::nextMethodOrdinal(), name} { }
+
+ virtual ~RecordedMethodBody() NO_THROWS {
+ }
+
+ MethodInfo &getMethod() {
+ return _method;
+ }
+
+ bool isOfMethod(MethodInfo &method) {
+
+ return method.id() == _method.id();
+ }
+
+ void addMethodInvocationHandler(typename ActualInvocation<arglist...>::Matcher *matcher,
+ ActualInvocationHandler<R, arglist...> *invocationHandler) {
+ ActualInvocationHandler<R, arglist...> *mock = buildMatchedInvocationHandler(matcher, invocationHandler);
+ std::shared_ptr<Destructible> destructable{mock};
+ _invocationHandlers.push_back(destructable);
+ }
+
+ void reset() {
+ _invocationHandlers.clear();
+ _actualInvocations.clear();
+ }
+
+ void clear() override {
+ _actualInvocations.clear();
+ }
+
+ R handleMethodInvocation(const typename fakeit::production_arg<arglist>::type... args) override {
+ unsigned int ordinal = Invocation::nextInvocationOrdinal();
+ MethodInfo &method = this->getMethod();
+ auto actualInvocation = new ActualInvocation<arglist...>(ordinal, method, std::forward<const typename fakeit::production_arg<arglist>::type>(args)...);
+
+
+ std::shared_ptr<Destructible> actualInvocationDtor{actualInvocation};
+
+ auto invocationHandler = getInvocationHandlerForActualArgs(*actualInvocation);
+ if (invocationHandler) {
+ auto &matcher = invocationHandler->getMatcher();
+ actualInvocation->setActualMatcher(&matcher);
+ _actualInvocations.push_back(actualInvocationDtor);
+ try {
+ return invocationHandler->handleMethodInvocation(actualInvocation->getActualArguments());
+ } catch (NoMoreRecordedActionException &) {
+ }
+ }
+
+ UnexpectedMethodCallEvent event(UnexpectedType::Unmatched, *actualInvocation);
+ _fakeit.handle(event);
+ std::string format{_fakeit.format(event)};
+ UnexpectedMethodCallException e(format);
+ throw e;
+ }
+
+ void scanActualInvocations(const std::function<void(ActualInvocation<arglist...> &)> &scanner) {
+ for (auto destructablePtr : _actualInvocations) {
+ ActualInvocation<arglist...> &invocation = asActualInvocation(*destructablePtr);
+ scanner(invocation);
+ }
+ }
+
+ void getActualInvocations(std::unordered_set<Invocation *> &into) const override {
+ for (auto destructablePtr : _actualInvocations) {
+ Invocation &invocation = asActualInvocation(*destructablePtr);
+ into.insert(&invocation);
+ }
+ }
+
+ void setMethodDetails(const std::string &mockName, const std::string &methodName) {
+ const std::string fullName{mockName + "." + methodName};
+ _method.setName(fullName);
+ }
+
+ };
+
+}
+#include <functional>
+#include <type_traits>
+#include <stdexcept>
+#include <utility>
+#include <functional>
+#include <type_traits>
+
+namespace fakeit {
+
+ struct Quantity {
+ Quantity(const int q) :
+ quantity(q) {
+ }
+
+ const int quantity;
+ } static Once(1);
+
+ template<typename R>
+ struct Quantifier : public Quantity {
+ Quantifier(const int q, const R &val) :
+ Quantity(q), value(val) {
+ }
+
+ const R &value;
+ };
+
+ template<>
+ struct Quantifier<void> : public Quantity {
+ explicit Quantifier(const int q) :
+ Quantity(q) {
+ }
+ };
+
+ struct QuantifierFunctor : public Quantifier<void> {
+ QuantifierFunctor(const int q) :
+ Quantifier<void>(q) {
+ }
+
+ template<typename R>
+ Quantifier<R> operator()(const R &value) {
+ return Quantifier<R>(quantity, value);
+ }
+ };
+
+ template<int q>
+ struct Times : public Quantity {
+
+ Times<q>() : Quantity(q) { }
+
+ template<typename R>
+ static Quantifier<R> of(const R &value) {
+ return Quantifier<R>(q, value);
+ }
+
+ static Quantifier<void> Void() {
+ return Quantifier<void>(q);
+ }
+ };
+
+#if defined (__GNUG__) || (_MSC_VER >= 1900)
+
+ inline QuantifierFunctor operator
+ ""
+
+ _Times(unsigned long long n) {
+ return QuantifierFunctor((int) n);
+ }
+
+ inline QuantifierFunctor operator
+ ""
+
+ _Time(unsigned long long n) {
+ if (n != 1)
+ throw std::invalid_argument("Only 1_Time is supported. Use X_Times (with s) if X is bigger than 1");
+ return QuantifierFunctor((int) n);
+ }
+
+#endif
+
+}
+#include <functional>
+#include <atomic>
+#include <tuple>
+#include <type_traits>
+
+
+namespace fakeit {
+
+ template<typename R, typename ... arglist>
+ struct Action : Destructible {
+ virtual R invoke(const ArgumentsTuple<arglist...> &) = 0;
+
+ virtual bool isDone() = 0;
+ };
+
+ template<typename R, typename ... arglist>
+ struct Repeat : Action<R, arglist...> {
+ virtual ~Repeat() = default;
+
+ Repeat(std::function<R(typename fakeit::test_arg<arglist>::type...)> func) :
+ f(func), times(1) {
+ }
+
+ Repeat(std::function<R(typename fakeit::test_arg<arglist>::type...)> func, long t) :
+ f(func), times(t) {
+ }
+
+ virtual R invoke(const ArgumentsTuple<arglist...> & args) override {
+ times--;
+ return TupleDispatcher::invoke<R, arglist...>(f, args);
+ }
+
+ virtual bool isDone() override {
+ return times == 0;
+ }
+
+ private:
+ std::function<R(typename fakeit::test_arg<arglist>::type...)> f;
+ long times;
+ };
+
+ template<typename R, typename ... arglist>
+ struct RepeatForever : public Action<R, arglist...> {
+
+ virtual ~RepeatForever() = default;
+
+ RepeatForever(std::function<R(typename fakeit::test_arg<arglist>::type...)> func) :
+ f(func) {
+ }
+
+ virtual R invoke(const ArgumentsTuple<arglist...> & args) override {
+ return TupleDispatcher::invoke<R, arglist...>(f, args);
+ }
+
+ virtual bool isDone() override {
+ return false;
+ }
+
+ private:
+ std::function<R(typename fakeit::test_arg<arglist>::type...)> f;
+ };
+
+ template<typename R, typename ... arglist>
+ struct ReturnDefaultValue : public Action<R, arglist...> {
+ virtual ~ReturnDefaultValue() = default;
+
+ virtual R invoke(const ArgumentsTuple<arglist...> &) override {
+ return DefaultValue<R>::value();
+ }
+
+ virtual bool isDone() override {
+ return false;
+ }
+ };
+
+ template<typename R, typename ... arglist>
+ struct ReturnDelegateValue : public Action<R, arglist...> {
+
+ ReturnDelegateValue(std::function<R(const typename fakeit::test_arg<arglist>::type...)> delegate) : _delegate(delegate) { }
+
+ virtual ~ReturnDelegateValue() = default;
+
+ virtual R invoke(const ArgumentsTuple<arglist...> & args) override {
+ return TupleDispatcher::invoke<R, arglist...>(_delegate, args);
+ }
+
+ virtual bool isDone() override {
+ return false;
+ }
+
+ private:
+ std::function<R(const typename fakeit::test_arg<arglist>::type...)> _delegate;
+ };
+
+}
+
+namespace fakeit {
+
+ template<typename R, typename ... arglist>
+ struct MethodStubbingProgress {
+
+ virtual ~MethodStubbingProgress() THROWS {
+ }
+
+ template<typename U = R>
+ typename std::enable_if<!std::is_reference<U>::value, MethodStubbingProgress<R, arglist...> &>::type
+ Return(const R &r) {
+ return Do([r](const typename fakeit::test_arg<arglist>::type...) -> R { return r; });
+ }
+
+ template<typename U = R>
+ typename std::enable_if<std::is_reference<U>::value, MethodStubbingProgress<R, arglist...> &>::type
+ Return(const R &r) {
+ return Do([&r](const typename fakeit::test_arg<arglist>::type...) -> R { return r; });
+ }
+
+ MethodStubbingProgress<R, arglist...> &
+ Return(const Quantifier<R> &q) {
+ const R &value = q.value;
+ auto method = [value](const arglist &...) -> R { return value; };
+ return DoImpl(new Repeat<R, arglist...>(method, q.quantity));
+ }
+
+ template<typename first, typename second, typename ... tail>
+ MethodStubbingProgress<R, arglist...> &
+ Return(const first &f, const second &s, const tail &... t) {
+ Return(f);
+ return Return(s, t...);
+ }
+
+
+ template<typename U = R>
+ typename std::enable_if<!std::is_reference<U>::value, void>::type
+ AlwaysReturn(const R &r) {
+ return AlwaysDo([r](const typename fakeit::test_arg<arglist>::type...) -> R { return r; });
+ }
+
+ template<typename U = R>
+ typename std::enable_if<std::is_reference<U>::value, void>::type
+ AlwaysReturn(const R &r) {
+ return AlwaysDo([&r](const typename fakeit::test_arg<arglist>::type...) -> R { return r; });
+ }
+
+ MethodStubbingProgress<R, arglist...> &
+ Return() {
+ return Do([](const typename fakeit::test_arg<arglist>::type...) -> R { return DefaultValue<R>::value(); });
+ }
+
+ void AlwaysReturn() {
+ return AlwaysDo([](const typename fakeit::test_arg<arglist>::type...) -> R { return DefaultValue<R>::value(); });
+ }
+
+ template<typename E>
+ MethodStubbingProgress<R, arglist...> &Throw(const E &e) {
+ return Do([e](const typename fakeit::test_arg<arglist>::type...) -> R { throw e; });
+ }
+
+ template<typename E>
+ MethodStubbingProgress<R, arglist...> &
+ Throw(const Quantifier<E> &q) {
+ const E &value = q.value;
+ auto method = [value](const arglist &...) -> R { throw value; };
+ return DoImpl(new Repeat<R, arglist...>(method, q.quantity));
+ }
+
+ template<typename first, typename second, typename ... tail>
+ MethodStubbingProgress<R, arglist...> &
+ Throw(const first &f, const second &s, const tail &... t) {
+ Throw(f);
+ return Throw(s, t...);
+ }
+
+ template<typename E>
+ void AlwaysThrow(const E &e) {
+ return AlwaysDo([e](const typename fakeit::test_arg<arglist>::type...) -> R { throw e; });
+ }
+
+ virtual MethodStubbingProgress<R, arglist...> &
+ Do(std::function<R(const typename fakeit::test_arg<arglist>::type...)> method) {
+ return DoImpl(new Repeat<R, arglist...>(method));
+ }
+
+ template<typename F>
+ MethodStubbingProgress<R, arglist...> &
+ Do(const Quantifier<F> &q) {
+ return DoImpl(new Repeat<R, arglist...>(q.value, q.quantity));
+ }
+
+ template<typename first, typename second, typename ... tail>
+ MethodStubbingProgress<R, arglist...> &
+ Do(const first &f, const second &s, const tail &... t) {
+ Do(f);
+ return Do(s, t...);
+ }
+
+ virtual void AlwaysDo(std::function<R(const typename fakeit::test_arg<arglist>::type...)> method) {
+ DoImpl(new RepeatForever<R, arglist...>(method));
+ }
+
+ protected:
+
+ virtual MethodStubbingProgress<R, arglist...> &DoImpl(Action<R, arglist...> *action) = 0;
+
+ private:
+ MethodStubbingProgress &operator=(const MethodStubbingProgress &other) = delete;
+ };
+
+
+ template<typename ... arglist>
+ struct MethodStubbingProgress<void, arglist...> {
+
+ virtual ~MethodStubbingProgress() THROWS {
+ }
+
+ MethodStubbingProgress<void, arglist...> &Return() {
+ auto lambda = [](const typename fakeit::test_arg<arglist>::type...) -> void {
+ return DefaultValue<void>::value();
+ };
+ return Do(lambda);
+ }
+
+ virtual MethodStubbingProgress<void, arglist...> &Do(
+ std::function<void(const typename fakeit::test_arg<arglist>::type...)> method) {
+ return DoImpl(new Repeat<void, arglist...>(method));
+ }
+
+
+ void AlwaysReturn() {
+ return AlwaysDo([](const typename fakeit::test_arg<arglist>::type...) -> void { return DefaultValue<void>::value(); });
+ }
+
+ MethodStubbingProgress<void, arglist...> &
+ Return(const Quantifier<void> &q) {
+ auto method = [](const arglist &...) -> void { return DefaultValue<void>::value(); };
+ return DoImpl(new Repeat<void, arglist...>(method, q.quantity));
+ }
+
+ template<typename E>
+ MethodStubbingProgress<void, arglist...> &Throw(const E &e) {
+ return Do([e](const typename fakeit::test_arg<arglist>::type...) -> void { throw e; });
+ }
+
+ template<typename E>
+ MethodStubbingProgress<void, arglist...> &
+ Throw(const Quantifier<E> &q) {
+ const E &value = q.value;
+ auto method = [value](const typename fakeit::test_arg<arglist>::type...) -> void { throw value; };
+ return DoImpl(new Repeat<void, arglist...>(method, q.quantity));
+ }
+
+ template<typename first, typename second, typename ... tail>
+ MethodStubbingProgress<void, arglist...> &
+ Throw(const first &f, const second &s, const tail &... t) {
+ Throw(f);
+ return Throw(s, t...);
+ }
+
+ template<typename E>
+ void AlwaysThrow(const E e) {
+ return AlwaysDo([e](const typename fakeit::test_arg<arglist>::type...) -> void { throw e; });
+ }
+
+ template<typename F>
+ MethodStubbingProgress<void, arglist...> &
+ Do(const Quantifier<F> &q) {
+ return DoImpl(new Repeat<void, arglist...>(q.value, q.quantity));
+ }
+
+ template<typename first, typename second, typename ... tail>
+ MethodStubbingProgress<void, arglist...> &
+ Do(const first &f, const second &s, const tail &... t) {
+ Do(f);
+ return Do(s, t...);
+ }
+
+ virtual void AlwaysDo(std::function<void(const typename fakeit::test_arg<arglist>::type...)> method) {
+ DoImpl(new RepeatForever<void, arglist...>(method));
+ }
+
+ protected:
+
+ virtual MethodStubbingProgress<void, arglist...> &DoImpl(Action<void, arglist...> *action) = 0;
+
+ private:
+ MethodStubbingProgress &operator=(const MethodStubbingProgress &other) = delete;
+ };
+
+
+}
+#include <vector>
+#include <functional>
+
+namespace fakeit {
+
+ class Finally {
+ private:
+ std::function<void()> _finallyClause;
+
+ Finally(const Finally &);
+
+ Finally &operator=(const Finally &);
+
+ public:
+ explicit Finally(std::function<void()> f) :
+ _finallyClause(f) {
+ }
+
+ ~Finally() {
+ _finallyClause();
+ }
+ };
+}
+
+namespace fakeit {
+
+
+ template<typename R, typename ... arglist>
+ struct ActionSequence : ActualInvocationHandler<R,arglist...> {
+
+ ActionSequence() {
+ clear();
+ }
+
+ void AppendDo(Action<R, arglist...> *action) {
+ append(action);
+ }
+
+ virtual R handleMethodInvocation(ArgumentsTuple<arglist...> & args) override
+ {
+ std::shared_ptr<Destructible> destructablePtr = _recordedActions.front();
+ Destructible &destructable = *destructablePtr;
+ Action<R, arglist...> &action = dynamic_cast<Action<R, arglist...> &>(destructable);
+ std::function<void()> finallyClause = [&]() -> void {
+ if (action.isDone())
+ _recordedActions.erase(_recordedActions.begin());
+ };
+ Finally onExit(finallyClause);
+ return action.invoke(args);
+ }
+
+ private:
+
+ struct NoMoreRecordedAction : Action<R, arglist...> {
+
+
+
+
+
+
+
+ virtual R invoke(const ArgumentsTuple<arglist...> &) override {
+ throw NoMoreRecordedActionException();
+ }
+
+ virtual bool isDone() override {
+ return false;
+ }
+ };
+
+ void append(Action<R, arglist...> *action) {
+ std::shared_ptr<Destructible> destructable{action};
+ _recordedActions.insert(_recordedActions.end() - 1, destructable);
+ }
+
+ void clear() {
+ _recordedActions.clear();
+ auto actionPtr = std::shared_ptr<Destructible> {new NoMoreRecordedAction()};
+ _recordedActions.push_back(actionPtr);
+ }
+
+ std::vector<std::shared_ptr<Destructible>> _recordedActions;
+ };
+
+}
+
+namespace fakeit {
+
+ template<typename C, typename DATA_TYPE>
+ class DataMemberStubbingRoot {
+ private:
+
+ public:
+ DataMemberStubbingRoot(const DataMemberStubbingRoot &) = default;
+
+ DataMemberStubbingRoot() = default;
+
+ void operator=(const DATA_TYPE&) {
+ }
+ };
+
+}
+#include <functional>
+#include <utility>
+#include <type_traits>
+#include <tuple>
+#include <memory>
+#include <vector>
+#include <unordered_set>
+#include <set>
+#include <iosfwd>
+
+namespace fakeit {
+
+ struct Xaction {
+ virtual void commit() = 0;
+ };
+}
+
+namespace fakeit {
+
+
+ template<typename R, typename ... arglist>
+ struct SpyingContext : Xaction {
+ virtual void appendAction(Action<R, arglist...> *action) = 0;
+
+ virtual std::function<R(arglist&...)> getOriginalMethod() = 0;
+ };
+}
+namespace fakeit {
+
+
+ template<typename R, typename ... arglist>
+ struct StubbingContext : public Xaction {
+ virtual void appendAction(Action<R, arglist...> *action) = 0;
+ };
+}
+#include <functional>
+#include <type_traits>
+#include <tuple>
+#include <memory>
+#include <vector>
+#include <unordered_set>
+
+
+namespace fakeit {
+
+ template<unsigned int index, typename ... arglist>
+ class MatchersCollector {
+
+ std::vector<Destructible *> &_matchers;
+
+ public:
+
+
+ template<std::size_t N>
+ using ArgType = typename std::tuple_element<N, std::tuple<arglist...>>::type;
+
+ template<std::size_t N>
+ using NakedArgType = typename naked_type<ArgType<index>>::type;
+
+ template<std::size_t N>
+ using ArgMatcherCreatorType = decltype(std::declval<TypedMatcherCreator<NakedArgType<N>>>());
+
+ MatchersCollector(std::vector<Destructible *> &matchers)
+ : _matchers(matchers) {
+ }
+
+ void CollectMatchers() {
+ }
+
+ template<typename Head>
+ typename std::enable_if<
+ std::is_constructible<NakedArgType<index>, Head>::value, void>
+ ::type CollectMatchers(const Head &value) {
+
+ TypedMatcher<NakedArgType<index>> *d = Eq<NakedArgType<index>>(value).createMatcher();
+ _matchers.push_back(d);
+ }
+
+ template<typename Head, typename ...Tail>
+ typename std::enable_if<
+ std::is_constructible<NakedArgType<index>, Head>::value
+ , void>
+ ::type CollectMatchers(const Head &head, const Tail &... tail) {
+ CollectMatchers(head);
+ MatchersCollector<index + 1, arglist...> c(_matchers);
+ c.CollectMatchers(tail...);
+ }
+
+ template<typename Head>
+ typename std::enable_if<
+ std::is_base_of<TypedMatcherCreator<NakedArgType<index>>, Head>::value, void>
+ ::type CollectMatchers(const Head &creator) {
+ TypedMatcher<NakedArgType<index>> *d = creator.createMatcher();
+ _matchers.push_back(d);
+ }
+
+ template<typename Head, typename ...Tail>
+
+ typename std::enable_if<
+ std::is_base_of<TypedMatcherCreator<NakedArgType<index>>, Head>::value, void>
+ ::type CollectMatchers(const Head &head, const Tail &... tail) {
+ CollectMatchers(head);
+ MatchersCollector<index + 1, arglist...> c(_matchers);
+ c.CollectMatchers(tail...);
+ }
+
+ template<typename Head>
+ typename std::enable_if<
+ std::is_same<AnyMatcher, Head>::value, void>
+ ::type CollectMatchers(const Head &) {
+ TypedMatcher<NakedArgType<index>> *d = Any<NakedArgType<index>>().createMatcher();
+ _matchers.push_back(d);
+ }
+
+ template<typename Head, typename ...Tail>
+ typename std::enable_if<
+ std::is_same<AnyMatcher, Head>::value, void>
+ ::type CollectMatchers(const Head &head, const Tail &... tail) {
+ CollectMatchers(head);
+ MatchersCollector<index + 1, arglist...> c(_matchers);
+ c.CollectMatchers(tail...);
+ }
+
+ };
+
+}
+
+namespace fakeit {
+
+ template<typename R, typename ... arglist>
+ class MethodMockingContext :
+ public Sequence,
+ public ActualInvocationsSource,
+ public virtual StubbingContext<R, arglist...>,
+ public virtual SpyingContext<R, arglist...>,
+ private Invocation::Matcher {
+ public:
+
+ struct Context : Destructible {
+
+
+ virtual typename std::function<R(arglist&...)> getOriginalMethod() = 0;
+
+ virtual std::string getMethodName() = 0;
+
+ virtual void addMethodInvocationHandler(typename ActualInvocation<arglist...>::Matcher *matcher,
+ ActualInvocationHandler<R, arglist...> *invocationHandler) = 0;
+
+ virtual void scanActualInvocations(const std::function<void(ActualInvocation<arglist...> &)> &scanner) = 0;
+
+ virtual void setMethodDetails(std::string mockName, std::string methodName) = 0;
+
+ virtual bool isOfMethod(MethodInfo &method) = 0;
+
+ virtual ActualInvocationsSource &getInvolvedMock() = 0;
+ };
+
+ private:
+ class Implementation {
+
+ Context *_stubbingContext;
+ ActionSequence<R, arglist...> *_recordedActionSequence;
+ typename ActualInvocation<arglist...>::Matcher *_invocationMatcher;
+ bool _commited;
+
+ Context &getStubbingContext() const {
+ return *_stubbingContext;
+ }
+
+ public:
+
+ Implementation(Context *stubbingContext)
+ : _stubbingContext(stubbingContext),
+ _recordedActionSequence(new ActionSequence<R, arglist...>()),
+ _invocationMatcher
+ {
+ new DefaultInvocationMatcher<arglist...>()}, _commited(false) {
+ }
+
+ ~Implementation() {
+ delete _stubbingContext;
+ if (!_commited) {
+
+ delete _recordedActionSequence;
+ delete _invocationMatcher;
+ }
+ }
+
+ ActionSequence<R, arglist...> &getRecordedActionSequence() {
+ return *_recordedActionSequence;
+ }
+
+ std::string format() const {
+ std::string s = getStubbingContext().getMethodName();
+ s += _invocationMatcher->format();
+ return s;
+ }
+
+ void getActualInvocations(std::unordered_set<Invocation *> &into) const {
+ auto scanner = [&](ActualInvocation<arglist...> &a) {
+ if (_invocationMatcher->matches(a)) {
+ into.insert(&a);
+ }
+ };
+ getStubbingContext().scanActualInvocations(scanner);
+ }
+
+
+ bool matches(Invocation &invocation) {
+ MethodInfo &actualMethod = invocation.getMethod();
+ if (!getStubbingContext().isOfMethod(actualMethod)) {
+ return false;
+ }
+
+ ActualInvocation<arglist...> &actualInvocation = dynamic_cast<ActualInvocation<arglist...> &>(invocation);
+ return _invocationMatcher->matches(actualInvocation);
+ }
+
+ void commit() {
+ getStubbingContext().addMethodInvocationHandler(_invocationMatcher, _recordedActionSequence);
+ _commited = true;
+ }
+
+ void appendAction(Action<R, arglist...> *action) {
+ getRecordedActionSequence().AppendDo(action);
+ }
+
+ void setMethodBodyByAssignment(std::function<R(const typename fakeit::test_arg<arglist>::type...)> method) {
+ appendAction(new RepeatForever<R, arglist...>(method));
+ commit();
+ }
+
+ void setMethodDetails(std::string mockName, std::string methodName) {
+ getStubbingContext().setMethodDetails(mockName, methodName);
+ }
+
+ void getInvolvedMocks(std::vector<ActualInvocationsSource *> &into) const {
+ into.push_back(&getStubbingContext().getInvolvedMock());
+ }
+
+ typename std::function<R(arglist &...)> getOriginalMethod() {
+ return getStubbingContext().getOriginalMethod();
+ }
+
+ void setInvocationMatcher(typename ActualInvocation<arglist...>::Matcher *matcher) {
+ delete _invocationMatcher;
+ _invocationMatcher = matcher;
+ }
+ };
+
+ protected:
+
+ MethodMockingContext(Context *stubbingContext)
+ : _impl{new Implementation(stubbingContext)} {
+ }
+
+ MethodMockingContext(MethodMockingContext &) = default;
+
+
+
+ MethodMockingContext(MethodMockingContext &&other)
+ : _impl(std::move(other._impl)) {
+ }
+
+ virtual ~MethodMockingContext() NO_THROWS { }
+
+ std::string format() const override {
+ return _impl->format();
+ }
+
+ unsigned int size() const override {
+ return 1;
+ }
+
+
+ void getInvolvedMocks(std::vector<ActualInvocationsSource *> &into) const override {
+ _impl->getInvolvedMocks(into);
+ }
+
+ void getExpectedSequence(std::vector<Invocation::Matcher *> &into) const override {
+ const Invocation::Matcher *b = this;
+ Invocation::Matcher *c = const_cast<Invocation::Matcher *>(b);
+ into.push_back(c);
+ }
+
+
+ void getActualInvocations(std::unordered_set<Invocation *> &into) const override {
+ _impl->getActualInvocations(into);
+ }
+
+
+ bool matches(Invocation &invocation) override {
+ return _impl->matches(invocation);
+ }
+
+ void commit() override {
+ _impl->commit();
+ }
+
+ void setMethodDetails(std::string mockName, std::string methodName) {
+ _impl->setMethodDetails(mockName, methodName);
+ }
+
+ void setMatchingCriteria(std::function<bool(arglist &...)> predicate) {
+ typename ActualInvocation<arglist...>::Matcher *matcher{
+ new UserDefinedInvocationMatcher<arglist...>(predicate)};
+ _impl->setInvocationMatcher(matcher);
+ }
+
+ void setMatchingCriteria(const std::vector<Destructible *> &matchers) {
+ typename ActualInvocation<arglist...>::Matcher *matcher{
+ new ArgumentsMatcherInvocationMatcher<arglist...>(matchers)};
+ _impl->setInvocationMatcher(matcher);
+ }
+
+
+ void appendAction(Action<R, arglist...> *action) override {
+ _impl->appendAction(action);
+ }
+
+ void setMethodBodyByAssignment(std::function<R(const typename fakeit::test_arg<arglist>::type...)> method) {
+ _impl->setMethodBodyByAssignment(method);
+ }
+
+ template<class ...matcherCreators, class = typename std::enable_if<
+ sizeof...(matcherCreators) == sizeof...(arglist)>::type>
+ void setMatchingCriteria(const matcherCreators &... matcherCreator) {
+ std::vector<Destructible *> matchers;
+
+ MatchersCollector<0, arglist...> c(matchers);
+ c.CollectMatchers(matcherCreator...);
+
+ MethodMockingContext<R, arglist...>::setMatchingCriteria(matchers);
+ }
+
+ private:
+
+ typename std::function<R(arglist&...)> getOriginalMethod() override {
+ return _impl->getOriginalMethod();
+ }
+
+ std::shared_ptr<Implementation> _impl;
+ };
+
+ template<typename R, typename ... arglist>
+ class MockingContext :
+ public MethodMockingContext<R, arglist...> {
+ MockingContext &operator=(const MockingContext &) = delete;
+
+ public:
+
+ MockingContext(typename MethodMockingContext<R, arglist...>::Context *stubbingContext)
+ : MethodMockingContext<R, arglist...>(stubbingContext) {
+ }
+
+ MockingContext(MockingContext &) = default;
+
+ MockingContext(MockingContext &&other)
+ : MethodMockingContext<R, arglist...>(std::move(other)) {
+ }
+
+ MockingContext<R, arglist...> &setMethodDetails(std::string mockName, std::string methodName) {
+ MethodMockingContext<R, arglist...>::setMethodDetails(mockName, methodName);
+ return *this;
+ }
+
+ MockingContext<R, arglist...> &Using(const arglist &... args) {
+ MethodMockingContext<R, arglist...>::setMatchingCriteria(args...);
+ return *this;
+ }
+
+ template<class ...arg_matcher>
+ MockingContext<R, arglist...> &Using(const arg_matcher &... arg_matchers) {
+ MethodMockingContext<R, arglist...>::setMatchingCriteria(arg_matchers...);
+ return *this;
+ }
+
+ MockingContext<R, arglist...> &Matching(std::function<bool(arglist &...)> matcher) {
+ MethodMockingContext<R, arglist...>::setMatchingCriteria(matcher);
+ return *this;
+ }
+
+ MockingContext<R, arglist...> &operator()(const arglist &... args) {
+ MethodMockingContext<R, arglist...>::setMatchingCriteria(args...);
+ return *this;
+ }
+
+ MockingContext<R, arglist...> &operator()(std::function<bool(arglist &...)> matcher) {
+ MethodMockingContext<R, arglist...>::setMatchingCriteria(matcher);
+ return *this;
+ }
+
+ void operator=(std::function<R(arglist &...)> method) {
+ MethodMockingContext<R, arglist...>::setMethodBodyByAssignment(method);
+ }
+
+ template<typename U = R>
+ typename std::enable_if<!std::is_reference<U>::value, void>::type operator=(const R &r) {
+ auto method = [r](const typename fakeit::test_arg<arglist>::type...) -> R { return r; };
+ MethodMockingContext<R, arglist...>::setMethodBodyByAssignment(method);
+ }
+
+ template<typename U = R>
+ typename std::enable_if<std::is_reference<U>::value, void>::type operator=(const R &r) {
+ auto method = [&r](const typename fakeit::test_arg<arglist>::type...) -> R { return r; };
+ MethodMockingContext<R, arglist...>::setMethodBodyByAssignment(method);
+ }
+ };
+
+ template<typename ... arglist>
+ class MockingContext<void, arglist...> :
+ public MethodMockingContext<void, arglist...> {
+ MockingContext &operator=(const MockingContext &) = delete;
+
+ public:
+
+ MockingContext(typename MethodMockingContext<void, arglist...>::Context *stubbingContext)
+ : MethodMockingContext<void, arglist...>(stubbingContext) {
+ }
+
+ MockingContext(MockingContext &) = default;
+
+ MockingContext(MockingContext &&other)
+ : MethodMockingContext<void, arglist...>(std::move(other)) {
+ }
+
+ MockingContext<void, arglist...> &setMethodDetails(std::string mockName, std::string methodName) {
+ MethodMockingContext<void, arglist...>::setMethodDetails(mockName, methodName);
+ return *this;
+ }
+
+ MockingContext<void, arglist...> &Using(const arglist &... args) {
+ MethodMockingContext<void, arglist...>::setMatchingCriteria(args...);
+ return *this;
+ }
+
+ template<class ...arg_matcher>
+ MockingContext<void, arglist...> &Using(const arg_matcher &... arg_matchers) {
+ MethodMockingContext<void, arglist...>::setMatchingCriteria(arg_matchers...);
+ return *this;
+ }
+
+ MockingContext<void, arglist...> &Matching(std::function<bool(arglist &...)> matcher) {
+ MethodMockingContext<void, arglist...>::setMatchingCriteria(matcher);
+ return *this;
+ }
+
+ MockingContext<void, arglist...> &operator()(const arglist &... args) {
+ MethodMockingContext<void, arglist...>::setMatchingCriteria(args...);
+ return *this;
+ }
+
+ MockingContext<void, arglist...> &operator()(std::function<bool(arglist &...)> matcher) {
+ MethodMockingContext<void, arglist...>::setMatchingCriteria(matcher);
+ return *this;
+ }
+
+ void operator=(std::function<void(arglist &...)> method) {
+ MethodMockingContext<void, arglist...>::setMethodBodyByAssignment(method);
+ }
+
+ };
+
+ class DtorMockingContext : public MethodMockingContext<void> {
+ public:
+
+ DtorMockingContext(MethodMockingContext<void>::Context *stubbingContext)
+ : MethodMockingContext<void>(stubbingContext) {
+ }
+
+ DtorMockingContext(DtorMockingContext &other) : MethodMockingContext<void>(other) {
+ }
+
+ DtorMockingContext(DtorMockingContext &&other) : MethodMockingContext<void>(std::move(other)) {
+ }
+
+ void operator=(std::function<void()> method) {
+ MethodMockingContext<void>::setMethodBodyByAssignment(method);
+ }
+
+ DtorMockingContext &setMethodDetails(std::string mockName, std::string methodName) {
+ MethodMockingContext<void>::setMethodDetails(mockName, methodName);
+ return *this;
+ }
+ };
+
+}
+
+namespace fakeit {
+
+
+ template<typename C, typename ... baseclasses>
+ class MockImpl : private MockObject<C>, public virtual ActualInvocationsSource {
+ public:
+
+ MockImpl(FakeitContext &fakeit, C &obj)
+ : MockImpl<C, baseclasses...>(fakeit, obj, true) {
+ }
+
+ MockImpl(FakeitContext &fakeit)
+ : MockImpl<C, baseclasses...>(fakeit, *(createFakeInstance()), false){
+ FakeObject<C, baseclasses...> *fake = asFakeObject(_instanceOwner.get());
+ fake->getVirtualTable().setCookie(1, this);
+ }
+
+ virtual ~MockImpl() NO_THROWS {
+ _proxy.detach();
+ }
+
+
+ void getActualInvocations(std::unordered_set<Invocation *> &into) const override {
+ std::vector<ActualInvocationsSource *> vec;
+ _proxy.getMethodMocks(vec);
+ for (ActualInvocationsSource *s : vec) {
+ s->getActualInvocations(into);
+ }
+ }
+
+ void initDataMembersIfOwner()
+ {
+ if (isOwner()) {
+ FakeObject<C, baseclasses...> *fake = asFakeObject(_instanceOwner.get());
+ fake->initializeDataMembersArea();
+ }
+ }
+
+ void reset() {
+ _proxy.Reset();
+ initDataMembersIfOwner();
+ }
+
+ void clear()
+ {
+ std::vector<ActualInvocationsContainer *> vec;
+ _proxy.getMethodMocks(vec);
+ for (ActualInvocationsContainer *s : vec) {
+ s->clear();
+ }
+ initDataMembersIfOwner();
+ }
+
+ virtual C &get() override {
+ return _proxy.get();
+ }
+
+ virtual FakeitContext &getFakeIt() override {
+ return _fakeit;
+ }
+
+ template<class DATA_TYPE, typename T, typename ... arglist, class = typename std::enable_if<std::is_base_of<T, C>::value>::type>
+ DataMemberStubbingRoot<C, DATA_TYPE> stubDataMember(DATA_TYPE T::*member, const arglist &... ctorargs) {
+ _proxy.stubDataMember(member, ctorargs...);
+ return DataMemberStubbingRoot<T, DATA_TYPE>();
+ }
+
+ template<int id, typename R, typename T, typename ... arglist, class = typename std::enable_if<std::is_base_of<T, C>::value>::type>
+ MockingContext<R, arglist...> stubMethod(R(T::*vMethod)(arglist...)) {
+ return MockingContext<R, arglist...>(new UniqueMethodMockingContextImpl < id, R, arglist... >
+ (*this, vMethod));
+ }
+
+ DtorMockingContext stubDtor() {
+ return DtorMockingContext(new DtorMockingContextImpl(*this));
+ }
+
+
+
+
+
+
+
+ private:
+
+
+
+
+
+
+
+
+
+ std::shared_ptr<FakeObject<C, baseclasses...>> _instanceOwner;
+ DynamicProxy<C, baseclasses...> _proxy;
+ FakeitContext &_fakeit;
+
+ MockImpl(FakeitContext &fakeit, C &obj, bool isSpy)
+ : _instanceOwner(isSpy ? nullptr : asFakeObject(&obj))
+ , _proxy{obj}
+ , _fakeit(fakeit) {}
+
+ static FakeObject<C, baseclasses...>* asFakeObject(void* instance){
+ return reinterpret_cast<FakeObject<C, baseclasses...> *>(instance);
+ }
+
+ template<typename R, typename ... arglist>
+ class MethodMockingContextBase : public MethodMockingContext<R, arglist...>::Context {
+ protected:
+ MockImpl<C, baseclasses...> &_mock;
+
+ virtual RecordedMethodBody<R, arglist...> &getRecordedMethodBody() = 0;
+
+ public:
+ MethodMockingContextBase(MockImpl<C, baseclasses...> &mock) : _mock(mock) { }
+
+ virtual ~MethodMockingContextBase() = default;
+
+ void addMethodInvocationHandler(typename ActualInvocation<arglist...>::Matcher *matcher,
+ ActualInvocationHandler<R, arglist...> *invocationHandler) {
+ getRecordedMethodBody().addMethodInvocationHandler(matcher, invocationHandler);
+ }
+
+ void scanActualInvocations(const std::function<void(ActualInvocation<arglist...> &)> &scanner) {
+ getRecordedMethodBody().scanActualInvocations(scanner);
+ }
+
+ void setMethodDetails(std::string mockName, std::string methodName) {
+ getRecordedMethodBody().setMethodDetails(mockName, methodName);
+ }
+
+ bool isOfMethod(MethodInfo &method) {
+ return getRecordedMethodBody().isOfMethod(method);
+ }
+
+ ActualInvocationsSource &getInvolvedMock() {
+ return _mock;
+ }
+
+ std::string getMethodName() {
+ return getRecordedMethodBody().getMethod().name();
+ }
+
+ };
+
+ template<typename R, typename ... arglist>
+ class MethodMockingContextImpl : public MethodMockingContextBase<R, arglist...> {
+ protected:
+
+ R (C::*_vMethod)(arglist...);
+
+ public:
+ virtual ~MethodMockingContextImpl() = default;
+
+ MethodMockingContextImpl(MockImpl<C, baseclasses...> &mock, R (C::*vMethod)(arglist...))
+ : MethodMockingContextBase<R, arglist...>(mock), _vMethod(vMethod) {
+ }
+
+
+ virtual std::function<R(arglist&...)> getOriginalMethod() override {
+ void *mPtr = MethodMockingContextBase<R, arglist...>::_mock.getOriginalMethod(_vMethod);
+ C * instance = &(MethodMockingContextBase<R, arglist...>::_mock.get());
+ return [=](arglist&... args) -> R {
+ auto m = union_cast<typename VTableMethodType<R,arglist...>::type>(mPtr);
+ return m(instance, std::forward<arglist>(args)...);
+ };
+ }
+ };
+
+
+ template<int id, typename R, typename ... arglist>
+ class UniqueMethodMockingContextImpl : public MethodMockingContextImpl<R, arglist...> {
+ protected:
+
+ virtual RecordedMethodBody<R, arglist...> &getRecordedMethodBody() override {
+ return MethodMockingContextBase<R, arglist...>::_mock.template stubMethodIfNotStubbed<id>(
+ MethodMockingContextBase<R, arglist...>::_mock._proxy,
+ MethodMockingContextImpl<R, arglist...>::_vMethod);
+ }
+
+ public:
+
+ UniqueMethodMockingContextImpl(MockImpl<C, baseclasses...> &mock, R (C::*vMethod)(arglist...))
+ : MethodMockingContextImpl<R, arglist...>(mock, vMethod) {
+ }
+ };
+
+ class DtorMockingContextImpl : public MethodMockingContextBase<void> {
+
+ protected:
+
+ virtual RecordedMethodBody<void> &getRecordedMethodBody() override {
+ return MethodMockingContextBase<void>::_mock.stubDtorIfNotStubbed(
+ MethodMockingContextBase<void>::_mock._proxy);
+ }
+
+ public:
+ virtual ~DtorMockingContextImpl() = default;
+
+ DtorMockingContextImpl(MockImpl<C, baseclasses...> &mock)
+ : MethodMockingContextBase<void>(mock) {
+ }
+
+ virtual std::function<void()> getOriginalMethod() override {
+ C &instance = MethodMockingContextBase<void>::_mock.get();
+ return [=, &instance]() -> void {
+ };
+ }
+
+ };
+
+ static MockImpl<C, baseclasses...> *getMockImpl(void *instance) {
+ FakeObject<C, baseclasses...> *fake = asFakeObject(instance);
+ MockImpl<C, baseclasses...> *mock = reinterpret_cast<MockImpl<C, baseclasses...> *>(fake->getVirtualTable().getCookie(
+ 1));
+ return mock;
+ }
+
+ bool isOwner(){ return _instanceOwner != nullptr;}
+
+ void unmockedDtor() {}
+
+ void unmocked() {
+ ActualInvocation<> invocation(Invocation::nextInvocationOrdinal(), UnknownMethod::instance());
+ UnexpectedMethodCallEvent event(UnexpectedType::Unmocked, invocation);
+ auto &fakeit = getMockImpl(this)->_fakeit;
+ fakeit.handle(event);
+
+ std::string format = fakeit.format(event);
+ UnexpectedMethodCallException e(format);
+ throw e;
+ }
+
+ static C *createFakeInstance() {
+ FakeObject<C, baseclasses...> *fake = new FakeObject<C, baseclasses...>();
+ void *unmockedMethodStubPtr = union_cast<void *>(&MockImpl<C, baseclasses...>::unmocked);
+ void *unmockedDtorStubPtr = union_cast<void *>(&MockImpl<C, baseclasses...>::unmockedDtor);
+ fake->getVirtualTable().initAll(unmockedMethodStubPtr);
+ if (VTUtils::hasVirtualDestructor<C>())
+ fake->setDtor(unmockedDtorStubPtr);
+ return reinterpret_cast<C *>(fake);
+ }
+
+ template<typename R, typename ... arglist>
+ void *getOriginalMethod(R (C::*vMethod)(arglist...)) {
+ auto vt = _proxy.getOriginalVT();
+ auto offset = VTUtils::getOffset(vMethod);
+ void *origMethodPtr = vt.getMethod(offset);
+ return origMethodPtr;
+ }
+
+ void *getOriginalDtor() {
+ auto vt = _proxy.getOriginalVT();
+ auto offset = VTUtils::getDestructorOffset<C>();
+ void *origMethodPtr = vt.getMethod(offset);
+ return origMethodPtr;
+ }
+
+ template<unsigned int id, typename R, typename ... arglist>
+ RecordedMethodBody<R, arglist...> &stubMethodIfNotStubbed(DynamicProxy<C, baseclasses...> &proxy,
+ R (C::*vMethod)(arglist...)) {
+ if (!proxy.isMethodStubbed(vMethod)) {
+ proxy.template stubMethod<id>(vMethod, createRecordedMethodBody < R, arglist... > (*this, vMethod));
+ }
+ Destructible *d = proxy.getMethodMock(vMethod);
+ RecordedMethodBody<R, arglist...> *methodMock = dynamic_cast<RecordedMethodBody<R, arglist...> *>(d);
+ return *methodMock;
+ }
+
+ RecordedMethodBody<void> &stubDtorIfNotStubbed(DynamicProxy<C, baseclasses...> &proxy) {
+ if (!proxy.isDtorStubbed()) {
+ proxy.stubDtor(createRecordedDtorBody(*this));
+ }
+ Destructible *d = proxy.getDtorMock();
+ RecordedMethodBody<void> *dtorMock = dynamic_cast<RecordedMethodBody<void> *>(d);
+ return *dtorMock;
+ }
+
+ template<typename R, typename ... arglist>
+ static RecordedMethodBody<R, arglist...> *createRecordedMethodBody(MockObject<C> &mock,
+ R(C::*vMethod)(arglist...)) {
+ return new RecordedMethodBody<R, arglist...>(mock.getFakeIt(), typeid(vMethod).name());
+ }
+
+ static RecordedMethodBody<void> *createRecordedDtorBody(MockObject<C> &mock) {
+ return new RecordedMethodBody<void>(mock.getFakeIt(), "dtor");
+ }
+ };
+}
+namespace fakeit {
+
+ template<typename R, typename... Args>
+ struct Prototype;
+
+ template<typename R, typename... Args>
+ struct Prototype<R(Args...)> {
+
+ typedef R Type(Args...);
+
+ typedef R ConstType(Args...) const;
+
+ template<class C>
+ struct MemberType {
+
+ typedef Type(C::*type);
+ typedef ConstType(C::*cosntType);
+
+ static type get(type t) {
+ return t;
+ }
+
+ static cosntType getconst(cosntType t) {
+ return t;
+ }
+
+ };
+
+ };
+
+ template<int X, typename R, typename C, typename... arglist>
+ struct UniqueMethod {
+ R (C::*method)(arglist...);
+
+ UniqueMethod(R (C::*vMethod)(arglist...)) : method(vMethod) { }
+
+ int uniqueId() {
+ return X;
+ }
+
+
+
+
+ };
+
+}
+
+
+namespace fakeit {
+ namespace internal {
+ }
+ using namespace fakeit::internal;
+
+ template<typename C, typename ... baseclasses>
+ class Mock : public ActualInvocationsSource {
+ MockImpl<C, baseclasses...> impl;
+ public:
+ virtual ~Mock() = default;
+
+ static_assert(std::is_polymorphic<C>::value, "Can only mock a polymorphic type");
+
+ Mock() : impl(Fakeit) {
+ }
+
+ explicit Mock(C &obj) : impl(Fakeit, obj) {
+ }
+
+ virtual C &get() {
+ return impl.get();
+ }
+
+
+
+
+
+ C &operator()() {
+ return get();
+ }
+
+ void Reset() {
+ impl.reset();
+ }
+
+ void ClearInvocationHistory() {
+ impl.clear();
+ }
+
+ template<class DATA_TYPE, typename ... arglist,
+ class = typename std::enable_if<std::is_member_object_pointer<DATA_TYPE C::*>::value>::type>
+ DataMemberStubbingRoot<C, DATA_TYPE> Stub(DATA_TYPE C::* member, const arglist &... ctorargs) {
+ return impl.stubDataMember(member, ctorargs...);
+ }
+
+ template<int id, typename R, typename T, typename ... arglist, class = typename std::enable_if<
+ !std::is_void<R>::value && std::is_base_of<T, C>::value>::type>
+ MockingContext<R, arglist...> stub(R (T::*vMethod)(arglist...) const) {
+ auto methodWithoutConstVolatile = reinterpret_cast<R (T::*)(arglist...)>(vMethod);
+ return impl.template stubMethod<id>(methodWithoutConstVolatile);
+ }
+
+ template<int id, typename R, typename T, typename... arglist, class = typename std::enable_if<
+ !std::is_void<R>::value && std::is_base_of<T, C>::value>::type>
+ MockingContext<R, arglist...> stub(R(T::*vMethod)(arglist...) volatile) {
+ auto methodWithoutConstVolatile = reinterpret_cast<R(T::*)(arglist...)>(vMethod);
+ return impl.template stubMethod<id>(methodWithoutConstVolatile);
+ }
+
+ template<int id, typename R, typename T, typename... arglist, class = typename std::enable_if<
+ !std::is_void<R>::value && std::is_base_of<T, C>::value>::type>
+ MockingContext<R, arglist...> stub(R(T::*vMethod)(arglist...) const volatile) {
+ auto methodWithoutConstVolatile = reinterpret_cast<R(T::*)(arglist...)>(vMethod);
+ return impl.template stubMethod<id>(methodWithoutConstVolatile);
+ }
+
+ template<int id, typename R, typename T, typename... arglist, class = typename std::enable_if<
+ !std::is_void<R>::value && std::is_base_of<T, C>::value>::type>
+ MockingContext<R, arglist...> stub(R(T::*vMethod)(arglist...)) {
+ return impl.template stubMethod<id>(vMethod);
+ }
+
+ template<int id, typename R, typename T, typename... arglist, class = typename std::enable_if<
+ std::is_void<R>::value && std::is_base_of<T, C>::value>::type>
+ MockingContext<void, arglist...> stub(R(T::*vMethod)(arglist...) const) {
+ auto methodWithoutConstVolatile = reinterpret_cast<void (T::*)(arglist...)>(vMethod);
+ return impl.template stubMethod<id>(methodWithoutConstVolatile);
+ }
+
+ template<int id, typename R, typename T, typename... arglist, class = typename std::enable_if<
+ std::is_void<R>::value && std::is_base_of<T, C>::value>::type>
+ MockingContext<void, arglist...> stub(R(T::*vMethod)(arglist...) volatile) {
+ auto methodWithoutConstVolatile = reinterpret_cast<void (T::*)(arglist...)>(vMethod);
+ return impl.template stubMethod<id>(methodWithoutConstVolatile);
+ }
+
+ template<int id, typename R, typename T, typename... arglist, class = typename std::enable_if<
+ std::is_void<R>::value && std::is_base_of<T, C>::value>::type>
+ MockingContext<void, arglist...> stub(R(T::*vMethod)(arglist...) const volatile) {
+ auto methodWithoutConstVolatile = reinterpret_cast<void (T::*)(arglist...)>(vMethod);
+ return impl.template stubMethod<id>(methodWithoutConstVolatile);
+ }
+
+ template<int id, typename R, typename T, typename... arglist, class = typename std::enable_if<
+ std::is_void<R>::value && std::is_base_of<T, C>::value>::type>
+ MockingContext<void, arglist...> stub(R(T::*vMethod)(arglist...)) {
+ auto methodWithoutConstVolatile = reinterpret_cast<void (T::*)(arglist...)>(vMethod);
+ return impl.template stubMethod<id>(methodWithoutConstVolatile);
+ }
+
+ DtorMockingContext dtor() {
+ return impl.stubDtor();
+ }
+
+ void getActualInvocations(std::unordered_set<Invocation *> &into) const override {
+ impl.getActualInvocations(into);
+ }
+
+ };
+
+}
+
+#include <exception>
+
+namespace fakeit {
+
+ class RefCount {
+ private:
+ int count;
+
+ public:
+ void AddRef() {
+ count++;
+ }
+
+ int Release() {
+ return --count;
+ }
+ };
+
+ template<typename T>
+ class smart_ptr {
+ private:
+ T *pData;
+ RefCount *reference;
+
+ public:
+ smart_ptr() : pData(0), reference(0) {
+ reference = new RefCount();
+ reference->AddRef();
+ }
+
+ smart_ptr(T *pValue) : pData(pValue), reference(0) {
+ reference = new RefCount();
+ reference->AddRef();
+ }
+
+ smart_ptr(const smart_ptr<T> &sp) : pData(sp.pData), reference(sp.reference) {
+ reference->AddRef();
+ }
+
+ ~smart_ptr() THROWS {
+ if (reference->Release() == 0) {
+ delete reference;
+ delete pData;
+ }
+ }
+
+ T &operator*() {
+ return *pData;
+ }
+
+ T *operator->() {
+ return pData;
+ }
+
+ smart_ptr<T> &operator=(const smart_ptr<T> &sp) {
+ if (this != &sp) {
+
+
+ if (reference->Release() == 0) {
+ delete reference;
+ delete pData;
+ }
+
+
+
+ pData = sp.pData;
+ reference = sp.reference;
+ reference->AddRef();
+ }
+ return *this;
+ }
+ };
+
+}
+
+namespace fakeit {
+
+ class WhenFunctor {
+
+ struct StubbingChange {
+
+ friend class WhenFunctor;
+
+ virtual ~StubbingChange() THROWS {
+
+ if (std::uncaught_exception()) {
+ return;
+ }
+
+ _xaction.commit();
+ }
+
+ StubbingChange(StubbingChange &other) :
+ _xaction(other._xaction) {
+ }
+
+ private:
+
+ StubbingChange(Xaction &xaction)
+ : _xaction(xaction) {
+ }
+
+ Xaction &_xaction;
+ };
+
+ public:
+
+ template<typename R, typename ... arglist>
+ struct MethodProgress : MethodStubbingProgress<R, arglist...> {
+
+ friend class WhenFunctor;
+
+ virtual ~MethodProgress() override = default;
+
+ MethodProgress(MethodProgress &other) :
+ _progress(other._progress), _context(other._context) {
+ }
+
+ MethodProgress(StubbingContext<R, arglist...> &xaction) :
+ _progress(new StubbingChange(xaction)), _context(xaction) {
+ }
+
+ protected:
+
+ virtual MethodStubbingProgress<R, arglist...> &DoImpl(Action<R, arglist...> *action) override {
+ _context.appendAction(action);
+ return *this;
+ }
+
+ private:
+ smart_ptr<StubbingChange> _progress;
+ StubbingContext<R, arglist...> &_context;
+ };
+
+
+ WhenFunctor() {
+ }
+
+ template<typename R, typename ... arglist>
+ MethodProgress<R, arglist...> operator()(const StubbingContext<R, arglist...> &stubbingContext) {
+ StubbingContext<R, arglist...> &rootWithoutConst = const_cast<StubbingContext<R, arglist...> &>(stubbingContext);
+ MethodProgress<R, arglist...> progress(rootWithoutConst);
+ return progress;
+ }
+
+ };
+
+}
+namespace fakeit {
+
+ class FakeFunctor {
+ private:
+ template<typename R, typename ... arglist>
+ void fake(const StubbingContext<R, arglist...> &root) {
+ StubbingContext<R, arglist...> &rootWithoutConst = const_cast<StubbingContext<R, arglist...> &>(root);
+ rootWithoutConst.appendAction(new ReturnDefaultValue<R, arglist...>());
+ rootWithoutConst.commit();
+ }
+
+ void operator()() {
+ }
+
+ public:
+
+ template<typename H, typename ... M>
+ void operator()(const H &head, const M &... tail) {
+ fake(head);
+ this->operator()(tail...);
+ }
+
+ };
+
+}
+#include <set>
+#include <set>
+
+
+namespace fakeit {
+
+ struct InvocationUtils {
+
+ static void sortByInvocationOrder(std::unordered_set<Invocation *> &ivocations,
+ std::vector<Invocation *> &result) {
+ auto comparator = [](Invocation *a, Invocation *b) -> bool {
+ return a->getOrdinal() < b->getOrdinal();
+ };
+ std::set<Invocation *, bool (*)(Invocation *a, Invocation *b)> sortedIvocations(comparator);
+ for (auto i : ivocations)
+ sortedIvocations.insert(i);
+
+ for (auto i : sortedIvocations)
+ result.push_back(i);
+ }
+
+ static void collectActualInvocations(std::unordered_set<Invocation *> &actualInvocations,
+ std::vector<ActualInvocationsSource *> &invocationSources) {
+ for (auto source : invocationSources) {
+ source->getActualInvocations(actualInvocations);
+ }
+ }
+
+ static void selectNonVerifiedInvocations(std::unordered_set<Invocation *> &actualInvocations,
+ std::unordered_set<Invocation *> &into) {
+ for (auto invocation : actualInvocations) {
+ if (!invocation->isVerified()) {
+ into.insert(invocation);
+ }
+ }
+ }
+
+ static void collectInvocationSources(std::vector<ActualInvocationsSource *> &) {
+ }
+
+ template<typename ... list>
+ static void collectInvocationSources(std::vector<ActualInvocationsSource *> &into,
+ const ActualInvocationsSource &mock,
+ const list &... tail) {
+ into.push_back(const_cast<ActualInvocationsSource *>(&mock));
+ collectInvocationSources(into, tail...);
+ }
+
+ static void collectSequences(std::vector<Sequence *> &) {
+ }
+
+ template<typename ... list>
+ static void collectSequences(std::vector<Sequence *> &vec, const Sequence &sequence, const list &... tail) {
+ vec.push_back(&const_cast<Sequence &>(sequence));
+ collectSequences(vec, tail...);
+ }
+
+ static void collectInvolvedMocks(std::vector<Sequence *> &allSequences,
+ std::vector<ActualInvocationsSource *> &involvedMocks) {
+ for (auto sequence : allSequences) {
+ sequence->getInvolvedMocks(involvedMocks);
+ }
+ }
+
+ template<class T>
+ static T &remove_const(const T &s) {
+ return const_cast<T &>(s);
+ }
+
+ };
+
+}
+
+#include <memory>
+
+#include <vector>
+#include <unordered_set>
+
+namespace fakeit {
+ struct MatchAnalysis {
+ std::vector<Invocation *> actualSequence;
+ std::vector<Invocation *> matchedInvocations;
+ int count;
+
+ void run(InvocationsSourceProxy &involvedInvocationSources, std::vector<Sequence *> &expectedPattern) {
+ getActualInvocationSequence(involvedInvocationSources, actualSequence);
+ count = countMatches(expectedPattern, actualSequence, matchedInvocations);
+ }
+
+ private:
+ static void getActualInvocationSequence(InvocationsSourceProxy &involvedMocks,
+ std::vector<Invocation *> &actualSequence) {
+ std::unordered_set<Invocation *> actualInvocations;
+ collectActualInvocations(involvedMocks, actualInvocations);
+ InvocationUtils::sortByInvocationOrder(actualInvocations, actualSequence);
+ }
+
+ static int countMatches(std::vector<Sequence *> &pattern, std::vector<Invocation *> &actualSequence,
+ std::vector<Invocation *> &matchedInvocations) {
+ int end = -1;
+ int count = 0;
+ int startSearchIndex = 0;
+ while (findNextMatch(pattern, actualSequence, startSearchIndex, end, matchedInvocations)) {
+ count++;
+ startSearchIndex = end;
+ }
+ return count;
+ }
+
+ static void collectActualInvocations(InvocationsSourceProxy &involvedMocks,
+ std::unordered_set<Invocation *> &actualInvocations) {
+ involvedMocks.getActualInvocations(actualInvocations);
+ }
+
+ static bool findNextMatch(std::vector<Sequence *> &pattern, std::vector<Invocation *> &actualSequence,
+ int startSearchIndex, int &end,
+ std::vector<Invocation *> &matchedInvocations) {
+ for (auto sequence : pattern) {
+ int index = findNextMatch(sequence, actualSequence, startSearchIndex);
+ if (index == -1) {
+ return false;
+ }
+ collectMatchedInvocations(actualSequence, matchedInvocations, index, sequence->size());
+ startSearchIndex = index + sequence->size();
+ }
+ end = startSearchIndex;
+ return true;
+ }
+
+
+ static void collectMatchedInvocations(std::vector<Invocation *> &actualSequence,
+ std::vector<Invocation *> &matchedInvocations, int start,
+ int length) {
+ int indexAfterMatchedPattern = start + length;
+ for (; start < indexAfterMatchedPattern; start++) {
+ matchedInvocations.push_back(actualSequence[start]);
+ }
+ }
+
+
+ static bool isMatch(std::vector<Invocation *> &actualSequence,
+ std::vector<Invocation::Matcher *> &expectedSequence, int start) {
+ bool found = true;
+ for (unsigned int j = 0; found && j < expectedSequence.size(); j++) {
+ Invocation *actual = actualSequence[start + j];
+ Invocation::Matcher *expected = expectedSequence[j];
+ found = found && expected->matches(*actual);
+ }
+ return found;
+ }
+
+ static int findNextMatch(Sequence *&pattern, std::vector<Invocation *> &actualSequence, int startSearchIndex) {
+ std::vector<Invocation::Matcher *> expectedSequence;
+ pattern->getExpectedSequence(expectedSequence);
+ for (int i = startSearchIndex; i < ((int) actualSequence.size() - (int) expectedSequence.size() + 1); i++) {
+ if (isMatch(actualSequence, expectedSequence, i)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ };
+}
+
+namespace fakeit {
+
+ struct SequenceVerificationExpectation {
+
+ friend class SequenceVerificationProgress;
+
+ ~SequenceVerificationExpectation() THROWS {
+ if (std::uncaught_exception()) {
+ return;
+ }
+ VerifyExpectation(_fakeit);
+ }
+
+ void setExpectedPattern(std::vector<Sequence *> expectedPattern) {
+ _expectedPattern = expectedPattern;
+ }
+
+ void setExpectedCount(const int count) {
+ _expectedCount = count;
+ }
+
+ void setFileInfo(const char * file, int line, const char * callingMethod) {
+ _file = file;
+ _line = line;
+ _testMethod = callingMethod;
+ }
+
+ private:
+
+ VerificationEventHandler &_fakeit;
+ InvocationsSourceProxy _involvedInvocationSources;
+ std::vector<Sequence *> _expectedPattern;
+ int _expectedCount;
+
+ const char * _file;
+ int _line;
+ const char * _testMethod;
+ bool _isVerified;
+
+ SequenceVerificationExpectation(
+ VerificationEventHandler &fakeit,
+ InvocationsSourceProxy mocks,
+ std::vector<Sequence *> &expectedPattern) :
+ _fakeit(fakeit),
+ _involvedInvocationSources(mocks),
+ _expectedPattern(expectedPattern),
+ _expectedCount(-1),
+ _line(0),
+ _isVerified(false) {
+ }
+
+
+ void VerifyExpectation(VerificationEventHandler &verificationErrorHandler) {
+ if (_isVerified)
+ return;
+ _isVerified = true;
+
+ MatchAnalysis ma;
+ ma.run(_involvedInvocationSources, _expectedPattern);
+
+ if (isAtLeastVerification() && atLeastLimitNotReached(ma.count)) {
+ return handleAtLeastVerificationEvent(verificationErrorHandler, ma.actualSequence, ma.count);
+ }
+
+ if (isExactVerification() && exactLimitNotMatched(ma.count)) {
+ return handleExactVerificationEvent(verificationErrorHandler, ma.actualSequence, ma.count);
+ }
+
+ markAsVerified(ma.matchedInvocations);
+ }
+
+ std::vector<Sequence *> &collectSequences(std::vector<Sequence *> &vec) {
+ return vec;
+ }
+
+ template<typename ... list>
+ std::vector<Sequence *> &collectSequences(std::vector<Sequence *> &vec, const Sequence &sequence,
+ const list &... tail) {
+ vec.push_back(&const_cast<Sequence &>(sequence));
+ return collectSequences(vec, tail...);
+ }
+
+
+ static void markAsVerified(std::vector<Invocation *> &matchedInvocations) {
+ for (auto i : matchedInvocations) {
+ i->markAsVerified();
+ }
+ }
+
+ bool isAtLeastVerification() {
+
+ return _expectedCount < 0;
+ }
+
+ bool isExactVerification() {
+ return !isAtLeastVerification();
+ }
+
+ bool atLeastLimitNotReached(int actualCount) {
+ return actualCount < -_expectedCount;
+ }
+
+ bool exactLimitNotMatched(int actualCount) {
+ return actualCount != _expectedCount;
+ }
+
+ void handleExactVerificationEvent(VerificationEventHandler &verificationErrorHandler,
+ std::vector<Invocation *> actualSequence, int count) {
+ SequenceVerificationEvent evt(VerificationType::Exact, _expectedPattern, actualSequence, _expectedCount,
+ count);
+ evt.setFileInfo(_file, _line, _testMethod);
+ return verificationErrorHandler.handle(evt);
+ }
+
+ void handleAtLeastVerificationEvent(VerificationEventHandler &verificationErrorHandler,
+ std::vector<Invocation *> actualSequence, int count) {
+ SequenceVerificationEvent evt(VerificationType::AtLeast, _expectedPattern, actualSequence, -_expectedCount,
+ count);
+ evt.setFileInfo(_file, _line, _testMethod);
+ return verificationErrorHandler.handle(evt);
+ }
+
+ };
+
+}
+namespace fakeit {
+ class ThrowFalseEventHandler : public VerificationEventHandler {
+
+ void handle(const SequenceVerificationEvent &) override {
+ throw false;
+ }
+
+ void handle(const NoMoreInvocationsVerificationEvent &) override {
+ throw false;
+ }
+ };
+}
+
+
+namespace fakeit {
+
+ struct FakeitContext;
+
+ class SequenceVerificationProgress {
+
+ friend class UsingFunctor;
+
+ friend class VerifyFunctor;
+
+ friend class UsingProgress;
+
+ smart_ptr<SequenceVerificationExpectation> _expectationPtr;
+
+ SequenceVerificationProgress(SequenceVerificationExpectation *ptr) : _expectationPtr(ptr) {
+ }
+
+ SequenceVerificationProgress(
+ FakeitContext &fakeit,
+ InvocationsSourceProxy sources,
+ std::vector<Sequence *> &allSequences) :
+ SequenceVerificationProgress(new SequenceVerificationExpectation(fakeit, sources, allSequences)) {
+ }
+
+ virtual void verifyInvocations(const int times) {
+ _expectationPtr->setExpectedCount(times);
+ }
+
+ class Terminator {
+ smart_ptr<SequenceVerificationExpectation> _expectationPtr;
+
+ bool toBool() {
+ try {
+ ThrowFalseEventHandler eh;
+ _expectationPtr->VerifyExpectation(eh);
+ return true;
+ }
+ catch (bool e) {
+ return e;
+ }
+ }
+
+ public:
+ Terminator(smart_ptr<SequenceVerificationExpectation> expectationPtr) : _expectationPtr(expectationPtr) { };
+
+ operator bool() {
+ return toBool();
+ }
+
+ bool operator!() const { return !const_cast<Terminator *>(this)->toBool(); }
+ };
+
+ public:
+
+ ~SequenceVerificationProgress() THROWS { };
+
+ operator bool() const {
+ return Terminator(_expectationPtr);
+ }
+
+ bool operator!() const { return !Terminator(_expectationPtr); }
+
+ Terminator Never() {
+ Exactly(0);
+ return Terminator(_expectationPtr);
+ }
+
+ Terminator Once() {
+ Exactly(1);
+ return Terminator(_expectationPtr);
+ }
+
+ Terminator Twice() {
+ Exactly(2);
+ return Terminator(_expectationPtr);
+ }
+
+ Terminator AtLeastOnce() {
+ verifyInvocations(-1);
+ return Terminator(_expectationPtr);
+ }
+
+ Terminator Exactly(const int times) {
+ if (times < 0) {
+ throw std::invalid_argument(std::string("bad argument times:").append(fakeit::to_string(times)));
+ }
+ verifyInvocations(times);
+ return Terminator(_expectationPtr);
+ }
+
+ Terminator Exactly(const Quantity &q) {
+ Exactly(q.quantity);
+ return Terminator(_expectationPtr);
+ }
+
+ Terminator AtLeast(const int times) {
+ if (times < 0) {
+ throw std::invalid_argument(std::string("bad argument times:").append(fakeit::to_string(times)));
+ }
+ verifyInvocations(-times);
+ return Terminator(_expectationPtr);
+ }
+
+ Terminator AtLeast(const Quantity &q) {
+ AtLeast(q.quantity);
+ return Terminator(_expectationPtr);
+ }
+
+ SequenceVerificationProgress setFileInfo(const char * file, int line, const char * callingMethod) {
+ _expectationPtr->setFileInfo(file, line, callingMethod);
+ return *this;
+ }
+ };
+}
+
+namespace fakeit {
+
+ class UsingProgress {
+ fakeit::FakeitContext &_fakeit;
+ InvocationsSourceProxy _sources;
+
+ void collectSequences(std::vector<fakeit::Sequence *> &) {
+ }
+
+ template<typename ... list>
+ void collectSequences(std::vector<fakeit::Sequence *> &vec, const fakeit::Sequence &sequence,
+ const list &... tail) {
+ vec.push_back(&const_cast<fakeit::Sequence &>(sequence));
+ collectSequences(vec, tail...);
+ }
+
+ public:
+
+ UsingProgress(fakeit::FakeitContext &fakeit, InvocationsSourceProxy source) :
+ _fakeit(fakeit),
+ _sources(source) {
+ }
+
+ template<typename ... list>
+ SequenceVerificationProgress Verify(const fakeit::Sequence &sequence, const list &... tail) {
+ std::vector<fakeit::Sequence *> allSequences;
+ collectSequences(allSequences, sequence, tail...);
+ SequenceVerificationProgress progress(_fakeit, _sources, allSequences);
+ return progress;
+ }
+
+ };
+}
+
+namespace fakeit {
+
+ class UsingFunctor {
+
+ friend class VerifyFunctor;
+
+ FakeitContext &_fakeit;
+
+ public:
+
+ UsingFunctor(FakeitContext &fakeit) : _fakeit(fakeit) {
+ }
+
+ template<typename ... list>
+ UsingProgress operator()(const ActualInvocationsSource &head, const list &... tail) {
+ std::vector<ActualInvocationsSource *> allMocks{&InvocationUtils::remove_const(head),
+ &InvocationUtils::remove_const(tail)...};
+ InvocationsSourceProxy aggregateInvocationsSource{new AggregateInvocationsSource(allMocks)};
+ UsingProgress progress(_fakeit, aggregateInvocationsSource);
+ return progress;
+ }
+
+ };
+}
+#include <set>
+
+namespace fakeit {
+
+ class VerifyFunctor {
+
+ FakeitContext &_fakeit;
+
+
+ public:
+
+ VerifyFunctor(FakeitContext &fakeit) : _fakeit(fakeit) {
+ }
+
+ template<typename ... list>
+ SequenceVerificationProgress operator()(const Sequence &sequence, const list &... tail) {
+ std::vector<Sequence *> allSequences{&InvocationUtils::remove_const(sequence),
+ &InvocationUtils::remove_const(tail)...};
+
+ std::vector<ActualInvocationsSource *> involvedSources;
+ InvocationUtils::collectInvolvedMocks(allSequences, involvedSources);
+ InvocationsSourceProxy aggregateInvocationsSource{new AggregateInvocationsSource(involvedSources)};
+
+ UsingProgress usingProgress(_fakeit, aggregateInvocationsSource);
+ return usingProgress.Verify(sequence, tail...);
+ }
+
+ };
+
+}
+#include <set>
+#include <memory>
+namespace fakeit {
+
+ class VerifyNoOtherInvocationsVerificationProgress {
+
+ friend class VerifyNoOtherInvocationsFunctor;
+
+ struct VerifyNoOtherInvocationsExpectation {
+
+ friend class VerifyNoOtherInvocationsVerificationProgress;
+
+ ~VerifyNoOtherInvocationsExpectation() THROWS {
+ if (std::uncaught_exception()) {
+ return;
+ }
+
+ VerifyExpectation(_fakeit);
+ }
+
+ void setFileInfo(const char * file, int line, const char * callingMethod) {
+ _file = file;
+ _line = line;
+ _callingMethod = callingMethod;
+ }
+
+ private:
+
+ VerificationEventHandler &_fakeit;
+ std::vector<ActualInvocationsSource *> _mocks;
+
+ const char * _file;
+ int _line;
+ const char * _callingMethod;
+ bool _isVerified;
+
+ VerifyNoOtherInvocationsExpectation(VerificationEventHandler &fakeit,
+ std::vector<ActualInvocationsSource *> mocks) :
+ _fakeit(fakeit),
+ _mocks(mocks),
+ _line(0),
+ _isVerified(false) {
+ }
+
+ VerifyNoOtherInvocationsExpectation(VerifyNoOtherInvocationsExpectation &other) = default;
+
+ void VerifyExpectation(VerificationEventHandler &verificationErrorHandler) {
+ if (_isVerified)
+ return;
+ _isVerified = true;
+
+ std::unordered_set<Invocation *> actualInvocations;
+ InvocationUtils::collectActualInvocations(actualInvocations, _mocks);
+
+ std::unordered_set<Invocation *> nonVerifiedInvocations;
+ InvocationUtils::selectNonVerifiedInvocations(actualInvocations, nonVerifiedInvocations);
+
+ if (nonVerifiedInvocations.size() > 0) {
+ std::vector<Invocation *> sortedNonVerifiedInvocations;
+ InvocationUtils::sortByInvocationOrder(nonVerifiedInvocations, sortedNonVerifiedInvocations);
+
+ std::vector<Invocation *> sortedActualInvocations;
+ InvocationUtils::sortByInvocationOrder(actualInvocations, sortedActualInvocations);
+
+ NoMoreInvocationsVerificationEvent evt(sortedActualInvocations, sortedNonVerifiedInvocations);
+ evt.setFileInfo(_file, _line, _callingMethod);
+ return verificationErrorHandler.handle(evt);
+ }
+ }
+
+ };
+
+ fakeit::smart_ptr<VerifyNoOtherInvocationsExpectation> _ptr;
+
+ VerifyNoOtherInvocationsVerificationProgress(VerifyNoOtherInvocationsExpectation *ptr) :
+ _ptr(ptr) {
+ }
+
+ VerifyNoOtherInvocationsVerificationProgress(FakeitContext &fakeit,
+ std::vector<ActualInvocationsSource *> &invocationSources)
+ : VerifyNoOtherInvocationsVerificationProgress(
+ new VerifyNoOtherInvocationsExpectation(fakeit, invocationSources)
+ ) {
+ }
+
+ bool toBool() {
+ try {
+ ThrowFalseEventHandler ev;
+ _ptr->VerifyExpectation(ev);
+ return true;
+ }
+ catch (bool e) {
+ return e;
+ }
+ }
+
+ public:
+
+
+ ~VerifyNoOtherInvocationsVerificationProgress() THROWS {
+ };
+
+ VerifyNoOtherInvocationsVerificationProgress setFileInfo(const char * file, int line,
+ const char * callingMethod) {
+ _ptr->setFileInfo(file, line, callingMethod);
+ return *this;
+ }
+
+ operator bool() const {
+ return const_cast<VerifyNoOtherInvocationsVerificationProgress *>(this)->toBool();
+ }
+
+ bool operator!() const { return !const_cast<VerifyNoOtherInvocationsVerificationProgress *>(this)->toBool(); }
+
+ };
+
+}
+
+
+namespace fakeit {
+ class VerifyNoOtherInvocationsFunctor {
+
+ FakeitContext &_fakeit;
+
+ public:
+
+ VerifyNoOtherInvocationsFunctor(FakeitContext &fakeit) : _fakeit(fakeit) {
+ }
+
+ void operator()() {
+ }
+
+ template<typename ... list>
+ VerifyNoOtherInvocationsVerificationProgress operator()(const ActualInvocationsSource &head,
+ const list &... tail) {
+ std::vector<ActualInvocationsSource *> invocationSources{&InvocationUtils::remove_const(head),
+ &InvocationUtils::remove_const(tail)...};
+ VerifyNoOtherInvocationsVerificationProgress progress{_fakeit, invocationSources};
+ return progress;
+ }
+ };
+
+}
+namespace fakeit {
+
+ class SpyFunctor {
+ private:
+
+ template<typename R, typename ... arglist>
+ void spy(const SpyingContext<R, arglist...> &root) {
+ SpyingContext<R, arglist...> &rootWithoutConst = const_cast<SpyingContext<R, arglist...> &>(root);
+ auto methodFromOriginalVT = rootWithoutConst.getOriginalMethod();
+ rootWithoutConst.appendAction(new ReturnDelegateValue<R, arglist...>(methodFromOriginalVT));
+ rootWithoutConst.commit();
+ }
+
+ void operator()() {
+ }
+
+ public:
+
+ template<typename H, typename ... M>
+ void operator()(const H &head, const M &... tail) {
+ spy(head);
+ this->operator()(tail...);
+ }
+
+ };
+
+}
+
+#include <vector>
+#include <set>
+
+namespace fakeit {
+ class VerifyUnverifiedFunctor {
+
+ FakeitContext &_fakeit;
+
+ public:
+
+ VerifyUnverifiedFunctor(FakeitContext &fakeit) : _fakeit(fakeit) {
+ }
+
+ template<typename ... list>
+ SequenceVerificationProgress operator()(const Sequence &sequence, const list &... tail) {
+ std::vector<Sequence *> allSequences{&InvocationUtils::remove_const(sequence),
+ &InvocationUtils::remove_const(tail)...};
+
+ std::vector<ActualInvocationsSource *> involvedSources;
+ InvocationUtils::collectInvolvedMocks(allSequences, involvedSources);
+
+ InvocationsSourceProxy aggregateInvocationsSource{new AggregateInvocationsSource(involvedSources)};
+ InvocationsSourceProxy unverifiedInvocationsSource{
+ new UnverifiedInvocationsSource(aggregateInvocationsSource)};
+
+ UsingProgress usingProgress(_fakeit, unverifiedInvocationsSource);
+ return usingProgress.Verify(sequence, tail...);
+ }
+
+ };
+
+ class UnverifiedFunctor {
+ public:
+ UnverifiedFunctor(FakeitContext &fakeit) : Verify(fakeit) {
+ }
+
+ VerifyUnverifiedFunctor Verify;
+
+ template<typename ... list>
+ UnverifiedInvocationsSource operator()(const ActualInvocationsSource &head, const list &... tail) {
+ std::vector<ActualInvocationsSource *> allMocks{&InvocationUtils::remove_const(head),
+ &InvocationUtils::remove_const(tail)...};
+ InvocationsSourceProxy aggregateInvocationsSource{new AggregateInvocationsSource(allMocks)};
+ UnverifiedInvocationsSource unverifiedInvocationsSource{aggregateInvocationsSource};
+ return unverifiedInvocationsSource;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ };
+}
+
+namespace fakeit {
+
+ static UsingFunctor Using(Fakeit);
+ static VerifyFunctor Verify(Fakeit);
+ static VerifyNoOtherInvocationsFunctor VerifyNoOtherInvocations(Fakeit);
+ static UnverifiedFunctor Unverified(Fakeit);
+ static SpyFunctor Spy;
+ static FakeFunctor Fake;
+ static WhenFunctor When;
+
+ template<class T>
+ class SilenceUnusedVariableWarnings {
+
+ void use(void *) {
+ }
+
+ SilenceUnusedVariableWarnings() {
+ use(&Fake);
+ use(&When);
+ use(&Spy);
+ use(&Using);
+ use(&Verify);
+ use(&VerifyNoOtherInvocations);
+ use(&_);
+ }
+ };
+
+}
+#ifdef _MSC_VER
+#define __func__ __FUNCTION__
+#endif
+
+#define MOCK_TYPE(mock) \
+ std::remove_reference<decltype(mock.get())>::type
+
+#define OVERLOADED_METHOD_PTR(mock, method, prototype) \
+ fakeit::Prototype<prototype>::MemberType<MOCK_TYPE(mock)>::get(&MOCK_TYPE(mock)::method)
+
+#define CONST_OVERLOADED_METHOD_PTR(mock, method, prototype) \
+ fakeit::Prototype<prototype>::MemberType<MOCK_TYPE(mock)>::getconst(&MOCK_TYPE(mock)::method)
+
+#define Dtor(mock) \
+ mock.dtor().setMethodDetails(#mock,"destructor")
+
+#define Method(mock, method) \
+ mock.template stub<__COUNTER__>(&MOCK_TYPE(mock)::method).setMethodDetails(#mock,#method)
+
+#define OverloadedMethod(mock, method, prototype) \
+ mock.template stub<__COUNTER__>(OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
+
+#define ConstOverloadedMethod(mock, method, prototype) \
+ mock.template stub<__COUNTER__>(CONST_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
+
+#define Verify(...) \
+ Verify( __VA_ARGS__ ).setFileInfo(__FILE__, __LINE__, __func__)
+
+#define Using(...) \
+ Using( __VA_ARGS__ )
+
+#define VerifyNoOtherInvocations(...) \
+ VerifyNoOtherInvocations( __VA_ARGS__ ).setFileInfo(__FILE__, __LINE__, __func__)
+
+#define Fake(...) \
+ Fake( __VA_ARGS__ )
+
+#define When(call) \
+ When(call)
+
+
+#endif
diff --git a/third_party/gsl-disable-gsl-suppress.patch b/third_party/gsl-disable-gsl-suppress.patch
new file mode 100644
index 0000000..fb1a126
--- /dev/null
+++ b/third_party/gsl-disable-gsl-suppress.patch
@@ -0,0 +1,11 @@
+--- a/include/gsl/gsl-lite.hpp
++++ b/include/gsl/gsl-lite.hpp
+@@ -1081,7 +1081,7 @@ namespace __cxxabiv1 { struct __cxa_eh_globals; extern "C" __cxa_eh_globals * __
+ // MSVC warning suppression macros:
+
+ #if gsl_COMPILER_MSVC_VERSION >= 140 && ! gsl_COMPILER_NVCC_VERSION
+-# define gsl_SUPPRESS_MSGSL_WARNING(expr) [[gsl::suppress(expr)]]
++# define gsl_SUPPRESS_MSGSL_WARNING(expr) /* Pimm: note disabled for intel [[gsl::suppress(expr)]]*/
+ # define gsl_SUPPRESS_MSVC_WARNING(code, descr) __pragma(warning(suppress: code) )
+ # define gsl_DISABLE_MSVC_WARNINGS(codes) __pragma(warning(push)) __pragma(warning(disable: codes))
+ # define gsl_RESTORE_MSVC_WARNINGS() __pragma(warning(pop ))
diff --git a/third_party/gsl.h b/third_party/gsl.h
new file mode 100644
index 0000000..1bfa97f
--- /dev/null
+++ b/third_party/gsl.h
@@ -0,0 +1,27 @@
+//
+// gsl-lite is based on GSL: Guidelines Support Library.
+// For more information see https://github.com/gsl-lite/gsl-lite
+//
+// Copyright (c) 2015 Martin Moene
+// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
+//
+// This code is licensed under the MIT License (MIT).
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+// mimic MS include hierarchy
+
+#ifndef GSL_GSL_H_INCLUDED
+#define GSL_GSL_H_INCLUDED
+
+#pragma message ("gsl.h is deprecated since version 0.27.0, use gsl/gsl-lite.hpp instead.")
+
+#include "gsl/gsl-lite.hpp"
+
+#endif // GSL_GSL_H_INCLUDED
diff --git a/third_party/gsl/gsl b/third_party/gsl/gsl
new file mode 100644
index 0000000..7ef52ac
--- /dev/null
+++ b/third_party/gsl/gsl
@@ -0,0 +1,29 @@
+//
+// gsl-lite is based on GSL: Guidelines Support Library.
+// For more information see https://github.com/martinmoene/gsl-lite
+//
+// Copyright (c) 2015 Martin Moene
+// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
+//
+// This code is licensed under the MIT License (MIT).
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+// mimic MS include hierarchy
+
+#pragma once
+
+#ifndef GSL_GSL_H_INCLUDED
+#define GSL_GSL_H_INCLUDED
+
+#pragma message ("gsl/gsl is deprecated since version 0.38.1, use gsl/gsl-lite.hpp instead.")
+
+#include "gsl-lite.hpp"
+
+#endif // GSL_GSL_H_INCLUDED
diff --git a/third_party/gsl/gsl-lite-vc6.hpp b/third_party/gsl/gsl-lite-vc6.hpp
new file mode 100644
index 0000000..3579336
--- /dev/null
+++ b/third_party/gsl/gsl-lite-vc6.hpp
@@ -0,0 +1,697 @@
+//
+// gsl-lite-vc6 is based on GSL: Guidelines Support Library,
+// For more information see https://github.com/gsl-lite/gsl-lite
+//
+// Copyright (c) 2015 Martin Moene
+// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
+//
+// This code is licensed under the MIT License (MIT).
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#pragma once
+
+#ifndef GSL_GSL_LITE_H_INCLUDED
+#define GSL_GSL_LITE_H_INCLUDED
+
+#include <exception>
+#include <iterator>
+#include <limits>
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+#include <vector>
+
+#define gsl_lite_VERSION "0.0.0"
+
+// Configuration:
+
+#ifndef gsl_FEATURE_IMPLICIT_MACRO
+# define gsl_FEATURE_IMPLICIT_MACRO 1
+#endif
+
+#ifndef gsl_FEATURE_OWNER_MACRO
+# define gsl_FEATURE_OWNER_MACRO 1
+#endif
+
+#ifndef gsl_FEATURE_SHARED_PTR
+# define gsl_FEATURE_SHARED_PTR 0
+#endif
+
+#ifndef gsl_FEATURE_UNIQUE_PTR
+# define gsl_FEATURE_UNIQUE_PTR 0
+#endif
+
+#ifndef gsl_CONFIG_THROWS_FOR_TESTING
+# define gsl_CONFIG_THROWS_FOR_TESTING 0
+#endif
+
+#ifndef gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS
+# define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS 0
+#endif
+
+#ifndef gsl_CONFIG_SHARED_PTR_INCLUDE
+# define gsl_CONFIG_SHARED_PTR_INCLUDE <boost/shared_ptr.hpp>
+#endif
+
+#ifndef gsl_CONFIG_UNIQUE_PTR_INCLUDE
+# define gsl_CONFIG_UNIQUE_PTR_INCLUDE <boost/unique_ptr.hpp>
+#endif
+
+#ifndef gsl_CONFIG_SHARED_PTR_DECL
+# define gsl_CONFIG_SHARED_PTR_DECL boost::shared_ptr
+#endif
+
+#ifndef gsl_CONFIG_UNIQUE_PTR_DECL
+# define gsl_CONFIG_UNIQUE_PTR_DECL boost::unique_ptr
+#endif
+
+// Compiler detection:
+
+#if defined(_MSC_VER ) && !defined(__clang__)
+# define gsl_COMPILER_MSVC_VER (_MSC_VER )
+# define gsl_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) )
+#else
+# define gsl_COMPILER_MSVC_VER 0
+# define gsl_COMPILER_MSVC_VERSION 0
+# define gsl_COMPILER_NON_MSVC 1
+#endif
+
+#if gsl_COMPILER_MSVC_VERSION != 60
+# error GSL Lite: this header is for Visual C++ 6
+#endif
+
+// half-open range [lo..hi):
+#define gsl_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) )
+
+// Presence of C++ language features:
+
+// C++ feature usage:
+
+#if gsl_FEATURE_IMPLICIT_MACRO
+# define implicit
+#endif
+
+#define gsl_DIMENSION_OF( a ) ( sizeof(a) / sizeof(0[a]) )
+
+#if gsl_FEATURE_SHARED_PTR
+# include gsl_CONFIG_SHARED_PTR_INCLUDE
+#endif
+
+#if gsl_FEATURE_UNIQUE_PTR
+# include gsl_CONFIG_UNIQUE_PTR_INCLUDE
+#endif
+
+namespace gsl {
+
+//
+// GSL.owner: ownership pointers
+//
+// ToDo:
+#if gsl_FEATURE_SHARED_PTR
+ using gsl_CONFIG_SHARED_PTR_DECL;
+#endif
+#if gsl_FEATURE_UNIQUE_PTR
+ using gsl_CONFIG_UNIQUE_PTR_DECL;
+#endif
+
+template< class T > struct owner { typedef T type; };
+
+#define gsl_HAVE_OWNER_TEMPLATE 0
+
+#if gsl_FEATURE_OWNER_MACRO
+# define Owner(t) ::gsl::owner<t>::type
+#endif
+
+//
+// GSL.assert: assertions
+//
+#define Expects(x) ::gsl::fail_fast_assert((x))
+#define Ensures(x) ::gsl::fail_fast_assert((x))
+
+#if gsl_CONFIG_THROWS_FOR_TESTING
+
+struct fail_fast : public std::runtime_error
+{
+ fail_fast()
+ : std::runtime_error( "GSL assertion" ) {}
+
+ explicit fail_fast( char const * const message )
+ : std::runtime_error( message ) {}
+};
+
+inline void fail_fast_assert( bool cond )
+{
+ if ( !cond )
+ throw fail_fast();
+}
+
+inline void fail_fast_assert( bool cond, char const * const message )
+{
+ if ( !cond )
+ throw fail_fast( message );
+}
+
+#else // gsl_CONFIG_THROWS_FOR_TESTING
+
+inline void fail_fast_assert( bool cond )
+{
+ if ( !cond )
+ terminate();
+}
+
+inline void fail_fast_assert( bool cond, char const * const )
+{
+ if ( !cond )
+ terminate();
+}
+
+#endif // gsl_CONFIG_THROWS_FOR_TESTING
+
+//
+// GSL.util: utilities
+//
+
+class final_action
+{
+public:
+ typedef void (*Action)();
+
+ final_action( Action action )
+ : action_( action ) {}
+
+ ~final_action()
+ {
+ action_();
+ }
+
+private:
+ Action action_;
+};
+
+template< class Fn >
+final_action finally( Fn const & f )
+{
+ return final_action(( f ));
+}
+
+template< class T, class U >
+T narrow_cast( U u )
+{
+ return static_cast<T>( u );
+}
+
+struct narrowing_error : public std::exception {};
+
+template< class T, class U >
+T narrow( U u )
+{
+ T t = narrow_cast<T>( u );
+
+ if ( static_cast<U>( t ) != u )
+ {
+ throw narrowing_error();
+ }
+ return t;
+}
+
+//
+// GSL.views: views
+//
+
+//
+// at() - Bounds-checked way of accessing static arrays, std::array, std::vector.
+//
+
+namespace detail {
+
+struct precedence_0 {};
+struct precedence_1 : precedence_0 {};
+struct order_precedence : precedence_1 {};
+
+template< class Array, class T >
+T & at( Array & arr, size_t index, T*, precedence_0 const & )
+{
+ Expects( index < gsl_DIMENSION_OF( arr ) );
+ return arr[index];
+}
+
+} // namespace detail
+
+// Create an at( container ) function:
+
+# define gsl_MK_AT( Cont ) \
+ namespace gsl { namespace detail { \
+ template< class T > \
+ inline T & at( Cont<T> & cont, size_t index, T*, precedence_1 const & ) \
+ { \
+ Expects( index < cont.size() ); \
+ return cont[index]; \
+ } }}
+
+template< class Cont >
+int & at( Cont & cont, size_t index )
+{
+ return detail::at( cont, index, &cont[0], detail::order_precedence() );
+}
+
+//
+// not_null<> - Wrap any indirection and enforce non-null.
+//
+template<class T>
+class not_null
+{
+public:
+ not_null( T t ) : ptr_ ( t ){ Expects( ptr_ != NULL ); }
+ not_null & operator=( T const & t ) { ptr_ = t ; Expects( ptr_ != NULL ); return *this; }
+
+ not_null( not_null const & other ) : ptr_ ( other.ptr_ ) {}
+ not_null & operator=( not_null const & other ) { ptr_ = other.ptr_; }
+
+ // VC6 accepts this anyway:
+ // template< typename U > not_null( not_null<U> const & other );
+ // template< typename U > not_null & operator=( not_null<U> const & other ) ;
+
+private:
+ // Prevent compilation when initialized with a literal 0:
+ not_null( int );
+ not_null & operator=( int );
+
+public:
+ T get() const
+ {
+ return ptr_;
+ }
+
+ operator T() const { return get(); }
+ T operator->() const { return get(); }
+
+ bool operator==(T const & rhs) const { return ptr_ == rhs; }
+ bool operator!=(T const & rhs) const { return !(*this == rhs); }
+
+private:
+ T ptr_;
+
+ not_null & operator++();
+ not_null & operator--();
+ not_null operator++( int );
+ not_null operator--( int );
+ not_null & operator+ ( size_t );
+ not_null & operator+=( size_t );
+ not_null & operator- ( size_t );
+ not_null & operator-=( size_t );
+};
+
+//
+// Byte-specific type.
+//
+typedef unsigned char byte;
+
+//
+// span<> - A 1D view of contiguous T's, replace (*,len).
+//
+template< class T >
+class span
+{
+public:
+ typedef size_t size_type;
+
+ typedef T value_type;
+ typedef T & reference;
+ typedef T * pointer;
+ typedef T const * const_pointer;
+
+ typedef pointer iterator;
+ typedef const_pointer const_iterator;
+
+ typedef std::reverse_iterator< iterator, T > reverse_iterator;
+ typedef std::reverse_iterator< const_iterator, const T > const_reverse_iterator;
+
+ // Todo:
+ // typedef typename std::iterator_traits< iterator >::difference_type difference_type;
+
+ span()
+ : begin_( NULL )
+ , end_ ( NULL )
+ {
+ Expects( size() == 0 );
+ }
+
+ span( pointer begin, pointer end )
+ : begin_( begin )
+ , end_ ( end )
+ {
+ Expects( begin <= end );
+ }
+
+ span( pointer data, size_type size )
+ : begin_( data )
+ , end_ ( data + size )
+ {
+ Expects( size == 0 || ( size > 0 && data != NULL ) );
+ }
+
+private:
+ struct precedence_0 {};
+ struct precedence_1 : precedence_0 {};
+ struct precedence_2 : precedence_1 {};
+ struct order_precedence : precedence_1 {};
+
+ template< class Array, class U >
+ span create( Array & arr, U*, precedence_0 const & ) const
+ {
+ return span( arr, gsl_DIMENSION_OF( arr ) );
+ }
+
+ span create( std::vector<T> & cont, T*, precedence_1 const & ) const
+ {
+ return span( &cont[0], cont.size() );
+ }
+
+public:
+ template< class Cont >
+ span( Cont & cont )
+ {
+ *this = create( cont, &cont[0], order_precedence() );
+ }
+
+#if 0
+ // =default constructor
+ span( span const & other )
+ : begin_( other.begin() )
+ , end_ ( other.end() )
+ {}
+#endif
+
+ span & operator=( span const & other )
+ {
+ // VC6 balks at copy-swap implementation (here),
+ // so we do it the simple way:
+ begin_ = other.begin_;
+ end_ = other.end_;
+ return *this;
+ }
+
+#if 0
+ // Converting from other span ?
+ template< typename U > operator=();
+#endif
+
+ iterator begin() const
+ {
+ return iterator( begin_ );
+ }
+
+ iterator end() const
+ {
+ return iterator( end_ );
+ }
+
+ const_iterator cbegin() const
+ {
+ return const_iterator( begin() );
+ }
+
+ const_iterator cend() const
+ {
+ return const_iterator( end() );
+ }
+
+ reverse_iterator rbegin() const
+ {
+ return reverse_iterator( end() );
+ }
+
+ reverse_iterator rend() const
+ {
+ return reverse_iterator( begin() );
+ }
+
+ const_reverse_iterator crbegin() const
+ {
+ return const_reverse_iterator( cend() );
+ }
+
+ const_reverse_iterator crend() const
+ {
+ return const_reverse_iterator( cbegin() );
+ }
+
+ operator bool () const
+ {
+ return begin_ != NULL;
+ }
+
+ reference operator[]( size_type index )
+ {
+ return at( index );
+ }
+
+ bool operator==( span const & other ) const
+ {
+ return size() == other.size()
+ && (begin_ == other.begin_ || std::equal( this->begin(), this->end(), other.begin() ) );
+ }
+
+ bool operator!=( span const & other ) const
+ {
+ return !( *this == other );
+ }
+
+ bool operator< ( span const & other ) const
+ {
+ return std::lexicographical_compare( this->begin(), this->end(), other.begin(), other.end() );
+ }
+
+ bool operator<=( span const & other ) const
+ {
+ return !( other < *this );
+ }
+
+ bool operator> ( span const & other ) const
+ {
+ return ( other < *this );
+ }
+
+ bool operator>=( span const & other ) const
+ {
+ return !( *this < other );
+ }
+
+ reference at( size_type index )
+ {
+ Expects( index >= 0 && index < size());
+ return begin_[ index ];
+ }
+
+ pointer data() const
+ {
+ return begin_;
+ }
+
+ bool empty() const
+ {
+ return size() == 0;
+ }
+
+ size_type size() const
+ {
+ return std::distance( begin_, end_ );
+ }
+
+ size_type length() const
+ {
+ return size();
+ }
+
+ size_type used_length() const
+ {
+ return length();
+ }
+
+ size_type bytes() const
+ {
+ return sizeof( value_type ) * size();
+ }
+
+ size_type used_bytes() const
+ {
+ return bytes();
+ }
+
+ void swap( span & other )
+ {
+ using std::swap;
+ swap( begin_, other.begin_ );
+ swap( end_ , other.end_ );
+ }
+
+ span< const byte > as_bytes() const
+ {
+ return span< const byte >( reinterpret_cast<const byte *>( data() ), bytes() );
+ }
+
+ span< byte > as_writeable_bytes() const
+ {
+ return span< byte >( reinterpret_cast<byte *>( data() ), bytes() );
+ }
+
+ template< class U >
+ struct mk
+ {
+ static span<U> view( U * data, size_type size )
+ {
+ return span<U>( data, size );
+ }
+ };
+
+ template< typename U >
+ span< U > as_span( U u = U() ) const
+ {
+ Expects( ( this->bytes() % sizeof(U) ) == 0 );
+ return mk<U>::view( reinterpret_cast<U *>( this->data() ), this->bytes() / sizeof( U ) );
+ }
+
+private:
+ pointer begin_;
+ pointer end_;
+};
+
+// span creator functions (see ctors)
+
+template< typename T>
+span< const byte > as_bytes( span<T> spn )
+{
+ return span< const byte >( reinterpret_cast<const byte *>( spn.data() ), spn.bytes() );
+}
+
+template< typename T>
+span< byte > as_writeable_bytes( span<T> spn )
+{
+ return span< byte >( reinterpret_cast<byte *>( spn.data() ), spn.bytes() );
+}
+
+template< typename T >
+span<T> as_span( T * begin, T * end )
+{
+ return span<T>( begin, end );
+}
+
+template< typename T >
+span<T> as_span( T * begin, size_t size )
+{
+ return span<T>( begin, size );
+}
+
+namespace detail {
+
+template< class T >
+struct mk
+{
+ static span<T> view( std::vector<T> & cont )
+ {
+ return span<T>( cont );
+ }
+};
+}
+
+template< class T >
+span<T> as_span( std::vector<T> & cont )
+{
+ return detail::mk<T>::view( cont );
+}
+
+//
+// String types:
+//
+
+typedef char * zstring;
+typedef wchar_t * zwstring;
+typedef const char * czstring;
+typedef const wchar_t * cwzstring;
+
+typedef span< char > string_span;
+typedef span< wchar_t > wstring_span;
+typedef span< const char > cstring_span;
+typedef span< const wchar_t > cwstring_span;
+
+// to_string() allow (explicit) conversions from string_span to string
+
+inline std::string to_string( string_span const & view )
+{
+ return std::string( view.data(), view.length() );
+}
+
+inline std::string to_string( cstring_span const & view )
+{
+ return std::string( view.data(), view.length() );
+}
+
+inline std::wstring to_string( wstring_span const & view )
+{
+ return std::wstring( view.data(), view.length() );
+}
+
+inline std::wstring to_string( cwstring_span const & view )
+{
+ return std::wstring( view.data(), view.length() );
+}
+
+//
+// ensure_sentinel()
+//
+// Provides a way to obtain a span from a contiguous sequence
+// that ends with a (non-inclusive) sentinel value.
+//
+// Will fail-fast if sentinel cannot be found before max elements are examined.
+//
+namespace detail {
+
+template<class T, class SizeType, const T Sentinel>
+struct ensure
+{
+ static span<T> sentinel( T * seq, SizeType max = (std::numeric_limits<SizeType>::max)() )
+ {
+ typedef T * pointer;
+ typedef typename std::iterator_traits<pointer>::difference_type difference_type;
+
+ pointer cur = seq;
+
+ while ( std::distance( seq, cur ) < static_cast<difference_type>( max ) && *cur != Sentinel )
+ ++cur;
+
+ Expects( *cur == Sentinel );
+
+ return span<T>( seq, cur - seq );
+ }
+};
+} // namespace detail
+
+//
+// ensure_z - creates a string_span for a czstring or cwzstring.
+// Will fail fast if a null-terminator cannot be found before
+// the limit of size_type.
+//
+
+template< typename T >
+span<T> ensure_z( T * sz, size_t max = (std::numeric_limits<size_t>::max)() )
+{
+ return detail::ensure<T, size_t, 0>::sentinel( sz, max );
+}
+
+} // namespace gsl
+
+// at( std::vector ):
+
+gsl_MK_AT( std::vector )
+
+#endif // GSL_GSL_LITE_H_INCLUDED
+
+// end of file
diff --git a/third_party/gsl/gsl-lite.h b/third_party/gsl/gsl-lite.h
new file mode 100644
index 0000000..a738253
--- /dev/null
+++ b/third_party/gsl/gsl-lite.h
@@ -0,0 +1,27 @@
+//
+// gsl-lite is based on GSL: Guidelines Support Library.
+// For more information see https://github.com/gsl-lite/gsl-lite
+//
+// Copyright (c) 2015 Martin Moene
+// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
+//
+// This code is licensed under the MIT License (MIT).
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+// mimic MS include hierarchy
+
+#ifndef GSL_GSL_LITE_H_INCLUDED
+#define GSL_GSL_LITE_H_INCLUDED
+
+#pragma message ("gsl/gsl-lite.h is deprecated since version 0.27.0, use gsl/gsl-lite.hpp instead.")
+
+#include "gsl-lite.hpp"
+
+#endif // GSL_GSL_LITE_H_INCLUDED
diff --git a/third_party/gsl/gsl-lite.hpp b/third_party/gsl/gsl-lite.hpp
new file mode 100644
index 0000000..21c114c
--- /dev/null
+++ b/third_party/gsl/gsl-lite.hpp
@@ -0,0 +1,5197 @@
+//
+// gsl-lite is based on GSL: Guidelines Support Library.
+// For more information see https://github.com/gsl-lite/gsl-lite
+//
+// Copyright (c) 2015-2019 Martin Moene
+// Copyright (c) 2019-2021 Moritz Beutel
+// Copyright (c) 2015-2018 Microsoft Corporation. All rights reserved.
+//
+// This code is licensed under the MIT License (MIT).
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#ifndef GSL_GSL_LITE_HPP_INCLUDED
+#define GSL_GSL_LITE_HPP_INCLUDED
+
+#include <exception> // for exception, terminate(), uncaught_exceptions()
+#include <limits>
+#include <memory> // for addressof(), unique_ptr<>, shared_ptr<>
+#include <iosfwd> // for basic_ostream<>
+#include <ios> // for ios_base, streamsize
+#include <stdexcept> // for logic_error
+#include <string>
+#include <utility> // for move(), forward<>(), swap()
+#include <cstddef> // for size_t, ptrdiff_t, nullptr_t
+
+#define gsl_lite_MAJOR 0
+#define gsl_lite_MINOR 38
+#define gsl_lite_PATCH 1
+
+#define gsl_lite_VERSION gsl_STRINGIFY(gsl_lite_MAJOR) "." gsl_STRINGIFY(gsl_lite_MINOR) "." gsl_STRINGIFY(gsl_lite_PATCH)
+
+#define gsl_STRINGIFY( x ) gsl_STRINGIFY_( x )
+#define gsl_STRINGIFY_( x ) #x
+#define gsl_CONCAT_( a, b ) gsl_CONCAT2_( a, b )
+#define gsl_CONCAT2_( a, b ) a##b
+#define gsl_EVALF_( f ) f()
+
+// configuration argument checking:
+
+#define gsl_DETAIL_CFG_TOGGLE_VALUE_1 1
+#define gsl_DETAIL_CFG_TOGGLE_VALUE_0 1
+#define gsl_DETAIL_CFG_DEFAULTS_VERSION_VALUE_1 1
+#define gsl_DETAIL_CFG_DEFAULTS_VERSION_VALUE_0 1
+#define gsl_DETAIL_CFG_STD_VALUE_98 1
+#define gsl_DETAIL_CFG_STD_VALUE_3 1
+#define gsl_DETAIL_CFG_STD_VALUE_03 1
+#define gsl_DETAIL_CFG_STD_VALUE_11 1
+#define gsl_DETAIL_CFG_STD_VALUE_14 1
+#define gsl_DETAIL_CFG_STD_VALUE_17 1
+#define gsl_DETAIL_CFG_STD_VALUE_20 1
+#define gsl_DETAIL_CFG_NO_VALUE_ 1
+#define gsl_DETAIL_CFG_NO_VALUE_1 1 // many compilers treat the command-line parameter "-Dfoo" as equivalent to "-Dfoo=1", so we tolerate that
+#define gsl_CHECK_CFG_TOGGLE_VALUE_( x ) gsl_CONCAT_( gsl_DETAIL_CFG_TOGGLE_VALUE_, x )
+#define gsl_CHECK_CFG_DEFAULTS_VERSION_VALUE_( x ) gsl_CONCAT_( gsl_DETAIL_CFG_DEFAULTS_VERSION_VALUE_, x )
+#define gsl_CHECK_CFG_STD_VALUE_( x ) gsl_CONCAT_( gsl_DETAIL_CFG_STD_VALUE_, x )
+#define gsl_CHECK_CFG_NO_VALUE_( x ) gsl_CONCAT_( gsl_DETAIL_CFG_NO_VALUE, gsl_CONCAT_( _, x ) )
+
+// gsl-lite backward compatibility:
+
+#if defined( gsl_CONFIG_DEFAULTS_VERSION )
+# if ! gsl_CHECK_CFG_DEFAULTS_VERSION_VALUE_( gsl_CONFIG_DEFAULTS_VERSION )
+# pragma message ("invalid configuration value gsl_CONFIG_DEFAULTS_VERSION=" gsl_STRINGIFY(gsl_CONFIG_DEFAULTS_VERSION) ", must be 0 or 1")
+# endif
+#else
+# define gsl_CONFIG_DEFAULTS_VERSION gsl_lite_MAJOR // default
+#endif
+# define gsl_CONFIG_DEFAULTS_VERSION_() gsl_CONFIG_DEFAULTS_VERSION
+
+#if defined( gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR )
+# pragma message ("invalid configuration value gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR=" gsl_STRINGIFY(gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR) ", must be 0 or 1")
+# endif
+# define gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR
+# pragma message ("gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR is deprecated since gsl-lite 0.7; replace with gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR, or consider span(with_container, cont).")
+#endif
+
+#if defined( gsl_CONFIG_CONTRACT_LEVEL_ON )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_LEVEL_ON )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_LEVEL_ON=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_LEVEL_ON) "; macro must be defined without value")
+# endif
+# pragma message ("gsl_CONFIG_CONTRACT_LEVEL_ON is deprecated since gsl-lite 0.36; replace with gsl_CONFIG_CONTRACT_CHECKING_ON.")
+# define gsl_CONFIG_CONTRACT_CHECKING_ON
+#endif
+#if defined( gsl_CONFIG_CONTRACT_LEVEL_OFF )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_LEVEL_OFF )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_LEVEL_OFF=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_LEVEL_OFF) "; macro must be defined without value")
+# endif
+# pragma message ("gsl_CONFIG_CONTRACT_LEVEL_OFF is deprecated since gsl-lite 0.36; replace with gsl_CONFIG_CONTRACT_CHECKING_OFF.")
+# define gsl_CONFIG_CONTRACT_CHECKING_OFF
+#endif
+#if defined( gsl_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY) "; macro must be defined without value")
+# endif
+# pragma message ("gsl_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY is deprecated since gsl-lite 0.36; replace with gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF and gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF.")
+# define gsl_CONFIG_CONTRACT_CHECKING_ON
+# define gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF
+# define gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF
+#elif defined( gsl_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY) "; macro must be defined without value")
+# endif
+# pragma message ("gsl_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY is deprecated since gsl-lite 0.36; replace with gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF and gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF.")
+# define gsl_CONFIG_CONTRACT_CHECKING_ON
+# define gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF
+# define gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF
+#endif
+
+// M-GSL compatibility:
+
+#if defined( GSL_THROW_ON_CONTRACT_VIOLATION )
+# if ! gsl_CHECK_CFG_NO_VALUE_( GSL_THROW_ON_CONTRACT_VIOLATION )
+# pragma message ("invalid configuration value GSL_THROW_ON_CONTRACT_VIOLATION=" gsl_STRINGIFY(GSL_THROW_ON_CONTRACT_VIOLATION) "; macro must be defined without value")
+# endif
+# define gsl_CONFIG_CONTRACT_VIOLATION_THROWS
+#endif
+
+#if defined( GSL_TERMINATE_ON_CONTRACT_VIOLATION )
+# if ! gsl_CHECK_CFG_NO_VALUE_( GSL_TERMINATE_ON_CONTRACT_VIOLATION )
+# pragma message ("invalid configuration value GSL_TERMINATE_ON_CONTRACT_VIOLATION=" gsl_STRINGIFY(GSL_TERMINATE_ON_CONTRACT_VIOLATION) "; macro must be defined without value")
+# endif
+# define gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES
+#endif
+
+#if defined( GSL_UNENFORCED_ON_CONTRACT_VIOLATION )
+# if ! gsl_CHECK_CFG_NO_VALUE_( GSL_UNENFORCED_ON_CONTRACT_VIOLATION )
+# pragma message ("invalid configuration value GSL_UNENFORCED_ON_CONTRACT_VIOLATION=" gsl_STRINGIFY(GSL_UNENFORCED_ON_CONTRACT_VIOLATION) "; macro must be defined without value")
+# endif
+# define gsl_CONFIG_CONTRACT_CHECKING_OFF
+#endif
+
+// Configuration: Features
+
+#if defined( gsl_FEATURE_WITH_CONTAINER_TO_STD )
+# if ! gsl_CHECK_CFG_STD_VALUE_( gsl_FEATURE_WITH_CONTAINER_TO_STD )
+# pragma message ("invalid configuration value gsl_FEATURE_WITH_CONTAINER_TO_STD=" gsl_STRINGIFY(gsl_FEATURE_WITH_CONTAINER_TO_STD) ", must be 98, 3, 11, 14, 17, or 20")
+# endif
+#else
+# define gsl_FEATURE_WITH_CONTAINER_TO_STD 99 // default
+#endif
+#define gsl_FEATURE_WITH_CONTAINER_TO_STD_() gsl_FEATURE_WITH_CONTAINER_TO_STD
+
+#if defined( gsl_FEATURE_MAKE_SPAN_TO_STD )
+# if ! gsl_CHECK_CFG_STD_VALUE_( gsl_FEATURE_MAKE_SPAN_TO_STD )
+# pragma message ("invalid configuration value gsl_FEATURE_MAKE_SPAN_TO_STD=" gsl_STRINGIFY(gsl_FEATURE_MAKE_SPAN_TO_STD) ", must be 98, 3, 11, 14, 17, or 20")
+# endif
+#else
+# define gsl_FEATURE_MAKE_SPAN_TO_STD 99 // default
+#endif
+#define gsl_FEATURE_MAKE_SPAN_TO_STD_() gsl_FEATURE_MAKE_SPAN_TO_STD
+
+#if defined( gsl_FEATURE_BYTE_SPAN_TO_STD )
+# if ! gsl_CHECK_CFG_STD_VALUE_( gsl_FEATURE_BYTE_SPAN_TO_STD )
+# pragma message ("invalid configuration value gsl_FEATURE_BYTE_SPAN_TO_STD=" gsl_STRINGIFY(gsl_FEATURE_BYTE_SPAN_TO_STD) ", must be 98, 3, 11, 14, 17, or 20")
+# endif
+#else
+# define gsl_FEATURE_BYTE_SPAN_TO_STD 99 // default
+#endif
+#define gsl_FEATURE_BYTE_SPAN_TO_STD_() gsl_FEATURE_BYTE_SPAN_TO_STD
+
+#if defined( gsl_FEATURE_IMPLICIT_MACRO )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_FEATURE_IMPLICIT_MACRO )
+# pragma message ("invalid configuration value gsl_FEATURE_IMPLICIT_MACRO=" gsl_STRINGIFY(gsl_FEATURE_IMPLICIT_MACRO) ", must be 0 or 1")
+# endif
+#else
+# define gsl_FEATURE_IMPLICIT_MACRO 0 // default
+#endif
+#define gsl_FEATURE_IMPLICIT_MACRO_() gsl_FEATURE_IMPLICIT_MACRO
+
+#if defined( gsl_FEATURE_OWNER_MACRO )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_FEATURE_OWNER_MACRO )
+# pragma message ("invalid configuration value gsl_FEATURE_OWNER_MACRO=" gsl_STRINGIFY(gsl_FEATURE_OWNER_MACRO) ", must be 0 or 1")
+# endif
+#else
+# define gsl_FEATURE_OWNER_MACRO (gsl_CONFIG_DEFAULTS_VERSION == 0) // default
+#endif
+#define gsl_FEATURE_OWNER_MACRO_() gsl_FEATURE_OWNER_MACRO
+
+#if defined( gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD )
+# pragma message ("invalid configuration value gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD=" gsl_STRINGIFY(gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD) ", must be 0 or 1")
+# endif
+#else
+# define gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD 0 // default
+#endif
+# define gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD_() gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD
+
+#if defined( gsl_FEATURE_GSL_LITE_NAMESPACE )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_FEATURE_GSL_LITE_NAMESPACE )
+# pragma message ("invalid configuration value gsl_FEATURE_GSL_LITE_NAMESPACE=" gsl_STRINGIFY(gsl_FEATURE_GSL_LITE_NAMESPACE) ", must be 0 or 1")
+# endif
+#else
+# define gsl_FEATURE_GSL_LITE_NAMESPACE (gsl_CONFIG_DEFAULTS_VERSION >= 1) // default
+#endif
+#define gsl_FEATURE_GSL_LITE_NAMESPACE_() gsl_FEATURE_GSL_LITE_NAMESPACE
+
+// Configuration: Other
+
+#if defined( gsl_CONFIG_TRANSPARENT_NOT_NULL )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_CONFIG_TRANSPARENT_NOT_NULL )
+# pragma message ("invalid configuration value gsl_CONFIG_TRANSPARENT_NOT_NULL=" gsl_STRINGIFY(gsl_CONFIG_TRANSPARENT_NOT_NULL) ", must be 0 or 1")
+# endif
+# if gsl_CONFIG_TRANSPARENT_NOT_NULL && defined( gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF )
+# error configuration option gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF is meaningless if gsl_CONFIG_TRANSPARENT_NOT_NULL=1
+# endif
+#else
+# define gsl_CONFIG_TRANSPARENT_NOT_NULL (gsl_CONFIG_DEFAULTS_VERSION >= 1) // default
+#endif
+# define gsl_CONFIG_TRANSPARENT_NOT_NULL_() gsl_CONFIG_TRANSPARENT_NOT_NULL
+
+#if ! defined( gsl_CONFIG_DEPRECATE_TO_LEVEL )
+# if gsl_CONFIG_DEFAULTS_VERSION >= 1
+# define gsl_CONFIG_DEPRECATE_TO_LEVEL 6
+# else
+# define gsl_CONFIG_DEPRECATE_TO_LEVEL 0
+# endif
+#endif
+
+#if ! defined( gsl_CONFIG_SPAN_INDEX_TYPE )
+# define gsl_CONFIG_SPAN_INDEX_TYPE std::size_t
+#endif
+# define gsl_CONFIG_SPAN_INDEX_TYPE_() gsl_CONFIG_SPAN_INDEX_TYPE
+
+#if ! defined( gsl_CONFIG_INDEX_TYPE )
+# if gsl_CONFIG_DEFAULTS_VERSION >= 1
+// p0122r3 uses std::ptrdiff_t
+# define gsl_CONFIG_INDEX_TYPE std::ptrdiff_t
+# else
+# define gsl_CONFIG_INDEX_TYPE gsl_CONFIG_SPAN_INDEX_TYPE
+# endif
+#endif
+# define gsl_CONFIG_INDEX_TYPE_() gsl_CONFIG_INDEX_TYPE
+
+#if defined( gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR )
+# pragma message ("invalid configuration value gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR=" gsl_STRINGIFY(gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR) ", must be 0 or 1")
+# endif
+#else
+# define gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR (gsl_CONFIG_DEFAULTS_VERSION >= 1) // default
+#endif
+#define gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR_() gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR
+
+#if defined( gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF )
+# pragma message ("invalid configuration value gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF=" gsl_STRINGIFY(gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF) ", must be 0 or 1")
+# endif
+#else
+# define gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF 0 // default
+#endif
+#define gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF_() gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF
+
+#if defined( gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS )
+# pragma message ("invalid configuration value gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS=" gsl_STRINGIFY(gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS) ", must be 0 or 1")
+# endif
+#else
+# define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS 0 // default
+#endif
+#define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS_() gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS
+
+#if defined( gsl_CONFIG_ALLOWS_SPAN_COMPARISON )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_CONFIG_ALLOWS_SPAN_COMPARISON )
+# pragma message ("invalid configuration value gsl_CONFIG_ALLOWS_SPAN_COMPARISON=" gsl_STRINGIFY(gsl_CONFIG_ALLOWS_SPAN_COMPARISON) ", must be 0 or 1")
+# endif
+#else
+# define gsl_CONFIG_ALLOWS_SPAN_COMPARISON (gsl_CONFIG_DEFAULTS_VERSION == 0) // default
+#endif
+#define gsl_CONFIG_ALLOWS_SPAN_COMPARISON_() gsl_CONFIG_ALLOWS_SPAN_COMPARISON
+
+#if defined( gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON )
+# pragma message ("invalid configuration value gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON=" gsl_STRINGIFY(gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON) ", must be 0 or 1")
+# endif
+#else
+# define gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON 1 // default
+#endif
+#define gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON_() gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON
+
+#if defined( gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR )
+# pragma message ("invalid configuration value gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR=" gsl_STRINGIFY(gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR) ", must be 0 or 1")
+# endif
+#else
+# define gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR 0 // default
+#endif
+#define gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR_() gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR
+
+#if defined( gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION )
+# if ! gsl_CHECK_CFG_TOGGLE_VALUE_( gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION )
+# pragma message ("invalid configuration value gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION=" gsl_STRINGIFY(gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION) ", must be 0 or 1")
+# endif
+#else
+# define gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION (gsl_CONFIG_DEFAULTS_VERSION >= 1) // default
+#endif
+#define gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION_() gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION
+
+#if defined( gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_CONTRACT_CHECKING_AUDIT )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_CHECKING_AUDIT )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_CHECKING_AUDIT=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_CHECKING_AUDIT) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_CONTRACT_CHECKING_ON )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_CHECKING_ON )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_CHECKING_ON=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_CHECKING_ON) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_CONTRACT_CHECKING_OFF )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_CHECKING_OFF )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_CHECKING_OFF=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_CHECKING_OFF) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_VIOLATION_THROWS )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_VIOLATION_THROWS=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_VIOLATION_THROWS) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_TRAPS )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_VIOLATION_TRAPS )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_VIOLATION_TRAPS=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_VIOLATION_TRAPS) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER )
+# pragma message ("invalid configuration value gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER=" gsl_STRINGIFY(gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME )
+# pragma message ("invalid configuration value gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME=" gsl_STRINGIFY(gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME) "; macro must be defined without value")
+# endif
+#endif
+#if defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE )
+# if ! gsl_CHECK_CFG_NO_VALUE_( gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE )
+# pragma message ("invalid configuration value gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE=" gsl_STRINGIFY(gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE) "; macro must be defined without value")
+# endif
+#endif
+
+#if 1 < defined( gsl_CONFIG_CONTRACT_CHECKING_AUDIT ) + defined( gsl_CONFIG_CONTRACT_CHECKING_ON ) + defined( gsl_CONFIG_CONTRACT_CHECKING_OFF )
+# error only one of gsl_CONFIG_CONTRACT_CHECKING_AUDIT, gsl_CONFIG_CONTRACT_CHECKING_ON, and gsl_CONFIG_CONTRACT_CHECKING_OFF may be defined
+#endif
+#if 1 < defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS ) + defined( gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES ) + defined( gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS ) + defined( gsl_CONFIG_CONTRACT_VIOLATION_TRAPS ) + defined( gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER )
+# error only one of gsl_CONFIG_CONTRACT_VIOLATION_THROWS, gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES, gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS, gsl_CONFIG_CONTRACT_VIOLATION_TRAPS, and gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER may be defined
+#endif
+#if 1 < defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME ) + defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE )
+# error only one of gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME and gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE may be defined
+#endif
+
+#if 0 == defined( gsl_CONFIG_CONTRACT_CHECKING_AUDIT ) + defined( gsl_CONFIG_CONTRACT_CHECKING_ON ) + defined( gsl_CONFIG_CONTRACT_CHECKING_OFF )
+// select default
+# define gsl_CONFIG_CONTRACT_CHECKING_ON
+#endif
+#if 0 == defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS ) + defined( gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES ) + defined( gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS ) + defined( gsl_CONFIG_CONTRACT_VIOLATION_TRAPS ) + defined( gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER )
+// select default
+# define gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES
+#endif
+#if 0 == defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME ) + defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE )
+// select default
+# define gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE
+#endif
+
+// C++ language version detection (C++20 is speculative):
+// Note: VC14.0/1900 (VS2015) lacks too much from C++14.
+
+#ifndef gsl_CPLUSPLUS
+# if defined(_MSVC_LANG ) && !defined(__clang__)
+# define gsl_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG )
+# else
+# define gsl_CPLUSPLUS __cplusplus
+# endif
+#endif
+
+// C++ standard library version:
+
+#ifndef gsl_CPLUSPLUS_STDLIB
+# define gsl_CPLUSPLUS_STDLIB gsl_CPLUSPLUS
+#endif
+
+#define gsl_CPP98_OR_GREATER ( gsl_CPLUSPLUS >= 199711L )
+#define gsl_CPP11_OR_GREATER ( gsl_CPLUSPLUS >= 201103L )
+#define gsl_CPP14_OR_GREATER ( gsl_CPLUSPLUS >= 201402L )
+#define gsl_CPP17_OR_GREATER ( gsl_CPLUSPLUS >= 201703L )
+#define gsl_CPP20_OR_GREATER ( gsl_CPLUSPLUS >= 202000L )
+
+// C++ language version (represent 98 as 3):
+
+#define gsl_CPLUSPLUS_V ( gsl_CPLUSPLUS / 100 - (gsl_CPLUSPLUS > 200000 ? 2000 : 1994) )
+
+// half-open range [lo..hi):
+#define gsl_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) )
+
+// Compiler versions:
+
+// MSVC++ 6.0 _MSC_VER == 1200 gsl_COMPILER_MSVC_VERSION == 60 (Visual Studio 6.0)
+// MSVC++ 7.0 _MSC_VER == 1300 gsl_COMPILER_MSVC_VERSION == 70 (Visual Studio .NET 2002)
+// MSVC++ 7.1 _MSC_VER == 1310 gsl_COMPILER_MSVC_VERSION == 71 (Visual Studio .NET 2003)
+// MSVC++ 8.0 _MSC_VER == 1400 gsl_COMPILER_MSVC_VERSION == 80 (Visual Studio 2005)
+// MSVC++ 9.0 _MSC_VER == 1500 gsl_COMPILER_MSVC_VERSION == 90 (Visual Studio 2008)
+// MSVC++ 10.0 _MSC_VER == 1600 gsl_COMPILER_MSVC_VERSION == 100 (Visual Studio 2010)
+// MSVC++ 11.0 _MSC_VER == 1700 gsl_COMPILER_MSVC_VERSION == 110 (Visual Studio 2012)
+// MSVC++ 12.0 _MSC_VER == 1800 gsl_COMPILER_MSVC_VERSION == 120 (Visual Studio 2013)
+// MSVC++ 14.0 _MSC_VER == 1900 gsl_COMPILER_MSVC_VERSION == 140 (Visual Studio 2015)
+// MSVC++ 14.1 _MSC_VER >= 1910 gsl_COMPILER_MSVC_VERSION == 141 (Visual Studio 2017)
+// MSVC++ 14.2 _MSC_VER >= 1920 gsl_COMPILER_MSVC_VERSION == 142 (Visual Studio 2019)
+
+#if defined( _MSC_VER ) && ! defined( __clang__ )
+# define gsl_COMPILER_MSVC_VER (_MSC_VER )
+# define gsl_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) )
+# define gsl_COMPILER_MSVC_VERSION_FULL (_MSC_VER - 100 * ( 5 + (_MSC_VER < 1900 ) ) )
+#else
+# define gsl_COMPILER_MSVC_VER 0
+# define gsl_COMPILER_MSVC_VERSION 0
+# define gsl_COMPILER_MSVC_VERSION_FULL 0
+#endif
+
+#define gsl_COMPILER_VERSION( major, minor, patch ) ( 10 * ( 10 * (major) + (minor) ) + (patch) )
+
+// AppleClang 7.0.0 __apple_build_version__ == 7000172 gsl_COMPILER_APPLECLANG_VERSION == 700 (Xcode 7.0, 7.0.1) (LLVM 3.7.0)
+// AppleClang 7.0.0 __apple_build_version__ == 7000176 gsl_COMPILER_APPLECLANG_VERSION == 700 (Xcode 7.1) (LLVM 3.7.0)
+// AppleClang 7.0.2 __apple_build_version__ == 7000181 gsl_COMPILER_APPLECLANG_VERSION == 702 (Xcode 7.2, 7.2.1) (LLVM 3.7.0)
+// AppleClang 7.3.0 __apple_build_version__ == 7030029 gsl_COMPILER_APPLECLANG_VERSION == 730 (Xcode 7.3) (LLVM 3.8.0)
+// AppleClang 7.3.0 __apple_build_version__ == 7030031 gsl_COMPILER_APPLECLANG_VERSION == 730 (Xcode 7.3.1) (LLVM 3.8.0)
+// AppleClang 8.0.0 __apple_build_version__ == 8000038 gsl_COMPILER_APPLECLANG_VERSION == 800 (Xcode 8.0) (LLVM 3.9.0)
+// AppleClang 8.0.0 __apple_build_version__ == 8000042 gsl_COMPILER_APPLECLANG_VERSION == 800 (Xcode 8.1, 8.2, 8.2.1) (LLVM 3.9.0)
+// AppleClang 8.1.0 __apple_build_version__ == 8020038 gsl_COMPILER_APPLECLANG_VERSION == 810 (Xcode 8.3) (LLVM 3.9.0)
+// AppleClang 8.1.0 __apple_build_version__ == 8020041 gsl_COMPILER_APPLECLANG_VERSION == 810 (Xcode 8.3.1) (LLVM 3.9.0)
+// AppleClang 8.1.0 __apple_build_version__ == 8020042 gsl_COMPILER_APPLECLANG_VERSION == 810 (Xcode 8.3.2, 8.3.3) (LLVM 3.9.0)
+// AppleClang 9.0.0 __apple_build_version__ == 9000037 gsl_COMPILER_APPLECLANG_VERSION == 900 (Xcode 9.0) (LLVM 4.0.0)
+// AppleClang 9.0.0 __apple_build_version__ == 9000038 gsl_COMPILER_APPLECLANG_VERSION == 900 (Xcode 9.1) (LLVM 4.0.0)
+// AppleClang 9.0.0 __apple_build_version__ == 9000039 gsl_COMPILER_APPLECLANG_VERSION == 900 (Xcode 9.2) (LLVM 4.0.0)
+// AppleClang 9.1.0 __apple_build_version__ == 9020039 gsl_COMPILER_APPLECLANG_VERSION == 910 (Xcode 9.3, 9.3.1) (LLVM 5.0.2)
+// AppleClang 9.1.0 __apple_build_version__ == 9020039 gsl_COMPILER_APPLECLANG_VERSION == 910 (Xcode 9.4, 9.4.1) (LLVM 5.0.2)
+// AppleClang 10.0.0 __apple_build_version__ == 10001145 gsl_COMPILER_APPLECLANG_VERSION == 1000 (Xcode 10.0, 10.1) (LLVM 6.0.1)
+// AppleClang 10.0.1 __apple_build_version__ == 10010046 gsl_COMPILER_APPLECLANG_VERSION == 1001 (Xcode 10.2, 10.2.1, 10.3) (LLVM 7.0.0)
+// AppleClang 11.0.0 __apple_build_version__ == 11000033 gsl_COMPILER_APPLECLANG_VERSION == 1100 (Xcode 11.1, 11.2, 11.3, 11.3.1) (LLVM 8.0.0)
+// AppleClang 11.0.3 __apple_build_version__ == 11030032 gsl_COMPILER_APPLECLANG_VERSION == 1103 (Xcode 11.4, 11.4.1, 11.5, 11.6) (LLVM 9.0.0)
+// AppleClang 12.0.0 __apple_build_version__ == 12000032 gsl_COMPILER_APPLECLANG_VERSION == 1200 (Xcode 12.0–12.4) (LLVM 10.0.0)
+// AppleClang 12.0.5 __apple_build_version__ == 12050022 gsl_COMPILER_APPLECLANG_VERSION == 1205 (Xcode 12.5) (LLVM 10.0.0)
+
+#if defined( __apple_build_version__ )
+# define gsl_COMPILER_APPLECLANG_VERSION gsl_COMPILER_VERSION( __clang_major__, __clang_minor__, __clang_patchlevel__ )
+# define gsl_COMPILER_CLANG_VERSION 0
+#elif defined( __clang__ )
+# define gsl_COMPILER_APPLECLANG_VERSION 0
+# define gsl_COMPILER_CLANG_VERSION gsl_COMPILER_VERSION( __clang_major__, __clang_minor__, __clang_patchlevel__ )
+#else
+# define gsl_COMPILER_APPLECLANG_VERSION 0
+# define gsl_COMPILER_CLANG_VERSION 0
+#endif
+
+#if defined( __GNUC__ ) && ! defined( __clang__ )
+# define gsl_COMPILER_GNUC_VERSION gsl_COMPILER_VERSION( __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ )
+#else
+# define gsl_COMPILER_GNUC_VERSION 0
+#endif
+
+#if defined( __NVCC__ )
+# define gsl_COMPILER_NVCC_VERSION ( __CUDACC_VER_MAJOR__ * 10 + __CUDACC_VER_MINOR__ )
+#else
+# define gsl_COMPILER_NVCC_VERSION 0
+#endif
+
+#if defined( __ARMCC_VERSION )
+# define gsl_COMPILER_ARMCC_VERSION ( __ARMCC_VERSION / 10000 )
+# define gsl_COMPILER_ARMCC_VERSION_FULL __ARMCC_VERSION
+#else
+# define gsl_COMPILER_ARMCC_VERSION 0
+# define gsl_COMPILER_ARMCC_VERSION_FULL 0
+#endif
+
+// Compiler non-strict aliasing:
+
+#if defined(__clang__) || defined(__GNUC__)
+# define gsl_may_alias __attribute__((__may_alias__))
+#else
+# define gsl_may_alias
+#endif
+
+// Presence of gsl, language and library features:
+
+#define gsl_IN_STD( v ) ( ((v) == 98 ? 3 : (v)) >= gsl_CPLUSPLUS_V )
+
+#define gsl_DEPRECATE_TO_LEVEL( level ) ( level <= gsl_CONFIG_DEPRECATE_TO_LEVEL )
+#define gsl_FEATURE_TO_STD( feature ) gsl_IN_STD( gsl_FEATURE( feature##_TO_STD ) )
+#define gsl_FEATURE( feature ) gsl_EVALF_( gsl_FEATURE_##feature##_ )
+#define gsl_CONFIG( feature ) gsl_EVALF_( gsl_CONFIG_##feature##_ )
+#define gsl_HAVE( feature ) gsl_EVALF_( gsl_HAVE_##feature##_ )
+
+// Presence of wide character support:
+
+#ifdef __DJGPP__
+# define gsl_HAVE_WCHAR 0
+#else
+# define gsl_HAVE_WCHAR 1
+#endif
+#define gsl_HAVE_WCHAR_() gsl_HAVE_WCHAR
+
+// Presence of language & library features:
+
+#if gsl_COMPILER_CLANG_VERSION || gsl_COMPILER_APPLECLANG_VERSION
+# ifdef __OBJC__
+ // There are a bunch of inconsistencies about __EXCEPTIONS and __has_feature(cxx_exceptions) in Clang 3.4/3.5/3.6.
+ // We're interested in C++ exceptions, which can be checked by __has_feature(cxx_exceptions) in 3.5+.
+ // In pre-3.5, __has_feature(cxx_exceptions) can be true if ObjC exceptions are enabled, but C++ exceptions are disabled.
+ // The recommended way to check is `__EXCEPTIONS && __has_feature(cxx_exceptions)`.
+ // See https://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
+ // Note: this is only relevant in Objective-C++, thus the ifdef.
+# if __EXCEPTIONS && __has_feature(cxx_exceptions)
+# define gsl_HAVE_EXCEPTIONS 1
+# else
+# define gsl_HAVE_EXCEPTIONS 0
+# endif // __EXCEPTIONS && __has_feature(cxx_exceptions)
+# else
+ // clang-cl doesn't define __EXCEPTIONS for MSVC compatibility (see https://reviews.llvm.org/D4065).
+ // Neither does Clang in MS-compatiblity mode.
+ // Let's hope no one tries to build Objective-C++ code using MS-compatibility mode or clang-cl.
+# if __has_feature(cxx_exceptions)
+# define gsl_HAVE_EXCEPTIONS 1
+# else
+# define gsl_HAVE_EXCEPTIONS 0
+# endif
+# endif
+#elif gsl_COMPILER_GNUC_VERSION
+# if gsl_BETWEEN(gsl_COMPILER_GNUC_VERSION, 1, 500)
+# ifdef __EXCEPTIONS
+# define gsl_HAVE_EXCEPTIONS 1
+# else
+# define gsl_HAVE_EXCEPTIONS 0
+# endif // __EXCEPTIONS
+# else
+# ifdef __cpp_exceptions
+# define gsl_HAVE_EXCEPTIONS 1
+# else
+# define gsl_HAVE_EXCEPTIONS 0
+# endif // __cpp_exceptions
+# endif // gsl_BETWEEN(gsl_COMPILER_GNUC_VERSION, 1, 500)
+#elif gsl_COMPILER_MSVC_VERSION
+# ifdef _CPPUNWIND
+# define gsl_HAVE_EXCEPTIONS 1
+# else
+# define gsl_HAVE_EXCEPTIONS 0
+# endif // _CPPUNWIND
+#else
+// For all other compilers, assume exceptions are always enabled.
+# define gsl_HAVE_EXCEPTIONS 1
+#endif
+#define gsl_HAVE_EXCEPTIONS_() gsl_HAVE_EXCEPTIONS
+
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS ) && ! gsl_HAVE_EXCEPTIONS
+# error Cannot use gsl_CONFIG_CONTRACT_VIOLATION_THROWS if exceptions are disabled.
+#endif // defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS ) && !gsl_HAVE( EXCEPTIONS )
+
+#ifdef _HAS_CPP0X
+# define gsl_HAS_CPP0X _HAS_CPP0X
+#else
+# define gsl_HAS_CPP0X 0
+#endif
+
+#define gsl_CPP11_100 (gsl_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1600)
+#define gsl_CPP11_110 (gsl_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1700)
+#define gsl_CPP11_120 (gsl_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1800)
+#define gsl_CPP11_140 (gsl_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1900)
+
+#define gsl_CPP14_000 (gsl_CPP14_OR_GREATER)
+#define gsl_CPP14_120 (gsl_CPP14_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1800)
+#define gsl_CPP14_140 (gsl_CPP14_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1900)
+
+#define gsl_CPP17_000 (gsl_CPP17_OR_GREATER)
+#define gsl_CPP17_140 (gsl_CPP17_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1900)
+
+#define gsl_CPP11_140_CPP0X_90 (gsl_CPP11_140 || (gsl_COMPILER_MSVC_VER >= 1500 && gsl_HAS_CPP0X))
+#define gsl_CPP11_140_CPP0X_100 (gsl_CPP11_140 || (gsl_COMPILER_MSVC_VER >= 1600 && gsl_HAS_CPP0X))
+
+// Presence of C++11 language features:
+
+#define gsl_HAVE_C99_PREPROCESSOR gsl_CPP11_140
+#define gsl_HAVE_AUTO gsl_CPP11_100
+#define gsl_HAVE_RVALUE_REFERENCE gsl_CPP11_100
+#define gsl_HAVE_FUNCTION_REF_QUALIFIER ( gsl_CPP11_140 && ! gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 1, 481 ) )
+#define gsl_HAVE_ENUM_CLASS gsl_CPP11_110
+#define gsl_HAVE_ALIAS_TEMPLATE gsl_CPP11_120
+#define gsl_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG gsl_CPP11_120
+#define gsl_HAVE_EXPLICIT gsl_CPP11_120
+#define gsl_HAVE_VARIADIC_TEMPLATE gsl_CPP11_120
+#define gsl_HAVE_IS_DELETE gsl_CPP11_120
+#define gsl_HAVE_CONSTEXPR_11 gsl_CPP11_140
+#define gsl_HAVE_IS_DEFAULT gsl_CPP11_140
+#define gsl_HAVE_NOEXCEPT gsl_CPP11_140
+#define gsl_HAVE_NORETURN ( gsl_CPP11_140 && ! gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 1, 480 ) )
+#define gsl_HAVE_EXPRESSION_SFINAE gsl_CPP11_140
+#define gsl_HAVE_OVERRIDE_FINAL gsl_CPP11_110
+
+#define gsl_HAVE_C99_PREPROCESSOR_() gsl_HAVE_C99_PREPROCESSOR
+#define gsl_HAVE_AUTO_() gsl_HAVE_AUTO
+#define gsl_HAVE_RVALUE_REFERENCE_() gsl_HAVE_RVALUE_REFERENCE
+#define gsl_HAVE_FUNCTION_REF_QUALIFIER_() gsl_HAVE_FUNCTION_REF_QUALIFIER
+#define gsl_HAVE_ENUM_CLASS_() gsl_HAVE_ENUM_CLASS
+#define gsl_HAVE_ALIAS_TEMPLATE_() gsl_HAVE_ALIAS_TEMPLATE
+#define gsl_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG_() gsl_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG
+#define gsl_HAVE_EXPLICIT_() gsl_HAVE_EXPLICIT
+#define gsl_HAVE_VARIADIC_TEMPLATE_() gsl_HAVE_VARIADIC_TEMPLATE
+#define gsl_HAVE_IS_DELETE_() gsl_HAVE_IS_DELETE
+#define gsl_HAVE_CONSTEXPR_11_() gsl_HAVE_CONSTEXPR_11
+#define gsl_HAVE_IS_DEFAULT_() gsl_HAVE_IS_DEFAULT
+#define gsl_HAVE_NOEXCEPT_() gsl_HAVE_NOEXCEPT
+#define gsl_HAVE_NORETURN_() gsl_HAVE_NORETURN
+#define gsl_HAVE_EXPRESSION_SFINAE_() gsl_HAVE_EXPRESSION_SFINAE
+#define gsl_HAVE_OVERRIDE_FINAL_() gsl_HAVE_OVERRIDE_FINAL
+
+// Presence of C++14 language features:
+
+#define gsl_HAVE_CONSTEXPR_14 ( gsl_CPP14_000 && ! gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 1, 600 ) )
+#define gsl_HAVE_DECLTYPE_AUTO gsl_CPP14_140
+#define gsl_HAVE_DEPRECATED ( gsl_CPP14_140 && ! gsl_BETWEEN( gsl_COMPILER_MSVC_VERSION, 1, 142 ) )
+
+#define gsl_HAVE_CONSTEXPR_14_() gsl_HAVE_CONSTEXPR_14
+#define gsl_HAVE_DECLTYPE_AUTO_() gsl_HAVE_DECLTYPE_AUTO
+#define gsl_HAVE_DEPRECATED_() gsl_HAVE_DEPRECATED
+
+// Presence of C++17 language features:
+// MSVC: template parameter deduction guides since Visual Studio 2017 v15.7
+
+#define gsl_HAVE_ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE gsl_CPP17_000
+#define gsl_HAVE_DEDUCTION_GUIDES ( gsl_CPP17_000 && ! gsl_BETWEEN( gsl_COMPILER_MSVC_VERSION_FULL, 1, 1414 ) )
+#define gsl_HAVE_NODISCARD gsl_CPP17_000
+#define gsl_HAVE_CONSTEXPR_17 gsl_CPP17_OR_GREATER
+
+#define gsl_HAVE_ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE_() gsl_HAVE_ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE
+#define gsl_HAVE_DEDUCTION_GUIDES_() gsl_HAVE_DEDUCTION_GUIDES
+#define gsl_HAVE_NODISCARD_() gsl_HAVE_NODISCARD
+#define gsl_HAVE_CONSTEXPR_17_() gsl_HAVE_CONSTEXPR_17
+
+// Presence of C++20 language features:
+
+#define gsl_HAVE_CONSTEXPR_20 gsl_CPP20_OR_GREATER
+
+#define gsl_HAVE_CONSTEXPR_20_() gsl_HAVE_CONSTEXPR_20
+
+// Presence of C++ library features:
+
+#if gsl_BETWEEN( gsl_COMPILER_ARMCC_VERSION, 1, 600 )
+// Some versions of the ARM compiler apparently ship without a C++11 standard library despite having some C++11 support.
+# define gsl_STDLIB_CPP98_OR_GREATER gsl_CPP98_OR_GREATER
+# define gsl_STDLIB_CPP11_OR_GREATER 0
+# define gsl_STDLIB_CPP14_OR_GREATER 0
+# define gsl_STDLIB_CPP17_OR_GREATER 0
+# define gsl_STDLIB_CPP20_OR_GREATER 0
+#else
+# define gsl_STDLIB_CPP98_OR_GREATER gsl_CPP98_OR_GREATER
+# define gsl_STDLIB_CPP11_OR_GREATER gsl_CPP11_OR_GREATER
+# define gsl_STDLIB_CPP14_OR_GREATER gsl_CPP14_OR_GREATER
+# define gsl_STDLIB_CPP17_OR_GREATER gsl_CPP17_OR_GREATER
+# define gsl_STDLIB_CPP20_OR_GREATER gsl_CPP20_OR_GREATER
+#endif
+
+#define gsl_STDLIB_CPP11_100 (gsl_STDLIB_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1600)
+#define gsl_STDLIB_CPP11_110 (gsl_STDLIB_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1700)
+#define gsl_STDLIB_CPP11_120 (gsl_STDLIB_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1800)
+#define gsl_STDLIB_CPP11_140 (gsl_STDLIB_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1900)
+
+#define gsl_STDLIB_CPP14_000 (gsl_STDLIB_CPP14_OR_GREATER)
+#define gsl_STDLIB_CPP14_120 (gsl_STDLIB_CPP14_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1800)
+#define gsl_STDLIB_CPP14_140 (gsl_STDLIB_CPP14_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1900)
+
+#define gsl_STDLIB_CPP17_000 (gsl_STDLIB_CPP17_OR_GREATER)
+#define gsl_STDLIB_CPP17_140 (gsl_STDLIB_CPP17_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1900)
+
+#define gsl_STDLIB_CPP11_140_CPP0X_90 (gsl_STDLIB_CPP11_140 || (gsl_COMPILER_MSVC_VER >= 1500 && gsl_HAS_CPP0X))
+#define gsl_STDLIB_CPP11_140_CPP0X_100 (gsl_STDLIB_CPP11_140 || (gsl_COMPILER_MSVC_VER >= 1600 && gsl_HAS_CPP0X))
+
+#define gsl_HAVE_ADDRESSOF gsl_STDLIB_CPP17_000
+#define gsl_HAVE_ARRAY gsl_STDLIB_CPP11_110
+#define gsl_HAVE_TYPE_TRAITS gsl_STDLIB_CPP11_110
+#define gsl_HAVE_TR1_TYPE_TRAITS gsl_STDLIB_CPP11_110
+#define gsl_HAVE_CONTAINER_DATA_METHOD gsl_STDLIB_CPP11_140_CPP0X_90
+#define gsl_HAVE_STD_DATA gsl_STDLIB_CPP17_000
+#ifdef __cpp_lib_ssize
+# define gsl_HAVE_STD_SSIZE 1
+#else
+# define gsl_HAVE_STD_SSIZE ( gsl_COMPILER_GNUC_VERSION >= 1000 && __cplusplus > 201703L )
+#endif
+#define gsl_HAVE_HASH gsl_STDLIB_CPP11_120
+#define gsl_HAVE_SIZED_TYPES gsl_STDLIB_CPP11_140
+#define gsl_HAVE_MAKE_SHARED gsl_STDLIB_CPP11_140_CPP0X_100
+#define gsl_HAVE_SHARED_PTR gsl_STDLIB_CPP11_140_CPP0X_100
+#define gsl_HAVE_UNIQUE_PTR gsl_STDLIB_CPP11_140_CPP0X_100
+#define gsl_HAVE_MAKE_UNIQUE gsl_STDLIB_CPP14_120
+#define gsl_HAVE_MOVE_FORWARD gsl_STDLIB_CPP11_100
+#define gsl_HAVE_NULLPTR gsl_STDLIB_CPP11_100
+#define gsl_HAVE_UNCAUGHT_EXCEPTIONS gsl_STDLIB_CPP17_140
+#define gsl_HAVE_ADD_CONST gsl_HAVE_TYPE_TRAITS
+#define gsl_HAVE_INITIALIZER_LIST gsl_STDLIB_CPP11_120
+#define gsl_HAVE_INTEGRAL_CONSTANT gsl_HAVE_TYPE_TRAITS
+#define gsl_HAVE_REMOVE_CONST gsl_HAVE_TYPE_TRAITS
+#define gsl_HAVE_REMOVE_REFERENCE gsl_HAVE_TYPE_TRAITS
+#define gsl_HAVE_REMOVE_CVREF gsl_STDLIB_CPP20_OR_GREATER
+#define gsl_HAVE_TR1_ADD_CONST gsl_HAVE_TR1_TYPE_TRAITS
+#define gsl_HAVE_TR1_INTEGRAL_CONSTANT gsl_HAVE_TR1_TYPE_TRAITS
+#define gsl_HAVE_TR1_REMOVE_CONST gsl_HAVE_TR1_TYPE_TRAITS
+#define gsl_HAVE_TR1_REMOVE_REFERENCE gsl_HAVE_TR1_TYPE_TRAITS
+
+#define gsl_HAVE_ADDRESSOF_() gsl_HAVE_ADDRESSOF
+#define gsl_HAVE_ARRAY_() gsl_HAVE_ARRAY
+#define gsl_HAVE_TYPE_TRAITS_() gsl_HAVE_TYPE_TRAITS
+#define gsl_HAVE_TR1_TYPE_TRAITS_() gsl_HAVE_TR1_TYPE_TRAITS
+#define gsl_HAVE_CONTAINER_DATA_METHOD_() gsl_HAVE_CONTAINER_DATA_METHOD
+#define gsl_HAVE_HASH_() gsl_HAVE_HASH
+#define gsl_HAVE_STD_DATA_() gsl_HAVE_STD_DATA
+#define gsl_HAVE_STD_SSIZE_() gsl_HAVE_STD_SSIZE
+#define gsl_HAVE_SIZED_TYPES_() gsl_HAVE_SIZED_TYPES
+#define gsl_HAVE_MAKE_SHARED_() gsl_HAVE_MAKE_SHARED
+#define gsl_HAVE_MOVE_FORWARD_() gsl_HAVE_MOVE_FORWARD
+#define gsl_HAVE_NULLPTR_() gsl_HAVE_NULLPTR // It's a language feature but needs library support, so we list it as a library feature.
+#define gsl_HAVE_SHARED_PTR_() gsl_HAVE_SHARED_PTR
+#define gsl_HAVE_UNIQUE_PTR_() gsl_HAVE_UNIQUE_PTR
+#define gsl_HAVE_MAKE_UNIQUE_() gsl_HAVE_MAKE_UNIQUE
+#define gsl_HAVE_UNCAUGHT_EXCEPTIONS_() gsl_HAVE_UNCAUGHT_EXCEPTIONS
+#define gsl_HAVE_ADD_CONST_() gsl_HAVE_ADD_CONST
+#define gsl_HAVE_INITIALIZER_LIST_() gsl_HAVE_INITIALIZER_LIST // It's a language feature but needs library support, so we list it as a library feature.
+#define gsl_HAVE_INTEGRAL_CONSTANT_() gsl_HAVE_INTEGRAL_CONSTANT
+#define gsl_HAVE_REMOVE_CONST_() gsl_HAVE_REMOVE_CONST
+#define gsl_HAVE_REMOVE_REFERENCE_() gsl_HAVE_REMOVE_REFERENCE
+#define gsl_HAVE_REMOVE_CVREF_() gsl_HAVE_REMOVE_CVREF
+#define gsl_HAVE_TR1_ADD_CONST_() gsl_HAVE_TR1_ADD_CONST
+#define gsl_HAVE_TR1_INTEGRAL_CONSTANT_() gsl_HAVE_TR1_INTEGRAL_CONSTANT
+#define gsl_HAVE_TR1_REMOVE_CONST_() gsl_HAVE_TR1_REMOVE_CONST
+#define gsl_HAVE_TR1_REMOVE_REFERENCE_() gsl_HAVE_TR1_REMOVE_REFERENCE
+
+// C++ feature usage:
+
+#if gsl_HAVE( ADDRESSOF )
+# define gsl_ADDRESSOF(x) std::addressof(x)
+#else
+# define gsl_ADDRESSOF(x) (&x)
+#endif
+
+#if gsl_HAVE( CONSTEXPR_11 )
+# define gsl_constexpr constexpr
+#else
+# define gsl_constexpr /*constexpr*/
+#endif
+
+#if gsl_HAVE( CONSTEXPR_14 )
+# define gsl_constexpr14 constexpr
+#else
+# define gsl_constexpr14 /*constexpr*/
+#endif
+
+#if gsl_HAVE( CONSTEXPR_17 )
+# define gsl_constexpr17 constexpr
+#else
+# define gsl_constexpr17 /*constexpr*/
+#endif
+
+#if gsl_HAVE( CONSTEXPR_20 )
+# define gsl_constexpr20 constexpr
+#else
+# define gsl_constexpr20 /*constexpr*/
+#endif
+
+#if gsl_HAVE( EXPLICIT )
+# define gsl_explicit explicit
+#else
+# define gsl_explicit /*explicit*/
+#endif
+
+#if gsl_FEATURE( IMPLICIT_MACRO )
+# define implicit /*implicit*/
+#endif
+
+#if gsl_HAVE( IS_DELETE )
+# define gsl_is_delete = delete
+#else
+# define gsl_is_delete
+#endif
+
+#if gsl_HAVE( IS_DELETE )
+# define gsl_is_delete_access public
+#else
+# define gsl_is_delete_access private
+#endif
+
+#if gsl_HAVE( NOEXCEPT )
+# define gsl_noexcept noexcept
+# define gsl_noexcept_if( expr ) noexcept( expr )
+#else
+# define gsl_noexcept throw()
+# define gsl_noexcept_if( expr ) /*noexcept( expr )*/
+#endif
+#if defined( gsl_TESTING_ )
+# define gsl_noexcept_not_testing
+#else
+# define gsl_noexcept_not_testing gsl_noexcept
+#endif
+
+#if gsl_HAVE( NULLPTR )
+# define gsl_nullptr nullptr
+#else
+# define gsl_nullptr NULL
+#endif
+
+#if gsl_HAVE( NODISCARD )
+# define gsl_NODISCARD [[nodiscard]]
+#else
+# define gsl_NODISCARD
+#endif
+
+#if gsl_HAVE( NORETURN )
+# define gsl_NORETURN [[noreturn]]
+#elif defined(_MSC_VER)
+# define gsl_NORETURN __declspec(noreturn)
+#elif gsl_COMPILER_GNUC_VERSION || gsl_COMPILER_CLANG_VERSION || gsl_COMPILER_APPLECLANG_VERSION || gsl_COMPILER_ARMCC_VERSION
+# define gsl_NORETURN __attribute__((noreturn))
+#else
+# define gsl_NORETURN
+#endif
+
+#if gsl_HAVE( DEPRECATED ) && ! defined( gsl_TESTING_ )
+# define gsl_DEPRECATED [[deprecated]]
+# define gsl_DEPRECATED_MSG( msg ) [[deprecated( msg )]]
+#else
+# define gsl_DEPRECATED
+# define gsl_DEPRECATED_MSG( msg )
+#endif
+
+#if gsl_HAVE( C99_PREPROCESSOR )
+# if gsl_CPP20_OR_GREATER
+# define gsl_CONSTRAINT(...) __VA_ARGS__
+# else
+# define gsl_CONSTRAINT(...) typename
+# endif
+#endif
+
+#if gsl_HAVE( TYPE_TRAITS )
+# define gsl_STATIC_ASSERT_( cond, msg ) static_assert( cond, msg )
+#else
+# define gsl_STATIC_ASSERT_( cond, msg ) ( ( void )sizeof( char[1 - 2*!!( cond ) ] ) )
+#endif
+
+#if gsl_HAVE( TYPE_TRAITS )
+
+#define gsl_DEFINE_ENUM_BITMASK_OPERATORS_( ENUM ) \
+ gsl_NODISCARD gsl_api inline gsl_constexpr ENUM \
+ operator~( ENUM val ) gsl_noexcept \
+ { \
+ typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
+ return ENUM( ~U( val ) ); \
+ } \
+ gsl_NODISCARD gsl_api inline gsl_constexpr ENUM \
+ operator|( ENUM lhs, ENUM rhs ) gsl_noexcept \
+ { \
+ typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
+ return ENUM( U( lhs ) | U( rhs ) ); \
+ } \
+ gsl_NODISCARD gsl_api inline gsl_constexpr ENUM \
+ operator&( ENUM lhs, ENUM rhs ) gsl_noexcept \
+ { \
+ typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
+ return ENUM( U( lhs ) & U( rhs ) ); \
+ } \
+ gsl_NODISCARD gsl_api inline gsl_constexpr ENUM \
+ operator^( ENUM lhs, ENUM rhs ) gsl_noexcept \
+ { \
+ typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
+ return ENUM( U( lhs ) ^ U( rhs ) ); \
+ } \
+ gsl_api inline gsl_constexpr14 ENUM & \
+ operator|=( ENUM & lhs, ENUM rhs ) gsl_noexcept \
+ { \
+ return lhs = lhs | rhs; \
+ } \
+ gsl_api inline gsl_constexpr14 ENUM & \
+ operator&=( ENUM & lhs, ENUM rhs ) gsl_noexcept \
+ { \
+ return lhs = lhs & rhs; \
+ } \
+ gsl_api inline gsl_constexpr14 ENUM & \
+ operator^=( ENUM & lhs, ENUM rhs ) gsl_noexcept \
+ { \
+ return lhs = lhs ^ rhs; \
+ }
+
+#define gsl_DEFINE_ENUM_RELATIONAL_OPERATORS_( ENUM ) \
+ gsl_NODISCARD gsl_api inline gsl_constexpr bool \
+ operator<( ENUM lhs, ENUM rhs ) gsl_noexcept \
+ { \
+ typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
+ return U( lhs ) < U( rhs ); \
+ } \
+ gsl_NODISCARD gsl_api inline gsl_constexpr bool \
+ operator>( ENUM lhs, ENUM rhs ) gsl_noexcept \
+ { \
+ typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
+ return U( lhs ) > U( rhs ); \
+ } \
+ gsl_NODISCARD gsl_api inline gsl_constexpr bool \
+ operator<=( ENUM lhs, ENUM rhs ) gsl_noexcept \
+ { \
+ typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
+ return U( lhs ) <= U( rhs ); \
+ } \
+ gsl_NODISCARD gsl_api inline gsl_constexpr bool \
+ operator>=( ENUM lhs, ENUM rhs ) gsl_noexcept \
+ { \
+ typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
+ return U( lhs ) >= U( rhs ); \
+ }
+
+ //
+ // Defines bitmask operators `|`, `&`, `^`, `~`, `|=`, `&=`, and `^=` for the given enum type.
+ //
+ // enum class Vegetables { tomato = 0b001, onion = 0b010, eggplant = 0b100 };
+ // gsl_DEFINE_ENUM_BITMASK_OPERATORS( Vegetables )
+ //
+#define gsl_DEFINE_ENUM_BITMASK_OPERATORS( ENUM ) gsl_DEFINE_ENUM_BITMASK_OPERATORS_( ENUM )
+
+ //
+ // Defines relational operators `<`, `>`, `<=`, `>=` for the given enum type.
+ //
+ // enum class OperatorPrecedence { additive = 0, multiplicative = 1, power = 2 };
+ // gsl_DEFINE_ENUM_RELATIONAL_OPERATORS( OperatorPrecedence )
+ //
+#define gsl_DEFINE_ENUM_RELATIONAL_OPERATORS( ENUM ) gsl_DEFINE_ENUM_RELATIONAL_OPERATORS_( ENUM )
+
+#endif // gsl_HAVE( TYPE_TRAITS )
+
+#define gsl_DIMENSION_OF( a ) ( sizeof(a) / sizeof(0[a]) )
+
+
+// Method enabling (C++98, VC120 (VS2013) cannot use __VA_ARGS__)
+
+#if gsl_HAVE( EXPRESSION_SFINAE )
+# define gsl_TRAILING_RETURN_TYPE_(T) auto
+# define gsl_RETURN_DECLTYPE_(EXPR) -> decltype( EXPR )
+#else
+# define gsl_TRAILING_RETURN_TYPE_(T) T
+# define gsl_RETURN_DECLTYPE_(EXPR)
+#endif
+
+// NOTE: When using SFINAE in gsl-lite, please note that overloads of function templates must always use SFINAE with non-type default arguments
+// as explained in https://en.cppreference.com/w/cpp/types/enable_if#Notes. `gsl_ENABLE_IF_()` implements graceful fallback to default
+// type arguments (for compilers that don't support non-type default arguments); please verify that this is appropriate in the given
+// situation, and add additional checks if necessary.
+//
+// Also, please note that `gsl_ENABLE_IF_()` doesn't enforce the constraint at all if no compiler/library support is available (i.e. pre-C++11).
+
+#if gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG )
+# if !gsl_BETWEEN( gsl_COMPILER_MSVC_VERSION, 1, 140 ) // VS 2013 seems to have trouble with SFINAE for default non-type arguments
+# define gsl_ENABLE_IF_(VA) , typename std::enable_if< ( VA ), int >::type = 0
+# else
+# define gsl_ENABLE_IF_(VA) , typename = typename std::enable_if< ( VA ), ::gsl::detail::enabler >::type
+# endif
+#else
+# define gsl_ENABLE_IF_(VA)
+#endif
+
+
+// Other features:
+
+#define gsl_HAVE_CONSTRAINED_SPAN_CONTAINER_CTOR ( gsl_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG && gsl_HAVE_CONTAINER_DATA_METHOD )
+#define gsl_HAVE_CONSTRAINED_SPAN_CONTAINER_CTOR_() gsl_HAVE_CONSTRAINED_SPAN_CONTAINER_CTOR
+
+#define gsl_HAVE_UNCONSTRAINED_SPAN_CONTAINER_CTOR ( gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR && gsl_COMPILER_NVCC_VERSION == 0 )
+#define gsl_HAVE_UNCONSTRAINED_SPAN_CONTAINER_CTOR_() gsl_HAVE_UNCONSTRAINED_SPAN_CONTAINER_CTOR
+
+// GSL API (e.g. for CUDA platform):
+
+// Guidelines for using `gsl_api`:
+//
+// NVCC imposes the restriction that a function annotated `__host__ __device__` cannot call host-only or device-only functions.
+// This makes `gsl_api` inappropriate for generic functions that call unknown code, e.g. the template constructors of `span<>`
+// or functions like `finally()` which accept an arbitrary function object.
+// It is often preferable to annotate functions only with `gsl_constexpr` or `gsl_constexpr14`. The "extended constexpr" mode
+// of NVCC (currently an experimental feature) will implicitly consider constexpr functions `__host__ __device__` functions
+// but tolerates calls to host-only or device-only functions.
+
+#ifndef gsl_api
+# ifdef __CUDACC__
+# define gsl_api __host__ __device__
+# else
+# define gsl_api /*gsl_api*/
+# endif
+#endif
+
+// Additional includes:
+
+#if ! gsl_CPP11_OR_GREATER
+# include <algorithm> // for swap() before C++11
+#endif // ! gsl_CPP11_OR_GREATER
+
+#if gsl_HAVE( ARRAY )
+# include <array> // indirectly includes reverse_iterator<>
+#endif
+
+#if ! gsl_HAVE( ARRAY )
+# include <iterator> // for reverse_iterator<>
+#endif
+
+#if ! gsl_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) || ! gsl_HAVE( AUTO )
+# include <vector>
+#endif
+
+#if gsl_HAVE( INITIALIZER_LIST )
+# include <initializer_list>
+#endif
+
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS )
+# include <cassert>
+#endif
+
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_TRAPS ) && gsl_COMPILER_MSVC_VERSION >= 110 // __fastfail() supported by VS 2012 and later
+# include <intrin.h>
+#endif
+
+#if gsl_HAVE( ENUM_CLASS ) && gsl_COMPILER_ARMCC_VERSION
+# include <endian.h>
+#endif
+
+#if gsl_HAVE( TYPE_TRAITS )
+# include <type_traits> // for enable_if<>,
+ // add_const<>, add_pointer<>, common_type<>, make_signed<>, remove_cv<>, remove_const<>, remove_volatile<>, remove_reference<>, remove_cvref<>, remove_pointer<>, underlying_type<>,
+ // is_assignable<>, is_constructible<>, is_const<>, is_convertible<>, is_integral<>, is_pointer<>, is_signed<>,
+ // integral_constant<>, declval()
+#elif gsl_HAVE( TR1_TYPE_TRAITS )
+# include <tr1/type_traits> // for add_const<>, remove_cv<>, remove_const<>, remove_volatile<>, remove_reference<>, integral_constant<>
+#endif
+
+#if gsl_FEATURE( EXPERIMENTAL_RETURN_GUARD )
+
+// Declare __cxa_get_globals() or equivalent in namespace gsl::detail for uncaught_exceptions():
+
+# if ! gsl_HAVE( UNCAUGHT_EXCEPTIONS )
+# if defined( _MSC_VER ) // MS-STL with either MSVC or clang-cl
+namespace gsl { namespace detail { extern "C" char * __cdecl _getptd(); } }
+# elif gsl_COMPILER_CLANG_VERSION || gsl_COMPILER_GNUC_VERSION || gsl_COMPILER_APPLECLANG_VERSION
+# if defined( __GLIBCXX__ ) || defined( __GLIBCPP__ ) // libstdc++: prototype from cxxabi.h
+# include <cxxabi.h>
+# elif ! defined( BOOST_CORE_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED_ ) // libc++: prototype from Boost?
+# if defined( __FreeBSD__ ) || defined( __OpenBSD__ )
+namespace __cxxabiv1 { struct __cxa_eh_globals; extern "C" __cxa_eh_globals * __cxa_get_globals(); }
+# else
+namespace __cxxabiv1 { struct __cxa_eh_globals; extern "C" __cxa_eh_globals * __cxa_get_globals() gsl_noexcept; }
+# endif
+# endif
+ namespace gsl { namespace detail { using ::__cxxabiv1::__cxa_get_globals; } }
+# endif
+# endif // ! gsl_HAVE( UNCAUGHT_EXCEPTIONS )
+#endif // gsl_FEATURE( EXPERIMENTAL_RETURN_GUARD )
+
+
+// MSVC warning suppression macros:
+
+#if gsl_COMPILER_MSVC_VERSION >= 140 && ! gsl_COMPILER_NVCC_VERSION
+# define gsl_SUPPRESS_MSGSL_WARNING(expr) /* Pimm: note disabled for intel [[gsl::suppress(expr)]]*/
+# define gsl_SUPPRESS_MSVC_WARNING(code, descr) __pragma(warning(suppress: code) )
+# define gsl_DISABLE_MSVC_WARNINGS(codes) __pragma(warning(push)) __pragma(warning(disable: codes))
+# define gsl_RESTORE_MSVC_WARNINGS() __pragma(warning(pop ))
+#else
+// TODO: define for Clang
+# define gsl_SUPPRESS_MSGSL_WARNING(expr)
+# define gsl_SUPPRESS_MSVC_WARNING(code, descr)
+# define gsl_DISABLE_MSVC_WARNINGS(codes)
+# define gsl_RESTORE_MSVC_WARNINGS()
+#endif
+
+// Suppress the following MSVC GSL warnings:
+// - C26432: gsl::c.21 : if you define or delete any default operation in the type '...', define or delete them all
+// - C26410: gsl::r.32 : the parameter 'ptr' is a reference to const unique pointer, use const T* or const T& instead
+// - C26415: gsl::r.30 : smart pointer parameter 'ptr' is used only to access contained pointer. Use T* or T& instead
+// - C26418: gsl::r.36 : shared pointer parameter 'ptr' is not copied or moved. Use T* or T& instead
+// - C26472: gsl::t.1 : don't use a static_cast for arithmetic conversions;
+// use brace initialization, gsl::narrow_cast or gsl::narrow
+// - C26439: gsl::f.6 : special function 'function' can be declared 'noexcept'
+// - C26440: gsl::f.6 : function 'function' can be declared 'noexcept'
+// - C26455: gsl::f.6 : default constructor may not throw. Declare it 'noexcept'
+// - C26473: gsl::t.1 : don't cast between pointer types where the source type and the target type are the same
+// - C26481: gsl::b.1 : don't use pointer arithmetic. Use span instead
+// - C26482: gsl::b.2 : only index into arrays using constant expressions
+// - C26446: gdl::b.4 : prefer to use gsl::at() instead of unchecked subscript operator
+// - C26490: gsl::t.1 : don't use reinterpret_cast
+// - C26487: gsl::l.4 : don't return a pointer '(<some number>'s result)' that may be invalid
+// - C26457: es.48 : (void) should not be used to ignore return values, use 'std::ignore =' instead
+
+gsl_DISABLE_MSVC_WARNINGS( 26432 26410 26415 26418 26472 26439 26440 26455 26473 26481 26482 26446 26490 26487 26457 )
+
+namespace gsl {
+
+// forward declare span<>:
+
+template< class T >
+class span;
+
+// C++98 emulation:
+
+namespace std98 {
+
+// We implement `equal()` and `lexicographical_compare()` here to avoid having to pull in the <algorithm> header.
+template< class InputIt1, class InputIt2 >
+bool equal( InputIt1 first1, InputIt1 last1, InputIt2 first2 )
+{
+ // Implementation borrowed from https://en.cppreference.com/w/cpp/algorithm/equal.
+ for ( ; first1 != last1; ++first1, ++first2 )
+ {
+ if ( ! (*first1 == *first2 ) ) return false;
+ }
+ return true;
+}
+template< class InputIt1, class InputIt2 >
+bool lexicographical_compare( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2 )
+{
+ // Implementation borrowed from https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare.
+ for ( ; first1 != last1 && first2 != last2; ++first1, (void) ++first2 )
+ {
+ if ( *first1 < *first2 ) return true;
+ if ( *first2 < *first1 ) return false;
+ }
+ return first1 == last1 && first2 != last2;
+}
+
+} // namespace std98
+
+// C++11 emulation:
+
+namespace std11 {
+
+#if gsl_HAVE( ADD_CONST )
+
+using std::add_const;
+
+#elif gsl_HAVE( TR1_ADD_CONST )
+
+using std::tr1::add_const;
+
+#else
+
+template< class T > struct add_const { typedef const T type; };
+
+#endif // gsl_HAVE( ADD_CONST )
+
+#if gsl_HAVE( REMOVE_CONST )
+
+using std::remove_cv;
+using std::remove_const;
+using std::remove_volatile;
+
+#elif gsl_HAVE( TR1_REMOVE_CONST )
+
+using std::tr1::remove_cv;
+using std::tr1::remove_const;
+using std::tr1::remove_volatile;
+
+#else
+
+template< class T > struct remove_const { typedef T type; };
+template< class T > struct remove_const<T const> { typedef T type; };
+
+template< class T > struct remove_volatile { typedef T type; };
+template< class T > struct remove_volatile<T volatile> { typedef T type; };
+
+template< class T >
+struct remove_cv
+{
+ typedef typename remove_volatile<typename remove_const<T>::type>::type type;
+};
+
+#endif // gsl_HAVE( REMOVE_CONST )
+
+#if gsl_HAVE( REMOVE_REFERENCE )
+
+using std::remove_reference;
+
+#elif gsl_HAVE( TR1_REMOVE_REFERENCE )
+
+using std::tr1::remove_reference;
+
+#else
+
+template< class T > struct remove_reference { typedef T type; };
+template< class T > struct remove_reference<T&> { typedef T type; };
+# if gsl_HAVE( RVALUE_REFERENCE )
+template< class T > struct remove_reference<T&&> { typedef T type; };
+# endif
+
+#endif // gsl_HAVE( REMOVE_REFERENCE )
+
+
+#if gsl_HAVE( INTEGRAL_CONSTANT )
+
+using std::integral_constant;
+using std::true_type;
+using std::false_type;
+
+#elif gsl_HAVE( TR1_INTEGRAL_CONSTANT )
+
+using std::tr1::integral_constant;
+using std::tr1::true_type;
+using std::tr1::false_type;
+
+#else
+
+template< class T, T v > struct integral_constant { enum { value = v }; };
+typedef integral_constant< bool, true > true_type;
+typedef integral_constant< bool, false > false_type;
+
+#endif
+
+#if gsl_HAVE( TYPE_TRAITS )
+
+using std::underlying_type;
+
+#elif gsl_HAVE( TR1_TYPE_TRAITS )
+
+using std::tr1::underlying_type;
+
+#else
+
+// We could try to define `underlying_type<>` for pre-C++11 here, but let's not until someone actually needs it.
+
+#endif
+
+} // namespace std11
+
+// C++14 emulation:
+
+namespace std14 {
+
+#if gsl_HAVE( UNIQUE_PTR )
+# if gsl_HAVE( MAKE_UNIQUE )
+
+using std::make_unique;
+
+# elif gsl_HAVE( VARIADIC_TEMPLATE )
+
+template< class T, class... Args >
+gsl_NODISCARD std::unique_ptr<T>
+make_unique( Args &&... args )
+{
+ return std::unique_ptr<T>( new T( std::forward<Args>( args )... ) );
+}
+
+# endif // gsl_HAVE( MAKE_UNIQUE ), gsl_HAVE( VARIADIC_TEMPLATE )
+#endif // gsl_HAVE( UNIQUE_PTR )
+
+} // namespace std14
+
+namespace detail {
+
+#if gsl_HAVE( VARIADIC_TEMPLATE )
+
+template < bool V0, class T0, class... Ts > struct conjunction_ { using type = T0; };
+template < class T0, class T1, class... Ts > struct conjunction_<true, T0, T1, Ts...> : conjunction_<T1::value, T1, Ts...> { };
+template < bool V0, class T0, class... Ts > struct disjunction_ { using type = T0; };
+template < class T0, class T1, class... Ts > struct disjunction_<false, T0, T1, Ts...> : disjunction_<T1::value, T1, Ts...> { };
+
+#endif
+
+template <typename> struct dependent_false : std11::integral_constant<bool, false> { };
+
+} // namespace detail
+
+// C++17 emulation:
+
+namespace std17 {
+
+template< bool v > struct bool_constant : std11::integral_constant<bool, v>{};
+
+#if gsl_CPP11_120
+
+template < class... Ts > struct conjunction;
+template < > struct conjunction< > : std11::true_type { };
+template < class T0, class... Ts > struct conjunction<T0, Ts...> : detail::conjunction_<T0::value, T0, Ts...>::type { };
+template < class... Ts > struct disjunction;
+template < > struct disjunction< > : std11::false_type { };
+template < class T0, class... Ts > struct disjunction<T0, Ts...> : detail::disjunction_<T0::value, T0, Ts...>::type { };
+template < class T > struct negation : std11::integral_constant<bool, !T::value> { };
+
+# if gsl_CPP14_OR_GREATER
+
+template < class... Ts > constexpr bool conjunction_v = conjunction<Ts...>::value;
+template < class... Ts > constexpr bool disjunction_v = disjunction<Ts...>::value;
+template < class T > constexpr bool negation_v = negation<T>::value;
+
+# endif // gsl_CPP14_OR_GREATER
+
+template< class... Ts >
+struct make_void { typedef void type; };
+
+template< class... Ts >
+using void_t = typename make_void< Ts... >::type;
+
+#endif // gsl_CPP11_120
+
+#if gsl_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR )
+
+template< class T, size_t N >
+gsl_NODISCARD gsl_api inline gsl_constexpr auto
+size( T const(&)[N] ) gsl_noexcept -> size_t
+{
+ return N;
+}
+
+template< class C >
+gsl_NODISCARD inline gsl_constexpr auto
+size( C const & cont ) -> decltype( cont.size() )
+{
+ return cont.size();
+}
+
+template< class T, size_t N >
+gsl_NODISCARD gsl_api inline gsl_constexpr auto
+data( T(&arr)[N] ) gsl_noexcept -> T*
+{
+ return &arr[0];
+}
+
+template< class C >
+gsl_NODISCARD inline gsl_constexpr auto
+data( C & cont ) -> decltype( cont.data() )
+{
+ return cont.data();
+}
+
+template< class C >
+gsl_NODISCARD inline gsl_constexpr auto
+data( C const & cont ) -> decltype( cont.data() )
+{
+ return cont.data();
+}
+
+template< class E >
+gsl_NODISCARD inline gsl_constexpr auto
+data( std::initializer_list<E> il ) gsl_noexcept -> E const *
+{
+ return il.begin();
+}
+
+#endif // gsl_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR )
+
+} // namespace std17
+
+// C++20 emulation:
+
+namespace std20 {
+
+#if gsl_CPP11_100
+
+struct identity
+{
+ template < class T >
+ gsl_constexpr T && operator ()( T && arg ) const gsl_noexcept
+ {
+ return std::forward<T>( arg );
+ }
+};
+
+# if gsl_HAVE( ENUM_CLASS )
+enum class endian
+{
+# if defined( _WIN32 )
+ little = 0,
+ big = 1,
+ native = little
+# elif gsl_COMPILER_GNUC_VERSION || gsl_COMPILER_CLANG_VERSION || gsl_COMPILER_APPLECLANG_VERSION
+ little = __ORDER_LITTLE_ENDIAN__,
+ big = __ORDER_BIG_ENDIAN__,
+ native = __BYTE_ORDER__
+# elif gsl_COMPILER_ARMCC_VERSION
+ // from <endian.h> header file
+ little = __LITTLE_ENDIAN,
+ big = __BIG_ENDIAN,
+ native = __BYTE_ORDER
+# else
+// Do not define any endianness constants for unknown compilers.
+# endif
+};
+# endif // gsl_HAVE( ENUM_CLASS )
+
+#endif // gsl_CPP11_100
+
+template< class T >
+struct type_identity
+{
+ typedef T type;
+};
+#if gsl_HAVE( ALIAS_TEMPLATE )
+template< class T >
+using type_identity_t = typename type_identity<T>::type;
+#endif // gsl_HAVE( ALIAS_TEMPLATE )
+
+#if gsl_HAVE( STD_SSIZE )
+
+using std::ssize;
+
+#elif gsl_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR )
+
+template < class C >
+gsl_NODISCARD gsl_constexpr auto
+ssize( C const & c )
+ -> typename std::common_type<std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type
+{
+ using R = typename std::common_type<std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type;
+ return static_cast<R>( c.size() );
+}
+
+template <class T, std::size_t N>
+gsl_NODISCARD gsl_constexpr auto
+ssize( T const(&)[N] ) gsl_noexcept -> std::ptrdiff_t
+{
+ return std::ptrdiff_t( N );
+}
+
+#endif // gsl_HAVE( STD_SSIZE )
+
+#if gsl_HAVE( REMOVE_CVREF )
+
+using std::remove_cvref;
+
+#else
+
+template< class T > struct remove_cvref { typedef typename std11::remove_cv< typename std11::remove_reference< T >::type >::type type; };
+
+#endif // gsl_HAVE( REMOVE_CVREF )
+
+} // namespace std20
+
+namespace detail {
+
+/// for gsl_ENABLE_IF_()
+
+/*enum*/ class enabler{};
+
+#if gsl_HAVE( TYPE_TRAITS )
+
+template< class Q >
+struct is_span_oracle : std::false_type{};
+
+template< class T>
+struct is_span_oracle< span<T> > : std::true_type{};
+
+template< class Q >
+struct is_span : is_span_oracle< typename std::remove_cv<Q>::type >{};
+
+template< class Q >
+struct is_std_array_oracle : std::false_type{};
+
+# if gsl_HAVE( ARRAY )
+
+template< class T, std::size_t Extent >
+struct is_std_array_oracle< std::array<T, Extent> > : std::true_type{};
+
+# endif
+
+template< class Q >
+struct is_std_array : is_std_array_oracle< typename std::remove_cv<Q>::type >{};
+
+template< class Q >
+struct is_array : std::false_type{};
+
+template< class T >
+struct is_array<T[]> : std::true_type{};
+
+template< class T, std::size_t N >
+struct is_array<T[N]> : std::true_type{};
+
+# if gsl_CPP11_140 && ! gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 1, 500 )
+
+template< class, class = void >
+struct has_size_and_data : std::false_type{};
+
+template< class C >
+struct has_size_and_data
+<
+ C, std17::void_t<
+ decltype( std17::size(std::declval<C>()) ),
+ decltype( std17::data(std::declval<C>()) ) >
+> : std::true_type{};
+
+template< class, class, class = void >
+struct is_compatible_element : std::false_type {};
+
+template< class C, class E >
+struct is_compatible_element
+<
+ C, E, std17::void_t<
+ decltype( std17::data(std::declval<C>()) ),
+ typename std::remove_pointer<decltype( std17::data( std::declval<C&>() ) )>::type(*)[] >
+> : std::is_convertible< typename std::remove_pointer<decltype( std17::data( std::declval<C&>() ) )>::type(*)[], E(*)[] >{};
+
+template< class C >
+struct is_container : std17::bool_constant
+<
+ ! is_span< C >::value
+ && ! is_array< C >::value
+ && ! is_std_array< C >::value
+ && has_size_and_data< C >::value
+>{};
+
+template< class C, class E >
+struct is_compatible_container : std17::bool_constant
+<
+ is_container<C>::value
+ && is_compatible_element<C,E>::value
+>{};
+
+# else // ^^^ gsl_CPP11_140 && ! gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 1, 500 ) ^^^ / vvv ! gsl_CPP11_140 || gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 1, 500 ) vvv
+
+template<
+ class C, class E
+ , typename = typename std::enable_if<
+ ! is_span< C >::value
+ && ! is_array< C >::value
+ && ! is_std_array< C >::value
+ && ( std::is_convertible< typename std::remove_pointer<decltype( std17::data( std::declval<C&>() ) )>::type(*)[], E(*)[] >::value)
+ // && has_size_and_data< C >::value
+ , enabler>::type
+ , class = decltype( std17::size(std::declval<C>()) )
+ , class = decltype( std17::data(std::declval<C>()) )
+>
+# if gsl_BETWEEN( gsl_COMPILER_MSVC_VERSION, 1, 140 )
+// VS2013 has insufficient support for expression SFINAE; we cannot make `is_compatible_container<>` a proper type trait here
+struct is_compatible_container : std::true_type { };
+# else
+struct is_compatible_container_r { is_compatible_container_r(int); };
+template< class C, class E >
+std::true_type is_compatible_container_f( is_compatible_container_r<C, E> );
+template< class C, class E >
+std::false_type is_compatible_container_f( ... );
+
+template< class C, class E >
+struct is_compatible_container : decltype( is_compatible_container_f< C, E >( 0 ) ) { };
+# endif // gsl_BETWEEN( gsl_COMPILER_MSVC_VERSION, 1, 140 )
+
+# endif // gsl_CPP11_140 && ! gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 1, 500 )
+
+#endif // gsl_HAVE( TYPE_TRAITS )
+
+} // namespace detail
+
+//
+// GSL.util: utilities
+//
+
+// Integer type for indices (e.g. in a loop).
+typedef gsl_CONFIG_INDEX_TYPE index;
+
+// Integer type for dimensions.
+typedef gsl_CONFIG_INDEX_TYPE dim;
+
+// Integer type for array strides.
+typedef gsl_CONFIG_INDEX_TYPE stride;
+
+// Integer type for pointer, iterator, or index differences.
+typedef gsl_CONFIG_INDEX_TYPE diff;
+
+//
+// GSL.owner: ownership pointers
+//
+#if gsl_HAVE( SHARED_PTR )
+ using std::unique_ptr;
+ using std::shared_ptr;
+ using std::make_shared;
+# if gsl_HAVE( MAKE_UNIQUE ) || gsl_HAVE( VARIADIC_TEMPLATE )
+ using std14::make_unique;
+# endif
+#endif
+
+#if gsl_HAVE( ALIAS_TEMPLATE )
+ template< class T
+#if gsl_HAVE( TYPE_TRAITS )
+ , typename = typename std::enable_if< std::is_pointer<T>::value >::type
+#endif
+ >
+ using owner = T;
+#elif gsl_CONFIG( DEFAULTS_VERSION ) == 0
+ // TODO vNext: remove
+ template< class T > struct owner { typedef T type; };
+#endif
+
+#define gsl_HAVE_OWNER_TEMPLATE gsl_HAVE_ALIAS_TEMPLATE
+#define gsl_HAVE_OWNER_TEMPLATE_() gsl_HAVE_OWNER_TEMPLATE
+
+// TODO vNext: remove
+#if gsl_FEATURE( OWNER_MACRO )
+# if gsl_HAVE( OWNER_TEMPLATE )
+# define Owner(t) ::gsl::owner<t>
+# else
+# define Owner(t) ::gsl::owner<t>::type
+# endif
+#endif
+
+//
+// GSL.assert: assertions
+//
+
+#if gsl_HAVE( TYPE_TRAITS )
+# define gsl_ELIDE_( x ) static_assert( ::std::is_constructible<bool, decltype( x )>::value, "argument of contract check must be convertible to bool" )
+#else
+# define gsl_ELIDE_( x )
+#endif
+#define gsl_NO_OP_() ( static_cast<void>( 0 ) )
+
+#if defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME )
+# if defined( __CUDACC__ ) && defined( __CUDA_ARCH__ )
+# if gsl_COMPILER_NVCC_VERSION >= 113
+# define gsl_ASSUME_( x ) ( ( x ) ? static_cast<void>(0) : __builtin_unreachable() )
+# define gsl_ASSUME_UNREACHABLE_() __builtin_unreachable()
+# else
+# define gsl_ASSUME_( x ) gsl_ELIDE_( x ) /* there is no assume intrinsic in CUDA device code */
+# define gsl_ASSUME_UNREACHABLE_() gsl_NO_OP_() /* there is no assume intrinsic in CUDA device code */
+# endif
+# elif gsl_COMPILER_MSVC_VERSION >= 140
+# define gsl_ASSUME_( x ) __assume( x )
+# define gsl_ASSUME_UNREACHABLE_() __assume( 0 )
+# elif gsl_COMPILER_GNUC_VERSION
+# define gsl_ASSUME_( x ) ( ( x ) ? static_cast<void>(0) : __builtin_unreachable() )
+# define gsl_ASSUME_UNREACHABLE_() __builtin_unreachable()
+# elif defined(__has_builtin)
+# if __has_builtin(__builtin_unreachable)
+# define gsl_ASSUME_( x ) ( ( x ) ? static_cast<void>(0) : __builtin_unreachable() )
+# define gsl_ASSUME_UNREACHABLE_() __builtin_unreachable()
+# else
+# error gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME: gsl-lite does not know how to generate UB optimization hints for this compiler; use gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE instead
+# endif
+# else
+# error gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME: gsl-lite does not know how to generate UB optimization hints for this compiler; use gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE instead
+# endif
+#endif // defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME )
+
+#if defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME )
+# define gsl_CONTRACT_UNENFORCED_( x ) gsl_ASSUME_( x )
+#else // defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE ) [default]
+# define gsl_CONTRACT_UNENFORCED_( x ) gsl_ELIDE_( x )
+#endif
+
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_TRAPS )
+# if defined( __CUDACC__ ) && defined( __CUDA_ARCH__ )
+# define gsl_TRAP_() __trap()
+# elif gsl_COMPILER_MSVC_VERSION >= 110 // __fastfail() supported by VS 2012 and later
+# define gsl_TRAP_() __fastfail( 0 ) /* legacy failure code for buffer-overrun errors, cf. winnt.h, "Fast fail failure codes" */
+# elif gsl_COMPILER_GNUC_VERSION
+# define gsl_TRAP_() __builtin_trap()
+# elif defined(__has_builtin)
+# if __has_builtin(__builtin_trap)
+# define gsl_TRAP_() __builtin_trap()
+# else
+# error gsl_CONFIG_CONTRACT_VIOLATION_TRAPS: gsl-lite does not know how to generate a trap instruction for this compiler; use gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES instead
+# endif
+# else
+# error gsl_CONFIG_CONTRACT_VIOLATION_TRAPS: gsl-lite does not know how to generate a trap instruction for this compiler; use gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES instead
+# endif
+#endif // defined( gsl_CONFIG_CONTRACT_VIOLATION_TRAPS )
+
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER )
+# define gsl_CONTRACT_CHECK_( str, x ) ( ( x ) ? static_cast<void>(0) : ::gsl::fail_fast_assert_handler( #x, str, __FILE__, __LINE__ ) )
+# if defined( __CUDACC__ ) && defined( __CUDA_ARCH__ )
+# define gsl_FAILFAST_() ( ::gsl::fail_fast_assert_handler( "", "GSL: failure", __FILE__, __LINE__ ), gsl_TRAP_() ) /* do not let the custom assertion handler continue execution */
+# else
+# define gsl_FAILFAST_() ( ::gsl::fail_fast_assert_handler( "", "GSL: failure", __FILE__, __LINE__ ), ::gsl::detail::fail_fast_terminate() ) /* do not let the custom assertion handler continue execution */
+# endif
+#elif defined( __CUDACC__ ) && defined( __CUDA_ARCH__ )
+# if defined( gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS ) || ! defined( NDEBUG )
+# define gsl_CONTRACT_CHECK_( str, x ) assert( str && ( x ) )
+# else
+# define gsl_CONTRACT_CHECK_( str, x ) ( ( x ) ? static_cast<void>(0) : __trap() )
+#endif
+# define gsl_FAILFAST_() ( __trap() )
+#elif defined( gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS )
+# define gsl_CONTRACT_CHECK_( str, x ) assert( str && ( x ) )
+# if ! defined( NDEBUG )
+# define gsl_FAILFAST_() ( assert( ! "GSL: failure" ), ::gsl::detail::fail_fast_terminate() )
+# else
+# define gsl_FAILFAST_() ( ::gsl::detail::fail_fast_terminate() )
+# endif
+#elif defined( gsl_CONFIG_CONTRACT_VIOLATION_TRAPS )
+# define gsl_CONTRACT_CHECK_( str, x ) ( ( x ) ? static_cast<void>(0) : gsl_TRAP_() )
+# if gsl_COMPILER_MSVC_VERSION
+# define gsl_FAILFAST_() ( gsl_TRAP_(), ::gsl::detail::fail_fast_terminate() )
+# else
+# define gsl_FAILFAST_() ( gsl_TRAP_() )
+# endif
+#elif defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS )
+# define gsl_CONTRACT_CHECK_( str, x ) ( ( x ) ? static_cast<void>(0) : ::gsl::detail::fail_fast_throw( str ": '" #x "' at " __FILE__ ":" gsl_STRINGIFY(__LINE__) ) )
+# define gsl_FAILFAST_() ( ::gsl::detail::fail_fast_throw( "GSL: failure at " __FILE__ ":" gsl_STRINGIFY(__LINE__) ) )
+#else // defined( gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES ) [default]
+# define gsl_CONTRACT_CHECK_( str, x ) ( ( x ) ? static_cast<void>(0) : ::gsl::detail::fail_fast_terminate() )
+# define gsl_FAILFAST_() ( ::gsl::detail::fail_fast_terminate() )
+#endif
+
+#if defined( gsl_CONFIG_CONTRACT_CHECKING_OFF ) || defined( gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF )
+# define gsl_Expects( x ) gsl_CONTRACT_UNENFORCED_( x )
+#else
+# define gsl_Expects( x ) gsl_CONTRACT_CHECK_( "GSL: Precondition failure", x )
+#endif
+#define Expects( x ) gsl_Expects( x )
+#if !defined( gsl_CONFIG_CONTRACT_CHECKING_AUDIT ) || defined( gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF )
+# define gsl_ExpectsAudit( x ) gsl_ELIDE_( x )
+#else
+# define gsl_ExpectsAudit( x ) gsl_CONTRACT_CHECK_( "GSL: Precondition failure (audit)", x )
+#endif
+
+#if defined( gsl_CONFIG_CONTRACT_CHECKING_OFF ) || defined( gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF )
+# define gsl_Ensures( x ) gsl_CONTRACT_UNENFORCED_( x )
+#else
+# define gsl_Ensures( x ) gsl_CONTRACT_CHECK_( "GSL: Postcondition failure", x )
+#endif
+#define Ensures( x ) gsl_Ensures( x )
+#if !defined( gsl_CONFIG_CONTRACT_CHECKING_AUDIT ) || defined( gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF )
+# define gsl_EnsuresAudit( x ) gsl_ELIDE_( x )
+#else
+# define gsl_EnsuresAudit( x ) gsl_CONTRACT_CHECK_( "GSL: Postcondition failure (audit)", x )
+#endif
+
+#if defined( gsl_CONFIG_CONTRACT_CHECKING_OFF ) || defined( gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF )
+# define gsl_Assert( x ) gsl_CONTRACT_UNENFORCED_( x )
+#else
+# define gsl_Assert( x ) gsl_CONTRACT_CHECK_( "GSL: Assertion failure", x )
+#endif
+#if !defined( gsl_CONFIG_CONTRACT_CHECKING_AUDIT ) || defined( gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF )
+# define gsl_AssertAudit( x ) gsl_ELIDE_( x )
+#else
+# define gsl_AssertAudit( x ) gsl_CONTRACT_CHECK_( "GSL: Assertion failure (audit)", x )
+#endif
+
+#define gsl_FailFast() gsl_FAILFAST_()
+
+
+struct fail_fast : public std::logic_error
+{
+ explicit fail_fast( char const * message )
+ : std::logic_error( message ) {}
+};
+
+namespace detail {
+
+
+#if gsl_HAVE( EXCEPTIONS )
+gsl_NORETURN inline void fail_fast_throw( char const * message )
+{
+ throw fail_fast( message );
+}
+#endif // gsl_HAVE( EXCEPTIONS )
+gsl_NORETURN inline void fail_fast_terminate() gsl_noexcept
+{
+ std::terminate();
+}
+
+} // namespace detail
+
+// Should be defined by user
+gsl_api void fail_fast_assert_handler( char const * const expression, char const * const message, char const * const file, int line );
+
+#if defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS )
+
+# if gsl_HAVE( EXCEPTIONS )
+gsl_DEPRECATED_MSG("don't call gsl::fail_fast_assert() directly; use contract checking macros instead")
+gsl_constexpr14 inline
+void fail_fast_assert( bool cond, char const * const message )
+{
+ if ( !cond )
+ throw fail_fast( message );
+}
+# endif // gsl_HAVE( EXCEPTIONS )
+
+#elif defined( gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER )
+
+gsl_DEPRECATED_MSG("don't call gsl::fail_fast_assert() directly; use contract checking macros instead")
+gsl_api gsl_constexpr14 inline
+void fail_fast_assert( bool cond, char const * const expression, char const * const message, char const * const file, int line )
+{
+ if ( !cond )
+ ::gsl::fail_fast_assert_handler( expression, message, file, line );
+}
+
+#else // defined( gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES ) [default]
+
+gsl_DEPRECATED_MSG("don't call gsl::fail_fast_assert() directly; use contract checking macros instead")
+gsl_constexpr14 inline
+void fail_fast_assert( bool cond ) gsl_noexcept
+{
+ if ( !cond )
+ std::terminate();
+}
+
+#endif
+
+
+//
+// GSL.util: utilities
+//
+
+#if gsl_FEATURE( EXPERIMENTAL_RETURN_GUARD )
+
+// Add uncaught_exceptions for pre-2017 MSVC, GCC and Clang
+// Return unsigned char to save stack space, uncaught_exceptions can only increase by 1 in a scope
+
+namespace std11 {
+
+# if gsl_HAVE( UNCAUGHT_EXCEPTIONS )
+
+inline unsigned char uncaught_exceptions() gsl_noexcept
+{
+ return static_cast<unsigned char>( std::uncaught_exceptions() );
+}
+
+# else // ! gsl_HAVE( UNCAUGHT_EXCEPTIONS )
+# if defined( _MSC_VER ) // MS-STL with either MSVC or clang-cl
+
+inline unsigned char uncaught_exceptions() gsl_noexcept
+{
+ return static_cast<unsigned char>( *reinterpret_cast<unsigned const*>( detail::_getptd() + (sizeof(void *) == 8 ? 0x100 : 0x90 ) ) );
+}
+
+# elif gsl_COMPILER_CLANG_VERSION || gsl_COMPILER_GNUC_VERSION || gsl_COMPILER_APPLECLANG_VERSION
+
+inline unsigned char uncaught_exceptions() gsl_noexcept
+{
+ return static_cast<unsigned char>( ( *reinterpret_cast<unsigned const *>( reinterpret_cast<unsigned char const *>(detail::__cxa_get_globals()) + sizeof(void *) ) ) );
+}
+
+# endif
+# endif
+
+} // namespace std11
+
+#endif // gsl_FEATURE( EXPERIMENTAL_RETURN_GUARD )
+
+#if gsl_STDLIB_CPP11_110
+
+gsl_DISABLE_MSVC_WARNINGS( 4702 ) // unreachable code
+
+template< class F >
+class final_action
+{
+public:
+ explicit final_action( F action ) gsl_noexcept
+ : action_( std::move( action ) )
+ , invoke_( true )
+ {}
+
+ final_action( final_action && other ) gsl_noexcept
+ : action_( std::move( other.action_ ) )
+ , invoke_( other.invoke_ )
+ {
+ other.invoke_ = false;
+ }
+
+ gsl_SUPPRESS_MSGSL_WARNING(f.6)
+ virtual ~final_action() gsl_noexcept
+ {
+ if ( invoke_ )
+ action_();
+ }
+
+gsl_is_delete_access:
+ final_action( final_action const & ) gsl_is_delete;
+ final_action & operator=( final_action const & ) gsl_is_delete;
+ final_action & operator=( final_action && ) gsl_is_delete;
+
+protected:
+ void dismiss() gsl_noexcept
+ {
+ invoke_ = false;
+ }
+
+private:
+ F action_;
+ bool invoke_;
+};
+
+template< class F >
+gsl_NODISCARD inline final_action<F>
+finally( F const & action ) gsl_noexcept
+{
+ return final_action<F>( action );
+}
+
+template< class F >
+gsl_NODISCARD inline final_action<F>
+finally( F && action ) gsl_noexcept
+{
+ return final_action<F>( std::forward<F>( action ) );
+}
+
+# if gsl_FEATURE( EXPERIMENTAL_RETURN_GUARD )
+
+template< class F >
+class final_action_return : public final_action<F>
+{
+public:
+ explicit final_action_return( F && action ) gsl_noexcept
+ : final_action<F>( std::move( action ) )
+ , exception_count( std11::uncaught_exceptions() )
+ {}
+
+ final_action_return( final_action_return && other ) gsl_noexcept
+ : final_action<F>( std::move( other ) )
+ , exception_count( std11::uncaught_exceptions() )
+ {}
+
+ ~final_action_return() override
+ {
+ if ( std11::uncaught_exceptions() != exception_count )
+ this->dismiss();
+ }
+
+gsl_is_delete_access:
+ final_action_return( final_action_return const & ) gsl_is_delete;
+ final_action_return & operator=( final_action_return const & ) gsl_is_delete;
+
+private:
+ unsigned char exception_count;
+};
+
+template< class F >
+gsl_NODISCARD inline final_action_return<F>
+on_return( F const & action ) gsl_noexcept
+{
+ return final_action_return<F>( action );
+}
+
+template< class F >
+gsl_NODISCARD inline final_action_return<F>
+on_return( F && action ) gsl_noexcept
+{
+ return final_action_return<F>( std::forward<F>( action ) );
+}
+
+template< class F >
+class final_action_error : public final_action<F>
+{
+public:
+ explicit final_action_error( F && action ) gsl_noexcept
+ : final_action<F>( std::move( action ) )
+ , exception_count( std11::uncaught_exceptions() )
+ {}
+
+ final_action_error( final_action_error && other ) gsl_noexcept
+ : final_action<F>( std::move( other ) )
+ , exception_count( std11::uncaught_exceptions() )
+ {}
+
+ ~final_action_error() override
+ {
+ if ( std11::uncaught_exceptions() == exception_count )
+ this->dismiss();
+ }
+
+gsl_is_delete_access:
+ final_action_error( final_action_error const & ) gsl_is_delete;
+ final_action_error & operator=( final_action_error const & ) gsl_is_delete;
+
+private:
+ unsigned char exception_count;
+};
+
+template< class F >
+gsl_NODISCARD inline final_action_error<F>
+on_error( F const & action ) gsl_noexcept
+{
+ return final_action_error<F>( action );
+}
+
+template< class F >
+gsl_NODISCARD inline final_action_error<F>
+on_error( F && action ) gsl_noexcept
+{
+ return final_action_error<F>( std::forward<F>( action ) );
+}
+
+# endif // gsl_FEATURE( EXPERIMENTAL_RETURN_GUARD )
+
+gsl_RESTORE_MSVC_WARNINGS()
+
+#else // ! gsl_STDLIB_CPP11_110
+
+class final_action
+{
+public:
+ typedef void (*Action)();
+
+ final_action( Action action )
+ : action_( action )
+ , invoke_( true )
+ {}
+
+ final_action( final_action const & other )
+ : action_( other.action_ )
+ , invoke_( other.invoke_ )
+ {
+ other.invoke_ = false;
+ }
+
+ virtual ~final_action()
+ {
+ if ( invoke_ )
+ action_();
+ }
+
+protected:
+ void dismiss()
+ {
+ invoke_ = false;
+ }
+
+private:
+ final_action & operator=( final_action const & );
+
+private:
+ Action action_;
+ mutable bool invoke_;
+};
+
+template< class F >
+inline final_action finally( F const & f )
+{
+ return final_action(( f ));
+}
+
+#if gsl_FEATURE( EXPERIMENTAL_RETURN_GUARD )
+
+class final_action_return : public final_action
+{
+public:
+ explicit final_action_return( Action action )
+ : final_action( action )
+ , exception_count( std11::uncaught_exceptions() )
+ {}
+
+ ~final_action_return()
+ {
+ if ( std11::uncaught_exceptions() != exception_count )
+ this->dismiss();
+ }
+
+private:
+ final_action_return & operator=( final_action_return const & );
+
+private:
+ unsigned char exception_count;
+};
+
+template< class F >
+inline final_action_return on_return( F const & action )
+{
+ return final_action_return( action );
+}
+
+class final_action_error : public final_action
+{
+public:
+ explicit final_action_error( Action action )
+ : final_action( action )
+ , exception_count( std11::uncaught_exceptions() )
+ {}
+
+ ~final_action_error()
+ {
+ if ( std11::uncaught_exceptions() == exception_count )
+ this->dismiss();
+ }
+
+private:
+ final_action_error & operator=( final_action_error const & );
+
+private:
+ unsigned char exception_count;
+};
+
+template< class F >
+inline final_action_error on_error( F const & action )
+{
+ return final_action_error( action );
+}
+
+# endif // gsl_FEATURE( EXPERIMENTAL_RETURN_GUARD )
+
+#endif // gsl_STDLIB_CPP11_110
+
+#if gsl_STDLIB_CPP11_120
+
+template< class T, class U >
+gsl_NODISCARD gsl_api inline gsl_constexpr T
+narrow_cast( U && u ) gsl_noexcept
+{
+ return static_cast<T>( std::forward<U>( u ) );
+}
+
+#else // ! gsl_STDLIB_CPP11_120
+
+template< class T, class U >
+gsl_api inline T
+narrow_cast( U u ) gsl_noexcept
+{
+ return static_cast<T>( u );
+}
+
+#endif // gsl_STDLIB_CPP11_120
+
+struct narrowing_error : public std::exception
+{
+ char const * what() const gsl_noexcept
+#if gsl_HAVE( OVERRIDE_FINAL )
+ override
+#endif
+ {
+ return "narrowing_error";
+ }
+};
+
+#if gsl_HAVE( TYPE_TRAITS )
+
+namespace detail {
+
+ template< class T, class U >
+ struct is_same_signedness : public std::integral_constant<bool, std::is_signed<T>::value == std::is_signed<U>::value> {};
+
+# if gsl_COMPILER_NVCC_VERSION
+ // We do this to circumvent NVCC warnings about pointless unsigned comparisons with 0.
+ template< class T >
+ gsl_constexpr gsl_api bool is_negative( T value, std::true_type /*isSigned*/ ) gsl_noexcept
+ {
+ return value < T();
+ }
+ template< class T >
+ gsl_constexpr gsl_api bool is_negative( T /*value*/, std::false_type /*isUnsigned*/ ) gsl_noexcept
+ {
+ return false;
+ }
+ template< class T, class U >
+ gsl_constexpr gsl_api bool have_same_sign( T, U, std::true_type /*isSameSignedness*/ ) gsl_noexcept
+ {
+ return true;
+ }
+ template< class T, class U >
+ gsl_constexpr gsl_api bool have_same_sign( T t, U u, std::false_type /*isSameSignedness*/ ) gsl_noexcept
+ {
+ return detail::is_negative( t, std::is_signed<T>() ) == detail::is_negative( u, std::is_signed<U>() );
+ }
+# endif // gsl_COMPILER_NVCC_VERSION
+
+} // namespace detail
+
+#endif
+
+template< class T, class U >
+gsl_NODISCARD
+#if !gsl_CONFIG( NARROW_THROWS_ON_TRUNCATION ) && !defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS )
+gsl_api
+#endif
+inline T
+narrow( U u )
+{
+#if gsl_CONFIG( NARROW_THROWS_ON_TRUNCATION ) && ! gsl_HAVE( EXCEPTIONS )
+ gsl_STATIC_ASSERT_( detail::dependent_false< T >::value,
+ "According to the GSL specification, narrow<>() throws an exception of type narrowing_error on truncation. Therefore "
+ "it cannot be used if exceptions are disabled. Consider using narrow_failfast<>() instead which raises a precondition "
+ "violation if the given value cannot be represented in the target type." );
+#endif
+
+ T t = static_cast<T>( u );
+
+ if ( static_cast<U>( t ) != u )
+ {
+#if gsl_HAVE( EXCEPTIONS ) && ( gsl_CONFIG( NARROW_THROWS_ON_TRUNCATION ) || defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS ) )
+ throw narrowing_error();
+#else
+ std::terminate();
+#endif
+ }
+
+#if gsl_HAVE( TYPE_TRAITS )
+# if gsl_COMPILER_NVCC_VERSION
+ if ( ! detail::have_same_sign( t, u, detail::is_same_signedness<T, U>() ) )
+# else
+ gsl_SUPPRESS_MSVC_WARNING( 4127, "conditional expression is constant" )
+ if ( ! detail::is_same_signedness<T, U>::value && ( t < T() ) != ( u < U() ) )
+# endif
+#else
+ // Don't assume T() works:
+ gsl_SUPPRESS_MSVC_WARNING( 4127, "conditional expression is constant" )
+ if ( ( t < 0 ) != ( u < 0 ) )
+#endif
+ {
+#if gsl_HAVE( EXCEPTIONS ) && ( gsl_CONFIG( NARROW_THROWS_ON_TRUNCATION ) || defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS ) )
+ throw narrowing_error();
+#else
+ std::terminate();
+#endif
+ }
+
+ return t;
+}
+
+template< class T, class U >
+gsl_NODISCARD gsl_api inline T
+narrow_failfast( U u )
+{
+ T t = static_cast<T>( u );
+
+ gsl_Expects( static_cast<U>( t ) == u );
+
+#if gsl_HAVE( TYPE_TRAITS )
+# if gsl_COMPILER_NVCC_VERSION
+ gsl_Expects( ::gsl::detail::have_same_sign( t, u, ::gsl::detail::is_same_signedness<T, U>() ) );
+# else
+ gsl_SUPPRESS_MSVC_WARNING( 4127, "conditional expression is constant" )
+ gsl_Expects( ( ::gsl::detail::is_same_signedness<T, U>::value || ( t < T() ) == ( u < U() ) ) );
+# endif
+#else
+ // Don't assume T() works:
+ gsl_SUPPRESS_MSVC_WARNING( 4127, "conditional expression is constant" )
+ gsl_Expects( ( t < 0 ) == ( u < 0 ) );
+#endif
+
+ return t;
+}
+
+
+//
+// at() - Bounds-checked way of accessing static arrays, std::array, std::vector.
+//
+
+template< class T, size_t N >
+gsl_NODISCARD gsl_api inline gsl_constexpr14 T &
+at( T(&arr)[N], size_t pos )
+{
+ gsl_Expects( pos < N );
+ return arr[pos];
+}
+
+template< class Container >
+gsl_NODISCARD gsl_api inline gsl_constexpr14 typename Container::value_type &
+at( Container & cont, size_t pos )
+{
+ gsl_Expects( pos < cont.size() );
+ return cont[pos];
+}
+
+template< class Container >
+gsl_NODISCARD gsl_api inline gsl_constexpr14 typename Container::value_type const &
+at( Container const & cont, size_t pos )
+{
+ gsl_Expects( pos < cont.size() );
+ return cont[pos];
+}
+
+#if gsl_HAVE( INITIALIZER_LIST )
+
+template< class T >
+gsl_NODISCARD gsl_api inline const gsl_constexpr14 T
+at( std::initializer_list<T> cont, size_t pos )
+{
+ gsl_Expects( pos < cont.size() );
+ return *( cont.begin() + pos );
+}
+#endif
+
+template< class T >
+gsl_NODISCARD gsl_api inline gsl_constexpr14 T &
+at( span<T> s, size_t pos )
+{
+ return s[ pos ];
+}
+
+//
+// GSL.views: views
+//
+
+//
+// not_null<> - Wrap any indirection and enforce non-null.
+//
+
+template< class T >
+class not_null;
+
+namespace detail {
+
+// helper class to figure out the pointed-to type of a pointer
+#if gsl_STDLIB_CPP11_OR_GREATER
+template< class T, class E = void >
+struct element_type_helper
+{
+ // For types without a member element_type (this will handle raw pointers)
+ typedef typename std::remove_reference< decltype( *std::declval<T>() ) >::type type;
+};
+
+template< class T >
+struct element_type_helper< T, std17::void_t< typename T::element_type > >
+{
+ // For types with a member element_type
+ typedef typename T::element_type type;
+};
+#else // ! gsl_STDLIB_CPP11_OR_GREATER
+// Pre-C++11, we cannot have decltype, so we cannot handle types without a member element_type
+template< class T, class E = void >
+struct element_type_helper
+{
+ typedef typename T::element_type type;
+};
+
+template< class T >
+struct element_type_helper< T* >
+{
+ typedef T type;
+};
+#endif // gsl_STDLIB_CPP11_OR_GREATER
+
+template< class T >
+struct is_not_null_or_bool_oracle : std11::false_type { };
+template< class T >
+struct is_not_null_or_bool_oracle< not_null<T> > : std11::true_type { };
+template<>
+struct is_not_null_or_bool_oracle< bool > : std11::true_type { };
+
+
+template< class T, bool IsCopyable = true >
+struct not_null_data;
+#if gsl_HAVE( MOVE_FORWARD )
+template< class T >
+struct not_null_data< T, false >
+{
+ T ptr_;
+
+ gsl_api gsl_constexpr14 not_null_data( T && _ptr ) gsl_noexcept
+ : ptr_( std::move( _ptr ) )
+ {
+ }
+
+ gsl_api gsl_constexpr14 not_null_data( not_null_data && other ) gsl_noexcept
+ : ptr_( std::move( other.ptr_ ) )
+ {
+ }
+ gsl_api gsl_constexpr14 not_null_data & operator=( not_null_data && other ) gsl_noexcept
+ {
+ ptr_ = std::move( other.ptr_ );
+ return *this;
+ }
+
+gsl_is_delete_access:
+ not_null_data( not_null_data const & ) gsl_is_delete;
+ not_null_data & operator=( not_null_data const & ) gsl_is_delete;
+};
+# if gsl_CONFIG_DEFAULTS_VERSION >= 1
+# endif // gsl_CONFIG_DEFAULTS_VERSION >= 1
+#endif // gsl_HAVE( MOVE_FORWARD )
+template< class T >
+struct not_null_data< T, true >
+{
+ T ptr_;
+
+ gsl_api gsl_constexpr14 not_null_data( T const & _ptr ) gsl_noexcept
+ : ptr_( _ptr )
+ {
+ }
+
+#if gsl_HAVE( MOVE_FORWARD )
+ gsl_api gsl_constexpr14 not_null_data( T && _ptr ) gsl_noexcept
+ : ptr_( std::move( _ptr ) )
+ {
+ }
+
+ gsl_api gsl_constexpr14 not_null_data( not_null_data && other ) gsl_noexcept
+ : ptr_( std::move( other.ptr_ ) )
+ {
+ }
+ gsl_api gsl_constexpr14 not_null_data & operator=( not_null_data && other ) gsl_noexcept
+ {
+ ptr_ = std::move( other.ptr_ );
+ return *this;
+ }
+#endif // gsl_HAVE( MOVE_FORWARD )
+
+ gsl_api gsl_constexpr14 not_null_data( not_null_data const & other )
+ : ptr_( other.ptr_ )
+ {
+ gsl_Expects( ptr_ != gsl_nullptr );
+ }
+ gsl_api gsl_constexpr14 not_null_data & operator=( not_null_data const & other )
+ {
+ gsl_Expects( other.ptr_ != gsl_nullptr );
+ ptr_ = other.ptr_;
+ return *this;
+ }
+};
+#if gsl_CONFIG_DEFAULTS_VERSION >= 1
+template< class T >
+struct not_null_data< T *, true >
+{
+ T * ptr_;
+
+ gsl_api gsl_constexpr14 not_null_data( T * _ptr ) gsl_noexcept
+ : ptr_( _ptr )
+ {
+ }
+};
+#endif // gsl_CONFIG_DEFAULTS_VERSION >= 1
+template< class T >
+struct is_copyable
+#if gsl_HAVE( TYPE_TRAITS )
+: std11::integral_constant< bool, std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value >
+#else
+: std11::true_type
+#endif
+{
+};
+#if gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( UNIQUE_PTR ) && gsl_BETWEEN( gsl_COMPILER_MSVC_VERSION, 1, 140 )
+// Type traits are buggy in VC++ 2013, so we explicitly declare `unique_ptr<>` non-copyable.
+template< class T, class Deleter >
+struct is_copyable< std::unique_ptr< T, Deleter > > : std11::false_type
+{
+};
+#endif
+
+template< class T >
+struct not_null_accessor;
+
+} // namespace detail
+
+template< class T >
+class not_null
+{
+private:
+ detail::not_null_data< T, detail::is_copyable< T >::value > data_;
+
+ // need to access `not_null<U>::data_`
+ template< class U >
+ friend class not_null;
+
+ template< class U >
+ friend struct detail::not_null_accessor;
+
+public:
+ typedef typename detail::element_type_helper<T>::type element_type;
+
+#if gsl_HAVE( TYPE_TRAITS )
+ static_assert( std::is_assignable<typename std::remove_const<typename std::remove_reference<T>::type>::type&, std::nullptr_t>::value, "T cannot be assigned nullptr." );
+#endif
+
+#if gsl_CONFIG( NOT_NULL_EXPLICIT_CTOR )
+# if gsl_HAVE( MOVE_FORWARD )
+ template< class U
+ // In Clang 3.x, `is_constructible<not_null<unique_ptr<X>>, unique_ptr<X>>` tries to instantiate the copy constructor of `unique_ptr<>`, triggering an error.
+ // Note that Apple Clang's `__clang_major__` etc. are different from regular Clang.
+# if gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && ! gsl_BETWEEN( gsl_COMPILER_CLANG_VERSION, 1, 400 ) && ! gsl_BETWEEN( gsl_COMPILER_APPLECLANG_VERSION, 1, 1001 )
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_constructible<T, U>::value ), int >::type = 0
+# endif
+ >
+ gsl_api gsl_constexpr14 explicit not_null( U other )
+ : data_( T( std::move( other ) ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+# else // a.k.a. ! gsl_HAVE( MOVE_FORWARD )
+ template< class U >
+ gsl_api gsl_constexpr14 explicit not_null( U const& other )
+ : data_( T( other ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+# endif // gsl_HAVE( MOVE_FORWARD )
+#else // a.k.a. !gsl_CONFIG( NOT_NULL_EXPLICIT_CTOR )
+# if gsl_HAVE( MOVE_FORWARD )
+ // In Clang 3.x, `is_constructible<not_null<unique_ptr<X>>, unique_ptr<X>>` tries to instantiate the copy constructor of `unique_ptr<>`, triggering an error.
+ // Note that Apple Clang's `__clang_major__` etc. are different from regular Clang.
+# if gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && ! gsl_BETWEEN( gsl_COMPILER_CLANG_VERSION, 1, 400 ) && ! gsl_BETWEEN( gsl_COMPILER_APPLECLANG_VERSION, 1, 1001 )
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_constructible<T, U>::value && !std::is_convertible<U, T>::value ), int >::type = 0
+ >
+ gsl_api gsl_constexpr14 explicit not_null( U other )
+ : data_( T( std::move( other ) ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_convertible<U, T>::value ), int >::type = 0
+ >
+ gsl_api gsl_constexpr14 not_null( U other )
+ : data_( std::move( other ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+# else // a.k.a. !( gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && ! gsl_BETWEEN( gsl_COMPILER_CLANG_VERSION, 1, 400 ) && ! gsl_BETWEEN( gsl_COMPILER_APPLECLANG_VERSION, 1, 1001 )
+ // If type_traits are not available, then we can't distinguish `is_convertible<>` and `is_constructible<>`, so we unconditionally permit implicit construction.
+ template< class U >
+ gsl_api gsl_constexpr14 not_null( U other )
+ : data_( T( std::move( other ) ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+# endif // gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && ! gsl_BETWEEN( gsl_COMPILER_CLANG_VERSION, 1, 400 ) && ! gsl_BETWEEN( gsl_COMPILER_APPLECLANG_VERSION, 1, 1001 )
+# else // a.k.a. ! gsl_HAVE( MOVE_FORWARD )
+ template< class U >
+ gsl_api gsl_constexpr14 not_null( U const& other )
+ : data_( T( other ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+# endif // gsl_HAVE( MOVE_FORWARD )
+#endif // gsl_CONFIG( NOT_NULL_EXPLICIT_CTOR )
+
+public:
+#if gsl_HAVE( MOVE_FORWARD )
+ // In Clang 3.x, `is_constructible<not_null<unique_ptr<X>>, unique_ptr<X>>` tries to instantiate the copy constructor of `unique_ptr<>`, triggering an error.
+ // Note that Apple Clang's `__clang_major__` etc. are different from regular Clang.
+# if gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && ! gsl_BETWEEN( gsl_COMPILER_CLANG_VERSION, 1, 400 ) && ! gsl_BETWEEN( gsl_COMPILER_APPLECLANG_VERSION, 1, 1001 )
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_constructible<T, U>::value && !std::is_convertible<U, T>::value ), int >::type = 0
+ >
+ gsl_api gsl_constexpr14 explicit not_null( not_null<U> other )
+ : data_( T( std::move( other.data_.ptr_ ) ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_convertible<U, T>::value ), int >::type = 0
+ >
+ gsl_api gsl_constexpr14 not_null( not_null<U> other )
+ : data_( T( std::move( other.data_.ptr_ ) ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+# else // a.k.a. ! ( gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && ! gsl_BETWEEN( gsl_COMPILER_CLANG_VERSION, 1, 400 ) && ! gsl_BETWEEN( gsl_COMPILER_APPLECLANG_VERSION, 1, 1001 )
+ // If type_traits are not available, then we can't distinguish `is_convertible<>` and `is_constructible<>`, so we unconditionally permit implicit construction.
+ template< class U >
+ gsl_api gsl_constexpr14 not_null( not_null<U> other )
+ : data_( T( std::move( other.data_.ptr_ ) ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+ template< class U >
+ gsl_api gsl_constexpr14 not_null<T>& operator=( not_null<U> other )
+ {
+ gsl_Expects( other.data_.ptr_ != gsl_nullptr );
+ data_.ptr_ = std::move( other.data_.ptr_ );
+ return *this;
+ }
+# endif // gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && ! gsl_BETWEEN( gsl_COMPILER_CLANG_VERSION, 1, 400 ) && ! gsl_BETWEEN( gsl_COMPILER_APPLECLANG_VERSION, 1, 1001 )
+#else // a.k.a. ! gsl_HAVE( MOVE_FORWARD )
+ template< class U >
+ gsl_api gsl_constexpr14 not_null( not_null<U> const& other )
+ : data_( T( other.data_.ptr_ ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+ template< class U >
+ gsl_api gsl_constexpr14 not_null<T>& operator=( not_null<U> const & other )
+ {
+ gsl_Expects( other.data_.ptr_ != gsl_nullptr );
+ data_.ptr_ = other.data_.ptr_;
+ return *this;
+ }
+#endif // gsl_HAVE( MOVE_FORWARD )
+
+#if gsl_CONFIG( TRANSPARENT_NOT_NULL )
+ gsl_NODISCARD gsl_api gsl_constexpr14 element_type *
+ get() const
+ {
+ element_type * result = data_.ptr_.get();
+ gsl_Ensures( result != gsl_nullptr );
+ return result;
+ }
+#else
+# if gsl_CONFIG( NOT_NULL_GET_BY_CONST_REF )
+ gsl_NODISCARD gsl_api gsl_constexpr14 T const &
+ get() const
+ {
+ T const & result = data_.ptr_;
+ gsl_Ensures( result != gsl_nullptr );
+ return result;
+ }
+# else
+ gsl_NODISCARD gsl_api gsl_constexpr14 T
+ get() const
+ {
+ T result = data_.ptr_;
+ gsl_Ensures( result != gsl_nullptr );
+ return result;
+ }
+# endif
+#endif
+
+ // We want an implicit conversion operator that can be used to convert from both lvalues (by
+ // const reference or by copy) and rvalues (by move). So it seems like we could define
+ //
+ // template< class U >
+ // operator U const &() const & { ... }
+ // template< class U >
+ // operator U &&() && { ... }
+ //
+ // However, having two conversion operators with different return types renders the assignment
+ // operator of the result type ambiguous:
+ //
+ // not_null<std::unique_ptr<T>> p( ... );
+ // std::unique_ptr<U> q;
+ // q = std::move( p ); // ambiguous
+ //
+ // To avoid this ambiguity, we have both overloads of the conversion operator return `U`
+ // rather than `U const &` or `U &&`. This implies that converting an lvalue always induces
+ // a copy, which can cause unnecessary copies or even fail to compile in some situations:
+ //
+ // not_null<std::shared_ptr<T>> sp( ... );
+ // std::shared_ptr<U> const & rs = sp; // unnecessary copy
+ // std::unique_ptr<U> const & ru = p; // error: cannot copy `unique_ptr<T>`
+ //
+ // However, these situations are rather unusual, and the following, more frequent situations
+ // remain unimpaired:
+ //
+ // std::shared_ptr<U> vs = sp; // no extra copy
+ // std::unique_ptr<U> vu = std::move( p );
+
+#if gsl_HAVE( MOVE_FORWARD ) && gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && gsl_HAVE( EXPLICIT )
+ // explicit conversion operator
+
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_constructible<U, T const &>::value && !std::is_convertible<T, U>::value && !detail::is_not_null_or_bool_oracle<U>::value ), int >::type = 0
+ >
+ gsl_NODISCARD gsl_api gsl_constexpr14 explicit
+ operator U() const
+# if gsl_HAVE( FUNCTION_REF_QUALIFIER )
+ &
+# endif
+ {
+ U result( data_.ptr_ );
+ gsl_Ensures( result != gsl_nullptr );
+ return result;
+ }
+# if gsl_HAVE( FUNCTION_REF_QUALIFIER )
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_constructible<U, T>::value && !std::is_convertible<T, U>::value && !detail::is_not_null_or_bool_oracle<U>::value ), int >::type = 0
+ >
+ gsl_NODISCARD gsl_api gsl_constexpr14 explicit
+ operator U() &&
+ {
+ U result( std::move( data_.ptr_ ) );
+ gsl_Ensures( result != gsl_nullptr );
+ return result;
+ }
+# endif
+
+ // implicit conversion operator
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_constructible<U, T const &>::value && std::is_convertible<T, U>::value && !detail::is_not_null_or_bool_oracle<U>::value ), int >::type = 0
+ >
+ gsl_NODISCARD gsl_api gsl_constexpr14
+ operator U() const
+# if gsl_HAVE( FUNCTION_REF_QUALIFIER )
+ &
+# endif
+ {
+ U result( data_.ptr_ );
+ gsl_Ensures( result != gsl_nullptr );
+ return result;
+ }
+# if gsl_HAVE( FUNCTION_REF_QUALIFIER )
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_convertible<T, U>::value && !detail::is_not_null_or_bool_oracle<U>::value ), int >::type = 0
+ >
+ gsl_NODISCARD gsl_api gsl_constexpr14
+ operator U() &&
+ {
+ U result( std::move( data_.ptr_ ) );
+ gsl_Ensures( result != gsl_nullptr );
+ return result;
+ }
+# endif
+#else // a.k.a. #if !( gsl_HAVE( MOVE_FORWARD ) && gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && gsl_HAVE( EXPLICIT ) )
+ template< class U >
+ gsl_NODISCARD gsl_api gsl_constexpr14
+ operator U() const
+ {
+ U result( data_.ptr_ );
+ gsl_Ensures( result != gsl_nullptr );
+ return result;
+ }
+#endif // gsl_HAVE( MOVE_FORWARD ) && gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && gsl_HAVE( EXPLICIT )
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 T const &
+ operator->() const
+ {
+ T const & result( data_.ptr_ );
+ gsl_Ensures( result != gsl_nullptr );
+ return result;
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 element_type &
+ operator*() const
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ return *data_.ptr_;
+ }
+
+#if gsl_HAVE( MOVE_FORWARD )
+ // Visual C++ 2013 doesn't generate default move constructors, so we declare them explicitly.
+ gsl_api gsl_constexpr14 not_null( not_null && other )
+ gsl_noexcept_not_testing // we want to be nothrow-movable despite the precondition check
+ : data_( std::move( other.data_ ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+ gsl_api gsl_constexpr14 not_null & operator=( not_null && other )
+ gsl_noexcept_not_testing // we want to be nothrow-movable despite the precondition check
+ {
+ gsl_Expects( other.data_.ptr_ != gsl_nullptr || &other == this );
+ data_ = std::move( other.data_ );
+ return *this;
+ }
+#endif // gsl_HAVE( MOVE_FORWARD )
+
+#if gsl_HAVE( IS_DEFAULT )
+ gsl_constexpr14 not_null( not_null const & ) = default;
+ gsl_constexpr14 not_null & operator=( not_null const & ) = default;
+#endif
+
+ gsl_api gsl_constexpr20 friend void swap( not_null & lhs, not_null & rhs )
+ gsl_noexcept_not_testing // we want to be nothrow-swappable despite the precondition check
+ {
+ gsl_Expects( lhs.data_.ptr_ != gsl_nullptr && rhs.data_.ptr_ != gsl_nullptr );
+ using std::swap;
+ swap( lhs.data_.ptr_, rhs.data_.ptr_ );
+ }
+
+gsl_is_delete_access:
+ not_null() gsl_is_delete;
+ // prevent compilation when initialized with a nullptr or literal 0:
+#if gsl_HAVE( NULLPTR )
+ not_null( std::nullptr_t ) gsl_is_delete;
+ not_null & operator=( std::nullptr_t ) gsl_is_delete;
+#else
+ not_null( int ) gsl_is_delete;
+ not_null & operator=( int ) gsl_is_delete;
+#endif
+
+ // unwanted operators...pointers only point to single objects!
+ not_null & operator++() gsl_is_delete;
+ not_null & operator--() gsl_is_delete;
+ not_null operator++( int ) gsl_is_delete;
+ not_null operator--( int ) gsl_is_delete;
+ not_null & operator+ ( size_t ) gsl_is_delete;
+ not_null & operator+=( size_t ) gsl_is_delete;
+ not_null & operator- ( size_t ) gsl_is_delete;
+ not_null & operator-=( size_t ) gsl_is_delete;
+ not_null & operator+=( std::ptrdiff_t ) gsl_is_delete;
+ not_null & operator-=( std::ptrdiff_t ) gsl_is_delete;
+ void operator[]( std::ptrdiff_t ) const gsl_is_delete;
+};
+#if gsl_CONFIG_DEFAULTS_VERSION >= 1
+template< class T >
+class not_null< T * >
+{
+private:
+ detail::not_null_data<T *, true> data_;
+
+ // need to access `not_null<U>::data_`
+ template< class U >
+ friend class not_null;
+
+ template< class U >
+ friend struct detail::not_null_accessor;
+
+public:
+ typedef T element_type;
+
+ gsl_api gsl_constexpr14
+#if gsl_CONFIG( NOT_NULL_EXPLICIT_CTOR )
+ explicit
+#endif // gsl_CONFIG( NOT_NULL_EXPLICIT_CTOR )
+ not_null( T * other )
+ : data_( other )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+
+#if gsl_HAVE( MOVE_FORWARD )
+ // In Clang 3.x, `is_constructible<not_null<unique_ptr<X>>, unique_ptr<X>>` tries to instantiate the copy constructor of `unique_ptr<>`, triggering an error.
+ // Note that Apple Clang's `__clang_major__` etc. are different from regular Clang.
+# if gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && ! gsl_BETWEEN( gsl_COMPILER_CLANG_VERSION, 1, 400 ) && ! gsl_BETWEEN( gsl_COMPILER_APPLECLANG_VERSION, 1, 1001 )
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_constructible<T*, U>::value && !std::is_convertible<U, T*>::value ), int >::type = 0
+ >
+ gsl_api gsl_constexpr14 explicit not_null( not_null<U> other )
+ : data_( static_cast<T*>( std::move( other.data_.ptr_ ) ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_convertible<U, T*>::value ), int >::type = 0
+ >
+ gsl_api gsl_constexpr14 not_null( not_null<U> other )
+ : data_( std::move( other.data_.ptr_ ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+# else // a.k.a. ! ( gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && ! gsl_BETWEEN( gsl_COMPILER_CLANG_VERSION, 1, 400 ) && ! gsl_BETWEEN( gsl_COMPILER_APPLECLANG_VERSION, 1, 1001 )
+ // If type_traits are not available, then we can't distinguish `is_convertible<>` and `is_constructible<>`, so we unconditionally permit implicit construction.
+ template< class U >
+ gsl_api gsl_constexpr14 not_null( not_null<U> other )
+ : data_( std::move( other.data_.ptr_ ) )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+ template< class U >
+ gsl_api gsl_constexpr14 not_null<T*>& operator=( not_null<U> other )
+ {
+ gsl_Expects( other.data_.ptr_ != gsl_nullptr );
+ data_.ptr_ = std::move( other.data_.ptr_ );
+ return *this;
+ }
+# endif // gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && ! gsl_BETWEEN( gsl_COMPILER_CLANG_VERSION, 1, 400 ) && ! gsl_BETWEEN( gsl_COMPILER_APPLECLANG_VERSION, 1, 1001 )
+#else // a.k.a. ! gsl_HAVE( MOVE_FORWARD )
+ template< class U >
+ gsl_api gsl_constexpr14 not_null( not_null<U> const& other )
+ : data_( other.data_.ptr_ )
+ {
+ gsl_Expects( data_.ptr_ != gsl_nullptr );
+ }
+ template< class U >
+ gsl_api gsl_constexpr14 not_null<T*>& operator=( not_null<U> const & other )
+ {
+ gsl_Expects( other.data_.ptr_ != gsl_nullptr );
+ data_.ptr_ = other.data_.ptr_;
+ return *this;
+ }
+#endif // gsl_HAVE( MOVE_FORWARD )
+
+#if ! gsl_CONFIG( TRANSPARENT_NOT_NULL )
+ gsl_NODISCARD gsl_api gsl_constexpr14 T*
+ get() const
+ {
+ return data_.ptr_;
+ }
+#endif
+
+#if gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && gsl_HAVE( EXPLICIT )
+ // explicit conversion operator
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_constructible<U, T*>::value && !std::is_convertible<T*, U>::value && !detail::is_not_null_or_bool_oracle<U>::value ), int >::type = 0
+ >
+ gsl_NODISCARD gsl_api gsl_constexpr14 explicit
+ operator U() const
+ {
+ return U( data_.ptr_ );
+ }
+
+ // implicit conversion operator
+ template< class U
+ // We *have* to use SFINAE with an NTTP arg here, otherwise the overload is ambiguous.
+ , typename std::enable_if< ( std::is_constructible<U, T*>::value && std::is_convertible<T*, U>::value && !detail::is_not_null_or_bool_oracle<U>::value ), int >::type = 0
+ >
+ gsl_NODISCARD gsl_api gsl_constexpr14
+ operator U() const
+ {
+ return data_.ptr_;
+ }
+#else // a.k.a. #if !( gsl_HAVE( MOVE_FORWARD ) && gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && gsl_HAVE( EXPLICIT ) )
+ template< class U >
+ gsl_NODISCARD gsl_api gsl_constexpr14
+ operator U() const
+ {
+ return data_.ptr_;
+ }
+#endif // gsl_HAVE( MOVE_FORWARD ) && gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) && gsl_HAVE( EXPLICIT )
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 T*
+ operator->() const
+ {
+ return data_.ptr_;
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 element_type &
+ operator*() const
+ {
+ return *data_.ptr_;
+ }
+
+#if gsl_HAVE( IS_DEFAULT )
+ gsl_constexpr14 not_null( not_null const & ) = default;
+ gsl_constexpr14 not_null & operator=( not_null const & ) = default;
+#endif
+
+ gsl_api gsl_constexpr20 friend void swap( not_null & lhs, not_null & rhs ) gsl_noexcept
+ {
+ using std::swap;
+ swap( lhs.data_.ptr_, rhs.data_.ptr_ );
+ }
+
+gsl_is_delete_access:
+ not_null() gsl_is_delete;
+ // prevent compilation when initialized with a nullptr or literal 0:
+#if gsl_HAVE( NULLPTR )
+ not_null( std::nullptr_t ) gsl_is_delete;
+ not_null & operator=( std::nullptr_t ) gsl_is_delete;
+#else
+ not_null( int ) gsl_is_delete;
+ not_null & operator=( int ) gsl_is_delete;
+#endif
+
+ // unwanted operators...pointers only point to single objects!
+ not_null & operator++() gsl_is_delete;
+ not_null & operator--() gsl_is_delete;
+ not_null operator++( int ) gsl_is_delete;
+ not_null operator--( int ) gsl_is_delete;
+ not_null & operator+ ( size_t ) gsl_is_delete;
+ not_null & operator+=( size_t ) gsl_is_delete;
+ not_null & operator- ( size_t ) gsl_is_delete;
+ not_null & operator-=( size_t ) gsl_is_delete;
+ not_null & operator+=( std::ptrdiff_t ) gsl_is_delete;
+ not_null & operator-=( std::ptrdiff_t ) gsl_is_delete;
+ void operator[]( std::ptrdiff_t ) const gsl_is_delete;
+};
+#endif // gsl_CONFIG_DEFAULTS_VERSION >= 1
+#if gsl_HAVE( DEDUCTION_GUIDES )
+template< class U >
+not_null( U ) -> not_null<U>;
+template< class U >
+not_null( not_null<U> ) -> not_null<U>;
+#endif
+
+#if gsl_HAVE( NULLPTR )
+void make_not_null( std::nullptr_t ) gsl_is_delete;
+#endif // gsl_HAVE( NULLPTR )
+#if gsl_HAVE( MOVE_FORWARD )
+template< class U >
+gsl_NODISCARD gsl_api gsl_constexpr14 not_null<U>
+make_not_null( U u )
+{
+ return not_null<U>( std::move( u ) );
+}
+template< class U >
+gsl_NODISCARD gsl_api gsl_constexpr14 not_null<U>
+make_not_null( not_null<U> u )
+{
+ return std::move( u );
+}
+#else // a.k.a. ! gsl_HAVE( MOVE_FORWARD )
+template< class U >
+gsl_NODISCARD gsl_api not_null<U>
+make_not_null( U const & u )
+{
+ return not_null<U>( u );
+}
+template< class U >
+gsl_NODISCARD gsl_api not_null<U>
+make_not_null( not_null<U> const & u )
+{
+ return u;
+}
+#endif // gsl_HAVE( MOVE_FORWARD )
+
+namespace detail {
+
+template< class T >
+struct as_nullable_helper
+{
+ typedef T type;
+};
+template< class T >
+struct as_nullable_helper< not_null<T> >
+{
+};
+
+template< class T >
+struct not_null_accessor
+{
+#if gsl_HAVE( MOVE_FORWARD )
+ static gsl_api T get( not_null<T>&& p ) gsl_noexcept
+ {
+ return std::move( p.data_.ptr_ );
+ }
+#endif
+ static gsl_api T const & get( not_null<T> const & p ) gsl_noexcept
+ {
+ return p.data_.ptr_;
+ }
+};
+
+namespace no_adl {
+
+#if gsl_HAVE( MOVE_FORWARD )
+template< class T >
+gsl_NODISCARD gsl_api gsl_constexpr auto as_nullable( T && p )
+gsl_noexcept_if( std::is_nothrow_move_constructible<T>::value )
+-> typename detail::as_nullable_helper<typename std20::remove_cvref<T>::type>::type
+{
+ return std::move( p );
+}
+template< class T >
+gsl_NODISCARD gsl_api gsl_constexpr14 T as_nullable( not_null<T> && p )
+{
+ T result = detail::not_null_accessor<T>::get( std::move( p ) );
+ gsl_Expects( result != gsl_nullptr );
+ return result;
+}
+#else // ! gsl_HAVE( MOVE_FORWARD )
+template< class T >
+gsl_NODISCARD gsl_api gsl_constexpr T const & as_nullable( T const & p ) gsl_noexcept
+{
+ return p;
+}
+#endif // gsl_HAVE( MOVE_FORWARD )
+template< class T >
+gsl_NODISCARD gsl_api gsl_constexpr14 T const & as_nullable( not_null<T> const & p )
+{
+ T const & result = detail::not_null_accessor<T>::get( p );
+ gsl_Expects( result != gsl_nullptr );
+ return result;
+}
+template< class T >
+gsl_NODISCARD gsl_api gsl_constexpr T* as_nullable( not_null<T*> p ) gsl_noexcept
+{
+ return detail::not_null_accessor<T*>::get( p );
+}
+
+} // namespace no_adl
+} // namespace detail
+
+using namespace detail::no_adl;
+
+// not_null with implicit constructor, allowing copy-initialization:
+
+template< class T >
+class not_null_ic : public not_null<T>
+{
+public:
+ template< class U
+ gsl_ENABLE_IF_(( std::is_constructible<T, U>::value ))
+ >
+ gsl_api gsl_constexpr14
+#if gsl_HAVE( MOVE_FORWARD )
+ not_null_ic( U && u )
+ : not_null<T>( std::forward<U>( u ) )
+#else // ! gsl_HAVE( MOVE_FORWARD )
+ not_null_ic( U const & u )
+ : not_null<T>( u )
+#endif // gsl_HAVE( MOVE_FORWARD )
+ {}
+};
+
+// more not_null unwanted operators
+
+template< class T, class U >
+std::ptrdiff_t operator-( not_null<T> const &, not_null<U> const & ) gsl_is_delete;
+
+template< class T >
+not_null<T> operator-( not_null<T> const &, std::ptrdiff_t ) gsl_is_delete;
+
+template< class T >
+not_null<T> operator+( not_null<T> const &, std::ptrdiff_t ) gsl_is_delete;
+
+template< class T >
+not_null<T> operator+( std::ptrdiff_t, not_null<T> const & ) gsl_is_delete;
+
+// not_null comparisons
+
+#if gsl_HAVE( NULLPTR ) && gsl_HAVE( IS_DELETE )
+template< class T >
+gsl_constexpr bool
+operator==( not_null<T> const &, std::nullptr_t ) = delete;
+template< class T >
+gsl_constexpr bool
+operator==( std::nullptr_t , not_null<T> const & ) = delete;
+template< class T >
+gsl_constexpr bool
+operator!=( not_null<T> const &, std::nullptr_t ) = delete;
+template< class T >
+gsl_constexpr bool
+operator!=( std::nullptr_t , not_null<T> const & ) = delete;
+#endif // gsl_HAVE( NULLPTR ) && gsl_HAVE( IS_DELETE )
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator==( not_null<T> const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( l.operator->() == r.operator->() )
+{
+ return l.operator->() == r.operator->();
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator==( not_null<T> const & l, U const & r )
+gsl_RETURN_DECLTYPE_(l.operator->() == r )
+{
+ return l.operator->() == r;
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator==( T const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( l == r.operator->() )
+{
+ return l == r.operator->();
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator<( not_null<T> const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( l.operator->() < r.operator->() )
+{
+ return l.operator->() < r.operator->();
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator<( not_null<T> const & l, U const & r )
+gsl_RETURN_DECLTYPE_( l.operator->() < r )
+{
+ return l.operator->() < r;
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator<( T const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( l < r.operator->() )
+{
+ return l < r.operator->();
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator!=( not_null<T> const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( !( l == r ) )
+{
+ return !( l == r );
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator!=( not_null<T> const & l, U const & r )
+gsl_RETURN_DECLTYPE_( !( l == r ) )
+{
+ return !( l == r );
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator!=( T const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( !( l == r ) )
+{
+ return !( l == r );
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator<=( not_null<T> const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( !( r < l ) )
+{
+ return !( r < l );
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator<=( not_null<T> const & l, U const & r )
+gsl_RETURN_DECLTYPE_( !( r < l ) )
+{
+ return !( r < l );
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator<=( T const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( !( r < l ) )
+{
+ return !( r < l );
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator>( not_null<T> const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( r < l )
+{
+ return r < l;
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator>( not_null<T> const & l, U const & r )
+gsl_RETURN_DECLTYPE_( r < l )
+{
+ return r < l;
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator>( T const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( r < l )
+{
+ return r < l;
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator>=( not_null<T> const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( !( l < r ) )
+{
+ return !( l < r );
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator>=( not_null<T> const & l, U const & r )
+gsl_RETURN_DECLTYPE_( !( l < r ) )
+{
+ return !( l < r );
+}
+template< class T, class U >
+gsl_NODISCARD inline gsl_api gsl_constexpr gsl_TRAILING_RETURN_TYPE_( bool )
+operator>=( T const & l, not_null<U> const & r )
+gsl_RETURN_DECLTYPE_( !( l < r ) )
+{
+ return !( l < r );
+}
+
+// print not_null
+
+template< class CharType, class Traits, class T >
+std::basic_ostream< CharType, Traits > & operator<<( std::basic_ostream< CharType, Traits > & os, not_null<T> const & p )
+{
+ return os << p.operator->();
+}
+
+
+//
+// Byte-specific type.
+//
+#if gsl_HAVE( ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE )
+ enum class gsl_may_alias byte : unsigned char {};
+#else
+ struct gsl_may_alias byte { typedef unsigned char type; type v; };
+#endif
+
+template< class T >
+gsl_NODISCARD gsl_api inline gsl_constexpr byte
+to_byte( T v ) gsl_noexcept
+{
+#if gsl_HAVE( ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE )
+ return static_cast<byte>( v );
+#elif gsl_HAVE( CONSTEXPR_11 )
+ return { static_cast<typename byte::type>( v ) };
+#else
+ byte b = { static_cast<typename byte::type>( v ) }; return b;
+#endif
+}
+
+template< class IntegerType gsl_ENABLE_IF_(( std::is_integral<IntegerType>::value )) >
+gsl_NODISCARD gsl_api inline gsl_constexpr IntegerType
+to_integer( byte b ) gsl_noexcept
+{
+#if gsl_HAVE( ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE )
+ return static_cast<typename std::underlying_type<byte>::type>( b );
+#else
+ return b.v;
+#endif
+}
+
+gsl_NODISCARD gsl_api inline gsl_constexpr unsigned char
+to_uchar( byte b ) gsl_noexcept
+{
+ return to_integer<unsigned char>( b );
+}
+
+gsl_NODISCARD gsl_api inline gsl_constexpr unsigned char
+to_uchar( int i ) gsl_noexcept
+{
+ return static_cast<unsigned char>( i );
+}
+
+template< class IntegerType gsl_ENABLE_IF_(( std::is_integral<IntegerType>::value )) >
+gsl_api inline gsl_constexpr14 byte &
+operator<<=( byte & b, IntegerType shift ) gsl_noexcept
+{
+#if gsl_HAVE( ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE )
+ return b = ::gsl::to_byte( ::gsl::to_uchar( b ) << shift );
+#else
+ b.v = ::gsl::to_uchar( b.v << shift ); return b;
+#endif
+}
+
+template< class IntegerType gsl_ENABLE_IF_(( std::is_integral<IntegerType>::value )) >
+gsl_NODISCARD gsl_api inline gsl_constexpr byte
+operator<<( byte b, IntegerType shift ) gsl_noexcept
+{
+ return ::gsl::to_byte( ::gsl::to_uchar( b ) << shift );
+}
+
+template< class IntegerType gsl_ENABLE_IF_(( std::is_integral<IntegerType>::value )) >
+gsl_NODISCARD gsl_api inline gsl_constexpr14 byte &
+operator>>=( byte & b, IntegerType shift ) gsl_noexcept
+{
+#if gsl_HAVE( ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE )
+ return b = ::gsl::to_byte( ::gsl::to_uchar( b ) >> shift );
+#else
+ b.v = ::gsl::to_uchar( b.v >> shift ); return b;
+#endif
+}
+
+template< class IntegerType gsl_ENABLE_IF_(( std::is_integral<IntegerType>::value )) >
+gsl_NODISCARD gsl_api inline gsl_constexpr byte
+operator>>( byte b, IntegerType shift ) gsl_noexcept
+{
+ return ::gsl::to_byte( ::gsl::to_uchar( b ) >> shift );
+}
+
+#if gsl_HAVE( ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE )
+gsl_DEFINE_ENUM_BITMASK_OPERATORS( byte )
+gsl_DEFINE_ENUM_RELATIONAL_OPERATORS( byte )
+#else // a.k.a. !gsl_HAVE( ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE )
+gsl_api inline gsl_constexpr bool operator==( byte l, byte r ) gsl_noexcept
+{
+ return l.v == r.v;
+}
+
+gsl_api inline gsl_constexpr bool operator!=( byte l, byte r ) gsl_noexcept
+{
+ return !( l == r );
+}
+
+gsl_api inline gsl_constexpr bool operator< ( byte l, byte r ) gsl_noexcept
+{
+ return l.v < r.v;
+}
+
+gsl_api inline gsl_constexpr bool operator<=( byte l, byte r ) gsl_noexcept
+{
+ return !( r < l );
+}
+
+gsl_api inline gsl_constexpr bool operator> ( byte l, byte r ) gsl_noexcept
+{
+ return ( r < l );
+}
+
+gsl_api inline gsl_constexpr bool operator>=( byte l, byte r ) gsl_noexcept
+{
+ return !( l < r );
+}
+
+gsl_api inline gsl_constexpr14 byte & operator|=( byte & l, byte r ) gsl_noexcept
+{
+ l.v |= r.v; return l;
+}
+
+gsl_api inline gsl_constexpr byte operator|( byte l, byte r ) gsl_noexcept
+{
+ return ::gsl::to_byte( l.v | r.v );
+}
+
+gsl_api inline gsl_constexpr14 byte & operator&=( byte & l, byte r ) gsl_noexcept
+{
+ l.v &= r.v; return l;
+}
+
+gsl_api inline gsl_constexpr byte operator&( byte l, byte r ) gsl_noexcept
+{
+ return ::gsl::to_byte( l.v & r.v );
+}
+
+gsl_api inline gsl_constexpr14 byte & operator^=( byte & l, byte r ) gsl_noexcept
+{
+ l.v ^= r.v; return l;
+}
+
+gsl_api inline gsl_constexpr byte operator^( byte l, byte r ) gsl_noexcept
+{
+ return ::gsl::to_byte( l.v ^ r.v );
+}
+
+gsl_api inline gsl_constexpr byte operator~( byte b ) gsl_noexcept
+{
+ return ::gsl::to_byte( ~b.v );
+}
+#endif // gsl_HAVE( ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE )
+
+#if gsl_FEATURE_TO_STD( WITH_CONTAINER )
+
+// Tag to select span constructor taking a container:
+
+struct with_container_t { gsl_constexpr with_container_t( ) gsl_noexcept { } };
+const gsl_constexpr with_container_t with_container; // TODO: this can lead to ODR violations because the symbol will be defined in multiple translation units
+
+#endif
+
+namespace detail {
+
+template< class T >
+gsl_api gsl_constexpr14 T * endptr( T * data, gsl_CONFIG_SPAN_INDEX_TYPE size )
+{
+ // Be sure to run the check before doing pointer arithmetics, which would be UB for `nullptr` and non-0 integers.
+ gsl_Expects( size == 0 || data != gsl_nullptr );
+ return data + size;
+}
+
+} // namespace detail
+
+//
+// span<> - A 1D view of contiguous T's, replace (*,len).
+//
+template< class T >
+class span
+{
+ template< class U > friend class span;
+
+public:
+ typedef gsl_CONFIG_SPAN_INDEX_TYPE index_type;
+
+ typedef T element_type;
+ typedef typename std11::remove_cv< T >::type value_type;
+
+ typedef T & reference;
+ typedef T * pointer;
+ typedef T const * const_pointer;
+ typedef T const & const_reference;
+
+ typedef pointer iterator;
+ typedef const_pointer const_iterator;
+
+ typedef std::reverse_iterator< iterator > reverse_iterator;
+ typedef std::reverse_iterator< const_iterator > const_reverse_iterator;
+
+ typedef gsl_CONFIG_SPAN_INDEX_TYPE size_type;
+ typedef std::ptrdiff_t difference_type;
+
+ // 26.7.3.2 Constructors, copy, and assignment [span.cons]
+
+ gsl_api gsl_constexpr span() gsl_noexcept
+ : first_( gsl_nullptr )
+ , last_ ( gsl_nullptr )
+ {
+ }
+
+#if ! gsl_DEPRECATE_TO_LEVEL( 5 )
+
+#if gsl_HAVE( NULLPTR )
+ gsl_api gsl_constexpr14 span( std::nullptr_t, index_type size_in )
+ : first_( nullptr )
+ , last_ ( nullptr )
+ {
+ gsl_Expects( size_in == 0 );
+ }
+#endif
+
+#if gsl_HAVE( IS_DELETE )
+ gsl_DEPRECATED
+ gsl_api gsl_constexpr span( reference data_in )
+ : span( &data_in, 1 )
+ {}
+
+ gsl_api gsl_constexpr span( element_type && ) = delete;
+#endif
+
+#endif // deprecate
+
+ gsl_api gsl_constexpr14 span( pointer data_in, index_type size_in )
+ : first_( data_in )
+ , last_( detail::endptr( data_in, size_in ) )
+ {
+ }
+
+ gsl_api gsl_constexpr14 span( pointer first_in, pointer last_in )
+ : first_( first_in )
+ , last_ ( last_in )
+ {
+ gsl_Expects( first_in <= last_in );
+ }
+
+#if ! gsl_DEPRECATE_TO_LEVEL( 5 )
+
+ template< class U >
+ gsl_api gsl_constexpr14 span( U * data_in, index_type size_in )
+ : first_( data_in )
+ , last_( detail::endptr( data_in, size_in ) )
+ {
+ }
+
+#endif // deprecate
+
+#if ! gsl_DEPRECATE_TO_LEVEL( 5 )
+ template< class U, size_t N >
+ gsl_api gsl_constexpr span( U (&arr)[N] ) gsl_noexcept
+ : first_( gsl_ADDRESSOF( arr[0] ) )
+ , last_ ( gsl_ADDRESSOF( arr[0] ) + N )
+ {}
+#else
+ template< size_t N
+ gsl_ENABLE_IF_(( std::is_convertible<value_type(*)[], element_type(*)[] >::value ))
+ >
+ gsl_api gsl_constexpr span( element_type (&arr)[N] ) gsl_noexcept
+ : first_( gsl_ADDRESSOF( arr[0] ) )
+ , last_ ( gsl_ADDRESSOF( arr[0] ) + N )
+ {}
+#endif // deprecate
+
+#if gsl_HAVE( ARRAY )
+#if ! gsl_DEPRECATE_TO_LEVEL( 5 )
+
+ template< class U, size_t N >
+ gsl_api gsl_constexpr span( std::array< U, N > & arr )
+ : first_( arr.data() )
+ , last_ ( arr.data() + N )
+ {}
+
+ template< class U, size_t N >
+ gsl_api gsl_constexpr span( std::array< U, N > const & arr )
+ : first_( arr.data() )
+ , last_ ( arr.data() + N )
+ {}
+
+#else
+
+ template< size_t N
+ gsl_ENABLE_IF_(( std::is_convertible<value_type(*)[], element_type(*)[] >::value ))
+ >
+ gsl_constexpr span( std::array< value_type, N > & arr )
+ : first_( arr.data() )
+ , last_ ( arr.data() + N )
+ {}
+
+ template< size_t N
+ gsl_ENABLE_IF_(( std::is_convertible<value_type(*)[], element_type(*)[] >::value ))
+ >
+ gsl_constexpr span( std::array< value_type, N > const & arr )
+ : first_( arr.data() )
+ , last_ ( arr.data() + N )
+ {}
+
+#endif // deprecate
+#endif // gsl_HAVE( ARRAY )
+
+#if gsl_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR )
+ template< class Container
+ gsl_ENABLE_IF_(( detail::is_compatible_container< Container, element_type >::value ))
+ >
+ gsl_api gsl_constexpr span( Container & cont ) gsl_noexcept
+ : first_( std17::data( cont ) )
+ , last_ ( std17::data( cont ) + std17::size( cont ) )
+ {}
+
+ template< class Container
+ gsl_ENABLE_IF_((
+ std::is_const< element_type >::value
+ && detail::is_compatible_container< Container, element_type >::value
+ ))
+ >
+ gsl_api gsl_constexpr span( Container const & cont ) gsl_noexcept
+ : first_( std17::data( cont ) )
+ , last_ ( std17::data( cont ) + std17::size( cont ) )
+ {}
+
+#elif gsl_HAVE( UNCONSTRAINED_SPAN_CONTAINER_CTOR )
+
+ template< class Container >
+ gsl_constexpr span( Container & cont )
+ : first_( cont.size() == 0 ? gsl_nullptr : gsl_ADDRESSOF( cont[0] ) )
+ , last_ ( cont.size() == 0 ? gsl_nullptr : gsl_ADDRESSOF( cont[0] ) + cont.size() )
+ {}
+
+ template< class Container >
+ gsl_constexpr span( Container const & cont )
+ : first_( cont.size() == 0 ? gsl_nullptr : gsl_ADDRESSOF( cont[0] ) )
+ , last_ ( cont.size() == 0 ? gsl_nullptr : gsl_ADDRESSOF( cont[0] ) + cont.size() )
+ {}
+
+#endif
+
+#if gsl_FEATURE_TO_STD( WITH_CONTAINER )
+
+ template< class Container >
+ gsl_constexpr span( with_container_t, Container & cont ) gsl_noexcept
+ : first_( cont.size() == 0 ? gsl_nullptr : gsl_ADDRESSOF( cont[0] ) )
+ , last_ ( cont.size() == 0 ? gsl_nullptr : gsl_ADDRESSOF( cont[0] ) + cont.size() )
+ {}
+
+ template< class Container >
+ gsl_constexpr span( with_container_t, Container const & cont ) gsl_noexcept
+ : first_( cont.size() == 0 ? gsl_nullptr : gsl_ADDRESSOF( cont[0] ) )
+ , last_ ( cont.size() == 0 ? gsl_nullptr : gsl_ADDRESSOF( cont[0] ) + cont.size() )
+ {}
+
+#endif
+
+#if !gsl_DEPRECATE_TO_LEVEL( 4 )
+ // constructor taking shared_ptr deprecated since 0.29.0
+
+# if gsl_HAVE( SHARED_PTR )
+ gsl_DEPRECATED
+ gsl_constexpr span( shared_ptr<element_type> const & ptr )
+ : first_( ptr.get() )
+ , last_ ( ptr.get() ? ptr.get() + 1 : gsl_nullptr )
+ {}
+# endif
+
+ // constructors taking unique_ptr deprecated since 0.29.0
+
+# if gsl_HAVE( UNIQUE_PTR )
+# if gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG )
+ template< class ArrayElementType = typename std::add_pointer<element_type>::type >
+# else
+ template< class ArrayElementType >
+# endif
+ gsl_DEPRECATED
+ gsl_constexpr span( unique_ptr<ArrayElementType> const & ptr, index_type count )
+ : first_( ptr.get() )
+ , last_ ( ptr.get() + count )
+ {}
+
+ gsl_DEPRECATED
+ gsl_constexpr span( unique_ptr<element_type> const & ptr )
+ : first_( ptr.get() )
+ , last_ ( ptr.get() ? ptr.get() + 1 : gsl_nullptr )
+ {}
+# endif
+
+#endif // deprecate shared_ptr, unique_ptr
+
+#if gsl_HAVE( IS_DEFAULT ) && ! gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 430, 600)
+ gsl_constexpr span( span && ) gsl_noexcept = default;
+ gsl_constexpr span( span const & ) = default;
+#else
+ gsl_api gsl_constexpr span( span const & other )
+ : first_( other.begin() )
+ , last_ ( other.end() )
+ {}
+#endif
+
+#if gsl_HAVE( IS_DEFAULT )
+ gsl_constexpr14 span & operator=( span && ) gsl_noexcept = default;
+ gsl_constexpr14 span & operator=( span const & ) gsl_noexcept = default;
+#else
+ gsl_constexpr14 span & operator=( span other ) gsl_noexcept
+ {
+ first_ = other.first_;
+ last_ = other.last_;
+ return *this;
+ }
+#endif
+
+ template< class U
+ gsl_ENABLE_IF_(( std::is_convertible<U(*)[], element_type(*)[]>::value ))
+ >
+ gsl_api gsl_constexpr span( span<U> const & other )
+ : first_( other.begin() )
+ , last_ ( other.end() )
+ {}
+
+#if 0
+ // Converting from other span ?
+ template< class U > operator=();
+#endif
+
+ // 26.7.3.3 Subviews [span.sub]
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 span
+ first( index_type count ) const
+ {
+ gsl_Expects( std::size_t( count ) <= std::size_t( this->size() ) );
+ return span( this->data(), count );
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 span
+ last( index_type count ) const
+ {
+ gsl_Expects( std::size_t( count ) <= std::size_t( this->size() ) );
+ return span( this->data() + this->size() - count, count );
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 span
+ subspan( index_type offset ) const
+ {
+ gsl_Expects( std::size_t( offset ) <= std::size_t( this->size() ) );
+ return span( this->data() + offset, this->size() - offset );
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 span
+ subspan( index_type offset, index_type count ) const
+ {
+ gsl_Expects(
+ std::size_t( offset ) <= std::size_t( this->size() ) &&
+ std::size_t( count ) <= std::size_t( this->size() - offset ) );
+ return span( this->data() + offset, count );
+ }
+
+ // 26.7.3.4 Observers [span.obs]
+
+ gsl_NODISCARD gsl_api gsl_constexpr index_type
+ size() const gsl_noexcept
+ {
+ return narrow_cast<index_type>( last_ - first_ );
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr std::ptrdiff_t
+ ssize() const gsl_noexcept
+ {
+ return narrow_cast<std::ptrdiff_t>( last_ - first_ );
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr index_type
+ size_bytes() const gsl_noexcept
+ {
+ return size() * narrow_cast<index_type>( sizeof( element_type ) );
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr bool
+ empty() const gsl_noexcept
+ {
+ return size() == 0;
+ }
+
+ // 26.7.3.5 Element access [span.elem]
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 reference
+ operator[]( index_type pos ) const
+ {
+ gsl_Expects( pos < size() );
+ return first_[ pos ];
+ }
+
+#if ! gsl_DEPRECATE_TO_LEVEL( 6 )
+ gsl_DEPRECATED_MSG("use subscript indexing instead")
+ gsl_api gsl_constexpr14 reference
+ operator()( index_type pos ) const
+ {
+ return (*this)[ pos ];
+ }
+
+ gsl_DEPRECATED_MSG("use subscript indexing instead")
+ gsl_api gsl_constexpr14 reference
+ at( index_type pos ) const
+ {
+ return (*this)[ pos ];
+ }
+#endif // deprecate
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 reference
+ front() const
+ {
+ gsl_Expects( first_ != last_ );
+ return *first_;
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 reference
+ back() const
+ {
+ gsl_Expects( first_ != last_ );
+ return *(last_ - 1);
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr pointer
+ data() const gsl_noexcept
+ {
+ return first_;
+ }
+
+ // 26.7.3.6 Iterator support [span.iterators]
+
+ gsl_NODISCARD gsl_api gsl_constexpr iterator
+ begin() const gsl_noexcept
+ {
+ return iterator( first_ );
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr iterator
+ end() const gsl_noexcept
+ {
+ return iterator( last_ );
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr const_iterator
+ cbegin() const gsl_noexcept
+ {
+#if gsl_CPP11_OR_GREATER
+ return { begin() };
+#else
+ return const_iterator( begin() );
+#endif
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr const_iterator
+ cend() const gsl_noexcept
+ {
+#if gsl_CPP11_OR_GREATER
+ return { end() };
+#else
+ return const_iterator( end() );
+#endif
+ }
+
+ gsl_NODISCARD gsl_constexpr17 reverse_iterator
+ rbegin() const gsl_noexcept
+ {
+ return reverse_iterator( end() );
+ }
+
+ gsl_NODISCARD gsl_constexpr17 reverse_iterator
+ rend() const gsl_noexcept
+ {
+ return reverse_iterator( begin() );
+ }
+
+ gsl_NODISCARD gsl_constexpr17 const_reverse_iterator
+ crbegin() const gsl_noexcept
+ {
+ return const_reverse_iterator( cend() );
+ }
+
+ gsl_NODISCARD gsl_constexpr17 const_reverse_iterator
+ crend() const gsl_noexcept
+ {
+ return const_reverse_iterator( cbegin() );
+ }
+
+ gsl_constexpr14 void swap( span & other ) gsl_noexcept
+ {
+ std::swap( first_, other.first_ );
+ std::swap( last_ , other.last_ );
+ }
+
+#if ! gsl_DEPRECATE_TO_LEVEL( 3 )
+ // member length() deprecated since 0.29.0
+
+ gsl_DEPRECATED_MSG("use size() instead")
+ gsl_api gsl_constexpr index_type length() const gsl_noexcept
+ {
+ return size();
+ }
+
+ // member length_bytes() deprecated since 0.29.0
+
+ gsl_DEPRECATED_MSG("use size_bytes() instead")
+ gsl_api gsl_constexpr index_type length_bytes() const gsl_noexcept
+ {
+ return size_bytes();
+ }
+#endif
+
+#if ! gsl_DEPRECATE_TO_LEVEL( 2 )
+ // member as_bytes(), as_writeable_bytes deprecated since 0.17.0
+
+ gsl_DEPRECATED_MSG("use free function gsl::as_bytes() instead")
+ gsl_api span< const byte > as_bytes() const gsl_noexcept
+ {
+ return span< const byte >( reinterpret_cast<const byte *>( data() ), size_bytes() ); // NOLINT
+ }
+
+ gsl_DEPRECATED_MSG("use free function gsl::as_writable_bytes() instead")
+ gsl_api span< byte > as_writeable_bytes() const gsl_noexcept
+ {
+ return span< byte >( reinterpret_cast<byte *>( data() ), size_bytes() ); // NOLINT
+ }
+
+#endif
+
+ template< class U >
+ gsl_NODISCARD gsl_api span< U >
+ as_span() const
+ {
+ gsl_Expects( ( this->size_bytes() % sizeof(U) ) == 0 );
+ return span< U >( reinterpret_cast<U *>( this->data() ), this->size_bytes() / sizeof( U ) ); // NOLINT
+ }
+
+private:
+ pointer first_;
+ pointer last_;
+};
+
+// class template argument deduction guides:
+
+#if gsl_HAVE( DEDUCTION_GUIDES ) // gsl_CPP17_OR_GREATER
+
+template< class T, size_t N >
+span( T (&)[N] ) -> span<T /*, N*/>;
+
+template< class T, size_t N >
+span( std::array<T, N> & ) -> span<T /*, N*/>;
+
+template< class T, size_t N >
+span( std::array<T, N> const & ) -> span<const T /*, N*/>;
+
+template< class Container >
+span( Container& ) -> span<typename Container::value_type>;
+
+template< class Container >
+span( Container const & ) -> span<const typename Container::value_type>;
+
+#endif // gsl_HAVE( DEDUCTION_GUIDES )
+
+// 26.7.3.7 Comparison operators [span.comparison]
+
+#if gsl_CONFIG( ALLOWS_SPAN_COMPARISON )
+# if gsl_CONFIG( ALLOWS_NONSTRICT_SPAN_COMPARISON )
+
+template< class T, class U >
+gsl_SUPPRESS_MSGSL_WARNING(stl.1)
+gsl_NODISCARD inline gsl_constexpr bool operator==( span<T> const & l, span<U> const & r )
+{
+ return l.size() == r.size()
+ && (l.begin() == r.begin() || std98::equal( l.begin(), l.end(), r.begin() ) );
+}
+
+template< class T, class U >
+gsl_SUPPRESS_MSGSL_WARNING(stl.1)
+gsl_NODISCARD inline gsl_constexpr bool operator< ( span<T> const & l, span<U> const & r )
+{
+ return std98::lexicographical_compare( l.begin(), l.end(), r.begin(), r.end() );
+}
+
+# else // a.k.a. !gsl_CONFIG( ALLOWS_NONSTRICT_SPAN_COMPARISON )
+
+template< class T >
+gsl_SUPPRESS_MSGSL_WARNING(stl.1)
+gsl_NODISCARD inline gsl_constexpr bool operator==( span<T> const & l, span<T> const & r )
+{
+ return l.size() == r.size()
+ && (l.begin() == r.begin() || std98::equal( l.begin(), l.end(), r.begin() ) );
+}
+
+template< class T >
+gsl_SUPPRESS_MSGSL_WARNING(stl.1)
+gsl_NODISCARD inline gsl_constexpr bool operator< ( span<T> const & l, span<T> const & r )
+{
+ return std98::lexicographical_compare( l.begin(), l.end(), r.begin(), r.end() );
+}
+# endif // gsl_CONFIG( ALLOWS_NONSTRICT_SPAN_COMPARISON )
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_constexpr bool operator!=( span<T> const & l, span<U> const & r )
+{
+ return !( l == r );
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_constexpr bool operator<=( span<T> const & l, span<U> const & r )
+{
+ return !( r < l );
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_constexpr bool operator> ( span<T> const & l, span<U> const & r )
+{
+ return ( r < l );
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_constexpr bool operator>=( span<T> const & l, span<U> const & r )
+{
+ return !( l < r );
+}
+#endif // gsl_CONFIG( ALLOWS_SPAN_COMPARISON )
+
+// span algorithms
+
+template< class T >
+gsl_NODISCARD gsl_api inline gsl_constexpr std::size_t
+size( span<T> const & spn )
+{
+ return static_cast<std::size_t>( spn.size() );
+}
+
+template< class T >
+gsl_NODISCARD gsl_api inline gsl_constexpr std::ptrdiff_t
+ssize( span<T> const & spn )
+{
+ return spn.ssize();
+}
+
+namespace detail {
+
+template< class II, class N, class OI >
+gsl_api gsl_constexpr14 inline OI copy_n( II first, N count, OI result )
+{
+ if ( count > 0 )
+ {
+ *result++ = *first;
+ for ( N i = 1; i < count; ++i )
+ {
+ *result++ = *++first;
+ }
+ }
+ return result;
+}
+}
+
+template< class T, class U >
+gsl_api gsl_constexpr14 inline void copy( span<T> src, span<U> dest )
+{
+#if gsl_CPP14_OR_GREATER // gsl_HAVE( TYPE_TRAITS ) (circumvent Travis clang 3.4)
+ static_assert( std::is_assignable<U &, T const &>::value, "Cannot assign elements of source span to elements of destination span" );
+#endif
+ gsl_Expects( dest.size() >= src.size() );
+ detail::copy_n( src.data(), src.size(), dest.data() );
+}
+
+// span creator functions (see ctors)
+
+template< class T >
+gsl_NODISCARD gsl_api inline span< const byte >
+as_bytes( span<T> spn ) gsl_noexcept
+{
+ return span< const byte >( reinterpret_cast<const byte *>( spn.data() ), spn.size_bytes() ); // NOLINT
+}
+
+template< class T>
+gsl_NODISCARD gsl_api inline span< byte >
+as_writable_bytes( span<T> spn ) gsl_noexcept
+{
+ return span< byte >( reinterpret_cast<byte *>( spn.data() ), spn.size_bytes() ); // NOLINT
+}
+
+#if ! gsl_DEPRECATE_TO_LEVEL( 6 )
+template< class T>
+gsl_DEPRECATED_MSG("use as_writable_bytes() (different spelling) instead")
+gsl_api inline span< byte > as_writeable_bytes( span<T> spn ) gsl_noexcept
+{
+ return span< byte >( reinterpret_cast<byte *>( spn.data() ), spn.size_bytes() ); // NOLINT
+}
+#endif // deprecate
+
+#if gsl_FEATURE_TO_STD( MAKE_SPAN )
+
+template< class T >
+gsl_NODISCARD gsl_api inline gsl_constexpr span<T>
+make_span( T * ptr, typename span<T>::index_type count )
+{
+ return span<T>( ptr, count );
+}
+
+template< class T >
+gsl_NODISCARD gsl_api inline gsl_constexpr span<T>
+make_span( T * first, T * last )
+{
+ return span<T>( first, last );
+}
+
+template< class T, size_t N >
+gsl_NODISCARD inline gsl_constexpr span<T>
+make_span( T (&arr)[N] )
+{
+ return span<T>( gsl_ADDRESSOF( arr[0] ), N );
+}
+
+#if gsl_HAVE( ARRAY )
+
+template< class T, size_t N >
+gsl_NODISCARD inline gsl_constexpr span<T>
+make_span( std::array<T,N> & arr )
+{
+ return span<T>( arr );
+}
+
+template< class T, size_t N >
+gsl_NODISCARD inline gsl_constexpr span<const T>
+make_span( std::array<T,N> const & arr )
+{
+ return span<const T>( arr );
+}
+#endif
+
+#if gsl_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) && gsl_HAVE( AUTO )
+
+template< class Container, class EP = decltype( std17::data(std::declval<Container&>())) >
+gsl_NODISCARD inline gsl_constexpr auto
+make_span( Container & cont ) -> span< typename std::remove_pointer<EP>::type >
+{
+ return span< typename std::remove_pointer<EP>::type >( cont );
+}
+
+template< class Container, class EP = decltype( std17::data(std::declval<Container&>())) >
+gsl_NODISCARD inline gsl_constexpr auto
+make_span( Container const & cont ) -> span< const typename std::remove_pointer<EP>::type >
+{
+ return span< const typename std::remove_pointer<EP>::type >( cont );
+}
+
+#else
+
+template< class T >
+inline span<T>
+make_span( std::vector<T> & cont )
+{
+ return span<T>( with_container, cont );
+}
+
+template< class T >
+inline span<const T>
+make_span( std::vector<T> const & cont )
+{
+ return span<const T>( with_container, cont );
+}
+#endif
+
+#if gsl_FEATURE_TO_STD( WITH_CONTAINER )
+
+template< class Container >
+gsl_NODISCARD inline gsl_constexpr span<typename Container::value_type>
+make_span( with_container_t, Container & cont ) gsl_noexcept
+{
+ return span< typename Container::value_type >( with_container, cont );
+}
+
+template< class Container >
+gsl_NODISCARD inline gsl_constexpr span<const typename Container::value_type>
+make_span( with_container_t, Container const & cont ) gsl_noexcept
+{
+ return span< const typename Container::value_type >( with_container, cont );
+}
+
+#endif // gsl_FEATURE_TO_STD( WITH_CONTAINER )
+
+#if !gsl_DEPRECATE_TO_LEVEL( 4 )
+template< class Ptr >
+gsl_DEPRECATED
+inline span<typename Ptr::element_type>
+make_span( Ptr & ptr )
+{
+ return span<typename Ptr::element_type>( ptr );
+}
+#endif // !gsl_DEPRECATE_TO_LEVEL( 4 )
+
+template< class Ptr >
+gsl_DEPRECATED
+inline span<typename Ptr::element_type>
+make_span( Ptr & ptr, typename span<typename Ptr::element_type>::index_type count )
+{
+ return span<typename Ptr::element_type>( ptr, count );
+}
+
+#endif // gsl_FEATURE_TO_STD( MAKE_SPAN )
+
+#if gsl_FEATURE_TO_STD( BYTE_SPAN )
+
+template< class T >
+gsl_NODISCARD gsl_api inline gsl_constexpr span<byte>
+byte_span( T & t ) gsl_noexcept
+{
+ return span<byte>( reinterpret_cast<byte *>( &t ), sizeof(T) );
+}
+
+template< class T >
+gsl_NODISCARD gsl_api inline gsl_constexpr span<const byte>
+byte_span( T const & t ) gsl_noexcept
+{
+ return span<const byte>( reinterpret_cast<byte const *>( &t ), sizeof(T) );
+}
+
+#endif // gsl_FEATURE_TO_STD( BYTE_SPAN )
+
+//
+// basic_string_span:
+//
+
+template< class T >
+class basic_string_span;
+
+namespace detail {
+
+template< class T >
+struct is_basic_string_span_oracle : std11::false_type {};
+
+template< class T >
+struct is_basic_string_span_oracle< basic_string_span<T> > : std11::true_type {};
+
+template< class T >
+struct is_basic_string_span : is_basic_string_span_oracle< typename std11::remove_cv<T>::type > {};
+
+template< class T >
+gsl_api inline gsl_constexpr14 std::size_t string_length( T * ptr, std::size_t max )
+{
+ if ( ptr == gsl_nullptr || max <= 0 )
+ return 0;
+
+ std::size_t len = 0;
+ while ( len < max && ptr[len] ) // NOLINT
+ ++len;
+
+ return len;
+}
+
+} // namespace detail
+
+//
+// basic_string_span<> - A view of contiguous characters, replace (*,len).
+//
+template< class T >
+class basic_string_span
+{
+public:
+ typedef T element_type;
+ typedef span<T> span_type;
+
+ typedef typename span_type::size_type size_type;
+ typedef typename span_type::index_type index_type;
+ typedef typename span_type::difference_type difference_type;
+
+ typedef typename span_type::pointer pointer ;
+ typedef typename span_type::reference reference ;
+
+ typedef typename span_type::iterator iterator ;
+ typedef typename span_type::const_iterator const_iterator ;
+ typedef typename span_type::reverse_iterator reverse_iterator;
+ typedef typename span_type::const_reverse_iterator const_reverse_iterator;
+
+ // construction:
+
+#if gsl_HAVE( IS_DEFAULT )
+ gsl_constexpr basic_string_span() gsl_noexcept = default;
+#else
+ gsl_api gsl_constexpr basic_string_span() gsl_noexcept {}
+#endif
+
+#if gsl_HAVE( NULLPTR )
+ gsl_api gsl_constexpr basic_string_span( std::nullptr_t ) gsl_noexcept
+ : span_( nullptr, static_cast<index_type>( 0 ) )
+ {}
+#endif
+
+#ifdef __CUDACC_RELAXED_CONSTEXPR__
+ gsl_api
+#endif // __CUDACC_RELAXED_CONSTEXPR__
+ gsl_constexpr basic_string_span( pointer ptr )
+ : span_( remove_z( ptr, (std::numeric_limits<index_type>::max)() ) )
+ {}
+
+ gsl_api gsl_constexpr basic_string_span( pointer ptr, index_type count )
+ : span_( ptr, count )
+ {}
+
+ gsl_api gsl_constexpr basic_string_span( pointer firstElem, pointer lastElem )
+ : span_( firstElem, lastElem )
+ {}
+
+ template< std::size_t N >
+ gsl_constexpr basic_string_span( element_type (&arr)[N] )
+ : span_( remove_z( gsl_ADDRESSOF( arr[0] ), N ) )
+ {}
+
+#if gsl_HAVE( ARRAY )
+
+ template< std::size_t N >
+ gsl_constexpr basic_string_span( std::array< typename std11::remove_const<element_type>::type, N> & arr )
+ : span_( remove_z( arr ) )
+ {}
+
+ template< std::size_t N >
+ gsl_constexpr basic_string_span( std::array< typename std11::remove_const<element_type>::type, N> const & arr )
+ : span_( remove_z( arr ) )
+ {}
+
+#endif
+
+#if gsl_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR )
+
+ // Exclude: array, [basic_string,] basic_string_span
+
+ template< class Container
+ gsl_ENABLE_IF_((
+ ! detail::is_std_array< Container >::value
+ && ! detail::is_basic_string_span< Container >::value
+ && std::is_convertible< typename Container::pointer, pointer >::value
+ && std::is_convertible< typename Container::pointer, decltype(std::declval<Container>().data()) >::value
+ ))
+ >
+ gsl_constexpr basic_string_span( Container & cont )
+ : span_( ( cont ) )
+ {}
+
+ // Exclude: array, [basic_string,] basic_string_span
+
+ template< class Container
+ gsl_ENABLE_IF_((
+ ! detail::is_std_array< Container >::value
+ && ! detail::is_basic_string_span< Container >::value
+ && std::is_convertible< typename Container::pointer, pointer >::value
+ && std::is_convertible< typename Container::pointer, decltype(std::declval<Container const &>().data()) >::value
+ ))
+ >
+ gsl_constexpr basic_string_span( Container const & cont )
+ : span_( ( cont ) )
+ {}
+
+#elif gsl_HAVE( UNCONSTRAINED_SPAN_CONTAINER_CTOR )
+
+ template< class Container >
+ gsl_constexpr basic_string_span( Container & cont )
+ : span_( cont )
+ {}
+
+ template< class Container >
+ gsl_constexpr basic_string_span( Container const & cont )
+ : span_( cont )
+ {}
+
+#else
+
+ template< class U >
+ gsl_api gsl_constexpr basic_string_span( span<U> const & rhs )
+ : span_( rhs )
+ {}
+
+#endif
+
+#if gsl_FEATURE_TO_STD( WITH_CONTAINER )
+
+ template< class Container >
+ gsl_constexpr basic_string_span( with_container_t, Container & cont )
+ : span_( with_container, cont )
+ {}
+#endif
+
+#if gsl_HAVE( IS_DEFAULT )
+# if gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 440, 600 )
+ gsl_constexpr basic_string_span( basic_string_span const & ) = default;
+
+ gsl_constexpr basic_string_span( basic_string_span && ) = default;
+# else
+ gsl_constexpr basic_string_span( basic_string_span const & ) gsl_noexcept = default;
+
+ gsl_constexpr basic_string_span( basic_string_span && ) gsl_noexcept = default;
+# endif
+#endif
+
+ template< class U
+ gsl_ENABLE_IF_(( std::is_convertible<typename basic_string_span<U>::pointer, pointer>::value ))
+ >
+ gsl_api gsl_constexpr basic_string_span( basic_string_span<U> const & rhs )
+ : span_( reinterpret_cast<pointer>( rhs.data() ), rhs.length() ) // NOLINT
+ {}
+
+#if gsl_STDLIB_CPP11_120
+ template< class U
+ gsl_ENABLE_IF_(( std::is_convertible<typename basic_string_span<U>::pointer, pointer>::value ))
+ >
+ gsl_api gsl_constexpr basic_string_span( basic_string_span<U> && rhs )
+ : span_( reinterpret_cast<pointer>( rhs.data() ), rhs.length() ) // NOLINT
+ {}
+#endif // gsl_STDLIB_CPP11_120
+
+ template< class CharTraits, class Allocator >
+ gsl_constexpr basic_string_span(
+ std::basic_string< typename std11::remove_const<element_type>::type, CharTraits, Allocator > & str )
+ : span_( gsl_ADDRESSOF( str[0] ), str.length() )
+ {}
+
+ template< class CharTraits, class Allocator >
+ gsl_constexpr basic_string_span(
+ std::basic_string< typename std11::remove_const<element_type>::type, CharTraits, Allocator > const & str )
+ : span_( gsl_ADDRESSOF( str[0] ), str.length() )
+ {}
+
+ // assignment:
+
+#if gsl_HAVE( IS_DEFAULT )
+ gsl_constexpr14 basic_string_span & operator=( basic_string_span const & ) gsl_noexcept = default;
+
+ gsl_constexpr14 basic_string_span & operator=( basic_string_span && ) gsl_noexcept = default;
+#endif
+
+ // sub span:
+
+ /*gsl_api*/ // currently disabled due to an apparent NVCC bug
+ gsl_NODISCARD gsl_constexpr14 basic_string_span
+ first( index_type count ) const
+ {
+ return span_.first( count );
+ }
+
+ /*gsl_api*/ // currently disabled due to an apparent NVCC bug
+ gsl_NODISCARD gsl_constexpr14 basic_string_span
+ last( index_type count ) const
+ {
+ return span_.last( count );
+ }
+
+ /*gsl_api*/ // currently disabled due to an apparent NVCC bug
+ gsl_NODISCARD gsl_constexpr14 basic_string_span
+ subspan( index_type offset ) const
+ {
+ return span_.subspan( offset );
+ }
+
+ /*gsl_api*/ // currently disabled due to an apparent NVCC bug
+ gsl_NODISCARD gsl_constexpr14 basic_string_span
+ subspan( index_type offset, index_type count ) const
+ {
+ return span_.subspan( offset, count );
+ }
+
+ // observers:
+
+ gsl_NODISCARD gsl_api gsl_constexpr index_type
+ length() const gsl_noexcept
+ {
+ return span_.size();
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr index_type
+ size() const gsl_noexcept
+ {
+ return span_.size();
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr index_type
+ length_bytes() const gsl_noexcept
+ {
+ return span_.size_bytes();
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr index_type
+ size_bytes() const gsl_noexcept
+ {
+ return span_.size_bytes();
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr bool
+ empty() const gsl_noexcept
+ {
+ return size() == 0;
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 reference
+ operator[]( index_type idx ) const
+ {
+ return span_[idx];
+ }
+
+#if ! gsl_DEPRECATE_TO_LEVEL( 6 )
+ gsl_DEPRECATED_MSG("use subscript indexing instead")
+ gsl_api gsl_constexpr14 reference operator()( index_type idx ) const
+ {
+ return span_[idx];
+ }
+#endif // deprecate
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 reference
+ front() const
+ {
+ return span_.front();
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr14 reference
+ back() const
+ {
+ return span_.back();
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr pointer
+ data() const gsl_noexcept
+ {
+ return span_.data();
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr iterator
+ begin() const gsl_noexcept
+ {
+ return span_.begin();
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr iterator
+ end() const gsl_noexcept
+ {
+ return span_.end();
+ }
+
+ gsl_NODISCARD gsl_constexpr17 reverse_iterator
+ rbegin() const gsl_noexcept
+ {
+ return span_.rbegin();
+ }
+
+ gsl_NODISCARD gsl_constexpr17 reverse_iterator
+ rend() const gsl_noexcept
+ {
+ return span_.rend();
+ }
+
+ // const version not in p0123r2:
+
+ gsl_NODISCARD gsl_api gsl_constexpr const_iterator
+ cbegin() const gsl_noexcept
+ {
+ return span_.cbegin();
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr const_iterator
+ cend() const gsl_noexcept
+ {
+ return span_.cend();
+ }
+
+ gsl_NODISCARD gsl_constexpr17 const_reverse_iterator
+ crbegin() const gsl_noexcept
+ {
+ return span_.crbegin();
+ }
+
+ gsl_NODISCARD gsl_constexpr17 const_reverse_iterator
+ crend() const gsl_noexcept
+ {
+ return span_.crend();
+ }
+
+private:
+ gsl_api static gsl_constexpr14 span_type remove_z( pointer sz, std::size_t max )
+ {
+ return span_type( sz, detail::string_length( sz, max ) );
+ }
+
+#if gsl_HAVE( ARRAY )
+ template< size_t N >
+ gsl_NODISCARD static gsl_constexpr14 span_type
+ remove_z( std::array<typename std11::remove_const<element_type>::type, N> & arr )
+ {
+ return remove_z( gsl_ADDRESSOF( arr[0] ), narrow_cast< std::size_t >( N ) );
+ }
+
+ template< size_t N >
+ gsl_NODISCARD static gsl_constexpr14 span_type
+ remove_z( std::array<typename std11::remove_const<element_type>::type, N> const & arr )
+ {
+ return remove_z( gsl_ADDRESSOF( arr[0] ), narrow_cast< std::size_t >( N ) );
+ }
+#endif
+
+private:
+ span_type span_;
+};
+
+// basic_string_span comparison functions:
+
+#if gsl_CONFIG( ALLOWS_NONSTRICT_SPAN_COMPARISON )
+
+template< class T, class U >
+gsl_SUPPRESS_MSGSL_WARNING(stl.1)
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator==( basic_string_span<T> const & l, U const & u ) gsl_noexcept
+{
+ const basic_string_span< typename std11::add_const<T>::type > r( u );
+
+ return l.size() == r.size()
+ && std98::equal( l.begin(), l.end(), r.begin() );
+}
+
+template< class T, class U >
+gsl_SUPPRESS_MSGSL_WARNING(stl.1)
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator<( basic_string_span<T> const & l, U const & u ) gsl_noexcept
+{
+ const basic_string_span< typename std11::add_const<T>::type > r( u );
+
+ return std98::lexicographical_compare( l.begin(), l.end(), r.begin(), r.end() );
+}
+
+#if gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG )
+
+template< class T, class U
+ gsl_ENABLE_IF_(( !detail::is_basic_string_span<U>::value ))
+>
+gsl_SUPPRESS_MSGSL_WARNING(stl.1)
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator==( U const & u, basic_string_span<T> const & r ) gsl_noexcept
+{
+ const basic_string_span< typename std11::add_const<T>::type > l( u );
+
+ return l.size() == r.size()
+ && std98::equal( l.begin(), l.end(), r.begin() );
+}
+
+template< class T, class U
+ gsl_ENABLE_IF_(( !detail::is_basic_string_span<U>::value ))
+>
+gsl_SUPPRESS_MSGSL_WARNING(stl.1)
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator<( U const & u, basic_string_span<T> const & r ) gsl_noexcept
+{
+ const basic_string_span< typename std11::add_const<T>::type > l( u );
+
+ return std98::lexicographical_compare( l.begin(), l.end(), r.begin(), r.end() );
+}
+#endif
+
+#else //gsl_CONFIG( ALLOWS_NONSTRICT_SPAN_COMPARISON )
+
+template< class T >
+gsl_SUPPRESS_MSGSL_WARNING(stl.1)
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator==( basic_string_span<T> const & l, basic_string_span<T> const & r ) gsl_noexcept
+{
+ return l.size() == r.size()
+ && std98::equal( l.begin(), l.end(), r.begin() );
+}
+
+template< class T >
+gsl_SUPPRESS_MSGSL_WARNING(stl.1)
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator<( basic_string_span<T> const & l, basic_string_span<T> const & r ) gsl_noexcept
+{
+ return std98::lexicographical_compare( l.begin(), l.end(), r.begin(), r.end() );
+}
+
+#endif // gsl_CONFIG( ALLOWS_NONSTRICT_SPAN_COMPARISON )
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator!=( basic_string_span<T> const & l, U const & r ) gsl_noexcept
+{
+ return !( l == r );
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator<=( basic_string_span<T> const & l, U const & r ) gsl_noexcept
+{
+#if gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) || ! gsl_CONFIG( ALLOWS_NONSTRICT_SPAN_COMPARISON )
+ return !( r < l );
+#else
+ basic_string_span< typename std11::add_const<T>::type > rr( r );
+ return !( rr < l );
+#endif
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator>( basic_string_span<T> const & l, U const & r ) gsl_noexcept
+{
+#if gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) || ! gsl_CONFIG( ALLOWS_NONSTRICT_SPAN_COMPARISON )
+ return ( r < l );
+#else
+ basic_string_span< typename std11::add_const<T>::type > rr( r );
+ return ( rr < l );
+#endif
+}
+
+template< class T, class U >
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator>=( basic_string_span<T> const & l, U const & r ) gsl_noexcept
+{
+ return !( l < r );
+}
+
+#if gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG )
+
+template< class T, class U
+ gsl_ENABLE_IF_(( !detail::is_basic_string_span<U>::value ))
+>
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator!=( U const & l, basic_string_span<T> const & r ) gsl_noexcept
+{
+ return !( l == r );
+}
+
+template< class T, class U
+ gsl_ENABLE_IF_(( !detail::is_basic_string_span<U>::value ))
+>
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator<=( U const & l, basic_string_span<T> const & r ) gsl_noexcept
+{
+ return !( r < l );
+}
+
+template< class T, class U
+ gsl_ENABLE_IF_(( !detail::is_basic_string_span<U>::value ))
+>
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator>( U const & l, basic_string_span<T> const & r ) gsl_noexcept
+{
+ return ( r < l );
+}
+
+template< class T, class U
+ gsl_ENABLE_IF_(( !detail::is_basic_string_span<U>::value ))
+>
+gsl_NODISCARD inline gsl_constexpr14 bool
+operator>=( U const & l, basic_string_span<T> const & r ) gsl_noexcept
+{
+ return !( l < r );
+}
+
+#endif // gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG )
+
+// convert basic_string_span to byte span:
+
+template< class T >
+gsl_NODISCARD gsl_api inline span< const byte >
+as_bytes( basic_string_span<T> spn ) gsl_noexcept
+{
+ return span< const byte >( reinterpret_cast<const byte *>( spn.data() ), spn.size_bytes() ); // NOLINT
+}
+
+//
+// String types:
+//
+
+typedef char * zstring;
+typedef const char * czstring;
+
+#if gsl_HAVE( WCHAR )
+typedef wchar_t * wzstring;
+typedef const wchar_t * cwzstring;
+#endif
+
+typedef basic_string_span< char > string_span;
+typedef basic_string_span< char const > cstring_span;
+
+#if gsl_HAVE( WCHAR )
+typedef basic_string_span< wchar_t > wstring_span;
+typedef basic_string_span< wchar_t const > cwstring_span;
+#endif
+
+// to_string() allow (explicit) conversions from string_span to string
+
+#if 0
+
+template< class T >
+inline std::basic_string< typename std::remove_const<T>::type > to_string( basic_string_span<T> spn )
+{
+ std::string( spn.data(), spn.length() );
+}
+
+#else
+
+gsl_NODISCARD inline std::string
+to_string( string_span const & spn )
+{
+ return std::string( spn.data(), static_cast<std::size_t>( spn.length() ) );
+}
+
+gsl_NODISCARD inline std::string
+to_string( cstring_span const & spn )
+{
+ return std::string( spn.data(), static_cast<std::size_t>( spn.length() ) );
+}
+
+#if gsl_HAVE( WCHAR )
+
+gsl_NODISCARD inline std::wstring
+to_string( wstring_span const & spn )
+{
+ return std::wstring( spn.data(), static_cast<std::size_t>( spn.length() ) );
+}
+
+gsl_NODISCARD inline std::wstring
+to_string( cwstring_span const & spn )
+{
+ return std::wstring( spn.data(), static_cast<std::size_t>( spn.length() ) );
+}
+
+#endif // gsl_HAVE( WCHAR )
+#endif // to_string()
+
+//
+// Stream output for string_span types
+//
+
+namespace detail {
+
+template< class Stream >
+void write_padding( Stream & os, std::streamsize n )
+{
+ for ( std::streamsize i = 0; i < n; ++i )
+ os.rdbuf()->sputc( os.fill() );
+}
+
+template< class Stream, class Span >
+Stream & write_to_stream( Stream & os, Span const & spn )
+{
+ typename Stream::sentry sentry( os );
+
+ if ( !os )
+ return os;
+
+ const std::streamsize length = gsl::narrow_failfast<std::streamsize>( spn.length() );
+
+ // Whether, and how, to pad
+ const bool pad = ( length < os.width() );
+ const bool left_pad = pad && ( os.flags() & std::ios_base::adjustfield ) == std::ios_base::right;
+
+ if ( left_pad )
+ detail::write_padding( os, os.width() - length );
+
+ // Write span characters
+ os.rdbuf()->sputn( spn.begin(), length );
+
+ if ( pad && !left_pad )
+ detail::write_padding( os, os.width() - length );
+
+ // Reset output stream width
+ os.width(0);
+
+ return os;
+}
+
+} // namespace detail
+
+template< typename Traits >
+std::basic_ostream< char, Traits > & operator<<( std::basic_ostream< char, Traits > & os, string_span const & spn )
+{
+ return detail::write_to_stream( os, spn );
+}
+
+template< typename Traits >
+std::basic_ostream< char, Traits > & operator<<( std::basic_ostream< char, Traits > & os, cstring_span const & spn )
+{
+ return detail::write_to_stream( os, spn );
+}
+
+#if gsl_HAVE( WCHAR )
+
+template< typename Traits >
+std::basic_ostream< wchar_t, Traits > & operator<<( std::basic_ostream< wchar_t, Traits > & os, wstring_span const & spn )
+{
+ return detail::write_to_stream( os, spn );
+}
+
+template< typename Traits >
+std::basic_ostream< wchar_t, Traits > & operator<<( std::basic_ostream< wchar_t, Traits > & os, cwstring_span const & spn )
+{
+ return detail::write_to_stream( os, spn );
+}
+
+#endif // gsl_HAVE( WCHAR )
+
+//
+// ensure_sentinel()
+//
+// Provides a way to obtain a span from a contiguous sequence
+// that ends with a (non-inclusive) sentinel value.
+//
+// Will fail-fast if sentinel cannot be found before max elements are examined.
+//
+namespace detail {
+
+template< class T, class SizeType, const T Sentinel >
+gsl_constexpr14 static span<T> ensure_sentinel( T * seq, SizeType max = (std::numeric_limits<SizeType>::max)() )
+{
+ typedef T * pointer;
+
+ gsl_SUPPRESS_MSVC_WARNING( 26429, "f.23: symbol 'cur' is never tested for nullness, it can be marked as not_null" )
+ pointer cur = seq;
+
+ while ( static_cast<SizeType>( cur - seq ) < max && *cur != Sentinel )
+ ++cur;
+
+ gsl_Expects( *cur == Sentinel );
+
+ return span<T>( seq, gsl::narrow_cast< typename span<T>::index_type >( cur - seq ) );
+}
+} // namespace detail
+
+//
+// ensure_z - creates a string_span for a czstring or cwzstring.
+// Will fail fast if a null-terminator cannot be found before
+// the limit of size_type.
+//
+
+template< class T >
+gsl_NODISCARD inline gsl_constexpr14 span<T>
+ensure_z( T * const & sz, size_t max = (std::numeric_limits<size_t>::max)() )
+{
+ return detail::ensure_sentinel<T, size_t, 0>( sz, max );
+}
+
+template< class T, size_t N >
+gsl_NODISCARD inline gsl_constexpr14 span<T>
+ensure_z( T (&sz)[N] )
+{
+ return ::gsl::ensure_z( gsl_ADDRESSOF( sz[0] ), N );
+}
+
+# if gsl_HAVE( TYPE_TRAITS )
+
+template< class Container >
+gsl_NODISCARD inline gsl_constexpr14 span< typename std::remove_pointer<typename Container::pointer>::type >
+ensure_z( Container & cont )
+{
+ return ::gsl::ensure_z( cont.data(), cont.length() );
+}
+# endif
+
+//
+// basic_zstring_span<> - A view of contiguous null-terminated characters, replace (*,len).
+//
+
+template <typename T>
+class basic_zstring_span
+{
+public:
+ typedef T element_type;
+ typedef span<T> span_type;
+
+ typedef typename span_type::index_type index_type;
+ typedef typename span_type::difference_type difference_type;
+
+ typedef element_type * czstring_type;
+ typedef basic_string_span<element_type> string_span_type;
+
+ gsl_api gsl_constexpr14 basic_zstring_span( span_type s )
+ : span_( s )
+ {
+ // expects a zero-terminated span
+ gsl_Expects( s.back() == '\0' );
+ }
+
+#if gsl_HAVE( IS_DEFAULT )
+ gsl_constexpr basic_zstring_span( basic_zstring_span const & ) = default;
+ gsl_constexpr basic_zstring_span( basic_zstring_span && ) = default;
+ gsl_constexpr14 basic_zstring_span & operator=( basic_zstring_span const & ) = default;
+ gsl_constexpr14 basic_zstring_span & operator=( basic_zstring_span && ) = default;
+#else
+ gsl_api gsl_constexpr basic_zstring_span( basic_zstring_span const & other) : span_ ( other.span_ ) {}
+ gsl_api gsl_constexpr basic_zstring_span & operator=( basic_zstring_span const & other ) { span_ = other.span_; return *this; }
+#endif
+
+ gsl_NODISCARD gsl_api gsl_constexpr bool
+ empty() const gsl_noexcept
+ {
+ return false;
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr string_span_type
+ as_string_span() const gsl_noexcept
+ {
+ return string_span_type( span_.data(), span_.size() - 1 );
+ }
+
+ /*gsl_api*/ // currently disabled due to an apparent NVCC bug
+ gsl_NODISCARD gsl_constexpr string_span_type
+ ensure_z() const
+ {
+ return ::gsl::ensure_z(span_.data(), span_.size());
+ }
+
+ gsl_NODISCARD gsl_api gsl_constexpr czstring_type
+ assume_z() const gsl_noexcept
+ {
+ return span_.data();
+ }
+
+private:
+ span_type span_;
+};
+
+//
+// zString types:
+//
+
+typedef basic_zstring_span< char > zstring_span;
+typedef basic_zstring_span< char const > czstring_span;
+
+#if gsl_HAVE( WCHAR )
+typedef basic_zstring_span< wchar_t > wzstring_span;
+typedef basic_zstring_span< wchar_t const > cwzstring_span;
+#endif
+
+} // namespace gsl
+
+#if gsl_HAVE( HASH )
+
+//
+// std::hash specializations for GSL types
+//
+
+namespace gsl {
+
+namespace detail {
+
+//
+// Helper struct for std::hash specializations
+//
+
+template<bool Condition>
+struct conditionally_enabled_hash
+{
+
+};
+
+// disabled as described in [unord.hash]
+template<>
+struct conditionally_enabled_hash< false >
+{
+gsl_is_delete_access:
+ conditionally_enabled_hash() gsl_is_delete;
+ conditionally_enabled_hash( conditionally_enabled_hash const & ) gsl_is_delete;
+ conditionally_enabled_hash( conditionally_enabled_hash && ) gsl_is_delete;
+ conditionally_enabled_hash & operator=( conditionally_enabled_hash const & ) gsl_is_delete;
+ conditionally_enabled_hash & operator=( conditionally_enabled_hash && ) gsl_is_delete;
+};
+
+} // namespace detail
+
+} // namespace gsl
+
+namespace std {
+
+template< class T >
+struct hash< ::gsl::not_null< T > > : public ::gsl::detail::conditionally_enabled_hash<is_default_constructible<hash<T>>::value>
+{
+public:
+ gsl_NODISCARD gsl_constexpr std::size_t
+ operator()( ::gsl::not_null<T> const & v ) const
+ // hash function is not `noexcept` because `as_nullable()` has preconditions
+ {
+ return hash<T>()( ::gsl::as_nullable( v ) );
+ }
+};
+template< class T >
+struct hash< ::gsl::not_null< T* > >
+{
+public:
+ gsl_NODISCARD gsl_constexpr std::size_t
+ operator()( ::gsl::not_null< T* > const & v ) const gsl_noexcept
+ {
+ return hash<T*>()( ::gsl::as_nullable( v ) );
+ }
+};
+
+template<>
+struct hash< ::gsl::byte >
+{
+public:
+ gsl_NODISCARD gsl_constexpr std::size_t operator()( ::gsl::byte v ) const gsl_noexcept
+ {
+ return ::gsl::to_integer<std::size_t>( v );
+ }
+};
+
+} // namespace std
+
+#endif // gsl_HAVE( HASH )
+
+#if gsl_FEATURE( GSL_LITE_NAMESPACE )
+
+// gsl_lite namespace:
+
+// gsl-lite currently keeps all symbols in the namespace `gsl`. The `gsl_lite` namespace contains all the symbols in the
+// `gsl` namespace, plus some extensions that are not specified in the Core Guidelines.
+//
+// Going forward, we want to support coexistence of gsl-lite with M-GSL, so we want to encourage using the `gsl_lite`
+// namespace when consuming gsl-lite. Typical use in library code would be:
+//
+// #include <gsl-lite/gsl-lite.hpp> // instead of <gsl/gsl-lite.hpp>
+//
+// namespace foo {
+// namespace gsl = ::gsl_lite; // convenience alias
+// double mean( gsl::span<double const> elements )
+// {
+// gsl_Expects( ! elements.empty() ); // instead of Expects()
+// ...
+// }
+// } // namespace foo
+//
+// In a future version, the new <gsl-lite/gsl-lite.hpp> header will only define the `gsl_lite` namespace and no
+// unprefixed `Expects()` and `Ensures()` macros to avoid collision with M-GSL. To ensure backward compatibility, the
+// old header <gsl/gsl-lite.hpp> will keep defining the `gsl` namespace and the `Expects()` and `Ensures()` macros.
+
+namespace gsl_lite {
+
+namespace std11 = ::gsl::std11;
+namespace std14 = ::gsl::std14;
+namespace std17 = ::gsl::std17;
+namespace std20 = ::gsl::std20;
+
+using namespace std11;
+using namespace std14;
+using namespace std17;
+using namespace std20;
+
+using namespace ::gsl::detail::no_adl;
+
+# if gsl_HAVE( SHARED_PTR )
+using std::unique_ptr;
+using std::shared_ptr;
+using std::make_shared;
+# endif
+
+using ::gsl::index;
+using ::gsl::dim;
+using ::gsl::stride;
+using ::gsl::diff;
+
+# if gsl_HAVE( ALIAS_TEMPLATE )
+# if gsl_BETWEEN( gsl_COMPILER_MSVC_VERSION, 1, 141 ) // VS 2015 and earlier have trouble with `using` for alias templates
+ template< class T
+# if gsl_HAVE( TYPE_TRAITS )
+ , typename = typename std::enable_if< std::is_pointer<T>::value >::type
+# endif
+ >
+ using owner = T;
+# else
+using ::gsl::owner;
+# endif
+# endif
+
+using ::gsl::fail_fast;
+
+using ::gsl::finally;
+# if gsl_FEATURE( EXPERIMENTAL_RETURN_GUARD )
+using ::gsl::on_return;
+using ::gsl::on_error;
+# endif // gsl_FEATURE( EXPERIMENTAL_RETURN_GUARD )
+
+using ::gsl::narrow_cast;
+using ::gsl::narrowing_error;
+using ::gsl::narrow;
+using ::gsl::narrow_failfast;
+
+using ::gsl::at;
+
+using ::gsl::not_null;
+using ::gsl::not_null_ic;
+using ::gsl::make_not_null;
+
+using ::gsl::byte;
+
+using ::gsl::to_byte;
+using ::gsl::to_integer;
+using ::gsl::to_uchar;
+using ::gsl::to_string;
+
+using ::gsl::with_container_t;
+using ::gsl::with_container;
+
+using ::gsl::span;
+using ::gsl::make_span;
+using ::gsl::byte_span;
+using ::gsl::copy;
+using ::gsl::as_bytes;
+using ::gsl::as_writable_bytes;
+# if ! gsl_DEPRECATE_TO_LEVEL( 6 )
+using ::gsl::as_writeable_bytes;
+# endif
+
+using ::gsl::basic_string_span;
+using ::gsl::string_span;
+using ::gsl::cstring_span;
+
+using ::gsl::basic_zstring_span;
+using ::gsl::zstring_span;
+using ::gsl::czstring_span;
+
+using ::gsl::zstring;
+using ::gsl::czstring;
+
+# if gsl_HAVE( WCHAR )
+using ::gsl::wzstring;
+using ::gsl::cwzstring;
+
+using ::gsl::wzstring_span;
+using ::gsl::cwzstring_span;
+# endif // gsl_HAVE( WCHAR )
+
+using ::gsl::ensure_z;
+
+} // namespace gsl_lite
+
+#endif // gsl_FEATURE( GSL_LITE_NAMESPACE )
+
+gsl_RESTORE_MSVC_WARNINGS()
+
+// #undef internal macros
+#undef gsl_STATIC_ASSERT_
+#undef gsl_ENABLE_IF_
+#undef gsl_TRAILING_RETURN_TYPE_
+#undef gsl_RETURN_DECLTYPE_
+
+#endif // GSL_GSL_LITE_HPP_INCLUDED
+
+// end of file
diff --git a/third_party/hdf5/hdf5_plugin_types.h b/third_party/hdf5/hdf5_plugin_types.h
new file mode 100644
index 0000000..b0f7d06
--- /dev/null
+++ b/third_party/hdf5/hdf5_plugin_types.h
@@ -0,0 +1,82 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Purpose: Header file for writing external HDF5 plugins.
+ */
+
+#ifndef _H5PLextern_H
+#define _H5PLextern_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum H5PL_type_t {
+ H5PL_TYPE_ERROR = -1, /* Error */
+ H5PL_TYPE_FILTER = 0, /* Filter */
+ H5PL_TYPE_NONE = 1 /* This must be last! */
+} H5PL_type_t;
+
+
+#define H5Z_CLASS_T_VERS (1)
+#define H5Z_FLAG_REVERSE 0x0100 /*reverse direction; read */
+
+/*
+ * Filter identifiers. Values 0 through 255 are for filters defined by the
+ * HDF5 library. Values 256 through 511 are available for testing new
+ * filters. Subsequent values should be obtained from the HDF5 development
+ * team at hdf5dev@ncsa.uiuc.edu. These values will never change because they
+ * appear in the HDF5 files.
+ */
+typedef int H5Z_filter_t;
+
+/*
+ * A filter gets definition flags and invocation flags (defined above), the
+ * client data array and size defined when the filter was added to the
+ * pipeline, the size in bytes of the data on which to operate, and pointers
+ * to a buffer and its allocated size.
+ *
+ * The filter should store the result in the supplied buffer if possible,
+ * otherwise it can allocate a new buffer, freeing the original. The
+ * allocated size of the new buffer should be returned through the BUF_SIZE
+ * pointer and the new buffer through the BUF pointer.
+ *
+ * The return value from the filter is the number of bytes in the output
+ * buffer. If an error occurs then the function should return zero and leave
+ * all pointer arguments unchanged.
+ */
+typedef size_t (*H5Z_func_t)(unsigned int flags, size_t cd_nelmts,
+ const unsigned int cd_values[], size_t nbytes,
+ size_t *buf_size, void **buf);
+
+/*
+ * The filter table maps filter identification numbers to structs that
+ * contain a pointers to the filter function and timing statistics.
+ */
+typedef struct H5Z_class2_t {
+ int version; /* Version number of the H5Z_class_t struct */
+ H5Z_filter_t id; /* Filter ID number */
+ unsigned encoder_present; /* Does this filter have an encoder? */
+ unsigned decoder_present; /* Does this filter have a decoder? */
+ const char *name; /* Comment for debugging */
+ void* can_apply; /* The "can apply" callback for a filter */
+ void* set_local; /* The "set local" callback for a filter */
+ H5Z_func_t filter; /* The actual filter function */
+} H5Z_class2_t;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _H5PLextern_H */
+
diff --git a/vbz/CMakeLists.txt b/vbz/CMakeLists.txt
new file mode 100644
index 0000000..964b765
--- /dev/null
+++ b/vbz/CMakeLists.txt
@@ -0,0 +1,55 @@
+
+add_library(vbz STATIC
+ v0/vbz_streamvbyte.h
+ v0/vbz_streamvbyte.cpp
+ v0/vbz_streamvbyte_impl.h
+ v0/vbz_streamvbyte_impl_sse3.h
+
+ v1/vbz_streamvbyte.h
+ v1/vbz_streamvbyte.cpp
+ v0/vbz_streamvbyte_impl.h
+
+ vbz.h
+ vbz.cpp
+)
+add_sanitizers(vbz)
+
+generate_export_header(vbz EXPORT_FILE_NAME vbz/vbz_export.h)
+
+set_property(TARGET vbz PROPERTY CXX_STANDARD 11)
+
+target_include_directories(vbz
+ PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${STREAMVBYTE_INSTALL_DIR}/include
+)
+
+# This explicit dependency is required to make sure the header files are installed into the right
+# location before we try building against them.
+add_dependencies(vbz
+ streamvbyte
+)
+
+if (WIN32 OR
+ (APPLE AND NOT "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm64") OR
+ "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64")
+ if(NOT MSVC)
+ target_compile_options(vbz PRIVATE -mssse3)
+ endif()
+endif()
+
+target_link_libraries(vbz
+ PUBLIC
+ ${STREAMVBYTE_STATIC_LIB}
+ zstd::zstd
+)
+
+if (BUILD_TESTING)
+ add_subdirectory(fuzzing)
+ add_subdirectory(test)
+
+ if (ENABLE_PERF_TESTING)
+ add_subdirectory(perf)
+ endif()
+endif()
diff --git a/vbz/fuzzing/CMakeLists.txt b/vbz/fuzzing/CMakeLists.txt
new file mode 100644
index 0000000..5ba040e
--- /dev/null
+++ b/vbz/fuzzing/CMakeLists.txt
@@ -0,0 +1,15 @@
+
+if (SANITIZE_FUZZER)
+ message(STATUS "Building vbz fuzz support")
+
+ add_executable(vbz_fuzz_test
+ vbz_fuzz.cpp
+ )
+
+ target_link_libraries(vbz_fuzz_test
+ PUBLIC
+ vbz)
+
+ add_sanitize_fuzzer(vbz_fuzz_test)
+ add_sanitizers(vbz_fuzz_test)
+endif() \ No newline at end of file
diff --git a/vbz/fuzzing/dictionary.txt b/vbz/fuzzing/dictionary.txt
new file mode 100644
index 0000000..f747b58
--- /dev/null
+++ b/vbz/fuzzing/dictionary.txt
@@ -0,0 +1,6 @@
+
+# Uses: 185923
+kw1="\xd1\x18\x00\x00"
+
+# Uses: 43711
+kw2="\xff\xff\xffX" \ No newline at end of file
diff --git a/vbz/fuzzing/fuzz_corpus/11373950051f7b0300995eccc2291ad06127cd8f b/vbz/fuzzing/fuzz_corpus/11373950051f7b0300995eccc2291ad06127cd8f
new file mode 100644
index 0000000..7818f9c
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/11373950051f7b0300995eccc2291ad06127cd8f
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/1bc554b64fa5315576f70da39b286cc131537ae2 b/vbz/fuzzing/fuzz_corpus/1bc554b64fa5315576f70da39b286cc131537ae2
new file mode 100644
index 0000000..e52d8e6
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/1bc554b64fa5315576f70da39b286cc131537ae2
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/24f78257221ba37aecd033a81647bc69946b5735 b/vbz/fuzzing/fuzz_corpus/24f78257221ba37aecd033a81647bc69946b5735
new file mode 100644
index 0000000..c208827
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/24f78257221ba37aecd033a81647bc69946b5735
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/251aa7eb7d9fe0bd76730c2a2853bd3d265604ea b/vbz/fuzzing/fuzz_corpus/251aa7eb7d9fe0bd76730c2a2853bd3d265604ea
new file mode 100644
index 0000000..226017b
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/251aa7eb7d9fe0bd76730c2a2853bd3d265604ea
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/29a99aa69faab4036a099ff9d7926324ecaa614a b/vbz/fuzzing/fuzz_corpus/29a99aa69faab4036a099ff9d7926324ecaa614a
new file mode 100644
index 0000000..4f4e997
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/29a99aa69faab4036a099ff9d7926324ecaa614a
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/41b10ad89a5538e3200320ef927cf2005af86143 b/vbz/fuzzing/fuzz_corpus/41b10ad89a5538e3200320ef927cf2005af86143
new file mode 100644
index 0000000..8b0086c
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/41b10ad89a5538e3200320ef927cf2005af86143
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/5ba93c9db0cff93f52b521d7420e43f6eda2784f b/vbz/fuzzing/fuzz_corpus/5ba93c9db0cff93f52b521d7420e43f6eda2784f
new file mode 100644
index 0000000..f76dd23
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/5ba93c9db0cff93f52b521d7420e43f6eda2784f
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/5fb98815de681bcc796f65f90e44c2836e24449f b/vbz/fuzzing/fuzz_corpus/5fb98815de681bcc796f65f90e44c2836e24449f
new file mode 100644
index 0000000..1f0614c
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/5fb98815de681bcc796f65f90e44c2836e24449f
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/61cd6ffc64ca7a0b6b1a726f394ef2c51000862a b/vbz/fuzzing/fuzz_corpus/61cd6ffc64ca7a0b6b1a726f394ef2c51000862a
new file mode 100644
index 0000000..2663868
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/61cd6ffc64ca7a0b6b1a726f394ef2c51000862a
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/657c3ab45863ec8d403c7c6959bf142acdbf7094 b/vbz/fuzzing/fuzz_corpus/657c3ab45863ec8d403c7c6959bf142acdbf7094
new file mode 100644
index 0000000..f3c50dd
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/657c3ab45863ec8d403c7c6959bf142acdbf7094
@@ -0,0 +1 @@
+)ø \ No newline at end of file
diff --git a/vbz/fuzzing/fuzz_corpus/7722745105e9e02e8f1aaf17f7b3aac5c56cd805 b/vbz/fuzzing/fuzz_corpus/7722745105e9e02e8f1aaf17f7b3aac5c56cd805
new file mode 100644
index 0000000..ab2c684
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/7722745105e9e02e8f1aaf17f7b3aac5c56cd805
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/80f5e802a77d76c6decedf63ae4a3dbaeb2ec8c3 b/vbz/fuzzing/fuzz_corpus/80f5e802a77d76c6decedf63ae4a3dbaeb2ec8c3
new file mode 100644
index 0000000..7c25ffe
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/80f5e802a77d76c6decedf63ae4a3dbaeb2ec8c3
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/846.bin b/vbz/fuzzing/fuzz_corpus/846.bin
new file mode 100644
index 0000000..dce7f2a
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/846.bin
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/8ed79960613916571ccfb082453d93037e7906b7 b/vbz/fuzzing/fuzz_corpus/8ed79960613916571ccfb082453d93037e7906b7
new file mode 100644
index 0000000..1be26a5
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/8ed79960613916571ccfb082453d93037e7906b7
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/9069ca78e7450a285173431b3e52c5c25299e473 b/vbz/fuzzing/fuzz_corpus/9069ca78e7450a285173431b3e52c5c25299e473
new file mode 100644
index 0000000..593f470
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/9069ca78e7450a285173431b3e52c5c25299e473
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/92d337489cc9f8e42313a745cbe190aa6c634693 b/vbz/fuzzing/fuzz_corpus/92d337489cc9f8e42313a745cbe190aa6c634693
new file mode 100644
index 0000000..60f1c9a
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/92d337489cc9f8e42313a745cbe190aa6c634693
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/9322befa32a921e42b72ce55c13451c04a356063 b/vbz/fuzzing/fuzz_corpus/9322befa32a921e42b72ce55c13451c04a356063
new file mode 100644
index 0000000..9588b78
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/9322befa32a921e42b72ce55c13451c04a356063
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/9b20c06ca1ad1d294400baa692fc97baeb4c9fca b/vbz/fuzzing/fuzz_corpus/9b20c06ca1ad1d294400baa692fc97baeb4c9fca
new file mode 100644
index 0000000..9d36013
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/9b20c06ca1ad1d294400baa692fc97baeb4c9fca
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/9c119958afbf93c6a952d2df3302a088f38244eb b/vbz/fuzzing/fuzz_corpus/9c119958afbf93c6a952d2df3302a088f38244eb
new file mode 100644
index 0000000..2587236
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/9c119958afbf93c6a952d2df3302a088f38244eb
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/a02a121e5b3350a7f8e9d1d7dbd367fab677c2aa b/vbz/fuzzing/fuzz_corpus/a02a121e5b3350a7f8e9d1d7dbd367fab677c2aa
new file mode 100644
index 0000000..35399c1
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/a02a121e5b3350a7f8e9d1d7dbd367fab677c2aa
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/c830b27f7a230e60f597313c46fed441e64c0373 b/vbz/fuzzing/fuzz_corpus/c830b27f7a230e60f597313c46fed441e64c0373
new file mode 100644
index 0000000..45d6ee4
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/c830b27f7a230e60f597313c46fed441e64c0373
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/cadf1d00e18837d36406165040faaac6b3ca13c4 b/vbz/fuzzing/fuzz_corpus/cadf1d00e18837d36406165040faaac6b3ca13c4
new file mode 100644
index 0000000..6da0b8a
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/cadf1d00e18837d36406165040faaac6b3ca13c4
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/cc5c77470e5a742320cce568cf9425c51815be8e b/vbz/fuzzing/fuzz_corpus/cc5c77470e5a742320cce568cf9425c51815be8e
new file mode 100644
index 0000000..7fb1067
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/cc5c77470e5a742320cce568cf9425c51815be8e
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/d26f4347af1e7892439ae8f1d0e5751706665d9b b/vbz/fuzzing/fuzz_corpus/d26f4347af1e7892439ae8f1d0e5751706665d9b
new file mode 100644
index 0000000..ce1c6f5
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/d26f4347af1e7892439ae8f1d0e5751706665d9b
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/dd426047b595164d7b461446228c6c0818e28297 b/vbz/fuzzing/fuzz_corpus/dd426047b595164d7b461446228c6c0818e28297
new file mode 100644
index 0000000..5fc7f59
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/dd426047b595164d7b461446228c6c0818e28297
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/e116607af449e9e9227cd27d65ce77c7639f718c b/vbz/fuzzing/fuzz_corpus/e116607af449e9e9227cd27d65ce77c7639f718c
new file mode 100644
index 0000000..2947589
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/e116607af449e9e9227cd27d65ce77c7639f718c
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/e70047cba798d17689d2ebc7e32ca793523c205f b/vbz/fuzzing/fuzz_corpus/e70047cba798d17689d2ebc7e32ca793523c205f
new file mode 100644
index 0000000..51e4ad7
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/e70047cba798d17689d2ebc7e32ca793523c205f
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/ed6e9aa0874d548f1935b94f27402b553fabc404 b/vbz/fuzzing/fuzz_corpus/ed6e9aa0874d548f1935b94f27402b553fabc404
new file mode 100644
index 0000000..857949a
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/ed6e9aa0874d548f1935b94f27402b553fabc404
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/ee987cb071dba7583bedc1fc3b3a75af9901a1c0 b/vbz/fuzzing/fuzz_corpus/ee987cb071dba7583bedc1fc3b3a75af9901a1c0
new file mode 100644
index 0000000..e5bbe3f
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/ee987cb071dba7583bedc1fc3b3a75af9901a1c0
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/f1a284806d5914ca836ae6f381d66e7331e01aa2 b/vbz/fuzzing/fuzz_corpus/f1a284806d5914ca836ae6f381d66e7331e01aa2
new file mode 100644
index 0000000..baaf421
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/f1a284806d5914ca836ae6f381d66e7331e01aa2
Binary files differ
diff --git a/vbz/fuzzing/fuzz_corpus/ff8cf611318fced9fa50c27e28e18533f4b5544e b/vbz/fuzzing/fuzz_corpus/ff8cf611318fced9fa50c27e28e18533f4b5544e
new file mode 100644
index 0000000..7b3808e
--- /dev/null
+++ b/vbz/fuzzing/fuzz_corpus/ff8cf611318fced9fa50c27e28e18533f4b5544e
Binary files differ
diff --git a/vbz/fuzzing/vbz_fuzz.cpp b/vbz/fuzzing/vbz_fuzz.cpp
new file mode 100644
index 0000000..cbada05
--- /dev/null
+++ b/vbz/fuzzing/vbz_fuzz.cpp
@@ -0,0 +1,108 @@
+#include <vbz.h>
+
+#include <cstddef>
+#include <cstdint>
+#include <fstream>
+#include <iostream>
+#include <utility>
+#include <vector>
+
+#define DEBUG_LOGGING 0
+
+template <typename... Args>
+void debug_log(Args&&... args)
+{
+#if DEBUG_LOGGING
+ using expander = int[];
+ (void)expander{0, (void(std::cout << std::forward<Args>(args)), 0)...};
+ std::cout << std::endl;
+#endif
+}
+
+void run_vbz_test(const uint8_t* data, size_t size, CompressionOptions const& options)
+{
+ // Try to compress random input data
+ {
+ auto max_size = vbz_max_compressed_size((vbz_size_t)size, &options);
+ if (vbz_is_error(max_size))
+ {
+ debug_log("compress: Error in size ", vbz_error_string(max_size));
+ max_size = size * 100; // make up a max value...
+ }
+
+ auto compressed = std::vector<char>(max_size);
+ // run both sized and non-sized methods.
+ auto compressed_size = vbz_compress_sized(data, size, compressed.data(), max_size, &options);
+ if (vbz_is_error(compressed_size))
+ {
+ debug_log("compress_sized: Error in compressed_size", vbz_error_string(compressed_size));
+ }
+ else
+ {
+ debug_log("compress_sized: Compressed to ", compressed_size, " bytes");
+ compressed.resize(compressed_size);
+ }
+
+ compressed_size = vbz_compress(data, size, compressed.data(), max_size, &options);
+ if (vbz_is_error(compressed_size))
+ {
+ debug_log("compress: Error in compressed_size", vbz_error_string(compressed_size));
+ }
+ else
+ {
+ debug_log("compress: Compressed to ", compressed_size, " bytes");
+ compressed.resize(compressed_size);
+ }
+
+ auto decompressed = std::vector<char>(size);
+ auto decompressed_size = vbz_decompress(compressed.data(), compressed.size(), decompressed.data(), size, &options);
+ if (vbz_is_error(decompressed_size))
+ {
+ debug_log("compress_sized: Error in decompressed_size ", vbz_error_string(decompressed_size));
+ }
+ else
+ {
+ debug_log("compress_sized: Decompressed to ", decompressed_size, " bytes");
+ }
+
+ decompressed_size = vbz_decompress_sized(compressed.data(), compressed.size(), decompressed.data(), size, &options);
+ if (vbz_is_error(decompressed_size))
+ {
+ debug_log("compress: Error in decompressed_size ", vbz_error_string(decompressed_size));
+ }
+ else
+ {
+ debug_log("compress: Decompressed to ", decompressed_size, " bytes");
+ }
+ }
+
+ // Try to decompress random input data...
+ {
+ auto const guess_destination_size = std::max(std::size_t(1024), size * 100);
+ auto decompress_dest = std::vector<char>(guess_destination_size);
+ // try both sized and non-sized methods.
+ auto decompressed_size = vbz_decompress(data, size, decompress_dest.data(), guess_destination_size, &options);
+ if (vbz_is_error(decompressed_size))
+ {
+ debug_log("decompress_sized: Error in decompressed_size ", vbz_error_string(decompressed_size));
+ }
+ decompressed_size = vbz_decompress_sized(data, size, decompress_dest.data(), guess_destination_size, &options);
+ if (vbz_is_error(decompressed_size))
+ {
+ debug_log("decompress: Error in decompressed_size ", vbz_error_string(decompressed_size));
+ }
+ }
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ debug_log("Begin with ", size, " bytes");
+
+ // Run with zstd
+ run_vbz_test(data, size, CompressionOptions{ true, 2, 1, VBZ_DEFAULT_VERSION });
+
+ // Run without zstd
+ run_vbz_test(data, size, CompressionOptions{ true, 2, 0, VBZ_DEFAULT_VERSION });
+
+ return 0;
+} \ No newline at end of file
diff --git a/vbz/perf/CMakeLists.txt b/vbz/perf/CMakeLists.txt
new file mode 100644
index 0000000..49c9889
--- /dev/null
+++ b/vbz/perf/CMakeLists.txt
@@ -0,0 +1,20 @@
+find_package(GoogleBenchmark)
+
+add_executable(vbz_perf_test
+ vbz_perf.cpp
+)
+add_sanitizers(vbz_perf_test)
+
+target_link_libraries(vbz_perf_test
+ PRIVATE
+ vbz
+ google::benchmark
+)
+
+set_property(TARGET vbz_perf_test PROPERTY CXX_STANDARD 11)
+
+add_test(
+ NAME vbz_perf_test
+ COMMAND vbz_perf_test
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+) \ No newline at end of file
diff --git a/vbz/perf/test_data_generator.h b/vbz/perf/test_data_generator.h
new file mode 100644
index 0000000..1bb593b
--- /dev/null
+++ b/vbz/perf/test_data_generator.h
@@ -0,0 +1,75 @@
+#pragma once
+
+#include "../test/test_data.h"
+
+#include <gsl/gsl-lite.hpp>
+
+#include <numeric>
+#include <random>
+
+// Generator that targets a consistent number of bytes of increasing sequence.
+template <typename T> struct SequenceGenerator
+{
+ static const std::size_t byte_target = 1000 * 1000; // 1mb
+
+ static std::vector<std::vector<T>> generate(std::size_t& max_element_count)
+ {
+ std::vector<T> input_values(byte_target / sizeof(T));
+ max_element_count = input_values.size();
+ std::iota(input_values.begin(), input_values.end(), 0);
+
+ return { input_values };
+ }
+};
+
+// Generator that targets a random set of reads of random lengths.
+//
+// Under a maximum target byte count.
+template <typename T>
+struct SignalGenerator
+{
+ static const std::size_t byte_target = 100 * 1000 * 1000; // 100 mb
+
+ static std::vector<std::vector<T>> generate(std::size_t& max_element_count)
+ {
+ auto const seed = 5;
+
+ static std::size_t max_element_count_static;
+ static auto const generated_reads = do_generation(seed, max_element_count_static);
+
+ max_element_count = max_element_count_static;
+ return generated_reads;
+ }
+
+private:
+ static std::vector<std::vector<T>> do_generation(unsigned int seed, std::size_t& max_element_count)
+ {
+ std::random_device rd;
+ std::default_random_engine rand(seed);
+ std::uniform_int_distribution<std::uint32_t> length_dist(30000, 200000);
+
+ std::size_t generated_bytes = 0;
+ std::vector<std::vector<T>> results;
+ while (generated_bytes < byte_target)
+ {
+ auto length = std::min<std::size_t>((byte_target-generated_bytes)/sizeof(T), length_dist(rand));
+ generated_bytes += length * sizeof(T);
+
+ std::vector<T> input_values(length);
+ max_element_count = std::max(max_element_count, input_values.size());
+
+
+ std::size_t idx = 0;
+ for (auto& e : input_values)
+ {
+ auto input_data = test_data[idx];
+ e = (T)input_data;
+ idx = (idx + 1) % test_data.size();
+ }
+
+ results.push_back(input_values);
+ }
+
+ return results;
+ }
+};
diff --git a/vbz/perf/vbz_perf.cpp b/vbz/perf/vbz_perf.cpp
new file mode 100644
index 0000000..3fb7e9c
--- /dev/null
+++ b/vbz/perf/vbz_perf.cpp
@@ -0,0 +1,175 @@
+#include "vbz.h"
+#include "test_data_generator.h"
+
+#include <benchmark/benchmark.h>
+
+template <typename VbzOptions, typename Generator>
+void streamvbyte_compress_benchmark(benchmark::State& state)
+{
+ std::size_t max_element_count = 0;
+ auto input_value_list = Generator::generate(max_element_count);
+
+ auto const int_size = sizeof(typename VbzOptions::IntType);
+
+ CompressionOptions options{
+ VbzOptions::UseZigZag,
+ int_size,
+ VbzOptions::ZstdLevel,
+ VBZ_DEFAULT_VERSION
+ };
+
+ std::vector<char> dest_buffer(vbz_max_compressed_size(vbz_size_t(max_element_count * int_size), &options));
+
+ std::size_t item_count = 0;
+ for (auto _ : state)
+ {
+ item_count = 0;
+ for (auto const& input_values : input_value_list)
+ {
+ auto const input_byte_count = input_values.size() * sizeof(input_values[0]);
+ item_count += input_values.size();
+ dest_buffer.resize(dest_buffer.capacity());
+
+
+ auto bytes_used = vbz_compress(
+ input_values.data(),
+ vbz_size_t(input_byte_count),
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ &options);
+
+ benchmark::DoNotOptimize(bytes_used);
+ }
+ }
+
+ state.SetItemsProcessed(state.iterations() * item_count);
+ state.SetBytesProcessed(state.iterations() * item_count * int_size);
+}
+
+template <typename VbzOptions, typename Generator>
+void streamvbyte_decompress_benchmark(benchmark::State& state)
+{
+ std::size_t max_element_count = 0;
+ auto input_value_list = Generator::generate(max_element_count);
+
+ auto const int_size = sizeof(typename VbzOptions::IntType);
+
+ CompressionOptions options{
+ VbzOptions::UseZigZag,
+ int_size,
+ VbzOptions::ZstdLevel
+ };
+
+ std::vector<char> compressed_buffer(vbz_max_compressed_size(vbz_size_t(max_element_count * int_size), &options));
+ std::vector<char> dest_buffer(max_element_count * int_size);
+
+ std::size_t item_count = 0;
+ for (auto _ : state)
+ {
+ item_count = 0;
+ for (auto const& input_values : input_value_list)
+ {
+ state.PauseTiming();
+ auto const input_byte_count = input_values.size() * sizeof(input_values[0]);
+ item_count += input_values.size();
+ compressed_buffer.resize(compressed_buffer.capacity());
+ dest_buffer.resize(input_byte_count);
+
+ auto compressed_used_bytes = vbz_compress(
+ input_values.data(),
+ vbz_size_t(input_byte_count),
+ compressed_buffer.data(),
+ vbz_size_t(compressed_buffer.size()),
+ &options
+ );
+
+ state.ResumeTiming();
+
+ auto bytes_expanded_to = vbz_decompress(
+ compressed_buffer.data(),
+ compressed_used_bytes,
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ &options
+ );
+ assert(bytes_expanded_to == input_byte_count);
+
+ benchmark::DoNotOptimize(bytes_expanded_to);
+ }
+ }
+
+ state.SetItemsProcessed(state.iterations() * item_count);
+ state.SetBytesProcessed(state.iterations() * item_count * int_size);
+}
+
+template <typename _IntType>
+struct VbzNoZStd
+{
+ using IntType = _IntType;
+ static const std::size_t UseZigZag = 1;
+ static const std::size_t ZstdLevel = 0;
+};
+
+template <typename _IntType>
+struct VbzZStd
+{
+ using IntType = _IntType;
+ static const std::size_t UseZigZag = 1;
+ static const std::size_t ZstdLevel = 1;
+};
+
+template <typename CompressionOptions>
+void compress_sequence(benchmark::State& state)
+{
+ streamvbyte_compress_benchmark<CompressionOptions, SequenceGenerator<typename CompressionOptions::IntType>>(state);
+}
+
+template <typename CompressionOptions>
+void compress_random(benchmark::State& state)
+{
+ streamvbyte_compress_benchmark<CompressionOptions, SignalGenerator<typename CompressionOptions::IntType>>(state);
+}
+
+template <typename CompressionOptions>
+void decompress_sequence(benchmark::State& state)
+{
+ streamvbyte_decompress_benchmark<CompressionOptions, SequenceGenerator<typename CompressionOptions::IntType>>(state);
+}
+
+template <typename CompressionOptions>
+void decompress_random(benchmark::State& state)
+{
+ streamvbyte_decompress_benchmark<CompressionOptions, SignalGenerator<typename CompressionOptions::IntType>>(state);
+}
+
+BENCHMARK_TEMPLATE(compress_sequence, VbzZStd<std::int8_t>);
+BENCHMARK_TEMPLATE(compress_sequence, VbzZStd<std::int16_t>);
+BENCHMARK_TEMPLATE(compress_sequence, VbzZStd<std::int32_t>);
+BENCHMARK_TEMPLATE(compress_sequence, VbzNoZStd<std::int8_t>);
+BENCHMARK_TEMPLATE(compress_sequence, VbzNoZStd<std::int16_t>);
+BENCHMARK_TEMPLATE(compress_sequence, VbzNoZStd<std::int32_t>);
+
+BENCHMARK_TEMPLATE(compress_random, VbzZStd<std::int8_t>);
+BENCHMARK_TEMPLATE(compress_random, VbzZStd<std::int16_t>);
+BENCHMARK_TEMPLATE(compress_random, VbzZStd<std::int32_t>);
+BENCHMARK_TEMPLATE(compress_random, VbzNoZStd<std::int8_t>);
+BENCHMARK_TEMPLATE(compress_random, VbzNoZStd<std::int16_t>);
+BENCHMARK_TEMPLATE(compress_random, VbzNoZStd<std::int32_t>);
+
+BENCHMARK_TEMPLATE(decompress_sequence, VbzZStd<std::int8_t>);
+BENCHMARK_TEMPLATE(decompress_sequence, VbzZStd<std::int16_t>);
+BENCHMARK_TEMPLATE(decompress_sequence, VbzZStd<std::int32_t>);
+BENCHMARK_TEMPLATE(decompress_sequence, VbzNoZStd<std::int8_t>);
+BENCHMARK_TEMPLATE(decompress_sequence, VbzNoZStd<std::int16_t>);
+BENCHMARK_TEMPLATE(decompress_sequence, VbzNoZStd<std::int32_t>);
+
+BENCHMARK_TEMPLATE(decompress_random, VbzZStd<std::int8_t>);
+BENCHMARK_TEMPLATE(decompress_random, VbzZStd<std::int16_t>);
+BENCHMARK_TEMPLATE(decompress_random, VbzZStd<std::int32_t>);
+BENCHMARK_TEMPLATE(decompress_random, VbzNoZStd<std::int8_t>);
+BENCHMARK_TEMPLATE(decompress_random, VbzNoZStd<std::int16_t>);
+BENCHMARK_TEMPLATE(decompress_random, VbzNoZStd<std::int32_t>);
+
+
+// Run the benchmark
+BENCHMARK_MAIN();
diff --git a/vbz/test/CMakeLists.txt b/vbz/test/CMakeLists.txt
new file mode 100644
index 0000000..0e1b48c
--- /dev/null
+++ b/vbz/test/CMakeLists.txt
@@ -0,0 +1,24 @@
+add_executable(vbz_test
+ streamvbyte_test.cpp
+ test_data.h
+ test_utils.h
+ vbz_test.cpp
+ main.cpp
+)
+add_sanitizers(vbz_test)
+
+set_property(TARGET vbz_test PROPERTY CXX_STANDARD 11)
+
+find_package( Threads )
+
+target_link_libraries(vbz_test
+ PUBLIC
+ vbz
+ ${CMAKE_THREAD_LIBS_INIT}
+)
+
+add_test(
+ NAME vbz_test
+ COMMAND vbz_test
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+)
diff --git a/vbz/test/main.cpp b/vbz/test/main.cpp
new file mode 100644
index 0000000..aca8cf3
--- /dev/null
+++ b/vbz/test/main.cpp
@@ -0,0 +1,2 @@
+#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
+#include "catch2/catch.hpp"
diff --git a/vbz/test/streamvbyte_test.cpp b/vbz/test/streamvbyte_test.cpp
new file mode 100644
index 0000000..a10c0cf
--- /dev/null
+++ b/vbz/test/streamvbyte_test.cpp
@@ -0,0 +1,239 @@
+#include "v0/vbz_streamvbyte.h"
+#include "v1/vbz_streamvbyte.h"
+
+#include "vbz.h"
+
+#include "test_utils.h"
+
+#include <numeric>
+#include <random>
+
+#include <catch2/catch.hpp>
+
+struct StreamVByteFunctions
+{
+ using SizeFn = decltype(vbz_max_streamvbyte_compressed_size_v0)*;
+ using CompressFn = decltype(vbz_delta_zig_zag_streamvbyte_compress_v0)*;
+ using DecompressFn = decltype(vbz_delta_zig_zag_streamvbyte_decompress_v0)*;
+
+ StreamVByteFunctions(
+ SizeFn _size,
+ CompressFn _compress,
+ DecompressFn _decompress
+ )
+ : size(_size)
+ , compress(_compress)
+ , decompress(_decompress)
+ {
+ }
+
+ SizeFn size;
+ CompressFn compress;
+ DecompressFn decompress;
+};
+
+StreamVByteFunctions const v0_functions{
+ vbz_max_streamvbyte_compressed_size_v0,
+ vbz_delta_zig_zag_streamvbyte_compress_v0,
+ vbz_delta_zig_zag_streamvbyte_decompress_v0
+};
+StreamVByteFunctions const v1_functions{
+ vbz_max_streamvbyte_compressed_size_v1,
+ vbz_delta_zig_zag_streamvbyte_compress_v1,
+ vbz_delta_zig_zag_streamvbyte_decompress_v1
+};
+
+template <typename T>
+void perform_streamvbyte_compression_test(
+ StreamVByteFunctions fns,
+ std::vector<T> const& data,
+ bool use_delta_zig_zag)
+{
+ INFO("Original " << dump_explicit<std::int64_t>(data));
+
+ auto const integer_size = sizeof(T);
+ auto const input_byte_count = data.size() * integer_size;
+ std::vector<std::int8_t> dest_buffer(fns.size(integer_size, vbz_size_t(input_byte_count)));
+ auto final_byte_count = fns.compress(
+ data.data(),
+ vbz_size_t(data.size() * sizeof(data[0])),
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ integer_size,
+ use_delta_zig_zag);
+ if (vbz_is_error(final_byte_count))
+ {
+ FAIL("Got error from vbz_delta_zig_zag_streamvbyte_compress");
+ return;
+ }
+ dest_buffer.resize(final_byte_count);
+
+ std::vector<int8_t> decompressed_bytes(data.size() * sizeof(data[0]));
+ auto decompressed_byte_count = fns.decompress(
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ decompressed_bytes.data(),
+ vbz_size_t(decompressed_bytes.size()),
+ integer_size,
+ use_delta_zig_zag
+ );
+
+ INFO("decompressed_bytes " << dump_explicit<std::int64_t>(decompressed_bytes));
+ if (vbz_is_error(decompressed_byte_count))
+ {
+ FAIL("Got error from vbz_delta_zig_zag_streamvbyte_decompress");
+ return;
+ }
+
+ decompressed_bytes.resize(decompressed_byte_count);
+ auto decompressed = gsl::make_span(decompressed_bytes).as_span<T>();
+ INFO("decompressed " << dump_explicit<std::int64_t>(decompressed));
+
+ THEN("Data is filtered and recovered correctly")
+ {
+ CHECK(decompressed == gsl::make_span(data));
+ }
+}
+
+template <typename T>
+void run_streamvbyte_compression_test_suite(StreamVByteFunctions fns)
+{
+ GIVEN("Simple data to compress")
+ {
+ std::vector<T> simple_data(100);
+ std::iota(simple_data.begin(), simple_data.end(), 0);
+
+ WHEN("Compressing with no delta zig zag")
+ {
+ perform_streamvbyte_compression_test(fns, simple_data, false);
+ }
+
+ WHEN("Compressing with delta zig zag")
+ {
+ perform_streamvbyte_compression_test(fns, simple_data, true);
+ }
+ }
+
+ GIVEN("Random data to compress")
+ {
+ std::vector<T> random_data(1000 * 1000);
+ auto seed = std::random_device()();
+ INFO("Seed " << seed);
+ std::default_random_engine rand(seed);
+ // std::uniform_int_distribution<std::int8_t> has issues on some platforms - always use 32 bit engine
+ std::uniform_int_distribution<std::int64_t> dist(std::numeric_limits<T>::min()/2, std::numeric_limits<T>::max()/2);
+ for (auto& e : random_data)
+ {
+ e = T(dist(rand));
+ }
+
+ WHEN("Compressing data")
+ {
+ perform_streamvbyte_compression_test(fns, random_data, std::is_signed<T>::value);
+ }
+ }
+}
+
+template <typename T> void perform_int_compressed_value_test(
+ StreamVByteFunctions const& fns,
+ std::vector<T> const& input_values,
+ bool perform_zig_zag,
+ std::vector<std::int8_t> const& expected_compressed)
+{
+ GIVEN("A known set of input signed values")
+ {
+ WHEN("Compressing/decompressing the values")
+ {
+ perform_streamvbyte_compression_test(fns, input_values, true);
+ perform_streamvbyte_compression_test(fns, input_values, false);
+ }
+
+ AND_WHEN("Compressing the values with delta zig zag")
+ {
+ std::vector<int8_t> dest_buffer(100);
+ auto final_byte_count = fns.compress(
+ input_values.data(),
+ vbz_size_t(input_values.size() * sizeof(input_values[0])),
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ sizeof(input_values[0]),
+ perform_zig_zag);
+ dest_buffer.resize(final_byte_count);
+
+ THEN("The values are as expected")
+ {
+ INFO("Compressed " << dump_explicit<std::int64_t>(dest_buffer));
+ INFO("Expected " << dump_explicit<std::int64_t>(expected_compressed));
+ CHECK(expected_compressed == dest_buffer);
+ }
+ }
+ }
+}
+
+SCENARIO("streamvbyte int8 encoding")
+{
+ run_streamvbyte_compression_test_suite<std::int8_t>(v0_functions);
+}
+
+SCENARIO("streamvbyte int16 encoding")
+{
+ run_streamvbyte_compression_test_suite<std::int16_t>(v0_functions);
+}
+
+SCENARIO("streamvbyte int32 encoding")
+{
+ run_streamvbyte_compression_test_suite<std::int32_t>(v0_functions);
+}
+
+SCENARIO("streamvbyte uint8 encoding")
+{
+ run_streamvbyte_compression_test_suite<std::uint8_t>(v0_functions);
+}
+
+SCENARIO("streamvbyte uint16 encoding")
+{
+ run_streamvbyte_compression_test_suite<std::uint16_t>(v0_functions);
+}
+
+SCENARIO("streamvbyte uint32 encoding")
+{
+ run_streamvbyte_compression_test_suite<std::uint32_t>(v0_functions);
+}
+
+SCENARIO("streamvbyte int16 encoding with known values.")
+{
+ GIVEN("signed types functions")
+ {
+ std::vector<std::int16_t> const input_values{ 0, -1, 4, -9, 16, -25, 36, -49, 64, -81, 100 };
+
+ GIVEN("v0 functions")
+ {
+ std::vector<int8_t> compressed_values_v0{ 0, 0, 20, 0, 1, 10, 25, 50, 81, 122, -87, -30, 33, 1, 106, 1 };
+ perform_int_compressed_value_test(v0_functions, input_values, true, compressed_values_v0);
+ }
+
+ GIVEN("v1 functions")
+ {
+ std::vector<int8_t> compressed_values_v1{ 0, 0, 20, 0, 1, 10, 25, 50, 81, 122, -87, -30, 33, 1, 106, 1, };
+ perform_int_compressed_value_test(v1_functions, input_values, true, compressed_values_v1);
+ }
+ }
+
+
+ GIVEN("unsigned signed types functions")
+ {
+ std::vector<std::uint16_t> input_values{ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 };
+
+ GIVEN("v0 functions")
+ {
+ std::vector<int8_t> compressed_values_v0{ 0, 0, 0, 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 };
+ perform_int_compressed_value_test(v0_functions, input_values, false, compressed_values_v0);
+ }
+
+ GIVEN("v1 functions")
+ {
+ std::vector<int8_t> compressed_values_v1{ 0, 0, 0, 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 };
+ perform_int_compressed_value_test(v1_functions, input_values, false, compressed_values_v1);
+ }
+ }
+}
diff --git a/vbz/test/test_data.h b/vbz/test/test_data.h
new file mode 100644
index 0000000..8e87a06
--- /dev/null
+++ b/vbz/test/test_data.h
@@ -0,0 +1,6 @@
+#include <cstdint>
+#include <vector>
+
+std::vector<std::int16_t> test_data{
+ 546, 332, 342, 329, 314, 290, 297, 286, 303, 306, 298, 308, 329, 322, 311, 305, 304, 315, 306, 312, 311, 309, 310, 309, 320, 312, 315, 310, 295, 311, 317, 304, 318, 300, 307, 312, 319, 314, 323, 312, 325, 326, 318, 311, 313, 317, 298, 301, 281, 310, 301, 315, 322, 300, 325, 297, 297, 311, 306, 310, 302, 305, 300, 318, 313, 296, 311, 313, 305, 310, 305, 300, 317, 310, 307, 314, 314, 295, 308, 304, 306, 299, 310, 310, 303, 290, 303, 313, 304, 299, 284, 305, 309, 315, 297, 313, 313, 315, 298, 305, 312, 309, 307, 310, 302, 310, 318, 318, 307, 313, 321, 309, 316, 312, 294, 315, 317, 311, 307, 308, 323, 322, 317, 315, 319, 299, 307, 306, 314, 314, 316, 321, 325, 317, 307, 317, 311, 315, 301, 317, 322, 326, 316, 318, 307, 302, 331, 303, 317, 308, 321, 311, 299, 318, 301, 314, 322, 302, 302, 314, 326, 321, 310, 314, 303, 300, 303, 306, 326, 312, 304, 306, 307, 302, 319, 305, 298, 310, 303, 313, 299, 319, 319, 303, 314, 318, 309, 310, 304, 305, 312, 306, 308, 299, 325, 288, 310, 306, 306, 290, 306, 318, 326, 317, 306, 317, 315, 313, 313, 306, 324, 304, 313, 320, 309, 302, 309, 309, 307, 306, 292, 327, 298, 306, 311, 312, 311, 324, 319, 311, 306, 296, 311, 314, 306, 303, 315, 293, 310, 314, 310, 319, 310, 306, 307, 313, 328, 299, 304, 311, 313, 311, 304, 319, 316, 309, 306, 308, 314, 319, 304, 308, 321, 314, 313, 306, 292, 311, 315, 313, 316, 316, 316, 310, 303, 308, 300, 305, 308, 312, 295, 293, 310, 293, 312, 304, 301, 310, 316, 305, 320, 295, 316, 300, 293, 317, 315, 308, 297, 307, 302, 297, 276, 285, 285, 272, 290, 289, 285, 286, 347, 357, 336, 329, 344, 327, 340, 332, 330, 334, 340, 332, 329, 325, 322, 331, 371, 528, 540, 545, 528, 539, 543, 555, 544, 535, 503, 457, 439, 461, 452, 449, 444, 454, 464, 495, 450, 394, 383, 368, 373, 363, 251, 256, 255, 236, 247, 249, 239, 248, 243, 242, 244, 242, 253, 242, 250, 249, 244, 229, 222, 225, 236, 229, 224, 229, 215, 220, 227, 222, 212, 277, 348, 347, 312, 274, 272, 248, 244, 280, 255, 341, 377, 355, 374, 388, 374, 379, 386, 375, 373, 376, 363, 370, 347, 372, 304, 297, 321, 302, 306, 310, 337, 353, 348, 337, 307, 299, 293, 278, 295, 316, 297, 294, 294, 263, 294, 360, 353, 355, 356, 365, 355, 354, 356, 344, 330, 362, 375, 367, 382, 375, 376, 395, 395, 354, 336, 327, 335, 332, 318, 317, 337, 337, 330, 319, 313, 312, 326, 327, 327, 235, 195, 173, 189, 184, 332, 351, 334, 334, 321, 356, 393, 405, 403, 397, 394, 395, 376, 397, 377, 391, 399, 397, 388, 411, 384, 397, 415, 365, 353, 350, 363, 344, 345, 348, 374, 354, 355, 328, 263, 246, 245, 225, 212, 195, 190, 195, 206, 229, 224, 289, 333, 337, 351, 370, 338, 327, 350, 319, 316, 328, 322, 315, 329, 332, 330, 335, 341, 314, 276, 270, 254, 246, 245, 259, 249, 240, 266, 273, 254, 252, 393, 367, 387, 372, 383, 374, 405, 394, 312, 262, 258, 265, 260, 258, 262, 249, 271, 285, 297, 344, 367, 280, 254, 279, 380, 343, 358, 361, 347, 352, 368, 373, 369, 370, 351, 369, 374, 367, 312, 293, 302, 261, 277, 297, 363, 352, 363, 352, 332, 272, 289, 289, 287, 310, 288, 302, 272, 273, 281, 307, 314, 311, 288, 293, 301, 296, 311, 409, 411, 386, 346, 413, 379, 410, 344, 335, 330, 336, 340, 343, 333, 333, 330, 302, 292, 313, 309, 318, 319, 317, 321, 331, 322, 393, 455, 450, 447, 434, 426, 384, 315, 309, 333, 312, 297, 303, 295, 338, 356, 339, 342, 343, 341, 340, 360, 334, 335, 331, 346, 328, 332, 337, 321, 346, 352, 347, 345, 336, 359, 366, 335, 322, 284, 294, 289, 300, 297, 280, 286, 283, 292, 305, 310, 290, 289, 288, 290, 292, 306, 309, 261, 242, 265, 262, 257, 250, 260, 246, 256, 236, 260, 281, 277, 275, 292, 285, 289, 272, 265, 292, 293, 296, 284, 277, 286, 303, 296, 295, 284, 275, 272, 287, 273, 273, 268, 293, 279, 300, 271, 297, 286, 296, 290, 295, 295, 273, 272, 290, 292, 295, 277, 291, 303, 286, 295, 288, 301, 276, 282, 274, 272, 276, 253, 249, 246, 237, 240, 252, 240, 239, 250, 242, 245, 271, 278, 291, 273, 291, 279, 274, 274, 282, 275, 274, 288, 232, 250, 247, 231, 243, 241, 235, 238, 239, 181, 163, 165, 163, 178, 168, 185, 190, 182, 170, 170, 186, 197, 178, 180, 164, 179, 362, 343, 348, 365, 350, 350, 334, 342, 344, 347, 340, 329, 357, 369, 351, 332, 312, 313, 305, 310, 319, 336, 355, 360, 360, 354, 356, 356, 356, 306, 294, 304, 290, 321, 194, 168, 175, 179, 175, 197, 179, 192, 167, 177, 171, 179, 373, 352, 348, 327, 348, 292, 183, 220, 357, 345, 345, 372, 346, 351, 331, 358, 361, 340, 344, 368, 362, 403, 380, 367, 383, 390, 361, 410, 402, 401, 403, 401, 343, 324, 327, 322, 333, 328, 328, 319, 289, 289, 286, 293, 350, 399, 381, 405, 382, 390, 385, 380, 392, 386, 329, 295, 285, 283, 286, 298, 323, 281, 296, 280, 271, 277, 296, 285, 325, 308, 327, 318, 305, 304, 307, 294, 293, 316, 314, 428, 420, 410, 411, 407, 379, 400, 347, 363, 339, 331, 320, 318, 352, 438, 420, 432, 431, 412, 423, 417, 401, 377, 399, 345, 331, 325, 313, 318, 303, 318, 332, 320, 339, 308, 321, 346, 332, 344, 360, 342, 345, 344, 351, 360, 339, 349, 350, 336, 339, 359, 343, 335, 325, 334, 333, 331, 308, 289, 286, 291, 283, 286, 278, 268, 342, 393, 378, 373, 408, 387, 372, 385, 372, 378, 387, 391, 385, 377, 407, 361, 391, 388, 373, 377, 365, 401, 387, 399, 372, 284, 292, 289, 277, 284, 264, 281, 265, 278, 291, 381, 381, 396, 392, 375, 401, 387, 343, 324, 303, 242, 256, 251, 245, 245, 252, 242, 233, 228, 237, 243, 239, 226, 221, 238, 226, 199, 226, 239, 247, 251, 239, 228, 222, 238, 232, 231, 236, 238, 234, 231, 237, 254, 281, 278, 272, 269, 271, 250, 244, 268, 267, 262, 292, 332, 325, 313, 335, 303, 331, 308, 309, 336, 329, 333, 326, 322, 341, 324, 336, 349, 351, 351, 352, 343, 346, 328, 325, 322, 281, 273, 264, 274, 270, 264, 261, 273, 257, 215, 214, 229, 214, 231, 272, 290, 273, 250, 216, 211, 219, 217, 194, 218, 213, 206, 224, 201, 222, 201, 226, 211, 205, 211, 204, 211, 215, 212, 224, 231, 230, 262, 239, 262, 236, 265, 243, 264, 240, 242, 258, 291, 353, 342, 354, 360, 339, 331, 348, 348, 363, 347, 341, 352, 361, 351, 348, 356, 366, 372, 364, 377, 362, 368, 368, 389, 389, 397, 375, 375, 384, 384, 389, 397, 388, 390, 378, 392, 381, 380, 393, 382, 387, 386, 407, 369, 383, 380, 357, 359, 335, 326, 305, 323, 323, 289, 281, 256, 276, 261, 266, 272, 248, 247, 267, 268, 241, 246, 249, 265, 300, 285, 282, 304, 380, 362, 359, 345, 352, 247, 235, 263, 354, 356, 345, 362, 355, 253, 365, 227, 209, 206, 256, 425, 449, 436, 424, 442, 383, 340, 330, 339, 332, 335, 349, 368, 342, 348, 328, 332, 329, 324, 353, 386, 392, 390, 411, 392, 403, 396, 383, 317, 303, 295, 283, 285, 294, 214, 208, 209, 208, 193, 207, 199, 211, 219, 200, 220, 205, 209, 234, 248, 256, 259, 256, 266, 263, 249, 267, 363, 390, 385, 384, 365, 369, 356, 371, 368, 360, 363, 347, 328, 321, 307, 308, 267, 245, 275, 285, 271, 384, 446, 406, 424, 399, 428, 296, 230, 217, 214, 207, 215, 212, 233, 327, 359, 353, 361, 350, 368, 354, 364, 357, 336, 379, 407, 410, 402, 401, 423, 404, 422, 384, 360, 352, 362, 354, 360, 346, 355, 355, 365, 359, 370, 342, 358, 343, 364, 359, 360, 358, 362, 380, 366, 367, 383, 371, 375, 378, 368, 361, 380, 347, 316, 298, 279, 246, 247, 246, 243, 251, 249, 233, 250, 244, 247, 228, 229, 262, 237, 199, 176, 157, 169, 189, 163, 177, 164, 168, 163, 172, 168, 161, 170, 293, 362, 361, 371, 360, 362, 380, 376, 410, 412, 400, 408, 404, 401, 405, 389, 404, 396, 408, 402, 396, 410, 360, 322, 316, 315, 314, 313, 321, 312, 313, 322, 329, 308, 313, 314, 296, 326, 333, 325, 304, 351, 386, 389, 395, 382, 373, 380, 393, 377, 363, 348, 345, 325, 266, 269, 267, 276, 256, 271, 269, 266, 263, 231, 255, 270, 286, 315, 370, 392, 387, 406, 413, 408, 388, 367, 362, 369, 379, 357, 359, 358, 348, 373, 364, 364, 358, 381, 367, 366, 370, 363, 360, 356, 369, 367, 356, 369, 360, 362, 361, 360, 314, 288, 287, 272, 251, 256, 252, 259, 274, 273, 266, 270, 287, 390, 399, 379, 384, 383, 370, 370, 373, 372, 370, 373, 382, 363, 352, 361, 284, 304, 271, 230, 220, 215, 211, 204, 198, 206, 224, 202, 204, 213, 217, 216, 201, 210, 233, 197, 207, 250, 280, 264, 263, 224, 209, 210, 195, 209, 213, 205, 234, 260, 247, 255, 254, 248, 254, 268, 263, 248, 247, 267, 263, 259, 264, 257, 330, 380, 370, 368, 371, 355, 349, 347, 365, 329, 349, 346, 347, 334, 248, 247, 244, 248, 240, 245, 228, 206, 214, 222, 217, 236, 220, 336, 381, 395, 392, 378, 376, 385, 368, 377, 357, 385, 372, 373, 390, 288, 296, 272, 287, 293, 252, 271, 275, 272, 284, 263, 260, 259, 254, 260, 247, 257, 231, 243, 229, 222, 232, 226, 238, 240, 241, 233, 251, 258, 259, 267, 255, 246, 246, 248, 244, 248, 222, 249, 226, 204, 221, 242, 242, 227, 226, 243, 221, 243, 216, 231, 278, 298, 322, 350, 339, 331, 300, 262, 370, 463, 458, 463, 448, 453, 454, 429, 349, 355, 354, 349, 367, 360, 349, 369, 359, 356, 439, 443, 365, 351, 310, 298, 308, 309, 319, 311, 308, 290, 296, 293, 295, 353, 373, 377, 366, 376, 369, 364, 355, 365, 351, 371, 367, 350, 374, 372, 373, 381, 359, 367, 373, 376, 377, 353, 365, 358, 381, 353, 380, 381, 365, 368, 372, 380, 378, 349, 316, 306, 313, 281, 315, 314, 291, 267, 275, 269, 237, 272, 240, 248, 254, 256, 243, 252, 241, 246, 256, 256, 250, 250, 241, 231, 232, 228, 208, 224, 224, 242, 278, 281, 270, 277, 297, 276, 292, 291, 378, 385, 360, 364, 367, 367, 365, 381, 371, 382, 368, 376, 383, 380, 394, 387, 380, 351, 315, 335, 319, 346, 357, 363, 328, 332, 318, 328, 297, 300, 303, 308, 302, 282, 277, 272, 266, 270, 263, 259, 252, 253, 255, 258, 255, 207, 198, 253, 261, 267, 254, 283, 262, 259, 266, 262, 332, 372, 378, 324, 269, 313, 372, 376, 376, 363, 366, 372, 382, 329, 344, 341, 342, 356, 348, 334, 343, 370, 318, 339, 351, 345, 353, 345, 357, 324, 345, 331, 353, 352, 345, 346, 343, 325, 345, 349, 360, 353, 345, 355, 347, 348, 355, 357, 353, 339, 349, 345, 340, 338, 357, 355, 343, 362, 357, 342, 351, 351, 360, 355, 364, 331, 350, 363, 347, 351, 350, 353, 342, 343, 342, 347, 339, 343, 348, 344, 332, 332, 321, 320, 327, 333, 313, 381, 403, 426, 406, 396, 416, 400, 398, 366, 355, 388, 401, 379, 372, 387, 377, 368, 379, 363, 380, 385, 337, 315, 324, 312, 336, 288, 316, 302, 310, 305, 317, 305, 306, 309, 310, 320, 312, 318, 308, 334, 305, 327, 322, 306, 306, 297, 306, 307, 312, 283, 294, 311, 320, 300, 291, 386, 444, 453, 442, 454, 425, 443, 348, 346, 352, 352, 358, 349, 352, 343, 354, 339, 353, 345, 350, 346, 364, 367, 351, 371, 366, 381, 369, 370, 352, 342, 350, 331, 330, 354, 338, 355, 349, 256, 281, 267, 250, 248, 246, 250, 256, 261, 277, 277, 257, 267, 274, 278, 279, 279, 280, 270, 278, 274, 288, 223, 281, 279, 341, 364, 357, 382, 368, 355, 369, 363, 325, 338, 334, 331, 339, 335, 333, 307, 324, 345, 333, 338, 315, 323, 368, 384, 371, 375, 378, 372, 367, 358, 383, 317, 262, 272, 245, 248, 276, 267, 258, 275, 299, 280, 253, 244, 247, 241, 261, 255, 240, 211, 231, 227, 270, 460, 454, 456, 447, 352, 346, 340, 350, 352, 359, 355, 361, 347, 308, 288, 269, 299, 299, 283, 286, 286, 286, 304, 283, 278, 296, 278, 280, 289, 281, 376, 392, 382, 393, 392, 379, 380, 378, 378, 379, 362, 343, 370, 361, 381, 362, 371, 381, 361, 368, 366, 329, 281, 273, 268, 277, 267, 255, 265, 277, 271, 334, 339, 367, 393, 372, 402, 397, 400, 405, 398, 375, 397, 395, 389, 383, 389, 396, 397, 406, 385, 374, 385, 382, 397, 391, 364, 383, 392, 379, 343, 295, 302, 293, 309, 276, 337, 388, 408, 388, 403, 389, 389, 305, 279, 302, 295, 289, 288, 297, 280, 340, 347, 346, 357, 394, 366, 364, 344, 374, 367, 295, 330, 348, 354, 363, 386, 349, 375, 367, 366, 357, 351, 355, 365, 341, 272, 219, 230, 222, 224, 249, 230, 217, 218, 253, 231, 226, 212, 248, 233, 234, 215, 244, 243, 253, 246, 255, 251, 254, 256, 263, 252, 300, 350, 364, 364, 355, 355, 353, 347, 350, 363, 337, 265, 264, 272, 263, 281, 265, 335, 370, 366, 361, 345, 359, 359, 359, 359, 353, 350, 344, 356, 311, 313, 289, 314, 289, 271, 216, 213, 236, 222, 196, 215, 210, 201, 205, 219, 200, 218, 219, 241, 249, 256, 254, 251, 327, 326, 360, 355, 346, 349, 373, 350, 341, 357, 350, 307, 290, 316, 300, 310, 277, 267, 242, 252, 239, 223, 204, 192, 190, 156, 187, 195, 192, 187, 191, 349, 364, 355, 383, 390, 394, 370, 359, 301, 306, 298, 299, 285, 279, 280, 290, 302, 290, 381, 380, 409, 384, 391, 384, 343, 347, 333, 285, 329, 336, 335, 310, 324, 265, 262, 296, 295, 307, 321, 323, 310, 307, 337, 360, 334, 353, 335, 341, 288, 282, 283, 314, 343, 292, 269, 352, 294, 273, 279, 270, 260, 272, 256, 270, 325, 307, 256, 363, 464, 435, 468, 458, 441, 434, 389, 335, 319, 314, 317, 315, 316, 303, 342, 436, 430, 445, 432, 434, 430, 428, 424, 436, 419, 405, 400, 349, 339, 365, 396, 351, 343, 350, 361, 342, 337, 348, 342, 352, 351, 383, 387, 379, 386, 374, 353, 342, 366, 361, 361, 348, 313, 288, 324, 266, 251, 287, 288, 270, 292, 291, 286, 286, 300, 277, 296, 287, 298, 308, 292, 294, 300, 292, 287, 293, 298, 292, 369, 371, 386, 385, 325, 391, 366, 362, 366, 361, 363, 371, 356, 364, 364, 365, 363, 352, 346, 368, 362, 380, 364, 362, 364, 365, 373, 366, 372, 341, 333, 294, 292, 259, 247, 258, 237, 264, 248, 236, 247, 237, 232, 235, 216, 209, 210, 208, 205, 214, 231, 248, 242, 235, 239, 235, 253, 270, 279, 273, 284, 272, 278, 276, 293, 279, 336, 411, 250, 298, 312, 310, 314, 325, 315, 305, 338, 324, 335, 353, 373, 372, 360, 366, 358, 373, 356, 371, 358, 363, 348, 361, 355, 369, 336, 365, 353, 337, 346, 317, 334, 366, 346, 339, 311, 283, 288, 306, 319, 278, 304, 335, 328, 320, 319, 394, 363, 366, 367, 364, 379, 374, 335, 314, 313, 305, 319, 312, 315, 315, 322, 310, 310, 309, 318, 308, 317, 307, 318, 312, 324, 326, 313, 307, 313, 312, 355, 355, 354, 337, 348, 352, 359, 372, 401, 358, 368, 368, 373, 341, 301, 276, 278, 277, 297, 280, 273, 295, 359, 368, 378, 363, 340, 272, 264, 225, 226, 210, 215, 237, 222, 204, 225, 346, 364, 356, 300, 302, 300, 294, 283, 281, 275, 252, 233, 231, 249, 207, 227, 224, 219, 230, 213, 229, 198, 212, 220, 346, 439, 384, 348, 340, 322, 320, 309, 318, 311, 363, 372, 383, 385, 380, 392, 364, 384, 372, 367, 363, 363, 373, 373, 351, 380, 366, 322, 309, 320, 286, 350, 358, 386, 367, 376, 339, 283, 267, 280, 299, 298, 270, 297, 283, 256, 251, 243, 248, 253, 244, 238, 238, 203, 215, 200, 185, 213, 196, 251, 240, 230, 245, 240, 242, 248, 271, 284, 279, 271, 274, 285, 316, 329, 330, 323, 306, 306, 301, 318, 349, 346, 332, 345, 343, 346, 358, 367, 364, 349, 351, 355, 374, 348, 315, 286, 294, 271, 254, 272, 261, 273, 274, 275, 262, 322, 341, 348, 274, 291, 297, 270, 245, 271, 259, 249, 245, 260, 254, 268, 267, 269, 243, 269, 249, 257, 260, 211, 198, 202, 186, 235, 216, 186, 202, 199, 202, 200, 185, 208, 182, 189, 189, 200, 185, 197, 218, 217, 207, 223, 224, 207, 219, 200, 208, 385, 377, 374, 388, 391, 388, 371, 371, 396, 415, 422, 429, 411, 419, 413, 404, 418, 419, 371, 368, 357, 360, 364, 367, 401, 359, 404, 431, 428, 425, 415, 378, 359, 349, 356, 360, 366, 362, 352, 342, 306, 326, 296, 282, 287, 274, 221, 235, 315, 414, 404, 381, 401, 389, 390, 392, 379, 290, 288, 292, 276, 283, 256, 188, 180, 188, 202, 264, 262, 258, 409, 394, 411, 407, 383, 307, 290, 274, 281, 265, 282, 287, 258, 247, 253, 248, 252, 260, 252, 249, 266, 256, 251, 264, 243, 253, 261, 293, 382, 401, 380, 378, 380, 394, 389, 412, 375, 391, 309, 348, 262, 388, 340, 354, 338, 335, 340, 331, 327, 333, 328, 330, 334, 329, 327, 318, 308, 309, 311, 345, 337, 346, 344, 346, 354, 338, 349, 347, 337, 340, 331, 333, 343, 336, 342, 347, 335, 327, 343, 325, 341, 344, 342, 331, 334, 336, 339, 351, 331, 346, 338, 343, 333, 397, 389, 375, 403, 401, 397, 392, 381, 383, 386, 377, 390, 393, 378, 385, 397, 316, 311, 317, 309, 305, 322, 301, 287, 239, 236, 247, 238, 245, 220, 243, 245, 228, 241, 263, 258, 323, 343, 349, 346, 353, 345, 391, 397, 349, 334, 352, 346, 384, 403, 386, 378, 390, 369, 397, 371, 306, 264, 230, 156, 163, 162, 153, 165, 166, 160, 171, 152, 172, 159, 164, 174, 312, 308, 314, 306, 291, 333, 304, 304, 288, 329, 327, 324, 309, 342, 339, 336, 338, 348, 351, 348, 340, 353, 332, 346, 344, 347, 348, 345, 343, 355, 345, 341, 351, 354, 343, 343, 335, 306, 300, 278, 307, 308, 301, 305, 309, 309, 304, 298, 298, 318, 289, 292, 299, 304, 308, 305, 302, 293, 297, 316, 312, 327, 326, 319, 325, 327, 312, 302, 294, 277, 293, 272, 275, 265, 282, 385, 382, 386, 384, 376, 316, 296, 312, 300, 312, 304, 303, 310, 287, 297, 355, 389, 312, 318, 320, 301, 320, 317, 297, 317, 308, 319, 310, 333, 296, 211, 214, 230, 190, 207, 192, 202, 193, 211, 183, 200, 208, 206, 193, 195, 181, 188, 189, 202, 189, 204, 204, 220, 182, 343, 429, 436, 420, 437, 412, 419, 425, 417, 427, 428, 413, 426, 411, 434, 422, 421, 419, 418, 420, 423, 348, 337, 342, 334, 322, 328, 313, 324, 327, 366, 393, 369, 365, 372, 366, 353, 299, 265, 299, 276, 279, 283, 284, 293, 281, 274, 262, 279, 280, 287, 271, 262, 283, 267, 281, 322, 336, 331, 325, 355, 317, 270, 312, 327, 333, 336, 372, 346, 351, 326, 314, 324, 340, 330, 340, 324, 337, 307, 299, 298, 287, 304, 299, 372, 407, 344, 332, 369, 325, 352, 319, 304, 335, 303, 245, 233, 249, 239, 229, 249, 289, 299, 291, 298, 349, 391, 392, 347, 308, 319, 301, 301, 306, 292, 314, 307, 283, 283, 308, 281, 299, 302, 314, 305, 317, 335, 364, 360, 386, 371, 377, 309, 283, 277, 304, 294, 291, 290, 299, 286, 283, 207, 210, 211, 206, 229, 203, 220, 208, 194, 201, 201, 199, 179, 205, 183, 196, 200, 189, 190, 205, 202, 199, 201, 195, 191, 265, 381, 348, 314, 405, 403, 379, 345, 326, 220, 232, 232, 281, 340, 338, 334, 352, 349, 339, 345, 334, 343, 348, 347, 398, 384, 396, 407, 401, 396, 409, 393, 368, 385, 361, 365, 354, 278, 317, 279, 260, 276, 331, 262, 262, 273, 271, 284, 261, 276, 254, 269, 280, 273, 271, 256, 259, 267, 267, 273, 330, 402, 442, 421, 414, 394, 397, 405, 422, 331, 329, 319, 306, 332, 311, 309, 316, 332, 355, 337, 334, 293, 325, 310, 320, 285, 249, 231, 265, 257, 247, 262, 256, 252, 217, 244, 330, 389, 385, 410, 401, 409, 369, 377, 374, 399, 382, 381, 364, 296, 301, 305, 293, 309, 298, 319, 305, 297, 284, 289, 300, 320, 439, 399, 428, 419, 403, 419, 440, 422, 428, 429, 413, 399, 295, 260, 258, 256, 256, 261, 246, 270, 279, 266, 247, 268, 305, 383, 382, 387, 360, 381, 372, 388, 379, 382, 384, 373, 385, 385, 387, 317, 274, 267, 266, 276, 252, 268, 249, 272, 247, 248, 259, 255, 262, 381, 372, 356, 253, 259, 367, 377, 378, 394, 381, 371, 362, 340, 275, 253, 301, 373, 374, 357, 380, 398, 372, 365, 351, 355, 362, 379, 363, 259, 264, 256, 262, 371, 381, 363, 381, 370, 349, 385, 377, 382, 373, 379, 384, 371, 377, 357, 375, 370, 387, 389, 385, 398, 379, 377, 359, 359, 377, 359, 370, 366, 369, 373, 368, 376, 327, 260, 273, 297, 284, 265, 256, 238, 271, 329, 380, 366, 369, 387, 376, 376, 371, 363, 354, 373, 356, 363, 368, 361, 342, 335, 338, 328, 329, 335, 327, 306, 329, 332, 354, 378, 356, 362, 359, 370, 360, 353, 359, 371, 371, 350, 368, 363, 334, 350, 322, 279, 264, 273, 314, 266, 268, 270, 265, 259, 275, 332, 265, 275, 273, 267, 275, 244, 293, 292, 334, 391, 374, 279, 272, 270, 274, 320, 257, 206, 190, 194, 195, 227, 226, 219, 188, 225, 245, 235, 225, 257, 227, 223, 233, 338, 391, 358, 266, 238, 236, 253, 274, 270, 270, 350, 381, 368, 344, 328, 374, 278, 235, 238, 239, 235, 228, 214, 240, 230, 229, 218, 237, 225, 226, 233, 219, 185, 192, 207, 200, 190, 193, 196, 216, 200, 194, 202, 191, 199, 195, 192, 186, 194, 204, 187, 278, 439, 435, 450, 431, 420, 444, 449, 444, 435, 437, 449, 437, 430, 441, 445, 447, 421, 435, 451, 413, 325, 289, 286, 322, 381, 291, 307, 289, 298, 282, 278, 286, 342, 338, 330, 330, 302, 320, 329, 312, 316, 331, 319, 307, 322, 364, 358, 345, 336, 364, 372, 386, 355, 367, 363, 301, 277, 264, 254, 262, 253, 249, 279, 260, 253, 196, 206, 227, 204, 214, 191, 182, 205, 367, 349, 357, 345, 359, 358, 352, 362, 349, 355, 396, 403, 401, 401, 394, 385, 376, 404, 377, 394, 368, 352, 372, 401, 376, 404, 380, 359, 333, 378, 384, 377, 370, 333, 308, 319, 311, 304, 297, 315, 310, 315, 303, 302, 310, 319, 309, 332, 344, 343, 347, 326, 348, 325, 356, 326, 334, 317, 325, 306, 321, 316, 317, 270, 263, 260, 256, 263, 260, 251, 267, 256, 350, 448, 437, 437, 431, 450, 445, 382, 347, 355, 367, 340, 347, 341, 357, 342, 340, 336, 342, 338, 346, 329, 353, 340, 346, 347, 343, 328, 307, 323, 308, 425, 439, 450, 447, 442, 425, 425, 429, 361, 298, 279, 272, 284, 281, 276, 283, 285, 293, 296, 308, 339, 322, 331, 338, 346, 334, 315, 342, 324, 328, 316, 322, 315, 321, 344, 363, 359, 365, 330, 327, 319, 364, 353, 358, 368, 360, 348, 338, 325, 324, 320, 326, 303, 314, 307, 309, 319, 372, 391, 388, 326, 231, 245, 249, 267, 384, 238, 253, 235, 260, 277, 239, 230, 274, 336, 317, 325, 316, 327, 319, 320, 303, 318, 311, 303, 322, 315, 305, 310, 291, 307, 304, 297, 325, 303, 306, 307, 305, 291, 306, 331, 300, 310, 303, 306, 312, 292, 284, 319, 301, 316, 315, 277, 298, 299, 314, 304, 301, 306, 315, 319, 309, 305, 304, 308, 296, 298, 316, 308, 333, 302, 309, 303, 304, 314, 304, 311, 309, 315, 294, 318, 323, 307, 319, 308, 305, 305, 319, 341, 320, 326, 336, 341, 364, 374, 361, 354, 350, 343, 311, 247, 256, 259, 252, 244, 265, 251, 307, 413, 413, 416, 413, 425, 415, 403, 413, 425, 423, 412, 396, 409, 415, 404, 342, 323, 339, 333, 343, 329, 334, 329, 361, 381, 367, 383, 320, 315, 294, 268, 263, 264, 252, 256, 250, 216, 201, 188, 180, 192, 180, 187, 189, 170, 184, 184, 188, 194, 187, 176, 203, 197, 206, 194, 204, 194, 187, 183, 195, 191, 204, 210, 265, 309, 316, 309, 320, 269, 330, 329, 328, 347, 394, 395, 397, 387, 385, 386, 390, 394, 387, 398, 345, 362, 359, 358, 372, 366, 364, 373, 375, 376, 344, 366, 319, 319, 296, 292, 289, 282, 233, 247, 259, 223, 214, 254, 261, 256, 246, 255, 257, 265, 250, 289, 419, 417, 430, 387, 387, 441, 408, 403, 406, 382, 317, 265, 269, 275, 254, 247, 254, 268, 251, 262, 269, 365, 375, 382, 374, 384, 388, 369, 392, 370, 368, 354, 310, 256, 239, 245, 243, 241, 227, 228, 226, 227, 221, 241, 229, 324, 366, 354, 367, 377, 413, 414, 422, 420, 412, 402, 422, 407, 423, 399, 411, 413, 401, 423, 406, 395, 414, 414, 393, 400, 410, 395, 365, 341, 329, 356, 360, 330, 340, 345, 340, 305, 289, 263, 274, 259, 268, 261, 294, 287, 292, 293, 339, 391, 390, 372, 369, 356, 367, 390, 361, 246, 252, 262, 238, 251, 246, 234, 237, 227, 227, 209, 219, 217, 219, 228, 225, 231, 242, 232, 228, 220, 234, 360, 386, 229, 233, 247, 237, 221, 244, 219, 231, 230, 308, 389, 320, 299, 420, 384, 402, 400, 394, 398, 407, 363, 337, 285, 293, 293, 284, 276, 277, 291, 303, 285, 283, 292, 269, 279, 292, 310, 302, 306, 319, 314, 317, 313, 301, 323, 316, 315, 317, 423, 432, 428, 442, 424, 428, 437, 375, 365, 367, 359, 370, 356, 373, 364, 359, 343, 333, 363, 353, 373, 360, 344, 357, 360, 349, 358, 351, 365, 346, 353, 331, 339, 332, 286, 303, 317, 291, 290, 262, 218, 228, 233, 235, 242, 254, 248, 229, 241, 228, 238, 230, 235, 238, 242, 235, 235, 242, 317, 430, 415, 399, 412, 441, 423, 421, 432, 424, 317, 306, 314, 328, 447, 430, 411, 417, 422, 429, 409, 394, 362, 383, 367, 360, 357, 366, 369, 367, 364, 378, 354, 357, 367, 378, 358, 353, 376, 376, 357, 363, 369, 370, 371, 378, 380, 364, 350, 359, 343, 346, 341, 350, 354, 343, 347, 369, 373, 330, 318, 297, 305, 311, 353, 275, 253, 268, 271, 181, 176, 160, 168, 189, 175, 197, 333, 334, 338, 323, 330, 331, 341, 343, 340, 337, 336, 319, 323, 317, 336, 332, 324, 324, 310, 326, 314, 297, 300, 337, 361, 380, 364, 405, 397, 392, 390, 402, 402, 399, 394, 391, 368, 352, 354, 356, 352, 365, 357, 355, 353, 352, 348, 351, 346, 364, 340, 301, 308, 302, 294, 293, 265, 248, 232, 251, 236, 236, 224, 231, 248, 231, 227, 198, 211, 188, 197, 200, 196, 202, 278, 259, 275, 305, 365, 349, 356, 342, 351, 352, 371, 356, 359, 356, 349, 343, 306, 273, 263, 258, 267, 264, 263, 263, 250, 266, 251, 271, 258, 262, 268, 257, 257, 267, 258, 251, 260, 259, 277, 273, 259, 259, 262, 254, 245, 251, 242, 269, 340, 336, 344, 357, 384, 362, 373, 407, 391, 394, 385, 389, 367, 362, 354, 360, 323, 315, 275, 316, 298, 269, 262, 278, 280, 259, 259, 269, 278, 279, 261, 269, 259, 259, 255, 251, 257, 248, 229, 232, 220, 236, 229, 205, 241, 216, 210, 198, 269, 301, 292, 286, 294, 283, 284, 296, 301, 307, 287, 357, 380, 377, 383, 376, 385, 377, 338, 302, 306, 302, 301, 301, 305, 295, 297, 303, 304, 300, 298, 289, 304, 283, 296, 287, 299, 278, 256, 262, 260, 244, 251, 223, 269, 251, 237, 260, 246, 238, 240, 236, 229, 246, 227, 235, 238, 221, 232, 243, 228, 229, 230, 234, 229, 209, 218, 186, 245, 221, 218, 197, 227, 212, 225, 219, 222, 213, 235, 226, 230, 239, 230, 253, 243, 273, 227, 215, 243, 212, 233, 231, 240, 235, 225, 235, 219, 251, 231, 223, 251, 271, 282, 271, 269, 267, 243, 247, 250, 272, 252, 235, 246, 242, 250, 247, 234, 216, 206, 209, 209, 202, 228, 218, 210, 233, 211, 213, 213, 208, 225, 215, 218, 200, 229, 212, 203, 218, 196, 192, 211, 207, 221, 235, 209, 212, 230, 190, 183, 181, 175, 181, 174, 174, 188, 182, 200, 179, 188, 199, 215, 214, 376, 384, 412, 386, 369, 389, 389, 393, 395, 389, 364, 396, 356, 314, 316, 324, 308, 322, 306, 320, 308, 308, 303, 310, 302, 303, 321, 293, 301, 296, 287, 290, 286, 285, 283, 284, 282, 277, 271, 287, 281, 298, 266, 290, 283, 244, 217, 223, 218, 225, 206, 204, 215, 214, 212, 237, 227, 229, 221, 219, 217, 221, 206, 223, 207, 209, 191, 205, 212, 206, 207, 279, 393, 408, 395, 412, 382, 376, 289, 310, 314, 301, 277, 286, 287, 300, 279, 278, 272, 286, 227, 209, 196, 237, 224, 245, 233, 235, 246, 233, 214, 206, 235, 211, 212, 215, 226, 216, 208, 220, 210, 225, 223, 212, 200, 219, 217, 217, 192, 220, 240, 214, 231, 208, 170, 226, 235, 213, 208, 216, 222, 217, 214, 223, 365, 402, 319, 415, 403, 401, 381, 382, 389, 375, 388, 377, 371, 381, 284, 293, 299, 255, 292, 262, 243, 230, 225, 219, 250, 252, 278, 246, 223, 246, 240, 253, 239, 258, 264, 242, 264, 273, 271, 242, 269, 273, 284, 260, 265, 261, 274, 262, 276, 265, 274, 276, 274, 270, 295, 240, 249, 240, 256, 255, 250, 248, 236, 251, 269, 244, 234, 251, 259, 254, 249, 239, 249, 236, 250, 239, 239, 247, 249, 249, 243, 242, 200, 201, 197, 192, 208, 194, 199, 197, 200, 214, 208, 210, 216, 213, 211, 217, 208, 224, 213, 214, 223, 214, 259, 382, 336, 363, 350, 378, 365, 372, 362, 331, 311, 317, 295, 303, 268, 286, 282, 289, 266, 277, 287, 299, 291, 282, 271, 281, 254, 292, 310, 281, 262, 269, 267, 272, 283, 283, 281, 282, 296, 355, 336, 360, 370, 351, 350, 359, 345, 352, 334, 359, 327, 330, 336, 307, 287, 273, 260, 282, 277, 288, 274, 277, 286, 292, 281, 271, 286, 284, 272, 287, 278, 291, 281, 294, 279, 277, 297, 289, 281, 297, 302, 376, 373, 379, 365, 339, 285, 335, 324, 413, 364, 322, 318, 274, 288, 281, 272, 258, 245, 222, 201, 208, 204, 196, 188, 205, 195, 235, 271, 249, 252, 264, 350, 339, 329, 350, 315, 301, 285, 305, 276, 275, 272, 291, 234, 244, 255, 232, 243, 261, 234, 259, 246, 236, 237, 243, 238, 246, 244, 235, 257, 247, 241, 237, 234, 203, 215, 208, 208, 191, 200, 216, 205, 201, 220, 188, 196, 205, 220, 214, 212, 207, 209, 220, 212, 231, 268, 276, 319, 324, 346, 354, 319, 334, 350, 334, 320, 327, 341, 348, 342, 340, 340, 331, 330, 321, 312, 290, 299, 299, 303, 291, 300, 300, 304, 302, 299, 295, 304, 298, 304, 302, 299, 304, 337, 335, 345, 331, 335, 345, 338, 324, 347, 337, 328, 354, 326, 341, 331, 337, 345, 379, 357, 349, 352, 352, 345, 283, 268, 279, 284, 225, 244, 239, 231, 235, 230, 270, 238, 244, 201, 228, 233, 214, 215, 218, 209, 197, 206, 192, 202, 200, 199, 192, 207, 202, 206, 204, 192, 190, 201, 195, 171, 189, 190, 199, 199, 179, 200, 177, 185, 195, 210, 199, 203, 192, 180, 187, 180, 201, 203, 204, 205, 189, 177, 262, 369, 375, 368, 375, 376, 362, 319, 322, 295, 298, 304, 305, 308, 294, 305, 334, 375, 374, 349, 361, 365, 376, 355, 365, 368, 345, 315, 317, 327, 316, 339, 320, 337, 307, 325, 269, 284, 269, 254, 263, 296, 433, 391, 402, 399, 407, 394, 384, 389, 388, 429, 377, 276, 280, 280, 269, 344, 278, 257, 276, 249, 281, 264, 272, 283, 262, 249, 268, 364, 429, 457, 435, 420, 422, 439, 444, 444, 362, 287, 270, 283, 287, 291, 280, 280, 295, 281, 279, 282, 298, 281, 293, 270, 279, 292, 340, 343, 336, 321, 345, 350, 349, 344, 339, 331, 358, 341, 327, 300, 320, 311, 324, 331, 322, 317, 332, 324, 285, 276, 298, 279, 271, 308, 368, 391, 428, 413, 412, 418, 420, 401, 427, 434, 423, 403, 374, 356, 367, 357, 357, 367, 345, 330, 324, 320, 241, 246, 236, 234, 228, 237, 229, 240, 217, 217, 281, 358, 331, 339, 335, 337, 359, 400, 413, 407, 401, 408, 393, 396, 407, 409, 407, 396, 413, 391, 409, 397, 364, 361, 345, 344, 344, 351, 361, 354, 340, 360, 363, 339, 346, 349, 358, 339, 350, 354, 344, 378, 362, 366, 367, 362, 369, 360, 369, 365, 356, 329, 293, 275, 262, 277, 271, 262, 271, 276, 262, 263, 269, 274, 269, 265, 281, 298, 305, 289, 295, 283, 289, 288, 304, 309, 297, 364, 349, 345, 340, 340, 350, 319, 328, 303, 310, 306, 300, 313, 333, 361, 381, 364, 364, 336, 335, 342, 332, 330, 327, 320, 312, 406, 457, 459, 434, 436, 434, 445, 397, 443, 431, 443, 437, 432, 423, 428, 454, 432, 430, 429, 432, 437, 424, 385, 328, 323, 332, 323, 333, 327, 329, 313, 341, 323, 317, 326, 379, 403, 360, 337, 337, 357, 329, 321, 320, 314, 326, 335, 344, 335, 354, 332, 347, 329, 336, 344, 345, 339, 380, 414, 396, 415, 410, 419, 400, 423, 389, 356, 373, 367, 388, 284, 295, 297, 299, 295, 319, 368, 281, 223, 254, 225, 269, 291, 267, 285, 288, 291, 292, 318, 404, 391, 368, 376, 373, 357, 353, 362, 361, 368, 377, 379, 286, 279, 268, 331, 395, 381, 373, 369, 375, 366, 378, 385, 375, 358, 362, 385, 380, 386, 357, 366, 372, 385, 369, 387, 385, 376, 394, 380, 381, 386, 396, 344, 306, 297, 305, 297, 276, 280, 228, 221, 220, 242, 240, 269, 262, 243, 241, 250, 247, 240, 237, 251, 239, 242, 236, 276, 321, 329, 381, 378, 358, 369, 372, 351, 350, 275, 251, 246, 242, 273, 249, 253, 194, 195, 197, 182, 207, 197, 195, 195, 213, 224, 216, 217, 213, 350, 424, 408, 397, 346, 339, 310, 321, 326, 314, 316, 299, 319, 316, 296, 305, 300, 313, 308, 291, 297, 284, 373, 425, 438, 405, 418, 393, 401, 388, 303, 319, 321, 317, 326, 332, 309, 324, 314, 362, 414, 318, 323, 425, 333, 315, 306, 321, 314, 310, 320, 318, 323, 432, 437, 407, 416, 416, 415, 416, 325, 332, 343, 318, 343, 312, 328, 320, 331, 329, 329, 307, 298, 297, 307, 318, 324, 324, 323, 328, 317, 333, 316, 299, 310, 410, 411, 404, 407, 418, 330, 339, 325, 323, 304, 320, 305, 312, 394, 422, 415, 427, 414, 417, 421, 417, 420, 384, 323, 366, 382, 356, 375, 371, 343, 312, 299, 300, 296, 299, 303, 298, 302, 297, 292, 307, 294, 300, 349, 350, 332, 328, 335, 338, 335, 342, 342, 350, 337, 330, 313, 297, 307, 309, 294, 322, 305, 333, 421, 401, 418, 402, 414, 417, 377, 319, 317, 335, 328, 309, 330, 322, 331, 326, 345, 303, 364, 432, 407, 438, 424, 386, 412, 357, 314, 327, 322, 319, 302, 333, 317, 316, 324, 420, 423, 427, 404, 417, 392, 391, 386, 322, 309, 308, 319, 332, 334, 313, 319, 337, 333, 309, 308, 311, 306, 321, 326, 316, 447, 443, 410, 408, 430, 431, 398, 414, 418, 406, 417, 414, 341, 322, 352, 377, 387, 382, 374, 360, 324, 321, 331, 319, 337, 306, 313, 377, 370, 364, 360, 360, 375, 366, 369, 340, 313, 324, 328, 268, 279, 273, 271, 382, 425, 433, 418, 433, 417, 416, 409, 339, 337, 318, 338, 321, 326, 315, 350, 383, 383, 368, 371, 363, 356, 296, 274, 264, 271, 249, 262, 244, 283, 267, 326, 411, 414, 417, 380, 346, 330, 317, 337, 332, 311, 328, 305, 319, 311, 313, 308, 317, 296, 310, 310, 308, 377, 449, 452, 448, 445, 447, 438, 426, 433, 427, 425, 418, 390, 365, 371, 353, 371, 359, 374, 360, 357, 372, 363, 316, 292, 284, 285, 289, 298, 282, 269, 209, 231, 253, 236, 251, 250, 248, 236, 235, 246, 255, 244, 254, 258, 261, 263, 249, 246, 247, 256, 238, 248, 313, 353, 360, 356, 320, 355, 353, 360, 370, 341, 353, 346, 356, 333, 331, 335, 337, 339, 335, 335, 337, 315, 293, 279, 281, 284, 265, 282, 284, 293, 269, 268, 277, 278, 284, 271, 287, 270, 269, 297, 278, 297, 299, 295, 268, 274, 296, 336, 339, 335, 353, 308, 329, 320, 343, 339, 329, 349, 333, 338, 357, 372, 352, 372, 262, 229, 222, 200, 222, 206, 192, 194, 228, 331, 327, 321, 325, 344, 327, 331, 332, 373, 369, 381, 395, 389, 382, 390, 378, 387, 304, 276, 271, 279, 353, 381, 362, 361, 342, 351, 371, 359, 370, 361, 369, 358, 305, 246, 253, 243, 238, 237, 239, 235, 231, 222, 229, 224, 215, 206, 242, 231, 222, 215, 226, 210, 230, 220, 272, 373, 390, 401, 398, 398, 406, 388, 373, 350, 308, 321, 326, 319, 318, 317, 328, 327, 319, 314, 312, 331, 311, 282, 243, 266, 235, 248, 248, 241, 249, 261, 345, 415, 392, 379, 398, 389, 395, 403, 386, 392, 393, 394, 397, 381, 383, 385, 403, 394, 396, 382, 377, 379, 377, 388, 383, 382, 335, 351, 341, 338, 344, 358, 359, 352, 356, 361, 343, 353, 359, 351, 344, 345, 344, 358, 350, 357, 369, 357, 350, 343, 312, 319, 297, 299, 257, 238, 231, 212, 238, 221, 219, 239, 270, 245, 253, 269, 244, 276, 267, 273, 246, 263, 256, 260, 251, 261, 257, 256, 343, 375, 380, 368, 363, 379, 351, 354, 374, 367, 357, 378, 368, 367, 371, 365, 371, 340, 390, 267, 256, 278, 232, 259, 237, 238, 242, 250, 229, 241, 248, 245, 217, 252, 234, 245, 226, 241, 228, 259, 236, 257, 275, 285, 383, 367, 363, 349, 357, 369, 351, 285, 258, 250, 265, 247, 235, 222, 207, 197, 200, 283, 400, 370, 403, 386, 366, 390, 361, 378, 400, 288, 309, 302, 284, 309, 296, 299, 336, 308, 293, 295, 295, 292, 303, 303, 288, 309, 302, 338, 320, 367, 380, 362, 375, 377, 365, 348, 388, 370, 362, 357, 374, 322, 280, 271, 283, 281, 289, 256, 270, 252, 280, 271, 269, 263, 262, 254, 234, 247, 291, 303, 319, 365, 382, 373, 390, 369, 359, 347, 369, 291, 290, 296, 290, 291, 307, 296, 306, 314, 313, 302, 296, 310, 370, 435, 430, 424, 430, 413, 360, 370, 385, 375, 357, 329, 313, 303, 267, 264, 268, 274, 273, 263, 271, 264, 255, 289, 250, 245, 231, 228, 215, 195, 223, 239, 246, 258, 253, 249, 248, 250, 259, 253, 250, 315, 308, 320, 327, 293, 304, 321, 376, 275, 339, 387, 368, 375, 327, 310, 302, 306, 307, 316, 318, 306, 313, 308, 318, 324, 325, 380, 357, 349, 360, 364, 259, 251, 250, 252, 246, 239, 249, 236, 246, 239, 201, 226, 234, 244, 242, 245, 238, 248, 246, 238, 233, 294, 423, 444, 413, 402, 410, 398, 403, 425, 411, 409, 386, 418, 396, 421, 369, 281, 266, 282, 283, 278, 259, 237, 250, 249, 263, 263, 264, 273, 266, 261, 278, 266, 287, 261, 270, 282, 264, 256, 268, 257, 255, 269, 379, 359, 375, 384, 365, 345, 274, 231, 275, 280, 285, 279, 266, 281, 280, 262, 288, 281, 266, 263, 283, 266, 324, 370, 380, 371, 379, 372, 376, 377, 361, 377, 371, 369, 357, 366, 362, 361, 362, 347, 367, 364, 369, 338, 331, 356, 343, 356, 331, 336, 328, 327, 307, 325, 322, 313, 313, 324, 326, 296, 358, 369, 368, 376, 376, 384, 385, 382, 368, 345, 348, 366, 374, 369, 365, 361, 362, 379, 372, 383, 361, 372, 362, 371, 367, 364, 384, 379, 380, 368, 383, 388, 372, 377, 359, 367, 307, 324, 296, 276, 294, 288, 307, 302, 292, 309, 264, 260, 187, 232, 251, 237, 209, 213, 211, 207, 202, 208, 198, 205, 212, 198, 206, 204, 230, 212, 226, 226, 235, 228, 224, 209, 216, 236, 200, 210, 202, 205, 220, 214, 201, 227, 243, 281, 281, 257, 267, 340, 337, 347, 335, 357, 341, 322, 327, 310, 321, 324, 295, 271, 288, 290, 286, 254, 255, 259, 239, 238, 229, 219, 227, 224, 234, 192, 199, 186, 221, 206, 201, 216, 225, 220, 200, 208, 228, 211, 200, 211, 205, 196, 185, 202, 223, 187, 199, 204, 196, 201, 198, 326, 390, 415, 393, 400, 400, 393, 391, 393, 354, 374, 352, 372, 364, 369, 371, 372, 354, 354, 315, 250, 296, 442, 426, 440, 452, 439, 435, 399, 371, 366, 381, 353, 363, 347, 347, 353, 361, 365, 336, 347, 358, 344, 357, 270, 284, 267, 270, 254, 255, 258, 253, 261, 281, 262, 251, 264, 273, 275, 271, 259, 244, 264, 263, 272, 264, 271, 249, 247, 252, 240, 247, 241, 242, 291, 291, 292, 291, 293, 287, 356, 402, 401, 413, 381, 405, 403, 402, 399, 413, 401, 390, 362, 358, 365, 336, 324, 365, 361, 352, 363, 331, 356, 343, 344, 343, 336, 342, 346, 348, 343, 310, 273, 273, 269, 271, 332, 321, 468, 387, 382, 295, 265, 268, 256, 256, 259, 248, 271, 344, 399, 373, 356, 372, 375, 377, 382, 365, 371, 368, 352, 381, 347, 297, 298, 285, 286, 294, 282, 280, 276, 269, 280, 274, 270, 278, 353, 338, 339, 336, 376, 377, 396, 391, 387, 390, 401, 405, 384, 375, 374, 394, 387, 391, 387, 380, 381, 384, 376, 368, 334, 321, 330, 342, 313, 329, 315, 323, 322, 328, 317, 308, 308, 333, 312, 314, 325, 370, 390, 368, 384, 405, 371, 362, 310, 300, 287, 282, 279, 271, 284, 288, 234, 187, 204, 201, 204, 211, 224, 234, 215, 240, 224, 212, 215, 231, 237, 238, 232, 226, 220, 224, 234, 218, 223, 226, 223, 233, 237, 231, 230, 223, 221, 224, 232, 229, 226, 226, 218, 235, 232, 224, 211, 219, 210, 211, 220, 221, 232, 231, 237, 261, 249, 260, 246, 242, 250, 265, 248, 236, 204, 221, 203, 207, 200, 200, 204, 199, 192, 203, 182, 222, 219, 230, 249, 427, 416, 445, 423, 423, 417, 427, 435, 448, 403, 296, 233, 423, 422, 415, 392, 408, 380, 386, 387, 391, 421, 405, 400, 283, 259, 247, 262, 267, 265, 272, 286, 379, 388, 364, 378, 371, 388, 333, 302, 301, 284, 233, 238, 251, 238, 240, 226, 237, 226, 236, 208, 208, 252, 227, 240, 259, 234, 230, 229, 244, 225, 251, 232, 273, 265, 280, 288, 268, 272, 318, 330, 345, 331, 337, 319, 334, 351, 419, 416, 414, 395, 422, 410, 416, 413, 362, 331, 329, 310, 306, 346, 322, 307, 340, 329, 373, 428, 435, 433, 438, 408, 415, 429, 424, 406, 425, 423, 413, 424, 399, 420, 426, 431, 414, 397, 362, 353, 357, 354, 362, 345, 357, 353, 363, 347, 352, 354, 350, 353, 393, 340, 358, 355, 358, 371, 368, 388, 386, 376, 394, 371, 367, 364, 379, 362, 346, 367, 363, 377, 367, 357, 358, 368, 351, 380, 371, 380, 390, 326, 315, 312, 293, 298, 303, 291, 320, 296, 294, 259, 247, 248, 248, 260, 273, 245, 250, 254, 235, 245, 234, 238, 229, 246, 254, 240, 252, 236, 239, 246, 221, 246, 245, 238, 235, 249, 241, 245, 242, 234, 264, 266, 265, 265, 264, 266, 257, 252, 256, 246, 276, 275, 273, 270, 304, 375, 371, 356, 349, 347, 346, 321, 330, 324, 332, 319, 324, 378, 404, 396, 398, 411, 396, 417, 376, 331, 321, 331, 300, 302, 298, 311, 328, 291, 313, 298, 294, 312, 327, 299, 295, 297, 244, 239, 256, 223, 234, 223, 235, 229, 225, 214, 226, 186, 198, 193, 199, 196, 222, 219, 228, 236, 238, 239, 219, 200, 212, 216, 215, 200, 205, 203, 231, 225, 208, 257, 277, 265, 267, 265, 281, 258, 266, 275, 272, 271, 280, 276, 270, 284, 279, 355, 387, 371, 365, 297, 284, 244, 266, 264, 260, 265, 263, 264, 258, 254, 249, 257, 262, 240, 225, 221, 213, 211, 217, 216, 218, 229, 236, 216, 208, 216, 215, 228, 229, 277, 255, 244, 237, 230, 262, 238, 240, 257, 243, 228, 250, 253, 250, 254, 233, 236, 246, 249, 254, 227, 235, 228, 236, 228, 238, 213, 247, 229, 217, 216, 229, 241, 236, 225, 245, 225, 217, 233, 235, 244, 285, 281, 305, 368, 368, 365, 368, 366, 369, 357, 330, 328, 308, 306, 320, 321, 424, 433, 421, 440, 418, 422, 375, 374, 343, 359, 350, 338, 348, 353, 341, 319, 326, 330, 317, 302, 350, 414, 415, 398, 423, 385, 382, 380, 375, 376, 318, 299, 289, 284, 271, 288, 288, 275, 255, 244, 240, 272, 235, 261, 244, 246, 236, 222, 237, 192, 156, 158, 175, 161, 159, 170, 157, 159, 173, 161, 146, 180, 159, 154, 196, 229, 248, 204, 221, 243, 210, 215, 193, 220, 210, 393, 444, 449, 443, 432, 438, 397, 376, 374, 381, 365, 369, 376, 353, 385, 367, 365, 377, 377, 371, 319, 293, 306, 294, 302, 297, 314, 293, 269, 285, 285, 250, 246, 230, 250, 250, 250, 242, 243, 233, 222, 267, 246, 236, 247, 266, 260, 256, 257, 249, 246, 227, 236, 230, 233, 222, 212, 215, 213, 218, 206, 218, 222, 223, 194, 204, 202, 219, 204, 228, 214, 234, 230, 223, 220, 229, 215, 227, 215, 211, 224, 223, 209, 181, 216, 234, 225, 208, 214, 204, 219, 214, 212, 224, 257, 260, 249, 254, 257, 269, 270, 262, 329, 330, 350, 331, 338, 340, 349, 332, 346, 353, 349, 350, 349, 367, 322, 320, 314, 301, 272, 262, 255, 222, 226, 236, 205, 204, 189, 208, 241, 238, 237, 244, 238, 236, 232, 248, 241, 249, 257, 320, 303, 312, 306, 311, 299, 360, 365, 373, 356, 353, 345, 350, 361, 333, 331, 352, 327, 314, 296, 295, 312, 308, 284, 296, 299, 343, 377, 371, 353, 378, 373, 382, 379, 363, 362, 368, 352, 359, 352, 341, 360, 345, 359, 357, 338, 337, 348, 348, 369, 349, 347, 383, 355, 333, 356, 353, 371, 338, 339, 354, 344, 349, 352, 333, 351, 348, 351, 327, 270, 284, 251, 234, 260, 258, 281, 257, 172, 172, 213, 198, 202, 217, 217, 215, 224, 248, 242, 225, 236, 260, 353, 311, 290, 309, 297, 295, 350, 406, 416, 376, 391, 348, 371, 372, 335, 307, 278, 228, 226, 246, 236, 240, 229, 242, 359, 416, 415, 396, 395, 402, 357, 273, 256, 249, 246, 331, 374, 364, 372, 332, 371, 361, 362, 372, 385, 352, 367, 373, 300, 292, 266, 285, 306, 297, 273, 291, 259, 247, 252, 279, 272, 281, 315, 311, 323, 336, 352, 368, 361, 390, 369, 372, 349, 281, 294, 280, 276, 292, 313, 253, 253, 245, 231, 189, 203, 196, 189, 207, 188, 207, 244, 268, 259, 257, 307, 315, 325, 332, 316, 283, 317, 306, 307, 311, 319, 327, 326, 365, 425, 429, 441, 401, 422, 419, 416, 421, 403, 427, 412, 419, 423, 425, 425, 374, 361, 366, 358, 340, 342, 332, 255, 223, 223, 237, 235, 207, 219, 208, 199, 211, 212, 230, 205, 301, 364, 359, 352, 349, 281, 272, 253, 258, 294, 249, 263, 254, 262, 275, 232, 260, 255, 260, 281, 250, 245, 256, 262, 287, 280, 256, 245, 302, 315, 256, 250, 261, 261, 253, 269, 264, 257, 265, 254, 270, 345, 330, 332, 342, 342, 337, 337, 334, 329, 338, 319, 320, 323, 331, 327, 334, 299, 281, 292, 310, 296, 298, 302, 330, 315, 308, 306, 305, 309, 302, 328, 316, 307, 301, 372, 439, 439, 410, 392, 331, 339, 339, 312, 329, 286, 322, 309, 317, 315, 308, 335, 315, 300, 370, 370, 392, 389, 374, 368, 377, 380, 371, 391, 378, 370, 376, 367, 353, 377, 376, 375, 366, 370, 367, 364, 356, 363, 354, 361, 365, 356, 331, 293, 294, 294, 299, 303, 288, 297, 294, 300, 293, 298, 302, 296, 297, 293, 287, 310, 271, 300, 289, 297, 279, 313, 327, 355, 366, 355, 351, 317, 303, 309, 328, 354, 363, 355, 376, 353, 351, 354, 360, 348, 355, 360, 352, 338, 363, 345, 358, 340, 358, 344, 349, 355, 349, 348, 348, 341, 355, 343, 350, 350, 343, 347, 360, 365, 366, 339, 346, 359, 355, 295, 299, 307, 285, 287, 303, 290, 295, 301, 278, 277, 250, 262, 266, 300, 271, 274, 222, 246, 245, 231, 232, 210, 216, 238, 257, 253, 252, 255, 256, 282, 272, 245, 305, 318, 324, 325, 352, 385, 398, 369, 374, 387, 382, 383, 363, 372, 355, 351, 360, 359, 358, 299, 298, 298, 308, 314, 302, 320, 312, 311, 305, 300, 286, 312, 294, 304, 306, 296, 295, 310, 290, 294, 285, 291, 285, 304, 285, 284, 287, 303, 323, 340, 331, 326, 323, 319, 319, 313, 323, 320, 309, 324, 316, 317, 328, 329, 326, 343, 397, 380, 376, 368, 388, 379, 391, 401, 398, 377, 399, 378, 384, 370, 401, 409, 384, 408, 357, 382, 370, 380, 374, 374, 323, 314, 337, 318, 335, 348, 380, 386, 379, 375, 370, 323, 303, 290, 305, 314, 346, 339, 342, 322, 324, 324, 338, 353, 389, 371, 373, 379, 362, 370, 357, 314, 323, 321, 332, 377, 384, 392, 381, 391, 378, 382, 385, 363, 356, 366, 359, 364, 376, 355, 359, 361, 358, 349, 365, 344, 344, 364, 331, 340, 341, 313, 269, 279, 254, 197, 196, 196, 219, 216, 214, 212, 190, 193, 204, 199, 210, 194, 211, 201, 190, 197, 196, 203, 180, 209, 210, 190, 193, 191, 192, 225, 259, 256, 277, 360, 368, 364, 347, 335, 334, 345, 341, 346, 339, 340, 307, 318, 321, 322, 327, 318, 315, 456, 457, 443, 450, 467, 428, 435, 458, 429, 438, 362, 366, 370, 369, 370, 365, 363, 363, 353, 358, 359, 359, 372, 364, 380, 376, 361, 375, 347, 419, 326, 345, 334, 351, 351, 359, 354, 358, 353, 336, 347, 358, 363, 354, 344, 353, 346, 356, 327, 326, 357, 354, 332, 359, 347, 347, 334, 325, 326, 325, 319, 307, 321, 322, 369, 352, 349, 354, 364, 345, 337, 348, 342, 355, 358, 343, 332, 329, 321, 305, 311, 294, 310, 310, 318, 305, 345, 356, 350, 344, 347, 342, 327, 344, 333, 326, 323, 324, 354, 382, 390, 380, 395, 394, 384, 400, 376, 370, 376, 374, 307, 318, 308, 303, 318, 331, 326, 364, 370, 376, 351, 364, 366, 348, 342, 338, 321, 308, 436, 427, 427, 410, 426, 410, 430, 432, 424, 417, 419, 423, 432, 431, 426, 423, 419, 387, 360, 359, 343, 362, 345, 352, 363, 358, 357, 351, 358, 353, 361, 375, 386, 362, 367, 381, 341, 325, 345, 318, 337, 335, 337, 334, 342, 339, 331, 331, 329, 345, 310, 272, 277, 284, 263, 289, 251, 266, 264, 256, 324, 393, 388, 384, 371, 364, 293, 279, 282, 277, 294, 285, 276, 275, 290, 286, 302, 333, 352, 337, 324, 356, 346, 343, 326, 352, 329, 324, 320, 315, 307, 314, 301, 308, 305, 292, 300, 302, 308, 322, 372, 364, 353, 345, 353, 349, 333, 357, 357, 339, 348, 309, 283, 275, 274, 256, 270, 230, 249, 229, 217, 236, 234, 243, 223, 226, 243, 248, 218, 225, 239, 234, 226, 223, 233, 216, 230, 221, 215, 215, 212, 225, 197, 199, 186, 200, 199, 245, 224, 223, 230, 223, 249, 229, 227, 237, 229, 226, 248, 239, 239, 248, 245, 252, 224, 234, 222, 242, 216, 224, 215, 215, 243, 218, 224, 232, 249, 227, 240, 234, 219, 185, 194, 174, 167, 211, 202, 194, 190, 200, 257, 282, 268, 256, 268, 306, 311, 396, 377, 379, 381, 408, 385, 331, 296, 301, 301, 305, 313, 295, 274, 289, 286, 295, 291, 304, 305, 295, 303, 294, 262, 261, 263, 283, 291, 278, 247, 253, 243, 241, 227, 231, 227, 224, 229, 231, 231, 227, 237, 245, 239, 241, 246, 206, 222, 225, 224, 251, 308, 301, 289, 307, 310, 325, 299, 328, 393, 388, 388, 388, 369, 392, 390, 349, 352, 358, 367, 366, 366, 365, 368, 359, 357, 337, 342, 336, 335, 325, 327, 450, 467, 458, 456, 417, 454, 439, 451, 471, 451, 470, 455, 434, 443, 446, 453, 430, 445, 444, 449, 454, 447, 450, 444, 446, 367, 512, 460, 450, 439, 438, 454, 442, 446, 438, 441, 430, 406, 381, 365, 374, 349, 265, 261, 263, 242, 255, 251, 250, 263, 259, 249, 249, 263, 254, 250, 268, 264, 257, 270, 268, 255, 271, 309, 383, 385, 384, 389, 380, 394, 395, 383, 388, 396, 289, 323, 282, 260, 369, 383, 377, 393, 387, 376, 359, 367, 353, 345, 345, 346, 361, 349, 303, 276, 261, 271, 212, 233, 209, 225, 216, 200, 236, 242, 248, 250, 307, 349, 357, 350, 356, 364, 366, 351, 347, 340, 355, 335, 338, 336, 351, 341, 336, 337, 339, 339, 343, 330, 342, 333, 330, 342, 341, 314, 303, 313, 311, 406, 427, 433, 437, 425, 420, 453, 424, 429, 440, 381, 356, 343, 342, 332, 305, 326, 314, 295, 321, 309, 303, 319, 377, 380, 381, 383, 375, 400, 389, 354, 380, 330, 295, 309, 306, 285, 333, 336, 360, 332, 340, 345, 338, 357, 351, 357, 355, 349, 349, 369, 365, 371, 357, 364, 355, 367, 361, 343, 337, 341, 342, 336, 347, 333, 350, 327, 338, 320, 314, 321, 318, 310, 292, 301, 309, 305, 322, 338, 337, 372, 397, 428, 407, 384, 362, 381, 382, 375, 376, 312, 319, 307, 311, 327, 393, 417, 416, 397, 409, 404, 420, 435, 411, 422, 410, 351, 335, 327, 324, 355, 384, 362, 366, 372, 369, 366, 305, 311, 303, 359, 311, 301, 293, 301, 312, 299, 299, 308, 305, 311, 298, 311, 289, 321, 321, 331, 329, 332, 334, 355, 319, 306, 287, 270, 304, 312, 305, 402, 405, 424, 349, 343, 342, 346, 344, 354, 350, 335, 344, 337, 345, 342, 327, 331, 318, 328, 332, 342, 326, 308, 317, 314, 303, 297, 305, 304, 311, 303, 326, 294, 359, 383, 390, 399, 389, 380, 387, 377, 394, 376, 383, 376, 278, 325, 333, 330, 325, 313, 310, 315, 306, 301, 306, 392, 321, 329, 301, 321, 322, 325, 301, 302, 320, 344, 356, 338, 366, 370, 358, 361, 360, 376, 373, 364, 355, 373, 357, 364, 355, 352, 377, 373, 360, 363, 362, 322, 299, 267, 325, 302, 291, 298, 301, 330, 313, 284, 259, 257, 257, 291, 263, 239, 232, 207, 215, 222, 221, 206, 224, 218, 205, 226, 215, 207, 208, 198, 217, 210, 192, 210, 211, 243, 254, 251, 260, 245, 275, 341, 344, 334, 325, 345, 333, 337, 336, 329, 342, 353, 368, 379, 391, 370, 346, 367, 354, 342, 352, 332, 354, 335, 325, 331, 346, 338, 334, 283, 285, 299, 307, 319, 289, 294, 248, 263, 229, 239, 228, 232, 235, 238, 255, 236, 244, 269, 262, 269, 279, 283, 286, 272, 282, 309, 357, 360, 372, 372, 364, 372, 359, 360, 356, 356, 358, 373, 381, 385, 401, 348, 393, 392, 331, 298, 291, 275, 260, 259, 276, 259, 272, 266, 262, 264, 249, 263, 276, 259, 286, 258, 266, 272, 276, 258, 266, 282, 272, 281, 277, 267, 276, 284, 277, 275, 273, 288, 294, 277, 281, 280, 313, 362, 329, 369, 346, 361, 364, 337, 339, 343, 395, 400, 312, 311, 299, 308, 282, 234, 228, 231, 247, 231, 236, 226, 239, 228, 233, 240, 232, 226, 236, 226, 226, 373, 459, 439, 448, 462, 446, 454, 444, 441, 444, 374, 370, 359, 354, 319, 316, 307, 305, 324, 314, 311, 322, 303, 304, 288, 301, 315, 268, 285, 269, 270, 273, 284, 317, 265, 291, 275, 261, 254, 258, 265, 254, 288, 254, 251, 253, 266, 253, 244, 262, 250, 257, 247, 276, 304, 280, 286, 275, 240, 256, 247, 239, 233, 294, 300, 285, 294, 285, 302, 288, 295, 369, 367, 352, 354, 396, 385, 381, 385, 371, 385, 380, 372, 321, 325, 306, 306, 297, 292, 288, 271, 268, 295, 248, 228, 219, 231, 226, 245, 245, 225, 227, 244, 235, 245, 230, 237, 230, 231, 232, 228, 232, 193, 212, 185, 196, 192, 235, 214, 215, 217, 227, 238, 243, 228, 261, 246, 244, 257, 294, 310, 335, 326, 334, 351, 345, 325, 332, 338, 327, 349, 352, 354, 335, 333, 346, 316, 319, 321, 326, 335, 325, 334, 336, 328, 328, 330, 320, 334, 319, 335, 325, 332, 315, 327, 291, 281, 281, 264, 268, 281, 263, 258, 264, 263, 250, 265, 259, 261, 257, 259, 263, 242, 271, 310, 443, 446, 451, 432, 444, 465, 441, 439, 451, 426, 370, 365, 369, 355, 369, 360, 395, 359, 379, 362, 315, 306, 294, 316, 300, 291, 293, 296, 302, 302, 296, 294, 296, 279, 287, 284, 286, 229, 249, 207, 186, 198, 198, 203, 202, 203, 197, 197, 373, 372, 367, 379, 374, 358, 303, 298, 298, 306, 309, 315, 271, 300, 286, 291, 294, 287, 283, 283, 278, 266, 216, 205, 199, 232, 227, 221, 228, 245, 240, 238, 246, 224, 222, 232, 264, 270, 274, 271, 274, 318, 338, 361, 345, 342, 355, 336, 260, 234, 248, 237, 252, 247, 263, 251, 264, 264, 281, 278, 275, 275, 292, 273, 269, 277, 270, 296, 257, 336, 346, 332, 306, 225, 235, 244, 221, 207, 222, 230, 227, 233, 225, 221, 218, 226, 221, 232, 218, 215, 218, 240, 237, 235, 216, 239, 217, 245, 223, 233, 329, 412, 404, 434, 412, 410, 433, 432, 399, 402, 418, 320, 277, 276, 281, 279, 292, 273, 348, 418, 378, 396, 385, 372, 385, 394, 361, 367, 392, 373, 253, 258, 243, 257, 246, 255, 247, 464, 455, 440, 433, 444, 451, 447, 436, 441, 437, 376, 350, 355, 344, 337, 350, 357, 353, 353, 344, 353, 344, 282, 266, 284, 276, 276, 279, 257, 272, 273, 269, 274, 260, 273, 271, 278, 283, 267, 282, 287, 264, 316, 379, 358, 331, 353, 355, 342, 344, 350, 345, 361, 367, 378, 379, 407, 303, 275, 269, 262, 258, 261, 260, 270, 276, 239, 238, 311, 380, 396, 368, 387, 403, 388, 384, 367, 380, 358, 343, 249, 236, 234, 218, 360, 312, 369, 341, 363, 356, 367, 361, 348, 360, 358, 396, 393, 416, 421, 363, 352, 363, 357, 340, 353, 345, 334, 333, 364, 389, 393, 375, 375, 345, 311, 282, 295, 247, 244, 256, 208, 215, 204, 220, 221, 225, 223, 219, 233, 212, 213, 219, 266, 270, 232, 223, 223, 242, 242, 241, 245, 243, 230, 212, 214, 218, 226, 226, 213, 215, 237, 228, 255, 238, 241, 241, 251, 243, 248, 254, 249, 250, 234, 257, 290, 287, 302, 302, 306, 325, 316, 319, 321, 315, 399, 418, 425, 433, 408, 417, 391, 399, 420, 397, 392, 362, 342, 331, 352, 360, 367, 331, 342, 327, 311, 314, 334, 344, 340, 350, 327, 354, 329, 322, 329, 329, 314, 336, 323, 326, 354, 329, 323, 381, 398, 401, 384, 398, 388, 383, 366, 369, 383, 378, 348, 281, 253, 253, 260, 287, 276, 261, 252, 266, 271, 263, 243, 239, 253, 268, 252, 246, 221, 215, 195, 224, 187, 347, 367, 352, 349, 321, 331, 341, 348, 333, 304, 330, 334, 332, 340, 334, 329, 331, 336, 319, 255, 251, 245, 232, 232, 237, 223, 227, 228, 329, 340, 356, 342, 351, 300, 296, 296, 267, 276, 297, 293, 318, 320, 311, 336, 327, 312, 280, 256, 250, 257, 242, 259, 254, 250, 294, 295, 302, 311, 322, 302, 313, 297, 301, 353, 429, 414, 407, 416, 405, 421, 439, 417, 422, 414, 387, 383, 380, 376, 368, 319, 292, 306, 281, 265, 265, 261, 198, 195, 188, 200, 212, 225, 209, 208, 229, 202, 206, 197, 206, 217, 228, 217, 224, 211, 263, 461, 441, 454, 443, 440, 428, 384, 357, 344, 326, 280, 287, 307, 260, 276, 269, 278, 282, 253, 266, 270, 272, 272, 310, 305, 314, 307, 301, 307, 311, 310, 364, 432, 395, 412, 418, 403, 403, 403, 417, 414, 412, 386, 415, 422, 408, 394, 349, 354, 333, 336, 361, 340, 355, 342, 336, 334, 351, 342, 350, 347, 346, 339, 357, 344, 335, 352, 368, 352, 371, 338, 355, 337, 343, 309, 321, 309, 312, 317, 317, 306, 320, 315, 307, 413, 423, 438, 431, 419, 430, 431, 433, 431, 437, 392, 407, 348, 357, 338, 351, 362, 349, 350, 343, 371, 348, 351, 355, 358, 368, 364, 359, 346, 333, 335, 321, 321, 329, 340, 334, 324, 323, 311, 333, 331, 334, 323, 330, 304, 253, 274, 268, 283, 278, 280, 260, 275, 326, 433, 446, 442, 448, 454, 412, 413, 439, 374, 331, 309, 326, 318, 323, 321, 312, 289, 330, 326, 385, 428, 416, 412, 409, 365, 378, 351, 353, 362, 373, 335, 339, 345, 349, 331, 341, 350, 348, 357, 343, 369, 386, 363, 408, 381, 377, 383, 377, 368, 381, 367, 353, 361, 353, 357, 356, 361, 357, 353, 360, 368, 353, 378, 376, 380, 368, 373, 391, 319, 296, 263, 235, 210, 228, 214, 231, 227, 223, 221, 224, 220, 224, 230, 241, 238, 225, 240, 234, 395, 464, 376, 372, 354, 340, 334, 333, 333, 336, 335, 340, 336, 344, 322, 316, 326, 311, 310, 308, 380, 359, 378, 380, 366, 355, 360, 362, 376, 360, 353, 366, 363, 352, 340, 335, 342, 335, 325, 319, 316, 322, 300, 305, 324, 314, 363, 381, 376, 381, 377, 372, 372, 374, 366, 389, 363, 343, 354, 314, 344, 332, 303, 334, 342, 346, 326, 333, 331, 343, 315, 315, 291, 294, 326, 382, 370, 357, 349, 368, 365, 340, 360, 361, 362, 355, 348, 359, 357, 358, 353, 355, 349, 360, 374, 376, 360, 360, 376, 393, 356, 347, 339, 333, 357, 347, 332, 297, 276, 277, 246, 249, 251, 275, 253, 249, 211, 222, 210, 223, 222, 205, 219, 225, 339, 347, 365, 369, 341, 342, 366, 339, 342, 332, 328, 323, 348, 345, 368, 332, 353, 329, 341, 341, 341, 353, 331, 322, 308, 317, 307, 304, 306, 304, 316, 295, 303, 312, 300, 301, 306, 295, 312, 299, 311, 296, 308, 304, 292, 315, 314, 339, 327, 294, 297, 301, 310, 345, 352, 377, 369, 374, 364, 382, 371, 386, 345, 342, 359, 351, 345, 348, 360, 367, 348, 361, 351, 349, 342, 352, 355, 334, 357, 351, 334, 312, 316, 302, 303, 306, 311, 326, 314, 368, 407, 394, 400, 358, 369, 302, 311, 290, 306, 295, 291, 303, 260, 276, 294, 282, 283, 269, 273, 292, 283, 263, 277, 270, 283, 293, 359, 339, 352, 350, 342, 351, 346, 363, 370, 338, 350, 317, 306, 308, 286, 284, 263, 257, 256, 232, 238, 232, 236, 237, 231, 242, 229, 185, 193, 221, 203, 210, 190, 195, 224, 210, 253, 261, 259, 255, 249, 262, 260, 247, 329, 353, 336, 335, 348, 333, 276, 263, 280, 272, 281, 282, 264, 366, 363, 353, 356, 365, 358, 365, 365, 337, 339, 340, 350, 359, 340, 342, 355, 368, 372, 369, 401, 396, 418, 385, 398, 398, 403, 384, 387, 394, 399, 397, 375, 374, 388, 383, 361, 331, 312, 321, 321, 315, 329, 309, 316, 318, 319, 389, 396, 378, 379, 391, 394, 361, 288, 279, 269, 287, 283, 264, 272, 296, 288, 296, 277, 299, 211, 209, 209, 196, 210, 193, 221, 209, 201, 209, 213, 213, 208, 211, 213, 215, 302, 377, 396, 351, 371, 364, 355, 355, 284, 373, 358, 360, 285, 261, 257, 267, 271, 243, 272, 266, 256, 246, 278, 266, 272, 293, 280, 277, 306, 296, 281, 272, 290, 275, 286, 280, 283, 294, 286, 277, 286, 292, 335, 366, 348, 350, 362, 363, 367, 265, 269, 279, 277, 270, 267, 279, 289, 280, 293, 274, 295, 285, 297, 346, 357, 355, 337, 347, 330, 297, 330, 310, 312, 333, 326, 322, 319, 322, 303, 302, 323, 333, 330, 321, 291, 273, 287, 298, 293, 289, 288, 301, 285, 304, 291, 293, 290, 270, 284, 313, 340, 338, 329, 320, 325, 336, 328, 339, 350, 372, 380, 365, 359, 325, 368, 363, 364, 374, 374, 413, 369, 348, 372, 336, 339, 338, 346, 338, 342, 337, 338, 343, 361, 368, 452, 347, 416, 347, 345, 352, 350, 352, 345, 345, 334, 324, 336, 336, 332, 320, 314, 321, 386, 381, 364, 368, 364, 382, 347, 278, 275, 261, 242, 240, 229, 226, 241, 223, 238, 267, 247, 229, 231, 228, 224, 226, 225, 220, 225, 211, 234, 238, 247, 245, 239, 259, 248, 243, 248, 265, 230, 236, 230, 250, 235, 236, 245, 216, 195, 188, 194, 181, 184, 203, 195, 201, 199, 197, 228, 273, 271, 273, 233, 294, 279, 275, 277, 270, 282, 275, 273, 268, 286, 280, 267, 318, 374, 372, 361, 361, 329, 312, 248, 275, 262, 247, 261, 267, 251, 262, 253, 238, 256, 254, 256, 256, 248, 248, 244, 237, 258, 256, 248, 241, 245, 256, 243, 248, 240, 242, 247, 243, 216, 222, 213, 214, 213, 214, 203, 209, 211, 222, 203, 202, 216, 209, 195, 272, 283, 296, 272, 272, 283, 320, 361, 347, 346, 281, 266, 257, 242, 240, 246, 257, 248, 259, 256, 262, 287, 352, 375, 368, 345, 376, 367, 360, 339, 339, 331, 334, 334, 350, 338, 338, 326, 335, 342, 315, 332, 389, 400, 382, 390, 383, 381, 380, 396, 378, 383, 323, 292, 289, 259, 285, 272, 251, 208, 215, 226, 202, 221, 235, 259, 260, 252, 277, 263, 243, 264, 258, 372, 374, 360, 358, 370, 356, 366, 351, 260, 280, 295, 361, 362, 359, 398, 387, 406, 357, 349, 343, 332, 356, 338, 338, 294, 300, 288, 300, 292, 296, 295, 297, 288, 295, 272, 354, 378, 379, 388, 369, 372, 364, 362, 366, 361, 353, 359, 359, 360, 357, 376, 358, 302, 296, 356, 296, 294, 261, 257, 256, 262, 259, 283, 305, 329, 306, 324, 308, 318, 306, 334, 376, 320, 341, 371, 366, 356, 380, 366, 337, 326, 364, 382, 365, 348, 344, 366, 384, 365, 358, 369, 349, 345, 343, 344, 344, 297, 266, 264, 296, 267, 274, 267, 269, 272, 241, 269, 276, 256, 260, 248, 250, 262, 269, 258, 260, 246, 311, 384, 382, 384, 390, 375, 390, 367, 352, 339, 302, 298, 285, 308, 285, 272, 265, 307, 289, 295, 278, 295, 301, 274, 293, 296, 289, 278, 283, 291, 276, 245, 224, 194, 220, 245, 238, 232, 219, 233, 228, 212, 219, 216, 212, 222, 221, 219, 220, 221, 200, 202, 184, 180, 191, 201, 184, 223, 386, 395, 377, 369, 393, 382, 383, 385, 378, 399, 375, 328, 288, 277, 278, 238, 243, 241, 219, 239, 250, 229, 246, 245, 238, 227, 233, 242, 265, 242, 237, 230, 233, 237, 242, 227, 223, 210, 202, 220, 221, 212, 215, 206, 198, 212, 201, 202, 197, 199, 195, 184, 255, 287, 276, 279, 271, 352, 347, 361, 339, 360, 355, 343, 348, 349, 349, 359, 358, 371, 363, 366, 364, 348, 344, 348, 361, 357, 363, 341, 343, 334, 338, 356, 354, 356, 379, 360, 353, 348, 345, 356, 352, 329, 344, 364, 358, 303, 293, 245, 232, 229, 211, 231, 246, 246, 239, 240, 257, 243, 250, 247, 249, 258, 320, 319, 328, 323, 307, 316, 321, 312, 313, 307, 304, 316, 326, 310, 322, 345, 415, 409, 384, 329, 346, 304, 293, 286, 307, 290, 307, 287, 294, 283, 289, 318, 297, 298, 330, 273, 291, 275, 305, 289, 276, 272, 289, 277, 353, 365, 337, 356, 371, 384, 379, 381, 351, 379, 345, 347, 356, 327, 294, 299, 295, 295, 244, 324, 271, 244, 277, 254, 241, 242, 246, 240, 267, 259, 296, 352, 338, 330, 348, 326, 338, 334, 331, 320, 331, 323, 336, 343, 336, 346, 350, 351, 338, 354, 337, 353, 359, 343, 330, 333, 357, 335, 349, 335, 351, 342, 351, 364, 345, 337, 335, 345, 341, 335, 350, 333, 353, 362, 371, 374, 366, 345, 321, 324, 332, 337, 360, 369, 404, 418, 417, 424, 428, 405, 427, 438, 423, 393, 398, 391, 417, 411, 393, 393, 367, 363, 349, 367, 354, 339, 338, 344, 328, 330, 310, 315, 310, 323, 314, 317, 332, 328, 321, 439, 447, 432, 430, 446, 420, 396, 362, 355, 327, 330, 315, 315, 319, 333, 317, 339, 302, 306, 286, 342, 333, 326, 277, 256, 257, 251, 327, 295, 241, 249, 260, 233, 276, 379, 372, 241, 230, 231, 229, 227, 227, 392, 335, 356, 349, 378, 311, 294, 300, 314, 287, 290, 296, 295, 318, 375, 366, 371, 372, 378, 356, 378, 356, 364, 380, 367, 372, 369, 330, 357, 371, 375, 337, 331, 337, 341, 318, 337, 341, 319, 330, 320, 257, 243, 238, 222, 213, 216, 368, 409, 411, 416, 396, 383, 378, 401, 395, 403, 399, 400, 406, 399, 393, 405, 373, 371, 348, 344, 361, 329, 331, 335, 299, 292, 276, 300, 285, 301, 291, 286, 310, 315, 275, 264, 265, 267, 272, 246, 231, 227, 238, 240, 234, 230, 241, 179, 194, 195, 197, 198, 216, 184, 190, 242, 269, 290, 273, 282, 264, 306, 312, 270, 268, 261, 262, 267, 258, 269, 274, 253, 277, 255, 263, 318, 363, 380, 380, 366, 365, 357, 378, 374, 380, 357, 369, 360, 353, 356, 368, 363, 382, 355, 368, 375, 377, 373, 387, 379, 397, 385, 383, 373, 364, 398, 362, 381, 365, 349, 365, 362, 367, 328, 330, 332, 320, 321, 331, 322, 319, 327, 326, 336, 309, 325, 315, 346, 348, 346, 345, 345, 362, 347, 343, 372, 370, 356, 368, 359, 369, 361, 352, 382, 367, 361, 363, 356, 368, 365, 368, 365, 370, 362, 369, 371, 369, 371, 356, 349, 368, 366, 368, 323, 323, 341, 322, 339, 337, 333, 333, 337, 348, 362, 333, 354, 336, 353, 343, 338, 334, 316, 289, 288, 287, 290, 298, 281, 291, 273, 291, 274, 277, 369, 380, 403, 306, 304, 293, 310, 308, 303, 320, 293, 206, 221, 216, 213, 223, 216, 214, 222, 222, 227, 230, 246, 238, 246, 289, 319, 325, 314, 296, 279, 278, 277, 311, 334, 332, 338, 315, 342, 338, 334, 321, 361, 375, 403, 396, 365, 393, 366, 378, 300, 282, 282, 290, 304, 300, 301, 286, 281, 274, 297, 284, 286, 307, 302, 297, 291, 276, 287, 278, 285, 298, 302, 286, 292, 301, 312, 289, 322, 371, 393, 376, 380, 372, 296, 291, 268, 268, 290, 275, 281, 267, 276, 277, 284, 289, 270, 258, 253, 322, 329, 330, 336, 314, 308, 307, 302, 304, 297, 318, 351, 356, 351, 366, 367, 363, 347, 359, 368, 345, 352, 352, 367, 375, 366, 350, 363, 348, 349, 362, 375, 367, 379, 376, 373, 370, 369, 367, 371, 378, 365, 369, 354, 362, 344, 351, 353, 343, 269, 274, 269, 284, 262, 254, 260, 292, 291, 280, 275, 281, 383, 366, 373, 370, 369, 370, 373, 316, 275, 293, 273, 257, 328, 229, 208, 216, 221, 217, 209, 205, 218, 218, 232, 261, 265, 247, 233, 267, 276, 275, 362, 359, 365, 378, 372, 364, 371, 371, 382, 366, 354, 352, 356, 333, 348, 345, 346, 347, 353, 351, 359, 354, 364, 351, 367, 356, 370, 370, 350, 349, 370, 372, 354, 371, 355, 386, 377, 357, 363, 379, 374, 386, 361, 364, 344, 359, 366, 355, 349, 355, 352, 331, 334, 362, 354, 365, 366, 365, 372, 379, 383, 372, 366, 370, 381, 359, 349, 391, 359, 353, 359, 356, 363, 356, 349, 299, 285, 278, 277, 265, 270, 222, 224, 218, 204, 206, 208, 203, 189, 163, 153, 174, 197, 240, 318, 334, 328, 334, 329, 307, 333, 318, 315, 319, 307, 315, 317, 323, 319, 303, 334, 319, 298, 304, 346, 330, 350, 336, 333, 376, 374, 368, 371, 359, 356, 306, 290, 271, 275, 284, 271, 229, 225, 218, 214, 219, 218, 242, 229, 237, 237, 243, 256, 255, 252, 250, 249, 262, 276, 229, 247, 241, 253, 238, 250, 268, 258, 257, 260, 255, 257, 253, 245, 265, 250, 258, 256, 255, 251, 231, 254, 240, 219, 198, 229, 233, 245, 247, 242, 240, 234, 242, 235, 256, 248, 242, 246, 235, 252, 236, 225, 243, 257, 268, 270, 265, 255, 259, 238, 252, 259, 264, 265, 263, 266, 311, 346, 338, 341, 385, 358, 377, 380, 396, 373, 354, 360, 368, 371, 369, 341, 310, 314, 304, 308, 353, 360, 347, 359, 343, 301, 278, 258, 268, 265, 254, 259, 265, 268, 326, 373, 373, 381, 383, 385, 392, 375, 372, 377, 371, 385, 359, 305, 257, 237, 260, 267, 253, 250, 263, 252, 270, 271, 263, 254, 252, 264, 248, 262, 255, 259, 260, 253, 285, 313, 306, 313, 310, 327, 320, 312, 305, 309, 351, 359, 371, 385, 355, 345, 340, 306, 290, 316, 300, 310, 312, 282, 280, 293, 340, 325, 312, 324, 328, 330, 289, 288, 294, 285, 291, 286, 316, 328, 323, 303, 317, 309, 329, 318, 311, 283, 299, 312, 324, 307, 326, 325, 297, 291, 296, 292, 292, 293, 345, 363, 372, 372, 331, 354, 334, 340, 325, 338, 339, 329, 352, 343, 355, 334, 348, 422, 389, 375, 377, 387, 393, 396, 405, 371, 388, 395, 354, 249, 228, 231, 223, 232, 218, 239, 235, 240, 244, 247, 220, 228, 252, 246, 234, 231, 229, 255, 261, 251, 315, 393, 384, 385, 383, 392, 394, 401, 368, 382, 342, 368, 352, 346, 350, 310, 293, 206, 217, 203, 214, 213, 204, 189, 188, 193, 196, 208, 194, 222, 274, 278, 273, 280, 255, 281, 276, 275, 289, 292, 389, 386, 369, 374, 375, 346, 340, 331, 341, 324, 342, 332, 323, 334, 338, 334, 311, 246, 260, 243, 256, 242, 252, 259, 245, 245, 278, 264, 280, 259, 269, 261, 244, 304, 318, 346, 343, 387, 379, 379, 380, 360, 371, 395, 325, 327, 369, 360, 335, 289, 289, 285, 278, 246, 278, 286, 270, 283, 255, 257, 251, 243, 251, 254, 220, 233, 207, 221, 240, 208, 191, 168, 171, 171, 183, 151, 168, 174, 156, 168, 199, 232, 217, 212, 210, 243, 254, 257, 294, 198, 334, 342, 359, 342, 339, 324, 308, 293, 292, 326, 348, 359, 349, 360, 326, 337, 335, 364, 342, 288, 273, 275, 275, 269, 274, 271, 269, 272, 250, 272, 264, 273, 287, 311, 309, 309, 323, 310, 329, 449, 430, 428, 427, 452, 429, 423, 349, 324, 357, 346, 336, 327, 339, 339, 349, 325, 321, 324, 330, 370, 402, 402, 394, 401, 399, 388, 397, 379, 407, 408, 380, 384, 347, 307, 286, 292, 291, 280, 290, 283, 292, 302, 301, 308, 260, 226, 243, 206, 210, 222, 215, 223, 215, 216, 221, 224, 217, 263, 259, 246, 250, 330, 312, 329, 333, 325, 353, 313, 333, 333, 324, 316, 294, 305, 304, 308, 294, 309, 303, 288, 328, 367, 387, 380, 379, 371, 330, 299, 305, 299, 296, 281, 309, 291, 298, 307, 296, 299, 296, 260, 259, 248, 277, 256, 271, 261, 257, 252, 248, 265, 261, 254, 290, 259, 260, 275, 279, 266, 274, 269, 270, 258, 246, 256, 276, 233, 211, 225, 199, 157, 180, 160, 259, 260, 273, 256, 347, 376, 361, 387, 364, 371, 374, 382, 372, 382, 367, 380, 372, 365, 361, 351, 364, 370, 360, 354, 343, 364, 324, 324, 339, 334, 344, 345, 335, 343, 348, 356, 350, 347, 320, 291, 300, 299, 280, 283, 297, 292, 296, 308, 302, 300, 300, 302, 300, 301, 355, 353, 401, 373, 387, 385, 371, 346, 270, 268, 264, 270, 258, 263, 257, 256, 248, 251, 273, 261, 262, 322, 250, 250, 250, 251, 251, 341, 345, 341, 338, 349, 333, 346, 349, 350, 349, 360, 349, 356, 353, 348, 346, 329, 356, 346, 345, 351, 348, 333, 352, 351, 328, 346, 346, 352, 344, 352, 338, 343, 352, 338, 355, 327, 337, 343, 344, 342, 344, 331, 341, 333, 336, 338, 340, 347, 358, 339, 340, 347, 357, 354, 346, 339, 356, 358, 328, 331, 331, 347, 334, 345, 356, 324, 340, 336, 326, 324, 345, 352, 324, 335, 373, 343, 374, 359, 375, 372, 356, 359, 356, 357, 362, 297, 276, 273, 264, 263, 243, 206, 203, 204, 207, 213, 205, 206, 213, 201, 208, 206, 204, 218, 123, 73, 231, 262, 249, 260, 262, 244, 240, 336, 368, 354, 349, 321, 325, 338, 324, 328, 326, 340, 350, 339, 340, 339, 325, 321, 325, 332, 275, 292, 281, 280, 244, 224, 332, 272, 276, 255, 258, 254, 241, 276, 296, 267, 220, 263, 270, 259, 225, 204, 222, 225, 233, 237, 192, 244, 256, 240, 235, 235, 196, 258, 233, 210, 215, 227, 233, 232, 218, 198, 186, 209, 204, 229, 277, 274, 275, 360, 350, 347, 366, 369, 363, 349, 316, 306, 228, 225, 227, 239, 210, 221, 233, 222, 227, 240, 288, 275, 243, 258, 250, 248, 278, 251, 247, 290, 237, 293, 297, 449, 437, 439, 437, 430, 455, 430, 453, 422, 437, 225, 260, 228, 223, 251, 346, 344, 346, 373, 365, 347, 373, 339, 356, 359, 366, 367, 361, 357, 302, 300, 292, 293, 281, 286, 270, 277, 276, 274, 293, 287, 274, 283, 292, 284, 298, 289, 288, 274, 276, 269, 232, 216, 222, 217, 212, 224, 218, 224, 228, 220, 254, 272, 274, 263, 277, 262, 275, 270, 279, 280, 287, 311, 283, 360, 355, 316, 288, 274, 271, 279, 246, 287, 274, 289, 295, 275, 271, 286, 347, 354, 349, 355, 359, 360, 356, 349, 366, 341, 338, 346, 331, 263, 223, 245, 231, 213, 217, 217, 253, 256, 264, 252, 257, 265, 264, 272, 274, 254, 279, 261, 267, 262, 278, 264, 377, 347, 358, 376, 344, 329, 346, 355, 349, 343, 345, 341, 348, 336, 356, 359, 353, 357, 369, 363, 350, 336, 357, 370, 354, 384, 379, 371, 367, 363, 371, 378, 368, 366, 379, 364, 310, 285, 295, 282, 288, 297, 296, 289, 295, 270, 236, 241, 237, 250, 219, 225, 233, 244, 228, 245, 235, 242, 229, 218, 257, 253, 227, 201, 272, 250, 254, 241, 241, 234, 230, 238, 256, 268, 279, 262, 278, 261, 266, 285, 264, 255, 287, 323, 342, 338, 329, 321, 304, 310, 334, 315, 312, 333, 352, 319, 312, 315, 307, 304, 314, 310, 308, 326, 323, 315, 296, 311, 292, 319, 330, 391, 379, 400, 398, 381, 386, 384, 371, 390, 382, 378, 361, 375, 348, 371, 366, 369, 373, 358, 348, 342, 354, 353, 360, 318, 268, 284, 237, 249, 257, 253, 244, 256, 221, 225, 239, 232, 186, 202, 203, 128, 174, 208, 185, 200, 246, 250, 267, 257, 245, 248, 298, 368, 365, 354, 358, 357, 358, 356, 359, 340, 362, 345, 366, 363, 337, 340, 325, 349, 368, 339, 332, 321, 339, 337, 336, 337, 326, 323, 342, 341, 331, 306, 313, 311, 303, 315, 303, 307, 287, 307, 306, 312, 312, 297, 289, 309, 367, 374, 363, 376, 370, 377, 366, 379, 366, 361, 343, 359, 351, 354, 348, 352, 359, 350, 327, 342, 336, 365, 339, 328, 399, 385, 367, 369, 375, 363, 387, 375, 362, 355, 372, 301, 272, 264, 258, 253, 262, 267, 248, 261, 254, 263, 271, 366, 356, 313, 334, 328, 337, 315, 325, 318, 334, 313, 304, 329, 316, 311, 336, 366, 350, 368, 371, 369, 372, 375, 360, 338, 282, 270, 243, 243, 221, 221, 189, 207, 204, 204, 227, 214, 243, 267, 254, 253, 264, 250, 258, 310, 357, 364, 363, 362, 347, 362, 352, 350, 332, 307, 302, 317, 325, 320, 308, 302, 313, 309, 266, 296, 298, 301, 290, 296, 295, 280, 384, 383, 391, 383, 393, 372, 388, 356, 353, 352, 354, 331, 352, 305, 297, 303, 297, 294, 285, 298, 275, 253, 234, 212, 215, 219, 221, 167, 175, 162, 178, 190, 268, 256, 269, 273, 275, 277, 260, 277, 279, 290, 276, 277, 280, 274, 256, 273, 267, 272, 263, 309, 346, 338, 342, 339, 338, 338, 341, 332, 342, 344, 340, 299, 280, 286, 272, 275, 286, 285, 299, 295, 277, 300, 285, 285, 387, 373, 356, 355, 364, 348, 369, 370, 353, 367, 346, 356, 346, 363, 351, 356, 358, 355, 362, 339, 354, 365, 344, 320, 327, 325, 328, 322, 397, 401, 409, 405, 383, 379, 370, 397, 372, 366, 306, 278, 282, 304, 284, 295, 301, 294, 296, 308, 307, 310, 298, 314, 311, 315, 306, 319, 314, 280, 309, 313, 317, 305, 309, 393, 401, 402, 355, 345, 337, 311, 302, 292, 292, 288, 285, 283, 267, 355, 371, 358, 359, 360, 366, 368, 366, 377, 366, 362, 352, 345, 344, 336, 329, 326, 316, 321, 318, 338, 324, 331, 341, 324, 330, 332, 337, 330, 327, 315, 306, 324, 292, 296, 276, 282, 285, 337, 326, 334, 315, 346, 339, 320, 313, 317, 294, 280, 300, 283, 277, 269, 266, 318, 359, 353, 380, 349, 346, 342, 344, 345, 339, 349, 348, 350, 349, 362, 349, 350, 352, 346, 344, 333, 349, 335, 358, 343, 342, 335, 336, 303, 321, 306, 308, 298, 308, 322, 318, 307, 306, 307, 440, 453, 458, 440, 443, 427, 421, 437, 416, 435, 433, 423, 428, 434, 435, 444, 436, 373, 348, 354, 346, 366, 357, 369, 375, 372, 360, 367, 351, 354, 361, 355, 365, 351, 355, 353, 361, 373, 353, 345, 346, 337, 328, 322, 330, 283, 257, 279, 273, 271, 294, 276, 275, 270, 274, 272, 265, 274, 272, 258, 289, 246, 246, 274, 262, 257, 206, 194, 214, 206, 205, 204, 202, 193, 213, 204, 212, 247, 264, 267, 251, 247, 271, 257, 262, 261, 263, 254, 253, 362, 338, 370, 345, 364, 352, 363, 353, 330, 297, 269, 255, 257, 240, 246, 214, 244, 256, 254, 240, 229, 235, 240, 246, 363, 386, 376, 396, 372, 372, 376, 356, 388, 368, 386, 365, 387, 361, 277, 283, 295, 266, 270, 271, 274, 267, 257, 249, 254, 325, 312, 329, 311, 312, 330, 330, 332, 322, 333, 322, 306, 301, 319, 320, 303, 291, 301, 299, 285, 276, 291, 272, 276, 317, 323, 322, 327, 328, 337, 335, 319, 336, 316, 284, 269, 336, 314, 341, 335, 281, 244, 215, 261, 237, 218, 225, 311, 358, 232, 235, 219, 320, 369, 429, 410, 441, 412, 383, 345, 364, 373, 355, 362, 353, 354, 360, 342, 361, 344, 363, 358, 352, 351, 357, 341, 325, 325, 320, 348, 336, 358, 366, 375, 412, 416, 389, 388, 393, 397, 411, 387, 372, 390, 379, 313, 348, 360, 290, 269, 270, 267, 269, 264, 275, 271, 276, 271, 263, 274, 232, 246, 249, 210, 237, 234, 239, 264, 292, 332, 365, 334, 326, 330, 307, 306, 282, 285, 273, 324, 350, 362, 347, 343, 312, 333, 334, 401, 360, 332, 334, 388, 374, 381, 313, 266, 259, 259, 269, 263, 268, 282, 261, 259, 272, 273, 265, 256, 258, 264, 271, 259, 278, 340, 428, 439, 400, 414, 389, 383, 389, 340, 283, 258, 270, 268, 252, 277, 264, 265, 238, 252, 259, 259, 248, 251, 250, 255, 247, 269, 242, 274, 254, 235, 245, 248, 257, 347, 327, 329, 325, 339, 341, 330, 284, 326, 340, 342, 331, 353, 363, 383, 373, 396, 393, 391, 372, 359, 344, 364, 394, 344, 332, 336, 326, 345, 328, 340, 348, 323, 320, 269, 263, 265, 251, 266, 303, 342, 353, 357, 326, 330, 344, 356, 342, 341, 348, 332, 355, 383, 393, 419, 356, 350, 342, 351, 357, 345, 334, 343, 354, 334, 317, 315, 312, 314, 302, 317, 318, 310, 304, 311, 329, 304, 314, 318, 368, 389, 388, 401, 378, 398, 384, 408, 387, 392, 398, 400, 413, 377, 390, 392, 388, 380, 371, 368, 380, 357, 306, 296, 310, 286, 300, 296, 293, 309, 299, 321, 306, 310, 316, 315, 324, 318, 348, 327, 333, 309, 326, 304, 309, 297, 291, 308, 298, 321, 322, 312, 309, 293, 299, 334, 340, 344, 366, 355, 351, 358, 344, 374, 352, 350, 350, 369, 352, 301, 270, 271, 277, 263, 260, 282, 257, 273, 258, 270, 263, 309, 344, 340, 334, 320, 315, 346, 348, 334, 344, 365, 331, 370, 366, 377, 385, 372, 355, 383, 378, 378, 393, 383, 389, 379, 385, 387, 379, 376, 382, 306, 322, 312, 338, 312, 323, 320, 321, 326, 293, 299, 312, 317, 297, 275, 289, 288, 288, 284, 284, 296, 274, 282, 287, 289, 285, 292, 277, 274, 282, 250, 222, 223, 231, 243, 249, 249, 249, 243, 240, 236, 215, 207, 220, 197, 196, 191, 254, 248, 242, 251, 246, 252, 262, 262, 249, 253, 262, 244, 219, 251, 257, 283, 261, 259, 267, 265, 264, 281, 278, 276, 267, 265, 275, 268, 282, 276, 266, 352, 384, 389, 371, 386, 382, 355, 357, 371, 364, 380, 372, 372, 389, 379, 371, 363, 366, 381, 365, 380, 382, 372, 380, 323, 331, 305, 315, 314, 296, 310, 306, 302, 310, 308, 309, 249, 221, 216, 213, 295, 329, 339, 342, 367, 335, 355, 361, 354, 354, 366, 361, 364, 354, 342, 300, 293, 285, 274, 290, 282, 255, 265, 285, 284, 285, 278, 291, 293, 275, 281, 301, 301, 328, 407, 427, 409, 415, 423, 389, 355, 322, 394, 344, 333, 386, 365, 360, 362, 335, 344, 400, 396, 346, 351, 306, 328, 328, 307, 313, 307, 312, 312, 313, 314, 311, 282, 242, 237, 242, 249, 234, 389, 398, 370, 344, 350, 345, 350, 384, 338, 321, 356, 363, 346, 343, 364, 349, 366, 278, 233, 209, 217, 221, 318, 368, 371, 367, 363, 358, 352, 359, 339, 305, 311, 308, 313, 303, 310, 279, 290, 303, 302, 295, 304, 283, 308, 279, 302, 324, 255, 236, 225, 240, 294, 286, 272, 209, 232, 231, 218, 235, 233, 219, 217, 217, 230, 224, 228, 213, 216, 220, 140, 141, 161, 175, 144, 151, 159, 165, 152, 146, 205, 198, 215, 217, 220, 229, 203, 226, 213, 207, 326, 395, 396, 391, 407, 388, 382, 388, 406, 367, 372, 369, 371, 268, 268, 256, 211, 204, 180, 196, 198, 212, 198, 182, 205, 283, 266, 248, 259, 355, 295, 383, 389, 391, 406, 381, 397, 389, 390, 355, 254, 252, 268, 229, 227, 208, 219, 211, 216, 230, 236, 351, 145, 201, 280, 340, 354, 367, 378, 406, 403, 376, 391, 384, 370, 387, 351, 342, 339, 322, 329, 324, 328, 311, 311, 321, 297, 320, 310, 299, 311, 311, 300, 303, 333, 285, 283, 286, 280, 279, 268, 274, 270, 242, 240, 245, 257, 237, 245, 255, 258, 272, 264, 277, 268, 257, 263, 266, 296, 266, 260, 259, 275, 259, 269, 279, 277, 257, 251, 272, 282, 276, 269, 266, 273, 274, 274, 266, 282, 273, 272, 265, 342, 380, 377, 385, 396, 371, 367, 375, 400, 380, 392, 396, 380, 370, 350, 362, 380, 365, 354, 329, 339, 359, 324, 309, 302, 330, 329, 357, 349, 344, 349, 353, 357, 339, 335, 339, 340, 344, 316, 326, 320, 368, 372, 384, 378, 363, 296, 287, 291, 265, 256, 273, 292, 237, 230, 222, 215, 234, 240, 229, 249, 217, 233, 229, 237, 226, 258, 264, 257, 271, 259, 265, 237, 252, 248, 254, 249, 256, 244, 249, 254, 243, 260, 254, 272, 269, 253, 269, 261, 274, 261, 261, 268, 249, 265, 249, 254, 257, 255, 246, 234, 245, 226, 257, 261, 243, 249, 247, 232, 244, 250, 262, 249, 243, 237, 264, 263, 231, 248, 233, 240, 226, 234, 244, 230, 220, 245, 236, 256, 234, 242, 232, 238, 244, 236, 237, 220, 244, 245, 242, 223, 226, 241, 247, 237, 238, 236, 232, 230, 241, 234, 240, 239, 234, 254, 185, 200, 181, 187, 198, 178, 196, 184, 186, 173, 197, 211, 196, 190, 183, 191, 193, 193, 185, 190, 190, 346, 374, 375, 367, 361, 376, 378, 367, 358, 362, 328, 325, 316, 309, 320, 341, 329, 329, 317, 316, 323, 334, 304, 306, 310, 319, 306, 317, 304, 308, 313, 319, 308, 305, 301, 303, 309, 318, 297, 284, 328, 324, 313, 327, 330, 323, 275, 258, 251, 241, 252, 332, 335, 350, 323, 343, 354, 349, 361, 352, 360, 366, 361, 360, 382, 367, 344, 368, 373, 357, 341, 354, 361, 347, 356, 370, 359, 370, 372, 350, 357, 347, 378, 364, 357, 356, 352, 381, 364, 274, 295, 288, 291, 279, 291, 274, 262, 276, 301, 300, 273, 287, 264, 286, 288, 266, 273, 275, 279, 295, 306, 290, 271, 369, 351, 365, 370, 302, 284, 291, 272, 294, 274, 290, 281, 278, 272, 252, 229, 148, 163, 159, 163, 171, 180, 160, 172, 167, 163, 151, 158, 171, 151, 169, 157, 202, 203, 201, 96, 294, 204, 284, 467, 447, 433, 397, 340, 363, 357, 430, 378, 380, 377, 367, 354, 378, 382, 369, 288, 289, 267, 261, 304, 259, 252, 245, 260, 268, 244, 253, 166, 187, 179, 180, 183, 206, 223, 265, 264, 281, 312, 302, 296, 339, 320, 347, 345, 350, 379, 373, 400, 374, 383, 370, 396, 402, 368, 390, 389, 372, 377, 397, 394, 383, 388, 399, 358, 361, 336, 324, 342, 324, 342, 325, 297, 270, 276, 277, 268, 253, 253, 236, 262, 235, 227, 224, 232, 234, 225, 235, 237, 221, 233, 235, 234, 243, 211, 209, 198, 202, 184, 201, 188, 210, 245, 257, 241, 253, 241, 241, 250, 250, 306, 386, 365, 373, 403, 381, 388, 387, 395, 377, 377, 377, 368, 364, 362, 362, 353, 360, 357, 349, 364, 358, 357, 354, 361, 360, 377, 363, 380, 391, 405, 393, 371, 366, 346, 366, 342, 349, 360, 341, 343, 350, 303, 275, 264, 269, 269, 265, 279, 269, 267, 271, 268, 258, 274, 266, 295, 316, 252, 275, 265, 284, 275, 280, 278, 287, 247, 262, 254, 236, 255, 235, 251, 256, 237, 240, 246, 252, 239, 249, 245, 249, 254, 246, 249, 247, 238, 239, 244, 235, 246, 245, 259, 244, 270, 234, 247, 244, 250, 249, 252, 257, 242, 262, 285, 262, 276, 350, 347, 356, 365, 350, 370, 348, 371, 350, 353, 351, 354, 358, 348, 350, 346, 359, 350, 351, 341, 358, 380, 364, 352, 339, 355, 333, 333, 265, 208, 210, 228, 212, 207, 220, 228, 232, 212, 243, 234, 251, 242, 238, 247, 248, 243, 216, 414, 399, 407, 394, 388, 404, 401, 386, 404, 396, 390, 310, 302, 252, 213, 200, 206, 201, 218, 196, 200, 225, 195, 202, 187, 199, 348, 361, 343, 346, 367, 342, 328, 303, 271, 288, 285, 295, 287, 288, 279, 274, 268, 310, 259, 268, 237, 227, 221, 225, 242, 229, 232, 243, 250, 239, 261, 289, 285, 274, 293, 283, 269, 284, 286, 286, 282, 287, 281, 275, 278, 285, 284, 277, 285, 295, 291, 348, 373, 383, 371, 387, 367, 372, 370, 374, 360, 378, 381, 312, 271, 265, 263, 257, 260, 264, 261, 251, 247, 238, 255, 259, 256, 256, 289, 374, 375, 383, 371, 378, 326, 323, 319, 312, 319, 312, 327, 338, 340, 342, 342, 333, 337, 325, 311, 320, 274, 262, 265, 273, 282, 271, 271, 270, 268, 278, 275, 267, 276, 268, 265, 263, 346, 371, 373, 372, 348, 358, 391, 280, 260, 259, 253, 268, 271, 265, 270, 290, 259, 259, 264, 270, 270, 243, 279, 259, 287, 260, 277, 285, 257, 270, 264, 258, 258, 263, 264, 248, 282, 275, 281, 280, 287, 262, 256, 267, 271, 269, 248, 275, 284, 277, 266, 266, 256, 264, 254, 282, 287, 262, 267, 265, 276, 290, 290, 270, 286, 266, 273, 257, 273, 271, 269, 276, 272, 249, 254, 260, 290, 266, 256, 276, 269, 268, 261, 278, 270, 264, 282, 258, 271, 273, 272, 264, 263, 282, 288, 267, 259, 262, 275, 306, 258, 260, 277, 283, 288, 273, 280, 290, 285, 279, 286, 281, 275, 285, 276, 288, 286, 292, 286, 281, 275, 275, 283, 285, 278, 280, 275, 278, 280, 281, 279, 281, 285, 274, 273, 272, 276, 292, 269, 293, 280, 278, 288, 270, 276, 277, 272, 283, 284, 287, 281, 272, 273, 280, 274, 271, 273, 272, 263, 279, 278, 284, 294, 281, 270, 290, 285, 271, 287, 271, 284, 272, 284, 274, 273, 281, 295, 282, 285, 275, 282, 279, 275, 280, 288, 275, 296, 279, 271, 266, 279, 268, 274, 273, 276, 290, 288, 277, 280, 276, 281, 284, 282, 296, 274, 284, 283, 280, 276, 270, 266, 245, 239, 242, 251, 260, 276, 262, 273, 282, 273, 285, 267, 260, 266, 279, 265, 275, 273, 281, 274, 269, 271, 256, 265, 268, 286
+};
diff --git a/vbz/test/test_utils.h b/vbz/test/test_utils.h
new file mode 100644
index 0000000..138ffe9
--- /dev/null
+++ b/vbz/test/test_utils.h
@@ -0,0 +1,45 @@
+#pragma once
+
+#include <gsl/gsl-lite.hpp>
+
+#include <iostream>
+
+namespace {
+
+template <typename T, typename PrintType>
+class ContainerDumper
+{
+public:
+ ContainerDumper(T const& t)
+ : m_data(t)
+ {
+ }
+
+ T const& m_data;
+};
+
+template <typename PrintType, typename Container>
+std::ostream& operator<<(std::ostream &str, ContainerDumper<Container, PrintType> const& container)
+{
+ str << "{ ";
+ for (auto const& e : container.m_data)
+ {
+ str << PrintType(e) << ", ";
+ }
+ str << "}";
+ return str;
+}
+
+template <typename PrintType, typename Container>
+ContainerDumper<Container, PrintType> dump_explicit(Container const& c)
+{
+ return ContainerDumper<Container, PrintType>{ c };
+}
+
+template <typename Container>
+ContainerDumper<Container, typename Container::value_type> dump(Container const& c)
+{
+ return ContainerDumper<Container, typename Container::value_type>{ c };
+}
+
+} \ No newline at end of file
diff --git a/vbz/test/vbz_test.cpp b/vbz/test/vbz_test.cpp
new file mode 100644
index 0000000..0e9ec90
--- /dev/null
+++ b/vbz/test/vbz_test.cpp
@@ -0,0 +1,350 @@
+#include <cstddef>
+#include <iostream>
+#include <numeric>
+#include <random>
+
+#include "vbz.h"
+#include "test_utils.h"
+
+#include "test_data.h"
+
+#include <catch2/catch.hpp>
+
+template <typename T>
+void perform_compression_test(
+ std::vector<T> const& data,
+ CompressionOptions const& options)
+{
+ auto const input_data_size = vbz_size_t(data.size() * sizeof(data[0]));
+ std::vector<int8_t> dest_buffer(vbz_max_compressed_size(input_data_size, &options));
+ auto final_byte_count = vbz_compress(
+ data.data(),
+ input_data_size,
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ &options);
+ REQUIRE(!vbz_is_error(final_byte_count));
+ dest_buffer.resize(final_byte_count);
+
+ std::vector<int8_t> decompressed_bytes(input_data_size);
+ auto decompressed_byte_count = vbz_decompress(
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ decompressed_bytes.data(),
+ vbz_size_t(decompressed_bytes.size()),
+ &options
+ );
+ REQUIRE(!vbz_is_error(decompressed_byte_count));
+ decompressed_bytes.resize(decompressed_byte_count);
+ auto decompressed = gsl::make_span(decompressed_bytes).as_span<T>();
+
+ //INFO("Original " << dump_explicit<std::int64_t>(data));
+ //INFO("Decompressed " << dump_explicit<std::int64_t>(decompressed));
+ CHECK(decompressed == gsl::make_span(data));
+}
+
+template <typename T>
+void run_compression_test_suite()
+{
+ GIVEN("Simple data to compress with no delta-zig-zag")
+ {
+ std::vector<T> simple_data(100);
+ std::iota(simple_data.begin(), simple_data.end(), 0);
+
+ CompressionOptions simple_options{
+ false, // no delta zig zag
+ sizeof(T),
+ 1,
+ VBZ_DEFAULT_VERSION
+ };
+
+ perform_compression_test(simple_data, simple_options);
+ }
+
+ GIVEN("Simple data to compress and applying delta zig zag")
+ {
+ std::vector<T> simple_data(100);
+ std::iota(simple_data.begin(), simple_data.end(), 0);
+
+ CompressionOptions simple_options{
+ true,
+ sizeof(T),
+ 1,
+ VBZ_DEFAULT_VERSION
+ };
+
+ perform_compression_test(simple_data, simple_options);
+ }
+
+ GIVEN("Simple data to compress with delta-zig-zag and no zstd")
+ {
+ std::vector<T> simple_data(100);
+ std::iota(simple_data.begin(), simple_data.end(), 0);
+
+ CompressionOptions simple_options{
+ true,
+ sizeof(T),
+ 0,
+ VBZ_DEFAULT_VERSION
+ };
+
+ perform_compression_test(simple_data, simple_options);
+ }
+
+ GIVEN("Random data to compress")
+ {
+ std::vector<T> random_data(10 * 1000);
+ auto seed = std::random_device()();
+ INFO("Seed " << seed);
+ std::default_random_engine rand(seed);
+ // std::uniform_int_distribution<std::int8_t> has issues on some platforms - always use 32 bit engine
+ std::uniform_int_distribution<std::int32_t> dist(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
+ for (auto& e : random_data)
+ {
+ e = dist(rand);
+ }
+
+ WHEN("Compressing with no delta zig zag")
+ {
+ CompressionOptions options{
+ false,
+ sizeof(T),
+ 1,
+ VBZ_DEFAULT_VERSION
+ };
+ perform_compression_test(random_data, options);
+ }
+
+ WHEN("Compressing with delta zig zag")
+ {
+ CompressionOptions options{
+ true,
+ sizeof(T),
+ 0,
+ VBZ_DEFAULT_VERSION
+ };
+
+ perform_compression_test(random_data, options);
+ }
+
+ WHEN("Compressing with zstd and delta zig zag")
+ {
+ CompressionOptions options{
+ true,
+ sizeof(T),
+ 1,
+ VBZ_DEFAULT_VERSION
+ };
+
+ perform_compression_test(random_data, options);
+ }
+ }
+}
+
+struct InputStruct
+{
+ std::uint32_t size = 100;
+ unsigned char keys[25] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ };
+};
+
+SCENARIO("vbz int8 encoding")
+{
+ run_compression_test_suite<std::int8_t>();
+}
+
+SCENARIO("vbz int16 encoding")
+{
+ run_compression_test_suite<std::int16_t>();
+}
+
+SCENARIO("vbz int32 encoding")
+{
+ run_compression_test_suite<std::int32_t>();
+}
+
+
+SCENARIO("vbz int32 known input data")
+{
+ GIVEN("A known input data set")
+ {
+ std::vector<std::int32_t> simple_data{ 5, 4, 3, 2, 1 };
+
+ WHEN("Compressed without zstd, with delta zig-zag")
+ {
+ CompressionOptions simple_options{
+ true,
+ sizeof(simple_data[0]),
+ 0,
+ VBZ_DEFAULT_VERSION
+ };
+
+ THEN("Data compresses/decompresses as expected")
+ {
+ perform_compression_test(simple_data, simple_options);
+ }
+
+ AND_WHEN("Checking compressed data")
+ {
+ auto const input_data_size = vbz_size_t(simple_data.size() * sizeof(simple_data[0]));
+ std::vector<int8_t> dest_buffer(vbz_max_compressed_size(input_data_size, &simple_options));
+ auto final_byte_count = vbz_compress(
+ simple_data.data(),
+ input_data_size,
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ &simple_options);
+ dest_buffer.resize(final_byte_count);
+
+ std::vector<int8_t> expected{ 0, 0, 10, 1, 1, 1, 1, };
+
+ INFO("Compressed " << dump_explicit<std::int64_t>(dest_buffer));
+ INFO("Decompressed " << dump_explicit<std::int64_t>(expected));
+ CHECK(dest_buffer == expected);
+ }
+ }
+
+ WHEN("Compressed with zstd and delta zig-zag")
+ {
+ CompressionOptions simple_options{
+ true,
+ sizeof(simple_data[0]),
+ 100,
+ VBZ_DEFAULT_VERSION
+ };
+
+ THEN("Data compresses/decompresses as expected")
+ {
+ perform_compression_test(simple_data, simple_options);
+ }
+
+ AND_WHEN("Checking compressed data")
+ {
+ auto const input_data_size = vbz_size_t(simple_data.size() * sizeof(simple_data[0]));
+ std::vector<int8_t> dest_buffer(vbz_max_compressed_size(input_data_size, &simple_options));
+ auto final_byte_count = vbz_compress(
+ simple_data.data(),
+ input_data_size,
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ &simple_options);
+ dest_buffer.resize(final_byte_count);
+
+ std::vector<int8_t> expected{ 40, -75, 47, -3, 32, 7, 57, 0, 0, 0, 0, 10, 1, 1, 1, 1, };
+
+ INFO("Compressed " << dump_explicit<std::int64_t>(dest_buffer));
+ INFO("Decompressed " << dump_explicit<std::int64_t>(expected));
+ CHECK(dest_buffer == expected);
+ }
+ }
+ }
+}
+
+SCENARIO("vbz int16 known input large data")
+{
+ GIVEN("Test data from a realistic dataset")
+ {
+ WHEN("Compressing with zig-zag deltas")
+ {
+ CompressionOptions options{
+ true,
+ sizeof(test_data[0]),
+ 0,
+ VBZ_DEFAULT_VERSION
+ };
+
+ perform_compression_test(test_data, options);
+ }
+
+ WHEN("Compressing with zstd")
+ {
+ CompressionOptions options{
+ true,
+ sizeof(test_data[0]),
+ 1,
+ VBZ_DEFAULT_VERSION
+ };
+
+ perform_compression_test(test_data, options);
+ }
+
+ WHEN("Compressing with no options")
+ {
+ CompressionOptions options{
+ false,
+ 1,
+ 0,
+ VBZ_DEFAULT_VERSION
+ };
+
+ perform_compression_test(test_data, options);
+ }
+ }
+}
+
+SCENARIO("vbz sized compression")
+{
+ GIVEN("A known input data set")
+ {
+ std::vector<std::int32_t> simple_data{ 5, 4, 3, 2, 1 };
+
+ WHEN("Compressed without zstd, with delta zig-zag")
+ {
+ CompressionOptions simple_options{
+ true,
+ sizeof(simple_data[0]),
+ 0,
+ VBZ_DEFAULT_VERSION
+ };
+
+
+ WHEN("Compressing data")
+ {
+ auto const input_data_size = vbz_size_t(simple_data.size() * sizeof(simple_data[0]));
+ std::vector<int8_t> compressed_buffer(vbz_max_compressed_size(input_data_size, &simple_options));
+
+ auto final_byte_count = vbz_compress_sized(
+ simple_data.data(),
+ input_data_size,
+ compressed_buffer.data(),
+ vbz_size_t(compressed_buffer.size()),
+ &simple_options);
+ compressed_buffer.resize(final_byte_count);
+
+ THEN("Data is compressed correctly")
+ {
+ std::vector<int8_t> expected{ 20, 0, 0, 0, 0, 0, 10, 1, 1, 1, 1, };
+
+ INFO("Compressed " << dump_explicit<std::int64_t>(compressed_buffer));
+ INFO("Decompressed " << dump_explicit<std::int64_t>(expected));
+ CHECK(compressed_buffer == expected);
+ }
+
+ AND_WHEN("Decompressing data")
+ {
+ std::vector<std::int8_t> dest_buffer(
+ vbz_decompressed_size(compressed_buffer.data(),
+ vbz_size_t(compressed_buffer.size()),
+ &simple_options)
+ );
+ CHECK(dest_buffer.size() == input_data_size);
+
+ auto final_byte_count = vbz_decompress_sized(
+ compressed_buffer.data(),
+ vbz_size_t(compressed_buffer.size()),
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ &simple_options);
+ CHECK(final_byte_count == input_data_size);
+
+ CHECK(gsl::make_span(dest_buffer).as_span<std::int32_t>() == gsl::make_span(simple_data));
+ }
+ }
+ }
+ }
+}
diff --git a/vbz/v0/vbz_streamvbyte.cpp b/vbz/v0/vbz_streamvbyte.cpp
new file mode 100644
index 0000000..609075e
--- /dev/null
+++ b/vbz/v0/vbz_streamvbyte.cpp
@@ -0,0 +1,108 @@
+#include "vbz_streamvbyte.h"
+#include "vbz_streamvbyte_impl.h"
+#include "vbz.h"
+
+#include <gsl/gsl-lite.hpp>
+
+vbz_size_t vbz_max_streamvbyte_compressed_size_v0(
+ std::size_t integer_size,
+ vbz_size_t source_size)
+{
+ if (source_size % integer_size != 0)
+ {
+ return VBZ_STREAMVBYTE_INPUT_SIZE_ERROR;
+ }
+
+ auto int_count = source_size / integer_size;
+ return vbz_size_t(streamvbyte_max_compressedbytes(std::uint32_t(int_count)));
+}
+
+vbz_size_t vbz_delta_zig_zag_streamvbyte_compress_v0(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ int integer_size,
+ bool use_delta_zig_zag_encoding)
+{
+ if (source_size % integer_size != 0)
+ {
+ return VBZ_STREAMVBYTE_INPUT_SIZE_ERROR;
+ }
+
+ auto const input_span = gsl::make_span(static_cast<char const*>(source), source_size);
+ auto const output_span = gsl::make_span(static_cast<char*>(destination), destination_capacity);
+ switch(integer_size) {
+ case 1: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV0<std::int8_t, true>::compress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV0<std::int8_t, false>::compress(input_span, output_span);
+ }
+ }
+ case 2: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV0<std::int16_t, true>::compress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV0<std::int16_t, false>::compress(input_span, output_span);
+ }
+ }
+ case 4: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV0<std::int32_t, true>::compress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV0<std::int32_t, false>::compress(input_span, output_span);
+ }
+ }
+ default:
+ return VBZ_STREAMVBYTE_INTEGER_SIZE_ERROR;
+ }
+}
+
+vbz_size_t vbz_delta_zig_zag_streamvbyte_decompress_v0(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_size,
+ int integer_size,
+ bool use_delta_zig_zag_encoding)
+{
+ if (destination_size % integer_size != 0)
+ {
+ return VBZ_STREAMVBYTE_DESTINATION_SIZE_ERROR;
+ }
+
+ auto const input_span = gsl::make_span(static_cast<char const*>(source), source_size);
+ auto const output_span = gsl::make_span(static_cast<char*>(destination), destination_size);
+ switch(integer_size) {
+ case 1: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV0<std::int8_t, true>::decompress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV0<std::int8_t, false>::decompress(input_span, output_span);
+ }
+ }
+ case 2: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV0<std::int16_t, true>::decompress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV0<std::int16_t, false>::decompress(input_span, output_span);
+ }
+ }
+ case 4: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV0<std::int32_t, true>::decompress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV0<std::int32_t, false>::decompress(input_span, output_span);
+ }
+ }
+ default:
+ return VBZ_STREAMVBYTE_INTEGER_SIZE_ERROR;
+ }
+}
diff --git a/vbz/v0/vbz_streamvbyte.h b/vbz/v0/vbz_streamvbyte.h
new file mode 100644
index 0000000..af050e0
--- /dev/null
+++ b/vbz/v0/vbz_streamvbyte.h
@@ -0,0 +1,54 @@
+#pragma once
+
+#include "vbz/vbz_export.h"
+#include "vbz.h"
+
+#include <cstddef>
+
+// Version 1 of streamvbyte
+//
+// This method follows streamvbyte exactly.
+
+/// \brief find the maximum size a compressed data stream
+/// using streamvbyte compression could be.
+/// \param integer_size The input integer size in bytes.
+/// \param source_size The size of the input buffer, in bytes.
+VBZ_EXPORT vbz_size_t vbz_max_streamvbyte_compressed_size_v0(
+ size_t integer_size,
+ vbz_size_t source_size);
+
+/// \brief Encode the source data using a combination of delta zig zag + streamvbyte encoding.
+/// \param source Source data for compression.
+/// \param source_size Source data size (in bytes)
+/// \param destination Destination buffer for compressed output.
+/// \param destination_capacity Size of the destination buffer to write to (see #max_streamvbyte_compressed_size)
+/// \param integer_size Number of bytes per integer
+/// \param use_delta_zig_zag_encoding Control if the data should be delta-zig-zag encoded before streamvbyte encoding.
+/// \return The number of bytes used to compress data into [destination].
+VBZ_EXPORT vbz_size_t vbz_delta_zig_zag_streamvbyte_compress_v0(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ int integer_size,
+ bool use_delta_zig_zag_encoding);
+
+/// \brief Decode the source data using a combination of delta zig zag + streamvbyte encoding.
+/// \param source Source compressed data for decompression.
+/// \param source_size Source data size (in bytes)
+/// \param destination Destination buffer for decompressed output.
+/// \param destination_size Size of the destination buffer to write to in bytes.
+/// This must be a multiple of integer_size, and equal to the number of
+/// expected output bytes exactly. The caller is expected to store this information alongside
+/// the compressed data.
+/// \param integer_size Number of bytes per integer (must equal size used to compress)
+/// \param use_delta_zig_zag_encoding Control if the data should be delta-zig-zag encoded before streamvbyte encoding.
+/// (must equal value used to compress).
+/// \return The number of bytes used to decompress data into [destination].
+VBZ_EXPORT vbz_size_t vbz_delta_zig_zag_streamvbyte_decompress_v0(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_size,
+ int integer_size,
+ bool use_delta_zig_zag_encoding); \ No newline at end of file
diff --git a/vbz/v0/vbz_streamvbyte_impl.h b/vbz/v0/vbz_streamvbyte_impl.h
new file mode 100644
index 0000000..357cb61
--- /dev/null
+++ b/vbz/v0/vbz_streamvbyte_impl.h
@@ -0,0 +1,94 @@
+#pragma once
+
+#include "vbz.h"
+
+#include "streamvbyte.h"
+#include "streamvbyte_zigzag.h"
+
+#include <gsl/gsl-lite.hpp>
+
+#include <vector>
+
+/// \brief Generic implementation, safe for all integer types, and platforms.
+template <typename T, bool UseZigZag>
+struct StreamVByteWorkerV0
+{
+ static vbz_size_t compress(gsl::span<char const> input_bytes, gsl::span<char> output)
+ {
+ auto const input = input_bytes.as_span<T const>();
+
+ if (!UseZigZag)
+ {
+ auto input_buffer = cast<std::uint32_t>(input);
+ return vbz_size_t(streamvbyte_encode(
+ input_buffer.data(),
+ std::uint32_t(input_buffer.size()),
+ output.as_span<std::uint8_t>().data()
+ ));
+ }
+
+ std::vector<std::int32_t> input_buffer = cast<std::int32_t>(input);
+ std::vector<std::uint32_t> intermediate_buffer(input.size());
+ zigzag_delta_encode(input_buffer.data(), intermediate_buffer.data(), input_buffer.size(), 0);
+
+ return vbz_size_t(streamvbyte_encode(
+ intermediate_buffer.data(),
+ std::uint32_t(intermediate_buffer.size()),
+ output.as_span<std::uint8_t>().data()
+ ));
+ }
+
+ static vbz_size_t decompress(gsl::span<char const> input, gsl::span<char> output_bytes)
+ {
+ auto const output = output_bytes.as_span<T>();
+
+ std::vector<std::uint32_t> intermediate_buffer(output.size());
+ auto read_bytes = streamvbyte_decode(
+ input.as_span<std::uint8_t const>().data(),
+ intermediate_buffer.data(),
+ vbz_size_t(intermediate_buffer.size())
+ );
+ if (read_bytes != input.size())
+ {
+ return VBZ_STREAMVBYTE_STREAM_ERROR;
+ }
+
+ if (!UseZigZag)
+ {
+ cast(gsl::make_span(intermediate_buffer), output);
+ return vbz_size_t(output.size() * sizeof(T));
+ }
+
+ std::vector<std::int32_t> output_buffer(output.size());
+ zigzag_delta_decode(intermediate_buffer.data(), output_buffer.data(), output_buffer.size(), 0);
+
+ cast(gsl::make_span(output_buffer), output);
+ return vbz_size_t(output.size() * sizeof(T));
+ }
+
+ template <typename U, typename V>
+ static std::vector<U> cast(gsl::span<V> const& input)
+ {
+ std::vector<U> output(input.size());
+ for (std::size_t i = 0; i < input.size(); ++i)
+ {
+ output[i] = input[i];
+ }
+ return output;
+ }
+
+ template <typename U, typename V>
+ static void cast(gsl::span<U> input, gsl::span<V> output)
+ {
+ for (std::size_t i = 0; i < input.size(); ++i)
+ {
+ output[i] = input[i];
+ }
+ }
+};
+
+#ifdef __SSE3__
+
+#include "vbz_streamvbyte_impl_sse3.h"
+
+#endif
diff --git a/vbz/v0/vbz_streamvbyte_impl_sse3.h b/vbz/v0/vbz_streamvbyte_impl_sse3.h
new file mode 100644
index 0000000..6ceff01
--- /dev/null
+++ b/vbz/v0/vbz_streamvbyte_impl_sse3.h
@@ -0,0 +1,659 @@
+#pragma once
+
+#include <cstring>
+#include <iostream>
+
+#if (defined __INTEL_COMPILER) && (defined WIN32)
+#include <intrin.h>
+#else
+#include <x86intrin.h>
+#endif
+
+// See: https://github.com/lemire/streamvbyte
+static const uint8_t encode_shuf_lut[64*16] = {
+ 0x00, 0x04, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x06, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x06, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x04, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF,
+ 0x00, 0x04, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF,
+ 0x00, 0x04, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF,
+ 0x00, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF,
+ 0x00, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF,
+ 0x00, 0x01, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF,
+ 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
+};
+
+// See: https://github.com/lemire/streamvbyte
+static const uint8_t len_lut[256] = {
+ 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10,
+ 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11,
+ 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12,
+ 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13,
+ 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11,
+ 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12,
+ 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13,
+ 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14,
+ 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12,
+ 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13,
+ 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14,
+ 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 12, 13, 14, 15,
+ 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13,
+ 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14,
+ 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 12, 13, 14, 15,
+ 10, 11, 12, 13, 11, 12, 13, 14, 12, 13, 14, 15, 13, 14, 15, 16,
+};
+
+// See: https://github.com/lemire/streamvbyte
+static int8_t decode_shuffleTable[256][16] = {
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1 }, // 0000
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1 }, // 1000
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1 }, // 2000
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, -1, -1, -1 }, // 3000
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1 }, // 0100
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1 }, // 1100
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, -1, -1, -1 }, // 2100
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, -1, -1, -1 }, // 3100
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, -1, -1, -1 }, // 0200
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, -1, -1, -1 }, // 1200
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, -1, -1, -1 }, // 2200
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, -1, -1, -1, 8, -1, -1, -1 }, // 3200
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, -1, -1, -1 }, // 0300
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, -1, -1, -1 }, // 1300
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, -1, -1, -1, 8, -1, -1, -1 }, // 2300
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, -1, -1, -1 }, // 3300
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1 }, // 0010
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1 }, // 1010
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, -1, -1, -1 }, // 2010
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, -1, -1, -1 }, // 3010
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1 }, // 0110
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, -1, -1, -1 }, // 1110
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, -1, -1, -1 }, // 2110
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, -1, -1, -1 }, // 3110
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, -1, -1, -1 }, // 0210
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, -1, -1, -1 }, // 1210
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, -1, -1, -1 }, // 2210
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, -1, -1, 9, -1, -1, -1 }, // 3210
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, -1, -1, -1 }, // 0310
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, -1, -1, -1 }, // 1310
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, -1, -1, 9, -1, -1, -1 }, // 2310
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, -1, -1, -1 }, // 3310
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1 }, // 0020
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, -1, -1, -1 }, // 1020
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, -1, -1, -1 }, // 2020
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, -1, 8, -1, -1, -1 }, // 3020
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, -1, -1, -1 }, // 0120
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, -1, -1, -1 }, // 1120
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, -1, -1, -1 }, // 2120
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, -1, 9, -1, -1, -1 }, // 3120
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, -1, -1, -1 }, // 0220
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, -1, -1, -1 }, // 1220
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, -1, -1, -1 }, // 2220
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, -1, 10, -1, -1, -1 }, // 3220
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, -1, 8, -1, -1, -1 }, // 0320
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, -1, 9, -1, -1, -1 }, // 1320
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, -1, -1, -1 }, // 2320
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, -1, -1, -1 }, // 3320
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1 }, // 0030
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, -1, -1, -1 }, // 1030
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, 7, 8, -1, -1, -1 }, // 2030
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, -1, -1, -1 }, // 3030
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, -1, -1, -1 }, // 0130
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, -1, -1, -1 }, // 1130
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, 8, 9, -1, -1, -1 }, // 2130
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, -1, -1, -1 }, // 3130
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, 7, 8, -1, -1, -1 }, // 0230
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, 8, 9, -1, -1, -1 }, // 1230
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, 9, 10, -1, -1, -1 }, // 2230
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, 10, 11, -1, -1, -1 }, // 3230
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1 }, // 0330
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1 }, // 1330
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1, -1 }, // 2330
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1 }, // 3330
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1 }, // 0001
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, -1, -1 }, // 1001
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, 6, -1, -1 }, // 2001
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, 7, -1, -1 }, // 3001
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, -1, -1 }, // 0101
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, -1, -1 }, // 1101
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, 7, -1, -1 }, // 2101
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, 8, -1, -1 }, // 3101
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, 6, -1, -1 }, // 0201
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, 7, -1, -1 }, // 1201
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, 8, -1, -1 }, // 2201
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, -1, -1, -1, 8, 9, -1, -1 }, // 3201
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, 7, -1, -1 }, // 0301
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, 8, -1, -1 }, // 1301
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, -1, -1, -1, 8, 9, -1, -1 }, // 2301
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, 10, -1, -1 }, // 3301
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1 }, // 0011
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, -1, -1 }, // 1011
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1 }, // 2011
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, 8, -1, -1 }, // 3011
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, -1, -1 }, // 0111
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1 }, // 1111
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, -1, -1 }, // 2111
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, 9, -1, -1 }, // 3111
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, 7, -1, -1 }, // 0211
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, -1, -1 }, // 1211
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, 9, -1, -1 }, // 2211
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, -1, -1, 9, 10, -1, -1 }, // 3211
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, 8, -1, -1 }, // 0311
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, 9, -1, -1 }, // 1311
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, -1, -1, 9, 10, -1, -1 }, // 2311
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, -1, -1 }, // 3311
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1 }, // 0021
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, 7, -1, -1 }, // 1021
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, 8, -1, -1 }, // 2021
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, -1, 8, 9, -1, -1 }, // 3021
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, 7, -1, -1 }, // 0121
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, -1, -1 }, // 1121
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, 9, -1, -1 }, // 2121
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, -1, 9, 10, -1, -1 }, // 3121
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, 8, -1, -1 }, // 0221
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, 9, -1, -1 }, // 1221
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, -1, -1 }, // 2221
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, -1, 10, 11, -1, -1 }, // 3221
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, -1, 8, 9, -1, -1 }, // 0321
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, -1, 9, 10, -1, -1 }, // 1321
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, -1, -1 }, // 2321
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, -1, -1 }, // 3321
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1 }, // 0031
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, 8, -1, -1 }, // 1031
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, 7, 8, 9, -1, -1 }, // 2031
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, 10, -1, -1 }, // 3031
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, 8, -1, -1 }, // 0131
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, 9, -1, -1 }, // 1131
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, 8, 9, 10, -1, -1 }, // 2131
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, 11, -1, -1 }, // 3131
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, 7, 8, 9, -1, -1 }, // 0231
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, 8, 9, 10, -1, -1 }, // 1231
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, -1, -1 }, // 2231
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, 10, 11, 12, -1, -1 }, // 3231
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1 }, // 0331
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1 }, // 1331
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1 }, // 2331
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1 }, // 3331
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1 }, // 0002
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, 6, -1 }, // 1002
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, 6, 7, -1 }, // 2002
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, 7, 8, -1 }, // 3002
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, 6, -1 }, // 0102
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, 7, -1 }, // 1102
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, 7, 8, -1 }, // 2102
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, 8, 9, -1 }, // 3102
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, 6, 7, -1 }, // 0202
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, 7, 8, -1 }, // 1202
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, 8, 9, -1 }, // 2202
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, -1, -1, -1, 8, 9, 10, -1 }, // 3202
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, 7, 8, -1 }, // 0302
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, 8, 9, -1 }, // 1302
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, -1, -1, -1, 8, 9, 10, -1 }, // 2302
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, 10, 11, -1 }, // 3302
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1 }, // 0012
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, 7, -1 }, // 1012
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, 7, 8, -1 }, // 2012
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, 8, 9, -1 }, // 3012
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, 7, -1 }, // 0112
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, 8, -1 }, // 1112
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, 9, -1 }, // 2112
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, 9, 10, -1 }, // 3112
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, 7, 8, -1 }, // 0212
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, 9, -1 }, // 1212
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, 9, 10, -1 }, // 2212
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, -1, -1, 9, 10, 11, -1 }, // 3212
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, 8, 9, -1 }, // 0312
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, 9, 10, -1 }, // 1312
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, -1, -1, 9, 10, 11, -1 }, // 2312
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, -1 }, // 3312
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1 }, // 0022
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, 7, 8, -1 }, // 1022
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, 8, 9, -1 }, // 2022
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, -1, 8, 9, 10, -1 }, // 3022
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, 7, 8, -1 }, // 0122
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, 9, -1 }, // 1122
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, 9, 10, -1 }, // 2122
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, -1, 9, 10, 11, -1 }, // 3122
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, 8, 9, -1 }, // 0222
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, 9, 10, -1 }, // 1222
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, 11, -1 }, // 2222
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, -1, 10, 11, 12, -1 }, // 3222
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, -1, 8, 9, 10, -1 }, // 0322
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, -1, 9, 10, 11, -1 }, // 1322
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, -1 }, // 2322
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, 13, -1 }, // 3322
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, -1 }, // 0032
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, 8, 9, -1 }, // 1032
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, -1 }, // 2032
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, 10, 11, -1 }, // 3032
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, 8, 9, -1 }, // 0132
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, 9, 10, -1 }, // 1132
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, 8, 9, 10, 11, -1 }, // 2132
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, 11, 12, -1 }, // 3132
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, 7, 8, 9, 10, -1 }, // 0232
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, 8, 9, 10, 11, -1 }, // 1232
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, -1 }, // 2232
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, 10, 11, 12, 13, -1 }, // 3232
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1 }, // 0332
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1 }, // 1332
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1 }, // 2332
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, -1 }, // 3332
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6 }, // 0003
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, 6, 7 }, // 1003
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, 6, 7, 8 }, // 2003
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, 7, 8, 9 }, // 3003
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, 6, 7 }, // 0103
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, 7, 8 }, // 1103
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, 7, 8, 9 }, // 2103
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, 8, 9, 10 }, // 3103
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, 6, 7, 8 }, // 0203
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, 7, 8, 9 }, // 1203
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, 8, 9, 10 }, // 2203
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, -1, -1, -1, 8, 9, 10, 11 }, // 3203
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, 7, 8, 9 }, // 0303
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, 8, 9, 10 }, // 1303
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, -1, -1, -1, 8, 9, 10, 11 }, // 2303
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, 10, 11, 12 }, // 3303
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7 }, // 0013
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, 7, 8 }, // 1013
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, 7, 8, 9 }, // 2013
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, 8, 9, 10 }, // 3013
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, 7, 8 }, // 0113
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, 8, 9 }, // 1113
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, 9, 10 }, // 2113
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, 9, 10, 11 }, // 3113
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, 7, 8, 9 }, // 0213
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, 9, 10 }, // 1213
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, 9, 10, 11 }, // 2213
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, -1, -1, 9, 10, 11, 12 }, // 3213
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, 8, 9, 10 }, // 0313
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, 9, 10, 11 }, // 1313
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, -1, -1, 9, 10, 11, 12 }, // 2313
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13 }, // 3313
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, 6, 7, 8 }, // 0023
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, 7, 8, 9 }, // 1023
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, 8, 9, 10 }, // 2023
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, -1, 8, 9, 10, 11 }, // 3023
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, 7, 8, 9 }, // 0123
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, 9, 10 }, // 1123
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, 9, 10, 11 }, // 2123
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, -1, 9, 10, 11, 12 }, // 3123
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, 8, 9, 10 }, // 0223
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, 9, 10, 11 }, // 1223
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, 11, 12 }, // 2223
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, -1, 10, 11, 12, 13 }, // 3223
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, -1, 8, 9, 10, 11 }, // 0323
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, -1, 9, 10, 11, 12 }, // 1323
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, 13 }, // 2323
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, 13, 14 }, // 3323
+ { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9 }, // 0033
+ { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, 8, 9, 10 }, // 1033
+ { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11 }, // 2033
+ { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, 10, 11, 12 }, // 3033
+ { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, 8, 9, 10 }, // 0133
+ { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11 }, // 1133
+ { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, 8, 9, 10, 11, 12 }, // 2133
+ { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, 11, 12, 13 }, // 3133
+ { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, 7, 8, 9, 10, 11 }, // 0233
+ { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, 8, 9, 10, 11, 12 }, // 1233
+ { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, 13 }, // 2233
+ { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, 10, 11, 12, 13, 14 }, // 3233
+ { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, // 0333
+ { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, // 1333
+ { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, // 2333
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // 3333
+};
+
+template <typename T>
+inline static std::size_t scalar_to_zig_zag(gsl::span<std::int16_t const> input, std::array<std::uint32_t, 8>& output, T last_value)
+{
+ auto const size = std::min(output.size(), input.size());
+ auto const shift_size = (sizeof(T)*8) - 1;
+ for (std::size_t i = 0; i < size; ++i)
+ {
+ T const delta = input[i] - last_value;
+ output[i] = (delta << 1) ^ (delta >> shift_size);
+ last_value = input[i];
+ }
+ return size;
+}
+
+template <typename T>
+inline static std::size_t zig_zag_to_scalar(gsl::span<std::uint32_t> const& input, gsl::span<std::int16_t> output, T last_value)
+{
+ auto const size = std::min(output.size(), input.size());
+ for (std::size_t i = 0; i < size; ++i)
+ {
+ std::uint32_t const zig_zag = input[i];
+ output[i] = ((zig_zag >> 1) ^ - (zig_zag & 1)) + last_value;
+ last_value = output[i];
+ }
+ return size;
+}
+
+template <typename IntType, typename RegType, typename PrintType=IntType>
+void dump_reg(std::ostream& str, RegType reg)
+{
+ union {
+ RegType reg;
+ IntType values[sizeof(RegType)/sizeof(IntType)];
+ } conv;
+ conv.reg = reg;
+
+ for (auto x : conv.values)
+ {
+ str << (PrintType)x << " ";
+ }
+}
+
+/// \brief Optimised ssse3 implementation for x64 when performing zig zag deltas.
+template <>
+struct StreamVByteWorkerV0<std::int16_t, true>
+{
+ static vbz_size_t compress(gsl::span<char const> input_bytes, gsl::span<char> output)
+ {
+ auto const input = input_bytes.as_span<std::int16_t const>();
+ std::uint32_t size = input.size();
+ if (size == 0)
+ {
+ return 0;
+ }
+
+ uint32_t keyLen = (size >> 2) + (((size & 3) + 3) >> 2); // 2-bits per each rounded up to byte boundry
+ char *keyPtr = &output[0];
+ char *dataPtr = &output[keyLen]; // variable length data after keys
+
+ const __m128i zero = _mm_set1_epi16(0);
+
+ auto step = 8;
+ std::size_t completed = 0;
+
+ auto prev_current = _mm_set1_epi16(0);
+ for (; (completed+step) <= size; completed += step)
+ {
+ // load data from source short buffer
+ auto current = _mm_lddqu_si128((__m128i*)(input.data() + completed));
+
+ // Combine to find previous values
+ auto prev = _mm_alignr_epi8(current, prev_current, 14);
+
+ // Find delta between elements
+ auto delta = _mm_sub_epi16(current, prev);
+ prev_current = current;
+
+ // Perform zig zag int reorganisation
+ auto shl = _mm_slli_epi16(delta, 1);
+ auto shr = _mm_srai_epi16(delta, 15);
+ auto xor_res = _mm_xor_si128(shl, shr);
+
+ auto low = _mm_unpacklo_epi16(xor_res, zero);
+ auto high = _mm_unpackhi_epi16(xor_res, zero);
+
+ // Perform normal sse3 streamvbyte encode
+ compress_int_registers(low, high, keyPtr, dataPtr);
+ }
+
+ std::array<std::uint32_t, 8> final_elements;
+ std::int16_t last_value = completed == 0 ? 0 : input[completed-1];
+ scalar_to_zig_zag(input.subspan(completed), final_elements, last_value);
+
+ // do remaining
+ uint32_t key = 0;
+ for(size_t i = 0; i < (size & 7); i++)
+ {
+ uint32_t dw = final_elements[i];
+ uint32_t symbol = (dw > 0x000000FF) + (dw > 0x0000FFFF) + (dw > 0x00FFFFFF);
+ key |= symbol << (i + i);
+ *((uint32_t*)dataPtr) = dw;
+ dataPtr += 1 + symbol;
+ }
+ memcpy(keyPtr, &key, ((size & 7) + 3) >> 2);
+
+ return dataPtr - output.begin();
+ }
+
+ static vbz_size_t decompress(gsl::span<char const> input, gsl::span<char> output_bytes)
+ {
+ auto const output = output_bytes.as_span<std::int16_t>();
+
+ int count = output.size();
+ if (count == 0)
+ {
+ return 0;
+ }
+
+ vbz_size_t key_byte_count = (count + 3) / 4;
+ if (input.size() < key_byte_count)
+ {
+ return VBZ_STREAMVBYTE_INPUT_SIZE_ERROR;
+ }
+
+ // full list of keys starts
+ // 2-bits per key (rounded up)
+ auto keys = input.subspan(0, key_byte_count).as_span<std::uint8_t const>();
+ // data starts at end of keys
+ gsl::span<char const> data = input.subspan(key_byte_count);
+ std::size_t key_byte_pairs = count / (4*2); // 2 bits per int - 4 ints per byte, iterate in pairs - 8 ints at once
+
+ std::size_t key_idx = 0;
+ std::size_t output_index = 0;
+ auto prev = _mm_set1_epi16(0); // previous set to 0 to begin with
+ for (; key_idx < key_byte_pairs; ++key_idx)
+ {
+ // We'll process at max 32 bytes of input from data - if theres < than that left we need to
+ // use the scalar impl
+ if (data.size() < 32)
+ {
+ break;
+ }
+
+ auto const key_1 = keys[key_idx*2];
+ auto data_1 = decompress_int_registers(key_1, data);
+
+ auto const key_2 = keys[key_idx*2+1];
+ auto data_2 = decompress_int_registers(key_2, data);
+
+ // Now unpack the decompressed data to signed integers.
+ auto const to_16_bit_left = _mm_setr_epi8(-1,-1,-1,-1,-1,-1,-1,-1, 0,1, 4,5, 8,9, 12, 13);
+ auto const to_16_bit_right = _mm_setr_epi8(0,1, 4,5, 8,9, 12, 13, -1,-1,-1,-1,-1,-1,-1,-1);
+ auto const left = _mm_shuffle_epi8(data_1, to_16_bit_left);
+ auto const right = _mm_shuffle_epi8(data_2, to_16_bit_right);
+ auto const values = _mm_alignr_epi8(right, left, 8);
+
+ const __m128i mask_1 = _mm_set1_epi16(1);
+ // Perform un-zig zag int reorganisation
+ // (n >> 1) ^ - (n & 1)
+ auto shr = _mm_srli_epi16(values, 1);
+ auto neg_bit = _mm_sign_epi16(_mm_and_si128(values, mask_1), _mm_set1_epi16(-1));
+ auto xor_res = _mm_xor_si128(shr, neg_bit);
+
+ // Combine to find previous values
+ auto zero = _mm_set1_epi16(0);
+ auto cum_sum = xor_res;
+ auto cum_sum_adder = xor_res;
+
+ for (std::size_t i = 0; i < 7; ++i)
+ {
+ auto next_cum_sum_adder = _mm_alignr_epi8(cum_sum_adder, zero, 14);
+ cum_sum = _mm_add_epi16(cum_sum, next_cum_sum_adder);
+ cum_sum_adder = next_cum_sum_adder;
+ }
+
+ cum_sum = _mm_add_epi16(cum_sum, prev);
+ _mm_storeu_si128((__m128i *)output.subspan(output_index).data(), cum_sum);
+
+ prev = _mm_shuffle_epi8(cum_sum, _mm_setr_epi8(14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15));
+ output_index += 8;
+ }
+
+ auto scalar_count = count - output_index;
+ if (scalar_count)
+ {
+ auto scalar_keys = keys.subspan(key_idx*2);
+ std::size_t key_index = 0;
+
+ std::array<std::uint32_t, 32> final_elements;
+ uint8_t shift = 0;
+ uint32_t key = scalar_keys[key_index++];
+
+ vbz_size_t error_value = 0;
+ for (uint32_t c = 0; c < scalar_count; c++)
+ {
+ if (shift == 8) {
+ shift = 0;
+ key = scalar_keys[key_index++];
+ }
+ uint32_t val = decompress_int(data, (key >> shift) & 0x3, error_value);
+ if (error_value)
+ {
+ return error_value;
+ }
+
+ final_elements[c] = val;
+ shift += 2;
+ }
+
+ std::int16_t last_value = output_index == 0 ? 0 : output.subspan(output_index - 1)[0];
+ zig_zag_to_scalar(gsl::make_span(final_elements).subspan(0, scalar_count), output.subspan(output_index), last_value);
+
+ }
+
+ if (data.size() != 0)
+ {
+ return VBZ_STREAMVBYTE_STREAM_ERROR;
+ }
+
+ return output.size() * sizeof(std::int16_t);
+ }
+
+ inline static void compress_int_registers(__m128i r0, __m128i r1, char*& keyPtr, char*& dataPtr)
+ {
+ std::size_t keys;
+ __m128i r2, r3;
+
+ const __m128i mask_01 = _mm_set1_epi8(0x01);
+ const __m128i mask_7F00 = _mm_set1_epi16(0x7F00);
+
+ r2 = _mm_min_epu8(mask_01, r0);
+ r3 = _mm_min_epu8(mask_01, r1);
+ r2 = _mm_packus_epi16(r2, r3);
+ r2 = _mm_min_epi16(r2, mask_01); // convert 0x01FF to 0x0101
+ r2 = _mm_adds_epu16(r2, mask_7F00); // convert: 0x0101 to 0x8001, 0xFF01 to 0xFFFF
+ keys = (size_t)_mm_movemask_epi8(r2);
+
+ r2 = _mm_loadu_si128((__m128i*)&encode_shuf_lut[(keys << 4) & 0x03F0]);
+ r3 = _mm_loadu_si128((__m128i*)&encode_shuf_lut[(keys >> 4) & 0x03F0]);
+ r0 = _mm_shuffle_epi8(r0, r2);
+ r1 = _mm_shuffle_epi8(r1, r3);
+
+ _mm_storeu_si128((__m128i *)dataPtr, r0);
+ dataPtr += len_lut[keys & 0xFF];
+ _mm_storeu_si128((__m128i *)dataPtr, r1);
+ dataPtr += len_lut[keys >> 8];
+
+ *((uint16_t*)keyPtr) = (uint16_t)keys;
+ keyPtr += 2;
+ }
+
+ inline static __m128i decompress_int_registers(uint32_t key, gsl::span<char const>& data_buffer)
+ {
+ uint8_t len;
+ __m128i data = _mm_loadu_si128(data_buffer.subspan(0, sizeof(__m128i)).as_span<__m128i const>().data());
+
+ uint8_t *pshuf = (uint8_t *) &decode_shuffleTable[key];
+ __m128i shuf = *(__m128i *)pshuf;
+ len = len_lut[key];
+
+ data = _mm_shuffle_epi8(data, shuf);
+ data_buffer = data_buffer.subspan(len);
+ return data;
+ }
+
+ inline static std::uint32_t decompress_int(gsl::span<char const>& data_buffer, int code, vbz_size_t& error_value)
+ {
+ std::size_t copy_size = 0;
+ if (code == 0) { // 1 byte
+ copy_size = 1;
+ } else if (code == 1) { // 2 bytes
+ copy_size = 2;
+ } else if (code == 2) { // 3 bytes
+ copy_size = 3;
+ } else { // code == 3
+ copy_size = 4;
+ }
+
+ if (data_buffer.size() < copy_size)
+ {
+ error_value = VBZ_STREAMVBYTE_STREAM_ERROR;
+ return 0;
+ }
+
+ std::uint32_t val = 0;
+ memcpy(&val, data_buffer.data(), copy_size);
+ data_buffer = data_buffer.subspan(copy_size);
+
+ return val;
+ }
+
+ template <typename U, typename V>
+ static void cast(gsl::span<U> input, gsl::span<V> output)
+ {
+ for (std::size_t i = 0; i < input.size(); ++i)
+ {
+ output[i] = input[i];
+ }
+ }
+};
diff --git a/vbz/v1/vbz_streamvbyte.cpp b/vbz/v1/vbz_streamvbyte.cpp
new file mode 100644
index 0000000..d2d9a67
--- /dev/null
+++ b/vbz/v1/vbz_streamvbyte.cpp
@@ -0,0 +1,112 @@
+#include "vbz_streamvbyte.h"
+#include "vbz_streamvbyte_impl.h"
+#include "../v0/vbz_streamvbyte_impl.h" // for 4 byte case
+#include "vbz.h"
+
+#include <gsl/gsl-lite.hpp>
+
+vbz_size_t vbz_max_streamvbyte_compressed_size_v1(
+ std::size_t integer_size,
+ vbz_size_t source_size)
+{
+ if (source_size % integer_size != 0)
+ {
+ return VBZ_STREAMVBYTE_INPUT_SIZE_ERROR;
+ }
+
+ auto int_count = source_size / integer_size;
+ return vbz_size_t(streamvbyte_max_compressedbytes(std::uint32_t(int_count)));
+}
+
+vbz_size_t vbz_delta_zig_zag_streamvbyte_compress_v1(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ int integer_size,
+ bool use_delta_zig_zag_encoding)
+{
+ if (source_size % integer_size != 0)
+ {
+ return VBZ_STREAMVBYTE_INPUT_SIZE_ERROR;
+ }
+
+ auto const input_span = gsl::make_span(static_cast<char const*>(source), source_size);
+ auto const output_span = gsl::make_span(static_cast<char*>(destination), destination_capacity);
+ switch(integer_size) {
+ case 1: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV1<std::int8_t, true>::compress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV1<std::int8_t, false>::compress(input_span, output_span);
+ }
+ }
+ case 2: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV0<std::int16_t, true>::compress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV0<std::int16_t, false>::compress(input_span, output_span);
+ }
+ }
+ case 4: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV0<std::int32_t, true>::compress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV0<std::int32_t, false>::compress(input_span, output_span);
+ }
+ }
+ default:
+ return VBZ_STREAMVBYTE_INTEGER_SIZE_ERROR;
+ }
+}
+
+vbz_size_t vbz_delta_zig_zag_streamvbyte_decompress_v1(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_size,
+ int integer_size,
+ bool use_delta_zig_zag_encoding)
+{
+ if (destination_size % integer_size != 0)
+ {
+ return VBZ_STREAMVBYTE_DESTINATION_SIZE_ERROR;
+ }
+
+ auto const input_span = gsl::make_span(static_cast<char const*>(source), source_size);
+ auto const output_span = gsl::make_span(static_cast<char*>(destination), destination_size);
+ switch(integer_size) {
+ case 1: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV1<std::int8_t, true>::decompress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV1<std::int8_t, false>::decompress(input_span, output_span);
+ }
+ }
+ // Integers larger than 1 byte have been shown to perform better (with zstd) when using version 0 compression
+ // likely the increased noise in the key section reduces compression efficiency negating the benefits of
+ // compressing 1 byte values into halfs.
+ case 2: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV0<std::int16_t, true>::decompress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV0<std::int16_t, false>::decompress(input_span, output_span);
+ }
+ }
+ case 4: {
+ if (use_delta_zig_zag_encoding) {
+ return StreamVByteWorkerV0<std::int32_t, true>::decompress(input_span, output_span);
+ }
+ else {
+ return StreamVByteWorkerV0<std::int32_t, false>::decompress(input_span, output_span);
+ }
+ }
+ default:
+ return VBZ_STREAMVBYTE_INTEGER_SIZE_ERROR;
+ }
+}
diff --git a/vbz/v1/vbz_streamvbyte.h b/vbz/v1/vbz_streamvbyte.h
new file mode 100644
index 0000000..b472293
--- /dev/null
+++ b/vbz/v1/vbz_streamvbyte.h
@@ -0,0 +1,54 @@
+#pragma once
+
+#include "vbz/vbz_export.h"
+#include "vbz.h"
+
+#include <cstddef>
+
+// Version 1 of streamvbyte
+//
+// This method introduces half byte + zero byte compression.
+
+/// \brief find the maximum size a compressed data stream
+/// using streamvbyte compression could be.
+/// \param integer_size The input integer size in bytes.
+/// \param source_size The size of the input buffer, in bytes.
+VBZ_EXPORT vbz_size_t vbz_max_streamvbyte_compressed_size_v1(
+ size_t integer_size,
+ vbz_size_t source_size);
+
+/// \brief Encode the source data using a combination of delta zig zag + streamvbyte encoding.
+/// \param source Source data for compression.
+/// \param source_size Source data size (in bytes)
+/// \param destination Destination buffer for compressed output.
+/// \param destination_capacity Size of the destination buffer to write to (see #max_streamvbyte_compressed_size)
+/// \param integer_size Number of bytes per integer
+/// \param use_delta_zig_zag_encoding Control if the data should be delta-zig-zag encoded before streamvbyte encoding.
+/// \return The number of bytes used to compress data into [destination].
+VBZ_EXPORT vbz_size_t vbz_delta_zig_zag_streamvbyte_compress_v1(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ int integer_size,
+ bool use_delta_zig_zag_encoding);
+
+/// \brief Decode the source data using a combination of delta zig zag + streamvbyte encoding.
+/// \param source Source compressed data for decompression.
+/// \param source_size Source data size (in bytes)
+/// \param destination Destination buffer for decompressed output.
+/// \param destination_size Size of the destination buffer to write to in bytes.
+/// This must be a multiple of integer_size, and equal to the number of
+/// expected output bytes exactly. The caller is expected to store this information alongside
+/// the compressed data.
+/// \param integer_size Number of bytes per integer (must equal size used to compress)
+/// \param use_delta_zig_zag_encoding Control if the data should be delta-zig-zag encoded before streamvbyte encoding.
+/// (must equal value used to compress).
+/// \return The number of bytes used to decompress data into [destination].
+VBZ_EXPORT vbz_size_t vbz_delta_zig_zag_streamvbyte_decompress_v1(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_size,
+ int integer_size,
+ bool use_delta_zig_zag_encoding); \ No newline at end of file
diff --git a/vbz/v1/vbz_streamvbyte_impl.h b/vbz/v1/vbz_streamvbyte_impl.h
new file mode 100644
index 0000000..b3bce88
--- /dev/null
+++ b/vbz/v1/vbz_streamvbyte_impl.h
@@ -0,0 +1,258 @@
+#pragma once
+
+#include "vbz.h"
+
+#include "streamvbyte.h"
+#include "streamvbyte_zigzag.h"
+
+#include <gsl/gsl-lite.hpp>
+
+#include <cassert>
+#include <vector>
+
+#ifdef _MSC_VER
+# define VBZ_RESTRICT __restrict
+#else
+# define VBZ_RESTRICT __restrict__
+#endif
+
+static inline uint32_t _decode_data(const uint8_t **dataPtrPtr, uint8_t code, uint8_t *data_shift) {
+ uint32_t val;
+
+ auto read_data = [&](uint8_t bits)
+ {
+ uint32_t return_val = 0;
+ auto& current_shift = *data_shift;
+ for (std::size_t i = 0; i < bits / 4; ++i)
+ {
+ if (current_shift == 8)
+ {
+ current_shift = 0;
+ *dataPtrPtr += 1;
+ }
+
+ const uint8_t *dataPtr = *dataPtrPtr;
+ auto val_bits = 0xf & (*dataPtr >> current_shift);
+ return_val |= val_bits << (i*4);
+ current_shift += 4;
+ }
+ return return_val;
+ };
+
+ if (code == 0) { // 0 bytes
+ val = 0;
+ } else if (code == 1) { // 1/2 byte
+ val = read_data(4);
+ } else if (code == 2) { // 1 byte
+ val = read_data(8);
+ } else if (code == 3) { // 2 bytes
+ val = read_data(16);
+ } else {
+ assert(0 && "Unknown code");
+ val = 0;
+ }
+
+ return val;
+}
+static const uint8_t *svb_decode_scalar(uint32_t *outPtr, const uint8_t *keyPtr,
+ const uint8_t *dataPtr,
+ uint32_t count) {
+ if (count == 0)
+ return dataPtr; // no reads or writes if no data
+
+ uint8_t data_shift = 0;
+ uint8_t shift = 0;
+ uint32_t key = *keyPtr++;
+ for (uint32_t c = 0; c < count; c++) {
+ if (shift == 8) {
+ shift = 0;
+ key = *keyPtr++;
+ }
+ uint32_t val = _decode_data(&dataPtr, (key >> shift) & 0x3, &data_shift);
+ *outPtr++ = val;
+ shift += 2;
+ }
+
+ if (data_shift != 0)
+ {
+ dataPtr += 1;
+ }
+
+ return dataPtr; // pointer to first unused byte after end
+}
+
+static uint8_t _encode_data(uint32_t val, uint8_t *VBZ_RESTRICT *dataPtrPtr, uint8_t* data_shift) {
+ uint8_t code;
+
+ auto write_data = [&](uint32_t value, uint8_t bits) {
+
+ auto& current_shift = *data_shift;
+ for (std::size_t i = 0; i < bits / 4; ++i)
+ {
+ if (current_shift == 8)
+ {
+ current_shift = 0;
+ *dataPtrPtr += 1;
+ }
+
+ auto val_masked = value & 0xf;
+ value >>= 4;
+
+ uint8_t *dataPtr = *dataPtrPtr;
+ if (current_shift == 0)
+ {
+ *dataPtr = 0;
+ }
+ *dataPtr |= val_masked << current_shift;
+ current_shift += 4;
+ }
+ };
+
+ if (val == 0) { // 0 bytes
+ code = 0;
+ } else if (val < (1 << 4)) { // 1/2 byte
+ write_data(val, 4);
+ code = 1;
+ } else if (val < (1 << 8)) { // 1 byte
+ write_data(val, 8);
+ code = 2;
+ } else { // 2 bytes
+ write_data(val, 16);
+ code = 3;
+ }
+
+ return code;
+}
+
+static uint8_t *svb_encode_scalar(const uint32_t *in,
+ uint8_t *VBZ_RESTRICT keyPtr,
+ uint8_t *VBZ_RESTRICT dataPtr,
+ uint32_t count) {
+ if (count == 0)
+ return dataPtr; // exit immediately if no data
+
+ uint8_t data_shift = 0;
+ uint8_t shift = 0; // cycles 0, 2, 4, 6, 0, 2, 4, 6, ...
+ uint8_t key = 0;
+ for (uint32_t c = 0; c < count; c++) {
+ if (shift == 8) {
+ shift = 0;
+ *keyPtr++ = key;
+ key = 0;
+ }
+ uint32_t val = in[c];
+ uint8_t code = _encode_data(val, &dataPtr, &data_shift);
+ key |= code << shift;
+ shift += 2;
+ }
+
+ if (data_shift != 0)
+ {
+ dataPtr += 1;
+ }
+
+ *keyPtr = key; // write last key (no increment needed)
+ return dataPtr; // pointer to first unused data byte
+}
+
+vbz_size_t streamvbyte_encode_half(uint32_t const* input, uint32_t count, uint8_t* output)
+{
+ uint8_t *keyPtr = output;
+ uint32_t keyLen = (count + 3) / 4; // 2-bits rounded to full byte
+ uint8_t *dataPtr = keyPtr + keyLen; // variable byte data after all keys
+
+ return vbz_size_t(svb_encode_scalar(input, keyPtr, dataPtr, count) - output);
+}
+
+vbz_size_t streamvbyte_decode_half(uint8_t const* input, uint32_t* output, uint32_t count)
+{
+ uint8_t *keyPtr = (uint8_t*)input;
+ uint32_t keyLen = (count + 3) / 4; // 2-bits rounded to full byte
+ uint8_t *dataPtr = keyPtr + keyLen; // variable byte data after all keys
+
+ return vbz_size_t(svb_decode_scalar(
+ output,
+ keyPtr,
+ dataPtr,
+ count
+ ) - input);
+}
+
+
+/// \brief Generic implementation, safe for all integer types, and platforms.
+template <typename T, bool UseZigZag>
+struct StreamVByteWorkerV1
+{
+ static vbz_size_t compress(gsl::span<char const> input_bytes, gsl::span<char> output)
+ {
+ auto const input = input_bytes.as_span<T const>();
+
+ if (!UseZigZag)
+ {
+ auto input_buffer = cast<std::uint32_t>(input);
+ return vbz_size_t(streamvbyte_encode_half(
+ input_buffer.data(),
+ std::uint32_t(input_buffer.size()),
+ output.as_span<std::uint8_t>().data()
+ ));
+ }
+
+ std::vector<std::int32_t> input_buffer = cast<std::int32_t>(input);
+ std::vector<std::uint32_t> intermediate_buffer(input.size());
+ zigzag_delta_encode(input_buffer.data(), intermediate_buffer.data(), input_buffer.size(), 0);
+
+ return vbz_size_t(streamvbyte_encode_half(
+ intermediate_buffer.data(),
+ std::uint32_t(intermediate_buffer.size()),
+ output.as_span<std::uint8_t>().data()
+ ));
+ }
+
+ static vbz_size_t decompress(gsl::span<char const> input, gsl::span<char> output_bytes)
+ {
+ auto const output = output_bytes.as_span<T>();
+
+ std::vector<std::uint32_t> intermediate_buffer(output.size());
+ auto read_bytes = streamvbyte_decode_half(
+ input.as_span<std::uint8_t const>().data(),
+ intermediate_buffer.data(),
+ vbz_size_t(intermediate_buffer.size())
+ );
+ if (read_bytes != input.size())
+ {
+ return VBZ_STREAMVBYTE_STREAM_ERROR;
+ }
+
+ if (!UseZigZag)
+ {
+ cast(gsl::make_span(intermediate_buffer), output);
+ return vbz_size_t(output.size() * sizeof(T));
+ }
+
+ std::vector<std::int32_t> output_buffer(output.size());
+ zigzag_delta_decode(intermediate_buffer.data(), output_buffer.data(), output_buffer.size(), 0);
+
+ cast(gsl::make_span(output_buffer), output);
+ return vbz_size_t(output.size() * sizeof(T));
+ }
+
+ template <typename U, typename V>
+ static std::vector<U> cast(gsl::span<V> const& input)
+ {
+ std::vector<U> output(input.size());
+ for (std::size_t i = 0; i < input.size(); ++i)
+ {
+ output[i] = input[i];
+ }
+ return output;
+ }
+
+ template <typename U, typename V>
+ static void cast(gsl::span<U> input, gsl::span<V> output)
+ {
+ for (std::size_t i = 0; i < input.size(); ++i)
+ {
+ output[i] = input[i];
+ }
+ }
+};
diff --git a/vbz/vbz.cpp b/vbz/vbz.cpp
new file mode 100644
index 0000000..8ae0b74
--- /dev/null
+++ b/vbz/vbz.cpp
@@ -0,0 +1,343 @@
+#include "v0/vbz_streamvbyte.h"
+#include "v1/vbz_streamvbyte.h"
+
+#include <gsl/gsl-lite.hpp>
+#include <zstd.h>
+
+#include <cassert>
+#include <cstddef>
+#include <iostream>
+#include <memory>
+
+// include last - it uses c headers which can mess things up.
+#include "vbz.h"
+
+namespace {
+// util for using malloc with unique_ptr
+struct free_delete
+{
+ void operator()(void* x) { free(x); }
+};
+
+gsl::span<char> make_data_buffer(void* data, vbz_size_t size)
+{
+ return gsl::make_span(static_cast<char*>(data), size);
+}
+
+gsl::span<char const> make_data_buffer(void const* data, vbz_size_t size)
+{
+ return gsl::make_span(static_cast<char const*>(data), size);
+}
+
+void copy_buffer(
+ gsl::span<char const> source,
+ gsl::span<char> dest)
+{
+ std::copy(source.begin(), source.end(), dest.begin());
+}
+
+struct VbzSizedHeader
+{
+ vbz_size_t original_size;
+};
+
+}
+
+extern "C" {
+
+bool vbz_is_error(vbz_size_t result_value)
+{
+ return result_value >= VBZ_FIRST_ERROR;
+}
+
+char const* vbz_error_string(vbz_size_t error_value)
+{
+ if (VBZ_ZSTD_ERROR == error_value) return "VBZ_ZSTD_ERROR";
+ if (VBZ_STREAMVBYTE_INPUT_SIZE_ERROR == error_value) return "VBZ_STREAMVBYTE_INPUT_SIZE_ERROR";
+ if (VBZ_STREAMVBYTE_INTEGER_SIZE_ERROR == error_value) return "VBZ_STREAMVBYTE_INTEGER_SIZE_ERROR";
+ if (VBZ_STREAMVBYTE_DESTINATION_SIZE_ERROR == error_value) return "VBZ_STREAMVBYTE_DESTINATION_SIZE_ERROR";
+ if (VBZ_STREAMVBYTE_STREAM_ERROR == error_value) return "VBZ_STREAMVBYTE_STREAM_ERROR";
+ if (VBZ_VERSION_ERROR == error_value) return "VBZ_VERSION_ERROR";
+
+ return "VBZ_UNKNOWN_ERROR";
+}
+
+vbz_size_t vbz_max_compressed_size(
+ vbz_size_t source_size,
+ CompressionOptions const* options)
+{
+ vbz_size_t max_size = source_size;
+ if (options->integer_size != 0 || options->perform_delta_zig_zag)
+ {
+ auto size_fn = vbz_max_streamvbyte_compressed_size_v0;
+ if (options->vbz_version == 1)
+ {
+ size_fn = vbz_max_streamvbyte_compressed_size_v1;
+ }
+ else if (options->vbz_version != 0)
+ {
+ return VBZ_VERSION_ERROR;
+ }
+
+ max_size = vbz_size_t(size_fn(options->integer_size, max_size));
+ if (vbz_is_error(max_size))
+ {
+ return max_size;
+ }
+ }
+
+ if (options->zstd_compression_level != 0)
+ {
+ max_size = vbz_size_t(ZSTD_compressBound(max_size));
+ }
+
+ // Always include sized header for simplicity.
+ return max_size + sizeof(VbzSizedHeader);
+}
+
+vbz_size_t vbz_compress(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ CompressionOptions const* options)
+{
+ auto current_source = make_data_buffer(source, source_size);
+ auto dest_buffer = make_data_buffer(destination, destination_capacity);
+
+ if (options->zstd_compression_level == 0 && options->integer_size == 0)
+ {
+ copy_buffer(current_source, dest_buffer);
+ return source_size;
+ }
+
+ // optional intermediate buffer - allocated if needed later, but stored for
+ // duration of call.
+ std::unique_ptr<void, free_delete> intermediate_storage;
+
+ if (options->integer_size != 0)
+ {
+ auto size_fn = vbz_max_streamvbyte_compressed_size_v0;
+ if (options->vbz_version == 1)
+ {
+ size_fn = vbz_max_streamvbyte_compressed_size_v1;
+ }
+ else if (options->vbz_version != 0)
+ {
+ return VBZ_VERSION_ERROR;
+ }
+
+ auto max_stream_v_byte_size = size_fn(
+ options->integer_size,
+ vbz_size_t(current_source.size())
+ );
+ if (vbz_is_error(max_stream_v_byte_size))
+ {
+ return max_stream_v_byte_size;
+ }
+
+ auto streamvbyte_dest = dest_buffer;
+ if (options->zstd_compression_level != 0)
+ {
+ intermediate_storage.reset(malloc(max_stream_v_byte_size));
+ streamvbyte_dest = make_data_buffer(intermediate_storage.get(), max_stream_v_byte_size);
+ }
+ else
+ {
+ assert(max_stream_v_byte_size <= destination_capacity);
+ }
+
+ auto compress_fn = vbz_delta_zig_zag_streamvbyte_compress_v0;
+ if (options->vbz_version == 1)
+ {
+ compress_fn = vbz_delta_zig_zag_streamvbyte_compress_v1;
+ }
+ else if (options->vbz_version != 0)
+ {
+ return VBZ_VERSION_ERROR;
+ }
+
+ auto compressed_size = compress_fn(
+ current_source.data(),
+ vbz_size_t(current_source.size()),
+ streamvbyte_dest.data(),
+ vbz_size_t(streamvbyte_dest.size()),
+ options->integer_size,
+ options->perform_delta_zig_zag
+ );
+
+ current_source = make_data_buffer(streamvbyte_dest.data(), compressed_size);
+ }
+
+ if (options->zstd_compression_level == 0)
+ {
+ // destination already written to above.
+ return vbz_size_t(current_source.size());
+ }
+
+ auto compressed_size = ZSTD_compress(
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ current_source.data(),
+ vbz_size_t(current_source.size()),
+ options->zstd_compression_level
+ );
+ if (ZSTD_isError(compressed_size))
+ {
+ return VBZ_ZSTD_ERROR;
+ }
+
+
+ return vbz_size_t(compressed_size);
+}
+
+vbz_size_t vbz_decompress(
+ const void* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_size,
+ CompressionOptions const* options)
+{
+ auto current_source = make_data_buffer(source, source_size);
+ auto dest_buffer = make_data_buffer(destination, destination_size);
+
+ // If nothing is enabled, just do a copy between buffers and return.
+ if (options->zstd_compression_level == 0 && options->integer_size == 0)
+ {
+ copy_buffer(current_source, dest_buffer);
+ return source_size;
+ }
+
+ // optional intermediate buffer - allocated if needed later, but stored for
+ // duration of call.
+ std::unique_ptr<void, free_delete> intermediate_storage;
+
+ if (options->zstd_compression_level != 0)
+ {
+ auto max_zstd_decompressed_size = ZSTD_getFrameContentSize(source, source_size);
+ if (ZSTD_isError(max_zstd_decompressed_size))
+ {
+ return VBZ_ZSTD_ERROR;
+ }
+
+ auto zstd_dest = dest_buffer;
+ if (options->integer_size != 0)
+ {
+ intermediate_storage.reset(malloc(max_zstd_decompressed_size));
+ zstd_dest = make_data_buffer(intermediate_storage.get(), (vbz_size_t)max_zstd_decompressed_size);
+ }
+ else
+ {
+ assert(max_zstd_decompressed_size <= destination_size);
+ }
+
+ auto compressed_size = ZSTD_decompress(
+ zstd_dest.data(),
+ zstd_dest.size(),
+ current_source.data(),
+ current_source.size()
+ );
+ if (ZSTD_isError(compressed_size))
+ {
+ return VBZ_ZSTD_ERROR;
+ }
+ current_source = make_data_buffer(zstd_dest.data(), vbz_size_t(compressed_size));
+ }
+
+ // if streamvbyte is disabled, return early.
+ if (options->integer_size == 0)
+ {
+ return vbz_size_t(current_source.size());
+ }
+
+ auto decompress_fn = vbz_delta_zig_zag_streamvbyte_decompress_v0;
+ if (options->vbz_version == 1)
+ {
+ decompress_fn = vbz_delta_zig_zag_streamvbyte_decompress_v1;
+ }
+ else if (options->vbz_version != 0)
+ {
+ return VBZ_VERSION_ERROR;
+ }
+
+ return decompress_fn(
+ current_source.data(),
+ vbz_size_t(current_source.size()),
+ dest_buffer.data(),
+ vbz_size_t(dest_buffer.size()),
+ options->integer_size,
+ options->perform_delta_zig_zag
+ );
+}
+
+vbz_size_t vbz_compress_sized(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ CompressionOptions const* options)
+{
+ auto dest_buffer = make_data_buffer(destination, destination_capacity);
+
+ // Extract header information
+ auto& dest_header = dest_buffer.subspan(0, sizeof(VbzSizedHeader)).as_span<VbzSizedHeader>()[0];
+ dest_header.original_size = source_size;
+
+ // Compress data info remaining dest buffer
+ auto dest_compressed_data = dest_buffer.subspan(sizeof(VbzSizedHeader));
+ auto compressed_size = vbz_compress(
+ source,
+ source_size,
+ dest_compressed_data.data(),
+ vbz_size_t(dest_compressed_data.size()),
+ options
+ );
+
+ return compressed_size + sizeof(VbzSizedHeader);
+}
+
+vbz_size_t vbz_decompress_sized(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ CompressionOptions const* options)
+{
+ auto source_buffer = make_data_buffer(source, source_size);
+
+ if (source_buffer.size() < sizeof(VbzSizedHeader))
+ {
+ return VBZ_STREAMVBYTE_DESTINATION_SIZE_ERROR;
+ }
+
+ // Extract header information
+ auto const& source_header = source_buffer.subspan(0, sizeof(VbzSizedHeader)).as_span<VbzSizedHeader const>()[0];
+ if (destination_capacity < source_header.original_size)
+ {
+ return VBZ_STREAMVBYTE_DESTINATION_SIZE_ERROR;
+ }
+
+ // Compress data info remaining dest buffer
+ auto src_compressed_data = source_buffer.subspan(sizeof(VbzSizedHeader));
+ return vbz_decompress(
+ src_compressed_data.data(),
+ vbz_size_t(src_compressed_data.size()),
+ destination,
+ source_header.original_size,
+ options
+ );
+}
+
+vbz_size_t vbz_decompressed_size(
+ void const* source,
+ vbz_size_t source_size,
+ CompressionOptions const* options)
+{
+ auto source_buffer = make_data_buffer(source, source_size);
+
+ auto const& source_header = source_buffer.subspan(0, sizeof(VbzSizedHeader)).as_span<VbzSizedHeader const>()[0];
+ return source_header.original_size;
+}
+
+
+}
diff --git a/vbz/vbz.h b/vbz/vbz.h
new file mode 100644
index 0000000..b7bd292
--- /dev/null
+++ b/vbz/vbz.h
@@ -0,0 +1,138 @@
+#pragma once
+
+#include "vbz/vbz_export.h"
+
+#include <stdint.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#define VBZ_DEFAULT_VERSION 0
+
+typedef uint32_t vbz_size_t;
+
+#define VBZ_ZSTD_ERROR ((vbz_size_t)-1)
+#define VBZ_STREAMVBYTE_INPUT_SIZE_ERROR ((vbz_size_t)-2)
+#define VBZ_STREAMVBYTE_INTEGER_SIZE_ERROR ((vbz_size_t)-3)
+#define VBZ_STREAMVBYTE_DESTINATION_SIZE_ERROR ((vbz_size_t)-4)
+#define VBZ_STREAMVBYTE_STREAM_ERROR ((vbz_size_t)-5)
+#define VBZ_VERSION_ERROR ((vbz_size_t)-6)
+#define VBZ_FIRST_ERROR VBZ_VERSION_ERROR
+
+struct CompressionOptions
+{
+ // Flag to indicate the data should be converted to delta
+ // then have zig zag encoding applied.
+ // This causes similar signed numbers close to zero to end
+ // up close to zero in unsigned space, and compresses better
+ // when performing variable integer compression.
+ bool perform_delta_zig_zag;
+ // Used to select the variable integer compression technique
+ // Should be one of 1, 2 or 4.
+ // Using a level of 1 will cause no variable integer encoding
+ // to be performed.
+ unsigned int integer_size;
+ // zstd compression to apply.
+ // Should be in the range "ZSTD_minCLevel" to "ZSTD_maxCLevel".
+ // 1 gives the best performance and still provides a sensible compression
+ // higher numbers use more CPU time for higher compression ratios.
+ // Passing 0 will cause zstd to not be applied to data.
+ unsigned int zstd_compression_level;
+
+ // version of vbz to apply.
+ // Should be initialised to 'VBZ_DEFAULT_VERSION' for the best, newest compression.
+ // of set to older values to decompress older streams.
+ unsigned int vbz_version;
+};
+
+/// \brief Find if a return value from a function is an error value.
+VBZ_EXPORT bool vbz_is_error(vbz_size_t result_value);
+
+/// \brief Find a string description for an error value
+VBZ_EXPORT char const* vbz_error_string(vbz_size_t error_value);
+
+/// \brief Find a theoretical max size for compressed output size.
+/// should be used to find the size of the destination buffer to allocate.
+/// \param source_size The size of the source buffer for compression in bytes.
+/// \param options The options which will be used to compress data.
+VBZ_EXPORT vbz_size_t vbz_max_compressed_size(
+ vbz_size_t source_size,
+ CompressionOptions const* options);
+
+/// \brief Compress data into a provided output buffer
+/// \param source Source data for compression.
+/// \param source_size Source data size (in bytes)
+/// \param destination Destination buffer for compressed output.
+/// \param destination_capacity Size of the destination buffer to write to (see #max_compressed_size)
+/// \param options Options controlling compression to apply.
+/// \return The size of the compressed object in bytes, or an error code if something went wrong.
+VBZ_EXPORT vbz_size_t vbz_compress(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ CompressionOptions const* options);
+
+/// \brief Decompress data into a provided output buffer
+/// \param source Source compressed data for decompression.
+/// \param source_size Compressed Source data size (in bytes)
+/// \param destination Destination buffer for decompressed output.
+/// \param destination_size Size of the destination buffer to write to in bytes.
+/// This must be a multiple of integer_size, and equal to the number of
+/// expected output bytes exactly. The caller is expected to store this information alongside
+/// the compressed data.
+/// \param options Options controlling decompression to
+/// apply (must be the same as the arguments passed to #vbz_compress).
+/// \return The size of the decompressed object in bytes (will equal destination_size unless an error occurs).
+VBZ_EXPORT vbz_size_t vbz_decompress(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_size,
+ CompressionOptions const* options);
+
+/// \brief Compress data into a provided output buffer, with the original size information stored.
+/// \note Must decompress data with #vbz_decompress_sized.
+/// \param source Source data for compression.
+/// \param source_size Source data size (in bytes)
+/// \param destination Destination buffer for compressed output.
+/// \param destination_capacity Size of the destination buffer to write to (see #max_compressed_size)
+/// \param options Options controlling compression to apply.
+/// \return The size of the compressed object in bytes, or an error code if something went wrong.
+VBZ_EXPORT vbz_size_t vbz_compress_sized(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ CompressionOptions const* options);
+
+/// \brief Decompress data into a provided output buffer, using size information stored with the compressed data.
+/// \note Must decompress data stored with #vbz_compress_sized.
+/// \param source Source compressed data for decompression.
+/// \param source_size Compressed Source data size (in bytes)
+/// \param destination Destination buffer for decompressed output.
+/// \param destination_capacity Capacity of the destination buffer, should be at least #vbz_max_decompressed_size bytes.
+/// \param options Options controlling decompression to
+/// apply (must be the same as the arguments passed to #vbz_compress_sized).
+/// \return The size of the decompressed object in bytes, or an error code if something went wrong.
+VBZ_EXPORT vbz_size_t vbz_decompress_sized(
+ void const* source,
+ vbz_size_t source_size,
+ void* destination,
+ vbz_size_t destination_capacity,
+ CompressionOptions const* options);
+
+/// \brief Find the size for a decompressed block.
+/// should be used to find the size of the destination buffer to allocate for decompression.
+/// \param source Source compressed data for decompression.
+/// \param source_size The size of the compressed source buffer in bytes.
+/// \param options The options which will be used to decompress data.
+VBZ_EXPORT vbz_size_t vbz_decompressed_size(
+ void const* source,
+ vbz_size_t source_size,
+ CompressionOptions const* options);
+
+#if defined(__cplusplus)
+}
+#endif
diff --git a/vbz_plugin/CMakeLists.txt b/vbz_plugin/CMakeLists.txt
new file mode 100644
index 0000000..e4612f0
--- /dev/null
+++ b/vbz_plugin/CMakeLists.txt
@@ -0,0 +1,105 @@
+
+add_library(vbz_hdf_plugin
+ vbz_plugin_user_utils.h
+ vbz_plugin.cpp
+ vbz_plugin.h
+)
+add_sanitizers(vbz_hdf_plugin)
+
+generate_export_header(vbz_hdf_plugin EXPORT_FILE_NAME vbz_plugin/vbz_hdf_plugin_export.h)
+
+set_property(TARGET vbz_hdf_plugin PROPERTY CXX_STANDARD 11)
+
+if(WIN32 AND HDF5_USE_STATIC_LIBRARIES)
+ # See vbz_plugin.cpp -- if also building with Python on Windows then the runtime
+ # used is determined by that Python version, so we only support dynamic builds.
+ if(ENABLE_PYTHON)
+ message(FATAL_ERROR "Cannot enable HDF5_USE_STATIC_LIBRARIES as well as ENABLE_PYTHON")
+ else()
+ add_definitions(-DHDF5_USE_STATIC_LIBRARIES)
+ endif()
+endif()
+
+target_include_directories(
+ vbz_hdf_plugin
+ PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/
+)
+
+target_link_libraries(vbz_hdf_plugin
+ PRIVATE
+ vbz
+)
+
+if (${CMAKE_CXX_COMPILER_ID} MATCHES "Intel" AND NOT WIN32)
+ target_link_libraries(vbz_hdf_plugin
+ PRIVATE
+ $<$<CXX_COMPILER_ID:Intel>:-static-intel>
+ $<$<CXX_COMPILER_ID:Intel>:-mkl=sequential>
+ $<$<CXX_COMPILER_ID:Intel>:-wd10237>
+ )
+endif()
+
+if (ENABLE_CODE_SIGNING)
+ hdf_add_signing_command(vbz_hdf_plugin)
+endif()
+
+if (WIN32)
+ target_compile_definitions(vbz_hdf_plugin
+ PRIVATE
+ -D_CRT_SECURE_NO_WARNINGS
+ )
+endif()
+
+if (BUILD_TESTING)
+ if (HDF5_FOUND)
+ add_subdirectory(hdf_test_utils)
+
+ add_subdirectory(test)
+
+ if (ENABLE_PERF_TESTING)
+ add_subdirectory(perf)
+ endif()
+ else()
+ message(STATUS "Not building hdf5 testing as hdf5 not found")
+ endif()
+endif()
+
+if (NOT VBZ_BUILD_ARCHIVE)
+ set(VBZ_PLUGIN_COMPONENT COMPONENT hdf_plugin)
+endif()
+
+set(INSTALL_DESTINATION "hdf5/lib/plugin")
+if (STANDARD_LIB_INSTALL)
+ set(VBZ_PLUGIN_COMPONENT COMPONENT vbz_hdf_plugin)
+ set_target_properties(vbz_hdf_plugin
+ PROPERTIES
+ VERSION ${PROJECT_VERSION}
+ SOVERSION ${PROJECT_VERSION_MAJOR}
+ )
+ if(WIN32)
+ set(INSTALL_DESTINATION "bin")
+ else()
+ set(INSTALL_DESTINATION "lib")
+ endif()
+elseif (VBZ_BUILD_ARCHIVE)
+ set(INSTALL_DESTINATION "bin")
+endif()
+
+install(
+ TARGETS vbz_hdf_plugin
+ DESTINATION ${INSTALL_DESTINATION}
+ ${VBZ_PLUGIN_COMPONENT}
+)
+
+if (APPLE AND VBZ_CODESIGN_IDENTITY AND VBZ_CODESIGN_KEYCHAIN)
+ add_custom_command(
+ TARGET vbz_hdf_plugin
+ POST_BUILD
+ COMMAND codesign -s "${VBZ_CODESIGN_IDENTITY}" "${VBZ_CODESIGN_KEYCHAIN}" --force --deep -vvvv $<TARGET_FILE:vbz_hdf_plugin>
+ COMMENT "Signing vbz_hdf_plugin with ${VBZ_CODESIGN_IDENTITY}"
+ )
+endif()
diff --git a/vbz_plugin/hdf5_dynamic.h b/vbz_plugin/hdf5_dynamic.h
new file mode 100644
index 0000000..575f0a7
--- /dev/null
+++ b/vbz_plugin/hdf5_dynamic.h
@@ -0,0 +1,145 @@
+#pragma once
+
+#include <dlfcn.h>
+
+#include <iostream>
+
+typedef int herr_t;
+typedef int H5Z_filter_t;
+typedef int htri_t;
+
+#ifdef HDF5_1_10_BUILD
+typedef int64_t hid_t;
+#else
+typedef int32_t hid_t;
+#endif
+
+#define H5E_DEFAULT (hid_t)0
+#define H5E_CANTREGISTER (*hdf5_dynamic::H5E_CANTREGISTER_g)
+#define H5Z_FLAG_REVERSE 0x0100 /*reverse direction; read */
+#define H5Z_CLASS_T_VERS (1)
+
+#define H5E_ERR_CLS (*hdf5_dynamic::H5E_ERR_CLS_g)
+#define H5E_CALLBACK (*hdf5_dynamic::H5E_CALLBACK_g)
+#define H5E_PLINE (*hdf5_dynamic::H5E_PLINE_g)
+
+#define H5T_NATIVE_UCHAR (*hdf5_dynamic::H5T_NATIVE_UCHAR_g)
+#define H5T_NATIVE_UINT8 (*hdf5_dynamic::H5T_NATIVE_UINT8_g)
+#define H5T_NATIVE_USHORT (*hdf5_dynamic::H5T_NATIVE_USHORT_g)
+#define H5T_NATIVE_UINT16 (*hdf5_dynamic::H5T_NATIVE_UINT16_g)
+#define H5T_NATIVE_UINT (*hdf5_dynamic::H5T_NATIVE_UINT_g)
+#define H5T_NATIVE_UINT32 (*hdf5_dynamic::H5T_NATIVE_UINT32_g)
+
+namespace hdf5_dynamic
+{
+
+void* lookup_symbol(char const* name)
+{
+ auto lib_handle = RTLD_DEFAULT;
+ if (auto lib_name = getenv("HDF5_LIB_PATH"))
+ {
+ std::cout << "Lookup symbols in specific lib " << lib_name << std::endl;
+ lib_handle = dlopen(lib_name, RTLD_LAZY|RTLD_GLOBAL);
+ if (!lib_handle)
+ {
+ std::cerr << dlerror() << std::endl;
+ std::abort();
+ }
+ }
+
+ auto sym = dlsym(lib_handle, name);
+ std::cout << "Lookup symbol " << name << ": " << sym << std::endl;
+ if (!sym)
+ {
+ std::cerr << dlerror() << std::endl;
+ std::abort();
+ }
+}
+
+template<typename Signature> class FunctionLookup;
+
+template<typename Ret, typename... Args>
+class FunctionLookup<Ret(Args...)>
+{
+public:
+ using FunctionPtrType = Ret(*)(Args...);
+
+ static FunctionPtrType lookup(char const* name)
+ {
+ return (FunctionPtrType)lookup_symbol(name);
+ }
+};
+
+template <typename T>
+class GlobalLookup
+{
+public:
+ static T* lookup(char const* name)
+ {
+ return (T*)lookup_symbol(name);
+ }
+};
+
+typedef htri_t (*H5Z_can_apply_func_t)(hid_t dcpl_id, hid_t type_id, hid_t space_id);
+typedef herr_t (*H5Z_set_local_func_t)(hid_t dcpl_id, hid_t type_id, hid_t space_id);
+typedef size_t (*H5Z_func_t)(unsigned int flags, size_t cd_nelmts,
+ const unsigned int cd_values[], size_t nbytes,
+ size_t *buf_size, void **buf);
+
+typedef struct H5Z_class_t {
+ int version; /* Version number of the H5Z_class_t struct */
+ H5Z_filter_t id; /* Filter ID number */
+ unsigned encoder_present; /* Does this filter have an encoder? */
+ unsigned decoder_present; /* Does this filter have a decoder? */
+ const char *name; /* Comment for debugging */
+ H5Z_can_apply_func_t can_apply; /* The "can apply" callback for a filter */
+ H5Z_set_local_func_t set_local; /* The "set local" callback for a filter */
+ H5Z_func_t filter; /* The actual filter function */
+} H5Z_class_t;
+
+typedef enum H5PL_type_t {
+ H5PL_TYPE_ERROR = -1, /* Error */
+ H5PL_TYPE_FILTER = 0, /* Filter */
+ H5PL_TYPE_NONE = 1 /* This must be last! */
+} H5PL_type_t;
+
+namespace function_defs
+{
+herr_t H5check_version(unsigned majnum, unsigned minnum, unsigned relnum);
+herr_t H5Pget_filter_by_id2(hid_t plist_id, H5Z_filter_t id,
+ unsigned int *flags/*out*/, size_t *cd_nelmts/*out*/,
+ unsigned cd_values[]/*out*/, size_t namelen, char name[]/*out*/,
+ unsigned *filter_config/*out*/);
+herr_t H5Pmodify_filter(hid_t plist_id, H5Z_filter_t filter,
+ unsigned int flags, size_t cd_nelmts,
+ const unsigned int cd_values[/*cd_nelmts*/]);
+herr_t H5Zregister(const void *cls);
+size_t H5Tget_size(hid_t type_id);
+size_t H5Tget_size(hid_t type_id);
+herr_t H5Epush2(hid_t err_stack, const char *file, const char *func, unsigned line,
+ hid_t cls_id, hid_t maj_id, hid_t min_id, const char *msg, ...);
+}
+
+static auto H5check_version = FunctionLookup<decltype(function_defs::H5check_version)>::lookup("H5check_version");
+static auto H5Pget_filter_by_id2 = FunctionLookup<decltype(function_defs::H5Pget_filter_by_id2)>::lookup("H5Pget_filter_by_id2");
+static auto H5Pmodify_filter = FunctionLookup<decltype(function_defs::H5Pmodify_filter)>::lookup("H5Pmodify_filter");
+static auto H5Zregister = FunctionLookup<decltype(function_defs::H5Zregister)>::lookup("H5Zregister");
+static auto H5Tget_size = FunctionLookup<decltype(function_defs::H5Tget_size)>::lookup("H5Tget_size");
+
+// Uses c varargs so a bit trickier to templatise
+using H5Epush2Type = decltype(function_defs::H5Epush2);
+static auto H5Epush2 = (H5Epush2Type*)lookup_symbol("H5Epush2");
+
+hid_t* H5E_ERR_CLS_g = GlobalLookup<hid_t>::lookup("H5E_ERR_CLS_g");
+hid_t* H5E_CANTREGISTER_g = GlobalLookup<hid_t>::lookup("H5E_CANTREGISTER_g");
+hid_t* H5E_CALLBACK_g = GlobalLookup<hid_t>::lookup("H5E_CALLBACK_g");
+hid_t* H5E_PLINE_g = GlobalLookup<hid_t>::lookup("H5E_PLINE_g");
+
+hid_t* H5T_NATIVE_UCHAR_g = GlobalLookup<hid_t>::lookup("H5T_NATIVE_UCHAR_g");
+hid_t* H5T_NATIVE_UINT8_g = GlobalLookup<hid_t>::lookup("H5T_NATIVE_UINT8_g");
+hid_t* H5T_NATIVE_USHORT_g = GlobalLookup<hid_t>::lookup("H5T_NATIVE_USHORT_g");
+hid_t* H5T_NATIVE_UINT16_g = GlobalLookup<hid_t>::lookup("H5T_NATIVE_UINT16_g");
+hid_t* H5T_NATIVE_UINT_g = GlobalLookup<hid_t>::lookup("H5T_NATIVE_UINT_g");
+hid_t* H5T_NATIVE_UINT32_g = GlobalLookup<hid_t>::lookup("H5T_NATIVE_UINT32_g");
+
+} \ No newline at end of file
diff --git a/vbz_plugin/hdf_test_utils/CMakeLists.txt b/vbz_plugin/hdf_test_utils/CMakeLists.txt
new file mode 100644
index 0000000..6f5cf3e
--- /dev/null
+++ b/vbz_plugin/hdf_test_utils/CMakeLists.txt
@@ -0,0 +1,17 @@
+add_library(hdf_test_utils STATIC
+ hdf_id_helper.cpp
+ hdf_id_helper.h
+)
+
+set_property(TARGET hdf_test_utils PROPERTY CXX_STANDARD 11)
+
+target_include_directories(hdf_test_utils
+ PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${HDF5_C_INCLUDE_DIRS}
+)
+
+target_link_libraries(hdf_test_utils
+ PRIVATE
+ ${HDF5_C_LIBRARIES}
+)
diff --git a/vbz_plugin/hdf_test_utils/hdf_id_helper.cpp b/vbz_plugin/hdf_test_utils/hdf_id_helper.cpp
new file mode 100644
index 0000000..f190e12
--- /dev/null
+++ b/vbz_plugin/hdf_test_utils/hdf_id_helper.cpp
@@ -0,0 +1,83 @@
+#include "hdf_id_helper.h"
+
+#define THROW(_ex) throw _ex
+
+#define THROW_ON_ERROR(code) \
+ if (code < 0) THROW(Exception())
+
+namespace ont { namespace hdf5 {
+
+static_assert(std::is_same<Id,hid_t>::value, "Mismatched ID types");
+
+IdRef IdRef::claim(Id id)
+{
+ if (id < 0 || H5Iis_valid(id) <= 0) {
+ THROW(Exception());
+ }
+ return IdRef(id);
+}
+
+IdRef IdRef::ref(Id id)
+{
+ assert(id >= 0);
+ THROW_ON_ERROR(H5Iinc_ref(id));
+ return IdRef(id);
+}
+
+IdRef IdRef::global_ref(Id id)
+{
+ assert(id >= 0);
+
+ // Increment the index here - never decrementing it.
+ THROW_ON_ERROR(H5Iinc_ref(id));
+ return global(id);
+}
+
+IdRef::IdRef(IdRef const& other)
+ : m_id(other.m_id)
+ , m_is_global_constant(other.m_is_global_constant)
+{
+ if (!m_is_global_constant && m_id >= 0) {
+ THROW_ON_ERROR(H5Iinc_ref(m_id));
+ }
+}
+
+IdRef& IdRef::operator=(IdRef const& other)
+{
+ if (!other.m_is_global_constant && other.m_id >= 0) {
+ THROW_ON_ERROR(H5Iinc_ref(other.m_id));
+ }
+ if (!m_is_global_constant && m_id >= 0) {
+ auto result = H5Idec_ref(m_id);
+ if (result < 0) {
+ // this will be logged by the auto-logging code
+ // (see install_error_function)
+ assert(false);
+ }
+ }
+ m_is_global_constant = other.m_is_global_constant;
+ m_id = other.m_id;
+ return *this;
+}
+
+IdRef::~IdRef()
+{
+ if (!m_is_global_constant && m_id >= 0) {
+ auto result = H5Idec_ref(m_id);
+ if (result < 0) {
+ // this will be logged by the auto-logging code
+ // (see install_error_function)
+ assert(false);
+ }
+ }
+}
+
+int IdRef::ref_count() const
+{
+ if (m_id < 0) {
+ return 0;
+ }
+ return H5Iget_ref(m_id);
+}
+
+}} \ No newline at end of file
diff --git a/vbz_plugin/hdf_test_utils/hdf_id_helper.h b/vbz_plugin/hdf_test_utils/hdf_id_helper.h
new file mode 100644
index 0000000..6484094
--- /dev/null
+++ b/vbz_plugin/hdf_test_utils/hdf_id_helper.h
@@ -0,0 +1,133 @@
+#pragma once
+
+#include <cassert>
+#include <cstdint>
+#include <stdexcept>
+#include <utility>
+
+#include <hdf5.h>
+
+namespace ont { namespace hdf5 {
+
+/// Thrown when something goes wrong internally in HDF5.
+class Exception : public std::runtime_error
+{
+public:
+ Exception()
+ : std::runtime_error("HDF5 exception")
+ {
+ }
+};
+
+/// An HDF5 identifier.
+///
+/// IdRef should be used by anything that wants to keep a reference to a HDF5
+/// object.
+using Id = hid_t;
+
+/// Maintains a reference to an HDF5 identifier.
+///
+/// When you first create the identifier, use IdRef::claim() to grab it and make
+/// sure it will be closed.
+class IdRef final
+{
+public:
+ /// Create an IdRef that takes ownership of an existing reference.
+ ///
+ /// This is intended for use when you receive an ID from the HDF5 library.
+ ///
+ /// The reference counter will be decremented on destruction, but will not
+ /// be incremented.
+ static IdRef claim(Id id);
+
+ /// Create an IdRef that takes a new reference to the ID.
+ ///
+ /// The reference counter will be incremented on creation, and decremented
+ /// on destruction.
+ static IdRef ref(Id id);
+
+ /// Create an IdRef that refers to a global ID.
+ ///
+ /// No reference counting will be done.
+ static IdRef global(Id id)
+ {
+ return IdRef(id, true);
+ }
+
+ /// Create an IdRef that refers to a global ID. This call
+ /// takes a non-global id and makes it global.
+ ///
+ /// No reference counting will be done.
+ static IdRef global_ref(Id id);
+
+ /// Create an invalid IdRef.
+ ///
+ /// The only use for the resulting object is to copy or move into it.
+ IdRef() = default;
+
+ IdRef(IdRef const& other);
+ IdRef& operator=(IdRef const&);
+
+ IdRef(IdRef && other)
+ : m_id(other.m_id)
+ , m_is_global_constant(other.m_is_global_constant)
+ {
+ other.m_id = -1;
+ other.m_is_global_constant = false;
+ }
+ IdRef& operator=(IdRef && other)
+ {
+ std::swap(m_id, other.m_id);
+ std::swap(m_is_global_constant, other.m_is_global_constant);
+ return *this;
+ }
+
+ ~IdRef();
+
+ void swap(IdRef & other) {
+ std::swap(m_id, other.m_id);
+ std::swap(m_is_global_constant, other.m_is_global_constant);
+ }
+
+ /// Take ownership of the ID.
+ ///
+ /// This object will no longer hold a reference to the ID. It is up to the
+ /// called to deref the ID.
+ Id release() {
+ Id id = m_id;
+ m_id = -1;
+ m_is_global_constant = false;
+ return id;
+ }
+
+ /// Get the ID.
+ ///
+ /// The reference count will not be changed. This is mostly for passing into
+ /// HDF5 function calls.
+ Id get() const
+ {
+ assert(m_id >= 0);
+ return m_id;
+ }
+
+ /// Get the reference count of the ID.
+ int ref_count() const;
+
+ /// Check whether this IdRef contains an ID.
+ ///
+ /// Note that it does not check whether HDF5 thinks the ID is valid.
+ explicit operator bool() const { return m_id >= 0; }
+
+private:
+ // use claim() or ref()
+ explicit IdRef(Id id) : m_id(id), m_is_global_constant(false) {}
+ explicit IdRef(Id id, bool is_global)
+ : m_id(id)
+ , m_is_global_constant(is_global)
+ {}
+
+ Id m_id = -1;
+ bool m_is_global_constant = false;
+};
+
+}} \ No newline at end of file
diff --git a/vbz_plugin/perf/CMakeLists.txt b/vbz_plugin/perf/CMakeLists.txt
new file mode 100644
index 0000000..4762271
--- /dev/null
+++ b/vbz_plugin/perf/CMakeLists.txt
@@ -0,0 +1,22 @@
+find_package(GoogleBenchmark)
+
+add_executable(vbz_hdf_perf_test
+ vbz_hdf_perf.cpp
+)
+add_sanitizers(vbz_hdf_perf_test)
+
+target_link_libraries(vbz_hdf_perf_test
+ PRIVATE
+ google::benchmark
+ ${HDF5_C_LIBRARIES}
+ hdf_test_utils
+ vbz_hdf_plugin
+)
+
+set_property(TARGET vbz_hdf_perf_test PROPERTY CXX_STANDARD 11)
+
+add_test(
+ NAME vbz_hdf_perf_test
+ COMMAND vbz_hdf_perf_test
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+)
diff --git a/vbz_plugin/perf/vbz_hdf_perf.cpp b/vbz_plugin/perf/vbz_hdf_perf.cpp
new file mode 100644
index 0000000..6182da2
--- /dev/null
+++ b/vbz_plugin/perf/vbz_hdf_perf.cpp
@@ -0,0 +1,175 @@
+#include "../test/test_utils.h"
+#include "../../vbz/perf/test_data_generator.h"
+
+#include "hdf_id_helper.h"
+#include "vbz_plugin.h"
+#include "vbz_plugin_user_utils.h"
+
+#include <hdf5.h>
+
+#include <array>
+
+#include <benchmark/benchmark.h>
+
+static bool plugin_init_result = vbz_register();
+
+template <typename IntType>
+hid_t get_h5_type()
+{
+ hid_t type = 0;
+ if (std::is_same<IntType, std::int8_t>::value)
+ {
+ type = H5T_NATIVE_UINT8;
+ }
+ else if (std::is_same<IntType, std::uint8_t>::value)
+ {
+ type = H5T_NATIVE_INT8;
+ }
+ else if (std::is_same<IntType, std::int16_t>::value)
+ {
+ type = H5T_NATIVE_UINT16;
+ }
+ else if (std::is_same<IntType, std::uint16_t>::value)
+ {
+ type = H5T_NATIVE_INT16;
+ }
+ else if (std::is_same<IntType, std::int32_t>::value)
+ {
+ type = H5T_NATIVE_UINT32;
+ }
+ else if (std::is_same<IntType, std::uint32_t>::value)
+ {
+ type = H5T_NATIVE_INT32;
+ }
+ else
+ {
+ std::abort();
+ }
+ return type;
+}
+
+template <bool UseZigZag, std::size_t ZstdLevel>
+void vbz_filter(hid_t creation_properties, int int_size)
+{
+ vbz_filter_enable(creation_properties, int_size, UseZigZag, ZstdLevel);
+}
+
+void zlib_filter(hid_t creation_properties, int)
+{
+ H5Pset_deflate(creation_properties, 1);
+}
+
+void no_filter(hid_t creation_properties, int)
+{
+}
+
+using FilterSetupFn = decltype(no_filter)*;
+
+template <typename Generator>
+void vbz_hdf_benchmark(benchmark::State& state, int integer_size, hid_t h5_type, FilterSetupFn setup_filter)
+{
+ (void)plugin_init_result;
+ std::size_t max_element_count = 0;
+ auto input_value_list = Generator::generate(max_element_count);
+
+ std::size_t item_count = 0;
+ for (auto _ : state)
+ {
+ std::size_t id = 0;
+
+ state.PauseTiming();
+ auto file_id = H5Fcreate("./test_file.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ auto file = IdRef::claim(file_id);
+ state.ResumeTiming();
+
+ item_count = 0;
+ for (auto const& input_values : input_value_list)
+ {
+ auto creation_properties = IdRef::claim(H5Pcreate(H5P_DATASET_CREATE));
+
+ std::array<hsize_t, 1> chunk_sizes{ { input_values.size() } };
+ H5Pset_chunk(creation_properties.get(), int(chunk_sizes.size()), chunk_sizes.data());
+
+ setup_filter(creation_properties.get(), integer_size);
+
+ std::string dset_name = std::to_string(id++);
+ auto dataset = create_dataset(file_id, dset_name.c_str(), h5_type, input_values.size(), creation_properties.get());
+
+ auto val = write_full_dataset(dataset.get(), h5_type, input_values);
+ item_count += input_values.size();
+ benchmark::DoNotOptimize(val);
+ }
+ }
+
+ state.SetItemsProcessed(state.iterations() * item_count);
+ state.SetBytesProcessed(state.iterations() * item_count * integer_size);
+}
+
+template <typename IntType, int ZstdLevel>
+void vbz_hdf_benchmark_sequence(benchmark::State& state)
+{
+ vbz_hdf_benchmark<SequenceGenerator<IntType>>(state, sizeof(IntType), get_h5_type<IntType>(), vbz_filter<true, ZstdLevel>);
+}
+
+template <typename IntType>
+void vbz_hdf_benchmark_sequence_uncompressed(benchmark::State& state)
+{
+ vbz_hdf_benchmark<SequenceGenerator<IntType>>(state, sizeof(IntType), get_h5_type<IntType>(), no_filter);
+}
+
+template <typename IntType>
+void vbz_hdf_benchmark_sequence_zlib(benchmark::State& state)
+{
+ vbz_hdf_benchmark<SequenceGenerator<IntType>>(state, sizeof(IntType), get_h5_type<IntType>(), zlib_filter);
+}
+
+template <typename IntType, int ZstdLevel>
+void vbz_hdf_benchmark_random(benchmark::State& state)
+{
+ vbz_hdf_benchmark<SignalGenerator<IntType>>(state, sizeof(IntType), get_h5_type<IntType>(), vbz_filter<true, ZstdLevel>);
+}
+
+template <typename IntType>
+void vbz_hdf_benchmark_random_uncompressed(benchmark::State& state)
+{
+ vbz_hdf_benchmark<SignalGenerator<IntType>>(state, sizeof(IntType), get_h5_type<IntType>(), no_filter);
+}
+
+template <typename IntType>
+void vbz_hdf_benchmark_random_zlib(benchmark::State& state)
+{
+ vbz_hdf_benchmark<SignalGenerator<IntType>>(state, sizeof(IntType), get_h5_type<IntType>(), zlib_filter);
+}
+
+/*BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_sequence, std::int8_t, 0);
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_sequence, std::int16_t, 0);
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_sequence, std::int32_t, 0);
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_sequence, std::int8_t, 1);
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_sequence, std::int16_t, 1);
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_sequence, std::int32_t, 1);
+
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_sequence_uncompressed, std::int8_t);
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_sequence_uncompressed, std::int16_t);
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_sequence_uncompressed, std::int32_t);
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_sequence_zlib, std::int8_t);
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_sequence_zlib, std::int16_t);
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_sequence_zlib, std::int32_t);*/
+
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_random, std::int8_t, 0);
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_random, std::int16_t, 0);
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_random, std::int32_t, 0);
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_random, std::int8_t, 1);
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_random, std::int16_t, 1);
+BENCHMARK_TEMPLATE2(vbz_hdf_benchmark_random, std::int32_t, 1);
+
+/*
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_random_uncompressed, std::int8_t);
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_random_uncompressed, std::int16_t);
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_random_uncompressed, std::int32_t);
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_random_zlib, std::int8_t);
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_random_zlib, std::int16_t);
+BENCHMARK_TEMPLATE(vbz_hdf_benchmark_random_zlib, std::int32_t);
+*/
+
+// Run the benchmark
+BENCHMARK_MAIN();
diff --git a/vbz_plugin/test/CMakeLists.txt b/vbz_plugin/test/CMakeLists.txt
new file mode 100644
index 0000000..d75ff95
--- /dev/null
+++ b/vbz_plugin/test/CMakeLists.txt
@@ -0,0 +1,20 @@
+add_executable(vbz_hdf_plugin_test
+ vbz_hdf_plugin_test.cpp
+ main.cpp
+)
+add_sanitizers(vbz_hdf_plugin_test)
+
+set_property(TARGET vbz_hdf_plugin_test PROPERTY CXX_STANDARD 11)
+
+target_link_libraries(vbz_hdf_plugin_test
+ PUBLIC
+ vbz_hdf_plugin
+ ${HDF5_C_LIBRARIES}
+ hdf_test_utils
+)
+
+add_test(
+ NAME vbz_hdf_plugin_test
+ COMMAND vbz_hdf_plugin_test "${CMAKE_SOURCE_DIR}/test_data"
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+)
diff --git a/vbz_plugin/test/main.cpp b/vbz_plugin/test/main.cpp
new file mode 100644
index 0000000..aca8cf3
--- /dev/null
+++ b/vbz_plugin/test/main.cpp
@@ -0,0 +1,2 @@
+#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
+#include "catch2/catch.hpp"
diff --git a/vbz_plugin/test/test_utils.h b/vbz_plugin/test/test_utils.h
new file mode 100644
index 0000000..b29e1c1
--- /dev/null
+++ b/vbz_plugin/test/test_utils.h
@@ -0,0 +1,108 @@
+#pragma once
+
+#include "hdf_id_helper.h"
+
+#include <vector>
+
+using namespace ont::hdf5;
+
+template <typename T>
+std::vector<T> read_1d_dataset(
+ hid_t parent,
+ char const* name,
+ hid_t expected_type
+ )
+{
+ if (H5Lexists(parent, name, H5P_DEFAULT) < 0)
+ {
+ return {};
+ }
+
+ auto dataset = IdRef::claim(H5Dopen(parent, name, H5P_DEFAULT));
+ auto type = IdRef::claim(H5Dget_type(dataset.get()));
+ auto dataspace = IdRef::claim(H5Dget_space(dataset.get()));
+
+ if (H5Tequal(type.get(), expected_type) < 0)
+ {
+ return {};
+ }
+
+ const int ndims = H5Sget_simple_extent_ndims(dataspace.get());
+ if (ndims != 1)
+ {
+ throw std::runtime_error("dataset isn't 1d");
+ }
+
+ hsize_t dims[1];
+ H5Sget_simple_extent_dims(dataspace.get(), dims, NULL);
+
+ std::vector<T> values(dims[0]);
+ auto buffer_space = IdRef::claim(
+ H5Screate_simple(1, dims, dims));
+ if (H5Dread(
+ dataset.get(),
+ expected_type,
+ buffer_space.get(),
+ H5S_ALL,
+ H5P_DEFAULT,
+ values.data()) < 0)
+ {
+ return {};
+ }
+
+ return values;
+}
+
+IdRef create_dataset(
+ hid_t parent,
+ char const* name,
+ hid_t type,
+ std::size_t size,
+ hid_t dataset_creation_properties)
+{
+ auto data_space = IdRef::claim(H5Screate(H5S_SIMPLE));
+ hsize_t size_arr[] = { size };
+ hsize_t max_size_arr[] = { size };
+ if (H5Sset_extent_simple(
+ data_space.get(),
+ 1,
+ size_arr,
+ max_size_arr) < 0)
+ {
+ return IdRef();
+ }
+
+ auto dataset_id = IdRef::claim(H5Dcreate(
+ parent,
+ name,
+ type,
+ data_space.get(),
+ H5P_DEFAULT,
+ dataset_creation_properties,
+ H5P_DEFAULT
+ )
+ );
+
+ return dataset_id;
+}
+
+template <typename T>
+bool write_full_dataset(
+ hid_t dataset,
+ hid_t type,
+ T const& data
+)
+{
+ if (H5Dwrite(
+ dataset,
+ type,
+ H5S_ALL,
+ H5S_ALL,
+ H5P_DEFAULT,
+ data.data()
+ ) < 0)
+ {
+ return false;
+ }
+ return true;
+}
diff --git a/vbz_plugin/test/vbz_hdf_plugin_test.cpp b/vbz_plugin/test/vbz_hdf_plugin_test.cpp
new file mode 100644
index 0000000..45f8ed0
--- /dev/null
+++ b/vbz_plugin/test/vbz_hdf_plugin_test.cpp
@@ -0,0 +1,137 @@
+#include "test_utils.h"
+#include "hdf_id_helper.h"
+#include "vbz_plugin.h"
+#include "vbz_plugin_user_utils.h"
+
+#include <hdf5.h>
+#include <catch2/catch.hpp>
+
+#include <array>
+#include <numeric>
+#include <random>
+
+static bool plugin_init_result = vbz_register();
+
+template <typename T> void run_linear_test(hid_t type, std::size_t count)
+{
+ (void)plugin_init_result;
+
+ GIVEN("An empty hdf file and a random data set")
+ {
+ auto file_id = H5Fcreate("./test_file.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ auto file = IdRef::claim(file_id);
+
+ // Generate an incrementing sequence of integers
+ std::vector<T> data(count);
+ std::iota(data.begin(), data.end(), 0);
+
+ WHEN("Inserting filtered data into file")
+ {
+ auto creation_properties = IdRef::claim(H5Pcreate(H5P_DATASET_CREATE));
+ std::array<hsize_t, 1> chunk_sizes{ { count / 8 } };
+ H5Pset_chunk(creation_properties.get(), int(chunk_sizes.size()), chunk_sizes.data());
+
+ vbz_filter_enable(creation_properties.get(), sizeof(T), true, 5);
+
+ auto dataset = create_dataset(file_id, "foo", type, data.size(), creation_properties.get());
+
+ write_full_dataset(dataset.get(), type, data);
+
+ THEN("Data is read back correctly")
+ {
+ auto read_data = read_1d_dataset<T>(file_id, "foo", type);
+ CHECK(read_data == data);
+ }
+ }
+ }
+}
+
+template<typename T>
+struct UniformIntDistribution {
+ using type = std::uniform_int_distribution<T>;
+};
+template<>
+struct UniformIntDistribution<uint8_t> {
+ // uint8_t isn't a valid parameter for uniform_int_distribution
+ using type = std::uniform_int_distribution<unsigned short>;
+};
+template<>
+struct UniformIntDistribution<int8_t> {
+ // int8_t isn't a valid parameter for uniform_int_distribution
+ using type = std::uniform_int_distribution<short>;
+};
+
+template <typename T> void run_random_test(hid_t type, std::size_t count)
+{
+ GIVEN("An empty hdf file and a random data set")
+ {
+ auto file_id = H5Fcreate("./test_file.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ auto file = IdRef::claim(file_id);
+
+ std::vector<T> data(count);
+
+ std::random_device rd;
+ std::default_random_engine random_engine(rd());
+ using Distribution = typename UniformIntDistribution<T>::type;
+ Distribution dist(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
+ for (auto& elem : data)
+ {
+ elem = T(dist(random_engine));
+ }
+
+ WHEN("Inserting filtered data into file")
+ {
+ auto creation_properties = IdRef::claim(H5Pcreate(H5P_DATASET_CREATE));
+ std::array<hsize_t, 1> chunk_sizes{ { count / 8 } };
+ H5Pset_chunk(creation_properties.get(), int(chunk_sizes.size()), chunk_sizes.data());
+ vbz_filter_enable(creation_properties.get(), sizeof(T), true, 1);
+
+ auto dataset = create_dataset(file_id, "foo", type, data.size(), creation_properties.get());
+
+ write_full_dataset(dataset.get(), type, data);
+
+ THEN("Data is read back correctly")
+ {
+ auto read_data = read_1d_dataset<T>(file_id, "foo", type);
+ CHECK(read_data == data);
+ }
+ }
+ }
+}
+
+SCENARIO("Using zstd filter on a int8 dataset")
+{
+ run_linear_test<std::int8_t>(H5T_NATIVE_INT8, 100);
+ run_random_test<std::int8_t>(H5T_NATIVE_INT8, 10 * 1000 * 1000);
+}
+
+SCENARIO("Using zstd filter on a int16 dataset")
+{
+ run_linear_test<std::int16_t>(H5T_NATIVE_INT16, 100);
+ run_random_test<std::int16_t>(H5T_NATIVE_INT16, 10 * 1000 * 1000);
+}
+
+SCENARIO("Using zstd filter on a int32 dataset")
+{
+ run_linear_test<std::int32_t>(H5T_NATIVE_INT32, 100);
+ run_random_test<std::int32_t>(H5T_NATIVE_INT32, 10 * 1000 * 1000);
+}
+
+SCENARIO("Using zstd filter on a uint8 dataset")
+{
+ run_linear_test<std::uint8_t>(H5T_NATIVE_UINT8, 100);
+ run_random_test<std::uint8_t>(H5T_NATIVE_UINT8, 10 * 1000 * 1000);
+}
+
+SCENARIO("Using zstd filter on a uint16 dataset")
+{
+ run_linear_test<std::uint16_t>(H5T_NATIVE_UINT16, 100);
+ run_random_test<std::uint16_t>(H5T_NATIVE_UINT16, 10 * 1000 * 1000);
+}
+
+SCENARIO("Using zstd filter on a uint32 dataset")
+{
+ run_linear_test<std::uint32_t>(H5T_NATIVE_UINT32, 100);
+ run_random_test<std::uint32_t>(H5T_NATIVE_UINT32, 10 * 1000 * 1000);
+}
+
diff --git a/vbz_plugin/vbz_plugin.cpp b/vbz_plugin/vbz_plugin.cpp
new file mode 100644
index 0000000..75e1612
--- /dev/null
+++ b/vbz_plugin/vbz_plugin.cpp
@@ -0,0 +1,261 @@
+#include "vbz_plugin/vbz_hdf_plugin_export.h"
+#include "vbz_plugin.h"
+#include "vbz.h"
+
+#include <gsl/gsl-lite.hpp>
+#include <hdf5/hdf5_plugin_types.h>
+
+#include <array>
+#include <chrono>
+#include <iostream>
+#include <memory>
+
+#ifdef _WIN32
+# ifndef NOMINMAX
+# define NOMINMAX
+#endif
+# include <Windows.h>
+#endif
+
+#define VBZ_DEBUG 0
+
+namespace {
+#if VBZ_DEBUG
+int checksum(gsl::span<char const> input)
+{
+ std::uint8_t output = 0x0;
+ for (auto x : input)
+ {
+ output ^= x;
+ }
+ return output;
+}
+#endif
+
+#if defined(_WIN32) && !defined(HDF5_USE_STATIC_LIBRARIES)
+HMODULE get_hdf_module()
+{
+ static HMODULE module = nullptr;
+ if (!module)
+ {
+ auto module_name = "hdf5.dll";
+ auto env_val = getenv("VBZ_DEBUG_HDF");
+ if (env_val && strcmp(env_val, "1") == 0)
+ {
+ module_name = "hdf5_D.dll";
+ }
+
+ module = LoadLibraryA(module_name);
+ }
+
+ if (!module)
+ {
+ std::cerr << "Failed to load hdf library" << std::endl;
+ std::abort();
+ }
+ return module;
+}
+
+#endif
+
+// Windows ends up using different runtimes/heaps depending on which
+// _python_ version hdf5 plugin was built against, the simple way to fix this
+// is to use whatever hdf5 uses for allocating memory.
+//
+void* h5_malloc(std::size_t size)
+{
+#if defined(_WIN32) && !defined(HDF5_USE_STATIC_LIBRARIES)
+ static auto module = get_hdf_module();
+
+ static auto malloc_memory = (void*(*)(size_t, bool))GetProcAddress(module, "H5allocate_memory");
+ return malloc_memory(size, false);
+#else
+ return malloc(size);
+#endif
+}
+
+void h5_free(void* memory)
+{
+#if defined(_WIN32) && !defined(HDF5_USE_STATIC_LIBRARIES)
+ static auto module = get_hdf_module();
+
+ static auto free_hdf5 = (int(*)(void *))GetProcAddress(module, "H5free_memory");
+ free_hdf5(memory);
+#else
+ free(memory);
+#endif
+}
+
+struct h5free_delete
+{
+ void operator()(void* x) { h5_free(x); }
+};
+
+
+}
+
+size_t vbz_filter(
+ unsigned flags,
+ size_t cd_nelmts,
+ const unsigned int cd_values[],
+ size_t nbytes,
+ size_t* buf_size,
+ void** buf)
+{
+ std::unique_ptr<void, h5free_delete> outbuf;
+ vbz_size_t outbuf_size = 0;
+ vbz_size_t outbuf_used_size = 0;
+
+ if (cd_nelmts < 3)
+ {
+ return 0;
+ }
+
+ unsigned int vbz_version = cd_values[FILTER_VBZ_VERSION_OPTION];
+ unsigned int integer_size = cd_values[FILTER_VBZ_INTEGER_SIZE_OPTION];
+ bool use_zig_zag = cd_values[FILTER_VBZ_USE_DELTA_ZIG_ZAG_COMPRESSION] != 0;
+
+ unsigned int compression_level = 1;
+ if (cd_nelmts > FILTER_VBZ_ZSTD_COMPRESSION_LEVEL_OPTION)
+ {
+ compression_level = cd_values[FILTER_VBZ_ZSTD_COMPRESSION_LEVEL_OPTION];
+ }
+
+ CompressionOptions options{ use_zig_zag, integer_size, compression_level, vbz_version };
+
+#if VBZ_DEBUG
+ std::cout << "======================================================\n"
+ << "Using options:"
+ << " integer_size: " << integer_size
+ << " use_zig_zag: " << use_zig_zag
+ << " compression_level: " << compression_level
+ << std::endl;
+#endif
+
+ // If decompressing
+ if (flags & H5Z_FLAG_REVERSE)
+ {
+ auto input_span = gsl::make_span(static_cast<char*>(*buf), *buf_size);
+ if (input_span.size() > std::numeric_limits<vbz_size_t>::max())
+ {
+ std::cerr << "vbz_filter: Chunk size too large." << std::endl;
+ return 0;
+ }
+
+#if VBZ_DEBUG
+ std::cout << "Decmpressing data with checksum " << checksum(input_span) << std::endl;
+#endif
+
+ auto const expected_uncompressed_size = vbz_decompressed_size(
+ input_span.data(),
+ vbz_size_t(input_span.size()),
+ &options);
+ if (vbz_is_error(expected_uncompressed_size))
+ {
+ std::cerr << "vbz_filter: size error" << std::endl;
+ return 0;
+ }
+ outbuf.reset(h5_malloc(expected_uncompressed_size));
+
+ outbuf_used_size = vbz_decompress_sized(
+ input_span.data(),
+ vbz_size_t(input_span.size()),
+ outbuf.get(),
+ expected_uncompressed_size,
+ &options);
+ if (vbz_is_error(outbuf_used_size))
+ {
+ std::cerr << "vbz_filter: compression error" << std::endl;
+ return 0;
+ }
+
+ if (outbuf_used_size != expected_uncompressed_size)
+ {
+ std::cerr << "vbz_filter: decompressed size error" << std::endl;
+ return 0;
+ }
+
+#if VBZ_DEBUG
+ std::cout << "Decompressed dataset from " << *buf_size << " bytes to " << outbuf_used_size
+ << " with checksum " << checksum(gsl::make_span(static_cast<char*>(outbuf.get()), outbuf_used_size)) << std::endl;
+#endif
+ }
+ else // compressing
+ {
+#if VBZ_DEBUG
+ std::cout << "Compressing data with checksum " << checksum(gsl::make_span(static_cast<char*>(*buf), *buf_size)) << std::endl;
+#endif
+ if (*buf_size > std::numeric_limits<vbz_size_t>::max())
+ {
+ std::cerr << "vbz_filter: Chunk size too large." << std::endl;
+ return 0;
+ }
+
+ auto const byte_remainder = *buf_size % integer_size;
+ if (byte_remainder != 0)
+ {
+ std::cerr << "vbz_filter: Invalid integer_size specified" << std::endl;
+ return 0;
+ }
+
+ outbuf_size = vbz_max_compressed_size(vbz_size_t(*buf_size), &options);
+ outbuf.reset(h5_malloc(outbuf_size));
+
+ auto output_span = gsl::make_span(static_cast<char*>(outbuf.get()), outbuf_size);
+
+ // do compress
+ outbuf_used_size += vbz_compress_sized(
+ *buf,
+ vbz_size_t(*buf_size),
+ output_span.data(),
+ vbz_size_t(output_span.size()),
+ &options
+ );
+ if (vbz_is_error(outbuf_used_size))
+ {
+ std::cerr << "vbz_filter: compression error" << std::endl;;
+ return 0;
+ }
+
+#if VBZ_DEBUG
+ std::cout << "Compressed dataset from " << *buf_size << " bytes to " << outbuf_used_size << " with checksum " << checksum(gsl::make_span(output_span.data(), outbuf_used_size)) << std::endl;
+#endif
+ }
+
+ h5_free(*buf);
+ *buf = outbuf.release();
+ *buf_size = outbuf_size;
+ return outbuf_used_size;
+}
+
+H5Z_class2_t const vbz_filter_struct = {
+ H5Z_CLASS_T_VERS, // version
+ FILTER_VBZ_ID, // id
+ 1, // encoder_present
+ 1, // decoder_present
+ "vbz", // name
+ nullptr, // can_apply
+ nullptr, // set_local
+ vbz_filter // filter
+};
+
+extern "C" VBZ_HDF_PLUGIN_EXPORT const void* vbz_plugin_info(void)
+{
+ return &vbz_filter_struct;
+}
+
+// hdf plugin hooks
+extern "C" VBZ_HDF_PLUGIN_EXPORT H5PL_type_t H5PLget_plugin_type(void)
+{
+ return H5PL_TYPE_FILTER;
+}
+
+// hdf plugin hooks
+extern "C" VBZ_HDF_PLUGIN_EXPORT const void* H5PLget_plugin_info(void)
+{
+#if VBZ_DEBUG
+ std::cout << "Registering vbz plugin" << std::endl;
+#endif
+
+ return vbz_plugin_info();
+}
diff --git a/vbz_plugin/vbz_plugin.h b/vbz_plugin/vbz_plugin.h
new file mode 100644
index 0000000..c1a54b5
--- /dev/null
+++ b/vbz_plugin/vbz_plugin.h
@@ -0,0 +1,10 @@
+#pragma once
+
+/// Filter ID
+/// \todo Register with hdf group
+#define FILTER_VBZ_ID 32020
+
+#define FILTER_VBZ_VERSION_OPTION 0
+#define FILTER_VBZ_INTEGER_SIZE_OPTION 1
+#define FILTER_VBZ_USE_DELTA_ZIG_ZAG_COMPRESSION 2
+#define FILTER_VBZ_ZSTD_COMPRESSION_LEVEL_OPTION 3
diff --git a/vbz_plugin/vbz_plugin_user_utils.h b/vbz_plugin/vbz_plugin_user_utils.h
new file mode 100644
index 0000000..9ddaee3
--- /dev/null
+++ b/vbz_plugin/vbz_plugin_user_utils.h
@@ -0,0 +1,62 @@
+#pragma once
+
+#include <hdf5.h>
+#include "vbz_plugin.h"
+
+#define FILTER_VBZ_VERSION 1
+
+extern "C" const void* vbz_plugin_info(void);
+
+/// \brief Call to enable the vbz filter on the specified creation properties.
+/// \param integer_size Size of integer type to be compressed. Leave at 0 to extract this information from the hdf type.
+/// \param use_zig_zag Control if zig zag encoding should be used on the type. If integer_size is not specified then the
+/// hdf type's signedness is used to fill in this field.
+/// \param zstd_compression_level Control the level of compression used to filter the dataset.
+/// \param vbz_version The version of compression to apply to user data.
+inline int vbz_filter_enable_versioned(
+ hid_t creation_properties,
+ unsigned int integer_size,
+ bool use_zig_zag,
+ unsigned int zstd_compression_level,
+ int vbz_version)
+{
+ unsigned int values[4] = {
+ (unsigned int)vbz_version,
+ integer_size,
+ use_zig_zag,
+ zstd_compression_level
+ };
+
+ return H5Pset_filter(creation_properties, FILTER_VBZ_ID, 0, 4, values);
+}
+
+/// \brief Call to enable the vbz filter on the specified creation properties.
+/// \param integer_size Size of integer type to be compressed. Leave at 0 to extract this information from the hdf type.
+/// \param use_zig_zag Control if zig zag encoding should be used on the type. If integer_size is not specified then the
+/// hdf type's signedness is used to fill in this field.
+/// \param zstd_compression_level Control the level of compression used to filter the dataset.
+inline int vbz_filter_enable(
+ hid_t creation_properties,
+ unsigned int integer_size,
+ bool use_zig_zag,
+ unsigned int zstd_compression_level)
+{
+ return vbz_filter_enable_versioned(
+ creation_properties,
+ integer_size,
+ use_zig_zag,
+ zstd_compression_level,
+ FILTER_VBZ_VERSION
+ );
+}
+
+inline bool vbz_register()
+{
+ int retval = H5Zregister(vbz_plugin_info());
+ if (retval < 0)
+ {
+ return 0;
+ }
+
+ return 1;
+}