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: #if !defined(__S32MEM_H__) sl@0: #define __S32MEM_H__ sl@0: #if !defined(__S32BUF_H__) sl@0: #include sl@0: #endif sl@0: #if !defined(__S32STOR_H__) sl@0: #include sl@0: #endif sl@0: sl@0: /** sl@0: * @publishedAll sl@0: * @released sl@0: * A stream buffer that uses plain memory for its implementation. sl@0: sl@0: A stream of this type is used by RMemWriteStream and RMemReadStream objects. sl@0: It also has intermediate buffering capabilities. sl@0: sl@0: This is a seekable stream buffer. sl@0: sl@0: @see RMemWriteStream sl@0: @see RMemReadStream sl@0: */ sl@0: class TMemBuf : public TStreamBuf sl@0: { sl@0: public: sl@0: IMPORT_C TMemBuf(); sl@0: IMPORT_C void Set(TUint8* aPtr,TUint8* anEnd,TInt aMode=ERead|EWrite); sl@0: protected: sl@0: IMPORT_C TInt UnderflowL(TInt aMaxLength); sl@0: IMPORT_C void OverflowL(); sl@0: IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset); sl@0: private: sl@0: inline TUint8* Base() const; sl@0: inline TUint8* End() const; sl@0: private: sl@0: TUint8* iBase; sl@0: }; sl@0: sl@0: /** sl@0: * @publishedAll sl@0: * @released sl@0: * A stream buffer that uses a descriptor for its implementation. sl@0: sl@0: A stream of this type is used by RDesWriteStream and RDesReadStream objects. sl@0: It also has intermediate buffering capabilities. sl@0: sl@0: This is a seekable stream buffer. sl@0: sl@0: When used in write mode, the length of the descriptor is only updated when sl@0: the stream buffer's SynchL() function is called, i.e. as a result of a call sl@0: to RWriteStream::CommitL(). sl@0: sl@0: @see RDesWriteStream sl@0: @see RDesReadStream sl@0: @see RWriteStream::CommitL() sl@0: @see MStreamBuf::SynchL() sl@0: */ sl@0: class TDesBuf : public TStreamBuf sl@0: { sl@0: public: sl@0: IMPORT_C TDesBuf(); sl@0: IMPORT_C void Set(TDes8& aDes,TInt aMode=ERead|EWrite); sl@0: protected: sl@0: IMPORT_C TInt UnderflowL(TInt aMaxLength); sl@0: IMPORT_C void OverflowL(); sl@0: IMPORT_C void DoSynchL(); sl@0: IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset); sl@0: private: sl@0: inline TDes8& Des() const; sl@0: inline TUint8* Base() const; sl@0: void Consolidate(); sl@0: private: sl@0: TDes8* iDes; sl@0: }; sl@0: sl@0: /** sl@0: * @publishedAll sl@0: * @released sl@0: * A stream buffer that uses a dynamic buffer for its implementation. sl@0: sl@0: A stream of this type is used by RBufWriteStream and RBufReadStream objects. sl@0: It also has intermediate buffering capabilities. sl@0: sl@0: This is a seekable stream buffer. sl@0: sl@0: There are three write modes: sl@0: sl@0: insert mode - inserts new data into the buffer at the offset passed to Set() sl@0: sl@0: overwrite mode - replaces the data in the buffer starting at the offset passed sl@0: to Set(). Once the end of the buffer is reached, it is automatically extended sl@0: as more data is written. This is the default mode. sl@0: sl@0: truncate mode - truncates the buffer to the offset passed to Set() before sl@0: data is written, extending the buffer. When writing, the buffer size as reported sl@0: by CBufBase::Size() may be larger than the data written to the stream. To sl@0: synchronise the buffer's reported size with the stream, call the MStreamBuf::SynchL() sl@0: function. sl@0: sl@0: Note that this object never takes ownership of the dynamic buffer, the CBufBase sl@0: type object. sl@0: sl@0: @see RBufWriteStream sl@0: @see RBufReadStream sl@0: @see CBufBase::Size() sl@0: @see MStreamBuf::SynchL() sl@0: */ sl@0: class TBufBuf : public TStreamBuf sl@0: { sl@0: public: sl@0: enum {ETruncate=0x10,EInsert=0x20}; sl@0: public: sl@0: IMPORT_C TBufBuf(); sl@0: IMPORT_C void Set(CBufBase& aBuf,TInt aPos,TInt aMode=ERead|EWrite); sl@0: protected: sl@0: IMPORT_C TInt UnderflowL(TInt aMaxLength); sl@0: IMPORT_C void OverflowL(); sl@0: IMPORT_C void DoSynchL(); sl@0: IMPORT_C void DoWriteL(const TAny* aPtr,TInt aLength); sl@0: IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset); sl@0: private: sl@0: inline CBufBase& Buf() const; sl@0: void Consolidate(); sl@0: // sl@0: void SetPos(TMark aMark,TInt aPos); sl@0: inline void SetPos(TRead,TInt aPos); sl@0: inline void SetPos(TWrite,TInt aPos); sl@0: TInt Pos(TMark aMark) const; sl@0: inline TInt Pos(TRead) const; sl@0: inline TInt Pos(TWrite) const; sl@0: inline TInt MovePos(TRead,TInt anOffset); sl@0: inline TInt MovePos(TWrite,TInt anOffset); sl@0: inline TInt Mark(TRead) const; sl@0: inline TInt Mark(TWrite) const; sl@0: private: sl@0: CBufBase* iBuf; sl@0: TInt iRPos; sl@0: TInt iWPos; sl@0: TInt iMode; sl@0: }; sl@0: sl@0: /** sl@0: @publishedAll sl@0: @released sl@0: sl@0: Supports the reading of a stream from a pointer of any type. sl@0: sl@0: @see TMemBuf sl@0: @see RReadStream sl@0: */ sl@0: class RMemReadStream : public RReadStream sl@0: { sl@0: public: sl@0: /** sl@0: Constructs an empty object. sl@0: sl@0: Call Open() to prepare the stream for reading. sl@0: */ sl@0: RMemReadStream() {} sl@0: IMPORT_C RMemReadStream(const TAny* aPtr,TInt aLength); sl@0: IMPORT_C void Open(const TAny* aPtr,TInt aLength); sl@0: private: sl@0: TMemBuf iSource; sl@0: }; sl@0: sl@0: /** sl@0: @publishedAll sl@0: @released sl@0: sl@0: Supports the writing of a stream to a pointer of any type. sl@0: sl@0: @see TMemBuf sl@0: @see RWriteStream sl@0: */ sl@0: class RMemWriteStream : public RWriteStream sl@0: { sl@0: public: sl@0: /** sl@0: Constructs an empty write stream object. sl@0: sl@0: Call Open() to prepare a stream for writing. sl@0: */ sl@0: RMemWriteStream() {} sl@0: inline RMemWriteStream(const MExternalizer& anExter); sl@0: IMPORT_C RMemWriteStream(TAny* aPtr,TInt aMaxLength); sl@0: IMPORT_C void Open(TAny* aPtr,TInt aMaxLength); sl@0: private: sl@0: TMemBuf iSink; sl@0: }; sl@0: sl@0: /** sl@0: @publishedAll sl@0: @released sl@0: sl@0: Supports the reading of a stream from an 8-bit descriptor. sl@0: sl@0: @see TMemBuf sl@0: @see RReadStream sl@0: */ sl@0: class RDesReadStream : public RReadStream sl@0: { sl@0: public: sl@0: /** sl@0: Constructs an empty read stream object. sl@0: sl@0: Call Open() to prepare the stream for reading. sl@0: */ sl@0: RDesReadStream() {} sl@0: IMPORT_C RDesReadStream(const TDesC8& aDes); sl@0: IMPORT_C void Open(const TDesC8& aDes); sl@0: private: sl@0: TMemBuf iSource; sl@0: }; sl@0: sl@0: /** sl@0: @publishedAll sl@0: @released sl@0: sl@0: Supports the writing of a stream to a stream buffer hosted by an 8-bit descriptor. sl@0: sl@0: @see TDesBuf sl@0: @see RWriteStream sl@0: */ sl@0: class RDesWriteStream : public RWriteStream sl@0: { sl@0: public: sl@0: /** sl@0: Constructs an empty write stream object. sl@0: sl@0: Call Open() to prepare a stream for writing. sl@0: */ sl@0: RDesWriteStream() {} sl@0: inline RDesWriteStream(const MExternalizer& anExter); sl@0: IMPORT_C RDesWriteStream(TDes8& aDes); sl@0: IMPORT_C void Open(TDes8& aDes); sl@0: private: sl@0: TDesBuf iSink; sl@0: }; sl@0: sl@0: /** sl@0: @publishedAll sl@0: @released sl@0: sl@0: Supports the opening of an existing stream hosted by a dynamic buffer. sl@0: The stream does not take ownership of the dynamic buffer, which means sl@0: that the creator is responsible for deleting the buffer when it is no sl@0: longer needed. sl@0: sl@0: @see TBufBuf sl@0: @see RReadStream sl@0: */ sl@0: class RBufReadStream : public RReadStream sl@0: { sl@0: public: sl@0: /** sl@0: Constructs an empty read stream object. sl@0: sl@0: Call Open() to prepare the stream for reading. sl@0: */ sl@0: RBufReadStream() {} sl@0: IMPORT_C RBufReadStream(const CBufBase& aBuf,TInt aPos=0); sl@0: IMPORT_C void Open(const CBufBase& aBuf,TInt aPos=0); sl@0: private: sl@0: TBufBuf iSource; sl@0: }; sl@0: sl@0: /** sl@0: @publishedAll sl@0: @released sl@0: sl@0: Supports the writing of a stream to a dynamic buffer. The stream does sl@0: not take ownership of the dynamic buffer, which means that the creator sl@0: is responsible for deleting the buffer when it is no longer needed. sl@0: sl@0: @see TBufBuf sl@0: @see RWriteStream sl@0: */ sl@0: class RBufWriteStream : public RWriteStream sl@0: { sl@0: public: sl@0: /** sl@0: Default constructor. Constructs an empty write stream object. sl@0: sl@0: Call Open(), Truncate() or Insert() to prepare a stream for writing. sl@0: */ sl@0: RBufWriteStream() {} sl@0: sl@0: inline RBufWriteStream(const MExternalizer& anExter); sl@0: IMPORT_C RBufWriteStream(CBufBase& aBuf,TInt aPos=0); sl@0: IMPORT_C void Open(CBufBase& aBuf,TInt aPos=0); sl@0: IMPORT_C void Truncate(CBufBase& aBuf,TInt aPos=0); sl@0: IMPORT_C void Insert(CBufBase& aBuf,TInt aPos); sl@0: inline void Append(CBufBase& aBuf); sl@0: private: sl@0: TBufBuf iSink; sl@0: }; sl@0: sl@0: /** sl@0: * @publishedAll sl@0: * @released sl@0: * In-memory non-persistent store. The buffer store does not have a root stream sl@0: and cannot be closed without losing all the data. sl@0: sl@0: It implements many of the operations defined by the store abstract framework. sl@0: Specifically, streams in this store can be: overwritten, replaced, appended, sl@0: deleted, and created in advance of being written to. However the class does sl@0: not support commit and revert operations. sl@0: sl@0: Overwriting an existing stream can result in a shorter stream; however, a sl@0: stream cannot be extended beyond its original length. Replacing a stream can sl@0: result in a stream which is longer or shorter than the original. The order sl@0: in which streams are written to a memory store is not important as streams sl@0: can be changed and rewritten. sl@0: */ sl@0: class CBufStore : public CStreamStore sl@0: { sl@0: public: sl@0: IMPORT_C static CBufStore* NewL(TInt anExpandSize); sl@0: IMPORT_C static CBufStore* NewLC(TInt anExpandSize); sl@0: IMPORT_C CBufStore(TInt anExpandSize); sl@0: IMPORT_C ~CBufStore(); sl@0: protected: sl@0: IMPORT_C TStreamId DoExtendL(); sl@0: IMPORT_C void DoDeleteL(TStreamId anId); sl@0: IMPORT_C MStreamBuf* DoReadL(TStreamId anId) const; sl@0: IMPORT_C MStreamBuf* DoCreateL(TStreamId& anId); sl@0: IMPORT_C MStreamBuf* DoWriteL(TStreamId anId); sl@0: IMPORT_C MStreamBuf* DoReplaceL(TStreamId anId); sl@0: private: sl@0: CBufSeg& BufL(TStreamId anId) const; sl@0: private: sl@0: CArrayFixFlat iBufArray; sl@0: TInt iExpandSize; sl@0: }; sl@0: sl@0: #include sl@0: #endif