[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

@ -37,8 +37,12 @@ struct FuncSuppressor
const char* m_s; const char* m_s;
}; };
struct NoQuote {}; struct NoQuote
struct Quote {}; {
};
struct Quote
{
};
DLLEXPORT extern const FuncSuppressor Continuation; DLLEXPORT extern const FuncSuppressor Continuation;
DLLEXPORT extern const FuncSuppressor SubEntry; DLLEXPORT extern const FuncSuppressor SubEntry;
@ -206,6 +210,24 @@ public:
const QVariantMap& map; 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 */ /** @brief output operator for DebugRow */
template < typename T, typename U > template < typename T, typename U >
inline QDebug& inline QDebug&
@ -240,6 +262,13 @@ operator<<( QDebug& s, const DebugMap& t )
} }
return s; return s;
} }
inline QDebug&
operator<<( QDebug& s, const Pointer& p )
{
s << NoQuote {} << '@' << p.ptr << Quote {};
return s;
}
} // namespace Logger } // namespace Logger
#define cDebug() Logger::CDebug( Logger::LOGDEBUG, Q_FUNC_INFO ) #define cDebug() Logger::CDebug( Logger::LOGDEBUG, Q_FUNC_INFO )