[libcalamares] Distinguish logging raw, shared and unique pointers
- It shouldn't be necessary to explicitly .get() pointers for logging, and it's convenient to know when a pointer is smart. * no annotation means raw (e.g. @0x0) * S means shared * U means unique
This commit is contained in:
parent
c43a6ab866
commit
38fa1d9567
@ -13,10 +13,13 @@
|
||||
#ifndef UTILS_LOGGER_H
|
||||
#define UTILS_LOGGER_H
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Logger
|
||||
{
|
||||
struct FuncSuppressor
|
||||
@ -206,16 +209,34 @@ public:
|
||||
* 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.
|
||||
*
|
||||
* Shared pointers are indicated by 'S@' and unique pointers by 'U@'.
|
||||
*/
|
||||
struct Pointer
|
||||
{
|
||||
public:
|
||||
explicit Pointer( const void* p )
|
||||
: ptr( p )
|
||||
, kind( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
explicit Pointer( const std::shared_ptr< T >& p )
|
||||
: ptr( p.get() )
|
||||
, kind( 'S' )
|
||||
{
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
explicit Pointer( const std::unique_ptr< T >& p )
|
||||
: ptr( p.get() )
|
||||
, kind( 'U' )
|
||||
{
|
||||
}
|
||||
|
||||
const void* const ptr;
|
||||
const char kind;
|
||||
};
|
||||
|
||||
/** @brief output operator for DebugRow */
|
||||
@ -256,7 +277,12 @@ operator<<( QDebug& s, const DebugMap& t )
|
||||
inline QDebug&
|
||||
operator<<( QDebug& s, const Pointer& p )
|
||||
{
|
||||
s << NoQuote << '@' << p.ptr << Quote;
|
||||
s << NoQuote;
|
||||
if ( p.kind )
|
||||
{
|
||||
s << p.kind;
|
||||
}
|
||||
s << '@' << p.ptr << Quote;
|
||||
return s;
|
||||
}
|
||||
} // namespace Logger
|
||||
|
@ -25,7 +25,7 @@ AutoMountManagementJob::prettyName() const
|
||||
Calamares::JobResult
|
||||
AutoMountManagementJob::exec()
|
||||
{
|
||||
Logger::CDebug(Logger::LOGVERBOSE) << "this" << Logger::Pointer( this ) << "value" << Logger::Pointer( m_stored.get() );
|
||||
Logger::CDebug(Logger::LOGVERBOSE) << "this" << Logger::Pointer( this ) << "value" << Logger::Pointer( m_stored );
|
||||
if ( m_stored )
|
||||
{
|
||||
CalamaresUtils::Partition::automountRestore( m_stored );
|
||||
|
@ -40,7 +40,7 @@ AutoMountJobTests::testRunThrice()
|
||||
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
||||
|
||||
auto original = CalamaresUtils::Partition::automountDisable( true );
|
||||
cDebug() << "Got automount info" << Logger::Pointer( original.get() );
|
||||
cDebug() << "Got automount info" << Logger::Pointer( original );
|
||||
|
||||
AutoMountManagementJob j( false );
|
||||
QVERIFY( j.exec() );
|
||||
|
Loading…
Reference in New Issue
Block a user