From 916c10816b9913c1f695ada703a788a75bbe54a2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 23 Jun 2020 12:29:18 +0200 Subject: [PATCH] [libcalamares] Logging-convenience for pointers - This reduces the amount of (void*) C-style casts in the code, and formats generic pointers more consistently. --- src/libcalamares/utils/Logger.h | 35 ++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 69674bc68..2354155ed 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -1,5 +1,5 @@ /* === This file is part of Calamares - === - * + * * SPDX-FileCopyrightText: 2010-2011 Christian Muehlhaeuser * SPDX-FileCopyrightText: 2014 Teo Mrnjavac * SPDX-FileCopyrightText: 2017-2019 Adriaan de Groot @@ -37,8 +37,12 @@ struct FuncSuppressor const char* m_s; }; -struct NoQuote {}; -struct Quote {}; +struct NoQuote +{ +}; +struct Quote +{ +}; DLLEXPORT extern const FuncSuppressor Continuation; DLLEXPORT extern const FuncSuppressor SubEntry; @@ -206,6 +210,24 @@ public: const QVariantMap& map; }; +/** + * @brief Formatted logging of a pointer + * + * Pointers are printed as void-pointer, so just an address (unlike, say, + * QObject pointers which show an address and some metadata) preceded + * by an '@'. This avoids C-style (void*) casts in the code. + */ +struct Pointer +{ +public: + explicit Pointer( void* p ) + : ptr( p ) + { + } + + const void* ptr; +}; + /** @brief output operator for DebugRow */ template < typename T, typename U > inline QDebug& @@ -240,6 +262,13 @@ operator<<( QDebug& s, const DebugMap& t ) } return s; } + +inline QDebug& +operator<<( QDebug& s, const Pointer& p ) +{ + s << NoQuote {} << '@' << p.ptr << Quote {}; + return s; +} } // namespace Logger #define cDebug() Logger::CDebug( Logger::LOGDEBUG, Q_FUNC_INFO )