epoc32/include/s32mem.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 s32mem.h
     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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #if !defined(__S32MEM_H__)
       
    17 #define __S32MEM_H__
       
    18 #if !defined(__S32BUF_H__)
       
    19 #include <s32buf.h>
       
    20 #endif
       
    21 #if !defined(__S32STOR_H__)
       
    22 #include <s32stor.h>
       
    23 #endif
       
    24 
       
    25 /**
       
    26  * @publishedAll 
       
    27  * @released
       
    28  * A stream buffer that uses plain memory for its implementation.
       
    29 
       
    30 A stream of this type is used by RMemWriteStream and RMemReadStream objects. 
       
    31 It also has intermediate buffering capabilities.
       
    32 
       
    33 This is a seekable stream buffer.
       
    34 
       
    35 @see RMemWriteStream
       
    36 @see RMemReadStream  
       
    37 */
       
    38 class TMemBuf : public TStreamBuf
       
    39 	{
       
    40 public:
       
    41 	IMPORT_C TMemBuf();
       
    42 	IMPORT_C void Set(TUint8* aPtr,TUint8* anEnd,TInt aMode=ERead|EWrite);
       
    43 protected:
       
    44 	IMPORT_C TInt UnderflowL(TInt aMaxLength);
       
    45 	IMPORT_C void OverflowL();
       
    46 	IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);
       
    47 private:
       
    48 	inline TUint8* Base() const;
       
    49 	inline TUint8* End() const;
       
    50 private:
       
    51 	TUint8* iBase;
       
    52 	};
       
    53 
       
    54 /**
       
    55  * @publishedAll 
       
    56  * @released
       
    57  * A stream buffer that uses a descriptor for its implementation.
       
    58 
       
    59 A stream of this type is used by RDesWriteStream and RDesReadStream objects. 
       
    60 It also has intermediate buffering capabilities.
       
    61 
       
    62 This is a seekable stream buffer.
       
    63 
       
    64 When used in write mode, the length of the descriptor is only updated when 
       
    65 the stream buffer's SynchL() function is called, i.e. as a result of a call 
       
    66 to RWriteStream::CommitL().
       
    67 
       
    68 @see RDesWriteStream
       
    69 @see RDesReadStream
       
    70 @see RWriteStream::CommitL()
       
    71 @see MStreamBuf::SynchL()  
       
    72 */
       
    73 class TDesBuf : public TStreamBuf
       
    74 	{
       
    75 public:
       
    76 	IMPORT_C TDesBuf();
       
    77 	IMPORT_C void Set(TDes8& aDes,TInt aMode=ERead|EWrite);
       
    78 protected:
       
    79 	IMPORT_C TInt UnderflowL(TInt aMaxLength);
       
    80 	IMPORT_C void OverflowL();
       
    81 	IMPORT_C void DoSynchL();
       
    82 	IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);
       
    83 private:
       
    84 	inline TDes8& Des() const;
       
    85 	inline TUint8* Base() const;
       
    86  	void Consolidate();
       
    87 private:
       
    88 	TDes8* iDes;
       
    89 	};
       
    90 
       
    91 /**
       
    92  * @publishedAll 
       
    93  * @released
       
    94  * A stream buffer that uses a dynamic buffer for its implementation.
       
    95 
       
    96 A stream of this type is used by RBufWriteStream and RBufReadStream objects. 
       
    97 It also has intermediate buffering capabilities.
       
    98 
       
    99 This is a seekable stream buffer.
       
   100 
       
   101 There are three write modes:
       
   102 
       
   103 insert mode - inserts new data into the buffer at the offset passed to Set()
       
   104 
       
   105 overwrite mode - replaces the data in the buffer starting at the offset passed 
       
   106 to Set(). Once the end of the buffer is reached, it is automatically extended 
       
   107 as more data is written. This is the default mode.
       
   108 
       
   109 truncate mode - truncates the buffer to the offset passed to Set() before 
       
   110 data is written, extending the buffer. When writing, the buffer size as reported 
       
   111 by CBufBase::Size() may be larger than the data written to the stream. To 
       
   112 synchronise the buffer's reported size with the stream, call the MStreamBuf::SynchL() 
       
   113 function.
       
   114 
       
   115 Note that this object never takes ownership of the dynamic buffer, the CBufBase 
       
   116 type object.
       
   117 
       
   118 @see RBufWriteStream
       
   119 @see RBufReadStream
       
   120 @see CBufBase::Size()
       
   121 @see MStreamBuf::SynchL() 
       
   122 */
       
   123 class TBufBuf : public TStreamBuf
       
   124 	{
       
   125 public:
       
   126 	enum {ETruncate=0x10,EInsert=0x20};
       
   127 public:
       
   128 	IMPORT_C TBufBuf();
       
   129 	IMPORT_C void Set(CBufBase& aBuf,TInt aPos,TInt aMode=ERead|EWrite);
       
   130 protected:
       
   131 	IMPORT_C TInt UnderflowL(TInt aMaxLength);
       
   132 	IMPORT_C void OverflowL();
       
   133 	IMPORT_C void DoSynchL();
       
   134 	IMPORT_C void DoWriteL(const TAny* aPtr,TInt aLength);
       
   135 	IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);
       
   136 private:
       
   137 	inline CBufBase& Buf() const;
       
   138  	void Consolidate();
       
   139 //
       
   140 	void SetPos(TMark aMark,TInt aPos);
       
   141 	inline void SetPos(TRead,TInt aPos);
       
   142 	inline void SetPos(TWrite,TInt aPos);
       
   143 	TInt Pos(TMark aMark) const;
       
   144 	inline TInt Pos(TRead) const;
       
   145 	inline TInt Pos(TWrite) const;
       
   146 	inline TInt MovePos(TRead,TInt anOffset);
       
   147 	inline TInt MovePos(TWrite,TInt anOffset);
       
   148 	inline TInt Mark(TRead) const;
       
   149 	inline TInt Mark(TWrite) const;
       
   150 private:
       
   151 	CBufBase* iBuf;
       
   152 	TInt iRPos;
       
   153 	TInt iWPos;
       
   154 	TInt iMode;
       
   155 	};
       
   156 
       
   157 /**
       
   158 @publishedAll 
       
   159 @released
       
   160 
       
   161 Supports the reading of a stream from a pointer of any type.
       
   162 
       
   163 @see TMemBuf
       
   164 @see RReadStream 
       
   165  */
       
   166 class RMemReadStream : public RReadStream
       
   167 	{
       
   168 public:
       
   169 	RMemReadStream() {}
       
   170 	IMPORT_C RMemReadStream(const TAny* aPtr,TInt aLength);
       
   171 	IMPORT_C void Open(const TAny* aPtr,TInt aLength);
       
   172 private:
       
   173 	TMemBuf iSource;
       
   174 	};
       
   175 
       
   176 /**
       
   177 @publishedAll 
       
   178 @released
       
   179 
       
   180 Supports the writing of a stream to a pointer of any type.
       
   181 
       
   182 @see TMemBuf
       
   183 @see RWriteStream 
       
   184  */
       
   185 class RMemWriteStream : public RWriteStream
       
   186 	{
       
   187 public:
       
   188 	RMemWriteStream() {}
       
   189 	inline RMemWriteStream(const MExternalizer<TStreamRef>& anExter);
       
   190 	IMPORT_C RMemWriteStream(TAny* aPtr,TInt aMaxLength);
       
   191 	IMPORT_C void Open(TAny* aPtr,TInt aMaxLength);
       
   192 private:
       
   193 	TMemBuf iSink;
       
   194 	};
       
   195 
       
   196 /**
       
   197 @publishedAll 
       
   198 @released
       
   199 
       
   200 Supports the reading of a stream from an 8-bit descriptor.
       
   201 
       
   202 @see TMemBuf
       
   203 @see RReadStream 
       
   204 */
       
   205 class RDesReadStream : public RReadStream
       
   206 	{
       
   207 public:
       
   208 	RDesReadStream() {}
       
   209 	IMPORT_C RDesReadStream(const TDesC8& aDes);
       
   210 	IMPORT_C void Open(const TDesC8& aDes);
       
   211 private:
       
   212 	TMemBuf iSource;
       
   213 	};
       
   214 
       
   215 /**
       
   216 @publishedAll 
       
   217 @released
       
   218 
       
   219 Supports the writing of a stream to an 8-bit descriptor.
       
   220 
       
   221 @see TDesBuf
       
   222 @see RWriteStream 
       
   223  */
       
   224 class RDesWriteStream : public RWriteStream
       
   225 	{
       
   226 public:
       
   227 	RDesWriteStream() {}
       
   228 	inline RDesWriteStream(const MExternalizer<TStreamRef>& anExter);
       
   229 	IMPORT_C RDesWriteStream(TDes8& aDes);
       
   230 	IMPORT_C void Open(TDes8& aDes);
       
   231 private:
       
   232 	TDesBuf iSink;
       
   233 	};
       
   234 
       
   235 /**
       
   236 @publishedAll 
       
   237 @released
       
   238 
       
   239 Supports the reading of a stream from a dynamic buffer.
       
   240 
       
   241 @see TBufBuf
       
   242 @see RReadStream 
       
   243 */
       
   244 class RBufReadStream : public RReadStream
       
   245 	{
       
   246 public:
       
   247 	RBufReadStream() {}
       
   248 	IMPORT_C RBufReadStream(const CBufBase& aBuf,TInt aPos=0);
       
   249 	IMPORT_C void Open(const CBufBase& aBuf,TInt aPos=0);
       
   250 private:
       
   251 	TBufBuf iSource;
       
   252 	};
       
   253 
       
   254 /**
       
   255 @publishedAll 
       
   256 @released
       
   257 
       
   258 Supports the writing of a stream to a dynamic buffer.
       
   259 
       
   260 @see TBufBuf
       
   261 @see RWriteStream 
       
   262  */
       
   263 class RBufWriteStream : public RWriteStream
       
   264 	{
       
   265 public:
       
   266 	RBufWriteStream() {}
       
   267 	inline RBufWriteStream(const MExternalizer<TStreamRef>& anExter);
       
   268 	IMPORT_C RBufWriteStream(CBufBase& aBuf,TInt aPos=0);
       
   269 	IMPORT_C void Open(CBufBase& aBuf,TInt aPos=0);
       
   270 	IMPORT_C void Truncate(CBufBase& aBuf,TInt aPos=0);
       
   271 	IMPORT_C void Insert(CBufBase& aBuf,TInt aPos);
       
   272 	inline void Append(CBufBase& aBuf);
       
   273 private:
       
   274 	TBufBuf iSink;
       
   275 	};
       
   276 
       
   277 /**
       
   278  * @publishedAll 
       
   279  * @released
       
   280  * In-memory non-persistent store. The buffer store does not have a root stream 
       
   281 and cannot be closed without losing all the data.
       
   282 
       
   283 It implements many of the operations defined by the store abstract framework. 
       
   284 Specifically, streams in this store can be: overwritten, replaced, appended, 
       
   285 deleted, and created in advance of being written to. However the class does 
       
   286 not support commit and revert operations.
       
   287 
       
   288 Overwriting an existing stream can result in a shorter stream; however, a 
       
   289 stream cannot be extended beyond its original length. Replacing a stream can 
       
   290 result in a stream which is longer or shorter than the original. The order 
       
   291 in which streams are written to a memory store is not important as streams 
       
   292 can be changed and rewritten.  
       
   293 */
       
   294 class CBufStore : public CStreamStore
       
   295 	{
       
   296 public:
       
   297 	IMPORT_C static CBufStore* NewL(TInt anExpandSize);
       
   298 	IMPORT_C static CBufStore* NewLC(TInt anExpandSize);
       
   299 	IMPORT_C CBufStore(TInt anExpandSize);
       
   300 	IMPORT_C ~CBufStore();
       
   301 protected:
       
   302 	IMPORT_C TStreamId DoExtendL();
       
   303 	IMPORT_C void DoDeleteL(TStreamId anId);
       
   304 	IMPORT_C MStreamBuf* DoReadL(TStreamId anId) const;
       
   305 	IMPORT_C MStreamBuf* DoCreateL(TStreamId& anId);
       
   306 	IMPORT_C MStreamBuf* DoWriteL(TStreamId anId);
       
   307 	IMPORT_C MStreamBuf* DoReplaceL(TStreamId anId);
       
   308 private:
       
   309 	CBufSeg& BufL(TStreamId anId) const;
       
   310 private:
       
   311 	CArrayFixFlat<CBufSeg*> iBufArray;
       
   312 	TInt iExpandSize;
       
   313 	};		
       
   314 
       
   315 #include <s32mem.inl>
       
   316 #endif