Enable use of QArrayDataPointer as a return type

This is done through a (POD) wrapper around a raw QTypedArrayData
pointer. The wrapper forces conscious decisions on the use of that
pointer, while implying it is internal API.

The pointed-to header is assumed to referenced, as if already owned by
the receiving QArrayDataPointer.

This wrapper is placed in the generic qarraydata.h header as its
definition doesn't depend on QArrayDataPointer by itself.

Change-Id: I9b2b6bb7dd9ab073dc7d882ccf999b32d793ed3f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
João Abecasis 2011-11-03 16:04:32 +01:00 committed by Qt by Nokia
parent d8ff456b4d
commit f218213a42
2 changed files with 12 additions and 0 deletions

View File

@ -177,6 +177,13 @@ struct QStaticArrayData
T data[N]; T data[N];
}; };
// Support for returning QArrayDataPointer<T> from functions
template <class T>
struct QArrayDataPointerRef
{
QTypedArrayData<T> *ptr;
};
#define Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(type, size) { \ #define Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(type, size) { \
Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, \ Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, \
(sizeof(QArrayData) + (Q_ALIGNOF(type) - 1)) \ (sizeof(QArrayData) + (Q_ALIGNOF(type) - 1)) \

View File

@ -76,6 +76,11 @@ public:
Q_CHECK_PTR(ptr); Q_CHECK_PTR(ptr);
} }
QArrayDataPointer(QArrayDataPointerRef<T> ref)
: d(ref.ptr)
{
}
QArrayDataPointer &operator=(const QArrayDataPointer &other) QArrayDataPointer &operator=(const QArrayDataPointer &other)
{ {
QArrayDataPointer tmp(other); QArrayDataPointer tmp(other);