From ad624432d85936facc410eed108e4106a3174d6a Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Sun, 25 Feb 2018 01:40:46 +0100 Subject: [PATCH] google-explicit-constructor --- include/spdlog/common.h | 6 +++--- include/spdlog/details/async_log_helper.h | 4 ++-- include/spdlog/details/mpmc_bounded_q.h | 11 +++++------ include/spdlog/details/null_mutex.h | 2 +- include/spdlog/details/registry.h | 9 +++++---- include/spdlog/logger.h | 2 +- include/spdlog/sinks/ansicolor_sink.h | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index c5ecc73a..3a691b34 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -106,7 +106,6 @@ using level_hasher = std::hash; } //level - // // Async overflow policy - block by default. // @@ -139,12 +138,14 @@ std::string errno_str(int err_num); class spdlog_ex : public std::exception { public: - spdlog_ex(const std::string& msg):_msg(msg) + explicit spdlog_ex(std::string msg) : _msg(std::move(msg)) {} + spdlog_ex(const std::string& msg, int last_errno) { _msg = msg + ": " + details::os::errno_str(last_errno); } + const char* what() const SPDLOG_NOEXCEPT override { return _msg.c_str(); @@ -163,5 +164,4 @@ using filename_t = std::wstring; using filename_t = std::string; #endif - } //spdlog diff --git a/include/spdlog/details/async_log_helper.h b/include/spdlog/details/async_log_helper.h index 2439df5f..ece3eb51 100644 --- a/include/spdlog/details/async_log_helper.h +++ b/include/spdlog/details/async_log_helper.h @@ -67,7 +67,7 @@ async_msg(async_msg&& other) SPDLOG_NOEXCEPT: msg_id(other.msg_id) {} - async_msg(async_msg_type m_type): + explicit async_msg(async_msg_type m_type): level(level::info), thread_id(0), msg_type(m_type), @@ -91,7 +91,7 @@ async_msg(async_msg&& other) SPDLOG_NOEXCEPT: async_msg& operator=(const async_msg& other) = delete; // construct from log_msg - async_msg(const details::log_msg& m): + explicit async_msg(const details::log_msg& m): level(m.level), time(m.time), thread_id(m.thread_id), diff --git a/include/spdlog/details/mpmc_bounded_q.h b/include/spdlog/details/mpmc_bounded_q.h index 887f530f..6187f3b9 100644 --- a/include/spdlog/details/mpmc_bounded_q.h +++ b/include/spdlog/details/mpmc_bounded_q.h @@ -53,13 +53,13 @@ namespace spdlog namespace details { -template +template class mpmc_bounded_queue { public: - using item_type = T; - mpmc_bounded_queue(size_t buffer_size) + + explicit mpmc_bounded_queue(size_t buffer_size) :max_size_(buffer_size), buffer_(new cell_t[buffer_size]), buffer_mask_(buffer_size - 1) @@ -79,6 +79,8 @@ public: delete[] buffer_; } + mpmc_bounded_queue(mpmc_bounded_queue const&) = delete; + void operator=(mpmc_bounded_queue const&) = delete; bool enqueue(T&& data) { @@ -167,9 +169,6 @@ private: cacheline_pad_t pad2_; std::atomic dequeue_pos_; cacheline_pad_t pad3_; - - mpmc_bounded_queue(mpmc_bounded_queue const&) = delete; - void operator= (mpmc_bounded_queue const&) = delete; }; } // ns details diff --git a/include/spdlog/details/null_mutex.h b/include/spdlog/details/null_mutex.h index 67b0aeee..82b0ed84 100644 --- a/include/spdlog/details/null_mutex.h +++ b/include/spdlog/details/null_mutex.h @@ -27,7 +27,7 @@ struct null_atomic_int int value; null_atomic_int() = default; - null_atomic_int(int val):value(val) + explicit null_atomic_int(int val) : value(val) {} int load(std::memory_order) const diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 3c134601..07881ae0 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -26,9 +26,12 @@ namespace spdlog { namespace details { -template class registry_t +template +class registry_t { public: + registry_t(const registry_t&) = delete; + registry_t& operator=(const registry_t&) = delete; void register_logger(std::shared_ptr logger) { @@ -38,7 +41,6 @@ public: _loggers[logger_name] = logger; } - std::shared_ptr get(const std::string& logger_name) { std::lock_guard lock(_mutex); @@ -111,6 +113,7 @@ public: std::lock_guard lock(_mutex); _loggers.clear(); } + std::shared_ptr create(const std::string& logger_name, sinks_init_list sinks) { return create(logger_name, sinks.begin(), sinks.end()); @@ -195,8 +198,6 @@ public: private: registry_t() = default; - registry_t(const registry_t&) = delete; - registry_t& operator=(const registry_t&) = delete; void throw_if_exists(const std::string &logger_name) { diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 742f667f..3e27a95e 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -25,7 +25,7 @@ namespace spdlog class logger { public: - logger(const std::string& logger_name, sink_ptr single_sink); + logger(const std::string& name, sink_ptr single_sink); logger(const std::string& name, sinks_init_list); template logger(const std::string& name, const It& begin, const It& end); diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 1b70c735..4bd884cc 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -26,7 +26,7 @@ template class ansicolor_sink : public base_sink { public: - ansicolor_sink(FILE* file): target_file_(file) + explicit ansicolor_sink(FILE* file) : target_file_(file) { should_do_colors_ = details::os::in_terminal(file) && details::os::is_color_terminal(); colors_[level::trace] = cyan;