predictivesearch/PcsAlgorithm/Algorithm2/inc/CPcsCache.h
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 85 38bb213f60ba
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/predictivesearch/PcsAlgorithm/Algorithm2/inc/CPcsCache.h	Wed Sep 01 12:29:52 2010 +0100
@@ -0,0 +1,246 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Used to cache the contacts in memory
+*
+*/
+
+#ifndef __CPCS_CACHE_ALGORITHM2_H__
+#define __CPCS_CACHE_ALGORITHM2_H__
+
+// INCLUDE FILES
+#include <e32base.h>
+#include <e32hashtab.h>
+
+#include "CPsData.h"
+#include "CPcsKeyMap.h"
+#include "CPcsPoolElement.h"
+#include "TCacheInfo.h"
+#include "CPcsDefs.h"
+
+class CPcsAlgorithm2;
+// CLASS DECLARATION
+class CPcsCache : public CBase
+    {
+
+public:
+
+    /**
+     * Two phase construction
+     */
+    static CPcsCache* NewL(CPcsAlgorithm2* aAlgorithm, const TDesC& aURI, 
+                           CPcsKeyMap& aKeyMap, TUint8 aUriId);
+
+    /**
+     * Virtual destructor
+     */
+    virtual ~CPcsCache();
+
+    /**
+     * Returns the database URI this cache support
+     */
+    TDesC& GetURI();
+
+    /**
+     * Get CPcsPoolElement for a key id
+     */
+    void GetContactsForKeyL(TInt aKeyId, RPointerArray<CPcsPoolElement>& aData);
+
+    /**
+     * Get all cached content
+     */
+    void GetAllContentsL(RPointerArray<CPsData>& aData);
+
+    /**
+     * Add a data element to the cache
+     */
+    void AddToCacheL(CPsData& aData);
+
+    /**
+     * Removes a data element from the cache
+     */
+    void RemoveFromCacheL(TInt aItemId);
+
+    /**
+     * Removes all data elements from the cache
+     */
+    void RemoveAllFromCache();
+
+    /**
+     * Sets data fields to the cache
+     */
+    void SetDataFields(RArray<TInt>& aDataFields);
+
+    /**
+     * Gets data fields from the cache
+     */
+    void GetDataFields(RArray<TInt>& aDataFields);
+
+    /**
+     * Updates the caching status for this cache
+     */
+    void UpdateCacheStatus(TInt aStatus);
+
+    /**
+     * Returns the cache status for this cache
+     */
+    TInt GetCacheStatus();
+
+    /**
+     * Returns the UriId
+     */
+    TUint8 GetUriId();
+
+    /**
+     * Returns the URI for this cache
+     */
+    HBufC* GetUri();
+    /**
+     * Sets sort order for data fields
+     */
+    void SetSortOrder(RArray<TInt>& aSortOrder);
+
+    /**
+     * Gets sort order for data fields
+     */
+    void GetSortOrder(RArray<TInt>& aSortOrder);
+
+    /**
+     * Get the index order corresponding to the sort order
+     */
+    void GetIndexOrder(RArray<TInt>& aIndexOrder);
+    
+    /**
+     * Resort data according to the new sortorder
+     */
+    void ResortdataInPoolsL();
+
+    /**
+     * Get data index of the first name field
+     */
+    TInt GetFirstNameIndex() const;
+
+    /**
+     * Get data index of the last name field
+     */
+    TInt GetLastNameIndex() const;
+
+private:
+
+    /**
+     * Constructor
+     */
+    CPcsCache();
+
+    /**
+     * Second phase constructor
+     */
+    void ConstructL(CPcsAlgorithm2* aAlgorithm, const TDesC& aURI,
+                    CPcsKeyMap& aKeyMap, TUint8 aUriId);
+
+    /**
+     * Utility function to add a contact to the pool
+     */
+    void AddToPoolL(TUint64& aPoolMap, CPsData& aData);
+
+    /**
+     * Utility function 
+     */
+    void SetPoolMap(TUint64& aPoolMap, TInt aArrayIndex);
+
+    /**
+     * Utility function 
+     */
+    TBool GetPoolMap(TUint64& aPoolMap, TInt aArrayIndex);
+
+    /**
+     * Gets all the first characters of the words in the data field according
+     * to which the contact should be inserted into cache.
+     */
+    void GetFirstCharsForDataL( const TDesC& aData, RArray<TChar>& aFirstChars ) const;
+    
+    /**
+     * Gets all the pool IDs matching the given characters. If there are two predictive
+     * keyboards available, then pool IDs are given according to both keyboards.
+     */
+    void GetPoolIdsForCharsL( const RArray<TChar>& aChars, RArray<TInt>& aPoolIds ) const;
+    
+    /**
+     * Utility function
+     */
+    void ComputeIndexOrder();
+private:
+
+    CPcsAlgorithm2* iAlgorithm;
+
+    /*
+     * Array of key maps
+     */
+    typedef RPointerArray<CPcsPoolElement> R_PTR_ARRAY;
+    RPointerArray<R_PTR_ARRAY> iKeyArr;
+
+    /*
+     * Hashmaps to remember the location of a contact in the pools
+     */
+    RHashMap<TInt, TUint64> iCacheInfo;
+
+    /*
+     * Master pool of all contacts in this cache
+     */
+    RPointerArray<CPsData> iMasterPool;
+    
+    /*
+    * Master pool backup of all contacts in this cache when sortorder changed
+    */
+    RPointerArray<CPsData> iMasterPoolBackup;
+
+    /*
+     * Not owned
+     */
+    CPcsKeyMap* iKeyMap;
+
+    /**
+     * Owned. Refer to the database URI this cache is for.
+     */
+    HBufC* iURI;
+
+    /**
+     * Internal URI id for this cache
+     */
+    TInt8 iUriId;
+
+    /**
+     * Current status of this cache
+     */
+    TInt iCacheStatus;
+
+    /**
+     * List of data fields (mapped to VPbk ids) supported by this cache
+     */
+    RArray<TInt> iDataFields;
+    /**
+     * Sort order of data fields expected by the clients
+     */
+    RArray<TInt> iSortOrder;
+
+    /**
+     * Order of indexes determined by correlating iDataFields and iSortOrder
+     * Each CPsData data element fields need to be compared in this order
+     * to get the client expected sort order for this cache.
+     */
+    RArray<TInt> iIndexOrder;
+
+    };
+
+#endif // __CPCS_CACHE_ALGORITHM2_H__
+// End of file