[libcalamares] Logging-convenience for pointers

- This reduces the amount of (void*) C-style casts in the code,
  and formats generic pointers more consistently.
This commit is contained in:
Adriaan de Groot 2020-06-23 12:29:18 +02:00
parent 192263cf9d
commit 916c10816b

View File

@ -1,5 +1,5 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
*
* SPDX-FileCopyrightText: 2010-2011 Christian Muehlhaeuser <muesli@tomahawk-player.org>
* SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
* SPDX-FileCopyrightText: 2017-2019 Adriaan de Groot <groot@kde.org>
@ -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 )