Changeset 604 for trunk/src


Ignore:
Timestamp:
Feb 26, 2010, 12:29:07 AM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: Added qDebugFmt() and qDebugFmtHex() debug stream modifiers to ease formatting of integers in debug printing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/io/qdebug.h

    r561 r604  
    255255}
    256256
     257template <class T>
     258struct QDebugFmt
     259{
     260    QDebugFmt(const char *fmt, const T &val) : format(fmt), value(val) {};
     261    const char *format;
     262    const T &value;
     263};
     264
     265template <class T>
     266inline QDebugFmt<T> qDebugFmt(const char *fmt, const T &val)
     267{
     268    return QDebugFmt<T>(fmt, val);
     269}
     270
     271inline QDebugFmt<char> qDebugFmtHex(const char &val) { return qDebugFmt("0x%02X", val); }
     272inline QDebugFmt<char> qDebugFmtHex(const uchar &val) { return qDebugFmtHex(reinterpret_cast<const char &>(val)); }
     273inline QDebugFmt<short> qDebugFmtHex(const short &val) { return qDebugFmt("0x%04X", val); }
     274inline QDebugFmt<short> qDebugFmtHex(const ushort &val) { return qDebugFmtHex(reinterpret_cast<const short &>(val)); }
     275inline QDebugFmt<int> qDebugFmtHex(const int &val) { return qDebugFmt("0x%08X", val); }
     276inline QDebugFmt<int> qDebugFmtHex(const uint &val) { return qDebugFmtHex(reinterpret_cast<const int &>(val)); }
     277inline QDebugFmt<long> qDebugFmtHex(const long &val) { return qDebugFmt("0x%08lX", val); }
     278inline QDebugFmt<long> qDebugFmtHex(const ulong &val) { return qDebugFmtHex(reinterpret_cast<const long &>(val)); }
     279
     280#if defined(FORCE_UREF)
     281template <class T>
     282inline QDebug &operator<<(QDebug debug, const QDebugFmt<T> &fmt)
     283#else
     284template <class T>
     285inline QDebug operator<<(QDebug debug, const QDebugFmt<T> &fmt)
     286#endif
     287{
     288    debug << QString().sprintf(fmt.format, fmt.value).toAscii().constData();
     289    return debug;
     290}
     291
    257292#if !defined(QT_NO_DEBUG_STREAM)
    258293Q_CORE_EXPORT_INLINE QDebug qDebug() { return QDebug(QtDebugMsg); }
Note: See TracChangeset for help on using the changeset viewer.