predictivesearch/PcsAlgorithm/Algorithm1/inc/CPcsCache.h
branchRCL_3
changeset 20 f4a778e096c2
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Used to cache the contacts in memory
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef __CPCS_CACHE_H__
       
    19 #define __CPCS_CACHE_H__
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32base.h>
       
    23 #include <e32hashtab.h>
       
    24 
       
    25 #include "CPsData.h"
       
    26 #include "CPcsKeyMap.h"
       
    27 #include "CPcsPoolElement.h"
       
    28 #include "TCacheInfo.h"
       
    29 #include "CPcsDefs.h"
       
    30 #include "CPcsAdaptiveGrid.h"
       
    31 
       
    32 // CLASS DECLARATION
       
    33 class CPcsCache : public CBase
       
    34 {
       
    35 
       
    36 	public:
       
    37 
       
    38 		/**
       
    39 		* Two phase construction
       
    40 		*/
       
    41 		static CPcsCache* NewL(const TDesC& aURI, CPcsKeyMap& aKeyMap, TUint8 aUriId);
       
    42 
       
    43 		/**
       
    44 		* Virtual destructor
       
    45 		*/
       
    46 		virtual ~CPcsCache();
       
    47 
       
    48 		/**
       
    49 		* Returns the database URI this cache support
       
    50 		*/
       
    51 		TDesC& GetURI();
       
    52 
       
    53 		/**
       
    54 		* Get CPcsPoolElement for a key id
       
    55 		*/
       
    56 		void GetContactsForKeyL(TInt aKeyId, RPointerArray<CPcsPoolElement>& aData);
       
    57 
       
    58 		/**
       
    59 		* Get all cached content
       
    60 		*/
       
    61 		void GetAllContentsL(RPointerArray<CPsData>& aData);
       
    62 
       
    63 		/**
       
    64 		* Add a data element to the cache
       
    65 		*/	    
       
    66 		void AddToCacheL(CPsData& aData);
       
    67 
       
    68 		/**
       
    69 		* Removes a data element from the cache
       
    70 		*/
       
    71 		void RemoveFromCacheL(TInt aItemId);
       
    72 
       
    73 		/**
       
    74 		* Removes all data elements from the cache
       
    75 		*/
       
    76 		void RemoveAllFromCache();
       
    77 
       
    78 		/**
       
    79 		* Sets data fields to the cache
       
    80 		*/
       
    81 		void SetDataFields(RArray<TInt>& aDataFields);
       
    82 
       
    83 		/**
       
    84 		* Gets data fields from the cache
       
    85 		*/
       
    86 		void GetDataFields(RArray<TInt>& aDataFields);
       
    87 
       
    88 		/**
       
    89 		* Updates the caching status for this cache
       
    90 		*/
       
    91 		void UpdateCacheStatus(TInt aStatus);
       
    92 
       
    93 		/**
       
    94 		* Returns the cache status for this cache
       
    95 		*/
       
    96 		TInt GetCacheStatus();
       
    97 
       
    98 		/**
       
    99 		* Returns the UriId
       
   100 		*/
       
   101 		TUint8 GetUriId();
       
   102 
       
   103 	    /**
       
   104 	    * Sets sort order for data fields
       
   105 	    */
       
   106 	    void SetSortOrder(RArray<TInt>& aSortOrder);
       
   107 	    
       
   108 	    /**
       
   109 	    * Gets sort order for data fields
       
   110 	    */
       
   111 	    void GetSortOrder(RArray<TInt>& aSortOrder);
       
   112 	    
       
   113 	    /**
       
   114 	    * Get the index order corresponding to the sort order
       
   115 	    */	
       
   116 		void GetIndexOrder(RArray<TInt>& aIndexOrder);
       
   117 		
       
   118         /**
       
   119         * Resort data according to the new sortorder
       
   120         */
       
   121         void ResortdataInPoolsL();
       
   122         
       
   123         /**
       
   124         * Returns the Adaptive Grid
       
   125         */  
       
   126         void GetAdaptiveGridL( const TBool aCompanyName, TDes& aAdaptiveGrid );
       
   127 
       
   128 	private:
       
   129 
       
   130 		/**
       
   131 		* Constructor
       
   132 		*/
       
   133 		CPcsCache();
       
   134 
       
   135 		/**
       
   136 		* Second phase constructor
       
   137 		*/
       
   138 		void ConstructL(const TDesC& aURI, CPcsKeyMap& aKeyMap, TUint8 aUriId);
       
   139 
       
   140 		/**
       
   141 		* Utility function to add a contact to the pool
       
   142 		*/
       
   143 		void AddToPoolL(TUint64& aPoolMap, CPsData& aData);
       
   144 
       
   145 		/**
       
   146 		* Utility function 
       
   147 		*/
       
   148 		void SetPoolMap(TUint64& aPoolMap, TInt aArrayIndex);
       
   149 
       
   150 		/**
       
   151 		* Utility function 
       
   152 		*/
       
   153 		TBool GetPoolMap(TUint64& aPoolMap, TInt aArrayIndex);
       
   154 
       
   155         /**
       
   156          * Utility function
       
   157          */
       
   158         void ComputeIndexOrder();
       
   159         
       
   160         /**
       
   161          * Matches Adaptive Grid Item Selector
       
   162          */
       
   163         TUint GridItemSelector( TInt aIndex, TBool& aUnnamed );
       
   164         
       
   165 	private:
       
   166 
       
   167 		/*
       
   168 		* Array of key maps
       
   169 		*/
       
   170 		typedef RPointerArray<CPcsPoolElement> R_PTR_ARRAY;
       
   171 		RPointerArray<R_PTR_ARRAY> iKeyArr;
       
   172 
       
   173 		/*
       
   174 		* Hashmaps to remember the location of a contact in the pools
       
   175 		*/
       
   176 		RHashMap<TInt, TUint64> iCacheInfo;
       
   177 
       
   178 		/*
       
   179 		* Master pool of all contacts in this cache
       
   180 		*/
       
   181 		RPointerArray<CPsData> iMasterPool;	
       
   182 		
       
   183 	    /*
       
   184 	    * Master pool backup of all contacts in this cache when sortorder changed
       
   185 	    */
       
   186 	    RPointerArray<CPsData> iMasterPoolBackup;
       
   187 
       
   188 		/*
       
   189 		* Not owned
       
   190 		*/
       
   191 		CPcsKeyMap* iKeyMap;
       
   192 
       
   193 		/**
       
   194 		* Owned. Refer to the database URI this cache is for.
       
   195 		*/
       
   196 		HBufC* iURI;
       
   197 
       
   198 		/**
       
   199 		* Internal URI id for this cache
       
   200 		*/
       
   201 		TUint8 iUriId;
       
   202 
       
   203 		/**
       
   204 		* Current status of this cache
       
   205 		*/
       
   206 		TInt iCacheStatus;
       
   207 
       
   208 		/**
       
   209 		* List of data fields (mapped to VPbk ids) supported by this cache
       
   210 		*/
       
   211 		RArray<TInt> iDataFields;
       
   212 		/**
       
   213 		* Sort order of data fields expected by the clients
       
   214 		*/
       
   215 		RArray<TInt> iSortOrder;
       
   216 		
       
   217 		/**
       
   218 		* Order of indexes determined by correlating iDataFields and iSortOrder
       
   219 		* Each CPsData data element fields need to be compared in this order
       
   220 		* to get the client expected sort order for this cache.
       
   221 		*/
       
   222 		RArray<TInt> iIndexOrder;
       
   223 		
       
   224 		/**
       
   225 		* Grid characters with reference counters.
       
   226 		*/
       
   227 		CPcsAdaptiveGrid* iAdaptiveGridMap;
       
   228 };
       
   229 
       
   230 
       
   231 #endif // __CPCS_CACHE_H__
       
   232 
       
   233 // End of file