sl@0: // Copyright (c) 2003-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 "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: // sl@0: sl@0: #include "ShiftedFileStore.h" sl@0: sl@0: /** sl@0: @internalComponent sl@0: CShiftedFileStore::OpenLC(RFs& aFs, const TDesC& aName, TUint aFileMode, TUint aFileOffset) method. sl@0: CFileStore::OpenL(RFs& aFs,const TDesC& aName,TUint aFileMode,const TFileStoreFactoryFunction aFactory[]) sl@0: method was used as an origin for the method's source code. sl@0: */ sl@0: CShiftedFileStore* CShiftedFileStore::OpenLC(RFs& aFs, const TDesC& aName, TUint aFileMode, TUint aFileOffset) sl@0: { sl@0: RFile file; sl@0: User::LeaveIfError(file.Open(aFs, aName, aFileMode)); sl@0: CShiftedFileStore* store = FromL(file, aFileOffset); sl@0: CleanupStack::PushL(store); sl@0: return store; sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: CShiftedFileStore::FromL(RFile& aFile, TUint aFileOffset) method. sl@0: CFileStore::FromL(RFile& aFile,TFileStoreFactoryFunction aFunction) method was used as an origin sl@0: for the method's source code. The only difference is that RFileBuf::Attach is called with possibly sl@0: non-zero offset. The original implementation always calls RFileBuf::Attach with zero offset. sl@0: */ sl@0: CShiftedFileStore* CShiftedFileStore::FromL(RFile& aFile, TUint aFileOffset) sl@0: { sl@0: if (static_cast(aFileOffset) < 0) sl@0: User::Leave(KErrArgument); sl@0: RFileBuf buf; sl@0: buf.Attach(aFile, static_cast (aFileOffset)); sl@0: buf.PushL(); sl@0: RReadStream stream(&buf); sl@0: TCheckedUid chk; sl@0: stream >> chk; sl@0: CFileStore* store = (*KDirectFileStoreFactoryFunction)(buf, chk.UidType()); sl@0: if(store == NULL) sl@0: User::Leave(KErrNotSupported); sl@0: //CleanupStack::Pop(2) is called, because: sl@0: //1) buf.PushL() - actually MStreamBuf::PushL() is called and it pushes buf sl@0: // into CleanupStack. sl@0: //1) CFileStore* store = (*KDirectFileStoreFactoryFunction)(buf, chk.UidType()) - sl@0: // FileStoreFactory::DirectLC() is called. sl@0: CleanupStack::Pop(2); sl@0: return static_cast (store); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: Constructor. Prevents compiler warnings. sl@0: Actually, CShiftedFileStore instance is newer created. CFileStore or CDirectFileStore sl@0: instance is created and downcasted to CShiftedFileStore. It is possible to do that: sl@0: CShiftedFileStore doesn't have data members at all. sl@0: */ sl@0: CShiftedFileStore::CShiftedFileStore(RFile& aFile) : sl@0: CDirectFileStore(aFile) sl@0: { sl@0: } sl@0: