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