sl@0: /* sl@0: * Copyright (c) 2004-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 the License "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: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: EXPORT_C RAttributeSet::RAttributeSet() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void RAttributeSet::Close() sl@0: { sl@0: // Clean up array sl@0: iAttributes.Reset(); sl@0: iAttributes.Close(); sl@0: } sl@0: sl@0: EXPORT_C void RAttributeSet::AddL(TInt aAttribute) sl@0: { sl@0: // Can't have duplicates so if the attribute already exists just reset its sl@0: // value back to KErrCANotSupported sl@0: if(SetValue(aAttribute, 0, KErrCANotSupported) != KErrNone) sl@0: { sl@0: // Doesn't exist so add it sl@0: AddL(aAttribute, 0, KErrCANotSupported); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TInt RAttributeSet::GetValue(TInt aAttribute, TInt& aValue) const sl@0: { sl@0: TInt i; sl@0: TInt count = iAttributes.Count(); sl@0: for(i = 0; i < count; i++) sl@0: { sl@0: if(iAttributes[i].iAttribute == aAttribute) sl@0: { sl@0: // Set the value and return the associated error code sl@0: aValue = iAttributes[i].iValue; sl@0: return iAttributes[i].iError; sl@0: } sl@0: } sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: EXPORT_C TInt RAttributeSet::SetValue(TInt aAttribute, TInt aValue, TInt aErrorCode) sl@0: { sl@0: TInt i; sl@0: TInt count = iAttributes.Count(); sl@0: for(i = 0; i < count; i++) sl@0: { sl@0: if(iAttributes[i].iAttribute == aAttribute) sl@0: { sl@0: iAttributes[i].iValue = aValue; sl@0: iAttributes[i].iError = aErrorCode; sl@0: return KErrNone; sl@0: } sl@0: } sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: EXPORT_C TInt RAttributeSet::operator [] (TInt aIndex) const sl@0: { sl@0: return iAttributes[aIndex].iAttribute; sl@0: } sl@0: sl@0: EXPORT_C TInt RAttributeSet::Count() const sl@0: { sl@0: return iAttributes.Count(); sl@0: } sl@0: sl@0: EXPORT_C void RAttributeSet::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: TInt i; sl@0: TInt count = iAttributes.Count(); sl@0: aStream.WriteInt32L(count); sl@0: for(i = 0; i < count; i++) sl@0: { sl@0: aStream.WriteInt32L(iAttributes[i].iAttribute); sl@0: aStream.WriteInt32L(iAttributes[i].iValue); sl@0: aStream.WriteInt32L(iAttributes[i].iError); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void RAttributeSet::InternalizeL(RReadStream& aStream) sl@0: { sl@0: TInt i; sl@0: TInt attribute; sl@0: TInt value; sl@0: TInt errorCode; sl@0: sl@0: // Read the number of attributes to internalize sl@0: TInt count = aStream.ReadInt32L(); sl@0: sl@0: // loop through all the attributes sl@0: for(i = 0; i < count; i++) sl@0: { sl@0: // Read the attribute and value from the stream sl@0: attribute = aStream.ReadInt32L(); sl@0: value = aStream.ReadInt32L(); sl@0: errorCode = aStream.ReadInt32L(); sl@0: sl@0: // try setting the attribute value first in case it already exists sl@0: if(SetValue(attribute, value, errorCode) != KErrNone) sl@0: { sl@0: // Doesn't exist so set a new values sl@0: AddL(attribute, value, errorCode); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void RAttributeSet::AddL(TInt aAttribute, TInt aValue, TInt aErrorCode) sl@0: { sl@0: TAttributeValue attribute; sl@0: attribute.iAttribute = aAttribute; sl@0: attribute.iValue = aValue; sl@0: attribute.iError = aErrorCode; sl@0: sl@0: // Append the new values to the iAttributes array sl@0: User::LeaveIfError(iAttributes.Append(attribute)); sl@0: }