From 71f0ee98ccc85d41ba7587d122c83011ab1e25c3 Mon Sep 17 00:00:00 2001 From: F1F7Y <64418963+F1F7Y@users.noreply.github.com> Date: Fri, 30 Jun 2023 03:10:24 +0200 Subject: Reorganize third-party dependencies into `thirdparty` directory (#491) * rename `include` to `thirdparty` * remove duplicate minhook in wsock32 * move minhook into its own directory * move openssl lib into separate directories --- thirdparty/spdlog/common.h | 249 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 thirdparty/spdlog/common.h (limited to 'thirdparty/spdlog/common.h') diff --git a/thirdparty/spdlog/common.h b/thirdparty/spdlog/common.h new file mode 100644 index 00000000..fb9a3660 --- /dev/null +++ b/thirdparty/spdlog/common.h @@ -0,0 +1,249 @@ +// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) + +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef SPDLOG_COMPILED_LIB +#undef SPDLOG_HEADER_ONLY +#if defined(_WIN32) && defined(SPDLOG_SHARED_LIB) +#ifdef spdlog_EXPORTS +#define SPDLOG_API __declspec(dllexport) +#else +#define SPDLOG_API __declspec(dllimport) +#endif +#else // !defined(_WIN32) || !defined(SPDLOG_SHARED_LIB) +#define SPDLOG_API +#endif +#define SPDLOG_INLINE +#else // !defined(SPDLOG_COMPILED_LIB) +#define SPDLOG_API +#define SPDLOG_HEADER_ONLY +#define SPDLOG_INLINE inline +#endif // #ifdef SPDLOG_COMPILED_LIB + +#include + +// visual studio upto 2013 does not support noexcept nor constexpr +#if defined(_MSC_VER) && (_MSC_VER < 1900) +#define SPDLOG_NOEXCEPT _NOEXCEPT +#define SPDLOG_CONSTEXPR +#else +#define SPDLOG_NOEXCEPT noexcept +#define SPDLOG_CONSTEXPR constexpr +#endif + +#if defined(__GNUC__) || defined(__clang__) +#define SPDLOG_DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) +#define SPDLOG_DEPRECATED __declspec(deprecated) +#else +#define SPDLOG_DEPRECATED +#endif + +// disable thread local on msvc 2013 +#ifndef SPDLOG_NO_TLS +#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__cplusplus_winrt) +#define SPDLOG_NO_TLS 1 +#endif +#endif + +#ifndef SPDLOG_FUNCTION +#define SPDLOG_FUNCTION static_cast(__FUNCTION__) +#endif + +#ifdef SPDLOG_NO_EXCEPTIONS +#define SPDLOG_TRY +#define SPDLOG_THROW(ex) \ + do \ + { \ + printf("spdlog fatal error: %s\n", ex.what()); \ + std::abort(); \ + } while (0) +#define SPDLOG_CATCH_ALL() +#else +#define SPDLOG_TRY try +#define SPDLOG_THROW(ex) throw(ex) +#define SPDLOG_CATCH_ALL() catch (...) +#endif + +namespace spdlog { + +class formatter; + +namespace sinks { +class sink; +} + +#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) +using filename_t = std::wstring; +// allow macro expansion to occur in SPDLOG_FILENAME_T +#define SPDLOG_FILENAME_T_INNER(s) L##s +#define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s) +#else +using filename_t = std::string; +#define SPDLOG_FILENAME_T(s) s +#endif + +using log_clock = std::chrono::system_clock; +using sink_ptr = std::shared_ptr; +using sinks_init_list = std::initializer_list; +using err_handler = std::function; +using string_view_t = fmt::basic_string_view; +using wstring_view_t = fmt::basic_string_view; +using memory_buf_t = fmt::basic_memory_buffer; +using wmemory_buf_t = fmt::basic_memory_buffer; + +#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT +#ifndef _WIN32 +#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows +#else +template +struct is_convertible_to_wstring_view : std::is_convertible +{}; +#endif // _WIN32 +#else +template +struct is_convertible_to_wstring_view : std::false_type +{}; +#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT + +#if defined(SPDLOG_NO_ATOMIC_LEVELS) +using level_t = details::null_atomic_int; +#else +using level_t = std::atomic; +#endif + +#define SPDLOG_LEVEL_TRACE 0 +#define SPDLOG_LEVEL_DEBUG 1 +#define SPDLOG_LEVEL_INFO 2 +#define SPDLOG_LEVEL_WARN 3 +#define SPDLOG_LEVEL_ERROR 4 +#define SPDLOG_LEVEL_CRITICAL 5 +#define SPDLOG_LEVEL_OFF 6 + +#if !defined(SPDLOG_ACTIVE_LEVEL) +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO +#endif + +// Log level enum +namespace level { +enum level_enum +{ + trace = SPDLOG_LEVEL_TRACE, + debug = SPDLOG_LEVEL_DEBUG, + info = SPDLOG_LEVEL_INFO, + warn = SPDLOG_LEVEL_WARN, + err = SPDLOG_LEVEL_ERROR, + critical = SPDLOG_LEVEL_CRITICAL, + off = SPDLOG_LEVEL_OFF, + n_levels +}; + +#if !defined(SPDLOG_LEVEL_NAMES) +#define SPDLOG_LEVEL_NAMES \ + { \ + "trace", "debug", "info", "warning", "error", "critical", "off" \ + } +#endif + +#if !defined(SPDLOG_SHORT_LEVEL_NAMES) + +#define SPDLOG_SHORT_LEVEL_NAMES \ + { \ + "T", "D", "I", "W", "E", "C", "O" \ + } +#endif + +SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; +SPDLOG_API void set_string_view(spdlog::level::level_enum l, const string_view_t &s) SPDLOG_NOEXCEPT; +SPDLOG_API const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; +SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT; + +} // namespace level + +// +// Color mode used by sinks with color support. +// +enum class color_mode +{ + always, + automatic, + never +}; + +// +// Pattern time - specific time getting to use for pattern_formatter. +// local time by default +// +enum class pattern_time_type +{ + local, // log localtime + utc // log utc +}; + +// +// Log exception +// +class SPDLOG_API spdlog_ex : public std::exception +{ +public: + explicit spdlog_ex(std::string msg); + spdlog_ex(const std::string &msg, int last_errno); + const char *what() const SPDLOG_NOEXCEPT override; + +private: + std::string msg_; +}; + +[[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno); +[[noreturn]] SPDLOG_API void throw_spdlog_ex(std::string msg); + +struct source_loc +{ + SPDLOG_CONSTEXPR source_loc() = default; + SPDLOG_CONSTEXPR source_loc(const char *filename_in, int line_in, const char *funcname_in) + : filename{filename_in} + , line{line_in} + , funcname{funcname_in} + {} + + SPDLOG_CONSTEXPR bool empty() const SPDLOG_NOEXCEPT + { + return line == 0; + } + const char *filename{nullptr}; + int line{0}; + const char *funcname{nullptr}; +}; + +namespace details { +// make_unique support for pre c++14 + +#if __cplusplus >= 201402L // C++14 and beyond +using std::make_unique; +#else +template +std::unique_ptr make_unique(Args &&...args) +{ + static_assert(!std::is_array::value, "arrays not supported"); + return std::unique_ptr(new T(std::forward(args)...)); +} +#endif +} // namespace details +} // namespace spdlog + +#ifdef SPDLOG_HEADER_ONLY +#include "common-inl.h" +#endif -- cgit v1.2.3