From d1eac88d18ae7dd11033dba87b6aebb220da9064 Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Thu, 29 Mar 2018 10:34:05 -0400 Subject: Enable clang-format Fix up errors and enable clang-format during CI builds. Change-Id: I4176b81f8b85a287af9354165e09ff66aeb9fb29 Signed-off-by: Brad Bishop --- src/elog.hpp | 196 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 93 insertions(+), 103 deletions(-) (limited to 'src/elog.hpp') diff --git a/src/elog.hpp b/src/elog.hpp index 234ef6f..996fd58 100644 --- a/src/elog.hpp +++ b/src/elog.hpp @@ -39,21 +39,22 @@ template <> struct ToString */ class ElogBase : public Callback { - public: - ElogBase(const ElogBase&) = delete; - ElogBase(ElogBase&&) = default; - ElogBase& operator=(const ElogBase&) = delete; - ElogBase& operator=(ElogBase&&) = default; - virtual ~ElogBase() = default; - ElogBase() : - Callback() {} - - /** @brief Callback interface implementation. */ - void operator()(Context ctx) override; - - private: - /** @brief Delegate type specific calls to subclasses. */ - virtual void log() const = 0; + public: + ElogBase(const ElogBase&) = delete; + ElogBase(ElogBase&&) = default; + ElogBase& operator=(const ElogBase&) = delete; + ElogBase& operator=(ElogBase&&) = default; + virtual ~ElogBase() = default; + ElogBase() : Callback() + { + } + + /** @brief Callback interface implementation. */ + void operator()(Context ctx) override; + + private: + /** @brief Delegate type specific calls to subclasses. */ + virtual void log() const = 0; }; namespace detail @@ -65,10 +66,9 @@ namespace detail * @tparam T - Error log type * @tparam Args - Metadata fields types. */ -template -struct CallElog +template struct CallElog { - static void op(Args&& ...args) + static void op(Args&&... args) { phosphor::logging::report(std::forward(args)...); } @@ -84,31 +84,29 @@ struct CallElog * @tparam Args - Metadata fields types. * @param[in] arguments - Metadata fields to be added to the error log */ -template -class Elog : public ElogBase +template class Elog : public ElogBase { - public: - Elog(const Elog&) = delete; - Elog(Elog&&) = default; - Elog& operator=(const Elog&) = delete; - Elog& operator=(Elog&&) = default; - ~Elog() = default; - Elog(Args&& ... arguments) : - ElogBase(), args(std::forward(arguments)...) {} - - private: - /** @brief elog interface implementation. */ - void log() const override - { - std::experimental::apply( - detail::CallElog::op, - std::tuple_cat(args)); - } - std::tuple args; + public: + Elog(const Elog&) = delete; + Elog(Elog&&) = default; + Elog& operator=(const Elog&) = delete; + Elog& operator=(Elog&&) = default; + ~Elog() = default; + Elog(Args&&... arguments) : + ElogBase(), args(std::forward(arguments)...) + { + } + private: + /** @brief elog interface implementation. */ + void log() const override + { + std::experimental::apply(detail::CallElog::op, + std::tuple_cat(args)); + } + std::tuple args; }; - /** * @class ElogWithMetadataCapture * @@ -135,75 +133,69 @@ class Elog : public ElogBase * @tparam metadataType - The metadata to use * @tparam propertyType - The data type of the captured properties */ -template +template class ElogWithMetadataCapture : public IndexedCallback { - public: - ElogWithMetadataCapture() = delete; - ElogWithMetadataCapture(const ElogWithMetadataCapture&) = delete; - ElogWithMetadataCapture(ElogWithMetadataCapture&&) = default; - ElogWithMetadataCapture& operator=( - const ElogWithMetadataCapture&) = delete; - ElogWithMetadataCapture& operator=( - ElogWithMetadataCapture&&) = default; - virtual ~ElogWithMetadataCapture() = default; - explicit ElogWithMetadataCapture( - const PropertyIndex& index) : - IndexedCallback(index) {} - - /** - * @brief Callback interface implementation that - * creates an error log - */ - void operator()(Context ctx) override - { - auto data = captureMetadata(); + public: + ElogWithMetadataCapture() = delete; + ElogWithMetadataCapture(const ElogWithMetadataCapture&) = delete; + ElogWithMetadataCapture(ElogWithMetadataCapture&&) = default; + ElogWithMetadataCapture& operator=(const ElogWithMetadataCapture&) = delete; + ElogWithMetadataCapture& operator=(ElogWithMetadataCapture&&) = default; + virtual ~ElogWithMetadataCapture() = default; + explicit ElogWithMetadataCapture(const PropertyIndex& index) : + IndexedCallback(index) + { + } - phosphor::logging::report( - metadataType(data.c_str())); - } + /** + * @brief Callback interface implementation that + * creates an error log + */ + void operator()(Context ctx) override + { + auto data = captureMetadata(); - private: - - /** - * @brief Builds a metadata string with property information - * - * Finds all of the properties in the index that have - * their condition pass/fail fields (get(storage)) - * set to true, and then packs those paths, names, and values - * into a metadata string that looks like: - * - * |path1:name1=value1|path2:name2=value2|... - * - * @return The metadata string - */ - std::string captureMetadata() + phosphor::logging::report(metadataType(data.c_str())); + } + + private: + /** + * @brief Builds a metadata string with property information + * + * Finds all of the properties in the index that have + * their condition pass/fail fields (get(storage)) + * set to true, and then packs those paths, names, and values + * into a metadata string that looks like: + * + * |path1:name1=value1|path2:name2=value2|... + * + * @return The metadata string + */ + std::string captureMetadata() + { + std::string metadata{'|'}; + + for (const auto& n : index) { - std::string metadata{'|'}; + const auto& storage = std::get(n.second).get(); + const auto& result = std::get(storage); - for (const auto& n : index) + if (!result.empty() && any_ns::any_cast(result)) { - const auto& storage = std::get(n.second).get(); - const auto& result = std::get(storage); - - if (!result.empty() && any_ns::any_cast(result)) - { - const auto& path = std::get(n.first).get(); - const auto& propertyName = std::get( - n.first).get(); - auto value = ToString::op( - any_ns::any_cast( - std::get(storage))); - - metadata += path + ":" + propertyName + - '=' + value + '|'; - } + const auto& path = std::get(n.first).get(); + const auto& propertyName = + std::get(n.first).get(); + auto value = + ToString::op(any_ns::any_cast( + std::get(storage))); + + metadata += path + ":" + propertyName + '=' + value + '|'; } + } - return metadata; - }; + return metadata; + }; }; /** @brief Argument type deduction for constructing Elog instances. @@ -212,11 +204,9 @@ class ElogWithMetadataCapture : public IndexedCallback * @tparam Args - Metadata fields types. * @param[in] arguments - Metadata fields to be added to the error log */ -template -auto makeElog(Args&& ... arguments) +template auto makeElog(Args&&... arguments) { - return std::make_unique>( - std::forward(arguments)...); + return std::make_unique>(std::forward(arguments)...); } } // namespace monitoring -- cgit v1.2.1