[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
|
#ifndef UTILS_LOGGER_H
|
||||||
#define UTILS_LOGGER_H
|
#define UTILS_LOGGER_H
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Logger
|
namespace Logger
|
||||||
{
|
{
|
||||||
struct FuncSuppressor
|
struct FuncSuppressor
|
||||||
@ -206,16 +209,34 @@ public:
|
|||||||
* Pointers are printed as void-pointer, so just an address (unlike, say,
|
* Pointers are printed as void-pointer, so just an address (unlike, say,
|
||||||
* QObject pointers which show an address and some metadata) preceded
|
* QObject pointers which show an address and some metadata) preceded
|
||||||
* by an '@'. This avoids C-style (void*) casts in the code.
|
* by an '@'. This avoids C-style (void*) casts in the code.
|
||||||
|
*
|
||||||
|
* Shared pointers are indicated by 'S@' and unique pointers by 'U@'.
|
||||||
*/
|
*/
|
||||||
struct Pointer
|
struct Pointer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Pointer( const void* p )
|
explicit Pointer( const void* p )
|
||||||
: ptr( 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 void* const ptr;
|
||||||
|
const char kind;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief output operator for DebugRow */
|
/** @brief output operator for DebugRow */
|
||||||
@ -256,7 +277,12 @@ operator<<( QDebug& s, const DebugMap& t )
|
|||||||
inline QDebug&
|
inline QDebug&
|
||||||
operator<<( QDebug& s, const Pointer& p )
|
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;
|
return s;
|
||||||
}
|
}
|
||||||
} // namespace Logger
|
} // namespace Logger
|
||||||
|
@ -25,7 +25,7 @@ AutoMountManagementJob::prettyName() const
|
|||||||
Calamares::JobResult
|
Calamares::JobResult
|
||||||
AutoMountManagementJob::exec()
|
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 )
|
if ( m_stored )
|
||||||
{
|
{
|
||||||
CalamaresUtils::Partition::automountRestore( m_stored );
|
CalamaresUtils::Partition::automountRestore( m_stored );
|
||||||
|
@ -40,7 +40,7 @@ AutoMountJobTests::testRunThrice()
|
|||||||
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
||||||
|
|
||||||
auto original = CalamaresUtils::Partition::automountDisable( true );
|
auto original = CalamaresUtils::Partition::automountDisable( true );
|
||||||
cDebug() << "Got automount info" << Logger::Pointer( original.get() );
|
cDebug() << "Got automount info" << Logger::Pointer( original );
|
||||||
|
|
||||||
AutoMountManagementJob j( false );
|
AutoMountManagementJob j( false );
|
||||||
QVERIFY( j.exec() );
|
QVERIFY( j.exec() );
|
||||||
|
Loading…
Reference in New Issue
Block a user