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
qssgdataref_p.h
Go to the documentation of this file.
1// Copyright (C) 2008-2012 NVIDIA Corporation.
2// Copyright (C) 2019 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6
7#ifndef QSSGDATAREF_H
8#define QSSGDATAREF_H
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. It exists purely as an
15// implementation detail. This header file may change from version to
16// version without notice, or even be removed.
17//
18// We mean it.
19//
20
21#include <QtQuick3DUtils/private/qtquick3dutilsglobal_p.h>
22
23#include <QtCore/qlist.h>
24#include <QtCore/qbytearray.h>
25
26QT_BEGIN_NAMESPACE
27
28template<typename T>
29struct QSSGDataView
30{
31 const T *mData;
32 qsizetype mSize;
33
34 explicit QSSGDataView(const QList<T> &data) : mData(data.constData()), mSize(data.size()) { Q_ASSERT(mSize >= 0); }
35 template <qsizetype N>
36 explicit QSSGDataView(const QVarLengthArray<T, N> &data) : mData(data.constData()), mSize(data.size()) { Q_ASSERT(mSize >= 0); }
37 QSSGDataView(const T *inData, qsizetype inSize) : mData(inData), mSize(inSize) { Q_ASSERT(mSize >= 0); }
38 constexpr QSSGDataView() : mData(nullptr), mSize(0) {}
39
40 qsizetype size() const { return mSize; }
41
42 const T *begin() const { return mData; }
43 const T *end() const { return mData + mSize; }
44
45 const T& first() const { Q_ASSERT(!isEmpty()); return *begin(); }
46 const T& last() const { Q_ASSERT(!isEmpty()); return *(end()-1); }
47
48 const T &operator[](int index) const
49 {
50 Q_ASSERT(index > -1);
51 Q_ASSERT(index < mSize);
52 return mData[index];
53 }
54
55 bool isEmpty() const { return (mSize == 0); }
56
57 void clear()
58 {
59 mData = nullptr;
60 mSize = 0;
61 }
62
63 operator const void *() { return reinterpret_cast<const void *>(mData); }
64};
65
66template<>
68{
69 const quint8 *mData;
71
72 explicit QSSGDataView(const QByteArray &data)
73 : mData(reinterpret_cast<const quint8 *>(data.constBegin())), mSize(data.size())
74 { Q_ASSERT(mSize >= 0); }
75 template<typename T>
76 explicit QSSGDataView(const QList<T> &data)
77 : mData(reinterpret_cast<const quint8 *>(data.constData())), mSize(data.size()*sizeof(T))
78 { Q_ASSERT(mSize >= 0); }
79 QSSGDataView(const quint8 *inData, qsizetype inSize) : mData(inData), mSize(inSize) { Q_ASSERT(mSize >= 0); }
80 template<typename T>
81 QSSGDataView(const T *inData, qsizetype inSize)
82 : mData(reinterpret_cast<const quint8 *>(inData)), mSize(inSize*sizeof(T))
83 { Q_ASSERT(mSize >= 0); }
84 constexpr QSSGDataView() : mData(nullptr), mSize(0) {}
85
86 qsizetype size() const { return mSize; }
87 bool isEmpty() const { return (mSize == 0); }
88
89 const quint8 *begin() const { return mData; }
90 const quint8 *end() const { return mData + mSize; }
91
92 const quint8 &operator[](int index) const
93 {
94 Q_ASSERT(index > -1);
95 Q_ASSERT(index < mSize);
96 return mData[index];
97 }
98
99 void clear()
100 {
101 mData = nullptr;
102 mSize = 0;
103 }
104
105 operator const void *() { return reinterpret_cast<const void *>(mData); }
106};
107
109
110template<typename T>
111inline QSSGDataView<T> toDataView(const T &type)
112{
113 return QSSGDataView<T>(&type, 1);
114}
115
116template<typename T>
117inline QSSGDataView<T> toDataView(const QList<T> &type)
118{
119 return QSSGDataView<T>(type);
120}
121
122template<typename T>
123inline QSSGByteView toByteView(const T &type)
124{
125 return QSSGByteView(&type, 1);
126}
127
128template<typename T>
129inline QSSGByteView toByteView(const QList<T> &type)
130{
131 return QSSGByteView(type);
132}
133
134template<>
135inline QSSGByteView toByteView(const QByteArray &type)
136{
137 return QSSGByteView(type);
138}
139
140inline QSSGByteView toByteView(const char *str)
141{
142 return QSSGByteView(str, qstrlen(str));
143}
144
145template<typename T>
146inline QSSGDataView<T> toDataView(const T *type, qsizetype count)
147{
148 return QSSGDataView<T>(type, count);
149}
150
151template<typename T>
152inline QSSGByteView toByteView(const T *type, qsizetype count)
153{
154 return QSSGByteView(type, count);
155}
156
157template<typename T>
159{
162
163 QSSGDataRef(T *inData, qsizetype inSize) : mData(inData), mSize(inSize) { Q_ASSERT(inSize >= 0); }
164 QSSGDataRef() : mData(nullptr), mSize(0) {}
165 qsizetype size() const { return mSize; }
166
167 T *begin() { return mData; }
168 T *end() { return mData + mSize; }
169
170 T *begin() const { return mData; }
171 T *end() const { return mData + mSize; }
172
173 T& first() { Q_ASSERT(!isEmpty()); return *begin(); }
174 T& last() { Q_ASSERT(!isEmpty()); return *(end()-1); }
175
176 const T &first() const { Q_ASSERT(!isEmpty()); return *begin(); }
177 const T &last() const { Q_ASSERT(!isEmpty()); return *(end()-1); }
178
179 bool isEmpty() const { return (mSize == 0); }
180
181 T &operator[](qsizetype index)
182 {
183 Q_ASSERT(index >= 0);
184 Q_ASSERT(index < mSize);
185 return mData[index];
186 }
187
188 const T &operator[](qsizetype index) const
189 {
190 Q_ASSERT(index >= 0);
191 Q_ASSERT(index < mSize);
192 return mData[index];
193 }
194
195 void clear()
196 {
197 mData = nullptr;
198 mSize = 0;
199 }
200
202 operator void *() { return reinterpret_cast<void *>(mData); }
203};
204
205using QSSGByteRef = QSSGDataRef<quint8>;
206
207template<typename T>
208inline QSSGDataRef<T> toDataRef(T &type)
209{
210 return QSSGDataRef<T>(&type, 1);
211}
212
213template<typename T>
214inline QSSGByteRef toByteRef(T &type)
215{
216 return QSSGByteRef(reinterpret_cast<quint8 *>(&type), sizeof(T));
217}
218
219template<typename T>
220inline QSSGDataRef<T> toDataRef(T *type, qsizetype count)
221{
222 return QSSGDataRef<T>(type, count);
223}
224
225template<typename T>
226inline QSSGByteRef toByteRef(T *type, qsizetype count)
227{
228 return QSSGByteRef(reinterpret_cast<quint8 *>(type), sizeof(T) * count);
229}
230
231QT_END_NAMESPACE
232
233#endif // QSSGDATAREF_H
Combined button and popup list for selecting options.
QSSGByteRef toByteRef(T &type)
QSSGByteView toByteView(const QList< T > &type)
QSSGByteView toByteView(const QByteArray &type)
QSSGByteView toByteView(const T &type)
QSSGByteView toByteView(const char *str)
QSSGDataRef< T > toDataRef(T *type, qsizetype count)
QSSGDataView< quint8 > QSSGByteView
QSSGByteRef toByteRef(T *type, qsizetype count)
QSSGByteView toByteView(const T *type, qsizetype count)
QSSGDataRef< T > toDataRef(T &type)
T * begin() const
T * end() const
qsizetype mSize
const T & first() const
qsizetype size() const
const T & last() const
bool isEmpty() const
const T & operator[](qsizetype index) const
T & operator[](qsizetype index)
QSSGDataRef(T *inData, qsizetype inSize)
const quint8 & operator[](int index) const
QSSGDataView(const QByteArray &data)
QSSGDataView(const T *inData, qsizetype inSize)
qsizetype size() const
QSSGDataView(const QList< T > &data)
QSSGDataView(const quint8 *inData, qsizetype inSize)
const quint8 * end() const
const quint8 * begin() const