|
1 // Copyright (c) 2008-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 inline RSettingsArray::RSettingsArray() : |
|
17 RArray<TServerSetting>(KGranularity, _FOFF(TServerSetting, iKey)) |
|
18 {iIsDefault=EFalse;} |
|
19 |
|
20 inline RSettingsArray::~RSettingsArray() |
|
21 { Reset(); } |
|
22 |
|
23 inline TServerSetting* RSettingsArray::Find(TInt aKey) const |
|
24 { |
|
25 TInt i = FindInUnsignedKeyOrder(TServerSetting(aKey)); |
|
26 return i>=0 ? const_cast<TServerSetting*>(&operator[](i)) : (TServerSetting*)0; |
|
27 } |
|
28 |
|
29 inline TInt RSettingsArray::FindIndex(const TServerSetting& aSetting) const |
|
30 { |
|
31 return FindInUnsignedKeyOrder(aSetting); |
|
32 } |
|
33 |
|
34 inline void RSettingsArray::OrderedInsertL(const TServerSetting& aEntry) |
|
35 { InsertInUnsignedKeyOrderL(aEntry); } |
|
36 |
|
37 inline TInt RSettingsArray::OrderedInsert(const TServerSetting& aEntry) |
|
38 { return InsertInUnsignedKeyOrder(aEntry); } |
|
39 |
|
40 inline TInt RSettingsArray::Count() const |
|
41 { return RArray<TServerSetting>::Count(); } |
|
42 |
|
43 inline const TServerSetting& RSettingsArray::operator[](TInt aIndex) const |
|
44 { |
|
45 return RArray<TServerSetting>::operator[](aIndex); |
|
46 } |
|
47 |
|
48 inline TServerSetting& RSettingsArray::operator[](TInt aIndex) |
|
49 { |
|
50 return RArray<TServerSetting>::operator[](aIndex); |
|
51 } |
|
52 |
|
53 inline void RSettingsArray::Remove(TInt aId) |
|
54 { |
|
55 TInt i = FindInUnsignedKeyOrder(TServerSetting(aId)); |
|
56 if(i>=0) |
|
57 DeleteElement(i); |
|
58 } |
|
59 |
|
60 inline void RSettingsArray::Reset() |
|
61 { |
|
62 for(TInt i=Count()-1; i>=0; i--) |
|
63 { |
|
64 operator[](i).Reset(); |
|
65 } |
|
66 RArray<TServerSetting>::Reset(); |
|
67 } |
|
68 |
|
69 inline void RSettingsArray::Close() |
|
70 { |
|
71 Reset(); |
|
72 } |
|
73 |
|
74 inline void RSettingsArray::DeleteElement(TInt aIndex) |
|
75 { |
|
76 operator[](aIndex).Reset(); |
|
77 RArray<TServerSetting>::Remove(aIndex); |
|
78 } |
|
79 |
|
80 inline void RSettingsArray::RemoveElement(TInt aIndex) |
|
81 { |
|
82 RArray<TServerSetting>::Remove(aIndex); |
|
83 } |
|
84 |
|
85 inline void RSettingsArray::AdoptL(RSettingsArray& aSrc) |
|
86 { |
|
87 Reset(); |
|
88 |
|
89 for(TInt i=aSrc.Count()-1; i>=0; i--) |
|
90 { |
|
91 AppendL(aSrc[0]); |
|
92 aSrc.RemoveElement(0); |
|
93 } |
|
94 } |
|
95 |
|
96 inline void RSettingsArray::ExternalizeL(RWriteStream& aStream) const |
|
97 { |
|
98 |
|
99 TInt32 numElements = Count() ; |
|
100 |
|
101 aStream << numElements ; |
|
102 for (TInt32 count = 0; count < numElements; count++) |
|
103 { |
|
104 aStream << (*this)[count] ; |
|
105 } |
|
106 } |
|
107 |
|
108 |
|
109 inline void RSettingsArray::WriteBackupStream(RWriteStream& aStream) const |
|
110 { |
|
111 |
|
112 // Note: Unlike the usual implementation of Externalize() |
|
113 // only selected data (settings with the "backup" bit set |
|
114 // in metadata) are streamed out!!! |
|
115 TInt32 numElementsToExternalize = 0; |
|
116 TInt32 numElements = Count() ; |
|
117 TInt32 count ; |
|
118 |
|
119 for (count = 0; count < numElements; count++) |
|
120 { |
|
121 if ((*this)[count].Meta() & KMetaBackup) |
|
122 numElementsToExternalize++ ; |
|
123 } |
|
124 |
|
125 aStream << numElementsToExternalize ; |
|
126 for (count = 0; count < numElements; count++) |
|
127 { |
|
128 if ((*this)[count].Meta() & KMetaBackup) |
|
129 aStream << (*this)[count] ; |
|
130 } |
|
131 } |
|
132 |
|
133 inline void RSettingsArray::InternalizeL(RReadStream& aStream) |
|
134 { |
|
135 TInt32 numElements; |
|
136 |
|
137 aStream >> numElements ; |
|
138 for (TInt32 count = 0; count < numElements; count++) |
|
139 { |
|
140 TServerSetting serverSetting ; |
|
141 aStream >> serverSetting ; |
|
142 serverSetting.PushL(); |
|
143 if(IsDefault()) |
|
144 { |
|
145 serverSetting.SetClean(); |
|
146 } |
|
147 AppendL(serverSetting) ; |
|
148 serverSetting.Pop(); |
|
149 } |
|
150 } |
|
151 |
|
152 inline TBool RSettingsArray::IsDefault() const |
|
153 { |
|
154 return iIsDefault; |
|
155 } |
|
156 |
|
157 inline void RSettingsArray::SetIsDefault(TBool aIsDefault) |
|
158 { |
|
159 iIsDefault=aIsDefault; |
|
160 } |
|
161 |
|
162 inline RRangePolicyArray::RRangePolicyArray() : |
|
163 RArray<TSettingsAccessPolicy>() |
|
164 {} |
|
165 |
|
166 inline RRangePolicyArray::~RRangePolicyArray() |
|
167 { Reset(); } |
|
168 |
|
169 inline TSettingsAccessPolicy* RRangePolicyArray::Find(TInt aKey) const |
|
170 { |
|
171 for(TInt ii = Count()-1; ii>=0;ii--) |
|
172 { |
|
173 if(operator[](ii).IsInRange(aKey)) |
|
174 return const_cast<TSettingsAccessPolicy*>(&operator[](ii)); |
|
175 } |
|
176 return NULL; |
|
177 } |
|
178 |
|
179 inline void RRangePolicyArray::ExternalizeL(RWriteStream& aStream) const |
|
180 { |
|
181 TInt32 numElements = Count() ; |
|
182 |
|
183 aStream << numElements ; |
|
184 |
|
185 for (TInt32 count = 0; count < numElements; count++) |
|
186 { |
|
187 aStream << (*this)[count] ; |
|
188 } |
|
189 } |
|
190 |
|
191 inline void RRangePolicyArray::InternalizeL(RReadStream& aStream) |
|
192 { |
|
193 TInt32 numElements = Count() ; |
|
194 aStream >> numElements ; |
|
195 for (TInt32 count = 0; count < numElements; count++) |
|
196 { |
|
197 TSettingsAccessPolicy newElement ; |
|
198 aStream >> newElement ; |
|
199 AppendL(newElement) ; |
|
200 } |
|
201 } |
|
202 |
|
203 inline RDefaultMetaArray::RDefaultMetaArray() : |
|
204 RArray<TSettingsDefaultMeta>() |
|
205 {} |
|
206 |
|
207 inline RDefaultMetaArray::~RDefaultMetaArray() |
|
208 { Reset(); } |
|
209 |
|
210 inline TSettingsDefaultMeta* RDefaultMetaArray::Find(TInt aKey) const |
|
211 { |
|
212 for(TInt ii = Count()-1; ii>=0;ii--) |
|
213 { |
|
214 if(operator[](ii).IsInRange(aKey)) |
|
215 return const_cast<TSettingsDefaultMeta*>(&operator[](ii)); |
|
216 } |
|
217 return NULL; |
|
218 } |
|
219 |
|
220 inline void RDefaultMetaArray::ExternalizeL(RWriteStream& aStream) const |
|
221 { |
|
222 TInt32 numElements = Count() ; |
|
223 |
|
224 aStream << numElements ; |
|
225 |
|
226 for (TInt32 count = 0; count < numElements; count++) |
|
227 { |
|
228 aStream << (*this)[count] ; |
|
229 } |
|
230 } |
|
231 |
|
232 inline void RDefaultMetaArray::InternalizeL(RReadStream& aStream) |
|
233 { |
|
234 TInt32 numElements = Count() ; |
|
235 aStream >> numElements ; |
|
236 for (TInt32 count = 0; count < numElements; count++) |
|
237 { |
|
238 TSettingsDefaultMeta newElement ; |
|
239 aStream >> newElement ; |
|
240 AppendL(newElement) ; |
|
241 } |
|
242 } |
|
243 |
|
244 inline RSingleMetaArray::RSingleMetaArray() : RArray<TSettingSingleMeta>() |
|
245 { |
|
246 } |
|
247 |
|
248 inline TInt RSingleMetaArray::Find(TUint32 aKey, TUint32& aMeta) const |
|
249 { |
|
250 TInt num = Count(); |
|
251 for(TInt i = 0; i < num; i++) |
|
252 { |
|
253 TSettingSingleMeta singleMeta = static_cast<TSettingSingleMeta> (operator[](i)); |
|
254 if(singleMeta.GetKey() == aKey) |
|
255 { |
|
256 aMeta = singleMeta.GetMeta(); |
|
257 return KErrNone; |
|
258 } |
|
259 } |
|
260 return KErrNotFound; |
|
261 } |