4#ifndef QARRAYDATAPOINTER_H
5#define QARRAYDATAPOINTER_H
7#include <QtCore/qarraydataops.h>
8#include <QtCore/qcontainertools_impl.h>
10#include <QtCore/q20functional.h>
11#include <QtCore/q20memory.h>
19 typedef QTypedArrayData<T> Data;
20 typedef QArrayDataOps<T> DataOps;
25 std::is_arithmetic<T>::value || std::is_pointer<T>::value || std::is_enum<T>::value
28 typedef typename std::conditional<pass_parameter_by_value, T, const T &>::type
parameter_type;
66 return {
nullptr,
const_cast<T *
>(rawData),
length };
78 :
d(std::exchange(
other.d,
nullptr)),
79 ptr(std::exchange(
other.ptr,
nullptr)),
86 DataOps &operator*() noexcept
88 return *
static_cast<DataOps *
>(
this);
93 return static_cast<DataOps *
>(
this);
98 return *
static_cast<const DataOps *
>(
this);
103 return static_cast<const DataOps *
>(
this);
109 (*this)->destroyAll();
120 const T *
data() const noexcept {
return ptr; }
161 if (
sizeof(T) !=
sizeof(X)) {
163 d->alloc =
d->alloc *
sizeof(T) /
sizeof(X);
165 auto od =
reinterpret_cast<QTypedArrayData<X> *
>(std::exchange(
d,
nullptr));
166 auto optr =
reinterpret_cast<X *
>(std::exchange(
ptr,
nullptr));
167 return { od, optr, std::exchange(
size, 0) };
197 bool readjusted =
false;
323 template <
typename InputIterator,
typename Projection = q20::
identity>
324 void assign(InputIterator
first, InputIterator last, Projection proj = {})
327 constexpr bool IsFwdIt = std::is_convertible_v<
328 typename std::iterator_traits<InputIterator>::iterator_category,
329 std::forward_iterator_tag>;
330 constexpr bool IsIdentity = std::is_same_v<Projection, q20::identity>;
332 if constexpr (IsFwdIt) {
346 const auto prependBufferEnd =
begin();
348 if constexpr (!std::is_nothrow_constructible_v<T,
decltype(std::invoke(proj, *
first))>) {
353 (*this)->truncate(0);
359 auto dst = capacityBegin;
360 const auto dend =
end();
370 if (
dst == prependBufferEnd) {
376 std::destroy(prependBufferEnd, dend);
389 std::destroy(
dst, dend);
393 if constexpr (IsFwdIt && IsIdentity) {
396 }
else if constexpr (IsFwdIt && !IsIdentity
397 && std::is_nothrow_constructible_v<T,
decltype(std::invoke(proj, *
first))>) {
403 (*this)->emplace(
size, std::invoke(proj, *
first));
404 }
while (++
first != last);
428 std::destroy(
begin(), newBeginning);
429 std::destroy(newBeginning +
n,
end());
432 return std::move(*
this);
438 void ref() noexcept {
if (
d)
d->ref(); }
439 bool deref() noexcept {
return !
d ||
d->deref(); }
441 bool isShared() const noexcept {
return !
d ||
d->isShared(); }
445 const typename Data::ArrayOptions
flags() const noexcept {
return d ?
d->flags : Data::ArrayOptionDefault; }
447 void clearFlag(
typename Data::ArrayOptions
f)
noexcept {
if (
d)
d->flags &=
~f; }
456 return this->
ptr - Data::dataStart(
d,
alignof(
typename Data::AlignmentDummy));
480 const bool valid =
header !=
nullptr && dataPtr !=
nullptr;
495 return lhs.data() == rhs.data() && lhs.size == rhs.size;
500 return lhs.data() != rhs.data() || lhs.size != rhs.size;
509inline void swap(QArrayDataPointer<T> &
p1, QArrayDataPointer<T> &
p2)
noexcept
521#define Q_ARRAY_LITERAL(Type, ...) \
522 ([]() -> QArrayDataPointer<Type> { \
523 static Type const data[] = { __VA_ARGS__ }; \
524 return QArrayDataPointer<Type>::fromRawData(const_cast<Type *>(data), std::size(data)); \
void swap(QPixmap &other) noexcept
Swaps pixmap other with this pixmap.
Combined button and popup list for selecting options.
static constexpr bool q_points_into_range(const T *p, const T *b, const T *e, Cmp less={}) noexcept
void q_relocate_overlap_n(T *first, N n, T *d_first)
T * construct_at(T *ptr, Args &&... args)
void swap(QArrayDataPointer< T > &p1, QArrayDataPointer< T > &p2) noexcept
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMax(const T &a, const T &b)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
constexpr void qt_ptr_swap(T *&lhs, T *&rhs) noexcept
Q_CHECK_PTR(a=new int[80])
Q_NODISCARD_CTOR constexpr QArrayDataPointer(Data *header, T *adata, qsizetype n=0) noexcept
friend bool operator==(const QArrayDataPointer &lhs, const QArrayDataPointer &rhs) noexcept
void setFlag(typename Data::ArrayOptions f) noexcept
void detachAndGrow(QArrayData::GrowthPosition where, qsizetype n, const T **data, QArrayDataPointer *old)
bool isShared() const noexcept
void relocate(qsizetype offset, const T **data=nullptr)
bool isNull() const noexcept
const T * data() const noexcept
const T * constBegin() const noexcept
qsizetype freeSpaceAtBegin() const noexcept
const DataOps & operator*() const noexcept
Q_NEVER_INLINE void reallocateAndGrow(QArrayData::GrowthPosition where, qsizetype n, QArrayDataPointer *old=nullptr)
void detach(QArrayDataPointer *old=nullptr)
bool needsDetach() const noexcept
bool isSharedWith(const QArrayDataPointer &other) const noexcept
qsizetype allocatedCapacity() noexcept
Q_NODISCARD_CTOR QArrayDataPointer(qsizetype alloc, qsizetype n=0, QArrayData::AllocationOption option=QArrayData::KeepSize)
const DataOps * operator->() const noexcept
const T * constEnd() const noexcept
std::conditional< pass_parameter_by_value, T, constT & >::type parameter_type
void setBegin(T *begin) noexcept
QArrayDataPointer< X > reinterpreted() &&
DataOps * operator->() noexcept
Q_NODISCARD_CTOR constexpr QArrayDataPointer() noexcept
qsizetype freeSpaceAtEnd() const noexcept
Q_NODISCARD_CTOR QArrayDataPointer(const QArrayDataPointer &other) noexcept
void swap(QArrayDataPointer &other) noexcept
const T * begin() const noexcept
const Data::ArrayOptions flags() const noexcept
qsizetype constAllocatedCapacity() const noexcept
void clear() noexcept(std::is_nothrow_destructible< T >::value)
const T * end() const noexcept
bool tryReadjustFreeSpace(QArrayData::GrowthPosition pos, qsizetype n, const T **data=nullptr)
friend bool operator!=(const QArrayDataPointer &lhs, const QArrayDataPointer &rhs) noexcept
QArrayDataPointer sliced(qsizetype pos, qsizetype n) &&
QArrayDataPointer & operator=(const QArrayDataPointer &other) noexcept
static QArrayDataPointer allocateGrow(const QArrayDataPointer &from, qsizetype n, QArrayData::GrowthPosition position)
Q_NODISCARD_CTOR QArrayDataPointer(QArrayDataPointer &&other) noexcept
QArrayDataPointer sliced(qsizetype pos, qsizetype n) const &
bool isMutable() const noexcept
@ pass_parameter_by_value
qsizetype detachCapacity(qsizetype newSize) const noexcept
void clearFlag(typename Data::ArrayOptions f) noexcept
static Q_NODISCARD_CTOR QArrayDataPointer fromRawData(const T *rawData, qsizetype length) noexcept
Q_NODISCARD_CTOR QArrayDataPointer(std::pair< QTypedArrayData< T > *, T * > adata, qsizetype n=0) noexcept
void assign(InputIterator first, InputIterator last, Projection proj={})