1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QRECURSIONWATCHER_P_H
5#define QRECURSIONWATCHER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19
20QT_BEGIN_NAMESPACE
21
22class QRecursionNode;
23class QRecursionNode {
24public:
25 inline QRecursionNode();
26 bool *_r;
27};
28
29template<class T, QRecursionNode T::*Node>
30class QRecursionWatcher {
31public:
32 inline QRecursionWatcher(T *);
33 inline ~QRecursionWatcher();
34 inline bool hasRecursed() const;
35private:
36 T *_t;
37 bool _r;
38};
39
40QRecursionNode::QRecursionNode()
41: _r(nullptr)
42{
43}
44
45template<class T, QRecursionNode T::*Node>
46QRecursionWatcher<T, Node>::QRecursionWatcher(T *t)
47: _t(t), _r(false)
48{
49 if ((_t->*Node)._r) *(_t->*Node)._r = true;
50 (_t->*Node)._r = &_r;
51}
52
53template<class T, QRecursionNode T::*Node>
54QRecursionWatcher<T, Node>::~QRecursionWatcher()
55{
56 if ((_t->*Node)._r == &_r) (_t->*Node)._r = nullptr;
57}
58
59template<class T, QRecursionNode T::*Node>
60bool QRecursionWatcher<T, Node>::hasRecursed() const
61{
62 return _r;
63}
64
65QT_END_NAMESPACE
66
67#endif // QRECURSIONWATCHER_P_H
68

source code of qtdeclarative/src/qml/qml/ftw/qrecursionwatcher_p.h