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
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
4#ifndef QQMLJSFIXEDPOOLARRAY_P_H
5#define QQMLJSFIXEDPOOLARRAY_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#include <private/qqmljsmemorypool_p.h>
20
22
23namespace QQmlJS {
24
25template <typename T>
27{
28 T *data;
29 int count = 0;
30
31public:
35
38
40 {
41 count = size;
42 data = reinterpret_cast<T*>(pool->allocate(count * sizeof(T)));
43 }
44
45 void allocate(MemoryPool *pool, const QVector<T> &vector)
46 {
47 count = vector.size();
48 data = reinterpret_cast<T*>(pool->allocate(count * sizeof(T)));
49
51 for (int i = 0; i < count; ++i)
52 new (data + i) T(vector.at(i));
53 } else if (count) {
54 memcpy(data, static_cast<const void*>(vector.constData()), count * sizeof(T));
55 }
56 }
57
58 template <typename Container>
59 void allocate(MemoryPool *pool, const Container &container)
60 {
61 count = container.size();
62 data = reinterpret_cast<T*>(pool->allocate(count * sizeof(T)));
63 typename Container::ConstIterator it = container.constBegin();
64 for (int i = 0; i < count; ++i)
65 new (data + i) T(*it++);
66 }
67
68 int size() const
69 { return count; }
70
71 const T &at(int index) const {
72 Q_ASSERT(index >= 0 && index < count);
73 return data[index];
74 }
75
76 T &at(int index) {
77 Q_ASSERT(index >= 0 && index < count);
78 return data[index];
79 }
80
81 T &operator[](int index) {
82 return at(index);
83 }
84
85
86 int indexOf(const T &value) const {
87 for (int i = 0; i < count; ++i)
88 if (data[i] == value)
89 return i;
90 return -1;
91 }
92
93 const T *begin() const { return data; }
94 const T *end() const { return data + count; }
95
96 T *begin() { return data; }
97 T *end() { return data + count; }
98};
99
100} // namespace QQmlJS
101
103
104#endif // QQMLJSFIXEDPOOLARRAY_P_H
qsizetype size() const noexcept
Definition qlist.h:397
const_pointer constData() const noexcept
Definition qlist.h:433
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
const T & at(int index) const
void allocate(MemoryPool *pool, const QVector< T > &vector)
void allocate(MemoryPool *pool, int size)
void allocate(MemoryPool *pool, const Container &container)
int indexOf(const T &value) const
FixedPoolArray(MemoryPool *pool, int size)
const_iterator constBegin() const noexcept
Definition qset.h:139
QSet< QString >::iterator it
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QList< int > vector
[14]
QObject::connect nullptr
QAction * at