3#ifndef QBYTEARRAYVIEW_H
4#define QBYTEARRAYVIEW_H
6#include <QtCore/qbytearrayalgorithms.h>
7#include <QtCore/qstringfwd.h>
8#include <QtCore/qarraydata.h>
11#include <QtCore/q20type_traits.h>
17template <
typename Byte>
19 : std::integral_constant<bool,
20 std::is_same_v<Byte, char> ||
21 std::is_same_v<Byte, uchar> ||
22 std::is_same_v<Byte, signed char> ||
23 std::is_same_v<Byte, std::byte>> {};
25template <
typename Byte>
29template <
typename Po
inter>
31template <
typename Byte>
34template<
typename Po
inter>
38template <
typename T,
typename Enable =
void>
46 IsCompatibleByteArrayPointer<decltype(std::data(std::declval<const T &>()))>,
48 std::is_convertible<decltype(std::size(std::declval<const T &>())), qsizetype>,
50 IsCompatibleByteType<typename std::iterator_traits<decltype(
51 std::begin(std::declval<const T &>()))>::value_type>,
52 std::is_convertible<decltype(std::begin(std::declval<const T &>())
53 != std::end(std::declval<const T &>())),
57 std::negation<std::is_same<std::decay_t<T>, QByteArray>>,
60 std::negation<std::is_array<T>>,
63 std::negation<std::is_same<std::decay_t<T>, QByteArrayView>>>>> : std::true_type {};
66template <
typename Char>
92 template <
typename Byte>
93 using if_compatible_byte =
94 typename std::enable_if_t<QtPrivate::IsCompatibleByteType<Byte>::value,
bool>;
96 template <
typename Po
inter>
97 using if_compatible_pointer =
98 typename std::enable_if_t<QtPrivate::IsCompatibleByteArrayPointer<Pointer>::value,
101 template <
typename T>
102 using if_compatible_qbytearray_like =
103 typename std::enable_if_t<std::is_same_v<T, QByteArray>,
bool>;
105 template <
typename T>
106 using if_compatible_container =
107 typename std::enable_if_t<QtPrivate::IsContainerCompatibleWithQByteArrayView<T>::value,
110 template <
typename Container>
111 static constexpr qsizetype lengthHelperContainer(
const Container &
c)
noexcept
116 static constexpr qsizetype lengthHelperCharArray(
const char *
data,
size_t size)
noexcept
118 const auto it = std::char_traits<char>::find(
data,
size,
'\0');
123 template <
typename Byte>
124 static const storage_type *castHelper(
const Byte *
data)
noexcept
125 {
return reinterpret_cast<const storage_type*
>(
data); }
126 static constexpr const storage_type *castHelper(
const storage_type *
data)
noexcept
131 : m_size(0),
m_data(
nullptr) {}
135 template <
typename Byte, if_compatible_
byte<Byte> = true>
140 template <
typename Byte, if_compatible_
byte<Byte> = true>
145 template <
typename Byte>
148 template <
typename Po
inter, if_compatible_po
inter<Po
inter> = true>
157 template <
typename ByteArray, if_compatible_q
bytearray_like<ByteArray> = true>
162 template <
typename Container, if_compatible_container<Container> = true>
165 template <
size_t Size>
170 template <
typename Byte,
size_t Size>
172 template <
typename Byte,
size_t Size, if_compatible_
byte<Byte> = true>
176 [[nodiscard]]
inline QByteArray toByteArray()
const;
222 {
return QtPrivate::toIntegral<short>(*
this,
ok,
base); }
224 {
return QtPrivate::toIntegral<ushort>(*
this,
ok,
base); }
226 {
return QtPrivate::toIntegral<int>(*
this,
ok,
base); }
228 {
return QtPrivate::toIntegral<uint>(*
this,
ok,
base); }
230 {
return QtPrivate::toIntegral<long>(*
this,
ok,
base); }
232 {
return QtPrivate::toIntegral<ulong>(*
this,
ok,
base); }
234 {
return QtPrivate::toIntegral<qlonglong>(*
this,
ok,
base); }
236 {
return QtPrivate::toIntegral<qulonglong>(*
this,
ok,
base); }
242 return r.value_or(0.0f);
249 return r.value_or(0.0);
255 {
return !empty() && front() ==
c; }
260 {
return !empty() && back() ==
c; }
300 [[nodiscard]]
constexpr bool empty() const noexcept {
return size() == 0; }
307 [[nodiscard]]
constexpr bool isNull() const noexcept {
return !
m_data; }
308 [[nodiscard]]
constexpr bool isEmpty() const noexcept {
return empty(); }
311 [[nodiscard]]
constexpr char first()
const {
return front(); }
312 [[nodiscard]]
constexpr char last()
const {
return back(); }
315 {
return lhs.size() == rhs.size() && (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0); }
317 {
return !(lhs == rhs); }
323 {
return !(lhs <= rhs); }
325 {
return !(lhs < rhs); }
329 const storage_type *
m_data;
333template<
typename QByteArrayLike,
334 std::enable_if_t<std::is_same_v<QByteArrayLike, QByteArray>,
bool> =
true>
344#if QT_DEPRECATED_SINCE(6, 0)
347 Qt::ChecksumType standard =
Qt::ChecksumIso3309)
constexpr char front() const
constexpr bool isNull() const noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
constexpr char first() const
qsizetype lastIndexOf(QByteArrayView a, qsizetype from) const noexcept
friend bool operator==(QByteArrayView lhs, QByteArrayView rhs) noexcept
constexpr char back() const
qsizetype lastIndexOf(char ch, qsizetype from=-1) const noexcept
constexpr char operator[](qsizetype n) const
std::reverse_iterator< iterator > reverse_iterator
constexpr QByteArrayView(const Container &c) noexcept
constexpr qsizetype length() const noexcept
bool contains(QByteArrayView a) const noexcept
constexpr const_iterator begin() const noexcept
bool startsWith(QByteArrayView other) const noexcept
constexpr char at(qsizetype n) const
constexpr const_iterator end() const noexcept
qlonglong toLongLong(bool *ok=nullptr, int base=10) const
constexpr QByteArrayView right(qsizetype n) const
int toInt(bool *ok=nullptr, int base=10) const
uint toUInt(bool *ok=nullptr, int base=10) const
qulonglong toULongLong(bool *ok=nullptr, int base=10) const
constexpr QByteArrayView(const Byte *data, qsizetype len)
constexpr const_reverse_iterator rend() const noexcept
constexpr QByteArrayView last(qsizetype n) const
qsizetype count(char ch) const noexcept
friend bool operator>=(QByteArrayView lhs, QByteArrayView rhs) noexcept
ushort toUShort(bool *ok=nullptr, int base=10) const
qsizetype indexOf(char ch, qsizetype from=0) const noexcept
float toFloat(bool *ok=nullptr) const
constexpr char last() const
constexpr QByteArrayView mid(qsizetype pos, qsizetype n=-1) const
value_type & const_reference
constexpr const_reverse_iterator rbegin() const noexcept
friend bool operator<=(QByteArrayView lhs, QByteArrayView rhs) noexcept
bool endsWith(QByteArrayView other) const noexcept
ulong toULong(bool *ok=nullptr, int base=10) const
short toShort(bool *ok=nullptr, int base=10) const
constexpr QByteArrayView sliced(qsizetype pos) const
constexpr QByteArrayView first(qsizetype n) const
const_pointer const_iterator
constexpr void truncate(qsizetype n)
bool endsWith(char c) const noexcept
constexpr bool isEmpty() const noexcept
qsizetype count(QByteArrayView a) const noexcept
constexpr const_reverse_iterator crbegin() const noexcept
constexpr qsizetype size() const noexcept
value_type * const_pointer
constexpr QByteArrayView() noexcept
constexpr const_iterator cbegin() const noexcept
QByteArrayView(const ByteArray &ba) noexcept
constexpr QByteArrayView(const Byte *first, const Byte *last)
constexpr bool empty() const noexcept
static constexpr QByteArrayView fromArray(const Byte(&data)[Size]) noexcept
constexpr QByteArrayView left(qsizetype n) const
qsizetype lastIndexOf(QByteArrayView a) const noexcept
bool contains(char c) const noexcept
int compare(QByteArrayView a, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QByteArrayView chopped(qsizetype len) const
constexpr void chop(qsizetype n)
constexpr QByteArrayView sliced(qsizetype pos, qsizetype n) const
bool isValidUtf8() const noexcept
constexpr const_reverse_iterator crend() const noexcept
constexpr const_pointer data() const noexcept
constexpr QByteArrayView(std::nullptr_t) noexcept
constexpr QByteArrayView(const Pointer &data) noexcept
long toLong(bool *ok=nullptr, int base=10) const
qsizetype indexOf(QByteArrayView a, qsizetype from=0) const noexcept
QByteArrayView trimmed() const noexcept
double toDouble(bool *ok=nullptr) const
constexpr const_iterator cend() const noexcept
constexpr const_pointer constData() const noexcept
constexpr QByteArrayView(const char(&data)[Size]) noexcept
bool startsWith(char c) const noexcept
friend bool operator!=(QByteArrayView lhs, QByteArrayView rhs) noexcept
bool isNull() const noexcept
Returns true if this byte array is null; otherwise returns false.
QSet< QString >::iterator it
Combined button and popup list for selecting options.
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QByteArrayView trimmed(QByteArrayView s) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT int compareMemory(QByteArrayView lhs, QByteArrayView rhs)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION ParsedNumber< float > toFloat(QByteArrayView a) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findByteArray(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION ParsedNumber< double > toDouble(QByteArrayView a) noexcept
static constexpr qsizetype lengthHelperPointer(const Char *data) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf8(QByteArrayView s) noexcept
int qstrnicmp(const char *str1, qsizetype len1, const char *str2, qsizetype len2)
Q_CORE_EXPORT quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard=Qt::ChecksumIso3309)
QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
bool operator>(const QPoint &a, const QPoint &b)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2)
#define QT_DEPRECATED_VERSION_X_6_0(text)
static int compare(quint64 a, quint64 b)
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)