Update contrib.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include <caf/attributeset.h>
21 #include <caf/caferr.h>
23 using namespace ContentAccess;
25 EXPORT_C RAttributeSet::RAttributeSet()
29 EXPORT_C void RAttributeSet::Close()
36 EXPORT_C void RAttributeSet::AddL(TInt aAttribute)
38 // Can't have duplicates so if the attribute already exists just reset its
39 // value back to KErrCANotSupported
40 if(SetValue(aAttribute, 0, KErrCANotSupported) != KErrNone)
42 // Doesn't exist so add it
43 AddL(aAttribute, 0, KErrCANotSupported);
47 EXPORT_C TInt RAttributeSet::GetValue(TInt aAttribute, TInt& aValue) const
50 TInt count = iAttributes.Count();
51 for(i = 0; i < count; i++)
53 if(iAttributes[i].iAttribute == aAttribute)
55 // Set the value and return the associated error code
56 aValue = iAttributes[i].iValue;
57 return iAttributes[i].iError;
63 EXPORT_C TInt RAttributeSet::SetValue(TInt aAttribute, TInt aValue, TInt aErrorCode)
66 TInt count = iAttributes.Count();
67 for(i = 0; i < count; i++)
69 if(iAttributes[i].iAttribute == aAttribute)
71 iAttributes[i].iValue = aValue;
72 iAttributes[i].iError = aErrorCode;
79 EXPORT_C TInt RAttributeSet::operator [] (TInt aIndex) const
81 return iAttributes[aIndex].iAttribute;
84 EXPORT_C TInt RAttributeSet::Count() const
86 return iAttributes.Count();
89 EXPORT_C void RAttributeSet::ExternalizeL(RWriteStream& aStream) const
92 TInt count = iAttributes.Count();
93 aStream.WriteInt32L(count);
94 for(i = 0; i < count; i++)
96 aStream.WriteInt32L(iAttributes[i].iAttribute);
97 aStream.WriteInt32L(iAttributes[i].iValue);
98 aStream.WriteInt32L(iAttributes[i].iError);
102 EXPORT_C void RAttributeSet::InternalizeL(RReadStream& aStream)
109 // Read the number of attributes to internalize
110 TInt count = aStream.ReadInt32L();
112 // loop through all the attributes
113 for(i = 0; i < count; i++)
115 // Read the attribute and value from the stream
116 attribute = aStream.ReadInt32L();
117 value = aStream.ReadInt32L();
118 errorCode = aStream.ReadInt32L();
120 // try setting the attribute value first in case it already exists
121 if(SetValue(attribute, value, errorCode) != KErrNone)
123 // Doesn't exist so set a new values
124 AddL(attribute, value, errorCode);
129 void RAttributeSet::AddL(TInt aAttribute, TInt aValue, TInt aErrorCode)
131 TAttributeValue attribute;
132 attribute.iAttribute = aAttribute;
133 attribute.iValue = aValue;
134 attribute.iError = aErrorCode;
136 // Append the new values to the iAttributes array
137 User::LeaveIfError(iAttributes.Append(attribute));