Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qtmm_alignment_support_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
QTMM_ALIGNMENT_SUPPORT_P_H
5
#
define
QTMM_ALIGNMENT_SUPPORT_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
/
qglobal
.
h
>
19
20
QT_BEGIN_NAMESPACE
21
22
namespace
QtMultimediaPrivate
{
23
24
template
<
typename
IntType>
25
inline
constexpr
bool
isPowerOfTwo
(IntType arg)
26
{
27
return
arg > 0 && (arg & (arg - 1)) == 0;
28
}
29
30
template
<
typename
Type>
31
constexpr
Type
alignUp
(Type arg, size_t alignment)
32
{
33
if
constexpr
(std::is_pointer_v<Type>) {
34
return
Type(alignUp(std::intptr_t(arg), alignment));
35
}
else
{
36
Q_ASSERT(isPowerOfTwo(alignment));
37
return
Type((arg + (Type(alignment) - 1)) & ~Type(alignment - 1));
38
}
39
}
40
41
template
<
typename
Type>
42
constexpr
Type
alignDown
(Type arg, size_t alignment)
43
{
44
if
constexpr
(std::is_pointer_v<Type>) {
45
return
Type(alignDown(std::intptr_t(arg), alignment));
46
}
else
{
47
Q_ASSERT(isPowerOfTwo(alignment));
48
return
arg & ~Type(alignment - 1);
49
}
50
}
51
52
template
<
typename
IntType>
53
constexpr
bool
isAligned
(IntType arg, size_t alignment)
54
{
55
if
constexpr
(std::is_pointer_v<IntType>) {
56
return
isAligned(std::intptr_t(arg), alignment);
57
}
else
{
58
Q_ASSERT(isPowerOfTwo(alignment));
59
return
(arg & (IntType(alignment) - 1)) == 0;
60
}
61
}
62
63
}
// namespace QtMultimediaPrivate
64
65
QT_END_NAMESPACE
66
67
#
endif
// QTMM_ALIGNMENT_SUPPORT_P_H
QtMultimediaPrivate::impl
Definition
qaudiosystem_p.h:257
QtMultimediaPrivate::alignUp
constexpr Type alignUp(Type arg, size_t alignment)
Definition
qtmm_alignment_support_p.h:31
QtMultimediaPrivate::isPowerOfTwo
constexpr bool isPowerOfTwo(IntType arg)
Definition
qtmm_alignment_support_p.h:25
QtMultimediaPrivate::isAligned
constexpr bool isAligned(IntType arg, size_t alignment)
Definition
qtmm_alignment_support_p.h:53
QtMultimediaPrivate::alignDown
constexpr Type alignDown(Type arg, size_t alignment)
Definition
qtmm_alignment_support_p.h:42
qtmultimedia
src
multimedia
support
qtmm_alignment_support_p.h
Generated on
for Qt by
1.18.0