summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--dependencies.yaml13
-rw-r--r--src/core/changes/qpropertynodeaddedchange_p.h1
-rw-r--r--src/core/changes/qpropertynoderemovedchange_p.h1
-rw-r--r--src/core/changes/qstaticpropertyupdatedchangebase_p.h1
-rw-r--r--src/core/resources/qboundedcircularbuffer_p.h149
-rw-r--r--src/core/resources/qcircularbuffer_p.h1330
-rw-r--r--src/core/resources/qframeallocator.cpp322
-rw-r--r--src/core/resources/qframeallocator_p.h112
-rw-r--r--src/core/resources/qframeallocator_p_p.h138
-rw-r--r--src/core/resources/qloadgltf_p.h7
-rw-r--r--src/core/resources/resources.pri7
-rw-r--r--src/doc/src/qcircularbuffer.qdoc1578
-rw-r--r--src/plugins/renderers/opengl/graphicshelpers/graphicscontext.cpp11
-rw-r--r--src/plugins/renderers/opengl/graphicshelpers/graphicscontext_p.h4
-rw-r--r--src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp6
-rw-r--r--src/plugins/renderers/opengl/jobs/renderviewinitializerjob.cpp1
-rw-r--r--src/plugins/renderers/opengl/jobs/renderviewinitializerjob_p.h1
-rw-r--r--src/plugins/renderers/opengl/jobs/renderviewjobutils_p.h4
-rw-r--r--src/plugins/renderers/opengl/opengl.pri2
-rw-r--r--src/plugins/renderers/opengl/renderer/frameprofiler_p.h2
-rw-r--r--src/plugins/renderers/opengl/renderer/renderer_p.h1
-rw-r--r--src/plugins/renderers/opengl/renderer/renderview_p.h1
-rw-r--r--src/plugins/renderers/opengl/renderer/shaderparameterpack.cpp2
-rw-r--r--src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h4
-rw-r--r--src/plugins/sceneparsers/gltfexport/gltfexporter.cpp38
-rw-r--r--src/plugins/sceneparsers/gltfexport/gltfexporter.h1
-rw-r--r--src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp5
-rw-r--r--src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp5
-rw-r--r--src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp2
-rw-r--r--src/quick3d/imports/input/qt3dquick3dinputplugin.cpp5
-rw-r--r--src/quick3d/imports/logic/qt3dquick3dlogicplugin.cpp5
-rw-r--r--src/quick3d/imports/render/qt3dquick3drenderplugin.cpp5
-rw-r--r--src/quick3d/imports/scene2d/qtquickscene2dplugin.cpp5
-rw-r--r--src/quick3d/imports/scene3d/qtquickscene3dplugin.cpp5
-rw-r--r--src/quick3d/quick3d/qt3dquicknodefactory.cpp2
-rw-r--r--src/quick3d/quick3danimation/qt3dquickanimationnodefactory.cpp2
-rw-r--r--src/quick3d/quick3dextras/qt3dquickextrasnodefactory.cpp2
-rw-r--r--src/quick3d/quick3dinput/qt3dquickinputnodefactory.cpp2
-rw-r--r--src/quick3d/quick3drender/qt3dquickrendernodefactory.cpp2
-rw-r--r--src/quick3d/quick3dscene2d/qt3dquickscene2dnodefactory.cpp2
-rw-r--r--src/render/framegraph/qrendercapture.cpp4
-rw-r--r--src/render/picking/qpicktriangleevent_p.h11
-rw-r--r--src/render/render.pro2
-rw-r--r--tests/auto/core/core.pro3
-rw-r--r--tests/auto/core/nodes/tst_nodes.cpp3
-rw-r--r--tests/auto/core/qboundedcircularbuffer/qboundedcircularbuffer.pro8
-rw-r--r--tests/auto/core/qboundedcircularbuffer/tst_qboundedcircularbuffer.cpp231
-rw-r--r--tests/auto/core/qcircularbuffer/qcircularbuffer.pro8
-rw-r--r--tests/auto/core/qcircularbuffer/tst_qcircularbuffer.cpp2044
-rw-r--r--tests/auto/core/qframeallocator/qframeallocator.pro7
-rw-r--r--tests/auto/core/qframeallocator/tst_qframeallocator.cpp767
-rw-r--r--tests/auto/input/mousedevice/tst_mousedevice.cpp38
-rw-r--r--tests/auto/render/commons/testrenderer.cpp4
-rw-r--r--tests/auto/render/gltfplugins/tst_gltfplugins.cpp9
-rw-r--r--tests/auto/render/opengl/renderviews/tst_renderviews.cpp2
-rw-r--r--tests/benchmarks/core/core.pro4
-rw-r--r--tests/benchmarks/core/qcircularbuffer/qcircularbuffer.pro8
-rw-r--r--tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp84
-rw-r--r--tests/benchmarks/core/qframeallocator/qframeallocator.pro6
-rw-r--r--tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp135
-rw-r--r--tools/qgltf/qgltf.cpp19
62 files changed, 120 insertions, 7065 deletions
diff --git a/.qmake.conf b/.qmake.conf
index 21b446c03..5c79e36dd 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -6,4 +6,4 @@ load(qt_build_config)
DEFINES += QT_NO_FOREACH
DEFINES += QT_NO_JAVA_STYLE_ITERATORS
-MODULE_VERSION = 5.15.0
+MODULE_VERSION = 6.0.0
diff --git a/dependencies.yaml b/dependencies.yaml
new file mode 100644
index 000000000..3987d7398
--- /dev/null
+++ b/dependencies.yaml
@@ -0,0 +1,13 @@
+dependencies:
+ ../qtbase:
+ ref: a13e8d6660913bec172d1374f78083498c539df0
+ required: true
+ ../qtdeclarative:
+ ref: 94d385327d932d27b7277e803d0eaa167f792222
+ required: false
+ ../qtgamepad:
+ ref: 3bf17cf8782d0cf38daaf6fc8afdd33517d382b0
+ required: false
+ ../qtimageformats:
+ ref: eb02e051725510dea7daf0d035ef635efbb6b993
+ required: false
diff --git a/src/core/changes/qpropertynodeaddedchange_p.h b/src/core/changes/qpropertynodeaddedchange_p.h
index 2930867ea..50840501c 100644
--- a/src/core/changes/qpropertynodeaddedchange_p.h
+++ b/src/core/changes/qpropertynodeaddedchange_p.h
@@ -60,7 +60,6 @@ QT_BEGIN_NAMESPACE
namespace Qt3DCore {
class QPropertyUpdatedChange;
-class QFrameAllocator;
class QPropertyNodeAddedChangePrivate : public QStaticPropertyValueAddedChangeBasePrivate
{
diff --git a/src/core/changes/qpropertynoderemovedchange_p.h b/src/core/changes/qpropertynoderemovedchange_p.h
index 0145cc507..8df349757 100644
--- a/src/core/changes/qpropertynoderemovedchange_p.h
+++ b/src/core/changes/qpropertynoderemovedchange_p.h
@@ -60,7 +60,6 @@ QT_BEGIN_NAMESPACE
namespace Qt3DCore {
class QPropertyUpdatedChange;
-class QFrameAllocator;
class QPropertyNodeRemovedChangePrivate : public QStaticPropertyValueRemovedChangeBasePrivate
{
diff --git a/src/core/changes/qstaticpropertyupdatedchangebase_p.h b/src/core/changes/qstaticpropertyupdatedchangebase_p.h
index 3f76e2f56..6b7d4c974 100644
--- a/src/core/changes/qstaticpropertyupdatedchangebase_p.h
+++ b/src/core/changes/qstaticpropertyupdatedchangebase_p.h
@@ -58,7 +58,6 @@ QT_BEGIN_NAMESPACE
namespace Qt3DCore {
class QPropertyUpdatedChange;
-class QFrameAllocator;
class QStaticPropertyUpdatedChangeBasePrivate : public QPropertyUpdatedChangeBasePrivate
{
diff --git a/src/core/resources/qboundedcircularbuffer_p.h b/src/core/resources/qboundedcircularbuffer_p.h
deleted file mode 100644
index 22299d7da..000000000
--- a/src/core/resources/qboundedcircularbuffer_p.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QT3DCORE_QBOUNDEDCIRCULARBUFFER_P_H
-#define QT3DCORE_QBOUNDEDCIRCULARBUFFER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/QReadWriteLock>
-#include <QtCore/QReadLocker>
-#include <QtCore/QSemaphore>
-#include <QtCore/QtGlobal>
-
-#include <Qt3DCore/private/qcircularbuffer_p.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DCore {
-
-template <class T>
-class QBoundedCircularBuffer
-{
-public:
- explicit QBoundedCircularBuffer(int capacity_)
- : m_free( capacity_ ),
- m_used( capacity_ ),
- m_buffer( capacity_ )
- {
- m_used.acquire(capacity_);
- }
-
- int capacity() const { return m_buffer.capacity(); }
- int freeSize() const { return m_free.available(); }
- int size() const { return m_used.available(); }
- bool isFull() const { return m_free.available() == 0; }
- bool isEmpty() const { return m_used.available() == 0; }
-
- void push_back(const T &value)
- {
- m_free.acquire();
- QWriteLocker locker(&m_lock);
- m_buffer.append(value);
- locker.unlock();
- m_used.release();
- }
-
- void push(const T &t) { push_back(t); }
- void append(const T &t) { push_back(t); }
-
- T pop_front()
- {
- m_used.acquire();
- QWriteLocker locker(&m_lock);
- T value = m_buffer.first();
- m_buffer.remove(0);
- locker.unlock();
- m_free.release();
- return value;
- }
-
- T pop() { return pop_front(); }
- T takeFirst() { return pop_front(); }
-
- void clear()
- {
- QWriteLocker locker(&m_lock);
- m_buffer.clear();
- int used = m_used.available();
- m_free.release(used);
- m_used.acquire(used);
- }
-
- T at(int i) const
- {
- QReadLocker readLocker(&m_lock);
- return m_buffer.at(i);
- }
-
- T front() const
- {
- QReadLocker readLocker(&m_lock);
- return m_buffer.front();
- }
-
- T back() const
- {
- QReadLocker readLocker(&m_lock);
- return m_buffer.back();
- }
-
-protected:
- Q_DISABLE_COPY(QBoundedCircularBuffer)
-
- QSemaphore m_free;
- QSemaphore m_used;
- QCircularBuffer<T> m_buffer;
- mutable QReadWriteLock m_lock;
-};
-
-} //Qt3D
-
-QT_END_NAMESPACE
-
-#endif // QT3DCORE_QBOUNDEDCIRCULARBUFFER_P_H
diff --git a/src/core/resources/qcircularbuffer_p.h b/src/core/resources/qcircularbuffer_p.h
deleted file mode 100644
index e10b7236d..000000000
--- a/src/core/resources/qcircularbuffer_p.h
+++ /dev/null
@@ -1,1330 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QT3DCORE_QCIRCULARBUFFER_H
-#define QT3DCORE_QCIRCULARBUFFER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <Qt3DCore/qt3dcore_global.h>
-#include <QtCore/QtGlobal>
-#include <QtCore/qlist.h>
-#include <QtCore/qpair.h>
-#include <QtCore/qshareddata.h>
-#include <QtCore/qvector.h>
-
-#include <algorithm>
-#include <iterator>
-#include <limits>
-#include <memory>
-#include <new>
-
-
-#ifdef Q_COMPILER_INITIALIZER_LISTS
-# include <initializer_list>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DCore {
-
-class CircularBufferData : public QSharedData
-{
-protected:
- CircularBufferData()
- : data(nullptr),
- capacity(0),
- size(0),
- first(-1),
- last(-1)
- {}
-
- ~CircularBufferData()
- {
- // Release the raw memory
- deallocate(data);
- }
-
- int wraparound(int index) const
- {
- index = index < capacity ? index : (index - capacity);
- Q_ASSERT(index < capacity); // make sure that wrapping around once was enough
- return index;
- }
-
- void *allocate(int count, size_t sizeOfT)
- { return operator new[](count * sizeOfT); }
- void deallocate(void *p)
- { operator delete[](p); }
-
- void *data; // Array of the actual data
-public:
- int capacity; // Size of the m_data array
- int size; // Number of elements of m_data actually used
- int first; // Index in m_data of the first element of the circular buffer
- int last; // Index in m_data of the last element of the circular buffer
-};
-
-template <typename T>
-class TypedCircularBufferData : public CircularBufferData
-{
- template <typename InputIterator>
- explicit TypedCircularBufferData(InputIterator f, InputIterator l, std::input_iterator_tag) Q_DECL_EQ_DELETE;
-public:
- TypedCircularBufferData() : CircularBufferData() {}
- template <typename ForwardIterator>
- explicit TypedCircularBufferData(ForwardIterator f, ForwardIterator l, std::forward_iterator_tag)
- {
- const int n = int(std::distance(f, l));
- CircularBufferData::data = allocate(n);
- std::uninitialized_copy(f, l, data());
- first = 0;
- last = n - 1;
- size = capacity = n;
- }
- ~TypedCircularBufferData()
- {
- if (QTypeInfo<T>::isComplex && size != 0) {
- // The type is complex so we manually call the destructor for each item
- // since we used the placement new operator to instantiate them
- if (first <= last) {
- // Destroy items from first to last
- T *b = data() + first;
- T *i = b + size;
- while (i-- != b)
- i->~T();
- } else {
- // Destroy items at end of data array
- T *b = data() + first;
- T *i = data() + capacity;
- while (i-- != b)
- i->~T();
-
- // Destroy items at beginning of data array
- b = data();
- i = b + last;
- while (i-- != b)
- i->~T();
- }
- }
-
- }
-
- using CircularBufferData::wraparound;
- T *allocate(int count) { return static_cast<T*>(CircularBufferData::allocate(count, sizeof(T))); }
- using CircularBufferData::deallocate;
- T *data() const { return static_cast<T*>(CircularBufferData::data); }
- void setData(T *newdata) { CircularBufferData::data = static_cast<void*>(newdata); }
-};
-
-template <typename T>
-class QCircularBuffer
-{
- typedef TypedCircularBufferData<T> Data;
-public:
- typedef QPair<T*,int> array_range;
- typedef QPair<const T*,int> const_array_range;
- typedef array_range ArrayRange;
- typedef const_array_range ConstArrayRange;
-
- QCircularBuffer()
- : d(new Data())
- {}
-
- explicit QCircularBuffer(int amount);
- explicit QCircularBuffer(int amount, const T &val);
- explicit QCircularBuffer(int amount, int initialSize, const T &value);
-#ifdef Q_COMPILER_INITIALIZER_LISTS
- QCircularBuffer(std::initializer_list<T> list)
- : d(new Data(list.begin(), list.end(), std::random_access_iterator_tag()))
- {}
-#endif
- template <typename ForwardIterator>
- explicit QCircularBuffer(ForwardIterator f, ForwardIterator l)
- : d(new Data(f, l, typename std::iterator_traits<ForwardIterator>::iterator_category()))
- {}
-
- QCircularBuffer(const QCircularBuffer<T> &other)
- : d(other.d)
- {}
-
- void swap(QCircularBuffer &other) { d.swap(other.d); }
-
- QCircularBuffer<T> &operator = (const QCircularBuffer<T> &other)
- {
- d = other.d;
- return *this;
- }
-
- ~QCircularBuffer() {}
-
- class iterator
- {
- public:
- typedef std::random_access_iterator_tag iterator_category;
- typedef ptrdiff_t difference_type;
- typedef T value_type;
- typedef T *pointer;
- typedef T &reference;
-
- Q_DECL_CONSTEXPR iterator() : buffer(nullptr), index(-1) {}
- iterator(QCircularBuffer<T> *buf, int idx)
- : buffer(buf), index(idx)
- {}
-
- T &operator*() const { return (*buffer)[ index ]; }
- T *operator->() const { return &(*buffer)[index]; }
- T &operator[](int j) const { return (*buffer)[ index + j ]; }
-
- bool operator==(const iterator &other) const
- {
- return (buffer == other.buffer && index == other.index);
- }
-
- bool operator!=(const iterator &other) const
- {
- return (buffer != other.buffer || index != other.index);
- }
-
- bool operator<(const iterator &other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::iterator::operator<", "iterators use different buffers");
- return index < other.index;
- }
-
- bool operator<=(const iterator &other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::iterator::operator<=", "iterators use different buffers");
- return index <= other.index;
- }
-
- bool operator>(const iterator &other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::iterator::operator>", "iterators use different buffers");
- return index > other.index;
- }
-
- bool operator>=(const iterator &other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::iterator::operator>=", "iterators use different buffers");
- return index >= other.index;
- }
-
- iterator &operator++() { ++index; return *this; }
- iterator operator++(int)
- {
- iterator ans = *this;
- ++index;
- return ans;
- }
-
- iterator &operator--() { --index; return *this; }
- iterator operator--(int)
- {
- iterator ans = *this;
- --index;
- return ans;
- }
-
- iterator &operator+=(int j) { index += j; return *this; }
- iterator &operator-=(int j) { index -= j; return *this; }
- iterator operator+(int j) const { return iterator(buffer, index + j); }
- iterator operator-(int j) const { return iterator(buffer, index - j); }
- int operator-(iterator other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::iterator::operator-", "iterators use different buffers");
- return index - other.index;
- }
-
- private:
- QCircularBuffer<T> *buffer;
- int index;
- friend class QCircularBuffer;
- };
- friend class iterator;
-
- class const_iterator
- {
- public:
- typedef std::random_access_iterator_tag iterator_category;
- typedef ptrdiff_t difference_type;
- typedef T value_type;
- typedef const T *pointer;
- typedef const T &reference;
-
- Q_DECL_CONSTEXPR const_iterator() : buffer(nullptr), index(-1) {}
- const_iterator(const QCircularBuffer<T> *buff, int idx)
- : buffer(buff), index(idx)
- {}
- const_iterator(const iterator &other)
- : buffer(other.buffer), index(other.index)
- {}
-
- const T &operator*() const { return buffer->at(index); }
- const T *operator->() const { return &buffer->at(index); }
- const T &operator[](int j) const { return buffer->at(index + j); }
-
- bool operator==(const const_iterator &other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::const_iterator::operator==", "iterators use different buffers");
- return index == other.index;
- }
-
- bool operator!=(const const_iterator &other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::const_iterator::operator!=", "iterators use different buffers");
- return index != other.index;
- }
-
- bool operator<(const const_iterator &other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::const_iterator::operator<", "iterators use different buffers");
- return index < other.index;
- }
-
- bool operator<=(const const_iterator &other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::const_iterator::operator<=", "iterators use different buffers");
- return index <= other.index;
- }
-
- bool operator>(const const_iterator &other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::const_iterator::operator>", "iterators use different buffers");
- return index > other.index;
- }
-
- bool operator>=(const const_iterator &other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::const_iterator::operator>=", "iterators use different buffers");
- return index >= other.index;
- }
-
- const_iterator &operator++() { ++index; return *this; }
- const_iterator operator++(int)
- {
- const_iterator ans = *this;
- ++index;
- return ans;
- }
-
- const_iterator &operator--() { --index; return *this; }
- const_iterator operator--(int)
- {
- const_iterator ans = *this;
- --index;
- return ans;
- }
-
- const_iterator &operator+=(int j) { index += j; return *this; }
- const_iterator &operator-=(int j) { index -= j; return *this; }
- const_iterator operator+(int j) const { return const_iterator(buffer, index + j); }
- const_iterator operator-(int j) const { return const_iterator(buffer, index - j); }
- int operator-(const_iterator other) const
- {
- Q_ASSERT_X(buffer == other.buffer, "QCircularBuffer<T>::const_iterator::operator-", "iterators use different buffers");
- return index - other.index;
- }
-
- private:
- const QCircularBuffer<T> *buffer;
- int index;
- friend class QCircularBuffer;
- };
- friend class const_iterator;
-
- typedef std::reverse_iterator<iterator> reverse_iterator;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
-
- iterator begin() { return iterator(this, 0); }
- const_iterator begin() const { return const_iterator(this, 0); }
- const_iterator cbegin() const { return const_iterator(this, 0); }
- reverse_iterator rbegin() { return reverse_iterator(end()); }
- const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
- const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); }
- const_iterator constBegin() const { return const_iterator(this, 0); }
- iterator end() { return iterator(this, d->size); }
- const_iterator end() const { return const_iterator(this, d->size); }
- const_iterator cend() const { return const_iterator(this, d->size); }
- reverse_iterator rend() { return reverse_iterator(begin()); }
- const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
- const_reverse_iterator crend() const { return const_reverse_iterator(begin()); }
- const_iterator constEnd() const { return const_iterator(this, d->size); }
- iterator insert(const_iterator before, int number, const T &val)
- {
- insert(before.index, number, val);
- return iterator(this, before.index);
- }
- iterator insert(const_iterator before, const T &val) { return insert(before, 1, val); }
- iterator erase(const_iterator b, const_iterator e)
- {
- int number = e - b;
- remove(b.index, number);
- return iterator(this, e.index - number);
- }
- iterator erase(const_iterator pos) { return erase(pos, pos + 1); }
-
- // STL compatibility
- typedef T value_type;
- typedef value_type *pointer;
- typedef const value_type *const_pointer;
- typedef value_type &reference;
- typedef const value_type &const_reference;
- typedef ptrdiff_t difference_type;
- typedef iterator Iterator;
- typedef const_iterator ConstIterator;
- typedef int size_type;
-
- void push_back(const T &t) { append(t); }
- void push_front(const T &t) { prepend(t); }
- void pop_back() { Q_ASSERT(!isEmpty()); erase(end() - 1); }
- void pop_front() { Q_ASSERT(!isEmpty()); erase(begin()); }
- bool empty() const { return isEmpty(); }
- T &front() { return first(); }
- const T &front() const { return first(); }
- T &back() { return last(); }
- const T &back() const { return last(); }
-
- QAtomicInt refCount() const { return d->ref; }
-
- void append(const T &val);
-
- const T &at(int i) const
- {
- Q_ASSERT_X(i >= 0 && i < d->size, "QCircularBuffer<T>::at", "index out of range");
- return d->data()[d->wraparound(d->first + i)];
- }
-
- const T &operator[](int i) const
- {
- Q_ASSERT_X(i >= 0 && i < d->size, "QCircularBuffer<T>::operator[]", "index out of range");
- return d->data()[d->wraparound(d->first + i)];
- }
-
- T &operator[](int i)
- {
- d.detach();
- Q_ASSERT_X(i >= 0 && i < d->size, "QCircularBuffer<T>::operator[]", "index out of range");
- return d->data()[d->wraparound(d->first + i)];
- }
-
- int capacity() const { return d->capacity; }
-
- void clear() { *this = QCircularBuffer<T>(d->capacity); }
-
- bool contains(const T &val) const;
- int count(const T &val) const;
- int count() const { return size(); }
-
- array_range data()
- {
- d.detach();
- if (d->size == 0)
- return array_range(nullptr, 0);
- if (!isLinearised())
- linearise();
- return array_range(d->data() + d->first, d->last - d->first + 1);
- }
- const_array_range data() const { return constData(); }
- const_array_range constData() const
- {
- if (!isLinearised() || d->size == 0)
- return const_array_range(nullptr, 0);
- return const_array_range(d->data() + d->first, d->last - d->first + 1);
- }
-
- array_range dataOne()
- {
- d.detach();
- if (d->size == 0)
- return array_range(nullptr, 0);
- if (isLinearised())
- return array_range(d->data() + d->first, d->last - d->first + 1);
- else
- return array_range(d->data() + d->first, d->capacity - d->first);
- }
- const_array_range dataOne() const { return constDataOne(); }
- const_array_range constDataOne() const
- {
- if (d->size == 0)
- return const_array_range(nullptr, 0);
- if (isLinearised())
- return const_array_range(d->data() + d->first, d->last - d->first + 1);
- else
- return const_array_range(d->data() + d->first, d->capacity - d->first);
- }
-
- array_range dataTwo()
- {
- d.detach();
- if (d->size == 0 || isLinearised())
- return array_range(nullptr, 0);
- return array_range(d->data(), d->last + 1);
- }
- const_array_range dataTwo() const { return constDataTwo(); }
- const_array_range constDataTwo() const
- {
- if (d->size == 0 || isLinearised())
- return const_array_range(nullptr, 0);
- return const_array_range(d->data(), d->last + 1);
- }
-
- bool endsWith(const T &val) const { return !isEmpty() && last() == val; }
- QCircularBuffer<T> &fill(const T &val, int number = -1);
- T &first() { Q_ASSERT(!isEmpty()); d.detach(); return d->data()[ d->first ]; }
- const T &first() const { Q_ASSERT(!isEmpty()); return d->data()[ d->first ]; }
- int freeSize() const { return sizeAvailable(); }
-
- static QCircularBuffer<T> fromList(const QList<T> &list)
- { return QCircularBuffer(list.begin(), list.end()); }
- static QCircularBuffer<T> fromVector(const QVector<T> &vector)
- { return QCircularBuffer(vector.begin(), vector.end()); }
-
- int indexOf(const T &val, int from = 0) const;
- void insert(int i, const T &val) { insert(i, 1, val); }
- void insert(int i, int number, const T &val);
- bool isEmpty() const { return d->size == 0; }
- bool isFull() const { return d->size == d->capacity; }
- bool isLinearised() const { return (d->last >= d->first); }
- T &last() { Q_ASSERT(!isEmpty()); return d->data()[ d->last ]; }
- const T &last() const { Q_ASSERT(!isEmpty()); return d->data()[ d->last ]; }
- int lastIndexOf(const T &val, int from = -1) const;
- void linearise()
- {
- if (!isLinearised()) {
- QCircularBuffer linearized(this->cbegin(), this->cend());
- swap(linearized);
- }
- }
-
- void prepend(const T &val);
- void remove(int i) { remove(i, 1); }
- void remove(int i, int number);
-
- void replace(int i, const T &val)
- {
- Q_ASSERT_X(i >= 0 && i < d->size, "QCircularBuffer<T>::replace", "index out of range");
- const T copy(val);
- (*this)[ i ] = copy;
- }
-
- void reserve(int amount) { setCapacity(amount); }
- void resize(int newSize);
- void setCapacity(int amount);
- int size() const { return d->size; }
- Q_DECL_CONSTEXPR int max_size() const { return std::numeric_limits<size_type>::max(); }
- int sizeAvailable() const { return d->capacity - d->size; }
- void squeeze() { setCapacity(size()); }
- bool startsWith(const T &val) const { return !isEmpty() && first() == val; }
-
- QList<T> toList() const;
- QVector<T> toVector() const;
-
- T value(int i) const
- {
- if (i < 0 || i >= d->size)
- return T();
- return at(i);
- }
-
- T value(int i, const T &defaultValue) const
- {
- if (i < 0 || i >= d->size)
- return defaultValue;
- return at(i);
- }
-
- QCircularBuffer<T> &operator+=(const T &other) { append(other); return *this; }
- QCircularBuffer<T> &operator+=(const QCircularBuffer<T> &other);
- QCircularBuffer<T> &operator+=(const QVector<T> &other);
- QCircularBuffer<T> &operator+=(const QList<T> &other);
-
- QCircularBuffer<T> &operator<<(const T &other) { append(other); return *this; }
- QCircularBuffer<T> &operator<<(const QCircularBuffer<T> &other) { *this += other; return *this; }
- QCircularBuffer<T> &operator<<(const QVector<T> &other) { *this += other; return *this; }
- QCircularBuffer<T> &operator<<(const QList<T> &other) { *this += other; return *this; }
-
- inline bool isSharedWith(const QCircularBuffer &other) const { return d == other.d; }
-
-private:
- QExplicitlySharedDataPointer<Data> d;
-};
-
-template <typename T>
-QCircularBuffer<T> operator+(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs);
-
-template <typename T>
-inline bool operator==(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-{ return lhs.isSharedWith(rhs) || (lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin())); }
-
-template <typename T>
-inline bool operator!=(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-{ return !operator==(lhs, rhs); }
-
-template <typename T>
-inline void swap(QCircularBuffer<T> &lhs, QCircularBuffer<T> &rhs)
-{ lhs.swap(rhs); }
-
-template <typename T>
-inline bool operator< (const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-{ return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); }
-
-template <typename T>
-inline bool operator> (const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-{ return operator<(rhs, lhs); }
-
-template <typename T>
-inline bool operator>=(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-{ return !operator<(lhs, rhs); }
-
-template <typename T>
-inline bool operator<=(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-{ return !operator>(lhs, rhs); }
-
-// out-of-line function implementations:
-
-#ifndef Q_QDOC
-
-template <typename T>
-QCircularBuffer<T>::QCircularBuffer(int amount)
- : d(new Data())
-{
- // Allocate some raw memory
- d->setData(d->allocate(amount));
- d->capacity = amount;
-
- // Initialize memory block to zero
- memset(d->data(), 0, amount * sizeof(T));
-}
-
-template <typename T>
-QCircularBuffer<T>::QCircularBuffer(int amount, const T &val)
- : d(new Data())
-{
- // Allocate some raw memory
- d->setData(d->allocate(amount));
- d->capacity = amount;
-
- // Initialize the objects. In this case we always use the placement new operator
- T *b = d->data();
- T *i = b + d->capacity;
- while (i != b)
- new (--i) T(val);
- d->first = 0;
- d->last = d->capacity - 1;
- d->size = d->capacity;
-}
-
-template <typename T>
-QCircularBuffer<T>::QCircularBuffer(int amount, int initialSize, const T &val)
- : d(new Data())
-{
- Q_ASSERT_X(amount >= initialSize, "QCircularBuffer<T>::QCircularBuffer(int capacity, int size, const T &value)", "size is greater than capacity");
-
- // Allocate some raw memory
- d->setData(d->allocate(amount));
- d->capacity = amount;
-
- // Initialize the objects that need to be set to the specified value.
- // In this case we always use the placement new operator
- T *b = d->data();
- T *i = b + initialSize;
- while (i != b)
- new (--i) T(val);
-
- // Initialize the remaining memory to zero
- memset(d->data() + initialSize, 0, (amount - initialSize) * sizeof(T));
-
- d->first = 0;
- d->last = initialSize - 1;
- d->size = initialSize;
-}
-
-template <typename T>
-void QCircularBuffer<T>::append(const T &val)
-{
- // If we have no capacity we do nothing
- if (!d->capacity)
- return;
- d.detach();
- if (d->size == d->capacity) {
- // Buffer is full. Overwrite earliest item and rotate
- d->data()[ d->first ] = val;
- d->first = d->wraparound(++d->first);
- d->last = d->wraparound(++d->last);
- } else if (d->size != 0) {
- // Buffer is partially full. Append data to end of array using appropriate method
- int index = d->wraparound(d->first + d->size);
- if (QTypeInfo<T>::isComplex)
- new (d->data() + index) T(val);
- else
- d->data()[ index ] = val;
- ++d->size;
- ++d->last;
- } else {
- // Buffer is empty. Append data to end of array using appropriate method
- d->size = 1;
- d->first = d->last = 0;
- if (QTypeInfo<T>::isComplex)
- new (d->data() + d->first) T(val);
- else
- d->data()[ d->first ] = val;
- }
-}
-
-template <typename T>
-bool QCircularBuffer<T>::contains(const T &val) const
-{
- if (isLinearised()) {
- T *b = d->data() + d->first;
- T *i = b + d->size;
- while (i != b)
- if (*--i == val)
- return true;
- return false;
- } else {
- // Check the array from m_first to the end
- T *b = d->data() + d->first;
- T *i = d->data() + d->capacity;
- while (i != b)
- if (*--i == val)
- return true;
-
- // Check array from 0 to m_end
- b = d->data();
- i = d->data() + d->last + 1;
- while (i != b)
- if (*--i == val)
- return true;
-
- return false;
- }
-}
-
-template <typename T>
-int QCircularBuffer<T>::count(const T &val) const
-{
- int c = 0;
- if (isLinearised()) {
- T *b = d->data() + d->first;
- T *i = b + d->size;
- while (i != b)
- if (*--i == val)
- ++c;
- } else {
- // Check the array from m_first to the end
- T *b = d->data() + d->first;
- T *i = d->data() + d->capacity;
- while (i != b)
- if (*--i == val)
- ++c;
-
- // Check array from 0 to m_end
- b = d->data();
- i = d->data() + d->last + 1;
- while (i != b)
- if (*--i == val)
- ++c;
- }
- return c;
-}
-
-template <typename T>
-QCircularBuffer<T> &QCircularBuffer<T>::fill(const T &val, int number)
-{
- Q_ASSERT_X(d->capacity >= number, "QCircularBuffer<T>::fill", "size is greater than capacity");
- const T copy(val);
- d.detach();
- int oldSize = d->size;
- d->size = (number < 0 ? d->size : number);
- d->first = (number == 0 ? -1 : 0);
- d->last = d->size - 1;
-
- // Copy item into array size times
- if (d->size) {
- T *b = d->data();
- T *i = d->data() + d->size;
- while (i != b)
- *--i = copy;
- }
-
- if (d->size < oldSize) {
- // Cleanup old items beyond end of new array
- T *b = d->data() + d->size;
- T *i = d->data() + oldSize;
- while (i-- != b) {
- i->~T();
- //TODO: Optimize to a single memset call
- memset(i, 0, sizeof(T));
- }
- }
-
- return *this;
-}
-
-template <typename T>
-int QCircularBuffer<T>::indexOf(const T &val, int from) const
-{
- Q_ASSERT_X(from < d->size, "QCircularBuffer<T>::indexOf", "from is greater than last valid index");
- if (from < 0)
- from = qMax(from + d->size, 0);
- else if (from >= d->size)
- from = d->size - 1;
- for (int i = from; i < d->size; ++i)
- if (at(i) == val)
- return i;
- return -1;
-}
-
-template <typename T>
-void QCircularBuffer<T>::insert(int i, int number, const T &val)
-{
- Q_ASSERT_X(i >= 0 && i <= d->size, "QCircularBuffer<T>::insert", "index out of range");
- d.detach();
- int freeCapacity = d->capacity - d->size;
-
- // Calculate number of elements that will actually be inserted. This
- // depends upon where the insertion has been requested and any spare
- // capacity left in the buffer. This is because elements at higher
- // indices will be pushed to the right and will potentially wrap around
- // to overwrite earlier elements.
- int numToInsert = qMin(number, i + freeCapacity);
-
- // Calculate the number of elements at the beginning of the buffer that
- // will be overwritten
- int numToOverwrite = qMin(i, qMax(0, number - freeCapacity));
-
- // Decide which way to shift to minimize the amount of copying required.
- if (i < d->size / 2) {
- // Inserting in lower half of buffer so we shift earlier items down
-
- // Shift data at the bottom end down. This may only be a subset if some
- // of the early data is to be overwritten.
- if (QTypeInfo<T>::isStatic) {
- int b = d->first + numToOverwrite;
- int e = d->first + i - 1;
- for (int j = b; j <= e; ++j) {
- int srcIndex = j % d->capacity;
- int dstIndex = (j - numToInsert + d->capacity) % d->capacity;
- T *src = d->data() + srcIndex;
- T *dst = d->data() + dstIndex;
-
- new (dst) T(*src);
- }
- } else {
- // We have a movable type so a simple memcopy (or maybe two or
- // three) will suffice to shift the data at the bottom end
- int numToMove = i - numToOverwrite;
- if (numToMove > 0) {
- int srcBegin = (d->first + numToOverwrite) % d->capacity;
- int srcEnd = (d->first + i - 1) % d->capacity;
- int dstBegin = (srcBegin - numToInsert + d->capacity) % d->capacity;
- int dstEnd = (srcEnd - numToInsert + d->capacity) % d->capacity;
-
- // Do we have any wrap-around problems to deal with?
- bool srcRegionWraps = (srcEnd < srcBegin);
- bool dstRegionWraps = (dstEnd < dstBegin);
- if (!srcRegionWraps && dstRegionWraps) {
- // Destination region wraps so do the move in two steps
- int wrapCount = abs(srcBegin - numToInsert);
- memmove(d->data() + d->capacity - wrapCount, d->data() + srcBegin, wrapCount * sizeof(T));
- memmove(d->data(), d->data() + srcBegin + wrapCount, (numToMove - wrapCount) * sizeof(T));
- } else if (srcRegionWraps && !dstRegionWraps) {
- // Source region wraps so do the move in two steps
- int wrapCount = d->capacity - srcBegin;
- memmove(d->data() + dstBegin, d->data() + d->capacity - wrapCount, wrapCount * sizeof(T));
- memmove(d->data() + dstBegin + numToInsert, d->data(), (numToMove - wrapCount) * sizeof(T));
- } else if (srcRegionWraps && dstRegionWraps) {
- // Source and destination regions wrap so we have to do this in three steps
- int srcWrapCount = d->capacity - srcBegin;
- memmove(d->data() + dstBegin, d->data() + d->capacity - srcWrapCount, srcWrapCount * sizeof(T));
- memmove(d->data() + d->capacity - numToInsert, d->data(), numToInsert * sizeof(T));
- memmove(d->data(), d->data() + numToInsert, (numToMove - srcWrapCount - numToInsert) * sizeof(T));
- } else {
- // No wrap around - do a single memmove
- memmove(d->data() + dstBegin, d->data() + srcBegin, numToMove * sizeof(T));
- }
- }
- }
-
- // Insert the new items
- int e = d->first + i;
- int b = e - numToInsert;
- for (int j = b; j < e; ++j) {
- T *p = d->data() + ((j + d->capacity) % d->capacity);
- new (p) T(val);
- }
-
- // Adjust the first, last and size indices as needed.
- // NB. The last index never changes in this regime.
- d->size += qMin(number, freeCapacity);
- d->first = (d->first - (numToInsert - numToOverwrite) + d->capacity) % d->capacity;
- } else {
- // Inserting in upper half of buffer so we shift later items up
-
- // Shift data at the top end up which may or may not overwrite some
- // of the earliest data
- if (QTypeInfo<T>::isStatic) {
- int b = d->first + d->size - 1;
- int e = d->first + i;
- for (int j = b; j >= e; j--) {
- int srcIndex = j % d->capacity;
- int dstIndex = (j + numToInsert) % d->capacity;
- T *src = d->data() + srcIndex;
- T *dst = d->data() + dstIndex;
-
- new (dst) T(*src);
- }
- } else {
- // We have a movable type so a simple memcopy (or maybe two or
- // three) will suffice to shift the data at the top end
- int numToMove = d->size - i;
- if (numToMove > 0) {
- int srcBegin = (d->first + i) % d->capacity;
- int srcEnd = d->last;
- int dstBegin = (srcBegin + numToInsert) % d->capacity;
- int dstEnd = (srcEnd + numToInsert) % d->capacity;
-
- // Do we have any wrap-around problems to deal with?
- bool srcRegionWraps = (srcEnd < srcBegin);
- bool dstRegionWraps = (dstEnd < dstBegin);
- if (!srcRegionWraps && dstRegionWraps) {
- // Destination region wraps so do the move in two steps
- int wrapCount = srcEnd + numToInsert - d->capacity + 1;
- memmove(d->data(), d->data() + srcEnd - wrapCount + 1, wrapCount * sizeof(T));
- memmove(d->data() + dstBegin, d->data() + srcBegin, (numToMove - wrapCount) * sizeof(T));
- } else if (srcRegionWraps && !dstRegionWraps) {
- // Source region wraps so do the move in two steps
- int wrapCount = d->last + 1;
- memmove(d->data() + numToInsert, d->data(), wrapCount * sizeof(T));
- memmove(d->data() + dstBegin, d->data() + srcBegin, (numToMove - wrapCount) * sizeof(T));
- } else if (srcRegionWraps && dstRegionWraps) {
- // Source and destination regions wrap so we have to do this in three steps
- int srcWrapCount = d->last + 1;
- memmove(d->data() + numToInsert, d->data(), srcWrapCount * sizeof(T));
- memmove(d->data(), d->data() + d->capacity - numToInsert, numToInsert * sizeof(T));
- memmove(d->data() + dstBegin, d->data() + srcBegin, (numToMove - srcWrapCount - numToInsert) * sizeof(T));
- } else {
- // No wrap around - do a single memmove
- memmove(d->data() + dstBegin, d->data() + srcBegin, numToMove * sizeof(T));
- }
- }
- }
-
- // Insert the new items
- for (int j = d->first + i; j < d->first + i + numToInsert; ++j) {
- T *p = d->data() + (j % d->capacity);
- new (p) T(val);
- }
-
- // Adjust the first, last and size indices as needed
- d->size += qMin(number, freeCapacity);
- d->first = (d->first + numToOverwrite) % d->capacity;
- d->last = (d->last + numToInsert) % d->capacity;
- }
-}
-
-template <typename T>
-int QCircularBuffer<T>::lastIndexOf(const T &val, int from) const
-{
- if (from < 0)
- from = qMax(from + d->size, 0);
- else if (from >= d->size)
- from = d->size - 1;
- for (int i = from; i >= 0; --i)
- if (at(i) == val)
- return i;
- return -1;
-}
-
-template <typename T>
-void QCircularBuffer<T>::prepend(const T &val)
-{
- // If we have no capacity we do nothing
- if (!d->capacity)
- return;
-
- d.detach();
- if (d->size == d->capacity) {
- // Buffer is full. Overwrite last item and rotate
- d->data()[ d->last ] = val;
- d->first = (--d->first + d->capacity) % d->capacity;
- d->last = (--d->last + d->capacity) % d->capacity;
- } else if (d->size != 0) {
- // Buffer is partially full. Prepend data to start of array using appropriate method
- d->first = (--d->first + d->capacity) % d->capacity;
- ++d->size;
- if (QTypeInfo<T>::isComplex)
- new (d->data() + d->first) T(val);
- else
- d->data()[ d->first ] = val;
- } else {
- // Buffer is empty. Prepend data to start of array using appropriate method
- d->size = 1;
- d->first = d->last = d->capacity - 1;
- if (QTypeInfo<T>::isComplex)
- new (d->data() + d->first) T(val);
- else
- d->data()[ d->first ] = val;
- }
-}
-
-template <typename T>
-void QCircularBuffer<T>::remove(int i, int number)
-{
- Q_ASSERT_X(i >= 0 && number > 0 && i + number <= d->size, "QCircularBuffer<T>::remove", "index out of range");
- d.detach();
-
- // HACK (it actually makes sense, but requires some more thinking)
- if ( i == 0 && !QTypeInfo<T>::isComplex ) {
- d->first = d->wraparound( d->first + number );
- d->size -= number;
- return;
- }
-
- // Calculate the number of items that need to be moved downward
- int numToMoveDown = d->size - number - i;
- int numToMoveUp = i;
-
- if (numToMoveDown < numToMoveUp) {
- // Move higher items down
- int numToMove = numToMoveDown;
-
- if (QTypeInfo<T>::isComplex) {
- // Copy items down from higher positions
- int b = d->first + i;
- int e = b + numToMove;
- for (int j = b; j < e ; ++j) {
- T *src = d->data() + ((j + number) % d->capacity);
- T *dst = d->data() + (j % d->capacity);
- new (dst) T(*src);
- }
-
- // Clean up items at end of buffer
- for (int j = d->last; j > d->last - number; --j) {
- T *p = d->data() + ((j + d->capacity) % d->capacity);
- p->~T();
- //TODO: Optimize to a single memset call
- memset(p, 0, sizeof(T));
- }
- } else {
- if (isLinearised()) {
- // With a linearised buffer we can do a simple move and removal of items
- memmove(d->data() + d->last - numToMove - number + 1, d->data() + d->last - numToMove + 1, numToMove * sizeof(T));
- memset(d->data() + d->last - number + 1, 0, number * sizeof(T));
- } else {
- // With a non-linearised buffer we need to be careful of wrapping issues
- int srcBegin = (d->last - numToMove + 1 + d->capacity) % d->capacity;
- int srcEnd = d->last;
- int dstBegin = (d->first + i) % d->capacity;
- int dstEnd = (dstBegin + numToMove - 1) % d->capacity;
-
- bool srcRegionWraps = (srcEnd < srcBegin);
- bool dstRegionWraps = (dstEnd < dstBegin);
- if (srcRegionWraps && !dstRegionWraps) {
- // Source region wraps so do the move in two steps
- int wrapCount = d->capacity - srcBegin;
- memmove(d->data() + dstBegin, d->data() + srcBegin, wrapCount * sizeof(T));
- memmove(d->data() + dstBegin + wrapCount, d->data(), (numToMove - wrapCount) * sizeof(T));
- } else if (!srcRegionWraps && dstRegionWraps) {
- // Destination region wraps so do the move in two steps
- int wrapCount = number - srcBegin;
- memmove(d->data() + d->capacity - wrapCount, d->data() + srcBegin, wrapCount * sizeof(T));
- memmove(d->data(), d->data() + srcBegin + wrapCount, (numToMove - wrapCount) * sizeof(T));
- } else if (srcRegionWraps && dstRegionWraps) {
- // Source and destination regions wrap so we have to do this in three steps
- int srcWrapCount = d->capacity - srcBegin;
- memmove(d->data() + dstBegin, d->data() + srcBegin, srcWrapCount * sizeof(T));
- memmove(d->data() + dstBegin + srcWrapCount, d->data(), number * sizeof(T));
- memmove(d->data(), d->data() + number, (numToMove - srcWrapCount - number) * sizeof(T));
- } else {
- // No wrap around, so we can do this in one hit
- memmove(d->data() + dstBegin, d->data() + srcBegin, numToMove * sizeof(T));
- }
-
- // We potentially have a disjoint region that needs zeroing
- int zeroStart = (d->last - number + d->capacity + 1) % d->capacity;
- int zeroEnd = d->last;
- if (zeroEnd < zeroStart) {
- // Region to be zeroed wraps. Do it in two steps.
- memset(d->data(), 0, (d->last + 1) * sizeof(T));
- memset(d->data() + zeroStart, 0, (number - d->last - 1) * sizeof(T));
- } else {
- // Region to be zeroed is contiguous
- memset(d->data() + zeroStart, 0, number * sizeof(T));
- }
- }
- }
-
- // Adjust the indices
- d->size -= number;
- d->last = (d->last - number + d->capacity) % d->capacity;
- } else {
- // Move lower items up
- int numToMove = numToMoveUp;
-
- if (QTypeInfo<T>::isComplex) {
- // Copy items up from lower positions
- int b = d->first + i - 1;
- int e = b - numToMove;
- for (int j = b; j > e ; --j) {
- T *src = d->data() + ((j + d->capacity) % d->capacity);
- T *dst = d->data() + ((j + d->capacity + number) % d->capacity);
- new (dst) T(*src);
- }
-
- // Clean up items at start of buffer
- for (int j = d->first; j < d->first + number; ++j) {
- T *p = d->data() + (j % d->capacity);
- p->~T();
- //TODO: Optimize to a single memset call
- memset(p, 0, sizeof(T));
- }
- } else {
- if (isLinearised()) {
- // With a linearised buffer we can do a simple move and removal of items
- memmove(d->data() + d->first + number, d->data() + d->first, numToMove * sizeof(T));
- memset(d->data() + d->first, 0, number * sizeof(T));
- } else {
- // With a non-linearised buffer we need to be careful of wrapping issues
- int srcBegin = d->first;
- int srcEnd = (srcBegin + numToMove - 1) % d->capacity;
- int dstBegin = (srcBegin + number) % d->capacity;
- int dstEnd = (dstBegin + numToMove - 1) % d->capacity;
-
- bool srcRegionWraps = (srcEnd < srcBegin);
- bool dstRegionWraps = (dstEnd < dstBegin);
- if (srcRegionWraps && !dstRegionWraps) {
- // Source region wraps so do the move in two steps
- int wrapCount = srcEnd + 1;
- memmove(d->data() + dstEnd - wrapCount + 1, d->data(), wrapCount * sizeof(T));
- memmove(d->data() + dstBegin, d->data() + srcBegin, (numToMove - wrapCount) * sizeof(T));
- } else if (!srcRegionWraps && dstRegionWraps) {
- // Destination region wraps so do the move in two steps
- int wrapCount = dstEnd + 1;
- memmove(d->data(), d->data() + srcEnd - wrapCount + 1, wrapCount * sizeof(T));
- memmove(d->data() + dstBegin, d->data() + srcBegin, (numToMove - wrapCount) * sizeof(T));
- } else if (srcRegionWraps && dstRegionWraps) {
- // Source and destination regions wrap so we have to do this in three steps
- int srcWrapCount = srcEnd + 1;
- memmove(d->data() + dstEnd - srcWrapCount + 1, d->data(), srcWrapCount * sizeof(T));
- memmove(d->data(), d->data() + d->capacity - number, number * sizeof(T));
- memmove(d->data() + dstBegin, d->data() + srcBegin, (numToMove - srcWrapCount - number) * sizeof(T));
- } else {
- // No wrap around, so we can do this in one hit
- memmove(d->data() + dstBegin, d->data() + srcBegin, numToMove * sizeof(T));
- }
-
- // We potentially have a disjoint region that needs zeroing
- int zeroStart = d->first;
- int zeroEnd = (zeroStart + number - 1) % d->capacity;
- if (zeroEnd < zeroStart) {
- // Region to be zeroed wraps. Do it in two steps.
- memset(d->data() + zeroStart, 0, (d->capacity - d->first) * sizeof(T));
- memset(d->data(), 0, (number - d->capacity + d->first) * sizeof(T));
- } else {
- // Region to be zeroed is contiguous
- memset(d->data() + zeroStart, 0, number * sizeof(T));
- }
- }
- }
-
- // Adjust the indices
- d->size -= number;
- d->first = (d->first + number) % d->capacity;
- }
-}
-
-template <typename T>
-void QCircularBuffer<T>::setCapacity(int amount)
-{
- if (amount == d->capacity)
- return;
-
- d.detach();
- // Allocate some new raw memory
- T *newData = d->allocate(amount);
-
- // How many items can we copy across?
- int newSize = qMin(d->size, amount);
-
- if (QTypeInfo<T>::isComplex) {
- // Copy across the elements from the original array
- for (int i = 0; i < newSize; ++i) {
- T *src = d->data() + ((d->first + i) % d->capacity);
- T *dst = newData + i;
- new (dst) T(*src);
- }
-
- // Destroy the original items.
- // The type is complex so we manually call the destructor for each item
- // since we used the placement new operator to instantiate them
- T *b = d->data();
- T *i = b + d->capacity;
- while (i-- != b)
- i->~T();
- } else {
- // Copy across the elements from the original array. The source region
- // potentially wraps so we may have to do this in one or two steps
- if (isLinearised()) {
- memmove(newData, d->data() + d->first, newSize * sizeof(T));
- } else {
- int step1Size = qMin(newSize, d->capacity - d->first);
- memmove(newData, d->data() + d->first, step1Size * sizeof(T));
- int step2Size = qMax(0, qMin(newSize - d->capacity + d->first, d->last + 1));
- memmove(newData + step1Size, d->data(), step2Size * sizeof(T));
- }
- }
-
- // Initialize any memory outside of the valid buffer (ie the unused items)
- memset(newData + newSize, 0, (amount - newSize) * sizeof(T));
-
- // Release the raw memory for the old array
- d->deallocate(d->data());
-
- // Assign the new memory to be our buffer data and fix indices
- d->setData(newData);
- d->capacity = amount;
- d->first = 0;
- d->size = newSize;
- d->last = d->size - 1;
-}
-
-template <typename T>
-void QCircularBuffer<T>::resize(int newSize)
-{
- Q_ASSERT_X(newSize >= 0 && newSize <= d->capacity, "QCircularBuffer<T>::resize", "size out of range");
- d.detach();
- if (newSize < d->size) {
- remove(newSize, d->size - newSize);
- } else if (newSize > d->size) {
- const T t = T();
- insert(d->size, newSize - d->size, t);
- }
-}
-
-template <typename T>
-QCircularBuffer<T> &QCircularBuffer<T>::operator+=(const QCircularBuffer<T> &other)
-{
- d.detach();
- // How many items do we need to copy? No point in ever copying across a number
- // greater than capacity
- int numToCopy = qMin(other.size(), d->capacity);
- int offset = other.size() - numToCopy;
- for (int i = 0; i < numToCopy; ++i)
- append(other.at(offset + i));
- return *this;
-}
-
-template <typename T>
-QCircularBuffer<T> &QCircularBuffer<T>::operator+=(const QVector<T> &other)
-{
- d.detach();
- // How many items do we need to copy? No point in ever copying across a number
- // greater than capacity
- int numToCopy = qMin(other.size(), d->capacity);
- int offset = other.size() - numToCopy;
- for (int i = 0; i < numToCopy; ++i)
- append(other.at(offset + i));
- return *this;
-}
-
-template <typename T>
-QCircularBuffer<T> &QCircularBuffer<T>::operator+=(const QList<T> &other)
-{
- d.detach();
- // How many items do we need to copy? No point in ever copying across a number
- // greater than capacity
- int numToCopy = qMin(other.size(), d->capacity);
- int offset = other.size() - numToCopy;
- for (int i = 0; i < numToCopy; ++i)
- append(other.at(offset + i));
- return *this;
-}
-
-template <typename T>
-QList<T> QCircularBuffer<T>::toList() const
-{
- QList<T> list;
- list.reserve(size());
- for (int i = 0; i < size(); ++i)
- list.append(at(i));
- return list;
-}
-
-template <typename T>
-QVector<T> QCircularBuffer<T>::toVector() const
-{
- QVector<T> vector;
- vector.reserve(size());
- for (int i = 0; i < size(); ++i)
- vector.append(at(i));
- return vector;
-}
-
-template <typename T>
-QCircularBuffer<T> operator+(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-{
- QCircularBuffer<T> circ(lhs.size() + rhs.size());
- for (int i = 0; i < lhs.size(); ++i)
- circ.append(lhs.at(i));
- for (int i = 0; i < rhs.size(); ++i)
- circ.append(rhs.at(i));
- return circ;
-}
-
-#endif // Q_QDOC
-
-Q_DECLARE_SEQUENTIAL_ITERATOR(CircularBuffer)
-Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(CircularBuffer)
-
-} //Qt3D
-
-QT_END_NAMESPACE
-
-#endif // QT3DCORE_QCIRCULARBUFFER_H
diff --git a/src/core/resources/qframeallocator.cpp b/src/core/resources/qframeallocator.cpp
deleted file mode 100644
index e85ae4057..000000000
--- a/src/core/resources/qframeallocator.cpp
+++ /dev/null
@@ -1,322 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/* !\internal
- \class Qt3DCore::QFrameAllocator
- \inmodule Qt3DCore
- \brief Provides a pool of memory chunks to be used to allocate objects on a per frame basis.
-
- The memory can be recycled by following frames by calling clear which won't deallocate any memory.
-
- \note Be really careful when allocating polymorphic types. You must be
- sure to call deallocate with the subclass type to properly release all
- memory.
-*/
-
-#include "qframeallocator_p.h"
-#include "qframeallocator_p_p.h"
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DCore {
-
-QFrameAllocatorPrivate::QFrameAllocatorPrivate()
- : m_maxObjectSize(0U)
- , m_alignment(0U)
-{
-}
-
-QFrameAllocator::QFrameAllocator(uint maxObjectSize, uint alignment, uint pageSize)
- : d_ptr(new QFrameAllocatorPrivate)
-{
- Q_ASSERT(alignment && pageSize && pageSize < UCHAR_MAX);
- Q_D(QFrameAllocator);
- d->m_maxObjectSize = maxObjectSize;
- d->m_alignment = alignment;
- d->m_allocatorPool.resize(d->allocatorIndexFromSize(maxObjectSize) + 1);
- for (int i = 0, n = d->m_allocatorPool.size(); i < n; ++i)
- d->m_allocatorPool[i].init((i + 1) * d->m_alignment, pageSize);
-}
-
-QFrameAllocator::~QFrameAllocator()
-{
- Q_D(QFrameAllocator);
- for (int i = 0, n = d->m_allocatorPool.size(); i < n; ++i)
- d->m_allocatorPool[i].release();
-}
-
-// Clear all memory chunks, allocated memory is not released
-void QFrameAllocator::clear()
-{
- Q_D(QFrameAllocator);
- for (int i = 0, n = d->m_allocatorPool.size(); i < n; ++i)
- d->m_allocatorPool[i].clear();
-}
-
-// Trim excess memory used by chunks
-void QFrameAllocator::trim()
-{
- Q_D(QFrameAllocator);
- for (int i = 0, n = d->m_allocatorPool.size(); i < n; ++i)
- d->m_allocatorPool[i].trim();
-}
-
-uint QFrameAllocator::maxObjectSize() const
-{
- Q_D(const QFrameAllocator);
- return d->m_maxObjectSize;
-}
-
-int QFrameAllocator::allocatorPoolSize() const
-{
- Q_D(const QFrameAllocator);
- return d->m_allocatorPool.size();
-}
-
-bool QFrameAllocator::isEmpty() const
-{
- Q_D(const QFrameAllocator);
- for (const QFixedFrameAllocator &allocator : d->m_allocatorPool) {
- if (!allocator.isEmpty())
- return false;
- }
- return true;
-}
-
-uint QFrameAllocator::totalChunkCount() const
-{
- Q_D(const QFrameAllocator);
- uint chunkCount = 0;
- for (const QFixedFrameAllocator& allocator : d->m_allocatorPool)
- chunkCount += allocator.chunkCount();
- return chunkCount;
-}
-
-QFixedFrameAllocator::QFixedFrameAllocator()
- : m_blockSize(0)
- , m_nbrBlock(0)
- , m_lastAllocatedChunck(nullptr)
- , m_lastFreedChunck(nullptr)
-{
-}
-
-QFixedFrameAllocator::~QFixedFrameAllocator()
-{
- release();
-}
-
-void QFixedFrameAllocator::init(uint blockSize, uchar pageSize)
-{
- m_blockSize = blockSize;
- m_nbrBlock = pageSize;
-}
-
-void *QFixedFrameAllocator::allocate()
-{
- Q_ASSERT(m_blockSize);
- return scan().allocate(m_blockSize);
-}
-
-QFrameChunk &QFixedFrameAllocator::scan()
-{
- Q_ASSERT(m_blockSize);
- Q_ASSERT(m_nbrBlock);
-
- if (m_lastAllocatedChunck && m_lastAllocatedChunck->m_blocksAvailable)
- return *m_lastAllocatedChunck;
-
- for (int i = 0; i < m_chunks.size(); i++) {
- if (m_chunks[i].m_blocksAvailable > 0) {
- m_lastAllocatedChunck = m_chunks.begin() + i;
- return *m_lastAllocatedChunck;
- }
- }
- m_chunks.resize(m_chunks.size() + 1);
- QFrameChunk &newChunk = m_chunks.last();
- newChunk.init(m_blockSize, m_nbrBlock);
- m_lastAllocatedChunck = &newChunk;
- m_lastFreedChunck = &newChunk;
- return newChunk;
-}
-
-void QFixedFrameAllocator::deallocate(void *ptr)
-{
- Q_ASSERT(m_blockSize && m_nbrBlock);
- if (!m_chunks.empty() && ptr != nullptr) {
- if (m_lastFreedChunck != nullptr && m_lastFreedChunck->contains(ptr, m_blockSize))
- m_lastFreedChunck->deallocate(ptr, m_blockSize);
- else {
- for (int i = 0; i < m_chunks.size(); i++) {
- if (m_chunks[i].contains(ptr, m_blockSize)) {
- m_chunks[i].deallocate(ptr, m_blockSize);
- m_lastFreedChunck = m_chunks.begin() + i;
- break ;
- }
- }
- }
- }
-}
-
-void QFixedFrameAllocator::trim()
-{
- for (int i = m_chunks.size() - 1; i >= 0; i--) {
- if (m_chunks.at(i).isEmpty()) {
- m_chunks[i].release();
- if (m_lastAllocatedChunck == &m_chunks[i])
- m_lastAllocatedChunck = nullptr;
- if (m_lastFreedChunck == &m_chunks[i])
- m_lastFreedChunck = nullptr;
- m_chunks.removeAt(i);
- }
- }
-}
-
-void QFixedFrameAllocator::release()
-{
- for (int i = m_chunks.size() - 1; i >= 0; i--)
- m_chunks[i].release();
- m_chunks.clear();
- m_lastAllocatedChunck = nullptr;
- m_lastFreedChunck = nullptr;
-}
-
-// Allows to reuse chunks without having to reinitialize and reallocate them
-void QFixedFrameAllocator::clear()
-{
- for (int i = m_chunks.size() - 1; i >= 0; i--)
- m_chunks[i].clear(m_blockSize, m_nbrBlock);
-}
-
-bool QFixedFrameAllocator::isEmpty() const
-{
- for (const QFrameChunk &chunck : m_chunks) {
- if (chunck.m_blocksAvailable != chunck.m_maxBlocksAvailable)
- return false;
- }
- return true;
-}
-
-// QFrameChuck is agnostic about blocksize
-// However if it was initialized with a block size of 16
-// You should then pass 16 to allocate and deallocate
-void QFrameChunk::init(uint blockSize, uchar blocks)
-{
- m_data = new uchar[blockSize * blocks];
- m_firstAvailableBlock = 0;
- m_blocksAvailable = blocks;
- m_maxBlocksAvailable = blocks;
- uchar *p = m_data;
- // Init each block with its position stored in its first byte
- for (uchar i = 0; i < blocks; p += blockSize)
- *p = ++i;
-#ifdef QFRAMEALLOCATOR_DEBUG
- VALGRIND_CREATE_MEMPOOL(m_data, 0, true);
- VALGRIND_MAKE_MEM_NOACCESS(m_data, blockSize * blocks);
- VALGRIND_MEMPOOL_ALLOC(m_data, m_data, blockSize * blocks);
-#endif
-}
-
-void *QFrameChunk::allocate(uint blockSize)
-{
- if (m_blocksAvailable == 0)
- return nullptr;
- uchar *r = m_data + (m_firstAvailableBlock * blockSize);
- m_firstAvailableBlock = *r;
- --m_blocksAvailable;
- return r;
-}
-
-// Shouldn't be called more than once for the same pointer
-void QFrameChunk::deallocate(void *p, uint blockSize)
-{
- if (p >= m_data) {
- uchar *toRelease = static_cast<uchar *>(p);
- uchar oldFreeBlock = m_firstAvailableBlock;
- m_firstAvailableBlock = static_cast<uchar>((toRelease - m_data) / blockSize);
- *toRelease = oldFreeBlock;
- ++m_blocksAvailable;
- }
-}
-
-bool QFrameChunk::contains(void *p, uint blockSize)
-{
- uchar *c = static_cast<uchar *>(p);
- return (m_data <= c && c < m_data + blockSize * m_maxBlocksAvailable);
-}
-
-// Reset chunck without releasing heap allocated memory
-void QFrameChunk::clear(uint blockSize, uchar blocks)
-{
- m_firstAvailableBlock = 0;
- m_blocksAvailable = blocks;
-
- uchar *p = m_data;
- // Init each block with its position stored in its first byte
- for (uchar i = 0; i < blocks; p += blockSize)
- *p = ++i;
-}
-
-void QFrameChunk::release()
-{
-#ifdef QFRAMEALLOCATOR_DEBUG
- VALGRIND_MEMPOOL_FREE(m_data, m_data);
- VALGRIND_DESTROY_MEMPOOL(m_data);
-#endif
- delete [] m_data;
-}
-
-void* QFrameAllocator::allocateRawMemory(size_t size)
-{
- Q_D(QFrameAllocator);
- Q_ASSERT(size <= d->m_maxObjectSize);
- uint allocatorIndex = d->allocatorIndexFromSize(uint(size));
- return d->allocateAtChunk(allocatorIndex);
-}
-
-void QFrameAllocator::deallocateRawMemory(void* ptr, size_t size)
-{
- Q_D(QFrameAllocator);
- Q_ASSERT(size <= d->m_maxObjectSize);
- uint allocatorIndex = d->allocatorIndexFromSize(uint(size));
- d->deallocateAtChunck(ptr, allocatorIndex);
-}
-
-} // Qt3D
-
-QT_END_NAMESPACE
diff --git a/src/core/resources/qframeallocator_p.h b/src/core/resources/qframeallocator_p.h
deleted file mode 100644
index 4c2b5a961..000000000
--- a/src/core/resources/qframeallocator_p.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QT3DCORE_QFRAMEALLOCATOR_P_H
-#define QT3DCORE_QFRAMEALLOCATOR_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifdef QFRAMEALLOCATOR_DEBUG
-#include <valgrind/valgrind.h>
-#include <valgrind/memcheck.h>
-#endif
-
-#include <QtCore/QDebug>
-#include <QtCore/QScopedPointer>
-#include <QtCore/QVector>
-
-#include <Qt3DCore/private/qt3dcore_global_p.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DCore {
-
-class QFrameAllocatorPrivate;
-
-class Q_3DCORE_PRIVATE_EXPORT QFrameAllocator
-{
-public:
- explicit QFrameAllocator(uint maxObjectSize, uint alignment = 16, uint pageSize = 128);
- ~QFrameAllocator();
-
- template<typename T>
- T* allocate()
- {
- void* ptr = allocateRawMemory(sizeof(T));
- new (ptr) T(); // Don't forget to call the constructor of the object using the placement new operator
- return static_cast<T*>(ptr);
- }
-
- template<typename T>
- void deallocate(T *ptr)
- {
- ptr->~T(); // Call destructor
- deallocateRawMemory(ptr, sizeof(T));
- }
-
- void* allocateRawMemory(size_t size);
-
- void deallocateRawMemory(void *ptr, size_t size);
-
- void clear();
- void trim();
- uint maxObjectSize() const;
- uint totalChunkCount() const;
- int allocatorPoolSize() const;
- bool isEmpty() const;
-
-private:
- Q_DECLARE_PRIVATE(QFrameAllocator)
- const QScopedPointer<QFrameAllocatorPrivate> d_ptr;
-};
-
-} // Qt3D
-
-QT_END_NAMESPACE
-
-#endif // QFRAMEALLOCATOR_P_H
diff --git a/src/core/resources/qframeallocator_p_p.h b/src/core/resources/qframeallocator_p_p.h
deleted file mode 100644
index bf4e0a2b1..000000000
--- a/src/core/resources/qframeallocator_p_p.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QT3DCORE_QFRAMEALLOCATOR_P_P_H
-#define QT3DCORE_QFRAMEALLOCATOR_P_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <Qt3DCore/qt3dcore_global.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DCore {
-
-class QFrameAllocator;
-
-struct Q_AUTOTEST_EXPORT QFrameChunk
-{
- void init(uint blockSize, uchar blocks);
- void *allocate(uint blockSize);
-
- void deallocate(void *p, uint blockSize);
- bool contains(void *p, uint blockSize);
- void clear(uint blockSize, uchar blocks);
- void release();
-
- inline bool isEmpty() const { return m_blocksAvailable == m_maxBlocksAvailable; }
-
- uchar *m_data;
- uchar m_firstAvailableBlock;
- uchar m_blocksAvailable;
- uchar m_maxBlocksAvailable;
-};
-
-class Q_AUTOTEST_EXPORT QFixedFrameAllocator
-{
-public:
- QFixedFrameAllocator();
- ~QFixedFrameAllocator();
-
- void init(uint blockSize, uchar pageSize = 128);
- void *allocate();
- void deallocate(void *ptr);
- void trim();
- void release();
- void clear();
- bool isEmpty() const;
-
- inline int chunkCount() const { return m_chunks.size(); }
- inline uchar pageSize() const { return m_nbrBlock; }
- inline uint blockSize() const { return m_blockSize; }
-
-private:
- QFrameChunk &scan();
-
-private:
- uint m_blockSize;
- uchar m_nbrBlock;
- QVector<QFrameChunk> m_chunks;
- QFrameChunk *m_lastAllocatedChunck;
- QFrameChunk *m_lastFreedChunck;
-};
-
-class QFrameAllocatorPrivate
-{
-public:
- QFrameAllocatorPrivate();
-
- inline void *allocateAtChunk(uint allocatorIndex)
- {
- return m_allocatorPool[allocatorIndex].allocate();
- }
-
- inline void deallocateAtChunck(void *ptr, uint allocatorIndex)
- {
- m_allocatorPool[allocatorIndex].deallocate(ptr);
- }
-
- inline uint allocatorIndexFromSize(uint targetSize) const
- {
- return (targetSize + m_alignment - 1) / m_alignment - 1;
- }
-
- uint m_maxObjectSize;
- uint m_alignment;
- QVector<QFixedFrameAllocator> m_allocatorPool;
-};
-
-} // Qt3D
-
-QT_END_NAMESPACE
-
-#endif // QT3DCORE_QFRAMEALLOCATOR_P_P_H
diff --git a/src/core/resources/qloadgltf_p.h b/src/core/resources/qloadgltf_p.h
index be7ee0d5f..ce49a2a80 100644
--- a/src/core/resources/qloadgltf_p.h
+++ b/src/core/resources/qloadgltf_p.h
@@ -60,13 +60,6 @@
inline QJsonDocument qLoadGLTF(const QByteArray &gltfData)
{
-#if QT_CONFIG(binaryjson)
- {
- QJsonDocument sceneDocument = QJsonDocument::fromBinaryData(gltfData);
- if (!sceneDocument.isNull())
- return sceneDocument;
- }
-#endif
{
const QCborValue cbor = QCborValue::fromCbor(gltfData);
if (cbor.isMap())
diff --git a/src/core/resources/resources.pri b/src/core/resources/resources.pri
index 89540a36d..d25070d56 100644
--- a/src/core/resources/resources.pri
+++ b/src/core/resources/resources.pri
@@ -1,15 +1,10 @@
HEADERS += \
$$PWD/qloadgltf_p.h \
$$PWD/qresourcemanager_p.h \
- $$PWD/qcircularbuffer_p.h \
- $$PWD/qboundedcircularbuffer_p.h \
- $$PWD/qframeallocator_p.h \
- $$PWD/qframeallocator_p_p.h \
$$PWD/qhandle_p.h
SOURCES += \
- $$PWD/qresourcemanager.cpp \
- $$PWD/qframeallocator.cpp
+ $$PWD/qresourcemanager.cpp
# Define proper SIMD flags for qresourcemanager.cpp
diff --git a/src/doc/src/qcircularbuffer.qdoc b/src/doc/src/qcircularbuffer.qdoc
deleted file mode 100644
index 90d307a04..000000000
--- a/src/doc/src/qcircularbuffer.qdoc
+++ /dev/null
@@ -1,1578 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/* !\internal
- \class Qt3DCore::QCircularBuffer
- \inmodule Qt3DCore
- \brief A template class providing a dynamic circular array.
-
- \ingroup tools
- \ingroup shared
-
- \reentrant
-
- QCircularBuffer\<T\> is one of Qt's generic \l{container classes}. It
- stores its items in adjacent memory locations and provides fast
- index-based access.
-
- QCircularBuffer\<T\> provides similar functionality as QVector\<T\> and QList\<T\>,
- but behaves differently when adding items to a full QCircularBuffer. Whereas
- QVector\<T\> and QList\<T\> will both grow to accommodate the new items,
- QCircularBuffer\<T\> will overwrite the oldest items. This provides circular
- behavior to the container, and also means that it can maintain a flat memory
- profile.
-
- QCircularBuffer\<T\> also offers performance gains over the other container classes when
- doing lots of appending or prepending to the buffer, such as in data logging
- applications. This is because appending (or prepending) an item does not require any
- extra memory to be allocated, unlike, for example, QVector\<T\> or QList\<T\>.
- Appending and prepending items to a QCircularBuffer\<T\> is an O(1) operation.
-
- As with QVector\<T\>, items in QCircularBuffer\<T\> occupy adjacent positions in memory.
- However, the items may not be located in order in a single array. At times, the internal
- indices used to store the positions of the first and last items may wrap around as the
- QCircularBuffer\<T\> is modified. If the index of the last item is greater than the
- index of the first item, then the buffer is said to be non-linearized.
-
- Here's an example of a QCircularBuffer that stores integers and a QCircularBuffer
- that stores QString values:
-
- \snippet code/src_core_qcircularbuffer.cpp 0
-
- The above examples create QCircularBuffer objects with a capacity of 0. The capacity
- is the number of items that can be stored in a QCircularBuffer. The size of a
- QCircularBuffer object is the number of items that actually are stored in it. Here's
- an example of creating a QCircularBuffer with a capacity for 200 elements and a size of 0:
-
- \snippet code/src_core_qcircularbuffer.cpp 1
-
- By default the QCircularBuffer is empty. If you want to create a circular buffer with
- unused capacity, pass a size argument to the constructor.
-
- \snippet code/src_core_qcircularbuffer.cpp 2
-
- If you wish to fill a subset of the QCircularBuffer with a default value, then you
- should also pass a size argument to the constructor. The following example creates
- a QCircularBuffer with a capacity for 200 QString items, and initializes the first 50
- of them to the value "Qt":
-
- \snippet code/src_core_qcircularbuffer.cpp 3
-
- You can also call fill() at any time to fill the QCircularBuffer with a value.
-
- QCircularBuffer uses 0-based indexes, just like C++ arrays. To access the
- item at a particular index position, you can use \l{operator[]()}{operator[]}. On
- non-const buffers, \l{operator[]()}{operator[]} returns a reference to the item
- that can be used on the left side of an assignment:
-
- \snippet code/src_core_qcircularbuffer.cpp 4
-
- For read-only access, an alternative syntax is to use at():
-
- \snippet code/src_core_qcircularbuffer.cpp 5
-
- at() can be faster than \l{operator[]()}{operator[]}, because it never causes
- a \l{deep copy} to occur.
-
- Another way to access the data stored in a QCircularBuffer is to call data(),
- or dataOne() and dataTwo() depending on if the buffer is linearized or not.
- See the discussion in isLinearised() for more information. The data() function
- returns an \l array_range object describing the array of items stored
- in the QCircularBuffer. You can use the pointer in the array_range to
- directly access and modify the elements stored in the circular buffer. The pointer is also
- useful if you need to pass a QCircularBuffer to a function that accepts a plain
- C++ array.
-
- If the circular buffer is non-linearized, the data() function will
- linearize it before returning. This can be an expensive operation for large buffers.
- To avoid this cost, QCircularBuffer also provides alternative methods called
- dataOne() and dataTwo() that return pointers to the two contiguous arrays used
- to represent the buffer. dataOne() returns a pointer to the earlier (or oldest)
- items, and dataTwo() returns a pointer to the later (or newer) items. The dataOne()
- and dataTwo() functions never cause the circular buffer to be linearized.
-
- If you wish to pass a C++ array to a function and that function is expensive to call,
- then you may wish to use the data() method so that you only need to call your
- expensive function once. If your function is cheap and you have a large circular
- buffer (so that linearizing it is expensive), then you may wish to use dataOne() and
- dataTwo() and call your function twice.
-
- Here is a simple example that shows the semantics of how QCircularBuffer operates:
-
- \snippet code/src_core_qcircularbuffer.cpp 6
-
- Notice how appending items to a full buffer overwrites the earliest items.
-
- If you want to find all occurrences of a particular value in a
- circular buffer, use indexOf() or lastIndexOf(). The former searches
- forward starting from a given index position, the latter searches
- backward. Both return the index of the matching item if they found
- one; otherwise, they return -1. For example:
-
- \snippet code/src_core_qcircularbuffer.cpp 7
-
- If you simply want to check whether a circular buffer contains a
- particular value, use contains(). If you want to find out how
- many times a particular value occurs in the circular buffer, use count().
-
- QCircularBuffer provides these basic functions to add, move, and remove
- items: insert(), replace(), remove(), prepend(), append(). The insert() and
- remove() functions can be slow (\l{linear time}) for large circular buffers,
- because they require moving many items in the circular buffer by one or more positions
- in memory. The implementation does however take care to minimize the number of
- items that need to be moved. In the extreme worst case for insert() and remove(),
- half of the items will be moved in memory. QCircularBuffer also takes care
- to move items around using the best method available for the type being stored.
- If your type is movable, then it is best to tell Qt about this by using the
- Q_DECLARE_TYPEINFO() macro. In such cases memory moves are performed using
- memmove() rather than calling the copy constructor for each item. If you want
- a container class that always provides fast insertion/removal in the middle,
- use QList or QLinkedList instead.
-
- Unlike plain C++ arrays, QCircularBuffers can be resized at any time by
- calling resize() or setCapacity(). The resize() function can only allocate
- items up to the number specified by capacity(). If you wish to alter the
- capacity of the CircularBuffer, then use setCapacity(). This can be slow as
- new memory needs to be allocated. It is most common to specify the capacity
- of the circular buffer in the constructor or immediately after construction,
- and then simply keep appending to the buffer. If you wish to reclaim any
- unused memory from the circular buffer, then call squeeze(). This is
- equivalent to calling \l {setCapacity()}{setCapacity}( size() ).
-
- Note that using non-const operators and functions can cause
- QCircularBuffer to do a deep copy of the data. This is due to
- \l{implicit sharing}.
-
- QCircularBuffer's value type must be an \l{assignable data type}. This
- covers most data types that are commonly used, but the compiler
- won't let you, for example, store a QWidget as a value; instead,
- store a QWidget *. Some functions have additional requirements;
- for example, indexOf() and lastIndexOf() expect the value type to
- support \c operator==(). These requirements are documented on a
- per-function basis.
-
- QCircularBuffer provides \l{STL-Style Iterators} (\l {const_iterator}
- and \l {iterator}). In practice, these are rarely used,
- because you can use indexes into the buffer.
-
- QCircularBuffer does \e not support inserting, prepending, appending, or
- replacing with references to its own values. Doing so will cause your
- application to abort with an error message.
-
- \sa iterator, const_iterator, QVector, QList, QLinkedList
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::QCircularBuffer()
-
- Constructs an empty circular buffer with zero capacity.
-
- \sa resize(), setCapacity()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::QCircularBuffer(int capacity)
-
- Constructs an empty circular buffer with an initial capacity of \a capacity
- elements.
-
- \sa resize(), setCapacity()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::QCircularBuffer(int capacity, const T &value)
-
- Constructs a circular buffer with an initial capacity and size of
- \a capacity elements.
-
- The elements are initialized to \a value.
-
- \sa resize(), setCapacity(), fill()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::QCircularBuffer(int capacity, int size, const T &value)
-
- Constructs a circular buffer with an initial capacity of \a capacity
- elements and initial size of \a size elements.
-
- The first \a size elements are initialized to \a value.
-
- \sa resize(), setCapacity(), fill()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::QCircularBuffer(const QCircularBuffer<T> &other)
-
- Constructs a copy of \a other.
-
- This operation takes \l{constant time}, because QCircularBuffer is
- \l{implicitly shared}. This makes returning a QCircularBuffer from a
- function very fast. If a shared instance is modified, it will be
- copied (copy-on-write), and that takes \l{linear time}.
-
- \sa operator=()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::~QCircularBuffer()
-
- Destroys the circular buffer.
-*/
-
-/* \fn QCircularBuffer &Qt3DCore::QCircularBuffer::operator=(const QCircularBuffer<T> &other)
-
- Assigns \a other to this circular buffer and returns a reference to this
- circular buffer.
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator Qt3DCore::QCircularBuffer::begin()
-
- Returns an \l{STL-Style iterators}{STL-style iterator} pointing to the first item in
- the circular buffer.
-
- \sa constBegin(), end()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator Qt3DCore::QCircularBuffer::begin() const
-
- \overload
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator Qt3DCore::QCircularBuffer::constBegin() const
-
- Returns a const \l{STL-Style Iterators}{STL-style iterator} pointing to the first item in
- the circular buffer.
-
- \sa begin(), constEnd()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator Qt3DCore::QCircularBuffer::end()
-
- Returns an \l {STL-Style Iterators} {STL-style iterator} pointing to the imaginary item
- after the last item in the circular buffer.
-
- \sa begin(), constEnd()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator Qt3DCore::QCircularBuffer::end() const
-
- \overload
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator Qt3DCore::QCircularBuffer::constEnd() const
-
- Returns a const \l{STL-Style Iterators} {STL-style iterator} pointing to the imaginary item
- after the last item in the circular buffer.
-
- \sa constBegin(), end()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator Qt3DCore::QCircularBuffer::erase(const_iterator pos)
-
- Removes the item pointed to by the iterator \a pos from the
- circular buffer, and returns an iterator to the next item in the circular
- buffer (which may be end()).
-
- \sa insert(), remove()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator Qt3DCore::QCircularBuffer::erase(const_iterator begin, const_iterator end)
-
- \overload
-
- Removes all the items from \a begin up to (but not including) \a
- end. Returns an iterator to the same item that \a end referred to
- before the call.
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::push_back(const T &value)
-
- This function is provided for STL compatibility. It is equivalent
- to append(\a value).
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::push_front(const T &value)
-
- This function is provided for STL compatibility. It is equivalent
- to prepend(\a value).
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::pop_back()
-
- This function is provided for STL compatibility. It is equivalent
- to erase(end() - 1).
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::pop_front()
-
- This function is provided for STL compatibility. It is equivalent
- to erase(begin()).
-*/
-
-/* \fn bool Qt3DCore::QCircularBuffer::empty() const
-
- This function is provided for STL compatibility. It is equivalent
- to isEmpty(), returning true if the circular buffer is empty; otherwise
- returns false.
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::reference Qt3DCore::QCircularBuffer::front()
-
- This function is provided for STL compatibility. It is equivalent
- to first().
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_reference Qt3DCore::QCircularBuffer::front() const
-
- \overload
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::reference Qt3DCore::QCircularBuffer::back()
-
- This function is provided for STL compatibility. It is equivalent
- to last().
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_reference Qt3DCore::QCircularBuffer::back() const
-
- \overload
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::refCount() const
-
- Returns the number of shallow copies that exist of this circular buffer.
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::append(const T &value)
-
- Inserts \a value at the end of the circular buffer. If the circular buffer
- is full, then the oldest element is overwritten.
-
- Example:
- \snippet code/src_core_qcircularbuffer.cpp 8
-
- This operation is very fast, because QCircularBuffer never allocates
- memory in this function.
-
- \sa operator<<(), operator+=(), prepend(), insert()
-*/
-
-/* \fn const T &Qt3DCore::QCircularBuffer::at(int i) const
-
- Returns the item at index position \a i in the circular buffer.
-
- \a i must be a valid index position in the circular buffer
- (i.e., 0 <= \a i < size()).
-
- \sa value(), operator[]()
-*/
-
-/* \fn T &Qt3DCore::QCircularBuffer::operator[](int i)
-
- Returns the item at index position \a i as a modifiable reference.
-
- \a i must be a valid index position in the circular buffer (i.e., 0 <= \a i
- < size()).
-
- Note that using non-const operators can cause QCircularBuffer to do a deep
- copy.
-
- \sa at(), value()
-*/
-
-/* \fn const T &Qt3DCore::QCircularBuffer::operator[](int i) const
-
- \overload
-
- Same as at(\a i).
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::capacity() const
-
- Returns the maximum number of elements that can be stored in
- the circular buffer.
-
- \sa setCapacity(), size()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::clear()
-
- Removes all elements from the circular buffer so that the size is
- zero. The capacity is unchanged.
-
- \sa isEmpty()
-*/
-
-/* \fn bool Qt3DCore::QCircularBuffer::contains(const T &value) const
-
- Returns true if the circular buffer contains an occurrence of \a value;
- otherwise returns false.
-
- This function requires the value type to have an implementation of
- \c operator==().
-
- \sa indexOf(), count()
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::count(const T &value) const
-
- Returns the number of occurrences of \a value in the circular buffer.
-
- This function requires the value type to have an implementation of
- \c operator==().
-
- \sa contains(), indexOf()
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::count() const
-
- \overload
-
- Same as size().
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::array_range Qt3DCore::QCircularBuffer::data()
-
- Returns an \l array_range describing the internal array of data. If
- the circular buffer is non-linearized, then this function causes it to be
- linearized. If the cost of linearisation is too high for your use case, then
- you should consider using the dataOne() and dataTwo() functions instead.
-
- If the circular buffer is empty then the pointer and array size returned
- will both be 0.
-
- \sa constData(), dataOne(), dataTwo(), isLinearised()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_array_range Qt3DCore::QCircularBuffer::data() const
-
- \overload
-
- If the circular buffer is non-linearized then the pointer and array size
- returned will both be 0 since linearising the circular buffer would break
- constness.
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_array_range Qt3DCore::QCircularBuffer::constData() const
-
- Returns a \l const_array_range describing the internal array of
- data.
-
- If the circular buffer is non-linearized then the pointer and array size
- returned will both be 0 since linearising the circular buffer would break
- constness.
-
- If the circular buffer is empty then the pointer and array size returned
- will both be 0.
-
- \sa data(), constDataOne(), constDataTwo(), isLinearised()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::array_range Qt3DCore::QCircularBuffer::dataOne()
-
- Returns an \l array_range describing the first internal array of
- contiguous data. If the circular buffer is linearized, then this function is
- equivalent to calling data(). If the circular buffer is non-linearized then
- the returned array range will describe a subset of the data contained in the
- circular buffer. This subset will consist of the earliest (lowest index) items
- in the buffer. To obtain an \l array_range for the remainder of the data, use
- the dataTwo() function.
-
- If the circular buffer is empty, then the pointer and array size returned
- will both be 0.
-
- \sa constDataOne(), dataTwo(), data(), isLinearised()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_array_range Qt3DCore::QCircularBuffer::dataOne() const
-
- \overload
-
- Unlike data(), this function always returns a valid \l const_array_range
- (unless the circular buffer is empty).
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_array_range Qt3DCore::QCircularBuffer::constDataOne() const
-
- Returns a \l const_array_range describing the first internal array of
- contiguous data. If the circular buffer is linearized, then this function is
- equivalent to calling constData(). If the circular buffer is non-linearized, then
- the returned array range will describe a subset of the data contained in the
- circular buffer. This subset will consist of the earliest (lowest index) items
- in the buffer. To obtain a \l const_array_range for the remainder of the data,
- use the constDataTwo() function.
-
- If the circular buffer is empty, then the pointer and array size returned
- will both be 0.
-
- \sa dataOne(), constDataTwo(), constData(), isLinearised()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::array_range Qt3DCore::QCircularBuffer::dataTwo()
-
- Returns an \l array_range describing the first internal array of
- contiguous data. If the circular buffer is linearized, then the pointer and array size
- returned will both be 0 since all the data will be contained in the array
- described by calling the dataOne() function.
-
- \sa dataOne(), constDataTwo(), data(), isLinearised()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_array_range Qt3DCore::QCircularBuffer::dataTwo() const
-
- \overload
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_array_range Qt3DCore::QCircularBuffer::constDataTwo() const
-
- Returns a \l const_array_range describing the first internal array of
- contiguous data. If the circular buffer is linearized, then the pointer and array size
- returned will both be 0 since all the data will be contained in the array
- described by calling the dataOne() function.
-
- \sa constDataOne(), dataTwo(), constData(), isLinearised()
-*/
-
-/* \fn bool Qt3DCore::QCircularBuffer::endsWith(const T &value) const
-
- Returns \c true if this circular buffer is not empty and its last
- item is equal to \a value; otherwise returns \c false.
-
- \sa isEmpty(), last(), startsWith()
-*/
-
-/* \fn QCircularBuffer<T>& Qt3DCore::QCircularBuffer::fill(const T &value, int size = -1)
-
- Assigns \a value to all items in the circular buffer. If \a size is
- different from -1 (the default), the circular buffer is resized to size \a
- size beforehand (size must be less than or equal to the capacity).
-
- This function also linearizes the circular buffer.
-
- Example:
- \snippet code/src_core_qcircularbuffer.cpp 14
-
- \sa resize()
-*/
-
-/* \fn T &Qt3DCore::QCircularBuffer::first()
-
- Returns a reference to the first item in the circular buffer. This
- function assumes that the circular buffer isn't empty.
-
- \sa last(), isEmpty()
-*/
-
-/* \fn const T &Qt3DCore::QCircularBuffer::first() const
-
- \overload
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::freeSize() const
-
- Returns the number of items that can be added to the circular buffer
- without causing the earliest item to be overwritten. It is equivalent
- to (capacity() - size()).
-
- \sa sizeAvailable(), capacity(), isEmpty(), isFull(), size()
-*/
-
-/* \fn static QCircularBuffer<T> Qt3DCore::QCircularBuffer::fromList(const QList<T>& list)
-
- Returns a QCircularBuffer object with the data contained in \a list. The
- capacity and size of the circular buffer will be equal to the size of
- \a list.
-
- Example:
- \snippet code/src_core_qcircularbuffer.cpp 18
-
- \sa fromVector(), toList(), toVector()
-*/
-
-/* \fn static QCircularBuffer<T> Qt3DCore::QCircularBuffer::fromVector(const QVector<T>& vector)
-
- Returns a QCircularBuffer object with the data contained in \a vector. The
- capacity and size of the circular buffer will be equal to the size of
- \a vector.
-
- \sa fromList(), toVector(), toList()
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::indexOf(const T &value, int from = 0) const
-
- Returns the index position of the first occurrence of \a value in
- the circular buffer, searching forward from index position \a from.
- Returns -1 if no item matched.
-
- Example:
- \snippet code/src_core_qcircularbuffer.cpp 15
-
- This function requires the value type to have an implementation of
- \c operator==().
-
- \sa lastIndexOf(), contains()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::insert(int i, const T &value)
-
- Inserts \a value at index position \a i in the circular buffer.
- If \a i is 0, the value is prepended to the circular buffer. If \a i
- is size(), the value is appended to the circular buffer. The capacity
- of the circular buffer is not changed.
-
- Example:
- \snippet code/src_core_qcircularbuffer.cpp 11
-
- Using this function is equivalent to calling insert(i, 1, value). See the
- discussion there for more information.
-
- Items at indexes \a i and higher are shifted along by one. If the circular
- buffer is full then the earliest item will be overwritten. Note that this
- has the non-obvious behavior that calling \c {insert(0, value)} on a circular
- buffer that is already full will effectively do nothing since the newly
- prepended item will immediately be overwritten by the highest item as it
- is shifted along one position.
-
- For large circular buffers, this operation can be slow (\l{linear time}),
- because it requires moving all the items at indexes \a i and
- above (or all items below index i depending upon where in the circular buffer
- the new item is inserted) by one position in memory. If you
- want a container class that provides a fast insert() function, use
- QLinkedList instead.
-
- If the capacity() is zero, then nothing will be inserted.
-
- \sa append(), prepend(), remove()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::insert(int i, int count, const T &value)
-
- \overload
-
- Inserts \a value at index position \a i in the circular buffer.
- If \a i is 0, the value is prepended to the circular buffer. If \a i
- is size(), the value is appended to the circular buffer. The capacity
- of the circular buffer is not changed.
-
- Items at indexes \a i and higher are shifted along by one. If the circular
- buffer has freeSize() < \a count, then the earliest items will be overwritten.
-
- The actual number of items that get inserted may not always be equal to
- \a count since this function preserves the capacity of the circular buffer,
- and since items at indexes i and higher are shifted along by one.
- The actual number of items inserted is min(\a count, \a i + freeSize()).
-
- For the same reasons, the number of items that get overwritten at the
- start of the circular buffer is min(\a i, max(0, \a count - freeSize())).
-
- Example:
- \snippet code/src_core_qcircularbuffer.cpp 12
-
- For large circular buffers, this operation can be slow (\l{linear time}),
- because it requires moving all the items at indexes \a i and
- above (or all items below index i depending upon where in the circular buffer
- the new item is inserted) in memory. If you want a container class that
- provides a fast insert() function, use QLinkedList instead.
-
- If the capacity() is zero, then nothing will be inserted.
-
- \sa append(), prepend(), remove()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator Qt3DCore::QCircularBuffer::insert(const_iterator before, int count, const T &value)
-
- \overload
-
- Inserts up to \a count items with value \a value in front of the item
- pointed to by the iterator \a before in the circular buffer. Returns an
- iterator pointing at the first of the inserted items.
-
- \sa append(), prepend(), remove()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator Qt3DCore::QCircularBuffer::insert(const_iterator before, const T &value)
-
- \overload
-
- Inserts \a value in front of the item pointed to by the iterator \a before.
- Returns an iterator pointing at the inserted item.
-
- \sa append(), prepend(), remove()
-*/
-
-/* \fn bool Qt3DCore::QCircularBuffer::isEmpty() const
-
- Returns true if the circular buffer has size 0; otherwise returns false.
-
- \sa capacity(), resize(), setCapacity(), size()
-*/
-
-/* \fn bool Qt3DCore::QCircularBuffer::isFull() const
-
- Returns true if the circular buffer is full ie if size() == capacity(); otherwise returns false.
-
- \sa capacity(), resize(), setCapacity(), size()
-*/
-
-/* \fn bool Qt3DCore::QCircularBuffer::isLinearised() const
-
- Returns \c true if the circular buffer is linearized; otherwise returns
- \c false.
-
- A circular buffer is said to be linearized if the position of the first
- item in the internal array occurs before the position of the last item. A
- little more explanation is provided for clarification.
-
- Internally, QCircularBuffer stores the items in a plain C++ array.
- Additionally, the positions in the array of the first and last items of
- the circular buffer are also stored (along with the capacity and size).
-
- Imagine a circular buffer of capacity 6 created and populated with the
- following code:
-
- \snippet code/src_core_qcircularbuffer.cpp 19
-
- After executing the above code, the internal state of the circular buffer
- would look like this:
-
- \img circularbuffer-1.png
-
- As you can see, the internal array has been populated from the beginning.
- The first item is located as position 0 in the array and the last item
- is located at position 4 in the array. The circular buffer is linearized
- because the last item occurs later in the array than the first item.
-
- If we now append another item to the circular buffer with:
-
- \snippet code/src_core_qcircularbuffer.cpp 20
-
- the internal representation then becomes:
-
- \img circularbuffer-2.png
-
- The circular buffer is still linearized, but it is now full. Appending
- further items will cause the oldest item to be overwritten. For example,
-
- \snippet code/src_core_qcircularbuffer.cpp 21
-
- causes the internal representation to become:
-
- \img circularbuffer-3.png
-
- We see that the oldest item (1) has been overwritten by the newest item
- (7), and that the first and last indexes have been adjusted accordingly.
- The circular buffer is now said to be non-linearized because the position
- of the last item is before the position of the first item.
-
- The circular buffer can always be linearized by calling the linearise()
- function. This can be an expensive operation (\l{linear time}) for large
- circular buffers since new memory has to be allocated, the items copied across,
- and the original memory deallocated.
-
- If you need to directly access the items stored in a circular buffer,
- (perhaps for a plain C++ function call) then you can use the data()
- function. If the circular buffer is non-linearized, then the data()
- function will linearize it for you before returning an \l array_range
- describing the array.
-
- To prevent the cost of the linearisation process, you can instead
- call the dataOne() and dataTwo() functions to obtain the two arrays
- used to represent a non-linearized circular buffer. After running the
- above sample code, calling the dataOne() function would return an
- \l array_range object describing the values 2-6, and the dataTwo() function
- would return an \l array_range object describing the value 7. Sometimes,
- accessing the items via the two arrays described by dataOne() and dataTwo(),
- can be quicker than calling data() and having the circular buffer
- linearized. The dataOne() and dataTwo() functions do not trigger a
- linearization.
-
- \sa linearise(), data(), dataOne(), dataTwo()
-*/
-
-/* \fn T &Qt3DCore::QCircularBuffer::last()
-
- Returns a reference to the last item in the circular buffer. This
- function assumes that the circular buffer isn't empty.
-
- \sa first(), isEmpty()
-*/
-
-/* \fn const T &Qt3DCore::QCircularBuffer::last() const
-
- \overload
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::lastIndexOf(const T &value, int from = -1) const
-
- Returns the index position of the last occurrence of the value \a
- value in the circular buffer, searching backward from index position \a
- from. If \a from is -1 (the default), the search starts at the
- last item. Returns -1 if no item is matched.
-
- Example:
- \snippet code/src_core_qcircularbuffer.cpp 16
-
- This function requires the value type to have an implementation of
- \c operator==().
-
- \sa indexOf()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::linearise()
-
- Linearizes the internal representation of the circular buffer such that
- all items are stored in a single contiguous array.
-
- This function can be expensive for large circular buffers (\l{linear time}).
-
- \sa isLinearised()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::prepend(const T &value)
-
- Inserts \a value at the beginning of the circular buffer. If the circular buffer
- is full, then the highest index item is overwritten.
-
- Example:
- \snippet code/src_core_qcircularbuffer.cpp 10
-
- This operation is very fast, because QCircularBuffer never allocates
- memory in this function.
-
- \sa operator<<(), operator+=(), append(), insert()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::remove(int i)
-
- Removes the element at index position \a i.
-
- \sa insert(), replace(), fill()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::remove(int i, int count)
-
- \overload
-
- Removes \a count elements from the middle of the circular buffer,
- starting at index position \a i.
-
- \sa insert(), replace(), fill()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::replace(int i, const T &value)
-
- Replaces the item at index position \a i with \a value.
-
- \a i must be a valid index position in the circular buffer (i.e., 0 <= \a
- i < size()).
-
- \sa operator[](), remove()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::reserve(int capacity)
-
- Sets the capacity of the circular buffer to \a capacity. It is a synonym for
- setCapacity().
-
- \sa setCapacity()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::resize(int size)
-
- Changes the size of the circular buffer to \a size which must be > 0 and
- <= capacity(). If \a size is less than the old size, then the highest indexed
- items are removed. If \a size is greater than the old size, then new items
- with a \l{default-constructed value} are appended to the end of the circular
- buffer.
-
- \sa size(), insert(), remove(), capacity(), setCapacity()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::setCapacity(int capacity)
-
- Sets the capacity of the circular buffer to \a capacity.
-
- \sa reserve(), capacity()
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::size() const
-
- Returns the number of items in the circular buffer.
-
- \sa sizeAvailable(), capacity(), resize()
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::sizeAvailable() const
-
- Returns the number of items that can be added to the circular buffer
- without causing the earliest item to be overwritten. It is equivalent
- to (capacity() - size()).
-
- \sa capacity(), isEmpty(), isFull(), size(), freeSize()
-*/
-
-/* \fn void Qt3DCore::QCircularBuffer::squeeze()
-
- Releases any unused memory from the circular buffer. It is equivalent
- to calling setCapacity(size()).
-
- \sa setCapacity(), size(), resize(), sizeAvailable()
-*/
-
-/* \fn bool Qt3DCore::QCircularBuffer::startsWith(const T &value) const
-
- Returns \c true if the circular buffer is not empty and its first
- item is equal to \a value; otherwise returns \c false.
-
- \sa isEmpty(), first(), endsWith()
-*/
-
-/* \fn QList<T> Qt3DCore::QCircularBuffer::toList() const
-
- Returns a QList object with the data contained in this QCircularBuffer.
-
- Example:
-
- \snippet code/src_core_qcircularbuffer.cpp 17
-
- \sa fromList(), toVector()
-*/
-
-/* \fn QVector<T> Qt3DCore::QCircularBuffer::toVector() const
-
- Returns a QVector object with the data contained in this QCircularBuffer.
-
- \sa fromVector(), toList()
-*/
-
-/* \fn T Qt3DCore::QCircularBuffer::value(int i) const
-
- Returns the value at index position \a i in the circular buffer.
-
- If the index \a i is out of bounds, the function returns
- a \l{default-constructed value}. If you are certain that
- \a i is within bounds, you can use at() instead, which is slightly
- faster.
-
- \sa at(), operator[]()
-*/
-
-/* \fn T Qt3DCore::QCircularBuffer::value(int i, const T &defaultValue) const
-
- \overload
-
- If the index \a i is out of bounds, the function returns
- \a defaultValue.
-*/
-
-/* \fn bool Qt3DCore::operator==(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-
- Returns \c true if the circular buffer \a lhs is equal to \a rhs; otherwise
- returns \c false.
-
- Two circular buffers are considered equal if they contain the same values
- in the same order and have the same capacity.
-
- This function requires the value type to have an implementation
- of \c operator==().
-
- \sa operator!=()
-*/
-
-/* \fn bool Qt3DCore::operator!=(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-
- Returns \c true if the circular buffer \a lhs is not equal to \a rhs; otherwise
- returns \c false.
-
- Two circular buffers are considered equal if they contain the same values
- in the same order and have the same capacity.
-
- This function requires the value type to have an implementation
- of \c operator==().
-
- \sa operator==()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer<T>& Qt3DCore::QCircularBuffer::operator+=(const T &other)
-
- Appends the item \a other to this circular buffer and returns a
- reference to this circular buffer.
-
- \sa operator+(), operator<<(), append()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer<T>& Qt3DCore::QCircularBuffer::operator+=(const QCircularBuffer<T>& other)
-
- \overload
-
- Appends the items of the \a other circular buffer to this circular
- buffer and returns a reference to this circular buffer.
-
- \sa operator+(), operator<<(), append()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer<T>& Qt3DCore::QCircularBuffer::operator+=(const QVector<T>& other)
-
- \overload
-*/
-
-/* \fn Qt3DCore::QCircularBuffer<T>& Qt3DCore::QCircularBuffer::operator+=(const QList<T>& other)
-
- \overload
-*/
-
-/* \fn Qt3DCore::QCircularBuffer<T>& Qt3DCore::QCircularBuffer::operator<<(const T &other)
-
- Appends the item \a other to this circular buffer and returns a
- reference to this circular buffer.
-
- \sa operator+(), operator+=(), append()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer<T>& Qt3DCore::QCircularBuffer::operator<<(const QCircularBuffer<T>& other)
-
- \overload
-
- Appends the items of the \a other circular buffer to this circular
- buffer and returns a reference to this circular buffer.
-
- \sa operator+(), operator+=(), append()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer<T>& Qt3DCore::QCircularBuffer::operator<<(const QVector<T>& other)
-
- \overload
-*/
-
-/* \fn Qt3DCore::QCircularBuffer<T>& Qt3DCore::QCircularBuffer::operator<<(const QList<T>& other)
-
- \overload
-*/
-
-/* \fn Qt3DCore::QCircularBuffer<T> Qt3DCore::operator+(const QCircularBuffer<T>& lhs, const QCircularBuffer<T>& rhs)
- \relates Qt3DCore::QCircularBuffer
-
- Returns a circular buffer object with capacity of lhs.size() + rhs.size() containing
- the items from \a lhs followed by the items from \a rhs.
-
- \sa {QCircularBuffer::}{operator+=()}
-*/
-
-/* \fn void Qt3DCore::swap(QCircularBuffer<T> &lhs, QCircularBuffer<T> &rhs)
-
- Swaps the contents of the circular buffer \a lhs with the contents of \a rhs.
-*/
-
-/* \fn bool Qt3DCore::operator<(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-
- Returns \c true if \a lhs is lexographically less than \a rhs. This is equivalent to calling
- \c{return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end())}.
-*/
-
-/* \fn bool Qt3DCore::operator>(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-
- Returns \c true if \a rhs is lexographically less than \a lhs.
-*/
-
-/* \fn bool Qt3DCore::operator>=(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-
- Returns \c true if \a lhs is lexographically less than or equal to \a rhs.
-*/
-
-/* \fn bool Qt3DCore::operator<=(const QCircularBuffer<T> &lhs, const QCircularBuffer<T> &rhs)
-
- Returns \c true if \a lhs is lexographically less than or equal to \a rhs.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::Iterator
-
- Qt-style synonym for \l iterator.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::ConstIterator
-
- Qt-style synonym for \l const_iterator.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::const_pointer
-
- Typedef for const T *. Provided for STL compatibility.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::const_reference
-
- Typedef for T &. Provided for STL compatibility.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::difference_type
-
- Typedef for ptrdiff_t. Provided for STL compatibility.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::pointer
-
- Typedef for T *. Provided for STL compatibility.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::reference
-
- Typedef for T &. Provided for STL compatibility.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::size_type
-
- Typedef for int. Provided for STL compatibility.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::value_type
-
- Typedef for T. Provided for STL compatibility.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::array_range
-
- Typedef for QPair<T*,int>. The first element is a pointer to the
- first element of an array of T. The second element is the number
- of elements in the array.
-
- \sa data(), dataOne(), dataTwo()
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::const_array_range
-
- Typedef for QPair<const T*,int>. The first element is a pointer to the
- first element of an array of const T. The second element is the number
- of elements in the array.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::ArrayRange
-
- Qt-style synonym for \l array_range.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::ConstArrayRange
-
- Qt-style synonym for \l const_array_range.
-*/
-
-
-/* \class Qt3DCore::QCircularBuffer::iterator
- \inmodule Qt3DCore
- \brief The Qt3DCore::QCircularBuffer::iterator class provides an STL-style non-const iterator for QCircularBuffer.
-
- QCircularBuffer provides both \l{STL-Style Iterators} and \l{Java-Style
- Iterators}.
-
- \sa begin(), end(), const_iterator
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::iterator::iterator_category
-
- A synonym for \e {std::random_access_iterator_tag} indicating
- this iterator is a random access iterator.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::iterator::difference_type
-
- \internal
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::iterator::value_type
-
- \internal
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::iterator::pointer
-
- \internal
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::iterator::reference
-
- \internal
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator::iterator()
-
- Constructs an uninitialized iterator.
-
- Functions like operator*() and operator++() should not be called
- on an uninitialized iterator. Use operator=() to assign a value
- to it before using it.
-
- \sa begin(), end()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator::iterator(QCircularBuffer<T> *buffer, int index)
-
- \internal
-*/
-
-/* \fn T &Qt3DCore::QCircularBuffer::iterator::operator*() const
-
- Returns a modifiable reference to the current item.
-
- You can change the value of an item by using operator*() on the
- left side of an assignment.
-
- \sa operator->()
-*/
-
-/* \fn T *Qt3DCore::QCircularBuffer::iterator::operator->() const
-
- Returns a pointer to the current item.
-
- \sa operator*()
-*/
-
-/* \fn T &Qt3DCore::QCircularBuffer::iterator::operator[](int j) const
-
- Returns a modifiable reference to the item at position *this +
- \a{j}.
-
- This function is provided to make QCircularBuffer iterators behave like C++
- pointers.
-
- \sa operator+()
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::iterator::operator==(const iterator &other) const
-
- Returns \c true if \a other points to the same item as this
- iterator; otherwise returns \c false.
-
- \sa operator!=()
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::iterator::operator!=(const iterator &other) const
-
- Returns \c true if \a other points to a different item than this
- iterator; otherwise returns \c false.
-
- \sa operator==()
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::iterator::operator<(const iterator& other) const
-
- Returns \c true if the item pointed to by this iterator occurs before
- the item pointed to by the \a other iterator.
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::iterator::operator<=(const iterator& other) const
-
- Returns \c true if the item pointed to by this iterator occurs before
- or at the same position as the item pointed to by the \a other iterator.
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::iterator::operator>(const iterator& other) const
-
- Returns \c true if the item pointed to by this iterator occurs after
- the item pointed to by the \a other iterator.
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::iterator::operator>=(const iterator& other) const
-
- Returns \c true if the item pointed to by this iterator occurs after
- or at the same position as the item pointed to by the \a other iterator.
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator &Qt3DCore::QCircularBuffer::iterator::operator++()
-
- The prefix ++ operator (\c{++it}) advances the iterator to the
- next item in the circular buffer and returns an iterator to the new current
- item.
-
- Calling this function on end() leads to undefined results.
-
- \sa operator--()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator Qt3DCore::QCircularBuffer::iterator::operator++(int)
-
- \overload
-
- The postfix ++ operator (\c{it++}) advances the iterator to the
- next item in the circular buffer and returns an iterator to the previously
- current item.
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator &Qt3DCore::QCircularBuffer::iterator::operator--()
-
- The prefix -- operator (\c{--it}) makes the preceding item
- the current item, and returns an iterator to the new current item.
-
- Calling this function on begin() leads to undefined results.
-
- \sa operator++()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator Qt3DCore::QCircularBuffer::iterator::operator--(int)
-
- \overload
-
- The postfix -- operator (\c{it--}) makes the preceding item
- the current item, and returns an iterator to the previously current item.
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator &Qt3DCore::QCircularBuffer::iterator::operator+=(int j)
-
- Advances the iterator by \a j items. (If \a j is negative, the
- iterator goes backward.)
-
- \sa operator-=(), operator+()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator &Qt3DCore::QCircularBuffer::iterator::operator-=(int j)
-
- Makes the iterator go back by \a j items. (If \a j is negative,
- the iterator goes forward.)
-
- \sa operator+=(), operator-()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator Qt3DCore::QCircularBuffer::iterator::operator+(int j) const
-
- Returns an iterator to the item at \a j positions forward from
- this iterator. (If \a j is negative, the iterator goes backward.)
-
- \sa operator-(), operator+=()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::iterator Qt3DCore::QCircularBuffer::iterator::operator-(int j) const
-
- Returns an iterator to the item at \a j positions backward from
- this iterator. (If \a j is negative, the iterator goes forward.)
-
- \sa operator+(), operator-=()
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::iterator::operator-(iterator other) const
-
- Returns the number of items between the item pointed to by \a
- other and the item pointed to by this iterator.
-*/
-
-
-/* \class Qt3DCore::QCircularBuffer::const_iterator
- \inmodule Qt3DCore
- \brief The Qt3DCore::QCircularBuffer::const_iterator class provides an STL-style const iterator for QCircularBuffer.
-
- QCircularBuffer provides both \l{STL-Style Iterators} and \l{Java-Style
- Iterators}.
-
- \sa constBegin(), constEnd(), iterator
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::const_iterator::iterator_category
-
- A synonym for \e {std::random_access_iterator_tag} indicating
- this iterator is a random access iterator.
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::const_iterator::difference_type
-
- \internal
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::const_iterator::value_type
-
- \internal
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::const_iterator::pointer
-
- \internal
-*/
-
-/* \typedef Qt3DCore::QCircularBuffer::const_iterator::reference
-
- \internal
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator::const_iterator()
-
- Constructs an uninitialized const iterator.
-
- Functions like operator*() and operator++() should not be called
- on an uninitialized iterator. Use operator=() to assign a value
- to it before using it.
-
- \sa begin(), end()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator::const_iterator(const iterator &other)
-
- \internal
-*/
-
-/* \fn const T &Qt3DCore::QCircularBuffer::const_iterator::operator*() const
-
- Returns a const reference to the current item.
-
- \sa operator->()
-*/
-
-/* \fn const T *Qt3DCore::QCircularBuffer::const_iterator::operator->() const
-
- Returns a pointer to the current item.
-
- \sa operator*()
-*/
-
-/* \fn const T &Qt3DCore::QCircularBuffer::const_iterator::operator[](int j) const
-
- Returns a const reference to the item at position *this +
- \a{j}.
-
- This function is provided to make QCircularBuffer iterators behave like C++
- pointers.
-
- \sa operator+()
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::const_iterator::operator==(const const_iterator &other) const
-
- Returns \c true if \a other points to the same item as this
- iterator; otherwise returns \c false.
-
- \sa operator!=()
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::const_iterator::operator!=(const const_iterator &other) const
-
- Returns \c true if \a other points to a different item than this
- iterator; otherwise returns \c false.
-
- \sa operator==()
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::const_iterator::operator<(const const_iterator& other) const
-
- Returns \c true if the item pointed to by this iterator occurs before
- the item pointed to by the \a other iterator.
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::const_iterator::operator<=(const const_iterator& other) const
-
- Returns \c true if the item pointed to by this iterator occurs before,
- or at the same position as the item pointed to by the \a other iterator.
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::const_iterator::operator>(const const_iterator& other) const
-
- Returns \c true if the item pointed to by this iterator occurs after
- the item pointed to by the \a other iterator.
-*/
-
-/*
- \fn bool Qt3DCore::QCircularBuffer::const_iterator::operator>=(const const_iterator& other) const
-
- Returns \c true if the item pointed to by this iterator occurs after,
- or at the same position as the item pointed to by the \a other iterator.
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator &Qt3DCore::QCircularBuffer::const_iterator::operator++()
-
- The prefix ++ operator (\c{++it}) advances the iterator to the
- next item in the circular buffer and returns an iterator to the new current
- item.
-
- Calling this function on constEnd() leads to undefined results.
-
- \sa operator--()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator Qt3DCore::QCircularBuffer::const_iterator::operator++(int)
-
- \overload
-
- The postfix ++ operator (\c{it++}) advances the iterator to the
- next item in the circular buffer and returns an iterator to the previously
- current item.
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator &Qt3DCore::QCircularBuffer::const_iterator::operator--()
-
- The prefix -- operator (\c{--it}) makes the preceding item the
- current and returns an iterator to the new current item.
-
- Calling this function on constBegin() leads to undefined results.
-
- \sa operator++()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator Qt3DCore::QCircularBuffer::const_iterator::operator--(int)
-
- \overload
-
- The postfix -- operator (\c{it--}) makes the preceding item the
- current and returns an iterator to the previously current item.
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator &Qt3DCore::QCircularBuffer::const_iterator::operator+=(int j)
-
- Advances the iterator by \a j items. (If \a j is negative, the
- iterator goes backward.)
-
- \sa operator-=(), operator+()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator &Qt3DCore::QCircularBuffer::const_iterator::operator-=(int j)
-
- Makes the iterator go back by \a j items. (If \a j is negative,
- the iterator goes forward.)
-
- \sa operator+=(), operator-()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator Qt3DCore::QCircularBuffer::const_iterator::operator+(int j) const
-
- Returns an iterator to the item at \a j positions forward from
- this iterator. (If \a j is negative, the iterator goes backward.)
-
- \sa operator-(), operator+=()
-*/
-
-/* \fn Qt3DCore::QCircularBuffer::const_iterator Qt3DCore::QCircularBuffer::const_iterator::operator-(int j) const
-
- Returns an iterator to the item at \a j positions backward from
- this iterator. (If \a j is negative, the iterator goes forward.)
-
- \sa operator+(), operator-=()
-*/
-
-/* \fn int Qt3DCore::QCircularBuffer::const_iterator::operator-(const_iterator other) const
-
- Returns the number of items between the item pointed to by \a
- other and the item pointed to by this iterator.
-*/
diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicscontext.cpp b/src/plugins/renderers/opengl/graphicshelpers/graphicscontext.cpp
index a4152449f..16cc3ff8f 100644
--- a/src/plugins/renderers/opengl/graphicshelpers/graphicscontext.cpp
+++ b/src/plugins/renderers/opengl/graphicshelpers/graphicscontext.cpp
@@ -83,7 +83,9 @@
#include <QSurface>
#include <QWindow>
#include <QOpenGLTexture>
-#include <QOpenGLDebugLogger>
+#ifdef QT_OPENGL_LIB
+#include <QtOpenGL/QOpenGLDebugLogger>
+#endif
QT_BEGIN_NAMESPACE
@@ -122,10 +124,12 @@ namespace OpenGL {
namespace {
+#ifdef QT_OPENGL_LIB
void logOpenGLDebugMessage(const QOpenGLDebugMessage &debugMessage)
{
qDebug() << "OpenGL debug message:" << debugMessage;
}
+#endif
} // anonymous
@@ -137,7 +141,9 @@ GraphicsContext::GraphicsContext()
, m_defaultFBO(0)
, m_gl(nullptr)
, m_glHelper(nullptr)
+#ifdef QT_OPENGL_LIB
, m_debugLogger(nullptr)
+#endif
, m_currentVAO(nullptr)
{
}
@@ -402,6 +408,7 @@ GraphicsHelperInterface *GraphicsContext::resolveHighestOpenGLFunctions()
const QByteArray debugLoggingMode = qgetenv("QT3DRENDER_DEBUG_LOGGING");
const bool enableDebugLogging = !debugLoggingMode.isEmpty();
+#ifdef QT_OPENGL_LIB
if (enableDebugLogging && !m_debugLogger) {
if (m_gl->hasExtension("GL_KHR_debug")) {
qCDebug(Backend) << "Qt3D: Enabling OpenGL debug logging";
@@ -421,7 +428,7 @@ GraphicsHelperInterface *GraphicsContext::resolveHighestOpenGLFunctions()
qCDebug(Backend) << "Qt3D: OpenGL debug logging requested but GL_KHR_debug not supported";
}
}
-
+#endif
// Set Vendor and Extensions of reference GraphicsApiFilter
// TO DO: would that vary like the glHelper ?
diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicscontext_p.h b/src/plugins/renderers/opengl/graphicshelpers/graphicscontext_p.h
index 5d122f450..8da1a420c 100644
--- a/src/plugins/renderers/opengl/graphicshelpers/graphicscontext_p.h
+++ b/src/plugins/renderers/opengl/graphicshelpers/graphicscontext_p.h
@@ -78,7 +78,9 @@ QT_BEGIN_NAMESPACE
class QOpenGLShaderProgram;
class QAbstractOpenGLFunctions;
+#ifdef QT_OPENGL_LIB
class QOpenGLDebugLogger;
+#endif
namespace Qt3DRender {
@@ -201,7 +203,9 @@ public:
QHash<QSurface *, GraphicsHelperInterface*> m_glHelpers;
GraphicsApiFilterData m_contextInfo;
+#ifdef QT_OPENGL_LIB
QScopedPointer<QOpenGLDebugLogger> m_debugLogger;
+#endif
friend class OpenGLVertexArrayObject;
OpenGLVertexArrayObject *m_currentVAO;
diff --git a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp
index e4b223185..25a7d0036 100644
--- a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp
+++ b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp
@@ -83,7 +83,9 @@
#include <QSurface>
#include <QWindow>
#include <QOpenGLTexture>
-#include <QOpenGLDebugLogger>
+#ifdef QT_OPENGL_LIB
+#include <QtOpenGL/QOpenGLDebugLogger>
+#endif
QT_BEGIN_NAMESPACE
@@ -762,10 +764,12 @@ void SubmissionContext::releaseOpenGL()
m_renderBufferHash.clear();
// Stop and destroy the OpenGL logger
+#ifdef QT_OPENGL_LIB
if (m_debugLogger) {
m_debugLogger->stopLogging();
m_debugLogger.reset(nullptr);
}
+#endif
}
// The OpenGLContext is not current on any surface at this point
diff --git a/src/plugins/renderers/opengl/jobs/renderviewinitializerjob.cpp b/src/plugins/renderers/opengl/jobs/renderviewinitializerjob.cpp
index 6be1016f0..e84ecc899 100644
--- a/src/plugins/renderers/opengl/jobs/renderviewinitializerjob.cpp
+++ b/src/plugins/renderers/opengl/jobs/renderviewinitializerjob.cpp
@@ -85,7 +85,6 @@ void RenderViewInitializerJob::run()
#endif
// Create a RenderView object
- // The RenderView are created from a QFrameAllocator stored in the current Thread local storage
m_renderView = new RenderView;
// RenderView should allocate heap resources using only the currentFrameAllocator
diff --git a/src/plugins/renderers/opengl/jobs/renderviewinitializerjob_p.h b/src/plugins/renderers/opengl/jobs/renderviewinitializerjob_p.h
index 2ebb5dc36..fa69719cc 100644
--- a/src/plugins/renderers/opengl/jobs/renderviewinitializerjob_p.h
+++ b/src/plugins/renderers/opengl/jobs/renderviewinitializerjob_p.h
@@ -53,7 +53,6 @@
//
#include <Qt3DCore/qaspectjob.h>
-#include <Qt3DCore/private/qframeallocator_p.h>
#include <QSize>
QT_BEGIN_NAMESPACE
diff --git a/src/plugins/renderers/opengl/jobs/renderviewjobutils_p.h b/src/plugins/renderers/opengl/jobs/renderviewjobutils_p.h
index 5b1413108..7b5ba2bfd 100644
--- a/src/plugins/renderers/opengl/jobs/renderviewjobutils_p.h
+++ b/src/plugins/renderers/opengl/jobs/renderviewjobutils_p.h
@@ -63,10 +63,6 @@
QT_BEGIN_NAMESPACE
-namespace Qt3DCore {
-class QFrameAllocator;
-}
-
namespace Qt3DRender {
namespace Render {
diff --git a/src/plugins/renderers/opengl/opengl.pri b/src/plugins/renderers/opengl/opengl.pri
index 1682ab7b3..657eb8556 100644
--- a/src/plugins/renderers/opengl/opengl.pri
+++ b/src/plugins/renderers/opengl/opengl.pri
@@ -1,4 +1,4 @@
-QT += core-private gui-private 3dcore 3dcore-private 3drender 3drender-private
+QT += core-private gui-private 3dcore 3dcore-private 3drender 3drender-private opengl-private
QT_PRIVATE = openglextensions
# Qt3D is free of Q_FOREACH - make sure it stays that way:
diff --git a/src/plugins/renderers/opengl/renderer/frameprofiler_p.h b/src/plugins/renderers/opengl/renderer/frameprofiler_p.h
index 59c9b68b6..591ace53e 100644
--- a/src/plugins/renderers/opengl/renderer/frameprofiler_p.h
+++ b/src/plugins/renderers/opengl/renderer/frameprofiler_p.h
@@ -40,7 +40,7 @@
// We mean it.
//
-#include <QOpenGLTimerQuery>
+#include <QOpenGLTimeMonitor>
#include <Qt3DCore/private/qthreadpooler_p.h>
#include <Qt3DCore/private/qt3dcore_global_p.h>
#include <memory>
diff --git a/src/plugins/renderers/opengl/renderer/renderer_p.h b/src/plugins/renderers/opengl/renderer/renderer_p.h
index f24e77152..4a6a26d93 100644
--- a/src/plugins/renderers/opengl/renderer/renderer_p.h
+++ b/src/plugins/renderers/opengl/renderer/renderer_p.h
@@ -113,7 +113,6 @@ class QScreen;
namespace Qt3DCore {
class QEntity;
-class QFrameAllocator;
class QEventFilterService;
}
diff --git a/src/plugins/renderers/opengl/renderer/renderview_p.h b/src/plugins/renderers/opengl/renderer/renderview_p.h
index a835c17f0..9d4e09df3 100644
--- a/src/plugins/renderers/opengl/renderer/renderview_p.h
+++ b/src/plugins/renderers/opengl/renderer/renderview_p.h
@@ -66,7 +66,6 @@
#include <Qt3DRender/private/qblitframebuffer_p.h>
#include <Qt3DRender/private/qwaitfence_p.h>
-#include <Qt3DCore/private/qframeallocator_p.h>
#include <Qt3DRender/private/aligned_malloc_p.h>
#include <renderer_p.h>
diff --git a/src/plugins/renderers/opengl/renderer/shaderparameterpack.cpp b/src/plugins/renderers/opengl/renderer/shaderparameterpack.cpp
index 8c509f804..c51595bb7 100644
--- a/src/plugins/renderers/opengl/renderer/shaderparameterpack.cpp
+++ b/src/plugins/renderers/opengl/renderer/shaderparameterpack.cpp
@@ -42,8 +42,6 @@
#include <graphicscontext_p.h>
#include <Qt3DRender/private/texture_p.h>
-#include <Qt3DCore/private/qframeallocator_p.h>
-
#include <QOpenGLShaderProgram>
#include <QDebug>
#include <QColor>
diff --git a/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h b/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h
index d658d223b..31ef4f7ea 100644
--- a/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h
+++ b/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h
@@ -64,10 +64,6 @@ QT_BEGIN_NAMESPACE
class QOpenGLShaderProgram;
-namespace Qt3DCore {
-class QFrameAllocator;
-}
-
namespace Qt3DRender {
namespace Render {
namespace OpenGL {
diff --git a/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp b/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp
index b4b87ef76..0f9a3bef9 100644
--- a/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp
+++ b/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp
@@ -284,9 +284,7 @@ GLTFExporter::~GLTFExporter()
// options : Export options.
//
// Supported options are:
-// "binaryJson" (bool): Generates a binary JSON file, which is more efficient to parse.
// "compactJson" (bool): Removes unnecessary whitespace from the generated JSON file.
-// Ignored if "binaryJson" option is true.
/*!
Exports the scene to the GLTF format
@@ -322,8 +320,6 @@ bool GLTFExporter::exportScene(QEntity *sceneRoot, const QString &outDir,
m_renderPassCount = 0;
m_effectCount = 0;
- m_gltfOpts.binaryJson = options.value(QStringLiteral("binaryJson"),
- QVariant(false)).toBool();
m_gltfOpts.compactJson = options.value(QStringLiteral("compactJson"),
QVariant(false)).toBool();
@@ -1582,32 +1578,18 @@ bool GLTFExporter::saveScene()
QString gltfName = m_exportDir + m_exportName + QStringLiteral(".qgltf");
f.setFileName(gltfName);
- qCDebug(GLTFExporterLog, " Writing %sJSON file: '%ls'",
- m_gltfOpts.binaryJson ? "binary " : "", qUtf16PrintableImpl(gltfName));
+ qCDebug(GLTFExporterLog, " Writing JSON file: '%ls'", qUtf16PrintableImpl(gltfName));
- if (m_gltfOpts.binaryJson) {
- if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
- m_exportedFiles.insert(QFileInfo(f.fileName()).fileName());
- QByteArray json = m_doc.toBinaryData();
- f.write(json);
- f.close();
- } else {
- qCWarning(GLTFExporterLog, " Writing binary JSON file '%ls' failed!",
- qUtf16PrintableImpl(gltfName));
- return false;
- }
+ if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
+ m_exportedFiles.insert(QFileInfo(f.fileName()).fileName());
+ QByteArray json = m_doc.toJson(m_gltfOpts.compactJson ? QJsonDocument::Compact
+ : QJsonDocument::Indented);
+ f.write(json);
+ f.close();
} else {
- if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
- m_exportedFiles.insert(QFileInfo(f.fileName()).fileName());
- QByteArray json = m_doc.toJson(m_gltfOpts.compactJson ? QJsonDocument::Compact
- : QJsonDocument::Indented);
- f.write(json);
- f.close();
- } else {
- qCWarning(GLTFExporterLog, " Writing JSON file '%ls' failed!",
- qUtf16PrintableImpl(gltfName));
- return false;
- }
+ qCWarning(GLTFExporterLog, " Writing JSON file '%ls' failed!",
+ qUtf16PrintableImpl(gltfName));
+ return false;
}
QString qrcName = m_exportDir + m_exportName + QStringLiteral(".qrc");
diff --git a/src/plugins/sceneparsers/gltfexport/gltfexporter.h b/src/plugins/sceneparsers/gltfexport/gltfexporter.h
index fe6977a6e..e135ea8eb 100644
--- a/src/plugins/sceneparsers/gltfexport/gltfexporter.h
+++ b/src/plugins/sceneparsers/gltfexport/gltfexporter.h
@@ -94,7 +94,6 @@ public:
const QString &exportName, const QVariantHash &options) final;
struct GltfOptions {
- bool binaryJson;
bool compactJson;
};
diff --git a/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp b/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp
index efb9fa706..8ca625a3e 100644
--- a/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp
+++ b/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp
@@ -102,8 +102,9 @@ void Qt3DQuick3DAnimationPlugin::registerTypes(const char *uri)
qmlRegisterUncreatableType<Qt3DAnimation::QAbstractChannelMapping>(uri, 2, 10, "AbstractChannelMapping", QStringLiteral("QAbstractChannelMapping is abstract"));
qmlRegisterType<Qt3DAnimation::QSkeletonMapping>(uri, 2, 10, "SkeletonMapping");
- // Auto-increment the import to stay in sync with ALL future Qt minor versions
- qmlRegisterModule(uri, 2, QT_VERSION_MINOR);
+ // The minor version used to be the current Qt 5 minor. For compatibility it is the last
+ // Qt 5 release.
+ qmlRegisterModule(uri, 2, 15);
}
QT_END_NAMESPACE
diff --git a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
index 59df221ab..75fa7b2da 100644
--- a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
+++ b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
@@ -84,8 +84,9 @@ void Qt3DQuick3DCorePlugin::registerTypes(const char *uri)
Qt3DCore::Quick::registerExtendedType<Qt3DCore::QJoint, Qt3DCore::Quick::Quick3DJoint>("QJoint", "Qt3D.Core/Joint", uri, 2, 10, "Joint");
- // Auto-increment the import to stay in sync with ALL future Qt minor versions
- qmlRegisterModule(uri, 2, QT_VERSION_MINOR);
+ // The minor version used to be the current Qt 5 minor. For compatibility it is the last
+ // Qt 5 release.
+ qmlRegisterModule(uri, 2, 15);
}
Qt3DQuick3DCorePlugin::~Qt3DQuick3DCorePlugin()
diff --git a/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp b/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp
index 9739b6604..707824182 100644
--- a/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp
+++ b/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp
@@ -148,7 +148,7 @@ QT_WARNING_POP
qmlRegisterType<Qt3DExtras::QText2DEntity>(uri, 2, 9, "Text2DEntity");
// Auto-increment the import to stay in sync with ALL future Qt minor versions
- qmlRegisterModule(uri, 2, QT_VERSION_MINOR);
+ qmlRegisterModule(uri, 2, 15);
}
diff --git a/src/quick3d/imports/input/qt3dquick3dinputplugin.cpp b/src/quick3d/imports/input/qt3dquick3dinputplugin.cpp
index 2a9596a00..3ea731885 100644
--- a/src/quick3d/imports/input/qt3dquick3dinputplugin.cpp
+++ b/src/quick3d/imports/input/qt3dquick3dinputplugin.cpp
@@ -106,8 +106,9 @@ void Qt3DQuick3DInputPlugin::registerTypes(const char *uri)
qmlRegisterType<Qt3DInput::QGamepadInput>(uri, 2, 0, "GamepadInput");
#endif
- // Auto-increment the import to stay in sync with ALL future Qt minor versions
- qmlRegisterModule(uri, 2, QT_VERSION_MINOR);
+ // The minor version used to be the current Qt 5 minor. For compatibility it is the last
+ // Qt 5 release.
+ qmlRegisterModule(uri, 2, 15);
}
QT_END_NAMESPACE
diff --git a/src/quick3d/imports/logic/qt3dquick3dlogicplugin.cpp b/src/quick3d/imports/logic/qt3dquick3dlogicplugin.cpp
index 0fbe64002..969b28a0d 100644
--- a/src/quick3d/imports/logic/qt3dquick3dlogicplugin.cpp
+++ b/src/quick3d/imports/logic/qt3dquick3dlogicplugin.cpp
@@ -48,8 +48,9 @@ void Qt3DQuick3DLogicPlugin::registerTypes(const char *uri)
{
qmlRegisterType<Qt3DLogic::QFrameAction>(uri, 2, 0, "FrameAction");
- // Auto-increment the import to stay in sync with ALL future Qt minor versions
- qmlRegisterModule(uri, 2, QT_VERSION_MINOR);
+ // The minor version used to be the current Qt 5 minor. For compatibility it is the last
+ // Qt 5 release.
+ qmlRegisterModule(uri, 2, 15);
}
QT_END_NAMESPACE
diff --git a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp
index 8acd71715..e42be550d 100644
--- a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp
+++ b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp
@@ -324,8 +324,9 @@ void Qt3DQuick3DRenderPlugin::registerTypes(const char *uri)
qmlRegisterType<Qt3DRender::QLineWidth>(uri, 2, 10, "LineWidth");
qmlRegisterType<Qt3DRender::QRasterMode>(uri, 2, 13, "RasterMode");
- // Auto-increment the import to stay in sync with ALL future Qt minor versions
- qmlRegisterModule(uri, 2, QT_VERSION_MINOR);
+ // The minor version used to be the current Qt 5 minor. For compatibility it is the last
+ // Qt 5 release.
+ qmlRegisterModule(uri, 2, 15);
}
QT_END_NAMESPACE
diff --git a/src/quick3d/imports/scene2d/qtquickscene2dplugin.cpp b/src/quick3d/imports/scene2d/qtquickscene2dplugin.cpp
index 0c410e84b..b63400ad9 100644
--- a/src/quick3d/imports/scene2d/qtquickscene2dplugin.cpp
+++ b/src/quick3d/imports/scene2d/qtquickscene2dplugin.cpp
@@ -54,8 +54,9 @@ void QtQuickScene2DPlugin::registerTypes(const char *uri)
{
qmlRegisterExtendedType<Qt3DRender::Quick::QScene2D, Qt3DRender::Render::Quick::QQuick3DScene2D>(uri, 2, 9, "Scene2D");
- // Auto-increment the import to stay in sync with ALL future Qt minor versions
- qmlRegisterModule(uri, 2, QT_VERSION_MINOR);
+ // The minor version used to be the current Qt 5 minor. For compatibility it is the last
+ // Qt 5 release.
+ qmlRegisterModule(uri, 2, 15);
}
QT_END_NAMESPACE
diff --git a/src/quick3d/imports/scene3d/qtquickscene3dplugin.cpp b/src/quick3d/imports/scene3d/qtquickscene3dplugin.cpp
index 00f24070e..3da9a54fc 100644
--- a/src/quick3d/imports/scene3d/qtquickscene3dplugin.cpp
+++ b/src/quick3d/imports/scene3d/qtquickscene3dplugin.cpp
@@ -52,8 +52,9 @@ void QtQuickScene3DPlugin::registerTypes(const char *uri)
qmlRegisterType<Qt3DRender::Scene3DItem, 14>(uri, 2, 14, "Scene3D");
qmlRegisterType<Qt3DRender::Scene3DView>(uri, 2, 14, "Scene3DView");
- // Auto-increment the import to stay in sync with ALL future Qt minor versions
- qmlRegisterModule(uri, 2, QT_VERSION_MINOR);
+ // The minor version used to be the current Qt 5 minor. For compatibility it is the last
+ // Qt 5 release.
+ qmlRegisterModule(uri, 2, 15);
}
QT_END_NAMESPACE
diff --git a/src/quick3d/quick3d/qt3dquicknodefactory.cpp b/src/quick3d/quick3d/qt3dquicknodefactory.cpp
index 1a37f9acc..87069a10e 100644
--- a/src/quick3d/quick3d/qt3dquicknodefactory.cpp
+++ b/src/quick3d/quick3d/qt3dquicknodefactory.cpp
@@ -64,7 +64,7 @@ QNode *QuickNodeFactory::createNode(const char *type)
if (!typeInfo.resolved) {
typeInfo.resolved = true;
- typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), typeInfo.version.first, typeInfo.version.second);
+ typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), QTypeRevision::fromVersion(typeInfo.version.first, typeInfo.version.second));
}
return typeInfo.t.isValid() ? qobject_cast<QNode *>(typeInfo.t.create()) : nullptr;
diff --git a/src/quick3d/quick3danimation/qt3dquickanimationnodefactory.cpp b/src/quick3d/quick3danimation/qt3dquickanimationnodefactory.cpp
index 879389bd9..b31b3048e 100644
--- a/src/quick3d/quick3danimation/qt3dquickanimationnodefactory.cpp
+++ b/src/quick3d/quick3danimation/qt3dquickanimationnodefactory.cpp
@@ -64,7 +64,7 @@ Qt3DCore::QNode *QuickAnimationNodeFactory::createNode(const char *type)
if (!typeInfo.resolved) {
typeInfo.resolved = true;
- typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), typeInfo.version.first, typeInfo.version.second);
+ typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), QTypeRevision::fromVersion(typeInfo.version.first, typeInfo.version.second));
}
return typeInfo.t.isValid() ? qobject_cast<Qt3DCore::QNode *>(typeInfo.t.create()) : nullptr;
diff --git a/src/quick3d/quick3dextras/qt3dquickextrasnodefactory.cpp b/src/quick3d/quick3dextras/qt3dquickextrasnodefactory.cpp
index 2e1f993f9..8897a6b75 100644
--- a/src/quick3d/quick3dextras/qt3dquickextrasnodefactory.cpp
+++ b/src/quick3d/quick3dextras/qt3dquickextrasnodefactory.cpp
@@ -64,7 +64,7 @@ Qt3DCore::QNode *QuickExtrasNodeFactory::createNode(const char *type)
if (!typeInfo.resolved) {
typeInfo.resolved = true;
- typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), typeInfo.version.first, typeInfo.version.second);
+ typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), QTypeRevision::fromVersion(typeInfo.version.first, typeInfo.version.second));
}
return typeInfo.t.isValid() ? qobject_cast<Qt3DCore::QNode *>(typeInfo.t.create()) : nullptr;
diff --git a/src/quick3d/quick3dinput/qt3dquickinputnodefactory.cpp b/src/quick3d/quick3dinput/qt3dquickinputnodefactory.cpp
index 0692b15d6..8b2e4d557 100644
--- a/src/quick3d/quick3dinput/qt3dquickinputnodefactory.cpp
+++ b/src/quick3d/quick3dinput/qt3dquickinputnodefactory.cpp
@@ -64,7 +64,7 @@ Qt3DCore::QNode *QuickInputNodeFactory::createNode(const char *type)
if (!typeInfo.resolved) {
typeInfo.resolved = true;
- typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), typeInfo.version.first, typeInfo.version.second);
+ typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), QTypeRevision::fromVersion(typeInfo.version.first, typeInfo.version.second));
}
return typeInfo.t.isValid() ? qobject_cast<Qt3DCore::QNode *>(typeInfo.t.create()) : nullptr;
diff --git a/src/quick3d/quick3drender/qt3dquickrendernodefactory.cpp b/src/quick3d/quick3drender/qt3dquickrendernodefactory.cpp
index a4f786a76..f146bbe4e 100644
--- a/src/quick3d/quick3drender/qt3dquickrendernodefactory.cpp
+++ b/src/quick3d/quick3drender/qt3dquickrendernodefactory.cpp
@@ -64,7 +64,7 @@ Qt3DCore::QNode *QuickRenderNodeFactory::createNode(const char *type)
if (!typeInfo.resolved) {
typeInfo.resolved = true;
- typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), typeInfo.version.first, typeInfo.version.second);
+ typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), QTypeRevision::fromVersion(typeInfo.version.first, typeInfo.version.second));
}
return typeInfo.t.isValid() ? qobject_cast<Qt3DCore::QNode *>(typeInfo.t.create()) : nullptr;
diff --git a/src/quick3d/quick3dscene2d/qt3dquickscene2dnodefactory.cpp b/src/quick3d/quick3dscene2d/qt3dquickscene2dnodefactory.cpp
index 417b28ea0..f757b0bbc 100644
--- a/src/quick3d/quick3dscene2d/qt3dquickscene2dnodefactory.cpp
+++ b/src/quick3d/quick3dscene2d/qt3dquickscene2dnodefactory.cpp
@@ -77,7 +77,7 @@ Qt3DCore::QNode *QuickScene2DNodeFactory::createNode(const char *type)
if (!typeInfo.resolved) {
typeInfo.resolved = true;
typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName),
- typeInfo.version.first, typeInfo.version.second);
+ QTypeRevision::fromVersion(typeInfo.version.first, typeInfo.version.second));
}
return typeInfo.t.isValid() ? qobject_cast<Qt3DCore::QNode *>(typeInfo.t.create()) : nullptr;
diff --git a/src/render/framegraph/qrendercapture.cpp b/src/render/framegraph/qrendercapture.cpp
index 3c6f90c7c..a10083374 100644
--- a/src/render/framegraph/qrendercapture.cpp
+++ b/src/render/framegraph/qrendercapture.cpp
@@ -119,6 +119,7 @@ namespace Qt3DRender {
* \since 5.9
*/
+#if QT_DEPRECATED_SINCE(5, 9)
/*!
* \qmlmethod void Qt3D.Render::RenderCaptureReply::saveToFile(fileName)
* \deprecated
@@ -127,6 +128,7 @@ namespace Qt3DRender {
*
* Deprecated in 5.9. Use saveImage().
*/
+#endif
/*!
* \qmlmethod RenderCaptureReply Qt3D.Render::RenderCapture::requestCapture(int captureId)
@@ -226,6 +228,7 @@ bool QRenderCaptureReply::saveImage(const QString &fileName) const
return false;
}
+#if QT_DEPRECATED_SINCE(5, 9)
/*!
* \deprecated
* Saves the render capture result as an image to \a fileName.
@@ -238,6 +241,7 @@ void QRenderCaptureReply::saveToFile(const QString &fileName) const
if (d->m_complete)
d->m_image.save(fileName);
}
+#endif
/*!
* \internal
diff --git a/src/render/picking/qpicktriangleevent_p.h b/src/render/picking/qpicktriangleevent_p.h
index d646ac2bb..738c985d9 100644
--- a/src/render/picking/qpicktriangleevent_p.h
+++ b/src/render/picking/qpicktriangleevent_p.h
@@ -37,6 +37,17 @@
**
****************************************************************************/
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#ifndef QT3DRENDER_QPICKTRIANGLEEVENT_P_H
#define QT3DRENDER_QPICKTRIANGLEEVENT_P_H
diff --git a/src/render/render.pro b/src/render/render.pro
index bf7ef072f..2b81e8a06 100644
--- a/src/render/render.pro
+++ b/src/render/render.pro
@@ -1,7 +1,7 @@
TARGET = Qt3DRender
MODULE = 3drender
-QT = core-private 3dcore-private
+QT = core-private 3dcore-private opengl
QT_FOR_PRIVATE = concurrent
DEFINES += BUILD_QT3D_MODULE
diff --git a/tests/auto/core/core.pro b/tests/auto/core/core.pro
index 994c6206c..3e4a8479d 100644
--- a/tests/auto/core/core.pro
+++ b/tests/auto/core/core.pro
@@ -3,8 +3,6 @@ TEMPLATE = subdirs
SUBDIRS = \
handle \
qresourcemanager \
- qcircularbuffer \
- qboundedcircularbuffer \
nodes \
qaspectengine \
qaspectfactory \
@@ -20,7 +18,6 @@ SUBDIRS = \
qtConfig(private_tests) {
SUBDIRS += \
qentity \
- qframeallocator \
qtransform \
threadpooler \
qpostman \
diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp
index aac8638c1..c39638754 100644
--- a/tests/auto/core/nodes/tst_nodes.cpp
+++ b/tests/auto/core/nodes/tst_nodes.cpp
@@ -1314,7 +1314,8 @@ void tst_Nodes::removingMultipleChildNodesFromNode()
// WHEN
spy.events.clear();
- qDeleteAll(root->children());
+ auto cl = root->children();
+ qDeleteAll(cl);
// THEN
QVERIFY(root->children().count() == 0);
diff --git a/tests/auto/core/qboundedcircularbuffer/qboundedcircularbuffer.pro b/tests/auto/core/qboundedcircularbuffer/qboundedcircularbuffer.pro
deleted file mode 100644
index 80ae30b67..000000000
--- a/tests/auto/core/qboundedcircularbuffer/qboundedcircularbuffer.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-TARGET = tst_qboundedcircularbuffer
-CONFIG += testcase
-TEMPLATE = app
-QT += testlib 3dcore 3dcore-private
-
-DEFINES += SRCDIR=\\\"$$PWD/\\\"
-
-SOURCES += tst_qboundedcircularbuffer.cpp
diff --git a/tests/auto/core/qboundedcircularbuffer/tst_qboundedcircularbuffer.cpp b/tests/auto/core/qboundedcircularbuffer/tst_qboundedcircularbuffer.cpp
deleted file mode 100644
index d2ef6d97d..000000000
--- a/tests/auto/core/qboundedcircularbuffer/tst_qboundedcircularbuffer.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QObject>
-#include <QtTest/QtTest>
-
-#include <Qt3DCore/private/qboundedcircularbuffer_p.h>
-
-using namespace Qt3DCore;
-
-class tst_QBoundedCircularBuffer : public QObject
-{
- Q_OBJECT
-private Q_SLOTS:
- void construction();
- void clear();
- void push();
- void pop();
- void at();
- void producerConsumer();
-};
-
-class MyComplexType
-{
-public:
- MyComplexType(int xx = 0)
- : x(xx),
- magicCheck(ms_magic)
- {
- ++ms_activeCount;
- }
-
- MyComplexType(const MyComplexType &other)
- : x(other.x),
- magicCheck(other.magicCheck)
- {
- ++ms_activeCount;
- }
-
- ~MyComplexType()
- {
- // Check that the constructor was actually called
- QVERIFY(ms_magic == magicCheck);
- --ms_activeCount;
- }
-
- MyComplexType &operator=(const MyComplexType &other)
- {
- if (this == &other)
- return *this;
- x = other.x;
- magicCheck = other.magicCheck;
- return *this;
- }
-
- int x;
- int magicCheck;
-
- static const int ms_magic = 0xfefefefe;
- static int ms_activeCount;
-};
-
-int MyComplexType::ms_activeCount = 0;
-
-void tst_QBoundedCircularBuffer::construction()
-{
- QBoundedCircularBuffer<int> buffer(10);
- QVERIFY(buffer.capacity() == 10);
- QVERIFY(buffer.freeSize() == 10);
- QVERIFY(buffer.size() == 0);
- QVERIFY(buffer.isEmpty() == true);
- QVERIFY(buffer.isFull() == false);
-}
-
-void tst_QBoundedCircularBuffer::clear()
-{
- QBoundedCircularBuffer<int> buffer(10);
- buffer.clear();
- QVERIFY(buffer.capacity() == 10);
- QVERIFY(buffer.freeSize() == 10);
- QVERIFY(buffer.size() == 0);
- QVERIFY(buffer.isEmpty() == true);
- QVERIFY(buffer.isFull() == false);
-}
-
-void tst_QBoundedCircularBuffer::push()
-{
- QBoundedCircularBuffer<MyComplexType> buffer(20);
- QVERIFY(buffer.freeSize() == 20);
- for (int i = 0; i < 15; i++) {
- const MyComplexType value(i);
- buffer.push(value);
- const MyComplexType testValue = buffer.back();
- QVERIFY(testValue.x == value.x);
- }
- QVERIFY(buffer.freeSize() == 5);
- QVERIFY(buffer.size() == 15);
-}
-
-void tst_QBoundedCircularBuffer::pop()
-{
- QBoundedCircularBuffer<MyComplexType> buffer(20);
- for (int i = 0; i < 15; i++) {
- const MyComplexType value(i);
- buffer.push(value);
- }
-
- for (int j = 0; j < 10; j++) {
- const MyComplexType value = buffer.pop();
- QVERIFY(value.x == j);
- }
- QVERIFY(buffer.freeSize() == 15);
- QVERIFY(buffer.size() == 5);
-}
-
-void tst_QBoundedCircularBuffer::at()
-{
- QBoundedCircularBuffer<MyComplexType> buffer(20);
- for (int i = 0; i < 10; i++) {
- const MyComplexType value(i);
- buffer.append(value);
- }
-
- for (int i = 0; i < 10; i++)
- QVERIFY(buffer.at(i).x == i);
-}
-
-class MyProducer : public QThread
-{
- Q_OBJECT
-public:
- MyProducer(QBoundedCircularBuffer<MyComplexType> *buffer)
- : QThread(),
- m_buffer(buffer)
- {
- }
-
- void run()
- {
- for (int i = 0; i < 10000; i++ ) {
- //qDebug() << "Producing" << i;
- const MyComplexType value(i);
- //if ( m_buffer->isFull() )
- // qDebug() << i << "The buffer is full. Waiting for consumer...";
- m_buffer->push(value);
-
- // Uncomment and adjust this to slow the producer down
- // usleep(130);
- }
- }
-
-private:
- QBoundedCircularBuffer<MyComplexType>* m_buffer;
-};
-
-class MyConsumer : public QThread
-{
- Q_OBJECT
-public:
- MyConsumer(QBoundedCircularBuffer<MyComplexType>* buffer)
- : QThread(),
- m_buffer(buffer)
- {}
-
- void run()
- {
- for (int i = 0; i < 10000; i++) {
- //qDebug() << "Consuming" << i;
- //if (m_buffer->isEmpty())
- // qDebug() << i << "The buffer is empty. Waiting for producer...";
- const MyComplexType value = m_buffer->pop();
- QVERIFY(value.x == i);
-
- // Uncomment and adjust this to slow the consumer down
- //usleep(100);
- }
- }
-
-private:
- QBoundedCircularBuffer<MyComplexType>* m_buffer;
-};
-
-void tst_QBoundedCircularBuffer::producerConsumer()
-{
- QBoundedCircularBuffer<MyComplexType> *buffer = new QBoundedCircularBuffer<MyComplexType>(20);
- MyProducer producer(buffer);
- MyConsumer consumer(buffer);
-
- // Produce and consume...
- producer.start();
- consumer.start();
-
- // Wait until both threads are done
- producer.wait();
- consumer.wait();
-
- // Check all items have been consumed
- QVERIFY(buffer->freeSize() == 20);
- QVERIFY(buffer->size() == 0);
-
- // Cleanup
- delete buffer;
-}
-
-QTEST_APPLESS_MAIN(tst_QBoundedCircularBuffer)
-#include "tst_qboundedcircularbuffer.moc"
diff --git a/tests/auto/core/qcircularbuffer/qcircularbuffer.pro b/tests/auto/core/qcircularbuffer/qcircularbuffer.pro
deleted file mode 100644
index 24fc35ff3..000000000
--- a/tests/auto/core/qcircularbuffer/qcircularbuffer.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-TARGET = tst_qcircularbuffer
-CONFIG += testcase
-TEMPLATE = app
-QT += testlib 3dcore 3dcore-private
-
-DEFINES += SRCDIR=\\\"$$PWD/\\\"
-
-SOURCES += tst_qcircularbuffer.cpp
diff --git a/tests/auto/core/qcircularbuffer/tst_qcircularbuffer.cpp b/tests/auto/core/qcircularbuffer/tst_qcircularbuffer.cpp
deleted file mode 100644
index 7d8f6eed6..000000000
--- a/tests/auto/core/qcircularbuffer/tst_qcircularbuffer.cpp
+++ /dev/null
@@ -1,2044 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QObject>
-#include <QtTest/QtTest>
-
-#include <Qt3DCore/private/qcircularbuffer_p.h>
-
-using namespace Qt3DCore;
-
-class tst_QCircularBuffer : public QObject
-{
- Q_OBJECT
-private Q_SLOTS:
- void construction();
- void destruction();
-
- void append();
- void at();
- void capacity();
- void clear();
- void contains();
- void count();
- void data();
- void dataOneTwo();
- void endsWith();
- void erase();
- void fill();
- void first();
- void fromList();
- void fromVector();
- void indexOf();
- void insert();
- void insertIterator();
- void isEmpty();
- void isFull();
- void isLinearised();
- void last();
- void lastIndexOf();
- void linearise();
- void prepend();
- void sharable();
-
- void removeStaticLinearised();
- void removeStaticNonLinearised();
- void removeMovableLinearised();
- void removeMovableNonLinearisedUpper();
- void removeMovableNonLinearisedLower();
-
- void replace();
- void resize();
-
- void setCapacityStatic();
- void setCapacityMovable();
-
- void size();
- void sizeAvailable();
- void startsWith();
- void toList();
- void toVector();
- void value();
-
- void operatorEquality();
- void operatorInequality();
- void operatorPlus();
- void operatorPlusEquals();
- void operatorStream();
-
- void const_iterator();
- void iterator();
-
- void testAppendFifo();
-};
-
-class MyComplexType
-{
-public:
- MyComplexType(int xx = 0)
- : x(xx),
- magicCheck(ms_magic)
- {
- ++ms_activeCount;
- }
-
- MyComplexType(const MyComplexType &other)
- : x(other.x),
- magicCheck(other.magicCheck)
- {
- ++ms_activeCount;
- }
-
- ~MyComplexType()
- {
- // Check that the constructor was actually called
- QVERIFY(ms_magic == magicCheck);
- --ms_activeCount;
- }
-
- MyComplexType &operator=(const MyComplexType &other)
- {
- if (this == &other)
- return *this;
- x = other.x;
- magicCheck = other.magicCheck;
- return *this;
- }
-
- int x;
- int magicCheck;
-
- static const int ms_magic = 0xfefefefe;
- static int ms_activeCount;
-};
-
-int MyComplexType::ms_activeCount = 0;
-
-void tst_QCircularBuffer::construction()
-{
- // Create an empty circular buffer
- QCircularBuffer<int> circ1;
- QVERIFY(circ1.capacity() == 0);
- QVERIFY(circ1.size() == 0);
-
- // Create a circular buffer with capacity for 10 items
- QCircularBuffer<int> circ2(10);
- QVERIFY(circ2.capacity() == 10);
-
- // Create a circular buffer with capacity for 3 items, all of which
- // are initialised to a specific value
- QCircularBuffer<int> circ3(3, 69);
- QVERIFY(circ3.capacity() == 3);
- QVERIFY(circ3.size() == 3);
- QVERIFY(circ3.at(0) == 69);
- QVERIFY(circ3.at(1) == 69);
- QVERIFY(circ3.at(2) == 69);
-
- // Create a circular buffer with capacity for 5 items. Pre-populate the
- // first 2 items to a known value.
- QCircularBuffer<int> circ4(5, 2, 10);
- QVERIFY(circ4.capacity() == 5);
- QVERIFY(circ4.size() == 2);
- QVERIFY(circ4.at(0) == 10);
- QVERIFY(circ4.at(1) == 10);
- QVERIFY(circ4.refCount().loadRelaxed() == 1);
-
- // Copy construct from circ4. Both circ4 and circ5 should now have a
- // refCount() of 2 since we are using implicit sharing.
- QCircularBuffer<int> circ5(circ4);
- QVERIFY(circ4.refCount().loadRelaxed() == 2);
- QVERIFY(circ5.refCount().loadRelaxed() == 2);
- QVERIFY(circ5.capacity() == 5);
- QVERIFY(circ5.size() == 2);
- QVERIFY(circ5.at(0) == 10);
- QVERIFY(circ5.at(1) == 10);
-}
-
-void tst_QCircularBuffer::destruction()
-{
- // Make sure that we only call the dtor for items that
- // have actually been constructed. There was a bug where we
- // were accidentally calling the dtor for all items in the
- // memory block (d->capacity items) rather than constructed
- // items (d->size items). The complex dtor of QVector showed
- // this up nicely with a crash. So now we test for this, but
- // in a non-crashy manner.
-
- // Reset the count of active (constructed items)
- MyComplexType::ms_activeCount = 0;
-
- // Populate a circular buffer and remove an item. The check
- // in the dtor makes sure that the item was constructed
- QCircularBuffer<MyComplexType> *cir = new QCircularBuffer<MyComplexType>(8);
- cir->append(MyComplexType(1));
- cir->append(MyComplexType(2));
- cir->append(MyComplexType(3));
- cir->remove(0);
- Q_UNUSED(cir)
-
- // Check that the dtor was called 2 times fewer than the constructor.
- // At this stage will still have 2 items in the circular buffer.
- QVERIFY(MyComplexType::ms_activeCount == 2);
-
- // Destroy the circular buffer and check that the active count
- // is 0. (Same number of calls to dtor as have been made to the constructors)
- delete cir;
- cir = nullptr;
- QVERIFY(MyComplexType::ms_activeCount == 0);
-}
-
-void tst_QCircularBuffer::append()
-{
- // Create a circular buffer with capacity for 3 items
- QCircularBuffer<int> circ(3);
-
- // Append some items
- circ.append(1);
- circ.append(2);
- circ.append(3);
-
- // The buffer should now contain the items 1, 2, 3 and be full
- QVERIFY(circ.at(0) == 1);
- QVERIFY(circ.at(1) == 2);
- QVERIFY(circ.at(2) == 3);
- QVERIFY(circ.isFull() == true);
-
- // Although the buffer is full we can still append items to it.
- // The earliest items will be overwritten
- circ.append(4);
- circ.append(5);
-
- // The buffer should now contain the items 3, 4, 5 and still be full
- QVERIFY(circ.at(0) == 3);
- QVERIFY(circ.at(1) == 4);
- QVERIFY(circ.at(2) == 5);
- QVERIFY(circ.isFull() == true);
-
- // Try appending beyond when the buffer becomes non-linearised
- QCircularBuffer<int> circ2(10);
- for (int i = 0; i < 15; ++i)
- circ2.append(i + 1);
- for (int i = 0; i < circ2.size(); ++i)
- QVERIFY(circ2.at(i) == 6 + i);
-}
-
-void tst_QCircularBuffer::at()
-{
- QCircularBuffer<int> circ(3, 10);
- QVERIFY(circ.at(0) == 10);
- QVERIFY(circ.at(1) == 10);
- QVERIFY(circ.at(2) == 10);
-
- circ.append(20);
- QVERIFY(circ.at(2) == 20);
-}
-
-void tst_QCircularBuffer::capacity()
-{
- QCircularBuffer<int> circ(10);
- QVERIFY(circ.capacity() == 10);
-}
-
-void tst_QCircularBuffer::clear()
-{
- QCircularBuffer<int> circ(3, 10);
- QVERIFY(circ.size() == 3);
- QVERIFY(circ.capacity() == 3);
-
- circ.clear();
- QVERIFY(circ.size() == 0);
- QVERIFY(circ.capacity() == 3);
- QVERIFY(circ.refCount().loadRelaxed() == 1);
-}
-
-void tst_QCircularBuffer::contains()
-{
- // Try simple test with a linearised buffer
- QCircularBuffer<int> circ(5);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(4);
- QVERIFY(circ.isLinearised() == true);
- QVERIFY(circ.contains(2) == true);
- QVERIFY(circ.contains(5) == false);
-
- // Now append some more items to make the buffer non-linearised and
- // test again.
- circ.append(5);
- circ.append(6);
- circ.append(7);
- QVERIFY(circ.isLinearised() == false);
- QVERIFY(circ.contains(6) == true);
- QVERIFY(circ.contains(7) == true);
- QVERIFY(circ.contains(8) == false);
-}
-
-void tst_QCircularBuffer::count()
-{
- // Test both versions of count() with a linearised buffer
- QCircularBuffer<int> circ(5);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(4);
- circ.append(4);
-
- QVERIFY(circ.isLinearised() == true);
- QVERIFY(circ.count() == 5);
- QVERIFY(circ.count(4) == 2);
-
- // Now with an non-linearised buffer
- circ.append(4);
- circ.append(4);
- QVERIFY(circ.isLinearised() == false);
- QVERIFY(circ.count() == 5);
- QVERIFY(circ.count(4) == 4);
-}
-
-void tst_QCircularBuffer::data()
-{
- //
- // data() and constData() tests
- //
-
- // Test with a simple linearised buffer first
- QCircularBuffer<int> circ(5);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(4);
- circ.append(5);
-
- QCircularBuffer<int>::array_range range = circ.data();
- int *p = range.first;
- QVERIFY(range.second == 5);
- for (int i = 0; i < range.second; ++i)
- QVERIFY(p[ i ] == i + 1);
-
- // Now with an non-linearised one. Note that the non-const version will
- // linearise the buffer.
- circ.append(6);
- circ.append(7);
- QVERIFY(circ.isLinearised() == false);
- range = circ.data();
- p = range.first;
- QVERIFY(range.second == 5);
- for (int i = 0; i < range.second; ++i)
- QVERIFY(p[ i ] == i + 3);
- QVERIFY(circ.isLinearised() == true);
-
- // Let's repeat the exercise with the const version of the data function
- QCircularBuffer<int> circ2(5);
- circ2.append(1);
- circ2.append(2);
- circ2.append(3);
- circ2.append(4);
- circ2.append(5);
-
- QCircularBuffer<int>::const_array_range range2 = const_cast<const QCircularBuffer<int> *>(&circ2)->data();
- const int *p2 = range2.first;
- for (int i = 0; i < range2.second; ++i)
- QVERIFY(p2[ i ] == i + 1);
-
- // We should get a null pointer for a non-linearised buffer
- circ2.append(6);
- circ2.append(7);
- QVERIFY(circ2.isLinearised() == false);
- range2 = const_cast<const QCircularBuffer<int> *>(&circ2)->data();
- QVERIFY(range2.first == 0);
- QVERIFY(range2.second == 0);
-
- // Let's repeat the exercise with the constData function
- QCircularBuffer<int> circ3(5);
- circ3.append(1);
- circ3.append(2);
- circ3.append(3);
- circ3.append(4);
- circ3.append(5);
-
- QCircularBuffer<int>::const_array_range range3 = circ3.constData();
- const int *p3 = range3.first;
- for (int i = 0; i < range3.second; ++i)
- QVERIFY(p3[ i ] == i + 1);
-
- // We should get a null pointer for a non-linearised buffer
- circ3.append(6);
- circ3.append(7);
- QVERIFY(circ3.isLinearised() == false);
- range3 = circ3.constData();
- QVERIFY(range3.first == 0);
- QVERIFY(range3.second == 0);
-}
-
-void tst_QCircularBuffer::dataOneTwo()
-{
- // Start off with a linearised buffer
- QCircularBuffer<int> circ(5);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(4);
- circ.append(5);
-
- QCircularBuffer<int>::array_range range = circ.dataOne();
- int *p = range.first;
- QVERIFY(range.second == 5);
- for (int i = 0; i < range.second; ++i)
- QVERIFY(p[ i ] == i + 1);
-
- // Test the const version too
- QCircularBuffer<int>::const_array_range constRange = const_cast< const QCircularBuffer<int> *>(&circ)->dataOne();
- const int *constp = constRange.first;
- QVERIFY(constRange.second == 5);
- for (int i = 0; i < constRange.second; ++i)
- QVERIFY(constp[ i ] == i + 1);
-
- // And the constDataOne() function
- constRange = circ.constDataOne();
- constp = constRange.first;
- QVERIFY(constRange.second == 5);
- for (int i = 0; i < constRange.second; ++i)
- QVERIFY(constp[ i ] == i + 1);
-
- // dataTwo should return a null array when the buffer is linearised
- QCircularBuffer<int>::array_range rangeb = circ.dataTwo();
- QVERIFY(rangeb.first == 0);
- QVERIFY(rangeb.second == 0);
-
- // Test the const version too
- QCircularBuffer<int>::const_array_range constRangeb = const_cast< const QCircularBuffer<int> *>(&circ)->dataTwo();
- QVERIFY(constRangeb.first == 0);
- QVERIFY(constRangeb.second == 0);
-
- // And the constDataTwo() function
- constRangeb = circ.constDataTwo();
- QVERIFY(constRangeb.first == 0);
- QVERIFY(constRangeb.second == 0);
-
- // Now make the buffer non-linearised by adding more items
- circ.append(6);
- circ.append(7);
- QVERIFY(circ.isLinearised() == false);
-
- // dataOne() should return the first contiguous part of the array
- range = circ.dataOne();
- p = range.first;
- QVERIFY(range.second == 3);
- for (int i = 0; i < range.second; ++i)
- QVERIFY(p[ i ] == i + 3);
- QVERIFY(circ.isLinearised() == false);
-
- // Test the const version too
- constRange = const_cast< const QCircularBuffer<int> *>(&circ)->dataOne();
- constp = constRange.first;
- QVERIFY(constRange.second == 3);
- for (int i = 0; i < constRange.second; ++i)
- QVERIFY(constp[ i ] == i + 3);
- QVERIFY(circ.isLinearised() == false);
-
- // And the constDataOne() function
- constRange = circ.constDataOne();
- constp = constRange.first;
- QVERIFY(constRange.second == 3);
- for (int i = 0; i < constRange.second; ++i)
- QVERIFY(constp[ i ] == i + 3);
- QVERIFY(circ.isLinearised() == false);
-
- // dataTwo should return the second contiguous part of the array
- rangeb = circ.dataTwo();
- QVERIFY(rangeb.second == 2);
- int *pb = rangeb.first;
- for (int i = 0; i < rangeb.second; ++i)
- QVERIFY(pb[ i ] == i + 6);
- QVERIFY(circ.isLinearised() == false);
-
- // Test the const version too
- constRangeb = const_cast< const QCircularBuffer<int> *>(&circ)->dataTwo();
- QVERIFY(constRangeb.second == 2);
- const int *constpb = constRangeb.first;
- for (int i = 0; i < constRangeb.second; ++i)
- QVERIFY(constpb[ i ] == i + 6);
- QVERIFY(circ.isLinearised() == false);
-
- // And finally, the constDataTwo() function.
- constRangeb = circ.constDataTwo();
- QVERIFY(constRangeb.second == 2);
- constpb = constRangeb.first;
- for (int i = 0; i < constRangeb.second; ++i)
- QVERIFY(constpb[ i ] == i + 6);
- QVERIFY(circ.isLinearised() == false);
-}
-
-void tst_QCircularBuffer::endsWith()
-{
- // Test with a linearised buffer
- QCircularBuffer<int> circ(5);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(4);
- circ.append(5);
- QVERIFY(circ.endsWith(5) == true);
- QVERIFY(circ.endsWith(3) == false);
-
- // Now with a non-linearised buffer
- circ.append(6);
- circ.append(7);
- QVERIFY(circ.endsWith(7) == true);
- QVERIFY(circ.endsWith(3) == false);
-
- // Now with an empty buffer
- QCircularBuffer<int> circ2(1);
- QVERIFY(!circ2.endsWith(1));
- circ2.append(1);
- QVERIFY(circ2.endsWith(1));
- circ2.erase(circ2.begin());
- QVERIFY(!circ2.endsWith(1));
-}
-
-void tst_QCircularBuffer::erase()
-{
- QCircularBuffer<int> circ(10);
- for (int i = 0; i < circ.capacity(); ++i)
- circ.append(i + 1);
-
- QCircularBuffer<int>::iterator pos = circ.begin() + 2;
- QCircularBuffer<int>::iterator it = circ.erase(pos);
-
- QVERIFY(circ.size() == circ.capacity() - 1);
- for (int i = 0; i < circ.size(); ++i) {
- if (i < 2)
- QVERIFY(circ.at(i) == i + 1);
- else
- QVERIFY(circ.at(i) == i + 2);
- }
-
- QVERIFY(*it == 4);
-
- QCircularBuffer<int>::iterator start = circ.begin() + 2;
- QCircularBuffer<int>::iterator end = circ.end();
- it = circ.erase(start, end);
- QVERIFY(circ.size() == 2);
- QVERIFY(circ.at(0) == 1);
- QVERIFY(circ.at(1) == 2);
- QVERIFY(it == circ.end());
-}
-
-void tst_QCircularBuffer::fill()
-{
- QCircularBuffer<int> circ(5, 0);
- circ.fill(2);
- QVERIFY(circ.capacity() == 5);
- QVERIFY(circ.size() == 5);
- for (int i = 0; i < 5; ++i)
- QVERIFY(circ.at(i) == 2);
-
- // Fill the first 3 entries with value 7
- circ.fill(7, 3);
- QVERIFY(circ.capacity() == 5);
- QVERIFY(circ.size() == 3);
- for (int i = 0; i < 3; ++i)
- QVERIFY(circ.at(i) == 7);
-
- // We abuse the data pointer to check that values beyond the valid array
- // have been reset when we resized down.
- QCircularBuffer<int>::array_range range = circ.data();
- QVERIFY(range.second == 3);
- QVERIFY(range.first[ 3 ] == 0);
- QVERIFY(range.first[ 4 ] == 0);
-}
-
-void tst_QCircularBuffer::first()
-{
- QCircularBuffer<int> circ(3);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- QVERIFY(circ.at(0) == 1);
- QVERIFY(circ.first() == 1);
-
- circ.append(4);
- circ.append(5);
- QVERIFY(circ.first() == 3);
-}
-
-void tst_QCircularBuffer::fromList()
-{
- QList<int> list = (QList<int>() << 1 << 2 << 3 << 4 << 5);
- QCircularBuffer<int> circ = QCircularBuffer<int>::fromList(list);
- QVERIFY(circ.capacity() == list.size());
- QVERIFY(circ.size() == list.size());
- QVERIFY(circ.isLinearised() == true);
- for (int i = 0; i < circ.size(); ++i)
- QVERIFY(circ.at(i) == list.at(i));
-}
-
-void tst_QCircularBuffer::fromVector()
-{
- QVector<int> vector = (QVector<int>() << 1 << 2 << 3 << 4 << 5);
- QCircularBuffer<int> circ = QCircularBuffer<int>::fromVector(vector);
- QVERIFY(circ.capacity() == vector.size());
- QVERIFY(circ.size() == vector.size());
- QVERIFY(circ.isLinearised() == true);
- for (int i = 0; i < circ.size(); ++i)
- QVERIFY(circ.at(i) == vector.at(i));
-}
-
-void tst_QCircularBuffer::indexOf()
-{
- QCircularBuffer<int> circ(5);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(2);
- circ.append(5);
-
- QVERIFY(circ.indexOf(3) == 2);
- QVERIFY(circ.indexOf(2) == 1);
- QVERIFY(circ.indexOf(2, 2) == 3);
-
- circ.append(6);
- circ.append(6);
- QVERIFY(circ.indexOf(2) == 1);
- QVERIFY(circ.indexOf(6) == 3);
- QVERIFY(circ.indexOf(6, 4) == 4);
-}
-
-void tst_QCircularBuffer::insert()
-{
- // Try a simple insert in the upper part of the buffer
- QCircularBuffer<MyComplexType> circ(8);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(4);
- circ.append(5);
- circ.append(6);
-
- QVERIFY(circ.capacity() == 8);
- QVERIFY(circ.size() == 6);
-
- circ.insert(4, 1, 0);
- QVERIFY(circ.capacity() == 8);
- QVERIFY(circ.size() == 7);
- QVERIFY(circ.at(0).x == 1);
- QVERIFY(circ.at(1).x == 2);
- QVERIFY(circ.at(2).x == 3);
- QVERIFY(circ.at(3).x == 4);
- QVERIFY(circ.at(4).x == 0);
- QVERIFY(circ.at(5).x == 5);
- QVERIFY(circ.at(6).x == 6);
-
- // Try a multiple insert in the upper part of the buffer
- QCircularBuffer<MyComplexType> circ2(8);
- circ2.append(1);
- circ2.append(2);
- circ2.append(3);
- circ2.append(4);
- circ2.append(5);
- circ2.append(6);
-
- QVERIFY(circ2.capacity() == 8);
- QVERIFY(circ2.size() == 6);
-
- circ2.insert(4, 7, 0);
- QVERIFY(circ2.capacity() == 8);
- QVERIFY(circ2.size() == 8);
- QVERIFY(circ2.at(0).x == 0);
- QVERIFY(circ2.at(1).x == 0);
- QVERIFY(circ2.at(2).x == 0);
- QVERIFY(circ2.at(3).x == 0);
- QVERIFY(circ2.at(4).x == 0);
- QVERIFY(circ2.at(5).x == 0);
- QVERIFY(circ2.at(6).x == 5);
- QVERIFY(circ2.at(7).x == 6);
-
- // Try a simple insert in the upper part of the buffer using a movable type.
- // This tests the case where the part of the buffer to be moved up does not
- // wrap around before or after the move.
- QCircularBuffer<int> circ3(8);
- circ3.append(1);
- circ3.append(2);
- circ3.append(3);
- circ3.append(4);
- circ3.append(5);
- circ3.append(6);
-
- circ3.insert(4, 1, 0);
- QVERIFY(circ3.capacity() == 8);
- QVERIFY(circ3.size() == 7);
- QVERIFY(circ3.at(0) == 1);
- QVERIFY(circ3.at(1) == 2);
- QVERIFY(circ3.at(2) == 3);
- QVERIFY(circ3.at(3) == 4);
- QVERIFY(circ3.at(4) == 0);
- QVERIFY(circ3.at(5) == 5);
- QVERIFY(circ3.at(6) == 6);
-
- // Do the same again but this time such that the destination buffer wraps around.
- QCircularBuffer<int> circ4(8);
- circ4.append(1);
- circ4.append(2);
- circ4.append(3);
- circ4.append(4);
- circ4.append(5);
- circ4.append(6);
-
- circ4.insert(4, 3, 0);
- QVERIFY(circ4.capacity() == 8);
- QVERIFY(circ4.size() == 8);
- QVERIFY(circ4.at(0) == 2);
- QVERIFY(circ4.at(1) == 3);
- QVERIFY(circ4.at(2) == 4);
- QVERIFY(circ4.at(3) == 0);
- QVERIFY(circ4.at(4) == 0);
- QVERIFY(circ4.at(5) == 0);
- QVERIFY(circ4.at(6) == 5);
- QVERIFY(circ4.at(7) == 6);
-
- // And now when the src buffer wraps
- QCircularBuffer<int> circ5(8);
- circ5.append(1);
- circ5.append(2);
- circ5.append(3);
- circ5.append(4);
- circ5.append(5);
- circ5.append(6);
- circ5.append(7);
- circ5.append(8);
- circ5.append(9);
- circ5.append(10);
-
- circ5.insert(4, 3, 0);
- QVERIFY(circ5.capacity() == 8);
- QVERIFY(circ5.size() == 8);
- QVERIFY(circ5.at(0) == 6);
- QVERIFY(circ5.at(1) == 0);
- QVERIFY(circ5.at(2) == 0);
- QVERIFY(circ5.at(3) == 0);
- QVERIFY(circ5.at(4) == 7);
- QVERIFY(circ5.at(5) == 8);
- QVERIFY(circ5.at(6) == 9);
- QVERIFY(circ5.at(7) == 10);
-
- // Finally when both src and dst buffers wrap
- QCircularBuffer<int> circ6(10);
- circ6.append(1);
- circ6.append(2);
- circ6.append(3);
- circ6.append(4);
- circ6.append(5);
- circ6.append(6);
- circ6.append(7);
- circ6.append(8);
- circ6.append(9);
- circ6.append(10);
- circ6.append(11);
- circ6.append(12);
-
- circ6.insert(5, 2, 0);
- QVERIFY(circ6.capacity() == 10);
- QVERIFY(circ6.size() == 10);
- QVERIFY(circ6.at(0) == 5);
- QVERIFY(circ6.at(1) == 6);
- QVERIFY(circ6.at(2) == 7);
- QVERIFY(circ6.at(3) == 0);
- QVERIFY(circ6.at(4) == 0);
- QVERIFY(circ6.at(5) == 8);
- QVERIFY(circ6.at(6) == 9);
- QVERIFY(circ6.at(7) == 10);
- QVERIFY(circ6.at(8) == 11);
- QVERIFY(circ6.at(9) == 12);
-
-
- // Try a simple insert in the lower part of the buffer
- QCircularBuffer<MyComplexType> circ7(8);
- circ7.append(1);
- circ7.append(2);
- circ7.append(3);
- circ7.append(4);
- circ7.append(5);
- circ7.append(6);
-
- QVERIFY(circ7.capacity() == 8);
- QVERIFY(circ7.size() == 6);
-
- circ7.insert(1, 1, 0);
- QVERIFY(circ7.capacity() == 8);
- QVERIFY(circ7.size() == 7);
- QVERIFY(circ7.at(0).x == 1);
- QVERIFY(circ7.at(1).x == 0);
- QVERIFY(circ7.at(2).x == 2);
- QVERIFY(circ7.at(3).x == 3);
- QVERIFY(circ7.at(4).x == 4);
- QVERIFY(circ7.at(5).x == 5);
- QVERIFY(circ7.at(6).x == 6);
-
- // Try a multiple insert in the lower part of the buffer
- QCircularBuffer<MyComplexType> circ8(8);
- circ8.append(1);
- circ8.append(2);
- circ8.append(3);
- circ8.append(4);
- circ8.append(5);
- circ8.append(6);
-
- QVERIFY(circ8.capacity() == 8);
- QVERIFY(circ8.size() == 6);
-
- circ8.insert(1, 4, 0);
- QVERIFY(circ8.capacity() == 8);
- QVERIFY(circ8.size() == 8);
- QVERIFY(circ8.at(0).x == 0);
- QVERIFY(circ8.at(1).x == 0);
- QVERIFY(circ8.at(2).x == 0);
- QVERIFY(circ8.at(3).x == 2);
- QVERIFY(circ8.at(4).x == 3);
- QVERIFY(circ8.at(5).x == 4);
- QVERIFY(circ8.at(6).x == 5);
- QVERIFY(circ8.at(7).x == 6);
-
- // Try a simple insert in the lower part of the buffer using a movable type.
- // This tests the case where the part of the buffer to be moved up does not
- // wrap around before or after the move.
- QCircularBuffer<int> circ9(10);
- circ9.append(1);
- circ9.append(2);
- circ9.append(3);
- circ9.append(4);
- circ9.append(5);
- circ9.append(6);
- circ9.append(7);
- circ9.append(8);
- circ9.append(9);
-
- circ9.insert(3, 2, 0);
- QVERIFY(circ9.capacity() == 10);
- QVERIFY(circ9.size() == 10);
- QVERIFY(circ9.at(0) == 2);
- QVERIFY(circ9.at(1) == 3);
- QVERIFY(circ9.at(2) == 0);
- QVERIFY(circ9.at(3) == 0);
- QVERIFY(circ9.at(4) == 4);
- QVERIFY(circ9.at(5) == 5);
- QVERIFY(circ9.at(6) == 6);
- QVERIFY(circ9.at(7) == 7);
- QVERIFY(circ9.at(8) == 8);
- QVERIFY(circ9.at(9) == 9);
-
- // And now when the src buffer wraps
- QCircularBuffer<int> circ10(10);
- circ10.append(3);
- circ10.append(4);
- circ10.append(5);
- circ10.append(6);
- circ10.append(7);
- circ10.append(8);
- circ10.append(9);
- circ10.append(10);
- circ10.prepend(2);
- circ10.prepend(1);
-
- // Verify that the input buffer is as expected
- QVERIFY(circ10.capacity() == 10);
- QVERIFY(circ10.size() == 10);
- QCircularBuffer<int>::const_array_range p2 = circ10.constDataTwo();
- QVERIFY(p2.second == 8);
- QVERIFY(p2.first[ 0 ] == 3);
- QVERIFY(p2.first[ 1 ] == 4);
- QVERIFY(p2.first[ 7 ] == 10);
- QCircularBuffer<int>::const_array_range p = circ10.constDataOne();
- QVERIFY(p.second == 2);
- QVERIFY(p.first[ 0 ] == 1);
- QVERIFY(p.first[ 1 ] == 2);
-
- circ10.insert(3, 1, 0);
- QVERIFY(circ10.capacity() == 10);
- QVERIFY(circ10.size() == 10);
- QVERIFY(circ10.at(0) == 2);
- QVERIFY(circ10.at(1) == 3);
- QVERIFY(circ10.at(2) == 0);
- QVERIFY(circ10.at(3) == 4);
- QVERIFY(circ10.at(4) == 5);
- QVERIFY(circ10.at(5) == 6);
- QVERIFY(circ10.at(6) == 7);
- QVERIFY(circ10.at(7) == 8);
- QVERIFY(circ10.at(8) == 9);
- QVERIFY(circ10.at(9) == 10);
-
- // Finally when both src and dst buffers wrap
- QCircularBuffer<int> circ11(13);
- circ11.append(4);
- circ11.append(5);
- circ11.append(6);
- circ11.append(7);
- circ11.append(8);
- circ11.append(9);
- circ11.append(10);
- circ11.append(11);
- circ11.append(12);
- circ11.append(13);
- circ11.prepend(3);
- circ11.prepend(2);
- circ11.prepend(1);
-
- // Verify that the input buffer is as expected
- QVERIFY(circ11.capacity() == 13);
- QVERIFY(circ11.size() == 13);
- p2 = circ11.constDataTwo();
- QVERIFY(p2.second == 10);
- QVERIFY(p2.first[ 0 ] == 4);
- QVERIFY(p2.first[ 1 ] == 5);
- QVERIFY(p2.first[ 9 ] == 13);
- p = circ11.constDataOne();
- QVERIFY(p.second == 3);
- QVERIFY(p.first[ 0 ] == 1);
- QVERIFY(p.first[ 1 ] == 2);
- QVERIFY(p.first[ 2 ] == 3);
-
- circ11.insert(5, 1, 0);
- QVERIFY(circ11.capacity() == 13);
- QVERIFY(circ11.size() == 13);
- QVERIFY(circ11.at(0) == 2);
- QVERIFY(circ11.at(1) == 3);
- QVERIFY(circ11.at(2) == 4);
- QVERIFY(circ11.at(3) == 5);
- QVERIFY(circ11.at(4) == 0);
- QVERIFY(circ11.at(5) == 6);
- QVERIFY(circ11.at(6) == 7);
- QVERIFY(circ11.at(7) == 8);
- QVERIFY(circ11.at(8) == 9);
- QVERIFY(circ11.at(9) == 10);
- QVERIFY(circ11.at(10) == 11);
- QVERIFY(circ11.at(11) == 12);
- QVERIFY(circ11.at(12) == 13);
-
- // Try inserting at the end of the buffer. Should work just like append()
- QCircularBuffer<int> circ12(10);
- for (int i = 0; i < 5; ++i)
- circ12.append(i + 1);
- for (int i = 5; i < 10; ++i)
- circ12.insert(circ12.size(), (i + 1) * 10);
- for (int i = 0; i < circ12.size(); ++i) {
- if (i < 5)
- QVERIFY(circ12.at(i) == i + 1);
- else
- QVERIFY(circ12.at(i) == (i + 1) * 10);
- }
-
- // Try inserting at the end of the buffer with non-movable type. Should work just like append()
- QCircularBuffer<MyComplexType> circ13(10);
- for (int i = 0; i < 5; ++i)
- circ13.append(i + 1);
- for (int i = 5; i < 10; ++i)
- circ13.insert(circ13.size(), (i + 1) * 10);
- for (int i = 0; i < circ13.size(); ++i) {
- if (i < 5)
- QVERIFY(circ13.at(i).x == i + 1);
- else
- QVERIFY(circ13.at(i).x == (i + 1) * 10);
- }
-
- // Insert multiple items at end of buffer
- QCircularBuffer<int> circ14(10);
- for (int i = 0; i < 5; ++i)
- circ14.append(i + 1);
- circ14.insert(circ14.size(), 7, 100);
- for (int i = 0; i < circ14.size(); ++i) {
- if (i < 3)
- QVERIFY(circ14.at(i) == i + 3);
- else
- QVERIFY(circ14.at(i) == 100);
- }
-
- // Insert multiple items at end of buffer of non-movable type
- QCircularBuffer<MyComplexType> circ15(10);
- for (int i = 0; i < 5; ++i)
- circ15.append(i + 1);
- circ15.insert(circ15.size(), 7, 100);
- for (int i = 0; i < circ15.size(); ++i) {
- if (i < 3)
- QVERIFY(circ15.at(i).x == i + 3);
- else
- QVERIFY(circ15.at(i).x == 100);
- }
-
- // Try inserting at the start of the buffer. Should work just like prepend()
- QCircularBuffer<int> circ16(10);
- for (int i = 0; i < 5; ++i)
- circ16.append(10);
- for (int i = 5; i < 10; ++i)
- circ16.insert(0, 20);
- for (int i = 0; i < circ16.size(); ++i) {
- if (i < 5)
- QVERIFY(circ16.at(i) == 20);
- else
- QVERIFY(circ16.at(i) == 10);
- }
-
- // Try inserting at the start of the buffer with non-movable type. Should work just like prepend()
- QCircularBuffer<MyComplexType> circ17(10);
- for (int i = 0; i < 5; ++i)
- circ17.append(10);
- for (int i = 5; i < 10; ++i)
- circ17.insert(0, 20);
- for (int i = 0; i < circ17.size(); ++i) {
- if (i < 5)
- QVERIFY(circ17.at(i).x == 20);
- else
- QVERIFY(circ17.at(i).x == 10);
- }
-
- // Try inserting multiple items at the start of the buffer. Should work just like prepend()
- QCircularBuffer<int> circ18(10);
- for (int i = 0; i < 5; ++i)
- circ18.append(10);
- circ18.insert(0, 5, 20);
- for (int i = 0; i < circ18.size(); ++i) {
- if (i < 5)
- QVERIFY(circ18.at(i) == 20);
- else
- QVERIFY(circ18.at(i) == 10);
- }
-
- // Try inserting multiple items at the start of the buffer. Should work just like prepend()
- QCircularBuffer<MyComplexType> circ19(10);
- for (int i = 0; i < 5; ++i)
- circ19.append(10);
- circ19.insert(0, 5, 20);
- for (int i = 0; i < circ19.size(); ++i) {
- if (i < 5)
- QVERIFY(circ19.at(i).x == 20);
- else
- QVERIFY(circ19.at(i).x == 10);
- }
-}
-
-void tst_QCircularBuffer::insertIterator()
-{
- // Test the overload of insert that take an iterator as opposed to an index
- QCircularBuffer<int> circ(10);
- for (int i = 0; i < 5; ++i)
- circ.append(i + 1);
-
- QCircularBuffer<int>::iterator it = circ.begin() + 2;
- QCircularBuffer<int>::iterator it2 = circ.insert(it, 3, 10);
- for (int i = 0; i < circ.size(); ++i) {
- if (i < 2)
- QVERIFY(circ.at(i) == i + 1);
- else if (i > 4)
- QVERIFY(circ.at(i) == i - 2);
- else
- QVERIFY(circ.at(i) == 10);
- }
-
- for (int i = 0; i < 3; ++i) {
- QVERIFY(*it2 == 10);
- ++it2;
- }
-}
-
-void tst_QCircularBuffer::isEmpty()
-{
- QCircularBuffer<int> circ(3);
- QVERIFY(circ.isEmpty() == true);
- circ.append(1);
- circ.append(2);
- QVERIFY(circ.isEmpty() == false);
- circ.clear();
- QVERIFY(circ.isEmpty() == true);
-}
-
-void tst_QCircularBuffer::isFull()
-{
- QCircularBuffer<int> circ(3);
- QVERIFY(circ.isFull() == false);
- circ.append(1);
- QVERIFY(circ.isFull() == false);
- circ.append(2);
- QVERIFY(circ.isFull() == false);
- circ.append(3);
- QVERIFY(circ.isFull() == true);
- circ.clear();
- QVERIFY(circ.isFull() == false);
-}
-
-void tst_QCircularBuffer::isLinearised()
-{
- QCircularBuffer<int> circ(3);
- QVERIFY(circ.isLinearised() == true);
- circ.append(1);
- QVERIFY(circ.isLinearised() == true);
- circ.append(2);
- QVERIFY(circ.isLinearised() == true);
- circ.append(3);
- QVERIFY(circ.isLinearised() == true);
- circ.append(4);
- QVERIFY(circ.isLinearised() == false);
- circ.clear();
- QVERIFY(circ.isLinearised() == true);
-}
-
-void tst_QCircularBuffer::last()
-{
- QCircularBuffer<int> circ(3);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- QVERIFY(circ.at(2) == 3);
- QVERIFY(circ.last() == 3);
-
- circ.append(4);
- circ.append(5);
- QVERIFY(circ.last() == 5);
-}
-
-void tst_QCircularBuffer::lastIndexOf()
-{
- QCircularBuffer<int> circ(5);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(2);
- circ.append(5);
-
- QVERIFY(circ.lastIndexOf(3) == 2);
- QVERIFY(circ.lastIndexOf(2) == 3);
- QVERIFY(circ.lastIndexOf(2, 2) == 1);
-
- circ.append(6);
- QVERIFY(circ.lastIndexOf(2) == 2);
- QVERIFY(circ.lastIndexOf(6) == 4);
- QVERIFY(circ.lastIndexOf(2, 1) == 0);
-}
-
-void tst_QCircularBuffer::linearise()
-{
- // Start with a linearised buffer
- QCircularBuffer<int> circ(5);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(4);
- circ.append(5);
- QVERIFY(circ.isLinearised() == true);
-
- // Add more items to make it non-linearised
- circ.append(6);
- circ.append(7);
- QVERIFY(circ.isLinearised() == false);
- QVERIFY(circ.at(0) == 3);
- QVERIFY(circ.at(1) == 4);
- QVERIFY(circ.at(2) == 5);
- QVERIFY(circ.at(3) == 6);
- QVERIFY(circ.at(4) == 7);
-
- // Now try to linearise it again
- circ.linearise();
- QVERIFY(circ.isLinearised() == true);
- QVERIFY(circ.at(0) == 3);
- QVERIFY(circ.at(1) == 4);
- QVERIFY(circ.at(2) == 5);
- QVERIFY(circ.at(3) == 6);
- QVERIFY(circ.at(4) == 7);
-}
-
-void tst_QCircularBuffer::prepend()
-{
- // Create a circular buffer with capacity for 3 items
- QCircularBuffer<int> circ(3);
-
- // Prepend some items
- circ.prepend(1);
- circ.prepend(2);
- circ.prepend(3);
-
- // The buffer should now contain the items 1, 2, 3 and be full
- QVERIFY(circ.at(0) == 3);
- QVERIFY(circ.at(1) == 2);
- QVERIFY(circ.at(2) == 1);
- QVERIFY(circ.isFull() == true);
-
- // Although the buffer is full we can still prepend items to it.
- // The latest items will be overwritten
- circ.prepend(4);
- circ.prepend(5);
-
- // The buffer should now contain the items 3, 4, 5 and still be full
- QVERIFY(circ.at(0) == 5);
- QVERIFY(circ.at(1) == 4);
- QVERIFY(circ.at(2) == 3);
- QVERIFY(circ.isFull() == true);
-}
-
-void tst_QCircularBuffer::sharable()
-{
- QCircularBuffer<int> circ(3);
-
- circ.push_back(1);
- circ.push_back(2);
- circ.push_back(3);
-
- {
- // take a reference to internal data and remember the current value:
- int &oldValueRef = circ.first();
- const int oldValue = oldValueRef;
-
- // make a copy of the container:
- const QCircularBuffer<int> c2 = circ;
-
- // modify copied-from container:
- oldValueRef = -1;
-
- // check that the copied-to container didn't change
- QEXPECT_FAIL("", "QCircularBuffer doesn't implement non-sharable state", Continue);
- QCOMPARE(c2.first(), oldValue);
- }
-}
-
-void tst_QCircularBuffer::removeStaticLinearised()
-{
- // Try some simple removes on a linearised buffer with a non-movable type
- QCircularBuffer<MyComplexType> circ(6);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(4);
- circ.append(5);
- circ.append(6);
-
- QVERIFY(circ.capacity() == 6);
- QVERIFY(circ.size() == 6);
-
- circ.remove(4, 2);
- QVERIFY(circ.capacity() == 6);
- QVERIFY(circ.size() == 4);
- QVERIFY(circ.at(0).x == 1);
- QVERIFY(circ.at(1).x == 2);
- QVERIFY(circ.at(2).x == 3);
- QVERIFY(circ.at(3).x == 4);
-
- // Restore the original
- circ.append(5);
- circ.append(6);
-
- // Now try removing in the upper part of the buffer but not all the
- // way to the end of it
- circ.remove(3, 1);
- QVERIFY(circ.capacity() == 6);
- QVERIFY(circ.size() == 5);
- QVERIFY(circ.at(0).x == 1);
- QVERIFY(circ.at(1).x == 2);
- QVERIFY(circ.at(2).x == 3);
- QVERIFY(circ.at(3).x == 5);
- QVERIFY(circ.at(4).x == 6);
-
- // Restore the original
- circ.clear();
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(4);
- circ.append(5);
- circ.append(6);
-
- // Now try to remove some points from the lower half
- circ.remove(1, 2);
- QVERIFY(circ.capacity() == 6);
- QVERIFY(circ.size() == 4);
- QVERIFY(circ.at(0).x == 1);
- QVERIFY(circ.at(1).x == 4);
- QVERIFY(circ.at(2).x == 5);
- QVERIFY(circ.at(3).x == 6);
-
- // Now try repeatedly removing the first item of a partially full buffer
- QCircularBuffer<MyComplexType> circ2(20);
- for (int i = 0; i < 15; ++i)
- circ2.append(i);
-
- QVERIFY(circ2.size() == 15);
- for (int i = 0; i < 15; ++i)
- QVERIFY(circ2.at(i).x == i);
-
- for (int i = 0; i < 10; ++i) {
- MyComplexType value = circ2.first();
- QVERIFY(value.x == i);
- circ2.remove(0);
- }
-}
-
-void tst_QCircularBuffer::removeStaticNonLinearised()
-{
- // Try the same type of tests with a non-linearised buffer.
-
- // First remove from upper part of the buffer
- QCircularBuffer<MyComplexType> circ(10);
- for (int i = 0; i < 15; ++i)
- circ.append(i + 1);
-
- QVERIFY(circ.capacity() == 10);
- QVERIFY(circ.size() == 10);
- QVERIFY(circ.isLinearised() == false);
- circ.remove(8, 2);
- QVERIFY(circ.capacity() == 10);
- QVERIFY(circ.size() == 8);
- QVERIFY(circ.at(0).x == 6);
- QVERIFY(circ.at(1).x == 7);
- QVERIFY(circ.at(2).x == 8);
- QVERIFY(circ.at(3).x == 9);
- QVERIFY(circ.at(4).x == 10);
- QVERIFY(circ.at(5).x == 11);
- QVERIFY(circ.at(6).x == 12);
- QVERIFY(circ.at(7).x == 13);
-
- // Restore the original
- circ.append(14);
- circ.append(15);
-
- // Remove some points from the lower half
- circ.remove(1, 4);
- QVERIFY(circ.capacity() == 10);
- QVERIFY(circ.size() == 6);
- QVERIFY(circ.at(0).x == 6);
- QVERIFY(circ.at(1).x == 11);
- QVERIFY(circ.at(2).x == 12);
- QVERIFY(circ.at(3).x == 13);
- QVERIFY(circ.at(4).x == 14);
- QVERIFY(circ.at(5).x == 15);
-
- // Remove all the way to the end
- QCircularBuffer<MyComplexType> circ2(6);
- for (int i = 0; i < 8; ++i)
- circ2.append(i + 1);
- circ2.remove(2, 4);
- QVERIFY(circ2.capacity() == 6);
- QVERIFY(circ2.size() == 2);
- QVERIFY(circ2.at(0).x == 3);
- QVERIFY(circ2.at(1).x == 4);
-
- // Try another couple of cases to be thorough
- QCircularBuffer<MyComplexType> circ3(6);
- for (int i = 0; i < 8; ++i)
- circ3.append(i + 1);
- circ3.remove(3, 2);
- QVERIFY(circ3.capacity() == 6);
- QVERIFY(circ3.size() == 4);
- QVERIFY(circ3.at(0).x == 3);
- QVERIFY(circ3.at(1).x == 4);
- QVERIFY(circ3.at(2).x == 5);
- QVERIFY(circ3.at(3).x == 8);
-
- QCircularBuffer<MyComplexType> circ4(6);
- for (int i = 0; i < 8; ++i)
- circ4.append(i + 1);
- circ4.remove(1, 2);
- QVERIFY(circ4.capacity() == 6);
- QVERIFY(circ4.size() == 4);
- QVERIFY(circ4.at(0).x == 3);
- QVERIFY(circ4.at(1).x == 6);
- QVERIFY(circ4.at(2).x == 7);
- QVERIFY(circ4.at(3).x == 8);
-}
-
-void tst_QCircularBuffer::removeMovableLinearised()
-{
- // Try to do some removes on linearised buffers of a non-movable type
-
- // Remove from the lower half of the buffer
- QCircularBuffer<int> circ(6);
- for (int i = 0; i < 6; ++i)
- circ.append(i + 1);
- circ.remove(1, 2);
- QVERIFY(circ.capacity() == 6);
- QVERIFY(circ.size() == 4);
- QVERIFY(circ.at(0) == 1);
- QVERIFY(circ.at(1) == 4);
- QVERIFY(circ.at(2) == 5);
- QVERIFY(circ.at(3) == 6);
-
- // Remove form the upper half of the buffer
- QCircularBuffer<int> circ2(6);
- for (int i = 0; i < 6; ++i)
- circ2.append(i + 1);
- circ2.remove(3, 2);
- QVERIFY(circ2.capacity() == 6);
- QVERIFY(circ2.size() == 4);
- QVERIFY(circ2.at(0) == 1);
- QVERIFY(circ2.at(1) == 2);
- QVERIFY(circ2.at(2) == 3);
- QVERIFY(circ2.at(3) == 6);
-}
-
-void tst_QCircularBuffer::removeMovableNonLinearisedUpper()
-{
- // Src region wraps and the dst region does not wrap
- QCircularBuffer<int> circ(20);
- for (int i = 0; i < 23; ++i)
- circ.append(i + 1);
- circ.remove(11, 5);
- QVERIFY(circ.size() == 15);
- for (int i = 0; i < 11; ++i)
- QVERIFY(circ.at(i) == i + 4);
- QVERIFY(circ.at(11) == 20);
- QVERIFY(circ.at(12) == 21);
- QVERIFY(circ.at(13) == 22);
- QVERIFY(circ.at(14) == 23);
-
- // Src region does not wrap and the dst region wraps
- QCircularBuffer<int> circ2(10);
- for (int i = 1; i <= 13; i++)
- circ2.append(i);
- circ2.remove(5, 2);
- QVERIFY(circ2.capacity() == 10);
- QVERIFY(circ2.size() == 8);
- QVERIFY(circ2.at(0) == 4);
- QVERIFY(circ2.at(1) == 5);
- QVERIFY(circ2.at(2) == 6);
- QVERIFY(circ2.at(3) == 7);
- QVERIFY(circ2.at(4) == 8);
- QVERIFY(circ2.at(5) == 11);
- QVERIFY(circ2.at(6) == 12);
- QVERIFY(circ2.at(7) == 13);
-
- // Src and dst regions wrap
- QCircularBuffer<int> circ3(10);
- for (int i = 1; i <= 13; i++)
- circ3.append(i);
- circ3.remove(5, 1);
- QVERIFY(circ3.capacity() == 10);
- QVERIFY(circ3.size() == 9);
- QVERIFY(circ3.at(0) == 4);
- QVERIFY(circ3.at(1) == 5);
- QVERIFY(circ3.at(2) == 6);
- QVERIFY(circ3.at(3) == 7);
- QVERIFY(circ3.at(4) == 8);
- QVERIFY(circ3.at(5) == 10);
- QVERIFY(circ3.at(6) == 11);
- QVERIFY(circ3.at(7) == 12);
- QVERIFY(circ3.at(8) == 13);
-
- // Neither the src nor dst regions wrap
- QCircularBuffer<int> circ4(20);
- for (int i = 0; i < 26; ++i)
- circ4.append(i + 1);
- circ4.remove(15, 3);
- QVERIFY(circ4.size() == 17);
- for (int i = 0; i < 15; ++i)
- QVERIFY(circ4.at(i) == i + 7);
- QVERIFY(circ4.at(15) == 25);
- QVERIFY(circ4.at(16) == 26);
-}
-
-void tst_QCircularBuffer::removeMovableNonLinearisedLower()
-{
- // Src region wraps and the dst region does not wrap.
- // This case also tests zeroing the free'd region when it is disjoint.
- QCircularBuffer<int> circ(20);
- for (int i = 0; i < 36; ++i)
- circ.append(i + 1);
- circ.remove(6, 7);
- QVERIFY(circ.size() == 13);
- for (int i = 0; i < 6; ++i)
- QVERIFY(circ.at(i) == i + 17);
- for (int i = 6; i < circ.size(); ++i)
- QVERIFY(circ.at(i) == i + 24);
-
- // Src region does not wrap and the dst region wraps
- // This case also tests zeroing the free'd region when it is contiguous.
- QCircularBuffer<int> circ2(20);
- for (int i = 0; i < 36; ++i)
- circ2.append(i + 1);
- circ2.remove(4, 3);
- QVERIFY(circ2.size() == 17);
- for (int i = 0; i < 4; ++i)
- QVERIFY(circ2.at(i) == i + 17);
- for (int i = 4; i < circ2.size(); ++i)
- QVERIFY(circ2.at(i) == i + 20);
-
- // Src and dst regions wrap
- QCircularBuffer<int> circ3(20);
- for (int i = 0; i < 36; ++i)
- circ3.append(i + 1);
- circ3.remove(6, 3);
- QVERIFY(circ3.size() == 17);
- for (int i = 0; i < 6; ++i)
- QVERIFY(circ3.at(i) == i + 17);
- for (int i = 6; i < circ3.size(); ++i)
- QVERIFY(circ3.at(i) == i + 20);
-
- // Neither the src nor dst regions wrap
- QCircularBuffer<int> circ4(20);
- for (int i = 0; i < 36; ++i)
- circ4.append(i + 1);
- circ4.remove(2, 1);
- QVERIFY(circ4.size() == 19);
- for (int i = 0; i < 2; ++i)
- QVERIFY(circ4.at(i) == i + 17);
- for (int i = 2; i < circ4.size(); ++i)
- QVERIFY(circ4.at(i) == i + 18);
-}
-
-void tst_QCircularBuffer::replace()
-{
- QCircularBuffer<int> circ(5, 7);
- for (int i = 0; i < 5; ++i)
- QVERIFY(circ.at(i) == 7);
-
- circ.replace(2, 100);
- for (int i = 0; i < 5; ++i) {
- if (i != 2)
- QVERIFY(circ.at(i) == 7);
- else
- QVERIFY(circ.at(2) == 100);
- }
-}
-
-void tst_QCircularBuffer::resize()
-{
- QCircularBuffer<int> circ(10);
- for (int i = 0; i < circ.capacity(); ++i)
- circ.append(i + 1);
- QVERIFY(circ.capacity() == 10);
- QVERIFY(circ.size() == 10);
-
- circ.resize(6);
- QVERIFY(circ.capacity() == 10);
- QVERIFY(circ.size() == 6);
- for (int i = 0; i < circ.size(); ++i)
- QVERIFY(circ.at(i) == i + 1);
-
- circ.resize(9);
- QVERIFY(circ.capacity() == 10);
- QVERIFY(circ.size() == 9);
- for (int i = 0; i < circ.size(); ++i) {
- if (i < 6)
- QVERIFY(circ.at(i) == i + 1);
- else
- QVERIFY(circ.at(i) == 0);
- }
-}
-
-void tst_QCircularBuffer::setCapacityStatic()
-{
- // New capacity < old capacity & src region wraps
- QCircularBuffer<MyComplexType> circ(20);
- for (int i = 0; i < 36; ++i)
- circ.append(i + 1);
- circ.setCapacity(10);
- QVERIFY(circ.capacity() == 10);
- QVERIFY(circ.size() == 10);
- for (int i = 0; i < circ.size(); ++i)
- QVERIFY(circ.at(i).x == i + 17);
-
- // New capacity < old capacity & src region does not wrap
- QCircularBuffer<MyComplexType> circ2(20);
- for (int i = 0; i < 36; ++i)
- circ2.append(i + 1);
- circ2.setCapacity(3);
- QVERIFY(circ2.capacity() == 3);
- QVERIFY(circ2.size() == 3);
- for (int i = 0; i < circ2.size(); ++i)
- QVERIFY(circ2.at(i).x == i + 17);
-
- // New capacity > old capacity
- QCircularBuffer<MyComplexType> circ3(20);
- for (int i = 0; i < 36; ++i)
- circ3.append(i + 1);
- circ3.setCapacity(25);
- QVERIFY(circ3.capacity() == 25);
- QVERIFY(circ3.size() == 20);
- for (int i = 0; i < circ3.size(); ++i)
- QVERIFY(circ3.at(i).x == i + 17);
-}
-
-void tst_QCircularBuffer::setCapacityMovable()
-{
- // New capacity < old capacity & src region wraps
- QCircularBuffer<int> circ(20);
- for (int i = 0; i < 36; ++i)
- circ.append(i + 1);
- circ.setCapacity(10);
- QVERIFY(circ.capacity() == 10);
- QVERIFY(circ.size() == 10);
- for (int i = 0; i < circ.size(); ++i)
- QVERIFY(circ.at(i) == i + 17);
-
- // New capacity < old capacity & src region does not wrap
- QCircularBuffer<int> circ2(20);
- for (int i = 0; i < 36; ++i)
- circ2.append(i + 1);
- circ2.setCapacity(3);
- QVERIFY(circ2.capacity() == 3);
- QVERIFY(circ2.size() == 3);
- for (int i = 0; i < circ2.size(); ++i)
- QVERIFY(circ2.at(i) == i + 17);
-
- // New capacity > old capacity
- QCircularBuffer<int> circ3(20);
- for (int i = 0; i < 36; ++i)
- circ3.append(i + 1);
- circ3.setCapacity(25);
- QVERIFY(circ3.capacity() == 25);
- QVERIFY(circ3.size() == 20);
- for (int i = 0; i < circ3.size(); ++i)
- QVERIFY(circ3.at(i) == i + 17);
-
- // We also need to test with a linearised buffer of a movable type
- QCircularBuffer<int> circ4(20);
- for (int i = 0; i < 15; ++i)
- circ4.append(i + 1);
- circ4.setCapacity(10);
- QVERIFY(circ4.capacity() == 10);
- QVERIFY(circ4.size() == 10);
- for (int i = 0; i < circ4.size(); ++i)
- QVERIFY(circ4.at(i) == i + 1);
-}
-
-void tst_QCircularBuffer::size()
-{
- QCircularBuffer<int> circ(3);
- QVERIFY(circ.capacity() == 3);
- QVERIFY(circ.isEmpty() == true);
- QVERIFY(circ.size() == 0);
- circ.append(1);
- QVERIFY(circ.size() == 1);
- circ.append(2);
- circ.append(3);
- QVERIFY(circ.isFull() == true);
- QVERIFY(circ.size() == 3);
- QVERIFY(circ.size() == circ.capacity());
-}
-
-void tst_QCircularBuffer::sizeAvailable()
-{
- QCircularBuffer<int> circ(10);
- QVERIFY(circ.capacity() == 10);
- QVERIFY(circ.size() == 0);
- QVERIFY(circ.sizeAvailable() == 10);
-
- for (int i = 0; i < 15; ++i) {
- circ.append(i + 1);
- QVERIFY(circ.size() == qMin(i + 1, circ.capacity()));
- QVERIFY(circ.sizeAvailable() == qMax(0, circ.capacity() - i - 1));
- }
-}
-
-void tst_QCircularBuffer::startsWith()
-{
- // Test with a linearised buffer
- QCircularBuffer<int> circ(5);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- circ.append(4);
- circ.append(5);
- QVERIFY(circ.startsWith(1) == true);
- QVERIFY(circ.endsWith(3) == false);
-
- // Now with a non-linearised buffer
- circ.append(6);
- circ.append(7);
- QVERIFY(circ.startsWith(3) == true);
- QVERIFY(circ.startsWith(1) == false);
-}
-
-void tst_QCircularBuffer::toList()
-{
- QCircularBuffer<int> circ(10);
- for (int i = 0; i < circ.capacity(); ++i)
- circ.append(i + 1);
- QList<int> list = circ.toList();
- QVERIFY(list.size() == circ.size());
- for (int i = 0; i < list.size(); ++i)
- QVERIFY(list.at(i) == circ.at(i));
-}
-
-void tst_QCircularBuffer::toVector()
-{
- QCircularBuffer<int> circ(10);
- for (int i = 0; i < circ.capacity(); ++i)
- circ.append(i + 1);
- QVector<int> vector = circ.toVector();
- QVERIFY(vector.size() == circ.size());
- for (int i = 0; i < vector.size(); ++i)
- QVERIFY(vector.at(i) == circ.at(i));
-}
-
-void tst_QCircularBuffer::value()
-{
- QCircularBuffer<int> circ(3);
- circ.append(1);
- circ.append(2);
- circ.append(3);
- QVERIFY(circ.value(0) == 1);
- QVERIFY(circ.value(1) == 2);
- QVERIFY(circ.value(2) == 3);
- QVERIFY(circ.value(3) == 0); // Out of range, so default value
- QVERIFY(circ.value(3, 7) == 7); // Out of range, so specified default value
-}
-
-void tst_QCircularBuffer::operatorEquality()
-{
- QCircularBuffer<int> circ1(10);
- QCircularBuffer<int> circ2(10);
- for (int i = 0; i < 10; i++) {
- circ1.append(i);
- circ2.append(i);
- }
-
- QVERIFY(circ1 == circ2);
-
- // This test for equality should be fast as it should find
- // that the internal d-pointers are the same and so be able
- // to skip the element by element comparison
- QCircularBuffer<int> circ3(circ1);
- QVERIFY(circ1 == circ3);
-}
-
-void tst_QCircularBuffer::operatorInequality()
-{
- QCircularBuffer<int> circ1(10);
- QCircularBuffer<int> circ2(11);
- for (int i = 0; i < 10; i++) {
- circ1.append(i);
- circ2.append(i);
- }
- circ2.append(11);
-
- QVERIFY(circ1 != circ2);
-
- QCircularBuffer<int> circ3(10);
- QCircularBuffer<int> circ4(10);
- for (int i = 0; i < 10; i++) {
- circ3.append(i);
- if (i == 4)
- circ4.append(100);
- else
- circ4.append(i);
- }
-
- QVERIFY(circ3 != circ4);
-}
-
-void tst_QCircularBuffer::operatorPlus()
-{
- QCircularBuffer<int> circ1(20);
- for (int i = 0; i < 10; ++i)
- circ1.append(i + 1);
-
- QCircularBuffer<int> circ2(5);
- for (int i = 0; i < circ2.capacity(); ++i)
- circ2.append(i + 11);
-
- QCircularBuffer<int> circ3 = circ1 + circ2;
- QVERIFY(circ3.capacity() == circ1.size() + circ2.size());
- QVERIFY(circ3.size() == circ1.size() + circ2.size());
- for (int i = 0; i < circ3.size(); ++i) {
- if (i < circ1.size())
- QVERIFY(circ3.at(i) == circ1.at(i));
- else
- QVERIFY(circ3.at(i) == circ2.at(i - circ1.size()));
- }
-}
-
-void tst_QCircularBuffer::operatorPlusEquals()
-{
- QCircularBuffer<int> circ(100);
- for (int i = 0; i < 10; ++i)
- circ.append(i + 1);
-
- // Add individual elements
- for (int i = 0; i < 10; ++i) {
- circ += i + 11;
- QVERIFY(circ.size() == i + 11);
- QVERIFY(circ.last() == i + 11);
- }
-
- // Add in an existing QCircularBuffer
- QCircularBuffer<int> circ2(10);
- for (int i = 0; i < 10; ++i)
- circ2.append(i + 21);
- circ += circ2;
- QVERIFY(circ.size() == 30);
- for (int i = 20; i < 30; ++i)
- QVERIFY(circ.at(i) == i + 1);
-
- // Add in a list
- QList<int> list;
- for (int i = 0; i < 10; ++i)
- list.append(i + 31);
- circ += list;
- QVERIFY(circ.size() == 40);
- for (int i = 30; i < 40; ++i)
- QVERIFY(circ.at(i) == i + 1);
-
- // Add in a vector
- QVector<int> vector;
- for (int i = 0; i < 10; ++i)
- vector.append(i + 41);
- circ += vector;
- QVERIFY(circ.size() == 50);
- for (int i = 40; i < 50; ++i)
- QVERIFY(circ.at(i) == i + 1);
-}
-
-void tst_QCircularBuffer::operatorStream()
-{
- QCircularBuffer<int> circ(100);
- for (int i = 0; i < 10; ++i)
- circ.append(i + 1);
-
- // Add individual elements
- for (int i = 0; i < 10; ++i) {
- circ << i + 11;
- QVERIFY(circ.size() == i + 11);
- QVERIFY(circ.last() == i + 11);
- }
-
- // Add in an existing QCircularBuffer
- QCircularBuffer<int> circ2(10);
- for (int i = 0; i < 10; ++i)
- circ2.append(i + 21);
- circ << circ2;
- QVERIFY(circ.size() == 30);
- for (int i = 20; i < 30; ++i)
- QVERIFY(circ.at(i) == i + 1);
-
- // Add in a list
- QList<int> list;
- for (int i = 0; i < 10; ++i)
- list.append(i + 31);
- circ << list;
- QVERIFY(circ.size() == 40);
- for (int i = 30; i < 40; ++i)
- QVERIFY(circ.at(i) == i + 1);
-
- // Add in a vector
- QVector<int> vector;
- for (int i = 0; i < 10; ++i)
- vector.append(i + 41);
- circ << vector;
- QVERIFY(circ.size() == 50);
- for (int i = 40; i < 50; ++i)
- QVERIFY(circ.at(i) == i + 1);
-}
-
-void tst_QCircularBuffer::const_iterator()
-{
- // Test basic iteration over a linearised buffer.
- // This tests operators !=, prefix ++, and *
- QCircularBuffer<int> circ(10);
- for (int i = 0; i < circ.capacity(); ++i)
- circ.append(i + 1);
-
- QCircularBuffer<int>::const_iterator it = circ.constBegin();
- int i = 0;
- while (it != circ.constEnd()) {
- QVERIFY(*it == circ.at(i++));
- ++it;
- }
- QVERIFY(i == circ.size());
-
- // Test basic iteration over a non-linearised buffer.
- // This tests operators !=, prefix ++, and *
- QCircularBuffer<int> circ2(10);
- for (int i = 0; i < 14; ++i)
- circ2.append(i + 1);
-
- QCircularBuffer<int>::const_iterator it2 = circ2.constBegin();
- i = 0;
- while (it2 != circ2.constEnd()) {
- QVERIFY(*it2 == circ2.at(i++));
- ++it2;
- }
- QVERIFY(i == circ2.size());
-
- // Reverse iteration
- while (it2 != circ2.constBegin()) {
- --it2;
- QVERIFY(*it2 == circ2.at(--i));
- }
- QVERIFY(i == 0);
-
- // Operator ==
- it = circ2.constBegin();
- it2 = circ2.constBegin();
- QVERIFY(it == it2);
-
- // Operator [int]
- for (int i = 0; i < circ2.size(); ++i)
- QVERIFY(it[ i ] == circ2.at(i));
-
- // Postfix operator ++
- QCircularBuffer<int>::const_iterator it3 = it2++;
- QVERIFY(it3 == it);
- QVERIFY(*it2 == circ2.at(1));
-
- // Comparison operators
- QVERIFY(it < it2);
- QVERIFY(it <= it2);
- QVERIFY(it <= it3);
- QVERIFY(it2 > it);
- QVERIFY(it2 >= it);
- QVERIFY(it3 >= it);
-
- // Postfix operator --
- it3 = it2--;
- QVERIFY(*it3 == circ2.at(1));
- QVERIFY(it2 == it);
-
- // Operator += and -=
- it2 += 1;
- QVERIFY(it2 == it3);
- it2 -= 1;
- QVERIFY(it2 == it);
-
- // Operator + (int) and operator - (int)
- QCircularBuffer<int>::const_iterator it4 = it + (circ2.size() - 1);
- QVERIFY(*it4 == circ2.last());
- QCircularBuffer<int>::const_iterator it5 = it4 - (circ2.size() - 1);
- QVERIFY(*it5 == circ2.first());
-
- // Operator - (const_iterator)
- QVERIFY(it4 - it5 == circ2.size() - 1);
-
- // Operator ->
- QCircularBuffer<MyComplexType> circ3(10);
- for (int i = 0; i < circ3.capacity(); ++i)
- circ3.append(i + 1);
- QCircularBuffer<MyComplexType>::const_iterator it6 = circ3.constBegin();
- for (int i = 0; i < circ2.capacity(); ++i)
- {
- QVERIFY(it6->x == circ3.at(i).x);
- ++it6;
- }
-}
-
-void tst_QCircularBuffer::iterator()
-{
- // Test basic iteration over a linearised buffer.
- // This tests operators !=, prefix ++, and *
- QCircularBuffer<int> circ(10);
- for (int i = 0; i < circ.capacity(); ++i)
- circ.append(i + 1);
-
- QCircularBuffer<int>::iterator it = circ.begin();
- int i = 0;
- while (it != circ.end()) {
- QVERIFY(*it == circ.at(i++));
- ++it;
- }
- QVERIFY(i == circ.size());
-
- // Test basic iteration over a non-linearised buffer.
- // This tests operators !=, prefix ++, and *
- QCircularBuffer<int> circ2(10);
- for (int i = 0; i < 14; ++i)
- circ2.append(i + 1);
-
- QCircularBuffer<int>::iterator it2 = circ2.begin();
- i = 0;
- while (it2 != circ2.end()) {
- QVERIFY(*it2 == circ2.at(i++));
- ++it2;
- }
- QVERIFY(i == circ2.size());
-
- // Reverse iteration
- while (it2 != circ2.begin()) {
- --it2;
- QVERIFY(*it2 == circ2.at(--i));
- }
- QVERIFY(i == 0);
-
- // Operator ==
- it = circ2.begin();
- it2 = circ2.begin();
- QVERIFY(it == it2);
-
- // Operator [int]
- for (int i = 0; i < circ2.size(); ++i)
- QVERIFY(it[ i ] == circ2.at(i));
-
- // Postfix operator ++
- QCircularBuffer<int>::iterator it3 = it2++;
- QVERIFY(it3 == it);
- QVERIFY(*it2 == circ2.at(1));
-
- // Comparison operators
- QVERIFY(it < it2);
- QVERIFY(it <= it2);
- QVERIFY(it <= it3);
- QVERIFY(it2 > it);
- QVERIFY(it2 >= it);
- QVERIFY(it3 >= it);
-
- // Postfix operator --
- it3 = it2--;
- QVERIFY(*it3 == circ2.at(1));
- QVERIFY(it2 == it);
-
- // Operator += and -=
- it2 += 1;
- QVERIFY(it2 == it3);
- it2 -= 1;
- QVERIFY(it2 == it);
-
- // Operator + (int) and operator - (int)
- QCircularBuffer<int>::iterator it4 = it + (circ2.size() - 1);
- QVERIFY(*it4 == circ2.last());
- QCircularBuffer<int>::iterator it5 = it4 - (circ2.size() - 1);
- QVERIFY(*it5 == circ2.first());
-
- // Operator - (const_iterator)
- QVERIFY(it4 - it5 == circ2.size() - 1);
-
- // Operator ->
- QCircularBuffer<MyComplexType> circ3(10);
- for (int i = 0; i < circ3.capacity(); ++i)
- circ3.append(i + 1);
- QCircularBuffer<MyComplexType>::iterator it6 = circ3.begin();
- for (int i = 0; i < circ2.capacity(); ++i) {
- QVERIFY(it6->x == circ3.at(i).x);
- ++it6;
- }
-}
-
-void tst_QCircularBuffer::testAppendFifo()
-{
- QCircularBuffer< float > c;
- c.setCapacity(5);
- c += QVector<float>(4, 0.0f);
- c.setCapacity(7);
- c += QVector<float>(4, 0.0f);
- c.remove(0, 2);
-}
-
-QTEST_APPLESS_MAIN(tst_QCircularBuffer)
-#include "tst_qcircularbuffer.moc"
diff --git a/tests/auto/core/qframeallocator/qframeallocator.pro b/tests/auto/core/qframeallocator/qframeallocator.pro
deleted file mode 100644
index 673ef12f4..000000000
--- a/tests/auto/core/qframeallocator/qframeallocator.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-TARGET = tst_qframeallocator
-CONFIG += testcase
-TEMPLATE = app
-
-SOURCES += tst_qframeallocator.cpp
-
-QT += testlib 3dcore 3dcore-private
diff --git a/tests/auto/core/qframeallocator/tst_qframeallocator.cpp b/tests/auto/core/qframeallocator/tst_qframeallocator.cpp
deleted file mode 100644
index 3d2355eb8..000000000
--- a/tests/auto/core/qframeallocator/tst_qframeallocator.cpp
+++ /dev/null
@@ -1,767 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <private/qframeallocator_p.h>
-#include <private/qframeallocator_p_p.h>
-
-class tst_QFrameAllocator : public QObject
-{
- Q_OBJECT
-public:
- tst_QFrameAllocator() : QObject() {}
- ~tst_QFrameAllocator() {}
-
- struct small
- {
- char c;
- };
-
- struct medium
- {
- int a, b, c;
- };
-
- struct big
- {
- int t[8];
- };
-
- struct huge
- {
- int t[64];
- };
-
- struct composed
- {
- QVector<int> vec;
- QList<int> list;
- int t;
- };
-
- struct subclass : public composed
- {
- float toto;
- // add some more data to force the subclass into a different bucket
- char data[32];
- };
-
-private slots:
-
- void initQFrameChunk();
- void singleAllocationQFrameChunk();
- void qvectorAllocationQFrameChunk();
- void multipleAllocationQFrameChunk();
- void overflowAllocationQFrameChunk();
- void singleDeallocationQFrameChunk();
- void multipleDeallocationQFrameChunk();
- void containsCheckQFrameChunk();
- void clearQFrameChunk();
- void initQFixedFrameAllocator();
- void allocateQFixedFrameAllocator();
- void deallocateQFixedFrameAllocator();
- void checkFragmentationQFixedFrameAllocator();
- void clearQFixedFrameAllocator();
- void initQFrameAllocator();
- void allocateWithQFrameAllocator();
- void deallocateWithQFrameAllocator();
- void testAllocationComposedValues();
- void allocateSubclass();
- void deallocateSubclass();
- void clearQFrameAllocator();
- void isEmptyQFrameAllocator();
- void subclassPointerClearing();
- void allocateWithRawMemoryDeallocate();
- void allocateDeallocateRawMemory();
-};
-
-void tst_QFrameAllocator::initQFrameChunk()
-{
- Qt3DCore::QFrameChunk c;
-
- c.init(16, 12);
-
- QVERIFY(c.m_blocksAvailable == c.m_maxBlocksAvailable);
- QCOMPARE(c.m_blocksAvailable, (uchar)12);
- QCOMPARE(c.m_firstAvailableBlock, (uchar)0);
- QVERIFY(c.m_data != nullptr);
- QVERIFY(c.isEmpty());
-
- for (int i = 0; i < 12; i++) {
- QCOMPARE(c.m_data[i * 16], (uchar)(i + 1));
- }
-}
-
-void tst_QFrameAllocator::singleAllocationQFrameChunk()
-{
- Qt3DCore::QFrameChunk c;
-
- c.init(16, 12);
-
- void *ptr = c.allocate(16);
-
- QVERIFY(c.contains(ptr, 16));
- QVERIFY(!c.isEmpty());
- QCOMPARE(c.m_blocksAvailable, (uchar)(c.m_maxBlocksAvailable - 1));
- QVERIFY(ptr != nullptr);
- QCOMPARE(c.m_firstAvailableBlock, (uchar)1);
- QCOMPARE(*((uchar*)ptr), (uchar)1);
-}
-
-void tst_QFrameAllocator::qvectorAllocationQFrameChunk()
-{
- Qt3DCore::QFrameChunk c;
-
- c.init(16, 12);
-
- QVector<int> *v = nullptr;
-
- QVERIFY(sizeof(v) < 16);
- v = static_cast<QVector<int> *>(c.allocate(16));
- QVERIFY(v != nullptr);
- new (v) QVector<int>();
- for (int i = 0; i < 1024; i++)
- v->append(i);
-}
-
-void tst_QFrameAllocator::multipleAllocationQFrameChunk()
-{
- Qt3DCore::QFrameChunk c;
-
- c.init(16, 12);
-
- QList<void *> ptrs;
- for (int i = 0; i < 6; i++) {
- ptrs << c.allocate(16);
- }
-
- QCOMPARE(c.m_maxBlocksAvailable, (uchar)12);
- QCOMPARE(c.m_blocksAvailable, (uchar)6);
- QCOMPARE(c.m_firstAvailableBlock, (uchar)6);
- QVERIFY(!c.isEmpty());
- for (int i = 0; i < 6; i++) {
- QVERIFY(ptrs.at(i) != nullptr);
- QCOMPARE(*((uchar*)ptrs.at(i)), (uchar)(i + 1));
- }
-}
-
-void tst_QFrameAllocator::overflowAllocationQFrameChunk()
-{
- Qt3DCore::QFrameChunk c;
-
- c.init(16, 12);
-
- QList<void *> ptrs;
- for (int i = 0; i < 15; i++) {
- ptrs << c.allocate(16);
- }
-
- QCOMPARE(c.m_maxBlocksAvailable, (uchar)12);
- QCOMPARE(c.m_blocksAvailable,(uchar) 0);
- QCOMPARE(c.m_firstAvailableBlock, (uchar)12);
- QVERIFY(!c.isEmpty());
- for (int i = 0; i < 15; i++) {
- if (i < 12) {
- QVERIFY(ptrs.at(i) != nullptr);
- QCOMPARE(*((uchar*)ptrs.at(i)), (uchar)(i + 1));
- }
- else {
- QVERIFY(ptrs.at(i) == nullptr);
- }
- }
-}
-
-void tst_QFrameAllocator::singleDeallocationQFrameChunk()
-{
- Qt3DCore::QFrameChunk c;
-
- c.init(16, 12);
-
- void *ptr = c.allocate(16);
-
- c.deallocate(ptr, 16);
-
- QVERIFY(c.m_blocksAvailable == c.m_maxBlocksAvailable);
- QCOMPARE(c.m_blocksAvailable, (uchar)12);
- QCOMPARE(c.m_firstAvailableBlock, (uchar)0);
- QVERIFY(c.m_data != nullptr);
- QVERIFY(c.isEmpty());
-
- for (int i = 0; i < 12; i++) {
- QCOMPARE(c.m_data[i * 16], (uchar)(i + 1));
- }
-}
-
-void tst_QFrameAllocator::multipleDeallocationQFrameChunk()
-{
- Qt3DCore::QFrameChunk c;
-
- c.init(16, 12);
-
- QList<void *> ptrs;
- for (int i = 0; i < 6; i++) {
- ptrs << c.allocate(16);
- }
-
- // Free half
-
- for (int i = 0; i < 6; i++) {
- c.deallocate(ptrs.at(i), 16);
- QCOMPARE(c.m_firstAvailableBlock, (uchar)(i));
- }
-
- QVERIFY(c.m_blocksAvailable == c.m_maxBlocksAvailable);
- QCOMPARE(c.m_blocksAvailable, (uchar)12);
- QVERIFY(c.m_data != nullptr);
- QVERIFY(c.isEmpty());
-
- // Refill all
- ptrs.clear();
- for (int i = 0; i < 12; i++) {
- void *ptr = c.allocate(16);
- ptrs << ptr;
- QVERIFY(ptr != nullptr);
- }
- QVERIFY(!c.isEmpty());
-
- // Free all
- for (int i = 0; i < 12; i++) {
- c.deallocate(ptrs.at(i), 16);
- }
- QVERIFY(c.isEmpty());
-
- // Refill all
- ptrs.clear();
-
- for (int i = 0; i < 12; i++) {
- void *ptr = c.allocate(16);
- ptrs << ptr;
- QVERIFY(ptr != nullptr);
- }
-
- // Free all in non linear behavior
- for (int i = 0; i < 6; i++) {
- c.deallocate(ptrs.takeLast(), 16);
- c.deallocate(ptrs.takeFirst(), 16);
- }
- QVERIFY(c.isEmpty());
-
- // Refill all
- ptrs.clear();
- for (int i = 0; i < 12; i++) {
- void *ptr = c.allocate(16);
- ptrs << ptr;
- QVERIFY(ptr != nullptr);
- }
- QVERIFY(!c.isEmpty());
-}
-
-void tst_QFrameAllocator::containsCheckQFrameChunk()
-{
- Qt3DCore::QFrameChunk c;
- Qt3DCore::QFrameChunk c2;
-
- c.init(16, 12);
- c2.init(16, 12);
-
- QList<void *> ptrs;
- for (int i = 0; i < 6; i++) {
- ptrs << c.allocate(16);
- }
-
- QVERIFY(!c.contains((void *)(quintptr)0xffffffff, 16));
- QVERIFY(!c2.contains((void *)(quintptr)0xffffffff, 16));
- QVERIFY(c.contains(ptrs.first(), 16));
- QVERIFY(!c2.contains(ptrs.first(), 16));
- QVERIFY(c.contains(ptrs.last(), 16));
- QVERIFY(!c2.contains(ptrs.last(), 16));
-
- for (int i = 0; i < 6; i++) {
- ptrs << c2.allocate(16);
- }
-
- QVERIFY(!c.contains((void *)(quintptr)0xffffffff, 16));
- QVERIFY(!c.contains(ptrs.last(), 16));
- QVERIFY(c.contains(ptrs.first(), 16));
- QVERIFY(c2.contains(ptrs.last(), 16));
- QVERIFY(!c2.contains(ptrs.first(), 16));
-}
-
-void tst_QFrameAllocator::clearQFrameChunk()
-{
- Qt3DCore::QFrameChunk c;
-
- c.init(16, 12);
- QList<void *> ptrs;
- for (int i = 0; i < 6; i++) {
- ptrs << c.allocate(16);
- }
- QVERIFY(!c.isEmpty());
- c.clear(16, 12);
- QVERIFY(c.isEmpty());
- QCOMPARE(c.m_blocksAvailable, c.m_maxBlocksAvailable);
- QCOMPARE(c.m_firstAvailableBlock, (uchar)0);
-
- for (int i = 0; i < 12; i++) {
- QCOMPARE(c.m_data[i * 16], (uchar)(i + 1));
- }
-}
-
-void tst_QFrameAllocator::initQFixedFrameAllocator()
-{
- Qt3DCore::QFixedFrameAllocator f;
-
- f.init(4);
-
- QCOMPARE(f.chunkCount(), 0);
- QCOMPARE(f.pageSize(), (uchar)128);
-}
-
-void tst_QFrameAllocator::allocateQFixedFrameAllocator()
-{
- Qt3DCore::QFixedFrameAllocator f;
-
- f.init(4, 128);
-
- QList<void *> ptrs;
-
- // Fill 1 chunck
- for (int i = 0; i < 128; i++) {
- void *ptr = f.allocate();
- QVERIFY(ptr != nullptr);
- ptrs << ptr;
- }
- QCOMPARE(f.chunkCount(), 1);
- // Fill half of chunk 2
- for (int i = 0; i < 64; i++) {
- void *ptr = f.allocate();
- QVERIFY(ptr != nullptr);
- ptrs << ptr;
- }
- // Free chunk 2
- QCOMPARE(f.chunkCount(), 2);
- for (int i = 0; i < 64; i++) {
- f.deallocate(ptrs.takeLast());
- }
- // Allocate 2 chunks worth of data which should create a single new chunk
- // as chunk 2 is empty
- QCOMPARE(f.chunkCount(), 2);
-
- for (int i = 0; i < 256; i++) {
- void *ptr = f.allocate();
- QVERIFY(ptr != nullptr);
- ptrs << ptr;
- }
- QCOMPARE(f.chunkCount(), 3);
-}
-
-void tst_QFrameAllocator::deallocateQFixedFrameAllocator()
-{
- Qt3DCore::QFixedFrameAllocator f;
-
- f.init(4);
-
- QList<void *> ptrs;
-
- for (int i = 0; i < 128; i++) {
- void *ptr = f.allocate();
- QVERIFY(ptr != nullptr);
- ptrs << ptr;
- }
- QCOMPARE(f.chunkCount(), 1);
- for (int i = 0; i < 64; i++) {
- void *ptr = f.allocate();
- QVERIFY(ptr != nullptr);
- ptrs << ptr;
- }
- QCOMPARE(f.chunkCount(), 2);
- for (int i = 0; i < 64; i++) {
- f.deallocate(ptrs.takeLast());
- }
- QCOMPARE(f.chunkCount(), 2);
- f.trim();
- QCOMPARE(f.chunkCount(), 1);
-
- for (int i = 0; i < 64; i++) {
- f.deallocate(ptrs.takeFirst());
- }
- QCOMPARE(f.chunkCount(), 1);
- for (int i = 0; i < 36; i++) {
- void *ptr = f.allocate();
- QVERIFY(ptr != nullptr);
- ptrs << ptr;
- }
- QCOMPARE(f.chunkCount(), 1);
-}
-
-void tst_QFrameAllocator::checkFragmentationQFixedFrameAllocator()
-{
- Qt3DCore::QFixedFrameAllocator f;
-
- f.init(4);
-
- QList<void *> ptrs;
-
- for (int i = 0; i < 256; i++) {
- void *ptr = f.allocate();
- QVERIFY(ptr != nullptr);
- ptrs << ptr;
- }
-
- QCOMPARE(f.chunkCount(), 2);
-
- for (int i = 0; i < 64; i++) {
- f.deallocate(ptrs.takeFirst());
- }
-
- QCOMPARE(f.chunkCount(), 2);
-
- for (int i = 0; i < 64; i++) {
- void *ptr = f.allocate();
- QVERIFY(ptr != nullptr);
- ptrs << ptr;
- }
- QCOMPARE(f.chunkCount(), 2);
-}
-
-void tst_QFrameAllocator::clearQFixedFrameAllocator()
-{
- Qt3DCore::QFixedFrameAllocator f;
-
- f.init(16);
-
- QList<void *> ptrs;
-
- for (int i = 0; i < 256; i++) {
- void *ptr = f.allocate();
- QVERIFY(ptr != nullptr);
- ptrs << ptr;
- }
- QCOMPARE(f.chunkCount(), 2);
-
- f.clear();
- QCOMPARE(f.chunkCount(), 2);
-
- for (int i = 0; i < 256; i++) {
- void *ptr = f.allocate();
- QVERIFY(ptr != nullptr);
- ptrs << ptr;
- }
- QCOMPARE(f.chunkCount(), 2);
-}
-
-void tst_QFrameAllocator::initQFrameAllocator()
-{
- Qt3DCore::QFrameAllocator f(4, 4);
- QCOMPARE(f.allocatorPoolSize(), 1);
-
-
- Qt3DCore::QFrameAllocator f2(32, 4);
- QCOMPARE(f2.allocatorPoolSize(), 8);
-}
-
-void tst_QFrameAllocator::allocateWithQFrameAllocator()
-{
- Qt3DCore::QFrameAllocator f2(256, 4);
- QCOMPARE(f2.allocatorPoolSize(), 256 / 4);
-
- QVERIFY(f2.allocate<small>());
- QVERIFY(f2.allocate<medium>());
- QVERIFY(f2.allocate<big>());
- QVERIFY(f2.allocate<huge>());
-
- QList<medium *> mediums;
- for (int i = 0; i < 800; i++) {
- medium *m = f2.allocate<medium>();
- QVERIFY(m);
- m->a = i;
- m->b = 800;
- m->c = m->b - m->a;
- mediums.append(m);
- }
- QCOMPARE(mediums.size(), 800);
- for (int i = 0; i < 800; i++) {
- medium *m = mediums.at(i);
- QCOMPARE(m->a, i);
- QCOMPARE(m->b, 800);
- QCOMPARE(m->c, m->b - m->a);
- }
-
- QList<huge *> huges;
- for (int i = 0; i < 250; i++) {
- huge *m = f2.allocate<huge>();
- QCOMPARE((int)(sizeof(m->t) / sizeof(int)), 64);
- for (int j = 0; j < 64; j++)
- m->t[j] = i * j;
- huges.append(m);
- }
- for (int i = 0; i < 250; i++) {
- huge *m = huges.at(i);
- for (int j = 0; j < 64; j++)
- QCOMPARE(m->t[j], i * j);
- }
-}
-
-void tst_QFrameAllocator::deallocateWithQFrameAllocator()
-{
- Qt3DCore::QFrameAllocator f2(256, 4);
- QCOMPARE(f2.allocatorPoolSize(), 256 / 4);
-
- small *s = f2.allocate<small>();
- QVERIFY(s);
- medium *m = f2.allocate<medium>();
- QVERIFY(m);
- big *b = f2.allocate<big>();
- QVERIFY(b);
- huge *h = f2.allocate<huge>();
- QVERIFY(h);
-
- f2.deallocate(s);
- f2.deallocate(m);
- f2.deallocate(b);
- f2.deallocate(h);
-}
-
-void tst_QFrameAllocator::testAllocationComposedValues()
-{
- Qt3DCore::QFrameAllocator f(128, 32);
-
- composed t;
-
- QVector<int> *v = f.allocate<QVector<int> >();
-
- QVERIFY(v);
-
- for (int i = 0; i < 10; i++)
- v->append(2);
-
-
- for (int i = 0; i < 100; i++) {
- t.vec.append(i);
- t.list.append(i);
- }
-
- composed *composedValues[30];
-
- for (auto &v : composedValues) {
- v = f.allocate<composed>();
- QVERIFY(v);
- for (int j = 0; j < 100; j++) {
- v->vec.append(j);
- v->list.append(j);
- v->t = 100;
- }
- }
-
- for (composed *c : composedValues) {
- QCOMPARE(c->vec.size(), 100);
- QCOMPARE(c->list.size(), 100);
- QCOMPARE(c->t, 100);
-
- for (int j = 0; j < 100; j++) {
- QCOMPARE(c->vec.at(j), j);
- QCOMPARE(c->list.at(j), j);
- }
- }
-}
-
-void tst_QFrameAllocator::allocateSubclass()
-{
- Qt3DCore::QFrameAllocator f(128, 32);
-
- QList<composed *> composeds;
-
- for (int i = 0; i < 256; i++) {
- // Allocate a composed object of size subclass
- // c is actually a subclass
- composed *c = static_cast<composed*>(f.allocateRawMemory(sizeof(subclass)));
- composeds << c;
- }
-
- QCOMPARE(composeds.count(), 256);
-
- for (composed *c : qAsConst(composeds)) {
- subclass *s = static_cast<subclass *>(c);
- s->toto = 2586.0f;
- }
-
- for (int i = 0; i < 256; i++) {
- subclass *s = static_cast<subclass *>(composeds.takeLast());
- QVERIFY(s->toto == 2586.0f);
- }
-}
-
-void tst_QFrameAllocator::deallocateSubclass()
-{
- Qt3DCore::QFrameAllocator f(128, 32);
-
-
- const int NUM_ITEMS = 256;
- QVector<void *> allocated(NUM_ITEMS);
- uint chunkCount = 0;
-
- for (int l = 0; l < 6; l++) {
-
- for (int i = 0; i < NUM_ITEMS; i++) {
- // Allocate a composed object of size subclass
- // c is actually a subclass
- allocated[i] = f.allocateRawMemory(sizeof(subclass));
- }
-
- if (!chunkCount)
- chunkCount = f.totalChunkCount();
- else
- QCOMPARE(chunkCount, f.totalChunkCount());
-
- for (int i = 0; i < NUM_ITEMS; i++) {
- f.deallocateRawMemory(allocated[i], sizeof(subclass));
- }
- }
-
-}
-
-void tst_QFrameAllocator::clearQFrameAllocator()
-{
- Qt3DCore::QFrameAllocator f(128, 32);
-
- for (int i = 0; i < 256; i++) {
- f.allocate<composed>();
- }
- uint chunkCount = f.totalChunkCount();
- f.clear();
- QCOMPARE(chunkCount, f.totalChunkCount());
-
- for (int i = 0; i < 256; i++) {
- QList<composed *> composeds;
- for (int j = 0; j < 256; j++) {
- composed *c = f.allocate<composed>();
- c ->t = i * j;
- composeds << c;
- }
- QCOMPARE(chunkCount, f.totalChunkCount());
- for (int j = 0; j < 256; j++) {
- QCOMPARE(composeds.at(j)->t, i * j);
- }
- f.clear();
- QCOMPARE(chunkCount, f.totalChunkCount());
- }
-}
-
-void tst_QFrameAllocator::isEmptyQFrameAllocator()
-{
- // GIVEN
- Qt3DCore::QFrameAllocator f(128, 32);
-
-
- // WHEN
- for (int i = 0; i < 256; ++i)
- f.allocate<composed>();
- // THEN
- QVERIFY(!f.isEmpty());
-
- // WHEN
- f.clear();
- // THEN
- QVERIFY(f.isEmpty());
-
- for (int i = 0; i < 256; ++i) {
-
- // GIVEN
- QVector<composed *> composeds;
- for (int j = 0; j < 256; ++j) {
- composed *c = f.allocate<composed>();
- c ->t = i * j;
- composeds << c;
- }
- // THEN
- QVERIFY(!f.isEmpty());
-
- // WHEN
- for (int j = 0; j < 256; ++j)
- f.deallocate(composeds.takeAt(0));
- // THEN
- QVERIFY(f.isEmpty());
- }
-}
-
-void tst_QFrameAllocator::subclassPointerClearing()
-{
- // GIVEN
- Qt3DCore::QFrameAllocator f(128, 32);
- QVector<composed *> data;
-
- // WHEN
- for (int i = 0; i < 32; ++i) {
- composed *c = (i % 2 == 0) ? f.allocate<composed>() : f.allocate<subclass>();
- data.append(c);
- }
- // THEN
- QVERIFY(!f.isEmpty());
-
- // WHEN
- for (int j = 0; j < 32; ++j) {
- if ((j % 2 == 0))
- f.deallocate<composed>(data.takeAt(0));
- else
- f.deallocate<subclass>(static_cast<subclass *>(data.takeAt(0)));
- }
-
- // THEN
- QVERIFY(f.isEmpty());
-}
-
-void tst_QFrameAllocator::allocateWithRawMemoryDeallocate()
-{
- // GIVEN
- Qt3DCore::QFrameAllocator f(128, 32);
- subclass *s = static_cast<subclass *>(f.allocateRawMemory(sizeof(subclass)));
- new (s) subclass();
-
- // WHEN
- f.deallocate(s);
-
- // THEN
- QVERIFY(f.isEmpty());
-}
-
-void tst_QFrameAllocator::allocateDeallocateRawMemory()
-{
- // GIVEN
- Qt3DCore::QFrameAllocator f(128, 32);
- subclass *s = f.allocate<subclass>();
-
- // WHEN
- f.deallocateRawMemory(s, sizeof(subclass));
-
- // THEN
- QVERIFY(f.isEmpty());
-}
-
-QTEST_APPLESS_MAIN(tst_QFrameAllocator)
-
-#include "tst_qframeallocator.moc"
diff --git a/tests/auto/input/mousedevice/tst_mousedevice.cpp b/tests/auto/input/mousedevice/tst_mousedevice.cpp
index 95ae8de56..cad1ab951 100644
--- a/tests/auto/input/mousedevice/tst_mousedevice.cpp
+++ b/tests/auto/input/mousedevice/tst_mousedevice.cpp
@@ -233,11 +233,14 @@ private Q_SLOTS:
Qt3DInput::Input::MouseDevice backendMouseDevice;
// WHEN
- auto eventList = QList<QT_PREPEND_NAMESPACE(QWheelEvent)>() << QT_PREPEND_NAMESPACE(QWheelEvent)(QPointF(500.0f, 500.0f),
- 120,
- Qt::NoButton,
- Qt::NoModifier,
- Qt::Vertical);
+ auto eventList = QList<QT_PREPEND_NAMESPACE(QWheelEvent)>()
+ << QT_PREPEND_NAMESPACE(QWheelEvent)(QPointF(500.0, 500.0),
+ QPointF(), QPoint(),
+ QPoint(0, 120),
+ Qt::NoButton,
+ Qt::NoModifier,
+ Qt::NoScrollPhase,
+ false);
backendMouseDevice.updateWheelEvents(eventList);
// THEN
@@ -246,11 +249,14 @@ private Q_SLOTS:
QCOMPARE(backendMouseDevice.sensitivity(), 0.1f);
// WHEN
- eventList = QList<QT_PREPEND_NAMESPACE(QWheelEvent)>() << QT_PREPEND_NAMESPACE(QWheelEvent)(QPointF(500.0f, 500.0f),
- 120,
- Qt::NoButton,
- Qt::NoModifier,
- Qt::Horizontal);
+ eventList = QList<QT_PREPEND_NAMESPACE(QWheelEvent)>()
+ << QT_PREPEND_NAMESPACE(QWheelEvent)(QPointF(500.0, 500.0),
+ QPointF(), QPoint(),
+ QPoint(120, 0),
+ Qt::NoButton,
+ Qt::NoModifier,
+ Qt::NoScrollPhase,
+ false);
backendMouseDevice.updateWheelEvents(eventList);
// THEN
@@ -259,11 +265,13 @@ private Q_SLOTS:
QCOMPARE(backendMouseDevice.sensitivity(), 0.1f);
// WHEN
- eventList = QList<QT_PREPEND_NAMESPACE(QWheelEvent)>() << QT_PREPEND_NAMESPACE(QWheelEvent)(QPointF(500.0f, 500.0f),
- 0,
- Qt::NoButton,
- Qt::NoModifier,
- Qt::Horizontal);
+ eventList = QList<QT_PREPEND_NAMESPACE(QWheelEvent)>()
+ << QT_PREPEND_NAMESPACE(QWheelEvent)(QPointF(500.0, 500.0),
+ QPointF(), QPoint(), QPoint(),
+ Qt::NoButton,
+ Qt::NoModifier,
+ Qt::NoScrollPhase,
+ false);
backendMouseDevice.updateWheelEvents(eventList);
// THEN
diff --git a/tests/auto/render/commons/testrenderer.cpp b/tests/auto/render/commons/testrenderer.cpp
index 5a36fecf2..6b6e2326e 100644
--- a/tests/auto/render/commons/testrenderer.cpp
+++ b/tests/auto/render/commons/testrenderer.cpp
@@ -38,7 +38,7 @@ TestRenderer::~TestRenderer()
void TestRenderer::markDirty(Qt3DRender::Render::AbstractRenderer::BackendNodeDirtySet changes, Qt3DRender::Render::BackendNode *node)
{
- Q_UNUSED(node);
+ Q_UNUSED(node)
m_changes |= changes;
}
@@ -67,7 +67,7 @@ QVariant TestRenderer::executeCommand(const QStringList &args)
void TestRenderer::setOffscreenSurfaceHelper(Qt3DRender::Render::OffscreenSurfaceHelper *helper)
{
- Q_UNUSED(helper);
+ Q_UNUSED(helper)
}
QSurfaceFormat TestRenderer::format()
diff --git a/tests/auto/render/gltfplugins/tst_gltfplugins.cpp b/tests/auto/render/gltfplugins/tst_gltfplugins.cpp
index 0de94a931..7f40fffcc 100644
--- a/tests/auto/render/gltfplugins/tst_gltfplugins.cpp
+++ b/tests/auto/render/gltfplugins/tst_gltfplugins.cpp
@@ -1131,20 +1131,16 @@ Qt3DCore::QEntity *tst_gltfPlugins::findCameraChild(Qt3DCore::QEntity *entity,
void tst_gltfPlugins::exportAndImport_data()
{
- QTest::addColumn<bool>("binaryJson");
QTest::addColumn<bool>("compactJson");
- QTest::newRow("No options") << false << false;
+ QTest::newRow("No options") << false;
#ifndef VISUAL_CHECK
- QTest::newRow("Binary json") << true << false;
- QTest::newRow("Compact json") << false << true;
- QTest::newRow("Binary/Compact json") << true << true; // Compact is ignored in this case
+ QTest::newRow("Compact json") << true;
#endif
}
void tst_gltfPlugins::exportAndImport()
{
- QFETCH(bool, binaryJson);
QFETCH(bool, compactJson);
createTestScene();
@@ -1164,7 +1160,6 @@ void tst_gltfPlugins::exportAndImport()
Qt3DRender::QSceneExportFactory::create(key, QStringList());
if (exporter != nullptr && key == QStringLiteral("gltfexport")) {
QVariantHash options;
- options.insert(QStringLiteral("binaryJson"), QVariant(binaryJson));
options.insert(QStringLiteral("compactJson"), QVariant(compactJson));
exporter->exportScene(m_sceneRoot1, exportDir, sceneName, options);
break;
diff --git a/tests/auto/render/opengl/renderviews/tst_renderviews.cpp b/tests/auto/render/opengl/renderviews/tst_renderviews.cpp
index 0b1e22909..6d01122d1 100644
--- a/tests/auto/render/opengl/renderviews/tst_renderviews.cpp
+++ b/tests/auto/render/opengl/renderviews/tst_renderviews.cpp
@@ -28,8 +28,6 @@
#include <QtTest/QTest>
#include <qbackendnodetester.h>
-#include <private/qframeallocator_p.h>
-#include <private/qframeallocator_p_p.h>
#include <private/memorybarrier_p.h>
#include <testpostmanarbiter.h>
#include <testrenderer.h>
diff --git a/tests/benchmarks/core/core.pro b/tests/benchmarks/core/core.pro
index 67710db78..50e447263 100644
--- a/tests/benchmarks/core/core.pro
+++ b/tests/benchmarks/core/core.pro
@@ -1,6 +1,4 @@
TEMPLATE = subdirs
SUBDIRS += \
- qcircularbuffer \
- qresourcesmanager \
- qframeallocator
+ qresourcesmanager
diff --git a/tests/benchmarks/core/qcircularbuffer/qcircularbuffer.pro b/tests/benchmarks/core/qcircularbuffer/qcircularbuffer.pro
deleted file mode 100644
index 4843a99a6..000000000
--- a/tests/benchmarks/core/qcircularbuffer/qcircularbuffer.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-TARGET = tst_bench_qcircularbuffer
-CONFIG += release
-TEMPLATE = app
-QT += testlib 3dcore 3dcore-private
-
-DEFINES += SRCDIR=\\\"$$PWD/\\\"
-
-SOURCES += tst_bench_qcircularbuffer.cpp
diff --git a/tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp b/tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp
deleted file mode 100644
index cac6e6d77..000000000
--- a/tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QObject>
-#include <QtTest/QtTest>
-
-#include <Qt3DCore/private/qcircularbuffer_p.h>
-
-using namespace Qt3DCore;
-
-class tst_QCircularBuffer : public QObject
-{
- Q_OBJECT
-private Q_SLOTS:
- void benchmarkAppend();
- void benchmarkAt();
-};
-
-void tst_QCircularBuffer::benchmarkAppend()
-{
- QCircularBuffer<float> c;
- c.setCapacity(100000);
- volatile int confuseTheOptimizer = 90000;
- QBENCHMARK {
- const int count = confuseTheOptimizer;
- for (int i = 0; i < count; i++) {
- c.append(float(i));
- }
- }
- const int count = confuseTheOptimizer;
- volatile float f;
- for (int i = 0; i < count; i++) {
- f = c.at(i);
- }
- Q_UNUSED(f);
-}
-
-void tst_QCircularBuffer::benchmarkAt()
-{
- QCircularBuffer<float> c;
- c.setCapacity(20000);
- volatile int confuseTheOptimizer = 90000;
- const int count = confuseTheOptimizer;
- for (int i = 0; i < count; i++) {
- c.append(float(i));
- }
- QCOMPARE(c.isLinearised(), false);
- QBENCHMARK {
- const int count = c.size();
- volatile float f;
- for (int i = 0; i < count; i++) {
- f = c.at(i);
- }
- Q_UNUSED(f);
- }
-}
-
-QTEST_APPLESS_MAIN(tst_QCircularBuffer)
-#include "tst_bench_qcircularbuffer.moc"
diff --git a/tests/benchmarks/core/qframeallocator/qframeallocator.pro b/tests/benchmarks/core/qframeallocator/qframeallocator.pro
deleted file mode 100644
index 4e360f64c..000000000
--- a/tests/benchmarks/core/qframeallocator/qframeallocator.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-TARGET = tst_bench_qframeallocator
-CONFIG += release
-TEMPLATE = app
-QT += testlib 3dcore 3dcore-private
-
-SOURCES += tst_bench_qframeallocator.cpp
diff --git a/tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp b/tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp
deleted file mode 100644
index d6aca6219..000000000
--- a/tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QObject>
-#include <QtTest/QtTest>
-
-#include <Qt3DCore/private/qframeallocator_p.h>
-
-using namespace Qt3DCore;
-
-class tst_QFrameAllocator : public QObject
-{
- Q_OBJECT
-
-private Q_SLOTS:
- void benchmarkAllocateSmall();
- void benchmarkAllocateBig();
- void benchmarkDeallocateSmall();
- void benchmarkDeallocateBig();
- void benchmarkAllocateRaw();
- void benchmarkDeallocateRaw();
-};
-
-namespace {
-template<uint Size>
-struct Object {
- char data[Size];
-};
-
-template<uint Size>
-void benchmarkAlloc()
-{
- QFrameAllocator allocator(128, 16, 128);
- QVector<Object<Size>*> items(10000);
- QBENCHMARK_ONCE {
- for (int i = 0; i < items.size(); ++i) {
- items[i] = allocator.allocate< Object<Size> >();
- }
- }
- for (Object<Size>* item : qAsConst(items)) {
- allocator.deallocate(item);
- }
-}
-
-template<uint Size>
-void benchmarkDealloc()
-{
- QFrameAllocator allocator(128, 16, 128);
- QVector<Object<Size>*> items(10000);
- for (int i = 0; i < items.size(); ++i) {
- items[i] = allocator.allocate< Object<Size> >();
- }
- QBENCHMARK_ONCE {
- for (Object<Size>* item : qAsConst(items)) {
- allocator.deallocate(item);
- }
- }
-}
-}
-
-void tst_QFrameAllocator::benchmarkAllocateSmall()
-{
- benchmarkAlloc<16>();
-}
-
-void tst_QFrameAllocator::benchmarkAllocateBig()
-{
- benchmarkAlloc<128>();
-}
-
-void tst_QFrameAllocator::benchmarkDeallocateSmall()
-{
- benchmarkDealloc<16>();
-}
-
-void tst_QFrameAllocator::benchmarkDeallocateBig()
-{
- benchmarkDealloc<128>();
-}
-
-void tst_QFrameAllocator::benchmarkAllocateRaw()
-{
- QFrameAllocator allocator(128, 16, 128);
- QVector<void*> items(10000);
- QBENCHMARK_ONCE {
- for (int i = 0; i < items.size(); ++i) {
- items[i] = allocator.allocateRawMemory(i % 128 + 1);
- }
- }
- for (int i = 0; i < items.size(); ++i) {
- allocator.deallocateRawMemory(items[i], i % 128 + 1);
- }
-}
-
-void tst_QFrameAllocator::benchmarkDeallocateRaw()
-{
- QFrameAllocator allocator(128, 16, 128);
- QVector<void*> items(10000);
- for (int i = 0; i < items.size(); ++i) {
- items[i] = allocator.allocateRawMemory(i % 128 + 1);
- }
- QBENCHMARK_ONCE {
- for (int i = 0; i < items.size(); ++i) {
- allocator.deallocateRawMemory(items[i], i % 128 + 1);
- }
- }
-}
-
-QTEST_APPLESS_MAIN(tst_QFrameAllocator)
-#include "tst_bench_qframeallocator.moc"
diff --git a/tools/qgltf/qgltf.cpp b/tools/qgltf/qgltf.cpp
index 91ecd5ba2..71cdb6b5e 100644
--- a/tools/qgltf/qgltf.cpp
+++ b/tools/qgltf/qgltf.cpp
@@ -216,9 +216,6 @@ static inline QVector<float> ai2qt(const aiMatrix4x4 &matrix)
struct Options {
QString outDir;
-#ifndef QT_BOOTSTRAPPED
- bool genBin;
-#endif
bool compact;
bool compress;
bool genTangents;
@@ -2453,17 +2450,6 @@ void GltfExporter::save(const QString &inputFilename)
QString gltfName = opts.outDir + basename + QStringLiteral(".qgltf");
f.setFileName(gltfName);
-#ifndef QT_BOOTSTRAPPED
- if (opts.showLog)
- qDebug().noquote() << (opts.genBin ? "Writing (binary JSON)" : "Writing") << gltfName;
-
- const QIODevice::OpenMode openMode = opts.genBin
- ? (QIODevice::WriteOnly | QIODevice::Truncate)
- : (QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
- const QByteArray json = opts.genBin
- ? m_doc.toBinaryData()
- : m_doc.toJson(opts.compact ? QJsonDocument::Compact : QJsonDocument::Indented);
-#else
if (opts.showLog)
qDebug().noquote() << "Writing" << gltfName;
@@ -2471,10 +2457,10 @@ void GltfExporter::save(const QString &inputFilename)
= QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text;
const QByteArray json
= m_doc.toJson(opts.compact ? QJsonDocument::Compact : QJsonDocument::Indented);
-#endif
if (f.open(openMode)) {
m_files.insert(QFileInfo(f.fileName()).fileName());
+ QByteArray json = m_doc.toJson(opts.compact ? QJsonDocument::Compact : QJsonDocument::Indented);
f.write(json);
f.close();
}
@@ -2545,9 +2531,6 @@ int main(int argc, char **argv)
cmdLine.addOption(silentOpt);
cmdLine.process(app);
opts.outDir = cmdLine.value(outDirOpt);
-#ifndef QT_BOOTSTRAPPED
- opts.genBin = cmdLine.isSet(binOpt);
-#endif
opts.compact = cmdLine.isSet(compactOpt);
opts.compress = cmdLine.isSet(compOpt);
opts.genTangents = cmdLine.isSet(tangentOpt);