diff --git a/.github/settings.yml b/.github/settings.yml index 118920f46..19973be34 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -12,6 +12,5 @@ branches: protection: required_status_checks: contexts: - - bazel-opt - Codacy Static Code Analysis - code-review/reviewable diff --git a/cpp/src/util/logging.h b/cpp/src/util/logging.h index f65148868..6c3bf8bad 100644 --- a/cpp/src/util/logging.h +++ b/cpp/src/util/logging.h @@ -1,83 +1,65 @@ #pragma once #include +#include #include #include - -struct scope_counter -{ +struct scope_counter { static std::size_t scope; - scope_counter () - { scope++; } + scope_counter() { scope++; } - ~scope_counter () - { scope--; } + ~scope_counter() { scope--; } - scope_counter (scope_counter const &rhs) = delete; + scope_counter(scope_counter const &rhs) = delete; }; -std::ostream &scope_indent (std::ostream &os, int line); +std::ostream &scope_indent(std::ostream &os, int line); #define SCOPE scope_counter const _scope - #ifdef HAVE_GLOG -# include -# undef LOG -# define LOG(KIND) scope_indent (COMPACT_GOOGLE_LOG_##KIND.stream(), __LINE__) +#include +#undef LOG +#define LOG(KIND) scope_indent(COMPACT_GOOGLE_LOG_##KIND.stream(), __LINE__) #else -namespace google -{ - inline void InitGoogleLogging (char const *) { } - inline void ShutdownGoogleLogging () { } - inline void LogToStderr () { } -} +namespace google { +inline void InitGoogleLogging(char const *) {} +inline void ShutdownGoogleLogging() {} +inline void LogToStderr() {} +} // namespace google -struct null_ostream - : std::ostream -{ -}; +struct null_ostream : std::ostream {}; -# define LOG(LEVEL) (null_ostream ()) -# define LOG_ASSERT(cond) assert (cond) +#define LOG(LEVEL) (null_ostream()) +#define LOG_ASSERT(cond) assert(cond) #endif -void output_hex (std::ostream &os, uint8_t const *data, size_t length); - +void output_hex(std::ostream &os, uint8_t const *data, size_t length); -struct formatter -{ - formatter (formatter &&fmt) - : text_ (std::move (fmt.text_)) - { } +struct formatter { + formatter(formatter &&fmt) : text_(std::move(fmt.text_)) {} - explicit formatter (std::vector text) - : text_ (std::move (text)) - { } + explicit formatter(std::vector text) : text_(std::move(text)) {} - friend std::ostream &operator << (std::ostream &os, formatter const &fmt); + friend std::ostream &operator<<(std::ostream &os, formatter const &fmt); private: std::vector const text_; }; +template +formatter format(char const (&fmt)[N], Args const &...args) { + std::vector text(snprintf(nullptr, 0, fmt, args...) + 1); + snprintf(text.data(), text.size(), fmt, args...); -template -formatter -format (char const (&fmt)[N], Args const &...args) -{ - std::vector text (snprintf (nullptr, 0, fmt, args...) + 1); - snprintf (text.data (), text.size (), fmt, args...); - - return formatter (std::move (text)); + return formatter(std::move(text)); } -template -std::ostream & -operator << (std::ostream &os, std::array const &array) -{ - output_hex (os, array.data (), array.size ()); +template +std::ostream &operator<<(std::ostream &os, + std::array const &array) { + output_hex(os, array.data(), array.size()); return os; }