diff --git a/.github/workflows/ccpp.yaml b/.github/workflows/ccpp.yaml index 17d9ddb2c..1ce70d864 100644 --- a/.github/workflows/ccpp.yaml +++ b/.github/workflows/ccpp.yaml @@ -19,7 +19,7 @@ jobs: - name: Install generic prerequisites run: | sudo apt-get update - sudo apt install -y libtbb-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libopenblas-dev liblapacke-dev + sudo apt install -y libtbb-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libopenblas-dev liblapacke-dev libfftw3-dev libsoapysdr-dev - name: Install OpenCV prerequisites run: | sudo apt-get update diff --git a/.github/workflows/ubuntu_no_opencv.yml b/.github/workflows/ubuntu_no_opencv.yml index 7f00ad312..0794b35ee 100644 --- a/.github/workflows/ubuntu_no_opencv.yml +++ b/.github/workflows/ubuntu_no_opencv.yml @@ -19,7 +19,7 @@ jobs: - name: Install generic prerequisites run: | sudo apt-get update - sudo apt install -y libtbb-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libopenblas-dev liblapacke-dev + sudo apt install -y libtbb-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libopenblas-dev liblapacke-dev libfftw3-dev libsoapysdr-dev - name: Install Qt run: | sudo apt install -y qt5-default qtscript-tools qtscript5-dev libqt5serialport5-dev diff --git a/BuildCoreCVS.bat b/BuildCoreCVS.bat new file mode 100644 index 000000000..02d1ce5fb --- /dev/null +++ b/BuildCoreCVS.bat @@ -0,0 +1,52 @@ +@echo off + +pushd %~dp0 + +set config=Release + +set build_sln=ON +if /i '%1' == 'OFF' set build_sln=OFF + +set configs=Release +set blddir=build + +call cmake\find_cmake.bat + +if not exist %blddir% mkdir %blddir% + +pushd %blddir% + +call "%MSVS_LOCATION%..\..\VC\Auxiliary\Build\vcvarsall.bat" x64 + +echo Generate CoreCVS sln + +cmake ..\ -G%generator_string% -Thost=x64 -DCMAKE_CONFIGURATION_TYPES=%configs% +if not %errorlevel% == 0 ( + echo CMake CoreCVS generation error! + popd + goto ERROR +) + +:BUILD +if '%build_sln%' == 'OFF' GOTO SUCCESS +echo CoreCVS is building +cmake --build . --config %config% -- /m /verbosity:normal +if not %errorlevel%==0 ( + echo CoreCVS build failed + popd + goto ERROR +) + +popd + +:SUCCESS +popd +exit /b 0 + +:USAGE +echo usage %~n0%~x0 [ON^|OFF] +echo arg1: ON=generate and build solution, OFF=generate solution only without build + +:ERROR + popd + exit /b 1 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ee06eae72..3c941b18e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,88 +1,117 @@ -cmake_minimum_required (VERSION 3.10) -project (CoreCVS) +cmake_minimum_required (VERSION 3.11) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) -set (CoreCVS_VERSION_MAJOR 1) -set (CoreCVS_VERSION_MINOR 0) +project(CoreCVS) -set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/") +set(CoreCVS_VERSION_MAJOR 1) +set(CoreCVS_VERSION_MINOR 0) + +# Debug/Release switch + +#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/") + +include(cmake/CMakeCpuOptions.cmake) +include(cmake/functions.cmake) +include(cmake/utility.cmake) + +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/bin) # Overall dependances option(USE_TBB "Should compile with TBB" YES) -IF ( USE_TBB ) - MESSAGE( STATUS "Including TBB on CORECVS build" ) +if(USE_TBB) + message(STATUS "Including TBB on CORECVS build") find_package(TBB REQUIRED) if (TBB_LIBRARY) add_definitions(-DWITH_TBB) endif() -ENDIF () - +endif() #option(USE_TBB "Should compile with FILESYSTEM" YES) -#IF ( USE_TBB ) -# MESSAGE( STATUS "Including FILESYSTEM on CORECVS build" ) +#if (USE_TBB) +# message(STATUS "Including FILESYSTEM on CORECVS build") # find_package(Filesystem) # if (FILESYSTEM_LIBRARY) # add_definitions(-DWITH_FILESYSTEM) # endif() -#ENDIF () +#endif() option(USE_OPENBLAS "Should compile with OpenBlas" YES) -IF ( USE_OPENBLAS ) - MESSAGE( STATUS "Including OpenBlas and Lapacke on CORECVS build" ) - find_package( OpenBlas ) - find_package( Lapacke ) +if(USE_OPENBLAS) + message(STATUS "Including OpenBlas and Lapacke on CORECVS build") + find_package(OpenBlas) + find_package(Lapacke) if (OpenBLAS_LIB AND Lapacke_LIB) add_definitions(-DWITH_BLAS) endif() -ENDIF () +endif() option(USE_OPENCV "Should compile with OpenCV" YES) -IF ( USE_OPENCV ) - MESSAGE( STATUS "Including OpenCV on CORECVS build" ) - find_package( OpenCV ) - if (OpenCV_LIBS) +if(USE_OPENCV) + message(STATUS "Including OpenCV on CORECVS build") + find_package(OpenCV) + if(OpenCV_LIBS) add_definitions(-DWITH_OPENCV) else() message("You requested OPENCV in the build, but none was found.") endif() -ENDIF () +endif() option(USE_LIBPNG "Should compile with LibPNG" YES) -IF ( USE_LIBPNG ) - MESSAGE( STATUS "Including LibPNG wherever possible" ) - find_package( Png ) -ENDIF () +if(USE_LIBPNG) + message(STATUS "Including LibPNG wherever possible") + find_package(Png) +endif() option(USE_LIBJPEG "Should compile with LibJPEG" YES) -IF ( USE_LIBJPEG ) - MESSAGE( STATUS "Including LibJpeg wherever possible" ) - find_package( Jpeg ) -ENDIF () +if(USE_LIBJPEG) + message(STATUS "Including LibJpeg wherever possible") + find_package(Jpeg) +endif() option(USE_EIGEN "Should compile with Eigen solver" YES) -IF ( USE_EIGEN ) - MESSAGE( STATUS "Including Eigen solver wherever possible" ) - find_package( Eigen ) -ENDIF () +if(USE_EIGEN) + message(STATUS "Including Eigen solver wherever possible") + find_package(Eigen) +endif() option(USE_CERES "Should compile with Ceres solver" YES) -IF ( USE_CERES ) - MESSAGE( STATUS "Including Ceres solver wherever possible" ) - find_package( Ceres ) +if(USE_CERES) + message(STATUS "Including Ceres solver wherever possible") + find_package(Ceres) +endif() + +option(USE_LIBFFT "Should compile with libfftw" YES) +IF ( USE_LIBFFT ) + MESSAGE( STATUS "Including libfftw wherever possible" ) + find_package( FFTW ) ENDIF () -option(USE_AVCODEC "Should compile with AVCODEC" YES) -IF ( USE_AVCODEC ) - MESSAGE( STATUS "Including AVCODEC wherever possible" ) - find_package( AVCodec ) -ELSE() - MESSAGE( STATUS "Including AVCODEC requested, but libaray not found" ) +option(USE_SOAPYSDR "Should compile with SoapySDR" YES) +IF ( USE_SOAPYSDR ) + MESSAGE( STATUS "Including SoapySDR wherever possible" ) + find_package( SoapySDR ) ENDIF () +option(USE_AVCODEC "Should compile with AVCODEC" YES) +if(USE_AVCODEC) + message(STATUS "Including AVCODEC wherever possible") + find_package(AVCodec) +else() + message(STATUS "Including AVCODEC requested, but libaray not found") +endif() option(USE_APRILTAG "Should compile with APRILTAG" YES) -IF ( USE_APRILTAG ) - MESSAGE(STATUS "Including Apriltag wherever possible") +if(USE_APRILTAG) + message(STATUS "Including Apriltag wherever possible") find_package(Apriltag) find_package(Threads) if (APRILTAG_FOUND) @@ -91,47 +120,29 @@ IF ( USE_APRILTAG ) message("You requested USE_APRILTAG in the build, but none was found.") endif() else() - MESSAGE(STATUS "Apriltag switched off") + message(STATUS "Apriltag switched off") endif() -### -# -# Debug/Release switch - -#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - - -include(cmake/CMakeCpuOptions.cmake) - - -### -# # Actual subprojects -# - -include(cmake/googletest.cmake) -fetch_googletest( - ${PROJECT_SOURCE_DIR}/cmake - ${PROJECT_BINARY_DIR}/googletest - ) -file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/bin) +if(UNIX) + include(cmake/googletest.cmake) + fetch_googletest( + ${PROJECT_SOURCE_DIR}/cmake + ${PROJECT_BINARY_DIR}/googletest + ) +endif(UNIX) add_subdirectory(core) add_subdirectory(utils) -add_subdirectory(test) -add_subdirectory(applications) -add_subdirectory(tools) - - -enable_testing() -add_subdirectory(test-core) -add_subdirectory(test-core/-perf) - - - +if(UNIX) + add_subdirectory(test) + add_subdirectory(applications) + add_subdirectory(tools) + add_subdirectory(wrappers) + enable_testing() + add_subdirectory(test-core) + add_subdirectory(test-core/-perf) +endif(UNIX) \ No newline at end of file diff --git a/GenerateCoreCVS.bat b/GenerateCoreCVS.bat new file mode 100644 index 000000000..38c588e02 --- /dev/null +++ b/GenerateCoreCVS.bat @@ -0,0 +1 @@ +call %~dp0BuildCoreCVS.bat OFF \ No newline at end of file diff --git a/applications/CMakeLists.txt b/applications/CMakeLists.txt index 4e75f84b9..58f230c98 100644 --- a/applications/CMakeLists.txt +++ b/applications/CMakeLists.txt @@ -1,5 +1,4 @@ - -set(TEST_SUBDIRECTORIES +set(SUBDIRECTORIES #base cloudview drone @@ -7,6 +6,7 @@ set(TEST_SUBDIRECTORIES imageview #laserscan # Cannot be included because it uses some deprecated/unknown API: calibrationHelpers.h nester + qtnester #nester-test # TODO: include this #recorder # Cannot be added because it depends on base application #robodetect # Cannot be included because it depends on deprecated filters @@ -15,15 +15,15 @@ set(TEST_SUBDIRECTORIES vinylCutter ) -if (apriltag_LIBS) - set(TEST_SUBDIRECTORIES - ${TEST_SUBDIRECTORIES} +if(APRILTAG_LIBS) + set(SUBDIRECTORIES + ${SUBDIRECTORIES} apriltag_test - ) + ) endif() +foreach(subdirectory ${SUBDIRECTORIES}) + message(STATUS "adding subdirectory/${subdirectory}") + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${subdirectory}) +endforeach(subdirectory) -foreach(test_subdirectory ${TEST_SUBDIRECTORIES}) - message(STATUS "adding subdirectory applications/${test_subdirectory}") - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${test_subdirectory}) -endforeach(test_subdirectory) diff --git a/applications/apriltag_test/CMakeLists.txt b/applications/apriltag_test/CMakeLists.txt index 23b600ffe..e4aa0049b 100644 --- a/applications/apriltag_test/CMakeLists.txt +++ b/applications/apriltag_test/CMakeLists.txt @@ -1,17 +1,43 @@ -project(apriltag_test) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications) +init_project(PROJECT_NAME apriltag_test) -set(SRC_FILES - ${CMAKE_CURRENT_LIST_DIR}/apriltag_test.cpp) -set(HDR_FILES - ${CMAKE_CURRENT_LIST_DIR}/apriltag_test.h) +set(PRIVATE_HEADER_FILE + apriltag_test.h + ) -add_executable(apriltag_test ${SRC_FILES} ${HDR_FILES}) +set(HEADERS + ${PRIVATE_HEADER_FILE} + ) -add_custom_command(TARGET POST_BUILD - COMMAND cp ${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/ - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" -) -#file(COPY ${PROJECT_NAME} DESTINATION ${CMAKE_BINARY_DIR}/bin) +set(SOURCE_FILE + apriltag_test.cpp + ) -target_link_libraries(apriltagtest cvs_utils corecvs ${OpenCV_LIBS}) \ No newline at end of file +set(SOURCES + ${SOURCE_FILE} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) + +target_link_libraries(${PROJECT_NAME} + corecvs_utils + corecvs + APRILTAGwrapper + ${OPENCV_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/applications/apriltag_test/apriltag_test.cpp b/applications/apriltag_test/apriltag_test.cpp index 4c6374282..44d5f5946 100644 --- a/applications/apriltag_test/apriltag_test.cpp +++ b/applications/apriltag_test/apriltag_test.cpp @@ -15,7 +15,7 @@ int main () { vector patts; - auto *a_detector = new apriltagDetector(); + auto *a_detector = new ApriltagDetector(); if(!cap.isOpened()){ cout << "Error opening video stream or file" << endl; diff --git a/applications/apriltag_test/apriltag_test.h b/applications/apriltag_test/apriltag_test.h index 9f0cd3a5a..3f3c5e58e 100644 --- a/applications/apriltag_test/apriltag_test.h +++ b/applications/apriltag_test/apriltag_test.h @@ -6,6 +6,6 @@ #define CORECVS_APRILTAG_TEST_H #include "opencv2/opencv.hpp" -#include "wrappers/apriltag_wrapper/apriltagDetector.h" +#include "apriltagDetector.h" #endif //CORECVS_APRILTAG_TEST_H diff --git a/applications/base/baseHostDialog.h b/applications/base/baseHostDialog.h index 1edf27337..ca643aef8 100644 --- a/applications/base/baseHostDialog.h +++ b/applications/base/baseHostDialog.h @@ -43,7 +43,7 @@ #include "generatedParameters/baseParameters.h" #include "camerasConfigParameters.h" #include "g12Image.h" -#include "advancedImageWidget.h" +#include "uis/advancedImageWidget.h" #include "histogramdialog.h" #include "memoryUsageCalculator.h" diff --git a/applications/base/baseParametersControlWidget.h b/applications/base/baseParametersControlWidget.h index e68e2be47..1bf90dd28 100644 --- a/applications/base/baseParametersControlWidget.h +++ b/applications/base/baseParametersControlWidget.h @@ -4,7 +4,7 @@ #include "generatedParameters/baseParameters.h" #include "ui_baseParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { class BaseParametersControlWidget; diff --git a/applications/base/presentationParametersControlWidget.h b/applications/base/presentationParametersControlWidget.h index b0dd5bb5e..68cb5bda4 100644 --- a/applications/base/presentationParametersControlWidget.h +++ b/applications/base/presentationParametersControlWidget.h @@ -4,7 +4,7 @@ #include "generatedParameters/presentationParameters.h" #include "ui_presentationParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { class PresentationParametersControlWidget; diff --git a/applications/cloudview/CMakeLists.txt b/applications/cloudview/CMakeLists.txt index ffe9e252c..2f78c86d6 100644 --- a/applications/cloudview/CMakeLists.txt +++ b/applications/cloudview/CMakeLists.txt @@ -1,19 +1,33 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.10) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications) +init_project(PROJECT_NAME cloudview) -project(cloudview) +set(SOURCE_FILE + main_cloudview.cpp + ) -add_executable(cloudview main_cloudview.cpp) +set(SOURCES + ${SOURCE_FILE} + ) -target_sources(cloudview +assign_source_group(${SOURCES}) + +add_executable(${PROJECT_NAME} + ${SOURCES} + ) + +target_link_libraries(${PROJECT_NAME} PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/main_cloudview.cpp -) + corecvs + corecvs_utils + ) -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" -) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) -target_link_libraries(cloudview cvs_utils corecvs) -target_include_directories(cloudview PUBLIC ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR} .) +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/applications/cloudview/main_cloudview.cpp b/applications/cloudview/main_cloudview.cpp index 6bfa8946e..dfd27dbd1 100644 --- a/applications/cloudview/main_cloudview.cpp +++ b/applications/cloudview/main_cloudview.cpp @@ -8,21 +8,21 @@ #include #include -#include -#include +#include <3d/sceneShaded.h> +#include <3d/billboardCaption3DScene.h> #include #include -#include - -#include "core/filesystem/folderScanner.h" -#include "core/fileformats/objLoader.h" -#include "core/utils/global.h" -#include "core/utils/utils.h" -#include "cloudViewDialog.h" -#include "mesh3DScene.h" -#include "core/fileformats/meshLoader.h" -#include "qtFileLoader.h" +#include + +#include "filesystem/folderScanner.h" +#include "fileformats/objLoader.h" +#include "utils/global.h" +#include "utils/utils.h" +#include "uis/cloudview/cloudViewDialog.h" +#include "3d/mesh3DScene.h" +#include "fileformats/meshLoader.h" +#include "fileformats/qtFileLoader.h" int main(int argc, char *argv[]) diff --git a/applications/drone/CMakeLists.txt b/applications/drone/CMakeLists.txt index bfbf36361..95aa8a254 100644 --- a/applications/drone/CMakeLists.txt +++ b/applications/drone/CMakeLists.txt @@ -1,16 +1,16 @@ -if (OpenCV_LIBS) - set(DRONE_SUBDIRECTORIES - drone-core - drone-ui - physics-test - drone-utils - drone-app - calibrator - - ) +set(DRONE_SUBDIRECTORIES + calibrator + #coptercontrol + drone-app + drone-core + drone-ui + drone-utils + physics-test + ) - foreach(test_subdirectory ${DRONE_SUBDIRECTORIES}) - message(STATUS "adding subdirectory test/${test_subdirectory}") - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${test_subdirectory}) - endforeach(test_subdirectory) -endif() +if (OpenCV_LIBS) + foreach(subdirectory ${DRONE_SUBDIRECTORIES}) + message(STATUS "adding subdirectory/${subdirectory}") + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${subdirectory}) + endforeach(subdirectory) +endif() \ No newline at end of file diff --git a/applications/drone/calibrator/CMakeLists.txt b/applications/drone/calibrator/CMakeLists.txt index 18fdeae65..0af0b9bc6 100644 --- a/applications/drone/calibrator/CMakeLists.txt +++ b/applications/drone/calibrator/CMakeLists.txt @@ -1,18 +1,71 @@ -project (drone-calibrator) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications/drone) +init_project(PROJECT_NAME calibrator) +find_package(Qt5 COMPONENTS REQUIRED Widgets) -set (SRC_FILES +set(SOURCES_FILE main_calibrator.cpp -) + ) -add_executable(drone-calibrator ${SRC_FILES}) +set(SOURCES + ${SOURCES_FILE} + ) -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" +add_executable(${PROJECT_NAME} + ${SOURCES} + ) + +set(ADDITIONAL_LIBS) + +if(OpenCV_LIBS) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + OPENCVwrapper ) +endif() + +if(AVCODEC_LIBS) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + AVCODECwrapper + ) + add_definitions(-DWITH_AVCODEC -DWITH_SWSCALE) +endif() + +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper + ) + add_definitions(-DWITH_LIBPNG) +endif() + +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() + +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs + corecvs_utils + drone-ui + Qt5::Widgets + pthread + ${ADDITIONAL_LIBS} + ) -target_link_libraries(drone-calibrator drone-ui drone-core cvs_utils corecvs pthread) -target_include_directories(drone-calibrator PUBLIC ${drone-ui_SOURCE_DIR} ${drone-core_SOURCE_DIR} ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR}) +set_target_properties(${PROJECT_NAME} + PROPERTIES + AUTORCC TRUE + FOLDER "${MODULE_NAME}" + ) +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/applications/drone/calibrator/main_calibrator.cpp b/applications/drone/calibrator/main_calibrator.cpp index f7277a2a5..5c0f5ecd9 100644 --- a/applications/drone/calibrator/main_calibrator.cpp +++ b/applications/drone/calibrator/main_calibrator.cpp @@ -1,12 +1,12 @@ #include -#include "qtFileLoader.h" +#include "fileformats/qtFileLoader.h" -#include "core/utils/utils.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/geometry/mesh/mesh3DDecorated.h" -#include "core/reflection/commandLineSetter.h" -#include "core/buffers/bufferFactory.h" -#include "core/stereointerface/dummyFlowProcessor.h" +#include "utils/utils.h" +#include "geometry/mesh/mesh3d.h" +#include "geometry/mesh/mesh3DDecorated.h" +#include "reflection/commandLineSetter.h" +#include "buffers/bufferFactory.h" +#include "stereointerface/dummyFlowProcessor.h" #ifdef WITH_LIBJPEG #include "libjpegFileReader.h" @@ -19,10 +19,9 @@ #include "patternDetect/openCVSquareDetector.h" #endif #ifdef WITH_APRILTAG -#include "wrappers/apriltag_wrapper/apriltagDetector.h" +#include "apriltagDetector.h" #endif - #include "physicsMainWindow.h" using namespace corecvs; diff --git a/applications/drone/coptercontrol/copterControlWidget.h b/applications/drone/coptercontrol/copterControlWidget.h index 4456008c5..6953b9e43 100644 --- a/applications/drone/coptercontrol/copterControlWidget.h +++ b/applications/drone/coptercontrol/copterControlWidget.h @@ -4,7 +4,7 @@ #include #include "generatedParameters/copter.h" #include "ui_copterControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { class CopterControlWidget; diff --git a/applications/drone/coptercontrol/copterDialog.cpp b/applications/drone/coptercontrol/copterDialog.cpp index eec2713b5..4e68b222d 100644 --- a/applications/drone/coptercontrol/copterDialog.cpp +++ b/applications/drone/coptercontrol/copterDialog.cpp @@ -16,7 +16,7 @@ #include #include #include "parametersMapper/parametersMapperCopter.h" -#include +#include CopterDialog::CopterDialog() : BaseHostDialog(), diff --git a/applications/drone/drone-app/CMakeLists.txt b/applications/drone/drone-app/CMakeLists.txt index 97e93a19e..1456dcfc7 100644 --- a/applications/drone/drone-app/CMakeLists.txt +++ b/applications/drone/drone-app/CMakeLists.txt @@ -1,18 +1,69 @@ -project (drone-app) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications/drone) +init_project(PROJECT_NAME drone-app) - -set (SRC_FILES +set(SOURCE_FILE mainDrone.cpp -) + ) + +set(SOURCES + ${SOURCE_FILE} + ) + +assign_source_group(${SOURCES}) -add_executable(drone-app mainDrone.cpp) +add_executable(${PROJECT_NAME} + ${SOURCES} + ) + +set(ADDITIONAL_LIBS) + +if(OpenCV_LIBS) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + OPENCVwrapper + ) +endif() -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" +if(AVCODEC_LIBS) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + AVCODECwrapper ) + add_definitions(-DWITH_AVCODEC -DWITH_SWSCALE) +endif() + +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper + ) + add_definitions(-DWITH_LIBPNG) +endif() + +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_JPEG) +endif() + +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs + corecvs_utils + drone-ui + pthread + ${ADDITIONAL_LIBS} + ) -target_link_libraries(drone-app drone-ui drone-core cvs_utils corecvs pthread) -target_include_directories(drone-app PUBLIC ${drone-ui_SOURCE_DIR} ${drone-core_SOURCE_DIR} ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR}) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/applications/drone/drone-app/mainDrone.cpp b/applications/drone/drone-app/mainDrone.cpp index 785af665d..1e481bf30 100644 --- a/applications/drone/drone-app/mainDrone.cpp +++ b/applications/drone/drone-app/mainDrone.cpp @@ -1,14 +1,14 @@ #include #include #include -#include "qtFileLoader.h" +#include "fileformats/qtFileLoader.h" -#include "core/utils/utils.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/geometry/mesh/mesh3DDecorated.h" -#include "core/reflection/commandLineSetter.h" -#include "core/buffers/bufferFactory.h" -#include "core/stereointerface/dummyFlowProcessor.h" +#include "utils/utils.h" +#include "reflection/commandLineSetter.h" +#include "buffers/bufferFactory.h" +#include "stereointerface/dummyFlowProcessor.h" +#include "geometry/mesh/mesh3d.h" +#include "geometry/mesh/mesh3DDecorated.h" #ifdef WITH_LIBJPEG #include "libjpegFileReader.h" @@ -22,7 +22,7 @@ #include "patternDetect/openCVCheckerBoardDetector.h" #endif #ifdef WITH_APRILTAG -#include "wrappers/apriltag_wrapper/apriltagDetector.h" +#include "apriltagDetector.h" #endif diff --git a/applications/drone/drone-core/CMakeLists.txt b/applications/drone/drone-core/CMakeLists.txt index b81481385..bbd69c0b4 100644 --- a/applications/drone/drone-core/CMakeLists.txt +++ b/applications/drone/drone-core/CMakeLists.txt @@ -1,138 +1,153 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.10) - -project (drone-core) - -add_library(drone-core STATIC ) - - -file(GLOB CURR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/xml/generated/*.cpp) -file(GLOB CURR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/xml/generated/*.h) - -set(SRC_FILES ${SRC_FILES} ${CURR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CURR_HDR_FILES}) - -set (INC_PATHS ${CMAKE_CURRENT_LIST_DIR}/xml/generated) - -include(../../../wrappers/joystick/sourcelist.cmake) -include(../../../wrappers/jsonmodern/sourcelist.cmake) - -target_sources(drone-core - PUBLIC - ${HDR_FILES} - - ${CMAKE_CURRENT_LIST_DIR}/calibration/calibration.h - - ${CMAKE_CURRENT_LIST_DIR}/copter/pid.h - ${CMAKE_CURRENT_LIST_DIR}/copter/droneObject.h - ${CMAKE_CURRENT_LIST_DIR}/copter/motor.h - ${CMAKE_CURRENT_LIST_DIR}/copter/quad.h - - ${CMAKE_CURRENT_LIST_DIR}/simulation/simulation.h - ${CMAKE_CURRENT_LIST_DIR}/simulation/simSphere.h - ${CMAKE_CURRENT_LIST_DIR}/simulation/simObject.h - ${CMAKE_CURRENT_LIST_DIR}/simulation/mainObject.h - ${CMAKE_CURRENT_LIST_DIR}/simulation/physicsCompoundObject.h - ${CMAKE_CURRENT_LIST_DIR}/simulation/physicsObject.h - ${CMAKE_CURRENT_LIST_DIR}/simulation/physicsSphere.h - - ${CMAKE_CURRENT_LIST_DIR}/mixer/controlsMixer.h - - ${CMAKE_CURRENT_LIST_DIR}/radio/frSkyMultimodule.h - ${CMAKE_CURRENT_LIST_DIR}/radio/multimoduleController.h - ${CMAKE_CURRENT_LIST_DIR}/radio/r9Module.h - - ${CMAKE_CURRENT_LIST_DIR}/autopilot/protoautopilot.h - ${CMAKE_CURRENT_LIST_DIR}/autopilot/vertexsquare.h - ${CMAKE_CURRENT_LIST_DIR}/opencvUtils/opencvTransformations.h - - ${CMAKE_CURRENT_LIST_DIR}/clientSender.h - ${CMAKE_CURRENT_LIST_DIR}/controlRecord.h - ${CMAKE_CURRENT_LIST_DIR}/comcontroller.h - ${CMAKE_CURRENT_LIST_DIR}/copterInputs.h - ${CMAKE_CURRENT_LIST_DIR}/joystick/joystickReader.h - - ${CMAKE_CURRENT_LIST_DIR}/world/simulationWorld.h - - - PRIVATE - ${SRC_FILES} - - ${CMAKE_CURRENT_LIST_DIR}/calibration/calibration.cpp - - ${CMAKE_CURRENT_LIST_DIR}/copter/pid.cpp - ${CMAKE_CURRENT_LIST_DIR}/copter/quad.cpp - ${CMAKE_CURRENT_LIST_DIR}/copter/droneObject.cpp - ${CMAKE_CURRENT_LIST_DIR}/copter/motor.cpp - - - ${CMAKE_CURRENT_LIST_DIR}/simulation/mainObject.cpp - ${CMAKE_CURRENT_LIST_DIR}/simulation/simulation.cpp - ${CMAKE_CURRENT_LIST_DIR}/simulation/simSphere.cpp - ${CMAKE_CURRENT_LIST_DIR}/simulation/simObject.cpp - ${CMAKE_CURRENT_LIST_DIR}/simulation/physicsCompoundObject.cpp - ${CMAKE_CURRENT_LIST_DIR}/simulation/physicsObject.cpp - ${CMAKE_CURRENT_LIST_DIR}/simulation/physicsSphere.cpp - - ${CMAKE_CURRENT_LIST_DIR}/mixer/controlsMixer.cpp - - ${CMAKE_CURRENT_LIST_DIR}/radio/frSkyMultimodule.cpp - ${CMAKE_CURRENT_LIST_DIR}/radio/multimoduleController.cpp - ${CMAKE_CURRENT_LIST_DIR}/radio/r9Module.cpp - - ${CMAKE_CURRENT_LIST_DIR}/autopilot/protoautopilot.cpp - ${CMAKE_CURRENT_LIST_DIR}/autopilot/vertexsquare.cpp - ${CMAKE_CURRENT_LIST_DIR}/opencvUtils/opencvTransformations.cpp - - ${CMAKE_CURRENT_LIST_DIR}/clientSender.cpp - ${CMAKE_CURRENT_LIST_DIR}/controlRecord.cpp - ${CMAKE_CURRENT_LIST_DIR}/copterInputs.cpp - ${CMAKE_CURRENT_LIST_DIR}/comcontroller.cpp - ${CMAKE_CURRENT_LIST_DIR}/joystick/joystickReader.cpp - - ${CMAKE_CURRENT_LIST_DIR}/world/simulationWorld.cpp +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications/drone) +init_project(PROJECT_NAME drone-core) + +find_package(Qt5 COMPONENTS REQUIRED SerialPort Core Gui Widgets) + +set(PUBLIC_HEADER_FILES + clientSender.h + comcontroller.h + controlRecord.h + copterInputs.h + autopilot/protoautopilot.h + autopilot/vertexsquare.h + calibration/calibration.h + copter/droneObject.h + copter/motor.h + copter/quad.h + copter/quadAngles.h + copter/pid.h + joystick/joystickReader.h + mixer/controlsMixer.h + opencvUtils/opencvTransformations.h + radio/frSkyMultimodule.h + radio/multimoduleController.h + radio/r9Module.h + simulation/mainObject.h + simulation/physicsCompoundObject.h + simulation/physicsObject.h + simulation/physicsSphere.h + simulation/simObject.h + simulation/simSphere.h + simulation/simulation.h + xml/generated/betaflightPIDParameters.h + xml/generated/flightControllerParameters.h + xml/generated/flightMode.h + xml/generated/mixerChannelOperationParameters.h + xml/generated/pIDParameters.h + xml/generated/rateParameters.h + xml/generated/sceneDrawBackendType.h + world/simulationWorld.h + ) -) +set(HEADERS + ${PUBLIC_HEADER_FILES} + ) -set(ADD_SRC_FILES ${ADD_SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/legacy/joystickInput.h - ${CMAKE_CURRENT_LIST_DIR}/legacy/joystickInput.cpp +set(SOURCE_FILES + clientSender.cpp + comcontroller.cpp + controlRecord.cpp + copterInputs.cpp ) +set(AUTOPILOT_SOURCE_FILES + autopilot/protoautopilot.cpp + autopilot/vertexsquare.cpp + ) -target_include_directories(drone-core PUBLIC - ${INC_PATHS} +set(CALIBRATION_SOURCE_FILE + calibration/calibration.cpp + ) - ${CMAKE_CURRENT_LIST_DIR} - ${CMAKE_CURRENT_LIST_DIR}/joystick - ${CMAKE_CURRENT_LIST_DIR}/radio - ${CMAKE_CURRENT_LIST_DIR}/mixer - ${CMAKE_CURRENT_LIST_DIR}/autopilot - ${CMAKE_CURRENT_LIST_DIR}/copter - ${CMAKE_CURRENT_LIST_DIR}/calibration - ${CMAKE_CURRENT_LIST_DIR}/opencvUtils - ${CMAKE_CURRENT_LIST_DIR}/simulation -) +set(COPTER_SOURCE_FILES + copter/droneObject.cpp + copter/motor.cpp + copter/quad.cpp + copter/quadAngles.cpp + copter/pid.cpp + ) -target_include_directories(drone-core PUBLIC ../../../wrappers/joystick) +set(JOYSTICK_SOURCE_FILE + joystick/joystickReader.cpp + ) + +set(MIXER_SOURCE_FILE + mixer/controlsMixer.cpp + ) -target_link_libraries(drone-core corecvs) +set(OPENCVUTILS_SOURCE_FILE + opencvUtils/opencvTransformations.cpp + ) +set(RADIO_SOURCE_FILES + radio/frSkyMultimodule.cpp + radio/multimoduleController.cpp + radio/r9Module.cpp + ) -target_include_directories(drone-core PUBLIC ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR} .) +set(SIMULATION_SOURCE_FILES + simulation/mainObject.cpp + simulation/physicsCompoundObject.cpp + simulation/physicsObject.cpp + simulation/physicsSphere.cpp + simulation/simObject.cpp + simulation/simSphere.cpp + simulation/simulation.cpp + ) +set(XML_SOURCE_FILES + xml/generated/betaflightPIDParameters.cpp + xml/generated/flightControllerParameters.cpp + xml/generated/mixerChannelOperationParameters.cpp + xml/generated/pIDParameters.cpp + xml/generated/rateParameters.cpp + ) -target_link_libraries(drone-core cvs_utils corecvs) +set(WORLD_SOURCE_FILES + world/simulationWorld.cpp + ) -if (OpenCV_LIBS) - target_link_libraries(drone-core ${OpenCV_LIBS}) -endif() +set(SOURCES + ${SOURCE_FILES} + ${AUTOPILOT_SOURCE_FILES} + ${CALIBRATION_SOURCE_FILE} + ${COPTER_SOURCE_FILES} + ${JOYSTICK_SOURCE_FILE} + ${LEGACY_SOURCE_FILE} + ${MIXER_SOURCE_FILE} + ${OPENCVUTILS_SOURCE_FILE} + ${RADIO_SOURCE_FILES} + ${SIMULATION_SOURCE_FILES} + ${XML_SOURCE_FILES} + ${WORLD_SOURCE_FILES} + ) +assign_source_group(${HEADERS} ${SOURCES}) -# Additional stuff mostly for IDE only +add_library(${PROJECT_NAME} STATIC + ${HEADERS} + ${SOURCES} + ) -file(GLOB CUR_ADD_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/xml/*.xml) -set(ADD_SRC_FILES ${ADD_SRC_FILES} ${CUR_ADD_SRC_FILES}) +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) -target_sources(drone-core PRIVATE ${ADD_SRC_FILES}) -set_source_files_properties(${ADD_SRC_FILES} PROPERTIES EXTERNAL_OBJECT true HEADER_FILE_ONLY TRUE) +target_link_libraries(${PROJECT_NAME} + PUBLIC + corecvs + corecvs_utils + Qt5::SerialPort + Qt5::Core + Qt5::Gui + Qt5::Widgets + JOYSTICKwrapper + ${OpenCV_LIBS} + ) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/applications/drone/drone-core/autopilot/protoautopilot.cpp b/applications/drone/drone-core/autopilot/protoautopilot.cpp index f52a9704a..b1e0e961b 100644 --- a/applications/drone/drone-core/autopilot/protoautopilot.cpp +++ b/applications/drone/drone-core/autopilot/protoautopilot.cpp @@ -9,7 +9,7 @@ #include #include -#include "droneObject.h" +#include "copter/droneObject.h" #include #include #include diff --git a/applications/drone/drone-core/autopilot/protoautopilot.h b/applications/drone/drone-core/autopilot/protoautopilot.h index 66067e51b..b805229e5 100644 --- a/applications/drone/drone-core/autopilot/protoautopilot.h +++ b/applications/drone/drone-core/autopilot/protoautopilot.h @@ -13,8 +13,8 @@ #include "vertexsquare.h" #include "copterInputs.h" -#include "mainObject.h" //Vector3dd here, and i dont understand where exactly -#include "droneObject.h" +#include "simulation/mainObject.h" //Vector3dd here, and i dont understand where exactly +#include "copter/droneObject.h" class ProtoAutoPilot { diff --git a/applications/drone/drone-core/autopilot/vertexsquare.h b/applications/drone/drone-core/autopilot/vertexsquare.h index 856f3b59a..ef36db6d5 100644 --- a/applications/drone/drone-core/autopilot/vertexsquare.h +++ b/applications/drone/drone-core/autopilot/vertexsquare.h @@ -1,7 +1,7 @@ #include "core/utils/global.h" #include "iostream" -#include "mainObject.h" +#include "simulation/mainObject.h" #ifndef VERTEXSQUARE_H #define VERTEXSQUARE_H diff --git a/applications/drone/drone-core/copter/droneObject.h b/applications/drone/drone-core/copter/droneObject.h index 49bfdcb5b..a2f6f3c36 100644 --- a/applications/drone/drone-core/copter/droneObject.h +++ b/applications/drone/drone-core/copter/droneObject.h @@ -11,8 +11,8 @@ #include "core/math/affine.h" #include "core/math/vector/vector3d.h" -#include "physicsCompoundObject.h" -#include "pid.h" +#include "simulation/physicsCompoundObject.h" +#include "copter/pid.h" class Sensor { diff --git a/applications/drone/drone-core/copter/motor.h b/applications/drone/drone-core/copter/motor.h index c8a6a10b4..0c7079963 100644 --- a/applications/drone/drone-core/copter/motor.h +++ b/applications/drone/drone-core/copter/motor.h @@ -4,13 +4,15 @@ #include #include -#include -#include "core/cameracalibration/calibrationDrawHelpers.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/math/affine.h" -#include "core/math/vector/vector3d.h" -#include "physicsSphere.h" +#include +#include "cameracalibration/calibrationDrawHelpers.h" +#include "geometry/mesh/mesh3d.h" +#include "math/affine.h" +#include "math/vector/vector3d.h" + +#include "simulation/physicsSphere.h" + class Motor : public PhysicsSphere { diff --git a/applications/drone/drone-core/copter/quad.h b/applications/drone/drone-core/copter/quad.h index a1bbf323b..3d54101ef 100644 --- a/applications/drone/drone-core/copter/quad.h +++ b/applications/drone/drone-core/copter/quad.h @@ -3,13 +3,13 @@ #include -#include -#include "core/cameracalibration/calibrationDrawHelpers.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/math/affine.h" -#include "core/math/vector/vector3d.h" +#include +#include "cameracalibration/calibrationDrawHelpers.h" +#include "geometry/mesh/mesh3d.h" +#include "math/affine.h" +#include "math/vector/vector3d.h" -#include "simObject.h" +#include "simulation/simObject.h" #include "copterInputs.h" #include "xml/generated/flightControllerParameters.h" diff --git a/applications/drone/drone-core/joystick/joystickReader.cpp b/applications/drone/drone-core/joystick/joystickReader.cpp index 396cff969..cbb73fd23 100644 --- a/applications/drone/drone-core/joystick/joystickReader.cpp +++ b/applications/drone/drone-core/joystick/joystickReader.cpp @@ -1,10 +1,12 @@ +#include "core/utils/global.h" + #include "joystickReader.h" #include "iostream" JoystickReader::JoystickReader(const std::string &deviceName) : LinuxJoystickInterface (deviceName) { - std::cout<<"JS Reader created"< #include "core/utils/log.h" -#include "core/geometry/mesh/mesh3d.h" #include "core/utils/utils.h" #include "core/geometry/mesh/mesh3d.h" diff --git a/applications/drone/drone-core/simulation/physicsSphere.cpp b/applications/drone/drone-core/simulation/physicsSphere.cpp index 3747843af..f7dfc01e1 100644 --- a/applications/drone/drone-core/simulation/physicsSphere.cpp +++ b/applications/drone/drone-core/simulation/physicsSphere.cpp @@ -1,6 +1,6 @@ #include "physicsSphere.h" -#include +#include <3d/mesh3DScene.h> PhysicsSphere::PhysicsSphere(): MaterialObject () { diff --git a/applications/drone/drone-core/simulation/simSphere.cpp b/applications/drone/drone-core/simulation/simSphere.cpp index 62d8e6dcc..f83465918 100644 --- a/applications/drone/drone-core/simulation/simSphere.cpp +++ b/applications/drone/drone-core/simulation/simSphere.cpp @@ -1,6 +1,6 @@ #include "simSphere.h" -#include +#include <3d/mesh3DScene.h> SimSphere::SimSphere() { diff --git a/applications/drone/drone-core/simulation/simulation.cpp b/applications/drone/drone-core/simulation/simulation.cpp index 1171fcc41..d304cadf4 100644 --- a/applications/drone/drone-core/simulation/simulation.cpp +++ b/applications/drone/drone-core/simulation/simulation.cpp @@ -5,7 +5,7 @@ #include "simulation.h" #include "simObject.h" #include "simSphere.h" -#include "mesh3DScene.h" +#include "3d/mesh3DScene.h" using namespace std; using namespace corecvs; diff --git a/applications/drone/drone-core/simulation/simulation.h b/applications/drone/drone-core/simulation/simulation.h index 46f5949c9..ea1a477c7 100644 --- a/applications/drone/drone-core/simulation/simulation.h +++ b/applications/drone/drone-core/simulation/simulation.h @@ -11,7 +11,7 @@ #include "physicsObject.h" #include "physicsSphere.h" #include "physicsCompoundObject.h" -#include "sceneShaded.h" +#include "3d/sceneShaded.h" class Simulation { diff --git a/applications/drone/drone-ui/CMakeLists.txt b/applications/drone/drone-ui/CMakeLists.txt index 260e477fc..781551397 100644 --- a/applications/drone/drone-ui/CMakeLists.txt +++ b/applications/drone/drone-ui/CMakeLists.txt @@ -1,108 +1,88 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.10) - -set (MODULE_NAME drone-ui) - -project (drone-ui) - - -set(CMAKE_INCLUDE_CURRENT_DIR "YES") -set(CMAKE_AUTOMOC "YES") -#set(CMAKE_AUTOUIC "YES") -set(CMAKE_AUTORCC "YES") +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications/drone) +init_project(PROJECT_NAME drone-ui) find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets Script) -add_library(drone-ui STATIC ) - - -target_sources(drone-ui - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/calibration/calibrationWidget.h - ${CMAKE_CURRENT_LIST_DIR}/calibration/imageForCalibrationWidget.h - - ${CMAKE_CURRENT_LIST_DIR}/joystick/JoystickOptionsWidget.h - ${CMAKE_CURRENT_LIST_DIR}/joystick/mixerChannelOperationWidget.h - - ${CMAKE_CURRENT_LIST_DIR}/radio/radioControlWidget.h - ${CMAKE_CURRENT_LIST_DIR}/copterInputsWidget.h - - ${CMAKE_CURRENT_LIST_DIR}/physicsMainWindow.h - ${CMAKE_CURRENT_LIST_DIR}/physicsAboutWidget.h - - ${CMAKE_CURRENT_LIST_DIR}/frameProcessor.h - -) - -target_sources(drone-ui - PRIVATE - - ${CMAKE_CURRENT_LIST_DIR}/calibration/calibrationWidget.cpp - ${CMAKE_CURRENT_LIST_DIR}/calibration/imageForCalibrationWidget.cpp - - ${CMAKE_CURRENT_LIST_DIR}/joystick/JoystickOptionsWidget.cpp - ${CMAKE_CURRENT_LIST_DIR}/joystick/mixerChannelOperationWidget.cpp - - ${CMAKE_CURRENT_LIST_DIR}/radio/radioControlWidget.cpp - ${CMAKE_CURRENT_LIST_DIR}/copterInputsWidget.cpp - - ${CMAKE_CURRENT_LIST_DIR}/physicsMainWindow.cpp - ${CMAKE_CURRENT_LIST_DIR}/physicsAboutWidget.cpp - - ${CMAKE_CURRENT_LIST_DIR}/frameProcessor.cpp - -) - -set (UI_FILES - ${CMAKE_CURRENT_LIST_DIR}/physicsAboutWidget.ui - ${CMAKE_CURRENT_LIST_DIR}/radio/radioControlWidget.ui - ${CMAKE_CURRENT_LIST_DIR}/joystick/JoystickOptionsWidget.ui - ${CMAKE_CURRENT_LIST_DIR}/joystick/mixerChannelOperationWidget.ui - ${CMAKE_CURRENT_LIST_DIR}/physicsMainWindow.ui - ${CMAKE_CURRENT_LIST_DIR}/calibration/imageForCalibrationWidget.ui - ${CMAKE_CURRENT_LIST_DIR}/calibration/calibrationWidget.ui - ${CMAKE_CURRENT_LIST_DIR}/copterInputsWidget.ui +set(PUBLIC_HEADER_FILES + calibration/calibrationWidget.h + calibration/imageForCalibrationWidget.h + copterInputsWidget.h + frameProcessor.h + joystick/JoystickOptionsWidget.h + joystick/mixerChannelOperationWidget.h + physicsAboutWidget.h + physicsMainWindow.h + radio/radioControlWidget.h ) -QT5_WRAP_UI( UI_HEADERS ${UI_FILES} ) - -#message(DRONE-UI: FILES: ${UI_FILES}) -#message(DRONE-UI: HEADERS: ${UI_HEADERS}) - +set(HEADERS + ${PUBLIC_HEADER_FILES} + ) +set(SOURCE_FILES + copterInputsWidget.cpp + frameProcessor.cpp + physicsAboutWidget.cpp + physicsMainWindow.cpp + ) -target_sources(drone-ui - PRIVATE - ${UI_HEADERS} - ${CMAKE_CURRENT_LIST_DIR}/drone.qrc +set(CALIBRATION_SOURCE_FILES + calibration/calibrationWidget.cpp + calibration/imageForCalibrationWidget.cpp ) -target_include_directories(drone-ui PUBLIC - ${CMAKE_CURRENT_LIST_DIR} - ${CMAKE_CURRENT_LIST_DIR}/joystick - ${CMAKE_CURRENT_LIST_DIR}/radio - ${CMAKE_CURRENT_LIST_DIR}/mixer - ${CMAKE_CURRENT_LIST_DIR}/autopilot - ${CMAKE_CURRENT_LIST_DIR}/copter - ${CMAKE_CURRENT_LIST_DIR}/calibration - ${CMAKE_CURRENT_LIST_DIR}/opencvUtils - ${CMAKE_CURRENT_LIST_DIR}/simulation +set(JOYSTICK_SOURCE_FILES + joystick/JoystickOptionsWidget.cpp + joystick/mixerChannelOperationWidget.cpp + ) - ${CMAKE_CURRENT_LIST_DIR}/world -) +set(RADIO_SOURCE_FILE + radio/radioControlWidget.cpp + ) +set(SOURCES + ${SOURCE_FILES} + ${CALIBRATION_SOURCE_FILES} + ${JOYSTICK_SOURCE_FILES} + ${RADIO_SOURCE_FILE} + ) -# Temporary fixes -SET(AUTOGEN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}_autogen/include") -target_include_directories(${MODULE_NAME} PUBLIC ${AUTOGEN_BUILD_DIR} ) -target_include_directories(${MODULE_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ) +set(RESOURCES + drone.qrc + ) -message("AUTOGEN_BUILD_DIR bin directory <${AUTOGEN_BUILD_DIR}>") +assign_source_group(${HEADERS} ${SOURCES} ${RESOURCES}) -target_include_directories(drone-ui PUBLIC ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR} ${drone-core_SOURCE_DIR} .) +add_library(${PROJECT_NAME} STATIC + ${HEADERS} + ${SOURCES} + ${RESOURCES} + ) -target_link_libraries(drone-ui drone-core cvs_utils corecvs) +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${AUTOGEN_BUILD_DIR} + ) -if (OpenCV_LIBS) - target_link_libraries(drone-ui ${OpenCV_LIBS}) -endif() +target_link_libraries(${PROJECT_NAME} + PUBLIC + corecvs_utils + corecvs + drone-core + JOYSTICKwrapper + Qt5::Core + Qt5::Gui + Qt5::Script + Qt5::Widgets + ${OpenCV_LIBS} + ) +set_target_properties(${PROJECT_NAME} + PROPERTIES + AUTOMOC TRUE + AUTOUIC TRUE + AUTORCC TRUE + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/applications/drone/drone-ui/calibration/calibrationWidget.cpp b/applications/drone/drone-ui/calibration/calibrationWidget.cpp index f5f07ee45..2336e6b3b 100644 --- a/applications/drone/drone-ui/calibration/calibrationWidget.cpp +++ b/applications/drone/drone-ui/calibration/calibrationWidget.cpp @@ -9,8 +9,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/applications/drone/drone-ui/calibration/calibrationWidget.h b/applications/drone/drone-ui/calibration/calibrationWidget.h index d9cd9b277..50abca977 100644 --- a/applications/drone/drone-ui/calibration/calibrationWidget.h +++ b/applications/drone/drone-ui/calibration/calibrationWidget.h @@ -4,10 +4,10 @@ #include #include "opencv2/core.hpp" #include "imageForCalibrationWidget.h" -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/applications/drone/drone-ui/calibration/calibrationWidget.ui b/applications/drone/drone-ui/calibration/calibrationWidget.ui index 4a806b366..2af8f6fa2 100644 --- a/applications/drone/drone-ui/calibration/calibrationWidget.ui +++ b/applications/drone/drone-ui/calibration/calibrationWidget.ui @@ -432,7 +432,7 @@ AdvancedImageWidget QWidget -
advancedImageWidget.h
+
uis/advancedImageWidget.h
1
diff --git a/applications/drone/drone-ui/calibration/imageForCalibrationWidget.cpp b/applications/drone/drone-ui/calibration/imageForCalibrationWidget.cpp index 6562d7a2b..1ad27c309 100644 --- a/applications/drone/drone-ui/calibration/imageForCalibrationWidget.cpp +++ b/applications/drone/drone-ui/calibration/imageForCalibrationWidget.cpp @@ -1,10 +1,10 @@ #include "imageForCalibrationWidget.h" #include "ui_imageForCalibrationWidget.h" #include "opencv2/core.hpp" -#include "opencvTransformations.h" +#include "opencvUtils/opencvTransformations.h" #include #include -#include +#include ImageForCalibrationWidget::ImageForCalibrationWidget(QWidget *parent) : diff --git a/applications/drone/drone-ui/frameProcessor.cpp b/applications/drone/drone-ui/frameProcessor.cpp index bb6d171c7..2b87db3d4 100644 --- a/applications/drone/drone-ui/frameProcessor.cpp +++ b/applications/drone/drone-ui/frameProcessor.cpp @@ -1,7 +1,7 @@ #include "frameProcessor.h" #include -#include +#include #include "physicsMainWindow.h" diff --git a/applications/drone/drone-ui/frameProcessor.h b/applications/drone/drone-ui/frameProcessor.h index 07afd211e..c56a6c58c 100644 --- a/applications/drone/drone-ui/frameProcessor.h +++ b/applications/drone/drone-ui/frameProcessor.h @@ -1,9 +1,9 @@ #ifndef FRAMEPROCESSOR_H #define FRAMEPROCESSOR_H #include -#include -#include -#include +#include +#include +#include #include diff --git a/applications/drone/drone-ui/joystick/JoystickOptionsWidget.cpp b/applications/drone/drone-ui/joystick/JoystickOptionsWidget.cpp index ef2d6183d..e28581cbe 100644 --- a/applications/drone/drone-ui/joystick/JoystickOptionsWidget.cpp +++ b/applications/drone/drone-ui/joystick/JoystickOptionsWidget.cpp @@ -56,24 +56,30 @@ void JoystickOptionsWidget::getProps() void JoystickOptionsWidget::openJoystick() { + SYNC_PRINT(("JoystickOptionsWidget::openJoystick() : called\n")); if (mInterface != NULL) { return; } std::string name = ui->deviceLineEdit->text().toStdString(); + SYNC_PRINT(("JoystickOptionsWidget::openJoystick() : creating joystick for <%s>\n", name.c_str())); + if (HelperUtils::endsWith(name, ".dump")) { + SYNC_PRINT(("Created PlaybackJoystickInterface\n")); mInterface = new JoystickListener(name, this); } else { + SYNC_PRINT(("Created LinuxJoystickInterface\n")); mInterface = new JoystickListener(name, this); } + mInterface->start(); + JoystickConfiguration conf = mInterface->getConfiguration(); conf.print(); reconfigure(conf); QObject::connect(mInterface, SIGNAL(joystickUpdated(JoystickState)), this, SLOT(newData(JoystickState)), Qt::QueuedConnection); QObject::connect(mInterface, SIGNAL(joystickUpdated(JoystickState)), this, SIGNAL(joystickUpdated(JoystickState)), Qt::QueuedConnection); - mInterface->start(); ui-> openPushButton->setEnabled(false); ui->closePushButton->setEnabled(true); } diff --git a/applications/drone/drone-ui/joystick/JoystickOptionsWidget.h b/applications/drone/drone-ui/joystick/JoystickOptionsWidget.h index a23db0f42..500e562b1 100644 --- a/applications/drone/drone-ui/joystick/JoystickOptionsWidget.h +++ b/applications/drone/drone-ui/joystick/JoystickOptionsWidget.h @@ -6,8 +6,10 @@ #include +#include #include + namespace Ui { class JoystickOptionsWidget; } @@ -20,13 +22,16 @@ class JoystickInterfaceQt : public QObject, public virtual corecvs::JoystickInte { Q_OBJECT - - - signals: void joystickUpdated(corecvs::JoystickState state); public: + JoystickInterfaceQt(const std::string &deviceName) : + corecvs::JoystickInterface(deviceName) + { + SYNC_PRINT(("JoystickInterfaceQt::JoystickInterfaceQt(%s): called\n", deviceName.c_str())); + } + virtual ~JoystickInterfaceQt(){} }; @@ -37,9 +42,11 @@ class JoystickListener : public JoystickInterfaceQt, public BaseObject JoystickOptionsWidget *mTarget = NULL; JoystickListener(const std::string &deviceName, JoystickOptionsWidget *target) : + JoystickInterfaceQt(deviceName), BaseObject(deviceName), mTarget(target) { + SYNC_PRINT(("JoystickListener::JoystickListener(%s, _): created\n", deviceName.c_str())); qRegisterMetaType("JoystickState"); } diff --git a/applications/drone/drone-ui/joystick/JoystickOptionsWidget.ui b/applications/drone/drone-ui/joystick/JoystickOptionsWidget.ui index c3c8a1df0..6f798803e 100644 --- a/applications/drone/drone-ui/joystick/JoystickOptionsWidget.ui +++ b/applications/drone/drone-ui/joystick/JoystickOptionsWidget.ui @@ -275,7 +275,7 @@ GraphPlotDialog QWidget -
graphPlotDialog.h
+
uis/graphPlotDialog.h
1
diff --git a/applications/drone/drone-ui/physicsAboutWidget.ui b/applications/drone/drone-ui/physicsAboutWidget.ui index 874106f33..cb05e30b2 100644 --- a/applications/drone/drone-ui/physicsAboutWidget.ui +++ b/applications/drone/drone-ui/physicsAboutWidget.ui @@ -33,7 +33,7 @@ AboutPropsTableWidget QTableWidget -
aboutPropsTableWidget.h
+
uis/aboutPropsTableWidget.h
diff --git a/applications/drone/drone-ui/physicsMainWindow.cpp b/applications/drone/drone-ui/physicsMainWindow.cpp index 08821227c..be7caa7e8 100644 --- a/applications/drone/drone-ui/physicsMainWindow.cpp +++ b/applications/drone/drone-ui/physicsMainWindow.cpp @@ -1,16 +1,15 @@ #include "wrappers/jsonmodern/jsonModernReader.h" -#include "calibrationWidget.h" +#include "calibration/calibrationWidget.h" #include "physicsMainWindow.h" #include "ui_physicsMainWindow.h" -#include -#include -#include +#include +#include +#include <3d/sceneShaded.h> #include - PhysicsMainWindow::PhysicsMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::PhysicsMainWindow) @@ -482,55 +481,6 @@ void PhysicsMainWindow::startSimuation() { } -void PhysicsMainWindow::frameValuesUpdate() -{ - /* std::thread thr([this]() - { - while(true) - { - if (currentMode==1) - { -#if 0 - throttleValue+=sign(throttleValueFromJS-1500); - if (throttleValue>1800){throttleValue=1799;} - if (throttleValue<900){throttleValue=901;} -#endif - } - -#if 0 - ui->Yaw->setValue(yawValue); - ui->Throttle->setValue(throttleValue); - - ui->label->setText("Yaw-"+QString::number(yawValue)); - ui->label_4->setText("throttle-"+QString::number(throttleValue)); - - ui->Pitch->setValue(pitchValue); - ui->Roll->setValue(rollValue); - - ui->label_2->setText("Roll-"+QString::number(rollValue)); - ui->label_3->setText("pitch-"+QString::number(pitchValue)); - - ui->CH5->setValue(CH5Value); - ui->CH6->setValue(CH6Value); - ui->CH7->setValue(CH7Value); - ui->CH8->setValue(CH8Value); - - ui->CH5_label->setText("CH5-"+QString::number(CH5Value)); - ui->CH6_label->setText("CH6-"+QString::number(CH6Value)); - ui->CH7_label->setText("CH7-"+QString::number(CH7Value)); - ui->CH8_label->setText("CH8-"+QString::number(CH8Value)); -#endif - - - usleep(30000); - - } - - }); - thr.detach(); -*/ -} - void PhysicsMainWindow::startRealMode() //starts controlling the copter { if (!virtualModeActive & !realModeActive) @@ -660,8 +610,8 @@ void PhysicsMainWindow::mainAction() copter.physicsTick(); } */ -/** - copter.flightControllerTick(joystick1.output); + +// copter.flightControllerTick(joystick.output); copter.physicsTick(); copter.visualTick(); @@ -681,7 +631,7 @@ void PhysicsMainWindow::mainAction() mGraphDialog.addGraphPoint("Z", copter.position.z()); mGraphDialog.update(); -**/ + //drone.flightControllerTick(joystick1.output); @@ -861,8 +811,14 @@ void PhysicsMainWindow::calibrateCamera() calibrationWidget.raise(); } -void PhysicsMainWindow::checkForJoystick() //auto connect + +void PhysicsMainWindow::repositionCloudCamera() { -// jReader->start(); + SYNC_PRINT(("PhysicsMainWindow::repositionCloudCamera(): called\n")); + CameraModel model; + mModelParametersWidget.getParameters(model); /* We get it from the UI just to be able to edit it. */ + cout << "Model to be set:" << endl; + cout << model << endl; + ui->cloud->setCamera(model); } diff --git a/applications/drone/drone-ui/physicsMainWindow.h b/applications/drone/drone-ui/physicsMainWindow.h index 7d706e9f0..37ff69540 100644 --- a/applications/drone/drone-ui/physicsMainWindow.h +++ b/applications/drone/drone-ui/physicsMainWindow.h @@ -8,37 +8,36 @@ #include #include -#include +#include #include -#include - -#include "calibration.h" -#include "cameraModelParametersControlWidget.h" -#include "capSettingsDialog.h" -#include "controlsMixer.h" -#include "flowFabricControlWidget.h" -#include "graphPlotDialog.h" -#include "inputSelectorWidget.h" -#include "radioControlWidget.h" -#include "joystickReader.h" +#include +#include "calibration/calibration.h" +#include "distortioncorrector/cameraModelParametersControlWidget.h" +#include "uis/capSettingsDialog.h" +#include "mixer/controlsMixer.h" +#include "corestructs/flowFabricControlWidget.h" +#include "uis/graphPlotDialog.h" +#include "widgets/inputSelectorWidget.h" +#include "radio/radioControlWidget.h" +#include "joystick/joystickReader.h" #include "copter/quad.h" #include "copter/droneObject.h" -#include "calibrationWidget.h" +#include "calibration/calibrationWidget.h" #include "clientSender.h" #include "copterInputsWidget.h" #include "frameProcessor.h" #include "physicsAboutWidget.h" -#include "protoautopilot.h" -#include "multimoduleController.h" +#include "autopilot/protoautopilot.h" +#include "radio/multimoduleController.h" #include "controlRecord.h" -#include "simulation.h" -#include "core/geometry/mesh/mesh3DDecorated.h" -#include "mesh3DScene.h" -#include "patternDetectorParametersWidget.h" +#include "simulation/simulation.h" +#include "geometry/mesh/mesh3DDecorated.h" +#include "3d/mesh3DScene.h" +#include "widgets/patternDetectorParametersWidget.h" namespace Ui { @@ -187,6 +186,7 @@ public slots: public slots: void updateUi(); void keepAliveJoyStick(); + void repositionCloudCamera(); /** Model download **/ public slots: @@ -200,10 +200,6 @@ public slots: private slots: - - - void checkForJoystick(); - void stopVirtualMode(); void startVirtualMode(); diff --git a/applications/drone/drone-ui/physicsMainWindow.ui b/applications/drone/drone-ui/physicsMainWindow.ui index 10e4cde28..77ae4855a 100644 --- a/applications/drone/drone-ui/physicsMainWindow.ui +++ b/applications/drone/drone-ui/physicsMainWindow.ui @@ -108,7 +108,7 @@ 0 0 1198 - 22 + 34 @@ -163,6 +163,7 @@ + @@ -170,10 +171,17 @@ + + + Simulation + + + + @@ -505,18 +513,36 @@ World Redraw + + + + :/new/prefix1/theater.png:/new/prefix1/theater.png + + + Start Simulation + + + + + + :/new/prefix1/zoom_layer.png:/new/prefix1/zoom_layer.png + + + Reposition Camera + + CloudViewDialog QWidget -
cloudViewDialog.h
+
uis/cloudview/cloudViewDialog.h
1
AdvancedImageWidget QWidget -
advancedImageWidget.h
+
uis/advancedImageWidget.h
1
@@ -528,7 +554,7 @@ LoggerWidget QWidget -
loggerWidget.h
+
widgets/loggerWidget.h
1
@@ -776,6 +802,22 @@ + + actionRepositionCamera + triggered() + PhysicsMainWindow + repositionCloudCamera() + + + -1 + -1 + + + 598 + 394 + + + showCameraInput() @@ -793,5 +835,6 @@ showPatternDetectionParameters() showProcessingParametersWidget() showStatistics() + repositionCloudCamera() diff --git a/applications/drone/drone-ui/radio/radioControlWidget.cpp b/applications/drone/drone-ui/radio/radioControlWidget.cpp index 0e4d43eb4..dbc245c2f 100644 --- a/applications/drone/drone-ui/radio/radioControlWidget.cpp +++ b/applications/drone/drone-ui/radio/radioControlWidget.cpp @@ -1,4 +1,4 @@ -#include "multimoduleController.h" +#include "radio/multimoduleController.h" #include "radioControlWidget.h" #include "ui_radioControlWidget.h" diff --git a/applications/drone/drone-ui/radio/radioControlWidget.h b/applications/drone/drone-ui/radio/radioControlWidget.h index 3f93c2f93..ed70de6c8 100644 --- a/applications/drone/drone-ui/radio/radioControlWidget.h +++ b/applications/drone/drone-ui/radio/radioControlWidget.h @@ -1,7 +1,7 @@ #ifndef RADIOCONTROLWIDGET_H #define RADIOCONTROLWIDGET_H -#include "multimoduleController.h" +#include "radio/multimoduleController.h" #include diff --git a/applications/drone/drone-utils/CMakeLists.txt b/applications/drone/drone-utils/CMakeLists.txt index e55341be7..9fe93a0dd 100644 --- a/applications/drone/drone-utils/CMakeLists.txt +++ b/applications/drone/drone-utils/CMakeLists.txt @@ -1,44 +1,52 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.10) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications/drone) +init_project(PROJECT_NAME drone-utils) + +set(SOURCE_FILE + main_drone_utils.cpp + ) + +set(SOURCES + ${SOURCE_FILE} + ) + +set(JSON_FILE + test_world.json + ) + +set(RESOURCES + ${JSON_FILE} + ) + +set_source_files_properties(${RESOURCES} + PROPERTIES + EXTERNAL_OBJECT TRUE + HEADER_FILE_ONLY TRUE + ) + +assign_source_group(${SOURCES} ${RESOURCES}) + +add_executable(${PROJECT_NAME} + ${SOURCES} + ${RESOURCES} + ) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs + corecvs_utils + drone-core + ${OpenCV_LIBS} + ) -set (NAME drone-utils) - -project (${NAME}) - -add_executable(${NAME} main_drone_utils.cpp) - - -# Temporary fixes -SET(AUTOGEN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_autogen/include") -target_include_directories(${NAME} PUBLIC ${AUTOGEN_BUILD_DIR} ) -target_include_directories(${NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ) - -message("AUTOGEN_BUILD_DIR bin directory <${AUTOGEN_BUILD_DIR}>") - -target_include_directories(${NAME} PUBLIC ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR} ${drone-core_SOURCE_DIR} .) - -target_link_libraries(${NAME} drone-core cvs_utils corecvs) - -if (OpenCV_LIBS) - target_link_libraries(${NAME} ${OpenCV_LIBS}) -endif() - - -# Additional stuff mostly for IDE only - -file(GLOB CUR_ADD_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.json) -set(ADD_SRC_FILES ${ADD_SRC_FILES} ${CUR_ADD_SRC_FILES}) - -target_sources(${NAME} PRIVATE ${ADD_SRC_FILES}) set_source_files_properties(${ADD_SRC_FILES} PROPERTIES EXTERNAL_OBJECT true HEADER_FILE_ONLY TRUE) +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) + # Adding raw resoures #add_custom_command(OUTPUT resource.o # COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/files && ld -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/resource.o test_world.json -# COMMAND objcopy --rename-section .data=.rodata,alloc,load,readonly,data,contents ${CMAKE_CURRENT_BINARY_DIR}/resource.o ${CMAKE_CURRENT_BINARY_DIR}/resource.o) - -# Copy result -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" - ) +# COMMAND objcopy --rename-section .data=.rodata,alloc,load,readonly,data,contents ${CMAKE_CURRENT_BINARY_DIR}/resource.o ${CMAKE_CURRENT_BINARY_DIR}/resource.o) \ No newline at end of file diff --git a/applications/drone/physics-test/CMakeLists.txt b/applications/drone/physics-test/CMakeLists.txt index 24efa35ec..db74cb783 100644 --- a/applications/drone/physics-test/CMakeLists.txt +++ b/applications/drone/physics-test/CMakeLists.txt @@ -1,39 +1,65 @@ -project (drone-physics-test) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications/drone) +init_project(PROJECT_NAME physics-test) +find_package(Qt5 COMPONENTS REQUIRED Gui) -set (NAME drone-physics-test ) +set(PRIVATE_HEADER_FILES + dzhanibekovBolt.h + testPhysicsObject.h + ) -set (SRC_FILES - testPhysicsObject.cpp +set(HEADERS + ${PRIVATE_HEADER_FILES} + ) + +set(SOURCE_FILES dzhanibekovBolt.cpp main_physics_test.cpp sim_physics_test.cpp -) - - -set (HDR_FILES - testPhysicsObject.h - dzhanibekovBolt.h -) + testPhysicsObject.cpp + ) +set(SOURCES + ${SOURCE_FILES} + ) -if(AVCODEC_LIBS) - message("Switching on avcodec support.") - include(../../../wrappers/avcodec/sourcelist.cmake) -endif() +assign_source_group(${HEADERS} ${SOURCES}) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES} ) +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" - ) +set(ADDITIONAL_LIBS) -if(AVCODEC_LIBS) - target_link_libraries(${NAME} ${AVCODEC_LIBS}) +if(AVCODEC_LIBS) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + AVCODECwrapper + ) + add_definitions(-DWITH_AVCODEC -DWITH_SWSCALE) endif() -target_link_libraries(${NAME} gtest gtest_main drone-core cvs_utils corecvs pthread ${LIBS}) -target_include_directories(${NAME} PUBLIC ${drone-core_SOURCE_DIR} ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR} .) +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs + corecvs_utils + drone-core + gtest + gtest_main + JSONMODERNwrapper + Qt5::Gui + pthread + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/applications/drone/physics-test/dzhanibekovBolt.h b/applications/drone/physics-test/dzhanibekovBolt.h index 4d4288378..ee38582bd 100644 --- a/applications/drone/physics-test/dzhanibekovBolt.h +++ b/applications/drone/physics-test/dzhanibekovBolt.h @@ -3,14 +3,14 @@ #include -#include -#include -#include "core/cameracalibration/calibrationDrawHelpers.h" -#include "core/math/affine.h" -#include "core/math/vector/vector3d.h" - -#include "physicsSphere.h" -#include "physicsCompoundObject.h" +#include "geometry/mesh/mesh3d.h" +#include "cameracalibration/cameraModel.h" +#include "cameracalibration/calibrationDrawHelpers.h" +#include "math/affine.h" +#include "math/vector/vector3d.h" + +#include "simulation/physicsSphere.h" +#include "simulation/physicsCompoundObject.h" #include "copterInputs.h" class DzhanibekovBolt : public PhysicsMainObject diff --git a/applications/drone/physics-test/main_physics_test.cpp b/applications/drone/physics-test/main_physics_test.cpp index 1d0461331..25e25ea2b 100644 --- a/applications/drone/physics-test/main_physics_test.cpp +++ b/applications/drone/physics-test/main_physics_test.cpp @@ -1,27 +1,25 @@ #include "gtest/gtest.h" #include "core/utils/utils.h" -#include "core/buffers/rgb24/abstractPainter.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/geometry/renderer/simpleRenderer.h" -#include "core/buffers/bufferFactory.h" -#include "core/filesystem/folderScanner.h" +#include "buffers/rgb24/abstractPainter.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "geometry/renderer/simpleRenderer.h" +#include "filesystem/folderScanner.h" #ifdef WITH_AVCODEC -#include "avEncoder.h" - -#include -#include +#include "avEncoder.h" +#include +#include #endif -#include "frSkyMultimodule.h" +#include "radio/frSkyMultimodule.h" #include -#include +#include -#include "core/fileformats/meshLoader.h" +#include "fileformats/meshLoader.h" #include "copter/quad.h" diff --git a/applications/drone/physics-test/sim_physics_test.cpp b/applications/drone/physics-test/sim_physics_test.cpp index a2a4072ef..281dbc907 100644 --- a/applications/drone/physics-test/sim_physics_test.cpp +++ b/applications/drone/physics-test/sim_physics_test.cpp @@ -16,10 +16,10 @@ #include #endif -#include "frSkyMultimodule.h" +#include "radio/frSkyMultimodule.h" #include -#include +#include "radio/multimoduleController.h" #include "core/fileformats/meshLoader.h" #include "copter/quad.h" diff --git a/applications/drone/physics-test/testPhysicsObject.h b/applications/drone/physics-test/testPhysicsObject.h index 993e9cd04..be47f8d0c 100644 --- a/applications/drone/physics-test/testPhysicsObject.h +++ b/applications/drone/physics-test/testPhysicsObject.h @@ -5,13 +5,13 @@ #include #include -#include -#include "core/cameracalibration/calibrationDrawHelpers.h" -#include "core/math/affine.h" -#include "core/math/vector/vector3d.h" +#include +#include "cameracalibration/calibrationDrawHelpers.h" +#include "math/affine.h" +#include "math/vector/vector3d.h" -#include "physicsSphere.h" -#include "physicsCompoundObject.h" +#include "simulation/physicsSphere.h" +#include "simulation/physicsCompoundObject.h" class TestPhysicsObject : public PhysicsMainObject { diff --git a/applications/egomotion/generated/ui/egomotionParametersControlWidget.h b/applications/egomotion/generated/ui/egomotionParametersControlWidget.h index 73c1fd2df..c27bbb0cf 100644 --- a/applications/egomotion/generated/ui/egomotionParametersControlWidget.h +++ b/applications/egomotion/generated/ui/egomotionParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "generated/egomotionParameters.h" #include "ui_egomotionParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/applications/imageview/CMakeLists.txt b/applications/imageview/CMakeLists.txt index 7a71ce36b..7cd64c5d2 100644 --- a/applications/imageview/CMakeLists.txt +++ b/applications/imageview/CMakeLists.txt @@ -1,40 +1,50 @@ -project (imageview) - -set(NAME imageview) - -set(CMAKE_INCLUDE_CURRENT_DIR "YES") -set(CMAKE_AUTOMOC "YES") -set(CMAKE_AUTORCC "YES") +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications) +init_project(PROJECT_NAME imageview) find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets) -set (UI_FILES - ${CMAKE_CURRENT_LIST_DIR}/imageViewMainWindow.ui +set(PRIVATE_HEADER_FILE + imageViewMainWindow.h ) -QT5_WRAP_UI( UI_HEADERS ${UI_FILES} ) - +set(HEADERS + ${PRIVATE_HEADER_FILE} + ) -add_executable(${NAME} - ${CMAKE_CURRENT_LIST_DIR}/imageViewMainWindow.h +set(SOURCE_FILES + imageViewMainWindow.cpp + main_imageview.cpp + ) - ${CMAKE_CURRENT_LIST_DIR}/imageViewMainWindow.cpp - ${CMAKE_CURRENT_LIST_DIR}/main_imageview.cpp - ${UI_HEADERS} -) +set(SOURCES + ${SOURCE_FILES} + ) -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" - ) +assign_source_group(${HEADERS} ${SOURCES}) -SET(AUTOGEN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_autogen/include") -target_include_directories(${NAME} PUBLIC ${AUTOGEN_BUILD_DIR} ) -target_include_directories(${NAME} PUBLIC ${AUTOGEN_BUILD_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -message("AUTOGEN_BUILD_DIR bin directory <${AUTOGEN_BUILD_DIR}>") +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs_utils + corecvs + Qt5::Core + Qt5::Gui + Qt5::Widgets + ) -target_include_directories(${NAME} PUBLIC ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR} .) -target_link_libraries(${NAME} cvs_utils corecvs) +set_target_properties(${PROJECT_NAME} + PROPERTIES + AUTOMOC TRUE + AUTOUIC TRUE + FOLDER "${MODULE_NAME}" + ) +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/applications/imageview/imageViewMainWindow.cpp b/applications/imageview/imageViewMainWindow.cpp index d249d5875..7a7e69365 100644 --- a/applications/imageview/imageViewMainWindow.cpp +++ b/applications/imageview/imageViewMainWindow.cpp @@ -1,12 +1,12 @@ #include -#include "pointListEditImageWidget.h" +#include "distortioncorrector/pointListEditImageWidget.h" #include "imageViewMainWindow.h" #include "ui_imageViewMainWindow.h" -#include "core/buffers/bufferFactory.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/converters/debayer.h" -#include "core/fileformats/ppmLoader.h" -#include "utils/corestructs/g12Image.h" +#include "buffers/bufferFactory.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/converters/debayer.h" +#include "fileformats/ppmLoader.h" +#include "corestructs/g12Image.h" ImageViewMainWindow::ImageViewMainWindow(QWidget *parent) : QWidget(parent), diff --git a/applications/imageview/imageViewMainWindow.h b/applications/imageview/imageViewMainWindow.h index 4e4908bb2..0b1471ac3 100644 --- a/applications/imageview/imageViewMainWindow.h +++ b/applications/imageview/imageViewMainWindow.h @@ -1,9 +1,9 @@ #ifndef IMAGEVIEWMAINWINDOW_H #define IMAGEVIEWMAINWINDOW_H -#include "core/buffers/rgb24/rgbTBuffer.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/converters/debayer.h" +#include "buffers/rgb24/rgbTBuffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/converters/debayer.h" #include diff --git a/applications/imageview/imageViewMainWindow.ui b/applications/imageview/imageViewMainWindow.ui index 914cc12f2..e551369d0 100644 --- a/applications/imageview/imageViewMainWindow.ui +++ b/applications/imageview/imageViewMainWindow.ui @@ -88,19 +88,19 @@ AdvancedImageWidget QWidget -
advancedImageWidget.h
+
uis/advancedImageWidget.h
1
BitSelectorParametersControlWidget QFrame -
bitSelectorParametersControlWidget.h
+
filters/ui/bitSelectorParametersControlWidget.h
1
DebayerParametersControlWidget QWidget -
debayerParametersControlWidget.h
+
corestructs/coreWidgets/debayerParametersControlWidget.h
1
diff --git a/applications/imageview/main_imageview.cpp b/applications/imageview/main_imageview.cpp index 93d3f5cde..46c280b9c 100644 --- a/applications/imageview/main_imageview.cpp +++ b/applications/imageview/main_imageview.cpp @@ -9,13 +9,13 @@ #include #include -#include +#include #include #include "core/utils/global.h" #include "core/utils/utils.h" -#include "qtFileLoader.h" +#include "fileformats/qtFileLoader.h" #include "imageViewMainWindow.h" int main(int argc, char *argv[]) diff --git a/applications/laserscan/main.cpp b/applications/laserscan/main.cpp index e7435c06a..53a9d3354 100644 --- a/applications/laserscan/main.cpp +++ b/applications/laserscan/main.cpp @@ -1,5 +1,5 @@ #include "core/geometry/gentryState.h" -#include "core/geometry/mesh3d.h" +#include "core/geometry/mesh/mesh3d.h" #include "calibrationHelpers.h" diff --git a/applications/nester/CMakeLists.txt b/applications/nester/CMakeLists.txt index 2fa8a532c..15b01bd0f 100644 --- a/applications/nester/CMakeLists.txt +++ b/applications/nester/CMakeLists.txt @@ -1,22 +1,43 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.10) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications) +init_project(PROJECT_NAME nester) -project(nester) +set(PRIVATE_HEADER_FILE + nester.h + ) -add_executable(nester main_nester.cpp) +set(HEADERS + ${PRIVATE_HEADER_FILE} + ) -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" - ) +set(SOURCE_FILES + main_nester.cpp + nester.cpp + ) -target_sources(nester - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/nester.h +set(SOURCES + ${SOURCE_FILES} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) + +target_link_libraries(${PROJECT_NAME} PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/main_nester.cpp - ${CMAKE_CURRENT_LIST_DIR}/nester.cpp -) + corecvs_utils + corecvs + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) -target_link_libraries(nester cvs_utils corecvs) -target_include_directories(nester PUBLIC ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR} .) \ No newline at end of file +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/applications/nester/main_nester.cpp b/applications/nester/main_nester.cpp index cd33e595e..f3cf37047 100644 --- a/applications/nester/main_nester.cpp +++ b/applications/nester/main_nester.cpp @@ -2,12 +2,12 @@ #include #include -#include "core/utils/utils.h" -#include "core/buffers/rgb24/abstractPainter.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/bufferFactory.h" -#include "core/fileformats/svgLoader.h" -#include "core/reflection/commandLineSetter.h" +#include "utils/utils.h" +#include "buffers/rgb24/abstractPainter.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/bufferFactory.h" +#include "fileformats/svgLoader.h" +#include "reflection/commandLineSetter.h" #define EPSIL 0.00001 diff --git a/applications/nester/nester.cpp b/applications/nester/nester.cpp index b1c95be8c..b27d5e820 100644 --- a/applications/nester/nester.cpp +++ b/applications/nester/nester.cpp @@ -1,14 +1,14 @@ #include #include -#include "core/utils/utils.h" -#include "core/buffers/rgb24/abstractPainter.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "utils/utils.h" +#include "buffers/rgb24/abstractPainter.h" +#include "buffers/rgb24/rgb24Buffer.h" -#include "core/fileformats/svgLoader.h" -#include +#include "fileformats/svgLoader.h" +#include #include -#include +#include #define EPSIL 0.00001 using namespace corecvs; diff --git a/applications/nester/nester.h b/applications/nester/nester.h index 636a89b91..bde4103c7 100644 --- a/applications/nester/nester.h +++ b/applications/nester/nester.h @@ -4,8 +4,8 @@ #include #include -#include "core/fileformats/svgLoader.h" -#include "core/geometry/polygons.h" +#include "fileformats/svgLoader.h" +#include "geometry/polygons.h" /* Helpers */ diff --git a/applications/qtnester/CMakeLists.txt b/applications/qtnester/CMakeLists.txt new file mode 100644 index 000000000..718c9ee22 --- /dev/null +++ b/applications/qtnester/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications) +init_project(PROJECT_NAME qtnester) + +find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets) + +set(PRIVATE_HEADER_FILES + imageViewMainWindow.h + ) + +set(HEADERS + ${PRIVATE_HEADER_FILES} + ) + +set(SOURCE_FILES + imageViewMainWindow.cpp + main_qtnester.cpp + ) + +set(SOURCES + ${SOURCE_FILES} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) + +#SET(AUTOGEN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_autogen/include") +#target_include_directories(${NAME} PUBLIC ${AUTOGEN_BUILD_DIR} ) +#target_include_directories(${NAME} PUBLIC ${AUTOGEN_BUILD_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +#message("AUTOGEN_BUILD_DIR bin directory <${AUTOGEN_BUILD_DIR}>") + +target_include_directories(${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${AUTOGEN_BUILD_DIR} + ) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs_utils + corecvs + Qt5::Core + Qt5::Gui + Qt5::Widgets + ${OpenCV_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + AUTOMOC TRUE + AUTOUIC TRUE + AUTORCC TRUE + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/applications/qtnester/imageViewMainWindow.cpp b/applications/qtnester/imageViewMainWindow.cpp new file mode 100644 index 000000000..6307620a6 --- /dev/null +++ b/applications/qtnester/imageViewMainWindow.cpp @@ -0,0 +1,208 @@ +#include +#include "distortioncorrector/pointListEditImageWidget.h" +#include "imageViewMainWindow.h" +#include "ui_imageViewMainWindow.h" +#include "buffers/bufferFactory.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/converters/debayer.h" +#include "fileformats/ppmLoader.h" +#include "utils/corestructs/g12Image.h" + +ImageViewMainWindow::ImageViewMainWindow(QWidget *parent) : + QWidget(parent), + bayer(NULL), + input(NULL), + ui(new Ui::ImageViewMainWindow) +{ + ui->setupUi(this); +#if 0 + delete(ui->widget); + PointListEditImageWidgetUnited *pointList = new PointListEditImageWidgetUnited(this); + pointList->setRightDrag(true); + ui->widget = pointList; + ui->mainLayout->addWidget(ui->widget, 0, 0, 3, 1); +#endif + + BitSelectorParameters defaultSelector; + defaultSelector.setShift(-2); + ui->bitSelector->setParameters(defaultSelector); + + ui->widget->setFitWindow(true); + ui->widget->setKeepAspect(true); + ui->widget->setRightDrag(true); + + connect(ui->bitSelector, SIGNAL(paramsChanged()), this, SLOT(paramsChanged())); + connect(ui->loadButton, SIGNAL(released()) , this, SLOT(loadImageAction())); + connect(ui->parameters, SIGNAL(paramsChanged()) , this, SLOT(debayer())); +} + +ImageViewMainWindow::~ImageViewMainWindow() +{ + delete_safe(ui); + delete_safe(input); +} + +void ImageViewMainWindow::setImage(RGB48Buffer *image) +{ + delete_safe(input); + input = image; + paramsChanged(); +} + +void ImageViewMainWindow::paramsChanged() +{ + if (input == NULL) + return; + + BitSelectorParameters mBitSelectorParameters; + ui->bitSelector->getParameters(mBitSelectorParameters); + + uint16_t mask = 0x0; + if (mBitSelectorParameters.bit0 ()) mask |= 0x0001; + if (mBitSelectorParameters.bit1 ()) mask |= 0x0002; + if (mBitSelectorParameters.bit2 ()) mask |= 0x0004; + if (mBitSelectorParameters.bit3 ()) mask |= 0x0008; + + if (mBitSelectorParameters.bit4 ()) mask |= 0x0010; + if (mBitSelectorParameters.bit5 ()) mask |= 0x0020; + if (mBitSelectorParameters.bit6 ()) mask |= 0x0040; + if (mBitSelectorParameters.bit7 ()) mask |= 0x0080; + + if (mBitSelectorParameters.bit8 ()) mask |= 0x0100; + if (mBitSelectorParameters.bit9 ()) mask |= 0x0200; + if (mBitSelectorParameters.bit10()) mask |= 0x0400; + if (mBitSelectorParameters.bit11()) mask |= 0x0800; + + if (mBitSelectorParameters.bit12()) mask |= 0x1000; + if (mBitSelectorParameters.bit13()) mask |= 0x2000; + if (mBitSelectorParameters.bit14()) mask |= 0x4000; + if (mBitSelectorParameters.bit15()) mask |= 0x8000; + + int shift = mBitSelectorParameters.shift(); + + RGB24Buffer *result = new RGB24Buffer(input->getSize()); + for (int i = 0; i < result->h; i ++) + { + for (int j = 0; j < result->w; j ++) + { + RGB48Buffer::InternalElementType colorIn = input->element(i, j); + RGBColor colorOut; + if (shift >= 0) { + colorOut.r() = (colorIn.r() & mask) << shift; + colorOut.g() = (colorIn.g() & mask) << shift; + colorOut.b() = (colorIn.b() & mask) << shift; + } + if (shift < 0) { + colorOut.r() = (colorIn.r() & mask) >> (-shift); + colorOut.g() = (colorIn.g() & mask) >> (-shift); + colorOut.b() = (colorIn.b() & mask) >> (-shift); + } + result->element(i,j) = colorOut; + } + } + // SYNC_PRINT(("Updating widget with [%d x %d]\n", result->w, result->h)); + ui->widget->setImage(QSharedPointer(new RGB24Image(result))); + ui->widget->update(); + delete_safe(result); +} + +void ImageViewMainWindow::loadImageAction() +{ + BufferFactory::getInstance()->printCaps(); + + QString name = QFileDialog::getOpenFileName( + this, + "Choose filename with Bayer or demosaic image", + ".", + "PPM Images (*.pgm *.ppm);;Generic Images (*.png *.jpg *.bmp)" + ); + if (name.isEmpty()) + return; + + loadImage(name); +} + +void ImageViewMainWindow::loadImage(QString name) +{ + delete_safe(bayer); + ui->widget->setInfoString("Loading..."); + meta.clear(); + int shift = 0; + if (name.endsWith(".ppm")) + { + SYNC_PRINT(("Loading PPM <%s>\n", name.toLatin1().constData())); + RGB48Buffer* result = PPMLoader().loadRgb48(name.toStdString(), &meta); + setImage(result); + shift = 8 - meta["bits"][0]; // left shift: 8 => 0, 10 => -2, 12 => -4 + } + else if (name.endsWith(".pgm")) + { + SYNC_PRINT(("Loading PGM <%s>\n", name.toLatin1().constData())); + bayer = PPMLoader().loadG12(name.toStdString(), &meta); + if (bayer == NULL) { + qDebug("Can't open Bayer file: %s", name.toLatin1().constData()); + } + debayer(); + shift = 8 - meta["bits"][0]; // left shift: 8 => 0, 10 => -2, 12 => -4 + } +#if 0 + else if (name.endsWith(".raw")) + { + + SYNC_PRINT(("Loading RAW <%s> - is not supported\n", name.toLatin1().constData())); + bayer = 0;// TopconRAWLoader24().loadAsBayer(name.toStdString()); // TODO: not restricted code + if (bayer == NULL) { + qDebug("Can't open Bayer file: %s", name.toLatin1().constData()); + } + debayer(); + shift = 8 - meta["bits"][0]; // left shift: 8 => 0, 10 => -2, 12 => -4 + } +#endif + + else + { + SYNC_PRINT(("Loading Generic <%s>\n", name.toLatin1().constData())); + RGB24Buffer* input = NULL; + try { + input = BufferFactory::getInstance()->loadRGB24Bitmap(name.toStdString()); + } + catch (...) { + input = nullptr; + } + if (!input) { + qDebug() << "Unable to load" << name; + return; + } + SYNC_PRINT(("Loaded size %d x %d\n", input->w, input->h)); + RGB48Buffer *image = new RGB48Buffer(input->getSize(), false); + Debayer::ConvertRgb24toRgb48(input, image); + setImage(image); + delete_safe(input); + } + + ui->widget->setInfoString("---"); + + BitSelectorParameters bitSelector; + ui->bitSelector->getParameters(bitSelector); + bitSelector.setShift(shift); + ui->bitSelector->setParameters(bitSelector); +} + +void ImageViewMainWindow::debayer() +{ + if (bayer == NULL) + return; + + Debayer::Parameters params; + ui->parameters->getParameters(params); + +#if 0 + Debayer d(bayer, meta["bits"][0], &meta, params.bayerPos()); + RGB48Buffer* result = new RGB48Buffer(bayer->h, bayer->w, false); + d.toRGB48(params.method(), result); +#else + RGB48Buffer* result = Debayer::DemosaicRgb48(bayer, params, meta); +#endif + + setImage(result); +} diff --git a/applications/qtnester/imageViewMainWindow.h b/applications/qtnester/imageViewMainWindow.h new file mode 100644 index 000000000..4e4908bb2 --- /dev/null +++ b/applications/qtnester/imageViewMainWindow.h @@ -0,0 +1,41 @@ +#ifndef IMAGEVIEWMAINWINDOW_H +#define IMAGEVIEWMAINWINDOW_H + +#include "core/buffers/rgb24/rgbTBuffer.h" +#include "core/buffers/g12Buffer.h" +#include "core/buffers/converters/debayer.h" + +#include + +namespace Ui { +class ImageViewMainWindow; +} + +using namespace corecvs; + +class ImageViewMainWindow : public QWidget +{ + Q_OBJECT + +public: + MetaData meta; + G12Buffer *bayer; + + RGB48Buffer *input; + explicit ImageViewMainWindow(QWidget *parent = 0); + ~ImageViewMainWindow(); + +public slots: + + void setImage(RGB48Buffer *image); + + void paramsChanged(void); + void loadImageAction(); + void loadImage(QString name); + + void debayer(); +private: + Ui::ImageViewMainWindow *ui; +}; + +#endif // IMAGEVIEWMAINWINDOW_H diff --git a/applications/qtnester/imageViewMainWindow.ui b/applications/qtnester/imageViewMainWindow.ui new file mode 100644 index 000000000..4608bb160 --- /dev/null +++ b/applications/qtnester/imageViewMainWindow.ui @@ -0,0 +1,109 @@ + + + ImageViewMainWindow + + + + 0 + 0 + 853 + 762 + + + + Form + + + + + + + + + + 0 + 0 + + + + + + + Load + + + Load + + + + :/new/prefix1/remove.png:/new/prefix1/remove.png + + + + 24 + 24 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 250 + 16777215 + + + + + + + + + 0 + 0 + + + + + + + + + AdvancedImageWidget + QWidget +
uis/advancedImageWidget.h
+ 1 +
+ + BitSelectorParametersControlWidget + QFrame +
filters/ui/bitSelectorParametersControlWidget.h
+ 1 +
+ + DebayerParametersControlWidget + QWidget +
corestructs/coreWidgets/debayerParametersControlWidget.h
+ 1 +
+
+ + +
diff --git a/applications/qtnester/main_qtnester.cpp b/applications/qtnester/main_qtnester.cpp new file mode 100644 index 000000000..1b79373ef --- /dev/null +++ b/applications/qtnester/main_qtnester.cpp @@ -0,0 +1,45 @@ +/** + * \file main_qt_recorder.cpp + * \brief Entry point for the recorder application + * + * \date Sep 17, 2010 + * \author Sergey Levi + */ + +#include +#include + +#include +#include + +#include "utils/global.h" + +#include "utils/utils.h" +#include "fileformats/qtFileLoader.h" +#include "imageViewMainWindow.h" + +int main(int argc, char *argv[]) +{ + SET_HANDLERS(); + + Q_INIT_RESOURCE(main); + + SYNC_PRINT(("Starting ImageView...\n")); + BufferFactory::printCaps(); + + QApplication app(argc, argv); + ImageViewMainWindow mainWindow; + + QTG12Loader::registerMyself(); + QTRGB24Loader::registerMyself(); + + if (argc > 1) + { + qDebug("Main: %s", argv[1]); + mainWindow.loadImage(QString(argv[1])); + } + + mainWindow.show(); + app.exec(); + SYNC_PRINT(("Exiting ImageView application...\n")); +} diff --git a/applications/recorder/recorderControlWidget.h b/applications/recorder/recorderControlWidget.h index 7097aa5d0..c8add69a6 100644 --- a/applications/recorder/recorderControlWidget.h +++ b/applications/recorder/recorderControlWidget.h @@ -4,7 +4,7 @@ #include #include "generatedParameters/recorder.h" #include "ui_recorderControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { class RecorderControlWidget; diff --git a/applications/robodetect/robodetectMainWindow.h b/applications/robodetect/robodetectMainWindow.h index 927e8a964..aa03af9cf 100644 --- a/applications/robodetect/robodetectMainWindow.h +++ b/applications/robodetect/robodetectMainWindow.h @@ -5,7 +5,7 @@ #include #include "ui_robodetectMainWindow.h" -#include "advancedImageWidget.h" +#include "uis/advancedImageWidget.h" #include "core/buffers/rgb24/rgb24Buffer.h" #include "cloudViewDialog.h" #include "localHistogram.h" diff --git a/applications/robodetect/widgets/robodetectImageWidget.h b/applications/robodetect/widgets/robodetectImageWidget.h index 2ec3b739f..a814b5302 100644 --- a/applications/robodetect/widgets/robodetectImageWidget.h +++ b/applications/robodetect/widgets/robodetectImageWidget.h @@ -6,7 +6,7 @@ * \date Dec 2, 2013 **/ -#include "advancedImageWidget.h" +#include "uis/advancedImageWidget.h" class RobodetectImageWidget: public AdvancedImageWidget { diff --git a/applications/scanner/scannerParametersControlWidget.h b/applications/scanner/scannerParametersControlWidget.h index 3b6e2c91f..d957c78d6 100644 --- a/applications/scanner/scannerParametersControlWidget.h +++ b/applications/scanner/scannerParametersControlWidget.h @@ -5,7 +5,7 @@ #include #include "generatedParameters/scannerParameters.h" #include "ui_scannerParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" #include "scannerThread.h" namespace Ui { diff --git a/applications/testbed/testbedMainWindow.h b/applications/testbed/testbedMainWindow.h index c7c778699..445a45fb3 100644 --- a/applications/testbed/testbedMainWindow.h +++ b/applications/testbed/testbedMainWindow.h @@ -5,7 +5,7 @@ #include #include "ui_testbedMainWindow.h" -#include "advancedImageWidget.h" +#include "uis/advancedImageWidget.h" #include "core/buffers/rgb24/rgb24Buffer.h" #include "cloudViewDialog.h" #include "localHistogram.h" diff --git a/applications/testbed/widgets/testbedImageWidget.h b/applications/testbed/widgets/testbedImageWidget.h index fbb9af214..5d15770e0 100644 --- a/applications/testbed/widgets/testbedImageWidget.h +++ b/applications/testbed/widgets/testbedImageWidget.h @@ -6,7 +6,7 @@ * \date Dec 2, 2013 **/ -#include "advancedImageWidget.h" +#include "uis/advancedImageWidget.h" class TestbedImageWidget: public AdvancedImageWidget { diff --git a/applications/vinylCutter/CMakeLists.txt b/applications/vinylCutter/CMakeLists.txt index 2ab61a45e..8af6fc174 100644 --- a/applications/vinylCutter/CMakeLists.txt +++ b/applications/vinylCutter/CMakeLists.txt @@ -1,45 +1,68 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.10) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME applications) +init_project(PROJECT_NAME vinylCutter) -project(vinylCutter) +find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets) -set(CMAKE_INCLUDE_CURRENT_DIR "YES") -set(CMAKE_AUTOMOC "YES") -set(CMAKE_AUTOUIC "YES") +set(PRIVATE_HEADER_FILES + gcodeHandler.h + mainWindow.h + myGraphicsView.h + gcodeToSceneInterpreter.h + ) -find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets Script) +set(HEADERS + ${PRIVATE_HEADER_FILES} + ) -add_executable(vinylCutter main_vinylCutter.cpp) +set(SOURCE_FILES + main_vinylCutter.cpp + mainWindow.cpp + myGraphicsView.cpp + gcodeHandler.cpp + gcodeToSceneInterpreter.cpp + ) -target_sources(vinylCutter - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/mainWindow.h +set(SOURCES + ${SOURCE_FILES} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) + +target_include_directories(${PROJECT_NAME} PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/main_vinylCutter.cpp - ${CMAKE_CURRENT_LIST_DIR}/mainWindow.cpp - ${CMAKE_CURRENT_LIST_DIR}/myGraphicsView.cpp - ${CMAKE_CURRENT_LIST_DIR}/gcodeHandler.cpp - ${CMAKE_CURRENT_LIST_DIR}/gcodeToSceneInterpreter.cpp -) + ${CMAKE_CURRENT_SOURCE_DIR} + ) + +file(GLOB RESOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/*.*) # Resource files copying: # we don't want to copy if we're building in the source dir -if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) - - # list of files for which we add a copy rule - set(data_SHADOW resources/background.png) - - foreach(item IN LISTS data_SHADOW) - message(STATUS ${item}) - add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${item}" - COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${item}" "${CMAKE_CURRENT_BINARY_DIR}/${item}" - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${item}" +if(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) + copy_files(${PROJECT_NAME} + RESOURCE_FILES + ${CMAKE_CURRENT_BINARY_DIR}/resources/ ) - endforeach() endif() -# files are only copied if a target depends on them -add_custom_target(data-target ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/resources/background.png") +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs_utils + corecvs + Qt5::Core + Qt5::Gui + Qt5::Widgets + ) -target_link_libraries(vinylCutter cvs_utils corecvs) -target_include_directories(vinylCutter PUBLIC ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR} .) \ No newline at end of file +set_target_properties(${PROJECT_NAME} + PROPERTIES + AUTOMOC TRUE + AUTOUIC TRUE + AUTORCC TRUE + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/applications/vinylCutter/mainWindow.cpp b/applications/vinylCutter/mainWindow.cpp index bc1f7c913..e67ac6481 100644 --- a/applications/vinylCutter/mainWindow.cpp +++ b/applications/vinylCutter/mainWindow.cpp @@ -1,5 +1,5 @@ #include "mainWindow.h" -#include "./ui_mainWindow.h" +#include "ui_mainWindow.h" using namespace corecvs; diff --git a/build_corecvs.sh b/build_corecvs.sh new file mode 100755 index 000000000..4b0ce865f --- /dev/null +++ b/build_corecvs.sh @@ -0,0 +1,9 @@ +mkdir -p build + +cd build + +cmake .. -DCMAKE_BUILD_TYPE=Release + +cmake --build . + +sudo make install \ No newline at end of file diff --git a/cmake/Modules/FindAVCodec.cmake b/cmake/Modules/FindAVCodec.cmake index d08d0be7e..fa3af4599 100644 --- a/cmake/Modules/FindAVCodec.cmake +++ b/cmake/Modules/FindAVCodec.cmake @@ -1,134 +1,128 @@ -SET(AVCODEC_INCLUDE_SEARCH_PATHS +set(AVCODEC_INCLUDE_SEARCH_PATHS /usr/include /usr/local/include /opt/libavcodec/include - $ENV{AVCODEC_HOME} - $ENV{AVCODEC_HOME}/include + $ENV{AVCODEC_ROOT_DIR} #CMake standart + $ENV{AVCODEC_ROOT_DIR}/include /usr/include/x86_64-linux-gnu/ -) + ) -SET(AVCODEC_LIB_SEARCH_PATHS +set(AVCODEC_LIB_SEARCH_PATHS /lib/ /lib64/ /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 - $ENV{AVCODEC_HOME} - $ENV{AVCODEC_HOME}/lib -) + $ENV{AVCODEC_ROOT_DIR} + $ENV{AVCODEC_ROOT_DIR}/lib + ) -# -#include -#include -#include -# - -FIND_PATH(AVCODEC_INCLUDE_DIR NAMES libavcodec/avcodec.h PATHS ${AVCODEC_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(AVCODEC_LIB NAMES avcodec PATHS ${AVCODEC_LIB_SEARCH_PATHS}) +find_path(AVCODEC_INCLUDE_DIR NAMES libavcodec/avcodec.h PATHS ${AVCODEC_INCLUDE_SEARCH_PATHS}) +find_library(AVCODEC_LIB NAMES avcodec libavcodec PATHS ${AVCODEC_LIB_SEARCH_PATHS}) -SET(AVCODEC_FOUND ON) +set(AVCODEC_FOUND ON) # Check include files -IF(NOT AVCODEC_INCLUDE_DIR) - SET(AVCODEC_FOUND OFF) - MESSAGE(STATUS "Could not find AVCODEC include. Turning AVCODEC_FOUND off") -ENDIF() +if(NOT AVCODEC_INCLUDE_DIR) + set(AVCODEC_FOUND OFF) + message(STATUS "Could not find AVCODEC include. Turning AVCODEC_FOUND off") +endif() # Check libraries -IF(NOT AVCODEC_LIB) - SET(AVCODEC_FOUND OFF) - MESSAGE(STATUS "Could not find AVCODEC lib. Turning AVCODEC_FOUND off") -ENDIF() +if(NOT AVCODEC_LIB) + set(AVCODEC_FOUND OFF) + message(STATUS "Could not find AVCODEC lib. Turning AVCODEC_FOUND off") +endif() -IF (AVCODEC_FOUND) - MESSAGE(STATUS "Found AVCODEC libraries: ${AVCODEC_LIB}") - MESSAGE(STATUS "Found AVCODEC include: ${AVCODEC_INCLUDE_DIR}") -ENDIF() +if(AVCODEC_FOUND) + message(STATUS "Found AVCODEC libraries: ${AVCODEC_LIB}") + message(STATUS "Found AVCODEC include: ${AVCODEC_INCLUDE_DIR}") +endif() ################################################### # ################################################### -FIND_PATH(AVUTIL_INCLUDE_DIR NAMES libavutil/frame.h PATHS ${AVCODEC_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(AVUTIL_LIB NAMES avutil PATHS ${AVCODEC_LIB_SEARCH_PATHS}) +find_path(AVUTIL_INCLUDE_DIR NAMES libavutil/frame.h PATHS ${AVCODEC_INCLUDE_SEARCH_PATHS}) +find_library(AVUTIL_LIB NAMES avutil libavutil PATHS ${AVCODEC_LIB_SEARCH_PATHS}) -SET(AVUTIL_FOUND ON) +set(AVUTIL_FOUND ON) # Check include files -IF(NOT AVUTIL_INCLUDE_DIR) - SET(AVUTIL_FOUND OFF) - MESSAGE(STATUS "Could not find AVUTIL include. Turning AVCODEC_FOUND off") -ENDIF() +if(NOT AVUTIL_INCLUDE_DIR) + set(AVUTIL_FOUND OFF) + message(STATUS "Could not find AVUTIL include. Turning AVCODEC_FOUND off") +endif() # Check libraries -IF(NOT AVUTIL_LIB) - SET(AVUTIL_FOUND OFF) - MESSAGE(STATUS "Could not find AVUTIL lib. Turning AVCODEC_FOUND off") -ENDIF() +if(NOT AVUTIL_LIB) + set(AVUTIL_FOUND OFF) + message(STATUS "Could not find AVUTIL lib. Turning AVCODEC_FOUND off") +endif() -IF (AVUTIL_FOUND) - MESSAGE(STATUS "Found AVUTIL libraries: ${AVUTIL_LIB}") - MESSAGE(STATUS "Found AVUTIL include: ${AVUTIL_INCLUDE_DIR}") -ENDIF() +if(AVUTIL_FOUND) + message(STATUS "Found AVUTIL libraries: ${AVUTIL_LIB}") + message(STATUS "Found AVUTIL include: ${AVUTIL_INCLUDE_DIR}") +endif() ################################################### # ################################################### -FIND_PATH(AVFORMAT_INCLUDE_DIR NAMES libavformat/avformat.h PATHS ${AVCODEC_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(AVFORMAT_LIB NAMES avformat PATHS ${AVCODEC_LIB_SEARCH_PATHS}) +find_path(AVFORMAT_INCLUDE_DIR NAMES libavformat/avformat.h PATHS ${AVCODEC_INCLUDE_SEARCH_PATHS}) +find_library(AVFORMAT_LIB NAMES avformat libavformat PATHS ${AVCODEC_LIB_SEARCH_PATHS}) -SET(AVFORMAT_FOUND ON) +set(AVFORMAT_FOUND ON) # Check include files -IF(NOT AVFORMAT_INCLUDE_DIR) - SET(AVFORMAT_FOUND OFF) - MESSAGE(STATUS "Could not find AVFORMAT include. Turning AVFORMAT_FOUND off") -ENDIF() +if(NOT AVFORMAT_INCLUDE_DIR) + set(AVFORMAT_FOUND OFF) + message(STATUS "Could not find AVFORMAT include. Turning AVFORMAT_FOUND off") +endif() # Check libraries -IF(NOT AVFORMAT_LIB) - SET(AVFORMAT_FOUND OFF) - MESSAGE(STATUS "Could not find AVFORMAT lib. Turning AVFORMAT_FOUND off") -ENDIF() +if(NOT AVFORMAT_LIB) + set(AVFORMAT_FOUND OFF) + message(STATUS "Could not find AVFORMAT lib. Turning AVFORMAT_FOUND off") +endif() -IF (AVFORMAT_FOUND) - MESSAGE(STATUS "Found AVFORMAT libraries: ${AVFORMAT_LIB}") - MESSAGE(STATUS "Found AVFORMAT include: ${AVFORMAT_INCLUDE_DIR}") -ENDIF() +if(AVFORMAT_FOUND) + message(STATUS "Found AVFORMAT libraries: ${AVFORMAT_LIB}") + message(STATUS "Found AVFORMAT include: ${AVFORMAT_INCLUDE_DIR}") +endif() ################################################### # ################################################### -FIND_PATH(SWSCALE_INCLUDE_DIR NAMES libswscale/swscale.h PATHS ${AVCODEC_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(SWSCALE_LIB NAMES swscale PATHS ${AVCODEC_LIB_SEARCH_PATHS}) +find_path(SWSCALE_INCLUDE_DIR NAMES libswscale/swscale.h PATHS ${AVCODEC_INCLUDE_SEARCH_PATHS}) +find_library(SWSCALE_LIB NAMES swscale libswscale PATHS ${AVCODEC_LIB_SEARCH_PATHS}) -SET(SWSCALE_FOUND ON) +set(SWSCALE_FOUND ON) # Check include files -IF(NOT SWSCALE_INCLUDE_DIR) - SET(SWSCALE_FOUND OFF) - MESSAGE(STATUS "Could not find SWSCALE include. Turning SWSCALE_FOUND off") -ENDIF() +if(NOT SWSCALE_INCLUDE_DIR) + set(SWSCALE_FOUND OFF) + message(STATUS "Could not find SWSCALE include. Turning SWSCALE_FOUND off") +endif() # Check libraries -IF(NOT SWSCALE_LIB) - SET(SWSCALE_FOUND OFF) - MESSAGE(STATUS "Could not find SWSCALE lib. Turning SWSCALE_FOUND off") -ENDIF() +if(NOT SWSCALE_LIB) + set(SWSCALE_FOUND OFF) + message(STATUS "Could not find SWSCALE lib. Turning SWSCALE_FOUND off") +endif() -IF (SWSCALE_FOUND) - MESSAGE(STATUS "Found SWSCALE libraries: ${SWSCALE_LIB}") - MESSAGE(STATUS "Found SWSCALE include: ${SWSCALE_INCLUDE_DIR}") -ENDIF() +if(SWSCALE_FOUND) + message(STATUS "Found SWSCALE libraries: ${SWSCALE_LIB}") + message(STATUS "Found SWSCALE include: ${SWSCALE_INCLUDE_DIR}") +endif() ################################################### -# + ################################################### if (AVCODEC_FOUND AND AVUTIL_FOUND AND AVFORMAT_FOUND AND SWSCALE_FOUND) set(AVCODEC_LIBS ${AVCODEC_LIB} ${AVUTIL_LIB} ${AVFORMAT_LIB} ${SWSCALE_LIB}) set(AVCODEC_INCLUDES ${AVCODEC_INCLUDE_DIR} ${AVUTIL_INCLUDE_DIR} ${AVFORMAT_INCLUDE_DIR} ${SWSCALE_INCLUDE_DIR}) - - MESSAGE(STATUS "Found all libs for encoder <${AVCODEC_LIBS}>") + message(STATUS "Found all libs for encoder <${AVCODEC_LIBS}>") endif() +mark_as_advanced(AVCODEC_LIBS AVCODEC_INCLUDES) diff --git a/cmake/Modules/FindApriltag.cmake b/cmake/Modules/FindApriltag.cmake index 05ec10a33..08f82d01e 100644 --- a/cmake/Modules/FindApriltag.cmake +++ b/cmake/Modules/FindApriltag.cmake @@ -1,4 +1,4 @@ -SET(APRILTAG_INCLUDE_SEARCH_PATHS +set(APRILTAG_INCLUDE_SEARCH_PATHS ${CMAKE_CURRENT_LIST_DIR}/../../siblings/apriltag # /usr/include/ # /usr/local/include/ @@ -6,7 +6,7 @@ SET(APRILTAG_INCLUDE_SEARCH_PATHS /usr/local/include/apriltag/common/ ) -SET(APRILTAG_LIB_SEARCH_PATHS +set(APRILTAG_LIB_SEARCH_PATHS ${CMAKE_CURRENT_LIST_DIR}/../../siblings/apriltag ${CMAKE_CURRENT_LIST_DIR}/../../siblings/apriltag/build ${CMAKE_CURRENT_LIST_DIR}/../../siblings/apriltag/build/lib @@ -20,7 +20,7 @@ SET(APRILTAG_LIB_SEARCH_PATHS #message(APRILTAG_LIB_SEARCH_PATHS: ${APRILTAG_LIB_SEARCH_PATHS}) -FIND_PATH(APRILTAG_INCLUDE_DIR NAMES +find_path(APRILTAG_INCLUDE_DIR NAMES apriltag.h apriltag_math.h apriltag_pose.h @@ -63,14 +63,25 @@ FIND_PATH(APRILTAG_INCLUDE_DIR NAMES PATHS ${APRILTAG_INCLUDE_SEARCH_PATHS} NO_DEFAULT_PATH ) -FIND_LIBRARY(APRILTAG_LIB NAMES apriltag PATHS ${APRILTAG_LIB_SEARCH_PATHS} NO_DEFAULT_PATH) +find_library(APRILTAG_LIB NAMES apriltag PATHS ${APRILTAG_LIB_SEARCH_PATHS} NO_DEFAULT_PATH) -if (APRILTAG_LIB) +if(APRILTAG_LIB) message("Apriltag has been found.") MESSAGE(STATUS "Found Apriltag libraries: ${APRILTAG_LIB}") MESSAGE(STATUS "Found Apriltag include: ${APRILTAG_INCLUDE_DIR}") - SET(APRILTAG_FOUND ON) + set(APRILTAG_FOUND ON) else() - SET(APRILTAG_FOUND OFF) + set(APRILTAG_FOUND OFF) endif() + + if(NOT TARGET APRILTAG::APRILTAG) + add_library(APRILTAG::APRILTAG SHARED IMPORTED) + set_target_properties(APRILTAG::APRILTAG PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${APRILTAG_INCLUDE_DIR}") + if(EXISTS "${APRILTAG_LIB}") + set_target_properties(APRILTAG::APRILTAG PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${APRILTAG_LIB}") + endif() + endif() \ No newline at end of file diff --git a/cmake/Modules/FindCeres.cmake b/cmake/Modules/FindCeres.cmake index c6d90d928..9231906f2 100644 --- a/cmake/Modules/FindCeres.cmake +++ b/cmake/Modules/FindCeres.cmake @@ -1,14 +1,15 @@ -SET(CERES_INCLUDE_SEARCH_PATHS +set(CERES_INCLUDE_SEARCH_PATHS /usr/include /usr/include/ceres /usr/local/include + /usr/local/include/ceres /usr/local/include/png-base /opt/libjpeg/include $ENV{CERES_HOME} $ENV{CERES_HOME}/include -) + ) -SET(CERES_LIB_SEARCH_PATHS +set(CERES_LIB_SEARCH_PATHS /lib/ /lib64/ /usr/lib @@ -18,38 +19,39 @@ SET(CERES_LIB_SEARCH_PATHS /opt/libjpeg/lib $ENV{CERES_HOME} $ENV{CERES_HOME}/lib -) + ) -FIND_PATH(CERES_INCLUDE_DIR NAMES ceres.h PATHS ${CERES_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(CERES_LIB NAMES ceres PATHS ${CERES_LIB_SEARCH_PATHS}) +find_path(CERES_INCLUDE_DIR NAMES ceres.h PATHS ${CERES_INCLUDE_SEARCH_PATHS}) +find_library(CERES_LIB NAMES libceres ceres PATHS ${CERES_LIB_SEARCH_PATHS}) -SET(CERES_FOUND ON) +set(CERES_FOUND ON) # Check include files -IF(NOT CERES_INCLUDE_DIR) - SET(CERES_FOUND OFF) - MESSAGE(STATUS "Could not find CERES include. Turning CERES_FOUND off") -ENDIF() +if(NOT CERES_INCLUDE_DIR) + set(CERES_FOUND OFF) + message(STATUS "Could not find CERES include. Turning CERES_FOUND off") +endif() # Check libraries -IF(NOT CERES_LIB) - SET(CERES_FOUND OFF) - MESSAGE(STATUS "Could not find CERES lib. Turning CERES_FOUND off") -ENDIF() - -IF (CERES_FOUND) -IF (NOT CERES_FIND_QUIETLY) - MESSAGE(STATUS "Found CERES libraries: ${CERES_LIB}") - MESSAGE(STATUS "Found CERES include: ${CERES_INCLUDE_DIR}") -ENDIF (NOT CERES_FIND_QUIETLY) -ELSE (CERES_FOUND) -IF (CERES_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find CERES") -ENDIF (CERES_FIND_REQUIRED) -ENDIF (CERES_FOUND) - -MARK_AS_ADVANCED( - CERES_INCLUDE_DIR - CERES_LIB - CERES -) +if(NOT CERES_LIB) + set(CERES_FOUND OFF) + message(STATUS "Could not find CERES lib. Turning CERES_FOUND off") +endif() + + +if(CERES_FOUND) +if(NOT CERES_FIND_QUIETLY) + message(STATUS "Found CERES libraries: ${CERES_LIB}") + message(STATUS "Found CERES include: ${CERES_INCLUDE_DIR}") +endif(NOT CERES_FIND_QUIETLY) +else(CERES_FOUND) +if(CERES_FIND_REQUIRED) + message(FATAL_ERROR "Could not find CERES") +endif(CERES_FIND_REQUIRED) +endif(CERES_FOUND) + +mark_as_advanced( + CERES_INCLUDE_DIR + CERES_LIB + CERES + ) diff --git a/cmake/Modules/FindEigen.cmake b/cmake/Modules/FindEigen.cmake index 5b33f8a92..c106b2158 100644 --- a/cmake/Modules/FindEigen.cmake +++ b/cmake/Modules/FindEigen.cmake @@ -8,18 +8,18 @@ SET(EIGEN_INCLUDE_SEARCH_PATHS $ENV{EIGEN_HOME}/include ) -FIND_PATH(EIGEN_INCLUDE_DIR NAMES Eigen/Core PATHS ${EIGEN_INCLUDE_SEARCH_PATHS}) +FIND_PATH(EIGEN_INCLUDE_DIRS NAMES Eigen/Core PATHS ${EIGEN_INCLUDE_SEARCH_PATHS}) SET(EIGEN_FOUND ON) # Check include files -IF(NOT EIGEN_INCLUDE_DIR) +IF(NOT EIGEN_INCLUDE_DIRS) SET(EIGEN_FOUND OFF) MESSAGE(STATUS "Could not find EIGEN include. Turning EIGEN_FOUND off") ENDIF() IF (EIGEN_FOUND) - MESSAGE(STATUS "Found EIGEN include: ${EIGEN_INCLUDE_DIR}") + MESSAGE(STATUS "Found EIGEN include: ${EIGEN_INCLUDE_DIRS}") ENDIF (EIGEN_FOUND) MARK_AS_ADVANCED( diff --git a/cmake/Modules/FindFFTW.cmake b/cmake/Modules/FindFFTW.cmake new file mode 100644 index 000000000..4dd1dac86 --- /dev/null +++ b/cmake/Modules/FindFFTW.cmake @@ -0,0 +1,80 @@ +cmake_minimum_required(VERSION 3.11) + +set(FFTW_FOUND FALSE) + +set(FFTW_INCLUDE_SEARCH_PATHS + /usr/include + /usr/include/FFTW + /usr/local/include + /opt/libFFTW/include + $ENV{FFTW_ROOT_DIR} + $ENV{FFTW_ROOT_DIR}/include + ) + +set(FFTW_LIB_SEARCH_PATHS + /lib/ + /lib64/ + /usr/lib + /usr/lib64 + /usr/local/lib + /usr/local/lib64 + /usr/lib/x86_64-linux-gnu + /opt/libFFTW/lib + $ENV{FFTW_ROOT_DIR} + $ENV{FFTW_ROOT_DIR}/lib + ) + +set(FFTW_INCLUDE_DIR NOTFOUND) +find_path(FFTW_INCLUDE_DIR + fftw3.h + PATHS ${FFTW_INCLUDE_SEARCH_PATHS} + NO_DEFAULT_PATH + ) + +set(FFTW_ERROR_REASON) +if(NOT FFTW_INCLUDE_DIR) + string(APPEND + FFTW_ERROR_REASON + "INCLUDE_DIRS for FFTW module not found. Set FFTW_ROOT to the location of FFTW." + ) +endif() + +#Check if we can use PkgConfig +find_package(PkgConfig) + +#Determine from PKG +if( PKG_CONFIG_FOUND AND NOT FFTW_ROOT ) + pkg_check_modules( PKG_FFTW QUIET "libfftw3" ) +endif() + +if(NOT FFTW_LIBRARY) + +find_library(FFTW_LIBRARY + NAMES libfftw3.so.3 libfftw3 libfftw + PATHS ${FFTW_LIB_SEARCH_PATHS} + ) + +endif() + +if(FFTW_INCLUDE_DIR) + set(FFTW_FOUND TRUE) +endif() + +if(FFTW_FOUND) + set(FFTW_LIBRARIES ${FFTW_LIBRARY}) + set(FFTW_INCLUDE_DIRS ${FFTW_INCLUDE_DIR}) + + if(NOT TARGET FFTW::FFTW) + add_library(FFTW::FFTW INTERFACE IMPORTED) + if(FFTW_INCLUDE_DIRS) + set_target_properties(FFTW::FFTW PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${FFTW_INCLUDE_DIRS}) + endif() + if(EXISTS ${FFTW_LIBRARIES}) + set_target_properties(FFTW::FFTW PROPERTIES + INTERFACE_LINK_LIBRARIES ${FFTW_LIBRARIES}) + endif() + endif() +endif() + +mark_as_advanced( FFTW_INCLUDE_DIRS FFTW_LIBRARIES) \ No newline at end of file diff --git a/cmake/Modules/FindJpeg.cmake b/cmake/Modules/FindJpeg.cmake index 88d25c068..8b8ffd249 100644 --- a/cmake/Modules/FindJpeg.cmake +++ b/cmake/Modules/FindJpeg.cmake @@ -1,14 +1,18 @@ -SET(JPEG_INCLUDE_SEARCH_PATHS +cmake_minimum_required(VERSION 3.11) + +set(JPEG_FOUND FALSE) + +set(JPEG_INCLUDE_SEARCH_PATHS /usr/include /usr/include/jpeg /usr/local/include /usr/local/include/png-base /opt/libjpeg/include - $ENV{JPEG_HOME} - $ENV{JPEG_HOME}/include -) + $ENV{JPEG_ROOT_DIR} + $ENV{JPEG_ROOT_DIR}/include + ) -SET(JPEG_LIB_SEARCH_PATHS +set(JPEG_LIB_SEARCH_PATHS /lib/ /lib64/ /usr/lib @@ -16,40 +20,52 @@ SET(JPEG_LIB_SEARCH_PATHS /usr/local/lib /usr/local/lib64 /opt/libjpeg/lib - $ENV{JPEG_HOME} - $ENV{JPEG_HOME}/lib -) - -FIND_PATH(JPEG_INCLUDE_DIR NAMES jpeglib.h PATHS ${JPEG_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(JPEG_LIB NAMES jpeg PATHS ${JPEG_LIB_SEARCH_PATHS}) - -SET(JPEG_FOUND ON) - -# Check include files -IF(NOT JPEG_INCLUDE_DIR) - SET(JPEG_FOUND OFF) - MESSAGE(STATUS "Could not find JPEG include. Turning JPEG_FOUND off") -ENDIF() - -# Check libraries -IF(NOT JPEG_LIB) - SET(JPEG_FOUND OFF) - MESSAGE(STATUS "Could not find JPEG lib. Turning JPEG_FOUND off") -ENDIF() - -IF (JPEG_FOUND) -IF (NOT JPEG_FIND_QUIETLY) - MESSAGE(STATUS "Found JPEG libraries: ${JPEG_LIB}") - MESSAGE(STATUS "Found JPEG include: ${JPEG_INCLUDE_DIR}") -ENDIF (NOT JPEG_FIND_QUIETLY) -ELSE (JPEG_FOUND) -IF (JPEG_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find JPEG") -ENDIF (JPEG_FIND_REQUIRED) -ENDIF (JPEG_FOUND) - -MARK_AS_ADVANCED( - JPEG_INCLUDE_DIR - JPEG_LIB - JPEG -) + $ENV{JPEG_ROOT_DIR} + $ENV{JPEG_ROOT_DIR}/lib + ) + +set(jpeg_headers ${jpeg_headers} jpeg.h libjpeg.h jpeglib.h) + +set(JPEG_INCLUDE_DIR NOTFOUND) +find_path(JPEG_INCLUDE_DIR + ${jpeg_headers} + PATHS ${JPEG_INCLUDE_SEARCH_PATHS} + NO_DEFAULT_PATH + ) + +set(JPEG_ERROR_REASON) +if(NOT JPEG_INCLUDE_DIR) + string(APPEND + JPEG_ERROR_REASON + "INCLUDE_DIRS for JPEG module not found. Set JPEG_ROOT to the location of JPEG." + ) +endif() + +set(jpeg_names ${JPEG_NAMES} jpeg jpeg-static libjpeg libjpeg.dll libjpeg-static) + +if(NOT JPEG_LIBRARY) + find_library(JPEG_LIBRARY NAMES ${jpeg_names} PATHS ${JPEG_LIB_SEARCH_PATHS}) +endif() + +if(JPEG_INCLUDE_DIR) + set(JPEG_FOUND TRUE) +endif() + +if(JPEG_FOUND) + set(JPEG_LIBRARIES ${JPEG_LIBRARY}) + set(JPEG_INCLUDE_DIRS ${JPEG_INCLUDE_DIR}) + + if(NOT TARGET JPEG::JPEG) + add_library(JPEG::JPEG INTERFACE IMPORTED) + if(JPEG_INCLUDE_DIRS) + set_target_properties(JPEG::JPEG PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${JPEG_INCLUDE_DIRS}) + endif() + if(EXISTS ${JPEG_LIBRARIES}) + set_target_properties(JPEG::JPEG PROPERTIES + INTERFACE_LINK_LIBRARIES ${JPEG_LIBRARIES}) + endif() + endif() +endif() + +mark_as_advanced(JPEG_LIBRARIES JPEG_INCLUDE_DIRS) \ No newline at end of file diff --git a/cmake/Modules/FindLapacke.cmake b/cmake/Modules/FindLapacke.cmake index 610b6a5cd..085d267a6 100644 --- a/cmake/Modules/FindLapacke.cmake +++ b/cmake/Modules/FindLapacke.cmake @@ -1,59 +1,69 @@ -SET(Lapacke_INCLUDE_SEARCH_PATHS -/usr/include -/usr/include/Lapacke -/usr/include/Lapacke-base -/usr/local/include -/usr/local/include/Lapacke -/usr/local/include/Lapacke-base -/opt/Lapacke/include -$ENV{Lapacke_HOME} -$ENV{Lapacke_HOME}/include -) - -SET(Lapacke_LIB_SEARCH_PATHS - /lib/ - /lib64/ - /usr/lib - /usr/lib64 - /usr/local/lib - /usr/local/lib64 - /opt/Lapacke/lib - $ENV{Lapacke}cd - $ENV{Lapacke}/lib - $ENV{Lapacke_HOME} - $ENV{Lapacke_HOME}/lib -) - -FIND_PATH(Lapacke_INCLUDE_DIR NAMES lapacke.h PATHS ${Lapacke_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(Lapacke_LIB NAMES lapacke PATHS ${Lapacke_LIB_SEARCH_PATHS}) - -SET(Lapacke_FOUND ON) +set(Lapacke_INCLUDE_SEARCH_PATHS + /usr/include + /usr/include/Lapacke + /usr/include/Lapacke-base + /usr/local/include + /usr/local/include/Lapacke + /usr/local/include/Lapacke-base + /opt/Lapacke/include + $ENV{Lapacke_ROOT_DIR} + $ENV{Lapacke_ROOT_DIR}/include + ) + +set(Lapacke_LIB_SEARCH_PATHS + /lib/ + /lib64/ + /usr/lib + /usr/lib64 + /usr/local/lib + /usr/lib/x86_64-linux-gnu + /usr/local/lib64 + /opt/Lapacke/lib + $ENV{Lapacke_ROOT_DIR} + $ENV{Lapacke_ROOT_DIR}/lib + ) + +find_path(Lapacke_INCLUDE_DIR NAMES lapacke.h PATHS ${Lapacke_INCLUDE_SEARCH_PATHS}) +find_library(Lapacke_LIB NAMES liblapacke liblapacke.so PATHS ${Lapacke_LIB_SEARCH_PATHS}) + +set(Lapacke_FOUND ON) # Check include files -IF(NOT Lapacke_INCLUDE_DIR) - SET(Lapacke_FOUND OFF) - MESSAGE(STATUS "Could not find Lapacke include. Turning Lapacke_FOUND off") -ENDIF() +if(NOT Lapacke_INCLUDE_DIR) + set(Lapacke_FOUND OFF) + message(STATUS "Could not find Lapacke include. Turning Lapacke_FOUND off") +endif() # Check libraries -IF(NOT Lapacke_LIB) - SET(Lapacke_FOUND OFF) - MESSAGE(STATUS "Could not find Lapacke lib. Turning Lapacke_FOUND off") -ENDIF() - -IF (Lapacke_FOUND) -IF (NOT Lapacke_FIND_QUIETLY) - MESSAGE(STATUS "Found Lapacke libraries: ${Lapacke_LIB}") - MESSAGE(STATUS "Found Lapacke include: ${Lapacke_INCLUDE_DIR}") -ENDIF (NOT Lapacke_FIND_QUIETLY) -ELSE (Lapacke_FOUND) -IF (Lapacke_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find Lapacke") -ENDIF (Lapacke_FIND_REQUIRED) -ENDIF (Lapacke_FOUND) - -MARK_AS_ADVANCED( - Lapacke_INCLUDE_DIR - Lapacke_LIB - Lapacke -) +if(NOT Lapacke_LIB) + set(Lapacke_FOUND OFF) + message(STATUS "Could not find Lapacke lib. Turning Lapacke_FOUND off") +endif() + +if (Lapacke_FOUND) +if (NOT Lapacke_FIND_QUIETLY) + message(STATUS "Found Lapacke libraries: ${Lapacke_LIB}") + message(STATUS "Found Lapacke include: ${Lapacke_INCLUDE_DIR}") +endif (NOT Lapacke_FIND_QUIETLY) +else (Lapacke_FOUND) +if (Lapacke_FIND_REQUIRED) + message(FATAL_ERROR "Could not find Lapacke") +endif (Lapacke_FIND_REQUIRED) +endif (Lapacke_FOUND) + + if(NOT TARGET LAPACKE::LAPACKE) + add_library(LAPACKE::LAPACKE SHARED IMPORTED) + set_target_properties(LAPACKE::LAPACKE PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Lapacke_INCLUDE_DIR}") + if(EXISTS "${Lapacke_LIB}") + set_target_properties(LAPACKE::LAPACKE PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${Lapacke_LIB}") + endif() + endif() + +mark_as_advanced( + Lapacke_INCLUDE_DIR + Lapacke_LIB + Lapacke + ) diff --git a/cmake/Modules/FindOpenBlas.cmake b/cmake/Modules/FindOpenBlas.cmake index b2179c268..3c42ed4e1 100644 --- a/cmake/Modules/FindOpenBlas.cmake +++ b/cmake/Modules/FindOpenBlas.cmake @@ -1,68 +1,70 @@ + set(Open_BLAS_INCLUDE_SEARCH_PATHS + /usr/include + /usr/include/openblas + /usr/include/openblas-base + /usr/local/include + /usr/local/include/openblas + /usr/local/include/openblas-base + /opt/OpenBLAS/include + $ENV{OpenBLAS_ROOT_DIR} + $ENV{OpenBLAS_ROOT_DIR}/include + ) + set(Open_BLAS_LIB_SEARCH_PATHS + /lib/ + /lib/openblas-base + /lib64/ + /usr/lib + /usr/lib/openblas-base + /usr/lib64 + /usr/local/lib + /usr/local/lib64 + /opt/OpenBLAS/lib + $ENV{OpenBLAS_ROOT_DIR} + $ENV{OpenBLAS_ROOT_DIR}/lib + ) -SET(Open_BLAS_INCLUDE_SEARCH_PATHS - ${CMAKE_CURRENT_LIST_DIR}/../../siblings/OpenBLAS - /usr/include - /usr/include/openblas - /usr/include/openblas-base - /usr/local/include - /usr/local/include/openblas - /usr/local/include/openblas-base - /opt/OpenBLAS/include - $ENV{OpenBLAS_HOME} - $ENV{OpenBLAS_HOME}/include - /usr/include/x86_64-linux-gnu/ -) +find_path(OpenBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS}) +find_library(OpenBLAS_LIB NAMES openblas libopenblas libopenblas.so PATHS ${Open_BLAS_LIB_SEARCH_PATHS}) -SET(Open_BLAS_LIB_SEARCH_PATHS - ${CMAKE_CURRENT_LIST_DIR}/../../siblings/OpenBLAS - /lib/ - /lib/openblas-base - /lib64/ - /usr/lib - /usr/lib/openblas-base - /usr/lib/x86_64-linux-gnu/ - /usr/lib64 - /usr/local/lib - /usr/local/lib64 - /opt/OpenBLAS/lib - $ENV{OpenBLAS}cd - $ENV{OpenBLAS}/lib - $ENV{OpenBLAS_HOME} - $ENV{OpenBLAS_HOME}/lib - -) - -FIND_PATH(OpenBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS} NO_DEFAULT_PATH) -FIND_LIBRARY(OpenBLAS_LIB NAMES openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS} NO_DEFAULT_PATH) - -SET(OpenBLAS_FOUND ON) +set(OpenBLAS_FOUND ON) # Check include files -IF(NOT OpenBLAS_INCLUDE_DIR) - SET(OpenBLAS_FOUND OFF) - MESSAGE(STATUS "Could not find OpenBLAS include. Turning OpenBLAS_FOUND off") -ENDIF() +if(NOT OpenBLAS_INCLUDE_DIR) + set(OpenBLAS_FOUND OFF) + message(STATUS "Could not find OpenBLAS include. Turning OpenBLAS_FOUND off") +endif() # Check libraries -IF(NOT OpenBLAS_LIB) - SET(OpenBLAS_FOUND OFF) - MESSAGE(STATUS "Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off") -ENDIF() +if(NOT OpenBLAS_LIB) + set(OpenBLAS_FOUND OFF) + message(STATUS "Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off") +endif() + +if (OpenBLAS_FOUND) +if (NOT OpenBLAS_FIND_QUIETLY) + message(STATUS "Found OpenBLAS libraries: ${OpenBLAS_LIB}") + message(STATUS "Found OpenBLAS include: ${OpenBLAS_INCLUDE_DIR}") +endif (NOT OpenBLAS_FIND_QUIETLY) +else (OpenBLAS_FOUND) +if (OpenBLAS_FIND_REQUIRED) + message(FATAL_ERROR "Could not find OpenBLAS") +endif (OpenBLAS_FIND_REQUIRED) +endif (OpenBLAS_FOUND) -IF (OpenBLAS_FOUND) -IF (NOT OpenBLAS_FIND_QUIETLY) - MESSAGE(STATUS "Found OpenBLAS libraries: ${OpenBLAS_LIB}") - MESSAGE(STATUS "Found OpenBLAS include: ${OpenBLAS_INCLUDE_DIR}") -ENDIF (NOT OpenBLAS_FIND_QUIETLY) -ELSE (OpenBLAS_FOUND) -IF (OpenBLAS_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find OpenBLAS") -ENDIF (OpenBLAS_FIND_REQUIRED) -ENDIF (OpenBLAS_FOUND) + if(NOT TARGET OPENBLAS::OPENBLAS) + add_library(OPENBLAS::OPENBLAS SHARED IMPORTED) + set_target_properties(OPENBLAS::OPENBLAS PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${OpenBLAS_INCLUDE_DIR}") + if(EXISTS "${OpenBLAS_LIB}") + set_target_properties(OPENBLAS::OPENBLAS PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${OpenBLAS_LIB}") + endif() + endif() -MARK_AS_ADVANCED( - OpenBLAS_INCLUDE_DIR - OpenBLAS_LIB - OpenBLAS -) +mark_as_advanced( + OpenBLAS_INCLUDE_DIR + OpenBLAS_LIB + OpenBLAS + ) diff --git a/cmake/Modules/FindPng.cmake b/cmake/Modules/FindPng.cmake index f13c244b1..a8ba9c83d 100644 --- a/cmake/Modules/FindPng.cmake +++ b/cmake/Modules/FindPng.cmake @@ -1,14 +1,60 @@ -SET(PNG_INCLUDE_SEARCH_PATHS +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindPNG +------- + +Find libpng, the official reference library for the PNG image format. + +Imported targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` target: + +``PNG::PNG`` + The libpng library, if found. + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``PNG_INCLUDE_DIRS`` + where to find png.h, etc. +``PNG_LIBRARIES`` + the libraries to link against to use PNG. +``PNG_DEFINITIONS`` + You should add_definitions(${PNG_DEFINITIONS}) before compiling code + that includes png library files. +``PNG_FOUND`` + If false, do not try to use PNG. +``PNG_VERSION_STRING`` + the version of the PNG library found (since CMake 2.8.8) + +Obsolete variables +^^^^^^^^^^^^^^^^^^ + +The following variables may also be set, for backwards compatibility: + +``PNG_LIBRARY`` + where to find the PNG library. +``PNG_INCLUDE_DIR`` + where to find the PNG headers (same as PNG_INCLUDE_DIRS) + +#]=======================================================================] + +set(PNG_INCLUDE_SEARCH_PATHS /usr/include /usr/include/png /usr/local/include /usr/local/include/png-base /opt/libpng/include - $ENV{PNG_HOME} - $ENV{PNG_HOME}/include -) + $ENV{PNG_ROOT_DIR} + $ENV{PNG_ROOT_DIR}/include + ) -SET(PNG_LIB_SEARCH_PATHS +set(PNG_LIB_SEARCH_PATHS /lib/ /lib64/ /usr/lib @@ -16,40 +62,96 @@ SET(PNG_LIB_SEARCH_PATHS /usr/local/lib /usr/local/lib64 /opt/png/lib - $ENV{PNG_HOME} - $ENV{PNG_HOME}/lib -) - -FIND_PATH(PNG_INCLUDE_DIR NAMES png.h PATHS ${PNG_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(PNG_LIB NAMES png PATHS ${PNG_LIB_SEARCH_PATHS}) - -SET(PNG_FOUND ON) - -# Check include files -IF(NOT PNG_INCLUDE_DIR) - SET(PNG_FOUND OFF) - MESSAGE(STATUS "Could not find PNG include. Turning PNG_FOUND off") -ENDIF() - -# Check libraries -IF(NOT PNG_LIB) - SET(PNG_FOUND OFF) - MESSAGE(STATUS "Could not find PNG lib. Turning PNG_FOUND off") -ENDIF() - -IF (PNG_FOUND) -IF (NOT PNG_FIND_QUIETLY) - MESSAGE(STATUS "Found PNG libraries: ${PNG_LIB}") - MESSAGE(STATUS "Found PNG include: ${PNG_INCLUDE_DIR}") -ENDIF (NOT PNG_FIND_QUIETLY) -ELSE (PNG_FOUND) -IF (PNG_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find PNG") -ENDIF (PNG_FIND_REQUIRED) -ENDIF (PNG_FOUND) - -MARK_AS_ADVANCED( - PNG_INCLUDE_DIR - PNG_LIB - PNG -) + $ENV{PNG_ROOT_DIR} + $ENV{PNG_ROOT_DIR}/lib + ) + +find_path(PNG_PNG_INCLUDE_DIR png.h PATHS ${PNG_INCLUDE_SEARCH_PATHS}) + +list(APPEND PNG_NAMES png libpng) + unset(PNG_NAMES_DEBUG) + +set(_PNG_VERSION_SUFFIXES 17 16 15 14 12) +if (PNG_FIND_VERSION MATCHES "^([0-9]+)\\.([0-9]+)(\\..*)?$") + set(_PNG_VERSION_SUFFIX_MIN "${CMAKE_MATCH_1}${CMAKE_MATCH_2}") + if (PNG_FIND_VERSION_EXACT) + set(_PNG_VERSION_SUFFIXES ${_PNG_VERSION_SUFFIX_MIN}) + else () + string(REGEX REPLACE + "${_PNG_VERSION_SUFFIX_MIN}.*" "${_PNG_VERSION_SUFFIX_MIN}" + _PNG_VERSION_SUFFIXES "${_PNG_VERSION_SUFFIXES}") + endif () + unset(_PNG_VERSION_SUFFIX_MIN) + endif () + foreach(v IN LISTS _PNG_VERSION_SUFFIXES) + list(APPEND PNG_NAMES png${v} libpng${v}) + list(APPEND PNG_NAMES_DEBUG png${v}d libpng${v}d) + endforeach() + unset(_PNG_VERSION_SUFFIXES) + # For compatibility with versions prior to this multi-config search, honor + # any PNG_LIBRARY that is already specified and skip the search. + if(NOT PNG_LIBRARY) + find_library(PNG_LIBRARY_RELEASE NAMES ${PNG_NAMES} PATHS ${PNG_LIB_SEARCH_PATHS}) + find_library(PNG_LIBRARY_DEBUG NAMES ${PNG_NAMES_DEBUG} PATHS ${PNG_LIB_SEARCH_PATHS}) + include(SelectLibraryConfigurations) + select_library_configurations(PNG) + mark_as_advanced(PNG_LIBRARY_RELEASE PNG_LIBRARY_DEBUG) + endif() + unset(PNG_NAMES) + unset(PNG_NAMES_DEBUG) + + # Set by select_library_configurations(), but we want the one from + # find_package_handle_standard_args() below. + unset(PNG_FOUND) + + if (PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR) + # png.h includes zlib.h. Sigh. + set(PNG_INCLUDE_DIRS ${PNG_PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ) + set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIRS} ) # for backward compatibility + set(PNG_LIBRARIES ${PNG_LIBRARY} ${ZLIB_LIBRARY}) + + if (CYGWIN) + if(BUILD_SHARED_LIBS) + # No need to define PNG_USE_DLL here, because it's default for Cygwin. + else() + set (PNG_DEFINITIONS -DPNG_STATIC) + set(_PNG_COMPILE_DEFINITIONS PNG_STATIC) + endif() + endif () + + if(NOT TARGET PNG::PNG) + add_library(PNG::PNG UNKNOWN IMPORTED) + set_target_properties(PNG::PNG PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "${_PNG_COMPILE_DEFINITIONS}" + INTERFACE_INCLUDE_DIRECTORIES "${PNG_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES PNG::PNG) + if(EXISTS "${PNG_LIBRARY}") + set_target_properties(PNG::PNG PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${PNG_LIBRARY}") + endif() + if(EXISTS "${PNG_LIBRARY_RELEASE}") + set_property(TARGET PNG::PNG APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(PNG::PNG PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${PNG_LIBRARY_RELEASE}") + endif() + if(EXISTS "${PNG_LIBRARY_DEBUG}") + set_property(TARGET PNG::PNG APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(PNG::PNG PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" + IMPORTED_LOCATION_DEBUG "${PNG_LIBRARY_DEBUG}") + endif() + endif() + + unset(_PNG_COMPILE_DEFINITIONS) + endif () + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PNG + REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR + VERSION_VAR PNG_VERSION_STRING) + +mark_as_advanced(PNG_PNG_INCLUDE_DIR PNG_LIBRARY PNG_LIB LIBPNG) diff --git a/cmake/Modules/FindSoapySDR.cmake b/cmake/Modules/FindSoapySDR.cmake new file mode 100644 index 000000000..854a04c20 --- /dev/null +++ b/cmake/Modules/FindSoapySDR.cmake @@ -0,0 +1,51 @@ +SET(SOAPYSDR_INCLUDE_SEARCH_PATHS + /usr/include + /usr/local/include + $ENV{SOAPYSDR_HOME} + $ENV{SOAPYSDR_HOME}/include +) + +SET(SOAPYSDR_LIB_SEARCH_PATHS + /lib/ + /lib64/ + /usr/lib + /usr/lib64 + /usr/local/lib + /usr/local/lib64 + $ENV{SOAPYSDR_HOME} + $ENV{SOAPYSDR_HOME}/lib +) + +FIND_PATH(SOAPYSDR_INCLUDE_DIR NAMES SoapySDR/Version.h PATHS ${SOAPYSDR_INCLUDE_SEARCH_PATHS}) +FIND_LIBRARY(SOAPYSDR_LIB NAMES SoapySDR PATHS ${SOAPYSDR_LIB_SEARCH_PATHS}) + +SET(SOAPYSDR_FOUND ON) + +# Check include files +IF(NOT SOAPYSDR_INCLUDE_DIR) + SET(SOAPYSDR_FOUND OFF) + MESSAGE(STATUS "Could not find SOAPYSDR include. Turning SOAPYSDR_FOUND off") +ENDIF() + +# Check libraries +IF(NOT SOAPYSDR_LIB) + SET(SOAPYSDR_FOUND OFF) + MESSAGE(STATUS "Could not find SOAPYSDR lib. Turning SOAPYSDR_FOUND off") +ENDIF() + +IF (SOAPYSDR_FOUND) +IF (NOT SOAPYSDR_FIND_QUIETLY) + MESSAGE(STATUS "Found SOAPYSDR libraries: ${SOAPYSDR_LIB}") + MESSAGE(STATUS "Found SOAPYSDR include: ${SOAPYSDR_INCLUDE_DIR}") +ENDIF (NOT SOAPYSDR_FIND_QUIETLY) +ELSE (SOAPYSDR_FOUND) +IF (SOAPYSDR_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find SOAPYSDR") +ENDIF (SOAPYSDR_FIND_REQUIRED) +ENDIF (SOAPYSDR_FOUND) + +MARK_AS_ADVANCED( + SOAPYSDR_INCLUDE_DIR + SOAPYSDR_LIB + SOAPYSDR +) diff --git a/cmake/Modules/FindTBB.cmake b/cmake/Modules/FindTBB.cmake index 2464fc42c..18065ebc4 100644 --- a/cmake/Modules/FindTBB.cmake +++ b/cmake/Modules/FindTBB.cmake @@ -1,13 +1,6 @@ -# Locate Intel Threading Building Blocks include paths and libraries -# FindTBB.cmake can be found at https://code.google.com/p/findtbb/ -# Written by Hannes Hofmann -# Improvements by Gino van den Bergen , -# Florian Uhlig , -# Jiri Marsik - -# The MIT License +# The MIT License (MIT) # -# Copyright (c) 2011 Hannes Hofmann +# Copyright (c) 2015 Justus Calvin # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -16,274 +9,345 @@ # 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 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. +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. -# GvdB: This module uses the environment variable TBB_ARCH_PLATFORM which defines architecture and compiler. -# e.g. "ia32/vc8" or "em64t/cc4.1.0_libc2.4_kernel2.6.16.21" -# TBB_ARCH_PLATFORM is set by the build script tbbvars[.bat|.sh|.csh], which can be found -# in the TBB installation directory (TBB_INSTALL_DIR). # -# GvdB: Mac OS X distribution places libraries directly in lib directory. +# Findtbb +# ------- # -# For backwards compatibility, you may explicitely set the CMake variables TBB_ARCHITECTURE and TBB_COMPILER. -# TBB_ARCHITECTURE [ ia32 | em64t | itanium ] -# which architecture to use -# TBB_COMPILER e.g. vc9 or cc3.2.3_libc2.3.2_kernel2.4.21 or cc4.0.1_os10.4.9 -# which compiler to use (detected automatically on Windows) - -# This module respects -# TBB_INSTALL_DIR or $ENV{TBB21_INSTALL_DIR} or $ENV{TBB_INSTALL_DIR} - -# This module defines -# TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc. -# TBB_LIBRARY_DIRS, where to find libtbb, libtbbmalloc -# TBB_DEBUG_LIBRARY_DIRS, where to find libtbb_debug, libtbbmalloc_debug -# TBB_INSTALL_DIR, the base TBB install directory -# TBB_LIBRARIES, the libraries to link against to use TBB. -# TBB_DEBUG_LIBRARIES, the libraries to link against to use TBB with debug symbols. -# TBB_FOUND, If false, don't try to use TBB. -# TBB_INTERFACE_VERSION, as defined in tbb/tbb_stddef.h - - -if (WIN32) -# has em64t/vc8 em64t/vc9 -# has ia32/vc7.1 ia32/vc8 ia32/vc9 -set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB") -set(_TBB_LIB_NAME "tbb") -set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") -set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") -set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") -if (MSVC71) -set (_TBB_COMPILER "vc7.1") -endif(MSVC71) -if (MSVC80) -set(_TBB_COMPILER "vc8") -endif(MSVC80) -if (MSVC90) -set(_TBB_COMPILER "vc9") -endif(MSVC90) -if(MSVC10) -set(_TBB_COMPILER "vc10") -endif(MSVC10) -# Todo: add other Windows compilers such as ICL. -set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) -endif (WIN32) - -if (UNIX) -if (APPLE) -# MAC -set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions") -# libs: libtbb.dylib, libtbbmalloc.dylib, *_debug -set(_TBB_LIB_NAME "tbb") -set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") -set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") -set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") -# default flavor on apple: ia32/cc4.0.1_os10.4.9 -# Jiri: There is no reason to presume there is only one flavor and -# that user's setting of variables should be ignored. -if(NOT TBB_COMPILER) -set(_TBB_COMPILER "cc4.0.1_os10.4.9") -elseif (NOT TBB_COMPILER) -set(_TBB_COMPILER ${TBB_COMPILER}) -endif(NOT TBB_COMPILER) -if(NOT TBB_ARCHITECTURE) -set(_TBB_ARCHITECTURE "ia32") -elseif(NOT TBB_ARCHITECTURE) -set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) -endif(NOT TBB_ARCHITECTURE) -else (APPLE) -# LINUX -set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include") -set(_TBB_LIB_NAME "tbb") -set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") -set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") -set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") -# has em64t/cc3.2.3_libc2.3.2_kernel2.4.21 em64t/cc3.3.3_libc2.3.3_kernel2.6.5 em64t/cc3.4.3_libc2.3.4_kernel2.6.9 em64t/cc4.1.0_libc2.4_kernel2.6.16.21 -# has ia32/* -# has itanium/* -set(_TBB_COMPILER ${TBB_COMPILER}) -set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) -endif (APPLE) -endif (UNIX) - -if (CMAKE_SYSTEM MATCHES "SunOS.*") -# SUN -# not yet supported -# has em64t/cc3.4.3_kernel5.10 -# has ia32/* -endif (CMAKE_SYSTEM MATCHES "SunOS.*") - - -#-- Clear the public variables -set (TBB_FOUND "NO") - - -#-- Find TBB install dir and set ${_TBB_INSTALL_DIR} and cached ${TBB_INSTALL_DIR} -# first: use CMake variable TBB_INSTALL_DIR -if (TBB_INSTALL_DIR) -set (_TBB_INSTALL_DIR ${TBB_INSTALL_DIR}) -endif (TBB_INSTALL_DIR) -# second: use environment variable -if (NOT _TBB_INSTALL_DIR) -if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") -set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR}) -endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") -# Intel recommends setting TBB21_INSTALL_DIR -if (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") -set (_TBB_INSTALL_DIR $ENV{TBB21_INSTALL_DIR}) -endif (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") -if (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "") -set (_TBB_INSTALL_DIR $ENV{TBB22_INSTALL_DIR}) -endif (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "") -if (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "") -set (_TBB_INSTALL_DIR $ENV{TBB30_INSTALL_DIR}) -endif (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "") -endif (NOT _TBB_INSTALL_DIR) -# third: try to find path automatically -if (NOT _TBB_INSTALL_DIR) -if (_TBB_DEFAULT_INSTALL_DIR) -set (_TBB_INSTALL_DIR ${_TBB_DEFAULT_INSTALL_DIR}) -endif (_TBB_DEFAULT_INSTALL_DIR) -endif (NOT _TBB_INSTALL_DIR) -# sanity check -if (NOT _TBB_INSTALL_DIR) -message (STATUS "Unable to find Intel TBB install directory. ${_TBB_INSTALL_DIR}") -else (NOT _TBB_INSTALL_DIR) -# finally: set the cached CMake variable TBB_INSTALL_DIR -if (NOT TBB_INSTALL_DIR) -set (TBB_INSTALL_DIR ${_TBB_INSTALL_DIR} CACHE PATH "Intel TBB install directory") -mark_as_advanced(TBB_INSTALL_DIR) -endif (NOT TBB_INSTALL_DIR) - - -#-- A macro to rewrite the paths of the library. This is necessary, because -# find_library() always found the em64t/vc9 version of the TBB libs -macro(TBB_CORRECT_LIB_DIR var_name) -# if (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t") -string(REPLACE em64t "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}}) -# endif (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t") -string(REPLACE ia32 "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}}) -string(REPLACE vc7.1 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) -string(REPLACE vc8 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) -string(REPLACE vc9 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) -string(REPLACE vc10 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) -endmacro(TBB_CORRECT_LIB_DIR var_content) - - -#-- Look for include directory and set ${TBB_INCLUDE_DIR} -set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include) -# Jiri: tbbvars now sets the CPATH environment variable to the directory -# containing the headers. -find_path(TBB_INCLUDE_DIR - tbb/task_scheduler_init.h - tbb/parallel_for.h -PATHS ${TBB_INC_SEARCH_DIR} ENV CPATH -) -mark_as_advanced(TBB_INCLUDE_DIR) - - -#-- Look for libraries -# GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh] -if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") -set (_TBB_LIBRARY_DIR -${_TBB_INSTALL_DIR}/lib/$ENV{TBB_ARCH_PLATFORM} -${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib -) -endif (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") -# Jiri: This block isn't mutually exclusive with the previous one -# (hence no else), instead I test if the user really specified -# the variables in question. -if ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL "")) -# HH: deprecated -message(STATUS "[Warning] FindTBB.cmake: The use of TBB_ARCHITECTURE and TBB_COMPILER is deprecated and may not be supported in future versions. Please set \$ENV{TBB_ARCH_PLATFORM} (using tbbvars.[bat|csh|sh]).") -# Jiri: It doesn't hurt to look in more places, so I store the hints from -# ENV{TBB_ARCH_PLATFORM} and the TBB_ARCHITECTURE and TBB_COMPILER -# variables and search them both. -set (_TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}/lib" ${_TBB_LIBRARY_DIR}) -endif ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL "")) - -# GvdB: Mac OS X distribution places libraries directly in lib directory. -list(APPEND _TBB_LIBRARY_DIR ${_TBB_INSTALL_DIR}/lib) - -# Jiri: No reason not to check the default paths. From recent versions, -# tbbvars has started exporting the LIBRARY_PATH and LD_LIBRARY_PATH -# variables, which now point to the directories of the lib files. -# It all makes more sense to use the ${_TBB_LIBRARY_DIR} as a HINTS -# argument instead of the implicit PATHS as it isn't hard-coded -# but computed by system introspection. Searching the LIBRARY_PATH -# and LD_LIBRARY_PATH environment variables is now even more important -# that tbbvars doesn't export TBB_ARCH_PLATFORM and it facilitates -# the use of TBB built from sources. -find_library(TBB_LIBRARY ${_TBB_LIB_NAME} HINTS ${_TBB_LIBRARY_DIR} -PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) -find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} HINTS ${_TBB_LIBRARY_DIR} -PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) - -#Extract path from TBB_LIBRARY name -get_filename_component(TBB_LIBRARY_DIR ${TBB_LIBRARY} PATH) - -#TBB_CORRECT_LIB_DIR(TBB_LIBRARY) -#TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY) -mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY) - -#-- Look for debug libraries -# Jiri: Changed the same way as for the release libraries. -find_library(TBB_LIBRARY_DEBUG ${_TBB_LIB_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} -PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) -find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} -PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) - -# Jiri: Self-built TBB stores the debug libraries in a separate directory. -# Extract path from TBB_LIBRARY_DEBUG name -get_filename_component(TBB_LIBRARY_DEBUG_DIR ${TBB_LIBRARY_DEBUG} PATH) - -#TBB_CORRECT_LIB_DIR(TBB_LIBRARY_DEBUG) -#TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY_DEBUG) -mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG) - - -if (TBB_INCLUDE_DIR) -if (TBB_LIBRARY) -set (TBB_FOUND "YES") -set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES}) -set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES}) -set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) -set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE) -# Jiri: Self-built TBB stores the debug libraries in a separate directory. -set (TBB_DEBUG_LIBRARY_DIRS ${TBB_LIBRARY_DEBUG_DIR} CACHE PATH "TBB debug library directory" FORCE) -mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_DEBUG_LIBRARY_DIRS TBB_LIBRARIES TBB_DEBUG_LIBRARIES) -message(STATUS "Found Intel TBB") -message(STATUS "Intel TBB include dir: " "${TBB_INCLUDE_DIR}") -message(STATUS "Intel TBB library dir: " "${TBB_LIBRARY_DIR}") -message(STATUS "Intel TBB libraries : " "${TBB_LIBRARIES}" ) - - -endif (TBB_LIBRARY) -endif (TBB_INCLUDE_DIR) - -if (NOT TBB_FOUND) -message("ERROR: Intel TBB NOT found!") -message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}") -# do only throw fatal, if this pkg is REQUIRED -if (TBB_FIND_REQUIRED) -message(FATAL_ERROR "Could NOT find TBB library.") -endif (TBB_FIND_REQUIRED) -endif (NOT TBB_FOUND) - -endif (NOT _TBB_INSTALL_DIR) - -if (TBB_FOUND) -set(TBB_INTERFACE_VERSION 0) -FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS) -STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}") -set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}") -endif (TBB_FOUND) +# Find TBB include directories and libraries. +# +# Usage: +# +# find_package(tbb [major[.minor]] [EXACT] +# [QUIET] [REQUIRED] +# [[COMPONENTS] [components...]] +# [OPTIONAL_COMPONENTS components...]) +# +# where the allowed components are tbbmalloc and tbb_preview. Users may modify +# the behavior of this module with the following variables: +# +# * TBB_ROOT_DIR - The base directory the of TBB installation. +# * TBB_INCLUDE_DIR - The directory that contains the TBB headers files. +# * TBB_LIBRARY - The directory that contains the TBB library files. +# * TBB__LIBRARY - The path of the TBB the corresponding TBB library. +# These libraries, if specified, override the +# corresponding library search results, where +# may be tbb, tbb_debug, tbbmalloc, tbbmalloc_debug, +# tbb_preview, or tbb_preview_debug. +# * TBB_USE_DEBUG_BUILD - The debug version of tbb libraries, if present, will +# be used instead of the release version. +# +# Users may modify the behavior of this module with the following environment +# variables: +# +# * TBB_INSTALL_DIR +# * TBBROOT +# * LIBRARY_PATH +# +# This module will set the following variables: +# +# * TBB_FOUND - Set to false, or undefined, if we haven’t found, or +# don’t want to use TBB. +# * TBB__FOUND - If False, optional part of TBB sytem is +# not available. +# * TBB_VERSION - The full version string +# * TBB_VERSION_MAJOR - The major version +# * TBB_VERSION_MINOR - The minor version +# * TBB_INTERFACE_VERSION - The interface version number defined in +# tbb/tbb_stddef.h. +# * TBB__LIBRARY_RELEASE - The path of the TBB release version of +# , where may be tbb, tbb_debug, +# tbbmalloc, tbbmalloc_debug, tbb_preview, or +# tbb_preview_debug. +# * TBB__LIBRARY_DEGUG - The path of the TBB release version of +# , where may be tbb, tbb_debug, +# tbbmalloc, tbbmalloc_debug, tbb_preview, or +# tbb_preview_debug. +# +# The following varibles should be used to build and link with TBB: +# +# * TBB_INCLUDE_DIRS - The include directory for TBB. +# * TBB_LIBRARIES - The libraries to link against to use TBB. +# * TBB_LIBRARIES_RELEASE - The release libraries to link against to use TBB. +# * TBB_LIBRARIES_DEBUG - The debug libraries to link against to use TBB. +# * TBB_DEFINITIONS - Definitions to use when compiling code that uses +# TBB. +# * TBB_DEFINITIONS_RELEASE - Definitions to use when compiling release code that +# uses TBB. +# * TBB_DEFINITIONS_DEBUG - Definitions to use when compiling debug code that +# uses TBB. +# +# This module will also create the "tbb::tbb" target that may be used when building +# executables and libraries. + +include(FindPackageHandleStandardArgs) + +if(NOT TBB_FOUND) + + ################################## + # Check the build type + ################################## + + if(NOT DEFINED TBB_USE_DEBUG_BUILD) + if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug|RelWithDebInfo|RELWITHDEBINFO|relwithdebinfo)") + set(TBB_BUILD_TYPE DEBUG) + else() + set(TBB_BUILD_TYPE RELEASE) + endif() + elseif(TBB_USE_DEBUG_BUILD) + set(TBB_BUILD_TYPE DEBUG) + else() + set(TBB_BUILD_TYPE RELEASE) + endif() + + ################################## + # Set the TBB search directories + ################################## + + # Define search paths based on user input and environment variables + set(TBB_SEARCH_DIR ${TBB_ROOT_DIR} $ENV{TBB_INSTALL_DIR} $ENV{TBB_ROOT_DIR} $ENV{TBB_PATH}) + + # Define the search directories based on the current platform + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(TBB_DEFAULT_SEARCH_DIR "C:/Program Files/Intel/TBB" + "C:/Program Files (x86)/Intel/TBB") + + # Set the target architecture + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(TBB_ARCHITECTURE "intel64") + else() + set(TBB_ARCHITECTURE "ia32") + endif() + + # Set the TBB search library path search suffix based on the version of VC + if(WINDOWS_STORE) + set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11_ui") + elseif(MSVC14) + set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc14") + elseif(MSVC12) + set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc12") + elseif(MSVC11) + set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11") + elseif(MSVC10) + set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc10") + endif() + + # Add the library path search suffix for the VC independent version of TBB + list(APPEND TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc_mt") + + string(REPLACE "lib/" "bin/" TBB_DLL_PATH_SUFFIX "${TBB_LIB_PATH_SUFFIX}") + + elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + # OS X + set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb") + + # TODO: Check to see which C++ library is being used by the compiler. + if(NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 13.0) + # The default C++ library on OS X 10.9 and later is libc++ + set(TBB_LIB_PATH_SUFFIX "lib/libc++" "lib") + else() + set(TBB_LIB_PATH_SUFFIX "lib") + endif() + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + # Linux + set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb") + + # TODO: Check compiler version to see the suffix should be /gcc4.1 or + # /gcc4.1. For now, assume that the compiler is more recent than + # gcc 4.4.x or later. + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(TBB_LIB_PATH_SUFFIX "lib/intel64/gcc4.4") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$") + set(TBB_LIB_PATH_SUFFIX "lib/ia32/gcc4.4") + endif() + endif() + + ################################## + # Find the TBB include dir + ################################## + + find_path(TBB_INCLUDE_DIRS tbb/tbb.h + HINTS ${TBB_INCLUDE_DIR} ${TBB_SEARCH_DIR} + PATHS ${TBB_DEFAULT_SEARCH_DIR} + PATH_SUFFIXES include) + + ################################## + # Set version strings + ################################## + + if(TBB_INCLUDE_DIRS) + file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file) + string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" + TBB_VERSION_MAJOR "${_tbb_version_file}") + string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" + TBB_VERSION_MINOR "${_tbb_version_file}") + string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" + TBB_INTERFACE_VERSION "${_tbb_version_file}") + set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}") + endif() + + ################################## + # Find TBB components + ################################## + + if(TBB_VERSION VERSION_LESS 4.3) + set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc tbb) + else() + set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc_proxy tbbmalloc tbb) + endif() + + # Find each component + foreach(_comp ${TBB_SEARCH_COMPOMPONENTS}) + if(";${TBB_FIND_COMPONENTS};tbb;" MATCHES ";${_comp};") + + # Search for the libraries + find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp} + HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} + PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH + PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX}) + + find_library(TBB_${_comp}_LIBRARY_DEBUG ${_comp}_debug + HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} + PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH + PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX}) + + # Search for the DLLs (Windows-only) + find_file(TBB_${_comp}_DLL_RELEASE ${_comp}.dll + HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} + PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH + PATH_SUFFIXES ${TBB_BIN_PATH_SUFFIX}) + + find_file(TBB_${_comp}_DLL_DEBUG ${_comp}_debug.dll + HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} + PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH + PATH_SUFFIXES ${TBB_BIN_PATH_SUFFIX}) + + if(TBB_${_comp}_LIBRARY_DEBUG) + list(APPEND TBB_LIBRARIES_DEBUG "${TBB_${_comp}_LIBRARY_DEBUG}") + list(APPEND TBB_DLLs_DEBUG "${TBB_${_comp}_DLL_DEBUG}") + endif() + if(TBB_${_comp}_LIBRARY_RELEASE) + list(APPEND TBB_LIBRARIES_RELEASE "${TBB_${_comp}_LIBRARY_RELEASE}") + list(APPEND TBB_DLLs_RELEASE "${TBB_${_comp}_DLL_RELEASE}") + endif() + if(TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE} AND NOT TBB_${_comp}_LIBRARY) + set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}}") + set(TBB_${_comp}_DLL "${TBB_${_comp}_DLL_${TBB_BUILD_TYPE}}") + endif() + + if(TBB_${_comp}_LIBRARY AND EXISTS "${TBB_${_comp}_LIBRARY}") + set(TBB_${_comp}_FOUND TRUE) + else() + set(TBB_${_comp}_FOUND FALSE) + endif() + + # Mark internal variables as advanced + mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE) + mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG) + mark_as_advanced(TBB_${_comp}_LIBRARY) + mark_as_advanced(TBB_${_comp}_DLL_RELEASE) + mark_as_advanced(TBB_${_comp}_DLL_DEBUG) + mark_as_advanced(TBB_${_comp}_DLL) + + endif() + endforeach() + + ################################## + # Set compile flags and libraries + ################################## + + set(TBB_DEFINITIONS_RELEASE "") + set(TBB_DEFINITIONS_DEBUG "-DTBB_USE_DEBUG=1") + + if(TBB_LIBRARIES_${TBB_BUILD_TYPE}) + set(TBB_DEFINITIONS "${TBB_DEFINITIONS_${TBB_BUILD_TYPE}}") + set(TBB_LIBRARIES "${TBB_LIBRARIES_${TBB_BUILD_TYPE}}") + set(TBB_DLLs "${TBB_DLLs_${TBB_BUILD_TYPE}}") + elseif(TBB_LIBRARIES_RELEASE) + set(TBB_DEFINITIONS "${TBB_DEFINITIONS_RELEASE}") + set(TBB_LIBRARIES "${TBB_LIBRARIES_RELEASE}") + set(TBB_DLLs "${TBB_DLLs_RELEASE}") + elseif(TBB_LIBRARIES_DEBUG) + set(TBB_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}") + set(TBB_LIBRARIES "${TBB_LIBRARIES_DEBUG}") + set(TBB_DLLs "${TBB_DLLs_DEBUG}") + endif() + + find_package_handle_standard_args(TBB + REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES + HANDLE_COMPONENTS + VERSION_VAR TBB_VERSION) + + ################################## + # Create targets + ################################## + + if(NOT CMAKE_VERSION VERSION_LESS 3.0 AND TBB_FOUND) + add_library(TBB::TBB SHARED IMPORTED) + if(WIN32) + set_target_properties(TBB::TBB PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS} + IMPORTED_LOCATION ${TBB_DLLs} + IMPORTED_IMPLIB ${TBB_LIBRARIES}) + if(TBB_LIBRARIES_RELEASE AND TBB_LIBRARIES_DEBUG) + set_target_properties(TBB::TBB PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "$<$,$>:TBB_USE_DEBUG=1>" + IMPORTED_LOCATION_DEBUG ${TBB_DLLs_DEBUG} + IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_DLLs_DEBUG} + IMPORTED_LOCATION_RELEASE ${TBB_DLLs_RELEASE} + IMPORTED_LOCATION_MINSIZEREL ${TBB_DLLs_RELEASE} + IMPORTED_IMPLIB_DEBUG ${TBB_LIBRARIES_DEBUG} + IMPORTED_IMPLIB_RELWITHDEBINFO ${TBB_LIBRARIES_DEBUG} + IMPORTED_IMPLIB_RELEASE ${TBB_LIBRARIES_RELEASE} + IMPORTED_IMPLIB_MINSIZEREL ${TBB_LIBRARIES_RELEASE} + ) + elseif(TBB_LIBRARIES_RELEASE) + set_target_properties(TBB::TBB PROPERTIES IMPORTED_LOCATION ${TBB_DLLs_RELEASE} IMPORTED_IMPLIB ${TBB_LIBRARIES_RELEASE}) + else() + set_target_properties(TBB::TBB PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}" + IMPORTED_LOCATION ${TBB_DLLs_DEBUG} + IMPORTED_IMPLIB ${TBB_LIBRARIES_DEBUG} + ) + endif() + else() + set_target_properties(TBB::TBB PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS} + IMPORTED_LOCATION ${TBB_LIBRARIES}) + if(TBB_LIBRARIES_RELEASE AND TBB_LIBRARIES_DEBUG) + set_target_properties(TBB::TBB PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "$<$,$>:TBB_USE_DEBUG=1>" + IMPORTED_LOCATION_DEBUG ${TBB_LIBRARIES_DEBUG} + IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_LIBRARIES_DEBUG} + IMPORTED_LOCATION_RELEASE ${TBB_LIBRARIES_RELEASE} + IMPORTED_LOCATION_MINSIZEREL ${TBB_LIBRARIES_RELEASE} + ) + elseif(TBB_LIBRARIES_RELEASE) + set_target_properties(TBB::TBB PROPERTIES IMPORTED_LOCATION ${TBB_LIBRARIES_RELEASE}) + else() + set_target_properties(TBB::TBB PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}" + IMPORTED_LOCATION ${TBB_LIBRARIES_DEBUG} + ) + endif() + endif() + endif() + + mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES TBB_DLLs) + + unset(TBB_ARCHITECTURE) + unset(TBB_BUILD_TYPE) + unset(TBB_LIB_PATH_SUFFIX) + unset(TBB_DEFAULT_SEARCH_DIR) + +endif() diff --git a/cmake/find_cmake.bat b/cmake/find_cmake.bat new file mode 100644 index 000000000..90e845da2 --- /dev/null +++ b/cmake/find_cmake.bat @@ -0,0 +1,58 @@ +@echo off +rem Locates CMake and updates path variable. Sets generator_string and generator_string_x86. +rem Set MSVS_LOCATION used to locate correct version of VS when building VS solutions +rem Avoids updating path if correct CMake version is already on path. +rem Prefer cmake version 3.14.5 identified by the environment variable CMAKE_3_14_5. +rem This is particularly important on builds servers. +rem If CMAKE_3_14_5 is unset, use what is on path or what is installed in standard locations. + +if not defined CMAKE_3_14_5 ( + goto use_heuristics_to_locate_cmake +) + +rem Check if any cmake version is already on path. +where cmake +if %ERRORLEVEL% equ 1 ( + rem No cmake found on path, add it + goto add_cmake_to_path +) +rem At least one cmake version found. Check if the first occurrence is equivalent to CMAKE_3_14_5. +for /f "delims=" %%A in ('where cmake') DO ( + set FIRST_CMAKE_ON_PATH=%%A + goto :exit_loop_on_first_occurence +) +:exit_loop_on_first_occurence +if "%CMAKE_3_14_5%\cmake.exe" == "%FIRST_CMAKE_ON_PATH%" ( + rem CMAKE_3_14_5 is already on path. + goto callcmake +) +:add_cmake_to_path +rem Add CMAKE_3_14_5 to path as first version to hide any other versions. +set "PATH=%CMAKE_3_14_5%;%PATH%" +goto callcmake + +:use_heuristics_to_locate_cmake +rem If CMake is on path use this version +where cmake +if %ERRORLEVEL% equ 0 ( + goto callcmake +) + +rem Attempt to locate CMake at the standard installed locations +set "PATH=C:\Program Files\CMake\bin;C:\Program Files (x86)\CMake\bin;%PATH%" + +:callcmake +rem Output cmake version used +cmake --version + +rem Specify Visual Studio version. Use this variable to make it easier to change Visual Studio version +set generator_string="Visual Studio 15 2017 Win64" + +rem Specify Visual Studio version. Use this variable to make it easier to change Visual Studio version +set generator_string_x86="Visual Studio 15 2017" + +rem Ensure MSVS_LOCATION is set for solutions where we don't use CMake +if defined MSVS_LOCATION goto done +set MSVS_LOCATION=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\ +if not exist "%MSVS_LOCATION%" set MSVS_LOCATION=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\ +:done diff --git a/cmake/functions.cmake b/cmake/functions.cmake new file mode 100644 index 000000000..879b16b43 --- /dev/null +++ b/cmake/functions.cmake @@ -0,0 +1,38 @@ +function(copy_files target_name files_to_copy output_dir) + add_custom_command(TARGET ${target_name} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory ${output_dir} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${${files_to_copy}} + ${output_dir} + VERBATIM + ) +endfunction(copy_files) + +function(copy_directory target_name dir_to_copy output_dir) + add_custom_command(TARGET ${target_name} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${dir_to_copy} + ${output_dir} + VERBATIM + ) +endfunction(copy_directory) + +function(disable_specific_warnings target_name) + set(specific_warnings "") + foreach(specific_warning ${ARGN}) + set(specific_warnings "${specific_warnings} -wd${specific_warning}") + endforeach() + set_target_properties(${target_name} + PROPERTIES COMPILE_FLAGS ${specific_warnings} + ) +endfunction(disable_specific_warnings) + +function(set_headers_prefix prefix header_list) + set(HEADERS) + foreach(HEADER ${${header_list}}) + set(HEADERS ${HEADERS} ${prefix}/${HEADER}) + endforeach(HEADER) + set(HEADERS ${HEADERS} PARENT_SCOPE) +endfunction(set_headers_prefix) \ No newline at end of file diff --git a/cmake/utility.cmake b/cmake/utility.cmake new file mode 100644 index 000000000..40e3bb1e8 --- /dev/null +++ b/cmake/utility.cmake @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.0.0) +cmake_policy(SET CMP0022 NEW) # INTERFACE_LINK_LIBRARIES defines the link interface + +# \desc Assigns source groups to files in argument based on paths +# - Example: assign_source_group("f1/a.h" "f1/f2/b.h") will place a.h under an f1 folder and b.h under an f2 folder inside f1 +# \param : The files to assign source groups to +function(assign_source_group) + foreach(_source IN ITEMS ${ARGN}) + if (IS_ABSOLUTE "${_source}") + file(RELATIVE_PATH _source_rel "${CMAKE_CURRENT_BINARY_DIR}" "${_source}") + if(IS_ABSOLUTE "${_source}") + else() + file(RELATIVE_PATH _source_rel "${CMAKE_CURRENT_SOURCE_DIR}" "${_source}") + endif() + else() + set(_source_rel "${_source}") + endif() + get_filename_component(_source_path "${_source_rel}" PATH) + string(REPLACE "/" "\\" _source_path_msvc "${_source_path}") + source_group("${_source_path_msvc}" FILES "${_source}") + endforeach() +endfunction(assign_source_group) + +function(target_assign_source_group target) + get_target_property(TARGET_SOURCES ${target} SOURCES) + assign_source_group(${TARGET_SOURCES}) +endfunction(target_assign_source_group) + +function(init_project target_out target_name) + set(${target_out} ${target_name} PARENT_SCOPE) + # Common configuration goes here +endfunction() diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 1039c302a..abf78df55 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,91 +1,143 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.10) - -project (corecvs) - -set (CORE_SUBMODULES - alignment - assignment - automotive - boosting - buffers - cammodel - fileformats - filesystem - framesources - filters - function - geometry - kalman - kltflow - math - meta - meanshift - rectification - reflection - segmentation - stats - tbbwrapper - utils - clustering3d - patterndetection - cameracalibration - polynomial - camerafixture - iterative - stereointerface - tinyxml2 - xml/generated - ) - -set ( ADDITIONAL_MODULES - # placer - delaunay - joystick - ) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME corecvs) +init_project(PROJECT_NAME ${MODULE_NAME}) message(STATUS "Core will use ${CORE_SUBMODULES} and ${ADDITIONAL_MODULES}") -add_library(corecvs STATIC) - -set_property(TARGET corecvs PROPERTY CXX_STANDARD 17) -set_property(TARGET corecvs PROPERTY CXX_STANDARD_REQUIRED ON) - -target_include_directories(corecvs PUBLIC ..) - -target_link_libraries(corecvs pthread) - -if (OpenBLAS_LIB) - message("Core: Would use OpenBLAS adding <${OpenBLAS_LIB}> to dependancies") - message("Core: Would use Lapacke adding <${Lapacke_LIB}> to dependancies") - target_include_directories(corecvs PUBLIC ${OpenBLAS_INCLUDE_DIR} ${Lapacke_INCLUDE_DIR}) - target_link_libraries(corecvs ${OpenBLAS_LIB} ${Lapacke_LIB}) -endif() +set(CORE_SUBMODULES + alignment + assignment + automotive + boosting + buffers + cameracalibration + camerafixture + cammodel + clustering3d + fileformats + filesystem + filters + framesources + function + geometry + iterative + kalman + kltflow + math + meanshift + meta + patterndetection + polynomial + rectification + reflection + segmentation + stats + stereointerface + tbbwrapper + tinyxml2 + utils + xml/generated + ) -if (TBB_LIBRARY) - message("Core: Would use TBB") - include_directories (${TBB_INCLUDE_DIR}) - target_link_libraries(corecvs ${TBB_LIBRARY}) -endif() +set(ADDITIONAL_MODULES + #placer + delaunay + joystick + ) foreach(core_module ${CORE_SUBMODULES}) message(STATUS "including ${core_module}") add_subdirectory(${core_module}) + string(TOUPPER ${core_module} core_module) + set(HEADERS + ${HEADERS} + ${${core_module}_HEADER_FILES} + ) + set(SOURCES + ${SOURCES} + ${${core_module}_SOURCE_FILES} + ) endforeach(core_module) foreach(add_core_module ${ADDITIONAL_MODULES}) message(STATUS "including ${add_core_module}") add_subdirectory(${add_core_module}) + string(TOUPPER ${add_core_module} add_core_module) + set(HEADERS + ${HEADERS} + ${${add_core_module}_HEADER_FILES} + ) + set(SOURCES + ${SOURCES} + ${${add_core_module}_SOURCE_FILES} + ) endforeach(add_core_module) +set(XML_RESOURCE_FILES + xml/basemock.xml + xml/clustering1.xml + xml/precise.xml + xml/bufferFilters.xml + xml/distortion.xml + xml/parameters.xml + xml/projections.xml + xml/calibration.xml + xml/filterBlock.xml + xml/patternDetector.xml + xml/stereoAlign.xml + ) + +set(RESOURCES + ${XML_RESOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/../.github/workflows/ccpp.yaml + ${CMAKE_CURRENT_LIST_DIR}/../.github/workflows/ubuntu_no_opencv.yml + ) + +set_source_files_properties(${RESOURCES} + PROPERTIES + EXTERNAL_OBJECT TRUE + HEADER_FILE_ONLY TRUE + ) + +assign_source_group(${HEADERS} ${SOURCES} ${RESOURCES}) + +add_library(${PROJECT_NAME} STATIC + ${HEADERS} + ${SOURCES} + ${RESOURCES} + ) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + .. + ) -# Additional stuff mostly for IDE only +set(ADDITIONAL_LIBS) -file(GLOB CUR_ADD_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/xml/*.xml) -set(ADD_SRC_FILES ${ADD_SRC_FILES} ${CUR_ADD_SRC_FILES}) +if(OpenBLAS_LIB) + message("Core: Would use OpenBLAS adding <${OpenBLAS_LIB}> to dependancies") + message("Core: Would use Lapacke adding <${Lapacke_LIB}> to dependancies") + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + OPENBLAS::OPENBLAS + LAPACKE::LAPACKE + ) +endif() -file(GLOB ADD_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/../.github/workflows/*.*) -set(ADD_SRC_FILES ${ADD_SRC_FILES} ${CUR_ADD_SRC_FILES}) +if(TBB_LIBRARY) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + TBB::TBB + ) +endif() -target_sources(corecvs PRIVATE ${ADD_SRC_FILES}) -set_source_files_properties(${ADD_SRC_FILES} PROPERTIES EXTERNAL_OBJECT true HEADER_FILE_ONLY TRUE) +target_link_libraries(${PROJECT_NAME} + pthread + ${ADDITIONAL_LIBS} + ) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/core/alignment/CMakeLists.txt b/core/alignment/CMakeLists.txt index 46d221fe1..a9ee6a585 100644 --- a/core/alignment/CMakeLists.txt +++ b/core/alignment/CMakeLists.txt @@ -1,33 +1,31 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/radialCorrection.h - ${CMAKE_CURRENT_LIST_DIR}/distortionCorrectTransform.h - ${CMAKE_CURRENT_LIST_DIR}/camerasCalibration/camerasCalibrationFunc.h - ${CMAKE_CURRENT_LIST_DIR}/radialFunc.h - ${CMAKE_CURRENT_LIST_DIR}/curvatureFunc.h - ${CMAKE_CURRENT_LIST_DIR}/angleFunction.h - ${CMAKE_CURRENT_LIST_DIR}/anglePointsFunction.h - ${CMAKE_CURRENT_LIST_DIR}/distPointsFunction.h - ${CMAKE_CURRENT_LIST_DIR}/selectableGeometryFeatures.h - ${CMAKE_CURRENT_LIST_DIR}/lmDistortionSolver.h - ${CMAKE_CURRENT_LIST_DIR}/lensDistortionModelParameters.h - ${CMAKE_CURRENT_LIST_DIR}/pointObservation.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/radialCorrection.cpp - ${CMAKE_CURRENT_LIST_DIR}/camerasCalibration/camerasCalibrationFunc.cpp - ${CMAKE_CURRENT_LIST_DIR}/radialFunc.cpp - ${CMAKE_CURRENT_LIST_DIR}/curvatureFunc.cpp - ${CMAKE_CURRENT_LIST_DIR}/angleFunction.cpp - ${CMAKE_CURRENT_LIST_DIR}/anglePointsFunction.cpp - ${CMAKE_CURRENT_LIST_DIR}/distPointsFunction.cpp - ${CMAKE_CURRENT_LIST_DIR}/selectableGeometryFeatures.cpp - ${CMAKE_CURRENT_LIST_DIR}/lmDistortionSolver.cpp - ${CMAKE_CURRENT_LIST_DIR}/lensDistortionModelParameters.cpp - ${CMAKE_CURRENT_LIST_DIR}/pointObservation.cpp -) -target_include_directories(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR} -) +set(ALIGNMENT_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/radialCorrection.h + ${CMAKE_CURRENT_LIST_DIR}/distortionCorrectTransform.h + ${CMAKE_CURRENT_LIST_DIR}/camerasCalibration/camerasCalibrationFunc.h + ${CMAKE_CURRENT_LIST_DIR}/radialFunc.h + ${CMAKE_CURRENT_LIST_DIR}/curvatureFunc.h + ${CMAKE_CURRENT_LIST_DIR}/angleFunction.h + ${CMAKE_CURRENT_LIST_DIR}/anglePointsFunction.h + ${CMAKE_CURRENT_LIST_DIR}/distPointsFunction.h + ${CMAKE_CURRENT_LIST_DIR}/selectableGeometryFeatures.h + ${CMAKE_CURRENT_LIST_DIR}/lmDistortionSolver.h + ${CMAKE_CURRENT_LIST_DIR}/lensDistortionModelParameters.h + ${CMAKE_CURRENT_LIST_DIR}/pointObservation.h + ) +set(ALIGNMENT_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/radialCorrection.cpp + ${CMAKE_CURRENT_LIST_DIR}/camerasCalibration/camerasCalibrationFunc.cpp + ${CMAKE_CURRENT_LIST_DIR}/radialFunc.cpp + ${CMAKE_CURRENT_LIST_DIR}/curvatureFunc.cpp + ${CMAKE_CURRENT_LIST_DIR}/angleFunction.cpp + ${CMAKE_CURRENT_LIST_DIR}/anglePointsFunction.cpp + ${CMAKE_CURRENT_LIST_DIR}/distPointsFunction.cpp + ${CMAKE_CURRENT_LIST_DIR}/selectableGeometryFeatures.cpp + ${CMAKE_CURRENT_LIST_DIR}/lmDistortionSolver.cpp + ${CMAKE_CURRENT_LIST_DIR}/lensDistortionModelParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/pointObservation.cpp + ) +set(ALIGNMENT_HEADER_FILES ${ALIGNMENT_HEADER_FILES} PARENT_SCOPE) +set(ALIGNMENT_SOURCE_FILES ${ALIGNMENT_SOURCE_FILES} PARENT_SCOPE) \ No newline at end of file diff --git a/core/alignment/angleFunction.cpp b/core/alignment/angleFunction.cpp index eca227f60..9decd5342 100644 --- a/core/alignment/angleFunction.cpp +++ b/core/alignment/angleFunction.cpp @@ -1,5 +1,5 @@ -#include "core/alignment/angleFunction.h" -#include "core/alignment/radialFunc.h" +#include "alignment/angleFunction.h" +#include "alignment/radialFunc.h" namespace corecvs { diff --git a/core/alignment/angleFunction.h b/core/alignment/angleFunction.h index 0a53dd8e8..674d2badb 100644 --- a/core/alignment/angleFunction.h +++ b/core/alignment/angleFunction.h @@ -1,5 +1,5 @@ #pragma once -#include "core/function/function.h" +#include "function/function.h" /** * \file angleFunction.h diff --git a/core/alignment/anglePointsFunction.cpp b/core/alignment/anglePointsFunction.cpp index 0eb3c9751..0a1b8bee9 100644 --- a/core/alignment/anglePointsFunction.cpp +++ b/core/alignment/anglePointsFunction.cpp @@ -1,4 +1,4 @@ -#include "core/alignment/anglePointsFunction.h" +#include "alignment/anglePointsFunction.h" namespace corecvs { diff --git a/core/alignment/anglePointsFunction.h b/core/alignment/anglePointsFunction.h index 1c22bf518..57d1e07c9 100644 --- a/core/alignment/anglePointsFunction.h +++ b/core/alignment/anglePointsFunction.h @@ -1,5 +1,5 @@ #pragma once -#include "core/alignment/radialFunc.h" +#include "alignment/radialFunc.h" namespace corecvs { diff --git a/core/alignment/camerasCalibration/camerasCalibrationFunc.cpp b/core/alignment/camerasCalibration/camerasCalibrationFunc.cpp index c5d7e997e..b4f8a2a0b 100644 --- a/core/alignment/camerasCalibration/camerasCalibrationFunc.cpp +++ b/core/alignment/camerasCalibration/camerasCalibrationFunc.cpp @@ -1,4 +1,4 @@ -#include "core/alignment/camerasCalibration/camerasCalibrationFunc.h" +#include "alignment/camerasCalibration/camerasCalibrationFunc.h" namespace corecvs { diff --git a/core/alignment/camerasCalibration/camerasCalibrationFunc.h b/core/alignment/camerasCalibration/camerasCalibrationFunc.h index aceb68f0e..d4aedc0d8 100644 --- a/core/alignment/camerasCalibration/camerasCalibrationFunc.h +++ b/core/alignment/camerasCalibration/camerasCalibrationFunc.h @@ -1,5 +1,5 @@ #pragma once -#include "core/function/function.h" +#include "function/function.h" namespace corecvs { diff --git a/core/alignment/curvatureFunc.cpp b/core/alignment/curvatureFunc.cpp index 6e4ffb90c..7b7844582 100644 --- a/core/alignment/curvatureFunc.cpp +++ b/core/alignment/curvatureFunc.cpp @@ -1,5 +1,5 @@ -#include "core/alignment/curvatureFunc.h" -#include "core/alignment/radialFunc.h" +#include "alignment/curvatureFunc.h" +#include "alignment/radialFunc.h" namespace corecvs { diff --git a/core/alignment/curvatureFunc.h b/core/alignment/curvatureFunc.h index 2d2d95eb4..099ae62fe 100644 --- a/core/alignment/curvatureFunc.h +++ b/core/alignment/curvatureFunc.h @@ -1,5 +1,5 @@ #pragma once -#include "core/function/function.h" +#include "function/function.h" namespace corecvs { diff --git a/core/alignment/distPointsFunction.cpp b/core/alignment/distPointsFunction.cpp index ba20b1dd1..8eb79674c 100644 --- a/core/alignment/distPointsFunction.cpp +++ b/core/alignment/distPointsFunction.cpp @@ -4,7 +4,7 @@ * \date Jun 11, 2013 **/ -#include "core/alignment/distPointsFunction.h" +#include "alignment/distPointsFunction.h" #include "../geometry/ellipticalApproximation.h" namespace corecvs diff --git a/core/alignment/distPointsFunction.h b/core/alignment/distPointsFunction.h index 12e8bca92..da148fa67 100644 --- a/core/alignment/distPointsFunction.h +++ b/core/alignment/distPointsFunction.h @@ -6,8 +6,8 @@ * \date Jun 11, 2013 **/ -#include "core/alignment/radialFunc.h" -#include "core/math/vector/vector2d.h" +#include "alignment/radialFunc.h" +#include "math/vector/vector2d.h" namespace corecvs { diff --git a/core/alignment/distortionCorrectTransform.h b/core/alignment/distortionCorrectTransform.h index 494e2f303..bed379565 100644 --- a/core/alignment/distortionCorrectTransform.h +++ b/core/alignment/distortionCorrectTransform.h @@ -1,5 +1,5 @@ #pragma once -#include "core/buffers/abstractBuffer.h" +#include "buffers/abstractBuffer.h" namespace corecvs { diff --git a/core/alignment/lensDistortionModelParameters.cpp b/core/alignment/lensDistortionModelParameters.cpp index c2ce9890c..7b37a5fbf 100644 --- a/core/alignment/lensDistortionModelParameters.cpp +++ b/core/alignment/lensDistortionModelParameters.cpp @@ -8,8 +8,8 @@ #include #include -#include "core/alignment/lensDistortionModelParameters.h" -#include "core/polynomial/polynomialSolver.h" +#include "alignment/lensDistortionModelParameters.h" +#include "polynomial/polynomialSolver.h" /** * Looks extremely unsafe because it depends on the order of static initialization. diff --git a/core/alignment/lensDistortionModelParameters.h b/core/alignment/lensDistortionModelParameters.h index 4b0c666d8..38d905173 100644 --- a/core/alignment/lensDistortionModelParameters.h +++ b/core/alignment/lensDistortionModelParameters.h @@ -8,13 +8,13 @@ * \author autoGenerator */ -#include "core/xml/generated/lensDistortionModelParametersBase.h" -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" -#include "core/math/levenmarq.h" -#include "core/math/matrix/matrix22.h" -//#include "core/polynomial/polynomialSolver.h" // including this dues to a compilation error with msvc2013/2015, see details at the polynomial.h +#include "xml/generated/lensDistortionModelParametersBase.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" +#include "math/levenmarq.h" +#include "math/matrix/matrix22.h" +//#include "polynomial/polynomialSolver.h" // including this dues to a compilation error with msvc2013/2015, see details at the polynomial.h /* * Embed includes. diff --git a/core/alignment/lmDistortionSolver.cpp b/core/alignment/lmDistortionSolver.cpp index 6a2ef18d4..5b62cef4c 100644 --- a/core/alignment/lmDistortionSolver.cpp +++ b/core/alignment/lmDistortionSolver.cpp @@ -1,9 +1,9 @@ -#include "core/alignment/lmDistortionSolver.h" +#include "alignment/lmDistortionSolver.h" #include "camerasCalibration/camerasCalibrationFunc.h" -#include "core/math/levenmarq.h" -#include "core/utils/log.h" -#include "core/alignment/anglePointsFunction.h" -#include "core/alignment/distPointsFunction.h" +#include "math/levenmarq.h" +#include "utils/log.h" +#include "alignment/anglePointsFunction.h" +#include "alignment/distPointsFunction.h" namespace corecvs { diff --git a/core/alignment/lmDistortionSolver.h b/core/alignment/lmDistortionSolver.h index d2696ff98..aa84e4bc9 100644 --- a/core/alignment/lmDistortionSolver.h +++ b/core/alignment/lmDistortionSolver.h @@ -1,10 +1,10 @@ #ifndef LMDISTORTIONSOLVER_H #define LMDISTORTIONSOLVER_H -#include "core/alignment/radialCorrection.h" -#include "core/alignment/selectableGeometryFeatures.h" -#include "core/xml/generated/lineDistortionEstimatorParameters.h" -#include "core/geometry/ellipticalApproximation.h" +#include "alignment/radialCorrection.h" +#include "alignment/selectableGeometryFeatures.h" +#include "xml/generated/lineDistortionEstimatorParameters.h" +#include "geometry/ellipticalApproximation.h" namespace corecvs { diff --git a/core/alignment/pointObservation.cpp b/core/alignment/pointObservation.cpp index 61ffb66b1..de76e57a9 100644 --- a/core/alignment/pointObservation.cpp +++ b/core/alignment/pointObservation.cpp @@ -1,2 +1,2 @@ -#include "core/alignment/pointObservation.h" +#include "alignment/pointObservation.h" diff --git a/core/alignment/pointObservation.h b/core/alignment/pointObservation.h index 5099ac73f..971653845 100644 --- a/core/alignment/pointObservation.h +++ b/core/alignment/pointObservation.h @@ -1,8 +1,8 @@ #ifndef POINTOBSERVATION_H #define POINTOBSERVATION_H -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" namespace corecvs { diff --git a/core/alignment/radialCorrection.cpp b/core/alignment/radialCorrection.cpp index 71d4c6e04..7068fef34 100644 --- a/core/alignment/radialCorrection.cpp +++ b/core/alignment/radialCorrection.cpp @@ -7,11 +7,11 @@ * \author alexander */ -#include "core/utils/global.h" -#include "core/alignment/radialCorrection.h" -#include "core/math/levenmarq.h" -#include "core/geometry/ellipticalApproximation.h" -#include "core/buffers/displacementBuffer.h" +#include "utils/global.h" +#include "alignment/radialCorrection.h" +#include "math/levenmarq.h" +#include "geometry/ellipticalApproximation.h" +#include "buffers/displacementBuffer.h" namespace corecvs { diff --git a/core/alignment/radialCorrection.h b/core/alignment/radialCorrection.h index 5b5f86b92..8397bb809 100644 --- a/core/alignment/radialCorrection.h +++ b/core/alignment/radialCorrection.h @@ -11,14 +11,14 @@ * \author alexander */ -#include "core/geometry/ellipticalApproximation.h" -#include "core/alignment/lensDistortionModelParameters.h" -#include "core/utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/function/function.h" -#include "core/math/levenmarq.h" +#include "geometry/ellipticalApproximation.h" +#include "alignment/lensDistortionModelParameters.h" +#include "utils/global.h" +#include "math/vector/vector2d.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "function/function.h" +#include "math/levenmarq.h" namespace corecvs { diff --git a/core/alignment/radialFunc.cpp b/core/alignment/radialFunc.cpp index a6dae0893..9fd5c4198 100644 --- a/core/alignment/radialFunc.cpp +++ b/core/alignment/radialFunc.cpp @@ -1,5 +1,5 @@ -#include "core/alignment/radialFunc.h" -#include "core/alignment/radialCorrection.h" +#include "alignment/radialFunc.h" +#include "alignment/radialCorrection.h" namespace corecvs { diff --git a/core/alignment/radialFunc.h b/core/alignment/radialFunc.h index 31c54743f..fb7ad37ca 100644 --- a/core/alignment/radialFunc.h +++ b/core/alignment/radialFunc.h @@ -1,6 +1,6 @@ #pragma once -#include "core/function/function.h" -#include "core/alignment/radialCorrection.h" +#include "function/function.h" +#include "alignment/radialCorrection.h" namespace corecvs { diff --git a/core/alignment/selectableGeometryFeatures.cpp b/core/alignment/selectableGeometryFeatures.cpp index a81c2a07d..90e9ec2dd 100644 --- a/core/alignment/selectableGeometryFeatures.cpp +++ b/core/alignment/selectableGeometryFeatures.cpp @@ -1,6 +1,6 @@ #include -#include "core/alignment/selectableGeometryFeatures.h" +#include "alignment/selectableGeometryFeatures.h" namespace corecvs { diff --git a/core/alignment/selectableGeometryFeatures.h b/core/alignment/selectableGeometryFeatures.h index a7127a8f8..28af0a561 100644 --- a/core/alignment/selectableGeometryFeatures.h +++ b/core/alignment/selectableGeometryFeatures.h @@ -3,8 +3,8 @@ #include #include #include -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/alignment/pointObservation.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "alignment/pointObservation.h" namespace corecvs { diff --git a/core/assignment/CMakeLists.txt b/core/assignment/CMakeLists.txt index 03a255ba8..bc36ca44f 100644 --- a/core/assignment/CMakeLists.txt +++ b/core/assignment/CMakeLists.txt @@ -1,7 +1,9 @@ -target_sources(corecvs - PUBLIC +set(ASSIGNMENT_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/assignmentOptimal.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/assignmentOptimal.cpp -) + PARENT_SCOPE + ) +set(ASSIGNMENT_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/assignmentOptimal.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/assignment/assignmentOptimal.cpp b/core/assignment/assignmentOptimal.cpp index ef0c45edf..d3feb398a 100644 --- a/core/assignment/assignmentOptimal.cpp +++ b/core/assignment/assignmentOptimal.cpp @@ -13,9 +13,9 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/assignment/assignmentOptimal.h" +#include "assignment/assignmentOptimal.h" namespace corecvs { /** diff --git a/core/assignment/assignmentOptimal.h b/core/assignment/assignmentOptimal.h index 70e0aa272..862f201df 100644 --- a/core/assignment/assignmentOptimal.h +++ b/core/assignment/assignmentOptimal.h @@ -10,9 +10,9 @@ */ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractBuffer.h" +#include "buffers/abstractBuffer.h" namespace corecvs { diff --git a/core/automotive/CMakeLists.txt b/core/automotive/CMakeLists.txt index 4fb7426ad..ec39af983 100644 --- a/core/automotive/CMakeLists.txt +++ b/core/automotive/CMakeLists.txt @@ -1,11 +1,13 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/FCostFunction.h - ${CMAKE_CURRENT_LIST_DIR}/flowVectorInformation.h - ${CMAKE_CURRENT_LIST_DIR}/simulation/testSceneSimulator.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/FCostFunction.cpp - ${CMAKE_CURRENT_LIST_DIR}/flowVectorInformation.cpp - ${CMAKE_CURRENT_LIST_DIR}/simulation/testSceneSimulator.cpp -) +set(AUTOMOTIVE_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/FCostFunction.h + ${CMAKE_CURRENT_LIST_DIR}/flowVectorInformation.h + ${CMAKE_CURRENT_LIST_DIR}/simulation/testSceneSimulator.h + PARENT_SCOPE + ) +set(AUTOMOTIVE_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/FCostFunction.cpp + ${CMAKE_CURRENT_LIST_DIR}/flowVectorInformation.cpp + ${CMAKE_CURRENT_LIST_DIR}/simulation/testSceneSimulator.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/automotive/FCostFunction.cpp b/core/automotive/FCostFunction.cpp index 1d1c5ff50..6d4440f56 100644 --- a/core/automotive/FCostFunction.cpp +++ b/core/automotive/FCostFunction.cpp @@ -217,10 +217,10 @@ **/ -#include "core/cameracalibration/cameraModel.h" -#include "core/automotive/FCostFunction.h" -#include "core/math/matrix/matrix44.h" -#include "core/math/eulerAngles.h" +#include "cameracalibration/cameraModel.h" +#include "automotive/FCostFunction.h" +#include "math/matrix/matrix44.h" +#include "math/eulerAngles.h" namespace corecvs { diff --git a/core/automotive/FCostFunction.h b/core/automotive/FCostFunction.h index 747cb8931..1fcb9ec86 100644 --- a/core/automotive/FCostFunction.h +++ b/core/automotive/FCostFunction.h @@ -12,11 +12,11 @@ */ -#include "core/cameracalibration/cameraModel.h" -#include "core/math/matrix/matrix44.h" -#include "core/cammodel/cameraParameters.h" -#include "core/math/eulerAngles.h" -#include "core/buffers/flow/floatFlowBuffer.h" +#include "cameracalibration/cameraModel.h" +#include "math/matrix/matrix44.h" +#include "cammodel/cameraParameters.h" +#include "math/eulerAngles.h" +#include "buffers/flow/floatFlowBuffer.h" namespace corecvs { class FCostFunction diff --git a/core/automotive/flowVectorInformation.cpp b/core/automotive/flowVectorInformation.cpp index 3df9cf564..7f64f1df5 100644 --- a/core/automotive/flowVectorInformation.cpp +++ b/core/automotive/flowVectorInformation.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/automotive/flowVectorInformation.h" +#include "automotive/flowVectorInformation.h" namespace corecvs { const char *FlowVectorInformation::REASON_NAMES[] = diff --git a/core/automotive/flowVectorInformation.h b/core/automotive/flowVectorInformation.h index e319403f3..1465811d2 100644 --- a/core/automotive/flowVectorInformation.h +++ b/core/automotive/flowVectorInformation.h @@ -8,9 +8,9 @@ #ifndef FLOWVECTORINFORMATION_H_ #define FLOWVECTORINFORMATION_H_ -#include "core/buffers/flow/floatFlowBuffer.h" -#include "core/automotive/FCostFunction.h" -#include "core/math/vector/vector3d.h" +#include "buffers/flow/floatFlowBuffer.h" +#include "automotive/FCostFunction.h" +#include "math/vector/vector3d.h" namespace corecvs { class FlowVectorInformation diff --git a/core/automotive/simulation/testSceneSimulator.cpp b/core/automotive/simulation/testSceneSimulator.cpp index f95f29323..d924526de 100644 --- a/core/automotive/simulation/testSceneSimulator.cpp +++ b/core/automotive/simulation/testSceneSimulator.cpp @@ -7,8 +7,8 @@ * \author alexander */ -#include "core/automotive/simulation/testSceneSimulator.h" -#include "core/automotive/FCostFunction.h" +#include "automotive/simulation/testSceneSimulator.h" +#include "automotive/FCostFunction.h" namespace corecvs { TestSceneSimulator::TestSceneSimulator() diff --git a/core/automotive/simulation/testSceneSimulator.h b/core/automotive/simulation/testSceneSimulator.h index 66af7bd52..c67151676 100644 --- a/core/automotive/simulation/testSceneSimulator.h +++ b/core/automotive/simulation/testSceneSimulator.h @@ -12,13 +12,13 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector3d.h" -#include "core/math/matrix/matrix44.h" -#include "core/buffers/flow/flowVector.h" -#include "core/cameracalibration/cameraModel.h" -#include "core/math/eulerAngles.h" +#include "math/vector/vector3d.h" +#include "math/matrix/matrix44.h" +#include "buffers/flow/flowVector.h" +#include "cameracalibration/cameraModel.h" +#include "math/eulerAngles.h" namespace corecvs { diff --git a/core/boosting/CMakeLists.txt b/core/boosting/CMakeLists.txt index 2c046c640..72a80a8e4 100644 --- a/core/boosting/CMakeLists.txt +++ b/core/boosting/CMakeLists.txt @@ -1,12 +1,15 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/adaBoost.h - ${CMAKE_CURRENT_LIST_DIR}/cascadeClassifier.h - ${CMAKE_CURRENT_LIST_DIR}/vjPattern.h - ${CMAKE_CURRENT_LIST_DIR}/detectedObject.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/adaBoost.cpp - ${CMAKE_CURRENT_LIST_DIR}/cascadeClassifier.cpp - ${CMAKE_CURRENT_LIST_DIR}/vjPattern.cpp - ${CMAKE_CURRENT_LIST_DIR}/detectedObject.cpp -) +set(BOOSTING_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/adaBoost.h + ${CMAKE_CURRENT_LIST_DIR}/cascadeClassifier.h + ${CMAKE_CURRENT_LIST_DIR}/vjPattern.h + ${CMAKE_CURRENT_LIST_DIR}/detectedObject.h + PARENT_SCOPE + ) + +set(BOOSTING_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/adaBoost.cpp + ${CMAKE_CURRENT_LIST_DIR}/cascadeClassifier.cpp + ${CMAKE_CURRENT_LIST_DIR}/vjPattern.cpp + ${CMAKE_CURRENT_LIST_DIR}/detectedObject.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/boosting/adaBoost.cpp b/core/boosting/adaBoost.cpp index 7538d166e..ef6ae711d 100644 --- a/core/boosting/adaBoost.cpp +++ b/core/boosting/adaBoost.cpp @@ -7,9 +7,9 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/boosting/adaBoost.h" +#include "boosting/adaBoost.h" namespace corecvs { diff --git a/core/boosting/adaBoost.h b/core/boosting/adaBoost.h index 64070e471..b3ca889c4 100644 --- a/core/boosting/adaBoost.h +++ b/core/boosting/adaBoost.h @@ -19,7 +19,7 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" #include "math.h" diff --git a/core/boosting/cascadeClassifier.cpp b/core/boosting/cascadeClassifier.cpp index 243e7ccc1..f5f8f9936 100644 --- a/core/boosting/cascadeClassifier.cpp +++ b/core/boosting/cascadeClassifier.cpp @@ -7,9 +7,9 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/boosting/cascadeClassifier.h" +#include "boosting/cascadeClassifier.h" namespace corecvs { CascadeClassifier::CascadeClassifier() diff --git a/core/boosting/cascadeClassifier.h b/core/boosting/cascadeClassifier.h index 1c1d446df..fbb08297f 100644 --- a/core/boosting/cascadeClassifier.h +++ b/core/boosting/cascadeClassifier.h @@ -10,10 +10,10 @@ #ifndef CASCADECLASSIFIER_H_ #define CASCADECLASSIFIER_H_ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/mipmapPyramid.h" +#include "buffers/g12Buffer.h" +#include "buffers/mipmapPyramid.h" namespace corecvs { class CascadeClassifier diff --git a/core/boosting/detectedObject.cpp b/core/boosting/detectedObject.cpp index 103adfcd3..e19a7478d 100644 --- a/core/boosting/detectedObject.cpp +++ b/core/boosting/detectedObject.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/boosting/detectedObject.h" +#include "boosting/detectedObject.h" namespace corecvs { diff --git a/core/boosting/detectedObject.h b/core/boosting/detectedObject.h index c98e09508..257de952a 100644 --- a/core/boosting/detectedObject.h +++ b/core/boosting/detectedObject.h @@ -9,9 +9,9 @@ * \author alexander */ -#include "core/math/vector/vector3d.h" -#include "core/math/quaternion.h" -#include "core/math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "math/quaternion.h" +#include "math/vector/vector2d.h" using corecvs::Vector3dd; using corecvs::Quaternion; diff --git a/core/boosting/vjPattern.cpp b/core/boosting/vjPattern.cpp index beeb9cfa9..839eda2b1 100644 --- a/core/boosting/vjPattern.cpp +++ b/core/boosting/vjPattern.cpp @@ -6,7 +6,7 @@ * \date Jun 22, 2010 * \author alexander */ -#include "core/boosting/vjPattern.h" +#include "boosting/vjPattern.h" namespace corecvs { diff --git a/core/boosting/vjPattern.h b/core/boosting/vjPattern.h index 009f9482a..dcf54acbe 100644 --- a/core/boosting/vjPattern.h +++ b/core/boosting/vjPattern.h @@ -17,16 +17,16 @@ #include #include -#include "core/utils/global.h" - -#include "core/tbbwrapper/tbbWrapper.h" -#include "core/math/mathUtils.h" -#include "core/buffers/integralBuffer.h" -#include "core/math/vector/vector3d.h" -#include "core/math/vector/vector2d.h" -#include "core/buffers/mipmapPyramid.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/boosting/adaBoost.h" +#include "utils/global.h" + +#include "tbbwrapper/tbbWrapper.h" +#include "math/mathUtils.h" +#include "buffers/integralBuffer.h" +#include "math/vector/vector3d.h" +#include "math/vector/vector2d.h" +#include "buffers/mipmapPyramid.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "boosting/adaBoost.h" using std::vector; diff --git a/core/buffers/CMakeLists.txt b/core/buffers/CMakeLists.txt index 7c7649a51..1f6fe3ab0 100644 --- a/core/buffers/CMakeLists.txt +++ b/core/buffers/CMakeLists.txt @@ -1,122 +1,124 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/memory/memoryBlock.h - ${CMAKE_CURRENT_LIST_DIR}/abstractBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/abstractContiniousBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/abstractKernel.h - ${CMAKE_CURRENT_LIST_DIR}/bufferFactory.h - ${CMAKE_CURRENT_LIST_DIR}/disparityBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/displacementBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/g8Buffer.h - ${CMAKE_CURRENT_LIST_DIR}/g12Buffer.h - ${CMAKE_CURRENT_LIST_DIR}/booleanBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/commonMappers.h - ${CMAKE_CURRENT_LIST_DIR}/integralBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/derivativeBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/mipmapPyramid.h - ${CMAKE_CURRENT_LIST_DIR}/flow/flowBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/flow/sixDBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/flow/floatFlowBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/flow/punchedBufferOperations.h - ${CMAKE_CURRENT_LIST_DIR}/flow/flowVector.h - ${CMAKE_CURRENT_LIST_DIR}/flow/depthBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/histogram/histogram.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/gaussian.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/laplace.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/sobel.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/threshold.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/arithmetic.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/copyKernel.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/logicKernels.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/fastKernel.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/readers.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/baseKernel.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/baseAlgebra.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/vectorAlgebra.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/scalarAlgebra.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/blurProcessor.h - ${CMAKE_CURRENT_LIST_DIR}/kernels/spatialGradient.h - ${CMAKE_CURRENT_LIST_DIR}/morphological/morphological.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgbColor.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgbTColor.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgb24Buffer.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgbTBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/hardcodeFont.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/hersheyVectorFont.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/abstractPainter.h - ${CMAKE_CURRENT_LIST_DIR}/voxels/voxelBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/fixeddisp/bilinearMapPoint.h - ${CMAKE_CURRENT_LIST_DIR}/fixeddisp/fixedPointBlMapper.h - ${CMAKE_CURRENT_LIST_DIR}/interpolator.h - ${CMAKE_CURRENT_LIST_DIR}/g12Buffer3d.h - ${CMAKE_CURRENT_LIST_DIR}/buffer3d.h - ${CMAKE_CURRENT_LIST_DIR}/transformationCache.h - ${CMAKE_CURRENT_LIST_DIR}/runtimeTypeBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/deformMap.h - ${CMAKE_CURRENT_LIST_DIR}/focusEstimator.h - ${CMAKE_CURRENT_LIST_DIR}/converters/debayer.h - ${CMAKE_CURRENT_LIST_DIR}/converters/debayerTool.h - ${CMAKE_CURRENT_LIST_DIR}/converters/labConverter.h - ${CMAKE_CURRENT_LIST_DIR}/converters/errorMetrics.h - ${CMAKE_CURRENT_LIST_DIR}/memory/alignedMemoryBlock.h - ${CMAKE_CURRENT_LIST_DIR}/convolver/convolver.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/lineSpan.h - ${CMAKE_CURRENT_LIST_DIR}/nonMaximalSuperssor.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/wuRasterizer.h - ${CMAKE_CURRENT_LIST_DIR}/abstractBufferParams.h - # ${CMAKE_CURRENT_LIST_DIR}/focusEstimator1.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/bresenhamRasterizer.h - ${CMAKE_CURRENT_LIST_DIR}/fixeddisp/fixedPointRemapper.h - ${CMAKE_CURRENT_LIST_DIR}/remapBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/rgb24/bezierRasterizer.h - ${CMAKE_CURRENT_LIST_DIR}/correspondenceList.h +set(BUFFERS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/memory/memoryBlock.h + ${CMAKE_CURRENT_LIST_DIR}/abstractBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/abstractContiniousBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/abstractKernel.h + ${CMAKE_CURRENT_LIST_DIR}/bufferFactory.h + ${CMAKE_CURRENT_LIST_DIR}/disparityBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/displacementBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/g8Buffer.h + ${CMAKE_CURRENT_LIST_DIR}/g12Buffer.h + ${CMAKE_CURRENT_LIST_DIR}/booleanBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/commonMappers.h + ${CMAKE_CURRENT_LIST_DIR}/integralBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/derivativeBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/mipmapPyramid.h + ${CMAKE_CURRENT_LIST_DIR}/flow/flowBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/flow/sixDBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/flow/floatFlowBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/flow/punchedBufferOperations.h + ${CMAKE_CURRENT_LIST_DIR}/flow/flowVector.h + ${CMAKE_CURRENT_LIST_DIR}/flow/depthBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/histogram/histogram.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/gaussian.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/laplace.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/sobel.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/threshold.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/arithmetic.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/copyKernel.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/logicKernels.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/fastKernel.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/readers.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/baseKernel.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/baseAlgebra.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/vectorAlgebra.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/fastkernel/scalarAlgebra.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/blurProcessor.h + ${CMAKE_CURRENT_LIST_DIR}/kernels/spatialGradient.h + ${CMAKE_CURRENT_LIST_DIR}/morphological/morphological.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgbColor.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgbTColor.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgb24Buffer.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgbTBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/hardcodeFont.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/hersheyVectorFont.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/abstractPainter.h + ${CMAKE_CURRENT_LIST_DIR}/voxels/voxelBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/fixeddisp/bilinearMapPoint.h + ${CMAKE_CURRENT_LIST_DIR}/fixeddisp/fixedPointBlMapper.h + ${CMAKE_CURRENT_LIST_DIR}/interpolator.h + ${CMAKE_CURRENT_LIST_DIR}/g12Buffer3d.h + ${CMAKE_CURRENT_LIST_DIR}/buffer3d.h + ${CMAKE_CURRENT_LIST_DIR}/transformationCache.h + ${CMAKE_CURRENT_LIST_DIR}/runtimeTypeBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/deformMap.h + ${CMAKE_CURRENT_LIST_DIR}/focusEstimator.h + ${CMAKE_CURRENT_LIST_DIR}/converters/debayer.h + ${CMAKE_CURRENT_LIST_DIR}/converters/debayerTool.h + ${CMAKE_CURRENT_LIST_DIR}/converters/labConverter.h + ${CMAKE_CURRENT_LIST_DIR}/converters/errorMetrics.h + ${CMAKE_CURRENT_LIST_DIR}/memory/alignedMemoryBlock.h + ${CMAKE_CURRENT_LIST_DIR}/convolver/convolver.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/lineSpan.h + ${CMAKE_CURRENT_LIST_DIR}/nonMaximalSuperssor.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/wuRasterizer.h + ${CMAKE_CURRENT_LIST_DIR}/abstractBufferParams.h +# ${CMAKE_CURRENT_LIST_DIR}/focusEstimator1.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/bresenhamRasterizer.h + ${CMAKE_CURRENT_LIST_DIR}/fixeddisp/fixedPointRemapper.h + ${CMAKE_CURRENT_LIST_DIR}/remapBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/rgb24/bezierRasterizer.h + ${CMAKE_CURRENT_LIST_DIR}/correspondenceList.h + PARENT_SCOPE + ) - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/memory/memoryBlock.cpp - ${CMAKE_CURRENT_LIST_DIR}/abstractBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/bufferFactory.cpp - ${CMAKE_CURRENT_LIST_DIR}/disparityBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/displacementBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/g8Buffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/g12Buffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/booleanBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/commonMappers.cpp - ${CMAKE_CURRENT_LIST_DIR}/mipmapPyramid.cpp - ${CMAKE_CURRENT_LIST_DIR}/derivativeBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/flow/flowBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/flow/sixDBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/flow/floatFlowBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/flow/depthBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/histogram/histogram.cpp - ${CMAKE_CURRENT_LIST_DIR}/kernels/gaussian.cpp - ${CMAKE_CURRENT_LIST_DIR}/kernels/sobel.cpp - ${CMAKE_CURRENT_LIST_DIR}/kernels/laplace.cpp - ${CMAKE_CURRENT_LIST_DIR}/kernels/threshold.cpp - ${CMAKE_CURRENT_LIST_DIR}/kernels/blurProcessor.cpp - ${CMAKE_CURRENT_LIST_DIR}/kernels/spatialGradient.cpp - ${CMAKE_CURRENT_LIST_DIR}/kernels/logicKernels.cpp - ${CMAKE_CURRENT_LIST_DIR}/morphological/morphological.cpp - ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgbColor.cpp - ${CMAKE_CURRENT_LIST_DIR}/rgb24/hardcodeFont.cpp - ${CMAKE_CURRENT_LIST_DIR}/rgb24/hersheyVectorFont.cpp - ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgb24Buffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/rgb24/abstractPainter.cpp - ${CMAKE_CURRENT_LIST_DIR}/g12Buffer3d.cpp - ${CMAKE_CURRENT_LIST_DIR}/buffer3d.cpp - ${CMAKE_CURRENT_LIST_DIR}/transformationCache.cpp - ${CMAKE_CURRENT_LIST_DIR}/runtimeTypeBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/deformMap.cpp - ${CMAKE_CURRENT_LIST_DIR}/focusEstimator.cpp - ${CMAKE_CURRENT_LIST_DIR}/converters/debayer.cpp - ${CMAKE_CURRENT_LIST_DIR}/converters/debayerTool.cpp - ${CMAKE_CURRENT_LIST_DIR}/converters/errorMetrics.cpp - ${CMAKE_CURRENT_LIST_DIR}/convolver/convolver.cpp - ${CMAKE_CURRENT_LIST_DIR}/rgb24/lineSpan.cpp - ${CMAKE_CURRENT_LIST_DIR}/nonMaximalSuperssor.cpp - # ${CMAKE_CURRENT_LIST_DIR}/focusEstimator1.cpp - ${CMAKE_CURRENT_LIST_DIR}/rgb24/wuRasterizer.cpp - ${CMAKE_CURRENT_LIST_DIR}/rgb24/bresenhamRasterizer.cpp - ${CMAKE_CURRENT_LIST_DIR}/remapBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/rgb24/bezierRasterizer.cpp - ${CMAKE_CURRENT_LIST_DIR}/correspondenceList.cpp - ) +set(BUFFERS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/memory/memoryBlock.cpp + ${CMAKE_CURRENT_LIST_DIR}/abstractBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/bufferFactory.cpp + ${CMAKE_CURRENT_LIST_DIR}/disparityBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/displacementBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/g8Buffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/g12Buffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/booleanBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/commonMappers.cpp + ${CMAKE_CURRENT_LIST_DIR}/mipmapPyramid.cpp + ${CMAKE_CURRENT_LIST_DIR}/derivativeBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/flow/flowBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/flow/sixDBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/flow/floatFlowBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/flow/depthBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/histogram/histogram.cpp + ${CMAKE_CURRENT_LIST_DIR}/kernels/gaussian.cpp + ${CMAKE_CURRENT_LIST_DIR}/kernels/sobel.cpp + ${CMAKE_CURRENT_LIST_DIR}/kernels/laplace.cpp + ${CMAKE_CURRENT_LIST_DIR}/kernels/threshold.cpp + ${CMAKE_CURRENT_LIST_DIR}/kernels/blurProcessor.cpp + ${CMAKE_CURRENT_LIST_DIR}/kernels/spatialGradient.cpp + ${CMAKE_CURRENT_LIST_DIR}/kernels/logicKernels.cpp + ${CMAKE_CURRENT_LIST_DIR}/morphological/morphological.cpp + ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgbColor.cpp + ${CMAKE_CURRENT_LIST_DIR}/rgb24/hardcodeFont.cpp + ${CMAKE_CURRENT_LIST_DIR}/rgb24/hersheyVectorFont.cpp + ${CMAKE_CURRENT_LIST_DIR}/rgb24/rgb24Buffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/rgb24/abstractPainter.cpp + ${CMAKE_CURRENT_LIST_DIR}/g12Buffer3d.cpp + ${CMAKE_CURRENT_LIST_DIR}/buffer3d.cpp + ${CMAKE_CURRENT_LIST_DIR}/transformationCache.cpp + ${CMAKE_CURRENT_LIST_DIR}/runtimeTypeBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/deformMap.cpp + ${CMAKE_CURRENT_LIST_DIR}/focusEstimator.cpp + ${CMAKE_CURRENT_LIST_DIR}/converters/debayer.cpp + ${CMAKE_CURRENT_LIST_DIR}/converters/debayerTool.cpp + ${CMAKE_CURRENT_LIST_DIR}/converters/errorMetrics.cpp + ${CMAKE_CURRENT_LIST_DIR}/convolver/convolver.cpp + ${CMAKE_CURRENT_LIST_DIR}/rgb24/lineSpan.cpp + ${CMAKE_CURRENT_LIST_DIR}/nonMaximalSuperssor.cpp +# ${CMAKE_CURRENT_LIST_DIR}/focusEstimator1.cpp + ${CMAKE_CURRENT_LIST_DIR}/rgb24/wuRasterizer.cpp + ${CMAKE_CURRENT_LIST_DIR}/rgb24/bresenhamRasterizer.cpp + ${CMAKE_CURRENT_LIST_DIR}/remapBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/rgb24/bezierRasterizer.cpp + ${CMAKE_CURRENT_LIST_DIR}/correspondenceList.cpp + PARENT_SCOPE + ) diff --git a/core/buffers/abstractBuffer.cpp b/core/buffers/abstractBuffer.cpp index 2001bffe6..1bcf76846 100644 --- a/core/buffers/abstractBuffer.cpp +++ b/core/buffers/abstractBuffer.cpp @@ -6,7 +6,7 @@ * \date Dec 21, 2012 * \author sf */ -#include "core/buffers/abstractBuffer.h" +#include "buffers/abstractBuffer.h" namespace corecvs { diff --git a/core/buffers/abstractBuffer.h b/core/buffers/abstractBuffer.h index 4d202babf..9f09d86d4 100644 --- a/core/buffers/abstractBuffer.h +++ b/core/buffers/abstractBuffer.h @@ -24,15 +24,15 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" +#include "math/vector/vector2d.h" #include "memory/memoryBlock.h" #include "memory/alignedMemoryBlock.h" -#include "core/tbbwrapper/tbbWrapper.h" // BlockedRange -#include "core/math/mathUtils.h" // randRanged +#include "tbbwrapper/tbbWrapper.h" // BlockedRange +#include "math/mathUtils.h" // randRanged -#include "core/buffers/abstractBufferParams.h" +#include "buffers/abstractBufferParams.h" namespace corecvs { diff --git a/core/buffers/abstractContiniousBuffer.h b/core/buffers/abstractContiniousBuffer.h index fe062dd28..a17d9d660 100644 --- a/core/buffers/abstractContiniousBuffer.h +++ b/core/buffers/abstractContiniousBuffer.h @@ -12,12 +12,12 @@ * TODO: Add nearest neighbor GEDB * TODO: Add colorspace converters GEDB */ -#include "core/utils/global.h" -#include "core/buffers/abstractBuffer.h" -#include "core/math/matrix/matrix.h" +#include "utils/global.h" +#include "buffers/abstractBuffer.h" +#include "math/matrix/matrix.h" -//#include "core/buffers/fixeddisp/fixedPointBlMapper.h" -//#include "core/buffers/fixeddisp/bilinearMapPoint.h" +//#include "buffers/fixeddisp/fixedPointBlMapper.h" +//#include "buffers/fixeddisp/bilinearMapPoint.h" namespace corecvs { diff --git a/core/buffers/abstractKernel.h b/core/buffers/abstractKernel.h index ec5d1fcd5..629d9ef57 100644 --- a/core/buffers/abstractKernel.h +++ b/core/buffers/abstractKernel.h @@ -12,8 +12,8 @@ */ -#include "core/utils/global.h" -#include "core/buffers/abstractBuffer.h" +#include "utils/global.h" +#include "buffers/abstractBuffer.h" namespace corecvs { diff --git a/core/buffers/booleanBuffer.cpp b/core/buffers/booleanBuffer.cpp index fbd481b32..7d2f38e69 100644 --- a/core/buffers/booleanBuffer.cpp +++ b/core/buffers/booleanBuffer.cpp @@ -4,7 +4,7 @@ * \date Sep 28, 2013 **/ -#include "core/buffers/booleanBuffer.h" +#include "buffers/booleanBuffer.h" namespace corecvs { diff --git a/core/buffers/booleanBuffer.h b/core/buffers/booleanBuffer.h index 91c1bebaa..62ecb3423 100644 --- a/core/buffers/booleanBuffer.h +++ b/core/buffers/booleanBuffer.h @@ -6,8 +6,8 @@ * \date Sep 28, 2013 **/ -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/buffers/g8Buffer.h" +#include "buffers/abstractContiniousBuffer.h" +#include "buffers/g8Buffer.h" namespace corecvs { diff --git a/core/buffers/buffer3d.cpp b/core/buffers/buffer3d.cpp index 670d5de58..ada81f712 100644 --- a/core/buffers/buffer3d.cpp +++ b/core/buffers/buffer3d.cpp @@ -1,4 +1,4 @@ -#include "core/buffers/buffer3d.h" +#include "buffers/buffer3d.h" namespace corecvs { diff --git a/core/buffers/buffer3d.h b/core/buffers/buffer3d.h index 410443057..f68173248 100644 --- a/core/buffers/buffer3d.h +++ b/core/buffers/buffer3d.h @@ -1,14 +1,14 @@ #ifndef BUFFER3D_H #define BUFFER3D_H -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector3d.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/rectification/triangulator.h" -#include "core/buffers/abstractContiniousBuffer.h" +#include "math/vector/vector3d.h" +#include "geometry/mesh/mesh3d.h" +#include "rectification/triangulator.h" +#include "buffers/abstractContiniousBuffer.h" #include "flow/punchedBufferOperations.h" -#include "core/clustering3d/cloud.h" +#include "clustering3d/cloud.h" namespace corecvs { diff --git a/core/buffers/bufferFactory.cpp b/core/buffers/bufferFactory.cpp index 897e3a55f..7e1556b67 100644 --- a/core/buffers/bufferFactory.cpp +++ b/core/buffers/bufferFactory.cpp @@ -6,14 +6,14 @@ * \date Jun 22, 2010 * \author alexander */ -#include "core/buffers/bufferFactory.h" -#include "core/fileformats/ppmLoader.h" -#include "core/fileformats/rawLoader.h" -#include "core/fileformats/bmpLoader.h" -#include "core/fileformats/tgaLoader.h" -#include "core/fileformats/floLoader.h" -#include "core/fileformats/svgLoader.h" -#include "core/fileformats/dxf_support/dxfLoader.h" +#include "buffers/bufferFactory.h" +#include "fileformats/ppmLoader.h" +#include "fileformats/rawLoader.h" +#include "fileformats/bmpLoader.h" +#include "fileformats/tgaLoader.h" +#include "fileformats/floLoader.h" +#include "fileformats/svgLoader.h" +#include "fileformats/dxf_support/dxfLoader.h" //#if __cplusplus > 199711L #if defined(WIN32) && (_MSC_VER < 1900) // we need a threadsafety singleton initialization described in paragraph 6.7.4 of the C++11 standard, msvc2013 doesn't support it fully... Don't care about gcc-versions diff --git a/core/buffers/bufferFactory.h b/core/buffers/bufferFactory.h index 44cefbc4e..01ea26f3b 100644 --- a/core/buffers/bufferFactory.h +++ b/core/buffers/bufferFactory.h @@ -9,13 +9,13 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/fileformats/bufferLoader.h" -#include "core/buffers/runtimeTypeBuffer.h" -#include "core/buffers/float/dpImage.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "fileformats/bufferLoader.h" +#include "buffers/runtimeTypeBuffer.h" +#include "buffers/float/dpImage.h" namespace corecvs { diff --git a/core/buffers/commonMappers.cpp b/core/buffers/commonMappers.cpp index ca721fe74..29712f98e 100644 --- a/core/buffers/commonMappers.cpp +++ b/core/buffers/commonMappers.cpp @@ -10,8 +10,8 @@ * \author: alexander */ -#include "core/buffers/commonMappers.h" -#include "core/buffers/g12Buffer.h" +#include "buffers/commonMappers.h" +#include "buffers/g12Buffer.h" namespace corecvs { diff --git a/core/buffers/commonMappers.h b/core/buffers/commonMappers.h index b147d2804..79e5aaa3c 100644 --- a/core/buffers/commonMappers.h +++ b/core/buffers/commonMappers.h @@ -11,84 +11,85 @@ #include #include -#include "core/buffers/abstractBuffer.h" -#include "core/buffers/g12Buffer.h" +#include "buffers/abstractBuffer.h" +#include "buffers/g12Buffer.h" namespace corecvs { -using std::unary_function; - -class GainOffsetMapper : public unary_function -{ - double gain; - int offset; - -public: - GainOffsetMapper(double _gain, int _offset) + class GainOffsetMapper { - gain = _gain; - offset = _offset; - } - uint16_t operator ()( const uint16_t &input) const - { - double value = ((double)input - offset) / gain; - if (value < 0) - return 0; - if (value >= G12Buffer::BUFFER_MAX_VALUE) - return G12Buffer::BUFFER_MAX_VALUE; - return (uint16_t)value; - } -}; + public: + double gain; + int offset; + GainOffsetMapper(double _gain, int _offset) + { + gain = _gain; + offset = _offset; + } -class ShiftMaskMapper : public unary_function -{ - uint32_t mask; - int8_t shift; + uint16_t operator ()(const uint16_t& input) const + { + double value = ((double)input - offset) / gain; + if (value < 0) + return 0; + if (value >= G12Buffer::BUFFER_MAX_VALUE) + return G12Buffer::BUFFER_MAX_VALUE; -public: - ShiftMaskMapper(uint32_t _mask, int8_t _shift) - { - mask = _mask; - shift = _shift; - } + return (uint16_t)value; + } + }; - uint16_t operator ()( const uint16_t &input) const - { - uint16_t value = input & mask; - if (shift > 0) - value <<= shift; - if (shift < 0) - value >>= (-shift); - return value; - } -}; - -class IntervalMapper : public unary_function -{ - int32_t min; - int32_t interval; - -public: - IntervalMapper(int32_t _min, int32_t _max) - { - min = _min; - interval = _max - _min; - } - uint16_t operator ()( const uint16_t &input) const + class ShiftMaskMapper { - int64_t value = ((uint64_t)input * interval) / G12Buffer::BUFFER_MAX_VALUE + min; - if (value < 0) - return 0; - if (value > G12Buffer::BUFFER_MAX_VALUE) - return G12Buffer::BUFFER_MAX_VALUE; - return (uint16_t)value; - } -}; - -} //namespace corecvs + public: + uint32_t mask; + int8_t shift; + + ShiftMaskMapper(uint32_t _mask, int8_t _shift) + { + mask = _mask; + shift = _shift; + } + + uint16_t operator ()(const uint16_t& input) const + { + uint16_t value = input & mask; + if (shift > 0) + value <<= shift; + if (shift < 0) + value >>= (-shift); + return value; + } + }; + + class IntervalMapper + { + public: + int32_t min; + int32_t interval; + IntervalMapper(int32_t _min, int32_t _max) + { + min = _min; + interval = _max - _min; + } + + uint16_t operator ()(const uint16_t& input) const + { + int64_t value = ((uint64_t)input * interval) / G12Buffer::BUFFER_MAX_VALUE + min; + if (value < 0) + return 0; + if (value > G12Buffer::BUFFER_MAX_VALUE) + return G12Buffer::BUFFER_MAX_VALUE; + + return (uint16_t)value; + } + }; + + +}; //namespace corecvs diff --git a/core/buffers/converters/colorConverters.cpp b/core/buffers/converters/colorConverters.cpp index 34443da45..8d4b7282c 100644 --- a/core/buffers/converters/colorConverters.cpp +++ b/core/buffers/converters/colorConverters.cpp @@ -5,7 +5,7 @@ * Author: alexander */ -#include "core/buffers/converters/colorConverters.h" +#include "buffers/converters/colorConverters.h" namespace corecvs { diff --git a/core/buffers/converters/debayer.cpp b/core/buffers/converters/debayer.cpp index 6daf63522..60f2337ad 100644 --- a/core/buffers/converters/debayer.cpp +++ b/core/buffers/converters/debayer.cpp @@ -1,7 +1,7 @@ -#include "core/buffers/converters/debayer.h" -#include "core/buffers/converters/labConverter.h" -#include "core/utils/log.h" -#include "core/math/fftw/fftwWrapper.h" +#include "buffers/converters/debayer.h" +#include "buffers/converters/labConverter.h" +#include "utils/log.h" +#include "math/fftw/fftwWrapper.h" namespace corecvs { diff --git a/core/buffers/converters/debayer.h b/core/buffers/converters/debayer.h index 48cbde3bd..567fb8cac 100644 --- a/core/buffers/converters/debayer.h +++ b/core/buffers/converters/debayer.h @@ -12,16 +12,16 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgbTBuffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/fileformats/metamap.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgbTBuffer.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "fileformats/metamap.h" -#include "core/xml/generated/debayerParameters.h" +#include "xml/generated/debayerParameters.h" namespace corecvs { diff --git a/core/buffers/converters/debayerTool.cpp b/core/buffers/converters/debayerTool.cpp index 26bf3ed33..bfd8a0d7e 100644 --- a/core/buffers/converters/debayerTool.cpp +++ b/core/buffers/converters/debayerTool.cpp @@ -1,12 +1,12 @@ -#include "core/buffers/converters/debayerTool.h" -#include "core/buffers/converters/debayer.h" -#include "core/buffers/converters/errorMetrics.h" -#include "core/reflection/commandLineSetter.h" -#include "core/fileformats/ppmLoader.h" -#include "core/fileformats/bmpLoader.h" -#include "core/filesystem/folderScanner.h" -#include "core/utils/utils.h" -#include "core/utils/log.h" +#include "buffers/converters/debayerTool.h" +#include "buffers/converters/debayer.h" +#include "buffers/converters/errorMetrics.h" +#include "reflection/commandLineSetter.h" +#include "fileformats/ppmLoader.h" +#include "fileformats/bmpLoader.h" +#include "filesystem/folderScanner.h" +#include "utils/utils.h" +#include "utils/log.h" namespace corecvs { diff --git a/core/buffers/converters/debayerTool.h b/core/buffers/converters/debayerTool.h index 55b0cb3e4..d5b9887d8 100644 --- a/core/buffers/converters/debayerTool.h +++ b/core/buffers/converters/debayerTool.h @@ -9,10 +9,10 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/reflection/commandLineSetter.h" -#include "core/buffers/converters/debayer.h" +#include "reflection/commandLineSetter.h" +#include "buffers/converters/debayer.h" namespace corecvs { diff --git a/core/buffers/converters/errorMetrics.cpp b/core/buffers/converters/errorMetrics.cpp index b4e1b142f..3f8c58e17 100644 --- a/core/buffers/converters/errorMetrics.cpp +++ b/core/buffers/converters/errorMetrics.cpp @@ -1,6 +1,6 @@ -#include "core/buffers/converters/errorMetrics.h" -#include "core/buffers/converters/debayer.h" -#include "core/fileformats/ppmLoader.h" +#include "buffers/converters/errorMetrics.h" +#include "buffers/converters/debayer.h" +#include "fileformats/ppmLoader.h" using namespace corecvs; diff --git a/core/buffers/converters/errorMetrics.h b/core/buffers/converters/errorMetrics.h index 98e7c8f7e..5a1e945c6 100644 --- a/core/buffers/converters/errorMetrics.h +++ b/core/buffers/converters/errorMetrics.h @@ -7,9 +7,9 @@ * \author pavel.vasilev */ -#include "core/utils/global.h" -#include "core/buffers/rgb24/rgbTBuffer.h" -#include "core/buffers/g12Buffer.h" +#include "utils/global.h" +#include "buffers/rgb24/rgbTBuffer.h" +#include "buffers/g12Buffer.h" namespace corecvs { diff --git a/core/buffers/converters/labConverter.h b/core/buffers/converters/labConverter.h index d5a261cb0..f38be0df9 100644 --- a/core/buffers/converters/labConverter.h +++ b/core/buffers/converters/labConverter.h @@ -10,9 +10,9 @@ #ifndef LABCONVERTER_H_ #define LABCONVERTER_H_ -#include "core/utils/global.h" -#include "core/buffers/rgb24/rgbTColor.h" -#include "core/buffers/rgb24/rgbColor.h" +#include "utils/global.h" +#include "buffers/rgb24/rgbTColor.h" +#include "buffers/rgb24/rgbColor.h" namespace corecvs { diff --git a/core/buffers/convolver/convolver.cpp b/core/buffers/convolver/convolver.cpp index ad1059fa6..a73d4148d 100644 --- a/core/buffers/convolver/convolver.cpp +++ b/core/buffers/convolver/convolver.cpp @@ -1,11 +1,11 @@ -#include "core/buffers/convolver/convolver.h" +#include "buffers/convolver/convolver.h" -#include "core/utils/global.h" -#include "core/buffers/kernels/fastkernel/fastKernel.h" -#include "core/buffers/kernels/arithmetic.h" +#include "utils/global.h" +#include "buffers/kernels/fastkernel/fastKernel.h" +#include "buffers/kernels/arithmetic.h" -#include "core/math/sse/sseWrapper.h" -#include "core/buffers/kernels/fastkernel/vectorTraits.h" +#include "math/sse/sseWrapper.h" +#include "buffers/kernels/fastkernel/vectorTraits.h" namespace corecvs { diff --git a/core/buffers/convolver/convolver.h b/core/buffers/convolver/convolver.h index 6f032004b..998034caf 100644 --- a/core/buffers/convolver/convolver.h +++ b/core/buffers/convolver/convolver.h @@ -9,14 +9,14 @@ * \date Mar 24, 2010 * \author alexander */ -#include "core/utils/global.h" -#include "core/math/matrix/matrix.h" +#include "utils/global.h" +#include "math/matrix/matrix.h" -#include "core/buffers/abstractBuffer.h" -#include "core/buffers/abstractKernel.h" +#include "buffers/abstractBuffer.h" +#include "buffers/abstractKernel.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/float/dpImage.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/float/dpImage.h" namespace corecvs { diff --git a/core/buffers/correspondenceList.cpp b/core/buffers/correspondenceList.cpp index 28543634f..645ce4895 100644 --- a/core/buffers/correspondenceList.cpp +++ b/core/buffers/correspondenceList.cpp @@ -7,9 +7,9 @@ * \author alexander */ -#include "core/math/mathUtils.h" -#include "core/buffers/correspondenceList.h" -#include "core/kltflow/kltGenerator.h" +#include "math/mathUtils.h" +#include "buffers/correspondenceList.h" +#include "kltflow/kltGenerator.h" namespace corecvs { CorrespondenceList::CorrespondenceList() diff --git a/core/buffers/correspondenceList.h b/core/buffers/correspondenceList.h index 1aba1200c..e0772d0a7 100644 --- a/core/buffers/correspondenceList.h +++ b/core/buffers/correspondenceList.h @@ -11,10 +11,10 @@ #define CCorrespondenceLIST_H_ #include -#include "core/math/vector/vector2d.h" -#include "core/buffers/flow/flowBuffer.h" -#include "core/buffers/flow/floatFlowBuffer.h" -#include "core/math/projectiveTransform.h" +#include "math/vector/vector2d.h" +#include "buffers/flow/flowBuffer.h" +#include "buffers/flow/floatFlowBuffer.h" +#include "math/projectiveTransform.h" namespace corecvs { diff --git a/core/buffers/deformMap.cpp b/core/buffers/deformMap.cpp index efe1c3edc..faa1e919e 100644 --- a/core/buffers/deformMap.cpp +++ b/core/buffers/deformMap.cpp @@ -1,4 +1,4 @@ -#include "core/buffers/deformMap.h" +#include "buffers/deformMap.h" namespace corecvs { diff --git a/core/buffers/deformMap.h b/core/buffers/deformMap.h index a6c9a49c9..7f981d35c 100644 --- a/core/buffers/deformMap.h +++ b/core/buffers/deformMap.h @@ -1,7 +1,7 @@ #ifndef DEFORMMAP_H #define DEFORMMAP_H -#include "core/math/vector/vector2d.h" +#include "math/vector/vector2d.h" namespace corecvs { diff --git a/core/buffers/derivativeBuffer.cpp b/core/buffers/derivativeBuffer.cpp index 17d42e4d7..37f98b18a 100644 --- a/core/buffers/derivativeBuffer.cpp +++ b/core/buffers/derivativeBuffer.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/buffers/derivativeBuffer.h" +#include "buffers/derivativeBuffer.h" namespace corecvs { DerivativeBuffer::DerivativeBuffer(G12Buffer *input) : DerivativeBufferBase(input->h, input->w) diff --git a/core/buffers/derivativeBuffer.h b/core/buffers/derivativeBuffer.h index af6170e8f..239b85cb5 100644 --- a/core/buffers/derivativeBuffer.h +++ b/core/buffers/derivativeBuffer.h @@ -12,11 +12,11 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/buffers/abstractBuffer.h" -#include "core/buffers/g12Buffer.h" +#include "math/vector/vector2d.h" +#include "buffers/abstractBuffer.h" +#include "buffers/g12Buffer.h" namespace corecvs { diff --git a/core/buffers/disparityBuffer.cpp b/core/buffers/disparityBuffer.cpp index 3cf1f11a8..30365eaed 100644 --- a/core/buffers/disparityBuffer.cpp +++ b/core/buffers/disparityBuffer.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/buffers/disparityBuffer.h" +#include "buffers/disparityBuffer.h" namespace corecvs { } //namespace corecvs diff --git a/core/buffers/disparityBuffer.h b/core/buffers/disparityBuffer.h index 4bd57f5ea..43aa50435 100644 --- a/core/buffers/disparityBuffer.h +++ b/core/buffers/disparityBuffer.h @@ -8,7 +8,7 @@ * \author alexander */ #include -#include "core/buffers/abstractContiniousBuffer.h" +#include "buffers/abstractContiniousBuffer.h" namespace corecvs { diff --git a/core/buffers/displacementBuffer.cpp b/core/buffers/displacementBuffer.cpp index 0bdf7469a..10f46e28b 100644 --- a/core/buffers/displacementBuffer.cpp +++ b/core/buffers/displacementBuffer.cpp @@ -6,7 +6,7 @@ * \date Mar 21, 2010 * \author alexander */ -#include "core/buffers/displacementBuffer.h" +#include "buffers/displacementBuffer.h" namespace corecvs { diff --git a/core/buffers/displacementBuffer.h b/core/buffers/displacementBuffer.h index d96b65373..a90260a6e 100644 --- a/core/buffers/displacementBuffer.h +++ b/core/buffers/displacementBuffer.h @@ -12,17 +12,17 @@ #include -#include "core/utils/global.h" - -#include "core/math/mathUtils.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/buffers/g12Buffer.h" -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix33.h" -#include "core/tbbwrapper/tbbWrapper.h" -#include "core/alignment/radialCorrection.h" -#include "core/alignment/distortionCorrectTransform.h" -#include "core/alignment/lensDistortionModelParameters.h" +#include "utils/global.h" + +#include "math/mathUtils.h" +#include "buffers/abstractContiniousBuffer.h" +#include "buffers/g12Buffer.h" +#include "math/vector/vector2d.h" +#include "math/matrix/matrix33.h" +#include "tbbwrapper/tbbWrapper.h" +#include "alignment/radialCorrection.h" +#include "alignment/distortionCorrectTransform.h" +#include "alignment/lensDistortionModelParameters.h" #include "../math/levenmarq.h" namespace corecvs { diff --git a/core/buffers/fixeddisp/fixedPointBlMapper.h b/core/buffers/fixeddisp/fixedPointBlMapper.h index 8bd9748cb..4f405441d 100644 --- a/core/buffers/fixeddisp/fixedPointBlMapper.h +++ b/core/buffers/fixeddisp/fixedPointBlMapper.h @@ -11,7 +11,7 @@ * \ingroup cppcorefiles */ -#include "core/buffers/fixeddisp/fixedPointRemapper.h" +#include "buffers/fixeddisp/fixedPointRemapper.h" namespace corecvs { diff --git a/core/buffers/fixeddisp/fixedPointRemapper.h b/core/buffers/fixeddisp/fixedPointRemapper.h index e71128a79..99e80f0c1 100644 --- a/core/buffers/fixeddisp/fixedPointRemapper.h +++ b/core/buffers/fixeddisp/fixedPointRemapper.h @@ -13,10 +13,10 @@ #include -#include "core/utils/global.h" -#include "core/buffers/abstractBuffer.h" -#include "core/math/matrix/matrix33.h" -#include "core/buffers/fixeddisp/bilinearMapPoint.h" +#include "utils/global.h" +#include "buffers/abstractBuffer.h" +#include "math/matrix/matrix33.h" +#include "buffers/fixeddisp/bilinearMapPoint.h" namespace corecvs { diff --git a/core/buffers/float/dpImage.h b/core/buffers/float/dpImage.h index b9f326094..773b05ca3 100644 --- a/core/buffers/float/dpImage.h +++ b/core/buffers/float/dpImage.h @@ -1,7 +1,7 @@ #ifndef DP_IMAGE_H #define DP_IMAGE_H -#include "core/buffers/abstractContiniousBuffer.h" +#include "buffers/abstractContiniousBuffer.h" namespace corecvs { diff --git a/core/buffers/flow/depthBuffer.cpp b/core/buffers/flow/depthBuffer.cpp index 401cff508..675b1191c 100644 --- a/core/buffers/flow/depthBuffer.cpp +++ b/core/buffers/flow/depthBuffer.cpp @@ -3,7 +3,7 @@ * * \date Dec 6, 2012 **/ -#include "core/buffers/flow/depthBuffer.h" +#include "buffers/flow/depthBuffer.h" namespace corecvs { diff --git a/core/buffers/flow/depthBuffer.h b/core/buffers/flow/depthBuffer.h index 8c3279375..bd2be9317 100644 --- a/core/buffers/flow/depthBuffer.h +++ b/core/buffers/flow/depthBuffer.h @@ -6,10 +6,10 @@ **/ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/buffers/flow/punchedBufferOperations.h" +#include "buffers/abstractContiniousBuffer.h" +#include "buffers/flow/punchedBufferOperations.h" namespace corecvs { diff --git a/core/buffers/flow/element6D.cpp b/core/buffers/flow/element6D.cpp index 02476a043..a49e1396d 100644 --- a/core/buffers/flow/element6D.cpp +++ b/core/buffers/flow/element6D.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/buffers/flow/element6D.h" +#include "buffers/flow/element6D.h" namespace corecvs { diff --git a/core/buffers/flow/element6D.h b/core/buffers/flow/element6D.h index 17960e26f..d9488d259 100644 --- a/core/buffers/flow/element6D.h +++ b/core/buffers/flow/element6D.h @@ -8,7 +8,7 @@ * \author alexander */ -#include "core/buffers/flow/flowBuffer.h" +#include "buffers/flow/flowBuffer.h" namespace corecvs { diff --git a/core/buffers/flow/floatFlowBuffer.cpp b/core/buffers/flow/floatFlowBuffer.cpp index 6824f4ac8..f0d873b94 100644 --- a/core/buffers/flow/floatFlowBuffer.cpp +++ b/core/buffers/flow/floatFlowBuffer.cpp @@ -6,10 +6,10 @@ * \date Jul 20, 2010 * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/flow/floatFlowBuffer.h" -#include "core/stats/calculationStats.h" +#include "buffers/flow/floatFlowBuffer.h" +#include "stats/calculationStats.h" namespace corecvs { diff --git a/core/buffers/flow/floatFlowBuffer.h b/core/buffers/flow/floatFlowBuffer.h index 4b3bb2f4c..f8cf800df 100644 --- a/core/buffers/flow/floatFlowBuffer.h +++ b/core/buffers/flow/floatFlowBuffer.h @@ -11,17 +11,17 @@ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/buffers/flow/flowBuffer.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/kltflow/kltGenerator.h" -#include "core/buffers/rgb24/rgbColor.h" +#include "math/vector/vector2d.h" +#include "buffers/flow/flowBuffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/abstractContiniousBuffer.h" +#include "kltflow/kltGenerator.h" +#include "buffers/rgb24/rgbColor.h" -#include "core/xml/generated/preciseInterpolationType.h" -#include "core/xml/generated/makePreciseParameters.h" +#include "xml/generated/preciseInterpolationType.h" +#include "xml/generated/makePreciseParameters.h" namespace corecvs { diff --git a/core/buffers/flow/flowBuffer.cpp b/core/buffers/flow/flowBuffer.cpp index e1a494272..329fd6e7d 100644 --- a/core/buffers/flow/flowBuffer.cpp +++ b/core/buffers/flow/flowBuffer.cpp @@ -9,13 +9,13 @@ */ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/flow/flowBuffer.h" -#include "core/math/sse/sseWrapper.h" -#include "core/math/neon/neonWrapper.h" -#include "core/tbbwrapper/tbbWrapper.h" -#include "core/buffers/flow/floatFlowBuffer.h" +#include "buffers/flow/flowBuffer.h" +#include "math/sse/sseWrapper.h" +#include "math/neon/neonWrapper.h" +#include "tbbwrapper/tbbWrapper.h" +#include "buffers/flow/floatFlowBuffer.h" namespace corecvs { diff --git a/core/buffers/flow/flowBuffer.h b/core/buffers/flow/flowBuffer.h index 07227c1d7..279c187d8 100644 --- a/core/buffers/flow/flowBuffer.h +++ b/core/buffers/flow/flowBuffer.h @@ -16,16 +16,16 @@ #ifdef WITH_SSE #include #endif -#include "core/math/sse/sseWrapper.h" -#include "core/math/neon/neonWrapper.h" +#include "math/sse/sseWrapper.h" +#include "math/neon/neonWrapper.h" -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/flow/punchedBufferOperations.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/math/vector/vector2d.h" -#include "core/buffers/flow/flowVector.h" -#include "core/math/matrix/matrix33.h" +#include "buffers/flow/punchedBufferOperations.h" +#include "buffers/abstractContiniousBuffer.h" +#include "math/vector/vector2d.h" +#include "buffers/flow/flowVector.h" +#include "math/matrix/matrix33.h" namespace corecvs { diff --git a/core/buffers/flow/flowVector.h b/core/buffers/flow/flowVector.h index 7e42ead91..f56b20ec2 100644 --- a/core/buffers/flow/flowVector.h +++ b/core/buffers/flow/flowVector.h @@ -11,7 +11,7 @@ #include -#include "core/math/vector/vector2d.h" +#include "math/vector/vector2d.h" namespace corecvs { diff --git a/core/buffers/flow/punchedBufferOperations.h b/core/buffers/flow/punchedBufferOperations.h index 133d96a0d..c0fae4461 100644 --- a/core/buffers/flow/punchedBufferOperations.h +++ b/core/buffers/flow/punchedBufferOperations.h @@ -12,11 +12,11 @@ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/tbbwrapper/tbbWrapper.h" -#include "core/buffers/float/dpImage.h" +#include "math/vector/vector2d.h" +#include "tbbwrapper/tbbWrapper.h" +#include "buffers/float/dpImage.h" namespace corecvs { diff --git a/core/buffers/flow/sixDBuffer.cpp b/core/buffers/flow/sixDBuffer.cpp index 8fff730dc..77168778d 100644 --- a/core/buffers/flow/sixDBuffer.cpp +++ b/core/buffers/flow/sixDBuffer.cpp @@ -6,8 +6,8 @@ * \author alexander */ -#include "core/utils/global.h" -#include "core/buffers/flow/sixDBuffer.h" +#include "utils/global.h" +#include "buffers/flow/sixDBuffer.h" namespace corecvs { diff --git a/core/buffers/flow/sixDBuffer.h b/core/buffers/flow/sixDBuffer.h index 77c0ea32c..30dd6f636 100644 --- a/core/buffers/flow/sixDBuffer.h +++ b/core/buffers/flow/sixDBuffer.h @@ -14,12 +14,12 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/buffers/flow/element6D.h" -#include "core/buffers/flow/punchedBufferOperations.h" -#include "core/buffers/flow/floatFlowBuffer.h" +#include "buffers/abstractContiniousBuffer.h" +#include "buffers/flow/element6D.h" +#include "buffers/flow/punchedBufferOperations.h" +#include "buffers/flow/floatFlowBuffer.h" namespace corecvs { diff --git a/core/buffers/focusEstimator.cpp b/core/buffers/focusEstimator.cpp index 9bfca0777..73d87eead 100644 --- a/core/buffers/focusEstimator.cpp +++ b/core/buffers/focusEstimator.cpp @@ -1,6 +1,6 @@ #include // NULL -#include "core/buffers/focusEstimator.h" +#include "buffers/focusEstimator.h" namespace corecvs { diff --git a/core/buffers/g12Buffer.cpp b/core/buffers/g12Buffer.cpp index 509d01548..44901af2a 100644 --- a/core/buffers/g12Buffer.cpp +++ b/core/buffers/g12Buffer.cpp @@ -8,14 +8,14 @@ * \author alexander */ -#include "core/buffers/g12Buffer.h" -#include "core/buffers/commonMappers.h" -#include "core/buffers/kernels/fastkernel/fastKernel.h" -#include "core/buffers/kernels/fastkernel/scalarAlgebra.h" -#include "core/buffers/kernels/fastkernel/vectorAlgebra.h" -#include "core/buffers/kernels/arithmetic.h" -#include "core/buffers/kernels/threshold.h" -#include "core/buffers/kernels/fastkernel/vectorTraits.h" +#include "buffers/g12Buffer.h" +#include "buffers/commonMappers.h" +#include "buffers/kernels/fastkernel/fastKernel.h" +#include "buffers/kernels/fastkernel/scalarAlgebra.h" +#include "buffers/kernels/fastkernel/vectorAlgebra.h" +#include "buffers/kernels/arithmetic.h" +#include "buffers/kernels/threshold.h" +#include "buffers/kernels/fastkernel/vectorTraits.h" //#include "rgb24/hardcodeFont.h" namespace corecvs { diff --git a/core/buffers/g12Buffer.h b/core/buffers/g12Buffer.h index 0810c6450..b69a90a5c 100644 --- a/core/buffers/g12Buffer.h +++ b/core/buffers/g12Buffer.h @@ -10,11 +10,11 @@ */ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractBuffer.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/buffers/fixeddisp/fixedPointBlMapper.h" +#include "buffers/abstractBuffer.h" +#include "buffers/abstractContiniousBuffer.h" +#include "buffers/fixeddisp/fixedPointBlMapper.h" namespace corecvs { diff --git a/core/buffers/g12Buffer3d.cpp b/core/buffers/g12Buffer3d.cpp index b1c302505..d2477b1a0 100644 --- a/core/buffers/g12Buffer3d.cpp +++ b/core/buffers/g12Buffer3d.cpp @@ -1,4 +1,4 @@ -#include "core/buffers/g12Buffer3d.h" +#include "buffers/g12Buffer3d.h" namespace corecvs { SwarmPoint* G12Buffer3d::p0 = NULL; diff --git a/core/buffers/g12Buffer3d.h b/core/buffers/g12Buffer3d.h index d5b167797..8933a8c62 100644 --- a/core/buffers/g12Buffer3d.h +++ b/core/buffers/g12Buffer3d.h @@ -1,11 +1,11 @@ #ifndef G12BUFFER3D_H #define G12BUFFER3D_H -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector3d.h" -#include "core/rectification/triangulator.h" -#include "core/buffers/abstractContiniousBuffer.h" +#include "math/vector/vector3d.h" +#include "rectification/triangulator.h" +#include "buffers/abstractContiniousBuffer.h" namespace corecvs { diff --git a/core/buffers/g8Buffer.cpp b/core/buffers/g8Buffer.cpp index 321811b5b..e7adcea96 100644 --- a/core/buffers/g8Buffer.cpp +++ b/core/buffers/g8Buffer.cpp @@ -7,13 +7,13 @@ * \author alexander */ -#include "core/buffers/g8Buffer.h" -#include "core/buffers/g12Buffer.h" -#include "core/math/sse/sseWrapper.h" +#include "buffers/g8Buffer.h" +#include "buffers/g12Buffer.h" +#include "math/sse/sseWrapper.h" -#include "core/buffers/kernels/fastkernel/vectorTraits.h" -#include "core/buffers/kernels/fastkernel/fastKernel.h" -#include "core/buffers/kernels/arithmetic.h" +#include "buffers/kernels/fastkernel/vectorTraits.h" +#include "buffers/kernels/fastkernel/fastKernel.h" +#include "buffers/kernels/arithmetic.h" namespace corecvs { diff --git a/core/buffers/g8Buffer.h b/core/buffers/g8Buffer.h index 791dcc5b4..aa68eefe8 100644 --- a/core/buffers/g8Buffer.h +++ b/core/buffers/g8Buffer.h @@ -11,9 +11,9 @@ #include -#include "core/buffers/abstractBuffer.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/buffers/g12Buffer.h" +#include "buffers/abstractBuffer.h" +#include "buffers/abstractContiniousBuffer.h" +#include "buffers/g12Buffer.h" namespace corecvs { diff --git a/core/buffers/histogram/histogram.cpp b/core/buffers/histogram/histogram.cpp index c44cb4f71..27a108586 100644 --- a/core/buffers/histogram/histogram.cpp +++ b/core/buffers/histogram/histogram.cpp @@ -7,9 +7,9 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/histogram/histogram.h" +#include "buffers/histogram/histogram.h" namespace corecvs { Histogram::~Histogram() diff --git a/core/buffers/histogram/histogram.h b/core/buffers/histogram/histogram.h index bd2ac03bd..33d3ef712 100644 --- a/core/buffers/histogram/histogram.h +++ b/core/buffers/histogram/histogram.h @@ -13,10 +13,10 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/commonMappers.h" +#include "buffers/g12Buffer.h" +#include "buffers/commonMappers.h" namespace corecvs { using std::vector; diff --git a/core/buffers/integralBuffer.h b/core/buffers/integralBuffer.h index 99504a0a4..8fe1810ba 100644 --- a/core/buffers/integralBuffer.h +++ b/core/buffers/integralBuffer.h @@ -17,18 +17,18 @@ #ifdef WITH_SSE #include #endif -#include "core/math/sse/sseWrapper.h" -#include "core/math/neon/neonWrapper.h" +#include "math/sse/sseWrapper.h" +#include "math/neon/neonWrapper.h" -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractBuffer.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/g8Buffer.h" +#include "buffers/abstractBuffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/g8Buffer.h" -#include "core/tbbwrapper/tbbWrapper.h" +#include "tbbwrapper/tbbWrapper.h" -#include "core/geometry/rectangle.h" +#include "geometry/rectangle.h" namespace corecvs { diff --git a/core/buffers/interpolator.h b/core/buffers/interpolator.h index 47d0b8157..e16fa5fe7 100644 --- a/core/buffers/interpolator.h +++ b/core/buffers/interpolator.h @@ -8,9 +8,9 @@ * \date Jul 6, 2010 * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/g12Buffer.h" +#include "buffers/g12Buffer.h" namespace corecvs { diff --git a/core/buffers/kernels/arithmetic.h b/core/buffers/kernels/arithmetic.h index ee147983f..5004cde77 100644 --- a/core/buffers/kernels/arithmetic.h +++ b/core/buffers/kernels/arithmetic.h @@ -9,8 +9,8 @@ * \author alexander */ -#include "core/buffers/abstractBuffer.h" -#include "core/utils/global.h" +#include "buffers/abstractBuffer.h" +#include "utils/global.h" namespace corecvs { diff --git a/core/buffers/kernels/blurProcessor.cpp b/core/buffers/kernels/blurProcessor.cpp index 284ef6feb..11b0ed556 100644 --- a/core/buffers/kernels/blurProcessor.cpp +++ b/core/buffers/kernels/blurProcessor.cpp @@ -6,11 +6,11 @@ * \date Sep 19, 2010 * \author alexander */ -#include "core/buffers/kernels/blurProcessor.h" -#include "core/tbbwrapper/tbbWrapper.h" +#include "buffers/kernels/blurProcessor.h" +#include "tbbwrapper/tbbWrapper.h" -#include "core/math/sse/sseWrapper.h" -#include "core/math/neon/neonWrapper.h" +#include "math/sse/sseWrapper.h" +#include "math/neon/neonWrapper.h" namespace corecvs { diff --git a/core/buffers/kernels/blurProcessor.h b/core/buffers/kernels/blurProcessor.h index 0cc54ad0c..04e83d760 100644 --- a/core/buffers/kernels/blurProcessor.h +++ b/core/buffers/kernels/blurProcessor.h @@ -9,10 +9,10 @@ #ifndef BLURPROCESSOR_H_ #define BLURPROCESSOR_H_ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/integralBuffer.h" -#include "core/buffers/g12Buffer.h" +#include "buffers/integralBuffer.h" +#include "buffers/g12Buffer.h" namespace corecvs { diff --git a/core/buffers/kernels/copyKernel.h b/core/buffers/kernels/copyKernel.h index 59057c4ab..b2aa48ac2 100644 --- a/core/buffers/kernels/copyKernel.h +++ b/core/buffers/kernels/copyKernel.h @@ -11,9 +11,9 @@ #ifndef COPYKERNEL_H_ #define COPYKERNEL_H_ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractKernel.h" +#include "buffers/abstractKernel.h" namespace corecvs { diff --git a/core/buffers/kernels/fastconverter/fastConverter.h b/core/buffers/kernels/fastconverter/fastConverter.h index 45b13f666..26a029139 100644 --- a/core/buffers/kernels/fastconverter/fastConverter.h +++ b/core/buffers/kernels/fastconverter/fastConverter.h @@ -10,11 +10,11 @@ #ifndef FASTKERNEL_H_ #define FASTKERNEL_H_ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/kernels/fastkernel/baseKernel.h" -#include "core/buffers/kernels/fastkernel/scalarAlgebra.h" -#include "core/tbbwrapper/tbbWrapper.h" +#include "buffers/kernels/fastkernel/baseKernel.h" +#include "buffers/kernels/fastkernel/scalarAlgebra.h" +#include "tbbwrapper/tbbWrapper.h" namespace corecvs { diff --git a/core/buffers/kernels/fastkernel/baseAlgebra.h b/core/buffers/kernels/fastkernel/baseAlgebra.h index 122b44b54..46f950f8b 100644 --- a/core/buffers/kernels/fastkernel/baseAlgebra.h +++ b/core/buffers/kernels/fastkernel/baseAlgebra.h @@ -9,7 +9,7 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { /** diff --git a/core/buffers/kernels/fastkernel/baseKernel.h b/core/buffers/kernels/fastkernel/baseKernel.h index ef9c3302c..7bf76a84d 100644 --- a/core/buffers/kernels/fastkernel/baseKernel.h +++ b/core/buffers/kernels/fastkernel/baseKernel.h @@ -9,7 +9,7 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { diff --git a/core/buffers/kernels/fastkernel/fastKernel.h b/core/buffers/kernels/fastkernel/fastKernel.h index ac8785b43..2be1c5812 100644 --- a/core/buffers/kernels/fastkernel/fastKernel.h +++ b/core/buffers/kernels/fastkernel/fastKernel.h @@ -7,11 +7,11 @@ * \date Sep 26, 2010 * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/kernels/fastkernel/baseKernel.h" -#include "core/buffers/kernels/fastkernel/scalarAlgebra.h" -#include "core/tbbwrapper/tbbWrapper.h" +#include "buffers/kernels/fastkernel/baseKernel.h" +#include "buffers/kernels/fastkernel/scalarAlgebra.h" +#include "tbbwrapper/tbbWrapper.h" namespace corecvs { diff --git a/core/buffers/kernels/fastkernel/readers.h b/core/buffers/kernels/fastkernel/readers.h index 6dee24b35..0612010cd 100644 --- a/core/buffers/kernels/fastkernel/readers.h +++ b/core/buffers/kernels/fastkernel/readers.h @@ -12,8 +12,8 @@ #include -#include "core/math/sse/sseWrapper.h" -#include "core/math/vector/fixedVector.h" +#include "math/sse/sseWrapper.h" +#include "math/vector/fixedVector.h" namespace corecvs { diff --git a/core/buffers/kernels/fastkernel/scalarAlgebra.h b/core/buffers/kernels/fastkernel/scalarAlgebra.h index 4bc75210b..3fc1e5c6f 100644 --- a/core/buffers/kernels/fastkernel/scalarAlgebra.h +++ b/core/buffers/kernels/fastkernel/scalarAlgebra.h @@ -9,10 +9,10 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/kernels/fastkernel/baseAlgebra.h" -#include "core/math/generic/genericMath.h" +#include "buffers/kernels/fastkernel/baseAlgebra.h" +#include "math/generic/genericMath.h" #ifdef TRACE_SCALAR_ALGEBRA #define DOTRACE_ALG(X) SYNC_PRINT(X) diff --git a/core/buffers/kernels/fastkernel/vectorAlgebra.h b/core/buffers/kernels/fastkernel/vectorAlgebra.h index e268dd4f9..17d75507b 100644 --- a/core/buffers/kernels/fastkernel/vectorAlgebra.h +++ b/core/buffers/kernels/fastkernel/vectorAlgebra.h @@ -9,13 +9,13 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/kernels/fastkernel/baseAlgebra.h" -#include "core/buffers/kernels/fastkernel/scalarAlgebra.h" +#include "buffers/kernels/fastkernel/baseAlgebra.h" +#include "buffers/kernels/fastkernel/scalarAlgebra.h" #ifdef WITH_SSE -#include "core/math/sse/sseWrapper.h" +#include "math/sse/sseWrapper.h" #endif namespace corecvs { diff --git a/core/buffers/kernels/fastkernel/vectorTraits.h b/core/buffers/kernels/fastkernel/vectorTraits.h index c450a97ed..6c9c8dca6 100644 --- a/core/buffers/kernels/fastkernel/vectorTraits.h +++ b/core/buffers/kernels/fastkernel/vectorTraits.h @@ -3,9 +3,9 @@ #include -#include "core/utils/global.h" -#include "core/math/sse/sseWrapper.h" -#include "core/buffers/kernels/fastkernel/vectorAlgebra.h" +#include "utils/global.h" +#include "math/sse/sseWrapper.h" +#include "buffers/kernels/fastkernel/vectorAlgebra.h" namespace corecvs { diff --git a/core/buffers/kernels/gaussian.cpp b/core/buffers/kernels/gaussian.cpp index b2347328c..d0c41bf14 100644 --- a/core/buffers/kernels/gaussian.cpp +++ b/core/buffers/kernels/gaussian.cpp @@ -8,9 +8,9 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/kernels/gaussian.h" +#include "buffers/kernels/gaussian.h" namespace corecvs { uint32_t Gaussian3x3int::data[9] = { diff --git a/core/buffers/kernels/gaussian.h b/core/buffers/kernels/gaussian.h index b4cd0b2ef..4a1fc346b 100644 --- a/core/buffers/kernels/gaussian.h +++ b/core/buffers/kernels/gaussian.h @@ -12,9 +12,9 @@ */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractKernel.h" +#include "buffers/abstractKernel.h" namespace corecvs { diff --git a/core/buffers/kernels/genericFastKernel.h b/core/buffers/kernels/genericFastKernel.h index d31598628..52fa6c25d 100644 --- a/core/buffers/kernels/genericFastKernel.h +++ b/core/buffers/kernels/genericFastKernel.h @@ -8,9 +8,9 @@ * \date Sep 26, 2010 * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/kernels/fastkernel/fastKernel.h" +#include "buffers/kernels/fastkernel/fastKernel.h" namespace corecvs { template diff --git a/core/buffers/kernels/laplace.h b/core/buffers/kernels/laplace.h index 65231728c..be2d0883e 100644 --- a/core/buffers/kernels/laplace.h +++ b/core/buffers/kernels/laplace.h @@ -1,7 +1,7 @@ #ifndef LAPLACE_H #define LAPLACE_H -#include "core/buffers/abstractKernel.h" +#include "buffers/abstractKernel.h" namespace corecvs { diff --git a/core/buffers/kernels/logicKernels.cpp b/core/buffers/kernels/logicKernels.cpp index da72d42eb..eb5d7803f 100644 --- a/core/buffers/kernels/logicKernels.cpp +++ b/core/buffers/kernels/logicKernels.cpp @@ -4,7 +4,7 @@ * \date Sep 24, 2013 **/ -#include "core/buffers/kernels/logicKernels.h" +#include "buffers/kernels/logicKernels.h" namespace corecvs { diff --git a/core/buffers/kernels/sobel.cpp b/core/buffers/kernels/sobel.cpp index c0e4fa41c..bde9c7c85 100644 --- a/core/buffers/kernels/sobel.cpp +++ b/core/buffers/kernels/sobel.cpp @@ -8,9 +8,9 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/kernels/sobel.h" +#include "buffers/kernels/sobel.h" namespace corecvs { diff --git a/core/buffers/kernels/sobel.h b/core/buffers/kernels/sobel.h index b330ad327..c3ab49b0e 100644 --- a/core/buffers/kernels/sobel.h +++ b/core/buffers/kernels/sobel.h @@ -11,9 +11,9 @@ #ifndef SOBEL_H_ #define SOBEL_H_ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractKernel.h" +#include "buffers/abstractKernel.h" namespace corecvs { diff --git a/core/buffers/kernels/spatialGradient.cpp b/core/buffers/kernels/spatialGradient.cpp index 0e738cb3c..7ac1bb2de 100644 --- a/core/buffers/kernels/spatialGradient.cpp +++ b/core/buffers/kernels/spatialGradient.cpp @@ -7,13 +7,13 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/kernels/spatialGradient.h" -#include "core/buffers/kernels/fastkernel/fastKernel.h" -#include "core/buffers/kernels/fastkernel/scalarAlgebra.h" -#include "core/buffers/kernels/gaussian.h" -#include "core/buffers/kernels/fastkernel/vectorTraits.h" +#include "buffers/kernels/spatialGradient.h" +#include "buffers/kernels/fastkernel/fastKernel.h" +#include "buffers/kernels/fastkernel/scalarAlgebra.h" +#include "buffers/kernels/gaussian.h" +#include "buffers/kernels/fastkernel/vectorTraits.h" namespace corecvs { diff --git a/core/buffers/kernels/spatialGradient.h b/core/buffers/kernels/spatialGradient.h index eb3e01b15..6d63bf5c6 100644 --- a/core/buffers/kernels/spatialGradient.h +++ b/core/buffers/kernels/spatialGradient.h @@ -10,14 +10,14 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/abstractBuffer.h" -#include "core/math/vector/vector3d.h" -#include "core/buffers/integralBuffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/abstractBuffer.h" +#include "math/vector/vector3d.h" +#include "buffers/integralBuffer.h" -#include "core/buffers/kernels/fastkernel/vectorTraits.h" +#include "buffers/kernels/fastkernel/vectorTraits.h" namespace corecvs { diff --git a/core/buffers/kernels/threshold.cpp b/core/buffers/kernels/threshold.cpp index 7c0c46608..938175461 100644 --- a/core/buffers/kernels/threshold.cpp +++ b/core/buffers/kernels/threshold.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/buffers/kernels/threshold.h" +#include "buffers/kernels/threshold.h" namespace corecvs { diff --git a/core/buffers/memory/memoryBlock.cpp b/core/buffers/memory/memoryBlock.cpp index 7e68f4e5f..d6e733eef 100644 --- a/core/buffers/memory/memoryBlock.cpp +++ b/core/buffers/memory/memoryBlock.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/buffers/memory/memoryBlock.h" +#include "buffers/memory/memoryBlock.h" namespace corecvs { } //namespace corecvs diff --git a/core/buffers/memory/memoryBlock.h b/core/buffers/memory/memoryBlock.h index bac6d12c8..a8cca5986 100644 --- a/core/buffers/memory/memoryBlock.h +++ b/core/buffers/memory/memoryBlock.h @@ -11,9 +11,9 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/utils/atomicOps.h" +#include "utils/atomicOps.h" namespace corecvs { diff --git a/core/buffers/mipmapPyramid.cpp b/core/buffers/mipmapPyramid.cpp index 22dd3d634..69afb9724 100644 --- a/core/buffers/mipmapPyramid.cpp +++ b/core/buffers/mipmapPyramid.cpp @@ -8,8 +8,8 @@ * \author alexander */ -#include "core/utils/global.h" -#include "core/buffers/mipmapPyramid.h" +#include "utils/global.h" +#include "buffers/mipmapPyramid.h" namespace corecvs { diff --git a/core/buffers/mipmapPyramid.h b/core/buffers/mipmapPyramid.h index a28115b4a..6c5bd9bc6 100644 --- a/core/buffers/mipmapPyramid.h +++ b/core/buffers/mipmapPyramid.h @@ -12,10 +12,10 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractBuffer.h" -#include "core/buffers/kernels/gaussian.h" +#include "buffers/abstractBuffer.h" +#include "buffers/kernels/gaussian.h" namespace corecvs { diff --git a/core/buffers/morphological/morphological.cpp b/core/buffers/morphological/morphological.cpp index b927c31fb..cf3542dba 100644 --- a/core/buffers/morphological/morphological.cpp +++ b/core/buffers/morphological/morphological.cpp @@ -6,10 +6,10 @@ * \author alexander */ -#include "core/buffers/morphological/morphological.h" -#include "core/buffers/kernels/fastkernel/fastKernel.h" -#include "core/buffers/kernels/fastkernel/vectorAlgebra.h" -#include "core/buffers/kernels/fastkernel/vectorTraits.h" +#include "buffers/morphological/morphological.h" +#include "buffers/kernels/fastkernel/fastKernel.h" +#include "buffers/kernels/fastkernel/vectorAlgebra.h" +#include "buffers/kernels/fastkernel/vectorTraits.h" namespace corecvs { /** diff --git a/core/buffers/morphological/morphological.h b/core/buffers/morphological/morphological.h index e757e80ad..ccf7192f4 100644 --- a/core/buffers/morphological/morphological.h +++ b/core/buffers/morphological/morphological.h @@ -11,8 +11,8 @@ */ -#include "core/buffers/g12Buffer.h" -#include "core/buffers/g8Buffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/g8Buffer.h" namespace corecvs { diff --git a/core/buffers/nonMaximalSuperssor.cpp b/core/buffers/nonMaximalSuperssor.cpp index 52ca3e3ba..38c791770 100644 --- a/core/buffers/nonMaximalSuperssor.cpp +++ b/core/buffers/nonMaximalSuperssor.cpp @@ -1,5 +1,5 @@ -#include "core/buffers/nonMaximalSuperssor.h" -#include "core/buffers/convolver/convolver.h" +#include "buffers/nonMaximalSuperssor.h" +#include "buffers/convolver/convolver.h" namespace corecvs { diff --git a/core/buffers/nonMaximalSuperssor.h b/core/buffers/nonMaximalSuperssor.h index ecc6b5783..042c258e7 100644 --- a/core/buffers/nonMaximalSuperssor.h +++ b/core/buffers/nonMaximalSuperssor.h @@ -1,7 +1,7 @@ #ifndef NONMAXIMALSUPERSSOR_H #define NONMAXIMALSUPERSSOR_H -#include "core/math/vector/vector2d.h" +#include "math/vector/vector2d.h" namespace corecvs { diff --git a/core/buffers/remapBuffer.cpp b/core/buffers/remapBuffer.cpp index 278551a39..61fd64ecd 100644 --- a/core/buffers/remapBuffer.cpp +++ b/core/buffers/remapBuffer.cpp @@ -7,7 +7,7 @@ * \ingroup cppcorefiles * \date Mar 18, 2018 */ -#include "core/buffers/remapBuffer.h" +#include "buffers/remapBuffer.h" namespace corecvs { diff --git a/core/buffers/remapBuffer.h b/core/buffers/remapBuffer.h index 151d26e31..f4d21d013 100644 --- a/core/buffers/remapBuffer.h +++ b/core/buffers/remapBuffer.h @@ -3,18 +3,18 @@ #include -#include "core/utils/global.h" - -#include "core/math/mathUtils.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/buffers/g12Buffer.h" -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix33.h" -#include "core/tbbwrapper/tbbWrapper.h" -#include "core/alignment/radialCorrection.h" -#include "core/alignment/distortionCorrectTransform.h" -#include "core/alignment/lensDistortionModelParameters.h" -#include "../math/levenmarq.h" +#include "utils/global.h" + +#include "math/mathUtils.h" +#include "buffers/abstractContiniousBuffer.h" +#include "buffers/g12Buffer.h" +#include "math/vector/vector2d.h" +#include "math/matrix/matrix33.h" +#include "tbbwrapper/tbbWrapper.h" +#include "alignment/radialCorrection.h" +#include "alignment/distortionCorrectTransform.h" +#include "alignment/lensDistortionModelParameters.h" +#include "math/levenmarq.h" namespace corecvs { diff --git a/core/buffers/rgb24/abstractPainter.cpp b/core/buffers/rgb24/abstractPainter.cpp index f2e06bd36..176edf428 100644 --- a/core/buffers/rgb24/abstractPainter.cpp +++ b/core/buffers/rgb24/abstractPainter.cpp @@ -4,7 +4,7 @@ * \date Nov 22, 2012 **/ -#include "core/buffers/rgb24/abstractPainter.h" +#include "buffers/rgb24/abstractPainter.h" namespace corecvs { diff --git a/core/buffers/rgb24/abstractPainter.h b/core/buffers/rgb24/abstractPainter.h index a2d6bbad5..ab0f77a43 100644 --- a/core/buffers/rgb24/abstractPainter.h +++ b/core/buffers/rgb24/abstractPainter.h @@ -9,16 +9,16 @@ #include #include -#include "core/stats/graphData.h" +#include "stats/graphData.h" -#include "core/utils/global.h" -#include "core/buffers/rgb24/hardcodeFont.h" -#include "core/buffers/rgb24/hersheyVectorFont.h" -#include "core/buffers/rgb24/rgbColor.h" -#include "core/geometry/polygons.h" -#include "core/geometry/conic.h" -#include "core/geometry/line.h" -#include "core/geometry/ellipse.h" +#include "utils/global.h" +#include "buffers/rgb24/hardcodeFont.h" +#include "buffers/rgb24/hersheyVectorFont.h" +#include "buffers/rgb24/rgbColor.h" +#include "geometry/polygons.h" +#include "geometry/conic.h" +#include "geometry/line.h" +#include "geometry/ellipse.h" namespace corecvs { @@ -124,16 +124,27 @@ class AbstractPainter uint16_t codepoint = ((theChar & 0x1F00) >> 2) | (theChar & 0x003F); - if (codepoint >=u'а' && codepoint <= u'я') +#ifdef WIN32 + if (codepoint >=u"а" && codepoint <= u"я") + char_ptr = HardcodeFont::cyrilic_glyphs + HardcodeFont::GLYPH_HEIGHT * (codepoint - u"а"); + if (codepoint >=u"А" && codepoint <= u"Я") + char_ptr = HardcodeFont::cyrilic_glyphs + HardcodeFont::GLYPH_HEIGHT * (codepoint - u"а"); +#else + if (codepoint >= u'а' && codepoint <= u'я') char_ptr = HardcodeFont::cyrilic_glyphs + HardcodeFont::GLYPH_HEIGHT * (codepoint - u'а'); - if (codepoint >=u'А' && codepoint <= u'Я') + if (codepoint >= u'А' && codepoint <= u'Я') char_ptr = HardcodeFont::cyrilic_glyphs + HardcodeFont::GLYPH_HEIGHT * (codepoint - u'а'); +#endif if (char_ptr == NULL) { printf("No symbol for %04X %04X %04X | %04X %04X\n", theChar, (theChar & 0x1F3F), - ((theChar & 0x1F00) >> 2) | (theChar & 0x003F), u'а', u'я'); +#ifdef WIN32 + ((theChar & 0x1F00) >> 2) | (theChar & 0x003F), u"а", u"я"); +#else + ((theChar & 0x1F00) >> 2) | (theChar & 0x003F), u'а', u'я'); +#endif return; } @@ -497,10 +508,67 @@ class AbstractPainter Vector2dd middle = ray.getPoint((t1+t2) / 2.0); mTarget->drawLine(middle, middle + line.normal().normalised() * drawNormal, color); } + } + + /** + * Off screen canvas graph draw + * This could be merged with GraphPlot dialog. + * + * If you want some fancy draw use 3rd party libraries. This is for a most basic drawing + * + **/ + void drawGraphGrid(const GraphData &data, bool gridX, double gainX, bool gridY, double gainY) + { + unsigned i; + unsigned lineNumber; + unsigned w = mTarget->getW(); + unsigned h = mTarget->getH(); + + if (gridX) { + while (gainX > 100) { + gainX /= 10; + } + + while (gainX < 10) { + gainX *= 10; + } + unsigned stepX = gainX * 2; + + lineNumber = w / stepX; + + for (i = 0; i < lineNumber; i++) { + if (stepX > 50) { + mTarget->drawLine(i * stepX + stepX / 2, 0, i * stepX + stepX / 2, h - 1, RGBColor::Green()); + } + mTarget->drawLine((i + 1) * stepX, 0, (i + 1) * stepX, h - 1, RGBColor::Green() / 2); + } + } + if (gridY && gainY > 0.005) { + + while (gainY > 100) { + gainY /= 10; + } + + while (gainY < 10) { + gainY *= 10; + } + unsigned stepY = gainY * 2; + + lineNumber = w / stepY; + for (i = 0; i < h / 2; i += stepY) { + if (stepY > 50) { + mTarget->drawLine(0, h / 2 + i + stepY / 2, w - 1, h / 2 + i + stepY / 2, RGBColor::Yellow()); + mTarget->drawLine(0, h / 2 - i - stepY / 2, w - 1, h / 2 - i - stepY / 2, RGBColor::Yellow()); + } + mTarget->drawLine(0, h / 2 + i + stepY, w - 1, h / 2 + i + stepY, RGBColor::Yellow() / 2); + mTarget->drawLine(0, h / 2 - i - stepY, w - 1, h / 2 - i - stepY, RGBColor::Yellow() / 2); + } + } } void drawGraph(const GraphData &data) { + } virtual ~AbstractPainter() {} diff --git a/core/buffers/rgb24/bezierRasterizer.cpp b/core/buffers/rgb24/bezierRasterizer.cpp index 133cd8cd2..24df7f87a 100644 --- a/core/buffers/rgb24/bezierRasterizer.cpp +++ b/core/buffers/rgb24/bezierRasterizer.cpp @@ -1,3 +1,3 @@ -#include "core/buffers/rgb24/bezierRasterizer.h" +#include "buffers/rgb24/bezierRasterizer.h" diff --git a/core/buffers/rgb24/bezierRasterizer.h b/core/buffers/rgb24/bezierRasterizer.h index 2f3002808..d0f5b65d6 100644 --- a/core/buffers/rgb24/bezierRasterizer.h +++ b/core/buffers/rgb24/bezierRasterizer.h @@ -1,7 +1,7 @@ #ifndef BEZIERRASTERIZER_H #define BEZIERRASTERIZER_H -#include "core/math/vector/vector2d.h" +#include "math/vector/vector2d.h" #include #include diff --git a/core/buffers/rgb24/bresenhamRasterizer.cpp b/core/buffers/rgb24/bresenhamRasterizer.cpp index 9ea472c15..5eebc2b04 100644 --- a/core/buffers/rgb24/bresenhamRasterizer.cpp +++ b/core/buffers/rgb24/bresenhamRasterizer.cpp @@ -1,4 +1,4 @@ -#include "core/buffers/rgb24/bresenhamRasterizer.h" +#include "buffers/rgb24/bresenhamRasterizer.h" BresenhamRasterizer::BresenhamRasterizer() { diff --git a/core/buffers/rgb24/hardcodeFont.cpp b/core/buffers/rgb24/hardcodeFont.cpp index db2948ed2..424008deb 100644 --- a/core/buffers/rgb24/hardcodeFont.cpp +++ b/core/buffers/rgb24/hardcodeFont.cpp @@ -7,9 +7,9 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/rgb24/hardcodeFont.h" +#include "buffers/rgb24/hardcodeFont.h" namespace corecvs { diff --git a/core/buffers/rgb24/hardcodeFont.h b/core/buffers/rgb24/hardcodeFont.h index 9466eac10..c054e8874 100644 --- a/core/buffers/rgb24/hardcodeFont.h +++ b/core/buffers/rgb24/hardcodeFont.h @@ -11,7 +11,7 @@ #define HARDCODEFONT_H_ #include -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { diff --git a/core/buffers/rgb24/hersheyVectorFont.cpp b/core/buffers/rgb24/hersheyVectorFont.cpp index ba5296bc0..5c243ee99 100644 --- a/core/buffers/rgb24/hersheyVectorFont.cpp +++ b/core/buffers/rgb24/hersheyVectorFont.cpp @@ -4,7 +4,7 @@ * \date Dec 8, 2012 **/ -#include "core/buffers/rgb24/hersheyVectorFont.h" +#include "buffers/rgb24/hersheyVectorFont.h" namespace corecvs { diff --git a/core/buffers/rgb24/lineSpan.cpp b/core/buffers/rgb24/lineSpan.cpp index 5646bea92..9462bf31a 100644 --- a/core/buffers/rgb24/lineSpan.cpp +++ b/core/buffers/rgb24/lineSpan.cpp @@ -1,2 +1,2 @@ -#include "core/buffers/rgb24/lineSpan.h" +#include "buffers/rgb24/lineSpan.h" diff --git a/core/buffers/rgb24/lineSpan.h b/core/buffers/rgb24/lineSpan.h index f2132d1da..4aabf0336 100644 --- a/core/buffers/rgb24/lineSpan.h +++ b/core/buffers/rgb24/lineSpan.h @@ -5,8 +5,8 @@ #include #include -#include "core/math/vector/vector2d.h" -#include "core/geometry/line.h" +#include "math/vector/vector2d.h" +#include "geometry/line.h" namespace corecvs { diff --git a/core/buffers/rgb24/rgb24Buffer.cpp b/core/buffers/rgb24/rgb24Buffer.cpp index 960618fa3..3f5195b18 100644 --- a/core/buffers/rgb24/rgb24Buffer.cpp +++ b/core/buffers/rgb24/rgb24Buffer.cpp @@ -6,15 +6,15 @@ * \date Mar 1, 2010 * \author alexander */ -#include "core/utils/global.h" - -#include "core/geometry/rectangle.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/rgb24/hardcodeFont.h" -#include "core/buffers/kernels/fastkernel/readers.h" -#include "core/math/vector/fixedVector.h" -#include "core/buffers/rgb24/bresenhamRasterizer.h" -#include "core/buffers/rgb24/wuRasterizer.h" +#include "utils/global.h" + +#include "geometry/rectangle.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/hardcodeFont.h" +#include "buffers/kernels/fastkernel/readers.h" +#include "math/vector/fixedVector.h" +#include "buffers/rgb24/bresenhamRasterizer.h" +#include "buffers/rgb24/wuRasterizer.h" #include "abstractPainter.h" @@ -898,7 +898,7 @@ void RGB24Buffer::drawContinuousBuffer(const AbstractBuffer &in, { for (int j = 0; j < mw; j++) { - if (std::isnan(in.element(i,j))) { + if (std::isnan(float(in.element(i,j)))) { continue; } element(i, j) = RGBColor::colorCode(lerp(0.0, 1.0, in.element(i,j), min, max), pallete); @@ -912,7 +912,7 @@ void RGB24Buffer::drawContinuousBuffer(const AbstractBuffer &in, { for (int j = 0; j < mw; j++) { - if (std::isnan(in.element(i,j))) { + if (std::isnan(float(in.element(i,j)))) { continue; } if (in.element(i,j) != std::numeric_limits::max()) { @@ -931,7 +931,7 @@ void RGB24Buffer::drawContinuousBuffer(const AbstractBuffer &in, for (int j = 0; j < mw; j++) { ContinuousType v = in.element(i,j); - if (std::isnan(v)) { + if (std::isnan(float(v))) { continue; } v = clamp(v, 0, 1) * 255; @@ -947,7 +947,7 @@ void RGB24Buffer::drawContinuousBuffer(const AbstractBuffer &in, for (int j = 0; j < mw; j++) { ContinuousType v = in.element(i,j); - if (std::isnan(v)) { + if (std::isnan(float(v))) { continue; } v = clamp(v, 0, 255); diff --git a/core/buffers/rgb24/rgb24Buffer.h b/core/buffers/rgb24/rgb24Buffer.h index 0348fd4ce..f1eafe1fc 100644 --- a/core/buffers/rgb24/rgb24Buffer.h +++ b/core/buffers/rgb24/rgb24Buffer.h @@ -11,24 +11,24 @@ #include -#include "core/utils/global.h" - -#include "core/buffers/fixeddisp/fixedPointBlMapper.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/g8Buffer.h" -#include "core/buffers/flow/flowBuffer.h" -#include "core/buffers/histogram/histogram.h" -#include "core/geometry/rectangle.h" -#include "core/geometry/polygons.h" -#include "core/buffers/rgb24/rgbColor.h" -#include "core/function/function.h" -#include "core/buffers/correspondenceList.h" -#include "core/xml/generated/imageChannel.h" - -#include "core/geometry/conic.h" - -#include "core/buffers/kernels/fastkernel/readers.h" +#include "utils/global.h" + +#include "buffers/fixeddisp/fixedPointBlMapper.h" +#include "buffers/abstractContiniousBuffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/g8Buffer.h" +#include "buffers/flow/flowBuffer.h" +#include "buffers/histogram/histogram.h" +#include "geometry/rectangle.h" +#include "geometry/polygons.h" +#include "buffers/rgb24/rgbColor.h" +#include "function/function.h" +#include "buffers/correspondenceList.h" +#include "xml/generated/imageChannel.h" + +#include "geometry/conic.h" + +#include "buffers/kernels/fastkernel/readers.h" namespace corecvs { diff --git a/core/buffers/rgb24/rgbColor.cpp b/core/buffers/rgb24/rgbColor.cpp index 527d21e3e..97c26ce5d 100644 --- a/core/buffers/rgb24/rgbColor.cpp +++ b/core/buffers/rgb24/rgbColor.cpp @@ -5,8 +5,8 @@ * \date Dec 4, 2011 * \author alexander */ -#include "core/utils/global.h" -#include "core/buffers/rgb24/rgbColor.h" +#include "utils/global.h" +#include "buffers/rgb24/rgbColor.h" namespace corecvs { diff --git a/core/buffers/rgb24/rgbColor.h b/core/buffers/rgb24/rgbColor.h index 9f2eaa7c4..6053771cf 100644 --- a/core/buffers/rgb24/rgbColor.h +++ b/core/buffers/rgb24/rgbColor.h @@ -10,13 +10,13 @@ #include #include -#include "core/math/vector/fixedVector.h" -#include "core/math/vector/vector3d.h" -#include "core/math/mathUtils.h" -#include "core/reflection/reflection.h" +#include "math/vector/fixedVector.h" +#include "math/vector/vector3d.h" +#include "math/mathUtils.h" +#include "reflection/reflection.h" -#include "core/xml/generated/rgbColorParameters.h" -#include "core/xml/generated/colorPallete.h" +#include "xml/generated/rgbColorParameters.h" +#include "xml/generated/colorPallete.h" namespace corecvs { diff --git a/core/buffers/rgb24/rgbTBuffer.h b/core/buffers/rgb24/rgbTBuffer.h index 2b739e109..c83d874e9 100644 --- a/core/buffers/rgb24/rgbTBuffer.h +++ b/core/buffers/rgb24/rgbTBuffer.h @@ -1,5 +1,5 @@ /** -* \file core/buffers/rgb24/rgbTBuffer.h +* \file buffers/rgb24/rgbTBuffer.h * * Declares the RGB buffer template class. * @@ -13,24 +13,24 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/fixeddisp/fixedPointBlMapper.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/g8Buffer.h" -#include "core/buffers/flow/flowBuffer.h" -#include "core/buffers/histogram/histogram.h" -#include "core/geometry/rectangle.h" -#include "core/buffers/rgb24/rgbTColor.h" -#include "core/function/function.h" -#include "core/buffers/correspondenceList.h" -#include "core/xml/generated/imageChannel.h" +#include "buffers/fixeddisp/fixedPointBlMapper.h" +#include "buffers/abstractContiniousBuffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/g8Buffer.h" +#include "buffers/flow/flowBuffer.h" +#include "buffers/histogram/histogram.h" +#include "geometry/rectangle.h" +#include "buffers/rgb24/rgbTColor.h" +#include "function/function.h" +#include "buffers/correspondenceList.h" +#include "xml/generated/imageChannel.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/geometry/conic.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "geometry/conic.h" -#include "core/buffers/kernels/fastkernel/readers.h" +#include "buffers/kernels/fastkernel/readers.h" namespace corecvs { diff --git a/core/buffers/rgb24/rgbTColor.h b/core/buffers/rgb24/rgbTColor.h index 7a680d40b..ed1d82b36 100644 --- a/core/buffers/rgb24/rgbTColor.h +++ b/core/buffers/rgb24/rgbTColor.h @@ -11,11 +11,11 @@ #include -#include "core/math/vector/fixedVector.h" -#include "core/math/vector/vector3d.h" -#include "core/math/mathUtils.h" +#include "math/vector/fixedVector.h" +#include "math/vector/vector3d.h" +#include "math/mathUtils.h" -#include "core/xml/generated/rgbColorParameters.h" +#include "xml/generated/rgbColorParameters.h" namespace corecvs { diff --git a/core/buffers/rgb24/wuRasterizer.cpp b/core/buffers/rgb24/wuRasterizer.cpp index 714f28895..29f5f033a 100644 --- a/core/buffers/rgb24/wuRasterizer.cpp +++ b/core/buffers/rgb24/wuRasterizer.cpp @@ -1,3 +1,3 @@ -#include "core/buffers/rgb24/wuRasterizer.h" +#include "buffers/rgb24/wuRasterizer.h" WuRasterizer::WuRasterizer() { } diff --git a/core/buffers/rgb24/wuRasterizer.h b/core/buffers/rgb24/wuRasterizer.h index ac00a8b56..1f633b76d 100644 --- a/core/buffers/rgb24/wuRasterizer.h +++ b/core/buffers/rgb24/wuRasterizer.h @@ -8,7 +8,7 @@ #include #include -#include "core/math/mathUtils.h" +#include "math/mathUtils.h" class WuRasterizer { // integer part of x diff --git a/core/buffers/runtimeTypeBuffer.cpp b/core/buffers/runtimeTypeBuffer.cpp index 5a70592c8..4575ed8f4 100644 --- a/core/buffers/runtimeTypeBuffer.cpp +++ b/core/buffers/runtimeTypeBuffer.cpp @@ -1,4 +1,4 @@ -#include "core/buffers/runtimeTypeBuffer.h" +#include "buffers/runtimeTypeBuffer.h" #include @@ -215,9 +215,9 @@ std::ostream& operator<<(std::ostream &os, const corecvs::RuntimeTypeBuffer &b) return os; } -#include "core/buffers/g12Buffer.h" -#include "core/buffers/g8Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/g8Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" namespace corecvs { diff --git a/core/buffers/runtimeTypeBuffer.h b/core/buffers/runtimeTypeBuffer.h index 28362c95c..ec5cc1f71 100644 --- a/core/buffers/runtimeTypeBuffer.h +++ b/core/buffers/runtimeTypeBuffer.h @@ -1,7 +1,7 @@ #ifndef RUNTIMETYPEBUFFER_H #define RUNTIMETYPEBUFFER_H -#include "core/utils/global.h" +#include "utils/global.h" #include #include diff --git a/core/buffers/transformationCache.cpp b/core/buffers/transformationCache.cpp index 0fa00ac41..038b183a5 100644 --- a/core/buffers/transformationCache.cpp +++ b/core/buffers/transformationCache.cpp @@ -1,4 +1,4 @@ -#include "core/buffers/transformationCache.h" +#include "buffers/transformationCache.h" namespace corecvs { diff --git a/core/buffers/transformationCache.h b/core/buffers/transformationCache.h index a69c97531..bd0b4a42a 100644 --- a/core/buffers/transformationCache.h +++ b/core/buffers/transformationCache.h @@ -1,7 +1,7 @@ #pragma once -#include "core/buffers/displacementBuffer.h" -#include "core/xml/generated/interpolationType.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "buffers/displacementBuffer.h" +#include "xml/generated/interpolationType.h" +#include "buffers/rgb24/rgb24Buffer.h" namespace corecvs { diff --git a/core/buffers/voxels/slicedSpace.h b/core/buffers/voxels/slicedSpace.h index 1631d595d..85e51e715 100644 --- a/core/buffers/voxels/slicedSpace.h +++ b/core/buffers/voxels/slicedSpace.h @@ -9,7 +9,7 @@ #ifndef SLICEDSPACE_H_ #define SLICEDSPACE_H_ -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { class SlicedSpace diff --git a/core/buffers/voxels/voxelBuffer.h b/core/buffers/voxels/voxelBuffer.h index 77215d264..539332f5b 100644 --- a/core/buffers/voxels/voxelBuffer.h +++ b/core/buffers/voxels/voxelBuffer.h @@ -11,10 +11,10 @@ #include -#include "core/utils/global.h" -#include "core/buffers/memory/memoryBlock.h" -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" +#include "utils/global.h" +#include "buffers/memory/memoryBlock.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" namespace corecvs { diff --git a/core/cameracalibration/CMakeLists.txt b/core/cameracalibration/CMakeLists.txt index 80e464cf5..fff2de4ab 100644 --- a/core/cameracalibration/CMakeLists.txt +++ b/core/cameracalibration/CMakeLists.txt @@ -1,5 +1,4 @@ -target_sources(corecvs - PUBLIC +set(CAMERACALIBRATION_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/flatPatternCalibrator.h ${CMAKE_CURRENT_LIST_DIR}/calibrationLocation.h ${CMAKE_CURRENT_LIST_DIR}/cameraConstraints.h @@ -13,9 +12,10 @@ target_sources(corecvs ${CMAKE_CURRENT_LIST_DIR}/projection/projectionFactory.h ${CMAKE_CURRENT_LIST_DIR}/ilFormat.h ${CMAKE_CURRENT_LIST_DIR}/projection/omnidirectionalProjection.h + PARENT_SCOPE + ) - - PRIVATE +set(CAMERACALIBRATION_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/calibrationLocation.cpp ${CMAKE_CURRENT_LIST_DIR}/flatPatternCalibrator.cpp ${CMAKE_CURRENT_LIST_DIR}/cameraConstraints.cpp @@ -29,5 +29,5 @@ target_sources(corecvs ${CMAKE_CURRENT_LIST_DIR}/projection/projectionFactory.cpp ${CMAKE_CURRENT_LIST_DIR}/ilFormat.cpp ${CMAKE_CURRENT_LIST_DIR}/projection/omnidirectionalProjection.cpp - - ) + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/cameracalibration/calibrationDrawHelpers.cpp b/core/cameracalibration/calibrationDrawHelpers.cpp index 4ad293ebb..687ea9f84 100644 --- a/core/cameracalibration/calibrationDrawHelpers.cpp +++ b/core/cameracalibration/calibrationDrawHelpers.cpp @@ -1,10 +1,10 @@ -#include "core/cameracalibration/calibrationDrawHelpers.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/cameracalibration/cameraModel.h" -#include "core/camerafixture/fixtureScene.h" -#include "core/alignment/selectableGeometryFeatures.h" -#include "core/buffers/rgb24/abstractPainter.h" -#include "core/camerafixture/cameraFixture.h" +#include "cameracalibration/calibrationDrawHelpers.h" +#include "geometry/mesh/mesh3d.h" +#include "cameracalibration/cameraModel.h" +#include "camerafixture/fixtureScene.h" +#include "alignment/selectableGeometryFeatures.h" +#include "buffers/rgb24/abstractPainter.h" +#include "camerafixture/cameraFixture.h" using namespace corecvs; diff --git a/core/cameracalibration/calibrationDrawHelpers.h b/core/cameracalibration/calibrationDrawHelpers.h index 56993f844..ac3e59cc1 100644 --- a/core/cameracalibration/calibrationDrawHelpers.h +++ b/core/cameracalibration/calibrationDrawHelpers.h @@ -1,10 +1,10 @@ #pragma once -#include "core/buffers/rgb24/rgbColor.h" -#include "core/xml/generated/calibrationDrawHelpersParameters.h" +#include "buffers/rgb24/rgbColor.h" +#include "xml/generated/calibrationDrawHelpersParameters.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/geometry/mesh/mesh3DDecorated.h" +#include "geometry/mesh/mesh3d.h" +#include "geometry/mesh/mesh3DDecorated.h" namespace corecvs { diff --git a/core/cameracalibration/calibrationLocation.cpp b/core/cameracalibration/calibrationLocation.cpp index b63d0525d..69e9f98a2 100644 --- a/core/cameracalibration/calibrationLocation.cpp +++ b/core/cameracalibration/calibrationLocation.cpp @@ -1,6 +1,6 @@ -#include "core/math/mathUtils.h" -#include "core/cameracalibration/calibrationLocation.h" -#include "core/reflection/printerVisitor.h" +#include "math/mathUtils.h" +#include "cameracalibration/calibrationLocation.h" +#include "reflection/printerVisitor.h" namespace corecvs { diff --git a/core/cameracalibration/calibrationLocation.h b/core/cameracalibration/calibrationLocation.h index b9832e02d..e636670d7 100644 --- a/core/cameracalibration/calibrationLocation.h +++ b/core/cameracalibration/calibrationLocation.h @@ -1,15 +1,15 @@ #ifndef CALIBRATION_LOCATION_H #define CALIBRATION_LOCATION_H -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/math/affine.h" -#include "core/math/eulerAngles.h" -#include "core/math/quaternion.h" -#include "core/math/mathUtils.h" -#include "core/math/matrix/matrix44.h" -#include "core/geometry/line.h" -#include "core/reflection/printerVisitor.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "math/affine.h" +#include "math/eulerAngles.h" +#include "math/quaternion.h" +#include "math/mathUtils.h" +#include "math/matrix/matrix44.h" +#include "geometry/line.h" +#include "reflection/printerVisitor.h" namespace corecvs { diff --git a/core/cameracalibration/cameraConstraints.cpp b/core/cameracalibration/cameraConstraints.cpp index f34f45457..d580c47b3 100644 --- a/core/cameracalibration/cameraConstraints.cpp +++ b/core/cameracalibration/cameraConstraints.cpp @@ -1,2 +1,2 @@ -#include "core/cameracalibration/cameraConstraints.h" +#include "cameracalibration/cameraConstraints.h" diff --git a/core/cameracalibration/cameraConstraints.h b/core/cameracalibration/cameraConstraints.h index a68019258..f1ced9212 100644 --- a/core/cameracalibration/cameraConstraints.h +++ b/core/cameracalibration/cameraConstraints.h @@ -3,7 +3,7 @@ #include -#include "core/utils/typesafeBitmaskEnums.h" +#include "utils/typesafeBitmaskEnums.h" namespace corecvs { enum class CameraConstraints diff --git a/core/cameracalibration/cameraModel.cpp b/core/cameracalibration/cameraModel.cpp index b6f6d082a..e0dda54d2 100644 --- a/core/cameracalibration/cameraModel.cpp +++ b/core/cameracalibration/cameraModel.cpp @@ -1,7 +1,7 @@ #include -#include "core/cameracalibration/cameraModel.h" -#include "core/geometry/convexHull.h" +#include "cameracalibration/cameraModel.h" +#include "geometry/convexHull.h" namespace corecvs { diff --git a/core/cameracalibration/cameraModel.h b/core/cameracalibration/cameraModel.h index fae720ca5..5df6cb52e 100644 --- a/core/cameracalibration/cameraModel.h +++ b/core/cameracalibration/cameraModel.h @@ -2,17 +2,17 @@ #define CAMERAMODEL_H #include "calibrationLocation.h" -#include "core/buffers/displacementBuffer.h" -#include "core/xml/generated/distortionApplicationParameters.h" -#include "core/rectification/essentialMatrix.h" -#include "core/alignment/lensDistortionModelParameters.h" -#include "core/alignment/pointObservation.h" -#include "core/geometry/polygons.h" -#include "core/reflection/dynamicObject.h" +#include "buffers/displacementBuffer.h" +#include "xml/generated/distortionApplicationParameters.h" +#include "rectification/essentialMatrix.h" +#include "alignment/lensDistortionModelParameters.h" +#include "alignment/pointObservation.h" +#include "geometry/polygons.h" +#include "reflection/dynamicObject.h" -#include "core/alignment/selectableGeometryFeatures.h" +#include "alignment/selectableGeometryFeatures.h" -#include "core/cameracalibration/projection/projectionFactory.h" +#include "cameracalibration/projection/projectionFactory.h" namespace corecvs { diff --git a/core/cameracalibration/flatPatternCalibrator.cpp b/core/cameracalibration/flatPatternCalibrator.cpp index f62572493..84ce1d6fb 100644 --- a/core/cameracalibration/flatPatternCalibrator.cpp +++ b/core/cameracalibration/flatPatternCalibrator.cpp @@ -1,4 +1,4 @@ -#include "core/cameracalibration/flatPatternCalibrator.h" +#include "cameracalibration/flatPatternCalibrator.h" corecvs::FlatPatternCalibrator::FlatPatternCalibrator(const CameraConstraints constraints, const PinholeCameraIntrinsics lockParams, const LineDistortionEstimatorParameters distortionEstimatorParams, const double lockFactor) : factor(lockFactor), K(0), N(0), absoluteConic(6), intrinsics(lockParams), lockParams(lockParams), distortionEstimationParams(distortionEstimatorParams), constraints(constraints), forceZeroSkew(!!(constraints & CameraConstraints::ZERO_SKEW)) { diff --git a/core/cameracalibration/flatPatternCalibrator.h b/core/cameracalibration/flatPatternCalibrator.h index f4f663d42..473a17b66 100644 --- a/core/cameracalibration/flatPatternCalibrator.h +++ b/core/cameracalibration/flatPatternCalibrator.h @@ -3,13 +3,13 @@ #include -#include "core/cameracalibration/cameraConstraints.h" -#include "core/math/matrix/homographyReconstructor.h" -#include "core/math/levenmarq.h" -#include "core/xml/generated/lineDistortionEstimatorParameters.h" -#include "core/cameracalibration/cameraModel.h" +#include "cameracalibration/cameraConstraints.h" +#include "math/matrix/homographyReconstructor.h" +#include "math/levenmarq.h" +#include "xml/generated/lineDistortionEstimatorParameters.h" +#include "cameracalibration/cameraModel.h" -#include "core/alignment/selectableGeometryFeatures.h" +#include "alignment/selectableGeometryFeatures.h" // In order to get 3-dof rotation, we should penalize for quaternion norm // The unclear part is it's weight diff --git a/core/cameracalibration/ilFormat.h b/core/cameracalibration/ilFormat.h index 31aa715e6..833051c1e 100644 --- a/core/cameracalibration/ilFormat.h +++ b/core/cameracalibration/ilFormat.h @@ -1,7 +1,7 @@ #ifndef ILFORMAT_H #define ILFORMAT_H -#include "core/camerafixture/fixtureScene.h" +#include "camerafixture/fixtureScene.h" namespace corecvs { diff --git a/core/cameracalibration/projection/equidistantProjection.cpp b/core/cameracalibration/projection/equidistantProjection.cpp index cd32b68bf..5f27dd6af 100644 --- a/core/cameracalibration/projection/equidistantProjection.cpp +++ b/core/cameracalibration/projection/equidistantProjection.cpp @@ -1,5 +1,5 @@ #include "equidistantProjection.h" -#include "core/reflection/reflection.h" +#include "reflection/reflection.h" namespace corecvs { diff --git a/core/cameracalibration/projection/equidistantProjection.h b/core/cameracalibration/projection/equidistantProjection.h index c5ead7515..e002ae48a 100644 --- a/core/cameracalibration/projection/equidistantProjection.h +++ b/core/cameracalibration/projection/equidistantProjection.h @@ -1,12 +1,12 @@ #ifndef EQUIDISTANTPROJECTION_H #define EQUIDISTANTPROJECTION_H -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/function/function.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "function/function.h" -#include "core/cameracalibration/projection/projectionModels.h" -#include "core/xml/generated/projectionBaseParameters.h" +#include "cameracalibration/projection/projectionModels.h" +#include "xml/generated/projectionBaseParameters.h" namespace corecvs{ /** @@ -59,7 +59,7 @@ class GenericEquidistantProjection{ ElementType r = shift.l2Metric(); shift /= r; ElementType tau = r / focal(); - out = Vector3d(shift.normalised() * sin(tau), cos(tau)); + out = Vector3d(shift.normalised() * std::sin(tau), std::cos(tau)); } }; diff --git a/core/cameracalibration/projection/equisolidAngleProjection.h b/core/cameracalibration/projection/equisolidAngleProjection.h index a03005017..f418f9f2f 100644 --- a/core/cameracalibration/projection/equisolidAngleProjection.h +++ b/core/cameracalibration/projection/equisolidAngleProjection.h @@ -1,12 +1,12 @@ #ifndef EQUISOLIDANGLEPROJECTION_H #define EQUISOLIDANGLEPROJECTION_H -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/function/function.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "function/function.h" -#include "core/cameracalibration/projection/projectionModels.h" -#include "core/xml/generated/projectionBaseParameters.h" +#include "cameracalibration/projection/projectionModels.h" +#include "xml/generated/projectionBaseParameters.h" namespace corecvs { /** @@ -37,7 +37,7 @@ class EquisolidAngleProjection : public ProjectionBaseParameters, public Camera { double theta = rayToAngle(p); Vector2dd dir = p.xy().normalised(); - return dir * 2 * focal() * sin(theta / 2) + principal(); + return dir * 2 * focal() *std::sin(theta / 2) + principal(); } virtual Vector3dd reverse(const Vector2dd &p) const override @@ -46,7 +46,7 @@ class EquisolidAngleProjection : public ProjectionBaseParameters, public Camera double r = shift.l2Metric(); shift /= r; double theta = 2 * asin(r / 2.0 / focal()); - return Vector3dd(shift.normalised() * sin(theta), cos(theta)); + return Vector3dd(shift.normalised() * std::sin(theta), std::cos(theta)); } /* TODO: Function not actually implemented */ diff --git a/core/cameracalibration/projection/omnidirectionalProjection.h b/core/cameracalibration/projection/omnidirectionalProjection.h index 25ff5fb60..bb69b6392 100644 --- a/core/cameracalibration/projection/omnidirectionalProjection.h +++ b/core/cameracalibration/projection/omnidirectionalProjection.h @@ -1,16 +1,16 @@ #ifndef OMNIDIRECTIONALPROJECTION_H #define OMNIDIRECTIONALPROJECTION_H -#include "core/polynomial/polynomial.h" -#include "core/polynomial/polynomialSolver.h" +#include "polynomial/polynomial.h" +#include "polynomial/polynomialSolver.h" -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/function/function.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "function/function.h" -#include "core/cameracalibration/projection/projectionModels.h" -#include "core/xml/generated/projectionBaseParameters.h" -#include "core/xml/generated/omnidirectionalBaseParameters.h" +#include "cameracalibration/projection/projectionModels.h" +#include "xml/generated/projectionBaseParameters.h" +#include "xml/generated/omnidirectionalBaseParameters.h" namespace corecvs{ diff --git a/core/cameracalibration/projection/pinholeCameraIntrinsics.cpp b/core/cameracalibration/projection/pinholeCameraIntrinsics.cpp index 999be5b09..ba4b249fd 100644 --- a/core/cameracalibration/projection/pinholeCameraIntrinsics.cpp +++ b/core/cameracalibration/projection/pinholeCameraIntrinsics.cpp @@ -1,4 +1,4 @@ -#include "core/cameracalibration/projection/pinholeCameraIntrinsics.h" +#include "cameracalibration/projection/pinholeCameraIntrinsics.h" using namespace std; diff --git a/core/cameracalibration/projection/pinholeCameraIntrinsics.h b/core/cameracalibration/projection/pinholeCameraIntrinsics.h index ad39fa6da..f22730bd4 100644 --- a/core/cameracalibration/projection/pinholeCameraIntrinsics.h +++ b/core/cameracalibration/projection/pinholeCameraIntrinsics.h @@ -1,10 +1,10 @@ #ifndef PINHOLECAMERAINTRINSICS_H #define PINHOLECAMERAINTRINSICS_H -#include "core/math/matrix/matrix44.h" -#include "core/cameracalibration/projection/projectionModels.h" -#include "core/xml/generated/pinholeCameraIntrinsicsBaseParameters.h" -#include "core/math/mathUtils.h" +#include "math/matrix/matrix44.h" +#include "cameracalibration/projection/projectionModels.h" +#include "xml/generated/pinholeCameraIntrinsicsBaseParameters.h" +#include "math/mathUtils.h" namespace corecvs { diff --git a/core/cameracalibration/projection/projectionFactory.h b/core/cameracalibration/projection/projectionFactory.h index 12700b591..d442385d4 100644 --- a/core/cameracalibration/projection/projectionFactory.h +++ b/core/cameracalibration/projection/projectionFactory.h @@ -1,11 +1,11 @@ #ifndef PROJECTIONFACTORY_H #define PROJECTIONFACTORY_H -#include "core/cameracalibration/projection/pinholeCameraIntrinsics.h" -#include "core/cameracalibration/projection/equidistantProjection.h" -#include "core/cameracalibration/projection/equisolidAngleProjection.h" -#include "core/cameracalibration/projection/omnidirectionalProjection.h" -#include "core/cameracalibration/projection/stereographicProjection.h" +#include "cameracalibration/projection/pinholeCameraIntrinsics.h" +#include "cameracalibration/projection/equidistantProjection.h" +#include "cameracalibration/projection/equisolidAngleProjection.h" +#include "cameracalibration/projection/omnidirectionalProjection.h" +#include "cameracalibration/projection/stereographicProjection.h" namespace corecvs { diff --git a/core/cameracalibration/projection/projectionModels.cpp b/core/cameracalibration/projection/projectionModels.cpp index 7dcbd743c..784ad348f 100644 --- a/core/cameracalibration/projection/projectionModels.cpp +++ b/core/cameracalibration/projection/projectionModels.cpp @@ -1,4 +1,4 @@ -#include "core/cameracalibration/projection/projectionModels.h" +#include "cameracalibration/projection/projectionModels.h" namespace corecvs { diff --git a/core/cameracalibration/projection/projectionModels.h b/core/cameracalibration/projection/projectionModels.h index 8afaca70d..b54f0b034 100644 --- a/core/cameracalibration/projection/projectionModels.h +++ b/core/cameracalibration/projection/projectionModels.h @@ -1,13 +1,11 @@ #ifndef PROJECTIONMODELS_H #define PROJECTIONMODELS_H -#include "core/xml/generated/projectionType.h" -#include "core/reflection/dynamicObject.h" +#include "xml/generated/projectionType.h" +#include "reflection/dynamicObject.h" -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" - -#include "core/cameracalibration/projection/projectionModels.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" namespace corecvs { @@ -120,7 +118,7 @@ class OrthographicProjection : /*public ProjectionBaseParameters,*/ public Camer { double tau = rayToAngle(p); Vector2dd dir = p.xy().normalised(); - return dir * focal * sin(tau); + return dir * focal * std::sin(tau); } virtual Vector3dd reverse(const Vector2dd &p) const override diff --git a/core/cameracalibration/projection/stereographicProjection.h b/core/cameracalibration/projection/stereographicProjection.h index 0e4af3bb0..0004a26b9 100644 --- a/core/cameracalibration/projection/stereographicProjection.h +++ b/core/cameracalibration/projection/stereographicProjection.h @@ -1,12 +1,12 @@ #ifndef STEREOGRAPHICPROJECTION_H #define STEREOGRAPHICPROJECTION_H -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/function/function.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "function/function.h" -#include "core/cameracalibration/projection/projectionModels.h" -#include "core/xml/generated/projectionBaseParameters.h" +#include "cameracalibration/projection/projectionModels.h" +#include "xml/generated/projectionBaseParameters.h" namespace corecvs { diff --git a/core/camerafixture/CMakeLists.txt b/core/camerafixture/CMakeLists.txt index 7625a68b3..50eab7c36 100644 --- a/core/camerafixture/CMakeLists.txt +++ b/core/camerafixture/CMakeLists.txt @@ -1,20 +1,21 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/fixtureCamera.h - ${CMAKE_CURRENT_LIST_DIR}/cameraFixture.h - ${CMAKE_CURRENT_LIST_DIR}/fixtureScene.h - ${CMAKE_CURRENT_LIST_DIR}/sceneFeaturePoint.h - ${CMAKE_CURRENT_LIST_DIR}/cameraPrototype.h - ${CMAKE_CURRENT_LIST_DIR}/fixtureScenePart.h - ${CMAKE_CURRENT_LIST_DIR}/wildcardablePointerPair.h +set(CAMERAFIXTURE_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/fixtureCamera.h + ${CMAKE_CURRENT_LIST_DIR}/cameraFixture.h + ${CMAKE_CURRENT_LIST_DIR}/fixtureScene.h + ${CMAKE_CURRENT_LIST_DIR}/sceneFeaturePoint.h + ${CMAKE_CURRENT_LIST_DIR}/cameraPrototype.h + ${CMAKE_CURRENT_LIST_DIR}/fixtureScenePart.h + ${CMAKE_CURRENT_LIST_DIR}/wildcardablePointerPair.h + PARENT_SCOPE + ) - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/fixtureCamera.cpp - ${CMAKE_CURRENT_LIST_DIR}/fixtureScene.cpp - ${CMAKE_CURRENT_LIST_DIR}/sceneFeaturePoint.cpp - ${CMAKE_CURRENT_LIST_DIR}/cameraFixture.cpp - ${CMAKE_CURRENT_LIST_DIR}/cameraPrototype.cpp - ${CMAKE_CURRENT_LIST_DIR}/fixtureScenePart.cpp - ${CMAKE_CURRENT_LIST_DIR}/wildcardablePointerPair.cpp - ) +set(CAMERAFIXTURE_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/fixtureCamera.cpp + ${CMAKE_CURRENT_LIST_DIR}/fixtureScene.cpp + ${CMAKE_CURRENT_LIST_DIR}/sceneFeaturePoint.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraFixture.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraPrototype.cpp + ${CMAKE_CURRENT_LIST_DIR}/fixtureScenePart.cpp + ${CMAKE_CURRENT_LIST_DIR}/wildcardablePointerPair.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/camerafixture/cameraFixture.cpp b/core/camerafixture/cameraFixture.cpp index 651caf207..d00c9736d 100644 --- a/core/camerafixture/cameraFixture.cpp +++ b/core/camerafixture/cameraFixture.cpp @@ -1,5 +1,5 @@ -#include "core/camerafixture/cameraFixture.h" -#include "core/camerafixture/fixtureScene.h" +#include "camerafixture/cameraFixture.h" +#include "camerafixture/fixtureScene.h" namespace corecvs { diff --git a/core/camerafixture/cameraFixture.h b/core/camerafixture/cameraFixture.h index f06136164..fe4b94878 100644 --- a/core/camerafixture/cameraFixture.h +++ b/core/camerafixture/cameraFixture.h @@ -7,10 +7,10 @@ #include #include -#include "core/alignment/pointObservation.h" +#include "alignment/pointObservation.h" -#include "core/utils/typesafeBitmaskEnums.h" -#include "core/cameracalibration/calibrationLocation.h" // LocationData +#include "utils/typesafeBitmaskEnums.h" +#include "cameracalibration/calibrationLocation.h" // LocationData #include "fixtureCamera.h" #include "fixtureScenePart.h" diff --git a/core/camerafixture/cameraPrototype.cpp b/core/camerafixture/cameraPrototype.cpp index 4931249d4..ede71bf11 100644 --- a/core/camerafixture/cameraPrototype.cpp +++ b/core/camerafixture/cameraPrototype.cpp @@ -1,4 +1,4 @@ -#include "core/camerafixture/cameraPrototype.h" +#include "camerafixture/cameraPrototype.h" namespace corecvs { diff --git a/core/camerafixture/cameraPrototype.h b/core/camerafixture/cameraPrototype.h index 4750c295c..9852d54fd 100644 --- a/core/camerafixture/cameraPrototype.h +++ b/core/camerafixture/cameraPrototype.h @@ -1,8 +1,8 @@ #ifndef CAMERA_PROTOTYPE_H #define CAMERA_PROTOTYPE_H -#include "core/camerafixture/fixtureScenePart.h" -#include "core/cameracalibration/cameraModel.h" +#include "camerafixture/fixtureScenePart.h" +#include "cameracalibration/cameraModel.h" namespace corecvs { diff --git a/core/camerafixture/fixtureCamera.cpp b/core/camerafixture/fixtureCamera.cpp index 5366482ef..04b51af7b 100644 --- a/core/camerafixture/fixtureCamera.cpp +++ b/core/camerafixture/fixtureCamera.cpp @@ -1,6 +1,6 @@ -#include "core/camerafixture/fixtureCamera.h" -#include "core/camerafixture/cameraFixture.h" -#include "core/camerafixture/fixtureScene.h" +#include "camerafixture/fixtureCamera.h" +#include "camerafixture/cameraFixture.h" +#include "camerafixture/fixtureScene.h" namespace corecvs { diff --git a/core/camerafixture/fixtureCamera.h b/core/camerafixture/fixtureCamera.h index 836857b41..d98e953b0 100644 --- a/core/camerafixture/fixtureCamera.h +++ b/core/camerafixture/fixtureCamera.h @@ -4,16 +4,16 @@ #include #include -#include "core/utils/atomicOps.h" -#include "core/cameracalibration/calibrationLocation.h" // LocationData -#include "core/alignment/lensDistortionModelParameters.h" -#include "core/geometry/line.h" -#include "core/geometry/convexPolyhedron.h" -#include "core/alignment/pointObservation.h" -#include "core/cameracalibration/cameraModel.h" -#include "core/camerafixture/fixtureScenePart.h" - -#include "core/camerafixture/cameraPrototype.h" // pls see comment below +#include "utils/atomicOps.h" +#include "cameracalibration/calibrationLocation.h" // LocationData +#include "alignment/lensDistortionModelParameters.h" +#include "geometry/line.h" +#include "geometry/convexPolyhedron.h" +#include "alignment/pointObservation.h" +#include "cameracalibration/cameraModel.h" +#include "camerafixture/fixtureScenePart.h" + +#include "camerafixture/cameraPrototype.h" // pls see comment below namespace corecvs { diff --git a/core/camerafixture/fixtureScene.cpp b/core/camerafixture/fixtureScene.cpp index 41dcfcd72..2810d0e29 100644 --- a/core/camerafixture/fixtureScene.cpp +++ b/core/camerafixture/fixtureScene.cpp @@ -1,10 +1,10 @@ -#include "core/camerafixture/fixtureScene.h" -#include "core/buffers/bufferFactory.h" -#include "core/math/affine.h" -#include "core/utils/utils.h" -#include "core/camerafixture/cameraFixture.h" -#include "core/utils/log.h" -#include "core/filesystem/folderScanner.h" +#include "camerafixture/fixtureScene.h" +#include "buffers/bufferFactory.h" +#include "math/affine.h" +#include "utils/utils.h" +#include "camerafixture/cameraFixture.h" +#include "utils/log.h" +#include "filesystem/folderScanner.h" namespace corecvs { diff --git a/core/camerafixture/fixtureScene.h b/core/camerafixture/fixtureScene.h index d436efda9..d78141307 100644 --- a/core/camerafixture/fixtureScene.h +++ b/core/camerafixture/fixtureScene.h @@ -5,11 +5,11 @@ #include #include -#include "core/camerafixture/fixtureScenePart.h" -#include "core/camerafixture/fixtureCamera.h" -#include "core/camerafixture/sceneFeaturePoint.h" -#include "core/camerafixture/cameraPrototype.h" -#include "core/utils/typesafeBitmaskEnums.h" +#include "camerafixture/fixtureScenePart.h" +#include "camerafixture/fixtureCamera.h" +#include "camerafixture/sceneFeaturePoint.h" +#include "camerafixture/cameraPrototype.h" +#include "utils/typesafeBitmaskEnums.h" /* In future Scene would like to control memory management for child objects */ //#define SCENE_OWN_ALLOCATOR_DRAFT diff --git a/core/camerafixture/fixtureScenePart.cpp b/core/camerafixture/fixtureScenePart.cpp index 2a0df36b8..ad0fa9860 100644 --- a/core/camerafixture/fixtureScenePart.cpp +++ b/core/camerafixture/fixtureScenePart.cpp @@ -1,4 +1,4 @@ -#include "core/camerafixture/fixtureScenePart.h" +#include "camerafixture/fixtureScenePart.h" namespace corecvs { diff --git a/core/camerafixture/fixtureScenePart.h b/core/camerafixture/fixtureScenePart.h index 029825a07..44ee39ade 100644 --- a/core/camerafixture/fixtureScenePart.h +++ b/core/camerafixture/fixtureScenePart.h @@ -1,9 +1,9 @@ #ifndef FIXTURE_SCENE_PART_H #define FIXTURE_SCENE_PART_H -#include "core/utils/global.h" -#include "core/utils/atomicOps.h" -#include "core/geometry/polygons.h" +#include "utils/global.h" +#include "utils/atomicOps.h" +#include "geometry/polygons.h" namespace corecvs { diff --git a/core/camerafixture/sceneFeaturePoint.cpp b/core/camerafixture/sceneFeaturePoint.cpp index 673f4ef2f..05f7645cf 100644 --- a/core/camerafixture/sceneFeaturePoint.cpp +++ b/core/camerafixture/sceneFeaturePoint.cpp @@ -1,9 +1,9 @@ -#include "core/camerafixture/sceneFeaturePoint.h" -#include "core/camerafixture/fixtureScene.h" -#include "core/camerafixture/cameraFixture.h" -#include "core/rectification/multicameraTriangulator.h" -#include "core/utils/visitors/propertyListVisitor.h" -#include "core/geometry/mesh/mesh3d.h" +#include "camerafixture/sceneFeaturePoint.h" +#include "camerafixture/fixtureScene.h" +#include "camerafixture/cameraFixture.h" +#include "rectification/multicameraTriangulator.h" +#include "utils/visitors/propertyListVisitor.h" +#include "geometry/mesh/mesh3d.h" #ifdef WITH_BOOST #include diff --git a/core/camerafixture/sceneFeaturePoint.h b/core/camerafixture/sceneFeaturePoint.h index 748953756..26b18f038 100644 --- a/core/camerafixture/sceneFeaturePoint.h +++ b/core/camerafixture/sceneFeaturePoint.h @@ -4,13 +4,13 @@ #include #include -#include "core/camerafixture/fixtureCamera.h" -#include "core/features2d/imageKeyPoints.h" -#include "core/camerafixture/wildcardablePointerPair.h" -#include "core/utils/typesafeBitmaskEnums.h" +#include "camerafixture/fixtureCamera.h" +#include "features2d/imageKeyPoints.h" +#include "camerafixture/wildcardablePointerPair.h" +#include "utils/typesafeBitmaskEnums.h" /* Presentation related */ -#include "core/buffers/rgb24/rgbColor.h" +#include "buffers/rgb24/rgbColor.h" namespace corecvs { diff --git a/core/camerafixture/wildcardablePointerPair.cpp b/core/camerafixture/wildcardablePointerPair.cpp index 364c25720..05a1099f1 100644 --- a/core/camerafixture/wildcardablePointerPair.cpp +++ b/core/camerafixture/wildcardablePointerPair.cpp @@ -1,5 +1,5 @@ -#include "core/camerafixture/wildcardablePointerPair.h" -#include "core/camerafixture/sceneFeaturePoint.h" +#include "camerafixture/wildcardablePointerPair.h" +#include "camerafixture/sceneFeaturePoint.h" namespace corecvs { diff --git a/core/cammodel/CMakeLists.txt b/core/cammodel/CMakeLists.txt index c5ba90090..0c159dcfc 100644 --- a/core/cammodel/CMakeLists.txt +++ b/core/cammodel/CMakeLists.txt @@ -1,16 +1,17 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/energyBuffer.h - ${CMAKE_CURRENT_LIST_DIR}/imagerControl.h - ${CMAKE_CURRENT_LIST_DIR}/cameraParameters.h - ${CMAKE_CURRENT_LIST_DIR}/sphericalCorrectionLUT.h - # ${CMAKE_CURRENT_LIST_DIR}/cameraModel.h +set(CAMMODEL_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/energyBuffer.h + ${CMAKE_CURRENT_LIST_DIR}/imagerControl.h + ${CMAKE_CURRENT_LIST_DIR}/cameraParameters.h + ${CMAKE_CURRENT_LIST_DIR}/sphericalCorrectionLUT.h +# ${CMAKE_CURRENT_LIST_DIR}/cameraModel.h + PARENT_SCOPE + ) - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/energyBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/imagerControl.cpp - ${CMAKE_CURRENT_LIST_DIR}/cameraParameters.cpp - ${CMAKE_CURRENT_LIST_DIR}/sphericalCorrectionLUT.cpp - # ${CMAKE_CURRENT_LIST_DIR}/cameraModel.cpp -) +set(CAMMODEL_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/energyBuffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/imagerControl.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/sphericalCorrectionLUT.cpp +# ${CMAKE_CURRENT_LIST_DIR}/cameraModel.cpp + PARENT_SCOPE + ) diff --git a/core/cammodel/cameraParameters.cpp b/core/cammodel/cameraParameters.cpp index f139cd4cb..61d76808c 100644 --- a/core/cammodel/cameraParameters.cpp +++ b/core/cammodel/cameraParameters.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/cammodel/cameraParameters.h" +#include "cammodel/cameraParameters.h" namespace corecvs { diff --git a/core/cammodel/cameraParameters.h b/core/cammodel/cameraParameters.h index 897524662..8c1c45833 100644 --- a/core/cammodel/cameraParameters.h +++ b/core/cammodel/cameraParameters.h @@ -6,12 +6,12 @@ * * \date Feb 10, 2011 */ -#include "core/utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix44.h" +#include "utils/global.h" +#include "math/vector/vector2d.h" +#include "math/matrix/matrix44.h" -#include "core/cameracalibration/cameraModel.h" -#include "core/cameracalibration/projection/pinholeCameraIntrinsics.h" +#include "cameracalibration/cameraModel.h" +#include "cameracalibration/projection/pinholeCameraIntrinsics.h" diff --git a/core/cammodel/energyBuffer.cpp b/core/cammodel/energyBuffer.cpp index 93bee3e94..f39746f0b 100644 --- a/core/cammodel/energyBuffer.cpp +++ b/core/cammodel/energyBuffer.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/cammodel/energyBuffer.h" +#include "cammodel/energyBuffer.h" namespace corecvs { diff --git a/core/cammodel/energyBuffer.h b/core/cammodel/energyBuffer.h index ab33a5e44..c10291a3c 100644 --- a/core/cammodel/energyBuffer.h +++ b/core/cammodel/energyBuffer.h @@ -10,7 +10,7 @@ #ifndef CENERGYBUFFER_H_ #define CENERGYBUFFER_H_ -#include "core/buffers/abstractContiniousBuffer.h" +#include "buffers/abstractContiniousBuffer.h" namespace corecvs { class EnergyBuffer : public AbstractContiniousBuffer diff --git a/core/cammodel/imagerControl.cpp b/core/cammodel/imagerControl.cpp index d7350e00a..9e30ed7c8 100644 --- a/core/cammodel/imagerControl.cpp +++ b/core/cammodel/imagerControl.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/cammodel/imagerControl.h" +#include "cammodel/imagerControl.h" namespace corecvs { #define TRACE_CONTROL_DETAILS diff --git a/core/cammodel/imagerControl.h b/core/cammodel/imagerControl.h index 343ad5af2..bb09d5ed6 100644 --- a/core/cammodel/imagerControl.h +++ b/core/cammodel/imagerControl.h @@ -9,7 +9,7 @@ * \author alexander */ -#include "core/buffers/histogram/histogram.h" +#include "buffers/histogram/histogram.h" namespace corecvs { diff --git a/core/cammodel/imagerProperties.cpp b/core/cammodel/imagerProperties.cpp index 619fffe66..fda202508 100644 --- a/core/cammodel/imagerProperties.cpp +++ b/core/cammodel/imagerProperties.cpp @@ -5,7 +5,7 @@ * Author: apimenov */ -#include "core/cammodel/imagerProperties.h" +#include "cammodel/imagerProperties.h" namespace corecvs { diff --git a/core/cammodel/sphericalCorrectionLUT.cpp b/core/cammodel/sphericalCorrectionLUT.cpp index 8b5800983..cbf19bd0f 100644 --- a/core/cammodel/sphericalCorrectionLUT.cpp +++ b/core/cammodel/sphericalCorrectionLUT.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/cammodel/sphericalCorrectionLUT.h" +#include "cammodel/sphericalCorrectionLUT.h" namespace corecvs { const size_t RadiusCorrectionLUT::LUT_SIZE_LIMIT; diff --git a/core/cammodel/sphericalCorrectionLUT.h b/core/cammodel/sphericalCorrectionLUT.h index 1d6b73413..416493dc8 100644 --- a/core/cammodel/sphericalCorrectionLUT.h +++ b/core/cammodel/sphericalCorrectionLUT.h @@ -11,9 +11,9 @@ #include #include -#include "core/buffers/abstractBuffer.h" -#include "core/math/vector/vector2d.h" -#include "core/buffers/deformMap.h" +#include "buffers/abstractBuffer.h" +#include "math/vector/vector2d.h" +#include "buffers/deformMap.h" namespace corecvs { diff --git a/core/clegacy/align_nonlinear.h b/core/clegacy/align_nonlinear.h index 3c54548df..8c0fd0e30 100644 --- a/core/clegacy/align_nonlinear.h +++ b/core/clegacy/align_nonlinear.h @@ -15,7 +15,7 @@ #endif #include "g12buffer.h" -#include "core/clegacy/math/geometry.h" +#include "clegacy/math/geometry.h" #ifdef DEPRICATED #include "displacement.h" diff --git a/core/clegacy/math/levenmarq.cpp b/core/clegacy/math/levenmarq.cpp index ba32b52bc..6ca490982 100644 --- a/core/clegacy/math/levenmarq.cpp +++ b/core/clegacy/math/levenmarq.cpp @@ -2,9 +2,9 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/levenmarq.h" +#include "math/levenmarq.h" #include "stdlib.h" namespace corecvs { diff --git a/core/clegacy/math/levenmarq.h b/core/clegacy/math/levenmarq.h index c6aa47d2d..babff8b71 100644 --- a/core/clegacy/math/levenmarq.h +++ b/core/clegacy/math/levenmarq.h @@ -1,6 +1,6 @@ #pragma once -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix.h" +#include "math/vector/vector2d.h" +#include "math/matrix/matrix.h" #include namespace corecvs { diff --git a/core/clegacy/math/linlse.h b/core/clegacy/math/linlse.h index 794d59a6a..1befeb5de 100644 --- a/core/clegacy/math/linlse.h +++ b/core/clegacy/math/linlse.h @@ -13,7 +13,7 @@ extern "C" { #endif -#include "core/math/matrix/matrix.h" +#include "math/matrix/matrix.h" namespace corecvs { #ifdef __cplusplus diff --git a/core/clegacy/math/math.pri b/core/clegacy/math/math.pri old mode 100644 new mode 100755 diff --git a/core/clustering3d/CMakeLists.txt b/core/clustering3d/CMakeLists.txt index a0c5cc642..b9e5435ec 100644 --- a/core/clustering3d/CMakeLists.txt +++ b/core/clustering3d/CMakeLists.txt @@ -1,15 +1,15 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/cloud.h - ${CMAKE_CURRENT_LIST_DIR}/swarmPoint.h - ${CMAKE_CURRENT_LIST_DIR}/cloudCluster.h - ${CMAKE_CURRENT_LIST_DIR}/clustering3d.h - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/cloud.cpp - ${CMAKE_CURRENT_LIST_DIR}/swarmPoint.cpp - ${CMAKE_CURRENT_LIST_DIR}/cloudCluster.cpp - ${CMAKE_CURRENT_LIST_DIR}/clustering3d.cpp +set(CLUSTERING3D_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/cloud.h + ${CMAKE_CURRENT_LIST_DIR}/swarmPoint.h + ${CMAKE_CURRENT_LIST_DIR}/cloudCluster.h + ${CMAKE_CURRENT_LIST_DIR}/clustering3d.h + PARENT_SCOPE ) - +set(CLUSTERING3D_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/cloud.cpp + ${CMAKE_CURRENT_LIST_DIR}/swarmPoint.cpp + ${CMAKE_CURRENT_LIST_DIR}/cloudCluster.cpp + ${CMAKE_CURRENT_LIST_DIR}/clustering3d.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/clustering3d/cloud.cpp b/core/clustering3d/cloud.cpp index 1f32ec896..5117d2947 100644 --- a/core/clustering3d/cloud.cpp +++ b/core/clustering3d/cloud.cpp @@ -4,7 +4,7 @@ * \date Feb 26, 2013 */ -#include "core/clustering3d/cloud.h" +#include "clustering3d/cloud.h" namespace corecvs { diff --git a/core/clustering3d/cloud.h b/core/clustering3d/cloud.h index ee92c07c5..d13a7dc38 100644 --- a/core/clustering3d/cloud.h +++ b/core/clustering3d/cloud.h @@ -5,9 +5,9 @@ * \date Feb 20, 2013 */ -#include "core/utils/global.h" -#include "core/clustering3d/swarmPoint.h" -#include "core/geometry/mesh/mesh3d.h" +#include "utils/global.h" +#include "clustering3d/swarmPoint.h" +#include "geometry/mesh/mesh3d.h" namespace corecvs { diff --git a/core/clustering3d/cloudCluster.cpp b/core/clustering3d/cloudCluster.cpp index 199e1553f..bcdf13a9d 100644 --- a/core/clustering3d/cloudCluster.cpp +++ b/core/clustering3d/cloudCluster.cpp @@ -1,4 +1,4 @@ -#include "core/clustering3d/cloudCluster.h" +#include "clustering3d/cloudCluster.h" namespace corecvs { diff --git a/core/clustering3d/cloudCluster.h b/core/clustering3d/cloudCluster.h index 6a57d9914..42fe6fca9 100644 --- a/core/clustering3d/cloudCluster.h +++ b/core/clustering3d/cloudCluster.h @@ -5,10 +5,10 @@ * \date Mar 15, 2013 */ -#include "core/utils/global.h" -#include "core/clustering3d/cloud.h" -#include "core/segmentation/segmentator.h" -#include "core/geometry/ellipticalApproximation.h" +#include "utils/global.h" +#include "clustering3d/cloud.h" +#include "segmentation/segmentator.h" +#include "geometry/ellipticalApproximation.h" namespace corecvs { diff --git a/core/clustering3d/clustering3d.cpp b/core/clustering3d/clustering3d.cpp index fc3bd4f7c..508b3de2c 100644 --- a/core/clustering3d/clustering3d.cpp +++ b/core/clustering3d/clustering3d.cpp @@ -1,4 +1,4 @@ -#include "core/clustering3d/clustering3d.h" +#include "clustering3d/clustering3d.h" namespace corecvs { diff --git a/core/clustering3d/clustering3d.h b/core/clustering3d/clustering3d.h index fc7272d9f..29598da49 100644 --- a/core/clustering3d/clustering3d.h +++ b/core/clustering3d/clustering3d.h @@ -5,14 +5,14 @@ * \date Mar 15, 2013 */ -#include "core/utils/global.h" -#include "core/clustering3d/cloud.h" -#include "core/clustering3d/cloudCluster.h" -#include "core/utils/preciseTimer.h" -#include "core/buffers/buffer3d.h" - -#include "core/stats/calculationStats.h" -#include "core/xml/generated/headSearchParameters.h" +#include "utils/global.h" +#include "clustering3d/cloud.h" +#include "clustering3d/cloudCluster.h" +#include "utils/preciseTimer.h" +#include "buffers/buffer3d.h" + +#include "stats/calculationStats.h" +#include "xml/generated/headSearchParameters.h" namespace corecvs { using std::vector; diff --git a/core/clustering3d/swarmPoint.cpp b/core/clustering3d/swarmPoint.cpp index 824109c9d..5a547fdd9 100644 --- a/core/clustering3d/swarmPoint.cpp +++ b/core/clustering3d/swarmPoint.cpp @@ -1,4 +1,4 @@ -#include "core/clustering3d/swarmPoint.h" +#include "clustering3d/swarmPoint.h" namespace corecvs { diff --git a/core/clustering3d/swarmPoint.h b/core/clustering3d/swarmPoint.h index e641d32e5..fb0c51972 100644 --- a/core/clustering3d/swarmPoint.h +++ b/core/clustering3d/swarmPoint.h @@ -5,9 +5,9 @@ * \date Mar 15, 2013 */ -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/buffers/rgb24/rgbColor.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "buffers/rgb24/rgbColor.h" namespace corecvs { diff --git a/core/delaunay/CMakeLists.txt b/core/delaunay/CMakeLists.txt index 3bf70013d..d3bd2a2b6 100644 --- a/core/delaunay/CMakeLists.txt +++ b/core/delaunay/CMakeLists.txt @@ -1,6 +1,9 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/delaunay.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/delaunay.cpp -) +set(DELAUNAY_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/delaunay.h + PARENT_SCOPE + ) + +set(DELAUNAY_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/delaunay.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/delaunay/delaunay.cpp b/core/delaunay/delaunay.cpp index 788210062..81635e52a 100644 --- a/core/delaunay/delaunay.cpp +++ b/core/delaunay/delaunay.cpp @@ -7,12 +7,12 @@ * \author Spirin Egor */ -#include "core/delaunay/delaunay.h" +#include "delaunay/delaunay.h" -#include "core/math/mathUtils.h" -#include "core/delaunay/delaunay.h" +#include "math/mathUtils.h" +#include "delaunay/delaunay.h" -#include "core/geometry/conic.h" +#include "geometry/conic.h" namespace corecvs { diff --git a/core/delaunay/delaunay.h b/core/delaunay/delaunay.h index 695b6b56b..5c995e046 100644 --- a/core/delaunay/delaunay.h +++ b/core/delaunay/delaunay.h @@ -12,8 +12,8 @@ #include -#include "core/math/vector/vector2d.h" -#include "core/geometry/triangle.h" +#include "math/vector/vector2d.h" +#include "geometry/triangle.h" namespace corecvs { diff --git a/core/edgedetector/cannyDetector.cpp b/core/edgedetector/cannyDetector.cpp index 5822cf39c..00161f8be 100644 --- a/core/edgedetector/cannyDetector.cpp +++ b/core/edgedetector/cannyDetector.cpp @@ -4,7 +4,7 @@ * \date Oct 19, 2013 **/ -#include "core/edgedetector/cannyDetector.h" +#include "edgedetector/cannyDetector.h" #if 0 void CannyDetector::recursiveEdgeProver(G12Buffer *buffer, int h, int w) { diff --git a/core/edgedetector/cannyDetector.h b/core/edgedetector/cannyDetector.h index e1df8a051..8c938ee79 100644 --- a/core/edgedetector/cannyDetector.h +++ b/core/edgedetector/cannyDetector.h @@ -7,8 +7,8 @@ **/ #if 0 -#include "core/buffers/g12Buffer.h" -#include "core/xml/generated/cannyParameters.h" +#include "buffers/g12Buffer.h" +#include "xml/generated/cannyParameters.h" using corecvs::G12Buffer; diff --git a/core/features2d/bufferReaderProvider.cpp b/core/features2d/bufferReaderProvider.cpp index ac89578d4..5e5bfd9e5 100644 --- a/core/features2d/bufferReaderProvider.cpp +++ b/core/features2d/bufferReaderProvider.cpp @@ -1,4 +1,4 @@ -#include "core/features2d/bufferReaderProvider.h" +#include "features2d/bufferReaderProvider.h" using corecvs::RuntimeTypeBuffer; diff --git a/core/features2d/bufferReaderProvider.h b/core/features2d/bufferReaderProvider.h index d9fc156fa..15c9db027 100644 --- a/core/features2d/bufferReaderProvider.h +++ b/core/features2d/bufferReaderProvider.h @@ -4,8 +4,8 @@ #include #include -#include "core/buffers/runtimeTypeBuffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "buffers/runtimeTypeBuffer.h" +#include "buffers/rgb24/rgb24Buffer.h" /** * This class is depricated. Use BufferFactory instead diff --git a/core/features2d/descriptorExtractorProvider.cpp b/core/features2d/descriptorExtractorProvider.cpp index 208464b6e..19ac17cd7 100644 --- a/core/features2d/descriptorExtractorProvider.cpp +++ b/core/features2d/descriptorExtractorProvider.cpp @@ -1,6 +1,6 @@ -#include "core/features2d/descriptorExtractorProvider.h" +#include "features2d/descriptorExtractorProvider.h" -#include "core/utils/global.h" +#include "utils/global.h" DescriptorExtractor* DescriptorExtractorProvider::getDescriptorExtractor(const DescriptorType &type, const std::string ¶ms) diff --git a/core/features2d/descriptorExtractorProvider.h b/core/features2d/descriptorExtractorProvider.h index f365a1a7e..b51d8cf3c 100644 --- a/core/features2d/descriptorExtractorProvider.h +++ b/core/features2d/descriptorExtractorProvider.h @@ -1,7 +1,7 @@ #pragma once -#include "core/features2d/imageKeyPoints.h" -#include "core/filters/newstyle/algoBase.h" +#include "features2d/imageKeyPoints.h" +#include "filters/newstyle/algoBase.h" class DescriptorExtractor : public virtual AlgoBase diff --git a/core/features2d/descriptorMatcherProvider.cpp b/core/features2d/descriptorMatcherProvider.cpp index c30506828..c02cd0820 100644 --- a/core/features2d/descriptorMatcherProvider.cpp +++ b/core/features2d/descriptorMatcherProvider.cpp @@ -1,6 +1,6 @@ -#include "core/features2d/descriptorMatcherProvider.h" +#include "features2d/descriptorMatcherProvider.h" -#include "core/utils/global.h" +#include "utils/global.h" using namespace corecvs; diff --git a/core/features2d/descriptorMatcherProvider.h b/core/features2d/descriptorMatcherProvider.h index d77fc2fa3..4ce1c8202 100644 --- a/core/features2d/descriptorMatcherProvider.h +++ b/core/features2d/descriptorMatcherProvider.h @@ -1,7 +1,7 @@ #pragma once -#include "core/features2d/descriptorExtractorProvider.h" -#include "core/features2d/imageMatches.h" +#include "features2d/descriptorExtractorProvider.h" +#include "features2d/imageMatches.h" class DescriptorMatcher : public virtual AlgoBase { diff --git a/core/features2d/featureDetectorProvider.cpp b/core/features2d/featureDetectorProvider.cpp index c96d004e2..9161580ae 100644 --- a/core/features2d/featureDetectorProvider.cpp +++ b/core/features2d/featureDetectorProvider.cpp @@ -1,6 +1,6 @@ -#include "core/features2d/featureDetectorProvider.h" +#include "features2d/featureDetectorProvider.h" -#include "core/utils/global.h" +#include "utils/global.h" using namespace corecvs; using namespace std; diff --git a/core/features2d/featureDetectorProvider.h b/core/features2d/featureDetectorProvider.h index e86fec30e..4a5aa6398 100644 --- a/core/features2d/featureDetectorProvider.h +++ b/core/features2d/featureDetectorProvider.h @@ -1,7 +1,7 @@ #pragma once -#include "core/features2d/imageKeyPoints.h" -#include "core/features2d/algoBase.h" +#include "features2d/imageKeyPoints.h" +#include "features2d/algoBase.h" class FeatureDetector : public virtual AlgoBase { diff --git a/core/features2d/featureMatchingPipeline.cpp b/core/features2d/featureMatchingPipeline.cpp index 5684368c5..0ee69c60b 100644 --- a/core/features2d/featureMatchingPipeline.cpp +++ b/core/features2d/featureMatchingPipeline.cpp @@ -1,13 +1,13 @@ -#include "core/features2d/featureMatchingPipeline.h" -#include "core/features2d/featureDetectorProvider.h" -#include "core/features2d/descriptorExtractorProvider.h" -#include "core/features2d/descriptorMatcherProvider.h" -#include "core/features2d/detectExtractAndMatchProvider.h" -#include "core/features2d/detectAndExtractProvider.h" -#include "core/features2d/bufferReaderProvider.h" -#include "core/features2d/vsfmIo.h" -#include "core/buffers/bufferFactory.h" -#include "core/utils/utils.h" +#include "features2d/featureMatchingPipeline.h" +#include "features2d/featureDetectorProvider.h" +#include "features2d/descriptorExtractorProvider.h" +#include "features2d/descriptorMatcherProvider.h" +#include "features2d/detectExtractAndMatchProvider.h" +#include "features2d/detectAndExtractProvider.h" +#include "features2d/bufferReaderProvider.h" +#include "features2d/vsfmIo.h" +#include "buffers/bufferFactory.h" +#include "utils/utils.h" #include #include diff --git a/core/features2d/featureMatchingPipeline.h b/core/features2d/featureMatchingPipeline.h index 4720f86d5..dc2b0e7fb 100644 --- a/core/features2d/featureMatchingPipeline.h +++ b/core/features2d/featureMatchingPipeline.h @@ -4,13 +4,13 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/features2d/imageKeyPoints.h" -#include "core/features2d/imageMatches.h" // RawMatches -#include "core/features2d/matchingPlan.h" // MatchPlan -#include "core/utils/statusTracker.h" -#include "core/tbbwrapper/tbbWrapper.h" // tbb::spin_mutex +#include "features2d/imageKeyPoints.h" +#include "features2d/imageMatches.h" // RawMatches +#include "features2d/matchingPlan.h" // MatchPlan +#include "utils/statusTracker.h" +#include "tbbwrapper/tbbWrapper.h" // tbb::spin_mutex class FeatureMatchingPipeline; diff --git a/core/features2d/imageKeyPoints.cpp b/core/features2d/imageKeyPoints.cpp index cf1c1023c..c35193429 100644 --- a/core/features2d/imageKeyPoints.cpp +++ b/core/features2d/imageKeyPoints.cpp @@ -1,6 +1,6 @@ -#include "core/features2d/imageKeyPoints.h" +#include "features2d/imageKeyPoints.h" -#include "core/utils/global.h" +#include "utils/global.h" #include #include diff --git a/core/features2d/imageKeyPoints.h b/core/features2d/imageKeyPoints.h index e99784e57..a5913709f 100644 --- a/core/features2d/imageKeyPoints.h +++ b/core/features2d/imageKeyPoints.h @@ -4,10 +4,10 @@ #include #include -#include "core/buffers/runtimeTypeBuffer.h" -#include "core/buffers/rgb24/rgbColor.h" +#include "buffers/runtimeTypeBuffer.h" +#include "buffers/rgb24/rgbColor.h" -#include "core/features2d/algoBase.h" +#include "features2d/algoBase.h" struct KeyPointArea { diff --git a/core/features2d/imageMatches.cpp b/core/features2d/imageMatches.cpp index 67067027d..d5f9a6f7d 100644 --- a/core/features2d/imageMatches.cpp +++ b/core/features2d/imageMatches.cpp @@ -1,6 +1,6 @@ -#include "core/features2d/imageMatches.h" +#include "features2d/imageMatches.h" -#include "core/utils/global.h" +#include "utils/global.h" #include #include diff --git a/core/features2d/matchingPlan.cpp b/core/features2d/matchingPlan.cpp index 832172ed5..40d30a3c4 100644 --- a/core/features2d/matchingPlan.cpp +++ b/core/features2d/matchingPlan.cpp @@ -1,6 +1,6 @@ -#include "core/features2d/matchingPlan.h" +#include "features2d/matchingPlan.h" -#include "core/utils/global.h" +#include "utils/global.h" #include diff --git a/core/features2d/vsfmIo.cpp b/core/features2d/vsfmIo.cpp index 4337283ff..05a55b837 100644 --- a/core/features2d/vsfmIo.cpp +++ b/core/features2d/vsfmIo.cpp @@ -1,6 +1,6 @@ -#include "core/features2d/vsfmIo.h" +#include "features2d/vsfmIo.h" -#include "core/utils/global.h" +#include "utils/global.h" #define BYTES_MAGIC(a, b, c, d) \ ((uint32_t(d) << 24) | (uint32_t(c) << 16) | (uint32_t(b) << 8) | uint32_t(a)) diff --git a/core/fileformats/CMakeLists.txt b/core/fileformats/CMakeLists.txt index ef15349ce..0bbcb24dd 100644 --- a/core/fileformats/CMakeLists.txt +++ b/core/fileformats/CMakeLists.txt @@ -1,63 +1,69 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/bufferLoader.h - ${CMAKE_CURRENT_LIST_DIR}/bmpLoader.h - ${CMAKE_CURRENT_LIST_DIR}/ppmLoader.h - ${CMAKE_CURRENT_LIST_DIR}/rawLoader.h - ${CMAKE_CURRENT_LIST_DIR}/plyLoader.h - ${CMAKE_CURRENT_LIST_DIR}/stlLoader.h - ${CMAKE_CURRENT_LIST_DIR}/metamap.h - ${CMAKE_CURRENT_LIST_DIR}/floLoader.h - ${CMAKE_CURRENT_LIST_DIR}/openCVDataLoader.h - ${CMAKE_CURRENT_LIST_DIR}/tgaLoader.h - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/entities/dxfEntity.h - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/entities/dxfEntityData.h - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/objects/dxfObject.h - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/objects/dxfObjectData.h - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/blocks/dxfBlock.h - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfDrawing.h - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfCodes.h - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfLoader.h - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfBuilder.h +set(FILEFORMATS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/bufferLoader.h + ${CMAKE_CURRENT_LIST_DIR}/bmpLoader.h + ${CMAKE_CURRENT_LIST_DIR}/ppmLoader.h + ${CMAKE_CURRENT_LIST_DIR}/rawLoader.h + ${CMAKE_CURRENT_LIST_DIR}/plyLoader.h + ${CMAKE_CURRENT_LIST_DIR}/stlLoader.h + ${CMAKE_CURRENT_LIST_DIR}/metamap.h + ${CMAKE_CURRENT_LIST_DIR}/floLoader.h + ${CMAKE_CURRENT_LIST_DIR}/openCVDataLoader.h + ${CMAKE_CURRENT_LIST_DIR}/tgaLoader.h + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/entities/dxfEntity.h + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/entities/dxfEntityData.h + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/objects/dxfObject.h + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/objects/dxfObjectData.h + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/blocks/dxfBlock.h + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfDrawing.h + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfCodes.h + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfLoader.h + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfBuilder.h + ) - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/bufferLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/bmpLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/ppmLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/rawLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/plyLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/stlLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/floLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/openCVDataLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/tgaLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/entities/dxfEntity.cpp - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/objects/dxfObject.cpp - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/blocks/dxfBlock.cpp - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfDrawing.cpp - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfCodes.cpp - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfBuilder.cpp -) +set(FILEFORMATS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/bufferLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/bmpLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/ppmLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/rawLoader.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/plyLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/stlLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/floLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/openCVDataLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/tgaLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/entities/dxfEntity.cpp + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/objects/dxfObject.cpp + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/blocks/dxfBlock.cpp + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfDrawing.cpp + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfCodes.cpp + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfBuilder.cpp + ) -if (1) +if(1) - target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/meshLoader.h - ${CMAKE_CURRENT_LIST_DIR}/objLoader.h - ${CMAKE_CURRENT_LIST_DIR}/gcodeLoader.h - ${CMAKE_CURRENT_LIST_DIR}/pltLoader.h - ${CMAKE_CURRENT_LIST_DIR}/xyzListLoader.h - ${CMAKE_CURRENT_LIST_DIR}/svgLoader.h - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfLoader.h - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/meshLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/objLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/gcodeLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/pltLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/xyzListLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/svgLoader.cpp - ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfLoader.cpp +set(FILEFORMATS_HEADER_FILES + ${FILEFORMATS_HEADER_FILES} + ${CMAKE_CURRENT_LIST_DIR}/meshLoader.h + ${CMAKE_CURRENT_LIST_DIR}/objLoader.h + ${CMAKE_CURRENT_LIST_DIR}/gcodeLoader.h + ${CMAKE_CURRENT_LIST_DIR}/pltLoader.h + ${CMAKE_CURRENT_LIST_DIR}/xyzListLoader.h + ${CMAKE_CURRENT_LIST_DIR}/svgLoader.h + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfLoader.h + PARENT_SCOPE + ) + +set(FILEFORMATS_SOURCE_FILES + ${FILEFORMATS_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/meshLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/objLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/gcodeLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/pltLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/xyzListLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/svgLoader.cpp + ${CMAKE_CURRENT_LIST_DIR}/dxf_support/dxfLoader.cpp ) endif() + +set(FILEFORMATS_HEADER_FILES ${FILEFORMATS_HEADER_FILES} PARENT_SCOPE) +set(FILEFORMATS_SOURCE_FILES ${FILEFORMATS_SOURCE_FILES} PARENT_SCOPE) diff --git a/core/fileformats/bmpLoader.cpp b/core/fileformats/bmpLoader.cpp index c4c40c458..e4e1cbbf1 100644 --- a/core/fileformats/bmpLoader.cpp +++ b/core/fileformats/bmpLoader.cpp @@ -7,8 +7,8 @@ * \author alexander */ -#include "core/fileformats/bmpLoader.h" -#include "core/utils/utils.h" +#include "fileformats/bmpLoader.h" +#include "utils/utils.h" #include #include diff --git a/core/fileformats/bmpLoader.h b/core/fileformats/bmpLoader.h index 3c967ba0d..8e2f0e278 100644 --- a/core/fileformats/bmpLoader.h +++ b/core/fileformats/bmpLoader.h @@ -10,11 +10,11 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/fileformats/bufferLoader.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "fileformats/bufferLoader.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" namespace corecvs { diff --git a/core/fileformats/bufferLoader.cpp b/core/fileformats/bufferLoader.cpp index a9c4b85e9..d31f91129 100644 --- a/core/fileformats/bufferLoader.cpp +++ b/core/fileformats/bufferLoader.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/fileformats/bufferLoader.h" +#include "fileformats/bufferLoader.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/blocks/dxfBlock.cpp b/core/fileformats/dxf_support/blocks/dxfBlock.cpp index 8ca621caa..5d604d7b1 100644 --- a/core/fileformats/dxf_support/blocks/dxfBlock.cpp +++ b/core/fileformats/dxf_support/blocks/dxfBlock.cpp @@ -2,8 +2,8 @@ // Created by Myasnikov Vladislav on 23.12.2019. // -#include "core/fileformats/dxf_support/blocks/dxfBlock.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "fileformats/dxf_support/blocks/dxfBlock.h" +#include "buffers/rgb24/rgb24Buffer.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/blocks/dxfBlock.h b/core/fileformats/dxf_support/blocks/dxfBlock.h index 1b8220c77..d046fffb9 100644 --- a/core/fileformats/dxf_support/blocks/dxfBlock.h +++ b/core/fileformats/dxf_support/blocks/dxfBlock.h @@ -6,9 +6,9 @@ #define DXF_SUPPORT_DXFBLOCK_H #include -#include "core/fileformats/dxf_support/entities/dxfEntity.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/math/vector/vector3d.h" +#include "fileformats/dxf_support/entities/dxfEntity.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "math/vector/vector3d.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/dxfBuilder.cpp b/core/fileformats/dxf_support/dxfBuilder.cpp index ca47078ff..fa2cac20d 100644 --- a/core/fileformats/dxf_support/dxfBuilder.cpp +++ b/core/fileformats/dxf_support/dxfBuilder.cpp @@ -2,7 +2,7 @@ // Created by Myasnikov Vladislav on 21.10.2019. // -#include "core/fileformats/dxf_support/dxfBuilder.h" +#include "fileformats/dxf_support/dxfBuilder.h" #include namespace corecvs { diff --git a/core/fileformats/dxf_support/dxfBuilder.h b/core/fileformats/dxf_support/dxfBuilder.h index 1c1e9a4eb..93dcabfba 100644 --- a/core/fileformats/dxf_support/dxfBuilder.h +++ b/core/fileformats/dxf_support/dxfBuilder.h @@ -8,12 +8,12 @@ #include #include #include -#include "core/fileformats/dxf_support/dxfCodes.h" -#include "core/fileformats/dxf_support/dxfDrawing.h" -#include "core/fileformats/dxf_support/objects/dxfObject.h" -#include "core/fileformats/dxf_support/entities/dxfEntity.h" -#include "core/fileformats/dxf_support/blocks/dxfBlock.h" -#include "core/math/vector/vector3d.h" +#include "fileformats/dxf_support/dxfCodes.h" +#include "fileformats/dxf_support/dxfDrawing.h" +#include "fileformats/dxf_support/objects/dxfObject.h" +#include "fileformats/dxf_support/entities/dxfEntity.h" +#include "fileformats/dxf_support/blocks/dxfBlock.h" +#include "math/vector/vector3d.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/dxfCodes.cpp b/core/fileformats/dxf_support/dxfCodes.cpp index 97a89447d..25432f887 100644 --- a/core/fileformats/dxf_support/dxfCodes.cpp +++ b/core/fileformats/dxf_support/dxfCodes.cpp @@ -2,7 +2,7 @@ // Created by Myasnikov Vladislav on 21.10.2019. // -#include "core/fileformats/dxf_support/dxfCodes.h" +#include "fileformats/dxf_support/dxfCodes.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/dxfDrawing.cpp b/core/fileformats/dxf_support/dxfDrawing.cpp index ed7e68a67..29119838b 100644 --- a/core/fileformats/dxf_support/dxfDrawing.cpp +++ b/core/fileformats/dxf_support/dxfDrawing.cpp @@ -2,7 +2,7 @@ // Created by Myasnikov Vladislav on 23.12.2019. // -#include "core/fileformats/dxf_support/dxfDrawing.h" +#include "fileformats/dxf_support/dxfDrawing.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/dxfDrawing.h b/core/fileformats/dxf_support/dxfDrawing.h index 9d88fc349..0d38e73e6 100644 --- a/core/fileformats/dxf_support/dxfDrawing.h +++ b/core/fileformats/dxf_support/dxfDrawing.h @@ -4,13 +4,13 @@ // Created by Myasnikov Vladislav on 5.12.2019. // -#include "core/fileformats/dxf_support/dxfCodes.h" -#include "core/fileformats/dxf_support/objects/dxfObject.h" -#include "core/fileformats/dxf_support/entities/dxfEntity.h" -#include "core/fileformats/dxf_support/blocks/dxfBlock.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" +#include "fileformats/dxf_support/dxfCodes.h" +#include "fileformats/dxf_support/objects/dxfObject.h" +#include "fileformats/dxf_support/entities/dxfEntity.h" +#include "fileformats/dxf_support/blocks/dxfBlock.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/dxfLoader.cpp b/core/fileformats/dxf_support/dxfLoader.cpp index b03dcd78c..7bd125b3e 100644 --- a/core/fileformats/dxf_support/dxfLoader.cpp +++ b/core/fileformats/dxf_support/dxfLoader.cpp @@ -2,12 +2,12 @@ // Created by Myasnikov Vladislav on 17.10.2019. // -#include "core/fileformats/dxf_support/dxfLoader.h" -#include "core/fileformats/dxf_support/dxfCodes.h" -#include "core/fileformats/dxf_support/dxfBuilder.h" -#include "core/utils/utils.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/rgb24/rgbColor.h" +#include "fileformats/dxf_support/dxfLoader.h" +#include "fileformats/dxf_support/dxfCodes.h" +#include "fileformats/dxf_support/dxfBuilder.h" +#include "utils/utils.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/rgbColor.h" #include #include #include diff --git a/core/fileformats/dxf_support/dxfLoader.h b/core/fileformats/dxf_support/dxfLoader.h index 98799ae14..85cec0696 100644 --- a/core/fileformats/dxf_support/dxfLoader.h +++ b/core/fileformats/dxf_support/dxfLoader.h @@ -5,14 +5,14 @@ #ifndef DXF_SUPPORT_DXFLOADER_H #define DXF_SUPPORT_DXFLOADER_H -#include "core/fileformats/dxf_support/dxfCodes.h" -#include "core/fileformats/dxf_support/dxfBuilder.h" -#include "core/buffers/rgb24/wuRasterizer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/rgb24/abstractPainter.h" -#include "core/fileformats/bufferLoader.h" -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" +#include "fileformats/dxf_support/dxfCodes.h" +#include "fileformats/dxf_support/dxfBuilder.h" +#include "buffers/rgb24/wuRasterizer.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/abstractPainter.h" +#include "fileformats/bufferLoader.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" #include namespace corecvs { diff --git a/core/fileformats/dxf_support/entities/dxfEntity.cpp b/core/fileformats/dxf_support/entities/dxfEntity.cpp index 725f1304a..f0074f59c 100644 --- a/core/fileformats/dxf_support/entities/dxfEntity.cpp +++ b/core/fileformats/dxf_support/entities/dxfEntity.cpp @@ -3,12 +3,12 @@ // #include -#include "core/fileformats/dxf_support/entities/dxfEntity.h" -#include "core/geometry/conic.h" -#include "core/utils/utils.h" -#include "core/buffers/rgb24/bezierRasterizer.h" -#include "core/buffers/rgb24/wuRasterizer.h" -#include "core/buffers/rgb24/abstractPainter.h" +#include "fileformats/dxf_support/entities/dxfEntity.h" +#include "geometry/conic.h" +#include "utils/utils.h" +#include "buffers/rgb24/bezierRasterizer.h" +#include "buffers/rgb24/wuRasterizer.h" +#include "buffers/rgb24/abstractPainter.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/entities/dxfEntity.h b/core/fileformats/dxf_support/entities/dxfEntity.h index c3f15b335..7912984b6 100644 --- a/core/fileformats/dxf_support/entities/dxfEntity.h +++ b/core/fileformats/dxf_support/entities/dxfEntity.h @@ -6,10 +6,10 @@ #define DXF_SUPPORT_DXFENTITY_H #include -#include "core/fileformats/dxf_support/dxfDrawing.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/fileformats/dxf_support/dxfCodes.h" -#include "core/fileformats/dxf_support/entities/dxfEntityData.h" +#include "fileformats/dxf_support/dxfDrawing.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "fileformats/dxf_support/dxfCodes.h" +#include "fileformats/dxf_support/entities/dxfEntityData.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/entities/dxfEntityData.h b/core/fileformats/dxf_support/entities/dxfEntityData.h index 19c94cf64..8bf1f6115 100644 --- a/core/fileformats/dxf_support/entities/dxfEntityData.h +++ b/core/fileformats/dxf_support/entities/dxfEntityData.h @@ -6,11 +6,11 @@ #define DXF_SUPPORT_DXFENTITYDATA_H #include -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/fileformats/dxf_support/blocks/dxfBlock.h" -#include "core/fileformats/dxf_support/entities/dxfEntity.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "fileformats/dxf_support/blocks/dxfBlock.h" +#include "fileformats/dxf_support/entities/dxfEntity.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/objects/dxfObject.cpp b/core/fileformats/dxf_support/objects/dxfObject.cpp index b84a4def7..f2e1a1a10 100644 --- a/core/fileformats/dxf_support/objects/dxfObject.cpp +++ b/core/fileformats/dxf_support/objects/dxfObject.cpp @@ -3,7 +3,7 @@ // #include -#include "core/fileformats/dxf_support/objects/dxfObject.h" +#include "fileformats/dxf_support/objects/dxfObject.h" namespace corecvs { diff --git a/core/fileformats/dxf_support/objects/dxfObject.h b/core/fileformats/dxf_support/objects/dxfObject.h index 828a0427d..556c591e9 100644 --- a/core/fileformats/dxf_support/objects/dxfObject.h +++ b/core/fileformats/dxf_support/objects/dxfObject.h @@ -6,7 +6,7 @@ #define DXF_SUPPORT_DXFOBJECT_H #include -#include "core/fileformats/dxf_support/objects/dxfObjectData.h" +#include "fileformats/dxf_support/objects/dxfObjectData.h" namespace corecvs { diff --git a/core/fileformats/floLoader.cpp b/core/fileformats/floLoader.cpp index 8f2c44ac7..5ec3d7c4d 100644 --- a/core/fileformats/floLoader.cpp +++ b/core/fileformats/floLoader.cpp @@ -1,5 +1,5 @@ -#include "core/fileformats/floLoader.h" -#include "core/utils/utils.h" +#include "fileformats/floLoader.h" +#include "utils/utils.h" #include "stdint.h" #include diff --git a/core/fileformats/floLoader.h b/core/fileformats/floLoader.h index 19d858ad8..edb1522bb 100644 --- a/core/fileformats/floLoader.h +++ b/core/fileformats/floLoader.h @@ -1,8 +1,8 @@ #ifndef FLOLOADER_H #define FLOLOADER_H -#include "core/buffers/flow/flowBuffer.h" -#include "core/buffers/flow/floatFlowBuffer.h" +#include "buffers/flow/flowBuffer.h" +#include "buffers/flow/floatFlowBuffer.h" #include "bufferLoader.h" diff --git a/core/fileformats/gcodeLoader.cpp b/core/fileformats/gcodeLoader.cpp index ecc945cd1..06214a5a4 100644 --- a/core/fileformats/gcodeLoader.cpp +++ b/core/fileformats/gcodeLoader.cpp @@ -1,5 +1,5 @@ -#include "core/fileformats/gcodeLoader.h" -#include "core/utils/utils.h" +#include "fileformats/gcodeLoader.h" +#include "utils/utils.h" #include #include diff --git a/core/fileformats/gcodeLoader.h b/core/fileformats/gcodeLoader.h index 75fa83f92..23fdb0a32 100644 --- a/core/fileformats/gcodeLoader.h +++ b/core/fileformats/gcodeLoader.h @@ -3,15 +3,15 @@ #include #include -#include "core/xml/generated/drawGCodeParameters.h" +#include "xml/generated/drawGCodeParameters.h" -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/geometry/polygons.h" +#include "geometry/mesh/mesh3d.h" +#include "geometry/polygons.h" -#include "core/xml/generated/gCodeColoringSheme.h" +#include "xml/generated/gCodeColoringSheme.h" namespace corecvs { diff --git a/core/fileformats/meshLoader.cpp b/core/fileformats/meshLoader.cpp index 6e5ea0551..b909c7f27 100644 --- a/core/fileformats/meshLoader.cpp +++ b/core/fileformats/meshLoader.cpp @@ -1,10 +1,10 @@ -#include "core/fileformats/meshLoader.h" -#include "core/fileformats/plyLoader.h" -#include "core/fileformats/stlLoader.h" -#include "core/fileformats/objLoader.h" -#include "core/fileformats/gcodeLoader.h" -#include "core/fileformats/xyzListLoader.h" -#include "core/utils/utils.h" +#include "fileformats/meshLoader.h" +#include "fileformats/plyLoader.h" +#include "fileformats/stlLoader.h" +#include "fileformats/objLoader.h" +#include "fileformats/gcodeLoader.h" +#include "fileformats/xyzListLoader.h" +#include "utils/utils.h" #include using namespace std; diff --git a/core/fileformats/meshLoader.h b/core/fileformats/meshLoader.h index 4e69f7f4f..a1e82f6d2 100644 --- a/core/fileformats/meshLoader.h +++ b/core/fileformats/meshLoader.h @@ -10,8 +10,8 @@ */ #include -#include "core/utils/global.h" -#include "core/geometry/mesh/mesh3d.h" +#include "utils/global.h" +#include "geometry/mesh/mesh3d.h" namespace corecvs { diff --git a/core/fileformats/objLoader.cpp b/core/fileformats/objLoader.cpp index 248d35404..bda1fa214 100644 --- a/core/fileformats/objLoader.cpp +++ b/core/fileformats/objLoader.cpp @@ -2,11 +2,11 @@ #include #include -#include "core/fileformats/objLoader.h" -#include "core/utils/utils.h" -#include "core/buffers/bufferFactory.h" +#include "fileformats/objLoader.h" +#include "utils/utils.h" +#include "buffers/bufferFactory.h" -#include "core/fileformats/bmpLoader.h" +#include "fileformats/bmpLoader.h" using namespace std; diff --git a/core/fileformats/objLoader.h b/core/fileformats/objLoader.h index 2dfe867be..0e79d35c6 100644 --- a/core/fileformats/objLoader.h +++ b/core/fileformats/objLoader.h @@ -9,13 +9,14 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/geometry/mesh/mesh3DDecorated.h" +#include "geometry/mesh/mesh3d.h" +#include "geometry/mesh/mesh3DDecorated.h" -#include "core/buffers/rgb24/rgb24Buffer.h" + +#include "buffers/rgb24/rgb24Buffer.h" namespace corecvs { using std::vector; diff --git a/core/fileformats/openCVDataLoader.h b/core/fileformats/openCVDataLoader.h index 14337c593..15b496837 100644 --- a/core/fileformats/openCVDataLoader.h +++ b/core/fileformats/openCVDataLoader.h @@ -1,10 +1,10 @@ #ifndef OPENCVDATALOADER_H #define OPENCVDATALOADER_H -#include "core/tinyxml2/tinyxml2.h" -#include "core/math/matrix/matrix.h" +#include "tinyxml2/tinyxml2.h" +#include "math/matrix/matrix.h" -#include "core/cameracalibration/cameraModel.h" +#include "cameracalibration/cameraModel.h" namespace corecvs { diff --git a/core/fileformats/pltLoader.cpp b/core/fileformats/pltLoader.cpp index fd3135f53..4b806632c 100644 --- a/core/fileformats/pltLoader.cpp +++ b/core/fileformats/pltLoader.cpp @@ -1,5 +1,5 @@ #include "pltLoader.h" -#include "core/utils/utils.h" +#include "utils/utils.h" #include diff --git a/core/fileformats/plyLoader.cpp b/core/fileformats/plyLoader.cpp index d7787550a..1510a7bb1 100644 --- a/core/fileformats/plyLoader.cpp +++ b/core/fileformats/plyLoader.cpp @@ -6,8 +6,8 @@ #include -#include "core/fileformats/plyLoader.h" -#include "core/utils/utils.h" +#include "fileformats/plyLoader.h" +#include "utils/utils.h" namespace corecvs { @@ -167,9 +167,9 @@ int PLYLoader::loadPLY(istream &input, Mesh3D &mesh) for (int k = 0; k < OBJ_LAST; k++) { - for (unsigned i = 0; i < objProps[k].size(); i++) + for (size_t i = 0; i < objProps[k].size(); i++) { - LOCAL_PRINT(("%d %s %s \n",i , Prop::typeToStr(objProps[k][i].type), Prop::nameToStr(objProps[k][i].name))); + LOCAL_PRINT(("%d %s %s \n", (int)i , Prop::typeToStr(objProps[k][i].type), Prop::nameToStr(objProps[k][i].name))); } LOCAL_PRINT(("\n")); } @@ -312,7 +312,7 @@ int PLYLoader::loadPLY(istream &input, Mesh3D &mesh) if (edgeColor) { work >> mesh.currentColor; - LOCAL_PRINT(("Color %d %d %d\n", mesh.currentColor.r(), mesh.currentColor.g(), mesh.currentColor.b())); + // LOCAL_PRINT(("Edge Color %d %d %d\n", mesh.currentColor.r(), mesh.currentColor.g(), mesh.currentColor.b())); } if (!edge.isInHypercube( @@ -338,11 +338,14 @@ int PLYLoader::loadPLY(istream &input, Mesh3D &mesh) SYNC_PRINT(("Unexpected EOF on vertex number %d\n", i)); return 1; } - float f; + //float f; Vector3dd vertex; - input.read((char *)&f, sizeof(f)); vertex.x() = f; - input.read((char *)&f, sizeof(f)); vertex.y() = f; - input.read((char *)&f, sizeof(f)); vertex.z() = f; + //input.read((char *)&f, sizeof(f)); vertex.x() = f; + //input.read((char *)&f, sizeof(f)); vertex.y() = f; + //input.read((char *)&f, sizeof(f)); vertex.z() = f; + vertex.x() = objProps[OBJ_VERTEX][0].getDouble(input); + vertex.y() = objProps[OBJ_VERTEX][1].getDouble(input); + vertex.z() = objProps[OBJ_VERTEX][2].getDouble(input); if (input.bad()) { SYNC_PRINT(("Corrupted vertex number %d\n", i)); @@ -399,17 +402,21 @@ int PLYLoader::loadPLY(istream &input, Mesh3D &mesh) SYNC_PRINT(("Unexpected EOF on vertex number %d\n", i)); return 1; } - float f; - Vector3dd vertex; - input.read((char *)&f, sizeof(f)); vertex.x() = f; - input.read((char *)&f, sizeof(f)); vertex.y() = f; - input.read((char *)&f, sizeof(f)); vertex.z() = f; + //float f; + Vector3dd vertex; + //input.read((char *)&f, sizeof(f)); vertex.x() = f; + //input.read((char *)&f, sizeof(f)); vertex.y() = f; + //input.read((char *)&f, sizeof(f)); vertex.z() = f; + vertex.x() = objProps[OBJ_VERTEX][0].getDouble(input); + vertex.y() = objProps[OBJ_VERTEX][1].getDouble(input); + vertex.z() = objProps[OBJ_VERTEX][2].getDouble(input); + // LOCAL_PRINT(("Position [%lf %lf %lf]\n", vertex.x(), vertex.y(), vertex.z())); if (vertexColor) { input.read((char *)&mesh.currentColor.r(), sizeof(uint8_t)); input.read((char *)&mesh.currentColor.g(), sizeof(uint8_t)); input.read((char *)&mesh.currentColor.b(), sizeof(uint8_t)); - LOCAL_PRINT(("Color %d %d %d\n", mesh.currentColor.r(), mesh.currentColor.g(), mesh.currentColor.b())); + // LOCAL_PRINT(("Color %d %d %d\n", mesh.currentColor.r(), mesh.currentColor.g(), mesh.currentColor.b())); } if (input.bad()) { SYNC_PRINT(("Corrupted vertex number %d\n", i)); @@ -425,7 +432,7 @@ int PLYLoader::loadPLY(istream &input, Mesh3D &mesh) #undef LOCAL_PRINT -int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) +int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format, bool useDouble, bool forceNoAlpha) { vector &vertexes = mesh.vertexes; vector &faces = mesh.faces; @@ -435,6 +442,9 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) vector &facesColor = mesh.facesColor;; vector &edgesColor = mesh.edgesColor;; + bool alpha = (format != PlyFormat::ASCII); + if (forceNoAlpha) alpha = false; + out << "ply" << std::endl; if (format == PlyFormat::ASCII) { out << "format ascii 1.0" << std::endl; @@ -442,15 +452,18 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) out << "format binary_little_endian 1.0" << std::endl; } + string coordType = useDouble ? "double" : "float"; + + out << "comment made by CVS software" << std::endl; out << "element vertex " << vertexes.size() << std::endl; - out << "property float x" << std::endl; - out << "property float y" << std::endl; - out << "property float z" << std::endl; + out << "property " << coordType << " x" << std::endl; + out << "property " << coordType << " y" << std::endl; + out << "property " << coordType << " z" << std::endl; out << "property uchar red" << std::endl; out << "property uchar green" << std::endl; out << "property uchar blue" << std::endl; - if (format != PlyFormat::ASCII) { + if (alpha) { out << "property uchar alpha" << std::endl; } @@ -463,7 +476,7 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) out << "property uchar red" << std::endl; out << "property uchar green" << std::endl; out << "property uchar blue" << std::endl; - if (format != PlyFormat::ASCII) { + if (alpha) { out << "property uchar alpha" << std::endl; } } @@ -477,7 +490,7 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) out << "property uchar red" << std::endl; out << "property uchar green" << std::endl; out << "property uchar blue" << std::endl; - if (format != PlyFormat::ASCII) { + if (alpha) { out << "property uchar alpha" << std::endl; } } @@ -485,7 +498,7 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) out << "end_header" << std::endl; if (format == PlyFormat::ASCII) { - for (unsigned i = 0; i < vertexes.size(); i++) + for (size_t i = 0; i < vertexes.size(); i++) { out << vertexes[i].x() << " " << vertexes[i].y() << " " @@ -506,7 +519,7 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) out << std::endl; } - for (unsigned i = 0; i < faces.size(); i++) + for (size_t i = 0; i < faces.size(); i++) { out << "3 " << faces[i].x() << " " @@ -520,7 +533,7 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) out << std::endl; } - for (unsigned i = 0; i < edges.size(); i++) + for (size_t i = 0; i < edges.size(); i++) { out << edges[i].x() << " " << edges[i].y() << " "; @@ -532,14 +545,20 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) out << std::endl; } } else { - for (unsigned i = 0; i < vertexes.size(); i++) + for (size_t i = 0; i < vertexes.size(); i++) { - float x = vertexes[i].x(); - float y = vertexes[i].y(); - float z = vertexes[i].z(); - out.write((char *)&x, sizeof(float)) ; - out.write((char *)&y, sizeof(float)) ; - out.write((char *)&z, sizeof(float)) ; + if (useDouble) { + out.write((char *)&vertexes[i].x(), sizeof(double)); + out.write((char *)&vertexes[i].y(), sizeof(double)); + out.write((char *)&vertexes[i].z(), sizeof(double)); + } else { + float x = vertexes[i].x(); + float y = vertexes[i].y(); + float z = vertexes[i].z(); + out.write((char *)&x, sizeof(float)); + out.write((char *)&y, sizeof(float)); + out.write((char *)&z, sizeof(float)); + } unsigned char r = 128; unsigned char g = 128; @@ -554,11 +573,13 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) out.write((char *)&r, sizeof(unsigned char)) ; out.write((char *)&g, sizeof(unsigned char)) ; out.write((char *)&b, sizeof(unsigned char)) ; - out.write((char *)&a, sizeof(unsigned char)) ; + if (alpha) { + out.write((char *)&a, sizeof(unsigned char)) ; + } } - for (unsigned i = 0; i < faces.size(); i++) + for (size_t i = 0; i < faces.size(); i++) { unsigned char n = 3; int32_t i0 = faces[i].x(); @@ -578,10 +599,12 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) out.write((char *)&r, sizeof(unsigned char)); out.write((char *)&g, sizeof(unsigned char)); out.write((char *)&b, sizeof(unsigned char)); - out.write((char *)&a, sizeof(unsigned char)); + if (alpha) { + out.write((char *)&a, sizeof(unsigned char)); + } } } - for (unsigned i = 0; i < edges.size(); i++) + for (size_t i = 0; i < edges.size(); i++) { int32_t i0 = edges[i].x(); int32_t i1 = edges[i].y(); @@ -598,7 +621,9 @@ int PLYLoader::savePLY(ostream &out, Mesh3D &mesh, PlyFormat format) out.write((char *)&r, sizeof(unsigned char)); out.write((char *)&g, sizeof(unsigned char)); out.write((char *)&b, sizeof(unsigned char)); - out.write((char *)&a, sizeof(unsigned char)); + if (alpha) { + out.write((char *)&a, sizeof(unsigned char)); + } } } } @@ -624,6 +649,8 @@ istream &operator >>(istream &in, PLYLoader::Prop &toLoad) if (type == "float" ) toLoad.type = PLYLoader::PROP_TYPE_FLOAT; if (type == "float32") toLoad.type = PLYLoader::PROP_TYPE_FLOAT; + if (type == "double" ) toLoad.type = PLYLoader::PROP_TYPE_DOUBLE; + if (type == "uchar") toLoad.type = PLYLoader::PROP_TYPE_UCHAR; if (type == "uint8") toLoad.type = PLYLoader::PROP_TYPE_UCHAR; @@ -666,6 +693,7 @@ istream &operator >>(istream &in, PLYLoader::Prop &toLoad) if (name == "red") toLoad.name = PLYLoader::PROP_NAME_RED; if (name == "green") toLoad.name = PLYLoader::PROP_NAME_GREEN; if (name == "blue") toLoad.name = PLYLoader::PROP_NAME_BLUE; + if (name == "alpha") toLoad.name = PLYLoader::PROP_NAME_ALPHA; if (name == "cluster") toLoad.name = PLYLoader::PROP_NAME_CLUSTER; @@ -682,10 +710,11 @@ istream &operator >>(istream &in, PLYLoader::Prop &toLoad) const char *PLYLoader::Prop::typeToStr(PLYLoader::PropType type) { switch (type) { - case PROP_TYPE_FLOAT: return "float"; - case PROP_TYPE_UCHAR: return "uchar"; - case PROP_TYPE_INT : return "int"; - case PROP_TYPE_LIST : return "list"; + case PROP_TYPE_FLOAT : return "float"; + case PROP_TYPE_DOUBLE: return "double"; + case PROP_TYPE_UCHAR : return "uchar"; + case PROP_TYPE_INT : return "int"; + case PROP_TYPE_LIST : return "list"; default: return "unknown"; } @@ -697,11 +726,12 @@ const char *PLYLoader::Prop::nameToStr(PLYLoader::PropName name) case PROP_NAME_X: return "x"; case PROP_NAME_Y: return "y"; - case PROP_NAME_Z: return "z"; + case PROP_NAME_Z: return "z"; - case PROP_NAME_RED: return "red"; + case PROP_NAME_RED : return "red"; case PROP_NAME_GREEN: return "green"; case PROP_NAME_BLUE : return "blue"; + case PROP_NAME_ALPHA: return "alpha"; case PROP_NAME_VERTEX1: return "vertex1"; case PROP_NAME_VERTEX2: return "vertex2"; diff --git a/core/fileformats/plyLoader.h b/core/fileformats/plyLoader.h index 19963a7e8..c72797ba9 100644 --- a/core/fileformats/plyLoader.h +++ b/core/fileformats/plyLoader.h @@ -8,9 +8,9 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/geometry/mesh/mesh3d.h" +#include "geometry/mesh/mesh3d.h" namespace corecvs { @@ -26,6 +26,7 @@ class PLYLoader { enum PropType { PROP_TYPE_FLOAT, + PROP_TYPE_DOUBLE, PROP_TYPE_UCHAR, PROP_TYPE_INT, PROP_TYPE_LIST, @@ -40,6 +41,7 @@ class PLYLoader { PROP_NAME_RED, PROP_NAME_GREEN, PROP_NAME_BLUE, + PROP_NAME_ALPHA, PROP_NAME_CLUSTER, @@ -63,6 +65,35 @@ class PLYLoader { static const char *typeToStr(PropType type); static const char *nameToStr(PropName name); + + double getDouble(std::istream &input) { + double toReturn = 0; + switch (type) { + case PROP_TYPE_FLOAT: { + float f = 0.0f; + input.read((char *)&f, sizeof(f)); toReturn = f; + break; + }; + case PROP_TYPE_DOUBLE: { + double d = 0.0; + input.read((char *)&d, sizeof(d)); toReturn = d; + break; + } + case PROP_TYPE_UCHAR: { + unsigned char c = 0; + input.read((char *)&c, sizeof(c)); toReturn = c; + break; + } + case PROP_TYPE_INT: { + int32_t i = 0; + input.read((char *)&i, sizeof(i)); toReturn = i; + break; + } + default: + break; + } + return toReturn; + } }; enum ObjType { @@ -81,7 +112,7 @@ class PLYLoader { {} int loadPLY(std::istream &input, Mesh3D &mesh); - int savePLY(std::ostream &out, Mesh3D &mesh, PlyFormat format = PlyFormat::ASCII); + int savePLY(std::ostream &out, Mesh3D &mesh, PlyFormat format = PlyFormat::ASCII, bool useDouble = false, bool forceNoAlpha = false); virtual ~PLYLoader(); }; diff --git a/core/fileformats/ppmLoader.cpp b/core/fileformats/ppmLoader.cpp index 64bfce7f3..779c27eae 100644 --- a/core/fileformats/ppmLoader.cpp +++ b/core/fileformats/ppmLoader.cpp @@ -9,12 +9,13 @@ * \author alexander */ #include +#include -#include "core/utils/global.h" -#include "core/utils/utils.h" -#include "core/fileformats/ppmLoader.h" -#include "core/buffers/converters/debayer.h" -#include "core/utils/log.h" +#include "utils/global.h" +#include "utils/utils.h" +#include "fileformats/ppmLoader.h" +#include "buffers/converters/debayer.h" +#include "utils/log.h" namespace corecvs { diff --git a/core/fileformats/ppmLoader.h b/core/fileformats/ppmLoader.h index 875f55e5f..d9819519d 100644 --- a/core/fileformats/ppmLoader.h +++ b/core/fileformats/ppmLoader.h @@ -13,13 +13,13 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/fileformats/bufferLoader.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgbTBuffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/fileformats/metamap.h" +#include "fileformats/bufferLoader.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgbTBuffer.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "fileformats/metamap.h" namespace corecvs { diff --git a/core/fileformats/rawLoader.cpp b/core/fileformats/rawLoader.cpp index 711d8dab7..215cc9fc3 100644 --- a/core/fileformats/rawLoader.cpp +++ b/core/fileformats/rawLoader.cpp @@ -8,8 +8,8 @@ */ #include -#include "core/utils/utils.h" -#include "core/fileformats/rawLoader.h" +#include "utils/utils.h" +#include "fileformats/rawLoader.h" namespace corecvs { diff --git a/core/fileformats/rawLoader.h b/core/fileformats/rawLoader.h index 11c09098e..244a54c98 100644 --- a/core/fileformats/rawLoader.h +++ b/core/fileformats/rawLoader.h @@ -10,10 +10,10 @@ #include -#include "core/utils/global.h" -#include "core/fileformats/bufferLoader.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/g12Buffer.h" +#include "utils/global.h" +#include "fileformats/bufferLoader.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/g12Buffer.h" namespace corecvs { diff --git a/core/fileformats/stlLoader.cpp b/core/fileformats/stlLoader.cpp index 8e064090c..0900f5bb8 100644 --- a/core/fileformats/stlLoader.cpp +++ b/core/fileformats/stlLoader.cpp @@ -1,5 +1,5 @@ -#include "core/fileformats/stlLoader.h" -#include "core/utils/utils.h" +#include "fileformats/stlLoader.h" +#include "utils/utils.h" namespace corecvs { diff --git a/core/fileformats/stlLoader.h b/core/fileformats/stlLoader.h index 790e3e22a..21580d8f8 100644 --- a/core/fileformats/stlLoader.h +++ b/core/fileformats/stlLoader.h @@ -9,9 +9,9 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/geometry/mesh/mesh3d.h" +#include "geometry/mesh/mesh3d.h" namespace corecvs { diff --git a/core/fileformats/svgLoader.cpp b/core/fileformats/svgLoader.cpp index f3f19c91f..50d6610a6 100644 --- a/core/fileformats/svgLoader.cpp +++ b/core/fileformats/svgLoader.cpp @@ -9,12 +9,12 @@ #include -#include "core/buffers/rgb24/bresenhamRasterizer.h" -#include "core/buffers/rgb24/bezierRasterizer.h" +#include "buffers/rgb24/bresenhamRasterizer.h" +#include "buffers/rgb24/bezierRasterizer.h" -#include "core/utils/utils.h" -#include "core/tinyxml2/tinyxml2.h" -#include "core/fileformats/svgLoader.h" +#include "utils/utils.h" +#include "tinyxml2/tinyxml2.h" +#include "fileformats/svgLoader.h" namespace corecvs { @@ -70,7 +70,7 @@ int SvgLoader::loadSvg(istream &input, SvgFile &svg) int len = input.tellg(); input.seekg(0, input.beg); - char data[len]; + char* data = new char[len]; input.read(data, len); XMLDocument xml; diff --git a/core/fileformats/svgLoader.h b/core/fileformats/svgLoader.h index 0593cb14d..1f752d9ea 100644 --- a/core/fileformats/svgLoader.h +++ b/core/fileformats/svgLoader.h @@ -10,14 +10,14 @@ #include #include -#include "core/utils/utils.h" -#include "core/tinyxml2/tinyxml2.h" -#include "core/geometry/polygons.h" -#include "core/geometry/ellipse.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/rgb24/wuRasterizer.h" -#include "core/buffers/rgb24/abstractPainter.h" -#include "core/fileformats/bufferLoader.h" +#include "utils/utils.h" +#include "tinyxml2/tinyxml2.h" +#include "geometry/polygons.h" +#include "geometry/ellipse.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/wuRasterizer.h" +#include "buffers/rgb24/abstractPainter.h" +#include "fileformats/bufferLoader.h" namespace corecvs { diff --git a/core/fileformats/tgaLoader.cpp b/core/fileformats/tgaLoader.cpp index dd44625d6..bce325f9f 100644 --- a/core/fileformats/tgaLoader.cpp +++ b/core/fileformats/tgaLoader.cpp @@ -1,5 +1,5 @@ #include "tgaLoader.h" -#include "core/utils/utils.h" +#include "utils/utils.h" namespace corecvs { diff --git a/core/fileformats/tgaLoader.h b/core/fileformats/tgaLoader.h index 1e4da2b34..5b90906cc 100644 --- a/core/fileformats/tgaLoader.h +++ b/core/fileformats/tgaLoader.h @@ -11,11 +11,11 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/fileformats/bufferLoader.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "fileformats/bufferLoader.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" namespace corecvs { diff --git a/core/fileformats/xyzListLoader.cpp b/core/fileformats/xyzListLoader.cpp index db518e97c..9d4f2787f 100644 --- a/core/fileformats/xyzListLoader.cpp +++ b/core/fileformats/xyzListLoader.cpp @@ -1,8 +1,8 @@ #include #include -#include "core/fileformats/xyzListLoader.h" -#include "core/utils/utils.h" +#include "fileformats/xyzListLoader.h" +#include "utils/utils.h" namespace corecvs { diff --git a/core/fileformats/xyzListLoader.h b/core/fileformats/xyzListLoader.h index f12130f1a..0692743cd 100644 --- a/core/fileformats/xyzListLoader.h +++ b/core/fileformats/xyzListLoader.h @@ -2,7 +2,7 @@ #define XYZLISTLOADER_H #include -#include "core/geometry/mesh/mesh3d.h" +#include "geometry/mesh/mesh3d.h" namespace corecvs { diff --git a/core/filesystem/CMakeLists.txt b/core/filesystem/CMakeLists.txt index 06266d44f..3dccadb5c 100644 --- a/core/filesystem/CMakeLists.txt +++ b/core/filesystem/CMakeLists.txt @@ -1,9 +1,11 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/folderScanner.h - ${CMAKE_CURRENT_LIST_DIR}/tempFolder.h - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/folderScanner.cpp - ${CMAKE_CURRENT_LIST_DIR}/tempFolder.cpp -) +set(FILESYSTEM_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/folderScanner.h + ${CMAKE_CURRENT_LIST_DIR}/tempFolder.h + PARENT_SCOPE + ) + +set(FILESYSTEM_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/folderScanner.cpp + ${CMAKE_CURRENT_LIST_DIR}/tempFolder.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/filesystem/folderScanner.cpp b/core/filesystem/folderScanner.cpp index dfff993ce..c12efefc2 100644 --- a/core/filesystem/folderScanner.cpp +++ b/core/filesystem/folderScanner.cpp @@ -1,12 +1,16 @@ -#include "core/filesystem/folderScanner.h" -#include "core/utils/log.h" -#include "core/utils/utils.h" +#include "filesystem/folderScanner.h" +#include "utils/log.h" +#include "utils/utils.h" #include #if !defined(WITH_STD_FILESYSTEM) #include -#include +# if defined (_MSC_VER) +# include <../dirent_msvc.h> +# else +# include +# endif #include #endif diff --git a/core/filesystem/folderScanner.h b/core/filesystem/folderScanner.h index efc06c561..0dd9a8526 100644 --- a/core/filesystem/folderScanner.h +++ b/core/filesystem/folderScanner.h @@ -9,7 +9,7 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" using std::vector; using std::string; diff --git a/core/filesystem/tempFolder.cpp b/core/filesystem/tempFolder.cpp index 0e2a861a4..d619f2c4e 100644 --- a/core/filesystem/tempFolder.cpp +++ b/core/filesystem/tempFolder.cpp @@ -1,7 +1,7 @@ -#include "core/filesystem/tempFolder.h" -#include "core/utils/log.h" -#include "core/utils/utils.h" -#include "core/filesystem/folderScanner.h" +#include "filesystem/tempFolder.h" +#include "utils/log.h" +#include "utils/utils.h" +#include "filesystem/folderScanner.h" //#include diff --git a/core/filesystem/tempFolder.h b/core/filesystem/tempFolder.h index 29e7884c5..702df23bf 100644 --- a/core/filesystem/tempFolder.h +++ b/core/filesystem/tempFolder.h @@ -4,7 +4,7 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { diff --git a/core/filters/CMakeLists.txt b/core/filters/CMakeLists.txt index 5bb5bc35a..289bd8a46 100644 --- a/core/filters/CMakeLists.txt +++ b/core/filters/CMakeLists.txt @@ -1,23 +1,63 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/newstyle/newStyleBlock.h - ${CMAKE_CURRENT_LIST_DIR}/newstyle/algoBase.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/newstyle/newStyleBlock.cpp -) +set(FILTERS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/newstyle/newStyleBlock.h + ${CMAKE_CURRENT_LIST_DIR}/newstyle/algoBase.h + ) + +set(FILTERS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/newstyle/newStyleBlock.cpp + ) +SET(OLDFILTERS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/legacy/abstractFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/backgroundFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/binarizeBlock.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/bitSelectorFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/cannyFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/filterGraph.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/filtersCollection.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/gainOffsetFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/inputFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/maskFilterBlock.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/operationFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/outputFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/sobelFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/thickeningBlock.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/txtFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/blocks/compoundFilter.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/blocks/filterBlock.h + ${CMAKE_CURRENT_LIST_DIR}/legacy/blocks/pins.h + ) -set (OLDFILTERS_ - ${CMAKE_CURRENT_LIST_DIR}/legacy/*.h - ${CMAKE_CURRENT_LIST_DIR}/legacy/blocks/*.h - ${CMAKE_CURRENT_LIST_DIR}/legacy/*.cpp - ${CMAKE_CURRENT_LIST_DIR}/legacy/blocks/*.cpp +SET(OLDFILTERS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/legacy/abstractFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/backgroundFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/binarizeBlock.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/bitSelectorFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/cannyFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/filtersCollection.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/gainOffsetFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/inputFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/maskFilterBlock.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/operationFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/outputFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/sobelFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/thickeningBlock.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/txtFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/blocks/compoundFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/blocks/filterBlock.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/blocks/filterGraph.cpp + ${CMAKE_CURRENT_LIST_DIR}/legacy/blocks/pins.cpp ) +set(FILTERS_HEADER_FILES + ${FILTERS_HEADER_FILES} +# ${OLDFILTERS_HEADER_FILES} + ) + +set(FILTERS_SOURCE_FILES + ${FILTERS_SOURCE_FILES} +# ${OLDFILTERS_SOURCE_FILES} + ) -#with_oldfilters { -# $${OLDFILTERS_HEADERS} -# $${OLDFILTERS_SOURCES} -#} else { -# OTHER_FILES += $${OLDFILTERS_HEADERS} $${OLDFILTERS_SOURCES} -#} +set(FILTERS_HEADER_FILES ${FILTERS_HEADER_FILES} PARENT_SCOPE) +set(FILTERS_SOURCE_FILES ${FILTERS_SOURCE_FILES} PARENT_SCOPE) diff --git a/core/filters/legacy/abstractFilter.cpp b/core/filters/legacy/abstractFilter.cpp index 786040c56..81f570a67 100644 --- a/core/filters/legacy/abstractFilter.cpp +++ b/core/filters/legacy/abstractFilter.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/filters/legacy/abstractFilter.h" +#include "filters/legacy/abstractFilter.h" namespace corecvs { diff --git a/core/filters/legacy/abstractFilter.h b/core/filters/legacy/abstractFilter.h index d12c2ee6a..be18e1bdf 100644 --- a/core/filters/legacy/abstractFilter.h +++ b/core/filters/legacy/abstractFilter.h @@ -9,7 +9,7 @@ */ -#include "core/buffers/g12Buffer.h" +#include "buffers/g12Buffer.h" namespace corecvs { diff --git a/core/filters/legacy/backgroundFilter.cpp b/core/filters/legacy/backgroundFilter.cpp index 87bcb1575..c5f46d65a 100644 --- a/core/filters/legacy/backgroundFilter.cpp +++ b/core/filters/legacy/backgroundFilter.cpp @@ -5,9 +5,9 @@ * \date Oct 11, 2012 */ -#include "core/filters/legacy/backgroundFilter.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/backgroundFilter.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/backgroundFilter.h b/core/filters/legacy/backgroundFilter.h index c921742d8..3760de56b 100644 --- a/core/filters/legacy/backgroundFilter.h +++ b/core/filters/legacy/backgroundFilter.h @@ -6,9 +6,9 @@ * \date Oct 11, 2012 */ -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/xml/generated/backgroundFilterParameters.h" -#include "core/filters/legacy/filtersCollection.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "xml/generated/backgroundFilterParameters.h" +#include "filters/legacy/filtersCollection.h" namespace corecvs { diff --git a/core/filters/legacy/binarizeBlock.cpp b/core/filters/legacy/binarizeBlock.cpp index 21558ba5c..57fa56562 100644 --- a/core/filters/legacy/binarizeBlock.cpp +++ b/core/filters/legacy/binarizeBlock.cpp @@ -5,9 +5,9 @@ * \date Jan 17, 2013 */ -#include "core/filters/legacy/binarizeBlock.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/binarizeBlock.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/binarizeBlock.h b/core/filters/legacy/binarizeBlock.h index b2ca11462..de9c5a8df 100644 --- a/core/filters/legacy/binarizeBlock.h +++ b/core/filters/legacy/binarizeBlock.h @@ -6,8 +6,8 @@ * \date Jan 17, 2013 */ -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/xml/generated/binarizeParameters.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "xml/generated/binarizeParameters.h" namespace corecvs { diff --git a/core/filters/legacy/bitSelectorFilter.cpp b/core/filters/legacy/bitSelectorFilter.cpp index 1c459a76a..bf2edbd15 100644 --- a/core/filters/legacy/bitSelectorFilter.cpp +++ b/core/filters/legacy/bitSelectorFilter.cpp @@ -6,10 +6,10 @@ * \author alexander */ -#include "core/filters/legacy/bitSelectorFilter.h" -#include "core/buffers/commonMappers.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/bitSelectorFilter.h" +#include "buffers/commonMappers.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/bitSelectorFilter.h b/core/filters/legacy/bitSelectorFilter.h index 9f30685d8..53b033844 100644 --- a/core/filters/legacy/bitSelectorFilter.h +++ b/core/filters/legacy/bitSelectorFilter.h @@ -8,9 +8,9 @@ * \author alexander */ -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/xml/generated/bitSelectorParameters.h" -#include "core/filters/legacy/filtersCollection.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "xml/generated/bitSelectorParameters.h" +#include "filters/legacy/filtersCollection.h" namespace corecvs { diff --git a/core/filters/legacy/blocks/compoundFilter.cpp b/core/filters/legacy/blocks/compoundFilter.cpp index 0688417bb..f452db2a9 100644 --- a/core/filters/legacy/blocks/compoundFilter.cpp +++ b/core/filters/legacy/blocks/compoundFilter.cpp @@ -1,4 +1,4 @@ -#include "core/filters/legacy/blocks/compoundFilter.h" +#include "filters/legacy/blocks/compoundFilter.h" namespace corecvs { diff --git a/core/filters/legacy/blocks/compoundFilter.h b/core/filters/legacy/blocks/compoundFilter.h index ad49bf6a1..78bbaa9b5 100644 --- a/core/filters/legacy/blocks/compoundFilter.h +++ b/core/filters/legacy/blocks/compoundFilter.h @@ -1,9 +1,9 @@ #ifndef COMPOUNDFILTER_H #define COMPOUNDFILTER_H -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/filters/legacy/filterGraph.h" -#include "core/filters/legacy/filtersCollection.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "filters/legacy/filterGraph.h" +#include "filters/legacy/filtersCollection.h" namespace corecvs { diff --git a/core/filters/legacy/blocks/filterBlock.cpp b/core/filters/legacy/blocks/filterBlock.cpp index 58cac4086..963e653ba 100644 --- a/core/filters/legacy/blocks/filterBlock.cpp +++ b/core/filters/legacy/blocks/filterBlock.cpp @@ -4,9 +4,9 @@ * \date Nov 9, 2012 **/ -#include "core/filters/legacy/blocks/filterBlock.h" -//#include "core/filters/legacy/blocks/filterGraph.h" -#include "core/reflection/serializerVisitor.h" +#include "filters/legacy/blocks/filterBlock.h" +//#include "filters/legacy/blocks/filterGraph.h" +#include "reflection/serializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/blocks/filterBlock.h b/core/filters/legacy/blocks/filterBlock.h index b96c6d672..2d6f916ae 100644 --- a/core/filters/legacy/blocks/filterBlock.h +++ b/core/filters/legacy/blocks/filterBlock.h @@ -10,9 +10,9 @@ #include #include -#include "core/utils/global.h" -#include "core/reflection/reflection.h" -#include "core/filters/legacy/blocks/pins.h" +#include "utils/global.h" +#include "reflection/reflection.h" +#include "filters/legacy/blocks/pins.h" #include namespace corecvs diff --git a/core/filters/legacy/blocks/filterGraph.cpp b/core/filters/legacy/blocks/filterGraph.cpp index 8646b01d3..55f9c271e 100644 --- a/core/filters/legacy/blocks/filterGraph.cpp +++ b/core/filters/legacy/blocks/filterGraph.cpp @@ -1,5 +1,5 @@ -#include "core/filters/legacy/filterGraph.h" -#include "core/filters/legacy/blocks/compoundFilter.h" +#include "filters/legacy/filterGraph.h" +#include "filters/legacy/blocks/compoundFilter.h" namespace corecvs { diff --git a/core/filters/legacy/blocks/pins.cpp b/core/filters/legacy/blocks/pins.cpp index 6a14da79f..4b3af8bbe 100644 --- a/core/filters/legacy/blocks/pins.cpp +++ b/core/filters/legacy/blocks/pins.cpp @@ -1,6 +1,6 @@ -#include "core/filters/legacy/blocks/pins.h" -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/filters/legacy/filterGraph.h" +#include "filters/legacy/blocks/pins.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "filters/legacy/filterGraph.h" namespace corecvs { diff --git a/core/filters/legacy/blocks/pins.h b/core/filters/legacy/blocks/pins.h index b54ac70f4..d83922645 100644 --- a/core/filters/legacy/blocks/pins.h +++ b/core/filters/legacy/blocks/pins.h @@ -8,8 +8,8 @@ * \author dpiatkin */ -#include "core/buffers/g12Buffer.h" -#include "core/tinyxml2/tinyxml2.h" +#include "buffers/g12Buffer.h" +#include "tinyxml2/tinyxml2.h" namespace corecvs { diff --git a/core/filters/legacy/cannyFilter.cpp b/core/filters/legacy/cannyFilter.cpp index b1e72faa7..05f38d5a6 100644 --- a/core/filters/legacy/cannyFilter.cpp +++ b/core/filters/legacy/cannyFilter.cpp @@ -6,14 +6,14 @@ * \author a.melnikov */ -#include "core/filters/legacy/cannyFilter.h" -#include "core/buffers/kernels/fastkernel/fastKernel.h" -#include "core/buffers/kernels/fastkernel/scalarAlgebra.h" -#include "core/buffers/kernels/fastkernel/vectorAlgebra.h" -#include "core/buffers/kernels/fastkernel/vectorTraits.h" -#include "core/buffers/derivativeBuffer.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/cannyFilter.h" +#include "buffers/kernels/fastkernel/fastKernel.h" +#include "buffers/kernels/fastkernel/scalarAlgebra.h" +#include "buffers/kernels/fastkernel/vectorAlgebra.h" +#include "buffers/kernels/fastkernel/vectorTraits.h" +#include "buffers/derivativeBuffer.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/cannyFilter.h b/core/filters/legacy/cannyFilter.h index faa7d8985..5af90e5e0 100644 --- a/core/filters/legacy/cannyFilter.h +++ b/core/filters/legacy/cannyFilter.h @@ -8,11 +8,11 @@ * \author a.melnikov */ -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/xml/generated/cannyParameters.h" -#include "core/filters/legacy/filtersCollection.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/derivativeBuffer.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "xml/generated/cannyParameters.h" +#include "filters/legacy/filtersCollection.h" +#include "buffers/g12Buffer.h" +#include "buffers/derivativeBuffer.h" namespace corecvs { diff --git a/core/filters/legacy/filterGraph.h b/core/filters/legacy/filterGraph.h index ed15e56ff..a8aa7a95a 100644 --- a/core/filters/legacy/filterGraph.h +++ b/core/filters/legacy/filterGraph.h @@ -6,9 +6,9 @@ #include #include -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/filters/legacy/filtersCollection.h" -#include "core/stats/calculationStats.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "filters/legacy/filtersCollection.h" +#include "stats/calculationStats.h" namespace corecvs { diff --git a/core/filters/legacy/filtersCollection.cpp b/core/filters/legacy/filtersCollection.cpp index 88052fe4e..e75e70f39 100644 --- a/core/filters/legacy/filtersCollection.cpp +++ b/core/filters/legacy/filtersCollection.cpp @@ -1,18 +1,18 @@ -#include "core/filters/legacy/filtersCollection.h" - -#include "core/filters/legacy/sobelFilter.h" -#include "core/filters/legacy/gainOffsetFilter.h" -#include "core/filters/legacy/bitSelectorFilter.h" -#include "core/filters/legacy/cannyFilter.h" -#include "core/filters/legacy/backgroundFilter.h" -#include "core/filters/legacy/operationFilter.h" -#include "core/filters/legacy/inputFilter.h" -#include "core/filters/legacy/outputFilter.h" -#include "core/filters/legacy/txtFilter.h" -#include "core/filters/legacy/binarizeBlock.h" -#include "core/filters/legacy/thickeningBlock.h" -#include "core/filters/legacy/maskFilterBlock.h" -#include "core/filters/legacy/blocks/compoundFilter.h" +#include "filters/legacy/filtersCollection.h" + +#include "filters/legacy/sobelFilter.h" +#include "filters/legacy/gainOffsetFilter.h" +#include "filters/legacy/bitSelectorFilter.h" +#include "filters/legacy/cannyFilter.h" +#include "filters/legacy/backgroundFilter.h" +#include "filters/legacy/operationFilter.h" +#include "filters/legacy/inputFilter.h" +#include "filters/legacy/outputFilter.h" +#include "filters/legacy/txtFilter.h" +#include "filters/legacy/binarizeBlock.h" +#include "filters/legacy/thickeningBlock.h" +#include "filters/legacy/maskFilterBlock.h" +#include "filters/legacy/blocks/compoundFilter.h" namespace corecvs { diff --git a/core/filters/legacy/filtersCollection.h b/core/filters/legacy/filtersCollection.h index 884e35a5b..5ce46390d 100644 --- a/core/filters/legacy/filtersCollection.h +++ b/core/filters/legacy/filtersCollection.h @@ -1,8 +1,8 @@ #ifndef FILTERSCOLLECTION_H #define FILTERSCOLLECTION_H -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/tinyxml2/tinyxml2.h" // for XMLDocument here +#include "filters/legacy/blocks/filterBlock.h" +#include "tinyxml2/tinyxml2.h" // for XMLDocument here #include namespace corecvs diff --git a/core/filters/legacy/gainOffsetFilter.cpp b/core/filters/legacy/gainOffsetFilter.cpp index e4ea08b80..04ae7880b 100644 --- a/core/filters/legacy/gainOffsetFilter.cpp +++ b/core/filters/legacy/gainOffsetFilter.cpp @@ -6,11 +6,11 @@ * \author alexander */ -#include "core/filters/legacy/gainOffsetFilter.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/commonMappers.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/gainOffsetFilter.h" +#include "buffers/g12Buffer.h" +#include "buffers/commonMappers.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/gainOffsetFilter.h b/core/filters/legacy/gainOffsetFilter.h index bff645390..f565e06f3 100644 --- a/core/filters/legacy/gainOffsetFilter.h +++ b/core/filters/legacy/gainOffsetFilter.h @@ -1,9 +1,9 @@ #ifndef GAIN_OFFSET_FILTER_H_ #define GAIN_OFFSET_FILTER_H_ -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/buffers/g12Buffer.h" -#include "core/xml/generated/gainOffsetParameters.h" -#include "core/filters/legacy/filtersCollection.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "buffers/g12Buffer.h" +#include "xml/generated/gainOffsetParameters.h" +#include "filters/legacy/filtersCollection.h" /** * \file gainOffsetFilter.h diff --git a/core/filters/legacy/inputFilter.cpp b/core/filters/legacy/inputFilter.cpp index 2695b0f74..328b2dd3b 100644 --- a/core/filters/legacy/inputFilter.cpp +++ b/core/filters/legacy/inputFilter.cpp @@ -1,6 +1,6 @@ -#include "core/filters/legacy/inputFilter.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/inputFilter.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/inputFilter.h b/core/filters/legacy/inputFilter.h index fbbf0acb8..0ad95b99c 100644 --- a/core/filters/legacy/inputFilter.h +++ b/core/filters/legacy/inputFilter.h @@ -1,9 +1,9 @@ #ifndef INPUTFILTERBLOCK_H #define INPUTFILTERBLOCK_H -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/buffers/g12Buffer.h" -#include "core/xml/generated/inputFilterParameters.h" -#include "core/filters/legacy/filtersCollection.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "buffers/g12Buffer.h" +#include "xml/generated/inputFilterParameters.h" +#include "filters/legacy/filtersCollection.h" namespace corecvs { diff --git a/core/filters/legacy/maskFilterBlock.cpp b/core/filters/legacy/maskFilterBlock.cpp index 171d0ff30..4dce2fd9e 100644 --- a/core/filters/legacy/maskFilterBlock.cpp +++ b/core/filters/legacy/maskFilterBlock.cpp @@ -5,9 +5,9 @@ * \date Jan 17, 2013 */ -#include "core/filters/legacy/maskFilterBlock.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/maskFilterBlock.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/maskFilterBlock.h b/core/filters/legacy/maskFilterBlock.h index 351f0f1d1..3ef337666 100644 --- a/core/filters/legacy/maskFilterBlock.h +++ b/core/filters/legacy/maskFilterBlock.h @@ -6,8 +6,8 @@ * \date Jan 17, 2013 */ -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/xml/generated/maskingParameters.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "xml/generated/maskingParameters.h" namespace corecvs { diff --git a/core/filters/legacy/operationFilter.cpp b/core/filters/legacy/operationFilter.cpp index 47435066e..9002f1363 100644 --- a/core/filters/legacy/operationFilter.cpp +++ b/core/filters/legacy/operationFilter.cpp @@ -4,9 +4,9 @@ * \date Nov 11, 2012 **/ -#include "core/filters/legacy/operationFilter.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/operationFilter.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/operationFilter.h b/core/filters/legacy/operationFilter.h index fcfe0e5b4..6c890e23e 100644 --- a/core/filters/legacy/operationFilter.h +++ b/core/filters/legacy/operationFilter.h @@ -5,15 +5,15 @@ * * \date Nov 11, 2012 **/ -#include "core/buffers/g12Buffer.h" - -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/buffers/kernels/fastkernel/baseAlgebra.h" -#include "core/buffers/kernels/fastkernel/fastKernel.h" -#include "core/buffers/kernels/fastkernel/vectorTraits.h" -#include "core/buffers/kernels/arithmetic.h" -#include "core/filters/legacy/filtersCollection.h" -#include "core/xml/generated/operationParameters.h" +#include "buffers/g12Buffer.h" + +#include "filters/legacy/blocks/filterBlock.h" +#include "buffers/kernels/fastkernel/baseAlgebra.h" +#include "buffers/kernels/fastkernel/fastKernel.h" +#include "buffers/kernels/fastkernel/vectorTraits.h" +#include "buffers/kernels/arithmetic.h" +#include "filters/legacy/filtersCollection.h" +#include "xml/generated/operationParameters.h" namespace corecvs { diff --git a/core/filters/legacy/outputFilter.cpp b/core/filters/legacy/outputFilter.cpp index c979b8b73..ec34fcf90 100644 --- a/core/filters/legacy/outputFilter.cpp +++ b/core/filters/legacy/outputFilter.cpp @@ -1,6 +1,6 @@ -#include "core/filters/legacy/outputFilter.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/outputFilter.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/outputFilter.h b/core/filters/legacy/outputFilter.h index 07bbd4eef..dac853ab9 100644 --- a/core/filters/legacy/outputFilter.h +++ b/core/filters/legacy/outputFilter.h @@ -1,9 +1,9 @@ #ifndef OUTPUTFILTERBLOCK_H #define OUTPUTFILTERBLOCK_H -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/buffers/g12Buffer.h" -#include "core/xml/generated/outputFilterParameters.h" -#include "core/filters/legacy/filtersCollection.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "buffers/g12Buffer.h" +#include "xml/generated/outputFilterParameters.h" +#include "filters/legacy/filtersCollection.h" namespace corecvs { diff --git a/core/filters/legacy/sobelFilter.cpp b/core/filters/legacy/sobelFilter.cpp index b5e9e9996..0dd59e943 100644 --- a/core/filters/legacy/sobelFilter.cpp +++ b/core/filters/legacy/sobelFilter.cpp @@ -6,15 +6,15 @@ * \author alexander */ -#include "core/filters/legacy/sobelFilter.h" -#include "core/buffers/kernels/fastkernel/fastKernel.h" -#include "core/buffers/kernels/fastkernel/scalarAlgebra.h" -#include "core/buffers/kernels/fastkernel/vectorAlgebra.h" -#include "core/buffers/kernels/sobel.h" -#include "core/buffers/kernels/fastkernel/vectorTraits.h" -#include "core/buffers/derivativeBuffer.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/sobelFilter.h" +#include "buffers/kernels/fastkernel/fastKernel.h" +#include "buffers/kernels/fastkernel/scalarAlgebra.h" +#include "buffers/kernels/fastkernel/vectorAlgebra.h" +#include "buffers/kernels/sobel.h" +#include "buffers/kernels/fastkernel/vectorTraits.h" +#include "buffers/derivativeBuffer.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/sobelFilter.h b/core/filters/legacy/sobelFilter.h index 928bc84cf..e3ecc348d 100644 --- a/core/filters/legacy/sobelFilter.h +++ b/core/filters/legacy/sobelFilter.h @@ -8,10 +8,10 @@ * \author alexander */ -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/buffers/g12Buffer.h" -#include "core/xml/generated/sobelParameters.h" -#include "core/filters/legacy/filtersCollection.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "buffers/g12Buffer.h" +#include "xml/generated/sobelParameters.h" +#include "filters/legacy/filtersCollection.h" namespace corecvs { diff --git a/core/filters/legacy/thickeningBlock.cpp b/core/filters/legacy/thickeningBlock.cpp index cf8755595..b89ed56df 100644 --- a/core/filters/legacy/thickeningBlock.cpp +++ b/core/filters/legacy/thickeningBlock.cpp @@ -5,9 +5,9 @@ * \date Jan 17, 2013 */ -#include "core/filters/legacy/thickeningBlock.h" -#include "core/reflection/serializerVisitor.h" -#include "core/reflection/deserializerVisitor.h" +#include "filters/legacy/thickeningBlock.h" +#include "reflection/serializerVisitor.h" +#include "reflection/deserializerVisitor.h" namespace corecvs { diff --git a/core/filters/legacy/thickeningBlock.h b/core/filters/legacy/thickeningBlock.h index 8a37ea5cb..6d1d5b09a 100644 --- a/core/filters/legacy/thickeningBlock.h +++ b/core/filters/legacy/thickeningBlock.h @@ -6,8 +6,8 @@ * \date Jan 17, 2013 */ -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/xml/generated/thickeningParameters.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "xml/generated/thickeningParameters.h" namespace corecvs { diff --git a/core/filters/legacy/txtFilter.cpp b/core/filters/legacy/txtFilter.cpp index 9502aa586..1aa75ec0a 100644 --- a/core/filters/legacy/txtFilter.cpp +++ b/core/filters/legacy/txtFilter.cpp @@ -1,4 +1,4 @@ -#include "core/filters/legacy/txtFilter.h" +#include "filters/legacy/txtFilter.h" namespace corecvs { diff --git a/core/filters/legacy/txtFilter.h b/core/filters/legacy/txtFilter.h index 08079dd25..56e8e24ac 100644 --- a/core/filters/legacy/txtFilter.h +++ b/core/filters/legacy/txtFilter.h @@ -8,8 +8,8 @@ * \author dpiatkin */ -#include "core/filters/legacy/blocks/filterBlock.h" -#include "core/filters/legacy/filtersCollection.h" +#include "filters/legacy/blocks/filterBlock.h" +#include "filters/legacy/filtersCollection.h" namespace corecvs { diff --git a/core/filters/newstyle/algoBase.h b/core/filters/newstyle/algoBase.h index 0b8739a72..f4c2d1d8d 100644 --- a/core/filters/newstyle/algoBase.h +++ b/core/filters/newstyle/algoBase.h @@ -6,7 +6,7 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" // This interface is necessary to make possible class implementing both FeatureDetector/DescriptorExtractor interfaces class AlgoBase diff --git a/core/filters/newstyle/newStyleBlock.cpp b/core/filters/newstyle/newStyleBlock.cpp index adb5480be..d52d3194b 100644 --- a/core/filters/newstyle/newStyleBlock.cpp +++ b/core/filters/newstyle/newStyleBlock.cpp @@ -1,4 +1,4 @@ -#include "core/filters/newstyle/newStyleBlock.h" +#include "filters/newstyle/newStyleBlock.h" namespace corecvs { diff --git a/core/filters/newstyle/newStyleBlock.h b/core/filters/newstyle/newStyleBlock.h index 73e7395db..cee92903f 100644 --- a/core/filters/newstyle/newStyleBlock.h +++ b/core/filters/newstyle/newStyleBlock.h @@ -1,7 +1,7 @@ #ifndef NEWSTYLEBLOCK_H #define NEWSTYLEBLOCK_H -#include "core/xml/generated/adderSubstractorParametersBase.h" +#include "xml/generated/adderSubstractorParametersBase.h" namespace corecvs { diff --git a/core/framesources/CMakeLists.txt b/core/framesources/CMakeLists.txt index 4bb1f3c4f..83c429ba0 100644 --- a/core/framesources/CMakeLists.txt +++ b/core/framesources/CMakeLists.txt @@ -1,35 +1,33 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/frames.h - ${CMAKE_CURRENT_LIST_DIR}/cameraControlParameters.h - ${CMAKE_CURRENT_LIST_DIR}/dummyVideoEncoderInterface.h - ${CMAKE_CURRENT_LIST_DIR}/imageCaptureInterface.h - - ${CMAKE_CURRENT_LIST_DIR}/file/abstractFileCapture.h - ${CMAKE_CURRENT_LIST_DIR}/file/abstractFileCaptureSpinThread.h - ${CMAKE_CURRENT_LIST_DIR}/file/fileCapture.h - ${CMAKE_CURRENT_LIST_DIR}/file/imageFileCaptureInterface.h - ${CMAKE_CURRENT_LIST_DIR}/file/precCapture.h - - ${CMAKE_CURRENT_LIST_DIR}/decoders/aLowCodec.h - ${CMAKE_CURRENT_LIST_DIR}/decoders/decoupleYUYV.h - ${CMAKE_CURRENT_LIST_DIR}/decoders/mjpegDecoder.h - ${CMAKE_CURRENT_LIST_DIR}/decoders/mjpegDecoderLazy.h +set(FRAMESOURCES_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/frames.h + ${CMAKE_CURRENT_LIST_DIR}/cameraControlParameters.h + ${CMAKE_CURRENT_LIST_DIR}/dummyVideoEncoderInterface.h + ${CMAKE_CURRENT_LIST_DIR}/imageCaptureInterface.h + ${CMAKE_CURRENT_LIST_DIR}/file/abstractFileCapture.h + ${CMAKE_CURRENT_LIST_DIR}/file/abstractFileCaptureSpinThread.h + ${CMAKE_CURRENT_LIST_DIR}/file/fileCapture.h + ${CMAKE_CURRENT_LIST_DIR}/file/imageFileCaptureInterface.h + ${CMAKE_CURRENT_LIST_DIR}/file/precCapture.h + ${CMAKE_CURRENT_LIST_DIR}/decoders/aLowCodec.h + ${CMAKE_CURRENT_LIST_DIR}/decoders/decoupleYUYV.h + ${CMAKE_CURRENT_LIST_DIR}/decoders/mjpegDecoder.h + ${CMAKE_CURRENT_LIST_DIR}/decoders/mjpegDecoderLazy.h + PARENT_SCOPE + ) - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/frames.cpp - ${CMAKE_CURRENT_LIST_DIR}/cameraControlParameters.cpp - ${CMAKE_CURRENT_LIST_DIR}/dummyVideoEncoderInterface.cpp - ${CMAKE_CURRENT_LIST_DIR}/imageCaptureInterface.cpp - - ${CMAKE_CURRENT_LIST_DIR}/file/abstractFileCapture.cpp - ${CMAKE_CURRENT_LIST_DIR}/file/abstractFileCaptureSpinThread.cpp - ${CMAKE_CURRENT_LIST_DIR}/file/fileCapture.cpp - ${CMAKE_CURRENT_LIST_DIR}/file/imageFileCaptureInterface.cpp - ${CMAKE_CURRENT_LIST_DIR}/file/precCapture.cpp - - ${CMAKE_CURRENT_LIST_DIR}/decoders/aLowCodec.cpp - ${CMAKE_CURRENT_LIST_DIR}/decoders/decoupleYUYV.cpp - ${CMAKE_CURRENT_LIST_DIR}/decoders/mjpegDecoder.cpp - ${CMAKE_CURRENT_LIST_DIR}/decoders/mjpegDecoderLazy.cpp -) +set(FRAMESOURCES_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/frames.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraControlParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/dummyVideoEncoderInterface.cpp + ${CMAKE_CURRENT_LIST_DIR}/imageCaptureInterface.cpp + ${CMAKE_CURRENT_LIST_DIR}/file/abstractFileCapture.cpp + ${CMAKE_CURRENT_LIST_DIR}/file/abstractFileCaptureSpinThread.cpp + ${CMAKE_CURRENT_LIST_DIR}/file/fileCapture.cpp + ${CMAKE_CURRENT_LIST_DIR}/file/imageFileCaptureInterface.cpp + ${CMAKE_CURRENT_LIST_DIR}/file/precCapture.cpp + ${CMAKE_CURRENT_LIST_DIR}/decoders/aLowCodec.cpp + ${CMAKE_CURRENT_LIST_DIR}/decoders/decoupleYUYV.cpp + ${CMAKE_CURRENT_LIST_DIR}/decoders/mjpegDecoder.cpp + ${CMAKE_CURRENT_LIST_DIR}/decoders/mjpegDecoderLazy.cpp + PARENT_SCOPE + ) diff --git a/core/framesources/decoders/aLowCodec.cpp b/core/framesources/decoders/aLowCodec.cpp index 3941619a9..32eb368bd 100644 --- a/core/framesources/decoders/aLowCodec.cpp +++ b/core/framesources/decoders/aLowCodec.cpp @@ -9,10 +9,10 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" #include "aLowCodec.h" -//#include "core/buffers/rgb24/rgb24Buffer.h" +//#include "buffers/rgb24/rgb24Buffer.h" using namespace corecvs; diff --git a/core/framesources/decoders/aLowCodec.h b/core/framesources/decoders/aLowCodec.h index eef01f357..859c90351 100644 --- a/core/framesources/decoders/aLowCodec.h +++ b/core/framesources/decoders/aLowCodec.h @@ -9,8 +9,8 @@ #include -#include "core/utils/global.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "utils/global.h" +#include "buffers/rgb24/rgb24Buffer.h" namespace corecvs { diff --git a/core/framesources/decoders/decoupleYUYV.h b/core/framesources/decoders/decoupleYUYV.h index 22713e8ea..62d300bf4 100644 --- a/core/framesources/decoders/decoupleYUYV.h +++ b/core/framesources/decoders/decoupleYUYV.h @@ -9,10 +9,10 @@ */ -#include "core/framesources/imageCaptureInterface.h" -#include "core/buffers/kernels/fastkernel/readers.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/sseWrapper.h" +#include "framesources/imageCaptureInterface.h" +#include "buffers/kernels/fastkernel/readers.h" +#include "math/vector/fixedVector.h" +#include "math/sse/sseWrapper.h" namespace corecvs { diff --git a/core/framesources/decoders/mjpegDecoder.cpp b/core/framesources/decoders/mjpegDecoder.cpp index b6e1534c8..c5c6349cb 100644 --- a/core/framesources/decoders/mjpegDecoder.cpp +++ b/core/framesources/decoders/mjpegDecoder.cpp @@ -2,7 +2,7 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" #include "mjpegDecoder.h" diff --git a/core/framesources/decoders/mjpegDecoderLazy.cpp b/core/framesources/decoders/mjpegDecoderLazy.cpp index 5091a9833..304620eea 100644 --- a/core/framesources/decoders/mjpegDecoderLazy.cpp +++ b/core/framesources/decoders/mjpegDecoderLazy.cpp @@ -10,7 +10,7 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" //#define _TRACE #ifdef _TRACE diff --git a/core/framesources/decoders/mjpegDecoderLazy.h b/core/framesources/decoders/mjpegDecoderLazy.h index 69322ddd4..3a5eb12eb 100644 --- a/core/framesources/decoders/mjpegDecoderLazy.h +++ b/core/framesources/decoders/mjpegDecoderLazy.h @@ -12,8 +12,8 @@ #define MJPEGDECODERLAZY_H_ #include -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" using namespace corecvs; diff --git a/core/framesources/dummyVideoEncoderInterface.h b/core/framesources/dummyVideoEncoderInterface.h index 457f4558a..d5f0c92bc 100644 --- a/core/framesources/dummyVideoEncoderInterface.h +++ b/core/framesources/dummyVideoEncoderInterface.h @@ -1,7 +1,7 @@ #ifndef DUMMY_VIDEO_ENCODER_INTERFACE_H #define DUMMY_VIDEO_ENCODER_INTERFACE_H -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" #include namespace corecvs { diff --git a/core/framesources/file/abstractFileCapture.cpp b/core/framesources/file/abstractFileCapture.cpp index 9c00f9314..a71c94d6e 100644 --- a/core/framesources/file/abstractFileCapture.cpp +++ b/core/framesources/file/abstractFileCapture.cpp @@ -2,7 +2,7 @@ #include #include "abstractFileCapture.h" -#include "core/utils/utils.h" +#include "utils/utils.h" AbstractFileCapture::AbstractFileCapture(const std::string ¶ms) : mDelay(0) diff --git a/core/framesources/file/abstractFileCapture.h b/core/framesources/file/abstractFileCapture.h index b378ee1b0..236b47b28 100644 --- a/core/framesources/file/abstractFileCapture.h +++ b/core/framesources/file/abstractFileCapture.h @@ -2,7 +2,7 @@ #include -#include "core/framesources/file/imageFileCaptureInterface.h" +#include "framesources/file/imageFileCaptureInterface.h" #include "abstractFileCaptureSpinThread.h" /** diff --git a/core/framesources/file/abstractFileCaptureSpinThread.h b/core/framesources/file/abstractFileCaptureSpinThread.h index 80dd5899b..a2c929ede 100644 --- a/core/framesources/file/abstractFileCaptureSpinThread.h +++ b/core/framesources/file/abstractFileCaptureSpinThread.h @@ -1,7 +1,7 @@ #pragma once #include -#include "core/framesources/imageCaptureInterface.h" +#include "framesources/imageCaptureInterface.h" class AbstractFileCapture; diff --git a/core/framesources/file/fileCapture.cpp b/core/framesources/file/fileCapture.cpp index ff3efcda7..e606f21c0 100644 --- a/core/framesources/file/fileCapture.cpp +++ b/core/framesources/file/fileCapture.cpp @@ -9,10 +9,10 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" #include "fileCapture.h" -#include "core/buffers/bufferFactory.h" +#include "buffers/bufferFactory.h" /* File capture interface */ FileCaptureInterface::FileCaptureInterface(string pathFmt, bool isVerbose, bool isRGB) diff --git a/core/framesources/file/fileCapture.h b/core/framesources/file/fileCapture.h index f65d05481..b98bfa334 100644 --- a/core/framesources/file/fileCapture.h +++ b/core/framesources/file/fileCapture.h @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/framesources/file/imageFileCaptureInterface.h" +#include "framesources/file/imageFileCaptureInterface.h" #include "abstractFileCaptureSpinThread.h" #include "abstractFileCapture.h" diff --git a/core/framesources/file/imageFileCaptureInterface.cpp b/core/framesources/file/imageFileCaptureInterface.cpp index 73f56326b..28c84e889 100644 --- a/core/framesources/file/imageFileCaptureInterface.cpp +++ b/core/framesources/file/imageFileCaptureInterface.cpp @@ -5,9 +5,9 @@ * \date Nov 20, 2012 * \author s.fedorenko */ -#include "core/utils/global.h" -#include "core/utils/utils.h" -#include "core/filesystem/folderScanner.h" +#include "utils/global.h" +#include "utils/utils.h" +#include "filesystem/folderScanner.h" #include "imageFileCaptureInterface.h" @@ -73,7 +73,7 @@ string ImageFileCaptureInterface::getImageFileName(uint imageNumber, uint channe mPathPrefix = "../"; } #ifdef WIN32 - else if (HelperUtils::pathExists((string("../../../../") + pathName).c_str())) + else if (FolderScanner::pathExists((string("../../../../") + pathName).c_str())) { mPathPrefix = "../../../../"; } diff --git a/core/framesources/file/imageFileCaptureInterface.h b/core/framesources/file/imageFileCaptureInterface.h index 925b82902..4fa1858a0 100644 --- a/core/framesources/file/imageFileCaptureInterface.h +++ b/core/framesources/file/imageFileCaptureInterface.h @@ -1,7 +1,7 @@ #pragma once #include -#include "core/framesources/imageCaptureInterface.h" +#include "framesources/imageCaptureInterface.h" class ImageFileCaptureInterface : public virtual ImageCaptureInterface { diff --git a/core/framesources/file/precCapture.cpp b/core/framesources/file/precCapture.cpp index 6a3861a96..7504e295a 100644 --- a/core/framesources/file/precCapture.cpp +++ b/core/framesources/file/precCapture.cpp @@ -9,12 +9,12 @@ #include #include -#include "core/utils/global.h" -#include "core/utils/utils.h" -#include "core/filesystem/folderScanner.h" +#include "utils/global.h" +#include "utils/utils.h" +#include "filesystem/folderScanner.h" #include "precCapture.h" -#include "core/buffers/bufferFactory.h" +#include "buffers/bufferFactory.h" /** Capture interface with precise simulation from the value "fps" view point */ diff --git a/core/framesources/file/precCapture.h b/core/framesources/file/precCapture.h index 50e862cdd..5aa9f2ef4 100644 --- a/core/framesources/file/precCapture.h +++ b/core/framesources/file/precCapture.h @@ -6,7 +6,7 @@ * \date Jan 9, 2015 * \author alexander */ -#include "core/framesources/file/imageFileCaptureInterface.h" +#include "framesources/file/imageFileCaptureInterface.h" #include "abstractFileCaptureSpinThread.h" #include "abstractFileCapture.h" diff --git a/core/framesources/frames.cpp b/core/framesources/frames.cpp index 1dadbca80..cabc9e2be 100644 --- a/core/framesources/frames.cpp +++ b/core/framesources/frames.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/framesources/frames.h" +#include "framesources/frames.h" Frames::Frames() { diff --git a/core/framesources/frames.h b/core/framesources/frames.h index 508126ccd..fbe4ad5fd 100644 --- a/core/framesources/frames.h +++ b/core/framesources/frames.h @@ -9,10 +9,10 @@ */ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/g12Buffer.h" -#include "core/framesources/imageCaptureInterface.h" +#include "buffers/g12Buffer.h" +#include "framesources/imageCaptureInterface.h" class Frames { diff --git a/core/framesources/imageCaptureInterface.cpp b/core/framesources/imageCaptureInterface.cpp index ee40ca15f..a32ea1012 100644 --- a/core/framesources/imageCaptureInterface.cpp +++ b/core/framesources/imageCaptureInterface.cpp @@ -10,7 +10,7 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" #include "imageCaptureInterface.h" #include "cameraControlParameters.h" diff --git a/core/framesources/imageCaptureInterface.h b/core/framesources/imageCaptureInterface.h index b880adf97..2f4a7e5fb 100644 --- a/core/framesources/imageCaptureInterface.h +++ b/core/framesources/imageCaptureInterface.h @@ -9,8 +9,8 @@ #include -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" using namespace corecvs; diff --git a/core/function/CMakeLists.txt b/core/function/CMakeLists.txt index 8300e6314..257e2eb40 100644 --- a/core/function/CMakeLists.txt +++ b/core/function/CMakeLists.txt @@ -1,7 +1,9 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/function.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/function.cpp +set(FUNCTION_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/function.h + PARENT_SCOPE + ) -) +set(FUNCTION_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/function.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/function/function.cpp b/core/function/function.cpp index 9f29ac91a..9f65b8a59 100644 --- a/core/function/function.cpp +++ b/core/function/function.cpp @@ -1,4 +1,4 @@ -#include "core/function/function.h" +#include "function/function.h" namespace corecvs { diff --git a/core/function/function.h b/core/function/function.h index 1d1a168a2..3133bcbd3 100644 --- a/core/function/function.h +++ b/core/function/function.h @@ -12,10 +12,10 @@ #include #include -#include "core/utils/global.h" -#include "core/math/matrix/matrix.h" -#include "core/math/sparseMatrix.h" -#include "core/math/vector/vector.h" +#include "utils/global.h" +#include "math/matrix/matrix.h" +#include "math/sparseMatrix.h" +#include "math/vector/vector.h" #include "wrappers/cblasLapack/cblasLapackeWrapper.h" namespace corecvs { diff --git a/core/geometry/CMakeLists.txt b/core/geometry/CMakeLists.txt index 0cdaaf2a5..f6fec2ba7 100644 --- a/core/geometry/CMakeLists.txt +++ b/core/geometry/CMakeLists.txt @@ -1,79 +1,73 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/ellipticalApproximation.h - ${CMAKE_CURRENT_LIST_DIR}/axisAlignedBox.h - ${CMAKE_CURRENT_LIST_DIR}/rectangle.h - ${CMAKE_CURRENT_LIST_DIR}/line.h - ${CMAKE_CURRENT_LIST_DIR}/triangulation.h - ${CMAKE_CURRENT_LIST_DIR}/polygons.h - ${CMAKE_CURRENT_LIST_DIR}/vptree.h - ${CMAKE_CURRENT_LIST_DIR}/convexPolyhedron.h - ${CMAKE_CURRENT_LIST_DIR}/conic.h - ${CMAKE_CURRENT_LIST_DIR}/polygonPointIterator.h - # ${CMAKE_CURRENT_LIST_DIR}/projection.h - ${CMAKE_CURRENT_LIST_DIR}/gentryState.h - ${CMAKE_CURRENT_LIST_DIR}/twoViewOptimalTriangulation.h - ${CMAKE_CURRENT_LIST_DIR}/ellipse.h - ${CMAKE_CURRENT_LIST_DIR}/ellipseFit.h - ${CMAKE_CURRENT_LIST_DIR}/plane3dFit.h - ${CMAKE_CURRENT_LIST_DIR}/convexHull.h - ${CMAKE_CURRENT_LIST_DIR}/convexHull3d.h - ${CMAKE_CURRENT_LIST_DIR}/convexQuickHull.h - ${CMAKE_CURRENT_LIST_DIR}/projectiveConvexQuickHull.h - ${CMAKE_CURRENT_LIST_DIR}/pointCloud.h - ${CMAKE_CURRENT_LIST_DIR}/halfspaceIntersector.h - ${CMAKE_CURRENT_LIST_DIR}/orientedBox.h - ${CMAKE_CURRENT_LIST_DIR}/plane.h - ${CMAKE_CURRENT_LIST_DIR}/kdtree.h - ${CMAKE_CURRENT_LIST_DIR}/beziercurve.h - ${CMAKE_CURRENT_LIST_DIR}/raytrace/bspTree.h - - ${CMAKE_CURRENT_LIST_DIR}/mesh/mesh3d.h - ${CMAKE_CURRENT_LIST_DIR}/mesh/mesh3DDecorated.h - ${CMAKE_CURRENT_LIST_DIR}/mesh/meshClicker.h - ${CMAKE_CURRENT_LIST_DIR}/mesh/meshFilter.h - ${CMAKE_CURRENT_LIST_DIR}/mesh/meshCache.h - - - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/ellipticalApproximation.cpp - ${CMAKE_CURRENT_LIST_DIR}/axisAlignedBox.cpp - ${CMAKE_CURRENT_LIST_DIR}/rectangle.cpp - ${CMAKE_CURRENT_LIST_DIR}/triangulation.cpp - ${CMAKE_CURRENT_LIST_DIR}/polygons.cpp - ${CMAKE_CURRENT_LIST_DIR}/convexPolyhedron.cpp - ${CMAKE_CURRENT_LIST_DIR}/conic.cpp - ${CMAKE_CURRENT_LIST_DIR}/polygonPointIterator.cpp - # ${CMAKE_CURRENT_LIST_DIR}/projection.cpp - ${CMAKE_CURRENT_LIST_DIR}/gentryState.cpp - ${CMAKE_CURRENT_LIST_DIR}/twoViewOptimalTriangulation.cpp - ${CMAKE_CURRENT_LIST_DIR}/ellipse.cpp - ${CMAKE_CURRENT_LIST_DIR}/ellipseFit.cpp - ${CMAKE_CURRENT_LIST_DIR}/plane3dFit.cpp - ${CMAKE_CURRENT_LIST_DIR}/convexHull.cpp - ${CMAKE_CURRENT_LIST_DIR}/convexHull3d.cpp - ${CMAKE_CURRENT_LIST_DIR}/convexQuickHull.cpp - ${CMAKE_CURRENT_LIST_DIR}/projectiveConvexQuickHull.cpp - ${CMAKE_CURRENT_LIST_DIR}/pointCloud.cpp - - ${CMAKE_CURRENT_LIST_DIR}/halfspaceIntersector.cpp - ${CMAKE_CURRENT_LIST_DIR}/orientedBox.cpp - ${CMAKE_CURRENT_LIST_DIR}/plane.cpp - - ${CMAKE_CURRENT_LIST_DIR}/mesh/mesh3d.cpp - ${CMAKE_CURRENT_LIST_DIR}/mesh/mesh3DDecorated.cpp - ${CMAKE_CURRENT_LIST_DIR}/mesh/meshClicker.cpp - ${CMAKE_CURRENT_LIST_DIR}/mesh/meshFilter.cpp - ${CMAKE_CURRENT_LIST_DIR}/mesh/meshCache.cpp +set(GEOMETRY_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/ellipticalApproximation.h + ${CMAKE_CURRENT_LIST_DIR}/axisAlignedBox.h + ${CMAKE_CURRENT_LIST_DIR}/rectangle.h + ${CMAKE_CURRENT_LIST_DIR}/line.h + ${CMAKE_CURRENT_LIST_DIR}/triangulation.h + ${CMAKE_CURRENT_LIST_DIR}/polygons.h + ${CMAKE_CURRENT_LIST_DIR}/mesh/mesh3d.h + ${CMAKE_CURRENT_LIST_DIR}/vptree.h + ${CMAKE_CURRENT_LIST_DIR}/convexPolyhedron.h + ${CMAKE_CURRENT_LIST_DIR}/conic.h + ${CMAKE_CURRENT_LIST_DIR}/polygonPointIterator.h +# ${CMAKE_CURRENT_LIST_DIR}/projection.h + ${CMAKE_CURRENT_LIST_DIR}/gentryState.h + ${CMAKE_CURRENT_LIST_DIR}/twoViewOptimalTriangulation.h + ${CMAKE_CURRENT_LIST_DIR}/mesh/mesh3DDecorated.h + ${CMAKE_CURRENT_LIST_DIR}/ellipse.h + ${CMAKE_CURRENT_LIST_DIR}/ellipseFit.h + ${CMAKE_CURRENT_LIST_DIR}/plane3dFit.h + ${CMAKE_CURRENT_LIST_DIR}/mesh/meshClicker.h + ${CMAKE_CURRENT_LIST_DIR}/mesh/meshFilter.h + ${CMAKE_CURRENT_LIST_DIR}/mesh/meshCache.h + ${CMAKE_CURRENT_LIST_DIR}/convexHull.h + ${CMAKE_CURRENT_LIST_DIR}/convexHull3d.h + ${CMAKE_CURRENT_LIST_DIR}/convexQuickHull.h + ${CMAKE_CURRENT_LIST_DIR}/projectiveConvexQuickHull.h + ${CMAKE_CURRENT_LIST_DIR}/pointCloud.h + ${CMAKE_CURRENT_LIST_DIR}/halfspaceIntersector.h + ${CMAKE_CURRENT_LIST_DIR}/orientedBox.h + ${CMAKE_CURRENT_LIST_DIR}/plane.h + ${CMAKE_CURRENT_LIST_DIR}/kdtree.h + ${CMAKE_CURRENT_LIST_DIR}/beziercurve.h + ${CMAKE_CURRENT_LIST_DIR}/raytrace/bspTree.h + ) -) +set(GEOMETRY_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/ellipticalApproximation.cpp + ${CMAKE_CURRENT_LIST_DIR}/axisAlignedBox.cpp + ${CMAKE_CURRENT_LIST_DIR}/rectangle.cpp + ${CMAKE_CURRENT_LIST_DIR}/triangulation.cpp + ${CMAKE_CURRENT_LIST_DIR}/polygons.cpp + ${CMAKE_CURRENT_LIST_DIR}/mesh/mesh3d.cpp + ${CMAKE_CURRENT_LIST_DIR}/convexPolyhedron.cpp + ${CMAKE_CURRENT_LIST_DIR}/conic.cpp + ${CMAKE_CURRENT_LIST_DIR}/polygonPointIterator.cpp +# ${CMAKE_CURRENT_LIST_DIR}/projection.cpp + ${CMAKE_CURRENT_LIST_DIR}/gentryState.cpp + ${CMAKE_CURRENT_LIST_DIR}/mesh/mesh3DDecorated.cpp + ${CMAKE_CURRENT_LIST_DIR}/twoViewOptimalTriangulation.cpp + ${CMAKE_CURRENT_LIST_DIR}/ellipse.cpp + ${CMAKE_CURRENT_LIST_DIR}/ellipseFit.cpp + ${CMAKE_CURRENT_LIST_DIR}/plane3dFit.cpp + ${CMAKE_CURRENT_LIST_DIR}/mesh/meshClicker.cpp + ${CMAKE_CURRENT_LIST_DIR}/mesh/meshFilter.cpp + ${CMAKE_CURRENT_LIST_DIR}/mesh/meshCache.cpp + ${CMAKE_CURRENT_LIST_DIR}/convexHull.cpp + ${CMAKE_CURRENT_LIST_DIR}/convexHull3d.cpp + ${CMAKE_CURRENT_LIST_DIR}/convexQuickHull.cpp + ${CMAKE_CURRENT_LIST_DIR}/projectiveConvexQuickHull.cpp + ${CMAKE_CURRENT_LIST_DIR}/pointCloud.cpp + ${CMAKE_CURRENT_LIST_DIR}/halfspaceIntersector.cpp + ${CMAKE_CURRENT_LIST_DIR}/orientedBox.cpp + ${CMAKE_CURRENT_LIST_DIR}/plane.cpp + ) option(with_renderer "Should compile renderer" YES) if(with_renderer) - target_sources(corecvs - PUBLIC + set(GEOMETRY_HEADER_FILES + ${GEOMETRY_HEADER_FILES} ${CMAKE_CURRENT_LIST_DIR}/raytrace/raytraceableNodeWrapper.h ${CMAKE_CURRENT_LIST_DIR}/raytrace/raytraceRenderer.h ${CMAKE_CURRENT_LIST_DIR}/raytrace/raytraceObjects.h @@ -84,8 +78,10 @@ if(with_renderer) ${CMAKE_CURRENT_LIST_DIR}/renderer/attributedTriangleSpanIterator.h ${CMAKE_CURRENT_LIST_DIR}/renderer/simpleRenderer.h ${CMAKE_CURRENT_LIST_DIR}/renderer/geometryIterator.h + ) - PRIVATE + set(GEOMETRY_SOURCE_FILES + ${GEOMETRY_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/raytrace/raytraceRenderer.cpp ${CMAKE_CURRENT_LIST_DIR}/raytrace/raytraceObjects.cpp ${CMAKE_CURRENT_LIST_DIR}/raytrace/perlinNoise.cpp @@ -95,11 +91,9 @@ if(with_renderer) ${CMAKE_CURRENT_LIST_DIR}/renderer/simpleRenderer.cpp ${CMAKE_CURRENT_LIST_DIR}/renderer/attributedTriangleSpanIterator.cpp ${CMAKE_CURRENT_LIST_DIR}/raytrace/sdfRenderableObjects.cpp - - ) - + ) endif() - - +set(GEOMETRY_HEADER_FILES ${GEOMETRY_HEADER_FILES} PARENT_SCOPE) +set(GEOMETRY_SOURCE_FILES ${GEOMETRY_SOURCE_FILES} PARENT_SCOPE) diff --git a/core/geometry/axisAlignedBox.h b/core/geometry/axisAlignedBox.h index 807bc8101..b75f6d9fc 100644 --- a/core/geometry/axisAlignedBox.h +++ b/core/geometry/axisAlignedBox.h @@ -1,9 +1,9 @@ #ifndef AXIS_ALIGNED_BOX_H #define AXIS_ALIGNED_BOX_H -#include "core/math/vector/vector3d.h" -#include "core/geometry/line.h" -#include "core/xml/generated/axisAlignedBoxParameters.h" +#include "math/vector/vector3d.h" +#include "geometry/line.h" +#include "xml/generated/axisAlignedBoxParameters.h" /** * \file axisAlignedBox.h diff --git a/core/geometry/conic.cpp b/core/geometry/conic.cpp index a712675b3..5308395ba 100644 --- a/core/geometry/conic.cpp +++ b/core/geometry/conic.cpp @@ -1,4 +1,4 @@ -#include "core/geometry/conic.h" +#include "geometry/conic.h" namespace corecvs { diff --git a/core/geometry/conic.h b/core/geometry/conic.h index fbdf9890b..bcd412f5c 100644 --- a/core/geometry/conic.h +++ b/core/geometry/conic.h @@ -1,10 +1,10 @@ #ifndef CONIC_H #define CONIC_H -#include "core/geometry/line.h" -#include "core/geometry/plane.h" -#include "core/geometry/triangle.h" -#include "core/buffers/rgb24/lineSpan.h" +#include "geometry/line.h" +#include "geometry/plane.h" +#include "geometry/triangle.h" +#include "buffers/rgb24/lineSpan.h" namespace corecvs { diff --git a/core/geometry/convexHull.cpp b/core/geometry/convexHull.cpp index d68748e12..169035c9c 100644 --- a/core/geometry/convexHull.cpp +++ b/core/geometry/convexHull.cpp @@ -1,6 +1,6 @@ -#include "core/geometry/convexHull.h" +#include "geometry/convexHull.h" -#include "core/geometry/mesh/mesh3d.h" +#include "geometry/mesh/mesh3d.h" using namespace corecvs; using namespace std; diff --git a/core/geometry/convexHull.h b/core/geometry/convexHull.h index 107cb3625..133e3a2f0 100644 --- a/core/geometry/convexHull.h +++ b/core/geometry/convexHull.h @@ -1,7 +1,7 @@ #include -#include "core/math/vector/vector3d.h" -#include "core/geometry/polygons.h" +#include "math/vector/vector3d.h" +#include "geometry/polygons.h" namespace corecvs { diff --git a/core/geometry/convexHull3d.h b/core/geometry/convexHull3d.h index d89aab307..da55de2bf 100644 --- a/core/geometry/convexHull3d.h +++ b/core/geometry/convexHull3d.h @@ -4,8 +4,8 @@ #include #include -#include "core/math/vector/vector3d.h" -#include "core/geometry/triangle.h" +#include "math/vector/vector3d.h" +#include "geometry/triangle.h" namespace corecvs { diff --git a/core/geometry/convexPolyhedron.cpp b/core/geometry/convexPolyhedron.cpp index ed65d546b..ee40f69ac 100644 --- a/core/geometry/convexPolyhedron.cpp +++ b/core/geometry/convexPolyhedron.cpp @@ -1,6 +1,6 @@ -#include "core/geometry/convexPolyhedron.h" -#include "core/geometry/halfspaceIntersector.h" -#include "core/geometry/mesh/mesh3d.h" +#include "convexPolyhedron.h" +#include "halfspaceIntersector.h" +#include "mesh/mesh3d.h" #include diff --git a/core/geometry/convexPolyhedron.h b/core/geometry/convexPolyhedron.h index f963c9dd4..404427a88 100644 --- a/core/geometry/convexPolyhedron.h +++ b/core/geometry/convexPolyhedron.h @@ -2,9 +2,9 @@ #define CONVEXPOLYHEDRON_H #include -#include "core/geometry/line.h" -#include "core/geometry/plane.h" -#include "core/geometry/axisAlignedBox.h" +#include "geometry/line.h" +#include "geometry/plane.h" +#include "geometry/axisAlignedBox.h" namespace corecvs { diff --git a/core/geometry/convexQuickHull.h b/core/geometry/convexQuickHull.h index 388efadbf..22964676f 100644 --- a/core/geometry/convexQuickHull.h +++ b/core/geometry/convexQuickHull.h @@ -8,8 +8,8 @@ #include -#include "core/math/vector/vector3d.h" -#include "core/geometry/triangle.h" +#include "math/vector/vector3d.h" +#include "geometry/triangle.h" namespace corecvs { diff --git a/core/geometry/ellipse.cpp b/core/geometry/ellipse.cpp index 929718ae4..f29f24e71 100644 --- a/core/geometry/ellipse.cpp +++ b/core/geometry/ellipse.cpp @@ -1,6 +1,6 @@ -#include "core/math/matrix/matrix22.h" -#include "core/geometry/ellipse.h" -#include "core/polynomial/polynomialSolver.h" +#include "math/matrix/matrix22.h" +#include "geometry/ellipse.h" +#include "polynomial/polynomialSolver.h" namespace corecvs { diff --git a/core/geometry/ellipse.h b/core/geometry/ellipse.h index 618d35af1..90b990659 100644 --- a/core/geometry/ellipse.h +++ b/core/geometry/ellipse.h @@ -1,11 +1,11 @@ #ifndef ELLIPSE_H #define ELLIPSE_H -#include "core/math/vector/vector2d.h" -#include "core/polynomial/polynomial.h" -#include "core/math/affine.h" -#include "core/geometry/line.h" -#include "core/geometry/conic.h" +#include "math/vector/vector2d.h" +#include "polynomial/polynomial.h" +#include "math/affine.h" +#include "geometry/line.h" +#include "geometry/conic.h" namespace corecvs { diff --git a/core/geometry/ellipseFit.cpp b/core/geometry/ellipseFit.cpp index f086fe364..0f4003ee0 100644 --- a/core/geometry/ellipseFit.cpp +++ b/core/geometry/ellipseFit.cpp @@ -1,5 +1,5 @@ -#include "core/geometry/ellipseFit.h" -#include "core/kalman/cholesky.h" +#include "geometry/ellipseFit.h" +#include "kalman/cholesky.h" #include "wrappers/cblasLapack/cblasLapackeWrapper.h" diff --git a/core/geometry/ellipseFit.h b/core/geometry/ellipseFit.h index c38e63c38..e6aba63a4 100644 --- a/core/geometry/ellipseFit.h +++ b/core/geometry/ellipseFit.h @@ -1,7 +1,7 @@ #ifndef ELLIPSEFIT_H #define ELLIPSEFIT_H -#include "core/geometry/ellipse.h" +#include "geometry/ellipse.h" namespace corecvs { diff --git a/core/geometry/ellipticalApproximation.cpp b/core/geometry/ellipticalApproximation.cpp index eba0421f1..53d6b1105 100644 --- a/core/geometry/ellipticalApproximation.cpp +++ b/core/geometry/ellipticalApproximation.cpp @@ -5,7 +5,7 @@ * \date Apr 14, 2011 * \author alexander */ -#include "core/geometry/ellipticalApproximation.h" +#include "geometry/ellipticalApproximation.h" namespace corecvs { diff --git a/core/geometry/ellipticalApproximation.h b/core/geometry/ellipticalApproximation.h index d0aab3e5f..37dd27a23 100644 --- a/core/geometry/ellipticalApproximation.h +++ b/core/geometry/ellipticalApproximation.h @@ -9,12 +9,12 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix.h" +#include "math/vector/vector2d.h" +#include "math/matrix/matrix.h" -#include "core/math/affine.h" +#include "math/affine.h" namespace corecvs { diff --git a/core/geometry/gentryState.cpp b/core/geometry/gentryState.cpp index ccfbcf741..3182677b7 100644 --- a/core/geometry/gentryState.cpp +++ b/core/geometry/gentryState.cpp @@ -1,4 +1,4 @@ -#include "core/geometry/gentryState.h" +#include "geometry/gentryState.h" GentryState::GentryState() { diff --git a/core/geometry/gentryState.h b/core/geometry/gentryState.h index eca2b697f..454928eca 100644 --- a/core/geometry/gentryState.h +++ b/core/geometry/gentryState.h @@ -1,9 +1,9 @@ #ifndef GENTRYSTATE_H #define GENTRYSTATE_H -#include "core/math/vector/vector3d.h" -#include "core/geometry/line.h" -#include "core/cameracalibration/cameraModel.h" +#include "math/vector/vector3d.h" +#include "geometry/line.h" +#include "cameracalibration/cameraModel.h" using namespace corecvs; diff --git a/core/geometry/halfspaceIntersector.cpp b/core/geometry/halfspaceIntersector.cpp index 65550358c..874a03081 100644 --- a/core/geometry/halfspaceIntersector.cpp +++ b/core/geometry/halfspaceIntersector.cpp @@ -1,7 +1,7 @@ -#include "core/geometry/halfspaceIntersector.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/geometry/polygons.h" -#include "core/geometry/convexHull.h" +#include "geometry/halfspaceIntersector.h" +#include "geometry/mesh/mesh3d.h" +#include "geometry/polygons.h" +#include "geometry/convexHull.h" namespace corecvs { diff --git a/core/geometry/halfspaceIntersector.h b/core/geometry/halfspaceIntersector.h index 4f32fee50..d3695c220 100644 --- a/core/geometry/halfspaceIntersector.h +++ b/core/geometry/halfspaceIntersector.h @@ -1,9 +1,9 @@ #ifndef HALFSPACEINTERSECTOR_H #define HALFSPACEINTERSECTOR_H -#include "core/geometry/polygons.h" -#include "core/geometry/convexQuickHull.h" -#include "core/geometry/projectiveConvexQuickHull.h" +#include "geometry/polygons.h" +#include "geometry/convexQuickHull.h" +#include "geometry/projectiveConvexQuickHull.h" namespace corecvs { diff --git a/core/geometry/insetOutset.h b/core/geometry/insetOutset.h index e344ffaf8..97ec0703d 100644 --- a/core/geometry/insetOutset.h +++ b/core/geometry/insetOutset.h @@ -8,7 +8,7 @@ #include #include #include -#include "core/geometry/polygons.h" +#include "geometry/polygons.h" using namespace corecvs; diff --git a/core/geometry/kdtree.h b/core/geometry/kdtree.h index 5824890fd..c7144dbc9 100644 --- a/core/geometry/kdtree.h +++ b/core/geometry/kdtree.h @@ -7,7 +7,7 @@ #include #include #include -#include "core/tbbwrapper/tbbWrapper.h" +#include "tbbwrapper/tbbWrapper.h" namespace corecvs { diff --git a/core/geometry/line.h b/core/geometry/line.h index 070306343..c15eca7ea 100644 --- a/core/geometry/line.h +++ b/core/geometry/line.h @@ -3,9 +3,9 @@ #include -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/math/matrix/matrix44.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "math/matrix/matrix44.h" namespace corecvs { diff --git a/core/geometry/mesh/mesh3DDecorated.h b/core/geometry/mesh/mesh3DDecorated.h index b3d7052e4..ca1e80ab9 100644 --- a/core/geometry/mesh/mesh3DDecorated.h +++ b/core/geometry/mesh/mesh3DDecorated.h @@ -1,8 +1,8 @@ #ifndef MESH3DDECORATED_H #define MESH3DDECORATED_H -#include "core/geometry/mesh/mesh3d.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "geometry/mesh/mesh3d.h" +#include "buffers/rgb24/rgb24Buffer.h" namespace corecvs { diff --git a/core/geometry/mesh/mesh3d.cpp b/core/geometry/mesh/mesh3d.cpp index be4344f61..35f126a16 100644 --- a/core/geometry/mesh/mesh3d.cpp +++ b/core/geometry/mesh/mesh3d.cpp @@ -5,11 +5,11 @@ **/ #include -#include "core/math/mathUtils.h" // M_PI -#include "core/buffers/rgb24/abstractPainter.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/fileformats/plyLoader.h" -#include "core/cammodel/cameraParameters.h" +#include "math/mathUtils.h" // M_PI +#include "buffers/rgb24/abstractPainter.h" +#include "geometry/mesh/mesh3d.h" +#include "fileformats/plyLoader.h" +#include "cammodel/cameraParameters.h" namespace corecvs { @@ -186,7 +186,6 @@ void Mesh3D::addAOB(const Vector3dd &c1, const Vector3dd &c2, bool addFaces) { Vector3d32 startId(vectorIndex, vectorIndex, vectorIndex); addFace(startId + Vector3d32(0, 1, 2)); - addFace(startId + Vector3d32(0, 1, 2)); addFace(startId + Vector3d32(2, 3, 0)); addFace(startId + Vector3d32(7, 6, 5)); addFace(startId + Vector3d32(5, 4, 7)); diff --git a/core/geometry/mesh/mesh3d.h b/core/geometry/mesh/mesh3d.h index ed92b85a6..3dc37286d 100644 --- a/core/geometry/mesh/mesh3d.h +++ b/core/geometry/mesh/mesh3d.h @@ -6,16 +6,16 @@ * \date Dec 13, 2012 **/ -#include "core/math/vector/vector3d.h" -#include "core/math/matrix/matrix33.h" -#include "core/math/matrix/matrix44.h" -#include "core/geometry/axisAlignedBox.h" -#include "core/geometry/ellipticalApproximation.h" -#include "core/geometry/polygons.h" -#include "core/geometry/conic.h" -#include "core/geometry/orientedBox.h" -#include "core/buffers/rgb24/rgbColor.h" -#include "core/xml/generated/axisAlignedBoxParameters.h" +#include "math/vector/vector3d.h" +#include "math/matrix/matrix33.h" +#include "math/matrix/matrix44.h" +#include "geometry/axisAlignedBox.h" +#include "geometry/ellipticalApproximation.h" +#include "geometry/polygons.h" +#include "geometry/conic.h" +#include "geometry/orientedBox.h" +#include "buffers/rgb24/rgbColor.h" +#include "xml/generated/axisAlignedBoxParameters.h" namespace corecvs { diff --git a/core/geometry/mesh/meshClicker.cpp b/core/geometry/mesh/meshClicker.cpp index 6b9a00442..7fb6fd87e 100644 --- a/core/geometry/mesh/meshClicker.cpp +++ b/core/geometry/mesh/meshClicker.cpp @@ -1,4 +1,4 @@ -#include "core/geometry/mesh/meshClicker.h" +#include "meshClicker.h" namespace corecvs { diff --git a/core/geometry/mesh/meshClicker.h b/core/geometry/mesh/meshClicker.h index 1e4bd6f0a..59ab88954 100644 --- a/core/geometry/mesh/meshClicker.h +++ b/core/geometry/mesh/meshClicker.h @@ -1,7 +1,7 @@ #ifndef MESHCLICKER_H #define MESHCLICKER_H -#include "core/geometry/mesh/mesh3d.h" +#include "geometry/mesh/mesh3d.h" namespace corecvs { diff --git a/core/geometry/orientedBox.h b/core/geometry/orientedBox.h index 4ad668ff0..dbe846399 100644 --- a/core/geometry/orientedBox.h +++ b/core/geometry/orientedBox.h @@ -1,9 +1,9 @@ #ifndef ORIENTEDBOX_H #define ORIENTEDBOX_H -#include -#include -#include +#include +#include +#include namespace corecvs { diff --git a/core/geometry/plane.h b/core/geometry/plane.h index ebb307012..a6ca92f66 100644 --- a/core/geometry/plane.h +++ b/core/geometry/plane.h @@ -1,8 +1,8 @@ #ifndef PLANE_H #define PLANE_H -#include "core/geometry/line.h" -#include "core/math/vector/vector4d.h" +#include "geometry/line.h" +#include "math/vector/vector4d.h" namespace corecvs { diff --git a/core/geometry/plane3dFit.cpp b/core/geometry/plane3dFit.cpp index 1e31cb5be..f8bd5fe6a 100644 --- a/core/geometry/plane3dFit.cpp +++ b/core/geometry/plane3dFit.cpp @@ -1,5 +1,5 @@ -#include "core/geometry/plane3dFit.h" -#include "core/rectification/ransac.h" +#include "geometry/plane3dFit.h" +#include "rectification/ransac.h" namespace corecvs { diff --git a/core/geometry/plane3dFit.h b/core/geometry/plane3dFit.h index 984fc55fb..906afe739 100644 --- a/core/geometry/plane3dFit.h +++ b/core/geometry/plane3dFit.h @@ -2,9 +2,9 @@ #define PLANE3DFIT_H #include -#include "core/math/vector/vector3d.h" -#include "core/geometry/plane.h" -#include "core/geometry/ellipticalApproximation.h" +#include "math/vector/vector3d.h" +#include "geometry/plane.h" +#include "geometry/ellipticalApproximation.h" namespace corecvs { diff --git a/core/geometry/planeFrame.h b/core/geometry/planeFrame.h index c03d4e82a..a6596053f 100644 --- a/core/geometry/planeFrame.h +++ b/core/geometry/planeFrame.h @@ -1,9 +1,9 @@ #ifndef PLANEFRAME_H #define PLANEFRAME_H -#include "core/math/vector/vector3d.h" -#include "core/geometry/plane.h" -#include "core/math/affine.h" +#include "math/vector/vector3d.h" +#include "geometry/plane.h" +#include "math/affine.h" namespace corecvs { diff --git a/core/geometry/pointCloud.cpp b/core/geometry/pointCloud.cpp index 5d3d65e52..49d4356d2 100644 --- a/core/geometry/pointCloud.cpp +++ b/core/geometry/pointCloud.cpp @@ -1,6 +1,6 @@ -#include "core/utils/utils.h" +#include "utils/utils.h" #include "pointCloud.h" -#include "core/filesystem/folderScanner.h" +#include "filesystem/folderScanner.h" namespace corecvs { diff --git a/core/geometry/pointCloud.h b/core/geometry/pointCloud.h index 21b2d878f..46248aa6c 100644 --- a/core/geometry/pointCloud.h +++ b/core/geometry/pointCloud.h @@ -3,11 +3,10 @@ #include #include -#include "core/math/vector/vector3d.h" -#include "core/geometry/mesh/mesh3d.h" - -#include "core/geometry/kdtree.h" -#include "core/geometry/raytrace/bspTree.h" +#include "math/vector/vector3d.h" +#include "geometry/mesh/mesh3d.h" +#include "geometry/kdtree.h" +#include "geometry/raytrace/bspTree.h" namespace corecvs { diff --git a/core/geometry/polygonPointIterator.cpp b/core/geometry/polygonPointIterator.cpp index d0e138c8a..c44b05e38 100644 --- a/core/geometry/polygonPointIterator.cpp +++ b/core/geometry/polygonPointIterator.cpp @@ -1,4 +1,4 @@ -#include "core/geometry/polygonPointIterator.h" +#include "geometry/polygonPointIterator.h" namespace corecvs { diff --git a/core/geometry/polygonPointIterator.h b/core/geometry/polygonPointIterator.h index aa5f1b9c0..a3ad510ec 100644 --- a/core/geometry/polygonPointIterator.h +++ b/core/geometry/polygonPointIterator.h @@ -1,8 +1,8 @@ #ifndef POLYGONPOINTITERATOR_H #define POLYGONPOINTITERATOR_H -#include "core/geometry/polygons.h" -#include "core/geometry/renderer/simpleRenderer.h" +#include "geometry/polygons.h" +#include "geometry/renderer/simpleRenderer.h" namespace corecvs { diff --git a/core/geometry/polygons.cpp b/core/geometry/polygons.cpp index 36aab11c1..de29b249e 100644 --- a/core/geometry/polygons.cpp +++ b/core/geometry/polygons.cpp @@ -8,12 +8,12 @@ */ #include "convexHull.h" -#include "core/geometry/polygons.h" -#include "core/math/mathUtils.h" -#include "core/utils/global.h" +#include "geometry/polygons.h" +#include "math/mathUtils.h" +#include "utils/global.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/rgb24/abstractPainter.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/abstractPainter.h" namespace corecvs { diff --git a/core/geometry/polygons.h b/core/geometry/polygons.h index 1ac224874..b44e5d8c0 100644 --- a/core/geometry/polygons.h +++ b/core/geometry/polygons.h @@ -15,13 +15,13 @@ #include #include -#include "core/math/vector/vector3d.h" -#include "core/xml/generated/axisAlignedBoxParameters.h" -#include "core/geometry/line.h" -#include "core/math/affine.h" -#include "core/geometry/rectangle.h" -#include "core/geometry/convexPolyhedron.h" -#include "core/geometry/planeFrame.h" +#include "math/vector/vector3d.h" +#include "xml/generated/axisAlignedBoxParameters.h" +#include "geometry/line.h" +#include "math/affine.h" +#include "geometry/rectangle.h" +#include "geometry/convexPolyhedron.h" +#include "geometry/planeFrame.h" namespace corecvs { diff --git a/core/geometry/projectiveConvexQuickHull.cpp b/core/geometry/projectiveConvexQuickHull.cpp index 9c7fe0ce9..7b6c90456 100644 --- a/core/geometry/projectiveConvexQuickHull.cpp +++ b/core/geometry/projectiveConvexQuickHull.cpp @@ -1,5 +1,5 @@ #include "projectiveConvexQuickHull.h" -#include "core/geometry/mesh/mesh3d.h" +#include "geometry/mesh/mesh3d.h" using namespace std; diff --git a/core/geometry/projectiveConvexQuickHull.h b/core/geometry/projectiveConvexQuickHull.h index 7737f245a..521d93c19 100644 --- a/core/geometry/projectiveConvexQuickHull.h +++ b/core/geometry/projectiveConvexQuickHull.h @@ -7,9 +7,9 @@ #include #include -#include "core/math/vector/vector3d.h" -#include "core/math/vector/vector4d.h" -#include "core/geometry/triangle.h" +#include "math/vector/vector3d.h" +#include "math/vector/vector4d.h" +#include "geometry/triangle.h" namespace corecvs { diff --git a/core/geometry/raytrace/bspTree.h b/core/geometry/raytrace/bspTree.h index b35f6761c..04166d132 100644 --- a/core/geometry/raytrace/bspTree.h +++ b/core/geometry/raytrace/bspTree.h @@ -1,11 +1,11 @@ #ifndef BSPTREE_H #define BSPTREE_H -#include "core/geometry/line.h" -#include "core/geometry/polygons.h" -#include "core/geometry/axisAlignedBox.h" -#include "core/geometry/conic.h" -#include "core/geometry/raytrace/raytraceRenderer.h" +#include "geometry/line.h" +#include "geometry/polygons.h" +#include "geometry/axisAlignedBox.h" +#include "geometry/conic.h" +#include "geometry/raytrace/raytraceRenderer.h" namespace corecvs { diff --git a/core/geometry/raytrace/materialExamples.cpp b/core/geometry/raytrace/materialExamples.cpp index 786b36551..caacef560 100644 --- a/core/geometry/raytrace/materialExamples.cpp +++ b/core/geometry/raytrace/materialExamples.cpp @@ -1,4 +1,4 @@ -#include "core/geometry/raytrace/materialExamples.h" +#include "geometry/raytrace/materialExamples.h" MaterialExamples::MaterialExamples() { diff --git a/core/geometry/raytrace/materialExamples.h b/core/geometry/raytrace/materialExamples.h index 487d37f2e..5f64d6082 100644 --- a/core/geometry/raytrace/materialExamples.h +++ b/core/geometry/raytrace/materialExamples.h @@ -1,8 +1,8 @@ #ifndef MATERIALEXAMPLES_H #define MATERIALEXAMPLES_H -#include "core/geometry/raytrace/perlinNoise.h" -#include "core/geometry/raytrace/raytraceRenderer.h" +#include "geometry/raytrace/perlinNoise.h" +#include "geometry/raytrace/raytraceRenderer.h" namespace corecvs { diff --git a/core/geometry/raytrace/perlinNoise.cpp b/core/geometry/raytrace/perlinNoise.cpp index 27af3dec7..5af413074 100644 --- a/core/geometry/raytrace/perlinNoise.cpp +++ b/core/geometry/raytrace/perlinNoise.cpp @@ -1,4 +1,4 @@ -#include "core/geometry/raytrace/perlinNoise.h" +#include "geometry/raytrace/perlinNoise.h" namespace corecvs { diff --git a/core/geometry/raytrace/perlinNoise.h b/core/geometry/raytrace/perlinNoise.h index f4de23ee0..61490e2bf 100644 --- a/core/geometry/raytrace/perlinNoise.h +++ b/core/geometry/raytrace/perlinNoise.h @@ -3,7 +3,7 @@ #include -#include "core/buffers/voxels/voxelBuffer.h" +#include "buffers/voxels/voxelBuffer.h" namespace corecvs { diff --git a/core/geometry/raytrace/raytraceObjects.cpp b/core/geometry/raytrace/raytraceObjects.cpp index 6102a1ee2..5dad23d56 100644 --- a/core/geometry/raytrace/raytraceObjects.cpp +++ b/core/geometry/raytrace/raytraceObjects.cpp @@ -1,4 +1,4 @@ -#include "core/geometry/raytrace/raytraceObjects.h" +#include "geometry/raytrace/raytraceObjects.h" const double RaytraceableSphere::EPSILON = 0.000001; diff --git a/core/geometry/raytrace/raytraceObjects.h b/core/geometry/raytrace/raytraceObjects.h index 602427f37..278eedad7 100644 --- a/core/geometry/raytrace/raytraceObjects.h +++ b/core/geometry/raytrace/raytraceObjects.h @@ -1,10 +1,10 @@ #ifndef RAYTRACEOBJECTS_H #define RAYTRACEOBJECTS_H -#include "core/geometry/raytrace/bspTree.h" -#include "core/geometry/mesh/mesh3DDecorated.h" -#include "core/geometry/raytrace/raytraceRenderer.h" -#include "core/geometry/raytrace/raytraceableNodeWrapper.h" +#include "geometry/raytrace/bspTree.h" +#include "geometry/mesh/mesh3DDecorated.h" +#include "geometry/raytrace/raytraceRenderer.h" +#include "geometry/raytrace/raytraceableNodeWrapper.h" class RaytraceableTransform : public Raytraceable { diff --git a/core/geometry/raytrace/raytraceRenderer.cpp b/core/geometry/raytrace/raytraceRenderer.cpp index e98975dc3..aeddee784 100644 --- a/core/geometry/raytrace/raytraceRenderer.cpp +++ b/core/geometry/raytrace/raytraceRenderer.cpp @@ -1,8 +1,8 @@ #include -#include "core/geometry/raytrace/raytraceRenderer.h" -#include "core/utils/preciseTimer.h" -#include "core/fileformats/bmpLoader.h" +#include "geometry/raytrace/raytraceRenderer.h" +#include "utils/preciseTimer.h" +#include "fileformats/bmpLoader.h" #include RaytraceRenderer::RaytraceRenderer() diff --git a/core/geometry/raytrace/raytraceRenderer.h b/core/geometry/raytrace/raytraceRenderer.h index f04d721b1..50dae7574 100644 --- a/core/geometry/raytrace/raytraceRenderer.h +++ b/core/geometry/raytrace/raytraceRenderer.h @@ -1,11 +1,11 @@ #ifndef RAYTRACERENDERER_H #define RAYTRACERENDERER_H -#include "core/geometry/polygons.h" -#include "core/cameracalibration/cameraModel.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/geometry/line.h" -#include "core/cameracalibration/projection/projectionModels.h" +#include "geometry/polygons.h" +#include "cameracalibration/cameraModel.h" +#include "geometry/mesh/mesh3d.h" +#include "geometry/line.h" +#include "cameracalibration/projection/projectionModels.h" namespace corecvs { diff --git a/core/geometry/raytrace/raytraceableNodeWrapper.h b/core/geometry/raytrace/raytraceableNodeWrapper.h index f5c448153..5b9547ce4 100644 --- a/core/geometry/raytrace/raytraceableNodeWrapper.h +++ b/core/geometry/raytrace/raytraceableNodeWrapper.h @@ -1,7 +1,7 @@ #ifndef RAYTRACEABLENODEWRAPPER_H #define RAYTRACEABLENODEWRAPPER_H -#include "core/geometry/raytrace/raytraceRenderer.h" +#include "geometry/raytrace/raytraceRenderer.h" #include "bspTree.h" namespace corecvs { diff --git a/core/geometry/raytrace/sdfRenderable.cpp b/core/geometry/raytrace/sdfRenderable.cpp index 04bb69123..f95237a31 100644 --- a/core/geometry/raytrace/sdfRenderable.cpp +++ b/core/geometry/raytrace/sdfRenderable.cpp @@ -1,4 +1,4 @@ -#include "core/geometry/raytrace/sdfRenderable.h" +#include "geometry/raytrace/sdfRenderable.h" SDFRenderable::SDFRenderable() { diff --git a/core/geometry/raytrace/sdfRenderable.h b/core/geometry/raytrace/sdfRenderable.h index 0caf8a1e2..8e1fdc567 100644 --- a/core/geometry/raytrace/sdfRenderable.h +++ b/core/geometry/raytrace/sdfRenderable.h @@ -1,10 +1,10 @@ #ifndef SDFRENDERABLE_H #define SDFRENDERABLE_H -#include "core/function/function.h" +#include "function/function.h" -#include "core/math/vector/vector3d.h" -#include "core/geometry/raytrace/raytraceObjects.h" +#include "math/vector/vector3d.h" +#include "geometry/raytrace/raytraceObjects.h" class SDFRenderable : public Raytraceable diff --git a/core/geometry/raytrace/sdfRenderableObjects.cpp b/core/geometry/raytrace/sdfRenderableObjects.cpp index 406c2970e..6256972ca 100644 --- a/core/geometry/raytrace/sdfRenderableObjects.cpp +++ b/core/geometry/raytrace/sdfRenderableObjects.cpp @@ -1,4 +1,4 @@ -#include "core/geometry/raytrace/sdfRenderableObjects.h" +#include "geometry/raytrace/sdfRenderableObjects.h" SDFRenderableSphere::SDFRenderableSphere(const Vector3dd &sphere, double r) : sphere(sphere), diff --git a/core/geometry/raytrace/sdfRenderableObjects.h b/core/geometry/raytrace/sdfRenderableObjects.h index 7a210ba08..a7c787ea4 100644 --- a/core/geometry/raytrace/sdfRenderableObjects.h +++ b/core/geometry/raytrace/sdfRenderableObjects.h @@ -1,10 +1,10 @@ #ifndef SDFRENDERABLEOBJECTS_H #define SDFRENDERABLEOBJECTS_H -#include "core/function/function.h" +#include "function/function.h" -#include "core/math/vector/vector3d.h" -#include "core/geometry/raytrace/sdfRenderable.h" +#include "math/vector/vector3d.h" +#include "geometry/raytrace/sdfRenderable.h" class SDFRenderableSphere : public SDFRenderable{ Vector3dd sphere; diff --git a/core/geometry/rectangle.cpp b/core/geometry/rectangle.cpp index 49ff2f7a1..e943de948 100644 --- a/core/geometry/rectangle.cpp +++ b/core/geometry/rectangle.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/geometry/rectangle.h" +#include "geometry/rectangle.h" namespace corecvs { diff --git a/core/geometry/rectangle.h b/core/geometry/rectangle.h index 2298a52dd..f1cadfaf3 100644 --- a/core/geometry/rectangle.h +++ b/core/geometry/rectangle.h @@ -11,8 +11,8 @@ #include -#include "core/math/vector/vector2d.h" -#include "core/geometry/convexPolyhedron.h" +#include "math/vector/vector2d.h" +#include "geometry/convexPolyhedron.h" namespace corecvs { diff --git a/core/geometry/renderer/geometryIterator.h b/core/geometry/renderer/geometryIterator.h index e15650ede..2ff9f2a4c 100644 --- a/core/geometry/renderer/geometryIterator.h +++ b/core/geometry/renderer/geometryIterator.h @@ -1,10 +1,10 @@ #ifndef GEOMETRY_ITERATOR_H #define GEOMETRY_ITERATOR_H -#include "core/math/mathUtils.h" -#include "core/math/matrix/matrix44.h" -#include "core/geometry/triangle.h" -#include "core/buffers/rgb24/lineSpan.h" +#include "math/mathUtils.h" +#include "math/matrix/matrix44.h" +#include "geometry/triangle.h" +#include "buffers/rgb24/lineSpan.h" namespace corecvs { diff --git a/core/geometry/renderer/simpleRenderer.cpp b/core/geometry/renderer/simpleRenderer.cpp index 2afd9dc77..ef41e6573 100644 --- a/core/geometry/renderer/simpleRenderer.cpp +++ b/core/geometry/renderer/simpleRenderer.cpp @@ -1,9 +1,8 @@ -#include "core/geometry/renderer/simpleRenderer.h" -#include "core/geometry/mesh/mesh3d.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/fileformats/bmpLoader.h" -#include "core/geometry/renderer/attributedTriangleSpanIterator.h" -#include +#include "geometry/renderer/simpleRenderer.h" +#include "geometry/mesh/mesh3d.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "fileformats/bmpLoader.h" +#include "geometry/renderer/attributedTriangleSpanIterator.h" namespace corecvs { diff --git a/core/geometry/renderer/simpleRenderer.h b/core/geometry/renderer/simpleRenderer.h index fb42e7096..b5f9a8476 100644 --- a/core/geometry/renderer/simpleRenderer.h +++ b/core/geometry/renderer/simpleRenderer.h @@ -6,17 +6,16 @@ **/ #include - -#include "core/utils/global.h" -#include "core/geometry/renderer/geometryIterator.h" -#include "core/buffers/abstractBuffer.h" -#include "core/buffers/rgb24/abstractPainter.h" -#include "core/geometry/mesh/mesh3DDecorated.h" -#include "core/buffers/mipmapPyramid.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/geometry/renderer/attributedTriangleSpanIterator.h" -#include "core/fileformats/bmpLoader.h" -#include "core/utils/debuggableBlock.h" +#include "utils/global.h" +#include "geometry/renderer/geometryIterator.h" +#include "buffers/abstractBuffer.h" +#include "buffers/rgb24/abstractPainter.h" +#include "geometry/mesh/mesh3DDecorated.h" +#include "buffers/mipmapPyramid.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "geometry/renderer/attributedTriangleSpanIterator.h" +#include "fileformats/bmpLoader.h" +#include "utils/debuggableBlock.h" namespace corecvs { diff --git a/core/geometry/triangle.h b/core/geometry/triangle.h index eef4d5eab..ffba749cb 100644 --- a/core/geometry/triangle.h +++ b/core/geometry/triangle.h @@ -1,8 +1,8 @@ #ifndef TRIANGLE_H #define TRIANGLE_H -#include "core/geometry/line.h" -#include "core/geometry/planeFrame.h" +#include "geometry/line.h" +#include "geometry/planeFrame.h" namespace corecvs { diff --git a/core/geometry/triangulation.cpp b/core/geometry/triangulation.cpp index eb40ab511..f004ca6db 100644 --- a/core/geometry/triangulation.cpp +++ b/core/geometry/triangulation.cpp @@ -9,9 +9,9 @@ */ #include -//#include "core/utils/preciseTimer.h" +//#include "utils/preciseTimer.h" -#include "core/geometry/triangulation.h" +#include "geometry/triangulation.h" namespace Triangulation { diff --git a/core/geometry/triangulation.h b/core/geometry/triangulation.h index d63f11b71..300218776 100644 --- a/core/geometry/triangulation.h +++ b/core/geometry/triangulation.h @@ -19,10 +19,10 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" // allow of using "Fast" split algorithm which is better for huge ammount of points #define FAST_SPLIT diff --git a/core/geometry/twoViewOptimalTriangulation.cpp b/core/geometry/twoViewOptimalTriangulation.cpp index 642ca8c65..1a23656a4 100644 --- a/core/geometry/twoViewOptimalTriangulation.cpp +++ b/core/geometry/twoViewOptimalTriangulation.cpp @@ -1,7 +1,7 @@ -#include "core/geometry/twoViewOptimalTriangulation.h" +#include "geometry/twoViewOptimalTriangulation.h" -#include "core/cameracalibration/cameraModel.h" -#include "core/polynomial/polynomialSolver.h" +#include "cameracalibration/cameraModel.h" +#include "polynomial/polynomialSolver.h" namespace corecvs { diff --git a/core/geometry/twoViewOptimalTriangulation.h b/core/geometry/twoViewOptimalTriangulation.h index fbd9e20d1..89ad31420 100644 --- a/core/geometry/twoViewOptimalTriangulation.h +++ b/core/geometry/twoViewOptimalTriangulation.h @@ -5,10 +5,10 @@ #include #include -#include "core/math/vector/vector3d.h" -#include "core/math/matrix/matrix33.h" -#include "core/math/matrix/matrix44.h" -#include "core/cameracalibration/cameraModel.h" +#include "math/vector/vector3d.h" +#include "math/matrix/matrix33.h" +#include "math/matrix/matrix44.h" +#include "cameracalibration/cameraModel.h" namespace corecvs { diff --git a/core/iterative/CMakeLists.txt b/core/iterative/CMakeLists.txt index be3c1f749..5a3eab57f 100644 --- a/core/iterative/CMakeLists.txt +++ b/core/iterative/CMakeLists.txt @@ -1,8 +1,11 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/minresQLP.h - ${CMAKE_CURRENT_LIST_DIR}/pcg.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/minresQLP.cpp - ${CMAKE_CURRENT_LIST_DIR}/pcg.cpp -) +set(ITERATIVE_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/minresQLP.h + ${CMAKE_CURRENT_LIST_DIR}/pcg.h + PARENT_SCOPE + ) + +set(ITERATIVE_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/minresQLP.cpp + ${CMAKE_CURRENT_LIST_DIR}/pcg.cpp + PARENT_SCOPE + ) diff --git a/core/iterative/minresQLP.cpp b/core/iterative/minresQLP.cpp index f5b84b926..26c6df805 100644 --- a/core/iterative/minresQLP.cpp +++ b/core/iterative/minresQLP.cpp @@ -1,4 +1,4 @@ -#include "core/iterative/minresQLP.h" +#include "iterative/minresQLP.h" namespace corecvs { diff --git a/core/iterative/minresQLP.h b/core/iterative/minresQLP.h index 8bd45658b..911cbb257 100644 --- a/core/iterative/minresQLP.h +++ b/core/iterative/minresQLP.h @@ -7,9 +7,9 @@ #include #include -#include "core/math/vector/vector.h" +#include "math/vector/vector.h" #include "wrappers/cblasLapack/cblasLapackeWrapper.h" -#include "core/tbbwrapper/tbbWrapper.h" +#include "tbbwrapper/tbbWrapper.h" #ifdef WITH_FMA #include "immintrin.h" diff --git a/core/iterative/pcg.cpp b/core/iterative/pcg.cpp index 05f06be2d..cee3bad8f 100644 --- a/core/iterative/pcg.cpp +++ b/core/iterative/pcg.cpp @@ -1,4 +1,4 @@ -#include "core/iterative/pcg.h" +#include "iterative/pcg.h" namespace corecvs { diff --git a/core/iterative/pcg.h b/core/iterative/pcg.h index 051e7e17f..5477fdd34 100644 --- a/core/iterative/pcg.h +++ b/core/iterative/pcg.h @@ -8,7 +8,7 @@ #include #include "wrappers/cblasLapack/cblasLapackeWrapper.h" -#include "core/math/vector/vector.h" +#include "math/vector/vector.h" namespace corecvs { diff --git a/core/joystick/CMakeLists.txt b/core/joystick/CMakeLists.txt index 8d17f4762..577d455c0 100644 --- a/core/joystick/CMakeLists.txt +++ b/core/joystick/CMakeLists.txt @@ -1,9 +1,12 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/joystickInterface.h - ${CMAKE_CURRENT_LIST_DIR}/playbackJoystickInterface.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/joystickInterface.cpp - ${CMAKE_CURRENT_LIST_DIR}/playbackJoystickInterface.cpp -) +set(JOYSTICK_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/joystickInterface.h + ${CMAKE_CURRENT_LIST_DIR}/playbackJoystickInterface.h + PARENT_SCOPE + ) + +set(JOYSTICK_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/joystickInterface.cpp + ${CMAKE_CURRENT_LIST_DIR}/playbackJoystickInterface.cpp + PARENT_SCOPE + ) diff --git a/core/joystick/joystickInterface.cpp b/core/joystick/joystickInterface.cpp index 22d913e01..0d92e016e 100644 --- a/core/joystick/joystickInterface.cpp +++ b/core/joystick/joystickInterface.cpp @@ -1,4 +1,5 @@ #include +#include "core/utils/global.h" #include "joystickInterface.h" namespace corecvs { @@ -13,4 +14,17 @@ void JoystickConfiguration::print() { cout << "Buttons :" << buttonNumber << endl; } +JoystickInterface::JoystickInterface() +{ + SYNC_PRINT(("JoystickInterface::JoystickInterface(): called.\n")); +} + +/* +JoystickInterface::JoystickInterface(const string &deviceName): + mDeviceName(deviceName) +{ + SYNC_PRINT(("JoystickInterface::JoystickInterface(string): called. Setting device to <%s>\n", mDeviceName.c_str())); +} +*/ + } // namespace corecvs diff --git a/core/joystick/joystickInterface.h b/core/joystick/joystickInterface.h index dd9020703..e5a387ce0 100644 --- a/core/joystick/joystickInterface.h +++ b/core/joystick/joystickInterface.h @@ -34,11 +34,9 @@ class JoystickInterface public: std::string mDeviceName; - JoystickInterface() {} + JoystickInterface(); - JoystickInterface(const std::string &deviceName): - mDeviceName(deviceName) - {} + //JoystickInterface(const std::string &deviceName); //static std::vector getDevices (const std::string &prefix = "/dev/input/js"); //static JoystickConfiguration getConfiguration(const std::string &deviceName); diff --git a/core/joystick/playbackJoystickInterface.cpp b/core/joystick/playbackJoystickInterface.cpp index 2c7bfbda6..29fc3d8db 100644 --- a/core/joystick/playbackJoystickInterface.cpp +++ b/core/joystick/playbackJoystickInterface.cpp @@ -1,22 +1,22 @@ #include -#include +//#include #include -#include "core/utils/global.h" -#include "core/utils/utils.h" +#include "utils/global.h" +#include "utils/utils.h" -#include "core/joystick/playbackJoystickInterface.h" +#include "joystick/playbackJoystickInterface.h" -#include "core/utils/preciseTimer.h" -#include "core/filesystem/folderScanner.h" +#include "utils/preciseTimer.h" +#include "filesystem/folderScanner.h" using namespace corecvs; using namespace std; -PlaybackJoystickInterface::PlaybackJoystickInterface(const string &deviceName): - corecvs::JoystickInterface(deviceName) +PlaybackJoystickInterface::PlaybackJoystickInterface(const string &deviceName) { - data.load(deviceName); + mDeviceName = deviceName; + data.load(mDeviceName); SYNC_PRINT(("PlaybackJoystickInterface::PlaybackJoystickInterface(): Loaded %d joystick moves\n", (int)data.states.size())); } @@ -90,7 +90,9 @@ void PlaybackJoystickInterface::run() delay = std::min(delay, data.states[count].timestamp - initialTimestamp); } - usleep(delay); + //usleep(delay); + bool QueryPerformanceCounter(delay); + uint64_t time = PreciseTimer::currentTime().usec() - initialTimestamp; diff --git a/core/kalman/CMakeLists.txt b/core/kalman/CMakeLists.txt index 4a759fa44..c120dd8ad 100644 --- a/core/kalman/CMakeLists.txt +++ b/core/kalman/CMakeLists.txt @@ -1,18 +1,19 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/cooSparseMatrix.h - ${CMAKE_CURRENT_LIST_DIR}/cholesky.h - ${CMAKE_CURRENT_LIST_DIR}/upperUnitaryMatrix.h - ${CMAKE_CURRENT_LIST_DIR}/uduDecomposed.h - # ${CMAKE_CURRENT_LIST_DIR}/kalman.h - ${CMAKE_CURRENT_LIST_DIR}/classicKalman.h - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/cooSparseMatrix.cpp - ${CMAKE_CURRENT_LIST_DIR}/cholesky.cpp - ${CMAKE_CURRENT_LIST_DIR}/upperUnitaryMatrix.cpp - ${CMAKE_CURRENT_LIST_DIR}/uduDecomposed.cpp - # ${CMAKE_CURRENT_LIST_DIR}/kalman.cpp - ${CMAKE_CURRENT_LIST_DIR}/classicKalman.cpp -) +set(KALMAN_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/cooSparseMatrix.h + ${CMAKE_CURRENT_LIST_DIR}/cholesky.h + ${CMAKE_CURRENT_LIST_DIR}/upperUnitaryMatrix.h + ${CMAKE_CURRENT_LIST_DIR}/uduDecomposed.h +# ${CMAKE_CURRENT_LIST_DIR}/kalman.h + ${CMAKE_CURRENT_LIST_DIR}/classicKalman.h + PARENT_SCOPE + ) +set(KALMAN_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/cooSparseMatrix.cpp + ${CMAKE_CURRENT_LIST_DIR}/cholesky.cpp + ${CMAKE_CURRENT_LIST_DIR}/upperUnitaryMatrix.cpp + ${CMAKE_CURRENT_LIST_DIR}/uduDecomposed.cpp +# ${CMAKE_CURRENT_LIST_DIR}/kalman.cpp + ${CMAKE_CURRENT_LIST_DIR}/classicKalman.cpp + PARENT_SCOPE + ) diff --git a/core/kalman/cholesky.cpp b/core/kalman/cholesky.cpp index b77686346..8206f8f12 100644 --- a/core/kalman/cholesky.cpp +++ b/core/kalman/cholesky.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/kalman/cholesky.h" +#include "kalman/cholesky.h" namespace corecvs { Cholesky::Cholesky() diff --git a/core/kalman/cholesky.h b/core/kalman/cholesky.h index 255a88f73..c168bb3f2 100644 --- a/core/kalman/cholesky.h +++ b/core/kalman/cholesky.h @@ -8,9 +8,9 @@ #ifndef CHOLESKY_H_ #define CHOLESKY_H_ -#include "core/math/matrix/matrix.h" -#include "core/math/matrix/diagonalMatrix.h" -#include "core/kalman/upperUnitaryMatrix.h" +#include "math/matrix/matrix.h" +#include "math/matrix/diagonalMatrix.h" +#include "kalman/upperUnitaryMatrix.h" namespace corecvs { /** diff --git a/core/kalman/classicKalman.cpp b/core/kalman/classicKalman.cpp index 2955600e5..8020cde66 100644 --- a/core/kalman/classicKalman.cpp +++ b/core/kalman/classicKalman.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/kalman/classicKalman.h" +#include "kalman/classicKalman.h" namespace corecvs { ClassicKalman::~ClassicKalman() diff --git a/core/kalman/classicKalman.h b/core/kalman/classicKalman.h index 8e80bbeda..4d2636748 100644 --- a/core/kalman/classicKalman.h +++ b/core/kalman/classicKalman.h @@ -7,11 +7,11 @@ */ #pragma once -#include "core/utils/global.h" +#include "utils/global.h" #include -#include "core/math/matrix/matrix.h" -#include "core/function/function.h" +#include "math/matrix/matrix.h" +#include "function/function.h" namespace corecvs { diff --git a/core/kalman/cooSparseMatrix.h b/core/kalman/cooSparseMatrix.h index 49f7635f3..113128a78 100644 --- a/core/kalman/cooSparseMatrix.h +++ b/core/kalman/cooSparseMatrix.h @@ -13,7 +13,7 @@ #include -#include "core/math/matrix/matrix.h" +#include "math/matrix/matrix.h" namespace corecvs { /** * diff --git a/core/kalman/uduDecomposed.h b/core/kalman/uduDecomposed.h index 8b815f9dd..3d55b041d 100644 --- a/core/kalman/uduDecomposed.h +++ b/core/kalman/uduDecomposed.h @@ -9,11 +9,11 @@ * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/kalman/upperUnitaryMatrix.h" -#include "core/math/matrix/diagonalMatrix.h" -#include "core/kalman/cholesky.h" +#include "kalman/upperUnitaryMatrix.h" +#include "math/matrix/diagonalMatrix.h" +#include "kalman/cholesky.h" namespace corecvs { diff --git a/core/kalman/upperUnitaryMatrix.cpp b/core/kalman/upperUnitaryMatrix.cpp index 124e3f015..79b76c5f1 100644 --- a/core/kalman/upperUnitaryMatrix.cpp +++ b/core/kalman/upperUnitaryMatrix.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/kalman/upperUnitaryMatrix.h" +#include "kalman/upperUnitaryMatrix.h" namespace corecvs { diff --git a/core/kalman/upperUnitaryMatrix.h b/core/kalman/upperUnitaryMatrix.h index 58596590b..7dec6fd45 100644 --- a/core/kalman/upperUnitaryMatrix.h +++ b/core/kalman/upperUnitaryMatrix.h @@ -12,7 +12,7 @@ #include -#include "core/math/matrix/matrix.h" +#include "math/matrix/matrix.h" namespace corecvs { /** diff --git a/core/kltflow/CMakeLists.txt b/core/kltflow/CMakeLists.txt index d50413f96..270b0763e 100644 --- a/core/kltflow/CMakeLists.txt +++ b/core/kltflow/CMakeLists.txt @@ -1,6 +1,9 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/kltGenerator.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/kltGenerator.cpp -) +set(KLTFLOW_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/kltGenerator.h + PARENT_SCOPE + ) + +set(KLTFLOW_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/kltGenerator.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/kltflow/kltGenerator.cpp b/core/kltflow/kltGenerator.cpp index 9faed5a70..db8630550 100644 --- a/core/kltflow/kltGenerator.cpp +++ b/core/kltflow/kltGenerator.cpp @@ -11,14 +11,14 @@ #undef TRACE -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/mathUtils.h" -#include "core/buffers/mipmapPyramid.h" -#include "core/kltflow/kltGenerator.h" -#include "core/math/vector/vector2d.h" +#include "math/mathUtils.h" +#include "buffers/mipmapPyramid.h" +#include "kltflow/kltGenerator.h" +#include "math/vector/vector2d.h" -#include "core/geometry/rectangle.h" +#include "geometry/rectangle.h" namespace corecvs { diff --git a/core/kltflow/kltGenerator.h b/core/kltflow/kltGenerator.h index 94ae80ef9..0c17ed5eb 100644 --- a/core/kltflow/kltGenerator.h +++ b/core/kltflow/kltGenerator.h @@ -8,17 +8,17 @@ * \date Feb 23, 2010 * \author alexander */ -#include "core/buffers/mipmapPyramid.h" -#include "core/buffers/integralBuffer.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/flow/flowBuffer.h" -#include "core/math/vector/vector3d.h" -#include "core/math/vector/vector2d.h" -#include "core/buffers/interpolator.h" -#include "core/buffers/kernels/spatialGradient.h" -#include "core/utils/global.h" -#include "core/math/mathUtils.h" -#include "core/buffers/mipmapPyramid.h" +#include "buffers/mipmapPyramid.h" +#include "buffers/integralBuffer.h" +#include "buffers/g12Buffer.h" +#include "buffers/flow/flowBuffer.h" +#include "math/vector/vector3d.h" +#include "math/vector/vector2d.h" +#include "buffers/interpolator.h" +#include "buffers/kernels/spatialGradient.h" +#include "utils/global.h" +#include "math/mathUtils.h" +#include "buffers/mipmapPyramid.h" namespace corecvs { diff --git a/core/math/CMakeLists.txt b/core/math/CMakeLists.txt index b751447fa..a2b97447f 100644 --- a/core/math/CMakeLists.txt +++ b/core/math/CMakeLists.txt @@ -1,93 +1,85 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/eulerAngles.h - ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix.h - ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix22.h - ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix33.h - ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix44.h - ${CMAKE_CURRENT_LIST_DIR}/matrix/diagonalMatrix.h - ${CMAKE_CURRENT_LIST_DIR}/matrix/blasReplacement.h - ${CMAKE_CURRENT_LIST_DIR}/sparseMatrix.h - ${CMAKE_CURRENT_LIST_DIR}/matrix/homographyReconstructor.h - ${CMAKE_CURRENT_LIST_DIR}/matrix/matrixOperations.h - ${CMAKE_CURRENT_LIST_DIR}/vector/vectorOperations.h - ${CMAKE_CURRENT_LIST_DIR}/vector/fixedArray.h - ${CMAKE_CURRENT_LIST_DIR}/vector/fixedVector.h - ${CMAKE_CURRENT_LIST_DIR}/vector/vector2d.h - ${CMAKE_CURRENT_LIST_DIR}/vector/vector3d.h - ${CMAKE_CURRENT_LIST_DIR}/vector/vector4d.h - ${CMAKE_CURRENT_LIST_DIR}/vector/vector.h - ${CMAKE_CURRENT_LIST_DIR}/fixed/fixedPoint24p8.h - ${CMAKE_CURRENT_LIST_DIR}/lutAlgebra.h - ${CMAKE_CURRENT_LIST_DIR}/projectiveTransform.h - ${CMAKE_CURRENT_LIST_DIR}/quaternion.h - ${CMAKE_CURRENT_LIST_DIR}/affine.h - ${CMAKE_CURRENT_LIST_DIR}/levenmarq.h - ${CMAKE_CURRENT_LIST_DIR}/gradientDescent.h - ${CMAKE_CURRENT_LIST_DIR}/helperFunctions.h - ${CMAKE_CURRENT_LIST_DIR}/generic/genericMath.h +set(MATH_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/eulerAngles.h + ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix.h + ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix22.h + ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix33.h + ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix44.h + ${CMAKE_CURRENT_LIST_DIR}/matrix/diagonalMatrix.h + ${CMAKE_CURRENT_LIST_DIR}/matrix/blasReplacement.h + ${CMAKE_CURRENT_LIST_DIR}/sparseMatrix.h + ${CMAKE_CURRENT_LIST_DIR}/matrix/homographyReconstructor.h + ${CMAKE_CURRENT_LIST_DIR}/matrix/matrixOperations.h + ${CMAKE_CURRENT_LIST_DIR}/vector/vectorOperations.h + ${CMAKE_CURRENT_LIST_DIR}/vector/fixedArray.h + ${CMAKE_CURRENT_LIST_DIR}/vector/fixedVector.h + ${CMAKE_CURRENT_LIST_DIR}/vector/vector2d.h + ${CMAKE_CURRENT_LIST_DIR}/vector/vector3d.h + ${CMAKE_CURRENT_LIST_DIR}/vector/vector4d.h + ${CMAKE_CURRENT_LIST_DIR}/vector/vector.h + ${CMAKE_CURRENT_LIST_DIR}/fixed/fixedPoint24p8.h + ${CMAKE_CURRENT_LIST_DIR}/lutAlgebra.h + ${CMAKE_CURRENT_LIST_DIR}/projectiveTransform.h + ${CMAKE_CURRENT_LIST_DIR}/quaternion.h + ${CMAKE_CURRENT_LIST_DIR}/affine.h + ${CMAKE_CURRENT_LIST_DIR}/levenmarq.h + ${CMAKE_CURRENT_LIST_DIR}/gradientDescent.h + ${CMAKE_CURRENT_LIST_DIR}/helperFunctions.h + ${CMAKE_CURRENT_LIST_DIR}/generic/genericMath.h + ${CMAKE_CURRENT_LIST_DIR}/sse/sseWrapper.h + ${CMAKE_CURRENT_LIST_DIR}/sse/sseInteger.h + ${CMAKE_CURRENT_LIST_DIR}/sse/int64x2.h + ${CMAKE_CURRENT_LIST_DIR}/sse/int32x4.h + ${CMAKE_CURRENT_LIST_DIR}/sse/int32x8v.h + ${CMAKE_CURRENT_LIST_DIR}/sse/float32x4.h + ${CMAKE_CURRENT_LIST_DIR}/sse/float32x8.h + ${CMAKE_CURRENT_LIST_DIR}/sse/floatT8.h + ${CMAKE_CURRENT_LIST_DIR}/sse/sseMath.h + ${CMAKE_CURRENT_LIST_DIR}/sse/intBase16x8.h + ${CMAKE_CURRENT_LIST_DIR}/sse/int16x8.h + ${CMAKE_CURRENT_LIST_DIR}/sse/uInt16x8.h + ${CMAKE_CURRENT_LIST_DIR}/sse/intBase8x16.h + ${CMAKE_CURRENT_LIST_DIR}/sse/int8x16.h + ${CMAKE_CURRENT_LIST_DIR}/sse/uInt8x16.h + ${CMAKE_CURRENT_LIST_DIR}/sse/doublex2.h + ${CMAKE_CURRENT_LIST_DIR}/sse/doublex4.h + ${CMAKE_CURRENT_LIST_DIR}/sse/doublex8.h + ${CMAKE_CURRENT_LIST_DIR}/avx/avxInteger.h + ${CMAKE_CURRENT_LIST_DIR}/avx/int16x16.h + ${CMAKE_CURRENT_LIST_DIR}/avx/int32x16v.h + ${CMAKE_CURRENT_LIST_DIR}/avx/int32x8.h + ${CMAKE_CURRENT_LIST_DIR}/avx/int64x4.h + ${CMAKE_CURRENT_LIST_DIR}/mathUtils.h + ${CMAKE_CURRENT_LIST_DIR}/eulerAngles.h + ${CMAKE_CURRENT_LIST_DIR}/puzzleBlock.h + ${CMAKE_CURRENT_LIST_DIR}/matrix/similarityReconstructor.h + ${CMAKE_CURRENT_LIST_DIR}/sse/doublexT4.h +# ${CMAKE_CURRENT_LIST_DIR}/extensiveCoding.h + ${CMAKE_CURRENT_LIST_DIR}/wisdom.h + ${CMAKE_CURRENT_LIST_DIR}/rotate.h + PARENT_SCOPE + ) - ${CMAKE_CURRENT_LIST_DIR}/sse/sseWrapper.h - ${CMAKE_CURRENT_LIST_DIR}/sse/sseInteger.h - ${CMAKE_CURRENT_LIST_DIR}/sse/int64x2.h - ${CMAKE_CURRENT_LIST_DIR}/sse/int32x4.h - ${CMAKE_CURRENT_LIST_DIR}/sse/int32x8v.h - ${CMAKE_CURRENT_LIST_DIR}/sse/float32x4.h - ${CMAKE_CURRENT_LIST_DIR}/sse/float32x8.h - ${CMAKE_CURRENT_LIST_DIR}/sse/floatT8.h - ${CMAKE_CURRENT_LIST_DIR}/sse/sseMath.h +set(MATH_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix.cpp + ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix22.cpp + ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix33.cpp + ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix44.cpp + ${CMAKE_CURRENT_LIST_DIR}/matrix/diagonalMatrix.cpp + ${CMAKE_CURRENT_LIST_DIR}/matrix/blasReplacement.cpp + ${CMAKE_CURRENT_LIST_DIR}/sparseMatrix.cpp + ${CMAKE_CURRENT_LIST_DIR}/matrix/homographyReconstructor.cpp + ${CMAKE_CURRENT_LIST_DIR}/vector/vector2d.cpp + ${CMAKE_CURRENT_LIST_DIR}/lutAlgebra.cpp + ${CMAKE_CURRENT_LIST_DIR}/affine.cpp + ${CMAKE_CURRENT_LIST_DIR}/projectiveTransform.cpp + ${CMAKE_CURRENT_LIST_DIR}/quaternion.cpp + ${CMAKE_CURRENT_LIST_DIR}/gradientDescent.cpp + ${CMAKE_CURRENT_LIST_DIR}/helperFunctions.cpp + ${CMAKE_CURRENT_LIST_DIR}/generic/genericMath.cpp + ${CMAKE_CURRENT_LIST_DIR}/sse/sseWrapper.cpp + ${CMAKE_CURRENT_LIST_DIR}/matrix/similarityReconstructor.cpp + ${CMAKE_CURRENT_LIST_DIR}/wisdom.cpp + ${CMAKE_CURRENT_LIST_DIR}/rotate.cpp + PARENT_SCOPE + ) - ${CMAKE_CURRENT_LIST_DIR}/sse/intBase16x8.h - ${CMAKE_CURRENT_LIST_DIR}/sse/int16x8.h - ${CMAKE_CURRENT_LIST_DIR}/sse/uInt16x8.h - - ${CMAKE_CURRENT_LIST_DIR}/sse/intBase8x16.h - ${CMAKE_CURRENT_LIST_DIR}/sse/int8x16.h - ${CMAKE_CURRENT_LIST_DIR}/sse/uInt8x16.h - ${CMAKE_CURRENT_LIST_DIR}/sse/doublex2.h - ${CMAKE_CURRENT_LIST_DIR}/sse/doublex4.h - ${CMAKE_CURRENT_LIST_DIR}/sse/doublex8.h - - ${CMAKE_CURRENT_LIST_DIR}/avx/avxInteger.h - ${CMAKE_CURRENT_LIST_DIR}/avx/int16x16.h - ${CMAKE_CURRENT_LIST_DIR}/avx/int32x16v.h - ${CMAKE_CURRENT_LIST_DIR}/avx/int32x8.h - ${CMAKE_CURRENT_LIST_DIR}/avx/int64x4.h - - ${CMAKE_CURRENT_LIST_DIR}/mathUtils.h - ${CMAKE_CURRENT_LIST_DIR}/eulerAngles.h - ${CMAKE_CURRENT_LIST_DIR}/puzzleBlock.h - ${CMAKE_CURRENT_LIST_DIR}/matrix/similarityReconstructor.h - ${CMAKE_CURRENT_LIST_DIR}/sse/doublexT4.h - # ${CMAKE_CURRENT_LIST_DIR}/extensiveCoding.h - ${CMAKE_CURRENT_LIST_DIR}/wisdom.h - ${CMAKE_CURRENT_LIST_DIR}/rotate.h - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix.cpp - ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix22.cpp - ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix33.cpp - ${CMAKE_CURRENT_LIST_DIR}/matrix/matrix44.cpp - ${CMAKE_CURRENT_LIST_DIR}/matrix/diagonalMatrix.cpp - ${CMAKE_CURRENT_LIST_DIR}/matrix/blasReplacement.cpp - ${CMAKE_CURRENT_LIST_DIR}/sparseMatrix.cpp - ${CMAKE_CURRENT_LIST_DIR}/matrix/homographyReconstructor.cpp - ${CMAKE_CURRENT_LIST_DIR}/vector/vector2d.cpp - ${CMAKE_CURRENT_LIST_DIR}/lutAlgebra.cpp - ${CMAKE_CURRENT_LIST_DIR}/affine.cpp - ${CMAKE_CURRENT_LIST_DIR}/projectiveTransform.cpp - ${CMAKE_CURRENT_LIST_DIR}/quaternion.cpp - ${CMAKE_CURRENT_LIST_DIR}/gradientDescent.cpp - ${CMAKE_CURRENT_LIST_DIR}/helperFunctions.cpp - ${CMAKE_CURRENT_LIST_DIR}/generic/genericMath.cpp - ${CMAKE_CURRENT_LIST_DIR}/sse/sseWrapper.cpp - ${CMAKE_CURRENT_LIST_DIR}/matrix/similarityReconstructor.cpp - ${CMAKE_CURRENT_LIST_DIR}/wisdom.cpp - ${CMAKE_CURRENT_LIST_DIR}/rotate.cpp -) - -#contains(DEFINES, "WITH_FFTW") { -# !build_pass: message(Adding core submodule math : fftw wrapper) -# ${CMAKE_CURRENT_LIST_DIR}/fftw/fftwWrapper.h -# ${CMAKE_CURRENT_LIST_DIR}/fftw/fftwWrapper.cpp -#} diff --git a/core/math/affine.cpp b/core/math/affine.cpp index 2b01f7f53..a5e5efb6b 100644 --- a/core/math/affine.cpp +++ b/core/math/affine.cpp @@ -5,9 +5,9 @@ * \date Apr 24, 2011 * \author alexander */ -#include "core/math/affine.h" -#include "core/math/mathUtils.h" -#include "core/math/matrix/matrix44.h" +#include "math/affine.h" +#include "math/mathUtils.h" +#include "math/matrix/matrix44.h" namespace corecvs { diff --git a/core/math/affine.h b/core/math/affine.h index 19a475d04..8f65ef00d 100644 --- a/core/math/affine.h +++ b/core/math/affine.h @@ -8,12 +8,12 @@ #ifndef AFFINE_H_ #define AFFINE_H_ -#include "core/math/vector/vector3d.h" -#include "core/math/quaternion.h" -#include "core/math/eulerAngles.h" -#include "core/math/matrix/matrix33.h" -#include "core/math/matrix/matrix22.h" -#include "core/geometry/line.h" +#include "math/vector/vector3d.h" +#include "math/quaternion.h" +#include "math/eulerAngles.h" +#include "math/matrix/matrix33.h" +#include "math/matrix/matrix22.h" +#include "geometry/line.h" namespace corecvs { diff --git a/core/math/avx/avxInteger.h b/core/math/avx/avxInteger.h index 05a8c347c..6cd0a538b 100644 --- a/core/math/avx/avxInteger.h +++ b/core/math/avx/avxInteger.h @@ -13,8 +13,8 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" namespace corecvs { diff --git a/core/math/avx/float32x8.h b/core/math/avx/float32x8.h index ae5d69938..0cb4f0d80 100644 --- a/core/math/avx/float32x8.h +++ b/core/math/avx/float32x8.h @@ -9,7 +9,7 @@ * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" //#include "int32x8.h" namespace corecvs { diff --git a/core/math/avx/int16x16.h b/core/math/avx/int16x16.h index 13eb9f0c6..68fb2c7a9 100644 --- a/core/math/avx/int16x16.h +++ b/core/math/avx/int16x16.h @@ -12,9 +12,9 @@ #include #include -#include "core/math/avx/avxInteger.h" -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" +#include "math/avx/avxInteger.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" namespace corecvs { diff --git a/core/math/avx/int32x16v.h b/core/math/avx/int32x16v.h index e0a829ef5..7b4b1dda0 100644 --- a/core/math/avx/int32x16v.h +++ b/core/math/avx/int32x16v.h @@ -8,10 +8,10 @@ * \date Sep 25, 2010 * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/math/avx/int32x8.h" +#include "math/vector/vector2d.h" +#include "math/avx/int32x8.h" namespace corecvs { diff --git a/core/math/avx/int32x8.h b/core/math/avx/int32x8.h index 8abcd2952..e31094174 100644 --- a/core/math/avx/int32x8.h +++ b/core/math/avx/int32x8.h @@ -14,11 +14,11 @@ #include #include -#include "core/math/avx/avxInteger.h" -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/int64x2.h" -#include "core/math/avx/int64x4.h" +#include "math/avx/avxInteger.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" +#include "math/sse/int64x2.h" +#include "math/avx/int64x4.h" namespace corecvs { diff --git a/core/math/avx/int64x4.h b/core/math/avx/int64x4.h index 74f082d80..05192c799 100644 --- a/core/math/avx/int64x4.h +++ b/core/math/avx/int64x4.h @@ -14,10 +14,10 @@ #include #include -#include "core/math/avx/avxInteger.h" -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/int64x2.h" +#include "math/avx/avxInteger.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" +#include "math/sse/int64x2.h" namespace corecvs { diff --git a/core/math/eulerAngles.h b/core/math/eulerAngles.h index 485a9d29f..24f612f53 100644 --- a/core/math/eulerAngles.h +++ b/core/math/eulerAngles.h @@ -8,7 +8,7 @@ #ifndef EULERANGLES_H_ #define EULERANGLES_H_ -#include "core/math/quaternion.h" +#include "math/quaternion.h" namespace corecvs { diff --git a/core/math/fftw/fftwWrapper.cpp b/core/math/fftw/fftwWrapper.cpp index e8c73cc1d..2523f50db 100644 --- a/core/math/fftw/fftwWrapper.cpp +++ b/core/math/fftw/fftwWrapper.cpp @@ -1,4 +1,4 @@ -#include "core/math/fftw/fftwWrapper.h" +#include "math/fftw/fftwWrapper.h" //#ifdef WITH_MKL diff --git a/core/math/fftw/fftwWrapper.h b/core/math/fftw/fftwWrapper.h index bd4808bd6..330a10253 100644 --- a/core/math/fftw/fftwWrapper.h +++ b/core/math/fftw/fftwWrapper.h @@ -8,12 +8,12 @@ #ifndef FFTWWRAPPER_H_ #define FFTWWRAPPER_H_ -#include "core/utils/global.h" +#include "utils/global.h" #include #include -#include "core/buffers/abstractBuffer.h" +#include "buffers/abstractBuffer.h" struct fftw_plan_s; typedef double fftw_complex[2]; diff --git a/core/math/fixed/fixedPoint24p8.cpp b/core/math/fixed/fixedPoint24p8.cpp index 9a4046963..c185ce9d2 100644 --- a/core/math/fixed/fixedPoint24p8.cpp +++ b/core/math/fixed/fixedPoint24p8.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/math/fixed/fixedPoint24p8.h" +#include "math/fixed/fixedPoint24p8.h" namespace corecvs { diff --git a/core/math/generic/genericMath.cpp b/core/math/generic/genericMath.cpp index 37cb6da0d..a293b2f72 100644 --- a/core/math/generic/genericMath.cpp +++ b/core/math/generic/genericMath.cpp @@ -5,7 +5,7 @@ * Author: alexander */ -#include "core/math/generic/genericMath.h" +#include "math/generic/genericMath.h" namespace corecvs { diff --git a/core/math/generic/genericMath.h b/core/math/generic/genericMath.h index 6771df180..4c9e43e8f 100644 --- a/core/math/generic/genericMath.h +++ b/core/math/generic/genericMath.h @@ -2,7 +2,7 @@ #define GENERICMATH_H_ #include -#include "core/utils/global.h" +#include "utils/global.h" /* * genericMath.h diff --git a/core/math/gradientDescent.cpp b/core/math/gradientDescent.cpp index 735c2d324..84311f2c6 100644 --- a/core/math/gradientDescent.cpp +++ b/core/math/gradientDescent.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/math/gradientDescent.h" +#include "math/gradientDescent.h" namespace corecvs { using std::endl; diff --git a/core/math/gradientDescent.h b/core/math/gradientDescent.h index 73564090c..b40dfbe62 100644 --- a/core/math/gradientDescent.h +++ b/core/math/gradientDescent.h @@ -10,9 +10,9 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/function/function.h" +#include "function/function.h" namespace corecvs { diff --git a/core/math/helperFunctions.cpp b/core/math/helperFunctions.cpp index 92962d097..769bbfe9d 100644 --- a/core/math/helperFunctions.cpp +++ b/core/math/helperFunctions.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/math/helperFunctions.h" +#include "math/helperFunctions.h" namespace corecvs { } //namespace corecvs diff --git a/core/math/helperFunctions.h b/core/math/helperFunctions.h index cfae2c011..167dbf93e 100644 --- a/core/math/helperFunctions.h +++ b/core/math/helperFunctions.h @@ -7,7 +7,7 @@ * \date Oct 21, 2011 * \author alexander */ -#include "core/function/function.h" +#include "function/function.h" namespace corecvs { /** diff --git a/core/math/levenmarq.h b/core/math/levenmarq.h index 406a9c116..e327fbd77 100644 --- a/core/math/levenmarq.h +++ b/core/math/levenmarq.h @@ -15,18 +15,18 @@ #include #include -#include "core/utils/global.h" - -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix.h" -#include "core/function/function.h" -#include "core/math/sparseMatrix.h" -#include "core/math/vector/vector.h" -#include "core/iterative/minresQLP.h" -#include "core/iterative/pcg.h" -#include "core/utils/statusTracker.h" -#include "core/utils/preciseTimer.h" -#include "core/stats/calculationStats.h" +#include "utils/global.h" + +#include "math/vector/vector2d.h" +#include "math/matrix/matrix.h" +#include "function/function.h" +#include "math/sparseMatrix.h" +#include "math/vector/vector.h" +#include "iterative/minresQLP.h" +#include "iterative/pcg.h" +#include "utils/statusTracker.h" +#include "utils/preciseTimer.h" +#include "stats/calculationStats.h" namespace corecvs { diff --git a/core/math/lutAlgebra.cpp b/core/math/lutAlgebra.cpp index bbb143a1d..628d76d00 100644 --- a/core/math/lutAlgebra.cpp +++ b/core/math/lutAlgebra.cpp @@ -7,8 +7,8 @@ * \author alexander */ -#include "core/math/lutAlgebra.h" -#include "core/math/vector/vector3d.h" +#include "math/lutAlgebra.h" +#include "math/vector/vector3d.h" #include #include namespace corecvs { diff --git a/core/math/lutAlgebra.h b/core/math/lutAlgebra.h index 20e3f2da5..94db630bd 100644 --- a/core/math/lutAlgebra.h +++ b/core/math/lutAlgebra.h @@ -14,7 +14,7 @@ #include #include -#include "core/math/vector/vector3d.h" +#include "math/vector/vector3d.h" #include "stdio.h" #include "math.h" diff --git a/core/math/mathUtils.h b/core/math/mathUtils.h index 2a37ce1ba..9a4e64382 100644 --- a/core/math/mathUtils.h +++ b/core/math/mathUtils.h @@ -7,7 +7,7 @@ * \date Mar 4, 2010 * \author alexander */ -#include "core/utils/global.h" +#include "../utils/global.h" #ifndef M_PI #define _USE_MATH_DEFINES diff --git a/core/math/matrix/blasReplacement.cpp b/core/math/matrix/blasReplacement.cpp index d09d465b1..a89a213f1 100644 --- a/core/math/matrix/blasReplacement.cpp +++ b/core/math/matrix/blasReplacement.cpp @@ -1,4 +1,4 @@ -#include "core/math/matrix/blasReplacement.h" +#include "math/matrix/blasReplacement.h" namespace corecvs { diff --git a/core/math/matrix/blasReplacement.h b/core/math/matrix/blasReplacement.h index afbc05c6e..4ef5bbd93 100644 --- a/core/math/matrix/blasReplacement.h +++ b/core/math/matrix/blasReplacement.h @@ -1,12 +1,13 @@ #ifndef BLAS_REPLACEMENT_H #define BLAS_REPLACEMENT_H -#include "core/utils/global.h" -#include "core/math/matrix/matrix.h" -#include "core/math/matrix/matrix33.h" +#include "utils/global.h" +#include "math/matrix/matrix.h" +#include "math/matrix/matrix33.h" -#include "core/tbbwrapper/tbbWrapper.h" -#include "core/math/sse/sseWrapper.h" +#include "tbbwrapper/tbbWrapper.h" +#include "math/sse/sseWrapper.h" +#include "math/sse/doublex4.h" namespace corecvs { @@ -199,7 +200,7 @@ struct ParallelMM8 int row = r.begin(); -#ifdef WITH_AVX +//#ifdef WITH_AVX for (; (row + BLOCK <= r.end()) && vectorize; row += BLOCK) { int column = 0; @@ -285,7 +286,7 @@ struct ParallelMM8 } } } -#endif +//#endif for (; row < r.end(); row++) { diff --git a/core/math/matrix/covMatrix22.h b/core/math/matrix/covMatrix22.h index e65954f78..455889618 100644 --- a/core/math/matrix/covMatrix22.h +++ b/core/math/matrix/covMatrix22.h @@ -1,8 +1,8 @@ #ifndef COVMATRIX22_H #define COVMATRIX22_H -#include "core/math/vector/vector3d.h" -#include "core/math/matrix/matrix22.h" +#include "math/vector/vector3d.h" +#include "math/matrix/matrix22.h" namespace corecvs { diff --git a/core/math/matrix/diagonalMatrix.cpp b/core/math/matrix/diagonalMatrix.cpp index 1082ce77a..413eb48c0 100644 --- a/core/math/matrix/diagonalMatrix.cpp +++ b/core/math/matrix/diagonalMatrix.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/math/matrix/diagonalMatrix.h" +#include "math/matrix/diagonalMatrix.h" namespace corecvs { double DiagonalMatrix::det() const diff --git a/core/math/matrix/diagonalMatrix.h b/core/math/matrix/diagonalMatrix.h index 8907e3042..e3151f5e4 100644 --- a/core/math/matrix/diagonalMatrix.h +++ b/core/math/matrix/diagonalMatrix.h @@ -10,7 +10,7 @@ #define DIAGONALMATRIX_H_ #include -#include "core/math/vector/fixedArray.h" +#include "math/vector/fixedArray.h" namespace corecvs { class Matrix; diff --git a/core/math/matrix/homographyReconstructor.cpp b/core/math/matrix/homographyReconstructor.cpp index 81f34c6cb..2fdab8f1f 100644 --- a/core/math/matrix/homographyReconstructor.cpp +++ b/core/math/matrix/homographyReconstructor.cpp @@ -8,12 +8,12 @@ #include -#include "core/math/matrix/homographyReconstructor.h" -#include "core/math/matrix/matrix.h" -#include "core/geometry/line.h" -#include "../vector/vector.h" -#include "../../kalman/classicKalman.h" -#include "../levenmarq.h" +#include "math/matrix/homographyReconstructor.h" +#include "math/matrix/matrix.h" +#include "geometry/line.h" +#include "math/vector/vector.h" +#include "kalman/classicKalman.h" +#include "math/levenmarq.h" namespace corecvs { diff --git a/core/math/matrix/homographyReconstructor.h b/core/math/matrix/homographyReconstructor.h index 2a69b1a7a..f73d67057 100644 --- a/core/math/matrix/homographyReconstructor.h +++ b/core/math/matrix/homographyReconstructor.h @@ -10,18 +10,18 @@ #include #include -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix33.h" -#include "core/math/matrix/matrix.h" -#include "core/math/matrix/matrixOperations.h" -#include "core/function/function.h" -#include "core/geometry/line.h" -#include "core/geometry/polygons.h" -#include "core/buffers/correspondenceList.h" -#include "core/filters/newstyle/newStyleBlock.h" -#include "core/cameracalibration/calibrationLocation.h" -#include "core/xml/generated/homographyAlgorithm.h" -#include "core/xml/generated/homorgaphyReconstructorBlockBase.h" +#include "math/vector/vector2d.h" +#include "math/matrix/matrix33.h" +#include "math/matrix/matrix.h" +#include "math/matrix/matrixOperations.h" +#include "function/function.h" +#include "geometry/line.h" +#include "geometry/polygons.h" +#include "buffers/correspondenceList.h" +#include "filters/newstyle/newStyleBlock.h" +#include "cameracalibration/calibrationLocation.h" +#include "xml/generated/homographyAlgorithm.h" +#include "xml/generated/homorgaphyReconstructorBlockBase.h" namespace corecvs { diff --git a/core/math/matrix/matrix.cpp b/core/math/matrix/matrix.cpp index 38865e786..9fdddb7c5 100644 --- a/core/math/matrix/matrix.cpp +++ b/core/math/matrix/matrix.cpp @@ -6,13 +6,13 @@ * \date Mar 24, 2010 * \author alexander */ -#include "core/utils/global.h" -#include "core/math/sparseMatrix.h" -#include "core/math/matrix/matrix.h" -#include "core/math/matrix/matrix33.h" -#include "core/math/matrix/blasReplacement.h" -#include "core/math/sse/sseWrapper.h" -#include "core/tbbwrapper/tbbWrapper.h" +#include "utils/global.h" +#include "math/sparseMatrix.h" +#include "math/matrix/matrix.h" +#include "math/matrix/matrix33.h" +#include "math/matrix/blasReplacement.h" +#include "math/sse/sseWrapper.h" +#include "tbbwrapper/tbbWrapper.h" #include "wrappers/cblasLapack/cblasLapackeWrapper.h" diff --git a/core/math/matrix/matrix.h b/core/math/matrix/matrix.h index 73752fd37..1ce79318c 100644 --- a/core/math/matrix/matrix.h +++ b/core/math/matrix/matrix.h @@ -12,13 +12,13 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractBuffer.h" -#include "core/math/matrix/matrix33.h" -#include "core/math/matrix/matrix44.h" -#include "core/math/matrix/diagonalMatrix.h" -#include "core/math/vector/vector.h" +#include "buffers/abstractBuffer.h" +#include "math/matrix/matrix33.h" +#include "math/matrix/matrix44.h" +#include "math/matrix/diagonalMatrix.h" +#include "math/vector/vector.h" namespace corecvs { diff --git a/core/math/matrix/matrix22.cpp b/core/math/matrix/matrix22.cpp index c14a33b94..dfd8b0a02 100644 --- a/core/math/matrix/matrix22.cpp +++ b/core/math/matrix/matrix22.cpp @@ -1,6 +1,6 @@ #include -#include "core/math/matrix/matrix22.h" +#include "math/matrix/matrix22.h" namespace corecvs { diff --git a/core/math/matrix/matrix22.h b/core/math/matrix/matrix22.h index eadb0962a..a97c4c05c 100644 --- a/core/math/matrix/matrix22.h +++ b/core/math/matrix/matrix22.h @@ -20,10 +20,10 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector3d.h" -#include "core/math/vector/fixedVector.h" +#include "math/vector/vector3d.h" +#include "math/vector/fixedVector.h" namespace corecvs { diff --git a/core/math/matrix/matrix33.cpp b/core/math/matrix/matrix33.cpp index 4d453651a..bf330c534 100644 --- a/core/math/matrix/matrix33.cpp +++ b/core/math/matrix/matrix33.cpp @@ -7,8 +7,8 @@ * \date Jan 27, 2007 * \author Alexander Pimenov **/ -#include "core/math/matrix/matrix33.h" -#include "core/math/matrix/matrix.h" +#include "math/matrix/matrix33.h" +#include "math/matrix/matrix.h" namespace corecvs { diff --git a/core/math/matrix/matrix33.h b/core/math/matrix/matrix33.h index 865295c52..a44d4b2a2 100644 --- a/core/math/matrix/matrix33.h +++ b/core/math/matrix/matrix33.h @@ -21,10 +21,10 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector3d.h" -#include "core/math/vector/fixedVector.h" +#include "math/vector/vector3d.h" +#include "math/vector/fixedVector.h" namespace corecvs { diff --git a/core/math/matrix/matrix44.cpp b/core/math/matrix/matrix44.cpp index 34980b910..6312f8cde 100644 --- a/core/math/matrix/matrix44.cpp +++ b/core/math/matrix/matrix44.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/math/matrix/matrix44.h" +#include "math/matrix/matrix44.h" namespace corecvs { Matrix44::Matrix44() diff --git a/core/math/matrix/matrix44.h b/core/math/matrix/matrix44.h index 986fb2388..5fcc8c87a 100644 --- a/core/math/matrix/matrix44.h +++ b/core/math/matrix/matrix44.h @@ -9,9 +9,9 @@ * \author alexander */ -#include "core/math/vector/fixedVector.h" -#include "core/math/matrix/matrix33.h" -#include "core/math/vector/vector4d.h" +#include "math/vector/fixedVector.h" +#include "math/matrix/matrix33.h" +#include "math/vector/vector4d.h" namespace corecvs { diff --git a/core/math/matrix/matrixOperations.h b/core/math/matrix/matrixOperations.h index 0c7262834..3b61ba40b 100644 --- a/core/math/matrix/matrixOperations.h +++ b/core/math/matrix/matrixOperations.h @@ -39,7 +39,7 @@ * \date Aug 28, 2015 **/ -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { template @@ -322,7 +322,7 @@ class MatrixVisitOperationsBase /** * A matrix over abstract buffer having a static size **/ -#include "core/buffers/abstractBuffer.h" +#include "buffers/abstractBuffer.h" template class AbsMatrixFixed : public AbstractBuffer, public MatrixOperationsBase, Element> @@ -357,7 +357,7 @@ class AbsMatrixFixed : public AbstractBuffer, public MatrixOperati * A matrix over fixed vector having a static size **/ -#include "core/math/vector/fixedVector.h" +#include "math/vector/fixedVector.h" template class FixMatrixFixed : public FixedVector, public MatrixOperationsBase, Element> diff --git a/core/math/matrix/similarityReconstructor.cpp b/core/math/matrix/similarityReconstructor.cpp index 61f754434..2774ed43d 100644 --- a/core/math/matrix/similarityReconstructor.cpp +++ b/core/math/matrix/similarityReconstructor.cpp @@ -1,6 +1,6 @@ -#include "core/math/matrix/similarityReconstructor.h" -#include "core/math/levenmarq.h" -#include "core/cameracalibration/calibrationLocation.h" +#include "math/matrix/similarityReconstructor.h" +#include "math/levenmarq.h" +#include "cameracalibration/calibrationLocation.h" namespace corecvs { diff --git a/core/math/matrix/similarityReconstructor.h b/core/math/matrix/similarityReconstructor.h index 3fe8b719a..1e235e7d0 100644 --- a/core/math/matrix/similarityReconstructor.h +++ b/core/math/matrix/similarityReconstructor.h @@ -11,14 +11,14 @@ #include #include -#include "core/math/affine.h" -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix33.h" -#include "core/buffers/correspondenceList.h" -#include "core/math/matrix/matrix.h" -#include "core/math/quaternion.h" -#include "core/function/function.h" -#include "core/math/affine.h" +#include "math/affine.h" +#include "math/vector/vector2d.h" +#include "math/matrix/matrix33.h" +#include "buffers/correspondenceList.h" +#include "math/matrix/matrix.h" +#include "math/quaternion.h" +#include "function/function.h" +#include "math/affine.h" namespace corecvs { diff --git a/core/math/neon/float32x4.h b/core/math/neon/float32x4.h index 2034e4d1d..62e98bd11 100644 --- a/core/math/neon/float32x4.h +++ b/core/math/neon/float32x4.h @@ -9,7 +9,7 @@ * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { class ALIGN_DATA(16) Float32x4 diff --git a/core/math/neon/int16x8.h b/core/math/neon/int16x8.h index 99ee33b82..9fd26a266 100644 --- a/core/math/neon/int16x8.h +++ b/core/math/neon/int16x8.h @@ -12,8 +12,8 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" namespace corecvs { diff --git a/core/math/neon/int32x4.h b/core/math/neon/int32x4.h index 1baeb4c70..e49725ede 100644 --- a/core/math/neon/int32x4.h +++ b/core/math/neon/int32x4.h @@ -12,9 +12,9 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/int64x2.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" +#include "math/sse/int64x2.h" namespace corecvs { #define _MM_SHUFFLE(fp3,fp2,fp1,fp0) \ diff --git a/core/math/neon/int32x8.h b/core/math/neon/int32x8.h index 53adaf609..f4944bb8e 100644 --- a/core/math/neon/int32x8.h +++ b/core/math/neon/int32x8.h @@ -8,8 +8,8 @@ * \date Sep 25, 2010 * \author: alexander */ -#include "core/utils/global.h" -#include "core/math/vector/vector2d.h" +#include "utils/global.h" +#include "math/vector/vector2d.h" namespace corecvs { class Int32x8 : public Vector2d diff --git a/core/math/neon/int32x8v.h b/core/math/neon/int32x8v.h index e4426938f..19e9a06b6 100644 --- a/core/math/neon/int32x8v.h +++ b/core/math/neon/int32x8v.h @@ -8,10 +8,10 @@ * \date Sep 25, 2010 * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/math/neon/int32x4.h" +#include "math/vector/vector2d.h" +#include "math/neon/int32x4.h" namespace corecvs { diff --git a/core/math/neon/int64x2.h b/core/math/neon/int64x2.h index 6f1f21c08..5a7a9ac2d 100644 --- a/core/math/neon/int64x2.h +++ b/core/math/neon/int64x2.h @@ -12,8 +12,8 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" namespace corecvs { class ALIGN_DATA(16) Int64x2 diff --git a/core/math/neon/neonMath.h b/core/math/neon/neonMath.h index ce72a6d0d..65f9e5b85 100644 --- a/core/math/neon/neonMath.h +++ b/core/math/neon/neonMath.h @@ -10,7 +10,7 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { class SSEMath diff --git a/core/math/neon/neonWrapper.cpp b/core/math/neon/neonWrapper.cpp index 090eefd50..802575108 100644 --- a/core/math/neon/neonWrapper.cpp +++ b/core/math/neon/neonWrapper.cpp @@ -6,7 +6,7 @@ * \date Oct 7, 2010 */ -#include "core/math/neon/neonWrapper.h" +#include "math/neon/neonWrapper.h" namespace corecvs { #ifdef PROFILE_ACCESS_ALIGNMENT diff --git a/core/math/neon/neonWrapper.h b/core/math/neon/neonWrapper.h index cadd603a9..7effc867a 100644 --- a/core/math/neon/neonWrapper.h +++ b/core/math/neon/neonWrapper.h @@ -11,11 +11,11 @@ #define NEON_WRAPPER_H_ #ifdef WITH_NEON -#include "core/math/neon/int64x2.h" -#include "core/math/neon/int32x4.h" -#include "core/math/neon/uInt32x4.h" -//#include "core/math/neon/int32x8.h" -#include "core/math/neon/int32x8v.h" +#include "math/neon/int64x2.h" +#include "math/neon/int32x4.h" +#include "math/neon/uInt32x4.h" +//#include "math/neon/int32x8.h" +#include "math/neon/int32x8v.h" // Int32x8 is a vector of two Int32x4 @@ -23,11 +23,11 @@ namespace corecvs { typedef Int32x8v Int32x8; } -#include "core/math/neon/int16x8.h" -#include "core/math/neon/uInt16x8.h" +#include "math/neon/int16x8.h" +#include "math/neon/uInt16x8.h" -#include "core/math/neon/float32x4.h" +#include "math/neon/float32x4.h" namespace corecvs { typedef Float32x4 FloatxN; diff --git a/core/math/neon/uInt16x8.h b/core/math/neon/uInt16x8.h index 785c1ad53..7c58f4eb8 100644 --- a/core/math/neon/uInt16x8.h +++ b/core/math/neon/uInt16x8.h @@ -12,8 +12,8 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" namespace corecvs { diff --git a/core/math/neon/uInt32x4.h b/core/math/neon/uInt32x4.h index 827f6c78c..632b42245 100644 --- a/core/math/neon/uInt32x4.h +++ b/core/math/neon/uInt32x4.h @@ -12,9 +12,9 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/int64x2.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" +#include "math/sse/int64x2.h" namespace corecvs { class ALIGN_DATA(16) UInt32x4 diff --git a/core/math/projectiveTransform.cpp b/core/math/projectiveTransform.cpp index 73733eabe..729ffcc9e 100644 --- a/core/math/projectiveTransform.cpp +++ b/core/math/projectiveTransform.cpp @@ -8,7 +8,7 @@ * \author alexander */ -#include "core/math/projectiveTransform.h" +#include "math/projectiveTransform.h" namespace corecvs { } //namespace corecvs diff --git a/core/math/projectiveTransform.h b/core/math/projectiveTransform.h index 163244db3..647b3a1a0 100644 --- a/core/math/projectiveTransform.h +++ b/core/math/projectiveTransform.h @@ -10,10 +10,10 @@ #ifndef PROJECTIVETRANSFORM_H_ #define PROJECTIVETRANSFORM_H_ -#include "core/buffers/deformMap.h" -#include "core/buffers/abstractBuffer.h" -#include "core/math/matrix/matrix33.h" -#include "core/math/vector/vector2d.h" +#include "buffers/deformMap.h" +#include "buffers/abstractBuffer.h" +#include "math/matrix/matrix33.h" +#include "math/vector/vector2d.h" namespace corecvs { /** diff --git a/core/math/quaternion.cpp b/core/math/quaternion.cpp index 8dce476d5..85d92ccab 100644 --- a/core/math/quaternion.cpp +++ b/core/math/quaternion.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/math/quaternion.h" +#include "math/quaternion.h" namespace corecvs { diff --git a/core/math/quaternion.h b/core/math/quaternion.h index 239c5c7ce..8ed92bee6 100644 --- a/core/math/quaternion.h +++ b/core/math/quaternion.h @@ -9,10 +9,10 @@ #ifndef QUATERNION_H_ #define QUATERNION_H_ -#include "core/math/matrix/matrix33.h" -#include "core/math/matrix/matrix44.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/mathUtils.h" +#include "math/matrix/matrix33.h" +#include "math/matrix/matrix44.h" +#include "math/vector/fixedVector.h" +#include "math/mathUtils.h" namespace corecvs { @@ -425,22 +425,23 @@ class GenericQuaternion : public FixedVectorBase, static GenericQuaternion RotationX(ElementType alpha) { - ElementType sina2 = sin(alpha * 0.5); - ElementType cosa2 = cos(alpha * 0.5); + ElementType sina2 = std::sin(alpha * 0.5); + ElementType cosa2 = std::cos(alpha * 0.5); return GenericQuaternion(sina2, 0.0, 0.0, cosa2); + } static GenericQuaternion RotationY(ElementType alpha) { - ElementType sina2 = sin(alpha * 0.5); - ElementType cosa2 = cos(alpha * 0.5); + ElementType sina2 = std::sin(alpha * 0.5); + ElementType cosa2 = std::cos(alpha * 0.5); return GenericQuaternion(0.0, sina2, 0.0, cosa2); } static GenericQuaternion RotationZ(ElementType alpha) { - ElementType sina2 = sin(alpha * 0.5); - ElementType cosa2 = cos(alpha * 0.5); + ElementType sina2 = std::sin(alpha * 0.5); + ElementType cosa2 = std::cos(alpha * 0.5); return GenericQuaternion(0.0, 0.0, sina2, cosa2); } diff --git a/core/math/rotate.cpp b/core/math/rotate.cpp index da32d141f..461aa5dc5 100644 --- a/core/math/rotate.cpp +++ b/core/math/rotate.cpp @@ -1,10 +1,10 @@ #include #include #include -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/utils/global.h" -#include "core/math/rotate.h" -#include "core/math/matrix/matrixOperations.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "utils/global.h" +#include "math/rotate.h" +#include "math/matrix/matrixOperations.h" namespace corecvs { @@ -164,18 +164,21 @@ RGB24Buffer* RotateHelper::rotateWithLancozVF(double angle, const RGB24Buffer *r } -RGB24Buffer* RotateHelper::rotateWithLancozVFP(double angle, const RGB24Buffer *rgb24buffer, int newH, int newW, double lanczos_size) { +RGB24Buffer* RotateHelper::rotateWithLancozVFP(double angle, const RGB24Buffer* rgb24buffer, int newH, int newW, double lanczos_size) { Matrix33 operation = // Matrix33::ShiftProj(rgb24buffer->w / 2, rgb24buffer->h / 2) - Matrix33::ShiftProj(newW / 2, newH / 2) - * Matrix33::RotationZ(angle) - * Matrix33::ShiftProj(-rgb24buffer->w / 2, -rgb24buffer->h / 2); + Matrix33::ShiftProj(newW / 2, newH / 2) + * Matrix33::RotationZ(angle) + * Matrix33::ShiftProj(-rgb24buffer->w / 2, -rgb24buffer->h / 2); operation.invert(); - RGB24Buffer *rotated = new RGB24Buffer(newH, newW); + RGB24Buffer* rotated = new RGB24Buffer(newH, newW); const int scale = 1024; + //float lut[(int)(lanczos_size + 1) * scale]; + //float* lut = new float[(int)(lanczos_size + 1) * scale]; + std::vector lut; + lut.resize((int)(lanczos_size + 1) * scale); - float lut[(int)(lanczos_size + 1) * scale]; for (size_t i = 0; i < CORE_COUNT_OF(lut); i++) { lut[i] = LanczosFilter((float) i / scale, (float)lanczos_size); // cout << lut[i] << ", "; @@ -253,13 +256,18 @@ RGB24Buffer* RotateHelper::rotateWithLancozVFPI(double angle, const RGB24Buffer operation.invert(); RGB24Buffer *rotated = new RGB24Buffer(newH, newW); - const int scale = 1024; + int scale = 1024; //const int pfpos = 1024; const int pfpos = 1048; - float lut [(int)(lanczos_size + 1) * scale]; - int32_t luti[(int)(lanczos_size + 1) * scale]; + //float lut [(int)(lanczos_size + 1) * scale]; + //int32_t luti[(int)(lanczos_size + 1) * scale]; + + std::vector lut; + lut.resize((int)(lanczos_size + 1) * scale); + std::vector luti; + lut.resize((int)(lanczos_size + 1) * scale); for (size_t i = 0; i < CORE_COUNT_OF(lut); i++) { lut [i] = LanczosFilter((double)i / scale, lanczos_size); diff --git a/core/math/rotate.h b/core/math/rotate.h index f1e1df5a9..5aefc9ce6 100644 --- a/core/math/rotate.h +++ b/core/math/rotate.h @@ -1,6 +1,6 @@ #ifndef ROTATE_H #define ROTATE_H -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" namespace corecvs { diff --git a/core/math/sparseMatrix.cpp b/core/math/sparseMatrix.cpp index 11893c42f..98b5ca24f 100644 --- a/core/math/sparseMatrix.cpp +++ b/core/math/sparseMatrix.cpp @@ -1,4 +1,4 @@ -#include "core/math/sparseMatrix.h" +#include "math/sparseMatrix.h" #include "wrappers/cblasLapack/cblasLapackeWrapper.h" #include diff --git a/core/math/sparseMatrix.h b/core/math/sparseMatrix.h index 3356487e7..d2bdf16d9 100644 --- a/core/math/sparseMatrix.h +++ b/core/math/sparseMatrix.h @@ -7,8 +7,8 @@ #include #include -#include "core/math/matrix/matrix.h" -#include "core/math/vector/vector.h" +#include "math/matrix/matrix.h" +#include "math/vector/vector.h" #ifdef WITH_MKL #include @@ -20,7 +20,7 @@ #include "cuda.h" #endif -#include "core/math/wisdom.h" +#include "math/wisdom.h" namespace corecvs { diff --git a/core/math/sse/doublex2.h b/core/math/sse/doublex2.h index 20b78ce49..52442efe5 100644 --- a/core/math/sse/doublex2.h +++ b/core/math/sse/doublex2.h @@ -10,7 +10,7 @@ * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" #ifdef WITH_FMA # include diff --git a/core/math/sse/doublex4.h b/core/math/sse/doublex4.h index 8a3346426..6b809f495 100644 --- a/core/math/sse/doublex4.h +++ b/core/math/sse/doublex4.h @@ -10,7 +10,7 @@ * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" #include diff --git a/core/math/sse/doublex8.h b/core/math/sse/doublex8.h index 01e280430..510b04ef2 100644 --- a/core/math/sse/doublex8.h +++ b/core/math/sse/doublex8.h @@ -10,9 +10,9 @@ * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/sse/doublex4.h" +#include "math/sse/doublex4.h" namespace corecvs { diff --git a/core/math/sse/doublexT4.h b/core/math/sse/doublexT4.h index 53960ac21..0c4818f52 100644 --- a/core/math/sse/doublexT4.h +++ b/core/math/sse/doublexT4.h @@ -10,10 +10,10 @@ * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/doublex4.h" +#include "math/vector/fixedVector.h" +#include "math/sse/doublex4.h" namespace corecvs { diff --git a/core/math/sse/float32x4.h b/core/math/sse/float32x4.h index b9b32cbee..51da4ba58 100644 --- a/core/math/sse/float32x4.h +++ b/core/math/sse/float32x4.h @@ -9,7 +9,7 @@ * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { diff --git a/core/math/sse/float32x8.h b/core/math/sse/float32x8.h index 6a638a12e..8bb553676 100644 --- a/core/math/sse/float32x8.h +++ b/core/math/sse/float32x8.h @@ -9,8 +9,8 @@ * \author: alexander */ -#include "core/utils/global.h" -#include "core/math/avx/int32x8.h" +#include "utils/global.h" +#include "math/avx/int32x8.h" namespace corecvs { diff --git a/core/math/sse/floatT8.h b/core/math/sse/floatT8.h index 8eceb50c7..8d97a7b79 100644 --- a/core/math/sse/floatT8.h +++ b/core/math/sse/floatT8.h @@ -10,10 +10,10 @@ * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/avx/float32x8.h" +#include "math/vector/fixedVector.h" +#include "math/avx/float32x8.h" namespace corecvs { diff --git a/core/math/sse/int16x8.h b/core/math/sse/int16x8.h index 35b79c840..ca0e69e6a 100644 --- a/core/math/sse/int16x8.h +++ b/core/math/sse/int16x8.h @@ -12,9 +12,9 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/intBase16x8.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" +#include "math/sse/intBase16x8.h" namespace corecvs { diff --git a/core/math/sse/int32x4.h b/core/math/sse/int32x4.h index d393ed736..6b3dd4d4a 100644 --- a/core/math/sse/int32x4.h +++ b/core/math/sse/int32x4.h @@ -13,9 +13,9 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/int64x2.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" +#include "math/sse/int64x2.h" namespace corecvs { diff --git a/core/math/sse/int32x8v.h b/core/math/sse/int32x8v.h index 8288e9d29..ec279f4ca 100644 --- a/core/math/sse/int32x8v.h +++ b/core/math/sse/int32x8v.h @@ -8,10 +8,10 @@ * \date Sep 25, 2010 * \author: alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/math/sse/int32x4.h" +#include "math/vector/vector2d.h" +#include "math/sse/int32x4.h" namespace corecvs { diff --git a/core/math/sse/int64x2.h b/core/math/sse/int64x2.h index 2650e850c..eaf125e16 100644 --- a/core/math/sse/int64x2.h +++ b/core/math/sse/int64x2.h @@ -12,10 +12,10 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/sseInteger.h" +#include "math/vector/fixedVector.h" +#include "math/sse/sseInteger.h" namespace corecvs { diff --git a/core/math/sse/int8x16.h b/core/math/sse/int8x16.h index e3b2789ea..a4465e62e 100644 --- a/core/math/sse/int8x16.h +++ b/core/math/sse/int8x16.h @@ -12,9 +12,9 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/intBase8x16.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" +#include "math/sse/intBase8x16.h" namespace corecvs { diff --git a/core/math/sse/intBase16x8.h b/core/math/sse/intBase16x8.h index 54aee7380..8fdc4c566 100644 --- a/core/math/sse/intBase16x8.h +++ b/core/math/sse/intBase16x8.h @@ -12,11 +12,11 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/sseInteger.h" -#include "core/math/sse/int32x4.h" -#include "core/math/sse/int32x8v.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" +#include "math/sse/sseInteger.h" +#include "math/sse/int32x4.h" +#include "math/sse/int32x8v.h" namespace corecvs { diff --git a/core/math/sse/intBase8x16.h b/core/math/sse/intBase8x16.h index 8a62e4dbb..d072348c1 100644 --- a/core/math/sse/intBase8x16.h +++ b/core/math/sse/intBase8x16.h @@ -12,8 +12,8 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" namespace corecvs { diff --git a/core/math/sse/sseInteger.h b/core/math/sse/sseInteger.h index 7f04e87b1..a04672f61 100644 --- a/core/math/sse/sseInteger.h +++ b/core/math/sse/sseInteger.h @@ -12,8 +12,8 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" namespace corecvs { diff --git a/core/math/sse/sseMath.h b/core/math/sse/sseMath.h index ebea5bfeb..94bc19b6e 100644 --- a/core/math/sse/sseMath.h +++ b/core/math/sse/sseMath.h @@ -7,10 +7,10 @@ * \date Oct 24, 2010 */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/sse/sseWrapper.h" -#include "core/math/puzzleBlock.h" +#include "math/sse/sseWrapper.h" +#include "math/puzzleBlock.h" #ifdef WITH_SSE4 #include #endif diff --git a/core/math/sse/sseWrapper.cpp b/core/math/sse/sseWrapper.cpp index 28c936a5c..b8b22f681 100644 --- a/core/math/sse/sseWrapper.cpp +++ b/core/math/sse/sseWrapper.cpp @@ -9,7 +9,7 @@ #include #include -#include "core/math/sse/sseWrapper.h" +#include "math/sse/sseWrapper.h" namespace corecvs { diff --git a/core/math/sse/sseWrapper.h b/core/math/sse/sseWrapper.h index 961d3af87..626bd37dd 100644 --- a/core/math/sse/sseWrapper.h +++ b/core/math/sse/sseWrapper.h @@ -11,38 +11,38 @@ #define SEEWRAPPER_H_ #ifdef WITH_SSE -#include "core/math/sse/sseInteger.h" -#include "core/math/sse/int64x2.h" -#include "core/math/sse/int32x4.h" -#include "core/math/sse/int32x8v.h" -#include "core/math/sse/int16x8.h" -#include "core/math/sse/uInt16x8.h" +#include "math/sse/sseInteger.h" +#include "math/sse/int64x2.h" +#include "math/sse/int32x4.h" +#include "math/sse/int32x8v.h" +#include "math/sse/int16x8.h" +#include "math/sse/uInt16x8.h" -#include "core/math/sse/int8x16.h" -#include "core/math/sse/uInt8x16.h" +#include "math/sse/int8x16.h" +#include "math/sse/uInt8x16.h" -#include "core/math/sse/float32x4.h" -#include "core/math/sse/doublex2.h" +#include "math/sse/float32x4.h" +#include "math/sse/doublex2.h" #endif // WITH_SSE #ifdef WITH_AVX -#include "core/math/sse/float32x8.h" -#include "core/math/sse/doublex4.h" -#include "core/math/sse/doublex8.h" -#include "core/math/sse/doublexT4.h" -#include "core/math/sse/floatT8.h" +#include "math/sse/float32x8.h" +#include "math/sse/doublex4.h" +#include "math/sse/doublex8.h" +#include "math/sse/doublexT4.h" +#include "math/sse/floatT8.h" #endif // WITH_AVX #ifdef WITH_AVX2 -#include "core/math/avx/avxInteger.h" -#include "core/math/avx/int64x4.h" -#include "core/math/avx/int32x8.h" -#include "core/math/avx/int32x16v.h" -#include "core/math/avx/int16x16.h" +#include "math/avx/avxInteger.h" +#include "math/avx/int64x4.h" +#include "math/avx/int32x8.h" +#include "math/avx/int32x16v.h" +#include "math/avx/int16x16.h" #endif // WITH_AVX2 #ifdef WITH_SSE -#include "core/math/sse/sseMath.h" +#include "math/sse/sseMath.h" #endif #ifdef _MSC_VER diff --git a/core/math/sse/uInt16x8.h b/core/math/sse/uInt16x8.h index 6f6238efd..082af96ca 100644 --- a/core/math/sse/uInt16x8.h +++ b/core/math/sse/uInt16x8.h @@ -13,10 +13,10 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/intBase16x8.h" +#include "math/vector/fixedVector.h" +#include "math/sse/intBase16x8.h" namespace corecvs { diff --git a/core/math/sse/uInt8x16.h b/core/math/sse/uInt8x16.h index 03919884f..61f21b9fd 100644 --- a/core/math/sse/uInt8x16.h +++ b/core/math/sse/uInt8x16.h @@ -12,9 +12,9 @@ #include #include -#include "core/utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/math/sse/intBase8x16.h" +#include "utils/global.h" +#include "math/vector/fixedVector.h" +#include "math/sse/intBase8x16.h" namespace corecvs { diff --git a/core/math/vector/fixedArray.h b/core/math/vector/fixedArray.h index e56b9a1ab..5f24b5abd 100644 --- a/core/math/vector/fixedArray.h +++ b/core/math/vector/fixedArray.h @@ -12,9 +12,9 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vectorOperations.h" +#include "math/vector/vectorOperations.h" namespace corecvs { diff --git a/core/math/vector/fixedVector.h b/core/math/vector/fixedVector.h index eeea20c84..ece267656 100644 --- a/core/math/vector/fixedVector.h +++ b/core/math/vector/fixedVector.h @@ -12,7 +12,7 @@ */ #include -#include "core/math/vector/vectorOperations.h" +#include "math/vector/vectorOperations.h" namespace corecvs { diff --git a/core/math/vector/vector.h b/core/math/vector/vector.h index 6db1498f3..a07005aa0 100644 --- a/core/math/vector/vector.h +++ b/core/math/vector/vector.h @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/math/vector/fixedArray.h" +#include "math/vector/fixedArray.h" namespace corecvs { diff --git a/core/math/vector/vector2d.cpp b/core/math/vector/vector2d.cpp index dfc5fd747..c91aa84ff 100644 --- a/core/math/vector/vector2d.cpp +++ b/core/math/vector/vector2d.cpp @@ -7,7 +7,7 @@ * \author sergeyfed */ -#include "core/math/vector/vector2d.h" +#include "math/vector/vector2d.h" namespace corecvs { diff --git a/core/math/vector/vector2d.h b/core/math/vector/vector2d.h index f39a27365..2b559a78f 100644 --- a/core/math/vector/vector2d.h +++ b/core/math/vector/vector2d.h @@ -15,17 +15,17 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" //#ifdef REFLECTION_IN_CORE -#include "core/reflection/reflection.h" +#include "reflection/reflection.h" //#endif // REFLECTION_IN_CORE -#include "core/math/vector/fixedVector.h" -#include "core/math/vector/vector.h" +#include "math/vector/fixedVector.h" +#include "math/vector/vector.h" // This is discussable if there should be such a dependancy -#include "core/xml/generated/vector2dParameters.h" +#include "xml/generated/vector2dParameters.h" namespace corecvs { diff --git a/core/math/vector/vector3d.h b/core/math/vector/vector3d.h index 522753721..f12031ada 100644 --- a/core/math/vector/vector3d.h +++ b/core/math/vector/vector3d.h @@ -12,8 +12,8 @@ #include -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector.h" namespace corecvs { diff --git a/core/math/vector/vector4d.h b/core/math/vector/vector4d.h index ad8377860..3cb52582a 100644 --- a/core/math/vector/vector4d.h +++ b/core/math/vector/vector4d.h @@ -11,9 +11,9 @@ #define _VECTOR4D_H_ #include "math.h" -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/math/vector/vector.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "math/vector/vector.h" namespace corecvs { diff --git a/core/math/vector/vectorOperations.h b/core/math/vector/vectorOperations.h index c6e6c8483..7cd345051 100644 --- a/core/math/vector/vectorOperations.h +++ b/core/math/vector/vectorOperations.h @@ -40,9 +40,9 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/reflection/reflection.h" +#include "reflection/reflection.h" using std::numeric_limits; //using std::istream; diff --git a/core/math/wisdom.cpp b/core/math/wisdom.cpp index 3ede6ade9..538f79fc9 100644 --- a/core/math/wisdom.cpp +++ b/core/math/wisdom.cpp @@ -1,4 +1,4 @@ -#include "core/math/wisdom.h" +#include "math/wisdom.h" #include diff --git a/core/math/wisdom.h b/core/math/wisdom.h index a90b13a45..439f72e47 100644 --- a/core/math/wisdom.h +++ b/core/math/wisdom.h @@ -13,8 +13,8 @@ #include #include -#include "core/utils/global.h" -#include "core/tbbwrapper/tbbWrapper.h" +#include "utils/global.h" +#include "tbbwrapper/tbbWrapper.h" namespace corecvs { diff --git a/core/meanshift/CMakeLists.txt b/core/meanshift/CMakeLists.txt index 08c41576d..9aaf53511 100644 --- a/core/meanshift/CMakeLists.txt +++ b/core/meanshift/CMakeLists.txt @@ -1,11 +1,12 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/meanShiftCalculator.h - ${CMAKE_CURRENT_LIST_DIR}/meanShiftWindow.h - ${CMAKE_CURRENT_LIST_DIR}/abstractMeanShiftKernel.h - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/meanShiftCalculator.cpp - ${CMAKE_CURRENT_LIST_DIR}/meanShiftWindow.cpp - ) +set(MEANSHIFT_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/meanShiftCalculator.h + ${CMAKE_CURRENT_LIST_DIR}/meanShiftWindow.h + ${CMAKE_CURRENT_LIST_DIR}/abstractMeanShiftKernel.h + PARENT_SCOPE + ) +set(MEANSHIFT_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/meanShiftCalculator.cpp + ${CMAKE_CURRENT_LIST_DIR}/meanShiftWindow.cpp + PARENT_SCOPE + ) diff --git a/core/meanshift/abstractMeanShiftKernel.h b/core/meanshift/abstractMeanShiftKernel.h index 65a8e8cb7..83f51ec18 100644 --- a/core/meanshift/abstractMeanShiftKernel.h +++ b/core/meanshift/abstractMeanShiftKernel.h @@ -11,7 +11,7 @@ * \author ylitvinov */ -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { class AbstractMeanShiftKernel diff --git a/core/meanshift/meanShiftCalculator.cpp b/core/meanshift/meanShiftCalculator.cpp index 2313e7827..36ce64e83 100644 --- a/core/meanshift/meanShiftCalculator.cpp +++ b/core/meanshift/meanShiftCalculator.cpp @@ -8,7 +8,7 @@ * \author ylitvinov */ -#include "core/meanshift/meanShiftCalculator.h" +#include "meanshift/meanShiftCalculator.h" namespace corecvs { diff --git a/core/meanshift/meanShiftCalculator.h b/core/meanshift/meanShiftCalculator.h index 05519e66b..c6db2b8e4 100644 --- a/core/meanshift/meanShiftCalculator.h +++ b/core/meanshift/meanShiftCalculator.h @@ -10,8 +10,8 @@ * \author ylitvinov */ -#include "core/meanshift/meanShiftWindow.h" -#include "core/meanshift/abstractMeanShiftKernel.h" +#include "meanshift/meanShiftWindow.h" +#include "meanshift/abstractMeanShiftKernel.h" #include namespace corecvs { diff --git a/core/meanshift/meanShiftWindow.cpp b/core/meanshift/meanShiftWindow.cpp index b2e8d8676..c443d819c 100644 --- a/core/meanshift/meanShiftWindow.cpp +++ b/core/meanshift/meanShiftWindow.cpp @@ -7,7 +7,7 @@ * \author tbryksin * \author ylitvinov */ -#include "core/meanshift/meanShiftWindow.h" +#include "meanshift/meanShiftWindow.h" namespace corecvs { diff --git a/core/meanshift/meanShiftWindow.h b/core/meanshift/meanShiftWindow.h index aa227df86..968b28e7a 100644 --- a/core/meanshift/meanShiftWindow.h +++ b/core/meanshift/meanShiftWindow.h @@ -10,9 +10,9 @@ * \author ylitvinov */ -#include "core/buffers/flow/flowBuffer.h" -#include "core/segmentation/tileGrid.h" -#include "core/meanshift/abstractMeanShiftKernel.h" +#include "buffers/flow/flowBuffer.h" +#include "segmentation/tileGrid.h" +#include "meanshift/abstractMeanShiftKernel.h" #include namespace corecvs { diff --git a/core/meta/CMakeLists.txt b/core/meta/CMakeLists.txt index ccfa6bad2..dab870c07 100644 --- a/core/meta/CMakeLists.txt +++ b/core/meta/CMakeLists.txt @@ -1,13 +1,15 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/astNode.h - ${CMAKE_CURRENT_LIST_DIR}/packedDerivative.h - ${CMAKE_CURRENT_LIST_DIR}/floatJIT.h - ${CMAKE_CURRENT_LIST_DIR}/astOptimize.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/astNode.cpp - ${CMAKE_CURRENT_LIST_DIR}/packedDerivative.cpp - ${CMAKE_CURRENT_LIST_DIR}/floatJIT.cpp - ${CMAKE_CURRENT_LIST_DIR}/astOptimize.cpp -) +set(META_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/astNode.h + ${CMAKE_CURRENT_LIST_DIR}/packedDerivative.h + ${CMAKE_CURRENT_LIST_DIR}/floatJIT.h + ${CMAKE_CURRENT_LIST_DIR}/astOptimize.h + PARENT_SCOPE + ) +set(META_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/astNode.cpp + ${CMAKE_CURRENT_LIST_DIR}/packedDerivative.cpp + ${CMAKE_CURRENT_LIST_DIR}/floatJIT.cpp + ${CMAKE_CURRENT_LIST_DIR}/astOptimize.cpp + PARENT_SCOPE + ) diff --git a/core/meta/astNode.cpp b/core/meta/astNode.cpp index 2c92641c7..31b74679d 100644 --- a/core/meta/astNode.cpp +++ b/core/meta/astNode.cpp @@ -3,7 +3,7 @@ #include -#include "core/meta/astNode.h" +#include "meta/astNode.h" namespace corecvs { diff --git a/core/meta/astNode.h b/core/meta/astNode.h index 8750f13c8..329d57c40 100644 --- a/core/meta/astNode.h +++ b/core/meta/astNode.h @@ -7,7 +7,7 @@ * * \ingroup cppcorefiles */ -#include "core/utils/global.h" +#include "utils/global.h" #include #include diff --git a/core/meta/astOptimize.cpp b/core/meta/astOptimize.cpp index fa945185a..1b97ff85b 100644 --- a/core/meta/astOptimize.cpp +++ b/core/meta/astOptimize.cpp @@ -1,4 +1,4 @@ -#include "core/meta/astOptimize.h" +#include "meta/astOptimize.h" AstOptimize::AstOptimize() { diff --git a/core/meta/floatJIT.cpp b/core/meta/floatJIT.cpp index d9e4c1135..984a53121 100644 --- a/core/meta/floatJIT.cpp +++ b/core/meta/floatJIT.cpp @@ -1,4 +1,4 @@ -#include "core/meta/floatJIT.h" +#include "meta/floatJIT.h" namespace corecvs { diff --git a/core/meta/floatJIT.h b/core/meta/floatJIT.h index 6c90015c7..968d7e5cf 100644 --- a/core/meta/floatJIT.h +++ b/core/meta/floatJIT.h @@ -1,7 +1,7 @@ #ifndef FLOATJIT_H #define FLOATJIT_H -#include "core/meta/astNode.h" +#include "meta/astNode.h" namespace corecvs { diff --git a/core/meta/packedDerivative.cpp b/core/meta/packedDerivative.cpp index cc43a606e..92a4a7217 100644 --- a/core/meta/packedDerivative.cpp +++ b/core/meta/packedDerivative.cpp @@ -1,4 +1,4 @@ -#include "core/meta/packedDerivative.h" +#include "meta/packedDerivative.h" namespace corecvs { diff --git a/core/patterndetection/CMakeLists.txt b/core/patterndetection/CMakeLists.txt index 489cad0f3..c0f334ecd 100644 --- a/core/patterndetection/CMakeLists.txt +++ b/core/patterndetection/CMakeLists.txt @@ -1,17 +1,17 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/patternDetector.h - ${CMAKE_CURRENT_LIST_DIR}/circlePatternGenerator.h - ${CMAKE_CURRENT_LIST_DIR}/boardAligner.h - ${CMAKE_CURRENT_LIST_DIR}/dummyPatternDetector.h - ${CMAKE_CURRENT_LIST_DIR}/harrisPatternDetector.h +set(PATTERNDETECTION_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/patternDetector.h + ${CMAKE_CURRENT_LIST_DIR}/circlePatternGenerator.h + ${CMAKE_CURRENT_LIST_DIR}/boardAligner.h + ${CMAKE_CURRENT_LIST_DIR}/dummyPatternDetector.h + ${CMAKE_CURRENT_LIST_DIR}/harrisPatternDetector.h + PARENT_SCOPE + ) - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/circlePatternGenerator.cpp - ${CMAKE_CURRENT_LIST_DIR}/boardAligner.cpp - ${CMAKE_CURRENT_LIST_DIR}/patternDetector.cpp - ${CMAKE_CURRENT_LIST_DIR}/dummyPatternDetector.cpp - ${CMAKE_CURRENT_LIST_DIR}/harrisPatternDetector.cpp - -) +set(PATTERNDETECTION_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/circlePatternGenerator.cpp + ${CMAKE_CURRENT_LIST_DIR}/boardAligner.cpp + ${CMAKE_CURRENT_LIST_DIR}/patternDetector.cpp + ${CMAKE_CURRENT_LIST_DIR}/dummyPatternDetector.cpp + ${CMAKE_CURRENT_LIST_DIR}/harrisPatternDetector.cpp + PARENT_SCOPE + ) diff --git a/core/patterndetection/boardAligner.cpp b/core/patterndetection/boardAligner.cpp index db7ed1f56..bd19c3170 100644 --- a/core/patterndetection/boardAligner.cpp +++ b/core/patterndetection/boardAligner.cpp @@ -1,8 +1,8 @@ -#include "core/patterndetection/boardAligner.h" +#include "patterndetection/boardAligner.h" -#include "core/buffers/rgb24/abstractPainter.h" -#include "core/math/matrix/homographyReconstructor.h" -#include "core/geometry/renderer/simpleRenderer.h" +#include "buffers/rgb24/abstractPainter.h" +#include "math/matrix/homographyReconstructor.h" +#include "geometry/renderer/simpleRenderer.h" using corecvs::RGBColor; using corecvs::Matrix33; diff --git a/core/patterndetection/boardAligner.h b/core/patterndetection/boardAligner.h index 7370546b1..0a2474bd1 100644 --- a/core/patterndetection/boardAligner.h +++ b/core/patterndetection/boardAligner.h @@ -4,10 +4,10 @@ #include #include -#include "core/math/vector/vector2d.h" -#include "core/patterndetection/circlePatternGenerator.h" -#include "core/alignment/selectableGeometryFeatures.h" -#include "core/utils/typesafeBitmaskEnums.h" +#include "math/vector/vector2d.h" +#include "patterndetection/circlePatternGenerator.h" +#include "alignment/selectableGeometryFeatures.h" +#include "utils/typesafeBitmaskEnums.h" using std::vector; using corecvs::Vector2dd; diff --git a/core/patterndetection/circlePatternGenerator.cpp b/core/patterndetection/circlePatternGenerator.cpp index 32e92ea10..a667257d8 100644 --- a/core/patterndetection/circlePatternGenerator.cpp +++ b/core/patterndetection/circlePatternGenerator.cpp @@ -1,6 +1,6 @@ -#include "core/patterndetection/circlePatternGenerator.h" -#include "core/math/matrix/homographyReconstructor.h" -#include "core/math/mathUtils.h" +#include "patterndetection/circlePatternGenerator.h" +#include "math/matrix/homographyReconstructor.h" +#include "math/mathUtils.h" using corecvs::Vector3dd; using corecvs::Vector2dd; diff --git a/core/patterndetection/circlePatternGenerator.h b/core/patterndetection/circlePatternGenerator.h index b693c13cb..885d1b88c 100644 --- a/core/patterndetection/circlePatternGenerator.h +++ b/core/patterndetection/circlePatternGenerator.h @@ -6,10 +6,10 @@ #include #include -#include "core/buffers/abstractBuffer.h" -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix33.h" -#include "core/buffers/float/dpImage.h" +#include "buffers/abstractBuffer.h" +#include "math/vector/vector2d.h" +#include "math/matrix/matrix33.h" +#include "buffers/float/dpImage.h" #ifdef WITH_TBB #include diff --git a/core/patterndetection/dummyPatternDetector.h b/core/patterndetection/dummyPatternDetector.h index d9fec9547..2dc097c05 100644 --- a/core/patterndetection/dummyPatternDetector.h +++ b/core/patterndetection/dummyPatternDetector.h @@ -1,7 +1,7 @@ #ifndef DUMMYPATTERNDETECTOR_H #define DUMMYPATTERNDETECTOR_H -#include "core/patterndetection/patternDetector.h" +#include "patterndetection/patternDetector.h" namespace corecvs { diff --git a/core/patterndetection/harrisPatternDetector.h b/core/patterndetection/harrisPatternDetector.h index 45a3aea00..3c068de1d 100644 --- a/core/patterndetection/harrisPatternDetector.h +++ b/core/patterndetection/harrisPatternDetector.h @@ -1,9 +1,9 @@ #ifndef HARRISPATTERNDETECTOR_H #define HARRISPATTERNDETECTOR_H -#include "core/patterndetection/patternDetector.h" +#include "patterndetection/patternDetector.h" -#include "core/xml/generated/harrisDetectionParameters.h" +#include "xml/generated/harrisDetectionParameters.h" namespace corecvs { diff --git a/core/patterndetection/patternDetector.cpp b/core/patterndetection/patternDetector.cpp index 0c343d2af..0cea56fdb 100644 --- a/core/patterndetection/patternDetector.cpp +++ b/core/patterndetection/patternDetector.cpp @@ -1,4 +1,4 @@ -#include "core/patterndetection/patternDetector.h" +#include "patterndetection/patternDetector.h" namespace corecvs { diff --git a/core/patterndetection/patternDetector.h b/core/patterndetection/patternDetector.h index 9d95f3c1f..5ddafd83c 100644 --- a/core/patterndetection/patternDetector.h +++ b/core/patterndetection/patternDetector.h @@ -1,19 +1,19 @@ #ifndef PATTERNDETECTOR #define PATTERNDETECTOR -#include "core/stats/calculationStats.h" -#include "core/utils/global.h" +#include "stats/calculationStats.h" +#include "utils/global.h" -#include "core/alignment/selectableGeometryFeatures.h" -#include "core/buffers/g8Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "alignment/selectableGeometryFeatures.h" +#include "buffers/g8Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" -#include "core/filters/newstyle/newStyleBlock.h" -#include "core/utils/debuggableBlock.h" -#include "core/reflection/dynamicObject.h" +#include "filters/newstyle/newStyleBlock.h" +#include "utils/debuggableBlock.h" +#include "reflection/dynamicObject.h" -#include "core/xml/generated/patternDetectorResultBase.h" +#include "xml/generated/patternDetectorResultBase.h" namespace corecvs { diff --git a/core/polynomial/CMakeLists.txt b/core/polynomial/CMakeLists.txt index 1547d9c5e..3779e536a 100644 --- a/core/polynomial/CMakeLists.txt +++ b/core/polynomial/CMakeLists.txt @@ -1,12 +1,15 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/polynomialSolver.h - ${CMAKE_CURRENT_LIST_DIR}/polynomial.h - ${CMAKE_CURRENT_LIST_DIR}/basis.h - ${CMAKE_CURRENT_LIST_DIR}/monom.h - ${CMAKE_CURRENT_LIST_DIR}/polynom.h - ${CMAKE_CURRENT_LIST_DIR}/finiteField.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/polynomialSolver.cpp - ${CMAKE_CURRENT_LIST_DIR}/polynomial.cpp -) +set(POLYNOMIAL_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/polynomialSolver.h + ${CMAKE_CURRENT_LIST_DIR}/polynomial.h + ${CMAKE_CURRENT_LIST_DIR}/basis.h + ${CMAKE_CURRENT_LIST_DIR}/monom.h + ${CMAKE_CURRENT_LIST_DIR}/polynom.h + ${CMAKE_CURRENT_LIST_DIR}/finiteField.h + PARENT_SCOPE + ) + +set(POLYNOMIAL_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/polynomialSolver.cpp + ${CMAKE_CURRENT_LIST_DIR}/polynomial.cpp + PARENT_SCOPE + ) diff --git a/core/polynomial/polynomial.cpp b/core/polynomial/polynomial.cpp index 67b6c710e..65cb2836d 100644 --- a/core/polynomial/polynomial.cpp +++ b/core/polynomial/polynomial.cpp @@ -1,4 +1,4 @@ -#include "core/polynomial/polynomial.h" +#include "polynomial/polynomial.h" #include diff --git a/core/polynomial/polynomial.h b/core/polynomial/polynomial.h index 7d86b992a..6c30ee78b 100644 --- a/core/polynomial/polynomial.h +++ b/core/polynomial/polynomial.h @@ -3,11 +3,11 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector.h" -#include "core/buffers/abstractBuffer.h" -#include "core/math/matrix/matrix.h" +#include "math/vector/vector.h" +#include "buffers/abstractBuffer.h" +#include "math/matrix/matrix.h" /* Including this header to source files together with opencv dues to a compilation error like this: ...\opencv\2411\sources\modules\core\include\opencv2/core/core.hpp(3211): error C2891: fixed_size: cannot take the address of a template parameter diff --git a/core/polynomial/polynomialSolver.cpp b/core/polynomial/polynomialSolver.cpp index 7fb8c8374..57c92ae42 100644 --- a/core/polynomial/polynomialSolver.cpp +++ b/core/polynomial/polynomialSolver.cpp @@ -1,6 +1,6 @@ -#include "core/polynomial/polynomialSolver.h" -#include "core/math/matrix/matrix.h" -#include "core/math/vector/vector.h" +#include "polynomial/polynomialSolver.h" +#include "math/matrix/matrix.h" +#include "math/vector/vector.h" #include "wrappers/cblasLapack/cblasLapackeWrapper.h" const double corecvs::PolynomialSolver::RELATIVE_TOLERANCE = 1e-9; diff --git a/core/polynomial/polynomialSolver.h b/core/polynomial/polynomialSolver.h index c0a5dfdd1..9d579b946 100644 --- a/core/polynomial/polynomialSolver.h +++ b/core/polynomial/polynomialSolver.h @@ -1,9 +1,9 @@ #ifndef POLYNOMIALSOLVER_H #define POLYNOMIALSOLVER_H -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/polynomial/polynomial.h" +#include "polynomial/polynomial.h" #define FIEDLER diff --git a/core/rectification/CMakeLists.txt b/core/rectification/CMakeLists.txt index 9bcb99267..c66868978 100644 --- a/core/rectification/CMakeLists.txt +++ b/core/rectification/CMakeLists.txt @@ -1,47 +1,28 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/essentialMatrix.h - ${CMAKE_CURRENT_LIST_DIR}/essentialEstimator.h - ${CMAKE_CURRENT_LIST_DIR}/iterativeEstimator.h - ${CMAKE_CURRENT_LIST_DIR}/ransacEstimator.h - ${CMAKE_CURRENT_LIST_DIR}/stereoAligner.h - ${CMAKE_CURRENT_LIST_DIR}/triangulator.h - ${CMAKE_CURRENT_LIST_DIR}/ransac.h - # ${CMAKE_CURRENT_LIST_DIR}/multicameraEstimator.h - ${CMAKE_CURRENT_LIST_DIR}/multicameraTriangulator.h - ${CMAKE_CURRENT_LIST_DIR}/sceneStereoAlignerBlock.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/essentialMatrix.cpp - ${CMAKE_CURRENT_LIST_DIR}/essentialEstimator.cpp - ${CMAKE_CURRENT_LIST_DIR}/iterativeEstimator.cpp - ${CMAKE_CURRENT_LIST_DIR}/ransacEstimator.cpp - ${CMAKE_CURRENT_LIST_DIR}/stereoAligner.cpp - ${CMAKE_CURRENT_LIST_DIR}/triangulator.cpp - # ${CMAKE_CURRENT_LIST_DIR}/multicameraEstimator.cpp - ${CMAKE_CURRENT_LIST_DIR}/multicameraTriangulator.cpp - ${CMAKE_CURRENT_LIST_DIR}/sceneStereoAlignerBlock.cpp - - ${CMAKE_CURRENT_LIST_DIR}/../xml/generated/essentialDerivative1.cpp - ${CMAKE_CURRENT_LIST_DIR}/../xml/generated/essentialDerivative2.cpp - ) - - - -#SOURCES_NOOPTIMIZE += xml/generated/essentialDerivative.cpp - -#with_fastbuild:!win32 { - -# message("Rectification module would use fastbuild") -# nooptimize.name = nooptimize -# nooptimize.input = SOURCES_NOOPTIMIZE -# nooptimize.dependency_type = TYPE_C -# nooptimize.variable_out = OBJECTS -# nooptimize.output = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}$${first(QMAKE_EXT_OBJ)} -# nooptimize.commands = $${QMAKE_CXX} $(CXXFLAGS) -O0 $(INCPATH) -c ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT} # Note the -O0 -# QMAKE_EXTRA_COMPILERS += nooptimize - -#} else { -# $$SOURCES_NOOPTIMIZE -#} - - +set(RECTIFICATION_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/essentialMatrix.h + ${CMAKE_CURRENT_LIST_DIR}/essentialEstimator.h + ${CMAKE_CURRENT_LIST_DIR}/iterativeEstimator.h + ${CMAKE_CURRENT_LIST_DIR}/ransacEstimator.h + ${CMAKE_CURRENT_LIST_DIR}/stereoAligner.h + ${CMAKE_CURRENT_LIST_DIR}/triangulator.h + ${CMAKE_CURRENT_LIST_DIR}/ransac.h +# ${CMAKE_CURRENT_LIST_DIR}/multicameraEstimator.h + ${CMAKE_CURRENT_LIST_DIR}/multicameraTriangulator.h + ${CMAKE_CURRENT_LIST_DIR}/sceneStereoAlignerBlock.h + PARENT_SCOPE + ) + +set(RECTIFICATION_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/essentialMatrix.cpp + ${CMAKE_CURRENT_LIST_DIR}/essentialEstimator.cpp + ${CMAKE_CURRENT_LIST_DIR}/iterativeEstimator.cpp + ${CMAKE_CURRENT_LIST_DIR}/ransacEstimator.cpp + ${CMAKE_CURRENT_LIST_DIR}/stereoAligner.cpp + ${CMAKE_CURRENT_LIST_DIR}/triangulator.cpp +# ${CMAKE_CURRENT_LIST_DIR}/multicameraEstimator.cpp + ${CMAKE_CURRENT_LIST_DIR}/multicameraTriangulator.cpp + ${CMAKE_CURRENT_LIST_DIR}/sceneStereoAlignerBlock.cpp + ${CMAKE_CURRENT_LIST_DIR}/../xml/generated/essentialDerivative1.cpp + ${CMAKE_CURRENT_LIST_DIR}/../xml/generated/essentialDerivative2.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/core/rectification/essentialEstimator.cpp b/core/rectification/essentialEstimator.cpp index 4ee643ac9..7da38bf82 100644 --- a/core/rectification/essentialEstimator.cpp +++ b/core/rectification/essentialEstimator.cpp @@ -7,15 +7,15 @@ */ -#include "core/rectification/essentialEstimator.h" -#include "core/math/quaternion.h" -#include "core/math/levenmarq.h" -#include "core/math/gradientDescent.h" -#include "core/kalman/classicKalman.h" -#include "core/polynomial/polynomialSolver.h" -#include "core/math/matrix/matrixOperations.h" -#include "core/meta/packedDerivative.h" -#include "core/meta/astNode.h" +#include "rectification/essentialEstimator.h" +#include "math/quaternion.h" +#include "math/levenmarq.h" +#include "math/gradientDescent.h" +#include "kalman/classicKalman.h" +#include "polynomial/polynomialSolver.h" +#include "math/matrix/matrixOperations.h" +#include "meta/packedDerivative.h" +#include "meta/astNode.h" //#include "kalman.h" @@ -378,10 +378,10 @@ std::vector EssentialEstimator::getEssential5point(const vector const double w12 = w1 * w1, w22 = w2 * w2, w32 = w3 * w3, w42 = w4 * w4, w52 = w5 * w5, w62 = w6 * w6, w72 = w7 * w7, w82 = w8 * w8, w92 = w9 * w9; corecvs::Matrix A(10, 10); -#include "core/rectification/p5pNumericPart.h" +#include "rectification/p5pNumericPart.h" // Now we fill polynomial part of matrix corecvs::PolynomialMatrix B(10, 3); -#include "core/rectification/p5pPolynomialPart.h" +#include "rectification/p5pPolynomialPart.h" A = A.inv(); diff --git a/core/rectification/essentialEstimator.h b/core/rectification/essentialEstimator.h index 7313d2204..0be52bbda 100644 --- a/core/rectification/essentialEstimator.h +++ b/core/rectification/essentialEstimator.h @@ -9,13 +9,13 @@ */ #include -#include "core/buffers/correspondenceList.h" -#include "core/rectification/essentialMatrix.h" -#include "core/function/function.h" -#include "core/math/quaternion.h" +#include "buffers/correspondenceList.h" +#include "rectification/essentialMatrix.h" +#include "function/function.h" +#include "math/quaternion.h" -#include "core/meta/astNode.h" -#include "core/math/matrix/matrixOperations.h" +#include "meta/astNode.h" +#include "math/matrix/matrixOperations.h" namespace corecvs { diff --git a/core/rectification/essentialMatrix.cpp b/core/rectification/essentialMatrix.cpp index 6ceb8a1b7..e924e45b6 100644 --- a/core/rectification/essentialMatrix.cpp +++ b/core/rectification/essentialMatrix.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/rectification/essentialMatrix.h" +#include "rectification/essentialMatrix.h" namespace corecvs { diff --git a/core/rectification/essentialMatrix.h b/core/rectification/essentialMatrix.h index 35cd5c1a0..d6ee8efdb 100644 --- a/core/rectification/essentialMatrix.h +++ b/core/rectification/essentialMatrix.h @@ -6,13 +6,13 @@ * \date Oct 1, 2011 * \author alexander */ -#include "core/math/matrix/matrix33.h" -#include "core/math/vector/vector3d.h" -#include "core/math/matrix/matrix.h" -#include "core/math/quaternion.h" -#include "core/geometry/line.h" -#include "core/buffers/correspondenceList.h" -#include "core/math/affine.h" +#include "math/matrix/matrix33.h" +#include "math/vector/vector3d.h" +#include "math/matrix/matrix.h" +#include "math/quaternion.h" +#include "geometry/line.h" +#include "buffers/correspondenceList.h" +#include "math/affine.h" namespace corecvs { diff --git a/core/rectification/iterativeEstimator.cpp b/core/rectification/iterativeEstimator.cpp index 7e52981b6..acd0f83f2 100644 --- a/core/rectification/iterativeEstimator.cpp +++ b/core/rectification/iterativeEstimator.cpp @@ -6,10 +6,10 @@ * \author alexander */ -#include "core/utils/global.h" -#include "core/utils/log.h" +#include "utils/global.h" +#include "utils/log.h" -#include "core/rectification/iterativeEstimator.h" +#include "rectification/iterativeEstimator.h" namespace corecvs { diff --git a/core/rectification/iterativeEstimator.h b/core/rectification/iterativeEstimator.h index 5bf752a71..4268b490f 100644 --- a/core/rectification/iterativeEstimator.h +++ b/core/rectification/iterativeEstimator.h @@ -8,10 +8,10 @@ * \author alexander */ -#include "core/rectification/essentialEstimator.h" -#include "core/xml/generated/iterativeEstimateParameters.h" +#include "rectification/essentialEstimator.h" +#include "xml/generated/iterativeEstimateParameters.h" -#include "core/camerafixture/fixtureScene.h" +#include "camerafixture/fixtureScene.h" namespace corecvs { diff --git a/core/rectification/multicameraTriangulator.cpp b/core/rectification/multicameraTriangulator.cpp index 4c05ad5a2..bac12c13d 100644 --- a/core/rectification/multicameraTriangulator.cpp +++ b/core/rectification/multicameraTriangulator.cpp @@ -1,7 +1,7 @@ -#include "core/rectification/multicameraTriangulator.h" -#include "core/geometry/twoViewOptimalTriangulation.h" -#include "core/math/levenmarq.h" -#include "core/geometry/ellipticalApproximation.h" +#include "rectification/multicameraTriangulator.h" +#include "geometry/twoViewOptimalTriangulation.h" +#include "math/levenmarq.h" +#include "geometry/ellipticalApproximation.h" #include diff --git a/core/rectification/multicameraTriangulator.h b/core/rectification/multicameraTriangulator.h index 1901f1fe1..7316add0e 100644 --- a/core/rectification/multicameraTriangulator.h +++ b/core/rectification/multicameraTriangulator.h @@ -3,12 +3,12 @@ #include -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/math/matrix/matrix.h" -#include "core/math/matrix/matrix33.h" -#include "core/math/matrix/matrix44.h" -#include "core/function/function.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "math/matrix/matrix.h" +#include "math/matrix/matrix33.h" +#include "math/matrix/matrix44.h" +#include "function/function.h" namespace corecvs { diff --git a/core/rectification/ransac.h b/core/rectification/ransac.h index a38ba11b8..b05bb3492 100644 --- a/core/rectification/ransac.h +++ b/core/rectification/ransac.h @@ -12,10 +12,10 @@ #include #include -#include "core/tbbwrapper/tbbWrapper.h" +#include "tbbwrapper/tbbWrapper.h" -#include "core/utils/global.h" -#include "core/xml/generated/ransacParameters.h" +#include "utils/global.h" +#include "xml/generated/ransacParameters.h" #ifdef WITH_TBB #include diff --git a/core/rectification/ransacEstimator.cpp b/core/rectification/ransacEstimator.cpp index 9c6eccaa3..70bbc8adb 100644 --- a/core/rectification/ransacEstimator.cpp +++ b/core/rectification/ransacEstimator.cpp @@ -8,13 +8,13 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/rectification/ransacEstimator.h" -#include "core/rectification/essentialMatrix.h" -#include "core/rectification/essentialEstimator.h" -#include "core/rectification/ransac.h" -#include "core/buffers/correspondenceList.h" +#include "rectification/ransacEstimator.h" +#include "rectification/essentialMatrix.h" +#include "rectification/essentialEstimator.h" +#include "rectification/ransac.h" +#include "buffers/correspondenceList.h" namespace corecvs { diff --git a/core/rectification/ransacEstimator.h b/core/rectification/ransacEstimator.h index 7e146256b..5d7e38d06 100644 --- a/core/rectification/ransacEstimator.h +++ b/core/rectification/ransacEstimator.h @@ -10,10 +10,10 @@ #include -#include "core/math/matrix/matrix33.h" -#include "core/buffers/correspondenceList.h" -#include "core/rectification/ransac.h" -#include "core/camerafixture/fixtureScene.h" +#include "math/matrix/matrix33.h" +#include "buffers/correspondenceList.h" +#include "rectification/ransac.h" +#include "camerafixture/fixtureScene.h" namespace corecvs { diff --git a/core/rectification/rectificationDoc.h b/core/rectification/rectificationDoc.h index acb577b8f..a72de0d84 100644 --- a/core/rectification/rectificationDoc.h +++ b/core/rectification/rectificationDoc.h @@ -1,4 +1,4 @@ -#include "core/rectification/stereoAligner.h" +#include "rectification/stereoAligner.h" /** \page pRectification Rectification documentation page \section Introduction diff --git a/core/rectification/sceneStereoAlignerBlock.cpp b/core/rectification/sceneStereoAlignerBlock.cpp index 81fb367e1..27e4561dc 100644 --- a/core/rectification/sceneStereoAlignerBlock.cpp +++ b/core/rectification/sceneStereoAlignerBlock.cpp @@ -1,9 +1,9 @@ -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/camerafixture/fixtureScene.h" -#include "core/camerafixture/cameraFixture.h" -#include "core/math/affine.h" -#include "core/rectification/sceneStereoAlignerBlock.h" -#include "core/rectification/stereoAligner.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "camerafixture/fixtureScene.h" +#include "camerafixture/cameraFixture.h" +#include "math/affine.h" +#include "rectification/sceneStereoAlignerBlock.h" +#include "rectification/stereoAligner.h" namespace corecvs { diff --git a/core/rectification/sceneStereoAlignerBlock.h b/core/rectification/sceneStereoAlignerBlock.h index 3c496dd8b..bdd2f609f 100644 --- a/core/rectification/sceneStereoAlignerBlock.h +++ b/core/rectification/sceneStereoAlignerBlock.h @@ -1,10 +1,10 @@ #ifndef SCENE_STEREO_ALIGNER_BLOCK_H #define SCENE_STEREO_ALIGNER_BLOCK_H -#include "core/filters/newstyle/newStyleBlock.h" -#include "core/xml/generated/sceneStereoAlignerBlockBase.h" +#include "filters/newstyle/newStyleBlock.h" +#include "xml/generated/sceneStereoAlignerBlockBase.h" -#include "core/camerafixture/fixtureCamera.h" +#include "camerafixture/fixtureCamera.h" namespace corecvs { diff --git a/core/rectification/stereoAligner.cpp b/core/rectification/stereoAligner.cpp index 0203e073d..96442e140 100644 --- a/core/rectification/stereoAligner.cpp +++ b/core/rectification/stereoAligner.cpp @@ -12,15 +12,15 @@ #include -#include "core/utils/global.h" - -#include "core/math/mathUtils.h" -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix.h" -#include "core/rectification/stereoAligner.h" -#include "core/rectification/ransac.h" -#include "core/geometry/line.h" -#include "core/rectification/essentialMatrix.h" +#include "utils/global.h" + +#include "math/mathUtils.h" +#include "math/vector/vector2d.h" +#include "math/matrix/matrix.h" +#include "rectification/stereoAligner.h" +#include "rectification/ransac.h" +#include "geometry/line.h" +#include "rectification/essentialMatrix.h" namespace corecvs { #if 0 diff --git a/core/rectification/stereoAligner.h b/core/rectification/stereoAligner.h index 3a709f2f1..e1f54dff9 100644 --- a/core/rectification/stereoAligner.h +++ b/core/rectification/stereoAligner.h @@ -11,9 +11,9 @@ */ -#include "core/math/projectiveTransform.h" -#include "core/buffers/correspondenceList.h" -#include "core/math/matrix/matrix33.h" +#include "math/projectiveTransform.h" +#include "buffers/correspondenceList.h" +#include "math/matrix/matrix33.h" namespace corecvs { class StereoTransformation diff --git a/core/rectification/triangulator.cpp b/core/rectification/triangulator.cpp index 705f7d817..43349323d 100644 --- a/core/rectification/triangulator.cpp +++ b/core/rectification/triangulator.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/rectification/triangulator.h" +#include "rectification/triangulator.h" namespace corecvs { diff --git a/core/rectification/triangulator.h b/core/rectification/triangulator.h index dc9614d6b..a151dc154 100644 --- a/core/rectification/triangulator.h +++ b/core/rectification/triangulator.h @@ -11,15 +11,15 @@ #include -#include "core/cammodel/cameraParameters.h" -#include "core/math/matrix/matrix33.h" -#include "core/rectification/essentialMatrix.h" -#include "core/buffers/flow/sixDBuffer.h" -#include "core/math/vector/vector3d.h" -#include "core/buffers/rgb24/rgbColor.h" -#include "core/buffers/flow/depthBuffer.h" -#include "core/clustering3d/cloud.h" -#include "core/tbbwrapper/tbbWrapper.h" +#include "cammodel/cameraParameters.h" +#include "math/matrix/matrix33.h" +#include "rectification/essentialMatrix.h" +#include "buffers/flow/sixDBuffer.h" +#include "math/vector/vector3d.h" +#include "buffers/rgb24/rgbColor.h" +#include "buffers/flow/depthBuffer.h" +#include "clustering3d/cloud.h" +#include "tbbwrapper/tbbWrapper.h" namespace corecvs { using std::vector; diff --git a/core/reflection/CMakeLists.txt b/core/reflection/CMakeLists.txt index f9b510992..a3f463006 100644 --- a/core/reflection/CMakeLists.txt +++ b/core/reflection/CMakeLists.txt @@ -1,38 +1,39 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/stringPrinterVisitor.h - ${CMAKE_CURRENT_LIST_DIR}/reflection.h - ${CMAKE_CURRENT_LIST_DIR}/defaultSetter.h - ${CMAKE_CURRENT_LIST_DIR}/printerVisitor.h - ${CMAKE_CURRENT_LIST_DIR}/usageVisitor.h - ${CMAKE_CURRENT_LIST_DIR}/serializerVisitor.h - ${CMAKE_CURRENT_LIST_DIR}/deserializerVisitor.h - ${CMAKE_CURRENT_LIST_DIR}/commandLineSetter.h - ${CMAKE_CURRENT_LIST_DIR}/extendedVisitor.h - ${CMAKE_CURRENT_LIST_DIR}/commandLineGetter.h - ${CMAKE_CURRENT_LIST_DIR}/jsonPrinter.h - ${CMAKE_CURRENT_LIST_DIR}/binaryReader.h - ${CMAKE_CURRENT_LIST_DIR}/binaryWriter.h - ${CMAKE_CURRENT_LIST_DIR}/dynamicObject.h - ${CMAKE_CURRENT_LIST_DIR}/advanced/advancedBinaryReader.h - ${CMAKE_CURRENT_LIST_DIR}/advanced/advancedBinaryWriter.h +set(REFLECTION_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/stringPrinterVisitor.h + ${CMAKE_CURRENT_LIST_DIR}/reflection.h + ${CMAKE_CURRENT_LIST_DIR}/defaultSetter.h + ${CMAKE_CURRENT_LIST_DIR}/printerVisitor.h + ${CMAKE_CURRENT_LIST_DIR}/usageVisitor.h + ${CMAKE_CURRENT_LIST_DIR}/serializerVisitor.h + ${CMAKE_CURRENT_LIST_DIR}/deserializerVisitor.h + ${CMAKE_CURRENT_LIST_DIR}/commandLineSetter.h + ${CMAKE_CURRENT_LIST_DIR}/extendedVisitor.h + ${CMAKE_CURRENT_LIST_DIR}/commandLineGetter.h + ${CMAKE_CURRENT_LIST_DIR}/jsonPrinter.h + ${CMAKE_CURRENT_LIST_DIR}/binaryReader.h + ${CMAKE_CURRENT_LIST_DIR}/binaryWriter.h + ${CMAKE_CURRENT_LIST_DIR}/dynamicObject.h + ${CMAKE_CURRENT_LIST_DIR}/advanced/advancedBinaryReader.h + ${CMAKE_CURRENT_LIST_DIR}/advanced/advancedBinaryWriter.h + PARENT_SCOPE + ) - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/stringPrinterVisitor.cpp - ${CMAKE_CURRENT_LIST_DIR}/defaultSetter.cpp - ${CMAKE_CURRENT_LIST_DIR}/printerVisitor.cpp - ${CMAKE_CURRENT_LIST_DIR}/usageVisitor.cpp - ${CMAKE_CURRENT_LIST_DIR}/serializerVisitor.cpp - ${CMAKE_CURRENT_LIST_DIR}/deserializerVisitor.cpp - ${CMAKE_CURRENT_LIST_DIR}/commandLineSetter.cpp - ${CMAKE_CURRENT_LIST_DIR}/reflection.cpp - ${CMAKE_CURRENT_LIST_DIR}/extendedVisitor.cpp - ${CMAKE_CURRENT_LIST_DIR}/commandLineGetter.cpp - ${CMAKE_CURRENT_LIST_DIR}/jsonPrinter.cpp - ${CMAKE_CURRENT_LIST_DIR}/binaryReader.cpp - ${CMAKE_CURRENT_LIST_DIR}/binaryWriter.cpp - ${CMAKE_CURRENT_LIST_DIR}/dynamicObject.cpp - ${CMAKE_CURRENT_LIST_DIR}/advanced/advancedBinaryReader.cpp - ${CMAKE_CURRENT_LIST_DIR}/advanced/advancedBinaryWriter.cpp - -) +set(REFLECTION_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/stringPrinterVisitor.cpp + ${CMAKE_CURRENT_LIST_DIR}/defaultSetter.cpp + ${CMAKE_CURRENT_LIST_DIR}/printerVisitor.cpp + ${CMAKE_CURRENT_LIST_DIR}/usageVisitor.cpp + ${CMAKE_CURRENT_LIST_DIR}/serializerVisitor.cpp + ${CMAKE_CURRENT_LIST_DIR}/deserializerVisitor.cpp + ${CMAKE_CURRENT_LIST_DIR}/commandLineSetter.cpp + ${CMAKE_CURRENT_LIST_DIR}/reflection.cpp + ${CMAKE_CURRENT_LIST_DIR}/extendedVisitor.cpp + ${CMAKE_CURRENT_LIST_DIR}/commandLineGetter.cpp + ${CMAKE_CURRENT_LIST_DIR}/jsonPrinter.cpp + ${CMAKE_CURRENT_LIST_DIR}/binaryReader.cpp + ${CMAKE_CURRENT_LIST_DIR}/binaryWriter.cpp + ${CMAKE_CURRENT_LIST_DIR}/dynamicObject.cpp + ${CMAKE_CURRENT_LIST_DIR}/advanced/advancedBinaryReader.cpp + ${CMAKE_CURRENT_LIST_DIR}/advanced/advancedBinaryWriter.cpp + PARENT_SCOPE + ) diff --git a/core/reflection/advanced/advancedBinaryReader.cpp b/core/reflection/advanced/advancedBinaryReader.cpp index e4a6bebb8..cc1f66d1f 100644 --- a/core/reflection/advanced/advancedBinaryReader.cpp +++ b/core/reflection/advanced/advancedBinaryReader.cpp @@ -1,5 +1,5 @@ -#include "core/reflection/advanced/advancedBinaryReader.h" -#include "core/utils/utils.h" +#include "reflection/advanced/advancedBinaryReader.h" +#include "utils/utils.h" namespace corecvs { diff --git a/core/reflection/advanced/advancedBinaryReader.h b/core/reflection/advanced/advancedBinaryReader.h index 103c26fd1..5ceb38800 100644 --- a/core/reflection/advanced/advancedBinaryReader.h +++ b/core/reflection/advanced/advancedBinaryReader.h @@ -7,10 +7,10 @@ #include #include -#include "core/reflection/reflection.h" -#include "core/utils/log.h" +#include "reflection/reflection.h" +#include "utils/log.h" -#include "core/reflection/advanced/advancedBinaryWriter.h" +#include "reflection/advanced/advancedBinaryWriter.h" namespace corecvs { diff --git a/core/reflection/advanced/advancedBinaryWriter.cpp b/core/reflection/advanced/advancedBinaryWriter.cpp index dfba71750..fda354edd 100644 --- a/core/reflection/advanced/advancedBinaryWriter.cpp +++ b/core/reflection/advanced/advancedBinaryWriter.cpp @@ -1,5 +1,5 @@ -#include "core/reflection/advanced/advancedBinaryWriter.h" -#include "core/utils/utils.h" +#include "reflection/advanced/advancedBinaryWriter.h" +#include "utils/utils.h" namespace corecvs { diff --git a/core/reflection/advanced/advancedBinaryWriter.h b/core/reflection/advanced/advancedBinaryWriter.h index 7b497ef07..206703a1e 100644 --- a/core/reflection/advanced/advancedBinaryWriter.h +++ b/core/reflection/advanced/advancedBinaryWriter.h @@ -7,8 +7,8 @@ #include #include -#include "core/reflection/reflection.h" -#include "core/utils/log.h" +#include "reflection/reflection.h" +#include "utils/log.h" namespace corecvs { diff --git a/core/reflection/binaryReader.cpp b/core/reflection/binaryReader.cpp index 0b8555d98..6958f48c8 100644 --- a/core/reflection/binaryReader.cpp +++ b/core/reflection/binaryReader.cpp @@ -1,5 +1,5 @@ -#include "core/reflection/binaryReader.h" -#include "core/utils/utils.h" +#include "reflection/binaryReader.h" +#include "utils/utils.h" namespace corecvs { diff --git a/core/reflection/binaryReader.h b/core/reflection/binaryReader.h index baf3fd330..9127580f1 100644 --- a/core/reflection/binaryReader.h +++ b/core/reflection/binaryReader.h @@ -7,10 +7,10 @@ #include #include -#include "core/reflection/reflection.h" -#include "core/utils/log.h" +#include "reflection/reflection.h" +#include "utils/log.h" -#include "core/reflection/binaryWriter.h" +#include "reflection/binaryWriter.h" namespace corecvs { diff --git a/core/reflection/binaryWriter.cpp b/core/reflection/binaryWriter.cpp index e1730070b..c82d55948 100644 --- a/core/reflection/binaryWriter.cpp +++ b/core/reflection/binaryWriter.cpp @@ -1,5 +1,5 @@ -#include "core/reflection/binaryWriter.h" -#include "core/utils/utils.h" +#include "reflection/binaryWriter.h" +#include "utils/utils.h" namespace corecvs { diff --git a/core/reflection/binaryWriter.h b/core/reflection/binaryWriter.h index 3e3372224..041b33257 100644 --- a/core/reflection/binaryWriter.h +++ b/core/reflection/binaryWriter.h @@ -7,8 +7,8 @@ #include #include -#include "core/reflection/reflection.h" -#include "core/utils/log.h" +#include "reflection/reflection.h" +#include "utils/log.h" namespace corecvs { diff --git a/core/reflection/commandLineGetter.cpp b/core/reflection/commandLineGetter.cpp index ef55b6826..15982aa25 100644 --- a/core/reflection/commandLineGetter.cpp +++ b/core/reflection/commandLineGetter.cpp @@ -1,4 +1,4 @@ -#include "core/reflection/commandLineGetter.h" +#include "reflection/commandLineGetter.h" namespace corecvs { diff --git a/core/reflection/commandLineGetter.h b/core/reflection/commandLineGetter.h index 545300002..a79851a85 100644 --- a/core/reflection/commandLineGetter.h +++ b/core/reflection/commandLineGetter.h @@ -4,8 +4,8 @@ #include #include #include -#include "core/utils/visitors/basePathVisitor.h" -#include "core/reflection/reflection.h" +#include "utils/visitors/basePathVisitor.h" +#include "reflection/reflection.h" namespace corecvs { diff --git a/core/reflection/commandLineSetter.cpp b/core/reflection/commandLineSetter.cpp index 7b184b2c8..20184e0da 100644 --- a/core/reflection/commandLineSetter.cpp +++ b/core/reflection/commandLineSetter.cpp @@ -1,4 +1,4 @@ -#include "core/reflection/commandLineSetter.h" +#include "reflection/commandLineSetter.h" namespace corecvs { diff --git a/core/reflection/commandLineSetter.h b/core/reflection/commandLineSetter.h index 0c26f2a09..a21fee853 100644 --- a/core/reflection/commandLineSetter.h +++ b/core/reflection/commandLineSetter.h @@ -6,11 +6,11 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/utils/visitors/basePathVisitor.h" -#include "core/reflection/reflection.h" -#include "core/reflection/dynamicObject.h" +#include "utils/visitors/basePathVisitor.h" +#include "reflection/reflection.h" +#include "reflection/dynamicObject.h" namespace corecvs { diff --git a/core/reflection/defaultSetter.cpp b/core/reflection/defaultSetter.cpp index 0c3c32a5e..43c94b554 100644 --- a/core/reflection/defaultSetter.cpp +++ b/core/reflection/defaultSetter.cpp @@ -1,4 +1,4 @@ -#include "core/reflection/defaultSetter.h" +#include "reflection/defaultSetter.h" namespace corecvs { diff --git a/core/reflection/defaultSetter.h b/core/reflection/defaultSetter.h index fae7f0639..313381aad 100644 --- a/core/reflection/defaultSetter.h +++ b/core/reflection/defaultSetter.h @@ -3,9 +3,9 @@ #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/reflection/reflection.h" +#include "reflection/reflection.h" namespace corecvs { diff --git a/core/reflection/deserializerVisitor.cpp b/core/reflection/deserializerVisitor.cpp index 834330299..878d73e13 100644 --- a/core/reflection/deserializerVisitor.cpp +++ b/core/reflection/deserializerVisitor.cpp @@ -1,4 +1,4 @@ -#include "core/reflection/deserializerVisitor.h" +#include "reflection/deserializerVisitor.h" #include namespace corecvs { diff --git a/core/reflection/deserializerVisitor.h b/core/reflection/deserializerVisitor.h index c33d67256..4be0fb115 100644 --- a/core/reflection/deserializerVisitor.h +++ b/core/reflection/deserializerVisitor.h @@ -1,8 +1,8 @@ #ifndef DESERIALIZERVISITOR_H #define DESERIALIZERVISITOR_H -#include "core/reflection/reflection.h" -#include "core/tinyxml2/tinyxml2.h" +#include "reflection/reflection.h" +#include "tinyxml2/tinyxml2.h" namespace corecvs { diff --git a/core/reflection/dynamicObject.cpp b/core/reflection/dynamicObject.cpp index 63a106608..ac8a42c60 100644 --- a/core/reflection/dynamicObject.cpp +++ b/core/reflection/dynamicObject.cpp @@ -1,4 +1,4 @@ -#include "core/reflection/dynamicObject.h" +#include "reflection/dynamicObject.h" namespace corecvs { diff --git a/core/reflection/dynamicObject.h b/core/reflection/dynamicObject.h index 4c326289f..b5e0e59b2 100644 --- a/core/reflection/dynamicObject.h +++ b/core/reflection/dynamicObject.h @@ -1,8 +1,8 @@ #ifndef DYNAMICOBJECT_H #define DYNAMICOBJECT_H -#include "core/reflection/reflection.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/printerVisitor.h" namespace corecvs { diff --git a/core/reflection/extendedVisitor.cpp b/core/reflection/extendedVisitor.cpp index d1226a37e..58706ce49 100644 --- a/core/reflection/extendedVisitor.cpp +++ b/core/reflection/extendedVisitor.cpp @@ -1,7 +1,7 @@ -#include "core/reflection/extendedVisitor.h" -#include "core/reflection/reflection.h" -#include "core/reflection/dynamicObject.h" -#include "core/reflection/defaultSetter.h" +#include "reflection/extendedVisitor.h" +#include "reflection/reflection.h" +#include "reflection/dynamicObject.h" +#include "reflection/defaultSetter.h" namespace corecvs { diff --git a/core/reflection/jsonPrinter.cpp b/core/reflection/jsonPrinter.cpp index f5cbd545a..919a6f9a3 100644 --- a/core/reflection/jsonPrinter.cpp +++ b/core/reflection/jsonPrinter.cpp @@ -1,5 +1,5 @@ -#include "core/reflection/jsonPrinter.h" -#include "core/utils/utils.h" +#include "reflection/jsonPrinter.h" +#include "utils/utils.h" namespace corecvs { diff --git a/core/reflection/jsonPrinter.h b/core/reflection/jsonPrinter.h index 9717496bb..c59fc74bb 100644 --- a/core/reflection/jsonPrinter.h +++ b/core/reflection/jsonPrinter.h @@ -9,8 +9,8 @@ #include #include -#include "core/reflection/reflection.h" -#include "core/utils/log.h" +#include "reflection/reflection.h" +#include "utils/log.h" namespace corecvs { diff --git a/core/reflection/printerVisitor.cpp b/core/reflection/printerVisitor.cpp index 4116ab303..59f1ee691 100644 --- a/core/reflection/printerVisitor.cpp +++ b/core/reflection/printerVisitor.cpp @@ -1,4 +1,4 @@ -#include "core/reflection/printerVisitor.h" +#include "reflection/printerVisitor.h" namespace corecvs { diff --git a/core/reflection/printerVisitor.h b/core/reflection/printerVisitor.h index 91c895df6..b86332311 100644 --- a/core/reflection/printerVisitor.h +++ b/core/reflection/printerVisitor.h @@ -5,7 +5,7 @@ #include #include -#include "core/reflection/reflection.h" +#include "reflection/reflection.h" namespace corecvs { diff --git a/core/reflection/reflection.cpp b/core/reflection/reflection.cpp index 5dcc82fad..f1847971c 100644 --- a/core/reflection/reflection.cpp +++ b/core/reflection/reflection.cpp @@ -1,4 +1,4 @@ -#include "core/reflection/reflection.h" +#include "reflection/reflection.h" namespace corecvs { diff --git a/core/reflection/reflection.h b/core/reflection/reflection.h index 71727a1b3..a704358bc 100644 --- a/core/reflection/reflection.h +++ b/core/reflection/reflection.h @@ -17,10 +17,10 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -//#include "core/math/vector/vector3d.h" -//#include "core/math/vector/vector2d.h" +//#include "math/vector/vector3d.h" +//#include "math/vector/vector2d.h" #undef min #undef max diff --git a/core/reflection/serializerVisitor.cpp b/core/reflection/serializerVisitor.cpp index af837b98a..2b5b7f88d 100644 --- a/core/reflection/serializerVisitor.cpp +++ b/core/reflection/serializerVisitor.cpp @@ -1,4 +1,4 @@ -#include "core/reflection/serializerVisitor.h" +#include "reflection/serializerVisitor.h" #include namespace corecvs { diff --git a/core/reflection/serializerVisitor.h b/core/reflection/serializerVisitor.h index 355e112f1..c638a3202 100644 --- a/core/reflection/serializerVisitor.h +++ b/core/reflection/serializerVisitor.h @@ -1,8 +1,8 @@ #ifndef MYXMLVISITOR_H #define MYXMLVISITOR_H -#include "core/reflection/reflection.h" -#include "core/tinyxml2/tinyxml2.h" +#include "reflection/reflection.h" +#include "tinyxml2/tinyxml2.h" namespace corecvs { diff --git a/core/reflection/stringPrinterVisitor.cpp b/core/reflection/stringPrinterVisitor.cpp index 19beb831d..36d8553b5 100644 --- a/core/reflection/stringPrinterVisitor.cpp +++ b/core/reflection/stringPrinterVisitor.cpp @@ -4,7 +4,7 @@ * \date May 12, 2014 **/ -#include "core/reflection/stringPrinterVisitor.h" +#include "reflection/stringPrinterVisitor.h" namespace corecvs { diff --git a/core/reflection/stringPrinterVisitor.h b/core/reflection/stringPrinterVisitor.h index 6d89f01a3..bf69305c5 100644 --- a/core/reflection/stringPrinterVisitor.h +++ b/core/reflection/stringPrinterVisitor.h @@ -7,7 +7,7 @@ **/ #include -#include "core/reflection/printerVisitor.h" +#include "reflection/printerVisitor.h" namespace corecvs { diff --git a/core/reflection/usageVisitor.cpp b/core/reflection/usageVisitor.cpp index ddc25808d..da3f6444c 100644 --- a/core/reflection/usageVisitor.cpp +++ b/core/reflection/usageVisitor.cpp @@ -1,4 +1,4 @@ -#include "core/reflection/usageVisitor.h" +#include "reflection/usageVisitor.h" namespace corecvs { diff --git a/core/reflection/usageVisitor.h b/core/reflection/usageVisitor.h index f3d86b193..4bc5377d8 100644 --- a/core/reflection/usageVisitor.h +++ b/core/reflection/usageVisitor.h @@ -5,8 +5,8 @@ #include #include -#include "core/reflection/reflection.h" -#include "core/reflection/dynamicObject.h" +#include "reflection/reflection.h" +#include "reflection/dynamicObject.h" namespace corecvs { diff --git a/core/segmentation/CMakeLists.txt b/core/segmentation/CMakeLists.txt index f362a08bf..e1f834678 100644 --- a/core/segmentation/CMakeLists.txt +++ b/core/segmentation/CMakeLists.txt @@ -1,10 +1,11 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/segmentator.h - ${CMAKE_CURRENT_LIST_DIR}/tileGrid.h - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/segmentator.cpp - ${CMAKE_CURRENT_LIST_DIR}/tileGrid.cpp -) +set(SEGMENTATION_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/segmentator.h + ${CMAKE_CURRENT_LIST_DIR}/tileGrid.h + PARENT_SCOPE + ) +set(SEGMENTATION_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/segmentator.cpp + ${CMAKE_CURRENT_LIST_DIR}/tileGrid.cpp + PARENT_SCOPE + ) diff --git a/core/segmentation/segmentator.cpp b/core/segmentation/segmentator.cpp index a46795380..046db1234 100644 --- a/core/segmentation/segmentator.cpp +++ b/core/segmentation/segmentator.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/segmentation/segmentator.h" +#include "segmentation/segmentator.h" namespace corecvs { diff --git a/core/segmentation/segmentator.h b/core/segmentation/segmentator.h index 681b3d72e..1b136bbea 100644 --- a/core/segmentation/segmentator.h +++ b/core/segmentation/segmentator.h @@ -13,11 +13,11 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/vector2d.h" -#include "core/buffers/abstractBuffer.h" -#include "core/buffers/g12Buffer.h" +#include "math/vector/vector2d.h" +#include "buffers/abstractBuffer.h" +#include "buffers/g12Buffer.h" namespace corecvs { diff --git a/core/segmentation/tileGrid.cpp b/core/segmentation/tileGrid.cpp index c366bc0e7..4a7d1242a 100644 --- a/core/segmentation/tileGrid.cpp +++ b/core/segmentation/tileGrid.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/segmentation/tileGrid.h" +#include "segmentation/tileGrid.h" namespace corecvs { diff --git a/core/segmentation/tileGrid.h b/core/segmentation/tileGrid.h index 2ab2f7b1e..7f9478182 100644 --- a/core/segmentation/tileGrid.h +++ b/core/segmentation/tileGrid.h @@ -10,12 +10,12 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/abstractContiniousBuffer.h" -#include "core/segmentation/segmentator.h" -#include "core/buffers/histogram/histogram.h" -#include "core/geometry/ellipticalApproximation.h" +#include "buffers/abstractContiniousBuffer.h" +#include "segmentation/segmentator.h" +#include "buffers/histogram/histogram.h" +#include "geometry/ellipticalApproximation.h" #include "../math/mathUtils.h" diff --git a/core/serializer/serializable.cpp b/core/serializer/serializable.cpp index 32a328b9d..6bafe4bad 100644 --- a/core/serializer/serializable.cpp +++ b/core/serializer/serializable.cpp @@ -6,7 +6,7 @@ * \author alexander */ -#include "core/serializer/serializable.h" +#include "serializer/serializable.h" namespace corecvs { template<> diff --git a/core/stats/CMakeLists.txt b/core/stats/CMakeLists.txt index 374aa13d5..3735e626e 100644 --- a/core/stats/CMakeLists.txt +++ b/core/stats/CMakeLists.txt @@ -1,9 +1,11 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/calculationStats.h - ${CMAKE_CURRENT_LIST_DIR}/graphData.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/calculationStats.cpp - ${CMAKE_CURRENT_LIST_DIR}/graphData.cpp - ) +set(STATS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/calculationStats.h + ${CMAKE_CURRENT_LIST_DIR}/graphData.h + PARENT_SCOPE + ) +set(STATS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/calculationStats.cpp + ${CMAKE_CURRENT_LIST_DIR}/graphData.cpp + PARENT_SCOPE + ) diff --git a/core/stats/calculationStats.cpp b/core/stats/calculationStats.cpp index f7562950f..a8f8abf9f 100644 --- a/core/stats/calculationStats.cpp +++ b/core/stats/calculationStats.cpp @@ -6,9 +6,9 @@ * \author alexander */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/stats/calculationStats.h" +#include "stats/calculationStats.h" namespace corecvs { diff --git a/core/stats/calculationStats.h b/core/stats/calculationStats.h index 7aefa844f..0ba06dd63 100644 --- a/core/stats/calculationStats.h +++ b/core/stats/calculationStats.h @@ -15,15 +15,15 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/vector/fixedVector.h" -#include "core/utils/preciseTimer.h" -#include "core/math/mathUtils.h" +#include "math/vector/fixedVector.h" +#include "utils/preciseTimer.h" +#include "math/mathUtils.h" /* This is for osd */ -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/rgb24/abstractPainter.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/abstractPainter.h" namespace corecvs { diff --git a/core/stats/graphData.cpp b/core/stats/graphData.cpp index 31ad2afbd..fa53ebaa8 100644 --- a/core/stats/graphData.cpp +++ b/core/stats/graphData.cpp @@ -1,4 +1,4 @@ -#include "core/utils/global.h" +#include "utils/global.h" #include "graphData.h" #include diff --git a/core/stereointerface/CMakeLists.txt b/core/stereointerface/CMakeLists.txt index be5d99b08..c643ec341 100644 --- a/core/stereointerface/CMakeLists.txt +++ b/core/stereointerface/CMakeLists.txt @@ -1,8 +1,11 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/processor6D.h - ${CMAKE_CURRENT_LIST_DIR}/dummyFlowProcessor.h - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/processor6D.cpp - ${CMAKE_CURRENT_LIST_DIR}/dummyFlowProcessor.cpp -) +set(STEREOINTERFACE_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/processor6D.h + ${CMAKE_CURRENT_LIST_DIR}/dummyFlowProcessor.h + PARENT_SCOPE + ) + +set(STEREOINTERFACE_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/processor6D.cpp + ${CMAKE_CURRENT_LIST_DIR}/dummyFlowProcessor.cpp + PARENT_SCOPE + ) diff --git a/core/stereointerface/dummyFlowProcessor.cpp b/core/stereointerface/dummyFlowProcessor.cpp index e38844aa5..30af4ee00 100644 --- a/core/stereointerface/dummyFlowProcessor.cpp +++ b/core/stereointerface/dummyFlowProcessor.cpp @@ -1,4 +1,4 @@ -#include "core/stereointerface/dummyFlowProcessor.h" +#include "stereointerface/dummyFlowProcessor.h" /** * Factory diff --git a/core/stereointerface/dummyFlowProcessor.h b/core/stereointerface/dummyFlowProcessor.h index 9701a6d8e..cdf718591 100644 --- a/core/stereointerface/dummyFlowProcessor.h +++ b/core/stereointerface/dummyFlowProcessor.h @@ -1,9 +1,9 @@ #ifndef DUMMY_FLOW_PROCESSOR_H #define DUMMY_FLOW_PROCESSOR_H -#include "core/stats/calculationStats.h" -#include "core/reflection/dynamicObject.h" -#include "core/stereointerface/processor6D.h" +#include "stats/calculationStats.h" +#include "reflection/dynamicObject.h" +#include "stereointerface/processor6D.h" namespace corecvs { diff --git a/core/stereointerface/processor6D.cpp b/core/stereointerface/processor6D.cpp index 621235dae..cd4e6578b 100644 --- a/core/stereointerface/processor6D.cpp +++ b/core/stereointerface/processor6D.cpp @@ -1,4 +1,4 @@ -#include "core/stereointerface/processor6D.h" +#include "stereointerface/processor6D.h" namespace corecvs { diff --git a/core/stereointerface/processor6D.h b/core/stereointerface/processor6D.h index 893f140a9..760129946 100644 --- a/core/stereointerface/processor6D.h +++ b/core/stereointerface/processor6D.h @@ -10,17 +10,17 @@ */ -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/reflection/dynamicObject.h" +#include "reflection/dynamicObject.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/flow/flowBuffer.h" -#include "core/buffers/flow/sixDBuffer.h" -#include "core/stats/calculationStats.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/flow/flowBuffer.h" +#include "buffers/flow/sixDBuffer.h" +#include "stats/calculationStats.h" -#include "core/patterndetection/patternDetector.h" +#include "patterndetection/patternDetector.h" namespace corecvs { diff --git a/core/tbbwrapper/CMakeLists.txt b/core/tbbwrapper/CMakeLists.txt index 2bbedea96..317a45e63 100644 --- a/core/tbbwrapper/CMakeLists.txt +++ b/core/tbbwrapper/CMakeLists.txt @@ -1,6 +1,4 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/tbbWrapper.h -) - - +set(TBBWRAPPER_HEADER_FILE + ${CMAKE_CURRENT_LIST_DIR}/tbbWrapper.h + PARENT_SCOPE + ) diff --git a/core/tbbwrapper/tbbWrapper.h b/core/tbbwrapper/tbbWrapper.h index 8d5a369d7..915a8567d 100644 --- a/core/tbbwrapper/tbbWrapper.h +++ b/core/tbbwrapper/tbbWrapper.h @@ -32,7 +32,7 @@ using namespace tbb; #endif -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { diff --git a/core/tinyxml2/CMakeLists.txt b/core/tinyxml2/CMakeLists.txt index 3bf93989d..5f37f2f4a 100644 --- a/core/tinyxml2/CMakeLists.txt +++ b/core/tinyxml2/CMakeLists.txt @@ -1,7 +1,9 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/tinyxml2.h +set(TINYXML2_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/tinyxml2.h + PARENT_SCOPE + ) - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/tinyxml2.cpp -) +set(TINYXML2_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/tinyxml2.cpp + PARENT_SCOPE + ) diff --git a/core/tinyxml2/tinyxml2.cpp b/core/tinyxml2/tinyxml2.cpp index abcc92342..cb39768ed 100755 --- a/core/tinyxml2/tinyxml2.cpp +++ b/core/tinyxml2/tinyxml2.cpp @@ -21,7 +21,7 @@ must not be misrepresented as being the original software. distribution. */ -#include "core/tinyxml2/tinyxml2.h" +#include "tinyxml2/tinyxml2.h" #include // yes, this one new style header, is in the Android SDK. # ifdef ANDROID_NDK diff --git a/core/utils/CMakeLists.txt b/core/utils/CMakeLists.txt index 05e5c58a1..8c9a56da0 100644 --- a/core/utils/CMakeLists.txt +++ b/core/utils/CMakeLists.txt @@ -1,32 +1,33 @@ -target_sources(corecvs - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/global.h - ${CMAKE_CURRENT_LIST_DIR}/stdint_win.h - ${CMAKE_CURRENT_LIST_DIR}/preciseTimer.h - ${CMAKE_CURRENT_LIST_DIR}/propertyList.h - ${CMAKE_CURRENT_LIST_DIR}/visitors/propertyListVisitor.h - ${CMAKE_CURRENT_LIST_DIR}/utils.h - ${CMAKE_CURRENT_LIST_DIR}/visitors/basePathVisitor.h - ${CMAKE_CURRENT_LIST_DIR}/log.h - ${CMAKE_CURRENT_LIST_DIR}/countedPtr.h - ${CMAKE_CURRENT_LIST_DIR}/atomicOps.h - ${CMAKE_CURRENT_LIST_DIR}/typesafeBitmaskEnums.h - ${CMAKE_CURRENT_LIST_DIR}/statusTracker.h - # ${CMAKE_CURRENT_LIST_DIR}/abstractImageNamer.h - # ${CMAKE_CURRENT_LIST_DIR}/statusTrackerCatcher.h - ${CMAKE_CURRENT_LIST_DIR}/debuggableBlock.h +set(UTILS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/global.h + ${CMAKE_CURRENT_LIST_DIR}/stdint_win.h + ${CMAKE_CURRENT_LIST_DIR}/preciseTimer.h + ${CMAKE_CURRENT_LIST_DIR}/propertyList.h + ${CMAKE_CURRENT_LIST_DIR}/visitors/propertyListVisitor.h + ${CMAKE_CURRENT_LIST_DIR}/utils.h + ${CMAKE_CURRENT_LIST_DIR}/visitors/basePathVisitor.h + ${CMAKE_CURRENT_LIST_DIR}/log.h + ${CMAKE_CURRENT_LIST_DIR}/countedPtr.h + ${CMAKE_CURRENT_LIST_DIR}/atomicOps.h + ${CMAKE_CURRENT_LIST_DIR}/typesafeBitmaskEnums.h + ${CMAKE_CURRENT_LIST_DIR}/statusTracker.h +# ${CMAKE_CURRENT_LIST_DIR}/abstractImageNamer.h +# ${CMAKE_CURRENT_LIST_DIR}/statusTrackerCatcher.h + ${CMAKE_CURRENT_LIST_DIR}/debuggableBlock.h + PARENT_SCOPE + ) - - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/memhooks.c - ${CMAKE_CURRENT_LIST_DIR}/util.c - ${CMAKE_CURRENT_LIST_DIR}/preciseTimer.cpp - ${CMAKE_CURRENT_LIST_DIR}/propertyList.cpp - ${CMAKE_CURRENT_LIST_DIR}/visitors/propertyListVisitor.cpp - ${CMAKE_CURRENT_LIST_DIR}/visitors/basePathVisitor.cpp - ${CMAKE_CURRENT_LIST_DIR}/utils.cpp - ${CMAKE_CURRENT_LIST_DIR}/log.cpp - ${CMAKE_CURRENT_LIST_DIR}/statusTracker.cpp - # ${CMAKE_CURRENT_LIST_DIR}/abstractImageNamer.cpp - ${CMAKE_CURRENT_LIST_DIR}/debuggableBlock.cpp -) +set(UTILS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/memhooks.c + ${CMAKE_CURRENT_LIST_DIR}/util.c + ${CMAKE_CURRENT_LIST_DIR}/preciseTimer.cpp + ${CMAKE_CURRENT_LIST_DIR}/propertyList.cpp + ${CMAKE_CURRENT_LIST_DIR}/visitors/propertyListVisitor.cpp + ${CMAKE_CURRENT_LIST_DIR}/visitors/basePathVisitor.cpp + ${CMAKE_CURRENT_LIST_DIR}/utils.cpp + ${CMAKE_CURRENT_LIST_DIR}/log.cpp + ${CMAKE_CURRENT_LIST_DIR}/statusTracker.cpp +# ${CMAKE_CURRENT_LIST_DIR}/abstractImageNamer.cpp + ${CMAKE_CURRENT_LIST_DIR}/debuggableBlock.cpp + PARENT_SCOPE + ) diff --git a/core/utils/countedPtr.h b/core/utils/countedPtr.h index ec368f21e..ba8ee7fd3 100644 --- a/core/utils/countedPtr.h +++ b/core/utils/countedPtr.h @@ -1,6 +1,6 @@ #pragma once -//#include "core/utils/global.h" +//#include "utils/global.h" template class CountedPtr diff --git a/core/utils/debuggableBlock.cpp b/core/utils/debuggableBlock.cpp index a5c1ef061..21ee45b30 100644 --- a/core/utils/debuggableBlock.cpp +++ b/core/utils/debuggableBlock.cpp @@ -1,4 +1,4 @@ -#include "core/buffers/bufferFactory.h" +#include "buffers/bufferFactory.h" #include "debuggableBlock.h" diff --git a/core/utils/debuggableBlock.h b/core/utils/debuggableBlock.h index f48e6f5fb..2da1881c4 100644 --- a/core/utils/debuggableBlock.h +++ b/core/utils/debuggableBlock.h @@ -4,7 +4,7 @@ #include #include -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" namespace corecvs { diff --git a/core/utils/global.h b/core/utils/global.h index 1c52873fa..80701f7b2 100644 --- a/core/utils/global.h +++ b/core/utils/global.h @@ -53,7 +53,7 @@ typedef int bool_t; // fast Boolean type #ifdef WIN32 # define strdup _strdup # define strcasecmp _stricmp -# ifdef _MSC_VER +# if _MSC_VER < 1900 # define snprintf sprintf_s # define putenv _putenv # endif diff --git a/core/utils/log.cpp b/core/utils/log.cpp index 696dbdc0d..280a28745 100644 --- a/core/utils/log.cpp +++ b/core/utils/log.cpp @@ -7,11 +7,11 @@ # include #endif -#include "core/utils/log.h" -#include "core/reflection/commandLineSetter.h" -#include "core/tbbwrapper/tbbWrapper.h" -#include "core/filesystem/tempFolder.h" -#include "core/utils/utils.h" +#include "utils/log.h" +#include "reflection/commandLineSetter.h" +#include "tbbwrapper/tbbWrapper.h" +#include "filesystem/tempFolder.h" +#include "utils/utils.h" const char *Log::level_names[] = { diff --git a/core/utils/log.h b/core/utils/log.h index 71cd08ae1..16987c90f 100644 --- a/core/utils/log.h +++ b/core/utils/log.h @@ -3,7 +3,7 @@ * \file log.h * \brief This class will be used for logging **/ -#include "core/utils/global.h" +#include "utils/global.h" #include #include @@ -21,7 +21,7 @@ #include #include // std::mutex -#include "core/buffers/memory/memoryBlock.h" +#include "buffers/memory/memoryBlock.h" using corecvs::ObjectRef; diff --git a/core/utils/preciseTimer.cpp b/core/utils/preciseTimer.cpp index f7e3e81f7..cbfb5ff79 100644 --- a/core/utils/preciseTimer.cpp +++ b/core/utils/preciseTimer.cpp @@ -28,7 +28,7 @@ #include -#include "core/utils/preciseTimer.h" +#include "utils/preciseTimer.h" namespace corecvs { diff --git a/core/utils/preciseTimer.h b/core/utils/preciseTimer.h index 58192558b..556bbc409 100644 --- a/core/utils/preciseTimer.h +++ b/core/utils/preciseTimer.h @@ -13,7 +13,7 @@ * * gettimeofday on linux */ #include -#include "core/math/mathUtils.h" +#include "math/mathUtils.h" namespace corecvs { diff --git a/core/utils/propertyList.cpp b/core/utils/propertyList.cpp index 31dd41a3b..65d25e123 100644 --- a/core/utils/propertyList.cpp +++ b/core/utils/propertyList.cpp @@ -7,7 +7,7 @@ * \author alexander */ -#include "core/utils/propertyList.h" +#include "utils/propertyList.h" namespace corecvs { diff --git a/core/utils/propertyList.h b/core/utils/propertyList.h index 31cd73e94..e442679c9 100644 --- a/core/utils/propertyList.h +++ b/core/utils/propertyList.h @@ -19,8 +19,8 @@ #include #include -#include "core/utils/global.h" -#include "core/utils/utils.h" +#include "utils/global.h" +#include "utils/utils.h" namespace corecvs { diff --git a/core/utils/statusTracker.cpp b/core/utils/statusTracker.cpp index 5424e85ae..84c8cae02 100644 --- a/core/utils/statusTracker.cpp +++ b/core/utils/statusTracker.cpp @@ -1,5 +1,5 @@ -#include "core/utils/statusTracker.h" -#include "core/tbbwrapper/tbbWrapper.h" +#include "utils/statusTracker.h" +#include "tbbwrapper/tbbWrapper.h" #include diff --git a/core/utils/statusTracker.h b/core/utils/statusTracker.h index 67716b69f..267d7ba4d 100644 --- a/core/utils/statusTracker.h +++ b/core/utils/statusTracker.h @@ -5,9 +5,9 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/tbbwrapper/tbbWrapper.h" +#include "tbbwrapper/tbbWrapper.h" struct CancelExecutionException : public AssertException { diff --git a/core/utils/utils.cpp b/core/utils/utils.cpp index 3e98c2016..246117abb 100644 --- a/core/utils/utils.cpp +++ b/core/utils/utils.cpp @@ -18,7 +18,7 @@ #endif #include -#include "core/utils/utils.h" +#include "utils/utils.h" namespace corecvs { diff --git a/core/utils/utils.h b/core/utils/utils.h index 93a7eb3bb..0bb2a6586 100644 --- a/core/utils/utils.h +++ b/core/utils/utils.h @@ -18,7 +18,7 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" namespace corecvs { diff --git a/core/utils/visitors/basePathVisitor.cpp b/core/utils/visitors/basePathVisitor.cpp index 743f6a87c..20c47a70b 100644 --- a/core/utils/visitors/basePathVisitor.cpp +++ b/core/utils/visitors/basePathVisitor.cpp @@ -6,8 +6,8 @@ * \author alexander */ -#include "core/utils/global.h" -#include "core/utils/visitors/basePathVisitor.h" +#include "utils/global.h" +#include "utils/visitors/basePathVisitor.h" namespace corecvs { diff --git a/core/utils/visitors/propertyListVisitor.cpp b/core/utils/visitors/propertyListVisitor.cpp index 384c3ba7f..206188723 100644 --- a/core/utils/visitors/propertyListVisitor.cpp +++ b/core/utils/visitors/propertyListVisitor.cpp @@ -5,8 +5,8 @@ * \date Nov 27, 2011 * \author alexander */ -#include "core/utils/global.h" -#include "core/utils/visitors/propertyListVisitor.h" +#include "utils/global.h" +#include "utils/visitors/propertyListVisitor.h" namespace corecvs { diff --git a/core/utils/visitors/propertyListVisitor.h b/core/utils/visitors/propertyListVisitor.h index c86e19b0c..bd29f8197 100644 --- a/core/utils/visitors/propertyListVisitor.h +++ b/core/utils/visitors/propertyListVisitor.h @@ -13,11 +13,11 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/utils/propertyList.h" -#include "core/utils/visitors/basePathVisitor.h" -#include "core/reflection/reflection.h" +#include "utils/propertyList.h" +#include "utils/visitors/basePathVisitor.h" +#include "reflection/reflection.h" namespace corecvs { diff --git a/core/xml/generated/CMakeLists.txt b/core/xml/generated/CMakeLists.txt index 0c0a21b80..d3e6cdf7d 100644 --- a/core/xml/generated/CMakeLists.txt +++ b/core/xml/generated/CMakeLists.txt @@ -1,10 +1,120 @@ -file(GLOB SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) +set(XML/GENERATED_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/adderSubstractorParametersBase.h + ${CMAKE_CURRENT_LIST_DIR}/axisAlignedBoxParameters.h + ${CMAKE_CURRENT_LIST_DIR}/backgroundFilterParameters.h + ${CMAKE_CURRENT_LIST_DIR}/binarizeParameters.h + ${CMAKE_CURRENT_LIST_DIR}/bitcodeBoardOrientation.h + ${CMAKE_CURRENT_LIST_DIR}/bitcodeBoardParamsBase.h + ${CMAKE_CURRENT_LIST_DIR}/bitSelectorParameters.h + ${CMAKE_CURRENT_LIST_DIR}/calibrationDrawHelpersParameters.h + ${CMAKE_CURRENT_LIST_DIR}/cannyParameters.h + ${CMAKE_CURRENT_LIST_DIR}/checkerboardDetectionAlgorithm.h + ${CMAKE_CURRENT_LIST_DIR}/checkerboardDetectionParameters.h + ${CMAKE_CURRENT_LIST_DIR}/chessBoardAssemblerParamsBase.h + ${CMAKE_CURRENT_LIST_DIR}/chessBoardCornerDetectorParamsBase.h + ${CMAKE_CURRENT_LIST_DIR}/clusteringDirectionType.h + ${CMAKE_CURRENT_LIST_DIR}/colorPallete.h + ${CMAKE_CURRENT_LIST_DIR}/debayerMethod.h + ${CMAKE_CURRENT_LIST_DIR}/debayerParameters.h + ${CMAKE_CURRENT_LIST_DIR}/distortionApplicationParameters.h + ${CMAKE_CURRENT_LIST_DIR}/distortionResizePolicy.h + ${CMAKE_CURRENT_LIST_DIR}/draw3dParameters.h + ${CMAKE_CURRENT_LIST_DIR}/draw3dStyle.h + ${CMAKE_CURRENT_LIST_DIR}/draw3dTextureGen.h + ${CMAKE_CURRENT_LIST_DIR}/drawGCodeParameters.h + ${CMAKE_CURRENT_LIST_DIR}/euclidianMoveParameters.h + ${CMAKE_CURRENT_LIST_DIR}/extrinsicsPlacerParameters.h + ${CMAKE_CURRENT_LIST_DIR}/focusEstimationParameters.h + ${CMAKE_CURRENT_LIST_DIR}/focusEstimationResult.h + ${CMAKE_CURRENT_LIST_DIR}/gainOffsetParameters.h + ${CMAKE_CURRENT_LIST_DIR}/gCodeColoringSheme.h + ${CMAKE_CURRENT_LIST_DIR}/harrisDetectionParameters.h + ${CMAKE_CURRENT_LIST_DIR}/headSearchParameters.h + ${CMAKE_CURRENT_LIST_DIR}/homographyAlgorithm.h + ${CMAKE_CURRENT_LIST_DIR}/homorgaphyReconstructorBlockBase.h + ${CMAKE_CURRENT_LIST_DIR}/imageChannel.h + ${CMAKE_CURRENT_LIST_DIR}/inputFilterParameters.h + ${CMAKE_CURRENT_LIST_DIR}/inputType.h + ${CMAKE_CURRENT_LIST_DIR}/interpolationType.h + ${CMAKE_CURRENT_LIST_DIR}/iterativeEstimateParameters.h + ${CMAKE_CURRENT_LIST_DIR}/lensDistortionModelParametersBase.h + ${CMAKE_CURRENT_LIST_DIR}/lineDistortionEstimatorCost.h + ${CMAKE_CURRENT_LIST_DIR}/lineDistortionEstimatorParameters.h + ${CMAKE_CURRENT_LIST_DIR}/makePreciseAlgorithm.h + ${CMAKE_CURRENT_LIST_DIR}/makePreciseParameters.h + ${CMAKE_CURRENT_LIST_DIR}/maskingParameters.h + ${CMAKE_CURRENT_LIST_DIR}/omnidirectionalBaseParameters.h + ${CMAKE_CURRENT_LIST_DIR}/openCVBinaryFilterType.h + ${CMAKE_CURRENT_LIST_DIR}/openCVFilterParameters.h + ${CMAKE_CURRENT_LIST_DIR}/operation.h + ${CMAKE_CURRENT_LIST_DIR}/operationParameters.h + ${CMAKE_CURRENT_LIST_DIR}/outputFilterParameters.h + ${CMAKE_CURRENT_LIST_DIR}/outputType.h + ${CMAKE_CURRENT_LIST_DIR}/patternDetectorResultBase.h + ${CMAKE_CURRENT_LIST_DIR}/pinholeCameraIntrinsicsBaseParameters.h + ${CMAKE_CURRENT_LIST_DIR}/preciseInterpolationType.h + ${CMAKE_CURRENT_LIST_DIR}/projectionBaseParameters.h + ${CMAKE_CURRENT_LIST_DIR}/projectionType.h + ${CMAKE_CURRENT_LIST_DIR}/ransacParameters.h + ${CMAKE_CURRENT_LIST_DIR}/rgbColorParameters.h + ${CMAKE_CURRENT_LIST_DIR}/sceneDrawBackendType.h + ${CMAKE_CURRENT_LIST_DIR}/sceneStereoAlignerBlockBase.h + ${CMAKE_CURRENT_LIST_DIR}/sobelMixingType.h + ${CMAKE_CURRENT_LIST_DIR}/sobelParameters.h + ${CMAKE_CURRENT_LIST_DIR}/stereoAlignParameters.h + ${CMAKE_CURRENT_LIST_DIR}/thickeningParameters.h + ${CMAKE_CURRENT_LIST_DIR}/vector2dParameters.h + ${CMAKE_CURRENT_LIST_DIR}/vector3dParameters.h + PARENT_SCOPE + ) -target_sources(corecvs - PUBLIC - ${HDR_FILES} - PRIVATE - ${SRC_FILES} - -) +set(XML/GENERATED_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/adderSubstractorParametersBase.cpp + ${CMAKE_CURRENT_LIST_DIR}/axisAlignedBoxParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/backgroundFilterParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/binarizeParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/bitcodeBoardParamsBase.cpp + ${CMAKE_CURRENT_LIST_DIR}/bitSelectorParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/calibrationDrawHelpersParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/cannyParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/checkerboardDetectionParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/chessBoardAssemblerParamsBase.cpp + ${CMAKE_CURRENT_LIST_DIR}/chessBoardCornerDetectorParamsBase.cpp + ${CMAKE_CURRENT_LIST_DIR}/debayerParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/distortionApplicationParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/draw3dParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/drawGCodeParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/essentialDerivative1.cpp + ${CMAKE_CURRENT_LIST_DIR}/essentialDerivative2.cpp + ${CMAKE_CURRENT_LIST_DIR}/essentialDerivative.cpp + ${CMAKE_CURRENT_LIST_DIR}/euclidianMoveParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/extrinsicsPlacerParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/focusEstimationParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/focusEstimationResult.cpp + ${CMAKE_CURRENT_LIST_DIR}/gainOffsetParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/harrisDetectionParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/headSearchParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/homorgaphyReconstructorBlockBase.cpp + ${CMAKE_CURRENT_LIST_DIR}/inputFilterParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/iterativeEstimateParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/lensDistortionModelParametersBase.cpp + ${CMAKE_CURRENT_LIST_DIR}/lineDistortionEstimatorParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/makePreciseParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/maskingParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/omnidirectionalBaseParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/openCVFilterParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/operationParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/outputFilterParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/patternDetectorResultBase.cpp + ${CMAKE_CURRENT_LIST_DIR}/pinholeCameraIntrinsicsBaseParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/projectionBaseParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/ransacParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/rgbColorParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/sceneStereoAlignerBlockBase.cpp + ${CMAKE_CURRENT_LIST_DIR}/sobelParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/stereoAlignParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/thickeningParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/vector2dParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/vector3dParameters.cpp + PARENT_SCOPE + ) diff --git a/core/xml/generated/adderSubstractorParametersBase.h b/core/xml/generated/adderSubstractorParametersBase.h index a6dd0e905..492fcb589 100644 --- a/core/xml/generated/adderSubstractorParametersBase.h +++ b/core/xml/generated/adderSubstractorParametersBase.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/axisAlignedBoxParameters.h b/core/xml/generated/axisAlignedBoxParameters.h index 4f86c1074..09b80dd58 100644 --- a/core/xml/generated/axisAlignedBoxParameters.h +++ b/core/xml/generated/axisAlignedBoxParameters.h @@ -9,9 +9,9 @@ * Generated from parameters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/backgroundFilterParameters.h b/core/xml/generated/backgroundFilterParameters.h index 3eabca31d..014846b33 100644 --- a/core/xml/generated/backgroundFilterParameters.h +++ b/core/xml/generated/backgroundFilterParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/binarizeParameters.h b/core/xml/generated/binarizeParameters.h index c183ca09d..303d6f310 100644 --- a/core/xml/generated/binarizeParameters.h +++ b/core/xml/generated/binarizeParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/bitSelectorParameters.h b/core/xml/generated/bitSelectorParameters.h index 0a677e304..50630aae5 100644 --- a/core/xml/generated/bitSelectorParameters.h +++ b/core/xml/generated/bitSelectorParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/bitcodeBoardParamsBase.h b/core/xml/generated/bitcodeBoardParamsBase.h index 9041bd2d5..22a6e477f 100644 --- a/core/xml/generated/bitcodeBoardParamsBase.h +++ b/core/xml/generated/bitcodeBoardParamsBase.h @@ -9,9 +9,9 @@ * Generated from patternDetector.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/bitcodeBoardOrientation.h" +#include "xml/generated/bitcodeBoardOrientation.h" /** * \brief Bitcode Board Params Base diff --git a/core/xml/generated/calibrationDrawHelpersParameters.h b/core/xml/generated/calibrationDrawHelpersParameters.h index df4a6abda..59c9f0f8c 100644 --- a/core/xml/generated/calibrationDrawHelpersParameters.h +++ b/core/xml/generated/calibrationDrawHelpersParameters.h @@ -9,9 +9,9 @@ * Generated from calibration.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/sceneDrawBackendType.h" +#include "xml/generated/sceneDrawBackendType.h" /** * \brief EXPERIMENTAL diff --git a/core/xml/generated/cannyParameters.h b/core/xml/generated/cannyParameters.h index 7b44e0f24..ac05445bc 100644 --- a/core/xml/generated/cannyParameters.h +++ b/core/xml/generated/cannyParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/checkerboardDetectionParameters.h b/core/xml/generated/checkerboardDetectionParameters.h index 3313d6887..97141869e 100644 --- a/core/xml/generated/checkerboardDetectionParameters.h +++ b/core/xml/generated/checkerboardDetectionParameters.h @@ -9,9 +9,9 @@ * Generated from patternDetector.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,8 +31,8 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/checkerboardDetectionAlgorithm.h" -#include "core/xml/generated/imageChannel.h" +#include "xml/generated/checkerboardDetectionAlgorithm.h" +#include "xml/generated/imageChannel.h" /** * \brief Checkerboard Detection Parameters diff --git a/core/xml/generated/chessBoardAssemblerParamsBase.h b/core/xml/generated/chessBoardAssemblerParamsBase.h index e8241896d..beebd4a94 100644 --- a/core/xml/generated/chessBoardAssemblerParamsBase.h +++ b/core/xml/generated/chessBoardAssemblerParamsBase.h @@ -9,9 +9,9 @@ * Generated from patternDetector.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/chessBoardCornerDetectorParamsBase.h b/core/xml/generated/chessBoardCornerDetectorParamsBase.h index d12073a7f..cbbe3f68e 100644 --- a/core/xml/generated/chessBoardCornerDetectorParamsBase.h +++ b/core/xml/generated/chessBoardCornerDetectorParamsBase.h @@ -9,9 +9,9 @@ * Generated from patternDetector.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/debayerParameters.h b/core/xml/generated/debayerParameters.h index 86e893279..6c708f335 100644 --- a/core/xml/generated/debayerParameters.h +++ b/core/xml/generated/debayerParameters.h @@ -9,9 +9,9 @@ * Generated from parameters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/debayerMethod.h" +#include "xml/generated/debayerMethod.h" /** * \brief Debayer Parameters diff --git a/core/xml/generated/distortionApplicationParameters.h b/core/xml/generated/distortionApplicationParameters.h index c573e0834..842bb8791 100644 --- a/core/xml/generated/distortionApplicationParameters.h +++ b/core/xml/generated/distortionApplicationParameters.h @@ -9,9 +9,9 @@ * Generated from distortion.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/distortionResizePolicy.h" +#include "xml/generated/distortionResizePolicy.h" /** * \brief Distortion Application Parameters diff --git a/core/xml/generated/drawGCodeParameters.h b/core/xml/generated/drawGCodeParameters.h index 5ffd8ce10..9feccf219 100644 --- a/core/xml/generated/drawGCodeParameters.h +++ b/core/xml/generated/drawGCodeParameters.h @@ -9,9 +9,9 @@ * Generated from parameters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/gCodeColoringSheme.h" +#include "xml/generated/gCodeColoringSheme.h" /** * \brief draw GCode Parameters diff --git a/core/xml/generated/essentialDerivative.cpp b/core/xml/generated/essentialDerivative.cpp index a26860670..a549cb3fb 100644 --- a/core/xml/generated/essentialDerivative.cpp +++ b/core/xml/generated/essentialDerivative.cpp @@ -1,5 +1,5 @@ -#include "core/buffers/correspondenceList.h" -#include "core/rectification/essentialEstimator.h" +#include "buffers/correspondenceList.h" +#include "rectification/essentialEstimator.h" namespace corecvs { diff --git a/core/xml/generated/essentialDerivative1.cpp b/core/xml/generated/essentialDerivative1.cpp index a13064db1..71b52b5e5 100644 --- a/core/xml/generated/essentialDerivative1.cpp +++ b/core/xml/generated/essentialDerivative1.cpp @@ -1,6 +1,6 @@ #include -#include "core/buffers/correspondenceList.h" -#include "core/rectification/essentialEstimator.h" +#include "buffers/correspondenceList.h" +#include "rectification/essentialEstimator.h" using namespace std; namespace corecvs { diff --git a/core/xml/generated/essentialDerivative2.cpp b/core/xml/generated/essentialDerivative2.cpp index 7fec5a01c..ec8ee9deb 100644 --- a/core/xml/generated/essentialDerivative2.cpp +++ b/core/xml/generated/essentialDerivative2.cpp @@ -1,6 +1,6 @@ #include -#include "core/buffers/correspondenceList.h" -#include "core/rectification/essentialEstimator.h" +#include "buffers/correspondenceList.h" +#include "rectification/essentialEstimator.h" using namespace std; namespace corecvs { diff --git a/core/xml/generated/euclidianMoveParameters.h b/core/xml/generated/euclidianMoveParameters.h index 08c5e57ef..c5e975182 100644 --- a/core/xml/generated/euclidianMoveParameters.h +++ b/core/xml/generated/euclidianMoveParameters.h @@ -9,9 +9,9 @@ * Generated from parameters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/extrinsicsPlacerParameters.h b/core/xml/generated/extrinsicsPlacerParameters.h index 0585bd2c9..d5a51875b 100644 --- a/core/xml/generated/extrinsicsPlacerParameters.h +++ b/core/xml/generated/extrinsicsPlacerParameters.h @@ -9,9 +9,9 @@ * Generated from calibration.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/focusEstimationParameters.h b/core/xml/generated/focusEstimationParameters.h index c244bcef9..684ab43be 100644 --- a/core/xml/generated/focusEstimationParameters.h +++ b/core/xml/generated/focusEstimationParameters.h @@ -9,9 +9,9 @@ * Generated from parameters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/focusEstimationResult.h b/core/xml/generated/focusEstimationResult.h index d570ff353..d2e5d2946 100644 --- a/core/xml/generated/focusEstimationResult.h +++ b/core/xml/generated/focusEstimationResult.h @@ -9,9 +9,9 @@ * Generated from parameters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/gainOffsetParameters.h b/core/xml/generated/gainOffsetParameters.h index b1a7da55b..fba5e07f4 100644 --- a/core/xml/generated/gainOffsetParameters.h +++ b/core/xml/generated/gainOffsetParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/harrisDetectionParameters.h b/core/xml/generated/harrisDetectionParameters.h index 9a7121922..c50f35d57 100644 --- a/core/xml/generated/harrisDetectionParameters.h +++ b/core/xml/generated/harrisDetectionParameters.h @@ -9,9 +9,9 @@ * Generated from parameters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/headSearchParameters.h b/core/xml/generated/headSearchParameters.h index f3e0e3af8..415b20394 100644 --- a/core/xml/generated/headSearchParameters.h +++ b/core/xml/generated/headSearchParameters.h @@ -9,9 +9,9 @@ * Generated from clustering1.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/homorgaphyReconstructorBlockBase.h b/core/xml/generated/homorgaphyReconstructorBlockBase.h index e1efb6a6b..0ec5759b0 100644 --- a/core/xml/generated/homorgaphyReconstructorBlockBase.h +++ b/core/xml/generated/homorgaphyReconstructorBlockBase.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -37,7 +37,7 @@ class Matrix33; /* * Additional includes for enum section. */ -#include "core/xml/generated/homographyAlgorithm.h" +#include "xml/generated/homographyAlgorithm.h" /** * \brief HomorgaphyReconstructorBlockBase diff --git a/core/xml/generated/inputFilterParameters.h b/core/xml/generated/inputFilterParameters.h index f8a73976f..9f8374fbf 100644 --- a/core/xml/generated/inputFilterParameters.h +++ b/core/xml/generated/inputFilterParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/inputType.h" +#include "xml/generated/inputType.h" /** * \brief Input Filter Parameters diff --git a/core/xml/generated/iterativeEstimateParameters.h b/core/xml/generated/iterativeEstimateParameters.h index 29169da72..5ab77488d 100644 --- a/core/xml/generated/iterativeEstimateParameters.h +++ b/core/xml/generated/iterativeEstimateParameters.h @@ -9,9 +9,9 @@ * Generated from stereoAlign.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/lensDistortionModelParametersBase.h b/core/xml/generated/lensDistortionModelParametersBase.h index 561431a88..446c7e489 100644 --- a/core/xml/generated/lensDistortionModelParametersBase.h +++ b/core/xml/generated/lensDistortionModelParametersBase.h @@ -9,9 +9,9 @@ * Generated from distortion.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/lineDistortionEstimatorParameters.h b/core/xml/generated/lineDistortionEstimatorParameters.h index 812f00a4b..1340955a1 100644 --- a/core/xml/generated/lineDistortionEstimatorParameters.h +++ b/core/xml/generated/lineDistortionEstimatorParameters.h @@ -9,9 +9,9 @@ * Generated from distortion.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/lineDistortionEstimatorCost.h" +#include "xml/generated/lineDistortionEstimatorCost.h" /** * \brief Line Distortion Estimator Parameters diff --git a/core/xml/generated/makePreciseParameters.h b/core/xml/generated/makePreciseParameters.h index 3a9d6f40b..7c740c69d 100644 --- a/core/xml/generated/makePreciseParameters.h +++ b/core/xml/generated/makePreciseParameters.h @@ -9,9 +9,9 @@ * Generated from precise.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,8 +31,8 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/makePreciseAlgorithm.h" -#include "core/xml/generated/preciseInterpolationType.h" +#include "xml/generated/makePreciseAlgorithm.h" +#include "xml/generated/preciseInterpolationType.h" /** * \brief Make Precise Parameters diff --git a/core/xml/generated/maskingParameters.h b/core/xml/generated/maskingParameters.h index ce73a0fa3..64982b82e 100644 --- a/core/xml/generated/maskingParameters.h +++ b/core/xml/generated/maskingParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/omnidirectionalBaseParameters.h b/core/xml/generated/omnidirectionalBaseParameters.h index 908c89429..d9bac513b 100644 --- a/core/xml/generated/omnidirectionalBaseParameters.h +++ b/core/xml/generated/omnidirectionalBaseParameters.h @@ -9,9 +9,9 @@ * Generated from projections.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/openCVFilterParameters.h b/core/xml/generated/openCVFilterParameters.h index a165f6166..98a0838e0 100644 --- a/core/xml/generated/openCVFilterParameters.h +++ b/core/xml/generated/openCVFilterParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/openCVBinaryFilterType.h" +#include "xml/generated/openCVBinaryFilterType.h" /** * \brief OpenCV Filter Parameters diff --git a/core/xml/generated/operationParameters.h b/core/xml/generated/operationParameters.h index cee004c94..90fa945a6 100644 --- a/core/xml/generated/operationParameters.h +++ b/core/xml/generated/operationParameters.h @@ -9,9 +9,9 @@ * Generated from filterBlock.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/operation.h" +#include "xml/generated/operation.h" /** * \brief Operation Parameters diff --git a/core/xml/generated/outputFilterParameters.h b/core/xml/generated/outputFilterParameters.h index 918f35e79..6c6941270 100644 --- a/core/xml/generated/outputFilterParameters.h +++ b/core/xml/generated/outputFilterParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/outputType.h" +#include "xml/generated/outputType.h" /** * \brief Output Filter Parameters diff --git a/core/xml/generated/patternDetectorResultBase.h b/core/xml/generated/patternDetectorResultBase.h index eec037813..421a4be9b 100644 --- a/core/xml/generated/patternDetectorResultBase.h +++ b/core/xml/generated/patternDetectorResultBase.h @@ -9,9 +9,9 @@ * Generated from parameters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -19,7 +19,7 @@ /* * Additional includes for Composite Types. */ -#include "core/xml/generated/vector2dParameters.h" +#include "xml/generated/vector2dParameters.h" // using namespace corecvs; diff --git a/core/xml/generated/pinholeCameraIntrinsicsBaseParameters.h b/core/xml/generated/pinholeCameraIntrinsicsBaseParameters.h index aece55cb3..4e2eca3c1 100644 --- a/core/xml/generated/pinholeCameraIntrinsicsBaseParameters.h +++ b/core/xml/generated/pinholeCameraIntrinsicsBaseParameters.h @@ -9,9 +9,9 @@ * Generated from projections.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -19,7 +19,7 @@ /* * Additional includes for Composite Types. */ -#include "core/xml/generated/vector2dParameters.h" +#include "xml/generated/vector2dParameters.h" // using namespace corecvs; diff --git a/core/xml/generated/projectionBaseParameters.h b/core/xml/generated/projectionBaseParameters.h index b9c7949f8..9ca6064ea 100644 --- a/core/xml/generated/projectionBaseParameters.h +++ b/core/xml/generated/projectionBaseParameters.h @@ -9,9 +9,9 @@ * Generated from projections.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/ransacParameters.h b/core/xml/generated/ransacParameters.h index 6b4b11044..44caec1b3 100644 --- a/core/xml/generated/ransacParameters.h +++ b/core/xml/generated/ransacParameters.h @@ -9,9 +9,9 @@ * Generated from stereoAlign.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/rgbColorParameters.h b/core/xml/generated/rgbColorParameters.h index 49fb00fb5..1e8aa4d72 100644 --- a/core/xml/generated/rgbColorParameters.h +++ b/core/xml/generated/rgbColorParameters.h @@ -9,9 +9,9 @@ * Generated from parameters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/sceneStereoAlignerBlockBase.h b/core/xml/generated/sceneStereoAlignerBlockBase.h index 537ec379d..eece14474 100644 --- a/core/xml/generated/sceneStereoAlignerBlockBase.h +++ b/core/xml/generated/sceneStereoAlignerBlockBase.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -19,7 +19,7 @@ /* * Additional includes for Composite Types. */ -#include "core/xml/generated/stereoAlignParameters.h" +#include "xml/generated/stereoAlignParameters.h" // using namespace corecvs; diff --git a/core/xml/generated/sobelParameters.h b/core/xml/generated/sobelParameters.h index b1aa42c4c..afdc290cc 100644 --- a/core/xml/generated/sobelParameters.h +++ b/core/xml/generated/sobelParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. @@ -31,7 +31,7 @@ /* * Additional includes for enum section. */ -#include "core/xml/generated/sobelMixingType.h" +#include "xml/generated/sobelMixingType.h" /** * \brief Sobel Parameters diff --git a/core/xml/generated/stereoAlignParameters.h b/core/xml/generated/stereoAlignParameters.h index 72ff1de95..5c810faab 100644 --- a/core/xml/generated/stereoAlignParameters.h +++ b/core/xml/generated/stereoAlignParameters.h @@ -9,9 +9,9 @@ * Generated from stereoAlign.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/thickeningParameters.h b/core/xml/generated/thickeningParameters.h index 14e8ad1d9..ada1d9ad6 100644 --- a/core/xml/generated/thickeningParameters.h +++ b/core/xml/generated/thickeningParameters.h @@ -9,9 +9,9 @@ * Generated from bufferFilters.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/vector2dParameters.h b/core/xml/generated/vector2dParameters.h index cb5d0c3e4..24f487d69 100644 --- a/core/xml/generated/vector2dParameters.h +++ b/core/xml/generated/vector2dParameters.h @@ -9,9 +9,9 @@ * Generated from basemock.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/core/xml/generated/vector3dParameters.h b/core/xml/generated/vector3dParameters.h index 5ac65f64c..baa861312 100644 --- a/core/xml/generated/vector3dParameters.h +++ b/core/xml/generated/vector3dParameters.h @@ -9,9 +9,9 @@ * Generated from basemock.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/dirent_msvc.h b/dirent_msvc.h new file mode 100644 index 000000000..55132b337 --- /dev/null +++ b/dirent_msvc.h @@ -0,0 +1,1160 @@ +/* + * Dirent interface for Microsoft Visual Studio + * + * Copyright (C) 1998-2019 Toni Ronkko + * This file is part of dirent. Dirent may be freely distributed + * under the MIT license. For all details and documentation, see + * https://github.com/tronkko/dirent + */ +#ifndef DIRENT_H +#define DIRENT_H + +/* Hide warnings about unreferenced local functions */ +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wunused-function" +#elif defined(_MSC_VER) +# pragma warning(disable:4505) +#elif defined(__GNUC__) +# pragma GCC diagnostic ignored "-Wunused-function" +#endif + +/* + * Include windows.h without Windows Sockets 1.1 to prevent conflicts with + * Windows Sockets 2.0. + */ +#ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Indicates that d_type field is available in dirent structure */ +#define _DIRENT_HAVE_D_TYPE + +/* Indicates that d_namlen field is available in dirent structure */ +#define _DIRENT_HAVE_D_NAMLEN + +/* Entries missing from MSVC 6.0 */ +#if !defined(FILE_ATTRIBUTE_DEVICE) +# define FILE_ATTRIBUTE_DEVICE 0x40 +#endif + +/* File type and permission flags for stat(), general mask */ +#if !defined(S_IFMT) +# define S_IFMT _S_IFMT +#endif + +/* Directory bit */ +#if !defined(S_IFDIR) +# define S_IFDIR _S_IFDIR +#endif + +/* Character device bit */ +#if !defined(S_IFCHR) +# define S_IFCHR _S_IFCHR +#endif + +/* Pipe bit */ +#if !defined(S_IFFIFO) +# define S_IFFIFO _S_IFFIFO +#endif + +/* Regular file bit */ +#if !defined(S_IFREG) +# define S_IFREG _S_IFREG +#endif + +/* Read permission */ +#if !defined(S_IREAD) +# define S_IREAD _S_IREAD +#endif + +/* Write permission */ +#if !defined(S_IWRITE) +# define S_IWRITE _S_IWRITE +#endif + +/* Execute permission */ +#if !defined(S_IEXEC) +# define S_IEXEC _S_IEXEC +#endif + +/* Pipe */ +#if !defined(S_IFIFO) +# define S_IFIFO _S_IFIFO +#endif + +/* Block device */ +#if !defined(S_IFBLK) +# define S_IFBLK 0 +#endif + +/* Link */ +#if !defined(S_IFLNK) +# define S_IFLNK 0 +#endif + +/* Socket */ +#if !defined(S_IFSOCK) +# define S_IFSOCK 0 +#endif + +/* Read user permission */ +#if !defined(S_IRUSR) +# define S_IRUSR S_IREAD +#endif + +/* Write user permission */ +#if !defined(S_IWUSR) +# define S_IWUSR S_IWRITE +#endif + +/* Execute user permission */ +#if !defined(S_IXUSR) +# define S_IXUSR 0 +#endif + +/* Read group permission */ +#if !defined(S_IRGRP) +# define S_IRGRP 0 +#endif + +/* Write group permission */ +#if !defined(S_IWGRP) +# define S_IWGRP 0 +#endif + +/* Execute group permission */ +#if !defined(S_IXGRP) +# define S_IXGRP 0 +#endif + +/* Read others permission */ +#if !defined(S_IROTH) +# define S_IROTH 0 +#endif + +/* Write others permission */ +#if !defined(S_IWOTH) +# define S_IWOTH 0 +#endif + +/* Execute others permission */ +#if !defined(S_IXOTH) +# define S_IXOTH 0 +#endif + +/* Maximum length of file name */ +#if !defined(PATH_MAX) +# define PATH_MAX MAX_PATH +#endif +#if !defined(FILENAME_MAX) +# define FILENAME_MAX MAX_PATH +#endif +#if !defined(NAME_MAX) +# define NAME_MAX FILENAME_MAX +#endif + +/* File type flags for d_type */ +#define DT_UNKNOWN 0 +#define DT_REG S_IFREG +#define DT_DIR S_IFDIR +#define DT_FIFO S_IFIFO +#define DT_SOCK S_IFSOCK +#define DT_CHR S_IFCHR +#define DT_BLK S_IFBLK +#define DT_LNK S_IFLNK + +/* Macros for converting between st_mode and d_type */ +#define IFTODT(mode) ((mode) & S_IFMT) +#define DTTOIF(type) (type) + +/* + * File type macros. Note that block devices, sockets and links cannot be + * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are + * only defined for compatibility. These macros should always return false + * on Windows. + */ +#if !defined(S_ISFIFO) +# define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) +#endif +#if !defined(S_ISDIR) +# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#endif +#if !defined(S_ISREG) +# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#endif +#if !defined(S_ISLNK) +# define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) +#endif +#if !defined(S_ISSOCK) +# define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) +#endif +#if !defined(S_ISCHR) +# define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) +#endif +#if !defined(S_ISBLK) +# define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) +#endif + +/* Return the exact length of the file name without zero terminator */ +#define _D_EXACT_NAMLEN(p) ((p)->d_namlen) + +/* Return the maximum size of a file name */ +#define _D_ALLOC_NAMLEN(p) ((PATH_MAX)+1) + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Wide-character version */ +struct _wdirent { + /* Always zero */ + long d_ino; + + /* File position within stream */ + long d_off; + + /* Structure size */ + unsigned short d_reclen; + + /* Length of name without \0 */ + size_t d_namlen; + + /* File type */ + int d_type; + + /* File name */ + wchar_t d_name[PATH_MAX+1]; +}; +typedef struct _wdirent _wdirent; + +struct _WDIR { + /* Current directory entry */ + struct _wdirent ent; + + /* Private file data */ + WIN32_FIND_DATAW data; + + /* True if data is valid */ + int cached; + + /* Win32 search handle */ + HANDLE handle; + + /* Initial directory name */ + wchar_t *patt; +}; +typedef struct _WDIR _WDIR; + +/* Multi-byte character version */ +struct dirent { + /* Always zero */ + long d_ino; + + /* File position within stream */ + long d_off; + + /* Structure size */ + unsigned short d_reclen; + + /* Length of name without \0 */ + size_t d_namlen; + + /* File type */ + int d_type; + + /* File name */ + char d_name[PATH_MAX+1]; +}; +typedef struct dirent dirent; + +struct DIR { + struct dirent ent; + struct _WDIR *wdirp; +}; +typedef struct DIR DIR; + + +/* Dirent functions */ +static DIR *opendir (const char *dirname); +static _WDIR *_wopendir (const wchar_t *dirname); + +static struct dirent *readdir (DIR *dirp); +static struct _wdirent *_wreaddir (_WDIR *dirp); + +static int readdir_r( + DIR *dirp, struct dirent *entry, struct dirent **result); +static int _wreaddir_r( + _WDIR *dirp, struct _wdirent *entry, struct _wdirent **result); + +static int closedir (DIR *dirp); +static int _wclosedir (_WDIR *dirp); + +static void rewinddir (DIR* dirp); +static void _wrewinddir (_WDIR* dirp); + +static int scandir (const char *dirname, struct dirent ***namelist, + int (*filter)(const struct dirent*), + int (*compare)(const struct dirent**, const struct dirent**)); + +static int alphasort (const struct dirent **a, const struct dirent **b); + +static int versionsort (const struct dirent **a, const struct dirent **b); + + +/* For compatibility with Symbian */ +#define wdirent _wdirent +#define WDIR _WDIR +#define wopendir _wopendir +#define wreaddir _wreaddir +#define wclosedir _wclosedir +#define wrewinddir _wrewinddir + + +/* Internal utility functions */ +static WIN32_FIND_DATAW *dirent_first (_WDIR *dirp); +static WIN32_FIND_DATAW *dirent_next (_WDIR *dirp); + +static int dirent_mbstowcs_s( + size_t *pReturnValue, + wchar_t *wcstr, + size_t sizeInWords, + const char *mbstr, + size_t count); + +static int dirent_wcstombs_s( + size_t *pReturnValue, + char *mbstr, + size_t sizeInBytes, + const wchar_t *wcstr, + size_t count); + +static void dirent_set_errno (int error); + + +/* + * Open directory stream DIRNAME for read and return a pointer to the + * internal working area that is used to retrieve individual directory + * entries. + */ +static _WDIR* +_wopendir( + const wchar_t *dirname) +{ + _WDIR *dirp; + DWORD n; + wchar_t *p; + + /* Must have directory name */ + if (dirname == NULL || dirname[0] == '\0') { + dirent_set_errno (ENOENT); + return NULL; + } + + /* Allocate new _WDIR structure */ + dirp = (_WDIR*) malloc (sizeof (struct _WDIR)); + if (!dirp) { + return NULL; + } + + /* Reset _WDIR structure */ + dirp->handle = INVALID_HANDLE_VALUE; + dirp->patt = NULL; + dirp->cached = 0; + + /* + * Compute the length of full path plus zero terminator + * + * Note that on WinRT there's no way to convert relative paths + * into absolute paths, so just assume it is an absolute path. + */ +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + /* Desktop */ + n = GetFullPathNameW (dirname, 0, NULL, NULL); +#else + /* WinRT */ + n = wcslen (dirname); +#endif + + /* Allocate room for absolute directory name and search pattern */ + dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16); + if (dirp->patt == NULL) { + goto exit_closedir; + } + + /* + * Convert relative directory name to an absolute one. This + * allows rewinddir() to function correctly even when current + * working directory is changed between opendir() and rewinddir(). + * + * Note that on WinRT there's no way to convert relative paths + * into absolute paths, so just assume it is an absolute path. + */ +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + /* Desktop */ + n = GetFullPathNameW (dirname, n, dirp->patt, NULL); + if (n <= 0) { + goto exit_closedir; + } +#else + /* WinRT */ + wcsncpy_s (dirp->patt, n+1, dirname, n); +#endif + + /* Append search pattern \* to the directory name */ + p = dirp->patt + n; + switch (p[-1]) { + case '\\': + case '/': + case ':': + /* Directory ends in path separator, e.g. c:\temp\ */ + /*NOP*/; + break; + + default: + /* Directory name doesn't end in path separator */ + *p++ = '\\'; + } + *p++ = '*'; + *p = '\0'; + + /* Open directory stream and retrieve the first entry */ + if (!dirent_first (dirp)) { + goto exit_closedir; + } + + /* Success */ + return dirp; + + /* Failure */ +exit_closedir: + _wclosedir (dirp); + return NULL; +} + +/* + * Read next directory entry. + * + * Returns pointer to static directory entry which may be overwritten by + * subsequent calls to _wreaddir(). + */ +static struct _wdirent* +_wreaddir( + _WDIR *dirp) +{ + struct _wdirent *entry; + + /* + * Read directory entry to buffer. We can safely ignore the return value + * as entry will be set to NULL in case of error. + */ + (void) _wreaddir_r (dirp, &dirp->ent, &entry); + + /* Return pointer to statically allocated directory entry */ + return entry; +} + +/* + * Read next directory entry. + * + * Returns zero on success. If end of directory stream is reached, then sets + * result to NULL and returns zero. + */ +static int +_wreaddir_r( + _WDIR *dirp, + struct _wdirent *entry, + struct _wdirent **result) +{ + WIN32_FIND_DATAW *datap; + + /* Read next directory entry */ + datap = dirent_next (dirp); + if (datap) { + size_t n; + DWORD attr; + + /* + * Copy file name as wide-character string. If the file name is too + * long to fit in to the destination buffer, then truncate file name + * to PATH_MAX characters and zero-terminate the buffer. + */ + n = 0; + while (n < PATH_MAX && datap->cFileName[n] != 0) { + entry->d_name[n] = datap->cFileName[n]; + n++; + } + entry->d_name[n] = 0; + + /* Length of file name excluding zero terminator */ + entry->d_namlen = n; + + /* File type */ + attr = datap->dwFileAttributes; + if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { + entry->d_type = DT_CHR; + } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { + entry->d_type = DT_DIR; + } else { + entry->d_type = DT_REG; + } + + /* Reset dummy fields */ + entry->d_ino = 0; + entry->d_off = 0; + entry->d_reclen = sizeof (struct _wdirent); + + /* Set result address */ + *result = entry; + + } else { + + /* Return NULL to indicate end of directory */ + *result = NULL; + + } + + return /*OK*/0; +} + +/* + * Close directory stream opened by opendir() function. This invalidates the + * DIR structure as well as any directory entry read previously by + * _wreaddir(). + */ +static int +_wclosedir( + _WDIR *dirp) +{ + int ok; + if (dirp) { + + /* Release search handle */ + if (dirp->handle != INVALID_HANDLE_VALUE) { + FindClose (dirp->handle); + } + + /* Release search pattern */ + free (dirp->patt); + + /* Release directory structure */ + free (dirp); + ok = /*success*/0; + + } else { + + /* Invalid directory stream */ + dirent_set_errno (EBADF); + ok = /*failure*/-1; + + } + return ok; +} + +/* + * Rewind directory stream such that _wreaddir() returns the very first + * file name again. + */ +static void +_wrewinddir( + _WDIR* dirp) +{ + if (dirp) { + /* Release existing search handle */ + if (dirp->handle != INVALID_HANDLE_VALUE) { + FindClose (dirp->handle); + } + + /* Open new search handle */ + dirent_first (dirp); + } +} + +/* Get first directory entry (internal) */ +static WIN32_FIND_DATAW* +dirent_first( + _WDIR *dirp) +{ + WIN32_FIND_DATAW *datap; + DWORD error; + + /* Open directory and retrieve the first entry */ + dirp->handle = FindFirstFileExW( + dirp->patt, FindExInfoStandard, &dirp->data, + FindExSearchNameMatch, NULL, 0); + if (dirp->handle != INVALID_HANDLE_VALUE) { + + /* a directory entry is now waiting in memory */ + datap = &dirp->data; + dirp->cached = 1; + + } else { + + /* Failed to open directory: no directory entry in memory */ + dirp->cached = 0; + datap = NULL; + + /* Set error code */ + error = GetLastError (); + switch (error) { + case ERROR_ACCESS_DENIED: + /* No read access to directory */ + dirent_set_errno (EACCES); + break; + + case ERROR_DIRECTORY: + /* Directory name is invalid */ + dirent_set_errno (ENOTDIR); + break; + + case ERROR_PATH_NOT_FOUND: + default: + /* Cannot find the file */ + dirent_set_errno (ENOENT); + } + + } + return datap; +} + +/* + * Get next directory entry (internal). + * + * Returns + */ +static WIN32_FIND_DATAW* +dirent_next( + _WDIR *dirp) +{ + WIN32_FIND_DATAW *p; + + /* Get next directory entry */ + if (dirp->cached != 0) { + + /* A valid directory entry already in memory */ + p = &dirp->data; + dirp->cached = 0; + + } else if (dirp->handle != INVALID_HANDLE_VALUE) { + + /* Get the next directory entry from stream */ + if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) { + /* Got a file */ + p = &dirp->data; + } else { + /* The very last entry has been processed or an error occurred */ + FindClose (dirp->handle); + dirp->handle = INVALID_HANDLE_VALUE; + p = NULL; + } + + } else { + + /* End of directory stream reached */ + p = NULL; + + } + + return p; +} + +/* + * Open directory stream using plain old C-string. + */ +static DIR* +opendir( + const char *dirname) +{ + struct DIR *dirp; + + /* Must have directory name */ + if (dirname == NULL || dirname[0] == '\0') { + dirent_set_errno (ENOENT); + return NULL; + } + + /* Allocate memory for DIR structure */ + dirp = (DIR*) malloc (sizeof (struct DIR)); + if (!dirp) { + return NULL; + } + { + int error; + wchar_t wname[PATH_MAX + 1]; + size_t n; + + /* Convert directory name to wide-character string */ + error = dirent_mbstowcs_s( + &n, wname, PATH_MAX + 1, dirname, PATH_MAX + 1); + if (error) { + /* + * Cannot convert file name to wide-character string. This + * occurs if the string contains invalid multi-byte sequences or + * the output buffer is too small to contain the resulting + * string. + */ + goto exit_free; + } + + + /* Open directory stream using wide-character name */ + dirp->wdirp = _wopendir (wname); + if (!dirp->wdirp) { + goto exit_free; + } + + } + + /* Success */ + return dirp; + + /* Failure */ +exit_free: + free (dirp); + return NULL; +} + +/* + * Read next directory entry. + */ +static struct dirent* +readdir( + DIR *dirp) +{ + struct dirent *entry; + + /* + * Read directory entry to buffer. We can safely ignore the return value + * as entry will be set to NULL in case of error. + */ + (void) readdir_r (dirp, &dirp->ent, &entry); + + /* Return pointer to statically allocated directory entry */ + return entry; +} + +/* + * Read next directory entry into called-allocated buffer. + * + * Returns zero on success. If the end of directory stream is reached, then + * sets result to NULL and returns zero. + */ +static int +readdir_r( + DIR *dirp, + struct dirent *entry, + struct dirent **result) +{ + WIN32_FIND_DATAW *datap; + + /* Read next directory entry */ + datap = dirent_next (dirp->wdirp); + if (datap) { + size_t n; + int error; + + /* Attempt to convert file name to multi-byte string */ + error = dirent_wcstombs_s( + &n, entry->d_name, PATH_MAX + 1, datap->cFileName, PATH_MAX + 1); + + /* + * If the file name cannot be represented by a multi-byte string, + * then attempt to use old 8+3 file name. This allows traditional + * Unix-code to access some file names despite of unicode + * characters, although file names may seem unfamiliar to the user. + * + * Be ware that the code below cannot come up with a short file + * name unless the file system provides one. At least + * VirtualBox shared folders fail to do this. + */ + if (error && datap->cAlternateFileName[0] != '\0') { + error = dirent_wcstombs_s( + &n, entry->d_name, PATH_MAX + 1, + datap->cAlternateFileName, PATH_MAX + 1); + } + + if (!error) { + DWORD attr; + + /* Length of file name excluding zero terminator */ + entry->d_namlen = n - 1; + + /* File attributes */ + attr = datap->dwFileAttributes; + if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { + entry->d_type = DT_CHR; + } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { + entry->d_type = DT_DIR; + } else { + entry->d_type = DT_REG; + } + + /* Reset dummy fields */ + entry->d_ino = 0; + entry->d_off = 0; + entry->d_reclen = sizeof (struct dirent); + + } else { + + /* + * Cannot convert file name to multi-byte string so construct + * an erroneous directory entry and return that. Note that + * we cannot return NULL as that would stop the processing + * of directory entries completely. + */ + entry->d_name[0] = '?'; + entry->d_name[1] = '\0'; + entry->d_namlen = 1; + entry->d_type = DT_UNKNOWN; + entry->d_ino = 0; + entry->d_off = -1; + entry->d_reclen = 0; + + } + + /* Return pointer to directory entry */ + *result = entry; + + } else { + + /* No more directory entries */ + *result = NULL; + + } + + return /*OK*/0; +} + +/* + * Close directory stream. + */ +static int +closedir( + DIR *dirp) +{ + int ok; + if (dirp) { + + /* Close wide-character directory stream */ + ok = _wclosedir (dirp->wdirp); + dirp->wdirp = NULL; + + /* Release multi-byte character version */ + free (dirp); + + } else { + + /* Invalid directory stream */ + dirent_set_errno (EBADF); + ok = /*failure*/-1; + + } + return ok; +} + +/* + * Rewind directory stream to beginning. + */ +static void +rewinddir( + DIR* dirp) +{ + /* Rewind wide-character string directory stream */ + _wrewinddir (dirp->wdirp); +} + +/* + * Scan directory for entries. + */ +static int +scandir( + const char *dirname, + struct dirent ***namelist, + int (*filter)(const struct dirent*), + int (*compare)(const struct dirent**, const struct dirent**)) +{ + struct dirent **files = NULL; + size_t size = 0; + size_t allocated = 0; + const size_t init_size = 1; + DIR *dir = NULL; + struct dirent *entry; + struct dirent *tmp = NULL; + size_t i; + int result = 0; + + /* Open directory stream */ + dir = opendir (dirname); + if (dir) { + + /* Read directory entries to memory */ + while (1) { + + /* Enlarge pointer table to make room for another pointer */ + if (size >= allocated) { + void *p; + size_t num_entries; + + /* Compute number of entries in the enlarged pointer table */ + if (size < init_size) { + /* Allocate initial pointer table */ + num_entries = init_size; + } else { + /* Double the size */ + num_entries = size * 2; + } + + /* Allocate first pointer table or enlarge existing table */ + p = realloc (files, sizeof (void*) * num_entries); + if (p != NULL) { + /* Got the memory */ + files = (dirent**) p; + allocated = num_entries; + } else { + /* Out of memory */ + result = -1; + break; + } + + } + + /* Allocate room for temporary directory entry */ + if (tmp == NULL) { + tmp = (struct dirent*) malloc (sizeof (struct dirent)); + if (tmp == NULL) { + /* Cannot allocate temporary directory entry */ + result = -1; + break; + } + } + + /* Read directory entry to temporary area */ + if (readdir_r (dir, tmp, &entry) == /*OK*/0) { + + /* Did we get an entry? */ + if (entry != NULL) { + int pass; + + /* Determine whether to include the entry in result */ + if (filter) { + /* Let the filter function decide */ + pass = filter (tmp); + } else { + /* No filter function, include everything */ + pass = 1; + } + + if (pass) { + /* Store the temporary entry to pointer table */ + files[size++] = tmp; + tmp = NULL; + + /* Keep up with the number of files */ + result++; + } + + } else { + + /* + * End of directory stream reached => sort entries and + * exit. + */ + qsort (files, size, sizeof (void*), + (int (*) (const void*, const void*)) compare); + break; + + } + + } else { + /* Error reading directory entry */ + result = /*Error*/ -1; + break; + } + + } + + } else { + /* Cannot open directory */ + result = /*Error*/ -1; + } + + /* Release temporary directory entry */ + free (tmp); + + /* Release allocated memory on error */ + if (result < 0) { + for (i = 0; i < size; i++) { + free (files[i]); + } + free (files); + files = NULL; + } + + /* Close directory stream */ + if (dir) { + closedir (dir); + } + + /* Pass pointer table to caller */ + if (namelist) { + *namelist = files; + } + return result; +} + +/* Alphabetical sorting */ +static int +alphasort( + const struct dirent **a, const struct dirent **b) +{ + return strcoll ((*a)->d_name, (*b)->d_name); +} + +/* Sort versions */ +static int +versionsort( + const struct dirent **a, const struct dirent **b) +{ + /* FIXME: implement strverscmp and use that */ + return alphasort (a, b); +} + +/* Convert multi-byte string to wide character string */ +static int +dirent_mbstowcs_s( + size_t *pReturnValue, + wchar_t *wcstr, + size_t sizeInWords, + const char *mbstr, + size_t count) +{ + int error; + +#if defined(_MSC_VER) && _MSC_VER >= 1400 + + /* Microsoft Visual Studio 2005 or later */ + error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count); + +#else + + /* Older Visual Studio or non-Microsoft compiler */ + size_t n; + + /* Convert to wide-character string (or count characters) */ + n = mbstowcs (wcstr, mbstr, sizeInWords); + if (!wcstr || n < count) { + + /* Zero-terminate output buffer */ + if (wcstr && sizeInWords) { + if (n >= sizeInWords) { + n = sizeInWords - 1; + } + wcstr[n] = 0; + } + + /* Length of resulting multi-byte string WITH zero terminator */ + if (pReturnValue) { + *pReturnValue = n + 1; + } + + /* Success */ + error = 0; + + } else { + + /* Could not convert string */ + error = 1; + + } + +#endif + return error; +} + +/* Convert wide-character string to multi-byte string */ +static int +dirent_wcstombs_s( + size_t *pReturnValue, + char *mbstr, + size_t sizeInBytes, /* max size of mbstr */ + const wchar_t *wcstr, + size_t count) +{ + int error; + +#if defined(_MSC_VER) && _MSC_VER >= 1400 + + /* Microsoft Visual Studio 2005 or later */ + error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count); + +#else + + /* Older Visual Studio or non-Microsoft compiler */ + size_t n; + + /* Convert to multi-byte string (or count the number of bytes needed) */ + n = wcstombs (mbstr, wcstr, sizeInBytes); + if (!mbstr || n < count) { + + /* Zero-terminate output buffer */ + if (mbstr && sizeInBytes) { + if (n >= sizeInBytes) { + n = sizeInBytes - 1; + } + mbstr[n] = '\0'; + } + + /* Length of resulting multi-bytes string WITH zero-terminator */ + if (pReturnValue) { + *pReturnValue = n + 1; + } + + /* Success */ + error = 0; + + } else { + + /* Cannot convert string */ + error = 1; + + } + +#endif + return error; +} + +/* Set errno variable */ +static void +dirent_set_errno( + int error) +{ +#if defined(_MSC_VER) && _MSC_VER >= 1400 + + /* Microsoft Visual Studio 2005 and later */ + _set_errno (error); + +#else + + /* Non-Microsoft compiler or older Microsoft compiler */ + errno = error; + +#endif +} + + +#ifdef __cplusplus +} +#endif +#endif /*DIRENT_H*/ \ No newline at end of file diff --git a/resources/main.qrc b/resources/main.qrc index 41a81d085..1a0e34a6e 100644 --- a/resources/main.qrc +++ b/resources/main.qrc @@ -128,6 +128,7 @@ radio_modern.png transmit_blue.png transmit.png + theater.png colors/color_blue.png diff --git a/resources/theater.png b/resources/theater.png new file mode 100644 index 000000000..002c73409 Binary files /dev/null and b/resources/theater.png differ diff --git a/siblings/OF_DIS b/siblings/OF_DIS new file mode 160000 index 000000000..2c9f2a674 --- /dev/null +++ b/siblings/OF_DIS @@ -0,0 +1 @@ +Subproject commit 2c9f2a674f3128d3a41c10e41cc9f3a35bb1b523 diff --git a/test-core/-perf/CMakeLists.txt b/test-core/-perf/CMakeLists.txt index d158ab23c..8faf1e112 100644 --- a/test-core/-perf/CMakeLists.txt +++ b/test-core/-perf/CMakeLists.txt @@ -1,52 +1,70 @@ -project (CoreCVSTestsPerf) - +cmake_minimum_required(VERSION 3.11) set(MODULE_NAME corecvs) -set(MODULE_NAME_TEST corecvs_core_perf_tests) +init_project(PROJECT_NAME ${MODULE_NAME}_core_perf_tests) + +message(STATUS "Including GTest on Tests build" ) + +set(DIR_NAME + test-core/-perf + ) +set(SOURCE_FILES + main.cpp + ../deform/test_deform.cpp + ) -MESSAGE( STATUS "Including GTest on Tests build" ) -#include_directories (${GTest_INCLUDE_DIR}/..) -include_directories (${GTest_INCLUDE_DIR}) +set(DEFORM_PROFILE_SOURCE_FILE + deform_profile/main_test_deform_profile.cpp + ) -set (CORE_TEST_PERF_SOURCES - main.cpp - +set(FASTKERNEL_DOUBLE_SOURCE_FILE fastkernel_double/main_test_fastkernel_double.cpp - fastkernel_profile/main_test_fastkernel_profile.cpp - - matrix_profile/main_test_matrix_profile.cpp - - hamilton/main_test_hamilton_profile.cpp - - ../deform/test_deform.cpp - deform_profile/main_test_deform_profile.cpp -) + ) -message(STATUS "SOURCE_DIR " ${corecvs_SOURCE_DIR}) -message(STATUS "TEST_SOURCE_DIR " ${PROJECT_SOURCE_DIR}) +set(HAMILTON_SOURCE_FILE + hamilton/main_test_hamilton_profile.cpp + ) +set(MATRIX_PROFILE_SOURCE_FILE + matrix_profile/main_test_matrix_profile.cpp + ) -add_executable(${MODULE_NAME_TEST} ${CORE_TEST_PERF_SOURCES}) +set(SOURCES + ${SOURCE_FILES} + ${DEFORM_PROFILE_SOURCE_FILE} + ${FASTKERNEL_DOUBLE_SOURCE_FILE} + ${HAMILTON_SOURCE_FILE} + ${MATRIX_PROFILE_SOURCE_FILE} + ) -add_custom_command(TARGET ${MODULE_NAME_TEST} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${MODULE_NAME_TEST} ${CMAKE_BINARY_DIR}/bin/${MODULE_NAME_TEST} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${MODULE_NAME_TEST} to binary directory" - ) +assign_source_group(${SOURCES}) -set_property(TARGET ${MODULE_NAME_TEST} PROPERTY CXX_STANDARD 17) -set_property(TARGET ${MODULE_NAME_TEST} PROPERTY CXX_STANDARD_REQUIRED ON) +message(STATUS "SOURCE_DIR " ${corecvs_SOURCE_DIR}) +message(STATUS "TEST_SOURCE_DIR " ${PROJECT_SOURCE_DIR}) + +add_executable(${PROJECT_NAME} + ${SOURCES} + ) +target_include_directories(${PROJECT_NAME} + PRIVATE + ${GTest_INCLUDE_DIR} + ) -target_link_libraries(${MODULE_NAME_TEST} gtest gtest_main stdc++fs corecvs) -#target_include_directories(${MODULE_NAME_TEST} PUBLIC ${corecvs_SOURCE_DIR} .) -target_include_directories(${MODULE_NAME_TEST} PUBLIC ${corecvs_SOURCE_DIR}) +target_link_libraries(${PROJECT_NAME} + corecvs + gtest + gtest_main + stdc++fs + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${DIR_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) # For ctest support. Not necessary to use but nice move for automated testing. add_test( - NAME - core-test-perf - COMMAND - ./${MODULE_NAME_TEST} -) - + NAME core-test-perf + COMMAND ./${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test-core/CMakeLists.txt b/test-core/CMakeLists.txt index 97277a78d..d15350638 100644 --- a/test-core/CMakeLists.txt +++ b/test-core/CMakeLists.txt @@ -1,153 +1,499 @@ -project (CoreCVSCoreTests) - +cmake_minimum_required(VERSION 3.11) set(MODULE_NAME corecvs) -set(MODULE_NAME_TEST corecvs_core_tests) - +init_project(PROJECT_NAME ${MODULE_NAME}_core_tests) MESSAGE( STATUS "Including GTest on Tests build" ) -#include_directories (${GTest_INCLUDE_DIR}/..) -set (CORE_TEST_SOURCES - eigen/main_test_eigen_integration.cpp +set(DIR_NAME + test-core + ) - ultrasound/main_test_ultrasound_reconstruction.cpp - ultrasound/model.cpp - ultrasound/imgreader.cpp - ultrasound/model.h - ultrasound/imgreader.h +set(CONVEXPOLYGON_HEADER_FILE + convexpolygon/convexDebug.h + ) +set(CPPUNIT_TEST_HEADER_FILES + cppunit_test/MatcherTest.h + ) + +set(GENERATED_HEADER_FILES generated/testEnum.h generated/testSubClass.h generated/testClass.h generated/testBlock.h + ) - generated/testSubClass.cpp - generated/testClass.cpp - generated/testBlock.cpp +set(SNOOKER_HEADER_FILES + snooker/commonTypes.h + snooker/errors.h + snooker/reflectionSegmentator.h + snooker/snookerSegmentator.h + ) + +set(STATEMACHINETEST_HEADER_FILES + stateMachineTest/test.h + stateMachineTest/test.h + ) + +set(ULTRASOUND_HEADER_FILES + ultrasound/model.h + ultrasound/imgreader.h + ) -# eigen/main_test_eigen.cpp +set(HEADERS + ${CONVEXPOLYGON_HEADER_FILE} + ${CPPUNIT_TEST_HEADER_FILES} + ${GENERATED_HEADER_FILES} + ${SNOOKER_HEADER_FILES} + ${STATEMACHINETEST_HEADER_FILES} + ${ULTRASOUND_HEADER_FILES} + ) + +set(AFFINE_SOURCE_FILE affine/main_test_affine.cpp + ) + +set(ALOWCODEC_SOURCE_FILE # aLowCodec/main_test_aLowCodec.cpp + ) + +set(ARITHMETICS_SOURCE_FILE arithmetics/main_test_arithmetics.cpp + ) + +set(ASSIGNMENT_SOURCE_FILE assignment/main_test_assignment.cpp + ) + +set(AUTOMOTIVE_SOURCE_FILE automotive/main_test_automotive.cpp + ) + +set(BEZIERRASTERIZER_SOURCE_FILE + bezierRasterizer/main_test_bezier_rasterizer.cpp + ) + +set(BSPRENDERER_SOURCE_FILE + bspRenderer/bspRenderTest.cpp + bspRenderer/bspRenderer.cpp + ) + +set(BSPTREE_SOURCE_FILE + bsptree/main_test_bsptree.cpp + ) + +set(BUFFER_SOURCE_FILE buffer/main_test_buffer.cpp + ) + +set(CALSTRUCTS_SOURCE_FILE +# calstructs/main_test_calstructs.cpp + ) + +set(CAMERACALIBRATION_SOURCE_FILE +# cameracalibration/main_test_camera_structs.cpp + ) + +set(CAMERAMODEL_SOURCE_FILE cameramodel/main_test_cameramodel.cpp + ) + +set(CAMERAFIXTURE_SOURCE_FILE + camerafixture/main_test_camerafixture.cpp + ) + +set(CHOLESKY_SOURCE_FILE? cholesky/main_test_cholesky.cpp + ) + +set(CLOUD_SOURCE_FILE cloud/main_test_cloud.cpp + ) + +set(COLOR_SOURCE_FILE color/main_test_color.cpp + ) + +set(COMMANDLINE_SOURCE_FILE commandline/main_test_commandline.cpp + ) + +set(CONIC_SOURCE_FILE + conic/main_test_conic.cpp + ) + +set(CONVEXHULL_SOURCE_FILE + convexhull/main_test_convexhull.cpp + ) + +set(CONVEXHULL2D_SOURCE_FILE + convexHull2d/main_test_convexHull2d.cpp + ) + +set(CONVEXPOLYGON_SOURCE_FILES + convexpolygon/convexDebug.cpp + convexpolygon/main_test_convexpolygon.cpp + ) + +set(CONVOLVE_SOURCE_FILE convolve/main_test_convolve.cpp + ) + +set(DEFORM_SOURCE_FILES deform/main_test_deform.cpp + deform/test_deform.cpp + ) + +set(DELAUNAY_SOURCE_FILE +# delaunay/main_test_delaunay.cpp + ) + +set(DERIVATIVE_SOURCE_FILE derivative/main_test_derivative.cpp + ) + +set(DRAW_SOURCE_FILE draw/main_test_draw.cpp + ) + +set (EIGEN_SOURCE_FILES + eigen/main_test_eigen_integration.cpp +# eigen/main_test_eigen.cpp + ) + +set(FASTKERNEL_SOURCE_FILE fastkernel/main_test_fastkernel.cpp + ) + +set(FILEFORMATS_SOURCE_FILE fileformats/main_test_fileformats.cpp + ) + +set(FILESYSTEM_SOURCE_FILE filesystem/main_test_filesystem.cpp + ) + +set(FUNCTION_SOURCE_FILE + function/main_test_function.cpp + ) + +set(GAUSSIANSOLUTION_SOURCE_FILE # gaussianSolution/main_test_gaussianSolution.cpp # TODO: check it... + ) + +set(GEOMETRY_SOURCE_FILE geometry/main_test_geometry.cpp + ) + +set(GENERATED_SOURCE_FILES + generated/testSubClass.cpp + generated/testClass.cpp + generated/testBlock.cpp + ) + +set(GRADIENT_SOURCE_FILE gradient/main_test_gradient.cpp + ) + +set(HALFSPACE_SOURCE_FILE + halfspace/main_test_halfspace.cpp + ) + +set(HISTOGRAM_SOURCE_FILE histogram/main_test_histogram.cpp + ) + +set(HOMOGRAPHY_SOURCE_FILE homography/main_test_homography.cpp + ) + +set(INTEGRAL_SOURCE_FILE integral/main_test_integral.cpp + ) + +set(INSET_OUTSET_SOURCE_FILE inset_outset/main_test_inset_outset.cpp + ) + +set(JSON_OUTSET_SOURCE_FILE + json/main_test_json.cpp + ) + +set(KALMAN_SOURCE_FILE kalman/main_test_kalman.cpp + ) + +set(KLT_CYCLE_SOURCE_FILE klt_cycle/main_test_klt_cycle.cpp + ) + +set(LEVENBERG_SOURCE_FILE levenberg/main_test_levenberg.cpp + ) + +set(LINEAR_SOURCE_FILE linear/main_test_linear.cpp + ) + +set(MATRIX_SOURCE_FILE matrix/main_test_matrix.cpp # TODO: Windows: assert at matrix\main_test_matrix.cpp:385 - Internal problem with double and stdout + ) + +set(MESHDRAW_SOURCE_FILE + meshdraw/main_test_meshdraw.cpp + ) + +set(MESHFILTER_SOURCE_FILE + meshfilter/main_test_meshfilter.cpp + ) + +set(META_SOURCE_FILE + meta/main_test_meta.cpp + ) + +set(MIDMAP_PYRAMID_SOURCE_FILE midmap_pyramid/main_test_midmap_pyramid.cpp + ) + +set(MOMENTS_SOURCE_FILE moments/main_test_moments.cpp + ) + +set(MORPHOLOGIC_SOURCE_FILE morphologic/main_test_morphologic.cpp + ) + +set(NOISE_SOURCE_FILE + noise/main_test_noise.cpp + ) + +set(ORIENTEDBOX_SOURCE_FILE + orientedbox/main_test_orientedbox.cpp + ) + +set(PLANEFIT_SOURCE_FILE + planefit/main_test_planefit.cpp + ) + +set(POLYNOMDISTORTION_SOURCE_FILE # polynomDistortion/main_test_polynomDistortion.cpp # TODO: check it... + ) + +set(POLYNOMIAL_SOURCE_FILES + polynomial/main_test_polynomial.cpp + polynomial/main_test_basis.cpp + polynomial/main_test_monom.cpp + polynomial/main_test_polynom.cpp + ) + +set(PROCESSOR6D_SOURCE_FILE + processor6d/main_test_processor6d.cpp + ) + +set(PROJECTION_SOURCE_FILE + projection/main_test_projection.cpp + ) + +set(QUADRIC_SOURCE_FILE + quadric/main_test_quadric.cpp + ) + +set(RANSAC_SOURCE_FILE ransac/main_test_ransac.cpp + ) + +set(RAYTRACE_SOURCE_FILE + raytrace/main_test_raytrace.cpp + ) + +set(READERS_SOURCE_FILE readers/main_test_readers.cpp + ) + +set(RECONSTRUCTION_SOURCE_FILE +# reconstruction/main_test_reconstruction.cpp + ) + +set(RECTIFICATOR_SOURCE_FILES rectificator/main_test_rectificator.cpp rectificator1/main_test_rectificator1.cpp + ) + +set(RENDERER_SOURCE_FILE + renderer/main_test_renderer.cpp + ) + +set(RGB24BUFFER_SOURCE_FILE rgb24buffer/main_test_rgb24buffer.cpp + ) + +set(ROTATION_SOURCE_FILE rotation/main_test_rotation_lanzcos.cpp + ) + +set(SERIALIZER_SOURCE_FILE serializer/main_test_serializer.cpp + ) + +set(SIMILARITY_SOURCE_FILE similarity/main_test_similarity.cpp + ) + +set(SPHERICDIST_SOURCE_FILE sphericdist/main_test_sphericdist.cpp + ) + +set(SSEWRAPPERS_SOURCE_FILE ssewrappers/main_test_ssewrappers.cpp + ) + +set(TBB_WRAPPER_SOURCE_FILE tbb_wrapper/main_test_tbb_wrapper.cpp + ) + +set(TRIANGULATOR_SOURCE_FILE triangulator/main_test_triangulator.cpp - vector/main_test_vector.cpp -# yuv/main_test_yuv.cpp -# cameracalibration/main_test_camera_structs.cpp - conic/main_test_conic.cpp -# calstructs/main_test_calstructs.cpp - polynomial/main_test_polynomial.cpp - polynomial/main_test_basis.cpp - polynomial/main_test_monom.cpp - polynomial/main_test_polynom.cpp -# reconstruction/main_test_reconstruction.cpp - meta/main_test_meta.cpp - function/main_test_function.cpp - deform/test_deform.cpp - camerafixture/main_test_camerafixture.cpp - renderer/main_test_renderer.cpp - raytrace/main_test_raytrace.cpp - json/main_test_json.cpp + ) + +set (ULTRASOUND_SOURCE_FILES + ultrasound/main_test_ultrasound_reconstruction.cpp + ultrasound/model.cpp + ultrasound/imgreader.cpp + ) + +set(UTILS_SOURCE_FILE utils/main_test_utils.cpp - quadric/main_test_quadric.cpp - planefit/main_test_planefit.cpp - noise/main_test_noise.cpp - projection/main_test_projection.cpp - vptree/main_test_vptree.cpp - meshfilter/main_test_meshfilter.cpp - meshdraw/main_test_meshdraw.cpp - meshcache/main_test_meshcache.cpp + ) - convexpolygon/convexDebug.cpp - convexpolygon/main_test_convexpolygon.cpp - convexhull/main_test_convexhull.cpp - convexHull2d/main_test_convexHull2d.cpp +set(VECTOR_SOURCE_FILE + vector/main_test_vector.cpp + ) + +set(VPTREE_SOURCE_FILE + vptree/main_test_vptree.cpp + ) +set(WURASTERIZER_SOURCE_FILE wuRasterizer/main_test_wu_rasterizer.cpp - bsptree/main_test_bsptree.cpp - halfspace/main_test_halfspace.cpp - orientedbox/main_test_orientedbox.cpp - processor6d/main_test_processor6d.cpp - bezierRasterizer/main_test_bezier_rasterizer.cpp -# delaunay/main_test_delaunay.cpp - bspRenderer/bspRenderTest.cpp - bspRenderer/bspRenderer.cpp + ) - cppunit_test/MatcherTest.h - snooker/commonTypes.h - snooker/errors.h - snooker/reflectionSegmentator.h - snooker/snookerSegmentator.h - convexpolygon/convexDebug.h - stateMachineTest/test.h - stateMachineTest/test.h -) +set(YUV_SOURCE_FILE +# yuv/main_test_yuv.cpp + ) + +set(SOURCES + ${AFFINE_SOURCE_FILE} + ${ALOWCODEC_SOURCE_FILE} + ${ARITHMETICS_SOURCE_FILE} + ${ASSIGNMENT_SOURCE_FILE} + ${AUTOMOTIVE_SOURCE_FILE} + ${BEZIERRASTERIZER_SOURCE_FILE} + ${BSPRENDERER_SOURCE_FILE} + ${BSPTREE_SOURCE_FILE} + ${BUFFER_SOURCE_FILE} + ${CALSTRUCTS_SOURCE_FILE} + ${CAMERACALIBRATION_SOURCE_FILE} + ${CAMERAMODEL_SOURCE_FILE} + ${CAMERAFIXTURE_SOURCE_FILE} + ${CHOLESKY_SOURCE_FILE} + ${CLOUD_SOURCE_FILE} + ${COLOR_SOURCE_FILE} + ${COMMANDLINE_SOURCE_FILE} + ${CONIC_SOURCE_FILE} + ${CONVEXHULL_SOURCE_FILE} + ${CONVEXHULL2D_SOURCE_FILE} + ${CONVEXPOLYGON_SOURCE_FILES} + ${CONVOLVE_SOURCE_FILE} + ${DEFORM_SOURCE_FILES} + ${DELAUNAY_SOURCE_FILE} + ${DERIVATIVE_SOURCE_FILE} + ${DRAW_SOURCE_FILE} + ${EIGEN_SOURCE_FILES} + ${FASTKERNEL_SOURCE_FILE} + ${FILEFORMATS_SOURCE_FILE} + ${FILESYSTEM_SOURCE_FILE} + ${FUNCTION_SOURCE_FILE} + ${GAUSSIANSOLUTION_SOURCE_FILE} + ${GEOMETRY_SOURCE_FILE} + ${GENERATED_SOURCE_FILES} + ${GRADIENT_SOURCE_FILE} + ${HALFSPACE_SOURCE_FILE} + ${HISTOGRAM_SOURCE_FILE} + ${HOMOGRAPHY_SOURCE_FILE} + ${INTEGRAL_SOURCE_FILE} + ${INSET_OUTSET_SOURCE_FILE} + ${JSON_OUTSET_SOURCE_FILE} + ${KALMAN_SOURCE_FILE} + ${KLT_CYCLE_SOURCE_FILE} + ${LEVENBERG_SOURCE_FILE} + ${LINEAR_SOURCE_FILE} + ${MATRIX_SOURCE_FILE} + ${MESHDRAW_SOURCE_FILE} + ${MESHFILTER_SOURCE_FILE} + ${META_SOURCE_FILE} + ${MIDMAP_PYRAMID_SOURCE_FILE} + ${MOMENTS_SOURCE_FILE} + ${MORPHOLOGIC_SOURCE_FILE} + ${NOISE_SOURCE_FILE} + ${ORIENTEDBOX_SOURCE_FILE} + ${PLANEFIT_SOURCE_FILE} + ${POLYNOMDISTORTION_SOURCE_FILE} + ${POLYNOMIAL_SOURCE_FILES} + ${PROCESSOR6D_SOURCE_FILE} + ${PROJECTION_SOURCE_FILE} + ${QUADRIC_SOURCE_FILE} + ${RANSAC_SOURCE_FILE} + ${RAYTRACE_SOURCE_FILE} + ${READERS_SOURCE_FILE} + ${RECONSTRUCTION_SOURCE_FILE} + ${RECTIFICATOR_SOURCE_FILES} + ${RENDERER_SOURCE_FILE} + ${RGB24BUFFER_SOURCE_FILE} + ${ROTATION_SOURCE_FILE} + ${SERIALIZER_SOURCE_FILE} + ${SIMILARITY_SOURCE_FILE} + ${SPHERICDIST_SOURCE_FILE} + ${SSEWRAPPERS_SOURCE_FILE} + ${TBB_WRAPPER_SOURCE_FILE} + ${TRIANGULATOR_SOURCE_FILE} + ${ULTRASOUND_SOURCE_FILES} + ${UTILS_SOURCE_FILE} + ${VECTOR_SOURCE_FILE} + ${VPTREE_SOURCE_FILE} + ${WURASTERIZER_SOURCE_FILE} + ${YUV_SOURCE_FILE} + ) message(STATUS "SOURCE_DIR " ${corecvs_SOURCE_DIR}) message(STATUS "TEST_SOURCE_DIR " ${PROJECT_SOURCE_DIR}) +assign_source_group(${HEADERS} ${SOURCES}) -add_executable(${MODULE_NAME_TEST} ${CORE_TEST_SOURCES}) +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ${RESOURCES} + ) -add_custom_command(TARGET ${MODULE_NAME_TEST} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${MODULE_NAME_TEST} ${CMAKE_BINARY_DIR}/bin/${MODULE_NAME_TEST} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${MODULE_NAME_TEST} to binary directory" - ) +target_link_libraries(${PROJECT_NAME} + corecvs + gtest + gtest_main + stdc++fs + ) -set_property(TARGET ${MODULE_NAME_TEST} PROPERTY CXX_STANDARD 17) -set_property(TARGET ${MODULE_NAME_TEST} PROPERTY CXX_STANDARD_REQUIRED ON) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) - -target_link_libraries(${MODULE_NAME_TEST} gtest gtest_main stdc++fs corecvs) -target_include_directories(${MODULE_NAME_TEST} PUBLIC ${corecvs_SOURCE_DIR}) +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${DIR_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) # For ctest support. Not necessary to use but nice move for automated testing. add_test( - NAME - core-test - COMMAND - ./${MODULE_NAME_TEST} -) - + NAME core-test + COMMAND ./$${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test-core/convexduality/main_test_convexduality.cpp b/test-core/convexduality/main_test_convexduality.cpp index e2b792e00..dc4a8dac1 100644 --- a/test-core/convexduality/main_test_convexduality.cpp +++ b/test-core/convexduality/main_test_convexduality.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include "gtest/gtest.h" #include "core/utils/global.h" diff --git a/test-core/mesh/main_test_mesh.cpp b/test-core/mesh/main_test_mesh.cpp index fbbf9f249..b7e6a7fbe 100644 --- a/test-core/mesh/main_test_mesh.cpp +++ b/test-core/mesh/main_test_mesh.cpp @@ -12,7 +12,7 @@ #include "gtest/gtest.h" #include "core/utils/global.h" -#include "core/geometry/mesh3DDecorated.h" +#include "core/geometry/mesh/mesh3DDecorated.h" using namespace std; using namespace corecvs; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 039561a6e..a6dd5a9a5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,33 +1,43 @@ - -set(TEST_SUBDIRECTORIES +set(SUBDIRECTORIES adoptcolor # depends on utils - avencode + autonavRW + avencode #command_harness - widget_harness example_scene + face_distortion fileloader + fftplayground flow_detector flowtest focus_stack gcodeplayground - mesh3dplayground grab24 grab24_qt - # jitplayground + #jitplayground + mesh3dplayground + #opencvpostcalib + #opencv_profile pattern_detector + #qtScriptConsole raytracerender reprojector #serialize1 softrender - face_distortion - autonavRW -) + #stereointerface + #vodometry + widget_harness + widgets_test + ) if (EIGEN_FOUND AND CERES_FOUND) - set(TEST_SUBDIRECTORIES ${TEST_SUBDIRECTORIES} ceres_playground) + set(SUBDIRECTORIES ${SUBDIRECTORIES} ceres_playground) +endif() + +if (SOAPYSDR_FOUND) + set(SUBDIRECTORIES ${SUBDIRECTORIES} sdrRecord) endif() -foreach(test_subdirectory ${TEST_SUBDIRECTORIES}) - message(STATUS "adding subdirectory test/${test_subdirectory}") - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${test_subdirectory}) -endforeach(test_subdirectory) +foreach(subdirectory ${SUBDIRECTORIES}) + message(STATUS "adding subdirectory/${subdirectory}") + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${subdirectory}) +endforeach(subdirectory) \ No newline at end of file diff --git a/test/adoptcolor/CMakeLists.txt b/test/adoptcolor/CMakeLists.txt index c9557c5a3..f34b9f082 100644 --- a/test/adoptcolor/CMakeLists.txt +++ b/test/adoptcolor/CMakeLists.txt @@ -1,33 +1,52 @@ -project (Adoptcolor) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME adoptcolor) - -set (FILELOADER_NAME adoptcolor ) - -set (SRC_FILES +set(SOURCE_FILE main_adoptcolor.cpp -) - -if (PNG_LIB) - message ("Adoptcolor would use LibPng") - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - message ("Adoptcolor would use LibJpeg") - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() + ) -add_executable(${FILELOADER_NAME} ${SRC_FILES} ${HDR_FILES}) +set(SOURCES + ${SOURCE_FILE} + ) -add_custom_command(TARGET ${FILELOADER_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${FILELOADER_NAME} ${CMAKE_BINARY_DIR}/bin/${FILELOADER_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${FILELOADER_NAME} to binary directory" - ) +assign_source_group(${SOURCES}) -include_directories(${INC_PATHS}) +add_executable(${PROJECT_NAME} + ${SOURCES} + ) +set(ADDITIONAL_LIBS) -target_link_libraries(${FILELOADER_NAME} ${LIBS} stdc++fs corecvs) +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper + ) + add_definitions(-DWITH_LIBPNG) +endif() +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() +target_link_libraries(${PROJECT_NAME} + PRIVATE + stdc++fs + corecvs + ${ADDITIONAL_LIBS} + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/test/adoptcolor/main_adoptcolor.cpp b/test/adoptcolor/main_adoptcolor.cpp index 59bcb4436..c86625025 100644 --- a/test/adoptcolor/main_adoptcolor.cpp +++ b/test/adoptcolor/main_adoptcolor.cpp @@ -1,10 +1,10 @@ #include -#include "core/buffers/bufferFactory.h" +#include "buffers/bufferFactory.h" -#include "core/fileformats/bmpLoader.h" -#include "core/geometry/ellipticalApproximation.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "fileformats/bmpLoader.h" +#include "geometry/ellipticalApproximation.h" +#include "buffers/rgb24/rgb24Buffer.h" #ifdef WITH_LIBJPEG #include "libjpegFileReader.h" diff --git a/test/autonavRW/CMakeLists.txt b/test/autonavRW/CMakeLists.txt index 9a8b79993..cb344be20 100644 --- a/test/autonavRW/CMakeLists.txt +++ b/test/autonavRW/CMakeLists.txt @@ -1,28 +1,52 @@ -project (Autonav_RW) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME autonavRW) -set (NAME autonav_RW) - -set (SRC_FILES +set(SOURCE_FILE main_autonavRW.cpp -) + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +set(SOURCES + ${SOURCE_FILE} + ) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +assign_source_group(${SOURCES}) -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" - ) +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -include_directories(${INC_PATHS}) +set(ADDITIONAL_LIBS) -target_link_libraries(${NAME} ${LIBS} stdc++fs corecvs) +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper + ) + add_definitions(-DWITH_LIBPNG) +endif() + +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() +target_link_libraries(${PROJECT_NAME} + PRIVATE + stdc++fs + corecvs + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/avencode/CMakeLists.txt b/test/avencode/CMakeLists.txt index adf213f2d..109e47169 100644 --- a/test/avencode/CMakeLists.txt +++ b/test/avencode/CMakeLists.txt @@ -1,26 +1,45 @@ -project (avencode) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME avencode) -set (MODULE_NAME avencode) - -set (SRC_FILES +set(SOURCE_FILE main_avencode.cpp -) - + ) -if(AVCODEC_LIBS) - message("Switching on avcodec support <${AVCODEC_LIBS}>") - include(../../wrappers/avcodec/sourcelist.cmake) -endif() +set(SOURCES + ${SOURCE_FILE} + ) -add_executable(${MODULE_NAME} ${SRC_FILES} ${HDR_FILES}) +assign_source_group(${SOURCES}) -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" - ) +add_executable(${PROJECT_NAME} + ${SOURCE_FILE} + ) -include_directories(${INC_PATHS}) +set(ADDITIONAL_LIBS) -target_link_libraries(${MODULE_NAME} ${LIBS} stdc++fs corecvs ) +if(AVCODEC_LIBS) + message("Switching on avcodec support <${AVCODEC_LIBS}>") + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + AVCODECwrapper + ) + add_definitions(-DWITH_AVCODEC -DWITH_SWSCALE) +endif() +target_link_libraries(${PROJECT_NAME} + PRIVATE + stdc++fs + corecvs + ${ADDITIONAL_LIBS} + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/test/ceres_playground/CMakeLists.txt b/test/ceres_playground/CMakeLists.txt index 4daaec6ba..81538ee4a 100644 --- a/test/ceres_playground/CMakeLists.txt +++ b/test/ceres_playground/CMakeLists.txt @@ -1,31 +1,53 @@ -project (ceres_playground) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME ceres_playground) - -set (NAME ceres_playground) - -set (SRC_FILES +set(SOURCE_FILE main_ceres_playground.cpp -) + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +set(SOURCES + ${SOURCE_FILE} + ) +assign_source_group(${SOURCES}) +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +set(ADDITIONAL_LIBS) -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) + add_definitions(-DWITH_LIBPNG) +endif() -include_directories(${INC_PATHS} ${EIGEN_INCLUDE_DIR} ${CERES_INCLUDE_DIR}) - -target_link_libraries(${NAME} ${LIBS} ceres stdc++fs corecvs) +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() +target_link_libraries(${PROJECT_NAME} + PRIVATE + stdc++fs + ceres + corecvs + ${ADDITIONAL_LIBS} + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/test/command_harness/CMakeLists.txt b/test/command_harness/CMakeLists.txt index acc5042b9..cfcb45e12 100644 --- a/test/command_harness/CMakeLists.txt +++ b/test/command_harness/CMakeLists.txt @@ -1,29 +1,51 @@ -project (command_harness) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME command_harness) +set(SOURCE_FILE + main_command_harness.cpp + ) -set (NAME command_harness) +#set(EXTERNAL_SOURCE_FILES +# ../widgets_test/main_widgets_test.cpp +# ../widgets_test/testNativeWidget.cpp +# ) -set (SRC_FILES - main_command_harness.cpp -) +set(SOURCES + ${SOURCE_FILE} +# ${EXTERNAL_SOURCE_FILES} + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +set(ADDITIONAL_LIBS) -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" +if (PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) +endif() -include_directories(${INC_PATHS}) - -target_link_libraries(${NAME} ${LIBS} cvs_utils stdc++fs corecvs) +if (JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) +endif() +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs + corecvs_utils + pthread + stdc++fs + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/test/command_harness/main_command_harness.cpp b/test/command_harness/main_command_harness.cpp index d8888fcce..15e715dde 100644 --- a/test/command_harness/main_command_harness.cpp +++ b/test/command_harness/main_command_harness.cpp @@ -15,8 +15,8 @@ #include "testClass.h" #endif -#include "qtFileLoader.h" -#include "reflectionWidget.h" +#include "fileformats/qtFileLoader.h" +#include "corestructs/reflectionWidget.h" #include "core/xml/generated/axisAlignedBoxParameters.h" #include "core/xml/generated/chessBoardAssemblerParamsBase.h" #include "core/xml/generated/checkerboardDetectionParameters.h" @@ -26,8 +26,8 @@ //#include "iterativeReconstructionNonlinearOptimizationParamsWrapper.h" #include "core/math/vector/vector2d.h" -#include "changeReceiver.h" -#include "testNativeWidget.h" +#include "../widget_harness/changeReceiver.h" +#include "../widgets_test/testNativeWidget.h" #include "core/math/matrix/homographyReconstructor.h" #include "core/rectification/sceneStereoAlignerBlock.h" diff --git a/test/example_scene/CMakeLists.txt b/test/example_scene/CMakeLists.txt index 899257983..368cb374e 100644 --- a/test/example_scene/CMakeLists.txt +++ b/test/example_scene/CMakeLists.txt @@ -1,32 +1,65 @@ -project (ExampleScene) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME example_scene) +find_package(Qt5 REQUIRED COMPONENTS Xml) -set (NAME example_scene ) +set(PRIVATE_HEADER_FILE + main_example_scene.h + ) + +set(HEADERS + ${PRIVATE_HEADER_FILE} + ) -set (SRC_FILES +set(SOURCE_FILE main_example_scene.cpp -) + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +set(SOURCES + ${SOURCE_FILE} + ) -include(../../wrappers/jsonmodern/sourcelist.cmake) +assign_source_group(${HEADERS} ${SOURCES}) +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +set(ADDITIONAL_LIBS) -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) + add_definitions(-DWITH_LIBPNG) +endif() + +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() -include_directories(${INC_PATHS}) +target_link_libraries(${PROJECT_NAME} + PRIVATE + stdc++fs + corecvs + corecvs_utils + Qt5::Xml + ${ADDITIONAL_LIBS} + ) -target_link_libraries(${NAME} ${LIBS} cvs_utils stdc++fs corecvs) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/example_scene/main_example_scene.cpp b/test/example_scene/main_example_scene.cpp index c26ff28bb..abd276fea 100644 --- a/test/example_scene/main_example_scene.cpp +++ b/test/example_scene/main_example_scene.cpp @@ -19,11 +19,11 @@ #include "core/cameracalibration/ilFormat.h" #include "core/math/vector/vector3d.h" -#include "xmlSetter.h" -#include "xmlGetter.h" +#include "visitors/xmlSetter.h" +#include "visitors/xmlGetter.h" -#include "jsonGetter.h" -#include "jsonSetter.h" +#include "visitors/jsonGetter.h" +#include "visitors/jsonSetter.h" #include "core/reflection/jsonPrinter.h" #include "core/geometry/mesh/mesh3d.h" diff --git a/test/face_distortion/CMakeLists.txt b/test/face_distortion/CMakeLists.txt index 97debaf07..311ce1461 100644 --- a/test/face_distortion/CMakeLists.txt +++ b/test/face_distortion/CMakeLists.txt @@ -1,29 +1,52 @@ -project (face_undistortion) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME face_distortion) +set(SOURCE_FILE + main_face_undistortion.cpp + ) -set (NAME face_undistortion) +set(SOURCES + ${SOURCE_FILE} + ) -set (SRC_FILES - main_face_undistortion.cpp -) +assign_source_group(${SOURCES}) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +set(ADDITIONAL_LIBS) -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${PROJECT_NAME} to binary directory" +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) + add_definitions(-DWITH_LIBPNG) +endif() -include_directories(${INC_PATHS}) - -target_link_libraries(${NAME} ${LIBS} stdc++fs corecvs) +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() +target_link_libraries(${PROJECT_NAME} + PRIVATE + stdc++fs + corecvs + ${ADDITIONAL_LIBS} + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/test/face_distortion/main_face_undistortion.cpp b/test/face_distortion/main_face_undistortion.cpp index 0ddd64be1..46a55c573 100644 --- a/test/face_distortion/main_face_undistortion.cpp +++ b/test/face_distortion/main_face_undistortion.cpp @@ -1,10 +1,10 @@ #include -#include "core/reflection/commandLineSetter.h" -#include "core/buffers/bufferFactory.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/rgb24/abstractPainter.h" +#include "reflection/commandLineSetter.h" +#include "buffers/bufferFactory.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/abstractPainter.h" #ifdef WITH_LIBJPEG diff --git a/test/face_distortion/main_fileloader.cpp b/test/face_distortion/main_fileloader.cpp index 9f53afbf8..ef5957219 100644 --- a/test/face_distortion/main_fileloader.cpp +++ b/test/face_distortion/main_fileloader.cpp @@ -1,11 +1,11 @@ #include -#include "core/reflection/commandLineSetter.h" -#include "core/buffers/bufferFactory.h" -#include "core/fileformats/bmpLoader.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/rgb24/abstractPainter.h" +#include "reflection/commandLineSetter.h" +#include "buffers/bufferFactory.h" +#include "fileformats/bmpLoader.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/abstractPainter.h" #ifdef WITH_LIBJPEG #include "libjpegFileReader.h" diff --git a/test/fftplayground/CMakeLists.txt b/test/fftplayground/CMakeLists.txt new file mode 100644 index 000000000..b486f0a32 --- /dev/null +++ b/test/fftplayground/CMakeLists.txt @@ -0,0 +1,61 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME fftplayground) + +set(SOURCE_FILE + main_fftplayground.cpp + ) + +set(SOURCES + ${SOURCE_FILE} + ) + +assign_source_group(${SOURCES}) + +add_executable(${PROJECT_NAME} + ${SOURCES} + ) + +set(ADDITIONAL_LIBS) + +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper + ) + add_definitions(-DWITH_LIBPNG) +endif() + +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() + +if (FFTW_LIBRARIES) + message ("fftplayground would use FFTW") + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + FFTW::FFTW + ) + add_definitions(-DWITH_FFTW) +endif() + +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs + pthread + ${ADDITIONAL_LIBS} + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/test/fftplayground/main_fftplayground.cpp b/test/fftplayground/main_fftplayground.cpp new file mode 100644 index 000000000..bc3898dab --- /dev/null +++ b/test/fftplayground/main_fftplayground.cpp @@ -0,0 +1,312 @@ +#include + +#include "core/reflection/commandLineSetter.h" +#include +#include + +#ifdef WITH_FFTW +#include +#endif +#ifdef WITH_LIBPNG +#include "libpngFileReader.h" +#endif + +using namespace std; +using namespace corecvs; + +void drawFFT(int window_size, vector> &data, std::string name) +{ + float *avg = new float[window_size]; + for(int j = 0; j < window_size; j++) + { + avg[j] = 0; + } + +#ifdef WITH_FFTW + fftw_complex *in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * window_size); + fftw_complex *out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * window_size); + + for (size_t i = 0; i + window_size < data.size(); i += window_size) + { + /* Don't want to use memcpy here so far, for more control*/ + for(int j = 0; j < window_size; j++) + { + in[j][0] = data[i+j].real(); + in[j][1] = data[i+j].imag(); + } + + fftw_plan pf; + pf = fftw_plan_dft_1d(window_size, in, out, FFTW_FORWARD, FFTW_ESTIMATE); + fftw_execute(pf); + fftw_destroy_plan(pf); + + for(int j = 0; j < window_size; j++) + { + avg[j] += out[j][0] * out[j][0] + out[j][1] * out[j][1]; + } + } +#endif + + int dscale = window_size / 1024; + float vscale = 0; + + for(int j = 0; j < window_size; j++) + { + if (avg[j] > vscale) vscale = avg[j]; + } + if (vscale == 0) vscale = 1; + vscale = 3000.0; + cout << "vscale :" << vscale << endl; + + RGB24Buffer *fftShow = new RGB24Buffer(1000, 1024); + + for(int j = 0; j < fftShow->w; j ++) + { + double value = 0; + for (int k = 0; k < dscale; k++) + { + value += avg[j * dscale + k]; + } + value /= dscale; + + //cout << j << " " << avg[j] << endl ; + int y0 = fftShow->h - 1 - (value / vscale); + + fftShow->drawVLine(j, fftShow->h - 1, y0, RGBColor::Red()); + } + BufferFactory::getInstance()->saveRGB24Bitmap(fftShow, name); + + deletearr_safe(avg); +} + + +int main (int argC, char **argV) +{ + CommandLineSetter s(argC, argV); + +#ifdef WITH_LIBPNG + LibpngFileReader::registerMyself(); + LibpngRuntimeTypeBufferLoader::registerMyself(); + LibpngFileSaver::registerMyself(); + SYNC_PRINT(("Libpng support on\n")); +#endif + + PreciseTimer timer; + + std::string input = "samples.bin"; + + if (s.nonPrefix().size() > 1) + { + input = s.nonPrefix()[1]; + } + + SYNC_PRINT(("Starting fftplayground for %s\n", input.c_str())); + + ifstream file; + file.open(input, ios::in | ios::binary); + if (file.fail()) + { + SYNC_PRINT(("Can't open input file <%s>\n", input.c_str())); + return 1; + } + SYNC_PRINT(("Opened input file <%s> will load %d byte datasamples\n", input.c_str(), (int)sizeof(float))); + + vector> data; + + file.seekg(0, std::ios::end); + size_t num_elements = file.tellg() / sizeof(std::complex); + file.seekg(0, std::ios::beg); + data.reserve(num_elements); + + for(int i = 0; !file.eof(); i++) + { + float re = 0.0; + float im = 0.0; + file.read((char *)&re, sizeof (float)); + file.read((char *)&im, sizeof (float)); + //cout << "Loaded: " << data.size() << " " << re << " + " << im << "i" << endl; + data.emplace_back(re, im); + } + float sampleFreq = 10e6f; + float samples = (float)data.size(); + float dataTime = samples / sampleFreq; + + /* NTSC */ + float frameRate = 30.0 / 1.001; + float scanLinesPerField = 262.5; + float scanLines = 525; + float visibleScanlines = 486; + + float samplesPerFrame = sampleFreq / frameRate; + + + SYNC_PRINT(("Loaded %d samples\n", (int)data.size())); + SYNC_PRINT((" This is %f seconds\n", dataTime)); + SYNC_PRINT((" We expect per frame %f samples\n", samplesPerFrame)); + + + + file.close(); + + + + int window_size = 4 * 1024 * 1024; + + /** + * Shift data to center. + * + * For more information see http://www.fftw.org/faq/section3.html#centerorigin + **/ + for(size_t i = 0; i < data.size(); i++) + { + if (i % 2) { + data[i].real(-data[i].real()); + data[i].imag(-data[i].imag()); + } + } + +#ifdef WITH_FFTW + + fftw_complex *in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * window_size); + fftw_complex *out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * window_size); + + fftw_complex *freq = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * window_size); + + fftw_complex *sync = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * window_size); + fftw_complex *filtered = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * window_size); + + drawFFT(window_size, data, "prefilter.png"); + + + for (int i = 0; i + window_size < data.size(); i += window_size) + { + /* Don't want to use memcpy here so far, for more control*/ + for(int j = 0; j < window_size; j++) + { + in[j][0] = data[i+j].real(); + in[j][1] = data[i+j].imag(); + } + + fftw_plan pf; + pf = fftw_plan_dft_1d(window_size, in, out, FFTW_FORWARD, FFTW_ESTIMATE); + fftw_execute(pf); + fftw_destroy_plan(pf); + + /* Filter. Don't want to think of anything more complicated */ + /* First delete the aliasing artifact from capute*/ + out[window_size / 2][0] = 0; + out[window_size / 2][1] = 0; + + + /* Seems like leftmost peak is a nice feature to get h-sync*/ + + /* Prepare data */ + + int shift = 2 * 1024 * 700; + int swindow = 2 * 1024 * 122; + + for(int j = 0; j < swindow; j++) + { + freq[j][0] = out[j + shift][0]; + freq[j][1] = out[j + shift][1]; + } + + for(int j = swindow; j < window_size; j++) + { + freq[j][0] = 0; + freq[j][1] = 0; + } + + + fftw_plan pb; + pb = fftw_plan_dft_1d(window_size, freq, filtered, FFTW_BACKWARD, FFTW_ESTIMATE); + fftw_execute(pb); + fftw_destroy_plan(pb); + + for(int j = 0; j < window_size; j++) + { + data[i+j].real(filtered[j][0] / window_size); + data[i+j].imag(filtered[j][1] / window_size); + } + } + fftw_free(in); + fftw_free(out); + fftw_free(sync); + fftw_free(filtered); + + drawFFT(window_size, data, "postfilter.png"); + +#endif + + RGB24Buffer *sliceGraph = new RGB24Buffer(500, 4000, RGBColor::White()); + for (int i = 1; i < sliceGraph->w && i < data.size(); i++) + { + double value0 = data[i - 1].imag() * data[i - 1].imag() + data[i - 1].real() * data[i - 1].real(); + double value1 = data[i ].imag() * data[i ].imag() + data[i ].real() * data[i ].real(); + + value0 = sqrt(value0); + value1 = sqrt(value1); + + value0 *= 4000; + value1 *= 4000; + + sliceGraph->drawLine( i - 1, sliceGraph->h - 1 - (int)value0, + i , sliceGraph->h - 1 - (int)value1, + RGBColor::Blue()); + } + BufferFactory::getInstance()->saveRGB24Bitmap(sliceGraph, "osciloscope.png"); + + + + int perframe = 333666; + int width = perframe / scanLines; + RGB24Buffer *syncShow = new RGB24Buffer(scanLines, width, RGBColor::White()); + float scale = 1.00088; + int startOffset = width * 201.15; + + + for(int i = 0; i < syncShow->h; i++) + { + for(int j = 0; j < syncShow->w; j++) + { + int offset = (i * syncShow->w + j) * scale + startOffset; + if (offset >= data.size()) + { + syncShow->element(i,j) = RGBColor::Green(); + continue; + } + + float re = data[offset].real() * 4000.0; + float im = data[offset].imag() * 4000.0; + + Vector3df color; + color[0] = 255.0 - sqrt((re * re) + (im * im)); + color[1] = color[0]; + color[2] = color[0]; + + syncShow->element(i,j) = RGBColor::FromFloat(color); + + } + } + BufferFactory::getInstance()->saveRGB24Bitmap(syncShow, "sync.png"); + + RGB24Buffer *deinterlace = new RGB24Buffer(scanLines, width, RGBColor::White()); + for(int i = 0; i < deinterlace->h; i++) + { + for(int j = 0; j < deinterlace->w; j++) + { + int h = i / 2; + if (i % 2) { + h += scanLines / 2; + } + deinterlace->element(i,j) = syncShow->element(h, j); + + } + } + + BufferFactory::getInstance()->saveRGB24Bitmap(deinterlace, "deint.png"); + + + return 0; +} + diff --git a/test/fileloader/CMakeLists.txt b/test/fileloader/CMakeLists.txt index 0af6291d0..983cc4f48 100644 --- a/test/fileloader/CMakeLists.txt +++ b/test/fileloader/CMakeLists.txt @@ -1,29 +1,52 @@ -project (Fileloader) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME fileloader) +set(SOURCE_FILE + main_fileloader.cpp + ) -set (NAME fileloader ) +set(SOURCES + ${SOURCE_FILE} + ) -set (SRC_FILES - main_fileloader.cpp -) +assign_source_group(${SOURCES}) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +set(ADDITIONAL_LIBS) -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) + add_definitions(-DWITH_LIBPNG) +endif() -include_directories(${INC_PATHS}) - -target_link_libraries(${NAME} ${LIBS} stdc++fs corecvs) +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() +target_link_libraries(${PROJECT_NAME} + PRIVATE + stdc++fs + corecvs + ${ADDITIONAL_LIBS} + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/test/flow_detector/CMakeLists.txt b/test/flow_detector/CMakeLists.txt index 96adb3c22..380ad7cf7 100644 --- a/test/flow_detector/CMakeLists.txt +++ b/test/flow_detector/CMakeLists.txt @@ -1,50 +1,70 @@ -project (FlowDetector) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME flow_detector) - -set (NAME flow_detector ) - -set (SRC_FILES +set(SOURCE_FILE main_flow_detector.cpp -) - -#set (SOURCES ${SOURCES} ${JSON_MODERN_HEADERS} ${JSON_MODERN_SOURCES}) + ) -#add_definitions( -DWITH_JSONMODERN ) -#include_directories(${JSON_MODERN_INCLUDES}) -#message(STATUS FlowDetector:${JSON_MODERN_INCLUDES} ) +set(SOURCES + ${SOURCE_FILE} + ) +assign_source_group(${SOURCES}) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -include(../../wrappers/jsonmodern/sourcelist.cmake) - -if (OpenCV_LIBS) -include(../../wrappers/opencv/sourcelist.cmake) -endif() +set(ADDITIONAL_LIBS) if(AVCODEC_LIBS) message("Switching on avcodec support <${AVCODEC_LIBS}>") - include(../../wrappers/avcodec/sourcelist.cmake) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + AVCODECwrapper + ) + add_definitions(-DWITH_AVCODEC -DWITH_SWSCALE) endif() - -#message(STATUS FlowDetector:${INCLUDEPATHS} ) - -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) - -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) + add_definitions(-DWITH_LIBPNG) +endif() -include_directories(${INC_PATHS}) +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() -target_link_libraries(${NAME} corecvs pthread ${LIBS}) +if (OpenCV_LIBS) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + OPENCVwrapper + ) +endif() +target_link_libraries(${PROJECT_NAME} + PRIVATE + stdc++fs + corecvs + pthread + JSONMODERNwrapper + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/flow_detector/main_flow_detector.cpp b/test/flow_detector/main_flow_detector.cpp index 8121f9303..b2cd7a34e 100644 --- a/test/flow_detector/main_flow_detector.cpp +++ b/test/flow_detector/main_flow_detector.cpp @@ -1,18 +1,18 @@ #include -#include -#include -#include +#include +#include +#include -#include +#include -#include +#include -#include "core/stereointerface/processor6D.h" +#include "stereointerface/processor6D.h" -#include "core/buffers/bufferFactory.h" -#include "core/fileformats/bmpLoader.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "buffers/bufferFactory.h" +#include "fileformats/bmpLoader.h" +#include "buffers/rgb24/rgb24Buffer.h" #ifdef WITH_LIBJPEG #include "libjpegFileReader.h" @@ -22,10 +22,10 @@ #endif #ifdef WITH_OPENCV #include -#include +#include #endif #ifdef WITH_DISFLOW -#include +#include #endif #ifdef WITH_AVCODEC #include "aviCapture.h" diff --git a/test/flowtest/CMakeLists.txt b/test/flowtest/CMakeLists.txt index 7cdba1325..598c78b2d 100644 --- a/test/flowtest/CMakeLists.txt +++ b/test/flowtest/CMakeLists.txt @@ -1,25 +1,43 @@ -project (Flowtest) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME flowtest) -set (NAME flowtest ) - -set (SRC_FILES +set(SOURCE_FILE main_flowtest.cpp -) + ) -if (OpenCV_LIBS) -include(../../wrappers/opencv/sourcelist.cmake) -endif() +set(SOURCES + ${SOURCE_FILE} + ) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) - -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" - ) - -target_link_libraries(${NAME} stdc++fs -pthread corecvs ${LIBS}) +assign_source_group(${SOURCES}) +add_executable(${PROJECT_NAME} + ${SOURCES} + ) +set(ADDITIONAL_LIBS) +if (OpenCV_LIBS) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + OPENCVwrapper + ) +endif() +target_link_libraries(${PROJECT_NAME} + PRIVATE + stdc++fs + corecvs + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/focus_stack/CMakeLists.txt b/test/focus_stack/CMakeLists.txt index c2f11a4de..7c75c3160 100644 --- a/test/focus_stack/CMakeLists.txt +++ b/test/focus_stack/CMakeLists.txt @@ -1,36 +1,62 @@ -project (FocusStack) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME focus_stack) -set (NAME focus_stack ) - -set (SRC_FILES - imageStack.cpp - laplacianStacking.cpp - main.cpp -) - -set (HDR_FILES +set(PRIVATE_HEADER_FILES fsAlgorithm.h imageStack.h laplacianStacking.h -) + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() +set(HEADERS + ${PRIVATE_HEADER_FILES} + ) -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +set(SOURCE_FILES + imageStack.cpp + laplacianStacking.cpp + main.cpp + ) + +set(SOURCES + ${SOURCE_FILES} + ) +assign_source_group(${HEADERS} ${SOURCES}) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" +set(ADDITIONAL_LIBS) + +if (PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + PNGwrapper ) +endif() -include_directories(${INC_PATHS}) +if (JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) +endif() -target_link_libraries(${NAME} ${LIBS} stdc++fs corecvs) +target_link_libraries(${PROJECT_NAME} + stdc++fs + corecvs + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/gcodeplayground/CMakeLists.txt b/test/gcodeplayground/CMakeLists.txt index 0d84b383a..9cd976032 100644 --- a/test/gcodeplayground/CMakeLists.txt +++ b/test/gcodeplayground/CMakeLists.txt @@ -1,34 +1,60 @@ -project (Gcodeplayground) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME gcodeplayground) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() +set(PRIVATE_HEADER_FILES + labelGcodeInterpreter.h + ) -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +set(HEADERS + ${PRIVATE_HEADER_FILES} + ) +set(SOURCE_FILES + labelGcodeInterpreter.cpp + main_gcodeplayground.cpp + ) -set (NAME gcodeplayground ) +set(SOURCES + ${SOURCE_FILES} + ) -set (SRC_FILES ${SRC_FILES} - labelGcodeInterpreter.cpp - main_gcodeplayground.cpp -) +assign_source_group(${HEADERS} ${SOURCES}) -set (HDR_FILES ${HDR_FILES} - labelGcodeInterpreter.h -) +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +set(ADDITIONAL_LIBS) -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" +if (PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + PNGwrapper ) +endif() -include_directories(${INC_PATHS}) - -target_link_libraries(${NAME} ${LIBS} corecvs pthread) +if (JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) +endif() +target_link_libraries(${PROJECT_NAME} + PRIVATE + pthread + corecvs + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/grab24/CMakeLists.txt b/test/grab24/CMakeLists.txt index 6c5ecb56e..a1e32f51f 100644 --- a/test/grab24/CMakeLists.txt +++ b/test/grab24/CMakeLists.txt @@ -1,20 +1,34 @@ -project (Grab24) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME grab24) +set(SOURCE_FILE + main_grab24.cpp + ) -set (NAME grab24 ) +set(SOURCES + ${SOURCE_FILE} + ) -set (SRC_FILES - main_grab24.cpp -) +assign_source_group(${SOURCES}) -add_executable(${NAME} ${SRC_FILES}) +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" - ) +target_link_libraries(${PROJECT_NAME} + corecvs + corecvs_utils + pthread + V4L2wrapper + ) -target_link_libraries(${NAME} cvs_utils corecvs pthread ${LIBS}) -target_include_directories(${NAME} PUBLIC ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR} .) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/grab24_qt/CMakeLists.txt b/test/grab24_qt/CMakeLists.txt index f1423d39d..a9b6956bf 100644 --- a/test/grab24_qt/CMakeLists.txt +++ b/test/grab24_qt/CMakeLists.txt @@ -1,30 +1,50 @@ -project (Grab24_qt) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME grab24_qt) +find_package(Qt5 REQUIRED COMPONENTS Widgets Gui) -set (NAME grab24_qt ) - -set(CMAKE_INCLUDE_CURRENT_DIR "YES") -set(CMAKE_AUTOMOC "YES") -set(CMAKE_AUTORCC "YES") - -find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets) - -set (SRC_FILES - main_grab24_qt.cpp -) - -set (HDR_FILES +set(PRIVATE_HEADER_FILE main_grab24_qt.h -) - -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) - -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" - ) - -target_link_libraries(${NAME} cvs_utils corecvs pthread ${LIBS}) -target_include_directories(${NAME} PUBLIC ${corecvs_SOURCE_DIR} ${cvs_utils_SOURCE_DIR}) - + ) + +set(HEADERS + ${PRIVATE_HEADER_FILE} + ) + +set(SOURCE_FILE + main_grab24_qt.cpp + ) + +set(SOURCES + ${SOURCE_FILE} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) + +target_link_libraries(${PROJECT_NAME} + corecvs_utils + pthread + corecvs + Qt5::Widgets + Qt5::Gui + V4L2wrapper + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + AUTOMOC TRUE + AUTOUIC TRUE + AUTORCC TRUE + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/grab24_qt/main_grab24_qt.cpp b/test/grab24_qt/main_grab24_qt.cpp index 344a291b0..bfeea1c04 100644 --- a/test/grab24_qt/main_grab24_qt.cpp +++ b/test/grab24_qt/main_grab24_qt.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -11,9 +12,9 @@ #include "core/utils/global.h" #include "core/fileformats/bmpLoader.h" #include "V4L2Capture.h" -#include "g12Image.h" -#include "imageCaptureInterfaceQt.h" -#include "advancedImageWidget.h" +#include "corestructs/g12Image.h" +#include "framesources/imageCaptureInterfaceQt.h" +#include "uis/advancedImageWidget.h" int main (int argc, char **argv) @@ -23,11 +24,11 @@ int main (int argc, char **argv) Q_INIT_RESOURCE(main); CommandLineSetter s(argc, argv); - /*if (s.hasOption("caps")) + if (s.hasOption("caps")) { - ImageCaptureInterfaceQtFactory:: + ImageCaptureInterfaceQtFactory::printCaps(); return 0; - }*/ + } std::string inputString = s.getString("input", "v4l2:/dev/video0:1/10"); @@ -52,7 +53,7 @@ int main (int argc, char **argv) if (returnCode == ImageCaptureInterface::FAILURE) { - SYNC_PRINT(("Can't open\n")); + SYNC_PRINT(("Can't open capture device <%s>\n", inputString.c_str())); return 1; } @@ -79,6 +80,11 @@ int main (int argc, char **argv) AdvancedImageWidget widget; widget.show(); + + CapSettingsDialog capSettings; + capSettings.show(); + capSettings.setCaptureInterface(rawInput); + processor.widget = &widget; diff --git a/test/grab24_qt/main_grab24_qt.h b/test/grab24_qt/main_grab24_qt.h index c99f28225..f18cadf86 100644 --- a/test/grab24_qt/main_grab24_qt.h +++ b/test/grab24_qt/main_grab24_qt.h @@ -2,7 +2,7 @@ #define MAIN_GRAB24_H_ #include -#include +#include class AdvancedImageWidget; diff --git a/test/jitplayground/main_jitplayground.cpp b/test/jitplayground/main_jitplayground.cpp index 04b3b395a..9ea978fb4 100644 --- a/test/jitplayground/main_jitplayground.cpp +++ b/test/jitplayground/main_jitplayground.cpp @@ -8,7 +8,7 @@ #include "core/camerafixture/fixtureScene.h" #include "core/camerafixture/cameraFixture.h" #include "core/cameracalibration/calibrationDrawHelpers.h" -#include "core/geometry/mesh3d.h" +#include "core/geometry/mesh/mesh3d.h" #include "reprojectionCostFunction.h" #include "core/meta/astNode.h" diff --git a/test/mesh3dplayground/CMakeLists.txt b/test/mesh3dplayground/CMakeLists.txt index 24544b297..01a4721f3 100644 --- a/test/mesh3dplayground/CMakeLists.txt +++ b/test/mesh3dplayground/CMakeLists.txt @@ -1,25 +1,46 @@ -project (mesh3dplayground) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME mesh3dplayground) -set (SRC_FILES +set(SOURCE_FILE main_mesh3dplayground.cpp -) + ) -set (HDR_FILES -) +set(SOURCES + ${SOURCE_FILE} + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() +assign_source_group(${SOURCES}) -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -set (NAME mesh3dplayground ) +set(ADDITIONAL_LIBS) +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper + ) + add_definitions(-DWITH_LIBPNG) +endif() -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) -include_directories(${INC_PATHS}) +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() -target_link_libraries(${NAME} ${LIBS} corecvs pthread) +target_link_libraries(${PROJECT_NAME} + pthread + corecvs + ${ADDITIONAL_LIBS} + ) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/test/mesh3dplayground/main_mesh3dplayground.cpp b/test/mesh3dplayground/main_mesh3dplayground.cpp index 27e8a7cda..f3bc5b1f9 100644 --- a/test/mesh3dplayground/main_mesh3dplayground.cpp +++ b/test/mesh3dplayground/main_mesh3dplayground.cpp @@ -3,12 +3,16 @@ #include "core/reflection/commandLineSetter.h" #include "core/fileformats/meshLoader.h" #include "core/fileformats/plyLoader.h" +#include "core/utils/utils.h" + #ifdef WITH_LIBPNG #include "libpngFileReader.h" #endif using namespace corecvs; +using namespace std; + int main (int argc, char **argv) { @@ -20,21 +24,67 @@ int main (int argc, char **argv) CommandLineSetter s(argc, argv); + if (s.hasOption("debug")) + { + Mesh3D mesh; + mesh.switchColor(); + mesh.setColor(RGBColor::Gray()); + mesh.addPoint(Vector3dd::Zero()); + + mesh.setColor(RGBColor::Red()); + mesh.addPoint(Vector3dd::OrtX()); + + mesh.setColor(RGBColor::Green()); + mesh.addPoint(Vector3dd::OrtY()); + + mesh.setColor(RGBColor::Blue()); + mesh.addPoint(Vector3dd::OrtZ()); + + PLYLoader saver; + ofstream file; + file.open("debug.ply", ios::out); + if (file.fail()) + { + SYNC_PRINT(("Can't open mesh file for writing\n")); + return 1; + } + saver.savePLY(file, mesh, PLYLoader::PlyFormat::BINARY_LITTLE_ENDIAN, true, true); + return 0; + } + vector nonPrefix = s.nonPrefix(); if (nonPrefix.size() <= 1) { SYNC_PRINT(("Usage: \n")); - SYNC_PRINT(("mesh3dplayground \n")); + SYNC_PRINT(("mesh3dplayground [--trace] [--decoration=] [--dump] [--nocenter] [--double]\n")); + SYNC_PRINT(("\n")); + SYNC_PRINT(("\tDecoration:\n")); + SYNC_PRINT(("\t 0 - cubes of [--size=]\n")); + SYNC_PRINT(("\t 1 - do nothing just dry run \n")); + SYNC_PRINT(("\n")); + SYNC_PRINT(("Unsigned size: %d\n", (int)sizeof(unsigned int))); + return 1; } + string meshName = nonPrefix[1]; - Mesh3D mesh; + bool trace = s.hasOption("trace"); + if (trace) { + SYNC_PRINT(("Switching trace on.\n")); + } + + Mesh3D mesh; mesh.switchColor(); - bool result = MeshLoader().load(&mesh, meshName); + bool result = false; + + MeshLoader loader; + loader.trace = trace; + result = loader.load(&mesh, meshName); if (!result) { SYNC_PRINT(("Unable to load <%s>\n", meshName.c_str())); return 2; } + if (!mesh.hasColor) { SYNC_PRINT(("Mesh has no color\n")); return 3; @@ -43,12 +93,61 @@ int main (int argc, char **argv) SYNC_PRINT(("Loaded <%s>\n", meshName.c_str())); mesh.dumpInfo(); + + if (s.hasOption("dump")) + { + SYNC_PRINT(("Dumping input")); + for (size_t i = 0; i < mesh.vertexes.size(); i++) + { + cout << mesh.vertexes[i] << " "; + if (mesh.hasColor) { + cout << mesh.vertexesColor[i] << " "; + } + cout << endl; + } + return 0; + } + + if (!s.hasOption("nocenter")) + { + Vector3dd center = Vector3dd::Zero(); + for (size_t i = 0; i < mesh.vertexes.size(); i++) + { + center += mesh.vertexes[i]; + } + if (mesh.vertexes.size() != 0) + { + center /= mesh.vertexes.size(); + } + + SYNC_PRINT(("Center is [%lf %lf %lf] shifting it to zero\n", center.x(), center.y(), center.z())); + for (size_t i = 0; i < mesh.vertexes.size(); i++) + { + mesh.vertexes[i] -= center; + } + } + Mesh3D meshExtended; meshExtended.switchColor(); double tsize = s.getDouble("size", 0.01 * 2/3 * 0.5); - SYNC_PRINT(("Adding triangle for each of the %d vertexes\n", (int)mesh.vertexes.size())); - for (size_t i = 0; i < mesh.vertexes.size(); i++) + + int decoration = s.getInt("decoration", 0); + + const char *decNames[] = {"box", "none"}; + + if (decoration < 0) decoration = 0; + if (decoration >= CORE_COUNT_OF(decNames)) { + decoration = CORE_COUNT_OF(decNames) - 1; + } + + int limitPoints = s.getInt("limit", -1); + if (limitPoints < 0) limitPoints = mesh.vertexes.size(); + + + SYNC_PRINT(("Adding <%s> for each of the %d vertexes of size %lf\n", decNames[decoration], (int)mesh.vertexes.size(), tsize)); + SYNC_PRINT(("We limit ourselfs to %d points\n", limitPoints)); + for (size_t i = 0; i < mesh.vertexes.size() && i < limitPoints; i++) { Vector3dd v = mesh.vertexes[i]; RGBColor color = mesh.vertexesColor[i]; @@ -61,12 +160,35 @@ int main (int argc, char **argv) v + (Vector3dd(0,1,0) - center)* tsize, v + (Vector3dd(0,0,1) - center)* tsize );*/ - meshExtended.addAOB(v - Vector3dd(1,1,1) * tsize, v + Vector3dd(1,1,1) * tsize); + switch (decoration) { + case 0: meshExtended.addAOB(v - Vector3dd(1,1,1) * tsize, v + Vector3dd(1,1,1) * tsize); break; + default: + case 1: meshExtended.addPoint(v); break; + } + } + + std::string baseName = HelperUtils::getFullPathWithoutExt(meshName); + std::string outName = baseName + "-out.ply"; + + bool storeDouble = s.hasOption("double"); + + if (!storeDouble) { + MeshLoader saver; + saver.binary = true; + saver.save(&meshExtended, outName); + } else { + PLYLoader saver; + ofstream file; + file.open(outName, ios::out); + if (file.fail()) + { + SYNC_PRINT(("Can't open mesh file for writing\n")); + return 1; + } + saver.savePLY(file, meshExtended, PLYLoader::PlyFormat::BINARY_LITTLE_ENDIAN, true, true); } - MeshLoader saver; - saver.binary = true; - saver.save(&meshExtended, "out.ply"); + meshExtended.dumpInfo(); return 0; } diff --git a/test/opencvpostcalib/main.cpp b/test/opencvpostcalib/main.cpp index e859a43a5..5d6637fe3 100644 --- a/test/opencvpostcalib/main.cpp +++ b/test/opencvpostcalib/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include "core/buffers/bufferFactory.h" #include "core/fileformats/bmpLoader.h" #include "core/buffers/rgb24/rgb24Buffer.h" diff --git a/test/pattern_detector/CMakeLists.txt b/test/pattern_detector/CMakeLists.txt index 4577e11e1..861a501a9 100644 --- a/test/pattern_detector/CMakeLists.txt +++ b/test/pattern_detector/CMakeLists.txt @@ -1,43 +1,67 @@ -project (PatternDetector) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME pattern_detector) -set (NAME pattern_detector ) +set(SOURCE_FILE + main_pattern_detector.cpp + ) -set (SRC_FILES - main_pattern_detector.cpp -) +set(SOURCES + ${SOURCE_FILE} + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +assign_source_group(${SOURCES}) -include(../../wrappers/jsonmodern/sourcelist.cmake) +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -if (OpenCV_LIBS) -include(../../wrappers/opencv/sourcelist.cmake) -endif() +set(ADDITIONAL_LIBS) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) - -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) + add_definitions(-DWITH_LIBPNG) +endif() -include_directories(${INC_PATHS}) +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() +if (OpenCV_LIBS) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + OPENCVwrapper + ) +endif() if (APRILTAG_FOUND) - target_link_libraries(${NAME} ${APRILTAG_LIB} Threads::Threads) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + APRILTAGwrapper + Threads::Threads + ) endif() -#message(STATUS PatternDetector:${INCLUDEPATHS} ) - +target_link_libraries(${PROJECT_NAME} + pthread + corecvs + JSONMODERNwrapper + ${ADDITIONAL_LIBS} + ) -target_link_libraries(${NAME} corecvs pthread cvs_utils ${LIBS}) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) - +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/raytracerender/CMakeLists.txt b/test/raytracerender/CMakeLists.txt index 09da8453b..28a0df9ee 100644 --- a/test/raytracerender/CMakeLists.txt +++ b/test/raytracerender/CMakeLists.txt @@ -1,38 +1,57 @@ -project (RaytraceRenderer) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME raytracerender) -set (NAME raytrace_renderer ) - -set (SRC_FILES +set(SOURCE_FILES main_raytracerender.cpp scene_large.cpp scene_pole.cpp scene_scanner.cpp scene_speedup.cpp scene_test1.cpp -) - -include(../../wrappers/jsonmodern/sourcelist.cmake) + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() +set(SOURCES + ${SOURCE_FILES} + ) -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +assign_source_group(${SOURCES}) -#message(RaytraceRenderer:${INCLUDEPATHS} ) +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +set(ADDITIONAL_LIBS) -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) + add_definitions(-DWITH_LIBPNG) +endif() -include_directories(${INC_PATHS}) - -target_link_libraries(${NAME} corecvs pthread ${LIBS}) +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() - +target_link_libraries(${PROJECT_NAME} + pthread + corecvs + JSONMODERNwrapper + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/reprojector/CMakeLists.txt b/test/reprojector/CMakeLists.txt index edf9cb7bb..d1320fe0f 100644 --- a/test/reprojector/CMakeLists.txt +++ b/test/reprojector/CMakeLists.txt @@ -1,30 +1,52 @@ -project (Reprojector) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME reprojector) -set (NAME reprojector) - -set (SRC_FILES +set(SOURCE_FILE main_reprojector.cpp -) - + ) -include(../../wrappers/jsonmodern/sourcelist.cmake) +set(SOURCES + ${SOURCE_FILE} + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() +assign_source_group(${SOURCES}) -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +set(ADDITIONAL_LIBS) -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) + add_definitions(-DWITH_LIBPNG) +endif() -include_directories(${INC_PATHS}) +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() -target_link_libraries(${NAME} corecvs pthread ${LIBS}) +target_link_libraries(${PROJECT_NAME} + pthread + corecvs + JSONMODERNwrapper + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/sdrRecord/CMakeLists.txt b/test/sdrRecord/CMakeLists.txt new file mode 100644 index 000000000..2a480d9ed --- /dev/null +++ b/test/sdrRecord/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME sdrRecord) + +set(PRIVATE_HEADER_FILES + sdrRecord.h + ) + +set(HEADERS + ${PRIVATE_HEADER_FILES} + ) + +set(SOURCE_FILES + sdrRecord.cpp + main.cpp + ) + +set(SOURCES + ${SOURCE_FILES} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + pthread + corecvs + SoapySDR + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/sdrRecord/main.cpp b/test/sdrRecord/main.cpp new file mode 100644 index 000000000..f8dc95691 --- /dev/null +++ b/test/sdrRecord/main.cpp @@ -0,0 +1,67 @@ +#include "core/reflection/commandLineSetter.h" +#include "core/utils/utils.h" + +#include + +#include "sdrRecord.h" + +using namespace corecvs; + +int main (int argC, char **argV) +{ + CommandLineSetter s(argC, argV); + + if (s.hasOption("list")) + { + SDRRecord::printDevices(); + return 0; + } + + vector input = s.nonPrefix(); + + if (input.size() != 2) + { + SYNC_PRINT(("Usage:\n")); + SYNC_PRINT((" sdrRecord \n")); + SYNC_PRINT((" - Will capture quadratures from \n")); + + SYNC_PRINT(("You have provided %d argumants\n", argC)); + + return 0; + } + + double centerFreq = HelperUtils::parseDouble(input[1]); + + SYNC_PRINT(("Initializing capture on frequency %f Hz (%f MHz)\n", centerFreq, centerFreq / 1000000.0)); + + SDRRecord* sdrCapture = new SDRRecord(centerFreq); + SDRRecord::CapErrorCode errorCode; + + errorCode = sdrCapture->initCapture(); + if (errorCode == SDRRecord::CapErrorCode::FAILURE) + { + SYNC_PRINT(("Cannot init capture\n")); + return 1; + } + + errorCode = sdrCapture->startCapture(); + if (errorCode == SDRRecord::CapErrorCode::FAILURE) + { + SYNC_PRINT(("Cannot start capture\n")); + return 1; + } + + SYNC_PRINT(("Record started, press Enter to stop...\n")); + std::string userInput; + if (std::getline(std::cin, userInput)) + errorCode = sdrCapture->stopCapture(); + if (errorCode == SDRRecord::CapErrorCode::FAILURE) + { + SYNC_PRINT(("Error stopping capture\n")); + return 1; + } + + delete sdrCapture; + return 0; +} + diff --git a/test/sdrRecord/sdrRecord.cpp b/test/sdrRecord/sdrRecord.cpp new file mode 100644 index 000000000..98337c4eb --- /dev/null +++ b/test/sdrRecord/sdrRecord.cpp @@ -0,0 +1,162 @@ +/** + * \file ATVCapture.cpp + * \brief Analogue TV decoder for SDR + * + * \date Mar 13, 2020 + * \author Ilya + */ + +#include "sdrRecord.h" + +SDRRecord::SDRRecord(double centerFreq) : centerFreq(centerFreq), mIsPaused(true) {} + + +SDRRecord::CapErrorCode SDRRecord::initCapture() +{ + SYNC_PRINT(("sdrRecord::initCapture(): called\n")); + + // TODO: automatic choice of device + SoapySDR::Kwargs args = SoapySDR::KwargsFromString("driver=hackrf"); + SDR = SoapySDR::Device::make(args); + if (SDR == nullptr) + { + SYNC_PRINT(("sdrRecord::initCapture(): Unable to make a device\n")); + return SDRRecord::FAILURE; + } + + /* Output some information */ + std::string driverKey = SDR->getDriverKey(); + std::string hardwareKey = SDR->getHardwareKey(); + + SYNC_PRINT(("Driver Key: %s\n", driverKey.c_str())); + SYNC_PRINT(("Hardware Key: %s\n", hardwareKey.c_str())); + + SYNC_PRINT(("Hardware Info:\n")); + SoapySDR::Kwargs list = SDR->getHardwareInfo(); + for (auto &key : list) + { + SYNC_PRINT((" %s - %s:\n", key.first.c_str(), key.second.c_str())); + } + + SYNC_PRINT(("Stream formats:\n")); + std::vector streamFormats = SDR->getStreamFormats(SOAPY_SDR_RX, 0); + for (auto &format : streamFormats) + { + SYNC_PRINT((" - %s:\n", format.c_str())); + } + + SYNC_PRINT(("Native formats:\n")); + double fullScale = 0.0; + std::string nativeStreamFormat = SDR->getNativeStreamFormat(SOAPY_SDR_RX, 0, fullScale); + SYNC_PRINT((" - %s:\n", nativeStreamFormat.c_str())); + + + /* Creating and opening stream */ + SDR->setSampleRate(SOAPY_SDR_RX, 0, sampleRate); + SDR->setFrequency (SOAPY_SDR_RX, 0, centerFreq); + rxStream = SDR->setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32); + + /* Output stream info */ + size_t mtu = SDR->getStreamMTU(rxStream); + SYNC_PRINT(("Created stream MTU is %d elements\n", (int)mtu)); + + size_t dmaBuffs = SDR->getNumDirectAccessBuffers(rxStream); + SYNC_PRINT(("Created stream has %d DMA buffers\n", (int)dmaBuffs)); + + + std::string output = "samples.bin"; + file.open(output, std::ios::out | std::ios::binary); + if (file.fail()) + { + SYNC_PRINT(("Can't open output file <%s>\n", output.c_str())); + return SDRRecord::FAILURE; + } + + SYNC_PRINT(("sdrRecord::initCapture(): exited\n")); + return SDRRecord::SUCCESS; +} + +SDRRecord::CapErrorCode SDRRecord::startCapture() +{ + SYNC_PRINT(("sdrRecord::startCapture(): called\n")); + + SDR->activateStream(rxStream, 0, 0, 0); + mIsPaused = false; + firstIteration = true; + + writer = std::thread(&SDRRecord::writing, this); + + SYNC_PRINT(("sdrRecord::startCapture(): exited\n")); + return SDRRecord::SUCCESS; +} + + +void SDRRecord::receiving(std::complex buffer[]) +{ + void *buffs[] = {buffer}; + int flags; + long long time_ns; + SDR->readStream(rxStream, buffs, buffSize, flags, time_ns, 1e5); +} + + +void SDRRecord::writing() +{ + float re, im; + for (u_char i = 0; !mIsPaused; i = 1 - i) + { + receiver = std::thread(&SDRRecord::receiving, this, buff[i]); + if (firstIteration) + { firstIteration = false; receiver.join(); continue; } + for (u_short sampleNumber = 0; sampleNumber < buffSize; sampleNumber++) + { + re = buff[1 - i][sampleNumber].real(); + im = buff[1 - i][sampleNumber].imag(); + file.write((char *)&re, sizeof (float)); + file.write((char *)&im, sizeof (float)); + } + receiver.join(); + } +} + + +SDRRecord::CapErrorCode SDRRecord::stopCapture() +{ + SYNC_PRINT(("sdrRecord::stopCapture(): called.\n")); + + mIsPaused = true; + writer.join(); + SDR->deactivateStream(rxStream, 0, 0); + return SDRRecord::SUCCESS; +} + + +SDRRecord::~SDRRecord() +{ + SYNC_PRINT(("sdrRecord::sdrRecord(): called\n")); + + if (!mIsPaused) + stopCapture(); + file.close(); + SDR->closeStream(rxStream); + SoapySDR::Device::unmake(SDR); + + SYNC_PRINT(("sdrRecord::sdrRecord(): exited\n")); +} + +void SDRRecord::printDevices() +{ + SoapySDR::KwargsList list = SoapySDR::Device::enumerate(); + SYNC_PRINT(("SoapySDR returns following devices:\n")); + int count = 1; + for (auto &dev : list) + { + SYNC_PRINT((" Device %d:\n", count)); + + for (auto &key : dev) + { + SYNC_PRINT((" %s - %s:\n", key.first.c_str(), key.second.c_str())); + } + count++; + } +} diff --git a/test/sdrRecord/sdrRecord.h b/test/sdrRecord/sdrRecord.h new file mode 100644 index 000000000..e01414387 --- /dev/null +++ b/test/sdrRecord/sdrRecord.h @@ -0,0 +1,65 @@ +/** + * \file ATVCapture.cpp + * \brief Analogue TV decoder for SDR + * + * \date May 7, 2020 + * \author Ilya + */ + +#ifndef CORECVS_SDRRECORD_H +#define CORECVS_SDRRECORD_H + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + + +class SDRRecord +{ +public: + explicit SDRRecord(double centerFreq); + + enum CapErrorCode + { + SUCCESS = 0, + FAILURE = 2 + }; + + SDRRecord::CapErrorCode initCapture(); + SDRRecord::CapErrorCode startCapture(); + SDRRecord::CapErrorCode stopCapture(); + + ~SDRRecord(); + bool mIsPaused; + bool firstIteration; + + static void printDevices(); + +private: + constexpr static const double sampleRate = 10e6; + const double centerFreq; + static const short buffSize = 1024; + std::ofstream file; + + SoapySDR::Device* SDR; + SoapySDR::Stream* rxStream; + + void receiving(std::complex buffer[]); + void writing(); + + std::thread receiver, writer; + std::complex buff[2][buffSize]; +}; + +#endif //CORECVS_SDRRECORD_H diff --git a/test/softrender/CMakeLists.txt b/test/softrender/CMakeLists.txt index bc7051281..f4af0037d 100644 --- a/test/softrender/CMakeLists.txt +++ b/test/softrender/CMakeLists.txt @@ -1,34 +1,52 @@ -project (SoftRender) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME softrender) -set (NAME softrender ) +set(SOURCE_FILE + main_softrender.cpp + ) -set (SRC_FILES - main_softrender.cpp -) +set(SOURCES + ${SOURCE_FILE} + ) +assign_source_group(${SOURCES}) -include(../../wrappers/jsonmodern/sourcelist.cmake) +add_executable(${PROJECT_NAME} + ${SOURCES} + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() - -#message(STATUS SoftRender:${INCLUDEPATHS} ) - -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +set(ADDITIONAL_LIBS) -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) + add_definitions(-DWITH_LIBPNG) +endif() -include_directories(${INC_PATHS}) - -target_link_libraries(${NAME} corecvs pthread ${LIBS}) +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() - +target_link_libraries(${PROJECT_NAME} + pthread + corecvs + JSONMODERNwrapper + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/test/softrender/main_softrender.cpp b/test/softrender/main_softrender.cpp index 9953f0724..3576195f0 100644 --- a/test/softrender/main_softrender.cpp +++ b/test/softrender/main_softrender.cpp @@ -19,6 +19,7 @@ #include "core/fileformats/bmpLoader.h" #include "core/utils/utils.h" #include "core/filesystem/folderScanner.h" +#include "buffers/bufferFactory.h" #if 0 int main(int argc, const char **argv) diff --git a/test/stabilization/frameprocessor.h b/test/stabilization/frameprocessor.h index aa34eff0c..082d6ae18 100644 --- a/test/stabilization/frameprocessor.h +++ b/test/stabilization/frameprocessor.h @@ -3,7 +3,7 @@ #include #include -#include "advancedImageWidget.h" +#include "uis/advancedImageWidget.h" #include "KLTFlow.h" class FrameProcessor : public QObject diff --git a/test/widget_harness/CMakeLists.txt b/test/widget_harness/CMakeLists.txt index ceca6f245..bd57999ac 100644 --- a/test/widget_harness/CMakeLists.txt +++ b/test/widget_harness/CMakeLists.txt @@ -1,29 +1,64 @@ -project (widget_harness) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME widget_harness) -set (NAME widget_harness) +find_package(Qt5 REQUIRED COMPONENTS Widgets) -set (SRC_FILES +set(PRIVATE_HEADER_FILE changeReceiver.h + ) + +set(HEADERS + ${PRIVATE_HEADER_FILE} + ) + +set(SOURCE_FILE main_widget_harness.cpp -) + ) -if (PNG_LIB) - include(../../wrappers/libpng/sourcelist.cmake) -endif() - -if (JPEG_LIB) - include(../../wrappers/libjpeg/sourcelist.cmake) -endif() +set(SOURCES + ${SOURCE_FILE} + ) + +assign_source_group(${HEADERS} ${SOURCES}) -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CURRENT_SOURCE_DIR} + ) + +set(ADDITIONAL_LIBS) + +if(PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper ) + add_definitions(-DWITH_LIBPNG) +endif() -include_directories(${INC_PATHS}) +if(JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) + add_definitions(-DWITH_LIBJPEG) +endif() -target_link_libraries(${NAME} ${LIBS} cvs_utils stdc++fs corecvs) +target_link_libraries(${PROJECT_NAME} + corecvs + corecvs_utils + Qt5::Widgets + stdc++fs + ${ADDITIONAL_LIBS} + ) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/test/widget_harness/changeReceiver.h b/test/widget_harness/changeReceiver.h index 749325ba5..5bb30aef5 100644 --- a/test/widget_harness/changeReceiver.h +++ b/test/widget_harness/changeReceiver.h @@ -2,7 +2,7 @@ #define CHANGERECIEVER_H #include -#include "reflectionWidget.h" +#include "corestructs/reflectionWidget.h" #ifdef INCLUDE_EXAMPLE #include "testClass.h" diff --git a/test/widget_harness/main_widget_harness.cpp b/test/widget_harness/main_widget_harness.cpp index 0dc629bfa..ef3a37860 100644 --- a/test/widget_harness/main_widget_harness.cpp +++ b/test/widget_harness/main_widget_harness.cpp @@ -14,10 +14,10 @@ #endif #include "core/filters/newstyle/newStyleBlock.h" -#include "widgetBlockHarness.h" +#include "corestructs/widgetBlockHarness.h" -#include "qtFileLoader.h" -#include "reflectionWidget.h" +#include "fileformats/qtFileLoader.h" +#include "corestructs/reflectionWidget.h" #include "core/math/vector/vector2d.h" #include "core/math/matrix/homographyReconstructor.h" diff --git a/test/widgets_test/CMakeLists.txt b/test/widgets_test/CMakeLists.txt new file mode 100644 index 000000000..3a6cb3fd4 --- /dev/null +++ b/test/widgets_test/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME test) +init_project(PROJECT_NAME widgets_test) + +find_package(Qt5 REQUIRED COMPONENTS Widgets Gui) + +set(PRIVATE_HEADER_FILES + changeReceiver.h + testNativeWidget.h + ) + +set(HEADERS + ${PRIVATE_HEADER_FILES} + ) + +set(SOURCE_FILES + main_widgets_test.cpp + testNativeWidget.cpp + ) + +set(SOURCES + ${SOURCE_FILES} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CURRENT_SOURCE_DIR} + ) + +set(ADDITIONAL_LIBS) + +if (PNG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBPNGwrapper + ) +endif() + +if (JPEG_LIB) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + LIBJPEGwrapper + ) +endif() + +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs + corecvs_utils + Qt5::Widgets + Qt5::Gui + stdc++fs + ${ADDITIONAL_LIBS} + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + AUTOMOC TRUE + AUTOUIC TRUE + AUTORCC TRUE + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/test/widgets_test/changeReceiver.h b/test/widgets_test/changeReceiver.h index 749325ba5..5bb30aef5 100644 --- a/test/widgets_test/changeReceiver.h +++ b/test/widgets_test/changeReceiver.h @@ -2,7 +2,7 @@ #define CHANGERECIEVER_H #include -#include "reflectionWidget.h" +#include "corestructs/reflectionWidget.h" #ifdef INCLUDE_EXAMPLE #include "testClass.h" diff --git a/test/widgets_test/main_widgets_test.cpp b/test/widgets_test/main_widgets_test.cpp index 5695894f4..09d191c70 100644 --- a/test/widgets_test/main_widgets_test.cpp +++ b/test/widgets_test/main_widgets_test.cpp @@ -15,8 +15,8 @@ #include "testClass.h" #endif -#include "qtFileLoader.h" -#include "reflectionWidget.h" +#include "fileformats/qtFileLoader.h" +#include "corestructs/reflectionWidget.h" #include "core/xml/generated/axisAlignedBoxParameters.h" #include "core/xml/generated/chessBoardAssemblerParamsBase.h" #include "core/xml/generated/checkerboardDetectionParameters.h" @@ -26,7 +26,7 @@ //#include "iterativeReconstructionNonlinearOptimizationParamsWrapper.h" #include "core/math/vector/vector2d.h" -#include "changeReceiver.h" +#include "../widget_harness/changeReceiver.h" #include "testNativeWidget.h" #include "core/math/matrix/homographyReconstructor.h" diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 5758ee588..b6f759fa2 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,8 +1,8 @@ -set(TEST_SUBDIRECTORIES +set(SUBDIRECTORIES generator ) -foreach(test_subdirectory ${TEST_SUBDIRECTORIES}) - message(STATUS "adding subdirectory applications/${test_subdirectory}") - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${test_subdirectory}) -endforeach(test_subdirectory) +foreach(subdirectory ${SUBDIRECTORIES}) + message(STATUS "adding subdirectory applications/${subdirectory}") + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${subdirectory}) +endforeach(subdirectory) diff --git a/tools/generator/CMakeLists.txt b/tools/generator/CMakeLists.txt index 134eb5dd9..74b0d629d 100644 --- a/tools/generator/CMakeLists.txt +++ b/tools/generator/CMakeLists.txt @@ -1,45 +1,102 @@ -project (Generator) - -set (NAME generator) - -set(SRC_FILES - ${CMAKE_CURRENT_LIST_DIR}/main.cpp - ${CMAKE_CURRENT_LIST_DIR}/pdoGenerator.cpp - ${CMAKE_CURRENT_LIST_DIR}/widgetUIGenerator.cpp - ${CMAKE_CURRENT_LIST_DIR}/documentationGenerator.cpp - ${CMAKE_CURRENT_LIST_DIR}/baseGenerator.cpp - ${CMAKE_CURRENT_LIST_DIR}/parametersMapperGenerator.cpp - ${CMAKE_CURRENT_LIST_DIR}/configLoader.cpp -) - -set(HDR_FILES - ${CMAKE_CURRENT_LIST_DIR}/reflectionGenerator.h - ${CMAKE_CURRENT_LIST_DIR}/pdoGenerator.h - ${CMAKE_CURRENT_LIST_DIR}/widgetUIGenerator.h - ${CMAKE_CURRENT_LIST_DIR}/documentationGenerator.h - ${CMAKE_CURRENT_LIST_DIR}/baseGenerator.h - ${CMAKE_CURRENT_LIST_DIR}/parametersMapperGenerator.h - ${CMAKE_CURRENT_LIST_DIR}/configLoader.h -) - -add_executable(${NAME} ${SRC_FILES} ${HDR_FILES}) - -add_custom_command(TARGET ${NAME} POST_BUILD - COMMAND cp ${PROJECT_BINARY_DIR}/${NAME} ${CMAKE_BINARY_DIR}/bin/${NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Copying ${NAME} to binary directory" - ) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME tools) +init_project(PROJECT_NAME generator) find_package(Qt5 COMPONENTS REQUIRED Core Xml) -target_link_libraries(${NAME} corecvs Qt5::Core Qt5::Xml ) +set(PRIVATE_HEADER_FILES + reflectionGenerator.h + pdoGenerator.h + widgetUIGenerator.h + documentationGenerator.h + baseGenerator.h + parametersMapperGenerator.h + configLoader.h + ) -# Additional stuff mostly for IDE only -file(GLOB CUR_ADD_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/xml/*.xml) -set(ADD_SRC_FILES ${ADD_SRC_FILES} ${CUR_ADD_SRC_FILES} ${CMAKE_CURRENT_LIST_DIR}/../../wrappers/opencv/xml/*.xml) +set(HEADERS + ${PRIVATE_HEADER_FILES} + ) -file(GLOB ADD_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.sh) -set(ADD_SRC_FILES ${ADD_SRC_FILES} ${CUR_ADD_SRC_FILES}) +set(SOURCE_FILES + main.cpp + pdoGenerator.cpp + widgetUIGenerator.cpp + documentationGenerator.cpp + baseGenerator.cpp + parametersMapperGenerator.cpp + configLoader.cpp + ) -target_sources(${NAME} PRIVATE ${ADD_SRC_FILES}) -set_source_files_properties(${ADD_SRC_FILES} PROPERTIES EXTERNAL_OBJECT true HEADER_FILE_ONLY TRUE) +set(SOURCES + ${SOURCE_FILES} + ) + +set(XML_FILES + xml/base.xml + xml/baseStub.xml + xml/copter.xml + xml/draw3dutils.xml + xml/egomotion.xml + xml/graphPlot.xml + xml/opencv.xml + xml/opencvsgm.xml + xml/presentation.xml + xml/recorder.xml + xml/rectify.xml + xml/test.xml + xml/utils.xml + ) + +set(TOOLS_GENERATOR_FILES + copy-base.sh + helper-regen.sh + h_stub.sh + regen-all.sh + regen-apriltag.sh + regen-basestub.sh + regen-copter.sh + regen-core.sh + regen-documentation.sh + regen-egomotion.sh + regen-merger.sh + regen-opencv.sh + regen-physics.sh + regen-recorder.sh + regen-scanner.sh + regen-test-core.sh + regen-utils.sh + selftest.sh + ) + +set(RESOURCES + ${XML_FILES} + ${TOOLS_GENERATOR_FILES} + ) + +set_source_files_properties(${RESOURCES} PROPERTIES EXTERNAL_OBJECT true HEADER_FILE_ONLY TRUE) + +assign_source_group(${HEADERS} ${SOURCES} ${RESOURCES}) + +add_executable(${PROJECT_NAME} + ${HEADERS} + ${SOURCES} + ${RESOURCES} + ) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs + Qt5::Core + Qt5::Xml + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) + +copy_directory(${PROJECT_NAME} + ${PROJECT_BINARY_DIR}/${MODULE_NAME}/${PROJECT_NAME} + ${CMAKE_BINARY_DIR}/bin/${MODULE_NAME}/${PROJECT_NAME} + ) \ No newline at end of file diff --git a/utils/3d/CMakeLists.txt b/utils/3d/CMakeLists.txt new file mode 100644 index 000000000..9a882b492 --- /dev/null +++ b/utils/3d/CMakeLists.txt @@ -0,0 +1,35 @@ +set(3D_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/billboardCaption3DScene.h + ${CMAKE_CURRENT_LIST_DIR}/coordinateFrame.h + ${CMAKE_CURRENT_LIST_DIR}/draw3dCameraParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/draw3dParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/draw3dViMouseParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/gCodeScene.h + ${CMAKE_CURRENT_LIST_DIR}/helper3DScenes.h + ${CMAKE_CURRENT_LIST_DIR}/mesh3DScene.h + ${CMAKE_CURRENT_LIST_DIR}/scene3D.h + ${CMAKE_CURRENT_LIST_DIR}/sceneShaded.h + ${CMAKE_CURRENT_LIST_DIR}/shadedSceneControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/generated/draw3dCameraParameters.h + ${CMAKE_CURRENT_LIST_DIR}/generated/draw3dViMouseParameters.h + ${CMAKE_CURRENT_LIST_DIR}/generated/viMouse3dFlowStyle.h + ${CMAKE_CURRENT_LIST_DIR}/generated/viMouse3dStereoStyle.h + PARENT_SCOPE + ) + +set(3D_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/billboardCaption3DScene.cpp + ${CMAKE_CURRENT_LIST_DIR}/coordinateFrame.cpp + ${CMAKE_CURRENT_LIST_DIR}/draw3dCameraParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/draw3dParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/draw3dViMouseParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/gCodeScene.cpp + ${CMAKE_CURRENT_LIST_DIR}/helper3DScenes.cpp + ${CMAKE_CURRENT_LIST_DIR}/mesh3DScene.cpp + ${CMAKE_CURRENT_LIST_DIR}/scene3D.cpp + ${CMAKE_CURRENT_LIST_DIR}/sceneShaded.cpp + ${CMAKE_CURRENT_LIST_DIR}/shadedSceneControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/generated/draw3dCameraParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/generated/draw3dViMouseParameters.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/3d/billboardCaption3DScene.cpp b/utils/3d/billboardCaption3DScene.cpp index 5f7f39c39..340c55266 100644 --- a/utils/3d/billboardCaption3DScene.cpp +++ b/utils/3d/billboardCaption3DScene.cpp @@ -1,4 +1,4 @@ -#include "openGLTools.h" +#include "opengl/openGLTools.h" #include "billboardCaption3DScene.h" BillboardCaption3DScene::BillboardCaption3DScene() diff --git a/utils/3d/billboardCaption3DScene.h b/utils/3d/billboardCaption3DScene.h index 1906b4710..5d5a2c555 100644 --- a/utils/3d/billboardCaption3DScene.h +++ b/utils/3d/billboardCaption3DScene.h @@ -7,7 +7,7 @@ #include "core/math/vector/vector3d.h" #include "scene3D.h" -#include "cloudViewDialog.h" +#include "uis/cloudview/cloudViewDialog.h" class BillboardCaption3DScene : public Scene3D { diff --git a/utils/3d/coordinateFrame.cpp b/utils/3d/coordinateFrame.cpp index 085ebdeeb..71a9d1c65 100644 --- a/utils/3d/coordinateFrame.cpp +++ b/utils/3d/coordinateFrame.cpp @@ -5,7 +5,7 @@ **/ #include "coordinateFrame.h" -#include "openGLTools.h" +#include "opengl/openGLTools.h" CoordinateFrame::CoordinateFrame() { diff --git a/utils/3d/draw3dCameraParametersControlWidget.cpp b/utils/3d/draw3dCameraParametersControlWidget.cpp index 94e716607..33bd829fc 100644 --- a/utils/3d/draw3dCameraParametersControlWidget.cpp +++ b/utils/3d/draw3dCameraParametersControlWidget.cpp @@ -9,13 +9,13 @@ #include "draw3dCameraParametersControlWidget.h" #include "ui_draw3dCameraParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" -#include "rgbColorParametersControlWidget.h" -#include "rgbColorParametersControlWidget.h" -#include "rgbColorParametersControlWidget.h" -#include "rgbColorParametersControlWidget.h" +#include "corestructs/coreWidgets/rgbColorParametersControlWidget.h" +#include "corestructs/coreWidgets/rgbColorParametersControlWidget.h" +#include "corestructs/coreWidgets/rgbColorParametersControlWidget.h" +#include "corestructs/coreWidgets/rgbColorParametersControlWidget.h" Draw3dCameraParametersControlWidget::Draw3dCameraParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) : ParametersControlWidgetBase(parent) diff --git a/utils/3d/draw3dCameraParametersControlWidget.h b/utils/3d/draw3dCameraParametersControlWidget.h index f37f02377..74cd4eecf 100644 --- a/utils/3d/draw3dCameraParametersControlWidget.h +++ b/utils/3d/draw3dCameraParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "generated/draw3dCameraParameters.h" #include "ui_draw3dCameraParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/3d/draw3dCameraParametersControlWidget.ui b/utils/3d/draw3dCameraParametersControlWidget.ui index 75f0b668f..b45b36f36 100644 --- a/utils/3d/draw3dCameraParametersControlWidget.ui +++ b/utils/3d/draw3dCameraParametersControlWidget.ui @@ -857,25 +857,25 @@ RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
diff --git a/utils/3d/draw3dParametersControlWidget.cpp b/utils/3d/draw3dParametersControlWidget.cpp index 5f39012aa..3873fee81 100644 --- a/utils/3d/draw3dParametersControlWidget.cpp +++ b/utils/3d/draw3dParametersControlWidget.cpp @@ -9,13 +9,13 @@ #include "draw3dParametersControlWidget.h" #include "ui_draw3dParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" -#include "rgbColorParametersControlWidget.h" -#include "rgbColorParametersControlWidget.h" -#include "rgbColorParametersControlWidget.h" -#include "rgbColorParametersControlWidget.h" +#include "corestructs/coreWidgets/rgbColorParametersControlWidget.h" +#include "corestructs/coreWidgets/rgbColorParametersControlWidget.h" +#include "corestructs/coreWidgets/rgbColorParametersControlWidget.h" +#include "corestructs/coreWidgets/rgbColorParametersControlWidget.h" Draw3dParametersControlWidget::Draw3dParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) : ParametersControlWidgetBase(parent) diff --git a/utils/3d/draw3dParametersControlWidget.h b/utils/3d/draw3dParametersControlWidget.h index fadfe632c..12098e2c4 100644 --- a/utils/3d/draw3dParametersControlWidget.h +++ b/utils/3d/draw3dParametersControlWidget.h @@ -1,8 +1,8 @@ #pragma once #include -#include "core/xml/generated/draw3dParameters.h" +#include "generated/draw3dCameraParameters.h" #include "ui_draw3dParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/3d/draw3dParametersControlWidget.ui b/utils/3d/draw3dParametersControlWidget.ui index 79d2328e4..d46a53f8e 100644 --- a/utils/3d/draw3dParametersControlWidget.ui +++ b/utils/3d/draw3dParametersControlWidget.ui @@ -705,25 +705,25 @@ RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
diff --git a/utils/3d/draw3dViMouseParametersControlWidget.cpp b/utils/3d/draw3dViMouseParametersControlWidget.cpp index 85d510428..cb5f996cf 100644 --- a/utils/3d/draw3dViMouseParametersControlWidget.cpp +++ b/utils/3d/draw3dViMouseParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "draw3dViMouseParametersControlWidget.h" #include "ui_draw3dViMouseParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" Draw3dViMouseParametersControlWidget::Draw3dViMouseParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/3d/draw3dViMouseParametersControlWidget.h b/utils/3d/draw3dViMouseParametersControlWidget.h index 63f22ae36..f3c40ef8e 100644 --- a/utils/3d/draw3dViMouseParametersControlWidget.h +++ b/utils/3d/draw3dViMouseParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "generated/draw3dViMouseParameters.h" #include "ui_draw3dViMouseParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/3d/gCodeScene.h b/utils/3d/gCodeScene.h index 906112a50..9e1cb516d 100644 --- a/utils/3d/gCodeScene.h +++ b/utils/3d/gCodeScene.h @@ -12,14 +12,14 @@ #include "scene3D.h" #include "sceneShaded.h" -#include "cloudViewDialog.h" -#include "core/fileformats/gcodeLoader.h" -#include "core/xml/generated/draw3dParameters.h" +#include "uis/cloudview/cloudViewDialog.h" +#include "fileformats/gcodeLoader.h" +#include "xml/generated/draw3dParameters.h" #include "draw3dParametersControlWidget.h" #include "draw3dCameraParametersControlWidget.h" -#include "core/xml/generated/drawGCodeParameters.h" +#include "xml/generated/drawGCodeParameters.h" -#include "reflectionWidget.h" +#include "corestructs/reflectionWidget.h" class GCodeScene : public SceneShaded { diff --git a/utils/3d/helper3DScenes.cpp b/utils/3d/helper3DScenes.cpp index 82426ac0a..b2e01d44a 100644 --- a/utils/3d/helper3DScenes.cpp +++ b/utils/3d/helper3DScenes.cpp @@ -1,6 +1,6 @@ #include "helper3DScenes.h" -#include +#include const int Grid3DScene::GRID_SIZE = 5; const int Grid3DScene::GRID_STEP = 250; diff --git a/utils/3d/helper3DScenes.h b/utils/3d/helper3DScenes.h index a51915c9c..5b3376cba 100644 --- a/utils/3d/helper3DScenes.h +++ b/utils/3d/helper3DScenes.h @@ -2,7 +2,7 @@ #define HELPER_3D_SCENES_H #include "scene3D.h" -#include "cloudViewDialog.h" +#include "uis/cloudview/cloudViewDialog.h" class Grid3DScene : public Scene3D { private: diff --git a/utils/3d/mesh3DScene.cpp b/utils/3d/mesh3DScene.cpp index 60905690a..89ed77ce7 100644 --- a/utils/3d/mesh3DScene.cpp +++ b/utils/3d/mesh3DScene.cpp @@ -14,8 +14,8 @@ #include "core/fileformats/meshLoader.h" #include "mesh3DScene.h" #include "opengl/openGLTools.h" -#include "core/xml/generated/draw3dParameters.h" -#include "painterHelpers.h" +#include "xml/generated/draw3dParameters.h" +#include "corestructs/painterHelpers.h" #include "core/math/mathUtils.h" #include "qtHelper.h" diff --git a/utils/3d/mesh3DScene.h b/utils/3d/mesh3DScene.h index 397395d71..c87586321 100644 --- a/utils/3d/mesh3DScene.h +++ b/utils/3d/mesh3DScene.h @@ -1,6 +1,6 @@ #pragma once /** - * \file mesh3D.h + * \file mesh/mesh3d.h * * \date Nov 13, 2012 **/ @@ -10,9 +10,9 @@ #include "core/utils/global.h" #include "scene3D.h" -#include "cloudViewDialog.h" -#include "core/fileformats/plyLoader.h" -#include "core/xml/generated/draw3dParameters.h" +#include "uis/cloudview/cloudViewDialog.h" +#include "fileformats/plyLoader.h" +#include "xml/generated/draw3dParameters.h" #include "draw3dParametersControlWidget.h" #include "draw3dCameraParametersControlWidget.h" diff --git a/utils/3d/scene3D.cpp b/utils/3d/scene3D.cpp index ad3a07edb..65f261940 100644 --- a/utils/3d/scene3D.cpp +++ b/utils/3d/scene3D.cpp @@ -8,8 +8,8 @@ #include "opengl/openGLTools.h" #include "scene3D.h" -#include "cloudViewDialog.h" -#include "core/math/matrix/matrix44.h" +#include "uis/cloudview/cloudViewDialog.h" +#include "math/matrix/matrix44.h" Scene3D::~Scene3D() diff --git a/utils/3d/scene3D.h b/utils/3d/scene3D.h index 61fa7f1e7..8318e96fa 100644 --- a/utils/3d/scene3D.h +++ b/utils/3d/scene3D.h @@ -8,11 +8,11 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/math/matrix/matrix44.h" -#include "core/xml/generated/draw3dParameters.h" -#include "parametersControlWidgetBase.h" +#include "math/matrix/matrix44.h" +#include "xml/generated/draw3dParameters.h" +#include "corestructs/parametersControlWidgetBase.h" class CloudViewDialog; diff --git a/utils/3d/sceneShaded.cpp b/utils/3d/sceneShaded.cpp index 0d757a506..9650900fa 100644 --- a/utils/3d/sceneShaded.cpp +++ b/utils/3d/sceneShaded.cpp @@ -8,8 +8,8 @@ #include #include "sceneShaded.h" -#include "cloudViewDialog.h" -#include "core/fileformats/bmpLoader.h" +#include "uis/cloudview/cloudViewDialog.h" +#include "fileformats/bmpLoader.h" QString textGlError(GLenum err) { @@ -565,9 +565,11 @@ void SceneShaded::drawMyself(CloudViewDialog * dialog) LOCAL_PRINT(("SceneShaded::drawMyself(): Binding textures\n")); if (mTextures[materialId] != (GLuint)(-1)) + { glEnable(GL_TEXTURE_2D); - glActiveTexture(GL_TEXTURE0); + QOpenGLFunctions glAT; + glAT.glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, mTextures[materialId]); mProgram[FACE]->setUniformValue(mTextureSampler, 0); mProgram[FACE]->setUniformValue(mHasTexture, (GLint)1); @@ -589,7 +591,8 @@ void SceneShaded::drawMyself(CloudViewDialog * dialog) if (mBumpmaps[materialId] != (GLuint)(-1)) { glEnable(GL_TEXTURE_2D); - glActiveTexture(GL_TEXTURE1); + QOpenGLFunctions glAT; + glAT.glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, mBumpmaps[materialId]); mProgram[FACE]->setUniformValue(mBumpSampler, 1); } else { @@ -602,10 +605,12 @@ void SceneShaded::drawMyself(CloudViewDialog * dialog) LOCAL_PRINT(("SceneShaded::drawMyself(): Unbinding\n")); glBindTexture(GL_TEXTURE_2D, 0); if (!oldTexEnable) { - glActiveTexture(GL_TEXTURE0); + QOpenGLFunctions glAT; + glAT.glActiveTexture(GL_TEXTURE0); glDisable(GL_TEXTURE_2D); - glActiveTexture(GL_TEXTURE1); + + glAT.glActiveTexture(GL_TEXTURE0); (GL_TEXTURE1); glDisable(GL_TEXTURE_2D); } diff --git a/utils/3d/sceneShaded.h b/utils/3d/sceneShaded.h index 6eaacce3d..e86ee0b86 100644 --- a/utils/3d/sceneShaded.h +++ b/utils/3d/sceneShaded.h @@ -7,8 +7,9 @@ #include "draw3dCameraParametersControlWidget.h" #include "scene3D.h" -#include "core/geometry/mesh/mesh3DDecorated.h" -#include "core/geometry/mesh/meshCache.h" +#include "geometry/mesh/mesh3DDecorated.h" +#include "geometry/mesh/meshCache.h" + #include "shadedSceneControlWidget.h" class QOpenGLShaderProgram; diff --git a/utils/3d/shadedSceneControlWidget.h b/utils/3d/shadedSceneControlWidget.h index ac5647b28..d43e85c29 100644 --- a/utils/3d/shadedSceneControlWidget.h +++ b/utils/3d/shadedSceneControlWidget.h @@ -1,7 +1,7 @@ #ifndef SHADEDSCENECONTROLWIDGET_H #define SHADEDSCENECONTROLWIDGET_H -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" #include "draw3dParametersControlWidget.h" #include diff --git a/utils/3d/shadedSceneControlWidget.ui b/utils/3d/shadedSceneControlWidget.ui index b45dc549f..261c20987 100644 --- a/utils/3d/shadedSceneControlWidget.ui +++ b/utils/3d/shadedSceneControlWidget.ui @@ -186,7 +186,7 @@ Draw3dParametersControlWidget QWidget -
draw3dParametersControlWidget.h
+
3d/draw3dParametersControlWidget.h
1
diff --git a/utils/3d/sourcelist.cmake b/utils/3d/sourcelist.cmake deleted file mode 100644 index f9a437053..000000000 --- a/utils/3d/sourcelist.cmake +++ /dev/null @@ -1,12 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) - -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/generated/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/generated/*.h) -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index e5b1a5d2e..e453d3a72 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,135 +1,198 @@ -project(corecvs_utils) +cmake_minimum_required(VERSION 3.11) set(MODULE_NAME cvs_utils) +init_project(PROJECT_NAME corecvs_utils) -set (UTILS_SUBDIRECTORIES +find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets Script Xml SerialPort) + +set(UTILS_MODULES camcalc - corestructs + corestructs distortioncorrector fileformats - filters - flowcolorers + filters + flowcolorers framesources - # memoryuse - # opengl + #memoryuse rectifier scripting serializer statistics uis visitors - widgets - ../wrappers/jsonmodern - ../wrappers/libpng - ../wrappers/libjpeg - ../wrappers/v4l2 - ../wrappers/avcodec - ) - -if (OpenCV_LIBS) - set(UTILS_SUBDIRECTORIES - ${UTILS_SUBDIRECTORIES} - ../wrappers/opencv + widgets ) -endif() - -if (APRILTAG_FOUND) - set(UTILS_SUBDIRECTORIES - ${UTILS_SUBDIRECTORIES} - ../wrappers/apriltag_wrapper + +set(UTILS_OPENGL_MODULES + 3d + opengl ) -endif() -option(WITH_OPENGL "Should use OpenGL from Qt" YES) -if(WITH_OPENGL) - set(UTILS_SUBDIRECTORIES - ${UTILS_SUBDIRECTORIES} - 3d - opengl - uis/cloudview +set(PUBLIC_HEADER_FILES + configManager.h + flowDrawer.h + matrixwidget.h + qtHelper.h + scannercontrol.h + timeliner.h + trackPainter.h + viAreaWidget.h + viGLAreaWidget.h ) -endif() - -set(CMAKE_INCLUDE_CURRENT_DIR "YES") -set(CMAKE_AUTOMOC "YES") -set(CMAKE_AUTORCC "YES") - - -find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets Script Xml SerialPort) - -add_library(${MODULE_NAME} STATIC) +foreach(utils_module ${UTILS_MODULES}) + message(STATUS "including ${utils_module}") + add_subdirectory(${utils_module}) + string(TOUPPER ${utils_module} utils_module) + set(HEADERS + ${HEADERS} + ${${utils_module}_HEADER_FILES} + ) + set(SOURCES + ${SOURCES} + ${${utils_module}_SOURCE_FILES} + ) +endforeach(utils_module) -target_link_libraries(${MODULE_NAME} corecvs Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Script Qt5::Xml Qt5::SerialPort) +option(WITH_OPENGL "Should use OpenGL from Qt" YES) if(WITH_OPENGL) - find_package(Qt5 COMPONENTS REQUIRED OpenGL) - target_link_libraries(${MODULE_NAME} Qt5::OpenGL GLU GL) + foreach(utils_opengl_module ${UTILS_OPENGL_MODULES}) + message(STATUS "including ${utils_opengl_module}") + add_subdirectory(${utils_opengl_module}) + string(TOUPPER ${utils_opengl_module} utils_opengl_module) + set(HEADERS + ${HEADERS} + ${${utils_opengl_module}_HEADER_FILES} + ) + set(SOURCES + ${SOURCES} + ${${utils_opengl_module}_SOURCE_FILES} + ) + endforeach(utils_opengl_module) endif() -file(GLOB SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -file(GLOB UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) +set(HEADERS + ${HEADERS} + ${PUBLIC_HEADER_FILES} + ${UIS_CLOUDVIEW_HEADER_FILES} + ) -list(REMOVE_ITEM SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/trackPainter.cpp") +set(SOURCE_FILES + configManager.cpp + flowDrawer.cpp + matrixwidget.cpp + qtHelper.cpp + scannercontrol.cpp + timeliner.cpp + viAreaWidget.cpp + viGLAreaWidget.cpp + ) -foreach(utils_subdirectory ${UTILS_SUBDIRECTORIES}) - message(STATUS "including utils/${utils_subdirectory}") - target_include_directories(${MODULE_NAME} PUBLIC ${utils_subdirectory}) - include(${utils_subdirectory}/sourcelist.cmake) -endforeach(utils_subdirectory) +set(SOURCES + ${SOURCES} + ${SOURCE_FILES} + ${UIS_CLOUDVIEW_SOURCE_FILES} + ) -#message(STATUS "Found ui files:" "${UI_FILES}") +set(XML_RESOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/../tools/generator/xml/utils.xml + ${CMAKE_CURRENT_LIST_DIR}/../tools/generator/xml/draw3dutils.xml + ${CMAKE_CURRENT_LIST_DIR}/../tools/generator/xml/graphPlot.xml + ) -message("Additional include path <${INC_PATHS}>") -target_include_directories(${MODULE_NAME} PUBLIC ${INC_PATHS}) -target_include_directories(${MODULE_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}) +set_source_files_properties(${XML_RESOURCE_FILES} + PROPERTIES + EXTERNAL_OBJECT TRUE + HEADER_FILE_ONLY TRUE + ) -# UI processing with QT -QT5_WRAP_UI( UI_HEADERS ${UI_FILES} ) +set(RESOURCES + ${XML_RESOURCE_FILES} + ../resources/main.qrc + ) -#message("Ui processor returned <${UI_HEADERS}>") +assign_source_group(${HEADERS} ${SOURCES} ${RESOURCES}) -# Temporary fixes -SET(AUTOGEN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}_autogen/include") -target_include_directories(${MODULE_NAME} PUBLIC ${AUTOGEN_BUILD_DIR} ) -target_include_directories(${MODULE_NAME} PUBLIC ${AUTOGEN_BUILD_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -message("AUTOGEN_BUILD_DIR bin directory <${AUTOGEN_BUILD_DIR}>") +add_library(${PROJECT_NAME} STATIC + ${HEADERS} + ${SOURCES} + ${RESOURCES} + ) -target_link_libraries(${MODULE_NAME} ${LIBS}) +set(AUTOGEN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_autogen/include") + +if(WIN32) + if(USE_OPENCV) + set(OPENCV_MODULES + $ENV{OPENCV_DIR}/ + $ENV{OPENCV_DIR}/../modules/core/include + $ENV{OPENCV_DIR}/../modules/highgui/include + $ENV{OPENCV_DIR}/../modules/imgcodecs/include + $ENV{OPENCV_DIR}/../modules/imgproc/include + $ENV{OPENCV_DIR}/../modules/objdetect/include + $ENV{OPENCV_DIR}/../modules/videoio/include + $ENV{OPENCV_DIR}/../modules/videostab/include + $ENV{OPENCV_DIR}/../modules/videostab/include + $ENV{OPENCV_CONTRIB_DIR}/../modules/optflow/include + ) + endif() +endif(WIN32) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${AUTOGEN_BUILD_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${OPENCV_MODULES} + ) + +set(ADDITIONAL_LIBS) if (OpenCV_LIBS) - target_link_libraries(${MODULE_NAME} ${OpenCV_LIBS}) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + OPENCVwrapper + ) endif() if (APRILTAG_FOUND) - target_link_libraries(${MODULE_NAME} ${APRILTAG_LIB} Threads::Threads) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + Threads::Threads + APRILTAGwrapper + ) endif() +if(WITH_OPENGL) + find_package(Qt5 COMPONENTS REQUIRED OpenGL) + set(ADDITIONAL_LIBS + ${ADDITIONAL_LIBS} + Qt5::OpenGL + GLU + GL + ) +endif() - - -target_sources(${MODULE_NAME} +target_link_libraries(${PROJECT_NAME} PUBLIC - ${HDR_FILES} - PRIVATE - ${UI_HEADERS} - ${SRC_FILES} - ../resources/main.qrc -) - -target_sources(${MODULE_NAME} PRIVATE ${ADD_SRC_FILES}) -set_source_files_properties(${ADD_SRC_FILES} PROPERTIES EXTERNAL_OBJECT true) - - -# Additional stuff mostly for IDE only - -set(ADD_SRC_FILES ${ADD_SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/../tools/generator/xml/utils.xml - ${CMAKE_CURRENT_LIST_DIR}/../tools/generator/xml/draw3dutils.xml - ${CMAKE_CURRENT_LIST_DIR}/../tools/generator/xml/graphPlot.xml + corecvs + Qt5::Widgets + Qt5::Core + Qt5::Gui + Qt5::Script + Qt5::Xml + Qt5::SerialPort + JSONMODERNwrapper + LIBPNGwrapper + LIBJPEGwrapper + V4L2wrapper + AVCODECwrapper + ${ADDITIONAL_LIBS} ) -target_sources(corecvs PRIVATE ${ADD_SRC_FILES}) -set_source_files_properties(${ADD_SRC_FILES} PROPERTIES EXTERNAL_OBJECT true HEADER_FILE_ONLY TRUE) - - +set_target_properties(${PROJECT_NAME} + PROPERTIES + AUTOMOC "TRUE" + AUTOUIC "TRUE" + AUTORCC "TRUE" + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/utils/camcalc/CMakeLists.txt b/utils/camcalc/CMakeLists.txt new file mode 100644 index 000000000..5a3ef0700 --- /dev/null +++ b/utils/camcalc/CMakeLists.txt @@ -0,0 +1,11 @@ +set(CAMCALC_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/cameraCalculatorWidget.h + ${CMAKE_CURRENT_LIST_DIR}/colorTimer.h + PARENT_SCOPE + ) + +set(CAMCALC_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/cameraCalculatorWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/colorTimer.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/camcalc/sourcelist.cmake b/utils/camcalc/sourcelist.cmake deleted file mode 100644 index 3c26109db..000000000 --- a/utils/camcalc/sourcelist.cmake +++ /dev/null @@ -1,8 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) - -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) diff --git a/utils/corestructs/CMakeLists.txt b/utils/corestructs/CMakeLists.txt new file mode 100644 index 000000000..e3eaf9d58 --- /dev/null +++ b/utils/corestructs/CMakeLists.txt @@ -0,0 +1,76 @@ +set(CORESTRUCTS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/flowFabricControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/g12Image.h + ${CMAKE_CURRENT_LIST_DIR}/histogramdialog.h + ${CMAKE_CURRENT_LIST_DIR}/histogramwidget.h + ${CMAKE_CURRENT_LIST_DIR}/lockableObject.h + ${CMAKE_CURRENT_LIST_DIR}/painterHelpers.h + ${CMAKE_CURRENT_LIST_DIR}/parametersControlWidgetBase.h + ${CMAKE_CURRENT_LIST_DIR}/pointerFieldWidget.h + ${CMAKE_CURRENT_LIST_DIR}/reflectionWidget.h + ${CMAKE_CURRENT_LIST_DIR}/saveFlowSettings.h + ${CMAKE_CURRENT_LIST_DIR}/universalVisitor.h + ${CMAKE_CURRENT_LIST_DIR}/widgetBlockHarness.h +# ${CMAKE_CURRENT_LIST_DIR}/zoomablearea.h + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/affine3dControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/featurePointControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/fixtureCameraControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/fixtureControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/fixtureGeometryControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/fixtureGlobalParametersWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/axisAlignedBoxParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/bitcodeBoardParamsBaseControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/checkerboardDetectionParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/chessBoardAssemblerParamsBaseControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/debayerParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/distortionApplicationParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/euclidianMoveParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/headSearchParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/lineDistortionEstimatorParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/makePreciseParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/rgbColorParametersControlWidget.h + PARENT_SCOPE + ) + +set(CORESTRUCTS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/flowFabricControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/g12Image.cpp + ${CMAKE_CURRENT_LIST_DIR}/histogramdialog.cpp + ${CMAKE_CURRENT_LIST_DIR}/histogramwidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/lockableObject.cpp + ${CMAKE_CURRENT_LIST_DIR}/painterHelpers.cpp + ${CMAKE_CURRENT_LIST_DIR}/parametersControlWidgetBase.cpp + ${CMAKE_CURRENT_LIST_DIR}/pointerFieldWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/reflectionWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/saveFlowSettings.cpp + ${CMAKE_CURRENT_LIST_DIR}/universalVisitor.cpp + ${CMAKE_CURRENT_LIST_DIR}/widgetBlockHarness.cpp +# ${CMAKE_CURRENT_LIST_DIR}/zoomablearea.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/affine3dControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/featurePointControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/fixtureCameraControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/fixtureControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/fixtureGeometryControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraModel/fixtureGlobalParametersWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/coreWidgets/adderSubstractorParametersBaseControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/axisAlignedBoxParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/bitcodeBoardParamsBaseControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/coreWidgets/calibrationDrawHelpersParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/checkerboardDetectionParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/chessBoardAssemblerParamsBaseControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/debayerParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/distortionApplicationParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/euclidianMoveParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/headSearchParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/coreWidgets/homorgaphyReconstructorBlockBaseControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/coreWidgets/iterativeEstimateParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/coreWidgets/lensDistortionModelParametersBaseControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/lineDistortionEstimatorParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/makePreciseParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/coreWidgets/ransacParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/rgbColorParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/coreWidgets/sceneStereoAlignerBlockBaseControlWidget.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/corestructs/cameraModel/affine3dControlWidget.h b/utils/corestructs/cameraModel/affine3dControlWidget.h index c3e48460b..6f216ec0b 100644 --- a/utils/corestructs/cameraModel/affine3dControlWidget.h +++ b/utils/corestructs/cameraModel/affine3dControlWidget.h @@ -4,7 +4,7 @@ #include #include "core/cameracalibration/calibrationLocation.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { class Affine3dControlWidget; diff --git a/utils/corestructs/cameraModel/affine3dControlWidget.ui b/utils/corestructs/cameraModel/affine3dControlWidget.ui index 723747e42..8fa0fbd51 100644 --- a/utils/corestructs/cameraModel/affine3dControlWidget.ui +++ b/utils/corestructs/cameraModel/affine3dControlWidget.ui @@ -202,7 +202,7 @@ AngleEditBox QWidget -
angleEditBox.h
+
widgets/angleEditBox.h
1
diff --git a/utils/corestructs/cameraModel/featurePointControlWidget.ui b/utils/corestructs/cameraModel/featurePointControlWidget.ui index 5f930d8af..711921284 100644 --- a/utils/corestructs/cameraModel/featurePointControlWidget.ui +++ b/utils/corestructs/cameraModel/featurePointControlWidget.ui @@ -302,7 +302,7 @@ RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
diff --git a/utils/corestructs/cameraModel/fixtureCameraControlWidget.h b/utils/corestructs/cameraModel/fixtureCameraControlWidget.h index d208e33e0..1cc6e870b 100644 --- a/utils/corestructs/cameraModel/fixtureCameraControlWidget.h +++ b/utils/corestructs/cameraModel/fixtureCameraControlWidget.h @@ -1,10 +1,10 @@ #ifndef FIXTURECAMERACONTROLWIDGET_H #define FIXTURECAMERACONTROLWIDGET_H -#include "core/camerafixture/fixtureCamera.h" +#include "camerafixture/fixtureCamera.h" #include -#include +#include namespace Ui { class FixtureCameraControlWidget; diff --git a/utils/corestructs/cameraModel/fixtureCameraControlWidget.ui b/utils/corestructs/cameraModel/fixtureCameraControlWidget.ui index 25ac4a7be..d2f926043 100644 --- a/utils/corestructs/cameraModel/fixtureCameraControlWidget.ui +++ b/utils/corestructs/cameraModel/fixtureCameraControlWidget.ui @@ -33,7 +33,7 @@ CameraModelParametersControlWidget QWidget -
cameraModelParametersControlWidget.h
+
distortioncorrector/cameraModelParametersControlWidget.h
1
diff --git a/utils/corestructs/cameraModel/fixtureControlWidget.ui b/utils/corestructs/cameraModel/fixtureControlWidget.ui index be0acfa68..32992702f 100644 --- a/utils/corestructs/cameraModel/fixtureControlWidget.ui +++ b/utils/corestructs/cameraModel/fixtureControlWidget.ui @@ -95,7 +95,7 @@ Affine3dControlWidget QWidget -
affine3dControlWidget.h
+
corestructs/cameraModel/affine3dControlWidget.h
1
diff --git a/utils/corestructs/cameraModel/fixtureGeometryControlWidget.h b/utils/corestructs/cameraModel/fixtureGeometryControlWidget.h index 0860842d0..4479b626b 100644 --- a/utils/corestructs/cameraModel/fixtureGeometryControlWidget.h +++ b/utils/corestructs/cameraModel/fixtureGeometryControlWidget.h @@ -3,11 +3,11 @@ #include -#include "core/camerafixture/sceneFeaturePoint.h" -#include "core/camerafixture/fixtureScenePart.h" -#include "parametersControlWidgetBase.h" +#include "camerafixture/sceneFeaturePoint.h" +#include "camerafixture/fixtureScenePart.h" +#include "corestructs/parametersControlWidgetBase.h" -#include "graphPlotDialog.h" +#include "uis/graphPlotDialog.h" namespace Ui { class FixtureGeometryControlWidget; diff --git a/utils/corestructs/cameraModel/fixtureGeometryControlWidget.ui b/utils/corestructs/cameraModel/fixtureGeometryControlWidget.ui index 323941365..2c79ed00e 100644 --- a/utils/corestructs/cameraModel/fixtureGeometryControlWidget.ui +++ b/utils/corestructs/cameraModel/fixtureGeometryControlWidget.ui @@ -433,7 +433,7 @@ RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
diff --git a/utils/corestructs/cameraModel/fixtureGlobalParametersWidget.ui b/utils/corestructs/cameraModel/fixtureGlobalParametersWidget.ui index a6424d349..475119129 100644 --- a/utils/corestructs/cameraModel/fixtureGlobalParametersWidget.ui +++ b/utils/corestructs/cameraModel/fixtureGlobalParametersWidget.ui @@ -100,7 +100,7 @@ Affine3dControlWidget QWidget -
affine3dControlWidget.h
+
corestructs/cameraModel/affine3dControlWidget.h
1
diff --git a/utils/corestructs/coreWidgets/axisAlignedBoxParametersControlWidget.cpp b/utils/corestructs/coreWidgets/axisAlignedBoxParametersControlWidget.cpp index e3e985477..48338283e 100644 --- a/utils/corestructs/coreWidgets/axisAlignedBoxParametersControlWidget.cpp +++ b/utils/corestructs/coreWidgets/axisAlignedBoxParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "axisAlignedBoxParametersControlWidget.h" #include "ui_axisAlignedBoxParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" AxisAlignedBoxParametersControlWidget::AxisAlignedBoxParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/axisAlignedBoxParametersControlWidget.h b/utils/corestructs/coreWidgets/axisAlignedBoxParametersControlWidget.h index be0e53f10..9996e7c1a 100644 --- a/utils/corestructs/coreWidgets/axisAlignedBoxParametersControlWidget.h +++ b/utils/corestructs/coreWidgets/axisAlignedBoxParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/axisAlignedBoxParameters.h" #include "ui_axisAlignedBoxParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/bitcodeBoardParamsBaseControlWidget.cpp b/utils/corestructs/coreWidgets/bitcodeBoardParamsBaseControlWidget.cpp index 28261a02b..a164bad3d 100644 --- a/utils/corestructs/coreWidgets/bitcodeBoardParamsBaseControlWidget.cpp +++ b/utils/corestructs/coreWidgets/bitcodeBoardParamsBaseControlWidget.cpp @@ -9,8 +9,8 @@ #include "bitcodeBoardParamsBaseControlWidget.h" #include "ui_bitcodeBoardParamsBaseControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" BitcodeBoardParamsBaseControlWidget::BitcodeBoardParamsBaseControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/bitcodeBoardParamsBaseControlWidget.h b/utils/corestructs/coreWidgets/bitcodeBoardParamsBaseControlWidget.h index 1c3513bf7..65a07e09f 100644 --- a/utils/corestructs/coreWidgets/bitcodeBoardParamsBaseControlWidget.h +++ b/utils/corestructs/coreWidgets/bitcodeBoardParamsBaseControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/bitcodeBoardParamsBase.h" #include "ui_bitcodeBoardParamsBaseControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/checkerboardDetectionParametersControlWidget.cpp b/utils/corestructs/coreWidgets/checkerboardDetectionParametersControlWidget.cpp index e75dc3846..01a402d8f 100644 --- a/utils/corestructs/coreWidgets/checkerboardDetectionParametersControlWidget.cpp +++ b/utils/corestructs/coreWidgets/checkerboardDetectionParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "checkerboardDetectionParametersControlWidget.h" #include "ui_checkerboardDetectionParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" CheckerboardDetectionParametersControlWidget::CheckerboardDetectionParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/checkerboardDetectionParametersControlWidget.h b/utils/corestructs/coreWidgets/checkerboardDetectionParametersControlWidget.h index c02eb7542..3f719c18c 100644 --- a/utils/corestructs/coreWidgets/checkerboardDetectionParametersControlWidget.h +++ b/utils/corestructs/coreWidgets/checkerboardDetectionParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/checkerboardDetectionParameters.h" #include "ui_checkerboardDetectionParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/chessBoardAssemblerParamsBaseControlWidget.cpp b/utils/corestructs/coreWidgets/chessBoardAssemblerParamsBaseControlWidget.cpp index 2306fca17..c446d186a 100644 --- a/utils/corestructs/coreWidgets/chessBoardAssemblerParamsBaseControlWidget.cpp +++ b/utils/corestructs/coreWidgets/chessBoardAssemblerParamsBaseControlWidget.cpp @@ -9,8 +9,8 @@ #include "chessBoardAssemblerParamsBaseControlWidget.h" #include "ui_chessBoardAssemblerParamsBaseControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" ChessBoardAssemblerParamsBaseControlWidget::ChessBoardAssemblerParamsBaseControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/chessBoardAssemblerParamsBaseControlWidget.h b/utils/corestructs/coreWidgets/chessBoardAssemblerParamsBaseControlWidget.h index 0285d591a..f1ea9ad20 100644 --- a/utils/corestructs/coreWidgets/chessBoardAssemblerParamsBaseControlWidget.h +++ b/utils/corestructs/coreWidgets/chessBoardAssemblerParamsBaseControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/chessBoardAssemblerParamsBase.h" #include "ui_chessBoardAssemblerParamsBaseControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.cpp b/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.cpp index 37ed5a2b0..e69f854d7 100644 --- a/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.cpp +++ b/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.cpp @@ -9,8 +9,8 @@ #include "chessBoardCornerDetectorParamsBaseControlWidget.h" #include "ui_chessBoardCornerDetectorParamsBaseControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" ChessBoardCornerDetectorParamsBaseControlWidget::ChessBoardCornerDetectorParamsBaseControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.h b/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.h index 861fb1fcb..ead786adf 100644 --- a/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.h +++ b/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/chessBoardCornerDetectorParamsBase.h" #include "ui_chessBoardCornerDetectorParamsBaseControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.ui b/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.ui index 3449ffc94..789620413 100644 --- a/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.ui +++ b/utils/corestructs/coreWidgets/chessBoardCornerDetectorParamsBaseControlWidget.ui @@ -622,7 +622,7 @@ DoubleVectorWidget QWidget -
vectorWidget.h
+
widgets/vectorWidget.h
1
diff --git a/utils/corestructs/coreWidgets/debayerParametersControlWidget.cpp b/utils/corestructs/coreWidgets/debayerParametersControlWidget.cpp index b809c99b8..59dbf5091 100644 --- a/utils/corestructs/coreWidgets/debayerParametersControlWidget.cpp +++ b/utils/corestructs/coreWidgets/debayerParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "debayerParametersControlWidget.h" #include "ui_debayerParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" DebayerParametersControlWidget::DebayerParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/debayerParametersControlWidget.h b/utils/corestructs/coreWidgets/debayerParametersControlWidget.h index da2f8d5cc..383f2d435 100644 --- a/utils/corestructs/coreWidgets/debayerParametersControlWidget.h +++ b/utils/corestructs/coreWidgets/debayerParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/debayerParameters.h" #include "ui_debayerParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/debayerParametersControlWidget.ui b/utils/corestructs/coreWidgets/debayerParametersControlWidget.ui index 9f6f07349..918a73462 100644 --- a/utils/corestructs/coreWidgets/debayerParametersControlWidget.ui +++ b/utils/corestructs/coreWidgets/debayerParametersControlWidget.ui @@ -230,7 +230,7 @@ DoubleVectorWidget QWidget -
vectorWidget.h
+
widgets/vectorWidget.h
1
diff --git a/utils/corestructs/coreWidgets/distortionApplicationParametersControlWidget.cpp b/utils/corestructs/coreWidgets/distortionApplicationParametersControlWidget.cpp index c8d2852cc..f295f5968 100644 --- a/utils/corestructs/coreWidgets/distortionApplicationParametersControlWidget.cpp +++ b/utils/corestructs/coreWidgets/distortionApplicationParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "distortionApplicationParametersControlWidget.h" #include "ui_distortionApplicationParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" DistortionApplicationParametersControlWidget::DistortionApplicationParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/distortionApplicationParametersControlWidget.h b/utils/corestructs/coreWidgets/distortionApplicationParametersControlWidget.h index 612e7069a..302e6ded5 100644 --- a/utils/corestructs/coreWidgets/distortionApplicationParametersControlWidget.h +++ b/utils/corestructs/coreWidgets/distortionApplicationParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/distortionApplicationParameters.h" #include "ui_distortionApplicationParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/euclidianMoveParametersControlWidget.cpp b/utils/corestructs/coreWidgets/euclidianMoveParametersControlWidget.cpp index 449ec85e1..017797b37 100644 --- a/utils/corestructs/coreWidgets/euclidianMoveParametersControlWidget.cpp +++ b/utils/corestructs/coreWidgets/euclidianMoveParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "euclidianMoveParametersControlWidget.h" #include "ui_euclidianMoveParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" EuclidianMoveParametersControlWidget::EuclidianMoveParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/euclidianMoveParametersControlWidget.h b/utils/corestructs/coreWidgets/euclidianMoveParametersControlWidget.h index ae1bf471b..2e972c118 100644 --- a/utils/corestructs/coreWidgets/euclidianMoveParametersControlWidget.h +++ b/utils/corestructs/coreWidgets/euclidianMoveParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/euclidianMoveParameters.h" #include "ui_euclidianMoveParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/headSearchParametersControlWidget.cpp b/utils/corestructs/coreWidgets/headSearchParametersControlWidget.cpp index 63bef67ec..ed53e7b74 100644 --- a/utils/corestructs/coreWidgets/headSearchParametersControlWidget.cpp +++ b/utils/corestructs/coreWidgets/headSearchParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "headSearchParametersControlWidget.h" #include "ui_headSearchParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" HeadSearchParametersControlWidget::HeadSearchParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/headSearchParametersControlWidget.h b/utils/corestructs/coreWidgets/headSearchParametersControlWidget.h index e9d5e2d61..2963a1f7b 100644 --- a/utils/corestructs/coreWidgets/headSearchParametersControlWidget.h +++ b/utils/corestructs/coreWidgets/headSearchParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/headSearchParameters.h" #include "ui_headSearchParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/lineDistortionEstimatorParametersControlWidget.cpp b/utils/corestructs/coreWidgets/lineDistortionEstimatorParametersControlWidget.cpp index 7dfece922..c07d95eb4 100644 --- a/utils/corestructs/coreWidgets/lineDistortionEstimatorParametersControlWidget.cpp +++ b/utils/corestructs/coreWidgets/lineDistortionEstimatorParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "lineDistortionEstimatorParametersControlWidget.h" #include "ui_lineDistortionEstimatorParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" LineDistortionEstimatorParametersControlWidget::LineDistortionEstimatorParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/lineDistortionEstimatorParametersControlWidget.h b/utils/corestructs/coreWidgets/lineDistortionEstimatorParametersControlWidget.h index 7ea6cd5ab..64f55ab62 100644 --- a/utils/corestructs/coreWidgets/lineDistortionEstimatorParametersControlWidget.h +++ b/utils/corestructs/coreWidgets/lineDistortionEstimatorParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/lineDistortionEstimatorParameters.h" #include "ui_lineDistortionEstimatorParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/makePreciseParametersControlWidget.cpp b/utils/corestructs/coreWidgets/makePreciseParametersControlWidget.cpp index 26750b55b..937b2d03f 100644 --- a/utils/corestructs/coreWidgets/makePreciseParametersControlWidget.cpp +++ b/utils/corestructs/coreWidgets/makePreciseParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "makePreciseParametersControlWidget.h" #include "ui_makePreciseParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" MakePreciseParametersControlWidget::MakePreciseParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/makePreciseParametersControlWidget.h b/utils/corestructs/coreWidgets/makePreciseParametersControlWidget.h index 77ae4ae08..b9eecf74c 100644 --- a/utils/corestructs/coreWidgets/makePreciseParametersControlWidget.h +++ b/utils/corestructs/coreWidgets/makePreciseParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/makePreciseParameters.h" #include "ui_makePreciseParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/corestructs/coreWidgets/rgbColorParametersControlWidget.cpp b/utils/corestructs/coreWidgets/rgbColorParametersControlWidget.cpp index e4aaccdc3..85a526187 100644 --- a/utils/corestructs/coreWidgets/rgbColorParametersControlWidget.cpp +++ b/utils/corestructs/coreWidgets/rgbColorParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "rgbColorParametersControlWidget.h" #include "ui_rgbColorParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" RgbColorParametersControlWidget::RgbColorParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/corestructs/coreWidgets/rgbColorParametersControlWidget.h b/utils/corestructs/coreWidgets/rgbColorParametersControlWidget.h index ab9de1f46..98c35424b 100644 --- a/utils/corestructs/coreWidgets/rgbColorParametersControlWidget.h +++ b/utils/corestructs/coreWidgets/rgbColorParametersControlWidget.h @@ -10,7 +10,7 @@ #include "core/xml/generated/rgbColorParameters.h" #include "ui_rgbColorParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" //#ifndef WIN32 //EM: said that it crashes on her Linux diff --git a/utils/corestructs/histogramdialog.ui b/utils/corestructs/histogramdialog.ui index bc07af097..efb466dbf 100644 --- a/utils/corestructs/histogramdialog.ui +++ b/utils/corestructs/histogramdialog.ui @@ -134,7 +134,7 @@ HistogramWidget QWidget -
histogramwidget.h
+
corestructs/histogramwidget.h
1 maximumChanged(QString) diff --git a/utils/corestructs/parametersControlWidgetBase.h b/utils/corestructs/parametersControlWidgetBase.h index 3c604cbc2..d2ec049e3 100644 --- a/utils/corestructs/parametersControlWidgetBase.h +++ b/utils/corestructs/parametersControlWidgetBase.h @@ -1,7 +1,7 @@ #ifndef PARAMETERS_CONTROL_WIDGET_BASE_H_ #define PARAMETERS_CONTROL_WIDGET_BASE_H_ /** - * \file parametersControlWidgetBase.h + * \file corestructs/parametersControlWidgetBase.h * * * diff --git a/utils/corestructs/pointerFieldWidget.cpp b/utils/corestructs/pointerFieldWidget.cpp index 031e74a44..a205f31d0 100644 --- a/utils/corestructs/pointerFieldWidget.cpp +++ b/utils/corestructs/pointerFieldWidget.cpp @@ -15,7 +15,7 @@ # include "rapidJSONReader.h" typedef RapidJSONReader JSONReader; #else -# include "jsonGetter.h" // it depends on Qt! +# include "visitors/jsonGetter.h" // it depends on Qt! typedef JSONGetter JSONReader; #endif diff --git a/utils/corestructs/pointerFieldWidget.h b/utils/corestructs/pointerFieldWidget.h index c70c0346a..050feff66 100644 --- a/utils/corestructs/pointerFieldWidget.h +++ b/utils/corestructs/pointerFieldWidget.h @@ -4,8 +4,8 @@ #include "core/reflection/reflection.h" #include //#include "cloudViewDialog.h" -#include "advancedImageWidget.h" -#include "cameraModelParametersControlWidget.h" +#include "uis/advancedImageWidget.h" +#include "distortioncorrector/cameraModelParametersControlWidget.h" namespace Ui { class PointerFieldWidget; diff --git a/utils/corestructs/reflectionWidget.cpp b/utils/corestructs/reflectionWidget.cpp index b22fb8d5a..b474cf23d 100644 --- a/utils/corestructs/reflectionWidget.cpp +++ b/utils/corestructs/reflectionWidget.cpp @@ -13,8 +13,8 @@ #include "pointerFieldWidget.h" #include "core/reflection/reflection.h" #include "reflectionWidget.h" -#include "vectorWidget.h" -#include "exponentialSlider.h" +#include "widgets/vectorWidget.h" +#include "widgets/exponentialSlider.h" #include "core/reflection/dynamicObject.h" using namespace corecvs; diff --git a/utils/corestructs/reflectionWidget.h b/utils/corestructs/reflectionWidget.h index fb7de7042..94b4ef463 100644 --- a/utils/corestructs/reflectionWidget.h +++ b/utils/corestructs/reflectionWidget.h @@ -4,7 +4,7 @@ #include #include -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" class ReflectionWidget : public ParametersControlWidgetBase { diff --git a/utils/corestructs/sourcelist.cmake b/utils/corestructs/sourcelist.cmake deleted file mode 100644 index d617bb814..000000000 --- a/utils/corestructs/sourcelist.cmake +++ /dev/null @@ -1,55 +0,0 @@ - -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) - -list(REMOVE_ITEM CUR_HDR_FILES "${CMAKE_CURRENT_LIST_DIR}/zoomablearea.h") -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/zoomablearea.cpp") - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) - -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/cameraModel/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/cameraModel/*.h) -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/cameraModel/*.ui) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) - -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/*.h) -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/coreWidgets/*.ui) - -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/coreWidgets/adderSubstractorParametersBaseControlWidget.cpp") -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/coreWidgets/homorgaphyReconstructorBlockBaseControlWidget.cpp") -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/coreWidgets/iterativeEstimateParametersControlWidget.cpp") -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/coreWidgets/calibrationDrawHelpersParametersControlWidget.cpp") -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/coreWidgets/lensDistortionModelParametersBaseControlWidget.cpp") -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/coreWidgets/sceneStereoAlignerBlockBaseControlWidget.cpp") -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/coreWidgets/ransacParametersControlWidget.cpp") - - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) - -set(INC_PATHS ${INC_PATHS} ${CMAKE_CURRENT_LIST_DIR}/cameraModel) -set(INC_PATHS ${INC_PATHS} ${CMAKE_CURRENT_LIST_DIR}/coreWidgets) - -# file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/libWidgets/*.cpp) -# file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/libWidgets/*.h) - - -# target_include_directories(cvs_utils PUBLIC "${CMAKE_CURRENT_LIST_DIR}/../widgets/") -# target_include_directories(cvs_utils PUBLIC "${CMAKE_CURRENT_LIST_DIR}/../visitors/") -# target_include_directories(cvs_utils PUBLIC "${CMAKE_CURRENT_LIST_DIR}") - - -# target_sources(cvs_utils -# PUBLIC -# ${HDR_FILES} -# PRIVATE -# ${SRC_FILES} -# ) diff --git a/utils/corestructs/zoomablearea.h b/utils/corestructs/zoomablearea.h index cc9a364ef..f22b78e9c 100644 --- a/utils/corestructs/zoomablearea.h +++ b/utils/corestructs/zoomablearea.h @@ -1,7 +1,7 @@ #ifndef ZOOMABLEAREA_H #define ZOOMABLEAREA_H -#include +#include #include "ui_zoomablearea.h" class ZoomableArea : public QWidget diff --git a/utils/distortioncorrector/CMakeLists.txt b/utils/distortioncorrector/CMakeLists.txt new file mode 100644 index 000000000..672c22ce3 --- /dev/null +++ b/utils/distortioncorrector/CMakeLists.txt @@ -0,0 +1,19 @@ +set(DISTORTIONCORRECTOR_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/calibrationFeaturesWidget.h + ${CMAKE_CURRENT_LIST_DIR}/cameraModelParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/distortionCorrectionDoc.h + ${CMAKE_CURRENT_LIST_DIR}/distortionParameters.h + ${CMAKE_CURRENT_LIST_DIR}/distortionWidget.h + ${CMAKE_CURRENT_LIST_DIR}/lensDistortionModelParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/pointListEditImageWidget.h + PARENT_SCOPE + ) + +set(DISTORTIONCORRECTOR_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/calibrationFeaturesWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/cameraModelParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/distortionWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/lensDistortionModelParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/pointListEditImageWidget.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/distortioncorrector/calibrationFeaturesWidget.cpp b/utils/distortioncorrector/calibrationFeaturesWidget.cpp index 424c62899..35c875306 100644 --- a/utils/distortioncorrector/calibrationFeaturesWidget.cpp +++ b/utils/distortioncorrector/calibrationFeaturesWidget.cpp @@ -5,10 +5,10 @@ #include "calibrationFeaturesWidget.h" #include "ui_calibrationFeaturesWidget.h" -#include "qSettingsSetter.h" -#include "qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" -#include "painterHelpers.h" +#include "corestructs/painterHelpers.h" #include "qtHelper.h" using namespace corecvs; diff --git a/utils/distortioncorrector/calibrationFeaturesWidget.h b/utils/distortioncorrector/calibrationFeaturesWidget.h index 70bbe0123..6767e9391 100644 --- a/utils/distortioncorrector/calibrationFeaturesWidget.h +++ b/utils/distortioncorrector/calibrationFeaturesWidget.h @@ -3,13 +3,13 @@ #include -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" #include "calibrationFeaturesWidget.h" -#include "core/alignment/selectableGeometryFeatures.h" +#include "alignment/selectableGeometryFeatures.h" -#include "advancedImageWidget.h" -#include "observationListModel.h" +#include "uis/advancedImageWidget.h" +#include "widgets/observationListModel.h" using corecvs::Vector2dd; using corecvs::Vector3dd; diff --git a/utils/distortioncorrector/cameraModelParametersControlWidget.h b/utils/distortioncorrector/cameraModelParametersControlWidget.h index 8cd2a6b37..5df43cbd6 100644 --- a/utils/distortioncorrector/cameraModelParametersControlWidget.h +++ b/utils/distortioncorrector/cameraModelParametersControlWidget.h @@ -4,15 +4,15 @@ #include #include -#include "parametersControlWidgetBase.h" -#include "core/alignment/lensDistortionModelParameters.h" +#include "corestructs/parametersControlWidgetBase.h" +#include "alignment/lensDistortionModelParameters.h" -#include "core/cameracalibration/cameraModel.h" +#include "cameracalibration/cameraModel.h" -#include "core/math/quaternion.h" -#include "core/math/vector/vector3d.h" +#include "math/quaternion.h" +#include "math/vector/vector3d.h" -#include "reflectionWidget.h" +#include "corestructs/reflectionWidget.h" namespace Ui { class CameraModelParametersControlWidget; diff --git a/utils/distortioncorrector/cameraModelParametersControlWidget.ui b/utils/distortioncorrector/cameraModelParametersControlWidget.ui index eab023c89..03959ba86 100644 --- a/utils/distortioncorrector/cameraModelParametersControlWidget.ui +++ b/utils/distortioncorrector/cameraModelParametersControlWidget.ui @@ -417,13 +417,13 @@ LensDistortionModelParametersControlWidget QWidget -
lensDistortionModelParametersControlWidget.h
+
distortioncorrector/lensDistortionModelParametersControlWidget.h
1
Affine3dControlWidget QWidget -
affine3dControlWidget.h
+
corestructs/cameraModel/affine3dControlWidget.h
1
diff --git a/utils/distortioncorrector/distortionWidget.cpp b/utils/distortioncorrector/distortionWidget.cpp index 947dd3e9e..074ea568c 100644 --- a/utils/distortioncorrector/distortionWidget.cpp +++ b/utils/distortioncorrector/distortionWidget.cpp @@ -1,16 +1,16 @@ #include "distortionWidget.h" -#include "core/utils/log.h" +#include "utils/log.h" #include "qtHelper.h" -#include "core/alignment/camerasCalibration/camerasCalibrationFunc.h" -#include "core/alignment/lmDistortionSolver.h" -#include "g12Image.h" -#include "core/buffers/displacementBuffer.h" +#include "alignment/camerasCalibration/camerasCalibrationFunc.h" +#include "alignment/lmDistortionSolver.h" +#include "corestructs/g12Image.h" +#include "buffers/displacementBuffer.h" #include "ui_distortionWidget.h" -#include "core/alignment/distPointsFunction.h" +#include "alignment/distPointsFunction.h" //#include "core/patterndetection/chessBoardDetector.h" #ifdef WITH_OPENCV -# include "openCvCheckerboardDetector.h" +# include "../../wrappers/opencv/openCvCheckerboardDetector.h" #endif using corecvs::DistPointsFunction; diff --git a/utils/distortioncorrector/distortionWidget.h b/utils/distortioncorrector/distortionWidget.h index 7bf109326..27b48ecaf 100644 --- a/utils/distortioncorrector/distortionWidget.h +++ b/utils/distortioncorrector/distortionWidget.h @@ -2,12 +2,12 @@ #include -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" #include "distortionParameters.h" -#include "core/math/vector/vector3d.h" -#include "core/buffers/displacementBuffer.h" -#include "core/segmentation/segmentator.h" -#include "observationListModel.h" +#include "math/vector/vector3d.h" +#include "buffers/displacementBuffer.h" +#include "segmentation/segmentator.h" +#include "widgets/observationListModel.h" namespace Ui { class DistortionWidget; diff --git a/utils/distortioncorrector/distortionWidget.ui b/utils/distortioncorrector/distortionWidget.ui index a02ed6784..5cc518d66 100644 --- a/utils/distortioncorrector/distortionWidget.ui +++ b/utils/distortioncorrector/distortionWidget.ui @@ -642,31 +642,31 @@ LensDistortionModelParametersControlWidget QWidget -
lensDistortionModelParametersControlWidget.h
+
distortioncorrector/lensDistortionModelParametersControlWidget.h
1
PaintImageWidget QWidget -
paintImageWidget.h
+
uis/paintImageWidget.h
1
CheckerboardDetectionParametersControlWidget QWidget -
checkerboardDetectionParametersControlWidget.h
+
corestructs/coreWidgets/checkerboardDetectionParametersControlWidget.h
1
LineDistortionEstimatorParametersControlWidget QWidget -
lineDistortionEstimatorParametersControlWidget.h
+
corestructs/coreWidgets/lineDistortionEstimatorParametersControlWidget.h
1
CalibrationFeaturesWidget QWidget -
calibrationFeaturesWidget.h
+
distortioncorrector/calibrationFeaturesWidget.h
1
diff --git a/utils/distortioncorrector/lensDistortionModelParametersControlWidget.cpp b/utils/distortioncorrector/lensDistortionModelParametersControlWidget.cpp index 334fd4efc..ddd0d8221 100644 --- a/utils/distortioncorrector/lensDistortionModelParametersControlWidget.cpp +++ b/utils/distortioncorrector/lensDistortionModelParametersControlWidget.cpp @@ -1,12 +1,12 @@ #include #include -#include "core/buffers/rgb24/abstractPainter.h" -#include "qtFileLoader.h" +#include "buffers/rgb24/abstractPainter.h" +#include "fileformats/qtFileLoader.h" #include "lensDistortionModelParametersControlWidget.h" #include "ui_lensDistortionModelParametersControlWidget.h" -#include "core/buffers/displacementBuffer.h" -#include "g12Image.h" +#include "buffers/displacementBuffer.h" +#include "corestructs/g12Image.h" LensDistortionModelParametersControlWidget::LensDistortionModelParametersControlWidget(QWidget *parent) : ParametersControlWidgetBase(parent), diff --git a/utils/distortioncorrector/lensDistortionModelParametersControlWidget.h b/utils/distortioncorrector/lensDistortionModelParametersControlWidget.h index 47ec420a7..02b37f4e8 100644 --- a/utils/distortioncorrector/lensDistortionModelParametersControlWidget.h +++ b/utils/distortioncorrector/lensDistortionModelParametersControlWidget.h @@ -3,11 +3,11 @@ #include -#include "parametersControlWidgetBase.h" -#include "core/alignment/radialCorrection.h" -#include "advancedImageWidget.h" -#include "graphPlotDialog.h" -#include "core/buffers/rgb24/rgb24Buffer.h" +#include "corestructs/parametersControlWidgetBase.h" +#include "alignment/radialCorrection.h" +#include "uis/advancedImageWidget.h" +#include "uis/graphPlotDialog.h" +#include "buffers/rgb24/rgb24Buffer.h" namespace Ui { class LensDistortionModelParametersContolWidget; diff --git a/utils/distortioncorrector/pointListEditImageWidget.cpp b/utils/distortioncorrector/pointListEditImageWidget.cpp index 5d4d54750..265b5d03a 100644 --- a/utils/distortioncorrector/pointListEditImageWidget.cpp +++ b/utils/distortioncorrector/pointListEditImageWidget.cpp @@ -1,7 +1,7 @@ #include #include "pointListEditImageWidget.h" -#include "painterHelpers.h" +#include "corestructs/painterHelpers.h" #include "qtHelper.h" diff --git a/utils/distortioncorrector/pointListEditImageWidget.h b/utils/distortioncorrector/pointListEditImageWidget.h index 862b083c8..fadec4495 100644 --- a/utils/distortioncorrector/pointListEditImageWidget.h +++ b/utils/distortioncorrector/pointListEditImageWidget.h @@ -3,8 +3,8 @@ #include -#include "advancedImageWidget.h" -#include "observationListModel.h" +#include "uis/advancedImageWidget.h" +#include "widgets/observationListModel.h" /** diff --git a/utils/distortioncorrector/sourcelist.cmake b/utils/distortioncorrector/sourcelist.cmake deleted file mode 100644 index a698aca23..000000000 --- a/utils/distortioncorrector/sourcelist.cmake +++ /dev/null @@ -1,7 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) diff --git a/utils/fileformats/CMakeLists.txt b/utils/fileformats/CMakeLists.txt new file mode 100644 index 000000000..94d1bf007 --- /dev/null +++ b/utils/fileformats/CMakeLists.txt @@ -0,0 +1,9 @@ +set(FILEFORMATS_HEADER_FILE + ${CMAKE_CURRENT_LIST_DIR}/qtFileLoader.h + PARENT_SCOPE + ) + +set(FILEFORMATS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/qtFileLoader.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/fileformats/qtFileLoader.cpp b/utils/fileformats/qtFileLoader.cpp index ccb9b2686..e533627dc 100644 --- a/utils/fileformats/qtFileLoader.cpp +++ b/utils/fileformats/qtFileLoader.cpp @@ -11,8 +11,8 @@ #include #include -#include "qtFileLoader.h" -#include "g12Image.h" +#include "fileformats/qtFileLoader.h" +#include "corestructs/g12Image.h" #include "qtHelper.h" using std::string; diff --git a/utils/fileformats/sourcelist.cmake b/utils/fileformats/sourcelist.cmake deleted file mode 100644 index 3a0554631..000000000 --- a/utils/fileformats/sourcelist.cmake +++ /dev/null @@ -1,5 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) \ No newline at end of file diff --git a/utils/filters/CMakeLists.txt b/utils/filters/CMakeLists.txt new file mode 100644 index 000000000..6d0e7e8ff --- /dev/null +++ b/utils/filters/CMakeLists.txt @@ -0,0 +1,80 @@ +set(FILTERS_HEADER_FILES + #${CMAKE_CURRENT_LIST_DIR}/filterExecuter.h + ${CMAKE_CURRENT_LIST_DIR}/filterParametersControlWidgetBase.h + #${CMAKE_CURRENT_LIST_DIR}/filterSelector.h + #${CMAKE_CURRENT_LIST_DIR}/openCVFilter.h + #${CMAKE_CURRENT_LIST_DIR}/graph/arrow.h + #${CMAKE_CURRENT_LIST_DIR}/graph/compoundBlockPresentation.h + #${CMAKE_CURRENT_LIST_DIR}/graph/diagramitem.h + #${CMAKE_CURRENT_LIST_DIR}/graph/diagramscene.h + #${CMAKE_CURRENT_LIST_DIR}/graph/diagramtextitem.h + #${CMAKE_CURRENT_LIST_DIR}/graph/filterBlockPresentation.h + #${CMAKE_CURRENT_LIST_DIR}/graph/filterGraphPresentation.h + #${CMAKE_CURRENT_LIST_DIR}/graph/filterPinPresentation.h + #${CMAKE_CURRENT_LIST_DIR}/graph/filterPresentationsCollection.h + #${CMAKE_CURRENT_LIST_DIR}/graph/g12PinPresentation.h + #${CMAKE_CURRENT_LIST_DIR}/graph/graphInterface.h + #${CMAKE_CURRENT_LIST_DIR}/graph/inputBlockPresentation.h + #${CMAKE_CURRENT_LIST_DIR}/graph/outputBlockPresentation.h + #${CMAKE_CURRENT_LIST_DIR}/graph/txtPinPresentation.h + #${CMAKE_CURRENT_LIST_DIR}/legacy/affinefilter.h + #${CMAKE_CURRENT_LIST_DIR}/legacy/basefilter.h + #${CMAKE_CURRENT_LIST_DIR}/legacy/bitselector.h + #${CMAKE_CURRENT_LIST_DIR}/legacy/gainoffset.h + #${CMAKE_CURRENT_LIST_DIR}/legacy/scalefilter.h + #${CMAKE_CURRENT_LIST_DIR}/legacy/sobelfilter.h + #${CMAKE_CURRENT_LIST_DIR}/ui/backgroundFilterParametersControlWidget.h + #${CMAKE_CURRENT_LIST_DIR}/ui/binarizeParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/ui/bitSelectorParametersControlWidget.h + #${CMAKE_CURRENT_LIST_DIR}/ui/cannyParametersControlWidget.h + #${CMAKE_CURRENT_LIST_DIR}/ui/gainOffsetParametersControlWidget.h + #${CMAKE_CURRENT_LIST_DIR}/ui/inputFilterParametersControlWidget.h + #${CMAKE_CURRENT_LIST_DIR}/ui/maskingParametersControlWidget.h + #${CMAKE_CURRENT_LIST_DIR}/ui/openCVFilterParametersControlWidget.h + #${CMAKE_CURRENT_LIST_DIR}/ui/operationParametersControlWidget.h + #${CMAKE_CURRENT_LIST_DIR}/ui/outputFilterParametersControlWidget.h + #${CMAKE_CURRENT_LIST_DIR}/ui/sobelParametersControlWidget.h + #${CMAKE_CURRENT_LIST_DIR}/ui/thickeningParametersControlWidget.h + PARENT_SCOPE + ) + +set(FILTERS_SOURCE_FILES + #${CMAKE_CURRENT_LIST_DIR}/filterExecuter.cpp + #${CMAKE_CURRENT_LIST_DIR}/filterSelector.cpp + #${CMAKE_CURRENT_LIST_DIR}/openCVFilter.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/arrow.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/compoundBlockPresentation.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/diagramitem.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/diagramscene.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/diagramtextitem.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/filterBlockPresentation.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/filterGraphPresentation.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/filterGraphSelector.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/filterPinPresentation.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/filterPresentationsCollection.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/g12PinPresentation.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/graphInterface.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/inputBlockPresentation.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/outputBlockPresentation.cpp + #${CMAKE_CURRENT_LIST_DIR}/graph/txtPinPresentation.cpp + #${CMAKE_CURRENT_LIST_DIR}/legacy/affinefilter.cpp + #${CMAKE_CURRENT_LIST_DIR}/legacy/basefilter.cpp + #${CMAKE_CURRENT_LIST_DIR}/legacy/bitselector.cpp + #${CMAKE_CURRENT_LIST_DIR}/legacy/gainoffset.cpp + #${CMAKE_CURRENT_LIST_DIR}/legacy/scalefilter.cpp + #${CMAKE_CURRENT_LIST_DIR}/legacy/sobelfilter.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/backgroundFilterParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/binarizeParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/ui/bitSelectorParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/cannyParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/gainOffsetParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/inputFilterParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/maskingParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/openCVFilterParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/operationFilterControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/operationParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/outputFilterParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/sobelParametersControlWidget.cpp + #${CMAKE_CURRENT_LIST_DIR}/ui/thickeningParametersControlWidget.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/filters/filterParametersControlWidgetBase.h b/utils/filters/filterParametersControlWidgetBase.h index 9a3f297bc..d5a53d879 100644 --- a/utils/filters/filterParametersControlWidgetBase.h +++ b/utils/filters/filterParametersControlWidgetBase.h @@ -14,7 +14,7 @@ #include "core/utils/global.h" #include "core/reflection/reflection.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" class FilterParametersControlWidgetBase : public QWidget { diff --git a/utils/filters/graph/filterGraphPresentation.h b/utils/filters/graph/filterGraphPresentation.h index fc298a926..6d426ec16 100644 --- a/utils/filters/graph/filterGraphPresentation.h +++ b/utils/filters/graph/filterGraphPresentation.h @@ -8,7 +8,7 @@ #include "arrow.h" -#include "exponentialSlider.h" +#include "widgets/exponentialSlider.h" #include "filterPresentationsCollection.h" class FilterGraphPresentation : public QWidget diff --git a/utils/filters/graph/filterGraphPresentation.ui b/utils/filters/graph/filterGraphPresentation.ui index accf3db57..03199a47f 100644 --- a/utils/filters/graph/filterGraphPresentation.ui +++ b/utils/filters/graph/filterGraphPresentation.ui @@ -192,7 +192,7 @@ ExponentialSlider QWidget -
exponentialSlider.h
+
widgets/exponentialSlider.h
1
diff --git a/utils/filters/graph/filterPresentationsCollection.cpp b/utils/filters/graph/filterPresentationsCollection.cpp index 760758905..0731b1481 100644 --- a/utils/filters/graph/filterPresentationsCollection.cpp +++ b/utils/filters/graph/filterPresentationsCollection.cpp @@ -4,17 +4,17 @@ #include "inputBlockPresentation.h" #include "outputBlockPresentation.h" -#include "sobelParametersControlWidget.h" -#include "gainOffsetParametersControlWidget.h" -#include "bitSelectorParametersControlWidget.h" -#include "cannyParametersControlWidget.h" -#include "backgroundFilterParametersControlWidget.h" -#include "inputFilterParametersControlWidget.h" -#include "outputFilterParametersControlWidget.h" -#include "operationParametersControlWidget.h" -#include "binarizeParametersControlWidget.h" -#include "thickeningParametersControlWidget.h" -#include "maskingParametersControlWidget.h" +#include "filters/ui/sobelParametersControlWidget.h" +#include "filters/ui/gainOffsetParametersControlWidget.h" +#include "filters/ui/bitSelectorParametersControlWidget.h" +#include "filters/ui/cannyParametersControlWidget.h" +#include "filters/ui/backgroundFilterParametersControlWidget.h" +#include "filters/ui/inputFilterParametersControlWidget.h" +#include "filters/ui/outputFilterParametersControlWidget.h" +#include "filters/ui/operationParametersControlWidget.h" +#include "filters/ui/binarizeParametersControlWidget.h" +#include "filters/ui/thickeningParametersControlWidget.h" +#include "filters/ui/maskingParametersControlWidget.h" FilterBlockPresentation *FilterPresentationsCollection::presentationByName(const int row, FilterBlock* filter, diff --git a/utils/filters/sourcelist.cmake b/utils/filters/sourcelist.cmake deleted file mode 100644 index 1d76cf10d..000000000 --- a/utils/filters/sourcelist.cmake +++ /dev/null @@ -1,45 +0,0 @@ -#file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -#file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -#set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -#set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) - -set(SRC_FILES ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/ui/bitSelectorParametersControlWidget.cpp - ) -set(HDR_FILES ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/ui/bitSelectorParametersControlWidget.h - ${CMAKE_CURRENT_LIST_DIR}/filterParametersControlWidgetBase.h - ) - -set(UI_FILES ${UI_FILES} - ${CMAKE_CURRENT_LIST_DIR}/ui/bitSelectorParametersControlWidget.ui - ) - -if (TEMP_COMMENT) -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/graph/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/graph/*.h) - -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/graph/filterGraphSelector.cpp") - -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/graph/diagramscene.cpp") -list(REMOVE_ITEM CUR_HDR_FILES "${CMAKE_CURRENT_LIST_DIR}/graph/diagramscene.h") - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) - - -# file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/legacy/*.cpp) -# file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/legacy/*.h) -# set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -# set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) - -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/ui/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/ui/*.h) -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/ui/operationFilterControlWidget.cpp") -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -endif() - -set(INC_PATHS ${INC_PATHS} ${CMAKE_CURRENT_LIST_DIR}/ui) - - diff --git a/utils/filters/ui/backgroundFilterParametersControlWidget.cpp b/utils/filters/ui/backgroundFilterParametersControlWidget.cpp index 6fbda9717..721a03928 100644 --- a/utils/filters/ui/backgroundFilterParametersControlWidget.cpp +++ b/utils/filters/ui/backgroundFilterParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "backgroundFilterParametersControlWidget.h" #include "ui_backgroundFilterParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" BackgroundFilterParametersControlWidget::BackgroundFilterParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/backgroundFilterParametersControlWidget.h b/utils/filters/ui/backgroundFilterParametersControlWidget.h index 19e6caa78..30dda46fa 100644 --- a/utils/filters/ui/backgroundFilterParametersControlWidget.h +++ b/utils/filters/ui/backgroundFilterParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/backgroundFilterParameters.h" #include "ui_backgroundFilterParametersControlWidget.h" -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { class BackgroundFilterParametersControlWidget; diff --git a/utils/filters/ui/binarizeParametersControlWidget.cpp b/utils/filters/ui/binarizeParametersControlWidget.cpp index ad6e7dc90..5bbb4ea94 100644 --- a/utils/filters/ui/binarizeParametersControlWidget.cpp +++ b/utils/filters/ui/binarizeParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "binarizeParametersControlWidget.h" #include "ui_binarizeParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" BinarizeParametersControlWidget::BinarizeParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/binarizeParametersControlWidget.h b/utils/filters/ui/binarizeParametersControlWidget.h index cd7fdba7f..909b86c0e 100644 --- a/utils/filters/ui/binarizeParametersControlWidget.h +++ b/utils/filters/ui/binarizeParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/binarizeParameters.h" #include "ui_binarizeParametersControlWidget.h" -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { class BinarizeParametersControlWidget; diff --git a/utils/filters/ui/bitSelectorParametersControlWidget.cpp b/utils/filters/ui/bitSelectorParametersControlWidget.cpp index e6e9eac03..1ac5ffc3f 100644 --- a/utils/filters/ui/bitSelectorParametersControlWidget.cpp +++ b/utils/filters/ui/bitSelectorParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "bitSelectorParametersControlWidget.h" #include "ui_bitSelectorParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" BitSelectorParametersControlWidget::BitSelectorParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/bitSelectorParametersControlWidget.h b/utils/filters/ui/bitSelectorParametersControlWidget.h index 54fb3c75f..970eab45d 100644 --- a/utils/filters/ui/bitSelectorParametersControlWidget.h +++ b/utils/filters/ui/bitSelectorParametersControlWidget.h @@ -2,7 +2,7 @@ #include "ui_bitSelectorParametersControlWidget.h" #include "core/xml/generated/bitSelectorParameters.h" -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { class BitSelectorParametersControlWidget; diff --git a/utils/filters/ui/cannyParametersControlWidget.cpp b/utils/filters/ui/cannyParametersControlWidget.cpp index 1667c49fc..e216097b6 100644 --- a/utils/filters/ui/cannyParametersControlWidget.cpp +++ b/utils/filters/ui/cannyParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "cannyParametersControlWidget.h" #include "ui_cannyParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" CannyParametersControlWidget::CannyParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/cannyParametersControlWidget.h b/utils/filters/ui/cannyParametersControlWidget.h index 21ea310ba..b69691d13 100644 --- a/utils/filters/ui/cannyParametersControlWidget.h +++ b/utils/filters/ui/cannyParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/cannyParameters.h" #include "ui_cannyParametersControlWidget.h" -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { diff --git a/utils/filters/ui/gainOffsetParametersControlWidget.cpp b/utils/filters/ui/gainOffsetParametersControlWidget.cpp index f52a4ea26..2471fb11d 100644 --- a/utils/filters/ui/gainOffsetParametersControlWidget.cpp +++ b/utils/filters/ui/gainOffsetParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "gainOffsetParametersControlWidget.h" #include "ui_gainOffsetParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" GainOffsetParametersControlWidget::GainOffsetParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/gainOffsetParametersControlWidget.h b/utils/filters/ui/gainOffsetParametersControlWidget.h index ec6126a22..2f41c3778 100644 --- a/utils/filters/ui/gainOffsetParametersControlWidget.h +++ b/utils/filters/ui/gainOffsetParametersControlWidget.h @@ -1,7 +1,7 @@ #pragma once -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" #include "core/xml/generated/gainOffsetParameters.h" #include "ui_gainOffsetParametersControlWidget.h" diff --git a/utils/filters/ui/inputFilterParametersControlWidget.cpp b/utils/filters/ui/inputFilterParametersControlWidget.cpp index f871f7c9a..b477c6e54 100644 --- a/utils/filters/ui/inputFilterParametersControlWidget.cpp +++ b/utils/filters/ui/inputFilterParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "inputFilterParametersControlWidget.h" #include "ui_inputFilterParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" InputFilterParametersControlWidget::InputFilterParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/inputFilterParametersControlWidget.h b/utils/filters/ui/inputFilterParametersControlWidget.h index 2f2388992..f50279b90 100644 --- a/utils/filters/ui/inputFilterParametersControlWidget.h +++ b/utils/filters/ui/inputFilterParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/inputFilterParameters.h" #include "ui_inputFilterParametersControlWidget.h" -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { diff --git a/utils/filters/ui/maskingParametersControlWidget.cpp b/utils/filters/ui/maskingParametersControlWidget.cpp index 356ee0ecd..f7ba6c661 100644 --- a/utils/filters/ui/maskingParametersControlWidget.cpp +++ b/utils/filters/ui/maskingParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "maskingParametersControlWidget.h" #include "ui_maskingParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" MaskingParametersControlWidget::MaskingParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/maskingParametersControlWidget.h b/utils/filters/ui/maskingParametersControlWidget.h index d5fa9e7c1..2674b4830 100644 --- a/utils/filters/ui/maskingParametersControlWidget.h +++ b/utils/filters/ui/maskingParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/maskingParameters.h" #include "ui_maskingParametersControlWidget.h" -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { class MaskingParametersControlWidget; diff --git a/utils/filters/ui/openCVFilterParametersControlWidget.cpp b/utils/filters/ui/openCVFilterParametersControlWidget.cpp index 1f008b761..b9cde7a40 100644 --- a/utils/filters/ui/openCVFilterParametersControlWidget.cpp +++ b/utils/filters/ui/openCVFilterParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "openCVFilterParametersControlWidget.h" #include "ui_openCVFilterParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" OpenCVFilterParametersControlWidget::OpenCVFilterParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/openCVFilterParametersControlWidget.h b/utils/filters/ui/openCVFilterParametersControlWidget.h index 4b54fdfd1..fec6e175f 100644 --- a/utils/filters/ui/openCVFilterParametersControlWidget.h +++ b/utils/filters/ui/openCVFilterParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/openCVFilterParameters.h" #include "ui_openCVFilterParametersControlWidget.h" -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { diff --git a/utils/filters/ui/operationParametersControlWidget.cpp b/utils/filters/ui/operationParametersControlWidget.cpp index d38a7a6aa..98d983244 100644 --- a/utils/filters/ui/operationParametersControlWidget.cpp +++ b/utils/filters/ui/operationParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "operationParametersControlWidget.h" #include "ui_operationParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" OperationParametersControlWidget::OperationParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/operationParametersControlWidget.h b/utils/filters/ui/operationParametersControlWidget.h index 62f9c7d88..c49f93b73 100644 --- a/utils/filters/ui/operationParametersControlWidget.h +++ b/utils/filters/ui/operationParametersControlWidget.h @@ -2,8 +2,8 @@ #include #include "core/xml/generated/operationParameters.h" #include "ui_operationParametersControlWidget.h" -#include "parametersControlWidgetBase.h" -#include "filterParametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { diff --git a/utils/filters/ui/outputFilterParametersControlWidget.cpp b/utils/filters/ui/outputFilterParametersControlWidget.cpp index dd2ad8aa3..31a36cee1 100644 --- a/utils/filters/ui/outputFilterParametersControlWidget.cpp +++ b/utils/filters/ui/outputFilterParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "outputFilterParametersControlWidget.h" #include "ui_outputFilterParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" OutputFilterParametersControlWidget::OutputFilterParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/outputFilterParametersControlWidget.h b/utils/filters/ui/outputFilterParametersControlWidget.h index 1d91ff757..32a1ded37 100644 --- a/utils/filters/ui/outputFilterParametersControlWidget.h +++ b/utils/filters/ui/outputFilterParametersControlWidget.h @@ -2,7 +2,7 @@ #include "core/xml/generated/outputFilterParameters.h" #include "ui_outputFilterParametersControlWidget.h" -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { diff --git a/utils/filters/ui/sobelParametersControlWidget.cpp b/utils/filters/ui/sobelParametersControlWidget.cpp index 7d14644de..49249b7fd 100644 --- a/utils/filters/ui/sobelParametersControlWidget.cpp +++ b/utils/filters/ui/sobelParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "sobelParametersControlWidget.h" #include "ui_sobelParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" SobelParametersControlWidget::SobelParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/sobelParametersControlWidget.h b/utils/filters/ui/sobelParametersControlWidget.h index d60772350..2841f9304 100644 --- a/utils/filters/ui/sobelParametersControlWidget.h +++ b/utils/filters/ui/sobelParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/sobelParameters.h" #include "ui_sobelParametersControlWidget.h" -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { diff --git a/utils/filters/ui/thickeningParametersControlWidget.cpp b/utils/filters/ui/thickeningParametersControlWidget.cpp index ae1bf2864..fd9104736 100644 --- a/utils/filters/ui/thickeningParametersControlWidget.cpp +++ b/utils/filters/ui/thickeningParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "thickeningParametersControlWidget.h" #include "ui_thickeningParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" ThickeningParametersControlWidget::ThickeningParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/filters/ui/thickeningParametersControlWidget.h b/utils/filters/ui/thickeningParametersControlWidget.h index 7a3f9117d..ab3fccc24 100644 --- a/utils/filters/ui/thickeningParametersControlWidget.h +++ b/utils/filters/ui/thickeningParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "core/xml/generated/thickeningParameters.h" #include "ui_thickeningParametersControlWidget.h" -#include "filterParametersControlWidgetBase.h" +#include "filters/filterParametersControlWidgetBase.h" namespace Ui { class ThickeningParametersControlWidget; diff --git a/utils/flowcolorers/CMakeLists.txt b/utils/flowcolorers/CMakeLists.txt new file mode 100644 index 000000000..20d6ba3d8 --- /dev/null +++ b/utils/flowcolorers/CMakeLists.txt @@ -0,0 +1,13 @@ +set(FLOWCOLORERS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/abstractFlowColorer.h + ${CMAKE_CURRENT_LIST_DIR}/flowColorer.h + ${CMAKE_CURRENT_LIST_DIR}/stereoColorer.h + PARENT_SCOPE + ) + +set(FLOWCOLORERS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/abstractFlowColorer.cpp + ${CMAKE_CURRENT_LIST_DIR}/flowColorer.cpp + ${CMAKE_CURRENT_LIST_DIR}/stereoColorer.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/flowcolorers/sourcelist.cmake b/utils/flowcolorers/sourcelist.cmake deleted file mode 100644 index 3a0554631..000000000 --- a/utils/flowcolorers/sourcelist.cmake +++ /dev/null @@ -1,5 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) \ No newline at end of file diff --git a/utils/framesources/CMakeLists.txt b/utils/framesources/CMakeLists.txt new file mode 100644 index 000000000..963522850 --- /dev/null +++ b/utils/framesources/CMakeLists.txt @@ -0,0 +1,25 @@ +set(FRAMESOURCES_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/imageCaptureInterfaceQt.h + ${CMAKE_CURRENT_LIST_DIR}/directShow/directShow.h + ${CMAKE_CURRENT_LIST_DIR}/directShow/directShowCapture.h + ${CMAKE_CURRENT_LIST_DIR}/directShow/directShowCaptureDecouple.h + ${CMAKE_CURRENT_LIST_DIR}/opencv/openCVCapture.h + ${CMAKE_CURRENT_LIST_DIR}/opencv/openCVFileCapture.h + ${CMAKE_CURRENT_LIST_DIR}/opencv/openCVHelper.h + #${CMAKE_CURRENT_LIST_DIR}/uEye/uEyeCameraDescriptor.h + #${CMAKE_CURRENT_LIST_DIR}/uEye/uEyeCapture.h + PARENT_SCOPE + ) + +set(FRAMESOURCES_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/imageCaptureInterfaceQt.cpp + ${CMAKE_CURRENT_LIST_DIR}/directShow/directShow.cpp + ${CMAKE_CURRENT_LIST_DIR}/directShow/directShowCapture.cpp + ${CMAKE_CURRENT_LIST_DIR}/directShow/directShowCaptureDecouple.cpp + ${CMAKE_CURRENT_LIST_DIR}/opencv/openCVCapture.cpp + ${CMAKE_CURRENT_LIST_DIR}/opencv/openCVFileCapture.cpp + ${CMAKE_CURRENT_LIST_DIR}/opencv/openCVHelper.cpp + #${CMAKE_CURRENT_LIST_DIR}/uEye/uEyeCameraDescriptor.cpp + #${CMAKE_CURRENT_LIST_DIR}/uEye/uEyeCapture.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/framesources/directShow/directShow.h b/utils/framesources/directShow/directShow.h index 4f7cf0679..143917f63 100644 --- a/utils/framesources/directShow/directShow.h +++ b/utils/framesources/directShow/directShow.h @@ -4,10 +4,10 @@ #include "core/utils/global.h" -#include "core/framesources/imageCaptureInterface.h" -#include "core/framesources/cameraControlParameters.h" // CameraParameters +#include "framesources/imageCaptureInterface.h" +#include "framesources/cameraControlParameters.h" // CameraParameters -#include "capdll.h" // DSCapDeviceId, CAPTURE_FORMAT_TYPE +#include "../../../wrappers/directShow/lib64/capdll.h" // DSCapDeviceId, CAPTURE_FORMAT_TYPE class DirectShowCameraDescriptor { diff --git a/utils/framesources/directShow/directShowCapture.h b/utils/framesources/directShow/directShowCapture.h index cced861a2..3cc65b4d9 100644 --- a/utils/framesources/directShow/directShowCapture.h +++ b/utils/framesources/directShow/directShowCapture.h @@ -13,10 +13,10 @@ #include #include "directShow.h" -#include "core/framesources/imageCaptureInterface.h" -#include "core/framesources/cameraControlParameters.h" // CameraParameters +#include "framesources/imageCaptureInterface.h" +#include "framesources/cameraControlParameters.h" // CameraParameters #include "core/utils/preciseTimer.h" -#include "../../frames.h" // Frames:: +#include "framesources/frames.h" // Frames:: #define PREFFERED_RGB_BPP 24 #define AUTOSELECT_FORMAT_FEATURE -255 diff --git a/utils/framesources/imageCaptureInterfaceQt.cpp b/utils/framesources/imageCaptureInterfaceQt.cpp index 62baf25b0..5f53aedf8 100644 --- a/utils/framesources/imageCaptureInterfaceQt.cpp +++ b/utils/framesources/imageCaptureInterfaceQt.cpp @@ -35,6 +35,10 @@ #include "opencv/openCVFileCapture.h" #endif +#ifdef WITH_ATVCAMERA + #include "wrappers/atv/atvCapture.h" +#endif + ImageCaptureInterfaceQt* ImageCaptureInterfaceQtFactory::fabric(string input, bool isRGB) { SYNC_PRINT(("ImageCaptureInterfaceQtFactory::fabric(%s, rgb=%s):called\n", input.c_str(), isRGB ? "true" : "false")); @@ -161,6 +165,16 @@ ImageCaptureInterfaceQt* ImageCaptureInterfaceQtFactory::fabric(string input, bo } #endif +#ifdef WITH_ATVCAMERA + string atv("atv:"); + if (input.substr(0, atv.size()) == atv) + { + SYNC_PRINT(("ImageCaptureInterface::fablic(): Creating ATVCamera input\n")); + string tmp = input.substr(atv.size()); + return new ImageCaptureInterfaceWrapper(tmp, isRGB); + } +#endif + return NULL; } @@ -195,3 +209,43 @@ ImageCaptureInterfaceQt *ImageCaptureInterfaceQtFactory::fabric(string input, in return NULL; } + +void ImageCaptureInterfaceQtFactory::printCaps() +{ + SYNC_PRINT(("Caps for ImageCaptureInterfaceQtFactory::fabric(string input, bool isRGB):\n")); + + SYNC_PRINT((" file:\n")); + SYNC_PRINT((" prec:\n")); + +#ifdef WITH_SYNCCAM + SYNC_PRINT((" sync:\n")); +#endif +#ifdef WITH_V4L2 + SYNC_PRINT((" v4l2:\n")); + SYNC_PRINT((" v4l2d:\n")); +#endif +#ifdef WITH_UEYE + SYNC_PRINT((" ueye:\n")); +#endif +#ifdef WITH_FLYCAP + SYNC_PRINT((" flycap:\n")); +#endif +#ifdef WITH_DIRECTSHOW + SYNC_PRINT((" dshow:\n")); + SYNC_PRINT((" dshowd:\n")); +#endif +#ifdef WITH_AVCODEC + SYNC_PRINT((" avcodec:\n")); + SYNC_PRINT((" rtsp:\n")); +#endif +#ifdef WITH_OPENCV + SYNC_PRINT((" any:\n")); + SYNC_PRINT((" vfw:\n")); + SYNC_PRINT((" ds:\n")); + SYNC_PRINT((" opencv_file:\n")); +#endif + +#ifdef WITH_ATVCAMERA + SYNC_PRINT((" atv:\n")); +#endif +} diff --git a/utils/framesources/imageCaptureInterfaceQt.h b/utils/framesources/imageCaptureInterfaceQt.h index 6fd8490a5..7735964cb 100644 --- a/utils/framesources/imageCaptureInterfaceQt.h +++ b/utils/framesources/imageCaptureInterfaceQt.h @@ -12,6 +12,8 @@ class ImageCaptureInterfaceQtFactory { public: static ImageCaptureInterfaceQt *fabric(string input, bool isRgb = false); static ImageCaptureInterfaceQt *fabric(string input, int h, int w, int fps, bool isRgb = false); + + static void printCaps(); }; class ImageCaptureQtNotifier : public QObject diff --git a/utils/framesources/opencv/openCVFileCapture.cpp b/utils/framesources/opencv/openCVFileCapture.cpp index 73a789d62..2ea9498cc 100644 --- a/utils/framesources/opencv/openCVFileCapture.cpp +++ b/utils/framesources/opencv/openCVFileCapture.cpp @@ -4,7 +4,11 @@ #include "openCVFileCapture.h" //#include "openCVHelper.h" -#include "openCVTools.h" +# if defined (_MSC_VER) +# include "../../../wrappers/opencv/openCVTools.h" +# else +# include +# endif OpenCvFileCapture::OpenCvFileCapture(const std::string ¶ms) : /*AbstractFileCapture(params),*/ diff --git a/utils/framesources/sourcelist.cmake b/utils/framesources/sourcelist.cmake deleted file mode 100644 index 6433082fd..000000000 --- a/utils/framesources/sourcelist.cmake +++ /dev/null @@ -1,18 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) - -if (WITH_DIRECTDRAW) - file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/directShow/*.cpp) - file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/directShow/*.h) - set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) - set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -endif() - -if (OpenCV_LIBS) - file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/opencv/*.cpp) - file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/opencv/*.h) - set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) - set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -endif() diff --git a/utils/framesources/uEye/uEyeCameraDescriptor.h b/utils/framesources/uEye/uEyeCameraDescriptor.h index dc26146bf..24e2d2fb8 100644 --- a/utils/framesources/uEye/uEyeCameraDescriptor.h +++ b/utils/framesources/uEye/uEyeCameraDescriptor.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include diff --git a/utils/framesources/uEye/uEyeCapture.h b/utils/framesources/uEye/uEyeCapture.h index dd5aa545d..02e96da39 100644 --- a/utils/framesources/uEye/uEyeCapture.h +++ b/utils/framesources/uEye/uEyeCapture.h @@ -12,13 +12,13 @@ #include #include #include -#include +#include #include "core/utils/global.h" #include "uEyeCameraDescriptor.h" -#include "core/framesources/cameraControlParameters.h" -#include "core/framesources/imageCaptureInterface.h" +#include "framesources/cameraControlParameters.h" +#include "framesources/imageCaptureInterface.h" #include "core/utils/preciseTimer.h" diff --git a/utils/memoryuse/CMakeLists.txt b/utils/memoryuse/CMakeLists.txt new file mode 100644 index 000000000..d55dc72da --- /dev/null +++ b/utils/memoryuse/CMakeLists.txt @@ -0,0 +1,15 @@ +set(MEMORYUSE_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/memoryUsageCalculator.h + ${CMAKE_CURRENT_LIST_DIR}/linuxMemoryUsageCalculator.h + ${CMAKE_CURRENT_LIST_DIR}/macMemoryUsageCalculator.h + ${CMAKE_CURRENT_LIST_DIR}/windowsMemoryUsageCalculator.h + PARENT_SCOPE + ) + +set(MEMORYUSE_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/memoryUsageCalculator.cpp + ${CMAKE_CURRENT_LIST_DIR}/linuxMemoryUsageCalculator.cpp + ${CMAKE_CURRENT_LIST_DIR}/macMemoryUsageCalculator.cpp + ${CMAKE_CURRENT_LIST_DIR}/windowsMemoryUsageCalculator.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/memoryuse/sourcelist.cmake b/utils/memoryuse/sourcelist.cmake deleted file mode 100644 index 3a0554631..000000000 --- a/utils/memoryuse/sourcelist.cmake +++ /dev/null @@ -1,5 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) \ No newline at end of file diff --git a/utils/opengl/CMakeLists.txt b/utils/opengl/CMakeLists.txt new file mode 100644 index 000000000..0fdaa91e3 --- /dev/null +++ b/utils/opengl/CMakeLists.txt @@ -0,0 +1,9 @@ +set(OPENGL_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/openGLTools.h + PARENT_SCOPE + ) + +set(OPENGL_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/openGLTools.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/opengl/sourcelist.cmake b/utils/opengl/sourcelist.cmake deleted file mode 100644 index 3a0554631..000000000 --- a/utils/opengl/sourcelist.cmake +++ /dev/null @@ -1,5 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) \ No newline at end of file diff --git a/utils/qtHelper.h b/utils/qtHelper.h index de2deab1d..256b0f44a 100644 --- a/utils/qtHelper.h +++ b/utils/qtHelper.h @@ -17,12 +17,12 @@ #include #include -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" -#include "core/geometry/rectangle.h" -#include "core/math/matrix/matrix33.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" +#include "geometry/rectangle.h" +#include "math/matrix/matrix33.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" using corecvs::Vector2d; using corecvs::Vector2d32; diff --git a/utils/rectifier/CMakeLists.txt b/utils/rectifier/CMakeLists.txt new file mode 100644 index 000000000..7267340cc --- /dev/null +++ b/utils/rectifier/CMakeLists.txt @@ -0,0 +1,16 @@ +set(RECTIFIER_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/estimationMethodType.h + ${CMAKE_CURRENT_LIST_DIR}/matchingMethodType.h + ${CMAKE_CURRENT_LIST_DIR}/optimizationMethodType.h + ${CMAKE_CURRENT_LIST_DIR}/rectifyParameters.h + ${CMAKE_CURRENT_LIST_DIR}/rectifyParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/universalRectifier.h + PARENT_SCOPE + ) + +set(RECTIFIER_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/rectifyParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/rectifyParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/universalRectifier.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/rectifier/rectifyParametersControlWidget.cpp b/utils/rectifier/rectifyParametersControlWidget.cpp index 29d10daec..f0329c1e0 100644 --- a/utils/rectifier/rectifyParametersControlWidget.cpp +++ b/utils/rectifier/rectifyParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "rectifyParametersControlWidget.h" #include "ui_rectifyParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" RectifyParametersControlWidget::RectifyParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/rectifier/rectifyParametersControlWidget.h b/utils/rectifier/rectifyParametersControlWidget.h index 5efc5f4e3..cba403c30 100644 --- a/utils/rectifier/rectifyParametersControlWidget.h +++ b/utils/rectifier/rectifyParametersControlWidget.h @@ -8,7 +8,7 @@ #include "core/math/vector/vector3d.h" #include "core/math/mathUtils.h" #include "rectifyParameters.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" #include "qtHelper.h" using namespace corecvs; diff --git a/utils/rectifier/rectifyParametersControlWidget.ui b/utils/rectifier/rectifyParametersControlWidget.ui index d698507de..eca364276 100644 --- a/utils/rectifier/rectifyParametersControlWidget.ui +++ b/utils/rectifier/rectifyParametersControlWidget.ui @@ -1235,7 +1235,7 @@ AngleEditBox QWidget -
angleEditBox.h
+
widgets/angleEditBox.h
1
diff --git a/utils/rectifier/sourcelist.cmake b/utils/rectifier/sourcelist.cmake deleted file mode 100644 index 9a5fd3c68..000000000 --- a/utils/rectifier/sourcelist.cmake +++ /dev/null @@ -1,7 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) diff --git a/utils/scripting/CMakeLists.txt b/utils/scripting/CMakeLists.txt new file mode 100644 index 000000000..624593dd8 --- /dev/null +++ b/utils/scripting/CMakeLists.txt @@ -0,0 +1,10 @@ +set(SCRIPTING_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/coreToScript.h + ${CMAKE_CURRENT_LIST_DIR}/scriptWindow.h + PARENT_SCOPE + ) + +set(SCRIPTING_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/scriptWindow.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/scripting/scriptWindow.h b/utils/scripting/scriptWindow.h index c5e2a6805..512be1c45 100644 --- a/utils/scripting/scriptWindow.h +++ b/utils/scripting/scriptWindow.h @@ -7,7 +7,7 @@ #include #include -#include "loggerWidget.h" +#include "widgets/loggerWidget.h" namespace Ui { class ScriptWindow; diff --git a/utils/scripting/scriptWindow.ui b/utils/scripting/scriptWindow.ui index 67ad1ffd5..ebf8dba57 100644 --- a/utils/scripting/scriptWindow.ui +++ b/utils/scripting/scriptWindow.ui @@ -110,7 +110,7 @@ p, li { white-space: pre-wrap; } LoggerWidget QWidget -
loggerWidget.h
+
widgets/loggerWidget.h
1
diff --git a/utils/scripting/sourcelist.cmake b/utils/scripting/sourcelist.cmake deleted file mode 100644 index a698aca23..000000000 --- a/utils/scripting/sourcelist.cmake +++ /dev/null @@ -1,7 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) diff --git a/utils/serializer/CMakeLists.txt b/utils/serializer/CMakeLists.txt new file mode 100644 index 000000000..76e24cf1d --- /dev/null +++ b/utils/serializer/CMakeLists.txt @@ -0,0 +1,13 @@ +set(SERIALIZER_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/serializedWidget.h + ${CMAKE_CURRENT_LIST_DIR}/serializer.h + ${CMAKE_CURRENT_LIST_DIR}/widgetQtIterator.h + PARENT_SCOPE + ) + +set(SERIALIZER_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/serializedWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/serializer.cpp + ${CMAKE_CURRENT_LIST_DIR}/widgetQtIterator.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/serializer/sourcelist.cmake b/utils/serializer/sourcelist.cmake deleted file mode 100644 index 3a0554631..000000000 --- a/utils/serializer/sourcelist.cmake +++ /dev/null @@ -1,5 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) \ No newline at end of file diff --git a/utils/statistics/CMakeLists.txt b/utils/statistics/CMakeLists.txt new file mode 100644 index 000000000..fe366ce2f --- /dev/null +++ b/utils/statistics/CMakeLists.txt @@ -0,0 +1,14 @@ +set(STATISTICS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/contentStatistics.h + ${CMAKE_CURRENT_LIST_DIR}/qtStatisticsCollector.h + ${CMAKE_CURRENT_LIST_DIR}/statisticsDialog.h + ${CMAKE_CURRENT_LIST_DIR}/userPoll.h + PARENT_SCOPE + ) + +set(STATISTICS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/contentStatistics.cpp + ${CMAKE_CURRENT_LIST_DIR}/statisticsDialog.cpp + ${CMAKE_CURRENT_LIST_DIR}/userPoll.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/statistics/sourcelist.cmake b/utils/statistics/sourcelist.cmake deleted file mode 100644 index a698aca23..000000000 --- a/utils/statistics/sourcelist.cmake +++ /dev/null @@ -1,7 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) diff --git a/utils/trackPainter.cpp b/utils/trackPainter.cpp index cba871d9a..47aa183ab 100644 --- a/utils/trackPainter.cpp +++ b/utils/trackPainter.cpp @@ -1,9 +1,9 @@ -#include "core/features2d/trackPainter.h" +#include "trackPainter.h" #include #include "core/features2d/bufferReaderProvider.h" -#include "core/buffers/rgb24/abstractPainter.h" +#include "buffers/rgb24/abstractPainter.h" using namespace cvs; diff --git a/utils/uis/CMakeLists.txt b/utils/uis/CMakeLists.txt new file mode 100644 index 000000000..441dcf8c0 --- /dev/null +++ b/utils/uis/CMakeLists.txt @@ -0,0 +1,41 @@ +set(UIS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/aboutDialog.h + ${CMAKE_CURRENT_LIST_DIR}/aboutPropsTableWidget.h + ${CMAKE_CURRENT_LIST_DIR}/advancedImageWidget.h + ${CMAKE_CURRENT_LIST_DIR}/capSettingsDialog.h + ${CMAKE_CURRENT_LIST_DIR}/graphPlotDialog.h + ${CMAKE_CURRENT_LIST_DIR}/histogramDepthDialog.h + ${CMAKE_CURRENT_LIST_DIR}/osdBaseWidget.h + ${CMAKE_CURRENT_LIST_DIR}/paintImageWidget.h + ${CMAKE_CURRENT_LIST_DIR}/pointsRectificationWidget.h + ${CMAKE_CURRENT_LIST_DIR}/textLabelWidget.h + PARENT_SCOPE + ) + +set(UIS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/aboutDialog.cpp + ${CMAKE_CURRENT_LIST_DIR}/aboutPropsTableWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/advancedImageWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/capSettingsDialog.cpp + ${CMAKE_CURRENT_LIST_DIR}/graphPlotDialog.cpp + ${CMAKE_CURRENT_LIST_DIR}/histogramDepthDialog.cpp + ${CMAKE_CURRENT_LIST_DIR}/osdBaseWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/paintImageWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/pointsRectificationWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/textLabelWidget.cpp + PARENT_SCOPE + ) + +set(UIS_CLOUDVIEW_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/cloudview/cloudViewDialog.cpp + ${CMAKE_CURRENT_LIST_DIR}/cloudview/scene3dTreeView.cpp + ${CMAKE_CURRENT_LIST_DIR}/cloudview/treeSceneController.cpp + PARENT_SCOPE + ) + +set(UIS_CLOUDVIEW_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/cloudview/cloudViewDialog.cpp + ${CMAKE_CURRENT_LIST_DIR}/cloudview/scene3dTreeView.cpp + ${CMAKE_CURRENT_LIST_DIR}/cloudview/treeSceneController.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/uis/advancedImageWidget.cpp b/utils/uis/advancedImageWidget.cpp index 0f42752b0..42d5cf4a9 100644 --- a/utils/uis/advancedImageWidget.cpp +++ b/utils/uis/advancedImageWidget.cpp @@ -13,9 +13,9 @@ #include "core/utils/global.h" -#include "core/buffers/rgb24/rgbColor.h" +#include "buffers/rgb24/rgbColor.h" #include "advancedImageWidget.h" -#include "saveFlowSettings.h" +#include "corestructs/saveFlowSettings.h" #include "core/math/mathUtils.h" #include "qtHelper.h" diff --git a/utils/uis/advancedImageWidget.h b/utils/uis/advancedImageWidget.h index aa2523953..5327d4d7d 100644 --- a/utils/uis/advancedImageWidget.h +++ b/utils/uis/advancedImageWidget.h @@ -12,11 +12,11 @@ #include #include -#include "core/math/vector/vector2d.h" -#include "core/math/matrix/matrix33.h" +#include "math/vector/vector2d.h" +#include "math/matrix/matrix33.h" #include "viAreaWidget.h" -#include "saveFlowSettings.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/saveFlowSettings.h" +#include "corestructs/parametersControlWidgetBase.h" #include "ui_advancedImageWidget.h" diff --git a/utils/uis/advancedImageWidget.ui b/utils/uis/advancedImageWidget.ui index 1a05433bf..041096b91 100644 --- a/utils/uis/advancedImageWidget.ui +++ b/utils/uis/advancedImageWidget.ui @@ -651,7 +651,7 @@ ExponentialSlider QWidget -
exponentialSlider.h
+
widgets/exponentialSlider.h
1 valueChanged(double) diff --git a/utils/uis/capSettingsDialog.cpp b/utils/uis/capSettingsDialog.cpp index 403792614..8a9a45300 100644 --- a/utils/uis/capSettingsDialog.cpp +++ b/utils/uis/capSettingsDialog.cpp @@ -1,6 +1,6 @@ #include "capSettingsDialog.h" -#include "parameterSelector.h" -#include "core/utils/log.h" +#include "widgets/parameterSelector.h" +#include "utils/log.h" #include #include diff --git a/utils/uis/capSettingsDialog.h b/utils/uis/capSettingsDialog.h index 98805f8b5..fbfbdda30 100644 --- a/utils/uis/capSettingsDialog.h +++ b/utils/uis/capSettingsDialog.h @@ -5,11 +5,11 @@ #include #include -#include "core/framesources/cameraControlParameters.h" -#include "core/framesources/imageCaptureInterface.h" +#include "framesources/cameraControlParameters.h" +#include "framesources/imageCaptureInterface.h" #include "ui_capSettingsDialog.h" -#include "parameterSlider.h" -#include "parametersControlWidgetBase.h" +#include "widgets/parameterSlider.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/utils/uis/cloudview/cloudViewDialog.cpp b/utils/uis/cloudview/cloudViewDialog.cpp index 3b3b28cc5..5f109ab6e 100644 --- a/utils/uis/cloudview/cloudViewDialog.cpp +++ b/utils/uis/cloudview/cloudViewDialog.cpp @@ -1,20 +1,20 @@ #include -#include -#include +#include <3d/gCodeScene.h> +#include <3d/helper3DScenes.h> #include #include #include "cloudViewDialog.h" #include "opengl/openGLTools.h" #include "3d/mesh3DScene.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "qSettingsSetter.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "visitors/qSettingsSetter.h" -#include "core/fileformats/meshLoader.h" -#include "core/fileformats/objLoader.h" +#include "fileformats/meshLoader.h" +#include "fileformats/objLoader.h" -#include "sceneShaded.h" +#include "3d/sceneShaded.h" // FIXIT: GOOPEN //#include "../../../restricted/applications/vimouse/faceDetection/faceMesh.h" diff --git a/utils/uis/cloudview/cloudViewDialog.h b/utils/uis/cloudview/cloudViewDialog.h index ec304fabd..7fc6fa935 100644 --- a/utils/uis/cloudview/cloudViewDialog.h +++ b/utils/uis/cloudview/cloudViewDialog.h @@ -9,21 +9,21 @@ #include "core/utils/global.h" #include "ui_cloudViewDialog.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/bufferFactory.h" +#include "buffers/g12Buffer.h" +#include "buffers/bufferFactory.h" #include "viAreaWidget.h" -#include "core/rectification/triangulator.h" -#include "transform3DSelector.h" +#include "rectification/triangulator.h" +#include "widgets/transform3DSelector.h" #include "3d/scene3D.h" #include "3d/draw3dParametersControlWidget.h" #include "3d/coordinateFrame.h" -#include "core/framesources/frames.h" -#include "coordinateFrame.h" +#include "framesources/frames.h" +#include "3d/coordinateFrame.h" #include "treeSceneController.h" -#include "core/cameracalibration/cameraModel.h" +#include "cameracalibration/cameraModel.h" -#include "textLabelWidget.h" -#include "core/stats/calculationStats.h" +#include "uis/textLabelWidget.h" +#include "stats/calculationStats.h" using namespace corecvs; diff --git a/utils/uis/cloudview/cloudViewDialog.ui b/utils/uis/cloudview/cloudViewDialog.ui index ed12581b7..5588759d2 100644 --- a/utils/uis/cloudview/cloudViewDialog.ui +++ b/utils/uis/cloudview/cloudViewDialog.ui @@ -697,12 +697,12 @@ Scene3DTreeView QTreeView -
scene3dTreeView.h
+
uis/cloudview/scene3dTreeView.h
RgbColorParametersControlWidget QWidget -
rgbColorParametersControlWidget.h
+
corestructs/coreWidgets/rgbColorParametersControlWidget.h
1
diff --git a/utils/uis/cloudview/sourcelist.cmake b/utils/uis/cloudview/sourcelist.cmake deleted file mode 100644 index b12c99fd3..000000000 --- a/utils/uis/cloudview/sourcelist.cmake +++ /dev/null @@ -1,11 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) - -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/generated/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/generated/*.h) -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) diff --git a/utils/uis/cloudview/treeSceneController.cpp b/utils/uis/cloudview/treeSceneController.cpp index 9c091071b..ca13d57f9 100644 --- a/utils/uis/cloudview/treeSceneController.cpp +++ b/utils/uis/cloudview/treeSceneController.cpp @@ -4,7 +4,7 @@ * \date Mar 1, 2013 **/ -#include "core/reflection/reflection.h" +#include "reflection/reflection.h" #include "treeSceneController.h" diff --git a/utils/uis/cloudview/treeSceneController.h b/utils/uis/cloudview/treeSceneController.h index facefbbef..43c39b61f 100644 --- a/utils/uis/cloudview/treeSceneController.h +++ b/utils/uis/cloudview/treeSceneController.h @@ -9,8 +9,8 @@ #include #include "3d/scene3D.h" -#include "transform3DSelector.h" -#include "coordinateFrame.h" +#include "widgets/transform3DSelector.h" +#include "3d/coordinateFrame.h" class TreeSceneModel; diff --git a/utils/uis/graphPlotDialog.ui b/utils/uis/graphPlotDialog.ui index f782b0571..ff464b024 100644 --- a/utils/uis/graphPlotDialog.ui +++ b/utils/uis/graphPlotDialog.ui @@ -451,7 +451,7 @@ GraphPlotParametersControlWidget QWidget -
graphPlotParametersControlWidget.h
+
widgets/graphPlotParametersControlWidget.h
1
diff --git a/utils/uis/histogramDepthDialog.ui b/utils/uis/histogramDepthDialog.ui index d6f5ad68e..e63befe93 100644 --- a/utils/uis/histogramDepthDialog.ui +++ b/utils/uis/histogramDepthDialog.ui @@ -268,7 +268,7 @@ HistogramWidget QWidget -
histogramwidget.h
+
corestructs/histogramwidget.h
1
diff --git a/utils/uis/paintImageWidget.h b/utils/uis/paintImageWidget.h index 92517f342..428cf1d2b 100644 --- a/utils/uis/paintImageWidget.h +++ b/utils/uis/paintImageWidget.h @@ -3,7 +3,7 @@ #include #include "core/alignment/selectableGeometryFeatures.h" -#include "advancedImageWidget.h" +#include "uis/advancedImageWidget.h" #include "core/geometry/polygons.h" namespace Ui { diff --git a/utils/uis/pointsRectificationWidget.cpp b/utils/uis/pointsRectificationWidget.cpp index 1519b427e..bf32ccf38 100644 --- a/utils/uis/pointsRectificationWidget.cpp +++ b/utils/uis/pointsRectificationWidget.cpp @@ -1,6 +1,6 @@ #include "pointsRectificationWidget.h" #include "ui_pointsRectificationWidget.h" -#include "g12Image.h" +#include "corestructs/g12Image.h" #include "qtHelper.h" diff --git a/utils/uis/pointsRectificationWidget.ui b/utils/uis/pointsRectificationWidget.ui index 933f85e2f..9684c302d 100644 --- a/utils/uis/pointsRectificationWidget.ui +++ b/utils/uis/pointsRectificationWidget.ui @@ -203,7 +203,7 @@ PaintImageWidget QWidget -
paintImageWidget.h
+
uis/paintImageWidget.h
1
diff --git a/utils/uis/sourcelist.cmake b/utils/uis/sourcelist.cmake deleted file mode 100644 index 544414c27..000000000 --- a/utils/uis/sourcelist.cmake +++ /dev/null @@ -1,22 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) - -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) - - -if(opengl) - file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/cloudview/*.cpp) - file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/cloudview/*.h) - file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/cloudview/*.ui) - - message("Some more UIs ${CUR_UI_FILES}") - - set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) - set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) - set(UI_FILES ${UI_FILES} ${CUR_UI_FILES} ) -else() - message("OpenGL is off") -endif() diff --git a/utils/visitors/CMakeLists.txt b/utils/visitors/CMakeLists.txt new file mode 100644 index 000000000..0d4071544 --- /dev/null +++ b/utils/visitors/CMakeLists.txt @@ -0,0 +1,21 @@ +set(VISITORS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/baseXMLVisitor.h + ${CMAKE_CURRENT_LIST_DIR}/jsonGetter.h + ${CMAKE_CURRENT_LIST_DIR}/jsonSetter.h + ${CMAKE_CURRENT_LIST_DIR}/qSettingsGetter.h + ${CMAKE_CURRENT_LIST_DIR}/qSettingsSetter.h + ${CMAKE_CURRENT_LIST_DIR}/xmlGetter.h + ${CMAKE_CURRENT_LIST_DIR}/xmlSetter.h + PARENT_SCOPE + ) + +set(VISITORS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/baseXMLVisitor.cpp + ${CMAKE_CURRENT_LIST_DIR}/jsonGetter.cpp + ${CMAKE_CURRENT_LIST_DIR}/jsonSetter.cpp + ${CMAKE_CURRENT_LIST_DIR}/qSettingsGetter.cpp + ${CMAKE_CURRENT_LIST_DIR}/qSettingsSetter.cpp + ${CMAKE_CURRENT_LIST_DIR}/xmlGetter.cpp + ${CMAKE_CURRENT_LIST_DIR}/xmlSetter.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/visitors/sourcelist.cmake b/utils/visitors/sourcelist.cmake deleted file mode 100644 index 5b94afb80..000000000 --- a/utils/visitors/sourcelist.cmake +++ /dev/null @@ -1,8 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -list(REMOVE_ITEM CUR_SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/defaultSetterOld.cpp") -list(REMOVE_ITEM CUR_HDR_FILES "${CMAKE_CURRENT_LIST_DIR}/defaultSetterOld.h") - -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) - diff --git a/utils/widgets/CMakeLists.txt b/utils/widgets/CMakeLists.txt new file mode 100644 index 000000000..e9ebc7475 --- /dev/null +++ b/utils/widgets/CMakeLists.txt @@ -0,0 +1,40 @@ +set(WIDGETS_HEADER_FILES + ${CMAKE_CURRENT_LIST_DIR}/angleEditBox.h + ${CMAKE_CURRENT_LIST_DIR}/exponentialSlider.h + ${CMAKE_CURRENT_LIST_DIR}/foldableWidget.h + ${CMAKE_CURRENT_LIST_DIR}/graphPlotParametersControlWidget.h + ${CMAKE_CURRENT_LIST_DIR}/inputSelectorWidget.h + ${CMAKE_CURRENT_LIST_DIR}/loggerWidget.h + ${CMAKE_CURRENT_LIST_DIR}/observationListModel.h + ${CMAKE_CURRENT_LIST_DIR}/parameterEditorWidget.h + ${CMAKE_CURRENT_LIST_DIR}/parameterSelector.h + ${CMAKE_CURRENT_LIST_DIR}/parameterSlider.h + ${CMAKE_CURRENT_LIST_DIR}/patternDetectorParametersWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/shift3dWidget.h + ${CMAKE_CURRENT_LIST_DIR}/transform3DSelector.h + ${CMAKE_CURRENT_LIST_DIR}/vectorWidget.h + ${CMAKE_CURRENT_LIST_DIR}/generated/graphPlotParameters.h + ${CMAKE_CURRENT_LIST_DIR}/generated/graphStyle.h + ${CMAKE_CURRENT_LIST_DIR}/generated/patternFromPoseParameters.h + PARENT_SCOPE + ) + +set(WIDGETS_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/angleEditBox.cpp + ${CMAKE_CURRENT_LIST_DIR}/exponentialSlider.cpp + ${CMAKE_CURRENT_LIST_DIR}/foldableWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/graphPlotParametersControlWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/inputSelectorWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/loggerWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/observationListModel.cpp + ${CMAKE_CURRENT_LIST_DIR}/parameterEditorWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/parameterSelector.cpp + ${CMAKE_CURRENT_LIST_DIR}/parameterSlider.cpp + ${CMAKE_CURRENT_LIST_DIR}/patternDetectorParametersWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/shift3dWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/transform3DSelector.cpp + ${CMAKE_CURRENT_LIST_DIR}/vectorWidget.cpp + ${CMAKE_CURRENT_LIST_DIR}/generated/graphPlotParameters.cpp + ${CMAKE_CURRENT_LIST_DIR}/generated/patternFromPoseParameters.cpp + PARENT_SCOPE + ) \ No newline at end of file diff --git a/utils/widgets/graphPlotParametersControlWidget.cpp b/utils/widgets/graphPlotParametersControlWidget.cpp index 6863ce1ad..c41f740ad 100644 --- a/utils/widgets/graphPlotParametersControlWidget.cpp +++ b/utils/widgets/graphPlotParametersControlWidget.cpp @@ -9,8 +9,8 @@ #include "graphPlotParametersControlWidget.h" #include "ui_graphPlotParametersControlWidget.h" #include -#include "qSettingsGetter.h" -#include "qSettingsSetter.h" +#include "visitors/qSettingsGetter.h" +#include "visitors/qSettingsSetter.h" GraphPlotParametersControlWidget::GraphPlotParametersControlWidget(QWidget *parent, bool _autoInit, QString _rootPath) diff --git a/utils/widgets/graphPlotParametersControlWidget.h b/utils/widgets/graphPlotParametersControlWidget.h index 9785faa30..54204bd52 100644 --- a/utils/widgets/graphPlotParametersControlWidget.h +++ b/utils/widgets/graphPlotParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "generated/graphPlotParameters.h" #include "ui_graphPlotParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { class GraphPlotParametersControlWidget; diff --git a/utils/widgets/graphPlotParametersControlWidget.ui b/utils/widgets/graphPlotParametersControlWidget.ui index b5255db79..2f5e11f8b 100644 --- a/utils/widgets/graphPlotParametersControlWidget.ui +++ b/utils/widgets/graphPlotParametersControlWidget.ui @@ -240,7 +240,7 @@ ExponentialSlider QWidget -
exponentialSlider.h
+
widgets/exponentialSlider.h
1 valueChanged(double) diff --git a/utils/widgets/inputSelectorWidget.h b/utils/widgets/inputSelectorWidget.h index 9a0b1bc79..afad8e22c 100644 --- a/utils/widgets/inputSelectorWidget.h +++ b/utils/widgets/inputSelectorWidget.h @@ -2,7 +2,7 @@ #define INPUTSELECTORWIDGET_H #include -#include +#include #include "ui_inputSelectorWidget.h" class InputSelectorWidget : public QWidget, public SaveableWidget diff --git a/utils/widgets/observationListModel.cpp b/utils/widgets/observationListModel.cpp index 098d4bf92..1f48f42a5 100644 --- a/utils/widgets/observationListModel.cpp +++ b/utils/widgets/observationListModel.cpp @@ -1,5 +1,5 @@ #include "observationListModel.h" -#include "pointListEditImageWidget.h" /* We can circunavigate this dependacy*/ +#include "distortioncorrector/pointListEditImageWidget.h" /* We can circunavigate this dependacy*/ /* Model */ diff --git a/utils/widgets/patternDetectorParametersWidget.cpp b/utils/widgets/patternDetectorParametersWidget.cpp index 732085144..8b0109cd9 100644 --- a/utils/widgets/patternDetectorParametersWidget.cpp +++ b/utils/widgets/patternDetectorParametersWidget.cpp @@ -2,7 +2,7 @@ #include "ui_patternDetectorParametersWidget.h" #include "core/patterndetection/patternDetector.h" -#include +#include using namespace corecvs; diff --git a/utils/widgets/patternDetectorParametersWidget.h b/utils/widgets/patternDetectorParametersWidget.h index f19827409..64ef80e19 100644 --- a/utils/widgets/patternDetectorParametersWidget.h +++ b/utils/widgets/patternDetectorParametersWidget.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include "core/reflection/dynamicObject.h" #include "generated/patternFromPoseParameters.h" diff --git a/utils/widgets/sourcelist.cmake b/utils/widgets/sourcelist.cmake deleted file mode 100644 index bd10b77bf..000000000 --- a/utils/widgets/sourcelist.cmake +++ /dev/null @@ -1,13 +0,0 @@ -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/*.h) -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) - -file(GLOB CUR_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/generated/*.cpp) -file(GLOB CUR_HDR_FILES ${CMAKE_CURRENT_LIST_DIR}/generated/*.h) -set(SRC_FILES ${SRC_FILES} ${CUR_SRC_FILES}) -set(HDR_FILES ${HDR_FILES} ${CUR_HDR_FILES}) - -file(GLOB CUR_UI_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ui) -set(UI_FILES ${UI_FILES} ${CUR_UI_FILES}) - diff --git a/utils/widgets/transform3DSelector.h b/utils/widgets/transform3DSelector.h index 208ce3a36..91a3bfcfd 100644 --- a/utils/widgets/transform3DSelector.h +++ b/utils/widgets/transform3DSelector.h @@ -3,8 +3,8 @@ -#include "core/math/matrix/matrix44.h" -#include "ui_transform3DSelector.h" +#include "math/matrix/matrix44.h" +#include "ui_transform3DSelector.h" #include using corecvs::Matrix44; diff --git a/utils/widgets/vectorWidget.h b/utils/widgets/vectorWidget.h index fb694dece..d7395e985 100644 --- a/utils/widgets/vectorWidget.h +++ b/utils/widgets/vectorWidget.h @@ -3,7 +3,7 @@ #include #include -#include "parametersControlWidgetBase.h" +#include "corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt new file mode 100644 index 000000000..4095285e7 --- /dev/null +++ b/wrappers/CMakeLists.txt @@ -0,0 +1,25 @@ +set(SUBDIRECTORIES + apriltag_wrapper + atv + avcodec + #cblasLapack + #cgal + #directShow + #eigen + #gtest + #gts + joystick + jsonmodern + #libfftw + libjpeg + libpng + opencv + #pcl + #rapidjson + v4l2 + ) + +foreach(subdirectory ${SUBDIRECTORIES}) + message(STATUS "adding subdirectory/${subdirectory}") + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${subdirectory}) +endforeach(subdirectory) \ No newline at end of file diff --git a/wrappers/apriltag_wrapper/CMakeLists.txt b/wrappers/apriltag_wrapper/CMakeLists.txt new file mode 100644 index 000000000..6e9bd18d2 --- /dev/null +++ b/wrappers/apriltag_wrapper/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME wrappers) +init_project(PROJECT_NAME APRILTAGwrapper) + +set(PUBLIC_HEADER_FILES + apriltagDetector.h + generated/apriltagParameters.h + #generated/aprilTagType.h + ) + +set(HEADERS + ${PUBLIC_HEADER_FILES} + ) + +set(SOURCE_FILES + apriltagDetector.cpp + generated/apriltagParameters.cpp + ) + +set(SOURCES + ${SOURCE_FILES} + ) + +set(XML_FILES + xml/apriltag.xml + ) + +set(TOOLS_GENERATOR_FILE + ${CMAKE_CURRENT_LIST_DIR}/../../tools/generator/regen-apriltag.sh + ) + +set(RESOURCES + ${XML_FILES} + ${TOOLS_GENERATOR_FILE} + ) + +assign_source_group(${HEADERS} ${SOURCES} ${RESOURCES}) + +add_library(${PROJECT_NAME} SHARED + ${HEADERS} + ${SOURCES} + ${RESOURCES} + ) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) + +target_link_libraries(${PROJECT_NAME} + PUBLIC + APRILTAG::APRILTAG + PRIVATE + corecvs + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/wrappers/apriltag_wrapper/sourcelist.cmake b/wrappers/apriltag_wrapper/sourcelist.cmake deleted file mode 100644 index f5113fcb5..000000000 --- a/wrappers/apriltag_wrapper/sourcelist.cmake +++ /dev/null @@ -1,24 +0,0 @@ -set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/apriltagDetector.h - ${CMAKE_CURRENT_LIST_DIR}/generated/apriltagParameters.h - ) - -set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/apriltagDetector.cpp - ${CMAKE_CURRENT_LIST_DIR}/generated/apriltagParameters.cpp - ) - - -set (INC_PATHS - ${INC_PATHS} - ${CMAKE_CURRENT_LIST_DIR} - ${APRILTAG_INCLUDE_DIR} - ) - -# Additional stuff mostly for IDE only -file(GLOB CURR_ADD_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/xml/*.xml) -set(ADD_SRC_FILES ${ADD_SRC_FILES} ${CURR_ADD_SRC_FILES} ) -file(GLOB CURR_ADD_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/../../tools/generator/regen-apriltag.sh) -set(ADD_SRC_FILES ${ADD_SRC_FILES} ${CURR_ADD_SRC_FILES} ) diff --git a/wrappers/atv/CMakeLists.txt b/wrappers/atv/CMakeLists.txt new file mode 100644 index 000000000..5033d29e4 --- /dev/null +++ b/wrappers/atv/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME wrappers) +init_project(PROJECT_NAME ATVCAMERAwrapper) + +set(PUBLIC_HEADER_FILES + atvCapture.h + filter.h + ) + +set(HEADERS + ${PUBLIC_HEADER_FILES} + ) + +set(SOURCE_FILES + atvCapture.cpp + filter.cpp + ) + +set(SOURCES + ${SOURCE_FILES} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_library(${PROJECT_NAME} SHARED + ${HEADERS} + ${SOURCES} + ) + +add_definitions(-DWITH_ATVCAMERA) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lfftw3f") + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +# ${FFTW_INCLUDE_DIR} + ) + +target_link_libraries(${PROJECT_NAME} + PUBLIC + corecvs + SoapySDR + ${FFTW_LIB} + ) + +# FIXME +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lfftw3f") +#set(LIBS ${LIBS} ${FFTW_LIB}) +#set (INC_PATHS +# ${INC_PATHS} +# ${FFTW_INCLUDE_DIR} +# ) diff --git a/wrappers/atv/atvCapture.cpp b/wrappers/atv/atvCapture.cpp new file mode 100644 index 000000000..57193c842 --- /dev/null +++ b/wrappers/atv/atvCapture.cpp @@ -0,0 +1,393 @@ +/** + * \file ATVCapture.cpp + * \brief Analogue TV decoder for SDR + * + * \date Mar 13, 2020 + * \author Ilya + */ + +#include "atvCapture.h" + + +u_short next_4(u_short i) +{ + return (i == 3) ? 0 : (i + 1); +} + + +ATVCapture::ATVCapture(const std::string& channel, bool isRGB) : + ATVCapture(getChannelFreq(channel), isRGB) {} + + +ATVCapture::ATVCapture(double channelFreq, bool isRGB) : + mIsPaused(true), mIsRGB(isRGB), centerFreq(channelFreq) {} + + +ImageCaptureInterface::CapErrorCode ATVCapture::initCapture() +{ + SYNC_PRINT(("ATVCapture::initCapture(): called\n")); + + if (centerFreq == -1) + { + SYNC_PRINT(("ATVCapture::initCapture(): Wrong center frequency value\n")); + return ImageCaptureInterface::FAILURE; + } + // TODO: automatic chose of device + + try { + SoapySDR::Kwargs args = SoapySDR::KwargsFromString("driver=hackrf"); + SDR = SoapySDR::Device::make(args); + } catch (...) { + SYNC_PRINT(("ATVCapture::initCapture(): Got an exeption from device creation\n")); + } + + + if (SDR == nullptr) + { + SYNC_PRINT(("ATVCapture::initCapture(): Unable to make a device\n")); + return ImageCaptureInterface::FAILURE; + } + + SDR->setSampleRate(SOAPY_SDR_RX, 0, sampleRate); + SDR->setFrequency (SOAPY_SDR_RX, 0, centerFreq); + rxStream = SDR->setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32); + + lumBackFrame = new G12Buffer(cameraFormat.height, cameraFormat.width); + lumFrontFrame = new G12Buffer(cameraFormat.height, cameraFormat.width); + backFrame = new RGB24Buffer(cameraFormat.height, cameraFormat.width); + frontFrame = new RGB24Buffer(cameraFormat.height, cameraFormat.width); + + input = (fftwf_complex*) fftw_malloc(sizeof(fftwf_complex) * buffSize); + output = (fftwf_complex*) fftw_malloc(sizeof(fftwf_complex) * buffSize); + freqLum = (fftwf_complex*) fftw_malloc(sizeof(fftwf_complex) * buffSize); + freqColor = (fftwf_complex*) fftw_malloc(sizeof(fftwf_complex) * buffSize); + lum = (fftwf_complex*) fftw_malloc(sizeof(fftwf_complex) * buffSize); + color = (fftwf_complex*) fftw_malloc(sizeof(fftwf_complex) * buffSize); + + forwardTransform = fftwf_plan_dft_1d(buffSize, input, output, FFTW_FORWARD, FFTW_PATIENT); + backwardLumTransform = fftwf_plan_dft_1d(buffSize, freqLum, lum, FFTW_BACKWARD, FFTW_PATIENT); + backwardColorTransform = fftwf_plan_dft_1d(buffSize, freqColor, color, FFTW_BACKWARD, FFTW_PATIENT); + + SYNC_PRINT(("ATVCapture::initCapture(): exited\n")); + return ImageCaptureInterface::SUCCESS; +} + + +ImageCaptureInterface::CapErrorCode ATVCapture::startCapture() +{ + SYNC_PRINT(("ATVCapture::startCapture(): called\n")); + + SDR->activateStream(rxStream, 0, 0, 0); + mIsPaused = false; + + receiver = std::thread(&ATVCapture::receiving, this); + filter = std::thread(&ATVCapture::filtering, this); + decoder = std::thread(&ATVCapture::decoding, this); + + SYNC_PRINT(("ATVCapture::startCapture(): exited\n")); + return ImageCaptureInterface::SUCCESS; +} + + +void ATVCapture::receiving() +{ + for (u_char i = 3; !mIsPaused; (i == 3) ? (i = 0) : (i++)) + { + bufferMutex[i].lock(); + + void *buffs[] = {buff[i]}; + int flags; + long long time_ns; + SDR->readStream(rxStream, buffs, buffSize, flags, time_ns, 1e5); + + bufferMutex[i].unlock(); + } +} + + +void ATVCapture::filtering() +{ + float re, im; + for (u_char i = 2; !mIsPaused; i = next_4(i)) + { + bufferMutex[i].lock(); + + // any filtering should be here + + for (u_short sampleNumber = 0; sampleNumber < buffSize; sampleNumber++) + { + input[sampleNumber][0] = buff[i][sampleNumber].real(); + input[sampleNumber][1] = buff[i][sampleNumber].imag(); + } + + fftwf_execute(forwardTransform); + + filterLum (input, freqLum, buffSize); + filterColor(input, freqColor, buffSize); + + fftwf_execute(backwardLumTransform); + fftwf_execute(backwardColorTransform); + + for (u_short sampleNumber = 0; sampleNumber < buffSize; sampleNumber++) + { + re = lum[sampleNumber][0]; im = lum[sampleNumber][1]; + buff[i][sampleNumber].real(fmin(100, sqrt(re * re + im * im))); + buff[i][sampleNumber].imag(0 /* some info about color */); + } + + bufferMutex[i].unlock(); + } +} + + +void ATVCapture::decoding() +{ + bufferMutex[0].lock(); + + u_char signalState = IDLE; + auto samplesCount = 0; + u_short lineNumber = 0; + u_short x; + for (u_char i = 0; !mIsPaused; i = next_4(i)) + { + bufferMutex[(i == 3) ? 0 : (i + 1)].lock(); + + for (u_short sampleNumber = 0; sampleNumber < buffSize; sampleNumber++) + { + switch (signalState) + { + case IDLE: + if (buff[i][sampleNumber].real() > HORIZONTAL_SYNC_THRESHOLD && + ((sampleNumber == buffSize - 1) ? buff[next_4(i)][0] : buff[i][sampleNumber + 1]).real() < + HORIZONTAL_SYNC_THRESHOLD) + { + signalState = HORIZONTAL_SYNC; + samplesCount = 0; + } + break; + case HORIZONTAL_SYNC: + if (samplesCount > HORIZONTAL_SYNC_DURATION * sampleRate) + { + signalState = BACK_PORCH; + samplesCount = 0; + } + break; + case BACK_PORCH: + if (samplesCount > BACK_PORCH_DURATION * sampleRate) + { + signalState = VIDEO; + samplesCount = 0; + } + break; + case VIDEO: + x = int(cameraFormat.width * samplesCount / (VIDEO_DURATION * sampleRate)); + lumBackFrame->element(lineNumber, x) = int( + (buff[i][sampleNumber].real() - BLACK_LEVEL) / (WHITE_LEVEL - BLACK_LEVEL) * 254); + if (samplesCount > VIDEO_DURATION * sampleRate) + { + signalState = FRONT_PORCH; + samplesCount = 0; + if (lineNumber == 525) + lineNumber = 2; + else + lineNumber += 2; + } + if (buff[i][sampleNumber].real() > HORIZONTAL_SYNC_THRESHOLD && + ((sampleNumber == buffSize - 1) ? buff[next_4(i)][0] : buff[i][sampleNumber + 1]).real() < + HORIZONTAL_SYNC_THRESHOLD && + samplesCount < 0.75 * VIDEO_DURATION * sampleRate) + { + signalState = VERTICAL_SYNC; + samplesCount = 0; + } + break; + case FRONT_PORCH: + if (buff[i][sampleNumber].real() > HORIZONTAL_SYNC_THRESHOLD && + ((sampleNumber == buffSize - 1) ? buff[next_4(i)][0] : buff[i][sampleNumber + 1]).real() < + HORIZONTAL_SYNC_THRESHOLD) + { + signalState = HORIZONTAL_SYNC; + samplesCount = 0; + } + if (samplesCount > FRONT_PORCH_DURATION * sampleRate) + { + signalState = HORIZONTAL_SYNC; + samplesCount = 0; + } + break; + case VERTICAL_SYNC: + if (buff[i][sampleNumber].real() > VERTICAL_SYNC_LEVEL) + { + lineNumber = 0; + signalState = IDLE; + std::swap(lumBackFrame, lumFrontFrame); + std::swap(backFrame, frontFrame); + ImageCaptureInterface::FrameMetadata frameData{}; + notifyAboutNewFrame(frameData); + } + break; + default: SYNC_PRINT(("ATVCamera::decoding(): wrong signalState\n")); + } + } + + bufferMutex[i].unlock(); + } + // bufferMutex[i].unlock(); +} + + +ImageCaptureInterface::CapErrorCode ATVCapture::pauseCapture() +{ + SYNC_PRINT(("ATVCapture::pauseCapture(): called. Pause is %s\n", mIsPaused ? "ON" : "OFF")); + + if (mIsPaused) + { + mIsPaused = !mIsPaused; + return startCapture(); + } + else + { + mIsPaused = !mIsPaused; + receiver.join(); + filter .join(); + decoder .join(); + SDR->deactivateStream(rxStream, 0, 0); + return ImageCaptureInterface::SUCCESS; + } +} + + +bool ATVCapture::supportPause() +{ return true; } + + +ImageCaptureInterface::FramePair ATVCapture::getFrame() +{ + FramePair result(nullptr, nullptr); + result.setRgbBufferLeft(frontFrame); + result.setBufferLeft(lumFrontFrame); + return result; +} + + +ATVCapture::~ATVCapture() +{ + SYNC_PRINT(("ATVCapture::~ATVCapture(): called\n")); + + pauseCapture(); + + fftwf_destroy_plan(forwardTransform); + fftwf_destroy_plan(backwardLumTransform); + fftwf_destroy_plan(backwardColorTransform); + + fftwf_free(input); + fftwf_free(output); + fftwf_free(freqLum); + fftwf_free(freqColor); + fftwf_free(lum); + fftwf_free(color); + + SDR->closeStream(rxStream); + SoapySDR::Device::unmake(SDR); + + SYNC_PRINT(("ATVCapture::~ATVCapture(): exited\n")); +} + + +double ATVCapture::getChannelFreq(std::string channel) +{ + unsigned short frequency; + unsigned short frequencies[10][8] = { + {5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725}, + {5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866}, + {5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945}, + {5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880}, + {5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917}, + {5362, 5399, 5436, 5473, 5510, 5547, 5584, 5621}, + {5325, 5348, 5366, 5384, 5402, 5420, 5438, 5456}, + {5474, 5492, 5510, 5528, 5546, 5564, 5582, 5600}, + {5333, 5373, 5413, 5453, 5493, 5533, 5573, 5613}, + {5653, 5693, 5733, 5773, 5813, 5853, 5893, 5933} + }; + + if (channel[1] > '8' || channel[1] < '1') + { + SYNC_PRINT (("ATVCapture: Channel name is wrong\n")); + return -1; + } + + switch (channel[0]) + { + case 'A': frequency = frequencies[0][channel[1] - 1 - '0']; break; + case 'B': frequency = frequencies[1][channel[1] - 1 - '0']; break; + case 'E': frequency = frequencies[2][channel[1] - 1 - '0']; break; + case 'F': frequency = frequencies[3][channel[1] - 1 - '0']; break; + case 'R': frequency = frequencies[4][channel[1] - 1 - '0']; break; + case 'D': frequency = frequencies[5][channel[1] - 1 - '0']; break; + case 'U': frequency = frequencies[6][channel[1] - 1 - '0']; break; + case 'O': frequency = frequencies[7][channel[1] - 1 - '0']; break; + case 'L': frequency = frequencies[8][channel[1] - 1 - '0']; break; + case 'H': frequency = frequencies[9][channel[1] - 1 - '0']; break; + default: SYNC_PRINT (("ATVCapture: Channel name is wrong\n")); return -1; + } + return 1e6 * frequency; +} + +ImageCaptureInterface::CapErrorCode ATVCapture::queryCameraParameters(CameraParameters ¶meter) +{ + parameter.mCameraControls[CameraParameters::GAIN].setActive (true); + parameter.mCameraControls[CameraParameters::GAIN].setMinimum (0); + parameter.mCameraControls[CameraParameters::GAIN].setMaximum (100000); + parameter.mCameraControls[CameraParameters::GAIN].setDefaultValue(50000); + + parameter.mCameraControls[CameraParameters::BRIGHTNESS].setActive (true); + parameter.mCameraControls[CameraParameters::BRIGHTNESS].setMinimum (0); + parameter.mCameraControls[CameraParameters::BRIGHTNESS].setMaximum (100000); + parameter.mCameraControls[CameraParameters::BRIGHTNESS].setDefaultValue(50000); + + parameter.mCameraControls[CameraParameters::CONTRAST].setActive (true); + parameter.mCameraControls[CameraParameters::CONTRAST].setMinimum (0); + parameter.mCameraControls[CameraParameters::CONTRAST].setMaximum (100000); + parameter.mCameraControls[CameraParameters::CONTRAST].setDefaultValue(50000); + + return ImageCaptureInterface::SUCCESS; +} + +ImageCaptureInterface::CapErrorCode ATVCapture::setCaptureProperty(int id, int value) +{ + switch (id) { + case CameraParameters::GAIN: + gain = value; + return ImageCaptureInterface::SUCCESS; + case CameraParameters::BRIGHTNESS: + brightness = value; + return ImageCaptureInterface::SUCCESS; + case CameraParameters::CONTRAST: + contrast = value; + return ImageCaptureInterface::SUCCESS; + default: + break; + + } + return ImageCaptureInterface::FAILURE; +} + +ImageCaptureInterface::CapErrorCode ATVCapture::getCaptureProperty(int id, int *value) +{ + switch (id) { + case CameraParameters::GAIN: + *value = gain; + return ImageCaptureInterface::SUCCESS; + case CameraParameters::BRIGHTNESS: + *value = brightness; + return ImageCaptureInterface::SUCCESS; + case CameraParameters::CONTRAST: + *value = contrast; + return ImageCaptureInterface::SUCCESS; + default: + break; + + } + return ImageCaptureInterface::FAILURE; + +} diff --git a/wrappers/atv/atvCapture.h b/wrappers/atv/atvCapture.h new file mode 100644 index 000000000..42c0deae8 --- /dev/null +++ b/wrappers/atv/atvCapture.h @@ -0,0 +1,134 @@ +/** + * \file ATVCapture.cpp + * \brief Analogue TV decoder for SDR + * + * \date Mar 13, 2020 + * \author Ilya + */ + +#ifndef CORECVS_ATV_H_ +#define CORECVS_ATV_H_ + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "framesources/cameraControlParameters.h" +#include "framesources/imageCaptureInterface.h" +#include "filter.h" + + +class ATVCapture : public virtual ImageCaptureInterface +{ +public: + ATVCapture(double channelFreq, bool isRGB); + ATVCapture(const std::string &channel, bool isRGB); + + ImageCaptureInterface::CapErrorCode initCapture() override; + ImageCaptureInterface::CapErrorCode startCapture() override; + ImageCaptureInterface::CapErrorCode pauseCapture() override; + ImageCaptureInterface::FramePair getFrame() override; + + ~ATVCapture() override; + + bool supportPause() override; + bool mIsPaused; + bool mIsRGB; + + CameraFormat cameraFormat = CameraFormat(525, 700, 30); + +private: + constexpr static const double sampleRate = 10e6; + const double centerFreq; + static const short buffSize = 1024; + + SoapySDR::Device* SDR = NULL; + SoapySDR::Stream* rxStream = NULL; + + void receiving(); + void filtering(); + void decoding(); + + std::thread receiver, filter, decoder; + std::complex buff[4][buffSize]; + std::mutex bufferMutex[4]; + + // double buffering with page flipping + G12Buffer *lumBackFrame, *lumFrontFrame; + RGB24Buffer *backFrame, *frontFrame; + + // buffers for FFTW + fftwf_complex *input, *output, *freqLum, *freqColor, *lum, *color; + + fftwf_plan forwardTransform, backwardLumTransform, backwardColorTransform; + + static double getChannelFreq(std::string channel); + + std::vector debug = {0}; + + // ImageCaptureInterface interface +public: + int gain = 0; + int brightness = 0; + int contrast = 0; + + virtual CapErrorCode queryCameraParameters(CameraParameters ¶meter) override; + virtual CapErrorCode setCaptureProperty(int id, int value) override; + virtual CapErrorCode getCaptureProperty(int id, int *value) override; +}; + + +class ATVCaptureProducer : public ImageCaptureInterfaceProducer +{ +public: + ATVCaptureProducer() = default; + + std::string getPrefix() override + { + return "atv:"; + } + + ImageCaptureInterface* produce(std::string &name, bool isRGB) override + { + return new ATVCapture(name, isRGB); + } +}; + +#define HORIZONTAL_SYNC_DURATION 4.7 * 0.000001 +#define BACK_PORCH_DURATION 4.7 * 0.000001 +#define VIDEO_DURATION 52.6 * 0.000001 +#define FRONT_PORCH_DURATION 1.5 * 0.000001 +#define LINE_DURATION 63.5 * 0.000001 + +#define IDLE 1 +#define LINES_TRANSMISSION 2 +#define FRONT_PORCH 3 +#define HORIZONTAL_SYNC 4 +#define BACK_PORCH 5 +#define VIDEO 6 +#define VERTICAL_SYNC 7 +#define EQUALISING 8 +#define SERRATION 9 +#define BLANKING 10 +#define EVEN 1 +#define ODD 0 + +#define BLACK_LEVEL 0 +#define WHITE_LEVEL 0 +#define HORIZONTAL_SYNC_THRESHOLD 0 +#define HORIZONTAL_SYNC_LEVEL 0 +#define BACK_PORCH_LEVEL 0 +#define FRONT_PORCH_LEVEL 0 +#define EQUALISING_LEVEL 0 +#define VERTICAL_SYNC_LEVEL 0 + +#endif /* CORECVS_ATV_H_ */ diff --git a/wrappers/atv/filter.cpp b/wrappers/atv/filter.cpp new file mode 100644 index 000000000..bd0dae664 --- /dev/null +++ b/wrappers/atv/filter.cpp @@ -0,0 +1,29 @@ +#include "filter.h" + +void filterLum(fftwf_complex *input, fftwf_complex *output, u_short buffSize) +{ + for (u_short freqNumber = 0; freqNumber < (buffSize / 2); freqNumber++) + { + output[freqNumber][0] = input[freqNumber][0]; + output[freqNumber][1] = input[freqNumber][1]; + } + for (u_short freqNumber = (buffSize / 2); freqNumber < buffSize; freqNumber++) + { + output[freqNumber][0] = 0; + output[freqNumber][1] = 0; + } +} + +void filterColor(fftwf_complex *input, fftwf_complex *output, u_short buffSize) +{ + for (u_short freqNumber = 0; freqNumber < (buffSize / 2); freqNumber++) + { + output[freqNumber][0] = 0; + output[freqNumber][1] = 0; + } + for (u_short freqNumber = (buffSize / 2); freqNumber < buffSize; freqNumber++) + { + output[freqNumber][0] = input[freqNumber][0]; + output[freqNumber][1] = input[freqNumber][1]; + } +} diff --git a/wrappers/atv/filter.h b/wrappers/atv/filter.h new file mode 100644 index 000000000..b69e922a8 --- /dev/null +++ b/wrappers/atv/filter.h @@ -0,0 +1,12 @@ +#ifndef ATV_FILTER_H +#define ATV_FILTER_H + +#include +#include + + +void filterLum(fftwf_complex *input, fftwf_complex *output, u_short buffSize); + +void filterColor(fftwf_complex *input, fftwf_complex *output, u_short buffSize); + +#endif //ATV_FILTER_H diff --git a/wrappers/atv/sourcelist.cmake b/wrappers/atv/sourcelist.cmake new file mode 100644 index 000000000..de5f01c37 --- /dev/null +++ b/wrappers/atv/sourcelist.cmake @@ -0,0 +1,27 @@ +project(ATVCAMERA) + +set(HDR_FILES + ${HDR_FILES} + ${CMAKE_CURRENT_LIST_DIR}/atvCapture.h + ${CMAKE_CURRENT_LIST_DIR}/filter.h + ) + + +set(SRC_FILES + ${SRC_FILES} + ${CMAKE_CURRENT_LIST_DIR}/atvCapture.cpp + ${CMAKE_CURRENT_LIST_DIR}/filter.cpp + ) + +add_definitions(-DWITH_ATVCAMERA) +include_directories(${CMAKE_CURRENT_LIST_DIR}) + +set(LIBS ${LIBS} SoapySDR) + +# FIXME +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lfftw3f") +set(LIBS ${LIBS} ${FFTW_LIB}) +set (INC_PATHS + ${INC_PATHS} + ${FFTW_INCLUDE_DIR} + ) diff --git a/wrappers/avcodec/CMakeLists.txt b/wrappers/avcodec/CMakeLists.txt new file mode 100644 index 000000000..5db850e94 --- /dev/null +++ b/wrappers/avcodec/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME wrappers) +init_project(PROJECT_NAME AVCODECwrapper) + +set(PUBLIC_HEADER_FILES + aviCapture.h + rtspCapture.h + avEncoder.h + swScaler.h + ) + +set(HEADERS + ${PUBLIC_HEADER_FILES} + ) + +set(SOURCE_FILES + aviCapture.cpp + rtspCapture.cpp + avEncoder.cpp + swScaler.cpp + ) + +set(SOURCES + ${SOURCE_FILES} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_library(${PROJECT_NAME} SHARED + ${HEADERS} + ${SOURCES} + ) + +add_definitions(-DWITH_AVCODEC -DWITH_SWSCALE) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${AVCODEC_INCLUDES} + ) + +target_link_libraries(${PROJECT_NAME} + PUBLIC + ${AVCODEC_LIBS} + PRIVATE + corecvs + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/wrappers/avcodec/aviCapture.cpp b/wrappers/avcodec/aviCapture.cpp index d628861f4..123a1395b 100644 --- a/wrappers/avcodec/aviCapture.cpp +++ b/wrappers/avcodec/aviCapture.cpp @@ -3,7 +3,7 @@ */ #include "aviCapture.h" -#include "core/utils/preciseTimer.h" +#include "utils/preciseTimer.h" extern "C" { #include diff --git a/wrappers/avcodec/rtspCapture.h b/wrappers/avcodec/rtspCapture.h index 45d9df969..43a4a1458 100644 --- a/wrappers/avcodec/rtspCapture.h +++ b/wrappers/avcodec/rtspCapture.h @@ -19,8 +19,8 @@ extern "C" { #include } -#include "core/framesources/imageCaptureInterface.h" -#include "core/utils/preciseTimer.h" +#include "framesources/imageCaptureInterface.h" +#include "utils/preciseTimer.h" class RTSPCapture : public virtual ImageCaptureInterface { diff --git a/wrappers/avcodec/sourcelist.cmake b/wrappers/avcodec/sourcelist.cmake deleted file mode 100644 index 913f28453..000000000 --- a/wrappers/avcodec/sourcelist.cmake +++ /dev/null @@ -1,23 +0,0 @@ -set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/aviCapture.h - ${CMAKE_CURRENT_LIST_DIR}/rtspCapture.h - ${CMAKE_CURRENT_LIST_DIR}/avEncoder.h - ${CMAKE_CURRENT_LIST_DIR}/swScaler.h - -) - - -set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/aviCapture.cpp - ${CMAKE_CURRENT_LIST_DIR}/rtspCapture.cpp - ${CMAKE_CURRENT_LIST_DIR}/avEncoder.cpp - ${CMAKE_CURRENT_LIST_DIR}/swScaler.cpp - -) - -add_definitions(-DWITH_AVCODEC -DWITH_SWSCALE) -include_directories(${CMAKE_CURRENT_LIST_DIR}) - -set(LIBS ${LIBS} ${AVCODEC_LIBS}) diff --git a/wrappers/directShow/lib64/capdll.h b/wrappers/directShow/lib64/capdll.h index 2f1cb45ab..b402ce0f2 100644 --- a/wrappers/directShow/lib64/capdll.h +++ b/wrappers/directShow/lib64/capdll.h @@ -8,6 +8,7 @@ // CAPDLL_API functions as being imported from a DLL, whereas this DLL sees symbols // defined with this macro as being exported. +#ifdef WIN32 #ifdef CAPDLL_EXPORTS # define CAPDLL_API __declspec(dllexport) # ifdef _MSC_VER @@ -19,6 +20,10 @@ # pragma message ( "Importing capdll funcs" ) # endif #endif +#else +// Linux +# define CAPDLL_API +#endif extern "C" { diff --git a/wrappers/joystick/CMakeLists.txt b/wrappers/joystick/CMakeLists.txt new file mode 100644 index 000000000..67d5f1d23 --- /dev/null +++ b/wrappers/joystick/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME wrappers) +init_project(PROJECT_NAME JOYSTICKwrapper) + +set(PUBLIC_HEADER_FILE + linuxJoystickInterface.h + ) + +set(HEADERS + ${PUBLIC_HEADER_FILE} + ) + +set(SOURCE_FILE + linuxJoystickInterface.cpp + ) + +set(SOURCES + ${SOURCE_FILE} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_library(${PROJECT_NAME} SHARED + ${HEADERS} + ${SOURCES} + ) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/wrappers/joystick/linuxJoystickInterface.cpp b/wrappers/joystick/linuxJoystickInterface.cpp index e69db5ee2..011ff1759 100644 --- a/wrappers/joystick/linuxJoystickInterface.cpp +++ b/wrappers/joystick/linuxJoystickInterface.cpp @@ -13,6 +13,12 @@ using namespace std; using namespace corecvs; +LinuxJoystickInterface::LinuxJoystickInterface(const string &deviceName) +{ + mDeviceName = deviceName; + SYNC_PRINT(("LinuxJoystickInterface::LinuxJoystickInterface(%s):called\n", deviceName.c_str())); +} + vector LinuxJoystickInterface::getDevices(const string &prefix) { vector toReturn; @@ -86,7 +92,7 @@ JoystickConfiguration LinuxJoystickInterface::getConfiguration(const std::string JoystickConfiguration LinuxJoystickInterface::getConfiguration() { if (mJoystickDevice == -1) { - SYNC_PRINT(("Device not open\n")); + SYNC_PRINT(("LinuxJoystickInterface::getConfiguration(): Device not open\n")); return JoystickConfiguration(); } diff --git a/wrappers/joystick/linuxJoystickInterface.h b/wrappers/joystick/linuxJoystickInterface.h index c1f34523c..095833c14 100644 --- a/wrappers/joystick/linuxJoystickInterface.h +++ b/wrappers/joystick/linuxJoystickInterface.h @@ -5,7 +5,7 @@ #include #include -#include +#include namespace std { class thread; @@ -14,15 +14,13 @@ namespace std { class LinuxJoystickInterface : public virtual corecvs::JoystickInterface { public: - LinuxJoystickInterface(const std::string &deviceName): - corecvs::JoystickInterface(deviceName) - {} + LinuxJoystickInterface(const std::string &deviceName); static std::vector getDevices (const std::string &prefix = "/dev/input/js"); static corecvs::JoystickConfiguration getConfiguration(const std::string &deviceName); - corecvs::JoystickConfiguration getConfiguration(); + corecvs::JoystickConfiguration getConfiguration() override; virtual bool start() override; virtual void stop() override; diff --git a/wrappers/joystick/sourcelist.cmake b/wrappers/joystick/sourcelist.cmake deleted file mode 100644 index 661ab1c6e..000000000 --- a/wrappers/joystick/sourcelist.cmake +++ /dev/null @@ -1,11 +0,0 @@ -set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/linuxJoystickInterface.h -) -include_directories(${CMAKE_CURRENT_LIST_DIR}) - -set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/linuxJoystickInterface.cpp -) - diff --git a/wrappers/jsonmodern/CMakeLists.txt b/wrappers/jsonmodern/CMakeLists.txt new file mode 100644 index 000000000..6eb191186 --- /dev/null +++ b/wrappers/jsonmodern/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME wrappers) +init_project(PROJECT_NAME JSONMODERNwrapper) + +set(PUBLIC_HEADER_FILES + jsonModernReader.h + sources/src/json.hpp + ) + +set(HEADERS + ${PUBLIC_HEADER_FILES} + ) + +set(SOURCE_FILE + jsonModernReader.cpp + ) + +set(SOURCES + ${SOURCE_FILE} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_library(${PROJECT_NAME} SHARED + ${HEADERS} + ${SOURCES} + ) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + corecvs + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/wrappers/jsonmodern/jsonModernReader.cpp b/wrappers/jsonmodern/jsonModernReader.cpp index 16d43a351..165868704 100644 --- a/wrappers/jsonmodern/jsonModernReader.cpp +++ b/wrappers/jsonmodern/jsonModernReader.cpp @@ -1,7 +1,7 @@ #include #include -#include "core/utils/utils.h" +#include "utils/utils.h" #include "jsonModernReader.h" using namespace corecvs; diff --git a/wrappers/jsonmodern/jsonModernReader.h b/wrappers/jsonmodern/jsonModernReader.h index 789313da6..05a2a1539 100644 --- a/wrappers/jsonmodern/jsonModernReader.h +++ b/wrappers/jsonmodern/jsonModernReader.h @@ -9,9 +9,9 @@ # define noexcept_if(pred) noexcept((pred)) #endif -#include "json.hpp" +#include "sources/src/json.hpp" -#include "core/reflection/reflection.h" +#include "reflection/reflection.h" using corecvs::IntField; using corecvs::Int64Field; diff --git a/wrappers/jsonmodern/sourcelist.cmake b/wrappers/jsonmodern/sourcelist.cmake deleted file mode 100644 index 189abf007..000000000 --- a/wrappers/jsonmodern/sourcelist.cmake +++ /dev/null @@ -1,15 +0,0 @@ -set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/jsonModernReader.h - ${CMAKE_CURRENT_LIST_DIR}/sources/src/json.hpp -) - -set (INC_PATHS - ${INC_PATHS} - ${CMAKE_CURRENT_LIST_DIR}/sources/src/ -) - -set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/jsonModernReader.cpp -) diff --git a/wrappers/jsonmodern/sources/src/json.hpp b/wrappers/jsonmodern/sources/src/json.hpp index 5c9ed7d9c..91cd2a293 100644 --- a/wrappers/jsonmodern/sources/src/json.hpp +++ b/wrappers/jsonmodern/sources/src/json.hpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 2.1.1 +| | |__ | | | | | | version 3.0.0 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -29,7 +29,7 @@ SOFTWARE. #ifndef NLOHMANN_JSON_HPP #define NLOHMANN_JSON_HPP -#include // all_of, copy, fill, find, for_each, none_of, remove, reverse, transform +#include // all_of, copy, fill, find, for_each, generate_n, none_of, remove, reverse, transform #include // array #include // assert #include // and, not, or @@ -38,11 +38,12 @@ SOFTWARE. #include // nullptr_t, ptrdiff_t, size_t #include // int64_t, uint64_t #include // abort, strtod, strtof, strtold, strtoul, strtoll, strtoull -#include // strlen +#include // memcpy, strlen #include // forward_list #include // function, hash, less #include // initializer_list -#include // istream, ostream +#include // hex +#include // istream, ostream #include // advance, begin, back_inserter, bidirectional_iterator_tag, distance, end, inserter, iterator, iterator_traits, next, random_access_iterator_tag, reverse_iterator #include // numeric_limits #include // locale @@ -53,6 +54,7 @@ SOFTWARE. #include // getline, stoi, string, to_string #include // add_pointer, conditional, decay, enable_if, false_type, integral_constant, is_arithmetic, is_base_of, is_const, is_constructible, is_convertible, is_default_constructible, is_enum, is_floating_point, is_integral, is_nothrow_move_assignable, is_nothrow_move_constructible, is_pointer, is_reference, is_same, is_scalar, is_signed, remove_const, remove_cv, remove_pointer, remove_reference, true_type, underlying_type #include // declval, forward, make_pair, move, pair, swap +#include // valarray #include // vector // exclude unsupported compilers @@ -60,7 +62,7 @@ SOFTWARE. #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" #endif -#elif defined(__GNUC__) +#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" #endif @@ -98,6 +100,23 @@ SOFTWARE. #define JSON_CATCH(exception) if(false) #endif +// manual branch prediction +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #define JSON_LIKELY(x) __builtin_expect(!!(x), 1) + #define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0) +#else + #define JSON_LIKELY(x) x + #define JSON_UNLIKELY(x) x +#endif + +// C++ language standard detection +#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 +#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) + #define JSON_HAS_CPP_14 +#endif + /*! @brief namespace for Niels Lohmann @see https://github.com/nlohmann @@ -105,6 +124,36 @@ SOFTWARE. */ namespace nlohmann { +template +struct adl_serializer; + +// forward declaration of basic_json (required to split the class) +template class ObjectType = std::map, + template class ArrayType = std::vector, + class StringType = std::string, class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template class AllocatorType = std::allocator, + template class JSONSerializer = adl_serializer> +class basic_json; + +// Ugly macros to avoid uglier copy-paste when specializing basic_json. They +// may be removed in the future once the class is split. + +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template class ObjectType, \ + template class ArrayType, \ + class StringType, class BooleanType, class NumberIntegerType, \ + class NumberUnsignedType, class NumberFloatType, \ + template class AllocatorType, \ + template class JSONSerializer> + +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json + /*! @brief unnamed namespace with internal helper functions @@ -123,12 +172,28 @@ namespace detail /*! @brief general exception of the @ref basic_json class -Extension of std::exception objects with a member @a id for exception ids. +This class is an extension of `std::exception` objects with a member @a id for +exception ids. It is used as the base class for all exceptions thrown by the +@ref basic_json class. This class can hence be used as "wildcard" to catch +exceptions. +Subclasses: +- @ref parse_error for exceptions indicating a parse error +- @ref invalid_iterator for exceptions indicating errors with iterators +- @ref type_error for exceptions indicating executing a member function with + a wrong type +- @ref out_of_range for exceptions indicating access out of the defined range +- @ref other_error for exceptions indicating other library errors + +@internal @note To have nothrow-copy-constructible exceptions, we internally use - std::runtime_error which can cope with arbitrary-length error messages. + `std::runtime_error` which can cope with arbitrary-length error messages. Intermediate strings are built with static functions and then passed to the actual constructor. +@endinternal + +@liveexample{The following code shows how arbitrary library exceptions can be +caught.,exception} @since version 3.0.0 */ @@ -136,7 +201,7 @@ class exception : public std::exception { public: /// returns the explanatory string - virtual const char* what() const noexcept override + const char* what() const noexcept override { return m.what(); } @@ -145,13 +210,11 @@ class exception : public std::exception const int id; protected: - exception(int id_, const char* what_arg) - : id(id_), m(what_arg) - {} + exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} - static std::string name(const std::string& ename, int id) + static std::string name(const std::string& ename, int id_) { - return "[json.exception." + ename + "." + std::to_string(id) + "] "; + return "[json.exception." + ename + "." + std::to_string(id_) + "] "; } private: @@ -162,36 +225,44 @@ class exception : public std::exception /*! @brief exception indicating a parse error -This excpetion is thrown by the library when a parse error occurs. Parse -errors can occur during the deserialization of JSON text as well as when -using JSON Patch. +This exception is thrown by the library when a parse error occurs. Parse errors +can occur during the deserialization of JSON text, CBOR, MessagePack, as well +as when using JSON Patch. Member @a byte holds the byte index of the last read character in the input file. -@note For an input with n bytes, 1 is the index of the first character - and n+1 is the index of the terminating null byte or the end of - file. This also holds true when reading a byte vector (CBOR or - MessagePack). - Exceptions have ids 1xx. -name / id | example massage | description +name / id | example message | description ------------------------------ | --------------- | ------------------------- json.exception.parse_error.101 | parse error at 2: unexpected end of input; expected string literal | This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member @a byte indicates the error position. json.exception.parse_error.102 | parse error at 14: missing or wrong low surrogate | JSON uses the `\uxxxx` format to describe Unicode characters. Code points above above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point. json.exception.parse_error.103 | parse error: code points above 0x10FFFF are invalid | Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid. json.exception.parse_error.104 | parse error: JSON patch must be an array of objects | [RFC 6902](https://tools.ietf.org/html/rfc6902) requires a JSON Patch document to be a JSON document that represents an array of objects. json.exception.parse_error.105 | parse error: operation must have string member 'op' | An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors. -json.exception.parse_error.106 | parse error: array index '01' must not begin with '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) may be `0` or any number wihtout a leading `0`. +json.exception.parse_error.106 | parse error: array index '01' must not begin with '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) may be `0` or any number without a leading `0`. json.exception.parse_error.107 | parse error: JSON pointer must be empty or begin with '/' - was: 'foo' | A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a `/` character. json.exception.parse_error.108 | parse error: escape character '~' must be followed with '0' or '1' | In a JSON Pointer, only `~0` and `~1` are valid escape sequences. json.exception.parse_error.109 | parse error: array index 'one' is not a number | A JSON Pointer array index must be a number. json.exception.parse_error.110 | parse error at 1: cannot read 2 bytes from vector | When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read. -json.exception.parse_error.111 | parse error: bad input stream | Parsing CBOR or MessagePack from an input stream where the [`badbit` or `failbit`](http://en.cppreference.com/w/cpp/io/ios_base/iostate) is set. -json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte: 0xf8 | Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read. +json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte: 0xF8 | Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read. json.exception.parse_error.113 | parse error at 2: expected a CBOR string; last byte: 0x98 | While parsing a map key, a value that is not a string has been read. +@note For an input with n bytes, 1 is the index of the first character and n+1 + is the index of the terminating null byte or the end of file. This also + holds true when reading a byte vector (CBOR or MessagePack). + +@liveexample{The following code shows how a `parse_error` exception can be +caught.,parse_error} + +@sa @ref exception for the base class of the library exceptions +@sa @ref invalid_iterator for exceptions indicating errors with iterators +@sa @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa @ref out_of_range for exceptions indicating access out of the defined range +@sa @ref other_error for exceptions indicating other library errors + @since version 3.0.0 */ class parse_error : public exception @@ -199,18 +270,18 @@ class parse_error : public exception public: /*! @brief create a parse error exception - @param[in] id the id of the exception - @param[in] byte_ the byte index where the error occured (or 0 if - the position cannot be determined) - @param[in] what_arg the explanatory string + @param[in] id_ the id of the exception + @param[in] byte_ the byte index where the error occurred (or 0 if the + position cannot be determined) + @param[in] what_arg the explanatory string @return parse_error object */ - static parse_error create(int id, size_t byte_, const std::string& what_arg) + static parse_error create(int id_, std::size_t byte_, const std::string& what_arg) { - std::string w = exception::name("parse_error", id) + "parse error" + + std::string w = exception::name("parse_error", id_) + "parse error" + (byte_ != 0 ? (" at " + std::to_string(byte_)) : "") + ": " + what_arg; - return parse_error(id, byte_, w.c_str()); + return parse_error(id_, byte_, w.c_str()); } /*! @@ -218,25 +289,26 @@ class parse_error : public exception The byte index of the last read character in the input file. - @note For an input with n bytes, 1 is the index of the first character - and n+1 is the index of the terminating null byte or the end of - file. This also holds true when reading a byte vector (CBOR or - MessagePack). + @note For an input with n bytes, 1 is the index of the first character and + n+1 is the index of the terminating null byte or the end of file. + This also holds true when reading a byte vector (CBOR or MessagePack). */ - const size_t byte; + const std::size_t byte; private: - parse_error(int id_, size_t byte_, const char* what_arg) - : exception(id_, what_arg), byte(byte_) - {} + parse_error(int id_, std::size_t byte_, const char* what_arg) + : exception(id_, what_arg), byte(byte_) {} }; /*! @brief exception indicating errors with iterators +This exception is thrown if iterators passed to a library function do not match +the expected semantics. + Exceptions have ids 2xx. -name / id | example massage | description +name / id | example message | description ----------------------------------- | --------------- | ------------------------- json.exception.invalid_iterator.201 | iterators are not compatible | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. json.exception.invalid_iterator.202 | iterator does not fit current value | In an erase or insert function, the passed iterator @a pos does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion. @@ -250,32 +322,44 @@ json.exception.invalid_iterator.209 | cannot use offsets with object iterators | json.exception.invalid_iterator.210 | iterators do not fit | The iterator range passed to the insert function are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. json.exception.invalid_iterator.211 | passed iterators may not belong to container | The iterator range passed to the insert function must not be a subrange of the container to insert to. json.exception.invalid_iterator.212 | cannot compare iterators of different containers | When two iterators are compared, they must belong to the same container. -json.exception.invalid_iterator.213 | cannot compare order of object iterators | The order of object iterators cannot be compated, because JSON objects are unordered. +json.exception.invalid_iterator.213 | cannot compare order of object iterators | The order of object iterators cannot be compared, because JSON objects are unordered. json.exception.invalid_iterator.214 | cannot get value | Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to @ref begin(). +@liveexample{The following code shows how an `invalid_iterator` exception can be +caught.,invalid_iterator} + +@sa @ref exception for the base class of the library exceptions +@sa @ref parse_error for exceptions indicating a parse error +@sa @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa @ref out_of_range for exceptions indicating access out of the defined range +@sa @ref other_error for exceptions indicating other library errors + @since version 3.0.0 */ class invalid_iterator : public exception { public: - static invalid_iterator create(int id, const std::string& what_arg) + static invalid_iterator create(int id_, const std::string& what_arg) { - std::string w = exception::name("invalid_iterator", id) + what_arg; - return invalid_iterator(id, w.c_str()); + std::string w = exception::name("invalid_iterator", id_) + what_arg; + return invalid_iterator(id_, w.c_str()); } private: invalid_iterator(int id_, const char* what_arg) - : exception(id_, what_arg) - {} + : exception(id_, what_arg) {} }; /*! @brief exception indicating executing a member function with a wrong type +This exception is thrown in case of a type error; that is, a library function is +executed on a JSON value whose type does not match the expected semantics. + Exceptions have ids 3xx. -name / id | example massage | description +name / id | example message | description ----------------------------- | --------------- | ------------------------- json.exception.type_error.301 | cannot create object from initializer list | To create an object from an initializer list, the initializer list must consist only of a list of pairs whose first element is a string. When this constraint is violated, an array is created instead. json.exception.type_error.302 | type must be object, but is array | During implicit or explicit value conversion, the JSON type must be compatible to the target type. For instance, a JSON string can only be converted into string types, but not into numbers or boolean types. @@ -288,33 +372,46 @@ json.exception.type_error.308 | cannot use push_back() with string | The @ref pu json.exception.type_error.309 | cannot use insert() with | The @ref insert() member functions can only be executed for certain JSON types. json.exception.type_error.310 | cannot use swap() with number | The @ref swap() member functions can only be executed for certain JSON types. json.exception.type_error.311 | cannot use emplace_back() with string | The @ref emplace_back() member function can only be executed for certain JSON types. +json.exception.type_error.312 | cannot use update() with string | The @ref update() member functions can only be executed for certain JSON types. json.exception.type_error.313 | invalid value to unflatten | The @ref unflatten function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well defined. json.exception.type_error.314 | only objects can be unflattened | The @ref unflatten function only works for an object whose keys are JSON Pointers. json.exception.type_error.315 | values in object must be primitive | The @ref unflatten function only works for an object whose keys are JSON Pointers and whose values are primitive. +json.exception.type_error.316 | invalid UTF-8 byte at index 10: 0x7E | The @ref dump function only works with UTF-8 encoded strings; that is, if you assign a `std::string` to a JSON value, make sure it is UTF-8 encoded. | + +@liveexample{The following code shows how a `type_error` exception can be +caught.,type_error} + +@sa @ref exception for the base class of the library exceptions +@sa @ref parse_error for exceptions indicating a parse error +@sa @ref invalid_iterator for exceptions indicating errors with iterators +@sa @ref out_of_range for exceptions indicating access out of the defined range +@sa @ref other_error for exceptions indicating other library errors @since version 3.0.0 */ class type_error : public exception { public: - static type_error create(int id, const std::string& what_arg) + static type_error create(int id_, const std::string& what_arg) { - std::string w = exception::name("type_error", id) + what_arg; - return type_error(id, w.c_str()); + std::string w = exception::name("type_error", id_) + what_arg; + return type_error(id_, w.c_str()); } private: - type_error(int id_, const char* what_arg) - : exception(id_, what_arg) - {} + type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} }; /*! @brief exception indicating access out of the defined range +This exception is thrown in case a library function is called on an input +parameter that exceeds the expected range, for instance in case of array +indices or nonexisting object keys. + Exceptions have ids 4xx. -name / id | example massage | description +name / id | example message | description ------------------------------- | --------------- | ------------------------- json.exception.out_of_range.401 | array index 3 is out of range | The provided array index @a i is larger than @a size-1. json.exception.out_of_range.402 | array index '-' (3) is out of range | The special array index `-` in a JSON Pointer never describes a valid element of the array, but the index past the end. That is, it can only be used to add elements at this position, but not to read it. @@ -323,47 +420,67 @@ json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value. json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed number could not be stored as without changing it to NaN or INF. +@liveexample{The following code shows how an `out_of_range` exception can be +caught.,out_of_range} + +@sa @ref exception for the base class of the library exceptions +@sa @ref parse_error for exceptions indicating a parse error +@sa @ref invalid_iterator for exceptions indicating errors with iterators +@sa @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa @ref other_error for exceptions indicating other library errors + @since version 3.0.0 */ class out_of_range : public exception { public: - static out_of_range create(int id, const std::string& what_arg) + static out_of_range create(int id_, const std::string& what_arg) { - std::string w = exception::name("out_of_range", id) + what_arg; - return out_of_range(id, w.c_str()); + std::string w = exception::name("out_of_range", id_) + what_arg; + return out_of_range(id_, w.c_str()); } private: - out_of_range(int id_, const char* what_arg) - : exception(id_, what_arg) - {} + out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} }; /*! -@brief exception indicating other errors +@brief exception indicating other library errors + +This exception is thrown in case of errors that cannot be classified with the +other exception types. Exceptions have ids 5xx. -name / id | example massage | description +name / id | example message | description ------------------------------ | --------------- | ------------------------- json.exception.other_error.501 | unsuccessful: {"op":"test","path":"/baz", "value":"bar"} | A JSON Patch operation 'test' failed. The unsuccessful operation is also printed. +json.exception.other_error.502 | invalid object size for conversion | Some conversions to user-defined types impose constraints on the object size (e.g. std::pair) + +@sa @ref exception for the base class of the library exceptions +@sa @ref parse_error for exceptions indicating a parse error +@sa @ref invalid_iterator for exceptions indicating errors with iterators +@sa @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa @ref out_of_range for exceptions indicating access out of the defined range + +@liveexample{The following code shows how an `other_error` exception can be +caught.,other_error} @since version 3.0.0 */ class other_error : public exception { public: - static other_error create(int id, const std::string& what_arg) + static other_error create(int id_, const std::string& what_arg) { - std::string w = exception::name("other_error", id) + what_arg; - return other_error(id, w.c_str()); + std::string w = exception::name("other_error", id_) + what_arg; + return other_error(id_, w.c_str()); } private: - other_error(int id_, const char* what_arg) - : exception(id_, what_arg) - {} + other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} }; @@ -398,15 +515,15 @@ value with the default value for a given type */ enum class value_t : uint8_t { - null, ///< null value - object, ///< object (unordered set of name/value pairs) - array, ///< array (ordered collection of values) - string, ///< string value - boolean, ///< boolean value - number_integer, ///< number value (signed integer) - number_unsigned, ///< number value (unsigned integer) - number_float, ///< number value (floating-point) - discarded ///< discarded by the the parser callback function + null, ///< null value + object, ///< object (unordered set of name/value pairs) + array, ///< array (ordered collection of values) + string, ///< string value + boolean, ///< boolean value + number_integer, ///< number value (signed integer) + number_unsigned, ///< number value (unsigned integer) + number_float, ///< number value (floating-point) + discarded ///< discarded by the the parser callback function }; /*! @@ -415,31 +532,21 @@ enum class value_t : uint8_t Returns an ordering that is similar to Python: - order: null < boolean < number < object < array < string - furthermore, each type is not smaller than itself +- discarded values are not comparable @since version 1.0.0 */ inline bool operator<(const value_t lhs, const value_t rhs) noexcept { static constexpr std::array order = {{ - 0, // null - 3, // object - 4, // array - 5, // string - 1, // boolean - 2, // integer - 2, // unsigned - 2, // float + 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, + 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */ } }; - // discarded values are not comparable - if (lhs == value_t::discarded or rhs == value_t::discarded) - { - return false; - } - - return order[static_cast(lhs)] < - order[static_cast(rhs)]; + const auto l_index = static_cast(lhs); + const auto r_index = static_cast(rhs); + return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index]; } @@ -447,6 +554,11 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept // helpers // ///////////// +template struct is_basic_json : std::false_type {}; + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +struct is_basic_json : std::true_type {}; + // alias templates to reduce boilerplate template using enable_if_t = typename std::enable_if::type; @@ -454,11 +566,36 @@ using enable_if_t = typename std::enable_if::type; template using uncvref_t = typename std::remove_cv::type>::type; -// taken from http://stackoverflow.com/a/26936864/266378 -template -using is_unscoped_enum = - std::integral_constant::value and - std::is_enum::value>; +// implementation of C++14 index_sequence and affiliates +// source: https://stackoverflow.com/a/32223343 +template +struct index_sequence +{ + using type = index_sequence; + using value_type = std::size_t; + static constexpr std::size_t size() noexcept + { + return sizeof...(Ints); + } +}; + +template +struct merge_and_renumber; + +template +struct merge_and_renumber, index_sequence> + : index_sequence < I1..., (sizeof...(I1) + I2)... > {}; + +template +struct make_index_sequence + : merge_and_renumber < typename make_index_sequence < N / 2 >::type, + typename make_index_sequence < N - N / 2 >::type > {}; + +template<> struct make_index_sequence<0> : index_sequence<> {}; +template<> struct make_index_sequence<1> : index_sequence<0> {}; + +template +using index_sequence_for = make_index_sequence; /* Implementation of two C++17 constructs: conjunction, negation. This is needed @@ -478,7 +615,7 @@ template struct conjunction : B1 {}; template struct conjunction : std::conditional, B1>::type {}; -template struct negation : std::integral_constant < bool, !B::value > {}; +template struct negation : std::integral_constant {}; // dispatch utility (taken from ranges-v3) template struct priority_tag : priority_tag < N - 1 > {}; @@ -513,6 +650,14 @@ struct external_constructor j.m_value = s; j.assert_invariant(); } + + template + static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s) + { + j.m_type = value_t::string; + j.m_value = std::move(s); + j.assert_invariant(); + } }; template<> @@ -562,9 +707,16 @@ struct external_constructor j.assert_invariant(); } + template + static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr) + { + j.m_type = value_t::array; + j.m_value = std::move(arr); + j.assert_invariant(); + } + template::value, + enable_if_t::value, int> = 0> static void construct(BasicJsonType& j, const CompatibleArrayType& arr) { @@ -587,6 +739,17 @@ struct external_constructor } j.assert_invariant(); } + + template::value, int> = 0> + static void construct(BasicJsonType& j, const std::valarray& arr) + { + j.m_type = value_t::array; + j.m_value = value_t::array; + j.m_value.array->resize(arr.size()); + std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin()); + j.assert_invariant(); + } }; template<> @@ -600,10 +763,16 @@ struct external_constructor j.assert_invariant(); } + template + static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj) + { + j.m_type = value_t::object; + j.m_value = std::move(obj); + j.assert_invariant(); + } + template::value, - int> = 0> + enable_if_t::value, int> = 0> static void construct(BasicJsonType& j, const CompatibleObjectType& obj) { using std::begin; @@ -656,10 +825,8 @@ template struct is_compatible_object_type_impl { static constexpr auto value = - std::is_constructible::value and - std::is_constructible::value; + std::is_constructible::value and + std::is_constructible::value; }; template @@ -678,8 +845,7 @@ struct is_basic_json_nested_type static auto constexpr value = std::is_same::value or std::is_same::value or std::is_same::value or - std::is_same::value or - std::is_same::value; + std::is_same::value; }; template @@ -707,8 +873,7 @@ struct is_compatible_integer_type_impl; static constexpr auto value = - std::is_constructible::value and + std::is_constructible::value and CompatibleLimits::is_integer and RealLimits::is_signed == CompatibleLimits::is_signed; }; @@ -720,7 +885,7 @@ struct is_compatible_integer_type is_compatible_integer_type_impl < std::is_integral::value and not std::is_same::value, - RealIntegerType, CompatibleNumberIntegerType > ::value; + RealIntegerType, CompatibleNumberIntegerType >::value; }; @@ -746,10 +911,8 @@ template struct has_non_default_from_json { private: - template < - typename U, - typename = enable_if_t::from_json(std::declval()))>::value >> + template::from_json(std::declval()))>::value>> static int detect(U&&); static void detect(...); @@ -778,21 +941,26 @@ struct has_to_json // to_json // ///////////// -template::value, int> = 0> +template::value, int> = 0> void to_json(BasicJsonType& j, T b) noexcept { external_constructor::construct(j, b); } template::value, int> = 0> + enable_if_t::value, int> = 0> void to_json(BasicJsonType& j, const CompatibleString& s) { external_constructor::construct(j, s); } +template +void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s) +{ + external_constructor::construct(j, std::move(s)); +} + template::value, int> = 0> void to_json(BasicJsonType& j, FloatType val) noexcept @@ -800,29 +968,26 @@ void to_json(BasicJsonType& j, FloatType val) noexcept external_constructor::construct(j, static_cast(val)); } -template < - typename BasicJsonType, typename CompatibleNumberUnsignedType, - enable_if_t::value, int> = 0 > +template::value, int> = 0> void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept { external_constructor::construct(j, static_cast(val)); } -template < - typename BasicJsonType, typename CompatibleNumberIntegerType, - enable_if_t::value, int> = 0 > +template::value, int> = 0> void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept { external_constructor::construct(j, static_cast(val)); } -template::value, int> = 0> -void to_json(BasicJsonType& j, UnscopedEnumType e) noexcept +template::value, int> = 0> +void to_json(BasicJsonType& j, EnumType e) noexcept { - external_constructor::construct(j, e); + using underlying_type = typename std::underlying_type::type; + external_constructor::construct(j, static_cast(e)); } template @@ -831,35 +996,66 @@ void to_json(BasicJsonType& j, const std::vector& e) external_constructor::construct(j, e); } -template < - typename BasicJsonType, typename CompatibleArrayType, - enable_if_t < - is_compatible_array_type::value or - std::is_same::value, - int > = 0 > -void to_json(BasicJsonType& j, const CompatibleArrayType& arr) +template::value or + std::is_same::value, + int> = 0> +void to_json(BasicJsonType& j, const CompatibleArrayType& arr) { external_constructor::construct(j, arr); } -template < - typename BasicJsonType, typename CompatibleObjectType, - enable_if_t::value, - int> = 0 > -void to_json(BasicJsonType& j, const CompatibleObjectType& arr) +template::value, int> = 0> +void to_json(BasicJsonType& j, std::valarray arr) +{ + external_constructor::construct(j, std::move(arr)); +} + +template +void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr) +{ + external_constructor::construct(j, std::move(arr)); +} + +template::value, int> = 0> +void to_json(BasicJsonType& j, const CompatibleObjectType& obj) +{ + external_constructor::construct(j, obj); +} + +template +void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj) { - external_constructor::construct(j, arr); + external_constructor::construct(j, std::move(obj)); } -template ::value, - int> = 0> +template::value, int> = 0> void to_json(BasicJsonType& j, T (&arr)[N]) { external_constructor::construct(j, arr); } +template +void to_json(BasicJsonType& j, const std::pair& p) +{ + j = {p.first, p.second}; +} + +template +void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence) +{ + j = {std::get(t)...}; +} + +template +void to_json(BasicJsonType& j, const std::tuple& t) +{ + to_json_tuple_impl(j, t, index_sequence_for {}); +} + /////////////// // from_json // /////////////// @@ -867,8 +1063,7 @@ void to_json(BasicJsonType& j, T (&arr)[N]) // overloads for basic_json template parameters template::value and - not std::is_same::value, + not std::is_same::value, int> = 0> void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) { @@ -876,35 +1071,31 @@ void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) { case value_t::number_unsigned: { - val = static_cast( - *j.template get_ptr()); + val = static_cast(*j.template get_ptr()); break; } case value_t::number_integer: { - val = static_cast( - *j.template get_ptr()); + val = static_cast(*j.template get_ptr()); break; } case value_t::number_float: { - val = static_cast( - *j.template get_ptr()); + val = static_cast(*j.template get_ptr()); break; } + default: - { - JSON_THROW(type_error::create(302, "type must be number, but is " + j.type_name())); - } + JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()))); } } template void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) { - if (not j.is_boolean()) + if (JSON_UNLIKELY(not j.is_boolean())) { - JSON_THROW(type_error::create(302, "type must be boolean, but is " + j.type_name())); + JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name()))); } b = *j.template get_ptr(); } @@ -912,9 +1103,9 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) template void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s) { - if (not j.is_string()) + if (JSON_UNLIKELY(not j.is_string())) { - JSON_THROW(type_error::create(302, "type must be string, but is " + j.type_name())); + JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()))); } s = *j.template get_ptr(); } @@ -937,21 +1128,21 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& get_arithmetic_value(j, val); } -template::value, int> = 0> -void from_json(const BasicJsonType& j, UnscopedEnumType& e) +template::value, int> = 0> +void from_json(const BasicJsonType& j, EnumType& e) { - typename std::underlying_type::type val; + typename std::underlying_type::type val; get_arithmetic_value(j, val); - e = static_cast(val); + e = static_cast(val); } template void from_json(const BasicJsonType& j, typename BasicJsonType::array_t& arr) { - if (not j.is_array()) + if (JSON_UNLIKELY(not j.is_array())) { - JSON_THROW(type_error::create(302, "type must be array, but is " + j.type_name())); + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()))); } arr = *j.template get_ptr(); } @@ -961,21 +1152,33 @@ template::value, int> = 0> void from_json(const BasicJsonType& j, std::forward_list& l) { - if (not j.is_array()) + if (JSON_UNLIKELY(not j.is_array())) { - JSON_THROW(type_error::create(302, "type must be array, but is " + j.type_name())); + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()))); } + std::transform(j.rbegin(), j.rend(), + std::front_inserter(l), [](const BasicJsonType & i) + { + return i.template get(); + }); +} - for (auto it = j.rbegin(), end = j.rend(); it != end; ++it) +// valarray doesn't have an insert method +template::value, int> = 0> +void from_json(const BasicJsonType& j, std::valarray& l) +{ + if (JSON_UNLIKELY(not j.is_array())) { - l.push_front(it->template get()); + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()))); } + l.resize(j.size()); + std::copy(j.m_value.array->begin(), j.m_value.array->end(), std::begin(l)); } template -void from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, priority_tag<0>) +void from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, priority_tag<0> /*unused*/) { - using std::begin; using std::end; std::transform(j.begin(), j.end(), @@ -988,12 +1191,11 @@ void from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, prio } template -auto from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, priority_tag<1>) +auto from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, priority_tag<1> /*unused*/) -> decltype( arr.reserve(std::declval()), void()) { - using std::begin; using std::end; arr.reserve(j.size()); @@ -1006,36 +1208,47 @@ auto from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, prio }); } +template +void from_json_array_impl(const BasicJsonType& j, std::array& arr, priority_tag<2> /*unused*/) +{ + for (std::size_t i = 0; i < N; ++i) + { + arr[i] = j.at(i).template get(); + } +} + template::value and std::is_convertible::value and not std::is_same::value, int> = 0> void from_json(const BasicJsonType& j, CompatibleArrayType& arr) { - if (not j.is_array()) + if (JSON_UNLIKELY(not j.is_array())) { - JSON_THROW(type_error::create(302, "type must be array, but is " + j.type_name())); + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()))); } - from_json_array_impl(j, arr, priority_tag<1> {}); + from_json_array_impl(j, arr, priority_tag<2> {}); } template::value, int> = 0> void from_json(const BasicJsonType& j, CompatibleObjectType& obj) { - if (not j.is_object()) + if (JSON_UNLIKELY(not j.is_object())) { - JSON_THROW(type_error::create(302, "type must be object, but is " + j.type_name())); + JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name()))); } auto inner_object = j.template get_ptr(); - using std::begin; - using std::end; - // we could avoid the assignment, but this might require a for loop, which - // might be less efficient than the container constructor for some - // containers (would it?) - obj = CompatibleObjectType(begin(*inner_object), end(*inner_object)); + using value_type = typename CompatibleObjectType::value_type; + std::transform( + inner_object->begin(), inner_object->end(), + std::inserter(obj, obj.begin()), + [](typename BasicJsonType::object_t::value_type const & p) + { + return value_type(p.first, p.second.template get()); + }); } // overload for arithmetic types, not chosen for basic_json template arguments @@ -1074,34 +1287,58 @@ void from_json(const BasicJsonType& j, ArithmeticType& val) val = static_cast(*j.template get_ptr()); break; } + default: - { - JSON_THROW(type_error::create(302, "type must be number, but is " + j.type_name())); - } + JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()))); } } +template +void from_json(const BasicJsonType& j, std::pair& p) +{ + p = {j.at(0).template get(), j.at(1).template get()}; +} + +template +void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence) +{ + t = std::make_tuple(j.at(Idx).template get::type>()...); +} + +template +void from_json(const BasicJsonType& j, std::tuple& t) +{ + from_json_tuple_impl(j, t, index_sequence_for {}); +} + struct to_json_fn { private: template - auto call(BasicJsonType& j, T&& val, priority_tag<1>) const noexcept_if(noexcept_if(to_json(j, std::forward(val)))) + auto call(BasicJsonType& j, T&& val, priority_tag<1> /*unused*/) const noexcept(noexcept(to_json(j, std::forward(val)))) -> decltype(to_json(j, std::forward(val)), void()) { return to_json(j, std::forward(val)); } template - void call(BasicJsonType&, T&&, priority_tag<0>) const noexcept + void call(BasicJsonType& /*unused*/, T&& /*unused*/, priority_tag<0> /*unused*/) const noexcept { static_assert(sizeof(BasicJsonType) == 0, "could not find to_json() method in T's namespace"); + +#ifdef _MSC_VER + // MSVC does not show a stacktrace for the above assert + using decayed = uncvref_t; + static_assert(sizeof(typename decayed::force_msvc_stacktrace) == 0, + "forcing MSVC stacktrace to show which T we're talking about."); +#endif } public: template void operator()(BasicJsonType& j, T&& val) const - noexcept_if(noexcept_if(std::declval().call(j, std::forward(val), priority_tag<1> {}))) + noexcept(noexcept(std::declval().call(j, std::forward(val), priority_tag<1> {}))) { return call(j, std::forward(val), priority_tag<1> {}); } @@ -1111,24 +1348,30 @@ struct from_json_fn { private: template - auto call(const BasicJsonType& j, T& val, priority_tag<1>) const - noexcept_if(noexcept_if(from_json(j, val))) + auto call(const BasicJsonType& j, T& val, priority_tag<1> /*unused*/) const + noexcept(noexcept(from_json(j, val))) -> decltype(from_json(j, val), void()) { return from_json(j, val); } template - void call(const BasicJsonType&, T&, priority_tag<0>) const noexcept + void call(const BasicJsonType& /*unused*/, T& /*unused*/, priority_tag<0> /*unused*/) const noexcept { static_assert(sizeof(BasicJsonType) == 0, "could not find from_json() method in T's namespace"); +#ifdef _MSC_VER + // MSVC does not show a stacktrace for the above assert + using decayed = uncvref_t; + static_assert(sizeof(typename decayed::force_msvc_stacktrace) == 0, + "forcing MSVC stacktrace to show which T we're talking about."); +#endif } public: template void operator()(const BasicJsonType& j, T& val) const - noexcept_if(noexcept_if(std::declval().call(j, val, priority_tag<1> {}))) + noexcept(noexcept(std::declval().call(j, val, priority_tag<1> {}))) { return call(j, val, priority_tag<1> {}); } @@ -1143,11936 +1386,12244 @@ struct static_const template constexpr T static_const::value; -} // namespace detail +//////////////////// +// input adapters // +//////////////////// -/// namespace to hold default `to_json` / `from_json` functions -namespace +/*! +@brief abstract input adapter interface + +Produces a stream of std::char_traits::int_type characters from a +std::istream, a buffer, or some other input type. Accepts the return of exactly +one non-EOF character for future input. The int_type characters returned +consist of all valid char values as positive values (typically unsigned char), +plus an EOF value outside that range, specified by the value of the function +std::char_traits::eof(). This value is typically -1, but could be any +arbitrary value which is not a valid char value. +*/ +struct input_adapter_protocol { -constexpr const auto& to_json = detail::static_const::value; -constexpr const auto& from_json = detail::static_const::value; -} + /// get a character [0,255] or std::char_traits::eof(). + virtual std::char_traits::int_type get_character() = 0; + /// restore the last non-eof() character to input + virtual void unget_character() = 0; + virtual ~input_adapter_protocol() = default; +}; +/// a type to simplify interfaces +using input_adapter_t = std::shared_ptr; /*! -@brief default JSONSerializer template argument - -This serializer ignores the template arguments and uses ADL -([argument-dependent lookup](http://en.cppreference.com/w/cpp/language/adl)) -for serialization. +Input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at +beginning of input. Does not support changing the underlying std::streambuf +in mid-input. Maintains underlying std::istream and std::streambuf to support +subsequent use of standard std::istream operations to process any input +characters following those used in parsing the JSON input. Clears the +std::istream flags; any input errors (e.g., EOF) will be detected by the first +subsequent call for input from the std::istream. */ -template -struct adl_serializer +class input_stream_adapter : public input_adapter_protocol { - /*! - @brief convert a JSON value to any value type + public: + ~input_stream_adapter() override + { + // clear stream flags; we use underlying streambuf I/O, do not + // maintain ifstream flags + is.clear(); + } - This function is usually called by the `get()` function of the - @ref basic_json class (either explicit or via conversion operators). + explicit input_stream_adapter(std::istream& i) + : is(i), sb(*i.rdbuf()) + { + // skip byte order mark + std::char_traits::int_type c; + if ((c = get_character()) == 0xEF) + { + if ((c = get_character()) == 0xBB) + { + if ((c = get_character()) == 0xBF) + { + return; // Ignore BOM + } + else if (c != std::char_traits::eof()) + { + is.unget(); + } + is.putback('\xBB'); + } + else if (c != std::char_traits::eof()) + { + is.unget(); + } + is.putback('\xEF'); + } + else if (c != std::char_traits::eof()) + { + is.unget(); // no byte order mark; process as usual + } + } - @param[in] j JSON value to read from - @param[in,out] val value to write to - */ - template - static void from_json(BasicJsonType&& j, ValueType& val) noexcept_if( - noexcept_if(::nlohmann::from_json(std::forward(j), val))) + // delete because of pointer members + input_stream_adapter(const input_stream_adapter&) = delete; + input_stream_adapter& operator=(input_stream_adapter&) = delete; + + // std::istream/std::streambuf use std::char_traits::to_int_type, to + // ensure that std::char_traits::eof() and the character 0xFF do not + // end up as the same value, eg. 0xFFFFFFFF. + std::char_traits::int_type get_character() override { - ::nlohmann::from_json(std::forward(j), val); + return sb.sbumpc(); } - /*! - @brief convert any value type to a JSON value + void unget_character() override + { + sb.sungetc(); // is.unget() avoided for performance + } - This function is usually called by the constructors of the @ref basic_json - class. + private: + /// the associated input stream + std::istream& is; + std::streambuf& sb; +}; - @param[in,out] j JSON value to write to - @param[in] val value to read from - */ - template - static void to_json(BasicJsonType& j, ValueType&& val) noexcept_if( - noexcept_if(::nlohmann::to_json(j, std::forward(val)))) +/// input adapter for buffer input +class input_buffer_adapter : public input_adapter_protocol +{ + public: + input_buffer_adapter(const char* b, const std::size_t l) + : cursor(b), limit(b + l), start(b) { - ::nlohmann::to_json(j, std::forward(val)); + // skip byte order mark + if (l >= 3 and b[0] == '\xEF' and b[1] == '\xBB' and b[2] == '\xBF') + { + cursor += 3; + } + } + + // delete because of pointer members + input_buffer_adapter(const input_buffer_adapter&) = delete; + input_buffer_adapter& operator=(input_buffer_adapter&) = delete; + + std::char_traits::int_type get_character() noexcept override + { + if (JSON_LIKELY(cursor < limit)) + { + return std::char_traits::to_int_type(*(cursor++)); + } + + return std::char_traits::eof(); + } + + void unget_character() noexcept override + { + if (JSON_LIKELY(cursor > start)) + { + --cursor; + } } + + private: + /// pointer to the current character + const char* cursor; + /// pointer past the last character + const char* limit; + /// pointer to the first character + const char* start; }; +class input_adapter +{ + public: + // native support -/*! -@brief a class to store JSON values + /// input adapter for input stream + input_adapter(std::istream& i) + : ia(std::make_shared(i)) {} -@tparam ObjectType type for JSON objects (`std::map` by default; will be used -in @ref object_t) -@tparam ArrayType type for JSON arrays (`std::vector` by default; will be used -in @ref array_t) -@tparam StringType type for JSON strings and object keys (`std::string` by -default; will be used in @ref string_t) -@tparam BooleanType type for JSON booleans (`bool` by default; will be used -in @ref boolean_t) -@tparam NumberIntegerType type for JSON integer numbers (`int64_t` by -default; will be used in @ref number_integer_t) -@tparam NumberUnsignedType type for JSON unsigned integer numbers (@c -`uint64_t` by default; will be used in @ref number_unsigned_t) -@tparam NumberFloatType type for JSON floating-point numbers (`double` by -default; will be used in @ref number_float_t) -@tparam AllocatorType type of the allocator to use (`std::allocator` by -default) -@tparam JSONSerializer the serializer to resolve internal calls to `to_json()` -and `from_json()` (@ref adl_serializer by default) + /// input adapter for input stream + input_adapter(std::istream&& i) + : ia(std::make_shared(i)) {} -@requirement The class satisfies the following concept requirements: -- Basic - - [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible): - JSON values can be default constructed. The result will be a JSON null - value. - - [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible): - A JSON value can be constructed from an rvalue argument. - - [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible): - A JSON value can be copy-constructed from an lvalue expression. - - [MoveAssignable](http://en.cppreference.com/w/cpp/concept/MoveAssignable): - A JSON value van be assigned from an rvalue argument. - - [CopyAssignable](http://en.cppreference.com/w/cpp/concept/CopyAssignable): - A JSON value can be copy-assigned from an lvalue expression. - - [Destructible](http://en.cppreference.com/w/cpp/concept/Destructible): - JSON values can be destructed. -- Layout - - [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType): - JSON values have - [standard layout](http://en.cppreference.com/w/cpp/language/data_members#Standard_layout): - All non-static data members are private and standard layout types, the - class has no virtual functions or (virtual) base classes. -- Library-wide - - [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable): - JSON values can be compared with `==`, see @ref - operator==(const_reference,const_reference). - - [LessThanComparable](http://en.cppreference.com/w/cpp/concept/LessThanComparable): - JSON values can be compared with `<`, see @ref - operator<(const_reference,const_reference). - - [Swappable](http://en.cppreference.com/w/cpp/concept/Swappable): - Any JSON lvalue or rvalue of can be swapped with any lvalue or rvalue of - other compatible types, using unqualified function call @ref swap(). - - [NullablePointer](http://en.cppreference.com/w/cpp/concept/NullablePointer): - JSON values can be compared against `std::nullptr_t` objects which are used - to model the `null` value. -- Container - - [Container](http://en.cppreference.com/w/cpp/concept/Container): - JSON values can be used like STL containers and provide iterator access. - - [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer); - JSON values can be used like STL containers and provide reverse iterator - access. + /// input adapter for buffer + template::value and + std::is_integral::type>::value and + sizeof(typename std::remove_pointer::type) == 1, + int>::type = 0> + input_adapter(CharT b, std::size_t l) + : ia(std::make_shared(reinterpret_cast(b), l)) {} -@invariant The member variables @a m_value and @a m_type have the following -relationship: -- If `m_type == value_t::object`, then `m_value.object != nullptr`. -- If `m_type == value_t::array`, then `m_value.array != nullptr`. -- If `m_type == value_t::string`, then `m_value.string != nullptr`. -The invariants are checked by member function assert_invariant(). + // derived support -@internal -@note ObjectType trick from http://stackoverflow.com/a/9860911 -@endinternal + /// input adapter for string literal + template::value and + std::is_integral::type>::value and + sizeof(typename std::remove_pointer::type) == 1, + int>::type = 0> + input_adapter(CharT b) + : input_adapter(reinterpret_cast(b), + std::strlen(reinterpret_cast(b))) {} + + /// input adapter for iterator range with contiguous storage + template::iterator_category, std::random_access_iterator_tag>::value, + int>::type = 0> + input_adapter(IteratorType first, IteratorType last) + { + // assertion to check that the iterator range is indeed contiguous, + // see http://stackoverflow.com/a/35008842/266378 for more discussion + assert(std::accumulate( + first, last, std::pair(true, 0), + [&first](std::pair res, decltype(*first) val) + { + res.first &= (val == *(std::next(std::addressof(*first), res.second++))); + return res; + }).first); -@see [RFC 7159: The JavaScript Object Notation (JSON) Data Interchange -Format](http://rfc7159.net/rfc7159) + // assertion to check that each element is 1 byte long + static_assert( + sizeof(typename std::iterator_traits::value_type) == 1, + "each element in the iterator range must have the size of 1 byte"); -@since version 1.0.0 + const auto len = static_cast(std::distance(first, last)); + if (JSON_LIKELY(len > 0)) + { + // there is at least one element: use the address of first + ia = std::make_shared(reinterpret_cast(&(*first)), len); + } + else + { + // the address of first cannot be used: use nullptr + ia = std::make_shared(nullptr, len); + } + } -@nosubgrouping -*/ -template < - template class ObjectType = std::map, - template class ArrayType = std::vector, - class StringType = std::string, - class BooleanType = bool, - class NumberIntegerType = std::int64_t, - class NumberUnsignedType = std::uint64_t, - class NumberFloatType = double, - template class AllocatorType = std::allocator, - template class JSONSerializer = adl_serializer - > -class basic_json -{ - private: - template friend struct detail::external_constructor; - /// workaround type for MSVC - using basic_json_t = basic_json; + /// input adapter for array + template + input_adapter(T (&array)[N]) + : input_adapter(std::begin(array), std::end(array)) {} - public: - using value_t = detail::value_t; - // forward declarations - template class iter_impl; - template class json_reverse_iterator; - class json_pointer; - template - using json_serializer = JSONSerializer; + /// input adapter for contiguous container + template::value and + std::is_base_of()))>::iterator_category>::value, + int>::type = 0> + input_adapter(const ContiguousContainer& c) + : input_adapter(std::begin(c), std::end(c)) {} + operator input_adapter_t() + { + return ia; + } - //////////////// - // exceptions // - //////////////// + private: + /// the actual adapter + input_adapter_t ia = nullptr; +}; - /// @name exceptions - /// Classes to implement user-defined exceptions. - /// @{ +////////////////////// +// lexer and parser // +////////////////////// - /// @copydoc detail::exception - using exception = detail::exception; - /// @copydoc detail::parse_error - using parse_error = detail::parse_error; - /// @copydoc detail::invalid_iterator - using invalid_iterator = detail::invalid_iterator; - /// @copydoc detail::type_error - using type_error = detail::type_error; - /// @copydoc detail::out_of_range - using out_of_range = detail::out_of_range; - /// @copydoc detail::other_error - using other_error = detail::other_error; +/*! +@brief lexical analysis - /// @} +This class organizes the lexical analysis during JSON deserialization. +*/ +template +class lexer +{ + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + public: + /// token types for the parser + enum class token_type + { + uninitialized, ///< indicating the scanner is uninitialized + literal_true, ///< the `true` literal + literal_false, ///< the `false` literal + literal_null, ///< the `null` literal + value_string, ///< a string -- use get_string() for actual value + value_unsigned, ///< an unsigned integer -- use get_number_unsigned() for actual value + value_integer, ///< a signed integer -- use get_number_integer() for actual value + value_float, ///< an floating point number -- use get_number_float() for actual value + begin_array, ///< the character for array begin `[` + begin_object, ///< the character for object begin `{` + end_array, ///< the character for array end `]` + end_object, ///< the character for object end `}` + name_separator, ///< the name separator `:` + value_separator, ///< the value separator `,` + parse_error, ///< indicating a parse error + end_of_input, ///< indicating the end of the input buffer + literal_or_value ///< a literal or the begin of a value (only for diagnostics) + }; + /// return name of values of type token_type (only used for errors) + static const char* token_type_name(const token_type t) noexcept + { + switch (t) + { + case token_type::uninitialized: + return ""; + case token_type::literal_true: + return "true literal"; + case token_type::literal_false: + return "false literal"; + case token_type::literal_null: + return "null literal"; + case token_type::value_string: + return "string literal"; + case lexer::token_type::value_unsigned: + case lexer::token_type::value_integer: + case lexer::token_type::value_float: + return "number literal"; + case token_type::begin_array: + return "'['"; + case token_type::begin_object: + return "'{'"; + case token_type::end_array: + return "']'"; + case token_type::end_object: + return "'}'"; + case token_type::name_separator: + return "':'"; + case token_type::value_separator: + return "','"; + case token_type::parse_error: + return ""; + case token_type::end_of_input: + return "end of input"; + case token_type::literal_or_value: + return "'[', '{', or a literal"; + default: // catch non-enum values + return "unknown token"; // LCOV_EXCL_LINE + } + } + + explicit lexer(detail::input_adapter_t adapter) + : ia(std::move(adapter)), decimal_point_char(get_decimal_point()) {} + + // delete because of pointer members + lexer(const lexer&) = delete; + lexer& operator=(lexer&) = delete; + + private: ///////////////////// - // container types // + // locales ///////////////////// - /// @name container types - /// The canonic container types to use @ref basic_json like any other STL - /// container. - /// @{ - - /// the type of elements in a basic_json container - using value_type = basic_json; + /// return the locale-dependent decimal point + static char get_decimal_point() noexcept + { + const auto loc = localeconv(); + assert(loc != nullptr); + return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point); + } - /// the type of an element reference - using reference = value_type&; - /// the type of an element const reference - using const_reference = const value_type&; + ///////////////////// + // scan functions + ///////////////////// - /// a type to represent differences between iterators - using difference_type = std::ptrdiff_t; - /// a type to represent container sizes - using size_type = std::size_t; + /*! + @brief get codepoint from 4 hex characters following `\u` - /// the allocator type - using allocator_type = AllocatorType; + For input "\u c1 c2 c3 c4" the codepoint is: + (c1 * 0x1000) + (c2 * 0x0100) + (c3 * 0x0010) + c4 + = (c1 << 12) + (c2 << 8) + (c3 << 4) + (c4 << 0) - /// the type of an element pointer - using pointer = typename std::allocator_traits::pointer; - /// the type of an element const pointer - using const_pointer = typename std::allocator_traits::const_pointer; + Furthermore, the possible characters '0'..'9', 'A'..'F', and 'a'..'f' + must be converted to the integers 0x0..0x9, 0xA..0xF, 0xA..0xF, resp. The + conversion is done by subtracting the offset (0x30, 0x37, and 0x57) + between the ASCII value of the character and the desired integer value. - /// an iterator for a basic_json container - using iterator = iter_impl; - /// a const iterator for a basic_json container - using const_iterator = iter_impl; - /// a reverse iterator for a basic_json container - using reverse_iterator = json_reverse_iterator; - /// a const reverse iterator for a basic_json container - using const_reverse_iterator = json_reverse_iterator; + @return codepoint (0x0000..0xFFFF) or -1 in case of an error (e.g. EOF or + non-hex character) + */ + int get_codepoint() + { + // this function only makes sense after reading `\u` + assert(current == 'u'); + int codepoint = 0; - /// @} + const auto factors = { 12, 8, 4, 0 }; + for (const auto factor : factors) + { + get(); + if (current >= '0' and current <= '9') + { + codepoint += ((current - 0x30) << factor); + } + else if (current >= 'A' and current <= 'F') + { + codepoint += ((current - 0x37) << factor); + } + else if (current >= 'a' and current <= 'f') + { + codepoint += ((current - 0x57) << factor); + } + else + { + return -1; + } + } - /*! - @brief returns the allocator associated with the container - */ - static allocator_type get_allocator() - { - return allocator_type(); + assert(0x0000 <= codepoint and codepoint <= 0xFFFF); + return codepoint; } /*! - @brief returns version information on the library + @brief check if the next byte(s) are inside a given range - This function returns a JSON object with information about the library, - including the version number and information on the platform and compiler. - - @return JSON object holding version information - key | description - ----------- | --------------- - `compiler` | Information on the used compiler. It is an object with the following keys: `c++` (the used C++ standard), `family` (the compiler family; possible values are `clang`, `icc`, `gcc`, `ilecpp`, `msvc`, `pgcpp`, `sunpro`, and `unknown`), and `version` (the compiler version). - `copyright` | The copyright line for the library as string. - `name` | The name of the library as string. - `platform` | The used platform as string. Possible values are `win32`, `linux`, `apple`, `unix`, and `unknown`. - `url` | The URL of the project as string. - `version` | The version of the library. It is an object with the following keys: `major`, `minor`, and `patch` as defined by [Semantic Versioning](http://semver.org), and `string` (the version string). + Adds the current byte and, for each passed range, reads a new byte and + checks if it is inside the range. If a violation was detected, set up an + error message and return false. Otherwise, return true. - @liveexample{The following code shows an example output of the `meta()` - function.,meta} + @param[in] ranges list of integers; interpreted as list of pairs of + inclusive lower and upper bound, respectively - @complexity Constant. + @pre The passed list @a ranges must have 2, 4, or 6 elements; that is, + 1, 2, or 3 pairs. This precondition is enforced by an assertion. - @since 2.1.0 + @return true if and only if no range violation was detected */ - static basic_json meta() + bool next_byte_in_range(std::initializer_list ranges) { - basic_json result; + assert(ranges.size() == 2 or ranges.size() == 4 or ranges.size() == 6); + add(current); - result["copyright"] = "(C) 2013-2017 Niels Lohmann"; - result["name"] = "JSON for Modern C++"; - result["url"] = "https://github.com/nlohmann/json"; - result["version"] = + for (auto range = ranges.begin(); range != ranges.end(); ++range) { - {"string", "2.1.1"}, {"major", 2}, {"minor", 1}, {"patch", 1} - }; - -#ifdef _WIN32 - result["platform"] = "win32"; -#elif defined __linux__ - result["platform"] = "linux"; -#elif defined __APPLE__ - result["platform"] = "apple"; -#elif defined __unix__ - result["platform"] = "unix"; -#else - result["platform"] = "unknown"; -#endif - -#if defined(__clang__) - result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}}; -#elif defined(__ICC) || defined(__INTEL_COMPILER) - result["compiler"] = {{"family", "icc"}, {"version", __INTEL_COMPILER}}; -#elif defined(__GNUC__) || defined(__GNUG__) - result["compiler"] = {{"family", "gcc"}, {"version", std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__) + "." + std::to_string(__GNUC_PATCHLEVEL__)}}; -#elif defined(__HP_cc) || defined(__HP_aCC) - result["compiler"] = "hp" -#elif defined(__IBMCPP__) - result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}}; -#elif defined(_MSC_VER) - result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}}; -#elif defined(__PGI) - result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}}; -#elif defined(__SUNPRO_CC) - result["compiler"] = {{"family", "sunpro"}, {"version", __SUNPRO_CC}}; -#else - result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}}; -#endif + get(); + if (JSON_LIKELY(*range <= current and current <= *(++range))) + { + add(current); + } + else + { + error_message = "invalid string: ill-formed UTF-8 byte"; + return false; + } + } -#ifdef __cplusplus - result["compiler"]["c++"] = std::to_string(__cplusplus); -#else - result["compiler"]["c++"] = "unknown"; -#endif - return result; + return true; } - - /////////////////////////// - // JSON value data types // - /////////////////////////// - - /// @name JSON value data types - /// The data types to store a JSON value. These types are derived from - /// the template arguments passed to class @ref basic_json. - /// @{ - /*! - @brief a type for an object + @brief scan a string literal - [RFC 7159](http://rfc7159.net/rfc7159) describes JSON objects as follows: - > An object is an unordered collection of zero or more name/value pairs, - > where a name is a string and a value is a string, number, boolean, null, - > object, or array. + This function scans a string according to Sect. 7 of RFC 7159. While + scanning, bytes are escaped and copied into buffer yytext. Then the function + returns successfully, yytext is *not* null-terminated (as it may contain \0 + bytes), and yytext.size() is the number of bytes in the string. - To store objects in C++, a type is defined by the template parameters - described below. + @return token_type::value_string if string could be successfully scanned, + token_type::parse_error otherwise - @tparam ObjectType the container to store objects (e.g., `std::map` or - `std::unordered_map`) - @tparam StringType the type of the keys or names (e.g., `std::string`). - The comparison function `std::less` is used to order elements - inside the container. - @tparam AllocatorType the allocator to use for objects (e.g., - `std::allocator`) + @note In case of errors, variable error_message contains a textual + description. + */ + token_type scan_string() + { + // reset yytext (ignore opening quote) + reset(); - #### Default type + // we entered the function by reading an open quote + assert(current == '\"'); - With the default values for @a ObjectType (`std::map`), @a StringType - (`std::string`), and @a AllocatorType (`std::allocator`), the default - value for @a object_t is: + while (true) + { + // get next character + switch (get()) + { + // end of file while parsing string + case std::char_traits::eof(): + { + error_message = "invalid string: missing closing quote"; + return token_type::parse_error; + } - @code {.cpp} - std::map< - std::string, // key_type - basic_json, // value_type - std::less, // key_compare - std::allocator> // allocator_type - > - @endcode - - #### Behavior + // closing quote + case '\"': + { + return token_type::value_string; + } - The choice of @a object_t influences the behavior of the JSON class. With - the default type, objects have the following behavior: + // escapes + case '\\': + { + switch (get()) + { + // quotation mark + case '\"': + add('\"'); + break; + // reverse solidus + case '\\': + add('\\'); + break; + // solidus + case '/': + add('/'); + break; + // backspace + case 'b': + add('\b'); + break; + // form feed + case 'f': + add('\f'); + break; + // line feed + case 'n': + add('\n'); + break; + // carriage return + case 'r': + add('\r'); + break; + // tab + case 't': + add('\t'); + break; - - When all names are unique, objects will be interoperable in the sense - that all software implementations receiving that object will agree on - the name-value mappings. - - When the names within an object are not unique, later stored name/value - pairs overwrite previously stored name/value pairs, leaving the used - names unique. For instance, `{"key": 1}` and `{"key": 2, "key": 1}` will - be treated as equal and both stored as `{"key": 1}`. - - Internally, name/value pairs are stored in lexicographical order of the - names. Objects will also be serialized (see @ref dump) in this order. - For instance, `{"b": 1, "a": 2}` and `{"a": 2, "b": 1}` will be stored - and serialized as `{"a": 2, "b": 1}`. - - When comparing objects, the order of the name/value pairs is irrelevant. - This makes objects interoperable in the sense that they will not be - affected by these differences. For instance, `{"b": 1, "a": 2}` and - `{"a": 2, "b": 1}` will be treated as equal. + // unicode escapes + case 'u': + { + const int codepoint1 = get_codepoint(); + int codepoint = codepoint1; // start with codepoint1 - #### Limits + if (JSON_UNLIKELY(codepoint1 == -1)) + { + error_message = "invalid string: '\\u' must be followed by 4 hex digits"; + return token_type::parse_error; + } - [RFC 7159](http://rfc7159.net/rfc7159) specifies: - > An implementation may set limits on the maximum depth of nesting. + // check if code point is a high surrogate + if (0xD800 <= codepoint1 and codepoint1 <= 0xDBFF) + { + // expect next \uxxxx entry + if (JSON_LIKELY(get() == '\\' and get() == 'u')) + { + const int codepoint2 = get_codepoint(); + + if (JSON_UNLIKELY(codepoint2 == -1)) + { + error_message = "invalid string: '\\u' must be followed by 4 hex digits"; + return token_type::parse_error; + } + + // check if codepoint2 is a low surrogate + if (JSON_LIKELY(0xDC00 <= codepoint2 and codepoint2 <= 0xDFFF)) + { + // overwrite codepoint + codepoint = + // high surrogate occupies the most significant 22 bits + (codepoint1 << 10) + // low surrogate occupies the least significant 15 bits + + codepoint2 + // there is still the 0xD800, 0xDC00 and 0x10000 noise + // in the result so we have to subtract with: + // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 + - 0x35FDC00; + } + else + { + error_message = "invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF"; + return token_type::parse_error; + } + } + else + { + error_message = "invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF"; + return token_type::parse_error; + } + } + else + { + if (JSON_UNLIKELY(0xDC00 <= codepoint1 and codepoint1 <= 0xDFFF)) + { + error_message = "invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF"; + return token_type::parse_error; + } + } - In this class, the object's limit of nesting is not constraint explicitly. - However, a maximum depth of nesting may be introduced by the compiler or - runtime environment. A theoretical limit can be queried by calling the - @ref max_size function of a JSON object. + // result of the above calculation yields a proper codepoint + assert(0x00 <= codepoint and codepoint <= 0x10FFFF); - #### Storage + // translate codepoint into bytes + if (codepoint < 0x80) + { + // 1-byte characters: 0xxxxxxx (ASCII) + add(codepoint); + } + else if (codepoint <= 0x7FF) + { + // 2-byte characters: 110xxxxx 10xxxxxx + add(0xC0 | (codepoint >> 6)); + add(0x80 | (codepoint & 0x3F)); + } + else if (codepoint <= 0xFFFF) + { + // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx + add(0xE0 | (codepoint >> 12)); + add(0x80 | ((codepoint >> 6) & 0x3F)); + add(0x80 | (codepoint & 0x3F)); + } + else + { + // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + add(0xF0 | (codepoint >> 18)); + add(0x80 | ((codepoint >> 12) & 0x3F)); + add(0x80 | ((codepoint >> 6) & 0x3F)); + add(0x80 | (codepoint & 0x3F)); + } - Objects are stored as pointers in a @ref basic_json type. That is, for any - access to object values, a pointer of type `object_t*` must be - dereferenced. + break; + } - @sa @ref array_t -- type for an array value + // other characters after escape + default: + error_message = "invalid string: forbidden character after backslash"; + return token_type::parse_error; + } - @since version 1.0.0 + break; + } - @note The order name/value pairs are added to the object is *not* - preserved by the library. Therefore, iterating an object may return - name/value pairs in a different order than they were originally stored. In - fact, keys will be traversed in alphabetical order as `std::map` with - `std::less` is used by default. Please note this behavior conforms to [RFC - 7159](http://rfc7159.net/rfc7159), because any order implements the - specified "unordered" nature of JSON objects. - */ - using object_t = ObjectType, - AllocatorType>>; + // invalid control characters + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + case 0x08: + case 0x09: + case 0x0A: + case 0x0B: + case 0x0C: + case 0x0D: + case 0x0E: + case 0x0F: + case 0x10: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + case 0x19: + case 0x1A: + case 0x1B: + case 0x1C: + case 0x1D: + case 0x1E: + case 0x1F: + { + error_message = "invalid string: control character must be escaped"; + return token_type::parse_error; + } + + // U+0020..U+007F (except U+0022 (quote) and U+005C (backspace)) + case 0x20: + case 0x21: + case 0x23: + case 0x24: + case 0x25: + case 0x26: + case 0x27: + case 0x28: + case 0x29: + case 0x2A: + case 0x2B: + case 0x2C: + case 0x2D: + case 0x2E: + case 0x2F: + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + case 0x38: + case 0x39: + case 0x3A: + case 0x3B: + case 0x3C: + case 0x3D: + case 0x3E: + case 0x3F: + case 0x40: + case 0x41: + case 0x42: + case 0x43: + case 0x44: + case 0x45: + case 0x46: + case 0x47: + case 0x48: + case 0x49: + case 0x4A: + case 0x4B: + case 0x4C: + case 0x4D: + case 0x4E: + case 0x4F: + case 0x50: + case 0x51: + case 0x52: + case 0x53: + case 0x54: + case 0x55: + case 0x56: + case 0x57: + case 0x58: + case 0x59: + case 0x5A: + case 0x5B: + case 0x5D: + case 0x5E: + case 0x5F: + case 0x60: + case 0x61: + case 0x62: + case 0x63: + case 0x64: + case 0x65: + case 0x66: + case 0x67: + case 0x68: + case 0x69: + case 0x6A: + case 0x6B: + case 0x6C: + case 0x6D: + case 0x6E: + case 0x6F: + case 0x70: + case 0x71: + case 0x72: + case 0x73: + case 0x74: + case 0x75: + case 0x76: + case 0x77: + case 0x78: + case 0x79: + case 0x7A: + case 0x7B: + case 0x7C: + case 0x7D: + case 0x7E: + case 0x7F: + { + add(current); + break; + } - /*! - @brief a type for an array + // U+0080..U+07FF: bytes C2..DF 80..BF + case 0xC2: + case 0xC3: + case 0xC4: + case 0xC5: + case 0xC6: + case 0xC7: + case 0xC8: + case 0xC9: + case 0xCA: + case 0xCB: + case 0xCC: + case 0xCD: + case 0xCE: + case 0xCF: + case 0xD0: + case 0xD1: + case 0xD2: + case 0xD3: + case 0xD4: + case 0xD5: + case 0xD6: + case 0xD7: + case 0xD8: + case 0xD9: + case 0xDA: + case 0xDB: + case 0xDC: + case 0xDD: + case 0xDE: + case 0xDF: + { + if (JSON_UNLIKELY(not next_byte_in_range({0x80, 0xBF}))) + { + return token_type::parse_error; + } + break; + } - [RFC 7159](http://rfc7159.net/rfc7159) describes JSON arrays as follows: - > An array is an ordered sequence of zero or more values. + // U+0800..U+0FFF: bytes E0 A0..BF 80..BF + case 0xE0: + { + if (JSON_UNLIKELY(not (next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } - To store objects in C++, a type is defined by the template parameters - explained below. + // U+1000..U+CFFF: bytes E1..EC 80..BF 80..BF + // U+E000..U+FFFF: bytes EE..EF 80..BF 80..BF + case 0xE1: + case 0xE2: + case 0xE3: + case 0xE4: + case 0xE5: + case 0xE6: + case 0xE7: + case 0xE8: + case 0xE9: + case 0xEA: + case 0xEB: + case 0xEC: + case 0xEE: + case 0xEF: + { + if (JSON_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } - @tparam ArrayType container type to store arrays (e.g., `std::vector` or - `std::list`) - @tparam AllocatorType allocator to use for arrays (e.g., `std::allocator`) + // U+D000..U+D7FF: bytes ED 80..9F 80..BF + case 0xED: + { + if (JSON_UNLIKELY(not (next_byte_in_range({0x80, 0x9F, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } - #### Default type + // U+10000..U+3FFFF F0 90..BF 80..BF 80..BF + case 0xF0: + { + if (JSON_UNLIKELY(not (next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } - With the default values for @a ArrayType (`std::vector`) and @a - AllocatorType (`std::allocator`), the default value for @a array_t is: + // U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF + case 0xF1: + case 0xF2: + case 0xF3: + { + if (JSON_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } - @code {.cpp} - std::vector< - basic_json, // value_type - std::allocator // allocator_type - > - @endcode + // U+100000..U+10FFFF F4 80..8F 80..BF 80..BF + case 0xF4: + { + if (JSON_UNLIKELY(not (next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } - #### Limits + // remaining bytes (80..C1 and F5..FF) are ill-formed + default: + { + error_message = "invalid string: ill-formed UTF-8 byte"; + return token_type::parse_error; + } + } + } + } - [RFC 7159](http://rfc7159.net/rfc7159) specifies: - > An implementation may set limits on the maximum depth of nesting. + static void strtof(float& f, const char* str, char** endptr) noexcept + { + f = std::strtof(str, endptr); + } - In this class, the array's limit of nesting is not constraint explicitly. - However, a maximum depth of nesting may be introduced by the compiler or - runtime environment. A theoretical limit can be queried by calling the - @ref max_size function of a JSON array. + static void strtof(double& f, const char* str, char** endptr) noexcept + { + f = std::strtod(str, endptr); + } - #### Storage + static void strtof(long double& f, const char* str, char** endptr) noexcept + { + f = std::strtold(str, endptr); + } - Arrays are stored as pointers in a @ref basic_json type. That is, for any - access to array values, a pointer of type `array_t*` must be dereferenced. + /*! + @brief scan a number literal - @sa @ref object_t -- type for an object value + This function scans a string according to Sect. 6 of RFC 7159. - @since version 1.0.0 - */ - using array_t = ArrayType>; + The function is realized with a deterministic finite state machine derived + from the grammar described in RFC 7159. Starting in state "init", the + input is read and used to determined the next state. Only state "done" + accepts the number. State "error" is a trap state to model errors. In the + table below, "anything" means any character but the ones listed before. - /*! - @brief a type for a string + state | 0 | 1-9 | e E | + | - | . | anything + ---------|----------|----------|----------|---------|---------|----------|----------- + init | zero | any1 | [error] | [error] | minus | [error] | [error] + minus | zero | any1 | [error] | [error] | [error] | [error] | [error] + zero | done | done | exponent | done | done | decimal1 | done + any1 | any1 | any1 | exponent | done | done | decimal1 | done + decimal1 | decimal2 | [error] | [error] | [error] | [error] | [error] | [error] + decimal2 | decimal2 | decimal2 | exponent | done | done | done | done + exponent | any2 | any2 | [error] | sign | sign | [error] | [error] + sign | any2 | any2 | [error] | [error] | [error] | [error] | [error] + any2 | any2 | any2 | done | done | done | done | done - [RFC 7159](http://rfc7159.net/rfc7159) describes JSON strings as follows: - > A string is a sequence of zero or more Unicode characters. + The state machine is realized with one label per state (prefixed with + "scan_number_") and `goto` statements between them. The state machine + contains cycles, but any cycle can be left when EOF is read. Therefore, + the function is guaranteed to terminate. - To store objects in C++, a type is defined by the template parameter - described below. Unicode values are split by the JSON class into - byte-sized characters during deserialization. + During scanning, the read bytes are stored in yytext. This string is + then converted to a signed integer, an unsigned integer, or a + floating-point number. - @tparam StringType the container to store strings (e.g., `std::string`). - Note this container is used for keys/names in objects, see @ref object_t. + @return token_type::value_unsigned, token_type::value_integer, or + token_type::value_float if number could be successfully scanned, + token_type::parse_error otherwise - #### Default type + @note The scanner is independent of the current locale. Internally, the + locale's decimal point is used instead of `.` to work with the + locale-dependent converters. + */ + token_type scan_number() + { + // reset yytext to store the number's bytes + reset(); - With the default values for @a StringType (`std::string`), the default - value for @a string_t is: + // the type of the parsed number; initially set to unsigned; will be + // changed if minus sign, decimal point or exponent is read + token_type number_type = token_type::value_unsigned; - @code {.cpp} - std::string - @endcode + // state (init): we just found out we need to scan a number + switch (current) + { + case '-': + { + add(current); + goto scan_number_minus; + } - #### Encoding + case '0': + { + add(current); + goto scan_number_zero; + } - Strings are stored in UTF-8 encoding. Therefore, functions like - `std::string::size()` or `std::string::length()` return the number of - bytes in the string rather than the number of characters or glyphs. + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any1; + } - #### String comparison + default: + { + // all other characters are rejected outside scan_number() + assert(false); // LCOV_EXCL_LINE + } + } - [RFC 7159](http://rfc7159.net/rfc7159) states: - > Software implementations are typically required to test names of object - > members for equality. Implementations that transform the textual - > representation into sequences of Unicode code units and then perform the - > comparison numerically, code unit by code unit, are interoperable in the - > sense that implementations will agree in all cases on equality or - > inequality of two strings. For example, implementations that compare - > strings with escaped characters unconverted may incorrectly find that - > `"a\\b"` and `"a\u005Cb"` are not equal. +scan_number_minus: + // state: we just parsed a leading minus sign + number_type = token_type::value_integer; + switch (get()) + { + case '0': + { + add(current); + goto scan_number_zero; + } - This implementation is interoperable as it does compare strings code unit - by code unit. + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any1; + } - #### Storage + default: + { + error_message = "invalid number; expected digit after '-'"; + return token_type::parse_error; + } + } - String values are stored as pointers in a @ref basic_json type. That is, - for any access to string values, a pointer of type `string_t*` must be - dereferenced. +scan_number_zero: + // state: we just parse a zero (maybe with a leading minus sign) + switch (get()) + { + case '.': + { + add(decimal_point_char); + goto scan_number_decimal1; + } - @since version 1.0.0 - */ - using string_t = StringType; + case 'e': + case 'E': + { + add(current); + goto scan_number_exponent; + } - /*! - @brief a type for a boolean + default: + goto scan_number_done; + } - [RFC 7159](http://rfc7159.net/rfc7159) implicitly describes a boolean as a - type which differentiates the two literals `true` and `false`. +scan_number_any1: + // state: we just parsed a number 0-9 (maybe with a leading minus sign) + switch (get()) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any1; + } - To store objects in C++, a type is defined by the template parameter @a - BooleanType which chooses the type to use. + case '.': + { + add(decimal_point_char); + goto scan_number_decimal1; + } - #### Default type + case 'e': + case 'E': + { + add(current); + goto scan_number_exponent; + } - With the default values for @a BooleanType (`bool`), the default value for - @a boolean_t is: + default: + goto scan_number_done; + } - @code {.cpp} - bool - @endcode +scan_number_decimal1: + // state: we just parsed a decimal point + number_type = token_type::value_float; + switch (get()) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_decimal2; + } - #### Storage + default: + { + error_message = "invalid number; expected digit after '.'"; + return token_type::parse_error; + } + } - Boolean values are stored directly inside a @ref basic_json type. +scan_number_decimal2: + // we just parsed at least one number after a decimal point + switch (get()) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_decimal2; + } - @since version 1.0.0 - */ - using boolean_t = BooleanType; + case 'e': + case 'E': + { + add(current); + goto scan_number_exponent; + } - /*! - @brief a type for a number (integer) + default: + goto scan_number_done; + } - [RFC 7159](http://rfc7159.net/rfc7159) describes numbers as follows: - > The representation of numbers is similar to that used in most - > programming languages. A number is represented in base 10 using decimal - > digits. It contains an integer component that may be prefixed with an - > optional minus sign, which may be followed by a fraction part and/or an - > exponent part. Leading zeros are not allowed. (...) Numeric values that - > cannot be represented in the grammar below (such as Infinity and NaN) - > are not permitted. +scan_number_exponent: + // we just parsed an exponent + number_type = token_type::value_float; + switch (get()) + { + case '+': + case '-': + { + add(current); + goto scan_number_sign; + } - This description includes both integer and floating-point numbers. - However, C++ allows more precise storage if it is known whether the number - is a signed integer, an unsigned integer or a floating-point number. - Therefore, three different types, @ref number_integer_t, @ref - number_unsigned_t and @ref number_float_t are used. + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any2; + } - To store integer numbers in C++, a type is defined by the template - parameter @a NumberIntegerType which chooses the type to use. + default: + { + error_message = + "invalid number; expected '+', '-', or digit after exponent"; + return token_type::parse_error; + } + } - #### Default type +scan_number_sign: + // we just parsed an exponent sign + switch (get()) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any2; + } - With the default values for @a NumberIntegerType (`int64_t`), the default - value for @a number_integer_t is: + default: + { + error_message = "invalid number; expected digit after exponent sign"; + return token_type::parse_error; + } + } - @code {.cpp} - int64_t - @endcode +scan_number_any2: + // we just parsed a number after the exponent or exponent sign + switch (get()) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any2; + } - #### Default behavior + default: + goto scan_number_done; + } - - The restrictions about leading zeros is not enforced in C++. Instead, - leading zeros in integer literals lead to an interpretation as octal - number. Internally, the value will be stored as decimal number. For - instance, the C++ integer literal `010` will be serialized to `8`. - During deserialization, leading zeros yield an error. - - Not-a-number (NaN) values will be serialized to `null`. +scan_number_done: + // unget the character after the number (we only read it to know that + // we are done scanning a number) + unget(); - #### Limits + char* endptr = nullptr; + errno = 0; - [RFC 7159](http://rfc7159.net/rfc7159) specifies: - > An implementation may set limits on the range and precision of numbers. + // try to parse integers first and fall back to floats + if (number_type == token_type::value_unsigned) + { + const auto x = std::strtoull(yytext.data(), &endptr, 10); - When the default type is used, the maximal integer number that can be - stored is `9223372036854775807` (INT64_MAX) and the minimal integer number - that can be stored is `-9223372036854775808` (INT64_MIN). Integer numbers - that are out of range will yield over/underflow when used in a - constructor. During deserialization, too large or small integer numbers - will be automatically be stored as @ref number_unsigned_t or @ref - number_float_t. + // we checked the number format before + assert(endptr == yytext.data() + yytext.size()); - [RFC 7159](http://rfc7159.net/rfc7159) further states: - > Note that when such software is used, numbers that are integers and are - > in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense - > that implementations will agree exactly on their numeric values. + if (errno == 0) + { + value_unsigned = static_cast(x); + if (value_unsigned == x) + { + return token_type::value_unsigned; + } + } + } + else if (number_type == token_type::value_integer) + { + const auto x = std::strtoll(yytext.data(), &endptr, 10); - As this range is a subrange of the exactly supported range [INT64_MIN, - INT64_MAX], this class's integer type is interoperable. + // we checked the number format before + assert(endptr == yytext.data() + yytext.size()); - #### Storage + if (errno == 0) + { + value_integer = static_cast(x); + if (value_integer == x) + { + return token_type::value_integer; + } + } + } - Integer number values are stored directly inside a @ref basic_json type. + // this code is reached if we parse a floating-point number or if an + // integer conversion above failed + strtof(value_float, yytext.data(), &endptr); - @sa @ref number_float_t -- type for number values (floating-point) + // we checked the number format before + assert(endptr == yytext.data() + yytext.size()); - @sa @ref number_unsigned_t -- type for number values (unsigned integer) + return token_type::value_float; + } - @since version 1.0.0 + /*! + @param[in] literal_text the literal text to expect + @param[in] length the length of the passed literal text + @param[in] return_type the token type to return on success */ - using number_integer_t = NumberIntegerType; + token_type scan_literal(const char* literal_text, const std::size_t length, + token_type return_type) + { + assert(current == literal_text[0]); + for (std::size_t i = 1; i < length; ++i) + { + if (JSON_UNLIKELY(get() != literal_text[i])) + { + error_message = "invalid literal"; + return token_type::parse_error; + } + } + return return_type; + } - /*! - @brief a type for a number (unsigned) + ///////////////////// + // input management + ///////////////////// - [RFC 7159](http://rfc7159.net/rfc7159) describes numbers as follows: - > The representation of numbers is similar to that used in most - > programming languages. A number is represented in base 10 using decimal - > digits. It contains an integer component that may be prefixed with an - > optional minus sign, which may be followed by a fraction part and/or an - > exponent part. Leading zeros are not allowed. (...) Numeric values that - > cannot be represented in the grammar below (such as Infinity and NaN) - > are not permitted. + /// reset yytext; current character is beginning of token + void reset() noexcept + { + yytext.clear(); + token_string.clear(); + token_string.push_back(std::char_traits::to_char_type(current)); + } - This description includes both integer and floating-point numbers. - However, C++ allows more precise storage if it is known whether the number - is a signed integer, an unsigned integer or a floating-point number. - Therefore, three different types, @ref number_integer_t, @ref - number_unsigned_t and @ref number_float_t are used. + /* + @brief get next character from the input - To store unsigned integer numbers in C++, a type is defined by the - template parameter @a NumberUnsignedType which chooses the type to use. + This function provides the interface to the used input adapter. It does + not throw in case the input reached EOF, but returns a + `std::char_traits::eof()` in that case. Stores the scanned characters + for use in error messages. - #### Default type + @return character read from the input + */ + std::char_traits::int_type get() + { + ++chars_read; + current = ia->get_character(); + if (JSON_LIKELY(current != std::char_traits::eof())) + { + token_string.push_back(std::char_traits::to_char_type(current)); + } + return current; + } - With the default values for @a NumberUnsignedType (`uint64_t`), the - default value for @a number_unsigned_t is: + /// unget current character (return it again on next get) + void unget() + { + --chars_read; + if (JSON_LIKELY(current != std::char_traits::eof())) + { + ia->unget_character(); + assert(token_string.size() != 0); + token_string.pop_back(); + } + } - @code {.cpp} - uint64_t - @endcode + /// add a character to yytext + void add(int c) + { + yytext.push_back(std::char_traits::to_char_type(c)); + } - #### Default behavior + public: + ///////////////////// + // value getters + ///////////////////// - - The restrictions about leading zeros is not enforced in C++. Instead, - leading zeros in integer literals lead to an interpretation as octal - number. Internally, the value will be stored as decimal number. For - instance, the C++ integer literal `010` will be serialized to `8`. - During deserialization, leading zeros yield an error. - - Not-a-number (NaN) values will be serialized to `null`. + /// return integer value + constexpr number_integer_t get_number_integer() const noexcept + { + return value_integer; + } - #### Limits + /// return unsigned integer value + constexpr number_unsigned_t get_number_unsigned() const noexcept + { + return value_unsigned; + } - [RFC 7159](http://rfc7159.net/rfc7159) specifies: - > An implementation may set limits on the range and precision of numbers. + /// return floating-point value + constexpr number_float_t get_number_float() const noexcept + { + return value_float; + } - When the default type is used, the maximal integer number that can be - stored is `18446744073709551615` (UINT64_MAX) and the minimal integer - number that can be stored is `0`. Integer numbers that are out of range - will yield over/underflow when used in a constructor. During - deserialization, too large or small integer numbers will be automatically - be stored as @ref number_integer_t or @ref number_float_t. + /// return current string value (implicitly resets the token; useful only once) + std::string move_string() + { + return std::move(yytext); + } - [RFC 7159](http://rfc7159.net/rfc7159) further states: - > Note that when such software is used, numbers that are integers and are - > in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense - > that implementations will agree exactly on their numeric values. + ///////////////////// + // diagnostics + ///////////////////// - As this range is a subrange (when considered in conjunction with the - number_integer_t type) of the exactly supported range [0, UINT64_MAX], - this class's integer type is interoperable. + /// return position of last read token + constexpr std::size_t get_position() const noexcept + { + return chars_read; + } - #### Storage + /// return the last read token (for errors only). Will never contain EOF + /// (an arbitrary value that is not a valid char value, often -1), because + /// 255 may legitimately occur. May contain NUL, which should be escaped. + std::string get_token_string() const + { + // escape control characters + std::string result; + for (auto c : token_string) + { + if ('\x00' <= c and c <= '\x1F') + { + // escape control characters + std::stringstream ss; + ss << "(c) << ">"; + result += ss.str(); + } + else + { + // add character as is + result.push_back(c); + } + } - Integer number values are stored directly inside a @ref basic_json type. + return result; + } - @sa @ref number_float_t -- type for number values (floating-point) - @sa @ref number_integer_t -- type for number values (integer) + /// return syntax error message + constexpr const char* get_error_message() const noexcept + { + return error_message; + } - @since version 2.0.0 - */ - using number_unsigned_t = NumberUnsignedType; + ///////////////////// + // actual scanner + ///////////////////// - /*! - @brief a type for a number (floating-point) + token_type scan() + { + // read next character and ignore whitespace + do + { + get(); + } + while (current == ' ' or current == '\t' or current == '\n' or current == '\r'); + + switch (current) + { + // structural characters + case '[': + return token_type::begin_array; + case ']': + return token_type::end_array; + case '{': + return token_type::begin_object; + case '}': + return token_type::end_object; + case ':': + return token_type::name_separator; + case ',': + return token_type::value_separator; + + // literals + case 't': + return scan_literal("true", 4, token_type::literal_true); + case 'f': + return scan_literal("false", 5, token_type::literal_false); + case 'n': + return scan_literal("null", 4, token_type::literal_null); + + // string + case '\"': + return scan_string(); + + // number + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return scan_number(); + + // end of input (the null byte is needed when parsing from + // string literals) + case '\0': + case std::char_traits::eof(): + return token_type::end_of_input; + + // error + default: + error_message = "invalid literal"; + return token_type::parse_error; + } + } - [RFC 7159](http://rfc7159.net/rfc7159) describes numbers as follows: - > The representation of numbers is similar to that used in most - > programming languages. A number is represented in base 10 using decimal - > digits. It contains an integer component that may be prefixed with an - > optional minus sign, which may be followed by a fraction part and/or an - > exponent part. Leading zeros are not allowed. (...) Numeric values that - > cannot be represented in the grammar below (such as Infinity and NaN) - > are not permitted. + private: + /// input adapter + detail::input_adapter_t ia = nullptr; - This description includes both integer and floating-point numbers. - However, C++ allows more precise storage if it is known whether the number - is a signed integer, an unsigned integer or a floating-point number. - Therefore, three different types, @ref number_integer_t, @ref - number_unsigned_t and @ref number_float_t are used. + /// the current character + std::char_traits::int_type current = std::char_traits::eof(); - To store floating-point numbers in C++, a type is defined by the template - parameter @a NumberFloatType which chooses the type to use. + /// the number of characters read + std::size_t chars_read = 0; - #### Default type + /// raw input token string (for error messages) + std::vector token_string {}; - With the default values for @a NumberFloatType (`double`), the default - value for @a number_float_t is: + /// buffer for variable-length tokens (numbers, strings) + std::string yytext {}; - @code {.cpp} - double - @endcode + /// a description of occurred lexer errors + const char* error_message = ""; - #### Default behavior + // number values + number_integer_t value_integer = 0; + number_unsigned_t value_unsigned = 0; + number_float_t value_float = 0; - - The restrictions about leading zeros is not enforced in C++. Instead, - leading zeros in floating-point literals will be ignored. Internally, - the value will be stored as decimal number. For instance, the C++ - floating-point literal `01.2` will be serialized to `1.2`. During - deserialization, leading zeros yield an error. - - Not-a-number (NaN) values will be serialized to `null`. + /// the decimal point + const char decimal_point_char = '.'; +}; - #### Limits +/*! +@brief syntax analysis - [RFC 7159](http://rfc7159.net/rfc7159) states: - > This specification allows implementations to set limits on the range and - > precision of numbers accepted. Since software that implements IEEE - > 754-2008 binary64 (double precision) numbers is generally available and - > widely used, good interoperability can be achieved by implementations - > that expect no more precision or range than these provide, in the sense - > that implementations will approximate JSON numbers within the expected - > precision. +This class implements a recursive decent parser. +*/ +template +class parser +{ + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + using lexer_t = lexer; + using token_type = typename lexer_t::token_type; - This implementation does exactly follow this approach, as it uses double - precision floating-point numbers. Note values smaller than - `-1.79769313486232e+308` and values greater than `1.79769313486232e+308` - will be stored as NaN internally and be serialized to `null`. + public: + enum class parse_event_t : uint8_t + { + /// the parser read `{` and started to process a JSON object + object_start, + /// the parser read `}` and finished processing a JSON object + object_end, + /// the parser read `[` and started to process a JSON array + array_start, + /// the parser read `]` and finished processing a JSON array + array_end, + /// the parser read a key of a value in an object + key, + /// the parser finished reading a JSON value + value + }; - #### Storage + using parser_callback_t = + std::function; - Floating-point number values are stored directly inside a @ref basic_json - type. + /// a parser reading from an input adapter + explicit parser(detail::input_adapter_t adapter, + const parser_callback_t cb = nullptr, + const bool allow_exceptions_ = true) + : callback(cb), m_lexer(adapter), allow_exceptions(allow_exceptions_) + {} - @sa @ref number_integer_t -- type for number values (integer) + /*! + @brief public parser interface - @sa @ref number_unsigned_t -- type for number values (unsigned integer) + @param[in] strict whether to expect the last token to be EOF + @param[in,out] result parsed JSON value - @since version 1.0.0 + @throw parse_error.101 in case of an unexpected token + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails */ - using number_float_t = NumberFloatType; + void parse(const bool strict, BasicJsonType& result) + { + // read first token + get_token(); - /// @} + parse_internal(true, result); + result.assert_invariant(); - private: + // in strict mode, input must be completely read + if (strict) + { + get_token(); + expect(token_type::end_of_input); + } - /// helper for exception-safe object creation - template - static T* create(Args&& ... args) - { - AllocatorType alloc; - auto deleter = [&](T * object) + // in case of an error, return discarded value + if (errored) { - alloc.deallocate(object, 1); - }; - std::unique_ptr object(alloc.allocate(1), deleter); - alloc.construct(object.get(), std::forward(args)...); - assert(object != nullptr); - return object.release(); - } + result = value_t::discarded; + return; + } - //////////////////////// - // JSON value storage // - //////////////////////// + // set top-level value to null if it was discarded by the callback + // function + if (result.is_discarded()) + { + result = nullptr; + } + } /*! - @brief a JSON value + @brief public accept interface - The actual storage for a JSON value of the @ref basic_json class. This - union combines the different storage types for the JSON value types - defined in @ref value_t. + @param[in] strict whether to expect the last token to be EOF + @return whether the input is a proper JSON text + */ + bool accept(const bool strict = true) + { + // read first token + get_token(); - JSON type | value_t type | used type - --------- | --------------- | ------------------------ - object | object | pointer to @ref object_t - array | array | pointer to @ref array_t - string | string | pointer to @ref string_t - boolean | boolean | @ref boolean_t - number | number_integer | @ref number_integer_t - number | number_unsigned | @ref number_unsigned_t - number | number_float | @ref number_float_t - null | null | *no value is stored* + if (not accept_internal()) + { + return false; + } - @note Variable-length types (objects, arrays, and strings) are stored as - pointers. The size of the union should not exceed 64 bits if the default - value types are used. + // strict => last token must be EOF + return not strict or (get_token() == token_type::end_of_input); + } - @since version 1.0.0 + private: + /*! + @brief the actual parser + @throw parse_error.101 in case of an unexpected token + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails */ - union json_value + void parse_internal(bool keep, BasicJsonType& result) { - /// object (stored with pointer to save storage) - object_t* object; - /// array (stored with pointer to save storage) - array_t* array; - /// string (stored with pointer to save storage) - string_t* string; - /// boolean - boolean_t boolean; - /// number (integer) - number_integer_t number_integer; - /// number (unsigned integer) - number_unsigned_t number_unsigned; - /// number (floating-point) - number_float_t number_float; + // never parse after a parse error was detected + assert(not errored); - /// default constructor (for null values) - json_value() = default; - /// constructor for booleans - json_value(boolean_t v) noexcept : boolean(v) {} - /// constructor for numbers (integer) - json_value(number_integer_t v) noexcept : number_integer(v) {} - /// constructor for numbers (unsigned) - json_value(number_unsigned_t v) noexcept : number_unsigned(v) {} - /// constructor for numbers (floating-point) - json_value(number_float_t v) noexcept : number_float(v) {} - /// constructor for empty values of a given type - json_value(value_t t) + // start with a discarded value + if (not result.is_discarded()) { - switch (t) + result.m_value.destroy(result.m_type); + result.m_type = value_t::discarded; + } + + switch (last_token) + { + case token_type::begin_object: { - case value_t::object: + if (keep) { - object = create(); - break; + if (callback) + { + keep = callback(depth++, parse_event_t::object_start, result); + } + + if (not callback or keep) + { + // explicitly set result to object to cope with {} + result.m_type = value_t::object; + result.m_value = value_t::object; + } } - case value_t::array: + // read next token + get_token(); + + // closing } -> we are done + if (last_token == token_type::end_object) { - array = create(); + if (keep and callback and not callback(--depth, parse_event_t::object_end, result)) + { + result.m_value.destroy(result.m_type); + result.m_type = value_t::discarded; + } break; } - case value_t::string: + // parse values + std::string key; + BasicJsonType value; + while (true) { - string = create(""); + // store key + if (not expect(token_type::value_string)) + { + return; + } + key = m_lexer.move_string(); + + bool keep_tag = false; + if (keep) + { + if (callback) + { + BasicJsonType k(key); + keep_tag = callback(depth, parse_event_t::key, k); + } + else + { + keep_tag = true; + } + } + + // parse separator (:) + get_token(); + if (not expect(token_type::name_separator)) + { + return; + } + + // parse and add value + get_token(); + value.m_value.destroy(value.m_type); + value.m_type = value_t::discarded; + parse_internal(keep, value); + + if (JSON_UNLIKELY(errored)) + { + return; + } + + if (keep and keep_tag and not value.is_discarded()) + { + result.m_value.object->emplace(std::move(key), std::move(value)); + } + + // comma -> next value + get_token(); + if (last_token == token_type::value_separator) + { + get_token(); + continue; + } + + // closing } + if (not expect(token_type::end_object)) + { + return; + } break; } - case value_t::boolean: + if (keep and callback and not callback(--depth, parse_event_t::object_end, result)) { - boolean = boolean_t(false); - break; + result.m_value.destroy(result.m_type); + result.m_type = value_t::discarded; } + break; + } - case value_t::number_integer: + case token_type::begin_array: + { + if (keep) { - number_integer = number_integer_t(0); - break; + if (callback) + { + keep = callback(depth++, parse_event_t::array_start, result); + } + + if (not callback or keep) + { + // explicitly set result to array to cope with [] + result.m_type = value_t::array; + result.m_value = value_t::array; + } } - case value_t::number_unsigned: + // read next token + get_token(); + + // closing ] -> we are done + if (last_token == token_type::end_array) { - number_unsigned = number_unsigned_t(0); + if (callback and not callback(--depth, parse_event_t::array_end, result)) + { + result.m_value.destroy(result.m_type); + result.m_type = value_t::discarded; + } break; } - case value_t::number_float: + // parse values + BasicJsonType value; + while (true) { - number_float = number_float_t(0.0); + // parse value + value.m_value.destroy(value.m_type); + value.m_type = value_t::discarded; + parse_internal(keep, value); + + if (JSON_UNLIKELY(errored)) + { + return; + } + + if (keep and not value.is_discarded()) + { + result.m_value.array->push_back(std::move(value)); + } + + // comma -> next value + get_token(); + if (last_token == token_type::value_separator) + { + get_token(); + continue; + } + + // closing ] + if (not expect(token_type::end_array)) + { + return; + } break; } - case value_t::null: + if (keep and callback and not callback(--depth, parse_event_t::array_end, result)) { - break; + result.m_value.destroy(result.m_type); + result.m_type = value_t::discarded; } + break; + } - default: + case token_type::literal_null: + { + result.m_type = value_t::null; + break; + } + + case token_type::value_string: + { + result.m_type = value_t::string; + result.m_value = m_lexer.move_string(); + break; + } + + case token_type::literal_true: + { + result.m_type = value_t::boolean; + result.m_value = true; + break; + } + + case token_type::literal_false: + { + result.m_type = value_t::boolean; + result.m_value = false; + break; + } + + case token_type::value_unsigned: + { + result.m_type = value_t::number_unsigned; + result.m_value = m_lexer.get_number_unsigned(); + break; + } + + case token_type::value_integer: + { + result.m_type = value_t::number_integer; + result.m_value = m_lexer.get_number_integer(); + break; + } + + case token_type::value_float: + { + result.m_type = value_t::number_float; + result.m_value = m_lexer.get_number_float(); + + // throw in case of infinity or NAN + if (JSON_UNLIKELY(not std::isfinite(result.m_value.number_float))) { - if (t == value_t::null) + if (allow_exceptions) { - JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 2.1.1")); // LCOV_EXCL_LINE + JSON_THROW(out_of_range::create(406, "number overflow parsing '" + + m_lexer.get_token_string() + "'")); } - break; + expect(token_type::uninitialized); } + break; } - } - /// constructor for strings - json_value(const string_t& value) - { - string = create(value); - } + case token_type::parse_error: + { + // using "uninitialized" to avoid "expected" message + if (not expect(token_type::uninitialized)) + { + return; + } + break; // LCOV_EXCL_LINE + } - /// constructor for objects - json_value(const object_t& value) - { - object = create(value); + default: + { + // the last token was unexpected; we expected a value + if (not expect(token_type::literal_or_value)) + { + return; + } + break; // LCOV_EXCL_LINE + } } - /// constructor for arrays - json_value(const array_t& value) + if (keep and callback and not callback(depth, parse_event_t::value, result)) { - array = create(value); + result.m_type = value_t::discarded; } - }; + } /*! - @brief checks the class invariants + @brief the actual acceptor - This function asserts the class invariants. It needs to be called at the - end of every constructor to make sure that created objects respect the - invariant. Furthermore, it has to be called each time the type of a JSON - value is changed, because the invariant expresses a relationship between - @a m_type and @a m_value. + @invariant 1. The last token is not yet processed. Therefore, the caller + of this function must make sure a token has been read. + 2. When this function returns, the last token is processed. + That is, the last read character was already considered. + + This invariant makes sure that no token needs to be "unput". */ - void assert_invariant() const + bool accept_internal() { - assert(m_type != value_t::object or m_value.object != nullptr); - assert(m_type != value_t::array or m_value.array != nullptr); - assert(m_type != value_t::string or m_value.string != nullptr); - } + switch (last_token) + { + case token_type::begin_object: + { + // read next token + get_token(); - public: - ////////////////////////// - // JSON parser callback // - ////////////////////////// + // closing } -> we are done + if (last_token == token_type::end_object) + { + return true; + } - /*! - @brief JSON callback events + // parse values + while (true) + { + // parse key + if (last_token != token_type::value_string) + { + return false; + } - This enumeration lists the parser events that can trigger calling a - callback function of type @ref parser_callback_t during parsing. + // parse separator (:) + get_token(); + if (last_token != token_type::name_separator) + { + return false; + } - @image html callback_events.png "Example when certain parse events are triggered" + // parse value + get_token(); + if (not accept_internal()) + { + return false; + } - @since version 1.0.0 - */ - enum class parse_event_t : uint8_t - { - /// the parser read `{` and started to process a JSON object - object_start, - /// the parser read `}` and finished processing a JSON object - object_end, - /// the parser read `[` and started to process a JSON array - array_start, - /// the parser read `]` and finished processing a JSON array - array_end, - /// the parser read a key of a value in an object - key, - /// the parser finished reading a JSON value - value - }; + // comma -> next value + get_token(); + if (last_token == token_type::value_separator) + { + get_token(); + continue; + } - /*! - @brief per-element parser callback type + // closing } + return (last_token == token_type::end_object); + } + } - With a parser callback function, the result of parsing a JSON text can be - influenced. When passed to @ref parse(std::istream&, const - parser_callback_t) or @ref parse(const CharT, const parser_callback_t), - it is called on certain events (passed as @ref parse_event_t via parameter - @a event) with a set recursion depth @a depth and context JSON value - @a parsed. The return value of the callback function is a boolean - indicating whether the element that emitted the callback shall be kept or - not. + case token_type::begin_array: + { + // read next token + get_token(); - We distinguish six scenarios (determined by the event type) in which the - callback function can be called. The following table describes the values - of the parameters @a depth, @a event, and @a parsed. + // closing ] -> we are done + if (last_token == token_type::end_array) + { + return true; + } - parameter @a event | description | parameter @a depth | parameter @a parsed - ------------------ | ----------- | ------------------ | ------------------- - parse_event_t::object_start | the parser read `{` and started to process a JSON object | depth of the parent of the JSON object | a JSON value with type discarded - parse_event_t::key | the parser read a key of a value in an object | depth of the currently parsed JSON object | a JSON string containing the key - parse_event_t::object_end | the parser read `}` and finished processing a JSON object | depth of the parent of the JSON object | the parsed JSON object - parse_event_t::array_start | the parser read `[` and started to process a JSON array | depth of the parent of the JSON array | a JSON value with type discarded - parse_event_t::array_end | the parser read `]` and finished processing a JSON array | depth of the parent of the JSON array | the parsed JSON array - parse_event_t::value | the parser finished reading a JSON value | depth of the value | the parsed JSON value + // parse values + while (true) + { + // parse value + if (not accept_internal()) + { + return false; + } - @image html callback_events.png "Example when certain parse events are triggered" + // comma -> next value + get_token(); + if (last_token == token_type::value_separator) + { + get_token(); + continue; + } - Discarding a value (i.e., returning `false`) has different effects - depending on the context in which function was called: + // closing ] + return (last_token == token_type::end_array); + } + } - - Discarded values in structured types are skipped. That is, the parser - will behave as if the discarded value was never read. - - In case a value outside a structured type is skipped, it is replaced - with `null`. This case happens if the top-level element is skipped. + case token_type::value_float: + { + // reject infinity or NAN + return std::isfinite(m_lexer.get_number_float()); + } - @param[in] depth the depth of the recursion during parsing + case token_type::literal_false: + case token_type::literal_null: + case token_type::literal_true: + case token_type::value_integer: + case token_type::value_string: + case token_type::value_unsigned: + return true; - @param[in] event an event of type parse_event_t indicating the context in - the callback function has been called + default: // the last token was unexpected + return false; + } + } - @param[in,out] parsed the current intermediate parse result; note that - writing to this value has no effect for parse_event_t::key events + /// get next token from lexer + token_type get_token() + { + return (last_token = m_lexer.scan()); + } - @return Whether the JSON value which called the function during parsing - should be kept (`true`) or not (`false`). In the latter case, it is either - skipped completely or replaced by an empty discarded object. + /*! + @throw parse_error.101 if expected token did not occur + */ + bool expect(token_type t) + { + if (JSON_UNLIKELY(t != last_token)) + { + errored = true; + expected = t; + if (allow_exceptions) + { + throw_exception(); + } + else + { + return false; + } + } - @sa @ref parse(std::istream&, parser_callback_t) or - @ref parse(const CharT, const parser_callback_t) for examples + return true; + } - @since version 1.0.0 - */ - using parser_callback_t = std::function; + [[noreturn]] void throw_exception() const + { + std::string error_msg = "syntax error - "; + if (last_token == token_type::parse_error) + { + error_msg += std::string(m_lexer.get_error_message()) + "; last read: '" + + m_lexer.get_token_string() + "'"; + } + else + { + error_msg += "unexpected " + std::string(lexer_t::token_type_name(last_token)); + } + if (expected != token_type::uninitialized) + { + error_msg += "; expected " + std::string(lexer_t::token_type_name(expected)); + } - ////////////////// - // constructors // - ////////////////// + JSON_THROW(parse_error::create(101, m_lexer.get_position(), error_msg)); + } - /// @name constructors and destructors - /// Constructors of class @ref basic_json, copy/move constructor, copy - /// assignment, static functions creating objects, and the destructor. - /// @{ + private: + /// current level of recursion + int depth = 0; + /// callback function + const parser_callback_t callback = nullptr; + /// the type of the last read token + token_type last_token = token_type::uninitialized; + /// the lexer + lexer_t m_lexer; + /// whether a syntax error occurred + bool errored = false; + /// possible reason for the syntax error + token_type expected = token_type::uninitialized; + /// whether to throw exceptions in case of errors + const bool allow_exceptions = true; +}; - /*! - @brief create an empty value with a given type +/////////////// +// iterators // +/////////////// - Create an empty JSON value with a given type. The value will be default - initialized with an empty value which depends on the type: +/*! +@brief an iterator for primitive JSON types - Value type | initial value - ----------- | ------------- - null | `null` - boolean | `false` - string | `""` - number | `0` - object | `{}` - array | `[]` +This class models an iterator for primitive JSON types (boolean, number, +string). It's only purpose is to allow the iterator/const_iterator classes +to "iterate" over primitive values. Internally, the iterator is modeled by +a `difference_type` variable. Value begin_value (`0`) models the begin, +end_value (`1`) models past the end. +*/ +class primitive_iterator_t +{ + public: + using difference_type = std::ptrdiff_t; - @param[in] value_type the type of the value to create + constexpr difference_type get_value() const noexcept + { + return m_it; + } - @complexity Constant. + /// set iterator to a defined beginning + void set_begin() noexcept + { + m_it = begin_value; + } - @liveexample{The following code shows the constructor for different @ref - value_t values,basic_json__value_t} + /// set iterator to a defined past the end + void set_end() noexcept + { + m_it = end_value; + } - @since version 1.0.0 - */ - basic_json(const value_t value_type) - : m_type(value_type), m_value(value_type) + /// return whether the iterator can be dereferenced + constexpr bool is_begin() const noexcept { - assert_invariant(); + return m_it == begin_value; } - /*! - @brief create a null object + /// return whether the iterator is at end + constexpr bool is_end() const noexcept + { + return m_it == end_value; + } - Create a `null` JSON value. It either takes a null pointer as parameter - (explicitly creating `null`) or no parameter (implicitly creating `null`). - The passed null pointer itself is not read -- it is only used to choose - the right constructor. + friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept + { + return lhs.m_it == rhs.m_it; + } - @complexity Constant. + friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept + { + return lhs.m_it < rhs.m_it; + } - @exceptionsafety No-throw guarantee: this constructor never throws - exceptions. + primitive_iterator_t operator+(difference_type i) + { + auto result = *this; + result += i; + return result; + } - @liveexample{The following code shows the constructor with and without a - null pointer parameter.,basic_json__nullptr_t} + friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept + { + return lhs.m_it - rhs.m_it; + } - @since version 1.0.0 - */ - basic_json(std::nullptr_t = nullptr) noexcept - : basic_json(value_t::null) + friend std::ostream& operator<<(std::ostream& os, primitive_iterator_t it) { - assert_invariant(); + return os << it.m_it; } - /*! - @brief create a JSON value + primitive_iterator_t& operator++() + { + ++m_it; + return *this; + } - This is a "catch all" constructor for all compatible JSON types; that is, - types for which a `to_json()` method exsits. The constructor forwards the - parameter @a val to that method (to `json_serializer
::to_json` method - with `U = uncvref_t`, to be exact). + primitive_iterator_t operator++(int) + { + auto result = *this; + m_it++; + return result; + } - Template type @a CompatibleType includes, but is not limited to, the - following types: - - **arrays**: @ref array_t and all kinds of compatible containers such as - `std::vector`, `std::deque`, `std::list`, `std::forward_list`, - `std::array`, `std::set`, `std::unordered_set`, `std::multiset`, and - `unordered_multiset` with a `value_type` from which a @ref basic_json - value can be constructed. - - **objects**: @ref object_t and all kinds of compatible associative - containers such as `std::map`, `std::unordered_map`, `std::multimap`, - and `std::unordered_multimap` with a `key_type` compatible to - @ref string_t and a `value_type` from which a @ref basic_json value can - be constructed. - - **strings**: @ref string_t, string literals, and all compatible string - containers can be used. - - **numbers**: @ref number_integer_t, @ref number_unsigned_t, - @ref number_float_t, and all convertible number types such as `int`, - `size_t`, `int64_t`, `float` or `double` can be used. - - **boolean**: @ref boolean_t / `bool` can be used. + primitive_iterator_t& operator--() + { + --m_it; + return *this; + } - See the examples below. + primitive_iterator_t operator--(int) + { + auto result = *this; + m_it--; + return result; + } - @tparam CompatibleType a type such that: - - @a CompatibleType is not derived from `std::istream`, - - @a CompatibleType is not @ref basic_json (to avoid hijacking copy/move - constructors), - - @a CompatibleType is not a @ref basic_json nested type (e.g., - @ref json_pointer, @ref iterator, etc ...) - - @ref @ref json_serializer has a - `to_json(basic_json_t&, CompatibleType&&)` method - - @tparam U = `uncvref_t` - - @param[in] val the value to be forwarded - - @complexity Usually linear in the size of the passed @a val, also - depending on the implementation of the called `to_json()` - method. - - @throw what `json_serializer::to_json()` throws - - @liveexample{The following code shows the constructor with several - compatible types.,basic_json__CompatibleType} + primitive_iterator_t& operator+=(difference_type n) + { + m_it += n; + return *this; + } - @since version 2.1.0 - */ - template, - detail::enable_if_t::value and - not std::is_same::value and - not detail::is_basic_json_nested_type< - basic_json_t, U>::value and - detail::has_to_json::value, - int> = 0> - basic_json(CompatibleType && val) noexcept_if(noexcept_if(JSONSerializer::to_json( - std::declval(), std::forward(val)))) + primitive_iterator_t& operator-=(difference_type n) { - JSONSerializer::to_json(*this, std::forward(val)); - assert_invariant(); + m_it -= n; + return *this; } - /*! - @brief create a container (array or object) from an initializer list + private: + static constexpr difference_type begin_value = 0; + static constexpr difference_type end_value = begin_value + 1; - Creates a JSON value of type array or object from the passed initializer - list @a init. In case @a type_deduction is `true` (default), the type of - the JSON value to be created is deducted from the initializer list @a init - according to the following rules: + /// iterator as signed integer type + difference_type m_it = (std::numeric_limits::min)(); +}; - 1. If the list is empty, an empty JSON object value `{}` is created. - 2. If the list consists of pairs whose first element is a string, a JSON - object value is created where the first elements of the pairs are - treated as keys and the second elements are as values. - 3. In all other cases, an array is created. +/*! +@brief an iterator value - The rules aim to create the best fit between a C++ initializer list and - JSON values. The rationale is as follows: +@note This structure could easily be a union, but MSVC currently does not allow +unions members with complex constructors, see https://github.com/nlohmann/json/pull/105. +*/ +template struct internal_iterator +{ + /// iterator for JSON objects + typename BasicJsonType::object_t::iterator object_iterator {}; + /// iterator for JSON arrays + typename BasicJsonType::array_t::iterator array_iterator {}; + /// generic iterator for all other types + primitive_iterator_t primitive_iterator {}; +}; - 1. The empty initializer list is written as `{}` which is exactly an empty - JSON object. - 2. C++ has now way of describing mapped types other than to list a list of - pairs. As JSON requires that keys must be of type string, rule 2 is the - weakest constraint one can pose on initializer lists to interpret them - as an object. - 3. In all other cases, the initializer list could not be interpreted as - JSON object type, so interpreting it as JSON array type is safe. +template class iteration_proxy; - With the rules described above, the following JSON values cannot be - expressed by an initializer list: +/*! +@brief a template for a bidirectional iterator for the @ref basic_json class - - the empty array (`[]`): use @ref array(std::initializer_list) - with an empty initializer list in this case - - arrays whose elements satisfy rule 2: use @ref - array(std::initializer_list) with the same initializer list - in this case +This class implements a both iterators (iterator and const_iterator) for the +@ref basic_json class. - @note When used without parentheses around an empty initializer list, @ref - basic_json() is called instead of this function, yielding the JSON null - value. +@note An iterator is called *initialized* when a pointer to a JSON value has + been set (e.g., by a constructor or a copy assignment). If the iterator is + default-constructed, it is *uninitialized* and most methods are undefined. + **The library uses assertions to detect calls on uninitialized iterators.** - @param[in] init initializer list with JSON values +@requirement The class satisfies the following concept requirements: +- +[BidirectionalIterator](http://en.cppreference.com/w/cpp/concept/BidirectionalIterator): + The iterator that can be moved can be moved in both directions (i.e. + incremented and decremented). - @param[in] type_deduction internal parameter; when set to `true`, the type - of the JSON value is deducted from the initializer list @a init; when set - to `false`, the type provided via @a manual_type is forced. This mode is - used by the functions @ref array(std::initializer_list) and - @ref object(std::initializer_list). +@since version 1.0.0, simplified in version 2.0.9, change to bidirectional + iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593) +*/ +template +class iter_impl +{ + /// allow basic_json to access private members + friend iter_impl::value, typename std::remove_const::type, const BasicJsonType>::type>; + friend BasicJsonType; + friend iteration_proxy; - @param[in] manual_type internal parameter; when @a type_deduction is set - to `false`, the created JSON value will use the provided type (only @ref - value_t::array and @ref value_t::object are valid); when @a type_deduction - is set to `true`, this parameter has no effect + using object_t = typename BasicJsonType::object_t; + using array_t = typename BasicJsonType::array_t; + // make sure BasicJsonType is basic_json or const basic_json + static_assert(is_basic_json::type>::value, + "iter_impl only accepts (const) basic_json"); - @throw type_error.301 if @a type_deduction is `false`, @a manual_type is - `value_t::object`, but @a init contains an element which is not a pair - whose first element is a string. In this case, the constructor could not - create an object. If @a type_deduction would have be `true`, an array - would have been created. See @ref object(std::initializer_list) - for an example. + public: - @complexity Linear in the size of the initializer list @a init. + /// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. + /// The C++ Standard has never required user-defined iterators to derive from std::iterator. + /// A user-defined iterator should provide publicly accessible typedefs named + /// iterator_category, value_type, difference_type, pointer, and reference. + /// Note that value_type is required to be non-const, even for constant iterators. + using iterator_category = std::bidirectional_iterator_tag; - @liveexample{The example below shows how JSON values are created from - initializer lists.,basic_json__list_init_t} + /// the type of the values when the iterator is dereferenced + using value_type = typename BasicJsonType::value_type; + /// a type to represent differences between iterators + using difference_type = typename BasicJsonType::difference_type; + /// defines a pointer to the type iterated over (value_type) + using pointer = typename std::conditional::value, + typename BasicJsonType::const_pointer, + typename BasicJsonType::pointer>::type; + /// defines a reference to the type iterated over (value_type) + using reference = + typename std::conditional::value, + typename BasicJsonType::const_reference, + typename BasicJsonType::reference>::type; - @sa @ref array(std::initializer_list) -- create a JSON array - value from an initializer list - @sa @ref object(std::initializer_list) -- create a JSON object - value from an initializer list + /// default constructor + iter_impl() = default; - @since version 1.0.0 + /*! + @brief constructor for a given JSON instance + @param[in] object pointer to a JSON object for this iterator + @pre object != nullptr + @post The iterator is initialized; i.e. `m_object != nullptr`. */ - basic_json(std::initializer_list init, - bool type_deduction = true, - value_t manual_type = value_t::array) + explicit iter_impl(pointer object) noexcept : m_object(object) { - // check if each element is an array with two elements whose first - // element is a string - bool is_an_object = std::all_of(init.begin(), init.end(), - [](const basic_json & element) - { - return element.is_array() and element.size() == 2 and element[0].is_string(); - }); + assert(m_object != nullptr); - // adjust type if type deduction is not wanted - if (not type_deduction) + switch (m_object->m_type) { - // if array is wanted, do not create an object though possible - if (manual_type == value_t::array) + case value_t::object: { - is_an_object = false; + m_it.object_iterator = typename object_t::iterator(); + break; } - // if object is wanted but impossible, throw an exception - if (manual_type == value_t::object and not is_an_object) + case value_t::array: { - JSON_THROW(type_error::create(301, "cannot create object from initializer list")); + m_it.array_iterator = typename array_t::iterator(); + break; } - } - - if (is_an_object) - { - // the initializer list is a list of pairs -> create object - m_type = value_t::object; - m_value = value_t::object; - std::for_each(init.begin(), init.end(), [this](const basic_json & element) + default: { - m_value.object->emplace(*(element[0].m_value.string), element[1]); - }); - } - else - { - // the initializer list describes an array -> create array - m_type = value_t::array; - m_value.array = create(init); + m_it.primitive_iterator = primitive_iterator_t(); + break; + } } - - assert_invariant(); } /*! - @brief explicitly create an array from an initializer list - - Creates a JSON array value from a given initializer list. That is, given a - list of values `a, b, c`, creates the JSON value `[a, b, c]`. If the - initializer list is empty, the empty array `[]` is created. - - @note This function is only needed to express two edge cases that cannot - be realized with the initializer list constructor (@ref - basic_json(std::initializer_list, bool, value_t)). These cases - are: - 1. creating an array whose elements are all pairs whose first element is a - string -- in this case, the initializer list constructor would create an - object, taking the first elements as keys - 2. creating an empty array -- passing the empty initializer list to the - initializer list constructor yields an empty object - - @param[in] init initializer list with JSON values to create an array from - (optional) - - @return JSON array value - - @complexity Linear in the size of @a init. - - @liveexample{The following code shows an example for the `array` - function.,array} + @note The conventional copy constructor and copy assignment are implicitly + defined. Combined with the following converting constructor and + assignment, they support: (1) copy from iterator to iterator, (2) + copy from const iterator to const iterator, and (3) conversion from + iterator to const iterator. However conversion from const iterator + to iterator is not defined. + */ - @sa @ref basic_json(std::initializer_list, bool, value_t) -- - create a JSON value from an initializer list - @sa @ref object(std::initializer_list) -- create a JSON object - value from an initializer list + /*! + @brief converting constructor + @param[in] other non-const iterator to copy from + @note It is not checked whether @a other is initialized. + */ + iter_impl(const iter_impl::type>& other) noexcept + : m_object(other.m_object), m_it(other.m_it) {} - @since version 1.0.0 + /*! + @brief converting assignment + @param[in,out] other non-const iterator to copy from + @return const/non-const iterator + @note It is not checked whether @a other is initialized. */ - static basic_json array(std::initializer_list init = - std::initializer_list()) + iter_impl& operator=(const iter_impl::type>& other) noexcept { - return basic_json(init, false, value_t::array); + m_object = other.m_object; + m_it = other.m_it; + return *this; } + private: /*! - @brief explicitly create an object from an initializer list + @brief set the iterator to the first value + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + void set_begin() noexcept + { + assert(m_object != nullptr); - Creates a JSON object value from a given initializer list. The initializer - lists elements must be pairs, and their first elements must be strings. If - the initializer list is empty, the empty object `{}` is created. + switch (m_object->m_type) + { + case value_t::object: + { + m_it.object_iterator = m_object->m_value.object->begin(); + break; + } - @note This function is only added for symmetry reasons. In contrast to the - related function @ref array(std::initializer_list), there are - no cases which can only be expressed by this function. That is, any - initializer list @a init can also be passed to the initializer list - constructor @ref basic_json(std::initializer_list, bool, value_t). + case value_t::array: + { + m_it.array_iterator = m_object->m_value.array->begin(); + break; + } - @param[in] init initializer list to create an object from (optional) + case value_t::null: + { + // set to end so begin()==end() is true: null is empty + m_it.primitive_iterator.set_end(); + break; + } - @return JSON object value + default: + { + m_it.primitive_iterator.set_begin(); + break; + } + } + } - @throw type_error.301 if @a init is not a list of pairs whose first - elements are strings. In this case, no object can be created. When such a - value is passed to @ref basic_json(std::initializer_list, bool, value_t), - an array would have been created from the passed initializer list @a init. - See example below. + /*! + @brief set the iterator past the last value + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + void set_end() noexcept + { + assert(m_object != nullptr); - @complexity Linear in the size of @a init. + switch (m_object->m_type) + { + case value_t::object: + { + m_it.object_iterator = m_object->m_value.object->end(); + break; + } - @liveexample{The following code shows an example for the `object` - function.,object} + case value_t::array: + { + m_it.array_iterator = m_object->m_value.array->end(); + break; + } - @sa @ref basic_json(std::initializer_list, bool, value_t) -- - create a JSON value from an initializer list - @sa @ref array(std::initializer_list) -- create a JSON array - value from an initializer list + default: + { + m_it.primitive_iterator.set_end(); + break; + } + } + } - @since version 1.0.0 + public: + /*! + @brief return a reference to the value pointed to by the iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - static basic_json object(std::initializer_list init = - std::initializer_list()) + reference operator*() const { - return basic_json(init, false, value_t::object); - } + assert(m_object != nullptr); - /*! - @brief construct an array with count copies of given value + switch (m_object->m_type) + { + case value_t::object: + { + assert(m_it.object_iterator != m_object->m_value.object->end()); + return m_it.object_iterator->second; + } - Constructs a JSON array value by creating @a cnt copies of a passed value. - In case @a cnt is `0`, an empty array is created. As postcondition, - `std::distance(begin(),end()) == cnt` holds. + case value_t::array: + { + assert(m_it.array_iterator != m_object->m_value.array->end()); + return *m_it.array_iterator; + } - @param[in] cnt the number of JSON copies of @a val to create - @param[in] val the JSON value to copy + case value_t::null: + JSON_THROW(invalid_iterator::create(214, "cannot get value")); - @complexity Linear in @a cnt. + default: + { + if (JSON_LIKELY(m_it.primitive_iterator.is_begin())) + { + return *m_object; + } - @liveexample{The following code shows examples for the @ref - basic_json(size_type\, const basic_json&) - constructor.,basic_json__size_type_basic_json} + JSON_THROW(invalid_iterator::create(214, "cannot get value")); + } + } + } - @since version 1.0.0 + /*! + @brief dereference the iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - basic_json(size_type cnt, const basic_json& val) - : m_type(value_t::array) + pointer operator->() const { - m_value.array = create(cnt, val); - assert_invariant(); - } - - /*! - @brief construct a JSON container given an iterator range - - Constructs the JSON value with the contents of the range `[first, last)`. - The semantics depends on the different types a JSON value can have: - - In case of primitive types (number, boolean, or string), @a first must - be `begin()` and @a last must be `end()`. In this case, the value is - copied. Otherwise, invalid_iterator.204 is thrown. - - In case of structured types (array, object), the constructor behaves as - similar versions for `std::vector`. - - In case of a null type, invalid_iterator.206 is thrown. - - @tparam InputIT an input iterator type (@ref iterator or @ref - const_iterator) - - @param[in] first begin of the range to copy from (included) - @param[in] last end of the range to copy from (excluded) - - @pre Iterators @a first and @a last must be initialized. **This - precondition is enforced with an assertion.** - - @pre Range `[first, last)` is valid. Usually, this precondition cannot be - checked efficiently. Only certain edge cases are detected; see the - description of the exceptions below. - - @throw invalid_iterator.201 if iterators @a first and @a last are not - compatible (i.e., do not belong to the same JSON value). In this case, - the range `[first, last)` is undefined. - @throw invalid_iterator.204 if iterators @a first and @a last belong to a - primitive type (number, boolean, or string), but @a first does not point - to the first element any more. In this case, the range `[first, last)` is - undefined. See example code below. - @throw invalid_iterator.206 if iterators @a first and @a last belong to a - null value. In this case, the range `[first, last)` is undefined. - - @complexity Linear in distance between @a first and @a last. - - @liveexample{The example below shows several ways to create JSON values by - specifying a subrange with iterators.,basic_json__InputIt_InputIt} - - @since version 1.0.0 - */ - template::value or - std::is_same::value, int>::type = 0> - basic_json(InputIT first, InputIT last) - { - assert(first.m_object != nullptr); - assert(last.m_object != nullptr); + assert(m_object != nullptr); - // make sure iterator fits the current value - if (first.m_object != last.m_object) + switch (m_object->m_type) { - JSON_THROW(invalid_iterator::create(201, "iterators are not compatible")); - } - - // copy type from first iterator - m_type = first.m_object->m_type; + case value_t::object: + { + assert(m_it.object_iterator != m_object->m_value.object->end()); + return &(m_it.object_iterator->second); + } - // check if iterator range is complete for primitive values - switch (m_type) - { - case value_t::boolean: - case value_t::number_float: - case value_t::number_integer: - case value_t::number_unsigned: - case value_t::string: + case value_t::array: { - if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end()) - { - JSON_THROW(invalid_iterator::create(204, "iterators out of range")); - } - break; + assert(m_it.array_iterator != m_object->m_value.array->end()); + return &*m_it.array_iterator; } default: { - break; + if (JSON_LIKELY(m_it.primitive_iterator.is_begin())) + { + return m_object; + } + + JSON_THROW(invalid_iterator::create(214, "cannot get value")); } } + } - switch (m_type) + /*! + @brief post-increment (it++) + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl operator++(int) + { + auto result = *this; + ++(*this); + return result; + } + + /*! + @brief pre-increment (++it) + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl& operator++() + { + assert(m_object != nullptr); + + switch (m_object->m_type) { - case value_t::number_integer: + case value_t::object: { - m_value.number_integer = first.m_object->m_value.number_integer; + std::advance(m_it.object_iterator, 1); break; } - case value_t::number_unsigned: + case value_t::array: { - m_value.number_unsigned = first.m_object->m_value.number_unsigned; + std::advance(m_it.array_iterator, 1); break; } - case value_t::number_float: + default: { - m_value.number_float = first.m_object->m_value.number_float; + ++m_it.primitive_iterator; break; } + } - case value_t::boolean: - { - m_value.boolean = first.m_object->m_value.boolean; - break; - } + return *this; + } - case value_t::string: - { - m_value = *first.m_object->m_value.string; - break; - } + /*! + @brief post-decrement (it--) + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl operator--(int) + { + auto result = *this; + --(*this); + return result; + } + + /*! + @brief pre-decrement (--it) + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl& operator--() + { + assert(m_object != nullptr); + switch (m_object->m_type) + { case value_t::object: { - m_value.object = create(first.m_it.object_iterator, - last.m_it.object_iterator); + std::advance(m_it.object_iterator, -1); break; } case value_t::array: { - m_value.array = create(first.m_it.array_iterator, - last.m_it.array_iterator); + std::advance(m_it.array_iterator, -1); break; } default: { - JSON_THROW(invalid_iterator::create(206, "cannot construct with iterators from " + - first.m_object->type_name())); + --m_it.primitive_iterator; + break; } } - assert_invariant(); + return *this; } - - /////////////////////////////////////// - // other constructors and destructor // - /////////////////////////////////////// - /*! - @brief copy constructor + @brief comparison: equal + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + bool operator==(const iter_impl& other) const + { + // if objects are not the same, the comparison is undefined + if (JSON_UNLIKELY(m_object != other.m_object)) + { + JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers")); + } - Creates a copy of a given JSON value. + assert(m_object != nullptr); - @param[in] other the JSON value to copy + switch (m_object->m_type) + { + case value_t::object: + return (m_it.object_iterator == other.m_it.object_iterator); - @complexity Linear in the size of @a other. + case value_t::array: + return (m_it.array_iterator == other.m_it.array_iterator); - @requirement This function helps `basic_json` satisfying the - [Container](http://en.cppreference.com/w/cpp/concept/Container) - requirements: - - The complexity is linear. - - As postcondition, it holds: `other == basic_json(other)`. + default: + return (m_it.primitive_iterator == other.m_it.primitive_iterator); + } + } - @liveexample{The following code shows an example for the copy - constructor.,basic_json__basic_json} + /*! + @brief comparison: not equal + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + bool operator!=(const iter_impl& other) const + { + return not operator==(other); + } - @since version 1.0.0 + /*! + @brief comparison: smaller + @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - basic_json(const basic_json& other) - : m_type(other.m_type) + bool operator<(const iter_impl& other) const { - // check of passed value is valid - other.assert_invariant(); + // if objects are not the same, the comparison is undefined + if (JSON_UNLIKELY(m_object != other.m_object)) + { + JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers")); + } - switch (m_type) + assert(m_object != nullptr); + + switch (m_object->m_type) { case value_t::object: - { - m_value = *other.m_value.object; - break; - } + JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators")); case value_t::array: - { - m_value = *other.m_value.array; - break; - } + return (m_it.array_iterator < other.m_it.array_iterator); - case value_t::string: - { - m_value = *other.m_value.string; - break; - } + default: + return (m_it.primitive_iterator < other.m_it.primitive_iterator); + } + } - case value_t::boolean: - { - m_value = other.m_value.boolean; - break; - } + /*! + @brief comparison: less than or equal + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + bool operator<=(const iter_impl& other) const + { + return not other.operator < (*this); + } - case value_t::number_integer: - { - m_value = other.m_value.number_integer; - break; - } + /*! + @brief comparison: greater than + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + bool operator>(const iter_impl& other) const + { + return not operator<=(other); + } - case value_t::number_unsigned: - { - m_value = other.m_value.number_unsigned; - break; - } + /*! + @brief comparison: greater than or equal + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + bool operator>=(const iter_impl& other) const + { + return not operator<(other); + } - case value_t::number_float: + /*! + @brief add to iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl& operator+=(difference_type i) + { + assert(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators")); + + case value_t::array: { - m_value = other.m_value.number_float; + std::advance(m_it.array_iterator, i); break; } default: { + m_it.primitive_iterator += i; break; } } - assert_invariant(); + return *this; } /*! - @brief move constructor - - Move constructor. Constructs a JSON value with the contents of the given - value @a other using move semantics. It "steals" the resources from @a - other and leaves it as JSON null value. - - @param[in,out] other value to move to this object - - @post @a other is a JSON null value - - @complexity Constant. - - @liveexample{The code below shows the move constructor explicitly called - via std::move.,basic_json__moveconstructor} - - @since version 1.0.0 + @brief subtract from iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - basic_json(basic_json&& other) noexcept - : m_type(std::move(other.m_type)), - m_value(std::move(other.m_value)) + iter_impl& operator-=(difference_type i) { - // check that passed value is valid - other.assert_invariant(); - - // invalidate payload - other.m_type = value_t::null; - other.m_value = {}; + return operator+=(-i); + } - assert_invariant(); + /*! + @brief add to iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl operator+(difference_type i) const + { + auto result = *this; + result += i; + return result; } /*! - @brief copy assignment + @brief addition of distance and iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + friend iter_impl operator+(difference_type i, const iter_impl& it) + { + auto result = it; + result += i; + return result; + } - Copy assignment operator. Copies a JSON value via the "copy and swap" - strategy: It is expressed in terms of the copy constructor, destructor, - and the swap() member function. - - @param[in] other value to copy from - - @complexity Linear. - - @requirement This function helps `basic_json` satisfying the - [Container](http://en.cppreference.com/w/cpp/concept/Container) - requirements: - - The complexity is linear. - - @liveexample{The code below shows and example for the copy assignment. It - creates a copy of value `a` which is then swapped with `b`. Finally\, the - copy of `a` (which is the null value after the swap) is - destroyed.,basic_json__copyassignment} - - @since version 1.0.0 + /*! + @brief subtract from iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - reference& operator=(basic_json other) noexcept_if( - std::is_nothrow_move_constructible::value and - std::is_nothrow_move_assignable::value and - std::is_nothrow_move_constructible::value and - std::is_nothrow_move_assignable::value - ) + iter_impl operator-(difference_type i) const { - // check that passed value is valid - other.assert_invariant(); - - using std::swap; - swap(m_type, other.m_type); - swap(m_value, other.m_value); - - assert_invariant(); - return *this; + auto result = *this; + result -= i; + return result; } /*! - @brief destructor + @brief return difference + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + difference_type operator-(const iter_impl& other) const + { + assert(m_object != nullptr); - Destroys the JSON value and frees all allocated memory. + switch (m_object->m_type) + { + case value_t::object: + JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators")); - @complexity Linear. + case value_t::array: + return m_it.array_iterator - other.m_it.array_iterator; - @requirement This function helps `basic_json` satisfying the - [Container](http://en.cppreference.com/w/cpp/concept/Container) - requirements: - - The complexity is linear. - - All stored elements are destroyed and all memory is freed. + default: + return m_it.primitive_iterator - other.m_it.primitive_iterator; + } + } - @since version 1.0.0 + /*! + @brief access to successor + @pre The iterator is initialized; i.e. `m_object != nullptr`. */ - ~basic_json() + reference operator[](difference_type n) const { - assert_invariant(); + assert(m_object != nullptr); - switch (m_type) + switch (m_object->m_type) { case value_t::object: - { - AllocatorType alloc; - alloc.destroy(m_value.object); - alloc.deallocate(m_value.object, 1); - break; - } + JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators")); case value_t::array: - { - AllocatorType alloc; - alloc.destroy(m_value.array); - alloc.deallocate(m_value.array, 1); - break; - } + return *std::next(m_it.array_iterator, n); - case value_t::string: - { - AllocatorType alloc; - alloc.destroy(m_value.string); - alloc.deallocate(m_value.string, 1); - break; - } + case value_t::null: + JSON_THROW(invalid_iterator::create(214, "cannot get value")); default: { - // all other types need no specific destructor - break; + if (JSON_LIKELY(m_it.primitive_iterator.get_value() == -n)) + { + return *m_object; + } + + JSON_THROW(invalid_iterator::create(214, "cannot get value")); } } } - /// @} + /*! + @brief return the key of an object iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + typename object_t::key_type key() const + { + assert(m_object != nullptr); - public: - /////////////////////// - // object inspection // - /////////////////////// + if (JSON_LIKELY(m_object->is_object())) + { + return m_it.object_iterator->first; + } - /// @name object inspection - /// Functions to inspect the type of a JSON value. - /// @{ + JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators")); + } /*! - @brief serialization - - Serialization function for JSON values. The function tries to mimic - Python's `json.dumps()` function, and currently supports its @a indent - parameter. + @brief return the value of an iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + reference value() const + { + return operator*(); + } - @param[in] indent If indent is nonnegative, then array elements and object - members will be pretty-printed with that indent level. An indent level of - `0` will only insert newlines. `-1` (the default) selects the most compact - representation. + private: + /// associated JSON instance + pointer m_object = nullptr; + /// the actual iterator of the associated instance + internal_iterator::type> m_it = {}; +}; - @return string containing the serialization of the JSON value +/// proxy class for the iterator_wrapper functions +template class iteration_proxy +{ + private: + /// helper class for iteration + class iteration_proxy_internal + { + private: + /// the iterator + IteratorType anchor; + /// an index for arrays (used to create key names) + std::size_t array_index = 0; - @complexity Linear. + public: + explicit iteration_proxy_internal(IteratorType it) noexcept : anchor(it) {} - @liveexample{The following example shows the effect of different @a indent - parameters to the result of the serialization.,dump} + /// dereference operator (needed for range-based for) + iteration_proxy_internal& operator*() + { + return *this; + } - @see https://docs.python.org/2/library/json.html#json.dump + /// increment operator (needed for range-based for) + iteration_proxy_internal& operator++() + { + ++anchor; + ++array_index; - @since version 1.0.0 - */ - string_t dump(const int indent = -1) const - { - std::stringstream ss; - serializer s(ss); + return *this; + } - if (indent >= 0) + /// inequality operator (needed for range-based for) + bool operator!=(const iteration_proxy_internal& o) const noexcept { - s.dump(*this, true, static_cast(indent)); + return anchor != o.anchor; } - else + + /// return key of the iterator + std::string key() const { - s.dump(*this, false, 0); - } + assert(anchor.m_object != nullptr); - return ss.str(); - } + switch (anchor.m_object->type()) + { + // use integer array index as key + case value_t::array: + return std::to_string(array_index); - /*! - @brief return the type of the JSON value (explicit) + // use key from the object + case value_t::object: + return anchor.key(); - Return the type of the JSON value as a value from the @ref value_t - enumeration. + // use an empty key for all primitive types + default: + return ""; + } + } - @return the type of the JSON value + /// return value of the iterator + typename IteratorType::reference value() const + { + return anchor.value(); + } + }; - @complexity Constant. + /// the container to iterate + typename IteratorType::reference container; - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. + public: + /// construct iteration proxy from a container + explicit iteration_proxy(typename IteratorType::reference cont) + : container(cont) {} - @liveexample{The following code exemplifies `type()` for all JSON - types.,type} + /// return iterator begin (needed for range-based for) + iteration_proxy_internal begin() noexcept + { + return iteration_proxy_internal(container.begin()); + } - @since version 1.0.0 - */ - constexpr value_t type() const noexcept + /// return iterator end (needed for range-based for) + iteration_proxy_internal end() noexcept { - return m_type; + return iteration_proxy_internal(container.end()); } +}; - /*! - @brief return whether type is primitive +/*! +@brief a template for a reverse iterator class - This function returns true iff the JSON type is primitive (string, number, - boolean, or null). +@tparam Base the base iterator type to reverse. Valid types are @ref +iterator (to create @ref reverse_iterator) and @ref const_iterator (to +create @ref const_reverse_iterator). - @return `true` if type is primitive (string, number, boolean, or null), - `false` otherwise. +@requirement The class satisfies the following concept requirements: +- +[BidirectionalIterator](http://en.cppreference.com/w/cpp/concept/BidirectionalIterator): + The iterator that can be moved can be moved in both directions (i.e. + incremented and decremented). +- [OutputIterator](http://en.cppreference.com/w/cpp/concept/OutputIterator): + It is possible to write to the pointed-to element (only if @a Base is + @ref iterator). - @complexity Constant. +@since version 1.0.0 +*/ +template +class json_reverse_iterator : public std::reverse_iterator +{ + public: + using difference_type = std::ptrdiff_t; + /// shortcut to the reverse iterator adapter + using base_iterator = std::reverse_iterator; + /// the reference type for the pointed-to element + using reference = typename Base::reference; - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. + /// create reverse iterator from iterator + json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept + : base_iterator(it) {} - @liveexample{The following code exemplifies `is_primitive()` for all JSON - types.,is_primitive} + /// create reverse iterator from base class + json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {} - @sa @ref is_structured() -- returns whether JSON value is structured - @sa @ref is_null() -- returns whether JSON value is `null` - @sa @ref is_string() -- returns whether JSON value is a string - @sa @ref is_boolean() -- returns whether JSON value is a boolean - @sa @ref is_number() -- returns whether JSON value is a number + /// post-increment (it++) + json_reverse_iterator operator++(int) + { + return static_cast(base_iterator::operator++(1)); + } - @since version 1.0.0 - */ - constexpr bool is_primitive() const noexcept + /// pre-increment (++it) + json_reverse_iterator& operator++() { - return is_null() or is_string() or is_boolean() or is_number(); + return static_cast(base_iterator::operator++()); } - /*! - @brief return whether type is structured + /// post-decrement (it--) + json_reverse_iterator operator--(int) + { + return static_cast(base_iterator::operator--(1)); + } - This function returns true iff the JSON type is structured (array or - object). + /// pre-decrement (--it) + json_reverse_iterator& operator--() + { + return static_cast(base_iterator::operator--()); + } - @return `true` if type is structured (array or object), `false` otherwise. + /// add to iterator + json_reverse_iterator& operator+=(difference_type i) + { + return static_cast(base_iterator::operator+=(i)); + } - @complexity Constant. + /// add to iterator + json_reverse_iterator operator+(difference_type i) const + { + return static_cast(base_iterator::operator+(i)); + } - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. + /// subtract from iterator + json_reverse_iterator operator-(difference_type i) const + { + return static_cast(base_iterator::operator-(i)); + } - @liveexample{The following code exemplifies `is_structured()` for all JSON - types.,is_structured} + /// return difference + difference_type operator-(const json_reverse_iterator& other) const + { + return base_iterator(*this) - base_iterator(other); + } - @sa @ref is_primitive() -- returns whether value is primitive - @sa @ref is_array() -- returns whether value is an array - @sa @ref is_object() -- returns whether value is an object + /// access to successor + reference operator[](difference_type n) const + { + return *(this->operator+(n)); + } - @since version 1.0.0 - */ - constexpr bool is_structured() const noexcept + /// return the key of an object iterator + auto key() const -> decltype(std::declval().key()) { - return is_array() or is_object(); + auto it = --this->base(); + return it.key(); } - /*! - @brief return whether value is null + /// return the value of an iterator + reference value() const + { + auto it = --this->base(); + return it.operator * (); + } +}; - This function returns true iff the JSON value is null. +///////////////////// +// output adapters // +///////////////////// - @return `true` if type is null, `false` otherwise. +/// abstract output adapter interface +template struct output_adapter_protocol +{ + virtual void write_character(CharType c) = 0; + virtual void write_characters(const CharType* s, std::size_t length) = 0; + virtual ~output_adapter_protocol() = default; +}; - @complexity Constant. +/// a type to simplify interfaces +template +using output_adapter_t = std::shared_ptr>; - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. +/// output adapter for byte vectors +template +class output_vector_adapter : public output_adapter_protocol +{ + public: + explicit output_vector_adapter(std::vector& vec) : v(vec) {} - @liveexample{The following code exemplifies `is_null()` for all JSON - types.,is_null} + void write_character(CharType c) override + { + v.push_back(c); + } - @since version 1.0.0 - */ - constexpr bool is_null() const noexcept + void write_characters(const CharType* s, std::size_t length) override { - return m_type == value_t::null; + std::copy(s, s + length, std::back_inserter(v)); } - /*! - @brief return whether value is a boolean + private: + std::vector& v; +}; - This function returns true iff the JSON value is a boolean. +/// output adapter for output streams +template +class output_stream_adapter : public output_adapter_protocol +{ + public: + explicit output_stream_adapter(std::basic_ostream& s) : stream(s) {} - @return `true` if type is boolean, `false` otherwise. + void write_character(CharType c) override + { + stream.put(c); + } - @complexity Constant. + void write_characters(const CharType* s, std::size_t length) override + { + stream.write(s, static_cast(length)); + } - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. + private: + std::basic_ostream& stream; +}; - @liveexample{The following code exemplifies `is_boolean()` for all JSON - types.,is_boolean} +/// output adapter for basic_string +template +class output_string_adapter : public output_adapter_protocol +{ + public: + explicit output_string_adapter(std::basic_string& s) : str(s) {} - @since version 1.0.0 - */ - constexpr bool is_boolean() const noexcept + void write_character(CharType c) override { - return m_type == value_t::boolean; + str.push_back(c); } - /*! - @brief return whether value is a number + void write_characters(const CharType* s, std::size_t length) override + { + str.append(s, length); + } - This function returns true iff the JSON value is a number. This includes - both integer and floating-point values. + private: + std::basic_string& str; +}; - @return `true` if type is number (regardless whether integer, unsigned - integer or floating-type), `false` otherwise. +template +class output_adapter +{ + public: + output_adapter(std::vector& vec) + : oa(std::make_shared>(vec)) {} - @complexity Constant. + output_adapter(std::basic_ostream& s) + : oa(std::make_shared>(s)) {} - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_number()` for all JSON - types.,is_number} - - @sa @ref is_number_integer() -- check if value is an integer or unsigned - integer number - @sa @ref is_number_unsigned() -- check if value is an unsigned integer - number - @sa @ref is_number_float() -- check if value is a floating-point number + output_adapter(std::basic_string& s) + : oa(std::make_shared>(s)) {} - @since version 1.0.0 - */ - constexpr bool is_number() const noexcept + operator output_adapter_t() { - return is_number_integer() or is_number_float(); + return oa; } - /*! - @brief return whether value is an integer number - - This function returns true iff the JSON value is an integer or unsigned - integer number. This excludes floating-point values. - - @return `true` if type is an integer or unsigned integer number, `false` - otherwise. - - @complexity Constant. + private: + output_adapter_t oa = nullptr; +}; - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. +////////////////////////////// +// binary reader and writer // +////////////////////////////// - @liveexample{The following code exemplifies `is_number_integer()` for all - JSON types.,is_number_integer} +/*! +@brief deserialization of CBOR and MessagePack values +*/ +template +class binary_reader +{ + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; - @sa @ref is_number() -- check if value is a number - @sa @ref is_number_unsigned() -- check if value is an unsigned integer - number - @sa @ref is_number_float() -- check if value is a floating-point number + public: + /*! + @brief create a binary reader - @since version 1.0.0 + @param[in] adapter input adapter to read from */ - constexpr bool is_number_integer() const noexcept + explicit binary_reader(input_adapter_t adapter) : ia(std::move(adapter)) { - return m_type == value_t::number_integer or m_type == value_t::number_unsigned; + assert(ia); } /*! - @brief return whether value is an unsigned integer number - - This function returns true iff the JSON value is an unsigned integer - number. This excludes floating-point and (signed) integer values. - - @return `true` if type is an unsigned integer number, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_number_unsigned()` for all - JSON types.,is_number_unsigned} + @brief create a JSON value from CBOR input - @sa @ref is_number() -- check if value is a number - @sa @ref is_number_integer() -- check if value is an integer or unsigned - integer number - @sa @ref is_number_float() -- check if value is a floating-point number + @param[in] strict whether to expect the input to be consumed completed + @return JSON value created from CBOR input - @since version 2.0.0 + @throw parse_error.110 if input ended unexpectedly or the end of file was + not reached when @a strict was set to true + @throw parse_error.112 if unsupported byte was read */ - constexpr bool is_number_unsigned() const noexcept + BasicJsonType parse_cbor(const bool strict) { - return m_type == value_t::number_unsigned; + const auto res = parse_cbor_internal(); + if (strict) + { + get(); + check_eof(true); + } + return res; } /*! - @brief return whether value is a floating-point number - - This function returns true iff the JSON value is a floating-point number. - This excludes integer and unsigned integer values. - - @return `true` if type is a floating-point number, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_number_float()` for all - JSON types.,is_number_float} + @brief create a JSON value from MessagePack input - @sa @ref is_number() -- check if value is number - @sa @ref is_number_integer() -- check if value is an integer number - @sa @ref is_number_unsigned() -- check if value is an unsigned integer - number + @param[in] strict whether to expect the input to be consumed completed + @return JSON value created from MessagePack input - @since version 1.0.0 + @throw parse_error.110 if input ended unexpectedly or the end of file was + not reached when @a strict was set to true + @throw parse_error.112 if unsupported byte was read */ - constexpr bool is_number_float() const noexcept + BasicJsonType parse_msgpack(const bool strict) { - return m_type == value_t::number_float; + const auto res = parse_msgpack_internal(); + if (strict) + { + get(); + check_eof(true); + } + return res; } /*! - @brief return whether value is an object - - This function returns true iff the JSON value is an object. - - @return `true` if type is object, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. + @brief determine system byte order - @liveexample{The following code exemplifies `is_object()` for all JSON - types.,is_object} + @return true if and only if system's byte order is little endian - @since version 1.0.0 + @note from http://stackoverflow.com/a/1001328/266378 */ - constexpr bool is_object() const noexcept + static constexpr bool little_endianess(int num = 1) noexcept { - return m_type == value_t::object; + return (*reinterpret_cast(&num) == 1); } + private: /*! - @brief return whether value is an array + @param[in] get_char whether a new character should be retrieved from the + input (true, default) or whether the last read + character should be considered instead + */ + BasicJsonType parse_cbor_internal(const bool get_char = true) + { + switch (get_char ? get() : current) + { + // EOF + case std::char_traits::eof(): + JSON_THROW(parse_error::create(110, chars_read, "unexpected end of input")); - This function returns true iff the JSON value is an array. + // Integer 0x00..0x17 (0..23) + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + case 0x08: + case 0x09: + case 0x0A: + case 0x0B: + case 0x0C: + case 0x0D: + case 0x0E: + case 0x0F: + case 0x10: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + return static_cast(current); - @return `true` if type is array, `false` otherwise. + case 0x18: // Unsigned integer (one-byte uint8_t follows) + return get_number(); - @complexity Constant. + case 0x19: // Unsigned integer (two-byte uint16_t follows) + return get_number(); - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. + case 0x1A: // Unsigned integer (four-byte uint32_t follows) + return get_number(); - @liveexample{The following code exemplifies `is_array()` for all JSON - types.,is_array} + case 0x1B: // Unsigned integer (eight-byte uint64_t follows) + return get_number(); - @since version 1.0.0 - */ - constexpr bool is_array() const noexcept - { - return m_type == value_t::array; - } + // Negative integer -1-0x00..-1-0x17 (-1..-24) + case 0x20: + case 0x21: + case 0x22: + case 0x23: + case 0x24: + case 0x25: + case 0x26: + case 0x27: + case 0x28: + case 0x29: + case 0x2A: + case 0x2B: + case 0x2C: + case 0x2D: + case 0x2E: + case 0x2F: + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + return static_cast(0x20 - 1 - current); - /*! - @brief return whether value is a string + case 0x38: // Negative integer (one-byte uint8_t follows) + { + // must be uint8_t ! + return static_cast(-1) - get_number(); + } - This function returns true iff the JSON value is a string. + case 0x39: // Negative integer -1-n (two-byte uint16_t follows) + { + return static_cast(-1) - get_number(); + } - @return `true` if type is string, `false` otherwise. + case 0x3A: // Negative integer -1-n (four-byte uint32_t follows) + { + return static_cast(-1) - get_number(); + } - @complexity Constant. + case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows) + { + return static_cast(-1) - + static_cast(get_number()); + } - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. + // UTF-8 string (0x00..0x17 bytes follow) + case 0x60: + case 0x61: + case 0x62: + case 0x63: + case 0x64: + case 0x65: + case 0x66: + case 0x67: + case 0x68: + case 0x69: + case 0x6A: + case 0x6B: + case 0x6C: + case 0x6D: + case 0x6E: + case 0x6F: + case 0x70: + case 0x71: + case 0x72: + case 0x73: + case 0x74: + case 0x75: + case 0x76: + case 0x77: + case 0x78: // UTF-8 string (one-byte uint8_t for n follows) + case 0x79: // UTF-8 string (two-byte uint16_t for n follow) + case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) + case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) + case 0x7F: // UTF-8 string (indefinite length) + { + return get_cbor_string(); + } - @liveexample{The following code exemplifies `is_string()` for all JSON - types.,is_string} + // array (0x00..0x17 data items follow) + case 0x80: + case 0x81: + case 0x82: + case 0x83: + case 0x84: + case 0x85: + case 0x86: + case 0x87: + case 0x88: + case 0x89: + case 0x8A: + case 0x8B: + case 0x8C: + case 0x8D: + case 0x8E: + case 0x8F: + case 0x90: + case 0x91: + case 0x92: + case 0x93: + case 0x94: + case 0x95: + case 0x96: + case 0x97: + { + return get_cbor_array(current & 0x1F); + } - @since version 1.0.0 - */ - constexpr bool is_string() const noexcept - { - return m_type == value_t::string; - } + case 0x98: // array (one-byte uint8_t for n follows) + { + return get_cbor_array(get_number()); + } - /*! - @brief return whether value is discarded + case 0x99: // array (two-byte uint16_t for n follow) + { + return get_cbor_array(get_number()); + } - This function returns true iff the JSON value was discarded during parsing - with a callback function (see @ref parser_callback_t). + case 0x9A: // array (four-byte uint32_t for n follow) + { + return get_cbor_array(get_number()); + } - @note This function will always be `false` for JSON values after parsing. - That is, discarded values can only occur during parsing, but will be - removed when inside a structured value or replaced by null in other cases. + case 0x9B: // array (eight-byte uint64_t for n follow) + { + return get_cbor_array(get_number()); + } - @return `true` if type is discarded, `false` otherwise. + case 0x9F: // array (indefinite length) + { + BasicJsonType result = value_t::array; + while (get() != 0xFF) + { + result.push_back(parse_cbor_internal(false)); + } + return result; + } - @complexity Constant. + // map (0x00..0x17 pairs of data items follow) + case 0xA0: + case 0xA1: + case 0xA2: + case 0xA3: + case 0xA4: + case 0xA5: + case 0xA6: + case 0xA7: + case 0xA8: + case 0xA9: + case 0xAA: + case 0xAB: + case 0xAC: + case 0xAD: + case 0xAE: + case 0xAF: + case 0xB0: + case 0xB1: + case 0xB2: + case 0xB3: + case 0xB4: + case 0xB5: + case 0xB6: + case 0xB7: + { + return get_cbor_object(current & 0x1F); + } - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. + case 0xB8: // map (one-byte uint8_t for n follows) + { + return get_cbor_object(get_number()); + } - @liveexample{The following code exemplifies `is_discarded()` for all JSON - types.,is_discarded} + case 0xB9: // map (two-byte uint16_t for n follow) + { + return get_cbor_object(get_number()); + } - @since version 1.0.0 - */ - constexpr bool is_discarded() const noexcept - { - return m_type == value_t::discarded; - } + case 0xBA: // map (four-byte uint32_t for n follow) + { + return get_cbor_object(get_number()); + } - /*! - @brief return the type of the JSON value (implicit) + case 0xBB: // map (eight-byte uint64_t for n follow) + { + return get_cbor_object(get_number()); + } - Implicitly return the type of the JSON value as a value from the @ref - value_t enumeration. + case 0xBF: // map (indefinite length) + { + BasicJsonType result = value_t::object; + while (get() != 0xFF) + { + auto key = get_cbor_string(); + result[key] = parse_cbor_internal(); + } + return result; + } - @return the type of the JSON value + case 0xF4: // false + { + return false; + } - @complexity Constant. + case 0xF5: // true + { + return true; + } - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. + case 0xF6: // null + { + return value_t::null; + } - @liveexample{The following code exemplifies the @ref value_t operator for - all JSON types.,operator__value_t} + case 0xF9: // Half-Precision Float (two-byte IEEE 754) + { + const int byte1 = get(); + check_eof(); + const int byte2 = get(); + check_eof(); - @since version 1.0.0 - */ - constexpr operator value_t() const noexcept - { - return m_type; - } + // code from RFC 7049, Appendix D, Figure 3: + // As half-precision floating-point numbers were only added + // to IEEE 754 in 2008, today's programming platforms often + // still only have limited support for them. It is very + // easy to include at least decoding support for them even + // without such support. An example of a small decoder for + // half-precision floating-point numbers in the C language + // is shown in Fig. 3. + const int half = (byte1 << 8) + byte2; + const int exp = (half >> 10) & 0x1F; + const int mant = half & 0x3FF; + double val; + if (exp == 0) + { + val = std::ldexp(mant, -24); + } + else if (exp != 31) + { + val = std::ldexp(mant + 1024, exp - 25); + } + else + { + val = (mant == 0) ? std::numeric_limits::infinity() + : std::numeric_limits::quiet_NaN(); + } + return (half & 0x8000) != 0 ? -val : val; + } - /// @} + case 0xFA: // Single-Precision Float (four-byte IEEE 754) + { + return get_number(); + } - private: - ////////////////// - // value access // - ////////////////// + case 0xFB: // Double-Precision Float (eight-byte IEEE 754) + { + return get_number(); + } - /// get a boolean (explicit) - boolean_t get_impl(boolean_t* /*unused*/) const - { - if (is_boolean()) - { - return m_value.boolean; + default: // anything else (0xFF is handled inside the other types) + { + std::stringstream ss; + ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << current; + JSON_THROW(parse_error::create(112, chars_read, "error reading CBOR; last byte: 0x" + ss.str())); + } } - - JSON_THROW(type_error::create(302, "type must be boolean, but is " + type_name())); } - /// get a pointer to the value (object) - object_t* get_impl_ptr(object_t* /*unused*/) noexcept + BasicJsonType parse_msgpack_internal() { - return is_object() ? m_value.object : nullptr; - } + switch (get()) + { + // EOF + case std::char_traits::eof(): + JSON_THROW(parse_error::create(110, chars_read, "unexpected end of input")); - /// get a pointer to the value (object) - constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept - { - return is_object() ? m_value.object : nullptr; - } + // positive fixint + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + case 0x08: + case 0x09: + case 0x0A: + case 0x0B: + case 0x0C: + case 0x0D: + case 0x0E: + case 0x0F: + case 0x10: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + case 0x19: + case 0x1A: + case 0x1B: + case 0x1C: + case 0x1D: + case 0x1E: + case 0x1F: + case 0x20: + case 0x21: + case 0x22: + case 0x23: + case 0x24: + case 0x25: + case 0x26: + case 0x27: + case 0x28: + case 0x29: + case 0x2A: + case 0x2B: + case 0x2C: + case 0x2D: + case 0x2E: + case 0x2F: + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + case 0x38: + case 0x39: + case 0x3A: + case 0x3B: + case 0x3C: + case 0x3D: + case 0x3E: + case 0x3F: + case 0x40: + case 0x41: + case 0x42: + case 0x43: + case 0x44: + case 0x45: + case 0x46: + case 0x47: + case 0x48: + case 0x49: + case 0x4A: + case 0x4B: + case 0x4C: + case 0x4D: + case 0x4E: + case 0x4F: + case 0x50: + case 0x51: + case 0x52: + case 0x53: + case 0x54: + case 0x55: + case 0x56: + case 0x57: + case 0x58: + case 0x59: + case 0x5A: + case 0x5B: + case 0x5C: + case 0x5D: + case 0x5E: + case 0x5F: + case 0x60: + case 0x61: + case 0x62: + case 0x63: + case 0x64: + case 0x65: + case 0x66: + case 0x67: + case 0x68: + case 0x69: + case 0x6A: + case 0x6B: + case 0x6C: + case 0x6D: + case 0x6E: + case 0x6F: + case 0x70: + case 0x71: + case 0x72: + case 0x73: + case 0x74: + case 0x75: + case 0x76: + case 0x77: + case 0x78: + case 0x79: + case 0x7A: + case 0x7B: + case 0x7C: + case 0x7D: + case 0x7E: + case 0x7F: + return static_cast(current); + + // fixmap + case 0x80: + case 0x81: + case 0x82: + case 0x83: + case 0x84: + case 0x85: + case 0x86: + case 0x87: + case 0x88: + case 0x89: + case 0x8A: + case 0x8B: + case 0x8C: + case 0x8D: + case 0x8E: + case 0x8F: + { + return get_msgpack_object(current & 0x0F); + } - /// get a pointer to the value (array) - array_t* get_impl_ptr(array_t* /*unused*/) noexcept - { - return is_array() ? m_value.array : nullptr; - } + // fixarray + case 0x90: + case 0x91: + case 0x92: + case 0x93: + case 0x94: + case 0x95: + case 0x96: + case 0x97: + case 0x98: + case 0x99: + case 0x9A: + case 0x9B: + case 0x9C: + case 0x9D: + case 0x9E: + case 0x9F: + { + return get_msgpack_array(current & 0x0F); + } + + // fixstr + case 0xA0: + case 0xA1: + case 0xA2: + case 0xA3: + case 0xA4: + case 0xA5: + case 0xA6: + case 0xA7: + case 0xA8: + case 0xA9: + case 0xAA: + case 0xAB: + case 0xAC: + case 0xAD: + case 0xAE: + case 0xAF: + case 0xB0: + case 0xB1: + case 0xB2: + case 0xB3: + case 0xB4: + case 0xB5: + case 0xB6: + case 0xB7: + case 0xB8: + case 0xB9: + case 0xBA: + case 0xBB: + case 0xBC: + case 0xBD: + case 0xBE: + case 0xBF: + return get_msgpack_string(); + + case 0xC0: // nil + return value_t::null; - /// get a pointer to the value (array) - constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept - { - return is_array() ? m_value.array : nullptr; - } + case 0xC2: // false + return false; - /// get a pointer to the value (string) - string_t* get_impl_ptr(string_t* /*unused*/) noexcept - { - return is_string() ? m_value.string : nullptr; - } + case 0xC3: // true + return true; - /// get a pointer to the value (string) - constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept - { - return is_string() ? m_value.string : nullptr; - } + case 0xCA: // float 32 + return get_number(); - /// get a pointer to the value (boolean) - boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept - { - return is_boolean() ? &m_value.boolean : nullptr; - } + case 0xCB: // float 64 + return get_number(); - /// get a pointer to the value (boolean) - constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept - { - return is_boolean() ? &m_value.boolean : nullptr; - } + case 0xCC: // uint 8 + return get_number(); - /// get a pointer to the value (integer number) - number_integer_t* get_impl_ptr(number_integer_t* /*unused*/) noexcept - { - return is_number_integer() ? &m_value.number_integer : nullptr; - } + case 0xCD: // uint 16 + return get_number(); - /// get a pointer to the value (integer number) - constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept - { - return is_number_integer() ? &m_value.number_integer : nullptr; - } + case 0xCE: // uint 32 + return get_number(); - /// get a pointer to the value (unsigned number) - number_unsigned_t* get_impl_ptr(number_unsigned_t* /*unused*/) noexcept - { - return is_number_unsigned() ? &m_value.number_unsigned : nullptr; - } + case 0xCF: // uint 64 + return get_number(); - /// get a pointer to the value (unsigned number) - constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept - { - return is_number_unsigned() ? &m_value.number_unsigned : nullptr; - } + case 0xD0: // int 8 + return get_number(); - /// get a pointer to the value (floating-point number) - number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept - { - return is_number_float() ? &m_value.number_float : nullptr; - } + case 0xD1: // int 16 + return get_number(); - /// get a pointer to the value (floating-point number) - constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept - { - return is_number_float() ? &m_value.number_float : nullptr; - } + case 0xD2: // int 32 + return get_number(); - /*! - @brief helper function to implement get_ref() + case 0xD3: // int 64 + return get_number(); - This funcion helps to implement get_ref() without code duplication for - const and non-const overloads + case 0xD9: // str 8 + case 0xDA: // str 16 + case 0xDB: // str 32 + return get_msgpack_string(); - @tparam ThisType will be deduced as `basic_json` or `const basic_json` + case 0xDC: // array 16 + { + return get_msgpack_array(get_number()); + } - @throw type_error.303 if ReferenceType does not match underlying value - type of the current JSON - */ - template - static ReferenceType get_ref_impl(ThisType& obj) - { - // helper type - using PointerType = typename std::add_pointer::type; + case 0xDD: // array 32 + { + return get_msgpack_array(get_number()); + } - // delegate the call to get_ptr<>() - auto ptr = obj.template get_ptr(); + case 0xDE: // map 16 + { + return get_msgpack_object(get_number()); + } - if (ptr != nullptr) - { - return *ptr; - } + case 0xDF: // map 32 + { + return get_msgpack_object(get_number()); + } - JSON_THROW(type_error::create(303, "incompatible ReferenceType for get_ref, actual type is " + obj.type_name())); - } + // positive fixint + case 0xE0: + case 0xE1: + case 0xE2: + case 0xE3: + case 0xE4: + case 0xE5: + case 0xE6: + case 0xE7: + case 0xE8: + case 0xE9: + case 0xEA: + case 0xEB: + case 0xEC: + case 0xED: + case 0xEE: + case 0xEF: + case 0xF0: + case 0xF1: + case 0xF2: + case 0xF3: + case 0xF4: + case 0xF5: + case 0xF6: + case 0xF7: + case 0xF8: + case 0xF9: + case 0xFA: + case 0xFB: + case 0xFC: + case 0xFD: + case 0xFE: + case 0xFF: + return static_cast(current); - public: - /// @name value access - /// Direct access to the stored value of a JSON value. - /// @{ + default: // anything else + { + std::stringstream ss; + ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << current; + JSON_THROW(parse_error::create(112, chars_read, + "error reading MessagePack; last byte: 0x" + ss.str())); + } + } + } /*! - @brief get special-case overload + @brief get next character from the input - This overloads avoids a lot of template boilerplate, it can be seen as the - identity method + This function provides the interface to the used input adapter. It does + not throw in case the input reached EOF, but returns a -'ve valued + `std::char_traits::eof()` in that case. - @tparam BasicJsonType == @ref basic_json + @return character read from the input + */ + int get() + { + ++chars_read; + return (current = ia->get_character()); + } - @return a copy of *this + /* + @brief read a number from the input - @complexity Constant. + @tparam NumberType the type of the number - @since version 2.1.0 + @return number of type @a NumberType + + @note This function needs to respect the system's endianess, because + bytes in CBOR and MessagePack are stored in network order (big + endian) and therefore need reordering on little endian systems. + + @throw parse_error.110 if input has less than `sizeof(NumberType)` bytes */ - template < - typename BasicJsonType, - detail::enable_if_t::type, - basic_json_t>::value, - int> = 0 > - basic_json get() const + template NumberType get_number() { - return *this; + // step 1: read input into array with system's byte order + std::array vec; + for (std::size_t i = 0; i < sizeof(NumberType); ++i) + { + get(); + check_eof(); + + // reverse byte order prior to conversion if necessary + if (is_little_endian) + { + vec[sizeof(NumberType) - i - 1] = static_cast(current); + } + else + { + vec[i] = static_cast(current); // LCOV_EXCL_LINE + } + } + + // step 2: convert array into number of type T and return + NumberType result; + std::memcpy(&result, vec.data(), sizeof(NumberType)); + return result; } /*! - @brief get a value (explicit) + @brief create a string by reading characters from the input - Explicit type conversion between the JSON value and a compatible value - which is [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible) - and [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible). - The value is converted by calling the @ref json_serializer - `from_json()` method. + @param[in] len number of bytes to read - The function is equivalent to executing - @code {.cpp} - ValueType ret; - JSONSerializer::from_json(*this, ret); - return ret; - @endcode + @note We can not reserve @a len bytes for the result, because @a len + may be too large. Usually, @ref check_eof() detects the end of + the input before we run out of string memory. - This overloads is chosen if: - - @a ValueType is not @ref basic_json, - - @ref json_serializer has a `from_json()` method of the form - `void from_json(const @ref basic_json&, ValueType&)`, and - - @ref json_serializer does not have a `from_json()` method of - the form `ValueType from_json(const @ref basic_json&)` + @return string created by reading @a len bytes - @tparam ValueTypeCV the provided value type - @tparam ValueType the returned value type + @throw parse_error.110 if input has less than @a len bytes + */ + template + std::string get_string(const NumberType len) + { + std::string result; + std::generate_n(std::back_inserter(result), len, [this]() + { + get(); + check_eof(); + return static_cast(current); + }); + return result; + } - @return copy of the JSON value, converted to @a ValueType + /*! + @brief reads a CBOR string - @throw what @ref json_serializer `from_json()` method throws + This function first reads starting bytes to determine the expected + string length and then copies this number of bytes into a string. + Additionally, CBOR's strings with indefinite lengths are supported. - @liveexample{The example below shows several conversions from JSON values - to other types. There a few things to note: (1) Floating-point numbers can - be converted to integers\, (2) A JSON array can be converted to a standard - `std::vector`\, (3) A JSON object can be converted to C++ - associative containers such as `std::unordered_map`.,get__ValueType_const} + @return string - @since version 2.1.0 + @throw parse_error.110 if input ended + @throw parse_error.113 if an unexpected byte is read */ - template < - typename ValueTypeCV, - typename ValueType = detail::uncvref_t, - detail::enable_if_t < - not std::is_same::value and - detail::has_from_json::value and - not detail::has_non_default_from_json::value, - int > = 0 > - ValueType get() const noexcept_if(noexcept_if( - JSONSerializer::from_json(std::declval(), std::declval()))) + std::string get_cbor_string() { - // we cannot static_assert on ValueTypeCV being non-const, because - // there is support for get(), which is why we - // still need the uncvref - static_assert(not std::is_reference::value, - "get() cannot be used with reference types, you might want to use get_ref()"); - static_assert(std::is_default_constructible::value, - "types must be DefaultConstructible when used with get()"); - - ValueType ret; - JSONSerializer::from_json(*this, ret); - return ret; - } + check_eof(); - /*! - @brief get a value (explicit); special case + switch (current) + { + // UTF-8 string (0x00..0x17 bytes follow) + case 0x60: + case 0x61: + case 0x62: + case 0x63: + case 0x64: + case 0x65: + case 0x66: + case 0x67: + case 0x68: + case 0x69: + case 0x6A: + case 0x6B: + case 0x6C: + case 0x6D: + case 0x6E: + case 0x6F: + case 0x70: + case 0x71: + case 0x72: + case 0x73: + case 0x74: + case 0x75: + case 0x76: + case 0x77: + { + return get_string(current & 0x1F); + } - Explicit type conversion between the JSON value and a compatible value - which is **not** [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible) - and **not** [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible). - The value is converted by calling the @ref json_serializer - `from_json()` method. + case 0x78: // UTF-8 string (one-byte uint8_t for n follows) + { + return get_string(get_number()); + } - The function is equivalent to executing - @code {.cpp} - return JSONSerializer::from_json(*this); - @endcode + case 0x79: // UTF-8 string (two-byte uint16_t for n follow) + { + return get_string(get_number()); + } - This overloads is chosen if: - - @a ValueType is not @ref basic_json and - - @ref json_serializer has a `from_json()` method of the form - `ValueType from_json(const @ref basic_json&)` + case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) + { + return get_string(get_number()); + } - @note If @ref json_serializer has both overloads of - `from_json()`, this one is chosen. + case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) + { + return get_string(get_number()); + } - @tparam ValueTypeCV the provided value type - @tparam ValueType the returned value type + case 0x7F: // UTF-8 string (indefinite length) + { + std::string result; + while (get() != 0xFF) + { + check_eof(); + result.push_back(static_cast(current)); + } + return result; + } - @return copy of the JSON value, converted to @a ValueType + default: + { + std::stringstream ss; + ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << current; + JSON_THROW(parse_error::create(113, chars_read, "expected a CBOR string; last byte: 0x" + ss.str())); + } + } + } - @throw what @ref json_serializer `from_json()` method throws + template + BasicJsonType get_cbor_array(const NumberType len) + { + BasicJsonType result = value_t::array; + std::generate_n(std::back_inserter(*result.m_value.array), len, [this]() + { + return parse_cbor_internal(); + }); + return result; + } - @since version 2.1.0 - */ - template < - typename ValueTypeCV, - typename ValueType = detail::uncvref_t, - detail::enable_if_t::value and - detail::has_non_default_from_json::value, int> = 0 > - ValueType get() const noexcept_if(noexcept_if( - JSONSerializer::from_json(std::declval()))) + template + BasicJsonType get_cbor_object(const NumberType len) { - static_assert(not std::is_reference::value, - "get() cannot be used with reference types, you might want to use get_ref()"); - return JSONSerializer::from_json(*this); + BasicJsonType result = value_t::object; + std::generate_n(std::inserter(*result.m_value.object, + result.m_value.object->end()), + len, [this]() + { + get(); + auto key = get_cbor_string(); + auto val = parse_cbor_internal(); + return std::make_pair(std::move(key), std::move(val)); + }); + return result; } /*! - @brief get a pointer value (explicit) + @brief reads a MessagePack string - Explicit pointer access to the internally stored JSON value. No copies are - made. + This function first reads starting bytes to determine the expected + string length and then copies this number of bytes into a string. - @warning The pointer becomes invalid if the underlying JSON object - changes. + @return string - @tparam PointerType pointer type; must be a pointer to @ref array_t, @ref - object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, - @ref number_unsigned_t, or @ref number_float_t. + @throw parse_error.110 if input ended + @throw parse_error.113 if an unexpected byte is read + */ + std::string get_msgpack_string() + { + check_eof(); - @return pointer to the internally stored JSON value if the requested - pointer type @a PointerType fits to the JSON value; `nullptr` otherwise + switch (current) + { + // fixstr + case 0xA0: + case 0xA1: + case 0xA2: + case 0xA3: + case 0xA4: + case 0xA5: + case 0xA6: + case 0xA7: + case 0xA8: + case 0xA9: + case 0xAA: + case 0xAB: + case 0xAC: + case 0xAD: + case 0xAE: + case 0xAF: + case 0xB0: + case 0xB1: + case 0xB2: + case 0xB3: + case 0xB4: + case 0xB5: + case 0xB6: + case 0xB7: + case 0xB8: + case 0xB9: + case 0xBA: + case 0xBB: + case 0xBC: + case 0xBD: + case 0xBE: + case 0xBF: + { + return get_string(current & 0x1F); + } - @complexity Constant. + case 0xD9: // str 8 + { + return get_string(get_number()); + } - @liveexample{The example below shows how pointers to internal values of a - JSON value can be requested. Note that no type conversions are made and a - `nullptr` is returned if the value and the requested pointer type does not - match.,get__PointerType} + case 0xDA: // str 16 + { + return get_string(get_number()); + } - @sa @ref get_ptr() for explicit pointer-member access + case 0xDB: // str 32 + { + return get_string(get_number()); + } - @since version 1.0.0 - */ - template::value, int>::type = 0> - PointerType get() noexcept + default: + { + std::stringstream ss; + ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << current; + JSON_THROW(parse_error::create(113, chars_read, + "expected a MessagePack string; last byte: 0x" + ss.str())); + } + } + } + + template + BasicJsonType get_msgpack_array(const NumberType len) { - // delegate the call to get_ptr - return get_ptr(); + BasicJsonType result = value_t::array; + std::generate_n(std::back_inserter(*result.m_value.array), len, [this]() + { + return parse_msgpack_internal(); + }); + return result; } - /*! - @brief get a pointer value (explicit) - @copydoc get() - */ - template::value, int>::type = 0> - constexpr const PointerType get() const noexcept + template + BasicJsonType get_msgpack_object(const NumberType len) { - // delegate the call to get_ptr - return get_ptr(); + BasicJsonType result = value_t::object; + std::generate_n(std::inserter(*result.m_value.object, + result.m_value.object->end()), + len, [this]() + { + get(); + auto key = get_msgpack_string(); + auto val = parse_msgpack_internal(); + return std::make_pair(std::move(key), std::move(val)); + }); + return result; } /*! - @brief get a pointer value (implicit) - - Implicit pointer access to the internally stored JSON value. No copies are - made. + @brief check if input ended + @throw parse_error.110 if input ended + */ + void check_eof(const bool expect_eof = false) const + { + if (expect_eof) + { + if (JSON_UNLIKELY(current != std::char_traits::eof())) + { + JSON_THROW(parse_error::create(110, chars_read, "expected end of input")); + } + } + else + { + if (JSON_UNLIKELY(current == std::char_traits::eof())) + { + JSON_THROW(parse_error::create(110, chars_read, "unexpected end of input")); + } + } + } - @warning Writing data to the pointee of the result yields an undefined - state. + private: + /// input adapter + input_adapter_t ia = nullptr; - @tparam PointerType pointer type; must be a pointer to @ref array_t, @ref - object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, - @ref number_unsigned_t, or @ref number_float_t. Enforced by a static - assertion. + /// the current character + int current = std::char_traits::eof(); - @return pointer to the internally stored JSON value if the requested - pointer type @a PointerType fits to the JSON value; `nullptr` otherwise + /// the number of characters read + std::size_t chars_read = 0; - @complexity Constant. + /// whether we can assume little endianess + const bool is_little_endian = little_endianess(); +}; - @liveexample{The example below shows how pointers to internal values of a - JSON value can be requested. Note that no type conversions are made and a - `nullptr` is returned if the value and the requested pointer type does not - match.,get_ptr} +/*! +@brief serialization to CBOR and MessagePack values +*/ +template +class binary_writer +{ + public: + /*! + @brief create a binary writer - @since version 1.0.0 + @param[in] adapter output adapter to write to */ - template::value, int>::type = 0> - PointerType get_ptr() noexcept + explicit binary_writer(output_adapter_t adapter) : oa(adapter) { - // get the type of the PointerType (remove pointer and const) - using pointee_t = typename std::remove_const::type>::type>::type; - // make sure the type matches the allowed types - static_assert( - std::is_same::value - or std::is_same::value - or std::is_same::value - or std::is_same::value - or std::is_same::value - or std::is_same::value - or std::is_same::value - , "incompatible pointer type"); - - // delegate the call to get_impl_ptr<>() - return get_impl_ptr(static_cast(nullptr)); + assert(oa); } /*! - @brief get a pointer value (implicit) - @copydoc get_ptr() + @brief[in] j JSON value to serialize */ - template::value and - std::is_const::type>::value, int>::type = 0> - constexpr const PointerType get_ptr() const noexcept + void write_cbor(const BasicJsonType& j) { - // get the type of the PointerType (remove pointer and const) - using pointee_t = typename std::remove_const::type>::type>::type; - // make sure the type matches the allowed types - static_assert( - std::is_same::value - or std::is_same::value - or std::is_same::value - or std::is_same::value - or std::is_same::value - or std::is_same::value - or std::is_same::value - , "incompatible pointer type"); + switch (j.type()) + { + case value_t::null: + { + oa->write_character(static_cast(0xF6)); + break; + } - // delegate the call to get_impl_ptr<>() const - return get_impl_ptr(static_cast(nullptr)); - } + case value_t::boolean: + { + oa->write_character(j.m_value.boolean + ? static_cast(0xF5) + : static_cast(0xF4)); + break; + } - /*! - @brief get a reference value (implicit) + case value_t::number_integer: + { + if (j.m_value.number_integer >= 0) + { + // CBOR does not differentiate between positive signed + // integers and unsigned integers. Therefore, we used the + // code from the value_t::number_unsigned case here. + if (j.m_value.number_integer <= 0x17) + { + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer <= (std::numeric_limits::max)()) + { + oa->write_character(static_cast(0x18)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer <= (std::numeric_limits::max)()) + { + oa->write_character(static_cast(0x19)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer <= (std::numeric_limits::max)()) + { + oa->write_character(static_cast(0x1A)); + write_number(static_cast(j.m_value.number_integer)); + } + else + { + oa->write_character(static_cast(0x1B)); + write_number(static_cast(j.m_value.number_integer)); + } + } + else + { + // The conversions below encode the sign in the first + // byte, and the value is converted to a positive number. + const auto positive_number = -1 - j.m_value.number_integer; + if (j.m_value.number_integer >= -24) + { + write_number(static_cast(0x20 + positive_number)); + } + else if (positive_number <= (std::numeric_limits::max)()) + { + oa->write_character(static_cast(0x38)); + write_number(static_cast(positive_number)); + } + else if (positive_number <= (std::numeric_limits::max)()) + { + oa->write_character(static_cast(0x39)); + write_number(static_cast(positive_number)); + } + else if (positive_number <= (std::numeric_limits::max)()) + { + oa->write_character(static_cast(0x3A)); + write_number(static_cast(positive_number)); + } + else + { + oa->write_character(static_cast(0x3B)); + write_number(static_cast(positive_number)); + } + } + break; + } - Implicit reference access to the internally stored JSON value. No copies - are made. + case value_t::number_unsigned: + { + if (j.m_value.number_unsigned <= 0x17) + { + write_number(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + oa->write_character(static_cast(0x18)); + write_number(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + oa->write_character(static_cast(0x19)); + write_number(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + oa->write_character(static_cast(0x1A)); + write_number(static_cast(j.m_value.number_unsigned)); + } + else + { + oa->write_character(static_cast(0x1B)); + write_number(static_cast(j.m_value.number_unsigned)); + } + break; + } - @warning Writing data to the referee of the result yields an undefined - state. + case value_t::number_float: // Double-Precision Float + { + oa->write_character(static_cast(0xFB)); + write_number(j.m_value.number_float); + break; + } - @tparam ReferenceType reference type; must be a reference to @ref array_t, - @ref object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, or - @ref number_float_t. Enforced by static assertion. + case value_t::string: + { + // step 1: write control byte and the string length + const auto N = j.m_value.string->size(); + if (N <= 0x17) + { + write_number(static_cast(0x60 + N)); + } + else if (N <= 0xFF) + { + oa->write_character(static_cast(0x78)); + write_number(static_cast(N)); + } + else if (N <= 0xFFFF) + { + oa->write_character(static_cast(0x79)); + write_number(static_cast(N)); + } + else if (N <= 0xFFFFFFFF) + { + oa->write_character(static_cast(0x7A)); + write_number(static_cast(N)); + } + // LCOV_EXCL_START + else if (N <= 0xFFFFFFFFFFFFFFFF) + { + oa->write_character(static_cast(0x7B)); + write_number(static_cast(N)); + } + // LCOV_EXCL_STOP - @return reference to the internally stored JSON value if the requested - reference type @a ReferenceType fits to the JSON value; throws - type_error.303 otherwise + // step 2: write the string + oa->write_characters( + reinterpret_cast(j.m_value.string->c_str()), + j.m_value.string->size()); + break; + } - @throw type_error.303 in case passed type @a ReferenceType is incompatible - with the stored JSON value; see example below + case value_t::array: + { + // step 1: write control byte and the array size + const auto N = j.m_value.array->size(); + if (N <= 0x17) + { + write_number(static_cast(0x80 + N)); + } + else if (N <= 0xFF) + { + oa->write_character(static_cast(0x98)); + write_number(static_cast(N)); + } + else if (N <= 0xFFFF) + { + oa->write_character(static_cast(0x99)); + write_number(static_cast(N)); + } + else if (N <= 0xFFFFFFFF) + { + oa->write_character(static_cast(0x9A)); + write_number(static_cast(N)); + } + // LCOV_EXCL_START + else if (N <= 0xFFFFFFFFFFFFFFFF) + { + oa->write_character(static_cast(0x9B)); + write_number(static_cast(N)); + } + // LCOV_EXCL_STOP - @complexity Constant. + // step 2: write each element + for (const auto& el : *j.m_value.array) + { + write_cbor(el); + } + break; + } - @liveexample{The example shows several calls to `get_ref()`.,get_ref} + case value_t::object: + { + // step 1: write control byte and the object size + const auto N = j.m_value.object->size(); + if (N <= 0x17) + { + write_number(static_cast(0xA0 + N)); + } + else if (N <= 0xFF) + { + oa->write_character(static_cast(0xB8)); + write_number(static_cast(N)); + } + else if (N <= 0xFFFF) + { + oa->write_character(static_cast(0xB9)); + write_number(static_cast(N)); + } + else if (N <= 0xFFFFFFFF) + { + oa->write_character(static_cast(0xBA)); + write_number(static_cast(N)); + } + // LCOV_EXCL_START + else if (N <= 0xFFFFFFFFFFFFFFFF) + { + oa->write_character(static_cast(0xBB)); + write_number(static_cast(N)); + } + // LCOV_EXCL_STOP - @since version 1.1.0 - */ - template::value, int>::type = 0> - ReferenceType get_ref() - { - // delegate call to get_ref_impl - return get_ref_impl(*this); - } + // step 2: write each element + for (const auto& el : *j.m_value.object) + { + write_cbor(el.first); + write_cbor(el.second); + } + break; + } - /*! - @brief get a reference value (implicit) - @copydoc get_ref() - */ - template::value and - std::is_const::type>::value, int>::type = 0> - ReferenceType get_ref() const - { - // delegate call to get_ref_impl - return get_ref_impl(*this); + default: + break; + } } /*! - @brief get a value (implicit) - - Implicit type conversion between the JSON value and a compatible value. - The call is realized by calling @ref get() const. - - @tparam ValueType non-pointer type compatible to the JSON value, for - instance `int` for JSON integer numbers, `bool` for JSON booleans, or - `std::vector` types for JSON arrays. The character type of @ref string_t - as well as an initializer list of this type is excluded to avoid - ambiguities as these types implicitly convert to `std::string`. - - @return copy of the JSON value, converted to type @a ValueType - - @throw type_error.302 in case passed type @a ValueType is incompatible - to the JSON value type (e.g., the JSON value is of type boolean, but a - string is requested); see example below - - @complexity Linear in the size of the JSON value. - - @liveexample{The example below shows several conversions from JSON values - to other types. There a few things to note: (1) Floating-point numbers can - be converted to integers\, (2) A JSON array can be converted to a standard - `std::vector`\, (3) A JSON object can be converted to C++ - associative containers such as `std::unordered_map`.,operator__ValueType} - - @since version 1.0.0 + @brief[in] j JSON value to serialize */ - template < typename ValueType, typename std::enable_if < - not std::is_pointer::value and - not std::is_same::value -#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015 - and not std::is_same>::value -#endif - , int >::type = 0 > - operator ValueType() const + void write_msgpack(const BasicJsonType& j) { - // delegate the call to get<>() const - return get(); - } - - /// @} - - - //////////////////// - // element access // - //////////////////// + switch (j.type()) + { + case value_t::null: // nil + { + oa->write_character(static_cast(0xC0)); + break; + } - /// @name element access - /// Access to the JSON value. - /// @{ + case value_t::boolean: // true and false + { + oa->write_character(j.m_value.boolean + ? static_cast(0xC3) + : static_cast(0xC2)); + break; + } - /*! - @brief access specified array element with bounds checking - - Returns a reference to the element at specified location @a idx, with - bounds checking. - - @param[in] idx index of the element to access - - @return reference to the element at index @a idx + case value_t::number_integer: + { + if (j.m_value.number_integer >= 0) + { + // MessagePack does not differentiate between positive + // signed integers and unsigned integers. Therefore, we used + // the code from the value_t::number_unsigned case here. + if (j.m_value.number_unsigned < 128) + { + // positive fixnum + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 8 + oa->write_character(static_cast(0xCC)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 16 + oa->write_character(static_cast(0xCD)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 32 + oa->write_character(static_cast(0xCE)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 64 + oa->write_character(static_cast(0xCF)); + write_number(static_cast(j.m_value.number_integer)); + } + } + else + { + if (j.m_value.number_integer >= -32) + { + // negative fixnum + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= (std::numeric_limits::min)() and + j.m_value.number_integer <= (std::numeric_limits::max)()) + { + // int 8 + oa->write_character(static_cast(0xD0)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= (std::numeric_limits::min)() and + j.m_value.number_integer <= (std::numeric_limits::max)()) + { + // int 16 + oa->write_character(static_cast(0xD1)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= (std::numeric_limits::min)() and + j.m_value.number_integer <= (std::numeric_limits::max)()) + { + // int 32 + oa->write_character(static_cast(0xD2)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= (std::numeric_limits::min)() and + j.m_value.number_integer <= (std::numeric_limits::max)()) + { + // int 64 + oa->write_character(static_cast(0xD3)); + write_number(static_cast(j.m_value.number_integer)); + } + } + break; + } - @throw type_error.304 if the JSON value is not an array; in this case, - calling `at` with an index makes no sense. See example below. - @throw out_of_range.401 if the index @a idx is out of range of the array; - that is, `idx >= size()`. See example below. + case value_t::number_unsigned: + { + if (j.m_value.number_unsigned < 128) + { + // positive fixnum + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 8 + oa->write_character(static_cast(0xCC)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 16 + oa->write_character(static_cast(0xCD)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 32 + oa->write_character(static_cast(0xCE)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 64 + oa->write_character(static_cast(0xCF)); + write_number(static_cast(j.m_value.number_integer)); + } + break; + } - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. + case value_t::number_float: // float 64 + { + oa->write_character(static_cast(0xCB)); + write_number(j.m_value.number_float); + break; + } - @complexity Constant. + case value_t::string: + { + // step 1: write control byte and the string length + const auto N = j.m_value.string->size(); + if (N <= 31) + { + // fixstr + write_number(static_cast(0xA0 | N)); + } + else if (N <= 255) + { + // str 8 + oa->write_character(static_cast(0xD9)); + write_number(static_cast(N)); + } + else if (N <= 65535) + { + // str 16 + oa->write_character(static_cast(0xDA)); + write_number(static_cast(N)); + } + else if (N <= 4294967295) + { + // str 32 + oa->write_character(static_cast(0xDB)); + write_number(static_cast(N)); + } - @since version 1.0.0 + // step 2: write the string + oa->write_characters( + reinterpret_cast(j.m_value.string->c_str()), + j.m_value.string->size()); + break; + } - @liveexample{The example below shows how array elements can be read and - written using `at()`. It also demonstrates the different exceptions that - can be thrown.,at__size_type} - */ - reference at(size_type idx) - { - // at only works for arrays - if (is_array()) - { - JSON_TRY + case value_t::array: { - return m_value.array->at(idx); + // step 1: write control byte and the array size + const auto N = j.m_value.array->size(); + if (N <= 15) + { + // fixarray + write_number(static_cast(0x90 | N)); + } + else if (N <= 0xFFFF) + { + // array 16 + oa->write_character(static_cast(0xDC)); + write_number(static_cast(N)); + } + else if (N <= 0xFFFFFFFF) + { + // array 32 + oa->write_character(static_cast(0xDD)); + write_number(static_cast(N)); + } + + // step 2: write each element + for (const auto& el : *j.m_value.array) + { + write_msgpack(el); + } + break; } - JSON_CATCH (std::out_of_range&) + + case value_t::object: { - // create better exception explanation - JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range")); + // step 1: write control byte and the object size + const auto N = j.m_value.object->size(); + if (N <= 15) + { + // fixmap + write_number(static_cast(0x80 | (N & 0xF))); + } + else if (N <= 65535) + { + // map 16 + oa->write_character(static_cast(0xDE)); + write_number(static_cast(N)); + } + else if (N <= 4294967295) + { + // map 32 + oa->write_character(static_cast(0xDF)); + write_number(static_cast(N)); + } + + // step 2: write each element + for (const auto& el : *j.m_value.object) + { + write_msgpack(el.first); + write_msgpack(el.second); + } + break; } + + default: + break; } - else + } + + private: + /* + @brief write a number to output input + + @param[in] n number of type @a NumberType + @tparam NumberType the type of the number + + @note This function needs to respect the system's endianess, because bytes + in CBOR and MessagePack are stored in network order (big endian) and + therefore need reordering on little endian systems. + */ + template void write_number(NumberType n) + { + // step 1: write number to array of length NumberType + std::array vec; + std::memcpy(vec.data(), &n, sizeof(NumberType)); + + // step 2: write array to output (with possible reordering) + if (is_little_endian) { - JSON_THROW(type_error::create(304, "cannot use at() with " + type_name())); + // reverse byte order prior to conversion if necessary + std::reverse(vec.begin(), vec.end()); } + + oa->write_characters(vec.data(), sizeof(NumberType)); } - /*! - @brief access specified array element with bounds checking + private: + /// whether we can assume little endianess + const bool is_little_endian = binary_reader::little_endianess(); - Returns a const reference to the element at specified location @a idx, - with bounds checking. + /// the output + output_adapter_t oa = nullptr; +}; - @param[in] idx index of the element to access +/////////////////// +// serialization // +/////////////////// - @return const reference to the element at index @a idx +template +class serializer +{ + using string_t = typename BasicJsonType::string_t; + using number_float_t = typename BasicJsonType::number_float_t; + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + public: + /*! + @param[in] s output stream to serialize to + @param[in] ichar indentation character to use + */ + serializer(output_adapter_t s, const char ichar) + : o(std::move(s)), loc(std::localeconv()), + thousands_sep(loc->thousands_sep == nullptr ? '\0' : * (loc->thousands_sep)), + decimal_point(loc->decimal_point == nullptr ? '\0' : * (loc->decimal_point)), + indent_char(ichar), indent_string(512, indent_char) {} - @throw type_error.304 if the JSON value is not an array; in this case, - calling `at` with an index makes no sense. See example below. - @throw out_of_range.401 if the index @a idx is out of range of the array; - that is, `idx >= size()`. See example below. + // delete because of pointer members + serializer(const serializer&) = delete; + serializer& operator=(const serializer&) = delete; - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. + /*! + @brief internal implementation of the serialization function - @complexity Constant. + This function is called by the public member function dump and organizes + the serialization internally. The indentation level is propagated as + additional parameter. In case of arrays and objects, the function is + called recursively. - @since version 1.0.0 + - strings and object keys are escaped using `escape_string()` + - integer numbers are converted implicitly via `operator<<` + - floating-point numbers are converted to a string using `"%g"` format - @liveexample{The example below shows how array elements can be read using - `at()`. It also demonstrates the different exceptions that can be thrown., - at__size_type_const} + @param[in] val value to serialize + @param[in] pretty_print whether the output shall be pretty-printed + @param[in] indent_step the indent level + @param[in] current_indent the current indent level (only used internally) */ - const_reference at(size_type idx) const + void dump(const BasicJsonType& val, const bool pretty_print, + const bool ensure_ascii, + const unsigned int indent_step, + const unsigned int current_indent = 0) { - // at only works for arrays - if (is_array()) + switch (val.m_type) { - JSON_TRY - { - return m_value.array->at(idx); - } - JSON_CATCH (std::out_of_range&) + case value_t::object: { - // create better exception explanation - JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range")); - } - } - else - { - JSON_THROW(type_error::create(304, "cannot use at() with " + type_name())); - } - } + if (val.m_value.object->empty()) + { + o->write_characters("{}", 2); + return; + } - /*! - @brief access specified object element with bounds checking + if (pretty_print) + { + o->write_characters("{\n", 2); - Returns a reference to the element at with specified key @a key, with - bounds checking. + // variable to hold indentation for recursive calls + const auto new_indent = current_indent + indent_step; + if (JSON_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } - @param[in] key key of the element to access + // first n-1 elements + auto i = val.m_value.object->cbegin(); + for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i) + { + o->write_characters(indent_string.c_str(), new_indent); + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\": ", 3); + dump(i->second, true, ensure_ascii, indent_step, new_indent); + o->write_characters(",\n", 2); + } - @return reference to the element at key @a key + // last element + assert(i != val.m_value.object->cend()); + assert(std::next(i) == val.m_value.object->cend()); + o->write_characters(indent_string.c_str(), new_indent); + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\": ", 3); + dump(i->second, true, ensure_ascii, indent_step, new_indent); - @throw type_error.304 if the JSON value is not an object; in this case, - calling `at` with a key makes no sense. See example below. - @throw out_of_range.403 if the key @a key is is not stored in the object; - that is, `find(key) == end()`. See example below. + o->write_character('\n'); + o->write_characters(indent_string.c_str(), current_indent); + o->write_character('}'); + } + else + { + o->write_character('{'); - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. + // first n-1 elements + auto i = val.m_value.object->cbegin(); + for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i) + { + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\":", 2); + dump(i->second, false, ensure_ascii, indent_step, current_indent); + o->write_character(','); + } - @complexity Logarithmic in the size of the container. + // last element + assert(i != val.m_value.object->cend()); + assert(std::next(i) == val.m_value.object->cend()); + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\":", 2); + dump(i->second, false, ensure_ascii, indent_step, current_indent); - @sa @ref operator[](const typename object_t::key_type&) for unchecked - access by reference - @sa @ref value() for access by value with a default value + o->write_character('}'); + } - @since version 1.0.0 + return; + } - @liveexample{The example below shows how object elements can be read and - written using `at()`. It also demonstrates the different exceptions that - can be thrown.,at__object_t_key_type} - */ - reference at(const typename object_t::key_type& key) - { - // at only works for objects - if (is_object()) - { - JSON_TRY - { - return m_value.object->at(key); - } - JSON_CATCH (std::out_of_range&) + case value_t::array: { - // create better exception explanation - JSON_THROW(out_of_range::create(403, "key '" + key + "' not found")); - } - } - else - { - JSON_THROW(type_error::create(304, "cannot use at() with " + type_name())); - } - } + if (val.m_value.array->empty()) + { + o->write_characters("[]", 2); + return; + } - /*! - @brief access specified object element with bounds checking + if (pretty_print) + { + o->write_characters("[\n", 2); - Returns a const reference to the element at with specified key @a key, - with bounds checking. + // variable to hold indentation for recursive calls + const auto new_indent = current_indent + indent_step; + if (JSON_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } - @param[in] key key of the element to access + // first n-1 elements + for (auto i = val.m_value.array->cbegin(); + i != val.m_value.array->cend() - 1; ++i) + { + o->write_characters(indent_string.c_str(), new_indent); + dump(*i, true, ensure_ascii, indent_step, new_indent); + o->write_characters(",\n", 2); + } - @return const reference to the element at key @a key + // last element + assert(not val.m_value.array->empty()); + o->write_characters(indent_string.c_str(), new_indent); + dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent); - @throw type_error.304 if the JSON value is not an object; in this case, - calling `at` with a key makes no sense. See example below. - @throw out_of_range.403 if the key @a key is is not stored in the object; - that is, `find(key) == end()`. See example below. + o->write_character('\n'); + o->write_characters(indent_string.c_str(), current_indent); + o->write_character(']'); + } + else + { + o->write_character('['); - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. + // first n-1 elements + for (auto i = val.m_value.array->cbegin(); + i != val.m_value.array->cend() - 1; ++i) + { + dump(*i, false, ensure_ascii, indent_step, current_indent); + o->write_character(','); + } - @complexity Logarithmic in the size of the container. + // last element + assert(not val.m_value.array->empty()); + dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent); - @sa @ref operator[](const typename object_t::key_type&) for unchecked - access by reference - @sa @ref value() for access by value with a default value + o->write_character(']'); + } - @since version 1.0.0 + return; + } - @liveexample{The example below shows how object elements can be read using - `at()`. It also demonstrates the different exceptions that can be thrown., - at__object_t_key_type_const} - */ - const_reference at(const typename object_t::key_type& key) const - { - // at only works for objects - if (is_object()) - { - JSON_TRY + case value_t::string: { - return m_value.object->at(key); + o->write_character('\"'); + dump_escaped(*val.m_value.string, ensure_ascii); + o->write_character('\"'); + return; } - JSON_CATCH (std::out_of_range&) + + case value_t::boolean: { - // create better exception explanation - JSON_THROW(out_of_range::create(403, "key '" + key + "' not found")); + if (val.m_value.boolean) + { + o->write_characters("true", 4); + } + else + { + o->write_characters("false", 5); + } + return; } - } - else - { - JSON_THROW(type_error::create(304, "cannot use at() with " + type_name())); - } - } - /*! - @brief access specified array element + case value_t::number_integer: + { + dump_integer(val.m_value.number_integer); + return; + } - Returns a reference to the element at specified location @a idx. + case value_t::number_unsigned: + { + dump_integer(val.m_value.number_unsigned); + return; + } - @note If @a idx is beyond the range of the array (i.e., `idx >= size()`), - then the array is silently filled up with `null` values to make `idx` a - valid reference to the last stored element. + case value_t::number_float: + { + dump_float(val.m_value.number_float); + return; + } - @param[in] idx index of the element to access + case value_t::discarded: + { + o->write_characters("", 11); + return; + } - @return reference to the element at index @a idx + case value_t::null: + { + o->write_characters("null", 4); + return; + } + } + } - @throw type_error.305 if the JSON value is not an array or null; in that - cases, using the [] operator with an index makes no sense. + private: + /*! + @brief returns the number of expected bytes following in UTF-8 string - @complexity Constant if @a idx is in the range of the array. Otherwise - linear in `idx - size()`. + @param[in] u the first byte of a UTF-8 string + @return the number of expected bytes following + */ + static constexpr std::size_t bytes_following(const uint8_t u) + { + return ((u <= 127) ? 0 + : ((192 <= u and u <= 223) ? 1 + : ((224 <= u and u <= 239) ? 2 + : ((240 <= u and u <= 247) ? 3 : std::string::npos)))); + } - @liveexample{The example below shows how array elements can be read and - written using `[]` operator. Note the addition of `null` - values.,operatorarray__size_type} + /*! + @brief calculates the extra space to escape a JSON string - @since version 1.0.0 + @param[in] s the string to escape + @param[in] ensure_ascii whether to escape non-ASCII characters with + \uXXXX sequences + @return the number of characters required to escape string @a s + + @complexity Linear in the length of string @a s. */ - reference operator[](size_type idx) + static std::size_t extra_space(const string_t& s, + const bool ensure_ascii) noexcept { - // implicitly convert null value to an empty array - if (is_null()) - { - m_type = value_t::array; - m_value.array = create(); - assert_invariant(); - } + std::size_t res = 0; - // operator[] only works for arrays - if (is_array()) + for (std::size_t i = 0; i < s.size(); ++i) { - // fill up array with null values if given idx is outside range - if (idx >= m_value.array->size()) + switch (s[i]) { - m_value.array->insert(m_value.array->end(), - idx - m_value.array->size() + 1, - basic_json()); - } + // control characters that can be escaped with a backslash + case '"': + case '\\': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + { + // from c (1 byte) to \x (2 bytes) + res += 1; + break; + } - return m_value.array->operator[](idx); - } + // control characters that need \uxxxx escaping + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + case 0x0B: + case 0x0E: + case 0x0F: + case 0x10: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + case 0x19: + case 0x1A: + case 0x1B: + case 0x1C: + case 0x1D: + case 0x1E: + case 0x1F: + { + // from c (1 byte) to \uxxxx (6 bytes) + res += 5; + break; + } - JSON_THROW(type_error::create(305, "cannot use operator[] with " + type_name())); - } + default: + { + if (ensure_ascii and (s[i] & 0x80 or s[i] == 0x7F)) + { + const auto bytes = bytes_following(static_cast(s[i])); + // invalid characters will be detected by throw_if_invalid_utf8 + assert (bytes != std::string::npos); - /*! - @brief access specified array element + if (bytes == 3) + { + // codepoints that need 4 bytes (i.e., 3 additional + // bytes) in UTF-8 need a surrogate pair when \u + // escaping is used: from 4 bytes to \uxxxx\uxxxx + // (12 bytes) + res += (12 - bytes - 1); + } + else + { + // from x bytes to \uxxxx (6 bytes) + res += (6 - bytes - 1); + } - Returns a const reference to the element at specified location @a idx. + // skip the additional bytes + i += bytes; + } + break; + } + } + } - @param[in] idx index of the element to access + return res; + } - @return const reference to the element at index @a idx + static void escape_codepoint(int codepoint, string_t& result, std::size_t& pos) + { + // expecting a proper codepoint + assert(0x00 <= codepoint and codepoint <= 0x10FFFF); - @throw type_error.305 if the JSON value is not an array; in that cases, - using the [] operator with an index makes no sense. + // the last written character was the backslash before the 'u' + assert(result[pos] == '\\'); - @complexity Constant. + // write the 'u' + result[++pos] = 'u'; - @liveexample{The example below shows how array elements can be read using - the `[]` operator.,operatorarray__size_type_const} + // convert a number 0..15 to its hex representation (0..f) + static const std::array hexify = + { + { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' + } + }; - @since version 1.0.0 - */ - const_reference operator[](size_type idx) const - { - // const operator[] only works for arrays - if (is_array()) + if (codepoint < 0x10000) { - return m_value.array->operator[](idx); + // codepoints U+0000..U+FFFF can be represented as \uxxxx. + result[++pos] = hexify[(codepoint >> 12) & 0x0F]; + result[++pos] = hexify[(codepoint >> 8) & 0x0F]; + result[++pos] = hexify[(codepoint >> 4) & 0x0F]; + result[++pos] = hexify[codepoint & 0x0F]; + } + else + { + // codepoints U+10000..U+10FFFF need a surrogate pair to be + // represented as \uxxxx\uxxxx. + // http://www.unicode.org/faq/utf_bom.html#utf16-4 + codepoint -= 0x10000; + const int high_surrogate = 0xD800 | ((codepoint >> 10) & 0x3FF); + const int low_surrogate = 0xDC00 | (codepoint & 0x3FF); + result[++pos] = hexify[(high_surrogate >> 12) & 0x0F]; + result[++pos] = hexify[(high_surrogate >> 8) & 0x0F]; + result[++pos] = hexify[(high_surrogate >> 4) & 0x0F]; + result[++pos] = hexify[high_surrogate & 0x0F]; + ++pos; // backslash is already in output + result[++pos] = 'u'; + result[++pos] = hexify[(low_surrogate >> 12) & 0x0F]; + result[++pos] = hexify[(low_surrogate >> 8) & 0x0F]; + result[++pos] = hexify[(low_surrogate >> 4) & 0x0F]; + result[++pos] = hexify[low_surrogate & 0x0F]; } - JSON_THROW(type_error::create(305, "cannot use operator[] with " + type_name())); + ++pos; } /*! - @brief access specified object element - - Returns a reference to the element at with specified key @a key. - - @note If @a key is not found in the object, then it is silently added to - the object and filled with a `null` value to make `key` a valid reference. - In case the value was `null` before, it is converted to an object. - - @param[in] key key of the element to access - - @return reference to the element at key @a key - - @throw type_error.305 if the JSON value is not an object or null; in that - cases, using the [] operator with a key makes no sense. + @brief dump escaped string - @complexity Logarithmic in the size of the container. - - @liveexample{The example below shows how object elements can be read and - written using the `[]` operator.,operatorarray__key_type} + Escape a string by replacing certain special characters by a sequence of an + escape character (backslash) and another character and other control + characters by a sequence of "\u" followed by a four-digit hex + representation. The escaped string is written to output stream @a o. - @sa @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa @ref value() for access by value with a default value + @param[in] s the string to escape + @param[in] ensure_ascii whether to escape non-ASCII characters with + \uXXXX sequences - @since version 1.0.0 + @complexity Linear in the length of string @a s. */ - reference operator[](const typename object_t::key_type& key) + void dump_escaped(const string_t& s, const bool ensure_ascii) const { - // implicitly convert null value to an empty object - if (is_null()) + throw_if_invalid_utf8(s); + + const auto space = extra_space(s, ensure_ascii); + if (space == 0) { - m_type = value_t::object; - m_value.object = create(); - assert_invariant(); + o->write_characters(s.c_str(), s.size()); + return; } - // operator[] only works for objects - if (is_object()) + // create a result string of necessary size + string_t result(s.size() + space, '\\'); + std::size_t pos = 0; + + for (std::size_t i = 0; i < s.size(); ++i) { - return m_value.object->operator[](key); - } + switch (s[i]) + { + case '"': // quotation mark (0x22) + { + result[pos + 1] = '"'; + pos += 2; + break; + } - JSON_THROW(type_error::create(305, "cannot use operator[] with " + type_name())); - } + case '\\': // reverse solidus (0x5C) + { + // nothing to change + pos += 2; + break; + } - /*! - @brief read-only access specified object element + case '\b': // backspace (0x08) + { + result[pos + 1] = 'b'; + pos += 2; + break; + } - Returns a const reference to the element at with specified key @a key. No - bounds checking is performed. + case '\f': // formfeed (0x0C) + { + result[pos + 1] = 'f'; + pos += 2; + break; + } - @warning If the element with key @a key does not exist, the behavior is - undefined. + case '\n': // newline (0x0A) + { + result[pos + 1] = 'n'; + pos += 2; + break; + } - @param[in] key key of the element to access + case '\r': // carriage return (0x0D) + { + result[pos + 1] = 'r'; + pos += 2; + break; + } - @return const reference to the element at key @a key + case '\t': // horizontal tab (0x09) + { + result[pos + 1] = 't'; + pos += 2; + break; + } - @pre The element with key @a key must exist. **This precondition is - enforced with an assertion.** + default: + { + // escape control characters (0x00..0x1F) or, if + // ensure_ascii parameter is used, non-ASCII characters + if ((0x00 <= s[i] and s[i] <= 0x1F) or + (ensure_ascii and (s[i] & 0x80 or s[i] == 0x7F))) + { + const auto bytes = bytes_following(static_cast(s[i])); + // invalid characters will be detected by throw_if_invalid_utf8 + assert (bytes != std::string::npos); - @throw type_error.305 if the JSON value is not an object; in that cases, - using the [] operator with a key makes no sense. + // check that the additional bytes are present + assert(i + bytes < s.size()); - @complexity Logarithmic in the size of the container. + // to use \uxxxx escaping, we first need to caluclate + // the codepoint from the UTF-8 bytes + int codepoint = 0; - @liveexample{The example below shows how object elements can be read using - the `[]` operator.,operatorarray__key_type_const} + assert(0 <= bytes and bytes <= 3); + switch (bytes) + { + case 0: + { + codepoint = s[i] & 0xFF; + break; + } - @sa @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa @ref value() for access by value with a default value + case 1: + { + codepoint = ((s[i] & 0x3F) << 6) + + (s[i + 1] & 0x7F); + break; + } - @since version 1.0.0 - */ - const_reference operator[](const typename object_t::key_type& key) const - { - // const operator[] only works for objects - if (is_object()) - { - assert(m_value.object->find(key) != m_value.object->end()); - return m_value.object->find(key)->second; + case 2: + { + codepoint = ((s[i] & 0x1F) << 12) + + ((s[i + 1] & 0x7F) << 6) + + (s[i + 2] & 0x7F); + break; + } + + case 3: + { + codepoint = ((s[i] & 0xF) << 18) + + ((s[i + 1] & 0x7F) << 12) + + ((s[i + 2] & 0x7F) << 6) + + (s[i + 3] & 0x7F); + break; + } + + default: + break; // LCOV_EXCL_LINE + } + + escape_codepoint(codepoint, result, pos); + i += bytes; + } + else + { + // all other characters are added as-is + result[pos++] = s[i]; + } + break; + } + } } - JSON_THROW(type_error::create(305, "cannot use operator[] with " + type_name())); + assert(pos == result.size()); + o->write_characters(result.c_str(), result.size()); } /*! - @brief access specified object element - - Returns a reference to the element at with specified key @a key. - - @note If @a key is not found in the object, then it is silently added to - the object and filled with a `null` value to make `key` a valid reference. - In case the value was `null` before, it is converted to an object. + @brief dump an integer - @param[in] key key of the element to access + Dump a given integer to output stream @a o. Works internally with + @a number_buffer. - @return reference to the element at key @a key + @param[in] x integer number (signed or unsigned) to dump + @tparam NumberType either @a number_integer_t or @a number_unsigned_t + */ + template::value or + std::is_same::value, + int> = 0> + void dump_integer(NumberType x) + { + // special case for "0" + if (x == 0) + { + o->write_character('0'); + return; + } - @throw type_error.305 if the JSON value is not an object or null; in that - cases, using the [] operator with a key makes no sense. + const bool is_negative = (x <= 0) and (x != 0); // see issue #755 + std::size_t i = 0; - @complexity Logarithmic in the size of the container. + while (x != 0) + { + // spare 1 byte for '\0' + assert(i < number_buffer.size() - 1); - @liveexample{The example below shows how object elements can be read and - written using the `[]` operator.,operatorarray__key_type} + const auto digit = std::labs(static_cast(x % 10)); + number_buffer[i++] = static_cast('0' + digit); + x /= 10; + } - @sa @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa @ref value() for access by value with a default value + if (is_negative) + { + // make sure there is capacity for the '-' + assert(i < number_buffer.size() - 2); + number_buffer[i++] = '-'; + } - @since version 1.0.0 - */ - template - reference operator[](T * (&key)[n]) - { - return operator[](static_cast(key)); + std::reverse(number_buffer.begin(), number_buffer.begin() + i); + o->write_characters(number_buffer.data(), i); } /*! - @brief read-only access specified object element + @brief dump a floating-point number - Returns a const reference to the element at with specified key @a key. No - bounds checking is performed. + Dump a given floating-point number to output stream @a o. Works internally + with @a number_buffer. - @warning If the element with key @a key does not exist, the behavior is - undefined. + @param[in] x floating-point number to dump + */ + void dump_float(number_float_t x) + { + // NaN / inf + if (not std::isfinite(x) or std::isnan(x)) + { + o->write_characters("null", 4); + return; + } - @note This function is required for compatibility reasons with Clang. + // get number of digits for a text -> float -> text round-trip + static constexpr auto d = std::numeric_limits::digits10; - @param[in] key key of the element to access + // the actual conversion + std::ptrdiff_t len = snprintf(number_buffer.data(), number_buffer.size(), "%.*g", d, x); - @return const reference to the element at key @a key + // negative value indicates an error + assert(len > 0); + // check if buffer was large enough + assert(static_cast(len) < number_buffer.size()); - @throw type_error.305 if the JSON value is not an object; in that cases, - using the [] operator with a key makes no sense. + // erase thousands separator + if (thousands_sep != '\0') + { + const auto end = std::remove(number_buffer.begin(), + number_buffer.begin() + len, thousands_sep); + std::fill(end, number_buffer.end(), '\0'); + assert((end - number_buffer.begin()) <= len); + len = (end - number_buffer.begin()); + } - @complexity Logarithmic in the size of the container. + // convert decimal point to '.' + if (decimal_point != '\0' and decimal_point != '.') + { + const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point); + if (dec_pos != number_buffer.end()) + { + *dec_pos = '.'; + } + } - @liveexample{The example below shows how object elements can be read using - the `[]` operator.,operatorarray__key_type_const} + o->write_characters(number_buffer.data(), static_cast(len)); - @sa @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa @ref value() for access by value with a default value + // determine if need to append ".0" + const bool value_is_int_like = + std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, + [](char c) + { + return (c == '.' or c == 'e'); + }); - @since version 1.0.0 - */ - template - const_reference operator[](T * (&key)[n]) const - { - return operator[](static_cast(key)); + if (value_is_int_like) + { + o->write_characters(".0", 2); + } } /*! - @brief access specified object element - - Returns a reference to the element at with specified key @a key. + @brief check whether a string is UTF-8 encoded - @note If @a key is not found in the object, then it is silently added to - the object and filled with a `null` value to make `key` a valid reference. - In case the value was `null` before, it is converted to an object. + The function checks each byte of a string whether it is UTF-8 encoded. The + result of the check is stored in the @a state parameter. The function must + be called initially with state 0 (accept). State 1 means the string must + be rejected, because the current byte is not allowed. If the string is + completely processed, but the state is non-zero, the string ended + prematurely; that is, the last byte indicated more bytes should have + followed. - @param[in] key key of the element to access + @param[in,out] state the state of the decoding + @param[in] byte next byte to decode - @return reference to the element at key @a key + @note The function has been edited: a std::array is used and the code + point is not calculated. - @throw type_error.305 if the JSON value is not an object or null; in that - cases, using the [] operator with a key makes no sense. + @copyright Copyright (c) 2008-2009 Bjoern Hoehrmann + @sa http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ + */ + static void decode(uint8_t& state, const uint8_t byte) + { + static const std::array utf8d = + { + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1F + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20..3F + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40..5F + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60..7F + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 80..9F + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // A0..BF + 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C0..DF + 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF + 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF + 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, // s1..s2 + 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // s3..s4 + 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, // s5..s6 + 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // s7..s8 + } + }; - @complexity Logarithmic in the size of the container. + const uint8_t type = utf8d[byte]; + state = utf8d[256u + state * 16u + type]; + } - @liveexample{The example below shows how object elements can be read and - written using the `[]` operator.,operatorarray__key_type} + /*! + @brief throw an exception if a string is not UTF-8 encoded - @sa @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa @ref value() for access by value with a default value + @param[in] str UTF-8 string to check + @throw type_error.316 if passed string is not UTF-8 encoded - @since version 1.1.0 + @since version 3.0.0 */ - template - reference operator[](T* key) + static void throw_if_invalid_utf8(const std::string& str) { - // implicitly convert null to object - if (is_null()) + // start with state 0 (= accept) + uint8_t state = 0; + + for (size_t i = 0; i < str.size(); ++i) { - m_type = value_t::object; - m_value = value_t::object; - assert_invariant(); + const auto byte = static_cast(str[i]); + decode(state, byte); + if (state == 1) + { + // state 1 means reject + std::stringstream ss; + ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << static_cast(byte); + JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + ss.str())); + } } - // at only works for objects - if (is_object()) + if (state != 0) { - return m_value.object->operator[](key); + // we finish reading, but do not accept: string was incomplete + std::stringstream ss; + ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << static_cast(static_cast(str.back())); + JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + ss.str())); } - - JSON_THROW(type_error::create(305, "cannot use operator[] with " + type_name())); } - /*! - @brief read-only access specified object element + private: + /// the output of the serializer + output_adapter_t o = nullptr; - Returns a const reference to the element at with specified key @a key. No - bounds checking is performed. + /// a (hopefully) large enough character buffer + std::array number_buffer{{}}; - @warning If the element with key @a key does not exist, the behavior is - undefined. + /// the locale + const std::lconv* loc = nullptr; + /// the locale's thousand separator character + const char thousands_sep = '\0'; + /// the locale's decimal point character + const char decimal_point = '\0'; - @param[in] key key of the element to access + /// the indentation character + const char indent_char; - @return const reference to the element at key @a key + /// the indentation string + string_t indent_string; +}; - @pre The element with key @a key must exist. **This precondition is - enforced with an assertion.** +template +class json_ref +{ + public: + using value_type = BasicJsonType; - @throw type_error.305 if the JSON value is not an object; in that cases, - using the [] operator with a key makes no sense. + json_ref(value_type&& value) + : owned_value(std::move(value)), value_ref(&owned_value), is_rvalue(true) + {} - @complexity Logarithmic in the size of the container. + json_ref(const value_type& value) + : value_ref(const_cast(&value)), is_rvalue(false) + {} - @liveexample{The example below shows how object elements can be read using - the `[]` operator.,operatorarray__key_type_const} + json_ref(std::initializer_list init) + : owned_value(init), value_ref(&owned_value), is_rvalue(true) + {} - @sa @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa @ref value() for access by value with a default value + template + json_ref(Args&& ... args) + : owned_value(std::forward(args)...), value_ref(&owned_value), is_rvalue(true) + {} - @since version 1.1.0 - */ - template - const_reference operator[](T* key) const + // class should be movable only + json_ref(json_ref&&) = default; + json_ref(const json_ref&) = delete; + json_ref& operator=(const json_ref&) = delete; + + value_type moved_or_copied() const { - // at only works for objects - if (is_object()) + if (is_rvalue) { - assert(m_value.object->find(key) != m_value.object->end()); - return m_value.object->find(key)->second; + return std::move(*value_ref); } - - JSON_THROW(type_error::create(305, "cannot use operator[] with " + type_name())); + return *value_ref; } - /*! - @brief access specified object element with default value - - Returns either a copy of an object's element at the specified key @a key - or a given default value if no element with key @a key exists. - - The function is basically equivalent to executing - @code {.cpp} - try { - return at(key); - } catch(out_of_range) { - return default_value; + value_type const& operator*() const + { + return *static_cast(value_ref); } - @endcode - @note Unlike @ref at(const typename object_t::key_type&), this function - does not throw if the given key @a key was not found. - - @note Unlike @ref operator[](const typename object_t::key_type& key), this - function does not implicitly add an element to the position defined by @a - key. This function is furthermore also applicable to const objects. + value_type const* operator->() const + { + return static_cast(value_ref); + } - @param[in] key key of the element to access - @param[in] default_value the value to return if @a key is not found + private: + mutable value_type owned_value = nullptr; + value_type* value_ref = nullptr; + const bool is_rvalue; +}; - @tparam ValueType type compatible to JSON values, for instance `int` for - JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for - JSON arrays. Note the type of the expected value at @a key and the default - value @a default_value must be compatible. +} // namespace detail - @return copy of the element at key @a key or @a default_value if @a key - is not found +/// namespace to hold default `to_json` / `from_json` functions +namespace +{ +constexpr const auto& to_json = detail::static_const::value; +constexpr const auto& from_json = detail::static_const::value; +} - @throw type_error.306 if the JSON value is not an objec; in that cases, - using `value()` with a key makes no sense. - @complexity Logarithmic in the size of the container. +/*! +@brief default JSONSerializer template argument - @liveexample{The example below shows how object elements can be queried - with a default value.,basic_json__value} +This serializer ignores the template arguments and uses ADL +([argument-dependent lookup](http://en.cppreference.com/w/cpp/language/adl)) +for serialization. +*/ +template +struct adl_serializer +{ + /*! + @brief convert a JSON value to any value type - @sa @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa @ref operator[](const typename object_t::key_type&) for unchecked - access by reference + This function is usually called by the `get()` function of the + @ref basic_json class (either explicit or via conversion operators). - @since version 1.0.0 + @param[in] j JSON value to read from + @param[in,out] val value to write to */ - template::value, int>::type = 0> - ValueType value(const typename object_t::key_type& key, ValueType default_value) const + template + static void from_json(BasicJsonType&& j, ValueType& val) noexcept( + noexcept(::nlohmann::from_json(std::forward(j), val))) { - // at only works for objects - if (is_object()) - { - // if key is found, return value and given default value otherwise - const auto it = find(key); - if (it != end()) - { - return *it; - } - - return default_value; - } - else - { - JSON_THROW(type_error::create(306, "cannot use value() with " + type_name())); - } + ::nlohmann::from_json(std::forward(j), val); } /*! - @brief overload for a default value of type const char* - @copydoc basic_json::value(const typename object_t::key_type&, ValueType) const + @brief convert any value type to a JSON value + + This function is usually called by the constructors of the @ref basic_json + class. + + @param[in,out] j JSON value to write to + @param[in] val value to read from */ - string_t value(const typename object_t::key_type& key, const char* default_value) const + template + static void to_json(BasicJsonType& j, ValueType&& val) noexcept( + noexcept(::nlohmann::to_json(j, std::forward(val)))) { - return value(key, string_t(default_value)); + ::nlohmann::to_json(j, std::forward(val)); } +}; + +/*! +@brief JSON Pointer + +A JSON pointer defines a string syntax for identifying a specific value +within a JSON document. It can be used with functions `at` and +`operator[]`. Furthermore, JSON pointers are the base for JSON patches. +@sa [RFC 6901](https://tools.ietf.org/html/rfc6901) + +@since version 2.0.0 +*/ +class json_pointer +{ + /// allow basic_json to access private members + NLOHMANN_BASIC_JSON_TPL_DECLARATION + friend class basic_json; + + public: /*! - @brief access specified object element via JSON Pointer with default value + @brief create JSON pointer - Returns either a copy of an object's element at the specified key @a key - or a given default value if no element with key @a key exists. + Create a JSON pointer according to the syntax described in + [Section 3 of RFC6901](https://tools.ietf.org/html/rfc6901#section-3). - The function is basically equivalent to executing - @code {.cpp} - try { - return at(ptr); - } catch(out_of_range) { - return default_value; - } - @endcode + @param[in] s string representing the JSON pointer; if omitted, the empty + string is assumed which references the whole JSON value - @note Unlike @ref at(const json_pointer&), this function does not throw - if the given key @a key was not found. + @throw parse_error.107 if the given JSON pointer @a s is nonempty and + does not begin with a slash (`/`); see example below - @param[in] ptr a JSON pointer to the element to access - @param[in] default_value the value to return if @a ptr found no value + @throw parse_error.108 if a tilde (`~`) in the given JSON pointer @a s + is not followed by `0` (representing `~`) or `1` (representing `/`); + see example below - @tparam ValueType type compatible to JSON values, for instance `int` for - JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for - JSON arrays. Note the type of the expected value at @a key and the default - value @a default_value must be compatible. + @liveexample{The example shows the construction several valid JSON + pointers as well as the exceptional behavior.,json_pointer} - @return copy of the element at key @a key or @a default_value if @a key - is not found + @since version 2.0.0 + */ + explicit json_pointer(const std::string& s = "") : reference_tokens(split(s)) {} - @throw type_error.306 if the JSON value is not an objec; in that cases, - using `value()` with a key makes no sense. + /*! + @brief return a string representation of the JSON pointer - @complexity Logarithmic in the size of the container. + @invariant For each JSON pointer `ptr`, it holds: + @code {.cpp} + ptr == json_pointer(ptr.to_string()); + @endcode - @liveexample{The example below shows how object elements can be queried - with a default value.,basic_json__value_ptr} + @return a string representation of the JSON pointer - @sa @ref operator[](const json_pointer&) for unchecked access by reference + @liveexample{The example shows the result of `to_string`., + json_pointer__to_string} - @since version 2.0.2 + @since version 2.0.0 */ - template::value, int>::type = 0> - ValueType value(const json_pointer& ptr, ValueType default_value) const + std::string to_string() const noexcept { - // at only works for objects - if (is_object()) + return std::accumulate(reference_tokens.begin(), reference_tokens.end(), + std::string{}, + [](const std::string & a, const std::string & b) { - // if pointer resolves a value, return it or use default value - JSON_TRY - { - return ptr.get_checked(this); - } - JSON_CATCH (out_of_range&) - { - return default_value; - } - } - - JSON_THROW(type_error::create(306, "cannot use value() with " + type_name())); + return a + "/" + escape(b); + }); } - /*! - @brief overload for a default value of type const char* - @copydoc basic_json::value(const json_pointer&, ValueType) const - */ - string_t value(const json_pointer& ptr, const char* default_value) const + /// @copydoc to_string() + operator std::string() const { - return value(ptr, string_t(default_value)); + return to_string(); } + private: /*! - @brief access the first element - - Returns a reference to the first element in the container. For a JSON - container `c`, the expression `c.front()` is equivalent to `*c.begin()`. - - @return In case of a structured type (array or object), a reference to the - first element is returned. In case of number, string, or boolean values, a - reference to the value is returned. - - @complexity Constant. - - @pre The JSON value must not be `null` (would throw `std::out_of_range`) - or an empty array or object (undefined behavior, **guarded by - assertions**). - @post The JSON value remains unchanged. - - @throw invalid_iterator.214 when called on `null` value - - @liveexample{The following code shows an example for `front()`.,front} + @brief remove and return last reference pointer + @throw out_of_range.405 if JSON pointer has no parent + */ + std::string pop_back() + { + if (JSON_UNLIKELY(is_root())) + { + JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent")); + } - @sa @ref back() -- access the last element + auto last = reference_tokens.back(); + reference_tokens.pop_back(); + return last; + } - @since version 1.0.0 - */ - reference front() + /// return whether pointer points to the root document + bool is_root() const { - return *begin(); + return reference_tokens.empty(); } - /*! - @copydoc basic_json::front() - */ - const_reference front() const + json_pointer top() const { - return *cbegin(); + if (JSON_UNLIKELY(is_root())) + { + JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent")); + } + + json_pointer result = *this; + result.reference_tokens = {reference_tokens[0]}; + return result; } + /*! - @brief access the last element + @brief create and return a reference to the pointed to value - Returns a reference to the last element in the container. For a JSON - container `c`, the expression `c.back()` is equivalent to - @code {.cpp} - auto tmp = c.end(); - --tmp; - return *tmp; - @endcode + @complexity Linear in the number of reference tokens. - @return In case of a structured type (array or object), a reference to the - last element is returned. In case of number, string, or boolean values, a - reference to the value is returned. + @throw parse_error.109 if array index is not a number + @throw type_error.313 if value cannot be unflattened + */ + NLOHMANN_BASIC_JSON_TPL_DECLARATION + NLOHMANN_BASIC_JSON_TPL& get_and_create(NLOHMANN_BASIC_JSON_TPL& j) const; - @complexity Constant. + /*! + @brief return a reference to the pointed to value - @pre The JSON value must not be `null` (would throw `std::out_of_range`) - or an empty array or object (undefined behavior, **guarded by - assertions**). - @post The JSON value remains unchanged. + @note This version does not throw if a value is not present, but tries to + create nested values instead. For instance, calling this function + with pointer `"/this/that"` on a null value is equivalent to calling + `operator[]("this").operator[]("that")` on that value, effectively + changing the null value to an object. - @throw invalid_iterator.214 when called on a `null` value. See example - below. + @param[in] ptr a JSON value - @liveexample{The following code shows an example for `back()`.,back} + @return reference to the JSON value pointed to by the JSON pointer - @sa @ref front() -- access the first element + @complexity Linear in the length of the JSON pointer. - @since version 1.0.0 + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + @throw out_of_range.404 if the JSON pointer can not be resolved */ - reference back() - { - auto tmp = end(); - --tmp; - return *tmp; - } + NLOHMANN_BASIC_JSON_TPL_DECLARATION + NLOHMANN_BASIC_JSON_TPL& get_unchecked(NLOHMANN_BASIC_JSON_TPL* ptr) const; /*! - @copydoc basic_json::back() + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + @throw out_of_range.402 if the array index '-' is used + @throw out_of_range.404 if the JSON pointer can not be resolved */ - const_reference back() const - { - auto tmp = cend(); - --tmp; - return *tmp; - } + NLOHMANN_BASIC_JSON_TPL_DECLARATION + NLOHMANN_BASIC_JSON_TPL& get_checked(NLOHMANN_BASIC_JSON_TPL* ptr) const; /*! - @brief remove element given an iterator - - Removes the element specified by iterator @a pos. The iterator @a pos must - be valid and dereferenceable. Thus the `end()` iterator (which is valid, - but is not dereferenceable) cannot be used as a value for @a pos. - - If called on a primitive type other than `null`, the resulting JSON value - will be `null`. + @brief return a const reference to the pointed to value - @param[in] pos iterator to the element to remove - @return Iterator following the last removed element. If the iterator @a - pos refers to the last element, the `end()` iterator is returned. - - @tparam IteratorType an @ref iterator or @ref const_iterator + @param[in] ptr a JSON value - @post Invalidates iterators and references at or after the point of the - erase, including the `end()` iterator. + @return const reference to the JSON value pointed to by the JSON + pointer - @throw type_error.307 if called on a `null` value; example: `"cannot use - erase() with null"` - @throw invalid_iterator.202 if called on an iterator which does not belong - to the current JSON value; example: `"iterator does not fit current - value"` - @throw invalid_iterator.205 if called on a primitive type with invalid - iterator (i.e., any iterator which is not `begin()`); example: `"iterator - out of range"` + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + @throw out_of_range.402 if the array index '-' is used + @throw out_of_range.404 if the JSON pointer can not be resolved + */ + NLOHMANN_BASIC_JSON_TPL_DECLARATION + const NLOHMANN_BASIC_JSON_TPL& get_unchecked(const NLOHMANN_BASIC_JSON_TPL* ptr) const; - @complexity The complexity depends on the type: - - objects: amortized constant - - arrays: linear in distance between @a pos and the end of the container - - strings: linear in the length of the string - - other types: constant + /*! + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + @throw out_of_range.402 if the array index '-' is used + @throw out_of_range.404 if the JSON pointer can not be resolved + */ + NLOHMANN_BASIC_JSON_TPL_DECLARATION + const NLOHMANN_BASIC_JSON_TPL& get_checked(const NLOHMANN_BASIC_JSON_TPL* ptr) const; - @liveexample{The example shows the result of `erase()` for different JSON - types.,erase__IteratorType} + /*! + @brief split the string input to reference tokens - @sa @ref erase(IteratorType, IteratorType) -- removes the elements in - the given range - @sa @ref erase(const typename object_t::key_type&) -- removes the element - from an object at the given key - @sa @ref erase(const size_type) -- removes the element from an array at - the given index + @note This function is only called by the json_pointer constructor. + All exceptions below are documented there. - @since version 1.0.0 + @throw parse_error.107 if the pointer is not empty or begins with '/' + @throw parse_error.108 if character '~' is not followed by '0' or '1' */ - template::value or - std::is_same::value, int>::type - = 0> - IteratorType erase(IteratorType pos) + static std::vector split(const std::string& reference_string) { - // make sure iterator fits the current value - if (this != pos.m_object) + std::vector result; + + // special case: empty reference string -> no reference tokens + if (reference_string.empty()) { - JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); + return result; } - IteratorType result = end(); + // check if nonempty reference string begins with slash + if (JSON_UNLIKELY(reference_string[0] != '/')) + { + JSON_THROW(detail::parse_error::create(107, 1, + "JSON pointer must be empty or begin with '/' - was: '" + + reference_string + "'")); + } - switch (m_type) + // extract the reference tokens: + // - slash: position of the last read slash (or end of string) + // - start: position after the previous slash + for ( + // search for the first slash after the first character + std::size_t slash = reference_string.find_first_of('/', 1), + // set the beginning of the first reference token + start = 1; + // we can stop if start == string::npos+1 = 0 + start != 0; + // set the beginning of the next reference token + // (will eventually be 0 if slash == std::string::npos) + start = slash + 1, + // find next slash + slash = reference_string.find_first_of('/', start)) { - case value_t::boolean: - case value_t::number_float: - case value_t::number_integer: - case value_t::number_unsigned: - case value_t::string: + // use the text between the beginning of the reference token + // (start) and the last slash (slash). + auto reference_token = reference_string.substr(start, slash - start); + + // check reference tokens are properly escaped + for (std::size_t pos = reference_token.find_first_of('~'); + pos != std::string::npos; + pos = reference_token.find_first_of('~', pos + 1)) { - if (not pos.m_it.primitive_iterator.is_begin()) - { - JSON_THROW(invalid_iterator::create(205, "iterator out of range")); - } + assert(reference_token[pos] == '~'); - if (is_string()) + // ~ must be followed by 0 or 1 + if (JSON_UNLIKELY(pos == reference_token.size() - 1 or + (reference_token[pos + 1] != '0' and + reference_token[pos + 1] != '1'))) { - AllocatorType alloc; - alloc.destroy(m_value.string); - alloc.deallocate(m_value.string, 1); - m_value.string = nullptr; + JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'")); } - - m_type = value_t::null; - assert_invariant(); - break; - } - - case value_t::object: - { - result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator); - break; - } - - case value_t::array: - { - result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator); - break; } - default: - { - JSON_THROW(type_error::create(307, "cannot use erase() with " + type_name())); - } + // finally, store the reference token + unescape(reference_token); + result.push_back(reference_token); } return result; } /*! - @brief remove elements given an iterator range + @brief replace all occurrences of a substring by another string - Removes the element specified by the range `[first; last)`. The iterator - @a first does not need to be dereferenceable if `first == last`: erasing - an empty range is a no-op. + @param[in,out] s the string to manipulate; changed so that all + occurrences of @a f are replaced with @a t + @param[in] f the substring to replace with @a t + @param[in] t the string to replace @a f - If called on a primitive type other than `null`, the resulting JSON value - will be `null`. + @pre The search string @a f must not be empty. **This precondition is + enforced with an assertion.** - @param[in] first iterator to the beginning of the range to remove - @param[in] last iterator past the end of the range to remove - @return Iterator following the last removed element. If the iterator @a - second refers to the last element, the `end()` iterator is returned. + @since version 2.0.0 + */ + static void replace_substring(std::string& s, const std::string& f, + const std::string& t) + { + assert(not f.empty()); + for (auto pos = s.find(f); // find first occurrence of f + pos != std::string::npos; // make sure f was found + s.replace(pos, f.size(), t), // replace with t, and + pos = s.find(f, pos + t.size())) // find next occurrence of f + {} + } - @tparam IteratorType an @ref iterator or @ref const_iterator + /// escape "~"" to "~0" and "/" to "~1" + static std::string escape(std::string s) + { + replace_substring(s, "~", "~0"); + replace_substring(s, "/", "~1"); + return s; + } - @post Invalidates iterators and references at or after the point of the - erase, including the `end()` iterator. + /// unescape "~1" to tilde and "~0" to slash (order is important!) + static void unescape(std::string& s) + { + replace_substring(s, "~1", "/"); + replace_substring(s, "~0", "~"); + } - @throw type_error.307 if called on a `null` value; example: `"cannot use - erase() with null"` - @throw invalid_iterator.203 if called on iterators which does not belong - to the current JSON value; example: `"iterators do not fit current value"` - @throw invalid_iterator.204 if called on a primitive type with invalid - iterators (i.e., if `first != begin()` and `last != end()`); example: - `"iterators out of range"` + /*! + @param[in] reference_string the reference string to the current value + @param[in] value the value to consider + @param[in,out] result the result object to insert values to - @complexity The complexity depends on the type: - - objects: `log(size()) + std::distance(first, last)` - - arrays: linear in the distance between @a first and @a last, plus linear - in the distance between @a last and end of the container - - strings: linear in the length of the string - - other types: constant + @note Empty objects or arrays are flattened to `null`. + */ + NLOHMANN_BASIC_JSON_TPL_DECLARATION + static void flatten(const std::string& reference_string, + const NLOHMANN_BASIC_JSON_TPL& value, + NLOHMANN_BASIC_JSON_TPL& result); - @liveexample{The example shows the result of `erase()` for different JSON - types.,erase__IteratorType_IteratorType} + /*! + @param[in] value flattened JSON - @sa @ref erase(IteratorType) -- removes the element at a given position - @sa @ref erase(const typename object_t::key_type&) -- removes the element - from an object at the given key - @sa @ref erase(const size_type) -- removes the element from an array at - the given index + @return unflattened JSON - @since version 1.0.0 + @throw parse_error.109 if array index is not a number + @throw type_error.314 if value is not an object + @throw type_error.315 if object values are not primitive + @throw type_error.313 if value cannot be unflattened */ - template::value or - std::is_same::value, int>::type - = 0> - IteratorType erase(IteratorType first, IteratorType last) - { - // make sure iterator fits the current value - if (this != first.m_object or this != last.m_object) - { - JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value")); - } + NLOHMANN_BASIC_JSON_TPL_DECLARATION + static NLOHMANN_BASIC_JSON_TPL + unflatten(const NLOHMANN_BASIC_JSON_TPL& value); - IteratorType result = end(); + friend bool operator==(json_pointer const& lhs, + json_pointer const& rhs) noexcept; - switch (m_type) - { - case value_t::boolean: - case value_t::number_float: - case value_t::number_integer: - case value_t::number_unsigned: - case value_t::string: - { - if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end()) - { - JSON_THROW(invalid_iterator::create(204, "iterators out of range")); - } + friend bool operator!=(json_pointer const& lhs, + json_pointer const& rhs) noexcept; - if (is_string()) - { - AllocatorType alloc; - alloc.destroy(m_value.string); - alloc.deallocate(m_value.string, 1); - m_value.string = nullptr; - } + /// the reference tokens + std::vector reference_tokens; +}; - m_type = value_t::null; - assert_invariant(); - break; - } +/*! +@brief a class to store JSON values - case value_t::object: - { - result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator, - last.m_it.object_iterator); - break; - } +@tparam ObjectType type for JSON objects (`std::map` by default; will be used +in @ref object_t) +@tparam ArrayType type for JSON arrays (`std::vector` by default; will be used +in @ref array_t) +@tparam StringType type for JSON strings and object keys (`std::string` by +default; will be used in @ref string_t) +@tparam BooleanType type for JSON booleans (`bool` by default; will be used +in @ref boolean_t) +@tparam NumberIntegerType type for JSON integer numbers (`int64_t` by +default; will be used in @ref number_integer_t) +@tparam NumberUnsignedType type for JSON unsigned integer numbers (@c +`uint64_t` by default; will be used in @ref number_unsigned_t) +@tparam NumberFloatType type for JSON floating-point numbers (`double` by +default; will be used in @ref number_float_t) +@tparam AllocatorType type of the allocator to use (`std::allocator` by +default) +@tparam JSONSerializer the serializer to resolve internal calls to `to_json()` +and `from_json()` (@ref adl_serializer by default) - case value_t::array: - { - result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator, - last.m_it.array_iterator); - break; - } +@requirement The class satisfies the following concept requirements: +- Basic + - [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible): + JSON values can be default constructed. The result will be a JSON null + value. + - [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible): + A JSON value can be constructed from an rvalue argument. + - [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible): + A JSON value can be copy-constructed from an lvalue expression. + - [MoveAssignable](http://en.cppreference.com/w/cpp/concept/MoveAssignable): + A JSON value van be assigned from an rvalue argument. + - [CopyAssignable](http://en.cppreference.com/w/cpp/concept/CopyAssignable): + A JSON value can be copy-assigned from an lvalue expression. + - [Destructible](http://en.cppreference.com/w/cpp/concept/Destructible): + JSON values can be destructed. +- Layout + - [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType): + JSON values have + [standard layout](http://en.cppreference.com/w/cpp/language/data_members#Standard_layout): + All non-static data members are private and standard layout types, the + class has no virtual functions or (virtual) base classes. +- Library-wide + - [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable): + JSON values can be compared with `==`, see @ref + operator==(const_reference,const_reference). + - [LessThanComparable](http://en.cppreference.com/w/cpp/concept/LessThanComparable): + JSON values can be compared with `<`, see @ref + operator<(const_reference,const_reference). + - [Swappable](http://en.cppreference.com/w/cpp/concept/Swappable): + Any JSON lvalue or rvalue of can be swapped with any lvalue or rvalue of + other compatible types, using unqualified function call @ref swap(). + - [NullablePointer](http://en.cppreference.com/w/cpp/concept/NullablePointer): + JSON values can be compared against `std::nullptr_t` objects which are used + to model the `null` value. +- Container + - [Container](http://en.cppreference.com/w/cpp/concept/Container): + JSON values can be used like STL containers and provide iterator access. + - [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer); + JSON values can be used like STL containers and provide reverse iterator + access. - default: - { - JSON_THROW(type_error::create(307, "cannot use erase() with " + type_name())); - } - } +@invariant The member variables @a m_value and @a m_type have the following +relationship: +- If `m_type == value_t::object`, then `m_value.object != nullptr`. +- If `m_type == value_t::array`, then `m_value.array != nullptr`. +- If `m_type == value_t::string`, then `m_value.string != nullptr`. +The invariants are checked by member function assert_invariant(). - return result; - } +@internal +@note ObjectType trick from http://stackoverflow.com/a/9860911 +@endinternal - /*! - @brief remove element from a JSON object given a key +@see [RFC 7159: The JavaScript Object Notation (JSON) Data Interchange +Format](http://rfc7159.net/rfc7159) - Removes elements from a JSON object with the key value @a key. +@since version 1.0.0 - @param[in] key value of the elements to remove +@nosubgrouping +*/ +NLOHMANN_BASIC_JSON_TPL_DECLARATION +class basic_json +{ + private: + template friend struct detail::external_constructor; + friend ::nlohmann::json_pointer; + friend ::nlohmann::detail::parser; + friend ::nlohmann::detail::serializer; + template + friend class ::nlohmann::detail::iter_impl; + template + friend class ::nlohmann::detail::binary_writer; + template + friend class ::nlohmann::detail::binary_reader; - @return Number of elements removed. If @a ObjectType is the default - `std::map` type, the return value will always be `0` (@a key was not - found) or `1` (@a key was found). + /// workaround type for MSVC + using basic_json_t = NLOHMANN_BASIC_JSON_TPL; - @post References and iterators to the erased elements are invalidated. - Other references and iterators are not affected. + // convenience aliases for types residing in namespace detail; + using lexer = ::nlohmann::detail::lexer; + using parser = ::nlohmann::detail::parser; - @throw type_error.307 when called on a type other than JSON object; - example: `"cannot use erase() with null"` + using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t; + template + using internal_iterator = ::nlohmann::detail::internal_iterator; + template + using iter_impl = ::nlohmann::detail::iter_impl; + template + using iteration_proxy = ::nlohmann::detail::iteration_proxy; + template using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator; - @complexity `log(size()) + count(key)` + template + using output_adapter_t = ::nlohmann::detail::output_adapter_t; - @liveexample{The example shows the effect of `erase()`.,erase__key_type} + using binary_reader = ::nlohmann::detail::binary_reader; + template using binary_writer = ::nlohmann::detail::binary_writer; - @sa @ref erase(IteratorType) -- removes the element at a given position - @sa @ref erase(IteratorType, IteratorType) -- removes the elements in - the given range - @sa @ref erase(const size_type) -- removes the element from an array at - the given index + using serializer = ::nlohmann::detail::serializer; - @since version 1.0.0 - */ - size_type erase(const typename object_t::key_type& key) - { - // this erase only works for objects - if (is_object()) - { - return m_value.object->erase(key); - } + public: + using value_t = detail::value_t; + /// @copydoc nlohmann::json_pointer + using json_pointer = ::nlohmann::json_pointer; + template + using json_serializer = JSONSerializer; + /// helper type for initializer lists of basic_json values + using initializer_list_t = std::initializer_list>; - JSON_THROW(type_error::create(307, "cannot use erase() with " + type_name())); - } + //////////////// + // exceptions // + //////////////// - /*! - @brief remove element from a JSON array given an index + /// @name exceptions + /// Classes to implement user-defined exceptions. + /// @{ - Removes element from a JSON array at the index @a idx. + /// @copydoc detail::exception + using exception = detail::exception; + /// @copydoc detail::parse_error + using parse_error = detail::parse_error; + /// @copydoc detail::invalid_iterator + using invalid_iterator = detail::invalid_iterator; + /// @copydoc detail::type_error + using type_error = detail::type_error; + /// @copydoc detail::out_of_range + using out_of_range = detail::out_of_range; + /// @copydoc detail::other_error + using other_error = detail::other_error; - @param[in] idx index of the element to remove + /// @} - @throw type_error.307 when called on a type other than JSON object; - example: `"cannot use erase() with null"` - @throw out_of_range.401 when `idx >= size()`; example: `"array index 17 - is out of range"` - @complexity Linear in distance between @a idx and the end of the container. + ///////////////////// + // container types // + ///////////////////// - @liveexample{The example shows the effect of `erase()`.,erase__size_type} + /// @name container types + /// The canonic container types to use @ref basic_json like any other STL + /// container. + /// @{ - @sa @ref erase(IteratorType) -- removes the element at a given position - @sa @ref erase(IteratorType, IteratorType) -- removes the elements in - the given range - @sa @ref erase(const typename object_t::key_type&) -- removes the element - from an object at the given key + /// the type of elements in a basic_json container + using value_type = basic_json; - @since version 1.0.0 - */ - void erase(const size_type idx) - { - // this erase only works for arrays - if (is_array()) - { - if (idx >= size()) - { - JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range")); - } + /// the type of an element reference + using reference = value_type&; + /// the type of an element const reference + using const_reference = const value_type&; - m_value.array->erase(m_value.array->begin() + static_cast(idx)); - } - else - { - JSON_THROW(type_error::create(307, "cannot use erase() with " + type_name())); - } - } + /// a type to represent differences between iterators + using difference_type = std::ptrdiff_t; + /// a type to represent container sizes + using size_type = std::size_t; - /// @} + /// the allocator type + using allocator_type = AllocatorType; + /// the type of an element pointer + using pointer = typename std::allocator_traits::pointer; + /// the type of an element const pointer + using const_pointer = typename std::allocator_traits::const_pointer; - //////////// - // lookup // - //////////// + /// an iterator for a basic_json container + using iterator = iter_impl; + /// a const iterator for a basic_json container + using const_iterator = iter_impl; + /// a reverse iterator for a basic_json container + using reverse_iterator = json_reverse_iterator; + /// a const reverse iterator for a basic_json container + using const_reverse_iterator = json_reverse_iterator; + + /// @} - /// @name lookup - /// @{ /*! - @brief find an element in a JSON object + @brief returns the allocator associated with the container + */ + static allocator_type get_allocator() + { + return allocator_type(); + } - Finds an element in a JSON object with key equivalent to @a key. If the - element is not found or the JSON value is not an object, end() is - returned. + /*! + @brief returns version information on the library - @note This method always returns @ref end() when executed on a JSON type - that is not an object. + This function returns a JSON object with information about the library, + including the version number and information on the platform and compiler. - @param[in] key key value of the element to search for + @return JSON object holding version information + key | description + ----------- | --------------- + `compiler` | Information on the used compiler. It is an object with the following keys: `c++` (the used C++ standard), `family` (the compiler family; possible values are `clang`, `icc`, `gcc`, `ilecpp`, `msvc`, `pgcpp`, `sunpro`, and `unknown`), and `version` (the compiler version). + `copyright` | The copyright line for the library as string. + `name` | The name of the library as string. + `platform` | The used platform as string. Possible values are `win32`, `linux`, `apple`, `unix`, and `unknown`. + `url` | The URL of the project as string. + `version` | The version of the library. It is an object with the following keys: `major`, `minor`, and `patch` as defined by [Semantic Versioning](http://semver.org), and `string` (the version string). - @return Iterator to an element with key equivalent to @a key. If no such - element is found or the JSON value is not an object, past-the-end (see - @ref end()) iterator is returned. + @liveexample{The following code shows an example output of the `meta()` + function.,meta} - @complexity Logarithmic in the size of the JSON object. + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. - @liveexample{The example shows how `find()` is used.,find__key_type} + @complexity Constant. - @since version 1.0.0 + @since 2.1.0 */ - iterator find(typename object_t::key_type key) + static basic_json meta() { - auto result = end(); + basic_json result; - if (is_object()) + result["copyright"] = "(C) 2013-2017 Niels Lohmann"; + result["name"] = "JSON for Modern C++"; + result["url"] = "https://github.com/nlohmann/json"; + result["version"] = { - result.m_it.object_iterator = m_value.object->find(key); - } - - return result; - } + {"string", "3.0.0"}, {"major", 3}, {"minor", 0}, {"patch", 0} + }; - /*! - @brief find an element in a JSON object - @copydoc find(typename object_t::key_type) - */ - const_iterator find(typename object_t::key_type key) const - { - auto result = cend(); +#ifdef _WIN32 + result["platform"] = "win32"; +#elif defined __linux__ + result["platform"] = "linux"; +#elif defined __APPLE__ + result["platform"] = "apple"; +#elif defined __unix__ + result["platform"] = "unix"; +#else + result["platform"] = "unknown"; +#endif - if (is_object()) - { - result.m_it.object_iterator = m_value.object->find(key); - } +#if defined(__ICC) || defined(__INTEL_COMPILER) + result["compiler"] = {{"family", "icc"}, {"version", __INTEL_COMPILER}}; +#elif defined(__clang__) + result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}}; +#elif defined(__GNUC__) || defined(__GNUG__) + result["compiler"] = {{"family", "gcc"}, {"version", std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__) + "." + std::to_string(__GNUC_PATCHLEVEL__)}}; +#elif defined(__HP_cc) || defined(__HP_aCC) + result["compiler"] = "hp" +#elif defined(__IBMCPP__) + result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}}; +#elif defined(_MSC_VER) + result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}}; +#elif defined(__PGI) + result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}}; +#elif defined(__SUNPRO_CC) + result["compiler"] = {{"family", "sunpro"}, {"version", __SUNPRO_CC}}; +#else + result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}}; +#endif +#ifdef __cplusplus + result["compiler"]["c++"] = std::to_string(__cplusplus); +#else + result["compiler"]["c++"] = "unknown"; +#endif return result; } - /*! - @brief returns the number of occurrences of a key in a JSON object - Returns the number of elements with key @a key. If ObjectType is the - default `std::map` type, the return value will always be `0` (@a key was - not found) or `1` (@a key was found). + /////////////////////////// + // JSON value data types // + /////////////////////////// - @note This method always returns `0` when executed on a JSON type that is - not an object. + /// @name JSON value data types + /// The data types to store a JSON value. These types are derived from + /// the template arguments passed to class @ref basic_json. + /// @{ - @param[in] key key value of the element to count +#if defined(JSON_HAS_CPP_14) + // Use transparent comparator if possible, combined with perfect forwarding + // on find() and count() calls prevents unnecessary string construction. + using object_comparator_t = std::less<>; +#else + using object_comparator_t = std::less; +#endif - @return Number of elements with key @a key. If the JSON value is not an - object, the return value will be `0`. + /*! + @brief a type for an object - @complexity Logarithmic in the size of the JSON object. + [RFC 7159](http://rfc7159.net/rfc7159) describes JSON objects as follows: + > An object is an unordered collection of zero or more name/value pairs, + > where a name is a string and a value is a string, number, boolean, null, + > object, or array. - @liveexample{The example shows how `count()` is used.,count} + To store objects in C++, a type is defined by the template parameters + described below. - @since version 1.0.0 - */ - size_type count(typename object_t::key_type key) const - { - // return 0 for all nonobject types - return is_object() ? m_value.object->count(key) : 0; - } + @tparam ObjectType the container to store objects (e.g., `std::map` or + `std::unordered_map`) + @tparam StringType the type of the keys or names (e.g., `std::string`). + The comparison function `std::less` is used to order elements + inside the container. + @tparam AllocatorType the allocator to use for objects (e.g., + `std::allocator`) - /// @} + #### Default type + With the default values for @a ObjectType (`std::map`), @a StringType + (`std::string`), and @a AllocatorType (`std::allocator`), the default + value for @a object_t is: - /////////////// - // iterators // - /////////////// + @code {.cpp} + std::map< + std::string, // key_type + basic_json, // value_type + std::less, // key_compare + std::allocator> // allocator_type + > + @endcode - /// @name iterators - /// @{ + #### Behavior - /*! - @brief returns an iterator to the first element + The choice of @a object_t influences the behavior of the JSON class. With + the default type, objects have the following behavior: - Returns an iterator to the first element. + - When all names are unique, objects will be interoperable in the sense + that all software implementations receiving that object will agree on + the name-value mappings. + - When the names within an object are not unique, later stored name/value + pairs overwrite previously stored name/value pairs, leaving the used + names unique. For instance, `{"key": 1}` and `{"key": 2, "key": 1}` will + be treated as equal and both stored as `{"key": 1}`. + - Internally, name/value pairs are stored in lexicographical order of the + names. Objects will also be serialized (see @ref dump) in this order. + For instance, `{"b": 1, "a": 2}` and `{"a": 2, "b": 1}` will be stored + and serialized as `{"a": 2, "b": 1}`. + - When comparing objects, the order of the name/value pairs is irrelevant. + This makes objects interoperable in the sense that they will not be + affected by these differences. For instance, `{"b": 1, "a": 2}` and + `{"a": 2, "b": 1}` will be treated as equal. - @image html range-begin-end.svg "Illustration from cppreference.com" + #### Limits - @return iterator to the first element + [RFC 7159](http://rfc7159.net/rfc7159) specifies: + > An implementation may set limits on the maximum depth of nesting. - @complexity Constant. + In this class, the object's limit of nesting is not explicitly constrained. + However, a maximum depth of nesting may be introduced by the compiler or + runtime environment. A theoretical limit can be queried by calling the + @ref max_size function of a JSON object. - @requirement This function helps `basic_json` satisfying the - [Container](http://en.cppreference.com/w/cpp/concept/Container) - requirements: - - The complexity is constant. + #### Storage - @liveexample{The following code shows an example for `begin()`.,begin} + Objects are stored as pointers in a @ref basic_json type. That is, for any + access to object values, a pointer of type `object_t*` must be + dereferenced. - @sa @ref cbegin() -- returns a const iterator to the beginning - @sa @ref end() -- returns an iterator to the end - @sa @ref cend() -- returns a const iterator to the end + @sa @ref array_t -- type for an array value @since version 1.0.0 + + @note The order name/value pairs are added to the object is *not* + preserved by the library. Therefore, iterating an object may return + name/value pairs in a different order than they were originally stored. In + fact, keys will be traversed in alphabetical order as `std::map` with + `std::less` is used by default. Please note this behavior conforms to [RFC + 7159](http://rfc7159.net/rfc7159), because any order implements the + specified "unordered" nature of JSON objects. */ - iterator begin() noexcept - { - iterator result(this); - result.set_begin(); - return result; - } + using object_t = ObjectType>>; /*! - @copydoc basic_json::cbegin() - */ - const_iterator begin() const noexcept - { - return cbegin(); - } + @brief a type for an array - /*! - @brief returns a const iterator to the first element + [RFC 7159](http://rfc7159.net/rfc7159) describes JSON arrays as follows: + > An array is an ordered sequence of zero or more values. - Returns a const iterator to the first element. + To store objects in C++, a type is defined by the template parameters + explained below. - @image html range-begin-end.svg "Illustration from cppreference.com" + @tparam ArrayType container type to store arrays (e.g., `std::vector` or + `std::list`) + @tparam AllocatorType allocator to use for arrays (e.g., `std::allocator`) - @return const iterator to the first element + #### Default type - @complexity Constant. + With the default values for @a ArrayType (`std::vector`) and @a + AllocatorType (`std::allocator`), the default value for @a array_t is: - @requirement This function helps `basic_json` satisfying the - [Container](http://en.cppreference.com/w/cpp/concept/Container) - requirements: - - The complexity is constant. - - Has the semantics of `const_cast(*this).begin()`. + @code {.cpp} + std::vector< + basic_json, // value_type + std::allocator // allocator_type + > + @endcode - @liveexample{The following code shows an example for `cbegin()`.,cbegin} + #### Limits - @sa @ref begin() -- returns an iterator to the beginning - @sa @ref end() -- returns an iterator to the end - @sa @ref cend() -- returns a const iterator to the end + [RFC 7159](http://rfc7159.net/rfc7159) specifies: + > An implementation may set limits on the maximum depth of nesting. + + In this class, the array's limit of nesting is not explicitly constrained. + However, a maximum depth of nesting may be introduced by the compiler or + runtime environment. A theoretical limit can be queried by calling the + @ref max_size function of a JSON array. + + #### Storage + + Arrays are stored as pointers in a @ref basic_json type. That is, for any + access to array values, a pointer of type `array_t*` must be dereferenced. + + @sa @ref object_t -- type for an object value @since version 1.0.0 */ - const_iterator cbegin() const noexcept - { - const_iterator result(this); - result.set_begin(); - return result; - } + using array_t = ArrayType>; /*! - @brief returns an iterator to one past the last element + @brief a type for a string - Returns an iterator to one past the last element. + [RFC 7159](http://rfc7159.net/rfc7159) describes JSON strings as follows: + > A string is a sequence of zero or more Unicode characters. - @image html range-begin-end.svg "Illustration from cppreference.com" + To store objects in C++, a type is defined by the template parameter + described below. Unicode values are split by the JSON class into + byte-sized characters during deserialization. - @return iterator one past the last element + @tparam StringType the container to store strings (e.g., `std::string`). + Note this container is used for keys/names in objects, see @ref object_t. - @complexity Constant. + #### Default type - @requirement This function helps `basic_json` satisfying the - [Container](http://en.cppreference.com/w/cpp/concept/Container) - requirements: - - The complexity is constant. + With the default values for @a StringType (`std::string`), the default + value for @a string_t is: - @liveexample{The following code shows an example for `end()`.,end} + @code {.cpp} + std::string + @endcode - @sa @ref cend() -- returns a const iterator to the end - @sa @ref begin() -- returns an iterator to the beginning - @sa @ref cbegin() -- returns a const iterator to the beginning + #### Encoding - @since version 1.0.0 - */ - iterator end() noexcept - { - iterator result(this); - result.set_end(); - return result; - } + Strings are stored in UTF-8 encoding. Therefore, functions like + `std::string::size()` or `std::string::length()` return the number of + bytes in the string rather than the number of characters or glyphs. - /*! - @copydoc basic_json::cend() + #### String comparison + + [RFC 7159](http://rfc7159.net/rfc7159) states: + > Software implementations are typically required to test names of object + > members for equality. Implementations that transform the textual + > representation into sequences of Unicode code units and then perform the + > comparison numerically, code unit by code unit, are interoperable in the + > sense that implementations will agree in all cases on equality or + > inequality of two strings. For example, implementations that compare + > strings with escaped characters unconverted may incorrectly find that + > `"a\\b"` and `"a\u005Cb"` are not equal. + + This implementation is interoperable as it does compare strings code unit + by code unit. + + #### Storage + + String values are stored as pointers in a @ref basic_json type. That is, + for any access to string values, a pointer of type `string_t*` must be + dereferenced. + + @since version 1.0.0 */ - const_iterator end() const noexcept - { - return cend(); - } + using string_t = StringType; /*! - @brief returns a const iterator to one past the last element + @brief a type for a boolean - Returns a const iterator to one past the last element. + [RFC 7159](http://rfc7159.net/rfc7159) implicitly describes a boolean as a + type which differentiates the two literals `true` and `false`. - @image html range-begin-end.svg "Illustration from cppreference.com" + To store objects in C++, a type is defined by the template parameter @a + BooleanType which chooses the type to use. - @return const iterator one past the last element + #### Default type - @complexity Constant. + With the default values for @a BooleanType (`bool`), the default value for + @a boolean_t is: - @requirement This function helps `basic_json` satisfying the - [Container](http://en.cppreference.com/w/cpp/concept/Container) - requirements: - - The complexity is constant. - - Has the semantics of `const_cast(*this).end()`. + @code {.cpp} + bool + @endcode - @liveexample{The following code shows an example for `cend()`.,cend} + #### Storage - @sa @ref end() -- returns an iterator to the end - @sa @ref begin() -- returns an iterator to the beginning - @sa @ref cbegin() -- returns a const iterator to the beginning + Boolean values are stored directly inside a @ref basic_json type. @since version 1.0.0 */ - const_iterator cend() const noexcept - { - const_iterator result(this); - result.set_end(); - return result; - } + using boolean_t = BooleanType; /*! - @brief returns an iterator to the reverse-beginning + @brief a type for a number (integer) - Returns an iterator to the reverse-beginning; that is, the last element. + [RFC 7159](http://rfc7159.net/rfc7159) describes numbers as follows: + > The representation of numbers is similar to that used in most + > programming languages. A number is represented in base 10 using decimal + > digits. It contains an integer component that may be prefixed with an + > optional minus sign, which may be followed by a fraction part and/or an + > exponent part. Leading zeros are not allowed. (...) Numeric values that + > cannot be represented in the grammar below (such as Infinity and NaN) + > are not permitted. - @image html range-rbegin-rend.svg "Illustration from cppreference.com" + This description includes both integer and floating-point numbers. + However, C++ allows more precise storage if it is known whether the number + is a signed integer, an unsigned integer or a floating-point number. + Therefore, three different types, @ref number_integer_t, @ref + number_unsigned_t and @ref number_float_t are used. - @complexity Constant. + To store integer numbers in C++, a type is defined by the template + parameter @a NumberIntegerType which chooses the type to use. - @requirement This function helps `basic_json` satisfying the - [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) - requirements: - - The complexity is constant. - - Has the semantics of `reverse_iterator(end())`. + #### Default type - @liveexample{The following code shows an example for `rbegin()`.,rbegin} + With the default values for @a NumberIntegerType (`int64_t`), the default + value for @a number_integer_t is: - @sa @ref crbegin() -- returns a const reverse iterator to the beginning - @sa @ref rend() -- returns a reverse iterator to the end - @sa @ref crend() -- returns a const reverse iterator to the end + @code {.cpp} + int64_t + @endcode - @since version 1.0.0 - */ - reverse_iterator rbegin() noexcept - { - return reverse_iterator(end()); - } + #### Default behavior - /*! - @copydoc basic_json::crbegin() - */ - const_reverse_iterator rbegin() const noexcept - { - return crbegin(); - } + - The restrictions about leading zeros is not enforced in C++. Instead, + leading zeros in integer literals lead to an interpretation as octal + number. Internally, the value will be stored as decimal number. For + instance, the C++ integer literal `010` will be serialized to `8`. + During deserialization, leading zeros yield an error. + - Not-a-number (NaN) values will be serialized to `null`. - /*! - @brief returns an iterator to the reverse-end + #### Limits - Returns an iterator to the reverse-end; that is, one before the first - element. + [RFC 7159](http://rfc7159.net/rfc7159) specifies: + > An implementation may set limits on the range and precision of numbers. - @image html range-rbegin-rend.svg "Illustration from cppreference.com" + When the default type is used, the maximal integer number that can be + stored is `9223372036854775807` (INT64_MAX) and the minimal integer number + that can be stored is `-9223372036854775808` (INT64_MIN). Integer numbers + that are out of range will yield over/underflow when used in a + constructor. During deserialization, too large or small integer numbers + will be automatically be stored as @ref number_unsigned_t or @ref + number_float_t. - @complexity Constant. + [RFC 7159](http://rfc7159.net/rfc7159) further states: + > Note that when such software is used, numbers that are integers and are + > in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense + > that implementations will agree exactly on their numeric values. - @requirement This function helps `basic_json` satisfying the - [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) - requirements: - - The complexity is constant. - - Has the semantics of `reverse_iterator(begin())`. + As this range is a subrange of the exactly supported range [INT64_MIN, + INT64_MAX], this class's integer type is interoperable. - @liveexample{The following code shows an example for `rend()`.,rend} + #### Storage - @sa @ref crend() -- returns a const reverse iterator to the end - @sa @ref rbegin() -- returns a reverse iterator to the beginning - @sa @ref crbegin() -- returns a const reverse iterator to the beginning + Integer number values are stored directly inside a @ref basic_json type. + + @sa @ref number_float_t -- type for number values (floating-point) + + @sa @ref number_unsigned_t -- type for number values (unsigned integer) @since version 1.0.0 */ - reverse_iterator rend() noexcept - { - return reverse_iterator(begin()); - } + using number_integer_t = NumberIntegerType; /*! - @copydoc basic_json::crend() - */ - const_reverse_iterator rend() const noexcept - { - return crend(); - } + @brief a type for a number (unsigned) - /*! - @brief returns a const reverse iterator to the last element + [RFC 7159](http://rfc7159.net/rfc7159) describes numbers as follows: + > The representation of numbers is similar to that used in most + > programming languages. A number is represented in base 10 using decimal + > digits. It contains an integer component that may be prefixed with an + > optional minus sign, which may be followed by a fraction part and/or an + > exponent part. Leading zeros are not allowed. (...) Numeric values that + > cannot be represented in the grammar below (such as Infinity and NaN) + > are not permitted. - Returns a const iterator to the reverse-beginning; that is, the last - element. + This description includes both integer and floating-point numbers. + However, C++ allows more precise storage if it is known whether the number + is a signed integer, an unsigned integer or a floating-point number. + Therefore, three different types, @ref number_integer_t, @ref + number_unsigned_t and @ref number_float_t are used. - @image html range-rbegin-rend.svg "Illustration from cppreference.com" + To store unsigned integer numbers in C++, a type is defined by the + template parameter @a NumberUnsignedType which chooses the type to use. - @complexity Constant. + #### Default type - @requirement This function helps `basic_json` satisfying the - [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) - requirements: - - The complexity is constant. - - Has the semantics of `const_cast(*this).rbegin()`. + With the default values for @a NumberUnsignedType (`uint64_t`), the + default value for @a number_unsigned_t is: - @liveexample{The following code shows an example for `crbegin()`.,crbegin} + @code {.cpp} + uint64_t + @endcode - @sa @ref rbegin() -- returns a reverse iterator to the beginning - @sa @ref rend() -- returns a reverse iterator to the end - @sa @ref crend() -- returns a const reverse iterator to the end + #### Default behavior - @since version 1.0.0 - */ - const_reverse_iterator crbegin() const noexcept - { - return const_reverse_iterator(cend()); - } + - The restrictions about leading zeros is not enforced in C++. Instead, + leading zeros in integer literals lead to an interpretation as octal + number. Internally, the value will be stored as decimal number. For + instance, the C++ integer literal `010` will be serialized to `8`. + During deserialization, leading zeros yield an error. + - Not-a-number (NaN) values will be serialized to `null`. - /*! - @brief returns a const reverse iterator to one before the first + #### Limits - Returns a const reverse iterator to the reverse-end; that is, one before - the first element. + [RFC 7159](http://rfc7159.net/rfc7159) specifies: + > An implementation may set limits on the range and precision of numbers. - @image html range-rbegin-rend.svg "Illustration from cppreference.com" + When the default type is used, the maximal integer number that can be + stored is `18446744073709551615` (UINT64_MAX) and the minimal integer + number that can be stored is `0`. Integer numbers that are out of range + will yield over/underflow when used in a constructor. During + deserialization, too large or small integer numbers will be automatically + be stored as @ref number_integer_t or @ref number_float_t. - @complexity Constant. + [RFC 7159](http://rfc7159.net/rfc7159) further states: + > Note that when such software is used, numbers that are integers and are + > in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense + > that implementations will agree exactly on their numeric values. - @requirement This function helps `basic_json` satisfying the - [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) - requirements: - - The complexity is constant. - - Has the semantics of `const_cast(*this).rend()`. + As this range is a subrange (when considered in conjunction with the + number_integer_t type) of the exactly supported range [0, UINT64_MAX], + this class's integer type is interoperable. - @liveexample{The following code shows an example for `crend()`.,crend} + #### Storage - @sa @ref rend() -- returns a reverse iterator to the end - @sa @ref rbegin() -- returns a reverse iterator to the beginning - @sa @ref crbegin() -- returns a const reverse iterator to the beginning + Integer number values are stored directly inside a @ref basic_json type. - @since version 1.0.0 - */ - const_reverse_iterator crend() const noexcept - { - return const_reverse_iterator(cbegin()); - } + @sa @ref number_float_t -- type for number values (floating-point) + @sa @ref number_integer_t -- type for number values (integer) - private: - // forward declaration - template class iteration_proxy; + @since version 2.0.0 + */ + using number_unsigned_t = NumberUnsignedType; - public: /*! - @brief wrapper to access iterator member functions in range-based for + @brief a type for a number (floating-point) - This function allows to access @ref iterator::key() and @ref - iterator::value() during range-based for loops. In these loops, a - reference to the JSON values is returned, so there is no access to the - underlying iterator. + [RFC 7159](http://rfc7159.net/rfc7159) describes numbers as follows: + > The representation of numbers is similar to that used in most + > programming languages. A number is represented in base 10 using decimal + > digits. It contains an integer component that may be prefixed with an + > optional minus sign, which may be followed by a fraction part and/or an + > exponent part. Leading zeros are not allowed. (...) Numeric values that + > cannot be represented in the grammar below (such as Infinity and NaN) + > are not permitted. - @note The name of this function is not yet final and may change in the - future. - */ - static iteration_proxy iterator_wrapper(reference cont) - { - return iteration_proxy(cont); - } + This description includes both integer and floating-point numbers. + However, C++ allows more precise storage if it is known whether the number + is a signed integer, an unsigned integer or a floating-point number. + Therefore, three different types, @ref number_integer_t, @ref + number_unsigned_t and @ref number_float_t are used. - /*! - @copydoc iterator_wrapper(reference) - */ - static iteration_proxy iterator_wrapper(const_reference cont) - { - return iteration_proxy(cont); - } + To store floating-point numbers in C++, a type is defined by the template + parameter @a NumberFloatType which chooses the type to use. - /// @} + #### Default type + With the default values for @a NumberFloatType (`double`), the default + value for @a number_float_t is: - ////////////// - // capacity // - ////////////// + @code {.cpp} + double + @endcode - /// @name capacity - /// @{ + #### Default behavior - /*! - @brief checks whether the container is empty + - The restrictions about leading zeros is not enforced in C++. Instead, + leading zeros in floating-point literals will be ignored. Internally, + the value will be stored as decimal number. For instance, the C++ + floating-point literal `01.2` will be serialized to `1.2`. During + deserialization, leading zeros yield an error. + - Not-a-number (NaN) values will be serialized to `null`. - Checks if a JSON value has no elements. + #### Limits - @return The return value depends on the different types and is - defined as follows: - Value type | return value - ----------- | ------------- - null | `true` - boolean | `false` - string | `false` - number | `false` - object | result of function `object_t::empty()` - array | result of function `array_t::empty()` + [RFC 7159](http://rfc7159.net/rfc7159) states: + > This specification allows implementations to set limits on the range and + > precision of numbers accepted. Since software that implements IEEE + > 754-2008 binary64 (double precision) numbers is generally available and + > widely used, good interoperability can be achieved by implementations + > that expect no more precision or range than these provide, in the sense + > that implementations will approximate JSON numbers within the expected + > precision. - @note This function does not return whether a string stored as JSON value - is empty - it returns whether the JSON container itself is empty which is - false in the case of a string. + This implementation does exactly follow this approach, as it uses double + precision floating-point numbers. Note values smaller than + `-1.79769313486232e+308` and values greater than `1.79769313486232e+308` + will be stored as NaN internally and be serialized to `null`. - @complexity Constant, as long as @ref array_t and @ref object_t satisfy - the Container concept; that is, their `empty()` functions have constant - complexity. + #### Storage - @requirement This function helps `basic_json` satisfying the - [Container](http://en.cppreference.com/w/cpp/concept/Container) - requirements: - - The complexity is constant. - - Has the semantics of `begin() == end()`. + Floating-point number values are stored directly inside a @ref basic_json + type. - @liveexample{The following code uses `empty()` to check if a JSON - object contains any elements.,empty} + @sa @ref number_integer_t -- type for number values (integer) - @sa @ref size() -- returns the number of elements + @sa @ref number_unsigned_t -- type for number values (unsigned integer) @since version 1.0.0 */ - bool empty() const noexcept - { - switch (m_type) - { - case value_t::null: - { - // null values are empty - return true; - } + using number_float_t = NumberFloatType; - case value_t::array: - { - // delegate call to array_t::empty() - return m_value.array->empty(); - } + /// @} - case value_t::object: - { - // delegate call to object_t::empty() - return m_value.object->empty(); - } + private: - default: - { - // all other types are nonempty - return false; - } - } - } + /// helper for exception-safe object creation + template + static T* create(Args&& ... args) + { + AllocatorType alloc; + using AllocatorTraits = std::allocator_traits>; - /*! - @brief returns the number of elements + auto deleter = [&](T * object) + { + AllocatorTraits::deallocate(alloc, object, 1); + }; + std::unique_ptr object(AllocatorTraits::allocate(alloc, 1), deleter); + AllocatorTraits::construct(alloc, object.get(), std::forward(args)...); + assert(object != nullptr); + return object.release(); + } - Returns the number of elements in a JSON value. + //////////////////////// + // JSON value storage // + //////////////////////// - @return The return value depends on the different types and is - defined as follows: - Value type | return value - ----------- | ------------- - null | `0` - boolean | `1` - string | `1` - number | `1` - object | result of function object_t::size() - array | result of function array_t::size() + /*! + @brief a JSON value - @note This function does not return the length of a string stored as JSON - value - it returns the number of elements in the JSON value which is 1 in - the case of a string. + The actual storage for a JSON value of the @ref basic_json class. This + union combines the different storage types for the JSON value types + defined in @ref value_t. - @complexity Constant, as long as @ref array_t and @ref object_t satisfy - the Container concept; that is, their size() functions have constant - complexity. - - @requirement This function helps `basic_json` satisfying the - [Container](http://en.cppreference.com/w/cpp/concept/Container) - requirements: - - The complexity is constant. - - Has the semantics of `std::distance(begin(), end())`. - - @liveexample{The following code calls `size()` on the different value - types.,size} + JSON type | value_t type | used type + --------- | --------------- | ------------------------ + object | object | pointer to @ref object_t + array | array | pointer to @ref array_t + string | string | pointer to @ref string_t + boolean | boolean | @ref boolean_t + number | number_integer | @ref number_integer_t + number | number_unsigned | @ref number_unsigned_t + number | number_float | @ref number_float_t + null | null | *no value is stored* - @sa @ref empty() -- checks whether the container is empty - @sa @ref max_size() -- returns the maximal number of elements + @note Variable-length types (objects, arrays, and strings) are stored as + pointers. The size of the union should not exceed 64 bits if the default + value types are used. @since version 1.0.0 */ - size_type size() const noexcept + union json_value { - switch (m_type) + /// object (stored with pointer to save storage) + object_t* object; + /// array (stored with pointer to save storage) + array_t* array; + /// string (stored with pointer to save storage) + string_t* string; + /// boolean + boolean_t boolean; + /// number (integer) + number_integer_t number_integer; + /// number (unsigned integer) + number_unsigned_t number_unsigned; + /// number (floating-point) + number_float_t number_float; + + /// default constructor (for null values) + json_value() = default; + /// constructor for booleans + json_value(boolean_t v) noexcept : boolean(v) {} + /// constructor for numbers (integer) + json_value(number_integer_t v) noexcept : number_integer(v) {} + /// constructor for numbers (unsigned) + json_value(number_unsigned_t v) noexcept : number_unsigned(v) {} + /// constructor for numbers (floating-point) + json_value(number_float_t v) noexcept : number_float(v) {} + /// constructor for empty values of a given type + json_value(value_t t) { - case value_t::null: + switch (t) { - // null values are empty - return 0; - } + case value_t::object: + { + object = create(); + break; + } - case value_t::array: - { - // delegate call to array_t::size() - return m_value.array->size(); - } + case value_t::array: + { + array = create(); + break; + } - case value_t::object: - { - // delegate call to object_t::size() - return m_value.object->size(); - } + case value_t::string: + { + string = create(""); + break; + } - default: - { - // all other types have size 1 - return 1; + case value_t::boolean: + { + boolean = boolean_t(false); + break; + } + + case value_t::number_integer: + { + number_integer = number_integer_t(0); + break; + } + + case value_t::number_unsigned: + { + number_unsigned = number_unsigned_t(0); + break; + } + + case value_t::number_float: + { + number_float = number_float_t(0.0); + break; + } + + case value_t::null: + { + object = nullptr; // silence warning, see #821 + break; + } + + default: + { + object = nullptr; // silence warning, see #821 + if (JSON_UNLIKELY(t == value_t::null)) + { + JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.0.0")); // LCOV_EXCL_LINE + } + break; + } } } - } - - /*! - @brief returns the maximum possible number of elements - Returns the maximum number of elements a JSON value is able to hold due to - system or library implementation limitations, i.e. `std::distance(begin(), - end())` for the JSON value. + /// constructor for strings + json_value(const string_t& value) + { + string = create(value); + } - @return The return value depends on the different types and is - defined as follows: - Value type | return value - ----------- | ------------- - null | `0` (same as `size()`) - boolean | `1` (same as `size()`) - string | `1` (same as `size()`) - number | `1` (same as `size()`) - object | result of function `object_t::max_size()` - array | result of function `array_t::max_size()` + /// constructor for rvalue strings + json_value(string_t&& value) + { + string = create(std::move(value)); + } - @complexity Constant, as long as @ref array_t and @ref object_t satisfy - the Container concept; that is, their `max_size()` functions have constant - complexity. + /// constructor for objects + json_value(const object_t& value) + { + object = create(value); + } - @requirement This function helps `basic_json` satisfying the - [Container](http://en.cppreference.com/w/cpp/concept/Container) - requirements: - - The complexity is constant. - - Has the semantics of returning `b.size()` where `b` is the largest - possible JSON value. + /// constructor for rvalue objects + json_value(object_t&& value) + { + object = create(std::move(value)); + } - @liveexample{The following code calls `max_size()` on the different value - types. Note the output is implementation specific.,max_size} + /// constructor for arrays + json_value(const array_t& value) + { + array = create(value); + } - @sa @ref size() -- returns the number of elements + /// constructor for rvalue arrays + json_value(array_t&& value) + { + array = create(std::move(value)); + } - @since version 1.0.0 - */ - size_type max_size() const noexcept - { - switch (m_type) + void destroy(value_t t) { - case value_t::array: + switch (t) { - // delegate call to array_t::max_size() - return m_value.array->max_size(); - } + case value_t::object: + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, object); + std::allocator_traits::deallocate(alloc, object, 1); + break; + } - case value_t::object: - { - // delegate call to object_t::max_size() - return m_value.object->max_size(); - } + case value_t::array: + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, array); + std::allocator_traits::deallocate(alloc, array, 1); + break; + } - default: - { - // all other types have max_size() == size() - return size(); + case value_t::string: + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, string); + std::allocator_traits::deallocate(alloc, string, 1); + break; + } + + default: + { + break; + } } } - } - - /// @} + }; + /*! + @brief checks the class invariants - /////////////// - // modifiers // - /////////////// + This function asserts the class invariants. It needs to be called at the + end of every constructor to make sure that created objects respect the + invariant. Furthermore, it has to be called each time the type of a JSON + value is changed, because the invariant expresses a relationship between + @a m_type and @a m_value. + */ + void assert_invariant() const + { + assert(m_type != value_t::object or m_value.object != nullptr); + assert(m_type != value_t::array or m_value.array != nullptr); + assert(m_type != value_t::string or m_value.string != nullptr); + } - /// @name modifiers - /// @{ + public: + ////////////////////////// + // JSON parser callback // + ////////////////////////// /*! - @brief clears the contents - - Clears the content of a JSON value and resets it to the default value as - if @ref basic_json(value_t) would have been called: + @brief parser event types - Value type | initial value - ----------- | ------------- - null | `null` - boolean | `false` - string | `""` - number | `0` - object | `{}` - array | `[]` + The parser callback distinguishes the following events: + - `object_start`: the parser read `{` and started to process a JSON object + - `key`: the parser read a key of a value in an object + - `object_end`: the parser read `}` and finished processing a JSON object + - `array_start`: the parser read `[` and started to process a JSON array + - `array_end`: the parser read `]` and finished processing a JSON array + - `value`: the parser finished reading a JSON value - @complexity Linear in the size of the JSON value. + @image html callback_events.png "Example when certain parse events are triggered" - @liveexample{The example below shows the effect of `clear()` to different - JSON types.,clear} + @sa @ref parser_callback_t for more information and examples + */ + using parse_event_t = typename parser::parse_event_t; - @since version 1.0.0 - */ - void clear() noexcept - { - switch (m_type) - { - case value_t::number_integer: - { - m_value.number_integer = 0; - break; - } - - case value_t::number_unsigned: - { - m_value.number_unsigned = 0; - break; - } - - case value_t::number_float: - { - m_value.number_float = 0.0; - break; - } + /*! + @brief per-element parser callback type - case value_t::boolean: - { - m_value.boolean = false; - break; - } + With a parser callback function, the result of parsing a JSON text can be + influenced. When passed to @ref parse, it is called on certain events + (passed as @ref parse_event_t via parameter @a event) with a set recursion + depth @a depth and context JSON value @a parsed. The return value of the + callback function is a boolean indicating whether the element that emitted + the callback shall be kept or not. - case value_t::string: - { - m_value.string->clear(); - break; - } + We distinguish six scenarios (determined by the event type) in which the + callback function can be called. The following table describes the values + of the parameters @a depth, @a event, and @a parsed. - case value_t::array: - { - m_value.array->clear(); - break; - } + parameter @a event | description | parameter @a depth | parameter @a parsed + ------------------ | ----------- | ------------------ | ------------------- + parse_event_t::object_start | the parser read `{` and started to process a JSON object | depth of the parent of the JSON object | a JSON value with type discarded + parse_event_t::key | the parser read a key of a value in an object | depth of the currently parsed JSON object | a JSON string containing the key + parse_event_t::object_end | the parser read `}` and finished processing a JSON object | depth of the parent of the JSON object | the parsed JSON object + parse_event_t::array_start | the parser read `[` and started to process a JSON array | depth of the parent of the JSON array | a JSON value with type discarded + parse_event_t::array_end | the parser read `]` and finished processing a JSON array | depth of the parent of the JSON array | the parsed JSON array + parse_event_t::value | the parser finished reading a JSON value | depth of the value | the parsed JSON value - case value_t::object: - { - m_value.object->clear(); - break; - } + @image html callback_events.png "Example when certain parse events are triggered" - default: - { - break; - } - } - } + Discarding a value (i.e., returning `false`) has different effects + depending on the context in which function was called: - /*! - @brief add an object to an array + - Discarded values in structured types are skipped. That is, the parser + will behave as if the discarded value was never read. + - In case a value outside a structured type is skipped, it is replaced + with `null`. This case happens if the top-level element is skipped. - Appends the given element @a val to the end of the JSON value. If the - function is called on a JSON null value, an empty array is created before - appending @a val. + @param[in] depth the depth of the recursion during parsing - @param[in] val the value to add to the JSON array + @param[in] event an event of type parse_event_t indicating the context in + the callback function has been called - @throw type_error.308 when called on a type other than JSON array or - null; example: `"cannot use push_back() with number"` + @param[in,out] parsed the current intermediate parse result; note that + writing to this value has no effect for parse_event_t::key events - @complexity Amortized constant. + @return Whether the JSON value which called the function during parsing + should be kept (`true`) or not (`false`). In the latter case, it is either + skipped completely or replaced by an empty discarded object. - @liveexample{The example shows how `push_back()` and `+=` can be used to - add elements to a JSON array. Note how the `null` value was silently - converted to a JSON array.,push_back} + @sa @ref parse for examples @since version 1.0.0 */ - void push_back(basic_json&& val) - { - // push_back only works for null objects or arrays - if (not(is_null() or is_array())) - { - JSON_THROW(type_error::create(308, "cannot use push_back() with " + type_name())); - } + using parser_callback_t = typename parser::parser_callback_t; - // transform null object into an array - if (is_null()) - { - m_type = value_t::array; - m_value = value_t::array; - assert_invariant(); - } - // add element to array (move semantics) - m_value.array->push_back(std::move(val)); - // invalidate object - val.m_type = value_t::null; - } + ////////////////// + // constructors // + ////////////////// - /*! - @brief add an object to an array - @copydoc push_back(basic_json&&) - */ - reference operator+=(basic_json&& val) - { - push_back(std::move(val)); - return *this; - } + /// @name constructors and destructors + /// Constructors of class @ref basic_json, copy/move constructor, copy + /// assignment, static functions creating objects, and the destructor. + /// @{ /*! - @brief add an object to an array - @copydoc push_back(basic_json&&) - */ - void push_back(const basic_json& val) - { - // push_back only works for null objects or arrays - if (not(is_null() or is_array())) - { - JSON_THROW(type_error::create(308, "cannot use push_back() with " + type_name())); - } - - // transform null object into an array - if (is_null()) - { - m_type = value_t::array; - m_value = value_t::array; - assert_invariant(); - } - - // add element to array - m_value.array->push_back(val); - } + @brief create an empty value with a given type - /*! - @brief add an object to an array - @copydoc push_back(basic_json&&) - */ - reference operator+=(const basic_json& val) - { - push_back(val); - return *this; - } + Create an empty JSON value with a given type. The value will be default + initialized with an empty value which depends on the type: - /*! - @brief add an object to an object + Value type | initial value + ----------- | ------------- + null | `null` + boolean | `false` + string | `""` + number | `0` + object | `{}` + array | `[]` - Inserts the given element @a val to the JSON object. If the function is - called on a JSON null value, an empty object is created before inserting - @a val. + @param[in] v the type of the value to create - @param[in] val the value to add to the JSON object + @complexity Constant. - @throw type_error.308 when called on a type other than JSON object or - null; example: `"cannot use push_back() with number"` + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. - @complexity Logarithmic in the size of the container, O(log(`size()`)). + @liveexample{The following code shows the constructor for different @ref + value_t values,basic_json__value_t} - @liveexample{The example shows how `push_back()` and `+=` can be used to - add elements to a JSON object. Note how the `null` value was silently - converted to a JSON object.,push_back__object_t__value} + @sa @ref clear() -- restores the postcondition of this constructor @since version 1.0.0 */ - void push_back(const typename object_t::value_type& val) - { - // push_back only works for null objects or objects - if (not(is_null() or is_object())) - { - JSON_THROW(type_error::create(308, "cannot use push_back() with " + type_name())); - } - - // transform null object into an object - if (is_null()) - { - m_type = value_t::object; - m_value = value_t::object; - assert_invariant(); - } - - // add element to array - m_value.object->insert(val); - } - - /*! - @brief add an object to an object - @copydoc push_back(const typename object_t::value_type&) - */ - reference operator+=(const typename object_t::value_type& val) + basic_json(const value_t v) + : m_type(v), m_value(v) { - push_back(val); - return *this; + assert_invariant(); } /*! - @brief add an object to an object - - This function allows to use `push_back` with an initializer list. In case - - 1. the current value is an object, - 2. the initializer list @a init contains only two elements, and - 3. the first element of @a init is a string, + @brief create a null object - @a init is converted into an object element and added using - @ref push_back(const typename object_t::value_type&). Otherwise, @a init - is converted to a JSON value and added using @ref push_back(basic_json&&). + Create a `null` JSON value. It either takes a null pointer as parameter + (explicitly creating `null`) or no parameter (implicitly creating `null`). + The passed null pointer itself is not read -- it is only used to choose + the right constructor. - @param[in] init an initializer list + @complexity Constant. - @complexity Linear in the size of the initializer list @a init. + @exceptionsafety No-throw guarantee: this constructor never throws + exceptions. - @note This function is required to resolve an ambiguous overload error, - because pairs like `{"key", "value"}` can be both interpreted as - `object_t::value_type` or `std::initializer_list`, see - https://github.com/nlohmann/json/issues/235 for more information. + @liveexample{The following code shows the constructor with and without a + null pointer parameter.,basic_json__nullptr_t} - @liveexample{The example shows how initializer lists are treated as - objects when possible.,push_back__initializer_list} + @since version 1.0.0 */ - void push_back(std::initializer_list init) + basic_json(std::nullptr_t = nullptr) noexcept + : basic_json(value_t::null) { - if (is_object() and init.size() == 2 and init.begin()->is_string()) - { - const string_t key = *init.begin(); - push_back(typename object_t::value_type(key, *(init.begin() + 1))); - } - else - { - push_back(basic_json(init)); - } + assert_invariant(); } /*! - @brief add an object to an object - @copydoc push_back(std::initializer_list) - */ - reference operator+=(std::initializer_list init) - { - push_back(init); - return *this; - } + @brief create a JSON value - /*! - @brief add an object to an array + This is a "catch all" constructor for all compatible JSON types; that is, + types for which a `to_json()` method exists. The constructor forwards the + parameter @a val to that method (to `json_serializer::to_json` method + with `U = uncvref_t`, to be exact). - Creates a JSON value from the passed parameters @a args to the end of the - JSON value. If the function is called on a JSON null value, an empty array - is created before appending the value created from @a args. + Template type @a CompatibleType includes, but is not limited to, the + following types: + - **arrays**: @ref array_t and all kinds of compatible containers such as + `std::vector`, `std::deque`, `std::list`, `std::forward_list`, + `std::array`, `std::valarray`, `std::set`, `std::unordered_set`, + `std::multiset`, and `std::unordered_multiset` with a `value_type` from + which a @ref basic_json value can be constructed. + - **objects**: @ref object_t and all kinds of compatible associative + containers such as `std::map`, `std::unordered_map`, `std::multimap`, + and `std::unordered_multimap` with a `key_type` compatible to + @ref string_t and a `value_type` from which a @ref basic_json value can + be constructed. + - **strings**: @ref string_t, string literals, and all compatible string + containers can be used. + - **numbers**: @ref number_integer_t, @ref number_unsigned_t, + @ref number_float_t, and all convertible number types such as `int`, + `size_t`, `int64_t`, `float` or `double` can be used. + - **boolean**: @ref boolean_t / `bool` can be used. - @param[in] args arguments to forward to a constructor of @ref basic_json - @tparam Args compatible types to create a @ref basic_json object + See the examples below. - @throw type_error.311 when called on a type other than JSON array or - null; example: `"cannot use emplace_back() with number"` + @tparam CompatibleType a type such that: + - @a CompatibleType is not derived from `std::istream`, + - @a CompatibleType is not @ref basic_json (to avoid hijacking copy/move + constructors), + - @a CompatibleType is not a @ref basic_json nested type (e.g., + @ref json_pointer, @ref iterator, etc ...) + - @ref @ref json_serializer has a + `to_json(basic_json_t&, CompatibleType&&)` method - @complexity Amortized constant. + @tparam U = `uncvref_t` - @liveexample{The example shows how `push_back()` can be used to add - elements to a JSON array. Note how the `null` value was silently converted - to a JSON array.,emplace_back} + @param[in] val the value to be forwarded to the respective constructor - @since version 2.0.8 - */ - template - void emplace_back(Args&& ... args) - { - // emplace_back only works for null objects or arrays - if (not(is_null() or is_array())) - { - JSON_THROW(type_error::create(311, "cannot use emplace_back() with " + type_name())); - } + @complexity Usually linear in the size of the passed @a val, also + depending on the implementation of the called `to_json()` + method. - // transform null object into an array - if (is_null()) - { - m_type = value_t::array; - m_value = value_t::array; - assert_invariant(); - } + @exceptionsafety Depends on the called constructor. For types directly + supported by the library (i.e., all types for which no `to_json()` function + was provided), strong guarantee holds: if an exception is thrown, there are + no changes to any JSON value. - // add element to array (perfect forwarding) - m_value.array->emplace_back(std::forward(args)...); + @liveexample{The following code shows the constructor with several + compatible types.,basic_json__CompatibleType} + + @since version 2.1.0 + */ + template, + detail::enable_if_t::value and + not std::is_same::value and + not detail::is_basic_json_nested_type< + basic_json_t, U>::value and + detail::has_to_json::value, + int> = 0> + basic_json(CompatibleType && val) noexcept(noexcept(JSONSerializer::to_json( + std::declval(), std::forward(val)))) + { + JSONSerializer::to_json(*this, std::forward(val)); + assert_invariant(); } /*! - @brief add an object to an object if key does not exist + @brief create a container (array or object) from an initializer list - Inserts a new element into a JSON object constructed in-place with the - given @a args if there is no element with the key in the container. If the - function is called on a JSON null value, an empty object is created before - appending the value created from @a args. + Creates a JSON value of type array or object from the passed initializer + list @a init. In case @a type_deduction is `true` (default), the type of + the JSON value to be created is deducted from the initializer list @a init + according to the following rules: - @param[in] args arguments to forward to a constructor of @ref basic_json - @tparam Args compatible types to create a @ref basic_json object + 1. If the list is empty, an empty JSON object value `{}` is created. + 2. If the list consists of pairs whose first element is a string, a JSON + object value is created where the first elements of the pairs are + treated as keys and the second elements are as values. + 3. In all other cases, an array is created. - @return a pair consisting of an iterator to the inserted element, or the - already-existing element if no insertion happened, and a bool - denoting whether the insertion took place. + The rules aim to create the best fit between a C++ initializer list and + JSON values. The rationale is as follows: - @throw type_error.311 when called on a type other than JSON object or - null; example: `"cannot use emplace() with number"` + 1. The empty initializer list is written as `{}` which is exactly an empty + JSON object. + 2. C++ has no way of describing mapped types other than to list a list of + pairs. As JSON requires that keys must be of type string, rule 2 is the + weakest constraint one can pose on initializer lists to interpret them + as an object. + 3. In all other cases, the initializer list could not be interpreted as + JSON object type, so interpreting it as JSON array type is safe. - @complexity Logarithmic in the size of the container, O(log(`size()`)). + With the rules described above, the following JSON values cannot be + expressed by an initializer list: - @liveexample{The example shows how `emplace()` can be used to add elements - to a JSON object. Note how the `null` value was silently converted to a - JSON object. Further note how no value is added if there was already one - value stored with the same key.,emplace} + - the empty array (`[]`): use @ref array(initializer_list_t) + with an empty initializer list in this case + - arrays whose elements satisfy rule 2: use @ref + array(initializer_list_t) with the same initializer list + in this case - @since version 2.0.8 + @note When used without parentheses around an empty initializer list, @ref + basic_json() is called instead of this function, yielding the JSON null + value. + + @param[in] init initializer list with JSON values + + @param[in] type_deduction internal parameter; when set to `true`, the type + of the JSON value is deducted from the initializer list @a init; when set + to `false`, the type provided via @a manual_type is forced. This mode is + used by the functions @ref array(initializer_list_t) and + @ref object(initializer_list_t). + + @param[in] manual_type internal parameter; when @a type_deduction is set + to `false`, the created JSON value will use the provided type (only @ref + value_t::array and @ref value_t::object are valid); when @a type_deduction + is set to `true`, this parameter has no effect + + @throw type_error.301 if @a type_deduction is `false`, @a manual_type is + `value_t::object`, but @a init contains an element which is not a pair + whose first element is a string. In this case, the constructor could not + create an object. If @a type_deduction would have be `true`, an array + would have been created. See @ref object(initializer_list_t) + for an example. + + @complexity Linear in the size of the initializer list @a init. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @liveexample{The example below shows how JSON values are created from + initializer lists.,basic_json__list_init_t} + + @sa @ref array(initializer_list_t) -- create a JSON array + value from an initializer list + @sa @ref object(initializer_list_t) -- create a JSON object + value from an initializer list + + @since version 1.0.0 */ - template - std::pair emplace(Args&& ... args) + basic_json(initializer_list_t init, + bool type_deduction = true, + value_t manual_type = value_t::array) { - // emplace only works for null objects or arrays - if (not(is_null() or is_object())) + // check if each element is an array with two elements whose first + // element is a string + bool is_an_object = std::all_of(init.begin(), init.end(), + [](const detail::json_ref& element_ref) + { + return (element_ref->is_array() and element_ref->size() == 2 and (*element_ref)[0].is_string()); + }); + + // adjust type if type deduction is not wanted + if (not type_deduction) { - JSON_THROW(type_error::create(311, "cannot use emplace() with " + type_name())); + // if array is wanted, do not create an object though possible + if (manual_type == value_t::array) + { + is_an_object = false; + } + + // if object is wanted but impossible, throw an exception + if (JSON_UNLIKELY(manual_type == value_t::object and not is_an_object)) + { + JSON_THROW(type_error::create(301, "cannot create object from initializer list")); + } } - // transform null object into an object - if (is_null()) + if (is_an_object) { + // the initializer list is a list of pairs -> create object m_type = value_t::object; m_value = value_t::object; - assert_invariant(); - } - // add element to array (perfect forwarding) - auto res = m_value.object->emplace(std::forward(args)...); - // create result iterator and set iterator to the result of emplace - auto it = begin(); - it.m_it.object_iterator = res.first; + std::for_each(init.begin(), init.end(), [this](const detail::json_ref& element_ref) + { + auto element = element_ref.moved_or_copied(); + m_value.object->emplace( + std::move(*((*element.m_value.array)[0].m_value.string)), + std::move((*element.m_value.array)[1])); + }); + } + else + { + // the initializer list describes an array -> create array + m_type = value_t::array; + m_value.array = create(init.begin(), init.end()); + } - // return pair of iterator and boolean - return {it, res.second}; + assert_invariant(); } /*! - @brief inserts element + @brief explicitly create an array from an initializer list - Inserts element @a val before iterator @a pos. + Creates a JSON array value from a given initializer list. That is, given a + list of values `a, b, c`, creates the JSON value `[a, b, c]`. If the + initializer list is empty, the empty array `[]` is created. - @param[in] pos iterator before which the content will be inserted; may be - the end() iterator - @param[in] val element to insert - @return iterator pointing to the inserted @a val. + @note This function is only needed to express two edge cases that cannot + be realized with the initializer list constructor (@ref + basic_json(initializer_list_t, bool, value_t)). These cases + are: + 1. creating an array whose elements are all pairs whose first element is a + string -- in this case, the initializer list constructor would create an + object, taking the first elements as keys + 2. creating an empty array -- passing the empty initializer list to the + initializer list constructor yields an empty object - @throw type_error.309 if called on JSON values other than arrays; - example: `"cannot use insert() with string"` - @throw invalid_iterator.202 if @a pos is not an iterator of *this; - example: `"iterator does not fit current value"` + @param[in] init initializer list with JSON values to create an array from + (optional) - @complexity Constant plus linear in the distance between @a pos and end of - the container. + @return JSON array value - @liveexample{The example shows how `insert()` is used.,insert} + @complexity Linear in the size of @a init. - @since version 1.0.0 - */ - iterator insert(const_iterator pos, const basic_json& val) - { - // insert only works for arrays - if (is_array()) - { - // check if iterator pos fits to this JSON value - if (pos.m_object != this) - { - JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); - } + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. - // insert to array and return iterator - iterator result(this); - result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val); - return result; - } + @liveexample{The following code shows an example for the `array` + function.,array} - JSON_THROW(type_error::create(309, "cannot use insert() with " + type_name())); - } + @sa @ref basic_json(initializer_list_t, bool, value_t) -- + create a JSON value from an initializer list + @sa @ref object(initializer_list_t) -- create a JSON object + value from an initializer list - /*! - @brief inserts element - @copydoc insert(const_iterator, const basic_json&) + @since version 1.0.0 */ - iterator insert(const_iterator pos, basic_json&& val) + static basic_json array(initializer_list_t init = {}) { - return insert(pos, val); + return basic_json(init, false, value_t::array); } /*! - @brief inserts elements + @brief explicitly create an object from an initializer list - Inserts @a cnt copies of @a val before iterator @a pos. + Creates a JSON object value from a given initializer list. The initializer + lists elements must be pairs, and their first elements must be strings. If + the initializer list is empty, the empty object `{}` is created. - @param[in] pos iterator before which the content will be inserted; may be - the end() iterator - @param[in] cnt number of copies of @a val to insert - @param[in] val element to insert - @return iterator pointing to the first element inserted, or @a pos if - `cnt==0` + @note This function is only added for symmetry reasons. In contrast to the + related function @ref array(initializer_list_t), there are + no cases which can only be expressed by this function. That is, any + initializer list @a init can also be passed to the initializer list + constructor @ref basic_json(initializer_list_t, bool, value_t). - @throw type_error.309 if called on JSON values other than arrays; example: - `"cannot use insert() with string"` - @throw invalid_iterator.202 if @a pos is not an iterator of *this; - example: `"iterator does not fit current value"` + @param[in] init initializer list to create an object from (optional) - @complexity Linear in @a cnt plus linear in the distance between @a pos - and end of the container. + @return JSON object value - @liveexample{The example shows how `insert()` is used.,insert__count} + @throw type_error.301 if @a init is not a list of pairs whose first + elements are strings. In this case, no object can be created. When such a + value is passed to @ref basic_json(initializer_list_t, bool, value_t), + an array would have been created from the passed initializer list @a init. + See example below. + + @complexity Linear in the size of @a init. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @liveexample{The following code shows an example for the `object` + function.,object} + + @sa @ref basic_json(initializer_list_t, bool, value_t) -- + create a JSON value from an initializer list + @sa @ref array(initializer_list_t) -- create a JSON array + value from an initializer list @since version 1.0.0 */ - iterator insert(const_iterator pos, size_type cnt, const basic_json& val) + static basic_json object(initializer_list_t init = {}) { - // insert only works for arrays - if (is_array()) - { - // check if iterator pos fits to this JSON value - if (pos.m_object != this) - { - JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); - } - - // insert to array and return iterator - iterator result(this); - result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val); - return result; - } - - JSON_THROW(type_error::create(309, "cannot use insert() with " + type_name())); + return basic_json(init, false, value_t::object); } /*! - @brief inserts elements + @brief construct an array with count copies of given value - Inserts elements from range `[first, last)` before iterator @a pos. + Constructs a JSON array value by creating @a cnt copies of a passed value. + In case @a cnt is `0`, an empty array is created. - @param[in] pos iterator before which the content will be inserted; may be - the end() iterator - @param[in] first begin of the range of elements to insert - @param[in] last end of the range of elements to insert + @param[in] cnt the number of JSON copies of @a val to create + @param[in] val the JSON value to copy - @throw type_error.309 if called on JSON values other than arrays; example: - `"cannot use insert() with string"` - @throw invalid_iterator.202 if @a pos is not an iterator of *this; - example: `"iterator does not fit current value"` - @throw invalid_iterator.210 if @a first and @a last do not belong to the - same JSON value; example: `"iterators do not fit"` - @throw invalid_iterator.211 if @a first or @a last are iterators into - container for which insert is called; example: `"passed iterators may not - belong to container"` + @post `std::distance(begin(),end()) == cnt` holds. - @return iterator pointing to the first element inserted, or @a pos if - `first==last` + @complexity Linear in @a cnt. - @complexity Linear in `std::distance(first, last)` plus linear in the - distance between @a pos and end of the container. + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. - @liveexample{The example shows how `insert()` is used.,insert__range} + @liveexample{The following code shows examples for the @ref + basic_json(size_type\, const basic_json&) + constructor.,basic_json__size_type_basic_json} @since version 1.0.0 */ - iterator insert(const_iterator pos, const_iterator first, const_iterator last) + basic_json(size_type cnt, const basic_json& val) + : m_type(value_t::array) { - // insert only works for arrays - if (not is_array()) - { - JSON_THROW(type_error::create(309, "cannot use insert() with " + type_name())); - } + m_value.array = create(cnt, val); + assert_invariant(); + } - // check if iterator pos fits to this JSON value - if (pos.m_object != this) - { - JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); - } + /*! + @brief construct a JSON container given an iterator range - // check if range iterators belong to the same JSON object - if (first.m_object != last.m_object) - { - JSON_THROW(invalid_iterator::create(210, "iterators do not fit")); - } + Constructs the JSON value with the contents of the range `[first, last)`. + The semantics depends on the different types a JSON value can have: + - In case of a null type, invalid_iterator.206 is thrown. + - In case of other primitive types (number, boolean, or string), @a first + must be `begin()` and @a last must be `end()`. In this case, the value is + copied. Otherwise, invalid_iterator.204 is thrown. + - In case of structured types (array, object), the constructor behaves as + similar versions for `std::vector` or `std::map`; that is, a JSON array + or object is constructed from the values in the range. - if (first.m_object == this or last.m_object == this) - { - JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container")); - } + @tparam InputIT an input iterator type (@ref iterator or @ref + const_iterator) - // insert to array and return iterator - iterator result(this); - result.m_it.array_iterator = m_value.array->insert( - pos.m_it.array_iterator, - first.m_it.array_iterator, - last.m_it.array_iterator); - return result; - } + @param[in] first begin of the range to copy from (included) + @param[in] last end of the range to copy from (excluded) - /*! - @brief inserts elements + @pre Iterators @a first and @a last must be initialized. **This + precondition is enforced with an assertion (see warning).** If + assertions are switched off, a violation of this precondition yields + undefined behavior. - Inserts elements from initializer list @a ilist before iterator @a pos. + @pre Range `[first, last)` is valid. Usually, this precondition cannot be + checked efficiently. Only certain edge cases are detected; see the + description of the exceptions below. A violation of this precondition + yields undefined behavior. - @param[in] pos iterator before which the content will be inserted; may be - the end() iterator - @param[in] ilist initializer list to insert the values from + @warning A precondition is enforced with a runtime assertion that will + result in calling `std::abort` if this precondition is not met. + Assertions can be disabled by defining `NDEBUG` at compile time. + See http://en.cppreference.com/w/cpp/error/assert for more + information. - @throw type_error.309 if called on JSON values other than arrays; example: - `"cannot use insert() with string"` - @throw invalid_iterator.202 if @a pos is not an iterator of *this; - example: `"iterator does not fit current value"` + @throw invalid_iterator.201 if iterators @a first and @a last are not + compatible (i.e., do not belong to the same JSON value). In this case, + the range `[first, last)` is undefined. + @throw invalid_iterator.204 if iterators @a first and @a last belong to a + primitive type (number, boolean, or string), but @a first does not point + to the first element any more. In this case, the range `[first, last)` is + undefined. See example code below. + @throw invalid_iterator.206 if iterators @a first and @a last belong to a + null value. In this case, the range `[first, last)` is undefined. - @return iterator pointing to the first element inserted, or @a pos if - `ilist` is empty + @complexity Linear in distance between @a first and @a last. - @complexity Linear in `ilist.size()` plus linear in the distance between - @a pos and end of the container. + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. - @liveexample{The example shows how `insert()` is used.,insert__ilist} + @liveexample{The example below shows several ways to create JSON values by + specifying a subrange with iterators.,basic_json__InputIt_InputIt} @since version 1.0.0 */ - iterator insert(const_iterator pos, std::initializer_list ilist) + template::value or + std::is_same::value, int>::type = 0> + basic_json(InputIT first, InputIT last) { - // insert only works for arrays - if (not is_array()) + assert(first.m_object != nullptr); + assert(last.m_object != nullptr); + + // make sure iterator fits the current value + if (JSON_UNLIKELY(first.m_object != last.m_object)) { - JSON_THROW(type_error::create(309, "cannot use insert() with " + type_name())); + JSON_THROW(invalid_iterator::create(201, "iterators are not compatible")); } - // check if iterator pos fits to this JSON value - if (pos.m_object != this) + // copy type from first iterator + m_type = first.m_object->m_type; + + // check if iterator range is complete for primitive values + switch (m_type) { - JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); + case value_t::boolean: + case value_t::number_float: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::string: + { + if (JSON_UNLIKELY(not first.m_it.primitive_iterator.is_begin() + or not last.m_it.primitive_iterator.is_end())) + { + JSON_THROW(invalid_iterator::create(204, "iterators out of range")); + } + break; + } + + default: + break; } - // insert to array and return iterator - iterator result(this); - result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist); - return result; - } + switch (m_type) + { + case value_t::number_integer: + { + m_value.number_integer = first.m_object->m_value.number_integer; + break; + } - /*! - @brief exchanges the values + case value_t::number_unsigned: + { + m_value.number_unsigned = first.m_object->m_value.number_unsigned; + break; + } - Exchanges the contents of the JSON value with those of @a other. Does not - invoke any move, copy, or swap operations on individual elements. All - iterators and references remain valid. The past-the-end iterator is - invalidated. + case value_t::number_float: + { + m_value.number_float = first.m_object->m_value.number_float; + break; + } - @param[in,out] other JSON value to exchange the contents with + case value_t::boolean: + { + m_value.boolean = first.m_object->m_value.boolean; + break; + } - @complexity Constant. + case value_t::string: + { + m_value = *first.m_object->m_value.string; + break; + } - @liveexample{The example below shows how JSON values can be swapped with - `swap()`.,swap__reference} + case value_t::object: + { + m_value.object = create(first.m_it.object_iterator, + last.m_it.object_iterator); + break; + } + + case value_t::array: + { + m_value.array = create(first.m_it.array_iterator, + last.m_it.array_iterator); + break; + } + + default: + JSON_THROW(invalid_iterator::create(206, "cannot construct with iterators from " + + std::string(first.m_object->type_name()))); + } - @since version 1.0.0 - */ - void swap(reference other) noexcept_if( - std::is_nothrow_move_constructible::value and - std::is_nothrow_move_assignable::value and - std::is_nothrow_move_constructible::value and - std::is_nothrow_move_assignable::value - ) - { - std::swap(m_type, other.m_type); - std::swap(m_value, other.m_value); assert_invariant(); } - /*! - @brief exchanges the values - - Exchanges the contents of a JSON array with those of @a other. Does not - invoke any move, copy, or swap operations on individual elements. All - iterators and references remain valid. The past-the-end iterator is - invalidated. - @param[in,out] other array to exchange the contents with + /////////////////////////////////////// + // other constructors and destructor // + /////////////////////////////////////// - @throw type_error.310 when JSON value is not an array; example: `"cannot - use swap() with string"` + /// @private + basic_json(const detail::json_ref& ref) + : basic_json(ref.moved_or_copied()) + {} - @complexity Constant. + /*! + @brief copy constructor - @liveexample{The example below shows how arrays can be swapped with - `swap()`.,swap__array_t} + Creates a copy of a given JSON value. + + @param[in] other the JSON value to copy + + @post `*this == other` + + @complexity Linear in the size of @a other. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @requirement This function helps `basic_json` satisfying the + [Container](http://en.cppreference.com/w/cpp/concept/Container) + requirements: + - The complexity is linear. + - As postcondition, it holds: `other == basic_json(other)`. + + @liveexample{The following code shows an example for the copy + constructor.,basic_json__basic_json} @since version 1.0.0 */ - void swap(array_t& other) + basic_json(const basic_json& other) + : m_type(other.m_type) { - // swap only works for arrays - if (is_array()) - { - std::swap(*(m_value.array), other); - } - else + // check of passed value is valid + other.assert_invariant(); + + switch (m_type) { - JSON_THROW(type_error::create(310, "cannot use swap() with " + type_name())); + case value_t::object: + { + m_value = *other.m_value.object; + break; + } + + case value_t::array: + { + m_value = *other.m_value.array; + break; + } + + case value_t::string: + { + m_value = *other.m_value.string; + break; + } + + case value_t::boolean: + { + m_value = other.m_value.boolean; + break; + } + + case value_t::number_integer: + { + m_value = other.m_value.number_integer; + break; + } + + case value_t::number_unsigned: + { + m_value = other.m_value.number_unsigned; + break; + } + + case value_t::number_float: + { + m_value = other.m_value.number_float; + break; + } + + default: + break; } + + assert_invariant(); } /*! - @brief exchanges the values + @brief move constructor - Exchanges the contents of a JSON object with those of @a other. Does not - invoke any move, copy, or swap operations on individual elements. All - iterators and references remain valid. The past-the-end iterator is - invalidated. + Move constructor. Constructs a JSON value with the contents of the given + value @a other using move semantics. It "steals" the resources from @a + other and leaves it as JSON null value. - @param[in,out] other object to exchange the contents with + @param[in,out] other value to move to this object - @throw type_error.310 when JSON value is not an object; example: - `"cannot use swap() with string"` + @post `*this` has the same value as @a other before the call. + @post @a other is a JSON null value. @complexity Constant. - @liveexample{The example below shows how objects can be swapped with - `swap()`.,swap__object_t} + @exceptionsafety No-throw guarantee: this constructor never throws + exceptions. + + @requirement This function helps `basic_json` satisfying the + [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible) + requirements. + + @liveexample{The code below shows the move constructor explicitly called + via std::move.,basic_json__moveconstructor} @since version 1.0.0 */ - void swap(object_t& other) + basic_json(basic_json&& other) noexcept + : m_type(std::move(other.m_type)), + m_value(std::move(other.m_value)) { - // swap only works for objects - if (is_object()) - { - std::swap(*(m_value.object), other); - } - else - { - JSON_THROW(type_error::create(310, "cannot use swap() with " + type_name())); - } + // check that passed value is valid + other.assert_invariant(); + + // invalidate payload + other.m_type = value_t::null; + other.m_value = {}; + + assert_invariant(); } /*! - @brief exchanges the values + @brief copy assignment - Exchanges the contents of a JSON string with those of @a other. Does not - invoke any move, copy, or swap operations on individual elements. All - iterators and references remain valid. The past-the-end iterator is - invalidated. + Copy assignment operator. Copies a JSON value via the "copy and swap" + strategy: It is expressed in terms of the copy constructor, destructor, + and the `swap()` member function. - @param[in,out] other string to exchange the contents with + @param[in] other value to copy from - @throw type_error.310 when JSON value is not a string; example: `"cannot - use swap() with boolean"` + @complexity Linear. - @complexity Constant. + @requirement This function helps `basic_json` satisfying the + [Container](http://en.cppreference.com/w/cpp/concept/Container) + requirements: + - The complexity is linear. - @liveexample{The example below shows how strings can be swapped with - `swap()`.,swap__string_t} + @liveexample{The code below shows and example for the copy assignment. It + creates a copy of value `a` which is then swapped with `b`. Finally\, the + copy of `a` (which is the null value after the swap) is + destroyed.,basic_json__copyassignment} @since version 1.0.0 */ - void swap(string_t& other) + reference& operator=(basic_json other) noexcept ( + std::is_nothrow_move_constructible::value and + std::is_nothrow_move_assignable::value and + std::is_nothrow_move_constructible::value and + std::is_nothrow_move_assignable::value + ) { - // swap only works for strings - if (is_string()) - { - std::swap(*(m_value.string), other); - } - else - { - JSON_THROW(type_error::create(310, "cannot use swap() with " + type_name())); - } + // check that passed value is valid + other.assert_invariant(); + + using std::swap; + swap(m_type, other.m_type); + swap(m_value, other.m_value); + + assert_invariant(); + return *this; + } + + /*! + @brief destructor + + Destroys the JSON value and frees all allocated memory. + + @complexity Linear. + + @requirement This function helps `basic_json` satisfying the + [Container](http://en.cppreference.com/w/cpp/concept/Container) + requirements: + - The complexity is linear. + - All stored elements are destroyed and all memory is freed. + + @since version 1.0.0 + */ + ~basic_json() + { + assert_invariant(); + m_value.destroy(m_type); } /// @} public: - ////////////////////////////////////////// - // lexicographical comparison operators // - ////////////////////////////////////////// + /////////////////////// + // object inspection // + /////////////////////// - /// @name lexicographical comparison operators + /// @name object inspection + /// Functions to inspect the type of a JSON value. /// @{ /*! - @brief comparison: equal + @brief serialization - Compares two JSON values for equality according to the following rules: - - Two JSON values are equal if (1) they are from the same type and (2) - their stored values are the same according to their respective - `operator==`. - - Integer and floating-point numbers are automatically converted before - comparison. Floating-point numbers are compared indirectly: two - floating-point numbers `f1` and `f2` are considered equal if neither - `f1 > f2` nor `f2 > f1` holds. Note than two NaN values are always - treated as unequal. - - Two JSON null values are equal. + Serialization function for JSON values. The function tries to mimic + Python's `json.dumps()` function, and currently supports its @a indent + and @a ensure_ascii parameters. - @note NaN values never compare equal to themselves or to other NaN values. + @param[in] indent If indent is nonnegative, then array elements and object + members will be pretty-printed with that indent level. An indent level of + `0` will only insert newlines. `-1` (the default) selects the most compact + representation. + @param[in] indent_char The character to use for indentation if @a indent is + greater than `0`. The default is ` ` (space). + @param[in] ensure_ascii If @a ensure_ascii is true, all non-ASCII characters + in the output are escaped with `\uXXXX` sequences, and the result consists + of ASCII characters only. - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether the values @a lhs and @a rhs are equal + @return string containing the serialization of the JSON value + + @throw type_error.316 if a string stored inside the JSON value is not + UTF-8 encoded @complexity Linear. - @liveexample{The example demonstrates comparing several JSON - types.,operator__equal} + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. - @since version 1.0.0 + @liveexample{The following example shows the effect of different @a indent\, + @a indent_char\, and @a ensure_ascii parameters to the result of the + serialization.,dump} + + @see https://docs.python.org/2/library/json.html#json.dump + + @since version 1.0.0; indentation character @a indent_char, option + @a ensure_ascii and exceptions added in version 3.0.0 */ - friend bool operator==(const_reference lhs, const_reference rhs) noexcept + string_t dump(const int indent = -1, const char indent_char = ' ', + const bool ensure_ascii = false) const { - const auto lhs_type = lhs.type(); - const auto rhs_type = rhs.type(); + string_t result; + serializer s(detail::output_adapter(result), indent_char); - if (lhs_type == rhs_type) + if (indent >= 0) { - switch (lhs_type) - { - case value_t::array: - { - return *lhs.m_value.array == *rhs.m_value.array; - } - case value_t::object: - { - return *lhs.m_value.object == *rhs.m_value.object; - } - case value_t::null: - { - return true; - } - case value_t::string: - { - return *lhs.m_value.string == *rhs.m_value.string; - } - case value_t::boolean: - { - return lhs.m_value.boolean == rhs.m_value.boolean; - } - case value_t::number_integer: - { - return lhs.m_value.number_integer == rhs.m_value.number_integer; - } - case value_t::number_unsigned: - { - return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned; - } - case value_t::number_float: - { - return lhs.m_value.number_float == rhs.m_value.number_float; - } - default: - { - return false; - } - } - } - else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float) - { - return static_cast(lhs.m_value.number_integer) == rhs.m_value.number_float; - } - else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer) - { - return lhs.m_value.number_float == static_cast(rhs.m_value.number_integer); - } - else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float) - { - return static_cast(lhs.m_value.number_unsigned) == rhs.m_value.number_float; - } - else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned) - { - return lhs.m_value.number_float == static_cast(rhs.m_value.number_unsigned); - } - else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer) - { - return static_cast(lhs.m_value.number_unsigned) == rhs.m_value.number_integer; + s.dump(*this, true, ensure_ascii, static_cast(indent)); } - else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned) + else { - return lhs.m_value.number_integer == static_cast(rhs.m_value.number_unsigned); + s.dump(*this, false, ensure_ascii, 0); } - return false; + return result; } /*! - @brief comparison: equal - @copydoc operator==(const_reference, const_reference) - */ - template::value, int>::type = 0> - friend bool operator==(const_reference lhs, const ScalarType rhs) noexcept - { - return (lhs == basic_json(rhs)); - } + @brief return the type of the JSON value (explicit) - /*! - @brief comparison: equal - @copydoc operator==(const_reference, const_reference) - */ - template::value, int>::type = 0> - friend bool operator==(const ScalarType lhs, const_reference rhs) noexcept - { - return (basic_json(lhs) == rhs); - } + Return the type of the JSON value as a value from the @ref value_t + enumeration. - /*! - @brief comparison: not equal + @return the type of the JSON value + Value type | return value + ------------------------- | ------------------------- + null | value_t::null + boolean | value_t::boolean + string | value_t::string + number (integer) | value_t::number_integer + number (unsigned integer) | value_t::number_unsigned + number (floating-point) | value_t::number_float + object | value_t::object + array | value_t::array + discarded | value_t::discarded - Compares two JSON values for inequality by calculating `not (lhs == rhs)`. + @complexity Constant. - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether the values @a lhs and @a rhs are not equal + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. - @complexity Linear. + @liveexample{The following code exemplifies `type()` for all JSON + types.,type} - @liveexample{The example demonstrates comparing several JSON - types.,operator__notequal} + @sa @ref operator value_t() -- return the type of the JSON value (implicit) + @sa @ref type_name() -- return the type as string @since version 1.0.0 */ - friend bool operator!=(const_reference lhs, const_reference rhs) noexcept + constexpr value_t type() const noexcept { - return not (lhs == rhs); + return m_type; } /*! - @brief comparison: not equal - @copydoc operator!=(const_reference, const_reference) - */ - template::value, int>::type = 0> - friend bool operator!=(const_reference lhs, const ScalarType rhs) noexcept - { - return (lhs != basic_json(rhs)); - } + @brief return whether type is primitive - /*! - @brief comparison: not equal - @copydoc operator!=(const_reference, const_reference) - */ - template::value, int>::type = 0> - friend bool operator!=(const ScalarType lhs, const_reference rhs) noexcept - { - return (basic_json(lhs) != rhs); - } + This function returns true if and only if the JSON type is primitive + (string, number, boolean, or null). - /*! - @brief comparison: less than + @return `true` if type is primitive (string, number, boolean, or null), + `false` otherwise. - Compares whether one JSON value @a lhs is less than another JSON value @a - rhs according to the following rules: - - If @a lhs and @a rhs have the same type, the values are compared using - the default `<` operator. - - Integer and floating-point numbers are automatically converted before - comparison - - In case @a lhs and @a rhs have different types, the values are ignored - and the order of the types is considered, see - @ref operator<(const value_t, const value_t). + @complexity Constant. - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether @a lhs is less than @a rhs + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. - @complexity Linear. + @liveexample{The following code exemplifies `is_primitive()` for all JSON + types.,is_primitive} - @liveexample{The example demonstrates comparing several JSON - types.,operator__less} + @sa @ref is_structured() -- returns whether JSON value is structured + @sa @ref is_null() -- returns whether JSON value is `null` + @sa @ref is_string() -- returns whether JSON value is a string + @sa @ref is_boolean() -- returns whether JSON value is a boolean + @sa @ref is_number() -- returns whether JSON value is a number @since version 1.0.0 */ - friend bool operator < (const_reference lhs, const_reference rhs) noexcept + constexpr bool is_primitive() const noexcept { - const auto lhs_type = lhs.type(); - const auto rhs_type = rhs.type(); - - if (lhs_type == rhs_type) - { - switch (lhs_type) - { - case value_t::array: - { - return *lhs.m_value.array < *rhs.m_value.array; - } - case value_t::object: - { - return *lhs.m_value.object < *rhs.m_value.object; - } - case value_t::null: - { - return false; - } - case value_t::string: - { - return *lhs.m_value.string < *rhs.m_value.string; - } - case value_t::boolean: - { - return lhs.m_value.boolean < rhs.m_value.boolean; - } - case value_t::number_integer: - { - return lhs.m_value.number_integer < rhs.m_value.number_integer; - } - case value_t::number_unsigned: - { - return lhs.m_value.number_unsigned < rhs.m_value.number_unsigned; - } - case value_t::number_float: - { - return lhs.m_value.number_float < rhs.m_value.number_float; - } - default: - { - return false; - } - } - } - else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float) - { - return static_cast(lhs.m_value.number_integer) < rhs.m_value.number_float; - } - else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer) - { - return lhs.m_value.number_float < static_cast(rhs.m_value.number_integer); - } - else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float) - { - return static_cast(lhs.m_value.number_unsigned) < rhs.m_value.number_float; - } - else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned) - { - return lhs.m_value.number_float < static_cast(rhs.m_value.number_unsigned); - } - else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned) - { - return lhs.m_value.number_integer < static_cast(rhs.m_value.number_unsigned); - } - else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer) - { - return static_cast(lhs.m_value.number_unsigned) < rhs.m_value.number_integer; - } - - // We only reach this line if we cannot compare values. In that case, - // we compare types. Note we have to call the operator explicitly, - // because MSVC has problems otherwise. - return operator<(lhs_type, rhs_type); + return is_null() or is_string() or is_boolean() or is_number(); } /*! - @brief comparison: less than or equal + @brief return whether type is structured - Compares whether one JSON value @a lhs is less than or equal to another - JSON value by calculating `not (rhs < lhs)`. + This function returns true if and only if the JSON type is structured + (array or object). - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether @a lhs is less than or equal to @a rhs + @return `true` if type is structured (array or object), `false` otherwise. - @complexity Linear. + @complexity Constant. - @liveexample{The example demonstrates comparing several JSON - types.,operator__greater} + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_structured()` for all JSON + types.,is_structured} + + @sa @ref is_primitive() -- returns whether value is primitive + @sa @ref is_array() -- returns whether value is an array + @sa @ref is_object() -- returns whether value is an object @since version 1.0.0 */ - friend bool operator<=(const_reference lhs, const_reference rhs) noexcept + constexpr bool is_structured() const noexcept { - return not (rhs < lhs); + return is_array() or is_object(); } /*! - @brief comparison: greater than + @brief return whether value is null - Compares whether one JSON value @a lhs is greater than another - JSON value by calculating `not (lhs <= rhs)`. + This function returns true if and only if the JSON value is null. - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether @a lhs is greater than to @a rhs + @return `true` if type is null, `false` otherwise. - @complexity Linear. + @complexity Constant. - @liveexample{The example demonstrates comparing several JSON - types.,operator__lessequal} + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_null()` for all JSON + types.,is_null} @since version 1.0.0 */ - friend bool operator>(const_reference lhs, const_reference rhs) noexcept + constexpr bool is_null() const noexcept { - return not (lhs <= rhs); + return (m_type == value_t::null); } /*! - @brief comparison: greater than or equal + @brief return whether value is a boolean - Compares whether one JSON value @a lhs is greater than or equal to another - JSON value by calculating `not (lhs < rhs)`. + This function returns true if and only if the JSON value is a boolean. - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether @a lhs is greater than or equal to @a rhs + @return `true` if type is boolean, `false` otherwise. - @complexity Linear. + @complexity Constant. - @liveexample{The example demonstrates comparing several JSON - types.,operator__greaterequal} + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_boolean()` for all JSON + types.,is_boolean} @since version 1.0.0 */ - friend bool operator>=(const_reference lhs, const_reference rhs) noexcept + constexpr bool is_boolean() const noexcept { - return not (lhs < rhs); + return (m_type == value_t::boolean); } - /// @} + /*! + @brief return whether value is a number + This function returns true if and only if the JSON value is a number. This + includes both integer (signed and unsigned) and floating-point values. - /////////////////// - // serialization // - /////////////////// + @return `true` if type is number (regardless whether integer, unsigned + integer or floating-type), `false` otherwise. - /// @name serialization - /// @{ + @complexity Constant. - private: - /*! - @brief wrapper around the serialization functions + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_number()` for all JSON + types.,is_number} + + @sa @ref is_number_integer() -- check if value is an integer or unsigned + integer number + @sa @ref is_number_unsigned() -- check if value is an unsigned integer + number + @sa @ref is_number_float() -- check if value is a floating-point number + + @since version 1.0.0 */ - class serializer + constexpr bool is_number() const noexcept { - private: - serializer(const serializer&) = delete; - serializer& operator=(const serializer&) = delete; + return is_number_integer() or is_number_float(); + } - public: - /*! - @param[in] s output stream to serialize to - */ - serializer(std::ostream& s) - : o(s), loc(std::localeconv()), - thousands_sep(!loc->thousands_sep ? '\0' : loc->thousands_sep[0]), - decimal_point(!loc->decimal_point ? '\0' : loc->decimal_point[0]) - {} + /*! + @brief return whether value is an integer number - /*! - @brief internal implementation of the serialization function + This function returns true if and only if the JSON value is a signed or + unsigned integer number. This excludes floating-point values. - This function is called by the public member function dump and - organizes the serialization internally. The indentation level is - propagated as additional parameter. In case of arrays and objects, the - function is called recursively. + @return `true` if type is an integer or unsigned integer number, `false` + otherwise. - - strings and object keys are escaped using `escape_string()` - - integer numbers are converted implicitly via `operator<<` - - floating-point numbers are converted to a string using `"%g"` format + @complexity Constant. - @param[in] val value to serialize - @param[in] pretty_print whether the output shall be pretty-printed - @param[in] indent_step the indent level - @param[in] current_indent the current indent level (only used internally) - */ - void dump(const basic_json& val, - const bool pretty_print, - const unsigned int indent_step, - const unsigned int current_indent = 0) - { - switch (val.m_type) - { - case value_t::object: - { - if (val.m_value.object->empty()) - { - o.write("{}", 2); - return; - } + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. - if (pretty_print) - { - o.write("{\n", 2); + @liveexample{The following code exemplifies `is_number_integer()` for all + JSON types.,is_number_integer} - // variable to hold indentation for recursive calls - const auto new_indent = current_indent + indent_step; - if (indent_string.size() < new_indent) - { - indent_string.resize(new_indent, ' '); - } + @sa @ref is_number() -- check if value is a number + @sa @ref is_number_unsigned() -- check if value is an unsigned integer + number + @sa @ref is_number_float() -- check if value is a floating-point number - // first n-1 elements - auto i = val.m_value.object->cbegin(); - for (size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i) - { - o.write(indent_string.c_str(), static_cast(new_indent)); - o.put('\"'); - dump_escaped(i->first); - o.write("\": ", 3); - dump(i->second, true, indent_step, new_indent); - o.write(",\n", 2); - } + @since version 1.0.0 + */ + constexpr bool is_number_integer() const noexcept + { + return (m_type == value_t::number_integer or m_type == value_t::number_unsigned); + } - // last element - assert(i != val.m_value.object->cend()); - o.write(indent_string.c_str(), static_cast(new_indent)); - o.put('\"'); - dump_escaped(i->first); - o.write("\": ", 3); - dump(i->second, true, indent_step, new_indent); - - o.put('\n'); - o.write(indent_string.c_str(), static_cast(current_indent)); - o.put('}'); - } - else - { - o.put('{'); + /*! + @brief return whether value is an unsigned integer number - // first n-1 elements - auto i = val.m_value.object->cbegin(); - for (size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i) - { - o.put('\"'); - dump_escaped(i->first); - o.write("\":", 2); - dump(i->second, false, indent_step, current_indent); - o.put(','); - } + This function returns true if and only if the JSON value is an unsigned + integer number. This excludes floating-point and signed integer values. - // last element - assert(i != val.m_value.object->cend()); - o.put('\"'); - dump_escaped(i->first); - o.write("\":", 2); - dump(i->second, false, indent_step, current_indent); + @return `true` if type is an unsigned integer number, `false` otherwise. - o.put('}'); - } + @complexity Constant. - return; - } + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. - case value_t::array: - { - if (val.m_value.array->empty()) - { - o.write("[]", 2); - return; - } + @liveexample{The following code exemplifies `is_number_unsigned()` for all + JSON types.,is_number_unsigned} - if (pretty_print) - { - o.write("[\n", 2); + @sa @ref is_number() -- check if value is a number + @sa @ref is_number_integer() -- check if value is an integer or unsigned + integer number + @sa @ref is_number_float() -- check if value is a floating-point number - // variable to hold indentation for recursive calls - const auto new_indent = current_indent + indent_step; - if (indent_string.size() < new_indent) - { - indent_string.resize(new_indent, ' '); - } + @since version 2.0.0 + */ + constexpr bool is_number_unsigned() const noexcept + { + return (m_type == value_t::number_unsigned); + } - // first n-1 elements - for (auto i = val.m_value.array->cbegin(); i != val.m_value.array->cend() - 1; ++i) - { - o.write(indent_string.c_str(), static_cast(new_indent)); - dump(*i, true, indent_step, new_indent); - o.write(",\n", 2); - } + /*! + @brief return whether value is a floating-point number - // last element - assert(not val.m_value.array->empty()); - o.write(indent_string.c_str(), static_cast(new_indent)); - dump(val.m_value.array->back(), true, indent_step, new_indent); + This function returns true if and only if the JSON value is a + floating-point number. This excludes signed and unsigned integer values. - o.put('\n'); - o.write(indent_string.c_str(), static_cast(current_indent)); - o.put(']'); - } - else - { - o.put('['); + @return `true` if type is a floating-point number, `false` otherwise. - // first n-1 elements - for (auto i = val.m_value.array->cbegin(); i != val.m_value.array->cend() - 1; ++i) - { - dump(*i, false, indent_step, current_indent); - o.put(','); - } + @complexity Constant. - // last element - assert(not val.m_value.array->empty()); - dump(val.m_value.array->back(), false, indent_step, current_indent); + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. - o.put(']'); - } + @liveexample{The following code exemplifies `is_number_float()` for all + JSON types.,is_number_float} - return; - } + @sa @ref is_number() -- check if value is number + @sa @ref is_number_integer() -- check if value is an integer number + @sa @ref is_number_unsigned() -- check if value is an unsigned integer + number - case value_t::string: - { - o.put('\"'); - dump_escaped(*val.m_value.string); - o.put('\"'); - return; - } + @since version 1.0.0 + */ + constexpr bool is_number_float() const noexcept + { + return (m_type == value_t::number_float); + } - case value_t::boolean: - { - if (val.m_value.boolean) - { - o.write("true", 4); - } - else - { - o.write("false", 5); - } - return; - } + /*! + @brief return whether value is an object - case value_t::number_integer: - { - dump_integer(val.m_value.number_integer); - return; - } + This function returns true if and only if the JSON value is an object. - case value_t::number_unsigned: - { - dump_integer(val.m_value.number_unsigned); - return; - } + @return `true` if type is object, `false` otherwise. - case value_t::number_float: - { - dump_float(val.m_value.number_float); - return; - } + @complexity Constant. - case value_t::discarded: - { - o.write("", 11); - return; - } + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. - case value_t::null: - { - o.write("null", 4); - return; - } - } - } + @liveexample{The following code exemplifies `is_object()` for all JSON + types.,is_object} - private: - /*! - @brief calculates the extra space to escape a JSON string + @since version 1.0.0 + */ + constexpr bool is_object() const noexcept + { + return (m_type == value_t::object); + } - @param[in] s the string to escape - @return the number of characters required to escape string @a s + /*! + @brief return whether value is an array - @complexity Linear in the length of string @a s. - */ - static std::size_t extra_space(const string_t& s) noexcept - { - return std::accumulate(s.begin(), s.end(), size_t{}, - [](size_t res, typename string_t::value_type c) - { - switch (c) - { - case '"': - case '\\': - case '\b': - case '\f': - case '\n': - case '\r': - case '\t': - { - // from c (1 byte) to \x (2 bytes) - return res + 1; - } + This function returns true if and only if the JSON value is an array. - case 0x00: - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - case 0x0b: - case 0x0e: - case 0x0f: - case 0x10: - case 0x11: - case 0x12: - case 0x13: - case 0x14: - case 0x15: - case 0x16: - case 0x17: - case 0x18: - case 0x19: - case 0x1a: - case 0x1b: - case 0x1c: - case 0x1d: - case 0x1e: - case 0x1f: - { - // from c (1 byte) to \uxxxx (6 bytes) - return res + 5; - } + @return `true` if type is array, `false` otherwise. - default: - { - return res; - } - } - }); - } + @complexity Constant. - /*! - @brief dump escaped string + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. - Escape a string by replacing certain special characters by a sequence - of an escape character (backslash) and another character and other - control characters by a sequence of "\u" followed by a four-digit hex - representation. The escaped string is written to output stream @a o. + @liveexample{The following code exemplifies `is_array()` for all JSON + types.,is_array} - @param[in] s the string to escape + @since version 1.0.0 + */ + constexpr bool is_array() const noexcept + { + return (m_type == value_t::array); + } - @complexity Linear in the length of string @a s. - */ - void dump_escaped(const string_t& s) const - { - const auto space = extra_space(s); - if (space == 0) - { - o.write(s.c_str(), static_cast(s.size())); - return; - } + /*! + @brief return whether value is a string - // create a result string of necessary size - string_t result(s.size() + space, '\\'); - std::size_t pos = 0; + This function returns true if and only if the JSON value is a string. - for (const auto& c : s) - { - switch (c) - { - // quotation mark (0x22) - case '"': - { - result[pos + 1] = '"'; - pos += 2; - break; - } + @return `true` if type is string, `false` otherwise. - // reverse solidus (0x5c) - case '\\': - { - // nothing to change - pos += 2; - break; - } + @complexity Constant. - // backspace (0x08) - case '\b': - { - result[pos + 1] = 'b'; - pos += 2; - break; - } + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. - // formfeed (0x0c) - case '\f': - { - result[pos + 1] = 'f'; - pos += 2; - break; - } + @liveexample{The following code exemplifies `is_string()` for all JSON + types.,is_string} - // newline (0x0a) - case '\n': - { - result[pos + 1] = 'n'; - pos += 2; - break; - } + @since version 1.0.0 + */ + constexpr bool is_string() const noexcept + { + return (m_type == value_t::string); + } - // carriage return (0x0d) - case '\r': - { - result[pos + 1] = 'r'; - pos += 2; - break; - } + /*! + @brief return whether value is discarded - // horizontal tab (0x09) - case '\t': - { - result[pos + 1] = 't'; - pos += 2; - break; - } + This function returns true if and only if the JSON value was discarded + during parsing with a callback function (see @ref parser_callback_t). - case 0x00: - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - case 0x0b: - case 0x0e: - case 0x0f: - case 0x10: - case 0x11: - case 0x12: - case 0x13: - case 0x14: - case 0x15: - case 0x16: - case 0x17: - case 0x18: - case 0x19: - case 0x1a: - case 0x1b: - case 0x1c: - case 0x1d: - case 0x1e: - case 0x1f: - { - // convert a number 0..15 to its hex representation - // (0..f) - static const char hexify[16] = - { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' - }; - - // print character c as \uxxxx - for (const char m : - { 'u', '0', '0', hexify[c >> 4], hexify[c & 0x0f] - }) - { - result[++pos] = m; - } + @note This function will always be `false` for JSON values after parsing. + That is, discarded values can only occur during parsing, but will be + removed when inside a structured value or replaced by null in other cases. - ++pos; - break; - } + @return `true` if type is discarded, `false` otherwise. - default: - { - // all other characters are added as-is - result[pos++] = c; - break; - } - } - } + @complexity Constant. - assert(pos == s.size() + space); - o.write(result.c_str(), static_cast(result.size())); - } - - /*! - @brief dump an integer - - Dump a given integer to output stream @a o. Works internally with - @a number_buffer. - - @param[in] x integer number (signed or unsigned) to dump - @tparam NumberType either @a number_integer_t or @a number_unsigned_t - */ - template::value or - std::is_same::value, int> = 0> - void dump_integer(NumberType x) - { - // special case for "0" - if (x == 0) - { - o.put('0'); - return; - } - - const bool is_negative = x < 0; - size_t i = 0; - - // spare 1 byte for '\0' - while (x != 0 and i < number_buffer.size() - 1) - { - const auto digit = std::labs(static_cast(x % 10)); - number_buffer[i++] = static_cast('0' + digit); - x /= 10; - } - - // make sure the number has been processed completely - assert(x == 0); - - if (is_negative) - { - // make sure there is capacity for the '-' - assert(i < number_buffer.size() - 2); - number_buffer[i++] = '-'; - } + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. - std::reverse(number_buffer.begin(), number_buffer.begin() + i); - o.write(number_buffer.data(), static_cast(i)); - } + @liveexample{The following code exemplifies `is_discarded()` for all JSON + types.,is_discarded} - /*! - @brief dump a floating-point number + @since version 1.0.0 + */ + constexpr bool is_discarded() const noexcept + { + return (m_type == value_t::discarded); + } - Dump a given floating-point number to output stream @a o. Works - internally with @a number_buffer. + /*! + @brief return the type of the JSON value (implicit) - @param[in] x floating-point number to dump - */ - void dump_float(number_float_t x) - { - // NaN / inf - if (not std::isfinite(x) or std::isnan(x)) - { - o.write("null", 4); - return; - } + Implicitly return the type of the JSON value as a value from the @ref + value_t enumeration. - // special case for 0.0 and -0.0 - if (x == 0) - { - if (std::signbit(x)) - { - o.write("-0.0", 4); - } - else - { - o.write("0.0", 3); - } - return; - } + @return the type of the JSON value - // get number of digits for a text -> float -> text round-trip - static constexpr auto d = std::numeric_limits::digits10; + @complexity Constant. - // the actual conversion - std::ptrdiff_t len = snprintf(number_buffer.data(), number_buffer.size(), - "%.*g", d, x); + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. - // negative value indicates an error - assert(len > 0); - // check if buffer was large enough - assert(static_cast(len) < number_buffer.size()); + @liveexample{The following code exemplifies the @ref value_t operator for + all JSON types.,operator__value_t} - // erase thousands separator - if (thousands_sep != '\0') - { - const auto end = std::remove(number_buffer.begin(), - number_buffer.begin() + len, - thousands_sep); - std::fill(end, number_buffer.end(), '\0'); - assert((end - number_buffer.begin()) <= len); - len = (end - number_buffer.begin()); - } + @sa @ref type() -- return the type of the JSON value (explicit) + @sa @ref type_name() -- return the type as string - // convert decimal point to '.' - if (decimal_point != '\0' and decimal_point != '.') - { - for (auto& c : number_buffer) - { - if (c == decimal_point) - { - c = '.'; - break; - } - } - } + @since version 1.0.0 + */ + constexpr operator value_t() const noexcept + { + return m_type; + } - o.write(number_buffer.data(), static_cast(len)); + /// @} - // determine if need to append ".0" - const bool value_is_int_like = std::none_of(number_buffer.begin(), - number_buffer.begin() + len + 1, - [](char c) - { - return c == '.' or c == 'e'; - }); + private: + ////////////////// + // value access // + ////////////////// - if (value_is_int_like) - { - o.write(".0", 2); - } + /// get a boolean (explicit) + boolean_t get_impl(boolean_t* /*unused*/) const + { + if (JSON_LIKELY(is_boolean())) + { + return m_value.boolean; } - private: - /// the output of the serializer - std::ostream& o; - - /// a (hopefully) large enough character buffer - std::array number_buffer{{}}; - - /// the locale - const std::lconv* loc = nullptr; - /// the locale's thousand separator character - const char thousands_sep = '\0'; - /// the locale's decimal point character - const char decimal_point = '\0'; - - /// the indentation string - string_t indent_string = string_t(512, ' '); - }; + JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(type_name()))); + } - public: - /*! - @brief serialize to stream + /// get a pointer to the value (object) + object_t* get_impl_ptr(object_t* /*unused*/) noexcept + { + return is_object() ? m_value.object : nullptr; + } - Serialize the given JSON value @a j to the output stream @a o. The JSON - value will be serialized using the @ref dump member function. The - indentation of the output can be controlled with the member variable - `width` of the output stream @a o. For instance, using the manipulator - `std::setw(4)` on @a o sets the indentation level to `4` and the - serialization result is the same as calling `dump(4)`. + /// get a pointer to the value (object) + constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept + { + return is_object() ? m_value.object : nullptr; + } - @param[in,out] o stream to serialize to - @param[in] j JSON value to serialize + /// get a pointer to the value (array) + array_t* get_impl_ptr(array_t* /*unused*/) noexcept + { + return is_array() ? m_value.array : nullptr; + } - @return the stream @a o + /// get a pointer to the value (array) + constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept + { + return is_array() ? m_value.array : nullptr; + } - @complexity Linear. + /// get a pointer to the value (string) + string_t* get_impl_ptr(string_t* /*unused*/) noexcept + { + return is_string() ? m_value.string : nullptr; + } - @liveexample{The example below shows the serialization with different - parameters to `width` to adjust the indentation level.,operator_serialize} + /// get a pointer to the value (string) + constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept + { + return is_string() ? m_value.string : nullptr; + } - @since version 1.0.0 - */ - friend std::ostream& operator<<(std::ostream& o, const basic_json& j) + /// get a pointer to the value (boolean) + boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept { - // read width member and use it as indentation parameter if nonzero - const bool pretty_print = (o.width() > 0); - const auto indentation = (pretty_print ? o.width() : 0); + return is_boolean() ? &m_value.boolean : nullptr; + } - // reset width to 0 for subsequent calls to this stream - o.width(0); + /// get a pointer to the value (boolean) + constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept + { + return is_boolean() ? &m_value.boolean : nullptr; + } - // do the actual serialization - serializer s(o); - s.dump(j, pretty_print, static_cast(indentation)); - return o; + /// get a pointer to the value (integer number) + number_integer_t* get_impl_ptr(number_integer_t* /*unused*/) noexcept + { + return is_number_integer() ? &m_value.number_integer : nullptr; } - /*! - @brief serialize to stream - @deprecated This stream operator is deprecated and will be removed in a - future version of the library. Please use - @ref std::ostream& operator<<(std::ostream&, const basic_json&) - instead; that is, replace calls like `j >> o;` with `o << j;`. - */ - JSON_DEPRECATED - friend std::ostream& operator>>(const basic_json& j, std::ostream& o) + /// get a pointer to the value (integer number) + constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept { - return o << j; + return is_number_integer() ? &m_value.number_integer : nullptr; } - /// @} + /// get a pointer to the value (unsigned number) + number_unsigned_t* get_impl_ptr(number_unsigned_t* /*unused*/) noexcept + { + return is_number_unsigned() ? &m_value.number_unsigned : nullptr; + } + /// get a pointer to the value (unsigned number) + constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept + { + return is_number_unsigned() ? &m_value.number_unsigned : nullptr; + } - ///////////////////// - // deserialization // - ///////////////////// + /// get a pointer to the value (floating-point number) + number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept + { + return is_number_float() ? &m_value.number_float : nullptr; + } - /// @name deserialization - /// @{ + /// get a pointer to the value (floating-point number) + constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept + { + return is_number_float() ? &m_value.number_float : nullptr; + } /*! - @brief deserialize from an array - - This function reads from an array of 1-byte values. - - @pre Each element of the container has a size of 1 byte. Violating this - precondition yields undefined behavior. **This precondition is enforced - with a static assertion.** - - @param[in] array array to read from - @param[in] cb a parser callback function of type @ref parser_callback_t - which is used to control the deserialization by filtering unwanted values - (optional) - - @return result of the deserialization - - @throw parse_error.101 if a parse error occurs; example: `""unexpected end - of input; expected string literal""` - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails - - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. The complexity can be higher if the parser callback function - @a cb has a super-linear complexity. + @brief helper function to implement get_ref() - @note A UTF-8 byte order mark is silently ignored. + This function helps to implement get_ref() without code duplication for + const and non-const overloads - @liveexample{The example below demonstrates the `parse()` function reading - from an array.,parse__array__parser_callback_t} + @tparam ThisType will be deduced as `basic_json` or `const basic_json` - @since version 2.0.3 + @throw type_error.303 if ReferenceType does not match underlying value + type of the current JSON */ - template - static basic_json parse(T (&array)[N], - const parser_callback_t cb = nullptr) + template + static ReferenceType get_ref_impl(ThisType& obj) { - // delegate the call to the iterator-range parse overload - return parse(std::begin(array), std::end(array), cb); - } + // delegate the call to get_ptr<>() + auto ptr = obj.template get_ptr::type>(); - /*! - @brief deserialize from string literal + if (JSON_LIKELY(ptr != nullptr)) + { + return *ptr; + } - @tparam CharT character/literal type with size of 1 byte - @param[in] s string literal to read a serialized JSON value from - @param[in] cb a parser callback function of type @ref parser_callback_t - which is used to control the deserialization by filtering unwanted values - (optional) + JSON_THROW(type_error::create(303, "incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()))); + } - @return result of the deserialization + public: + /// @name value access + /// Direct access to the stored value of a JSON value. + /// @{ - @throw parse_error.101 in case of an unexpected token - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails + /*! + @brief get special-case overload - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. The complexity can be higher if the parser callback function - @a cb has a super-linear complexity. + This overloads avoids a lot of template boilerplate, it can be seen as the + identity method - @note A UTF-8 byte order mark is silently ignored. - @note String containers like `std::string` or @ref string_t can be parsed - with @ref parse(const ContiguousContainer&, const parser_callback_t) + @tparam BasicJsonType == @ref basic_json - @liveexample{The example below demonstrates the `parse()` function with - and without callback function.,parse__string__parser_callback_t} + @return a copy of *this - @sa @ref parse(std::istream&, const parser_callback_t) for a version that - reads from an input stream + @complexity Constant. - @since version 1.0.0 (originally for @ref string_t) + @since version 2.1.0 */ - template::value and - std::is_integral::type>::value and - sizeof(typename std::remove_pointer::type) == 1, int>::type = 0> - static basic_json parse(const CharT s, - const parser_callback_t cb = nullptr) + template::type, basic_json_t>::value, + int> = 0> + basic_json get() const { - return parser(reinterpret_cast(s), cb).parse(); + return *this; } /*! - @brief deserialize from stream + @brief get a value (explicit) - @param[in,out] i stream to read a serialized JSON value from - @param[in] cb a parser callback function of type @ref parser_callback_t - which is used to control the deserialization by filtering unwanted values - (optional) + Explicit type conversion between the JSON value and a compatible value + which is [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible) + and [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible). + The value is converted by calling the @ref json_serializer + `from_json()` method. - @return result of the deserialization + The function is equivalent to executing + @code {.cpp} + ValueType ret; + JSONSerializer::from_json(*this, ret); + return ret; + @endcode - @throw parse_error.101 in case of an unexpected token - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails - @throw parse_error.111 if input stream is in a bad state + This overloads is chosen if: + - @a ValueType is not @ref basic_json, + - @ref json_serializer has a `from_json()` method of the form + `void from_json(const basic_json&, ValueType&)`, and + - @ref json_serializer does not have a `from_json()` method of + the form `ValueType from_json(const basic_json&)` - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. The complexity can be higher if the parser callback function - @a cb has a super-linear complexity. + @tparam ValueTypeCV the provided value type + @tparam ValueType the returned value type - @note A UTF-8 byte order mark is silently ignored. + @return copy of the JSON value, converted to @a ValueType - @liveexample{The example below demonstrates the `parse()` function with - and without callback function.,parse__istream__parser_callback_t} + @throw what @ref json_serializer `from_json()` method throws - @sa @ref parse(const CharT, const parser_callback_t) for a version - that reads from a string + @liveexample{The example below shows several conversions from JSON values + to other types. There a few things to note: (1) Floating-point numbers can + be converted to integers\, (2) A JSON array can be converted to a standard + `std::vector`\, (3) A JSON object can be converted to C++ + associative containers such as `std::unordered_map`.,get__ValueType_const} - @since version 1.0.0 + @since version 2.1.0 */ - static basic_json parse(std::istream& i, - const parser_callback_t cb = nullptr) + template, + detail::enable_if_t < + not std::is_same::value and + detail::has_from_json::value and + not detail::has_non_default_from_json::value, + int> = 0> + ValueType get() const noexcept(noexcept( + JSONSerializer::from_json(std::declval(), std::declval()))) { - return parser(i, cb).parse(); - } + // we cannot static_assert on ValueTypeCV being non-const, because + // there is support for get(), which is why we + // still need the uncvref + static_assert(not std::is_reference::value, + "get() cannot be used with reference types, you might want to use get_ref()"); + static_assert(std::is_default_constructible::value, + "types must be DefaultConstructible when used with get()"); - /*! - @copydoc parse(std::istream&, const parser_callback_t) - */ - static basic_json parse(std::istream&& i, - const parser_callback_t cb = nullptr) - { - return parser(i, cb).parse(); + ValueType ret; + JSONSerializer::from_json(*this, ret); + return ret; } /*! - @brief deserialize from an iterator range with contiguous storage - - This function reads from an iterator range of a container with contiguous - storage of 1-byte values. Compatible container types include - `std::vector`, `std::string`, `std::array`, `std::valarray`, and - `std::initializer_list`. Furthermore, C-style arrays can be used with - `std::begin()`/`std::end()`. User-defined containers can be used as long - as they implement random-access iterators and a contiguous storage. - - @pre The iterator range is contiguous. Violating this precondition yields - undefined behavior. **This precondition is enforced with an assertion.** - @pre Each element in the range has a size of 1 byte. Violating this - precondition yields undefined behavior. **This precondition is enforced - with a static assertion.** + @brief get a value (explicit); special case - @warning There is no way to enforce all preconditions at compile-time. If - the function is called with noncompliant iterators and with - assertions switched off, the behavior is undefined and will most - likely yield segmentation violation. + Explicit type conversion between the JSON value and a compatible value + which is **not** [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible) + and **not** [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible). + The value is converted by calling the @ref json_serializer + `from_json()` method. - @tparam IteratorType iterator of container with contiguous storage - @param[in] first begin of the range to parse (included) - @param[in] last end of the range to parse (excluded) - @param[in] cb a parser callback function of type @ref parser_callback_t - which is used to control the deserialization by filtering unwanted values - (optional) + The function is equivalent to executing + @code {.cpp} + return JSONSerializer::from_json(*this); + @endcode - @return result of the deserialization + This overloads is chosen if: + - @a ValueType is not @ref basic_json and + - @ref json_serializer has a `from_json()` method of the form + `ValueType from_json(const basic_json&)` - @throw parse_error.101 in case of an unexpected token - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails + @note If @ref json_serializer has both overloads of + `from_json()`, this one is chosen. - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. The complexity can be higher if the parser callback function - @a cb has a super-linear complexity. + @tparam ValueTypeCV the provided value type + @tparam ValueType the returned value type - @note A UTF-8 byte order mark is silently ignored. + @return copy of the JSON value, converted to @a ValueType - @liveexample{The example below demonstrates the `parse()` function reading - from an iterator range.,parse__iteratortype__parser_callback_t} + @throw what @ref json_serializer `from_json()` method throws - @since version 2.0.3 + @since version 2.1.0 */ - template::iterator_category>::value, int>::type = 0> - static basic_json parse(IteratorType first, IteratorType last, - const parser_callback_t cb = nullptr) + template, + detail::enable_if_t::value and + detail::has_non_default_from_json::value, + int> = 0> + ValueType get() const noexcept(noexcept( + JSONSerializer::from_json(std::declval()))) { - // assertion to check that the iterator range is indeed contiguous, - // see http://stackoverflow.com/a/35008842/266378 for more discussion - assert(std::accumulate(first, last, std::pair(true, 0), - [&first](std::pair res, decltype(*first) val) - { - res.first &= (val == *(std::next(std::addressof(*first), res.second++))); - return res; - }).first); - - // assertion to check that each element is 1 byte long - static_assert(sizeof(typename std::iterator_traits::value_type) == 1, - "each element in the iterator range must have the size of 1 byte"); - - // if iterator range is empty, create a parser with an empty string - // to generate "unexpected EOF" error message - if (std::distance(first, last) <= 0) - { - return parser("").parse(); - } - - return parser(first, last, cb).parse(); + static_assert(not std::is_reference::value, + "get() cannot be used with reference types, you might want to use get_ref()"); + return JSONSerializer::from_json(*this); } /*! - @brief deserialize from a container with contiguous storage - - This function reads from a container with contiguous storage of 1-byte - values. Compatible container types include `std::vector`, `std::string`, - `std::array`, and `std::initializer_list`. User-defined containers can be - used as long as they implement random-access iterators and a contiguous - storage. - - @pre The container storage is contiguous. Violating this precondition - yields undefined behavior. **This precondition is enforced with an - assertion.** - @pre Each element of the container has a size of 1 byte. Violating this - precondition yields undefined behavior. **This precondition is enforced - with a static assertion.** + @brief get a pointer value (explicit) - @warning There is no way to enforce all preconditions at compile-time. If - the function is called with a noncompliant container and with - assertions switched off, the behavior is undefined and will most - likely yield segmentation violation. + Explicit pointer access to the internally stored JSON value. No copies are + made. - @tparam ContiguousContainer container type with contiguous storage - @param[in] c container to read from - @param[in] cb a parser callback function of type @ref parser_callback_t - which is used to control the deserialization by filtering unwanted values - (optional) + @warning The pointer becomes invalid if the underlying JSON object + changes. - @return result of the deserialization + @tparam PointerType pointer type; must be a pointer to @ref array_t, @ref + object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, + @ref number_unsigned_t, or @ref number_float_t. - @throw parse_error.101 in case of an unexpected token - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails + @return pointer to the internally stored JSON value if the requested + pointer type @a PointerType fits to the JSON value; `nullptr` otherwise - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. The complexity can be higher if the parser callback function - @a cb has a super-linear complexity. + @complexity Constant. - @note A UTF-8 byte order mark is silently ignored. + @liveexample{The example below shows how pointers to internal values of a + JSON value can be requested. Note that no type conversions are made and a + `nullptr` is returned if the value and the requested pointer type does not + match.,get__PointerType} - @liveexample{The example below demonstrates the `parse()` function reading - from a contiguous container.,parse__contiguouscontainer__parser_callback_t} + @sa @ref get_ptr() for explicit pointer-member access - @since version 2.0.3 + @since version 1.0.0 */ - template::value and - std::is_base_of< - std::random_access_iterator_tag, - typename std::iterator_traits()))>::iterator_category>::value - , int>::type = 0> - static basic_json parse(const ContiguousContainer& c, - const parser_callback_t cb = nullptr) + template::value, int>::type = 0> + PointerType get() noexcept { - // delegate the call to the iterator-range parse overload - return parse(std::begin(c), std::end(c), cb); + // delegate the call to get_ptr + return get_ptr(); } /*! - @brief deserialize from stream - @deprecated This stream operator is deprecated and will be removed in a - future version of the library. Please use - @ref std::istream& operator>>(std::istream&, basic_json&) - instead; that is, replace calls like `j << i;` with `i >> j;`. + @brief get a pointer value (explicit) + @copydoc get() */ - JSON_DEPRECATED - friend std::istream& operator<<(basic_json& j, std::istream& i) + template::value, int>::type = 0> + constexpr const PointerType get() const noexcept { - j = parser(i).parse(); - return i; + // delegate the call to get_ptr + return get_ptr(); } /*! - @brief deserialize from stream - - Deserializes an input stream to a JSON value. + @brief get a pointer value (implicit) - @param[in,out] i input stream to read a serialized JSON value from - @param[in,out] j JSON value to write the deserialized input to + Implicit pointer access to the internally stored JSON value. No copies are + made. - @throw parse_error.101 in case of an unexpected token - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails - @throw parse_error.111 if input stream is in a bad state + @warning Writing data to the pointee of the result yields an undefined + state. - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. + @tparam PointerType pointer type; must be a pointer to @ref array_t, @ref + object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, + @ref number_unsigned_t, or @ref number_float_t. Enforced by a static + assertion. - @note A UTF-8 byte order mark is silently ignored. + @return pointer to the internally stored JSON value if the requested + pointer type @a PointerType fits to the JSON value; `nullptr` otherwise - @liveexample{The example below shows how a JSON value is constructed by - reading a serialization from a stream.,operator_deserialize} + @complexity Constant. - @sa parse(std::istream&, const parser_callback_t) for a variant with a - parser callback function to filter values while parsing + @liveexample{The example below shows how pointers to internal values of a + JSON value can be requested. Note that no type conversions are made and a + `nullptr` is returned if the value and the requested pointer type does not + match.,get_ptr} @since version 1.0.0 */ - friend std::istream& operator>>(std::istream& i, basic_json& j) + template::value, int>::type = 0> + PointerType get_ptr() noexcept { - j = parser(i).parse(); - return i; - } - - /// @} - - ////////////////////////////////////////// - // binary serialization/deserialization // - ////////////////////////////////////////// + // get the type of the PointerType (remove pointer and const) + using pointee_t = typename std::remove_const::type>::type>::type; + // make sure the type matches the allowed types + static_assert( + std::is_same::value + or std::is_same::value + or std::is_same::value + or std::is_same::value + or std::is_same::value + or std::is_same::value + or std::is_same::value + , "incompatible pointer type"); - /// @name binary serialization/deserialization support - /// @{ + // delegate the call to get_impl_ptr<>() + return get_impl_ptr(static_cast(nullptr)); + } - private: /*! - @note Some code in the switch cases has been copied, because otherwise - copilers would complain about implicit fallthrough and there is no - portable attribute to mute such warnings. + @brief get a pointer value (implicit) + @copydoc get_ptr() */ - template - static void add_to_vector(std::vector& vec, size_t bytes, const T number) + template::value and + std::is_const::type>::value, int>::type = 0> + constexpr const PointerType get_ptr() const noexcept { - assert(bytes == 1 or bytes == 2 or bytes == 4 or bytes == 8); + // get the type of the PointerType (remove pointer and const) + using pointee_t = typename std::remove_const::type>::type>::type; + // make sure the type matches the allowed types + static_assert( + std::is_same::value + or std::is_same::value + or std::is_same::value + or std::is_same::value + or std::is_same::value + or std::is_same::value + or std::is_same::value + , "incompatible pointer type"); - switch (bytes) - { - case 8: - { - vec.push_back(static_cast((static_cast(number) >> 070) & 0xff)); - vec.push_back(static_cast((static_cast(number) >> 060) & 0xff)); - vec.push_back(static_cast((static_cast(number) >> 050) & 0xff)); - vec.push_back(static_cast((static_cast(number) >> 040) & 0xff)); - vec.push_back(static_cast((number >> 030) & 0xff)); - vec.push_back(static_cast((number >> 020) & 0xff)); - vec.push_back(static_cast((number >> 010) & 0xff)); - vec.push_back(static_cast(number & 0xff)); - break; - } + // delegate the call to get_impl_ptr<>() const + return get_impl_ptr(static_cast(nullptr)); + } - case 4: - { - vec.push_back(static_cast((number >> 030) & 0xff)); - vec.push_back(static_cast((number >> 020) & 0xff)); - vec.push_back(static_cast((number >> 010) & 0xff)); - vec.push_back(static_cast(number & 0xff)); - break; - } + /*! + @brief get a reference value (implicit) - case 2: - { - vec.push_back(static_cast((number >> 010) & 0xff)); - vec.push_back(static_cast(number & 0xff)); - break; - } + Implicit reference access to the internally stored JSON value. No copies + are made. - case 1: - { - vec.push_back(static_cast(number & 0xff)); - break; - } - } + @warning Writing data to the referee of the result yields an undefined + state. + + @tparam ReferenceType reference type; must be a reference to @ref array_t, + @ref object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, or + @ref number_float_t. Enforced by static assertion. + + @return reference to the internally stored JSON value if the requested + reference type @a ReferenceType fits to the JSON value; throws + type_error.303 otherwise + + @throw type_error.303 in case passed type @a ReferenceType is incompatible + with the stored JSON value; see example below + + @complexity Constant. + + @liveexample{The example shows several calls to `get_ref()`.,get_ref} + + @since version 1.1.0 + */ + template::value, int>::type = 0> + ReferenceType get_ref() + { + // delegate call to get_ref_impl + return get_ref_impl(*this); + } + + /*! + @brief get a reference value (implicit) + @copydoc get_ref() + */ + template::value and + std::is_const::type>::value, int>::type = 0> + ReferenceType get_ref() const + { + // delegate call to get_ref_impl + return get_ref_impl(*this); } /*! - @brief take sufficient bytes from a vector to fill an integer variable + @brief get a value (implicit) + + Implicit type conversion between the JSON value and a compatible value. + The call is realized by calling @ref get() const. + + @tparam ValueType non-pointer type compatible to the JSON value, for + instance `int` for JSON integer numbers, `bool` for JSON booleans, or + `std::vector` types for JSON arrays. The character type of @ref string_t + as well as an initializer list of this type is excluded to avoid + ambiguities as these types implicitly convert to `std::string`. + + @return copy of the JSON value, converted to type @a ValueType + + @throw type_error.302 in case passed type @a ValueType is incompatible + to the JSON value type (e.g., the JSON value is of type boolean, but a + string is requested); see example below + + @complexity Linear in the size of the JSON value. + + @liveexample{The example below shows several conversions from JSON values + to other types. There a few things to note: (1) Floating-point numbers can + be converted to integers\, (2) A JSON array can be converted to a standard + `std::vector`\, (3) A JSON object can be converted to C++ + associative containers such as `std::unordered_map`.,operator__ValueType} + + @since version 1.0.0 + */ + template < typename ValueType, typename std::enable_if < + not std::is_pointer::value and + not std::is_same>::value and + not std::is_same::value +#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015 + and not std::is_same>::value +#endif +#if defined(JSON_HAS_CPP_17) + and not std::is_same::value +#endif + , int >::type = 0 > + operator ValueType() const + { + // delegate the call to get<>() const + return get(); + } + + /// @} - In the context of binary serialization formats, we need to read several - bytes from a byte vector and combine them to multi-byte integral data - types. - @param[in] vec byte vector to read from - @param[in] current_index the position in the vector after which to read + //////////////////// + // element access // + //////////////////// + + /// @name element access + /// Access to the JSON value. + /// @{ - @return the next sizeof(T) bytes from @a vec, in reverse order as T + /*! + @brief access specified array element with bounds checking - @tparam T the integral return type + Returns a reference to the element at specified location @a idx, with + bounds checking. - @throw parse_error.110 if there are less than sizeof(T)+1 bytes in the - vector @a vec to read + @param[in] idx index of the element to access - In the for loop, the bytes from the vector are copied in reverse order into - the return value. In the figures below, let sizeof(T)=4 and `i` be the loop - variable. + @return reference to the element at index @a idx - Precondition: + @throw type_error.304 if the JSON value is not an array; in this case, + calling `at` with an index makes no sense. See example below. + @throw out_of_range.401 if the index @a idx is out of range of the array; + that is, `idx >= size()`. See example below. - vec: | | | a | b | c | d | T: | | | | | - ^ ^ ^ ^ - current_index i ptr sizeof(T) + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. - Postcondition: + @complexity Constant. - vec: | | | a | b | c | d | T: | d | c | b | a | - ^ ^ ^ - | i ptr - current_index + @since version 1.0.0 - @sa Code adapted from . + @liveexample{The example below shows how array elements can be read and + written using `at()`. It also demonstrates the different exceptions that + can be thrown.,at__size_type} */ - template - static T get_from_vector(const std::vector& vec, const size_t current_index) + reference at(size_type idx) { - // check if we can read sizeof(T) bytes starting the next index - check_length(vec.size(), sizeof(T), current_index + 1); - - T result; - auto* ptr = reinterpret_cast(&result); - for (size_t i = 0; i < sizeof(T); ++i) + // at only works for arrays + if (JSON_LIKELY(is_array())) + { + JSON_TRY + { + return m_value.array->at(idx); + } + JSON_CATCH (std::out_of_range&) + { + // create better exception explanation + JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range")); + } + } + else { - *ptr++ = vec[current_index + sizeof(T) - i]; + JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()))); } - return result; } /*! - @brief create a MessagePack serialization of a given JSON value + @brief access specified array element with bounds checking + + Returns a const reference to the element at specified location @a idx, + with bounds checking. - This is a straightforward implementation of the MessagePack specification. + @param[in] idx index of the element to access - @param[in] j JSON value to serialize - @param[in,out] v byte vector to write the serialization to + @return const reference to the element at index @a idx + + @throw type_error.304 if the JSON value is not an array; in this case, + calling `at` with an index makes no sense. See example below. + @throw out_of_range.401 if the index @a idx is out of range of the array; + that is, `idx >= size()`. See example below. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @complexity Constant. + + @since version 1.0.0 - @sa https://github.com/msgpack/msgpack/blob/master/spec.md + @liveexample{The example below shows how array elements can be read using + `at()`. It also demonstrates the different exceptions that can be thrown., + at__size_type_const} */ - static void to_msgpack_internal(const basic_json& j, std::vector& v) + const_reference at(size_type idx) const { - switch (j.type()) + // at only works for arrays + if (JSON_LIKELY(is_array())) { - case value_t::null: + JSON_TRY { - // nil - v.push_back(0xc0); - break; + return m_value.array->at(idx); } - - case value_t::boolean: + JSON_CATCH (std::out_of_range&) { - // true and false - v.push_back(j.m_value.boolean ? 0xc3 : 0xc2); - break; + // create better exception explanation + JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range")); } + } + else + { + JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()))); + } + } - case value_t::number_integer: - { - if (j.m_value.number_integer >= 0) - { - // MessagePack does not differentiate between positive - // signed integers and unsigned integers. Therefore, we - // used the code from the value_t::number_unsigned case - // here. - if (j.m_value.number_unsigned < 128) - { - // positive fixnum - add_to_vector(v, 1, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) - { - // uint 8 - v.push_back(0xcc); - add_to_vector(v, 1, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) - { - // uint 16 - v.push_back(0xcd); - add_to_vector(v, 2, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) - { - // uint 32 - v.push_back(0xce); - add_to_vector(v, 4, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) - { - // uint 64 - v.push_back(0xcf); - add_to_vector(v, 8, j.m_value.number_unsigned); - } - } - else - { - if (j.m_value.number_integer >= -32) - { - // negative fixnum - add_to_vector(v, 1, j.m_value.number_integer); - } - else if (j.m_value.number_integer >= (std::numeric_limits::min)() and j.m_value.number_integer <= (std::numeric_limits::max)()) - { - // int 8 - v.push_back(0xd0); - add_to_vector(v, 1, j.m_value.number_integer); - } - else if (j.m_value.number_integer >= (std::numeric_limits::min)() and j.m_value.number_integer <= (std::numeric_limits::max)()) - { - // int 16 - v.push_back(0xd1); - add_to_vector(v, 2, j.m_value.number_integer); - } - else if (j.m_value.number_integer >= (std::numeric_limits::min)() and j.m_value.number_integer <= (std::numeric_limits::max)()) - { - // int 32 - v.push_back(0xd2); - add_to_vector(v, 4, j.m_value.number_integer); - } - else if (j.m_value.number_integer >= (std::numeric_limits::min)() and j.m_value.number_integer <= (std::numeric_limits::max)()) - { - // int 64 - v.push_back(0xd3); - add_to_vector(v, 8, j.m_value.number_integer); - } - } - break; - } + /*! + @brief access specified object element with bounds checking - case value_t::number_unsigned: - { - if (j.m_value.number_unsigned < 128) - { - // positive fixnum - add_to_vector(v, 1, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) - { - // uint 8 - v.push_back(0xcc); - add_to_vector(v, 1, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) - { - // uint 16 - v.push_back(0xcd); - add_to_vector(v, 2, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) - { - // uint 32 - v.push_back(0xce); - add_to_vector(v, 4, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) - { - // uint 64 - v.push_back(0xcf); - add_to_vector(v, 8, j.m_value.number_unsigned); - } - break; - } + Returns a reference to the element at with specified key @a key, with + bounds checking. - case value_t::number_float: - { - // float 64 - v.push_back(0xcb); - const auto* helper = reinterpret_cast(&(j.m_value.number_float)); - for (size_t i = 0; i < 8; ++i) - { - v.push_back(helper[7 - i]); - } - break; - } + @param[in] key key of the element to access - case value_t::string: - { - const auto N = j.m_value.string->size(); - if (N <= 31) - { - // fixstr - v.push_back(static_cast(0xa0 | N)); - } - else if (N <= 255) - { - // str 8 - v.push_back(0xd9); - add_to_vector(v, 1, N); - } - else if (N <= 65535) - { - // str 16 - v.push_back(0xda); - add_to_vector(v, 2, N); - } - else if (N <= 4294967295) - { - // str 32 - v.push_back(0xdb); - add_to_vector(v, 4, N); - } + @return reference to the element at key @a key - // append string - std::copy(j.m_value.string->begin(), j.m_value.string->end(), - std::back_inserter(v)); - break; - } + @throw type_error.304 if the JSON value is not an object; in this case, + calling `at` with a key makes no sense. See example below. + @throw out_of_range.403 if the key @a key is is not stored in the object; + that is, `find(key) == end()`. See example below. - case value_t::array: - { - const auto N = j.m_value.array->size(); - if (N <= 15) - { - // fixarray - v.push_back(static_cast(0x90 | N)); - } - else if (N <= 0xffff) - { - // array 16 - v.push_back(0xdc); - add_to_vector(v, 2, N); - } - else if (N <= 0xffffffff) - { - // array 32 - v.push_back(0xdd); - add_to_vector(v, 4, N); - } + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. - // append each element - for (const auto& el : *j.m_value.array) - { - to_msgpack_internal(el, v); - } - break; - } + @complexity Logarithmic in the size of the container. - case value_t::object: - { - const auto N = j.m_value.object->size(); - if (N <= 15) - { - // fixmap - v.push_back(static_cast(0x80 | (N & 0xf))); - } - else if (N <= 65535) - { - // map 16 - v.push_back(0xde); - add_to_vector(v, 2, N); - } - else if (N <= 4294967295) - { - // map 32 - v.push_back(0xdf); - add_to_vector(v, 4, N); - } + @sa @ref operator[](const typename object_t::key_type&) for unchecked + access by reference + @sa @ref value() for access by value with a default value - // append each element - for (const auto& el : *j.m_value.object) - { - to_msgpack_internal(el.first, v); - to_msgpack_internal(el.second, v); - } - break; - } + @since version 1.0.0 - default: + @liveexample{The example below shows how object elements can be read and + written using `at()`. It also demonstrates the different exceptions that + can be thrown.,at__object_t_key_type} + */ + reference at(const typename object_t::key_type& key) + { + // at only works for objects + if (JSON_LIKELY(is_object())) + { + JSON_TRY { - break; + return m_value.object->at(key); + } + JSON_CATCH (std::out_of_range&) + { + // create better exception explanation + JSON_THROW(out_of_range::create(403, "key '" + key + "' not found")); } } + else + { + JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()))); + } } /*! - @brief create a CBOR serialization of a given JSON value + @brief access specified object element with bounds checking - This is a straightforward implementation of the CBOR specification. + Returns a const reference to the element at with specified key @a key, + with bounds checking. - @param[in] j JSON value to serialize - @param[in,out] v byte vector to write the serialization to + @param[in] key key of the element to access + + @return const reference to the element at key @a key + + @throw type_error.304 if the JSON value is not an object; in this case, + calling `at` with a key makes no sense. See example below. + @throw out_of_range.403 if the key @a key is is not stored in the object; + that is, `find(key) == end()`. See example below. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @complexity Logarithmic in the size of the container. + + @sa @ref operator[](const typename object_t::key_type&) for unchecked + access by reference + @sa @ref value() for access by value with a default value + + @since version 1.0.0 - @sa https://tools.ietf.org/html/rfc7049 + @liveexample{The example below shows how object elements can be read using + `at()`. It also demonstrates the different exceptions that can be thrown., + at__object_t_key_type_const} */ - static void to_cbor_internal(const basic_json& j, std::vector& v) + const_reference at(const typename object_t::key_type& key) const { - switch (j.type()) + // at only works for objects + if (JSON_LIKELY(is_object())) { - case value_t::null: + JSON_TRY { - v.push_back(0xf6); - break; + return m_value.object->at(key); } - - case value_t::boolean: + JSON_CATCH (std::out_of_range&) { - v.push_back(j.m_value.boolean ? 0xf5 : 0xf4); - break; + // create better exception explanation + JSON_THROW(out_of_range::create(403, "key '" + key + "' not found")); } + } + else + { + JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()))); + } + } - case value_t::number_integer: - { - if (j.m_value.number_integer >= 0) - { - // CBOR does not differentiate between positive signed - // integers and unsigned integers. Therefore, we used the - // code from the value_t::number_unsigned case here. - if (j.m_value.number_integer <= 0x17) - { - add_to_vector(v, 1, j.m_value.number_integer); - } - else if (j.m_value.number_integer <= (std::numeric_limits::max)()) - { - v.push_back(0x18); - // one-byte uint8_t - add_to_vector(v, 1, j.m_value.number_integer); - } - else if (j.m_value.number_integer <= (std::numeric_limits::max)()) - { - v.push_back(0x19); - // two-byte uint16_t - add_to_vector(v, 2, j.m_value.number_integer); - } - else if (j.m_value.number_integer <= (std::numeric_limits::max)()) - { - v.push_back(0x1a); - // four-byte uint32_t - add_to_vector(v, 4, j.m_value.number_integer); - } - else - { - v.push_back(0x1b); - // eight-byte uint64_t - add_to_vector(v, 8, j.m_value.number_integer); - } - } - else - { - // The conversions below encode the sign in the first - // byte, and the value is converted to a positive number. - const auto positive_number = -1 - j.m_value.number_integer; - if (j.m_value.number_integer >= -24) - { - v.push_back(static_cast(0x20 + positive_number)); - } - else if (positive_number <= (std::numeric_limits::max)()) - { - // int 8 - v.push_back(0x38); - add_to_vector(v, 1, positive_number); - } - else if (positive_number <= (std::numeric_limits::max)()) - { - // int 16 - v.push_back(0x39); - add_to_vector(v, 2, positive_number); - } - else if (positive_number <= (std::numeric_limits::max)()) - { - // int 32 - v.push_back(0x3a); - add_to_vector(v, 4, positive_number); - } - else - { - // int 64 - v.push_back(0x3b); - add_to_vector(v, 8, positive_number); - } - } - break; - } + /*! + @brief access specified array element - case value_t::number_unsigned: - { - if (j.m_value.number_unsigned <= 0x17) - { - v.push_back(static_cast(j.m_value.number_unsigned)); - } - else if (j.m_value.number_unsigned <= 0xff) - { - v.push_back(0x18); - // one-byte uint8_t - add_to_vector(v, 1, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= 0xffff) - { - v.push_back(0x19); - // two-byte uint16_t - add_to_vector(v, 2, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= 0xffffffff) - { - v.push_back(0x1a); - // four-byte uint32_t - add_to_vector(v, 4, j.m_value.number_unsigned); - } - else if (j.m_value.number_unsigned <= 0xffffffffffffffff) - { - v.push_back(0x1b); - // eight-byte uint64_t - add_to_vector(v, 8, j.m_value.number_unsigned); - } - break; - } + Returns a reference to the element at specified location @a idx. - case value_t::number_float: - { - // Double-Precision Float - v.push_back(0xfb); - const auto* helper = reinterpret_cast(&(j.m_value.number_float)); - for (size_t i = 0; i < 8; ++i) - { - v.push_back(helper[7 - i]); - } - break; - } + @note If @a idx is beyond the range of the array (i.e., `idx >= size()`), + then the array is silently filled up with `null` values to make `idx` a + valid reference to the last stored element. - case value_t::string: - { - const auto N = j.m_value.string->size(); - if (N <= 0x17) - { - v.push_back(static_cast(0x60 + N)); // 1 byte for string + size - } - else if (N <= 0xff) - { - v.push_back(0x78); // one-byte uint8_t for N - add_to_vector(v, 1, N); - } - else if (N <= 0xffff) - { - v.push_back(0x79); // two-byte uint16_t for N - add_to_vector(v, 2, N); - } - else if (N <= 0xffffffff) - { - v.push_back(0x7a); // four-byte uint32_t for N - add_to_vector(v, 4, N); - } - // LCOV_EXCL_START - else if (N <= 0xffffffffffffffff) - { - v.push_back(0x7b); // eight-byte uint64_t for N - add_to_vector(v, 8, N); - } - // LCOV_EXCL_STOP + @param[in] idx index of the element to access - // append string - std::copy(j.m_value.string->begin(), j.m_value.string->end(), - std::back_inserter(v)); - break; - } + @return reference to the element at index @a idx - case value_t::array: - { - const auto N = j.m_value.array->size(); - if (N <= 0x17) - { - v.push_back(static_cast(0x80 + N)); // 1 byte for array + size - } - else if (N <= 0xff) - { - v.push_back(0x98); // one-byte uint8_t for N - add_to_vector(v, 1, N); - } - else if (N <= 0xffff) - { - v.push_back(0x99); // two-byte uint16_t for N - add_to_vector(v, 2, N); - } - else if (N <= 0xffffffff) - { - v.push_back(0x9a); // four-byte uint32_t for N - add_to_vector(v, 4, N); - } - // LCOV_EXCL_START - else if (N <= 0xffffffffffffffff) - { - v.push_back(0x9b); // eight-byte uint64_t for N - add_to_vector(v, 8, N); - } - // LCOV_EXCL_STOP + @throw type_error.305 if the JSON value is not an array or null; in that + cases, using the [] operator with an index makes no sense. - // append each element - for (const auto& el : *j.m_value.array) - { - to_cbor_internal(el, v); - } - break; - } + @complexity Constant if @a idx is in the range of the array. Otherwise + linear in `idx - size()`. - case value_t::object: - { - const auto N = j.m_value.object->size(); - if (N <= 0x17) - { - v.push_back(static_cast(0xa0 + N)); // 1 byte for object + size - } - else if (N <= 0xff) - { - v.push_back(0xb8); - add_to_vector(v, 1, N); // one-byte uint8_t for N - } - else if (N <= 0xffff) - { - v.push_back(0xb9); - add_to_vector(v, 2, N); // two-byte uint16_t for N - } - else if (N <= 0xffffffff) - { - v.push_back(0xba); - add_to_vector(v, 4, N); // four-byte uint32_t for N - } - // LCOV_EXCL_START - else if (N <= 0xffffffffffffffff) - { - v.push_back(0xbb); - add_to_vector(v, 8, N); // eight-byte uint64_t for N - } - // LCOV_EXCL_STOP + @liveexample{The example below shows how array elements can be read and + written using `[]` operator. Note the addition of `null` + values.,operatorarray__size_type} - // append each element - for (const auto& el : *j.m_value.object) - { - to_cbor_internal(el.first, v); - to_cbor_internal(el.second, v); - } - break; - } + @since version 1.0.0 + */ + reference operator[](size_type idx) + { + // implicitly convert null value to an empty array + if (is_null()) + { + m_type = value_t::array; + m_value.array = create(); + assert_invariant(); + } - default: + // operator[] only works for arrays + if (JSON_LIKELY(is_array())) + { + // fill up array with null values if given idx is outside range + if (idx >= m_value.array->size()) { - break; + m_value.array->insert(m_value.array->end(), + idx - m_value.array->size() + 1, + basic_json()); } + + return m_value.array->operator[](idx); } + + JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name()))); } + /*! + @brief access specified array element - /* - @brief checks if given lengths do not exceed the size of a given vector + Returns a const reference to the element at specified location @a idx. + + @param[in] idx index of the element to access - To secure the access to the byte vector during CBOR/MessagePack - deserialization, bytes are copied from the vector into buffers. This - function checks if the number of bytes to copy (@a len) does not exceed - the size @s size of the vector. Additionally, an @a offset is given from - where to start reading the bytes. + @return const reference to the element at index @a idx - This function checks whether reading the bytes is safe; that is, offset is - a valid index in the vector, offset+len + @throw type_error.305 if the JSON value is not an array; in that case, + using the [] operator with an index makes no sense. - @param[in] size size of the byte vector - @param[in] len number of bytes to read - @param[in] offset offset where to start reading + @complexity Constant. - vec: x x x x x X X X X X - ^ ^ ^ - 0 offset len + @liveexample{The example below shows how array elements can be read using + the `[]` operator.,operatorarray__size_type_const} - @throws out_of_range if `len > v.size()` + @since version 1.0.0 */ - static void check_length(const size_t size, const size_t len, const size_t offset) + const_reference operator[](size_type idx) const { - // simple case: requested length is greater than the vector's length - if (len > size or offset > size) - { - JSON_THROW(parse_error::create(110, offset + 1, "cannot read " + std::to_string(len) + " bytes from vector")); - } - - // second case: adding offset would result in overflow - if ((size > ((std::numeric_limits::max)() - offset))) + // const operator[] only works for arrays + if (JSON_LIKELY(is_array())) { - JSON_THROW(parse_error::create(110, offset + 1, "cannot read " + std::to_string(len) + " bytes from vector")); + return m_value.array->operator[](idx); } - // last case: reading past the end of the vector - if (len + offset > size) - { - JSON_THROW(parse_error::create(110, offset + 1, "cannot read " + std::to_string(len) + " bytes from vector")); - } + JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name()))); } /*! - @brief check if the next byte belongs to a string + @brief access specified object element + + Returns a reference to the element at with specified key @a key. + + @note If @a key is not found in the object, then it is silently added to + the object and filled with a `null` value to make `key` a valid reference. + In case the value was `null` before, it is converted to an object. + + @param[in] key key of the element to access + + @return reference to the element at key @a key - While parsing a map, the keys must be strings. This function checks if the - current byte is one of the start bytes for a string in MessagePack: + @throw type_error.305 if the JSON value is not an object or null; in that + cases, using the [] operator with a key makes no sense. + + @complexity Logarithmic in the size of the container. - - 0xa0 - 0xbf: fixstr - - 0xd9: str 8 - - 0xda: str 16 - - 0xdb: str 32 + @liveexample{The example below shows how object elements can be read and + written using the `[]` operator.,operatorarray__key_type} - @param[in] v MessagePack serialization - @param[in] idx byte index in @a v to check for a string + @sa @ref at(const typename object_t::key_type&) for access by reference + with range checking + @sa @ref value() for access by value with a default value - @throw parse_error.113 if `v[idx]` does not belong to a string + @since version 1.0.0 */ - static void msgpack_expect_string(const std::vector& v, size_t idx) + reference operator[](const typename object_t::key_type& key) { - check_length(v.size(), 1, idx); + // implicitly convert null value to an empty object + if (is_null()) + { + m_type = value_t::object; + m_value.object = create(); + assert_invariant(); + } - const auto byte = v[idx]; - if ((byte >= 0xa0 and byte <= 0xbf) or (byte >= 0xd9 and byte <= 0xdb)) + // operator[] only works for objects + if (JSON_LIKELY(is_object())) { - return; + return m_value.object->operator[](key); } - std::stringstream ss; - ss << std::hex << static_cast(v[idx]); - JSON_THROW(parse_error::create(113, idx + 1, "expected a MessagePack string; last byte: 0x" + ss.str())); + JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name()))); } /*! - @brief check if the next byte belongs to a string + @brief read-only access specified object element + + Returns a const reference to the element at with specified key @a key. No + bounds checking is performed. + + @warning If the element with key @a key does not exist, the behavior is + undefined. + + @param[in] key key of the element to access + + @return const reference to the element at key @a key - While parsing a map, the keys must be strings. This function checks if the - current byte is one of the start bytes for a string in CBOR: + @pre The element with key @a key must exist. **This precondition is + enforced with an assertion.** + + @throw type_error.305 if the JSON value is not an object; in that case, + using the [] operator with a key makes no sense. - - 0x60 - 0x77: fixed length - - 0x78 - 0x7b: variable length - - 0x7f: indefinity length + @complexity Logarithmic in the size of the container. + + @liveexample{The example below shows how object elements can be read using + the `[]` operator.,operatorarray__key_type_const} - @param[in] v CBOR serialization - @param[in] idx byte index in @a v to check for a string + @sa @ref at(const typename object_t::key_type&) for access by reference + with range checking + @sa @ref value() for access by value with a default value - @throw parse_error.113 if `v[idx]` does not belong to a string + @since version 1.0.0 */ - static void cbor_expect_string(const std::vector& v, size_t idx) + const_reference operator[](const typename object_t::key_type& key) const { - check_length(v.size(), 1, idx); - - const auto byte = v[idx]; - if ((byte >= 0x60 and byte <= 0x7b) or byte == 0x7f) + // const operator[] only works for objects + if (JSON_LIKELY(is_object())) { - return; + assert(m_value.object->find(key) != m_value.object->end()); + return m_value.object->find(key)->second; } - std::stringstream ss; - ss << std::hex << static_cast(v[idx]); - JSON_THROW(parse_error::create(113, idx + 1, "expected a CBOR string; last byte: 0x" + ss.str())); + JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name()))); } /*! - @brief create a JSON value from a given MessagePack vector + @brief access specified object element - @param[in] v MessagePack serialization - @param[in] idx byte index to start reading from @a v + Returns a reference to the element at with specified key @a key. - @return deserialized JSON value + @note If @a key is not found in the object, then it is silently added to + the object and filled with a `null` value to make `key` a valid reference. + In case the value was `null` before, it is converted to an object. - @throw parse_error.110 if the given vector ends prematurely - @throw parse_error.112 if unsupported features from MessagePack were - used in the given vector @a v or if the input is not valid MessagePack - @throw parse_error.113 if a string was expected as map key, but not found + @param[in] key key of the element to access - @sa https://github.com/msgpack/msgpack/blob/master/spec.md - */ - static basic_json from_msgpack_internal(const std::vector& v, size_t& idx) - { - // store and increment index - const size_t current_idx = idx++; + @return reference to the element at key @a key + + @throw type_error.305 if the JSON value is not an object or null; in that + cases, using the [] operator with a key makes no sense. + + @complexity Logarithmic in the size of the container. + + @liveexample{The example below shows how object elements can be read and + written using the `[]` operator.,operatorarray__key_type} - // make sure reading 1 byte is safe - check_length(v.size(), 1, current_idx); + @sa @ref at(const typename object_t::key_type&) for access by reference + with range checking + @sa @ref value() for access by value with a default value - if (v[current_idx] <= 0xbf) + @since version 1.1.0 + */ + template + reference operator[](T* key) + { + // implicitly convert null to object + if (is_null()) { - if (v[current_idx] <= 0x7f) // positive fixint - { - return v[current_idx]; - } - if (v[current_idx] <= 0x8f) // fixmap - { - basic_json result = value_t::object; - const size_t len = v[current_idx] & 0x0f; - for (size_t i = 0; i < len; ++i) - { - msgpack_expect_string(v, idx); - std::string key = from_msgpack_internal(v, idx); - result[key] = from_msgpack_internal(v, idx); - } - return result; - } - else if (v[current_idx] <= 0x9f) // fixarray - { - basic_json result = value_t::array; - const size_t len = v[current_idx] & 0x0f; - for (size_t i = 0; i < len; ++i) - { - result.push_back(from_msgpack_internal(v, idx)); - } - return result; - } - else // fixstr - { - const size_t len = v[current_idx] & 0x1f; - const size_t offset = current_idx + 1; - idx += len; // skip content bytes - check_length(v.size(), len, offset); - return std::string(reinterpret_cast(v.data()) + offset, len); - } + m_type = value_t::object; + m_value = value_t::object; + assert_invariant(); } - else if (v[current_idx] >= 0xe0) // negative fixint + + // at only works for objects + if (JSON_LIKELY(is_object())) { - return static_cast(v[current_idx]); + return m_value.object->operator[](key); } - else - { - switch (v[current_idx]) - { - case 0xc0: // nil - { - return value_t::null; - } - case 0xc2: // false - { - return false; - } + JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name()))); + } - case 0xc3: // true - { - return true; - } + /*! + @brief read-only access specified object element - case 0xca: // float 32 - { - // copy bytes in reverse order into the double variable - float res; - check_length(v.size(), sizeof(float), current_idx + 1); - for (size_t byte = 0; byte < sizeof(float); ++byte) - { - reinterpret_cast(&res)[sizeof(float) - byte - 1] = v[current_idx + 1 + byte]; - } - idx += sizeof(float); // skip content bytes - return res; - } + Returns a const reference to the element at with specified key @a key. No + bounds checking is performed. - case 0xcb: // float 64 - { - // copy bytes in reverse order into the double variable - double res; - check_length(v.size(), sizeof(double), current_idx + 1); - for (size_t byte = 0; byte < sizeof(double); ++byte) - { - reinterpret_cast(&res)[sizeof(double) - byte - 1] = v[current_idx + 1 + byte]; - } - idx += sizeof(double); // skip content bytes - return res; - } + @warning If the element with key @a key does not exist, the behavior is + undefined. - case 0xcc: // uint 8 - { - idx += 1; // skip content byte - return get_from_vector(v, current_idx); - } + @param[in] key key of the element to access - case 0xcd: // uint 16 - { - idx += 2; // skip 2 content bytes - return get_from_vector(v, current_idx); - } + @return const reference to the element at key @a key - case 0xce: // uint 32 - { - idx += 4; // skip 4 content bytes - return get_from_vector(v, current_idx); - } + @pre The element with key @a key must exist. **This precondition is + enforced with an assertion.** - case 0xcf: // uint 64 - { - idx += 8; // skip 8 content bytes - return get_from_vector(v, current_idx); - } + @throw type_error.305 if the JSON value is not an object; in that case, + using the [] operator with a key makes no sense. - case 0xd0: // int 8 - { - idx += 1; // skip content byte - return get_from_vector(v, current_idx); - } + @complexity Logarithmic in the size of the container. - case 0xd1: // int 16 - { - idx += 2; // skip 2 content bytes - return get_from_vector(v, current_idx); - } + @liveexample{The example below shows how object elements can be read using + the `[]` operator.,operatorarray__key_type_const} - case 0xd2: // int 32 - { - idx += 4; // skip 4 content bytes - return get_from_vector(v, current_idx); - } + @sa @ref at(const typename object_t::key_type&) for access by reference + with range checking + @sa @ref value() for access by value with a default value - case 0xd3: // int 64 - { - idx += 8; // skip 8 content bytes - return get_from_vector(v, current_idx); - } + @since version 1.1.0 + */ + template + const_reference operator[](T* key) const + { + // at only works for objects + if (JSON_LIKELY(is_object())) + { + assert(m_value.object->find(key) != m_value.object->end()); + return m_value.object->find(key)->second; + } - case 0xd9: // str 8 - { - const auto len = static_cast(get_from_vector(v, current_idx)); - const size_t offset = current_idx + 2; - idx += len + 1; // skip size byte + content bytes - check_length(v.size(), len, offset); - return std::string(reinterpret_cast(v.data()) + offset, len); - } + JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name()))); + } - case 0xda: // str 16 - { - const auto len = static_cast(get_from_vector(v, current_idx)); - const size_t offset = current_idx + 3; - idx += len + 2; // skip 2 size bytes + content bytes - check_length(v.size(), len, offset); - return std::string(reinterpret_cast(v.data()) + offset, len); - } + /*! + @brief access specified object element with default value - case 0xdb: // str 32 - { - const auto len = static_cast(get_from_vector(v, current_idx)); - const size_t offset = current_idx + 5; - idx += len + 4; // skip 4 size bytes + content bytes - check_length(v.size(), len, offset); - return std::string(reinterpret_cast(v.data()) + offset, len); - } + Returns either a copy of an object's element at the specified key @a key + or a given default value if no element with key @a key exists. - case 0xdc: // array 16 - { - basic_json result = value_t::array; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 2; // skip 2 size bytes - for (size_t i = 0; i < len; ++i) - { - result.push_back(from_msgpack_internal(v, idx)); - } - return result; - } + The function is basically equivalent to executing + @code {.cpp} + try { + return at(key); + } catch(out_of_range) { + return default_value; + } + @endcode - case 0xdd: // array 32 - { - basic_json result = value_t::array; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 4; // skip 4 size bytes - for (size_t i = 0; i < len; ++i) - { - result.push_back(from_msgpack_internal(v, idx)); - } - return result; - } + @note Unlike @ref at(const typename object_t::key_type&), this function + does not throw if the given key @a key was not found. - case 0xde: // map 16 - { - basic_json result = value_t::object; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 2; // skip 2 size bytes - for (size_t i = 0; i < len; ++i) - { - msgpack_expect_string(v, idx); - std::string key = from_msgpack_internal(v, idx); - result[key] = from_msgpack_internal(v, idx); - } - return result; - } + @note Unlike @ref operator[](const typename object_t::key_type& key), this + function does not implicitly add an element to the position defined by @a + key. This function is furthermore also applicable to const objects. - case 0xdf: // map 32 - { - basic_json result = value_t::object; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 4; // skip 4 size bytes - for (size_t i = 0; i < len; ++i) - { - msgpack_expect_string(v, idx); - std::string key = from_msgpack_internal(v, idx); - result[key] = from_msgpack_internal(v, idx); - } - return result; - } + @param[in] key key of the element to access + @param[in] default_value the value to return if @a key is not found - default: - { - std::stringstream ss; - ss << std::hex << static_cast(v[current_idx]); - JSON_THROW(parse_error::create(112, current_idx + 1, "error reading MessagePack; last byte: 0x" + ss.str())); - } - } - } - } + @tparam ValueType type compatible to JSON values, for instance `int` for + JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for + JSON arrays. Note the type of the expected value at @a key and the default + value @a default_value must be compatible. - /*! - @brief create a JSON value from a given CBOR vector + @return copy of the element at key @a key or @a default_value if @a key + is not found - @param[in] v CBOR serialization - @param[in] idx byte index to start reading from @a v + @throw type_error.306 if the JSON value is not an object; in that case, + using `value()` with a key makes no sense. - @return deserialized JSON value + @complexity Logarithmic in the size of the container. - @throw parse_error.110 if the given vector ends prematurely - @throw parse_error.112 if unsupported features from CBOR were - used in the given vector @a v or if the input is not valid CBOR - @throw parse_error.113 if a string was expected as map key, but not found + @liveexample{The example below shows how object elements can be queried + with a default value.,basic_json__value} + + @sa @ref at(const typename object_t::key_type&) for access by reference + with range checking + @sa @ref operator[](const typename object_t::key_type&) for unchecked + access by reference - @sa https://tools.ietf.org/html/rfc7049 + @since version 1.0.0 */ - static basic_json from_cbor_internal(const std::vector& v, size_t& idx) + template::value, int>::type = 0> + ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const { - // store and increment index - const size_t current_idx = idx++; - - // make sure reading 1 byte is safe - check_length(v.size(), 1, current_idx); - - switch (v[current_idx]) + // at only works for objects + if (JSON_LIKELY(is_object())) { - // Integer 0x00..0x17 (0..23) - case 0x00: - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - case 0x08: - case 0x09: - case 0x0a: - case 0x0b: - case 0x0c: - case 0x0d: - case 0x0e: - case 0x0f: - case 0x10: - case 0x11: - case 0x12: - case 0x13: - case 0x14: - case 0x15: - case 0x16: - case 0x17: + // if key is found, return value and given default value otherwise + const auto it = find(key); + if (it != end()) { - return v[current_idx]; + return *it; } - case 0x18: // Unsigned integer (one-byte uint8_t follows) - { - idx += 1; // skip content byte - return get_from_vector(v, current_idx); - } + return default_value; + } - case 0x19: // Unsigned integer (two-byte uint16_t follows) - { - idx += 2; // skip 2 content bytes - return get_from_vector(v, current_idx); - } + JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()))); + } - case 0x1a: // Unsigned integer (four-byte uint32_t follows) - { - idx += 4; // skip 4 content bytes - return get_from_vector(v, current_idx); - } + /*! + @brief overload for a default value of type const char* + @copydoc basic_json::value(const typename object_t::key_type&, ValueType) const + */ + string_t value(const typename object_t::key_type& key, const char* default_value) const + { + return value(key, string_t(default_value)); + } - case 0x1b: // Unsigned integer (eight-byte uint64_t follows) - { - idx += 8; // skip 8 content bytes - return get_from_vector(v, current_idx); - } + /*! + @brief access specified object element via JSON Pointer with default value - // Negative integer -1-0x00..-1-0x17 (-1..-24) - case 0x20: - case 0x21: - case 0x22: - case 0x23: - case 0x24: - case 0x25: - case 0x26: - case 0x27: - case 0x28: - case 0x29: - case 0x2a: - case 0x2b: - case 0x2c: - case 0x2d: - case 0x2e: - case 0x2f: - case 0x30: - case 0x31: - case 0x32: - case 0x33: - case 0x34: - case 0x35: - case 0x36: - case 0x37: - { - return static_cast(0x20 - 1 - v[current_idx]); - } + Returns either a copy of an object's element at the specified key @a key + or a given default value if no element with key @a key exists. - case 0x38: // Negative integer (one-byte uint8_t follows) - { - idx += 1; // skip content byte - // must be uint8_t ! - return static_cast(-1) - get_from_vector(v, current_idx); - } + The function is basically equivalent to executing + @code {.cpp} + try { + return at(ptr); + } catch(out_of_range) { + return default_value; + } + @endcode - case 0x39: // Negative integer -1-n (two-byte uint16_t follows) - { - idx += 2; // skip 2 content bytes - return static_cast(-1) - get_from_vector(v, current_idx); - } + @note Unlike @ref at(const json_pointer&), this function does not throw + if the given key @a key was not found. - case 0x3a: // Negative integer -1-n (four-byte uint32_t follows) - { - idx += 4; // skip 4 content bytes - return static_cast(-1) - get_from_vector(v, current_idx); - } + @param[in] ptr a JSON pointer to the element to access + @param[in] default_value the value to return if @a ptr found no value - case 0x3b: // Negative integer -1-n (eight-byte uint64_t follows) - { - idx += 8; // skip 8 content bytes - return static_cast(-1) - static_cast(get_from_vector(v, current_idx)); - } + @tparam ValueType type compatible to JSON values, for instance `int` for + JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for + JSON arrays. Note the type of the expected value at @a key and the default + value @a default_value must be compatible. - // UTF-8 string (0x00..0x17 bytes follow) - case 0x60: - case 0x61: - case 0x62: - case 0x63: - case 0x64: - case 0x65: - case 0x66: - case 0x67: - case 0x68: - case 0x69: - case 0x6a: - case 0x6b: - case 0x6c: - case 0x6d: - case 0x6e: - case 0x6f: - case 0x70: - case 0x71: - case 0x72: - case 0x73: - case 0x74: - case 0x75: - case 0x76: - case 0x77: - { - const auto len = static_cast(v[current_idx] - 0x60); - const size_t offset = current_idx + 1; - idx += len; // skip content bytes - check_length(v.size(), len, offset); - return std::string(reinterpret_cast(v.data()) + offset, len); - } + @return copy of the element at key @a key or @a default_value if @a key + is not found - case 0x78: // UTF-8 string (one-byte uint8_t for n follows) - { - const auto len = static_cast(get_from_vector(v, current_idx)); - const size_t offset = current_idx + 2; - idx += len + 1; // skip size byte + content bytes - check_length(v.size(), len, offset); - return std::string(reinterpret_cast(v.data()) + offset, len); - } + @throw type_error.306 if the JSON value is not an objec; in that case, + using `value()` with a key makes no sense. - case 0x79: // UTF-8 string (two-byte uint16_t for n follow) - { - const auto len = static_cast(get_from_vector(v, current_idx)); - const size_t offset = current_idx + 3; - idx += len + 2; // skip 2 size bytes + content bytes - check_length(v.size(), len, offset); - return std::string(reinterpret_cast(v.data()) + offset, len); - } + @complexity Logarithmic in the size of the container. - case 0x7a: // UTF-8 string (four-byte uint32_t for n follow) - { - const auto len = static_cast(get_from_vector(v, current_idx)); - const size_t offset = current_idx + 5; - idx += len + 4; // skip 4 size bytes + content bytes - check_length(v.size(), len, offset); - return std::string(reinterpret_cast(v.data()) + offset, len); - } + @liveexample{The example below shows how object elements can be queried + with a default value.,basic_json__value_ptr} + + @sa @ref operator[](const json_pointer&) for unchecked access by reference - case 0x7b: // UTF-8 string (eight-byte uint64_t for n follow) + @since version 2.0.2 + */ + template::value, int>::type = 0> + ValueType value(const json_pointer& ptr, const ValueType& default_value) const + { + // at only works for objects + if (JSON_LIKELY(is_object())) + { + // if pointer resolves a value, return it or use default value + JSON_TRY { - const auto len = static_cast(get_from_vector(v, current_idx)); - const size_t offset = current_idx + 9; - idx += len + 8; // skip 8 size bytes + content bytes - check_length(v.size(), len, offset); - return std::string(reinterpret_cast(v.data()) + offset, len); + return ptr.get_checked(this); } - - case 0x7f: // UTF-8 string (indefinite length) + JSON_CATCH (out_of_range&) { - std::string result; - while (static_cast(check_length(v.size(), 1, idx)), v[idx] != 0xff) - { - string_t s = from_cbor_internal(v, idx); - result += s; - } - // skip break byte (0xFF) - idx += 1; - return result; + return default_value; } + } - // array (0x00..0x17 data items follow) - case 0x80: - case 0x81: - case 0x82: - case 0x83: - case 0x84: - case 0x85: - case 0x86: - case 0x87: - case 0x88: - case 0x89: - case 0x8a: - case 0x8b: - case 0x8c: - case 0x8d: - case 0x8e: - case 0x8f: - case 0x90: - case 0x91: - case 0x92: - case 0x93: - case 0x94: - case 0x95: - case 0x96: - case 0x97: - { - basic_json result = value_t::array; - const auto len = static_cast(v[current_idx] - 0x80); - for (size_t i = 0; i < len; ++i) - { - result.push_back(from_cbor_internal(v, idx)); - } - return result; - } - - case 0x98: // array (one-byte uint8_t for n follows) - { - basic_json result = value_t::array; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 1; // skip 1 size byte - for (size_t i = 0; i < len; ++i) - { - result.push_back(from_cbor_internal(v, idx)); - } - return result; - } - - case 0x99: // array (two-byte uint16_t for n follow) - { - basic_json result = value_t::array; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 2; // skip 4 size bytes - for (size_t i = 0; i < len; ++i) - { - result.push_back(from_cbor_internal(v, idx)); - } - return result; - } - - case 0x9a: // array (four-byte uint32_t for n follow) - { - basic_json result = value_t::array; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 4; // skip 4 size bytes - for (size_t i = 0; i < len; ++i) - { - result.push_back(from_cbor_internal(v, idx)); - } - return result; - } - - case 0x9b: // array (eight-byte uint64_t for n follow) - { - basic_json result = value_t::array; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 8; // skip 8 size bytes - for (size_t i = 0; i < len; ++i) - { - result.push_back(from_cbor_internal(v, idx)); - } - return result; - } - - case 0x9f: // array (indefinite length) - { - basic_json result = value_t::array; - while (static_cast(check_length(v.size(), 1, idx)), v[idx] != 0xff) - { - result.push_back(from_cbor_internal(v, idx)); - } - // skip break byte (0xFF) - idx += 1; - return result; - } - - // map (0x00..0x17 pairs of data items follow) - case 0xa0: - case 0xa1: - case 0xa2: - case 0xa3: - case 0xa4: - case 0xa5: - case 0xa6: - case 0xa7: - case 0xa8: - case 0xa9: - case 0xaa: - case 0xab: - case 0xac: - case 0xad: - case 0xae: - case 0xaf: - case 0xb0: - case 0xb1: - case 0xb2: - case 0xb3: - case 0xb4: - case 0xb5: - case 0xb6: - case 0xb7: - { - basic_json result = value_t::object; - const auto len = static_cast(v[current_idx] - 0xa0); - for (size_t i = 0; i < len; ++i) - { - cbor_expect_string(v, idx); - std::string key = from_cbor_internal(v, idx); - result[key] = from_cbor_internal(v, idx); - } - return result; - } - - case 0xb8: // map (one-byte uint8_t for n follows) - { - basic_json result = value_t::object; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 1; // skip 1 size byte - for (size_t i = 0; i < len; ++i) - { - cbor_expect_string(v, idx); - std::string key = from_cbor_internal(v, idx); - result[key] = from_cbor_internal(v, idx); - } - return result; - } - - case 0xb9: // map (two-byte uint16_t for n follow) - { - basic_json result = value_t::object; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 2; // skip 2 size bytes - for (size_t i = 0; i < len; ++i) - { - cbor_expect_string(v, idx); - std::string key = from_cbor_internal(v, idx); - result[key] = from_cbor_internal(v, idx); - } - return result; - } - - case 0xba: // map (four-byte uint32_t for n follow) - { - basic_json result = value_t::object; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 4; // skip 4 size bytes - for (size_t i = 0; i < len; ++i) - { - cbor_expect_string(v, idx); - std::string key = from_cbor_internal(v, idx); - result[key] = from_cbor_internal(v, idx); - } - return result; - } + JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()))); + } - case 0xbb: // map (eight-byte uint64_t for n follow) - { - basic_json result = value_t::object; - const auto len = static_cast(get_from_vector(v, current_idx)); - idx += 8; // skip 8 size bytes - for (size_t i = 0; i < len; ++i) - { - cbor_expect_string(v, idx); - std::string key = from_cbor_internal(v, idx); - result[key] = from_cbor_internal(v, idx); - } - return result; - } + /*! + @brief overload for a default value of type const char* + @copydoc basic_json::value(const json_pointer&, ValueType) const + */ + string_t value(const json_pointer& ptr, const char* default_value) const + { + return value(ptr, string_t(default_value)); + } - case 0xbf: // map (indefinite length) - { - basic_json result = value_t::object; - while (static_cast(check_length(v.size(), 1, idx)), v[idx] != 0xff) - { - cbor_expect_string(v, idx); - std::string key = from_cbor_internal(v, idx); - result[key] = from_cbor_internal(v, idx); - } - // skip break byte (0xFF) - idx += 1; - return result; - } + /*! + @brief access the first element - case 0xf4: // false - { - return false; - } + Returns a reference to the first element in the container. For a JSON + container `c`, the expression `c.front()` is equivalent to `*c.begin()`. - case 0xf5: // true - { - return true; - } + @return In case of a structured type (array or object), a reference to the + first element is returned. In case of number, string, or boolean values, a + reference to the value is returned. - case 0xf6: // null - { - return value_t::null; - } + @complexity Constant. - case 0xf9: // Half-Precision Float (two-byte IEEE 754) - { - idx += 2; // skip two content bytes + @pre The JSON value must not be `null` (would throw `std::out_of_range`) + or an empty array or object (undefined behavior, **guarded by + assertions**). + @post The JSON value remains unchanged. - // code from RFC 7049, Appendix D, Figure 3: - // As half-precision floating-point numbers were only added to - // IEEE 754 in 2008, today's programming platforms often still - // only have limited support for them. It is very easy to - // include at least decoding support for them even without such - // support. An example of a small decoder for half-precision - // floating-point numbers in the C language is shown in Fig. 3. - check_length(v.size(), 2, current_idx + 1); - const int half = (v[current_idx + 1] << 8) + v[current_idx + 2]; - const int exp = (half >> 10) & 0x1f; - const int mant = half & 0x3ff; - double val; - if (exp == 0) - { - val = std::ldexp(mant, -24); - } - else if (exp != 31) - { - val = std::ldexp(mant + 1024, exp - 25); - } - else - { - val = mant == 0 - ? std::numeric_limits::infinity() - : std::numeric_limits::quiet_NaN(); - } - return (half & 0x8000) != 0 ? -val : val; - } + @throw invalid_iterator.214 when called on `null` value - case 0xfa: // Single-Precision Float (four-byte IEEE 754) - { - // copy bytes in reverse order into the float variable - float res; - check_length(v.size(), sizeof(float), current_idx + 1); - for (size_t byte = 0; byte < sizeof(float); ++byte) - { - reinterpret_cast(&res)[sizeof(float) - byte - 1] = v[current_idx + 1 + byte]; - } - idx += sizeof(float); // skip content bytes - return res; - } + @liveexample{The following code shows an example for `front()`.,front} - case 0xfb: // Double-Precision Float (eight-byte IEEE 754) - { - // copy bytes in reverse order into the double variable - double res; - check_length(v.size(), sizeof(double), current_idx + 1); - for (size_t byte = 0; byte < sizeof(double); ++byte) - { - reinterpret_cast(&res)[sizeof(double) - byte - 1] = v[current_idx + 1 + byte]; - } - idx += sizeof(double); // skip content bytes - return res; - } + @sa @ref back() -- access the last element - default: // anything else (0xFF is handled inside the other types) - { - std::stringstream ss; - ss << std::hex << static_cast(v[current_idx]); - JSON_THROW(parse_error::create(112, current_idx + 1, "error reading CBOR; last byte: 0x" + ss.str())); - } - } + @since version 1.0.0 + */ + reference front() + { + return *begin(); } - public: /*! - @brief create a MessagePack serialization of a given JSON value - - Serializes a given JSON value @a j to a byte vector using the MessagePack - serialization format. MessagePack is a binary serialization format which - aims to be more compact than JSON itself, yet more efficient to parse. - - The library uses the following mapping from JSON values types to - MessagePack types according to the MessagePack specification: - - JSON value type | value/range | MessagePack type | first byte - --------------- | --------------------------------- | ---------------- | ---------- - null | `null` | nil | 0xc0 - boolean | `true` | true | 0xc3 - boolean | `false` | false | 0xc2 - number_integer | -9223372036854775808..-2147483649 | int64 | 0xd3 - number_integer | -2147483648..-32769 | int32 | 0xd2 - number_integer | -32768..-129 | int16 | 0xd1 - number_integer | -128..-33 | int8 | 0xd0 - number_integer | -32..-1 | negative fixint | 0xe0..0xff - number_integer | 0..127 | positive fixint | 0x00..0x7f - number_integer | 128..255 | uint 8 | 0xcc - number_integer | 256..65535 | uint 16 | 0xcd - number_integer | 65536..4294967295 | uint 32 | 0xce - number_integer | 4294967296..18446744073709551615 | uint 64 | 0xcf - number_unsigned | 0..127 | positive fixint | 0x00..0x7f - number_unsigned | 128..255 | uint 8 | 0xcc - number_unsigned | 256..65535 | uint 16 | 0xcd - number_unsigned | 65536..4294967295 | uint 32 | 0xce - number_unsigned | 4294967296..18446744073709551615 | uint 64 | 0xcf - number_float | *any value* | float 64 | 0xcb - string | *length*: 0..31 | fixstr | 0xa0..0xbf - string | *length*: 32..255 | str 8 | 0xd9 - string | *length*: 256..65535 | str 16 | 0xda - string | *length*: 65536..4294967295 | str 32 | 0xdb - array | *size*: 0..15 | fixarray | 0x90..0x9f - array | *size*: 16..65535 | array 16 | 0xdc - array | *size*: 65536..4294967295 | array 32 | 0xdd - object | *size*: 0..15 | fix map | 0x80..0x8f - object | *size*: 16..65535 | map 16 | 0xde - object | *size*: 65536..4294967295 | map 32 | 0xdf + @copydoc basic_json::front() + */ + const_reference front() const + { + return *cbegin(); + } - @note The mapping is **complete** in the sense that any JSON value type - can be converted to a MessagePack value. + /*! + @brief access the last element - @note The following values can **not** be converted to a MessagePack value: - - strings with more than 4294967295 bytes - - arrays with more than 4294967295 elements - - objects with more than 4294967295 elements + Returns a reference to the last element in the container. For a JSON + container `c`, the expression `c.back()` is equivalent to + @code {.cpp} + auto tmp = c.end(); + --tmp; + return *tmp; + @endcode - @note The following MessagePack types are not used in the conversion: - - bin 8 - bin 32 (0xc4..0xc6) - - ext 8 - ext 32 (0xc7..0xc9) - - float 32 (0xca) - - fixext 1 - fixext 16 (0xd4..0xd8) + @return In case of a structured type (array or object), a reference to the + last element is returned. In case of number, string, or boolean values, a + reference to the value is returned. - @note Any MessagePack output created @ref to_msgpack can be successfully - parsed by @ref from_msgpack. + @complexity Constant. - @param[in] j JSON value to serialize - @return MessagePack serialization as byte vector + @pre The JSON value must not be `null` (would throw `std::out_of_range`) + or an empty array or object (undefined behavior, **guarded by + assertions**). + @post The JSON value remains unchanged. - @complexity Linear in the size of the JSON value @a j. + @throw invalid_iterator.214 when called on a `null` value. See example + below. - @liveexample{The example shows the serialization of a JSON value to a byte - vector in MessagePack format.,to_msgpack} + @liveexample{The following code shows an example for `back()`.,back} - @sa http://msgpack.org - @sa @ref from_msgpack(const std::vector&, const size_t) for the - analogous deserialization - @sa @ref to_cbor(const basic_json& for the related CBOR format + @sa @ref front() -- access the first element - @since version 2.0.9 + @since version 1.0.0 */ - static std::vector to_msgpack(const basic_json& j) + reference back() { - std::vector result; - to_msgpack_internal(j, result); - return result; + auto tmp = end(); + --tmp; + return *tmp; } /*! - @brief create a JSON value from a byte vector in MessagePack format + @copydoc basic_json::back() + */ + const_reference back() const + { + auto tmp = cend(); + --tmp; + return *tmp; + } - Deserializes a given byte vector @a v to a JSON value using the MessagePack - serialization format. + /*! + @brief remove element given an iterator - The library maps MessagePack types to JSON value types as follows: + Removes the element specified by iterator @a pos. The iterator @a pos must + be valid and dereferenceable. Thus the `end()` iterator (which is valid, + but is not dereferenceable) cannot be used as a value for @a pos. - MessagePack type | JSON value type | first byte - ---------------- | --------------- | ---------- - positive fixint | number_unsigned | 0x00..0x7f - fixmap | object | 0x80..0x8f - fixarray | array | 0x90..0x9f - fixstr | string | 0xa0..0xbf - nil | `null` | 0xc0 - false | `false` | 0xc2 - true | `true` | 0xc3 - float 32 | number_float | 0xca - float 64 | number_float | 0xcb - uint 8 | number_unsigned | 0xcc - uint 16 | number_unsigned | 0xcd - uint 32 | number_unsigned | 0xce - uint 64 | number_unsigned | 0xcf - int 8 | number_integer | 0xd0 - int 16 | number_integer | 0xd1 - int 32 | number_integer | 0xd2 - int 64 | number_integer | 0xd3 - str 8 | string | 0xd9 - str 16 | string | 0xda - str 32 | string | 0xdb - array 16 | array | 0xdc - array 32 | array | 0xdd - map 16 | object | 0xde - map 32 | object | 0xdf - negative fixint | number_integer | 0xe0-0xff + If called on a primitive type other than `null`, the resulting JSON value + will be `null`. - @warning The mapping is **incomplete** in the sense that not all - MessagePack types can be converted to a JSON value. The following - MessagePack types are not supported and will yield parse errors: - - bin 8 - bin 32 (0xc4..0xc6) - - ext 8 - ext 32 (0xc7..0xc9) - - fixext 1 - fixext 16 (0xd4..0xd8) + @param[in] pos iterator to the element to remove + @return Iterator following the last removed element. If the iterator @a + pos refers to the last element, the `end()` iterator is returned. - @note Any MessagePack output created @ref to_msgpack can be successfully - parsed by @ref from_msgpack. + @tparam IteratorType an @ref iterator or @ref const_iterator - @param[in] v a byte vector in MessagePack format - @param[in] start_index the index to start reading from @a v (0 by default) - @return deserialized JSON value + @post Invalidates iterators and references at or after the point of the + erase, including the `end()` iterator. - @throw parse_error.110 if the given vector ends prematurely - @throw parse_error.112 if unsupported features from MessagePack were - used in the given vector @a v or if the input is not valid MessagePack - @throw parse_error.113 if a string was expected as map key, but not found + @throw type_error.307 if called on a `null` value; example: `"cannot use + erase() with null"` + @throw invalid_iterator.202 if called on an iterator which does not belong + to the current JSON value; example: `"iterator does not fit current + value"` + @throw invalid_iterator.205 if called on a primitive type with invalid + iterator (i.e., any iterator which is not `begin()`); example: `"iterator + out of range"` - @complexity Linear in the size of the byte vector @a v. + @complexity The complexity depends on the type: + - objects: amortized constant + - arrays: linear in distance between @a pos and the end of the container + - strings: linear in the length of the string + - other types: constant - @liveexample{The example shows the deserialization of a byte vector in - MessagePack format to a JSON value.,from_msgpack} + @liveexample{The example shows the result of `erase()` for different JSON + types.,erase__IteratorType} - @sa http://msgpack.org - @sa @ref to_msgpack(const basic_json&) for the analogous serialization - @sa @ref from_cbor(const std::vector&, const size_t) for the - related CBOR format + @sa @ref erase(IteratorType, IteratorType) -- removes the elements in + the given range + @sa @ref erase(const typename object_t::key_type&) -- removes the element + from an object at the given key + @sa @ref erase(const size_type) -- removes the element from an array at + the given index - @since version 2.0.9, parameter @a start_index since 2.1.1 + @since version 1.0.0 */ - static basic_json from_msgpack(const std::vector& v, - const size_t start_index = 0) + template::value or + std::is_same::value, int>::type + = 0> + IteratorType erase(IteratorType pos) { - size_t i = start_index; - return from_msgpack_internal(v, i); - } - - /*! - @brief create a MessagePack serialization of a given JSON value - - Serializes a given JSON value @a j to a byte vector using the CBOR (Concise - Binary Object Representation) serialization format. CBOR is a binary - serialization format which aims to be more compact than JSON itself, yet - more efficient to parse. - - The library uses the following mapping from JSON values types to - CBOR types according to the CBOR specification (RFC 7049): + // make sure iterator fits the current value + if (JSON_UNLIKELY(this != pos.m_object)) + { + JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); + } - JSON value type | value/range | CBOR type | first byte - --------------- | ------------------------------------------ | ---------------------------------- | --------------- - null | `null` | Null | 0xf6 - boolean | `true` | True | 0xf5 - boolean | `false` | False | 0xf4 - number_integer | -9223372036854775808..-2147483649 | Negative integer (8 bytes follow) | 0x3b - number_integer | -2147483648..-32769 | Negative integer (4 bytes follow) | 0x3a - number_integer | -32768..-129 | Negative integer (2 bytes follow) | 0x39 - number_integer | -128..-25 | Negative integer (1 byte follow) | 0x38 - number_integer | -24..-1 | Negative integer | 0x20..0x37 - number_integer | 0..23 | Integer | 0x00..0x17 - number_integer | 24..255 | Unsigned integer (1 byte follow) | 0x18 - number_integer | 256..65535 | Unsigned integer (2 bytes follow) | 0x19 - number_integer | 65536..4294967295 | Unsigned integer (4 bytes follow) | 0x1a - number_integer | 4294967296..18446744073709551615 | Unsigned integer (8 bytes follow) | 0x1b - number_unsigned | 0..23 | Integer | 0x00..0x17 - number_unsigned | 24..255 | Unsigned integer (1 byte follow) | 0x18 - number_unsigned | 256..65535 | Unsigned integer (2 bytes follow) | 0x19 - number_unsigned | 65536..4294967295 | Unsigned integer (4 bytes follow) | 0x1a - number_unsigned | 4294967296..18446744073709551615 | Unsigned integer (8 bytes follow) | 0x1b - number_float | *any value* | Double-Precision Float | 0xfb - string | *length*: 0..23 | UTF-8 string | 0x60..0x77 - string | *length*: 23..255 | UTF-8 string (1 byte follow) | 0x78 - string | *length*: 256..65535 | UTF-8 string (2 bytes follow) | 0x79 - string | *length*: 65536..4294967295 | UTF-8 string (4 bytes follow) | 0x7a - string | *length*: 4294967296..18446744073709551615 | UTF-8 string (8 bytes follow) | 0x7b - array | *size*: 0..23 | array | 0x80..0x97 - array | *size*: 23..255 | array (1 byte follow) | 0x98 - array | *size*: 256..65535 | array (2 bytes follow) | 0x99 - array | *size*: 65536..4294967295 | array (4 bytes follow) | 0x9a - array | *size*: 4294967296..18446744073709551615 | array (8 bytes follow) | 0x9b - object | *size*: 0..23 | map | 0xa0..0xb7 - object | *size*: 23..255 | map (1 byte follow) | 0xb8 - object | *size*: 256..65535 | map (2 bytes follow) | 0xb9 - object | *size*: 65536..4294967295 | map (4 bytes follow) | 0xba - object | *size*: 4294967296..18446744073709551615 | map (8 bytes follow) | 0xbb + IteratorType result = end(); - @note The mapping is **complete** in the sense that any JSON value type - can be converted to a CBOR value. + switch (m_type) + { + case value_t::boolean: + case value_t::number_float: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::string: + { + if (JSON_UNLIKELY(not pos.m_it.primitive_iterator.is_begin())) + { + JSON_THROW(invalid_iterator::create(205, "iterator out of range")); + } - @note The following CBOR types are not used in the conversion: - - byte strings (0x40..0x5f) - - UTF-8 strings terminated by "break" (0x7f) - - arrays terminated by "break" (0x9f) - - maps terminated by "break" (0xbf) - - date/time (0xc0..0xc1) - - bignum (0xc2..0xc3) - - decimal fraction (0xc4) - - bigfloat (0xc5) - - tagged items (0xc6..0xd4, 0xd8..0xdb) - - expected conversions (0xd5..0xd7) - - simple values (0xe0..0xf3, 0xf8) - - undefined (0xf7) - - half and single-precision floats (0xf9-0xfa) - - break (0xff) + if (is_string()) + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, m_value.string); + std::allocator_traits::deallocate(alloc, m_value.string, 1); + m_value.string = nullptr; + } - @param[in] j JSON value to serialize - @return MessagePack serialization as byte vector + m_type = value_t::null; + assert_invariant(); + break; + } - @complexity Linear in the size of the JSON value @a j. + case value_t::object: + { + result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator); + break; + } - @liveexample{The example shows the serialization of a JSON value to a byte - vector in CBOR format.,to_cbor} + case value_t::array: + { + result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator); + break; + } - @sa http://cbor.io - @sa @ref from_cbor(const std::vector&, const size_t) for the - analogous deserialization - @sa @ref to_msgpack(const basic_json& for the related MessagePack format + default: + JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()))); + } - @since version 2.0.9 - */ - static std::vector to_cbor(const basic_json& j) - { - std::vector result; - to_cbor_internal(j, result); return result; } /*! - @brief create a JSON value from a byte vector in CBOR format - - Deserializes a given byte vector @a v to a JSON value using the CBOR - (Concise Binary Object Representation) serialization format. - - The library maps CBOR types to JSON value types as follows: + @brief remove elements given an iterator range - CBOR type | JSON value type | first byte - ---------------------- | --------------- | ---------- - Integer | number_unsigned | 0x00..0x17 - Unsigned integer | number_unsigned | 0x18 - Unsigned integer | number_unsigned | 0x19 - Unsigned integer | number_unsigned | 0x1a - Unsigned integer | number_unsigned | 0x1b - Negative integer | number_integer | 0x20..0x37 - Negative integer | number_integer | 0x38 - Negative integer | number_integer | 0x39 - Negative integer | number_integer | 0x3a - Negative integer | number_integer | 0x3b - Negative integer | number_integer | 0x40..0x57 - UTF-8 string | string | 0x60..0x77 - UTF-8 string | string | 0x78 - UTF-8 string | string | 0x79 - UTF-8 string | string | 0x7a - UTF-8 string | string | 0x7b - UTF-8 string | string | 0x7f - array | array | 0x80..0x97 - array | array | 0x98 - array | array | 0x99 - array | array | 0x9a - array | array | 0x9b - array | array | 0x9f - map | object | 0xa0..0xb7 - map | object | 0xb8 - map | object | 0xb9 - map | object | 0xba - map | object | 0xbb - map | object | 0xbf - False | `false` | 0xf4 - True | `true` | 0xf5 - Nill | `null` | 0xf6 - Half-Precision Float | number_float | 0xf9 - Single-Precision Float | number_float | 0xfa - Double-Precision Float | number_float | 0xfb + Removes the element specified by the range `[first; last)`. The iterator + @a first does not need to be dereferenceable if `first == last`: erasing + an empty range is a no-op. - @warning The mapping is **incomplete** in the sense that not all CBOR - types can be converted to a JSON value. The following CBOR types - are not supported and will yield parse errors (parse_error.112): - - byte strings (0x40..0x5f) - - date/time (0xc0..0xc1) - - bignum (0xc2..0xc3) - - decimal fraction (0xc4) - - bigfloat (0xc5) - - tagged items (0xc6..0xd4, 0xd8..0xdb) - - expected conversions (0xd5..0xd7) - - simple values (0xe0..0xf3, 0xf8) - - undefined (0xf7) + If called on a primitive type other than `null`, the resulting JSON value + will be `null`. - @warning CBOR allows map keys of any type, whereas JSON only allows - strings as keys in object values. Therefore, CBOR maps with keys - other than UTF-8 strings are rejected (parse_error.113). + @param[in] first iterator to the beginning of the range to remove + @param[in] last iterator past the end of the range to remove + @return Iterator following the last removed element. If the iterator @a + second refers to the last element, the `end()` iterator is returned. - @note Any CBOR output created @ref to_cbor can be successfully parsed by - @ref from_cbor. + @tparam IteratorType an @ref iterator or @ref const_iterator - @param[in] v a byte vector in CBOR format - @param[in] start_index the index to start reading from @a v (0 by default) - @return deserialized JSON value + @post Invalidates iterators and references at or after the point of the + erase, including the `end()` iterator. - @throw parse_error.110 if the given vector ends prematurely - @throw parse_error.112 if unsupported features from CBOR were - used in the given vector @a v or if the input is not valid CBOR - @throw parse_error.113 if a string was expected as map key, but not found + @throw type_error.307 if called on a `null` value; example: `"cannot use + erase() with null"` + @throw invalid_iterator.203 if called on iterators which does not belong + to the current JSON value; example: `"iterators do not fit current value"` + @throw invalid_iterator.204 if called on a primitive type with invalid + iterators (i.e., if `first != begin()` and `last != end()`); example: + `"iterators out of range"` - @complexity Linear in the size of the byte vector @a v. + @complexity The complexity depends on the type: + - objects: `log(size()) + std::distance(first, last)` + - arrays: linear in the distance between @a first and @a last, plus linear + in the distance between @a last and end of the container + - strings: linear in the length of the string + - other types: constant - @liveexample{The example shows the deserialization of a byte vector in CBOR - format to a JSON value.,from_cbor} + @liveexample{The example shows the result of `erase()` for different JSON + types.,erase__IteratorType_IteratorType} - @sa http://cbor.io - @sa @ref to_cbor(const basic_json&) for the analogous serialization - @sa @ref from_msgpack(const std::vector&, const size_t) for the - related MessagePack format + @sa @ref erase(IteratorType) -- removes the element at a given position + @sa @ref erase(const typename object_t::key_type&) -- removes the element + from an object at the given key + @sa @ref erase(const size_type) -- removes the element from an array at + the given index - @since version 2.0.9, parameter @a start_index since 2.1.1 + @since version 1.0.0 */ - static basic_json from_cbor(const std::vector& v, - const size_t start_index = 0) + template::value or + std::is_same::value, int>::type + = 0> + IteratorType erase(IteratorType first, IteratorType last) { - size_t i = start_index; - return from_cbor_internal(v, i); - } - - /// @} - - /////////////////////////// - // convenience functions // - /////////////////////////// + // make sure iterator fits the current value + if (JSON_UNLIKELY(this != first.m_object or this != last.m_object)) + { + JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value")); + } - /*! - @brief return the type as string + IteratorType result = end(); - Returns the type name as string to be used in error messages - usually to - indicate that a function was called on a wrong JSON type. + switch (m_type) + { + case value_t::boolean: + case value_t::number_float: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::string: + { + if (JSON_LIKELY(not first.m_it.primitive_iterator.is_begin() + or not last.m_it.primitive_iterator.is_end())) + { + JSON_THROW(invalid_iterator::create(204, "iterators out of range")); + } - @return basically a string representation of a the @a m_type member + if (is_string()) + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, m_value.string); + std::allocator_traits::deallocate(alloc, m_value.string, 1); + m_value.string = nullptr; + } - @complexity Constant. + m_type = value_t::null; + assert_invariant(); + break; + } - @liveexample{The following code exemplifies `type_name()` for all JSON - types.,type_name} + case value_t::object: + { + result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator, + last.m_it.object_iterator); + break; + } - @since version 1.0.0, public since 2.1.0 - */ - std::string type_name() const - { - { - switch (m_type) + case value_t::array: { - case value_t::null: - return "null"; - case value_t::object: - return "object"; - case value_t::array: - return "array"; - case value_t::string: - return "string"; - case value_t::boolean: - return "boolean"; - case value_t::discarded: - return "discarded"; - default: - return "number"; + result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator, + last.m_it.array_iterator); + break; } + + default: + JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()))); } + + return result; } + /*! + @brief remove element from a JSON object given a key - private: - ////////////////////// - // member variables // - ////////////////////// + Removes elements from a JSON object with the key value @a key. - /// the type of the current element - value_t m_type = value_t::null; + @param[in] key value of the elements to remove - /// the value of the current element - json_value m_value = {}; + @return Number of elements removed. If @a ObjectType is the default + `std::map` type, the return value will always be `0` (@a key was not + found) or `1` (@a key was found). + @post References and iterators to the erased elements are invalidated. + Other references and iterators are not affected. - private: - /////////////// - // iterators // - /////////////// + @throw type_error.307 when called on a type other than JSON object; + example: `"cannot use erase() with null"` - /*! - @brief an iterator for primitive JSON types + @complexity `log(size()) + count(key)` + + @liveexample{The example shows the effect of `erase()`.,erase__key_type} + + @sa @ref erase(IteratorType) -- removes the element at a given position + @sa @ref erase(IteratorType, IteratorType) -- removes the elements in + the given range + @sa @ref erase(const size_type) -- removes the element from an array at + the given index - This class models an iterator for primitive JSON types (boolean, number, - string). It's only purpose is to allow the iterator/const_iterator classes - to "iterate" over primitive values. Internally, the iterator is modeled by - a `difference_type` variable. Value begin_value (`0`) models the begin, - end_value (`1`) models past the end. + @since version 1.0.0 */ - class primitive_iterator_t + size_type erase(const typename object_t::key_type& key) { - public: - - difference_type get_value() const noexcept - { - return m_it; - } - /// set iterator to a defined beginning - void set_begin() noexcept + // this erase only works for objects + if (JSON_LIKELY(is_object())) { - m_it = begin_value; + return m_value.object->erase(key); } - /// set iterator to a defined past the end - void set_end() noexcept - { - m_it = end_value; - } + JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()))); + } - /// return whether the iterator can be dereferenced - constexpr bool is_begin() const noexcept - { - return (m_it == begin_value); - } + /*! + @brief remove element from a JSON array given an index - /// return whether the iterator is at end - constexpr bool is_end() const noexcept - { - return (m_it == end_value); - } + Removes element from a JSON array at the index @a idx. - friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept - { - return lhs.m_it == rhs.m_it; - } + @param[in] idx index of the element to remove - friend constexpr bool operator!=(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept - { - return !(lhs == rhs); - } + @throw type_error.307 when called on a type other than JSON object; + example: `"cannot use erase() with null"` + @throw out_of_range.401 when `idx >= size()`; example: `"array index 17 + is out of range"` - friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept - { - return lhs.m_it < rhs.m_it; - } + @complexity Linear in distance between @a idx and the end of the container. - friend constexpr bool operator<=(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept - { - return lhs.m_it <= rhs.m_it; - } + @liveexample{The example shows the effect of `erase()`.,erase__size_type} - friend constexpr bool operator>(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept - { - return lhs.m_it > rhs.m_it; - } + @sa @ref erase(IteratorType) -- removes the element at a given position + @sa @ref erase(IteratorType, IteratorType) -- removes the elements in + the given range + @sa @ref erase(const typename object_t::key_type&) -- removes the element + from an object at the given key - friend constexpr bool operator>=(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept + @since version 1.0.0 + */ + void erase(const size_type idx) + { + // this erase only works for arrays + if (JSON_LIKELY(is_array())) { - return lhs.m_it >= rhs.m_it; - } + if (JSON_UNLIKELY(idx >= size())) + { + JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range")); + } - primitive_iterator_t operator+(difference_type i) - { - auto result = *this; - result += i; - return result; + m_value.array->erase(m_value.array->begin() + static_cast(idx)); } - - friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept + else { - return lhs.m_it - rhs.m_it; + JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()))); } + } - friend std::ostream& operator<<(std::ostream& os, primitive_iterator_t it) - { - return os << it.m_it; - } + /// @} - primitive_iterator_t& operator++() - { - ++m_it; - return *this; - } - primitive_iterator_t operator++(int) - { - auto result = *this; - m_it++; - return result; - } + //////////// + // lookup // + //////////// - primitive_iterator_t& operator--() - { - --m_it; - return *this; - } + /// @name lookup + /// @{ - primitive_iterator_t operator--(int) - { - auto result = *this; - m_it--; - return result; - } + /*! + @brief find an element in a JSON object - primitive_iterator_t& operator+=(difference_type n) - { - m_it += n; - return *this; - } + Finds an element in a JSON object with key equivalent to @a key. If the + element is not found or the JSON value is not an object, end() is + returned. - primitive_iterator_t& operator-=(difference_type n) - { - m_it -= n; - return *this; - } + @note This method always returns @ref end() when executed on a JSON type + that is not an object. - private: - static constexpr difference_type begin_value = 0; - static constexpr difference_type end_value = begin_value + 1; + @param[in] key key value of the element to search for. - /// iterator as signed integer type - difference_type m_it = std::numeric_limits::denorm_min(); - }; + @return Iterator to an element with key equivalent to @a key. If no such + element is found or the JSON value is not an object, past-the-end (see + @ref end()) iterator is returned. - /*! - @brief an iterator value + @complexity Logarithmic in the size of the JSON object. + + @liveexample{The example shows how `find()` is used.,find__key_type} - @note This structure could easily be a union, but MSVC currently does not - allow unions members with complex constructors, see - https://github.com/nlohmann/json/pull/105. + @since version 1.0.0 */ - struct internal_iterator + template + iterator find(KeyT&& key) { - /// iterator for JSON objects - typename object_t::iterator object_iterator; - /// iterator for JSON arrays - typename array_t::iterator array_iterator; - /// generic iterator for all other types - primitive_iterator_t primitive_iterator; + auto result = end(); - /// create an uninitialized internal_iterator - internal_iterator() noexcept - : object_iterator(), array_iterator(), primitive_iterator() - {} - }; + if (is_object()) + { + result.m_it.object_iterator = m_value.object->find(std::forward(key)); + } + + return result; + } - /// proxy class for the iterator_wrapper functions - template - class iteration_proxy + /*! + @brief find an element in a JSON object + @copydoc find(KeyT&&) + */ + template + const_iterator find(KeyT&& key) const { - private: - /// helper class for iteration - class iteration_proxy_internal - { - private: - /// the iterator - IteratorType anchor; - /// an index for arrays (used to create key names) - size_t array_index = 0; + auto result = cend(); - public: - explicit iteration_proxy_internal(IteratorType it) noexcept - : anchor(it) - {} + if (is_object()) + { + result.m_it.object_iterator = m_value.object->find(std::forward(key)); + } - /// dereference operator (needed for range-based for) - iteration_proxy_internal& operator*() - { - return *this; - } + return result; + } - /// increment operator (needed for range-based for) - iteration_proxy_internal& operator++() - { - ++anchor; - ++array_index; + /*! + @brief returns the number of occurrences of a key in a JSON object - return *this; - } + Returns the number of elements with key @a key. If ObjectType is the + default `std::map` type, the return value will always be `0` (@a key was + not found) or `1` (@a key was found). - /// inequality operator (needed for range-based for) - bool operator!= (const iteration_proxy_internal& o) const - { - return anchor != o.anchor; - } + @note This method always returns `0` when executed on a JSON type that is + not an object. - /// return key of the iterator - typename basic_json::string_t key() const - { - assert(anchor.m_object != nullptr); + @param[in] key key value of the element to count - switch (anchor.m_object->type()) - { - // use integer array index as key - case value_t::array: - { - return std::to_string(array_index); - } + @return Number of elements with key @a key. If the JSON value is not an + object, the return value will be `0`. - // use key from the object - case value_t::object: - { - return anchor.key(); - } + @complexity Logarithmic in the size of the JSON object. - // use an empty key for all primitive types - default: - { - return ""; - } - } - } + @liveexample{The example shows how `count()` is used.,count} - /// return value of the iterator - typename IteratorType::reference value() const - { - return anchor.value(); - } - }; + @since version 1.0.0 + */ + template + size_type count(KeyT&& key) const + { + // return 0 for all nonobject types + return is_object() ? m_value.object->count(std::forward(key)) : 0; + } - /// the container to iterate - typename IteratorType::reference container; + /// @} - public: - /// construct iteration proxy from a container - explicit iteration_proxy(typename IteratorType::reference cont) - : container(cont) - {} - /// return iterator begin (needed for range-based for) - iteration_proxy_internal begin() noexcept - { - return iteration_proxy_internal(container.begin()); - } + /////////////// + // iterators // + /////////////// - /// return iterator end (needed for range-based for) - iteration_proxy_internal end() noexcept - { - return iteration_proxy_internal(container.end()); - } - }; + /// @name iterators + /// @{ - public: /*! - @brief a template for a random access iterator for the @ref basic_json class + @brief returns an iterator to the first element - This class implements a both iterators (iterator and const_iterator) for the - @ref basic_json class. + Returns an iterator to the first element. - @note An iterator is called *initialized* when a pointer to a JSON value - has been set (e.g., by a constructor or a copy assignment). If the - iterator is default-constructed, it is *uninitialized* and most - methods are undefined. **The library uses assertions to detect calls - on uninitialized iterators.** + @image html range-begin-end.svg "Illustration from cppreference.com" - @requirement The class satisfies the following concept requirements: - - [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator): - The iterator that can be moved to point (forward and backward) to any - element in constant time. + @return iterator to the first element - @since version 1.0.0, simplified in version 2.0.9 - */ - template - class iter_impl : public std::iterator - { - /// allow basic_json to access private members - friend class basic_json; + @complexity Constant. - // make sure U is basic_json or const basic_json - static_assert(std::is_same::value - or std::is_same::value, - "iter_impl only accepts (const) basic_json"); + @requirement This function helps `basic_json` satisfying the + [Container](http://en.cppreference.com/w/cpp/concept/Container) + requirements: + - The complexity is constant. - public: - /// the type of the values when the iterator is dereferenced - using value_type = typename basic_json::value_type; - /// a type to represent differences between iterators - using difference_type = typename basic_json::difference_type; - /// defines a pointer to the type iterated over (value_type) - using pointer = typename std::conditional::value, - typename basic_json::const_pointer, - typename basic_json::pointer>::type; - /// defines a reference to the type iterated over (value_type) - using reference = typename std::conditional::value, - typename basic_json::const_reference, - typename basic_json::reference>::type; - /// the category of the iterator - using iterator_category = std::bidirectional_iterator_tag; - - /// default constructor - iter_impl() = default; - - /*! - @brief constructor for a given JSON instance - @param[in] object pointer to a JSON object for this iterator - @pre object != nullptr - @post The iterator is initialized; i.e. `m_object != nullptr`. - */ - explicit iter_impl(pointer object) noexcept - : m_object(object) - { - assert(m_object != nullptr); - - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - m_it.object_iterator = typename object_t::iterator(); - break; - } + @liveexample{The following code shows an example for `begin()`.,begin} - case basic_json::value_t::array: - { - m_it.array_iterator = typename array_t::iterator(); - break; - } + @sa @ref cbegin() -- returns a const iterator to the beginning + @sa @ref end() -- returns an iterator to the end + @sa @ref cend() -- returns a const iterator to the end - default: - { - m_it.primitive_iterator = primitive_iterator_t(); - break; - } - } - } + @since version 1.0.0 + */ + iterator begin() noexcept + { + iterator result(this); + result.set_begin(); + return result; + } - /* - Use operator `const_iterator` instead of `const_iterator(const iterator& - other) noexcept` to avoid two class definitions for @ref iterator and - @ref const_iterator. + /*! + @copydoc basic_json::cbegin() + */ + const_iterator begin() const noexcept + { + return cbegin(); + } - This function is only called if this class is an @ref iterator. If this - class is a @ref const_iterator this function is not called. - */ - operator const_iterator() const - { - const_iterator ret; + /*! + @brief returns a const iterator to the first element - if (m_object) - { - ret.m_object = m_object; - ret.m_it = m_it; - } + Returns a const iterator to the first element. - return ret; - } + @image html range-begin-end.svg "Illustration from cppreference.com" - /*! - @brief copy constructor - @param[in] other iterator to copy from - @note It is not checked whether @a other is initialized. - */ - iter_impl(const iter_impl& other) noexcept - : m_object(other.m_object), m_it(other.m_it) - {} + @return const iterator to the first element - /*! - @brief copy assignment - @param[in,out] other iterator to copy from - @note It is not checked whether @a other is initialized. - */ - iter_impl& operator=(iter_impl other) noexcept_if( - std::is_nothrow_move_constructible::value and - std::is_nothrow_move_assignable::value and - std::is_nothrow_move_constructible::value and - std::is_nothrow_move_assignable::value - ) - { - std::swap(m_object, other.m_object); - std::swap(m_it, other.m_it); - return *this; - } + @complexity Constant. - private: - /*! - @brief set the iterator to the first value - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - void set_begin() noexcept - { - assert(m_object != nullptr); + @requirement This function helps `basic_json` satisfying the + [Container](http://en.cppreference.com/w/cpp/concept/Container) + requirements: + - The complexity is constant. + - Has the semantics of `const_cast(*this).begin()`. - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - m_it.object_iterator = m_object->m_value.object->begin(); - break; - } - - case basic_json::value_t::array: - { - m_it.array_iterator = m_object->m_value.array->begin(); - break; - } + @liveexample{The following code shows an example for `cbegin()`.,cbegin} - case basic_json::value_t::null: - { - // set to end so begin()==end() is true: null is empty - m_it.primitive_iterator.set_end(); - break; - } + @sa @ref begin() -- returns an iterator to the beginning + @sa @ref end() -- returns an iterator to the end + @sa @ref cend() -- returns a const iterator to the end - default: - { - m_it.primitive_iterator.set_begin(); - break; - } - } - } + @since version 1.0.0 + */ + const_iterator cbegin() const noexcept + { + const_iterator result(this); + result.set_begin(); + return result; + } - /*! - @brief set the iterator past the last value - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - void set_end() noexcept - { - assert(m_object != nullptr); + /*! + @brief returns an iterator to one past the last element - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - m_it.object_iterator = m_object->m_value.object->end(); - break; - } + Returns an iterator to one past the last element. - case basic_json::value_t::array: - { - m_it.array_iterator = m_object->m_value.array->end(); - break; - } + @image html range-begin-end.svg "Illustration from cppreference.com" - default: - { - m_it.primitive_iterator.set_end(); - break; - } - } - } + @return iterator one past the last element - public: - /*! - @brief return a reference to the value pointed to by the iterator - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - reference operator*() const - { - assert(m_object != nullptr); + @complexity Constant. - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - assert(m_it.object_iterator != m_object->m_value.object->end()); - return m_it.object_iterator->second; - } + @requirement This function helps `basic_json` satisfying the + [Container](http://en.cppreference.com/w/cpp/concept/Container) + requirements: + - The complexity is constant. - case basic_json::value_t::array: - { - assert(m_it.array_iterator != m_object->m_value.array->end()); - return *m_it.array_iterator; - } + @liveexample{The following code shows an example for `end()`.,end} - case basic_json::value_t::null: - { - JSON_THROW(invalid_iterator::create(214, "cannot get value")); - } + @sa @ref cend() -- returns a const iterator to the end + @sa @ref begin() -- returns an iterator to the beginning + @sa @ref cbegin() -- returns a const iterator to the beginning - default: - { - if (m_it.primitive_iterator.is_begin()) - { - return *m_object; - } + @since version 1.0.0 + */ + iterator end() noexcept + { + iterator result(this); + result.set_end(); + return result; + } - JSON_THROW(invalid_iterator::create(214, "cannot get value")); - } - } - } + /*! + @copydoc basic_json::cend() + */ + const_iterator end() const noexcept + { + return cend(); + } - /*! - @brief dereference the iterator - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - pointer operator->() const - { - assert(m_object != nullptr); + /*! + @brief returns a const iterator to one past the last element - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - assert(m_it.object_iterator != m_object->m_value.object->end()); - return &(m_it.object_iterator->second); - } + Returns a const iterator to one past the last element. - case basic_json::value_t::array: - { - assert(m_it.array_iterator != m_object->m_value.array->end()); - return &*m_it.array_iterator; - } + @image html range-begin-end.svg "Illustration from cppreference.com" - default: - { - if (m_it.primitive_iterator.is_begin()) - { - return m_object; - } + @return const iterator one past the last element - JSON_THROW(invalid_iterator::create(214, "cannot get value")); - } - } - } + @complexity Constant. - /*! - @brief post-increment (it++) - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - iter_impl operator++(int) - { - auto result = *this; - ++(*this); - return result; - } + @requirement This function helps `basic_json` satisfying the + [Container](http://en.cppreference.com/w/cpp/concept/Container) + requirements: + - The complexity is constant. + - Has the semantics of `const_cast(*this).end()`. - /*! - @brief pre-increment (++it) - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - iter_impl& operator++() - { - assert(m_object != nullptr); + @liveexample{The following code shows an example for `cend()`.,cend} - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - std::advance(m_it.object_iterator, 1); - break; - } + @sa @ref end() -- returns an iterator to the end + @sa @ref begin() -- returns an iterator to the beginning + @sa @ref cbegin() -- returns a const iterator to the beginning - case basic_json::value_t::array: - { - std::advance(m_it.array_iterator, 1); - break; - } + @since version 1.0.0 + */ + const_iterator cend() const noexcept + { + const_iterator result(this); + result.set_end(); + return result; + } - default: - { - ++m_it.primitive_iterator; - break; - } - } + /*! + @brief returns an iterator to the reverse-beginning - return *this; - } + Returns an iterator to the reverse-beginning; that is, the last element. - /*! - @brief post-decrement (it--) - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - iter_impl operator--(int) - { - auto result = *this; - --(*this); - return result; - } + @image html range-rbegin-rend.svg "Illustration from cppreference.com" - /*! - @brief pre-decrement (--it) - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - iter_impl& operator--() - { - assert(m_object != nullptr); + @complexity Constant. - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - std::advance(m_it.object_iterator, -1); - break; - } + @requirement This function helps `basic_json` satisfying the + [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) + requirements: + - The complexity is constant. + - Has the semantics of `reverse_iterator(end())`. - case basic_json::value_t::array: - { - std::advance(m_it.array_iterator, -1); - break; - } + @liveexample{The following code shows an example for `rbegin()`.,rbegin} - default: - { - --m_it.primitive_iterator; - break; - } - } + @sa @ref crbegin() -- returns a const reverse iterator to the beginning + @sa @ref rend() -- returns a reverse iterator to the end + @sa @ref crend() -- returns a const reverse iterator to the end - return *this; - } + @since version 1.0.0 + */ + reverse_iterator rbegin() noexcept + { + return reverse_iterator(end()); + } - /*! - @brief comparison: equal - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - bool operator==(const iter_impl& other) const - { - // if objects are not the same, the comparison is undefined - if (m_object != other.m_object) - { - JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers")); - } + /*! + @copydoc basic_json::crbegin() + */ + const_reverse_iterator rbegin() const noexcept + { + return crbegin(); + } - assert(m_object != nullptr); + /*! + @brief returns an iterator to the reverse-end - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - return (m_it.object_iterator == other.m_it.object_iterator); - } + Returns an iterator to the reverse-end; that is, one before the first + element. - case basic_json::value_t::array: - { - return (m_it.array_iterator == other.m_it.array_iterator); - } + @image html range-rbegin-rend.svg "Illustration from cppreference.com" - default: - { - return (m_it.primitive_iterator == other.m_it.primitive_iterator); - } - } - } + @complexity Constant. - /*! - @brief comparison: not equal - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - bool operator!=(const iter_impl& other) const - { - return not operator==(other); - } + @requirement This function helps `basic_json` satisfying the + [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) + requirements: + - The complexity is constant. + - Has the semantics of `reverse_iterator(begin())`. - /*! - @brief comparison: smaller - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - bool operator<(const iter_impl& other) const - { - // if objects are not the same, the comparison is undefined - if (m_object != other.m_object) - { - JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers")); - } + @liveexample{The following code shows an example for `rend()`.,rend} - assert(m_object != nullptr); + @sa @ref crend() -- returns a const reverse iterator to the end + @sa @ref rbegin() -- returns a reverse iterator to the beginning + @sa @ref crbegin() -- returns a const reverse iterator to the beginning - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators")); - } + @since version 1.0.0 + */ + reverse_iterator rend() noexcept + { + return reverse_iterator(begin()); + } - case basic_json::value_t::array: - { - return (m_it.array_iterator < other.m_it.array_iterator); - } + /*! + @copydoc basic_json::crend() + */ + const_reverse_iterator rend() const noexcept + { + return crend(); + } - default: - { - return (m_it.primitive_iterator < other.m_it.primitive_iterator); - } - } - } + /*! + @brief returns a const reverse iterator to the last element - /*! - @brief comparison: less than or equal - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - bool operator<=(const iter_impl& other) const - { - return not other.operator < (*this); - } + Returns a const iterator to the reverse-beginning; that is, the last + element. - /*! - @brief comparison: greater than - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - bool operator>(const iter_impl& other) const - { - return not operator<=(other); - } + @image html range-rbegin-rend.svg "Illustration from cppreference.com" - /*! - @brief comparison: greater than or equal - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - bool operator>=(const iter_impl& other) const - { - return not operator<(other); - } + @complexity Constant. - /*! - @brief add to iterator - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - iter_impl& operator+=(difference_type i) - { - assert(m_object != nullptr); - - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators")); - } + @requirement This function helps `basic_json` satisfying the + [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) + requirements: + - The complexity is constant. + - Has the semantics of `const_cast(*this).rbegin()`. - case basic_json::value_t::array: - { - std::advance(m_it.array_iterator, i); - break; - } + @liveexample{The following code shows an example for `crbegin()`.,crbegin} - default: - { - m_it.primitive_iterator += i; - break; - } - } + @sa @ref rbegin() -- returns a reverse iterator to the beginning + @sa @ref rend() -- returns a reverse iterator to the end + @sa @ref crend() -- returns a const reverse iterator to the end - return *this; - } + @since version 1.0.0 + */ + const_reverse_iterator crbegin() const noexcept + { + return const_reverse_iterator(cend()); + } - /*! - @brief subtract from iterator - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - iter_impl& operator-=(difference_type i) - { - return operator+=(-i); - } + /*! + @brief returns a const reverse iterator to one before the first - /*! - @brief add to iterator - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - iter_impl operator+(difference_type i) - { - auto result = *this; - result += i; - return result; - } + Returns a const reverse iterator to the reverse-end; that is, one before + the first element. - /*! - @brief subtract from iterator - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - iter_impl operator-(difference_type i) - { - auto result = *this; - result -= i; - return result; - } + @image html range-rbegin-rend.svg "Illustration from cppreference.com" - /*! - @brief return difference - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - difference_type operator-(const iter_impl& other) const - { - assert(m_object != nullptr); + @complexity Constant. - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators")); - } + @requirement This function helps `basic_json` satisfying the + [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) + requirements: + - The complexity is constant. + - Has the semantics of `const_cast(*this).rend()`. - case basic_json::value_t::array: - { - return m_it.array_iterator - other.m_it.array_iterator; - } + @liveexample{The following code shows an example for `crend()`.,crend} - default: - { - return m_it.primitive_iterator - other.m_it.primitive_iterator; - } - } - } + @sa @ref rend() -- returns a reverse iterator to the end + @sa @ref rbegin() -- returns a reverse iterator to the beginning + @sa @ref crbegin() -- returns a const reverse iterator to the beginning - /*! - @brief access to successor - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - reference operator[](difference_type n) const - { - assert(m_object != nullptr); + @since version 1.0.0 + */ + const_reverse_iterator crend() const noexcept + { + return const_reverse_iterator(cbegin()); + } - switch (m_object->m_type) - { - case basic_json::value_t::object: - { - JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators")); - } + public: + /*! + @brief wrapper to access iterator member functions in range-based for - case basic_json::value_t::array: - { - return *std::next(m_it.array_iterator, n); - } + This function allows to access @ref iterator::key() and @ref + iterator::value() during range-based for loops. In these loops, a + reference to the JSON values is returned, so there is no access to the + underlying iterator. - case basic_json::value_t::null: - { - JSON_THROW(invalid_iterator::create(214, "cannot get value")); - } + For loop without iterator_wrapper: - default: - { - if (m_it.primitive_iterator.get_value() == -n) - { - return *m_object; - } + @code{cpp} + for (auto it = j_object.begin(); it != j_object.end(); ++it) + { + std::cout << "key: " << it.key() << ", value:" << it.value() << '\n'; + } + @endcode - JSON_THROW(invalid_iterator::create(214, "cannot get value")); - } - } - } + Range-based for loop without iterator proxy: - /*! - @brief return the key of an object iterator - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - typename object_t::key_type key() const - { - assert(m_object != nullptr); + @code{cpp} + for (auto it : j_object) + { + // "it" is of type json::reference and has no key() member + std::cout << "value: " << it << '\n'; + } + @endcode - if (m_object->is_object()) - { - return m_it.object_iterator->first; - } + Range-based for loop with iterator proxy: - JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators")); - } + @code{cpp} + for (auto it : json::iterator_wrapper(j_object)) + { + std::cout << "key: " << it.key() << ", value:" << it.value() << '\n'; + } + @endcode - /*! - @brief return the value of an iterator - @pre The iterator is initialized; i.e. `m_object != nullptr`. - */ - reference value() const - { - return operator*(); - } + @note When iterating over an array, `key()` will return the index of the + element as string (see example). - private: - /// associated JSON instance - pointer m_object = nullptr; - /// the actual iterator of the associated instance - internal_iterator m_it = internal_iterator(); - }; + @param[in] ref reference to a JSON value + @return iteration proxy object wrapping @a ref with an interface to use in + range-based for loops - /*! - @brief a template for a reverse iterator class + @liveexample{The following code shows how the wrapper is used,iterator_wrapper} - @tparam Base the base iterator type to reverse. Valid types are @ref - iterator (to create @ref reverse_iterator) and @ref const_iterator (to - create @ref const_reverse_iterator). + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. - @requirement The class satisfies the following concept requirements: - - [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator): - The iterator that can be moved to point (forward and backward) to any - element in constant time. - - [OutputIterator](http://en.cppreference.com/w/cpp/concept/OutputIterator): - It is possible to write to the pointed-to element (only if @a Base is - @ref iterator). + @complexity Constant. - @since version 1.0.0 + @note The name of this function is not yet final and may change in the + future. */ - template - class json_reverse_iterator : public std::reverse_iterator + static iteration_proxy iterator_wrapper(reference ref) { - public: - /// shortcut to the reverse iterator adaptor - using base_iterator = std::reverse_iterator; - /// the reference type for the pointed-to element - using reference = typename Base::reference; - - /// create reverse iterator from iterator - json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept - : base_iterator(it) - {} + return iteration_proxy(ref); + } - /// create reverse iterator from base class - json_reverse_iterator(const base_iterator& it) noexcept - : base_iterator(it) - {} + /*! + @copydoc iterator_wrapper(reference) + */ + static iteration_proxy iterator_wrapper(const_reference ref) + { + return iteration_proxy(ref); + } - /// post-increment (it++) - json_reverse_iterator operator++(int) - { - return base_iterator::operator++(1); - } + /// @} - /// pre-increment (++it) - json_reverse_iterator& operator++() - { - base_iterator::operator++(); - return *this; - } - /// post-decrement (it--) - json_reverse_iterator operator--(int) - { - return base_iterator::operator--(1); - } + ////////////// + // capacity // + ////////////// - /// pre-decrement (--it) - json_reverse_iterator& operator--() - { - base_iterator::operator--(); - return *this; - } + /// @name capacity + /// @{ - /// add to iterator - json_reverse_iterator& operator+=(difference_type i) - { - base_iterator::operator+=(i); - return *this; - } + /*! + @brief checks whether the container is empty. - /// add to iterator - json_reverse_iterator operator+(difference_type i) const - { - auto result = *this; - result += i; - return result; - } + Checks if a JSON value has no elements (i.e. whether its @ref size is `0`). - /// subtract from iterator - json_reverse_iterator operator-(difference_type i) const - { - auto result = *this; - result -= i; - return result; - } + @return The return value depends on the different types and is + defined as follows: + Value type | return value + ----------- | ------------- + null | `true` + boolean | `false` + string | `false` + number | `false` + object | result of function `object_t::empty()` + array | result of function `array_t::empty()` - /// return difference - difference_type operator-(const json_reverse_iterator& other) const - { - return this->base() - other.base(); - } + @liveexample{The following code uses `empty()` to check if a JSON + object contains any elements.,empty} - /// access to successor - reference operator[](difference_type n) const - { - return *(this->operator+(n)); - } + @complexity Constant, as long as @ref array_t and @ref object_t satisfy + the Container concept; that is, their `empty()` functions have constant + complexity. - /// return the key of an object iterator - typename object_t::key_type key() const - { - auto it = --this->base(); - return it.key(); - } + @iterators No changes. - /// return the value of an iterator - reference value() const - { - auto it = --this->base(); - return it.operator * (); - } - }; + @exceptionsafety No-throw guarantee: this function never throws exceptions. + @note This function does not return whether a string stored as JSON value + is empty - it returns whether the JSON container itself is empty which is + false in the case of a string. - private: - ////////////////////// - // lexer and parser // - ////////////////////// + @requirement This function helps `basic_json` satisfying the + [Container](http://en.cppreference.com/w/cpp/concept/Container) + requirements: + - The complexity is constant. + - Has the semantics of `begin() == end()`. - /*! - @brief lexical analysis + @sa @ref size() -- returns the number of elements - This class organizes the lexical analysis during JSON deserialization. The - core of it is a scanner generated by [re2c](http://re2c.org) that - processes a buffer and recognizes tokens according to RFC 7159. + @since version 1.0.0 */ - class lexer + bool empty() const noexcept { - public: - /// token types for the parser - enum class token_type - { - uninitialized, ///< indicating the scanner is uninitialized - literal_true, ///< the `true` literal - literal_false, ///< the `false` literal - literal_null, ///< the `null` literal - value_string, ///< a string -- use get_string() for actual value - value_unsigned, ///< an unsigned integer -- use get_number() for actual value - value_integer, ///< a signed integer -- use get_number() for actual value - value_float, ///< an floating point number -- use get_number() for actual value - begin_array, ///< the character for array begin `[` - begin_object, ///< the character for object begin `{` - end_array, ///< the character for array end `]` - end_object, ///< the character for object end `}` - name_separator, ///< the name separator `:` - value_separator, ///< the value separator `,` - parse_error, ///< indicating a parse error - end_of_input ///< indicating the end of the input buffer - }; - - /// the char type to use in the lexer - using lexer_char_t = unsigned char; - - /// a lexer from a buffer with given length - lexer(const lexer_char_t* buff, const size_t len) noexcept - : m_content(buff) + switch (m_type) { - assert(m_content != nullptr); - m_start = m_cursor = m_content; - m_limit = m_content + len; - } + case value_t::null: + { + // null values are empty + return true; + } - /*! - @brief a lexer from an input stream - @throw parse_error.111 if input stream is in a bad state - */ - explicit lexer(std::istream& s) - : m_stream(&s), m_line_buffer() - { - // immediately abort if stream is erroneous - if (s.fail()) + case value_t::array: { - JSON_THROW(parse_error::create(111, 0, "bad input stream")); + // delegate call to array_t::empty() + return m_value.array->empty(); } - // fill buffer - fill_line_buffer(); + case value_t::object: + { + // delegate call to object_t::empty() + return m_value.object->empty(); + } - // skip UTF-8 byte-order mark - if (m_line_buffer.size() >= 3 and m_line_buffer.substr(0, 3) == "\xEF\xBB\xBF") + default: { - m_line_buffer[0] = ' '; - m_line_buffer[1] = ' '; - m_line_buffer[2] = ' '; + // all other types are nonempty + return false; } } + } - // switch off unwanted functions (due to pointer members) - lexer() = delete; - lexer(const lexer&) = delete; - lexer operator=(const lexer&) = delete; + /*! + @brief returns the number of elements - /*! - @brief create a string from one or two Unicode code points + Returns the number of elements in a JSON value. - There are two cases: (1) @a codepoint1 is in the Basic Multilingual - Plane (U+0000 through U+FFFF) and @a codepoint2 is 0, or (2) - @a codepoint1 and @a codepoint2 are a UTF-16 surrogate pair to - represent a code point above U+FFFF. + @return The return value depends on the different types and is + defined as follows: + Value type | return value + ----------- | ------------- + null | `0` + boolean | `1` + string | `1` + number | `1` + object | result of function object_t::size() + array | result of function array_t::size() - @param[in] codepoint1 the code point (can be high surrogate) - @param[in] codepoint2 the code point (can be low surrogate or 0) + @liveexample{The following code calls `size()` on the different value + types.,size} - @return string representation of the code point; the length of the - result string is between 1 and 4 characters. + @complexity Constant, as long as @ref array_t and @ref object_t satisfy + the Container concept; that is, their size() functions have constant + complexity. - @throw parse_error.102 if the low surrogate is invalid; example: - `""missing or wrong low surrogate""` - @throw parse_error.103 if code point is > 0x10ffff; example: `"code - points above 0x10FFFF are invalid"` + @iterators No changes. - @complexity Constant. + @exceptionsafety No-throw guarantee: this function never throws exceptions. - @see - */ - string_t to_unicode(const std::size_t codepoint1, - const std::size_t codepoint2 = 0) const - { - // calculate the code point from the given code points - std::size_t codepoint = codepoint1; + @note This function does not return the length of a string stored as JSON + value - it returns the number of elements in the JSON value which is 1 in + the case of a string. - // check if codepoint1 is a high surrogate - if (codepoint1 >= 0xD800 and codepoint1 <= 0xDBFF) - { - // check if codepoint2 is a low surrogate - if (codepoint2 >= 0xDC00 and codepoint2 <= 0xDFFF) - { - codepoint = - // high surrogate occupies the most significant 22 bits - (codepoint1 << 10) - // low surrogate occupies the least significant 15 bits - + codepoint2 - // there is still the 0xD800, 0xDC00 and 0x10000 noise - // in the result so we have to subtract with: - // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 - - 0x35FDC00; - } - else - { - JSON_THROW(parse_error::create(102, get_position(), "missing or wrong low surrogate")); - } - } + @requirement This function helps `basic_json` satisfying the + [Container](http://en.cppreference.com/w/cpp/concept/Container) + requirements: + - The complexity is constant. + - Has the semantics of `std::distance(begin(), end())`. - string_t result; + @sa @ref empty() -- checks whether the container is empty + @sa @ref max_size() -- returns the maximal number of elements - if (codepoint < 0x80) + @since version 1.0.0 + */ + size_type size() const noexcept + { + switch (m_type) + { + case value_t::null: { - // 1-byte characters: 0xxxxxxx (ASCII) - result.append(1, static_cast(codepoint)); + // null values are empty + return 0; } - else if (codepoint <= 0x7ff) + + case value_t::array: { - // 2-byte characters: 110xxxxx 10xxxxxx - result.append(1, static_cast(0xC0 | (codepoint >> 6))); - result.append(1, static_cast(0x80 | (codepoint & 0x3F))); + // delegate call to array_t::size() + return m_value.array->size(); } - else if (codepoint <= 0xffff) + + case value_t::object: { - // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx - result.append(1, static_cast(0xE0 | (codepoint >> 12))); - result.append(1, static_cast(0x80 | ((codepoint >> 6) & 0x3F))); - result.append(1, static_cast(0x80 | (codepoint & 0x3F))); + // delegate call to object_t::size() + return m_value.object->size(); } - else if (codepoint <= 0x10ffff) + + default: { - // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - result.append(1, static_cast(0xF0 | (codepoint >> 18))); - result.append(1, static_cast(0x80 | ((codepoint >> 12) & 0x3F))); - result.append(1, static_cast(0x80 | ((codepoint >> 6) & 0x3F))); - result.append(1, static_cast(0x80 | (codepoint & 0x3F))); + // all other types have size 1 + return 1; } - else + } + } + + /*! + @brief returns the maximum possible number of elements + + Returns the maximum number of elements a JSON value is able to hold due to + system or library implementation limitations, i.e. `std::distance(begin(), + end())` for the JSON value. + + @return The return value depends on the different types and is + defined as follows: + Value type | return value + ----------- | ------------- + null | `0` (same as `size()`) + boolean | `1` (same as `size()`) + string | `1` (same as `size()`) + number | `1` (same as `size()`) + object | result of function `object_t::max_size()` + array | result of function `array_t::max_size()` + + @liveexample{The following code calls `max_size()` on the different value + types. Note the output is implementation specific.,max_size} + + @complexity Constant, as long as @ref array_t and @ref object_t satisfy + the Container concept; that is, their `max_size()` functions have constant + complexity. + + @iterators No changes. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @requirement This function helps `basic_json` satisfying the + [Container](http://en.cppreference.com/w/cpp/concept/Container) + requirements: + - The complexity is constant. + - Has the semantics of returning `b.size()` where `b` is the largest + possible JSON value. + + @sa @ref size() -- returns the number of elements + + @since version 1.0.0 + */ + size_type max_size() const noexcept + { + switch (m_type) + { + case value_t::array: { - JSON_THROW(parse_error::create(103, get_position(), "code points above 0x10FFFF are invalid")); + // delegate call to array_t::max_size() + return m_value.array->max_size(); } - return result; + case value_t::object: + { + // delegate call to object_t::max_size() + return m_value.object->max_size(); + } + + default: + { + // all other types have max_size() == size() + return size(); + } } + } + + /// @} + + + /////////////// + // modifiers // + /////////////// + + /// @name modifiers + /// @{ + + /*! + @brief clears the contents + + Clears the content of a JSON value and resets it to the default value as + if @ref basic_json(value_t) would have been called with the current value + type from @ref type(): + + Value type | initial value + ----------- | ------------- + null | `null` + boolean | `false` + string | `""` + number | `0` + object | `{}` + array | `[]` + + @post Has the same effect as calling + @code {.cpp} + *this = basic_json(type()); + @endcode + + @liveexample{The example below shows the effect of `clear()` to different + JSON types.,clear} + + @complexity Linear in the size of the JSON value. - /// return name of values of type token_type (only used for errors) - static std::string token_type_name(const token_type t) + @iterators All iterators, pointers and references related to this container + are invalidated. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @sa @ref basic_json(value_t) -- constructor that creates an object with the + same value than calling `clear()` + + @since version 1.0.0 + */ + void clear() noexcept + { + switch (m_type) { - switch (t) + case value_t::number_integer: { - case token_type::uninitialized: - return ""; - case token_type::literal_true: - return "true literal"; - case token_type::literal_false: - return "false literal"; - case token_type::literal_null: - return "null literal"; - case token_type::value_string: - return "string literal"; - case lexer::token_type::value_unsigned: - case lexer::token_type::value_integer: - case lexer::token_type::value_float: - return "number literal"; - case token_type::begin_array: - return "'['"; - case token_type::begin_object: - return "'{'"; - case token_type::end_array: - return "']'"; - case token_type::end_object: - return "'}'"; - case token_type::name_separator: - return "':'"; - case token_type::value_separator: - return "','"; - case token_type::parse_error: - return ""; - case token_type::end_of_input: - return "end of input"; - default: - { - // catch non-enum values - return "unknown token"; // LCOV_EXCL_LINE - } + m_value.number_integer = 0; + break; + } + + case value_t::number_unsigned: + { + m_value.number_unsigned = 0; + break; + } + + case value_t::number_float: + { + m_value.number_float = 0.0; + break; + } + + case value_t::boolean: + { + m_value.boolean = false; + break; + } + + case value_t::string: + { + m_value.string->clear(); + break; + } + + case value_t::array: + { + m_value.array->clear(); + break; + } + + case value_t::object: + { + m_value.object->clear(); + break; } + + default: + break; } + } + + /*! + @brief add an object to an array + + Appends the given element @a val to the end of the JSON value. If the + function is called on a JSON null value, an empty array is created before + appending @a val. - /*! - This function implements a scanner for JSON. It is specified using - regular expressions that try to follow RFC 7159 as close as possible. - These regular expressions are then translated into a minimized - deterministic finite automaton (DFA) by the tool - [re2c](http://re2c.org). As a result, the translated code for this - function consists of a large block of code with `goto` jumps. + @param[in] val the value to add to the JSON array - @return the class of the next token read from the buffer + @throw type_error.308 when called on a type other than JSON array or + null; example: `"cannot use push_back() with number"` - @complexity Linear in the length of the input.\n + @complexity Amortized constant. - Proposition: The loop below will always terminate for finite input.\n + @liveexample{The example shows how `push_back()` and `+=` can be used to + add elements to a JSON array. Note how the `null` value was silently + converted to a JSON array.,push_back} - Proof (by contradiction): Assume a finite input. To loop forever, the - loop must never hit code with a `break` statement. The only code - snippets without a `break` statement is the continue statement for - whitespace. To loop forever, the input must be an infinite sequence - whitespace. This contradicts the assumption of finite input, q.e.d. - */ - token_type scan() + @since version 1.0.0 + */ + void push_back(basic_json&& val) + { + // push_back only works for null objects or arrays + if (JSON_UNLIKELY(not(is_null() or is_array()))) { - while (true) - { - // pointer for backtracking information - m_marker = nullptr; + JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()))); + } - // remember the begin of the token - m_start = m_cursor; - assert(m_start != nullptr); + // transform null object into an array + if (is_null()) + { + m_type = value_t::array; + m_value = value_t::array; + assert_invariant(); + } + // add element to array (move semantics) + m_value.array->push_back(std::move(val)); + // invalidate object + val.m_type = value_t::null; + } - { - lexer_char_t yych; - unsigned int yyaccept = 0; - static const unsigned char yybm[] = - { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 32, 32, 0, 0, 32, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 160, 128, 0, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 0, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - if ((m_limit - m_cursor) < 5) - { - fill_line_buffer(5); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yybm[0 + yych] & 32) - { - goto basic_json_parser_6; - } - if (yych <= '[') - { - if (yych <= '-') - { - if (yych <= '"') - { - if (yych <= 0x00) - { - goto basic_json_parser_2; - } - if (yych <= '!') - { - goto basic_json_parser_4; - } - goto basic_json_parser_9; - } - else - { - if (yych <= '+') - { - goto basic_json_parser_4; - } - if (yych <= ',') - { - goto basic_json_parser_10; - } - goto basic_json_parser_12; - } - } - else - { - if (yych <= '9') - { - if (yych <= '/') - { - goto basic_json_parser_4; - } - if (yych <= '0') - { - goto basic_json_parser_13; - } - goto basic_json_parser_15; - } - else - { - if (yych <= ':') - { - goto basic_json_parser_17; - } - if (yych <= 'Z') - { - goto basic_json_parser_4; - } - goto basic_json_parser_19; - } - } - } - else - { - if (yych <= 'n') - { - if (yych <= 'e') - { - if (yych == ']') - { - goto basic_json_parser_21; - } - goto basic_json_parser_4; - } - else - { - if (yych <= 'f') - { - goto basic_json_parser_23; - } - if (yych <= 'm') - { - goto basic_json_parser_4; - } - goto basic_json_parser_24; - } - } - else - { - if (yych <= 'z') - { - if (yych == 't') - { - goto basic_json_parser_25; - } - goto basic_json_parser_4; - } - else - { - if (yych <= '{') - { - goto basic_json_parser_26; - } - if (yych == '}') - { - goto basic_json_parser_28; - } - goto basic_json_parser_4; - } - } - } -basic_json_parser_2: - ++m_cursor; - { - last_token_type = token_type::end_of_input; - break; - } -basic_json_parser_4: - ++m_cursor; -basic_json_parser_5: - { - last_token_type = token_type::parse_error; - break; - } -basic_json_parser_6: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yybm[0 + yych] & 32) - { - goto basic_json_parser_6; - } - { - position += static_cast((m_cursor - m_start)); - continue; - } -basic_json_parser_9: - yyaccept = 0; - yych = *(m_marker = ++m_cursor); - if (yych <= 0x1F) - { - goto basic_json_parser_5; - } - if (yych <= 0x7F) - { - goto basic_json_parser_31; - } - if (yych <= 0xC1) - { - goto basic_json_parser_5; - } - if (yych <= 0xF4) - { - goto basic_json_parser_31; - } - goto basic_json_parser_5; -basic_json_parser_10: - ++m_cursor; - { - last_token_type = token_type::value_separator; - break; - } -basic_json_parser_12: - yych = *++m_cursor; - if (yych <= '/') - { - goto basic_json_parser_5; - } - if (yych <= '0') - { - goto basic_json_parser_43; - } - if (yych <= '9') - { - goto basic_json_parser_45; - } - goto basic_json_parser_5; -basic_json_parser_13: - yyaccept = 1; - yych = *(m_marker = ++m_cursor); - if (yych <= '9') - { - if (yych == '.') - { - goto basic_json_parser_47; - } - if (yych >= '0') - { - goto basic_json_parser_48; - } - } - else - { - if (yych <= 'E') - { - if (yych >= 'E') - { - goto basic_json_parser_51; - } - } - else - { - if (yych == 'e') - { - goto basic_json_parser_51; - } - } - } -basic_json_parser_14: - { - last_token_type = token_type::value_unsigned; - break; - } -basic_json_parser_15: - yyaccept = 1; - m_marker = ++m_cursor; - if ((m_limit - m_cursor) < 3) - { - fill_line_buffer(3); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yybm[0 + yych] & 64) - { - goto basic_json_parser_15; - } - if (yych <= 'D') - { - if (yych == '.') - { - goto basic_json_parser_47; - } - goto basic_json_parser_14; - } - else - { - if (yych <= 'E') - { - goto basic_json_parser_51; - } - if (yych == 'e') - { - goto basic_json_parser_51; - } - goto basic_json_parser_14; - } -basic_json_parser_17: - ++m_cursor; - { - last_token_type = token_type::name_separator; - break; - } -basic_json_parser_19: - ++m_cursor; - { - last_token_type = token_type::begin_array; - break; - } -basic_json_parser_21: - ++m_cursor; - { - last_token_type = token_type::end_array; - break; - } -basic_json_parser_23: - yyaccept = 0; - yych = *(m_marker = ++m_cursor); - if (yych == 'a') - { - goto basic_json_parser_52; - } - goto basic_json_parser_5; -basic_json_parser_24: - yyaccept = 0; - yych = *(m_marker = ++m_cursor); - if (yych == 'u') - { - goto basic_json_parser_53; - } - goto basic_json_parser_5; -basic_json_parser_25: - yyaccept = 0; - yych = *(m_marker = ++m_cursor); - if (yych == 'r') - { - goto basic_json_parser_54; - } - goto basic_json_parser_5; -basic_json_parser_26: - ++m_cursor; - { - last_token_type = token_type::begin_object; - break; - } -basic_json_parser_28: - ++m_cursor; - { - last_token_type = token_type::end_object; - break; - } -basic_json_parser_30: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; -basic_json_parser_31: - if (yybm[0 + yych] & 128) - { - goto basic_json_parser_30; - } - if (yych <= 0xE0) - { - if (yych <= '\\') - { - if (yych <= 0x1F) - { - goto basic_json_parser_32; - } - if (yych <= '"') - { - goto basic_json_parser_33; - } - goto basic_json_parser_35; - } - else - { - if (yych <= 0xC1) - { - goto basic_json_parser_32; - } - if (yych <= 0xDF) - { - goto basic_json_parser_36; - } - goto basic_json_parser_37; - } - } - else - { - if (yych <= 0xEF) - { - if (yych == 0xED) - { - goto basic_json_parser_39; - } - goto basic_json_parser_38; - } - else - { - if (yych <= 0xF0) - { - goto basic_json_parser_40; - } - if (yych <= 0xF3) - { - goto basic_json_parser_41; - } - if (yych <= 0xF4) - { - goto basic_json_parser_42; - } - } - } -basic_json_parser_32: - m_cursor = m_marker; - if (yyaccept <= 1) - { - if (yyaccept == 0) - { - goto basic_json_parser_5; - } - else - { - goto basic_json_parser_14; - } - } - else - { - if (yyaccept == 2) - { - goto basic_json_parser_44; - } - else - { - goto basic_json_parser_58; - } - } -basic_json_parser_33: - ++m_cursor; - { - last_token_type = token_type::value_string; - break; - } -basic_json_parser_35: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= 'e') - { - if (yych <= '/') - { - if (yych == '"') - { - goto basic_json_parser_30; - } - if (yych <= '.') - { - goto basic_json_parser_32; - } - goto basic_json_parser_30; - } - else - { - if (yych <= '\\') - { - if (yych <= '[') - { - goto basic_json_parser_32; - } - goto basic_json_parser_30; - } - else - { - if (yych == 'b') - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; - } - } - } - else - { - if (yych <= 'q') - { - if (yych <= 'f') - { - goto basic_json_parser_30; - } - if (yych == 'n') - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; - } - else - { - if (yych <= 's') - { - if (yych <= 'r') - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; - } - else - { - if (yych <= 't') - { - goto basic_json_parser_30; - } - if (yych <= 'u') - { - goto basic_json_parser_55; - } - goto basic_json_parser_32; - } - } - } -basic_json_parser_36: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= 0x7F) - { - goto basic_json_parser_32; - } - if (yych <= 0xBF) - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; -basic_json_parser_37: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= 0x9F) - { - goto basic_json_parser_32; - } - if (yych <= 0xBF) - { - goto basic_json_parser_36; - } - goto basic_json_parser_32; -basic_json_parser_38: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= 0x7F) - { - goto basic_json_parser_32; - } - if (yych <= 0xBF) - { - goto basic_json_parser_36; - } - goto basic_json_parser_32; -basic_json_parser_39: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= 0x7F) - { - goto basic_json_parser_32; - } - if (yych <= 0x9F) - { - goto basic_json_parser_36; - } - goto basic_json_parser_32; -basic_json_parser_40: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= 0x8F) - { - goto basic_json_parser_32; - } - if (yych <= 0xBF) - { - goto basic_json_parser_38; - } - goto basic_json_parser_32; -basic_json_parser_41: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= 0x7F) - { - goto basic_json_parser_32; - } - if (yych <= 0xBF) - { - goto basic_json_parser_38; - } - goto basic_json_parser_32; -basic_json_parser_42: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= 0x7F) - { - goto basic_json_parser_32; - } - if (yych <= 0x8F) - { - goto basic_json_parser_38; - } - goto basic_json_parser_32; -basic_json_parser_43: - yyaccept = 2; - yych = *(m_marker = ++m_cursor); - if (yych <= '9') - { - if (yych == '.') - { - goto basic_json_parser_47; - } - if (yych >= '0') - { - goto basic_json_parser_48; - } - } - else - { - if (yych <= 'E') - { - if (yych >= 'E') - { - goto basic_json_parser_51; - } - } - else - { - if (yych == 'e') - { - goto basic_json_parser_51; - } - } - } -basic_json_parser_44: - { - last_token_type = token_type::value_integer; - break; - } -basic_json_parser_45: - yyaccept = 2; - m_marker = ++m_cursor; - if ((m_limit - m_cursor) < 3) - { - fill_line_buffer(3); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= '9') - { - if (yych == '.') - { - goto basic_json_parser_47; - } - if (yych <= '/') - { - goto basic_json_parser_44; - } - goto basic_json_parser_45; - } - else - { - if (yych <= 'E') - { - if (yych <= 'D') - { - goto basic_json_parser_44; - } - goto basic_json_parser_51; - } - else - { - if (yych == 'e') - { - goto basic_json_parser_51; - } - goto basic_json_parser_44; - } - } -basic_json_parser_47: - yych = *++m_cursor; - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych <= '9') - { - goto basic_json_parser_56; - } - goto basic_json_parser_32; -basic_json_parser_48: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= '/') - { - goto basic_json_parser_50; - } - if (yych <= '9') - { - goto basic_json_parser_48; - } -basic_json_parser_50: - { - last_token_type = token_type::parse_error; - break; - } -basic_json_parser_51: - yych = *++m_cursor; - if (yych <= ',') - { - if (yych == '+') - { - goto basic_json_parser_59; - } - goto basic_json_parser_32; - } - else - { - if (yych <= '-') - { - goto basic_json_parser_59; - } - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych <= '9') - { - goto basic_json_parser_60; - } - goto basic_json_parser_32; - } -basic_json_parser_52: - yych = *++m_cursor; - if (yych == 'l') - { - goto basic_json_parser_62; - } - goto basic_json_parser_32; -basic_json_parser_53: - yych = *++m_cursor; - if (yych == 'l') - { - goto basic_json_parser_63; - } - goto basic_json_parser_32; -basic_json_parser_54: - yych = *++m_cursor; - if (yych == 'u') - { - goto basic_json_parser_64; - } - goto basic_json_parser_32; -basic_json_parser_55: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= '@') - { - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych <= '9') - { - goto basic_json_parser_65; - } - goto basic_json_parser_32; - } - else - { - if (yych <= 'F') - { - goto basic_json_parser_65; - } - if (yych <= '`') - { - goto basic_json_parser_32; - } - if (yych <= 'f') - { - goto basic_json_parser_65; - } - goto basic_json_parser_32; - } -basic_json_parser_56: - yyaccept = 3; - m_marker = ++m_cursor; - if ((m_limit - m_cursor) < 3) - { - fill_line_buffer(3); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= 'D') - { - if (yych <= '/') - { - goto basic_json_parser_58; - } - if (yych <= '9') - { - goto basic_json_parser_56; - } - } - else - { - if (yych <= 'E') - { - goto basic_json_parser_51; - } - if (yych == 'e') - { - goto basic_json_parser_51; - } - } -basic_json_parser_58: - { - last_token_type = token_type::value_float; - break; - } -basic_json_parser_59: - yych = *++m_cursor; - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych >= ':') - { - goto basic_json_parser_32; - } -basic_json_parser_60: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= '/') - { - goto basic_json_parser_58; - } - if (yych <= '9') - { - goto basic_json_parser_60; - } - goto basic_json_parser_58; -basic_json_parser_62: - yych = *++m_cursor; - if (yych == 's') - { - goto basic_json_parser_66; - } - goto basic_json_parser_32; -basic_json_parser_63: - yych = *++m_cursor; - if (yych == 'l') - { - goto basic_json_parser_67; - } - goto basic_json_parser_32; -basic_json_parser_64: - yych = *++m_cursor; - if (yych == 'e') - { - goto basic_json_parser_69; - } - goto basic_json_parser_32; -basic_json_parser_65: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= '@') - { - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych <= '9') - { - goto basic_json_parser_71; - } - goto basic_json_parser_32; - } - else - { - if (yych <= 'F') - { - goto basic_json_parser_71; - } - if (yych <= '`') - { - goto basic_json_parser_32; - } - if (yych <= 'f') - { - goto basic_json_parser_71; - } - goto basic_json_parser_32; - } -basic_json_parser_66: - yych = *++m_cursor; - if (yych == 'e') - { - goto basic_json_parser_72; - } - goto basic_json_parser_32; -basic_json_parser_67: - ++m_cursor; - { - last_token_type = token_type::literal_null; - break; - } -basic_json_parser_69: - ++m_cursor; - { - last_token_type = token_type::literal_true; - break; - } -basic_json_parser_71: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= '@') - { - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych <= '9') - { - goto basic_json_parser_74; - } - goto basic_json_parser_32; - } - else - { - if (yych <= 'F') - { - goto basic_json_parser_74; - } - if (yych <= '`') - { - goto basic_json_parser_32; - } - if (yych <= 'f') - { - goto basic_json_parser_74; - } - goto basic_json_parser_32; - } -basic_json_parser_72: - ++m_cursor; - { - last_token_type = token_type::literal_false; - break; - } -basic_json_parser_74: - ++m_cursor; - if (m_limit <= m_cursor) - { - fill_line_buffer(1); // LCOV_EXCL_LINE - } - yych = *m_cursor; - if (yych <= '@') - { - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych <= '9') - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; - } - else - { - if (yych <= 'F') - { - goto basic_json_parser_30; - } - if (yych <= '`') - { - goto basic_json_parser_32; - } - if (yych <= 'f') - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; - } - } + /*! + @brief add an object to an array + @copydoc push_back(basic_json&&) + */ + reference operator+=(basic_json&& val) + { + push_back(std::move(val)); + return *this; + } + + /*! + @brief add an object to an array + @copydoc push_back(basic_json&&) + */ + void push_back(const basic_json& val) + { + // push_back only works for null objects or arrays + if (JSON_UNLIKELY(not(is_null() or is_array()))) + { + JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()))); + } + + // transform null object into an array + if (is_null()) + { + m_type = value_t::array; + m_value = value_t::array; + assert_invariant(); + } + + // add element to array + m_value.array->push_back(val); + } + + /*! + @brief add an object to an array + @copydoc push_back(basic_json&&) + */ + reference operator+=(const basic_json& val) + { + push_back(val); + return *this; + } + + /*! + @brief add an object to an object + + Inserts the given element @a val to the JSON object. If the function is + called on a JSON null value, an empty object is created before inserting + @a val. + + @param[in] val the value to add to the JSON object + + @throw type_error.308 when called on a type other than JSON object or + null; example: `"cannot use push_back() with number"` + + @complexity Logarithmic in the size of the container, O(log(`size()`)). + + @liveexample{The example shows how `push_back()` and `+=` can be used to + add elements to a JSON object. Note how the `null` value was silently + converted to a JSON object.,push_back__object_t__value} + + @since version 1.0.0 + */ + void push_back(const typename object_t::value_type& val) + { + // push_back only works for null objects or objects + if (JSON_UNLIKELY(not(is_null() or is_object()))) + { + JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()))); + } + + // transform null object into an object + if (is_null()) + { + m_type = value_t::object; + m_value = value_t::object; + assert_invariant(); + } + + // add element to array + m_value.object->insert(val); + } + + /*! + @brief add an object to an object + @copydoc push_back(const typename object_t::value_type&) + */ + reference operator+=(const typename object_t::value_type& val) + { + push_back(val); + return *this; + } + + /*! + @brief add an object to an object + + This function allows to use `push_back` with an initializer list. In case + + 1. the current value is an object, + 2. the initializer list @a init contains only two elements, and + 3. the first element of @a init is a string, + + @a init is converted into an object element and added using + @ref push_back(const typename object_t::value_type&). Otherwise, @a init + is converted to a JSON value and added using @ref push_back(basic_json&&). + + @param[in] init an initializer list + + @complexity Linear in the size of the initializer list @a init. + + @note This function is required to resolve an ambiguous overload error, + because pairs like `{"key", "value"}` can be both interpreted as + `object_t::value_type` or `std::initializer_list`, see + https://github.com/nlohmann/json/issues/235 for more information. + + @liveexample{The example shows how initializer lists are treated as + objects when possible.,push_back__initializer_list} + */ + void push_back(initializer_list_t init) + { + if (is_object() and init.size() == 2 and (*init.begin())->is_string()) + { + basic_json&& key = init.begin()->moved_or_copied(); + push_back(typename object_t::value_type( + std::move(key.get_ref()), (init.begin() + 1)->moved_or_copied())); + } + else + { + push_back(basic_json(init)); + } + } + + /*! + @brief add an object to an object + @copydoc push_back(initializer_list_t) + */ + reference operator+=(initializer_list_t init) + { + push_back(init); + return *this; + } + + /*! + @brief add an object to an array + + Creates a JSON value from the passed parameters @a args to the end of the + JSON value. If the function is called on a JSON null value, an empty array + is created before appending the value created from @a args. + + @param[in] args arguments to forward to a constructor of @ref basic_json + @tparam Args compatible types to create a @ref basic_json object + + @throw type_error.311 when called on a type other than JSON array or + null; example: `"cannot use emplace_back() with number"` + + @complexity Amortized constant. + + @liveexample{The example shows how `push_back()` can be used to add + elements to a JSON array. Note how the `null` value was silently converted + to a JSON array.,emplace_back} + + @since version 2.0.8 + */ + template + void emplace_back(Args&& ... args) + { + // emplace_back only works for null objects or arrays + if (JSON_UNLIKELY(not(is_null() or is_array()))) + { + JSON_THROW(type_error::create(311, "cannot use emplace_back() with " + std::string(type_name()))); + } + + // transform null object into an array + if (is_null()) + { + m_type = value_t::array; + m_value = value_t::array; + assert_invariant(); + } + + // add element to array (perfect forwarding) + m_value.array->emplace_back(std::forward(args)...); + } + + /*! + @brief add an object to an object if key does not exist + + Inserts a new element into a JSON object constructed in-place with the + given @a args if there is no element with the key in the container. If the + function is called on a JSON null value, an empty object is created before + appending the value created from @a args. + + @param[in] args arguments to forward to a constructor of @ref basic_json + @tparam Args compatible types to create a @ref basic_json object + + @return a pair consisting of an iterator to the inserted element, or the + already-existing element if no insertion happened, and a bool + denoting whether the insertion took place. + + @throw type_error.311 when called on a type other than JSON object or + null; example: `"cannot use emplace() with number"` + + @complexity Logarithmic in the size of the container, O(log(`size()`)). + + @liveexample{The example shows how `emplace()` can be used to add elements + to a JSON object. Note how the `null` value was silently converted to a + JSON object. Further note how no value is added if there was already one + value stored with the same key.,emplace} + + @since version 2.0.8 + */ + template + std::pair emplace(Args&& ... args) + { + // emplace only works for null objects or arrays + if (JSON_UNLIKELY(not(is_null() or is_object()))) + { + JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name()))); + } + + // transform null object into an object + if (is_null()) + { + m_type = value_t::object; + m_value = value_t::object; + assert_invariant(); + } + + // add element to array (perfect forwarding) + auto res = m_value.object->emplace(std::forward(args)...); + // create result iterator and set iterator to the result of emplace + auto it = begin(); + it.m_it.object_iterator = res.first; + + // return pair of iterator and boolean + return {it, res.second}; + } + + /*! + @brief inserts element + + Inserts element @a val before iterator @a pos. + + @param[in] pos iterator before which the content will be inserted; may be + the end() iterator + @param[in] val element to insert + @return iterator pointing to the inserted @a val. + + @throw type_error.309 if called on JSON values other than arrays; + example: `"cannot use insert() with string"` + @throw invalid_iterator.202 if @a pos is not an iterator of *this; + example: `"iterator does not fit current value"` + + @complexity Constant plus linear in the distance between @a pos and end of + the container. + + @liveexample{The example shows how `insert()` is used.,insert} + + @since version 1.0.0 + */ + iterator insert(const_iterator pos, const basic_json& val) + { + // insert only works for arrays + if (JSON_LIKELY(is_array())) + { + // check if iterator pos fits to this JSON value + if (JSON_UNLIKELY(pos.m_object != this)) + { + JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); + } + + // insert to array and return iterator + iterator result(this); + result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val); + return result; + } + + JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()))); + } + + /*! + @brief inserts element + @copydoc insert(const_iterator, const basic_json&) + */ + iterator insert(const_iterator pos, basic_json&& val) + { + return insert(pos, val); + } + + /*! + @brief inserts elements + + Inserts @a cnt copies of @a val before iterator @a pos. + + @param[in] pos iterator before which the content will be inserted; may be + the end() iterator + @param[in] cnt number of copies of @a val to insert + @param[in] val element to insert + @return iterator pointing to the first element inserted, or @a pos if + `cnt==0` + + @throw type_error.309 if called on JSON values other than arrays; example: + `"cannot use insert() with string"` + @throw invalid_iterator.202 if @a pos is not an iterator of *this; + example: `"iterator does not fit current value"` + + @complexity Linear in @a cnt plus linear in the distance between @a pos + and end of the container. + + @liveexample{The example shows how `insert()` is used.,insert__count} + + @since version 1.0.0 + */ + iterator insert(const_iterator pos, size_type cnt, const basic_json& val) + { + // insert only works for arrays + if (JSON_LIKELY(is_array())) + { + // check if iterator pos fits to this JSON value + if (JSON_UNLIKELY(pos.m_object != this)) + { + JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); + } + + // insert to array and return iterator + iterator result(this); + result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val); + return result; + } + + JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()))); + } + + /*! + @brief inserts elements + + Inserts elements from range `[first, last)` before iterator @a pos. + + @param[in] pos iterator before which the content will be inserted; may be + the end() iterator + @param[in] first begin of the range of elements to insert + @param[in] last end of the range of elements to insert + + @throw type_error.309 if called on JSON values other than arrays; example: + `"cannot use insert() with string"` + @throw invalid_iterator.202 if @a pos is not an iterator of *this; + example: `"iterator does not fit current value"` + @throw invalid_iterator.210 if @a first and @a last do not belong to the + same JSON value; example: `"iterators do not fit"` + @throw invalid_iterator.211 if @a first or @a last are iterators into + container for which insert is called; example: `"passed iterators may not + belong to container"` + + @return iterator pointing to the first element inserted, or @a pos if + `first==last` + + @complexity Linear in `std::distance(first, last)` plus linear in the + distance between @a pos and end of the container. + + @liveexample{The example shows how `insert()` is used.,insert__range} + + @since version 1.0.0 + */ + iterator insert(const_iterator pos, const_iterator first, const_iterator last) + { + // insert only works for arrays + if (JSON_UNLIKELY(not is_array())) + { + JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()))); + } + + // check if iterator pos fits to this JSON value + if (JSON_UNLIKELY(pos.m_object != this)) + { + JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); + } + + // check if range iterators belong to the same JSON object + if (JSON_UNLIKELY(first.m_object != last.m_object)) + { + JSON_THROW(invalid_iterator::create(210, "iterators do not fit")); + } + + if (JSON_UNLIKELY(first.m_object == this)) + { + JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container")); + } + + // insert to array and return iterator + iterator result(this); + result.m_it.array_iterator = m_value.array->insert( + pos.m_it.array_iterator, + first.m_it.array_iterator, + last.m_it.array_iterator); + return result; + } + + /*! + @brief inserts elements + + Inserts elements from initializer list @a ilist before iterator @a pos. + + @param[in] pos iterator before which the content will be inserted; may be + the end() iterator + @param[in] ilist initializer list to insert the values from + + @throw type_error.309 if called on JSON values other than arrays; example: + `"cannot use insert() with string"` + @throw invalid_iterator.202 if @a pos is not an iterator of *this; + example: `"iterator does not fit current value"` + + @return iterator pointing to the first element inserted, or @a pos if + `ilist` is empty + + @complexity Linear in `ilist.size()` plus linear in the distance between + @a pos and end of the container. + + @liveexample{The example shows how `insert()` is used.,insert__ilist} + + @since version 1.0.0 + */ + iterator insert(const_iterator pos, initializer_list_t ilist) + { + // insert only works for arrays + if (JSON_UNLIKELY(not is_array())) + { + JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()))); + } + + // check if iterator pos fits to this JSON value + if (JSON_UNLIKELY(pos.m_object != this)) + { + JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); + } + + // insert to array and return iterator + iterator result(this); + result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist.begin(), ilist.end()); + return result; + } + + /*! + @brief inserts elements + + Inserts elements from range `[first, last)`. + + @param[in] first begin of the range of elements to insert + @param[in] last end of the range of elements to insert + + @throw type_error.309 if called on JSON values other than objects; example: + `"cannot use insert() with string"` + @throw invalid_iterator.202 if iterator @a first or @a last does does not + point to an object; example: `"iterators first and last must point to + objects"` + @throw invalid_iterator.210 if @a first and @a last do not belong to the + same JSON value; example: `"iterators do not fit"` + + @complexity Logarithmic: `O(N*log(size() + N))`, where `N` is the number + of elements to insert. + + @liveexample{The example shows how `insert()` is used.,insert__range_object} + + @since version 3.0.0 + */ + void insert(const_iterator first, const_iterator last) + { + // insert only works for objects + if (JSON_UNLIKELY(not is_object())) + { + JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()))); + } + + // check if range iterators belong to the same JSON object + if (JSON_UNLIKELY(first.m_object != last.m_object)) + { + JSON_THROW(invalid_iterator::create(210, "iterators do not fit")); + } + + // passed iterators must belong to objects + if (JSON_UNLIKELY(not first.m_object->is_object())) + { + JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects")); + } + + m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator); + } + + /*! + @brief updates a JSON object from another object, overwriting existing keys - } + Inserts all values from JSON object @a j and overwrites existing keys. + + @param[in] j JSON object to read values from + + @throw type_error.312 if called on JSON values other than objects; example: + `"cannot use update() with string"` + + @complexity O(N*log(size() + N)), where N is the number of elements to + insert. + + @liveexample{The example shows how `update()` is used.,update} + + @sa https://docs.python.org/3.6/library/stdtypes.html#dict.update + + @since version 3.0.0 + */ + void update(const_reference j) + { + // implicitly convert null value to an empty object + if (is_null()) + { + m_type = value_t::object; + m_value.object = create(); + assert_invariant(); + } + + if (JSON_UNLIKELY(not is_object())) + { + JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()))); + } + if (JSON_UNLIKELY(not j.is_object())) + { + JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()))); + } - position += static_cast((m_cursor - m_start)); - return last_token_type; + for (auto it = j.begin(); it != j.end(); ++it) + { + m_value.object->operator[](it.key()) = it.value(); } + } + + /*! + @brief updates a JSON object from another object, overwriting existing keys + + Inserts all values from from range `[first, last)` and overwrites existing + keys. - /*! - @brief append data from the stream to the line buffer + @param[in] first begin of the range of elements to insert + @param[in] last end of the range of elements to insert - This function is called by the scan() function when the end of the - buffer (`m_limit`) is reached and the `m_cursor` pointer cannot be - incremented without leaving the limits of the line buffer. Note re2c - decides when to call this function. + @throw type_error.312 if called on JSON values other than objects; example: + `"cannot use update() with string"` + @throw invalid_iterator.202 if iterator @a first or @a last does does not + point to an object; example: `"iterators first and last must point to + objects"` + @throw invalid_iterator.210 if @a first and @a last do not belong to the + same JSON value; example: `"iterators do not fit"` - If the lexer reads from contiguous storage, there is no trailing null - byte. Therefore, this function must make sure to add these padding - null bytes. + @complexity O(N*log(size() + N)), where N is the number of elements to + insert. - If the lexer reads from an input stream, this function reads the next - line of the input. + @liveexample{The example shows how `update()` is used__range.,update} - @pre - p p p p p p u u u u u x . . . . . . - ^ ^ ^ ^ - m_content m_start | m_limit - m_cursor + @sa https://docs.python.org/3.6/library/stdtypes.html#dict.update - @post - u u u u u x x x x x x x . . . . . . - ^ ^ ^ - | m_cursor m_limit - m_start - m_content - */ - void fill_line_buffer(size_t n = 0) + @since version 3.0.0 + */ + void update(const_iterator first, const_iterator last) + { + // implicitly convert null value to an empty object + if (is_null()) { - // if line buffer is used, m_content points to its data - assert(m_line_buffer.empty() - or m_content == reinterpret_cast(m_line_buffer.data())); + m_type = value_t::object; + m_value.object = create(); + assert_invariant(); + } - // if line buffer is used, m_limit is set past the end of its data - assert(m_line_buffer.empty() - or m_limit == m_content + m_line_buffer.size()); + if (JSON_UNLIKELY(not is_object())) + { + JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()))); + } - // pointer relationships - assert(m_content <= m_start); - assert(m_start <= m_cursor); - assert(m_cursor <= m_limit); - assert(m_marker == nullptr or m_marker <= m_limit); + // check if range iterators belong to the same JSON object + if (JSON_UNLIKELY(first.m_object != last.m_object)) + { + JSON_THROW(invalid_iterator::create(210, "iterators do not fit")); + } - // number of processed characters (p) - const auto num_processed_chars = static_cast(m_start - m_content); - // offset for m_marker wrt. to m_start - const auto offset_marker = (m_marker == nullptr) ? 0 : m_marker - m_start; - // number of unprocessed characters (u) - const auto offset_cursor = m_cursor - m_start; + // passed iterators must belong to objects + if (JSON_UNLIKELY(not first.m_object->is_object() + or not first.m_object->is_object())) + { + JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects")); + } - // no stream is used or end of file is reached - if (m_stream == nullptr or m_stream->eof()) - { - // m_start may or may not be pointing into m_line_buffer at - // this point. We trust the standard library to do the right - // thing. See http://stackoverflow.com/q/28142011/266378 - m_line_buffer.assign(m_start, m_limit); + for (auto it = first; it != last; ++it) + { + m_value.object->operator[](it.key()) = it.value(); + } + } - // append n characters to make sure that there is sufficient - // space between m_cursor and m_limit - m_line_buffer.append(1, '\x00'); - if (n > 0) - { - m_line_buffer.append(n - 1, '\x01'); - } - } - else - { - // delete processed characters from line buffer - m_line_buffer.erase(0, num_processed_chars); - // read next line from input stream - m_line_buffer_tmp.clear(); + /*! + @brief exchanges the values - // check if stream is still good - if (m_stream->fail()) - { - JSON_THROW(parse_error::create(111, 0, "bad input stream")); - } + Exchanges the contents of the JSON value with those of @a other. Does not + invoke any move, copy, or swap operations on individual elements. All + iterators and references remain valid. The past-the-end iterator is + invalidated. - std::getline(*m_stream, m_line_buffer_tmp, '\n'); + @param[in,out] other JSON value to exchange the contents with - // add line with newline symbol to the line buffer - m_line_buffer += m_line_buffer_tmp; - m_line_buffer.push_back('\n'); - } + @complexity Constant. + + @liveexample{The example below shows how JSON values can be swapped with + `swap()`.,swap__reference} + + @since version 1.0.0 + */ + void swap(reference other) noexcept ( + std::is_nothrow_move_constructible::value and + std::is_nothrow_move_assignable::value and + std::is_nothrow_move_constructible::value and + std::is_nothrow_move_assignable::value + ) + { + std::swap(m_type, other.m_type); + std::swap(m_value, other.m_value); + assert_invariant(); + } + + /*! + @brief exchanges the values + + Exchanges the contents of a JSON array with those of @a other. Does not + invoke any move, copy, or swap operations on individual elements. All + iterators and references remain valid. The past-the-end iterator is + invalidated. + + @param[in,out] other array to exchange the contents with + + @throw type_error.310 when JSON value is not an array; example: `"cannot + use swap() with string"` + + @complexity Constant. + + @liveexample{The example below shows how arrays can be swapped with + `swap()`.,swap__array_t} + + @since version 1.0.0 + */ + void swap(array_t& other) + { + // swap only works for arrays + if (JSON_LIKELY(is_array())) + { + std::swap(*(m_value.array), other); + } + else + { + JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()))); + } + } + + /*! + @brief exchanges the values + + Exchanges the contents of a JSON object with those of @a other. Does not + invoke any move, copy, or swap operations on individual elements. All + iterators and references remain valid. The past-the-end iterator is + invalidated. + + @param[in,out] other object to exchange the contents with + + @throw type_error.310 when JSON value is not an object; example: + `"cannot use swap() with string"` + + @complexity Constant. + + @liveexample{The example below shows how objects can be swapped with + `swap()`.,swap__object_t} - // set pointers - m_content = reinterpret_cast(m_line_buffer.data()); - assert(m_content != nullptr); - m_start = m_content; - m_marker = m_start + offset_marker; - m_cursor = m_start + offset_cursor; - m_limit = m_start + m_line_buffer.size(); + @since version 1.0.0 + */ + void swap(object_t& other) + { + // swap only works for objects + if (JSON_LIKELY(is_object())) + { + std::swap(*(m_value.object), other); + } + else + { + JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()))); } + } + + /*! + @brief exchanges the values + + Exchanges the contents of a JSON string with those of @a other. Does not + invoke any move, copy, or swap operations on individual elements. All + iterators and references remain valid. The past-the-end iterator is + invalidated. + + @param[in,out] other string to exchange the contents with + + @throw type_error.310 when JSON value is not a string; example: `"cannot + use swap() with boolean"` + + @complexity Constant. - /// return string representation of last read token - string_t get_token_string() const + @liveexample{The example below shows how strings can be swapped with + `swap()`.,swap__string_t} + + @since version 1.0.0 + */ + void swap(string_t& other) + { + // swap only works for strings + if (JSON_LIKELY(is_string())) { - assert(m_start != nullptr); - return string_t(reinterpret_cast(m_start), - static_cast(m_cursor - m_start)); + std::swap(*(m_value.string), other); + } + else + { + JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()))); } + } + + /// @} + + public: + ////////////////////////////////////////// + // lexicographical comparison operators // + ////////////////////////////////////////// + + /// @name lexicographical comparison operators + /// @{ + + /*! + @brief comparison: equal + + Compares two JSON values for equality according to the following rules: + - Two JSON values are equal if (1) they are from the same type and (2) + their stored values are the same according to their respective + `operator==`. + - Integer and floating-point numbers are automatically converted before + comparison. Note than two NaN values are always treated as unequal. + - Two JSON null values are equal. + + @note Floating-point inside JSON values numbers are compared with + `json::number_float_t::operator==` which is `double::operator==` by + default. To compare floating-point while respecting an epsilon, an alternative + [comparison function](https://github.com/mariokonrad/marnav/blob/master/src/marnav/math/floatingpoint.hpp#L34-#L39) + could be used, for instance + @code {.cpp} + template::value, T>::type> + inline bool is_same(T a, T b, T epsilon = std::numeric_limits::epsilon()) noexcept + { + return std::abs(a - b) <= epsilon; + } + @endcode + + @note NaN values never compare equal to themselves or to other NaN values. + + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether the values @a lhs and @a rhs are equal + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @complexity Linear. + + @liveexample{The example demonstrates comparing several JSON + types.,operator__equal} + + @since version 1.0.0 + */ + friend bool operator==(const_reference lhs, const_reference rhs) noexcept + { + const auto lhs_type = lhs.type(); + const auto rhs_type = rhs.type(); + + if (lhs_type == rhs_type) + { + switch (lhs_type) + { + case value_t::array: + return (*lhs.m_value.array == *rhs.m_value.array); + + case value_t::object: + return (*lhs.m_value.object == *rhs.m_value.object); + + case value_t::null: + return true; + + case value_t::string: + return (*lhs.m_value.string == *rhs.m_value.string); + + case value_t::boolean: + return (lhs.m_value.boolean == rhs.m_value.boolean); - /*! - @brief return string value for string tokens + case value_t::number_integer: + return (lhs.m_value.number_integer == rhs.m_value.number_integer); + + case value_t::number_unsigned: + return (lhs.m_value.number_unsigned == rhs.m_value.number_unsigned); - The function iterates the characters between the opening and closing - quotes of the string value. The complete string is the range - [m_start,m_cursor). Consequently, we iterate from m_start+1 to - m_cursor-1. + case value_t::number_float: + return (lhs.m_value.number_float == rhs.m_value.number_float); - We differentiate two cases: + default: + return false; + } + } + else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float) + { + return (static_cast(lhs.m_value.number_integer) == rhs.m_value.number_float); + } + else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer) + { + return (lhs.m_value.number_float == static_cast(rhs.m_value.number_integer)); + } + else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float) + { + return (static_cast(lhs.m_value.number_unsigned) == rhs.m_value.number_float); + } + else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned) + { + return (lhs.m_value.number_float == static_cast(rhs.m_value.number_unsigned)); + } + else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer) + { + return (static_cast(lhs.m_value.number_unsigned) == rhs.m_value.number_integer); + } + else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned) + { + return (lhs.m_value.number_integer == static_cast(rhs.m_value.number_unsigned)); + } - 1. Escaped characters. In this case, a new character is constructed - according to the nature of the escape. Some escapes create new - characters (e.g., `"\\n"` is replaced by `"\n"`), some are copied - as is (e.g., `"\\\\"`). Furthermore, Unicode escapes of the shape - `"\\uxxxx"` need special care. In this case, to_unicode takes care - of the construction of the values. - 2. Unescaped characters are copied as is. + return false; + } - @pre `m_cursor - m_start >= 2`, meaning the length of the last token - is at least 2 bytes which is trivially true for any string (which - consists of at least two quotes). + /*! + @brief comparison: equal + @copydoc operator==(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator==(const_reference lhs, const ScalarType rhs) noexcept + { + return (lhs == basic_json(rhs)); + } - " c1 c2 c3 ... " - ^ ^ - m_start m_cursor + /*! + @brief comparison: equal + @copydoc operator==(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator==(const ScalarType lhs, const_reference rhs) noexcept + { + return (basic_json(lhs) == rhs); + } - @complexity Linear in the length of the string.\n + /*! + @brief comparison: not equal - Lemma: The loop body will always terminate.\n + Compares two JSON values for inequality by calculating `not (lhs == rhs)`. - Proof (by contradiction): Assume the loop body does not terminate. As - the loop body does not contain another loop, one of the called - functions must never return. The called functions are `std::strtoul` - and to_unicode. Neither function can loop forever, so the loop body - will never loop forever which contradicts the assumption that the loop - body does not terminate, q.e.d.\n + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether the values @a lhs and @a rhs are not equal - Lemma: The loop condition for the for loop is eventually false.\n + @complexity Linear. - Proof (by contradiction): Assume the loop does not terminate. Due to - the above lemma, this can only be due to a tautological loop - condition; that is, the loop condition i < m_cursor - 1 must always be - true. Let x be the change of i for any loop iteration. Then - m_start + 1 + x < m_cursor - 1 must hold to loop indefinitely. This - can be rephrased to m_cursor - m_start - 2 > x. With the - precondition, we x <= 0, meaning that the loop condition holds - indefinitely if i is always decreased. However, observe that the value - of i is strictly increasing with each iteration, as it is incremented - by 1 in the iteration expression and never decremented inside the loop - body. Hence, the loop condition will eventually be false which - contradicts the assumption that the loop condition is a tautology, - q.e.d. + @exceptionsafety No-throw guarantee: this function never throws exceptions. - @return string value of current token without opening and closing - quotes - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails - */ - string_t get_string() const - { - assert(m_cursor - m_start >= 2); + @liveexample{The example demonstrates comparing several JSON + types.,operator__notequal} - string_t result; - result.reserve(static_cast(m_cursor - m_start - 2)); + @since version 1.0.0 + */ + friend bool operator!=(const_reference lhs, const_reference rhs) noexcept + { + return not (lhs == rhs); + } - // iterate the result between the quotes - for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i) - { - // find next escape character - auto e = std::find(i, m_cursor - 1, '\\'); - if (e != i) - { - // see https://github.com/nlohmann/json/issues/365#issuecomment-262874705 - for (auto k = i; k < e; k++) - { - result.push_back(static_cast(*k)); - } - i = e - 1; // -1 because of ++i - } - else - { - // processing escaped character - // read next character - ++i; + /*! + @brief comparison: not equal + @copydoc operator!=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator!=(const_reference lhs, const ScalarType rhs) noexcept + { + return (lhs != basic_json(rhs)); + } - switch (*i) - { - // the default escapes - case 't': - { - result += "\t"; - break; - } - case 'b': - { - result += "\b"; - break; - } - case 'f': - { - result += "\f"; - break; - } - case 'n': - { - result += "\n"; - break; - } - case 'r': - { - result += "\r"; - break; - } - case '\\': - { - result += "\\"; - break; - } - case '/': - { - result += "/"; - break; - } - case '"': - { - result += "\""; - break; - } + /*! + @brief comparison: not equal + @copydoc operator!=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator!=(const ScalarType lhs, const_reference rhs) noexcept + { + return (basic_json(lhs) != rhs); + } - // unicode - case 'u': - { - // get code xxxx from uxxxx - auto codepoint = std::strtoul(std::string(reinterpret_cast(i + 1), - 4).c_str(), nullptr, 16); + /*! + @brief comparison: less than - // check if codepoint is a high surrogate - if (codepoint >= 0xD800 and codepoint <= 0xDBFF) - { - // make sure there is a subsequent unicode - if ((i + 6 >= m_limit) or * (i + 5) != '\\' or * (i + 6) != 'u') - { - JSON_THROW(parse_error::create(102, get_position(), "missing low surrogate")); - } + Compares whether one JSON value @a lhs is less than another JSON value @a + rhs according to the following rules: + - If @a lhs and @a rhs have the same type, the values are compared using + the default `<` operator. + - Integer and floating-point numbers are automatically converted before + comparison + - In case @a lhs and @a rhs have different types, the values are ignored + and the order of the types is considered, see + @ref operator<(const value_t, const value_t). - // get code yyyy from uxxxx\uyyyy - auto codepoint2 = std::strtoul(std::string(reinterpret_cast - (i + 7), 4).c_str(), nullptr, 16); - result += to_unicode(codepoint, codepoint2); - // skip the next 10 characters (xxxx\uyyyy) - i += 10; - } - else if (codepoint >= 0xDC00 and codepoint <= 0xDFFF) - { - // we found a lone low surrogate - JSON_THROW(parse_error::create(102, get_position(), "missing high surrogate")); - } - else - { - // add unicode character(s) - result += to_unicode(codepoint); - // skip the next four characters (xxxx) - i += 4; - } - break; - } - } - } - } + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether @a lhs is less than @a rhs - return result; - } + @complexity Linear. + @exceptionsafety No-throw guarantee: this function never throws exceptions. - /*! - @brief parse string into a built-in arithmetic type as if the current - locale is POSIX. + @liveexample{The example demonstrates comparing several JSON + types.,operator__less} - @note in floating-point case strtod may parse past the token's end - - this is not an error + @since version 1.0.0 + */ + friend bool operator<(const_reference lhs, const_reference rhs) noexcept + { + const auto lhs_type = lhs.type(); + const auto rhs_type = rhs.type(); - @note any leading blanks are not handled - */ - struct strtonum + if (lhs_type == rhs_type) { - public: - strtonum(const char* start, const char* end) - : m_start(start), m_end(end) - {} - - /*! - @return true iff parsed successfully as number of type T - - @param[in,out] val shall contain parsed value, or undefined value - if could not parse - */ - template::value>::type> - bool to(T& val) const + switch (lhs_type) { - return parse(val, std::is_integral()); - } - - private: - const char* const m_start = nullptr; - const char* const m_end = nullptr; - - // floating-point conversion + case value_t::array: + return (*lhs.m_value.array) < (*rhs.m_value.array); - // overloaded wrappers for strtod/strtof/strtold - // that will be called from parse - static void strtof(float& f, const char* str, char** endptr) - { - f = std::strtof(str, endptr); - } + case value_t::object: + return *lhs.m_value.object < *rhs.m_value.object; - static void strtof(double& f, const char* str, char** endptr) - { - f = std::strtod(str, endptr); - } + case value_t::null: + return false; - static void strtof(long double& f, const char* str, char** endptr) - { - f = std::strtold(str, endptr); - } + case value_t::string: + return *lhs.m_value.string < *rhs.m_value.string; - template - bool parse(T& value, /*is_integral=*/std::false_type) const - { - // replace decimal separator with locale-specific version, - // when necessary; data will point to either the original - // string, or buf, or tempstr containing the fixed string. - std::string tempstr; - std::array buf; - const size_t len = static_cast(m_end - m_start); + case value_t::boolean: + return lhs.m_value.boolean < rhs.m_value.boolean; - // lexer will reject empty numbers - assert(len > 0); + case value_t::number_integer: + return lhs.m_value.number_integer < rhs.m_value.number_integer; - // since dealing with strtod family of functions, we're - // getting the decimal point char from the C locale facilities - // instead of C++'s numpunct facet of the current std::locale - const auto loc = localeconv(); - assert(loc != nullptr); - const char decimal_point_char = (loc->decimal_point == nullptr) ? '.' : loc->decimal_point[0]; + case value_t::number_unsigned: + return lhs.m_value.number_unsigned < rhs.m_value.number_unsigned; - const char* data = m_start; + case value_t::number_float: + return lhs.m_value.number_float < rhs.m_value.number_float; - if (decimal_point_char != '.') - { - const size_t ds_pos = static_cast(std::find(m_start, m_end, '.') - m_start); + default: + return false; + } + } + else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float) + { + return static_cast(lhs.m_value.number_integer) < rhs.m_value.number_float; + } + else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer) + { + return lhs.m_value.number_float < static_cast(rhs.m_value.number_integer); + } + else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float) + { + return static_cast(lhs.m_value.number_unsigned) < rhs.m_value.number_float; + } + else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned) + { + return lhs.m_value.number_float < static_cast(rhs.m_value.number_unsigned); + } + else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned) + { + return lhs.m_value.number_integer < static_cast(rhs.m_value.number_unsigned); + } + else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer) + { + return static_cast(lhs.m_value.number_unsigned) < rhs.m_value.number_integer; + } - if (ds_pos != len) - { - // copy the data into the local buffer or tempstr, if - // buffer is too small; replace decimal separator, and - // update data to point to the modified bytes - if ((len + 1) < buf.size()) - { - std::copy(m_start, m_end, buf.begin()); - buf[len] = 0; - buf[ds_pos] = decimal_point_char; - data = buf.data(); - } - else - { - tempstr.assign(m_start, m_end); - tempstr[ds_pos] = decimal_point_char; - data = tempstr.c_str(); - } - } - } + // We only reach this line if we cannot compare values. In that case, + // we compare types. Note we have to call the operator explicitly, + // because MSVC has problems otherwise. + return operator<(lhs_type, rhs_type); + } - char* endptr = nullptr; - value = 0; - // this calls appropriate overload depending on T - strtof(value, data, &endptr); + /*! + @brief comparison: less than + @copydoc operator<(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator<(const_reference lhs, const ScalarType rhs) noexcept + { + return (lhs < basic_json(rhs)); + } - // parsing was successful iff strtof parsed exactly the number - // of characters determined by the lexer (len) - const bool ok = (endptr == (data + len)); + /*! + @brief comparison: less than + @copydoc operator<(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator<(const ScalarType lhs, const_reference rhs) noexcept + { + return (basic_json(lhs) < rhs); + } - if (ok and (value == static_cast(0.0)) and (*data == '-')) - { - // some implementations forget to negate the zero - value = -0.0; - } + /*! + @brief comparison: less than or equal - return ok; - } + Compares whether one JSON value @a lhs is less than or equal to another + JSON value by calculating `not (rhs < lhs)`. - // integral conversion + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether @a lhs is less than or equal to @a rhs - signed long long parse_integral(char** endptr, /*is_signed*/std::true_type) const - { - return std::strtoll(m_start, endptr, 10); - } + @complexity Linear. - unsigned long long parse_integral(char** endptr, /*is_signed*/std::false_type) const - { - return std::strtoull(m_start, endptr, 10); - } + @exceptionsafety No-throw guarantee: this function never throws exceptions. - template - bool parse(T& value, /*is_integral=*/std::true_type) const - { - char* endptr = nullptr; - errno = 0; // these are thread-local - const auto x = parse_integral(&endptr, std::is_signed()); + @liveexample{The example demonstrates comparing several JSON + types.,operator__greater} - // called right overload? - static_assert(std::is_signed() == std::is_signed(), ""); + @since version 1.0.0 + */ + friend bool operator<=(const_reference lhs, const_reference rhs) noexcept + { + return not (rhs < lhs); + } - value = static_cast(x); + /*! + @brief comparison: less than or equal + @copydoc operator<=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator<=(const_reference lhs, const ScalarType rhs) noexcept + { + return (lhs <= basic_json(rhs)); + } - return (x == static_cast(value)) // x fits into destination T - and (x < 0) == (value < 0) // preserved sign - //and ((x != 0) or is_integral()) // strto[u]ll did nto fail - and (errno == 0) // strto[u]ll did not overflow - and (m_start < m_end) // token was not empty - and (endptr == m_end); // parsed entire token exactly - } - }; + /*! + @brief comparison: less than or equal + @copydoc operator<=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator<=(const ScalarType lhs, const_reference rhs) noexcept + { + return (basic_json(lhs) <= rhs); + } - /*! - @brief return number value for number tokens + /*! + @brief comparison: greater than - This function translates the last token into the most appropriate - number type (either integer, unsigned integer or floating point), - which is passed back to the caller via the result parameter. + Compares whether one JSON value @a lhs is greater than another + JSON value by calculating `not (lhs <= rhs)`. - integral numbers that don't fit into the the range of the respective - type are parsed as number_float_t + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether @a lhs is greater than to @a rhs - floating-point values do not satisfy std::isfinite predicate - are converted to value_t::null + @complexity Linear. - throws if the entire string [m_start .. m_cursor) cannot be - interpreted as a number + @exceptionsafety No-throw guarantee: this function never throws exceptions. - @param[out] result @ref basic_json object to receive the number. - @param[in] token the type of the number token - */ - bool get_number(basic_json& result, const token_type token) const - { - assert(m_start != nullptr); - assert(m_start < m_cursor); - assert((token == token_type::value_unsigned) or - (token == token_type::value_integer) or - (token == token_type::value_float)); + @liveexample{The example demonstrates comparing several JSON + types.,operator__lessequal} - strtonum num_converter(reinterpret_cast(m_start), - reinterpret_cast(m_cursor)); + @since version 1.0.0 + */ + friend bool operator>(const_reference lhs, const_reference rhs) noexcept + { + return not (lhs <= rhs); + } - switch (token) - { - case lexer::token_type::value_unsigned: - { - number_unsigned_t val; - if (num_converter.to(val)) - { - // parsing successful - result.m_type = value_t::number_unsigned; - result.m_value = val; - return true; - } - break; - } + /*! + @brief comparison: greater than + @copydoc operator>(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator>(const_reference lhs, const ScalarType rhs) noexcept + { + return (lhs > basic_json(rhs)); + } - case lexer::token_type::value_integer: - { - number_integer_t val; - if (num_converter.to(val)) - { - // parsing successful - result.m_type = value_t::number_integer; - result.m_value = val; - return true; - } - break; - } + /*! + @brief comparison: greater than + @copydoc operator>(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator>(const ScalarType lhs, const_reference rhs) noexcept + { + return (basic_json(lhs) > rhs); + } - default: - { - break; - } - } + /*! + @brief comparison: greater than or equal - // parse float (either explicitly or because a previous conversion - // failed) - number_float_t val; - if (num_converter.to(val)) - { - // parsing successful - result.m_type = value_t::number_float; - result.m_value = val; + Compares whether one JSON value @a lhs is greater than or equal to another + JSON value by calculating `not (lhs < rhs)`. - // throw in case of infinity or NAN - if (not std::isfinite(result.m_value.number_float)) - { - JSON_THROW(out_of_range::create(406, "number overflow parsing '" + get_token_string() + "'")); - } + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether @a lhs is greater than or equal to @a rhs - return true; - } + @complexity Linear. - // couldn't parse number in any format - return false; - } + @exceptionsafety No-throw guarantee: this function never throws exceptions. - constexpr size_t get_position() const - { - return position; - } + @liveexample{The example demonstrates comparing several JSON + types.,operator__greaterequal} - private: - /// optional input stream - std::istream* m_stream = nullptr; - /// line buffer buffer for m_stream - string_t m_line_buffer {}; - /// used for filling m_line_buffer - string_t m_line_buffer_tmp {}; - /// the buffer pointer - const lexer_char_t* m_content = nullptr; - /// pointer to the beginning of the current symbol - const lexer_char_t* m_start = nullptr; - /// pointer for backtracking information - const lexer_char_t* m_marker = nullptr; - /// pointer to the current symbol - const lexer_char_t* m_cursor = nullptr; - /// pointer to the end of the buffer - const lexer_char_t* m_limit = nullptr; - /// the last token type - token_type last_token_type = token_type::end_of_input; - /// current position in the input (read bytes) - size_t position = 0; - }; + @since version 1.0.0 + */ + friend bool operator>=(const_reference lhs, const_reference rhs) noexcept + { + return not (lhs < rhs); + } /*! - @brief syntax analysis - - This class implements a recursive decent parser. + @brief comparison: greater than or equal + @copydoc operator>=(const_reference, const_reference) */ - class parser + template::value, int>::type = 0> + friend bool operator>=(const_reference lhs, const ScalarType rhs) noexcept { - public: - /// a parser reading from a string literal - parser(const char* buff, const parser_callback_t cb = nullptr) - : callback(cb), - m_lexer(reinterpret_cast(buff), std::strlen(buff)) - {} - - /*! - @brief a parser reading from an input stream - @throw parse_error.111 if input stream is in a bad state - */ - parser(std::istream& is, const parser_callback_t cb = nullptr) - : callback(cb), m_lexer(is) - {} - - /// a parser reading from an iterator range with contiguous storage - template::iterator_category, std::random_access_iterator_tag>::value - , int>::type - = 0> - parser(IteratorType first, IteratorType last, const parser_callback_t cb = nullptr) - : callback(cb), - m_lexer(reinterpret_cast(&(*first)), - static_cast(std::distance(first, last))) - {} - - /*! - @brief public parser interface - @throw parse_error.101 in case of an unexpected token - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails - */ - basic_json parse() - { - // read first token - get_token(); - - basic_json result = parse_internal(true); - result.assert_invariant(); + return (lhs >= basic_json(rhs)); + } - expect(lexer::token_type::end_of_input); + /*! + @brief comparison: greater than or equal + @copydoc operator>=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator>=(const ScalarType lhs, const_reference rhs) noexcept + { + return (basic_json(lhs) >= rhs); + } - // return parser result and replace it with null in case the - // top-level value was discarded by the callback function - return result.is_discarded() ? basic_json() : std::move(result); - } + /// @} - private: - /*! - @brief the actual parser - @throw parse_error.101 in case of an unexpected token - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails - */ - basic_json parse_internal(bool keep) - { - auto result = basic_json(value_t::discarded); + /////////////////// + // serialization // + /////////////////// - switch (last_token) - { - case lexer::token_type::begin_object: - { - if (keep and (not callback - or ((keep = callback(depth++, parse_event_t::object_start, result)) != 0))) - { - // explicitly set result to object to cope with {} - result.m_type = value_t::object; - result.m_value = value_t::object; - } + /// @name serialization + /// @{ - // read next token - get_token(); + /*! + @brief serialize to stream - // closing } -> we are done - if (last_token == lexer::token_type::end_object) - { - get_token(); - if (keep and callback and not callback(--depth, parse_event_t::object_end, result)) - { - result = basic_json(value_t::discarded); - } - return result; - } + Serialize the given JSON value @a j to the output stream @a o. The JSON + value will be serialized using the @ref dump member function. - // no comma is expected here - unexpect(lexer::token_type::value_separator); + - The indentation of the output can be controlled with the member variable + `width` of the output stream @a o. For instance, using the manipulator + `std::setw(4)` on @a o sets the indentation level to `4` and the + serialization result is the same as calling `dump(4)`. - // otherwise: parse key-value pairs - do - { - // ugly, but could be fixed with loop reorganization - if (last_token == lexer::token_type::value_separator) - { - get_token(); - } + - The indentation character can be controlled with the member variable + `fill` of the output stream @a o. For instance, the manipulator + `std::setfill('\\t')` sets indentation to use a tab character rather than + the default space character. - // store key - expect(lexer::token_type::value_string); - const auto key = m_lexer.get_string(); + @param[in,out] o stream to serialize to + @param[in] j JSON value to serialize - bool keep_tag = false; - if (keep) - { - if (callback) - { - basic_json k(key); - keep_tag = callback(depth, parse_event_t::key, k); - } - else - { - keep_tag = true; - } - } + @return the stream @a o - // parse separator (:) - get_token(); - expect(lexer::token_type::name_separator); + @throw type_error.316 if a string stored inside the JSON value is not + UTF-8 encoded - // parse and add value - get_token(); - auto value = parse_internal(keep); - if (keep and keep_tag and not value.is_discarded()) - { - result[key] = std::move(value); - } - } - while (last_token == lexer::token_type::value_separator); + @complexity Linear. - // closing } - expect(lexer::token_type::end_object); - get_token(); - if (keep and callback and not callback(--depth, parse_event_t::object_end, result)) - { - result = basic_json(value_t::discarded); - } + @liveexample{The example below shows the serialization with different + parameters to `width` to adjust the indentation level.,operator_serialize} - return result; - } + @since version 1.0.0; indentation character added in version 3.0.0 + */ + friend std::ostream& operator<<(std::ostream& o, const basic_json& j) + { + // read width member and use it as indentation parameter if nonzero + const bool pretty_print = (o.width() > 0); + const auto indentation = (pretty_print ? o.width() : 0); - case lexer::token_type::begin_array: - { - if (keep and (not callback - or ((keep = callback(depth++, parse_event_t::array_start, result)) != 0))) - { - // explicitly set result to object to cope with [] - result.m_type = value_t::array; - result.m_value = value_t::array; - } + // reset width to 0 for subsequent calls to this stream + o.width(0); - // read next token - get_token(); + // do the actual serialization + serializer s(detail::output_adapter(o), o.fill()); + s.dump(j, pretty_print, false, static_cast(indentation)); + return o; + } - // closing ] -> we are done - if (last_token == lexer::token_type::end_array) - { - get_token(); - if (callback and not callback(--depth, parse_event_t::array_end, result)) - { - result = basic_json(value_t::discarded); - } - return result; - } + /*! + @brief serialize to stream + @deprecated This stream operator is deprecated and will be removed in a + future version of the library. Please use + @ref operator<<(std::ostream&, const basic_json&) + instead; that is, replace calls like `j >> o;` with `o << j;`. + @since version 1.0.0; deprecated since version 3.0.0 + */ + JSON_DEPRECATED + friend std::ostream& operator>>(const basic_json& j, std::ostream& o) + { + return o << j; + } - // no comma is expected here - unexpect(lexer::token_type::value_separator); + /// @} - // otherwise: parse values - do - { - // ugly, but could be fixed with loop reorganization - if (last_token == lexer::token_type::value_separator) - { - get_token(); - } - // parse value - auto value = parse_internal(keep); - if (keep and not value.is_discarded()) - { - result.push_back(std::move(value)); - } - } - while (last_token == lexer::token_type::value_separator); + ///////////////////// + // deserialization // + ///////////////////// - // closing ] - expect(lexer::token_type::end_array); - get_token(); - if (keep and callback and not callback(--depth, parse_event_t::array_end, result)) - { - result = basic_json(value_t::discarded); - } + /// @name deserialization + /// @{ - return result; - } + /*! + @brief deserialize from a compatible input - case lexer::token_type::literal_null: - { - get_token(); - result.m_type = value_t::null; - break; - } + This function reads from a compatible input. Examples are: + - an array of 1-byte values + - strings with character/literal type with size of 1 byte + - input streams + - container with contiguous storage of 1-byte values. Compatible container + types include `std::vector`, `std::string`, `std::array`, + `std::valarray`, and `std::initializer_list`. Furthermore, C-style + arrays can be used with `std::begin()`/`std::end()`. User-defined + containers can be used as long as they implement random-access iterators + and a contiguous storage. - case lexer::token_type::value_string: - { - const auto s = m_lexer.get_string(); - get_token(); - result = basic_json(s); - break; - } + @pre Each element of the container has a size of 1 byte. Violating this + precondition yields undefined behavior. **This precondition is enforced + with a static assertion.** - case lexer::token_type::literal_true: - { - get_token(); - result.m_type = value_t::boolean; - result.m_value = true; - break; - } + @pre The container storage is contiguous. Violating this precondition + yields undefined behavior. **This precondition is enforced with an + assertion.** + @pre Each element of the container has a size of 1 byte. Violating this + precondition yields undefined behavior. **This precondition is enforced + with a static assertion.** - case lexer::token_type::literal_false: - { - get_token(); - result.m_type = value_t::boolean; - result.m_value = false; - break; - } + @warning There is no way to enforce all preconditions at compile-time. If + the function is called with a noncompliant container and with + assertions switched off, the behavior is undefined and will most + likely yield segmentation violation. - case lexer::token_type::value_unsigned: - case lexer::token_type::value_integer: - case lexer::token_type::value_float: - { - m_lexer.get_number(result, last_token); - get_token(); - break; - } + @param[in] i input to read from + @param[in] cb a parser callback function of type @ref parser_callback_t + which is used to control the deserialization by filtering unwanted values + (optional) - default: - { - // the last token was unexpected - unexpect(last_token); - } - } + @return result of the deserialization - if (keep and callback and not callback(depth, parse_event_t::value, result)) - { - result = basic_json(value_t::discarded); - } - return result; - } + @throw parse_error.101 if a parse error occurs; example: `""unexpected end + of input; expected string literal""` + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails - /// get next token from lexer - typename lexer::token_type get_token() - { - last_token = m_lexer.scan(); - return last_token; - } + @complexity Linear in the length of the input. The parser is a predictive + LL(1) parser. The complexity can be higher if the parser callback function + @a cb has a super-linear complexity. - /*! - @throw parse_error.101 if expected token did not occur - */ - void expect(typename lexer::token_type t) const - { - if (t != last_token) - { - std::string error_msg = "parse error - unexpected "; - error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token_string() + - "'") : - lexer::token_type_name(last_token)); - error_msg += "; expected " + lexer::token_type_name(t); - JSON_THROW(parse_error::create(101, m_lexer.get_position(), error_msg)); - } - } + @note A UTF-8 byte order mark is silently ignored. - /*! - @throw parse_error.101 if unexpected token occurred - */ - void unexpect(typename lexer::token_type t) const - { - if (t == last_token) - { - std::string error_msg = "parse error - unexpected "; - error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token_string() + - "'") : - lexer::token_type_name(last_token)); - JSON_THROW(parse_error::create(101, m_lexer.get_position(), error_msg)); - } - } + @liveexample{The example below demonstrates the `parse()` function reading + from an array.,parse__array__parser_callback_t} - private: - /// current level of recursion - int depth = 0; - /// callback function - const parser_callback_t callback = nullptr; - /// the type of the last read token - typename lexer::token_type last_token = lexer::token_type::uninitialized; - /// the lexer - lexer m_lexer; - }; + @liveexample{The example below demonstrates the `parse()` function with + and without callback function.,parse__string__parser_callback_t} - public: - /*! - @brief JSON Pointer + @liveexample{The example below demonstrates the `parse()` function with + and without callback function.,parse__istream__parser_callback_t} - A JSON pointer defines a string syntax for identifying a specific value - within a JSON document. It can be used with functions `at` and - `operator[]`. Furthermore, JSON pointers are the base for JSON patches. + @liveexample{The example below demonstrates the `parse()` function reading + from a contiguous container.,parse__contiguouscontainer__parser_callback_t} - @sa [RFC 6901](https://tools.ietf.org/html/rfc6901) + @since version 2.0.3 (contiguous containers) + */ + static basic_json parse(detail::input_adapter i, + const parser_callback_t cb = nullptr, + const bool allow_exceptions = true) + { + basic_json result; + parser(i, cb, allow_exceptions).parse(true, result); + return result; + } - @since version 2.0.0 + /*! + @copydoc basic_json parse(detail::input_adapter, const parser_callback_t) */ - class json_pointer + static basic_json parse(detail::input_adapter& i, + const parser_callback_t cb = nullptr, + const bool allow_exceptions = true) { - /// allow basic_json to access private members - friend class basic_json; + basic_json result; + parser(i, cb, allow_exceptions).parse(true, result); + return result; + } - public: - /*! - @brief create JSON pointer + static bool accept(detail::input_adapter i) + { + return parser(i).accept(true); + } - Create a JSON pointer according to the syntax described in - [Section 3 of RFC6901](https://tools.ietf.org/html/rfc6901#section-3). + static bool accept(detail::input_adapter& i) + { + return parser(i).accept(true); + } - @param[in] s string representing the JSON pointer; if omitted, the - empty string is assumed which references the whole JSON - value + /*! + @brief deserialize from an iterator range with contiguous storage - @throw parse_error.107 if the given JSON pointer @a s is nonempty and - does not begin with a slash (`/`); see example below + This function reads from an iterator range of a container with contiguous + storage of 1-byte values. Compatible container types include + `std::vector`, `std::string`, `std::array`, `std::valarray`, and + `std::initializer_list`. Furthermore, C-style arrays can be used with + `std::begin()`/`std::end()`. User-defined containers can be used as long + as they implement random-access iterators and a contiguous storage. - @throw parse_error.108 if a tilde (`~`) in the given JSON pointer @a s - is not followed by `0` (representing `~`) or `1` (representing `/`); - see example below + @pre The iterator range is contiguous. Violating this precondition yields + undefined behavior. **This precondition is enforced with an assertion.** + @pre Each element in the range has a size of 1 byte. Violating this + precondition yields undefined behavior. **This precondition is enforced + with a static assertion.** - @liveexample{The example shows the construction several valid JSON - pointers as well as the exceptional behavior.,json_pointer} + @warning There is no way to enforce all preconditions at compile-time. If + the function is called with noncompliant iterators and with + assertions switched off, the behavior is undefined and will most + likely yield segmentation violation. - @since version 2.0.0 - */ - explicit json_pointer(const std::string& s = "") - : reference_tokens(split(s)) - {} + @tparam IteratorType iterator of container with contiguous storage + @param[in] first begin of the range to parse (included) + @param[in] last end of the range to parse (excluded) + @param[in] cb a parser callback function of type @ref parser_callback_t + which is used to control the deserialization by filtering unwanted values + (optional) + @param[in] allow_exceptions whether to throw exceptions in case of a + parse error (optional, true by default) - /*! - @brief return a string representation of the JSON pointer + @return result of the deserialization - @invariant For each JSON pointer `ptr`, it holds: - @code {.cpp} - ptr == json_pointer(ptr.to_string()); - @endcode + @throw parse_error.101 in case of an unexpected token + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails - @return a string representation of the JSON pointer + @complexity Linear in the length of the input. The parser is a predictive + LL(1) parser. The complexity can be higher if the parser callback function + @a cb has a super-linear complexity. - @liveexample{The example shows the result of `to_string`., - json_pointer__to_string} + @note A UTF-8 byte order mark is silently ignored. - @since version 2.0.0 - */ - std::string to_string() const noexcept - { - return std::accumulate(reference_tokens.begin(), - reference_tokens.end(), std::string{}, - [](const std::string & a, const std::string & b) - { - return a + "/" + escape(b); - }); - } + @liveexample{The example below demonstrates the `parse()` function reading + from an iterator range.,parse__iteratortype__parser_callback_t} - /// @copydoc to_string() - operator std::string() const - { - return to_string(); - } + @since version 2.0.3 + */ + template::iterator_category>::value, int>::type = 0> + static basic_json parse(IteratorType first, IteratorType last, + const parser_callback_t cb = nullptr, + const bool allow_exceptions = true) + { + basic_json result; + parser(detail::input_adapter(first, last), cb, allow_exceptions).parse(true, result); + return result; + } - private: - /*! - @brief remove and return last reference pointer - @throw out_of_range.405 if JSON pointer has no parent - */ - std::string pop_back() - { - if (is_root()) - { - JSON_THROW(out_of_range::create(405, "JSON pointer has no parent")); - } + template::iterator_category>::value, int>::type = 0> + static bool accept(IteratorType first, IteratorType last) + { + return parser(detail::input_adapter(first, last)).accept(true); + } - auto last = reference_tokens.back(); - reference_tokens.pop_back(); - return last; - } + /*! + @brief deserialize from stream + @deprecated This stream operator is deprecated and will be removed in a + future version of the library. Please use + @ref operator>>(std::istream&, basic_json&) + instead; that is, replace calls like `j << i;` with `i >> j;`. + @since version 1.0.0; deprecated since version 3.0.0 + */ + JSON_DEPRECATED + friend std::istream& operator<<(basic_json& j, std::istream& i) + { + return operator>>(i, j); + } - /// return whether pointer points to the root document - bool is_root() const - { - return reference_tokens.empty(); - } + /*! + @brief deserialize from stream - json_pointer top() const - { - if (is_root()) - { - JSON_THROW(out_of_range::create(405, "JSON pointer has no parent")); - } + Deserializes an input stream to a JSON value. - json_pointer result = *this; - result.reference_tokens = {reference_tokens[0]}; - return result; - } + @param[in,out] i input stream to read a serialized JSON value from + @param[in,out] j JSON value to write the deserialized input to - /*! - @brief create and return a reference to the pointed to value + @throw parse_error.101 in case of an unexpected token + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails - @complexity Linear in the number of reference tokens. + @complexity Linear in the length of the input. The parser is a predictive + LL(1) parser. - @throw parse_error.109 if array index is not a number - @throw type_error.313 if value cannot be unflattened - */ - reference get_and_create(reference j) const - { - pointer result = &j; + @note A UTF-8 byte order mark is silently ignored. - // in case no reference tokens exist, return a reference to the - // JSON value j which will be overwritten by a primitive value - for (const auto& reference_token : reference_tokens) - { - switch (result->m_type) - { - case value_t::null: - { - if (reference_token == "0") - { - // start a new array if reference token is 0 - result = &result->operator[](0); - } - else - { - // start a new object otherwise - result = &result->operator[](reference_token); - } - break; - } + @liveexample{The example below shows how a JSON value is constructed by + reading a serialization from a stream.,operator_deserialize} - case value_t::object: - { - // create an entry in the object - result = &result->operator[](reference_token); - break; - } + @sa parse(std::istream&, const parser_callback_t) for a variant with a + parser callback function to filter values while parsing - case value_t::array: - { - // create an entry in the array - JSON_TRY - { - result = &result->operator[](static_cast(std::stoi(reference_token))); - } - JSON_CATCH (std::invalid_argument&) - { - JSON_THROW(parse_error::create(109, 0, "array index '" + reference_token + "' is not a number")); - } - break; - } + @since version 1.0.0 + */ + friend std::istream& operator>>(std::istream& i, basic_json& j) + { + parser(detail::input_adapter(i)).parse(false, j); + return i; + } - /* - The following code is only reached if there exists a - reference token _and_ the current value is primitive. In - this case, we have an error situation, because primitive - values may only occur as single value; that is, with an - empty list of reference tokens. - */ - default: - { - JSON_THROW(type_error::create(313, "invalid value to unflatten")); - } - } - } + /// @} - return *result; - } + /////////////////////////// + // convenience functions // + /////////////////////////// + + /*! + @brief return the type as string + + Returns the type name as string to be used in error messages - usually to + indicate that a function was called on a wrong JSON type. - /*! - @brief return a reference to the pointed to value + @return a string representation of a the @a m_type member: + Value type | return value + ----------- | ------------- + null | `"null"` + boolean | `"boolean"` + string | `"string"` + number | `"number"` (for all number types) + object | `"object"` + array | `"array"` + discarded | `"discarded"` - @note This version does not throw if a value is not present, but tries - to create nested values instead. For instance, calling this function - with pointer `"/this/that"` on a null value is equivalent to calling - `operator[]("this").operator[]("that")` on that value, effectively - changing the null value to an object. + @exceptionsafety No-throw guarantee: this function never throws exceptions. - @param[in] ptr a JSON value + @complexity Constant. - @return reference to the JSON value pointed to by the JSON pointer + @liveexample{The following code exemplifies `type_name()` for all JSON + types.,type_name} - @complexity Linear in the length of the JSON pointer. + @sa @ref type() -- return the type of the JSON value + @sa @ref operator value_t() -- return the type of the JSON value (implicit) - @throw parse_error.106 if an array index begins with '0' - @throw parse_error.109 if an array index was not a number - @throw out_of_range.404 if the JSON pointer can not be resolved - */ - reference get_unchecked(pointer ptr) const + @since version 1.0.0, public since 2.1.0, `const char*` and `noexcept` + since 3.0.0 + */ + const char* type_name() const noexcept + { { - for (const auto& reference_token : reference_tokens) + switch (m_type) { - // convert null values to arrays or objects before continuing - if (ptr->m_type == value_t::null) - { - // check if reference token is a number - const bool nums = std::all_of(reference_token.begin(), - reference_token.end(), - [](const char x) - { - return (x >= '0' and x <= '9'); - }); + case value_t::null: + return "null"; + case value_t::object: + return "object"; + case value_t::array: + return "array"; + case value_t::string: + return "string"; + case value_t::boolean: + return "boolean"; + case value_t::discarded: + return "discarded"; + default: + return "number"; + } + } + } - // change value to array for numbers or "-" or to object - // otherwise - if (nums or reference_token == "-") - { - *ptr = value_t::array; - } - else - { - *ptr = value_t::object; - } - } - switch (ptr->m_type) - { - case value_t::object: - { - // use unchecked object access - ptr = &ptr->operator[](reference_token); - break; - } + private: + ////////////////////// + // member variables // + ////////////////////// - case value_t::array: - { - // error condition (cf. RFC 6901, Sect. 4) - if (reference_token.size() > 1 and reference_token[0] == '0') - { - JSON_THROW(parse_error::create(106, 0, "array index '" + reference_token + "' must not begin with '0'")); - } + /// the type of the current element + value_t m_type = value_t::null; - if (reference_token == "-") - { - // explicitly treat "-" as index beyond the end - ptr = &ptr->operator[](ptr->m_value.array->size()); - } - else - { - // convert array index to number; unchecked access - JSON_TRY - { - ptr = &ptr->operator[](static_cast(std::stoi(reference_token))); - } - JSON_CATCH (std::invalid_argument&) - { - JSON_THROW(parse_error::create(109, 0, "array index '" + reference_token + "' is not a number")); - } - } - break; - } + /// the value of the current element + json_value m_value = {}; + + ////////////////////////////////////////// + // binary serialization/deserialization // + ////////////////////////////////////////// + + /// @name binary serialization/deserialization support + /// @{ + + public: + /*! + @brief create a CBOR serialization of a given JSON value - default: - { - JSON_THROW(out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); - } - } - } + Serializes a given JSON value @a j to a byte vector using the CBOR (Concise + Binary Object Representation) serialization format. CBOR is a binary + serialization format which aims to be more compact than JSON itself, yet + more efficient to parse. - return *ptr; - } + The library uses the following mapping from JSON values types to + CBOR types according to the CBOR specification (RFC 7049): - /*! - @throw parse_error.106 if an array index begins with '0' - @throw parse_error.109 if an array index was not a number - @throw out_of_range.402 if the array index '-' is used - @throw out_of_range.404 if the JSON pointer can not be resolved - */ - reference get_checked(pointer ptr) const - { - for (const auto& reference_token : reference_tokens) - { - switch (ptr->m_type) - { - case value_t::object: - { - // note: at performs range check - ptr = &ptr->at(reference_token); - break; - } + JSON value type | value/range | CBOR type | first byte + --------------- | ------------------------------------------ | ---------------------------------- | --------------- + null | `null` | Null | 0xF6 + boolean | `true` | True | 0xF5 + boolean | `false` | False | 0xF4 + number_integer | -9223372036854775808..-2147483649 | Negative integer (8 bytes follow) | 0x3B + number_integer | -2147483648..-32769 | Negative integer (4 bytes follow) | 0x3A + number_integer | -32768..-129 | Negative integer (2 bytes follow) | 0x39 + number_integer | -128..-25 | Negative integer (1 byte follow) | 0x38 + number_integer | -24..-1 | Negative integer | 0x20..0x37 + number_integer | 0..23 | Integer | 0x00..0x17 + number_integer | 24..255 | Unsigned integer (1 byte follow) | 0x18 + number_integer | 256..65535 | Unsigned integer (2 bytes follow) | 0x19 + number_integer | 65536..4294967295 | Unsigned integer (4 bytes follow) | 0x1A + number_integer | 4294967296..18446744073709551615 | Unsigned integer (8 bytes follow) | 0x1B + number_unsigned | 0..23 | Integer | 0x00..0x17 + number_unsigned | 24..255 | Unsigned integer (1 byte follow) | 0x18 + number_unsigned | 256..65535 | Unsigned integer (2 bytes follow) | 0x19 + number_unsigned | 65536..4294967295 | Unsigned integer (4 bytes follow) | 0x1A + number_unsigned | 4294967296..18446744073709551615 | Unsigned integer (8 bytes follow) | 0x1B + number_float | *any value* | Double-Precision Float | 0xFB + string | *length*: 0..23 | UTF-8 string | 0x60..0x77 + string | *length*: 23..255 | UTF-8 string (1 byte follow) | 0x78 + string | *length*: 256..65535 | UTF-8 string (2 bytes follow) | 0x79 + string | *length*: 65536..4294967295 | UTF-8 string (4 bytes follow) | 0x7A + string | *length*: 4294967296..18446744073709551615 | UTF-8 string (8 bytes follow) | 0x7B + array | *size*: 0..23 | array | 0x80..0x97 + array | *size*: 23..255 | array (1 byte follow) | 0x98 + array | *size*: 256..65535 | array (2 bytes follow) | 0x99 + array | *size*: 65536..4294967295 | array (4 bytes follow) | 0x9A + array | *size*: 4294967296..18446744073709551615 | array (8 bytes follow) | 0x9B + object | *size*: 0..23 | map | 0xA0..0xB7 + object | *size*: 23..255 | map (1 byte follow) | 0xB8 + object | *size*: 256..65535 | map (2 bytes follow) | 0xB9 + object | *size*: 65536..4294967295 | map (4 bytes follow) | 0xBA + object | *size*: 4294967296..18446744073709551615 | map (8 bytes follow) | 0xBB - case value_t::array: - { - if (reference_token == "-") - { - // "-" always fails the range check - JSON_THROW(out_of_range::create(402, "array index '-' (" + - std::to_string(ptr->m_value.array->size()) + - ") is out of range")); - } + @note The mapping is **complete** in the sense that any JSON value type + can be converted to a CBOR value. - // error condition (cf. RFC 6901, Sect. 4) - if (reference_token.size() > 1 and reference_token[0] == '0') - { - JSON_THROW(parse_error::create(106, 0, "array index '" + reference_token + "' must not begin with '0'")); - } + @note If NaN or Infinity are stored inside a JSON number, they are + serialized properly. This behavior differs from the @ref dump() + function which serializes NaN or Infinity to `null`. - // note: at performs range check - JSON_TRY - { - ptr = &ptr->at(static_cast(std::stoi(reference_token))); - } - JSON_CATCH (std::invalid_argument&) - { - JSON_THROW(parse_error::create(109, 0, "array index '" + reference_token + "' is not a number")); - } - break; - } + @note The following CBOR types are not used in the conversion: + - byte strings (0x40..0x5F) + - UTF-8 strings terminated by "break" (0x7F) + - arrays terminated by "break" (0x9F) + - maps terminated by "break" (0xBF) + - date/time (0xC0..0xC1) + - bignum (0xC2..0xC3) + - decimal fraction (0xC4) + - bigfloat (0xC5) + - tagged items (0xC6..0xD4, 0xD8..0xDB) + - expected conversions (0xD5..0xD7) + - simple values (0xE0..0xF3, 0xF8) + - undefined (0xF7) + - half and single-precision floats (0xF9-0xFA) + - break (0xFF) - default: - { - JSON_THROW(out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); - } - } - } + @param[in] j JSON value to serialize + @return MessagePack serialization as byte vector - return *ptr; - } + @complexity Linear in the size of the JSON value @a j. - /*! - @brief return a const reference to the pointed to value + @liveexample{The example shows the serialization of a JSON value to a byte + vector in CBOR format.,to_cbor} - @param[in] ptr a JSON value + @sa http://cbor.io + @sa @ref from_cbor(const std::vector&, const size_t) for the + analogous deserialization + @sa @ref to_msgpack(const basic_json&) for the related MessagePack format - @return const reference to the JSON value pointed to by the JSON - pointer + @since version 2.0.9 + */ + static std::vector to_cbor(const basic_json& j) + { + std::vector result; + to_cbor(j, result); + return result; + } - @throw parse_error.106 if an array index begins with '0' - @throw parse_error.109 if an array index was not a number - @throw out_of_range.402 if the array index '-' is used - @throw out_of_range.404 if the JSON pointer can not be resolved - */ - const_reference get_unchecked(const_pointer ptr) const - { - for (const auto& reference_token : reference_tokens) - { - switch (ptr->m_type) - { - case value_t::object: - { - // use unchecked object access - ptr = &ptr->operator[](reference_token); - break; - } + static void to_cbor(const basic_json& j, detail::output_adapter o) + { + binary_writer(o).write_cbor(j); + } - case value_t::array: - { - if (reference_token == "-") - { - // "-" cannot be used for const access - JSON_THROW(out_of_range::create(402, "array index '-' (" + - std::to_string(ptr->m_value.array->size()) + - ") is out of range")); - } + static void to_cbor(const basic_json& j, detail::output_adapter o) + { + binary_writer(o).write_cbor(j); + } - // error condition (cf. RFC 6901, Sect. 4) - if (reference_token.size() > 1 and reference_token[0] == '0') - { - JSON_THROW(parse_error::create(106, 0, "array index '" + reference_token + "' must not begin with '0'")); - } + /*! + @brief create a MessagePack serialization of a given JSON value - // use unchecked array access - JSON_TRY - { - ptr = &ptr->operator[](static_cast(std::stoi(reference_token))); - } - JSON_CATCH (std::invalid_argument&) - { - JSON_THROW(parse_error::create(109, 0, "array index '" + reference_token + "' is not a number")); - } - break; - } + Serializes a given JSON value @a j to a byte vector using the MessagePack + serialization format. MessagePack is a binary serialization format which + aims to be more compact than JSON itself, yet more efficient to parse. - default: - { - JSON_THROW(out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); - } - } - } + The library uses the following mapping from JSON values types to + MessagePack types according to the MessagePack specification: - return *ptr; - } + JSON value type | value/range | MessagePack type | first byte + --------------- | --------------------------------- | ---------------- | ---------- + null | `null` | nil | 0xC0 + boolean | `true` | true | 0xC3 + boolean | `false` | false | 0xC2 + number_integer | -9223372036854775808..-2147483649 | int64 | 0xD3 + number_integer | -2147483648..-32769 | int32 | 0xD2 + number_integer | -32768..-129 | int16 | 0xD1 + number_integer | -128..-33 | int8 | 0xD0 + number_integer | -32..-1 | negative fixint | 0xE0..0xFF + number_integer | 0..127 | positive fixint | 0x00..0x7F + number_integer | 128..255 | uint 8 | 0xCC + number_integer | 256..65535 | uint 16 | 0xCD + number_integer | 65536..4294967295 | uint 32 | 0xCE + number_integer | 4294967296..18446744073709551615 | uint 64 | 0xCF + number_unsigned | 0..127 | positive fixint | 0x00..0x7F + number_unsigned | 128..255 | uint 8 | 0xCC + number_unsigned | 256..65535 | uint 16 | 0xCD + number_unsigned | 65536..4294967295 | uint 32 | 0xCE + number_unsigned | 4294967296..18446744073709551615 | uint 64 | 0xCF + number_float | *any value* | float 64 | 0xCB + string | *length*: 0..31 | fixstr | 0xA0..0xBF + string | *length*: 32..255 | str 8 | 0xD9 + string | *length*: 256..65535 | str 16 | 0xDA + string | *length*: 65536..4294967295 | str 32 | 0xDB + array | *size*: 0..15 | fixarray | 0x90..0x9F + array | *size*: 16..65535 | array 16 | 0xDC + array | *size*: 65536..4294967295 | array 32 | 0xDD + object | *size*: 0..15 | fix map | 0x80..0x8F + object | *size*: 16..65535 | map 16 | 0xDE + object | *size*: 65536..4294967295 | map 32 | 0xDF - /*! - @throw parse_error.106 if an array index begins with '0' - @throw parse_error.109 if an array index was not a number - @throw out_of_range.402 if the array index '-' is used - @throw out_of_range.404 if the JSON pointer can not be resolved - */ - const_reference get_checked(const_pointer ptr) const - { - for (const auto& reference_token : reference_tokens) - { - switch (ptr->m_type) - { - case value_t::object: - { - // note: at performs range check - ptr = &ptr->at(reference_token); - break; - } + @note The mapping is **complete** in the sense that any JSON value type + can be converted to a MessagePack value. - case value_t::array: - { - if (reference_token == "-") - { - // "-" always fails the range check - JSON_THROW(out_of_range::create(402, "array index '-' (" + - std::to_string(ptr->m_value.array->size()) + - ") is out of range")); - } + @note The following values can **not** be converted to a MessagePack value: + - strings with more than 4294967295 bytes + - arrays with more than 4294967295 elements + - objects with more than 4294967295 elements - // error condition (cf. RFC 6901, Sect. 4) - if (reference_token.size() > 1 and reference_token[0] == '0') - { - JSON_THROW(parse_error::create(106, 0, "array index '" + reference_token + "' must not begin with '0'")); - } + @note The following MessagePack types are not used in the conversion: + - bin 8 - bin 32 (0xC4..0xC6) + - ext 8 - ext 32 (0xC7..0xC9) + - float 32 (0xCA) + - fixext 1 - fixext 16 (0xD4..0xD8) - // note: at performs range check - JSON_TRY - { - ptr = &ptr->at(static_cast(std::stoi(reference_token))); - } - JSON_CATCH (std::invalid_argument&) - { - JSON_THROW(parse_error::create(109, 0, "array index '" + reference_token + "' is not a number")); - } - break; - } + @note Any MessagePack output created @ref to_msgpack can be successfully + parsed by @ref from_msgpack. - default: - { - JSON_THROW(out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); - } - } - } + @note If NaN or Infinity are stored inside a JSON number, they are + serialized properly. This behavior differs from the @ref dump() + function which serializes NaN or Infinity to `null`. - return *ptr; - } + @param[in] j JSON value to serialize + @return MessagePack serialization as byte vector - /*! - @brief split the string input to reference tokens + @complexity Linear in the size of the JSON value @a j. - @note This function is only called by the json_pointer constructor. - All exceptions below are documented there. + @liveexample{The example shows the serialization of a JSON value to a byte + vector in MessagePack format.,to_msgpack} - @throw parse_error.107 if the pointer is not empty or begins with '/' - @throw parse_error.108 if character '~' is not followed by '0' or '1' - */ - static std::vector split(const std::string& reference_string) - { - std::vector result; + @sa http://msgpack.org + @sa @ref from_msgpack(const std::vector&, const size_t) for the + analogous deserialization + @sa @ref to_cbor(const basic_json& for the related CBOR format - // special case: empty reference string -> no reference tokens - if (reference_string.empty()) - { - return result; - } + @since version 2.0.9 + */ + static std::vector to_msgpack(const basic_json& j) + { + std::vector result; + to_msgpack(j, result); + return result; + } - // check if nonempty reference string begins with slash - if (reference_string[0] != '/') - { - JSON_THROW(parse_error::create(107, 1, "JSON pointer must be empty or begin with '/' - was: '" + reference_string + "'")); - } + static void to_msgpack(const basic_json& j, detail::output_adapter o) + { + binary_writer(o).write_msgpack(j); + } - // extract the reference tokens: - // - slash: position of the last read slash (or end of string) - // - start: position after the previous slash - for ( - // search for the first slash after the first character - size_t slash = reference_string.find_first_of('/', 1), - // set the beginning of the first reference token - start = 1; - // we can stop if start == string::npos+1 = 0 - start != 0; - // set the beginning of the next reference token - // (will eventually be 0 if slash == std::string::npos) - start = slash + 1, - // find next slash - slash = reference_string.find_first_of('/', start)) - { - // use the text between the beginning of the reference token - // (start) and the last slash (slash). - auto reference_token = reference_string.substr(start, slash - start); + static void to_msgpack(const basic_json& j, detail::output_adapter o) + { + binary_writer(o).write_msgpack(j); + } - // check reference tokens are properly escaped - for (size_t pos = reference_token.find_first_of('~'); - pos != std::string::npos; - pos = reference_token.find_first_of('~', pos + 1)) - { - assert(reference_token[pos] == '~'); + /*! + @brief create a JSON value from an input in CBOR format - // ~ must be followed by 0 or 1 - if (pos == reference_token.size() - 1 or - (reference_token[pos + 1] != '0' and - reference_token[pos + 1] != '1')) - { - JSON_THROW(parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'")); - } - } + Deserializes a given input @a i to a JSON value using the CBOR (Concise + Binary Object Representation) serialization format. - // finally, store the reference token - unescape(reference_token); - result.push_back(reference_token); - } + The library maps CBOR types to JSON value types as follows: - return result; - } + CBOR type | JSON value type | first byte + ---------------------- | --------------- | ---------- + Integer | number_unsigned | 0x00..0x17 + Unsigned integer | number_unsigned | 0x18 + Unsigned integer | number_unsigned | 0x19 + Unsigned integer | number_unsigned | 0x1A + Unsigned integer | number_unsigned | 0x1B + Negative integer | number_integer | 0x20..0x37 + Negative integer | number_integer | 0x38 + Negative integer | number_integer | 0x39 + Negative integer | number_integer | 0x3A + Negative integer | number_integer | 0x3B + Negative integer | number_integer | 0x40..0x57 + UTF-8 string | string | 0x60..0x77 + UTF-8 string | string | 0x78 + UTF-8 string | string | 0x79 + UTF-8 string | string | 0x7A + UTF-8 string | string | 0x7B + UTF-8 string | string | 0x7F + array | array | 0x80..0x97 + array | array | 0x98 + array | array | 0x99 + array | array | 0x9A + array | array | 0x9B + array | array | 0x9F + map | object | 0xA0..0xB7 + map | object | 0xB8 + map | object | 0xB9 + map | object | 0xBA + map | object | 0xBB + map | object | 0xBF + False | `false` | 0xF4 + True | `true` | 0xF5 + Nill | `null` | 0xF6 + Half-Precision Float | number_float | 0xF9 + Single-Precision Float | number_float | 0xFA + Double-Precision Float | number_float | 0xFB - /*! - @brief replace all occurrences of a substring by another string + @warning The mapping is **incomplete** in the sense that not all CBOR + types can be converted to a JSON value. The following CBOR types + are not supported and will yield parse errors (parse_error.112): + - byte strings (0x40..0x5F) + - date/time (0xC0..0xC1) + - bignum (0xC2..0xC3) + - decimal fraction (0xC4) + - bigfloat (0xC5) + - tagged items (0xC6..0xD4, 0xD8..0xDB) + - expected conversions (0xD5..0xD7) + - simple values (0xE0..0xF3, 0xF8) + - undefined (0xF7) - @param[in,out] s the string to manipulate; changed so that all - occurrences of @a f are replaced with @a t - @param[in] f the substring to replace with @a t - @param[in] t the string to replace @a f + @warning CBOR allows map keys of any type, whereas JSON only allows + strings as keys in object values. Therefore, CBOR maps with keys + other than UTF-8 strings are rejected (parse_error.113). - @pre The search string @a f must not be empty. **This precondition is - enforced with an assertion.** + @note Any CBOR output created @ref to_cbor can be successfully parsed by + @ref from_cbor. - @since version 2.0.0 - */ - static void replace_substring(std::string& s, - const std::string& f, - const std::string& t) - { - assert(not f.empty()); + @param[in] i an input in CBOR format convertible to an input adapter + @param[in] strict whether to expect the input to be consumed until EOF + (true by default) + @return deserialized JSON value - for ( - size_t pos = s.find(f); // find first occurrence of f - pos != std::string::npos; // make sure f was found - s.replace(pos, f.size(), t), // replace with t - pos = s.find(f, pos + t.size()) // find next occurrence of f - ); - } + @throw parse_error.110 if the given input ends prematurely or the end of + file was not reached when @a strict was set to true + @throw parse_error.112 if unsupported features from CBOR were + used in the given input @a v or if the input is not valid CBOR + @throw parse_error.113 if a string was expected as map key, but not found - /// escape tilde and slash - static std::string escape(std::string s) - { - // escape "~"" to "~0" and "/" to "~1" - replace_substring(s, "~", "~0"); - replace_substring(s, "/", "~1"); - return s; - } + @complexity Linear in the size of the input @a i. - /// unescape tilde and slash - static void unescape(std::string& s) - { - // first transform any occurrence of the sequence '~1' to '/' - replace_substring(s, "~1", "/"); - // then transform any occurrence of the sequence '~0' to '~' - replace_substring(s, "~0", "~"); - } + @liveexample{The example shows the deserialization of a byte vector in CBOR + format to a JSON value.,from_cbor} - /*! - @param[in] reference_string the reference string to the current value - @param[in] value the value to consider - @param[in,out] result the result object to insert values to + @sa http://cbor.io + @sa @ref to_cbor(const basic_json&) for the analogous serialization + @sa @ref from_msgpack(detail::input_adapter, const bool) for the + related MessagePack format - @note Empty objects or arrays are flattened to `null`. - */ - static void flatten(const std::string& reference_string, - const basic_json& value, - basic_json& result) - { - switch (value.m_type) - { - case value_t::array: - { - if (value.m_value.array->empty()) - { - // flatten empty array as null - result[reference_string] = nullptr; - } - else - { - // iterate array and use index as reference string - for (size_t i = 0; i < value.m_value.array->size(); ++i) - { - flatten(reference_string + "/" + std::to_string(i), - value.m_value.array->operator[](i), result); - } - } - break; - } + @since version 2.0.9; parameter @a start_index since 2.1.1; changed to + consume input adapters, removed start_index parameter, and added + @a strict parameter since 3.0.0 + */ + static basic_json from_cbor(detail::input_adapter i, + const bool strict = true) + { + return binary_reader(i).parse_cbor(strict); + } - case value_t::object: - { - if (value.m_value.object->empty()) - { - // flatten empty object as null - result[reference_string] = nullptr; - } - else - { - // iterate object and use keys as reference string - for (const auto& element : *value.m_value.object) - { - flatten(reference_string + "/" + escape(element.first), - element.second, result); - } - } - break; - } + /*! + @copydoc from_cbor(detail::input_adapter, const bool) + */ + template::value, int> = 0> + static basic_json from_cbor(A1 && a1, A2 && a2, const bool strict = true) + { + return binary_reader(detail::input_adapter(std::forward(a1), std::forward(a2))).parse_cbor(strict); + } - default: - { - // add primitive value with its reference string - result[reference_string] = value; - break; - } - } - } + /*! + @brief create a JSON value from an input in MessagePack format - /*! - @param[in] value flattened JSON + Deserializes a given input @a i to a JSON value using the MessagePack + serialization format. - @return unflattened JSON + The library maps MessagePack types to JSON value types as follows: - @throw parse_error.109 if array index is not a number - @throw type_error.314 if value is not an object - @throw type_error.315 if object values are not primitive - @throw type_error.313 if value cannot be unflattened - */ - static basic_json unflatten(const basic_json& value) - { - if (not value.is_object()) - { - JSON_THROW(type_error::create(314, "only objects can be unflattened")); - } + MessagePack type | JSON value type | first byte + ---------------- | --------------- | ---------- + positive fixint | number_unsigned | 0x00..0x7F + fixmap | object | 0x80..0x8F + fixarray | array | 0x90..0x9F + fixstr | string | 0xA0..0xBF + nil | `null` | 0xC0 + false | `false` | 0xC2 + true | `true` | 0xC3 + float 32 | number_float | 0xCA + float 64 | number_float | 0xCB + uint 8 | number_unsigned | 0xCC + uint 16 | number_unsigned | 0xCD + uint 32 | number_unsigned | 0xCE + uint 64 | number_unsigned | 0xCF + int 8 | number_integer | 0xD0 + int 16 | number_integer | 0xD1 + int 32 | number_integer | 0xD2 + int 64 | number_integer | 0xD3 + str 8 | string | 0xD9 + str 16 | string | 0xDA + str 32 | string | 0xDB + array 16 | array | 0xDC + array 32 | array | 0xDD + map 16 | object | 0xDE + map 32 | object | 0xDF + negative fixint | number_integer | 0xE0-0xFF - basic_json result; + @warning The mapping is **incomplete** in the sense that not all + MessagePack types can be converted to a JSON value. The following + MessagePack types are not supported and will yield parse errors: + - bin 8 - bin 32 (0xC4..0xC6) + - ext 8 - ext 32 (0xC7..0xC9) + - fixext 1 - fixext 16 (0xD4..0xD8) - // iterate the JSON object values - for (const auto& element : *value.m_value.object) - { - if (not element.second.is_primitive()) - { - JSON_THROW(type_error::create(315, "values in object must be primitive")); - } + @note Any MessagePack output created @ref to_msgpack can be successfully + parsed by @ref from_msgpack. - // assign value to reference pointed to by JSON pointer; Note - // that if the JSON pointer is "" (i.e., points to the whole - // value), function get_and_create returns a reference to - // result itself. An assignment will then create a primitive - // value. - json_pointer(element.first).get_and_create(result) = element.second; - } + @param[in] i an input in MessagePack format convertible to an input + adapter + @param[in] strict whether to expect the input to be consumed until EOF + (true by default) - return result; - } + @throw parse_error.110 if the given input ends prematurely or the end of + file was not reached when @a strict was set to true + @throw parse_error.112 if unsupported features from MessagePack were + used in the given input @a i or if the input is not valid MessagePack + @throw parse_error.113 if a string was expected as map key, but not found - friend bool operator==(json_pointer const& lhs, - json_pointer const& rhs) noexcept - { - return lhs.reference_tokens == rhs.reference_tokens; - } + @complexity Linear in the size of the input @a i. - friend bool operator!=(json_pointer const& lhs, - json_pointer const& rhs) noexcept - { - return !(lhs == rhs); - } + @liveexample{The example shows the deserialization of a byte vector in + MessagePack format to a JSON value.,from_msgpack} - /// the reference tokens - std::vector reference_tokens {}; - }; + @sa http://msgpack.org + @sa @ref to_msgpack(const basic_json&) for the analogous serialization + @sa @ref from_cbor(detail::input_adapter, const bool) for the related CBOR + format + + @since version 2.0.9; parameter @a start_index since 2.1.1; changed to + consume input adapters, removed start_index parameter, and added + @a strict parameter since 3.0.0 + */ + static basic_json from_msgpack(detail::input_adapter i, + const bool strict = true) + { + return binary_reader(i).parse_msgpack(strict); + } + + /*! + @copydoc from_msgpack(detail::input_adapter, const bool) + */ + template::value, int> = 0> + static basic_json from_msgpack(A1 && a1, A2 && a2, const bool strict = true) + { + return binary_reader(detail::input_adapter(std::forward(a1), std::forward(a2))).parse_msgpack(strict); + } + + /// @} ////////////////////////// // JSON Pointer support // @@ -13277,7 +13828,7 @@ class basic_json @complexity Linear in the size the JSON value. @throw type_error.314 if value is not an object - @throw type_error.315 if object values are not primitve + @throw type_error.315 if object values are not primitive @liveexample{The following code shows how a flattened JSON object is unflattened into the original nested JSON object.,unflatten} @@ -13426,7 +13977,7 @@ class basic_json else { const auto idx = std::stoi(last_path); - if (static_cast(idx) > parent.size()) + if (JSON_UNLIKELY(static_cast(idx) > parent.size())) { // avoid undefined behavior JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range")); @@ -13461,7 +14012,7 @@ class basic_json { // perform range check auto it = parent.find(last_path); - if (it != parent.end()) + if (JSON_LIKELY(it != parent.end())) { parent.erase(it); } @@ -13478,7 +14029,7 @@ class basic_json }; // type check: top level value must be an array - if (not json_patch.is_array()) + if (JSON_UNLIKELY(not json_patch.is_array())) { JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects")); } @@ -13498,13 +14049,13 @@ class basic_json const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'"; // check if desired value is present - if (it == val.m_value.object->end()) + if (JSON_UNLIKELY(it == val.m_value.object->end())) { JSON_THROW(parse_error::create(105, 0, error_msg + " must have member '" + member + "'")); } // check if result is of type string - if (string_type and not it->second.is_string()) + if (JSON_UNLIKELY(string_type and not it->second.is_string())) { JSON_THROW(parse_error::create(105, 0, error_msg + " must have string member '" + member + "'")); } @@ -13514,7 +14065,7 @@ class basic_json }; // type check: every element of the array must be an object - if (not val.is_object()) + if (JSON_UNLIKELY(not val.is_object())) { JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects")); } @@ -13564,7 +14115,7 @@ class basic_json case patch_operations::copy: { - const std::string from_path = get_value("copy", "from", true);; + const std::string from_path = get_value("copy", "from", true); const json_pointer from_ptr(from_path); // the "from" location must exist - use at() @@ -13587,7 +14138,7 @@ class basic_json } // throw an exception if test fails - if (not success) + if (JSON_UNLIKELY(not success)) { JSON_THROW(other_error::create(501, "unsuccessful: " + val.dump())); } @@ -13639,8 +14190,7 @@ class basic_json @since version 2.0.0 */ - static basic_json diff(const basic_json& source, - const basic_json& target, + static basic_json diff(const basic_json& source, const basic_json& target, const std::string& path = "") { // the patch @@ -13657,9 +14207,7 @@ class basic_json // different types: replace value result.push_back( { - {"op", "replace"}, - {"path", path}, - {"value", target} + {"op", "replace"}, {"path", path}, {"value", target} }); } else @@ -13669,7 +14217,7 @@ class basic_json case value_t::array: { // first pass: traverse common elements - size_t i = 0; + std::size_t i = 0; while (i < source.size() and i < target.size()) { // recursive call to compare array values at index i @@ -13729,8 +14277,7 @@ class basic_json // found a key that is not in o -> remove it result.push_back(object( { - {"op", "remove"}, - {"path", path + "/" + key} + {"op", "remove"}, {"path", path + "/" + key} })); } } @@ -13744,8 +14291,7 @@ class basic_json const auto key = json_pointer::escape(it.key()); result.push_back( { - {"op", "add"}, - {"path", path + "/" + key}, + {"op", "add"}, {"path", path + "/" + key}, {"value", it.value()} }); } @@ -13759,9 +14305,7 @@ class basic_json // both primitive type: replace value result.push_back( { - {"op", "replace"}, - {"path", path}, - {"value", target} + {"op", "replace"}, {"path", path}, {"value", target} }); break; } @@ -13787,6 +14331,400 @@ uses the standard template types. @since version 1.0.0 */ using json = basic_json<>; + +////////////////// +// json_pointer // +////////////////// + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +NLOHMANN_BASIC_JSON_TPL& +json_pointer::get_and_create(NLOHMANN_BASIC_JSON_TPL& j) const +{ + using size_type = typename NLOHMANN_BASIC_JSON_TPL::size_type; + auto result = &j; + + // in case no reference tokens exist, return a reference to the JSON value + // j which will be overwritten by a primitive value + for (const auto& reference_token : reference_tokens) + { + switch (result->m_type) + { + case detail::value_t::null: + { + if (reference_token == "0") + { + // start a new array if reference token is 0 + result = &result->operator[](0); + } + else + { + // start a new object otherwise + result = &result->operator[](reference_token); + } + break; + } + + case detail::value_t::object: + { + // create an entry in the object + result = &result->operator[](reference_token); + break; + } + + case detail::value_t::array: + { + // create an entry in the array + JSON_TRY + { + result = &result->operator[](static_cast(std::stoi(reference_token))); + } + JSON_CATCH(std::invalid_argument&) + { + JSON_THROW(detail::parse_error::create(109, 0, "array index '" + reference_token + "' is not a number")); + } + break; + } + + /* + The following code is only reached if there exists a reference + token _and_ the current value is primitive. In this case, we have + an error situation, because primitive values may only occur as + single value; that is, with an empty list of reference tokens. + */ + default: + JSON_THROW(detail::type_error::create(313, "invalid value to unflatten")); + } + } + + return *result; +} + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +NLOHMANN_BASIC_JSON_TPL& +json_pointer::get_unchecked(NLOHMANN_BASIC_JSON_TPL* ptr) const +{ + using size_type = typename NLOHMANN_BASIC_JSON_TPL::size_type; + for (const auto& reference_token : reference_tokens) + { + // convert null values to arrays or objects before continuing + if (ptr->m_type == detail::value_t::null) + { + // check if reference token is a number + const bool nums = + std::all_of(reference_token.begin(), reference_token.end(), + [](const char x) + { + return (x >= '0' and x <= '9'); + }); + + // change value to array for numbers or "-" or to object otherwise + *ptr = (nums or reference_token == "-") + ? detail::value_t::array + : detail::value_t::object; + } + + switch (ptr->m_type) + { + case detail::value_t::object: + { + // use unchecked object access + ptr = &ptr->operator[](reference_token); + break; + } + + case detail::value_t::array: + { + // error condition (cf. RFC 6901, Sect. 4) + if (JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0')) + { + JSON_THROW(detail::parse_error::create(106, 0, + "array index '" + reference_token + + "' must not begin with '0'")); + } + + if (reference_token == "-") + { + // explicitly treat "-" as index beyond the end + ptr = &ptr->operator[](ptr->m_value.array->size()); + } + else + { + // convert array index to number; unchecked access + JSON_TRY + { + ptr = &ptr->operator[]( + static_cast(std::stoi(reference_token))); + } + JSON_CATCH(std::invalid_argument&) + { + JSON_THROW(detail::parse_error::create(109, 0, "array index '" + reference_token + "' is not a number")); + } + } + break; + } + + default: + JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); + } + } + + return *ptr; +} + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +NLOHMANN_BASIC_JSON_TPL& +json_pointer::get_checked(NLOHMANN_BASIC_JSON_TPL* ptr) const +{ + using size_type = typename NLOHMANN_BASIC_JSON_TPL::size_type; + for (const auto& reference_token : reference_tokens) + { + switch (ptr->m_type) + { + case detail::value_t::object: + { + // note: at performs range check + ptr = &ptr->at(reference_token); + break; + } + + case detail::value_t::array: + { + if (JSON_UNLIKELY(reference_token == "-")) + { + // "-" always fails the range check + JSON_THROW(detail::out_of_range::create(402, + "array index '-' (" + std::to_string(ptr->m_value.array->size()) + + ") is out of range")); + } + + // error condition (cf. RFC 6901, Sect. 4) + if (JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0')) + { + JSON_THROW(detail::parse_error::create(106, 0, + "array index '" + reference_token + + "' must not begin with '0'")); + } + + // note: at performs range check + JSON_TRY + { + ptr = &ptr->at(static_cast(std::stoi(reference_token))); + } + JSON_CATCH(std::invalid_argument&) + { + JSON_THROW(detail::parse_error::create(109, 0, "array index '" + reference_token + "' is not a number")); + } + break; + } + + default: + JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); + } + } + + return *ptr; +} + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +const NLOHMANN_BASIC_JSON_TPL& +json_pointer::get_unchecked(const NLOHMANN_BASIC_JSON_TPL* ptr) const +{ + using size_type = typename NLOHMANN_BASIC_JSON_TPL::size_type; + for (const auto& reference_token : reference_tokens) + { + switch (ptr->m_type) + { + case detail::value_t::object: + { + // use unchecked object access + ptr = &ptr->operator[](reference_token); + break; + } + + case detail::value_t::array: + { + if (JSON_UNLIKELY(reference_token == "-")) + { + // "-" cannot be used for const access + JSON_THROW(detail::out_of_range::create(402, + "array index '-' (" + std::to_string(ptr->m_value.array->size()) + + ") is out of range")); + } + + // error condition (cf. RFC 6901, Sect. 4) + if (JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0')) + { + JSON_THROW(detail::parse_error::create(106, 0, + "array index '" + reference_token + + "' must not begin with '0'")); + } + + // use unchecked array access + JSON_TRY + { + ptr = &ptr->operator[]( + static_cast(std::stoi(reference_token))); + } + JSON_CATCH(std::invalid_argument&) + { + JSON_THROW(detail::parse_error::create(109, 0, "array index '" + reference_token + "' is not a number")); + } + break; + } + + default: + JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); + } + } + + return *ptr; +} + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +const NLOHMANN_BASIC_JSON_TPL& +json_pointer::get_checked(const NLOHMANN_BASIC_JSON_TPL* ptr) const +{ + using size_type = typename NLOHMANN_BASIC_JSON_TPL::size_type; + for (const auto& reference_token : reference_tokens) + { + switch (ptr->m_type) + { + case detail::value_t::object: + { + // note: at performs range check + ptr = &ptr->at(reference_token); + break; + } + + case detail::value_t::array: + { + if (JSON_UNLIKELY(reference_token == "-")) + { + // "-" always fails the range check + JSON_THROW(detail::out_of_range::create(402, + "array index '-' (" + std::to_string(ptr->m_value.array->size()) + + ") is out of range")); + } + + // error condition (cf. RFC 6901, Sect. 4) + if (JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0')) + { + JSON_THROW(detail::parse_error::create(106, 0, + "array index '" + reference_token + + "' must not begin with '0'")); + } + + // note: at performs range check + JSON_TRY + { + ptr = &ptr->at(static_cast(std::stoi(reference_token))); + } + JSON_CATCH(std::invalid_argument&) + { + JSON_THROW(detail::parse_error::create(109, 0, "array index '" + reference_token + "' is not a number")); + } + break; + } + + default: + JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); + } + } + + return *ptr; +} + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +void json_pointer::flatten(const std::string& reference_string, + const NLOHMANN_BASIC_JSON_TPL& value, + NLOHMANN_BASIC_JSON_TPL& result) +{ + switch (value.m_type) + { + case detail::value_t::array: + { + if (value.m_value.array->empty()) + { + // flatten empty array as null + result[reference_string] = nullptr; + } + else + { + // iterate array and use index as reference string + for (std::size_t i = 0; i < value.m_value.array->size(); ++i) + { + flatten(reference_string + "/" + std::to_string(i), + value.m_value.array->operator[](i), result); + } + } + break; + } + + case detail::value_t::object: + { + if (value.m_value.object->empty()) + { + // flatten empty object as null + result[reference_string] = nullptr; + } + else + { + // iterate object and use keys as reference string + for (const auto& element : *value.m_value.object) + { + flatten(reference_string + "/" + escape(element.first), element.second, result); + } + } + break; + } + + default: + { + // add primitive value with its reference string + result[reference_string] = value; + break; + } + } +} + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +NLOHMANN_BASIC_JSON_TPL +json_pointer::unflatten(const NLOHMANN_BASIC_JSON_TPL& value) +{ + if (JSON_UNLIKELY(not value.is_object())) + { + JSON_THROW(detail::type_error::create(314, "only objects can be unflattened")); + } + + NLOHMANN_BASIC_JSON_TPL result; + + // iterate the JSON object values + for (const auto& element : *value.m_value.object) + { + if (JSON_UNLIKELY(not element.second.is_primitive())) + { + JSON_THROW(detail::type_error::create(315, "values in object must be primitive")); + } + + // assign value to reference pointed to by JSON pointer; Note that if + // the JSON pointer is "" (i.e., points to the whole value), function + // get_and_create returns a reference to result itself. An assignment + // will then create a primitive value. + json_pointer(element.first).get_and_create(result) = element.second; + } + + return result; +} + +inline bool operator==(json_pointer const& lhs, json_pointer const& rhs) noexcept +{ + return (lhs.reference_tokens == rhs.reference_tokens); +} + +inline bool operator!=(json_pointer const& lhs, json_pointer const& rhs) noexcept +{ + return not (lhs == rhs); +} } // namespace nlohmann @@ -13804,7 +14742,7 @@ namespace std */ template<> inline void swap(nlohmann::json& j1, - nlohmann::json& j2) noexcept_if( + nlohmann::json& j2) noexcept( is_nothrow_move_constructible::value and is_nothrow_move_assignable::value ) @@ -13830,8 +14768,10 @@ struct hash }; /// specialization for std::less -template <> -struct less<::nlohmann::detail::value_t> +/// @note: do not remove the space after '<', +/// see https://github.com/nlohmann/json/pull/679 +template<> +struct less< ::nlohmann::detail::value_t> { /*! @brief compare two value_t enum values @@ -13886,11 +14826,18 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) #pragma GCC diagnostic pop #endif +#if defined(__clang__) + #pragma GCC diagnostic pop +#endif // clean up #undef JSON_CATCH #undef JSON_THROW #undef JSON_TRY +#undef JSON_LIKELY +#undef JSON_UNLIKELY #undef JSON_DEPRECATED +#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION +#undef NLOHMANN_BASIC_JSON_TPL #endif diff --git a/wrappers/libfftw/libpng.pri b/wrappers/libfftw/libpng.pri new file mode 100644 index 000000000..3bb3bc301 --- /dev/null +++ b/wrappers/libfftw/libpng.pri @@ -0,0 +1,13 @@ +isEmpty(LIBPNG_WRAPPER_DIR) { + message(Incorrect usage of libpng.pri with empty LIBPNG_WRAPPER_DIR. Libpng is switched off!) +} else { + include(libpngLibs.pri) +} + +contains(DEFINES, WITH_LIBPNG) { # if it's installed properly with found path for lib + + INCLUDEPATH += $$LIBPNG_WRAPPER_DIR + + HEADERS += $$LIBPNG_WRAPPER_DIR/libpngFileReader.h + SOURCES += $$LIBPNG_WRAPPER_DIR/libpngFileReader.cpp +} diff --git a/wrappers/libfftw/sourcelist.cmake b/wrappers/libfftw/sourcelist.cmake new file mode 100644 index 000000000..ebe004a54 --- /dev/null +++ b/wrappers/libfftw/sourcelist.cmake @@ -0,0 +1,16 @@ +set (HDR_FILES + ${HDR_FILES} +) + + +set (SRC_FILES + ${SRC_FILES} +) + +add_definitions(-DWITH_FFTW) +set (INC_PATHS + ${INC_PATHS} + ${FFTW_INCLUDE_DIRS} + ) + +set(LIBS ${LIBS} ${FFTW_LIBRARIES}) diff --git a/wrappers/libjpeg/CMakeLists.txt b/wrappers/libjpeg/CMakeLists.txt new file mode 100644 index 000000000..820f8cb15 --- /dev/null +++ b/wrappers/libjpeg/CMakeLists.txt @@ -0,0 +1,43 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME wrappers) +init_project(PROJECT_NAME LIBJPEGwrapper) + +set(PUBLIC_HEADER_FILE + libjpegFileReader.h + ) + +set(HEADERS + ${PUBLIC_HEADER_FILE} + ) + +set(SOURCE_FILE + libjpegFileReader.cpp + ) + +set(SOURCES + ${SOURCE_FILE} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_library(${PROJECT_NAME} SHARED + ${HEADERS} + ${SOURCES} + ) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) + +target_link_libraries(${PROJECT_NAME} + PUBLIC + JPEG::JPEG + PRIVATE + corecvs + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/wrappers/libjpeg/libjpegFileReader.h b/wrappers/libjpeg/libjpegFileReader.h index f1535d7b7..20b9e439b 100644 --- a/wrappers/libjpeg/libjpegFileReader.h +++ b/wrappers/libjpeg/libjpegFileReader.h @@ -1,8 +1,8 @@ #ifndef LIBJPEGFILEREADER_H #define LIBJPEGFILEREADER_H -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/bufferFactory.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/bufferFactory.h" class LibjpegFileReader : public corecvs::BufferLoader diff --git a/wrappers/libjpeg/sourcelist.cmake b/wrappers/libjpeg/sourcelist.cmake deleted file mode 100644 index a51cbae36..000000000 --- a/wrappers/libjpeg/sourcelist.cmake +++ /dev/null @@ -1,20 +0,0 @@ -set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/libjpegFileReader.h -) - - -set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/libjpegFileReader.cpp -) - -add_definitions(-DWITH_LIBJPEG) - -set (INC_PATHS - ${INC_PATHS} - ${CMAKE_CURRENT_LIST_DIR} - ${JPEG_INCLUDE_DIR} - ) - -set(LIBS ${LIBS} ${JPEG_LIB}) diff --git a/wrappers/libpng/CMakeLists.txt b/wrappers/libpng/CMakeLists.txt new file mode 100644 index 000000000..06dafcc67 --- /dev/null +++ b/wrappers/libpng/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME wrappers) +init_project(PROJECT_NAME LIBPNGwrapper) + +set(PUBLIC_HEADER_FILE + libpngFileReader.h + ) + +set(HEADERS + ${PUBLIC_HEADER_FILE} + ) + +set(SOURCE_FILE + libpngFileReader.cpp + ) + +set(SOURCES + ${SOURCE_FILE} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_library(${PROJECT_NAME} SHARED + ${HEADERS} + ${SOURCES} + ) + +add_definitions(-DWITH_LIBPNG) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) + +target_link_libraries(${PROJECT_NAME} + PUBLIC + PNG::PNG + PRIVATE + corecvs + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/wrappers/libpng/libpngFileReader.h b/wrappers/libpng/libpngFileReader.h index c072806d1..1bbc0ff1f 100644 --- a/wrappers/libpng/libpngFileReader.h +++ b/wrappers/libpng/libpngFileReader.h @@ -4,14 +4,14 @@ #include #include -#include "core/utils/global.h" - -#include "core/fileformats/bufferLoader.h" -#include "core/buffers/bufferFactory.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/rgb24/rgbTBuffer.h" -#include "core/buffers/runtimeTypeBuffer.h" +#include "utils/global.h" + +#include "fileformats/bufferLoader.h" +#include "buffers/bufferFactory.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/rgb24/rgbTBuffer.h" +#include "buffers/runtimeTypeBuffer.h" using std::string; diff --git a/wrappers/libpng/sourcelist.cmake b/wrappers/libpng/sourcelist.cmake deleted file mode 100644 index dc46d185c..000000000 --- a/wrappers/libpng/sourcelist.cmake +++ /dev/null @@ -1,19 +0,0 @@ -set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/libpngFileReader.h -) - - -set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/libpngFileReader.cpp -) - -add_definitions(-DWITH_LIBPNG) -set (INC_PATHS - ${INC_PATHS} - ${CMAKE_CURRENT_LIST_DIR} - ${PNG_INCLUDE_DIR} - ) - -set(LIBS ${LIBS} ${PNG_LIB}) diff --git a/wrappers/opencv/CMakeLists.txt b/wrappers/opencv/CMakeLists.txt new file mode 100644 index 000000000..9a0e46701 --- /dev/null +++ b/wrappers/opencv/CMakeLists.txt @@ -0,0 +1,148 @@ +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME wrappers) +init_project(PROJECT_NAME OPENCVwrapper) + +find_package(Qt5 COMPONENTS REQUIRED Widgets) + +set (USE_PCAFLOW ON) + +set(PUBLIC_HEADER_FILES + featureDetectorCV.h + KLTFlow.h + openCvFileReader.h + openCVTools.h + semiGlobalBlockMatching.h + openCvCheckerboardDetector.h + #faceDetect/faceDetect.h + patternDetect/openCVSquareDetector.h + patternDetect/openCVCheckerBoardDetector.h + ) + +set(GENERATED_HEADER_FILES + generated/openCVKLTParameters.h + generated/openCVBMParameters.h + generated/openCVSGMParameters.h + generated/openCVSquareDetectorParameters.h + generated/openCVCheckerBoardDetectorParameters.h + ) + +#Disflow #redo by adding as library +set(DISFLOW_DIR ${CMAKE_CURRENT_LIST_DIR}/../../siblings/OF_DIS/) + +if(EXISTS "${DISFLOW_DIR}/oflow.cpp") + message("DISFLOW has been found at <${DISFLOW_DIR}>.") + set(DISFLOW_FOUND ON) +else() + set(DISFLOW_FOUND OFF) +endif() + +if(DISFLOW_FOUND) + add_definitions(-DWITH_DISFLOW) + set (DISFLOW_HDR_FILES + ${CMAKE_CURRENT_LIST_DIR}/DISFlow/DISFlow.h + ${CMAKE_CURRENT_LIST_DIR}/generated/disFlowParameters.h + ) +endif() + +if (USE_PCAFLOW) + set (PCAFLOW_HEADER_FILES + PCAFlow/PCAFlowProcessor.h + generated/openCVPCAFlowParameters.h + ) +endif() + +set(HEADERS + ${PUBLIC_HEADER_FILES} + ${GENERATED_HEADER_FILES} + ${DISFLOW_HDR_FILES} + ${PCAFLOW_HEADER_FILES} + ) + +set(SOURCE_FILES + openCVTools.cpp + openCvFileReader.cpp + KLTFlow.cpp + semiGlobalBlockMatching.cpp + openCvCheckerboardDetector.cpp + openCvImageRemapper.cpp + #faceDetect/faceDetect.cpp + patternDetect/openCVSquareDetector.cpp + patternDetect/openCVCheckerBoardDetector.cpp + ) + +set(GENERATED_SOURCE_FILES + generated/openCVKLTParameters.cpp + generated/openCVBMParameters.cpp + generated/openCVSGMParameters.cpp + generated/openCVSquareDetectorParameters.cpp + generated/openCVCheckerBoardDetectorParameters.cpp + ) + +if (DISFLOW_FOUND) + set (DISFLOW_SRC_FILES + ${CMAKE_CURRENT_LIST_DIR}/DISFlow/DISFlow.cpp + ${CMAKE_CURRENT_LIST_DIR}/generated/disFlowParameters.cpp + ) + + set (DISFLOW_SOURCE_FILES + ${DISFLOW_DIR}/oflow.cpp + ${DISFLOW_DIR}/patch.cpp + ${DISFLOW_DIR}/patchgrid.cpp + ${DISFLOW_DIR}/refine_variational.cpp + ${DISFLOW_DIR}/FDF1.0.1/image.c + ${DISFLOW_DIR}/FDF1.0.1/opticalflow_aux.c + ${DISFLOW_DIR}/FDF1.0.1/solver.c + ) + + set_source_files_properties(${DISFLOW_SOURCE_FILES} PROPERTIES COMPILE_DEFINITIONS "SELECTMODE=1; SELECTCHANNEL=3") +endif() + +if (USE_PCAFLOW) + set (PCAFLOW_SOURCE_FILES + PCAFlow/PCAFlowProcessor.cpp + generated/openCVPCAFlowParameters.cpp + ) +endif() + +set(SOURCES + ${SOURCE_FILES} + ${GENERATED_SOURCE_FILES} + ${DISFLOW_SRC_FILES} + ${DISFLOW_SOURCE_FILES} + ${PCAFLOW_SOURCE_FILES} + ) + +assign_source_group(${HEADERS} ${SOURCES}) + +add_library(${PROJECT_NAME} STATIC + ${HEADERS} + ${SOURCES} + ) + +set(ADDITIONAL_DIRS) + +if (DISFLOW_FOUND) + set(ADDITIONAL_DIRS + ${ADDITIONAL_DIRS} + ${EIGEN_INCLUDE_DIR} + ) +endif() + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${ADDITIONAL_DIRS} + ) + +target_link_libraries(${PROJECT_NAME} + PUBLIC + ${OpenCV_LIBS} + corecvs + Qt5::Widgets + ) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + AUTOUIC TRUE + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/wrappers/opencv/DISFlow/DISFlow.h b/wrappers/opencv/DISFlow/DISFlow.h index 49f61d804..a0a7192bf 100644 --- a/wrappers/opencv/DISFlow/DISFlow.h +++ b/wrappers/opencv/DISFlow/DISFlow.h @@ -7,7 +7,11 @@ #include #include #include -#include +# if defined (_MSC_VER) +# include +# else +# include +# endif #include #include diff --git a/wrappers/opencv/PCAFlow/PCAFlowProcessor.h b/wrappers/opencv/PCAFlow/PCAFlowProcessor.h index 9534c1fa9..98844202c 100644 --- a/wrappers/opencv/PCAFlow/PCAFlowProcessor.h +++ b/wrappers/opencv/PCAFlow/PCAFlowProcessor.h @@ -7,7 +7,7 @@ #include -#include "core/stereointerface/processor6D.h" +#include "stereointerface/processor6D.h" #include "generated/openCVPCAFlowParameters.h" using namespace corecvs; using namespace cv; diff --git a/wrappers/opencv/generated/openCVBMParameters.h b/wrappers/opencv/generated/openCVBMParameters.h index 0aee8acdc..9f6ca0597 100644 --- a/wrappers/opencv/generated/openCVBMParameters.h +++ b/wrappers/opencv/generated/openCVBMParameters.h @@ -9,9 +9,9 @@ * Generated from opencvsgm.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/wrappers/opencv/generated/openCVBMParametersControlWidget.h b/wrappers/opencv/generated/openCVBMParametersControlWidget.h index 4713d7944..54052d7c0 100644 --- a/wrappers/opencv/generated/openCVBMParametersControlWidget.h +++ b/wrappers/opencv/generated/openCVBMParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "openCVBMParameters.h" #include "ui_openCVBMParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "utils/corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/wrappers/opencv/generated/openCVKLTParameters.h b/wrappers/opencv/generated/openCVKLTParameters.h index 7fc25ef92..836ffad18 100644 --- a/wrappers/opencv/generated/openCVKLTParameters.h +++ b/wrappers/opencv/generated/openCVKLTParameters.h @@ -9,9 +9,9 @@ * Generated from opencv.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/wrappers/opencv/generated/openCVSGMParameters.h b/wrappers/opencv/generated/openCVSGMParameters.h index e14c8114e..effdbe5d4 100644 --- a/wrappers/opencv/generated/openCVSGMParameters.h +++ b/wrappers/opencv/generated/openCVSGMParameters.h @@ -9,9 +9,9 @@ * Generated from opencvsgm.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/wrappers/opencv/generated/openCVSGMParametersControlWidget.h b/wrappers/opencv/generated/openCVSGMParametersControlWidget.h index e12fda6ff..0d1b19ae3 100644 --- a/wrappers/opencv/generated/openCVSGMParametersControlWidget.h +++ b/wrappers/opencv/generated/openCVSGMParametersControlWidget.h @@ -2,7 +2,7 @@ #include #include "generated/openCVSGMParameters.h" #include "ui_openCVSGMParametersControlWidget.h" -#include "parametersControlWidgetBase.h" +#include "utils/corestructs/parametersControlWidgetBase.h" namespace Ui { diff --git a/wrappers/opencv/generated/openCVSquareDetectorParameters.h b/wrappers/opencv/generated/openCVSquareDetectorParameters.h index 857695399..2afbdd40a 100644 --- a/wrappers/opencv/generated/openCVSquareDetectorParameters.h +++ b/wrappers/opencv/generated/openCVSquareDetectorParameters.h @@ -9,9 +9,9 @@ * Generated from opencv.xml */ -#include "core/reflection/reflection.h" -#include "core/reflection/defaultSetter.h" -#include "core/reflection/printerVisitor.h" +#include "reflection/reflection.h" +#include "reflection/defaultSetter.h" +#include "reflection/printerVisitor.h" /* * Embed includes. diff --git a/wrappers/opencv/openCVTools.h b/wrappers/opencv/openCVTools.h index f23783bc0..4ffec636b 100644 --- a/wrappers/opencv/openCVTools.h +++ b/wrappers/opencv/openCVTools.h @@ -12,13 +12,13 @@ #include // CvSize, IplImage -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/buffers/g8Buffer.h" -#include "core/math/vector/vector2d.h" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/rgb24/rgb24Buffer.h" -#include "core/buffers/runtimeTypeBuffer.h" +#include "buffers/g8Buffer.h" +#include "math/vector/vector2d.h" +#include "buffers/g12Buffer.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/runtimeTypeBuffer.h" using corecvs::G12Buffer; using corecvs::G8Buffer; diff --git a/wrappers/opencv/openCvCheckerboardDetector.h b/wrappers/opencv/openCvCheckerboardDetector.h index c5b6cc92e..4848dd0a7 100644 --- a/wrappers/opencv/openCvCheckerboardDetector.h +++ b/wrappers/opencv/openCvCheckerboardDetector.h @@ -1,14 +1,14 @@ #pragma once -#include "core/math/vector/vector2d.h" -#include "core/math/vector/vector3d.h" +#include "math/vector/vector2d.h" +#include "math/vector/vector3d.h" -#include "core/patterndetection/patternDetector.h" -#include "core/patterndetection/boardAligner.h" -#include "core/xml/generated/checkerboardDetectionParameters.h" +#include "patterndetection/patternDetector.h" +#include "patterndetection/boardAligner.h" +#include "xml/generated/checkerboardDetectionParameters.h" -#include // Point2f +#include // Point2f class OpenCvCheckerboardDetector : public corecvs::PatternGeometryDetector , protected CheckerboardDetectionParameters diff --git a/wrappers/opencv/openCvFileReader.cpp b/wrappers/opencv/openCvFileReader.cpp index 74fe47848..1fe22a099 100644 --- a/wrappers/opencv/openCvFileReader.cpp +++ b/wrappers/opencv/openCvFileReader.cpp @@ -1,4 +1,4 @@ -#include "core/utils/utils.h" +#include "utils/utils.h" #include "openCvFileReader.h" #include "openCVTools.h" @@ -105,7 +105,6 @@ RGB24Buffer *OpenCVRGB24Loader::load(const std::string & name) } return OpenCVTools::getRGB24BufferFromCVMat(img); } - OpenCVRuntimeTypeBufferLoader::OpenCVRuntimeTypeBufferLoader() {} diff --git a/wrappers/opencv/openCvImageRemapper.cpp b/wrappers/opencv/openCvImageRemapper.cpp index f555982c4..4bff33e50 100644 --- a/wrappers/opencv/openCvImageRemapper.cpp +++ b/wrappers/opencv/openCvImageRemapper.cpp @@ -1,5 +1,6 @@ #include "opencv2/imgproc/imgproc.hpp" -#include "openCvImageRemapper.h" +#include "buffers/rgb24/rgb24Buffer.h" +#include "buffers/displacementBuffer.h" #ifdef WITH_OPENCV_GPU #include diff --git a/wrappers/opencv/openCvImageRemapper.h b/wrappers/opencv/openCvImageRemapper.h index 8d11b32cd..ff93509d8 100644 --- a/wrappers/opencv/openCvImageRemapper.h +++ b/wrappers/opencv/openCvImageRemapper.h @@ -68,5 +68,5 @@ typedef struct OpenCLRemapCache #endif void remap( corecvs::RGB24Buffer &src, corecvs::RGB24Buffer &dst, const corecvs::DisplacementBuffer &transform ); -}; + diff --git a/wrappers/opencv/patternDetect/openCVSquareDetector.h b/wrappers/opencv/patternDetect/openCVSquareDetector.h index 83d9c7d84..ec0787dbd 100644 --- a/wrappers/opencv/patternDetect/openCVSquareDetector.h +++ b/wrappers/opencv/patternDetect/openCVSquareDetector.h @@ -3,12 +3,12 @@ #include -#include +#include -#include -#include +#include +#include #include -#include "../generated/openCVSquareDetectorParameters.h" +#include "generated/openCVSquareDetectorParameters.h" class OpenCVSquareDetector : public corecvs::PatternDetector diff --git a/wrappers/opencv/semiGlobalBlockMatching.h b/wrappers/opencv/semiGlobalBlockMatching.h index 6120b2d83..a7304a81b 100644 --- a/wrappers/opencv/semiGlobalBlockMatching.h +++ b/wrappers/opencv/semiGlobalBlockMatching.h @@ -3,9 +3,9 @@ #include "opencv2/calib3d/calib3d.hpp" -#include "core/buffers/g12Buffer.h" -#include "core/buffers/flow/flowBuffer.h" -#include "core/math/vector/vector2d.h" +#include "buffers/g12Buffer.h" +#include "buffers/flow/flowBuffer.h" +#include "math/vector/vector2d.h" #include "generated/openCVSGMParameters.h" #include "generated/openCVBMParameters.h" diff --git a/wrappers/opencv/sourcelist.cmake b/wrappers/opencv/sourcelist.cmake deleted file mode 100644 index 7e9ef5015..000000000 --- a/wrappers/opencv/sourcelist.cmake +++ /dev/null @@ -1,124 +0,0 @@ -#project (OpenCVJSONWrapper) - -message(STATUS "Including OpenCVWrapper") - -set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/featureDetectorCV.h - ${CMAKE_CURRENT_LIST_DIR}/KLTFlow.h - ${CMAKE_CURRENT_LIST_DIR}/openCvFileReader.h - ${CMAKE_CURRENT_LIST_DIR}/openCVTools.h - ${CMAKE_CURRENT_LIST_DIR}/semiGlobalBlockMatching.h - ${CMAKE_CURRENT_LIST_DIR}/openCvCheckerboardDetector.h - ${CMAKE_CURRENT_LIST_DIR}/patternDetect/openCVSquareDetector.h - ${CMAKE_CURRENT_LIST_DIR}/patternDetect/openCVCheckerBoardDetector.h - -) - -set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/openCVTools.cpp - ${CMAKE_CURRENT_LIST_DIR}/openCvFileReader.cpp - ${CMAKE_CURRENT_LIST_DIR}/KLTFlow.cpp - ${CMAKE_CURRENT_LIST_DIR}/semiGlobalBlockMatching.cpp - ${CMAKE_CURRENT_LIST_DIR}/openCvCheckerboardDetector.cpp - ${CMAKE_CURRENT_LIST_DIR}/openCvImageRemapper.cpp - ${CMAKE_CURRENT_LIST_DIR}/patternDetect/openCVSquareDetector.cpp - ${CMAKE_CURRENT_LIST_DIR}/patternDetect/openCVCheckerBoardDetector.cpp - -) - - -# Generated block - -set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVKLTParameters.h - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVBMParameters.h - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVSGMParameters.h - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVSquareDetectorParameters.h - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVCheckerBoardDetectorParameters.h - -) - -set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVKLTParameters.cpp - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVBMParameters.cpp - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVSGMParameters.cpp - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVSquareDetectorParameters.cpp - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVCheckerBoardDetectorParameters.cpp -) - -# Disflow -set (DISFLOW_DIR ${CMAKE_CURRENT_LIST_DIR}/../../siblings/OF_DIS/) - -if(EXISTS "${DISFLOW_DIR}/oflow.cpp") - message("DISFLOW has been found at <${DISFLOW_DIR}>.") - SET(DISFLOW_FOUND ON) -else() - SET(DISFLOW_FOUND OFF) -endif() - - -if (DISFLOW_FOUND) - add_definitions(-DWITH_DISFLOW) - - set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/DISFlow/DISFlow.h - ${CMAKE_CURRENT_LIST_DIR}/generated/disFlowParameters.h - ) - - set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/DISFlow/DISFlow.cpp - ${CMAKE_CURRENT_LIST_DIR}/generated/disFlowParameters.cpp - ) - - set (DISFLOW_SRC_FILES - ${DISFLOW_DIR}/oflow.cpp - ${DISFLOW_DIR}/patch.cpp - ${DISFLOW_DIR}/patchgrid.cpp - ${DISFLOW_DIR}/refine_variational.cpp - ${DISFLOW_DIR}/FDF1.0.1/image.c - ${DISFLOW_DIR}/FDF1.0.1/opticalflow_aux.c - ${DISFLOW_DIR}/FDF1.0.1/solver.c - ) - - include_directories(PUBLIC ${EIGEN_INCLUDE_DIR}) - set_source_files_properties(${DISFLOW_SRC_FILES} PROPERTIES COMPILE_DEFINITIONS "SELECTMODE=1; SELECTCHANNEL=3") - - set (SRC_FILES - ${SRC_FILES} - ${DISFLOW_SRC_FILES} - ) -endif() - - -set (USE_PCAFLOW ON) -if (USE_PCAFLOW) - - set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/PCAFlow/PCAFlowProcessor.h - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVPCAFlowParameters.h - ) - - set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/PCAFlow/PCAFlowProcessor.cpp - ${CMAKE_CURRENT_LIST_DIR}/generated/openCVPCAFlowParameters.cpp - ) - - include_directories(PUBLIC ${CMAKE_CURRENT_LIST_DIR}/PCAFlow) - -endif() - - - - -include_directories(${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/patternDetect) -include_directories(PUBLIC ${OpenCV_INCLUDE_DIRS}) -link_libraries(${MODULE_NAME} ${OpenCV_LIBS}) - diff --git a/wrappers/v4l2/CMakeLists.txt b/wrappers/v4l2/CMakeLists.txt index 6808ffc1b..328449e3a 100644 --- a/wrappers/v4l2/CMakeLists.txt +++ b/wrappers/v4l2/CMakeLists.txt @@ -1,35 +1,52 @@ -#project (V4L2Wrapper) +cmake_minimum_required(VERSION 3.11) +set(MODULE_NAME wrappers) +init_project(PROJECT_NAME V4L2wrapper) + +find_package(Qt5 COMPONENTS REQUIRED Core) #Gui Widgets Script Xml SerialPort) message(STATUS "Including V4L2Wrapper") -set (HEADERS - ${HEADERS} - ${CMAKE_CURRENT_LIST_DIR}/V4L2CaptureDecouple.h - ${CMAKE_CURRENT_LIST_DIR}/V4L2Capture.h - ${CMAKE_CURRENT_LIST_DIR}/wrappers/v4l2/V4L2.h -) +set(PUBLIC_HEADER_FILES + V4L2CaptureDecouple.h + V4L2Capture.h + V4L2.h + ) -set (SOURCES - ${SOURCES} - ${CMAKE_CURRENT_LIST_DIR}/V4L2CaptureDecouple.cpp - ${CMAKE_CURRENT_LIST_DIR}/V4L2Capture.cpp - ${CMAKE_CURRENT_LIST_DIR}/wrappers/v4l2/V4L2.cpp -) - -set (INCLUDEPATHS - ${INCLUDEPATHS} - ${CMAKE_CURRENT_LIST_DIR} -) - -set (LIBS - ${LIBS} - v4l2 -) +set(HEADERS + ${PUBLIC_HEADER_FILES} + ) -include_directories(${INCLUDEPATHS}) -add_definitions( -DWITH_LIBJPEG ) +set (SOURCE_FILES + V4L2CaptureDecouple.cpp + V4L2Capture.cpp + V4L2.cpp + ) +set(SOURCES + ${SOURCE_FILES} + ) +assign_source_group(${HEADERS} ${SOURCES}) +add_library(${PROJECT_NAME} SHARED + ${HEADERS} + ${SOURCES} + ) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) +target_link_libraries(${PROJECT_NAME} + corecvs + v4l2 + Qt5::Core + ) + +add_definitions( -DWITH_LIBJPEG ) +set_target_properties(${PROJECT_NAME} + PROPERTIES + FOLDER "${MODULE_NAME}" + ) \ No newline at end of file diff --git a/wrappers/v4l2/V4L2CaptureDecouple.h b/wrappers/v4l2/V4L2CaptureDecouple.h index 54f02e68c..2c1270205 100644 --- a/wrappers/v4l2/V4L2CaptureDecouple.h +++ b/wrappers/v4l2/V4L2CaptureDecouple.h @@ -11,12 +11,12 @@ #include #include -#include "core/utils/global.h" +#include "utils/global.h" -#include "core/utils/preciseTimer.h" -#include "core/framesources/imageCaptureInterface.h" -#include "core/framesources/cameraControlParameters.h" -#include "core/framesources/decoders/decoupleYUYV.h" +#include "utils/preciseTimer.h" +#include "framesources/imageCaptureInterface.h" +#include "framesources/cameraControlParameters.h" +#include "framesources/decoders/decoupleYUYV.h" #include "V4L2Capture.h" #include "V4L2.h" diff --git a/wrappers/v4l2/sourcelist.cmake b/wrappers/v4l2/sourcelist.cmake deleted file mode 100644 index d51b015c1..000000000 --- a/wrappers/v4l2/sourcelist.cmake +++ /dev/null @@ -1,16 +0,0 @@ -set (HDR_FILES - ${HDR_FILES} - ${CMAKE_CURRENT_LIST_DIR}/V4L2CaptureDecouple.h - ${CMAKE_CURRENT_LIST_DIR}/V4L2Capture.h - ${CMAKE_CURRENT_LIST_DIR}/V4L2.h -) - - -set (SRC_FILES - ${SRC_FILES} - ${CMAKE_CURRENT_LIST_DIR}/V4L2CaptureDecouple.cpp - ${CMAKE_CURRENT_LIST_DIR}/V4L2Capture.cpp - ${CMAKE_CURRENT_LIST_DIR}/V4L2.cpp -) - -add_definitions(-DWITH_V4L2)