os/persistentdata/persistentstorage/dbms/pcdbms/ustor/US_STD.H
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <e32std.h>
    17 #include <u32std.h>
    18 #include "D32REC.H"
    19 #include "D32STOR.H"
    20 #include <s32buf.h>
    21 //#include <s32crypt.h>
    22 #include <s32btree.h>
    23 #include <s32ucmp.h>
    24 //#include <e32hal.h>
    25 #include <e32math.h>
    26 #include "D32Assert.h"
    27 
    28 // classes defined
    29 class TDbStoreIndexStats;
    30 class CDbStoreIndexDef;
    31 class TRecordSize;
    32 class CDbStoreDef;
    33 class RClusterMap;
    34 class TClusterLinkCache;
    35 struct TClusterDes;
    36 class CCluster;
    37 class CClusterCache;
    38 class CDbStoreRecords;
    39 class CDbStoreBlobs;
    40 class CDbStoreIndex;
    41 class CDbStoreTable;
    42 class RDbStoreReadStream;
    43 class RDbStoreWriteStream;
    44 class MDbStreamFilter;
    45 class CDbStoreCompression;
    46 
    47 /**
    48 @internalComponent
    49 */
    50 enum TStorePanic
    51 	{
    52 	EDbUnimplemented,
    53 	EDbNoStore,
    54 	EDbCannotSeek,
    55 	EDbNotFixedFieldType,
    56 	EDbWrongType
    57 	};
    58 
    59 /**
    60 @internalComponent
    61 */
    62 GLREF_C void Panic(TStorePanic aPanic);
    63 
    64 /**
    65 @internalComponent
    66 */
    67 GLREF_D const TDbDriver KBuiltinDriver;
    68 
    69 /**
    70 @internalComponent
    71 */
    72 const TUid KDbmsStoreDatabase={268435561};
    73 
    74 /**
    75 @internalComponent
    76 */
    77 const TInt KDbStoreMaxRecordLength=0x200A;		// v5.10 32 nullable longtext columns
    78 const TInt KClusterLimit=0x1000;
    79 const TInt KMaxClustering=16;
    80 const TInt KBlobRefSize=sizeof(TDbBlobId)+sizeof(TInt32);
    81 const TInt KMinInlineLimit=16;
    82 const TInt KMaxIndexKeySize=248;
    83 
    84 /**
    85 @internalComponent
    86 */
    87 class TDbStoreIndexStats
    88 	{
    89 public:
    90 	/**
    91 	@internalComponent
    92 	*/
    93 	class TBound
    94 		{
    95 	public:
    96 		inline void Set(TReal64 aBound);
    97 		void Set(const TInt64& aBound);
    98 		void Set(const TText8* aPtr,TInt aLen,const TTextOps& aConv);
    99 		void Set(const TText16* aPtr,TInt aLen,const TTextOps& aConv);
   100 		void Set(const TDbLookupKey::SColumn& aBound,const TTextOps& aConv);
   101 	public:
   102 		TReal64 iValue;
   103 		};
   104 	enum TType {EContinuous,EDiscrete};
   105 public:
   106 	inline TDbStoreIndexStats();
   107 //
   108 	void InternalizeL(RReadStream& aStream);
   109 	void ExternalizeL(RWriteStream& aStream) const;
   110 //
   111 	inline void Reset(TInt aCardinality=0);
   112 	inline void Inc();
   113 	inline void Dec();
   114 	inline void Refresh(TType aType);
   115 //
   116 	inline TBool IsValid() const;
   117 	inline TBool NeedsRefresh() const;
   118 	inline TInt Cardinality() const;
   119 	TInt Span(TUint aInclusion,const TDbLookupKey* aLower,const TDbLookupKey* aUpper,const TTextOps& aConv) const;
   120 private:
   121 	inline void Touch();
   122 	TInt ReverseSpan(TUint aInclusion,const TDbLookupKey* aLower,const TDbLookupKey* aUpper,const TTextOps& aConv) const;
   123 private:
   124 	enum {ERefreshFactor=3};
   125 	enum {EInvalid=-1,ERefresh=0};
   126 	enum {ERefreshShift=2+ERefreshFactor,EFlagsMask=(1<<ERefreshShift)-1};
   127 	enum {EFlgDiscrete=0x1,EFlgClustering=0x2};
   128 private:
   129 	TInt iCardinality;
   130 	TInt iRefresh;
   131 	TUint iFlags;
   132 public:
   133 	TBound iLower;
   134 	TBound iUpper;
   135 	};
   136 
   137 /**
   138 @internalComponent
   139 */
   140 class CDbStoreIndexDef : public CDbTableIndexDef
   141 	{
   142 public:
   143 	static CDbStoreIndexDef* NewLC(const TDesC& aName,const CDbKey& aKey,const HDbColumnSet& aColumns);
   144 	static CDbStoreIndexDef* NewL(RReadStream& aStream);
   145 	void ExternalizeL(RWriteStream& aStream) const;
   146 	inline void SetTokenId(TStreamId anId);
   147 	inline TStreamId TokenId() const;
   148 //
   149 	static TInt KeySize(const TDbKeyCol& aKeyCol,const TDbColumnDef& aColumn);
   150 	static void CheckSizeL(const CDbKey& aKey,const HDbColumnSet& aColSet);
   151 private:
   152 	CDbStoreIndexDef();
   153 	static CDbStoreIndexDef* NewLC(const TDesC& aName);
   154 private:
   155 	TStreamId iTokenId;
   156 public:
   157 	__MUTABLE TDbStoreIndexStats iStats;	// cache the statistics here
   158 	};
   159 
   160 /**
   161 @internalComponent
   162 */
   163 class TRecordSize
   164 	{
   165 public:
   166 	TBool Set(const HDbColumnSet& aColumns);
   167 	inline TInt Clustering() const;
   168 	inline TInt InlineLimit() const;
   169 //
   170 	static void CheckSizeL(const HDbColumnSet& aColumns);
   171 	static TInt InlineLimit(const HDbColumnSet& aColumns);
   172 //
   173 	static inline TInt FixedFieldSize(TDbColType aType);
   174 private:
   175 	TInt iClustering;
   176 	TInt iInlineLimit;
   177 private:
   178 	static TUint8 const FieldSizes[];
   179 	};
   180 
   181 /**
   182 @internalComponent
   183 */
   184 NONSHARABLE_CLASS(CDbStoreDef) : public CDbTableDef
   185 	{
   186 public:
   187 	static CDbStoreDef* NewLC(const TDesC& aName,const CDbColSet& aColSet);
   188 	static CDbStoreDef* NewL(RReadStream& aStream);
   189 	void ExternalizeL(RWriteStream& aStream) const;
   190 	inline void SetTokenId(TStreamId anId);
   191 	inline TStreamId TokenId() const;
   192 	inline TInt Clustering() const;
   193 	inline TInt InlineLimit() const;
   194 	void Changed();
   195 private:
   196 	void AlteredColumnSetL(HDbColumnSet& aSet,const CDbColSet& aChange,const CDbColSet& aAdd);
   197 protected:
   198 	CDbStoreDef();
   199 private:
   200 	static CDbStoreDef* NewLC(const TDesC& aName,TInt aColumnCount);
   201 private:
   202 	TStreamId iTokenId;
   203 	TRecordSize iInfo;
   204 	};
   205 
   206 /**
   207 @internalComponent
   208 */
   209 typedef TUint32 TClusterId;
   210 
   211 /**
   212 @internalComponent
   213 */
   214 const TClusterId KNullClusterId=0;
   215 
   216 /**
   217 @internalComponent
   218 */
   219 inline TClusterId ClusterId(TDbRecordId aRecordId);
   220 inline TInt RecordIndex(TDbRecordId aRecordId);
   221 inline TDbRecordId RecordId(TClusterId aId,TInt aIndex);
   222 inline TClusterId ClusterId(TStreamId aStreamId);
   223 
   224 /**
   225 @internalComponent
   226 */
   227 class RClusterMap
   228 	{
   229 private:
   230 	enum {EGranularity=8};
   231 	class TIdPair
   232 		{
   233 	public:
   234 		TClusterId iId;
   235 		TClusterId iPreviousId;
   236 		};
   237 public:
   238 	enum {ESeparation=16};
   239 public:
   240 	inline RClusterMap();
   241 	inline void Close();
   242 //
   243 	void ResetL(TClusterId aHeadCluster);
   244 	inline void BindL(TClusterId aPrevious,TClusterId aCluster);
   245 	void Drop(TClusterId aCluster,TClusterId aNext);
   246 	TBool At(TClusterId aCluster,TClusterId& aPrevious);
   247 	inline TClusterId LastBound() const;
   248 	inline void Complete(TClusterId aLastCluster);
   249 	inline TBool IsComplete() const;
   250 private:
   251 	void AddL(TClusterId aCluster);
   252 	void InsertL(TClusterId aCluster,TClusterId aPrevious);
   253 	TIdPair* At(TClusterId aCluster);
   254 private:
   255 	TIdPair* iMap;
   256 	TInt iEntries;
   257 	TInt iAlloc;
   258 	TClusterId iLastBound;
   259 	TClusterId iLastMapped;
   260 	TInt iSkipped;
   261 	TBool iComplete;
   262 	};
   263 
   264 /**
   265 @internalComponent
   266 */
   267 class TClusterLinkCache
   268 	{
   269 public:
   270 	inline void Invalidate();
   271 	inline void Reset(TClusterId aBaseId);
   272 	inline void Bind(TClusterId aPrevious,TClusterId aCluster,RClusterMap& aMap);
   273 	void Add(const TClusterId* aFirst,const TClusterId* aLast);
   274 	void Drop(TClusterId aCluster,TClusterId aNext);
   275 	TBool Has(TClusterId aCluster) const;
   276 	TBool At(TClusterId aCluster,TClusterId& aPrevious) const;
   277 private:
   278 	void Add(TClusterId aCluster,RClusterMap& aMap);
   279 private:
   280 	TClusterId iMap[RClusterMap::ESeparation+1];
   281 	TClusterId* iEnd;
   282 	};
   283 
   284 /**
   285 @internalComponent
   286 */
   287 struct TClusterDes
   288 	{
   289 public:
   290 	void InternalizeL(RReadStream& aStream);
   291 	void ExternalizeL(RWriteStream& aStream) const;
   292 public:
   293 	TClusterId iNext;
   294 	TUint32 iMembership;
   295 	};
   296 
   297 /**
   298 @internalComponent
   299 */
   300 NONSHARABLE_CLASS(CCluster) : public CBase
   301 	{
   302 	friend class CClusterCache;
   303 private:
   304 	enum {EGranularity=0x200};
   305 	enum {EExpandBuffer=0x40};
   306 public:
   307 	/**
   308 	@internalComponent
   309 	*/
   310 	NONSHARABLE_CLASS(MAlter)
   311 		{
   312 	public:
   313 		virtual TInt RecordExpansion(const TUint8* aRec,TInt aLength);
   314 		virtual TUint8* AlterRecordL(TUint8* aWPtr,const TUint8* aRPtr,TInt aLength) =0;
   315 		};
   316 public:
   317 	static CCluster* NewL(CDbStoreDatabase& aDatabase);
   318 	~CCluster();
   319 //
   320 	void FlushL();
   321 	void Discard();
   322 //
   323 	void Create(TClusterId aClusterId);
   324 	void ReadL(TClusterId aCluster);
   325 	void Relink(TClusterId aNextClusterId);
   326 	void AlterL(MAlter& anAlterer);
   327 //
   328 	TPtrC8 RecordL(TInt aIndex);
   329 	TUint8* UpdateL(TInt aIndex,TInt aNewSize);
   330 	TBool DeleteL(TInt aIndex);
   331 	inline TBool IsFull() const;
   332 //
   333 	inline TClusterId Id() const;
   334 	inline const TClusterDes& Des() const;
   335 private:
   336 	CCluster(CDbStoreDatabase& aDatabase);
   337 //
   338 	TInt SetSizeL(TInt aSize);
   339 	void AdjustMap(TUint8** aMapEntry,TInt aAdjust);
   340 	void SetRecordL(TInt aIndex,TInt aNewSize);
   341 	void AdjustL(TUint8** aMapEntry,TInt aAdjust,TUint8* aData);
   342 private:
   343 	TDblQueLink iLink;
   344 	CDbStoreDatabase& iDatabase;
   345 	TInt iSize;
   346 	TClusterId iCluster;
   347 	TClusterDes iDes;
   348 	TBool iModified;
   349 	TUint8* iMap[KMaxClustering+1];
   350 	};
   351 
   352 /**
   353 @internalComponent
   354 */
   355 NONSHARABLE_CLASS(CClusterCache) : public CBase
   356 	{
   357 	#ifndef MAX_CLUSTER_CACHE_SIZE
   358 		#define MAX_CLUSTER_CACHE_SIZE 8
   359 	#else
   360 		#if MAX_CLUSTER_CACHE_SIZE < 4
   361 			#error "MAX_CLUSTER_CACHE_SIZE macro value can't be less than 4"
   362 		#endif
   363 	#endif
   364 	enum {EMaxClusters=MAX_CLUSTER_CACHE_SIZE};
   365 public:
   366 	static CClusterCache* NewL(CDbStoreDatabase& aDatabase);
   367 	~CClusterCache();
   368 //
   369 	void FlushL();
   370 	void Discard();
   371 //
   372 	CCluster* Cluster(TClusterId aCluster);
   373 	CCluster& ClusterL(TClusterId aCluster);
   374 	CCluster& ClusterL();
   375 //
   376 	inline CDbStoreDatabase& Database();
   377 	inline CStreamStore& Store();
   378 private:
   379 	inline CClusterCache(CDbStoreDatabase& aDatabase);
   380 //
   381 	void Apply(void (*aFunc)(CCluster*));
   382 	CCluster& AddClusterL();
   383 	CCluster& NewClusterL();
   384 	CCluster& Touch(CCluster& aCluster);
   385 private:
   386 	CDbStoreDatabase& iDatabase;
   387 	TClusterId iCachePlus1;
   388 	TClusterId iCachePlus2;
   389 	TUint8 iFollowOnHits;
   390 	TUint8 iClusters;
   391 	TDblQue<CCluster> iCache;
   392 	};
   393 
   394 /**
   395 @internalComponent
   396 */
   397 NONSHARABLE_CLASS(CDbStoreRecords) : public CDbRecordSpace
   398 	{
   399 public:
   400 	class TIteratorC;
   401 	class CIter;
   402 public:
   403 	static TStreamId CreateL(CClusterCache& aCache);
   404 	static CDbStoreRecords* NewL(CClusterCache& aCache,const CDbStoreDef& aDef);
   405 //
   406 	static TInt CardinalityL(CStreamStore& aStore,const CDbStoreDef& aDef);
   407 //
   408 	TBool GotoL(TDbPosition aPosition,TIteratorC& anIterator);
   409 	TBool GotoL(TDbRecordId aRecordId,TIteratorC& anIterator);
   410 	TBool DeletedL(TDbPosition aPosition,TIteratorC& anIterator);
   411 //
   412 	inline TClusterId Head() const;
   413 	inline TInt Count() const;
   414 	TInt DiscardL(TClusterId& aCluster);
   415 	TClusterId AlterL(TClusterId aCluster,CCluster::MAlter& anAlterer);
   416 	void DestroyL();
   417 // providing for CDbRecordSpace
   418 	TBool ExistsL(TDbRecordId aRecordId);
   419 	TPtrC8 ReadL(TDbRecordId aRecordId) const;
   420 	TUint8* DoReplaceL(TDbRecordId aRecordId,TInt aRecordSize);
   421 	TUint AutoIncrementL();
   422 	TUint8* DoNewL(TInt aRecordSize);
   423 	TDbRecordId AppendL();
   424 	void DoEraseL(TDbRecordId aRecordId);
   425 	CDbRecordIter* IteratorL();
   426 	TBool RestoreL();
   427 	void SynchL();
   428 private:
   429 	CDbStoreRecords(CClusterCache& aCache);
   430 	~CDbStoreRecords();
   431 // 
   432 	TUint8* UpdateRecordL(TDbRecordId aRecordId,TInt aNewSize);
   433 	void DesL(TClusterDes& aDes,TClusterId aCluster);
   434 	void CompleteMapL();
   435 	TClusterId NextClusterL(TClusterDes& aDes,TClusterId aCluster);
   436 	TClusterId PreviousClusterL(TClusterDes& aDes,TClusterId aCluster);
   437 	TBool LocateL(TClusterId aCluster);
   438 private:
   439 	class TToken
   440 		{
   441 	public:
   442 		void InternalizeL(RReadStream& aStream);
   443 		void ExternalizeL(RWriteStream& aStream) const;
   444 	public:
   445 		TClusterId iHead;
   446 		TDbRecordId iNext;
   447 		TInt iCount;
   448 		TUint iAutoIncrement;
   449 		};
   450 private:
   451 	CClusterCache& iCache;
   452 	TStreamId iTokenId;
   453 	TToken iToken;
   454 	TInt iClustering;
   455 	TClusterLinkCache iLinks;
   456 	RClusterMap iMap;
   457 	};
   458 
   459 /**
   460 @internalComponent
   461 */
   462 NONSHARABLE_CLASS(CDbStoreBlobs) : public CDbBlobSpace
   463 	{
   464 public:
   465 	CDbStoreBlobs(CDbStoreDatabase& aDatabase,TInt aInlineLimit);
   466 //
   467 	MStreamBuf* DoCreateL(TDbBlobId &aBlobId,TDbColType aType);
   468 	MStreamBuf* ReadL(TDbBlobId aBlobId,TDbColType aType) const;
   469 	void DoDeleteL(TDbBlobId aBlobId);
   470 private:
   471 	CDbStoreDatabase& iDatabase;
   472 	};
   473 
   474 /**
   475 @internalComponent
   476 */
   477 NONSHARABLE_CLASS(CDbStoreIndex) : public CDbRecordIndex
   478 	{
   479 public:
   480 	class HKey;
   481 	class HDupKey;
   482 	class CIter;
   483 	class CDiscarder;
   484 	class CRecover;
   485 	class CRepair;
   486 public:
   487 	static CDbStoreIndex* NewL(CDbStoreDatabase& aDatabase,const CDbStoreIndexDef& aDef,const CDbTableDef& aTable);
   488 	~CDbStoreIndex();
   489 //
   490 	static TStreamId CreateL(CDbStoreDatabase& aDatabase,const CDbStoreIndexDef& aDef);
   491 	static TBool IsDamagedL(CDbStoreDatabase& aDatabase,const CDbStoreIndexDef& aDef);
   492 //
   493 	inline HKey& Key() const;
   494 	inline const TBtree& Tree() const;
   495 	inline TInt Count() const;
   496 	void RepairL();
   497 	void DiscardL();
   498 	void DestroyL();
   499 private:
   500 	CDbStoreIndex(CDbStoreDatabase& aDatabase,const CDbStoreIndexDef& aDef);
   501 //
   502 	void RefreshStatsL();
   503 // CDbTableIndex framework
   504 	TFind FindL(TDbRecordId aRecordId,const RDbTableRow& aRow);
   505 	TBool DoInsertL(TDbRecordId aRecordId,const RDbTableRow& aRow);
   506 	void DoDeleteL(TDbRecordId aRecordId,const RDbTableRow& aRow);
   507 	CDbRecordIter* IteratorL(TUint aInclusion,const TDbLookupKey* aLowerBound,const TDbLookupKey* aUpperBound);
   508 	TBool RestoreL();
   509 	void AboutToModifyL();
   510 	void SynchL();
   511 private:
   512 	CDbStoreDatabase& iDatabase;
   513 	TStreamId iTokenId;
   514 	TBtree iTree;
   515 	HKey* iKey;
   516 	TBtreeInlineLeafOrg iLeafOrg;
   517 	TBtreeInlineIndexOrg iIndexOrg;
   518 	TDbStoreIndexStats& iStats;
   519 	};
   520 
   521 /**
   522 @internalComponent
   523 */
   524 NONSHARABLE_CLASS(CDbStoreIndex::CDiscarder) : public CDbTableDatabase::CStepper
   525 	{
   526 public:
   527 	CDiscarder();
   528 	~CDiscarder();
   529 	TInt Open(CDbStoreIndex* anIndex);
   530 private:
   531 	TInt StepL(TInt aStep);
   532 private:
   533 	CDbStoreIndex* iIndex;
   534 	};
   535 
   536 /**
   537 @internalComponent
   538 */
   539 NONSHARABLE_CLASS(CDbStoreTable) : public CDbTable
   540 	{
   541 public:
   542 	class CDiscarder;
   543 	class CAlter;
   544 	class CCompressor;
   545 	friend class CDiscarder;
   546 	friend class CAlter;
   547 	friend class CCompressor;
   548 public:
   549 	CDbStoreTable(CDbStoreDatabase& aDatabase,const CDbTableDef& aDef);
   550 private:
   551 	inline const CDbStoreDef& Def() const;
   552 	inline CDbStoreDatabase& Database();
   553 	inline CDbStoreRecords& StoreRecordsL();
   554 //
   555 	TInt RowSize(const TUint8* aRec,TInt aLength);
   556 	const TUint8* CopyToRow(TDbCell* aCell,TInt aSize,const TUint8* aRec);
   557 	TUint8* AlterRecordL(TUint8* aWPtr,const TUint8* aRPtr,TInt aLength,TInt aInlineLimit);
   558 // providing for CDbTable framework
   559 	TInt IndexSpanL(const CDbTableIndexDef& aIndex,TUint aInclusion,const TDbLookupKey* aLowerBound,const TDbLookupKey* aUpperBound);
   560 	CDbRecordSpace* RecordSpaceL();
   561 	CDbBlobSpace* BlobSpaceL();
   562 	CDbRecordIndex* RecordIndexL(const CDbTableIndexDef& anIndex);
   563 	void CopyToRowL(RDbRow& aRow,const TDesC8& aRecord);
   564 	TInt RecordLength(const RDbRow& aRow);
   565 	TInt OptimizedRowLength(const RDbRow& aRow);
   566 	void CopyFromRow(TUint8* aRecord,const RDbRow& aRow);
   567 	};
   568 
   569 /**
   570 @internalComponent
   571 */
   572 NONSHARABLE_CLASS(CDbStoreTable::CDiscarder) : public CDbTableDatabase::CStepper, public CCluster::MAlter
   573 	{
   574 private:
   575 	enum {EDiscardClusters=32,EBlobDiscardClusters=2};
   576 public:
   577 	CDiscarder();
   578 	~CDiscarder();
   579 	TInt OpenL(CDbStoreTable* aTable);
   580 private:
   581 	TInt StepL(TInt aStep);
   582 	TUint8* AlterRecordL(TUint8* aWPtr,const TUint8* aRPtr,TInt aLength);
   583 private:
   584 	CDbStoreTable* iTable;
   585 	CDbStoreRecords* iRecords;
   586 	TClusterId iCluster;
   587 	RDbRow iRow;
   588 	};
   589 
   590 /**
   591 @internalComponent
   592 */
   593 NONSHARABLE_CLASS(CDbStoreTable::CAlter) : public CDbTableDatabase::CStepper, public CCluster::MAlter
   594 	{
   595 public:
   596 	CAlter();
   597 	~CAlter();
   598 	void OpenL(CDbStoreTable* aTable,const HDbColumnSet& aNewSet);
   599 private:
   600 	TUint8* AlterRecordL(TUint8* aWPtr,const TUint8* aRPtr,TInt aLength);
   601 	TInt RecordExpansion(const TUint8* aRec,TInt aLength);
   602 	TInt StepL(TInt aStep);
   603 private:
   604 	TInt iExpansion;
   605 	TInt iInlineLimit;
   606 	CDbStoreTable* iTable;
   607 	CDbStoreRecords* iRecords;
   608 	TClusterId iCluster;
   609 	TInt iStep;
   610 	};
   611 
   612 /**
   613 @internalComponent
   614 */
   615 class RDbStoreReadStream : public RStoreReadStream
   616 	{
   617 public:
   618 	enum TType {EMixed,EBinary,EText};
   619 public:
   620 	inline RDbStoreReadStream(CDbStoreDatabase& aDatabase)
   621 		:iDatabase(aDatabase)
   622 		{}
   623 	void FilterL(TType aType,TUint32 aInit);
   624 private:
   625 	CDbStoreDatabase& iDatabase;
   626 	};
   627 
   628 /**
   629 @internalComponent
   630 */
   631 class RDbStoreWriteStream : public RStoreWriteStream
   632 	{
   633 public:
   634 	enum TType {EMixed,EBinary,EText};
   635 public:
   636 	inline RDbStoreWriteStream(CDbStoreDatabase& aDatabase)
   637 		:iDatabase(aDatabase)
   638 		{}
   639 	void FilterL(TType aType,TUint32 aInit);
   640 private:
   641 	CDbStoreDatabase& iDatabase;
   642 	};
   643 
   644 /**
   645 @internalComponent
   646 */
   647 class MDbStreamFilter
   648 	{
   649 public:
   650 	virtual MStreamBuf* FilterL(MStreamBuf* aHost,TUint32 aInit,RDbStoreReadStream::TType aType) =0;
   651 	virtual MStreamBuf* FilterL(MStreamBuf* aHost,TUint32 aInit,RDbStoreWriteStream::TType aType) =0;
   652 	};
   653 
   654 
   655 /**
   656 @internalComponent
   657 */
   658 NONSHARABLE_CLASS(CDbStoreCompression) : public CBase, public MDbStreamFilter
   659 	{
   660 public:
   661 	/**
   662 	@internalComponent
   663 	*/
   664 	class TEncoding
   665 		{
   666 	public:
   667 		enum {ELiterals=256,ELengths=28,ESpecials=1,EDistances=44};
   668 		enum {ELitLens=ELiterals+ELengths+ESpecials};
   669 		enum {EEos=ELiterals+ELengths};
   670 	public:
   671 		TUint32 iLitLen[ELitLens];
   672 		TUint32 iDistance[EDistances];
   673 		};
   674 public:
   675 	static CDbStoreCompression* NewL();
   676 //
   677 	void EncodeL();
   678 	inline void Inflate();
   679 	void ExternalizeL(RWriteStream& aStream) const;
   680 	void InternalizeL(RReadStream& aStream);
   681 // for MDbStreamFilter
   682 	MStreamBuf* FilterL(MStreamBuf* aHost,TUint32 aInit,RDbStoreReadStream::TType aType);
   683 	MStreamBuf* FilterL(MStreamBuf* aHost,TUint32 aInit,RDbStoreWriteStream::TType aType);
   684 private:
   685 	inline CDbStoreCompression();
   686 private:
   687 	enum TState {EAnalysis,EEncoding,EDecoding,EInflating};
   688 private:
   689 	TState iState;
   690 	TEncoding iEncoding[3];
   691 	};
   692 
   693 #include "US_STD.INL"