├── .gitattributes ├── .idea ├── .gitignore ├── .name ├── deployment.xml ├── encodings.xml ├── genetic_algorithm.iml ├── misc.xml ├── modules.xml └── vcs.xml ├── 1.json ├── 3rdparty └── include │ ├── json │ ├── allocator.h │ ├── assertions.h │ ├── autolink.h │ ├── config.h │ ├── features.h │ ├── forwards.h │ ├── json.h │ ├── reader.h │ ├── value.h │ ├── version.h │ └── writer.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 │ │ ├── clzll.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 │ ├── uri.h │ └── writer.h │ └── spdlog │ ├── async.h │ ├── async_logger-inl.h │ ├── async_logger.h │ ├── cfg │ ├── argv.h │ ├── env.h │ ├── helpers-inl.h │ └── helpers.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 │ ├── periodic_worker-inl.h │ ├── periodic_worker.h │ ├── registry-inl.h │ ├── registry.h │ ├── synchronous_factory.h │ ├── tcp_client-windows.h │ ├── tcp_client.h │ ├── thread_pool-inl.h │ ├── thread_pool.h │ ├── udp_client-windows.h │ ├── udp_client.h │ └── windows_include.h │ ├── fmt │ ├── bin_to_hex.h │ ├── bundled │ │ ├── args.h │ │ ├── chrono.h │ │ ├── color.h │ │ ├── compile.h │ │ ├── core.h │ │ ├── fmt.license.rst │ │ ├── format-inl.h │ │ ├── format.h │ │ ├── locale.h │ │ ├── os.h │ │ ├── ostream.h │ │ ├── printf.h │ │ ├── ranges.h │ │ └── xchar.h │ ├── chrono.h │ ├── compile.h │ ├── fmt.h │ ├── ostr.h │ ├── ranges.h │ └── xchar.h │ ├── formatter.h │ ├── fwd.h │ ├── logger-inl.h │ ├── logger.h │ ├── pattern_formatter-inl.h │ ├── pattern_formatter.h │ ├── sinks │ ├── android_sink.h │ ├── ansicolor_sink-inl.h │ ├── ansicolor_sink.h │ ├── base_sink-inl.h │ ├── base_sink.h │ ├── basic_file_sink-inl.h │ ├── basic_file_sink.h │ ├── daily_file_sink.h │ ├── dist_sink.h │ ├── dup_filter_sink.h │ ├── hourly_file_sink.h │ ├── mongo_sink.h │ ├── msvc_sink.h │ ├── null_sink.h │ ├── ostream_sink.h │ ├── qt_sinks.h │ ├── ringbuffer_sink.h │ ├── rotating_file_sink-inl.h │ ├── rotating_file_sink.h │ ├── sink-inl.h │ ├── sink.h │ ├── stdout_color_sinks-inl.h │ ├── stdout_color_sinks.h │ ├── stdout_sinks-inl.h │ ├── stdout_sinks.h │ ├── syslog_sink.h │ ├── systemd_sink.h │ ├── tcp_sink.h │ ├── udp_sink.h │ ├── win_eventlog_sink.h │ ├── wincolor_sink-inl.h │ └── wincolor_sink.h │ ├── spdlog-inl.h │ ├── spdlog.h │ ├── stopwatch.h │ ├── tweakme.h │ └── version.h ├── CMakeLists.txt ├── EasyThreadPool ├── CMakeLists.txt ├── easythreadpool.cpp └── easythreadpool.h ├── GenerateIterate ├── CMakeLists.txt ├── GenerateIterate.cpp ├── GenerateIterate.h └── Train.h ├── PlayGame ├── CMakeLists.txt └── SixPieces │ ├── CMakeLists.txt │ ├── SixInitialize.cpp │ ├── SixInitialize.h │ ├── SixPiece.cpp │ ├── SixPiece.h │ ├── SixPiece_test.cpp │ ├── SixSelfPlay.cpp │ ├── SixSelfPlay.h │ └── cmake-build-debug │ ├── .cmake │ └── api │ │ └── v1 │ │ └── reply │ │ ├── cmakeFiles-v1-29965649996fd1b329d5.json │ │ ├── codemodel-v2-cf8e51656c0e2e41cda9.json │ │ ├── index-2022-10-13T07-26-19-0490.json │ │ └── target-SixPiece_test-Debug-7d473c6aa20fa7783f12.json │ ├── .ninja_deps │ ├── .ninja_log │ ├── CMakeFiles │ ├── SixPiece_test.dir │ │ ├── SixInitialize.cpp.obj │ │ ├── SixPiece.cpp.obj │ │ └── SixPiece_test.cpp.obj │ ├── clion-log.txt │ └── sixpiece.dir │ │ ├── SixInitialize.cpp.obj │ │ └── SixPiece.cpp.obj │ ├── Testing │ └── Temporary │ │ └── LastTest.log │ └── libsixpiece.a ├── README.md ├── cmake-build-debug └── EasyThreadPool │ └── cmake_install.cmake ├── conf ├── TrainData.json └── config.json ├── main.cpp ├── public └── tsglobal.hpp └── queue ├── CMakeLists.txt ├── Makefile ├── cmake_install.cmake ├── ringqueue.hpp ├── rte_ring.cpp ├── rte_ring.h ├── test.cpp ├── test.h └── threadsafecontainer.hpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Genetic -------------------------------------------------------------------------------- /.idea/deployment.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/genetic_algorithm.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /1.json: -------------------------------------------------------------------------------- 1 | {"1":"5"} 2 | -------------------------------------------------------------------------------- /3rdparty/include/json/allocator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef CPPTL_JSON_ALLOCATOR_H_INCLUDED 7 | #define CPPTL_JSON_ALLOCATOR_H_INCLUDED 8 | 9 | #include 10 | #include 11 | 12 | namespace Json { 13 | template 14 | class SecureAllocator { 15 | public: 16 | // Type definitions 17 | using value_type = T; 18 | using pointer = T*; 19 | using const_pointer = const T*; 20 | using reference = T&; 21 | using const_reference = const T&; 22 | using size_type = std::size_t; 23 | using difference_type = std::ptrdiff_t; 24 | 25 | /** 26 | * Allocate memory for N items using the standard allocator. 27 | */ 28 | pointer allocate(size_type n) { 29 | // allocate using "global operator new" 30 | return static_cast(::operator new(n * sizeof(T))); 31 | } 32 | 33 | /** 34 | * Release memory which was allocated for N items at pointer P. 35 | * 36 | * The memory block is filled with zeroes before being released. 37 | * The pointer argument is tagged as "volatile" to prevent the 38 | * compiler optimizing out this critical step. 39 | */ 40 | void deallocate(volatile pointer p, size_type n) { 41 | std::memset(p, 0, n * sizeof(T)); 42 | // free using "global operator delete" 43 | ::operator delete(p); 44 | } 45 | 46 | /** 47 | * Construct an item in-place at pointer P. 48 | */ 49 | template 50 | void construct(pointer p, Args&&... args) { 51 | // construct using "placement new" and "perfect forwarding" 52 | ::new (static_cast(p)) T(std::forward(args)...); 53 | } 54 | 55 | size_type max_size() const { 56 | return size_t(-1) / sizeof(T); 57 | } 58 | 59 | pointer address( reference x ) const { 60 | return std::addressof(x); 61 | } 62 | 63 | const_pointer address( const_reference x ) const { 64 | return std::addressof(x); 65 | } 66 | 67 | /** 68 | * Destroy an item in-place at pointer P. 69 | */ 70 | void destroy(pointer p) { 71 | // destroy using "explicit destructor" 72 | p->~T(); 73 | } 74 | 75 | // Boilerplate 76 | SecureAllocator() {} 77 | template SecureAllocator(const SecureAllocator&) {} 78 | template struct rebind { using other = SecureAllocator; }; 79 | }; 80 | 81 | 82 | template 83 | bool operator==(const SecureAllocator&, const SecureAllocator&) { 84 | return true; 85 | } 86 | 87 | template 88 | bool operator!=(const SecureAllocator&, const SecureAllocator&) { 89 | return false; 90 | } 91 | 92 | } //namespace Json 93 | 94 | #endif // CPPTL_JSON_ALLOCATOR_H_INCLUDED 95 | -------------------------------------------------------------------------------- /3rdparty/include/json/assertions.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED 7 | #define CPPTL_JSON_ASSERTIONS_H_INCLUDED 8 | 9 | #include 10 | #include 11 | 12 | #if !defined(JSON_IS_AMALGAMATION) 13 | #include "config.h" 14 | #endif // if !defined(JSON_IS_AMALGAMATION) 15 | 16 | /** It should not be possible for a maliciously designed file to 17 | * cause an abort() or seg-fault, so these macros are used only 18 | * for pre-condition violations and internal logic errors. 19 | */ 20 | #if JSON_USE_EXCEPTION 21 | 22 | // @todo <= add detail about condition in exception 23 | # define JSON_ASSERT(condition) \ 24 | {if (!(condition)) {Json::throwLogicError( "assert json failed" );}} 25 | 26 | # define JSON_FAIL_MESSAGE(message) \ 27 | { \ 28 | JSONCPP_OSTRINGSTREAM oss; oss << message; \ 29 | Json::throwLogicError(oss.str()); \ 30 | abort(); \ 31 | } 32 | 33 | #else // JSON_USE_EXCEPTION 34 | 35 | # define JSON_ASSERT(condition) assert(condition) 36 | 37 | // The call to assert() will show the failure message in debug builds. In 38 | // release builds we abort, for a core-dump or debugger. 39 | # define JSON_FAIL_MESSAGE(message) \ 40 | { \ 41 | JSONCPP_OSTRINGSTREAM oss; oss << message; \ 42 | assert(false && oss.str().c_str()); \ 43 | abort(); \ 44 | } 45 | 46 | 47 | #endif 48 | 49 | #define JSON_ASSERT_MESSAGE(condition, message) \ 50 | if (!(condition)) { \ 51 | JSON_FAIL_MESSAGE(message); \ 52 | } 53 | 54 | #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED 55 | -------------------------------------------------------------------------------- /3rdparty/include/json/autolink.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_AUTOLINK_H_INCLUDED 7 | #define JSON_AUTOLINK_H_INCLUDED 8 | 9 | #include "config.h" 10 | 11 | #ifdef JSON_IN_CPPTL 12 | #include 13 | #endif 14 | 15 | #if !defined(JSON_NO_AUTOLINK) && !defined(JSON_DLL_BUILD) && \ 16 | !defined(JSON_IN_CPPTL) 17 | #define CPPTL_AUTOLINK_NAME "json" 18 | #undef CPPTL_AUTOLINK_DLL 19 | #ifdef JSON_DLL 20 | #define CPPTL_AUTOLINK_DLL 21 | #endif 22 | #include "autolink.h" 23 | #endif 24 | 25 | #endif // JSON_AUTOLINK_H_INCLUDED 26 | -------------------------------------------------------------------------------- /3rdparty/include/json/features.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef CPPTL_JSON_FEATURES_H_INCLUDED 7 | #define CPPTL_JSON_FEATURES_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | #include "forwards.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | 13 | namespace Json { 14 | 15 | /** \brief Configuration passed to reader and writer. 16 | * This configuration object can be used to force the Reader or Writer 17 | * to behave in a standard conforming way. 18 | */ 19 | class JSON_API Features { 20 | public: 21 | /** \brief A configuration that allows all features and assumes all strings 22 | * are UTF-8. 23 | * - C & C++ comments are allowed 24 | * - Root object can be any JSON value 25 | * - Assumes Value strings are encoded in UTF-8 26 | */ 27 | static Features all(); 28 | 29 | /** \brief A configuration that is strictly compatible with the JSON 30 | * specification. 31 | * - Comments are forbidden. 32 | * - Root object must be either an array or an object value. 33 | * - Assumes Value strings are encoded in UTF-8 34 | */ 35 | static Features strictMode(); 36 | 37 | /** \brief Initialize the configuration like JsonConfig::allFeatures; 38 | */ 39 | Features(); 40 | 41 | /// \c true if comments are allowed. Default: \c true. 42 | bool allowComments_; 43 | 44 | /// \c true if root must be either an array or an object value. Default: \c 45 | /// false. 46 | bool strictRoot_; 47 | 48 | /// \c true if dropped null placeholders are allowed. Default: \c false. 49 | bool allowDroppedNullPlaceholders_; 50 | 51 | /// \c true if numeric object key are allowed. Default: \c false. 52 | bool allowNumericKeys_; 53 | }; 54 | 55 | } // namespace Json 56 | 57 | #endif // CPPTL_JSON_FEATURES_H_INCLUDED 58 | -------------------------------------------------------------------------------- /3rdparty/include/json/forwards.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_FORWARDS_H_INCLUDED 7 | #define JSON_FORWARDS_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | #include "config.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | 13 | namespace Json { 14 | 15 | // writer.h 16 | class FastWriter; 17 | class StyledWriter; 18 | 19 | // reader.h 20 | class Reader; 21 | 22 | // features.h 23 | class Features; 24 | 25 | // value.h 26 | typedef unsigned int ArrayIndex; 27 | class StaticString; 28 | class Path; 29 | class PathArgument; 30 | class Value; 31 | class ValueIteratorBase; 32 | class ValueIterator; 33 | class ValueConstIterator; 34 | 35 | } // namespace Json 36 | 37 | #endif // JSON_FORWARDS_H_INCLUDED 38 | -------------------------------------------------------------------------------- /3rdparty/include/json/json.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_JSON_H_INCLUDED 7 | #define JSON_JSON_H_INCLUDED 8 | 9 | #include "autolink.h" 10 | #include "value.h" 11 | #include "reader.h" 12 | #include "writer.h" 13 | #include "features.h" 14 | 15 | #endif // JSON_JSON_H_INCLUDED 16 | -------------------------------------------------------------------------------- /3rdparty/include/json/version.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file (and "version") is generated by CMake. 2 | // Run CMake configure step to update it. 3 | #ifndef JSON_VERSION_H_INCLUDED 4 | # define JSON_VERSION_H_INCLUDED 5 | 6 | # define JSONCPP_VERSION_STRING "1.7.4" 7 | # define JSONCPP_VERSION_MAJOR 1 8 | # define JSONCPP_VERSION_MINOR 7 9 | # define JSONCPP_VERSION_PATCH 4 10 | # define JSONCPP_VERSION_QUALIFIER 11 | # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) 12 | 13 | #ifdef JSONCPP_USING_SECURE_MEMORY 14 | #undef JSONCPP_USING_SECURE_MEMORY 15 | #endif 16 | #define JSONCPP_USING_SECURE_MEMORY 0 17 | // If non-zero, the library zeroes any memory that it has allocated before 18 | // it frees its memory. 19 | 20 | #endif // JSON_VERSION_H_INCLUDED 21 | -------------------------------------------------------------------------------- /3rdparty/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. 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 | -------------------------------------------------------------------------------- /3rdparty/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. 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 - !eof_ <= 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 | -------------------------------------------------------------------------------- /3rdparty/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. 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 | -------------------------------------------------------------------------------- /3rdparty/include/rapidjson/internal/clzll.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. 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_CLZLL_H_ 16 | #define RAPIDJSON_CLZLL_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(_MSC_VER) && !defined(UNDER_CE) 21 | #include 22 | #if defined(_WIN64) 23 | #pragma intrinsic(_BitScanReverse64) 24 | #else 25 | #pragma intrinsic(_BitScanReverse) 26 | #endif 27 | #endif 28 | 29 | RAPIDJSON_NAMESPACE_BEGIN 30 | namespace internal { 31 | 32 | inline uint32_t clzll(uint64_t x) { 33 | // Passing 0 to __builtin_clzll is UB in GCC and results in an 34 | // infinite loop in the software implementation. 35 | RAPIDJSON_ASSERT(x != 0); 36 | 37 | #if defined(_MSC_VER) && !defined(UNDER_CE) 38 | unsigned long r = 0; 39 | #if defined(_WIN64) 40 | _BitScanReverse64(&r, x); 41 | #else 42 | // Scan the high 32 bits. 43 | if (_BitScanReverse(&r, static_cast(x >> 32))) 44 | return 63 - (r + 32); 45 | 46 | // Scan the low 32 bits. 47 | _BitScanReverse(&r, static_cast(x & 0xFFFFFFFF)); 48 | #endif // _WIN64 49 | 50 | return 63 - r; 51 | #elif (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll) 52 | // __builtin_clzll wrapper 53 | return static_cast(__builtin_clzll(x)); 54 | #else 55 | // naive version 56 | uint32_t r = 0; 57 | while (!(x & (static_cast(1) << 63))) { 58 | x <<= 1; 59 | ++r; 60 | } 61 | 62 | return r; 63 | #endif // _MSC_VER 64 | } 65 | 66 | #define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll 67 | 68 | } // namespace internal 69 | RAPIDJSON_NAMESPACE_END 70 | 71 | #endif // RAPIDJSON_CLZLL_H_ 72 | -------------------------------------------------------------------------------- /3rdparty/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. 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 | -------------------------------------------------------------------------------- /3rdparty/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. 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 | -------------------------------------------------------------------------------- /3rdparty/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. 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 | //! Custom strcmpn() which works on different character types. 49 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 50 | \param s1 Null-terminated input string. 51 | \param s2 Null-terminated input string. 52 | \return 0 if equal 53 | */ 54 | template 55 | inline int StrCmp(const Ch* s1, const Ch* s2) { 56 | RAPIDJSON_ASSERT(s1 != 0); 57 | RAPIDJSON_ASSERT(s2 != 0); 58 | while(*s1 && (*s1 == *s2)) { s1++; s2++; } 59 | return static_cast(*s1) < static_cast(*s2) ? -1 : static_cast(*s1) > static_cast(*s2); 60 | } 61 | 62 | //! Returns number of code points in a encoded string. 63 | template 64 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 65 | RAPIDJSON_ASSERT(s != 0); 66 | RAPIDJSON_ASSERT(outCount != 0); 67 | GenericStringStream is(s); 68 | const typename Encoding::Ch* end = s + length; 69 | SizeType count = 0; 70 | while (is.src_ < end) { 71 | unsigned codepoint; 72 | if (!Encoding::Decode(is, &codepoint)) 73 | return false; 74 | count++; 75 | } 76 | *outCount = count; 77 | return true; 78 | } 79 | 80 | } // namespace internal 81 | RAPIDJSON_NAMESPACE_END 82 | 83 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 84 | -------------------------------------------------------------------------------- /3rdparty/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. 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 | -------------------------------------------------------------------------------- /3rdparty/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. 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 | -------------------------------------------------------------------------------- /3rdparty/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. 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 | -------------------------------------------------------------------------------- /3rdparty/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. 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 | -------------------------------------------------------------------------------- /3rdparty/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 with 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 18 | #include 19 | #include 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, 1U); 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( 77 | size_t q_size, size_t thread_count, std::function on_thread_start, std::function on_thread_stop) 78 | { 79 | auto tp = std::make_shared(q_size, thread_count, on_thread_start, on_thread_stop); 80 | details::registry::instance().set_tp(std::move(tp)); 81 | } 82 | 83 | inline void init_thread_pool(size_t q_size, size_t thread_count, std::function on_thread_start) 84 | { 85 | init_thread_pool(q_size, thread_count, on_thread_start, [] {}); 86 | } 87 | 88 | inline void init_thread_pool(size_t q_size, size_t thread_count) 89 | { 90 | init_thread_pool( 91 | q_size, thread_count, [] {}, [] {}); 92 | } 93 | 94 | // get the global thread pool. 95 | inline std::shared_ptr thread_pool() 96 | { 97 | return details::registry::instance().get_tp(); 98 | } 99 | } // namespace spdlog 100 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #endif 9 | 10 | #include 11 | #include 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 | 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 | 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(msg.source) 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(source_loc()) 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 | -------------------------------------------------------------------------------- /3rdparty/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 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 SPDLOG_API 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 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/cfg/argv.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | #include 6 | #include 7 | 8 | // 9 | // Init log levels using each argv entry that starts with "SPDLOG_LEVEL=" 10 | // 11 | // set all loggers to debug level: 12 | // example.exe "SPDLOG_LEVEL=debug" 13 | 14 | // set logger1 to trace level 15 | // example.exe "SPDLOG_LEVEL=logger1=trace" 16 | 17 | // turn off all logging except for logger1 and logger2: 18 | // example.exe "SPDLOG_LEVEL=off,logger1=debug,logger2=info" 19 | 20 | namespace spdlog { 21 | namespace cfg { 22 | 23 | // search for SPDLOG_LEVEL= in the args and use it to init the levels 24 | inline void load_argv_levels(int argc, const char **argv) 25 | { 26 | const std::string spdlog_level_prefix = "SPDLOG_LEVEL="; 27 | for (int i = 1; i < argc; i++) 28 | { 29 | std::string arg = argv[i]; 30 | if (arg.find(spdlog_level_prefix) == 0) 31 | { 32 | auto levels_string = arg.substr(spdlog_level_prefix.size()); 33 | helpers::load_levels(levels_string); 34 | } 35 | } 36 | } 37 | 38 | inline void load_argv_levels(int argc, char **argv) 39 | { 40 | load_argv_levels(argc, const_cast(argv)); 41 | } 42 | 43 | } // namespace cfg 44 | } // namespace spdlog 45 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/cfg/env.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | #include 6 | #include 7 | #include 8 | 9 | // 10 | // Init levels and patterns from env variables SPDLOG_LEVEL 11 | // Inspired from Rust's "env_logger" crate (https://crates.io/crates/env_logger). 12 | // Note - fallback to "info" level on unrecognized levels 13 | // 14 | // Examples: 15 | // 16 | // set global level to debug: 17 | // export SPDLOG_LEVEL=debug 18 | // 19 | // turn off all logging except for logger1: 20 | // export SPDLOG_LEVEL="*=off,logger1=debug" 21 | // 22 | 23 | // turn off all logging except for logger1 and logger2: 24 | // export SPDLOG_LEVEL="off,logger1=debug,logger2=info" 25 | 26 | namespace spdlog { 27 | namespace cfg { 28 | inline void load_env_levels() 29 | { 30 | auto env_val = details::os::getenv("SPDLOG_LEVEL"); 31 | if (!env_val.empty()) 32 | { 33 | helpers::load_levels(env_val); 34 | } 35 | } 36 | 37 | } // namespace cfg 38 | } // namespace spdlog 39 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/cfg/helpers-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | # include 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace spdlog { 20 | namespace cfg { 21 | namespace helpers { 22 | 23 | // inplace convert to lowercase 24 | inline std::string &to_lower_(std::string &str) 25 | { 26 | std::transform( 27 | str.begin(), str.end(), str.begin(), [](char ch) { return static_cast((ch >= 'A' && ch <= 'Z') ? ch + ('a' - 'A') : ch); }); 28 | return str; 29 | } 30 | 31 | // inplace trim spaces 32 | inline std::string &trim_(std::string &str) 33 | { 34 | const char *spaces = " \n\r\t"; 35 | str.erase(str.find_last_not_of(spaces) + 1); 36 | str.erase(0, str.find_first_not_of(spaces)); 37 | return str; 38 | } 39 | 40 | // return (name,value) trimmed pair from given "name=value" string. 41 | // return empty string on missing parts 42 | // "key=val" => ("key", "val") 43 | // " key = val " => ("key", "val") 44 | // "key=" => ("key", "") 45 | // "val" => ("", "val") 46 | 47 | inline std::pair extract_kv_(char sep, const std::string &str) 48 | { 49 | auto n = str.find(sep); 50 | std::string k, v; 51 | if (n == std::string::npos) 52 | { 53 | v = str; 54 | } 55 | else 56 | { 57 | k = str.substr(0, n); 58 | v = str.substr(n + 1); 59 | } 60 | return std::make_pair(trim_(k), trim_(v)); 61 | } 62 | 63 | // return vector of key/value pairs from sequence of "K1=V1,K2=V2,.." 64 | // "a=AAA,b=BBB,c=CCC,.." => {("a","AAA"),("b","BBB"),("c", "CCC"),...} 65 | inline std::unordered_map extract_key_vals_(const std::string &str) 66 | { 67 | std::string token; 68 | std::istringstream token_stream(str); 69 | std::unordered_map rv{}; 70 | while (std::getline(token_stream, token, ',')) 71 | { 72 | if (token.empty()) 73 | { 74 | continue; 75 | } 76 | auto kv = extract_kv_('=', token); 77 | rv[kv.first] = kv.second; 78 | } 79 | return rv; 80 | } 81 | 82 | SPDLOG_INLINE void load_levels(const std::string &input) 83 | { 84 | if (input.empty() || input.size() > 512) 85 | { 86 | return; 87 | } 88 | 89 | auto key_vals = extract_key_vals_(input); 90 | std::unordered_map levels; 91 | level::level_enum global_level = level::info; 92 | bool global_level_found = false; 93 | 94 | for (auto &name_level : key_vals) 95 | { 96 | auto &logger_name = name_level.first; 97 | auto level_name = to_lower_(name_level.second); 98 | auto level = level::from_str(level_name); 99 | // ignore unrecognized level names 100 | if (level == level::off && level_name != "off") 101 | { 102 | continue; 103 | } 104 | if (logger_name.empty()) // no logger name indicate global level 105 | { 106 | global_level_found = true; 107 | global_level = level; 108 | } 109 | else 110 | { 111 | levels[logger_name] = level; 112 | } 113 | } 114 | 115 | details::registry::instance().set_levels(std::move(levels), global_level_found ? &global_level : nullptr); 116 | } 117 | 118 | } // namespace helpers 119 | } // namespace cfg 120 | } // namespace spdlog 121 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/cfg/helpers.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace cfg { 11 | namespace helpers { 12 | // 13 | // Init levels from given string 14 | // 15 | // Examples: 16 | // 17 | // set global level to debug: "debug" 18 | // turn off all logging except for logger1: "off,logger1=debug" 19 | // turn off all logging except for logger1 and logger2: "off,logger1=debug,logger2=info" 20 | // 21 | SPDLOG_API void load_levels(const std::string &txt); 22 | } // namespace helpers 23 | 24 | } // namespace cfg 25 | } // namespace spdlog 26 | 27 | #ifdef SPDLOG_HEADER_ONLY 28 | # include "helpers-inl.h" 29 | #endif // SPDLOG_HEADER_ONLY 30 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | namespace level { 15 | 16 | #if __cplusplus >= 201703L 17 | constexpr 18 | #endif 19 | static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; 20 | 21 | static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; 22 | 23 | SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT 24 | { 25 | return level_string_views[l]; 26 | } 27 | 28 | SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT 29 | { 30 | return short_level_names[l]; 31 | } 32 | 33 | SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT 34 | { 35 | auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name); 36 | if (it != std::end(level_string_views)) 37 | return static_cast(it - std::begin(level_string_views)); 38 | 39 | // check also for "warn" and "err" before giving up.. 40 | if (name == "warn") 41 | { 42 | return level::warn; 43 | } 44 | if (name == "err") 45 | { 46 | return level::err; 47 | } 48 | return level::off; 49 | } 50 | } // namespace level 51 | 52 | SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg) 53 | : msg_(std::move(msg)) 54 | {} 55 | 56 | SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) 57 | { 58 | #ifdef SPDLOG_USE_STD_FORMAT 59 | msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what(); 60 | #else 61 | memory_buf_t outbuf; 62 | fmt::format_system_error(outbuf, last_errno, msg.c_str()); 63 | msg_ = fmt::to_string(outbuf); 64 | #endif 65 | } 66 | 67 | SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT 68 | { 69 | return msg_.c_str(); 70 | } 71 | 72 | SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno) 73 | { 74 | SPDLOG_THROW(spdlog_ex(msg, last_errno)); 75 | } 76 | 77 | SPDLOG_INLINE void throw_spdlog_ex(std::string msg) 78 | { 79 | SPDLOG_THROW(spdlog_ex(std::move(msg))); 80 | } 81 | 82 | } // namespace spdlog 83 | -------------------------------------------------------------------------------- /3rdparty/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 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_ = std::move(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 void backtracer::push_back(const log_msg &msg) 52 | { 53 | std::lock_guard lock{mutex_}; 54 | messages_.push_back(log_msg_buffer{msg}); 55 | } 56 | 57 | // pop all items in the q and apply the given fun on each of them. 58 | SPDLOG_INLINE void backtracer::foreach_pop(std::function fun) 59 | { 60 | std::lock_guard lock{mutex_}; 61 | while (!messages_.empty()) 62 | { 63 | auto &front_msg = messages_.front(); 64 | fun(front_msg); 65 | messages_.pop_front(); 66 | } 67 | } 68 | } // namespace details 69 | } // namespace spdlog 70 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | // Store log messages in circular buffer. 14 | // Useful for storing debug data in case of error/warning happens. 15 | 16 | namespace spdlog { 17 | namespace details { 18 | class SPDLOG_API backtracer 19 | { 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 | void push_back(const log_msg &msg); 35 | 36 | // pop all items in the q and apply the given fun on each of them. 37 | void foreach_pop(std::function fun); 38 | }; 39 | 40 | } // namespace details 41 | } // namespace spdlog 42 | 43 | #ifdef SPDLOG_HEADER_ONLY 44 | # include "backtracer-inl.h" 45 | #endif 46 | -------------------------------------------------------------------------------- /3rdparty/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 | // circular q view of std::vector. 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | namespace spdlog { 11 | namespace details { 12 | template 13 | class circular_q 14 | { 15 | size_t max_items_ = 0; 16 | typename std::vector::size_type head_ = 0; 17 | typename std::vector::size_type tail_ = 0; 18 | size_t overrun_counter_ = 0; 19 | std::vector v_; 20 | 21 | public: 22 | using value_type = T; 23 | 24 | // empty ctor - create a disabled queue with no elements allocated at all 25 | circular_q() = default; 26 | 27 | explicit circular_q(size_t max_items) 28 | : max_items_(max_items + 1) // one item is reserved as marker for full q 29 | , v_(max_items_) 30 | {} 31 | 32 | circular_q(const circular_q &) = default; 33 | circular_q &operator=(const circular_q &) = default; 34 | 35 | // move cannot be default, 36 | // since we need to reset head_, tail_, etc to zero in the moved object 37 | circular_q(circular_q &&other) SPDLOG_NOEXCEPT 38 | { 39 | copy_moveable(std::move(other)); 40 | } 41 | 42 | circular_q &operator=(circular_q &&other) SPDLOG_NOEXCEPT 43 | { 44 | copy_moveable(std::move(other)); 45 | return *this; 46 | } 47 | 48 | // push back, overrun (oldest) item if no room left 49 | void push_back(T &&item) 50 | { 51 | if (max_items_ > 0) 52 | { 53 | v_[tail_] = std::move(item); 54 | tail_ = (tail_ + 1) % max_items_; 55 | 56 | if (tail_ == head_) // overrun last item if full 57 | { 58 | head_ = (head_ + 1) % max_items_; 59 | ++overrun_counter_; 60 | } 61 | } 62 | } 63 | 64 | // Return reference to the front item. 65 | // If there are no elements in the container, the behavior is undefined. 66 | const T &front() const 67 | { 68 | return v_[head_]; 69 | } 70 | 71 | T &front() 72 | { 73 | return v_[head_]; 74 | } 75 | 76 | // Return number of elements actually stored 77 | size_t size() const 78 | { 79 | if (tail_ >= head_) 80 | { 81 | return tail_ - head_; 82 | } 83 | else 84 | { 85 | return max_items_ - (head_ - tail_); 86 | } 87 | } 88 | 89 | // Return const reference to item by index. 90 | // If index is out of range 0…size()-1, the behavior is undefined. 91 | const T &at(size_t i) const 92 | { 93 | assert(i < size()); 94 | return v_[(head_ + i) % max_items_]; 95 | } 96 | 97 | // Pop item from front. 98 | // If there are no elements in the container, the behavior is undefined. 99 | void pop_front() 100 | { 101 | head_ = (head_ + 1) % max_items_; 102 | } 103 | 104 | bool empty() const 105 | { 106 | return tail_ == head_; 107 | } 108 | 109 | bool full() const 110 | { 111 | // head is ahead of the tail by 1 112 | if (max_items_ > 0) 113 | { 114 | return ((tail_ + 1) % max_items_) == head_; 115 | } 116 | return false; 117 | } 118 | 119 | size_t overrun_counter() const 120 | { 121 | return overrun_counter_; 122 | } 123 | 124 | private: 125 | // copy from other&& and reset it to disabled state 126 | void copy_moveable(circular_q &&other) SPDLOG_NOEXCEPT 127 | { 128 | max_items_ = other.max_items_; 129 | head_ = other.head_; 130 | tail_ = other.tail_; 131 | overrun_counter_ = other.overrun_counter_; 132 | v_ = std::move(other.v_); 133 | 134 | // put &&other in disabled, but valid state 135 | other.max_items_ = 0; 136 | other.head_ = other.tail_ = 0; 137 | other.overrun_counter_ = 0; 138 | } 139 | }; 140 | } // namespace details 141 | } // namespace spdlog 142 | -------------------------------------------------------------------------------- /3rdparty/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 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 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | 12 | // Helper class for file sinks. 13 | // When failing to open a file, retry several times(5) with a delay interval(10 ms). 14 | // Throw spdlog_ex exception on errors. 15 | 16 | class SPDLOG_API file_helper 17 | { 18 | public: 19 | file_helper() = default; 20 | explicit file_helper(const file_event_handlers &event_handlers); 21 | 22 | file_helper(const file_helper &) = delete; 23 | file_helper &operator=(const file_helper &) = delete; 24 | ~file_helper(); 25 | 26 | void open(const filename_t &fname, bool truncate = false); 27 | void reopen(bool truncate); 28 | void flush(); 29 | void close(); 30 | void write(const memory_buf_t &buf); 31 | size_t size() const; 32 | const filename_t &filename() const; 33 | 34 | // 35 | // return file path and its extension: 36 | // 37 | // "mylog.txt" => ("mylog", ".txt") 38 | // "mylog" => ("mylog", "") 39 | // "mylog." => ("mylog.", "") 40 | // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") 41 | // 42 | // the starting dot in filenames is ignored (hidden files): 43 | // 44 | // ".mylog" => (".mylog". "") 45 | // "my_folder/.mylog" => ("my_folder/.mylog", "") 46 | // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") 47 | static std::tuple split_by_extension(const filename_t &fname); 48 | 49 | private: 50 | const int open_tries_ = 5; 51 | const unsigned int open_interval_ = 10; 52 | std::FILE *fd_{nullptr}; 53 | filename_t filename_; 54 | file_event_handlers event_handlers_; 55 | }; 56 | } // namespace details 57 | } // namespace spdlog 58 | 59 | #ifdef SPDLOG_HEADER_ONLY 60 | # include "file_helper-inl.h" 61 | #endif 62 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #endif 9 | 10 | #include 11 | 12 | namespace spdlog { 13 | namespace details { 14 | 15 | SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::source_loc loc, string_view_t a_logger_name, 16 | spdlog::level::level_enum lvl, spdlog::string_view_t msg) 17 | : logger_name(a_logger_name) 18 | , level(lvl) 19 | , time(log_time) 20 | #ifndef SPDLOG_NO_THREAD_ID 21 | , thread_id(os::thread_id()) 22 | #endif 23 | , source(loc) 24 | , payload(msg) 25 | {} 26 | 27 | SPDLOG_INLINE log_msg::log_msg( 28 | spdlog::source_loc loc, string_view_t a_logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg) 29 | : log_msg(os::now(), loc, a_logger_name, lvl, msg) 30 | {} 31 | 32 | SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg) 33 | : log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg) 34 | {} 35 | 36 | } // namespace details 37 | } // namespace spdlog 38 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | struct SPDLOG_API log_msg 12 | { 13 | log_msg() = default; 14 | log_msg(log_clock::time_point log_time, source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); 15 | log_msg(source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); 16 | log_msg(string_view_t logger_name, level::level_enum lvl, string_view_t msg); 17 | log_msg(const log_msg &other) = default; 18 | log_msg &operator=(const log_msg &other) = default; 19 | 20 | string_view_t logger_name; 21 | level::level_enum level{level::off}; 22 | log_clock::time_point time; 23 | size_t thread_id{0}; 24 | 25 | // wrapping the formatted text with color (updated by pattern_formatter). 26 | mutable size_t color_range_start{0}; 27 | mutable size_t color_range_end{0}; 28 | 29 | source_loc source; 30 | string_view_t payload; 31 | }; 32 | } // namespace details 33 | } // namespace spdlog 34 | 35 | #ifdef SPDLOG_HEADER_ONLY 36 | # include "log_msg-inl.h" 37 | #endif 38 | -------------------------------------------------------------------------------- /3rdparty/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 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) SPDLOG_NOEXCEPT : log_msg{other}, buffer{std::move(other.buffer)} 30 | { 31 | update_string_views(); 32 | } 33 | 34 | SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other) 35 | { 36 | log_msg::operator=(other); 37 | buffer.clear(); 38 | buffer.append(other.buffer.data(), other.buffer.data() + other.buffer.size()); 39 | update_string_views(); 40 | return *this; 41 | } 42 | 43 | SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT 44 | { 45 | log_msg::operator=(other); 46 | buffer = std::move(other.buffer); 47 | update_string_views(); 48 | return *this; 49 | } 50 | 51 | SPDLOG_INLINE void log_msg_buffer::update_string_views() 52 | { 53 | logger_name = string_view_t{buffer.data(), logger_name.size()}; 54 | payload = string_view_t{buffer.data() + logger_name.size(), payload.size()}; 55 | } 56 | 57 | } // namespace details 58 | } // namespace spdlog 59 | -------------------------------------------------------------------------------- /3rdparty/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 7 | 8 | namespace spdlog { 9 | namespace details { 10 | 11 | // Extend log_msg with internal buffer to store its payload. 12 | // This is needed since log_msg holds string_views that points to stack data. 13 | 14 | class SPDLOG_API log_msg_buffer : public log_msg 15 | { 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) SPDLOG_NOEXCEPT; 24 | log_msg_buffer &operator=(const log_msg_buffer &other); 25 | log_msg_buffer &operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT; 26 | }; 27 | 28 | } // namespace details 29 | } // namespace spdlog 30 | 31 | #ifdef SPDLOG_HEADER_ONLY 32 | # include "log_msg_buffer-inl.h" 33 | #endif 34 | -------------------------------------------------------------------------------- /3rdparty/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 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 up to 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 up to 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 | size_t size() 114 | { 115 | std::unique_lock lock(queue_mutex_); 116 | return q_.size(); 117 | } 118 | 119 | private: 120 | std::mutex queue_mutex_; 121 | std::condition_variable push_cv_; 122 | std::condition_variable pop_cv_; 123 | spdlog::details::circular_q q_; 124 | }; 125 | } // namespace details 126 | } // namespace spdlog 127 | -------------------------------------------------------------------------------- /3rdparty/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 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include // std::time_t 8 | 9 | namespace spdlog { 10 | namespace details { 11 | namespace os { 12 | 13 | SPDLOG_API spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT; 14 | 15 | SPDLOG_API std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; 16 | 17 | SPDLOG_API std::tm localtime() SPDLOG_NOEXCEPT; 18 | 19 | SPDLOG_API std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; 20 | 21 | SPDLOG_API 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 | #if !defined(SPDLOG_FOLDER_SEPS) 36 | # ifdef _WIN32 37 | # define SPDLOG_FOLDER_SEPS "\\/" 38 | # else 39 | # define SPDLOG_FOLDER_SEPS "/" 40 | # endif 41 | #endif 42 | 43 | SPDLOG_CONSTEXPR static const char folder_seps[] = SPDLOG_FOLDER_SEPS; 44 | SPDLOG_CONSTEXPR static const filename_t::value_type folder_seps_filename[] = SPDLOG_FILENAME_T(SPDLOG_FOLDER_SEPS); 45 | 46 | // fopen_s on non windows for writing 47 | SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode); 48 | 49 | // Remove filename. return 0 on success 50 | SPDLOG_API int remove(const filename_t &filename) SPDLOG_NOEXCEPT; 51 | 52 | // Remove file if exists. return 0 on success 53 | // Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread) 54 | SPDLOG_API int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT; 55 | 56 | SPDLOG_API int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT; 57 | 58 | // Return if file exists. 59 | SPDLOG_API bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT; 60 | 61 | // Return file size according to open FILE* object 62 | SPDLOG_API size_t filesize(FILE *f); 63 | 64 | // Return utc offset in minutes or throw spdlog_ex on failure 65 | SPDLOG_API int utc_minutes_offset(const std::tm &tm = details::os::localtime()); 66 | 67 | // Return current thread id as size_t 68 | // It exists because the std::this_thread::get_id() is much slower(especially 69 | // under VS 2013) 70 | SPDLOG_API size_t _thread_id() SPDLOG_NOEXCEPT; 71 | 72 | // Return current thread id as size_t (from thread local storage) 73 | SPDLOG_API size_t thread_id() SPDLOG_NOEXCEPT; 74 | 75 | // This is avoid msvc issue in sleep_for that happens if the clock changes. 76 | // See https://github.com/gabime/spdlog/issues/609 77 | SPDLOG_API void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT; 78 | 79 | SPDLOG_API std::string filename_to_str(const filename_t &filename); 80 | 81 | SPDLOG_API int pid() SPDLOG_NOEXCEPT; 82 | 83 | // Determine if the terminal supports colors 84 | // Source: https://github.com/agauniyal/rang/ 85 | SPDLOG_API bool is_color_terminal() SPDLOG_NOEXCEPT; 86 | 87 | // Determine if the terminal attached 88 | // Source: https://github.com/agauniyal/rang/ 89 | SPDLOG_API bool in_terminal(FILE *file) SPDLOG_NOEXCEPT; 90 | 91 | #if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) 92 | SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target); 93 | 94 | SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target); 95 | #endif 96 | 97 | // Return directory name from given path or empty string 98 | // "abc/file" => "abc" 99 | // "abc/" => "abc" 100 | // "abc" => "" 101 | // "abc///" => "abc//" 102 | SPDLOG_API filename_t dir_name(const filename_t &path); 103 | 104 | // Create a dir from the given path. 105 | // Return true if succeeded or if this dir already exists. 106 | SPDLOG_API bool create_dir(const filename_t &path); 107 | 108 | // non thread safe, cross platform getenv/getenv_s 109 | // return empty string if field not found 110 | SPDLOG_API std::string getenv(const char *field); 111 | 112 | } // namespace os 113 | } // namespace details 114 | } // namespace spdlog 115 | 116 | #ifdef SPDLOG_HEADER_ONLY 117 | # include "os-inl.h" 118 | #endif 119 | -------------------------------------------------------------------------------- /3rdparty/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 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 | -------------------------------------------------------------------------------- /3rdparty/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 SPDLOG_API 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 | -------------------------------------------------------------------------------- /3rdparty/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 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 SPDLOG_API registry 28 | { 29 | public: 30 | using log_levels = std::unordered_map; 31 | registry(const registry &) = delete; 32 | registry &operator=(const registry &) = delete; 33 | 34 | void register_logger(std::shared_ptr new_logger); 35 | void initialize_logger(std::shared_ptr new_logger); 36 | std::shared_ptr get(const std::string &logger_name); 37 | std::shared_ptr default_logger(); 38 | 39 | // Return raw ptr to the default logger. 40 | // To be used directly by the spdlog default api (e.g. spdlog::info) 41 | // This make the default API faster, but cannot be used concurrently with set_default_logger(). 42 | // e.g do not call set_default_logger() from one thread while calling spdlog::info() from another. 43 | logger *get_default_raw(); 44 | 45 | // set default logger. 46 | // default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map. 47 | void set_default_logger(std::shared_ptr new_default_logger); 48 | 49 | void set_tp(std::shared_ptr tp); 50 | 51 | std::shared_ptr get_tp(); 52 | 53 | // Set global formatter. Each sink in each logger will get a clone of this object 54 | void set_formatter(std::unique_ptr formatter); 55 | 56 | void enable_backtrace(size_t n_messages); 57 | 58 | void disable_backtrace(); 59 | 60 | void set_level(level::level_enum log_level); 61 | 62 | void flush_on(level::level_enum log_level); 63 | 64 | void flush_every(std::chrono::seconds interval); 65 | 66 | void set_error_handler(err_handler handler); 67 | 68 | void apply_all(const std::function)> &fun); 69 | 70 | void flush_all(); 71 | 72 | void drop(const std::string &logger_name); 73 | 74 | void drop_all(); 75 | 76 | // clean all resources and threads started by the registry 77 | void shutdown(); 78 | 79 | std::recursive_mutex &tp_mutex(); 80 | 81 | void set_automatic_registration(bool automatic_registration); 82 | 83 | // set levels for all existing/future loggers. global_level can be null if should not set. 84 | void set_levels(log_levels levels, level::level_enum *global_level); 85 | 86 | static registry &instance(); 87 | 88 | private: 89 | registry(); 90 | ~registry(); 91 | 92 | void throw_if_exists_(const std::string &logger_name); 93 | void register_logger_(std::shared_ptr new_logger); 94 | bool set_level_from_cfg_(logger *logger); 95 | std::mutex logger_map_mutex_, flusher_mutex_; 96 | std::recursive_mutex tp_mutex_; 97 | std::unordered_map> loggers_; 98 | log_levels log_levels_; 99 | std::unique_ptr formatter_; 100 | spdlog::level::level_enum global_log_level_ = level::info; 101 | level::level_enum flush_level_ = level::off; 102 | err_handler err_handler_; 103 | std::shared_ptr tp_; 104 | std::unique_ptr periodic_flusher_; 105 | std::shared_ptr default_logger_; 106 | bool automatic_registration_ = true; 107 | size_t backtrace_n_messages_ = 0; 108 | }; 109 | 110 | } // namespace details 111 | } // namespace spdlog 112 | 113 | #ifdef SPDLOG_HEADER_ONLY 114 | # include "registry-inl.h" 115 | #endif 116 | -------------------------------------------------------------------------------- /3rdparty/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 25 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | namespace details { 15 | 16 | SPDLOG_INLINE thread_pool::thread_pool( 17 | size_t q_max_items, size_t threads_n, std::function on_thread_start, std::function on_thread_stop) 18 | : q_(q_max_items) 19 | { 20 | if (threads_n == 0 || threads_n > 1000) 21 | { 22 | throw_spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid " 23 | "range is 1-1000)"); 24 | } 25 | for (size_t i = 0; i < threads_n; i++) 26 | { 27 | threads_.emplace_back([this, on_thread_start, on_thread_stop] { 28 | on_thread_start(); 29 | this->thread_pool::worker_loop_(); 30 | on_thread_stop(); 31 | }); 32 | } 33 | } 34 | 35 | SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std::function on_thread_start) 36 | : thread_pool(q_max_items, threads_n, on_thread_start, [] {}) 37 | {} 38 | 39 | SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n) 40 | : thread_pool( 41 | q_max_items, threads_n, [] {}, [] {}) 42 | {} 43 | 44 | // message all threads to terminate gracefully join them 45 | SPDLOG_INLINE thread_pool::~thread_pool() 46 | { 47 | SPDLOG_TRY 48 | { 49 | for (size_t i = 0; i < threads_.size(); i++) 50 | { 51 | post_async_msg_(async_msg(async_msg_type::terminate), async_overflow_policy::block); 52 | } 53 | 54 | for (auto &t : threads_) 55 | { 56 | t.join(); 57 | } 58 | } 59 | SPDLOG_CATCH_STD 60 | } 61 | 62 | void SPDLOG_INLINE thread_pool::post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy) 63 | { 64 | async_msg async_m(std::move(worker_ptr), async_msg_type::log, msg); 65 | post_async_msg_(std::move(async_m), overflow_policy); 66 | } 67 | 68 | void SPDLOG_INLINE thread_pool::post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy) 69 | { 70 | post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy); 71 | } 72 | 73 | size_t SPDLOG_INLINE thread_pool::overrun_counter() 74 | { 75 | return q_.overrun_counter(); 76 | } 77 | 78 | size_t SPDLOG_INLINE thread_pool::queue_size() 79 | { 80 | return q_.size(); 81 | } 82 | 83 | void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy) 84 | { 85 | if (overflow_policy == async_overflow_policy::block) 86 | { 87 | q_.enqueue(std::move(new_msg)); 88 | } 89 | else 90 | { 91 | q_.enqueue_nowait(std::move(new_msg)); 92 | } 93 | } 94 | 95 | void SPDLOG_INLINE thread_pool::worker_loop_() 96 | { 97 | while (process_next_msg_()) {} 98 | } 99 | 100 | // process next message in the queue 101 | // return true if this thread should still be active (while no terminate msg 102 | // was received) 103 | bool SPDLOG_INLINE thread_pool::process_next_msg_() 104 | { 105 | async_msg incoming_async_msg; 106 | bool dequeued = q_.dequeue_for(incoming_async_msg, std::chrono::seconds(10)); 107 | if (!dequeued) 108 | { 109 | return true; 110 | } 111 | 112 | switch (incoming_async_msg.msg_type) 113 | { 114 | case async_msg_type::log: { 115 | incoming_async_msg.worker_ptr->backend_sink_it_(incoming_async_msg); 116 | return true; 117 | } 118 | case async_msg_type::flush: { 119 | incoming_async_msg.worker_ptr->backend_flush_(); 120 | return true; 121 | } 122 | 123 | case async_msg_type::terminate: { 124 | return false; 125 | } 126 | 127 | default: { 128 | assert(false); 129 | } 130 | } 131 | 132 | return true; 133 | } 134 | 135 | } // namespace details 136 | } // namespace spdlog 137 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace spdlog { 17 | class async_logger; 18 | 19 | namespace details { 20 | 21 | using async_logger_ptr = std::shared_ptr; 22 | 23 | enum class async_msg_type 24 | { 25 | log, 26 | flush, 27 | terminate 28 | }; 29 | 30 | // Async msg to move to/from the queue 31 | // Movable only. should never be copied 32 | struct async_msg : log_msg_buffer 33 | { 34 | async_msg_type msg_type{async_msg_type::log}; 35 | async_logger_ptr worker_ptr; 36 | 37 | async_msg() = default; 38 | ~async_msg() = default; 39 | 40 | // should only be moved in or out of the queue.. 41 | async_msg(const async_msg &) = delete; 42 | 43 | // support for vs2013 move 44 | #if defined(_MSC_VER) && _MSC_VER <= 1800 45 | async_msg(async_msg &&other) 46 | : log_msg_buffer(std::move(other)) 47 | , msg_type(other.msg_type) 48 | , worker_ptr(std::move(other.worker_ptr)) 49 | {} 50 | 51 | async_msg &operator=(async_msg &&other) 52 | { 53 | *static_cast(this) = std::move(other); 54 | msg_type = other.msg_type; 55 | worker_ptr = std::move(other.worker_ptr); 56 | return *this; 57 | } 58 | #else // (_MSC_VER) && _MSC_VER <= 1800 59 | async_msg(async_msg &&) = default; 60 | async_msg &operator=(async_msg &&) = default; 61 | #endif 62 | 63 | // construct from log_msg with given type 64 | async_msg(async_logger_ptr &&worker, async_msg_type the_type, const details::log_msg &m) 65 | : log_msg_buffer{m} 66 | , msg_type{the_type} 67 | , worker_ptr{std::move(worker)} 68 | {} 69 | 70 | async_msg(async_logger_ptr &&worker, async_msg_type the_type) 71 | : log_msg_buffer{} 72 | , msg_type{the_type} 73 | , worker_ptr{std::move(worker)} 74 | {} 75 | 76 | explicit async_msg(async_msg_type the_type) 77 | : async_msg{nullptr, the_type} 78 | {} 79 | }; 80 | 81 | class SPDLOG_API thread_pool 82 | { 83 | public: 84 | using item_type = async_msg; 85 | using q_type = details::mpmc_blocking_queue; 86 | 87 | thread_pool(size_t q_max_items, size_t threads_n, std::function on_thread_start, std::function on_thread_stop); 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 and 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 | size_t queue_size(); 101 | 102 | private: 103 | q_type q_; 104 | 105 | std::vector threads_; 106 | 107 | void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy); 108 | void worker_loop_(); 109 | 110 | // process next message in the queue 111 | // return true if this thread should still be active (while no terminate msg 112 | // was received) 113 | bool process_next_msg_(); 114 | }; 115 | 116 | } // namespace details 117 | } // namespace spdlog 118 | 119 | #ifdef SPDLOG_HEADER_ONLY 120 | # include "thread_pool-inl.h" 121 | #endif 122 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/details/udp_client-windows.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // Helper RAII over winsock udp client socket. 7 | // Will throw on construction if socket creation failed. 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #pragma comment(lib, "Ws2_32.lib") 19 | #pragma comment(lib, "Mswsock.lib") 20 | #pragma comment(lib, "AdvApi32.lib") 21 | 22 | namespace spdlog { 23 | namespace details { 24 | class udp_client 25 | { 26 | static constexpr int TX_BUFFER_SIZE = 1024 * 10; 27 | SOCKET socket_ = INVALID_SOCKET; 28 | sockaddr_in addr_ = {0}; 29 | 30 | static void init_winsock_() 31 | { 32 | WSADATA wsaData; 33 | auto rv = ::WSAStartup(MAKEWORD(2, 2), &wsaData); 34 | if (rv != 0) 35 | { 36 | throw_winsock_error_("WSAStartup failed", ::WSAGetLastError()); 37 | } 38 | } 39 | 40 | static void throw_winsock_error_(const std::string &msg, int last_error) 41 | { 42 | char buf[512]; 43 | ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_error, 44 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (sizeof(buf) / sizeof(char)), NULL); 45 | 46 | throw_spdlog_ex(fmt_lib::format("udp_sink - {}: {}", msg, buf)); 47 | } 48 | 49 | void cleanup_() 50 | { 51 | if (socket_ != INVALID_SOCKET) 52 | { 53 | ::closesocket(socket_); 54 | } 55 | socket_ = INVALID_SOCKET; 56 | ::WSACleanup(); 57 | } 58 | 59 | public: 60 | udp_client(const std::string &host, uint16_t port) 61 | { 62 | init_winsock_(); 63 | 64 | addr_.sin_family = PF_INET; 65 | addr_.sin_port = htons(port); 66 | addr_.sin_addr.s_addr = INADDR_ANY; 67 | if (InetPtonA(PF_INET, host.c_str(), &addr_.sin_addr.s_addr) != 1) 68 | { 69 | int last_error = ::WSAGetLastError(); 70 | ::WSACleanup(); 71 | throw_winsock_error_("error: Invalid address!", last_error); 72 | } 73 | 74 | socket_ = ::socket(PF_INET, SOCK_DGRAM, 0); 75 | if (socket_ == INVALID_SOCKET) 76 | { 77 | int last_error = ::WSAGetLastError(); 78 | ::WSACleanup(); 79 | throw_winsock_error_("error: Create Socket failed", last_error); 80 | } 81 | 82 | int option_value = TX_BUFFER_SIZE; 83 | if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast(&option_value), sizeof(option_value)) < 0) 84 | { 85 | int last_error = ::WSAGetLastError(); 86 | cleanup_(); 87 | throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error); 88 | } 89 | } 90 | 91 | ~udp_client() 92 | { 93 | cleanup_(); 94 | } 95 | 96 | SOCKET fd() const 97 | { 98 | return socket_; 99 | } 100 | 101 | void send(const char *data, size_t n_bytes) 102 | { 103 | socklen_t tolen = sizeof(struct sockaddr); 104 | if (::sendto(socket_, data, static_cast(n_bytes), 0, (struct sockaddr *)&addr_, tolen) == -1) 105 | { 106 | throw_spdlog_ex("sendto(2) failed", errno); 107 | } 108 | } 109 | }; 110 | } // namespace details 111 | } // namespace spdlog 112 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/details/udp_client.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // Helper RAII over unix udp client socket. 7 | // Will throw on construction if the socket creation failed. 8 | 9 | #ifdef _WIN32 10 | # error "include udp_client-windows.h instead" 11 | #endif 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | namespace spdlog { 26 | namespace details { 27 | 28 | class udp_client 29 | { 30 | static constexpr int TX_BUFFER_SIZE = 1024 * 10; 31 | int socket_ = -1; 32 | struct sockaddr_in sockAddr_; 33 | 34 | void cleanup_() 35 | { 36 | if (socket_ != -1) 37 | { 38 | ::close(socket_); 39 | socket_ = -1; 40 | } 41 | } 42 | 43 | public: 44 | udp_client(const std::string &host, uint16_t port) 45 | { 46 | socket_ = ::socket(PF_INET, SOCK_DGRAM, 0); 47 | if (socket_ < 0) 48 | { 49 | throw_spdlog_ex("error: Create Socket Failed!"); 50 | } 51 | 52 | int option_value = TX_BUFFER_SIZE; 53 | if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast(&option_value), sizeof(option_value)) < 0) 54 | { 55 | cleanup_(); 56 | throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!"); 57 | } 58 | 59 | sockAddr_.sin_family = AF_INET; 60 | sockAddr_.sin_port = htons(port); 61 | 62 | if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0) 63 | { 64 | cleanup_(); 65 | throw_spdlog_ex("error: Invalid address!"); 66 | } 67 | 68 | ::memset(sockAddr_.sin_zero, 0x00, sizeof(sockAddr_.sin_zero)); 69 | } 70 | 71 | ~udp_client() 72 | { 73 | cleanup_(); 74 | } 75 | 76 | int fd() const 77 | { 78 | return socket_; 79 | } 80 | 81 | // Send exactly n_bytes of the given data. 82 | // On error close the connection and throw. 83 | void send(const char *data, size_t n_bytes) 84 | { 85 | ssize_t toslen = 0; 86 | socklen_t tolen = sizeof(struct sockaddr); 87 | if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == -1) 88 | { 89 | throw_spdlog_ex("sendto(2) failed", errno); 90 | } 91 | } 92 | }; 93 | } // namespace details 94 | } // namespace spdlog 95 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/details/windows_include.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef NOMINMAX 4 | # define NOMINMAX // prevent windows redefining min/max 5 | #endif 6 | 7 | #ifndef WIN32_LEAN_AND_MEAN 8 | # define WIN32_LEAN_AND_MEAN 9 | #endif 10 | 11 | #include 12 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/fmt/bundled/fmt.license.rst: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 - present, Victor Zverovich 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | --- Optional exception to the license --- 23 | 24 | As an exception, if, as a result of your compiling your source code, portions 25 | of this Software are embedded into a machine-executable object form of such 26 | source code, you may redistribute such embedded portions in such object form 27 | without including the above copyright and permission notices. 28 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/fmt/bundled/locale.h: -------------------------------------------------------------------------------- 1 | #include "xchar.h" 2 | #warning fmt/locale.h is deprecated, include fmt/format.h or fmt/xchar.h instead 3 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/fmt/chrono.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's chrono support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | # if !defined(SPDLOG_FMT_EXTERNAL) 13 | # ifdef SPDLOG_HEADER_ONLY 14 | # ifndef FMT_HEADER_ONLY 15 | # define FMT_HEADER_ONLY 16 | # endif 17 | # endif 18 | # include 19 | # else 20 | # include 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/fmt/compile.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's compile-time support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | # if !defined(SPDLOG_FMT_EXTERNAL) 13 | # ifdef SPDLOG_HEADER_ONLY 14 | # ifndef FMT_HEADER_ONLY 15 | # define FMT_HEADER_ONLY 16 | # endif 17 | # endif 18 | # include 19 | # else 20 | # include 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /3rdparty/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 defined(SPDLOG_USE_STD_FORMAT) // SPDLOG_USE_STD_FORMAT is defined - use std::format 14 | # include 15 | #elif !defined(SPDLOG_FMT_EXTERNAL) 16 | # if !defined(SPDLOG_COMPILED_LIB) && !defined(FMT_HEADER_ONLY) 17 | # define FMT_HEADER_ONLY 18 | # endif 19 | # ifndef FMT_USE_WINDOWS_H 20 | # define FMT_USE_WINDOWS_H 0 21 | # endif 22 | // enable the 'n' flag in for backward compatibility with fmt 6.x 23 | # define FMT_DEPRECATED_N_SPECIFIER 24 | # include 25 | # include 26 | #else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib 27 | # include 28 | # include 29 | #endif 30 | -------------------------------------------------------------------------------- /3rdparty/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 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | # if !defined(SPDLOG_FMT_EXTERNAL) 13 | # ifdef SPDLOG_HEADER_ONLY 14 | # ifndef FMT_HEADER_ONLY 15 | # define FMT_HEADER_ONLY 16 | # endif 17 | # endif 18 | # include 19 | # else 20 | # include 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/fmt/ranges.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's ranges support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | # if !defined(SPDLOG_FMT_EXTERNAL) 13 | # ifdef SPDLOG_HEADER_ONLY 14 | # ifndef FMT_HEADER_ONLY 15 | # define FMT_HEADER_ONLY 16 | # endif 17 | # endif 18 | # include 19 | # else 20 | # include 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/fmt/xchar.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's xchar support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | # if !defined(SPDLOG_FMT_EXTERNAL) 13 | # ifdef SPDLOG_HEADER_ONLY 14 | # ifndef FMT_HEADER_ONLY 15 | # define FMT_HEADER_ONLY 16 | # endif 17 | # endif 18 | # include 19 | # else 20 | # include 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 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 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | namespace spdlog { 7 | class logger; 8 | class formatter; 9 | 10 | namespace sinks { 11 | class sink; 12 | } 13 | 14 | namespace level { 15 | enum level_enum : int; 16 | } 17 | 18 | } // namespace spdlog 19 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/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 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | namespace spdlog { 20 | namespace details { 21 | 22 | // padding information. 23 | struct padding_info 24 | { 25 | enum class pad_side 26 | { 27 | left, 28 | right, 29 | center 30 | }; 31 | 32 | padding_info() = default; 33 | padding_info(size_t width, padding_info::pad_side side, bool truncate) 34 | : width_(width) 35 | , side_(side) 36 | , truncate_(truncate) 37 | , enabled_(true) 38 | {} 39 | 40 | bool enabled() const 41 | { 42 | return enabled_; 43 | } 44 | size_t width_ = 0; 45 | pad_side side_ = pad_side::left; 46 | bool truncate_ = false; 47 | bool enabled_ = false; 48 | }; 49 | 50 | class SPDLOG_API flag_formatter 51 | { 52 | public: 53 | explicit flag_formatter(padding_info padinfo) 54 | : padinfo_(padinfo) 55 | {} 56 | flag_formatter() = default; 57 | virtual ~flag_formatter() = default; 58 | virtual void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) = 0; 59 | 60 | protected: 61 | padding_info padinfo_; 62 | }; 63 | 64 | } // namespace details 65 | 66 | class SPDLOG_API custom_flag_formatter : public details::flag_formatter 67 | { 68 | public: 69 | virtual std::unique_ptr clone() const = 0; 70 | 71 | void set_padding_info(const details::padding_info &padding) 72 | { 73 | flag_formatter::padinfo_ = padding; 74 | } 75 | }; 76 | 77 | class SPDLOG_API pattern_formatter final : public formatter 78 | { 79 | public: 80 | using custom_flags = std::unordered_map>; 81 | 82 | explicit pattern_formatter(std::string pattern, pattern_time_type time_type = pattern_time_type::local, 83 | std::string eol = spdlog::details::os::default_eol, custom_flags custom_user_flags = custom_flags()); 84 | 85 | // use default pattern is not given 86 | explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol); 87 | 88 | pattern_formatter(const pattern_formatter &other) = delete; 89 | pattern_formatter &operator=(const pattern_formatter &other) = delete; 90 | 91 | std::unique_ptr clone() const override; 92 | void format(const details::log_msg &msg, memory_buf_t &dest) override; 93 | 94 | template 95 | pattern_formatter &add_flag(char flag, Args &&... args) 96 | { 97 | custom_handlers_[flag] = details::make_unique(std::forward(args)...); 98 | return *this; 99 | } 100 | void set_pattern(std::string pattern); 101 | void need_localtime(bool need = true); 102 | 103 | private: 104 | std::string pattern_; 105 | std::string eol_; 106 | pattern_time_type pattern_time_type_; 107 | bool need_localtime_; 108 | std::tm cached_tm_; 109 | std::chrono::seconds last_log_secs_; 110 | std::vector> formatters_; 111 | custom_flags custom_handlers_; 112 | 113 | std::tm get_time_(const details::log_msg &msg); 114 | template 115 | void handle_flag_(char flag, details::padding_info padding); 116 | 117 | // Extract given pad spec (e.g. %8X) 118 | // Advance the given it pass the end of the padding spec found (if any) 119 | // Return padding. 120 | static details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end); 121 | 122 | void compile_pattern_(const std::string &pattern); 123 | }; 124 | } // namespace spdlog 125 | 126 | #ifdef SPDLOG_HEADER_ONLY 127 | # include "pattern_formatter-inl.h" 128 | #endif 129 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | #include 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(ansicolor_sink &&other) = delete; 34 | 35 | ansicolor_sink &operator=(const ansicolor_sink &other) = delete; 36 | ansicolor_sink &operator=(ansicolor_sink &&other) = delete; 37 | 38 | void set_color(level::level_enum color_level, string_view_t color); 39 | void set_color_mode(color_mode mode); 40 | bool should_color(); 41 | 42 | void log(const details::log_msg &msg) override; 43 | void flush() override; 44 | void set_pattern(const std::string &pattern) final; 45 | void set_formatter(std::unique_ptr sink_formatter) override; 46 | 47 | // Formatting codes 48 | const string_view_t reset = "\033[m"; 49 | const string_view_t bold = "\033[1m"; 50 | const string_view_t dark = "\033[2m"; 51 | const string_view_t underline = "\033[4m"; 52 | const string_view_t blink = "\033[5m"; 53 | const string_view_t reverse = "\033[7m"; 54 | const string_view_t concealed = "\033[8m"; 55 | const string_view_t clear_line = "\033[K"; 56 | 57 | // Foreground colors 58 | const string_view_t black = "\033[30m"; 59 | const string_view_t red = "\033[31m"; 60 | const string_view_t green = "\033[32m"; 61 | const string_view_t yellow = "\033[33m"; 62 | const string_view_t blue = "\033[34m"; 63 | const string_view_t magenta = "\033[35m"; 64 | const string_view_t cyan = "\033[36m"; 65 | const string_view_t white = "\033[37m"; 66 | 67 | /// Background colors 68 | const string_view_t on_black = "\033[40m"; 69 | const string_view_t on_red = "\033[41m"; 70 | const string_view_t on_green = "\033[42m"; 71 | const string_view_t on_yellow = "\033[43m"; 72 | const string_view_t on_blue = "\033[44m"; 73 | const string_view_t on_magenta = "\033[45m"; 74 | const string_view_t on_cyan = "\033[46m"; 75 | const string_view_t on_white = "\033[47m"; 76 | 77 | /// Bold colors 78 | const string_view_t yellow_bold = "\033[33m\033[1m"; 79 | const string_view_t red_bold = "\033[31m\033[1m"; 80 | const string_view_t bold_on_red = "\033[1m\033[41m"; 81 | 82 | private: 83 | FILE *target_file_; 84 | mutex_t &mutex_; 85 | bool should_do_colors_; 86 | std::unique_ptr formatter_; 87 | std::array colors_; 88 | void print_ccode_(const string_view_t &color_code); 89 | void print_range_(const memory_buf_t &formatted, size_t start, size_t end); 90 | static std::string to_string_(const string_view_t &sv); 91 | }; 92 | 93 | template 94 | class ansicolor_stdout_sink : public ansicolor_sink 95 | { 96 | public: 97 | explicit ansicolor_stdout_sink(color_mode mode = color_mode::automatic); 98 | }; 99 | 100 | template 101 | class ansicolor_stderr_sink : public ansicolor_sink 102 | { 103 | public: 104 | explicit ansicolor_stderr_sink(color_mode mode = color_mode::automatic); 105 | }; 106 | 107 | using ansicolor_stdout_sink_mt = ansicolor_stdout_sink; 108 | using ansicolor_stdout_sink_st = ansicolor_stdout_sink; 109 | 110 | using ansicolor_stderr_sink_mt = ansicolor_stderr_sink; 111 | using ansicolor_stderr_sink_st = ansicolor_stderr_sink; 112 | 113 | } // namespace sinks 114 | } // namespace spdlog 115 | 116 | #ifdef SPDLOG_HEADER_ONLY 117 | # include "ansicolor_sink-inl.h" 118 | #endif 119 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #endif 9 | 10 | #include 11 | #include 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 | -------------------------------------------------------------------------------- /3rdparty/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 13 | #include 14 | #include 15 | 16 | namespace spdlog { 17 | namespace sinks { 18 | template 19 | class SPDLOG_API base_sink : public sink 20 | { 21 | public: 22 | base_sink(); 23 | explicit base_sink(std::unique_ptr formatter); 24 | ~base_sink() override = default; 25 | 26 | base_sink(const base_sink &) = delete; 27 | base_sink(base_sink &&) = delete; 28 | 29 | base_sink &operator=(const base_sink &) = delete; 30 | base_sink &operator=(base_sink &&) = delete; 31 | 32 | void log(const details::log_msg &msg) final; 33 | void flush() final; 34 | void set_pattern(const std::string &pattern) final; 35 | void set_formatter(std::unique_ptr sink_formatter) final; 36 | 37 | protected: 38 | // sink formatter 39 | std::unique_ptr formatter_; 40 | Mutex mutex_; 41 | 42 | virtual void sink_it_(const details::log_msg &msg) = 0; 43 | virtual void flush_() = 0; 44 | virtual void set_pattern_(const std::string &pattern); 45 | virtual void set_formatter_(std::unique_ptr sink_formatter); 46 | }; 47 | } // namespace sinks 48 | } // namespace spdlog 49 | 50 | #ifdef SPDLOG_HEADER_ONLY 51 | # include "base_sink-inl.h" 52 | #endif 53 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | namespace sinks { 15 | 16 | template 17 | SPDLOG_INLINE basic_file_sink::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers &event_handlers) 18 | : file_helper_{event_handlers} 19 | { 20 | file_helper_.open(filename, truncate); 21 | } 22 | 23 | template 24 | SPDLOG_INLINE const filename_t &basic_file_sink::filename() const 25 | { 26 | return file_helper_.filename(); 27 | } 28 | 29 | template 30 | SPDLOG_INLINE void basic_file_sink::sink_it_(const details::log_msg &msg) 31 | { 32 | memory_buf_t formatted; 33 | base_sink::formatter_->format(msg, formatted); 34 | file_helper_.write(formatted); 35 | } 36 | 37 | template 38 | SPDLOG_INLINE void basic_file_sink::flush_() 39 | { 40 | file_helper_.flush(); 41 | } 42 | 43 | } // namespace sinks 44 | } // namespace spdlog 45 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace spdlog { 15 | namespace sinks { 16 | /* 17 | * Trivial file sink with single file as target 18 | */ 19 | template 20 | class basic_file_sink final : public base_sink 21 | { 22 | public: 23 | explicit basic_file_sink(const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {}); 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( 44 | const std::string &logger_name, const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {}) 45 | { 46 | return Factory::template create(logger_name, filename, truncate, event_handlers); 47 | } 48 | 49 | template 50 | inline std::shared_ptr basic_logger_st( 51 | const std::string &logger_name, const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {}) 52 | { 53 | return Factory::template create(logger_name, filename, truncate, event_handlers); 54 | } 55 | 56 | } // namespace spdlog 57 | 58 | #ifdef SPDLOG_HEADER_ONLY 59 | # include "basic_file_sink-inl.h" 60 | #endif 61 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // Distribution sink (mux). Stores a vector of sinks which get called when log 17 | // is called 18 | 19 | namespace spdlog { 20 | namespace sinks { 21 | 22 | template 23 | class dist_sink : public base_sink 24 | { 25 | public: 26 | dist_sink() = default; 27 | explicit dist_sink(std::vector> sinks) 28 | : sinks_(sinks) 29 | {} 30 | 31 | dist_sink(const dist_sink &) = delete; 32 | dist_sink &operator=(const dist_sink &) = delete; 33 | 34 | void add_sink(std::shared_ptr sink) 35 | { 36 | std::lock_guard lock(base_sink::mutex_); 37 | sinks_.push_back(sink); 38 | } 39 | 40 | void remove_sink(std::shared_ptr sink) 41 | { 42 | std::lock_guard lock(base_sink::mutex_); 43 | sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); 44 | } 45 | 46 | void set_sinks(std::vector> sinks) 47 | { 48 | std::lock_guard lock(base_sink::mutex_); 49 | sinks_ = std::move(sinks); 50 | } 51 | 52 | std::vector> &sinks() 53 | { 54 | return sinks_; 55 | } 56 | 57 | protected: 58 | void sink_it_(const details::log_msg &msg) override 59 | { 60 | for (auto &sink : sinks_) 61 | { 62 | if (sink->should_log(msg.level)) 63 | { 64 | sink->log(msg); 65 | } 66 | } 67 | } 68 | 69 | void flush_() override 70 | { 71 | for (auto &sink : sinks_) 72 | { 73 | sink->flush(); 74 | } 75 | } 76 | 77 | void set_pattern_(const std::string &pattern) override 78 | { 79 | set_formatter_(details::make_unique(pattern)); 80 | } 81 | 82 | void set_formatter_(std::unique_ptr sink_formatter) override 83 | { 84 | base_sink::formatter_ = std::move(sink_formatter); 85 | for (auto &sink : sinks_) 86 | { 87 | sink->set_formatter(base_sink::formatter_->clone()); 88 | } 89 | } 90 | std::vector> sinks_; 91 | }; 92 | 93 | using dist_sink_mt = dist_sink; 94 | using dist_sink_st = dist_sink; 95 | 96 | } // namespace sinks 97 | } // namespace spdlog 98 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | // Duplicate message removal sink. 16 | // Skip the message if previous one is identical and less than "max_skip_duration" have passed 17 | // 18 | // Example: 19 | // 20 | // #include 21 | // 22 | // int main() { 23 | // auto dup_filter = std::make_shared(std::chrono::seconds(5)); 24 | // dup_filter->add_sink(std::make_shared()); 25 | // spdlog::logger l("logger", dup_filter); 26 | // l.info("Hello"); 27 | // l.info("Hello"); 28 | // l.info("Hello"); 29 | // l.info("Different Hello"); 30 | // } 31 | // 32 | // Will produce: 33 | // [2019-06-25 17:50:56.511] [logger] [info] Hello 34 | // [2019-06-25 17:50:56.512] [logger] [info] Skipped 3 duplicate messages.. 35 | // [2019-06-25 17:50:56.512] [logger] [info] Different Hello 36 | 37 | namespace spdlog { 38 | namespace sinks { 39 | template 40 | class dup_filter_sink : public dist_sink 41 | { 42 | public: 43 | template 44 | explicit dup_filter_sink(std::chrono::duration max_skip_duration) 45 | : max_skip_duration_{max_skip_duration} 46 | {} 47 | 48 | protected: 49 | std::chrono::microseconds max_skip_duration_; 50 | log_clock::time_point last_msg_time_; 51 | std::string last_msg_payload_; 52 | size_t skip_counter_ = 0; 53 | 54 | void sink_it_(const details::log_msg &msg) override 55 | { 56 | bool filtered = filter_(msg); 57 | if (!filtered) 58 | { 59 | skip_counter_ += 1; 60 | return; 61 | } 62 | 63 | // log the "skipped.." message 64 | if (skip_counter_ > 0) 65 | { 66 | char buf[64]; 67 | auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast(skip_counter_)); 68 | if (msg_size > 0 && static_cast(msg_size) < sizeof(buf)) 69 | { 70 | details::log_msg skipped_msg{msg.logger_name, level::info, string_view_t{buf, static_cast(msg_size)}}; 71 | dist_sink::sink_it_(skipped_msg); 72 | } 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 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/sinks/mongo_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 | // 7 | // Custom sink for mongodb 8 | // Building and using requires mongocxx library. 9 | // For building mongocxx library check the url below 10 | // http://mongocxx.org/mongocxx-v3/installation/ 11 | // 12 | 13 | #include "spdlog/common.h" 14 | #include "spdlog/details/log_msg.h" 15 | #include "spdlog/sinks/base_sink.h" 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace spdlog { 27 | namespace sinks { 28 | template 29 | class mongo_sink : public base_sink 30 | { 31 | public: 32 | mongo_sink(const std::string &db_name, const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017") 33 | { 34 | try 35 | { 36 | client_ = spdlog::details::make_unique(mongocxx::uri{uri}); 37 | db_name_ = db_name; 38 | coll_name_ = collection_name; 39 | } 40 | catch (const std::exception) 41 | { 42 | throw spdlog_ex("Error opening database"); 43 | } 44 | } 45 | 46 | ~mongo_sink() 47 | { 48 | flush_(); 49 | } 50 | 51 | protected: 52 | void sink_it_(const details::log_msg &msg) override 53 | { 54 | using bsoncxx::builder::stream::document; 55 | using bsoncxx::builder::stream::finalize; 56 | 57 | if (client_ != nullptr) 58 | { 59 | auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << level::to_string_view(msg.level).data() 60 | << "message" << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name" 61 | << std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id" 62 | << static_cast(msg.thread_id) << finalize; 63 | client_->database(db_name_).collection(coll_name_).insert_one(doc.view()); 64 | } 65 | } 66 | 67 | void flush_() override {} 68 | 69 | private: 70 | static mongocxx::instance instance_; 71 | std::string db_name_; 72 | std::string coll_name_; 73 | std::unique_ptr client_ = nullptr; 74 | }; 75 | template<> 76 | mongocxx::instance mongo_sink::instance_{}; 77 | 78 | #include "spdlog/details/null_mutex.h" 79 | #include 80 | using mongo_sink_mt = mongo_sink; 81 | using mongo_sink_st = mongo_sink; 82 | 83 | } // namespace sinks 84 | 85 | template 86 | inline std::shared_ptr mongo_logger_mt(const std::string &logger_name, const std::string &db_name, 87 | const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017") 88 | { 89 | return Factory::template create(logger_name, db_name, collection_name, uri); 90 | } 91 | 92 | template 93 | inline std::shared_ptr mongo_logger_st(const std::string &logger_name, const std::string &db_name, 94 | const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017") 95 | { 96 | return Factory::template create(logger_name, db_name, collection_name, uri); 97 | } 98 | 99 | } // namespace spdlog 100 | -------------------------------------------------------------------------------- /3rdparty/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 9 | # include 10 | 11 | # include 12 | # include 13 | 14 | // Avoid including windows.h (https://stackoverflow.com/a/30741042) 15 | extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString); 16 | 17 | namespace spdlog { 18 | namespace sinks { 19 | /* 20 | * MSVC sink (logging using OutputDebugStringA) 21 | */ 22 | template 23 | class msvc_sink : public base_sink 24 | { 25 | public: 26 | msvc_sink() = default; 27 | 28 | protected: 29 | void sink_it_(const details::log_msg &msg) override 30 | { 31 | memory_buf_t formatted; 32 | base_sink::formatter_->format(msg, formatted); 33 | formatted.push_back('\0'); // add a null terminator for OutputDebugStringA 34 | OutputDebugStringA(formatted.data()); 35 | } 36 | 37 | void flush_() override {} 38 | }; 39 | 40 | using msvc_sink_mt = msvc_sink; 41 | using msvc_sink_st = msvc_sink; 42 | 43 | using windebug_sink_mt = msvc_sink_mt; 44 | using windebug_sink_st = msvc_sink_st; 45 | 46 | } // namespace sinks 47 | } // namespace spdlog 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | 15 | template 16 | class null_sink : public base_sink 17 | { 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 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | template 15 | class ostream_sink final : public base_sink 16 | { 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 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/sinks/qt_sinks.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman, mguludag and spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // 7 | // Custom sink for QPlainTextEdit or QTextEdit and its childs(QTextBrowser... 8 | // etc) Building and using requires Qt library. 9 | // 10 | 11 | #include "spdlog/common.h" 12 | #include "spdlog/details/log_msg.h" 13 | #include "spdlog/details/synchronous_factory.h" 14 | #include "spdlog/sinks/base_sink.h" 15 | 16 | #include 17 | #include 18 | 19 | // 20 | // qt_sink class 21 | // 22 | namespace spdlog { 23 | namespace sinks { 24 | template 25 | class qt_sink : public base_sink 26 | { 27 | public: 28 | qt_sink(QObject *qt_object, const std::string &meta_method) 29 | { 30 | qt_object_ = qt_object; 31 | meta_method_ = meta_method; 32 | } 33 | 34 | ~qt_sink() 35 | { 36 | flush_(); 37 | } 38 | 39 | protected: 40 | void sink_it_(const details::log_msg &msg) override 41 | { 42 | memory_buf_t formatted; 43 | base_sink::formatter_->format(msg, formatted); 44 | string_view_t str = string_view_t(formatted.data(), formatted.size()); 45 | QMetaObject::invokeMethod(qt_object_, meta_method_.c_str(), Qt::AutoConnection, 46 | Q_ARG(QString, QString::fromUtf8(str.data(), static_cast(str.size())).trimmed())); 47 | } 48 | 49 | void flush_() override {} 50 | 51 | private: 52 | QObject *qt_object_ = nullptr; 53 | std::string meta_method_; 54 | }; 55 | 56 | #include "spdlog/details/null_mutex.h" 57 | #include 58 | using qt_sink_mt = qt_sink; 59 | using qt_sink_st = qt_sink; 60 | } // namespace sinks 61 | 62 | // 63 | // Factory functions 64 | // 65 | template 66 | inline std::shared_ptr qt_logger_mt(const std::string &logger_name, QTextEdit *qt_object, const std::string &meta_method = "append") 67 | { 68 | return Factory::template create(logger_name, qt_object, meta_method); 69 | } 70 | 71 | template 72 | inline std::shared_ptr qt_logger_st(const std::string &logger_name, QTextEdit *qt_object, const std::string &meta_method = "append") 73 | { 74 | return Factory::template create(logger_name, qt_object, meta_method); 75 | } 76 | 77 | template 78 | inline std::shared_ptr qt_logger_mt( 79 | const std::string &logger_name, QPlainTextEdit *qt_object, const std::string &meta_method = "appendPlainText") 80 | { 81 | return Factory::template create(logger_name, qt_object, meta_method); 82 | } 83 | 84 | template 85 | inline std::shared_ptr qt_logger_st( 86 | const std::string &logger_name, QPlainTextEdit *qt_object, const std::string &meta_method = "appendPlainText") 87 | { 88 | return Factory::template create(logger_name, qt_object, meta_method); 89 | } 90 | 91 | template 92 | inline std::shared_ptr qt_logger_mt(const std::string &logger_name, QObject *qt_object, const std::string &meta_method) 93 | { 94 | return Factory::template create(logger_name, qt_object, meta_method); 95 | } 96 | 97 | template 98 | inline std::shared_ptr qt_logger_st(const std::string &logger_name, QObject *qt_object, const std::string &meta_method) 99 | { 100 | return Factory::template create(logger_name, qt_object, meta_method); 101 | } 102 | } // namespace spdlog 103 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/sinks/ringbuffer_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/sinks/base_sink.h" 7 | #include "spdlog/details/circular_q.h" 8 | #include "spdlog/details/log_msg_buffer.h" 9 | #include "spdlog/details/null_mutex.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace spdlog { 16 | namespace sinks { 17 | /* 18 | * Ring buffer sink 19 | */ 20 | template 21 | class ringbuffer_sink final : public base_sink 22 | { 23 | public: 24 | explicit ringbuffer_sink(size_t n_items) 25 | : q_{n_items} 26 | {} 27 | 28 | std::vector last_raw(size_t lim = 0) 29 | { 30 | std::lock_guard lock(base_sink::mutex_); 31 | auto items_available = q_.size(); 32 | auto n_items = lim > 0 ? (std::min)(lim, items_available) : items_available; 33 | std::vector ret; 34 | ret.reserve(n_items); 35 | for (size_t i = (items_available - n_items); i < items_available; i++) 36 | { 37 | ret.push_back(q_.at(i)); 38 | } 39 | return ret; 40 | } 41 | 42 | std::vector last_formatted(size_t lim = 0) 43 | { 44 | std::lock_guard lock(base_sink::mutex_); 45 | auto items_available = q_.size(); 46 | auto n_items = lim > 0 ? (std::min)(lim, items_available) : items_available; 47 | std::vector ret; 48 | ret.reserve(n_items); 49 | for (size_t i = (items_available - n_items); i < items_available; i++) 50 | { 51 | memory_buf_t formatted; 52 | base_sink::formatter_->format(q_.at(i), formatted); 53 | ret.push_back(std::move(SPDLOG_BUF_TO_STRING(formatted))); 54 | } 55 | return ret; 56 | } 57 | 58 | protected: 59 | void sink_it_(const details::log_msg &msg) override 60 | { 61 | q_.push_back(details::log_msg_buffer{msg}); 62 | } 63 | void flush_() override {} 64 | 65 | private: 66 | details::circular_q q_; 67 | }; 68 | 69 | using ringbuffer_sink_mt = ringbuffer_sink; 70 | using ringbuffer_sink_st = ringbuffer_sink; 71 | 72 | } // namespace sinks 73 | 74 | } // namespace spdlog 75 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace spdlog { 16 | namespace sinks { 17 | 18 | // 19 | // Rotating file sink based on size 20 | // 21 | template 22 | class rotating_file_sink final : public base_sink 23 | { 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 | const file_event_handlers &event_handlers = {}); 27 | static filename_t calc_filename(const filename_t &filename, std::size_t index); 28 | filename_t filename(); 29 | 30 | protected: 31 | void sink_it_(const details::log_msg &msg) override; 32 | void flush_() override; 33 | 34 | private: 35 | // Rotate files: 36 | // log.txt -> log.1.txt 37 | // log.1.txt -> log.2.txt 38 | // log.2.txt -> log.3.txt 39 | // log.3.txt -> delete 40 | void rotate_(); 41 | 42 | // delete the target if exists, and rename the src file to target 43 | // return true on success, false otherwise. 44 | bool rename_file_(const filename_t &src_filename, const filename_t &target_filename); 45 | 46 | filename_t base_filename_; 47 | std::size_t max_size_; 48 | std::size_t max_files_; 49 | std::size_t current_size_; 50 | details::file_helper file_helper_; 51 | }; 52 | 53 | using rotating_file_sink_mt = rotating_file_sink; 54 | using rotating_file_sink_st = rotating_file_sink; 55 | 56 | } // namespace sinks 57 | 58 | // 59 | // factory functions 60 | // 61 | 62 | template 63 | inline std::shared_ptr rotating_logger_mt(const std::string &logger_name, const filename_t &filename, size_t max_file_size, 64 | size_t max_files, bool rotate_on_open = false, const file_event_handlers &event_handlers = {}) 65 | { 66 | return Factory::template create( 67 | logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers); 68 | } 69 | 70 | template 71 | inline std::shared_ptr rotating_logger_st(const std::string &logger_name, const filename_t &filename, size_t max_file_size, 72 | size_t max_files, bool rotate_on_open = false, const file_event_handlers &event_handlers = {}) 73 | { 74 | return Factory::template create( 75 | logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers); 76 | } 77 | } // namespace spdlog 78 | 79 | #ifdef SPDLOG_HEADER_ONLY 80 | # include "rotating_file_sink-inl.h" 81 | #endif 82 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #endif 9 | 10 | #include 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 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | 9 | namespace spdlog { 10 | 11 | namespace sinks { 12 | class SPDLOG_API 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 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | 15 | template 16 | SPDLOG_INLINE std::shared_ptr stdout_color_mt(const std::string &logger_name, 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 39 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #else 9 | # include 10 | #endif 11 | 12 | #include 13 | 14 | namespace spdlog { 15 | namespace sinks { 16 | #ifdef _WIN32 17 | using stdout_color_sink_mt = wincolor_stdout_sink_mt; 18 | using stdout_color_sink_st = wincolor_stdout_sink_st; 19 | using stderr_color_sink_mt = wincolor_stderr_sink_mt; 20 | using stderr_color_sink_st = wincolor_stderr_sink_st; 21 | #else 22 | using stdout_color_sink_mt = ansicolor_stdout_sink_mt; 23 | using stdout_color_sink_st = ansicolor_stdout_sink_st; 24 | using stderr_color_sink_mt = ansicolor_stderr_sink_mt; 25 | using stderr_color_sink_st = ansicolor_stderr_sink_st; 26 | #endif 27 | } // namespace sinks 28 | 29 | template 30 | std::shared_ptr stdout_color_mt(const std::string &logger_name, 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 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef _WIN32 12 | # include 13 | #endif 14 | 15 | namespace spdlog { 16 | 17 | namespace sinks { 18 | 19 | template 20 | class stdout_sink_base : public sink 21 | { 22 | public: 23 | using mutex_t = typename ConsoleMutex::mutex_t; 24 | explicit stdout_sink_base(FILE *file); 25 | ~stdout_sink_base() override = default; 26 | 27 | stdout_sink_base(const stdout_sink_base &other) = delete; 28 | stdout_sink_base(stdout_sink_base &&other) = delete; 29 | 30 | stdout_sink_base &operator=(const stdout_sink_base &other) = delete; 31 | stdout_sink_base &operator=(stdout_sink_base &&other) = delete; 32 | 33 | void log(const details::log_msg &msg) override; 34 | void flush() override; 35 | void set_pattern(const std::string &pattern) override; 36 | 37 | void set_formatter(std::unique_ptr sink_formatter) override; 38 | 39 | protected: 40 | mutex_t &mutex_; 41 | FILE *file_; 42 | std::unique_ptr formatter_; 43 | #ifdef _WIN32 44 | HANDLE handle_; 45 | #endif // WIN32 46 | }; 47 | 48 | template 49 | class stdout_sink : public stdout_sink_base 50 | { 51 | public: 52 | stdout_sink(); 53 | }; 54 | 55 | template 56 | class stderr_sink : public stdout_sink_base 57 | { 58 | public: 59 | stderr_sink(); 60 | }; 61 | 62 | using stdout_sink_mt = stdout_sink; 63 | using stdout_sink_st = stdout_sink; 64 | 65 | using stderr_sink_mt = stderr_sink; 66 | using stderr_sink_st = stderr_sink; 67 | 68 | } // namespace sinks 69 | 70 | // factory methods 71 | template 72 | std::shared_ptr stdout_logger_mt(const std::string &logger_name); 73 | 74 | template 75 | std::shared_ptr stdout_logger_st(const std::string &logger_name); 76 | 77 | template 78 | std::shared_ptr stderr_logger_mt(const std::string &logger_name); 79 | 80 | template 81 | std::shared_ptr stderr_logger_st(const std::string &logger_name); 82 | 83 | } // namespace spdlog 84 | 85 | #ifdef SPDLOG_HEADER_ONLY 86 | # include "stdout_sinks-inl.h" 87 | #endif 88 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace spdlog { 15 | namespace sinks { 16 | /** 17 | * Sink that write to syslog using the `syscall()` library call. 18 | */ 19 | template 20 | class syslog_sink : public base_sink 21 | { 22 | 23 | public: 24 | syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting) 25 | : enable_formatting_{enable_formatting} 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 | , ident_{std::move(ident)} 34 | { 35 | // set ident to be program name if empty 36 | ::openlog(ident_.empty() ? nullptr : ident_.c_str(), syslog_option, syslog_facility); 37 | } 38 | 39 | ~syslog_sink() override 40 | { 41 | ::closelog(); 42 | } 43 | 44 | syslog_sink(const syslog_sink &) = delete; 45 | syslog_sink &operator=(const syslog_sink &) = delete; 46 | 47 | protected: 48 | void sink_it_(const details::log_msg &msg) override 49 | { 50 | string_view_t payload; 51 | memory_buf_t formatted; 52 | if (enable_formatting_) 53 | { 54 | base_sink::formatter_->format(msg, formatted); 55 | payload = string_view_t(formatted.data(), formatted.size()); 56 | } 57 | else 58 | { 59 | payload = msg.payload; 60 | } 61 | 62 | size_t length = payload.size(); 63 | // limit to max int 64 | if (length > static_cast(std::numeric_limits::max())) 65 | { 66 | length = static_cast(std::numeric_limits::max()); 67 | } 68 | 69 | ::syslog(syslog_prio_from_level(msg), "%.*s", static_cast(length), payload.data()); 70 | } 71 | 72 | void flush_() override {} 73 | bool enable_formatting_ = false; 74 | 75 | private: 76 | using levels_array = std::array; 77 | levels_array syslog_levels_; 78 | // must store the ident because the man says openlog might use the pointer as 79 | // is and not a string copy 80 | const std::string ident_; 81 | 82 | // 83 | // Simply maps spdlog's log level to syslog priority level. 84 | // 85 | int syslog_prio_from_level(const details::log_msg &msg) const 86 | { 87 | return syslog_levels_.at(static_cast(msg.level)); 88 | } 89 | }; 90 | 91 | using syslog_sink_mt = syslog_sink; 92 | using syslog_sink_st = syslog_sink; 93 | } // namespace sinks 94 | 95 | // Create and register a syslog logger 96 | template 97 | inline std::shared_ptr syslog_logger_mt(const std::string &logger_name, const std::string &syslog_ident = "", int syslog_option = 0, 98 | int syslog_facility = LOG_USER, bool enable_formatting = false) 99 | { 100 | return Factory::template create(logger_name, syslog_ident, syslog_option, syslog_facility, enable_formatting); 101 | } 102 | 103 | template 104 | inline std::shared_ptr syslog_logger_st(const std::string &logger_name, const std::string &syslog_ident = "", int syslog_option = 0, 105 | int syslog_facility = LOG_USER, bool enable_formatting = false) 106 | { 107 | return Factory::template create(logger_name, syslog_ident, syslog_option, syslog_facility, enable_formatting); 108 | } 109 | } // namespace spdlog 110 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/sinks/tcp_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #ifdef _WIN32 10 | # include 11 | #else 12 | # include 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #pragma once 21 | 22 | // Simple tcp client sink 23 | // Connects to remote address and send the formatted log. 24 | // Will attempt to reconnect if connection drops. 25 | // If more complicated behaviour is needed (i.e get responses), you can inherit it and override the sink_it_ method. 26 | 27 | namespace spdlog { 28 | namespace sinks { 29 | 30 | struct tcp_sink_config 31 | { 32 | std::string server_host; 33 | int server_port; 34 | bool lazy_connect = false; // if true connect on first log call instead of on construction 35 | 36 | tcp_sink_config(std::string host, int port) 37 | : server_host{std::move(host)} 38 | , server_port{port} 39 | {} 40 | }; 41 | 42 | template 43 | class tcp_sink : public spdlog::sinks::base_sink 44 | { 45 | public: 46 | // connect to tcp host/port or throw if failed 47 | // host can be hostname or ip address 48 | 49 | explicit tcp_sink(tcp_sink_config sink_config) 50 | : config_{std::move(sink_config)} 51 | { 52 | if (!config_.lazy_connect) 53 | { 54 | this->client_.connect(config_.server_host, config_.server_port); 55 | } 56 | } 57 | 58 | ~tcp_sink() override = default; 59 | 60 | protected: 61 | void sink_it_(const spdlog::details::log_msg &msg) override 62 | { 63 | spdlog::memory_buf_t formatted; 64 | spdlog::sinks::base_sink::formatter_->format(msg, formatted); 65 | if (!client_.is_connected()) 66 | { 67 | client_.connect(config_.server_host, config_.server_port); 68 | } 69 | client_.send(formatted.data(), formatted.size()); 70 | } 71 | 72 | void flush_() override {} 73 | tcp_sink_config config_; 74 | details::tcp_client client_; 75 | }; 76 | 77 | using tcp_sink_mt = tcp_sink; 78 | using tcp_sink_st = tcp_sink; 79 | 80 | } // namespace sinks 81 | } // namespace spdlog 82 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/sinks/udp_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #ifdef _WIN32 10 | # include 11 | #else 12 | # include 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | // Simple udp client sink 21 | // Sends formatted log via udp 22 | 23 | namespace spdlog { 24 | namespace sinks { 25 | 26 | struct udp_sink_config 27 | { 28 | std::string server_host; 29 | uint16_t server_port; 30 | 31 | udp_sink_config(std::string host, uint16_t port) 32 | : server_host{std::move(host)} 33 | , server_port{port} 34 | {} 35 | }; 36 | 37 | template 38 | class udp_sink : public spdlog::sinks::base_sink 39 | { 40 | public: 41 | // host can be hostname or ip address 42 | explicit udp_sink(udp_sink_config sink_config) 43 | : client_{sink_config.server_host, sink_config.server_port} 44 | {} 45 | 46 | ~udp_sink() override = default; 47 | 48 | protected: 49 | void sink_it_(const spdlog::details::log_msg &msg) override 50 | { 51 | spdlog::memory_buf_t formatted; 52 | spdlog::sinks::base_sink::formatter_->format(msg, formatted); 53 | client_.send(formatted.data(), formatted.size()); 54 | } 55 | 56 | void flush_() override {} 57 | details::udp_client client_; 58 | }; 59 | 60 | using udp_sink_mt = udp_sink; 61 | using udp_sink_st = udp_sink; 62 | 63 | } // namespace sinks 64 | 65 | // 66 | // factory functions 67 | // 68 | template 69 | inline std::shared_ptr udp_logger_mt(const std::string &logger_name, sinks::udp_sink_config skin_config) 70 | { 71 | return Factory::template create(logger_name, skin_config); 72 | } 73 | 74 | } // namespace spdlog 75 | -------------------------------------------------------------------------------- /3rdparty/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 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace spdlog { 18 | namespace sinks { 19 | /* 20 | * Windows color console sink. Uses WriteConsoleA to write to the console with 21 | * colors 22 | */ 23 | template 24 | class wincolor_sink : public sink 25 | { 26 | public: 27 | wincolor_sink(void *out_handle, color_mode mode); 28 | ~wincolor_sink() override; 29 | 30 | wincolor_sink(const wincolor_sink &other) = delete; 31 | wincolor_sink &operator=(const wincolor_sink &other) = delete; 32 | 33 | // change the color for the given level 34 | void set_color(level::level_enum level, std::uint16_t color); 35 | void log(const details::log_msg &msg) final override; 36 | void flush() final override; 37 | void set_pattern(const std::string &pattern) override final; 38 | void set_formatter(std::unique_ptr sink_formatter) override final; 39 | void set_color_mode(color_mode mode); 40 | 41 | protected: 42 | using mutex_t = typename ConsoleMutex::mutex_t; 43 | void *out_handle_; 44 | mutex_t &mutex_; 45 | bool should_do_colors_; 46 | std::unique_ptr formatter_; 47 | std::array colors_; 48 | 49 | // set foreground color and return the orig console attributes (for resetting later) 50 | std::uint16_t set_foreground_color_(std::uint16_t attribs); 51 | 52 | // print a range of formatted message to console 53 | void print_range_(const memory_buf_t &formatted, size_t start, size_t end); 54 | 55 | // in case we are redirected to file (not in console mode) 56 | void write_to_file_(const memory_buf_t &formatted); 57 | 58 | void set_color_mode_impl(color_mode mode); 59 | }; 60 | 61 | template 62 | class wincolor_stdout_sink : public wincolor_sink 63 | { 64 | public: 65 | explicit wincolor_stdout_sink(color_mode mode = color_mode::automatic); 66 | }; 67 | 68 | template 69 | class wincolor_stderr_sink : public wincolor_sink 70 | { 71 | public: 72 | explicit wincolor_stderr_sink(color_mode mode = color_mode::automatic); 73 | }; 74 | 75 | using wincolor_stdout_sink_mt = wincolor_stdout_sink; 76 | using wincolor_stdout_sink_st = wincolor_stdout_sink; 77 | 78 | using wincolor_stderr_sink_mt = wincolor_stderr_sink; 79 | using wincolor_stderr_sink_st = wincolor_stderr_sink; 80 | } // namespace sinks 81 | } // namespace spdlog 82 | 83 | #ifdef SPDLOG_HEADER_ONLY 84 | # include "wincolor_sink-inl.h" 85 | #endif 86 | -------------------------------------------------------------------------------- /3rdparty/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 8 | #endif 9 | 10 | #include 11 | #include 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 level::level_enum get_level() 51 | { 52 | return default_logger_raw()->level(); 53 | } 54 | 55 | SPDLOG_INLINE bool should_log(level::level_enum log_level) 56 | { 57 | return default_logger_raw()->should_log(log_level); 58 | } 59 | 60 | SPDLOG_INLINE void set_level(level::level_enum log_level) 61 | { 62 | details::registry::instance().set_level(log_level); 63 | } 64 | 65 | SPDLOG_INLINE void flush_on(level::level_enum log_level) 66 | { 67 | details::registry::instance().flush_on(log_level); 68 | } 69 | 70 | SPDLOG_INLINE void flush_every(std::chrono::seconds interval) 71 | { 72 | details::registry::instance().flush_every(interval); 73 | } 74 | 75 | SPDLOG_INLINE void set_error_handler(void (*handler)(const std::string &msg)) 76 | { 77 | details::registry::instance().set_error_handler(handler); 78 | } 79 | 80 | SPDLOG_INLINE void register_logger(std::shared_ptr logger) 81 | { 82 | details::registry::instance().register_logger(std::move(logger)); 83 | } 84 | 85 | SPDLOG_INLINE void apply_all(const std::function)> &fun) 86 | { 87 | details::registry::instance().apply_all(fun); 88 | } 89 | 90 | SPDLOG_INLINE void drop(const std::string &name) 91 | { 92 | details::registry::instance().drop(name); 93 | } 94 | 95 | SPDLOG_INLINE void drop_all() 96 | { 97 | details::registry::instance().drop_all(); 98 | } 99 | 100 | SPDLOG_INLINE void shutdown() 101 | { 102 | details::registry::instance().shutdown(); 103 | } 104 | 105 | SPDLOG_INLINE void set_automatic_registration(bool automatic_registration) 106 | { 107 | details::registry::instance().set_automatic_registration(automatic_registration); 108 | } 109 | 110 | SPDLOG_INLINE std::shared_ptr default_logger() 111 | { 112 | return details::registry::instance().default_logger(); 113 | } 114 | 115 | SPDLOG_INLINE spdlog::logger *default_logger_raw() 116 | { 117 | return details::registry::instance().get_default_raw(); 118 | } 119 | 120 | SPDLOG_INLINE void set_default_logger(std::shared_ptr default_logger) 121 | { 122 | details::registry::instance().set_default_logger(std::move(default_logger)); 123 | } 124 | 125 | } // namespace spdlog 126 | -------------------------------------------------------------------------------- /3rdparty/include/spdlog/stopwatch.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | // Stopwatch support for spdlog (using std::chrono::steady_clock). 9 | // Displays elapsed seconds since construction as double. 10 | // 11 | // Usage: 12 | // 13 | // spdlog::stopwatch sw; 14 | // ... 15 | // spdlog::debug("Elapsed: {} seconds", sw); => "Elapsed 0.005116733 seconds" 16 | // spdlog::info("Elapsed: {:.6} seconds", sw); => "Elapsed 0.005163 seconds" 17 | // 18 | // 19 | // If other units are needed (e.g. millis instead of double), include "fmt/chrono.h" and use "duration_cast<..>(sw.elapsed())": 20 | // 21 | // #include 22 | //.. 23 | // using std::chrono::duration_cast; 24 | // using std::chrono::milliseconds; 25 | // spdlog::info("Elapsed {}", duration_cast(sw.elapsed())); => "Elapsed 5ms" 26 | 27 | namespace spdlog { 28 | class stopwatch 29 | { 30 | using clock = std::chrono::steady_clock; 31 | std::chrono::time_point start_tp_; 32 | 33 | public: 34 | stopwatch() 35 | : start_tp_{clock::now()} 36 | {} 37 | 38 | std::chrono::duration elapsed() const 39 | { 40 | return std::chrono::duration(clock::now() - start_tp_); 41 | } 42 | 43 | void reset() 44 | { 45 | start_tp_ = clock::now(); 46 | } 47 | }; 48 | } // namespace spdlog 49 | 50 | // Support for fmt formatting (e.g. "{:012.9}" or just "{}") 51 | namespace 52 | #ifdef SPDLOG_USE_STD_FORMAT 53 | std 54 | #else 55 | fmt 56 | #endif 57 | { 58 | 59 | template<> 60 | struct formatter : formatter 61 | { 62 | template 63 | auto format(const spdlog::stopwatch &sw, FormatContext &ctx) -> decltype(ctx.out()) 64 | { 65 | return formatter::format(sw.elapsed().count(), ctx); 66 | } 67 | }; 68 | } // namespace std 69 | -------------------------------------------------------------------------------- /3rdparty/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 10 8 | #define SPDLOG_VER_PATCH 0 9 | 10 | #define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH) 11 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | project(Genetic) 3 | set(CMAKE_CXX_STANDARD 11) 4 | 5 | set(THIRD_PARTY_PATH ${PROJECT_SOURCE_DIR}/3rdparty) 6 | 7 | 8 | add_definitions(-DASIO_STANDALONE) 9 | add_definitions(-DORMPP_ENABLE_MYSQL) 10 | 11 | include_directories(${THIRD_PARTY_PATH}/include) 12 | include_directories(${PROJECT_SOURCE_DIR}/kafka) 13 | include_directories(${PROJECT_SOURCE_DIR}/net/include) 14 | include_directories(${PROJECT_SOURCE_DIR}/tools) 15 | 16 | include_directories(${THIRD_PARTY_PATH}/include) 17 | 18 | link_directories(${THIRD_PARTY_PATH}/lib) 19 | 20 | ADD_SUBDIRECTORY(EasyThreadPool) 21 | ADD_SUBDIRECTORY(queue) 22 | ADD_SUBDIRECTORY(GenerateIterate) 23 | ADD_SUBDIRECTORY(PlayGame) 24 | 25 | add_library(${PROJECT_NAME} main.cpp ) 26 | 27 | 28 | set(gene Generate) 29 | set(gene_SOURCE main.cpp) 30 | 31 | add_executable(${gene} ${gene_SOURCE}) 32 | 33 | target_link_libraries(${gene} sixpiece GenerateIterate) 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /EasyThreadPool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | project(easythreadpool) 3 | set(CMAKE_CXX_STANDARD 11) 4 | add_library(${PROJECT_NAME} easythreadpool.cpp easythreadpool.h) 5 | 6 | #set_target_properties(easythreadpool PROPERTIES LINKER_LANGUAGE CXX) -------------------------------------------------------------------------------- /EasyThreadPool/easythreadpool.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Parsifal on 2022/8/22. 3 | // 4 | //#include "easythreadpool.h" 5 | // 6 | //threadpool::threadpool(size_t t) { 7 | // for (int i = 0; i < t; i++) { 8 | // pool.emplace_back(&threadpool::schedual, this); 9 | // } 10 | //} 11 | -------------------------------------------------------------------------------- /GenerateIterate/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GenerateIterate) 2 | 3 | add_library(${PROJECT_NAME} GenerateIterate.cpp GenerateIterate.h) 4 | -------------------------------------------------------------------------------- /GenerateIterate/GenerateIterate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Parsifal on 2022/5/31. 3 | // 4 | 5 | #ifndef GENETIC_ALGORITHM_GENETICITERATE_H 6 | #define GENETIC_ALGORITHM_GENETICITERATE_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | class General 20 | { 21 | 22 | public: 23 | virtual ~General(){}; 24 | struct GeneVariate 25 | { 26 | std::vector> population; 27 | int child_num; 28 | std::vector> champion; 29 | int fitness_standard; 30 | int fitness_max; 31 | int champaion_num; 32 | GeneVariate(std::vector> vector, int i, std::vector> vector1, int i1, int i2, 33 | int i3) :population(vector), child_num(i),champion(vector1), fitness_standard(i1), fitness_max(i2), champaion_num(i3){}; 34 | }; 35 | 36 | void CalculateFitnessMaxAndFitnessStandard(std::shared_ptr data_muster); 37 | 38 | void CrossingOverPrePare(std::shared_ptr data_muster); 39 | 40 | private: 41 | 42 | std::vector RandomPairing(int &num); 43 | int VariateMasker(std::shared_ptr data_muster,int &pos); 44 | void Variate(std::shared_ptr data_muster,int &pos); 45 | 46 | // void Variation(std::vector &individual, int fitness_standard, int fitness_max); 47 | 48 | int CrossingOverJudge(std::shared_ptr data_muster,int &pos_x,int &pos_y); 49 | 50 | void CrossingOver(std::shared_ptr data_muster,int &pos_x,int &pos_y); 51 | 52 | void RecombinationOfGrne(std::shared_ptr data_muster); 53 | }; 54 | 55 | #endif // GENETIC_ALGORITHM_GENETICITERATE_H 56 | -------------------------------------------------------------------------------- /GenerateIterate/Train.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Parsifal on 2022/8/17. 3 | // 4 | 5 | #ifndef UO_TOOLS_TRAIN_H 6 | #define UO_TOOLS_TRAIN_H 7 | 8 | 9 | 10 | #endif //UO_TOOLS_TRAIN_H 11 | -------------------------------------------------------------------------------- /PlayGame/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(SixPieces) -------------------------------------------------------------------------------- /PlayGame/SixPieces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | project(sixpiece) 3 | 4 | add_library(${PROJECT_NAME} SixInitialize.h SixInitialize.cpp SixPiece.cpp SixPiece.h SixSelfPlay.cpp SixSelfPlay.h) 5 | target_link_libraries(${PROJECT_NAME} easythreadpool GenerateIterate) 6 | 7 | set(test SixPiece_test) 8 | set(test_SOURCE SixPiece_test.cpp ) 9 | add_executable(${test} ${test_SOURCE}) 10 | target_link_libraries(${test} sixpiece ) 11 | 12 | 13 | set(SelfPlay SelfPlay) 14 | set(SelfPlay_SOURCE SixSelfPlay.cpp SixSelfPlay.h ) 15 | add_executable(${SelfPlay} ${SelfPlay_SOURCE}) 16 | target_link_libraries(${SelfPlay} sixpiece ) -------------------------------------------------------------------------------- /PlayGame/SixPieces/SixInitialize.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Parsifal on 2022/10/13. 3 | // 4 | 5 | #ifndef GENETIC_SIXINITIALIZE_H 6 | #define GENETIC_SIXINITIALIZE_H 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | struct Point //������Ľṹ��? 13 | { 14 | int x, y; 15 | }; 16 | 17 | enum class Gene{ 18 | huowu = 0, 19 | mianwu, 20 | huosi,miansi,huosan,miansan, huoer,mianer, 21 | adaptability 22 | }; 23 | 24 | enum class IterateType{ 25 | ForTrain=0, 26 | ForPlay, 27 | HasData 28 | }; 29 | enum class Direction{ 30 | Up,Left,LeftUp,RightUp,OpponentUp,OpponentLeft,OpponentLeftUp,OpponentRightUp 31 | }; 32 | struct DirectionBoardElement{ 33 | int num; 34 | int left_enemy; 35 | int right_enemy; 36 | DirectionBoardElement():left_enemy(-1),right_enemy(-1),num(0){} 37 | }; 38 | struct PieceDirection{ 39 | std::vectordirection_piece_num; 40 | std::vectordirection_piece_type;//活死 41 | 42 | long long int score; 43 | 44 | }; 45 | 46 | struct TrainPiectElement 47 | { 48 | int population_num; 49 | int champaion_num; 50 | int iterate_type; 51 | int convergence_step; 52 | int contest_round; 53 | int match_times; 54 | std::vector> general_checkerboard; 55 | std::vector> population; 56 | std::vector> champion; 57 | 58 | }; 59 | 60 | struct TemporaryData 61 | { 62 | int target_num; 63 | int len; 64 | long long int max_score; 65 | int real_player; 66 | int now_player; 67 | int opponent_player; 68 | std::vector> general_checkerboard; 69 | std::vector> direction_checkerboard; 70 | std::vector gene; 71 | Point real_six; 72 | Point opponent_six; 73 | Point max_pos; 74 | TemporaryData():target_num(6),max_score(0), real_six{-1,-1},opponent_six{-1,-1}, max_pos{-1,-1}{}; 75 | }; 76 | 77 | class InitParameter { 78 | public: 79 | virtual ~InitParameter(){}; 80 | void InitPopulation(shared_ptr board); 81 | void InitPopulationForTrain(std::shared_ptr board); 82 | void InitPopulationForPlay(std::shared_ptr board); 83 | void InitializePieceDirectionSpace(std::shared_ptr tem); 84 | void InitializeDirectionBoard(int &position_x,int &pisition_y,std::shared_ptr tem); 85 | void InitializeDirectionBoardForOpponent(int &position_x,int &pisition_y,std::shared_ptr tem); 86 | void InitializeDirectionBoardOfEnemyNum(int &position_x,int &pisition_y,std::shared_ptr tem); 87 | 88 | 89 | }; 90 | #endif //GENETIC_SIXINITIALIZE_H 91 | -------------------------------------------------------------------------------- /PlayGame/SixPieces/SixPiece.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Parsifal on 2022/6/17. 3 | // 4 | 5 | #ifndef GENETICALGORITHM_SIXPIECE_H 6 | #define GENETICALGORITHM_SIXPIECE_H 7 | 8 | #include 9 | #include 10 | #include "../../GenerateIterate/GenerateIterate.h" 11 | #include "../../EasyThreadPool/easythreadpool.h" 12 | #include "SixInitialize.h" 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | 20 | 21 | class SixPiece :public General,public InitParameter{ 22 | public: 23 | mutex read; 24 | condition_variable wait_read; 25 | void MakeChampion(shared_ptr board); 26 | int PopulationPlayAGame(const int &player_gene_pos1,const int &player_gene_pos2,const std::shared_ptr board) ; 27 | void SignalCommunication(); 28 | void MakePopulationWhenTrain(std::shared_ptr board); 29 | 30 | 31 | // for test 32 | void DisPlayBoard(std::vector> general_checkerboard); 33 | void DisplayScore(std::shared_ptr tem); 34 | 35 | void GetPKQueue(std::vector &pk_queue); 36 | 37 | void CacheTemporaryDate( std::shared_ptr board,std::shared_ptr tem,const int &player_gene_pos); 38 | 39 | void SetRecord(Point &pos,std::shared_ptr tem_player1,std::shared_ptr tem_player2); 40 | virtual ~SixPiece(){}; 41 | //private: 42 | void PopulationContest(std::shared_ptr board); 43 | void SingleContest(const int player1,const int player2,std::shared_ptr board,std::unordered_map &ma); 44 | void UpdateNextRoundQueue(std::vector &pk_queue,std::unordered_map &ma); 45 | void SelectChampion(std::shared_ptr board,std::vector &pk_queue); 46 | 47 | void UpdateQuadrantStatus(std::shared_ptr tem); 48 | void FindMaxAndAddScore(std::shared_ptr tem,int &x,int &y); 49 | void UpdatePieceTypeAndNum(std::shared_ptr tem); 50 | int GetPieceNum(std::shared_ptr tem, int &player,int type,int &x,int &y); 51 | int GetPieceTypeForLeft(std::shared_ptr tem, int &player, int type,const int &x,const int &y); 52 | int GetPieceTypeForRight(std::shared_ptr tem, int &player, int type,const int &x,const int &y); 53 | 54 | long long int GetScore(std::shared_ptr tem,int &x,int &y,int direction); 55 | void CalCulateScoreForNowPlayer(std::shared_ptr tem); 56 | void CalCulateScoreForOppoNentPlayer(std::shared_ptr tem); 57 | 58 | void ShowChampion(std::shared_ptr board); 59 | void GetStepXStepY( int &step_x, int &step_y ,int &type); 60 | 61 | 62 | 63 | }; 64 | 65 | #endif //GENETICALGORITHM_SIXPIECE_H 66 | -------------------------------------------------------------------------------- /PlayGame/SixPieces/SixSelfPlay.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Parsifal on 2022/10/13. 3 | // 4 | 5 | #ifndef GENETIC_SIXSELFPLAY_H 6 | #define GENETIC_SIXSELFPLAY_H 7 | #include "SixPiece.h" 8 | #include "SixInitialize.h" 9 | #include "rapidjson/document.h" 10 | #include "rapidjson/writer.h" 11 | #include "rapidjson/stringbuffer.h" 12 | #include 13 | #include "rapidjson/istreamwrapper.h" 14 | #include "rapidjson/prettywriter.h" 15 | #include "rapidjson/rapidjson.h" 16 | #include "rapidjson/stringbuffer.h" 17 | #include "rapidjson/filewritestream.h" 18 | #include 19 | #include 20 | using namespace rapidjson; 21 | class SelfPlay:public SixPiece 22 | { 23 | public: 24 | ~SelfPlay(){}; 25 | void WriteData(const std::shared_ptr board,string path,int sleep_time); 26 | void writeToJsonFile(string filepath,const std::shared_ptr board); 27 | string readfile(string path); 28 | string MakeIterateData(const std::shared_ptr board); 29 | void ParseIteratrDate(std::shared_ptr board,string &str); 30 | bool IsConfigEmpty(string path); 31 | void ReadData(string filepath,const std::shared_ptr board); 32 | void Train(); 33 | std::shared_ptr MakeTestData(SixPiece &test); 34 | }; 35 | #endif //GENETIC_SIXSELFPLAY_H 36 | -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-cf8e51656c0e2e41cda9.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations" : 3 | [ 4 | { 5 | "directories" : 6 | [ 7 | { 8 | "build" : ".", 9 | "jsonFile" : "directory-.-Debug-d0094a50bb2071803777.json", 10 | "minimumCMakeVersion" : 11 | { 12 | "string" : "3.8" 13 | }, 14 | "projectIndex" : 0, 15 | "source" : ".", 16 | "targetIndexes" : 17 | [ 18 | 0, 19 | 1 20 | ] 21 | } 22 | ], 23 | "name" : "Debug", 24 | "projects" : 25 | [ 26 | { 27 | "directoryIndexes" : 28 | [ 29 | 0 30 | ], 31 | "name" : "sixpiece", 32 | "targetIndexes" : 33 | [ 34 | 0, 35 | 1 36 | ] 37 | } 38 | ], 39 | "targets" : 40 | [ 41 | { 42 | "directoryIndex" : 0, 43 | "id" : "SixPiece_test::@6890427a1f51a3e7e1df", 44 | "jsonFile" : "target-SixPiece_test-Debug-7d473c6aa20fa7783f12.json", 45 | "name" : "SixPiece_test", 46 | "projectIndex" : 0 47 | }, 48 | { 49 | "directoryIndex" : 0, 50 | "id" : "sixpiece::@6890427a1f51a3e7e1df", 51 | "jsonFile" : "target-sixpiece-Debug-123a42f7795bc0f226b8.json", 52 | "name" : "sixpiece", 53 | "projectIndex" : 0 54 | } 55 | ] 56 | } 57 | ], 58 | "kind" : "codemodel", 59 | "paths" : 60 | { 61 | "build" : "D:/study/github/genetic_algorithm/PlayGame/SixPieces/cmake-build-debug", 62 | "source" : "D:/study/github/genetic_algorithm/PlayGame/SixPieces" 63 | }, 64 | "version" : 65 | { 66 | "major" : 2, 67 | "minor" : 3 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/.cmake/api/v1/reply/index-2022-10-13T07-26-19-0490.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmake" : 3 | { 4 | "generator" : 5 | { 6 | "multiConfig" : false, 7 | "name" : "Ninja" 8 | }, 9 | "paths" : 10 | { 11 | "cmake" : "D:/CLion 2021.3.3/bin/cmake/win/bin/cmake.exe", 12 | "cpack" : "D:/CLion 2021.3.3/bin/cmake/win/bin/cpack.exe", 13 | "ctest" : "D:/CLion 2021.3.3/bin/cmake/win/bin/ctest.exe", 14 | "root" : "D:/CLion 2021.3.3/bin/cmake/win/share/cmake-3.21" 15 | }, 16 | "version" : 17 | { 18 | "isDirty" : false, 19 | "major" : 3, 20 | "minor" : 21, 21 | "patch" : 1, 22 | "string" : "3.21.1", 23 | "suffix" : "" 24 | } 25 | }, 26 | "objects" : 27 | [ 28 | { 29 | "jsonFile" : "codemodel-v2-cf8e51656c0e2e41cda9.json", 30 | "kind" : "codemodel", 31 | "version" : 32 | { 33 | "major" : 2, 34 | "minor" : 3 35 | } 36 | }, 37 | { 38 | "jsonFile" : "cache-v2-473f2e429cdc1f16c897.json", 39 | "kind" : "cache", 40 | "version" : 41 | { 42 | "major" : 2, 43 | "minor" : 0 44 | } 45 | }, 46 | { 47 | "jsonFile" : "cmakeFiles-v1-29965649996fd1b329d5.json", 48 | "kind" : "cmakeFiles", 49 | "version" : 50 | { 51 | "major" : 1, 52 | "minor" : 0 53 | } 54 | }, 55 | { 56 | "jsonFile" : "toolchains-v1-7273fd4b82e70c0071cf.json", 57 | "kind" : "toolchains", 58 | "version" : 59 | { 60 | "major" : 1, 61 | "minor" : 0 62 | } 63 | } 64 | ], 65 | "reply" : 66 | { 67 | "cache-v2" : 68 | { 69 | "jsonFile" : "cache-v2-473f2e429cdc1f16c897.json", 70 | "kind" : "cache", 71 | "version" : 72 | { 73 | "major" : 2, 74 | "minor" : 0 75 | } 76 | }, 77 | "cmakeFiles-v1" : 78 | { 79 | "jsonFile" : "cmakeFiles-v1-29965649996fd1b329d5.json", 80 | "kind" : "cmakeFiles", 81 | "version" : 82 | { 83 | "major" : 1, 84 | "minor" : 0 85 | } 86 | }, 87 | "codemodel-v2" : 88 | { 89 | "jsonFile" : "codemodel-v2-cf8e51656c0e2e41cda9.json", 90 | "kind" : "codemodel", 91 | "version" : 92 | { 93 | "major" : 2, 94 | "minor" : 3 95 | } 96 | }, 97 | "toolchains-v1" : 98 | { 99 | "jsonFile" : "toolchains-v1-7273fd4b82e70c0071cf.json", 100 | "kind" : "toolchains", 101 | "version" : 102 | { 103 | "major" : 1, 104 | "minor" : 0 105 | } 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/.cmake/api/v1/reply/target-SixPiece_test-Debug-7d473c6aa20fa7783f12.json: -------------------------------------------------------------------------------- 1 | { 2 | "artifacts" : 3 | [ 4 | { 5 | "path" : "SixPiece_test.exe" 6 | }, 7 | { 8 | "path" : "SixPiece_test.pdb" 9 | } 10 | ], 11 | "backtrace" : 1, 12 | "backtraceGraph" : 13 | { 14 | "commands" : 15 | [ 16 | "add_executable", 17 | "target_link_libraries" 18 | ], 19 | "files" : 20 | [ 21 | "CMakeLists.txt" 22 | ], 23 | "nodes" : 24 | [ 25 | { 26 | "file" : 0 27 | }, 28 | { 29 | "command" : 0, 30 | "file" : 0, 31 | "line" : 9, 32 | "parent" : 0 33 | }, 34 | { 35 | "command" : 1, 36 | "file" : 0, 37 | "line" : 10, 38 | "parent" : 0 39 | } 40 | ] 41 | }, 42 | "compileGroups" : 43 | [ 44 | { 45 | "compileCommandFragments" : 46 | [ 47 | { 48 | "fragment" : "-g" 49 | } 50 | ], 51 | "language" : "CXX", 52 | "sourceIndexes" : 53 | [ 54 | 0 55 | ] 56 | } 57 | ], 58 | "dependencies" : 59 | [ 60 | { 61 | "backtrace" : 2, 62 | "id" : "sixpiece::@6890427a1f51a3e7e1df" 63 | } 64 | ], 65 | "id" : "SixPiece_test::@6890427a1f51a3e7e1df", 66 | "link" : 67 | { 68 | "commandFragments" : 69 | [ 70 | { 71 | "fragment" : "-g", 72 | "role" : "flags" 73 | }, 74 | { 75 | "fragment" : "", 76 | "role" : "flags" 77 | }, 78 | { 79 | "backtrace" : 2, 80 | "fragment" : "libsixpiece.a", 81 | "role" : "libraries" 82 | }, 83 | { 84 | "fragment" : "-leasythreadpool", 85 | "role" : "libraries" 86 | }, 87 | { 88 | "fragment" : "-lGenerateIterate", 89 | "role" : "libraries" 90 | }, 91 | { 92 | "fragment" : "-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32", 93 | "role" : "libraries" 94 | } 95 | ], 96 | "language" : "CXX" 97 | }, 98 | "name" : "SixPiece_test", 99 | "nameOnDisk" : "SixPiece_test.exe", 100 | "paths" : 101 | { 102 | "build" : ".", 103 | "source" : "." 104 | }, 105 | "sourceGroups" : 106 | [ 107 | { 108 | "name" : "Source Files", 109 | "sourceIndexes" : 110 | [ 111 | 0 112 | ] 113 | } 114 | ], 115 | "sources" : 116 | [ 117 | { 118 | "backtrace" : 1, 119 | "compileGroupIndex" : 0, 120 | "path" : "SixPiece_test.cpp", 121 | "sourceGroupIndex" : 0 122 | } 123 | ], 124 | "type" : "EXECUTABLE" 125 | } 126 | -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/.ninja_deps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paxifaer/genetic_algorithm/HEAD/PlayGame/SixPieces/cmake-build-debug/.ninja_deps -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/.ninja_log: -------------------------------------------------------------------------------- 1 | # ninja log v5 2 | 0 2639 6873479949202081 CMakeFiles/sixpiece.dir/SixInitialize.cpp.obj c3796d8e34274bb 3 | 937 2655 6873479949368197 CMakeFiles/SixPiece_test.dir/SixInitialize.cpp.obj 82d935dde6b2dc01 4 | 342 4804 6873479970833340 CMakeFiles/SixPiece_test.dir/SixPiece_test.cpp.obj e73a0bd85a1f2aab 5 | 319 5117 6873479973965733 CMakeFiles/sixpiece.dir/SixPiece.cpp.obj 72566cb5d2e2e41 6 | 628 5183 6873479974170933 CMakeFiles/SixPiece_test.dir/SixPiece.cpp.obj 4e288dde61cddad9 7 | 5117 5886 6873479978549567 libsixpiece.a 5dbdf113c8d80db5 8 | -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/CMakeFiles/SixPiece_test.dir/SixInitialize.cpp.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paxifaer/genetic_algorithm/HEAD/PlayGame/SixPieces/cmake-build-debug/CMakeFiles/SixPiece_test.dir/SixInitialize.cpp.obj -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/CMakeFiles/SixPiece_test.dir/SixPiece.cpp.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paxifaer/genetic_algorithm/HEAD/PlayGame/SixPieces/cmake-build-debug/CMakeFiles/SixPiece_test.dir/SixPiece.cpp.obj -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/CMakeFiles/SixPiece_test.dir/SixPiece_test.cpp.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paxifaer/genetic_algorithm/HEAD/PlayGame/SixPieces/cmake-build-debug/CMakeFiles/SixPiece_test.dir/SixPiece_test.cpp.obj -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/CMakeFiles/clion-log.txt: -------------------------------------------------------------------------------- 1 | "D:\CLion 2021.3.3\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=D:/CLion 2021.3.3/bin/ninja/win/ninja.exe" -G Ninja D:\study\github\genetic_algorithm\PlayGame\SixPieces 2 | -- Configuring done 3 | -- Generating done 4 | -- Build files have been written to: D:/study/github/genetic_algorithm/PlayGame/SixPieces/cmake-build-debug 5 | -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/CMakeFiles/sixpiece.dir/SixInitialize.cpp.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paxifaer/genetic_algorithm/HEAD/PlayGame/SixPieces/cmake-build-debug/CMakeFiles/sixpiece.dir/SixInitialize.cpp.obj -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/CMakeFiles/sixpiece.dir/SixPiece.cpp.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paxifaer/genetic_algorithm/HEAD/PlayGame/SixPieces/cmake-build-debug/CMakeFiles/sixpiece.dir/SixPiece.cpp.obj -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/Testing/Temporary/LastTest.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paxifaer/genetic_algorithm/HEAD/PlayGame/SixPieces/cmake-build-debug/Testing/Temporary/LastTest.log -------------------------------------------------------------------------------- /PlayGame/SixPieces/cmake-build-debug/libsixpiece.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paxifaer/genetic_algorithm/HEAD/PlayGame/SixPieces/cmake-build-debug/libsixpiece.a -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # genetic_algorithm 2 | 3 | 该项目属于棋类游戏算法设计类型: 4 | 算法采用遗传算法 5 | origin分支采用c语言编写,Generic分支采用C++语法编写,两种方式均可header-only。 6 | orign分支目前种群个数仅有64个,无多线程加速,运行较慢,且不再更新。 7 | Generic版本目前使用了一些指针和多线程加速。速度上有了显著的提升,可在较短时间内。同时训练1024个种群. 8 | 为提升种群数量,采用了self_play机制,简单来说就是预训练。将训练机制与实际对战时分开。兼顾了算法精度与速度 9 | 10 | 11 | 有兴趣的小伙伴欢迎+q私聊:807128216 12 | -------------------------------------------------------------------------------- /cmake-build-debug/EasyThreadPool/cmake_install.cmake: -------------------------------------------------------------------------------- 1 | # Install script for directory: D:/study/github/genetic_algorithm/EasyThreadPool 2 | 3 | # Set the install prefix 4 | if(NOT DEFINED CMAKE_INSTALL_PREFIX) 5 | set(CMAKE_INSTALL_PREFIX "C:/Program Files (x86)/Genetic") 6 | endif() 7 | string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") 8 | 9 | # Set the install configuration name. 10 | if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) 11 | if(BUILD_TYPE) 12 | string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" 13 | CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") 14 | else() 15 | set(CMAKE_INSTALL_CONFIG_NAME "Debug") 16 | endif() 17 | message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") 18 | endif() 19 | 20 | # Set the component getting installed. 21 | if(NOT CMAKE_INSTALL_COMPONENT) 22 | if(COMPONENT) 23 | message(STATUS "Install component: \"${COMPONENT}\"") 24 | set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") 25 | else() 26 | set(CMAKE_INSTALL_COMPONENT) 27 | endif() 28 | endif() 29 | 30 | # Is this installation the result of a crosscompile? 31 | if(NOT DEFINED CMAKE_CROSSCOMPILING) 32 | set(CMAKE_CROSSCOMPILING "FALSE") 33 | endif() 34 | 35 | # Set default install directory permissions. 36 | if(NOT DEFINED CMAKE_OBJDUMP) 37 | set(CMAKE_OBJDUMP "D:/environmentpackage/mingw64/bin/llvm-objdump.exe") 38 | endif() 39 | 40 | -------------------------------------------------------------------------------- /conf/TrainData.json: -------------------------------------------------------------------------------- 1 | {"max_time":"0"} -------------------------------------------------------------------------------- /conf/config.json: -------------------------------------------------------------------------------- 1 | {"1":"5"} 2 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | //#include "PlayGame/SixPieces/SixPiece.h" 2 | //#include "spdlog/spdlog.h" 3 | //#include "spdlog/sinks/rotating_file_sink.h" 4 | //#include "spdlog/async.h" 5 | // 6 | //#define SPDLOG_FILENAME "log/SixPiece.log" 7 | //#define SPDLOGGERNAME "SixPiece" 8 | //#define LOGGER spdlog::get(SPDLOGGERNAME) 9 | // 10 | ////void initspdlog() 11 | ////{ 12 | //// spdlog::flush_every(std::chrono::seconds(5)); 13 | //// auto file_logger = spdlog::rotating_logger_mt(SPDLOGGERNAME, SPDLOG_FILENAME, 1024 * 1024 * 200, 5); 14 | //// LOGGER->set_level(spdlog::level::info); // Set global log level to info 15 | //// LOGGER->set_pattern("[%Y-%m-%d %H:%M:%S.%e %^%L%$ %t] %v"); 16 | ////} 17 | // 18 | //int main() 19 | //{ 20 | //// SixPiece a; 21 | //// a.SignalCommunication(); 22 | // 23 | // 24 | // 25 | // return 0; 26 | //} 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | #include 36 | #include "rapidjson/document.h" 37 | #include "rapidjson/istreamwrapper.h" 38 | #include "rapidjson/prettywriter.h" 39 | #include "rapidjson/rapidjson.h" 40 | #include "rapidjson/stringbuffer.h" 41 | #include "rapidjson/writer.h" 42 | #include "rapidjson/filewritestream.h" 43 | #include 44 | using namespace std; 45 | using namespace rapidjson; 46 | 47 | Document readJsonfile(string path) 48 | { 49 | 50 | rapidjson::Document doc; 51 | std::ifstream in(path, std::ios::binary); 52 | 53 | if (!in.is_open()) 54 | { cout<< "file is not open!!"; 55 | return doc; 56 | } 57 | 58 | 59 | IStreamWrapper config(in); 60 | doc.ParseStream(config); 61 | 62 | // StringBuffer buffer; 63 | // Writer writer(buffer); 64 | // doc.Accept(writer); 65 | 66 | in.close(); 67 | return doc; 68 | } 69 | 70 | string readfile(string path){ 71 | ifstream readFile; 72 | 73 | readFile.open(path); //打开需要操作的文件 74 | 75 | if (readFile.fail()) 76 | { 77 | cout<<"fail"; 78 | return path; //说明文件读取失败! 79 | } 80 | 81 | std::string sBuffer; 82 | 83 | readFile>>sBuffer; 84 | 85 | return sBuffer; 86 | } 87 | 88 | 89 | void writeToJsonFile(string &jsonstr, string filepath) 90 | { 91 | Document doc ; 92 | string str= readfile(filepath.c_str()); 93 | doc.Parse(str.c_str()); 94 | 95 | rapidjson::Document::AllocatorType &allocator = doc.GetAllocator(); 96 | doc.SetObject(); 97 | string time; 98 | doc.AddMember("1", "2", allocator); 99 | 100 | doc["1"] = "5"; 101 | 102 | string fstr; 103 | rapidjson::StringBuffer strBuffer; 104 | rapidjson::Writer writer(strBuffer); 105 | doc.Accept(writer); 106 | fstr = strBuffer.GetString(); 107 | 108 | fstream fout(filepath,ios::out|ios::trunc); 109 | fout< 2 | template 3 | struct PublicAlign32pow2 4 | { 5 | enum 6 | { 7 | first = SIZE | SIZE >> 1, 8 | second = first | first >> 2, 9 | third = second | second >> 4, 10 | value = third | third >> 8 11 | }; 12 | }; 13 | 14 | template 15 | struct CheckSize 16 | { 17 | enum{value = -1}; 18 | }; 19 | 20 | template 21 | struct CheckSize::value < 0x7fffffff)>::type> 22 | { 23 | enum{value = PublicAlign32pow2::value+1}; 24 | }; 25 | 26 | template class Template> 27 | struct is_specialization_of : std::false_type {}; 28 | 29 | template