1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/store/INC/S32MEM.H Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,352 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#if !defined(__S32MEM_H__)
1.20 +#define __S32MEM_H__
1.21 +#if !defined(__S32BUF_H__)
1.22 +#include <s32buf.h>
1.23 +#endif
1.24 +#if !defined(__S32STOR_H__)
1.25 +#include <s32stor.h>
1.26 +#endif
1.27 +
1.28 +/**
1.29 + * @publishedAll
1.30 + * @released
1.31 + * A stream buffer that uses plain memory for its implementation.
1.32 +
1.33 +A stream of this type is used by RMemWriteStream and RMemReadStream objects.
1.34 +It also has intermediate buffering capabilities.
1.35 +
1.36 +This is a seekable stream buffer.
1.37 +
1.38 +@see RMemWriteStream
1.39 +@see RMemReadStream
1.40 +*/
1.41 +class TMemBuf : public TStreamBuf
1.42 + {
1.43 +public:
1.44 + IMPORT_C TMemBuf();
1.45 + IMPORT_C void Set(TUint8* aPtr,TUint8* anEnd,TInt aMode=ERead|EWrite);
1.46 +protected:
1.47 + IMPORT_C TInt UnderflowL(TInt aMaxLength);
1.48 + IMPORT_C void OverflowL();
1.49 + IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);
1.50 +private:
1.51 + inline TUint8* Base() const;
1.52 + inline TUint8* End() const;
1.53 +private:
1.54 + TUint8* iBase;
1.55 + };
1.56 +
1.57 +/**
1.58 + * @publishedAll
1.59 + * @released
1.60 + * A stream buffer that uses a descriptor for its implementation.
1.61 +
1.62 +A stream of this type is used by RDesWriteStream and RDesReadStream objects.
1.63 +It also has intermediate buffering capabilities.
1.64 +
1.65 +This is a seekable stream buffer.
1.66 +
1.67 +When used in write mode, the length of the descriptor is only updated when
1.68 +the stream buffer's SynchL() function is called, i.e. as a result of a call
1.69 +to RWriteStream::CommitL().
1.70 +
1.71 +@see RDesWriteStream
1.72 +@see RDesReadStream
1.73 +@see RWriteStream::CommitL()
1.74 +@see MStreamBuf::SynchL()
1.75 +*/
1.76 +class TDesBuf : public TStreamBuf
1.77 + {
1.78 +public:
1.79 + IMPORT_C TDesBuf();
1.80 + IMPORT_C void Set(TDes8& aDes,TInt aMode=ERead|EWrite);
1.81 +protected:
1.82 + IMPORT_C TInt UnderflowL(TInt aMaxLength);
1.83 + IMPORT_C void OverflowL();
1.84 + IMPORT_C void DoSynchL();
1.85 + IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);
1.86 +private:
1.87 + inline TDes8& Des() const;
1.88 + inline TUint8* Base() const;
1.89 + void Consolidate();
1.90 +private:
1.91 + TDes8* iDes;
1.92 + };
1.93 +
1.94 +/**
1.95 + * @publishedAll
1.96 + * @released
1.97 + * A stream buffer that uses a dynamic buffer for its implementation.
1.98 +
1.99 +A stream of this type is used by RBufWriteStream and RBufReadStream objects.
1.100 +It also has intermediate buffering capabilities.
1.101 +
1.102 +This is a seekable stream buffer.
1.103 +
1.104 +There are three write modes:
1.105 +
1.106 +insert mode - inserts new data into the buffer at the offset passed to Set()
1.107 +
1.108 +overwrite mode - replaces the data in the buffer starting at the offset passed
1.109 +to Set(). Once the end of the buffer is reached, it is automatically extended
1.110 +as more data is written. This is the default mode.
1.111 +
1.112 +truncate mode - truncates the buffer to the offset passed to Set() before
1.113 +data is written, extending the buffer. When writing, the buffer size as reported
1.114 +by CBufBase::Size() may be larger than the data written to the stream. To
1.115 +synchronise the buffer's reported size with the stream, call the MStreamBuf::SynchL()
1.116 +function.
1.117 +
1.118 +Note that this object never takes ownership of the dynamic buffer, the CBufBase
1.119 +type object.
1.120 +
1.121 +@see RBufWriteStream
1.122 +@see RBufReadStream
1.123 +@see CBufBase::Size()
1.124 +@see MStreamBuf::SynchL()
1.125 +*/
1.126 +class TBufBuf : public TStreamBuf
1.127 + {
1.128 +public:
1.129 + enum {ETruncate=0x10,EInsert=0x20};
1.130 +public:
1.131 + IMPORT_C TBufBuf();
1.132 + IMPORT_C void Set(CBufBase& aBuf,TInt aPos,TInt aMode=ERead|EWrite);
1.133 +protected:
1.134 + IMPORT_C TInt UnderflowL(TInt aMaxLength);
1.135 + IMPORT_C void OverflowL();
1.136 + IMPORT_C void DoSynchL();
1.137 + IMPORT_C void DoWriteL(const TAny* aPtr,TInt aLength);
1.138 + IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);
1.139 +private:
1.140 + inline CBufBase& Buf() const;
1.141 + void Consolidate();
1.142 +//
1.143 + void SetPos(TMark aMark,TInt aPos);
1.144 + inline void SetPos(TRead,TInt aPos);
1.145 + inline void SetPos(TWrite,TInt aPos);
1.146 + TInt Pos(TMark aMark) const;
1.147 + inline TInt Pos(TRead) const;
1.148 + inline TInt Pos(TWrite) const;
1.149 + inline TInt MovePos(TRead,TInt anOffset);
1.150 + inline TInt MovePos(TWrite,TInt anOffset);
1.151 + inline TInt Mark(TRead) const;
1.152 + inline TInt Mark(TWrite) const;
1.153 +private:
1.154 + CBufBase* iBuf;
1.155 + TInt iRPos;
1.156 + TInt iWPos;
1.157 + TInt iMode;
1.158 + };
1.159 +
1.160 +/**
1.161 +@publishedAll
1.162 +@released
1.163 +
1.164 +Supports the reading of a stream from a pointer of any type.
1.165 +
1.166 +@see TMemBuf
1.167 +@see RReadStream
1.168 + */
1.169 +class RMemReadStream : public RReadStream
1.170 + {
1.171 +public:
1.172 +/**
1.173 +Constructs an empty object.
1.174 +
1.175 +Call Open() to prepare the stream for reading.
1.176 +*/
1.177 + RMemReadStream() {}
1.178 + IMPORT_C RMemReadStream(const TAny* aPtr,TInt aLength);
1.179 + IMPORT_C void Open(const TAny* aPtr,TInt aLength);
1.180 +private:
1.181 + TMemBuf iSource;
1.182 + };
1.183 +
1.184 +/**
1.185 +@publishedAll
1.186 +@released
1.187 +
1.188 +Supports the writing of a stream to a pointer of any type.
1.189 +
1.190 +@see TMemBuf
1.191 +@see RWriteStream
1.192 + */
1.193 +class RMemWriteStream : public RWriteStream
1.194 + {
1.195 +public:
1.196 +/**
1.197 +Constructs an empty write stream object.
1.198 +
1.199 +Call Open() to prepare a stream for writing.
1.200 +*/
1.201 + RMemWriteStream() {}
1.202 + inline RMemWriteStream(const MExternalizer<TStreamRef>& anExter);
1.203 + IMPORT_C RMemWriteStream(TAny* aPtr,TInt aMaxLength);
1.204 + IMPORT_C void Open(TAny* aPtr,TInt aMaxLength);
1.205 +private:
1.206 + TMemBuf iSink;
1.207 + };
1.208 +
1.209 +/**
1.210 +@publishedAll
1.211 +@released
1.212 +
1.213 +Supports the reading of a stream from an 8-bit descriptor.
1.214 +
1.215 +@see TMemBuf
1.216 +@see RReadStream
1.217 +*/
1.218 +class RDesReadStream : public RReadStream
1.219 + {
1.220 +public:
1.221 +/**
1.222 +Constructs an empty read stream object.
1.223 +
1.224 +Call Open() to prepare the stream for reading.
1.225 +*/
1.226 + RDesReadStream() {}
1.227 + IMPORT_C RDesReadStream(const TDesC8& aDes);
1.228 + IMPORT_C void Open(const TDesC8& aDes);
1.229 +private:
1.230 + TMemBuf iSource;
1.231 + };
1.232 +
1.233 +/**
1.234 +@publishedAll
1.235 +@released
1.236 +
1.237 +Supports the writing of a stream to a stream buffer hosted by an 8-bit descriptor.
1.238 +
1.239 +@see TDesBuf
1.240 +@see RWriteStream
1.241 + */
1.242 +class RDesWriteStream : public RWriteStream
1.243 + {
1.244 +public:
1.245 +/**
1.246 +Constructs an empty write stream object.
1.247 +
1.248 +Call Open() to prepare a stream for writing.
1.249 +*/
1.250 + RDesWriteStream() {}
1.251 + inline RDesWriteStream(const MExternalizer<TStreamRef>& anExter);
1.252 + IMPORT_C RDesWriteStream(TDes8& aDes);
1.253 + IMPORT_C void Open(TDes8& aDes);
1.254 +private:
1.255 + TDesBuf iSink;
1.256 + };
1.257 +
1.258 +/**
1.259 +@publishedAll
1.260 +@released
1.261 +
1.262 +Supports the opening of an existing stream hosted by a dynamic buffer.
1.263 +The stream does not take ownership of the dynamic buffer, which means
1.264 +that the creator is responsible for deleting the buffer when it is no
1.265 +longer needed.
1.266 +
1.267 +@see TBufBuf
1.268 +@see RReadStream
1.269 +*/
1.270 +class RBufReadStream : public RReadStream
1.271 + {
1.272 +public:
1.273 +/**
1.274 +Constructs an empty read stream object.
1.275 +
1.276 +Call Open() to prepare the stream for reading.
1.277 +*/
1.278 + RBufReadStream() {}
1.279 + IMPORT_C RBufReadStream(const CBufBase& aBuf,TInt aPos=0);
1.280 + IMPORT_C void Open(const CBufBase& aBuf,TInt aPos=0);
1.281 +private:
1.282 + TBufBuf iSource;
1.283 + };
1.284 +
1.285 +/**
1.286 +@publishedAll
1.287 +@released
1.288 +
1.289 +Supports the writing of a stream to a dynamic buffer. The stream does
1.290 +not take ownership of the dynamic buffer, which means that the creator
1.291 +is responsible for deleting the buffer when it is no longer needed.
1.292 +
1.293 +@see TBufBuf
1.294 +@see RWriteStream
1.295 + */
1.296 +class RBufWriteStream : public RWriteStream
1.297 + {
1.298 +public:
1.299 +/**
1.300 +Default constructor. Constructs an empty write stream object.
1.301 +
1.302 +Call Open(), Truncate() or Insert() to prepare a stream for writing.
1.303 +*/
1.304 + RBufWriteStream() {}
1.305 +
1.306 + inline RBufWriteStream(const MExternalizer<TStreamRef>& anExter);
1.307 + IMPORT_C RBufWriteStream(CBufBase& aBuf,TInt aPos=0);
1.308 + IMPORT_C void Open(CBufBase& aBuf,TInt aPos=0);
1.309 + IMPORT_C void Truncate(CBufBase& aBuf,TInt aPos=0);
1.310 + IMPORT_C void Insert(CBufBase& aBuf,TInt aPos);
1.311 + inline void Append(CBufBase& aBuf);
1.312 +private:
1.313 + TBufBuf iSink;
1.314 + };
1.315 +
1.316 +/**
1.317 + * @publishedAll
1.318 + * @released
1.319 + * In-memory non-persistent store. The buffer store does not have a root stream
1.320 +and cannot be closed without losing all the data.
1.321 +
1.322 +It implements many of the operations defined by the store abstract framework.
1.323 +Specifically, streams in this store can be: overwritten, replaced, appended,
1.324 +deleted, and created in advance of being written to. However the class does
1.325 +not support commit and revert operations.
1.326 +
1.327 +Overwriting an existing stream can result in a shorter stream; however, a
1.328 +stream cannot be extended beyond its original length. Replacing a stream can
1.329 +result in a stream which is longer or shorter than the original. The order
1.330 +in which streams are written to a memory store is not important as streams
1.331 +can be changed and rewritten.
1.332 +*/
1.333 +class CBufStore : public CStreamStore
1.334 + {
1.335 +public:
1.336 + IMPORT_C static CBufStore* NewL(TInt anExpandSize);
1.337 + IMPORT_C static CBufStore* NewLC(TInt anExpandSize);
1.338 + IMPORT_C CBufStore(TInt anExpandSize);
1.339 + IMPORT_C ~CBufStore();
1.340 +protected:
1.341 + IMPORT_C TStreamId DoExtendL();
1.342 + IMPORT_C void DoDeleteL(TStreamId anId);
1.343 + IMPORT_C MStreamBuf* DoReadL(TStreamId anId) const;
1.344 + IMPORT_C MStreamBuf* DoCreateL(TStreamId& anId);
1.345 + IMPORT_C MStreamBuf* DoWriteL(TStreamId anId);
1.346 + IMPORT_C MStreamBuf* DoReplaceL(TStreamId anId);
1.347 +private:
1.348 + CBufSeg& BufL(TStreamId anId) const;
1.349 +private:
1.350 + CArrayFixFlat<CBufSeg*> iBufArray;
1.351 + TInt iExpandSize;
1.352 + };
1.353 +
1.354 +#include <s32mem.inl>
1.355 +#endif