diff --git a/OpenFace.sln b/OpenFace.sln
index d1fd2932..8e670276 100644
--- a/OpenFace.sln
+++ b/OpenFace.sln
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dlib", "lib\3rdParty\dlib\dlib.vcxproj", "{B47A5F12-2567-44E9-AE49-35763EC82149}"
-EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LandmarkDetector", "lib\local\LandmarkDetector\LandmarkDetector.vcxproj", "{BDC1D107-DE17-4705-8E7B-CDDE8BFB2BF8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FaceAnalyser", "lib\local\FaceAnalyser\FaceAnalyser.vcxproj", "{0E7FC556-0E80-45EA-A876-DDE4C2FEDCD7}"
@@ -49,14 +47,6 @@ Global
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {B47A5F12-2567-44E9-AE49-35763EC82149}.Debug|Win32.ActiveCfg = Debug|Win32
- {B47A5F12-2567-44E9-AE49-35763EC82149}.Debug|Win32.Build.0 = Debug|Win32
- {B47A5F12-2567-44E9-AE49-35763EC82149}.Debug|x64.ActiveCfg = Debug|x64
- {B47A5F12-2567-44E9-AE49-35763EC82149}.Debug|x64.Build.0 = Debug|x64
- {B47A5F12-2567-44E9-AE49-35763EC82149}.Release|Win32.ActiveCfg = Release|Win32
- {B47A5F12-2567-44E9-AE49-35763EC82149}.Release|Win32.Build.0 = Release|Win32
- {B47A5F12-2567-44E9-AE49-35763EC82149}.Release|x64.ActiveCfg = Release|x64
- {B47A5F12-2567-44E9-AE49-35763EC82149}.Release|x64.Build.0 = Release|x64
{BDC1D107-DE17-4705-8E7B-CDDE8BFB2BF8}.Debug|Win32.ActiveCfg = Debug|Win32
{BDC1D107-DE17-4705-8E7B-CDDE8BFB2BF8}.Debug|Win32.Build.0 = Debug|Win32
{BDC1D107-DE17-4705-8E7B-CDDE8BFB2BF8}.Debug|x64.ActiveCfg = Debug|x64
@@ -174,7 +164,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
- {B47A5F12-2567-44E9-AE49-35763EC82149} = {652CCE53-4997-4B43-9A99-28D075199C99}
{BDC1D107-DE17-4705-8E7B-CDDE8BFB2BF8} = {99FEBA13-BDDF-4076-B57E-D8EF4076E20D}
{0E7FC556-0E80-45EA-A876-DDE4C2FEDCD7} = {99FEBA13-BDDF-4076-B57E-D8EF4076E20D}
{8A23C00D-767D-422D-89A3-CF225E3DAB4B} = {9961DDAC-BE6E-4A6E-8EEF-FFC7D67BD631}
diff --git a/lib/3rdParty/dlib/CMakeLists.txt b/lib/3rdParty/dlib/CMakeLists.txt
deleted file mode 100644
index 8db4ea91..00000000
--- a/lib/3rdParty/dlib/CMakeLists.txt
+++ /dev/null
@@ -1,432 +0,0 @@
-#
-# This is a CMake makefile. You can find the cmake utility and
-# information about it at http://www.cmake.org
-#
-
-# setting this makes CMake allow normal looking if else statements
-SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
-
-cmake_minimum_required(VERSION 2.4)
-
-# Suppress cmake warnings about changes in new versions.
-if(COMMAND cmake_policy)
- cmake_policy(SET CMP0003 NEW)
-endif()
-
-add_definitions(-DDLIB_HAVE_SSE2)
-add_definitions(-DDLIB_HAVE_SSE3)
-add_definitions(-DDLIB_HAVE_SSE41)
-
-# make macros that can add #define directives to the entire project. Not just
-# to the dlib library itself. I.e. to dlib and to any projects that depend
-# on dlib.
-macro ( add_global_define def_name )
- if (NOT CMAKE_CXX_FLAGS MATCHES "-D${def_name}")
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${def_name}"
- CACHE STRING "Flags used by the compiler during all C++ builds."
- FORCE)
- endif ()
-endmacro()
-macro ( remove_global_define def_name )
- if (CMAKE_CXX_FLAGS MATCHES " -D${def_name}")
- string (REGEX REPLACE " -D${def_name}" "" temp_var ${CMAKE_CXX_FLAGS})
- set (CMAKE_CXX_FLAGS "${temp_var}"
- CACHE STRING "Flags used by the compiler during all C++ builds."
- FORCE)
- endif ()
-endmacro()
-
-
-# Make sure ENABLE_ASSERTS is defined for debug builds
-if (NOT CMAKE_CXX_FLAGS_DEBUG MATCHES "-DENABLE_ASSERTS")
- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DENABLE_ASSERTS"
- CACHE STRING "Flags used by the compiler during C++ debug builds."
- FORCE)
-endif ()
-
-
-# Don't try to call add_library(dlib) and setup dlib's stuff if it has already
-# been done by some other part of the current cmake project. We do this
-# because it avoids getting warnings/errors about cmake policy CMP0002. This
-# happens when a project tries to call add_subdirectory() on dlib more than
-# once. This most often happens when the top level of a project depends on two
-# or more other things which both depend on dlib.
-if (NOT TARGET dlib)
-
- set (DLIB_ISO_CPP_ONLY_STR
- "Enable this if you don't want to compile any non-ISO C++ code (i.e. you don't use any of the API Wrappers)" )
- set (DLIB_NO_GUI_SUPPORT_STR
- "Enable this if you don't want to compile any of the dlib GUI code" )
- set (DLIB_ENABLE_STACK_TRACE_STR
- "Enable this if you want to turn on the DLIB_STACK_TRACE macros" )
- set (DLIB_ENABLE_ASSERTS_STR
- "Enable this if you want to turn on the DLIB_ASSERT macro" )
- set (DLIB_USE_BLAS_STR
- "Disable this if you don't want to use a BLAS library" )
- set (DLIB_USE_LAPACK_STR
- "Disable this if you don't want to use a LAPACK library" )
- set (DLIB_LINK_WITH_LIBPNG_STR
- "Disable this if you don't want to link against libpng" )
- set (DLIB_LINK_WITH_LIBJPEG_STR
- "Disable this if you don't want to link against libjpeg" )
- set (DLIB_LINK_WITH_SQLITE3_STR
- "Disable this if you don't want to link against sqlite3" )
- set (DLIB_LINK_WITH_FFTW_STR
- "Disable this if you don't want to link against fftw" )
-
- option(DLIB_ISO_CPP_ONLY ${DLIB_ISO_CPP_ONLY_STR} OFF)
- option(DLIB_NO_GUI_SUPPORT ${DLIB_NO_GUI_SUPPORT_STR} OFF)
- option(DLIB_ENABLE_STACK_TRACE ${DLIB_ENABLE_STACK_TRACE_STR} OFF)
- option(DLIB_ENABLE_ASSERTS ${DLIB_ENABLE_ASSERTS_STR} OFF)
- option(DLIB_USE_BLAS ${DLIB_USE_BLAS_STR} ON)
- option(DLIB_USE_LAPACK ${DLIB_USE_LAPACK_STR} ON)
- option(DLIB_LINK_WITH_LIBPNG ${DLIB_LINK_WITH_LIBPNG_STR} ON)
- option(DLIB_LINK_WITH_LIBJPEG ${DLIB_LINK_WITH_LIBJPEG_STR} ON)
- option(DLIB_LINK_WITH_SQLITE3 ${DLIB_LINK_WITH_SQLITE3_STR} ON)
- option(DLIB_LINK_WITH_FFTW ${DLIB_LINK_WITH_FFTW_STR} ON)
-
- set(source_files
- include/dlib/base64/base64_kernel_1.cpp
- include/dlib/bigint/bigint_kernel_1.cpp
- include/dlib/bigint/bigint_kernel_2.cpp
- include/dlib/bit_stream/bit_stream_kernel_1.cpp
- include/dlib/entropy_decoder/entropy_decoder_kernel_1.cpp
- include/dlib/entropy_decoder/entropy_decoder_kernel_2.cpp
- include/dlib/entropy_encoder/entropy_encoder_kernel_1.cpp
- include/dlib/entropy_encoder/entropy_encoder_kernel_2.cpp
- include/dlib/md5/md5_kernel_1.cpp
- include/dlib/tokenizer/tokenizer_kernel_1.cpp
- include/dlib/unicode/unicode.cpp
- include/dlib/data_io/image_dataset_metadata.cpp)
-
- if (DLIB_ISO_CPP_ONLY)
- add_library(dlib STATIC ${source_files} )
- else()
-
- set(source_files ${source_files}
- include/dlib/sockets/sockets_kernel_1.cpp
- include/dlib/bsp/bsp.cpp
- include/dlib/dir_nav/dir_nav_kernel_1.cpp
- include/dlib/dir_nav/dir_nav_kernel_2.cpp
- include/dlib/dir_nav/dir_nav_extensions.cpp
- include/dlib/linker/linker_kernel_1.cpp
- include/dlib/logger/extra_logger_headers.cpp
- include/dlib/logger/logger_kernel_1.cpp
- include/dlib/logger/logger_config_file.cpp
- include/dlib/misc_api/misc_api_kernel_1.cpp
- include/dlib/misc_api/misc_api_kernel_2.cpp
- include/dlib/sockets/sockets_extensions.cpp
- include/dlib/sockets/sockets_kernel_2.cpp
- include/dlib/sockstreambuf/sockstreambuf.cpp
- include/dlib/sockstreambuf/sockstreambuf_unbuffered.cpp
- include/dlib/server/server_kernel.cpp
- include/dlib/server/server_iostream.cpp
- include/dlib/server/server_http.cpp
- include/dlib/threads/multithreaded_object_extension.cpp
- include/dlib/threads/threaded_object_extension.cpp
- include/dlib/threads/threads_kernel_1.cpp
- include/dlib/threads/threads_kernel_2.cpp
- include/dlib/threads/threads_kernel_shared.cpp
- include/dlib/threads/thread_pool_extension.cpp
- include/dlib/timer/timer.cpp
- include/dlib/stack_trace.cpp
- )
-
- # we want to link to the right stuff depending on our platform.
- if (WIN32 AND NOT CYGWIN) ###############################################################################
- if (DLIB_NO_GUI_SUPPORT)
- set (dlib_needed_libraries ws2_32)
- else()
- set (dlib_needed_libraries ws2_32 comctl32 gdi32 imm32)
- endif()
- elseif(APPLE) ############################################################################
- find_library(pthreadlib pthread)
- set (dlib_needed_libraries ${pthreadlib})
-
- if (NOT DLIB_NO_GUI_SUPPORT)
- find_library(xlib X11)
- # make sure X11 is in the include path
- find_path(xlib_path Xlib.h
- PATHS
- /Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include
- PATH_SUFFIXES X11
- )
- if (xlib AND xlib_path)
- get_filename_component(x11_path ${xlib_path} PATH CACHE)
- include_directories(${x11_path})
- set(dlib_needed_libraries ${dlib_needed_libraries} ${xlib} )
- else()
- message(" *****************************************************************************")
- message(" *** DLIB GUI SUPPORT DISABLED BECAUSE X11 DEVELOPMENT LIBRARIES NOT FOUND ***")
- message(" *** Make sure libx11-dev is installed if you want GUI support ***")
- message(" *****************************************************************************")
- set(DLIB_NO_GUI_SUPPORT ON CACHE STRING ${DLIB_NO_GUI_SUPPORT_STR} FORCE )
- endif()
- endif()
-
- mark_as_advanced(pthreadlib xlib xlib_path x11_path)
- else () ##################################################################################
- find_library(pthreadlib pthread)
- set (dlib_needed_libraries ${pthreadlib})
-
- # link to the nsl library if it exists. this is something you need sometimes
- find_library(nsllib nsl)
- if (nsllib)
- set (dlib_needed_libraries ${dlib_needed_libraries} ${nsllib})
- endif ()
-
- # link to the socket library if it exists. this is something you need on solaris
- find_library(socketlib socket)
- if (socketlib)
- set (dlib_needed_libraries ${dlib_needed_libraries} ${socketlib})
- endif ()
-
- if (NOT DLIB_NO_GUI_SUPPORT)
- include(FindX11)
- if (X11_FOUND)
- include_directories(${X11_INCLUDE_DIR})
- set (dlib_needed_libraries ${dlib_needed_libraries} ${X11_LIBRARIES})
- else()
- message(" *****************************************************************************")
- message(" *** DLIB GUI SUPPORT DISABLED BECAUSE X11 DEVELOPMENT LIBRARIES NOT FOUND ***")
- message(" *** Make sure libx11-dev is installed if you want GUI support ***")
- message(" *****************************************************************************")
- set(DLIB_NO_GUI_SUPPORT ON CACHE STRING ${DLIB_NO_GUI_SUPPORT_STR} FORCE )
- endif()
- endif()
-
- mark_as_advanced(nsllib pthreadlib socketlib)
- endif () ##################################################################################
-
- if (NOT DLIB_NO_GUI_SUPPORT)
- set(source_files ${source_files}
- include/dlib/gui_widgets/fonts.cpp
- include/dlib/gui_widgets/widgets.cpp
- include/dlib/gui_widgets/drawable.cpp
- include/dlib/gui_widgets/canvas_drawing.cpp
- include/dlib/gui_widgets/style.cpp
- include/dlib/gui_widgets/base_widgets.cpp
- include/dlib/gui_core/gui_core_kernel_1.cpp
- include/dlib/gui_core/gui_core_kernel_2.cpp
- )
- endif()
-
-
- if (DLIB_LINK_WITH_LIBPNG)
- # try to find libpng
- set(ZLIB_FIND_QUIETLY ON)
- set(PNG_FIND_QUIETLY ON)
- include(FindPNG)
- if (PNG_FOUND)
- include_directories(${PNG_INCLUDE_DIR})
- set (dlib_needed_libraries ${dlib_needed_libraries} ${PNG_LIBRARY})
- else()
- # If we can't find libpng then statically compile it in.
- include_directories(external/libpng external/zlib)
- set(source_files ${source_files}
- include/dlib/external/libpng/png.c
- include/dlib/external/libpng/pngerror.c
- include/dlib/external/libpng/pngget.c
- include/dlib/external/libpng/pngmem.c
- include/dlib/external/libpng/pngpread.c
- include/dlib/external/libpng/pngread.c
- include/dlib/external/libpng/pngrio.c
- include/dlib/external/libpng/pngrtran.c
- include/dlib/external/libpng/pngrutil.c
- include/dlib/external/libpng/pngset.c
- include/dlib/external/libpng/pngtrans.c
- include/dlib/external/libpng/pngwio.c
- include/dlib/external/libpng/pngwrite.c
- include/dlib/external/libpng/pngwtran.c
- include/dlib/external/libpng/pngwutil.c
- include/dlib/external/zlib/adler32.c
- include/dlib/external/zlib/compress.c
- include/dlib/external/zlib/crc32.c
- include/dlib/external/zlib/deflate.c
- include/dlib/external/zlib/gzclose.c
- include/dlib/external/zlib/gzlib.c
- include/dlib/external/zlib/gzread.c
- include/dlib/external/zlib/gzwrite.c
- include/dlib/external/zlib/infback.c
- include/dlib/external/zlib/inffast.c
- include/dlib/external/zlib/inflate.c
- include/dlib/external/zlib/inftrees.c
- include/dlib/external/zlib/trees.c
- include/dlib/external/zlib/uncompr.c
- include/dlib/external/zlib/zutil.c
- )
- endif()
- set(source_files ${source_files}
- include/dlib/image_loader/png_loader.cpp
- include/dlib/image_saver/save_png.cpp
- )
- endif()
-
- if (DLIB_LINK_WITH_LIBJPEG)
- # try to find libjpeg
- include(FindJPEG)
- if (JPEG_FOUND)
- include_directories(${JPEG_INCLUDE_DIR})
- set (dlib_needed_libraries ${dlib_needed_libraries} ${JPEG_LIBRARY})
- else()
- # If we can't find libjpeg then statically compile it in.
- include_directories(external/libjpeg)
- set(source_files ${source_files}
- include/dlib/external/libjpeg/jcomapi.cpp
- include/dlib/external/libjpeg/jdapimin.cpp
- include/dlib/external/libjpeg/jdapistd.cpp
- include/dlib/external/libjpeg/jdatasrc.cpp
- include/dlib/external/libjpeg/jdcoefct.cpp
- include/dlib/external/libjpeg/jdcolor.cpp
- include/dlib/external/libjpeg/jddctmgr.cpp
- include/dlib/external/libjpeg/jdhuff.cpp
- include/dlib/external/libjpeg/jdinput.cpp
- include/dlib/external/libjpeg/jdmainct.cpp
- include/dlib/external/libjpeg/jdmarker.cpp
- include/dlib/external/libjpeg/jdmaster.cpp
- include/dlib/external/libjpeg/jdmerge.cpp
- include/dlib/external/libjpeg/jdphuff.cpp
- include/dlib/external/libjpeg/jdpostct.cpp
- include/dlib/external/libjpeg/jdsample.cpp
- include/dlib/external/libjpeg/jerror.cpp
- include/dlib/external/libjpeg/jidctflt.cpp
- include/dlib/external/libjpeg/jidctfst.cpp
- include/dlib/external/libjpeg/jidctint.cpp
- include/dlib/external/libjpeg/jidctred.cpp
- include/dlib/external/libjpeg/jmemmgr.cpp
- include/dlib/external/libjpeg/jmemnobs.cpp
- include/dlib/external/libjpeg/jquant1.cpp
- include/dlib/external/libjpeg/jquant2.cpp
- include/dlib/external/libjpeg/jutils.cpp )
- endif()
- set(source_files ${source_files}
- include/dlib/image_loader/jpeg_loader.cpp
- )
- endif()
-
-
- if (DLIB_USE_BLAS OR DLIB_USE_LAPACK)
- # Try to find BLAS and LAPACK
- include(cmake_find_blas.txt)
-
- if (DLIB_USE_BLAS)
- if (blas_found)
- set (dlib_needed_libraries ${dlib_needed_libraries} ${blas_libraries})
- else()
- set(DLIB_USE_BLAS OFF CACHE STRING ${DLIB_USE_BLAS_STR} FORCE )
- endif()
- endif()
-
- if (DLIB_USE_LAPACK)
- if (lapack_found)
- set (dlib_needed_libraries ${dlib_needed_libraries} ${lapack_libraries})
- else()
- set(DLIB_USE_LAPACK OFF CACHE STRING ${DLIB_USE_LAPACK_STR} FORCE )
- endif()
- endif()
- endif()
-
-
-
- if (DLIB_LINK_WITH_SQLITE3)
- find_library(sqlite sqlite3)
- # make sure sqlite3.h is in the include path
- find_path(sqlite_path sqlite3.h)
- if (sqlite AND sqlite_path)
- get_filename_component(sqlite_path2 ${sqlite_path} PATH CACHE)
- include_directories(${sqlite_path2})
- set(dlib_needed_libraries ${dlib_needed_libraries} ${sqlite} )
- else()
- set(DLIB_LINK_WITH_SQLITE3 OFF CACHE STRING ${DLIB_LINK_WITH_SQLITE3_STR} FORCE )
- endif()
- mark_as_advanced(sqlite sqlite_path sqlite_path2)
- endif()
-
-
-
- if (DLIB_LINK_WITH_FFTW)
- find_library(fftw fftw3)
- # make sure fftw3.h is in the include path
- find_path(fftw_path fftw3.h)
- if (fftw AND fftw_path)
- get_filename_component(fftw_path2 ${fftw_path} PATH CACHE)
- include_directories(${fftw_path2})
- set(dlib_needed_libraries ${dlib_needed_libraries} ${fftw} )
- else()
- set(DLIB_LINK_WITH_FFTW OFF CACHE STRING ${DLIB_LINK_WITH_SQLITE3_STR} FORCE )
- endif()
- mark_as_advanced(fftw fftw_path fftw_path2)
- endif()
-
-
- add_library(dlib STATIC ${source_files} )
- target_link_libraries(dlib ${dlib_needed_libraries} )
-
- endif () ##### end of if NOT DLIB_ISO_CPP_ONLY ##########################################################
-
-
- #test for some things that really should be true about the compiler
- include(TestForSTDNamespace)
- include(TestForANSIStreamHeaders)
-
-
- if (DLIB_LINK_WITH_LIBPNG AND NOT DLIB_ISO_CPP_ONLY)
- add_global_define(DLIB_PNG_SUPPORT)
- else()
- remove_global_define(DLIB_PNG_SUPPORT)
- endif()
-
- if (DLIB_LINK_WITH_LIBJPEG AND NOT DLIB_ISO_CPP_ONLY)
- add_global_define(DLIB_JPEG_SUPPORT)
- else()
- remove_global_define(DLIB_JPEG_SUPPORT)
- endif()
-
- if (DLIB_LINK_WITH_FFTW AND NOT DLIB_ISO_CPP_ONLY)
- add_global_define(DLIB_USE_FFTW)
- else()
- remove_global_define(DLIB_USE_FFTW)
- endif()
-
-
- if (DLIB_USE_BLAS AND blas_found)
- add_global_define(DLIB_USE_BLAS)
- else()
- remove_global_define(DLIB_USE_BLAS)
- endif()
-
- if (DLIB_USE_LAPACK AND lapack_found)
- add_global_define(DLIB_USE_LAPACK)
- else()
- remove_global_define(DLIB_USE_LAPACK)
- endif()
-
-
- if (DLIB_ISO_CPP_ONLY)
- add_global_define(DLIB_ISO_CPP_ONLY)
- else()
- remove_global_define(DLIB_ISO_CPP_ONLY)
- endif()
-
-
- if (DLIB_NO_GUI_SUPPORT)
- add_global_define(DLIB_NO_GUI_SUPPORT)
- else()
- remove_global_define(DLIB_NO_GUI_SUPPORT)
- endif()
-
- if (DLIB_ENABLE_STACK_TRACE)
- add_global_define(DLIB_ENABLE_STACK_TRACE)
- else()
- remove_global_define(DLIB_ENABLE_STACK_TRACE)
- endif()
-
-
- if (DLIB_ENABLE_ASSERTS)
- add_global_define(ENABLE_ASSERTS)
- else()
- remove_global_define(ENABLE_ASSERTS)
- endif()
-
-
-endif()
\ No newline at end of file
diff --git a/lib/3rdParty/dlib/cmake_find_blas.txt b/lib/3rdParty/dlib/cmake_find_blas.txt
deleted file mode 100644
index 27e0543a..00000000
--- a/lib/3rdParty/dlib/cmake_find_blas.txt
+++ /dev/null
@@ -1,227 +0,0 @@
-#
-# This is a CMake makefile. You can find the cmake utility and
-# information about it at http://www.cmake.org
-#
-#
-# This cmake file tries to find installed BLAS and LAPACK libraries.
-# It looks for an installed copy of the Intel MKL library first and then
-# attempts to find some other BLAS and LAPACK libraries if you don't have
-# the Intel MKL.
-#
-# blas_found - True if BLAS is available
-# lapack_found - True if LAPACK is available
-# blas_libraries - link against these to use BLAS library
-# lapack_libraries - link against these to use LAPACK library
-
-# setting this makes CMake allow normal looking if else statements
-SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
-
-SET(blas_found 0)
-SET(lapack_found 0)
-
-
-if (UNIX)
- message(STATUS "Searching for BLAS and LAPACK")
-
- include(CheckTypeSize)
- check_type_size( "void*" SIZE_OF_VOID_PTR)
-
- if (SIZE_OF_VOID_PTR EQUAL 8)
- set( mkl_search_path
- /opt/intel/mkl/*/lib/em64t
- /opt/intel/mkl/lib/intel64
- /opt/intel/lib/intel64
- )
-
- find_library(mkl_intel mkl_intel_lp64 ${mkl_search_path})
- else()
- set( mkl_search_path
- /opt/intel/mkl/*/lib/32
- /opt/intel/mkl/lib/ia32
- /opt/intel/lib/ia32
- )
-
- find_library(mkl_intel mkl_intel ${mkl_search_path})
- endif()
-
- include(CheckLibraryExists)
-
-
- # Search for the needed libraries from the MKL. We will try to link against the mkl_rt
- # file first since this way avoids linking bugs in some cases.
- find_library(mkl_rt mkl_rt ${mkl_search_path})
- mark_as_advanced( mkl_rt )
- # if we found the MKL
- if ( mkl_rt)
- set(blas_libraries ${mkl_rt} )
- set(lapack_libraries ${mkl_rt} )
- set(blas_found 1)
- set(lapack_found 1)
- set(found_intel_mkl 1)
- message(STATUS "Found Intel MKL BLAS/LAPACK library")
- endif()
-
-
-
- if (NOT found_intel_mkl)
- # Search for the needed libraries from the MKL. This time try looking for a different
- # set of MKL files and try to link against those.
- find_library(mkl_core mkl_core ${mkl_search_path})
- find_library(mkl_thread mkl_intel_thread ${mkl_search_path})
- find_library(mkl_iomp iomp5 ${mkl_search_path})
- find_library(mkl_pthread pthread ${mkl_search_path})
-
- mark_as_advanced( mkl_intel mkl_core mkl_thread mkl_iomp mkl_pthread)
- # If we found the MKL
- if (mkl_intel AND mkl_core AND mkl_thread AND mkl_iomp AND mkl_pthread)
- set(blas_libraries ${mkl_intel} ${mkl_core} ${mkl_thread} ${mkl_iomp} ${mkl_pthread})
- set(lapack_libraries ${mkl_intel} ${mkl_core} ${mkl_thread} ${mkl_iomp} ${mkl_pthread})
- set(blas_found 1)
- set(lapack_found 1)
- set(found_intel_mkl 1)
- message(STATUS "Found Intel MKL BLAS/LAPACK library")
- endif()
- endif()
-
-
- # try to find some other LAPACK libraries if we didn't find the MKL
- set(extra_paths
- /usr/lib64
- /usr/lib64/atlas-sse3
- /usr/lib64/atlas-sse2
- /usr/lib64/atlas
- /usr/lib
- /usr/lib/atlas-sse3
- /usr/lib/atlas-sse2
- /usr/lib/atlas)
-
-
- if (NOT lapack_found)
- find_library(lapack_lib NAMES lapack lapack-3 PATHS ${extra_paths})
- if (lapack_lib)
- set(lapack_libraries ${lapack_lib})
- set(lapack_found 1)
- message(STATUS "Found LAPACK library")
- endif()
- mark_as_advanced( lapack_lib)
- endif()
-
-
- # try to find some other BLAS libraries if we didn't find the MKL
-
- if (NOT blas_found)
- find_library(atlas_lib atlas PATHS ${extra_paths})
- find_library(cblas_lib cblas PATHS ${extra_paths})
- if (atlas_lib AND cblas_lib)
- set(blas_libraries ${atlas_lib} ${cblas_lib})
- set(blas_found 1)
- message(STATUS "Found ATLAS BLAS library")
- endif()
- mark_as_advanced( atlas_lib cblas_lib)
- endif()
-
-
- if (NOT blas_found)
- find_library(cblas_lib cblas PATHS ${extra_paths})
- if (cblas_lib)
- set(blas_libraries ${cblas_lib})
- set(blas_found 1)
- message(STATUS "Found CBLAS library")
- endif()
- mark_as_advanced( cblas_lib)
- endif()
-
-
- if (NOT blas_found)
- find_library(generic_blas blas PATHS ${extra_paths})
- if (generic_blas)
- set(blas_libraries ${generic_blas})
- set(blas_found 1)
- message(STATUS "Found BLAS library")
- endif()
- mark_as_advanced( generic_blas)
- endif()
-
-
-
-
- # Make sure we really found a CBLAS library. That is, it needs to expose
- # the proper cblas link symbols. So here we test if one of them is present
- # and assume everything is good if it is. Note that we don't do this check if
- # we found the Intel MKL since for some reason CHECK_FUNCTION_EXISTS doesn't work
- # with it. But it's fine since the MKL should always have cblas.
- if (blas_found AND NOT found_intel_mkl)
- INCLUDE (CheckFunctionExists)
- set(CMAKE_REQUIRED_LIBRARIES ${blas_libraries})
- CHECK_FUNCTION_EXISTS(cblas_ddot HAVE_CBLAS)
- if (NOT HAVE_CBLAS)
- message(STATUS "BLAS library does not have cblas symbols, so dlib will not use BLAS or LAPACK")
- set(blas_found 0)
- set(lapack_found 0)
- endif()
- endif()
-
-
- if (NOT blas_found)
- message(" *****************************************************************************")
- message(" *** No BLAS library found so using dlib's built in BLAS. However, if you ***")
- message(" *** install an optimized BLAS such as openblas or the Intel MKL your code ***")
- message(" *** will run faster. On Ubuntu you can install openblas by executing: ***")
- message(" *** sudo apt-get install libopenblas-dev liblapack-dev ***")
- message(" *****************************************************************************")
- endif()
-
-elseif(WIN32 AND NOT MINGW)
- message(STATUS "Searching for BLAS and LAPACK")
-
- include(CheckTypeSize)
- check_type_size( "void*" SIZE_OF_VOID_PTR)
- if (SIZE_OF_VOID_PTR EQUAL 8)
- set( mkl_search_path
- "C:/Program Files (x86)/Intel/Composer XE/mkl/lib/intel64"
- "C:/Program Files (x86)/Intel/Composer XE/compiler/lib/intel64"
- "C:/Program Files/Intel/Composer XE/mkl/lib/intel64"
- "C:/Program Files/Intel/Composer XE/compiler/lib/intel64"
- )
- find_library(mkl_intel mkl_intel_lp64 ${mkl_search_path})
- else()
- set( mkl_search_path
- "C:/Program Files (x86)/Intel/Composer XE/mkl/lib/ia32"
- "C:/Program Files (x86)/Intel/Composer XE/compiler/lib/ia32"
- "C:/Program Files/Intel/Composer XE/mkl/lib/ia32"
- "C:/Program Files/Intel/Composer XE/compiler/lib/ia32"
- )
- find_library(mkl_intel mkl_intel_c ${mkl_search_path})
- endif()
-
-
- # Search for the needed libraries from the MKL.
- find_library(mkl_core mkl_core ${mkl_search_path})
- find_library(mkl_thread mkl_intel_thread ${mkl_search_path})
- find_library(mkl_iomp libiomp5md ${mkl_search_path})
-
- mark_as_advanced( mkl_intel mkl_core mkl_thread mkl_iomp)
- # If we found the MKL
- if (mkl_intel AND mkl_core AND mkl_thread AND mkl_iomp )
- set(blas_libraries ${mkl_intel} ${mkl_core} ${mkl_thread} ${mkl_iomp} )
- set(lapack_libraries ${mkl_intel} ${mkl_core} ${mkl_thread} ${mkl_iomp} )
- set(blas_found 1)
- set(lapack_found 1)
- message(STATUS "Found Intel MKL BLAS/LAPACK library")
-
- if (MSVC)
- # need to set /bigobj when statically linking with the MKL on
- # visual studio or it doesn't work right.
- if (NOT CMAKE_CXX_FLAGS MATCHES "/bigobj")
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj"
- CACHE STRING "Flags used by the compiler during all C++ builds."
- FORCE)
- endif ()
- endif()
- endif()
-
-
-endif()
-
-
-
diff --git a/lib/3rdParty/dlib/dlib.props b/lib/3rdParty/dlib/dlib.props
index c0323b9a..47dffa57 100644
--- a/lib/3rdParty/dlib/dlib.props
+++ b/lib/3rdParty/dlib/dlib.props
@@ -4,5 +4,9 @@
$(SolutionDir)lib\3rdParty\dlib\include\dlib\..;%(AdditionalIncludeDirectories)
+
+ $(SolutionDir)lib\3rdParty\dlib\lib\$(PlatformTarget)\$(PlatformToolset)\$(Configuration);%(AdditionalLibraryDirectories)
+ dlib.lib;%(AdditionalDependencies)
+
\ No newline at end of file
diff --git a/lib/3rdParty/dlib/dlib.vcxproj b/lib/3rdParty/dlib/dlib.vcxproj
deleted file mode 100644
index 0f263123..00000000
--- a/lib/3rdParty/dlib/dlib.vcxproj
+++ /dev/null
@@ -1,217 +0,0 @@
-
-
-
-
- Debug
- Win32
-
-
- Debug
- x64
-
-
- Release
- Win32
-
-
- Release
- x64
-
-
-
-
-
-
- {B47A5F12-2567-44E9-AE49-35763EC82149}
- Win32Proj
- Win32
- dlib
- 8.1
-
-
-
- StaticLibrary
- false
- Unicode
- v140
-
-
- StaticLibrary
- false
- Unicode
- v140
-
-
- StaticLibrary
- false
- Unicode
- v140
- true
-
-
- StaticLibrary
- false
- Unicode
- v140
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <_ProjectFileVersion>10.0.20506.1
- $(SolutionDir)$(Configuration)\
- $(ProjectDir)$(Configuration)\
- dlib
- dlib
- .lib
- .lib
- $(SolutionDir)$(Configuration)\
- $(ProjectDir)$(Configuration)\
- $(ProjectName)
- $(ProjectName)
- .lib
- .lib
-
-
-
- $(SolutionDir)dlib/include/dlib/..;%(AdditionalIncludeDirectories)
- EnableFastChecks
- CompileAsCpp
- ProgramDatabase
- StreamingSIMDExtensions2
- Sync
- Disabled
- Disabled
- NotUsing
- MultiThreadedDebugDLL
- true
- Level3
- DLIB_NO_GUI_SUPPORT;WIN32;_WINDOWS;_DEBUG;ENABLE_ASSERTS;DLIB_HAVE_SSE2;DLIB_HAVE_SSE3;DLIB_HAVE_SSE41;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)
- Debug
- $(IntDir)
- $(IntDir)vc$(PlatformToolsetVersion).pdb
- true
-
-
- true
-
-
-
-
- $(SolutionDir)dlib/include/dlib/..;%(AdditionalIncludeDirectories)
- EnableFastChecks
- CompileAsCpp
- ProgramDatabase
- AdvancedVectorExtensions
- Sync
- Disabled
- Disabled
- NotUsing
- MultiThreadedDebugDLL
- true
- Level3
- DLIB_NO_GUI_SUPPORT;WIN64;_WINDOWS;_DEBUG;ENABLE_ASSERTS;DLIB_HAVE_SSE2;DLIB_HAVE_SSE3;DLIB_HAVE_SSE41;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)
- Debug
- $(IntDir)
- $(IntDir)vc$(PlatformToolsetVersion).pdb
- true
-
-
- true
-
-
-
-
- $(SolutionDir)dlib/include/dlib/..;%(AdditionalIncludeDirectories)
- CompileAsCpp
- AdvancedVectorExtensions
- Sync
- AnySuitable
- Full
- NotUsing
- MultiThreadedDLL
- true
- Level3
-
-
- DLIB_NO_GUI_SUPPORT;WIN32;_WINDOWS;NDEBUG;DLIB_HAVE_SSE2;DLIB_HAVE_SSE3;DLIB_HAVE_SSE41;%(PreprocessorDefinitions)
- $(IntDir)
- $(IntDir)
- $(IntDir)vc$(PlatformToolsetVersion).pdb
- Speed
- true
-
-
- WIN32;_WINDOWS;DLIB_PNG_SUPPORT;DLIB_JPEG_SUPPORT;NDEBUG;DLIB_HAVE_SSE2;DLIB_HAVE_SSE3;DLIB_HAVE_SSE41;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)
- $(SolutionDir)/dlib/..;$(SolutionDir)/dlib/external/libpng;$(SolutionDir)/dlib/external/zlib;$(SolutionDir)/dlib/external/libjpeg;%(AdditionalIncludeDirectories)
-
-
- $(SolutionDir)/dlib/..;$(SolutionDir)/dlib/external/libpng;$(SolutionDir)/dlib/external/zlib;$(SolutionDir)/dlib/external/libjpeg;%(AdditionalIncludeDirectories)
- $(IntDir)
- %(Filename).h
- %(Filename).tlb
- %(Filename)_i.c
- %(Filename)_p.c
-
-
- true
-
-
-
-
- $(SolutionDir)dlib/include/dlib/..;%(AdditionalIncludeDirectories)
- CompileAsCpp
- AdvancedVectorExtensions
- Sync
- AnySuitable
- Full
- NotUsing
- MultiThreadedDLL
- true
- Level3
-
-
- DLIB_NO_GUI_SUPPORT;WIN64;_WINDOWS;NDEBUG;DLIB_HAVE_SSE2;DLIB_HAVE_SSE3;DLIB_HAVE_SSE41;%(PreprocessorDefinitions)
- $(IntDir)
- $(IntDir)
- $(IntDir)vc$(PlatformToolsetVersion).pdb
- Speed
- true
-
-
- WIN32;_WINDOWS;DLIB_PNG_SUPPORT;DLIB_JPEG_SUPPORT;NDEBUG;DLIB_HAVE_SSE2;DLIB_HAVE_SSE3;DLIB_HAVE_SSE41;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)
- $(SolutionDir)/dlib/..;$(SolutionDir)/dlib/external/libpng;$(SolutionDir)/dlib/external/zlib;$(SolutionDir)/dlib/external/libjpeg;%(AdditionalIncludeDirectories)
-
-
- $(SolutionDir)/dlib/..;$(SolutionDir)/dlib/external/libpng;$(SolutionDir)/dlib/external/zlib;$(SolutionDir)/dlib/external/libjpeg;%(AdditionalIncludeDirectories)
- $(IntDir)
- %(Filename).h
- %(Filename).tlb
- %(Filename)_i.c
- %(Filename)_p.c
-
-
- true
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib/3rdParty/dlib/include/dlib/add_python_module b/lib/3rdParty/dlib/include/dlib/add_python_module
deleted file mode 100644
index 2e5c2f3b..00000000
--- a/lib/3rdParty/dlib/include/dlib/add_python_module
+++ /dev/null
@@ -1,111 +0,0 @@
-# This is a CMake file that sets up the add_python_module() macro. This macro
-# lets you easily make python modules that use dlib.
-#
-# The macro takes the module name as its first argument and then a list of
-# source files to compile into the module. See ../tools/python/CMakeLists.txt
-# for an example.
-#
-# It also sets up a macro called install_${module_name}_to() where
-# ${module_name} is whatever you named your module. This install_*_to() macro
-# takes a folder name and creates an install target that will copy the compiled
-# python module to that folder when you run "make install". Note that the path
-# given to install_*_to() is relative to your CMakeLists.txt file.
-
-
-
-# A list of various paths you need to search on windows since people install
-# boost in a bunch of different places.
-set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}
- "C:/local/boost_1_*"
- "C:/Program Files (x86)/boost/boost_1_*"
- "C:/Program Files/boost/boost_1_*")
-set(BOOST_LIBRARYDIR "C:/local/boost_1_*/lib32-msvc-*")
-
-
-
-#SET(Boost_USE_STATIC_LIBS OFF)
-#SET(Boost_USE_MULTITHREADED ON)
-#SET(Boost_USE_STATIC_RUNTIME OFF)
-set(Boost_NO_BOOST_CMAKE ON)
-
-FIND_PACKAGE(Boost 1.41.0 COMPONENTS python REQUIRED)
-FIND_PACKAGE(PythonLibs 2.6 REQUIRED)
-
-if (WIN32 AND NOT Boost_LIBRARIES)
- message(FATAL_ERROR "We couldn't find the right version of boost python. If you installed boost and you are still "
- "getting this error then you might have installed a version of boost that was compiled with a different "
- "version of visual studio than the one you are using. So you have to make sure that the version of "
- "visual studio is the same version that was used to compile the copy of boost you are using.")
-endif()
-
-
-INCLUDE_DIRECTORIES("${Boost_INCLUDE_DIRS}")
-if (PYTHON_INCLUDE_PATH)
- INCLUDE_DIRECTORIES("${PYTHON_INCLUDE_PATH}" )
-else()
- INCLUDE_DIRECTORIES("${PYTHON_INCLUDE_DIRS}" )
-endif()
-
-if (CMAKE_COMPILER_IS_GNUCXX)
- add_definitions("-fPIC")
-endif()
-
-# include dlib so we can link against it
-string(REGEX REPLACE "add_python_module$" "" dlib_path ${CMAKE_CURRENT_LIST_FILE})
-include(${dlib_path}/cmake)
-
-# We put the extra _ on the end of the name just so it's possible to
-# have a module name of dlib and not get a conflict with the target named
-# dlib in ../dlib/cmake. We use the target OUPUT_NAME property to ensure the
-# output name is set to what the user asked for (i.e. no _).
-macro(add_python_module module_name module_sources )
- ADD_LIBRARY(${module_name}_ SHARED ${module_sources} ${ARGN} )
- TARGET_LINK_LIBRARIES(${module_name}_ ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} dlib)
- if(WIN32 AND NOT CYGWIN)
- SET_TARGET_PROPERTIES( ${module_name}_
- PROPERTIES
- PREFIX ""
- SUFFIX ".pyd"
- OUTPUT_NAME ${module_name}
- )
- elseif(CYGWIN)
- SET_TARGET_PROPERTIES( ${module_name}_
- PROPERTIES
- PREFIX ""
- SUFFIX ".dll"
- OUTPUT_NAME ${module_name}
- )
- else()
- SET_TARGET_PROPERTIES( ${module_name}_
- PROPERTIES
- PREFIX ""
- SUFFIX ".so"
- OUTPUT_NAME ${module_name}
- )
- endif()
-
- macro(install_${module_name}_to path)
- # Determine the path to our CMakeLists.txt file.
- string(REGEX REPLACE "CMakeLists.txt$" "" base_path ${CMAKE_CURRENT_LIST_FILE})
- INSTALL(TARGETS ${module_name}_
- DESTINATION "${base_path}/${path}"
- )
-
- # On windows we will usually need to have the boost-python .dll files in the same folder or
- # you will get an error about how they can't be found. So copy the boost .dll files along with
- # your module to the install folder to avoid this.
- if (WIN32)
- list(GET Boost_LIBRARIES 1 boostlibs1)
- list(GET Boost_LIBRARIES 3 boostlibs2)
- string(REGEX REPLACE ".lib$" ".dll" boostdlls1 ${boostlibs1})
- string(REGEX REPLACE ".lib$" ".dll" boostdlls2 ${boostlibs2})
- INSTALL(FILES ${boostdlls1} ${boostdlls2}
- DESTINATION "${base_path}/${path}"
- )
- endif()
- endmacro()
-
-endmacro()
-
-
-
diff --git a/lib/3rdParty/dlib/include/dlib/algs.h b/lib/3rdParty/dlib/include/dlib/algs.h
index 640a62f4..9a2e0d22 100644
--- a/lib/3rdParty/dlib/include/dlib/algs.h
+++ b/lib/3rdParty/dlib/include/dlib/algs.h
@@ -1,12 +1,37 @@
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
+
+#ifdef DLIB_ALL_SOURCE_END
+#include "dlib_basic_cpp_build_tutorial.txt"
+#endif
+
#ifndef DLIB_ALGs_
#define DLIB_ALGs_
// this file contains miscellaneous stuff
+// Give people who forget the -std=c++11 option a reminder
+#if (defined(__GNUC__) && ((__GNUC__ >= 4 && __GNUC_MINOR__ >= 8) || (__GNUC__ > 4))) || \
+ (defined(__clang__) && ((__clang_major__ >= 3 && __clang_minor__ >= 4) || (__clang_major__ >= 3)))
+ #if __cplusplus < 201103
+ #error "Dlib requires C++11 support. Give your compiler the -std=c++11 option to enable it."
+ #endif
+#endif
+
+#if defined __NVCC__
+ // Disable the "statement is unreachable" message since it will go off on code that is
+ // actually reachable but just happens to not be reachable sometimes during certain
+ // template instantiations.
+ #pragma diag_suppress code_is_unreachable
+#endif
+
#ifdef _MSC_VER
+
+#if _MSC_VER < 1900
+#error "dlib versions newer than v19.1 use C++11 and therefore require Visual Studio 2015 or newer."
+#endif
+
// Disable the following warnings for Visual Studio
// this is to disable the "'this' : used in base member initializer list"
@@ -43,6 +68,16 @@
// This warning happens often in generic code that works with functions and isn't useful.
#pragma warning(disable : 4180)
+// Disable "warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)"
+#pragma warning(disable : 4290)
+
+
+// DNN module uses template-based network declaration that leads to very long
+// type names. Visual Studio will produce Warning C4503 in such cases. https://msdn.microsoft.com/en-us/library/074af4b6.aspx says
+// that correct binaries are still produced even when this warning happens, but linker errors from visual studio, if they occurr could be confusing.
+#pragma warning( disable: 4503 )
+
+
#endif
#ifdef __BORLANDC__
@@ -71,6 +106,7 @@ namespace std
#include // for std::swap
#include // for std::bad_alloc
#include
+#include
#include // for std::numeric_limits for is_finite()
#include "assert.h"
#include "error.h"
@@ -275,7 +311,7 @@ namespace dlib
typename A,
typename B
>
- bool operator> (
+ constexpr bool operator> (
const A& a,
const B& b
) { return b < a; }
@@ -286,7 +322,7 @@ namespace dlib
typename A,
typename B
>
- bool operator!= (
+ constexpr bool operator!= (
const A& a,
const B& b
) { return !(a == b); }
@@ -297,7 +333,7 @@ namespace dlib
typename A,
typename B
>
- bool operator<= (
+ constexpr bool operator<= (
const A& a,
const B& b
) { return !(b < a); }
@@ -308,7 +344,7 @@ namespace dlib
typename A,
typename B
>
- bool operator>= (
+ constexpr bool operator>= (
const A& a,
const B& b
) { return !(a < b); }
@@ -480,6 +516,13 @@ namespace dlib
// ----------------------------------------------------------------------------------------
+ struct general_ {};
+ struct special_ : general_ {};
+ template struct int_ { typedef int type; };
+
+// ----------------------------------------------------------------------------------------
+
+
/*!A is_same_object
This is a templated function which checks if both of its arguments are actually
@@ -759,10 +802,10 @@ namespace dlib
abs<4>::value == 4
!*/
- template
- struct tabs { const static long value = x; };
- template
- struct tabs::type> { const static long value = -x; };
+ template
+ struct tabs { const static long value = x; };
+ template
+ struct tabs::type> { const static long value = -x; };
// ----------------------------------------------------------------------------------------
@@ -774,10 +817,10 @@ namespace dlib
abs<4,7>::value == 7
!*/
- template
- struct tmax { const static long value = x; };
- template
- struct tmax x)>::type> { const static long value = y; };
+ template
+ struct tmax { const static long value = x; };
+ template
+ struct tmax x)>::type> { const static long value = y; };
// ----------------------------------------------------------------------------------------
@@ -789,12 +832,12 @@ namespace dlib
abs<4,7>::value == 4
!*/
- template
- struct tmin { const static long value = x; };
- template
- struct tmin::type> { const static long value = y; };
+ template
+ struct tmin { const static long value = x; };
+ template
+ struct tmin::type> { const static long value = y; };
- // ----------------------------------------------------------------------------------------
+// ----------------------------------------------------------------------------------------
#define DLIB_MAKE_HAS_MEMBER_FUNCTION_TEST(testname, returnT, funct_name, args) \
struct _two_bytes_##testname { char a[2]; }; \
@@ -1025,6 +1068,88 @@ namespace dlib
void* const data;
};
+// ----------------------------------------------------------------------------------------
+
+ template <
+ typename T,
+ typename F
+ >
+ auto max_scoring_element(
+ const T& container,
+ F score_func
+ ) -> decltype(std::make_pair(*container.begin(), 0.0))
+ /*!
+ requires
+ - container has .begin() and .end(), allowing it to be enumerated.
+ - score_func() is a function that takes an element of the container and returns a double.
+ ensures
+ - This function finds the element of container that has the largest score,
+ according to score_func(), and returns a std::pair containing that maximal
+ element along with the score.
+ - If the container is empty then make_pair(a default initialized object, -infinity) is returned.
+ !*/
+ {
+ double best_score = -std::numeric_limits::infinity();
+ auto best_i = container.begin();
+ for (auto i = container.begin(); i != container.end(); ++i)
+ {
+ auto score = score_func(*i);
+ if (score > best_score)
+ {
+ best_score = score;
+ best_i = i;
+ }
+ }
+
+ using item_type = typename std::remove_reference::type;
+
+ if (best_i == container.end())
+ return std::make_pair(item_type(), best_score);
+ else
+ return std::make_pair(*best_i, best_score);
+ }
+
+// ----------------------------------------------------------------------------------------
+
+ template <
+ typename T,
+ typename F
+ >
+ auto min_scoring_element(
+ const T& container,
+ F score_func
+ ) -> decltype(std::make_pair(*container.begin(), 0.0))
+ /*!
+ requires
+ - container has .begin() and .end(), allowing it to be enumerated.
+ - score_func() is a function that takes an element of the container and returns a double.
+ ensures
+ - This function finds the element of container that has the smallest score,
+ according to score_func(), and returns a std::pair containing that minimal
+ element along with the score.
+ - If the container is empty then make_pair(a default initialized object, infinity) is returned.
+ !*/
+ {
+ double best_score = std::numeric_limits::infinity();
+ auto best_i = container.begin();
+ for (auto i = container.begin(); i != container.end(); ++i)
+ {
+ auto score = score_func(*i);
+ if (score < best_score)
+ {
+ best_score = score;
+ best_i = i;
+ }
+ }
+
+ using item_type = typename std::remove_reference::type;
+
+ if (best_i == container.end())
+ return std::make_pair(item_type(), best_score);
+ else
+ return std::make_pair(*best_i, best_score);
+ }
+
// ----------------------------------------------------------------------------------------
}
diff --git a/lib/3rdParty/dlib/include/dlib/all/source.cpp b/lib/3rdParty/dlib/include/dlib/all/source.cpp
deleted file mode 100644
index 1177de59..00000000
--- a/lib/3rdParty/dlib/include/dlib/all/source.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (C) 2006 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef DLIB_ALL_SOURCe_
-#define DLIB_ALL_SOURCe_
-
-// ISO C++ code
-#include "../base64/base64_kernel_1.cpp"
-//#include "../bigint/bigint_kernel_1.cpp"
-//#include "../bigint/bigint_kernel_2.cpp"
-#include "../bit_stream/bit_stream_kernel_1.cpp"
-#include "../entropy_decoder/entropy_decoder_kernel_1.cpp"
-#include "../entropy_decoder/entropy_decoder_kernel_2.cpp"
-#include "../entropy_encoder/entropy_encoder_kernel_1.cpp"
-#include "../entropy_encoder/entropy_encoder_kernel_2.cpp"
-//#include "../md5/md5_kernel_1.cpp"
-#include "../tokenizer/tokenizer_kernel_1.cpp"
-//#include "../unicode/unicode.cpp"
-//#include "../data_io/image_dataset_metadata.cpp"
-
-#ifndef DLIB_ISO_CPP_ONLY
-// Code that depends on OS specific APIs
-
-// include this first so that it can disable the older version
-// of the winsock API when compiled in windows.
-#include "../sockets/sockets_kernel_1.cpp"
-//#include "../bsp/bsp.cpp"
-
-//#include "../dir_nav/dir_nav_kernel_1.cpp"
-//#include "../dir_nav/dir_nav_kernel_2.cpp"
-//#include "../dir_nav/dir_nav_extensions.cpp"
-//#include "../linker/linker_kernel_1.cpp"
-//#include "../logger/extra_logger_headers.cpp"
-//#include "../logger/logger_kernel_1.cpp"
-//#include "../logger/logger_config_file.cpp"
-#include "../misc_api/misc_api_kernel_1.cpp"
-#include "../misc_api/misc_api_kernel_2.cpp"
-#include "../sockets/sockets_extensions.cpp"
-#include "../sockets/sockets_kernel_2.cpp"
-#include "../sockstreambuf/sockstreambuf.cpp"
-#include "../sockstreambuf/sockstreambuf_unbuffered.cpp"
-//#include "../server/server_kernel.cpp"
-//#include "../server/server_iostream.cpp"
-//#include "../server/server_http.cpp"
-//#include "../threads/multithreaded_object_extension.cpp"
-#include "../threads/threaded_object_extension.cpp"
-#include "../threads/threads_kernel_1.cpp"
-#include "../threads/threads_kernel_2.cpp"
-#include "../threads/threads_kernel_shared.cpp"
-//#include "../threads/thread_pool_extension.cpp"
-#include "../timer/timer.cpp"
-//#include "../stack_trace.cpp"
-
-#ifdef DLIB_PNG_SUPPORT
-#include "../image_loader/png_loader.cpp"
-#include "../image_saver/save_png.cpp"
-#endif
-
-#ifdef DLIB_JPEG_SUPPORT
-#include "../image_loader/jpeg_loader.cpp"
-#endif
-
-#ifndef DLIB_NO_GUI_SUPPORT
-#include "../gui_widgets/fonts.cpp"
-#include "../gui_widgets/widgets.cpp"
-#include "../gui_widgets/drawable.cpp"
-#include "../gui_widgets/canvas_drawing.cpp"
-#include "../gui_widgets/style.cpp"
-#include "../gui_widgets/base_widgets.cpp"
-#include "../gui_core/gui_core_kernel_1.cpp"
-#include "../gui_core/gui_core_kernel_2.cpp"
-#endif // DLIB_NO_GUI_SUPPORT
-
-#endif // DLIB_ISO_CPP_ONLY
-
-#endif // DLIB_ALL_SOURCe_
-
diff --git a/lib/3rdParty/dlib/include/dlib/all_console.cpp b/lib/3rdParty/dlib/include/dlib/all_console.cpp
deleted file mode 100644
index 556983be..00000000
--- a/lib/3rdParty/dlib/include/dlib/all_console.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright (C) 2006 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef DLIB_ALL_CONSOLe_
-#define DLIB_ALL_CONSOLe_
-
-#error "This file has been replaced. Instead you should add dlib/all/source.cpp to your project"
-
-#endif // DLIB_ALL_CONSOLe_
-
diff --git a/lib/3rdParty/dlib/include/dlib/all_gui.cpp b/lib/3rdParty/dlib/include/dlib/all_gui.cpp
deleted file mode 100644
index cd397dbf..00000000
--- a/lib/3rdParty/dlib/include/dlib/all_gui.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright (C) 2006 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef DLIB_ALL_GUi_
-#define DLIB_ALL_GUi_
-
-#error "This file has been replaced. Instead you should add dlib/all/source.cpp to your project"
-
-#endif // DLIB_ALL_GUi_
-
diff --git a/lib/3rdParty/dlib/include/dlib/any/any.h b/lib/3rdParty/dlib/include/dlib/any/any.h
index 6d9938d6..b5ef1bc8 100644
--- a/lib/3rdParty/dlib/include/dlib/any/any.h
+++ b/lib/3rdParty/dlib/include/dlib/any/any.h
@@ -4,7 +4,9 @@
#define DLIB_AnY_H_
#include "any_abstract.h"
-#include "../smart_pointers.h"
+#include "../algs.h"
+
+#include
#include
namespace dlib
@@ -136,7 +138,7 @@ namespace dlib
virtual ~base() {}
virtual void copy_to (
- scoped_ptr& dest
+ std::unique_ptr& dest
) const = 0;
};
@@ -148,14 +150,14 @@ namespace dlib
derived(const T& val) : item(val) {}
virtual void copy_to (
- scoped_ptr& dest
+ std::unique_ptr& dest
) const
{
dest.reset(new derived(item));
}
};
- scoped_ptr data;
+ std::unique_ptr data;
};
// ----------------------------------------------------------------------------------------
diff --git a/lib/3rdParty/dlib/include/dlib/any/any_decision_function.h b/lib/3rdParty/dlib/include/dlib/any/any_decision_function.h
index d165fcca..771e9302 100644
--- a/lib/3rdParty/dlib/include/dlib/any/any_decision_function.h
+++ b/lib/3rdParty/dlib/include/dlib/any/any_decision_function.h
@@ -4,7 +4,6 @@
#define DLIB_AnY_DECISION_FUNCTION_Hh_
#include "any.h"
-#include "../smart_pointers.h"
#include "any_decision_function_abstract.h"
@@ -148,7 +147,7 @@ namespace dlib
virtual ~base() {}
virtual void copy_to (
- scoped_ptr& dest
+ std::unique_ptr& dest
) const = 0;
virtual result_type evaluate (
@@ -164,7 +163,7 @@ namespace dlib
derived(const T& val) : item(val) {}
virtual void copy_to (
- scoped_ptr& dest
+ std::unique_ptr& dest
) const
{
dest.reset(new derived(item));
@@ -178,7 +177,7 @@ namespace dlib
}
};
- scoped_ptr data;
+ std::unique_ptr data;
};
// ----------------------------------------------------------------------------------------
diff --git a/lib/3rdParty/dlib/include/dlib/any/any_function.h b/lib/3rdParty/dlib/include/dlib/any/any_function.h
index d9aa4931..f186b4d3 100644
--- a/lib/3rdParty/dlib/include/dlib/any/any_function.h
+++ b/lib/3rdParty/dlib/include/dlib/any/any_function.h
@@ -4,7 +4,6 @@
#define DLIB_AnY_FUNCTION_Hh_
#include "any.h"
-#include "../smart_pointers.h"
#include "any_function_abstract.h"
@@ -32,6 +31,16 @@ namespace dlib
typedef void arg8_type;
typedef void arg9_type;
typedef void arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 0;
};
@@ -53,6 +62,16 @@ namespace dlib
typedef void arg8_type;
typedef void arg9_type;
typedef void arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 1;
};
@@ -74,6 +93,16 @@ namespace dlib
typedef void arg8_type;
typedef void arg9_type;
typedef void arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 2;
};
@@ -95,6 +124,16 @@ namespace dlib
typedef void arg8_type;
typedef void arg9_type;
typedef void arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 3;
};
@@ -117,6 +156,16 @@ namespace dlib
typedef void arg8_type;
typedef void arg9_type;
typedef void arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 4;
};
@@ -139,6 +188,16 @@ namespace dlib
typedef void arg8_type;
typedef void arg9_type;
typedef void arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 5;
};
@@ -161,6 +220,16 @@ namespace dlib
typedef void arg8_type;
typedef void arg9_type;
typedef void arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 6;
};
@@ -184,6 +253,16 @@ namespace dlib
typedef void arg8_type;
typedef void arg9_type;
typedef void arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 7;
};
@@ -207,6 +286,16 @@ namespace dlib
typedef A8 arg8_type;
typedef void arg9_type;
typedef void arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 8;
};
@@ -230,6 +319,16 @@ namespace dlib
typedef A8 arg8_type;
typedef A9 arg9_type;
typedef void arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 9;
};
@@ -254,10 +353,415 @@ namespace dlib
typedef A8 arg8_type;
typedef A9 arg9_type;
typedef A10 arg10_type;
+ typedef void arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
const static unsigned long num_args = 10;
};
+ template <
+ typename T,
+ typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6,
+ typename A7, typename A8, typename A9,
+ typename A10,
+ typename A11
+ >
+ struct sig_traits
+ {
+ typedef T result_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ typedef A4 arg4_type;
+ typedef A5 arg5_type;
+ typedef A6 arg6_type;
+ typedef A7 arg7_type;
+ typedef A8 arg8_type;
+ typedef A9 arg9_type;
+ typedef A10 arg10_type;
+ typedef A11 arg11_type;
+ typedef void arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
+
+ const static unsigned long num_args = 11;
+ };
+
+ template <
+ typename T,
+ typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6,
+ typename A7, typename A8, typename A9,
+ typename A10,
+ typename A11,
+ typename A12
+ >
+ struct sig_traits
+ {
+ typedef T result_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ typedef A4 arg4_type;
+ typedef A5 arg5_type;
+ typedef A6 arg6_type;
+ typedef A7 arg7_type;
+ typedef A8 arg8_type;
+ typedef A9 arg9_type;
+ typedef A10 arg10_type;
+ typedef A11 arg11_type;
+ typedef A12 arg12_type;
+ typedef void arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
+
+ const static unsigned long num_args = 12;
+ };
+
+ template <
+ typename T,
+ typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6,
+ typename A7, typename A8, typename A9,
+ typename A10,
+ typename A11,
+ typename A12,
+ typename A13
+ >
+ struct sig_traits
+ {
+ typedef T result_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ typedef A4 arg4_type;
+ typedef A5 arg5_type;
+ typedef A6 arg6_type;
+ typedef A7 arg7_type;
+ typedef A8 arg8_type;
+ typedef A9 arg9_type;
+ typedef A10 arg10_type;
+ typedef A11 arg11_type;
+ typedef A12 arg12_type;
+ typedef A13 arg13_type;
+ typedef void arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
+
+ const static unsigned long num_args = 13;
+ };
+
+ template <
+ typename T,
+ typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6,
+ typename A7, typename A8, typename A9,
+ typename A10,
+ typename A11,
+ typename A12,
+ typename A13,
+ typename A14
+ >
+ struct sig_traits
+ {
+ typedef T result_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ typedef A4 arg4_type;
+ typedef A5 arg5_type;
+ typedef A6 arg6_type;
+ typedef A7 arg7_type;
+ typedef A8 arg8_type;
+ typedef A9 arg9_type;
+ typedef A10 arg10_type;
+ typedef A11 arg11_type;
+ typedef A12 arg12_type;
+ typedef A13 arg13_type;
+ typedef A14 arg14_type;
+ typedef void arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
+
+ const static unsigned long num_args = 14;
+ };
+
+ template <
+ typename T,
+ typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6,
+ typename A7, typename A8, typename A9,
+ typename A10,
+ typename A11,
+ typename A12,
+ typename A13,
+ typename A14,
+ typename A15
+ >
+ struct sig_traits
+ {
+ typedef T result_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ typedef A4 arg4_type;
+ typedef A5 arg5_type;
+ typedef A6 arg6_type;
+ typedef A7 arg7_type;
+ typedef A8 arg8_type;
+ typedef A9 arg9_type;
+ typedef A10 arg10_type;
+ typedef A11 arg11_type;
+ typedef A12 arg12_type;
+ typedef A13 arg13_type;
+ typedef A14 arg14_type;
+ typedef A15 arg15_type;
+ typedef void arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
+
+ const static unsigned long num_args = 15;
+ };
+
+ template <
+ typename T,
+ typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6,
+ typename A7, typename A8, typename A9,
+ typename A10,
+ typename A11,
+ typename A12,
+ typename A13,
+ typename A14,
+ typename A15,
+ typename A16
+ >
+ struct sig_traits
+ {
+ typedef T result_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ typedef A4 arg4_type;
+ typedef A5 arg5_type;
+ typedef A6 arg6_type;
+ typedef A7 arg7_type;
+ typedef A8 arg8_type;
+ typedef A9 arg9_type;
+ typedef A10 arg10_type;
+ typedef A11 arg11_type;
+ typedef A12 arg12_type;
+ typedef A13 arg13_type;
+ typedef A14 arg14_type;
+ typedef A15 arg15_type;
+ typedef A16 arg16_type;
+ typedef void arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
+
+ const static unsigned long num_args = 16;
+ };
+
+ template <
+ typename T,
+ typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6,
+ typename A7, typename A8, typename A9,
+ typename A10,
+ typename A11,
+ typename A12,
+ typename A13,
+ typename A14,
+ typename A15,
+ typename A16,
+ typename A17
+ >
+ struct sig_traits
+ {
+ typedef T result_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ typedef A4 arg4_type;
+ typedef A5 arg5_type;
+ typedef A6 arg6_type;
+ typedef A7 arg7_type;
+ typedef A8 arg8_type;
+ typedef A9 arg9_type;
+ typedef A10 arg10_type;
+ typedef A11 arg11_type;
+ typedef A12 arg12_type;
+ typedef A13 arg13_type;
+ typedef A14 arg14_type;
+ typedef A15 arg15_type;
+ typedef A16 arg16_type;
+ typedef A17 arg17_type;
+ typedef void arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
+
+ const static unsigned long num_args = 17;
+ };
+
+ template <
+ typename T,
+ typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6,
+ typename A7, typename A8, typename A9,
+ typename A10,
+ typename A11,
+ typename A12,
+ typename A13,
+ typename A14,
+ typename A15,
+ typename A16,
+ typename A17,
+ typename A18
+ >
+ struct sig_traits
+ {
+ typedef T result_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ typedef A4 arg4_type;
+ typedef A5 arg5_type;
+ typedef A6 arg6_type;
+ typedef A7 arg7_type;
+ typedef A8 arg8_type;
+ typedef A9 arg9_type;
+ typedef A10 arg10_type;
+ typedef A11 arg11_type;
+ typedef A12 arg12_type;
+ typedef A13 arg13_type;
+ typedef A14 arg14_type;
+ typedef A15 arg15_type;
+ typedef A16 arg16_type;
+ typedef A17 arg17_type;
+ typedef A18 arg18_type;
+ typedef void arg19_type;
+ typedef void arg20_type;
+
+ const static unsigned long num_args = 18;
+ };
+
+ template <
+ typename T,
+ typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6,
+ typename A7, typename A8, typename A9,
+ typename A10,
+ typename A11,
+ typename A12,
+ typename A13,
+ typename A14,
+ typename A15,
+ typename A16,
+ typename A17,
+ typename A18,
+ typename A19
+ >
+ struct sig_traits
+ {
+ typedef T result_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ typedef A4 arg4_type;
+ typedef A5 arg5_type;
+ typedef A6 arg6_type;
+ typedef A7 arg7_type;
+ typedef A8 arg8_type;
+ typedef A9 arg9_type;
+ typedef A10 arg10_type;
+ typedef A11 arg11_type;
+ typedef A12 arg12_type;
+ typedef A13 arg13_type;
+ typedef A14 arg14_type;
+ typedef A15 arg15_type;
+ typedef A16 arg16_type;
+ typedef A17 arg17_type;
+ typedef A18 arg18_type;
+ typedef A19 arg19_type;
+ typedef void arg20_type;
+
+ const static unsigned long num_args = 19;
+ };
+
+ template <
+ typename T,
+ typename A1, typename A2, typename A3,
+ typename A4, typename A5, typename A6,
+ typename A7, typename A8, typename A9,
+ typename A10,
+ typename A11,
+ typename A12,
+ typename A13,
+ typename A14,
+ typename A15,
+ typename A16,
+ typename A17,
+ typename A18,
+ typename A19,
+ typename A20
+ >
+ struct sig_traits
+ {
+ typedef T result_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ typedef A4 arg4_type;
+ typedef A5 arg5_type;
+ typedef A6 arg6_type;
+ typedef A7 arg7_type;
+ typedef A8 arg8_type;
+ typedef A9 arg9_type;
+ typedef A10 arg10_type;
+ typedef A11 arg11_type;
+ typedef A12 arg12_type;
+ typedef A13 arg13_type;
+ typedef A14 arg14_type;
+ typedef A15 arg15_type;
+ typedef A16 arg16_type;
+ typedef A17 arg17_type;
+ typedef A18 arg18_type;
+ typedef A19 arg19_type;
+ typedef A20 arg20_type;
+
+ const static unsigned long num_args = 20;
+ };
+
// ----------------------------------------------------------------------------------------
template <
diff --git a/lib/3rdParty/dlib/include/dlib/any/any_function_impl.h b/lib/3rdParty/dlib/include/dlib/any/any_function_impl.h
index efd4b2b1..f9a45683 100644
--- a/lib/3rdParty/dlib/include/dlib/any/any_function_impl.h
+++ b/lib/3rdParty/dlib/include/dlib/any/any_function_impl.h
@@ -166,7 +166,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual result_type evaluate () const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
template <
@@ -177,7 +177,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual T evaluate ( A1) const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
template <
@@ -188,7 +188,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual T evaluate (A1,A2) const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
template <
@@ -199,7 +199,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual T evaluate (A1,A2,A3) const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
template <
@@ -211,7 +211,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual T evaluate (A1,A2,A3,A4) const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
template <
@@ -223,7 +223,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual T evaluate (A1,A2,A3,A4,A5) const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
template <
@@ -235,7 +235,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual T evaluate (A1,A2,A3,A4,A5,A6) const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
template <
@@ -248,7 +248,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual T evaluate (A1,A2,A3,A4,A5,A6,A7) const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
template <
@@ -261,7 +261,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual T evaluate (A1,A2,A3,A4,A5,A6,A7,A8) const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
template <
@@ -274,7 +274,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual T evaluate (A1,A2,A3,A4,A5,A6,A7,A8,A9) const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
template <
@@ -288,7 +288,7 @@ struct Tbase
{
virtual ~Tbase() {}
virtual T evaluate (A1,A2,A3,A4,A5,A6,A7,A8,A9,A10) const = 0;
- virtual void copy_to ( scoped_ptr& dest) const = 0;
+ virtual void copy_to ( std::unique_ptr& dest) const = 0;
};
typedef Tbase base;
@@ -318,7 +318,7 @@ static typename disable_if,const T&>::type deref (const U& item)
typename funct_type::type item; \
derived() {} \
derived(const T& val) : item(copy(val)) {} \
- virtual void copy_to ( scoped_ptr& dest) const \
+ virtual void copy_to ( std::unique_ptr& dest) const \
{ dest.reset(new derived(deref(item))); }
template
@@ -508,7 +508,7 @@ struct derived : public base
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
};
-scoped_ptr data;
+std::unique_ptr data;
#undef DLIB_ANY_FUNCTION_DERIVED_BOILERPLATE
diff --git a/lib/3rdParty/dlib/include/dlib/any/any_trainer.h b/lib/3rdParty/dlib/include/dlib/any/any_trainer.h
index 2346ca4f..4df10a14 100644
--- a/lib/3rdParty/dlib/include/dlib/any/any_trainer.h
+++ b/lib/3rdParty/dlib/include/dlib/any/any_trainer.h
@@ -4,7 +4,6 @@
#define DLIB_AnY_TRAINER_H_
#include "any.h"
-#include "../smart_pointers.h"
#include "any_decision_function.h"
@@ -157,7 +156,7 @@ namespace dlib
) const = 0;
virtual void copy_to (
- scoped_ptr& dest
+ std::unique_ptr& dest
) const = 0;
};
@@ -169,7 +168,7 @@ namespace dlib
derived(const T& val) : item(val) {}
virtual void copy_to (
- scoped_ptr& dest
+ std::unique_ptr& dest
) const
{
dest.reset(new derived(item));
@@ -184,7 +183,7 @@ namespace dlib
}
};
- scoped_ptr data;
+ std::unique_ptr data;
};
// ----------------------------------------------------------------------------------------
diff --git a/lib/3rdParty/dlib/include/dlib/array/array_kernel.h b/lib/3rdParty/dlib/include/dlib/array/array_kernel.h
index ca1c23b4..02858ba4 100644
--- a/lib/3rdParty/dlib/include/dlib/array/array_kernel.h
+++ b/lib/3rdParty/dlib/include/dlib/array/array_kernel.h
@@ -90,8 +90,26 @@ namespace dlib
_at_start(true)
{}
+ array(const array&) = delete;
+ array& operator=(array&) = delete;
+
+ array(
+ array&& item
+ ) : array()
+ {
+ swap(item);
+ }
+
+ array& operator=(
+ array&& item
+ )
+ {
+ swap(item);
+ return *this;
+ }
+
explicit array (
- unsigned long new_size
+ size_t new_size
) :
array_size(0),
max_array_size(0),
@@ -110,22 +128,22 @@ namespace dlib
);
inline const T& operator[] (
- unsigned long pos
+ size_t pos
) const;
inline T& operator[] (
- unsigned long pos
+ size_t pos
);
void set_size (
- unsigned long size
+ size_t size
);
- inline unsigned long max_size(
+ inline size_t max_size(
) const;
void set_max_size(
- unsigned long max
+ size_t max
);
void swap (
@@ -133,7 +151,7 @@ namespace dlib
);
// functions from the enumerable interface
- inline unsigned long size (
+ inline size_t size (
) const;
inline bool at_start (
@@ -158,7 +176,7 @@ namespace dlib
);
void resize (
- unsigned long new_size
+ size_t new_size
);
const T& back (
@@ -178,6 +196,10 @@ namespace dlib
T& item
);
+ void push_back (
+ T&& item
+ );
+
typedef T* iterator;
typedef const T* const_iterator;
iterator begin() { return array_elements; }
@@ -190,18 +212,14 @@ namespace dlib
typename mem_manager::template rebind::other pool;
// data members
- unsigned long array_size;
- unsigned long max_array_size;
+ size_t array_size;
+ size_t max_array_size;
T* array_elements;
mutable T* pos;
T* last_pos;
mutable bool _at_start;
- // restricted functions
- array(array&); // copy constructor
- array& operator=(array&); // assignment operator
-
};
template <
@@ -229,7 +247,7 @@ namespace dlib
serialize(item.max_size(),out);
serialize(item.size(),out);
- for (unsigned long i = 0; i < item.size(); ++i)
+ for (size_t i = 0; i < item.size(); ++i)
serialize(item[i],out);
}
catch (serialization_error e)
@@ -249,12 +267,12 @@ namespace dlib
{
try
{
- unsigned long max_size, size;
+ size_t max_size, size;
deserialize(max_size,in);
deserialize(size,in);
item.set_max_size(max_size);
item.set_size(size);
- for (unsigned long i = 0; i < size; ++i)
+ for (size_t i = 0; i < size; ++i)
deserialize(item[i],in);
}
catch (serialization_error e)
@@ -314,7 +332,7 @@ namespace dlib
>
const T& array::
operator[] (
- unsigned long pos
+ size_t pos
) const
{
// make sure requires clause is not broken
@@ -337,7 +355,7 @@ namespace dlib
>
T& array::
operator[] (
- unsigned long pos
+ size_t pos
)
{
// make sure requires clause is not broken
@@ -360,7 +378,7 @@ namespace dlib
>
void array::
set_size (
- unsigned long size
+ size_t size
)
{
// make sure requires clause is not broken
@@ -386,7 +404,7 @@ namespace dlib
typename T,
typename mem_manager
>
- unsigned long array::
+ size_t array::
size (
) const
{
@@ -401,7 +419,7 @@ namespace dlib
>
void array::
set_max_size(
- unsigned long max
+ size_t max
)
{
reset();
@@ -439,7 +457,7 @@ namespace dlib
typename T,
typename mem_manager
>
- unsigned long array::
+ size_t array::
max_size (
) const
{
@@ -457,8 +475,8 @@ namespace dlib
array& item
)
{
- unsigned long array_size_temp = item.array_size;
- unsigned long max_array_size_temp = item.max_array_size;
+ auto array_size_temp = item.array_size;
+ auto max_array_size_temp = item.max_array_size;
T* array_elements_temp = item.array_elements;
item.array_size = array_size;
@@ -627,7 +645,7 @@ namespace dlib
>
void array::
resize (
- unsigned long new_size
+ size_t new_size
)
{
if (this->max_size() < new_size)
@@ -635,7 +653,7 @@ namespace dlib
array temp;
temp.set_max_size(new_size);
temp.set_size(new_size);
- for (unsigned long i = 0; i < this->size(); ++i)
+ for (size_t i = 0; i < this->size(); ++i)
{
exchange((*this)[i],temp[i]);
}
@@ -750,7 +768,7 @@ namespace dlib
array temp;
temp.set_max_size(this->size()*2 + 1);
temp.set_size(this->size()+1);
- for (unsigned long i = 0; i < this->size(); ++i)
+ for (size_t i = 0; i < this->size(); ++i)
{
exchange((*this)[i],temp[i]);
}
@@ -764,6 +782,17 @@ namespace dlib
}
}
+// ----------------------------------------------------------------------------------------
+
+ template <
+ typename T,
+ typename mem_manager
+ >
+ void array::
+ push_back (
+ T&& item
+ ) { push_back(item); }
+
// ----------------------------------------------------------------------------------------
template
diff --git a/lib/3rdParty/dlib/include/dlib/array/array_kernel_abstract.h b/lib/3rdParty/dlib/include/dlib/array/array_kernel_abstract.h
index 1d714979..5cfdd483 100644
--- a/lib/3rdParty/dlib/include/dlib/array/array_kernel_abstract.h
+++ b/lib/3rdParty/dlib/include/dlib/array/array_kernel_abstract.h
@@ -66,7 +66,7 @@ namespace dlib
!*/
explicit array (
- unsigned long new_size
+ size_t new_size
);
/*!
ensures
@@ -85,6 +85,25 @@ namespace dlib
- all memory associated with *this has been released
!*/
+ array(
+ array&& item
+ );
+ /*!
+ ensures
+ - move constructs *this from item. Therefore, the state of item is
+ moved into *this and #item has a valid but unspecified state.
+ !*/
+
+ array& operator=(
+ array&& item
+ );
+ /*!
+ ensures
+ - move assigns *this from item. Therefore, the state of item is
+ moved into *this and #item has a valid but unspecified state.
+ - returns a reference to #*this
+ !*/
+
void clear (
);
/*!
@@ -97,7 +116,7 @@ namespace dlib
!*/
const T& operator[] (
- unsigned long pos
+ size_t pos
) const;
/*!
requires
@@ -107,7 +126,7 @@ namespace dlib
!*/
T& operator[] (
- unsigned long pos
+ size_t pos
);
/*!
requires
@@ -117,7 +136,7 @@ namespace dlib
!*/
void set_size (
- unsigned long size
+ size_t size
);
/*!
requires
@@ -136,7 +155,7 @@ namespace dlib
if it does throw then the call to set_size() has no effect
!*/
- unsigned long max_size(
+ size_t max_size(
) const;
/*!
ensures
@@ -144,7 +163,7 @@ namespace dlib
!*/
void set_max_size(
- unsigned long max
+ size_t max
);
/*!
ensures
@@ -179,7 +198,7 @@ namespace dlib
!*/
void resize (
- unsigned long new_size
+ size_t new_size
);
/*!
ensures
@@ -255,6 +274,11 @@ namespace dlib
If an exception is thrown then it has no effect on *this.
!*/
+ void push_back (T&& item) { push_back(item); }
+ /*!
+ enable push_back from rvalues
+ !*/
+
typedef T* iterator;
typedef const T* const_iterator;
diff --git a/lib/3rdParty/dlib/include/dlib/array2d/array2d_generic_image.h b/lib/3rdParty/dlib/include/dlib/array2d/array2d_generic_image.h
index 13323376..a96f5e3c 100644
--- a/lib/3rdParty/dlib/include/dlib/array2d/array2d_generic_image.h
+++ b/lib/3rdParty/dlib/include/dlib/array2d/array2d_generic_image.h
@@ -13,6 +13,11 @@ namespace dlib
{
typedef T pixel_type;
};
+ template
+ struct image_traits >
+ {
+ typedef T pixel_type;
+ };
template
inline long num_rows( const array2d& img) { return img.nr(); }
diff --git a/lib/3rdParty/dlib/include/dlib/array2d/array2d_kernel.h b/lib/3rdParty/dlib/include/dlib/array2d/array2d_kernel.h
index c4429824..c3cd9584 100644
--- a/lib/3rdParty/dlib/include/dlib/array2d/array2d_kernel.h
+++ b/lib/3rdParty/dlib/include/dlib/array2d/array2d_kernel.h
@@ -60,6 +60,9 @@ namespace dlib
typedef T type;
typedef mem_manager mem_manager_type;
+ typedef T* iterator;
+ typedef const T* const_iterator;
+
// -----------------------------------
@@ -72,7 +75,7 @@ namespace dlib
- (*this)[x] == data[x]
!*/
- friend class array2d;
+ friend class array2d;
friend class row_helper;
public:
@@ -160,6 +163,24 @@ namespace dlib
set_size(rows,cols);
}
+ array2d(const array2d&) = delete; // copy constructor
+ array2d& operator=(const array2d&) = delete; // assignment operator
+
+#ifdef DLIB_HAS_RVALUE_REFERENCES
+ array2d(array2d&& item) : array2d()
+ {
+ swap(item);
+ }
+
+ array2d& operator= (
+ array2d&& rhs
+ )
+ {
+ swap(rhs);
+ return *this;
+ }
+#endif
+
virtual ~array2d (
) { clear(); }
@@ -294,8 +315,8 @@ namespace dlib
}
}
- unsigned long size (
- ) const { return static_cast(nc_ * nr_); }
+ size_t size (
+ ) const { return static_cast(nc_) * static_cast(nr_); }
long width_step (
) const
@@ -303,6 +324,27 @@ namespace dlib
return nc_*sizeof(T);
}
+ iterator begin()
+ {
+ return data;
+ }
+
+ iterator end()
+ {
+ return data+size();
+ }
+
+ const_iterator begin() const
+ {
+ return data;
+ }
+
+ const_iterator end() const
+ {
+ return data+size();
+ }
+
+
private:
@@ -315,10 +357,6 @@ namespace dlib
T* last;
mutable bool at_start_;
- // restricted functions
- array2d(array2d&); // copy constructor
- array2d& operator=(array2d&); // assignment operator
-
};
// ----------------------------------------------------------------------------------------
diff --git a/lib/3rdParty/dlib/include/dlib/array2d/array2d_kernel_abstract.h b/lib/3rdParty/dlib/include/dlib/array2d/array2d_kernel_abstract.h
index f037522b..daccfc60 100644
--- a/lib/3rdParty/dlib/include/dlib/array2d/array2d_kernel_abstract.h
+++ b/lib/3rdParty/dlib/include/dlib/array2d/array2d_kernel_abstract.h
@@ -64,6 +64,8 @@ namespace dlib
typedef T type;
typedef mem_manager mem_manager_type;
+ typedef T* iterator;
+ typedef const T* const_iterator;
// ----------------------------------------
@@ -122,6 +124,18 @@ namespace dlib
- std::bad_alloc
!*/
+ array2d(const array2d&) = delete; // copy constructor
+ array2d& operator=(const array2d&) = delete; // assignment operator
+
+ array2d(
+ array2d&& item
+ );
+ /*!
+ ensures
+ - Moves the state of item into *this.
+ - #item is in a valid but unspecified state.
+ !*/
+
array2d (
long rows,
long cols
@@ -218,6 +232,16 @@ namespace dlib
- swaps *this and item
!*/
+ array2d& operator= (
+ array2d&& rhs
+ );
+ /*!
+ ensures
+ - Moves the state of item into *this.
+ - #item is in a valid but unspecified state.
+ - returns #*this
+ !*/
+
long width_step (
) const;
/*!
@@ -233,11 +257,41 @@ namespace dlib
An example of such an object is the dlib::cv_image.
!*/
- private:
+ iterator begin(
+ );
+ /*!
+ ensures
+ - returns a random access iterator pointing to the first element in this
+ object.
+ - The iterator will iterate over the elements of the object in row major
+ order.
+ !*/
- // restricted functions
- array2d(array2d&); // copy constructor
- array2d& operator=(array2d&); // assignment operator
+ iterator end(
+ );
+ /*!
+ ensures
+ - returns a random access iterator pointing to one past the end of the last
+ element in this object.
+ !*/
+
+ const_iterator begin(
+ ) const;
+ /*!
+ ensures
+ - returns a random access iterator pointing to the first element in this
+ object.
+ - The iterator will iterate over the elements of the object in row major
+ order.
+ !*/
+
+ const_iterator end(
+ ) const;
+ /*!
+ ensures
+ - returns a random access iterator pointing to one past the end of the last
+ element in this object.
+ !*/
};
diff --git a/lib/3rdParty/dlib/include/dlib/assert.h b/lib/3rdParty/dlib/include/dlib/assert.h
index cce9645a..370f9c07 100644
--- a/lib/3rdParty/dlib/include/dlib/assert.h
+++ b/lib/3rdParty/dlib/include/dlib/assert.h
@@ -20,12 +20,53 @@
// (C) Copyright Gennaro Prota 2003.
// (C) Copyright Eric Friedman 2003.
// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef BOOST_JOIN
-#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )
-#define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)
-#define BOOST_DO_JOIN2( X, Y ) X##Y
+//
+#ifndef DLIB_BOOST_JOIN
+#define DLIB_BOOST_JOIN( X, Y ) DLIB_BOOST_DO_JOIN( X, Y )
+#define DLIB_BOOST_DO_JOIN( X, Y ) DLIB_BOOST_DO_JOIN2(X,Y)
+#define DLIB_BOOST_DO_JOIN2( X, Y ) X##Y
#endif
+// figure out if the compiler has rvalue references.
+#if defined(__clang__)
+# if __has_feature(cxx_rvalue_references)
+# define DLIB_HAS_RVALUE_REFERENCES
+# endif
+# if __has_feature(cxx_generalized_initializers)
+# define DLIB_HAS_INITIALIZER_LISTS
+# endif
+#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) && defined(__GXX_EXPERIMENTAL_CXX0X__)
+# define DLIB_HAS_RVALUE_REFERENCES
+# define DLIB_HAS_INITIALIZER_LISTS
+#elif defined(_MSC_VER) && _MSC_VER >= 1800
+# define DLIB_HAS_INITIALIZER_LISTS
+# define DLIB_HAS_RVALUE_REFERENCES
+#elif defined(_MSC_VER) && _MSC_VER >= 1600
+# define DLIB_HAS_RVALUE_REFERENCES
+#elif defined(__INTEL_COMPILER) && defined(BOOST_INTEL_STDCXX0X)
+# define DLIB_HAS_RVALUE_REFERENCES
+# define DLIB_HAS_INITIALIZER_LISTS
+#endif
+
+#if defined(__APPLE__) && defined(__GNUC_LIBSTD__) && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402)
+ // Apple has not updated libstdc++ in some time and anything under 4.02 does not have for sure.
+# undef DLIB_HAS_INITIALIZER_LISTS
+#endif
+
+// figure out if the compiler has static_assert.
+#if defined(__clang__)
+# if __has_feature(cxx_static_assert)
+# define DLIB_HAS_STATIC_ASSERT
+# endif
+#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) && defined(__GXX_EXPERIMENTAL_CXX0X__)
+# define DLIB_HAS_STATIC_ASSERT
+#elif defined(_MSC_VER) && _MSC_VER >= 1600
+# define DLIB_HAS_STATIC_ASSERT
+#elif defined(__INTEL_COMPILER) && defined(BOOST_INTEL_STDCXX0X)
+# define DLIB_HAS_STATIC_ASSERT
+#endif
+
+
// -----------------------------
namespace dlib
@@ -37,6 +78,9 @@ namespace dlib
template struct assert_are_same_type {enum{value=1};};
template struct assert_are_not_same_type {enum{value=1}; };
template struct assert_are_not_same_type {};
+
+ template struct assert_types_match {enum{value=0};};
+ template struct assert_types_match {enum{value=1};};
}
@@ -48,14 +92,22 @@ namespace dlib
#define DLIB_NO_WARN_UNUSED
#endif
-#define COMPILE_TIME_ASSERT(expression) \
- DLIB_NO_WARN_UNUSED typedef char BOOST_JOIN(DLIB_CTA, __LINE__)[::dlib::compile_time_assert<(bool)(expression)>::value]
+// Use the newer static_assert if it's available since it produces much more readable error
+// messages.
+#ifdef DLIB_HAS_STATIC_ASSERT
+ #define COMPILE_TIME_ASSERT(expression) static_assert(expression, "Failed assertion")
+ #define ASSERT_ARE_SAME_TYPE(type1, type2) static_assert(::dlib::assert_types_match::value, "These types should be the same but aren't.")
+ #define ASSERT_ARE_NOT_SAME_TYPE(type1, type2) static_assert(!::dlib::assert_types_match::value, "These types should NOT be the same.")
+#else
+ #define COMPILE_TIME_ASSERT(expression) \
+ DLIB_NO_WARN_UNUSED typedef char DLIB_BOOST_JOIN(DLIB_CTA, __LINE__)[::dlib::compile_time_assert<(bool)(expression)>::value]
-#define ASSERT_ARE_SAME_TYPE(type1, type2) \
- DLIB_NO_WARN_UNUSED typedef char BOOST_JOIN(DLIB_AAST, __LINE__)[::dlib::assert_are_same_type::value]
+ #define ASSERT_ARE_SAME_TYPE(type1, type2) \
+ DLIB_NO_WARN_UNUSED typedef char DLIB_BOOST_JOIN(DLIB_AAST, __LINE__)[::dlib::assert_are_same_type::value]
-#define ASSERT_ARE_NOT_SAME_TYPE(type1, type2) \
- DLIB_NO_WARN_UNUSED typedef char BOOST_JOIN(DLIB_AANST, __LINE__)[::dlib::assert_are_not_same_type::value]
+ #define ASSERT_ARE_NOT_SAME_TYPE(type1, type2) \
+ DLIB_NO_WARN_UNUSED typedef char DLIB_BOOST_JOIN(DLIB_AANST, __LINE__)[::dlib::assert_are_not_same_type::value]
+#endif
// -----------------------------
@@ -88,7 +140,7 @@ namespace dlib
#define DLIB_FUNCTION_NAME "unknown function"
#endif
-#define DLIB_CASSERT(_exp,_message) \
+#define DLIBM_CASSERT(_exp,_message) \
{if ( !(_exp) ) \
{ \
dlib_assert_breakpoint(); \
@@ -101,12 +153,22 @@ namespace dlib
throw dlib::fatal_error(dlib::EBROKEN_ASSERT,dlib_o_out.str()); \
}}
+// This macro is not needed if you have a real C++ compiler. It's here to work around bugs in Visual Studio's preprocessor.
+#define DLIB_WORKAROUND_VISUAL_STUDIO_BUGS(x) x
+// Make it so the 2nd argument of DLIB_CASSERT is optional. That is, you can call it like
+// DLIB_CASSERT(exp) or DLIB_CASSERT(exp,message).
+#define DLIBM_CASSERT_1_ARGS(exp) DLIBM_CASSERT(exp,"")
+#define DLIBM_CASSERT_2_ARGS(exp,message) DLIBM_CASSERT(exp,message)
+#define DLIBM_GET_3TH_ARG(arg1, arg2, arg3, ...) arg3
+#define DLIBM_CASSERT_CHOOSER(...) DLIB_WORKAROUND_VISUAL_STUDIO_BUGS(DLIBM_GET_3TH_ARG(__VA_ARGS__, DLIBM_CASSERT_2_ARGS, DLIBM_CASSERT_1_ARGS))
+#define DLIB_CASSERT(...) DLIB_WORKAROUND_VISUAL_STUDIO_BUGS(DLIBM_CASSERT_CHOOSER(__VA_ARGS__)(__VA_ARGS__))
+
#ifdef ENABLE_ASSERTS
- #define DLIB_ASSERT(_exp,_message) DLIB_CASSERT(_exp,_message)
+ #define DLIB_ASSERT(...) DLIB_CASSERT(__VA_ARGS__)
#define DLIB_IF_ASSERT(exp) exp
#else
- #define DLIB_ASSERT(_exp,_message)
+ #define DLIB_ASSERT(...) {}
#define DLIB_IF_ASSERT(exp)
#endif
@@ -126,8 +188,8 @@ namespace dlib
!*/
// Use the fact that in C++03 you can't put non-PODs into a union.
#define DLIB_ASSERT_HAS_STANDARD_LAYOUT(type) \
- union BOOST_JOIN(DAHSL_,__LINE__) { type TYPE_NOT_STANDARD_LAYOUT; }; \
- DLIB_NO_WARN_UNUSED typedef char BOOST_JOIN(DAHSL2_,__LINE__)[sizeof(BOOST_JOIN(DAHSL_,__LINE__))];
+ union DLIB_BOOST_JOIN(DAHSL_,__LINE__) { type TYPE_NOT_STANDARD_LAYOUT; }; \
+ DLIB_NO_WARN_UNUSED typedef char DLIB_BOOST_JOIN(DAHSL2_,__LINE__)[sizeof(DLIB_BOOST_JOIN(DAHSL_,__LINE__))];
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
diff --git a/lib/3rdParty/dlib/include/dlib/base64/base64_kernel_1.cpp b/lib/3rdParty/dlib/include/dlib/base64/base64_kernel_1.cpp
deleted file mode 100644
index 06cae3d9..00000000
--- a/lib/3rdParty/dlib/include/dlib/base64/base64_kernel_1.cpp
+++ /dev/null
@@ -1,403 +0,0 @@
-// Copyright (C) 2006 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef DLIB_BASE64_KERNEL_1_CPp_
-#define DLIB_BASE64_KERNEL_1_CPp_
-
-#include "base64_kernel_1.h"
-#include
-#include
-#include
-
-namespace dlib
-{
-
-// ----------------------------------------------------------------------------------------
-
- base64::line_ending_type base64::
- line_ending (
- ) const
- {
- return eol_style;
- }
-
-// ----------------------------------------------------------------------------------------
-
- void base64::
- set_line_ending (
- line_ending_type eol_style_
- )
- {
- eol_style = eol_style_;
- }
-
-// ----------------------------------------------------------------------------------------
-
- base64::
- base64 (
- ) :
- encode_table(0),
- decode_table(0),
- bad_value(100),
- eol_style(LF)
- {
- try
- {
- encode_table = new char[64];
- decode_table = new unsigned char[UCHAR_MAX];
- }
- catch (...)
- {
- if (encode_table) delete [] encode_table;
- if (decode_table) delete [] decode_table;
- throw;
- }
-
- // now set up the tables with the right stuff
- encode_table[0] = 'A';
- encode_table[17] = 'R';
- encode_table[34] = 'i';
- encode_table[51] = 'z';
-
- encode_table[1] = 'B';
- encode_table[18] = 'S';
- encode_table[35] = 'j';
- encode_table[52] = '0';
-
- encode_table[2] = 'C';
- encode_table[19] = 'T';
- encode_table[36] = 'k';
- encode_table[53] = '1';
-
- encode_table[3] = 'D';
- encode_table[20] = 'U';
- encode_table[37] = 'l';
- encode_table[54] = '2';
-
- encode_table[4] = 'E';
- encode_table[21] = 'V';
- encode_table[38] = 'm';
- encode_table[55] = '3';
-
- encode_table[5] = 'F';
- encode_table[22] = 'W';
- encode_table[39] = 'n';
- encode_table[56] = '4';
-
- encode_table[6] = 'G';
- encode_table[23] = 'X';
- encode_table[40] = 'o';
- encode_table[57] = '5';
-
- encode_table[7] = 'H';
- encode_table[24] = 'Y';
- encode_table[41] = 'p';
- encode_table[58] = '6';
-
- encode_table[8] = 'I';
- encode_table[25] = 'Z';
- encode_table[42] = 'q';
- encode_table[59] = '7';
-
- encode_table[9] = 'J';
- encode_table[26] = 'a';
- encode_table[43] = 'r';
- encode_table[60] = '8';
-
- encode_table[10] = 'K';
- encode_table[27] = 'b';
- encode_table[44] = 's';
- encode_table[61] = '9';
-
- encode_table[11] = 'L';
- encode_table[28] = 'c';
- encode_table[45] = 't';
- encode_table[62] = '+';
-
- encode_table[12] = 'M';
- encode_table[29] = 'd';
- encode_table[46] = 'u';
- encode_table[63] = '/';
-
- encode_table[13] = 'N';
- encode_table[30] = 'e';
- encode_table[47] = 'v';
-
- encode_table[14] = 'O';
- encode_table[31] = 'f';
- encode_table[48] = 'w';
-
- encode_table[15] = 'P';
- encode_table[32] = 'g';
- encode_table[49] = 'x';
-
- encode_table[16] = 'Q';
- encode_table[33] = 'h';
- encode_table[50] = 'y';
-
-
-
- // we can now fill out the decode_table by using the encode_table
- for (int i = 0; i < UCHAR_MAX; ++i)
- {
- decode_table[i] = bad_value;
- }
- for (unsigned char i = 0; i < 64; ++i)
- {
- decode_table[(unsigned char)encode_table[i]] = i;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- base64::
- ~base64 (
- )
- {
- delete [] encode_table;
- delete [] decode_table;
- }
-
-// ----------------------------------------------------------------------------------------
-
- void base64::
- encode (
- std::istream& in_,
- std::ostream& out_
- ) const
- {
- using namespace std;
- streambuf& in = *in_.rdbuf();
- streambuf& out = *out_.rdbuf();
-
- unsigned char inbuf[3];
- unsigned char outbuf[4];
- streamsize status = in.sgetn(reinterpret_cast(&inbuf),3);
-
- unsigned char c1, c2, c3, c4, c5, c6;
-
- int counter = 19;
-
- // while we haven't hit the end of the input stream
- while (status != 0)
- {
- if (counter == 0)
- {
- counter = 19;
- // write a newline
- char ch;
- switch (eol_style)
- {
- case CR:
- ch = '\r';
- if (out.sputn(&ch,1)!=1)
- throw std::ios_base::failure("error occured in the base64 object");
- break;
- case LF:
- ch = '\n';
- if (out.sputn(&ch,1)!=1)
- throw std::ios_base::failure("error occured in the base64 object");
- break;
- case CRLF:
- ch = '\r';
- if (out.sputn(&ch,1)!=1)
- throw std::ios_base::failure("error occured in the base64 object");
- ch = '\n';
- if (out.sputn(&ch,1)!=1)
- throw std::ios_base::failure("error occured in the base64 object");
- break;
- default:
- DLIB_CASSERT(false,"this should never happen");
- }
- }
- --counter;
-
- if (status == 3)
- {
- // encode the bytes in inbuf to base64 and write them to the output stream
- c1 = inbuf[0]&0xfc;
- c2 = inbuf[0]&0x03;
- c3 = inbuf[1]&0xf0;
- c4 = inbuf[1]&0x0f;
- c5 = inbuf[2]&0xc0;
- c6 = inbuf[2]&0x3f;
-
- outbuf[0] = c1>>2;
- outbuf[1] = (c2<<4)|(c3>>4);
- outbuf[2] = (c4<<2)|(c5>>6);
- outbuf[3] = c6;
-
-
- outbuf[0] = encode_table[outbuf[0]];
- outbuf[1] = encode_table[outbuf[1]];
- outbuf[2] = encode_table[outbuf[2]];
- outbuf[3] = encode_table[outbuf[3]];
-
- // write the encoded bytes to the output stream
- if (out.sputn(reinterpret_cast(&outbuf),4)!=4)
- {
- throw std::ios_base::failure("error occured in the base64 object");
- }
-
- // get 3 more input bytes
- status = in.sgetn(reinterpret_cast(&inbuf),3);
- continue;
- }
- else if (status == 2)
- {
- // we are at the end of the input stream and need to add some padding
-
- // encode the bytes in inbuf to base64 and write them to the output stream
- c1 = inbuf[0]&0xfc;
- c2 = inbuf[0]&0x03;
- c3 = inbuf[1]&0xf0;
- c4 = inbuf[1]&0x0f;
- c5 = 0;
-
- outbuf[0] = c1>>2;
- outbuf[1] = (c2<<4)|(c3>>4);
- outbuf[2] = (c4<<2)|(c5>>6);
- outbuf[3] = '=';
-
- outbuf[0] = encode_table[outbuf[0]];
- outbuf[1] = encode_table[outbuf[1]];
- outbuf[2] = encode_table[outbuf[2]];
-
- // write the encoded bytes to the output stream
- if (out.sputn(reinterpret_cast(&outbuf),4)!=4)
- {
- throw std::ios_base::failure("error occured in the base64 object");
- }
-
-
- break;
- }
- else // in this case status must be 1
- {
- // we are at the end of the input stream and need to add some padding
-
- // encode the bytes in inbuf to base64 and write them to the output stream
- c1 = inbuf[0]&0xfc;
- c2 = inbuf[0]&0x03;
- c3 = 0;
-
- outbuf[0] = c1>>2;
- outbuf[1] = (c2<<4)|(c3>>4);
- outbuf[2] = '=';
- outbuf[3] = '=';
-
- outbuf[0] = encode_table[outbuf[0]];
- outbuf[1] = encode_table[outbuf[1]];
-
-
- // write the encoded bytes to the output stream
- if (out.sputn(reinterpret_cast(&outbuf),4)!=4)
- {
- throw std::ios_base::failure("error occured in the base64 object");
- }
-
- break;
- }
- } // while (status != 0)
-
-
- // make sure the stream buffer flushes to its I/O channel
- out.pubsync();
- }
-
-// ----------------------------------------------------------------------------------------
-
- void base64::
- decode (
- std::istream& in_,
- std::ostream& out_
- ) const
- {
- using namespace std;
- streambuf& in = *in_.rdbuf();
- streambuf& out = *out_.rdbuf();
-
- unsigned char inbuf[4];
- unsigned char outbuf[3];
- int inbuf_pos = 0;
- streamsize status = in.sgetn(reinterpret_cast(inbuf),1);
-
- // only count this character if it isn't some kind of filler
- if (status == 1 && decode_table[inbuf[0]] != bad_value )
- ++inbuf_pos;
-
- unsigned char c1, c2, c3, c4, c5, c6;
- streamsize outsize;
-
- // while we haven't hit the end of the input stream
- while (status != 0)
- {
- // if we have 4 valid characters
- if (inbuf_pos == 4)
- {
- inbuf_pos = 0;
-
- // this might be the end of the encoded data so we need to figure out if
- // there was any padding applied.
- outsize = 3;
- if (inbuf[3] == '=')
- {
- if (inbuf[2] == '=')
- outsize = 1;
- else
- outsize = 2;
- }
-
- // decode the incoming characters
- inbuf[0] = decode_table[inbuf[0]];
- inbuf[1] = decode_table[inbuf[1]];
- inbuf[2] = decode_table[inbuf[2]];
- inbuf[3] = decode_table[inbuf[3]];
-
-
- // now pack these guys into bytes rather than 6 bit chunks
- c1 = inbuf[0]<<2;
- c2 = inbuf[1]>>4;
- c3 = inbuf[1]<<4;
- c4 = inbuf[2]>>2;
- c5 = inbuf[2]<<6;
- c6 = inbuf[3];
-
- outbuf[0] = c1|c2;
- outbuf[1] = c3|c4;
- outbuf[2] = c5|c6;
-
-
- // write the encoded bytes to the output stream
- if (out.sputn(reinterpret_cast(&outbuf),outsize)!=outsize)
- {
- throw std::ios_base::failure("error occured in the base64 object");
- }
- }
-
- // get more input characters
- status = in.sgetn(reinterpret_cast(inbuf + inbuf_pos),1);
- // only count this character if it isn't some kind of filler
- if ((decode_table[inbuf[inbuf_pos]] != bad_value || inbuf[inbuf_pos] == '=') &&
- status != 0)
- ++inbuf_pos;
- } // while (status != 0)
-
- if (inbuf_pos != 0)
- {
- ostringstream sout;
- sout << inbuf_pos << " extra characters were found at the end of the encoded data."
- << " This may indicate that the data stream has been truncated.";
- // this happens if we hit EOF in the middle of decoding a 24bit block.
- throw decode_error(sout.str());
- }
-
- // make sure the stream buffer flushes to its I/O channel
- out.pubsync();
- }
-
-// ----------------------------------------------------------------------------------------
-
-}
-
-#endif // DLIB_BASE64_KERNEL_1_CPp_
-
diff --git a/lib/3rdParty/dlib/include/dlib/base64/base64_kernel_abstract.h b/lib/3rdParty/dlib/include/dlib/base64/base64_kernel_abstract.h
index 7bd85e13..0a63d3b8 100644
--- a/lib/3rdParty/dlib/include/dlib/base64/base64_kernel_abstract.h
+++ b/lib/3rdParty/dlib/include/dlib/base64/base64_kernel_abstract.h
@@ -93,7 +93,7 @@ namespace dlib
) const;
/*!
ensures
- - reads data from in (until EOF is reached) and decodees it
+ - reads data from in (until EOF is reached), decodes it,
and writes it to out.
throws
- std::ios_base::failure
diff --git a/lib/3rdParty/dlib/include/dlib/bayes_utils/bayes_utils.h b/lib/3rdParty/dlib/include/dlib/bayes_utils/bayes_utils.h
index 72d84729..04b3d118 100644
--- a/lib/3rdParty/dlib/include/dlib/bayes_utils/bayes_utils.h
+++ b/lib/3rdParty/dlib/include/dlib/bayes_utils/bayes_utils.h
@@ -5,6 +5,11 @@
#include "bayes_utils_abstract.h"
+#include
+#include
+#include
+#include
+
#include "../string.h"
#include "../map.h"
#include "../matrix.h"
@@ -13,11 +18,7 @@
#include "../set.h"
#include "../algs.h"
#include "../noncopyable.h"
-#include "../smart_pointers.h"
#include "../graph.h"
-#include
-#include
-#include
namespace dlib
{
@@ -355,7 +356,7 @@ namespace dlib
table.clear();
}
- unsigned long size () const { return table.size(); }
+ size_t size () const { return table.size(); }
bool move_next() const { return table.move_next(); }
void reset() const { table.reset(); }
map_pair& element()
@@ -1659,7 +1660,7 @@ namespace dlib
private:
- scoped_ptr impl;
+ std::unique_ptr impl;
unsigned long num_nodes;
};
diff --git a/lib/3rdParty/dlib/include/dlib/bayes_utils/bayes_utils_abstract.h b/lib/3rdParty/dlib/include/dlib/bayes_utils/bayes_utils_abstract.h
index f2ac8643..b19e6e1d 100644
--- a/lib/3rdParty/dlib/include/dlib/bayes_utils/bayes_utils_abstract.h
+++ b/lib/3rdParty/dlib/include/dlib/bayes_utils/bayes_utils_abstract.h
@@ -367,7 +367,7 @@ namespace dlib
std::ostream& out
);
/*!
- provides deserialization support
+ provides serialization support
!*/
void deserialize (
@@ -499,7 +499,7 @@ namespace dlib
std::ostream& out
);
/*!
- provides deserialization support
+ provides serialization support
!*/
void deserialize (
@@ -615,7 +615,7 @@ namespace dlib
std::ostream& out
);
/*!
- provides deserialization support
+ provides serialization support
!*/
void deserialize (
diff --git a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_1.cpp b/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_1.cpp
deleted file mode 100644
index feef761c..00000000
--- a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_1.cpp
+++ /dev/null
@@ -1,1720 +0,0 @@
-// Copyright (C) 2003 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef DLIB_BIGINT_KERNEL_1_CPp_
-#define DLIB_BIGINT_KERNEL_1_CPp_
-#include "bigint_kernel_1.h"
-
-#include
-
-namespace dlib
-{
-
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
- // member/friend function definitions
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1::
- bigint_kernel_1 (
- ) :
- slack(25),
- data(new data_record(slack))
- {}
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1::
- bigint_kernel_1 (
- uint32 value
- ) :
- slack(25),
- data(new data_record(slack))
- {
- *(data->number) = static_cast(value&0xFFFF);
- *(data->number+1) = static_cast((value>>16)&0xFFFF);
- if (*(data->number+1) != 0)
- data->digits_used = 2;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1::
- bigint_kernel_1 (
- const bigint_kernel_1& item
- ) :
- slack(25),
- data(item.data)
- {
- data->references += 1;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1::
- ~bigint_kernel_1 (
- )
- {
- if (data->references == 1)
- {
- delete data;
- }
- else
- {
- data->references -= 1;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 bigint_kernel_1::
- operator+ (
- const bigint_kernel_1& rhs
- ) const
- {
- data_record* temp = new data_record (
- std::max(rhs.data->digits_used,data->digits_used) + slack
- );
- long_add(data,rhs.data,temp);
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator+= (
- const bigint_kernel_1& rhs
- )
- {
- // if there are other references to our data
- if (data->references != 1)
- {
- data_record* temp = new data_record(std::max(data->digits_used,rhs.data->digits_used)+slack);
- data->references -= 1;
- long_add(data,rhs.data,temp);
- data = temp;
- }
- // if data is not big enough for the result
- else if (data->size <= std::max(data->digits_used,rhs.data->digits_used))
- {
- data_record* temp = new data_record(std::max(data->digits_used,rhs.data->digits_used)+slack);
- long_add(data,rhs.data,temp);
- delete data;
- data = temp;
- }
- // there is enough size and no references
- else
- {
- long_add(data,rhs.data,data);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 bigint_kernel_1::
- operator- (
- const bigint_kernel_1& rhs
- ) const
- {
- data_record* temp = new data_record (
- data->digits_used + slack
- );
- long_sub(data,rhs.data,temp);
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator-= (
- const bigint_kernel_1& rhs
- )
- {
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- long_sub(data,rhs.data,temp);
- data = temp;
- }
- else
- {
- long_sub(data,rhs.data,data);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 bigint_kernel_1::
- operator* (
- const bigint_kernel_1& rhs
- ) const
- {
- data_record* temp = new data_record (
- data->digits_used + rhs.data->digits_used + slack
- );
- long_mul(data,rhs.data,temp);
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator*= (
- const bigint_kernel_1& rhs
- )
- {
- // create a data_record to store the result of the multiplication in
- data_record* temp = new data_record(rhs.data->digits_used+data->digits_used+slack);
- long_mul(data,rhs.data,temp);
-
- // if there are other references to data
- if (data->references != 1)
- {
- data->references -= 1;
- }
- else
- {
- delete data;
- }
- data = temp;
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 bigint_kernel_1::
- operator/ (
- const bigint_kernel_1& rhs
- ) const
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data_record* remainder;
- try {
- remainder = new data_record(data->digits_used+slack);
- } catch (...) { delete temp; throw; }
-
- long_div(data,rhs.data,temp,remainder);
- delete remainder;
-
-
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator/= (
- const bigint_kernel_1& rhs
- )
- {
-
- data_record* temp = new data_record(data->digits_used+slack);
- data_record* remainder;
- try {
- remainder = new data_record(data->digits_used+slack);
- } catch (...) { delete temp; throw; }
-
- long_div(data,rhs.data,temp,remainder);
-
- // check if there are other references to data
- if (data->references != 1)
- {
- data->references -= 1;
- }
- // if there are no references to data then it must be deleted
- else
- {
- delete data;
- }
- data = temp;
- delete remainder;
-
-
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 bigint_kernel_1::
- operator% (
- const bigint_kernel_1& rhs
- ) const
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data_record* remainder;
- try {
- remainder = new data_record(data->digits_used+slack);
- } catch (...) { delete temp; throw; }
-
- long_div(data,rhs.data,temp,remainder);
- delete temp;
- return bigint_kernel_1(remainder,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator%= (
- const bigint_kernel_1& rhs
- )
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data_record* remainder;
- try {
- remainder = new data_record(data->digits_used+slack);
- } catch (...) { delete temp; throw; }
-
- long_div(data,rhs.data,temp,remainder);
-
- // check if there are other references to data
- if (data->references != 1)
- {
- data->references -= 1;
- }
- // if there are no references to data then it must be deleted
- else
- {
- delete data;
- }
- data = remainder;
- delete temp;
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bigint_kernel_1::
- operator < (
- const bigint_kernel_1& rhs
- ) const
- {
- return is_less_than(data,rhs.data);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bigint_kernel_1::
- operator == (
- const bigint_kernel_1& rhs
- ) const
- {
- return is_equal_to(data,rhs.data);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator= (
- const bigint_kernel_1& rhs
- )
- {
- if (this == &rhs)
- return *this;
-
- // if we have the only reference to our data then delete it
- if (data->references == 1)
- {
- delete data;
- data = rhs.data;
- data->references += 1;
- }
- else
- {
- data->references -= 1;
- data = rhs.data;
- data->references += 1;
- }
-
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- std::ostream& operator<< (
- std::ostream& out_,
- const bigint_kernel_1& rhs
- )
- {
- std::ostream out(out_.rdbuf());
-
- typedef bigint_kernel_1 bigint;
-
- bigint::data_record* temp = new bigint::data_record(*rhs.data,0);
-
-
-
- // get a char array big enough to hold the number in ascii format
- char* str;
- try {
- str = new char[(rhs.data->digits_used)*5+10];
- } catch (...) { delete temp; throw; }
-
- char* str_start = str;
- str += (rhs.data->digits_used)*5+9;
- *str = 0; --str;
-
-
- uint16 remainder;
- rhs.short_div(temp,10000,temp,remainder);
-
- // pull the digits out of remainder
- char a = remainder % 10 + '0';
- remainder /= 10;
- char b = remainder % 10 + '0';
- remainder /= 10;
- char c = remainder % 10 + '0';
- remainder /= 10;
- char d = remainder % 10 + '0';
- remainder /= 10;
-
-
- *str = a; --str;
- *str = b; --str;
- *str = c; --str;
- *str = d; --str;
-
-
- // keep looping until temp represents zero
- while (temp->digits_used != 1 || *(temp->number) != 0)
- {
- rhs.short_div(temp,10000,temp,remainder);
-
- // pull the digits out of remainder
- char a = remainder % 10 + '0';
- remainder /= 10;
- char b = remainder % 10 + '0';
- remainder /= 10;
- char c = remainder % 10 + '0';
- remainder /= 10;
- char d = remainder % 10 + '0';
- remainder /= 10;
-
- *str = a; --str;
- *str = b; --str;
- *str = c; --str;
- *str = d; --str;
- }
-
- // throw away and extra leading zeros
- ++str;
- if (*str == '0')
- ++str;
- if (*str == '0')
- ++str;
- if (*str == '0')
- ++str;
-
-
-
-
- out << str;
- delete [] str_start;
- delete temp;
- return out_;
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- std::istream& operator>> (
- std::istream& in_,
- bigint_kernel_1& rhs
- )
- {
- std::istream in(in_.rdbuf());
-
- // ignore any leading whitespaces
- while (in.peek() == ' ' || in.peek() == '\t' || in.peek() == '\n')
- {
- in.get();
- }
-
- // if the first digit is not an integer then this is an error
- if ( !(in.peek() >= '0' && in.peek() <= '9'))
- {
- in_.clear(std::ios::failbit);
- return in_;
- }
-
- int num_read;
- bigint_kernel_1 temp;
- do
- {
-
- // try to get 4 chars from in
- num_read = 1;
- char a = 0;
- char b = 0;
- char c = 0;
- char d = 0;
-
- if (in.peek() >= '0' && in.peek() <= '9')
- {
- num_read *= 10;
- a = in.get();
- }
- if (in.peek() >= '0' && in.peek() <= '9')
- {
- num_read *= 10;
- b = in.get();
- }
- if (in.peek() >= '0' && in.peek() <= '9')
- {
- num_read *= 10;
- c = in.get();
- }
- if (in.peek() >= '0' && in.peek() <= '9')
- {
- num_read *= 10;
- d = in.get();
- }
-
- // merge the for digits into an uint16
- uint16 num = 0;
- if (a != 0)
- {
- num = a - '0';
- }
- if (b != 0)
- {
- num *= 10;
- num += b - '0';
- }
- if (c != 0)
- {
- num *= 10;
- num += c - '0';
- }
- if (d != 0)
- {
- num *= 10;
- num += d - '0';
- }
-
-
- if (num_read != 1)
- {
- // shift the digits in temp left by the number of new digits we just read
- temp *= num_read;
- // add in new digits
- temp += num;
- }
-
- } while (num_read == 10000);
-
-
- rhs = temp;
- return in_;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 operator+ (
- uint16 lhs,
- const bigint_kernel_1& rhs
- )
- {
- typedef bigint_kernel_1 bigint;
- bigint::data_record* temp = new bigint::data_record
- (rhs.data->digits_used+rhs.slack);
-
- rhs.short_add(rhs.data,lhs,temp);
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 operator+ (
- const bigint_kernel_1& lhs,
- uint16 rhs
- )
- {
- typedef bigint_kernel_1 bigint;
- bigint::data_record* temp = new bigint::data_record
- (lhs.data->digits_used+lhs.slack);
-
- lhs.short_add(lhs.data,rhs,temp);
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator+= (
- uint16 rhs
- )
- {
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- short_add(data,rhs,temp);
- data = temp;
- }
- // or if we need to enlarge data then do so
- else if (data->digits_used == data->size)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- short_add(data,rhs,temp);
- delete data;
- data = temp;
- }
- // or if there is plenty of space and no references
- else
- {
- short_add(data,rhs,data);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 operator- (
- uint16 lhs,
- const bigint_kernel_1& rhs
- )
- {
- typedef bigint_kernel_1 bigint;
- bigint::data_record* temp = new bigint::data_record(rhs.slack);
-
- *(temp->number) = lhs - *(rhs.data->number);
-
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 operator- (
- const bigint_kernel_1& lhs,
- uint16 rhs
- )
- {
- typedef bigint_kernel_1 bigint;
- bigint::data_record* temp = new bigint::data_record
- (lhs.data->digits_used+lhs.slack);
-
- lhs.short_sub(lhs.data,rhs,temp);
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator-= (
- uint16 rhs
- )
- {
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- short_sub(data,rhs,temp);
- data = temp;
- }
- else
- {
- short_sub(data,rhs,data);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 operator* (
- uint16 lhs,
- const bigint_kernel_1& rhs
- )
- {
- typedef bigint_kernel_1 bigint;
- bigint::data_record* temp = new bigint::data_record
- (rhs.data->digits_used+rhs.slack);
-
- rhs.short_mul(rhs.data,lhs,temp);
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 operator* (
- const bigint_kernel_1& lhs,
- uint16 rhs
- )
- {
- typedef bigint_kernel_1 bigint;
- bigint::data_record* temp = new bigint::data_record
- (lhs.data->digits_used+lhs.slack);
-
- lhs.short_mul(lhs.data,rhs,temp);
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator*= (
- uint16 rhs
- )
- {
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- short_mul(data,rhs,temp);
- data = temp;
- }
- // or if we need to enlarge data
- else if (data->digits_used == data->size)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- short_mul(data,rhs,temp);
- delete data;
- data = temp;
- }
- else
- {
- short_mul(data,rhs,data);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 operator/ (
- uint16 lhs,
- const bigint_kernel_1& rhs
- )
- {
- typedef bigint_kernel_1 bigint;
- bigint::data_record* temp = new bigint::data_record(rhs.slack);
-
- // if rhs might not be bigger than lhs
- if (rhs.data->digits_used == 1)
- {
- *(temp->number) = lhs/ *(rhs.data->number);
- }
-
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 operator/ (
- const bigint_kernel_1& lhs,
- uint16 rhs
- )
- {
- typedef bigint_kernel_1 bigint;
- bigint::data_record* temp = new bigint::data_record
- (lhs.data->digits_used+lhs.slack);
-
- uint16 remainder;
- lhs.short_div(lhs.data,rhs,temp,remainder);
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator/= (
- uint16 rhs
- )
- {
- uint16 remainder;
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- short_div(data,rhs,temp,remainder);
- data = temp;
- }
- else
- {
- short_div(data,rhs,data,remainder);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 operator% (
- uint16 lhs,
- const bigint_kernel_1& rhs
- )
- {
- typedef bigint_kernel_1 bigint;
- // temp is zero by default
- bigint::data_record* temp = new bigint::data_record(rhs.slack);
-
- if (rhs.data->digits_used == 1)
- {
- // if rhs is just an uint16 inside then perform the modulus
- *(temp->number) = lhs % *(rhs.data->number);
- }
- else
- {
- // if rhs is bigger than lhs then the answer is lhs
- *(temp->number) = lhs;
- }
-
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 operator% (
- const bigint_kernel_1& lhs,
- uint16 rhs
- )
- {
- typedef bigint_kernel_1 bigint;
- bigint::data_record* temp = new bigint::data_record(lhs.data->digits_used+lhs.slack);
-
- uint16 remainder;
-
- lhs.short_div(lhs.data,rhs,temp,remainder);
- temp->digits_used = 1;
- *(temp->number) = remainder;
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator%= (
- uint16 rhs
- )
- {
- uint16 remainder;
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- short_div(data,rhs,temp,remainder);
- data = temp;
- }
- else
- {
- short_div(data,rhs,data,remainder);
- }
-
- data->digits_used = 1;
- *(data->number) = remainder;
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool operator < (
- uint16 lhs,
- const bigint_kernel_1& rhs
- )
- {
- return (rhs.data->digits_used > 1 || lhs < *(rhs.data->number) );
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool operator < (
- const bigint_kernel_1& lhs,
- uint16 rhs
- )
- {
- return (lhs.data->digits_used == 1 && *(lhs.data->number) < rhs);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool operator == (
- const bigint_kernel_1& lhs,
- uint16 rhs
- )
- {
- return (lhs.data->digits_used == 1 && *(lhs.data->number) == rhs);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool operator == (
- uint16 lhs,
- const bigint_kernel_1& rhs
- )
- {
- return (rhs.data->digits_used == 1 && *(rhs.data->number) == lhs);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator= (
- uint16 rhs
- )
- {
- // check if there are other references to our data
- if (data->references != 1)
- {
- data->references -= 1;
- try {
- data = new data_record(slack);
- } catch (...) { data->references += 1; throw; }
- }
- else
- {
- data->digits_used = 1;
- }
-
- *(data->number) = rhs;
-
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator++ (
- )
- {
- // if there are other references to this data then make a copy of it
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- increment(data,temp);
- data = temp;
- }
- // or if we need to enlarge data then do so
- else if (data->digits_used == data->size)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- increment(data,temp);
- delete data;
- data = temp;
- }
- else
- {
- increment(data,data);
- }
-
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 bigint_kernel_1::
- operator++ (
- int
- )
- {
- data_record* temp; // this is the copy of temp we will return in the end
-
- data_record* temp2 = new data_record(data->digits_used+slack);
- increment(data,temp2);
-
- temp = data;
- data = temp2;
-
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_1& bigint_kernel_1::
- operator-- (
- )
- {
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- decrement(data,temp);
- data = temp;
- }
- else
- {
- decrement(data,data);
- }
-
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_1 bigint_kernel_1::
- operator-- (
- int
- )
- {
- data_record* temp; // this is the copy of temp we will return in the end
-
- data_record* temp2 = new data_record(data->digits_used+slack);
- decrement(data,temp2);
-
- temp = data;
- data = temp2;
-
- return bigint_kernel_1(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
- // private member function definitions
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- short_add (
- const data_record* data,
- uint16 value,
- data_record* result
- ) const
- {
- // put value into the carry part of temp
- uint32 temp = value;
- temp <<= 16;
-
-
- const uint16* number = data->number;
- const uint16* end = number + data->digits_used; // one past the end of number
- uint16* r = result->number;
-
- while (number != end)
- {
- // add *number and the current carry
- temp = *number + (temp>>16);
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
-
- ++number;
- ++r;
- }
-
- // if there is a final carry
- if ((temp>>16) != 0)
- {
- result->digits_used = data->digits_used + 1;
- // store the carry in the most significant digit of the result
- *r = static_cast(temp>>16);
- }
- else
- {
- result->digits_used = data->digits_used;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- short_sub (
- const data_record* data,
- uint16 value,
- data_record* result
- ) const
- {
-
-
- const uint16* number = data->number;
- const uint16* end = number + data->digits_used - 1;
- uint16* r = result->number;
-
- uint32 temp = *number - value;
-
- // put the low word of temp into *data
- *r = static_cast(temp & 0xFFFF);
-
-
- while (number != end)
- {
- ++number;
- ++r;
-
- // subtract the carry from *number
- temp = *number - (temp>>31);
-
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
- }
-
- // if we lost a digit in the subtraction
- if (*r == 0)
- {
- if (data->digits_used == 1)
- result->digits_used = 1;
- else
- result->digits_used = data->digits_used - 1;
- }
- else
- {
- result->digits_used = data->digits_used;
- }
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- short_mul (
- const data_record* data,
- uint16 value,
- data_record* result
- ) const
- {
-
- uint32 temp = 0;
-
-
- const uint16* number = data->number;
- uint16* r = result->number;
- const uint16* end = r + data->digits_used;
-
-
-
- while ( r != end)
- {
-
- // multiply *data and value and add in the carry
- temp = *number*(uint32)value + (temp>>16);
-
- // put the low word of temp into *data
- *r = static_cast(temp & 0xFFFF);
-
- ++number;
- ++r;
- }
-
- // if there is a final carry
- if ((temp>>16) != 0)
- {
- result->digits_used = data->digits_used + 1;
- // put the final carry into the most significant digit of the result
- *r = static_cast(temp>>16);
- }
- else
- {
- result->digits_used = data->digits_used;
- }
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- short_div (
- const data_record* data,
- uint16 value,
- data_record* result,
- uint16& rem
- ) const
- {
-
- uint16 remainder = 0;
- uint32 temp;
-
-
-
- const uint16* number = data->number + data->digits_used - 1;
- const uint16* end = number - data->digits_used;
- uint16* r = result->number + data->digits_used - 1;
-
-
- // if we are losing a digit in this division
- if (*number < value)
- {
- if (data->digits_used == 1)
- result->digits_used = 1;
- else
- result->digits_used = data->digits_used - 1;
- }
- else
- {
- result->digits_used = data->digits_used;
- }
-
-
- // perform the actual division
- while (number != end)
- {
-
- temp = *number + (((uint32)remainder)<<16);
-
- *r = static_cast(temp/value);
- remainder = static_cast(temp%value);
-
- --number;
- --r;
- }
-
- rem = remainder;
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- long_add (
- const data_record* lhs,
- const data_record* rhs,
- data_record* result
- ) const
- {
- // put value into the carry part of temp
- uint32 temp=0;
-
- uint16* min_num; // the number with the least digits used
- uint16* max_num; // the number with the most digits used
- uint16* min_end; // one past the end of min_num
- uint16* max_end; // one past the end of max_num
- uint16* r = result->number;
-
- uint32 max_digits_used;
- if (lhs->digits_used < rhs->digits_used)
- {
- max_digits_used = rhs->digits_used;
- min_num = lhs->number;
- max_num = rhs->number;
- min_end = min_num + lhs->digits_used;
- max_end = max_num + rhs->digits_used;
- }
- else
- {
- max_digits_used = lhs->digits_used;
- min_num = rhs->number;
- max_num = lhs->number;
- min_end = min_num + rhs->digits_used;
- max_end = max_num + lhs->digits_used;
- }
-
-
-
-
- while (min_num != min_end)
- {
- // add *min_num, *max_num and the current carry
- temp = *min_num + *max_num + (temp>>16);
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
-
- ++min_num;
- ++max_num;
- ++r;
- }
-
-
- while (max_num != max_end)
- {
- // add *max_num and the current carry
- temp = *max_num + (temp>>16);
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
-
- ++max_num;
- ++r;
- }
-
- // check if there was a final carry
- if ((temp>>16) != 0)
- {
- result->digits_used = max_digits_used + 1;
- // put the carry into the most significant digit in the result
- *r = static_cast(temp>>16);
- }
- else
- {
- result->digits_used = max_digits_used;
- }
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- long_sub (
- const data_record* lhs,
- const data_record* rhs,
- data_record* result
- ) const
- {
-
-
- const uint16* number1 = lhs->number;
- const uint16* number2 = rhs->number;
- const uint16* end = number2 + rhs->digits_used;
- uint16* r = result->number;
-
-
-
- uint32 temp =0;
-
-
- while (number2 != end)
- {
-
- // subtract *number2 from *number1 and then subtract any carry
- temp = *number1 - *number2 - (temp>>31);
-
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
-
- ++number1;
- ++number2;
- ++r;
- }
-
- end = lhs->number + lhs->digits_used;
- while (number1 != end)
- {
-
- // subtract the carry from *number1
- temp = *number1 - (temp>>31);
-
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
-
- ++number1;
- ++r;
- }
-
- result->digits_used = lhs->digits_used;
- // adjust the number of digits used appropriately
- --r;
- while (*r == 0 && result->digits_used > 1)
- {
- --r;
- --result->digits_used;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- long_div (
- const data_record* lhs,
- const data_record* rhs,
- data_record* result,
- data_record* remainder
- ) const
- {
- // zero result
- result->digits_used = 1;
- *(result->number) = 0;
-
- uint16* a;
- uint16* b;
- uint16* end;
-
- // copy lhs into remainder
- remainder->digits_used = lhs->digits_used;
- a = remainder->number;
- end = a + remainder->digits_used;
- b = lhs->number;
- while (a != end)
- {
- *a = *b;
- ++a;
- ++b;
- }
-
-
- // if rhs is bigger than lhs then result == 0 and remainder == lhs
- // so then we can quit right now
- if (is_less_than(lhs,rhs))
- {
- return;
- }
-
-
- // make a temporary number
- data_record temp(lhs->digits_used + slack);
-
-
- // shift rhs left until it is one shift away from being larger than lhs and
- // put the number of left shifts necessary into shifts
- uint32 shifts;
- shifts = (lhs->digits_used - rhs->digits_used) * 16;
-
- shift_left(rhs,&temp,shifts);
-
-
- // while (lhs > temp)
- while (is_less_than(&temp,lhs))
- {
- shift_left(&temp,&temp,1);
- ++shifts;
- }
- // make sure lhs isn't smaller than temp
- while (is_less_than(lhs,&temp))
- {
- shift_right(&temp,&temp);
- --shifts;
- }
-
-
-
- // we want to execute the loop shifts +1 times
- ++shifts;
- while (shifts != 0)
- {
- shift_left(result,result,1);
- // if (temp <= remainder)
- if (!is_less_than(remainder,&temp))
- {
- long_sub(remainder,&temp,remainder);
-
- // increment result
- uint16* r = result->number;
- uint16* end = r + result->digits_used;
- while (true)
- {
- ++(*r);
- // if there was no carry then we are done
- if (*r != 0)
- break;
-
- ++r;
-
- // if we hit the end of r and there is still a carry then
- // the next digit of r is 1 and there is one more digit used
- if (r == end)
- {
- *r = 1;
- ++(result->digits_used);
- break;
- }
- }
- }
- shift_right(&temp,&temp);
- --shifts;
- }
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- long_mul (
- const data_record* lhs,
- const data_record* rhs,
- data_record* result
- ) const
- {
- // make result be zero
- result->digits_used = 1;
- *(result->number) = 0;
-
-
- const data_record* aa;
- const data_record* bb;
-
- if (lhs->digits_used < rhs->digits_used)
- {
- // make copies of lhs and rhs and give them an appropriate amount of
- // extra memory so there won't be any overflows
- aa = lhs;
- bb = rhs;
- }
- else
- {
- // make copies of lhs and rhs and give them an appropriate amount of
- // extra memory so there won't be any overflows
- aa = rhs;
- bb = lhs;
- }
- // this is where we actually copy lhs and rhs
- data_record b(*bb,aa->digits_used+slack); // the larger(approximately) of lhs and rhs
-
-
- uint32 shift_value = 0;
- uint16* anum = aa->number;
- uint16* end = anum + aa->digits_used;
- while (anum != end )
- {
- uint16 bit = 0x0001;
-
- for (int i = 0; i < 16; ++i)
- {
- // if the specified bit of a is 1
- if ((*anum & bit) != 0)
- {
- shift_left(&b,&b,shift_value);
- shift_value = 0;
- long_add(&b,result,result);
- }
- ++shift_value;
- bit <<= 1;
- }
-
- ++anum;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- shift_left (
- const data_record* data,
- data_record* result,
- uint32 shift_amount
- ) const
- {
- uint32 offset = shift_amount/16;
- shift_amount &= 0xf; // same as shift_amount %= 16;
-
- uint16* r = result->number + data->digits_used + offset; // result
- uint16* end = data->number;
- uint16* s = end + data->digits_used; // source
- const uint32 temp = 16 - shift_amount;
-
- *r = (*(--s) >> temp);
- // set the number of digits used in the result
- // if the upper bits from *s were zero then don't count this first word
- if (*r == 0)
- {
- result->digits_used = data->digits_used + offset;
- }
- else
- {
- result->digits_used = data->digits_used + offset + 1;
- }
- --r;
-
- while (s != end)
- {
- *r = ((*s << shift_amount) | ( *(s-1) >> temp));
- --r;
- --s;
- }
- *r = *s << shift_amount;
-
- // now zero the rest of the result
- end = result->number;
- while (r != end)
- *(--r) = 0;
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- shift_right (
- const data_record* data,
- data_record* result
- ) const
- {
-
- uint16* r = result->number; // result
- uint16* s = data->number; // source
- uint16* end = s + data->digits_used - 1;
-
- while (s != end)
- {
- *r = (*s >> 1) | (*(s+1) << 15);
- ++r;
- ++s;
- }
- *r = *s >> 1;
-
-
- // calculate the new number for digits_used
- if (*r == 0)
- {
- if (data->digits_used != 1)
- result->digits_used = data->digits_used - 1;
- else
- result->digits_used = 1;
- }
- else
- {
- result->digits_used = data->digits_used;
- }
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bigint_kernel_1::
- is_less_than (
- const data_record* lhs,
- const data_record* rhs
- ) const
- {
- uint32 lhs_digits_used = lhs->digits_used;
- uint32 rhs_digits_used = rhs->digits_used;
-
- // if lhs is definitely less than rhs
- if (lhs_digits_used < rhs_digits_used )
- return true;
- // if lhs is definitely greater than rhs
- else if (lhs_digits_used > rhs_digits_used)
- return false;
- else
- {
- uint16* end = lhs->number;
- uint16* l = end + lhs_digits_used;
- uint16* r = rhs->number + rhs_digits_used;
-
- while (l != end)
- {
- --l;
- --r;
- if (*l < *r)
- return true;
- else if (*l > *r)
- return false;
- }
-
- // at this point we know that they are equal
- return false;
- }
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bigint_kernel_1::
- is_equal_to (
- const data_record* lhs,
- const data_record* rhs
- ) const
- {
- // if lhs and rhs are definitely not equal
- if (lhs->digits_used != rhs->digits_used )
- {
- return false;
- }
- else
- {
- uint16* l = lhs->number;
- uint16* r = rhs->number;
- uint16* end = l + lhs->digits_used;
-
- while (l != end)
- {
- if (*l != *r)
- return false;
- ++l;
- ++r;
- }
-
- // at this point we know that they are equal
- return true;
- }
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- increment (
- const data_record* source,
- data_record* dest
- ) const
- {
- uint16* s = source->number;
- uint16* d = dest->number;
- uint16* end = s + source->digits_used;
- while (true)
- {
- *d = *s + 1;
-
- // if there was no carry then break out of the loop
- if (*d != 0)
- {
- dest->digits_used = source->digits_used;
-
- // copy the rest of the digits over to d
- ++d; ++s;
- while (s != end)
- {
- *d = *s;
- ++d;
- ++s;
- }
-
- break;
- }
-
-
- ++s;
-
- // if we have hit the end of s and there was a carry up to this point
- // then just make the next digit 1 and add one to the digits used
- if (s == end)
- {
- ++d;
- dest->digits_used = source->digits_used + 1;
- *d = 1;
- break;
- }
-
- ++d;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_1::
- decrement (
- const data_record* source,
- data_record* dest
- ) const
- {
- uint16* s = source->number;
- uint16* d = dest->number;
- uint16* end = s + source->digits_used;
- while (true)
- {
- *d = *s - 1;
-
- // if there was no carry then break out of the loop
- if (*d != 0xFFFF)
- {
- // if we lost a digit in the subtraction
- if (*d == 0 && s+1 == end)
- {
- if (source->digits_used == 1)
- dest->digits_used = 1;
- else
- dest->digits_used = source->digits_used - 1;
- }
- else
- {
- dest->digits_used = source->digits_used;
- }
- break;
- }
- else
- {
- ++d;
- ++s;
- }
-
- }
-
- // copy the rest of the digits over to d
- ++d;
- ++s;
- while (s != end)
- {
- *d = *s;
- ++d;
- ++s;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
-}
-#endif // DLIB_BIGINT_KERNEL_1_CPp_
-
diff --git a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_1.h b/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_1.h
index 12a51d0f..3e7f3d85 100644
--- a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_1.h
+++ b/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_1.h
@@ -12,7 +12,6 @@
namespace dlib
{
- using namespace dlib::relational_operators; // defined in algs.h
class bigint_kernel_1
{
@@ -531,6 +530,10 @@ namespace dlib
}
}
+ inline bool operator> (const bigint_kernel_1& a, const bigint_kernel_1& b) { return b < a; }
+ inline bool operator!= (const bigint_kernel_1& a, const bigint_kernel_1& b) { return !(a == b); }
+ inline bool operator<= (const bigint_kernel_1& a, const bigint_kernel_1& b) { return !(b < a); }
+ inline bool operator>= (const bigint_kernel_1& a, const bigint_kernel_1& b) { return !(a < b); }
}
#ifdef NO_MAKEFILE
diff --git a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_2.cpp b/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_2.cpp
deleted file mode 100644
index 005e080a..00000000
--- a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_2.cpp
+++ /dev/null
@@ -1,1945 +0,0 @@
-// Copyright (C) 2003 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef DLIB_BIGINT_KERNEL_2_CPp_
-#define DLIB_BIGINT_KERNEL_2_CPp_
-#include "bigint_kernel_2.h"
-
-#include
-#include
-
-namespace dlib
-{
-
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
- // member/friend function definitions
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2::
- bigint_kernel_2 (
- ) :
- slack(25),
- data(new data_record(slack))
- {}
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2::
- bigint_kernel_2 (
- uint32 value
- ) :
- slack(25),
- data(new data_record(slack))
- {
- *(data->number) = static_cast(value&0xFFFF);
- *(data->number+1) = static_cast((value>>16)&0xFFFF);
- if (*(data->number+1) != 0)
- data->digits_used = 2;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2::
- bigint_kernel_2 (
- const bigint_kernel_2& item
- ) :
- slack(25),
- data(item.data)
- {
- data->references += 1;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2::
- ~bigint_kernel_2 (
- )
- {
- if (data->references == 1)
- {
- delete data;
- }
- else
- {
- data->references -= 1;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 bigint_kernel_2::
- operator+ (
- const bigint_kernel_2& rhs
- ) const
- {
- data_record* temp = new data_record (
- std::max(rhs.data->digits_used,data->digits_used) + slack
- );
- long_add(data,rhs.data,temp);
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator+= (
- const bigint_kernel_2& rhs
- )
- {
- // if there are other references to our data
- if (data->references != 1)
- {
- data_record* temp = new data_record(std::max(data->digits_used,rhs.data->digits_used)+slack);
- data->references -= 1;
- long_add(data,rhs.data,temp);
- data = temp;
- }
- // if data is not big enough for the result
- else if (data->size <= std::max(data->digits_used,rhs.data->digits_used))
- {
- data_record* temp = new data_record(std::max(data->digits_used,rhs.data->digits_used)+slack);
- long_add(data,rhs.data,temp);
- delete data;
- data = temp;
- }
- // there is enough size and no references
- else
- {
- long_add(data,rhs.data,data);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 bigint_kernel_2::
- operator- (
- const bigint_kernel_2& rhs
- ) const
- {
- data_record* temp = new data_record (
- data->digits_used + slack
- );
- long_sub(data,rhs.data,temp);
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator-= (
- const bigint_kernel_2& rhs
- )
- {
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- long_sub(data,rhs.data,temp);
- data = temp;
- }
- else
- {
- long_sub(data,rhs.data,data);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 bigint_kernel_2::
- operator* (
- const bigint_kernel_2& rhs
- ) const
- {
- data_record* temp = new data_record (
- data->digits_used + rhs.data->digits_used + slack
- );
- long_mul(data,rhs.data,temp);
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator*= (
- const bigint_kernel_2& rhs
- )
- {
- // create a data_record to store the result of the multiplication in
- data_record* temp = new data_record(rhs.data->digits_used+data->digits_used+slack);
- long_mul(data,rhs.data,temp);
-
- // if there are other references to data
- if (data->references != 1)
- {
- data->references -= 1;
- }
- else
- {
- delete data;
- }
- data = temp;
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 bigint_kernel_2::
- operator/ (
- const bigint_kernel_2& rhs
- ) const
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data_record* remainder;
- try {
- remainder = new data_record(data->digits_used+slack);
- } catch (...) { delete temp; throw; }
-
- long_div(data,rhs.data,temp,remainder);
- delete remainder;
-
-
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator/= (
- const bigint_kernel_2& rhs
- )
- {
-
- data_record* temp = new data_record(data->digits_used+slack);
- data_record* remainder;
- try {
- remainder = new data_record(data->digits_used+slack);
- } catch (...) { delete temp; throw; }
-
- long_div(data,rhs.data,temp,remainder);
-
- // check if there are other references to data
- if (data->references != 1)
- {
- data->references -= 1;
- }
- // if there are no references to data then it must be deleted
- else
- {
- delete data;
- }
- data = temp;
- delete remainder;
-
-
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 bigint_kernel_2::
- operator% (
- const bigint_kernel_2& rhs
- ) const
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data_record* remainder;
- try {
- remainder = new data_record(data->digits_used+slack);
- } catch (...) { delete temp; throw; }
-
- long_div(data,rhs.data,temp,remainder);
- delete temp;
- return bigint_kernel_2(remainder,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator%= (
- const bigint_kernel_2& rhs
- )
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data_record* remainder;
- try {
- remainder = new data_record(data->digits_used+slack);
- } catch (...) { delete temp; throw; }
-
- long_div(data,rhs.data,temp,remainder);
-
- // check if there are other references to data
- if (data->references != 1)
- {
- data->references -= 1;
- }
- // if there are no references to data then it must be deleted
- else
- {
- delete data;
- }
- data = remainder;
- delete temp;
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bigint_kernel_2::
- operator < (
- const bigint_kernel_2& rhs
- ) const
- {
- return is_less_than(data,rhs.data);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bigint_kernel_2::
- operator == (
- const bigint_kernel_2& rhs
- ) const
- {
- return is_equal_to(data,rhs.data);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator= (
- const bigint_kernel_2& rhs
- )
- {
- if (this == &rhs)
- return *this;
-
- // if we have the only reference to our data then delete it
- if (data->references == 1)
- {
- delete data;
- data = rhs.data;
- data->references += 1;
- }
- else
- {
- data->references -= 1;
- data = rhs.data;
- data->references += 1;
- }
-
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- std::ostream& operator<< (
- std::ostream& out_,
- const bigint_kernel_2& rhs
- )
- {
- std::ostream out(out_.rdbuf());
-
- typedef bigint_kernel_2 bigint;
-
- bigint::data_record* temp = new bigint::data_record(*rhs.data,0);
-
-
-
- // get a char array big enough to hold the number in ascii format
- char* str;
- try {
- str = new char[(rhs.data->digits_used)*5+10];
- } catch (...) { delete temp; throw; }
-
- char* str_start = str;
- str += (rhs.data->digits_used)*5+9;
- *str = 0; --str;
-
-
- uint16 remainder;
- rhs.short_div(temp,10000,temp,remainder);
-
- // pull the digits out of remainder
- char a = remainder % 10 + '0';
- remainder /= 10;
- char b = remainder % 10 + '0';
- remainder /= 10;
- char c = remainder % 10 + '0';
- remainder /= 10;
- char d = remainder % 10 + '0';
- remainder /= 10;
-
-
- *str = a; --str;
- *str = b; --str;
- *str = c; --str;
- *str = d; --str;
-
-
- // keep looping until temp represents zero
- while (temp->digits_used != 1 || *(temp->number) != 0)
- {
- rhs.short_div(temp,10000,temp,remainder);
-
- // pull the digits out of remainder
- char a = remainder % 10 + '0';
- remainder /= 10;
- char b = remainder % 10 + '0';
- remainder /= 10;
- char c = remainder % 10 + '0';
- remainder /= 10;
- char d = remainder % 10 + '0';
- remainder /= 10;
-
- *str = a; --str;
- *str = b; --str;
- *str = c; --str;
- *str = d; --str;
- }
-
- // throw away and extra leading zeros
- ++str;
- if (*str == '0')
- ++str;
- if (*str == '0')
- ++str;
- if (*str == '0')
- ++str;
-
-
-
-
- out << str;
- delete [] str_start;
- delete temp;
- return out_;
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- std::istream& operator>> (
- std::istream& in_,
- bigint_kernel_2& rhs
- )
- {
- std::istream in(in_.rdbuf());
-
- // ignore any leading whitespaces
- while (in.peek() == ' ' || in.peek() == '\t' || in.peek() == '\n')
- {
- in.get();
- }
-
- // if the first digit is not an integer then this is an error
- if ( !(in.peek() >= '0' && in.peek() <= '9'))
- {
- in_.clear(std::ios::failbit);
- return in_;
- }
-
- int num_read;
- bigint_kernel_2 temp;
- do
- {
-
- // try to get 4 chars from in
- num_read = 1;
- char a = 0;
- char b = 0;
- char c = 0;
- char d = 0;
-
- if (in.peek() >= '0' && in.peek() <= '9')
- {
- num_read *= 10;
- a = in.get();
- }
- if (in.peek() >= '0' && in.peek() <= '9')
- {
- num_read *= 10;
- b = in.get();
- }
- if (in.peek() >= '0' && in.peek() <= '9')
- {
- num_read *= 10;
- c = in.get();
- }
- if (in.peek() >= '0' && in.peek() <= '9')
- {
- num_read *= 10;
- d = in.get();
- }
-
- // merge the for digits into an uint16
- uint16 num = 0;
- if (a != 0)
- {
- num = a - '0';
- }
- if (b != 0)
- {
- num *= 10;
- num += b - '0';
- }
- if (c != 0)
- {
- num *= 10;
- num += c - '0';
- }
- if (d != 0)
- {
- num *= 10;
- num += d - '0';
- }
-
-
- if (num_read != 1)
- {
- // shift the digits in temp left by the number of new digits we just read
- temp *= num_read;
- // add in new digits
- temp += num;
- }
-
- } while (num_read == 10000);
-
-
- rhs = temp;
- return in_;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 operator+ (
- uint16 lhs,
- const bigint_kernel_2& rhs
- )
- {
- typedef bigint_kernel_2 bigint;
- bigint::data_record* temp = new bigint::data_record
- (rhs.data->digits_used+rhs.slack);
-
- rhs.short_add(rhs.data,lhs,temp);
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 operator+ (
- const bigint_kernel_2& lhs,
- uint16 rhs
- )
- {
- typedef bigint_kernel_2 bigint;
- bigint::data_record* temp = new bigint::data_record
- (lhs.data->digits_used+lhs.slack);
-
- lhs.short_add(lhs.data,rhs,temp);
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator+= (
- uint16 rhs
- )
- {
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- short_add(data,rhs,temp);
- data = temp;
- }
- // or if we need to enlarge data then do so
- else if (data->digits_used == data->size)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- short_add(data,rhs,temp);
- delete data;
- data = temp;
- }
- // or if there is plenty of space and no references
- else
- {
- short_add(data,rhs,data);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 operator- (
- uint16 lhs,
- const bigint_kernel_2& rhs
- )
- {
- typedef bigint_kernel_2 bigint;
- bigint::data_record* temp = new bigint::data_record(rhs.slack);
-
- *(temp->number) = lhs - *(rhs.data->number);
-
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 operator- (
- const bigint_kernel_2& lhs,
- uint16 rhs
- )
- {
- typedef bigint_kernel_2 bigint;
- bigint::data_record* temp = new bigint::data_record
- (lhs.data->digits_used+lhs.slack);
-
- lhs.short_sub(lhs.data,rhs,temp);
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator-= (
- uint16 rhs
- )
- {
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- short_sub(data,rhs,temp);
- data = temp;
- }
- else
- {
- short_sub(data,rhs,data);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 operator* (
- uint16 lhs,
- const bigint_kernel_2& rhs
- )
- {
- typedef bigint_kernel_2 bigint;
- bigint::data_record* temp = new bigint::data_record
- (rhs.data->digits_used+rhs.slack);
-
- rhs.short_mul(rhs.data,lhs,temp);
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 operator* (
- const bigint_kernel_2& lhs,
- uint16 rhs
- )
- {
- typedef bigint_kernel_2 bigint;
- bigint::data_record* temp = new bigint::data_record
- (lhs.data->digits_used+lhs.slack);
-
- lhs.short_mul(lhs.data,rhs,temp);
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator*= (
- uint16 rhs
- )
- {
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- short_mul(data,rhs,temp);
- data = temp;
- }
- // or if we need to enlarge data
- else if (data->digits_used == data->size)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- short_mul(data,rhs,temp);
- delete data;
- data = temp;
- }
- else
- {
- short_mul(data,rhs,data);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 operator/ (
- uint16 lhs,
- const bigint_kernel_2& rhs
- )
- {
- typedef bigint_kernel_2 bigint;
- bigint::data_record* temp = new bigint::data_record(rhs.slack);
-
- // if rhs might not be bigger than lhs
- if (rhs.data->digits_used == 1)
- {
- *(temp->number) = lhs/ *(rhs.data->number);
- }
-
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 operator/ (
- const bigint_kernel_2& lhs,
- uint16 rhs
- )
- {
- typedef bigint_kernel_2 bigint;
- bigint::data_record* temp = new bigint::data_record
- (lhs.data->digits_used+lhs.slack);
-
- uint16 remainder;
- lhs.short_div(lhs.data,rhs,temp,remainder);
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator/= (
- uint16 rhs
- )
- {
- uint16 remainder;
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- short_div(data,rhs,temp,remainder);
- data = temp;
- }
- else
- {
- short_div(data,rhs,data,remainder);
- }
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 operator% (
- uint16 lhs,
- const bigint_kernel_2& rhs
- )
- {
- typedef bigint_kernel_2 bigint;
- // temp is zero by default
- bigint::data_record* temp = new bigint::data_record(rhs.slack);
-
- if (rhs.data->digits_used == 1)
- {
- // if rhs is just an uint16 inside then perform the modulus
- *(temp->number) = lhs % *(rhs.data->number);
- }
- else
- {
- // if rhs is bigger than lhs then the answer is lhs
- *(temp->number) = lhs;
- }
-
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 operator% (
- const bigint_kernel_2& lhs,
- uint16 rhs
- )
- {
- typedef bigint_kernel_2 bigint;
- bigint::data_record* temp = new bigint::data_record(lhs.data->digits_used+lhs.slack);
-
- uint16 remainder;
-
- lhs.short_div(lhs.data,rhs,temp,remainder);
- temp->digits_used = 1;
- *(temp->number) = remainder;
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator%= (
- uint16 rhs
- )
- {
- uint16 remainder;
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- short_div(data,rhs,temp,remainder);
- data = temp;
- }
- else
- {
- short_div(data,rhs,data,remainder);
- }
-
- data->digits_used = 1;
- *(data->number) = remainder;
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool operator < (
- uint16 lhs,
- const bigint_kernel_2& rhs
- )
- {
- return (rhs.data->digits_used > 1 || lhs < *(rhs.data->number) );
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool operator < (
- const bigint_kernel_2& lhs,
- uint16 rhs
- )
- {
- return (lhs.data->digits_used == 1 && *(lhs.data->number) < rhs);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool operator == (
- const bigint_kernel_2& lhs,
- uint16 rhs
- )
- {
- return (lhs.data->digits_used == 1 && *(lhs.data->number) == rhs);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool operator == (
- uint16 lhs,
- const bigint_kernel_2& rhs
- )
- {
- return (rhs.data->digits_used == 1 && *(rhs.data->number) == lhs);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator= (
- uint16 rhs
- )
- {
- // check if there are other references to our data
- if (data->references != 1)
- {
- data->references -= 1;
- try {
- data = new data_record(slack);
- } catch (...) { data->references += 1; throw; }
- }
- else
- {
- data->digits_used = 1;
- }
-
- *(data->number) = rhs;
-
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator++ (
- )
- {
- // if there are other references to this data then make a copy of it
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- increment(data,temp);
- data = temp;
- }
- // or if we need to enlarge data then do so
- else if (data->digits_used == data->size)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- increment(data,temp);
- delete data;
- data = temp;
- }
- else
- {
- increment(data,data);
- }
-
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 bigint_kernel_2::
- operator++ (
- int
- )
- {
- data_record* temp; // this is the copy of temp we will return in the end
-
- data_record* temp2 = new data_record(data->digits_used+slack);
- increment(data,temp2);
-
- temp = data;
- data = temp2;
-
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bigint_kernel_2& bigint_kernel_2::
- operator-- (
- )
- {
- // if there are other references to this data
- if (data->references != 1)
- {
- data_record* temp = new data_record(data->digits_used+slack);
- data->references -= 1;
- decrement(data,temp);
- data = temp;
- }
- else
- {
- decrement(data,data);
- }
-
- return *this;
- }
-
-// ----------------------------------------------------------------------------------------
-
- const bigint_kernel_2 bigint_kernel_2::
- operator-- (
- int
- )
- {
- data_record* temp; // this is the copy of temp we will return in the end
-
- data_record* temp2 = new data_record(data->digits_used+slack);
- decrement(data,temp2);
-
- temp = data;
- data = temp2;
-
- return bigint_kernel_2(temp,0);
- }
-
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
- // private member function definitions
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- short_add (
- const data_record* data,
- uint16 value,
- data_record* result
- ) const
- {
- // put value into the carry part of temp
- uint32 temp = value;
- temp <<= 16;
-
-
- const uint16* number = data->number;
- const uint16* end = number + data->digits_used; // one past the end of number
- uint16* r = result->number;
-
- while (number != end)
- {
- // add *number and the current carry
- temp = *number + (temp>>16);
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
-
- ++number;
- ++r;
- }
-
- // if there is a final carry
- if ((temp>>16) != 0)
- {
- result->digits_used = data->digits_used + 1;
- // store the carry in the most significant digit of the result
- *r = static_cast(temp>>16);
- }
- else
- {
- result->digits_used = data->digits_used;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- short_sub (
- const data_record* data,
- uint16 value,
- data_record* result
- ) const
- {
-
-
- const uint16* number = data->number;
- const uint16* end = number + data->digits_used - 1;
- uint16* r = result->number;
-
- uint32 temp = *number - value;
-
- // put the low word of temp into *data
- *r = static_cast(temp & 0xFFFF);
-
-
- while (number != end)
- {
- ++number;
- ++r;
-
- // subtract the carry from *number
- temp = *number - (temp>>31);
-
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
- }
-
- // if we lost a digit in the subtraction
- if (*r == 0)
- {
- if (data->digits_used == 1)
- result->digits_used = 1;
- else
- result->digits_used = data->digits_used - 1;
- }
- else
- {
- result->digits_used = data->digits_used;
- }
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- short_mul (
- const data_record* data,
- uint16 value,
- data_record* result
- ) const
- {
-
- uint32 temp = 0;
-
-
- const uint16* number = data->number;
- uint16* r = result->number;
- const uint16* end = r + data->digits_used;
-
-
-
- while ( r != end)
- {
-
- // multiply *data and value and add in the carry
- temp = *number*(uint32)value + (temp>>16);
-
- // put the low word of temp into *data
- *r = static_cast(temp & 0xFFFF);
-
- ++number;
- ++r;
- }
-
- // if there is a final carry
- if ((temp>>16) != 0)
- {
- result->digits_used = data->digits_used + 1;
- // put the final carry into the most significant digit of the result
- *r = static_cast(temp>>16);
- }
- else
- {
- result->digits_used = data->digits_used;
- }
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- short_div (
- const data_record* data,
- uint16 value,
- data_record* result,
- uint16& rem
- ) const
- {
-
- uint16 remainder = 0;
- uint32 temp;
-
-
-
- const uint16* number = data->number + data->digits_used - 1;
- const uint16* end = number - data->digits_used;
- uint16* r = result->number + data->digits_used - 1;
-
-
- // if we are losing a digit in this division
- if (*number < value)
- {
- if (data->digits_used == 1)
- result->digits_used = 1;
- else
- result->digits_used = data->digits_used - 1;
- }
- else
- {
- result->digits_used = data->digits_used;
- }
-
-
- // perform the actual division
- while (number != end)
- {
-
- temp = *number + (((uint32)remainder)<<16);
-
- *r = static_cast(temp/value);
- remainder = static_cast(temp%value);
-
- --number;
- --r;
- }
-
- rem = remainder;
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- long_add (
- const data_record* lhs,
- const data_record* rhs,
- data_record* result
- ) const
- {
- // put value into the carry part of temp
- uint32 temp=0;
-
- uint16* min_num; // the number with the least digits used
- uint16* max_num; // the number with the most digits used
- uint16* min_end; // one past the end of min_num
- uint16* max_end; // one past the end of max_num
- uint16* r = result->number;
-
- uint32 max_digits_used;
- if (lhs->digits_used < rhs->digits_used)
- {
- max_digits_used = rhs->digits_used;
- min_num = lhs->number;
- max_num = rhs->number;
- min_end = min_num + lhs->digits_used;
- max_end = max_num + rhs->digits_used;
- }
- else
- {
- max_digits_used = lhs->digits_used;
- min_num = rhs->number;
- max_num = lhs->number;
- min_end = min_num + rhs->digits_used;
- max_end = max_num + lhs->digits_used;
- }
-
-
-
-
- while (min_num != min_end)
- {
- // add *min_num, *max_num and the current carry
- temp = *min_num + *max_num + (temp>>16);
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
-
- ++min_num;
- ++max_num;
- ++r;
- }
-
-
- while (max_num != max_end)
- {
- // add *max_num and the current carry
- temp = *max_num + (temp>>16);
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
-
- ++max_num;
- ++r;
- }
-
- // check if there was a final carry
- if ((temp>>16) != 0)
- {
- result->digits_used = max_digits_used + 1;
- // put the carry into the most significant digit in the result
- *r = static_cast(temp>>16);
- }
- else
- {
- result->digits_used = max_digits_used;
- }
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- long_sub (
- const data_record* lhs,
- const data_record* rhs,
- data_record* result
- ) const
- {
-
-
- const uint16* number1 = lhs->number;
- const uint16* number2 = rhs->number;
- const uint16* end = number2 + rhs->digits_used;
- uint16* r = result->number;
-
-
-
- uint32 temp =0;
-
-
- while (number2 != end)
- {
-
- // subtract *number2 from *number1 and then subtract any carry
- temp = *number1 - *number2 - (temp>>31);
-
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
-
- ++number1;
- ++number2;
- ++r;
- }
-
- end = lhs->number + lhs->digits_used;
- while (number1 != end)
- {
-
- // subtract the carry from *number1
- temp = *number1 - (temp>>31);
-
- // put the low word of temp into *r
- *r = static_cast(temp & 0xFFFF);
-
- ++number1;
- ++r;
- }
-
- result->digits_used = lhs->digits_used;
- // adjust the number of digits used appropriately
- --r;
- while (*r == 0 && result->digits_used > 1)
- {
- --r;
- --result->digits_used;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- long_div (
- const data_record* lhs,
- const data_record* rhs,
- data_record* result,
- data_record* remainder
- ) const
- {
- // zero result
- result->digits_used = 1;
- *(result->number) = 0;
-
- uint16* a;
- uint16* b;
- uint16* end;
-
- // copy lhs into remainder
- remainder->digits_used = lhs->digits_used;
- a = remainder->number;
- end = a + remainder->digits_used;
- b = lhs->number;
- while (a != end)
- {
- *a = *b;
- ++a;
- ++b;
- }
-
-
- // if rhs is bigger than lhs then result == 0 and remainder == lhs
- // so then we can quit right now
- if (is_less_than(lhs,rhs))
- {
- return;
- }
-
-
- // make a temporary number
- data_record temp(lhs->digits_used + slack);
-
-
- // shift rhs left until it is one shift away from being larger than lhs and
- // put the number of left shifts necessary into shifts
- uint32 shifts;
- shifts = (lhs->digits_used - rhs->digits_used) * 16;
-
- shift_left(rhs,&temp,shifts);
-
-
- // while (lhs > temp)
- while (is_less_than(&temp,lhs))
- {
- shift_left(&temp,&temp,1);
- ++shifts;
- }
- // make sure lhs isn't smaller than temp
- while (is_less_than(lhs,&temp))
- {
- shift_right(&temp,&temp);
- --shifts;
- }
-
-
-
- // we want to execute the loop shifts +1 times
- ++shifts;
- while (shifts != 0)
- {
- shift_left(result,result,1);
- // if (temp <= remainder)
- if (!is_less_than(remainder,&temp))
- {
- long_sub(remainder,&temp,remainder);
-
- // increment result
- uint16* r = result->number;
- uint16* end = r + result->digits_used;
- while (true)
- {
- ++(*r);
- // if there was no carry then we are done
- if (*r != 0)
- break;
-
- ++r;
-
- // if we hit the end of r and there is still a carry then
- // the next digit of r is 1 and there is one more digit used
- if (r == end)
- {
- *r = 1;
- ++(result->digits_used);
- break;
- }
- }
- }
- shift_right(&temp,&temp);
- --shifts;
- }
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- long_mul (
- const data_record* lhs,
- const data_record* rhs,
- data_record* result
- ) const
- {
- // if one of the numbers is small then use this simple but O(n^2) algorithm
- if (std::min(lhs->digits_used, rhs->digits_used) < 10)
- {
- // make result be zero
- result->digits_used = 1;
- *(result->number) = 0;
-
-
- const data_record* aa;
- const data_record* bb;
-
- if (lhs->digits_used < rhs->digits_used)
- {
- // make copies of lhs and rhs and give them an appropriate amount of
- // extra memory so there won't be any overflows
- aa = lhs;
- bb = rhs;
- }
- else
- {
- // make copies of lhs and rhs and give them an appropriate amount of
- // extra memory so there won't be any overflows
- aa = rhs;
- bb = lhs;
- }
-
- // copy the larger(approximately) of lhs and rhs into b
- data_record b(*bb,aa->digits_used+slack);
-
-
- uint32 shift_value = 0;
- uint16* anum = aa->number;
- uint16* end = anum + aa->digits_used;
- while (anum != end )
- {
- uint16 bit = 0x0001;
-
- for (int i = 0; i < 16; ++i)
- {
- // if the specified bit of a is 1
- if ((*anum & bit) != 0)
- {
- shift_left(&b,&b,shift_value);
- shift_value = 0;
- long_add(&b,result,result);
- }
- ++shift_value;
- bit <<= 1;
- }
-
- ++anum;
- }
- }
- else // else if both lhs and rhs are large then use the more complex
- // O(n*logn) algorithm
- {
- uint32 size = 1;
- // make size a power of 2
- while (size < (lhs->digits_used + rhs->digits_used)*2)
- {
- size *= 2;
- }
-
- // allocate some temporary space so we can do the FFT
- ct* a = new ct[size];
- ct* b; try {b = new ct[size]; } catch (...) { delete [] a; throw; }
-
- // load lhs into the a array. We are breaking the input number into
- // 8bit chunks for the purpose of using this fft algorithm. The reason
- // for this is so that we have smaller numbers coming out of the final
- // ifft. This helps avoid overflow.
- for (uint32 i = 0; i < lhs->digits_used; ++i)
- {
- a[i*2] = ct((t)(lhs->number[i]&0xFF),0);
- a[i*2+1] = ct((t)(lhs->number[i]>>8),0);
- }
- for (uint32 i = lhs->digits_used*2; i < size; ++i)
- {
- a[i] = 0;
- }
-
- // load rhs into the b array
- for (uint32 i = 0; i < rhs->digits_used; ++i)
- {
- b[i*2] = ct((t)(rhs->number[i]&0xFF),0);
- b[i*2+1] = ct((t)(rhs->number[i]>>8),0);
- }
- for (uint32 i = rhs->digits_used*2; i < size; ++i)
- {
- b[i] = 0;
- }
-
- // perform the forward fft of a and b
- fft(a,size);
- fft(b,size);
-
- const double l = 1.0/size;
-
- // do the pointwise multiply of a and b and also apply the scale
- // factor in this loop too.
- for (unsigned long i = 0; i < size; ++i)
- {
- a[i] = l*a[i]*b[i];
- }
-
- // Now compute the inverse fft of the pointwise multiplication of a and b.
- // This is basically the result. We just have to take care of any carries
- // that should happen.
- ifft(a,size);
-
- // loop over the result and propagate any carries that need to take place.
- // We will also be moving the resulting numbers into result->number at
- // the same time.
- uint64 carry = 0;
- result->digits_used = 0;
- int zeros = 0;
- const uint32 len = lhs->digits_used + rhs->digits_used;
- for (unsigned long i = 0; i < len; ++i)
- {
- uint64 num1 = static_cast(std::floor(a[i*2].real()+0.5));
- num1 += carry;
- carry = 0;
- if (num1 > 255)
- {
- carry = num1 >> 8;
- num1 = (num1&0xFF);
- }
-
- uint64 num2 = static_cast(std::floor(a[i*2+1].real()+0.5));
- num2 += carry;
- carry = 0;
- if (num2 > 255)
- {
- carry = num2 >> 8;
- num2 = (num2&0xFF);
- }
-
- // put the new number into its final place
- num1 = (num2<<8) | num1;
- result->number[i] = static_cast(num1);
-
- // keep track of the number of leading zeros
- if (num1 == 0)
- ++zeros;
- else
- zeros = 0;
- ++(result->digits_used);
- }
-
- // adjust digits_used so that it reflects the actual number
- // of non-zero digits in our representation.
- result->digits_used -= zeros;
-
- // if the result was zero then adjust the result accordingly
- if (result->digits_used == 0)
- {
- // make result be zero
- result->digits_used = 1;
- *(result->number) = 0;
- }
-
- // free all the temporary buffers
- delete [] a;
- delete [] b;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- shift_left (
- const data_record* data,
- data_record* result,
- uint32 shift_amount
- ) const
- {
- uint32 offset = shift_amount/16;
- shift_amount &= 0xf; // same as shift_amount %= 16;
-
- uint16* r = result->number + data->digits_used + offset; // result
- uint16* end = data->number;
- uint16* s = end + data->digits_used; // source
- const uint32 temp = 16 - shift_amount;
-
- *r = (*(--s) >> temp);
- // set the number of digits used in the result
- // if the upper bits from *s were zero then don't count this first word
- if (*r == 0)
- {
- result->digits_used = data->digits_used + offset;
- }
- else
- {
- result->digits_used = data->digits_used + offset + 1;
- }
- --r;
-
- while (s != end)
- {
- *r = ((*s << shift_amount) | ( *(s-1) >> temp));
- --r;
- --s;
- }
- *r = *s << shift_amount;
-
- // now zero the rest of the result
- end = result->number;
- while (r != end)
- *(--r) = 0;
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- shift_right (
- const data_record* data,
- data_record* result
- ) const
- {
-
- uint16* r = result->number; // result
- uint16* s = data->number; // source
- uint16* end = s + data->digits_used - 1;
-
- while (s != end)
- {
- *r = (*s >> 1) | (*(s+1) << 15);
- ++r;
- ++s;
- }
- *r = *s >> 1;
-
-
- // calculate the new number for digits_used
- if (*r == 0)
- {
- if (data->digits_used != 1)
- result->digits_used = data->digits_used - 1;
- else
- result->digits_used = 1;
- }
- else
- {
- result->digits_used = data->digits_used;
- }
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bigint_kernel_2::
- is_less_than (
- const data_record* lhs,
- const data_record* rhs
- ) const
- {
- uint32 lhs_digits_used = lhs->digits_used;
- uint32 rhs_digits_used = rhs->digits_used;
-
- // if lhs is definitely less than rhs
- if (lhs_digits_used < rhs_digits_used )
- return true;
- // if lhs is definitely greater than rhs
- else if (lhs_digits_used > rhs_digits_used)
- return false;
- else
- {
- uint16* end = lhs->number;
- uint16* l = end + lhs_digits_used;
- uint16* r = rhs->number + rhs_digits_used;
-
- while (l != end)
- {
- --l;
- --r;
- if (*l < *r)
- return true;
- else if (*l > *r)
- return false;
- }
-
- // at this point we know that they are equal
- return false;
- }
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bigint_kernel_2::
- is_equal_to (
- const data_record* lhs,
- const data_record* rhs
- ) const
- {
- // if lhs and rhs are definitely not equal
- if (lhs->digits_used != rhs->digits_used )
- {
- return false;
- }
- else
- {
- uint16* l = lhs->number;
- uint16* r = rhs->number;
- uint16* end = l + lhs->digits_used;
-
- while (l != end)
- {
- if (*l != *r)
- return false;
- ++l;
- ++r;
- }
-
- // at this point we know that they are equal
- return true;
- }
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- increment (
- const data_record* source,
- data_record* dest
- ) const
- {
- uint16* s = source->number;
- uint16* d = dest->number;
- uint16* end = s + source->digits_used;
- while (true)
- {
- *d = *s + 1;
-
- // if there was no carry then break out of the loop
- if (*d != 0)
- {
- dest->digits_used = source->digits_used;
-
- // copy the rest of the digits over to d
- ++d; ++s;
- while (s != end)
- {
- *d = *s;
- ++d;
- ++s;
- }
-
- break;
- }
-
-
- ++s;
-
- // if we have hit the end of s and there was a carry up to this point
- // then just make the next digit 1 and add one to the digits used
- if (s == end)
- {
- ++d;
- dest->digits_used = source->digits_used + 1;
- *d = 1;
- break;
- }
-
- ++d;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- decrement (
- const data_record* source,
- data_record* dest
- ) const
- {
- uint16* s = source->number;
- uint16* d = dest->number;
- uint16* end = s + source->digits_used;
- while (true)
- {
- *d = *s - 1;
-
- // if there was no carry then break out of the loop
- if (*d != 0xFFFF)
- {
- // if we lost a digit in the subtraction
- if (*d == 0 && s+1 == end)
- {
- if (source->digits_used == 1)
- dest->digits_used = 1;
- else
- dest->digits_used = source->digits_used - 1;
- }
- else
- {
- dest->digits_used = source->digits_used;
- }
- break;
- }
- else
- {
- ++d;
- ++s;
- }
-
- }
-
- // copy the rest of the digits over to d
- ++d;
- ++s;
- while (s != end)
- {
- *d = *s;
- ++d;
- ++s;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- fft (
- ct* data,
- unsigned long len
- ) const
- {
- const t pi2 = -2.0*3.1415926535897932384626433832795028841971693993751;
-
- const unsigned long half = len/2;
-
- std::vector twiddle_factors;
- twiddle_factors.resize(half);
-
- // compute the complex root of unity w
- const t temp = pi2/len;
- ct w = ct(std::cos(temp),std::sin(temp));
-
- ct w_pow = 1;
-
- // compute the twiddle factors
- for (std::vector::size_type j = 0; j < twiddle_factors.size(); ++j)
- {
- twiddle_factors[j] = w_pow;
- w_pow *= w;
- }
-
- ct a, b;
-
- // now compute the decimation in frequency. This first
- // outer loop loops log2(len) number of times
- unsigned long skip = 1;
- for (unsigned long step = half; step != 0; step >>= 1)
- {
- // do blocks of butterflies in this loop
- for (unsigned long j = 0; j < len; j += step*2)
- {
- // do step butterflies
- for (unsigned long k = 0; k < step; ++k)
- {
- const unsigned long a_idx = j+k;
- const unsigned long b_idx = j+k+step;
- a = data[a_idx] + data[b_idx];
- b = (data[a_idx] - data[b_idx])*twiddle_factors[k*skip];
- data[a_idx] = a;
- data[b_idx] = b;
- }
- }
- skip *= 2;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bigint_kernel_2::
- ifft(
- ct* data,
- unsigned long len
- ) const
- {
- const t pi2 = 2.0*3.1415926535897932384626433832795028841971693993751;
-
- const unsigned long half = len/2;
-
- std::vector twiddle_factors;
- twiddle_factors.resize(half);
-
- // compute the complex root of unity w
- const t temp = pi2/len;
- ct w = ct(std::cos(temp),std::sin(temp));
-
- ct w_pow = 1;
-
- // compute the twiddle factors
- for (std::vector::size_type j = 0; j < twiddle_factors.size(); ++j)
- {
- twiddle_factors[j] = w_pow;
- w_pow *= w;
- }
-
- ct a, b;
-
- // now compute the inverse decimation in frequency. This first
- // outer loop loops log2(len) number of times
- unsigned long skip = half;
- for (unsigned long step = 1; step <= half; step <<= 1)
- {
- // do blocks of butterflies in this loop
- for (unsigned long j = 0; j < len; j += step*2)
- {
- // do step butterflies
- for (unsigned long k = 0; k < step; ++k)
- {
- const unsigned long a_idx = j+k;
- const unsigned long b_idx = j+k+step;
- data[b_idx] *= twiddle_factors[k*skip];
- a = data[a_idx] + data[b_idx];
- b = data[a_idx] - data[b_idx];
- data[a_idx] = a;
- data[b_idx] = b;
- }
- }
- skip /= 2;
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
-}
-#endif // DLIB_BIGINT_KERNEL_2_CPp_
-
diff --git a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_2.h b/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_2.h
index 9950d4e9..cbd8f895 100644
--- a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_2.h
+++ b/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_2.h
@@ -15,8 +15,6 @@
namespace dlib
{
- using namespace dlib::relational_operators; // defined in algs.h
-
class bigint_kernel_2
{
/*!
@@ -557,6 +555,11 @@ namespace dlib
}
}
+ inline bool operator> (const bigint_kernel_2& a, const bigint_kernel_2& b) { return b < a; }
+ inline bool operator!= (const bigint_kernel_2& a, const bigint_kernel_2& b) { return !(a == b); }
+ inline bool operator<= (const bigint_kernel_2& a, const bigint_kernel_2& b) { return !(b < a); }
+ inline bool operator>= (const bigint_kernel_2& a, const bigint_kernel_2& b) { return !(a < b); }
+
}
#ifdef NO_MAKEFILE
diff --git a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_abstract.h b/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_abstract.h
index ef9eb9ec..99a54520 100644
--- a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_abstract.h
+++ b/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_abstract.h
@@ -10,7 +10,6 @@
namespace dlib
{
- using namespace dlib::relational_operators; // defined in algs.h
class bigint
{
@@ -661,6 +660,10 @@ namespace dlib
provides deserialization support
!*/
+ inline bool operator> (const bigint& a, const bigint& b) { return b < a; }
+ inline bool operator!= (const bigint& a, const bigint& b) { return !(a == b); }
+ inline bool operator<= (const bigint& a, const bigint& b) { return !(b < a); }
+ inline bool operator>= (const bigint& a, const bigint& b) { return !(a < b); }
}
#endif // DLIB_BIGINT_KERNEl_ABSTRACT_
diff --git a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_c.h b/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_c.h
index da25b03d..954869a3 100644
--- a/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_c.h
+++ b/lib/3rdParty/dlib/include/dlib/bigint/bigint_kernel_c.h
@@ -1122,6 +1122,17 @@ namespace dlib
return *this;
}
+// ----------------------------------------------------------------------------------------
+
+ template < typename bigint_base >
+ inline bool operator> (const bigint_kernel_c& a, const bigint_kernel_c& b) { return b < a; }
+ template < typename bigint_base >
+ inline bool operator!= (const bigint_kernel_c& a, const bigint_kernel_c& b) { return !(a == b); }
+ template < typename bigint_base >
+ inline bool operator<= (const bigint_kernel_c& a, const bigint_kernel_c& b) { return !(b < a); }
+ template < typename bigint_base >
+ inline bool operator>= (const bigint_kernel_c& a, const bigint_kernel_c& b) { return !(a < b); }
+
// ----------------------------------------------------------------------------------------
}
diff --git a/lib/3rdParty/dlib/include/dlib/binary_search_tree/binary_search_tree_kernel_1.h b/lib/3rdParty/dlib/include/dlib/binary_search_tree/binary_search_tree_kernel_1.h
index 5db58c42..418eb07d 100644
--- a/lib/3rdParty/dlib/include/dlib/binary_search_tree/binary_search_tree_kernel_1.h
+++ b/lib/3rdParty/dlib/include/dlib/binary_search_tree/binary_search_tree_kernel_1.h
@@ -168,7 +168,7 @@ namespace dlib
);
// functions from the enumerable interface
- inline unsigned long size (
+ inline size_t size (
) const;
bool at_start (
@@ -597,7 +597,7 @@ namespace dlib
typename mem_manager,
typename compare
>
- unsigned long binary_search_tree_kernel_1::
+ size_t binary_search_tree_kernel_1::
size (
) const
{
diff --git a/lib/3rdParty/dlib/include/dlib/binary_search_tree/binary_search_tree_kernel_2.h b/lib/3rdParty/dlib/include/dlib/binary_search_tree/binary_search_tree_kernel_2.h
index 7ca78c91..098d38c2 100644
--- a/lib/3rdParty/dlib/include/dlib/binary_search_tree/binary_search_tree_kernel_2.h
+++ b/lib/3rdParty/dlib/include/dlib/binary_search_tree/binary_search_tree_kernel_2.h
@@ -169,7 +169,7 @@ namespace dlib
);
// functions from the enumerable interface
- inline unsigned long size (
+ inline size_t size (
) const;
bool at_start (
@@ -543,7 +543,7 @@ namespace dlib
typename mem_manager,
typename compare
>
- unsigned long binary_search_tree_kernel_2::
+ size_t binary_search_tree_kernel_2::
size (
) const
{
diff --git a/lib/3rdParty/dlib/include/dlib/bit_stream/bit_stream_kernel_1.cpp b/lib/3rdParty/dlib/include/dlib/bit_stream/bit_stream_kernel_1.cpp
deleted file mode 100644
index ad3d63ef..00000000
--- a/lib/3rdParty/dlib/include/dlib/bit_stream/bit_stream_kernel_1.cpp
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright (C) 2003 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef DLIB_BIT_STREAM_KERNEL_1_CPp_
-#define DLIB_BIT_STREAM_KERNEL_1_CPp_
-
-
-#include "bit_stream_kernel_1.h"
-#include "../algs.h"
-
-#include
-
-namespace dlib
-{
-
- inline void swap (
- bit_stream_kernel_1& a,
- bit_stream_kernel_1& b
- ) { a.swap(b); }
-
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
- // member function definitions
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-
- void bit_stream_kernel_1::
- clear (
- )
- {
- if (write_mode)
- {
- write_mode = false;
-
- // flush output buffer
- if (buffer_size > 0)
- {
- buffer <<= 8 - buffer_size;
- osp->write(reinterpret_cast(&buffer),1);
- }
- }
- else
- read_mode = false;
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bit_stream_kernel_1::
- set_input_stream (
- std::istream& is
- )
- {
- isp = &is;
- read_mode = true;
-
- buffer_size = 0;
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bit_stream_kernel_1::
- set_output_stream (
- std::ostream& os
- )
- {
- osp = &os;
- write_mode = true;
-
- buffer_size = 0;
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bit_stream_kernel_1::
- close (
- )
- {
- if (write_mode)
- {
- write_mode = false;
-
- // flush output buffer
- if (buffer_size > 0)
- {
- buffer <<= 8 - buffer_size;
- osp->write(reinterpret_cast(&buffer),1);
- }
- }
- else
- read_mode = false;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bit_stream_kernel_1::
- is_in_write_mode (
- ) const
- {
- return write_mode;
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bit_stream_kernel_1::
- is_in_read_mode (
- ) const
- {
- return read_mode;
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bit_stream_kernel_1::
- write (
- int bit
- )
- {
- // flush buffer if necessary
- if (buffer_size == 8)
- {
- buffer <<= 8 - buffer_size;
- if (osp->rdbuf()->sputn(reinterpret_cast(&buffer),1) == 0)
- {
- throw std::ios_base::failure("error occured in the bit_stream object");
- }
-
- buffer_size = 0;
- }
-
- ++buffer_size;
- buffer <<= 1;
- buffer += static_cast(bit);
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bit_stream_kernel_1::
- read (
- int& bit
- )
- {
- // get new byte if necessary
- if (buffer_size == 0)
- {
- if (isp->rdbuf()->sgetn(reinterpret_cast(&buffer), 1) == 0)
- {
- // if we didn't read anything then return false
- return false;
- }
-
- buffer_size = 8;
- }
-
- // put the most significant bit from buffer into bit
- bit = static_cast(buffer >> 7);
-
- // shift out the bit that was just read
- buffer <<= 1;
- --buffer_size;
-
- return true;
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bit_stream_kernel_1::
- swap (
- bit_stream_kernel_1& item
- )
- {
-
- std::istream* isp_temp = item.isp;
- std::ostream* osp_temp = item.osp;
- bool write_mode_temp = item.write_mode;
- bool read_mode_temp = item.read_mode;
- unsigned char buffer_temp = item.buffer;
- unsigned short buffer_size_temp = item.buffer_size;
-
- item.isp = isp;
- item.osp = osp;
- item.write_mode = write_mode;
- item.read_mode = read_mode;
- item.buffer = buffer;
- item.buffer_size = buffer_size;
-
-
- isp = isp_temp;
- osp = osp_temp;
- write_mode = write_mode_temp;
- read_mode = read_mode_temp;
- buffer = buffer_temp;
- buffer_size = buffer_size_temp;
-
- }
-
-// ----------------------------------------------------------------------------------------
-
-}
-#endif // DLIB_BIT_STREAM_KERNEL_1_CPp_
-
diff --git a/lib/3rdParty/dlib/include/dlib/string/cassert b/lib/3rdParty/dlib/include/dlib/bits/c++config.h
similarity index 100%
rename from lib/3rdParty/dlib/include/dlib/string/cassert
rename to lib/3rdParty/dlib/include/dlib/bits/c++config.h
diff --git a/lib/3rdParty/dlib/include/dlib/bridge.h b/lib/3rdParty/dlib/include/dlib/bridge.h
index 79f89559..4b633c40 100644
--- a/lib/3rdParty/dlib/include/dlib/bridge.h
+++ b/lib/3rdParty/dlib/include/dlib/bridge.h
@@ -1,5 +1,11 @@
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
+
+#ifdef DLIB_ALL_SOURCE_END
+#include "dlib_basic_cpp_build_tutorial.txt"
+#endif
+
+
#ifndef DLIB_BRIdGE_
#define DLIB_BRIdGE_
diff --git a/lib/3rdParty/dlib/include/dlib/bridge/bridge.h b/lib/3rdParty/dlib/include/dlib/bridge/bridge.h
index 3160102d..da4e0bd7 100644
--- a/lib/3rdParty/dlib/include/dlib/bridge/bridge.h
+++ b/lib/3rdParty/dlib/include/dlib/bridge/bridge.h
@@ -3,17 +3,19 @@
#ifndef DLIB_BRIDGe_Hh_
#define DLIB_BRIDGe_Hh_
-#include "bridge_abstract.h"
+#include
+#include
#include
+
+#include "bridge_abstract.h"
#include "../pipe.h"
#include "../threads.h"
-#include "../smart_pointers.h"
#include "../serialize.h"
#include "../sockets.h"
#include "../sockstreambuf.h"
#include "../logger.h"
#include "../algs.h"
-#include
+
namespace dlib
{
@@ -141,7 +143,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
- namespace impl
+ namespace impl_brns
{
class impl_bridge_base
{
@@ -545,8 +547,8 @@ namespace dlib
signaler s;
bool receive_thread_active;
bool transmit_thread_active;
- scoped_ptr con;
- scoped_ptr list;
+ std::unique_ptr con;
+ std::unique_ptr list;
const unsigned short port;
const std::string ip;
transmit_pipe_type* const transmit_pipe;
@@ -594,26 +596,26 @@ namespace dlib
listen_on_port network_parameters,
bridge_transmit_decoration transmit_pipe,
bridge_receive_decoration receive_pipe
- ) { pimpl.reset(); pimpl.reset(new impl::impl_bridge(network_parameters.port, &transmit_pipe.p, &receive_pipe.p)); }
+ ) { pimpl.reset(); pimpl.reset(new impl_brns::impl_bridge(network_parameters.port, &transmit_pipe.p, &receive_pipe.p)); }
template < typename T, typename R >
void reconfigure (
listen_on_port network_parameters,
bridge_receive_decoration receive_pipe,
bridge_transmit_decoration transmit_pipe
- ) { pimpl.reset(); pimpl.reset(new impl::impl_bridge(network_parameters.port, &transmit_pipe.p, &receive_pipe.p)); }
+ ) { pimpl.reset(); pimpl.reset(new impl_brns::impl_bridge(network_parameters.port, &transmit_pipe.p, &receive_pipe.p)); }
template < typename T >
void reconfigure (
listen_on_port network_parameters,
bridge_transmit_decoration transmit_pipe
- ) { pimpl.reset(); pimpl.reset(new impl::impl_bridge(network_parameters.port, &transmit_pipe.p, 0)); }
+ ) { pimpl.reset(); pimpl.reset(new impl_brns::impl_bridge(network_parameters.port, &transmit_pipe.p, 0)); }
template < typename R >
void reconfigure (
listen_on_port network_parameters,
bridge_receive_decoration receive_pipe
- ) { pimpl.reset(); pimpl.reset(new impl::impl_bridge(network_parameters.port, 0, &receive_pipe.p)); }
+ ) { pimpl.reset(); pimpl.reset(new impl_brns::impl_bridge(network_parameters.port, 0, &receive_pipe.p)); }
@@ -623,26 +625,26 @@ namespace dlib
connect_to_ip_and_port network_parameters,
bridge_transmit_decoration transmit_pipe,
bridge_receive_decoration receive_pipe
- ) { pimpl.reset(); pimpl.reset(new impl::impl_bridge(network_parameters.ip, network_parameters.port, &transmit_pipe.p, &receive_pipe.p)); }
+ ) { pimpl.reset(); pimpl.reset(new impl_brns::impl_bridge(network_parameters.ip, network_parameters.port, &transmit_pipe.p, &receive_pipe.p)); }
template < typename T, typename R >
void reconfigure (
connect_to_ip_and_port network_parameters,
bridge_receive_decoration receive_pipe,
bridge_transmit_decoration transmit_pipe
- ) { pimpl.reset(); pimpl.reset(new impl::impl_bridge(network_parameters.ip, network_parameters.port, &transmit_pipe.p, &receive_pipe.p)); }
+ ) { pimpl.reset(); pimpl.reset(new impl_brns::impl_bridge(network_parameters.ip, network_parameters.port, &transmit_pipe.p, &receive_pipe.p)); }
template < typename R >
void reconfigure (
connect_to_ip_and_port network_parameters,
bridge_receive_decoration receive_pipe
- ) { pimpl.reset(); pimpl.reset(new impl::impl_bridge(network_parameters.ip, network_parameters.port, 0, &receive_pipe.p)); }
+ ) { pimpl.reset(); pimpl.reset(new impl_brns::impl_bridge(network_parameters.ip, network_parameters.port, 0, &receive_pipe.p)); }
template < typename T >
void reconfigure (
connect_to_ip_and_port network_parameters,
bridge_transmit_decoration transmit_pipe
- ) { pimpl.reset(); pimpl.reset(new impl::impl_bridge(network_parameters.ip, network_parameters.port, &transmit_pipe.p, 0)); }
+ ) { pimpl.reset(); pimpl.reset(new impl_brns::impl_bridge(network_parameters.ip, network_parameters.port, &transmit_pipe.p, 0)); }
bridge_status get_bridge_status (
@@ -656,7 +658,7 @@ namespace dlib
private:
- scoped_ptr pimpl;
+ std::unique_ptr pimpl;
};
// ----------------------------------------------------------------------------------------
diff --git a/lib/3rdParty/dlib/include/dlib/bsp/bsp.cpp b/lib/3rdParty/dlib/include/dlib/bsp/bsp.cpp
deleted file mode 100644
index f1367cf5..00000000
--- a/lib/3rdParty/dlib/include/dlib/bsp/bsp.cpp
+++ /dev/null
@@ -1,495 +0,0 @@
-// Copyright (C) 2012 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef DLIB_BSP_CPph_
-#define DLIB_BSP_CPph_
-
-#include "bsp.h"
-#include
-
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-
-namespace dlib
-{
-
- namespace impl1
- {
-
- void connect_all (
- map_id_to_con& cons,
- const std::vector& hosts,
- unsigned long node_id
- )
- {
- cons.clear();
- for (unsigned long i = 0; i < hosts.size(); ++i)
- {
- scoped_ptr con(new bsp_con(hosts[i]));
- dlib::serialize(node_id, con->stream); // tell the other end our node_id
- unsigned long id = i+1;
- cons.add(id, con);
- }
- }
-
- void connect_all_hostinfo (
- map_id_to_con& cons,
- const std::vector& hosts,
- unsigned long node_id,
- std::string& error_string
- )
- {
- cons.clear();
- for (unsigned long i = 0; i < hosts.size(); ++i)
- {
- try
- {
- scoped_ptr con(new bsp_con(hosts[i].addr));
- dlib::serialize(node_id, con->stream); // tell the other end our node_id
- con->stream.flush();
- unsigned long id = hosts[i].node_id;
- cons.add(id, con);
- }
- catch (std::exception&)
- {
- std::ostringstream sout;
- sout << "Could not connect to " << hosts[i].addr;
- error_string = sout.str();
- break;
- }
- }
- }
-
-
- void send_out_connection_orders (
- map_id_to_con& cons,
- const std::vector& hosts
- )
- {
- // tell everyone their node ids
- cons.reset();
- while (cons.move_next())
- {
- dlib::serialize(cons.element().key(), cons.element().value()->stream);
- }
-
- // now tell them who to connect to
- std::vector targets;
- for (unsigned long i = 0; i < hosts.size(); ++i)
- {
- hostinfo info(hosts[i], i+1);
-
- dlib::serialize(targets, cons[info.node_id]->stream);
- targets.push_back(info);
-
- // let the other host know how many incoming connections to expect
- const unsigned long num = hosts.size()-targets.size();
- dlib::serialize(num, cons[info.node_id]->stream);
- cons[info.node_id]->stream.flush();
- }
- }
-
- // ------------------------------------------------------------------------------------
-
-
- }
-
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-
- namespace impl2
- {
- // These control bytes are sent before each message between nodes. Note that many
- // of these are only sent between the control node (node 0) and the other nodes.
- // This is because the controller node is responsible for handling the
- // synchronization that needs to happen when all nodes block on calls to
- // receive_data()
- // at the same time.
-
- // denotes a normal content message.
- const static char MESSAGE_HEADER = 0;
-
- // sent to the controller node when someone receives a message via receive_data().
- const static char GOT_MESSAGE = 1;
-
- // sent to the controller node when someone sends a message via send().
- const static char SENT_MESSAGE = 2;
-
- // sent to the controller node when someone enters a call to receive_data()
- const static char IN_WAITING_STATE = 3;
-
- // broadcast when a node terminates itself.
- const static char NODE_TERMINATE = 5;
-
- // broadcast by the controller node when it determines that all nodes are blocked
- // on calls to receive_data() and there aren't any messages in flight. This is also
- // what makes us go to the next epoch.
- const static char SEE_ALL_IN_WAITING_STATE = 6;
-
- // This isn't ever transmitted between nodes. It is used internally to indicate
- // that an error occurred.
- const static char READ_ERROR = 7;
-
- // ------------------------------------------------------------------------------------
-
- void read_thread (
- impl1::bsp_con* con,
- unsigned long node_id,
- unsigned long sender_id,
- impl1::thread_safe_message_queue& msg_buffer
- )
- {
- try
- {
- while(true)
- {
- impl1::msg_data msg;
- deserialize(msg.msg_type, con->stream);
- msg.sender_id = sender_id;
-
- if (msg.msg_type == MESSAGE_HEADER)
- {
- msg.data.reset(new std::vector);
- deserialize(msg.epoch, con->stream);
- deserialize(*msg.data, con->stream);
- }
-
- msg_buffer.push_and_consume(msg);
-
- if (msg.msg_type == NODE_TERMINATE)
- break;
- }
- }
- catch (std::exception& e)
- {
- impl1::msg_data msg;
- msg.data.reset(new std::vector);
- vectorstream sout(*msg.data);
- sout << "An exception was thrown while attempting to receive a message from processing node " << sender_id << ".\n";
- sout << " Sending processing node address: " << con->con->get_foreign_ip() << ":" << con->con->get_foreign_port() << std::endl;
- sout << " Receiving processing node address: " << con->con->get_local_ip() << ":" << con->con->get_local_port() << std::endl;
- sout << " Receiving processing node id: " << node_id << std::endl;
- sout << " Error message in the exception: " << e.what() << std::endl;
-
- msg.sender_id = sender_id;
- msg.msg_type = READ_ERROR;
-
- msg_buffer.push_and_consume(msg);
- }
- catch (...)
- {
- impl1::msg_data msg;
- msg.data.reset(new std::vector);
- vectorstream sout(*msg.data);
- sout << "An exception was thrown while attempting to receive a message from processing node " << sender_id << ".\n";
- sout << " Sending processing node address: " << con->con->get_foreign_ip() << ":" << con->con->get_foreign_port() << std::endl;
- sout << " Receiving processing node address: " << con->con->get_local_ip() << ":" << con->con->get_local_port() << std::endl;
- sout << " Receiving processing node id: " << node_id << std::endl;
-
- msg.sender_id = sender_id;
- msg.msg_type = READ_ERROR;
-
- msg_buffer.push_and_consume(msg);
- }
- }
-
- // ------------------------------------------------------------------------------------
-
- }
-
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-// IMPLEMENTATION OF bsp_context OBJECT MEMBERS
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-
- void bsp_context::
- close_all_connections_gracefully(
- )
- {
- if (node_id() != 0)
- {
- _cons.reset();
- while (_cons.move_next())
- {
- // tell the other end that we are intentionally dropping the connection
- serialize(impl2::NODE_TERMINATE,_cons.element().value()->stream);
- _cons.element().value()->stream.flush();
- }
- }
-
- impl1::msg_data msg;
- // now wait for all the other nodes to terminate
- while (num_terminated_nodes < _cons.size() )
- {
- if (node_id() == 0 && num_waiting_nodes + num_terminated_nodes == _cons.size() && outstanding_messages == 0)
- {
- num_waiting_nodes = 0;
- broadcast_byte(impl2::SEE_ALL_IN_WAITING_STATE);
- ++current_epoch;
- }
-
- if (!msg_buffer.pop(msg))
- throw dlib::socket_error("Error reading from msg_buffer in dlib::bsp_context.");
-
- if (msg.msg_type == impl2::NODE_TERMINATE)
- {
- ++num_terminated_nodes;
- _cons[msg.sender_id]->terminated = true;
- }
- else if (msg.msg_type == impl2::READ_ERROR)
- {
- throw dlib::socket_error(msg.data_to_string());
- }
- else if (msg.msg_type == impl2::MESSAGE_HEADER)
- {
- throw dlib::socket_error("A BSP node received a message after it has terminated.");
- }
- else if (msg.msg_type == impl2::GOT_MESSAGE)
- {
- --num_waiting_nodes;
- --outstanding_messages;
- }
- else if (msg.msg_type == impl2::SENT_MESSAGE)
- {
- ++outstanding_messages;
- }
- else if (msg.msg_type == impl2::IN_WAITING_STATE)
- {
- ++num_waiting_nodes;
- }
- }
-
- if (node_id() == 0)
- {
- _cons.reset();
- while (_cons.move_next())
- {
- // tell the other end that we are intentionally dropping the connection
- serialize(impl2::NODE_TERMINATE,_cons.element().value()->stream);
- _cons.element().value()->stream.flush();
- }
-
- if (outstanding_messages != 0)
- {
- std::ostringstream sout;
- sout << "A BSP job was allowed to terminate before all sent messages have been received.\n";
- sout << "There are at least " << outstanding_messages << " messages still in flight. Make sure all sent messages\n";
- sout << "have a corresponding call to receive().";
- throw dlib::socket_error(sout.str());
- }
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- bsp_context::
- ~bsp_context()
- {
- _cons.reset();
- while (_cons.move_next())
- {
- _cons.element().value()->con->shutdown();
- }
-
- msg_buffer.disable();
-
- // this will wait for all the threads to terminate
- threads.clear();
- }
-
-// ----------------------------------------------------------------------------------------
-
- bsp_context::
- bsp_context(
- unsigned long node_id_,
- impl1::map_id_to_con& cons_
- ) :
- outstanding_messages(0),
- num_waiting_nodes(0),
- num_terminated_nodes(0),
- current_epoch(1),
- _cons(cons_),
- _node_id(node_id_)
- {
- // spawn a bunch of read threads, one for each connection
- _cons.reset();
- while (_cons.move_next())
- {
- scoped_ptr ptr(new thread_function(&impl2::read_thread,
- _cons.element().value().get(),
- _node_id,
- _cons.element().key(),
- ref(msg_buffer)));
- threads.push_back(ptr);
- }
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool bsp_context::
- receive_data (
- shared_ptr >& item,
- unsigned long& sending_node_id
- )
- {
- notify_control_node(impl2::IN_WAITING_STATE);
-
- while (true)
- {
- // If there aren't any nodes left to give us messages then return right now.
- // We need to check the msg_buffer size to make sure there aren't any
- // unprocessed message there. Recall that this can happen because status
- // messages always jump to the front of the message buffer. So we might have
- // learned about the node terminations before processing their messages for us.
- if (num_terminated_nodes == _cons.size() && msg_buffer.size() == 0)
- {
- return false;
- }
-
- // if all running nodes are currently blocking forever on receive_data()
- if (node_id() == 0 && outstanding_messages == 0 && num_terminated_nodes + num_waiting_nodes == _cons.size())
- {
- num_waiting_nodes = 0;
- broadcast_byte(impl2::SEE_ALL_IN_WAITING_STATE);
-
- // Note that the reason we have this epoch counter is so we can tell if a
- // sent message is from before or after one of these "all nodes waiting"
- // synchronization events. If we didn't have the epoch count we would have
- // a race condition where one node gets the SEE_ALL_IN_WAITING_STATE
- // message before others and then sends out a message to another node
- // before that node got the SEE_ALL_IN_WAITING_STATE message. Then that
- // node would think the normal message came before SEE_ALL_IN_WAITING_STATE
- // which would be bad.
- ++current_epoch;
- return false;
- }
-
- impl1::msg_data data;
- if (!msg_buffer.pop(data, current_epoch))
- throw dlib::socket_error("Error reading from msg_buffer in dlib::bsp_context.");
-
-
- switch(data.msg_type)
- {
- case impl2::MESSAGE_HEADER: {
- item = data.data;
- sending_node_id = data.sender_id;
- notify_control_node(impl2::GOT_MESSAGE);
- return true;
- } break;
-
- case impl2::IN_WAITING_STATE: {
- ++num_waiting_nodes;
- } break;
-
- case impl2::GOT_MESSAGE: {
- --outstanding_messages;
- --num_waiting_nodes;
- } break;
-
- case impl2::SENT_MESSAGE: {
- ++outstanding_messages;
- } break;
-
- case impl2::NODE_TERMINATE: {
- ++num_terminated_nodes;
- _cons[data.sender_id]->terminated = true;
- } break;
-
- case impl2::SEE_ALL_IN_WAITING_STATE: {
- ++current_epoch;
- return false;
- } break;
-
- case impl2::READ_ERROR: {
- throw dlib::socket_error(data.data_to_string());
- } break;
-
- default: {
- throw dlib::socket_error("Unknown message received by dlib::bsp_context");
- } break;
- } // end switch()
- } // end while (true)
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bsp_context::
- notify_control_node (
- char val
- )
- {
- if (node_id() == 0)
- {
- using namespace impl2;
- switch(val)
- {
- case SENT_MESSAGE: {
- ++outstanding_messages;
- } break;
-
- case GOT_MESSAGE: {
- --outstanding_messages;
- } break;
-
- case IN_WAITING_STATE: {
- // nothing to do in this case
- } break;
-
- default:
- DLIB_CASSERT(false,"This should never happen");
- }
- }
- else
- {
- serialize(val, _cons[0]->stream);
- _cons[0]->stream.flush();
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bsp_context::
- broadcast_byte (
- char val
- )
- {
- for (unsigned long i = 0; i < number_of_nodes(); ++i)
- {
- // don't send to yourself or to terminated nodes
- if (i == node_id() || _cons[i]->terminated)
- continue;
-
- serialize(val, _cons[i]->stream);
- _cons[i]->stream.flush();
- }
- }
-
-// ----------------------------------------------------------------------------------------
-
- void bsp_context::
- send_data(
- const std::vector& item,
- unsigned long target_node_id
- )
- {
- using namespace impl2;
- if (_cons[target_node_id]->terminated)
- throw socket_error("Attempt to send a message to a node that has terminated.");
-
- serialize(MESSAGE_HEADER, _cons[target_node_id]->stream);
- serialize(current_epoch, _cons[target_node_id]->stream);
- serialize(item, _cons[target_node_id]->stream);
- _cons[target_node_id]->stream.flush();
-
- notify_control_node(SENT_MESSAGE);
- }
-
-// ----------------------------------------------------------------------------------------
-
-}
-
-#endif // DLIB_BSP_CPph_
-
diff --git a/lib/3rdParty/dlib/include/dlib/bsp/bsp.h b/lib/3rdParty/dlib/include/dlib/bsp/bsp.h
index 59485a01..f0732c15 100644
--- a/lib/3rdParty/dlib/include/dlib/bsp/bsp.h
+++ b/lib/3rdParty/dlib/include/dlib/bsp/bsp.h
@@ -4,17 +4,19 @@
#define DLIB_BsP_Hh_
#include "bsp_abstract.h"
+
+#include
+#include
+#include
+
#include "../sockets.h"
#include "../array.h"
-#include "../smart_pointers.h"
#include "../sockstreambuf.h"
#include "../string.h"
#include "../serialize.h"
#include "../map.h"
#include "../ref.h"
#include "../vectorstream.h"
-#include