predictivesearch/PcsUtils/src/CPsPattern.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Utility class to hold a match pattern for predictive search.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <s32mem.h>
       
    21 #include "CPsPattern.h"
       
    22 
       
    23 // ============================== MEMBER FUNCTIONS ============================
       
    24 
       
    25 
       
    26 // ----------------------------------------------------------------------------
       
    27 // CPsPattern::NewL
       
    28 // Two Phase constructor
       
    29 // ----------------------------------------------------------------------------
       
    30 EXPORT_C CPsPattern* CPsPattern::NewL()
       
    31 {
       
    32 	CPsPattern* self = new (ELeave) CPsPattern();	
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop();
       
    36     return self;
       
    37 	
       
    38 }
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // CPsPattern::CPsPattern
       
    42 // Default constructor
       
    43 // ----------------------------------------------------------------------------
       
    44 CPsPattern::CPsPattern()
       
    45 {
       
    46 }
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // CPsPattern::ConstructL
       
    50 // Two phase construction
       
    51 // ----------------------------------------------------------------------------
       
    52 void CPsPattern::ConstructL()
       
    53 {
       
    54     iPattern = NULL;
       
    55     iFirstIndex = -1;
       
    56 }
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 // CPsPattern::~CPsPattern
       
    60 // Destructor
       
    61 // ----------------------------------------------------------------------------
       
    62 EXPORT_C CPsPattern::~CPsPattern()
       
    63 {	
       
    64     if ( iPattern )
       
    65     {
       
    66     	delete iPattern;
       
    67     	iPattern = NULL;
       
    68     }
       
    69 }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CPsPattern::SetPatternL
       
    73 // Sets the match pattern
       
    74 // ----------------------------------------------------------------------------
       
    75 EXPORT_C void CPsPattern::SetPatternL(TDesC& aPattern)
       
    76 {   
       
    77     iPattern = aPattern.AllocL();
       
    78 }
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // CPsPattern::SetFirstIndex
       
    82 // Set the first index
       
    83 // ----------------------------------------------------------------------------
       
    84 EXPORT_C void CPsPattern::SetFirstIndex(TInt aFirstIndex)
       
    85 {
       
    86 	iFirstIndex = aFirstIndex;
       
    87 }
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CPsPattern::Pattern
       
    91 // Returns the match pattern
       
    92 // ----------------------------------------------------------------------------
       
    93 EXPORT_C TDesC& CPsPattern::Pattern()
       
    94 {
       
    95     return *iPattern;
       
    96 }
       
    97 
       
    98 // ----------------------------------------------------------------------------
       
    99 // CPsPattern::FirstIndex
       
   100 // Returns the first index of this pattern
       
   101 // ----------------------------------------------------------------------------
       
   102 EXPORT_C TInt CPsPattern::FirstIndex()
       
   103 {
       
   104     return iFirstIndex;
       
   105 }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // CPsPattern::ExternalizeL
       
   109 // Writes 'this' to aStream
       
   110 // ----------------------------------------------------------------------------
       
   111 EXPORT_C void CPsPattern::ExternalizeL(RWriteStream& aStream)
       
   112 {
       
   113 	TInt length = iPattern->Length();
       
   114         
       
   115     // Write the char sequence length	        
       
   116     aStream.WriteUint16L(length);	
       
   117         
       
   118     // Write the char sequence
       
   119     aStream << *iPattern;
       
   120 	
       
   121 	// Write first index
       
   122 	aStream.WriteInt32L(iFirstIndex);
       
   123 }
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // CPsPattern::InternalizeL
       
   127 // Initializes 'this' with the contents of aStream
       
   128 // ----------------------------------------------------------------------------
       
   129 EXPORT_C void CPsPattern::InternalizeL(RReadStream& aStream)
       
   130 {    
       
   131 	// Size of sequence
       
   132 	TInt szSeq = aStream.ReadUint16L();
       
   133 
       
   134 	// Character sequence
       
   135 	iPattern = HBufC::NewLC(aStream, szSeq);
       
   136 	CleanupStack::Pop();
       
   137     
       
   138     // Read first index
       
   139     iFirstIndex = aStream.ReadInt32L();
       
   140 }
       
   141 
       
   142 // End of file
       
   143