williamr@2
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
2 |
// All rights reserved.
|
williamr@2
|
3 |
// This component and the accompanying materials are made available
|
williamr@4
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
williamr@2
|
5 |
// which accompanies this distribution, and is available
|
williamr@4
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@2
|
7 |
//
|
williamr@2
|
8 |
// Initial Contributors:
|
williamr@2
|
9 |
// Nokia Corporation - initial contribution.
|
williamr@2
|
10 |
//
|
williamr@2
|
11 |
// Contributors:
|
williamr@2
|
12 |
//
|
williamr@2
|
13 |
// Description:
|
williamr@2
|
14 |
//
|
williamr@2
|
15 |
|
williamr@2
|
16 |
// Class TStreamMark
|
williamr@2
|
17 |
inline TStreamMark::TStreamMark()
|
williamr@2
|
18 |
: iPos(KStreamBeginning-1)
|
williamr@2
|
19 |
/** Constructs a default shared stream mark object.
|
williamr@2
|
20 |
|
williamr@2
|
21 |
The position for the mark is uninitialised.
|
williamr@2
|
22 |
|
williamr@2
|
23 |
An uninitialised mark means that a call to IsEmpty() returns true.
|
williamr@2
|
24 |
|
williamr@2
|
25 |
@see IsEmpty() */
|
williamr@2
|
26 |
{}
|
williamr@2
|
27 |
inline TStreamMark::TStreamMark(TStreamPos aPos)
|
williamr@2
|
28 |
: iPos(aPos)
|
williamr@2
|
29 |
/** Constructs the shared stream mark object, setting the mark to the specified
|
williamr@2
|
30 |
stream position.
|
williamr@2
|
31 |
|
williamr@2
|
32 |
An initialised mark means that a call to IsEmpty() returns false.
|
williamr@2
|
33 |
|
williamr@2
|
34 |
@param aPos The stream position
|
williamr@2
|
35 |
@see IsEmpty() */
|
williamr@2
|
36 |
{
|
williamr@2
|
37 |
#if defined (_DEBUG)
|
williamr@2
|
38 |
__DbgChkPos(aPos);
|
williamr@2
|
39 |
#endif
|
williamr@2
|
40 |
}
|
williamr@2
|
41 |
inline TStreamMark& TStreamMark::operator=(TStreamPos aPos)
|
williamr@2
|
42 |
/** Assigns the specified stream position value to this shared stream mark object.
|
williamr@2
|
43 |
|
williamr@2
|
44 |
@param aPos The stream position value to be assigned.
|
williamr@2
|
45 |
@return A reference to this shared stream mark object. */
|
williamr@2
|
46 |
{
|
williamr@2
|
47 |
#if defined (_DEBUG)
|
williamr@2
|
48 |
__DbgChkPos(aPos);
|
williamr@2
|
49 |
#endif
|
williamr@2
|
50 |
iPos=aPos;
|
williamr@2
|
51 |
return *this;
|
williamr@2
|
52 |
}
|
williamr@2
|
53 |
inline TStreamMark::operator TStreamMark*()
|
williamr@2
|
54 |
{return this;}
|
williamr@2
|
55 |
inline TStreamMark::operator const TStreamMark*() const
|
williamr@2
|
56 |
{return this;}
|
williamr@2
|
57 |
inline TBool TStreamMark::operator==(const TStreamMark& aMark) const
|
williamr@2
|
58 |
/** Tests whether this object and the specified referenced shared stream mark object
|
williamr@2
|
59 |
are the same object.
|
williamr@2
|
60 |
|
williamr@2
|
61 |
@param aMark A reference to a shared stream mark object.
|
williamr@2
|
62 |
@return True, if the two objects are the same object; false, otherwise. */
|
williamr@2
|
63 |
{return this==&aMark;}
|
williamr@2
|
64 |
inline TBool TStreamMark::operator==(const TStreamMark* aPtr) const
|
williamr@2
|
65 |
{return this==aPtr;}
|
williamr@2
|
66 |
inline TBool TStreamMark::operator!=(const TStreamMark& aMark) const
|
williamr@2
|
67 |
/** Tests whether this object and the specified shared stream mark object are different
|
williamr@2
|
68 |
objects.
|
williamr@2
|
69 |
|
williamr@2
|
70 |
@param aMark A pointer to a shared stream mark object.
|
williamr@2
|
71 |
@return True, if the two objects are different objects; false, otherwise. */
|
williamr@2
|
72 |
{return this!=&aMark;}
|
williamr@2
|
73 |
inline TBool TStreamMark::operator!=(const TStreamMark* aPtr) const
|
williamr@2
|
74 |
{return this!=aPtr;}
|
williamr@2
|
75 |
inline TBool TStreamMark::IsEmpty() const
|
williamr@2
|
76 |
/** Tests whether this mark object is uninitialised.
|
williamr@2
|
77 |
|
williamr@2
|
78 |
@return True, if this mark object is uninitialised; false, otherwise. */
|
williamr@2
|
79 |
{return iPos<KStreamBeginning;}
|
williamr@2
|
80 |
inline void TStreamMark::Clear()
|
williamr@2
|
81 |
/** Resets the mark object to its default state.
|
williamr@2
|
82 |
|
williamr@2
|
83 |
On return from this function, the mark is uninitialised and a call to IsEmpty()
|
williamr@2
|
84 |
returns true.
|
williamr@2
|
85 |
|
williamr@2
|
86 |
Empties the object/makes it empty so that IsEmpty() returns false */
|
williamr@2
|
87 |
{iPos=KStreamBeginning-1;}
|
williamr@2
|
88 |
inline TStreamPos TStreamMark::Position() const
|
williamr@2
|
89 |
/** Gets the position of the mark.
|
williamr@2
|
90 |
|
williamr@2
|
91 |
@return The stream position. */
|
williamr@2
|
92 |
{
|
williamr@2
|
93 |
#if defined (_DEBUG)
|
williamr@2
|
94 |
__DbgChkPos(iPos);
|
williamr@2
|
95 |
#endif
|
williamr@2
|
96 |
return iPos;
|
williamr@2
|
97 |
}
|
williamr@2
|
98 |
inline TBool TStreamMark::IsWith(TStreamExchange& aHost) const
|
williamr@2
|
99 |
/** Tests whether the specified shared streaming manager currently refers to this
|
williamr@2
|
100 |
mark object.
|
williamr@2
|
101 |
|
williamr@2
|
102 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
103 |
@return True, if the shared stream manager refers to this mark; false, otherwise. */
|
williamr@2
|
104 |
{return aHost.RefersTo(*this);}
|
williamr@2
|
105 |
inline TBool TStreamMark::RelatesTo(TStreamExchange& aHost) const
|
williamr@2
|
106 |
/** Tests whether the specified shared streaming manager currently refers to this
|
williamr@2
|
107 |
mark object OR whether this mark object is initialised.
|
williamr@2
|
108 |
|
williamr@2
|
109 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
110 |
@return True, if the shared stream manager refers to this mark OR if this mark
|
williamr@2
|
111 |
object is initialised; false, otherwise.
|
williamr@2
|
112 |
@see IsWith()
|
williamr@2
|
113 |
@see TStreamExchange::IsActive() */
|
williamr@2
|
114 |
{return iPos>=KStreamBeginning||aHost.RefersTo(*this);}
|
williamr@2
|
115 |
inline void TStreamMark::Withdraw(TStreamExchange& aHost)
|
williamr@2
|
116 |
/** Instructs the shared streaming manager to remove any reference it has to this
|
williamr@2
|
117 |
mark object.
|
williamr@2
|
118 |
|
williamr@2
|
119 |
@param aHost The object that manages shared streaming. */
|
williamr@2
|
120 |
{aHost.Drop(*this);}
|
williamr@2
|
121 |
inline void TStreamMark::ExtractL(TStreamExchange& aHost)
|
williamr@2
|
122 |
/** Refreshes this mark from the mark in the host stream buffer and tells the shared
|
williamr@2
|
123 |
streaming manager to drop any reference it has to to this mark object.
|
williamr@2
|
124 |
|
williamr@2
|
125 |
@param aHost The object that manages shared streaming. */
|
williamr@2
|
126 |
{aHost.GetL(*this);}
|
williamr@2
|
127 |
inline TInt TStreamMark::ReadL(TStreamExchange& aHost,TAny* aPtr,TInt aMaxLength)
|
williamr@2
|
128 |
/** Reads data from the shared stream into the specified memory location.
|
williamr@2
|
129 |
|
williamr@2
|
130 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
131 |
@param aPtr A pointer to the target memory location for the data read from
|
williamr@2
|
132 |
the shared stream.
|
williamr@2
|
133 |
@param aMaxLength The maximum number of bytes to be read.
|
williamr@2
|
134 |
@return The number of bytes read. */
|
williamr@2
|
135 |
{return aHost.DoReadL(aPtr,aMaxLength,*this);}
|
williamr@2
|
136 |
inline TInt TStreamMark::ReadL(TStreamExchange& aHost,TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
|
williamr@2
|
137 |
/** Reads data, asynchronously, from the shared stream into the specified descriptor.
|
williamr@2
|
138 |
|
williamr@2
|
139 |
If the function leaves, then no read request will have been initiated.
|
williamr@2
|
140 |
|
williamr@2
|
141 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
142 |
@param aDes The target descriptor for the data read from the shared stream.
|
williamr@2
|
143 |
@param aMaxLength The maximum number of bytes to be read.
|
williamr@2
|
144 |
@param aStatus The request status that indicates the completion status of this
|
williamr@2
|
145 |
asynchronous request.
|
williamr@2
|
146 |
@return The maximum number of bytes to be read, as used in this request. This
|
williamr@2
|
147 |
can be different to the value supplied in aMaxLength; this is dependent on
|
williamr@2
|
148 |
the implementation of the underlying stream. */
|
williamr@2
|
149 |
{return aHost.DoReadL(aDes,aMaxLength,aStatus,*this);}
|
williamr@2
|
150 |
inline TStreamTransfer TStreamMark::ReadL(TStreamExchange& aHost,MStreamInput& anInput,TStreamTransfer aTransfer)
|
williamr@2
|
151 |
/** Reads data from the shared stream into the specified data sink.
|
williamr@2
|
152 |
|
williamr@2
|
153 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
154 |
@param anInput The sink which is the target for the read operation.
|
williamr@2
|
155 |
@param aTransfer Defines the amount of data available to be read from the shared
|
williamr@2
|
156 |
stream.
|
williamr@2
|
157 |
@return The amount of data that was not consumed. */
|
williamr@2
|
158 |
{return aHost.DoReadL(anInput,aTransfer,*this);}
|
williamr@2
|
159 |
inline TInt TStreamMark::ReadL(TStreamExchange& aHost,MStreamInput& anInput,TInt aMaxLength)
|
williamr@2
|
160 |
/** Reads data from the shared stream into the specified data sink.
|
williamr@2
|
161 |
|
williamr@2
|
162 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
163 |
@param anInput The sink which is the target for the read operation.
|
williamr@2
|
164 |
@param aMaxLength The maximum amount of data available to be read from the
|
williamr@2
|
165 |
shared stream.
|
williamr@2
|
166 |
@return The amount of data that was not consumed. */
|
williamr@2
|
167 |
{return aMaxLength-aHost.DoReadL(anInput,TStreamTransfer(aMaxLength),*this).Left();}
|
williamr@2
|
168 |
inline void TStreamMark::ReadL(TStreamExchange& aHost,MStreamInput& anInput)
|
williamr@2
|
169 |
/** Reads data from the shared stream into the specified data sink.
|
williamr@2
|
170 |
|
williamr@2
|
171 |
No explicit limit is placed on the amount of data that can be read.
|
williamr@2
|
172 |
|
williamr@2
|
173 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
174 |
@param anInput The sink which is the target for the read operation. */
|
williamr@2
|
175 |
{aHost.DoReadL(anInput,KStreamUnlimited,*this);}
|
williamr@2
|
176 |
inline void TStreamMark::WriteL(TStreamExchange& aHost,const TAny* aPtr,TInt aLength)
|
williamr@2
|
177 |
/** Writes data from the specified memory location into the shared stream.
|
williamr@2
|
178 |
|
williamr@2
|
179 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
180 |
@param aPtr A pointer to the memory location from which data is to be written
|
williamr@2
|
181 |
to the shared stream.
|
williamr@2
|
182 |
@param aLength The number of bytes to be written. */
|
williamr@2
|
183 |
{aHost.DoWriteL(aPtr,aLength,*this);}
|
williamr@2
|
184 |
inline TInt TStreamMark::WriteL(TStreamExchange& aHost,const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
|
williamr@2
|
185 |
/** Writes data, asynchronously, from the specified descriptor into the shared
|
williamr@2
|
186 |
stream.
|
williamr@2
|
187 |
|
williamr@2
|
188 |
If the function leaves, then no write request will have been initiated.
|
williamr@2
|
189 |
|
williamr@2
|
190 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
191 |
@param aDes The source descriptor for the data to be written into the shared
|
williamr@2
|
192 |
stream.
|
williamr@2
|
193 |
@param aMaxLength The maximum number of bytes to be written.
|
williamr@2
|
194 |
@param aStatus The request status that indicates the completion status of this
|
williamr@2
|
195 |
asynchronous request.
|
williamr@2
|
196 |
@return The maximum number of bytes to be written, as used in this request.
|
williamr@2
|
197 |
This can be different to the value supplied in aMaxLength; this is dependent
|
williamr@2
|
198 |
on the implementation. */
|
williamr@2
|
199 |
{return aHost.DoWriteL(aDes,aMaxLength,aStatus,*this);}
|
williamr@2
|
200 |
inline TStreamTransfer TStreamMark::WriteL(TStreamExchange& aHost,MStreamOutput& anOutput,TStreamTransfer aTransfer)
|
williamr@2
|
201 |
/** Writes data into the shared stream from the specified data source.
|
williamr@2
|
202 |
|
williamr@2
|
203 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
204 |
@param anOutput The data source for the write operation.
|
williamr@2
|
205 |
@param aTransfer Defines the amount of data to be pulled from the output stream
|
williamr@2
|
206 |
object.
|
williamr@2
|
207 |
@return A stream transfer object defining the amount of data that was not consumed. */
|
williamr@2
|
208 |
{return aHost.DoWriteL(anOutput,aTransfer,*this);}
|
williamr@2
|
209 |
inline TInt TStreamMark::WriteL(TStreamExchange& aHost,MStreamOutput& anOutput,TInt aMaxLength)
|
williamr@2
|
210 |
/** Writes data into the shared stream from the specified data source
|
williamr@2
|
211 |
|
williamr@2
|
212 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
213 |
@param anOutput The data source for the write operation.
|
williamr@2
|
214 |
@param aMaxLength The maximum amount of data available to be written.
|
williamr@2
|
215 |
@return The amount of data that was not consumed. */
|
williamr@2
|
216 |
{return aMaxLength-aHost.DoWriteL(anOutput,TStreamTransfer(aMaxLength),*this).Left();}
|
williamr@2
|
217 |
inline void TStreamMark::WriteL(TStreamExchange& aHost,MStreamOutput& anOutput)
|
williamr@2
|
218 |
/** Writes data into the shared stream from the specified data source.
|
williamr@2
|
219 |
|
williamr@2
|
220 |
No explicit limit is placed on the amount of data that can be written.
|
williamr@2
|
221 |
|
williamr@2
|
222 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
223 |
@param anOutput The data source for the write operation. */
|
williamr@2
|
224 |
{aHost.DoWriteL(anOutput,KStreamUnlimited,*this);}
|
williamr@2
|
225 |
inline void TStreamMark::SeekL(TStreamExchange& aHost,TStreamPos aPos)
|
williamr@2
|
226 |
{aHost.DoSeekL(*this,EStreamBeginning,aPos.Offset());}
|
williamr@2
|
227 |
inline TStreamPos TStreamMark::SeekL(TStreamExchange& aHost,TStreamLocation aLocation,TInt anOffset)
|
williamr@2
|
228 |
/** Moves the position of the mark in the host stream.
|
williamr@2
|
229 |
|
williamr@2
|
230 |
The new position is calculated by adding the specified offset to one of:
|
williamr@2
|
231 |
|
williamr@2
|
232 |
the position of the beginning of the host stream
|
williamr@2
|
233 |
|
williamr@2
|
234 |
the position of the end of the host stream
|
williamr@2
|
235 |
|
williamr@2
|
236 |
the position of the current mark.
|
williamr@2
|
237 |
|
williamr@2
|
238 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
239 |
@param aLocation The location in the host stream on which the calculation of
|
williamr@2
|
240 |
the new position is based.
|
williamr@2
|
241 |
@param anOffset The offset value.
|
williamr@2
|
242 |
@return The new position of the mark. */
|
williamr@2
|
243 |
{return aHost.DoSeekL(*this,aLocation,anOffset);}
|
williamr@2
|
244 |
inline TStreamPos TStreamMark::SeekL(TStreamExchange& aHost,TInt anOffset)
|
williamr@2
|
245 |
/** Moves the position of the mark in the host stream.
|
williamr@2
|
246 |
|
williamr@2
|
247 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
248 |
@param anOffset The amount by which the position of the mark is to be moved
|
williamr@2
|
249 |
relative to the existing position of the mark.
|
williamr@2
|
250 |
@return The new position of the mark. */
|
williamr@2
|
251 |
{return aHost.DoSeekL(*this,EStreamMark,anOffset);}
|
williamr@2
|
252 |
inline TStreamPos TStreamMark::TellL(TStreamExchange& aHost) const
|
williamr@2
|
253 |
/** Gets the position of the mark within the host stream.
|
williamr@2
|
254 |
|
williamr@2
|
255 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
256 |
@return The stream position. */
|
williamr@2
|
257 |
{return aHost.DoSeekL(CONST_CAST(TStreamMark&,*this),EStreamMark,0);}
|
williamr@2
|
258 |
|
williamr@2
|
259 |
// Class TStreamExchange
|
williamr@2
|
260 |
inline TStreamExchange::TStreamExchange()
|
williamr@2
|
261 |
: iHost(NULL),iRMrk(NULL),iWMrk(NULL)
|
williamr@2
|
262 |
/** Constructs an empty object.
|
williamr@2
|
263 |
|
williamr@2
|
264 |
Call Share() to prepare for access to a shared stream buffer. */
|
williamr@2
|
265 |
{}
|
williamr@2
|
266 |
inline TStreamExchange::TStreamExchange(MStreamBuf* aHost)
|
williamr@2
|
267 |
: iHost(aHost),iRMrk(NULL),iWMrk(NULL)
|
williamr@2
|
268 |
/** Constructs the object, specifying the stream buffer that will act as the shared
|
williamr@2
|
269 |
host.
|
williamr@2
|
270 |
|
williamr@2
|
271 |
@param aHost A pointer to a stream buffer that will act as the shared host. */
|
williamr@2
|
272 |
{}
|
williamr@2
|
273 |
inline void TStreamExchange::Share(MStreamBuf* aHost)
|
williamr@2
|
274 |
/** Tells the object to use the specified stream buffer that will act as the shared
|
williamr@2
|
275 |
host.
|
williamr@2
|
276 |
|
williamr@2
|
277 |
@param aHost A pointer to a stream buffer that will act as the shared host. */
|
williamr@2
|
278 |
{iHost=aHost;}
|
williamr@2
|
279 |
inline TBool TStreamExchange::IsActive() const
|
williamr@2
|
280 |
/** Tests whether this object is using a stream buffer that is acting as shared
|
williamr@2
|
281 |
host.
|
williamr@2
|
282 |
|
williamr@2
|
283 |
@return True, if this object is using a shared host ; false, otherwise. */
|
williamr@2
|
284 |
{return iHost!=NULL;}
|
williamr@2
|
285 |
|
williamr@2
|
286 |
// Class RShareBuf
|
williamr@2
|
287 |
inline void RShareBuf::Open(TStreamExchange& aHost,TInt aMode)
|
williamr@2
|
288 |
/** Prepares the shared stream buffer for streaming.
|
williamr@2
|
289 |
|
williamr@2
|
290 |
The function sets the read mark and/or the write mark to the beginning of
|
williamr@2
|
291 |
the host stream.
|
williamr@2
|
292 |
|
williamr@2
|
293 |
@param aHost The object that manages shared streaming.
|
williamr@2
|
294 |
@param aMode The streaming mode. This can be read and/or write, as indicated
|
williamr@2
|
295 |
by the ERead and EWrite bits.
|
williamr@2
|
296 |
@see MStreamBuf::TRead
|
williamr@2
|
297 |
@see MStreamBuf::TWrite
|
williamr@2
|
298 |
@see KStreamBeginning */
|
williamr@2
|
299 |
{Open(aHost,KStreamBeginning,aMode);}
|
williamr@2
|
300 |
|
williamr@2
|
301 |
// Class RShareWriteStream
|
williamr@2
|
302 |
inline RShareWriteStream::RShareWriteStream(const MExternalizer<TStreamRef>& anExter)
|
williamr@2
|
303 |
: RWriteStream(anExter)
|
williamr@2
|
304 |
{}
|
williamr@4
|
305 |
|