messagingfw/msgtestfw/Framework/src/CMtfTestParameterStore.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2003-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 /**
       
    17  @file
       
    18 */
       
    19  
       
    20 #include "CMtfTestParameterStore.h"
       
    21 #include "CMtfTestAction.h" 
       
    22 #include "CMtfTestParameter.h"
       
    23 
       
    24 CMtfTestParameterStore* CMtfTestParameterStore::NewL()
       
    25 {
       
    26 	CMtfTestParameterStore* self = new (ELeave) CMtfTestParameterStore;
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL();
       
    29 	CleanupStack::Pop(self);
       
    30 	return self;
       
    31 }
       
    32 
       
    33 CMtfTestParameterStore::CMtfTestParameterStore()
       
    34 {
       
    35 }
       
    36 
       
    37 void CMtfTestParameterStore::ConstructL()
       
    38 {
       
    39 }
       
    40 
       
    41 CMtfTestParameterStore::~CMtfTestParameterStore()
       
    42 {	
       
    43 	iParameters.ResetAndDestroy();
       
    44 }
       
    45 
       
    46 /** Stores a parameter at the beginning of the array. The parameter is stored at the
       
    47 beginning of the array so that when the object is deleted, the last stored parameter is
       
    48 deleted first. The function takes ownership of aParameter at the END. */
       
    49 void CMtfTestParameterStore::StoreParameterL(CMtfTestParameter* aParameter)
       
    50 {
       
    51 	User::LeaveIfError(iParameters.Insert(aParameter,0));
       
    52 }
       
    53 
       
    54 TInt CMtfTestParameterStore::ObtainParameterIndexL(const TDesC& aParameterName) const
       
    55 {
       
    56 	TInt parameterCount = iParameters.Count();
       
    57 	TInt count;
       
    58 	TBool parameterFound = EFalse;
       
    59 	
       
    60 	for(count=0; count<parameterCount; count++)
       
    61 	{
       
    62 		if (iParameters[count]->Name() == aParameterName)
       
    63 		{ 
       
    64 			parameterFound = ETrue;
       
    65 			break;
       
    66 		}
       
    67 	}
       
    68 	
       
    69 	if (!parameterFound)
       
    70 	{
       
    71 		User::Leave(KErrNotFound);
       
    72 	}
       
    73 	
       
    74 	return count;
       
    75 }
       
    76 
       
    77 const CMtfTestParameter& CMtfTestParameterStore::ObtainParameterL(const TDesC& aParameterName) const
       
    78 {
       
    79 	return *iParameters[ObtainParameterIndexL(aParameterName)];
       
    80 }
       
    81 
       
    82 void CMtfTestParameterStore::DeleteParameterL(const TDesC& aParameterName)
       
    83 {
       
    84 	TInt index = ObtainParameterIndexL(aParameterName);
       
    85 	delete iParameters[index];
       
    86 	iParameters.Remove(index);
       
    87 }