From 57868277db0de8c7600aa30b8f56c9f22c9cd0f4 Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 1 Oct 2023 18:01:02 +0300 Subject: [PATCH] clang format --- CMakeLists.txt | 17 +++++++++++------ bench/CMakeLists.txt | 4 ++-- example/CMakeLists.txt | 7 ++----- include/spdlog/sinks/wincolor_sink.h | 8 ++++---- src/sinks/wincolor_sink.cpp | 17 ++++++++--------- src/spdlog.cpp | 3 +-- tests/CMakeLists.txt | 5 +++-- 7 files changed, 31 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f275a57..ea7098ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,10 +147,16 @@ message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) # --------------------------------------------------------------------------------------- # Static/Shared library # --------------------------------------------------------------------------------------- -file(GLOB SPDLOG_HEADERS "include/spdlog/*.h" "include/spdlog/sinks/*.h" "include/spdlog/details/*.h" "include/spdlog/fmt/*.h" "include/spdlog/cfg/*.h" ) +file( + GLOB + SPDLOG_HEADERS + "include/spdlog/*.h" + "include/spdlog/sinks/*.h" + "include/spdlog/details/*.h" + "include/spdlog/fmt/*.h" + "include/spdlog/cfg/*.h") file(GLOB SPDLOG_SRCS "src/*.cpp" "src/details/*.cpp" "src/sinks/*.cpp" "src/cfg/*.cpp") - # add {fmt} lib sources is not using external fmt if(NOT SPDLOG_USE_STD_FORMAT AND NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO) file(GLOB BUNDLED_FMT_HEADERS "include/spdlog/fmt/bundled/*.h") @@ -158,7 +164,6 @@ if(NOT SPDLOG_USE_STD_FORMAT AND NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTE list(APPEND SPDLOG_SRCS src/fmt/bundled_fmtlib_format.cpp) endif() - if(SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS) if(WIN32) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY) @@ -195,9 +200,9 @@ set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX d) # set source groups for visual studio if(CMAKE_GENERATOR MATCHES "Visual Studio") - list(REMOVE_ITEM SPDLOG_SRCS "${CMAKE_CURRENT_BINARY_DIR}/version.rc") - source_group(TREE ${CMAKE_SOURCE_DIR}/include PREFIX include FILES ${SPDLOG_HEADERS}) - source_group(TREE ${CMAKE_SOURCE_DIR}/src PREFIX sources FILES ${SPDLOG_SRCS}) + list(REMOVE_ITEM SPDLOG_SRCS "${CMAKE_CURRENT_BINARY_DIR}/version.rc") + source_group(TREE ${CMAKE_SOURCE_DIR}/include PREFIX include FILES ${SPDLOG_HEADERS}) + source_group(TREE ${CMAKE_SOURCE_DIR}/src PREFIX sources FILES ${SPDLOG_SRCS}) endif() if(COMMAND target_precompile_headers AND SPDLOG_ENABLE_PCH) diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index d2d1467d..ed8fcc9b 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -36,8 +36,8 @@ target_link_libraries(latency PRIVATE benchmark::benchmark spdlog::spdlog) add_executable(formatter-bench formatter-bench.cpp) target_link_libraries(formatter-bench PRIVATE benchmark::benchmark spdlog::spdlog) - # copy dll to the executable folder for msvc if(MSVC AND (SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS)) - add_custom_command(TARGET latency POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $) + add_custom_command(TARGET latency POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ + $) endif() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index e83311af..88c74952 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -8,14 +8,11 @@ if(NOT TARGET spdlog) find_package(spdlog REQUIRED) endif() - add_executable(example example.cpp) target_link_libraries(example PRIVATE spdlog::spdlog $<$:ws2_32>) - # copy dll to the executable folder for msvc if(MSVC AND (SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS)) - add_custom_command(TARGET example POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different - $ $) + add_custom_command(TARGET example POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ + $) endif() - diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index f04ef5c8..7a151007 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -29,12 +29,12 @@ public: wincolor_sink &operator=(const wincolor_sink &other) = delete; // change the color for the given level - void set_color(level level, std::uint16_t color); + void set_color(level level, std::uint16_t color); void set_color_mode(color_mode mode); -private: - void *out_handle_; - bool should_do_colors_; +private: + void *out_handle_; + bool should_do_colors_; std::array colors_; // set foreground color and return the orig console attributes (for resetting later) diff --git a/src/sinks/wincolor_sink.cpp b/src/sinks/wincolor_sink.cpp index ad6ed78e..322bbab0 100644 --- a/src/sinks/wincolor_sink.cpp +++ b/src/sinks/wincolor_sink.cpp @@ -2,20 +2,22 @@ // Distributed under the MIT License (http://opensource.org/licenses/MIT) #ifdef _WIN32 - // clang-format off +// clang-format off #include "spdlog/details/windows_include.h" #include "spdlog/sinks/wincolor_sink.h" #include "spdlog/common.h" #include // clang-format on -#include -#include + #include + + #include namespace spdlog { namespace sinks { template -wincolor_sink::wincolor_sink(void *out_handle, color_mode mode) : out_handle_(out_handle) { +wincolor_sink::wincolor_sink(void *out_handle, color_mode mode) + : out_handle_(out_handle) { set_color_mode_impl(mode); // set level colors colors_.at(level_to_number(level::trace)) = @@ -48,7 +50,7 @@ void wincolor_sink::sink_it_(const details::log_msg &msg) { if (out_handle_ == nullptr || out_handle_ == INVALID_HANDLE_VALUE) { return; } - + msg.color_range_start = 0; msg.color_range_end = 0; memory_buf_t formatted; @@ -74,7 +76,6 @@ void wincolor_sink::flush_() { // windows console always flushed? } - template void wincolor_sink::set_color_mode(color_mode mode) { std::lock_guard lock(base_sink::mutex_); @@ -112,9 +113,7 @@ std::uint16_t wincolor_sink::set_foreground_color_(std::uint16_t attribs) // print a range of formatted message to console template -void wincolor_sink::print_range_(const memory_buf_t &formatted, - size_t start, - size_t end) { +void wincolor_sink::print_range_(const memory_buf_t &formatted, size_t start, size_t end) { if (end > start) { auto size = static_cast(end - start); auto ignored = ::WriteConsoleA(static_cast(out_handle_), formatted.data() + start, diff --git a/src/spdlog.cpp b/src/spdlog.cpp index 51e21ff2..8282ea32 100644 --- a/src/spdlog.cpp +++ b/src/spdlog.cpp @@ -25,8 +25,7 @@ void set_formatter(std::unique_ptr formatter) { } void set_pattern(std::string pattern, pattern_time_type time_type) { - set_formatter( - std::make_unique(std::move(pattern), time_type)); + set_formatter(std::make_unique(std::move(pattern), time_type)); } level get_level() { return default_logger_raw()->log_level(); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 780aedf1..0a5688ae 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -87,8 +87,9 @@ if(SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_ALL) # copy dll to the executable folder for msvc if(MSVC AND (SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS)) - add_custom_command(TARGET spdlog-utests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different - $ $) + add_custom_command( + TARGET spdlog-utests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ + $) endif() endif()