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
q_pmr_emulation_p.h
Go to the documentation of this file.
1
// Copyright (C) 2025 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
Q_PMR_EMULATION_P_H
5
#
define
Q_PMR_EMULATION_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
/
qtconfigmacros
.
h
>
19
20
#
if
defined
(
__APPLE__
)
21
// minimum requirement: iOS 17.0, macOS 14.0, watchOS 10.0 and tvOS 17.0.
22
#
include
<
Availability
.
h
>
23
#
if
!
_LIBCPP_AVAILABILITY_HAS_PMR
24
#
define
QT_MM_PMR_EMULATION
25
#
endif
26
#
endif
27
28
#
if
defined
(
Q_OS_VXWORKS
)
29
// std::pmr::deque<variant> doesn't seem to compile on VxWorks, so we use our emulation
30
#
define
QT_MM_PMR_EMULATION
31
#
endif
32
33
#
if
!
__has_include
(
<
memory_resource
>
)
34
#
define
QT_MM_PMR_EMULATION
35
#
endif
36
37
#
ifdef
QT_MM_PMR_EMULATION
38
39
#
include
<
QtCore
/
qassert
.
h
>
40
41
#
include
<
cstddef
>
42
#
include
<
new
>
43
#
include
<
typeinfo
>
44
45
#
else
46
47
#
include
<
memory_resource
>
48
49
#
endif
50
51
#
include
<
map
>
52
#
include
<
vector
>
53
54
QT_BEGIN_NAMESPACE
55
56
namespace
QtMultimediaPrivate
::
pmr
{
57
58
#
ifndef
QT_MM_PMR_EMULATION
59
60
using
memory_resource =
std
::pmr::memory_resource;
61
template
<
typename
T =
std
::byte>
62
using
polymorphic_allocator =
std
::pmr::polymorphic_allocator<T>;
63
64
inline
auto
get_default_resource()
noexcept
65
{
66
return
std
::pmr::get_default_resource();
67
}
68
69
inline
auto
new_delete_resource()
noexcept
70
{
71
return
std
::pmr::new_delete_resource();
72
}
73
74
#
else
75
76
class
memory_resource
;
77
memory_resource
*
get_default_resource
()
noexcept
;
78
memory_resource
*
new_delete_resource
()
noexcept
;
79
80
class
memory_resource
81
{
82
public
:
83
memory_resource
() =
default
;
84
memory_resource
(
const
memory_resource
&) =
delete
;
85
memory_resource
&
operator
=(
const
memory_resource
&) =
delete
;
86
virtual
~
memory_resource
()
noexcept
=
default
;
87
88
[[
nodiscard
]]
89
void
*
allocate
(
size_t
bytes
,
size_t
alignment
=
alignof
(
std
::
max_align_t
))
90
{
91
return
do_allocate
(
bytes
,
alignment
);
92
}
93
94
void
deallocate
(
void
*
p
,
size_t
bytes
,
size_t
alignment
=
alignof
(
std
::
max_align_t
))
95
{
96
do_deallocate
(
p
,
bytes
,
alignment
);
97
}
98
99
bool
is_equal
(
const
memory_resource
&
other
)
const
noexcept
{
return
do_is_equal
(
other
); }
100
101
protected
:
102
virtual
void
*
do_allocate
(
size_t
bytes
,
size_t
alignment
) = 0;
103
virtual
void
do_deallocate
(
void
*
p
,
size_t
bytes
,
size_t
alignment
) = 0;
104
virtual
bool
do_is_equal
(
const
memory_resource
&
other
)
const
noexcept
{
return
this
== &
other
; }
105
106
private
:
107
template
<
class
T
>
108
friend
class
polymorphic_allocator
;
109
};
110
111
inline
bool
operator
==(
const
memory_resource
&
a
,
const
memory_resource
&
b
)
noexcept
112
{
113
return
&
a
== &
b
||
a
.
is_equal
(
b
);
114
}
115
116
inline
bool
operator
!=(
const
memory_resource
&
a
,
const
memory_resource
&
b
)
noexcept
117
{
118
return
!(
a
==
b
);
119
}
120
121
template
<
class
T
>
122
class
polymorphic_allocator
123
{
124
public
:
125
using
value_type
=
T
;
126
127
polymorphic_allocator
()
noexcept
=
default
;
128
polymorphic_allocator
(
memory_resource
*
r
) :
m_resource
(
r
) {
Q_ASSERT
(
r
); }
129
polymorphic_allocator
(
const
polymorphic_allocator
&
other
)
noexcept
=
default
;
130
131
template
<
class
U
>
132
polymorphic_allocator
(
const
polymorphic_allocator
<
U
> &
other
)
noexcept
133
:
m_resource
(
other
.
resource
())
134
{
135
}
136
137
polymorphic_allocator
&
operator
=(
const
polymorphic_allocator
&
other
)
noexcept
=
default
;
138
139
[[
nodiscard
]]
140
T
*
allocate
(
size_t
n
)
141
{
142
void
*
ptr
=
m_resource
->
allocate
(
n
*
sizeof
(
T
),
alignof
(
T
));
143
return
static_cast
<
T
*>(
ptr
);
144
}
145
146
void
deallocate
(
T
*
p
,
size_t
n
) {
m_resource
->
deallocate
(
p
,
n
*
sizeof
(
T
),
alignof
(
T
)); }
147
148
[[
nodiscard
]]
149
memory_resource
*
resource
()
const
noexcept
150
{
151
return
m_resource
;
152
}
153
154
[[
nodiscard
]]
155
polymorphic_allocator
select_on_container_copy_construction
()
const
156
{
157
return
polymorphic_allocator
();
158
}
159
160
private
:
161
memory_resource
*
m_resource
=
get_default_resource
();
162
};
163
164
template
<
class
T1
,
class
T2
>
165
bool
operator
==(
const
polymorphic_allocator
<
T1
> &
a
,
const
polymorphic_allocator
<
T2
> &
b
)
noexcept
166
{
167
return
*
a
.
resource
() == *
b
.
resource
();
168
}
169
170
template
<
class
T1
,
class
T2
>
171
bool
operator
!=(
const
polymorphic_allocator
<
T1
> &
a
,
const
polymorphic_allocator
<
T2
> &
b
)
noexcept
172
{
173
return
!(
a
==
b
);
174
}
175
176
namespace
detail
{
177
178
class
new_delete_resource_impl
final
:
public
memory_resource
179
{
180
public
:
181
using
memory_resource
::
memory_resource
;
182
183
protected
:
184
void
*
do_allocate
(
size_t
bytes
,
size_t
alignment
)
override
185
{
186
return
::
operator
new
(
bytes
,
static_cast
<
std
::
align_val_t
>(
alignment
));
187
}
188
189
void
do_deallocate
(
void
*
p
, [[
maybe_unused
]]
size_t
bytes
,
size_t
alignment
)
override
190
{
191
#
ifdef
__cpp_sized_deallocation
192
::
operator
delete
(
p
,
bytes
,
static_cast
<
std
::
align_val_t
>(
alignment
));
193
#
else
194
::
operator
delete
(
p
,
static_cast
<
std
::
align_val_t
>(
alignment
));
195
#
endif
196
}
197
198
bool
do_is_equal
(
const
memory_resource
&
other
)
const
noexcept
override
199
{
200
return
&
other
==
this
||
typeid
(
other
) ==
typeid
(
new_delete_resource_impl
);
201
}
202
};
203
204
}
// namespace detail
205
206
inline
memory_resource
*
new_delete_resource
()
noexcept
207
{
208
static
detail
::
new_delete_resource_impl
instance
;
209
return
&
instance
;
210
}
211
212
inline
memory_resource
*
get_default_resource
()
noexcept
213
{
214
return
new_delete_resource
();
215
}
216
217
#
endif
218
219
template
<
typename
T
>
220
using
vector
=
std
::
vector
<
T
,
polymorphic_allocator
<
T
>>;
221
222
template
<
typename
K
,
typename
V
,
typename
C
=
std
::
less
<
K
>>
223
using
map
=
std
::
map
<
K
,
V
,
C
,
polymorphic_allocator
<
std
::
pair
<
const
K
,
V
>>>;
224
225
}
// namespace QtMultimediaPrivate::pmr
226
227
QT_END_NAMESPACE
228
229
#
ifdef
QT_MM_PMR_EMULATION
230
#
undef
QT_MM_PMR_EMULATION
231
#
endif
// QT_MM_PMR_EMULATION
232
233
#
endif
// Q_PMR_EMULATION_P_H
QtMultimediaPrivate::pmr
Definition
q_pmr_emulation_p.h:56
QtMultimediaPrivate
Definition
qaudiosystem_p.h:51
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
__has_include
#define __has_include(x)
Definition
qcompilerdetection.h:459
qtmultimedia
src
multimedia
audio
q_pmr_emulation_p.h
Generated on
for Qt by
1.16.1