19 #ifndef LIB_QUENTIER_UTILITY_PRINTABLE_H
20 #define LIB_QUENTIER_UTILITY_PRINTABLE_H
22 #include <quentier/utility/Linkage.h>
23 #include <quentier/utility/Macros.h>
29 #include <QTextStream>
41 virtual QTextStream & print(QTextStream & strm)
const = 0;
43 virtual const QString toString()
const;
45 friend QUENTIER_EXPORT QTextStream & operator << (
46 QTextStream & strm,
const Printable & printable);
48 friend QUENTIER_EXPORT QDebug & operator << (
49 QDebug & debug,
const Printable & printable);
63 const QString ToString(
const T &
object)
66 QTextStream strm(&str, QIODevice::WriteOnly);
71 template <
class TKey,
class TValue>
72 const QString ToString(
const QHash<TKey, TValue> &
object)
75 QTextStream strm(&str, QIODevice::WriteOnly);
76 strm << QStringLiteral(
"QHash: \n");
78 typedef typename QHash<TKey,TValue>::const_iterator CIter;
79 CIter hashEnd =
object.end();
80 for(CIter it =
object.begin(); it != hashEnd; ++it) {
81 strm << QStringLiteral(
"[") << it.key() << QStringLiteral(
"] = ")
82 << it.value() << QStringLiteral(
";\n");
88 const QString ToString(
const QSet<T> &
object)
91 QTextStream strm(&str, QIODevice::WriteOnly);
92 strm << QStringLiteral(
"QSet: \n");
94 typedef typename QSet<T>::const_iterator CIter;
95 CIter setEnd =
object.end();
96 for(CIter it =
object.begin(); it != setEnd; ++it) {
97 strm << QStringLiteral(
"[") << *it << QStringLiteral(
"];\n");
102 #define QUENTIER_DECLARE_PRINTABLE(type, ...) \
103 QUENTIER_EXPORT QTextStream & \
104 operator << (QTextStream & strm, const type & obj); \
105 inline QDebug & operator << (QDebug & debug, const type & obj) \
107 debug << ToString<type, ##__VA_ARGS__>(obj); \
The Printable class is the interface for Quentier's internal classes which should be able to write th...
Definition: Printable.h:39