1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
'\" t
.TH TQDeepCopy 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
TQDeepCopy \- Template class which ensures that
.SH SYNOPSIS
All the functions in this class are reentrant when TQt is built with thread support.</p>
.PP
\fC#include <tqdeepcopy.h>\fR
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBTQDeepCopy\fR ()"
.br
.ti -1c
.BI "\fBTQDeepCopy\fR ( const T & t )"
.br
.ti -1c
.BI "TQDeepCopy<T> & \fBoperator=\fR ( const T & t )"
.br
.ti -1c
.BI "\fBoperator T\fR ()"
.br
.in -1c
.SH DESCRIPTION
The TQDeepCopy 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
TQString s1 = "abcd";
.br
TQString s2 = s1;
.br
TQString s3 = s2;
.br
TQString s4 = s3;
.br
TQString s5 = s2;
.br
.fi
.PP
TQDeepCopy 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
TQString s1 = "abcd";
.br
TQString s2 = s1;
.br
TQDeepCopy<TQString> s3 = s2; // s3 is a deep copy of s2
.br
TQString s4 = s3; // s4 is a deep copy of s3
.br
TQString 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
TQString s1 = "abcd";
.br
TQString s2 = s1;
.br
TQString s3 = TQDeepCopy<TQString>( s2 ); // s3 is a deep copy of s2
.br
TQString s4 = s3; // s4 is a shallow copy of s3
.br
TQString s5 = s2;
.br
.fi
.PP
TQDeepCopy 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
TQDeepCopy<TQString> global_string; // global string data
.br
TQMutex global_mutex; // mutex to protext global_string
.br
.br
...
.br
.br
void setGlobalString( const TQString &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
TQString 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 TQString, which is an implicitly shared class. The behavior of TQDeepCopy is the same when using explicitly shared classes like TQByteArray.
.PP
Currently, TQDeepCopy works with the following classes:
.TP
TQMemArray (including subclasses like TQByteArray and TQCString)
.TP
TQMap
.TP
TQString
.TP
TQValueList (including subclasses like TQStringList and TQValueStack)
.TP
TQValueVector
.PP
See also Thread Support in Qt, Implicitly and Explicitly Shared Classes, and Non-GUI Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "TQDeepCopy::TQDeepCopy ()"
Constructs an empty instance of type \fIT\fR.
.SH "TQDeepCopy::TQDeepCopy ( const T & t )"
Constructs a deep copy of \fIt\fR.
.SH "TQDeepCopy::operator T ()"
Returns a deep copy of the encapsulated data.
.SH "TQDeepCopy<T> & TQDeepCopy::operator= ( const T & t )"
Assigns a deep copy of \fIt\fR.
.SH "SEE ALSO"
.BR http://doc.trolltech.com/tqdeepcopy.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 TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt 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 (tqdeepcopy.3qt) and the Qt
version (3.3.8).
|