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
qanimationjobutil_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QANIMATIONJOBUTIL_P_H
6#define QANIMATIONJOBUTIL_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/qcompilerdetection.h>
20#include <QtCore/qtconfigmacros.h>
21
22#include <type_traits>
23
25
26QT_BEGIN_NAMESPACE
27
28#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU_ONLY >= 1300
29# define ACTION_IF_DISABLE_DANGLING_POINTER_WARNING QT_WARNING_DISABLE_GCC("-Wdangling-pointer")
30#else
31# define ACTION_IF_DISABLE_DANGLING_POINTER_WARNING
32#endif
33
34// SelfDeletable is used for self-destruction detection along with
35// ACTION_IF_DELETED and RETURN_IF_DELETED macros. While using, the objects
36// under test should have a member m_selfDeletable of type SelfDeletable
37struct SelfDeletable {
38 ~SelfDeletable() {
39 if (m_wasDeleted)
40 *m_wasDeleted = true;
41 }
42 bool *m_wasDeleted = nullptr;
43};
44
45// \param p pointer to object under test, which should have a member m_selfDeletable of type SelfDeletable
46// \param func statements or functions that to be executed under test.
47// \param action post process if p was deleted under test.
48#define ACTION_IF_DELETED(p, func, action) do
49 {
50 QT_WARNING_PUSH
52 static_assert(std::is_same<decltype((p)->m_selfDeletable), SelfDeletable>::value, "m_selfDeletable must be SelfDeletable");
53 bool *prevWasDeleted = (p)->m_selfDeletable.m_wasDeleted;
54 bool wasDeleted = false;
55 (p)->m_selfDeletable.m_wasDeleted = &wasDeleted;
56 {func;}
57 if (wasDeleted) {
58 if (prevWasDeleted)
59 *prevWasDeleted = true;
60 {action;}
61 }
62 (p)->m_selfDeletable.m_wasDeleted = prevWasDeleted;
63 QT_WARNING_POP \
64}while (false)
65
66#define RETURN_IF_DELETED(func) ACTION_IF_DELETED
67 (this, func, return)
68
69QT_END_NAMESPACE
70
71#endif // QANIMATIONJOBUTIL_P_H
#define ACTION_IF_DISABLE_DANGLING_POINTER_WARNING
QT_REQUIRE_CONFIG(qml_animation)