predictivesearch/PcsAlgorithm/Algorithm1/inc/CPcsCache.h
changeset 0 e686773b3f54
child 15 e8e3147d53eb
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 
       
    31 // CLASS DECLARATION
       
    32 class CPcsCache : public CBase
       
    33 {
       
    34 
       
    35 	public:
       
    36 
       
    37 		/**
       
    38 		* Two phase construction
       
    39 		*/
       
    40 		static CPcsCache* NewL(TDesC& aURI, CPcsKeyMap& aKeyMap, TUint8 aUriId);
       
    41 
       
    42 		/**
       
    43 		* Virtual destructor
       
    44 		*/
       
    45 		virtual ~CPcsCache();
       
    46 
       
    47 		/**
       
    48 		* Returns the database URI this cache support
       
    49 		*/
       
    50 		TDesC& GetURI();
       
    51 
       
    52 		/**
       
    53 		* Get CPcsPoolElement for a key id
       
    54 		*/
       
    55 		void GetContactsForKeyL(TInt aKeyId, RPointerArray<CPcsPoolElement>& aData);
       
    56 
       
    57 		/**
       
    58 		* Get all cached content
       
    59 		*/
       
    60 		void GetAllContentsL(RPointerArray<CPsData>& aData);
       
    61 
       
    62 		/**
       
    63 		* Add a data element to the cache
       
    64 		*/	    
       
    65 		void AddToCacheL(CPsData& aData);
       
    66 
       
    67 		/**
       
    68 		* Removes a data element from the cache
       
    69 		*/
       
    70 		void RemoveFromCacheL(TInt aItemId);	    
       
    71 
       
    72 		/**
       
    73 		* Removes all data elements from the cache
       
    74 		*/
       
    75 		void RemoveAllFromCacheL();
       
    76 
       
    77 		/**
       
    78 		* Sets data fields to the cache
       
    79 		*/
       
    80 		void SetDataFields(RArray<TInt>& aDataFields);
       
    81 
       
    82 		/**
       
    83 		* Gets data fields from the cache
       
    84 		*/
       
    85 		void GetDataFields(RArray<TInt>& aDataFields);
       
    86 
       
    87 		/**
       
    88 		* Updates the caching status for this cache
       
    89 		*/
       
    90 		void UpdateCacheStatus(TInt aStatus);
       
    91 
       
    92 		/**
       
    93 		* Returns the cache status for this cache
       
    94 		*/
       
    95 		TInt GetCacheStatus();
       
    96 
       
    97 		/**
       
    98 		* Returns the UriId
       
    99 		*/
       
   100 		TUint8 GetUriId();
       
   101 
       
   102 		/**
       
   103 		* Returns the URI for this cache
       
   104 		*/
       
   105 		HBufC* GetUri();
       
   106 	    /**
       
   107 	    * Sets sort order for data fields
       
   108 	    */
       
   109 	    void SetSortOrder(RArray<TInt>& aSortOrder);
       
   110 	    
       
   111 	    /**
       
   112 	    * Gets sort order for data fields
       
   113 	    */
       
   114 	    void GetSortOrder(RArray<TInt>& aSortOrder);
       
   115 	    
       
   116 	    /**
       
   117 	    * Get the index order corresponding to the sort order
       
   118 	    */	
       
   119 		void GetIndexOrder(RArray<TInt>& aIndexOrder);
       
   120 		
       
   121         /**
       
   122          * Resort data according to the new sortorder
       
   123          */
       
   124         void ResortdataInPoolsL();
       
   125 
       
   126 	private:
       
   127 
       
   128 		/**
       
   129 		* Constructor
       
   130 		*/
       
   131 		CPcsCache();
       
   132 
       
   133 		/**
       
   134 		* Second phase constructor
       
   135 		*/
       
   136 		void ConstructL(TDesC& aURI, CPcsKeyMap& aKeyMap, TUint8 aUriId);
       
   137 
       
   138 		/**
       
   139 		* Utility function to add a contact to the pool
       
   140 		*/
       
   141 		void AddToPoolL(TInt& aInfo, CPsData& data);
       
   142 
       
   143 		/**
       
   144 		* Utility function 
       
   145 		*/
       
   146 		void SetPoolMap(TInt& aPoolMap, TInt aPoolId);
       
   147 
       
   148 		/**
       
   149 		* Utility function 
       
   150 		*/
       
   151 		TBool GetPoolMap(TInt& aPoolMap, TInt arrayIndex);
       
   152 
       
   153         /**
       
   154          * Utility function
       
   155          */
       
   156         void ComputeIndexOrder();
       
   157 	private:    
       
   158 
       
   159 
       
   160 		/*
       
   161 		* Array of key maps
       
   162 		*/
       
   163 		typedef RPointerArray<CPcsPoolElement> R_PTR_ARRAY;
       
   164 		RPointerArray<R_PTR_ARRAY> keyArr;     
       
   165 
       
   166 		/*
       
   167 		* Hashmaps to remember the location of a contact in the pools
       
   168 		*/
       
   169 		RHashMap<TInt, TInt> cacheInfo;			
       
   170 
       
   171 		/*
       
   172 		* Master pool of all contacts in this cache
       
   173 		*/
       
   174 		RPointerArray<CPsData> masterPool;	
       
   175 		
       
   176 	    /*
       
   177 	    * Master pool backup of all contacts in this cache when sortorder changed
       
   178 	    */
       
   179 	    RPointerArray<CPsData> masterPoolBackup;  
       
   180 
       
   181 		/*
       
   182 		* Not owned
       
   183 		*/
       
   184 		CPcsKeyMap* keyMap;		
       
   185 
       
   186 		/**
       
   187 		* Owned. Refer to the database URI this cache is for.
       
   188 		*/
       
   189 		HBufC* iURI;	
       
   190 
       
   191 		/**
       
   192 		* Internal URI id for this cache
       
   193 		*/
       
   194 		TInt8 iUriId;
       
   195 
       
   196 		/**
       
   197 		* Current status of this cache
       
   198 		*/
       
   199 		TInt iCacheStatus;
       
   200 
       
   201 		/**
       
   202 		* List of data fields (mapped to VPbk ids) supported by this cache
       
   203 		*/
       
   204 		RArray<TInt> 	iDataFields;
       
   205 		/**
       
   206 		* Sort order of data fields expected by the clients
       
   207 		*/
       
   208 		RArray<TInt>    iSortOrder;
       
   209 		
       
   210 		/**
       
   211 		* Order of indexes determined by correlating iDataFields and iSortOrder
       
   212 		* Each CPsData data element fields need to be compared in this order
       
   213 		* to get the client expected sort order for this cache.
       
   214 		*/
       
   215 		RArray<TInt>    iIndexOrder;
       
   216 		
       
   217 };
       
   218 
       
   219 
       
   220 #endif // __CPCS_CACHE_H__
       
   221 
       
   222 // End of file