├── .gitattributes ├── .gitignore ├── .vscode └── launch.json ├── CMakeLists.txt ├── LICENSE ├── README.md ├── WinQuickUpdater.code-workspace ├── create_vs_project.bat ├── extern ├── include │ ├── cxxopts.hpp │ ├── d3d9 │ │ ├── D3DCSX.h │ │ ├── D3DX_DXGIFormatConvert.inl │ │ ├── D3Dcommon.h │ │ ├── D3Dcompiler.h │ │ ├── DXGI.h │ │ ├── DXGIFormat.h │ │ ├── DXGIType.h │ │ ├── Dcommon.h │ │ ├── DxErr.h │ │ ├── d3d.h │ │ ├── d3d9.h │ │ ├── d3d9caps.h │ │ ├── d3d9types.h │ │ ├── d3dcaps.h │ │ ├── d3drm.h │ │ ├── d3drmdef.h │ │ ├── d3drmobj.h │ │ ├── d3drmwin.h │ │ ├── d3dtypes.h │ │ ├── d3dvec.inl │ │ ├── d3dx.h │ │ ├── d3dx9.h │ │ ├── d3dx9anim.h │ │ ├── d3dx9core.h │ │ ├── d3dx9effect.h │ │ ├── d3dx9math.h │ │ ├── d3dx9math.inl │ │ ├── d3dx9mesh.h │ │ ├── d3dx9shader.h │ │ ├── d3dx9shape.h │ │ ├── d3dx9tex.h │ │ ├── d3dx9xof.h │ │ ├── d3dxcore.h │ │ ├── d3dxerr.h │ │ ├── d3dxmath.h │ │ ├── d3dxmath.inl │ │ ├── d3dxshapes.h │ │ ├── d3dxsprite.h │ │ ├── dxfile.h │ │ ├── dxsdk.inc │ │ ├── dxsdkver.h │ │ ├── dxtlib.h │ │ ├── dxtrans.h │ │ ├── dxva.h │ │ └── qedit.h │ ├── fmt │ │ ├── chrono.h │ │ ├── color.h │ │ ├── compile.h │ │ ├── core.h │ │ ├── format-inl.h │ │ ├── format.h │ │ ├── locale.h │ │ ├── ostream.h │ │ ├── posix.h │ │ ├── printf.h │ │ ├── ranges.h │ │ └── safe-duration-cast.h │ ├── imgui │ │ ├── LICENSE.txt │ │ ├── fonts │ │ │ ├── Cousine-Regular.ttf │ │ │ ├── DroidSans.ttf │ │ │ ├── Karla-Regular.ttf │ │ │ ├── ProggyClean.ttf │ │ │ ├── ProggyTiny.ttf │ │ │ ├── Roboto-Medium.ttf │ │ │ └── binary_to_compressed_c.cpp │ │ ├── imconfig.h │ │ ├── imgui.cpp │ │ ├── imgui.h │ │ ├── imgui_demo.cpp │ │ ├── imgui_draw.cpp │ │ ├── imgui_impl_dx9.cpp │ │ ├── imgui_impl_dx9.h │ │ ├── imgui_impl_win32.cpp │ │ ├── imgui_impl_win32.h │ │ ├── imgui_internal.h │ │ ├── imgui_widgets.cpp │ │ ├── imstb_rectpack.h │ │ ├── imstb_textedit.h │ │ └── imstb_truetype.h │ ├── rapidjson │ │ ├── allocators.h │ │ ├── cursorstreamwrapper.h │ │ ├── document.h │ │ ├── encodedstream.h │ │ ├── encodings.h │ │ ├── error │ │ │ ├── en.h │ │ │ └── error.h │ │ ├── filereadstream.h │ │ ├── filewritestream.h │ │ ├── fwd.h │ │ ├── internal │ │ │ ├── biginteger.h │ │ │ ├── diyfp.h │ │ │ ├── dtoa.h │ │ │ ├── ieee754.h │ │ │ ├── itoa.h │ │ │ ├── meta.h │ │ │ ├── pow10.h │ │ │ ├── regex.h │ │ │ ├── stack.h │ │ │ ├── strfunc.h │ │ │ ├── strtod.h │ │ │ └── swap.h │ │ ├── istreamwrapper.h │ │ ├── memorybuffer.h │ │ ├── memorystream.h │ │ ├── msinttypes │ │ │ ├── inttypes.h │ │ │ └── stdint.h │ │ ├── ostreamwrapper.h │ │ ├── pointer.h │ │ ├── prettywriter.h │ │ ├── rapidjson.h │ │ ├── reader.h │ │ ├── schema.h │ │ ├── stream.h │ │ ├── stringbuffer.h │ │ └── writer.h │ └── spdlog │ │ ├── async.h │ │ ├── async_logger-inl.h │ │ ├── async_logger.h │ │ ├── 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 │ │ ├── pattern_formatter-inl.h │ │ ├── pattern_formatter.h │ │ ├── periodic_worker-inl.h │ │ ├── periodic_worker.h │ │ ├── registry-inl.h │ │ ├── registry.h │ │ ├── synchronous_factory.h │ │ ├── thread_pool-inl.h │ │ └── thread_pool.h │ │ ├── fmt │ │ ├── bin_to_hex.h │ │ ├── fmt.h │ │ └── ostr.h │ │ ├── formatter.h │ │ ├── logger-inl.h │ │ ├── logger.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 │ │ ├── daily_file_sink.h │ │ ├── dist_sink.h │ │ ├── dup_filter_sink.h │ │ ├── msvc_sink.h │ │ ├── null_sink.h │ │ ├── ostream_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 │ │ ├── wincolor_sink-inl.h │ │ └── wincolor_sink.h │ │ ├── spdlog-inl.h │ │ ├── spdlog.h │ │ ├── tweakme.h │ │ └── version.h ├── lib_x64 │ ├── DxErr.lib │ ├── d3d9.lib │ ├── d3dx9.lib │ ├── dinput8.lib │ ├── spdlog.lib │ └── spdlogd.lib └── lib_x86 │ ├── DxErr.lib │ ├── d3d9.lib │ ├── d3dx9.lib │ ├── dinput8.lib │ ├── spdlog.lib │ └── spdlogd.lib ├── include ├── abstract_singleton.hpp ├── application.hpp ├── basic_log.hpp ├── d3d_impl.hpp ├── error_handler.hpp ├── log_helper.hpp ├── main_ui.hpp ├── pch.hpp ├── ui_types.hpp ├── widget.hpp ├── win_updater.hpp └── window.hpp └── src ├── application.cpp ├── d3d_impl.cpp ├── entry.cpp ├── log_helper.cpp ├── main_ui.cpp ├── ui_types.cpp ├── widget.cpp ├── win_updater.cpp └── window.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | *.bat eol=crlf -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Attach", 9 | "type": "cppvsdbg", 10 | "request": "attach", 11 | "processId": "${command:pickProcess}" 12 | }, 13 | { 14 | "name": "Launch", 15 | "type": "cppvsdbg", 16 | "request": "launch", 17 | "program": "${workspaceFolder}/Bin/WinQuickUpdater.exe", 18 | "args": [], 19 | "stopAtEntry": false, 20 | "cwd": "${workspaceFolder}/Bin/", 21 | "environment": [], 22 | "externalConsole": false 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | project(WinQuickUpdater) 3 | 4 | add_definitions(-DFMT_HEADER_ONLY) # fmt 5 | 6 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ../Bin) 7 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ../Bin) 8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ../Bin) 9 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ../Bin) 10 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ../Bin) 11 | 12 | if(MSVC) 13 | set(LIB_RT_SUFFIX "mt") 14 | set(LIB_RT_OPTION "/MT") 15 | 16 | foreach(flag_var CMAKE_C_FLAGS CMAKE_CXX_FLAGS) 17 | foreach(config_name "" DEBUG RELEASE MINSIZEREL RELWITHDEBINFO) 18 | set(var_name "${flag_var}") 19 | 20 | if(NOT "${config_name}" STREQUAL "") 21 | set(var_name "${var_name}_${config_name}") 22 | endif() 23 | 24 | string(REPLACE "/MD" "${LIB_RT_OPTION}" ${var_name} "${${var_name}}") 25 | set(${var_name} "${${var_name}}" CACHE STRING "" FORCE) 26 | endforeach() 27 | endforeach() 28 | 29 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS} ${MT_BUILD}") 30 | endif() 31 | 32 | if (CMAKE_SIZEOF_VOID_P EQUAL 8) 33 | link_directories(${PROJECT_SOURCE_DIR}/extern/lib_x64) 34 | else() 35 | link_directories(${PROJECT_SOURCE_DIR}/extern/lib_x86) 36 | endif() 37 | 38 | include_directories(${PROJECT_SOURCE_DIR}/extern/include) 39 | include_directories(${PROJECT_SOURCE_DIR}/extern/include/imgui) 40 | 41 | file(GLOB HEADERS 42 | "${PROJECT_SOURCE_DIR}/extern/include/imgui/*.h" 43 | "${PROJECT_SOURCE_DIR}/include/*.hpp" 44 | ) 45 | file(GLOB SOURCES 46 | "${PROJECT_SOURCE_DIR}/extern/include/imgui/*.cpp" 47 | "${PROJECT_SOURCE_DIR}/src/*.cpp" 48 | ) 49 | 50 | add_executable( 51 | ${PROJECT_NAME} 52 | ${HEADERS} 53 | ${SOURCES} 54 | ) 55 | 56 | set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) 57 | set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) 58 | set_property(TARGET ${PROJECT_NAME} PROPERTY CMAKE_CXX_EXTENSIONS OFF) 59 | 60 | target_precompile_headers(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include/pch.hpp) 61 | 62 | target_link_libraries( 63 | ${PROJECT_NAME} 64 | d3d9 d3dx9 DxErr dinput8 dwmapi 65 | ) 66 | 67 | SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\"") 68 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 mq1n 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Sample](https://i.imgur.com/ogBL1Wr.png) -------------------------------------------------------------------------------- /WinQuickUpdater.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": { 8 | "workbench.colorCustomizations": { 9 | "activityBar.background": "#203123", 10 | "titleBar.activeBackground": "#2D4531", 11 | "titleBar.activeForeground": "#F9FBFA" 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /create_vs_project.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rmdir /s /q .vs_proj 3 | 4 | mkdir .vs_proj 5 | 6 | pushd .vs_proj 7 | 8 | cmake .. -DCMAKE_BUILD_TYPE=Debug 9 | 10 | popd 11 | 12 | @echo Project make done! 13 | goto :eof 14 | -------------------------------------------------------------------------------- /extern/include/d3d9/Dcommon.h: -------------------------------------------------------------------------------- 1 | //+-------------------------------------------------------------------------- 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | // Abstract: 6 | // Public API definitions for DWrite and D2D 7 | // 8 | //---------------------------------------------------------------------------- 9 | 10 | #ifndef DCOMMON_H_INCLUDED 11 | #define DCOMMON_H_INCLUDED 12 | 13 | // 14 | //These macros are defined in the Windows 7 SDK, however to enable development using the technical preview, 15 | //they are included here temporarily. 16 | // 17 | #ifndef DEFINE_ENUM_FLAG_OPERATORS 18 | #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \ 19 | extern "C++" { \ 20 | inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) | ((int)b)); } \ 21 | inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) |= ((int)b)); } \ 22 | inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) & ((int)b)); } \ 23 | inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) &= ((int)b)); } \ 24 | inline ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((int)a)); } \ 25 | inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) ^ ((int)b)); } \ 26 | inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) ^= ((int)b)); } \ 27 | } 28 | #endif 29 | 30 | #ifndef __field_ecount_opt 31 | #define __field_ecount_opt(x) 32 | #endif 33 | 34 | #ifndef __range 35 | #define __range(x,y) 36 | #endif 37 | 38 | #ifndef __field_ecount 39 | #define __field_ecount(x) 40 | #endif 41 | 42 | /// 43 | /// The measuring method used for text layout. 44 | /// 45 | typedef enum DWRITE_MEASURING_MODE 46 | { 47 | /// 48 | /// Text is measured using glyph ideal metrics whose values are independent to the current display resolution. 49 | /// 50 | DWRITE_MEASURING_MODE_NATURAL, 51 | 52 | /// 53 | /// Text is measured using glyph display compatible metrics whose values tuned for the current display resolution. 54 | /// 55 | DWRITE_MEASURING_MODE_GDI_CLASSIC, 56 | 57 | /// 58 | /// Text is measured using the same glyph display metrics as text measured by GDI using a font 59 | /// created with CLEARTYPE_NATURAL_QUALITY. 60 | /// 61 | DWRITE_MEASURING_MODE_GDI_NATURAL 62 | 63 | } DWRITE_MEASURING_MODE; 64 | 65 | #endif /* DCOMMON_H_INCLUDED */ 66 | -------------------------------------------------------------------------------- /extern/include/d3d9/DxErr.h: -------------------------------------------------------------------------------- 1 | /*==========================================================================; 2 | * 3 | * 4 | * File: dxerr.h 5 | * Content: DirectX Error Library Include File 6 | * 7 | ****************************************************************************/ 8 | 9 | #ifndef _DXERR_H_ 10 | #define _DXERR_H_ 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif //__cplusplus 15 | 16 | // 17 | // DXGetErrorString 18 | // 19 | // Desc: Converts a DirectX HRESULT to a string 20 | // 21 | // Args: HRESULT hr Can be any error code from 22 | // XACT XAUDIO2 XAPO XINPUT DXGI D3D10 D3DX10 D3D9 D3DX9 DDRAW DSOUND DINPUT DSHOW 23 | // 24 | // Return: Converted string 25 | // 26 | const char* WINAPI DXGetErrorStringA(__in HRESULT hr); 27 | const WCHAR* WINAPI DXGetErrorStringW(__in HRESULT hr); 28 | 29 | #ifdef UNICODE 30 | #define DXGetErrorString DXGetErrorStringW 31 | #else 32 | #define DXGetErrorString DXGetErrorStringA 33 | #endif 34 | 35 | 36 | // 37 | // DXGetErrorDescription 38 | // 39 | // Desc: Returns a string description of a DirectX HRESULT 40 | // 41 | // Args: HRESULT hr Can be any error code from 42 | // XACT XAUDIO2 XAPO XINPUT DXGI D3D10 D3DX10 D3D9 D3DX9 DDRAW DSOUND DINPUT DSHOW 43 | // 44 | // Return: String description 45 | // 46 | const char* WINAPI DXGetErrorDescriptionA(__in HRESULT hr); 47 | const WCHAR* WINAPI DXGetErrorDescriptionW(__in HRESULT hr); 48 | 49 | #ifdef UNICODE 50 | #define DXGetErrorDescription DXGetErrorDescriptionW 51 | #else 52 | #define DXGetErrorDescription DXGetErrorDescriptionA 53 | #endif 54 | 55 | 56 | // 57 | // DXTrace 58 | // 59 | // Desc: Outputs a formatted error message to the debug stream 60 | // 61 | // Args: CHAR* strFile The current file, typically passed in using the 62 | // __FILE__ macro. 63 | // DWORD dwLine The current line number, typically passed in using the 64 | // __LINE__ macro. 65 | // HRESULT hr An HRESULT that will be traced to the debug stream. 66 | // CHAR* strMsg A string that will be traced to the debug stream (may be NULL) 67 | // BOOL bPopMsgBox If TRUE, then a message box will popup also containing the passed info. 68 | // 69 | // Return: The hr that was passed in. 70 | // 71 | HRESULT WINAPI DXTraceA( __in_z const char* strFile, __in DWORD dwLine, __in HRESULT hr, __in_z_opt const char* strMsg, __in BOOL bPopMsgBox ); 72 | HRESULT WINAPI DXTraceW( __in_z const char* strFile, __in DWORD dwLine, __in HRESULT hr, __in_z_opt const WCHAR* strMsg, __in BOOL bPopMsgBox ); 73 | 74 | #ifdef UNICODE 75 | #define DXTrace DXTraceW 76 | #else 77 | #define DXTrace DXTraceA 78 | #endif 79 | 80 | 81 | // 82 | // Helper macros 83 | // 84 | #if defined(DEBUG) | defined(_DEBUG) 85 | #define DXTRACE_MSG(str) DXTrace( __FILE__, (DWORD)__LINE__, 0, str, FALSE ) 86 | #define DXTRACE_ERR(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, FALSE ) 87 | #define DXTRACE_ERR_MSGBOX(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, TRUE ) 88 | #else 89 | #define DXTRACE_MSG(str) (0L) 90 | #define DXTRACE_ERR(str,hr) (hr) 91 | #define DXTRACE_ERR_MSGBOX(str,hr) (hr) 92 | #endif 93 | 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif //__cplusplus 98 | 99 | #endif // _DXERR_H_ 100 | -------------------------------------------------------------------------------- /extern/include/d3d9/d3drmwin.h: -------------------------------------------------------------------------------- 1 | /*==========================================================================; 2 | * 3 | * Copyright (C) 1995-1997 Microsoft Corporation. All Rights Reserved. 4 | * 5 | * File: d3drm.h 6 | * Content: Direct3DRM include file 7 | * 8 | ***************************************************************************/ 9 | 10 | #ifndef __D3DRMWIN_H__ 11 | #define __D3DRMWIN_H__ 12 | 13 | #ifndef WIN32 14 | #define WIN32 15 | #endif 16 | 17 | #include "d3drm.h" 18 | 19 | #include "ddraw.h" 20 | #include "d3d.h" 21 | 22 | /* 23 | * GUIDS used by Direct3DRM Windows interface 24 | */ 25 | DEFINE_GUID(IID_IDirect3DRMWinDevice, 0xc5016cc0, 0xd273, 0x11ce, 0xac, 0x48, 0x0, 0x0, 0xc0, 0x38, 0x25, 0xa1); 26 | 27 | WIN_TYPES(IDirect3DRMWinDevice, DIRECT3DRMWINDEVICE); 28 | 29 | #undef INTERFACE 30 | #define INTERFACE IDirect3DRMWinDevice 31 | 32 | DECLARE_INTERFACE_(IDirect3DRMWinDevice, IDirect3DRMObject) 33 | { 34 | IUNKNOWN_METHODS(PURE); 35 | IDIRECT3DRMOBJECT_METHODS(PURE); 36 | 37 | /* 38 | * IDirect3DRMWinDevice methods 39 | */ 40 | 41 | /* Repaint the window with the last frame which was rendered. */ 42 | STDMETHOD(HandlePaint)(THIS_ HDC hdc) PURE; 43 | 44 | /* Respond to a WM_ACTIVATE message. */ 45 | STDMETHOD(HandleActivate)(THIS_ WORD wparam) PURE; 46 | }; 47 | 48 | 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /extern/include/d3d9/d3dx.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx.h 6 | // Content: D3DX utility library 7 | // 8 | /////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifndef __D3DX_H__ 11 | #define __D3DX_H__ 12 | 13 | #ifndef D3DXINLINE 14 | #ifdef __cplusplus 15 | #define D3DXINLINE inline 16 | #else 17 | #define D3DXINLINE _inline 18 | #endif 19 | #endif 20 | 21 | #include "d3dxcore.h" 22 | #include "d3dxmath.h" 23 | #include "d3dxshapes.h" 24 | #include "d3dxsprite.h" 25 | 26 | #endif //__D3DX_H__ 27 | -------------------------------------------------------------------------------- /extern/include/d3d9/d3dx9.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9.h 6 | // Content: D3DX utility library 7 | // 8 | ////////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifdef __D3DX_INTERNAL__ 11 | #error Incorrect D3DX header used 12 | #endif 13 | 14 | #ifndef __D3DX9_H__ 15 | #define __D3DX9_H__ 16 | 17 | 18 | // Defines 19 | #include 20 | 21 | #define D3DX_DEFAULT ((UINT) -1) 22 | #define D3DX_DEFAULT_NONPOW2 ((UINT) -2) 23 | #define D3DX_DEFAULT_FLOAT FLT_MAX 24 | #define D3DX_FROM_FILE ((UINT) -3) 25 | #define D3DFMT_FROM_FILE ((D3DFORMAT) -3) 26 | 27 | #ifndef D3DXINLINE 28 | #ifdef _MSC_VER 29 | #if (_MSC_VER >= 1200) 30 | #define D3DXINLINE __forceinline 31 | #else 32 | #define D3DXINLINE __inline 33 | #endif 34 | #else 35 | #ifdef __cplusplus 36 | #define D3DXINLINE inline 37 | #else 38 | #define D3DXINLINE 39 | #endif 40 | #endif 41 | #endif 42 | 43 | 44 | 45 | // Includes 46 | #include "d3d9.h" 47 | #include "d3dx9math.h" 48 | #include "d3dx9core.h" 49 | #include "d3dx9xof.h" 50 | #include "d3dx9mesh.h" 51 | #include "d3dx9shader.h" 52 | #include "d3dx9effect.h" 53 | 54 | #include "d3dx9tex.h" 55 | #include "d3dx9shape.h" 56 | #include "d3dx9anim.h" 57 | 58 | 59 | 60 | // Errors 61 | #define _FACDD 0x876 62 | #define MAKE_DDHRESULT( code ) MAKE_HRESULT( 1, _FACDD, code ) 63 | 64 | enum _D3DXERR { 65 | D3DXERR_CANNOTMODIFYINDEXBUFFER = MAKE_DDHRESULT(2900), 66 | D3DXERR_INVALIDMESH = MAKE_DDHRESULT(2901), 67 | D3DXERR_CANNOTATTRSORT = MAKE_DDHRESULT(2902), 68 | D3DXERR_SKINNINGNOTSUPPORTED = MAKE_DDHRESULT(2903), 69 | D3DXERR_TOOMANYINFLUENCES = MAKE_DDHRESULT(2904), 70 | D3DXERR_INVALIDDATA = MAKE_DDHRESULT(2905), 71 | D3DXERR_LOADEDMESHASNODATA = MAKE_DDHRESULT(2906), 72 | D3DXERR_DUPLICATENAMEDFRAGMENT = MAKE_DDHRESULT(2907), 73 | D3DXERR_CANNOTREMOVELASTITEM = MAKE_DDHRESULT(2908), 74 | }; 75 | 76 | 77 | #endif //__D3DX9_H__ 78 | 79 | -------------------------------------------------------------------------------- /extern/include/d3d9/dxsdk.inc: -------------------------------------------------------------------------------- 1 | !IFDEF BORLAND 2 | cc = bcc32 3 | rc = brc32 4 | link = ilink32 5 | bldlib = tlib 6 | cflags = -c -3 -j1 -X -Vd -I$(INCLUDE) 7 | rcflags = -r -fo 8 | linkflags = -n -V4.0 -aa 9 | !IFDEF main 10 | linkflags = $(linkflags) -ap 11 | borobjs=c0x32.obj 12 | !ELSE 13 | linkflags = $(linkflags) -Tpe 14 | borobjs=c0w32.obj 15 | !ENDIF 16 | linkflags = $(linkflags) -j$(LIB) -L$(LIB) 17 | libflags=$(OBJ_DIR)\$(proj).lib 18 | outobj = -o 19 | commas =, 20 | outexe= 21 | borlib=+ 22 | deflibs = import32.lib cw32mti.lib ole2w32.lib 23 | !IFDEF MFC 24 | cflags =$(cflags) -VF -w-hid -w-par -w-aus -w-inl -w-inq -WM -Vd /D_NO_VCL;_RTLDLL;_AFXDLL;_X86_;_WINDOWS;_MSC_VER=1100;WIN32; 25 | !IFDEF NODEBUG 26 | deflibs = bfc42.lib bfcs42.lib $(deflibs) 27 | !ELSE 28 | deflibs = BFC42D.lib BFCS42D.lib bfcd42d.lib bfco42d.lib bfcn42d.lib $(deflibs) 29 | !ENDIF 30 | !ENDIF 31 | 32 | d3dframe=..\..\lib\borland\d3dframe.lib 33 | 34 | !IFDEF nodebug 35 | cdebug = -Od 36 | linkdebug = /x 37 | cflags = $(cflags) /DNDEBUG; 38 | !ELSE 39 | cdebug = -Od -v -y 40 | linkdebug = /v 41 | cflags = $(cflags) /DDEBUG; 42 | !ENDIF 43 | 44 | !ELSE 45 | !IFDEF WATCOM 46 | cc = cl 47 | rc = rc 48 | link = link 49 | bldlib = lib 50 | deflibs = kernel32.lib gdi32.lib user32.lib advapi32.lib gdi32.lib comdlg32.lib winspool.lib shell32.lib winmm.lib comctl32.lib ole32.lib oleaut32.lib 51 | cflags = -c /D "WIN32" /D "_WINDOWS" 52 | !IFDEF NODEBUG 53 | cflags =$(cflags) /D "NDEBUG" 54 | cdebug = -Ox 55 | linkdebug = 56 | !IFDEF MFC 57 | cflags =$(cflags) /MD /D "_AFXDLL" 58 | !ELSE 59 | cflags =$(cflags) /ML 60 | !ENDIF 61 | !ELSE 62 | cflags =$(cflags) /D "DEBUG" 63 | cdebug = -Z7 -Ox 64 | linkdebug = -map -debug:full 65 | !IFDEF MFC 66 | cflags =$(cflags) /MDd /D "_AFXDLL" 67 | !ELSE 68 | cflags =$(cflags) /MLd 69 | !ENDIF 70 | !ENDIF 71 | rcflags = -r -fo 72 | linkflags = /INCREMENTAL:NO /NOLOGO 73 | !IFDEF main 74 | linkflags = $(linkflags) /SUBSYSTEM:CONSOLE 75 | !ELSE 76 | linkflags = $(linkflags) /SUBSYSTEM:WINDOWS 77 | !ENDIF 78 | libflags=/OUT:$(OBJ_DIR)\$(proj).lib 79 | outobj = -Fo 80 | commas= 81 | outexe=-out: 82 | borobjs= 83 | borlib= 84 | d3dframe=..\..\lib\watcom\d3dframe.lib 85 | 86 | !ELSE 87 | cc = cl 88 | rc = rc 89 | link = link 90 | bldlib = lib 91 | deflibs = kernel32.lib gdi32.lib user32.lib advapi32.lib gdi32.lib comdlg32.lib winspool.lib shell32.lib winmm.lib comctl32.lib ole32.lib oleaut32.lib 92 | cflags = -c /D "WIN32" /D "_WINDOWS" 93 | linkflags= 94 | !IFDEF NODEBUG 95 | cflags =$(cflags) /D "NDEBUG" 96 | cdebug = -Ox 97 | linkdebug = /RELEASE 98 | !IFDEF MFC 99 | cflags =$(cflags) /MD /D "_AFXDLL" 100 | !ELSE 101 | cflags =$(cflags) /ML 102 | !ENDIF 103 | !ELSE 104 | cflags = $(cflags) /D "DEBUG" 105 | cdebug = -Z7 -Ox 106 | linkdebug = -map -debug:full -debugtype:cv 107 | !IFDEF MFC 108 | cflags =$(cflags) /MDd /D "_AFXDLL" 109 | !ELSE 110 | linkflags = $(linkflags) /NODEFAULTLIB:LIBC 111 | cflags =$(cflags) /MLd 112 | !ENDIF 113 | !ENDIF 114 | cflags =$(cflags) 115 | rcflags = -r -fo 116 | linkflags = $(linkflags) /INCREMENTAL:NO /PDB:NONE /NOLOGO 117 | !IFDEF main 118 | linkflags = $(linkflags) /SUBSYSTEM:CONSOLE 119 | !ELSE 120 | linkflags = $(linkflags) /SUBSYSTEM:WINDOWS 121 | !ENDIF 122 | libflags=/OUT:$(OBJ_DIR)\$(proj).lib /SUBSYSTEM:WINDOWS 123 | outobj = -Fo 124 | commas= 125 | outexe=-out: 126 | borobjs= 127 | borlib= 128 | d3dframe=..\..\lib\d3dframe.lib 129 | 130 | !ENDIF 131 | !ENDIF 132 | -------------------------------------------------------------------------------- /extern/include/d3d9/dxsdkver.h: -------------------------------------------------------------------------------- 1 | /*==========================================================================; 2 | * 3 | * 4 | * File: dxsdkver.h 5 | * Content: DirectX SDK Version Include File 6 | * 7 | ****************************************************************************/ 8 | 9 | #ifndef _DXSDKVER_H_ 10 | #define _DXSDKVER_H_ 11 | 12 | #define _DXSDK_PRODUCT_MAJOR 9 13 | #define _DXSDK_PRODUCT_MINOR 29 14 | #define _DXSDK_BUILD_MAJOR 1962 15 | #define _DXSDK_BUILD_MINOR 0 16 | 17 | #endif // _DXSDKVER_H_ 18 | 19 | -------------------------------------------------------------------------------- /extern/include/fmt/locale.h: -------------------------------------------------------------------------------- 1 | // Formatting library for C++ - std::locale support 2 | // 3 | // Copyright (c) 2012 - present, Victor Zverovich 4 | // All rights reserved. 5 | // 6 | // For the license information refer to format.h. 7 | 8 | #ifndef FMT_LOCALE_H_ 9 | #define FMT_LOCALE_H_ 10 | 11 | #include 12 | #include "format.h" 13 | 14 | FMT_BEGIN_NAMESPACE 15 | 16 | namespace internal { 17 | template 18 | typename buffer_context::iterator vformat_to( 19 | const std::locale& loc, buffer& buf, 20 | basic_string_view format_str, 21 | basic_format_args> args) { 22 | using range = buffer_range; 23 | return vformat_to>(buf, to_string_view(format_str), args, 24 | internal::locale_ref(loc)); 25 | } 26 | 27 | template 28 | std::basic_string vformat(const std::locale& loc, 29 | basic_string_view format_str, 30 | basic_format_args> args) { 31 | basic_memory_buffer buffer; 32 | internal::vformat_to(loc, buffer, format_str, args); 33 | return fmt::to_string(buffer); 34 | } 35 | } // namespace internal 36 | 37 | template > 38 | inline std::basic_string vformat( 39 | const std::locale& loc, const S& format_str, 40 | basic_format_args> args) { 41 | return internal::vformat(loc, to_string_view(format_str), args); 42 | } 43 | 44 | template > 45 | inline std::basic_string format(const std::locale& loc, 46 | const S& format_str, Args&&... args) { 47 | return internal::vformat( 48 | loc, to_string_view(format_str), 49 | {internal::make_args_checked(format_str, args...)}); 50 | } 51 | 52 | template ::value, char_t>> 55 | inline OutputIt vformat_to(OutputIt out, const std::locale& loc, 56 | const S& format_str, 57 | format_args_t args) { 58 | using range = internal::output_range; 59 | return vformat_to>( 60 | range(out), to_string_view(format_str), args, internal::locale_ref(loc)); 61 | } 62 | 63 | template ::value&& 65 | internal::is_string::value)> 66 | inline OutputIt format_to(OutputIt out, const std::locale& loc, 67 | const S& format_str, Args&&... args) { 68 | internal::check_format_string(format_str); 69 | using context = format_context_t>; 70 | format_arg_store as{args...}; 71 | return vformat_to(out, loc, to_string_view(format_str), 72 | basic_format_args(as)); 73 | } 74 | 75 | FMT_END_NAMESPACE 76 | 77 | #endif // FMT_LOCALE_H_ 78 | -------------------------------------------------------------------------------- /extern/include/imgui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2020 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /extern/include/imgui/fonts/Cousine-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/include/imgui/fonts/Cousine-Regular.ttf -------------------------------------------------------------------------------- /extern/include/imgui/fonts/DroidSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/include/imgui/fonts/DroidSans.ttf -------------------------------------------------------------------------------- /extern/include/imgui/fonts/Karla-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/include/imgui/fonts/Karla-Regular.ttf -------------------------------------------------------------------------------- /extern/include/imgui/fonts/ProggyClean.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/include/imgui/fonts/ProggyClean.ttf -------------------------------------------------------------------------------- /extern/include/imgui/fonts/ProggyTiny.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/include/imgui/fonts/ProggyTiny.ttf -------------------------------------------------------------------------------- /extern/include/imgui/fonts/Roboto-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/include/imgui/fonts/Roboto-Medium.ttf -------------------------------------------------------------------------------- /extern/include/imgui/imgui_impl_dx9.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for DirectX9 2 | // This needs to be used along with a Platform Binding (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 7 | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. 8 | 9 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 10 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 11 | // https://github.com/ocornut/imgui 12 | 13 | #pragma once 14 | #include "imgui.h" // IMGUI_IMPL_API 15 | 16 | struct IDirect3DDevice9; 17 | 18 | IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device); 19 | IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown(); 20 | IMGUI_IMPL_API void ImGui_ImplDX9_NewFrame(); 21 | IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data); 22 | 23 | // Use if you want to reset your rendering device without losing Dear ImGui state. 24 | IMGUI_IMPL_API bool ImGui_ImplDX9_CreateDeviceObjects(); 25 | IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects(); 26 | -------------------------------------------------------------------------------- /extern/include/imgui/imgui_impl_win32.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for Windows (standard windows API for 32 and 64 bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) 6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 7 | // [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE). 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 10 | 11 | #pragma once 12 | #include "imgui.h" // IMGUI_IMPL_API 13 | 14 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 15 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 16 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 17 | 18 | // Configuration 19 | // - Disable gamepad support or linking with xinput.lib 20 | //#define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 21 | //#define IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT 22 | 23 | // Win32 message handler your application need to call. 24 | // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. 25 | // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. 26 | #if 0 27 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 28 | #endif 29 | 30 | // DPI-related helpers (optional) 31 | // - Use to enable DPI awareness without having to create an application manifest. 32 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 33 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 34 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 35 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 36 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); 37 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd 38 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor 39 | -------------------------------------------------------------------------------- /extern/include/rapidjson/cursorstreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_CURSORSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_CURSORSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | 20 | #if defined(__GNUC__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | 25 | #if defined(_MSC_VER) && _MSC_VER <= 1800 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(4702) // unreachable code 28 | RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 29 | #endif 30 | 31 | RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | 34 | //! Cursor stream wrapper for counting line and column number if error exists. 35 | /*! 36 | \tparam InputStream Any stream that implements Stream Concept 37 | */ 38 | template > 39 | class CursorStreamWrapper : public GenericStreamWrapper { 40 | public: 41 | typedef typename Encoding::Ch Ch; 42 | 43 | CursorStreamWrapper(InputStream& is): 44 | GenericStreamWrapper(is), line_(1), col_(0) {} 45 | 46 | // counting line and column number 47 | Ch Take() { 48 | Ch ch = this->is_.Take(); 49 | if(ch == '\n') { 50 | line_ ++; 51 | col_ = 0; 52 | } else { 53 | col_ ++; 54 | } 55 | return ch; 56 | } 57 | 58 | //! Get the error line number, if error exists. 59 | size_t GetLine() const { return line_; } 60 | //! Get the error column number, if error exists. 61 | size_t GetColumn() const { return col_; } 62 | 63 | private: 64 | size_t line_; //!< Current Line 65 | size_t col_; //!< Current Column 66 | }; 67 | 68 | #if defined(_MSC_VER) && _MSC_VER <= 1800 69 | RAPIDJSON_DIAG_POP 70 | #endif 71 | 72 | #if defined(__GNUC__) 73 | RAPIDJSON_DIAG_POP 74 | #endif 75 | 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_ 79 | -------------------------------------------------------------------------------- /extern/include/rapidjson/error/en.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_ERROR_EN_H_ 16 | #define RAPIDJSON_ERROR_EN_H_ 17 | 18 | #include "error.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(switch-enum) 23 | RAPIDJSON_DIAG_OFF(covered-switch-default) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Maps error code of parsing into error message. 29 | /*! 30 | \ingroup RAPIDJSON_ERRORS 31 | \param parseErrorCode Error code obtained in parsing. 32 | \return the error message. 33 | \note User can make a copy of this function for localization. 34 | Using switch-case is safer for future modification of error codes. 35 | */ 36 | inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) { 37 | switch (parseErrorCode) { 38 | case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error."); 39 | 40 | case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty."); 41 | case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values."); 42 | 43 | case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value."); 44 | 45 | case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member."); 46 | case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member."); 47 | case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member."); 48 | 49 | case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element."); 50 | 51 | case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string."); 52 | case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid."); 53 | case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string."); 54 | case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string."); 55 | case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string."); 56 | 57 | case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double."); 58 | case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number."); 59 | case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number."); 60 | 61 | case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error."); 62 | case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error."); 63 | 64 | default: return RAPIDJSON_ERROR_STRING("Unknown error."); 65 | } 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #ifdef __clang__ 71 | RAPIDJSON_DIAG_POP 72 | #endif 73 | 74 | #endif // RAPIDJSON_ERROR_EN_H_ 75 | -------------------------------------------------------------------------------- /extern/include/rapidjson/filereadstream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_FILEREADSTREAM_H_ 16 | #define RAPIDJSON_FILEREADSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | RAPIDJSON_DIAG_OFF(unreachable-code) 25 | RAPIDJSON_DIAG_OFF(missing-noreturn) 26 | #endif 27 | 28 | RAPIDJSON_NAMESPACE_BEGIN 29 | 30 | //! File byte stream for input using fread(). 31 | /*! 32 | \note implements Stream concept 33 | */ 34 | class FileReadStream { 35 | public: 36 | typedef char Ch; //!< Character type (byte). 37 | 38 | //! Constructor. 39 | /*! 40 | \param fp File pointer opened for read. 41 | \param buffer user-supplied buffer. 42 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 43 | */ 44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 45 | RAPIDJSON_ASSERT(fp_ != 0); 46 | RAPIDJSON_ASSERT(bufferSize >= 4); 47 | Read(); 48 | } 49 | 50 | Ch Peek() const { return *current_; } 51 | Ch Take() { Ch c = *current_; Read(); return c; } 52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 53 | 54 | // Not implemented 55 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 56 | void Flush() { RAPIDJSON_ASSERT(false); } 57 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 58 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 59 | 60 | // For encoding detection only. 61 | const Ch* Peek4() const { 62 | return (current_ + 4 <= bufferLast_) ? current_ : 0; 63 | } 64 | 65 | private: 66 | void Read() { 67 | if (current_ < bufferLast_) 68 | ++current_; 69 | else if (!eof_) { 70 | count_ += readCount_; 71 | readCount_ = std::fread(buffer_, 1, bufferSize_, fp_); 72 | bufferLast_ = buffer_ + readCount_ - 1; 73 | current_ = buffer_; 74 | 75 | if (readCount_ < bufferSize_) { 76 | buffer_[readCount_] = '\0'; 77 | ++bufferLast_; 78 | eof_ = true; 79 | } 80 | } 81 | } 82 | 83 | std::FILE* fp_; 84 | Ch *buffer_; 85 | size_t bufferSize_; 86 | Ch *bufferLast_; 87 | Ch *current_; 88 | size_t readCount_; 89 | size_t count_; //!< Number of characters read 90 | bool eof_; 91 | }; 92 | 93 | RAPIDJSON_NAMESPACE_END 94 | 95 | #ifdef __clang__ 96 | RAPIDJSON_DIAG_POP 97 | #endif 98 | 99 | #endif // RAPIDJSON_FILESTREAM_H_ 100 | -------------------------------------------------------------------------------- /extern/include/rapidjson/filewritestream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_FILEWRITESTREAM_H_ 16 | #define RAPIDJSON_FILEWRITESTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(unreachable-code) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of C file stream for output using fwrite(). 29 | /*! 30 | \note implements Stream concept 31 | */ 32 | class FileWriteStream { 33 | public: 34 | typedef char Ch; //!< Character type. Only support char. 35 | 36 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { 37 | RAPIDJSON_ASSERT(fp_ != 0); 38 | } 39 | 40 | void Put(char c) { 41 | if (current_ >= bufferEnd_) 42 | Flush(); 43 | 44 | *current_++ = c; 45 | } 46 | 47 | void PutN(char c, size_t n) { 48 | size_t avail = static_cast(bufferEnd_ - current_); 49 | while (n > avail) { 50 | std::memset(current_, c, avail); 51 | current_ += avail; 52 | Flush(); 53 | n -= avail; 54 | avail = static_cast(bufferEnd_ - current_); 55 | } 56 | 57 | if (n > 0) { 58 | std::memset(current_, c, n); 59 | current_ += n; 60 | } 61 | } 62 | 63 | void Flush() { 64 | if (current_ != buffer_) { 65 | size_t result = std::fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_); 66 | if (result < static_cast(current_ - buffer_)) { 67 | // failure deliberately ignored at this time 68 | // added to avoid warn_unused_result build errors 69 | } 70 | current_ = buffer_; 71 | } 72 | } 73 | 74 | // Not implemented 75 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 76 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 77 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 78 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 79 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 80 | 81 | private: 82 | // Prohibit copy constructor & assignment operator. 83 | FileWriteStream(const FileWriteStream&); 84 | FileWriteStream& operator=(const FileWriteStream&); 85 | 86 | std::FILE* fp_; 87 | char *buffer_; 88 | char *bufferEnd_; 89 | char *current_; 90 | }; 91 | 92 | //! Implement specialized version of PutN() with memset() for better performance. 93 | template<> 94 | inline void PutN(FileWriteStream& stream, char c, size_t n) { 95 | stream.PutN(c, n); 96 | } 97 | 98 | RAPIDJSON_NAMESPACE_END 99 | 100 | #ifdef __clang__ 101 | RAPIDJSON_DIAG_POP 102 | #endif 103 | 104 | #endif // RAPIDJSON_FILESTREAM_H_ 105 | -------------------------------------------------------------------------------- /extern/include/rapidjson/internal/ieee754.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_IEEE754_ 16 | #define RAPIDJSON_IEEE754_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | class Double { 24 | public: 25 | Double() {} 26 | Double(double d) : d_(d) {} 27 | Double(uint64_t u) : u_(u) {} 28 | 29 | double Value() const { return d_; } 30 | uint64_t Uint64Value() const { return u_; } 31 | 32 | double NextPositiveDouble() const { 33 | RAPIDJSON_ASSERT(!Sign()); 34 | return Double(u_ + 1).Value(); 35 | } 36 | 37 | bool Sign() const { return (u_ & kSignMask) != 0; } 38 | uint64_t Significand() const { return u_ & kSignificandMask; } 39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } 40 | 41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } 42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } 43 | bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } 44 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } 45 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } 46 | 47 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } 48 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } 49 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } 50 | 51 | static int EffectiveSignificandSize(int order) { 52 | if (order >= -1021) 53 | return 53; 54 | else if (order <= -1074) 55 | return 0; 56 | else 57 | return order + 1074; 58 | } 59 | 60 | private: 61 | static const int kSignificandSize = 52; 62 | static const int kExponentBias = 0x3FF; 63 | static const int kDenormalExponent = 1 - kExponentBias; 64 | static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); 65 | static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 66 | static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 67 | static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 68 | 69 | union { 70 | double d_; 71 | uint64_t u_; 72 | }; 73 | }; 74 | 75 | } // namespace internal 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_IEEE754_ 79 | -------------------------------------------------------------------------------- /extern/include/rapidjson/internal/pow10.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_POW10_ 16 | #define RAPIDJSON_POW10_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Computes integer powers of 10 in double (10.0^n). 24 | /*! This function uses lookup table for fast and accurate results. 25 | \param n non-negative exponent. Must <= 308. 26 | \return 10.0^n 27 | */ 28 | inline double Pow10(int n) { 29 | static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes 30 | 1e+0, 31 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 32 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, 33 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, 34 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, 35 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, 36 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, 37 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, 38 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, 39 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, 40 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, 41 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, 42 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, 43 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, 44 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, 45 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, 46 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 47 | }; 48 | RAPIDJSON_ASSERT(n >= 0 && n <= 308); 49 | return e[n]; 50 | } 51 | 52 | } // namespace internal 53 | RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // RAPIDJSON_POW10_ 56 | -------------------------------------------------------------------------------- /extern/include/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | #include 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | namespace internal { 23 | 24 | //! Custom strlen() which works on different character types. 25 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 26 | \param s Null-terminated input string. 27 | \return Number of characters in the string. 28 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 29 | */ 30 | template 31 | inline SizeType StrLen(const Ch* s) { 32 | RAPIDJSON_ASSERT(s != 0); 33 | const Ch* p = s; 34 | while (*p) ++p; 35 | return SizeType(p - s); 36 | } 37 | 38 | template <> 39 | inline SizeType StrLen(const char* s) { 40 | return SizeType(std::strlen(s)); 41 | } 42 | 43 | template <> 44 | inline SizeType StrLen(const wchar_t* s) { 45 | return SizeType(std::wcslen(s)); 46 | } 47 | 48 | //! Returns number of code points in a encoded string. 49 | template 50 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 51 | RAPIDJSON_ASSERT(s != 0); 52 | RAPIDJSON_ASSERT(outCount != 0); 53 | GenericStringStream is(s); 54 | const typename Encoding::Ch* end = s + length; 55 | SizeType count = 0; 56 | while (is.src_ < end) { 57 | unsigned codepoint; 58 | if (!Encoding::Decode(is, &codepoint)) 59 | return false; 60 | count++; 61 | } 62 | *outCount = count; 63 | return true; 64 | } 65 | 66 | } // namespace internal 67 | RAPIDJSON_NAMESPACE_END 68 | 69 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 70 | -------------------------------------------------------------------------------- /extern/include/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /extern/include/rapidjson/istreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_ISTREAMWRAPPER_H_ 16 | #define RAPIDJSON_ISTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | #ifdef _MSC_VER 27 | RAPIDJSON_DIAG_PUSH 28 | RAPIDJSON_DIAG_OFF(4351) // new behavior: elements of array 'array' will be default initialized 29 | #endif 30 | 31 | RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | //! Wrapper of \c std::basic_istream into RapidJSON's Stream concept. 34 | /*! 35 | The classes can be wrapped including but not limited to: 36 | 37 | - \c std::istringstream 38 | - \c std::stringstream 39 | - \c std::wistringstream 40 | - \c std::wstringstream 41 | - \c std::ifstream 42 | - \c std::fstream 43 | - \c std::wifstream 44 | - \c std::wfstream 45 | 46 | \tparam StreamType Class derived from \c std::basic_istream. 47 | */ 48 | 49 | template 50 | class BasicIStreamWrapper { 51 | public: 52 | typedef typename StreamType::char_type Ch; 53 | BasicIStreamWrapper(StreamType& stream) : stream_(stream), count_(), peekBuffer_() {} 54 | 55 | Ch Peek() const { 56 | typename StreamType::int_type c = stream_.peek(); 57 | return RAPIDJSON_LIKELY(c != StreamType::traits_type::eof()) ? static_cast(c) : static_cast('\0'); 58 | } 59 | 60 | Ch Take() { 61 | typename StreamType::int_type c = stream_.get(); 62 | if (RAPIDJSON_LIKELY(c != StreamType::traits_type::eof())) { 63 | count_++; 64 | return static_cast(c); 65 | } 66 | else 67 | return '\0'; 68 | } 69 | 70 | // tellg() may return -1 when failed. So we count by ourself. 71 | size_t Tell() const { return count_; } 72 | 73 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 74 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 75 | void Flush() { RAPIDJSON_ASSERT(false); } 76 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 77 | 78 | // For encoding detection only. 79 | const Ch* Peek4() const { 80 | RAPIDJSON_ASSERT(sizeof(Ch) == 1); // Only usable for byte stream. 81 | int i; 82 | bool hasError = false; 83 | for (i = 0; i < 4; ++i) { 84 | typename StreamType::int_type c = stream_.get(); 85 | if (c == StreamType::traits_type::eof()) { 86 | hasError = true; 87 | stream_.clear(); 88 | break; 89 | } 90 | peekBuffer_[i] = static_cast(c); 91 | } 92 | for (--i; i >= 0; --i) 93 | stream_.putback(peekBuffer_[i]); 94 | return !hasError ? peekBuffer_ : 0; 95 | } 96 | 97 | private: 98 | BasicIStreamWrapper(const BasicIStreamWrapper&); 99 | BasicIStreamWrapper& operator=(const BasicIStreamWrapper&); 100 | 101 | StreamType& stream_; 102 | size_t count_; //!< Number of characters read. Note: 103 | mutable Ch peekBuffer_[4]; 104 | }; 105 | 106 | typedef BasicIStreamWrapper IStreamWrapper; 107 | typedef BasicIStreamWrapper WIStreamWrapper; 108 | 109 | #if defined(__clang__) || defined(_MSC_VER) 110 | RAPIDJSON_DIAG_POP 111 | #endif 112 | 113 | RAPIDJSON_NAMESPACE_END 114 | 115 | #endif // RAPIDJSON_ISTREAMWRAPPER_H_ 116 | -------------------------------------------------------------------------------- /extern/include/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYBUFFER_H_ 16 | #define RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /extern/include/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYSTREAM_H_ 16 | #define RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(unreachable-code) 23 | RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Represents an in-memory input byte stream. 29 | /*! 30 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 31 | 32 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 33 | 34 | Differences between MemoryStream and StringStream: 35 | 1. StringStream has encoding but MemoryStream is a byte stream. 36 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 37 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 38 | \note implements Stream concept 39 | */ 40 | struct MemoryStream { 41 | typedef char Ch; // byte 42 | 43 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 44 | 45 | Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 46 | Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 47 | size_t Tell() const { return static_cast(src_ - begin_); } 48 | 49 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 50 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 51 | void Flush() { RAPIDJSON_ASSERT(false); } 52 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 53 | 54 | // For encoding detection only. 55 | const Ch* Peek4() const { 56 | return Tell() + 4 <= size_ ? src_ : 0; 57 | } 58 | 59 | const Ch* src_; //!< Current read position. 60 | const Ch* begin_; //!< Original head of the string. 61 | const Ch* end_; //!< End of stream. 62 | size_t size_; //!< Size of the stream. 63 | }; 64 | 65 | RAPIDJSON_NAMESPACE_END 66 | 67 | #ifdef __clang__ 68 | RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 72 | -------------------------------------------------------------------------------- /extern/include/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_OSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /extern/include/rapidjson/stringbuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_STRINGBUFFER_H_ 16 | #define RAPIDJSON_STRINGBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 22 | #include // std::move 23 | #endif 24 | 25 | #include "internal/stack.h" 26 | 27 | #if defined(__clang__) 28 | RAPIDJSON_DIAG_PUSH 29 | RAPIDJSON_DIAG_OFF(c++98-compat) 30 | #endif 31 | 32 | RAPIDJSON_NAMESPACE_BEGIN 33 | 34 | //! Represents an in-memory output stream. 35 | /*! 36 | \tparam Encoding Encoding of the stream. 37 | \tparam Allocator type for allocating memory buffer. 38 | \note implements Stream concept 39 | */ 40 | template 41 | class GenericStringBuffer { 42 | public: 43 | typedef typename Encoding::Ch Ch; 44 | 45 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 46 | 47 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 48 | GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {} 49 | GenericStringBuffer& operator=(GenericStringBuffer&& rhs) { 50 | if (&rhs != this) 51 | stack_ = std::move(rhs.stack_); 52 | return *this; 53 | } 54 | #endif 55 | 56 | void Put(Ch c) { *stack_.template Push() = c; } 57 | void PutUnsafe(Ch c) { *stack_.template PushUnsafe() = c; } 58 | void Flush() {} 59 | 60 | void Clear() { stack_.Clear(); } 61 | void ShrinkToFit() { 62 | // Push and pop a null terminator. This is safe. 63 | *stack_.template Push() = '\0'; 64 | stack_.ShrinkToFit(); 65 | stack_.template Pop(1); 66 | } 67 | 68 | void Reserve(size_t count) { stack_.template Reserve(count); } 69 | Ch* Push(size_t count) { return stack_.template Push(count); } 70 | Ch* PushUnsafe(size_t count) { return stack_.template PushUnsafe(count); } 71 | void Pop(size_t count) { stack_.template Pop(count); } 72 | 73 | const Ch* GetString() const { 74 | // Push and pop a null terminator. This is safe. 75 | *stack_.template Push() = '\0'; 76 | stack_.template Pop(1); 77 | 78 | return stack_.template Bottom(); 79 | } 80 | 81 | //! Get the size of string in bytes in the string buffer. 82 | size_t GetSize() const { return stack_.GetSize(); } 83 | 84 | //! Get the length of string in Ch in the string buffer. 85 | size_t GetLength() const { return stack_.GetSize() / sizeof(Ch); } 86 | 87 | static const size_t kDefaultCapacity = 256; 88 | mutable internal::Stack stack_; 89 | 90 | private: 91 | // Prohibit copy constructor & assignment operator. 92 | GenericStringBuffer(const GenericStringBuffer&); 93 | GenericStringBuffer& operator=(const GenericStringBuffer&); 94 | }; 95 | 96 | //! String buffer with UTF8 encoding 97 | typedef GenericStringBuffer > StringBuffer; 98 | 99 | template 100 | inline void PutReserve(GenericStringBuffer& stream, size_t count) { 101 | stream.Reserve(count); 102 | } 103 | 104 | template 105 | inline void PutUnsafe(GenericStringBuffer& stream, typename Encoding::Ch c) { 106 | stream.PutUnsafe(c); 107 | } 108 | 109 | //! Implement specialized version of PutN() with memset() for better performance. 110 | template<> 111 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 112 | std::memset(stream.stack_.Push(n), c, n * sizeof(c)); 113 | } 114 | 115 | RAPIDJSON_NAMESPACE_END 116 | 117 | #if defined(__clang__) 118 | RAPIDJSON_DIAG_POP 119 | #endif 120 | 121 | #endif // RAPIDJSON_STRINGBUFFER_H_ 122 | -------------------------------------------------------------------------------- /extern/include/spdlog/async.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 | // 7 | // Async logging using global thread pool 8 | // All loggers created here share same global thread pool. 9 | // Each log message is pushed to a queue along withe a shared pointer to the 10 | // logger. 11 | // If a logger deleted while having pending messages in the queue, it's actual 12 | // destruction will defer 13 | // until all its messages are processed by the thread pool. 14 | // This is because each message in the queue holds a shared_ptr to the 15 | // originating logger. 16 | 17 | #include "spdlog/async_logger.h" 18 | #include "spdlog/details/registry.h" 19 | #include "spdlog/details/thread_pool.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace spdlog { 26 | 27 | namespace details { 28 | static const size_t default_async_q_size = 8192; 29 | } 30 | 31 | // async logger factory - creates async loggers backed with thread pool. 32 | // if a global thread pool doesn't already exist, create it with default queue 33 | // size of 8192 items and single thread. 34 | template 35 | struct async_factory_impl 36 | { 37 | template 38 | static std::shared_ptr create(std::string logger_name, SinkArgs &&... args) 39 | { 40 | auto ®istry_inst = details::registry::instance(); 41 | 42 | // create global thread pool if not already exists.. 43 | 44 | auto &mutex = registry_inst.tp_mutex(); 45 | std::lock_guard tp_lock(mutex); 46 | auto tp = registry_inst.get_tp(); 47 | if (tp == nullptr) 48 | { 49 | tp = std::make_shared(details::default_async_q_size, 1); 50 | registry_inst.set_tp(tp); 51 | } 52 | 53 | auto sink = std::make_shared(std::forward(args)...); 54 | auto new_logger = std::make_shared(std::move(logger_name), std::move(sink), std::move(tp), OverflowPolicy); 55 | registry_inst.initialize_logger(new_logger); 56 | return new_logger; 57 | } 58 | }; 59 | 60 | using async_factory = async_factory_impl; 61 | using async_factory_nonblock = async_factory_impl; 62 | 63 | template 64 | inline std::shared_ptr create_async(std::string logger_name, SinkArgs &&... sink_args) 65 | { 66 | return async_factory::create(std::move(logger_name), std::forward(sink_args)...); 67 | } 68 | 69 | template 70 | inline std::shared_ptr create_async_nb(std::string logger_name, SinkArgs &&... sink_args) 71 | { 72 | return async_factory_nonblock::create(std::move(logger_name), std::forward(sink_args)...); 73 | } 74 | 75 | // set global thread pool. 76 | inline void init_thread_pool(size_t q_size, size_t thread_count, std::function on_thread_start) 77 | { 78 | auto tp = std::make_shared(q_size, thread_count, on_thread_start); 79 | details::registry::instance().set_tp(std::move(tp)); 80 | } 81 | 82 | // set global thread pool. 83 | inline void init_thread_pool(size_t q_size, size_t thread_count) 84 | { 85 | init_thread_pool(q_size, thread_count, [] {}); 86 | } 87 | 88 | // get the global thread pool. 89 | inline std::shared_ptr thread_pool() 90 | { 91 | return details::registry::instance().get_tp(); 92 | } 93 | } // namespace spdlog 94 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/async_logger.h" 8 | #endif 9 | 10 | #include "spdlog/sinks/sink.h" 11 | #include "spdlog/details/thread_pool.h" 12 | 13 | #include 14 | #include 15 | 16 | SPDLOG_INLINE spdlog::async_logger::async_logger( 17 | std::string logger_name, sinks_init_list sinks_list, std::weak_ptr tp, async_overflow_policy overflow_policy) 18 | : async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), std::move(tp), overflow_policy) 19 | {} 20 | 21 | SPDLOG_INLINE spdlog::async_logger::async_logger( 22 | std::string logger_name, sink_ptr single_sink, std::weak_ptr tp, async_overflow_policy overflow_policy) 23 | : async_logger(std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy) 24 | {} 25 | 26 | // send the log message to the thread pool 27 | SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg) 28 | { 29 | if (auto pool_ptr = thread_pool_.lock()) 30 | { 31 | pool_ptr->post_log(shared_from_this(), msg, overflow_policy_); 32 | } 33 | else 34 | { 35 | SPDLOG_THROW(spdlog_ex("async log: thread pool doesn't exist anymore")); 36 | } 37 | } 38 | 39 | // send flush request to the thread pool 40 | SPDLOG_INLINE void spdlog::async_logger::flush_() 41 | { 42 | if (auto pool_ptr = thread_pool_.lock()) 43 | { 44 | pool_ptr->post_flush(shared_from_this(), overflow_policy_); 45 | } 46 | else 47 | { 48 | SPDLOG_THROW(spdlog_ex("async flush: thread pool doesn't exist anymore")); 49 | } 50 | } 51 | 52 | // 53 | // backend functions - called from the thread pool to do the actual job 54 | // 55 | SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg) 56 | { 57 | for (auto &sink : sinks_) 58 | { 59 | if (sink->should_log(msg.level)) 60 | { 61 | SPDLOG_TRY 62 | { 63 | sink->log(msg); 64 | } 65 | SPDLOG_LOGGER_CATCH() 66 | } 67 | } 68 | 69 | if (should_flush_(msg)) 70 | { 71 | backend_flush_(); 72 | } 73 | } 74 | 75 | SPDLOG_INLINE void spdlog::async_logger::backend_flush_() 76 | { 77 | for (auto &sink : sinks_) 78 | { 79 | SPDLOG_TRY 80 | { 81 | sink->flush(); 82 | } 83 | SPDLOG_LOGGER_CATCH() 84 | } 85 | } 86 | 87 | SPDLOG_INLINE std::shared_ptr spdlog::async_logger::clone(std::string new_name) 88 | { 89 | auto cloned = std::make_shared(*this); 90 | cloned->name_ = std::move(new_name); 91 | return cloned; 92 | } 93 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/logger.h" 18 | 19 | namespace spdlog { 20 | 21 | // Async overflow policy - block by default. 22 | enum class async_overflow_policy 23 | { 24 | block, // Block until message can be enqueued 25 | overrun_oldest // Discard oldest message in the queue if full when trying to 26 | // add new item. 27 | }; 28 | 29 | namespace details { 30 | class thread_pool; 31 | } 32 | 33 | class async_logger final : public std::enable_shared_from_this, public logger 34 | { 35 | friend class details::thread_pool; 36 | 37 | public: 38 | template 39 | async_logger(std::string logger_name, It begin, It end, std::weak_ptr tp, 40 | async_overflow_policy overflow_policy = async_overflow_policy::block) 41 | : logger(std::move(logger_name), begin, end) 42 | , thread_pool_(std::move(tp)) 43 | , overflow_policy_(overflow_policy) 44 | {} 45 | 46 | async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr tp, 47 | async_overflow_policy overflow_policy = async_overflow_policy::block); 48 | 49 | async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr tp, 50 | async_overflow_policy overflow_policy = async_overflow_policy::block); 51 | 52 | std::shared_ptr clone(std::string new_name) override; 53 | 54 | protected: 55 | void sink_it_(const details::log_msg &msg) override; 56 | void flush_() override; 57 | void backend_sink_it_(const details::log_msg &incoming_log_msg); 58 | void backend_flush_(); 59 | 60 | private: 61 | std::weak_ptr thread_pool_; 62 | async_overflow_policy overflow_policy_; 63 | }; 64 | } // namespace spdlog 65 | 66 | #ifdef SPDLOG_HEADER_ONLY 67 | #include "async_logger-inl.h" 68 | #endif 69 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/common.h" 8 | #endif 9 | 10 | namespace spdlog { 11 | namespace level { 12 | static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; 13 | 14 | static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; 15 | 16 | SPDLOG_INLINE string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT 17 | { 18 | return level_string_views[l]; 19 | } 20 | 21 | SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT 22 | { 23 | return short_level_names[l]; 24 | } 25 | 26 | SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT 27 | { 28 | int level = 0; 29 | for (const auto &level_str : level_string_views) 30 | { 31 | if (level_str == name) 32 | { 33 | return static_cast(level); 34 | } 35 | level++; 36 | } 37 | return level::off; 38 | } 39 | } // namespace level 40 | 41 | SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg) 42 | : msg_(std::move(msg)) 43 | {} 44 | 45 | SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) 46 | { 47 | memory_buf_t outbuf; 48 | fmt::format_system_error(outbuf, last_errno, msg); 49 | msg_ = fmt::to_string(outbuf); 50 | } 51 | 52 | SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT 53 | { 54 | return msg_.c_str(); 55 | } 56 | 57 | } // namespace spdlog 58 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/backtracer.h" 8 | #endif 9 | namespace spdlog { 10 | namespace details { 11 | SPDLOG_INLINE backtracer::backtracer(const backtracer &other) 12 | { 13 | std::lock_guard lock(other.mutex_); 14 | enabled_ = other.enabled(); 15 | messages_ = other.messages_; 16 | } 17 | 18 | SPDLOG_INLINE backtracer::backtracer(backtracer &&other) SPDLOG_NOEXCEPT 19 | { 20 | std::lock_guard lock(other.mutex_); 21 | enabled_ = other.enabled(); 22 | messages_ = std::move(other.messages_); 23 | } 24 | 25 | SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other) 26 | { 27 | std::lock_guard lock(mutex_); 28 | enabled_ = other.enabled(); 29 | messages_ = other.messages_; 30 | return *this; 31 | } 32 | 33 | SPDLOG_INLINE void backtracer::enable(size_t size) 34 | { 35 | std::lock_guard lock{mutex_}; 36 | enabled_.store(true, std::memory_order_relaxed); 37 | messages_ = circular_q{size}; 38 | } 39 | 40 | SPDLOG_INLINE void backtracer::disable() 41 | { 42 | std::lock_guard lock{mutex_}; 43 | enabled_.store(false, std::memory_order_relaxed); 44 | } 45 | 46 | SPDLOG_INLINE bool backtracer::enabled() const 47 | { 48 | return enabled_.load(std::memory_order_relaxed); 49 | } 50 | 51 | SPDLOG_INLINE backtracer::operator bool() const 52 | { 53 | return enabled(); 54 | } 55 | 56 | SPDLOG_INLINE void backtracer::push_back(const log_msg &msg) 57 | { 58 | std::lock_guard lock{mutex_}; 59 | messages_.push_back(log_msg_buffer{msg}); 60 | } 61 | 62 | // pop all items in the q and apply the given fun on each of them. 63 | SPDLOG_INLINE void backtracer::foreach_pop(std::function fun) 64 | { 65 | std::lock_guard lock{mutex_}; 66 | while (!messages_.empty()) 67 | { 68 | auto &front_msg = messages_.front(); 69 | fun(front_msg); 70 | messages_.pop_front(); 71 | } 72 | } 73 | } // namespace details 74 | } // namespace spdlog 75 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/log_msg_buffer.h" 7 | #include "spdlog/details/circular_q.h" 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 backtracer 19 | { 20 | mutable std::mutex mutex_; 21 | std::atomic enabled_{false}; 22 | circular_q messages_; 23 | 24 | public: 25 | backtracer() = default; 26 | backtracer(const backtracer &other); 27 | 28 | backtracer(backtracer &&other) SPDLOG_NOEXCEPT; 29 | backtracer &operator=(backtracer other); 30 | 31 | void enable(size_t size); 32 | void disable(); 33 | bool enabled() const; 34 | explicit operator bool() const; 35 | void push_back(const log_msg &msg); 36 | 37 | // pop all items in the q and apply the given fun on each of them. 38 | void foreach_pop(std::function fun); 39 | }; 40 | 41 | } // namespace details 42 | } // namespace spdlog 43 | 44 | #ifdef SPDLOG_HEADER_ONLY 45 | #include "backtracer-inl.h" 46 | #endif -------------------------------------------------------------------------------- /extern/include/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 | // cirucal q view of std::vector. 5 | #pragma once 6 | 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | template 12 | class circular_q 13 | { 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 | , v_(max_items_) 29 | {} 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 37 | { 38 | copy_moveable(std::move(other)); 39 | } 40 | 41 | circular_q &operator=(circular_q &&other) SPDLOG_NOEXCEPT 42 | { 43 | copy_moveable(std::move(other)); 44 | return *this; 45 | } 46 | 47 | // push back, overrun (oldest) item if no room left 48 | void push_back(T &&item) 49 | { 50 | if (max_items_ > 0) 51 | { 52 | v_[tail_] = std::move(item); 53 | tail_ = (tail_ + 1) % max_items_; 54 | 55 | if (tail_ == head_) // overrun last item if full 56 | { 57 | head_ = (head_ + 1) % max_items_; 58 | ++overrun_counter_; 59 | } 60 | } 61 | } 62 | 63 | // Return reference to the front item. 64 | // If there are no elements in the container, the behavior is undefined. 65 | const T &front() const 66 | { 67 | return v_[head_]; 68 | } 69 | 70 | T &front() 71 | { 72 | return v_[head_]; 73 | } 74 | 75 | // Pop item from front. 76 | // If there are no elements in the container, the behavior is undefined. 77 | void pop_front() 78 | { 79 | head_ = (head_ + 1) % max_items_; 80 | } 81 | 82 | bool empty() const 83 | { 84 | return tail_ == head_; 85 | } 86 | 87 | bool full() const 88 | { 89 | // head is ahead of the tail by 1 90 | if (max_items_ > 0) 91 | { 92 | return ((tail_ + 1) % max_items_) == head_; 93 | } 94 | return false; 95 | } 96 | 97 | size_t overrun_counter() const 98 | { 99 | return overrun_counter_; 100 | } 101 | 102 | private: 103 | // copy from other&& and reset it to disabled state 104 | void copy_moveable(circular_q &&other) SPDLOG_NOEXCEPT 105 | { 106 | max_items_ = other.max_items_; 107 | head_ = other.head_; 108 | tail_ = other.tail_; 109 | overrun_counter_ = other.overrun_counter_; 110 | v_ = std::move(other.v_); 111 | 112 | // put &&other in disabled, but valid state 113 | other.max_items_ = 0; 114 | other.head_ = other.tail_ = 0; 115 | other.overrun_counter_ = 0; 116 | } 117 | }; 118 | } // namespace details 119 | } // namespace spdlog 120 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/null_mutex.h" 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | 12 | struct console_mutex 13 | { 14 | using mutex_t = std::mutex; 15 | static mutex_t &mutex() 16 | { 17 | static mutex_t s_mutex; 18 | return s_mutex; 19 | } 20 | }; 21 | 22 | struct console_nullmutex 23 | { 24 | using mutex_t = null_mutex; 25 | static mutex_t &mutex() 26 | { 27 | static mutex_t s_mutex; 28 | return s_mutex; 29 | } 30 | }; 31 | } // namespace details 32 | } // namespace spdlog 33 | -------------------------------------------------------------------------------- /extern/include/spdlog/details/file_helper-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 "spdlog/details/file_helper.h" 8 | #endif 9 | 10 | #include "spdlog/details/os.h" 11 | #include "spdlog/common.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace spdlog { 21 | namespace details { 22 | 23 | SPDLOG_INLINE file_helper::~file_helper() 24 | { 25 | close(); 26 | } 27 | 28 | SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate) 29 | { 30 | close(); 31 | auto *mode = truncate ? SPDLOG_FILENAME_T("wb") : SPDLOG_FILENAME_T("ab"); 32 | _filename = fname; 33 | for (int tries = 0; tries < open_tries; ++tries) 34 | { 35 | if (!os::fopen_s(&fd_, fname, mode)) 36 | { 37 | return; 38 | } 39 | 40 | details::os::sleep_for_millis(open_interval); 41 | } 42 | 43 | SPDLOG_THROW(spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno)); 44 | } 45 | 46 | SPDLOG_INLINE void file_helper::reopen(bool truncate) 47 | { 48 | if (_filename.empty()) 49 | { 50 | SPDLOG_THROW(spdlog_ex("Failed re opening file - was not opened before")); 51 | } 52 | open(_filename, truncate); 53 | } 54 | 55 | SPDLOG_INLINE void file_helper::flush() 56 | { 57 | std::fflush(fd_); 58 | } 59 | 60 | SPDLOG_INLINE void file_helper::close() 61 | { 62 | if (fd_ != nullptr) 63 | { 64 | std::fclose(fd_); 65 | fd_ = nullptr; 66 | } 67 | } 68 | 69 | SPDLOG_INLINE void file_helper::write(const memory_buf_t &buf) 70 | { 71 | size_t msg_size = buf.size(); 72 | auto data = buf.data(); 73 | if (std::fwrite(data, 1, msg_size, fd_) != msg_size) 74 | { 75 | SPDLOG_THROW(spdlog_ex("Failed writing to file " + os::filename_to_str(_filename), errno)); 76 | } 77 | } 78 | 79 | SPDLOG_INLINE size_t file_helper::size() const 80 | { 81 | if (fd_ == nullptr) 82 | { 83 | SPDLOG_THROW(spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename))); 84 | } 85 | return os::filesize(fd_); 86 | } 87 | 88 | SPDLOG_INLINE const filename_t &file_helper::filename() const 89 | { 90 | return _filename; 91 | } 92 | 93 | SPDLOG_INLINE bool file_helper::file_exists(const filename_t &fname) 94 | { 95 | return os::file_exists(fname); 96 | } 97 | 98 | // 99 | // return file path and its extension: 100 | // 101 | // "mylog.txt" => ("mylog", ".txt") 102 | // "mylog" => ("mylog", "") 103 | // "mylog." => ("mylog.", "") 104 | // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") 105 | // 106 | // the starting dot in filenames is ignored (hidden files): 107 | // 108 | // ".mylog" => (".mylog". "") 109 | // "my_folder/.mylog" => ("my_folder/.mylog", "") 110 | // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") 111 | SPDLOG_INLINE std::tuple file_helper::split_by_extension(const filename_t &fname) 112 | { 113 | auto ext_index = fname.rfind('.'); 114 | 115 | // no valid extension found - return whole path and empty string as 116 | // extension 117 | if (ext_index == filename_t::npos || ext_index == 0 || ext_index == fname.size() - 1) 118 | { 119 | return std::make_tuple(fname, filename_t()); 120 | } 121 | 122 | // treat casese like "/etc/rc.d/somelogfile or "/abc/.hiddenfile" 123 | auto folder_index = fname.rfind(details::os::folder_sep); 124 | if (folder_index != filename_t::npos && folder_index >= ext_index - 1) 125 | { 126 | return std::make_tuple(fname, filename_t()); 127 | } 128 | 129 | // finally - return a valid base and extension tuple 130 | return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index)); 131 | } 132 | } // namespace details 133 | } // namespace spdlog 134 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/common.h" 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 file_helper 17 | { 18 | public: 19 | explicit file_helper() = default; 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 close(); 29 | void write(const memory_buf_t &buf); 30 | size_t size() const; 31 | const filename_t &filename() const; 32 | static bool file_exists(const filename_t &fname); 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 int open_interval = 10; 52 | std::FILE *fd_{nullptr}; 53 | filename_t _filename; 54 | }; 55 | } // namespace details 56 | } // namespace spdlog 57 | 58 | #ifdef SPDLOG_HEADER_ONLY 59 | #include "file_helper-inl.h" 60 | #endif 61 | -------------------------------------------------------------------------------- /extern/include/spdlog/details/fmt_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include "spdlog/fmt/fmt.h" 8 | #include "spdlog/common.h" 9 | 10 | // Some fmt helpers to efficiently format and pad ints and strings 11 | namespace spdlog { 12 | namespace details { 13 | namespace fmt_helper { 14 | 15 | inline spdlog::string_view_t to_string_view(const memory_buf_t &buf) SPDLOG_NOEXCEPT 16 | { 17 | return spdlog::string_view_t{buf.data(), buf.size()}; 18 | } 19 | 20 | inline void append_string_view(spdlog::string_view_t view, memory_buf_t &dest) 21 | { 22 | auto *buf_ptr = view.data(); 23 | if (buf_ptr != nullptr) 24 | { 25 | dest.append(buf_ptr, buf_ptr + view.size()); 26 | } 27 | } 28 | 29 | template 30 | inline void append_int(T n, memory_buf_t &dest) 31 | { 32 | fmt::format_int i(n); 33 | dest.append(i.data(), i.data() + i.size()); 34 | } 35 | 36 | template 37 | inline unsigned count_digits(T n) 38 | { 39 | using count_type = typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type; 40 | return static_cast(fmt::internal::count_digits(static_cast(n))); 41 | } 42 | 43 | inline void pad2(int n, memory_buf_t &dest) 44 | { 45 | if (n > 99) 46 | { 47 | append_int(n, dest); 48 | } 49 | else if (n > 9) // 10-99 50 | { 51 | dest.push_back(static_cast('0' + n / 10)); 52 | dest.push_back(static_cast('0' + n % 10)); 53 | } 54 | else if (n >= 0) // 0-9 55 | { 56 | dest.push_back('0'); 57 | dest.push_back(static_cast('0' + n)); 58 | } 59 | else // negatives (unlikely, but just in case, let fmt deal with it) 60 | { 61 | fmt::format_to(dest, "{:02}", n); 62 | } 63 | } 64 | 65 | template 66 | inline void pad_uint(T n, unsigned int width, memory_buf_t &dest) 67 | { 68 | static_assert(std::is_unsigned::value, "pad_uint must get unsigned T"); 69 | auto digits = count_digits(n); 70 | if (width > digits) 71 | { 72 | const char *zeroes = "0000000000000000000"; 73 | dest.append(zeroes, zeroes + width - digits); 74 | } 75 | append_int(n, dest); 76 | } 77 | 78 | template 79 | inline void pad3(T n, memory_buf_t &dest) 80 | { 81 | pad_uint(n, 3, dest); 82 | } 83 | 84 | template 85 | inline void pad6(T n, memory_buf_t &dest) 86 | { 87 | pad_uint(n, 6, dest); 88 | } 89 | 90 | template 91 | inline void pad9(T n, memory_buf_t &dest) 92 | { 93 | pad_uint(n, 9, dest); 94 | } 95 | 96 | // return fraction of a second of the given time_point. 97 | // e.g. 98 | // fraction(tp) -> will return the millis part of the second 99 | template 100 | inline ToDuration time_fraction(log_clock::time_point tp) 101 | { 102 | using std::chrono::duration_cast; 103 | using std::chrono::seconds; 104 | auto duration = tp.time_since_epoch(); 105 | auto secs = duration_cast(duration); 106 | return duration_cast(duration) - duration_cast(secs); 107 | } 108 | 109 | } // namespace fmt_helper 110 | } // namespace details 111 | } // namespace spdlog 112 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/log_msg.h" 8 | #endif 9 | 10 | #include "spdlog/details/os.h" 11 | 12 | namespace spdlog { 13 | namespace details { 14 | 15 | SPDLOG_INLINE log_msg::log_msg(spdlog::source_loc loc, string_view_t logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg) 16 | : logger_name(logger_name) 17 | , level(lvl) 18 | #ifndef SPDLOG_NO_DATETIME 19 | , time(os::now()) 20 | #endif 21 | 22 | #ifndef SPDLOG_NO_THREAD_ID 23 | , thread_id(os::thread_id()) 24 | #endif 25 | , source(loc) 26 | , payload(msg) 27 | {} 28 | 29 | SPDLOG_INLINE log_msg::log_msg(string_view_t logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg) 30 | : log_msg(source_loc{}, logger_name, lvl, msg) 31 | {} 32 | 33 | } // namespace details 34 | } // namespace spdlog 35 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/common.h" 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | struct log_msg 12 | { 13 | log_msg() = default; 14 | log_msg(source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); 15 | log_msg(string_view_t logger_name, level::level_enum lvl, string_view_t msg); 16 | log_msg(const log_msg &other) = default; 17 | 18 | string_view_t logger_name; 19 | level::level_enum level{level::off}; 20 | log_clock::time_point time; 21 | size_t thread_id{0}; 22 | 23 | // wrapping the formatted text with color (updated by pattern_formatter). 24 | mutable size_t color_range_start{0}; 25 | mutable size_t color_range_end{0}; 26 | 27 | source_loc source; 28 | string_view_t payload; 29 | }; 30 | } // namespace details 31 | } // namespace spdlog 32 | 33 | #ifdef SPDLOG_HEADER_ONLY 34 | #include "log_msg-inl.h" 35 | #endif 36 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/log_msg_buffer.h" 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 | { 16 | buffer.append(logger_name.begin(), logger_name.end()); 17 | buffer.append(payload.begin(), payload.end()); 18 | update_string_views(); 19 | } 20 | 21 | SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other) 22 | : log_msg{other} 23 | { 24 | buffer.append(logger_name.begin(), logger_name.end()); 25 | buffer.append(payload.begin(), payload.end()); 26 | update_string_views(); 27 | } 28 | 29 | SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) 30 | : log_msg{std::move(other)} 31 | , buffer{std::move(other.buffer)} 32 | { 33 | update_string_views(); 34 | } 35 | 36 | SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other) 37 | { 38 | log_msg::operator=(other); 39 | buffer.clear(); 40 | buffer.append(other.buffer.data(), other.buffer.data() + other.buffer.size()); 41 | update_string_views(); 42 | return *this; 43 | } 44 | 45 | SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) 46 | { 47 | log_msg::operator=(std::move(other)); 48 | buffer = std::move(other.buffer); 49 | update_string_views(); 50 | return *this; 51 | } 52 | 53 | SPDLOG_INLINE void log_msg_buffer::update_string_views() 54 | { 55 | logger_name = string_view_t{buffer.data(), logger_name.size()}; 56 | payload = string_view_t{buffer.data() + logger_name.size(), payload.size()}; 57 | } 58 | 59 | } // namespace details 60 | } // namespace spdlog 61 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/log_msg.h" 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 log_msg_buffer : public log_msg 15 | { 16 | memory_buf_t buffer; 17 | void update_string_views(); 18 | 19 | public: 20 | log_msg_buffer() = default; 21 | explicit log_msg_buffer(const log_msg &orig_msg); 22 | log_msg_buffer(const log_msg_buffer &other); 23 | log_msg_buffer(log_msg_buffer &&other); 24 | log_msg_buffer &operator=(const log_msg_buffer &other); 25 | log_msg_buffer &operator=(log_msg_buffer &&other); 26 | }; 27 | 28 | } // namespace details 29 | } // namespace spdlog 30 | 31 | #ifdef SPDLOG_HEADER_ONLY 32 | #include "log_msg_buffer-inl.h" 33 | #endif 34 | -------------------------------------------------------------------------------- /extern/include/spdlog/details/mpmc_blocking_q.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 | // multi producer-multi consumer blocking queue. 7 | // enqueue(..) - will block until room found to put the new message. 8 | // enqueue_nowait(..) - will return immediately with false if no room left in 9 | // the queue. 10 | // dequeue_for(..) - will block until the queue is not empty or timeout have 11 | // passed. 12 | 13 | #include "spdlog/details/circular_q.h" 14 | 15 | #include 16 | #include 17 | 18 | namespace spdlog { 19 | namespace details { 20 | 21 | template 22 | class mpmc_blocking_queue 23 | { 24 | public: 25 | using item_type = T; 26 | explicit mpmc_blocking_queue(size_t max_items) 27 | : q_(max_items) 28 | {} 29 | 30 | #ifndef __MINGW32__ 31 | // try to enqueue and block if no room left 32 | void enqueue(T &&item) 33 | { 34 | { 35 | std::unique_lock lock(queue_mutex_); 36 | pop_cv_.wait(lock, [this] { return !this->q_.full(); }); 37 | q_.push_back(std::move(item)); 38 | } 39 | push_cv_.notify_one(); 40 | } 41 | 42 | // enqueue immediately. overrun oldest message in the queue if no room left. 43 | void enqueue_nowait(T &&item) 44 | { 45 | { 46 | std::unique_lock lock(queue_mutex_); 47 | q_.push_back(std::move(item)); 48 | } 49 | push_cv_.notify_one(); 50 | } 51 | 52 | // try to dequeue item. if no item found. wait upto timeout and try again 53 | // Return true, if succeeded dequeue item, false otherwise 54 | bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration) 55 | { 56 | { 57 | std::unique_lock lock(queue_mutex_); 58 | if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); })) 59 | { 60 | return false; 61 | } 62 | popped_item = std::move(q_.front()); 63 | q_.pop_front(); 64 | } 65 | pop_cv_.notify_one(); 66 | return true; 67 | } 68 | 69 | #else 70 | // apparently mingw deadlocks if the mutex is released before cv.notify_one(), 71 | // so release the mutex at the very end each function. 72 | 73 | // try to enqueue and block if no room left 74 | void enqueue(T &&item) 75 | { 76 | std::unique_lock lock(queue_mutex_); 77 | pop_cv_.wait(lock, [this] { return !this->q_.full(); }); 78 | q_.push_back(std::move(item)); 79 | push_cv_.notify_one(); 80 | } 81 | 82 | // enqueue immediately. overrun oldest message in the queue if no room left. 83 | void enqueue_nowait(T &&item) 84 | { 85 | std::unique_lock lock(queue_mutex_); 86 | q_.push_back(std::move(item)); 87 | push_cv_.notify_one(); 88 | } 89 | 90 | // try to dequeue item. if no item found. wait upto timeout and try again 91 | // Return true, if succeeded dequeue item, false otherwise 92 | bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration) 93 | { 94 | std::unique_lock lock(queue_mutex_); 95 | if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); })) 96 | { 97 | return false; 98 | } 99 | popped_item = std::move(q_.front()); 100 | q_.pop_front(); 101 | pop_cv_.notify_one(); 102 | return true; 103 | } 104 | 105 | #endif 106 | 107 | size_t overrun_counter() 108 | { 109 | std::unique_lock lock(queue_mutex_); 110 | return q_.overrun_counter(); 111 | } 112 | 113 | private: 114 | std::mutex queue_mutex_; 115 | std::condition_variable push_cv_; 116 | std::condition_variable pop_cv_; 117 | spdlog::details::circular_q q_; 118 | }; 119 | } // namespace details 120 | } // namespace spdlog 121 | -------------------------------------------------------------------------------- /extern/include/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 | { 14 | void lock() const {} 15 | void unlock() const {} 16 | bool try_lock() const 17 | { 18 | return true; 19 | } 20 | }; 21 | 22 | struct null_atomic_int 23 | { 24 | int value; 25 | null_atomic_int() = default; 26 | 27 | explicit null_atomic_int(int new_value) 28 | : value(new_value) 29 | {} 30 | 31 | int load(std::memory_order = std::memory_order_relaxed) const 32 | { 33 | return value; 34 | } 35 | 36 | void store(int new_value, std::memory_order = std::memory_order_relaxed) 37 | { 38 | value = new_value; 39 | } 40 | 41 | int exchange(int new_value, std::memory_order = std::memory_order_relaxed) 42 | { 43 | std::swap(new_value, value); 44 | return new_value; // return value before the call 45 | } 46 | }; 47 | 48 | } // namespace details 49 | } // namespace spdlog 50 | -------------------------------------------------------------------------------- /extern/include/spdlog/details/os.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/common.h" 7 | #include // std::time_t 8 | 9 | namespace spdlog { 10 | namespace details { 11 | namespace os { 12 | 13 | spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT; 14 | 15 | std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; 16 | 17 | std::tm localtime() SPDLOG_NOEXCEPT; 18 | 19 | std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; 20 | 21 | std::tm gmtime() SPDLOG_NOEXCEPT; 22 | 23 | // eol definition 24 | #if !defined(SPDLOG_EOL) 25 | #ifdef _WIN32 26 | #define SPDLOG_EOL "\r\n" 27 | #else 28 | #define SPDLOG_EOL "\n" 29 | #endif 30 | #endif 31 | 32 | SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL; 33 | 34 | // folder separator 35 | #ifdef _WIN32 36 | const char folder_sep = '\\'; 37 | #else 38 | SPDLOG_CONSTEXPR static const char folder_sep = '/'; 39 | #endif 40 | 41 | void prevent_child_fd(FILE *f); 42 | 43 | // fopen_s on non windows for writing 44 | bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode); 45 | 46 | // Remove filename. return 0 on success 47 | int remove(const filename_t &filename) SPDLOG_NOEXCEPT; 48 | 49 | // Remove file if exists. return 0 on success 50 | // Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread) 51 | int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT; 52 | 53 | int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT; 54 | 55 | // Return if file exists. 56 | bool file_exists(const filename_t &filename) SPDLOG_NOEXCEPT; 57 | 58 | // Return file size according to open FILE* object 59 | size_t filesize(FILE *f); 60 | 61 | // Return utc offset in minutes or throw spdlog_ex on failure 62 | int utc_minutes_offset(const std::tm &tm = details::os::localtime()); 63 | 64 | // Return current thread id as size_t 65 | // It exists because the std::this_thread::get_id() is much slower(especially 66 | // under VS 2013) 67 | size_t _thread_id() SPDLOG_NOEXCEPT; 68 | 69 | // Return current thread id as size_t (from thread local storage) 70 | size_t thread_id() SPDLOG_NOEXCEPT; 71 | 72 | // This is avoid msvc issue in sleep_for that happens if the clock changes. 73 | // See https://github.com/gabime/spdlog/issues/609 74 | void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT; 75 | 76 | std::string filename_to_str(const filename_t &filename); 77 | 78 | int pid() SPDLOG_NOEXCEPT; 79 | 80 | // Determine if the terminal supports colors 81 | // Source: https://github.com/agauniyal/rang/ 82 | bool is_color_terminal() SPDLOG_NOEXCEPT; 83 | 84 | // Detrmine if the terminal attached 85 | // Source: https://github.com/agauniyal/rang/ 86 | bool in_terminal(FILE *file) SPDLOG_NOEXCEPT; 87 | 88 | #if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) 89 | void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target); 90 | #endif 91 | 92 | } // namespace os 93 | } // namespace details 94 | } // namespace spdlog 95 | 96 | #ifdef SPDLOG_HEADER_ONLY 97 | #include "os-inl.h" 98 | #endif 99 | -------------------------------------------------------------------------------- /extern/include/spdlog/details/pattern_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 "spdlog/common.h" 7 | #include "spdlog/details/log_msg.h" 8 | #include "spdlog/details/os.h" 9 | #include "spdlog/formatter.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace spdlog { 19 | namespace details { 20 | 21 | // padding information. 22 | struct padding_info 23 | { 24 | enum pad_side 25 | { 26 | left, 27 | right, 28 | center 29 | }; 30 | 31 | padding_info() = default; 32 | padding_info(size_t width, padding_info::pad_side side) 33 | : width_(width) 34 | , side_(side) 35 | {} 36 | 37 | bool enabled() const 38 | { 39 | return width_ != 0; 40 | } 41 | const size_t width_ = 0; 42 | const pad_side side_ = left; 43 | }; 44 | 45 | class flag_formatter 46 | { 47 | public: 48 | explicit flag_formatter(padding_info padinfo) 49 | : padinfo_(padinfo) 50 | {} 51 | flag_formatter() = default; 52 | virtual ~flag_formatter() = default; 53 | virtual void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) = 0; 54 | 55 | protected: 56 | padding_info padinfo_; 57 | }; 58 | 59 | } // namespace details 60 | 61 | class pattern_formatter final : public formatter 62 | { 63 | public: 64 | explicit pattern_formatter( 65 | std::string pattern, pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol); 66 | 67 | // use default pattern is not given 68 | explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol); 69 | 70 | pattern_formatter(const pattern_formatter &other) = delete; 71 | pattern_formatter &operator=(const pattern_formatter &other) = delete; 72 | 73 | std::unique_ptr clone() const override; 74 | void format(const details::log_msg &msg, memory_buf_t &dest) override; 75 | 76 | private: 77 | std::string pattern_; 78 | std::string eol_; 79 | pattern_time_type pattern_time_type_; 80 | std::tm cached_tm_; 81 | std::chrono::seconds last_log_secs_; 82 | std::vector> formatters_; 83 | 84 | std::tm get_time_(const details::log_msg &msg); 85 | template 86 | void handle_flag_(char flag, details::padding_info padding); 87 | 88 | // Extract given pad spec (e.g. %8X) 89 | // Advance the given it pass the end of the padding spec found (if any) 90 | // Return padding. 91 | details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end); 92 | 93 | void compile_pattern_(const std::string &pattern); 94 | }; 95 | } // namespace spdlog 96 | 97 | #ifdef SPDLOG_HEADER_ONLY 98 | #include "pattern_formatter-inl.h" 99 | #endif 100 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/periodic_worker.h" 8 | #endif 9 | 10 | namespace spdlog { 11 | namespace details { 12 | 13 | SPDLOG_INLINE periodic_worker::periodic_worker(const std::function &callback_fun, std::chrono::seconds interval) 14 | { 15 | active_ = (interval > std::chrono::seconds::zero()); 16 | if (!active_) 17 | { 18 | return; 19 | } 20 | 21 | worker_thread_ = std::thread([this, callback_fun, interval]() { 22 | for (;;) 23 | { 24 | std::unique_lock lock(this->mutex_); 25 | if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; })) 26 | { 27 | return; // active_ == false, so exit this thread 28 | } 29 | callback_fun(); 30 | } 31 | }); 32 | } 33 | 34 | // stop the worker thread and join it 35 | SPDLOG_INLINE periodic_worker::~periodic_worker() 36 | { 37 | if (worker_thread_.joinable()) 38 | { 39 | { 40 | std::lock_guard lock(mutex_); 41 | active_ = false; 42 | } 43 | cv_.notify_one(); 44 | worker_thread_.join(); 45 | } 46 | } 47 | 48 | } // namespace details 49 | } // namespace spdlog 50 | -------------------------------------------------------------------------------- /extern/include/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 to finish first). 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | namespace spdlog { 18 | namespace details { 19 | 20 | class periodic_worker 21 | { 22 | public: 23 | periodic_worker(const std::function &callback_fun, std::chrono::seconds interval); 24 | periodic_worker(const periodic_worker &) = delete; 25 | periodic_worker &operator=(const periodic_worker &) = delete; 26 | // stop the worker thread and join it 27 | ~periodic_worker(); 28 | 29 | private: 30 | bool active_; 31 | std::thread worker_thread_; 32 | std::mutex mutex_; 33 | std::condition_variable cv_; 34 | }; 35 | } // namespace details 36 | } // namespace spdlog 37 | 38 | #ifdef SPDLOG_HEADER_ONLY 39 | #include "periodic_worker-inl.h" 40 | #endif 41 | -------------------------------------------------------------------------------- /extern/include/spdlog/details/registry.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 | // Loggers registry of unique name->logger pointer 7 | // An attempt to create a logger with an already existing name will result with spdlog_ex exception. 8 | // If user requests a non existing logger, nullptr will be returned 9 | // This class is thread safe 10 | 11 | #include "spdlog/common.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace spdlog { 21 | class logger; 22 | 23 | namespace details { 24 | class thread_pool; 25 | class periodic_worker; 26 | 27 | class registry 28 | { 29 | public: 30 | registry(const registry &) = delete; 31 | registry &operator=(const registry &) = delete; 32 | 33 | void register_logger(std::shared_ptr new_logger); 34 | void initialize_logger(std::shared_ptr new_logger); 35 | std::shared_ptr get(const std::string &logger_name); 36 | std::shared_ptr default_logger(); 37 | 38 | // Return raw ptr to the default logger. 39 | // To be used directly by the spdlog default api (e.g. spdlog::info) 40 | // This make the default API faster, but cannot be used concurrently with set_default_logger(). 41 | // e.g do not call set_default_logger() from one thread while calling spdlog::info() from another. 42 | logger *get_default_raw(); 43 | 44 | // set default logger. 45 | // default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map. 46 | void set_default_logger(std::shared_ptr new_default_logger); 47 | 48 | void set_tp(std::shared_ptr tp); 49 | 50 | std::shared_ptr get_tp(); 51 | 52 | // Set global formatter. Each sink in each logger will get a clone of this object 53 | void set_formatter(std::unique_ptr formatter); 54 | 55 | void enable_backtrace(size_t n_messages); 56 | 57 | void disable_backtrace(); 58 | 59 | void set_level(level::level_enum log_level); 60 | 61 | void flush_on(level::level_enum log_level); 62 | 63 | void flush_every(std::chrono::seconds interval); 64 | 65 | void set_error_handler(void (*handler)(const std::string &msg)); 66 | 67 | void apply_all(const std::function)> &fun); 68 | 69 | void flush_all(); 70 | 71 | void drop(const std::string &logger_name); 72 | 73 | void drop_all(); 74 | 75 | // clean all resources and threads started by the registry 76 | void shutdown(); 77 | 78 | std::recursive_mutex &tp_mutex(); 79 | 80 | void set_automatic_registration(bool automatic_regsistration); 81 | 82 | static registry &instance(); 83 | 84 | private: 85 | registry(); 86 | ~registry() = default; 87 | 88 | void throw_if_exists_(const std::string &logger_name); 89 | void register_logger_(std::shared_ptr new_logger); 90 | std::mutex logger_map_mutex_, flusher_mutex_; 91 | std::recursive_mutex tp_mutex_; 92 | std::unordered_map> loggers_; 93 | std::unique_ptr formatter_; 94 | level::level_enum level_ = level::info; 95 | level::level_enum flush_level_ = level::off; 96 | void (*err_handler_)(const std::string &msg); 97 | std::shared_ptr tp_; 98 | std::unique_ptr periodic_flusher_; 99 | std::shared_ptr default_logger_; 100 | bool automatic_registration_ = true; 101 | size_t backtrace_n_messages_ = 0; 102 | }; 103 | 104 | } // namespace details 105 | } // namespace spdlog 106 | 107 | #ifdef SPDLOG_HEADER_ONLY 108 | #include "registry-inl.h" 109 | #endif 110 | -------------------------------------------------------------------------------- /extern/include/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 | { 15 | template 16 | static std::shared_ptr create(std::string logger_name, SinkArgs &&... args) 17 | { 18 | auto sink = std::make_shared(std::forward(args)...); 19 | auto new_logger = std::make_shared(std::move(logger_name), std::move(sink)); 20 | details::registry::instance().initialize_logger(new_logger); 21 | return new_logger; 22 | } 23 | }; 24 | } // namespace spdlog -------------------------------------------------------------------------------- /extern/include/spdlog/details/thread_pool-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 "spdlog/details/thread_pool.h" 8 | #endif 9 | 10 | #include "spdlog/common.h" 11 | 12 | namespace spdlog { 13 | namespace details { 14 | 15 | SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std::function on_thread_start) 16 | : q_(q_max_items) 17 | { 18 | if (threads_n == 0 || threads_n > 1000) 19 | { 20 | SPDLOG_THROW(spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid " 21 | "range is 1-1000)")); 22 | } 23 | for (size_t i = 0; i < threads_n; i++) 24 | { 25 | threads_.emplace_back([this, on_thread_start] { 26 | on_thread_start(); 27 | this->thread_pool::worker_loop_(); 28 | }); 29 | } 30 | } 31 | 32 | SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n) 33 | : thread_pool(q_max_items, threads_n, [] {}) 34 | {} 35 | 36 | // message all threads to terminate gracefully join them 37 | SPDLOG_INLINE thread_pool::~thread_pool() 38 | { 39 | SPDLOG_TRY 40 | { 41 | for (size_t i = 0; i < threads_.size(); i++) 42 | { 43 | post_async_msg_(async_msg(async_msg_type::terminate), async_overflow_policy::block); 44 | } 45 | 46 | for (auto &t : threads_) 47 | { 48 | t.join(); 49 | } 50 | } 51 | SPDLOG_CATCH_ALL() {} 52 | } 53 | 54 | void SPDLOG_INLINE thread_pool::post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy) 55 | { 56 | async_msg async_m(std::move(worker_ptr), async_msg_type::log, msg); 57 | post_async_msg_(std::move(async_m), overflow_policy); 58 | } 59 | 60 | void SPDLOG_INLINE thread_pool::post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy) 61 | { 62 | post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy); 63 | } 64 | 65 | size_t SPDLOG_INLINE thread_pool::overrun_counter() 66 | { 67 | return q_.overrun_counter(); 68 | } 69 | 70 | void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy) 71 | { 72 | if (overflow_policy == async_overflow_policy::block) 73 | { 74 | q_.enqueue(std::move(new_msg)); 75 | } 76 | else 77 | { 78 | q_.enqueue_nowait(std::move(new_msg)); 79 | } 80 | } 81 | 82 | void SPDLOG_INLINE thread_pool::worker_loop_() 83 | { 84 | while (process_next_msg_()) {}; 85 | } 86 | 87 | // process next message in the queue 88 | // return true if this thread should still be active (while no terminate msg 89 | // was received) 90 | bool SPDLOG_INLINE thread_pool::process_next_msg_() 91 | { 92 | async_msg incoming_async_msg; 93 | bool dequeued = q_.dequeue_for(incoming_async_msg, std::chrono::seconds(10)); 94 | if (!dequeued) 95 | { 96 | return true; 97 | } 98 | 99 | switch (incoming_async_msg.msg_type) 100 | { 101 | case async_msg_type::log: 102 | { 103 | incoming_async_msg.worker_ptr->backend_sink_it_(incoming_async_msg); 104 | return true; 105 | } 106 | case async_msg_type::flush: 107 | { 108 | incoming_async_msg.worker_ptr->backend_flush_(); 109 | return true; 110 | } 111 | 112 | case async_msg_type::terminate: 113 | { 114 | return false; 115 | } 116 | 117 | default: 118 | { 119 | assert(false && "Unexpected async_msg_type"); 120 | } 121 | } 122 | 123 | return true; 124 | } 125 | 126 | } // namespace details 127 | } // namespace spdlog 128 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/log_msg_buffer.h" 7 | #include "spdlog/details/mpmc_blocking_q.h" 8 | #include "spdlog/details/os.h" 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 24 | { 25 | log, 26 | flush, 27 | terminate 28 | }; 29 | 30 | #include "spdlog/details/log_msg_buffer.h" 31 | // Async msg to move to/from the queue 32 | // Movable only. should never be copied 33 | struct async_msg : log_msg_buffer 34 | { 35 | async_msg_type msg_type{async_msg_type::log}; 36 | async_logger_ptr worker_ptr; 37 | 38 | async_msg() = default; 39 | ~async_msg() = default; 40 | 41 | // should only be moved in or out of the queue.. 42 | async_msg(const async_msg &) = delete; 43 | 44 | // support for vs2013 move 45 | #if defined(_MSC_VER) && _MSC_VER <= 1800 46 | async_msg(async_msg &&other) 47 | : log_msg_buffer(std::move(other)) 48 | , msg_type(other.msg_type) 49 | , worker_ptr(std::move(other.worker_ptr)) 50 | {} 51 | 52 | async_msg &operator=(async_msg &&other) 53 | { 54 | *static_cast(this) = std::move(other); 55 | msg_type = other.msg_type; 56 | worker_ptr = std::move(other.worker_ptr); 57 | return *this; 58 | } 59 | #else // (_MSC_VER) && _MSC_VER <= 1800 60 | async_msg(async_msg &&) = default; 61 | async_msg &operator=(async_msg &&) = default; 62 | #endif 63 | 64 | // construct from log_msg with given type 65 | async_msg(async_logger_ptr &&worker, async_msg_type the_type, const details::log_msg &m) 66 | : log_msg_buffer{m} 67 | , msg_type{the_type} 68 | , worker_ptr{std::move(worker)} 69 | {} 70 | 71 | async_msg(async_logger_ptr &&worker, async_msg_type the_type) 72 | : log_msg_buffer{} 73 | , msg_type{the_type} 74 | , worker_ptr{std::move(worker)} 75 | {} 76 | 77 | explicit async_msg(async_msg_type the_type) 78 | : async_msg{nullptr, the_type} 79 | {} 80 | }; 81 | 82 | class thread_pool 83 | { 84 | public: 85 | using item_type = async_msg; 86 | using q_type = details::mpmc_blocking_queue; 87 | 88 | thread_pool(size_t q_max_items, size_t threads_n, std::function on_thread_start); 89 | thread_pool(size_t q_max_items, size_t threads_n); 90 | 91 | // message all threads to terminate gracefully join them 92 | ~thread_pool(); 93 | 94 | thread_pool(const thread_pool &) = delete; 95 | thread_pool &operator=(thread_pool &&) = delete; 96 | 97 | void post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy); 98 | void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy); 99 | size_t overrun_counter(); 100 | 101 | private: 102 | q_type q_; 103 | 104 | std::vector threads_; 105 | 106 | void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy); 107 | void worker_loop_(); 108 | 109 | // process next message in the queue 110 | // return true if this thread should still be active (while no terminate msg 111 | // was received) 112 | bool process_next_msg_(); 113 | }; 114 | 115 | } // namespace details 116 | } // namespace spdlog 117 | 118 | #ifdef SPDLOG_HEADER_ONLY 119 | #include "thread_pool-inl.h" 120 | #endif 121 | -------------------------------------------------------------------------------- /extern/include/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 0 // !defined(SPDLOG_FMT_EXTERNAL) 14 | #ifdef SPDLOG_HEADER_ONLY 15 | #ifndef FMT_HEADER_ONLY 16 | #define FMT_HEADER_ONLY 17 | #endif 18 | #endif 19 | #ifndef FMT_USE_WINDOWS_H 20 | #define FMT_USE_WINDOWS_H 0 21 | #endif 22 | #include "bundled/core.h" 23 | #include "bundled/format.h" 24 | #else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib 25 | #include "fmt/core.h" 26 | #include "fmt/format.h" 27 | #endif 28 | -------------------------------------------------------------------------------- /extern/include/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 | #if 0 // !defined(SPDLOG_FMT_EXTERNAL) 11 | #ifndef FMT_HEADER_ONLY 12 | #define FMT_HEADER_ONLY 13 | #endif 14 | #include "bundled/ostream.h" 15 | #include "fmt.h" 16 | #else 17 | #include 18 | #endif 19 | -------------------------------------------------------------------------------- /extern/include/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 "fmt/fmt.h" 7 | #include "spdlog/details/log_msg.h" 8 | 9 | namespace spdlog { 10 | 11 | class formatter 12 | { 13 | public: 14 | virtual ~formatter() = default; 15 | virtual void format(const details::log_msg &msg, memory_buf_t &dest) = 0; 16 | virtual std::unique_ptr clone() const = 0; 17 | }; 18 | } // namespace spdlog 19 | -------------------------------------------------------------------------------- /extern/include/spdlog/sinks/android_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 | #ifdef __ANDROID__ 7 | 8 | #include "spdlog/details/fmt_helper.h" 9 | #include "spdlog/details/null_mutex.h" 10 | #include "spdlog/details/os.h" 11 | #include "spdlog/sinks/base_sink.h" 12 | #include "spdlog/details/synchronous_factory.h" 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #if !defined(SPDLOG_ANDROID_RETRIES) 21 | #define SPDLOG_ANDROID_RETRIES 2 22 | #endif 23 | 24 | namespace spdlog { 25 | namespace sinks { 26 | 27 | /* 28 | * Android sink (logging using __android_log_write) 29 | */ 30 | template 31 | class android_sink final : public base_sink 32 | { 33 | public: 34 | explicit android_sink(std::string tag = "spdlog", bool use_raw_msg = false) 35 | : tag_(std::move(tag)) 36 | , use_raw_msg_(use_raw_msg) 37 | {} 38 | 39 | protected: 40 | void sink_it_(const details::log_msg &msg) override 41 | { 42 | const android_LogPriority priority = convert_to_android_(msg.level); 43 | memory_buf_t formatted; 44 | if (use_raw_msg_) 45 | { 46 | details::fmt_helper::append_string_view(msg.payload, formatted); 47 | } 48 | else 49 | { 50 | base_sink::formatter_->format(msg, formatted); 51 | } 52 | formatted.push_back('\0'); 53 | const char *msg_output = formatted.data(); 54 | 55 | // See system/core/liblog/logger_write.c for explanation of return value 56 | int ret = __android_log_write(priority, tag_.c_str(), msg_output); 57 | int retry_count = 0; 58 | while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES)) 59 | { 60 | details::os::sleep_for_millis(5); 61 | ret = __android_log_write(priority, tag_.c_str(), msg_output); 62 | retry_count++; 63 | } 64 | 65 | if (ret < 0) 66 | { 67 | SPDLOG_THROW(spdlog_ex("__android_log_write() failed", ret)); 68 | } 69 | } 70 | 71 | void flush_() override {} 72 | 73 | private: 74 | static android_LogPriority convert_to_android_(spdlog::level::level_enum level) 75 | { 76 | switch (level) 77 | { 78 | case spdlog::level::trace: 79 | return ANDROID_LOG_VERBOSE; 80 | case spdlog::level::debug: 81 | return ANDROID_LOG_DEBUG; 82 | case spdlog::level::info: 83 | return ANDROID_LOG_INFO; 84 | case spdlog::level::warn: 85 | return ANDROID_LOG_WARN; 86 | case spdlog::level::err: 87 | return ANDROID_LOG_ERROR; 88 | case spdlog::level::critical: 89 | return ANDROID_LOG_FATAL; 90 | default: 91 | return ANDROID_LOG_DEFAULT; 92 | } 93 | } 94 | 95 | std::string tag_; 96 | bool use_raw_msg_; 97 | }; 98 | 99 | using android_sink_mt = android_sink; 100 | using android_sink_st = android_sink; 101 | } // namespace sinks 102 | 103 | // Create and register android syslog logger 104 | 105 | template 106 | inline std::shared_ptr android_logger_mt(const std::string &logger_name, const std::string &tag = "spdlog") 107 | { 108 | return Factory::template create(logger_name, tag); 109 | } 110 | 111 | template 112 | inline std::shared_ptr android_logger_st(const std::string &logger_name, const std::string &tag = "spdlog") 113 | { 114 | return Factory::template create(logger_name, tag); 115 | } 116 | 117 | } // namespace spdlog 118 | 119 | #endif // __ANDROID__ -------------------------------------------------------------------------------- /extern/include/spdlog/sinks/ansicolor_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/console_globals.h" 7 | #include "spdlog/details/null_mutex.h" 8 | #include "spdlog/sinks/sink.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace spdlog { 15 | namespace sinks { 16 | 17 | /** 18 | * This sink prefixes the output with an ANSI escape sequence color code 19 | * depending on the severity 20 | * of the message. 21 | * If no color terminal detected, omit the escape codes. 22 | */ 23 | 24 | template 25 | class ansicolor_sink : public sink 26 | { 27 | public: 28 | using mutex_t = typename ConsoleMutex::mutex_t; 29 | ansicolor_sink(FILE *target_file, color_mode mode); 30 | ~ansicolor_sink() override = default; 31 | 32 | ansicolor_sink(const ansicolor_sink &other) = delete; 33 | ansicolor_sink &operator=(const ansicolor_sink &other) = delete; 34 | void set_color(level::level_enum color_level, string_view_t color); 35 | void set_color_mode(color_mode mode); 36 | bool should_color(); 37 | 38 | void log(const details::log_msg &msg) override; 39 | void flush() override; 40 | void set_pattern(const std::string &pattern) final; 41 | void set_formatter(std::unique_ptr sink_formatter) override; 42 | 43 | // Formatting codes 44 | const string_view_t reset = "\033[m"; 45 | const string_view_t bold = "\033[1m"; 46 | const string_view_t dark = "\033[2m"; 47 | const string_view_t underline = "\033[4m"; 48 | const string_view_t blink = "\033[5m"; 49 | const string_view_t reverse = "\033[7m"; 50 | const string_view_t concealed = "\033[8m"; 51 | const string_view_t clear_line = "\033[K"; 52 | 53 | // Foreground colors 54 | const string_view_t black = "\033[30m"; 55 | const string_view_t red = "\033[31m"; 56 | const string_view_t green = "\033[32m"; 57 | const string_view_t yellow = "\033[33m"; 58 | const string_view_t blue = "\033[34m"; 59 | const string_view_t magenta = "\033[35m"; 60 | const string_view_t cyan = "\033[36m"; 61 | const string_view_t white = "\033[37m"; 62 | 63 | /// Background colors 64 | const string_view_t on_black = "\033[40m"; 65 | const string_view_t on_red = "\033[41m"; 66 | const string_view_t on_green = "\033[42m"; 67 | const string_view_t on_yellow = "\033[43m"; 68 | const string_view_t on_blue = "\033[44m"; 69 | const string_view_t on_magenta = "\033[45m"; 70 | const string_view_t on_cyan = "\033[46m"; 71 | const string_view_t on_white = "\033[47m"; 72 | 73 | /// Bold colors 74 | const string_view_t yellow_bold = "\033[33m\033[1m"; 75 | const string_view_t red_bold = "\033[31m\033[1m"; 76 | const string_view_t bold_on_red = "\033[1m\033[41m"; 77 | 78 | private: 79 | FILE *target_file_; 80 | mutex_t &mutex_; 81 | bool should_do_colors_; 82 | std::unique_ptr formatter_; 83 | std::unordered_map colors_; 84 | void print_ccode_(const string_view_t &color_code); 85 | void print_range_(const memory_buf_t &formatted, size_t start, size_t end); 86 | }; 87 | 88 | template 89 | class ansicolor_stdout_sink : public ansicolor_sink 90 | { 91 | public: 92 | explicit ansicolor_stdout_sink(color_mode mode = color_mode::automatic); 93 | }; 94 | 95 | template 96 | class ansicolor_stderr_sink : public ansicolor_sink 97 | { 98 | public: 99 | explicit ansicolor_stderr_sink(color_mode mode = color_mode::automatic); 100 | }; 101 | 102 | using ansicolor_stdout_sink_mt = ansicolor_stdout_sink; 103 | using ansicolor_stdout_sink_st = ansicolor_stdout_sink; 104 | 105 | using ansicolor_stderr_sink_mt = ansicolor_stderr_sink; 106 | using ansicolor_stderr_sink_st = ansicolor_stderr_sink; 107 | 108 | } // namespace sinks 109 | } // namespace spdlog 110 | 111 | #ifdef SPDLOG_HEADER_ONLY 112 | #include "ansicolor_sink-inl.h" 113 | #endif 114 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/sinks/base_sink.h" 8 | #endif 9 | 10 | #include "spdlog/common.h" 11 | #include "spdlog/details/pattern_formatter.h" 12 | 13 | #include 14 | 15 | template 16 | SPDLOG_INLINE spdlog::sinks::base_sink::base_sink() 17 | : formatter_{details::make_unique()} 18 | {} 19 | 20 | template 21 | SPDLOG_INLINE spdlog::sinks::base_sink::base_sink(std::unique_ptr formatter) 22 | : formatter_{std::move(formatter)} 23 | {} 24 | 25 | template 26 | void SPDLOG_INLINE spdlog::sinks::base_sink::log(const details::log_msg &msg) 27 | { 28 | std::lock_guard lock(mutex_); 29 | sink_it_(msg); 30 | } 31 | 32 | template 33 | void SPDLOG_INLINE spdlog::sinks::base_sink::flush() 34 | { 35 | std::lock_guard lock(mutex_); 36 | flush_(); 37 | } 38 | 39 | template 40 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern(const std::string &pattern) 41 | { 42 | std::lock_guard lock(mutex_); 43 | set_pattern_(pattern); 44 | } 45 | 46 | template 47 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_formatter(std::unique_ptr sink_formatter) 48 | { 49 | std::lock_guard lock(mutex_); 50 | set_formatter_(std::move(sink_formatter)); 51 | } 52 | 53 | template 54 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern_(const std::string &pattern) 55 | { 56 | set_formatter_(details::make_unique(pattern)); 57 | } 58 | 59 | template 60 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_formatter_(std::unique_ptr sink_formatter) 61 | { 62 | formatter_ = std::move(sink_formatter); 63 | } 64 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/common.h" 13 | #include "spdlog/details/log_msg.h" 14 | #include "spdlog/sinks/sink.h" 15 | 16 | namespace spdlog { 17 | namespace sinks { 18 | template 19 | class base_sink : public sink 20 | { 21 | public: 22 | base_sink(); 23 | explicit base_sink(std::unique_ptr formatter); 24 | base_sink(const base_sink &) = delete; 25 | base_sink &operator=(const base_sink &) = delete; 26 | void log(const details::log_msg &msg) final; 27 | void flush() final; 28 | void set_pattern(const std::string &pattern) final; 29 | void set_formatter(std::unique_ptr sink_formatter) final; 30 | 31 | protected: 32 | // sink formatter 33 | std::unique_ptr formatter_; 34 | Mutex mutex_; 35 | 36 | virtual void sink_it_(const details::log_msg &msg) = 0; 37 | virtual void flush_() = 0; 38 | virtual void set_pattern_(const std::string &pattern); 39 | virtual void set_formatter_(std::unique_ptr sink_formatter); 40 | }; 41 | } // namespace sinks 42 | } // namespace spdlog 43 | 44 | #ifdef SPDLOG_HEADER_ONLY 45 | #include "base_sink-inl.h" 46 | #endif 47 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/sinks/basic_file_sink.h" 8 | #endif 9 | 10 | #include "spdlog/common.h" 11 | #include "spdlog/details/os.h" 12 | 13 | namespace spdlog { 14 | namespace sinks { 15 | 16 | template 17 | SPDLOG_INLINE basic_file_sink::basic_file_sink(const filename_t &filename, bool truncate) 18 | { 19 | file_helper_.open(filename, truncate); 20 | } 21 | 22 | template 23 | SPDLOG_INLINE const filename_t &basic_file_sink::filename() const 24 | { 25 | return file_helper_.filename(); 26 | } 27 | 28 | template 29 | SPDLOG_INLINE void basic_file_sink::sink_it_(const details::log_msg &msg) 30 | { 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 | { 39 | file_helper_.flush(); 40 | } 41 | 42 | } // namespace sinks 43 | } // namespace spdlog 44 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/file_helper.h" 7 | #include "spdlog/details/null_mutex.h" 8 | #include "spdlog/sinks/base_sink.h" 9 | #include "spdlog/details/synchronous_factory.h" 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 | { 22 | public: 23 | explicit basic_file_sink(const filename_t &filename, bool truncate = false); 24 | const filename_t &filename() const; 25 | 26 | protected: 27 | void sink_it_(const details::log_msg &msg) override; 28 | void flush_() override; 29 | 30 | private: 31 | details::file_helper file_helper_; 32 | }; 33 | 34 | using basic_file_sink_mt = basic_file_sink; 35 | using basic_file_sink_st = basic_file_sink; 36 | 37 | } // namespace sinks 38 | 39 | // 40 | // factory functions 41 | // 42 | template 43 | inline std::shared_ptr basic_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false) 44 | { 45 | return Factory::template create(logger_name, filename, truncate); 46 | } 47 | 48 | template 49 | inline std::shared_ptr basic_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false) 50 | { 51 | return Factory::template create(logger_name, filename, truncate); 52 | } 53 | 54 | } // namespace spdlog 55 | 56 | #ifdef SPDLOG_HEADER_ONLY 57 | #include "basic_file_sink-inl.h" 58 | #endif -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/log_msg.h" 8 | #include "spdlog/details/null_mutex.h" 9 | #include "spdlog/details/pattern_formatter.h" 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 | { 25 | public: 26 | dist_sink() = default; 27 | dist_sink(const dist_sink &) = delete; 28 | dist_sink &operator=(const dist_sink &) = delete; 29 | 30 | void add_sink(std::shared_ptr sink) 31 | { 32 | std::lock_guard lock(base_sink::mutex_); 33 | sinks_.push_back(sink); 34 | } 35 | 36 | void remove_sink(std::shared_ptr sink) 37 | { 38 | std::lock_guard lock(base_sink::mutex_); 39 | sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); 40 | } 41 | 42 | void set_sinks(std::vector> sinks) 43 | { 44 | std::lock_guard lock(base_sink::mutex_); 45 | sinks_ = std::move(sinks); 46 | } 47 | 48 | std::vector> &sinks() 49 | { 50 | return sinks_; 51 | } 52 | 53 | protected: 54 | void sink_it_(const details::log_msg &msg) override 55 | { 56 | for (auto &sink : sinks_) 57 | { 58 | if (sink->should_log(msg.level)) 59 | { 60 | sink->log(msg); 61 | } 62 | } 63 | } 64 | 65 | void flush_() override 66 | { 67 | for (auto &sink : sinks_) 68 | { 69 | sink->flush(); 70 | } 71 | } 72 | 73 | void set_pattern_(const std::string &pattern) override 74 | { 75 | set_formatter_(details::make_unique(pattern)); 76 | } 77 | 78 | void set_formatter_(std::unique_ptr sink_formatter) override 79 | { 80 | base_sink::formatter_ = std::move(sink_formatter); 81 | for (auto &sink : sinks_) 82 | { 83 | sink->set_formatter(base_sink::formatter_->clone()); 84 | } 85 | } 86 | std::vector> sinks_; 87 | }; 88 | 89 | using dist_sink_mt = dist_sink; 90 | using dist_sink_st = dist_sink; 91 | 92 | } // namespace sinks 93 | } // namespace spdlog 94 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/null_mutex.h" 8 | #include "spdlog/details/log_msg.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | // Duplicate message removal sink. 15 | // Skip the message if previous one is identical and less than "max_skip_duration" have passed 16 | // 17 | // Example: 18 | // 19 | // #include "spdlog/sinks/dup_filter_sink.h" 20 | // 21 | // int main() { 22 | // auto dup_filter = std::make_shared(std::chrono::seconds(5)); 23 | // dup_filter->add_sink(std::make_shared()); 24 | // spdlog::logger l("logger", dup_filter); 25 | // l.info("Hello"); 26 | // l.info("Hello"); 27 | // l.info("Hello"); 28 | // l.info("Different Hello"); 29 | // } 30 | // 31 | // Will produce: 32 | // [2019-06-25 17:50:56.511] [logger] [info] Hello 33 | // [2019-06-25 17:50:56.512] [logger] [info] Skipped 3 duplicate messages.. 34 | // [2019-06-25 17:50:56.512] [logger] [info] Different Hello 35 | 36 | #ifdef SPDLOG_NO_DATETIME 37 | #error "spdlog::sinks::dup_filter_sink: cannot work when SPDLOG_NO_DATETIME is defined" 38 | #endif 39 | 40 | namespace spdlog { 41 | namespace sinks { 42 | template 43 | class dup_filter_sink : public dist_sink 44 | { 45 | public: 46 | template 47 | explicit dup_filter_sink(std::chrono::duration max_skip_duration) 48 | : max_skip_duration_{max_skip_duration} 49 | {} 50 | 51 | protected: 52 | std::chrono::microseconds max_skip_duration_; 53 | log_clock::time_point last_msg_time_; 54 | std::string last_msg_payload_; 55 | size_t skip_counter_ = 0; 56 | 57 | void sink_it_(const details::log_msg &msg) override 58 | { 59 | bool filtered = filter_(msg); 60 | if (!filtered) 61 | { 62 | skip_counter_ += 1; 63 | return; 64 | } 65 | 66 | // log the "skipped.." message 67 | if (skip_counter_ > 0) 68 | { 69 | memory_buf_t buf; 70 | fmt::format_to(buf, "Skipped {} duplicate messages..", skip_counter_); 71 | details::log_msg skipped_msg{msg.logger_name, msg.level, string_view_t{buf.data(), buf.size()}}; 72 | dist_sink::sink_it_(skipped_msg); 73 | } 74 | 75 | // log current message 76 | dist_sink::sink_it_(msg); 77 | last_msg_time_ = msg.time; 78 | skip_counter_ = 0; 79 | last_msg_payload_.assign(msg.payload.data(), msg.payload.data() + msg.payload.size()); 80 | } 81 | 82 | // return whether the log msg should be displayed (true) or skipped (false) 83 | bool filter_(const details::log_msg &msg) 84 | { 85 | auto filter_duration = msg.time - last_msg_time_; 86 | return (filter_duration > max_skip_duration_) || (msg.payload != last_msg_payload_); 87 | } 88 | }; 89 | 90 | using dup_filter_sink_mt = dup_filter_sink; 91 | using dup_filter_sink_st = dup_filter_sink; 92 | 93 | } // namespace sinks 94 | } // namespace spdlog 95 | -------------------------------------------------------------------------------- /extern/include/spdlog/sinks/msvc_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2016 Alexander Dalshov. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #if defined(_WIN32) 7 | 8 | #include "spdlog/details/null_mutex.h" 9 | #include "spdlog/sinks/base_sink.h" 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace spdlog { 17 | namespace sinks { 18 | /* 19 | * MSVC sink (logging using OutputDebugStringA) 20 | */ 21 | template 22 | class msvc_sink : public base_sink 23 | { 24 | public: 25 | explicit msvc_sink() {} 26 | 27 | protected: 28 | void sink_it_(const details::log_msg &msg) override 29 | { 30 | 31 | memory_buf_t formatted; 32 | base_sink::formatter_->format(msg, formatted); 33 | OutputDebugStringA(fmt::to_string(formatted).c_str()); 34 | } 35 | 36 | void flush_() override {} 37 | }; 38 | 39 | using msvc_sink_mt = msvc_sink; 40 | using msvc_sink_st = msvc_sink; 41 | 42 | using windebug_sink_mt = msvc_sink_mt; 43 | using windebug_sink_st = msvc_sink_st; 44 | 45 | } // namespace sinks 46 | } // namespace spdlog 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/null_mutex.h" 7 | #include "spdlog/sinks/base_sink.h" 8 | #include "spdlog/details/synchronous_factory.h" 9 | 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | 15 | template 16 | class null_sink : public base_sink 17 | { 18 | protected: 19 | void sink_it_(const details::log_msg &) override {} 20 | void flush_() override {} 21 | }; 22 | 23 | using null_sink_mt = null_sink; 24 | using null_sink_st = null_sink; 25 | 26 | } // namespace sinks 27 | 28 | template 29 | inline std::shared_ptr null_logger_mt(const std::string &logger_name) 30 | { 31 | auto null_logger = Factory::template create(logger_name); 32 | null_logger->set_level(level::off); 33 | return null_logger; 34 | } 35 | 36 | template 37 | inline std::shared_ptr null_logger_st(const std::string &logger_name) 38 | { 39 | auto null_logger = Factory::template create(logger_name); 40 | null_logger->set_level(level::off); 41 | return null_logger; 42 | } 43 | 44 | } // namespace spdlog 45 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/null_mutex.h" 7 | #include "spdlog/sinks/base_sink.h" 8 | 9 | #include 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | template 15 | class ostream_sink final : public base_sink 16 | { 17 | public: 18 | explicit ostream_sink(std::ostream &os, bool force_flush = false) 19 | : ostream_(os) 20 | , force_flush_(force_flush) 21 | {} 22 | ostream_sink(const ostream_sink &) = delete; 23 | ostream_sink &operator=(const ostream_sink &) = delete; 24 | 25 | protected: 26 | void sink_it_(const details::log_msg &msg) override 27 | { 28 | memory_buf_t formatted; 29 | base_sink::formatter_->format(msg, formatted); 30 | ostream_.write(formatted.data(), static_cast(formatted.size())); 31 | if (force_flush_) 32 | { 33 | ostream_.flush(); 34 | } 35 | } 36 | 37 | void flush_() override 38 | { 39 | ostream_.flush(); 40 | } 41 | 42 | std::ostream &ostream_; 43 | bool force_flush_; 44 | }; 45 | 46 | using ostream_sink_mt = ostream_sink; 47 | using ostream_sink_st = ostream_sink; 48 | 49 | } // namespace sinks 50 | } // namespace spdlog 51 | -------------------------------------------------------------------------------- /extern/include/spdlog/sinks/rotating_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 "spdlog/sinks/rotating_file_sink.h" 8 | #endif 9 | 10 | #include "spdlog/common.h" 11 | 12 | #include "spdlog/details/file_helper.h" 13 | #include "spdlog/details/null_mutex.h" 14 | #include "spdlog/fmt/fmt.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace spdlog { 24 | namespace sinks { 25 | 26 | template 27 | SPDLOG_INLINE rotating_file_sink::rotating_file_sink( 28 | filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open) 29 | : base_filename_(std::move(base_filename)) 30 | , max_size_(max_size) 31 | , max_files_(max_files) 32 | { 33 | file_helper_.open(calc_filename(base_filename_, 0)); 34 | current_size_ = file_helper_.size(); // expensive. called only once 35 | if (rotate_on_open && current_size_ > 0) 36 | { 37 | rotate_(); 38 | } 39 | } 40 | 41 | // calc filename according to index and file extension if exists. 42 | // e.g. calc_filename("logs/mylog.txt, 3) => "logs/mylog.3.txt". 43 | template 44 | SPDLOG_INLINE filename_t rotating_file_sink::calc_filename(const filename_t &filename, std::size_t index) 45 | { 46 | if (index == 0u) 47 | { 48 | return filename; 49 | } 50 | 51 | filename_t basename, ext; 52 | std::tie(basename, ext) = details::file_helper::split_by_extension(filename); 53 | return fmt::format(SPDLOG_FILENAME_T("{}.{}{}"), basename, index, ext); 54 | } 55 | 56 | template 57 | SPDLOG_INLINE const filename_t &rotating_file_sink::filename() const 58 | { 59 | return file_helper_.filename(); 60 | } 61 | 62 | template 63 | SPDLOG_INLINE void rotating_file_sink::sink_it_(const details::log_msg &msg) 64 | { 65 | memory_buf_t formatted; 66 | base_sink::formatter_->format(msg, formatted); 67 | current_size_ += formatted.size(); 68 | if (current_size_ > max_size_) 69 | { 70 | rotate_(); 71 | current_size_ = formatted.size(); 72 | } 73 | file_helper_.write(formatted); 74 | } 75 | 76 | template 77 | SPDLOG_INLINE void rotating_file_sink::flush_() 78 | { 79 | file_helper_.flush(); 80 | } 81 | 82 | // Rotate files: 83 | // log.txt -> log.1.txt 84 | // log.1.txt -> log.2.txt 85 | // log.2.txt -> log.3.txt 86 | // log.3.txt -> delete 87 | template 88 | SPDLOG_INLINE void rotating_file_sink::rotate_() 89 | { 90 | using details::os::filename_to_str; 91 | file_helper_.close(); 92 | for (auto i = max_files_; i > 0; --i) 93 | { 94 | filename_t src = calc_filename(base_filename_, i - 1); 95 | if (!details::file_helper::file_exists(src)) 96 | { 97 | continue; 98 | } 99 | filename_t target = calc_filename(base_filename_, i); 100 | 101 | if (!rename_file(src, target)) 102 | { 103 | // if failed try again after a small delay. 104 | // this is a workaround to a windows issue, where very high rotation 105 | // rates can cause the rename to fail with permission denied (because of antivirus?). 106 | details::os::sleep_for_millis(100); 107 | if (!rename_file(src, target)) 108 | { 109 | file_helper_.reopen(true); // truncate the log file anyway to prevent it to grow beyond its limit! 110 | current_size_ = 0; 111 | SPDLOG_THROW( 112 | spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno)); 113 | } 114 | } 115 | } 116 | file_helper_.reopen(true); 117 | } 118 | 119 | // delete the target if exists, and rename the src file to target 120 | // return true on success, false otherwise. 121 | template 122 | SPDLOG_INLINE bool rotating_file_sink::rename_file(const filename_t &src_filename, const filename_t &target_filename) 123 | { 124 | // try to delete the target file in case it already exists. 125 | (void)details::os::remove(target_filename); 126 | return details::os::rename(src_filename, target_filename) == 0; 127 | } 128 | 129 | } // namespace sinks 130 | } // namespace spdlog 131 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/sinks/base_sink.h" 7 | #include "spdlog/details/file_helper.h" 8 | #include "spdlog/details/null_mutex.h" 9 | #include "spdlog/details/synchronous_factory.h" 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 | { 24 | public: 25 | rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false); 26 | static filename_t calc_filename(const filename_t &filename, std::size_t index); 27 | const filename_t &filename() const; 28 | 29 | protected: 30 | void sink_it_(const details::log_msg &msg) override; 31 | void flush_() override; 32 | 33 | private: 34 | // Rotate files: 35 | // log.txt -> log.1.txt 36 | // log.1.txt -> log.2.txt 37 | // log.2.txt -> log.3.txt 38 | // log.3.txt -> delete 39 | void rotate_(); 40 | 41 | // delete the target if exists, and rename the src file to target 42 | // return true on success, false otherwise. 43 | bool rename_file(const filename_t &src_filename, const filename_t &target_filename); 44 | 45 | filename_t base_filename_; 46 | std::size_t max_size_; 47 | std::size_t max_files_; 48 | std::size_t current_size_; 49 | details::file_helper file_helper_; 50 | }; 51 | 52 | using rotating_file_sink_mt = rotating_file_sink; 53 | using rotating_file_sink_st = rotating_file_sink; 54 | 55 | } // namespace sinks 56 | 57 | // 58 | // factory functions 59 | // 60 | 61 | template 62 | inline std::shared_ptr rotating_logger_mt( 63 | const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files, bool rotate_on_open = false) 64 | { 65 | return Factory::template create(logger_name, filename, max_file_size, max_files, rotate_on_open); 66 | } 67 | 68 | template 69 | inline std::shared_ptr rotating_logger_st( 70 | const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files, bool rotate_on_open = false) 71 | { 72 | return Factory::template create(logger_name, filename, max_file_size, max_files, rotate_on_open); 73 | } 74 | } // namespace spdlog 75 | 76 | #ifdef SPDLOG_HEADER_ONLY 77 | #include "rotating_file_sink-inl.h" 78 | #endif -------------------------------------------------------------------------------- /extern/include/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 "spdlog/sinks/sink.h" 8 | #endif 9 | 10 | #include "spdlog/common.h" 11 | 12 | SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const 13 | { 14 | return msg_level >= level_.load(std::memory_order_relaxed); 15 | } 16 | 17 | SPDLOG_INLINE void spdlog::sinks::sink::set_level(level::level_enum log_level) 18 | { 19 | level_.store(log_level, std::memory_order_relaxed); 20 | } 21 | 22 | SPDLOG_INLINE spdlog::level::level_enum spdlog::sinks::sink::level() const 23 | { 24 | return static_cast(level_.load(std::memory_order_relaxed)); 25 | } 26 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/log_msg.h" 7 | #include "spdlog/formatter.h" 8 | 9 | namespace spdlog { 10 | 11 | namespace sinks { 12 | class sink 13 | { 14 | public: 15 | virtual ~sink() = default; 16 | virtual void log(const details::log_msg &msg) = 0; 17 | virtual void flush() = 0; 18 | virtual void set_pattern(const std::string &pattern) = 0; 19 | virtual void set_formatter(std::unique_ptr sink_formatter) = 0; 20 | 21 | void set_level(level::level_enum log_level); 22 | level::level_enum level() const; 23 | bool should_log(level::level_enum msg_level) const; 24 | 25 | protected: 26 | // sink log level - default is all 27 | level_t level_{level::trace}; 28 | }; 29 | 30 | } // namespace sinks 31 | } // namespace spdlog 32 | 33 | #ifdef SPDLOG_HEADER_ONLY 34 | #include "sink-inl.h" 35 | #endif 36 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/sinks/stdout_color_sinks.h" 8 | #endif 9 | 10 | #include "spdlog/logger.h" 11 | #include "spdlog/common.h" 12 | 13 | namespace spdlog { 14 | 15 | template 16 | SPDLOG_INLINE std::shared_ptr stdout_color_mt(const std::string &logger_name, color_mode mode) 17 | { 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, color_mode mode) 23 | { 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, color_mode mode) 29 | { 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, color_mode mode) 35 | { 36 | return Factory::template create(logger_name, mode); 37 | } 38 | } // namespace spdlog -------------------------------------------------------------------------------- /extern/include/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 "spdlog/sinks/wincolor_sink.h" 8 | #else 9 | #include "spdlog/sinks/ansicolor_sink.h" 10 | #endif 11 | 12 | #include "spdlog/details/synchronous_factory.h" 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, color_mode mode = color_mode::automatic); 31 | 32 | template 33 | std::shared_ptr stdout_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic); 34 | 35 | template 36 | std::shared_ptr stderr_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic); 37 | 38 | template 39 | std::shared_ptr stderr_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic); 40 | 41 | } // namespace spdlog 42 | 43 | #ifdef SPDLOG_HEADER_ONLY 44 | #include "stdout_color_sinks-inl.h" 45 | #endif 46 | -------------------------------------------------------------------------------- /extern/include/spdlog/sinks/stdout_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 "spdlog/sinks/stdout_sinks.h" 8 | #endif 9 | 10 | #include "spdlog/details/console_globals.h" 11 | #include "spdlog/details/pattern_formatter.h" 12 | #include 13 | 14 | namespace spdlog { 15 | 16 | namespace sinks { 17 | 18 | template 19 | SPDLOG_INLINE stdout_sink_base::stdout_sink_base(FILE *file) 20 | : mutex_(ConsoleMutex::mutex()) 21 | , file_(file) 22 | , formatter_(details::make_unique()) 23 | {} 24 | 25 | template 26 | SPDLOG_INLINE void stdout_sink_base::log(const details::log_msg &msg) 27 | { 28 | std::lock_guard lock(mutex_); 29 | memory_buf_t formatted; 30 | formatter_->format(msg, formatted); 31 | fwrite(formatted.data(), sizeof(char), formatted.size(), file_); 32 | fflush(file_); // flush every line to terminal 33 | } 34 | 35 | template 36 | SPDLOG_INLINE void stdout_sink_base::flush() 37 | { 38 | std::lock_guard lock(mutex_); 39 | fflush(file_); 40 | } 41 | 42 | template 43 | SPDLOG_INLINE void stdout_sink_base::set_pattern(const std::string &pattern) 44 | { 45 | std::lock_guard lock(mutex_); 46 | formatter_ = std::unique_ptr(new pattern_formatter(pattern)); 47 | } 48 | 49 | template 50 | SPDLOG_INLINE void stdout_sink_base::set_formatter(std::unique_ptr sink_formatter) 51 | { 52 | std::lock_guard lock(mutex_); 53 | formatter_ = std::move(sink_formatter); 54 | } 55 | 56 | // stdout sink 57 | template 58 | SPDLOG_INLINE stdout_sink::stdout_sink() 59 | : stdout_sink_base(stdout) 60 | {} 61 | 62 | // stderr sink 63 | template 64 | SPDLOG_INLINE stderr_sink::stderr_sink() 65 | : stdout_sink_base(stderr) 66 | {} 67 | 68 | } // namespace sinks 69 | 70 | // factory methods 71 | template 72 | SPDLOG_INLINE std::shared_ptr stdout_logger_mt(const std::string &logger_name) 73 | { 74 | return Factory::template create(logger_name); 75 | } 76 | 77 | template 78 | SPDLOG_INLINE std::shared_ptr stdout_logger_st(const std::string &logger_name) 79 | { 80 | return Factory::template create(logger_name); 81 | } 82 | 83 | template 84 | SPDLOG_INLINE std::shared_ptr stderr_logger_mt(const std::string &logger_name) 85 | { 86 | return Factory::template create(logger_name); 87 | } 88 | 89 | template 90 | SPDLOG_INLINE std::shared_ptr stderr_logger_st(const std::string &logger_name) 91 | { 92 | return Factory::template create(logger_name); 93 | } 94 | } // namespace spdlog 95 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/details/console_globals.h" 7 | #include "spdlog/details/synchronous_factory.h" 8 | #include "spdlog/sinks/sink.h" 9 | #include 10 | 11 | namespace spdlog { 12 | 13 | namespace sinks { 14 | 15 | template 16 | class stdout_sink_base : public sink 17 | { 18 | public: 19 | using mutex_t = typename ConsoleMutex::mutex_t; 20 | explicit stdout_sink_base(FILE *file); 21 | ~stdout_sink_base() override = default; 22 | stdout_sink_base(const stdout_sink_base &other) = delete; 23 | stdout_sink_base &operator=(const stdout_sink_base &other) = delete; 24 | 25 | void log(const details::log_msg &msg) override; 26 | void flush() override; 27 | void set_pattern(const std::string &pattern) override; 28 | 29 | void set_formatter(std::unique_ptr sink_formatter) override; 30 | 31 | protected: 32 | mutex_t &mutex_; 33 | FILE *file_; 34 | std::unique_ptr formatter_; 35 | }; 36 | 37 | template 38 | class stdout_sink : public stdout_sink_base 39 | { 40 | public: 41 | stdout_sink(); 42 | }; 43 | 44 | template 45 | class stderr_sink : public stdout_sink_base 46 | { 47 | public: 48 | stderr_sink(); 49 | }; 50 | 51 | using stdout_sink_mt = stdout_sink; 52 | using stdout_sink_st = stdout_sink; 53 | 54 | using stderr_sink_mt = stderr_sink; 55 | using stderr_sink_st = stderr_sink; 56 | 57 | } // namespace sinks 58 | 59 | // factory methods 60 | template 61 | std::shared_ptr stdout_logger_mt(const std::string &logger_name); 62 | 63 | template 64 | std::shared_ptr stdout_logger_st(const std::string &logger_name); 65 | 66 | template 67 | std::shared_ptr stderr_logger_mt(const std::string &logger_name); 68 | 69 | template 70 | std::shared_ptr stderr_logger_st(const std::string &logger_name); 71 | 72 | } // namespace spdlog 73 | 74 | #ifdef SPDLOG_HEADER_ONLY 75 | #include "stdout_sinks-inl.h" 76 | #endif 77 | -------------------------------------------------------------------------------- /extern/include/spdlog/sinks/syslog_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/sinks/base_sink.h" 7 | #include "spdlog/details/null_mutex.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | namespace sinks { 15 | /** 16 | * Sink that write to syslog using the `syscall()` library call. 17 | */ 18 | template 19 | class syslog_sink : public base_sink 20 | { 21 | 22 | public: 23 | syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting) 24 | : enable_formatting_{enable_formatting} 25 | , syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG, 26 | /* spdlog::level::debug */ LOG_DEBUG, 27 | /* spdlog::level::info */ LOG_INFO, 28 | /* spdlog::level::warn */ LOG_WARNING, 29 | /* spdlog::level::err */ LOG_ERR, 30 | /* spdlog::level::critical */ LOG_CRIT, 31 | /* spdlog::level::off */ LOG_INFO}} 32 | , ident_{std::move(ident)} 33 | { 34 | // set ident to be program name if empty 35 | ::openlog(ident_.empty() ? nullptr : ident_.c_str(), syslog_option, syslog_facility); 36 | } 37 | 38 | ~syslog_sink() override 39 | { 40 | ::closelog(); 41 | } 42 | 43 | syslog_sink(const syslog_sink &) = delete; 44 | syslog_sink &operator=(const syslog_sink &) = delete; 45 | 46 | protected: 47 | void sink_it_(const details::log_msg &msg) override 48 | { 49 | string_view_t payload; 50 | memory_buf_t formatted; 51 | if (enable_formatting_) 52 | { 53 | base_sink::formatter_->format(msg, formatted); 54 | payload = string_view_t(formatted.data(), formatted.size()); 55 | } 56 | else 57 | { 58 | payload = msg.payload; 59 | } 60 | 61 | size_t length = payload.size(); 62 | // limit to max int 63 | if (length > static_cast(std::numeric_limits::max())) 64 | { 65 | length = static_cast(std::numeric_limits::max()); 66 | } 67 | 68 | ::syslog(syslog_prio_from_level(msg), "%.*s", static_cast(length), payload.data()); 69 | } 70 | 71 | void flush_() override {} 72 | bool enable_formatting_ = false; 73 | 74 | private: 75 | using levels_array = std::array; 76 | levels_array syslog_levels_; 77 | // must store the ident because the man says openlog might use the pointer as 78 | // is and not a string copy 79 | const std::string ident_; 80 | 81 | // 82 | // Simply maps spdlog's log level to syslog priority level. 83 | // 84 | int syslog_prio_from_level(const details::log_msg &msg) const 85 | { 86 | return syslog_levels_.at(static_cast(msg.level)); 87 | } 88 | }; 89 | 90 | using syslog_sink_mt = syslog_sink; 91 | using syslog_sink_st = syslog_sink; 92 | } // namespace sinks 93 | 94 | // Create and register a syslog logger 95 | template 96 | inline std::shared_ptr syslog_logger_mt(const std::string &logger_name, const std::string &syslog_ident = "", int syslog_option = 0, 97 | int syslog_facility = LOG_USER, bool enable_formatting = false) 98 | { 99 | return Factory::template create(logger_name, syslog_ident, syslog_option, syslog_facility, enable_formatting); 100 | } 101 | 102 | template 103 | inline std::shared_ptr syslog_logger_st(const std::string &logger_name, const std::string &syslog_ident = "", int syslog_option = 0, 104 | int syslog_facility = LOG_USER, bool enable_formatting = false) 105 | { 106 | return Factory::template create(logger_name, syslog_ident, syslog_option, syslog_facility, enable_formatting); 107 | } 108 | } // namespace spdlog 109 | -------------------------------------------------------------------------------- /extern/include/spdlog/sinks/systemd_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2019 ZVYAGIN.Alexander@gmail.com 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/sinks/base_sink.h" 7 | #include "spdlog/details/null_mutex.h" 8 | #include "spdlog/details/synchronous_factory.h" 9 | 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | 15 | /** 16 | * Sink that write to systemd journal using the `sd_journal_send()` library call. 17 | * 18 | * Locking is not needed, as `sd_journal_send()` itself is thread-safe. 19 | */ 20 | template 21 | class systemd_sink : public base_sink 22 | { 23 | public: 24 | // 25 | systemd_sink() 26 | : syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG, 27 | /* spdlog::level::debug */ LOG_DEBUG, 28 | /* spdlog::level::info */ LOG_INFO, 29 | /* spdlog::level::warn */ LOG_WARNING, 30 | /* spdlog::level::err */ LOG_ERR, 31 | /* spdlog::level::critical */ LOG_CRIT, 32 | /* spdlog::level::off */ LOG_INFO}} 33 | {} 34 | 35 | ~systemd_sink() override {} 36 | 37 | systemd_sink(const systemd_sink &) = delete; 38 | systemd_sink &operator=(const systemd_sink &) = delete; 39 | 40 | protected: 41 | using levels_array = std::array; 42 | levels_array syslog_levels_; 43 | 44 | void sink_it_(const details::log_msg &msg) override 45 | { 46 | int err; 47 | 48 | size_t length = msg.payload.size(); 49 | // limit to max int 50 | if (length > static_cast(std::numeric_limits::max())) 51 | { 52 | length = static_cast(std::numeric_limits::max()); 53 | } 54 | 55 | // Do not send source location if not available 56 | if (msg.source.empty()) 57 | { 58 | // Note: function call inside '()' to avoid macro expansion 59 | err = (sd_journal_send)( 60 | "MESSAGE=%.*s", static_cast(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), nullptr); 61 | } 62 | else 63 | { 64 | err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), 65 | "SOURCE_FILE=%s", msg.source.filename, "SOURCE_LINE=%d", msg.source.line, "SOURCE_FUNC=%s", msg.source.funcname, nullptr); 66 | } 67 | 68 | if (err) 69 | { 70 | SPDLOG_THROW(spdlog_ex("Failed writing to systemd", errno)); 71 | } 72 | } 73 | 74 | int syslog_level(level::level_enum l) 75 | { 76 | return syslog_levels_.at(static_cast(l)); 77 | } 78 | 79 | void flush_() override {} 80 | }; 81 | 82 | using systemd_sink_mt = systemd_sink; 83 | using systemd_sink_st = systemd_sink; 84 | } // namespace sinks 85 | 86 | // Create and register a syslog logger 87 | template 88 | inline std::shared_ptr systemd_logger_mt(const std::string &logger_name) 89 | { 90 | return Factory::template create(logger_name); 91 | } 92 | 93 | template 94 | inline std::shared_ptr systemd_logger_st(const std::string &logger_name) 95 | { 96 | return Factory::template create(logger_name); 97 | } 98 | } // namespace spdlog 99 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/common.h" 7 | #include "spdlog/details/console_globals.h" 8 | #include "spdlog/details/null_mutex.h" 9 | #include "spdlog/sinks/sink.h" 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 | { 26 | public: 27 | const WORD BOLD = FOREGROUND_INTENSITY; 28 | const WORD RED = FOREGROUND_RED; 29 | const WORD GREEN = FOREGROUND_GREEN; 30 | const WORD CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE; 31 | const WORD WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; 32 | const WORD YELLOW = FOREGROUND_RED | FOREGROUND_GREEN; 33 | 34 | wincolor_sink(HANDLE out_handle, color_mode mode); 35 | ~wincolor_sink() override; 36 | 37 | wincolor_sink(const wincolor_sink &other) = delete; 38 | wincolor_sink &operator=(const wincolor_sink &other) = delete; 39 | 40 | // change the color for the given level 41 | void set_color(level::level_enum level, WORD color); 42 | void log(const details::log_msg &msg) final override; 43 | void flush() final override; 44 | void set_pattern(const std::string &pattern) override final; 45 | void set_formatter(std::unique_ptr sink_formatter) override final; 46 | void set_color_mode(color_mode mode); 47 | 48 | protected: 49 | using mutex_t = typename ConsoleMutex::mutex_t; 50 | HANDLE out_handle_; 51 | mutex_t &mutex_; 52 | bool in_console_; 53 | bool should_do_colors_; 54 | std::unique_ptr formatter_; 55 | std::unordered_map colors_; 56 | 57 | // set foreground color and return the orig console attributes (for resetting later) 58 | WORD set_foreground_color_(WORD attribs); 59 | 60 | // print a range of formatted message to console 61 | void print_range_(const memory_buf_t &formatted, size_t start, size_t end); 62 | 63 | // in case we are redirected to file (not in console mode) 64 | void write_to_file_(const memory_buf_t &formatted); 65 | }; 66 | 67 | template 68 | class wincolor_stdout_sink : public wincolor_sink 69 | { 70 | public: 71 | explicit wincolor_stdout_sink(color_mode mode = color_mode::automatic); 72 | }; 73 | 74 | template 75 | class wincolor_stderr_sink : public wincolor_sink 76 | { 77 | public: 78 | explicit wincolor_stderr_sink(color_mode mode = color_mode::automatic); 79 | }; 80 | 81 | using wincolor_stdout_sink_mt = wincolor_stdout_sink; 82 | using wincolor_stdout_sink_st = wincolor_stdout_sink; 83 | 84 | using wincolor_stderr_sink_mt = wincolor_stderr_sink; 85 | using wincolor_stderr_sink_st = wincolor_stderr_sink; 86 | 87 | } // namespace sinks 88 | } // namespace spdlog 89 | 90 | #ifdef SPDLOG_HEADER_ONLY 91 | #include "wincolor_sink-inl.h" 92 | #endif 93 | -------------------------------------------------------------------------------- /extern/include/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 "spdlog/spdlog.h" 8 | #endif 9 | 10 | #include "spdlog/common.h" 11 | #include "spdlog/details/pattern_formatter.h" 12 | 13 | namespace spdlog { 14 | 15 | SPDLOG_INLINE void initialize_logger(std::shared_ptr logger) 16 | { 17 | details::registry::instance().initialize_logger(std::move(logger)); 18 | } 19 | 20 | SPDLOG_INLINE std::shared_ptr get(const std::string &name) 21 | { 22 | return details::registry::instance().get(name); 23 | } 24 | 25 | SPDLOG_INLINE void set_formatter(std::unique_ptr formatter) 26 | { 27 | details::registry::instance().set_formatter(std::move(formatter)); 28 | } 29 | 30 | SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type) 31 | { 32 | set_formatter(std::unique_ptr(new pattern_formatter(std::move(pattern), time_type))); 33 | } 34 | 35 | SPDLOG_INLINE void enable_backtrace(size_t n_messages) 36 | { 37 | details::registry::instance().enable_backtrace(n_messages); 38 | } 39 | 40 | SPDLOG_INLINE void disable_backtrace() 41 | { 42 | details::registry::instance().disable_backtrace(); 43 | } 44 | 45 | SPDLOG_INLINE void dump_backtrace() 46 | { 47 | default_logger_raw()->dump_backtrace(); 48 | } 49 | 50 | SPDLOG_INLINE void set_level(level::level_enum log_level) 51 | { 52 | details::registry::instance().set_level(log_level); 53 | } 54 | 55 | SPDLOG_INLINE void flush_on(level::level_enum log_level) 56 | { 57 | details::registry::instance().flush_on(log_level); 58 | } 59 | 60 | SPDLOG_INLINE void flush_every(std::chrono::seconds interval) 61 | { 62 | details::registry::instance().flush_every(interval); 63 | } 64 | 65 | SPDLOG_INLINE void set_error_handler(void (*handler)(const std::string &msg)) 66 | { 67 | details::registry::instance().set_error_handler(handler); 68 | } 69 | 70 | SPDLOG_INLINE void register_logger(std::shared_ptr logger) 71 | { 72 | details::registry::instance().register_logger(std::move(logger)); 73 | } 74 | 75 | SPDLOG_INLINE void apply_all(const std::function)> &fun) 76 | { 77 | details::registry::instance().apply_all(fun); 78 | } 79 | 80 | SPDLOG_INLINE void drop(const std::string &name) 81 | { 82 | details::registry::instance().drop(name); 83 | } 84 | 85 | SPDLOG_INLINE void drop_all() 86 | { 87 | details::registry::instance().drop_all(); 88 | } 89 | 90 | SPDLOG_INLINE void shutdown() 91 | { 92 | details::registry::instance().shutdown(); 93 | } 94 | 95 | SPDLOG_INLINE void set_automatic_registration(bool automatic_registation) 96 | { 97 | details::registry::instance().set_automatic_registration(automatic_registation); 98 | } 99 | 100 | SPDLOG_INLINE std::shared_ptr default_logger() 101 | { 102 | return details::registry::instance().default_logger(); 103 | } 104 | 105 | SPDLOG_INLINE spdlog::logger *default_logger_raw() 106 | { 107 | return details::registry::instance().get_default_raw(); 108 | } 109 | 110 | SPDLOG_INLINE void set_default_logger(std::shared_ptr default_logger) 111 | { 112 | details::registry::instance().set_default_logger(std::move(default_logger)); 113 | } 114 | 115 | } // namespace spdlog -------------------------------------------------------------------------------- /extern/include/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 4 8 | #define SPDLOG_VER_PATCH 2 9 | 10 | #define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH) 11 | -------------------------------------------------------------------------------- /extern/lib_x64/DxErr.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x64/DxErr.lib -------------------------------------------------------------------------------- /extern/lib_x64/d3d9.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x64/d3d9.lib -------------------------------------------------------------------------------- /extern/lib_x64/d3dx9.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x64/d3dx9.lib -------------------------------------------------------------------------------- /extern/lib_x64/dinput8.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x64/dinput8.lib -------------------------------------------------------------------------------- /extern/lib_x64/spdlog.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x64/spdlog.lib -------------------------------------------------------------------------------- /extern/lib_x64/spdlogd.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x64/spdlogd.lib -------------------------------------------------------------------------------- /extern/lib_x86/DxErr.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x86/DxErr.lib -------------------------------------------------------------------------------- /extern/lib_x86/d3d9.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x86/d3d9.lib -------------------------------------------------------------------------------- /extern/lib_x86/d3dx9.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x86/d3dx9.lib -------------------------------------------------------------------------------- /extern/lib_x86/dinput8.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x86/dinput8.lib -------------------------------------------------------------------------------- /extern/lib_x86/spdlog.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x86/spdlog.lib -------------------------------------------------------------------------------- /extern/lib_x86/spdlogd.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mq1n/WinQuickUpdater/6dd1db6c6ee01b91074e9e32eec7eaf3b4811ccf/extern/lib_x86/spdlogd.lib -------------------------------------------------------------------------------- /include/abstract_singleton.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | template 6 | class CSingleton 7 | { 8 | static T * ms_singleton; 9 | 10 | public: 11 | CSingleton() 12 | { 13 | if (ms_singleton) 14 | MessageBoxA(nullptr, typeid(T).name(), "CSingleton() DECLARED MORE THAN ONCE", MB_ICONEXCLAMATION | MB_OK); 15 | 16 | assert(!ms_singleton); 17 | ms_singleton = static_cast(this); 18 | } 19 | 20 | virtual ~CSingleton() 21 | { 22 | if (!ms_singleton) 23 | MessageBoxA(nullptr, typeid(T).name(), "~CSingleton() FREED AT RUNTIME", MB_ICONEXCLAMATION | MB_OK); 24 | 25 | assert(ms_singleton); 26 | ms_singleton = nullptr; 27 | } 28 | 29 | CSingleton(const CSingleton&) = delete; 30 | CSingleton(CSingleton&&) noexcept = delete; 31 | CSingleton& operator=(const CSingleton&) = delete; 32 | CSingleton& operator=(CSingleton&&) noexcept = delete; 33 | 34 | __forceinline static T & Instance() 35 | { 36 | if (!ms_singleton) 37 | MessageBoxA(nullptr, typeid(T).name(), "CSingleton::Instance() NEVER DECLARED", MB_ICONEXCLAMATION | MB_OK); 38 | 39 | assert(ms_singleton); 40 | return (*ms_singleton); 41 | } 42 | 43 | __forceinline static T * InstancePtr() 44 | { 45 | return (ms_singleton); 46 | } 47 | }; 48 | 49 | template 50 | T * CSingleton::ms_singleton = nullptr; 51 | -------------------------------------------------------------------------------- /include/application.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "abstract_singleton.hpp" 3 | #include "window.hpp" 4 | #include "main_ui.hpp" 5 | #include "win_updater.hpp" 6 | 7 | namespace WinQuickUpdater 8 | { 9 | class CApplication : public CSingleton 10 | { 11 | public: 12 | CApplication(int argc, char* argv[]); 13 | virtual ~CApplication(); 14 | 15 | void destroy(); 16 | int main_routine(); 17 | 18 | auto get_window() const { return m_wnd.get(); }; 19 | auto get_ui() const { return m_ui.get(); }; 20 | auto get_updater() const { return m_updater.get(); }; 21 | auto is_silent() const { return m_silent; }; 22 | 23 | protected: 24 | void parse_command_line(int argc, char* argv[]); 25 | void parse_config_file(); 26 | 27 | private: 28 | std::string m_config_file; 29 | bool m_silent; 30 | 31 | std::shared_ptr m_wnd; 32 | std::shared_ptr m_ui; 33 | std::shared_ptr m_updater; 34 | }; 35 | }; 36 | -------------------------------------------------------------------------------- /include/basic_log.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace WinQuickUpdater 8 | { 9 | static void FileLog(const std::string& stFileName, const std::string& stLogData) 10 | { 11 | std::ofstream f(stFileName.c_str(), std::ofstream::out | std::ofstream::app); 12 | f << stLogData.c_str() << std::endl; 13 | f.close(); 14 | } 15 | 16 | static void FileLogf(const std::string& stFileName, const char* c_szFormat, ...) 17 | { 18 | char szBuffer[8192] = { 0 }; 19 | 20 | va_list vaArgList; 21 | va_start(vaArgList, c_szFormat); 22 | vsprintf_s(szBuffer, c_szFormat, vaArgList); 23 | va_end(vaArgList); 24 | 25 | FileLog(stFileName.c_str(), szBuffer); 26 | } 27 | 28 | static void DebugLog(const char* c_szLogData) 29 | { 30 | OutputDebugStringA(c_szLogData); 31 | } 32 | 33 | static void DebugLogf(const char* c_szFormat, ...) 34 | { 35 | char szBuffer[8192] = { 0 }; 36 | 37 | va_list vaArgList; 38 | va_start(vaArgList, c_szFormat); 39 | vsprintf_s(szBuffer, c_szFormat, vaArgList); 40 | va_end(vaArgList); 41 | 42 | DebugLog(szBuffer); 43 | } 44 | 45 | static void ConsoleLog(const char* c_szLogData) 46 | { 47 | fputs(c_szLogData, stdout); 48 | } 49 | 50 | static void ConsoleLogf(const char* c_szFormat, ...) 51 | { 52 | char szBuffer[8192] = { 0 }; 53 | 54 | va_list vaArgList; 55 | va_start(vaArgList, c_szFormat); 56 | vsprintf_s(szBuffer, c_szFormat, vaArgList); 57 | va_end(vaArgList); 58 | 59 | ConsoleLog(szBuffer); 60 | } 61 | 62 | static void Logf(const std::string& stFileName, const char* c_szFormat, ...) 63 | { 64 | char szBuffer[8192] = { 0 }; 65 | 66 | va_list vaArgList; 67 | va_start(vaArgList, c_szFormat); 68 | vsprintf_s(szBuffer, c_szFormat, vaArgList); 69 | va_end(vaArgList); 70 | 71 | #ifdef _DEBUG 72 | DebugLog(szBuffer); 73 | #endif 74 | ConsoleLog(szBuffer); 75 | FileLog(stFileName.c_str(), szBuffer); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /include/d3d_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "abstract_singleton.hpp" 3 | 4 | namespace WinQuickUpdater 5 | { 6 | class CD3DManager : public CSingleton 7 | { 8 | public: 9 | CD3DManager(); 10 | virtual ~CD3DManager(); 11 | 12 | void CreateDevice(); 13 | void CleanupDevice(); 14 | void ResetDevice(); 15 | 16 | void SetupImGui(); 17 | void CleanupImGui(); 18 | 19 | void OnRenderFrame(); 20 | 21 | void SetWindow(HWND hWnd) { m_hWnd = hWnd; }; 22 | void SetPosition(int width, int height); 23 | 24 | auto GetD3D() const { return m_pD3DEx; }; 25 | auto GetDevice() const { return m_pD3DDevEx; }; 26 | auto GetParameters() const { return m_pD3DParams; }; 27 | HWND GetWindow() const { return m_hWnd; }; 28 | 29 | private: 30 | bool m_initialized; 31 | HWND m_hWnd; 32 | 33 | LPDIRECT3D9EX m_pD3DEx; 34 | LPDIRECT3DDEVICE9EX m_pD3DDevEx; 35 | D3DPRESENT_PARAMETERS m_pD3DParams; 36 | }; 37 | }; 38 | -------------------------------------------------------------------------------- /include/error_handler.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace WinQuickUpdater 5 | { 6 | class CError 7 | { 8 | public: 9 | CError(DWORD error_code = ::GetLastError()) : 10 | m_error_code(error_code), m_sys_err(std::system_error(std::error_code(m_error_code, std::system_category()))) {}; 11 | CError(const std::string& message, DWORD error_code = GetLastError()) : 12 | m_error_code(error_code), m_message(message), m_sys_err(std::system_error(std::error_code(m_error_code, std::system_category()), m_message)) {}; 13 | ~CError() = default; 14 | 15 | CError(const CError&) = delete; 16 | CError(CError&&) noexcept = delete; 17 | CError& operator=(const CError&) = delete; 18 | CError& operator=(CError&&) noexcept = delete; 19 | 20 | auto code() const { return m_error_code; }; 21 | auto msg() const { return m_message; }; 22 | auto what() const { return m_sys_err.what(); } 23 | 24 | private: 25 | DWORD m_error_code; 26 | std::string m_message; 27 | std::system_error m_sys_err; 28 | }; 29 | }; 30 | -------------------------------------------------------------------------------- /include/log_helper.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "abstract_singleton.hpp" 3 | #include "basic_log.hpp" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace WinQuickUpdater 11 | { 12 | static constexpr auto CUSTOM_LOG_FILENAME = "WinQuickUpdater.log"; 13 | static constexpr auto CUSTOM_LOG_ERROR_FILENAME = "WinQuickUpdaterError.log"; 14 | 15 | enum ELogLevels 16 | { 17 | LL_SYS, 18 | LL_ERR, 19 | LL_CRI, 20 | LL_WARN, 21 | LL_DEV, 22 | LL_TRACE 23 | }; 24 | 25 | class CLog : public CSingleton 26 | { 27 | public: 28 | CLog() = default; 29 | CLog(const std::string& stLoggerName, const std::string& stFileName); 30 | 31 | void Log(int32_t nLevel, const std::string& stBuffer); 32 | void LogError(const std::string& stMessage, bool bFatal = true, bool bShowLastError = true); 33 | 34 | private: 35 | mutable std::recursive_mutex m_pkMtMutex; 36 | 37 | std::shared_ptr m_pkLoggerImpl; 38 | std::string m_stLoggerName; 39 | std::string m_stFileName; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /include/main_ui.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "abstract_singleton.hpp" 3 | 4 | namespace WinQuickUpdater::gui 5 | { 6 | struct SUpdateContext 7 | { 8 | int64_t idx; 9 | std::wstring id; 10 | uint8_t type; 11 | std::wstring name; 12 | std::wstring desc; 13 | std::string date; 14 | bool checked{false}; 15 | }; 16 | enum EUpdaterStatus : uint8_t 17 | { 18 | UPDATER_STATUS_UNKNOWN, 19 | UPDATER_STATUS_INITIALIZED, 20 | UPDATER_STATUS_SEARCHING, 21 | UPDATER_STATUS_SEARCH_COMPLETED, 22 | UPDATER_STATUS_DOWNLOADING, 23 | UPDATER_STATUS_INSTALLING, 24 | UPDATER_STATUS_COMPLETED 25 | }; 26 | 27 | class main_ui : public CSingleton 28 | { 29 | public: 30 | main_ui(const std::string& title); 31 | virtual ~main_ui(); 32 | 33 | void DrawMainUI(); 34 | void OnDraw(); 35 | 36 | auto IsOpenPtr() { return &m_open; }; 37 | auto IsOpen() const { return m_open; }; 38 | 39 | std::string get_current_status(); 40 | auto can_start_update() const { return m_can_start_update; }; 41 | auto get_selected_updates() const { return m_selected_updates; }; 42 | 43 | void set_completed(const std::string& type); 44 | void set_percentage(const std::string& type, int64_t idx, int64_t perc, int64_t total); 45 | void set_status(uint8_t status); 46 | void show_progress_bar() { m_show_progressbar = true; }; 47 | void show_update_list(uint32_t item_count) { m_show_listbox = true; m_listbox_item_count = item_count; }; 48 | void add_update(const SUpdateContext& ctx) { m_updates.emplace_back(ctx); }; 49 | void add_target_update(const SUpdateContext& ctx) { m_target_updates.emplace_back(ctx); }; 50 | 51 | private: 52 | uint32_t m_start_time; 53 | std::string m_title; 54 | bool m_open; 55 | bool m_updates_open; 56 | bool m_focus; 57 | std::string m_current_object; 58 | std::vector m_updates; 59 | std::vector m_target_updates; 60 | std::vector m_selected_updates; 61 | 62 | bool m_selected; 63 | uint8_t m_status; 64 | bool m_can_start_update; 65 | 66 | bool m_show_listbox; 67 | uint32_t m_listbox_item_count; 68 | 69 | bool m_show_progressbar; 70 | uint8_t m_progressbar_step; 71 | }; 72 | }; 73 | -------------------------------------------------------------------------------- /include/pch.hpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define DIRECTINPUT_VERSION 0x0800 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 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | using namespace std::string_literals; 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | using namespace rapidjson; 37 | -------------------------------------------------------------------------------- /include/ui_types.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace WinQuickUpdater 5 | { 6 | namespace gui 7 | { 8 | class point 9 | { 10 | friend class rectangle; 11 | 12 | public: 13 | point(); 14 | point(unsigned int x, unsigned int y); 15 | 16 | virtual bool operator==(const point& pt) const; 17 | virtual bool operator!=(const point& pt) const; 18 | virtual bool operator<(const point& pt) const; 19 | virtual bool operator<=(const point& pt) const; 20 | virtual bool operator>(const point& pt) const; 21 | virtual bool operator>=(const point& pt) const; 22 | 23 | unsigned int get_x(); 24 | unsigned int get_y(); 25 | 26 | void set_x(unsigned int x); 27 | void set_y(unsigned int y); 28 | void set_x_y(unsigned int x, unsigned int y); 29 | 30 | private: unsigned int x; 31 | unsigned int y; 32 | }; 33 | 34 | class size 35 | { 36 | friend class rectangle; 37 | 38 | public: 39 | size(); 40 | size(unsigned int width, unsigned int height); 41 | size(const size& sz); 42 | 43 | bool is_zero() const; 44 | virtual bool operator==(const size& sz) const; 45 | virtual bool operator!=(const size& sz) const; 46 | 47 | unsigned int get_width(); 48 | unsigned int get_height(); 49 | 50 | void set_width(unsigned int width); 51 | void set_height(unsigned int height); 52 | void set_width_height(unsigned int width, unsigned int height); 53 | 54 | private: 55 | unsigned int width; 56 | unsigned int height; 57 | }; 58 | 59 | class rectangle : public point, public size 60 | { 61 | public: 62 | rectangle(); 63 | rectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height); 64 | rectangle(const size& sz); 65 | rectangle(const point& pt, const size& sz = size()); 66 | 67 | bool operator==(const rectangle& rect) const; 68 | bool operator!=(const rectangle& rect) const; 69 | 70 | rectangle& operator=(const point& pt); 71 | rectangle& operator=(const size& sz); 72 | }; 73 | }; 74 | }; 75 | -------------------------------------------------------------------------------- /include/widget.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "ui_types.hpp" 4 | 5 | namespace WinQuickUpdater 6 | { 7 | namespace gui 8 | { 9 | using TMessageFunction = std::function ; 10 | using TMessagePair = std::pair ; 11 | 12 | class widget 13 | { 14 | public: 15 | widget(HWND hwnd_parent = nullptr, HINSTANCE instance = nullptr, bool is_window = false); 16 | ~widget(); 17 | 18 | bool create( 19 | const std::string& class_name, const std::string& widget_name, rectangle& rect, 20 | unsigned int style, unsigned int ex_style = 0, unsigned int menu_handle = 0 21 | ); 22 | 23 | void add_message_handlers(const std::vector & vec); 24 | void remove_message_handler(unsigned int message); 25 | 26 | bool set_text(const std::string& text) const; 27 | void set_instance(HINSTANCE instance); 28 | void set_visible(bool isVisible); 29 | void show(); 30 | void hide(); 31 | void set_position(int x, int y); 32 | void set_center_position(); 33 | 34 | HWND get_handle() const; 35 | HINSTANCE get_instance() const; 36 | bool is_visible() const; 37 | int get_screen_width() const; 38 | int get_screen_height() const; 39 | void get_window_rect(RECT* prc); 40 | void get_client_rect(RECT* prc); 41 | void get_mouse_position(POINT* ppt); 42 | 43 | public: 44 | static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 45 | static std::unordered_map widget_list; 46 | 47 | private: 48 | std::unordered_map custom_messages; 49 | 50 | HFONT font; 51 | 52 | HWND hwnd; 53 | HWND hwnd_parent; 54 | 55 | HINSTANCE instance; 56 | 57 | WNDPROC original_wndproc; 58 | 59 | bool is_window; 60 | bool m_visible; 61 | }; 62 | } 63 | }; 64 | -------------------------------------------------------------------------------- /include/window.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "abstract_singleton.hpp" 3 | #include "ui_types.hpp" 4 | #include "widget.hpp" 5 | 6 | namespace WinQuickUpdater 7 | { 8 | namespace gui 9 | { 10 | class window : public CSingleton , public widget 11 | { 12 | public: 13 | window(); 14 | ~window(); 15 | 16 | void assemble(std::string const& class_name, std::string const& window_name, rectangle rect, const char* icon_name); 17 | void destroy(); 18 | 19 | bool has_message() const; 20 | bool peek_single_message(MSG& msg) const; 21 | bool get_single_message(MSG& msg) const; 22 | void peek_message_loop(std::function cb); 23 | void get_message_loop(std::function cb); 24 | 25 | protected: 26 | bool create_class(std::string const& class_name, const char* icon_name); 27 | bool create_window(std::string const& class_name, std::string const& window_name, rectangle& rect); 28 | 29 | void set_message_handlers(); 30 | 31 | private: 32 | std::string m_class_name; 33 | }; 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /src/entry.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/pch.hpp" 2 | #include "../include/application.hpp" 3 | #include "../include/d3d_impl.hpp" 4 | #include "../include/log_helper.hpp" 5 | #include 6 | 7 | volatile bool interrupted{ false }; 8 | 9 | static void interrupt_handler(int signal) 10 | { 11 | if (interrupted) 12 | return; 13 | interrupted = true; 14 | 15 | if (WinQuickUpdater::CApplication::InstancePtr()) 16 | WinQuickUpdater::CApplication::Instance().destroy(); 17 | } 18 | 19 | int main(int, char**) 20 | { 21 | // Check ImGui version 22 | IMGUI_CHECKVERSION(); 23 | 24 | // Hide console window 25 | ShowWindow(GetConsoleWindow(), SW_HIDE); 26 | 27 | // Setup signal handlers 28 | std::signal(SIGINT, &interrupt_handler); 29 | std::signal(SIGABRT, &interrupt_handler); 30 | std::signal(SIGTERM, &interrupt_handler); 31 | 32 | // Initialize instances 33 | static WinQuickUpdater::CLog kLogManager("WinQuickUpdater", WinQuickUpdater::CUSTOM_LOG_FILENAME); 34 | static WinQuickUpdater::CD3DManager kD3DManager; 35 | static WinQuickUpdater::CApplication kApplication(__argc, __argv); 36 | 37 | // Start to main routine 38 | return kApplication.main_routine(); 39 | } 40 | -------------------------------------------------------------------------------- /src/log_helper.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/pch.hpp" 2 | #include "../include/log_helper.hpp" 3 | #include "../include/basic_log.hpp" 4 | #include "../include/error_handler.hpp" 5 | 6 | namespace WinQuickUpdater 7 | { 8 | static void LogErrorHandler(const std::string& stMessage) 9 | { 10 | Logf(CUSTOM_LOG_ERROR_FILENAME, "Log error handled: %s\n", stMessage.c_str()); 11 | MessageBoxA(0, stMessage.c_str(), "Log manager initilization fail!", 0); 12 | abort(); 13 | } 14 | 15 | CLog::CLog(const std::string& stLoggerName, const std::string& stFileName) : 16 | m_stLoggerName(stLoggerName), m_stFileName(stFileName) 17 | { 18 | try 19 | { 20 | auto sinks = std::vector(); 21 | 22 | sinks.push_back(std::make_shared()); 23 | sinks.push_back(std::make_shared()); 24 | sinks.push_back(std::make_shared(m_stFileName.c_str())); 25 | 26 | m_pkLoggerImpl = std::make_shared(m_stLoggerName.c_str(), sinks.begin(), sinks.end()); 27 | // m_pkLoggerImpl->set_error_handler(LogErrorHandler); 28 | } 29 | catch (const spdlog::spdlog_ex & ex) 30 | { 31 | Logf(CUSTOM_LOG_ERROR_FILENAME, "Exception throw on InitLogger (spdlog::spdlog_ex): %s\n", ex.what()); 32 | abort(); 33 | } 34 | catch (uint32_t dwNumber) 35 | { 36 | Logf(CUSTOM_LOG_ERROR_FILENAME, "Exception throw on InitLogger (w/ number): %p\n", dwNumber); 37 | abort(); 38 | } 39 | catch (...) 40 | { 41 | Logf(CUSTOM_LOG_ERROR_FILENAME, "Exception throw on InitLogger (w/o information!)\n"); 42 | abort(); 43 | } 44 | } 45 | 46 | void CLog::Log(int32_t nLevel, const std::string& stBuffer) 47 | { 48 | try 49 | { 50 | switch (nLevel) 51 | { 52 | case LL_SYS: 53 | m_pkLoggerImpl->info(stBuffer.c_str()); 54 | break; 55 | case LL_CRI: 56 | m_pkLoggerImpl->critical(stBuffer.c_str()); 57 | break; 58 | case LL_ERR: 59 | m_pkLoggerImpl->error(stBuffer.c_str()); 60 | break; 61 | case LL_DEV: 62 | m_pkLoggerImpl->debug(stBuffer.c_str()); 63 | break; 64 | case LL_TRACE: 65 | m_pkLoggerImpl->trace(stBuffer.c_str()); 66 | break; 67 | case LL_WARN: 68 | m_pkLoggerImpl->warn(stBuffer.c_str()); 69 | break; 70 | } 71 | m_pkLoggerImpl->flush(); 72 | } 73 | catch (const spdlog::spdlog_ex & ex) 74 | { 75 | Logf(CUSTOM_LOG_ERROR_FILENAME, "Exception throw on sys_log (spdlog::spdlog_ex %s\n", ex.what()); 76 | abort(); 77 | } 78 | catch (uint32_t dwNumber) 79 | { 80 | Logf(CUSTOM_LOG_ERROR_FILENAME, "Exception throw on sys_log (w/ number): %p\n", dwNumber); 81 | abort(); 82 | } 83 | catch (...) 84 | { 85 | Logf(CUSTOM_LOG_ERROR_FILENAME, "Exception throw on sys_log (w/o information!"); 86 | abort(); 87 | } 88 | } 89 | 90 | void CLog::LogError(const std::string& stMessage, bool bFatal, bool bShowLastError) 91 | { 92 | const auto err = CError{ stMessage, ::GetLastError() }; 93 | 94 | auto msg = ""s; 95 | if (bShowLastError) 96 | msg = fmt::format("{0} (Code: {1})", err.what(), err.code()); 97 | else 98 | msg = fmt::format("{0}", err.msg()); 99 | 100 | Log(LL_ERR, msg.c_str()); 101 | MessageBoxA(0, msg.c_str(), 0, MB_ICONERROR); 102 | 103 | if (bFatal) 104 | std::exit(EXIT_FAILURE); 105 | } 106 | } -------------------------------------------------------------------------------- /src/ui_types.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/pch.hpp" 2 | #include "../include/ui_types.hpp" 3 | 4 | namespace WinQuickUpdater 5 | { 6 | namespace gui 7 | { 8 | /* point */ 9 | point::point() 10 | : x(0), y(0) 11 | { 12 | 13 | } 14 | 15 | point::point(unsigned int x, unsigned int y) 16 | : x(x), y(y) 17 | { 18 | 19 | } 20 | 21 | bool point::operator==(const point& pt) const 22 | { 23 | return ((this->x == pt.x) && (this->y == pt.y)); 24 | } 25 | 26 | bool point::operator!=(const point& pt) const 27 | { 28 | return ((this->x != pt.x) || (this->y != pt.y)); 29 | } 30 | 31 | bool point::operator<(const point& pt) const 32 | { 33 | return ((this->y < pt.y) || (this->y == pt.y && this->x < pt.x)); 34 | } 35 | 36 | bool point::operator<=(const point& pt) const 37 | { 38 | return ((this->y < pt.y) || (this->y == pt.y && this->x <= pt.x)); 39 | } 40 | 41 | bool point::operator>(const point& pt) const 42 | { 43 | return ((this->y > pt.y) || (this->y == pt.y && this->x > pt.x)); 44 | } 45 | 46 | bool point::operator>=(const point& pt) const 47 | { 48 | return ((this->y > pt.y) || (this->y == pt.y && this->x >= pt.x)); 49 | } 50 | 51 | unsigned int point::get_x() 52 | { 53 | return this->x; 54 | } 55 | 56 | unsigned int point::get_y() 57 | { 58 | return this->y; 59 | } 60 | 61 | void point::set_x(unsigned int x) 62 | { 63 | this->x = x; 64 | } 65 | 66 | void point::set_y(unsigned int y) 67 | { 68 | this->y = y; 69 | } 70 | 71 | void point::set_x_y(unsigned int x, unsigned int y) 72 | { 73 | this->x = x; 74 | this->y = y; 75 | } 76 | 77 | /* size */ 78 | size::size() 79 | : width(0), height(0) 80 | { 81 | 82 | } 83 | 84 | size::size(unsigned int width, unsigned int height) 85 | : width(width), height(height) 86 | { 87 | 88 | } 89 | 90 | size::size(const size& sz) 91 | : width(sz.width), height(sz.height) 92 | { 93 | 94 | } 95 | 96 | bool size::is_zero() const 97 | { 98 | return (this->width == 0 || this->height == 0); 99 | } 100 | 101 | bool size::operator==(const size& sz) const 102 | { 103 | return ((this->width == sz.width) && (this->height == sz.height)); 104 | } 105 | 106 | bool size::operator!=(const size& sz) const 107 | { 108 | return ((this->width != sz.width) || (this->height != sz.height)); 109 | } 110 | 111 | unsigned int size::get_width() 112 | { 113 | return this->width; 114 | } 115 | 116 | unsigned int size::get_height() 117 | { 118 | return this->height; 119 | } 120 | 121 | void size::set_width(unsigned int width) 122 | { 123 | this->width = width; 124 | } 125 | 126 | void size::set_height(unsigned int height) 127 | { 128 | this->height = height; 129 | } 130 | 131 | void size::set_width_height(unsigned int width, unsigned int height) 132 | { 133 | this->width = width; 134 | this->height = height; 135 | } 136 | 137 | /* rectangle */ 138 | rectangle::rectangle() 139 | : point(0, 0), size(0, 0) 140 | { 141 | 142 | } 143 | 144 | rectangle::rectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height) 145 | : point(x, y), size(width, height) 146 | { 147 | 148 | } 149 | 150 | rectangle::rectangle(const size& sz) 151 | : point(0, 0), size(sz) 152 | { 153 | 154 | } 155 | 156 | rectangle::rectangle(const point& pt, const size& sz) 157 | : point(pt.x, pt.y), size(sz.width, sz.height) 158 | { 159 | 160 | } 161 | 162 | bool rectangle::operator==(const rectangle& rect) const 163 | { 164 | return ((this->width == rect.width) && (this->height == rect.height)); 165 | } 166 | 167 | bool rectangle::operator!=(const rectangle& rect) const 168 | { 169 | return ((this->width != rect.width) || (this->height != rect.height)); 170 | } 171 | 172 | rectangle& rectangle::operator=(const point& pt) 173 | { 174 | x = pt.x; 175 | y = pt.y; 176 | return *this; 177 | } 178 | 179 | rectangle& rectangle::operator=(const size& sz) 180 | { 181 | width = sz.width; 182 | height = sz.height; 183 | return *this; 184 | } 185 | } 186 | }; 187 | --------------------------------------------------------------------------------