/**************************************************************************** ** ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtCore module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** GNU Lesser General Public License Usage ** This file may be used under the terms of the GNU Lesser General Public ** License version 2.1 as published by the Free Software Foundation and ** appearing in the file LICENSE.LGPL included in the packaging of this ** file. Please review the following information to ensure the GNU Lesser ** General Public License version 2.1 requirements will be met: ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU General ** Public License version 3.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of this ** file. Please review the following information to ensure the GNU General ** Public License version 3.0 requirements will be met: ** http://www.gnu.org/copyleft/gpl.html. ** ** Other Usage ** Alternatively, this file may be used in accordance with the terms and ** conditions contained in a signed written agreement between you and Nokia. ** ** ** ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QARRAYDATAPOINTER_H #define QARRAYDATAPOINTER_H #include QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Core) template struct QArrayDataPointer { private: typedef QTypedArrayData Data; typedef QArrayDataOps DataOps; public: QArrayDataPointer() : d(Data::sharedNull()) { } QArrayDataPointer(const QArrayDataPointer &other) : d((other.d->ref.ref(), other.d)) { } explicit QArrayDataPointer(QTypedArrayData *ptr) : d(ptr) { } QArrayDataPointer &operator=(const QArrayDataPointer &other) { QArrayDataPointer tmp(other); this->swap(tmp); return *this; } DataOps &operator*() const { Q_ASSERT(d); return *static_cast(d); } DataOps *operator->() const { Q_ASSERT(d); return static_cast(d); } ~QArrayDataPointer() { if (!d->ref.deref()) { (*this)->destroyAll(); Data::deallocate(d); } } bool isNull() const { return d == Data::sharedNull(); } Data *data() const { return d; } void swap(QArrayDataPointer &other) { qSwap(d, other.d); } void clear() { QArrayDataPointer tmp(d); d = Data::sharedEmpty(); } private: Data *d; }; template inline bool operator==(const QArrayDataPointer &lhs, const QArrayDataPointer &rhs) { return lhs.data() == rhs.data(); } template inline bool operator!=(const QArrayDataPointer &lhs, const QArrayDataPointer &rhs) { return lhs.data() != rhs.data(); } template inline void qSwap(QArrayDataPointer &p1, QArrayDataPointer &p2) { p1.swap(p2); } QT_END_NAMESPACE namespace std { template inline void swap( QT_PREPEND_NAMESPACE(QArrayDataPointer) &p1, QT_PREPEND_NAMESPACE(QArrayDataPointer) &p2) { p1.swap(p2); } } QT_END_HEADER #endif // include guard