1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QDEBUG_H
6#define QDEBUG_H
7
8#if 0
9#pragma qt_class(QtDebug)
10#endif
11
12#include <QtCore/qcontainerfwd.h>
13#include <QtCore/qtextstream.h>
14#include <QtCore/qstring.h>
15#include <QtCore/qcontiguouscache.h>
16#include <QtCore/qsharedpointer.h>
17
18// all these have already been included by various headers above, but don't rely on indirect includes:
19#include <chrono>
20#include <list>
21#include <map>
22#include <string>
23#include <string_view>
24#include <utility>
25#include <vector>
26
27#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 1
28# include <QtCore/qlist.h>
29# include <QtCore/qmap.h>
30# include <QtCore/qset.h>
31# include <QtCore/qvarlengtharray.h>
32#endif
33
34QT_BEGIN_NAMESPACE
35
36class QT6_ONLY(Q_CORE_EXPORT) QDebug : public QIODeviceBase
37{
38 friend class QMessageLogger;
39 friend class QDebugStateSaver;
40 friend class QDebugStateSaverPrivate;
41 struct Stream {
42 enum { VerbosityShift = 29, VerbosityMask = 0x7 };
43
44 Stream(QIODevice *device)
45 : ts(device)
46 {}
47 Stream(QString *string)
48 : ts(string, WriteOnly)
49 {}
50 Stream(QtMsgType t)
51 : ts(&buffer, WriteOnly),
52 type(t),
53 message_output(true)
54 {}
55 QTextStream ts;
56 QString buffer;
57 int ref = 1;
58 QtMsgType type = QtDebugMsg;
59 bool space = true;
60 bool noQuotes = false;
61 bool message_output = false;
62 int verbosity = DefaultVerbosity;
63 QMessageLogContext context;
64 } *stream;
65
66 enum Latin1Content { ContainsBinary = 0, ContainsLatin1 };
67
68 QT7_ONLY(Q_CORE_EXPORT) void putUcs4(uint ucs4);
69 QT7_ONLY(Q_CORE_EXPORT) void putString(const QChar *begin, size_t length);
70 QT7_ONLY(Q_CORE_EXPORT) void putByteArray(const char *begin, size_t length, Latin1Content content);
71 QT7_ONLY(Q_CORE_EXPORT) void putTimeUnit(qint64 num, qint64 den);
72public:
73 explicit QDebug(QIODevice *device) : stream(new Stream(device)) {}
74 explicit QDebug(QString *string) : stream(new Stream(string)) {}
75 explicit QDebug(QtMsgType t) : stream(new Stream(t)) {}
76 QDebug(const QDebug &o) : stream(o.stream) { ++stream->ref; }
77 QDebug(QDebug &&other) noexcept : stream{std::exchange(obj&: other.stream, new_val: nullptr)} {}
78 inline QDebug &operator=(const QDebug &other);
79 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QDebug)
80 ~QDebug();
81 void swap(QDebug &other) noexcept { qt_ptr_swap(lhs&: stream, rhs&: other.stream); }
82
83 QT7_ONLY(Q_CORE_EXPORT) QDebug &resetFormat();
84
85 inline QDebug &space() { stream->space = true; stream->ts << ' '; return *this; }
86 inline QDebug &nospace() { stream->space = false; return *this; }
87 inline QDebug &maybeSpace() { if (stream->space) stream->ts << ' '; return *this; }
88 inline QDebug &verbosity(int verbosityLevel) { stream->verbosity = verbosityLevel; return *this; }
89 int verbosity() const { return stream->verbosity; }
90 void setVerbosity(int verbosityLevel) { stream->verbosity = verbosityLevel; }
91 enum VerbosityLevel { MinimumVerbosity = 0, DefaultVerbosity = 2, MaximumVerbosity = 7 };
92
93 bool autoInsertSpaces() const { return stream->space; }
94 void setAutoInsertSpaces(bool b) { stream->space = b; }
95
96 inline QDebug &quote() { stream->noQuotes = false; return *this; }
97 inline QDebug &noquote() { stream->noQuotes = true; return *this; }
98 inline QDebug &maybeQuote(char c = '"') { if (!stream->noQuotes) stream->ts << c; return *this; }
99
100 inline QDebug &operator<<(QChar t) { putUcs4(ucs4: t.unicode()); return maybeSpace(); }
101 inline QDebug &operator<<(bool t) { stream->ts << (t ? "true" : "false"); return maybeSpace(); }
102 inline QDebug &operator<<(char t) { stream->ts << t; return maybeSpace(); }
103 inline QDebug &operator<<(signed short t) { stream->ts << t; return maybeSpace(); }
104 inline QDebug &operator<<(unsigned short t) { stream->ts << t; return maybeSpace(); }
105 inline QDebug &operator<<(char16_t t) { return *this << QChar(t); }
106 inline QDebug &operator<<(char32_t t) { putUcs4(ucs4: t); return maybeSpace(); }
107 inline QDebug &operator<<(signed int t) { stream->ts << t; return maybeSpace(); }
108 inline QDebug &operator<<(unsigned int t) { stream->ts << t; return maybeSpace(); }
109 inline QDebug &operator<<(signed long t) { stream->ts << t; return maybeSpace(); }
110 inline QDebug &operator<<(unsigned long t) { stream->ts << t; return maybeSpace(); }
111 inline QDebug &operator<<(qint64 t) { stream->ts << t; return maybeSpace(); }
112 inline QDebug &operator<<(quint64 t) { stream->ts << t; return maybeSpace(); }
113 inline QDebug &operator<<(qfloat16 t) { stream->ts << t; return maybeSpace(); }
114 inline QDebug &operator<<(float t) { stream->ts << t; return maybeSpace(); }
115 inline QDebug &operator<<(double t) { stream->ts << t; return maybeSpace(); }
116 inline QDebug &operator<<(const char* t) { stream->ts << QString::fromUtf8(utf8: t); return maybeSpace(); }
117 inline QDebug &operator<<(const char16_t *t) { stream->ts << QStringView(t); return maybeSpace(); }
118 inline QDebug &operator<<(const QString & t) { putString(begin: t.constData(), length: size_t(t.size())); return maybeSpace(); }
119 inline QDebug &operator<<(QStringView s) { putString(begin: s.data(), length: size_t(s.size())); return maybeSpace(); }
120 inline QDebug &operator<<(QUtf8StringView s) { putByteArray(begin: reinterpret_cast<const char*>(s.data()), length: s.size(), content: ContainsBinary); return maybeSpace(); }
121 inline QDebug &operator<<(QLatin1StringView t) { putByteArray(begin: t.latin1(), length: t.size(), content: ContainsLatin1); return maybeSpace(); }
122 inline QDebug &operator<<(const QByteArray & t) { putByteArray(begin: t.constData(), length: t.size(), content: ContainsBinary); return maybeSpace(); }
123 inline QDebug &operator<<(QByteArrayView t) { putByteArray(begin: t.constData(), length: t.size(), content: ContainsBinary); return maybeSpace(); }
124 inline QDebug &operator<<(const void * t) { stream->ts << t; return maybeSpace(); }
125 inline QDebug &operator<<(std::nullptr_t) { stream->ts << "(nullptr)"; return maybeSpace(); }
126 inline QDebug &operator<<(QTextStreamFunction f) {
127 stream->ts << f;
128 return *this;
129 }
130
131 inline QDebug &operator<<(QTextStreamManipulator m)
132 { stream->ts << m; return *this; }
133
134#ifdef Q_QDOC
135 template <typename Char, typename...Args>
136 QDebug &operator<<(const std::basic_string<Char, Args...> &s);
137
138 template <typename Char, typename...Args>
139 QDebug &operator<<(std::basic_string_view<Char, Args...> s);
140#else
141 template <typename...Args>
142 QDebug &operator<<(const std::basic_string<char, Args...> &s)
143 { return *this << QUtf8StringView(s); }
144
145 template <typename...Args>
146 QDebug &operator<<(std::basic_string_view<char, Args...> s)
147 { return *this << QUtf8StringView(s); }
148
149#ifdef __cpp_char8_t
150 template <typename...Args>
151 QDebug &operator<<(const std::basic_string<char8_t, Args...> &s)
152 { return *this << QUtf8StringView(s); }
153
154 template <typename...Args>
155 QDebug &operator<<(std::basic_string_view<char8_t, Args...> s)
156 { return *this << QUtf8StringView(s); }
157#endif // __cpp_char8_t
158
159 template <typename...Args>
160 QDebug &operator<<(const std::basic_string<char16_t, Args...> &s)
161 { return *this << QStringView(s); }
162
163 template <typename...Args>
164 QDebug &operator<<(std::basic_string_view<char16_t, Args...> s)
165 { return *this << QStringView(s); }
166
167 template <typename...Args>
168 QDebug &operator<<(const std::basic_string<wchar_t, Args...> &s)
169 {
170 if constexpr (sizeof(wchar_t) == 2)
171 return *this << QStringView(s);
172 else
173 return *this << QString::fromWCharArray(string: s.data(), size: s.size()); // ### optimize
174 }
175
176 template <typename...Args>
177 QDebug &operator<<(std::basic_string_view<wchar_t, Args...> s)
178 {
179 if constexpr (sizeof(wchar_t) == 2)
180 return *this << QStringView(s);
181 else
182 return *this << QString::fromWCharArray(string: s.data(), size: s.size()); // ### optimize
183 }
184
185 template <typename...Args>
186 QDebug &operator<<(const std::basic_string<char32_t, Args...> &s)
187 { return *this << QString::fromUcs4(s.data(), s.size()); }
188
189 template <typename...Args>
190 QDebug &operator<<(std::basic_string_view<char32_t, Args...> s)
191 { return *this << QString::fromUcs4(s.data(), s.size()); }
192#endif // !Q_QDOC
193
194 template <typename Rep, typename Period>
195 QDebug &operator<<(std::chrono::duration<Rep, Period> duration)
196 {
197 stream->ts << duration.count();
198 putTimeUnit(num: Period::num, den: Period::den);
199 return maybeSpace();
200 }
201
202 template <typename T>
203 static QString toString(T &&object)
204 {
205 QString buffer;
206 QDebug stream(&buffer);
207 stream.nospace() << std::forward<T>(object);
208 return buffer;
209 }
210};
211
212Q_DECLARE_SHARED(QDebug)
213
214class QDebugStateSaverPrivate;
215class QDebugStateSaver
216{
217public:
218 Q_NODISCARD_CTOR Q_CORE_EXPORT
219 QDebugStateSaver(QDebug &dbg);
220 Q_CORE_EXPORT
221 ~QDebugStateSaver();
222private:
223 Q_DISABLE_COPY(QDebugStateSaver)
224 QScopedPointer<QDebugStateSaverPrivate> d;
225};
226
227class QNoDebug
228{
229public:
230 inline QNoDebug &operator<<(QTextStreamFunction) { return *this; }
231 inline QNoDebug &operator<<(QTextStreamManipulator) { return *this; }
232 inline QNoDebug &space() { return *this; }
233 inline QNoDebug &nospace() { return *this; }
234 inline QNoDebug &maybeSpace() { return *this; }
235 inline QNoDebug &quote() { return *this; }
236 inline QNoDebug &noquote() { return *this; }
237 inline QNoDebug &maybeQuote(const char = '"') { return *this; }
238 inline QNoDebug &verbosity(int) { return *this; }
239
240 template<typename T>
241 inline QNoDebug &operator<<(const T &) { return *this; }
242};
243
244inline QDebug &QDebug::operator=(const QDebug &other)
245{
246 QDebug{other}.swap(other&: *this);
247 return *this;
248}
249
250namespace QtPrivate {
251
252template <typename SequentialContainer>
253inline QDebug printSequentialContainer(QDebug debug, const char *which, const SequentialContainer &c)
254{
255 const QDebugStateSaver saver(debug);
256 debug.nospace() << which << '(';
257 typename SequentialContainer::const_iterator it = c.begin(), end = c.end();
258 if (it != end) {
259 debug << *it;
260 ++it;
261 }
262 while (it != end) {
263 debug << ", " << *it;
264 ++it;
265 }
266 debug << ')';
267 return debug;
268}
269
270template <typename AssociativeContainer>
271inline QDebug printAssociativeContainer(QDebug debug, const char *which, const AssociativeContainer &c)
272{
273 const QDebugStateSaver saver(debug);
274 debug.nospace() << which << "(";
275 for (typename AssociativeContainer::const_iterator it = c.constBegin();
276 it != c.constEnd(); ++it) {
277 debug << '(' << it.key() << ", " << it.value() << ')';
278 }
279 debug << ')';
280 return debug;
281}
282
283} // namespace QtPrivate
284
285template<typename ...T>
286using QDebugIfHasDebugStream =
287 std::enable_if_t<std::conjunction_v<QTypeTraits::has_ostream_operator<QDebug, T>...>, QDebug>;
288
289template<typename Container, typename ...T>
290using QDebugIfHasDebugStreamContainer =
291 std::enable_if_t<std::conjunction_v<QTypeTraits::has_ostream_operator_container<QDebug, Container, T>...>, QDebug>;
292
293#ifndef Q_QDOC
294
295template<typename T>
296inline QDebugIfHasDebugStreamContainer<QList<T>, T> operator<<(QDebug debug, const QList<T> &vec)
297{
298 return QtPrivate::printSequentialContainer(debug, "QList", vec);
299}
300
301template<typename T, qsizetype P>
302inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const QVarLengthArray<T, P> &vec)
303{
304 return QtPrivate::printSequentialContainer(debug, "QVarLengthArray", vec);
305}
306
307template <typename T, typename Alloc>
308inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const std::vector<T, Alloc> &vec)
309{
310 return QtPrivate::printSequentialContainer(debug, "std::vector", vec);
311}
312
313template <typename T, typename Alloc>
314inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const std::list<T, Alloc> &vec)
315{
316 return QtPrivate::printSequentialContainer(debug, "std::list", vec);
317}
318
319template <typename T>
320inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, std::initializer_list<T> list)
321{
322 return QtPrivate::printSequentialContainer(debug, "std::initializer_list", list);
323}
324
325template <typename Key, typename T, typename Compare, typename Alloc>
326inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug, const std::map<Key, T, Compare, Alloc> &map)
327{
328 return QtPrivate::printSequentialContainer(debug, "std::map", map); // yes, sequential: *it is std::pair
329}
330
331template <typename Key, typename T, typename Compare, typename Alloc>
332inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug, const std::multimap<Key, T, Compare, Alloc> &map)
333{
334 return QtPrivate::printSequentialContainer(debug, "std::multimap", map); // yes, sequential: *it is std::pair
335}
336
337template <class Key, class T>
338inline QDebugIfHasDebugStreamContainer<QMap<Key, T>, Key, T> operator<<(QDebug debug, const QMap<Key, T> &map)
339{
340 return QtPrivate::printAssociativeContainer(debug, "QMap", map);
341}
342
343template <class Key, class T>
344inline QDebugIfHasDebugStreamContainer<QMultiMap<Key, T>, Key, T> operator<<(QDebug debug, const QMultiMap<Key, T> &map)
345{
346 return QtPrivate::printAssociativeContainer(debug, "QMultiMap", map);
347}
348
349template <class Key, class T>
350inline QDebugIfHasDebugStreamContainer<QHash<Key, T>, Key, T> operator<<(QDebug debug, const QHash<Key, T> &hash)
351{
352 return QtPrivate::printAssociativeContainer(debug, "QHash", hash);
353}
354
355template <class Key, class T>
356inline QDebugIfHasDebugStreamContainer<QMultiHash<Key, T>, Key, T> operator<<(QDebug debug, const QMultiHash<Key, T> &hash)
357{
358 return QtPrivate::printAssociativeContainer(debug, "QMultiHash", hash);
359}
360
361template <class T1, class T2>
362inline QDebugIfHasDebugStream<T1, T2> operator<<(QDebug debug, const std::pair<T1, T2> &pair)
363{
364 const QDebugStateSaver saver(debug);
365 debug.nospace() << "std::pair(" << pair.first << ',' << pair.second << ')';
366 return debug;
367}
368
369template <typename T>
370inline QDebugIfHasDebugStreamContainer<QSet<T>, T> operator<<(QDebug debug, const QSet<T> &set)
371{
372 return QtPrivate::printSequentialContainer(debug, "QSet", set);
373}
374
375template <class T>
376inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const QContiguousCache<T> &cache)
377{
378 const QDebugStateSaver saver(debug);
379 debug.nospace() << "QContiguousCache(";
380 for (qsizetype i = cache.firstIndex(); i <= cache.lastIndex(); ++i) {
381 debug << cache[i];
382 if (i != cache.lastIndex())
383 debug << ", ";
384 }
385 debug << ')';
386 return debug;
387}
388
389#else
390template <class T>
391QDebug operator<<(QDebug debug, const QList<T> &list);
392
393template <class T, qsizetype P>
394QDebug operator<<(QDebug debug, const QVarLengthArray<T, P> &array);
395
396template <typename T, typename Alloc>
397QDebug operator<<(QDebug debug, const std::vector<T, Alloc> &vec);
398
399template <typename T, typename Alloc>
400QDebug operator<<(QDebug debug, const std::list<T, Alloc> &vec);
401
402template <typename Key, typename T, typename Compare, typename Alloc>
403QDebug operator<<(QDebug debug, const std::map<Key, T, Compare, Alloc> &map);
404
405template <typename Key, typename T, typename Compare, typename Alloc>
406QDebug operator<<(QDebug debug, const std::multimap<Key, T, Compare, Alloc> &map);
407
408template <class Key, class T>
409QDebug operator<<(QDebug debug, const QMap<Key, T> &map);
410
411template <class Key, class T>
412QDebug operator<<(QDebug debug, const QMultiMap<Key, T> &map);
413
414template <class Key, class T>
415QDebug operator<<(QDebug debug, const QHash<Key, T> &hash);
416
417template <class Key, class T>
418QDebug operator<<(QDebug debug, const QMultiHash<Key, T> &hash);
419
420template <typename T>
421QDebug operator<<(QDebug debug, const QSet<T> &set);
422
423template <class T1, class T2>
424QDebug operator<<(QDebug debug, const QPair<T1, T2> &pair);
425
426template <class T1, class T2>
427QDebug operator<<(QDebug debug, const std::pair<T1, T2> &pair);
428
429template <typename T>
430QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache);
431
432#endif // Q_QDOC
433
434template <class T>
435inline QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr)
436{
437 QDebugStateSaver saver(debug);
438 debug.nospace() << "QSharedPointer(" << ptr.data() << ")";
439 return debug;
440}
441
442template <typename T, typename Tag> class QTaggedPointer;
443
444template <typename T, typename Tag>
445inline QDebug operator<<(QDebug debug, const QTaggedPointer<T, Tag> &ptr)
446{
447 QDebugStateSaver saver(debug);
448 debug.nospace() << "QTaggedPointer(" << ptr.pointer() << ", " << ptr.tag() << ")";
449 return debug;
450}
451
452Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, int value);
453
454template <typename Int>
455void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, Int value)
456{
457 const QDebugStateSaver saver(debug);
458 debug.resetFormat();
459 debug.nospace() << "QFlags(" << Qt::hex << Qt::showbase;
460 bool needSeparator = false;
461 for (size_t i = 0; i < sizeofT * 8; ++i) {
462 if (value & (Int(1) << i)) {
463 if (needSeparator)
464 debug << '|';
465 else
466 needSeparator = true;
467 debug << (Int(1) << i);
468 }
469 }
470 debug << ')';
471}
472
473#if !defined(QT_NO_QOBJECT) && !defined(Q_QDOC)
474Q_CORE_EXPORT QDebug qt_QMetaEnum_debugOperator(QDebug&, qint64 value, const QMetaObject *meta, const char *name);
475Q_CORE_EXPORT QDebug qt_QMetaEnum_flagDebugOperator(QDebug &dbg, quint64 value, const QMetaObject *meta, const char *name);
476
477template<typename T>
478typename std::enable_if<QtPrivate::IsQEnumHelper<T>::Value, QDebug>::type
479operator<<(QDebug dbg, T value)
480{
481 const QMetaObject *obj = qt_getEnumMetaObject(value);
482 const char *name = qt_getEnumName(value);
483 return qt_QMetaEnum_debugOperator(dbg, static_cast<typename std::underlying_type<T>::type>(value), obj, name);
484}
485
486template<typename T,
487 typename A = typename std::enable_if<std::is_enum<T>::value, void>::type,
488 typename B = typename std::enable_if<sizeof(T) <= sizeof(int), void>::type,
489 typename C = typename std::enable_if<!QtPrivate::IsQEnumHelper<T>::Value, void>::type,
490 typename D = typename std::enable_if<QtPrivate::IsQEnumHelper<QFlags<T>>::Value, void>::type>
491inline QDebug operator<<(QDebug dbg, T value)
492{
493 typedef QFlags<T> FlagsT;
494 const QMetaObject *obj = qt_getEnumMetaObject(FlagsT());
495 const char *name = qt_getEnumName(FlagsT());
496 return qt_QMetaEnum_debugOperator(dbg, typename FlagsT::Int(value), obj, name);
497}
498
499template <class T>
500inline typename std::enable_if<
501 QtPrivate::IsQEnumHelper<T>::Value || QtPrivate::IsQEnumHelper<QFlags<T> >::Value,
502 QDebug>::type
503qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags)
504{
505 const QMetaObject *obj = qt_getEnumMetaObject(T());
506 const char *name = qt_getEnumName(T());
507 return qt_QMetaEnum_flagDebugOperator(debug, flags.toInt(), obj, name);
508}
509
510template <class T>
511inline typename std::enable_if<
512 !QtPrivate::IsQEnumHelper<T>::Value && !QtPrivate::IsQEnumHelper<QFlags<T> >::Value,
513 QDebug>::type
514qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags)
515#else // !QT_NO_QOBJECT && !Q_QDOC
516template <class T>
517inline QDebug qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags)
518#endif
519{
520 qt_QMetaEnum_flagDebugOperator(debug, sizeof(T), typename QFlags<T>::Int(flags));
521 return debug;
522}
523
524template<typename T>
525inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
526{
527 // We have to use an indirection otherwise specialisation of some other overload of the
528 // operator<< the compiler would try to instantiate QFlags<T> for the std::enable_if
529 return qt_QMetaEnum_flagDebugOperator_helper(debug, flags);
530}
531
532inline QDebug operator<<(QDebug debug, QKeyCombination combination)
533{
534 QDebugStateSaver saver(debug);
535 debug.nospace() << "QKeyCombination("
536 << combination.keyboardModifiers()
537 << ", "
538 << combination.key()
539 << ")";
540 return debug;
541}
542
543#ifdef Q_OS_DARWIN
544
545// We provide QDebug stream operators for commonly used Core Foundation
546// and Core Graphics types, as well as NSObject. Additional CF/CG types
547// may be added by the user, using Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE.
548
549#define QT_FOR_EACH_CORE_FOUNDATION_TYPE(F) \
550 F(CFArray) \
551 F(CFURL) \
552 F(CFData) \
553 F(CFNumber) \
554 F(CFDictionary) \
555 F(CFLocale) \
556 F(CFDate) \
557 F(CFBoolean) \
558 F(CFTimeZone) \
559
560#define QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(F) \
561 F(CFError) \
562 F(CFBundle) \
563
564#define QT_FOR_EACH_CORE_GRAPHICS_TYPE(F) \
565 F(CGPath) \
566
567#define QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(F) \
568 F(CGColorSpace) \
569 F(CGImage) \
570 F(CGFont) \
571 F(CGColor) \
572
573#define QT_FORWARD_DECLARE_CF_TYPE(type) Q_FORWARD_DECLARE_CF_TYPE(type);
574#define QT_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type);
575#define QT_FORWARD_DECLARE_CG_TYPE(type) Q_FORWARD_DECLARE_CG_TYPE(type);
576#define QT_FORWARD_DECLARE_MUTABLE_CG_TYPE(type) Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(type);
577
578QT_END_NAMESPACE
579Q_FORWARD_DECLARE_CF_TYPE(CFString);
580struct objc_object;
581Q_FORWARD_DECLARE_OBJC_CLASS(NSObject);
582QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_CF_TYPE)
583QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_MUTABLE_CF_TYPE)
584QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_CG_TYPE)
585QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_MUTABLE_CG_TYPE)
586QT_BEGIN_NAMESPACE
587
588#define QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType) \
589 Q_CORE_EXPORT QDebug operator<<(QDebug, CFType##Ref);
590
591#define Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType) \
592 QDebug operator<<(QDebug debug, CFType##Ref ref) \
593 { \
594 if (!ref) \
595 return debug << QT_STRINGIFY(CFType) "Ref(0x0)"; \
596 if (CFStringRef description = CFCopyDescription(ref)) { \
597 QDebugStateSaver saver(debug); \
598 debug.noquote() << description; \
599 CFRelease(description); \
600 } \
601 return debug; \
602 }
603
604// Defined in qcore_mac_objc.mm
605#if defined(__OBJC__)
606Q_CORE_EXPORT QDebug operator<<(QDebug, id);
607#endif
608Q_CORE_EXPORT QDebug operator<<(QDebug, objc_object *);
609Q_CORE_EXPORT QDebug operator<<(QDebug, const NSObject *);
610Q_CORE_EXPORT QDebug operator<<(QDebug, CFStringRef);
611
612QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
613QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
614QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
615QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
616
617#undef QT_FORWARD_DECLARE_CF_TYPE
618#undef QT_FORWARD_DECLARE_MUTABLE_CF_TYPE
619#undef QT_FORWARD_DECLARE_CG_TYPE
620#undef QT_FORWARD_DECLARE_MUTABLE_CG_TYPE
621
622#endif // Q_OS_DARWIN
623
624QT_END_NAMESPACE
625
626#endif // QDEBUG_H
627

source code of qtbase/src/corelib/io/qdebug.h