Moved spdlog::make_unique to spdlog::details::make_unique and prevent T to be array

This commit is contained in:
gabime 2018-09-26 23:48:36 +03:00
parent e3a66473b2
commit e8dae26176
5 changed files with 47 additions and 43 deletions

View File

@ -15,6 +15,7 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <type_traits>
#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) #if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
#include <codecvt> #include <codecvt>
@ -168,16 +169,19 @@ using filename_t = std::string;
err_handler_("Unknown exeption in logger"); \ err_handler_("Unknown exeption in logger"); \
} }
//
// make_unique support namespace details {
// // make_unique support for pre c++14
#if __cplusplus >= 201402L // C++14 and beyond #if __cplusplus >= 201402L // C++14 and beyond
using std::make_unique; using std::make_unique;
#else #else
template<typename T, typename... Args> template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args &&... args) std::unique_ptr<T> make_unique(Args &&... args)
{ {
static_assert(!std::is_array<T>::value, "arrays to not supported" );
return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
} }
#endif #endif
} // namespace details
} // namespace spdlog } // namespace spdlog

View File

@ -49,7 +49,7 @@ inline void spdlog::logger::set_formatter(std::unique_ptr<spdlog::formatter> f)
inline void spdlog::logger::set_pattern(std::string pattern, pattern_time_type time_type) inline void spdlog::logger::set_pattern(std::string pattern, pattern_time_type time_type)
{ {
auto new_formatter = spdlog::make_unique<spdlog::pattern_formatter>(std::move(pattern), time_type); auto new_formatter = details::make_unique<spdlog::pattern_formatter>(std::move(pattern), time_type);
set_formatter(std::move(new_formatter)); set_formatter(std::move(new_formatter));
} }

View File

