Update contrib.
2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "UniqueInstanceImpl.h"
20 #include "AssertFileAndLine.h"
22 using namespace UniqueInstance;
25 #define USE_INTEGRITY_CHECK 1
27 #define USE_INTEGRITY_CHECK 0
30 // CUniqueInstanceRepositoryBase : user version in front of compiler firewall
31 void CUniqueInstanceRepositoryBase::ConstructL(TCompareFn* aCompare,
32 TDeleteFn* aDelete, TCopyFnL* aCopyL,
33 TInt aMaxLinks, TInt aObjectSize)
35 CRepositoryImpl* p = new(ELeave) CRepositoryImpl(aCompare,
36 aDelete, aCopyL, aObjectSize);
37 CleanupStack::PushL(p);
38 p->ConstructL(aMaxLinks);
44 CUniqueInstanceRepositoryBase::~CUniqueInstanceRepositoryBase()
49 void CUniqueInstanceRepositoryBase::Test() const
54 // RInstanceImpl : manager for a unique instance
55 RInstanceImpl::RInstanceImpl(CUniqueInstanceRepositoryBase& aRepository)
56 : iRepository(aRepository.iImpl)
58 iPtr = iRepository->NullElement();
61 RInstanceImpl::~RInstanceImpl()
63 ASSERT(iRepository->IsNull(iPtr));
66 void RInstanceImpl::TakeL(void* a)
69 #if USE_INTEGRITY_CHECK
72 UniqueInstance::SElement* r = iRepository->InsertOrIncL(a);
73 iRepository->DeleteOrDec(iPtr);
75 #if USE_INTEGRITY_CHECK
80 void RInstanceImpl::TakeCopyL(void* a)
83 #if USE_INTEGRITY_CHECK
86 UniqueInstance::SElement* r = iRepository->IncOrCopyL(a);
87 iRepository->DeleteOrDec(iPtr);
89 #if USE_INTEGRITY_CHECK
94 void* RInstanceImpl::Peek() const
96 #if USE_INTEGRITY_CHECK
102 void* RInstanceImpl::DropL()
104 #if USE_INTEGRITY_CHECK
107 void* object = iRepository->DetatchOrCopyL(iPtr);
108 iPtr = iRepository->NullElement();
109 #if USE_INTEGRITY_CHECK
115 void RInstanceImpl::Close()
117 #if USE_INTEGRITY_CHECK
120 iRepository->DeleteOrDec(iPtr);
121 iPtr = iRepository->NullElement();
122 #if USE_INTEGRITY_CHECK
127 void RInstanceImpl::CopyTo(RInstanceImpl& aOther) const
129 #if USE_INTEGRITY_CHECK
131 CRepositoryImpl* otherRep = aOther.iRepository;
137 aOther.iRepository = iRepository;
139 #if USE_INTEGRITY_CHECK
145 void RInstanceImpl::MoveTo(RInstanceImpl& aOther)
147 #if USE_INTEGRITY_CHECK
149 CRepositoryImpl* otherRep = aOther.iRepository;
155 aOther.iRepository = iRepository;
157 iPtr = iRepository->NullElement();
159 #if USE_INTEGRITY_CHECK
165 // standard copy and delete functions
166 void* CUniqueInstanceRepositoryBase::DumbCopyL(void* aBuf, TInt aSize)
168 void* newBuf = User::AllocL(aSize);
169 Mem::Copy(newBuf, aBuf, aSize);
173 void CUniqueInstanceRepositoryBase::DumbDelete(void* aBuf)
178 // CUniqueInstanceRepository<TDes>
179 void* CUniqueInstanceRepository<TDes>::DesCopyL(void* a, TInt)
181 TDesC* des = reinterpret_cast<TDesC*>(a);
182 return des->AllocL();
185 TInt CUniqueInstanceRepository<TDes>::DesCompare(void* aL, void* aR)
187 TDesC* lh = reinterpret_cast<TDesC*>(aL);
188 TDesC* rh = reinterpret_cast<TDesC*>(aR);
189 return lh->Compare(*rh);
192 void CUniqueInstanceRepository<TDes>::DesDelete(void* a)