sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: // Class RReadStream sl@0: inline RReadStream::RReadStream() sl@0: : iSrc(NULL) sl@0: /** Sets the stream buffer source to NULL, which implies that it is safe to close sl@0: sl@0: @see RReadStream::Source() */ sl@0: {} sl@0: inline RReadStream::RReadStream(MStreamBuf* aSource) sl@0: : iSrc(aSource) sl@0: /** Constructs a read stream over the supplied stream buffer. sl@0: sl@0: @param aSource The stream buffer used to read from the read stream. sl@0: @see RReadStream::Source() */ sl@0: {} sl@0: inline MStreamBuf* RReadStream::Source() sl@0: /** Gets the underlying stream buffer for the read stream. This provides access sl@0: to the stream-buffer implementation used by the read stream. sl@0: sl@0: Note: sl@0: sl@0: If the stream buffer supports seeking, this allows the RReadStream client sl@0: to have random access to the stream data. sl@0: sl@0: @return The underlying stream buffer for the read stream. sl@0: @see RReadStream::Attach() sl@0: @see RReadStream::Detach() */ sl@0: {return iSrc;} sl@0: inline void RReadStream::Close() sl@0: /** Frees resources used by the stream. sl@0: sl@0: @see RReadStream::Release() */ sl@0: {Release();} sl@0: inline void RReadStream::ReadL(RWriteStream& aStream) sl@0: /** Writes the content of this stream to the specified write stream. sl@0: sl@0: @param aStream A reference to the write stream to which this stream is to be written.*/ sl@0: {aStream.WriteL(*this);} sl@0: inline void RReadStream::ReadL(RWriteStream& aStream,TInt aLength) sl@0: /** Writes the content of this stream to the specified write stream. sl@0: sl@0: @param aStream A reference to the write stream to which this stream is to be written. sl@0: @param aLength The length of data from this stream to be written to aStream.*/ sl@0: {aStream.WriteL(*this,aLength);} sl@0: inline void RReadStream::Pop() sl@0: /** Removes the cleanup item for this read stream object from the cleanup stack. */ sl@0: {CleanupStack::Pop();} sl@0: inline void RReadStream::Attach(MStreamBuf* aSource) sl@0: /** Sets the stream buffer source for this read stream. The existing source (if sl@0: there is one) will be discarded. sl@0: sl@0: This is useful for derived classes, enabling them to set the source following sl@0: construction. sl@0: sl@0: Note: sl@0: sl@0: Release() is not called on any discarded stream buffer. sl@0: sl@0: @param aSource The new source stream buffer for this read stream. sl@0: @see RReadStream::Source() sl@0: @see RReadStream::Detach() */ sl@0: {iSrc=aSource;} sl@0: inline void RReadStream::Detach() sl@0: /** Sets the stream buffer source for this read stream to NULL. The existing source, sl@0: if there is one, will be discarded. sl@0: sl@0: Note that Release() is not called on any discarded stream buffer. sl@0: sl@0: @see RReadStream::Source() sl@0: @see RReadStream::Attach() */ sl@0: {iSrc=NULL;} sl@0: sl@0: // Class RWriteStream sl@0: inline RWriteStream::RWriteStream() sl@0: : iSnk(NULL),iExterL(NULL) sl@0: /** The stream buffer sink, as returned by Sink(), is set to NULL, and the stream sl@0: has no associated Store map. */ sl@0: {} sl@0: inline RWriteStream::RWriteStream(const MExternalizer& anExter) sl@0: : iSnk(NULL),iExterL(&anExter) sl@0: /** Constructs a write stream with an associated store map. The stream buffer sink sl@0: is set to NULL. sl@0: sl@0: @param anExter Specifies an externaliser. For example, CStoreMap implements sl@0: MExternalizer. */ sl@0: {} sl@0: inline RWriteStream::RWriteStream(MStreamBuf* aSink) sl@0: : iSnk(aSink),iExterL(NULL) sl@0: /** Constructs a write stream over the supplied stream buffer. The stream has no sl@0: associated Store map. sl@0: sl@0: @param aSink The stream buffer used to write to the write stream. */ sl@0: {} sl@0: inline MStreamBuf* RWriteStream::Sink() sl@0: /** Gets the underlying stream buffer for the write stream. This provides access sl@0: to the stream-buffer implementation used by the write stream. sl@0: sl@0: @return The underlying stream buffer for the write stream. */ sl@0: {return iSnk;} sl@0: inline void RWriteStream::Pop() sl@0: /** Removes the cleanup item for this write stream object from the cleanup stack. */ sl@0: {CleanupStack::Pop();} sl@0: inline void RWriteStream::Attach(MStreamBuf* aSink) sl@0: /** Sets the stream buffer sink for this write stream. The existing sink, if there sl@0: is one, will be discarded. sl@0: sl@0: This is useful for derived classes, enabling them to set the sink following sl@0: construction. sl@0: sl@0: Note: sl@0: sl@0: Release() is not called for discarded sinks. sl@0: sl@0: @param aSink The stream buffer sink for this write stream. */ sl@0: {iSnk=aSink;} sl@0: inline void RWriteStream::Detach() sl@0: /** Sets the stream buffer sink for this write stream to NULL. The existing sink, sl@0: if there is one, will be discarded. sl@0: sl@0: Note: sl@0: sl@0: Release() is not called for discarded sinks. */ sl@0: {iSnk=NULL;} sl@0: sl@0: // Class TCardinality sl@0: inline TCardinality::TCardinality(TInt aCount) sl@0: :iCount(aCount) sl@0: /** Constructs the object with the specified value. sl@0: sl@0: @param aCount The value for this object. */ sl@0: { sl@0: #if defined (_DEBUG) sl@0: __DbgChkRange(aCount); sl@0: #endif sl@0: } sl@0: inline TCardinality::operator TInt() const sl@0: { sl@0: #if defined (_DEBUG) sl@0: __DbgChkRange(iCount); sl@0: #endif sl@0: return iCount; sl@0: } sl@0: sl@0: // Template class TExternalizer sl@0: template sl@0: inline void TExternalizer::operator()(const T& anObject,RWriteStream& aStream) const sl@0: {aStream< sl@0: inline TExternalizeFunction TExternalizer::Function() sl@0: /** Gets a pointer to the function to be used to perform externalisation. sl@0: sl@0: The implementation is the private, static member of this class, ExternalizeAsL(). sl@0: sl@0: @return The externalisation function. */ sl@0: {return &ExternalizeAsL;} sl@0: template sl@0: void TExternalizer::ExternalizeAsL(const TAny* aPtr,RWriteStream& aStream) sl@0: {aStream<<*((const T*)aPtr);} sl@0: inline TExternalizer::TExternalizer(TExternalizeFunction aFunction) sl@0: : iFunc(aFunction) sl@0: {} sl@0: inline void TExternalizer::operator()(const TAny* aPtr,RWriteStream& aStream) const sl@0: {(*iFunc)(aPtr,aStream);} sl@0: inline TExternalizeFunction TExternalizer::Function() const sl@0: {return iFunc;} sl@0: sl@0: // Template class TInternalizer sl@0: template sl@0: inline void TInternalizer::operator()(T& anObject,RReadStream& aStream) const sl@0: {aStream>>anObject;} sl@0: template sl@0: inline TInternalizeFunction TInternalizer::Function() sl@0: /** Gets a pointer to the function to be used to perform internalisation. sl@0: sl@0: The implementation is the private, static member of this class, InternalizeAsL(). sl@0: sl@0: @return The internalisation function. */ sl@0: {return &InternalizeAsL;} sl@0: template sl@0: void TInternalizer::InternalizeAsL(TAny* aPtr,RReadStream& aStream) sl@0: {aStream>>*((T*)aPtr);} sl@0: inline TInternalizer::TInternalizer(TInternalizeFunction aFunction) sl@0: : iFunc(aFunction) sl@0: {} sl@0: inline void TInternalizer::operator()(TAny* aPtr,RReadStream& aStream) const sl@0: {(*iFunc)(aPtr,aStream);} sl@0: inline TInternalizeFunction TInternalizer::Function() const sl@0: {return iFunc;} sl@0: sl@0: // Template class MExternalizer sl@0: template sl@0: inline void MExternalizer::operator()(const T& anObject,RWriteStream& aStream) const sl@0: {ExternalizeL(anObject,aStream);} sl@0: sl@0: // Template class MInternalizer sl@0: template sl@0: inline void MInternalizer::operator()(T& anObject,RReadStream& aStream) const sl@0: {InternalizeL(anObject,aStream);} sl@0: sl@0: // Class TStreamRef sl@0: inline TStreamRef::TStreamRef(const TAny* aPtr,TExternalizeFunction aFunction) sl@0: : iPtr(aPtr),iFunc(aFunction) sl@0: /** Constructor. sl@0: sl@0: @param aPtr A pointer to the object for which externalisation is being done. sl@0: @param aFunction The externalisation function. */ sl@0: {} sl@0: inline const TAny* TStreamRef::Ptr() const sl@0: /** Gets the pointer to the object to be externalised. sl@0: sl@0: @return The object to be externalised. */ sl@0: {return iPtr;} sl@0: inline TExternalizeFunction TStreamRef::Function() const sl@0: /** Gets a pointer to the externalisation function. sl@0: sl@0: @return The externalisation function. */ sl@0: {return iFunc;} sl@0: inline void TStreamRef::ExternalizeL(RWriteStream& aStream) const sl@0: /** Externalises the object to the specified write stream. sl@0: sl@0: @param aStream The write stream. */ sl@0: {aStream.WriteRefL(*this);} sl@0: sl@0: // Externalization and internalization functions sl@0: IMPORT_C void ExternalizeL(TInt64 anInt64,RWriteStream& aStream); sl@0: IMPORT_C void InternalizeL(TInt64& anInt64,RReadStream& aStream); sl@0: sl@0: IMPORT_C void ExternalizeL(const TDesC8& aDes8,RWriteStream& aStream); sl@0: IMPORT_C void ExternalizeL(const TDesC16& aDes16,RWriteStream& aStream); sl@0: IMPORT_C void InternalizeL(TDes8& aDes8,RReadStream& aStream); sl@0: IMPORT_C void InternalizeL(TDes16& aDes16,RReadStream& aStream); sl@0: sl@0: IMPORT_C void ExternalizeL(const TCheckedUid& aUid,RWriteStream& aStream); sl@0: IMPORT_C void InternalizeL(TCheckedUid& aUid,RReadStream& aStream); sl@0: sl@0: IMPORT_C void ExternalizeL(TPoint aPoint,RWriteStream& aStream); sl@0: IMPORT_C void ExternalizeL(TSize aSize,RWriteStream& aStream); sl@0: IMPORT_C void ExternalizeL(const TRect& aRect,RWriteStream& aStream); sl@0: IMPORT_C void InternalizeL(TPoint& aPoint,RReadStream& aStream); sl@0: IMPORT_C void InternalizeL(TSize& aSize,RReadStream& aStream); sl@0: IMPORT_C void InternalizeL(TRect& aRect,RReadStream& aStream); sl@0: sl@0: IMPORT_C void ExternalizeL(const CBufBase& aBuf,RWriteStream& aStream); sl@0: IMPORT_C void InternalizeL(CBufBase& aBuf,RReadStream& aStream); sl@0: sl@0: IMPORT_C void ArrayExternalizeCountL(TInt aCount,RWriteStream& aStream); sl@0: IMPORT_C void DoExternalizeAllL(const CArrayFixBase& anArray,RWriteStream& aStream,TExternalizer anExter); sl@0: IMPORT_C TInt ArrayInternalizeCountL(RReadStream& aStream); sl@0: IMPORT_C void DoInternalizeAllL(CArrayFixBase& anArray,RReadStream& aStream,TInternalizer anInter); sl@0: sl@0: template sl@0: inline void ExternalizeCountL(const CArrayFix& anArray,RWriteStream& aStream) sl@0: {ArrayExternalizeCountL(anArray.Count(),aStream);} sl@0: template sl@0: inline void ExternalizeAllL(const CArrayFix& anArray,RWriteStream& aStream) sl@0: {DoExternalizeAllL(anArray,aStream,TExternalizer::Function());} sl@0: template sl@0: void InternalizeCountL(CArrayFix& anArray,RReadStream& aStream) sl@0: { sl@0: TInt n=ArrayInternalizeCountL(aStream); sl@0: anArray.ResizeL(n); sl@0: } sl@0: template sl@0: inline void InternalizeAllL(CArrayFix& anArray,RReadStream& aStream) sl@0: {DoInternalizeAllL(anArray,aStream,TInternalizer::Function());} sl@0: sl@0: template sl@0: void ExternalizeL(const CArrayFix& anArray,RWriteStream& aStream) sl@0: { sl@0: ExternalizeCountL(anArray,aStream); sl@0: ExternalizeAllL(anArray,aStream); sl@0: } sl@0: template sl@0: void InternalizeL(CArrayFix& anArray,RReadStream& aStream) sl@0: { sl@0: InternalizeCountL(anArray,aStream); sl@0: InternalizeAllL(anArray,aStream); sl@0: } sl@0: sl@0: template sl@0: inline void ExternalizeL(const T* aPtr,RWriteStream& aStream) sl@0: {aStream<::Function());} sl@0: sl@0: template sl@0: inline void DoExternalizeL(const T& anObject,RWriteStream& aStream,Externalize::Member) sl@0: {anObject.ExternalizeL(aStream);} sl@0: template sl@0: inline void DoInternalizeL(T& anObject,RReadStream& aStream,Internalize::Member) sl@0: {anObject.InternalizeL(aStream);} sl@0: sl@0: template sl@0: inline void DoExternalizeL(const T& anObject,RWriteStream& aStream,Externalize::Function) sl@0: {ExternalizeL(anObject,aStream);} sl@0: template sl@0: inline void DoInternalizeL(T& anObject,RReadStream& aStream,Internalize::Function) sl@0: {InternalizeL(anObject,aStream);} sl@0: sl@0: // Externalization and internalization selectors sl@0: inline Externalize::Member Externalization(const TAny*) sl@0: {return Externalize::Member();} sl@0: inline Internalize::Member Internalization(TAny*) sl@0: {return Internalize::Member();} sl@0: sl@0: inline Externalize::Function Externalization(const TDesC8*) sl@0: {return Externalize::Function();} sl@0: inline Externalize::Function Externalization(const TDesC16*) sl@0: {return Externalize::Function();} sl@0: inline Internalize::Function Internalization(TDes8*) sl@0: {return Internalize::Function();} sl@0: inline Internalize::Function Internalization(TDes16*) sl@0: {return Internalize::Function();} sl@0: sl@0: inline Externalize::Function Externalization(const CBufBase*) sl@0: {return Externalize::Function();} sl@0: inline Externalize::Function Externalization(const CArrayFixBase*) sl@0: {return Externalize::Function();} sl@0: inline Internalize::Function Internalization(CBufBase*) sl@0: {return Internalize::Function();} sl@0: inline Internalize::Function Internalization(CArrayFixBase*) sl@0: {return Internalize::Function();} sl@0: sl@0: template sl@0: inline Externalize::Function Externalization(T*const*) sl@0: {return Externalize::Function();} sl@0: sl@0: // Input and output operators sl@0: template sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const T& anObject) sl@0: {DoExternalizeL(anObject,aStream,Externalization(&anObject));return aStream;} sl@0: template sl@0: inline RReadStream& operator>>(RReadStream& aStream,T& anObject) sl@0: {DoInternalizeL(anObject,aStream,Internalization(&anObject));return aStream;} sl@0: sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TInt8& anInt8) sl@0: {aStream.WriteInt8L(anInt8);return aStream;} sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TInt16& anInt16) sl@0: {aStream.WriteInt16L(anInt16);return aStream;} sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TInt32& anInt32) sl@0: {aStream.WriteInt32L(anInt32);return aStream;} sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TUint8& aUint8) sl@0: {aStream.WriteUint8L(aUint8);return aStream;} sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TUint16& aUint16) sl@0: {aStream.WriteUint16L(aUint16);return aStream;} sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TUint32& aUint32) sl@0: {aStream.WriteUint32L(aUint32);return aStream;} sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TReal32& aReal32) sl@0: {aStream.WriteReal32L(aReal32);return aStream;} sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TReal64& aReal64) sl@0: {aStream.WriteReal64L(aReal64);return aStream;} sl@0: sl@0: inline RReadStream& operator>>(RReadStream& aStream,TInt8& anInt8) sl@0: {anInt8=aStream.ReadInt8L();return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TInt16& anInt16) sl@0: {anInt16=aStream.ReadInt16L();return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TInt32& anInt32) sl@0: {anInt32=aStream.ReadInt32L();return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TUint8& aUint8) sl@0: {aUint8=aStream.ReadUint8L();return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TUint16& aUint16) sl@0: {aUint16=aStream.ReadUint16L();return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TUint32& aUint32) sl@0: {aUint32=aStream.ReadUint32L();return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TReal32& aReal32) sl@0: {aReal32=aStream.ReadReal32L();return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TReal64& aReal64) sl@0: {aReal64=aStream.ReadReal64L();return aStream;} sl@0: sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TInt64& anInt64) sl@0: {ExternalizeL(anInt64,aStream);return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TInt64& anInt64) sl@0: {InternalizeL(anInt64,aStream);return aStream;} sl@0: sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TUid& aUid) sl@0: {return aStream<>(RReadStream& aStream,TUid& aUid) sl@0: {return aStream>>aUid.iUid;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TCheckedUid& aUid) sl@0: {InternalizeL(aUid,aStream);return aStream;} sl@0: sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TPoint& aPoint) sl@0: {ExternalizeL(aPoint,aStream);return aStream;} sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TSize& aSize) sl@0: {ExternalizeL(aSize,aStream);return aStream;} sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TRect& aRect) sl@0: {ExternalizeL(aRect,aStream);return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TPoint& aPoint) sl@0: {InternalizeL(aPoint,aStream);return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TSize& aSize) sl@0: {InternalizeL(aSize,aStream);return aStream;} sl@0: inline RReadStream& operator>>(RReadStream& aStream,TRect& aRect) sl@0: {InternalizeL(aRect,aStream);return aStream;} sl@0: sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,const TStreamRef& aRef) sl@0: {aRef.ExternalizeL(aStream);return aStream;} sl@0: