|
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 <s32strm.h> |
|
20 #include "attributeset.h" |
|
21 #include "caferr.h" |
|
22 |
|
23 using namespace ContentAccess; |
|
24 |
|
25 EXPORT_C RAttributeSet::RAttributeSet() |
|
26 { |
|
27 } |
|
28 |
|
29 EXPORT_C void RAttributeSet::Close() |
|
30 { |
|
31 // Clean up array |
|
32 iAttributes.Reset(); |
|
33 iAttributes.Close(); |
|
34 } |
|
35 |
|
36 EXPORT_C void RAttributeSet::AddL(TInt aAttribute) |
|
37 { |
|
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) |
|
41 { |
|
42 // Doesn't exist so add it |
|
43 AddL(aAttribute, 0, KErrCANotSupported); |
|
44 } |
|
45 } |
|
46 |
|
47 EXPORT_C TInt RAttributeSet::GetValue(TInt aAttribute, TInt& aValue) const |
|
48 { |
|
49 TInt i; |
|
50 TInt count = iAttributes.Count(); |
|
51 for(i = 0; i < count; i++) |
|
52 { |
|
53 if(iAttributes[i].iAttribute == aAttribute) |
|
54 { |
|
55 // Set the value and return the associated error code |
|
56 aValue = iAttributes[i].iValue; |
|
57 return iAttributes[i].iError; |
|
58 } |
|
59 } |
|
60 return KErrNotFound; |
|
61 } |
|
62 |
|
63 EXPORT_C TInt RAttributeSet::SetValue(TInt aAttribute, TInt aValue, TInt aErrorCode) |
|
64 { |
|
65 TInt i; |
|
66 TInt count = iAttributes.Count(); |
|
67 for(i = 0; i < count; i++) |
|
68 { |
|
69 if(iAttributes[i].iAttribute == aAttribute) |
|
70 { |
|
71 iAttributes[i].iValue = aValue; |
|
72 iAttributes[i].iError = aErrorCode; |
|
73 return KErrNone; |
|
74 } |
|
75 } |
|
76 return KErrNotFound; |
|
77 } |
|
78 |
|
79 EXPORT_C TInt RAttributeSet::operator [] (TInt aIndex) const |
|
80 { |
|
81 return iAttributes[aIndex].iAttribute; |
|
82 } |
|
83 |
|
84 EXPORT_C TInt RAttributeSet::Count() const |
|
85 { |
|
86 return iAttributes.Count(); |
|
87 } |
|
88 |
|
89 EXPORT_C void RAttributeSet::ExternalizeL(RWriteStream& aStream) const |
|
90 { |
|
91 TInt i; |
|
92 TInt count = iAttributes.Count(); |
|
93 aStream.WriteInt32L(count); |
|
94 for(i = 0; i < count; i++) |
|
95 { |
|
96 aStream.WriteInt32L(iAttributes[i].iAttribute); |
|
97 aStream.WriteInt32L(iAttributes[i].iValue); |
|
98 aStream.WriteInt32L(iAttributes[i].iError); |
|
99 } |
|
100 } |
|
101 |
|
102 EXPORT_C void RAttributeSet::InternalizeL(RReadStream& aStream) |
|
103 { |
|
104 TInt i; |
|
105 TInt attribute; |
|
106 TInt value; |
|
107 TInt errorCode; |
|
108 |
|
109 // Read the number of attributes to internalize |
|
110 TInt count = aStream.ReadInt32L(); |
|
111 |
|
112 // loop through all the attributes |
|
113 for(i = 0; i < count; i++) |
|
114 { |
|
115 // Read the attribute and value from the stream |
|
116 attribute = aStream.ReadInt32L(); |
|
117 value = aStream.ReadInt32L(); |
|
118 errorCode = aStream.ReadInt32L(); |
|
119 |
|
120 // try setting the attribute value first in case it already exists |
|
121 if(SetValue(attribute, value, errorCode) != KErrNone) |
|
122 { |
|
123 // Doesn't exist so set a new values |
|
124 AddL(attribute, value, errorCode); |
|
125 } |
|
126 } |
|
127 } |
|
128 |
|
129 void RAttributeSet::AddL(TInt aAttribute, TInt aValue, TInt aErrorCode) |
|
130 { |
|
131 TAttributeValue attribute; |
|
132 attribute.iAttribute = aAttribute; |
|
133 attribute.iValue = aValue; |
|
134 attribute.iError = aErrorCode; |
|
135 |
|
136 // Append the new values to the iAttributes array |
|
137 User::LeaveIfError(iAttributes.Append(attribute)); |
|
138 } |