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
qqmljsfixedpoolarray_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
QQMLJSFIXEDPOOLARRAY_P_H
6
#
define
QQMLJSFIXEDPOOLARRAY_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
/
qglobal
.
h
>
20
#
include
<
private
/
qqmljsmemorypool_p
.
h
>
21
22
QT_BEGIN_NAMESPACE
23
24
namespace
QQmlJS
{
25
26
template
<
typename
T>
27
class
FixedPoolArray
28
{
29
T *data;
30
int
count = 0;
31
32
public
:
33
FixedPoolArray
()
34
: data(
nullptr
)
35
{}
36
37
FixedPoolArray
(MemoryPool *pool,
int
size)
38
{ allocate(pool, size); }
39
40
void
allocate
(MemoryPool *pool,
int
size)
41
{
42
count = size;
43
data =
reinterpret_cast
<T*>(pool->allocate(count *
sizeof
(T)));
44
}
45
46
void
allocate
(MemoryPool *pool,
const
QList<T> &vector)
47
{
48
count = vector.size();
49
data =
reinterpret_cast
<T*>(pool->allocate(count *
sizeof
(T)));
50
51
if
(QTypeInfo<T>::isComplex) {
52
for
(
int
i = 0; i < count; ++i)
53
new
(data + i) T(vector.at(i));
54
}
else
if
(count) {
55
memcpy(data,
static_cast
<
const
void
*>(vector.constData()), count *
sizeof
(T));
56
}
57
}
58
59
template
<
typename
Container>
60
void
allocate
(MemoryPool *pool,
const
Container &container)
61
{
62
count = container.size();
63
data =
reinterpret_cast
<T*>(pool->allocate(count *
sizeof
(T)));
64
typename
Container::ConstIterator it = container.constBegin();
65
for
(
int
i = 0; i < count; ++i)
66
new
(data + i) T(*it++);
67
}
68
69
int
size
()
const
70
{
return
count; }
71
72
const
T &
at
(
int
index)
const
{
73
Q_ASSERT(index >= 0 && index < count);
74
return
data[index];
75
}
76
77
T &
at
(
int
index) {
78
Q_ASSERT(index >= 0 && index < count);
79
return
data[index];
80
}
81
82
T &
operator
[](
int
index) {
83
return
at(index);
84
}
85
86
87
int
indexOf
(
const
T &value)
const
{
88
for
(
int
i = 0; i < count; ++i)
89
if
(data[i] == value)
90
return
i;
91
return
-1;
92
}
93
94
const
T *
begin
()
const
{
return
data; }
95
const
T *
end
()
const
{
return
data + count; }
96
97
T *
begin
() {
return
data; }
98
T *
end
() {
return
data + count; }
99
};
100
101
}
// namespace QQmlJS
102
103
QT_END_NAMESPACE
104
105
#
endif
// QQMLJSFIXEDPOOLARRAY_P_H
QQmlJS::FixedPoolArray
Definition
qqmljsfixedpoolarray_p.h:28
QQmlJS::FixedPoolArray::end
const T * end() const
Definition
qqmljsfixedpoolarray_p.h:95
QQmlJS::FixedPoolArray::at
const T & at(int index) const
Definition
qqmljsfixedpoolarray_p.h:72
QQmlJS::FixedPoolArray::allocate
void allocate(MemoryPool *pool, const QList< T > &vector)
Definition
qqmljsfixedpoolarray_p.h:46
QQmlJS::FixedPoolArray::allocate
void allocate(MemoryPool *pool, int size)
Definition
qqmljsfixedpoolarray_p.h:40
QQmlJS::FixedPoolArray::FixedPoolArray
FixedPoolArray()
Definition
qqmljsfixedpoolarray_p.h:33
QQmlJS::FixedPoolArray::operator[]
T & operator[](int index)
Definition
qqmljsfixedpoolarray_p.h:82
QQmlJS::FixedPoolArray::begin
T * begin()
Definition
qqmljsfixedpoolarray_p.h:97
QQmlJS::FixedPoolArray::begin
const T * begin() const
Definition
qqmljsfixedpoolarray_p.h:94
QQmlJS::FixedPoolArray::allocate
void allocate(MemoryPool *pool, const Container &container)
Definition
qqmljsfixedpoolarray_p.h:60
QQmlJS::FixedPoolArray::indexOf
int indexOf(const T &value) const
Definition
qqmljsfixedpoolarray_p.h:87
QQmlJS::FixedPoolArray::at
T & at(int index)
Definition
qqmljsfixedpoolarray_p.h:77
QQmlJS::FixedPoolArray::end
T * end()
Definition
qqmljsfixedpoolarray_p.h:98
QQmlJS::FixedPoolArray::size
int size() const
Definition
qqmljsfixedpoolarray_p.h:69
QQmlJS::FixedPoolArray::FixedPoolArray
FixedPoolArray(MemoryPool *pool, int size)
Definition
qqmljsfixedpoolarray_p.h:37
QQmlJS
Definition
qv4bytecodegenerator_p.h:27
qtdeclarative
src
qml
common
qqmljsfixedpoolarray_p.h
Generated on
for Qt by
1.18.0