You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qt3/doc/man/man3/qdeepcopy.3qt

191 lines
5.1 KiB

'\" t
.TH QDeepCopy 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QDeepCopy \- Template class which ensures that
.SH SYNOPSIS
All the functions in this class are reentrant when Qt is built with thread support.</p>
.PP
\fC#include <qdeepcopy.h>\fR
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQDeepCopy\fR ()"
.br
.ti -1c
.BI "\fBQDeepCopy\fR ( const T & t )"
.br
.ti -1c
.BI "QDeepCopy<T> & \fBoperator=\fR ( const T & t )"
.br
.ti -1c
.BI "\fBoperator T\fR ()"
.br
.in -1c
.SH DESCRIPTION
The QDeepCopy class is a template class which ensures that implicitly shared and explicitly shared classes reference unique data.
.PP
Normally, shared copies reference the same data to optimize memory use and for maximum speed. In the example below, \fCs1\fR, \fCs2\fR, \fCs3\fR, \fCs4\fR and \fCs5\fR share data.
.PP
.nf
.br
// all 5 strings share the same data
.br
QString s1 = "abcd";
.br
QString s2 = s1;
.br
QString s3 = s2;
.br
QString s4 = s3;
.br
QString s5 = s2;
.br
.fi
.PP
QDeepCopy can be used several ways to ensure that an object references unique, unshared data. In the example below, \fCs1\fR, \fCs2\fR and \fCs5\fR share data, while neither \fCs3\fR nor \fCs4\fR share data.
.PP
.nf
.br
// s1, s2 and s5 share the same data, neither s3 nor s4 are shared
.br
QString s1 = "abcd";
.br
QString s2 = s1;
.br
QDeepCopy<QString> s3 = s2; // s3 is a deep copy of s2
.br
QString s4 = s3; // s4 is a deep copy of s3
.br
QString s5 = s2;
.br
.fi
.PP
In the example below, \fCs1\fR, \fCs2\fR and \fCs5\fR share data, and \fCs3\fR and \fCs4\fR share data.
.PP
.nf
.br
// s1, s2 and s5 share the same data, s3 and s4 share the same data
.br
QString s1 = "abcd";
.br
QString s2 = s1;
.br
QString s3 = QDeepCopy<QString>( s2 ); // s3 is a deep copy of s2
.br
QString s4 = s3; // s4 is a shallow copy of s3
.br
QString s5 = s2;
.br
.fi
.PP
QDeepCopy can also provide safety in multithreaded applications that use shared classes. In the example below, the variable \fCglobal_string\fR is used safely since the data contained in \fCglobal_string\fR is always a deep copy. This ensures that all threads get a unique copy of the data, and that any assignments to \fCglobal_string\fR will result in a deep copy.
.PP
.nf
.br
QDeepCopy<QString> global_string; // global string data
.br
QMutex global_mutex; // mutex to protext global_string
.br
.br
...
.br
.br
void setGlobalString( const QString &str )
.br
{
.br
global_mutex.lock();
.br
global_string = str; // global_string is a deep copy of str
.br
global_mutex.unlock();
.br
}
.br
.br
...
.br
.br
void MyThread::run()
.br
{
.br
global_mutex.lock();
.br
QString str = global_string; // str is a deep copy of global_string
.br
global_mutex.unlock();
.br
.br
// process the string data
.br
...
.br
.br
// update global_string
.br
setGlobalString( str );
.br
}
.br
.fi
.PP
\fBWarning:\fR It is the application developer's responsibility to protect the object shared across multiple threads.
.PP
The examples above use QString, which is an implicitly shared class. The behavior of QDeepCopy is the same when using explicitly shared classes like QByteArray.
.PP
Currently, QDeepCopy works with the following classes:
.TP
QMemArray (including subclasses like QByteArray and QCString)
.TP
QMap
.TP
QString
.TP
QValueList (including subclasses like QStringList and QValueStack)
.TP
QValueVector
.PP
See also Thread Support in Qt, Implicitly and Explicitly Shared Classes, and Non-GUI Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QDeepCopy::QDeepCopy ()"
Constructs an empty instance of type \fIT\fR.
.SH "QDeepCopy::QDeepCopy ( const T & t )"
Constructs a deep copy of \fIt\fR.
.SH "QDeepCopy::operator T ()"
Returns a deep copy of the encapsulated data.
.SH "QDeepCopy<T> & QDeepCopy::operator= ( const T & t )"
Assigns a deep copy of \fIt\fR.
.SH "SEE ALSO"
.BR http://doc.trolltech.com/qdeepcopy.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qdeepcopy.3qt) and the Qt
version (3.3.8).