summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbitarray.cpp7
-rw-r--r--src/corelib/tools/qbitarray.h2
-rw-r--r--src/corelib/tools/qbytearray.cpp17
-rw-r--r--src/corelib/tools/qbytearray.h2
-rw-r--r--src/corelib/tools/qcontiguouscache.cpp7
-rw-r--r--src/corelib/tools/qcontiguouscache.h1
-rw-r--r--src/corelib/tools/qhash.cpp14
-rw-r--r--src/corelib/tools/qhash.h2
-rw-r--r--src/corelib/tools/qlinkedlist.cpp7
-rw-r--r--src/corelib/tools/qlinkedlist.h1
-rw-r--r--src/corelib/tools/qlist.cpp7
-rw-r--r--src/corelib/tools/qlist.h1
-rw-r--r--src/corelib/tools/qlocale.cpp1
-rw-r--r--src/corelib/tools/qlocale.h2
-rw-r--r--src/corelib/tools/qmap.cpp14
-rw-r--r--src/corelib/tools/qmap.h2
-rw-r--r--src/corelib/tools/qpoint.cpp6
-rw-r--r--src/corelib/tools/qqueue.cpp8
-rw-r--r--src/corelib/tools/qqueue.h1
-rw-r--r--src/corelib/tools/qregexp.cpp8
-rw-r--r--src/corelib/tools/qregexp.h1
-rw-r--r--src/corelib/tools/qscopedpointer.h12
-rw-r--r--src/corelib/tools/qset.h1
-rw-r--r--src/corelib/tools/qset.qdoc7
-rw-r--r--src/corelib/tools/qshareddata.h14
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h10
-rw-r--r--src/corelib/tools/qsize.cpp6
-rw-r--r--src/corelib/tools/qstack.cpp8
-rw-r--r--src/corelib/tools/qstack.h1
-rw-r--r--src/corelib/tools/qstring.cpp7
-rw-r--r--src/corelib/tools/qstring.h1
-rw-r--r--src/corelib/tools/qvarlengtharray.h124
-rw-r--r--src/corelib/tools/qvarlengtharray.qdoc208
-rw-r--r--src/corelib/tools/qvector.cpp7
-rw-r--r--src/corelib/tools/qvector.h7
35 files changed, 518 insertions, 6 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp
index 04018ba20f..a1ad787e09 100644
--- a/src/corelib/tools/qbitarray.cpp
+++ b/src/corelib/tools/qbitarray.cpp
@@ -418,6 +418,13 @@ void QBitArray::fill(bool value, int begin, int end)
this bit array.
*/
+/*! \fn void QBitArray::swap(QBitArray &other)
+ \since 4.8
+
+ Swaps bit array \a other with this bit array. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QBitArray::operator==(const QBitArray &other) const
Returns true if \a other is equal to this bit array; otherwise
diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h
index bd79904ec6..ddda5e7af0 100644
--- a/src/corelib/tools/qbitarray.h
+++ b/src/corelib/tools/qbitarray.h
@@ -68,6 +68,8 @@ public:
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QBitArray &other) { qSwap(d, other.d); }
+
inline int size() const { return (d.size() << 3) - *d.constData(); }
inline int count() const { return (d.size() << 3) - *d.constData(); }
int count(bool on) const;
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 6ba9fd3e75..f26d8783f6 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -541,6 +541,11 @@ QByteArray qUncompress(const uchar* data, int nbytes)
forever {
ulong alloc = len;
+ if (len >= (1 << 31) - sizeof(QByteArray::Data)) {
+ //QByteArray does not support that huge size anyway.
+ qWarning("qUncompress: Input data is corrupted");
+ return QByteArray();
+ }
QByteArray::Data *p = static_cast<QByteArray::Data *>(qRealloc(d.data(), sizeof(QByteArray::Data) + alloc));
if (!p) {
// we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS
@@ -556,6 +561,11 @@ QByteArray qUncompress(const uchar* data, int nbytes)
switch (res) {
case Z_OK:
if (len != alloc) {
+ if (len >= (1 << 31) - sizeof(QByteArray::Data)) {
+ //QByteArray does not support that huge size anyway.
+ qWarning("qUncompress: Input data is corrupted");
+ return QByteArray();
+ }
QByteArray::Data *p = static_cast<QByteArray::Data *>(qRealloc(d.data(), sizeof(QByteArray::Data) + len));
if (!p) {
// we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS
@@ -904,6 +914,13 @@ QByteArray &QByteArray::operator=(const char *str)
return *this;
}
+/*! \fn void QByteArray::swap(QByteArray &other)
+ \since 4.8
+
+ Swaps byte array \a other with this byte array. This operation is very
+ fast and never fails.
+*/
+
/*! \fn int QByteArray::size() const
Returns the number of bytes in this byte array.
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index 3cdcaabd4e..b625f4c5e2 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -149,6 +149,8 @@ public:
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QByteArray &other) { qSwap(d, other.d); }
+
inline int size() const;
bool isEmpty() const;
void resize(int size);
diff --git a/src/corelib/tools/qcontiguouscache.cpp b/src/corelib/tools/qcontiguouscache.cpp
index 3ba5186af9..7880bd3a3d 100644
--- a/src/corelib/tools/qcontiguouscache.cpp
+++ b/src/corelib/tools/qcontiguouscache.cpp
@@ -194,6 +194,13 @@ MyRecord record(int row) const
Assigns \a other to this cache and returns a reference to this cache.
*/
+/*! \fn void QContiguousCache::swap(QContiguousCache<T> &other)
+ \since 4.8
+
+ Swaps cache \a other with this cache. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QContiguousCache::operator==(const QContiguousCache<T> &other) const
Returns true if \a other is equal to this cache; otherwise returns false.
diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h
index 4c1a846633..3d0a1593b5 100644
--- a/src/corelib/tools/qcontiguouscache.h
+++ b/src/corelib/tools/qcontiguouscache.h
@@ -114,6 +114,7 @@ public:
inline QContiguousCache<T> &operator=(QContiguousCache<T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QContiguousCache<T> &other) { qSwap(d, other.d); }
bool operator==(const QContiguousCache<T> &other) const;
inline bool operator!=(const QContiguousCache<T> &other) const { return !(*this == other); }
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 2971c063c1..3dc9c92fff 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -730,6 +730,20 @@ void QHashData::checkSanity()
Assigns \a other to this hash and returns a reference to this hash.
*/
+/*! \fn void QHash::swap(QHash<Key, T> &other)
+ \since 4.8
+
+ Swaps hash \a other with this hash. This operation is very
+ fast and never fails.
+*/
+
+/*! \fn void QMultiHash::swap(QMultiHash<Key, T> &other)
+ \since 4.8
+
+ Swaps hash \a other with this hash. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QHash::operator==(const QHash<Key, T> &other) const
Returns true if \a other is equal to this hash; otherwise returns
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 992ff33b94..21fca2dd05 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -287,6 +287,7 @@ public:
inline QHash<Key, T> &operator=(QHash<Key, T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QHash<Key, T> &other) { qSwap(d, other.d); }
bool operator==(const QHash<Key, T> &other) const;
inline bool operator!=(const QHash<Key, T> &other) const { return !(*this == other); }
@@ -925,6 +926,7 @@ class QMultiHash : public QHash<Key, T>
public:
QMultiHash() {}
QMultiHash(const QHash<Key, T> &other) : QHash<Key, T>(other) {}
+ inline void swap(QMultiHash<Key, T> &other) { QHash<Key, T>::swap(other); } // prevent QMultiHash<->QHash swaps
inline typename QHash<Key, T>::iterator replace(const Key &key, const T &value)
{ return QHash<Key, T>::insert(key, value); }
diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp
index 7213c6ef31..7b452fc1b8 100644
--- a/src/corelib/tools/qlinkedlist.cpp
+++ b/src/corelib/tools/qlinkedlist.cpp
@@ -147,6 +147,13 @@ QLinkedListData QLinkedListData::shared_null = {
list.
*/
+/*! \fn void QLinkedList::swap(QLinkedList<T> &other)
+ \since 4.8
+
+ Swaps list \a other with this list. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QLinkedList::operator==(const QLinkedList<T> &other) const
Returns true if \a other is equal to this list; otherwise returns
diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h
index c0879441fd..849bfd3a52 100644
--- a/src/corelib/tools/qlinkedlist.h
+++ b/src/corelib/tools/qlinkedlist.h
@@ -89,6 +89,7 @@ public:
inline QLinkedList<T> &operator=(QLinkedList<T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QLinkedList<T> &other) { qSwap(d, other.d); }
bool operator==(const QLinkedList<T> &l) const;
inline bool operator!=(const QLinkedList<T> &l) const { return !(*this == l); }
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index 9ba3768acb..5706171130 100644
--- a/src/corelib/tools/qlist.cpp
+++ b/src/corelib/tools/qlist.cpp
@@ -602,6 +602,13 @@ void **QListData::erase(void **xi)
list.
*/
+/*! \fn void QList::swap(QList<T> &other)
+ \since 4.8
+
+ Swaps list \a other with this list. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QList::operator==(const QList<T> &other) const
Returns true if \a other is equal to this list; otherwise returns
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 8f988d60a2..b1fcabfa8c 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -126,6 +126,7 @@ public:
inline QList &operator=(QList &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QList<T> &other) { qSwap(d, other.d); }
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QList(std::initializer_list<T> args) : d(&QListData::shared_null)
{ d->ref.ref(); qCopy(args.begin(), args.end(), std::back_inserter(*this)); }
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 6b1de5ef0e..2fb3616223 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -7308,6 +7308,7 @@ Q_CORE_EXPORT char *qdtoa( double d, int mode, int ndigits, int *decpt, int *sig
Q_CORE_EXPORT double qstrtod(const char *s00, const char **se, bool *ok)
{
+ errno = 0;
double ret = strtod((char*)s00, (char**)se);
if (ok) {
if((ret == 0.0l && errno == ERANGE)
diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h
index 8b424bbc3a..1af2cb476a 100644
--- a/src/corelib/tools/qlocale.h
+++ b/src/corelib/tools/qlocale.h
@@ -114,7 +114,7 @@ class Q_CORE_EXPORT QLocale
friend class QString;
friend class QByteArray;
friend class QIntValidator;
- friend class QDoubleValidator;
+ friend class QDoubleValidatorPrivate;
friend class QTextStream;
friend class QTextStreamPrivate;
diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp
index 3143ee4081..5a5fffde8a 100644
--- a/src/corelib/tools/qmap.cpp
+++ b/src/corelib/tools/qmap.cpp
@@ -404,6 +404,20 @@ void QMapData::dump()
Assigns \a other to this map and returns a reference to this map.
*/
+/*! \fn void QMap::swap(QMap<Key, T> &other)
+ \since 4.8
+
+ Swaps map \a other with this map. This operation is very
+ fast and never fails.
+*/
+
+/*! \fn void QMultiMap::swap(QMultiMap<Key, T> &other)
+ \since 4.8
+
+ Swaps map \a other with this map. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QMap::operator==(const QMap<Key, T> &other) const
Returns true if \a other is equal to this map; otherwise returns
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h
index ce8fd75f7a..2897529463 100644
--- a/src/corelib/tools/qmap.h
+++ b/src/corelib/tools/qmap.h
@@ -189,6 +189,7 @@ public:
inline QMap<Key, T> &operator=(QMap<Key, T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QMap<Key, T> &other) { qSwap(d, other.d); }
#ifndef QT_NO_STL
explicit QMap(const typename std::map<Key, T> &other);
std::map<Key, T> toStdMap() const;
@@ -973,6 +974,7 @@ class QMultiMap : public QMap<Key, T>
public:
QMultiMap() {}
QMultiMap(const QMap<Key, T> &other) : QMap<Key, T>(other) {}
+ inline void swap(QMultiMap<Key, T> &other) { QMap<Key, T>::swap(other); }
inline typename QMap<Key, T>::iterator replace(const Key &key, const T &value)
{ return QMap<Key, T>::insert(key, value); }
diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp
index 66f06e9ccd..c297709ee5 100644
--- a/src/corelib/tools/qpoint.cpp
+++ b/src/corelib/tools/qpoint.cpp
@@ -438,8 +438,12 @@ QDebug operator<<(QDebug d, const QPointF &p)
/*!
\fn bool QPointF::isNull() const
- Returns true if both the x and y coordinates are set to 0.0,
+ Returns true if both the x and y coordinates are set to +0.0;
otherwise returns false.
+
+ \note Since this function treats +0.0 and -0.0 differently, points
+ with zero-valued coordinates where either or both values have a
+ negative sign are not defined to be null points.
*/
diff --git a/src/corelib/tools/qqueue.cpp b/src/corelib/tools/qqueue.cpp
index 849bb0b473..36026956b2 100644
--- a/src/corelib/tools/qqueue.cpp
+++ b/src/corelib/tools/qqueue.cpp
@@ -91,6 +91,14 @@
*/
/*!
+ \fn void QQueue::swap(QQueue<T> &other)
+ \since 4.8
+
+ Swaps queue \a other with this queue. This operation is very
+ fast and never fails.
+*/
+
+/*!
\fn void QQueue::enqueue(const T& t)
Adds value \a t to the tail of the queue.
diff --git a/src/corelib/tools/qqueue.h b/src/corelib/tools/qqueue.h
index c29134b6f1..4ef1a61023 100644
--- a/src/corelib/tools/qqueue.h
+++ b/src/corelib/tools/qqueue.h
@@ -56,6 +56,7 @@ class QQueue : public QList<T>
public:
inline QQueue() {}
inline ~QQueue() {}
+ inline void swap(QQueue<T> &other) { QList<T>::swap(other); } // prevent QList<->QQueue swaps
inline void enqueue(const T &t) { QList<T>::append(t); }
inline T dequeue() { return QList<T>::takeFirst(); }
inline T &head() { return QList<T>::first(); }
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp
index 7a26c4f364..5d2a0e3954 100644
--- a/src/corelib/tools/qregexp.cpp
+++ b/src/corelib/tools/qregexp.cpp
@@ -3858,6 +3858,14 @@ QRegExp &QRegExp::operator=(const QRegExp &rx)
}
/*!
+ \fn void QRegExp::swap(QRegExp &other)
+ \since 4.8
+
+ Swaps regular expression \a other with this regular
+ expression. This operation is very fast and never fails.
+*/
+
+/*!
Returns true if this regular expression is equal to \a rx;
otherwise returns false.
diff --git a/src/corelib/tools/qregexp.h b/src/corelib/tools/qregexp.h
index 0b4a702c62..4a74f90dbc 100644
--- a/src/corelib/tools/qregexp.h
+++ b/src/corelib/tools/qregexp.h
@@ -80,6 +80,7 @@ public:
inline QRegExp &operator=(QRegExp &&other)
{ qSwap(priv,other.priv); return *this; }
#endif
+ inline void swap(QRegExp &other) { qSwap(priv, other.priv); }
bool operator==(const QRegExp &rx) const;
inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h
index 40d3851f5d..b3a6db6fe4 100644
--- a/src/corelib/tools/qscopedpointer.h
+++ b/src/corelib/tools/qscopedpointer.h
@@ -186,6 +186,18 @@ template <class T, class Cleanup>
Q_INLINE_TEMPLATE void qSwap(QScopedPointer<T, Cleanup> &p1, QScopedPointer<T, Cleanup> &p2)
{ p1.swap(p2); }
+#ifndef QT_NO_STL
+QT_END_NAMESPACE
+namespace std {
+ template <class T, class Cleanup>
+ Q_INLINE_TEMPLATE void swap(QT_PREPEND_NAMESPACE(QScopedPointer)<T, Cleanup> &p1, QT_PREPEND_NAMESPACE(QScopedPointer)<T, Cleanup> &p2)
+ { p1.swap(p2); }
+}
+QT_BEGIN_NAMESPACE
+#endif
+
+
+
namespace QtPrivate {
template <typename X, typename Y> struct QScopedArrayEnsureSameType;
template <typename X> struct QScopedArrayEnsureSameType<X,X> { typedef X* Type; };
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h
index dc3c45a046..472078f8dc 100644
--- a/src/corelib/tools/qset.h
+++ b/src/corelib/tools/qset.h
@@ -65,6 +65,7 @@ public:
inline QSet<T> &operator=(QSet<T> &&other)
{ qSwap(q_hash, other.q_hash); return *this; }
#endif
+ inline void swap(QSet<T> &other) { q_hash.swap(other.q_hash); }
inline bool operator==(const QSet<T> &other) const
{ return q_hash == other.q_hash; }
diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc
index 0bc2d2d68a..57368f04c3 100644
--- a/src/corelib/tools/qset.qdoc
+++ b/src/corelib/tools/qset.qdoc
@@ -123,6 +123,13 @@
*/
/*!
+ \fn void QSet::swap(QSet<T> &other)
+
+ Swaps set \a other with this set. This operation is very fast and
+ never fails.
+*/
+
+/*!
\fn bool QSet::operator==(const QSet<T> &other) const
Returns true if the \a other set is equal to this set; otherwise
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h
index b646a9d3ce..45456feb54 100644
--- a/src/corelib/tools/qshareddata.h
+++ b/src/corelib/tools/qshareddata.h
@@ -263,6 +263,20 @@ template <class T>
Q_INLINE_TEMPLATE void qSwap(QExplicitlySharedDataPointer<T> &p1, QExplicitlySharedDataPointer<T> &p2)
{ p1.swap(p2); }
+#ifndef QT_NO_STL
+QT_END_NAMESPACE
+namespace std {
+ template <class T>
+ Q_INLINE_TEMPLATE void swap(QT_PREPEND_NAMESPACE(QSharedDataPointer)<T> &p1, QT_PREPEND_NAMESPACE(QSharedDataPointer)<T> &p2)
+ { p1.swap(p2); }
+
+ template <class T>
+ Q_INLINE_TEMPLATE void swap(QT_PREPEND_NAMESPACE(QExplicitlySharedDataPointer)<T> &p1, QT_PREPEND_NAMESPACE(QExplicitlySharedDataPointer)<T> &p2)
+ { p1.swap(p2); }
+}
+QT_BEGIN_NAMESPACE
+#endif
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 4b477133e3..ef8c454f2a 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -784,6 +784,16 @@ inline void qSwap(QSharedPointer<T> &p1, QSharedPointer<T> &p2)
p1.swap(p2);
}
+#ifndef QT_NO_STL
+QT_END_NAMESPACE
+namespace std {
+ template <class T>
+ inline void swap(QT_PREPEND_NAMESPACE(QSharedPointer)<T> &p1, QT_PREPEND_NAMESPACE(QSharedPointer)<T> &p2)
+ { p1.swap(p2); }
+}
+QT_BEGIN_NAMESPACE
+#endif
+
namespace QtSharedPointer {
// helper functions:
template <class X, class T>
diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp
index 20ac344b39..12287abf5c 100644
--- a/src/corelib/tools/qsize.cpp
+++ b/src/corelib/tools/qsize.cpp
@@ -492,9 +492,13 @@ QDebug operator<<(QDebug dbg, const QSize &s) {
/*!
\fn bool QSizeF::isNull() const
- Returns true if both the width and height is 0; otherwise returns
+ Returns true if both the width and height are +0.0; otherwise returns
false.
+ \note Since this function treats +0.0 and -0.0 differently, sizes with
+ zero width and height where either or both values have a negative
+ sign are not defined to be null sizes.
+
\sa isValid(), isEmpty()
*/
diff --git a/src/corelib/tools/qstack.cpp b/src/corelib/tools/qstack.cpp
index fa149006e6..b42fe3bc3a 100644
--- a/src/corelib/tools/qstack.cpp
+++ b/src/corelib/tools/qstack.cpp
@@ -91,6 +91,14 @@
*/
/*!
+ \fn void QStack::swap(QStack<T> &other)
+ \since 4.8
+
+ Swaps stack \a other with this stack. This operation is very fast and
+ never fails.
+*/
+
+/*!
\fn void QStack::push(const T& t)
Adds element \a t to the top of the stack.
diff --git a/src/corelib/tools/qstack.h b/src/corelib/tools/qstack.h
index 526c7051eb..6ddc38119b 100644
--- a/src/corelib/tools/qstack.h
+++ b/src/corelib/tools/qstack.h
@@ -56,6 +56,7 @@ class QStack : public QVector<T>
public:
inline QStack() {}
inline ~QStack() {}
+ inline void swap(QStack<T> &other) { QVector<T>::swap(other); } // prevent QVector<->QStack swaps
inline void push(const T &t) { QVector<T>::append(t); }
T pop();
T &top();
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 2737574ec2..a3d89f226a 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -1174,6 +1174,13 @@ QString::QString(QChar ch)
*/
+/*! \fn void QString::swap(QString &other)
+ \since 4.8
+
+ Swaps string \a other with this string. This operation is very fast and
+ never fails.
+*/
+
/*! \fn void QString::detach()
\internal
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 589fdc2d20..07f43ca2c8 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -108,6 +108,7 @@ public:
inline QString &operator=(QString &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QString &other) { qSwap(d, other.d); }
inline int size() const { return d->size; }
inline int count() const { return d->size; }
inline int length() const;
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 4a6bb4b802..38823239a0 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -44,7 +44,10 @@
#include <QtCore/qcontainerfwd.h>
#include <QtCore/qglobal.h>
+#include <QtCore/qalgorithms.h>
+
#include <new>
+#include <string.h>
QT_BEGIN_HEADER
@@ -123,6 +126,18 @@ public:
}
}
void append(const T *buf, int size);
+ inline QVarLengthArray<T, Prealloc> &operator<<(const T &t)
+ { append(t); return *this; }
+ inline QVarLengthArray<T, Prealloc> &operator+=(const T &t)
+ { append(t); return *this; }
+
+ void prepend(const T &t);
+ void insert(int i, const T &t);
+ void insert(int i, int n, const T &t);
+ void replace(int i, const T &t);
+ void remove(int i);
+ void remove(int i, int n);
+
inline T *data() { return ptr; }
inline const T *data() const { return ptr; }
@@ -135,6 +150,21 @@ public:
typedef const value_type &const_reference;
typedef qptrdiff difference_type;
+
+ typedef T* iterator;
+ typedef const T* const_iterator;
+
+ inline iterator begin() { return ptr; }
+ inline const_iterator begin() const { return ptr; }
+ inline const_iterator constBegin() const { return ptr; }
+ inline iterator end() { return ptr + s; }
+ inline const_iterator end() const { return ptr + s; }
+ inline const_iterator constEnd() const { return ptr + s; }
+ iterator insert(iterator before, int n, const T &x);
+ inline iterator insert(iterator before, const T &x) { return insert(before, 1, x); }
+ iterator erase(iterator begin, iterator end);
+ inline iterator erase(iterator pos) { return erase(pos, pos+1); }
+
private:
friend class QPodList<T, Prealloc>;
void realloc(int size, int alloc);
@@ -272,6 +302,100 @@ Q_OUTOFLINE_TEMPLATE T QVarLengthArray<T, Prealloc>::value(int i, const T &defau
return (i < 0 || i >= size()) ? defaultValue : at(i);
}
+template <class T, int Prealloc>
+inline void QVarLengthArray<T, Prealloc>::insert(int i, const T &t)
+{ Q_ASSERT_X(i >= 0 && i <= s, "QVarLengthArray::insert", "index out of range");
+ insert(begin() + i, 1, t); }
+template <class T, int Prealloc>
+inline void QVarLengthArray<T, Prealloc>::insert(int i, int n, const T &t)
+{ Q_ASSERT_X(i >= 0 && i <= s, "QVarLengthArray::insert", "index out of range");
+ insert(begin() + i, n, t); }
+template <class T, int Prealloc>
+inline void QVarLengthArray<T, Prealloc>::remove(int i, int n)
+{ Q_ASSERT_X(i >= 0 && n >= 0 && i + n <= s, "QVarLengthArray::remove", "index out of range");
+ erase(begin() + i, begin() + i + n); }
+template <class T, int Prealloc>
+inline void QVarLengthArray<T, Prealloc>::remove(int i)
+{ Q_ASSERT_X(i >= 0 && i < s, "QVarLengthArray::remove", "index out of range");
+ erase(begin() + i, begin() + i + 1); }
+template <class T, int Prealloc>
+inline void QVarLengthArray<T, Prealloc>::prepend(const T &t)
+{ insert(begin(), 1, t); }
+
+template <class T, int Prealloc>
+inline void QVarLengthArray<T, Prealloc>::replace(int i, const T &t)
+{
+ Q_ASSERT_X(i >= 0 && i < s, "QVarLengthArray::replace", "index out of range");
+ const T copy(t);
+ data()[i] = copy;
+}
+
+
+template <class T, int Prealloc>
+Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(iterator before, size_type n, const T &t)
+{
+ int offset = int(before - ptr);
+ if (n != 0) {
+ resize(s + n);
+ const T copy(t);
+ if (QTypeInfo<T>::isStatic) {
+ T *b = ptr + offset;
+ T *j = ptr + s;
+ T *i = j - n;
+ while (i != b)
+ *--j = *--i;
+ i = b + n;
+ while (i != b)
+ *--i = copy;
+ } else {
+ T *b = ptr + offset;
+ T *i = b + n;
+ memmove(i, b, (s - offset - n) * sizeof(T));
+ while (i != b)
+ new (--i) T(copy);
+ }
+ }
+ return ptr + offset;
+}
+
+template <class T, int Prealloc>
+Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::erase(iterator abegin, iterator aend)
+{
+ int f = int(abegin - ptr);
+ int l = int(aend - ptr);
+ int n = l - f;
+ if (QTypeInfo<T>::isComplex) {
+ qCopy(ptr + l, ptr + s, ptr + f);
+ T *i = ptr + s;
+ T *b = ptr + s - n;
+ while (i != b) {
+ --i;
+ i->~T();
+ }
+ } else {
+ memmove(ptr + f, ptr + l, (s - l) * sizeof(T));
+ }
+ s -= n;
+ return ptr + f;
+}
+
+template <typename T, int Prealloc1, int Prealloc2>
+bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
+{
+ if (l.size() != r.size())
+ return false;
+ for (int i = 0; i < l.size(); i++) {
+ if (l.at(i) != r.at(i))
+ return false;
+ }
+ return true;
+}
+
+template <typename T, int Prealloc1, int Prealloc2>
+bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
+{
+ return !(l == r);
+}
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc
index 6f91bccd0d..4d5d5d1412 100644
--- a/src/corelib/tools/qvarlengtharray.qdoc
+++ b/src/corelib/tools/qvarlengtharray.qdoc
@@ -337,3 +337,211 @@
Typedef for const T &. Provided for STL compatibility.
*/
+/*! \fn void QVarLengthArray::prepend(const T &value)
+
+ \since 4.8
+ Inserts \a value at the beginning of the array.
+
+
+ This is the same as vector.insert(0, \a value).
+
+ For large arrays, this operation can be slow (\l{linear time}),
+ because it requires moving all the items in the vector by one
+ position further in memory. If you want a container class that
+ provides a fast prepend() function, use QList or QLinkedList
+ instead.
+
+ \sa append(), insert()
+*/
+
+/*! \fn void QVarLengthArray::replace(int i, const T &value)
+
+ \since 4.8
+ Replaces the item at index position \a i with \a value.
+
+ \a i must be a valid index position in the array (i.e., 0 <= \a
+ i < size()).
+
+ \sa operator[](), remove()
+*/
+
+/*! \fn void QVarLengthArray::remove(int i)
+
+ \overload
+ \since 4.8
+
+ Removes the element at index position \a i.
+
+ \sa insert(), replace()
+*/
+
+/*! \fn void QVarLengthArray::remove(int i, int count)
+
+ \overload
+ \since 4.8
+
+ Removes \a count elements from the middle of the array, starting at
+ index position \a i.
+
+ \sa insert(), replace()
+*/
+
+/*! \fn QVarLengthArray::iterator QVarLengthArray::begin()
+ \since 4.8
+
+ Returns an \l{STL-style iterator} pointing to the first item in
+ the array.
+
+ \sa constBegin(), end()
+*/
+
+/*! \fn QVarLengthArray::const_iterator QVarLengthArray::begin() const
+ \since 4.8
+ \overload
+*/
+
+/*! \fn QVarLengthArray::const_iterator QVarLengthArray::constBegin() const
+ \since 4.8
+
+ Returns a const \l{STL-style iterator} pointing to the first item
+ in the array.
+
+ \sa begin(), constEnd()
+*/
+
+/*! \fn QVarLengthArray::iterator QVarLengthArray::end()
+ \since 4.8
+
+ Returns an \l{STL-style iterator} pointing to the imaginary item
+ after the last item in the array.
+
+ \sa begin(), constEnd()
+*/
+
+/*! \fn QVarLengthArray::const_iterator QVarLengthArray::end() const
+ \since 4.8
+
+ \overload
+*/
+
+/*! \fn QVarLengthArray::const_iterator QVarLengthArray::constEnd() const
+ \since 4.8
+
+ Returns a const \l{STL-style iterator} pointing to the imaginary
+ item after the last item in the array.
+
+ \sa constBegin(), end()
+*/
+
+/*! \fn QVarLengthArray::iterator QVarLengthArray::erase(iterator pos)
+ \since 4.8
+
+ Removes the item pointed to by the iterator \a pos from the
+ vector, and returns an iterator to the next item in the vector
+ (which may be end()).
+
+ \sa insert(), remove()
+*/
+
+/*! \fn QVarLengthArray::iterator QVarLengthArray::erase(iterator begin, iterator end)
+
+ \overload
+ \since 4.8
+
+ 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 QVarLengthArray::insert(int i, const T &value)
+ \since 4.8
+
+ Inserts \a value at index position \a i in the array. If \a i is
+ 0, the value is prepended to the vector. If \a i is size(), the
+ value is appended to the vector.
+
+ For large arrays, this operation can be slow (\l{linear time}),
+ because it requires moving all the items at indexes \a i and
+ above by one position further in memory. If you want a container
+ class that provides a fast insert() function, use QLinkedList
+ instead.
+
+ \sa remove()
+*/
+
+/*! \fn void QVarLengthArray::insert(int i, int count, const T &value)
+
+ \overload
+ \since 4.8
+
+ Inserts \a count copies of \a value at index position \a i in the
+ vector.
+*/
+
+/*! \fn QVarLengthArray::iterator QVarLengthArray::insert(iterator before, const T &value)
+
+ \overload
+ \since 4.8
+
+ Inserts \a value in front of the item pointed to by the iterator
+ \a before. Returns an iterator pointing at the inserted item.
+*/
+
+/*! \fn QVarLengthArray::iterator QVarLengthArray::insert(iterator before, int count, const T &value)
+
+ \since 4.8
+ Inserts \a count copies of \a value in front of the item pointed to
+ by the iterator \a before. Returns an iterator pointing at the
+ first of the inserted items.
+*/
+
+
+
+/*! \fn bool operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
+
+ \relates QVarLengthArray
+ \since 4.8
+ Returns true if the two array are equal;
+
+ Two arrays are considered equal if they contain the same values
+ in the same order.
+
+ This function requires the value type to have an implementation
+ of \c operator==().
+
+ \sa operator!=()
+*/
+
+/*! \fn bool operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
+
+ \relates QVarLengthArray
+ \since 4.8
+ Returns true if the two array are different;
+
+ Two arrays are considered equal if they contain the same values
+ in the same order.
+
+ This function requires the value type to have an implementation
+ of \c operator==().
+
+ \sa operator==()
+*/
+
+/*! \fn QVarLengthArray &QVarLengthArray::operator<<(const T &value)
+
+ \since 4.8
+ Appends \a value to the array and returns a reference to this
+ vector.
+
+ \sa append(), operator+=()
+*/
+
+/*! \fn QVarLengthArray &QVarLengthArray::operator+=(const T &value)
+
+ \since 4.8
+ Appends \a value to the array and returns a reference to this
+ vector.
+
+ \sa append(), operator<<()
+*/
+
diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp
index 3a13540766..0497211690 100644
--- a/src/corelib/tools/qvector.cpp
+++ b/src/corelib/tools/qvector.cpp
@@ -285,6 +285,13 @@ int QVectorData::grow(int sizeofTypedData, int size, int sizeofT, bool excessive
vector.
*/
+/*! \fn void QVector::swap(QVector<T> &other)
+ \since 4.8
+
+ Swaps vector \a other with this vector. This operation is very fast and
+ never fails.
+*/
+
/*! \fn bool QVector::operator==(const QVector<T> &other) const
Returns true if \a other is equal to this vector; otherwise
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index c16aefb2ef..0f7db88c90 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -125,6 +125,7 @@ public:
inline QVector<T> operator=(QVector<T> &&other)
{ qSwap(p, other.p); return *this; }
#endif
+ inline void swap(QVector<T> &other) { qSwap(d, other.d); }
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QVector(std::initializer_list<T> args);
#endif
@@ -303,7 +304,7 @@ public:
#ifndef QT_NO_STL
static inline QVector<T> fromStdVector(const std::vector<T> &vector)
- { QVector<T> tmp; tmp.reserve(vector.size()); qCopy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; }
+ { QVector<T> tmp; tmp.reserve(int(vector.size())); qCopy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; }
inline std::vector<T> toStdVector() const
{ std::vector<T> tmp; tmp.reserve(size()); qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }
#endif
@@ -439,9 +440,9 @@ QVector<T>::QVector(int asize, const T &t)
template <typename T>
QVector<T>::QVector(std::initializer_list<T> args)
{
- d = malloc(args.size());
+ d = malloc(int(args.size()));
d->ref = 1;
- d->alloc = d->size = args.size();
+ d->alloc = d->size = int(args.size());
d->sharable = true;
d->capacity = false;
T* i = p->array + d->size;