Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qrecursionwatcher_p.h
Go to the documentation of this file.
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// Qt-Security score:significant
4
5#ifndef QRECURSIONWATCHER_P_H
6#define QRECURSIONWATCHER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/private/qglobal_p.h>
20
21QT_BEGIN_NAMESPACE
22
23class QRecursionNode;
25public:
26 inline QRecursionNode();
27 bool *_r;
28};
29
30template<class T, QRecursionNode T::*Node>
32public:
33 inline QRecursionWatcher(T *);
35 inline bool hasRecursed() const;
36private:
37 T *_t;
38 bool _r;
39};
40
42: _r(nullptr)
43{
44}
45
46template<class T, QRecursionNode T::*Node>
47QRecursionWatcher<T, Node>::QRecursionWatcher(T *t)
48: _t(t), _r(false)
49{
50 if ((_t->*Node)._r) *(_t->*Node)._r = true;
51 (_t->*Node)._r = &_r;
52}
53
54template<class T, QRecursionNode T::*Node>
55QRecursionWatcher<T, Node>::~QRecursionWatcher()
56{
57 if ((_t->*Node)._r == &_r) (_t->*Node)._r = nullptr;
58}
59
60template<class T, QRecursionNode T::*Node>
61bool QRecursionWatcher<T, Node>::hasRecursed() const
62{
63 return _r;
64}
65
66QT_END_NAMESPACE
67
68#endif // QRECURSIONWATCHER_P_H