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