phonebookengines_old/contactsmodel/tsrc/T_rndutils.h
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __T_RNDUTILS_H__
       
    17 #define __T_RNDUTILS_H__
       
    18 
       
    19 
       
    20 #include "T_UTILS.H"
       
    21 #include "t_utils2.h"
       
    22 
       
    23 const TInt KDigramNumberOfNonLetters =  3;	// space, -, null
       
    24 const TInt KDigramNumberOfLetters =  26 ;
       
    25 const TInt KDigramNumberOfChars =  KDigramNumberOfLetters*2+ KDigramNumberOfNonLetters;
       
    26 
       
    27 /** Used to create randomly generated words using n-grams found in the specified data file.
       
    28 	Using n-grams lead to much more realistic words and thus makes it obvious a descriptor
       
    29 	is data and not noise.
       
    30 	This implementation only supports digrams */
       
    31 	
       
    32 class CWordNgrams : public CBase, public MRandomWordGenerator
       
    33 	{
       
    34 	public:
       
    35 		HBufC* WordLC();
       
    36 		
       
    37 	protected: 
       
    38 		
       
    39 		TBool AddLetter(TDes& aWord);
       
    40 		void ConstructL(const TDesC& aFilename, TInt aNgramSize = 2, TBool aUseNarrowChar = ETrue);
       
    41 		virtual TChar NextLetter(const TDesC& aWord) = 0;
       
    42 		virtual void SetNgram(const TDesC8& aNgram, TUint aNumber) = 0;
       
    43 		virtual void SetNgram(const TDesC16& aNgram, TUint aNumber) = 0;
       
    44 
       
    45 	};
       
    46 	
       
    47 
       
    48 /** Implementation of CWordNgrams which uses digram frequencies (letter pairs)
       
    49 	to generate random words */
       
    50 class CWordDigrams : public CWordNgrams
       
    51 	{
       
    52 	public:
       
    53 		static CWordDigrams* NewLC(const TDesC& aFilename, TInt64& aRandSeed );
       
    54 		virtual ~CWordDigrams();
       
    55 		
       
    56 	protected: 
       
    57 		void ConstructL(const TDesC& aFilename);
       
    58 		void SetNgram(const TDesC8& aNgram, TUint aNumber);
       
    59 		void SetNgram(const TDesC16& aNgram, TUint aNumber); // empty function
       
    60 		TChar NextLetter(const TDesC& aWord);
       
    61 
       
    62 	private:
       
    63 		CWordDigrams(TInt64& aRandSeed);
       
    64 		static TInt Index(const TChar c);
       
    65 		static TChar Char(TInt i);
       
    66 		
       
    67 	private:
       
    68 		TInt64& iRandSeed;
       
    69 		TUint8 iDigrams[KDigramNumberOfChars][KDigramNumberOfChars];
       
    70 		TUint16 iSizes[KDigramNumberOfChars];
       
    71 	};
       
    72 
       
    73 
       
    74 
       
    75 #endif