@ -547,7 +547,7 @@ public:
std::unique_ptr<formatter> clone() const override std::unique_ptr<formatter> clone() const override
{ {
return spdlog::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_); return details::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_);
} }
void format(const details::log_msg &msg, fmt::memory_buffer &dest) override void format(const details::log_msg &msg, fmt::memory_buffer &dest) override
@ -592,141 +592,141 @@ private:
{ {
// logger name // logger name
case 'n': case 'n':
formatters_.push_back(spdlog::make_unique<details::name_formatter>()); formatters_.push_back(details::make_unique<details::name_formatter>());
break; break;
case 'l': case 'l':
formatters_.push_back(spdlog::make_unique<details::level_formatter>()); formatters_.push_back(details::make_unique<details::level_formatter>());
break; break;
case 'L': case 'L':
formatters_.push_back(spdlog::make_unique<details::short_level_formatter>()); formatters_.push_back(details::make_unique<details::short_level_formatter>());
break; break;
case ('t'): case ('t'):
formatters_.push_back(spdlog::make_unique<details::t_formatter>()); formatters_.push_back(details::make_unique<details::t_formatter>());
break; break;
case ('v'): case ('v'):
formatters_.push_back(spdlog::make_unique<details::v_formatter>()); formatters_.push_back(details::make_unique<details::v_formatter>());
break; break;
case ('a'): case ('a'):
formatters_.push_back(spdlog::make_unique<details::a_formatter>()); formatters_.push_back(details::make_unique<details::a_formatter>());
break; break;
case ('A'): case ('A'):
formatters_.push_back(spdlog::make_unique<details::A_formatter>()); formatters_.push_back(details::make_unique<details::A_formatter>());
break; break;
case ('b'): case ('b'):
case ('h'): case ('h'):
formatters_.push_back(spdlog::make_unique<details::b_formatter>()); formatters_.push_back(details::make_unique<details::b_formatter>());
break; break;
case ('B'): case ('B'):
formatters_.push_back(spdlog::make_unique<details::B_formatter>()); formatters_.push_back(details::make_unique<details::B_formatter>());
break; break;
case ('c'): case ('c'):
formatters_.push_back(spdlog::make_unique<details::c_formatter>()); formatters_.push_back(details::make_unique<details::c_formatter>());
break; break;
case ('C'): case ('C'):
formatters_.push_back(spdlog::make_unique<details::C_formatter>()); formatters_.push_back(details::make_unique<details::C_formatter>());
break; break;
case ('Y'): case ('Y'):
formatters_.push_back(spdlog::make_unique<details::Y_formatter>()); formatters_.push_back(details::make_unique<details::Y_formatter>());
break; break;
case ('D'): case ('D'):
case ('x'): case ('x'):
formatters_.push_back(spdlog::make_unique<details::D_formatter>()); formatters_.push_back(details::make_unique<details::D_formatter>());
break; break;
case ('m'): case ('m'):
formatters_.push_back(spdlog::make_unique<details::m_formatter>()); formatters_.push_back(details::make_unique<details::m_formatter>());
break; break;
case ('d'): case ('d'):
formatters_.push_back(spdlog::make_unique<details::d_formatter>()); formatters_.push_back(details::make_unique<details::d_formatter>());
break; break;
case ('H'): case ('H'):
formatters_.push_back(spdlog::make_unique<details::H_formatter>()); formatters_.push_back(details::make_unique<details::H_formatter>());
break; break;
case ('I'): case ('I'):
formatters_.push_back(spdlog::make_unique<details::I_formatter>()); formatters_.push_back(details::make_unique<details::I_formatter>());
break; break;
case ('M'): case ('M'):
formatters_.push_back(spdlog::make_unique<details::M_formatter>()); formatters_.push_back(details::make_unique<details::M_formatter>());
break; break;
case ('S'): case ('S'):
formatters_.push_back(spdlog::make_unique<details::S_formatter>()); formatters_.push_back(details::make_unique<details::S_formatter>());
break; break;
case ('e'): case ('e'):
formatters_.push_back(spdlog::make_unique<details::e_formatter>()); formatters_.push_back(details::make_unique<details::e_formatter>());
break; break;
case ('f'): case ('f'):
formatters_.push_back(spdlog::make_unique<details::f_formatter>()); formatters_.push_back(details::make_unique<details::f_formatter>());
break; break;
case ('F'): case ('F'):
formatters_.push_back(spdlog::make_unique<details::F_formatter>()); formatters_.push_back(details::make_unique<details::F_formatter>());
break; break;
case ('E'): case ('E'):
formatters_.push_back(spdlog::make_unique<details::E_formatter>()); formatters_.push_back(details::make_unique<details::E_formatter>());
break; break;
case ('p'): case ('p'):
formatters_.push_back(spdlog::make_unique<details::p_formatter>()); formatters_.push_back(details::make_unique<details::p_formatter>());
break; break;
case ('r'): case ('r'):
formatters_.push_back(spdlog::make_unique<details::r_formatter>()); formatters_.push_back(details::make_unique<details::r_formatter>());
break; break;
case ('R'): case ('R'):
formatters_.push_back(spdlog::make_unique<details::R_formatter>()); formatters_.push_back(details::make_unique<details::R_formatter>());
break; break;
case ('T'): case ('T'):
case ('X'): case ('X'):
formatters_.push_back(spdlog::make_unique<details::T_formatter>()); formatters_.push_back(details::make_unique<details::T_formatter>());
break; break;
case ('z'): case ('z'):
formatters_.push_back(spdlog::make_unique<details::z_formatter>()); formatters_.push_back(details::make_unique<details::z_formatter>());
break; break;
case ('+'): case ('+'):
formatters_.push_back(spdlog::make_unique<details::full_formatter>()); formatters_.push_back(details::make_unique<details::full_formatter>());
break; break;
case ('P'): case ('P'):
formatters_.push_back(spdlog::make_unique<details::pid_formatter>()); formatters_.push_back(details::make_unique<details::pid_formatter>());
break; break;
case ('i'): case ('i'):
formatters_.push_back(spdlog::make_unique<details::i_formatter>()); formatters_.push_back(details::make_unique<details::i_formatter>());
break; break;
case ('^'): case ('^'):
formatters_.push_back(spdlog::make_unique<details::color_start_formatter>()); formatters_.push_back(details::make_unique<details::color_start_formatter>());
break; break;
case ('$'): case ('$'):
formatters_.push_back(spdlog::make_unique<details::color_stop_formatter>()); formatters_.push_back(details::make_unique<details::color_stop_formatter>());
break; break;
default: // Unknown flag appears as is default: // Unknown flag appears as is
formatters_.push_back(spdlog::make_unique<details::ch_formatter>('%')); formatters_.push_back(details::make_unique<details::ch_formatter>('%'));
formatters_.push_back(spdlog::make_unique<details::ch_formatter>(flag)); formatters_.push_back(details::make_unique<details::ch_formatter>(flag));
break; break;
} }
} }
@ -757,7 +757,7 @@ private:
{ {
if (!user_chars) if (!user_chars)
{ {
user_chars = spdlog::make_unique<details::aggregate_formatter>(); user_chars = details::make_unique<details::aggregate_formatter>();
} }
user_chars->add_ch(*it); user_chars->add_ch(*it);
} }

View File

@ -113,7 +113,7 @@ public:
{ {
std::lock_guard<std::mutex> lock(flusher_mutex_); std::lock_guard<std::mutex> lock(flusher_mutex_);
std::function<void()> clbk = std::bind(&registry::flush_all, this); std::function<void()> clbk = std::bind(&registry::flush_all, this);
periodic_flusher_ = spdlog::make_unique<periodic_worker>(clbk, interval); periodic_flusher_ = details::make_unique<periodic_worker>(clbk, interval);
} }
void set_error_handler(log_err_handler handler) void set_error_handler(log_err_handler handler)

View File

@ -56,7 +56,7 @@ protected:
virtual void set_pattern_(const std::string &pattern) virtual void set_pattern_(const std::string &pattern)
{ {
set_formatter_(spdlog::make_unique<spdlog::pattern_formatter>(pattern)); set_formatter_(details::make_unique<spdlog::pattern_formatter>(pattern));
} }
virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter) virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter)