clfwrapper/ClientSrc/CCLFDbItemContainer.cpp
changeset 0 c53acadfccc6
child 40 910a23996aa0
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CCLFDbItemContainer.h"
       
    21 #include    <mdeobject.h> 
       
    22 #include    <f32file.h>
       
    23 #include    "CLFPanics.h"
       
    24 
       
    25 const TInt KCLFContainerArrayGranularity( 25 );
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CCLFContainerItem::CCLFContainerItem
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CCLFContainerItem::CCLFContainerItem( const CMdEObject* aObject )
       
    34     : iReferenceCount( 0 ), iMdEObject( aObject ), iDeprecated( EFalse ),
       
    35       iItemId( aObject->Id() )
       
    36     {
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CCLFContainerItem::CCLFContainerItem
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CCLFContainerItem::CCLFContainerItem()
       
    44     : iReferenceCount( 0 ), iMdEObject( NULL ), iDeprecated( EFalse ),
       
    45       iItemId( 0 )
       
    46 	{
       
    47 	}
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CCLFContainerItem::NewLC
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CCLFContainerItem* CCLFContainerItem::NewLC( const CMdEObject* aObject )
       
    54     {
       
    55     CCLFContainerItem* self = new ( ELeave ) CCLFContainerItem( aObject );
       
    56     CleanupStack::PushL( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CCLFContainerItem::~CCLFContainerItem
       
    62 // Destructor
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CCLFContainerItem::~CCLFContainerItem()
       
    66     {
       
    67     delete iMdEObject;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CCLFContainerItem::Compare
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 TInt CCLFContainerItem::Compare( const CCLFContainerItem& aFirst,
       
    75 					             const CCLFContainerItem& aSecond )
       
    76 	{
       
    77 	return aFirst.iItemId - aSecond.iItemId;
       
    78 	}
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CCLFDbItemContainer::TFindHelper::TFindHelper
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CCLFDbItemContainer::TFindHelper::TFindHelper()
       
    85     : iItemId( 0 ), 
       
    86       iIndex( 0 )
       
    87     {
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CCLFDbItemContainer::TFindHelper::Reset
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CCLFDbItemContainer::TFindHelper::Reset()
       
    95     {
       
    96     iItemId = 0;
       
    97     iIndex = 0;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CCLFDbItemContainer::TFindHelper::Set
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CCLFDbItemContainer::TFindHelper::Set( TCLFItemId aItemId, 
       
   105                                                    TInt aIndex )
       
   106     {
       
   107     iItemId = aItemId;
       
   108     iIndex = aIndex;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CCLFDbItemContainer::CCLFDbItemContainer
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 CCLFDbItemContainer::CCLFDbItemContainer()
       
   116     : iItemArray( KCLFContainerArrayGranularity ),
       
   117       iArraySorter( CCLFContainerItem::Compare )
       
   118     {
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CCLFDbItemContainer::NewL
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 CCLFDbItemContainer* CCLFDbItemContainer::NewL()
       
   126     {
       
   127     return new( ELeave ) CCLFDbItemContainer;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CCLFDbItemContainer::~CCLFDbItemContainer
       
   132 // Destructor
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 CCLFDbItemContainer::~CCLFDbItemContainer()
       
   136     {
       
   137     iItemArray.ResetAndDestroy();
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CCLFDbItemContainer::ItemById
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 CCLFContainerItem* CCLFDbItemContainer::ItemById( const TCLFItemId aItemId ) const
       
   145     {
       
   146     CCLFContainerItem* item = NULL;
       
   147     TInt index( FindItem( aItemId, item ) );
       
   148     while ( index >= 0 )
       
   149         {
       
   150 		if( !( item->iDeprecated ) )
       
   151 			{
       
   152 			return item;
       
   153 			}
       
   154         index = NextItem( item );
       
   155         }
       
   156     return NULL;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CCLFDbItemContainer::ReleaseItem
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CCLFDbItemContainer::ReleaseItem( CCLFContainerItem* aItem )
       
   164     {
       
   165     const TInt index( iItemArray.Find( aItem ) );
       
   166     if ( index >= 0 )
       
   167         {
       
   168         aItem->iReferenceCount--;
       
   169         __ASSERT_DEBUG ( aItem->iReferenceCount >= 0,
       
   170                          User::Panic( KCLFPanicText, ECLFNullPointer ) );
       
   171         if ( aItem->iReferenceCount <= 0 )
       
   172             {
       
   173             iItemArray.Remove( index );
       
   174             delete aItem;
       
   175             aItem = NULL;
       
   176             }
       
   177         }
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CCLFDbItemContainer::SetDeprecatedItems
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CCLFDbItemContainer::SetDeprecatedItems(
       
   185                                     const RArray<TCLFItemId>& aItemIdArray )
       
   186     {
       
   187     const TInt count( aItemIdArray.Count() );
       
   188     for ( TInt i = 0 ; i < count ; ++i )
       
   189         {
       
   190         CCLFContainerItem* item = NULL;
       
   191         TInt index( FindItem( aItemIdArray[i], item ) );
       
   192         while ( index >= 0 )
       
   193             {
       
   194             item->iDeprecated = ETrue;
       
   195             index = NextItem( item );
       
   196             }
       
   197         }
       
   198     }
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CCLFDbItemContainer::FindItem
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 TInt CCLFDbItemContainer::FindItem( TCLFItemId aItemId, 
       
   205                                     CCLFContainerItem*& aItem ) const
       
   206     {
       
   207     iFindHelper.Reset();
       
   208 	iFindItem.SetItemId( aItemId );
       
   209     const TInt index ( iItemArray.SpecificFindInOrder( 
       
   210                                         &iFindItem, 
       
   211                                         iArraySorter, 
       
   212                                         EArrayFindMode_First ) );
       
   213 	if ( index >= 0 )
       
   214 		{
       
   215     	iFindHelper.Set( aItemId, index );
       
   216 		aItem = iItemArray[index];
       
   217 		return index;
       
   218 		}
       
   219     return KErrNotFound;
       
   220     
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CCLFDbItemContainer::NextItem
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 TInt CCLFDbItemContainer::NextItem( CCLFContainerItem*& aItem ) const
       
   228     {
       
   229     const TInt count( iItemArray.Count() );
       
   230     if ( iFindHelper.iIndex < count )
       
   231         {
       
   232         CCLFContainerItem* item = iItemArray[ iFindHelper.iIndex ];
       
   233         if ( iFindHelper.iItemId == item->iItemId )
       
   234             {
       
   235             iFindHelper.iIndex++;
       
   236             aItem = item;
       
   237             return iFindHelper.iIndex - 1;
       
   238             }
       
   239         }
       
   240     return KErrNotFound;
       
   241     }
       
   242 
       
   243 //  End of File