srsf/sispeechrecognitiondata/src/nsssispeechrecognitiondatadevasr.cpp
branchRCL_3
changeset 19 e36f3802f733
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2004-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:  This file contains definition of the SISpeechRecognitionDataDevASR structure and API.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32std.h>
       
    22 #include <s32mem.h>
       
    23 #include "nsssispeechrecognitiondatadevasr.h"
       
    24 #include "nsssispeechrecognitiondatatest.h"
       
    25 #include "nsssidataserialize.h"
       
    26 
       
    27 #include "rubydebug.h"
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 /** Maximal number of pronunciations, that is allowed to be stored per lexicon.
       
    32     0 means no limit.
       
    33     4800 is a maximal number of pronunciations for 400 contacts (400*12) */
       
    34 const TInt KMaxPronunciations = 4800;
       
    35 
       
    36 // Starting value for lexicon usage counter
       
    37 const TInt KInitialCounterValue = 1;
       
    38 
       
    39 // Define this if SINDE lexicon optimization is on
       
    40 #define __SIND_LEXICON_OPT
       
    41 
       
    42 /*****************************************************************************/
       
    43 
       
    44 // ============================ MEMBER FUNCTIONS ===============================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CSIParameters::CSIParameters
       
    48 // C++ default constructor can NOT contain any code, that
       
    49 // might leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C CSIParameters::CSIParameters()
       
    53 {
       
    54 }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CSIParameters::ConstructL
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C void CSIParameters::ConstructL()
       
    62 {
       
    63 } 
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CSIParameters::NewL
       
    67 // Two-phased constructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 EXPORT_C CSIParameters* CSIParameters::NewL()
       
    71 {
       
    72 	CSIParameters* self = NewLC();
       
    73   	CleanupStack::Pop( self );
       
    74     return self;
       
    75 }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CSIParameters::NewLC
       
    79 // Two-phased constructor.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 EXPORT_C CSIParameters* CSIParameters::NewLC()
       
    83 {
       
    84 	CSIParameters* self = new (ELeave) CSIParameters();
       
    85     CleanupStack::PushL( self );
       
    86     self->ConstructL(); 
       
    87     return self;
       
    88 }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CSIParameters::~CSIParameters
       
    92 // Destructor.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C CSIParameters::~CSIParameters()
       
    96 {
       
    97 	iParameterValues.Reset();
       
    98 	iParameterIDs.Reset();
       
    99 }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CSIParameters::SetParameterL
       
   103 // Sets a value X to parameter Y.
       
   104 // (other items were commented in the headers)
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 EXPORT_C void CSIParameters::SetParameterL( const TInt aParameterID, const TInt aParameterValue )
       
   108 {
       
   109 	RUBY_DEBUG_BLOCKL("CSIParameters::SetParameterL");
       
   110     TInt index = iParameterIDs.Find( aParameterID );
       
   111 
       
   112     // If the parameter has been set earlier, update the value
       
   113     if ( index != KErrNotFound )
       
   114         {
       
   115         iParameterValues[index] = aParameterValue;
       
   116         }
       
   117     else{
       
   118 		// create new item for ID and value
       
   119 		User::LeaveIfError( iParameterIDs.Append( aParameterID ) );
       
   120 		TInt error = iParameterValues.Append( aParameterValue );
       
   121 		if ( error )
       
   122 		    {
       
   123 			// remove the previously added
       
   124 			iParameterIDs.Remove( iParameterIDs.Count() - 1 );
       
   125 			User::Leave( error );
       
   126 		    }
       
   127         }
       
   128 }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CSIParameters::ParameterL
       
   132 // Returns the value of a parameter.
       
   133 // (other items were commented in the headers)
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C TInt CSIParameters::ParameterL( const TInt aParameterID ) const
       
   137 {
       
   138 	RUBY_DEBUG_BLOCK("CSIParameters::ParameterL");
       
   139     TInt index = iParameterIDs.Find( aParameterID );
       
   140 
       
   141     // Leave, if not found.
       
   142     User::LeaveIfError( index );
       
   143 
       
   144     return iParameterValues[index];
       
   145 }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CSIParameters::InternalizeL
       
   149 // Restores the object from the stream.
       
   150 // (other items were commented in the headers)
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C void CSIParameters::InternalizeL( RReadStream& aStream )
       
   154     {
       
   155     RUBY_DEBUG_BLOCKL("CSIParameters::InternalizeL");
       
   156     if ( iParameterIDs.Count() > 0 )
       
   157         {
       
   158         User::Leave( KErrInUse );
       
   159         }
       
   160 
       
   161     // Check ID 
       
   162     if ( aStream.ReadInt32L() != KBinaryParameterID )
       
   163         User::Leave( KErrCorrupt );
       
   164 
       
   165     // Param count; can be 0.
       
   166     TInt count = aStream.ReadInt32L();
       
   167 
       
   168     // Read values
       
   169     for( TInt k( 0 ); k < count; k++ )
       
   170         {
       
   171         TInt id    = aStream.ReadInt32L();
       
   172         TInt value = aStream.ReadInt32L();
       
   173 
       
   174         SetParameterL( id, value );
       
   175         }
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CSIParameters::ExternalizeL
       
   180 // Stores the object to a stream.
       
   181 // (other items were commented in the headers)
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 EXPORT_C void CSIParameters::ExternalizeL(RWriteStream& aStream ) const
       
   185     {
       
   186 
       
   187     TInt count = iParameterIDs.Count();
       
   188 
       
   189     // Write ID 
       
   190     aStream.WriteInt32L( KBinaryParameterID );
       
   191 
       
   192     // Param count; can be 0.
       
   193     aStream.WriteInt32L( count );
       
   194 
       
   195     for( TInt k( 0 ); k < count; k++ )
       
   196         {
       
   197         aStream.WriteInt32L( iParameterIDs   [k] );
       
   198         aStream.WriteInt32L( iParameterValues[k] );
       
   199         }
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CSIParameters::ListParametersL
       
   204 // Populates given arrays with parameter IDs and values.
       
   205 // (other items were commented in the headers)
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 EXPORT_C void CSIParameters::ListParametersL( RArray<TInt>& aParameterIDs, 
       
   209                                               RArray<TInt>& aParameterValues ) const
       
   210     {
       
   211     RUBY_DEBUG_BLOCKL("CSIParameters::ListParametersL");
       
   212     TInt i = 0;
       
   213 
       
   214     aParameterIDs.Reset();
       
   215     aParameterValues.Reset();
       
   216 
       
   217     // Loop through all parameter IDs
       
   218     for ( i = 0; i < iParameterIDs.Count(); i++ )
       
   219         {
       
   220         aParameterIDs.Append( iParameterIDs[i] );
       
   221         }
       
   222 
       
   223     // Loop through all parameter values
       
   224     for ( i = 0; i < iParameterValues.Count(); i++ )
       
   225         {
       
   226         aParameterValues.Append( iParameterValues[i] );
       
   227         }
       
   228     }
       
   229 
       
   230 /*****************************************************************************/
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CSIRuleVariant::CSIRuleVariant
       
   234 // C++ default constructor can NOT contain any code, that
       
   235 // might leave.
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 EXPORT_C CSIRuleVariant::CSIRuleVariant( const TSIRuleVariantID aRuleVariantID, 
       
   239 										const TSILexiconID aLexiconID)
       
   240 										:	iRuleVariantID(aRuleVariantID),
       
   241 										iLexiconID(aLexiconID),
       
   242 										iLanguage( ELangEnglish) // UK English as default
       
   243 										
       
   244 {
       
   245 }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CSIRuleVariant::ConstructL
       
   249 // Symbian 2nd phase constructor can leave.
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 EXPORT_C void CSIRuleVariant::ConstructL()
       
   253 {
       
   254 	CSIParameters::ConstructL();
       
   255 } 
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CSIRuleVariant::NewL
       
   259 // Two-phased constructor.
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 EXPORT_C CSIRuleVariant* CSIRuleVariant::NewL(const TSIRuleVariantID aRuleVariantID, 
       
   263 											  const TSILexiconID aLexiconID)
       
   264 {
       
   265 	CSIRuleVariant* self =  NewLC(aRuleVariantID, aLexiconID );
       
   266     CleanupStack::Pop( self );
       
   267     return self;
       
   268 }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CSIRuleVariant::NewLC
       
   272 // Two-phased constructor.
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 EXPORT_C CSIRuleVariant* CSIRuleVariant::NewLC(const TSIRuleVariantID aRuleVariantID, 
       
   276 											  const TSILexiconID aLexiconID)
       
   277 {
       
   278 	CSIRuleVariant* self = new (ELeave) CSIRuleVariant(aRuleVariantID, aLexiconID );
       
   279     CleanupStack::PushL( self );
       
   280     self->ConstructL();
       
   281     return self;
       
   282 }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CSIRuleVariant::~CSIParameters
       
   286 // Destructor.
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 EXPORT_C CSIRuleVariant::~CSIRuleVariant()
       
   290 {
       
   291 	iPronunciationIDs.Reset();
       
   292 }
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CSIRuleVariant::RuleVariantID
       
   296 // Returns the ID of the rule variant.
       
   297 // (other items were commented in a header).
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 EXPORT_C TSIRuleVariantID CSIRuleVariant::RuleVariantID() const
       
   301 {
       
   302 	return iRuleVariantID;
       
   303 }
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // CSIRuleVariant::LexiconID
       
   307 // Returns the ID of the lexicon, which contains the pronunciations.
       
   308 // (other items were commented in a header).
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 EXPORT_C TSILexiconID CSIRuleVariant::LexiconID() const
       
   312 {
       
   313 	return iLexiconID;
       
   314 }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CSIRuleVariant::SetPronunciationIDsL
       
   318 // Sets the pronunciation.
       
   319 // (other items were commented in a header).
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 EXPORT_C void CSIRuleVariant::SetPronunciationIDsL( const TSIPronunciationIDSequence& aPronunciationIDs)
       
   323 {
       
   324 	RUBY_DEBUG_BLOCKL("CSIRuleVariant::SetPronunciationIDsL");
       
   325 	for ( TInt i( 0 ); i < aPronunciationIDs.Count(); i++)
       
   326 	{
       
   327 		User::LeaveIfError( iPronunciationIDs.Append( aPronunciationIDs[i] ) );
       
   328 	}
       
   329 }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CSIRuleVariant::GetPronunciationIDsL
       
   333 // Fetches the pronunciation.
       
   334 // (other items were commented in a header).
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 EXPORT_C void CSIRuleVariant::GetPronunciationIDsL( TSIPronunciationIDSequence& aPronunciationIDs ) const
       
   338 {
       
   339 	RUBY_DEBUG_BLOCKL("CSIRuleVariant::GetPronunciationIDsL");
       
   340 	aPronunciationIDs.Reset();
       
   341 	for ( TInt i( 0 ); i < iPronunciationIDs.Count(); i++)
       
   342 	{
       
   343 		User::LeaveIfError( aPronunciationIDs.Append( iPronunciationIDs[i] ) );
       
   344 	}
       
   345 }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CSIRuleVariant::SetLanguage
       
   349 // Sets the pronunciation language.
       
   350 // (other items were commented in a header).
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 EXPORT_C void CSIRuleVariant::SetLanguage(TLanguage aLanguage)
       
   354 {
       
   355 	iLanguage=aLanguage;
       
   356 }
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CSIRuleVariant::Language
       
   360 // Gets the pronunciation language.
       
   361 // (other items were commented in a header).
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 EXPORT_C TLanguage CSIRuleVariant::Language() const
       
   365 {
       
   366 	return iLanguage;
       
   367 }
       
   368 
       
   369 /*****************************************************************************/
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CSIRule::CSIRule
       
   373 // C++ default constructor can NOT contain any code, that
       
   374 // might leave.
       
   375 // -----------------------------------------------------------------------------
       
   376 //
       
   377 EXPORT_C CSIRule::CSIRule(TSIRuleID aRuleID)
       
   378 :	iRuleID(aRuleID)
       
   379 {
       
   380 }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CSIRule::ConstructL
       
   384 // Symbian 2nd phase constructor can leave.
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 EXPORT_C void CSIRule::ConstructL()
       
   388 {
       
   389 }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CSIRule::NewL
       
   393 // Two-phased constructor.
       
   394 // -----------------------------------------------------------------------------
       
   395 //
       
   396 EXPORT_C CSIRule* CSIRule::NewL(const TSIRuleID aRuleID)
       
   397 {
       
   398 	CSIRule* self = NewLC(aRuleID); 
       
   399 	CleanupStack::Pop(self);
       
   400     return self;
       
   401 }
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // CSIRule::NewLC
       
   405 // Two-phased constructor.
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 EXPORT_C CSIRule* CSIRule::NewLC(const TSIRuleID aRuleID)
       
   409 {
       
   410 	CSIRule* self = new (ELeave) CSIRule(aRuleID);
       
   411     CleanupStack::PushL( self );
       
   412     self->ConstructL();
       
   413 	return self;
       
   414 }
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // CSIRule::~CSIRule
       
   418 // Destructor.
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 EXPORT_C CSIRule::~CSIRule()
       
   422 {
       
   423 	iRuleVariantArray.ResetAndDestroy();
       
   424 }
       
   425 
       
   426 
       
   427 
       
   428 
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // CSIRule::RuleID
       
   432 // Returns the ID of the rule.
       
   433 // -----------------------------------------------------------------------------
       
   434 //
       
   435 EXPORT_C TSIRuleID CSIRule::RuleID() const
       
   436 {
       
   437 	return iRuleID;
       
   438 } 
       
   439 
       
   440 // -----------------------------------------------------------------------------
       
   441 // CSIRule::Count
       
   442 // Returns the number of rule variants.
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 EXPORT_C TInt CSIRule::Count() const
       
   446 {
       
   447 	return iRuleVariantArray.Count();
       
   448 }
       
   449 
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // CSIRule::Compare
       
   453 // Compares two CSIRule objects to each other based on ids.
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 TInt CSIRule::Compare( const CSIRule& aFirst, 
       
   457                        const CSIRule& aSecond )
       
   458     {
       
   459     if ( aFirst.RuleID() < aSecond.RuleID() )
       
   460         {
       
   461         return -1;
       
   462         }
       
   463     if ( aFirst.RuleID() > aSecond.RuleID() )
       
   464         {
       
   465         return 1;
       
   466         }
       
   467     // IDs are equal
       
   468     return 0;
       
   469     }
       
   470 
       
   471 // -----------------------------------------------------------------------------
       
   472 // CSIRule::AtL
       
   473 // Used to get a variant.
       
   474 // -----------------------------------------------------------------------------
       
   475 //
       
   476 EXPORT_C CSIRuleVariant& CSIRule::AtL(TInt aIndex) const
       
   477 {
       
   478 	// too much output RUBY_DEBUG_BLOCK("CSIRule::AtL"); 
       
   479 	if(aIndex<0 || aIndex >= Count()) 
       
   480 		{
       
   481 		RUBY_DEBUG2("[Error!]CSIRule::AtL index [%d] is out of bounds. Count is [%d]. Leaving with KErrArgument", aIndex, Count());
       
   482 		User::Leave(KErrArgument);
       
   483 		}		
       
   484 	return *(iRuleVariantArray[aIndex]);
       
   485 }
       
   486 
       
   487 // -----------------------------------------------------------------------------
       
   488 // CSIRule::Find
       
   489 // Returns the index of the variant with given id.
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 EXPORT_C  TInt CSIRule::Find(TSIRuleVariantID aRuleVariantID) const
       
   493 {
       
   494 	for ( TInt i(0); i < iRuleVariantArray.Count(); i++ )
       
   495 	{
       
   496 		if ( aRuleVariantID == iRuleVariantArray[i]->RuleVariantID() )
       
   497 		{
       
   498 			return i;
       
   499 		}
       
   500 	} 
       
   501 	return( KErrNotFound );
       
   502 }
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CSIRule::AddL
       
   506 // Adds a rule variant to the rule.
       
   507 // -----------------------------------------------------------------------------
       
   508 //
       
   509 EXPORT_C void CSIRule::AddL( CSIRuleVariant* aRuleVariant )
       
   510 {
       
   511 	RUBY_DEBUG_BLOCKL("CSIRule::AddL");
       
   512     // Check that the rule isn't already there
       
   513 	if ( Find( aRuleVariant->RuleVariantID() ) != KErrNotFound )
       
   514 	{
       
   515 		User::Leave( KErrAlreadyExists );
       
   516 	}
       
   517 
       
   518     User::LeaveIfError( iRuleVariantArray.Append( aRuleVariant ) );
       
   519 }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CSIRule::RuleVariantL
       
   523 // Used to get a rule variant with given ID.
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 EXPORT_C  CSIRuleVariant& CSIRule::RuleVariantL(TSIRuleVariantID aRuleVariantID) const
       
   527 {
       
   528 	RUBY_DEBUG_BLOCK("CSIRule::RuleVariantL");
       
   529 	TInt aIndex = Find(aRuleVariantID);
       
   530 	
       
   531     User::LeaveIfError( aIndex );
       
   532 	
       
   533     return(AtL(aIndex));
       
   534 }
       
   535 
       
   536 // -----------------------------------------------------------------------------
       
   537 // CSIRule::DeleteL
       
   538 // Deletes the rule variant with given ID.
       
   539 // -----------------------------------------------------------------------------
       
   540 //
       
   541 EXPORT_C void CSIRule::DeleteL(TSIRuleVariantID aRuleVariantID)
       
   542 {
       
   543 	RUBY_DEBUG_BLOCK("CSIRule::DeleteL");
       
   544     TInt index = User::LeaveIfError( Find( aRuleVariantID ) );
       
   545 
       
   546     delete  iRuleVariantArray[index];
       
   547 	iRuleVariantArray.Remove(index);
       
   548 }
       
   549 
       
   550 
       
   551 
       
   552 
       
   553 
       
   554 /*****************************************************************************/
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // CSIGrammar::CSIGrammar
       
   558 // C++ default constructor can NOT contain any code, that
       
   559 // might leave.
       
   560 // -----------------------------------------------------------------------------
       
   561 //
       
   562 EXPORT_C CSIGrammar::CSIGrammar(TSIGrammarID aGrammarID)
       
   563 :	iGrammarID(aGrammarID)
       
   564 {
       
   565 }
       
   566 
       
   567 // -----------------------------------------------------------------------------
       
   568 // CSIGrammar::ConstructL
       
   569 // Symbian 2nd phase constructor can leave.
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 EXPORT_C void CSIGrammar::ConstructL()
       
   573 {
       
   574 }
       
   575 
       
   576 // -----------------------------------------------------------------------------
       
   577 // CSIGrammar::NewL
       
   578 // Two-phased constructor.
       
   579 // -----------------------------------------------------------------------------
       
   580 //
       
   581 EXPORT_C CSIGrammar* CSIGrammar::NewL(const TSIGrammarID aGrammarID)
       
   582 {
       
   583     CSIGrammar* self = NewLC(aGrammarID);
       
   584 	CleanupStack::Pop(self);
       
   585     return self;
       
   586 }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CSIGrammar::NewLC
       
   590 // Two-phased constructor.
       
   591 // -----------------------------------------------------------------------------
       
   592 //
       
   593 EXPORT_C CSIGrammar* CSIGrammar::NewLC(const TSIGrammarID aGrammarID)
       
   594 {
       
   595 	CSIGrammar* self = new (ELeave) CSIGrammar(aGrammarID);
       
   596     CleanupStack::PushL( self );
       
   597     self->ConstructL();
       
   598 	return self;
       
   599 	
       
   600 }
       
   601 
       
   602 // -----------------------------------------------------------------------------
       
   603 // CSIGrammar::~CSIGrammar
       
   604 // Destructor.
       
   605 // -----------------------------------------------------------------------------
       
   606 //
       
   607 EXPORT_C CSIGrammar::~CSIGrammar()
       
   608 {
       
   609 	iRuleArray.ResetAndDestroy();
       
   610 	iRuleArray.Close();
       
   611 }
       
   612 
       
   613 
       
   614 
       
   615 // -----------------------------------------------------------------------------
       
   616 // CSIGrammar::GrammarID
       
   617 // Returns the ID of the given grammar.
       
   618 // (other items were commented in the headers)
       
   619 // -----------------------------------------------------------------------------
       
   620 //
       
   621 EXPORT_C TSIGrammarID CSIGrammar::GrammarID() const
       
   622 {
       
   623 	return iGrammarID;
       
   624 }
       
   625 
       
   626 
       
   627 // -----------------------------------------------------------------------------
       
   628 // CSIGrammar::AddL
       
   629 // Adds a rule to the grammar.
       
   630 // (other items were commented in the headers)
       
   631 // -----------------------------------------------------------------------------
       
   632 //
       
   633 EXPORT_C void CSIGrammar::AddL(CSIRule* aRule)
       
   634 {
       
   635 	// too much output RUBY_DEBUG_BLOCKL("CSIGrammar::AddL");
       
   636 
       
   637     // Order function which is used when finding the correct place to insert
       
   638     TLinearOrder<CSIRule> order( CSIRule::Compare );
       
   639 
       
   640     // InsertInOrderL does not allow duplicates
       
   641     iRuleArray.InsertInOrderL( aRule, order );
       
   642 }
       
   643 
       
   644 // -----------------------------------------------------------------------------
       
   645 // CSIGrammar::DeleteL
       
   646 // Deletes a rule with given ID.
       
   647 // (other items were commented in the headers)
       
   648 // -----------------------------------------------------------------------------
       
   649 //
       
   650 EXPORT_C void CSIGrammar::DeleteL(TSIRuleID aRuleID)
       
   651 {
       
   652 	RUBY_DEBUG_BLOCK("CSIGrammar::DeleteL");
       
   653 	TInt index = Find(aRuleID);
       
   654     User::LeaveIfError( index );
       
   655 
       
   656 	delete iRuleArray[index];
       
   657 	iRuleArray.Remove(index);
       
   658 }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // CSIGrammar::AtL
       
   662 // Used to get a rule.
       
   663 // (other items were commented in the headers)
       
   664 // -----------------------------------------------------------------------------
       
   665 //
       
   666 EXPORT_C CSIRule& CSIGrammar::AtL(TInt anIndex) const
       
   667 {
       
   668 	if(anIndex<0 || anIndex >= Count())
       
   669 		{
       
   670 		RUBY_DEBUG2("[Error!]CSIGrammar::AtL index [%d] is out of bounds. Count is [%d]. Leaving with KErrArgument", anIndex, Count());
       
   671 		User::Leave(KErrArgument);
       
   672 		}
       
   673 		
       
   674 	return *(iRuleArray[anIndex]);
       
   675 	
       
   676 }
       
   677 
       
   678 // -----------------------------------------------------------------------------
       
   679 // CSIGrammar::Find
       
   680 // Finds the index of the rule with given ID.
       
   681 // (other items were commented in the headers)
       
   682 // -----------------------------------------------------------------------------
       
   683 //
       
   684 EXPORT_C TInt CSIGrammar::Find(TSIRuleID aRuleID) const
       
   685 {
       
   686     // Order function which is used when finding the correct item
       
   687     TLinearOrder<CSIRule> order( CSIRule::Compare );
       
   688 
       
   689     TInt retVal = KErrNotFound;
       
   690 
       
   691     TRAPD( error,
       
   692 
       
   693         // Construct a 'dummy' CSIPronunciation so that comparison can be done 
       
   694         // against it
       
   695         CSIRule* rule = CSIRule::NewL( aRuleID );
       
   696 
       
   697         CleanupStack::PushL( rule );
       
   698 
       
   699         // Use binary search since array is kept in the order of rule ids
       
   700         retVal = iRuleArray.FindInOrderL( rule, order );
       
   701     
       
   702         CleanupStack::PopAndDestroy( rule );
       
   703         );
       
   704 
       
   705     if ( error != KErrNone )
       
   706         {
       
   707         return error;
       
   708         }
       
   709     return retVal;
       
   710 }
       
   711 
       
   712 // -----------------------------------------------------------------------------
       
   713 // CSIGrammar::Count
       
   714 // Returns the number of rules.
       
   715 // (other items were commented in the headers)
       
   716 // -----------------------------------------------------------------------------
       
   717 //
       
   718 EXPORT_C TInt CSIGrammar::Count() const
       
   719 {
       
   720 	return iRuleArray.Count();
       
   721 }
       
   722 
       
   723 // -----------------------------------------------------------------------------
       
   724 // CSIGrammar::RuleL
       
   725 // Used to get a rule with given ID.
       
   726 // (other items were commented in the headers)
       
   727 // -----------------------------------------------------------------------------
       
   728 //
       
   729 EXPORT_C  CSIRule&  CSIGrammar::RuleL(TSIRuleID aRuleID) const
       
   730 {
       
   731 	RUBY_DEBUG_BLOCK("CSIGrammar::RuleL");
       
   732 	TInt aIndex = Find(aRuleID);
       
   733 #ifdef _DEBUG
       
   734 	if( aIndex < 0 ) 
       
   735 		{
       
   736 		RUBY_DEBUG2("CSIGrammar::RuleL Error [%d] finding aRuleID [%d]. Leaving", aIndex, aRuleID);
       
   737 		}
       
   738 #endif	
       
   739     User::LeaveIfError( aIndex );
       
   740 	
       
   741     return(AtL(aIndex));
       
   742 }
       
   743 
       
   744 // -----------------------------------------------------------------------------
       
   745 // CSIGrammar::ExternalizeL
       
   746 // Stores the object to the stream.
       
   747 // (other items were commented in the headers)
       
   748 // -----------------------------------------------------------------------------
       
   749 //
       
   750 EXPORT_C void CSIGrammar::ExternalizeL( RWriteStream& aWriteStream ) const
       
   751     {
       
   752     aWriteStream.WriteInt32L( KBinaryGrammarID );
       
   753 
       
   754     CSIGrammarSerializer* grammarSerializer = CSIGrammarSerializer::NewLC( *this );
       
   755     grammarSerializer->ExternalizeL( aWriteStream );
       
   756     CleanupStack::PopAndDestroy( grammarSerializer );
       
   757 
       
   758     aWriteStream.WriteInt32L( KBinaryGrammarID );
       
   759     }
       
   760 
       
   761 // -----------------------------------------------------------------------------
       
   762 // CSIGrammar::InternalizeL
       
   763 // Restores the object from a stream.
       
   764 // (other items were commented in the headers)
       
   765 // -----------------------------------------------------------------------------
       
   766 //
       
   767 EXPORT_C void CSIGrammar::InternalizeL( RReadStream& aReadStream )
       
   768     {
       
   769     RUBY_DEBUG_BLOCK("CSIGrammar::InternalizeL");
       
   770     if ( iRuleArray.Count() > 0 )
       
   771         {
       
   772         User::Leave( KErrInUse );
       
   773         }
       
   774 
       
   775     // Read header: Format ID, grammar ID and number of rules.
       
   776     if ( aReadStream.ReadInt32L() != KBinaryGrammarID )
       
   777         {
       
   778         User::Leave( KErrCorrupt );
       
   779         }
       
   780 
       
   781     CSIGrammarSerializer* grammarSerializer
       
   782         = CSIGrammarSerializer::NewLC( aReadStream );
       
   783 
       
   784     grammarSerializer->RestoreL( *this, iGrammarID );
       
   785     CleanupStack::PopAndDestroy( grammarSerializer );
       
   786 
       
   787     if ( aReadStream.ReadInt32L() != KBinaryGrammarID )
       
   788         {
       
   789         User::Leave( KErrCorrupt );
       
   790         }
       
   791     }
       
   792 
       
   793 /*****************************************************************************/
       
   794 
       
   795 // -----------------------------------------------------------------------------
       
   796 // CSICompiledGrammar::CSICompiledGrammar
       
   797 // C++ default constructor can NOT contain any code, that
       
   798 // might leave.
       
   799 // -----------------------------------------------------------------------------
       
   800 //
       
   801 EXPORT_C CSICompiledGrammar::CSICompiledGrammar(TSIGrammarID aGrammarID 
       
   802 												)
       
   803 												: CSIGrammar(aGrammarID), iValidData(EFalse),  iGrammarCompilerData( NULL )
       
   804 {
       
   805 }
       
   806 
       
   807 // -----------------------------------------------------------------------------
       
   808 // CSICompiledGrammar::ConstructL
       
   809 // Symbian 2nd phase constructor can leave.
       
   810 // -----------------------------------------------------------------------------
       
   811 //
       
   812 EXPORT_C void CSICompiledGrammar::ConstructL()
       
   813 {
       
   814 }
       
   815 
       
   816 // -----------------------------------------------------------------------------
       
   817 // CSICompiledGrammar::NewL
       
   818 // Two-phased constructor.
       
   819 // -----------------------------------------------------------------------------
       
   820 //
       
   821 EXPORT_C CSICompiledGrammar* CSICompiledGrammar::NewL(TSIGrammarID aGrammarID)
       
   822 {
       
   823 	CSICompiledGrammar* self = NewLC(aGrammarID) ;    
       
   824 	CleanupStack::Pop(self);
       
   825     return self;
       
   826 }
       
   827 
       
   828 // -----------------------------------------------------------------------------
       
   829 // CSICompiledGrammar::NewLC
       
   830 // Two-phased constructor.
       
   831 // -----------------------------------------------------------------------------
       
   832 //
       
   833 EXPORT_C CSICompiledGrammar* CSICompiledGrammar::NewLC(TSIGrammarID aGrammarID)
       
   834 {
       
   835 	CSICompiledGrammar* self = new (ELeave) CSICompiledGrammar(aGrammarID) ;
       
   836     CleanupStack::PushL( self );
       
   837     self->ConstructL();
       
   838     return self;
       
   839 }
       
   840 
       
   841 // -----------------------------------------------------------------------------
       
   842 // CSICompiledGrammar::~CSICompiledGrammar
       
   843 // Destructor.
       
   844 // -----------------------------------------------------------------------------
       
   845 //
       
   846 EXPORT_C CSICompiledGrammar::~CSICompiledGrammar()
       
   847 {
       
   848 	delete iGrammarCompilerData;
       
   849 }
       
   850 
       
   851 // -----------------------------------------------------------------------------
       
   852 // CSICompiledGrammar::AddL
       
   853 // Adds a new rule to the grammar.
       
   854 // (other items were commented in the headers)
       
   855 // -----------------------------------------------------------------------------
       
   856 //
       
   857 EXPORT_C void CSICompiledGrammar::AddL(CSIRule* aRule)
       
   858 {
       
   859 	RUBY_DEBUG_BLOCKL("CSICompiledGrammar::AddL");
       
   860 	iValidData = EFalse;
       
   861 	CSIGrammar::AddL(aRule);
       
   862 }
       
   863 
       
   864 // -----------------------------------------------------------------------------
       
   865 // CSICompiledGrammar::DeleteL
       
   866 // Delets a rule with given ID.
       
   867 // (other items were commented in the headers)
       
   868 // -----------------------------------------------------------------------------
       
   869 //
       
   870 EXPORT_C void CSICompiledGrammar::DeleteL(TSIRuleID aRuleID)
       
   871 {
       
   872 	RUBY_DEBUG_BLOCK("CSICompiledGrammar::DeleteL");
       
   873 	iValidData = EFalse;
       
   874 	CSIGrammar::DeleteL(aRuleID);
       
   875 }
       
   876 
       
   877 
       
   878 // -----------------------------------------------------------------------------
       
   879 // CSICompiledGrammar::SetCompiledData
       
   880 // Sets the compiled grammar data.
       
   881 // (other items were commented in the headers)
       
   882 // -----------------------------------------------------------------------------
       
   883 //
       
   884 EXPORT_C void CSICompiledGrammar::SetCompiledData( HBufC8* aCompilerData )
       
   885 {	 
       
   886 	delete  iGrammarCompilerData;
       
   887 	iGrammarCompilerData = aCompilerData;
       
   888 }
       
   889 
       
   890 
       
   891 // -----------------------------------------------------------------------------
       
   892 // CSICompiledGrammar::CompiledData
       
   893 // Gets a descriptor to the compiled grammar data.
       
   894 // (other items were commented in the headers)
       
   895 // -----------------------------------------------------------------------------
       
   896 //
       
   897 EXPORT_C   TDesC8&  CSICompiledGrammar::CompiledData() const
       
   898 {
       
   899 	return *iGrammarCompilerData;
       
   900 }
       
   901 
       
   902 // -----------------------------------------------------------------------------
       
   903 // CSICompiledGrammar::ExternalizeL
       
   904 // Stores the object to the stream.
       
   905 // (other items were commented in the headers)
       
   906 // -----------------------------------------------------------------------------
       
   907 //
       
   908 EXPORT_C void CSICompiledGrammar::ExternalizeL( RWriteStream& aWriteStream ) const
       
   909     {
       
   910     aWriteStream.WriteInt32L( KBinaryCompiledGrammarID );
       
   911 
       
   912     CSIGrammar::ExternalizeL( aWriteStream );
       
   913 
       
   914     // Read compiled grammar data
       
   915     if ( iGrammarCompilerData )
       
   916         {
       
   917         TInt length = iGrammarCompilerData->Length();
       
   918         aWriteStream.WriteInt32L( length );
       
   919         aWriteStream.WriteL( iGrammarCompilerData->Des(), length );
       
   920         }
       
   921     else
       
   922         {
       
   923         aWriteStream.WriteInt32L( 0 );
       
   924         }
       
   925 
       
   926     // Corruption check
       
   927     aWriteStream.WriteInt32L( KBinaryCompiledGrammarID );
       
   928     }
       
   929 
       
   930 // -----------------------------------------------------------------------------
       
   931 // CSICompiledGrammar::InternalizeL
       
   932 // Restores the object from a stream.
       
   933 // (other items were commented in the headers)
       
   934 // -----------------------------------------------------------------------------
       
   935 //
       
   936 EXPORT_C void CSICompiledGrammar::InternalizeL( RReadStream& aReadStream )
       
   937     {
       
   938     RUBY_DEBUG_BLOCK("CSICompiledGrammar::InternalizeL");
       
   939     if ( aReadStream.ReadInt32L() != KBinaryCompiledGrammarID )
       
   940         User::Leave( KErrCorrupt );
       
   941 
       
   942     CSIGrammar::InternalizeL( aReadStream );
       
   943 
       
   944     // Read compiled grammar data
       
   945     TInt length = aReadStream.ReadInt32L();
       
   946 
       
   947     if ( length > 0 )
       
   948         {
       
   949         iGrammarCompilerData = HBufC8::NewL( length );
       
   950         TPtr8 compilerDataPtr = iGrammarCompilerData->Des();
       
   951         aReadStream.ReadL( compilerDataPtr, length );
       
   952         }
       
   953 
       
   954     // Corruption check
       
   955     if ( aReadStream.ReadInt32L() != KBinaryCompiledGrammarID )
       
   956         User::Leave( KErrCorrupt );
       
   957     }
       
   958 
       
   959 /*****************************************************************************/
       
   960 // -----------------------------------------------------------------------------
       
   961 // TSIRuleVariantInfo::TSIRuleVariantInfo
       
   962 // C++ default constructor can NOT contain any code, that
       
   963 // might leave.
       
   964 // -----------------------------------------------------------------------------
       
   965 //
       
   966 EXPORT_C TSIRuleVariantInfo::TSIRuleVariantInfo( 
       
   967 												const TSIGrammarID aGrammarID, 			
       
   968 												const TSIRuleID aRuleID, 
       
   969 												const TSIRuleVariantID aRuleVariantID )
       
   970 												:	iGrammarID( aGrammarID ),
       
   971 												iRuleID( aRuleID ),
       
   972 												iRuleVariantID( aRuleVariantID )
       
   973 {
       
   974     // nothing
       
   975 }
       
   976 
       
   977 // -----------------------------------------------------------------------------
       
   978 // TSIRuleVariantInfo::~TSIRuleVariantInfo
       
   979 // Destructor.
       
   980 // -----------------------------------------------------------------------------
       
   981 //
       
   982 EXPORT_C TSIRuleVariantInfo::~TSIRuleVariantInfo()
       
   983 {
       
   984 	// nothing
       
   985 }
       
   986 
       
   987 
       
   988 // -----------------------------------------------------------------------------
       
   989 // TSIRuleVariantInfo::GrammarID
       
   990 // Returns the grammar ID.
       
   991 // (other items were commented in the headers)
       
   992 // -----------------------------------------------------------------------------
       
   993 //
       
   994 EXPORT_C TSIGrammarID TSIRuleVariantInfo::GrammarID() const
       
   995 {
       
   996     return iGrammarID;
       
   997 }
       
   998 // -----------------------------------------------------------------------------
       
   999 // TSIRuleVariantInfo::RuleID
       
  1000 // Return rule identifier.
       
  1001 // (other items were commented in a header).
       
  1002 // -----------------------------------------------------------------------------
       
  1003 //
       
  1004 EXPORT_C TSIRuleID TSIRuleVariantInfo::RuleID() const
       
  1005 {
       
  1006     return iRuleID;
       
  1007 }
       
  1008 
       
  1009 // -----------------------------------------------------------------------------
       
  1010 // TSIRuleVariantInfo::RuleVariantID
       
  1011 // Return rule variant identifier.
       
  1012 // (other items were commented in a header).
       
  1013 // -----------------------------------------------------------------------------
       
  1014 //
       
  1015 EXPORT_C TSIRuleVariantID TSIRuleVariantInfo::RuleVariantID() const
       
  1016 {
       
  1017     return iRuleVariantID;
       
  1018 }
       
  1019 
       
  1020 /******************************************************************************/
       
  1021 
       
  1022 // -----------------------------------------------------------------------------
       
  1023 // CSIPronunciation::CSIPronunciation
       
  1024 // C++ default constructor can NOT contain any code, that
       
  1025 // might leave.
       
  1026 // -----------------------------------------------------------------------------
       
  1027 //
       
  1028 EXPORT_C CSIPronunciation::CSIPronunciation( const TSIPronunciationID aPronunciationID,
       
  1029                                              const TSIModelBankID aModelBankID )
       
  1030                                             : iPronunciationID( aPronunciationID ),
       
  1031                                               iModelBankID( aModelBankID ),
       
  1032                                               iPhonemeSequence( NULL )
       
  1033     {
       
  1034     }
       
  1035 
       
  1036 // -----------------------------------------------------------------------------
       
  1037 // CSIPronunciation::ConstructL
       
  1038 // Symbian 2nd phase constructor can leave.
       
  1039 // -----------------------------------------------------------------------------
       
  1040 //
       
  1041 EXPORT_C void CSIPronunciation::ConstructL()
       
  1042     {
       
  1043     }
       
  1044 
       
  1045 
       
  1046 // -----------------------------------------------------------------------------
       
  1047 // CSIPronunciation::NewL
       
  1048 // Two-phased constructor.
       
  1049 // -----------------------------------------------------------------------------
       
  1050 //
       
  1051 EXPORT_C CSIPronunciation* CSIPronunciation::NewL( const TSIPronunciationID aPronunciationID, 
       
  1052                                                    const TSIModelBankID aModelBankID )
       
  1053     {
       
  1054     CSIPronunciation* self = NewLC ( aPronunciationID, aModelBankID );
       
  1055     CleanupStack::Pop( self );
       
  1056     return self;
       
  1057     }
       
  1058 
       
  1059 
       
  1060 
       
  1061 // -----------------------------------------------------------------------------
       
  1062 // CSIPronunciation::NewLC
       
  1063 // Two-phased constructor.
       
  1064 // -----------------------------------------------------------------------------
       
  1065 //
       
  1066 EXPORT_C CSIPronunciation* CSIPronunciation::NewLC( const TSIPronunciationID aPronunciationID, 
       
  1067                                                     const TSIModelBankID aModelBankID )
       
  1068     {
       
  1069     CSIPronunciation* self = new (ELeave) CSIPronunciation( aPronunciationID, aModelBankID );
       
  1070     CleanupStack::PushL( self );
       
  1071     self->ConstructL();
       
  1072     return self;
       
  1073     }
       
  1074 
       
  1075 // -----------------------------------------------------------------------------
       
  1076 // CSIPronunciation::~CSIPronunciation
       
  1077 // Destructor.
       
  1078 // -----------------------------------------------------------------------------
       
  1079 //
       
  1080 EXPORT_C CSIPronunciation::~CSIPronunciation()
       
  1081     {
       
  1082     delete iPhonemeSequence;
       
  1083     }
       
  1084 
       
  1085 // -----------------------------------------------------------------------------
       
  1086 // CSIPronunciation::Compare
       
  1087 // Compares two CSIPronunciation objects to each other based on ids.
       
  1088 // -----------------------------------------------------------------------------
       
  1089 //
       
  1090 TInt CSIPronunciation::Compare( const CSIPronunciation& aFirst, 
       
  1091                                 const CSIPronunciation& aSecond )
       
  1092     {
       
  1093     if ( aFirst.PronunciationID() < aSecond.PronunciationID() )
       
  1094         {
       
  1095         return -1;
       
  1096         }
       
  1097     if ( aFirst.PronunciationID() > aSecond.PronunciationID() )
       
  1098         {
       
  1099         return 1;
       
  1100         }
       
  1101     // IDs are equal
       
  1102     return 0;
       
  1103     }
       
  1104 
       
  1105 // -----------------------------------------------------------------------------
       
  1106 // CSIPronunciation::ComparePhonemes
       
  1107 // Compares two CSIPronunciation objects to each other based pronunciations.
       
  1108 // -----------------------------------------------------------------------------
       
  1109 //
       
  1110 TInt CSIPronunciation::ComparePhonemes( const CSIPronunciation& aFirst, 
       
  1111                                         const CSIPronunciation& aSecond )
       
  1112     {
       
  1113     if ( aFirst.PhonemeSequence() < aSecond.PhonemeSequence() )
       
  1114         {
       
  1115         return -1;
       
  1116         }
       
  1117     if ( aFirst.PhonemeSequence() > aSecond.PhonemeSequence() )
       
  1118         {
       
  1119         return 1;
       
  1120         }
       
  1121     // Phoneme sequences are equal
       
  1122     return 0;
       
  1123     }
       
  1124 
       
  1125 // -----------------------------------------------------------------------------
       
  1126 // CSIPronunciation::PronunciationID
       
  1127 // Returns the pronunciation ID.
       
  1128 // -----------------------------------------------------------------------------
       
  1129 //
       
  1130 EXPORT_C TSIPronunciationID CSIPronunciation::PronunciationID() const
       
  1131     {
       
  1132     return iPronunciationID;
       
  1133     }
       
  1134 
       
  1135 // -----------------------------------------------------------------------------
       
  1136 // CSIPronunciation::ModelBankID
       
  1137 // Returns the pronunciation ID.
       
  1138 // -----------------------------------------------------------------------------
       
  1139 //
       
  1140 EXPORT_C TSIModelBankID CSIPronunciation::ModelBankID() const
       
  1141     {
       
  1142     return iModelBankID;
       
  1143     }
       
  1144 
       
  1145 // -----------------------------------------------------------------------------
       
  1146 // CSIPronunciation::SetPhonemeSequenceL
       
  1147 // Sets Phoneme Sequence
       
  1148 // -----------------------------------------------------------------------------
       
  1149 //
       
  1150 EXPORT_C void CSIPronunciation::SetPhonemeSequenceL( const TDesC8& aPhonemeSequence )
       
  1151     {
       
  1152     if ( iPhonemeSequence )
       
  1153         {
       
  1154         // delete old data
       
  1155         delete iPhonemeSequence;
       
  1156         iPhonemeSequence = NULL;
       
  1157         }
       
  1158 	
       
  1159     iPhonemeSequence = HBufC8::NewL( aPhonemeSequence.Length() );
       
  1160     (*iPhonemeSequence) = aPhonemeSequence;
       
  1161     }
       
  1162 
       
  1163 
       
  1164 // -----------------------------------------------------------------------------
       
  1165 // CSIPronunciation::PhonemeSequence
       
  1166 // returns Phoneme Sequence
       
  1167 // -----------------------------------------------------------------------------
       
  1168 //
       
  1169 EXPORT_C const TDesC8& CSIPronunciation::PhonemeSequence() const
       
  1170     {
       
  1171     return *iPhonemeSequence;
       
  1172     }
       
  1173 
       
  1174 // -----------------------------------------------------------------------------
       
  1175 // CSIPronunciation::SetPronunciationID
       
  1176 // Sets the pronunciation ID.
       
  1177 // -----------------------------------------------------------------------------
       
  1178 //
       
  1179 EXPORT_C void CSIPronunciation::SetPronunciationID( TSIPronunciationID aPronunciationID )
       
  1180     {
       
  1181     iPronunciationID=aPronunciationID;
       
  1182     }
       
  1183     
       
  1184 /*****************************************************************************/
       
  1185 
       
  1186 // -----------------------------------------------------------------------------
       
  1187 // CSILexicon::CSILexicon
       
  1188 // C++ default constructor can NOT contain any code, that
       
  1189 // might leave.
       
  1190 // -----------------------------------------------------------------------------
       
  1191 //
       
  1192 EXPORT_C CSILexicon::CSILexicon( TSILexiconID aLexiconID )
       
  1193                                : iLexiconID(aLexiconID)
       
  1194     {
       
  1195     }
       
  1196 
       
  1197 // -----------------------------------------------------------------------------
       
  1198 // CSILexicon::ConstructL
       
  1199 // Symbian 2nd phase constructor can leave.
       
  1200 // -----------------------------------------------------------------------------
       
  1201 //
       
  1202 EXPORT_C void CSILexicon::ConstructL()
       
  1203     {
       
  1204     }
       
  1205 
       
  1206 // -----------------------------------------------------------------------------
       
  1207 // CSILexicon::NewL
       
  1208 // Two-phased constructor.
       
  1209 // -----------------------------------------------------------------------------
       
  1210 //
       
  1211 EXPORT_C CSILexicon* CSILexicon::NewL( TSILexiconID aLexiconID )
       
  1212     {
       
  1213     CSILexicon* self = NewLC( aLexiconID );
       
  1214     CleanupStack::Pop( self );
       
  1215     return self;
       
  1216     }
       
  1217 
       
  1218 
       
  1219 // -----------------------------------------------------------------------------
       
  1220 // CSILexicon::NewLC
       
  1221 // Two-phased constructor.
       
  1222 // -----------------------------------------------------------------------------
       
  1223 //
       
  1224 EXPORT_C CSILexicon* CSILexicon::NewLC( TSILexiconID aLexiconID )
       
  1225     {
       
  1226     CSILexicon* self = new ( ELeave ) CSILexicon( aLexiconID );
       
  1227     CleanupStack::PushL( self );
       
  1228     self->ConstructL(); 
       
  1229     return self;
       
  1230     }
       
  1231 
       
  1232 // -----------------------------------------------------------------------------
       
  1233 // CSILexicon::~CSILexicon
       
  1234 // Destructor.
       
  1235 // -----------------------------------------------------------------------------
       
  1236 //
       
  1237 EXPORT_C CSILexicon::~CSILexicon()
       
  1238     {
       
  1239     iPronunciationArray.ResetAndDestroy();
       
  1240     iPronunciationArray.Close();
       
  1241     iPronunOrder.Close();
       
  1242     }
       
  1243 
       
  1244 // -----------------------------------------------------------------------------
       
  1245 // CSILexicon::LexiconID
       
  1246 // Gets the ID of the lexicon.
       
  1247 // -----------------------------------------------------------------------------
       
  1248 //
       
  1249 EXPORT_C TSIGrammarID CSILexicon::LexiconID() const
       
  1250     {
       
  1251     return iLexiconID;
       
  1252     }
       
  1253 
       
  1254 // -----------------------------------------------------------------------------
       
  1255 // CSILexicon::AddL
       
  1256 // Adds a pronunciation.
       
  1257 // -----------------------------------------------------------------------------
       
  1258 //
       
  1259 EXPORT_C void CSILexicon::AddL( CSIPronunciation* aPronunciation )
       
  1260     {
       
  1261 #ifdef __SIND_LEXICON_OPT
       
  1262     RUBY_DEBUG_BLOCKL( "CSILexicon::AddL (SINDE optimized)" );
       
  1263     
       
  1264     RUBY_ASSERT_DEBUG( iPronunciationArray.Count() == iPronunOrder.Count(), User::Leave( KErrCorrupt ) );
       
  1265     
       
  1266     // Check if current lexicon already holds maximal allowed number of 
       
  1267     // pronunciations or that there is no limit
       
  1268     if( ( KMaxPronunciations != 0 ) && ( iPronunciationArray.Count() > KMaxPronunciations ) )
       
  1269     	{
       
  1270     	User::Leave( KErrNoMemory );
       
  1271     	}
       
  1272 
       
  1273     if ( aPronunciation == NULL )
       
  1274         {
       
  1275         User::Leave( KErrArgument );
       
  1276         }
       
  1277         
       
  1278     // Check that pronunciation is not null
       
  1279     const TDesC8& phonemeSeq = aPronunciation->PhonemeSequence();
       
  1280 
       
  1281     if ( &phonemeSeq == NULL )
       
  1282         {
       
  1283         User::Leave( KErrArgument );
       
  1284         }
       
  1285 
       
  1286     // Check if CSIPronunciation which is given as parameter has the usage counter already
       
  1287     TRAPD( error, TInt temp = aPronunciation->ParameterL( KLexiconReferenceCounter ) );
       
  1288     TBool counterFound( EFalse );
       
  1289     
       
  1290     if ( error == KErrNone )
       
  1291         {
       
  1292         counterFound = ETrue;
       
  1293         }
       
  1294     else
       
  1295         {
       
  1296         counterFound = EFalse;
       
  1297         // New counter
       
  1298         aPronunciation->SetParameterL( KLexiconReferenceCounter, KInitialCounterValue );
       
  1299         }
       
  1300 
       
  1301     // 1. Insert first based on the phoneme sequence order
       
  1302     TLinearOrder<CSIPronunciation> phonemeOrder( CSIPronunciation::ComparePhonemes );
       
  1303     TRAP( error, iPronunOrder.InsertInOrderL( aPronunciation, phonemeOrder ) );
       
  1304     
       
  1305     // Store the index for later use
       
  1306     TInt phonemeSeqIndex = iPronunOrder.FindInOrder( aPronunciation, phonemeOrder );
       
  1307       
       
  1308     // Don't add the same data again
       
  1309     if ( error == KErrAlreadyExists )
       
  1310         {
       
  1311         // Append counter only if it was not found from the parameter
       
  1312         // This way externalize/internalize works ok, counter won't be touched when
       
  1313         // there is one already
       
  1314         if ( !counterFound )
       
  1315             {
       
  1316             TInt counterValue( 0 );
       
  1317             // Just increase the usage counter
       
  1318             CSIPronunciation* existingPronun = iPronunOrder[phonemeSeqIndex];
       
  1319             counterValue = existingPronun->ParameterL( KLexiconReferenceCounter );
       
  1320             counterValue++;
       
  1321             existingPronun->SetParameterL( KLexiconReferenceCounter, counterValue );
       
  1322             }
       
  1323         User::Leave( KErrAlreadyExists );
       
  1324         }
       
  1325     else
       
  1326         {
       
  1327         User::LeaveIfError( error );
       
  1328         
       
  1329         TLinearOrder<CSIPronunciation> order( CSIPronunciation::Compare );
       
  1330         
       
  1331         // 2. Insert to the array which is kept in the order of pronunciation id
       
  1332         TRAPD( error, iPronunciationArray.InsertInOrderL( aPronunciation, order ) );
       
  1333         if ( error != KErrNone )
       
  1334             {
       
  1335             // Remove previously added element from pronunciation ordered table
       
  1336             iPronunOrder.Remove( phonemeSeqIndex );
       
  1337             User::Leave( error );
       
  1338             }
       
  1339         }
       
  1340 
       
  1341 #else
       
  1342     RUBY_DEBUG_BLOCKL("CSILexicon::AddL");
       
  1343     
       
  1344     // Check if current lexicon already hold maximal alloud number of 
       
  1345     // pronunciations or that there is no limit
       
  1346     if( ( KMaxPronunciations != 0 ) && ( iPronunciationArray.Count() > KMaxPronunciations ) )
       
  1347     	{
       
  1348     	User::Leave( KErrNoMemory );
       
  1349     	}
       
  1350     // Quick check, if pronun id of the added pronunciation is bigger than the
       
  1351     // last one which is already in array, we can add that to the last
       
  1352     if ( iPronunciationArray.Count() == 0 )
       
  1353         {
       
  1354         User::LeaveIfError( iPronunciationArray.Append( aPronunciation ) );
       
  1355         return;
       
  1356         }
       
  1357     else
       
  1358         {
       
  1359         if ( iPronunciationArray[iPronunciationArray.Count() - 1]->PronunciationID() < aPronunciation->PronunciationID() )
       
  1360             {
       
  1361             User::LeaveIfError( iPronunciationArray.Append( aPronunciation ) );
       
  1362             return;
       
  1363             }
       
  1364         }
       
  1365 
       
  1366     // Check that pronunciation is not null
       
  1367     const TDesC8& phonemeSeq = aPronunciation->PhonemeSequence();
       
  1368 
       
  1369     if ( &phonemeSeq == NULL )
       
  1370         {
       
  1371         User::Leave( KErrArgument );
       
  1372         }
       
  1373 
       
  1374     // Order function which is used when finding the correct place to insert
       
  1375     TLinearOrder<CSIPronunciation> order( CSIPronunciation::Compare );
       
  1376 
       
  1377     // InsertInOrderL does not allow duplicates, that is what we actually want!
       
  1378     iPronunciationArray.InsertInOrderL( aPronunciation, order );
       
  1379 #endif // __SIND_LEXICON_OPT
       
  1380     }
       
  1381 
       
  1382 // -----------------------------------------------------------------------------
       
  1383 // CSILexicon::AddPronunciationToEndL
       
  1384 // Adds pronunciation to end of the array
       
  1385 // -----------------------------------------------------------------------------
       
  1386 //
       
  1387 void CSILexicon::AddPronunciationToEndL( CSIPronunciation* aPronunciation )
       
  1388     {   
       
  1389     TLinearOrder<CSIPronunciation> phonemeOrder( CSIPronunciation::ComparePhonemes );    
       
  1390     TInt error = iPronunciationArray.Append( aPronunciation );
       
  1391     if ( error != KErrNone )
       
  1392         {
       
  1393         // Remove previously added element from pronunciation ordered table
       
  1394         iPronunOrder.Remove( iPronunOrder.FindInOrder( aPronunciation, phonemeOrder ) );
       
  1395         User::Leave( error );
       
  1396         }
       
  1397     }
       
  1398 
       
  1399 // -----------------------------------------------------------------------------
       
  1400 // CSILexicon::AtL
       
  1401 // Used to get a pronunciation.
       
  1402 // -----------------------------------------------------------------------------
       
  1403 //
       
  1404 EXPORT_C CSIPronunciation& CSILexicon::AtL( TInt anIndex ) const
       
  1405     {
       
  1406     RUBY_DEBUG_BLOCKL("CSILexicon::AtL");
       
  1407     if ( anIndex < 0 || anIndex >= Count() )
       
  1408         {
       
  1409         RUBY_DEBUG2("CSILexicon::AtL index [%d] is ut of bounds. Count [%d]. Leaving with KErrArg", anIndex, Count());
       
  1410         User::Leave( KErrArgument );
       
  1411         }
       
  1412 	return *( iPronunciationArray[anIndex] );
       
  1413     } 
       
  1414 
       
  1415 // -----------------------------------------------------------------------------
       
  1416 // CSILexicon::DeleteL
       
  1417 // Deletes a pronunciation with given ID
       
  1418 // -----------------------------------------------------------------------------
       
  1419 //
       
  1420 EXPORT_C void CSILexicon::DeleteL( TSIPronunciationID aPronunciationID )
       
  1421     {
       
  1422 #ifdef __SIND_LEXICON_OPT
       
  1423     RUBY_DEBUG_BLOCK( "CSILexicon::DeleteL (SINDE optimized)" );
       
  1424     
       
  1425     TInt pronunIdIndex = Find( aPronunciationID );
       
  1426     User::LeaveIfError( pronunIdIndex );
       
  1427     
       
  1428     CSIPronunciation& pronunciation = AtL( pronunIdIndex );
       
  1429     
       
  1430     TInt counter = pronunciation.ParameterL( KLexiconReferenceCounter );
       
  1431     counter--;
       
  1432     
       
  1433     // If counter reaches zero, then pronunciation should be also deleted
       
  1434     if ( counter == 0 )
       
  1435         {
       
  1436         // Find the index in array ordered by phoneme sequence
       
  1437         TLinearOrder<CSIPronunciation> phonemeOrder( CSIPronunciation::ComparePhonemes );
       
  1438         TInt phonemeSeqIndex = iPronunOrder.FindInOrder( &pronunciation, phonemeOrder );
       
  1439         User::LeaveIfError( phonemeSeqIndex );
       
  1440        
       
  1441         // Remove from array ordered by pronunciation        
       
  1442         iPronunOrder.Remove( phonemeSeqIndex );
       
  1443         
       
  1444         // Remove from array ordered by pronunciation id
       
  1445         delete iPronunciationArray[pronunIdIndex];
       
  1446         iPronunciationArray.Remove( pronunIdIndex );        
       
  1447         }
       
  1448     else
       
  1449         {
       
  1450         pronunciation.SetParameterL( KLexiconReferenceCounter, counter );
       
  1451         }
       
  1452 #else
       
  1453     RUBY_DEBUG_BLOCK("CSILexicon::DeleteL");
       
  1454     TInt index = Find( aPronunciationID );
       
  1455     User::LeaveIfError( index );
       
  1456 
       
  1457     delete iPronunciationArray[index];
       
  1458     iPronunciationArray.Remove( index );
       
  1459 #endif
       
  1460     }
       
  1461 
       
  1462 // -----------------------------------------------------------------------------
       
  1463 // CSILexicon::Find
       
  1464 // Finds the index of pronunciation with the given ID.
       
  1465 // -----------------------------------------------------------------------------
       
  1466 //
       
  1467 EXPORT_C TInt CSILexicon::Find( TSIPronunciationID aPronunciationID ) const
       
  1468     {
       
  1469     // Order function which is used when finding the correct item
       
  1470     TLinearOrder<CSIPronunciation> order( CSIPronunciation::Compare );
       
  1471 
       
  1472     TInt retVal = KErrNotFound;
       
  1473 
       
  1474     // Construct a 'dummy' CSIPronunciation so that comparison can be done 
       
  1475     // against it
       
  1476     CSIPronunciation* pronun = NULL;
       
  1477     TRAPD( error, pronun = CSIPronunciation::NewL( aPronunciationID, 0 ) );
       
  1478     if ( error )
       
  1479         {
       
  1480         return error;
       
  1481         }
       
  1482 
       
  1483     // Use binary search since array is kept in the order of pronunciation ids
       
  1484     TRAP( error, retVal = iPronunciationArray.FindInOrderL( pronun, order ) );
       
  1485     delete pronun;
       
  1486     if ( error )
       
  1487         {
       
  1488         return error;
       
  1489         }
       
  1490     return retVal;
       
  1491     } 
       
  1492 
       
  1493 // -----------------------------------------------------------------------------
       
  1494 // CSILexicon::Find
       
  1495 // Finds the index of the pronunciation with the given phoneme sequence.
       
  1496 // -----------------------------------------------------------------------------
       
  1497 //
       
  1498 EXPORT_C TInt CSILexicon::Find( const TDesC8& aPhonemeSequence ) const
       
  1499     {
       
  1500 #ifdef __SIND_LEXICON_OPT    
       
  1501     // Order function which is used when finding the correct item
       
  1502     TLinearOrder<CSIPronunciation> order( CSIPronunciation::ComparePhonemes );
       
  1503 
       
  1504     TInt retVal = KErrNotFound;
       
  1505 
       
  1506     // Construct a 'dummy' CSIPronunciation so that comparison can be done 
       
  1507     // against it
       
  1508     CSIPronunciation* pronun = NULL;
       
  1509     TRAPD( error, 
       
  1510         pronun = CSIPronunciation::NewL( 0, 0 );
       
  1511         pronun->SetPhonemeSequenceL( aPhonemeSequence );
       
  1512         // Use binary search since array is kept in the order of pronunciation ids
       
  1513         retVal = iPronunOrder.FindInOrderL( pronun, order );
       
  1514         ); // TRAPD
       
  1515     delete pronun;
       
  1516     if ( error )
       
  1517         {
       
  1518         return error;
       
  1519         }
       
  1520     
       
  1521     // retVal is index to iPronunOrder array, but what we actually need is 
       
  1522     // index to iPronunciationArray
       
  1523     pronun = iPronunOrder[ retVal ];
       
  1524             
       
  1525     return Find( pronun->PronunciationID() );
       
  1526 #else    
       
  1527     for ( TInt i=0; i < iPronunciationArray.Count(); i++ )
       
  1528 	{
       
  1529 		if ( aPhonemeSequence == iPronunciationArray[i]->PhonemeSequence() )
       
  1530 		{
       
  1531 			return i;
       
  1532 		}
       
  1533 	}
       
  1534 	return KErrNotFound;
       
  1535 #endif // __SIND_LEXICON_OPT	
       
  1536     }
       
  1537 
       
  1538 // -----------------------------------------------------------------------------
       
  1539 // CSILexicon::Count
       
  1540 // Counts the number of pronunciations.
       
  1541 // -----------------------------------------------------------------------------
       
  1542 //
       
  1543 EXPORT_C TInt CSILexicon::Count() const
       
  1544     {
       
  1545     return iPronunciationArray.Count();
       
  1546     }
       
  1547 
       
  1548 // -----------------------------------------------------------------------------
       
  1549 // CSILexicon::ExternalizeL
       
  1550 // Stores the object to the stream.
       
  1551 // -----------------------------------------------------------------------------
       
  1552 //
       
  1553 EXPORT_C void CSILexicon::ExternalizeL( RWriteStream& aWriteStream ) const
       
  1554     {
       
  1555     // Externalization involves so many data structures,
       
  1556     // That I put them to a dedicated class, CSILexiconSerializer.
       
  1557     CSILexiconSerializer* serializer = CSILexiconSerializer::NewLC( *this );
       
  1558 
       
  1559     aWriteStream.WriteInt32L( KBinaryLexiconID );
       
  1560     serializer->ExternalizeL( aWriteStream );
       
  1561     aWriteStream.WriteInt32L( KBinaryLexiconID );
       
  1562 
       
  1563     CleanupStack::PopAndDestroy( serializer );
       
  1564     }
       
  1565 
       
  1566 // -----------------------------------------------------------------------------
       
  1567 // CSILexicon::InternalizeL
       
  1568 // Restores the object from the stream.
       
  1569 // -----------------------------------------------------------------------------
       
  1570 //
       
  1571 EXPORT_C void CSILexicon::InternalizeL( RReadStream& aReadStream )
       
  1572     {
       
  1573     // Header should be KBinaryLexiconID
       
  1574     if ( aReadStream.ReadInt32L() != KBinaryLexiconID )
       
  1575         {
       
  1576         User::Leave( KErrCorrupt );
       
  1577         }
       
  1578 
       
  1579     CSILexiconSerializer* serializer
       
  1580         = CSILexiconSerializer::NewLC( aReadStream );
       
  1581 
       
  1582     serializer->RestoreL( *this, iLexiconID );
       
  1583 
       
  1584     CleanupStack::PopAndDestroy( serializer );
       
  1585 
       
  1586     // Last integer should be KBinaryLexiconID
       
  1587     if ( aReadStream.ReadInt32L() != KBinaryLexiconID )
       
  1588         {
       
  1589         User::Leave( KErrCorrupt );
       
  1590         }
       
  1591     }
       
  1592 
       
  1593 /*****************************************************************************/
       
  1594 
       
  1595 // -----------------------------------------------------------------------------
       
  1596 // CSIModel::CSIModel
       
  1597 // C++ default constructor can NOT contain any code, that
       
  1598 // might leave.
       
  1599 // -----------------------------------------------------------------------------
       
  1600 //
       
  1601 EXPORT_C CSIModel::CSIModel( const TSIModelID aModelID )
       
  1602 :	iModelID(aModelID),
       
  1603 iAcousticModel(NULL)
       
  1604 {
       
  1605 }
       
  1606 
       
  1607 // -----------------------------------------------------------------------------
       
  1608 // CSIModel::ConstructL
       
  1609 // Symbian 2nd phase constructor can leave.
       
  1610 // -----------------------------------------------------------------------------
       
  1611 //
       
  1612 EXPORT_C void CSIModel::ConstructL()
       
  1613 {
       
  1614 }
       
  1615 
       
  1616 // -----------------------------------------------------------------------------
       
  1617 // CSIModel::NewL
       
  1618 // Two-phased constructor.
       
  1619 // -----------------------------------------------------------------------------
       
  1620 //
       
  1621 EXPORT_C CSIModel* CSIModel::NewL( const TSIModelID aModelID = 0 )
       
  1622 {
       
  1623 	CSIModel* self = NewLC( aModelID );
       
  1624  	CleanupStack::Pop( self );
       
  1625     return self;
       
  1626 }
       
  1627 
       
  1628 
       
  1629 // -----------------------------------------------------------------------------
       
  1630 // CSIModel::NewLC
       
  1631 // Two-phased constructor.
       
  1632 // -----------------------------------------------------------------------------
       
  1633 //
       
  1634 EXPORT_C CSIModel* CSIModel::NewLC( const TSIModelID aModelID = 0 )
       
  1635 {
       
  1636 	CSIModel* self = new (ELeave) CSIModel( aModelID );
       
  1637     CleanupStack::PushL( self );
       
  1638     self->ConstructL(); 
       
  1639     return self;
       
  1640 }
       
  1641 
       
  1642 // -----------------------------------------------------------------------------
       
  1643 // CSIModel::~CSIModel
       
  1644 // Destructor.
       
  1645 // -----------------------------------------------------------------------------
       
  1646 //
       
  1647 EXPORT_C CSIModel::~CSIModel()
       
  1648 {
       
  1649 	delete iAcousticModel;
       
  1650 }
       
  1651 
       
  1652 // -----------------------------------------------------------------------------
       
  1653 // CSIModel::SetModelID
       
  1654 // Sets the model ID.
       
  1655 // (other items were commented in the headers)
       
  1656 // -----------------------------------------------------------------------------
       
  1657 //
       
  1658 EXPORT_C void CSIModel::SetModelID(const TSIModelID aModelID)
       
  1659 {
       
  1660 	iModelID = aModelID;
       
  1661 }
       
  1662 
       
  1663 // -----------------------------------------------------------------------------
       
  1664 // CSIModel::ModelID
       
  1665 // Returns the model ID.
       
  1666 // (other items were commented in the headers)
       
  1667 // -----------------------------------------------------------------------------
       
  1668 //
       
  1669 EXPORT_C TSIModelID CSIModel::ModelID() const
       
  1670 {
       
  1671 	return iModelID;
       
  1672 }
       
  1673 
       
  1674 // -----------------------------------------------------------------------------
       
  1675 // CSIModel::SetAcousticModel
       
  1676 // Sets the model data. CSIModel takes ownership of the data.
       
  1677 // (other items were commented in the headers)
       
  1678 // -----------------------------------------------------------------------------
       
  1679 //
       
  1680 EXPORT_C void CSIModel::SetAcousticModel( HBufC8*  aAcousticModel)
       
  1681 {	 
       
  1682 	delete iAcousticModel;
       
  1683 	iAcousticModel=aAcousticModel;
       
  1684 }
       
  1685 
       
  1686 // -----------------------------------------------------------------------------
       
  1687 // CSIModel::AcousticModel
       
  1688 // Used to get the acoustic data of the model.
       
  1689 // (other items were commented in the headers)
       
  1690 // -----------------------------------------------------------------------------
       
  1691 //
       
  1692 EXPORT_C   TDesC8& CSIModel::AcousticModel() const
       
  1693 {
       
  1694 	return *iAcousticModel;
       
  1695 }
       
  1696 
       
  1697 /*****************************************************************************/
       
  1698 
       
  1699 // -----------------------------------------------------------------------------
       
  1700 // CSIModelBank::CSIModelBank
       
  1701 // C++ default constructor can NOT contain any code, that
       
  1702 // might leave.
       
  1703 // -----------------------------------------------------------------------------
       
  1704 //
       
  1705 EXPORT_C CSIModelBank::CSIModelBank( const TSIModelBankID aModelBankID)
       
  1706 :	iModelBankID(aModelBankID)
       
  1707 {
       
  1708 }
       
  1709 
       
  1710 // -----------------------------------------------------------------------------
       
  1711 // CSIModelBank::ConstructL
       
  1712 // Symbian 2nd phase constructor can leave.
       
  1713 // -----------------------------------------------------------------------------
       
  1714 //
       
  1715 EXPORT_C void CSIModelBank::ConstructL()
       
  1716 {
       
  1717 }
       
  1718 
       
  1719 // -----------------------------------------------------------------------------
       
  1720 // CSIModelBank::NewL
       
  1721 // Two-phased constructor.
       
  1722 // -----------------------------------------------------------------------------
       
  1723 //
       
  1724 EXPORT_C CSIModelBank* CSIModelBank::NewL(const TSIModelBankID aModelBankID)
       
  1725 {
       
  1726 	CSIModelBank* self =NewLC(aModelBankID);
       
  1727  	CleanupStack::Pop( self );
       
  1728     return self;
       
  1729 }
       
  1730 
       
  1731 
       
  1732 // -----------------------------------------------------------------------------
       
  1733 // CSIModelBank::NewLC
       
  1734 // Two-phased constructor.
       
  1735 // -----------------------------------------------------------------------------
       
  1736 //
       
  1737 EXPORT_C CSIModelBank* CSIModelBank::NewLC(const TSIModelBankID aModelBankID)
       
  1738 {
       
  1739 	CSIModelBank* self = new (ELeave) CSIModelBank(aModelBankID);
       
  1740     CleanupStack::PushL( self );
       
  1741     self->ConstructL();
       
  1742     return self;
       
  1743 }
       
  1744 
       
  1745 // -----------------------------------------------------------------------------
       
  1746 // CSIModelBank::~CSIModelBank
       
  1747 // Destructor.
       
  1748 // -----------------------------------------------------------------------------
       
  1749 //
       
  1750 EXPORT_C CSIModelBank::~CSIModelBank()
       
  1751 {
       
  1752 	iModelArray.ResetAndDestroy();
       
  1753 	iModelArray.Close();
       
  1754 }
       
  1755 
       
  1756 // -----------------------------------------------------------------------------
       
  1757 // CSIModelBank::ModelBankID
       
  1758 // Returns the ID of the model bank.
       
  1759 // (other items were commented in the headers)
       
  1760 // -----------------------------------------------------------------------------
       
  1761 //
       
  1762 EXPORT_C TSIModelBankID CSIModelBank::ModelBankID() const
       
  1763 {
       
  1764 	return iModelBankID;
       
  1765 }
       
  1766 
       
  1767 // -----------------------------------------------------------------------------
       
  1768 // CSIModelBank::AddL
       
  1769 // Adds a new model to the bank.
       
  1770 // (other items were commented in the headers)
       
  1771 // -----------------------------------------------------------------------------
       
  1772 //
       
  1773 EXPORT_C void CSIModelBank::AddL( const CSIModel* aModel)
       
  1774 {
       
  1775 	if(Find(aModel->ModelID()) == KErrNotFound)
       
  1776 	{
       
  1777 		iModelArray.Append(aModel);
       
  1778 	}
       
  1779 	else
       
  1780 	{
       
  1781 		User::Leave(KErrAlreadyExists);
       
  1782 		
       
  1783 	}
       
  1784 }
       
  1785 
       
  1786 // -----------------------------------------------------------------------------
       
  1787 // CSIModelBank::AtL
       
  1788 // Used to get a model from the bank.
       
  1789 // (other items were commented in the headers)
       
  1790 // -----------------------------------------------------------------------------
       
  1791 //
       
  1792 EXPORT_C CSIModel& CSIModelBank::AtL( const TInt anIndex) const
       
  1793 {
       
  1794 	if(anIndex<0 || anIndex >= Count())
       
  1795 		User::Leave(KErrArgument);
       
  1796 	
       
  1797 	return *(iModelArray[anIndex]);
       
  1798 }
       
  1799 
       
  1800 // -----------------------------------------------------------------------------
       
  1801 // CSIModelBank::Find
       
  1802 // Finds a model with the given ID.
       
  1803 // (other items were commented in the headers)
       
  1804 // -----------------------------------------------------------------------------
       
  1805 //
       
  1806 EXPORT_C TInt CSIModelBank::Find(const TSIModelID aModelID) const
       
  1807 {
       
  1808 	for(TInt i=0; i < iModelArray.Count(); i++)
       
  1809 	{
       
  1810 		if(aModelID == iModelArray[i]->ModelID())
       
  1811 		{
       
  1812 			return i;
       
  1813 		}
       
  1814 	}
       
  1815 	return KErrNotFound;
       
  1816 }
       
  1817 
       
  1818 // -----------------------------------------------------------------------------
       
  1819 // CSIModelBank::DeleteL
       
  1820 // Deletes a model with the given ID.
       
  1821 // (other items were commented in the headers)
       
  1822 // -----------------------------------------------------------------------------
       
  1823 //
       
  1824 EXPORT_C void CSIModelBank::DeleteL(TSIModelID aModelID)
       
  1825 {
       
  1826 	TInt index = Find(aModelID );
       
  1827 	if ( index != KErrNotFound)
       
  1828 	{
       
  1829 		delete iModelArray[index];
       
  1830 		iModelArray.Remove(index);
       
  1831 	}
       
  1832 	
       
  1833 	else  {
       
  1834 		User::Leave( KErrNotFound );
       
  1835 	}
       
  1836 }
       
  1837 
       
  1838 // -----------------------------------------------------------------------------
       
  1839 // CSIModelBank::Count
       
  1840 // Returns the number of models in the bank.
       
  1841 // (other items were commented in the headers)
       
  1842 // -----------------------------------------------------------------------------
       
  1843 //
       
  1844 EXPORT_C TInt CSIModelBank::Count() const
       
  1845 {
       
  1846 	return iModelArray.Count();
       
  1847 }
       
  1848 
       
  1849 /*****************************************************************************/
       
  1850 
       
  1851 // -----------------------------------------------------------------------------
       
  1852 // CSIPronunciationInfo::CSIPronunciationInfo
       
  1853 // C++ default constructor can NOT contain any code, that
       
  1854 // might leave.
       
  1855 // -----------------------------------------------------------------------------
       
  1856 //
       
  1857 EXPORT_C CSIPronunciationInfo::CSIPronunciationInfo( RPointerArray<HBufC8> aPronunciation,
       
  1858                                                      TLanguage aLanguage )
       
  1859                                                    : iPronunciationArray( aPronunciation ),
       
  1860                                                      iLanguage( aLanguage )
       
  1861 {
       
  1862     // nothing
       
  1863 }
       
  1864 
       
  1865 // -----------------------------------------------------------------------------
       
  1866 // CSIPronunciationInfo::ConstructL
       
  1867 // Symbian 2nd phase constructor can leave.
       
  1868 // -----------------------------------------------------------------------------
       
  1869 //
       
  1870 EXPORT_C void CSIPronunciationInfo::ConstructL()
       
  1871 {
       
  1872 	
       
  1873 	CSIParameters::ConstructL();
       
  1874 } 
       
  1875 
       
  1876 // -----------------------------------------------------------------------------
       
  1877 // CSIPronunciationInfo::NewL
       
  1878 // Two-phased constructor.
       
  1879 // -----------------------------------------------------------------------------
       
  1880 //
       
  1881 EXPORT_C CSIPronunciationInfo* CSIPronunciationInfo::NewL( RPointerArray<HBufC8> aPronunciation ,TLanguage aLanguage  )
       
  1882 {
       
  1883 	CSIPronunciationInfo* self = NewLC( aPronunciation,aLanguage );
       
  1884 	CleanupStack::Pop( self );
       
  1885     return self;
       
  1886 }
       
  1887 
       
  1888 // -----------------------------------------------------------------------------
       
  1889 // CSIPronunciationInfo::NewLC
       
  1890 // Two-phased constructor.
       
  1891 // -----------------------------------------------------------------------------
       
  1892 //
       
  1893 EXPORT_C CSIPronunciationInfo* CSIPronunciationInfo::NewLC( RPointerArray<HBufC8> aPronunciation ,TLanguage aLanguage  )
       
  1894 {
       
  1895 	CSIPronunciationInfo* self = new (ELeave) CSIPronunciationInfo( aPronunciation,aLanguage );
       
  1896     CleanupStack::PushL( self );
       
  1897     self->ConstructL();
       
  1898 	return self;
       
  1899 }
       
  1900 
       
  1901 // -----------------------------------------------------------------------------
       
  1902 // CSIPronunciationInfo::~CSIPronunciationInfo
       
  1903 // Destructor.
       
  1904 // -----------------------------------------------------------------------------
       
  1905 //
       
  1906 EXPORT_C CSIPronunciationInfo::~CSIPronunciationInfo()
       
  1907 {
       
  1908 	iPronunciationArray.ResetAndDestroy();
       
  1909 	
       
  1910 } 
       
  1911 
       
  1912 
       
  1913 // -----------------------------------------------------------------------------
       
  1914 // CSIPronunciationInfo::SetPronunciationL
       
  1915 // Sets the index and phoneme sequence.
       
  1916 // (other items were commented in the headers)
       
  1917 // -----------------------------------------------------------------------------
       
  1918 //
       
  1919 EXPORT_C void CSIPronunciationInfo::SetPronunciationL(TInt aIndex, HBufC8* aPronunciation)
       
  1920 {
       
  1921 	if( aIndex < 0 || aIndex > iPronunciationArray.Count() )
       
  1922         {
       
  1923         // wrong index
       
  1924 		User::Leave( KErrArgument );
       
  1925         }
       
  1926     else if ( aIndex < iPronunciationArray.Count() )
       
  1927         {
       
  1928         // replace old pronunciation
       
  1929         delete iPronunciationArray[aIndex];
       
  1930 	    iPronunciationArray[aIndex] = aPronunciation;
       
  1931         }
       
  1932     else if ( aIndex == iPronunciationArray.Count() )
       
  1933         {
       
  1934         // append new pronunciation
       
  1935         iPronunciationArray.Append( aPronunciation );
       
  1936         }
       
  1937 }
       
  1938 
       
  1939 // -----------------------------------------------------------------------------
       
  1940 // CSIPronunciationInfo::PhonemeSequence
       
  1941 // Return phoneme sequence.
       
  1942 // (other items were commented in a header).
       
  1943 // -----------------------------------------------------------------------------
       
  1944 //
       
  1945 EXPORT_C TDesC8& CSIPronunciationInfo::PronunciationL(TInt aIndex) const
       
  1946 {
       
  1947 	if(aIndex<0 || aIndex >= Count())
       
  1948 		User::Leave(KErrArgument);
       
  1949 	
       
  1950     return *(iPronunciationArray[aIndex]);
       
  1951 }
       
  1952 
       
  1953 // -----------------------------------------------------------------------------
       
  1954 // CSIPronunciationInfo::Language
       
  1955 // Returns language.
       
  1956 // (other items were commented in the headers)
       
  1957 // -----------------------------------------------------------------------------
       
  1958 //
       
  1959 EXPORT_C TLanguage CSIPronunciationInfo::Language() const
       
  1960 {
       
  1961 	return iLanguage;
       
  1962 }
       
  1963 
       
  1964 // -----------------------------------------------------------------------------
       
  1965 // CSIPronunciationInfo::Count
       
  1966 // Returns the number of pronunciations.
       
  1967 // (other items were commented in the headers)
       
  1968 // -----------------------------------------------------------------------------
       
  1969 //
       
  1970 EXPORT_C TInt CSIPronunciationInfo::Count() const
       
  1971 {
       
  1972 	return  iPronunciationArray.Count();
       
  1973 }
       
  1974 
       
  1975 
       
  1976 
       
  1977 /******************************************************************************/
       
  1978 
       
  1979 // -----------------------------------------------------------------------------
       
  1980 // CSITtpWordList::CSITtpWordList
       
  1981 // C++ default constructor can NOT contain any code, that
       
  1982 // might leave.
       
  1983 // -----------------------------------------------------------------------------
       
  1984 //
       
  1985 EXPORT_C CSITtpWordList::CSITtpWordList() 
       
  1986 : 
       
  1987 iReserved( NULL )
       
  1988 {
       
  1989 }
       
  1990 
       
  1991 // -----------------------------------------------------------------------------
       
  1992 // CSITtpWordList::ConstructL
       
  1993 // Symbian 2nd phase constructor can leave.
       
  1994 // -----------------------------------------------------------------------------
       
  1995 //
       
  1996 EXPORT_C void CSITtpWordList::ConstructL()
       
  1997 {
       
  1998 }
       
  1999 
       
  2000 // -----------------------------------------------------------------------------
       
  2001 // CSITtpWordList::NewL
       
  2002 // Two-phased constructor.
       
  2003 // -----------------------------------------------------------------------------
       
  2004 //
       
  2005 EXPORT_C CSITtpWordList* CSITtpWordList::NewL()
       
  2006 {
       
  2007     CSITtpWordList* self = NewLC();
       
  2008     CleanupStack::Pop( self );	
       
  2009     return self;
       
  2010 }
       
  2011 
       
  2012 // -----------------------------------------------------------------------------
       
  2013 // CSITtpWordList::NewLC
       
  2014 // Two-phased constructor.
       
  2015 // -----------------------------------------------------------------------------
       
  2016 //
       
  2017 EXPORT_C CSITtpWordList* CSITtpWordList::NewLC()
       
  2018 {
       
  2019     CSITtpWordList* self = new ( ELeave ) CSITtpWordList();   
       
  2020     CleanupStack::PushL( self );
       
  2021     self->ConstructL();
       
  2022      return self;
       
  2023 }
       
  2024 
       
  2025 // Destructor
       
  2026 // -----------------------------------------------------------------------------
       
  2027 // CSITtpWordList::~CSITtpWordList
       
  2028 // Destructor.
       
  2029 // -----------------------------------------------------------------------------
       
  2030 //
       
  2031 EXPORT_C CSITtpWordList::~CSITtpWordList()
       
  2032 {
       
  2033 	iWordArray.ResetAndDestroy();
       
  2034 	iIndexArray.Close();
       
  2035 	iPronunciationArray.ResetAndDestroy();
       
  2036 }
       
  2037 
       
  2038 // -----------------------------------------------------------------------------
       
  2039 // CSITtpWordList::AddL
       
  2040 // Add word to list.
       
  2041 // (other items were commented in a header).
       
  2042 // -----------------------------------------------------------------------------
       
  2043 //
       
  2044 EXPORT_C void CSITtpWordList::AddL(
       
  2045 								   MDesCArray* aWords)
       
  2046 {
       
  2047 	TInt error = iWordArray.Append( aWords );
       
  2048 	User::LeaveIfError( error );
       
  2049 	
       
  2050 }
       
  2051 
       
  2052 // -----------------------------------------------------------------------------
       
  2053 // CSITtpWordList::Count
       
  2054 // Return number of words.
       
  2055 // (other items were commented in a header).
       
  2056 // -----------------------------------------------------------------------------
       
  2057 //
       
  2058 EXPORT_C TInt CSITtpWordList::Count() const
       
  2059 {
       
  2060 	return iWordArray.Count();
       
  2061 }
       
  2062 
       
  2063 // -----------------------------------------------------------------------------
       
  2064 // CSITtpWordList::At
       
  2065 // Give text of given index
       
  2066 // (other items were commented in a header).
       
  2067 // -----------------------------------------------------------------------------
       
  2068 //
       
  2069 EXPORT_C  MDesCArray& CSITtpWordList::AtL( 
       
  2070 										  const TInt aIndex ) const
       
  2071 {
       
  2072 	if(aIndex<0 || aIndex >= Count())
       
  2073 		User::Leave(KErrArgument);
       
  2074 	return *(iWordArray[aIndex]);
       
  2075 }
       
  2076 
       
  2077 // -----------------------------------------------------------------------------
       
  2078 // CSITtpWordList::DeleteL
       
  2079 // Deletes a word.
       
  2080 // (other items were commented in the headers)
       
  2081 // -----------------------------------------------------------------------------
       
  2082 //
       
  2083 EXPORT_C   void CSITtpWordList::DeleteL(TInt aIndex) 	{
       
  2084 	if(aIndex<0 || aIndex >= Count())
       
  2085 		User::Leave(KErrArgument);
       
  2086 	delete iWordArray[aIndex];
       
  2087 	iWordArray.Remove(aIndex);
       
  2088 	
       
  2089 	// delete pronunciation which index match to given
       
  2090 	for ( TInt i(0); i < iIndexArray.Count(); i++ )
       
  2091 	{
       
  2092 		if ( iIndexArray[i] == aIndex )
       
  2093 		{
       
  2094 			delete iPronunciationArray[i];
       
  2095 			iPronunciationArray.Remove(i);
       
  2096 		}
       
  2097 	}
       
  2098 }
       
  2099 
       
  2100 // -----------------------------------------------------------------------------
       
  2101 // CSITtpWordList::SetPronunciationL
       
  2102 // Put pronunciation to given index
       
  2103 // (other items were commented in a header).
       
  2104 // -----------------------------------------------------------------------------
       
  2105 //
       
  2106 EXPORT_C void CSITtpWordList::AppendPronunciationL( 
       
  2107 													const TInt aIndex, 
       
  2108 													CSIPronunciationInfo* aPronunciation )
       
  2109 {
       
  2110 	TInt error = iPronunciationArray.Append( aPronunciation );
       
  2111 	User::LeaveIfError( error );
       
  2112 	error = iIndexArray.Append(  aIndex );
       
  2113 	if ( error )
       
  2114 	{
       
  2115 		// remove the added pronunciation
       
  2116 		iPronunciationArray.Remove( iPronunciationArray.Count() - 1 );
       
  2117 		User::Leave( error );
       
  2118 	}
       
  2119 }
       
  2120 
       
  2121 // -----------------------------------------------------------------------------
       
  2122 // CSITtpWordList::GetPronunciationsL
       
  2123 // Give pronunciation information of given index
       
  2124 // (other items were commented in a header).
       
  2125 // -----------------------------------------------------------------------------
       
  2126 //
       
  2127 EXPORT_C void CSITtpWordList::GetPronunciationsL( 
       
  2128 												 const TInt aIndex,
       
  2129 												 RPointerArray<CSIPronunciationInfo>& aPronunciations ) const
       
  2130 {
       
  2131     CleanupClosePushL( aPronunciations ); 
       
  2132 	// clear given array
       
  2133 	aPronunciations.Reset();
       
  2134 	
       
  2135 	// add pronunciation which index match to given
       
  2136 	for ( TInt i(0); i < iIndexArray.Count(); i++ )
       
  2137 	{
       
  2138 		if ( iIndexArray[i] == aIndex )
       
  2139 		{
       
  2140 			TInt error = aPronunciations.Append( iPronunciationArray[i] );
       
  2141 			User::LeaveIfError( error );
       
  2142 		}
       
  2143 	}
       
  2144 	CleanupStack::Pop( &aPronunciations ); 
       
  2145 }
       
  2146 /*****************************************************************************/
       
  2147 
       
  2148 // -----------------------------------------------------------------------------
       
  2149 // CSIResult::CSIResult
       
  2150 // C++ default constructor can NOT contain any code, that
       
  2151 // might leave.
       
  2152 // -----------------------------------------------------------------------------
       
  2153 //
       
  2154 EXPORT_C CSIResult::CSIResult()
       
  2155 :	iGrammarID(0),
       
  2156 iRuleID(0), iRuleVariantID(0)
       
  2157 {
       
  2158 }
       
  2159 
       
  2160 // -----------------------------------------------------------------------------
       
  2161 // CSIResult::ConstructL
       
  2162 // Symbian 2nd phase constructor can leave.
       
  2163 // -----------------------------------------------------------------------------
       
  2164 //
       
  2165 EXPORT_C void CSIResult::ConstructL()
       
  2166 {
       
  2167 }
       
  2168 
       
  2169 // -----------------------------------------------------------------------------
       
  2170 // CSIResult::NewL
       
  2171 // Two-phased constructor.
       
  2172 // -----------------------------------------------------------------------------
       
  2173 //
       
  2174 EXPORT_C CSIResult* CSIResult::NewL()
       
  2175 {
       
  2176 	CSIResult* self = NewLC();
       
  2177   	CleanupStack::Pop( self );
       
  2178     return self;
       
  2179 }
       
  2180 
       
  2181 
       
  2182 
       
  2183 // -----------------------------------------------------------------------------
       
  2184 // CSIResult::NewLC
       
  2185 // Two-phased constructor.
       
  2186 // -----------------------------------------------------------------------------
       
  2187 //
       
  2188 EXPORT_C CSIResult* CSIResult::NewLC()
       
  2189 {
       
  2190 	CSIResult* self = new (ELeave) CSIResult();
       
  2191     CleanupStack::PushL( self );
       
  2192     self->ConstructL();
       
  2193      return self;
       
  2194 }
       
  2195 
       
  2196 // -----------------------------------------------------------------------------
       
  2197 // CSIResult::~CSIResult
       
  2198 // Destructor.
       
  2199 // -----------------------------------------------------------------------------
       
  2200 //
       
  2201 EXPORT_C CSIResult::~CSIResult()
       
  2202 {
       
  2203 	delete iSIPronunciation;
       
  2204 }
       
  2205 
       
  2206 // -----------------------------------------------------------------------------
       
  2207 // CSIResult::SetGrammarID
       
  2208 // Sets the grammar ID.
       
  2209 // (other items were commented in the headers)
       
  2210 // -----------------------------------------------------------------------------
       
  2211 //
       
  2212 EXPORT_C void CSIResult::SetGrammarID(const TSIGrammarID aGrammarID)
       
  2213 {
       
  2214 	iGrammarID = aGrammarID;
       
  2215 }
       
  2216 
       
  2217 // -----------------------------------------------------------------------------
       
  2218 // CSIResult::GrammarID
       
  2219 // Returns the grammar ID.
       
  2220 // (other items were commented in the headers)
       
  2221 // -----------------------------------------------------------------------------
       
  2222 //
       
  2223 EXPORT_C TSIGrammarID CSIResult::GrammarID() const
       
  2224 {
       
  2225 	return iGrammarID;
       
  2226 }
       
  2227 
       
  2228 // -----------------------------------------------------------------------------
       
  2229 // CSIResult::SetRuleID
       
  2230 // (other items were commented in the headers)
       
  2231 // -----------------------------------------------------------------------------
       
  2232 //
       
  2233 EXPORT_C void CSIResult::SetRuleID(const TSIRuleID aRuleID)
       
  2234 {
       
  2235 	iRuleID = aRuleID;
       
  2236 }
       
  2237 
       
  2238 // -----------------------------------------------------------------------------
       
  2239 // CSIResult::RuleID
       
  2240 // (other items were commented in the headers)
       
  2241 // -----------------------------------------------------------------------------
       
  2242 //
       
  2243 EXPORT_C TSIRuleID CSIResult::RuleID() const
       
  2244 {
       
  2245 	return iRuleID;
       
  2246 }
       
  2247 
       
  2248 // -----------------------------------------------------------------------------
       
  2249 // CSIResult::SetRuleVariantID
       
  2250 // (other items were commented in the headers)
       
  2251 // -----------------------------------------------------------------------------
       
  2252 //
       
  2253 EXPORT_C void CSIResult::SetRuleVariantID(const TSIRuleVariantID aRuleVariantID)
       
  2254 {
       
  2255 	iRuleVariantID = aRuleVariantID;
       
  2256 }
       
  2257 
       
  2258 // -----------------------------------------------------------------------------
       
  2259 // CSIResult::RuleVariantID
       
  2260 // (other items were commented in the headers)
       
  2261 // -----------------------------------------------------------------------------
       
  2262 //
       
  2263 EXPORT_C TSIRuleVariantID CSIResult::RuleVariantID() const
       
  2264 {
       
  2265 	return iRuleVariantID;
       
  2266 }
       
  2267 
       
  2268 // -----------------------------------------------------------------------------
       
  2269 // CSIResult::SetScore
       
  2270 // (other items were commented in the headers)
       
  2271 // -----------------------------------------------------------------------------
       
  2272 //
       
  2273 EXPORT_C void CSIResult::SetScore(const TInt32 aScore)
       
  2274 {
       
  2275 	iScore = aScore;
       
  2276 }
       
  2277 
       
  2278 // -----------------------------------------------------------------------------
       
  2279 // CSIResult::Score
       
  2280 // (other items were commented in the headers)
       
  2281 // -----------------------------------------------------------------------------
       
  2282 //
       
  2283 EXPORT_C TInt32 CSIResult::Score() const
       
  2284 {
       
  2285 	return iScore;
       
  2286 }
       
  2287 
       
  2288 // -----------------------------------------------------------------------------
       
  2289 // CSIResult::Pronunciation
       
  2290 // Returns the pronunciation of the recognized word.
       
  2291 // (other items were commented in the headers)
       
  2292 // -----------------------------------------------------------------------------
       
  2293 //
       
  2294 EXPORT_C  CSIPronunciation& CSIResult::Pronunciation() const 
       
  2295 {
       
  2296 	return *iSIPronunciation;
       
  2297 }
       
  2298 
       
  2299 // -----------------------------------------------------------------------------
       
  2300 // CSIResult::SetPronunciation
       
  2301 // Returns the recognized pronunciation.
       
  2302 // (other items were commented in the headers)
       
  2303 // -----------------------------------------------------------------------------
       
  2304 //
       
  2305 EXPORT_C void CSIResult::SetPronunciation( CSIPronunciation* aSIPronunciation) 
       
  2306 {										     
       
  2307 	iSIPronunciation=aSIPronunciation;
       
  2308 }
       
  2309 
       
  2310 
       
  2311 /*****************************************************************************/
       
  2312 
       
  2313 
       
  2314 // -----------------------------------------------------------------------------
       
  2315 // CSIResultSet::CSIResultSet
       
  2316 // C++ default constructor can NOT contain any code, that
       
  2317 // might leave.
       
  2318 // -----------------------------------------------------------------------------
       
  2319 //
       
  2320 EXPORT_C CSIResultSet::CSIResultSet()
       
  2321 :	iAdaptationData(NULL)
       
  2322 {
       
  2323 }
       
  2324 
       
  2325 // -----------------------------------------------------------------------------
       
  2326 // CSIResultSet::ConstructL
       
  2327 // Symbian 2nd phase constructor can leave.
       
  2328 // -----------------------------------------------------------------------------
       
  2329 //
       
  2330 EXPORT_C void CSIResultSet::ConstructL()
       
  2331 {
       
  2332 }
       
  2333 
       
  2334 // -----------------------------------------------------------------------------
       
  2335 // CSIResultSet::NewL
       
  2336 // Two-phased constructor.
       
  2337 // -----------------------------------------------------------------------------
       
  2338 //
       
  2339 EXPORT_C CSIResultSet* CSIResultSet::NewL()
       
  2340 {
       
  2341 	CSIResultSet* self = NewLC();
       
  2342 	CleanupStack::Pop( self );
       
  2343     return self;
       
  2344 }
       
  2345 
       
  2346 // -----------------------------------------------------------------------------
       
  2347 // CSIResultSet::NewLC
       
  2348 // Two-phased constructor.
       
  2349 // -----------------------------------------------------------------------------
       
  2350 //
       
  2351 EXPORT_C CSIResultSet* CSIResultSet::NewLC()
       
  2352 {
       
  2353 	CSIResultSet* self = new (ELeave) CSIResultSet();
       
  2354     CleanupStack::PushL( self );
       
  2355     self->ConstructL(); 
       
  2356     return self;
       
  2357 }
       
  2358 
       
  2359 // -----------------------------------------------------------------------------
       
  2360 // CSIResultSet::~CSIResultSet
       
  2361 // Destructor.
       
  2362 // -----------------------------------------------------------------------------
       
  2363 //
       
  2364 EXPORT_C CSIResultSet::~CSIResultSet()
       
  2365 {
       
  2366 	iResultArray.ResetAndDestroy();
       
  2367 	iResultArray.Close();
       
  2368 	delete iAdaptationData ;
       
  2369 }
       
  2370 
       
  2371 // -----------------------------------------------------------------------------
       
  2372 // CSIResultSet::AddL
       
  2373 // Adds a result to the set.
       
  2374 // (other items were commented in the headers)
       
  2375 // -----------------------------------------------------------------------------
       
  2376 //
       
  2377 EXPORT_C void CSIResultSet::AddL( const CSIResult* aResult)
       
  2378 {
       
  2379 	TInt error = iResultArray.Append(aResult);
       
  2380 	User::LeaveIfError( error ); 
       
  2381 }
       
  2382 
       
  2383 // -----------------------------------------------------------------------------
       
  2384 // CSIResultSet::AtL
       
  2385 // Used to get a result.
       
  2386 // (other items were commented in the headers)
       
  2387 // -----------------------------------------------------------------------------
       
  2388 //
       
  2389 EXPORT_C  CSIResult& CSIResultSet::AtL(const TInt aIndex)
       
  2390 {
       
  2391 	if(aIndex<0 || aIndex >= Count())
       
  2392 		User::Leave(KErrArgument);
       
  2393 	return *(iResultArray[aIndex]);
       
  2394 }
       
  2395 
       
  2396 EXPORT_C  const CSIResult& CSIResultSet::AtL(const TInt aIndex) const
       
  2397 {
       
  2398 	if(aIndex<0 || aIndex >= Count())
       
  2399 		User::Leave(KErrArgument);
       
  2400 	return *(iResultArray[aIndex]);
       
  2401 }
       
  2402 
       
  2403 // -----------------------------------------------------------------------------
       
  2404 // CSIResultSet::Count
       
  2405 // Counts the number of results in the set.
       
  2406 // (other items were commented in the headers)
       
  2407 // -----------------------------------------------------------------------------
       
  2408 //
       
  2409 EXPORT_C TInt CSIResultSet::Count() const
       
  2410 {
       
  2411 	return iResultArray.Count();
       
  2412 }
       
  2413 
       
  2414 // -----------------------------------------------------------------------------
       
  2415 // CSIResultSet::DeleteL
       
  2416 // Deletes a result. 
       
  2417 // (other items were commented in the headers)
       
  2418 // -----------------------------------------------------------------------------
       
  2419 //
       
  2420 EXPORT_C  void  CSIResultSet::DeleteL(TInt aIndex) 	
       
  2421 {
       
  2422 	if(aIndex<0 || aIndex >= Count())
       
  2423 		User::Leave(KErrArgument);
       
  2424 	iResultArray.Remove(aIndex);
       
  2425 }
       
  2426 
       
  2427 // -----------------------------------------------------------------------------
       
  2428 // CSIResultSet::SetAdaptationData
       
  2429 // Sets the adaptation data.
       
  2430 // (other items were commented in the headers)
       
  2431 // -----------------------------------------------------------------------------
       
  2432 //
       
  2433 EXPORT_C  void CSIResultSet::SetAdaptationData( HBufC8* aAdaptationData )
       
  2434 {
       
  2435 	delete iAdaptationData;
       
  2436 	iAdaptationData =aAdaptationData;
       
  2437 }
       
  2438 
       
  2439 // -----------------------------------------------------------------------------
       
  2440 // CSIResultSet::AdaptationData
       
  2441 // Gets the adaptation data.
       
  2442 // (other items were commented in the headers)
       
  2443 // -----------------------------------------------------------------------------
       
  2444 //
       
  2445 EXPORT_C   TDesC8& CSIResultSet::AdaptationData( )
       
  2446 {  
       
  2447 	return *iAdaptationData;
       
  2448 }
       
  2449 
       
  2450 // -----------------------------------------------------------------------------
       
  2451 // CSIResultSet::ExternalizeL
       
  2452 // Stores the object to the stream.
       
  2453 // (other items were commented in the headers)
       
  2454 // -----------------------------------------------------------------------------
       
  2455 //
       
  2456 EXPORT_C void CSIResultSet::ExternalizeL( RWriteStream& aWriteStream ) const
       
  2457     {
       
  2458     aWriteStream.WriteInt32L( KBinaryResultSetID );
       
  2459 
       
  2460     if ( iAdaptationData != NULL )
       
  2461         {
       
  2462         aWriteStream.WriteInt32L( iAdaptationData->Length() );
       
  2463         aWriteStream.WriteL( *iAdaptationData );
       
  2464         }
       
  2465     else{
       
  2466         aWriteStream.WriteInt32L( 0 );
       
  2467         }
       
  2468 
       
  2469     aWriteStream.WriteInt32L( iResultArray.Count() );
       
  2470 
       
  2471     // Write the data
       
  2472     for ( TInt k( 0 ); k < iResultArray.Count(); k++ )
       
  2473         {
       
  2474         CSIResult*        result = iResultArray[ k ];
       
  2475         const CSIPronunciation& pronun = result->Pronunciation();
       
  2476 
       
  2477         aWriteStream.WriteInt32L( result->GrammarID() );
       
  2478         aWriteStream.WriteInt32L( result->RuleID() );
       
  2479         aWriteStream.WriteInt32L( result->RuleVariantID() );
       
  2480         aWriteStream.WriteInt32L( result->Score() );
       
  2481         result->CSIParameters::ExternalizeL( aWriteStream );
       
  2482 
       
  2483         // !!!! Crashes, if pronunciation is zero.
       
  2484 
       
  2485         // Pronunciations
       
  2486         const TDesC8& seq = pronun.PhonemeSequence();
       
  2487         TInt length = seq.Length();
       
  2488 
       
  2489         aWriteStream.WriteInt32L( length );
       
  2490         aWriteStream.WriteL( seq );
       
  2491 
       
  2492         aWriteStream.WriteInt32L( pronun.PronunciationID() );
       
  2493         aWriteStream.WriteInt32L( pronun.ModelBankID() );
       
  2494         pronun.ExternalizeL( aWriteStream );
       
  2495         }
       
  2496 
       
  2497     aWriteStream.WriteInt32L( KBinaryResultSetID );
       
  2498     }
       
  2499 
       
  2500 // -----------------------------------------------------------------------------
       
  2501 // CSIResultSet::InternalizeL
       
  2502 // Restores the object from the stream.
       
  2503 // (other items were commented in the headers)
       
  2504 // -----------------------------------------------------------------------------
       
  2505 //
       
  2506 EXPORT_C void CSIResultSet::InternalizeL( RReadStream& aReadStream )
       
  2507     {
       
  2508     if ( iAdaptationData != NULL || iResultArray.Count() > 0 )
       
  2509         {
       
  2510         User::Leave( KErrInUse );
       
  2511         }
       
  2512 
       
  2513     if ( aReadStream.ReadInt32L() != KBinaryResultSetID )
       
  2514         {
       
  2515         User::Leave( KErrCorrupt );
       
  2516         }
       
  2517 
       
  2518     TInt length = aReadStream.ReadInt32L();
       
  2519 
       
  2520     if ( length )
       
  2521         {
       
  2522         iAdaptationData = HBufC8::NewL( length );
       
  2523         TPtr8 adaptationDataDes = iAdaptationData->Des();
       
  2524         aReadStream.ReadL( adaptationDataDes, length );
       
  2525         }
       
  2526     else{
       
  2527         iAdaptationData = 0;
       
  2528         }
       
  2529 
       
  2530     TInt resultCount = aReadStream.ReadInt32L();
       
  2531 
       
  2532     for ( TInt k = 0; k < resultCount; k++ )
       
  2533         {
       
  2534         CSIResult*        result = CSIResult::NewLC();
       
  2535 
       
  2536         result->SetGrammarID    ( (TSIGrammarID)    aReadStream.ReadInt32L() );
       
  2537         result->SetRuleID       ( (TSIRuleID)       aReadStream.ReadInt32L() );
       
  2538         result->SetRuleVariantID( (TSIRuleVariantID)aReadStream.ReadInt32L() );
       
  2539         result->SetScore        ( aReadStream.ReadInt32L() );
       
  2540         result->CSIParameters::InternalizeL( aReadStream );
       
  2541 
       
  2542         // Pronunciations
       
  2543 
       
  2544         TInt length = aReadStream.ReadInt32L();
       
  2545         HBufC8* seq = HBufC8::NewLC( length );
       
  2546 
       
  2547         TPtr8 seqPtr = seq->Des();
       
  2548         aReadStream.ReadL( seqPtr, length );
       
  2549 
       
  2550         TSIPronunciationID pronunciationID = aReadStream.ReadInt32L();
       
  2551         TSIModelBankID modelBankID 
       
  2552             = (TSIModelBankID)aReadStream.ReadInt32L();
       
  2553 
       
  2554         CSIPronunciation* pronun
       
  2555             = CSIPronunciation::NewLC( pronunciationID, modelBankID );
       
  2556         pronun->SetPhonemeSequenceL( *seq );
       
  2557 
       
  2558         pronun->CSIParameters::InternalizeL( aReadStream );
       
  2559 
       
  2560         result->SetPronunciation( pronun );
       
  2561 
       
  2562         AddL( result );
       
  2563 
       
  2564         CleanupStack::Pop( pronun );
       
  2565         CleanupStack::PopAndDestroy( seq );
       
  2566         CleanupStack::Pop( result );
       
  2567         }
       
  2568 
       
  2569     if ( aReadStream.ReadInt32L() != KBinaryResultSetID )
       
  2570         User::Leave( KErrCorrupt );
       
  2571     }
       
  2572 
       
  2573 //		void DeleteL(TInt aIndex);
       
  2574 
       
  2575 //  End of File