applayerpluginsandutils/httpprotocolplugins/WspProtocolHandler/CWspHeaderCodePages.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "CWspHeaderCodePages.h"
       
    17 
       
    18 #include "CHeaderCodePage.h"
       
    19 
       
    20 CWspHeaderCodePages* CWspHeaderCodePages::NewL()
       
    21 	{
       
    22 	return new (ELeave) CWspHeaderCodePages();
       
    23 	}
       
    24 
       
    25 CWspHeaderCodePages::~CWspHeaderCodePages()
       
    26 	{
       
    27 	iCodePages.ResetAndDestroy();
       
    28 	}
       
    29 
       
    30 CWspHeaderCodePages::CWspHeaderCodePages()
       
    31 : CBase(), iIndex(KErrNotFound)
       
    32 	{
       
    33 	}
       
    34 
       
    35 TInt CWspHeaderCodePages::Start() const
       
    36 	{
       
    37 	// Have any code pages been added?
       
    38 	if( iCodePages.Count() != 0 )
       
    39 		{
       
    40 		// There are code pages in array - set index to start
       
    41 		iIndex = 0;
       
    42 		}
       
    43 	// iIndex now is the error (return) value
       
    44 	return iIndex;
       
    45 	}
       
    46 
       
    47 TInt CWspHeaderCodePages::GetNext(TUint8& aPageCode, TPtrC8& aPageName) const
       
    48 	{
       
    49 	// Check to see if array can be accessed
       
    50 	TInt error = KErrNone;
       
    51 	if( iIndex == KErrNotFound )
       
    52 		{
       
    53 		// Array is empty or have indexed to end of array
       
    54 		error = KErrNotFound;
       
    55 		}
       
    56 	else
       
    57 		{
       
    58 		// Have still got a code page to access - get values
       
    59 		const CHeaderCodePage& codePage = *iCodePages[iIndex];
       
    60 		aPageCode = codePage.GetPageCode();
       
    61 		aPageName.Set(codePage.GetPageName());
       
    62 
       
    63 		// Increment index and check to see reached the end of the array
       
    64 		++iIndex;
       
    65 		if( iIndex == iCodePages.Count() )
       
    66 			{
       
    67 			iIndex = KErrNotFound;
       
    68 			}
       
    69 		}
       
    70 	return error;
       
    71 	}
       
    72 
       
    73 void CWspHeaderCodePages::Reset()
       
    74 	{
       
    75 	// Reset the array and index
       
    76 	iCodePages.ResetAndDestroy();
       
    77 	iIndex = KErrNotFound;
       
    78 	}
       
    79 
       
    80 void CWspHeaderCodePages::AddHeaderCodePageL(TUint8 aPageCode, const TDesC8& aPageName)
       
    81 	{
       
    82 	// Create code page object
       
    83 	CHeaderCodePage* codePage = CHeaderCodePage::NewL(aPageCode, aPageName);
       
    84 	CleanupStack::PushL(codePage);
       
    85 
       
    86 	// Append to array
       
    87 	User::LeaveIfError(iCodePages.Append(codePage));
       
    88 	CleanupStack::Pop(codePage);
       
    89 	}
       
    90