phonebookengines/VirtualPhonebook/inc/RDigitString.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Digit string handler class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef VPBKENGUTILS_RDIGITSTRING_H
       
    20 #define VPBKENGUTILS_RDIGITSTRING_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32std.h>
       
    24 
       
    25 namespace VPbkEngUtils {
       
    26 
       
    27 // FORWARD DECLARATIONS
       
    28 class TFixedDigitString;
       
    29 
       
    30 
       
    31 // CLASS DECLARATIONS
       
    32 
       
    33 /**
       
    34  * Variable-length digit string.
       
    35  * Phone number matching helper class: encodes decimal digit characters to BCD 
       
    36  * (Binary Coded Decimal) format for efficient matching.
       
    37  */
       
    38 class RDigitString
       
    39     {
       
    40     public:
       
    41         /**
       
    42          * Default constructor. Resets this digit string to empty.
       
    43          */
       
    44         RDigitString();
       
    45 
       
    46         /**
       
    47          * Releases resources used for storing the digit string. This object
       
    48          * must not be used after Close() has been called to it.
       
    49          */
       
    50         void Close();
       
    51 
       
    52         /**
       
    53          * Returns the length of this digit string.
       
    54          *
       
    55          * @return the number of digits in this digit string,
       
    56          */
       
    57         TInt Length() const;
       
    58 
       
    59         /**
       
    60          * Returns true if this digit string is empty.
       
    61          */
       
    62         TBool IsEmpty() const;
       
    63 
       
    64         /**
       
    65          * Returns the maximum number of digits this object may contain.
       
    66          */
       
    67         static TInt MaxLength();
       
    68 
       
    69         /**
       
    70          * Returns non-modifiable decimal digit at position aIndex.
       
    71          *
       
    72          * @pre  aIndex >= 0 && aIndex < Length()
       
    73          * @post result >= 0 && result <= 9
       
    74          */
       
    75         TInt operator[](TInt aIndex) const;
       
    76 
       
    77         /**
       
    78          * Compares the digits in this string to another digit string.
       
    79          *
       
    80          * @param aOther    the other digit string to compare this string with.
       
    81          * @param aNumDigits    the number of digits to compare. Zero means
       
    82          *                      all digits are compared. 
       
    83          * @return  true if aNumDigits digits match, false otherwise. Undefined
       
    84          *          if aNumDigits < 0 || aNumDigits > MaxLength().
       
    85          */
       
    86         TBool Compare(const RDigitString& aOther, TInt aNumDigits) const;
       
    87 
       
    88         /**
       
    89          * Resets this digit string to empty.
       
    90          *
       
    91          * @post Length() == 0
       
    92          */
       
    93         void Reset();
       
    94 
       
    95         /**
       
    96          * Encodes digit characters from text to this digit string.
       
    97          *
       
    98          * @param aDigitsText   text to encode decimal digit characters from.
       
    99          *                      Nondigit characters are skipped.
       
   100          * @exception KErrOverflow  If aDigitsText contains too many digits to
       
   101          *                          fit into this data structure. If this
       
   102          *                          function leaves this object's state is 
       
   103          *                          unchanged.
       
   104          * @exception KErrNoMemory  If encoding runs out of memory. If this 
       
   105          *                          function leaves this object's state is 
       
   106          *                          unchanged.
       
   107          */
       
   108         void EncodeDigitsL(const TDesC& aDigitsText);
       
   109 
       
   110     private:  // Data
       
   111         /// Number of active elements in iDigits
       
   112         TInt16 iSubCount;
       
   113         /// Maxmimum size of the array iDigits points to
       
   114         TInt16 iSubCapacity;
       
   115         /// Own. Encoded digits
       
   116         TFixedDigitString* iDigits;
       
   117     };
       
   118 
       
   119 
       
   120 } // namespace VPbkEngUtils
       
   121 
       
   122 #endif  // VPBKENGUTILS_RDIGITSTRING_H
       
   123