First public contribution.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 inline RReadStream::RReadStream()
19 /** Sets the stream buffer source to NULL, which implies that it is safe to close
21 @see RReadStream::Source() */
23 inline RReadStream::RReadStream(MStreamBuf* aSource)
25 /** Constructs a read stream over the supplied stream buffer.
27 @param aSource The stream buffer used to read from the read stream.
28 @see RReadStream::Source() */
30 inline MStreamBuf* RReadStream::Source()
31 /** Gets the underlying stream buffer for the read stream. This provides access
32 to the stream-buffer implementation used by the read stream.
36 If the stream buffer supports seeking, this allows the RReadStream client
37 to have random access to the stream data.
39 @return The underlying stream buffer for the read stream.
40 @see RReadStream::Attach()
41 @see RReadStream::Detach() */
43 inline void RReadStream::Close()
44 /** Frees resources used by the stream.
46 @see RReadStream::Release() */
48 inline void RReadStream::ReadL(RWriteStream& aStream)
49 /** Writes the content of this stream to the specified write stream.
51 @param aStream A reference to the write stream to which this stream is to be written.*/
52 {aStream.WriteL(*this);}
53 inline void RReadStream::ReadL(RWriteStream& aStream,TInt aLength)
54 /** Writes the content of this stream to the specified write stream.
56 @param aStream A reference to the write stream to which this stream is to be written.
57 @param aLength The length of data from this stream to be written to aStream.*/
58 {aStream.WriteL(*this,aLength);}
59 inline void RReadStream::Pop()
60 /** Removes the cleanup item for this read stream object from the cleanup stack. */
61 {CleanupStack::Pop();}
62 inline void RReadStream::Attach(MStreamBuf* aSource)
63 /** Sets the stream buffer source for this read stream. The existing source (if
64 there is one) will be discarded.
66 This is useful for derived classes, enabling them to set the source following
71 Release() is not called on any discarded stream buffer.
73 @param aSource The new source stream buffer for this read stream.
74 @see RReadStream::Source()
75 @see RReadStream::Detach() */
77 inline void RReadStream::Detach()
78 /** Sets the stream buffer source for this read stream to NULL. The existing source,
79 if there is one, will be discarded.
81 Note that Release() is not called on any discarded stream buffer.
83 @see RReadStream::Source()
84 @see RReadStream::Attach() */
88 inline RWriteStream::RWriteStream()
89 : iSnk(NULL),iExterL(NULL)
90 /** The stream buffer sink, as returned by Sink(), is set to NULL, and the stream
91 has no associated Store map. */
93 inline RWriteStream::RWriteStream(const MExternalizer<TStreamRef>& anExter)
94 : iSnk(NULL),iExterL(&anExter)
95 /** Constructs a write stream with an associated store map. The stream buffer sink
98 @param anExter Specifies an externaliser. For example, CStoreMap implements
99 MExternalizer<TStreamRef>. */
101 inline RWriteStream::RWriteStream(MStreamBuf* aSink)
102 : iSnk(aSink),iExterL(NULL)
103 /** Constructs a write stream over the supplied stream buffer. The stream has no
104 associated Store map.
106 @param aSink The stream buffer used to write to the write stream. */
108 inline MStreamBuf* RWriteStream::Sink()
109 /** Gets the underlying stream buffer for the write stream. This provides access
110 to the stream-buffer implementation used by the write stream.
112 @return The underlying stream buffer for the write stream. */
114 inline void RWriteStream::Pop()
115 /** Removes the cleanup item for this write stream object from the cleanup stack. */
116 {CleanupStack::Pop();}
117 inline void RWriteStream::Attach(MStreamBuf* aSink)
118 /** Sets the stream buffer sink for this write stream. The existing sink, if there
119 is one, will be discarded.
121 This is useful for derived classes, enabling them to set the sink following
126 Release() is not called for discarded sinks.
128 @param aSink The stream buffer sink for this write stream. */
130 inline void RWriteStream::Detach()
131 /** Sets the stream buffer sink for this write stream to NULL. The existing sink,
132 if there is one, will be discarded.
136 Release() is not called for discarded sinks. */
139 // Class TCardinality
140 inline TCardinality::TCardinality(TInt aCount)
142 /** Constructs the object with the specified value.
144 @param aCount The value for this object. */
147 __DbgChkRange(aCount);
150 inline TCardinality::operator TInt() const
153 __DbgChkRange(iCount);
158 // Template class TExternalizer
160 inline void TExternalizer<T>::operator()(const T& anObject,RWriteStream& aStream) const
163 inline TExternalizeFunction TExternalizer<T>::Function()
164 /** Gets a pointer to the function to be used to perform externalisation.
166 The implementation is the private, static member of this class, ExternalizeAsL().
168 @return The externalisation function. */
169 {return &ExternalizeAsL;}
171 void TExternalizer<T>::ExternalizeAsL(const TAny* aPtr,RWriteStream& aStream)
172 {aStream<<*((const T*)aPtr);}
173 inline TExternalizer<TAny>::TExternalizer(TExternalizeFunction aFunction)
176 inline void TExternalizer<TAny>::operator()(const TAny* aPtr,RWriteStream& aStream) const
177 {(*iFunc)(aPtr,aStream);}
178 inline TExternalizeFunction TExternalizer<TAny>::Function() const
181 // Template class TInternalizer
183 inline void TInternalizer<T>::operator()(T& anObject,RReadStream& aStream) const
186 inline TInternalizeFunction TInternalizer<T>::Function()
187 /** Gets a pointer to the function to be used to perform internalisation.
189 The implementation is the private, static member of this class, InternalizeAsL().
191 @return The internalisation function. */
192 {return &InternalizeAsL;}
194 void TInternalizer<T>::InternalizeAsL(TAny* aPtr,RReadStream& aStream)
195 {aStream>>*((T*)aPtr);}
196 inline TInternalizer<TAny>::TInternalizer(TInternalizeFunction aFunction)
199 inline void TInternalizer<TAny>::operator()(TAny* aPtr,RReadStream& aStream) const
200 {(*iFunc)(aPtr,aStream);}
201 inline TInternalizeFunction TInternalizer<TAny>::Function() const
204 // Template class MExternalizer
206 inline void MExternalizer<T>::operator()(const T& anObject,RWriteStream& aStream) const
207 {ExternalizeL(anObject,aStream);}
209 // Template class MInternalizer
211 inline void MInternalizer<T>::operator()(T& anObject,RReadStream& aStream) const
212 {InternalizeL(anObject,aStream);}
215 inline TStreamRef::TStreamRef(const TAny* aPtr,TExternalizeFunction aFunction)
216 : iPtr(aPtr),iFunc(aFunction)
219 @param aPtr A pointer to the object for which externalisation is being done.
220 @param aFunction The externalisation function. */
222 inline const TAny* TStreamRef::Ptr() const
223 /** Gets the pointer to the object to be externalised.
225 @return The object to be externalised. */
227 inline TExternalizeFunction TStreamRef::Function() const
228 /** Gets a pointer to the externalisation function.
230 @return The externalisation function. */
232 inline void TStreamRef::ExternalizeL(RWriteStream& aStream) const
233 /** Externalises the object to the specified write stream.
235 @param aStream The write stream. */
236 {aStream.WriteRefL(*this);}
238 // Externalization and internalization functions
239 IMPORT_C void ExternalizeL(TInt64 anInt64,RWriteStream& aStream);
240 IMPORT_C void InternalizeL(TInt64& anInt64,RReadStream& aStream);
242 IMPORT_C void ExternalizeL(const TDesC8& aDes8,RWriteStream& aStream);
243 IMPORT_C void ExternalizeL(const TDesC16& aDes16,RWriteStream& aStream);
244 IMPORT_C void InternalizeL(TDes8& aDes8,RReadStream& aStream);
245 IMPORT_C void InternalizeL(TDes16& aDes16,RReadStream& aStream);
247 IMPORT_C void ExternalizeL(const TCheckedUid& aUid,RWriteStream& aStream);
248 IMPORT_C void InternalizeL(TCheckedUid& aUid,RReadStream& aStream);
250 IMPORT_C void ExternalizeL(TPoint aPoint,RWriteStream& aStream);
251 IMPORT_C void ExternalizeL(TSize aSize,RWriteStream& aStream);
252 IMPORT_C void ExternalizeL(const TRect& aRect,RWriteStream& aStream);
253 IMPORT_C void InternalizeL(TPoint& aPoint,RReadStream& aStream);
254 IMPORT_C void InternalizeL(TSize& aSize,RReadStream& aStream);
255 IMPORT_C void InternalizeL(TRect& aRect,RReadStream& aStream);
257 IMPORT_C void ExternalizeL(const CBufBase& aBuf,RWriteStream& aStream);
258 IMPORT_C void InternalizeL(CBufBase& aBuf,RReadStream& aStream);
260 IMPORT_C void ArrayExternalizeCountL(TInt aCount,RWriteStream& aStream);
261 IMPORT_C void DoExternalizeAllL(const CArrayFixBase& anArray,RWriteStream& aStream,TExternalizer<TAny> anExter);
262 IMPORT_C TInt ArrayInternalizeCountL(RReadStream& aStream);
263 IMPORT_C void DoInternalizeAllL(CArrayFixBase& anArray,RReadStream& aStream,TInternalizer<TAny> anInter);
266 inline void ExternalizeCountL(const CArrayFix<T>& anArray,RWriteStream& aStream)
267 {ArrayExternalizeCountL(anArray.Count(),aStream);}
269 inline void ExternalizeAllL(const CArrayFix<T>& anArray,RWriteStream& aStream)
270 {DoExternalizeAllL(anArray,aStream,TExternalizer<T>::Function());}
272 void InternalizeCountL(CArrayFix<T>& anArray,RReadStream& aStream)
274 TInt n=ArrayInternalizeCountL(aStream);
278 inline void InternalizeAllL(CArrayFix<T>& anArray,RReadStream& aStream)
279 {DoInternalizeAllL(anArray,aStream,TInternalizer<T>::Function());}
282 void ExternalizeL(const CArrayFix<T>& anArray,RWriteStream& aStream)
284 ExternalizeCountL(anArray,aStream);
285 ExternalizeAllL(anArray,aStream);
288 void InternalizeL(CArrayFix<T>& anArray,RReadStream& aStream)
290 InternalizeCountL(anArray,aStream);
291 InternalizeAllL(anArray,aStream);
295 inline void ExternalizeL(const T* aPtr,RWriteStream& aStream)
296 {aStream<<TStreamRef(aPtr,TExternalizer<T>::Function());}
299 inline void DoExternalizeL(const T& anObject,RWriteStream& aStream,Externalize::Member)
300 {anObject.ExternalizeL(aStream);}
302 inline void DoInternalizeL(T& anObject,RReadStream& aStream,Internalize::Member)
303 {anObject.InternalizeL(aStream);}
306 inline void DoExternalizeL(const T& anObject,RWriteStream& aStream,Externalize::Function)
307 {ExternalizeL(anObject,aStream);}
309 inline void DoInternalizeL(T& anObject,RReadStream& aStream,Internalize::Function)
310 {InternalizeL(anObject,aStream);}
312 // Externalization and internalization selectors
313 inline Externalize::Member Externalization(const TAny*)
314 {return Externalize::Member();}
315 inline Internalize::Member Internalization(TAny*)
316 {return Internalize::Member();}
318 inline Externalize::Function Externalization(const TDesC8*)
319 {return Externalize::Function();}
320 inline Externalize::Function Externalization(const TDesC16*)
321 {return Externalize::Function();}
322 inline Internalize::Function Internalization(TDes8*)
323 {return Internalize::Function();}
324 inline Internalize::Function Internalization(TDes16*)
325 {return Internalize::Function();}
327 inline Externalize::Function Externalization(const CBufBase*)
328 {return Externalize::Function();}
329 inline Externalize::Function Externalization(const CArrayFixBase*)
330 {return Externalize::Function();}
331 inline Internalize::Function Internalization(CBufBase*)
332 {return Internalize::Function();}
333 inline Internalize::Function Internalization(CArrayFixBase*)
334 {return Internalize::Function();}
337 inline Externalize::Function Externalization(T*const*)
338 {return Externalize::Function();}
340 // Input and output operators
342 inline RWriteStream& operator<<(RWriteStream& aStream,const T& anObject)
343 {DoExternalizeL(anObject,aStream,Externalization(&anObject));return aStream;}
345 inline RReadStream& operator>>(RReadStream& aStream,T& anObject)
346 {DoInternalizeL(anObject,aStream,Internalization(&anObject));return aStream;}
348 inline RWriteStream& operator<<(RWriteStream& aStream,const TInt8& anInt8)
349 {aStream.WriteInt8L(anInt8);return aStream;}
350 inline RWriteStream& operator<<(RWriteStream& aStream,const TInt16& anInt16)
351 {aStream.WriteInt16L(anInt16);return aStream;}
352 inline RWriteStream& operator<<(RWriteStream& aStream,const TInt32& anInt32)
353 {aStream.WriteInt32L(anInt32);return aStream;}
354 inline RWriteStream& operator<<(RWriteStream& aStream,const TUint8& aUint8)
355 {aStream.WriteUint8L(aUint8);return aStream;}
356 inline RWriteStream& operator<<(RWriteStream& aStream,const TUint16& aUint16)
357 {aStream.WriteUint16L(aUint16);return aStream;}
358 inline RWriteStream& operator<<(RWriteStream& aStream,const TUint32& aUint32)
359 {aStream.WriteUint32L(aUint32);return aStream;}
360 inline RWriteStream& operator<<(RWriteStream& aStream,const TReal32& aReal32)
361 {aStream.WriteReal32L(aReal32);return aStream;}
362 inline RWriteStream& operator<<(RWriteStream& aStream,const TReal64& aReal64)
363 {aStream.WriteReal64L(aReal64);return aStream;}
365 inline RReadStream& operator>>(RReadStream& aStream,TInt8& anInt8)
366 {anInt8=aStream.ReadInt8L();return aStream;}
367 inline RReadStream& operator>>(RReadStream& aStream,TInt16& anInt16)
368 {anInt16=aStream.ReadInt16L();return aStream;}
369 inline RReadStream& operator>>(RReadStream& aStream,TInt32& anInt32)
370 {anInt32=aStream.ReadInt32L();return aStream;}
371 inline RReadStream& operator>>(RReadStream& aStream,TUint8& aUint8)
372 {aUint8=aStream.ReadUint8L();return aStream;}
373 inline RReadStream& operator>>(RReadStream& aStream,TUint16& aUint16)
374 {aUint16=aStream.ReadUint16L();return aStream;}
375 inline RReadStream& operator>>(RReadStream& aStream,TUint32& aUint32)
376 {aUint32=aStream.ReadUint32L();return aStream;}
377 inline RReadStream& operator>>(RReadStream& aStream,TReal32& aReal32)
378 {aReal32=aStream.ReadReal32L();return aStream;}
379 inline RReadStream& operator>>(RReadStream& aStream,TReal64& aReal64)
380 {aReal64=aStream.ReadReal64L();return aStream;}
382 inline RWriteStream& operator<<(RWriteStream& aStream,const TInt64& anInt64)
383 {ExternalizeL(anInt64,aStream);return aStream;}
384 inline RReadStream& operator>>(RReadStream& aStream,TInt64& anInt64)
385 {InternalizeL(anInt64,aStream);return aStream;}
387 inline RWriteStream& operator<<(RWriteStream& aStream,const TUid& aUid)
388 {return aStream<<aUid.iUid;}
389 inline RWriteStream& operator<<(RWriteStream& aStream,const TCheckedUid& aUid)
390 {ExternalizeL(aUid,aStream);return aStream;}
391 inline RReadStream& operator>>(RReadStream& aStream,TUid& aUid)
392 {return aStream>>aUid.iUid;}
393 inline RReadStream& operator>>(RReadStream& aStream,TCheckedUid& aUid)
394 {InternalizeL(aUid,aStream);return aStream;}
396 inline RWriteStream& operator<<(RWriteStream& aStream,const TPoint& aPoint)
397 {ExternalizeL(aPoint,aStream);return aStream;}
398 inline RWriteStream& operator<<(RWriteStream& aStream,const TSize& aSize)
399 {ExternalizeL(aSize,aStream);return aStream;}
400 inline RWriteStream& operator<<(RWriteStream& aStream,const TRect& aRect)
401 {ExternalizeL(aRect,aStream);return aStream;}
402 inline RReadStream& operator>>(RReadStream& aStream,TPoint& aPoint)
403 {InternalizeL(aPoint,aStream);return aStream;}
404 inline RReadStream& operator>>(RReadStream& aStream,TSize& aSize)
405 {InternalizeL(aSize,aStream);return aStream;}
406 inline RReadStream& operator>>(RReadStream& aStream,TRect& aRect)
407 {InternalizeL(aRect,aStream);return aStream;}
409 inline RWriteStream& operator<<(RWriteStream& aStream,const TStreamRef& aRef)
410 {aRef.ExternalizeL(aStream);return aStream;}