From 3456aabfce7d24ec7340a389eda23ee53dd8d55a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 27 Feb 2020 11:59:24 +0100 Subject: [PATCH] [libcalamares] Expand utility of list-logging - Allow logging any QList type (needs explicit call in usage). - Add a DebugList inheriting from DebugListT to keep existing code that logs QStringLists. - For Calamares 3.3, consider using C++17 and class template deduction. --- src/libcalamares/utils/Logger.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 643b3059b..9163aef07 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -134,14 +134,32 @@ public: * will produce a single timestamped debug line with continuations. * Each element of the list of strings will be logged on a separate line. */ -struct DebugList +/* TODO: Calamares 3.3, bump requirements to C++17, and rename + * this to DebugList, dropping the convenience-definition + * below. In C++17, class template argument deduction is + * added, so `DebugList( whatever )` determines the right + * type already (also for QStringList). + */ +template < typename T > +struct DebugListT { - explicit DebugList( const QStringList& l ) + using list_t = QList< T >; + + explicit DebugListT( const list_t& l ) : list( l ) { } - const QStringList& list; + const list_t& list; +}; + +///@brief Convenience for QStringList, needs no template parameters +struct DebugList : public DebugListT< QString > +{ + explicit DebugList( const list_t& l ) + : DebugListT( l ) + { + } }; /** @@ -174,9 +192,10 @@ operator<<( QDebug& s, const DebugRow< T, U >& t ) return s; } -/** @brief output operator for DebugList */ +/** @brief output operator for DebugList, assuming operator<< for T exists */ +template < typename T = QString > inline QDebug& -operator<<( QDebug& s, const DebugList& c ) +operator<<( QDebug& s, const DebugListT< T >& c ) { for ( const auto& i : c.list ) {