os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/dirstreamable.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/dirstreamable.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,128 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <caf/dirstreamable.h>
    1.23 +
    1.24 +const TUint KCDirArrayGranularity=0x200;
    1.25 +
    1.26 +using namespace ContentAccess;
    1.27 +
    1.28 +
    1.29 +EXPORT_C CDirStreamable* CDirStreamable::NewL(CDir &aDir)
    1.30 +	{
    1.31 +	CDirStreamable* self = new (ELeave) CDirStreamable;
    1.32 +	CleanupStack::PushL(self);
    1.33 +	self->ConstructL(aDir);
    1.34 +	CleanupStack::Pop(self);
    1.35 +	return self;
    1.36 +	}
    1.37 +
    1.38 +EXPORT_C CDirStreamable* CDirStreamable::NewL()
    1.39 +	{
    1.40 +	CDirStreamable* self = new (ELeave) CDirStreamable;
    1.41 +	CleanupStack::PushL(self);
    1.42 +	self->ConstructL();
    1.43 +	CleanupStack::Pop(self);
    1.44 +	return self;
    1.45 +	}
    1.46 +
    1.47 +
    1.48 +EXPORT_C CDirStreamable* CDirStreamable::NewL(RReadStream aStream)
    1.49 +	{
    1.50 +	CDirStreamable* self = new (ELeave) CDirStreamable;
    1.51 +	CleanupStack::PushL(self);
    1.52 +	self->ConstructL();
    1.53 +	self->InternalizeL(aStream);
    1.54 +	CleanupStack::Pop(self);
    1.55 +	return self;
    1.56 +	}
    1.57 +		
    1.58 +CDirStreamable::CDirStreamable()
    1.59 +	{
    1.60 +	}
    1.61 +
    1.62 +
    1.63 +void CDirStreamable::ConstructL()
    1.64 +	{
    1.65 +	iArray=new(ELeave) CArrayPakFlat<TEntry>(KCDirArrayGranularity);
    1.66 +	}
    1.67 +	
    1.68 +void CDirStreamable::ConstructL(CDir& aDir)
    1.69 +	{
    1.70 +	iArray=new(ELeave) CArrayPakFlat<TEntry>(KCDirArrayGranularity);
    1.71 +
    1.72 +	// copy entries to ourselves
    1.73 +	TInt i = 0;
    1.74 +	for(i = 0; i < aDir.Count(); i++)
    1.75 +		{
    1.76 +		TEntry entry = aDir[i];
    1.77 +		AddL(entry);
    1.78 +		}
    1.79 +	}
    1.80 +
    1.81 +CDirStreamable::~CDirStreamable()
    1.82 +	{
    1.83 +	}
    1.84 +        
    1.85 +EXPORT_C void CDirStreamable::AddL(const TEntry &aEntry)
    1.86 +	{
    1.87 +	CDir::AddL(aEntry);
    1.88 +	}
    1.89 +
    1.90 +EXPORT_C TInt CDirStreamable::Count() const
    1.91 +	{
    1.92 +	return CDir::Count();	
    1.93 +	}
    1.94 +	
    1.95 +EXPORT_C const TEntry& CDirStreamable::operator[](TInt aIndex) const
    1.96 +	{
    1.97 +	return CDir::operator [](aIndex);	
    1.98 +	}
    1.99 +	
   1.100 +EXPORT_C TInt CDirStreamable::Sort(TUint aEntrySortKey)
   1.101 +	{
   1.102 +	return CDir::Sort(aEntrySortKey);	
   1.103 +	}
   1.104 +        
   1.105 +EXPORT_C void CDirStreamable::ExternalizeL(RWriteStream& aStream) const
   1.106 +	{
   1.107 +	TInt i = 0;
   1.108 +	TInt count = Count();
   1.109 +	aStream.WriteInt32L(count);
   1.110 +	for(i = 0; i < count; i++)
   1.111 +		{
   1.112 +		TEntry aEntry = (*this)[i]; 
   1.113 +		TPckgC <TEntry> pckg(aEntry);
   1.114 +		aStream.WriteL(pckg);	
   1.115 +		}
   1.116 +	}
   1.117 +
   1.118 +void CDirStreamable::InternalizeL(RReadStream& aStream)
   1.119 +	{
   1.120 +	TInt i = 0;
   1.121 +	TInt count = aStream.ReadInt32L();
   1.122 +	for(i = 0; i < count; i++)
   1.123 +		{
   1.124 +		TEntry aEntry;
   1.125 +		TPckg<TEntry> pckg(aEntry);
   1.126 +		aStream.ReadL(pckg);
   1.127 +		
   1.128 +		// add to CDir base class array
   1.129 +		AddL(aEntry);
   1.130 +		}
   1.131 +	}