landmarks/locationlandmarks/server/src/EPos_CPosLmNameIndex.cpp
branchRCL_3
changeset 10 d6e4203b7ebe
parent 8 6fcbaa43369c
child 20 2b4ea9893b66
equal deleted inserted replaced
9:e000e7e1f1b1 10:d6e4203b7ebe
   327             if ( item )
   327             if ( item )
   328                 {
   328                 {
   329                 // the original item has been changed
   329                 // the original item has been changed
   330                 item->SetInvalid();
   330                 item->SetInvalid();
   331                 }
   331                 }
   332             // add new item for this ID
   332             
       
   333 			CleanupStack::Pop( name );//ownership of name is transferred in the call to DoInsertL
       
   334 			
       
   335 			// add new item for this ID
   333             // here comparison must be done using collation
   336             // here comparison must be done using collation
   334             CIndexItem* newItem = DoInsertL( id, name ); // takes onwership of name
   337             CIndexItem* newItem = DoInsertL( id, name ); // takes onwership of name
   335             newItem->SetValid();
   338             newItem->SetValid();
   336             
   339             
   337             TLinearOrder<CIndexItem> order( CIndexItem::CompareById );
   340             TLinearOrder<CIndexItem> order( CIndexItem::CompareById );
   338             iIdSortedArray.InsertInOrder( newItem, order );
   341             iIdSortedArray.InsertInOrder( newItem, order );
   339             CleanupStack::Pop( name );
       
   340             }
   342             }
   341         else
   343         else
   342             {
   344             {
   343             // this item already exists in the index
   345             // this item already exists in the index
   344             item->SetValid();
   346             item->SetValid();
   438 //--------------------------------------------------------------------
   440 //--------------------------------------------------------------------
   439 //
   441 //
   440 void CPosLmNameIndex::InsertL( TPosLmItemId aLmid, const TDesC& aName )
   442 void CPosLmNameIndex::InsertL( TPosLmItemId aLmid, const TDesC& aName )
   441     {
   443     {
   442     HBufC* name = aName.AllocLC();
   444     HBufC* name = aName.AllocLC();
       
   445     CleanupStack::Pop( name );//ownership of name is transferred in the call to UpdateL/InsertL
   443     InsertL( aLmid, name );
   446     InsertL( aLmid, name );
   444     CleanupStack::Pop( name );
       
   445     }
   447     }
   446 
   448 
   447 //--------------------------------------------------------------------
   449 //--------------------------------------------------------------------
   448 //--------------------------------------------------------------------
   450 //--------------------------------------------------------------------
   449 //
   451 //
   457 //--------------------------------------------------------------------
   459 //--------------------------------------------------------------------
   458 //--------------------------------------------------------------------
   460 //--------------------------------------------------------------------
   459 //
   461 //
   460 CPosLmNameIndex::CIndexItem* CPosLmNameIndex::DoInsertL( TPosLmItemId aLmid, HBufC* aName )
   462 CPosLmNameIndex::CIndexItem* CPosLmNameIndex::DoInsertL( TPosLmItemId aLmid, HBufC* aName )
   461     {
   463     {
   462     if ( Find( aLmid ) >= 0 ) // finds valid item
   464     CleanupStack::PushL( aName );//ownership of aName is transferred to this class
       
   465 	if ( Find( aLmid ) >= 0 ) // finds valid item
   463         {
   466         {
   464         User::Leave( KErrAlreadyExists ); // duplicate ID found
   467         User::Leave( KErrAlreadyExists ); // duplicate ID found
   465         }
   468         }
   466     
   469     
   467     CIndexItem* landmark = new (ELeave) CIndexItem( aLmid, aName ); // takes ownership of aName
   470     CIndexItem* landmark = new (ELeave) CIndexItem( aLmid, aName ); // takes ownership of aName
   468     CleanupStack::PushL( landmark );
   471     
       
   472 	CleanupStack::Pop( aName );
       
   473 	CleanupStack::PushL( landmark );
   469     
   474     
   470     TLmIndexNameKey key;
   475     TLmIndexNameKey key;
   471     iArray->InsertIsqAllowDuplicatesL( landmark, key );
   476     iArray->InsertIsqAllowDuplicatesL( landmark, key );
   472 
   477 
   473     CleanupStack::Pop( landmark );
   478     CleanupStack::Pop( landmark );
   485 //--------------------------------------------------------------------
   490 //--------------------------------------------------------------------
   486 //--------------------------------------------------------------------
   491 //--------------------------------------------------------------------
   487 //
   492 //
   488 void CPosLmNameIndex::AppendL( TPosLmItemId aLmid, HBufC* aName )
   493 void CPosLmNameIndex::AppendL( TPosLmItemId aLmid, HBufC* aName )
   489     {
   494     {
       
   495 	//Ownership of aName is transferred in this call
       
   496 	CleanupStack::PushL( aName );
   490     CIndexItem* landmark = new (ELeave) CIndexItem( aLmid, aName );
   497     CIndexItem* landmark = new (ELeave) CIndexItem( aLmid, aName );
   491     CleanupStack::PushL( landmark );
   498     CleanupStack::Pop( aName );
       
   499 	
       
   500 	CleanupStack::PushL( landmark );
   492     AppendL( landmark );
   501     AppendL( landmark );
   493     CleanupStack::Pop( landmark );
   502     CleanupStack::Pop( landmark );
   494     }
   503     }
   495 
   504 
   496 //--------------------------------------------------------------------
   505 //--------------------------------------------------------------------
   525     CIndexItem* entry = iArray->At( aIndex );
   534     CIndexItem* entry = iArray->At( aIndex );
   526     if ( !iInTransaction )
   535     if ( !iInTransaction )
   527         {
   536         {
   528         iDataSize -= entry->Size();
   537         iDataSize -= entry->Size();
   529         ASSERT( iDataSize >= 0 );
   538         ASSERT( iDataSize >= 0 );
   530         delete entry;
       
   531         iArray->Delete( aIndex );
   539         iArray->Delete( aIndex );
       
   540 		delete entry;
   532         }
   541         }
   533     else
   542     else
   534         {
   543         {
   535         entry->SetInvalid();
   544         entry->SetInvalid();
   536         }
   545         }
   540 //--------------------------------------------------------------------
   549 //--------------------------------------------------------------------
   541 //
   550 //
   542 void CPosLmNameIndex::UpdateL( TPosLmItemId aId, const TDesC& aName )
   551 void CPosLmNameIndex::UpdateL( TPosLmItemId aId, const TDesC& aName )
   543     {
   552     {
   544     HBufC* name = aName.AllocLC();
   553     HBufC* name = aName.AllocLC();
       
   554     CleanupStack::Pop( name );//ownership of name is transferred in the call to UpdateL
   545 //coverity[freed_arg : FALSE]
   555 //coverity[freed_arg : FALSE]
   546     UpdateL( aId, name );
   556     UpdateL( aId, name );
   547 //coverity[pass_freed_arg : FALSE]
   557 //coverity[pass_freed_arg : FALSE]
   548     CleanupStack::Pop( name );
       
   549     }
   558     }
   550 
   559 
   551 //--------------------------------------------------------------------
   560 //--------------------------------------------------------------------
   552 //--------------------------------------------------------------------
   561 //--------------------------------------------------------------------
   553 //
   562 //
   638     TInt32 count = aIn.ReadInt32L();
   647     TInt32 count = aIn.ReadInt32L();
   639     if ( count < 0 ) User::Leave( KErrCorrupt );
   648     if ( count < 0 ) User::Leave( KErrCorrupt );
   640     for ( TInt i = 0; i < count; i++ ) 
   649     for ( TInt i = 0; i < count; i++ ) 
   641         {
   650         {
   642         CIndexItem* item = CIndexItem::NewLC( aIn );
   651         CIndexItem* item = CIndexItem::NewLC( aIn );
       
   652 		CleanupStack::Pop( item ); //Ownership of item is transferred in the AppendL call
   643         AppendL( item ); // array takes ownership
   653         AppendL( item ); // array takes ownership
   644         CleanupStack::Pop( item );
       
   645         }
   654         }
   646     iStatus = KErrNone;
   655     iStatus = KErrNone;
   647     }
   656     }
   648 
   657 
   649 //--------------------------------------------------------------------
   658 //--------------------------------------------------------------------
   842     for ( TInt i = iArray->Count() - 1; i >= 0 ; i-- ) 
   851     for ( TInt i = iArray->Count() - 1; i >= 0 ; i-- ) 
   843         {
   852         {
   844         CIndexItem* item = iArray->At( i );
   853         CIndexItem* item = iArray->At( i );
   845         if ( !item->IsValid() )
   854         if ( !item->IsValid() )
   846             {
   855             {
   847             delete item;
       
   848             iArray->Delete( i );
   856             iArray->Delete( i );
       
   857 			delete item;
   849             }
   858             }
   850         }
   859         }
   851     }
   860     }
   852 
   861 
   853 //--------------------------------------------------------------------
   862 //--------------------------------------------------------------------
   876             {
   885             {
   877             item->SetValid();
   886             item->SetValid();
   878             }
   887             }
   879         else if ( !item->IsValid() )
   888         else if ( !item->IsValid() )
   880             {
   889             {
   881             delete item;
       
   882             iArray->Delete( i );
   890             iArray->Delete( i );
       
   891 			delete item;
   883             }
   892             }
   884         }
   893         }
   885     iInTransaction = EFalse;
   894     iInTransaction = EFalse;
   886     }
   895     }
   887 
   896 
   897     for ( TInt i = iArray->Count() - 1; i >= 0 ; i-- ) 
   906     for ( TInt i = iArray->Count() - 1; i >= 0 ; i-- ) 
   898         {
   907         {
   899         CIndexItem* item = iArray->At( i );
   908         CIndexItem* item = iArray->At( i );
   900         if ( item->IsTemp() )
   909         if ( item->IsTemp() )
   901             {
   910             {
   902             delete item;
       
   903             iArray->Delete( i );
   911             iArray->Delete( i );
       
   912 			delete item;
   904             }
   913             }
   905         else if ( !item->IsValid() )
   914         else if ( !item->IsValid() )
   906             {
   915             {
   907             item->SetValid();
   916             item->SetValid();
   908             }
   917             }