I end up creating my own shared array using QVector
template <typename Type>
class QfwSharedArray
{
public:
QfwSharedArray() : d( new QfwSharedArrayData ) {
}
QfwSharedArray( const QVector<Type>& array ) : d( new QfwSharedArrayData ) {
setArray( array );
}
QfwSharedArray( const QfwSharedArray& org ) : d( org.d ) {
}
~QfwSharedArray() {
}
QfwSharedArray& operator=( const QfwSharedArray& rhs ) {
d = rhs.d;
return *this;
}
bool operator==( const QfwSharedArray& rhs ) const {
return d == rhs.d;
}
bool operator!=( const QfwSharedArray& rhs ) const {
return !operator==( rhs );
}
const QVector<Type>& array() const {
return d->array;
}
QVector<Type>& array() {
return d->array;
}
int size() const {
return d->array.size();
}
void resize( int size ) {
d->array.resize( size );
}
void setArray( const QVector<Type>& array ) {
d->array = array;
}
operator QVector<Type>&() {
return d->array;
}
operator const QVector<Type>&() const {
return d->array;
}
QVector<Type>& operator() () {
return d->array;
}
const QVector<Type>& operator() () const {
return d->array;
}
Type &operator[]( int i ) {
return d->array[ i ];
}
const Type &operator[]( int i ) const {
return d->array[ i ];
}
private:
public:
QVector<Type> array;
};
QExplicitlySharedDataPointer<QfwSharedArrayData> d;
};
template <typename Type>
QDebug operator<<( QDebug dbg, const QfwSharedArray<Type>& sa ) {
dbg.nospace() << sa.array();
return dbg.nospace();
}
template <typename Type>
class QfwSharedArray
{
public:
QfwSharedArray() : d( new QfwSharedArrayData ) {
}
QfwSharedArray( const QVector<Type>& array ) : d( new QfwSharedArrayData ) {
setArray( array );
}
QfwSharedArray( const QfwSharedArray& org ) : d( org.d ) {
}
~QfwSharedArray() {
}
QfwSharedArray& operator=( const QfwSharedArray& rhs ) {
d = rhs.d;
return *this;
}
bool operator==( const QfwSharedArray& rhs ) const {
return d == rhs.d;
}
bool operator!=( const QfwSharedArray& rhs ) const {
return !operator==( rhs );
}
const QVector<Type>& array() const {
return d->array;
}
QVector<Type>& array() {
return d->array;
}
int size() const {
return d->array.size();
}
void resize( int size ) {
d->array.resize( size );
}
void setArray( const QVector<Type>& array ) {
d->array = array;
}
operator QVector<Type>&() {
return d->array;
}
operator const QVector<Type>&() const {
return d->array;
}
QVector<Type>& operator() () {
return d->array;
}
const QVector<Type>& operator() () const {
return d->array;
}
Type &operator[]( int i ) {
return d->array[ i ];
}
const Type &operator[]( int i ) const {
return d->array[ i ];
}
private:
class QfwSharedArrayData : public QSharedData {
public:
QVector<Type> array;
};
QExplicitlySharedDataPointer<QfwSharedArrayData> d;
};
template <typename Type>
QDebug operator<<( QDebug dbg, const QfwSharedArray<Type>& sa ) {
dbg.nospace() << sa.array();
return dbg.nospace();
}
To copy to clipboard, switch view to plain text mode
Bookmarks