summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydata.h
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2011-11-22 17:28:14 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-09 17:19:30 +0100
commitf1e48d48fd58b28b1dc18652af3fc74da5e112fd (patch)
tree41f355093999ea8dabf9c196afb4e0ad275ce547 /src/corelib/tools/qarraydata.h
parentd91b4f0b13926a0861d7e172f14437d20d06332e (diff)
Add AllocateOptions to QArrayData
This approach is better for future ABI evolution than using individual bool parameters. QArrayData now also offers to calculate allocate options for typical detach and clone operations: the CapacityReserved flag is preserved, while cloning resets the Unsharable state. Change-Id: I256e135adcf27a52a5c7d6130069c35c8b946bc3 Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'src/corelib/tools/qarraydata.h')
-rw-r--r--src/corelib/tools/qarraydata.h37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h
index 2486bebafa..8eb543ee51 100644
--- a/src/corelib/tools/qarraydata.h
+++ b/src/corelib/tools/qarraydata.h
@@ -73,14 +73,43 @@ struct Q_CORE_EXPORT QArrayData
return reinterpret_cast<const char *>(this) + offset;
}
+ enum AllocateOption {
+ CapacityReserved = 0x1,
+ Unsharable = 0x2,
+
+ Default = 0
+ };
+
+ Q_DECLARE_FLAGS(AllocateOptions, AllocateOption)
+
+ AllocateOptions detachFlags() const
+ {
+ AllocateOptions result;
+ if (!ref.isSharable())
+ result |= Unsharable;
+ if (capacityReserved)
+ result |= CapacityReserved;
+ return result;
+ }
+
+ AllocateOptions cloneFlags() const
+ {
+ AllocateOptions result;
+ if (capacityReserved)
+ result |= CapacityReserved;
+ return result;
+ }
+
static QArrayData *allocate(size_t objectSize, size_t alignment,
- size_t capacity, bool reserve, bool sharable) Q_REQUIRED_RESULT;
+ size_t capacity, AllocateOptions options = Default) Q_REQUIRED_RESULT;
static void deallocate(QArrayData *data, size_t objectSize,
size_t alignment);
static const QArrayData shared_null;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocateOptions)
+
template <class T>
struct QTypedArrayData
: QArrayData
@@ -98,11 +127,11 @@ struct QTypedArrayData
class AlignmentDummy { QArrayData header; T data; };
- static QTypedArrayData *allocate(size_t capacity, bool reserve = false,
- bool sharable = true) Q_REQUIRED_RESULT
+ static QTypedArrayData *allocate(size_t capacity,
+ AllocateOptions options = Default) Q_REQUIRED_RESULT
{
return static_cast<QTypedArrayData *>(QArrayData::allocate(sizeof(T),
- Q_ALIGNOF(AlignmentDummy), capacity, reserve, sharable));
+ Q_ALIGNOF(AlignmentDummy), capacity, options));
}
static void deallocate(QArrayData *data)