clang format and SPLDOG_HEADER_ONLY macro

This commit is contained in:
gabime
2019-05-12 00:22:39 +03:00
parent 540f865355
commit 6bcb422c80
37 changed files with 227 additions and 249 deletions

View File

@@ -17,8 +17,7 @@ public:
explicit circular_q(size_t max_items)
: max_items_(max_items + 1) // one item is reserved as marker for full q
, v_(max_items_)
{
}
{}
// push back, overrun (oldest) item if no room left
void push_back(T &&item)

View File

@@ -3,7 +3,6 @@
#pragma once
#include "spdlog/details/null_mutex.h"
#include <cstdio>
#include <mutex>

View File

@@ -14,6 +14,7 @@
namespace spdlog {
namespace details {
SPDLOG_INLINE file_helper::~file_helper()
{
close();

View File

@@ -55,6 +55,6 @@ private:
} // namespace details
} // namespace spdlog
#ifndef SPDLOG_STATIC_LIB
#ifdef SPDLOG_HEADER_ONLY
#include "file_helper-inl.h"
#endif

View File

@@ -6,7 +6,10 @@
#include "spdlog/details/os.h"
#include "spdlog/sinks/sink.h"
SPDLOG_INLINE spdlog::details::log_msg::log_msg(
namespace spdlog {
namespace details {
SPDLOG_INLINE log_msg::log_msg(
spdlog::source_loc loc, const std::string *loggers_name, spdlog::level::level_enum lvl, spdlog::string_view_t view)
: logger_name(loggers_name)
, level(lvl)
@@ -19,10 +22,11 @@ SPDLOG_INLINE spdlog::details::log_msg::log_msg(
#endif
, source(loc)
, payload(view)
{
}
{}
SPDLOG_INLINE spdlog::details::log_msg::log_msg(const std::string *loggers_name, spdlog::level::level_enum lvl, spdlog::string_view_t view)
SPDLOG_INLINE log_msg::log_msg(const std::string *loggers_name, spdlog::level::level_enum lvl, spdlog::string_view_t view)
: log_msg(source_loc{}, loggers_name, lvl, view)
{
}
{}
} // namespace details
} // namespace spdlog

View File

@@ -11,7 +11,6 @@ namespace details {
struct log_msg
{
log_msg(source_loc loc, const std::string *loggers_name, level::level_enum lvl, string_view_t view);
log_msg(const std::string *loggers_name, level::level_enum lvl, string_view_t view);
log_msg(const log_msg &other) = default;
@@ -31,6 +30,6 @@ struct log_msg
} // namespace details
} // namespace spdlog
#ifndef SPDLOG_STATIC_LIB
#ifdef SPDLOG_HEADER_ONLY
#include "log_msg-inl.h"
#endif

View File

@@ -25,8 +25,7 @@ public:
using item_type = T;
explicit mpmc_blocking_queue(size_t max_items)
: q_(max_items)
{
}
{}
#ifndef __MINGW32__
// try to enqueue and block if no room left

View File

@@ -25,8 +25,7 @@ struct null_atomic_int
explicit null_atomic_int(int val)
: value(val)
{
}
{}
int load(std::memory_order) const
{

View File

@@ -88,6 +88,6 @@ void wbuf_to_utf8buf(const fmt::wmemory_buffer &wbuf, fmt::memory_buffer &target
} // namespace details
} // namespace spdlog
#ifndef SPDLOG_STATIC_LIB
#ifdef SPDLOG_HEADER_ONLY
#include "os-inl.h"
#endif

View File

@@ -58,8 +58,7 @@ public:
scoped_pad(spdlog::string_view_t txt, padding_info &padinfo, fmt::memory_buffer &dest)
: scoped_pad(txt.size(), padinfo, dest)
{
}
{}
~scoped_pad()
{
@@ -90,8 +89,7 @@ class name_formatter : public flag_formatter
public:
explicit name_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
{
@@ -113,8 +111,7 @@ class level_formatter : public flag_formatter
public:
explicit level_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
{
@@ -137,8 +134,7 @@ class short_level_formatter : public flag_formatter
public:
explicit short_level_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
{
@@ -169,8 +165,7 @@ class a_formatter : public flag_formatter
public:
explicit a_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{
@@ -187,8 +182,7 @@ class A_formatter : public flag_formatter
public:
explicit A_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{
@@ -205,8 +199,7 @@ class b_formatter : public flag_formatter
public:
explicit b_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{
@@ -224,8 +217,7 @@ class B_formatter : public flag_formatter
public:
explicit B_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{
@@ -241,8 +233,7 @@ class c_formatter final : public flag_formatter
public:
explicit c_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{
@@ -273,8 +264,7 @@ class C_formatter final : public flag_formatter
public:
explicit C_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{
@@ -290,8 +280,7 @@ class D_formatter final : public flag_formatter
public:
explicit D_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{
@@ -327,8 +316,7 @@ class m_formatter final : public flag_formatter
public:
explicit m_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{
@@ -344,8 +332,7 @@ class d_formatter final : public flag_formatter
public:
explicit d_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{
@@ -361,8 +348,7 @@ class H_formatter final : public flag_formatter
public:
explicit H_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{
@@ -707,8 +693,7 @@ class ch_formatter final : public flag_formatter
public:
explicit ch_formatter(char ch)
: ch_(ch)
{
}
{}
void format(const details::log_msg &, const std::tm &, fmt::memory_buffer &dest) override
{
@@ -746,8 +731,7 @@ class color_start_formatter final : public flag_formatter
public:
explicit color_start_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
{
@@ -759,8 +743,7 @@ class color_stop_formatter final : public flag_formatter
public:
explicit color_stop_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
{
@@ -864,8 +847,7 @@ class full_formatter final : public flag_formatter
public:
explicit full_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{
}
{}
void format(const details::log_msg &msg, const std::tm &tm_time, fmt::memory_buffer &dest) override
{

View File

@@ -6,7 +6,6 @@
#include "spdlog/common.h"
#include "spdlog/details/log_msg.h"
#include "spdlog/details/os.h"
#include "spdlog/fmt/fmt.h"
#include "spdlog/formatter.h"
#include <chrono>
@@ -33,8 +32,7 @@ struct padding_info
padding_info(size_t width, padding_info::pad_side side)
: width_(width)
, side_(side)
{
}
{}
bool enabled() const
{
@@ -49,8 +47,7 @@ class flag_formatter
public:
explicit flag_formatter(padding_info padinfo)
: padinfo_(padinfo)
{
}
{}
flag_formatter() = default;
virtual ~flag_formatter() = default;
virtual void format(const details::log_msg &msg, const std::tm &tm_time, fmt::memory_buffer &dest) = 0;
@@ -83,8 +80,8 @@ private:
std::tm cached_tm_;
std::chrono::seconds last_log_secs_;
std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
std::tm get_time_(const details::log_msg &msg);
std::tm get_time_(const details::log_msg &msg);
void handle_flag_(char flag, details::padding_info padding);
// Extract given pad spec (e.g. %8X)
@@ -96,6 +93,6 @@ private:
};
} // namespace spdlog
#ifndef SPDLOG_STATIC_LIB
#ifdef SPDLOG_HEADER_ONLY
#include "pattern_formatter-inl.h"
#endif

View File

@@ -2,8 +2,9 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once
SPDLOG_INLINE spdlog::details::periodic_worker::periodic_worker(const std::function<void()> &callback_fun, std::chrono::seconds interval)
namespace spdlog {
namespace details {
SPDLOG_INLINE periodic_worker::periodic_worker(const std::function<void()> &callback_fun, std::chrono::seconds interval)
{
active_ = (interval > std::chrono::seconds::zero());
if (!active_)
@@ -25,7 +26,7 @@ SPDLOG_INLINE spdlog::details::periodic_worker::periodic_worker(const std::funct
}
// stop the worker thread and join it
SPDLOG_INLINE spdlog::details::periodic_worker::~periodic_worker()
SPDLOG_INLINE periodic_worker::~periodic_worker()
{
if (worker_thread_.joinable())
{
@@ -37,3 +38,6 @@ SPDLOG_INLINE spdlog::details::periodic_worker::~periodic_worker()
worker_thread_.join();
}
}
} // namespace details
} // namespace spdlog

View File

@@ -35,6 +35,6 @@ private:
} // namespace details
} // namespace spdlog
#ifndef SPDLOG_STATIC_LIB
#ifdef SPDLOG_HEADER_ONLY
#include "periodic_worker-inl.h"
#endif

View File

@@ -99,6 +99,6 @@ private:
} // namespace details
} // namespace spdlog
#ifndef SPDLOG_STATIC_LIB
#ifdef SPDLOG_HEADER_ONLY
#include "registry-inl.h"
#endif

View File

@@ -5,7 +5,9 @@
#include "spdlog/common.h"
SPDLOG_INLINE spdlog::details::thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
namespace spdlog {
namespace details {
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
: q_(q_max_items)
{
if (threads_n == 0 || threads_n > 1000)
@@ -20,7 +22,7 @@ SPDLOG_INLINE spdlog::details::thread_pool::thread_pool(size_t q_max_items, size
}
// message all threads to terminate gracefully join them
SPDLOG_INLINE spdlog::details::thread_pool::~thread_pool()
SPDLOG_INLINE thread_pool::~thread_pool()
{
try
{
@@ -35,28 +37,26 @@ SPDLOG_INLINE spdlog::details::thread_pool::~thread_pool()
}
}
catch (...)
{
}
{}
}
void SPDLOG_INLINE spdlog::details::thread_pool::post_log(
async_logger_ptr &&worker_ptr, details::log_msg &msg, async_overflow_policy overflow_policy)
void SPDLOG_INLINE thread_pool::post_log(async_logger_ptr &&worker_ptr, details::log_msg &msg, async_overflow_policy overflow_policy)
{
async_msg async_m(std::move(worker_ptr), async_msg_type::log, msg);
post_async_msg_(std::move(async_m), overflow_policy);
}
void SPDLOG_INLINE spdlog::details::thread_pool::post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy)
void SPDLOG_INLINE thread_pool::post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy)
{
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
}
size_t SPDLOG_INLINE spdlog::details::thread_pool::overrun_counter()
size_t SPDLOG_INLINE thread_pool::overrun_counter()
{
return q_.overrun_counter();
}
void SPDLOG_INLINE spdlog::details::thread_pool::post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy)
void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy)
{
if (overflow_policy == async_overflow_policy::block)
{
@@ -68,7 +68,7 @@ void SPDLOG_INLINE spdlog::details::thread_pool::post_async_msg_(async_msg &&new
}
}
void SPDLOG_INLINE spdlog::details::thread_pool::worker_loop_()
void SPDLOG_INLINE thread_pool::worker_loop_()
{
while (process_next_msg_()) {};
}
@@ -76,7 +76,7 @@ void SPDLOG_INLINE spdlog::details::thread_pool::worker_loop_()
// process next message in the queue
// return true if this thread should still be active (while no terminate msg
// was received)
bool SPDLOG_INLINE spdlog::details::thread_pool::process_next_msg_()
bool SPDLOG_INLINE thread_pool::process_next_msg_()
{
async_msg incoming_async_msg;
bool dequeued = q_.dequeue_for(incoming_async_msg, std::chrono::seconds(10));
@@ -107,3 +107,6 @@ bool SPDLOG_INLINE spdlog::details::thread_pool::process_next_msg_()
assert(false && "Unexpected async_msg_type");
return true;
}
} // namespace details
} // namespace spdlog

View File

@@ -57,8 +57,7 @@ struct async_msg
msg_id(other.msg_id),
source(other.source),
worker_ptr(std::move(other.worker_ptr))
{
}
{}
async_msg &operator=(async_msg &&other) SPDLOG_NOEXCEPT
{
@@ -98,13 +97,11 @@ struct async_msg
, msg_id(0)
, source()
, worker_ptr(std::move(worker))
{
}
{}
explicit async_msg(async_msg_type the_type)
: async_msg(nullptr, the_type)
{
}
{}
// copy into log_msg
log_msg to_log_msg()
@@ -154,6 +151,6 @@ private:
} // namespace details
} // namespace spdlog
#ifndef SPDLOG_STATIC_LIB
#ifdef SPDLOG_HEADER_ONLY
#include "thread_pool-inl.h"
#endif