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
qvarlengtharray.h
Go to the documentation of this file.
1// Copyright (C) 2021 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 QVARLENGTHARRAY_H
5#define QVARLENGTHARRAY_H
6
7#if 0
8#pragma qt_class(QVarLengthArray)
9#pragma qt_sync_stop_processing
10#endif
11
12#include <QtCore/qcompare.h>
13#include <QtCore/qcontainerfwd.h>
14#include <QtCore/qglobal.h>
15#include <QtCore/qalgorithms.h>
16#include <QtCore/qcontainertools_impl.h>
17#include <QtCore/qhashfunctions.h>
18#include <QtCore/qttypetraits.h>
19
20#include <algorithm>
21#include <initializer_list>
22#include <iterator>
23#include <QtCore/q20memory.h>
24#include <new>
25
26#include <string.h>
27#include <stdlib.h>
28
29QT_BEGIN_NAMESPACE
30
31template <size_t Size, size_t Align, qsizetype Prealloc>
32class QVLAStorage
33{
34 template <size_t> class print;
35protected:
36 QVLAStorage() = default;
37 QT_DECLARE_RO5_SMF_AS_DEFAULTED(QVLAStorage)
38
39 alignas(Align) char array[Prealloc * (Align > Size ? Align : Size)];
40 QT_WARNING_PUSH
41 QT_WARNING_DISABLE_DEPRECATED
42 // ensure we maintain BC: std::aligned_storage_t was only specified by a
43 // minimum size, but for BC we need the substitution to be exact in size:
44 static_assert(std::is_same_v<print<sizeof(std::aligned_storage_t<Size, Align>[Prealloc])>,
45 print<sizeof(array)>>);
46 QT_WARNING_POP
47};
48
50{
51protected:
52 QVLABaseBase() = default;
54
55 qsizetype a; // capacity
56 qsizetype s; // size
57 void *ptr; // data
58
59 Q_ALWAYS_INLINE constexpr void verify([[maybe_unused]] qsizetype pos = 0,
60 [[maybe_unused]] qsizetype n = 1) const
61 {
62 Q_ASSERT(pos >= 0);
63 Q_ASSERT(pos <= size());
64 Q_ASSERT(n >= 0);
65 Q_ASSERT(n <= size() - pos);
66 }
67
68 struct free_deleter {
69 void operator()(void *p) const noexcept { free(p); }
70 };
71 using malloced_ptr = std::unique_ptr<void, free_deleter>;
72
73public:
75
76 constexpr size_type capacity() const noexcept { return a; }
77 constexpr size_type size() const noexcept { return s; }
78 constexpr bool empty() const noexcept { return size() == 0; }
79};
80
81template<class T>
82class QVLABase : public QVLABaseBase
83{
84protected:
85 QVLABase() = default;
87
88public:
89 T *data() noexcept { return static_cast<T *>(ptr); }
90 const T *data() const noexcept { return static_cast<T *>(ptr); }
91
92 using iterator = T*;
93 using const_iterator = const T*;
94
95 iterator begin() noexcept { return data(); }
96 const_iterator begin() const noexcept { return data(); }
97 const_iterator cbegin() const noexcept { return begin(); }
98 iterator end() noexcept { return data() + size(); }
99 const_iterator end() const noexcept { return data() + size(); }
100 const_iterator cend() const noexcept { return end(); }
101
103 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
104
105 reverse_iterator rbegin() noexcept { return reverse_iterator{end()}; }
106 const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator{end()}; }
107 const_reverse_iterator crbegin() const noexcept { return rbegin(); }
108 reverse_iterator rend() noexcept { return reverse_iterator{begin()}; }
109 const_reverse_iterator rend() const noexcept { return const_reverse_iterator{begin()}; }
110 const_reverse_iterator crend() const noexcept { return rend(); }
111
112 using value_type = T;
113 using reference = value_type&;
114 using const_reference = const value_type&;
115 using pointer = value_type*;
116 using const_pointer = const value_type*;
118
119 reference front()
120 {
121 verify();
122 return *begin();
123 }
124
125 const_reference front() const
126 {
127 verify();
128 return *begin();
129 }
130
131 reference back()
132 {
133 verify();
134 return *rbegin();
135 }
136
137 const_reference back() const
138 {
139 verify();
140 return *rbegin();
141 }
142
143 void pop_back()
144 {
145 verify();
146 if constexpr (QTypeInfo<T>::isComplex)
147 data()[size() - 1].~T();
148 --s;
149 }
150
151 template <typename AT = T>
152 qsizetype indexOf(const AT &t, qsizetype from = 0) const;
153 template <typename AT = T>
154 qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const;
155 template <typename AT = T>
156 bool contains(const AT &t) const;
157
158 reference operator[](qsizetype idx)
159 {
160 verify(idx);
161 return data()[idx];
162 }
163 const_reference operator[](qsizetype idx) const
164 {
165 verify(idx);
166 return data()[idx];
167 }
168
169 value_type value(qsizetype i) const;
170 value_type value(qsizetype i, const T& defaultValue) const;
171
172 void replace(qsizetype i, const T &t);
173 void remove(qsizetype i, qsizetype n = 1);
174 template <typename AT = T>
175 qsizetype removeAll(const AT &t);
176 template <typename AT = T>
177 bool removeOne(const AT &t);
178 template <typename Predicate>
179 qsizetype removeIf(Predicate pred);
180
181 void clear()
182 {
183 if constexpr (QTypeInfo<T>::isComplex)
184 std::destroy_n(data(), size());
185 s = 0;
186 }
187
188 iterator erase(const_iterator begin, const_iterator end);
189 iterator erase(const_iterator pos) { return erase(pos, pos + 1); }
190
191 static constexpr qsizetype maxSize() noexcept
192 {
193 // -1 to deal with the pointer one-past-the-end
194 return (QtPrivate::MaxAllocSize / sizeof(T)) - 1;
195 }
196 constexpr qsizetype max_size() const noexcept
197 {
198 return maxSize();
199 }
200
201 size_t hash(size_t seed) const noexcept(QtPrivate::QNothrowHashable_v<T>)
202 {
203 return qHashRange(begin(), end(), seed);
204 }
205protected:
206 void growBy(qsizetype prealloc, void *array, qsizetype increment)
207 { reallocate_impl(prealloc, array, size(), (std::max)(size() * 2, size() + increment)); }
208 template <typename...Args>
209 reference emplace_back_impl(qsizetype prealloc, void *array, Args&&...args)
210 {
211 if (size() == capacity()) // ie. size() != 0
212 growBy(prealloc, array, 1);
213 reference r = *q20::construct_at(end(), std::forward<Args>(args)...);
214 ++s;
215 return r;
216 }
217 template <typename...Args>
218 iterator emplace_impl(qsizetype prealloc, void *array, const_iterator pos, Args&&...arg);
219
220 iterator insert_impl(qsizetype prealloc, void *array, const_iterator pos, qsizetype n, const T &t);
221
222 template <typename S>
223 bool equal(const QVLABase<S> &other) const
224 {
225 return std::equal(begin(), end(), other.begin(), other.end());
226 }
227 template <typename S>
228 bool less_than(const QVLABase<S> &other) const
229 {
230 return std::lexicographical_compare(begin(), end(), other.begin(), other.end());
231 }
232
233 void append_impl(qsizetype prealloc, void *array, const T *buf, qsizetype n);
234 void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc);
235 void resize_impl(qsizetype prealloc, void *array, qsizetype sz, const T &v)
236 {
237 if (QtPrivate::q_points_into_range(&v, begin(), end())) {
238 resize_impl(prealloc, array, sz, T(v));
239 return;
240 }
241 reallocate_impl(prealloc, array, sz, qMax(sz, capacity()));
242 while (size() < sz) {
243 q20::construct_at(data() + size(), v);
244 ++s;
245 }
246 }
247 void resize_impl(qsizetype prealloc, void *array, qsizetype sz)
248 {
249 reallocate_impl(prealloc, array, sz, qMax(sz, capacity()));
250 if constexpr (QTypeInfo<T>::isComplex) {
251 // call default constructor for new objects (which can throw)
252 while (size() < sz) {
253 q20::construct_at(data() + size());
254 ++s;
255 }
256 } else {
257 s = sz;
258 }
259 }
260
261 void assign_impl(qsizetype prealloc, void *array, qsizetype n, const T &t);
262 template <typename Iterator>
263 void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last);
264
265 bool isValidIterator(const const_iterator &i) const
266 {
267 const std::less<const T *> less = {};
268 return !less(cend(), i) && !less(i, cbegin());
269 }
270};
271
272// Prealloc = 256 by default, specified in qcontainerfwd.h
273template<class T, qsizetype Prealloc>
275#if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || defined(QT_BOOTSTRAPPED)
276 : public QVLAStorage<sizeof(T), alignof(T), Prealloc>,
277 public QVLABase<T>
278#else
279 : public QVLABase<T>,
280 public QVLAStorage<sizeof(T), alignof(T), Prealloc>
281#endif
282{
283 template <class S, qsizetype Prealloc2>
284 friend class QVarLengthArray;
285 using Base = QVLABase<T>;
286 using Storage = QVLAStorage<sizeof(T), alignof(T), Prealloc>;
287 static_assert(Prealloc > 0, "QVarLengthArray Prealloc must be greater than 0.");
288 static_assert(std::is_nothrow_destructible_v<T>, "Types with throwing destructors are not supported in Qt containers.");
289 using Base::verify;
290
291 template <typename U>
293 template <typename InputIterator>
295public:
296 static constexpr qsizetype PreallocatedSize = Prealloc;
297
298 using size_type = typename Base::size_type;
299 using value_type = typename Base::value_type;
300 using pointer = typename Base::pointer;
301 using const_pointer = typename Base::const_pointer;
302 using reference = typename Base::reference;
303 using const_reference = typename Base::const_reference;
304 using difference_type = typename Base::difference_type;
305
306 using iterator = typename Base::iterator;
307 using const_iterator = typename Base::const_iterator;
308 using reverse_iterator = typename Base::reverse_iterator;
309 using const_reverse_iterator = typename Base::const_reverse_iterator;
310
312 {
313 this->a = Prealloc;
314 this->s = 0;
315 this->ptr = this->array;
316 }
317
318 inline explicit QVarLengthArray(qsizetype size);
319
320#ifndef Q_QDOC
321 template <typename U = T, if_copyable<U> = true>
322#endif
323 explicit QVarLengthArray(qsizetype sz, const T &v)
325 {
326 resize(sz, v);
327 }
328
331 {
332 append(other.constData(), other.size());
333 }
334
337 : Base(other)
338 {
339 const auto otherInlineStorage = reinterpret_cast<T*>(other.array);
340 if (data() == otherInlineStorage) {
341 // inline buffer - move into our inline buffer:
342 this->ptr = this->array;
343 QtPrivate::q_uninitialized_relocate_n(otherInlineStorage, size(), data());
344 } else {
345 // heap buffer - we just stole the memory
346 }
347 // reset other to internal storage:
348 other.a = Prealloc;
349 other.s = 0;
350 other.ptr = otherInlineStorage;
351 }
352
353 QVarLengthArray(std::initializer_list<T> args)
354 : QVarLengthArray(args.begin(), args.end())
355 {
356 }
357
358 template <typename InputIterator, if_input_iterator<InputIterator> = true>
359 inline QVarLengthArray(InputIterator first, InputIterator last)
361 {
362 QtPrivate::reserveIfForwardIterator(this, first, last);
363 std::copy(first, last, std::back_inserter(*this));
364 }
365
367 {
368 if constexpr (QTypeInfo<T>::isComplex)
369 std::destroy_n(data(), size());
370 if (data() != reinterpret_cast<T *>(this->array))
371 free(data());
372 }
373 inline QVarLengthArray<T, Prealloc> &operator=(const QVarLengthArray<T, Prealloc> &other)
374 {
375 if (this != &other) {
376 clear();
377 append(other.constData(), other.size());
378 }
379 return *this;
380 }
381
384 {
385 // we're only required to be self-move-assignment-safe
386 // when we're in the moved-from state (Hinnant criterion)
387 // the moved-from state is the empty state, so we're good with the clear() here:
388 clear();
389 Q_ASSERT(capacity() >= Prealloc);
390 const auto otherInlineStorage = other.array;
391 if (other.ptr != otherInlineStorage) {
392 // heap storage: steal the external buffer, reset other to otherInlineStorage
393 this->a = std::exchange(other.a, Prealloc);
394 this->ptr = std::exchange(other.ptr, otherInlineStorage);
395 } else {
396 // inline storage: move into our storage (doesn't matter whether inline or external)
397 QtPrivate::q_uninitialized_relocate_n(other.data(), other.size(), data());
398 }
399 this->s = std::exchange(other.s, 0);
400 return *this;
401 }
402
403 QVarLengthArray<T, Prealloc> &operator=(std::initializer_list<T> list)
404 {
405 assign(list);
406 return *this;
407 }
408
409 inline void removeLast()
410 {
411 Base::pop_back();
412 }
413#ifdef Q_QDOC
414 inline qsizetype size() const { return this->s; }
415 static constexpr qsizetype maxSize() noexcept { return QVLABase<T>::maxSize(); }
416 constexpr qsizetype max_size() const noexcept { return QVLABase<T>::max_size(); }
417#endif
418 using Base::size;
419 using Base::max_size;
420 inline qsizetype count() const { return size(); }
421 inline qsizetype length() const { return size(); }
422 inline T &first()
423 {
424 return front();
425 }
426 inline const T &first() const
427 {
428 return front();
429 }
430 T &last()
431 {
432 return back();
433 }
434 const T &last() const
435 {
436 return back();
437 }
438 bool isEmpty() const { return empty(); }
439 void resize(qsizetype sz) { Base::resize_impl(Prealloc, this->array, sz); }
440#ifndef Q_QDOC
441 template <typename U = T, if_copyable<U> = true>
442#endif
443 void resize(qsizetype sz, const T &v)
444 { Base::resize_impl(Prealloc, this->array, sz, v); }
445 using Base::clear;
446#ifdef Q_QDOC
447 inline void clear() { resize(0); }
448#endif
449 void squeeze() { reallocate(size(), size()); }
450
451 using Base::capacity;
452#ifdef Q_QDOC
453 qsizetype capacity() const { return this->a; }
454#endif
455 void reserve(qsizetype sz) { if (sz > capacity()) reallocate(size(), sz); }
456
457#ifdef Q_QDOC
458 template <typename AT = T>
459 inline qsizetype indexOf(const AT &t, qsizetype from = 0) const;
460 template <typename AT = T>
461 inline qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const;
462 template <typename AT = T>
463 inline bool contains(const AT &t) const;
464#endif
465 using Base::indexOf;
466 using Base::lastIndexOf;
467 using Base::contains;
468
469#ifdef Q_QDOC
470 inline T &operator[](qsizetype idx)
471 {
472 verify(idx);
473 return data()[idx];
474 }
475 inline const T &operator[](qsizetype idx) const
476 {
477 verify(idx);
478 return data()[idx];
479 }
480#endif
481 using Base::operator[];
482 inline const T &at(qsizetype idx) const { return operator[](idx); }
483
484#ifdef Q_QDOC
485 T value(qsizetype i) const;
486 T value(qsizetype i, const T &defaultValue) const;
487#endif
488 using Base::value;
489
490 inline void append(const T &t)
491 {
492 if (size() == capacity())
493 emplace_back(T(t));
494 else
495 emplace_back(t);
496 }
497
498 void append(T &&t)
499 {
500 emplace_back(std::move(t));
501 }
502
503 void append(const T *buf, qsizetype sz)
504 { Base::append_impl(Prealloc, this->array, buf, sz); }
505 inline QVarLengthArray<T, Prealloc> &operator<<(const T &t)
506 { append(t); return *this; }
507 inline QVarLengthArray<T, Prealloc> &operator<<(T &&t)
508 { append(std::move(t)); return *this; }
509 inline QVarLengthArray<T, Prealloc> &operator+=(const T &t)
510 { append(t); return *this; }
511 inline QVarLengthArray<T, Prealloc> &operator+=(T &&t)
512 { append(std::move(t)); return *this; }
513
514#if QT_DEPRECATED_SINCE(6, 3)
515 QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.")
516 void prepend(T &&t);
517 QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.")
518 void prepend(const T &t);
519#endif
520 void insert(qsizetype i, T &&t);
521 void insert(qsizetype i, const T &t);
522 void insert(qsizetype i, qsizetype n, const T &t);
523
524 QVarLengthArray &assign(qsizetype n, const T &t)
525 { Base::assign_impl(Prealloc, this->array, n, t); return *this; }
526 template <typename InputIterator, if_input_iterator<InputIterator> = true>
527 QVarLengthArray &assign(InputIterator first, InputIterator last)
528 { Base::assign_impl(Prealloc, this->array, first, last); return *this; }
529 QVarLengthArray &assign(std::initializer_list<T> list)
530 { assign(list.begin(), list.end()); return *this; }
531
532#ifdef Q_QDOC
533 void replace(qsizetype i, const T &t);
534 void remove(qsizetype i, qsizetype n = 1);
535 template <typename AT = T>
536 qsizetype removeAll(const AT &t);
537 template <typename AT = T>
538 bool removeOne(const AT &t);
539 template <typename Predicate>
541#endif
542 using Base::replace;
543 using Base::remove;
544 using Base::removeAll;
545 using Base::removeOne;
546 using Base::removeIf;
547
548#ifdef Q_QDOC
549 inline T *data() { return this->ptr; }
550 inline const T *data() const { return this->ptr; }
551#endif
552 using Base::data;
553 inline const T *constData() const { return data(); }
554#ifdef Q_QDOC
555 inline iterator begin() { return data(); }
556 inline const_iterator begin() const { return data(); }
557 inline const_iterator cbegin() const { return begin(); }
558 inline const_iterator constBegin() const { return begin(); }
559 inline iterator end() { return data() + size(); }
560 inline const_iterator end() const { return data() + size(); }
561 inline const_iterator cend() const { return end(); }
562#endif
563
564 using Base::begin;
565 using Base::cbegin;
566 auto constBegin() const -> const_iterator { return begin(); }
567 using Base::end;
568 using Base::cend;
569 inline const_iterator constEnd() const { return end(); }
570#ifdef Q_QDOC
577#endif
578 using Base::rbegin;
579 using Base::crbegin;
580 using Base::rend;
581 using Base::crend;
582
583 iterator insert(const_iterator before, qsizetype n, const T &x)
584 { return Base::insert_impl(Prealloc, this->array, before, n, x); }
585 iterator insert(const_iterator before, T &&x) { return emplace(before, std::move(x)); }
586 inline iterator insert(const_iterator before, const T &x) { return insert(before, 1, x); }
587#ifdef Q_QDOC
589 inline iterator erase(const_iterator pos) { return erase(pos, pos + 1); }
590#endif
591 using Base::erase;
592
593 // STL compatibility:
594#ifdef Q_QDOC
595 inline bool empty() const { return isEmpty(); }
596#endif
597 using Base::empty;
598 inline void push_back(const T &t) { append(t); }
599 void push_back(T &&t) { append(std::move(t)); }
600#ifdef Q_QDOC
601 inline void pop_back() { removeLast(); }
602 inline T &front() { return first(); }
603 inline const T &front() const { return first(); }
604 inline T &back() { return last(); }
605 inline const T &back() const { return last(); }
606#endif
607 using Base::pop_back;
608 using Base::front;
609 using Base::back;
611 template <typename...Args>
612 iterator emplace(const_iterator pos, Args &&...args)
613 { return Base::emplace_impl(Prealloc, this->array, pos, std::forward<Args>(args)...); }
614 template <typename...Args>
615 T &emplace_back(Args &&...args)
616 { return Base::emplace_back_impl(Prealloc, this->array, std::forward<Args>(args)...); }
617
618
619#ifdef Q_QDOC
620 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
621 friend inline bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
622 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
623 friend inline bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
624 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
625 friend inline bool operator< (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
626 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
627 friend inline bool operator> (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
628 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
629 friend inline bool operator<=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
630 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
631 friend inline bool operator>=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
632 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
633 friend inline auto operator<=>(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
634#else
635private:
636 template <typename U = T, qsizetype Prealloc2 = Prealloc,
637 Qt::if_has_qt_compare_three_way<U, U> = true>
638 friend auto
639 compareThreeWay(const QVarLengthArray &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
640 {
641 return QtOrderingPrivate::lexicographicalCompareThreeWay(lhs.begin(), lhs.end(),
642 rhs.begin(), rhs.end());
643 }
644
645#if defined(__cpp_lib_three_way_comparison) && defined(__cpp_lib_concepts)
646 template <typename U = T, qsizetype Prealloc2 = Prealloc,
648 friend auto
650 {
652 rhs.begin(), rhs.end(),
654 }
655#endif // __cpp_lib_three_way_comparison && __cpp_lib_concepts
656
657public:
658 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
659 QTypeTraits::compare_eq_result<U> operator==(const QVarLengthArray<T, Prealloc> &l, const QVarLengthArray<T, Prealloc2> &r)
660 {
661 return l.equal(r);
662 }
663
664 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
665 QTypeTraits::compare_eq_result<U> operator!=(const QVarLengthArray<T, Prealloc> &l, const QVarLengthArray<T, Prealloc2> &r)
666 {
667 return !(l == r);
668 }
669
670#ifndef __cpp_lib_three_way_comparison
671 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
672 QTypeTraits::compare_lt_result<U> operator<(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
673 noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(),
674 rhs.begin(), rhs.end())))
675 {
676 return lhs.less_than(rhs);
677 }
678
679 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
680 QTypeTraits::compare_lt_result<U> operator>(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
681 noexcept(noexcept(lhs < rhs))
682 {
683 return rhs < lhs;
684 }
685
686 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
687 QTypeTraits::compare_lt_result<U> operator<=(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
688 noexcept(noexcept(lhs < rhs))
689 {
690 return !(lhs > rhs);
691 }
692
693 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
694 QTypeTraits::compare_lt_result<U> operator>=(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
695 noexcept(noexcept(lhs < rhs))
696 {
697 return !(lhs < rhs);
698 }
699#endif // __cpp_lib_three_way_comparison
700#endif // Q_QDOC
701
702private:
703 template <typename U, qsizetype Prealloc2>
704 bool equal(const QVarLengthArray<U, Prealloc2> &other) const
705 { return Base::equal(other); }
706 template <typename U, qsizetype Prealloc2>
707 bool less_than(const QVarLengthArray<U, Prealloc2> &other) const
708 { return Base::less_than(other); }
709
710 void reallocate(qsizetype sz, qsizetype alloc)
711 { Base::reallocate_impl(Prealloc, this->array, sz, alloc); }
712
713 using Base::isValidIterator;
714};
715
716template <typename InputIterator,
717 typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
718 QtPrivate::IfIsInputIterator<InputIterator> = true>
719QVarLengthArray(InputIterator, InputIterator) -> QVarLengthArray<ValueType>;
720
721template <class T, qsizetype Prealloc>
722Q_INLINE_TEMPLATE QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype asize)
723 : QVarLengthArray()
724{
725 Q_ASSERT_X(asize >= 0, "QVarLengthArray::QVarLengthArray(qsizetype)",
726 "Size must be greater than or equal to 0.");
727
728 // historically, this ctor worked for non-copyable/non-movable T, so keep it working, why not?
729 // resize(asize) // this requires a movable or copyable T, can't use, need to do it by hand
730
731 if (asize > Prealloc) {
732 this->ptr = malloc(asize * sizeof(T));
733 Q_CHECK_PTR(this->ptr);
734 this->a = asize;
735 }
736 if constexpr (QTypeInfo<T>::isComplex)
737 std::uninitialized_default_construct_n(data(), asize);
738 this->s = asize;
739}
740
741template <class T>
742template <typename AT>
743Q_INLINE_TEMPLATE qsizetype QVLABase<T>::indexOf(const AT &t, qsizetype from) const
744{
745 if (from < 0)
746 from = qMax(from + size(), qsizetype(0));
747 if (from < size()) {
748 const T *n = data() + from - 1;
749 const T *e = end();
750 while (++n != e)
751 if (*n == t)
752 return n - data();
753 }
754 return -1;
755}
756
757template <class T>
758template <typename AT>
759Q_INLINE_TEMPLATE qsizetype QVLABase<T>::lastIndexOf(const AT &t, qsizetype from) const
760{
761 if (from < 0)
762 from += size();
763 else if (from >= size())
764 from = size() - 1;
765 if (from >= 0) {
766 const T *b = begin();
767 const T *n = b + from + 1;
768 while (n != b) {
769 if (*--n == t)
770 return n - b;
771 }
772 }
773 return -1;
774}
775
776template <class T>
777template <typename AT>
778Q_INLINE_TEMPLATE bool QVLABase<T>::contains(const AT &t) const
779{
780 const T *b = begin();
781 const T *i = end();
782 while (i != b) {
783 if (*--i == t)
784 return true;
785 }
786 return false;
787}
788
789template <class T>
790Q_OUTOFLINE_TEMPLATE void QVLABase<T>::append_impl(qsizetype prealloc, void *array, const T *abuf, qsizetype increment)
791{
792 Q_ASSERT(abuf || increment == 0);
793 if (increment <= 0)
794 return;
795
796 const qsizetype asize = size() + increment;
797
798 if (asize >= capacity())
799 growBy(prealloc, array, increment);
800
801 if constexpr (QTypeInfo<T>::isComplex)
802 std::uninitialized_copy_n(abuf, increment, end());
803 else
804 memcpy(static_cast<void *>(end()), static_cast<const void *>(abuf), increment * sizeof(T));
805
806 this->s = asize;
807}
808
809template <class T>
810Q_OUTOFLINE_TEMPLATE void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, qsizetype n, const T &t)
811{
812 Q_ASSERT(n >= 0);
813 if (n > capacity()) {
814 reallocate_impl(prealloc, array, 0, capacity()); // clear
815 resize_impl(prealloc, array, n, t);
816 } else {
817 auto mid = (std::min)(n, size());
818 std::fill(data(), data() + mid, t);
819 std::uninitialized_fill(data() + mid, data() + n, t);
820 s = n;
821 erase(data() + n, data() + size());
822 }
823}
824
825template <class T>
826template <typename Iterator>
827Q_OUTOFLINE_TEMPLATE void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last)
828{
829 // This function only provides the basic exception guarantee.
830 constexpr bool IsFwdIt =
831 std::is_convertible_v<typename std::iterator_traits<Iterator>::iterator_category,
832 std::forward_iterator_tag>;
833 if constexpr (IsFwdIt) {
834 const qsizetype n = std::distance(first, last);
835 if (n > capacity())
836 reallocate_impl(prealloc, array, 0, n); // clear & reserve n
837 }
838
839 auto dst = begin();
840 const auto dend = end();
841 while (true) {
842 if (first == last) { // ran out of elements to assign
843 std::destroy(dst, dend);
844 break;
845 }
846 if (dst == dend) { // ran out of existing elements to overwrite
847 if constexpr (IsFwdIt) {
848 dst = std::uninitialized_copy(first, last, dst);
849 break;
850 } else {
851 do {
852 emplace_back_impl(prealloc, array, *first);
853 } while (++first != last);
854 return; // size() is already correct (and dst invalidated)!
855 }
856 }
857 *dst = *first; // overwrite existing element
858 ++dst;
859 ++first;
860 }
861 this->s = dst - begin();
862}
863
864template <class T>
865Q_OUTOFLINE_TEMPLATE void QVLABase<T>::reallocate_impl(qsizetype prealloc, void *array, qsizetype asize, qsizetype aalloc)
866{
867 Q_ASSERT(aalloc >= asize);
868 Q_ASSERT(data());
869 T *oldPtr = data();
870 qsizetype osize = size();
871
872 const qsizetype copySize = qMin(asize, osize);
873 Q_ASSERT(copySize >= 0);
874
875 if (aalloc != capacity()) {
876 QVLABaseBase::malloced_ptr guard;
877 void *newPtr;
878 qsizetype newA;
879 if (aalloc > prealloc) {
880 newPtr = malloc(aalloc * sizeof(T));
881 guard.reset(newPtr);
882 Q_CHECK_PTR(newPtr); // could throw
883 // by design: in case of QT_NO_EXCEPTIONS malloc must not fail or it crashes here
884 newA = aalloc;
885 } else {
886 newPtr = array;
887 newA = prealloc;
888 }
889 QtPrivate::q_uninitialized_relocate_n(oldPtr, copySize,
890 reinterpret_cast<T *>(newPtr));
891 // commit:
892 ptr = newPtr;
893 guard.release();
894 a = newA;
895 }
896 s = copySize;
897
898 // destroy remaining old objects
899 if constexpr (QTypeInfo<T>::isComplex) {
900 if (osize > asize)
901 std::destroy(oldPtr + asize, oldPtr + osize);
902 }
903
904 if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != data())
905 free(oldPtr);
906}
907
908template <class T>
909Q_OUTOFLINE_TEMPLATE T QVLABase<T>::value(qsizetype i) const
910{
911 if (size_t(i) >= size_t(size()))
912 return T();
913 return operator[](i);
914}
915template <class T>
916Q_OUTOFLINE_TEMPLATE T QVLABase<T>::value(qsizetype i, const T &defaultValue) const
917{
918 return (size_t(i) >= size_t(size())) ? defaultValue : operator[](i);
919}
920
921template <class T, qsizetype Prealloc>
922inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, T &&t)
923{ verify(i, 0);
924 insert(cbegin() + i, std::move(t)); }
925template <class T, qsizetype Prealloc>
926inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, const T &t)
927{ verify(i, 0);
928 insert(begin() + i, 1, t); }
929template <class T, qsizetype Prealloc>
930inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, qsizetype n, const T &t)
931{ verify(i, 0);
932 insert(begin() + i, n, t); }
933template <class T>
934inline void QVLABase<T>::remove(qsizetype i, qsizetype n)
935{ verify(i, n);
936 erase(begin() + i, begin() + i + n); }
937template <class T>
938template <typename AT>
939inline qsizetype QVLABase<T>::removeAll(const AT &t)
940{ return QtPrivate::sequential_erase_with_copy(*this, t); }
941template <class T>
942template <typename AT>
943inline bool QVLABase<T>::removeOne(const AT &t)
944{ return QtPrivate::sequential_erase_one(*this, t); }
945template <class T>
946template <typename Predicate>
947inline qsizetype QVLABase<T>::removeIf(Predicate pred)
948{ return QtPrivate::sequential_erase_if(*this, pred); }
949#if QT_DEPRECATED_SINCE(6, 3)
950template <class T, qsizetype Prealloc>
951inline void QVarLengthArray<T, Prealloc>::prepend(T &&t)
952{ insert(cbegin(), std::move(t)); }
953template <class T, qsizetype Prealloc>
954inline void QVarLengthArray<T, Prealloc>::prepend(const T &t)
955{ insert(begin(), 1, t); }
956#endif
957
958template <class T>
959inline void QVLABase<T>::replace(qsizetype i, const T &t)
960{
961 verify(i);
962 data()[i] = t;
963}
964
965template <class T>
966template <typename...Args>
967Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::emplace_impl(qsizetype prealloc, void *array, const_iterator before, Args &&...args) -> iterator
968{
969 Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid");
970 Q_ASSERT(size() <= capacity());
971 Q_ASSERT(capacity() > 0);
972
973 const qsizetype offset = qsizetype(before - cbegin());
974 emplace_back_impl(prealloc, array, std::forward<Args>(args)...);
975 const auto b = begin() + offset;
976 const auto e = end();
977 QtPrivate::q_rotate(b, e - 1, e);
978 return b;
979}
980
981template <class T>
982Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::insert_impl(qsizetype prealloc, void *array, const_iterator before, qsizetype n, const T &t) -> iterator
983{
984 Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid");
985
986 const qsizetype offset = qsizetype(before - cbegin());
987 resize_impl(prealloc, array, size() + n, t);
988 const auto b = begin() + offset;
989 const auto e = end();
990 QtPrivate::q_rotate(b, e - n, e);
991 return b;
992}
993
994template <class T>
995Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::erase(const_iterator abegin, const_iterator aend) -> iterator
996{
997 Q_ASSERT_X(isValidIterator(abegin), "QVarLengthArray::erase", "The specified const_iterator argument 'abegin' is invalid");
998 Q_ASSERT_X(isValidIterator(aend), "QVarLengthArray::erase", "The specified const_iterator argument 'aend' is invalid");
999
1000 qsizetype f = qsizetype(abegin - cbegin());
1001 qsizetype l = qsizetype(aend - cbegin());
1002 qsizetype n = l - f;
1003
1004 if (n == 0) // avoid UB in std::move() below
1005 return data() + f;
1006
1007 Q_ASSERT(n > 0); // aend must be reachable from abegin
1008
1009 if constexpr (!QTypeInfo<T>::isRelocatable) {
1010 std::move(begin() + l, end(), QT_MAKE_CHECKED_ARRAY_ITERATOR(begin() + f, size() - f));
1011 std::destroy(end() - n, end());
1012 } else {
1013 std::destroy(abegin, aend);
1014 memmove(static_cast<void *>(data() + f), static_cast<const void *>(data() + l), (size() - l) * sizeof(T));
1015 }
1016 this->s -= n;
1017 return data() + f;
1018}
1019
1020#ifdef Q_QDOC
1021// Fake definitions for qdoc, only the redeclaration is used.
1022template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1023bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1024{ return bool{}; }
1025template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1026bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1027{ return bool{}; }
1028template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1029bool operator< (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1030{ return bool{}; }
1031template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1032bool operator> (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1033{ return bool{}; }
1034template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1035bool operator<=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1036{ return bool{}; }
1037template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1038bool operator>=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1039{ return bool{}; }
1040#endif
1041
1042template <typename T, qsizetype Prealloc>
1043size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)
1044 noexcept(QtPrivate::QNothrowHashable_v<T>)
1045{
1046 return key.hash(seed);
1047}
1048
1049template <typename T, qsizetype Prealloc, typename AT>
1050qsizetype erase(QVarLengthArray<T, Prealloc> &array, const AT &t)
1051{
1052 return array.removeAll(t);
1053}
1054
1055template <typename T, qsizetype Prealloc, typename Predicate>
1056qsizetype erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred)
1057{
1058 return array.removeIf(pred);
1059}
1060
1061QT_END_NAMESPACE
1062
1063#endif // QVARLENGTHARRAY_H
QByteArray & operator*() noexcept
Definition qbytearray.h:803
QByteArray::Base64DecodingStatus decodingStatus
Definition qbytearray.h:788
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
Definition qbytearray.h:807
void swap(QByteArray::FromBase64Result &other) noexcept
Definition qbytearray.h:790
operator bool() const noexcept
\variable QByteArray::FromBase64Result::decoded
Definition qbytearray.h:796
const QByteArray & operator*() const noexcept
Returns the decoded byte array.
Definition qbytearray.h:804
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
Definition qbytearray.h:818
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qdatastream.h:49
\inmodule QtCore
Definition qeventloop.h:59
int initFrom(const QMessageLogContext &logContext)
void populateBacktrace(int frameCount)
QInternalMessageLogContext(const QMessageLogContext &logContext, const QLoggingCategory &categoryOverride)
Definition qlogging_p.h:65
std::optional< BacktraceStorage > backtrace
Definition qlogging_p.h:57
static constexpr int DefaultBacktraceDepth
Definition qlogging_p.h:47
Definition qlist.h:80
\inmodule QtCore
Definition qlogging.h:43
constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
Definition qlogging.h:48
const char * category
Definition qlogging.h:55
constexpr QMessageLogContext() noexcept=default
const char * function
Definition qlogging.h:54
const char * file
Definition qlogging.h:53
\inmodule QtCore
Definition qlogging.h:73
QDebug debug(CategoryFunction catFunc) const
QDebug debug(const QLoggingCategory &cat) const
Logs a debug message into category cat using a QDebug stream.
Definition qlogging.cpp:450
void void void void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QDebug debug() const
Logs a debug message using a QDebug stream.
Definition qlogging.cpp:436
QDebug info(const QLoggingCategory &cat) const
Logs an informational message into the category cat using a QDebug stream.
Definition qlogging.cpp:539
QDebug info() const
Logs an informational message using a QDebug stream.
Definition qlogging.cpp:525
QNoDebug noDebug(...) const noexcept
QDebug info(CategoryFunction catFunc) const
\inmodule QtCore
Definition qmutex.h:332
Mutex * mutex() const noexcept
Returns the mutex on which the QMutexLocker is operating.
Definition qmutex.h:340
void unlock() noexcept
Unlocks this mutex locker.
Definition qmutex.h:338
~QMutexLocker() noexcept
Destroys the QMutexLocker and unlocks the mutex that was locked in the constructor.
Definition qmutex.h:336
void relock() noexcept
Relocks an unlocked mutex locker.
Definition qmutex.h:339
\inmodule QtCore
Definition qmutex.h:328
constexpr size_type capacity() const noexcept
Q_ALWAYS_INLINE constexpr void verify(qsizetype pos=0, qsizetype n=1) const
constexpr bool empty() const noexcept
QVLABaseBase()=default
constexpr size_type size() const noexcept
value_type value(qsizetype i, const T &defaultValue) const
const_reverse_iterator rend() const noexcept
void remove(qsizetype i, qsizetype n=1)
void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc)
const_reference operator[](qsizetype idx) const
value_type value(qsizetype i) const
const_reverse_iterator rbegin() const noexcept
reference emplace_back_impl(qsizetype prealloc, void *array, Args &&...args)
bool less_than(const QVLABase< S > &other) const
qsizetype removeIf(Predicate pred)
iterator erase(const_iterator pos)
const_reference back() const
reverse_iterator rbegin() noexcept
const_iterator cbegin() const noexcept
qsizetype lastIndexOf(const AT &t, qsizetype from=-1) const
void resize_impl(qsizetype prealloc, void *array, qsizetype sz, const T &v)
void growBy(qsizetype prealloc, void *array, qsizetype increment)
bool removeOne(const AT &t)
bool equal(const QVLABase< S > &other) const
void pop_back()
reference front()
iterator erase(const_iterator begin, const_iterator end)
const_reference front() const
bool isValidIterator(const const_iterator &i) const
const_iterator cend() const noexcept
static constexpr qsizetype maxSize() noexcept
const_reverse_iterator crbegin() const noexcept
iterator end() noexcept
void resize_impl(qsizetype prealloc, void *array, qsizetype sz)
void replace(qsizetype i, const T &t)
iterator insert_impl(qsizetype prealloc, void *array, const_iterator pos, qsizetype n, const T &t)
void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last)
reference operator[](qsizetype idx)
size_t hash(size_t seed) const noexcept(QtPrivate::QNothrowHashable_v< T >)
Q_OUTOFLINE_TEMPLATE void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last)
const_iterator end() const noexcept
qsizetype indexOf(const AT &t, qsizetype from=0) const
QVLABase()=default
const_iterator begin() const noexcept
qsizetype removeAll(const AT &t)
Q_INLINE_TEMPLATE bool contains(const AT &t) const
void append_impl(qsizetype prealloc, void *array, const T *buf, qsizetype n)
const_reverse_iterator crend() const noexcept
bool contains(const AT &t) const
reverse_iterator rend() noexcept
constexpr qsizetype max_size() const noexcept
reference back()
void assign_impl(qsizetype prealloc, void *array, qsizetype n, const T &t)
iterator begin() noexcept
iterator emplace_impl(qsizetype prealloc, void *array, const_iterator pos, Args &&...arg)
bool isEmpty() const
friend QTypeTraits::compare_lt_result< U > operator>(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(lhs< rhs))
QVarLengthArray & assign(InputIterator first, InputIterator last)
QVarLengthArray< T, Prealloc > & operator+=(const T &t)
iterator insert(const_iterator before, T &&x)
const T & first() const
T & emplace_back(Args &&...args)
const T & at(qsizetype idx) const
void resize(qsizetype sz)
QVarLengthArray< T, Prealloc > & operator=(const QVarLengthArray< T, Prealloc > &other)
qsizetype count() const
void push_back(T &&t)
QVarLengthArray(qsizetype sz, const T &v)
QVarLengthArray(const QVarLengthArray &other)
QVarLengthArray(qsizetype size)
iterator insert(const_iterator before, qsizetype n, const T &x)
QVarLengthArray(InputIterator first, InputIterator last)
iterator emplace(const_iterator pos, Args &&...args)
void insert(qsizetype i, T &&t)
QVarLengthArray(QVarLengthArray &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
friend QTypeTraits::compare_lt_result< U > operator<=(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(lhs< rhs))
const T & last() const
QVarLengthArray & operator=(QVarLengthArray &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
static constexpr qsizetype PreallocatedSize
friend QTypeTraits::compare_eq_result< U > operator==(const QVarLengthArray< T, Prealloc > &l, const QVarLengthArray< T, Prealloc2 > &r)
QVarLengthArray & assign(qsizetype n, const T &t)
QVarLengthArray< T, Prealloc > & operator+=(T &&t)
const_iterator constEnd() const
friend QTypeTraits::compare_eq_result< U > operator!=(const QVarLengthArray< T, Prealloc > &l, const QVarLengthArray< T, Prealloc2 > &r)
friend QTypeTraits::compare_lt_result< U > operator>=(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(lhs< rhs))
void resize(qsizetype sz, const T &v)
void append(const T *buf, qsizetype sz)
QVarLengthArray< T, Prealloc > & operator=(std::initializer_list< T > list)
friend auto compareThreeWay(const QVarLengthArray &lhs, const QVarLengthArray< T, Prealloc2 > &rhs)
QVarLengthArray(std::initializer_list< T > args)
qsizetype length() const
iterator insert(const_iterator before, const T &x)
friend QTypeTraits::compare_lt_result< U > operator<(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end())))
void insert(qsizetype i, const T &t)
void append(const T &t)
const T * constData() const
void push_back(const T &t)
auto constBegin() const -> const_iterator
QVarLengthArray() noexcept
void reserve(qsizetype sz)
QVarLengthArray & assign(std::initializer_list< T > list)
void insert(qsizetype i, qsizetype n, const T &t)
static Q_CONSTINIT thread_local bool msgHandlerGrabbed
static const char ifCriticalTokenC[]
static const char emptyTokenC[]
static Q_NEVER_INLINE void qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg, va_list ap)
Definition qlogging.cpp:333
static void preformattedMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &formattedMessage)
static bool systemHasStderr()
Returns true if writing to stderr is supported.
Definition qlogging.cpp:187
static const char endifTokenC[]
static bool isDefaultCategory(const char *category)
Definition qlogging.cpp:879
static const char messageTokenC[]
static constexpr SystemMessageSink systemMessageSink
static void qt_maybe_message_fatal(QtMsgType, const QMessageLogContext &context, String &&message)
\inmodule QtCore \title Qt Logging Types
#define HANDLE_IF_TOKEN(LEVEL)
Q_DECLARE_TYPEINFO(QMessagePattern::BacktraceParams, Q_RELOCATABLE_TYPE)
static const char timeTokenC[]
static bool is_fatal_count_down(QAtomicInt &n)
Definition qlogging.cpp:150
static const char qthreadptrTokenC[]
static const char fileTokenC[]
static const char ifDebugTokenC[]
static const char ifFatalTokenC[]
static const char categoryTokenC[]
static const char lineTokenC[]
static const char typeTokenC[]
static const char ifCategoryTokenC[]
static int checked_var_value(const char *varname)
Definition qlogging.cpp:136
static const char pidTokenC[]
Q_TRACE_POINT(qtcore, qt_message_print, int type, const char *category, const char *function, const char *file, int line, const QString &message)
static const char threadidTokenC[]
static QString formatLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &str)
static const char backtraceTokenC[]
static const char functionTokenC[]
#define IF_TOKEN(LEVEL)
static const char ifWarningTokenC[]
static const char appnameTokenC[]
static bool isFatal(QtMsgType msgType)
Definition qlogging.cpp:161
static const char ifInfoTokenC[]
static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message)
static bool stderrHasConsoleAttached()
Returns true if writing to stderr will end up in a console/terminal visible to the user.
Definition qlogging.cpp:212
Combined button and popup list for selecting options.
QDebug printAssociativeContainer(QDebug debug, const char *which, const AssociativeContainer &c)
Definition qdebug.h:386
bool shouldLogToStderr()
Returns true if logging stderr should be ensured.
Definition qlogging.cpp:265
QDebug printSequentialContainer(QDebug debug, const char *which, const SequentialContainer &c)
Definition qdebug.h:368
QByteArray operator""_ba(const char *str, size_t size) noexcept
Definition qbytearray.h:853
Definition qcompare.h:76
QT_BEGIN_NAMESPACE Q_NORETURN void qAbort()
Definition qassert.cpp:24
QByteArray operator+(const QByteArray &a1, const char *a2)
Definition qbytearray.h:709
QByteArray qUncompress(const QByteArray &data)
Definition qbytearray.h:778
QByteArray operator+(char a1, const QByteArray &a2)
Definition qbytearray.h:719
QByteArray operator+(QByteArray &&lhs, char rhs)
Definition qbytearray.h:715
QByteArray operator+(const QByteArray &a1, char a2)
Definition qbytearray.h:713
QByteArray operator+(const char *a1, const QByteArray &a2)
Definition qbytearray.h:717
QByteArray operator+(QByteArray &&lhs, const QByteArray &rhs)
Definition qbytearray.h:707
qsizetype erase_if(QByteArray &ba, Predicate pred)
Definition qbytearray.h:836
QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
Definition qbytearray.h:705
QByteArray qCompress(const QByteArray &data, int compressionLevel=-1)
Definition qbytearray.h:776
#define QT5_NULL_STRINGS
Definition qbytearray.h:25
qsizetype erase(QByteArray &ba, const T &t)
Definition qbytearray.h:830
QByteArray operator+(QByteArray &&lhs, const char *rhs)
Definition qbytearray.h:711
#define __has_builtin(x)
#define __has_include(x)
#define __has_cpp_attribute(x)
void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, Int value)
Definition qdebug.h:615
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, quint64 value)
Definition qdebug.cpp:1415
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, uint value)
Definition qdebug.cpp:1406
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2462
#define QT_MESSAGELOG_FUNC
Definition qlogging.h:161
Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(int code, const char *msg,...)
Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(const char *msg,...)
#define QT_MESSAGELOG_FILE
Definition qlogging.h:159
#define QT_MESSAGE_LOGGER_NORETURN
Definition qlogging.h:69
#define QT_MESSAGELOG_LINE
Definition qlogging.h:160
Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern)
#define QT_MESSAGELOGCONTEXT
Definition qlogging.h:154
QtMsgType
Definition qlogging.h:29
@ QtCriticalMsg
Definition qlogging.h:33
@ QtFatalMsg
Definition qlogging.h:34
@ QtDebugMsg
Definition qlogging.h:30
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const QString &message)
void(* QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &)
Definition qlogging.h:196
#define Q_LOGGING_CATEGORY(name,...)
#define QT_MESSAGE_LOGGER_COMMON(category, level)
#define Q_DECLARE_LOGGING_CATEGORY(name)
QMutex QBasicMutex
Definition qmutex.h:346
QScopeGuard(F(&)()) -> QScopeGuard< F(*)()>
qsizetype erase(QVarLengthArray< T, Prealloc > &array, const AT &t)
qsizetype erase_if(QVarLengthArray< T, Prealloc > &array, Predicate pred)
size_t qHash(const QVarLengthArray< T, Prealloc > &key, size_t seed=0) noexcept(QtPrivate::QNothrowHashable_v< T >)
void setPattern(const QString &pattern)
std::unique_ptr< std::unique_ptr< const char[]>[]> literals
std::chrono::steady_clock::time_point appStartTime
std::unique_ptr< const char *[]> tokens
QList< QString > timeArgs
static QBasicMutex mutex
void setDefaultPattern()
void operator()(void *p) const noexcept
static constexpr bool Value
Definition qdebug.h:680
static constexpr bool Value
Definition qdebug.h:676