phonebookengines/cntsortplugin/src/csortkeyarray.cpp
changeset 81 640d30f4fb64
parent 77 c18f9fa7f42e
child 84 63017c97b1d6
equal deleted inserted replaced
77:c18f9fa7f42e 81:640d30f4fb64
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *     Sort key array for Contact model ECOM sort plugin.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "csortkeyarray.h"
       
    21 
       
    22 namespace {
       
    23 
       
    24 #ifdef _DEBUG
       
    25     
       
    26 enum TPanicReason
       
    27     {
       
    28     EPanicPreCond_SetText
       
    29     };
       
    30     
       
    31 void Panic(TPanicReason aReason)
       
    32     {
       
    33     _LIT(KPanicText, "CSortKeyArray");
       
    34     User::Panic(KPanicText, aReason);
       
    35     }
       
    36 
       
    37 #endif // _DEBUG
       
    38 
       
    39 } // namespace
       
    40 
       
    41 inline CSortKeyArray::CSortKeyArray()
       
    42     {
       
    43     }
       
    44 
       
    45 CSortKeyArray* CSortKeyArray::NewL()
       
    46     {
       
    47     return new(ELeave) CSortKeyArray;
       
    48     }
       
    49 
       
    50 CSortKeyArray::~CSortKeyArray()
       
    51     {
       
    52     iKeyTypes.Close();
       
    53     iTexts.Close();
       
    54     }
       
    55 
       
    56 void CSortKeyArray::AppendL(const TSortKey& aKey)
       
    57     {
       
    58     User::LeaveIfError(iKeyTypes.Append(aKey.Type()));
       
    59     TInt err = iTexts.Append(aKey.Text());
       
    60     if (err != KErrNone)
       
    61         {
       
    62         // if appending to iTexts was not successful remove also the
       
    63         // item in iKeyTypes to keep arrays in sync.
       
    64         iKeyTypes.Remove(iKeyTypes.Count() - 1);
       
    65         User::Leave(err);
       
    66         }
       
    67     }
       
    68 
       
    69 void CSortKeyArray::SetText(const TDesC& aText, TInt aIndex)
       
    70     {
       
    71     __ASSERT_DEBUG(aIndex < iTexts.Count(), Panic(EPanicPreCond_SetText));
       
    72     iTexts[aIndex].Set(aText);
       
    73     }
       
    74 
       
    75 void CSortKeyArray::Reset()
       
    76     {
       
    77     iKeyTypes.Reset();
       
    78     iTexts.Reset();
       
    79     }
       
    80 
       
    81 TInt CSortKeyArray::SortKeyCount() const
       
    82     {
       
    83     return iKeyTypes.Count();
       
    84     }
       
    85 
       
    86 TSortKey CSortKeyArray::SortKeyAt(TInt aIndex) const
       
    87     {
       
    88     return TSortKey(iTexts[aIndex], iKeyTypes[aIndex]);
       
    89     }
       
    90 
       
    91 // End of File