predictivesearch/PcsAlgorithm/Algorithm1/inc/CPcsAlgorithm1Utils.h
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63: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:  Predictive Contact Search Algorithm 1 main class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_PCS_ALGORITHM_1_UTILS
       
    20 #define C_PCS_ALGORITHM_1_UTILS
       
    21 
       
    22 // INCLUDE FILES
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <e32hashtab.h>
       
    26 
       
    27 
       
    28 // FORWARD DECLARATION
       
    29 class CPsData;
       
    30 class CPsQuery;
       
    31 
       
    32 typedef RPointerArray<CPsData> CPSDATA_R_PTR_ARRAY;
       
    33 
       
    34 
       
    35 // CLASS DECLARATION
       
    36 class CPcsAlgorithm1Utils : public CBase
       
    37 {
       
    38 	public: 
       
    39 
       
    40 		/**
       
    41 		 * Merge function to merge the search results from different arrays
       
    42 		 * into a single array in sorted order.
       
    43 		 * It merges all the result sets that are there in iSearchResultsArr
       
    44          * into single result set. This is a wrapper funciton implemented that
       
    45          * works for all type of key board modes
       
    46 		 */
       
    47 		static void FormCompleteSearchResultsL(RPointerArray<CPSDATA_R_PTR_ARRAY>& aSearchResultsArr, 
       
    48 										       RPointerArray<CPsData>& SearchResults);
       
    49 
       
    50         /**
       
    51          * Compare by character.
       
    52          */
       
    53 		static TInt CompareByCharacter(const TChar& aFirst, const TChar& aSecond);
       
    54 
       
    55 		/**
       
    56 		 * Compare by length.
       
    57 		 */
       
    58 		static TInt CompareByLength(const HBufC& aFirst, const HBufC& aSecond);
       
    59 
       
    60 		/**
       
    61 		 * Compare strings exactly case sensitively.
       
    62 		 */
       
    63 		static TBool CompareExact(const TDesC& aFirst, const TDesC& aSecond);
       
    64 
       
    65 		/**
       
    66 		 * Compare strings with collate rules depending on locale.
       
    67 		 */
       
    68 		static TInt CompareCollate(const TDesC& aFirst, const TDesC& aSecond);
       
    69 
       
    70 		/**
       
    71 		 * Compare for keys and strings:
       
    72 		 * - Case sensitive compare for keys,
       
    73 		 * - Case insensitive and language dependent compare for Contact Data and Query.
       
    74 		 */
       
    75 		static TBool MyCompareKeyAndString(const TDesC& aContactString,
       
    76 		                                   const TDesC& aQueryAsString,
       
    77 		                                   CPsQuery& aPsQuery);
       
    78 
       
    79 		/**
       
    80          * Case Sensitive compare for keys
       
    81          */
       
    82 		static TBool MyCompareK(const TDesC& aLeft, const TDesC& aRight, CPsQuery& aPsQuery);
       
    83 
       
    84 		/**
       
    85          * Customized CompareC
       
    86          */
       
    87         static TInt MyCompareC(const TDesC& aLeft, const TDesC& aRight);
       
    88 		
       
    89         
       
    90         /**
       
    91          * TLinearOrder rule for comparison of data objects
       
    92          */
       
    93         static TInt CompareDataBySortOrderL(const CPsData& aObject1,
       
    94                                             const CPsData& aObject2);
       
    95 
       
    96         /**
       
    97          * Trim off all white spaces and special chars
       
    98          */
       
    99         static void MyTrim(TDes& aString);
       
   100         
       
   101         
       
   102         /**
       
   103          * Check if the input URI is of contact search in a group template form
       
   104          */
       
   105         static TBool IsGroupUri(TDesC& aURI);
       
   106 
       
   107         /**
       
   108          * Constructs a bit pattern using the required/supported data fields
       
   109          * For example, 6, 4 and 27 are supported fields <-- 00000111
       
   110          *              6 and 4 are required fields      <-- 00000011
       
   111          * Bit pattern returned is 00000011.
       
   112          */
       
   113         static TUint8 FilterDataFieldsL(const RArray<TInt>& aRequiredDataFields,
       
   114                                         const RArray<TInt>& aSupportedDataFields);
       
   115     
       
   116         /**
       
   117          * Create upper-case match sequence buffer from matching part and append it to
       
   118          * array unless there's equal sequence already present.
       
   119          */
       
   120         static void AppendMatchToSeqL( RPointerArray<TDesC>& aMatchSeq, const TDesC& aMatch );
       
   121 };
       
   122 
       
   123 
       
   124 // CleanupStack helpers for item owning RPointerArrays
       
   125 template <class T>
       
   126 class CleanupResetAndDestroy
       
   127     {
       
   128 public:
       
   129     inline static void PushL(T& aRef)
       
   130         { CleanupStack::PushL(TCleanupItem(&ResetAndDestroy,&aRef)); }
       
   131 private:
       
   132     inline static void ResetAndDestroy(TAny *aPtr)
       
   133         { static_cast<T*>(aPtr)->ResetAndDestroy(); }
       
   134     };
       
   135 
       
   136 template <class T>
       
   137 inline void CleanupResetAndDestroyPushL(T& aRef)
       
   138     { CleanupResetAndDestroy<T>::PushL(aRef); }
       
   139 
       
   140 #endif // C_PCS_ALGORITHM_1_UTILS
       
   141