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