sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\euser\us_ref.cpp sl@0: // sl@0: // sl@0: sl@0: #include "us_std.h" sl@0: sl@0: sl@0: sl@0: /** sl@0: Frees the memory holding the contained object. sl@0: */ sl@0: EXPORT_C void RRefBase::Free() sl@0: { sl@0: sl@0: if (iPtr) sl@0: { sl@0: if (--iPtr[-1]==0) sl@0: User::Free(iPtr-1); sl@0: iPtr=NULL; sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Creates a copy of an object, which is to be contained by sl@0: this reference object. sl@0: sl@0: @param aPtr A pointer to memory holding a copy of the object. sl@0: @param aSize The size of the memory required to hold the object. sl@0: */ sl@0: EXPORT_C void RRefBase::DoAlloc(const TAny *aPtr,TInt aSize) sl@0: { sl@0: sl@0: __ASSERT_ALWAYS(aSize>=0,Panic(ERefAllocSizeNegative)); sl@0: Free(); sl@0: iPtr=(TInt *)User::Alloc(aSize+sizeof(TInt)); sl@0: if (iPtr!=NULL) sl@0: { sl@0: iPtr++; sl@0: iPtr[-1]=1; sl@0: Mem::Copy(iPtr,aPtr,aSize); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Creates a copy of an object, which is to be contained by sl@0: this reference object, and leaves on error. sl@0: sl@0: @param aPtr A pointer to memory holding a copy of the object. sl@0: @param aSize The size of the memory required to hold the object. sl@0: */ sl@0: EXPORT_C void RRefBase::DoAllocL(const TAny *aPtr,TInt aSize) sl@0: { sl@0: sl@0: DoAlloc(aPtr,aSize); sl@0: User::LeaveIfNull(iPtr); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Provides an implementation for the RRef class copy sl@0: constructor and assignment operator. sl@0: sl@0: @param aRef The reference object to be copied. sl@0: sl@0: @see RRef sl@0: */ sl@0: EXPORT_C void RRefBase::Copy(const RRefBase &aRef) sl@0: { sl@0: sl@0: if (this!=(&aRef)) sl@0: { sl@0: Free(); sl@0: iPtr=aRef.iPtr; sl@0: iPtr[-1]++; sl@0: } sl@0: } sl@0: