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