windowing/windowserver/nonnga/remotegc/CacheBase.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "CacheBase.h"
       
    17 
       
    18 /**
       
    19 Constructor
       
    20 Initialized the iCachedItems array with granularity 8 and an offset to iHandle in TCacheEntry,
       
    21 which will be used to find specific entries later.
       
    22 */
       
    23 CCacheBase::CCacheBase() : iCachedItems(8, _FOFF(TCacheEntry, iHandle))
       
    24 	{
       
    25 	
       
    26 	}
       
    27 	
       
    28 CCacheBase::~CCacheBase()
       
    29 	{
       
    30 	for(TInt i = 0; i < iCachedItems.Count(); i++)
       
    31 		{
       
    32 		delete iCachedItems[i].iCachedItem;
       
    33 		iCachedItems[i].iCachedItem = NULL;
       
    34 		}
       
    35 		
       
    36 	iCachedItems.Reset();	
       
    37 	}
       
    38 
       
    39 /**
       
    40 Begins an update of the cache.
       
    41 */
       
    42 void CCacheBase::BeginUpdate()
       
    43 	{
       
    44 	// Sets all cached items to not used
       
    45 	for(TInt i = 0; i < iCachedItems.Count(); i++)
       
    46 		{
       
    47 		iCachedItems[i].iIsUsed = EFalse;
       
    48 		}		
       
    49 	}
       
    50 
       
    51 /**
       
    52 End an update of the cache.
       
    53 */
       
    54 void CCacheBase::EndUpdate()
       
    55 	{
       
    56 	// Removes all cached items that are not used
       
    57 	for(TInt i = 0; i < iCachedItems.Count(); i++)
       
    58 		{
       
    59 		if(!iCachedItems[i].iIsUsed)
       
    60 			{
       
    61 			delete iCachedItems[i].iCachedItem;
       
    62 			iCachedItems.Remove(i--);
       
    63 			}			
       
    64 		}
       
    65 	}
       
    66 	
       
    67 /**
       
    68 Returns an item from the cache corresponding to a specific handle.
       
    69 
       
    70 @param aHandle A handle to match against an item in the cache.
       
    71 @return The item that matches the handle provided as a parameter.
       
    72 */
       
    73 const CBase* CCacheBase::Resolve(TInt aHandle)
       
    74 	{
       
    75 	TCacheEntry entry(aHandle);
       
    76 	TInt index = iCachedItems.FindInUnsignedKeyOrder(entry);
       
    77 	
       
    78 	if(index != KErrNotFound)
       
    79 		return iCachedItems[index].iCachedItem;		
       
    80 	else
       
    81 		return NULL;
       
    82 	}
       
    83 
       
    84