├── .gitattributes ├── .gitignore ├── CMakeFiles └── cmake.check_cache ├── CMakeLists.txt ├── README.md ├── app ├── CMakeLists.txt ├── main │ ├── CMakeLists.txt │ └── y.cpp └── para │ ├── CMakeLists.txt │ └── example_para.cpp ├── appveyor.yml ├── cmake ├── AutoCollect.cmake ├── Colors.cmake ├── ConfigSafeGuards.cmake ├── LTO.cmake ├── Misc.cmake ├── Warnings.cmake └── macros │ ├── AutoCollect.cmake │ ├── CheckBuildDir.cmake │ ├── CheckPlatform.cmake │ ├── ConfigureBaseTargets.cmake │ ├── ConfigureScripts.cmake │ ├── EnsureVersion.cmake │ ├── FindBoost.cmake │ ├── FindMySQL.cmake │ ├── FindOpenSSL.cmake │ ├── FindPCHSupport.cmake │ ├── FindPackageHandleStandardArgs.cmake │ ├── FindPackageMessage.cmake │ ├── FindReadline.cmake │ └── GroupSources.cmake ├── dep ├── CMakeLists.txt ├── boost │ └── CMakeLists.txt ├── bzip2 │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README │ ├── blocksort.c │ ├── bzlib.c │ ├── bzlib.h │ ├── bzlib_private.h │ ├── compress.c │ ├── crctable.c │ ├── decompress.c │ ├── huffman.c │ └── randtable.c ├── httprequest │ ├── CMakeLists.txt │ ├── HttpManager.cpp │ ├── HttpManager.h │ ├── HttpRequest.cpp │ ├── HttpRequest.h │ └── SPSCQueue.h ├── jsonlib │ ├── CMakeLists.txt │ ├── allocator.h │ ├── assertions.h │ ├── config.h │ ├── forwards.h │ ├── json.h │ ├── json_features.h │ ├── json_reader.cpp │ ├── json_tool.h │ ├── json_value.cpp │ ├── json_valueiterator.inl │ ├── json_writer.cpp │ ├── parser.cpp │ ├── parser.h │ ├── reader.h │ ├── value.h │ ├── version.h │ └── writer.h ├── log │ ├── CMakeLists.txt │ └── spdlog │ │ ├── async.cpp │ │ ├── async.h │ │ ├── async_logger-inl.h │ │ ├── async_logger.h │ │ ├── bundled_fmtlib_format.cpp │ │ ├── cfg.cpp │ │ ├── cfg │ │ ├── argv.h │ │ ├── env.h │ │ ├── helpers-inl.h │ │ └── helpers.h │ │ ├── color_sinks.cpp │ │ ├── common-inl.h │ │ ├── common.h │ │ ├── details │ │ ├── backtracer-inl.h │ │ ├── backtracer.h │ │ ├── circular_q.h │ │ ├── console_globals.h │ │ ├── file_helper-inl.h │ │ ├── file_helper.h │ │ ├── fmt_helper.h │ │ ├── log_msg-inl.h │ │ ├── log_msg.h │ │ ├── log_msg_buffer-inl.h │ │ ├── log_msg_buffer.h │ │ ├── mpmc_blocking_q.h │ │ ├── null_mutex.h │ │ ├── os-inl.h │ │ ├── os.h │ │ ├── periodic_worker-inl.h │ │ ├── periodic_worker.h │ │ ├── registry-inl.h │ │ ├── registry.h │ │ ├── synchronous_factory.h │ │ ├── tcp_client-windows.h │ │ ├── tcp_client.h │ │ ├── thread_pool-inl.h │ │ ├── thread_pool.h │ │ ├── udp_client-windows.h │ │ ├── udp_client.h │ │ └── windows_include.h │ │ ├── file_sinks.cpp │ │ ├── fmt │ │ ├── bin_to_hex.h │ │ ├── bundled │ │ │ ├── args.h │ │ │ ├── chrono.h │ │ │ ├── color.h │ │ │ ├── compile.h │ │ │ ├── core.h │ │ │ ├── fmt.license.rst │ │ │ ├── format-inl.h │ │ │ ├── format.h │ │ │ ├── locale.h │ │ │ ├── os.h │ │ │ ├── ostream.h │ │ │ ├── printf.h │ │ │ ├── ranges.h │ │ │ ├── std.h │ │ │ └── xchar.h │ │ ├── chrono.h │ │ ├── compile.h │ │ ├── fmt.h │ │ ├── ostr.h │ │ ├── ranges.h │ │ ├── std.h │ │ └── xchar.h │ │ ├── formatter.h │ │ ├── fwd.h │ │ ├── logger-inl.h │ │ ├── logger.h │ │ ├── pattern_formatter-inl.h │ │ ├── pattern_formatter.h │ │ ├── sinks │ │ ├── android_sink.h │ │ ├── ansicolor_sink-inl.h │ │ ├── ansicolor_sink.h │ │ ├── base_sink-inl.h │ │ ├── base_sink.h │ │ ├── basic_file_sink-inl.h │ │ ├── basic_file_sink.h │ │ ├── callback_sink.h │ │ ├── daily_file_sink.h │ │ ├── dist_sink.h │ │ ├── dup_filter_sink.h │ │ ├── hourly_file_sink.h │ │ ├── kafka_sink.h │ │ ├── mongo_sink.h │ │ ├── msvc_sink.h │ │ ├── null_sink.h │ │ ├── ostream_sink.h │ │ ├── qt_sinks.h │ │ ├── ringbuffer_sink.h │ │ ├── rotating_file_sink-inl.h │ │ ├── rotating_file_sink.h │ │ ├── sink-inl.h │ │ ├── sink.h │ │ ├── stdout_color_sinks-inl.h │ │ ├── stdout_color_sinks.h │ │ ├── stdout_sinks-inl.h │ │ ├── stdout_sinks.h │ │ ├── syslog_sink.h │ │ ├── systemd_sink.h │ │ ├── tcp_sink.h │ │ ├── udp_sink.h │ │ ├── win_eventlog_sink.h │ │ ├── wincolor_sink-inl.h │ │ └── wincolor_sink.h │ │ ├── spdlog-inl.h │ │ ├── spdlog.cpp │ │ ├── spdlog.h │ │ ├── stdout_sinks.cpp │ │ ├── stopwatch.h │ │ ├── tweakme.h │ │ └── version.h ├── readline │ └── CMakeLists.txt ├── restclient │ ├── CMakeLists.txt │ ├── Connection.cpp │ ├── Connection.h │ ├── Helper.cpp │ ├── Helper.h │ ├── RestClient.cpp │ └── RestClient.h ├── threads │ └── CMakeLists.txt ├── utf8cpp │ ├── CMakeLists.txt │ ├── utf8.h │ └── utf8 │ │ ├── checked.h │ │ ├── core.h │ │ ├── cpp11.h │ │ ├── cpp17.h │ │ └── unchecked.h └── zlib │ ├── CMakeLists.txt │ ├── adler32.c │ ├── compress.c │ ├── crc32.c │ ├── crc32.h │ ├── deflate.c │ ├── deflate.h │ ├── gzclose.c │ ├── gzguts.h │ ├── gzlib.c │ ├── gzread.c │ ├── gzwrite.c │ ├── infback.c │ ├── inffast.c │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inftrees.c │ ├── inftrees.h │ ├── trees.c │ ├── trees.h │ ├── uncompr.c │ ├── zconf.h │ ├── zlib.h │ ├── zutil.c │ └── zutil.h ├── example ├── helloworld.y └── readfile.y ├── include ├── Config.h.in ├── Dummy.h └── Tlog.h ├── setup.sh └── src ├── CMakeLists.txt ├── Dummy.cpp ├── Tlog.cpp └── common ├── CMakeLists.txt └── CommonBase ├── Base.cpp ├── Base.h └── CMakeLists.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Lineendings 2 | *.sln eol=crlf 3 | *.vcproj eol=crlf 4 | *.vcxproj* eol=crlf 5 | 6 | src/shared/revision_nr.h eol=lf 7 | src/shared/revision_sql.h eol=lf 8 | 9 | # Whitespace rules 10 | # strict (no trailing, no tabs) 11 | *.cpp whitespace=trailing-space,space-before-tab,tab-in-indent,cr-at-eol 12 | *.h whitespace=trailing-space,space-before-tab,tab-in-indent,cr-at-eol 13 | 14 | # normal (no trailing) 15 | *.sql whitespace=trailing-space,space-before-tab,cr-at-eol 16 | *.txt whitespace=trailing-space,space-before-tab,cr-at-eol 17 | 18 | # special files which must ignore whitespace 19 | *.patch whitespace=-trailing-space 20 | 21 | 22 | *.cpp linguist-language=c++ 23 | *.hpp linguist-language=c++ 24 | *.cxx linguist-language=c++ 25 | *.in linguist-language=c++ 26 | *.h linguist-language=c++ 27 | *.c linguist-language=c 28 | *.y linguist-language=y 29 | *.java linguist-language=java 30 | *.sh linguist-language=shell 31 | *.xml linguist-language=xml 32 | *.md linguist-language=markdown 33 | *.html linguist-language=html 34 | *.cmake linguist-language=cmake 35 | CMakeLists.txt linguist-language=cmake -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | *.x 34 | 35 | # Build directory 36 | build/ 37 | 38 | cmake-build* 39 | 40 | .idea -------------------------------------------------------------------------------- /CMakeFiles/cmake.check_cache: -------------------------------------------------------------------------------- 1 | # This file is generated by cmake for dependency checking of the CMakeCache.txt file 2 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This is y language which called y language 2 | 3 | cmake_minimum_required(VERSION 3.12.4) 4 | 5 | project(y VERSION 0.1 ) 6 | 7 | set(CMAKE_BUILD_TYPE Release) 8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY executable) 9 | 10 | set(CMAKE_CXX_STANDARD 17) 11 | 12 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY executable) 13 | cmake_policy(SET CMP0144 NEW) 14 | # -------------------------------------------------------------------------------- 15 | # Config 16 | # -------------------------------------------------------------------------------- 17 | 18 | set(CMAKE_INSTALL_PREFIX /usr/local/${PROJECT_NAME}) 19 | link_directories(/usr/local/openssl/lib) 20 | set(OPENSSL_INCLUDE_DIR /usr/local/openssl/include) 21 | set(OPENSSL_CRYPTO_LIBRARY /usr/local/openssl/lib) 22 | set(OPENSSL_SSL_LIBRARY /usr/local/openssl/lib) 23 | 24 | set(BOOST_ROOT /usr/local/boost) 25 | link_directories(/usr/local/boost/lib) 26 | include_directories(/usr/local/boost/include) 27 | find_package(OpenSSL REQUIRED COMPONENTS Crypto SSL) 28 | 29 | # -------------------------------------------------------------------------------- 30 | # Options 31 | # -------------------------------------------------------------------------------- 32 | # Options: Things you can set via commandline options to cmake (e.g. -DENABLE_LTO=[ON|OFF]) 33 | option(ENABLE_WARNINGS_SETTINGS "Allow target_set_warnings to add flags and defines. 34 | Set this to OFF if you want to provide your own warning parameters." ON) 35 | option(ENABLE_LTO "Enable link time optimization" ON) 36 | option(ENABLE_DOCTESTS "Include tests in the library. Setting this to OFF will remove all doctest related code. 37 | Tests in tests/*.cpp will still be enabled." ON) 38 | 39 | # Include stuff. No change needed. 40 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") 41 | include(ConfigSafeGuards) 42 | include(Colors) 43 | #include(CTest) 44 | include(LTO) 45 | include(Misc) 46 | include(Warnings) 47 | include(AutoCollect) 48 | 49 | # Check for LTO support. 50 | find_lto(CXX) 51 | 52 | # -------------------------------------------------------------------------------- 53 | # Locate files (change as needed). 54 | # -------------------------------------------------------------------------------- 55 | CollectSourceFiles( 56 | ${CMAKE_CURRENT_SOURCE_DIR}/src 57 | PRIVATE_SOURCES 58 | # Exclude 59 | ${CMAKE_CURRENT_SOURCE_DIR}/src/log) 60 | 61 | 62 | message("CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) 63 | message("PRIVATE_SOURCES: " ${PRIVATE_SOURCES}) 64 | 65 | set(SOURCES # All .cpp files in src/ 66 | ${PRIVATE_SOURCES} 67 | ${Header_List} ) 68 | message("SOURCES: " ${SOURCES}) 69 | 70 | set(TESTFILES # All .cpp files in tests/ 71 | tests/y.cpp 72 | ) 73 | set(LIBRARY_NAME engine) # Default name for the library built from src/*.cpp (change if you wish) 74 | 75 | 76 | # Set up tests (see tests/CMakeLists.txt). 77 | #add_subdirectory(tests) 78 | 79 | # cmake config 80 | list(APPEND CMAKE_MODULE_PATH 81 | "${CMAKE_SOURCE_DIR}/cmake/macros") 82 | 83 | # -------------------------------------------------------------------------------- 84 | # Build! (Change as needed) 85 | # -------------------------------------------------------------------------------- 86 | add_subdirectory(app) 87 | add_subdirectory(dep) 88 | add_subdirectory(src) 89 | 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Y language 2 | ================================ 3 | > a new script language which called Y language or WHY language 4 | 5 | ## website 6 | [office website](http://y-lang.org) 7 | 8 | ## example 9 | ```why 10 | #!/bin/why 11 | 12 | msg = "hello world!" 13 | fun helloworld(msg) 14 | { 15 | print(msg) 16 | return msg 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # app 2 | add_subdirectory(para) 3 | add_subdirectory(main) -------------------------------------------------------------------------------- /app/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message("CMakeLists.txt load y ...") 2 | 3 | SET(MAIN_EXECUTE y) 4 | 5 | add_executable(${MAIN_EXECUTE} y.cpp) # Name of exec. and location of file. 6 | 7 | target_link_libraries(${MAIN_EXECUTE} 8 | PRIVATE 9 | engine 10 | ) 11 | 12 | target_set_warnings(${MAIN_EXECUTE} ENABLE ALL AS_ERROR ALL DISABLE Annoying) # Set warnings (if needed). 13 | target_enable_lto(${MAIN_EXECUTE} optimized) # enable link-time-optimization if available for non-debug configurations 14 | 15 | target_compile_definitions(${MAIN_EXECUTE} PRIVATE BOOST_STACKTRACE_USE_ADDR2LINE) 16 | target_link_libraries(${MAIN_EXECUTE} PRIVATE dl) 17 | 18 | ## cmake 3.27 required 19 | #target_link_options(${MAIN_EXECUTE} PRIVATE "-no-pie") 20 | 21 | install(TARGETS ${MAIN_EXECUTE} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) 22 | -------------------------------------------------------------------------------- /app/main/y.cpp: -------------------------------------------------------------------------------- 1 | #ifdef ENABLE_DOCTEST_IN_LIBRARY 2 | #define DOCTEST_CONFIG_IMPLEMENT 3 | #include "doctest/doctest.h" 4 | #endif 5 | 6 | #include 7 | #include 8 | 9 | #include "exampleConfig.h" 10 | #include "Dummy.h" 11 | #include "Tlog.h" 12 | 13 | #include "spdlog/spdlog.h" 14 | 15 | 16 | 17 | /* 18 | */ 19 | int main() { 20 | spdlog::info("Welcome to Y language: {} !", "any thing"); 21 | std::system("echo Y language is a new language !"); 22 | 23 | std::cout<<__cplusplus< 12 | #include 13 | #include 14 | #include 15 | 16 | void print_stacktrace(int signum) { 17 | ::signal(signum, SIG_DFL); 18 | printf("Stack trace:\n%s\n", boost::stacktrace::to_string(boost::stacktrace::stacktrace()).c_str()); 19 | ::raise(SIGABRT); 20 | } 21 | 22 | void crash2222 () 23 | { 24 | char* aaa = nullptr; 25 | std::string bbb(aaa); 26 | std::vector x(5); 27 | for (int i =0; i < 100; ++ i) 28 | x[i] += 3.0 * i; 29 | } 30 | 31 | int main() { 32 | ::signal(SIGSEGV, &print_stacktrace); 33 | ::signal(SIGABRT, &print_stacktrace); 34 | 35 | // spdlog::info("test para {} !", "any api"); 36 | 37 | // crash2222(); 38 | 39 | HttpRequest httpRequest; 40 | httpRequest.RequestDirect("http://postman-echo.com/headers"); 41 | 42 | return 0; 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | #---------------------------------# 2 | # environment configuration # 3 | #---------------------------------# 4 | 5 | # Build worker image (VM template) 6 | image: WMF 5 7 | 8 | clone_depth: 3 9 | 10 | platform: 11 | - Win32 12 | - x64 13 | 14 | configuration: 15 | - Debug 16 | - Release 17 | 18 | # environment: 19 | # matrix: 20 | # - TOOLSET: v140 21 | 22 | matrix: 23 | fast_finish: false 24 | 25 | # scripts that are called at very beginning, before repo cloning 26 | init: 27 | - cmd: cmake --version 28 | - cmd: msbuild /version 29 | 30 | before_build: 31 | - cmake . -Bbuild -A%PLATFORM% -DCMAKE_BUILD_TYPE=%configuration% 32 | 33 | build: 34 | project: build/CPP_BOILERPLATE.sln 35 | parallel: true 36 | verbosity: minimal 37 | 38 | test_script: 39 | - cd build 40 | - set CTEST_OUTPUT_ON_FAILURE=1 41 | - ctest -C %configuration% 42 | - cd .. 43 | -------------------------------------------------------------------------------- /cmake/AutoCollect.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | # Collects all source files into the given variable, 12 | # which is useful to include all sources in subdirectories. 13 | # Ignores full qualified directories listed in the variadic arguments. 14 | # 15 | # Use it like: 16 | # CollectSourceFiles( 17 | # ${CMAKE_CURRENT_SOURCE_DIR} 18 | # COMMON_PRIVATE_SOURCES 19 | # # Exclude 20 | # ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders 21 | # ${CMAKE_CURRENT_SOURCE_DIR}/Platform) 22 | # 23 | function(CollectSourceFiles current_dir variable) 24 | list(FIND ARGN "${current_dir}" IS_EXCLUDED) 25 | if(IS_EXCLUDED EQUAL -1) 26 | file(GLOB COLLECTED_SOURCES 27 | ${current_dir}/*.c 28 | ${current_dir}/*.cc 29 | ${current_dir}/*.cpp) 30 | list(APPEND ${variable} ${COLLECTED_SOURCES}) 31 | 32 | file(GLOB SUB_DIRECTORIES ${current_dir}/*) 33 | foreach(SUB_DIRECTORY ${SUB_DIRECTORIES}) 34 | if(IS_DIRECTORY ${SUB_DIRECTORY}) 35 | CollectSourceFiles("${SUB_DIRECTORY}" "${variable}" "${ARGN}") 36 | endif() 37 | endforeach() 38 | set(${variable} ${${variable}} PARENT_SCOPE) 39 | endif() 40 | endfunction() 41 | 42 | # Collects all subdirectoroies into the given variable, 43 | # which is useful to include all subdirectories. 44 | # Ignores full qualified directories listed in the variadic arguments. 45 | # 46 | # Use it like: 47 | # CollectIncludeDirectories( 48 | # ${CMAKE_CURRENT_SOURCE_DIR} 49 | # COMMON_PUBLIC_INCLUDES 50 | # # Exclude 51 | # ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders 52 | # ${CMAKE_CURRENT_SOURCE_DIR}/Platform) 53 | # 54 | function(CollectIncludeDirectories current_dir variable) 55 | list(FIND ARGN "${current_dir}" IS_EXCLUDED) 56 | if(IS_EXCLUDED EQUAL -1) 57 | list(APPEND ${variable} ${current_dir}) 58 | file(GLOB SUB_DIRECTORIES ${current_dir}/*) 59 | foreach(SUB_DIRECTORY ${SUB_DIRECTORIES}) 60 | if(IS_DIRECTORY ${SUB_DIRECTORY}) 61 | CollectIncludeDirectories("${SUB_DIRECTORY}" "${variable}" "${ARGN}") 62 | endif() 63 | endforeach() 64 | set(${variable} ${${variable}} PARENT_SCOPE) 65 | endif() 66 | endfunction() 67 | -------------------------------------------------------------------------------- /cmake/Colors.cmake: -------------------------------------------------------------------------------- 1 | IF(NOT WIN32) 2 | string(ASCII 27 Esc) 3 | set(ColorReset "${Esc}[m") 4 | set(ColorBold "${Esc}[1m") 5 | set(Red "${Esc}[31m") 6 | set(Green "${Esc}[32m") 7 | set(Yellow "${Esc}[33m") 8 | set(Blue "${Esc}[34m") 9 | set(Magenta "${Esc}[35m") 10 | set(Cyan "${Esc}[36m") 11 | set(White "${Esc}[37m") 12 | set(BoldRed "${Esc}[1;31m") 13 | set(BoldGreen "${Esc}[1;32m") 14 | set(BoldYellow "${Esc}[1;33m") 15 | set(BoldBlue "${Esc}[1;34m") 16 | set(BoldMagenta "${Esc}[1;35m") 17 | set(BoldCyan "${Esc}[1;36m") 18 | set(BoldWhite "${Esc}[1;37m") 19 | ENDIF() 20 | -------------------------------------------------------------------------------- /cmake/ConfigSafeGuards.cmake: -------------------------------------------------------------------------------- 1 | # guard against in-source builds 2 | if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) 3 | message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.") 4 | endif() 5 | 6 | # guard against bad build-type strings 7 | if (NOT CMAKE_BUILD_TYPE) 8 | message(STATUS "No build type selected, default to Debug") 9 | set(CMAKE_BUILD_TYPE "Debug") 10 | endif() 11 | 12 | string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower) 13 | string(TOUPPER "${CMAKE_BUILD_TYPE}" cmake_build_type_toupper) 14 | if( NOT cmake_build_type_tolower STREQUAL "debug" 15 | AND NOT cmake_build_type_tolower STREQUAL "release" 16 | AND NOT cmake_build_type_tolower STREQUAL "profile" 17 | AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo" 18 | AND NOT cmake_build_type_tolower STREQUAL "coverage") 19 | message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Coverage, Release, Profile, RelWithDebInfo (case-insensitive).") 20 | endif() 21 | -------------------------------------------------------------------------------- /cmake/Misc.cmake: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------------- 2 | # Misc (no change needed). 3 | # -------------------------------------------------------------------------------- 4 | # Have CMake parse the config file, generating the config header, with 5 | # correct definitions. Here only used to make version number available to 6 | # the source code. Include "exampleConfig.h" (no .in suffix) in the source. 7 | configure_file ( 8 | "${PROJECT_SOURCE_DIR}/include/Config.h.in" 9 | "${PROJECT_BINARY_DIR}/exampleConfig.h" 10 | ) 11 | # add the binary tree to the search path for include files 12 | # so that we will find exampleConfig.h 13 | include_directories("${PROJECT_BINARY_DIR}") 14 | 15 | # Ask CMake to output a compile_commands.json file for use with things like Vim YCM. 16 | set(CMAKE_EXPORT_COMPILE_COMMANDS 1) 17 | -------------------------------------------------------------------------------- /cmake/macros/AutoCollect.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | # Collects all source files into the given variable, 12 | # which is useful to include all sources in subdirectories. 13 | # Ignores full qualified directories listed in the variadic arguments. 14 | # 15 | # Use it like: 16 | # CollectSourceFiles( 17 | # ${CMAKE_CURRENT_SOURCE_DIR} 18 | # COMMON_PRIVATE_SOURCES 19 | # # Exclude 20 | # ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders 21 | # ${CMAKE_CURRENT_SOURCE_DIR}/Platform) 22 | # 23 | function(CollectSourceFiles current_dir variable) 24 | list(FIND ARGN "${current_dir}" IS_EXCLUDED) 25 | if(IS_EXCLUDED EQUAL -1) 26 | file(GLOB COLLECTED_SOURCES 27 | ${current_dir}/*.c 28 | ${current_dir}/*.cc 29 | ${current_dir}/*.cpp 30 | ${current_dir}/*.inl 31 | ${current_dir}/*.def 32 | ${current_dir}/*.h 33 | ${current_dir}/*.hh 34 | ${current_dir}/*.hpp) 35 | list(APPEND ${variable} ${COLLECTED_SOURCES}) 36 | 37 | file(GLOB SUB_DIRECTORIES ${current_dir}/*) 38 | foreach(SUB_DIRECTORY ${SUB_DIRECTORIES}) 39 | if(IS_DIRECTORY ${SUB_DIRECTORY}) 40 | CollectSourceFiles("${SUB_DIRECTORY}" "${variable}" "${ARGN}") 41 | endif() 42 | endforeach() 43 | set(${variable} ${${variable}} PARENT_SCOPE) 44 | endif() 45 | endfunction() 46 | 47 | # Collects all subdirectoroies into the given variable, 48 | # which is useful to include all subdirectories. 49 | # Ignores full qualified directories listed in the variadic arguments. 50 | # 51 | # Use it like: 52 | # CollectIncludeDirectories( 53 | # ${CMAKE_CURRENT_SOURCE_DIR} 54 | # COMMON_PUBLIC_INCLUDES 55 | # # Exclude 56 | # ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders 57 | # ${CMAKE_CURRENT_SOURCE_DIR}/Platform) 58 | # 59 | function(CollectIncludeDirectories current_dir variable) 60 | list(FIND ARGN "${current_dir}" IS_EXCLUDED) 61 | if(IS_EXCLUDED EQUAL -1) 62 | list(APPEND ${variable} ${current_dir}) 63 | file(GLOB SUB_DIRECTORIES ${current_dir}/*) 64 | foreach(SUB_DIRECTORY ${SUB_DIRECTORIES}) 65 | if(IS_DIRECTORY ${SUB_DIRECTORY}) 66 | CollectIncludeDirectories("${SUB_DIRECTORY}" "${variable}" "${ARGN}") 67 | endif() 68 | endforeach() 69 | set(${variable} ${${variable}} PARENT_SCOPE) 70 | endif() 71 | endfunction() 72 | -------------------------------------------------------------------------------- /cmake/macros/CheckBuildDir.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | # 12 | # Force out-of-source build 13 | # 14 | 15 | string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" BUILDING_IN_SOURCE) 16 | 17 | if(BUILDING_IN_SOURCE) 18 | message(FATAL_ERROR " 19 | This project requires an out of source build. Remove the file 'CMakeCache.txt' 20 | found in this directory before continuing, create a separate build directory 21 | and run 'cmake path_to_project [options]' from there. 22 | ") 23 | endif() 24 | -------------------------------------------------------------------------------- /cmake/macros/CheckPlatform.cmake: -------------------------------------------------------------------------------- 1 | # check what platform we're on (64-bit or 32-bit), and create a simpler test than CMAKE_SIZEOF_VOID_P 2 | if(CMAKE_SIZEOF_VOID_P MATCHES 8) 3 | set(PLATFORM 64) 4 | MESSAGE(STATUS "Detected 64-bit platform") 5 | else() 6 | set(PLATFORM 32) 7 | MESSAGE(STATUS "Detected 32-bit platform") 8 | endif() 9 | 10 | if(WIN32) 11 | include("${CMAKE_SOURCE_DIR}/cmake/platform/win/settings.cmake") 12 | elseif(UNIX) 13 | include("${CMAKE_SOURCE_DIR}/cmake/platform/unix/settings.cmake") 14 | endif() 15 | -------------------------------------------------------------------------------- /cmake/macros/ConfigureBaseTargets.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | # An interface library to make the target com available to other targets 12 | add_library(trinity-compile-option-interface INTERFACE) 13 | 14 | # Use -std=c++11 instead of -std=gnu++11 15 | set(CMAKE_CXX_EXTENSIONS OFF) 16 | 17 | # An interface library to make the target features available to other targets 18 | add_library(trinity-feature-interface INTERFACE) 19 | 20 | target_compile_features(trinity-feature-interface 21 | INTERFACE 22 | cxx_std_20) 23 | 24 | # An interface library to make the warnings level available to other targets 25 | # This interface taget is set-up through the platform specific script 26 | add_library(trinity-warning-interface INTERFACE) 27 | 28 | # An interface used for all other interfaces 29 | add_library(trinity-default-interface INTERFACE) 30 | target_link_libraries(trinity-default-interface 31 | INTERFACE 32 | trinity-compile-option-interface 33 | trinity-feature-interface) 34 | 35 | # An interface used for silencing all warnings 36 | add_library(trinity-no-warning-interface INTERFACE) 37 | 38 | if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") 39 | target_compile_options(trinity-no-warning-interface 40 | INTERFACE 41 | /W0) 42 | else() 43 | target_compile_options(trinity-no-warning-interface 44 | INTERFACE 45 | -w) 46 | endif() 47 | 48 | # An interface library to change the default behaviour 49 | # to hide symbols automatically. 50 | add_library(trinity-hidden-symbols-interface INTERFACE) 51 | 52 | # An interface amalgamation which provides the flags and definitions 53 | # used by the dependency targets. 54 | add_library(trinity-dependency-interface INTERFACE) 55 | target_link_libraries(trinity-dependency-interface 56 | INTERFACE 57 | trinity-default-interface 58 | trinity-no-warning-interface 59 | trinity-hidden-symbols-interface) 60 | 61 | # An interface amalgamation which provides the flags and definitions 62 | # used by the core targets. 63 | add_library(trinity-core-interface INTERFACE) 64 | target_link_libraries(trinity-core-interface 65 | INTERFACE 66 | trinity-default-interface 67 | trinity-warning-interface) 68 | -------------------------------------------------------------------------------- /cmake/macros/ConfigureScripts.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | # Returns the base path to the script directory in the source directory 12 | function(WarnAboutSpacesInBuildPath) 13 | # Only check win32 since unix doesn't allow spaces in paths 14 | if(WIN32) 15 | string(FIND "${CMAKE_BINARY_DIR}" " " SPACE_INDEX_POS) 16 | 17 | if(SPACE_INDEX_POS GREATER -1) 18 | message("") 19 | message(WARNING " *** WARNING!\n" 20 | " *** Your selected build directory contains spaces!\n" 21 | " *** Please note that this will cause issues!") 22 | endif() 23 | endif() 24 | endfunction() 25 | 26 | # Returns the base path to the script directory in the source directory 27 | function(GetScriptsBasePath variable) 28 | set(${variable} "${CMAKE_SOURCE_DIR}/src/server/scripts" PARENT_SCOPE) 29 | endfunction() 30 | 31 | # Stores the absolut path of the given module in the variable 32 | function(GetPathToScriptModule module variable) 33 | GetScriptsBasePath(SCRIPTS_BASE_PATH) 34 | set(${variable} "${SCRIPTS_BASE_PATH}/${module}" PARENT_SCOPE) 35 | endfunction() 36 | 37 | # Stores the project name of the given module in the variable 38 | function(GetProjectNameOfScriptModule module variable) 39 | string(TOLOWER "scripts_${SCRIPT_MODULE}" GENERATED_NAME) 40 | set(${variable} "${GENERATED_NAME}" PARENT_SCOPE) 41 | endfunction() 42 | 43 | # Creates a list of all script modules 44 | # and stores it in the given variable. 45 | function(GetScriptModuleList variable) 46 | GetScriptsBasePath(BASE_PATH) 47 | file(GLOB LOCALE_SCRIPT_MODULE_LIST RELATIVE 48 | ${BASE_PATH} 49 | ${BASE_PATH}/*) 50 | 51 | set(${variable}) 52 | foreach(SCRIPT_MODULE ${LOCALE_SCRIPT_MODULE_LIST}) 53 | GetPathToScriptModule(${SCRIPT_MODULE} SCRIPT_MODULE_PATH) 54 | if(IS_DIRECTORY ${SCRIPT_MODULE_PATH}) 55 | list(APPEND ${variable} ${SCRIPT_MODULE}) 56 | endif() 57 | endforeach() 58 | set(${variable} ${${variable}} PARENT_SCOPE) 59 | endfunction() 60 | 61 | # Converts the given script module name into it's 62 | # variable name which holds the linkage type. 63 | function(ScriptModuleNameToVariable module variable) 64 | string(TOUPPER ${module} ${variable}) 65 | set(${variable} "SCRIPTS_${${variable}}") 66 | set(${variable} ${${variable}} PARENT_SCOPE) 67 | endfunction() 68 | 69 | # Stores in the given variable whether dynamic linking is required 70 | function(IsDynamicLinkingRequired variable) 71 | if(SCRIPTS MATCHES "dynamic") 72 | set(IS_DEFAULT_VALUE_DYNAMIC ON) 73 | endif() 74 | 75 | GetScriptModuleList(SCRIPT_MODULE_LIST) 76 | set(IS_REQUIRED OFF) 77 | foreach(SCRIPT_MODULE ${SCRIPT_MODULE_LIST}) 78 | ScriptModuleNameToVariable(${SCRIPT_MODULE} SCRIPT_MODULE_VARIABLE) 79 | if((${SCRIPT_MODULE_VARIABLE} STREQUAL "dynamic") OR 80 | (${SCRIPT_MODULE_VARIABLE} STREQUAL "default" AND IS_DEFAULT_VALUE_DYNAMIC)) 81 | set(IS_REQUIRED ON) 82 | break() 83 | endif() 84 | endforeach() 85 | set(${variable} ${IS_REQUIRED} PARENT_SCOPE) 86 | endfunction() 87 | 88 | # Stores the native variable name 89 | function(GetNativeSharedLibraryName module variable) 90 | if(WIN32) 91 | set(${variable} "${module}.dll" PARENT_SCOPE) 92 | elseif(APPLE) 93 | set(${variable} "lib${module}.dylib" PARENT_SCOPE) 94 | else() 95 | set(${variable} "lib${module}.so" PARENT_SCOPE) 96 | endif() 97 | endfunction() 98 | 99 | # Stores the native install path in the variable 100 | function(GetInstallOffset variable) 101 | if(WIN32) 102 | set(${variable} "${CMAKE_INSTALL_PREFIX}/scripts" PARENT_SCOPE) 103 | else() 104 | set(${variable} "${CMAKE_INSTALL_PREFIX}/bin/scripts" PARENT_SCOPE) 105 | endif() 106 | endfunction() 107 | -------------------------------------------------------------------------------- /cmake/macros/FindPCHSupport.cmake: -------------------------------------------------------------------------------- 1 | if(CMAKE_VERSION VERSION_LESS "3.16.0") 2 | if(MSVC) 3 | # Specify the maximum PreCompiled Header memory allocation limit 4 | # Fixes a compiler-problem when using PCH - the /Ym flag is adjusted by the compiler in MSVC2012, 5 | # hence we need to set an upper limit with /Zm to avoid discrepancies) 6 | # (And yes, this is a verified, unresolved bug with MSVC... *sigh*) 7 | # 8 | # Note: This workaround was verified to be required on MSVC 2017 as well 9 | set(COTIRE_PCH_MEMORY_SCALING_FACTOR 500) 10 | endif() 11 | 12 | include(cotire) 13 | 14 | function(ADD_CXX_PCH TARGET_NAME_LIST PCH_HEADER) 15 | # Use the header for every target 16 | foreach(TARGET_NAME ${TARGET_NAME_LIST}) 17 | # Disable unity builds 18 | set_target_properties(${TARGET_NAME} PROPERTIES COTIRE_ADD_UNITY_BUILD OFF) 19 | 20 | # Set the prefix header 21 | set_target_properties(${TARGET_NAME} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT ${PCH_HEADER}) 22 | 23 | # Workaround for cotire bug: https://github.com/sakra/cotire/issues/138 24 | set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 17) 25 | endforeach() 26 | 27 | cotire(${TARGET_NAME_LIST}) 28 | endfunction(ADD_CXX_PCH) 29 | else() 30 | function(ADD_CXX_PCH TARGET_NAME_LIST PCH_HEADER) 31 | foreach(TARGET_NAME ${TARGET_NAME_LIST}) 32 | target_precompile_headers(${TARGET_NAME} PRIVATE ${PCH_HEADER}) 33 | endforeach() 34 | endfunction(ADD_CXX_PCH) 35 | endif() 36 | -------------------------------------------------------------------------------- /cmake/macros/FindPackageMessage.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | #[=======================================================================[.rst: 5 | FindPackageMessage 6 | ------------------ 7 | 8 | .. code-block:: cmake 9 | 10 | find_package_message( "message for user" "find result details") 11 | 12 | This function is intended to be used in FindXXX.cmake modules files. 13 | It will print a message once for each unique find result. This is 14 | useful for telling the user where a package was found. The first 15 | argument specifies the name (XXX) of the package. The second argument 16 | specifies the message to display. The third argument lists details 17 | about the find result so that if they change the message will be 18 | displayed again. The macro also obeys the QUIET argument to the 19 | find_package command. 20 | 21 | Example: 22 | 23 | .. code-block:: cmake 24 | 25 | if(X11_FOUND) 26 | find_package_message(X11 "Found X11: ${X11_X11_LIB}" 27 | "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") 28 | else() 29 | ... 30 | endif() 31 | #]=======================================================================] 32 | 33 | function(find_package_message pkg msg details) 34 | # Avoid printing a message repeatedly for the same find result. 35 | if(NOT ${pkg}_FIND_QUIETLY) 36 | string(REPLACE "\n" "" details "${details}") 37 | set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) 38 | if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") 39 | # The message has not yet been printed. 40 | message(STATUS "${msg}") 41 | 42 | # Save the find details in the cache to avoid printing the same 43 | # message again. 44 | set("${DETAILS_VAR}" "${details}" 45 | CACHE INTERNAL "Details about finding ${pkg}") 46 | endif() 47 | endif() 48 | endfunction() 49 | -------------------------------------------------------------------------------- /cmake/macros/FindReadline.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 2 of the License, or (at your 6 | # option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, but WITHOUT 9 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | # more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along 14 | # with this program. If not, see . 15 | 16 | #[=======================================================================[.rst: 17 | FindReadline 18 | ----------- 19 | 20 | Find The GNU Readline Library. 21 | 22 | Imported Targets 23 | ^^^^^^^^^^^^^^^^ 24 | 25 | This module defines the following :prop_tgt:`IMPORTED` targets: 26 | 27 | ``Readline::Readline`` 28 | The Readline library, if found. 29 | 30 | Result Variables 31 | ^^^^^^^^^^^^^^^^ 32 | 33 | This module will set the following variables in your project: 34 | 35 | ``READLINE_FOUND`` 36 | System has The GNU Readline Library. 37 | ``READLINE_INCLUDE_DIR`` 38 | The Readline include directory. 39 | ``READLINE_LIBRARY`` 40 | The Readline library. 41 | 42 | Hints 43 | ^^^^^ 44 | 45 | Set ``READLINE_ROOT_DIR`` to the root directory of Readline installation. 46 | #]=======================================================================] 47 | 48 | find_path(READLINE_INCLUDE_DIR 49 | NAMES 50 | readline/readline.h 51 | HINTS 52 | ${READLINE_ROOT_DIR} 53 | ENV READLINE_ROOT_DIR 54 | PATH_SUFFIXES 55 | include) 56 | 57 | find_library(READLINE_LIBRARY 58 | NAMES 59 | readline 60 | HINTS 61 | ${READLINE_ROOT_DIR} 62 | ENV READLINE_ROOT_DIR 63 | PATH_SUFFIXES 64 | lib) 65 | 66 | if(READLINE_INCLUDE_DIR AND EXISTS "${READLINE_INCLUDE_DIR}/readline/readline.h") 67 | file(STRINGS "${READLINE_INCLUDE_DIR}/readline/readline.h" readline_major 68 | REGEX "^#[\t ]*define[\t ]+RL_VERSION_MAJOR[\t ]+([0-9])+.*") 69 | file(STRINGS "${READLINE_INCLUDE_DIR}/readline/readline.h" readline_minor 70 | REGEX "^#[\t ]*define[\t ]+RL_VERSION_MINOR[\t ]+([0-9])+.*") 71 | if (readline_major AND readline_minor) 72 | string(REGEX REPLACE "^.*RL_VERSION_MAJOR[\t ]+([0-9])+.*$" 73 | "\\1" readline_major "${readline_major}") 74 | string(REGEX REPLACE "^.*RL_VERSION_MINOR[\t ]+([0-9])+.*$" 75 | "\\1" readline_minor "${readline_minor}") 76 | set(READLINE_VERSION "${readline_major}.${readline_minor}") 77 | endif() 78 | endif() 79 | 80 | include(FindPackageHandleStandardArgs) 81 | find_package_handle_standard_args(Readline 82 | REQUIRED_VARS 83 | READLINE_LIBRARY 84 | READLINE_INCLUDE_DIR 85 | VERSION_VAR 86 | READLINE_VERSION 87 | ) 88 | 89 | mark_as_advanced(READLINE_FOUND READLINE_LIBRARY READLINE_INCLUDE_DIR) 90 | 91 | if(READLINE_FOUND) 92 | message(STATUS "Found Readline library: ${READLINE_LIBRARY}") 93 | message(STATUS "Found Readline headers: ${READLINE_INCLUDE_DIR}") 94 | 95 | if (NOT TARGET Readline::Readline) 96 | add_library(Readline::Readline UNKNOWN IMPORTED) 97 | set_target_properties(Readline::Readline 98 | PROPERTIES 99 | IMPORTED_LOCATION 100 | "${READLINE_LIBRARY}" 101 | INTERFACE_INCLUDE_DIRECTORIES 102 | "${READLINE_INCLUDE_DIR}") 103 | endif() 104 | endif() 105 | -------------------------------------------------------------------------------- /cmake/macros/GroupSources.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | macro(GroupSources dir) 12 | # Skip this if WITH_SOURCE_TREE is not set (empty string). 13 | if(NOT ${WITH_SOURCE_TREE} STREQUAL "") 14 | # Include all header and c files 15 | file(GLOB_RECURSE elements RELATIVE ${dir} *.h *.hpp *.c *.cpp *.cc) 16 | 17 | foreach(element ${elements}) 18 | # Extract filename and directory 19 | get_filename_component(element_name ${element} NAME) 20 | get_filename_component(element_dir ${element} DIRECTORY) 21 | 22 | if(NOT ${element_dir} STREQUAL "") 23 | # If the file is in a subdirectory use it as source group. 24 | if(${WITH_SOURCE_TREE} STREQUAL "flat") 25 | # Build flat structure by using only the first subdirectory. 26 | string(FIND ${element_dir} "/" delemiter_pos) 27 | if(NOT ${delemiter_pos} EQUAL -1) 28 | string(SUBSTRING ${element_dir} 0 ${delemiter_pos} group_name) 29 | source_group("${group_name}" FILES ${dir}/${element}) 30 | else() 31 | # Build hierarchical structure. 32 | # File is in root directory. 33 | source_group("${element_dir}" FILES ${dir}/${element}) 34 | endif() 35 | else() 36 | # Use the full hierarchical structure to build source_groups. 37 | string(REPLACE "/" "\\" group_name ${element_dir}) 38 | source_group("${group_name}" FILES ${dir}/${element}) 39 | endif() 40 | else() 41 | # If the file is in the root directory, place it in the root source_group. 42 | source_group("\\" FILES ${dir}/${element}) 43 | endif() 44 | endforeach() 45 | endif() 46 | endmacro() 47 | 48 | if(WITH_SOURCE_TREE STREQUAL "hierarchical-folders") 49 | # Use folders 50 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 51 | endif() 52 | -------------------------------------------------------------------------------- /dep/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # include dep 2 | add_subdirectory(boost) 3 | add_subdirectory(bzip2) 4 | add_subdirectory(httprequest) 5 | add_subdirectory(jsonlib) 6 | add_subdirectory(log) 7 | add_subdirectory(readline) 8 | add_subdirectory(restclient) 9 | add_subdirectory(threads) 10 | add_subdirectory(utf8cpp) 11 | add_subdirectory(zlib) -------------------------------------------------------------------------------- /dep/bzip2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | if(UNIX) 12 | # Look for an installed bzip2 on unix 13 | find_package(BZip2 REQUIRED) 14 | 15 | add_library(bzip2 SHARED IMPORTED GLOBAL) 16 | 17 | set_target_properties(bzip2 18 | PROPERTIES 19 | IMPORTED_LOCATION 20 | "${BZIP2_LIBRARIES}" 21 | INTERFACE_INCLUDE_DIRECTORIES 22 | "${BZIP2_INCLUDE_DIRS}") 23 | else() 24 | # Use the bundled source on windows 25 | file(GLOB sources *.c) 26 | add_library(bzip2 STATIC 27 | ${sources}) 28 | 29 | set_target_properties(bzip2 PROPERTIES LINKER_LANGUAGE CXX) 30 | 31 | target_include_directories(bzip2 32 | PUBLIC 33 | .) 34 | 35 | target_link_libraries(bzip2 36 | PRIVATE 37 | trinity-dependency-interface) 38 | 39 | set_target_properties(bzip2 40 | PROPERTIES 41 | FOLDER 42 | "dep") 43 | endif() 44 | -------------------------------------------------------------------------------- /dep/bzip2/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------- 3 | 4 | This program, "bzip2", the associated library "libbzip2", and all 5 | documentation, are copyright (C) 1996-2010 Julian R Seward. All 6 | rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | 15 | 2. The origin of this software must not be misrepresented; you must 16 | not claim that you wrote the original software. If you use this 17 | software in a product, an acknowledgment in the product 18 | documentation would be appreciated but is not required. 19 | 20 | 3. Altered source versions must be plainly marked as such, and must 21 | not be misrepresented as being the original software. 22 | 23 | 4. The name of the author may not be used to endorse or promote 24 | products derived from this software without specific prior written 25 | permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 28 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 29 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 31 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 33 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 35 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | 39 | Julian Seward, jseward@bzip.org 40 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 41 | 42 | -------------------------------------------------------------------------- 43 | -------------------------------------------------------------------------------- /dep/bzip2/randtable.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Table for randomising repetitive blocks ---*/ 4 | /*--- randtable.c ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #include "bzlib_private.h" 23 | 24 | 25 | /*---------------------------------------------*/ 26 | Int32 BZ2_rNums[512] = { 27 | 619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 28 | 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 29 | 733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 30 | 419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 31 | 878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 32 | 862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 33 | 150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 34 | 170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 35 | 73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 36 | 909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 37 | 641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 38 | 161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 39 | 382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 40 | 98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 41 | 227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 42 | 469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 43 | 184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 44 | 715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 45 | 951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 46 | 652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 47 | 645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 48 | 609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 49 | 653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 50 | 411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 51 | 170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 52 | 857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 53 | 669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 54 | 944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 55 | 344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 56 | 897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 57 | 433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 58 | 686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 59 | 946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 60 | 978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 61 | 680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 62 | 707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 63 | 297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 64 | 134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 65 | 343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 66 | 140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 67 | 170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 68 | 369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 69 | 804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 70 | 896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 71 | 661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 72 | 768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 73 | 61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 74 | 372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 75 | 780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 76 | 920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 77 | 645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 78 | 936, 638 79 | }; 80 | 81 | 82 | /*-------------------------------------------------------------*/ 83 | /*--- end randtable.c ---*/ 84 | /*-------------------------------------------------------------*/ 85 | -------------------------------------------------------------------------------- /dep/httprequest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message("CMakeLists.txt load http_request ...") 2 | 3 | SET(LIBRARY_NAME http_request) 4 | file(GLOB sources *.cpp *.c *.h) 5 | 6 | add_library(${LIBRARY_NAME} STATIC 7 | ${sources} 8 | ) 9 | 10 | target_include_directories(${LIBRARY_NAME} 11 | PUBLIC 12 | ../../include 13 | ${PROJECT_SOURCE_DIR}/dep/httprequest 14 | ${PROJECT_SOURCE_DIR}/dep/restclient 15 | ) 16 | 17 | target_link_libraries(${LIBRARY_NAME} 18 | rest_client 19 | ) 20 | 21 | install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) -------------------------------------------------------------------------------- /dep/httprequest/HttpManager.h: -------------------------------------------------------------------------------- 1 | #ifndef ELUNA_HTTP_MANAGER_H 2 | #define ELUNA_HTTP_MANAGER_H 3 | 4 | #include 5 | 6 | #include "RestClient.h" 7 | #include "SPSCQueue.h" 8 | #include "Connection.h" 9 | #include 10 | #include 11 | #include 12 | 13 | struct HttpWorkItem 14 | { 15 | public: 16 | HttpWorkItem(int funcRef, const std::string& httpVerb, const std::string& url, const std::string& body); 17 | HttpWorkItem(int funcRef, const std::string& httpVerb, const std::string& url, const std::string& body, const RestClient::HeaderFields& headers); 18 | 19 | int funcRef; 20 | std::string httpVerb; 21 | std::string url; 22 | std::string body; 23 | RestClient::HeaderFields headers; 24 | }; 25 | 26 | struct HttpResponse 27 | { 28 | public: 29 | HttpResponse(int funcRef, int statusCode, const std::string& body, const RestClient::HeaderFields& headers); 30 | 31 | int funcRef; 32 | int statusCode; 33 | std::string body; 34 | RestClient::HeaderFields headers; 35 | }; 36 | 37 | 38 | class HttpManager 39 | { 40 | public: 41 | HttpManager(); 42 | ~HttpManager(); 43 | 44 | static HttpManager* GetInstance(); 45 | 46 | void StartHttpWorker(); 47 | void StopHttpWorker(); 48 | void PushRequest(HttpWorkItem* item); 49 | void HandleHttpResponses(); 50 | bool ParseUrl(const std::string& url, std::string& host, std::string& path); 51 | RestClient::Response DoRequest(std::string& url); 52 | RestClient::Response DoRequest(HttpWorkItem* req); 53 | 54 | private: 55 | void ClearQueues(); 56 | void HttpWorkerThread(); 57 | 58 | rigtorp::SPSCQueue workQueue; 59 | rigtorp::SPSCQueue responseQueue; 60 | std::thread workerThread; 61 | std::thread responseThread; 62 | bool startedWorkerThread; 63 | bool startedResponseThread; 64 | std::atomic_bool cancelationToken; 65 | std::condition_variable condVar; 66 | std::mutex condVarMutex; 67 | std::regex parseUrlRegex; 68 | 69 | std::atomic_bool cancelationTokenResponse; 70 | std::condition_variable condVarResponse; 71 | std::mutex condVarMutexResponse; 72 | 73 | }; 74 | 75 | 76 | #endif // #ifndef ELUNA_HTTP_MANAGER_H 77 | -------------------------------------------------------------------------------- /dep/httprequest/HttpRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by geektcp on 11/12/23. 3 | // 4 | 5 | #ifndef EXECUTOR_HTTPREQUEST_H 6 | #define EXECUTOR_HTTPREQUEST_H 7 | 8 | #include "HttpManager.h" 9 | 10 | class HttpRequest { 11 | public: 12 | HttpRequest(); 13 | ~HttpRequest(); 14 | 15 | 16 | static HttpRequest* GetInstance(); 17 | 18 | int RequestAsync( 19 | std::string url 20 | ); 21 | 22 | int RequestAsync( 23 | std::string method, 24 | std::string url); 25 | 26 | int RequestAsync( 27 | std::string method, 28 | std::string url, 29 | std::string body); 30 | 31 | int RequestAsync(std::string method, 32 | std::string url, 33 | std::string body, 34 | std::map headers); 35 | 36 | 37 | RestClient::Response RequestDirect( 38 | std::string url 39 | ); 40 | 41 | RestClient::Response RequestDirect( 42 | std::string method, 43 | std::string url); 44 | 45 | RestClient::Response RequestDirect( 46 | std::string method, 47 | std::string url, 48 | std::string body); 49 | 50 | RestClient::Response RequestDirect(std::string method, 51 | std::string url, 52 | std::string body, 53 | std::map headers); 54 | 55 | RestClient::Response RequestDirect( 56 | HttpWorkItem* url 57 | ); 58 | 59 | }; 60 | 61 | 62 | #endif //EXECUTOR_HTTPREQUEST_H 63 | -------------------------------------------------------------------------------- /dep/jsonlib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #add_subdirectory(lib_json) 2 | #if(JSONCPP_WITH_TESTS) 3 | # add_subdirectory(jsontestrunner) 4 | # add_subdirectory(test_lib_json) 5 | #endif() 6 | 7 | 8 | #if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) 9 | # add_compile_definitions(JSON_DLL_BUILD) 10 | #else() 11 | # add_definitions(-DJSON_DLL_BUILD) 12 | #endif() 13 | 14 | set(LIBRARY_NAME json_lib) 15 | 16 | file(GLOB_RECURSE sources *.cpp *.c *.h) 17 | 18 | # STATIC or SHARED is ok, but must use STATIC in wow project 19 | add_library(${LIBRARY_NAME} SHARED 20 | ${sources} parser.cpp parser.h) 21 | 22 | #set_target_properties(${SHARED_LIB} PROPERTIES 23 | # OUTPUT_NAME jsoncpp 24 | # VERSION ${PROJECT_VERSION} 25 | # SOVERSION ${PROJECT_SOVERSION} 26 | # POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS} 27 | # ) 28 | 29 | 30 | 31 | install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) -------------------------------------------------------------------------------- /dep/jsonlib/allocator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_ALLOCATOR_H_INCLUDED 7 | #define JSON_ALLOCATOR_H_INCLUDED 8 | 9 | #include 10 | #include 11 | 12 | #pragma pack(push) 13 | #pragma pack() 14 | 15 | namespace Json { 16 | template class SecureAllocator { 17 | public: 18 | // Type definitions 19 | using value_type = T; 20 | using pointer = T*; 21 | using const_pointer = const T*; 22 | using reference = T&; 23 | using const_reference = const T&; 24 | using size_type = std::size_t; 25 | using difference_type = std::ptrdiff_t; 26 | 27 | /** 28 | * Allocate memory for N items using the standard allocator. 29 | */ 30 | pointer allocate(size_type n) { 31 | // allocate using "global operator new" 32 | return static_cast(::operator new(n * sizeof(T))); 33 | } 34 | 35 | /** 36 | * Release memory which was allocated for N items at pointer P. 37 | * 38 | * The memory block is filled with zeroes before being released. 39 | */ 40 | void deallocate(pointer p, size_type n) { 41 | // memset_s is used because memset may be optimized away by the compiler 42 | memset_s(p, n * sizeof(T), 0, n * sizeof(T)); 43 | // free using "global operator delete" 44 | ::operator delete(p); 45 | } 46 | 47 | /** 48 | * Construct an item in-place at pointer P. 49 | */ 50 | template void construct(pointer p, Args&&... args) { 51 | // construct using "placement new" and "perfect forwarding" 52 | ::new (static_cast(p)) T(std::forward(args)...); 53 | } 54 | 55 | size_type max_size() const { return size_t(-1) / sizeof(T); } 56 | 57 | pointer address(reference x) const { return std::addressof(x); } 58 | 59 | const_pointer address(const_reference x) const { return std::addressof(x); } 60 | 61 | /** 62 | * Destroy an item in-place at pointer P. 63 | */ 64 | void destroy(pointer p) { 65 | // destroy using "explicit destructor" 66 | p->~T(); 67 | } 68 | 69 | // Boilerplate 70 | SecureAllocator() {} 71 | template SecureAllocator(const SecureAllocator&) {} 72 | template struct rebind { using other = SecureAllocator; }; 73 | }; 74 | 75 | template 76 | bool operator==(const SecureAllocator&, const SecureAllocator&) { 77 | return true; 78 | } 79 | 80 | template 81 | bool operator!=(const SecureAllocator&, const SecureAllocator&) { 82 | return false; 83 | } 84 | 85 | } // namespace Json 86 | 87 | #pragma pack(pop) 88 | 89 | #endif // JSON_ALLOCATOR_H_INCLUDED 90 | -------------------------------------------------------------------------------- /dep/jsonlib/assertions.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_ASSERTIONS_H_INCLUDED 7 | #define JSON_ASSERTIONS_H_INCLUDED 8 | 9 | #include 10 | #include 11 | 12 | #if !defined(JSON_IS_AMALGAMATION) 13 | #include "config.h" 14 | #endif // if !defined(JSON_IS_AMALGAMATION) 15 | 16 | /** It should not be possible for a maliciously designed file to 17 | * cause an abort() or seg-fault, so these macros are used only 18 | * for pre-condition violations and internal logic errors. 19 | */ 20 | #if JSON_USE_EXCEPTION 21 | 22 | // @todo <= add detail about condition in exception 23 | #define JSON_ASSERT(condition) \ 24 | do { \ 25 | if (!(condition)) { \ 26 | Json::throwLogicError("assert json failed"); \ 27 | } \ 28 | } while (0) 29 | 30 | #define JSON_FAIL_MESSAGE(message) \ 31 | do { \ 32 | OStringStream oss; \ 33 | oss << message; \ 34 | Json::throwLogicError(oss.str()); \ 35 | abort(); \ 36 | } while (0) 37 | 38 | #else // JSON_USE_EXCEPTION 39 | 40 | #define JSON_ASSERT(condition) assert(condition) 41 | 42 | // The call to assert() will show the failure message in debug builds. In 43 | // release builds we abort, for a core-dump or debugger. 44 | #define JSON_FAIL_MESSAGE(message) \ 45 | { \ 46 | OStringStream oss; \ 47 | oss << message; \ 48 | assert(false && oss.str().c_str()); \ 49 | abort(); \ 50 | } 51 | 52 | #endif 53 | 54 | #define JSON_ASSERT_MESSAGE(condition, message) \ 55 | do { \ 56 | if (!(condition)) { \ 57 | JSON_FAIL_MESSAGE(message); \ 58 | } \ 59 | } while (0) 60 | 61 | #endif // JSON_ASSERTIONS_H_INCLUDED 62 | -------------------------------------------------------------------------------- /dep/jsonlib/forwards.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_FORWARDS_H_INCLUDED 7 | #define JSON_FORWARDS_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | #include "config.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | 13 | namespace Json { 14 | 15 | // writer.h 16 | class StreamWriter; 17 | class StreamWriterBuilder; 18 | class Writer; 19 | class FastWriter; 20 | class StyledWriter; 21 | class StyledStreamWriter; 22 | 23 | // reader.h 24 | class Reader; 25 | class CharReader; 26 | class CharReaderBuilder; 27 | 28 | // json_features.h 29 | class Features; 30 | 31 | // value.h 32 | using ArrayIndex = unsigned int; 33 | class StaticString; 34 | class Path; 35 | class PathArgument; 36 | class Value; 37 | class ValueIteratorBase; 38 | class ValueIterator; 39 | class ValueConstIterator; 40 | 41 | } // namespace Json 42 | 43 | #endif // JSON_FORWARDS_H_INCLUDED 44 | -------------------------------------------------------------------------------- /dep/jsonlib/json.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_JSON_H_INCLUDED 7 | #define JSON_JSON_H_INCLUDED 8 | 9 | #include "config.h" 10 | #include "json_features.h" 11 | #include "reader.h" 12 | #include "value.h" 13 | #include "writer.h" 14 | #include "parser.h" 15 | 16 | 17 | #endif // JSON_JSON_H_INCLUDED 18 | -------------------------------------------------------------------------------- /dep/jsonlib/json_features.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_FEATURES_H_INCLUDED 7 | #define JSON_FEATURES_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | #include "forwards.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | 13 | #pragma pack(push) 14 | #pragma pack() 15 | 16 | namespace Json { 17 | 18 | /** \brief Configuration passed to reader and writer. 19 | * This configuration object can be used to force the Reader or Writer 20 | * to behave in a standard conforming way. 21 | */ 22 | class JSON_API Features { 23 | public: 24 | /** \brief A configuration that allows all features and assumes all strings 25 | * are UTF-8. 26 | * - C & C++ comments are allowed 27 | * - Root object can be any JSON value 28 | * - Assumes Value strings are encoded in UTF-8 29 | */ 30 | static Features all(); 31 | 32 | /** \brief A configuration that is strictly compatible with the JSON 33 | * specification. 34 | * - Comments are forbidden. 35 | * - Root object must be either an array or an object value. 36 | * - Assumes Value strings are encoded in UTF-8 37 | */ 38 | static Features strictMode(); 39 | 40 | /** \brief Initialize the configuration like JsonConfig::allFeatures; 41 | */ 42 | Features(); 43 | 44 | /// \c true if comments are allowed. Default: \c true. 45 | bool allowComments_{true}; 46 | 47 | /// \c true if root must be either an array or an object value. Default: \c 48 | /// false. 49 | bool strictRoot_{false}; 50 | 51 | /// \c true if dropped null placeholders are allowed. Default: \c false. 52 | bool allowDroppedNullPlaceholders_{false}; 53 | 54 | /// \c true if numeric object key are allowed. Default: \c false. 55 | bool allowNumericKeys_{false}; 56 | }; 57 | 58 | } // namespace Json 59 | 60 | #pragma pack(pop) 61 | 62 | #endif // JSON_FEATURES_H_INCLUDED 63 | -------------------------------------------------------------------------------- /dep/jsonlib/parser.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by geektcp on 11/14/23. 3 | // 4 | 5 | #include "parser.h" 6 | 7 | #include 8 | 9 | Json::Value parser::parseString(std::string rawJson) 10 | { 11 | const auto rawJsonLength = static_cast(rawJson.length()); 12 | JSONCPP_STRING err; 13 | Json::Value root; 14 | 15 | Json::CharReaderBuilder builder; 16 | const std::unique_ptr reader(builder.newCharReader()); 17 | if (!reader->parse( 18 | rawJson.c_str(), 19 | rawJson.c_str() + rawJsonLength, 20 | &root, 21 | &err)) 22 | { 23 | printf("parse json failed: %s", rawJson); 24 | } 25 | 26 | return root; 27 | } -------------------------------------------------------------------------------- /dep/jsonlib/parser.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by geektcp on 11/14/23. 3 | // 4 | 5 | #ifndef EXECUTOR_PASER_H 6 | #define EXECUTOR_PASER_H 7 | 8 | #include "json.h" 9 | 10 | class parser { 11 | public: 12 | static Json::Value parseString(std::string str); 13 | 14 | }; 15 | 16 | 17 | #endif //EXECUTOR_PASER_H 18 | -------------------------------------------------------------------------------- /dep/jsonlib/version.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_VERSION_H_INCLUDED 2 | #define JSON_VERSION_H_INCLUDED 3 | 4 | // Note: version must be updated in three places when doing a release. This 5 | // annoying process ensures that amalgamate, CMake, and meson all report the 6 | // correct version. 7 | // 1. /meson.build 8 | // 2. /include/json/version.h 9 | // 3. /CMakeLists.txt 10 | // IMPORTANT: also update the SOVERSION!! 11 | 12 | #define JSONCPP_VERSION_STRING "1.9.5" 13 | #define JSONCPP_VERSION_MAJOR 1 14 | #define JSONCPP_VERSION_MINOR 9 15 | #define JSONCPP_VERSION_PATCH 5 16 | #define JSONCPP_VERSION_QUALIFIER 17 | #define JSONCPP_VERSION_HEXA \ 18 | ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \ 19 | (JSONCPP_VERSION_PATCH << 8)) 20 | 21 | #ifdef JSONCPP_USING_SECURE_MEMORY 22 | #undef JSONCPP_USING_SECURE_MEMORY 23 | #endif 24 | #define JSONCPP_USING_SECURE_MEMORY 0 25 | // If non-zero, the library zeroes any memory that it has allocated before 26 | // it frees its memory. 27 | 28 | #endif // JSON_VERSION_H_INCLUDED 29 | -------------------------------------------------------------------------------- /dep/log/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message("CMakeLists.txt load spd_log ...") 2 | 3 | SET(LIBRARY_NAME spd_log) 4 | 5 | #SPDLOG_COMPILED_LIB 6 | 7 | file(GLOB_RECURSE sources *.cpp *.c *.h) 8 | 9 | add_library(${LIBRARY_NAME} 10 | ${sources} 11 | ) 12 | 13 | target_include_directories(${LIBRARY_NAME} 14 | PUBLIC 15 | ${PROJECT_SOURCE_DIR}/dep/log 16 | ) 17 | 18 | # must 19 | find_package(Threads REQUIRED) 20 | 21 | # must 22 | target_link_libraries( 23 | ${LIBRARY_NAME} 24 | PUBLIC Threads::Threads 25 | ) 26 | 27 | # must exist, if not ,then report : 28 | # #error Please define SPDLOG_COMPILED_LIB to compile this file. 29 | # it is same with cpp or head file : #define SPDLOG_COMPILED_LIB 30 | add_definitions(-DSPDLOG_COMPILED_LIB) 31 | 32 | install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) -------------------------------------------------------------------------------- /dep/log/spdlog/async.cpp: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef SPDLOG_COMPILED_LIB 5 | #error Please define SPDLOG_COMPILED_LIB to compile this file. 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | -------------------------------------------------------------------------------- /dep/log/spdlog/async_logger-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | SPDLOG_INLINE spdlog::async_logger::async_logger(std::string logger_name, 17 | sinks_init_list sinks_list, 18 | std::weak_ptr tp, 19 | async_overflow_policy overflow_policy) 20 | : async_logger(std::move(logger_name), 21 | sinks_list.begin(), 22 | sinks_list.end(), 23 | std::move(tp), 24 | overflow_policy) {} 25 | 26 | SPDLOG_INLINE spdlog::async_logger::async_logger(std::string logger_name, 27 | sink_ptr single_sink, 28 | std::weak_ptr tp, 29 | async_overflow_policy overflow_policy) 30 | : async_logger( 31 | std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy) {} 32 | 33 | // send the log message to the thread pool 34 | SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg){ 35 | SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){ 36 | pool_ptr->post_log(shared_from_this(), msg, overflow_policy_); 37 | } 38 | else { 39 | throw_spdlog_ex("async log: thread pool doesn't exist anymore"); 40 | } 41 | } 42 | SPDLOG_LOGGER_CATCH(msg.source) 43 | } 44 | 45 | // send flush request to the thread pool 46 | SPDLOG_INLINE void spdlog::async_logger::flush_(){ 47 | SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){ 48 | pool_ptr->post_flush(shared_from_this(), overflow_policy_); 49 | } 50 | else { 51 | throw_spdlog_ex("async flush: thread pool doesn't exist anymore"); 52 | } 53 | } 54 | SPDLOG_LOGGER_CATCH(source_loc()) 55 | } 56 | 57 | // 58 | // backend functions - called from the thread pool to do the actual job 59 | // 60 | SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg) { 61 | for (auto &sink : sinks_) { 62 | if (sink->should_log(msg.level)) { 63 | SPDLOG_TRY { sink->log(msg); } 64 | SPDLOG_LOGGER_CATCH(msg.source) 65 | } 66 | } 67 | 68 | if (should_flush_(msg)) { 69 | backend_flush_(); 70 | } 71 | } 72 | 73 | SPDLOG_INLINE void spdlog::async_logger::backend_flush_() { 74 | for (auto &sink : sinks_) { 75 | SPDLOG_TRY { sink->flush(); } 76 | SPDLOG_LOGGER_CATCH(source_loc()) 77 | } 78 | } 79 | 80 | SPDLOG_INLINE std::shared_ptr spdlog::async_logger::clone(std::string new_name) { 81 | auto cloned = std::make_shared(*this); 82 | cloned->name_ = std::move(new_name); 83 | return cloned; 84 | } 85 | -------------------------------------------------------------------------------- /dep/log/spdlog/async_logger.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // Fast asynchronous logger. 7 | // Uses pre allocated queue. 8 | // Creates a single back thread to pop messages from the queue and log them. 9 | // 10 | // Upon each log write the logger: 11 | // 1. Checks if its log level is enough to log the message 12 | // 2. Push a new copy of the message to a queue (or block the caller until 13 | // space is available in the queue) 14 | // Upon destruction, logs all remaining messages in the queue before 15 | // destructing.. 16 | 17 | #include 18 | 19 | namespace spdlog { 20 | 21 | // Async overflow policy - block by default. 22 | enum class async_overflow_policy { 23 | block, // Block until message can be enqueued 24 | overrun_oldest, // Discard oldest message in the queue if full when trying to 25 | // add new item. 26 | discard_new // Discard new message if the queue is full when trying to add new item. 27 | }; 28 | 29 | namespace details { 30 | class thread_pool; 31 | } 32 | 33 | class SPDLOG_API async_logger final : public std::enable_shared_from_this, 34 | public logger { 35 | friend class details::thread_pool; 36 | 37 | public: 38 | template 39 | async_logger(std::string logger_name, 40 | It begin, 41 | It end, 42 | std::weak_ptr tp, 43 | async_overflow_policy overflow_policy = async_overflow_policy::block) 44 | : logger(std::move(logger_name), begin, end), 45 | thread_pool_(std::move(tp)), 46 | overflow_policy_(overflow_policy) {} 47 | 48 | async_logger(std::string logger_name, 49 | sinks_init_list sinks_list, 50 | std::weak_ptr tp, 51 | async_overflow_policy overflow_policy = async_overflow_policy::block); 52 | 53 | async_logger(std::string logger_name, 54 | sink_ptr single_sink, 55 | std::weak_ptr tp, 56 | async_overflow_policy overflow_policy = async_overflow_policy::block); 57 | 58 | std::shared_ptr clone(std::string new_name) override; 59 | 60 | protected: 61 | void sink_it_(const details::log_msg &msg) override; 62 | void flush_() override; 63 | void backend_sink_it_(const details::log_msg &incoming_log_msg); 64 | void backend_flush_(); 65 | 66 | private: 67 | std::weak_ptr thread_pool_; 68 | async_overflow_policy overflow_policy_; 69 | }; 70 | } // namespace spdlog 71 | 72 | #ifdef SPDLOG_HEADER_ONLY 73 | #include "async_logger-inl.h" 74 | #endif 75 | -------------------------------------------------------------------------------- /dep/log/spdlog/bundled_fmtlib_format.cpp: -------------------------------------------------------------------------------- 1 | // Slightly modified version of fmt lib's format.cc (version 1.9.1) source file. 2 | // Copyright (c) 2012 - 2016, Victor Zverovich 3 | // All rights reserved. 4 | 5 | #ifndef SPDLOG_COMPILED_LIB 6 | #error Please define SPDLOG_COMPILED_LIB to compile this file. 7 | #endif 8 | 9 | #if !defined(SPDLOG_FMT_EXTERNAL) && !defined(SPDLOG_USE_STD_FORMAT) 10 | 11 | #include 12 | 13 | FMT_BEGIN_NAMESPACE 14 | namespace detail { 15 | 16 | template FMT_API auto dragonbox::to_decimal(float x) noexcept -> dragonbox::decimal_fp; 17 | template FMT_API auto dragonbox::to_decimal(double x) noexcept -> dragonbox::decimal_fp; 18 | 19 | #ifndef FMT_STATIC_THOUSANDS_SEPARATOR 20 | template FMT_API locale_ref::locale_ref(const std::locale &loc); 21 | template FMT_API auto locale_ref::get() const -> std::locale; 22 | #endif 23 | 24 | // Explicit instantiations for char. 25 | 26 | template FMT_API auto thousands_sep_impl(locale_ref) -> thousands_sep_result; 27 | template FMT_API auto decimal_point_impl(locale_ref) -> char; 28 | 29 | template FMT_API void buffer::append(const char *, const char *); 30 | 31 | // DEPRECATED! 32 | // There is no correspondent extern template in format.h because of 33 | // incompatibility between clang and gcc (#2377). 34 | template FMT_API void vformat_to(buffer &, 35 | string_view, 36 | basic_format_args, 37 | locale_ref); 38 | 39 | // Explicit instantiations for wchar_t. 40 | 41 | template FMT_API auto thousands_sep_impl(locale_ref) -> thousands_sep_result; 42 | template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t; 43 | 44 | template FMT_API void buffer::append(const wchar_t *, const wchar_t *); 45 | 46 | } // namespace detail 47 | FMT_END_NAMESPACE 48 | 49 | #endif // !SPDLOG_FMT_EXTERNAL 50 | -------------------------------------------------------------------------------- /dep/log/spdlog/cfg.cpp: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef SPDLOG_COMPILED_LIB 5 | #error Please define SPDLOG_COMPILED_LIB to compile this file. 6 | #endif 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /dep/log/spdlog/cfg/argv.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | #include 6 | #include 7 | 8 | // 9 | // Init log levels using each argv entry that starts with "SPDLOG_LEVEL=" 10 | // 11 | // set all loggers to debug level: 12 | // example.exe "SPDLOG_LEVEL=debug" 13 | 14 | // set logger1 to trace level 15 | // example.exe "SPDLOG_LEVEL=logger1=trace" 16 | 17 | // turn off all logging except for logger1 and logger2: 18 | // example.exe "SPDLOG_LEVEL=off,logger1=debug,logger2=info" 19 | 20 | namespace spdlog { 21 | namespace cfg { 22 | 23 | // search for SPDLOG_LEVEL= in the args and use it to init the levels 24 | inline void load_argv_levels(int argc, const char **argv) { 25 | const std::string spdlog_level_prefix = "SPDLOG_LEVEL="; 26 | for (int i = 1; i < argc; i++) { 27 | std::string arg = argv[i]; 28 | if (arg.find(spdlog_level_prefix) == 0) { 29 | auto levels_string = arg.substr(spdlog_level_prefix.size()); 30 | helpers::load_levels(levels_string); 31 | } 32 | } 33 | } 34 | 35 | inline void load_argv_levels(int argc, char **argv) { 36 | load_argv_levels(argc, const_cast(argv)); 37 | } 38 | 39 | } // namespace cfg 40 | } // namespace spdlog 41 | -------------------------------------------------------------------------------- /dep/log/spdlog/cfg/env.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | #include 6 | #include 7 | #include 8 | 9 | // 10 | // Init levels and patterns from env variables SPDLOG_LEVEL 11 | // Inspired from Rust's "env_logger" crate (https://crates.io/crates/env_logger). 12 | // Note - fallback to "info" level on unrecognized levels 13 | // 14 | // Examples: 15 | // 16 | // set global level to debug: 17 | // export SPDLOG_LEVEL=debug 18 | // 19 | // turn off all logging except for logger1: 20 | // export SPDLOG_LEVEL="*=off,logger1=debug" 21 | // 22 | 23 | // turn off all logging except for logger1 and logger2: 24 | // export SPDLOG_LEVEL="off,logger1=debug,logger2=info" 25 | 26 | namespace spdlog { 27 | namespace cfg { 28 | inline void load_env_levels() { 29 | auto env_val = details::os::getenv("SPDLOG_LEVEL"); 30 | if (!env_val.empty()) { 31 | helpers::load_levels(env_val); 32 | } 33 | } 34 | 35 | } // namespace cfg 36 | } // namespace spdlog 37 | -------------------------------------------------------------------------------- /dep/log/spdlog/cfg/helpers-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace spdlog { 20 | namespace cfg { 21 | namespace helpers { 22 | 23 | // inplace convert to lowercase 24 | inline std::string &to_lower_(std::string &str) { 25 | std::transform(str.begin(), str.end(), str.begin(), [](char ch) { 26 | return static_cast((ch >= 'A' && ch <= 'Z') ? ch + ('a' - 'A') : ch); 27 | }); 28 | return str; 29 | } 30 | 31 | // inplace trim spaces 32 | inline std::string &trim_(std::string &str) { 33 | const char *spaces = " \n\r\t"; 34 | str.erase(str.find_last_not_of(spaces) + 1); 35 | str.erase(0, str.find_first_not_of(spaces)); 36 | return str; 37 | } 38 | 39 | // return (name,value) trimmed pair from given "name=value" string. 40 | // return empty string on missing parts 41 | // "key=val" => ("key", "val") 42 | // " key = val " => ("key", "val") 43 | // "key=" => ("key", "") 44 | // "val" => ("", "val") 45 | 46 | inline std::pair extract_kv_(char sep, const std::string &str) { 47 | auto n = str.find(sep); 48 | std::string k, v; 49 | if (n == std::string::npos) { 50 | v = str; 51 | } else { 52 | k = str.substr(0, n); 53 | v = str.substr(n + 1); 54 | } 55 | return std::make_pair(trim_(k), trim_(v)); 56 | } 57 | 58 | // return vector of key/value pairs from sequence of "K1=V1,K2=V2,.." 59 | // "a=AAA,b=BBB,c=CCC,.." => {("a","AAA"),("b","BBB"),("c", "CCC"),...} 60 | inline std::unordered_map extract_key_vals_(const std::string &str) { 61 | std::string token; 62 | std::istringstream token_stream(str); 63 | std::unordered_map rv{}; 64 | while (std::getline(token_stream, token, ',')) { 65 | if (token.empty()) { 66 | continue; 67 | } 68 | auto kv = extract_kv_('=', token); 69 | rv[kv.first] = kv.second; 70 | } 71 | return rv; 72 | } 73 | 74 | SPDLOG_INLINE void load_levels(const std::string &input) { 75 | if (input.empty() || input.size() > 512) { 76 | return; 77 | } 78 | 79 | auto key_vals = extract_key_vals_(input); 80 | std::unordered_map levels; 81 | level::level_enum global_level = level::info; 82 | bool global_level_found = false; 83 | 84 | for (auto &name_level : key_vals) { 85 | auto &logger_name = name_level.first; 86 | auto level_name = to_lower_(name_level.second); 87 | auto level = level::from_str(level_name); 88 | // ignore unrecognized level names 89 | if (level == level::off && level_name != "off") { 90 | continue; 91 | } 92 | if (logger_name.empty()) // no logger name indicate global level 93 | { 94 | global_level_found = true; 95 | global_level = level; 96 | } else { 97 | levels[logger_name] = level; 98 | } 99 | } 100 | 101 | details::registry::instance().set_levels(std::move(levels), 102 | global_level_found ? &global_level : nullptr); 103 | } 104 | 105 | } // namespace helpers 106 | } // namespace cfg 107 | } // namespace spdlog 108 | -------------------------------------------------------------------------------- /dep/log/spdlog/cfg/helpers.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace cfg { 11 | namespace helpers { 12 | // 13 | // Init levels from given string 14 | // 15 | // Examples: 16 | // 17 | // set global level to debug: "debug" 18 | // turn off all logging except for logger1: "off,logger1=debug" 19 | // turn off all logging except for logger1 and logger2: "off,logger1=debug,logger2=info" 20 | // 21 | SPDLOG_API void load_levels(const std::string &txt); 22 | } // namespace helpers 23 | 24 | } // namespace cfg 25 | } // namespace spdlog 26 | 27 | #ifdef SPDLOG_HEADER_ONLY 28 | #include "helpers-inl.h" 29 | #endif // SPDLOG_HEADER_ONLY 30 | -------------------------------------------------------------------------------- /dep/log/spdlog/color_sinks.cpp: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef SPDLOG_COMPILED_LIB 5 | #error Please define SPDLOG_COMPILED_LIB to compile this file. 6 | #endif 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | // 13 | // color sinks 14 | // 15 | #ifdef _WIN32 16 | #include 17 | template class SPDLOG_API spdlog::sinks::wincolor_sink; 18 | template class SPDLOG_API spdlog::sinks::wincolor_sink; 19 | template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink; 20 | template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink; 21 | template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink; 22 | template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink; 23 | #else 24 | #include "spdlog/sinks/ansicolor_sink-inl.h" 25 | template class SPDLOG_API spdlog::sinks::ansicolor_sink; 26 | template class SPDLOG_API spdlog::sinks::ansicolor_sink; 27 | template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink; 28 | template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink; 29 | template class SPDLOG_API spdlog::sinks::ansicolor_stderr_sink; 30 | template class SPDLOG_API spdlog::sinks::ansicolor_stderr_sink; 31 | #endif 32 | 33 | // factory methods for color loggers 34 | #include "spdlog/sinks/stdout_color_sinks-inl.h" 35 | template SPDLOG_API std::shared_ptr 36 | spdlog::stdout_color_mt(const std::string &logger_name, 37 | color_mode mode); 38 | template SPDLOG_API std::shared_ptr 39 | spdlog::stdout_color_st(const std::string &logger_name, 40 | color_mode mode); 41 | template SPDLOG_API std::shared_ptr 42 | spdlog::stderr_color_mt(const std::string &logger_name, 43 | color_mode mode); 44 | template SPDLOG_API std::shared_ptr 45 | spdlog::stderr_color_st(const std::string &logger_name, 46 | color_mode mode); 47 | 48 | template SPDLOG_API std::shared_ptr spdlog::stdout_color_mt( 49 | const std::string &logger_name, color_mode mode); 50 | template SPDLOG_API std::shared_ptr spdlog::stdout_color_st( 51 | const std::string &logger_name, color_mode mode); 52 | template SPDLOG_API std::shared_ptr spdlog::stderr_color_mt( 53 | const std::string &logger_name, color_mode mode); 54 | template SPDLOG_API std::shared_ptr spdlog::stderr_color_st( 55 | const std::string &logger_name, color_mode mode); 56 | -------------------------------------------------------------------------------- /dep/log/spdlog/common-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | namespace level { 15 | 16 | #if __cplusplus >= 201703L 17 | constexpr 18 | #endif 19 | static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; 20 | 21 | static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; 22 | 23 | SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT { 24 | return level_string_views[l]; 25 | } 26 | 27 | SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT { 28 | return short_level_names[l]; 29 | } 30 | 31 | SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT { 32 | auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name); 33 | if (it != std::end(level_string_views)) 34 | return static_cast(std::distance(std::begin(level_string_views), it)); 35 | 36 | // check also for "warn" and "err" before giving up.. 37 | if (name == "warn") { 38 | return level::warn; 39 | } 40 | if (name == "err") { 41 | return level::err; 42 | } 43 | return level::off; 44 | } 45 | } // namespace level 46 | 47 | SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg) 48 | : msg_(std::move(msg)) {} 49 | 50 | SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) { 51 | #ifdef SPDLOG_USE_STD_FORMAT 52 | msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what(); 53 | #else 54 | memory_buf_t outbuf; 55 | fmt::format_system_error(outbuf, last_errno, msg.c_str()); 56 | msg_ = fmt::to_string(outbuf); 57 | #endif 58 | } 59 | 60 | SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT { return msg_.c_str(); } 61 | 62 | SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno) { 63 | SPDLOG_THROW(spdlog_ex(msg, last_errno)); 64 | } 65 | 66 | SPDLOG_INLINE void throw_spdlog_ex(std::string msg) { SPDLOG_THROW(spdlog_ex(std::move(msg))); } 67 | 68 | } // namespace spdlog 69 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/backtracer-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | namespace spdlog { 10 | namespace details { 11 | SPDLOG_INLINE backtracer::backtracer(const backtracer &other) { 12 | std::lock_guard lock(other.mutex_); 13 | enabled_ = other.enabled(); 14 | messages_ = other.messages_; 15 | } 16 | 17 | SPDLOG_INLINE backtracer::backtracer(backtracer &&other) SPDLOG_NOEXCEPT { 18 | std::lock_guard lock(other.mutex_); 19 | enabled_ = other.enabled(); 20 | messages_ = std::move(other.messages_); 21 | } 22 | 23 | SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other) { 24 | std::lock_guard lock(mutex_); 25 | enabled_ = other.enabled(); 26 | messages_ = std::move(other.messages_); 27 | return *this; 28 | } 29 | 30 | SPDLOG_INLINE void backtracer::enable(size_t size) { 31 | std::lock_guard lock{mutex_}; 32 | enabled_.store(true, std::memory_order_relaxed); 33 | messages_ = circular_q{size}; 34 | } 35 | 36 | SPDLOG_INLINE void backtracer::disable() { 37 | std::lock_guard lock{mutex_}; 38 | enabled_.store(false, std::memory_order_relaxed); 39 | } 40 | 41 | SPDLOG_INLINE bool backtracer::enabled() const { return enabled_.load(std::memory_order_relaxed); } 42 | 43 | SPDLOG_INLINE void backtracer::push_back(const log_msg &msg) { 44 | std::lock_guard lock{mutex_}; 45 | messages_.push_back(log_msg_buffer{msg}); 46 | } 47 | 48 | SPDLOG_INLINE bool backtracer::empty() const { 49 | std::lock_guard lock{mutex_}; 50 | return messages_.empty(); 51 | } 52 | 53 | // pop all items in the q and apply the given fun on each of them. 54 | SPDLOG_INLINE void backtracer::foreach_pop(std::function fun) { 55 | std::lock_guard lock{mutex_}; 56 | while (!messages_.empty()) { 57 | auto &front_msg = messages_.front(); 58 | fun(front_msg); 59 | messages_.pop_front(); 60 | } 61 | } 62 | } // namespace details 63 | } // namespace spdlog 64 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/backtracer.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | // Store log messages in circular buffer. 14 | // Useful for storing debug data in case of error/warning happens. 15 | 16 | namespace spdlog { 17 | namespace details { 18 | class SPDLOG_API backtracer { 19 | mutable std::mutex mutex_; 20 | std::atomic enabled_{false}; 21 | circular_q messages_; 22 | 23 | public: 24 | backtracer() = default; 25 | backtracer(const backtracer &other); 26 | 27 | backtracer(backtracer &&other) SPDLOG_NOEXCEPT; 28 | backtracer &operator=(backtracer other); 29 | 30 | void enable(size_t size); 31 | void disable(); 32 | bool enabled() const; 33 | void push_back(const log_msg &msg); 34 | bool empty() const; 35 | 36 | // pop all items in the q and apply the given fun on each of them. 37 | void foreach_pop(std::function fun); 38 | }; 39 | 40 | } // namespace details 41 | } // namespace spdlog 42 | 43 | #ifdef SPDLOG_HEADER_ONLY 44 | #include "backtracer-inl.h" 45 | #endif 46 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/circular_q.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | // circular q view of std::vector. 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | namespace spdlog { 11 | namespace details { 12 | template 13 | class circular_q { 14 | size_t max_items_ = 0; 15 | typename std::vector::size_type head_ = 0; 16 | typename std::vector::size_type tail_ = 0; 17 | size_t overrun_counter_ = 0; 18 | std::vector v_; 19 | 20 | public: 21 | using value_type = T; 22 | 23 | // empty ctor - create a disabled queue with no elements allocated at all 24 | circular_q() = default; 25 | 26 | explicit circular_q(size_t max_items) 27 | : max_items_(max_items + 1) // one item is reserved as marker for full q 28 | , 29 | v_(max_items_) {} 30 | 31 | circular_q(const circular_q &) = default; 32 | circular_q &operator=(const circular_q &) = default; 33 | 34 | // move cannot be default, 35 | // since we need to reset head_, tail_, etc to zero in the moved object 36 | circular_q(circular_q &&other) SPDLOG_NOEXCEPT { copy_moveable(std::move(other)); } 37 | 38 | circular_q &operator=(circular_q &&other) SPDLOG_NOEXCEPT { 39 | copy_moveable(std::move(other)); 40 | return *this; 41 | } 42 | 43 | // push back, overrun (oldest) item if no room left 44 | void push_back(T &&item) { 45 | if (max_items_ > 0) { 46 | v_[tail_] = std::move(item); 47 | tail_ = (tail_ + 1) % max_items_; 48 | 49 | if (tail_ == head_) // overrun last item if full 50 | { 51 | head_ = (head_ + 1) % max_items_; 52 | ++overrun_counter_; 53 | } 54 | } 55 | } 56 | 57 | // Return reference to the front item. 58 | // If there are no elements in the container, the behavior is undefined. 59 | const T &front() const { return v_[head_]; } 60 | 61 | T &front() { return v_[head_]; } 62 | 63 | // Return number of elements actually stored 64 | size_t size() const { 65 | if (tail_ >= head_) { 66 | return tail_ - head_; 67 | } else { 68 | return max_items_ - (head_ - tail_); 69 | } 70 | } 71 | 72 | // Return const reference to item by index. 73 | // If index is out of range 0…size()-1, the behavior is undefined. 74 | const T &at(size_t i) const { 75 | assert(i < size()); 76 | return v_[(head_ + i) % max_items_]; 77 | } 78 | 79 | // Pop item from front. 80 | // If there are no elements in the container, the behavior is undefined. 81 | void pop_front() { head_ = (head_ + 1) % max_items_; } 82 | 83 | bool empty() const { return tail_ == head_; } 84 | 85 | bool full() const { 86 | // head is ahead of the tail by 1 87 | if (max_items_ > 0) { 88 | return ((tail_ + 1) % max_items_) == head_; 89 | } 90 | return false; 91 | } 92 | 93 | size_t overrun_counter() const { return overrun_counter_; } 94 | 95 | void reset_overrun_counter() { overrun_counter_ = 0; } 96 | 97 | private: 98 | // copy from other&& and reset it to disabled state 99 | void copy_moveable(circular_q &&other) SPDLOG_NOEXCEPT { 100 | max_items_ = other.max_items_; 101 | head_ = other.head_; 102 | tail_ = other.tail_; 103 | overrun_counter_ = other.overrun_counter_; 104 | v_ = std::move(other.v_); 105 | 106 | // put &&other in disabled, but valid state 107 | other.max_items_ = 0; 108 | other.head_ = other.tail_ = 0; 109 | other.overrun_counter_ = 0; 110 | } 111 | }; 112 | } // namespace details 113 | } // namespace spdlog 114 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/console_globals.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | 12 | struct console_mutex { 13 | using mutex_t = std::mutex; 14 | static mutex_t &mutex() { 15 | static mutex_t s_mutex; 16 | return s_mutex; 17 | } 18 | }; 19 | 20 | struct console_nullmutex { 21 | using mutex_t = null_mutex; 22 | static mutex_t &mutex() { 23 | static mutex_t s_mutex; 24 | return s_mutex; 25 | } 26 | }; 27 | } // namespace details 28 | } // namespace spdlog 29 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/file_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | 12 | // Helper class for file sinks. 13 | // When failing to open a file, retry several times(5) with a delay interval(10 ms). 14 | // Throw spdlog_ex exception on errors. 15 | 16 | class SPDLOG_API file_helper { 17 | public: 18 | file_helper() = default; 19 | explicit file_helper(const file_event_handlers &event_handlers); 20 | 21 | file_helper(const file_helper &) = delete; 22 | file_helper &operator=(const file_helper &) = delete; 23 | ~file_helper(); 24 | 25 | void open(const filename_t &fname, bool truncate = false); 26 | void reopen(bool truncate); 27 | void flush(); 28 | void sync(); 29 | void close(); 30 | void write(const memory_buf_t &buf); 31 | size_t size() const; 32 | const filename_t &filename() const; 33 | 34 | // 35 | // return file path and its extension: 36 | // 37 | // "mylog.txt" => ("mylog", ".txt") 38 | // "mylog" => ("mylog", "") 39 | // "mylog." => ("mylog.", "") 40 | // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") 41 | // 42 | // the starting dot in filenames is ignored (hidden files): 43 | // 44 | // ".mylog" => (".mylog". "") 45 | // "my_folder/.mylog" => ("my_folder/.mylog", "") 46 | // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") 47 | static std::tuple split_by_extension(const filename_t &fname); 48 | 49 | private: 50 | const int open_tries_ = 5; 51 | const unsigned int open_interval_ = 10; 52 | std::FILE *fd_{nullptr}; 53 | filename_t filename_; 54 | file_event_handlers event_handlers_; 55 | }; 56 | } // namespace details 57 | } // namespace spdlog 58 | 59 | #ifdef SPDLOG_HEADER_ONLY 60 | #include "file_helper-inl.h" 61 | #endif 62 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/log_msg-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | 12 | namespace spdlog { 13 | namespace details { 14 | 15 | SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, 16 | spdlog::source_loc loc, 17 | string_view_t a_logger_name, 18 | spdlog::level::level_enum lvl, 19 | spdlog::string_view_t msg) 20 | : logger_name(a_logger_name), 21 | level(lvl), 22 | time(log_time) 23 | #ifndef SPDLOG_NO_THREAD_ID 24 | , 25 | thread_id(os::thread_id()) 26 | #endif 27 | , 28 | source(loc), 29 | payload(msg) { 30 | } 31 | 32 | SPDLOG_INLINE log_msg::log_msg(spdlog::source_loc loc, 33 | string_view_t a_logger_name, 34 | spdlog::level::level_enum lvl, 35 | spdlog::string_view_t msg) 36 | : log_msg(os::now(), loc, a_logger_name, lvl, msg) {} 37 | 38 | SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, 39 | spdlog::level::level_enum lvl, 40 | spdlog::string_view_t msg) 41 | : log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg) {} 42 | 43 | } // namespace details 44 | } // namespace spdlog 45 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/log_msg.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | struct SPDLOG_API log_msg { 12 | log_msg() = default; 13 | log_msg(log_clock::time_point log_time, 14 | source_loc loc, 15 | string_view_t logger_name, 16 | level::level_enum lvl, 17 | string_view_t msg); 18 | log_msg(source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); 19 | log_msg(string_view_t logger_name, level::level_enum lvl, string_view_t msg); 20 | log_msg(const log_msg &other) = default; 21 | log_msg &operator=(const log_msg &other) = default; 22 | 23 | string_view_t logger_name; 24 | level::level_enum level{level::off}; 25 | log_clock::time_point time; 26 | size_t thread_id{0}; 27 | 28 | // wrapping the formatted text with color (updated by pattern_formatter). 29 | mutable size_t color_range_start{0}; 30 | mutable size_t color_range_end{0}; 31 | 32 | source_loc source; 33 | string_view_t payload; 34 | }; 35 | } // namespace details 36 | } // namespace spdlog 37 | 38 | #ifdef SPDLOG_HEADER_ONLY 39 | #include "log_msg-inl.h" 40 | #endif 41 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/log_msg_buffer-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | namespace spdlog { 11 | namespace details { 12 | 13 | SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg &orig_msg) 14 | : log_msg{orig_msg} { 15 | buffer.append(logger_name.begin(), logger_name.end()); 16 | buffer.append(payload.begin(), payload.end()); 17 | update_string_views(); 18 | } 19 | 20 | SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other) 21 | : log_msg{other} { 22 | buffer.append(logger_name.begin(), logger_name.end()); 23 | buffer.append(payload.begin(), payload.end()); 24 | update_string_views(); 25 | } 26 | 27 | SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT 28 | : log_msg{other}, 29 | buffer{std::move(other.buffer)} { 30 | update_string_views(); 31 | } 32 | 33 | SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other) { 34 | log_msg::operator=(other); 35 | buffer.clear(); 36 | buffer.append(other.buffer.data(), other.buffer.data() + other.buffer.size()); 37 | update_string_views(); 38 | return *this; 39 | } 40 | 41 | SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT { 42 | log_msg::operator=(other); 43 | buffer = std::move(other.buffer); 44 | update_string_views(); 45 | return *this; 46 | } 47 | 48 | SPDLOG_INLINE void log_msg_buffer::update_string_views() { 49 | logger_name = string_view_t{buffer.data(), logger_name.size()}; 50 | payload = string_view_t{buffer.data() + logger_name.size(), payload.size()}; 51 | } 52 | 53 | } // namespace details 54 | } // namespace spdlog 55 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/log_msg_buffer.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace spdlog { 9 | namespace details { 10 | 11 | // Extend log_msg with internal buffer to store its payload. 12 | // This is needed since log_msg holds string_views that points to stack data. 13 | 14 | class SPDLOG_API log_msg_buffer : public log_msg { 15 | memory_buf_t buffer; 16 | void update_string_views(); 17 | 18 | public: 19 | log_msg_buffer() = default; 20 | explicit log_msg_buffer(const log_msg &orig_msg); 21 | log_msg_buffer(const log_msg_buffer &other); 22 | log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT; 23 | log_msg_buffer &operator=(const log_msg_buffer &other); 24 | log_msg_buffer &operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT; 25 | }; 26 | 27 | } // namespace details 28 | } // namespace spdlog 29 | 30 | #ifdef SPDLOG_HEADER_ONLY 31 | #include "log_msg_buffer-inl.h" 32 | #endif 33 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/null_mutex.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | // null, no cost dummy "mutex" and dummy "atomic" int 9 | 10 | namespace spdlog { 11 | namespace details { 12 | struct null_mutex { 13 | void lock() const {} 14 | void unlock() const {} 15 | }; 16 | 17 | struct null_atomic_int { 18 | int value; 19 | null_atomic_int() = default; 20 | 21 | explicit null_atomic_int(int new_value) 22 | : value(new_value) {} 23 | 24 | int load(std::memory_order = std::memory_order_relaxed) const { return value; } 25 | 26 | void store(int new_value, std::memory_order = std::memory_order_relaxed) { value = new_value; } 27 | 28 | int exchange(int new_value, std::memory_order = std::memory_order_relaxed) { 29 | std::swap(new_value, value); 30 | return new_value; // return value before the call 31 | } 32 | }; 33 | 34 | } // namespace details 35 | } // namespace spdlog 36 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/periodic_worker-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | namespace spdlog { 11 | namespace details { 12 | 13 | // stop the worker thread and join it 14 | SPDLOG_INLINE periodic_worker::~periodic_worker() { 15 | if (worker_thread_.joinable()) { 16 | { 17 | std::lock_guard lock(mutex_); 18 | active_ = false; 19 | } 20 | cv_.notify_one(); 21 | worker_thread_.join(); 22 | } 23 | } 24 | 25 | } // namespace details 26 | } // namespace spdlog 27 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/periodic_worker.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // periodic worker thread - periodically executes the given callback function. 7 | // 8 | // RAII over the owned thread: 9 | // creates the thread on construction. 10 | // stops and joins the thread on destruction (if the thread is executing a callback, wait for it 11 | // to finish first). 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | namespace spdlog { 19 | namespace details { 20 | 21 | class SPDLOG_API periodic_worker { 22 | public: 23 | template 24 | periodic_worker(const std::function &callback_fun, 25 | std::chrono::duration interval) { 26 | active_ = (interval > std::chrono::duration::zero()); 27 | if (!active_) { 28 | return; 29 | } 30 | 31 | worker_thread_ = std::thread([this, callback_fun, interval]() { 32 | for (;;) { 33 | std::unique_lock lock(this->mutex_); 34 | if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; })) { 35 | return; // active_ == false, so exit this thread 36 | } 37 | callback_fun(); 38 | } 39 | }); 40 | } 41 | periodic_worker(const periodic_worker &) = delete; 42 | periodic_worker &operator=(const periodic_worker &) = delete; 43 | // stop the worker thread and join it 44 | ~periodic_worker(); 45 | 46 | private: 47 | bool active_; 48 | std::thread worker_thread_; 49 | std::mutex mutex_; 50 | std::condition_variable cv_; 51 | }; 52 | } // namespace details 53 | } // namespace spdlog 54 | 55 | #ifdef SPDLOG_HEADER_ONLY 56 | #include "periodic_worker-inl.h" 57 | #endif 58 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/synchronous_factory.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "registry.h" 7 | 8 | namespace spdlog { 9 | 10 | // Default logger factory- creates synchronous loggers 11 | class logger; 12 | 13 | struct synchronous_factory { 14 | template 15 | static std::shared_ptr create(std::string logger_name, SinkArgs &&...args) { 16 | auto sink = std::make_shared(std::forward(args)...); 17 | auto new_logger = std::make_shared(std::move(logger_name), std::move(sink)); 18 | details::registry::instance().initialize_logger(new_logger); 19 | return new_logger; 20 | } 21 | }; 22 | } // namespace spdlog 23 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/thread_pool.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace spdlog { 17 | class async_logger; 18 | 19 | namespace details { 20 | 21 | using async_logger_ptr = std::shared_ptr; 22 | 23 | enum class async_msg_type { log, flush, terminate }; 24 | 25 | // Async msg to move to/from the queue 26 | // Movable only. should never be copied 27 | struct async_msg : log_msg_buffer { 28 | async_msg_type msg_type{async_msg_type::log}; 29 | async_logger_ptr worker_ptr; 30 | 31 | async_msg() = default; 32 | ~async_msg() = default; 33 | 34 | // should only be moved in or out of the queue.. 35 | async_msg(const async_msg &) = delete; 36 | 37 | // support for vs2013 move 38 | #if defined(_MSC_VER) && _MSC_VER <= 1800 39 | async_msg(async_msg &&other) 40 | : log_msg_buffer(std::move(other)), 41 | msg_type(other.msg_type), 42 | worker_ptr(std::move(other.worker_ptr)) {} 43 | 44 | async_msg &operator=(async_msg &&other) { 45 | *static_cast(this) = std::move(other); 46 | msg_type = other.msg_type; 47 | worker_ptr = std::move(other.worker_ptr); 48 | return *this; 49 | } 50 | #else // (_MSC_VER) && _MSC_VER <= 1800 51 | async_msg(async_msg &&) = default; 52 | async_msg &operator=(async_msg &&) = default; 53 | #endif 54 | 55 | // construct from log_msg with given type 56 | async_msg(async_logger_ptr &&worker, async_msg_type the_type, const details::log_msg &m) 57 | : log_msg_buffer{m}, 58 | msg_type{the_type}, 59 | worker_ptr{std::move(worker)} {} 60 | 61 | async_msg(async_logger_ptr &&worker, async_msg_type the_type) 62 | : log_msg_buffer{}, 63 | msg_type{the_type}, 64 | worker_ptr{std::move(worker)} {} 65 | 66 | explicit async_msg(async_msg_type the_type) 67 | : async_msg{nullptr, the_type} {} 68 | }; 69 | 70 | class SPDLOG_API thread_pool { 71 | public: 72 | using item_type = async_msg; 73 | using q_type = details::mpmc_blocking_queue; 74 | 75 | thread_pool(size_t q_max_items, 76 | size_t threads_n, 77 | std::function on_thread_start, 78 | std::function on_thread_stop); 79 | thread_pool(size_t q_max_items, size_t threads_n, std::function on_thread_start); 80 | thread_pool(size_t q_max_items, size_t threads_n); 81 | 82 | // message all threads to terminate gracefully and join them 83 | ~thread_pool(); 84 | 85 | thread_pool(const thread_pool &) = delete; 86 | thread_pool &operator=(thread_pool &&) = delete; 87 | 88 | void post_log(async_logger_ptr &&worker_ptr, 89 | const details::log_msg &msg, 90 | async_overflow_policy overflow_policy); 91 | void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy); 92 | size_t overrun_counter(); 93 | void reset_overrun_counter(); 94 | size_t discard_counter(); 95 | void reset_discard_counter(); 96 | size_t queue_size(); 97 | 98 | private: 99 | q_type q_; 100 | 101 | std::vector threads_; 102 | 103 | void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy); 104 | void worker_loop_(); 105 | 106 | // process next message in the queue 107 | // return true if this thread should still be active (while no terminate msg 108 | // was received) 109 | bool process_next_msg_(); 110 | }; 111 | 112 | } // namespace details 113 | } // namespace spdlog 114 | 115 | #ifdef SPDLOG_HEADER_ONLY 116 | #include "thread_pool-inl.h" 117 | #endif 118 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/udp_client-windows.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // Helper RAII over winsock udp client socket. 7 | // Will throw on construction if socket creation failed. 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #if defined(_MSC_VER) 19 | #pragma comment(lib, "Ws2_32.lib") 20 | #pragma comment(lib, "Mswsock.lib") 21 | #pragma comment(lib, "AdvApi32.lib") 22 | #endif 23 | 24 | namespace spdlog { 25 | namespace details { 26 | class udp_client { 27 | static constexpr int TX_BUFFER_SIZE = 1024 * 10; 28 | SOCKET socket_ = INVALID_SOCKET; 29 | sockaddr_in addr_ = {}; 30 | 31 | static void init_winsock_() { 32 | WSADATA wsaData; 33 | auto rv = ::WSAStartup(MAKEWORD(2, 2), &wsaData); 34 | if (rv != 0) { 35 | throw_winsock_error_("WSAStartup failed", ::WSAGetLastError()); 36 | } 37 | } 38 | 39 | static void throw_winsock_error_(const std::string &msg, int last_error) { 40 | char buf[512]; 41 | ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, 42 | last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 43 | (sizeof(buf) / sizeof(char)), NULL); 44 | 45 | throw_spdlog_ex(fmt_lib::format("udp_sink - {}: {}", msg, buf)); 46 | } 47 | 48 | void cleanup_() { 49 | if (socket_ != INVALID_SOCKET) { 50 | ::closesocket(socket_); 51 | } 52 | socket_ = INVALID_SOCKET; 53 | ::WSACleanup(); 54 | } 55 | 56 | public: 57 | udp_client(const std::string &host, uint16_t port) { 58 | init_winsock_(); 59 | 60 | addr_.sin_family = PF_INET; 61 | addr_.sin_port = htons(port); 62 | addr_.sin_addr.s_addr = INADDR_ANY; 63 | if (InetPtonA(PF_INET, host.c_str(), &addr_.sin_addr.s_addr) != 1) { 64 | int last_error = ::WSAGetLastError(); 65 | ::WSACleanup(); 66 | throw_winsock_error_("error: Invalid address!", last_error); 67 | } 68 | 69 | socket_ = ::socket(PF_INET, SOCK_DGRAM, 0); 70 | if (socket_ == INVALID_SOCKET) { 71 | int last_error = ::WSAGetLastError(); 72 | ::WSACleanup(); 73 | throw_winsock_error_("error: Create Socket failed", last_error); 74 | } 75 | 76 | int option_value = TX_BUFFER_SIZE; 77 | if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, 78 | reinterpret_cast(&option_value), sizeof(option_value)) < 0) { 79 | int last_error = ::WSAGetLastError(); 80 | cleanup_(); 81 | throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error); 82 | } 83 | } 84 | 85 | ~udp_client() { cleanup_(); } 86 | 87 | SOCKET fd() const { return socket_; } 88 | 89 | void send(const char *data, size_t n_bytes) { 90 | socklen_t tolen = sizeof(struct sockaddr); 91 | if (::sendto(socket_, data, static_cast(n_bytes), 0, (struct sockaddr *)&addr_, 92 | tolen) == -1) { 93 | throw_spdlog_ex("sendto(2) failed", errno); 94 | } 95 | } 96 | }; 97 | } // namespace details 98 | } // namespace spdlog 99 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/udp_client.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // Helper RAII over unix udp client socket. 7 | // Will throw on construction if the socket creation failed. 8 | 9 | #ifdef _WIN32 10 | #error "include udp_client-windows.h instead" 11 | #endif 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | namespace spdlog { 26 | namespace details { 27 | 28 | class udp_client { 29 | static constexpr int TX_BUFFER_SIZE = 1024 * 10; 30 | int socket_ = -1; 31 | struct sockaddr_in sockAddr_; 32 | 33 | void cleanup_() { 34 | if (socket_ != -1) { 35 | ::close(socket_); 36 | socket_ = -1; 37 | } 38 | } 39 | 40 | public: 41 | udp_client(const std::string &host, uint16_t port) { 42 | socket_ = ::socket(PF_INET, SOCK_DGRAM, 0); 43 | if (socket_ < 0) { 44 | throw_spdlog_ex("error: Create Socket Failed!"); 45 | } 46 | 47 | int option_value = TX_BUFFER_SIZE; 48 | if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, 49 | reinterpret_cast(&option_value), sizeof(option_value)) < 0) { 50 | cleanup_(); 51 | throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!"); 52 | } 53 | 54 | sockAddr_.sin_family = AF_INET; 55 | sockAddr_.sin_port = htons(port); 56 | 57 | if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0) { 58 | cleanup_(); 59 | throw_spdlog_ex("error: Invalid address!"); 60 | } 61 | 62 | ::memset(sockAddr_.sin_zero, 0x00, sizeof(sockAddr_.sin_zero)); 63 | } 64 | 65 | ~udp_client() { cleanup_(); } 66 | 67 | int fd() const { return socket_; } 68 | 69 | // Send exactly n_bytes of the given data. 70 | // On error close the connection and throw. 71 | void send(const char *data, size_t n_bytes) { 72 | ssize_t toslen = 0; 73 | socklen_t tolen = sizeof(struct sockaddr); 74 | if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == 75 | -1) { 76 | throw_spdlog_ex("sendto(2) failed", errno); 77 | } 78 | } 79 | }; 80 | } // namespace details 81 | } // namespace spdlog 82 | -------------------------------------------------------------------------------- /dep/log/spdlog/details/windows_include.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef NOMINMAX 4 | #define NOMINMAX // prevent windows redefining min/max 5 | #endif 6 | 7 | #ifndef WIN32_LEAN_AND_MEAN 8 | #define WIN32_LEAN_AND_MEAN 9 | #endif 10 | 11 | #include 12 | -------------------------------------------------------------------------------- /dep/log/spdlog/file_sinks.cpp: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef SPDLOG_COMPILED_LIB 5 | #error Please define SPDLOG_COMPILED_LIB to compile this file. 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | template class SPDLOG_API spdlog::sinks::basic_file_sink; 16 | template class SPDLOG_API spdlog::sinks::basic_file_sink; 17 | 18 | #include 19 | template class SPDLOG_API spdlog::sinks::rotating_file_sink; 20 | template class SPDLOG_API spdlog::sinks::rotating_file_sink; 21 | -------------------------------------------------------------------------------- /dep/log/spdlog/fmt/bundled/fmt.license.rst: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 - present, Victor Zverovich 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | --- Optional exception to the license --- 23 | 24 | As an exception, if, as a result of your compiling your source code, portions 25 | of this Software are embedded into a machine-executable object form of such 26 | source code, you may redistribute such embedded portions in such object form 27 | without including the above copyright and permission notices. 28 | -------------------------------------------------------------------------------- /dep/log/spdlog/fmt/bundled/locale.h: -------------------------------------------------------------------------------- 1 | #include "xchar.h" 2 | #warning fmt/locale.h is deprecated, include fmt/format.h or fmt/xchar.h instead 3 | -------------------------------------------------------------------------------- /dep/log/spdlog/fmt/chrono.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's chrono support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | #if !defined(SPDLOG_FMT_EXTERNAL) 13 | #ifdef SPDLOG_HEADER_ONLY 14 | #ifndef FMT_HEADER_ONLY 15 | #define FMT_HEADER_ONLY 16 | #endif 17 | #endif 18 | #include 19 | #else 20 | #include 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /dep/log/spdlog/fmt/compile.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's compile-time support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | #if !defined(SPDLOG_FMT_EXTERNAL) 13 | #ifdef SPDLOG_HEADER_ONLY 14 | #ifndef FMT_HEADER_ONLY 15 | #define FMT_HEADER_ONLY 16 | #endif 17 | #endif 18 | #include 19 | #else 20 | #include 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /dep/log/spdlog/fmt/fmt.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016-2018 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | 8 | // 9 | // Include a bundled header-only copy of fmtlib or an external one. 10 | // By default spdlog include its own copy. 11 | // 12 | 13 | #if defined(SPDLOG_USE_STD_FORMAT) // SPDLOG_USE_STD_FORMAT is defined - use std::format 14 | #include 15 | #elif !defined(SPDLOG_FMT_EXTERNAL) 16 | #if !defined(SPDLOG_COMPILED_LIB) && !defined(FMT_HEADER_ONLY) 17 | #define FMT_HEADER_ONLY 18 | #endif 19 | #ifndef FMT_USE_WINDOWS_H 20 | #define FMT_USE_WINDOWS_H 0 21 | #endif 22 | // enable the 'n' flag in for backward compatibility with fmt 6.x 23 | #define FMT_DEPRECATED_N_SPECIFIER 24 | // enable ostream formatting for backward compatibility with fmt 8.x 25 | #define FMT_DEPRECATED_OSTREAM 26 | 27 | #include 28 | #include 29 | 30 | #else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib 31 | #include 32 | #include 33 | #endif 34 | -------------------------------------------------------------------------------- /dep/log/spdlog/fmt/ostr.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's ostream support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | #if !defined(SPDLOG_FMT_EXTERNAL) 13 | #ifdef SPDLOG_HEADER_ONLY 14 | #ifndef FMT_HEADER_ONLY 15 | #define FMT_HEADER_ONLY 16 | #endif 17 | #endif 18 | #include 19 | #else 20 | #include 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /dep/log/spdlog/fmt/ranges.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's ranges support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | #if !defined(SPDLOG_FMT_EXTERNAL) 13 | #ifdef SPDLOG_HEADER_ONLY 14 | #ifndef FMT_HEADER_ONLY 15 | #define FMT_HEADER_ONLY 16 | #endif 17 | #endif 18 | #include 19 | #else 20 | #include 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /dep/log/spdlog/fmt/std.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's std support (for formatting e.g. 9 | // std::filesystem::path, std::thread::id, std::monostate, std::variant, ...) 10 | // 11 | 12 | #if !defined(SPDLOG_USE_STD_FORMAT) 13 | #if !defined(SPDLOG_FMT_EXTERNAL) 14 | #ifdef SPDLOG_HEADER_ONLY 15 | #ifndef FMT_HEADER_ONLY 16 | #define FMT_HEADER_ONLY 17 | #endif 18 | #endif 19 | #include 20 | #else 21 | #include 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /dep/log/spdlog/fmt/xchar.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's xchar support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | #if !defined(SPDLOG_FMT_EXTERNAL) 13 | #ifdef SPDLOG_HEADER_ONLY 14 | #ifndef FMT_HEADER_ONLY 15 | #define FMT_HEADER_ONLY 16 | #endif 17 | #endif 18 | #include 19 | #else 20 | #include 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /dep/log/spdlog/formatter.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | 11 | class formatter { 12 | public: 13 | virtual ~formatter() = default; 14 | virtual void format(const details::log_msg &msg, memory_buf_t &dest) = 0; 15 | virtual std::unique_ptr clone() const = 0; 16 | }; 17 | } // namespace spdlog 18 | -------------------------------------------------------------------------------- /dep/log/spdlog/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | namespace spdlog { 7 | class logger; 8 | class formatter; 9 | 10 | namespace sinks { 11 | class sink; 12 | } 13 | 14 | namespace level { 15 | enum level_enum : int; 16 | } 17 | 18 | } // namespace spdlog 19 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/base_sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | template 17 | SPDLOG_INLINE spdlog::sinks::base_sink::base_sink() 18 | : formatter_{details::make_unique()} {} 19 | 20 | template 21 | SPDLOG_INLINE spdlog::sinks::base_sink::base_sink( 22 | std::unique_ptr formatter) 23 | : formatter_{std::move(formatter)} {} 24 | 25 | template 26 | void SPDLOG_INLINE spdlog::sinks::base_sink::log(const details::log_msg &msg) { 27 | std::lock_guard lock(mutex_); 28 | sink_it_(msg); 29 | } 30 | 31 | template 32 | void SPDLOG_INLINE spdlog::sinks::base_sink::flush() { 33 | std::lock_guard lock(mutex_); 34 | flush_(); 35 | } 36 | 37 | template 38 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern(const std::string &pattern) { 39 | std::lock_guard lock(mutex_); 40 | set_pattern_(pattern); 41 | } 42 | 43 | template 44 | void SPDLOG_INLINE 45 | spdlog::sinks::base_sink::set_formatter(std::unique_ptr sink_formatter) { 46 | std::lock_guard lock(mutex_); 47 | set_formatter_(std::move(sink_formatter)); 48 | } 49 | 50 | template 51 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern_(const std::string &pattern) { 52 | set_formatter_(details::make_unique(pattern)); 53 | } 54 | 55 | template 56 | void SPDLOG_INLINE 57 | spdlog::sinks::base_sink::set_formatter_(std::unique_ptr sink_formatter) { 58 | formatter_ = std::move(sink_formatter); 59 | } 60 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/base_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | // 6 | // base sink templated over a mutex (either dummy or real) 7 | // concrete implementation should override the sink_it_() and flush_() methods. 8 | // locking is taken care of in this class - no locking needed by the 9 | // implementers.. 10 | // 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace spdlog { 17 | namespace sinks { 18 | template 19 | class SPDLOG_API base_sink : public sink { 20 | public: 21 | base_sink(); 22 | explicit base_sink(std::unique_ptr formatter); 23 | ~base_sink() override = default; 24 | 25 | base_sink(const base_sink &) = delete; 26 | base_sink(base_sink &&) = delete; 27 | 28 | base_sink &operator=(const base_sink &) = delete; 29 | base_sink &operator=(base_sink &&) = delete; 30 | 31 | void log(const details::log_msg &msg) final; 32 | void flush() final; 33 | void set_pattern(const std::string &pattern) final; 34 | void set_formatter(std::unique_ptr sink_formatter) final; 35 | 36 | protected: 37 | // sink formatter 38 | std::unique_ptr formatter_; 39 | Mutex mutex_; 40 | 41 | virtual void sink_it_(const details::log_msg &msg) = 0; 42 | virtual void flush_() = 0; 43 | virtual void set_pattern_(const std::string &pattern); 44 | virtual void set_formatter_(std::unique_ptr sink_formatter); 45 | }; 46 | } // namespace sinks 47 | } // namespace spdlog 48 | 49 | #ifdef SPDLOG_HEADER_ONLY 50 | #include "base_sink-inl.h" 51 | #endif 52 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/basic_file_sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | namespace sinks { 15 | 16 | template 17 | SPDLOG_INLINE basic_file_sink::basic_file_sink(const filename_t &filename, 18 | bool truncate, 19 | const file_event_handlers &event_handlers) 20 | : file_helper_{event_handlers} { 21 | file_helper_.open(filename, truncate); 22 | } 23 | 24 | template 25 | SPDLOG_INLINE const filename_t &basic_file_sink::filename() const { 26 | return file_helper_.filename(); 27 | } 28 | 29 | template 30 | SPDLOG_INLINE void basic_file_sink::sink_it_(const details::log_msg &msg) { 31 | memory_buf_t formatted; 32 | base_sink::formatter_->format(msg, formatted); 33 | file_helper_.write(formatted); 34 | } 35 | 36 | template 37 | SPDLOG_INLINE void basic_file_sink::flush_() { 38 | file_helper_.flush(); 39 | } 40 | 41 | } // namespace sinks 42 | } // namespace spdlog 43 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/basic_file_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace spdlog { 15 | namespace sinks { 16 | /* 17 | * Trivial file sink with single file as target 18 | */ 19 | template 20 | class basic_file_sink final : public base_sink { 21 | public: 22 | explicit basic_file_sink(const filename_t &filename, 23 | bool truncate = false, 24 | const file_event_handlers &event_handlers = {}); 25 | const filename_t &filename() const; 26 | 27 | protected: 28 | void sink_it_(const details::log_msg &msg) override; 29 | void flush_() override; 30 | 31 | private: 32 | details::file_helper file_helper_; 33 | }; 34 | 35 | using basic_file_sink_mt = basic_file_sink; 36 | using basic_file_sink_st = basic_file_sink; 37 | 38 | } // namespace sinks 39 | 40 | // 41 | // factory functions 42 | // 43 | template 44 | inline std::shared_ptr basic_logger_mt(const std::string &logger_name, 45 | const filename_t &filename, 46 | bool truncate = false, 47 | const file_event_handlers &event_handlers = {}) { 48 | return Factory::template create(logger_name, filename, truncate, 49 | event_handlers); 50 | } 51 | 52 | template 53 | inline std::shared_ptr basic_logger_st(const std::string &logger_name, 54 | const filename_t &filename, 55 | bool truncate = false, 56 | const file_event_handlers &event_handlers = {}) { 57 | return Factory::template create(logger_name, filename, truncate, 58 | event_handlers); 59 | } 60 | 61 | } // namespace spdlog 62 | 63 | #ifdef SPDLOG_HEADER_ONLY 64 | #include "basic_file_sink-inl.h" 65 | #endif 66 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/callback_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | 15 | // callbacks type 16 | typedef std::function custom_log_callback; 17 | 18 | namespace sinks { 19 | /* 20 | * Trivial callback sink, gets a callback function and calls it on each log 21 | */ 22 | template 23 | class callback_sink final : public base_sink { 24 | public: 25 | explicit callback_sink(const custom_log_callback &callback) 26 | : callback_{callback} {} 27 | 28 | protected: 29 | void sink_it_(const details::log_msg &msg) override { callback_(msg); } 30 | void flush_() override{}; 31 | 32 | private: 33 | custom_log_callback callback_; 34 | }; 35 | 36 | using callback_sink_mt = callback_sink; 37 | using callback_sink_st = callback_sink; 38 | 39 | } // namespace sinks 40 | 41 | // 42 | // factory functions 43 | // 44 | template 45 | inline std::shared_ptr callback_logger_mt(const std::string &logger_name, 46 | const custom_log_callback &callback) { 47 | return Factory::template create(logger_name, callback); 48 | } 49 | 50 | template 51 | inline std::shared_ptr callback_logger_st(const std::string &logger_name, 52 | const custom_log_callback &callback) { 53 | return Factory::template create(logger_name, callback); 54 | } 55 | 56 | } // namespace spdlog 57 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/dist_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "base_sink.h" 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // Distribution sink (mux). Stores a vector of sinks which get called when log 17 | // is called 18 | 19 | namespace spdlog { 20 | namespace sinks { 21 | 22 | template 23 | class dist_sink : public base_sink { 24 | public: 25 | dist_sink() = default; 26 | explicit dist_sink(std::vector> sinks) 27 | : sinks_(sinks) {} 28 | 29 | dist_sink(const dist_sink &) = delete; 30 | dist_sink &operator=(const dist_sink &) = delete; 31 | 32 | void add_sink(std::shared_ptr sub_sink) { 33 | std::lock_guard lock(base_sink::mutex_); 34 | sinks_.push_back(sub_sink); 35 | } 36 | 37 | void remove_sink(std::shared_ptr sub_sink) { 38 | std::lock_guard lock(base_sink::mutex_); 39 | sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sub_sink), sinks_.end()); 40 | } 41 | 42 | void set_sinks(std::vector> sinks) { 43 | std::lock_guard lock(base_sink::mutex_); 44 | sinks_ = std::move(sinks); 45 | } 46 | 47 | std::vector> &sinks() { return sinks_; } 48 | 49 | protected: 50 | void sink_it_(const details::log_msg &msg) override { 51 | for (auto &sub_sink : sinks_) { 52 | if (sub_sink->should_log(msg.level)) { 53 | sub_sink->log(msg); 54 | } 55 | } 56 | } 57 | 58 | void flush_() override { 59 | for (auto &sub_sink : sinks_) { 60 | sub_sink->flush(); 61 | } 62 | } 63 | 64 | void set_pattern_(const std::string &pattern) override { 65 | set_formatter_(details::make_unique(pattern)); 66 | } 67 | 68 | void set_formatter_(std::unique_ptr sink_formatter) override { 69 | base_sink::formatter_ = std::move(sink_formatter); 70 | for (auto &sub_sink : sinks_) { 71 | sub_sink->set_formatter(base_sink::formatter_->clone()); 72 | } 73 | } 74 | std::vector> sinks_; 75 | }; 76 | 77 | using dist_sink_mt = dist_sink; 78 | using dist_sink_st = dist_sink; 79 | 80 | } // namespace sinks 81 | } // namespace spdlog 82 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/dup_filter_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "dist_sink.h" 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | // Duplicate message removal sink. 16 | // Skip the message if previous one is identical and less than "max_skip_duration" have passed 17 | // 18 | // Example: 19 | // 20 | // #include 21 | // 22 | // int main() { 23 | // auto dup_filter = std::make_shared(std::chrono::seconds(5), 24 | // level::info); dup_filter->add_sink(std::make_shared()); 25 | // spdlog::logger l("logger", dup_filter); 26 | // l.info("Hello"); 27 | // l.info("Hello"); 28 | // l.info("Hello"); 29 | // l.info("Different Hello"); 30 | // } 31 | // 32 | // Will produce: 33 | // [2019-06-25 17:50:56.511] [logger] [info] Hello 34 | // [2019-06-25 17:50:56.512] [logger] [info] Skipped 3 duplicate messages.. 35 | // [2019-06-25 17:50:56.512] [logger] [info] Different Hello 36 | 37 | namespace spdlog { 38 | namespace sinks { 39 | template 40 | class dup_filter_sink : public dist_sink { 41 | public: 42 | template 43 | explicit dup_filter_sink(std::chrono::duration max_skip_duration, 44 | level::level_enum notification_level = level::info) 45 | : max_skip_duration_{max_skip_duration}, 46 | log_level_{notification_level} {} 47 | 48 | protected: 49 | std::chrono::microseconds max_skip_duration_; 50 | log_clock::time_point last_msg_time_; 51 | std::string last_msg_payload_; 52 | size_t skip_counter_ = 0; 53 | level::level_enum log_level_; 54 | 55 | void sink_it_(const details::log_msg &msg) override { 56 | bool filtered = filter_(msg); 57 | if (!filtered) { 58 | skip_counter_ += 1; 59 | return; 60 | } 61 | 62 | // log the "skipped.." message 63 | if (skip_counter_ > 0) { 64 | char buf[64]; 65 | auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", 66 | static_cast(skip_counter_)); 67 | if (msg_size > 0 && static_cast(msg_size) < sizeof(buf)) { 68 | details::log_msg skipped_msg{msg.source, msg.logger_name, log_level_, 69 | string_view_t{buf, static_cast(msg_size)}}; 70 | dist_sink::sink_it_(skipped_msg); 71 | } 72 | } 73 | 74 | // log current message 75 | dist_sink::sink_it_(msg); 76 | last_msg_time_ = msg.time; 77 | skip_counter_ = 0; 78 | last_msg_payload_.assign(msg.payload.data(), msg.payload.data() + msg.payload.size()); 79 | } 80 | 81 | // return whether the log msg should be displayed (true) or skipped (false) 82 | bool filter_(const details::log_msg &msg) { 83 | auto filter_duration = msg.time - last_msg_time_; 84 | return (filter_duration > max_skip_duration_) || (msg.payload != last_msg_payload_); 85 | } 86 | }; 87 | 88 | using dup_filter_sink_mt = dup_filter_sink; 89 | using dup_filter_sink_st = dup_filter_sink; 90 | 91 | } // namespace sinks 92 | } // namespace spdlog 93 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/msvc_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2016 Alexander Dalshov & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #if defined(_WIN32) 7 | 8 | #include 9 | #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) 10 | #include 11 | #endif 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | // Avoid including windows.h (https://stackoverflow.com/a/30741042) 18 | #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) 19 | extern "C" __declspec(dllimport) void __stdcall OutputDebugStringW(const wchar_t *lpOutputString); 20 | #else 21 | extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString); 22 | #endif 23 | extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); 24 | 25 | namespace spdlog { 26 | namespace sinks { 27 | /* 28 | * MSVC sink (logging using OutputDebugStringA) 29 | */ 30 | template 31 | class msvc_sink : public base_sink { 32 | public: 33 | msvc_sink() = default; 34 | msvc_sink(bool check_debugger_present) 35 | : check_debugger_present_{check_debugger_present} {}; 36 | 37 | protected: 38 | void sink_it_(const details::log_msg &msg) override { 39 | if (check_debugger_present_ && !IsDebuggerPresent()) { 40 | return; 41 | } 42 | memory_buf_t formatted; 43 | base_sink::formatter_->format(msg, formatted); 44 | formatted.push_back('\0'); // add a null terminator for OutputDebugString 45 | #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) 46 | wmemory_buf_t wformatted; 47 | details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), wformatted); 48 | OutputDebugStringW(wformatted.data()); 49 | #else 50 | OutputDebugStringA(formatted.data()); 51 | #endif 52 | } 53 | 54 | void flush_() override {} 55 | 56 | bool check_debugger_present_ = true; 57 | }; 58 | 59 | using msvc_sink_mt = msvc_sink; 60 | using msvc_sink_st = msvc_sink; 61 | 62 | using windebug_sink_mt = msvc_sink_mt; 63 | using windebug_sink_st = msvc_sink_st; 64 | 65 | } // namespace sinks 66 | } // namespace spdlog 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/null_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | 15 | template 16 | class null_sink : public base_sink { 17 | protected: 18 | void sink_it_(const details::log_msg &) override {} 19 | void flush_() override {} 20 | }; 21 | 22 | using null_sink_mt = null_sink; 23 | using null_sink_st = null_sink; 24 | 25 | } // namespace sinks 26 | 27 | template 28 | inline std::shared_ptr null_logger_mt(const std::string &logger_name) { 29 | auto null_logger = Factory::template create(logger_name); 30 | null_logger->set_level(level::off); 31 | return null_logger; 32 | } 33 | 34 | template 35 | inline std::shared_ptr null_logger_st(const std::string &logger_name) { 36 | auto null_logger = Factory::template create(logger_name); 37 | null_logger->set_level(level::off); 38 | return null_logger; 39 | } 40 | 41 | } // namespace spdlog 42 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/ostream_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | template 15 | class ostream_sink final : public base_sink { 16 | public: 17 | explicit ostream_sink(std::ostream &os, bool force_flush = false) 18 | : ostream_(os), 19 | force_flush_(force_flush) {} 20 | ostream_sink(const ostream_sink &) = delete; 21 | ostream_sink &operator=(const ostream_sink &) = delete; 22 | 23 | protected: 24 | void sink_it_(const details::log_msg &msg) override { 25 | memory_buf_t formatted; 26 | base_sink::formatter_->format(msg, formatted); 27 | ostream_.write(formatted.data(), static_cast(formatted.size())); 28 | if (force_flush_) { 29 | ostream_.flush(); 30 | } 31 | } 32 | 33 | void flush_() override { ostream_.flush(); } 34 | 35 | std::ostream &ostream_; 36 | bool force_flush_; 37 | }; 38 | 39 | using ostream_sink_mt = ostream_sink; 40 | using ostream_sink_st = ostream_sink; 41 | 42 | } // namespace sinks 43 | } // namespace spdlog 44 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/ringbuffer_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/details/circular_q.h" 7 | #include "spdlog/details/log_msg_buffer.h" 8 | #include "spdlog/details/null_mutex.h" 9 | #include "spdlog/sinks/base_sink.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace spdlog { 16 | namespace sinks { 17 | /* 18 | * Ring buffer sink 19 | */ 20 | template 21 | class ringbuffer_sink final : public base_sink { 22 | public: 23 | explicit ringbuffer_sink(size_t n_items) 24 | : q_{n_items} {} 25 | 26 | std::vector last_raw(size_t lim = 0) { 27 | std::lock_guard lock(base_sink::mutex_); 28 | auto items_available = q_.size(); 29 | auto n_items = lim > 0 ? (std::min)(lim, items_available) : items_available; 30 | std::vector ret; 31 | ret.reserve(n_items); 32 | for (size_t i = (items_available - n_items); i < items_available; i++) { 33 | ret.push_back(q_.at(i)); 34 | } 35 | return ret; 36 | } 37 | 38 | std::vector last_formatted(size_t lim = 0) { 39 | std::lock_guard lock(base_sink::mutex_); 40 | auto items_available = q_.size(); 41 | auto n_items = lim > 0 ? (std::min)(lim, items_available) : items_available; 42 | std::vector ret; 43 | ret.reserve(n_items); 44 | for (size_t i = (items_available - n_items); i < items_available; i++) { 45 | memory_buf_t formatted; 46 | base_sink::formatter_->format(q_.at(i), formatted); 47 | ret.push_back(SPDLOG_BUF_TO_STRING(formatted)); 48 | } 49 | return ret; 50 | } 51 | 52 | protected: 53 | void sink_it_(const details::log_msg &msg) override { 54 | q_.push_back(details::log_msg_buffer{msg}); 55 | } 56 | void flush_() override {} 57 | 58 | private: 59 | details::circular_q q_; 60 | }; 61 | 62 | using ringbuffer_sink_mt = ringbuffer_sink; 63 | using ringbuffer_sink_st = ringbuffer_sink; 64 | 65 | } // namespace sinks 66 | 67 | } // namespace spdlog 68 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/rotating_file_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace spdlog { 16 | namespace sinks { 17 | 18 | // 19 | // Rotating file sink based on size 20 | // 21 | template 22 | class rotating_file_sink final : public base_sink { 23 | public: 24 | rotating_file_sink(filename_t base_filename, 25 | std::size_t max_size, 26 | std::size_t max_files, 27 | bool rotate_on_open = false, 28 | const file_event_handlers &event_handlers = {}); 29 | static filename_t calc_filename(const filename_t &filename, std::size_t index); 30 | filename_t filename(); 31 | 32 | protected: 33 | void sink_it_(const details::log_msg &msg) override; 34 | void flush_() override; 35 | 36 | private: 37 | // Rotate files: 38 | // log.txt -> log.1.txt 39 | // log.1.txt -> log.2.txt 40 | // log.2.txt -> log.3.txt 41 | // log.3.txt -> delete 42 | void rotate_(); 43 | 44 | // delete the target if exists, and rename the src file to target 45 | // return true on success, false otherwise. 46 | bool rename_file_(const filename_t &src_filename, const filename_t &target_filename); 47 | 48 | filename_t base_filename_; 49 | std::size_t max_size_; 50 | std::size_t max_files_; 51 | std::size_t current_size_; 52 | details::file_helper file_helper_; 53 | }; 54 | 55 | using rotating_file_sink_mt = rotating_file_sink; 56 | using rotating_file_sink_st = rotating_file_sink; 57 | 58 | } // namespace sinks 59 | 60 | // 61 | // factory functions 62 | // 63 | 64 | template 65 | inline std::shared_ptr rotating_logger_mt(const std::string &logger_name, 66 | const filename_t &filename, 67 | size_t max_file_size, 68 | size_t max_files, 69 | bool rotate_on_open = false, 70 | const file_event_handlers &event_handlers = {}) { 71 | return Factory::template create( 72 | logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers); 73 | } 74 | 75 | template 76 | inline std::shared_ptr rotating_logger_st(const std::string &logger_name, 77 | const filename_t &filename, 78 | size_t max_file_size, 79 | size_t max_files, 80 | bool rotate_on_open = false, 81 | const file_event_handlers &event_handlers = {}) { 82 | return Factory::template create( 83 | logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers); 84 | } 85 | } // namespace spdlog 86 | 87 | #ifdef SPDLOG_HEADER_ONLY 88 | #include "rotating_file_sink-inl.h" 89 | #endif 90 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | 12 | SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const { 13 | return msg_level >= level_.load(std::memory_order_relaxed); 14 | } 15 | 16 | SPDLOG_INLINE void spdlog::sinks::sink::set_level(level::level_enum log_level) { 17 | level_.store(log_level, std::memory_order_relaxed); 18 | } 19 | 20 | SPDLOG_INLINE spdlog::level::level_enum spdlog::sinks::sink::level() const { 21 | return static_cast(level_.load(std::memory_order_relaxed)); 22 | } 23 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | 11 | namespace sinks { 12 | class SPDLOG_API sink { 13 | public: 14 | virtual ~sink() = default; 15 | virtual void log(const details::log_msg &msg) = 0; 16 | virtual void flush() = 0; 17 | virtual void set_pattern(const std::string &pattern) = 0; 18 | virtual void set_formatter(std::unique_ptr sink_formatter) = 0; 19 | 20 | void set_level(level::level_enum log_level); 21 | level::level_enum level() const; 22 | bool should_log(level::level_enum msg_level) const; 23 | 24 | protected: 25 | // sink log level - default is all 26 | level_t level_{level::trace}; 27 | }; 28 | 29 | } // namespace sinks 30 | } // namespace spdlog 31 | 32 | #ifdef SPDLOG_HEADER_ONLY 33 | #include "sink-inl.h" 34 | #endif 35 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/stdout_color_sinks-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | 15 | template 16 | SPDLOG_INLINE std::shared_ptr stdout_color_mt(const std::string &logger_name, 17 | color_mode mode) { 18 | return Factory::template create(logger_name, mode); 19 | } 20 | 21 | template 22 | SPDLOG_INLINE std::shared_ptr stdout_color_st(const std::string &logger_name, 23 | color_mode mode) { 24 | return Factory::template create(logger_name, mode); 25 | } 26 | 27 | template 28 | SPDLOG_INLINE std::shared_ptr stderr_color_mt(const std::string &logger_name, 29 | color_mode mode) { 30 | return Factory::template create(logger_name, mode); 31 | } 32 | 33 | template 34 | SPDLOG_INLINE std::shared_ptr stderr_color_st(const std::string &logger_name, 35 | color_mode mode) { 36 | return Factory::template create(logger_name, mode); 37 | } 38 | } // namespace spdlog 39 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/stdout_color_sinks.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifdef _WIN32 7 | #include 8 | #else 9 | #include 10 | #endif 11 | 12 | #include 13 | 14 | namespace spdlog { 15 | namespace sinks { 16 | #ifdef _WIN32 17 | using stdout_color_sink_mt = wincolor_stdout_sink_mt; 18 | using stdout_color_sink_st = wincolor_stdout_sink_st; 19 | using stderr_color_sink_mt = wincolor_stderr_sink_mt; 20 | using stderr_color_sink_st = wincolor_stderr_sink_st; 21 | #else 22 | using stdout_color_sink_mt = ansicolor_stdout_sink_mt; 23 | using stdout_color_sink_st = ansicolor_stdout_sink_st; 24 | using stderr_color_sink_mt = ansicolor_stderr_sink_mt; 25 | using stderr_color_sink_st = ansicolor_stderr_sink_st; 26 | #endif 27 | } // namespace sinks 28 | 29 | template 30 | std::shared_ptr stdout_color_mt(const std::string &logger_name, 31 | color_mode mode = color_mode::automatic); 32 | 33 | template 34 | std::shared_ptr stdout_color_st(const std::string &logger_name, 35 | color_mode mode = color_mode::automatic); 36 | 37 | template 38 | std::shared_ptr stderr_color_mt(const std::string &logger_name, 39 | color_mode mode = color_mode::automatic); 40 | 41 | template 42 | std::shared_ptr stderr_color_st(const std::string &logger_name, 43 | color_mode mode = color_mode::automatic); 44 | 45 | } // namespace spdlog 46 | 47 | #ifdef SPDLOG_HEADER_ONLY 48 | #include "stdout_color_sinks-inl.h" 49 | #endif 50 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/stdout_sinks.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef _WIN32 12 | #include 13 | #endif 14 | 15 | namespace spdlog { 16 | 17 | namespace sinks { 18 | 19 | template 20 | class stdout_sink_base : public sink { 21 | public: 22 | using mutex_t = typename ConsoleMutex::mutex_t; 23 | explicit stdout_sink_base(FILE *file); 24 | ~stdout_sink_base() override = default; 25 | 26 | stdout_sink_base(const stdout_sink_base &other) = delete; 27 | stdout_sink_base(stdout_sink_base &&other) = delete; 28 | 29 | stdout_sink_base &operator=(const stdout_sink_base &other) = delete; 30 | stdout_sink_base &operator=(stdout_sink_base &&other) = delete; 31 | 32 | void log(const details::log_msg &msg) override; 33 | void flush() override; 34 | void set_pattern(const std::string &pattern) override; 35 | 36 | void set_formatter(std::unique_ptr sink_formatter) override; 37 | 38 | protected: 39 | mutex_t &mutex_; 40 | FILE *file_; 41 | std::unique_ptr formatter_; 42 | #ifdef _WIN32 43 | HANDLE handle_; 44 | #endif // WIN32 45 | }; 46 | 47 | template 48 | class stdout_sink : public stdout_sink_base { 49 | public: 50 | stdout_sink(); 51 | }; 52 | 53 | template 54 | class stderr_sink : public stdout_sink_base { 55 | public: 56 | stderr_sink(); 57 | }; 58 | 59 | using stdout_sink_mt = stdout_sink; 60 | using stdout_sink_st = stdout_sink; 61 | 62 | using stderr_sink_mt = stderr_sink; 63 | using stderr_sink_st = stderr_sink; 64 | 65 | } // namespace sinks 66 | 67 | // factory methods 68 | template 69 | std::shared_ptr stdout_logger_mt(const std::string &logger_name); 70 | 71 | template 72 | std::shared_ptr stdout_logger_st(const std::string &logger_name); 73 | 74 | template 75 | std::shared_ptr stderr_logger_mt(const std::string &logger_name); 76 | 77 | template 78 | std::shared_ptr stderr_logger_st(const std::string &logger_name); 79 | 80 | } // namespace spdlog 81 | 82 | #ifdef SPDLOG_HEADER_ONLY 83 | #include "stdout_sinks-inl.h" 84 | #endif 85 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/tcp_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #ifdef _WIN32 10 | #include 11 | #else 12 | #include 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #pragma once 21 | 22 | // Simple tcp client sink 23 | // Connects to remote address and send the formatted log. 24 | // Will attempt to reconnect if connection drops. 25 | // If more complicated behaviour is needed (i.e get responses), you can inherit it and override the 26 | // sink_it_ method. 27 | 28 | namespace spdlog { 29 | namespace sinks { 30 | 31 | struct tcp_sink_config { 32 | std::string server_host; 33 | int server_port; 34 | bool lazy_connect = false; // if true connect on first log call instead of on construction 35 | 36 | tcp_sink_config(std::string host, int port) 37 | : server_host{std::move(host)}, 38 | server_port{port} {} 39 | }; 40 | 41 | template 42 | class tcp_sink : public spdlog::sinks::base_sink { 43 | public: 44 | // connect to tcp host/port or throw if failed 45 | // host can be hostname or ip address 46 | 47 | explicit tcp_sink(tcp_sink_config sink_config) 48 | : config_{std::move(sink_config)} { 49 | if (!config_.lazy_connect) { 50 | this->client_.connect(config_.server_host, config_.server_port); 51 | } 52 | } 53 | 54 | ~tcp_sink() override = default; 55 | 56 | protected: 57 | void sink_it_(const spdlog::details::log_msg &msg) override { 58 | spdlog::memory_buf_t formatted; 59 | spdlog::sinks::base_sink::formatter_->format(msg, formatted); 60 | if (!client_.is_connected()) { 61 | client_.connect(config_.server_host, config_.server_port); 62 | } 63 | client_.send(formatted.data(), formatted.size()); 64 | } 65 | 66 | void flush_() override {} 67 | tcp_sink_config config_; 68 | details::tcp_client client_; 69 | }; 70 | 71 | using tcp_sink_mt = tcp_sink; 72 | using tcp_sink_st = tcp_sink; 73 | 74 | } // namespace sinks 75 | } // namespace spdlog 76 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/udp_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #ifdef _WIN32 10 | #include 11 | #else 12 | #include 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | // Simple udp client sink 21 | // Sends formatted log via udp 22 | 23 | namespace spdlog { 24 | namespace sinks { 25 | 26 | struct udp_sink_config { 27 | std::string server_host; 28 | uint16_t server_port; 29 | 30 | udp_sink_config(std::string host, uint16_t port) 31 | : server_host{std::move(host)}, 32 | server_port{port} {} 33 | }; 34 | 35 | template 36 | class udp_sink : public spdlog::sinks::base_sink { 37 | public: 38 | // host can be hostname or ip address 39 | explicit udp_sink(udp_sink_config sink_config) 40 | : client_{sink_config.server_host, sink_config.server_port} {} 41 | 42 | ~udp_sink() override = default; 43 | 44 | protected: 45 | void sink_it_(const spdlog::details::log_msg &msg) override { 46 | spdlog::memory_buf_t formatted; 47 | spdlog::sinks::base_sink::formatter_->format(msg, formatted); 48 | client_.send(formatted.data(), formatted.size()); 49 | } 50 | 51 | void flush_() override {} 52 | details::udp_client client_; 53 | }; 54 | 55 | using udp_sink_mt = udp_sink; 56 | using udp_sink_st = udp_sink; 57 | 58 | } // namespace sinks 59 | 60 | // 61 | // factory functions 62 | // 63 | template 64 | inline std::shared_ptr udp_logger_mt(const std::string &logger_name, 65 | sinks::udp_sink_config skin_config) { 66 | return Factory::template create(logger_name, skin_config); 67 | } 68 | 69 | } // namespace spdlog 70 | -------------------------------------------------------------------------------- /dep/log/spdlog/sinks/wincolor_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace spdlog { 18 | namespace sinks { 19 | /* 20 | * Windows color console sink. Uses WriteConsoleA to write to the console with 21 | * colors 22 | */ 23 | template 24 | class wincolor_sink : public sink { 25 | public: 26 | wincolor_sink(void *out_handle, color_mode mode); 27 | ~wincolor_sink() override; 28 | 29 | wincolor_sink(const wincolor_sink &other) = delete; 30 | wincolor_sink &operator=(const wincolor_sink &other) = delete; 31 | 32 | // change the color for the given level 33 | void set_color(level::level_enum level, std::uint16_t color); 34 | void log(const details::log_msg &msg) final override; 35 | void flush() final override; 36 | void set_pattern(const std::string &pattern) override final; 37 | void set_formatter(std::unique_ptr sink_formatter) override final; 38 | void set_color_mode(color_mode mode); 39 | 40 | protected: 41 | using mutex_t = typename ConsoleMutex::mutex_t; 42 | void *out_handle_; 43 | mutex_t &mutex_; 44 | bool should_do_colors_; 45 | std::unique_ptr formatter_; 46 | std::array colors_; 47 | 48 | // set foreground color and return the orig console attributes (for resetting later) 49 | std::uint16_t set_foreground_color_(std::uint16_t attribs); 50 | 51 | // print a range of formatted message to console 52 | void print_range_(const memory_buf_t &formatted, size_t start, size_t end); 53 | 54 | // in case we are redirected to file (not in console mode) 55 | void write_to_file_(const memory_buf_t &formatted); 56 | 57 | void set_color_mode_impl(color_mode mode); 58 | }; 59 | 60 | template 61 | class wincolor_stdout_sink : public wincolor_sink { 62 | public: 63 | explicit wincolor_stdout_sink(color_mode mode = color_mode::automatic); 64 | }; 65 | 66 | template 67 | class wincolor_stderr_sink : public wincolor_sink { 68 | public: 69 | explicit wincolor_stderr_sink(color_mode mode = color_mode::automatic); 70 | }; 71 | 72 | using wincolor_stdout_sink_mt = wincolor_stdout_sink; 73 | using wincolor_stdout_sink_st = wincolor_stdout_sink; 74 | 75 | using wincolor_stderr_sink_mt = wincolor_stderr_sink; 76 | using wincolor_stderr_sink_st = wincolor_stderr_sink; 77 | } // namespace sinks 78 | } // namespace spdlog 79 | 80 | #ifdef SPDLOG_HEADER_ONLY 81 | #include "wincolor_sink-inl.h" 82 | #endif 83 | -------------------------------------------------------------------------------- /dep/log/spdlog/spdlog-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | 15 | SPDLOG_INLINE void initialize_logger(std::shared_ptr logger) { 16 | details::registry::instance().initialize_logger(std::move(logger)); 17 | } 18 | 19 | SPDLOG_INLINE std::shared_ptr get(const std::string &name) { 20 | return details::registry::instance().get(name); 21 | } 22 | 23 | SPDLOG_INLINE void set_formatter(std::unique_ptr formatter) { 24 | details::registry::instance().set_formatter(std::move(formatter)); 25 | } 26 | 27 | SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type) { 28 | set_formatter( 29 | std::unique_ptr(new pattern_formatter(std::move(pattern), time_type))); 30 | } 31 | 32 | SPDLOG_INLINE void enable_backtrace(size_t n_messages) { 33 | details::registry::instance().enable_backtrace(n_messages); 34 | } 35 | 36 | SPDLOG_INLINE void disable_backtrace() { details::registry::instance().disable_backtrace(); } 37 | 38 | SPDLOG_INLINE void dump_backtrace() { default_logger_raw()->dump_backtrace(); } 39 | 40 | SPDLOG_INLINE level::level_enum get_level() { return default_logger_raw()->level(); } 41 | 42 | SPDLOG_INLINE bool should_log(level::level_enum log_level) { 43 | return default_logger_raw()->should_log(log_level); 44 | } 45 | 46 | SPDLOG_INLINE void set_level(level::level_enum log_level) { 47 | details::registry::instance().set_level(log_level); 48 | } 49 | 50 | SPDLOG_INLINE void flush_on(level::level_enum log_level) { 51 | details::registry::instance().flush_on(log_level); 52 | } 53 | 54 | SPDLOG_INLINE void set_error_handler(void (*handler)(const std::string &msg)) { 55 | details::registry::instance().set_error_handler(handler); 56 | } 57 | 58 | SPDLOG_INLINE void register_logger(std::shared_ptr logger) { 59 | details::registry::instance().register_logger(std::move(logger)); 60 | } 61 | 62 | SPDLOG_INLINE void apply_all(const std::function)> &fun) { 63 | details::registry::instance().apply_all(fun); 64 | } 65 | 66 | SPDLOG_INLINE void drop(const std::string &name) { details::registry::instance().drop(name); } 67 | 68 | SPDLOG_INLINE void drop_all() { details::registry::instance().drop_all(); } 69 | 70 | SPDLOG_INLINE void shutdown() { details::registry::instance().shutdown(); } 71 | 72 | SPDLOG_INLINE void set_automatic_registration(bool automatic_registration) { 73 | details::registry::instance().set_automatic_registration(automatic_registration); 74 | } 75 | 76 | SPDLOG_INLINE std::shared_ptr default_logger() { 77 | return details::registry::instance().default_logger(); 78 | } 79 | 80 | SPDLOG_INLINE spdlog::logger *default_logger_raw() { 81 | return details::registry::instance().get_default_raw(); 82 | } 83 | 84 | SPDLOG_INLINE void set_default_logger(std::shared_ptr default_logger) { 85 | details::registry::instance().set_default_logger(std::move(default_logger)); 86 | } 87 | 88 | SPDLOG_INLINE void apply_logger_env_levels(std::shared_ptr logger) { 89 | details::registry::instance().apply_logger_env_levels(std::move(logger)); 90 | } 91 | 92 | } // namespace spdlog 93 | -------------------------------------------------------------------------------- /dep/log/spdlog/spdlog.cpp: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef SPDLOG_COMPILED_LIB 5 | #error Please define SPDLOG_COMPILED_LIB to compile this file. 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | // template instantiate logger constructor with sinks init list 24 | template SPDLOG_API spdlog::logger::logger(std::string name, 25 | sinks_init_list::iterator begin, 26 | sinks_init_list::iterator end); 27 | template class SPDLOG_API spdlog::sinks::base_sink; 28 | template class SPDLOG_API spdlog::sinks::base_sink; 29 | -------------------------------------------------------------------------------- /dep/log/spdlog/stdout_sinks.cpp: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #ifndef SPDLOG_COMPILED_LIB 5 | #error Please define SPDLOG_COMPILED_LIB to compile this file. 6 | #endif 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | template class SPDLOG_API spdlog::sinks::stdout_sink_base; 15 | template class SPDLOG_API spdlog::sinks::stdout_sink_base; 16 | template class SPDLOG_API spdlog::sinks::stdout_sink; 17 | template class SPDLOG_API spdlog::sinks::stdout_sink; 18 | template class SPDLOG_API spdlog::sinks::stderr_sink; 19 | template class SPDLOG_API spdlog::sinks::stderr_sink; 20 | 21 | template SPDLOG_API std::shared_ptr 22 | spdlog::stdout_logger_mt(const std::string &logger_name); 23 | template SPDLOG_API std::shared_ptr 24 | spdlog::stdout_logger_st(const std::string &logger_name); 25 | template SPDLOG_API std::shared_ptr 26 | spdlog::stderr_logger_mt(const std::string &logger_name); 27 | template SPDLOG_API std::shared_ptr 28 | spdlog::stderr_logger_st(const std::string &logger_name); 29 | 30 | template SPDLOG_API std::shared_ptr spdlog::stdout_logger_mt( 31 | const std::string &logger_name); 32 | template SPDLOG_API std::shared_ptr spdlog::stdout_logger_st( 33 | const std::string &logger_name); 34 | template SPDLOG_API std::shared_ptr spdlog::stderr_logger_mt( 35 | const std::string &logger_name); 36 | template SPDLOG_API std::shared_ptr spdlog::stderr_logger_st( 37 | const std::string &logger_name); 38 | -------------------------------------------------------------------------------- /dep/log/spdlog/stopwatch.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | // Stopwatch support for spdlog (using std::chrono::steady_clock). 10 | // Displays elapsed seconds since construction as double. 11 | // 12 | // Usage: 13 | // 14 | // spdlog::stopwatch sw; 15 | // ... 16 | // spdlog::debug("Elapsed: {} seconds", sw); => "Elapsed 0.005116733 seconds" 17 | // spdlog::info("Elapsed: {:.6} seconds", sw); => "Elapsed 0.005163 seconds" 18 | // 19 | // 20 | // If other units are needed (e.g. millis instead of double), include "fmt/chrono.h" and use 21 | // "duration_cast<..>(sw.elapsed())": 22 | // 23 | // #include 24 | //.. 25 | // using std::chrono::duration_cast; 26 | // using std::chrono::milliseconds; 27 | // spdlog::info("Elapsed {}", duration_cast(sw.elapsed())); => "Elapsed 5ms" 28 | 29 | namespace spdlog { 30 | class stopwatch { 31 | using clock = std::chrono::steady_clock; 32 | std::chrono::time_point start_tp_; 33 | 34 | public: 35 | stopwatch() 36 | : start_tp_{clock::now()} {} 37 | 38 | std::chrono::duration elapsed() const { 39 | return std::chrono::duration(clock::now() - start_tp_); 40 | } 41 | 42 | void reset() { start_tp_ = clock::now(); } 43 | }; 44 | } // namespace spdlog 45 | 46 | // Support for fmt formatting (e.g. "{:012.9}" or just "{}") 47 | namespace 48 | #ifdef SPDLOG_USE_STD_FORMAT 49 | std 50 | #else 51 | fmt 52 | #endif 53 | { 54 | 55 | template <> 56 | struct formatter : formatter { 57 | template 58 | auto format(const spdlog::stopwatch &sw, FormatContext &ctx) const -> decltype(ctx.out()) { 59 | return formatter::format(sw.elapsed().count(), ctx); 60 | } 61 | }; 62 | } // namespace std 63 | -------------------------------------------------------------------------------- /dep/log/spdlog/version.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define SPDLOG_VER_MAJOR 1 7 | #define SPDLOG_VER_MINOR 12 8 | #define SPDLOG_VER_PATCH 0 9 | 10 | #define SPDLOG_TO_VERSION(major, minor, patch) (major * 10000 + minor * 100 + patch) 11 | #define SPDLOG_VERSION SPDLOG_TO_VERSION(SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH) 12 | -------------------------------------------------------------------------------- /dep/readline/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | add_library(readline INTERFACE) 12 | 13 | if( UNIX ) 14 | find_package(Readline REQUIRED) 15 | 16 | target_link_libraries(readline 17 | INTERFACE 18 | Readline::Readline) 19 | endif() 20 | -------------------------------------------------------------------------------- /dep/restclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message("CMakeLists.txt load rest_client ...") 2 | 3 | SET(LIBRARY_NAME rest_client) 4 | 5 | find_package(Threads REQUIRED) 6 | find_package(CURL REQUIRED) 7 | #find_package(jsonlib) 8 | 9 | add_library(${LIBRARY_NAME} 10 | RestClient.cpp 11 | Helper.cpp 12 | Connection.cpp) 13 | 14 | target_include_directories(${LIBRARY_NAME} 15 | PUBLIC 16 | ../../src 17 | ) 18 | 19 | # must 20 | find_package(CURL REQUIRED) 21 | 22 | # must 23 | target_link_libraries(${LIBRARY_NAME} 24 | PUBLIC CURL::libcurl 25 | ) 26 | 27 | 28 | install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) -------------------------------------------------------------------------------- /dep/restclient/Helper.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file helpers.cpp 3 | * @brief implementation of the restclient helpers 4 | * @author Daniel Schauenberg 5 | */ 6 | 7 | #include "Helper.h" 8 | 9 | #include 10 | 11 | #include "RestClient.h" 12 | 13 | /** 14 | * @brief write callback function for libcurl 15 | * 16 | * @param data returned data of size (size*nmemb) 17 | * @param size size parameter 18 | * @param nmemb memblock parameter 19 | * @param userdata pointer to user data to save/work with return data 20 | * 21 | * @return (size * nmemb) 22 | */ 23 | size_t RestClient::Helpers::write_callback(void *data, size_t size, 24 | size_t nmemb, void *userdata) { 25 | RestClient::Response* r; 26 | r = reinterpret_cast(userdata); 27 | r->body.append(reinterpret_cast(data), size*nmemb); 28 | 29 | return (size * nmemb); 30 | } 31 | 32 | /** 33 | * @brief header callback for libcurl 34 | * 35 | * @param data returned (header line) 36 | * @param size of data 37 | * @param nmemb memblock 38 | * @param userdata pointer to user data object to save headr data 39 | * @return size * nmemb; 40 | */ 41 | size_t RestClient::Helpers::header_callback(void *data, size_t size, 42 | size_t nmemb, void *userdata) { 43 | RestClient::Response* r; 44 | r = reinterpret_cast(userdata); 45 | std::string header(reinterpret_cast(data), size*nmemb); 46 | size_t seperator = header.find_first_of(':'); 47 | if ( std::string::npos == seperator ) { 48 | // roll with non seperated headers... 49 | trim(header); 50 | if (0 == header.length()) { 51 | return (size * nmemb); // blank line; 52 | } 53 | r->headers[header] = "present"; 54 | } else { 55 | std::string key = header.substr(0, seperator); 56 | trim(key); 57 | std::string value = header.substr(seperator + 1); 58 | trim(value); 59 | r->headers[key] = value; 60 | } 61 | 62 | return (size * nmemb); 63 | } 64 | 65 | /** 66 | * @brief read callback function for libcurl 67 | * 68 | * @param data pointer of max size (size*nmemb) to write data to 69 | * @param size size parameter 70 | * @param nmemb memblock parameter 71 | * @param userdata pointer to user data to read data from 72 | * 73 | * @return (size * nmemb) 74 | */ 75 | size_t RestClient::Helpers::read_callback(void *data, size_t size, 76 | size_t nmemb, void *userdata) { 77 | /** get upload struct */ 78 | RestClient::Helpers::UploadObject* u; 79 | u = reinterpret_cast(userdata); 80 | /** set correct sizes */ 81 | size_t curl_size = size * nmemb; 82 | size_t copy_size = (u->length < curl_size) ? u->length : curl_size; 83 | /** copy data to buffer */ 84 | std::memcpy(data, u->data, copy_size); 85 | /** decrement length and increment data pointer */ 86 | u->length -= copy_size; 87 | u->data += copy_size; 88 | /** return copied size */ 89 | return copy_size; 90 | } 91 | -------------------------------------------------------------------------------- /dep/restclient/Helper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file helpers.h 3 | * @brief header file for restclient-cpp helpers 4 | * @author Daniel Schauenberg 5 | * @version 6 | * @date 2010-10-11 7 | */ 8 | 9 | #ifndef INCLUDE_RESTCLIENT_CPP_HELPERS_H_ 10 | #define INCLUDE_RESTCLIENT_CPP_HELPERS_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | /** 19 | * @brief namespace for all RestClient definitions 20 | */ 21 | namespace RestClient { 22 | 23 | /** 24 | * @brief: namespace for all helper functions 25 | */ 26 | namespace Helpers { 27 | 28 | /** @struct UploadObject 29 | * @brief This structure represents the payload to upload on POST 30 | * requests 31 | * @var UploadObject::data 32 | * Member 'data' contains the data to upload 33 | * @var UploadObject::length 34 | * Member 'length' contains the length of the data to upload 35 | */ 36 | typedef struct { 37 | const char* data; 38 | size_t length; 39 | } UploadObject; 40 | 41 | // writedata callback function 42 | size_t write_callback(void *ptr, size_t size, size_t nmemb, 43 | void *userdata); 44 | 45 | // header callback function 46 | size_t header_callback(void *ptr, size_t size, size_t nmemb, 47 | void *userdata); 48 | // read callback function 49 | size_t read_callback(void *ptr, size_t size, size_t nmemb, 50 | void *userdata); 51 | 52 | // trim from start 53 | static inline std::string <rim(std::string &s) { // NOLINT 54 | s.erase(s.begin(), std::find_if(s.begin(), s.end(), 55 | [](int c) {return !std::isspace(c);})); 56 | return s; 57 | } 58 | 59 | // trim from end 60 | static inline std::string &rtrim(std::string &s) { // NOLINT 61 | s.erase(std::find_if(s.rbegin(), s.rend(), 62 | [](int c) {return !std::isspace(c);}).base(), s.end()); 63 | return s; 64 | } 65 | 66 | // trim from both ends 67 | static inline std::string &trim(std::string &s) { // NOLINT 68 | return ltrim(rtrim(s)); 69 | } 70 | } // namespace Helpers 71 | 72 | } // namespace RestClient 73 | 74 | #endif // INCLUDE_RESTCLIENT_CPP_HELPERS_H_ 75 | -------------------------------------------------------------------------------- /dep/restclient/RestClient.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file restclient.h 3 | * @brief libcurl wrapper for REST calls 4 | * @author Daniel Schauenberg 5 | * @version 6 | * @date 2010-10-11 7 | */ 8 | 9 | #ifndef INCLUDE_RESTCLIENT_CPP_RESTCLIENT_H_ 10 | #define INCLUDE_RESTCLIENT_CPP_RESTCLIENT_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | /** 18 | * @brief namespace for all RestClient definitions 19 | */ 20 | namespace RestClient { 21 | 22 | /** 23 | * public data definitions 24 | */ 25 | typedef std::map HeaderFields; 26 | 27 | typedef struct { 28 | int code; 29 | std::string body; 30 | HeaderFields headers; 31 | } Request; 32 | 33 | /** @struct Response 34 | * @brief This structure represents the HTTP response data 35 | * @var Response::code 36 | * Member 'code' contains the HTTP response code, or cURL error code 37 | * @var Response::body 38 | * Member 'body' contains the HTTP response body, or curl_easy_strerror output 39 | * @var Response::headers 40 | * Member 'headers' contains the HTTP response headers 41 | */ 42 | typedef struct { 43 | int code; 44 | std::string body; 45 | HeaderFields headers; 46 | } Response; 47 | 48 | // init and disable functions 49 | int init(); 50 | void disable(); 51 | 52 | /** 53 | * public methods for the simple API. These don't allow a lot of 54 | * configuration but are meant for simple HTTP calls. 55 | * 56 | */ 57 | Response GET(const std::string& url); 58 | Response POST(const std::string& url, 59 | const std::string& content_type, 60 | const std::string& data); 61 | Response PUT(const std::string& url, 62 | const std::string& content_type, 63 | const std::string& data); 64 | Response PATCH(const std::string& url, 65 | const std::string& content_type, 66 | const std::string& data); 67 | Response DELETE(const std::string& url); 68 | Response HEAD(const std::string& url); 69 | Response OPTIONS(const std::string& url); 70 | 71 | } // namespace RestClient 72 | 73 | #endif // INCLUDE_RESTCLIENT_CPP_RESTCLIENT_H_ 74 | -------------------------------------------------------------------------------- /dep/threads/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | find_package(Threads REQUIRED) 12 | 13 | add_library(threads INTERFACE) 14 | target_link_libraries(threads 15 | INTERFACE 16 | ${CMAKE_THREAD_LIBS_INIT}) 17 | -------------------------------------------------------------------------------- /dep/utf8cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | add_library(utf8cpp INTERFACE) 12 | 13 | target_include_directories(utf8cpp 14 | INTERFACE 15 | .) 16 | -------------------------------------------------------------------------------- /dep/utf8cpp/utf8.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006 Nemanja Trifunovic 2 | 3 | /* 4 | Permission is hereby granted, free of charge, to any person or organization 5 | obtaining a copy of the software and accompanying documentation covered by 6 | this license (the "Software") to use, reproduce, display, distribute, 7 | execute, and transmit the Software, and to prepare derivative works of the 8 | Software, and to permit third-parties to whom the Software is furnished to 9 | do so, all subject to the following: 10 | 11 | The copyright notices in the Software and this entire statement, including 12 | the above license grant, this restriction and the following disclaimer, 13 | must be included in all copies of the Software, in whole or in part, and 14 | all derivative works of the Software, unless such copies or derivative 15 | works are solely in the form of machine-executable object code generated by 16 | a source language processor. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | 28 | #ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 29 | #define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 30 | 31 | #include "utf8/checked.h" 32 | #include "utf8/unchecked.h" 33 | 34 | #endif // header guard 35 | -------------------------------------------------------------------------------- /dep/utf8cpp/utf8/cpp11.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Nemanja Trifunovic 2 | 3 | /* 4 | Permission is hereby granted, free of charge, to any person or organization 5 | obtaining a copy of the software and accompanying documentation covered by 6 | this license (the "Software") to use, reproduce, display, distribute, 7 | execute, and transmit the Software, and to prepare derivative works of the 8 | Software, and to permit third-parties to whom the Software is furnished to 9 | do so, all subject to the following: 10 | 11 | The copyright notices in the Software and this entire statement, including 12 | the above license grant, this restriction and the following disclaimer, 13 | must be included in all copies of the Software, in whole or in part, and 14 | all derivative works of the Software, unless such copies or derivative 15 | works are solely in the form of machine-executable object code generated by 16 | a source language processor. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | 28 | #ifndef UTF8_FOR_CPP_a184c22c_d012_11e8_a8d5_f2801f1b9fd1 29 | #define UTF8_FOR_CPP_a184c22c_d012_11e8_a8d5_f2801f1b9fd1 30 | 31 | #include "checked.h" 32 | #include 33 | 34 | namespace utf8 35 | { 36 | 37 | inline void append(char32_t cp, std::string& s) 38 | { 39 | append(uint32_t(cp), std::back_inserter(s)); 40 | } 41 | 42 | inline std::string utf16to8(const std::u16string& s) 43 | { 44 | std::string result; 45 | utf16to8(s.begin(), s.end(), std::back_inserter(result)); 46 | return result; 47 | } 48 | 49 | inline std::u16string utf8to16(const std::string& s) 50 | { 51 | std::u16string result; 52 | utf8to16(s.begin(), s.end(), std::back_inserter(result)); 53 | return result; 54 | } 55 | 56 | inline std::string utf32to8(const std::u32string& s) 57 | { 58 | std::string result; 59 | utf32to8(s.begin(), s.end(), std::back_inserter(result)); 60 | return result; 61 | } 62 | 63 | inline std::u32string utf8to32(const std::string& s) 64 | { 65 | std::u32string result; 66 | utf8to32(s.begin(), s.end(), std::back_inserter(result)); 67 | return result; 68 | } 69 | 70 | inline std::size_t find_invalid(const std::string& s) 71 | { 72 | std::string::const_iterator invalid = find_invalid(s.begin(), s.end()); 73 | return (invalid == s.end()) ? std::string::npos : static_cast(invalid - s.begin()); 74 | } 75 | 76 | inline bool is_valid(const std::string& s) 77 | { 78 | return is_valid(s.begin(), s.end()); 79 | } 80 | 81 | inline std::string replace_invalid(const std::string& s, char32_t replacement) 82 | { 83 | std::string result; 84 | replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement); 85 | return result; 86 | } 87 | 88 | inline std::string replace_invalid(const std::string& s) 89 | { 90 | std::string result; 91 | replace_invalid(s.begin(), s.end(), std::back_inserter(result)); 92 | return result; 93 | } 94 | 95 | inline bool starts_with_bom(const std::string& s) 96 | { 97 | return starts_with_bom(s.begin(), s.end()); 98 | } 99 | 100 | } // namespace utf8 101 | 102 | #endif // header guard 103 | 104 | -------------------------------------------------------------------------------- /dep/utf8cpp/utf8/cpp17.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Nemanja Trifunovic 2 | 3 | /* 4 | Permission is hereby granted, free of charge, to any person or organization 5 | obtaining a copy of the software and accompanying documentation covered by 6 | this license (the "Software") to use, reproduce, display, distribute, 7 | execute, and transmit the Software, and to prepare derivative works of the 8 | Software, and to permit third-parties to whom the Software is furnished to 9 | do so, all subject to the following: 10 | 11 | The copyright notices in the Software and this entire statement, including 12 | the above license grant, this restriction and the following disclaimer, 13 | must be included in all copies of the Software, in whole or in part, and 14 | all derivative works of the Software, unless such copies or derivative 15 | works are solely in the form of machine-executable object code generated by 16 | a source language processor. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | 28 | #ifndef UTF8_FOR_CPP_7e906c01_03a3_4daf_b420_ea7ea952b3c9 29 | #define UTF8_FOR_CPP_7e906c01_03a3_4daf_b420_ea7ea952b3c9 30 | 31 | #include "checked.h" 32 | #include 33 | 34 | namespace utf8 35 | { 36 | 37 | inline void append(char32_t cp, std::string& s) 38 | { 39 | append(uint32_t(cp), std::back_inserter(s)); 40 | } 41 | 42 | inline std::string utf16to8(std::u16string_view s) 43 | { 44 | std::string result; 45 | utf16to8(s.begin(), s.end(), std::back_inserter(result)); 46 | return result; 47 | } 48 | 49 | inline std::u16string utf8to16(std::string_view s) 50 | { 51 | std::u16string result; 52 | utf8to16(s.begin(), s.end(), std::back_inserter(result)); 53 | return result; 54 | } 55 | 56 | inline std::string utf32to8(std::u32string_view s) 57 | { 58 | std::string result; 59 | utf32to8(s.begin(), s.end(), std::back_inserter(result)); 60 | return result; 61 | } 62 | 63 | inline std::u32string utf8to32(std::string_view s) 64 | { 65 | std::u32string result; 66 | utf8to32(s.begin(), s.end(), std::back_inserter(result)); 67 | return result; 68 | } 69 | 70 | inline std::size_t find_invalid(std::string_view s) 71 | { 72 | std::string_view::const_iterator invalid = find_invalid(s.begin(), s.end()); 73 | return (invalid == s.end()) ? std::string_view::npos : static_cast(invalid - s.begin()); 74 | } 75 | 76 | inline bool is_valid(std::string_view s) 77 | { 78 | return is_valid(s.begin(), s.end()); 79 | } 80 | 81 | inline std::string replace_invalid(std::string_view s, char32_t replacement) 82 | { 83 | std::string result; 84 | replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement); 85 | return result; 86 | } 87 | 88 | inline std::string replace_invalid(std::string_view s) 89 | { 90 | std::string result; 91 | replace_invalid(s.begin(), s.end(), std::back_inserter(result)); 92 | return result; 93 | } 94 | 95 | inline bool starts_with_bom(std::string_view s) 96 | { 97 | return starts_with_bom(s.begin(), s.end()); 98 | } 99 | 100 | } // namespace utf8 101 | 102 | #endif // header guard 103 | 104 | -------------------------------------------------------------------------------- /dep/zlib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of the TrinityCore Project. See AUTHORS file for Copyright information 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | if(UNIX) 12 | # Look for an installed zlib on unix 13 | find_package(ZLIB REQUIRED) 14 | 15 | add_library(zlib SHARED IMPORTED GLOBAL) 16 | 17 | set_target_properties(zlib 18 | PROPERTIES 19 | IMPORTED_LOCATION 20 | "${ZLIB_LIBRARIES}" 21 | INTERFACE_INCLUDE_DIRECTORIES 22 | "${ZLIB_INCLUDE_DIRS}") 23 | else() 24 | # Use the bundled source on windows 25 | SET(zlib_STAT_SRCS 26 | adler32.c 27 | compress.c 28 | crc32.c 29 | deflate.c 30 | infback.c 31 | inffast.c 32 | inflate.c 33 | inftrees.c 34 | trees.c 35 | uncompr.c 36 | zutil.c 37 | ) 38 | 39 | add_library(zlib STATIC 40 | ${zlib_STAT_SRCS}) 41 | 42 | set_target_properties(zlib PROPERTIES LINKER_LANGUAGE CXX) 43 | 44 | target_include_directories(zlib 45 | PUBLIC 46 | .) 47 | 48 | target_link_libraries(zlib 49 | PRIVATE 50 | trinity-dependency-interface) 51 | 52 | set_target_properties(zlib 53 | PROPERTIES 54 | FOLDER 55 | "dep") 56 | endif() 57 | -------------------------------------------------------------------------------- /dep/zlib/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | const uInt max = (uInt)-1; 32 | uLong left; 33 | 34 | left = *destLen; 35 | *destLen = 0; 36 | 37 | stream.zalloc = (alloc_func)0; 38 | stream.zfree = (free_func)0; 39 | stream.opaque = (voidpf)0; 40 | 41 | err = deflateInit(&stream, level); 42 | if (err != Z_OK) return err; 43 | 44 | stream.next_out = dest; 45 | stream.avail_out = 0; 46 | stream.next_in = (z_const Bytef *)source; 47 | stream.avail_in = 0; 48 | 49 | do { 50 | if (stream.avail_out == 0) { 51 | stream.avail_out = left > (uLong)max ? max : (uInt)left; 52 | left -= stream.avail_out; 53 | } 54 | if (stream.avail_in == 0) { 55 | stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen; 56 | sourceLen -= stream.avail_in; 57 | } 58 | err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH); 59 | } while (err == Z_OK); 60 | 61 | *destLen = stream.total_out; 62 | deflateEnd(&stream); 63 | return err == Z_STREAM_END ? Z_OK : err; 64 | } 65 | 66 | /* =========================================================================== 67 | */ 68 | int ZEXPORT compress (dest, destLen, source, sourceLen) 69 | Bytef *dest; 70 | uLongf *destLen; 71 | const Bytef *source; 72 | uLong sourceLen; 73 | { 74 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 75 | } 76 | 77 | /* =========================================================================== 78 | If the default memLevel or windowBits for deflateInit() is changed, then 79 | this function needs to be updated. 80 | */ 81 | uLong ZEXPORT compressBound (sourceLen) 82 | uLong sourceLen; 83 | { 84 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 85 | (sourceLen >> 25) + 13; 86 | } 87 | -------------------------------------------------------------------------------- /dep/zlib/gzclose.c: -------------------------------------------------------------------------------- 1 | /* gzclose.c -- zlib gzclose() function 2 | * Copyright (C) 2004, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "gzguts.h" 7 | 8 | /* gzclose() is in a separate file so that it is linked in only if it is used. 9 | That way the other gzclose functions can be used instead to avoid linking in 10 | unneeded compression or decompression routines. */ 11 | int ZEXPORT gzclose(file) 12 | gzFile file; 13 | { 14 | #ifndef NO_GZCOMPRESS 15 | gz_statep state; 16 | 17 | if (file == NULL) 18 | return Z_STREAM_ERROR; 19 | state = (gz_statep)file; 20 | 21 | return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); 22 | #else 23 | return gzclose_r(file); 24 | #endif 25 | } 26 | -------------------------------------------------------------------------------- /dep/zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /dep/zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is 39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 | codes. These values were found by exhaustive searches using the program 41 | examples/enough.c found in the zlib distribtution. The arguments to that 42 | program are the number of symbols, the initial root table size, and the 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592. 45 | The initial root table size (9 or 6) is found in the fifth argument of the 46 | inflate_table() calls in inflate.c and infback.c. If the root table size is 47 | changed, then these maximum sizes would be need to be recalculated and 48 | updated. */ 49 | #define ENOUGH_LENS 852 50 | #define ENOUGH_DISTS 592 51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 | 53 | /* Type of code to build for inflate_table() */ 54 | typedef enum { 55 | CODES, 56 | LENS, 57 | DISTS 58 | } codetype; 59 | 60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 61 | unsigned codes, code FAR * FAR *table, 62 | unsigned FAR *bits, unsigned short FAR *work)); 63 | -------------------------------------------------------------------------------- /dep/zlib/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. *sourceLen is 13 | the byte length of the source buffer. Upon entry, *destLen is the total size 14 | of the destination buffer, which must be large enough to hold the entire 15 | uncompressed data. (The size of the uncompressed data must have been saved 16 | previously by the compressor and transmitted to the decompressor by some 17 | mechanism outside the scope of this compression library.) Upon exit, 18 | *destLen is the size of the decompressed data and *sourceLen is the number 19 | of source bytes consumed. Upon return, source + *sourceLen points to the 20 | first unused input byte. 21 | 22 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough 23 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, or 24 | Z_DATA_ERROR if the input data was corrupted, including if the input data is 25 | an incomplete zlib stream. 26 | */ 27 | int ZEXPORT uncompress2 (dest, destLen, source, sourceLen) 28 | Bytef *dest; 29 | uLongf *destLen; 30 | const Bytef *source; 31 | uLong *sourceLen; 32 | { 33 | z_stream stream; 34 | int err; 35 | const uInt max = (uInt)-1; 36 | uLong len, left; 37 | Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */ 38 | 39 | len = *sourceLen; 40 | if (*destLen) { 41 | left = *destLen; 42 | *destLen = 0; 43 | } 44 | else { 45 | left = 1; 46 | dest = buf; 47 | } 48 | 49 | stream.next_in = (z_const Bytef *)source; 50 | stream.avail_in = 0; 51 | stream.zalloc = (alloc_func)0; 52 | stream.zfree = (free_func)0; 53 | stream.opaque = (voidpf)0; 54 | 55 | err = inflateInit(&stream); 56 | if (err != Z_OK) return err; 57 | 58 | stream.next_out = dest; 59 | stream.avail_out = 0; 60 | 61 | do { 62 | if (stream.avail_out == 0) { 63 | stream.avail_out = left > (uLong)max ? max : (uInt)left; 64 | left -= stream.avail_out; 65 | } 66 | if (stream.avail_in == 0) { 67 | stream.avail_in = len > (uLong)max ? max : (uInt)len; 68 | len -= stream.avail_in; 69 | } 70 | err = inflate(&stream, Z_NO_FLUSH); 71 | } while (err == Z_OK); 72 | 73 | *sourceLen -= len + stream.avail_in; 74 | if (dest != buf) 75 | *destLen = stream.total_out; 76 | else if (stream.total_out && err == Z_BUF_ERROR) 77 | left = 1; 78 | 79 | inflateEnd(&stream); 80 | return err == Z_STREAM_END ? Z_OK : 81 | err == Z_NEED_DICT ? Z_DATA_ERROR : 82 | err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR : 83 | err; 84 | } 85 | 86 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 87 | Bytef *dest; 88 | uLongf *destLen; 89 | const Bytef *source; 90 | uLong sourceLen; 91 | { 92 | return uncompress2(dest, destLen, source, &sourceLen); 93 | } 94 | -------------------------------------------------------------------------------- /example/helloworld.y: -------------------------------------------------------------------------------- 1 | #!/bin/why 2 | 3 | string fun helloworld(msg) 4 | { 5 | print(msg) 6 | return msg 7 | } -------------------------------------------------------------------------------- /example/readfile.y: -------------------------------------------------------------------------------- 1 | #!/bin/why 2 | 3 | fun readfile(filename) 4 | { 5 | var handler = openfile(filename) 6 | handler.write("something!") 7 | handler.close() 8 | 9 | return true 10 | } -------------------------------------------------------------------------------- /include/Config.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains definitions made in CMakeLists.txt 3 | * that we want available in the source code. 4 | * In the source code, include "exampleConfig.h" (no .in suffix). 5 | * This header file will be generated, and filled with the 6 | * right definition values. Change the namings as you wish, 7 | * but make sure they match up with whats in CMakeLists.txt. 8 | */ 9 | #define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ 10 | #define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@ 11 | #define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@ 12 | #define PROJECT_VERSION_TWEAK @PROJECT_VERSION_TWEAK@ 13 | -------------------------------------------------------------------------------- /include/Dummy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef uint32_t uint32; 5 | /** 6 | * This is a dummy class to demonstrate features of the boiler plate. 7 | */ 8 | 9 | 10 | class Dummy { 11 | public: 12 | 13 | /** 14 | * Default constructor for Dummy (does nothing). 15 | */ 16 | Dummy() = default; 17 | 18 | /** 19 | * Returns a bool. 20 | * @return Always True. 21 | */ 22 | bool DoSomething(); 23 | static void CallBack(); 24 | void Init(uint32_t constAccountId, uint32 constGuid); 25 | 26 | }; 27 | 28 | 29 | -------------------------------------------------------------------------------- /include/Tlog.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by geektcp on 10/9/23. 3 | // 4 | #pragma once 5 | #include "spdlog/spdlog.h" 6 | 7 | 8 | class Tlog { 9 | private: 10 | std::shared_ptr _logger; 11 | 12 | public: 13 | 14 | /** 15 | * Default constructor for Dummy (does nothing). 16 | */ 17 | Tlog() = default; 18 | 19 | /** 20 | * Returns a bool. 21 | * @return Always True. 22 | */ 23 | bool innerLog(){ 24 | spdlog::info("Welcome to Tlog!"); 25 | return false; 26 | } 27 | 28 | bool log(); 29 | }; 30 | 31 | 32 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Revert to first commit, add and commit everything as single commit. 4 | git reset $(git commit-tree HEAD^{tree} -m "Boiler plate for C++ project added") 5 | 6 | name=$(git config user.name) 7 | email=$(git config user.email) 8 | 9 | # If this script is called with an argument, use that as the amended author 10 | # EX: ./setup.sh "Author Name " 11 | if [[ "$1" ]]; then 12 | git commit --amend --author="$1" 13 | else 14 | git commit --amend --author="$name <$email>" 15 | fi 16 | 17 | # Remove the remote (you probably want your own instead). 18 | git remote remove origin 19 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(common) 2 | 3 | 4 | message("CMakeLists.txt load engine ...") 5 | 6 | SET(LIBRARY_NAME engine) 7 | 8 | file(GLOB sources *.cpp *.c *.h) 9 | 10 | add_library(${LIBRARY_NAME} ${sources}) 11 | 12 | include_directories(${CMAKE_HOME_DIRECTORY}/src/log) 13 | 14 | target_include_directories(${LIBRARY_NAME} 15 | PUBLIC 16 | ${PROJECT_SOURCE_DIR}/include 17 | ${PROJECT_SOURCE_DIR}/src/common/CommonBase 18 | ) 19 | 20 | target_link_libraries(${LIBRARY_NAME} 21 | common_base 22 | ) 23 | -------------------------------------------------------------------------------- /src/Dummy.cpp: -------------------------------------------------------------------------------- 1 | #include "Dummy.h" 2 | #include "spdlog/spdlog.h" 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | struct Foo{ 9 | void print_sum(int n1, int n2, int n3){ 10 | std::cout << "sum = " << n1 + n2 + n3 << std::endl; 11 | } 12 | }; 13 | 14 | void print(int &n1, int &n2, int &n3){ 15 | n1++; 16 | n2++; 17 | n3++; 18 | } 19 | 20 | bool Dummy::DoSomething() { 21 | spdlog::info("Welcome to Y !"); 22 | Init(3, 2); 23 | // Do silly things, using some C++17 features to enforce C++17 builds only. 24 | constexpr int digits[2] = {0, 1}; 25 | auto [zero, one] = digits; 26 | return zero + one < 17; 27 | } 28 | 29 | 30 | void Dummy::Init(uint32 constAccountId, uint32 constGuid){ 31 | uint32& accountId = constAccountId; 32 | uint32& guid = constGuid; 33 | spdlog::info("constAccountId: {} | constGuid: {}",constAccountId, constGuid); 34 | spdlog::info("accountId: {} | guid: {}",accountId, guid); 35 | } 36 | 37 | void Dummy::CallBack() 38 | { 39 | Foo foo; 40 | auto callback = std::bind(&Foo::print_sum, &foo, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); 41 | callback(5, 10, 15); 42 | //std::placeholders::_1... // para 43 | 44 | int a = 1, b = 2, c = 3; 45 | auto func2 = std::bind(print, a, b, std::ref(c)); 46 | func2(); 47 | std::cout <<"a = " << a << endl; 48 | cout <<"b = " << b << endl; 49 | cout <<"c = " << c << endl; 50 | }; -------------------------------------------------------------------------------- /src/Tlog.cpp: -------------------------------------------------------------------------------- 1 | #include "spdlog/sinks/stdout_color_sinks.h" 2 | #include "Tlog.h" 3 | #include "spdlog/spdlog.h" 4 | 5 | #define TLOG_INFO Tlog::log() 6 | 7 | bool Tlog::log() { 8 | innerLog( ); 9 | auto console = spdlog::stdout_color_mt("console"); 10 | console->info("Welcome to Y language!"); 11 | // Do silly things, using some C++17 features to enforce C++17 builds only. 12 | constexpr int digits[2] = {0, 1}; 13 | auto [zero, one] = digits; 14 | spdlog::info("Welcome to Y!"); 15 | return zero + one > 3; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(CommonBase) -------------------------------------------------------------------------------- /src/common/CommonBase/Base.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by geektcp on 11/17/23. 3 | // 4 | 5 | -------------------------------------------------------------------------------- /src/common/CommonBase/Base.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by geektcp on 11/17/23. 3 | // 4 | 5 | #ifndef Y_BASE_H 6 | #define Y_BASE_H 7 | 8 | #endif //Y_BASE_H 9 | -------------------------------------------------------------------------------- /src/common/CommonBase/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message("CMakeLists.txt load common_base ...") 2 | 3 | SET(LIBRARY_NAME common_base) 4 | 5 | file(GLOB sources *.cpp *.c *.h) 6 | 7 | add_library(${LIBRARY_NAME} ${sources}) 8 | 9 | 10 | 11 | target_include_directories(${LIBRARY_NAME} 12 | PUBLIC 13 | ${PROJECT_SOURCE_DIR}/include 14 | ${PROJECT_SOURCE_DIR}/src 15 | ${PROJECT_SOURCE_DIR}/dep/log 16 | ${PROJECT_SOURCE_DIR}/dep/httplib 17 | ${PROJECT_SOURCE_DIR}/dep/restclient 18 | ${PROJECT_SOURCE_DIR}/dep/jsonlib 19 | ${PROJECT_SOURCE_DIR}/dep/httprequest 20 | ) 21 | 22 | target_link_libraries(${LIBRARY_NAME} 23 | boost 24 | spd_log 25 | json_lib 26 | http_request 27 | ) 28 | --------------------------------------------------------------------------------