os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/dirstreamable.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <caf/dirstreamable.h>
    20 
    21 const TUint KCDirArrayGranularity=0x200;
    22 
    23 using namespace ContentAccess;
    24 
    25 
    26 EXPORT_C CDirStreamable* CDirStreamable::NewL(CDir &aDir)
    27 	{
    28 	CDirStreamable* self = new (ELeave) CDirStreamable;
    29 	CleanupStack::PushL(self);
    30 	self->ConstructL(aDir);
    31 	CleanupStack::Pop(self);
    32 	return self;
    33 	}
    34 
    35 EXPORT_C CDirStreamable* CDirStreamable::NewL()
    36 	{
    37 	CDirStreamable* self = new (ELeave) CDirStreamable;
    38 	CleanupStack::PushL(self);
    39 	self->ConstructL();
    40 	CleanupStack::Pop(self);
    41 	return self;
    42 	}
    43 
    44 
    45 EXPORT_C CDirStreamable* CDirStreamable::NewL(RReadStream aStream)
    46 	{
    47 	CDirStreamable* self = new (ELeave) CDirStreamable;
    48 	CleanupStack::PushL(self);
    49 	self->ConstructL();
    50 	self->InternalizeL(aStream);
    51 	CleanupStack::Pop(self);
    52 	return self;
    53 	}
    54 		
    55 CDirStreamable::CDirStreamable()
    56 	{
    57 	}
    58 
    59 
    60 void CDirStreamable::ConstructL()
    61 	{
    62 	iArray=new(ELeave) CArrayPakFlat<TEntry>(KCDirArrayGranularity);
    63 	}
    64 	
    65 void CDirStreamable::ConstructL(CDir& aDir)
    66 	{
    67 	iArray=new(ELeave) CArrayPakFlat<TEntry>(KCDirArrayGranularity);
    68 
    69 	// copy entries to ourselves
    70 	TInt i = 0;
    71 	for(i = 0; i < aDir.Count(); i++)
    72 		{
    73 		TEntry entry = aDir[i];
    74 		AddL(entry);
    75 		}
    76 	}
    77 
    78 CDirStreamable::~CDirStreamable()
    79 	{
    80 	}
    81         
    82 EXPORT_C void CDirStreamable::AddL(const TEntry &aEntry)
    83 	{
    84 	CDir::AddL(aEntry);
    85 	}
    86 
    87 EXPORT_C TInt CDirStreamable::Count() const
    88 	{
    89 	return CDir::Count();	
    90 	}
    91 	
    92 EXPORT_C const TEntry& CDirStreamable::operator[](TInt aIndex) const
    93 	{
    94 	return CDir::operator [](aIndex);	
    95 	}
    96 	
    97 EXPORT_C TInt CDirStreamable::Sort(TUint aEntrySortKey)
    98 	{
    99 	return CDir::Sort(aEntrySortKey);	
   100 	}
   101         
   102 EXPORT_C void CDirStreamable::ExternalizeL(RWriteStream& aStream) const
   103 	{
   104 	TInt i = 0;
   105 	TInt count = Count();
   106 	aStream.WriteInt32L(count);
   107 	for(i = 0; i < count; i++)
   108 		{
   109 		TEntry aEntry = (*this)[i]; 
   110 		TPckgC <TEntry> pckg(aEntry);
   111 		aStream.WriteL(pckg);	
   112 		}
   113 	}
   114 
   115 void CDirStreamable::InternalizeL(RReadStream& aStream)
   116 	{
   117 	TInt i = 0;
   118 	TInt count = aStream.ReadInt32L();
   119 	for(i = 0; i < count; i++)
   120 		{
   121 		TEntry aEntry;
   122 		TPckg<TEntry> pckg(aEntry);
   123 		aStream.ReadL(pckg);
   124 		
   125 		// add to CDir base class array
   126 		AddL(aEntry);
   127 		}
   128 	}