Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
btraii_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 BTRAII_P_H
5#define BTRAII_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
20#include <utility>
21
23
24namespace DarwinBluetooth {
25
26enum class RetainPolicy
27{
30};
31
32// The class StrongReference and its descendant ScopedGuard
33// are RAII classes dealing with raw pointers to NSObject class
34// and its descendants (and thus hiding Objective-C's retain/
35// release semantics). The header itself is meant to be included
36// into *.cpp files so it's a pure C++ code without any Objective-C
37// syntax. Thus it's a bit clunky - the type information is 'erased'
38// and has to be enforced by the code using these smart pointers.
39// That's because these types are Objective-C classes - thus require
40// Objective-C compiler to work. Member-function template 'getAs' is
41// a convenience shortcut giving the desired pointer type in
42// Objective-C++ files (*.mm).
44{
45public:
46 StrongReference() = default;
47 StrongReference(void *object, RetainPolicy policy);
50
52
55
56 void swap(StrongReference &other) noexcept
57 {
58 std::swap(objCInstance, other.objCInstance);
59 }
60
61 void *release();
62
63 void reset();
64 void reset(void *newInstance, RetainPolicy policy);
65
66 template<class ObjCType>
67 ObjCType *getAs() const
68 {
69 return static_cast<ObjCType *>(objCInstance);
70 }
71
72 operator bool() const
73 {
74 return !!objCInstance;
75 }
76
77private:
78 void *objCInstance = nullptr;
79};
80
81class ScopedPointer final : public StrongReference
82{
83public:
84 ScopedPointer() = default;
86 : StrongReference(instance, policy)
87 {
88 }
89
90private:
91 Q_DISABLE_COPY_MOVE(ScopedPointer)
92};
93
94} // namespace DarwinBluetooth
95
97
98#endif // BTRAII_P_H
ScopedPointer(void *instance, RetainPolicy policy)
Definition btraii_p.h:85
ObjCType * getAs() const
Definition btraii_p.h:67
StrongReference & operator=(const StrongReference &other) noexcept
Definition btraii.mm:39
void swap(StrongReference &other) noexcept
Definition btraii_p.h:56
Combined button and popup list for selecting options.
QSharedPointer< T > other(t)
[5]
QSizePolicy policy