|
1 /* |
|
2 * Copyright (c) 2005-2007 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 "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: An list for fieldtype references. Implements |
|
15 * MVPbkFieldTypeList so can be used e.g as parameter to Find |
|
16 * operation. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "CVPbkFieldTypeRefsList.h" |
|
23 #include <barsread.h> |
|
24 #include "TVPbkFieldVersitProperty.h" |
|
25 |
|
26 |
|
27 // -------------------------------------------------------------------------- |
|
28 // CVPbkFieldTypeRefsList::CVPbkFieldTypeRefsList |
|
29 // -------------------------------------------------------------------------- |
|
30 // |
|
31 inline CVPbkFieldTypeRefsList::CVPbkFieldTypeRefsList() |
|
32 { |
|
33 } |
|
34 |
|
35 // -------------------------------------------------------------------------- |
|
36 // CVPbkFieldTypeRefsList::~CVPbkFieldTypeRefsList |
|
37 // -------------------------------------------------------------------------- |
|
38 // |
|
39 CVPbkFieldTypeRefsList::~CVPbkFieldTypeRefsList() |
|
40 { |
|
41 iFieldTypes.Reset(); |
|
42 } |
|
43 |
|
44 // -------------------------------------------------------------------------- |
|
45 // CVPbkFieldTypeRefsList::NewL |
|
46 // -------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C CVPbkFieldTypeRefsList* CVPbkFieldTypeRefsList::NewL() |
|
49 { |
|
50 CVPbkFieldTypeRefsList* self = new(ELeave) CVPbkFieldTypeRefsList; |
|
51 return self; |
|
52 } |
|
53 |
|
54 // -------------------------------------------------------------------------- |
|
55 // CVPbkFieldTypeRefsList::AppendL |
|
56 // -------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C void CVPbkFieldTypeRefsList::AppendL(const MVPbkFieldType& aFieldType) |
|
59 { |
|
60 const TInt matchPriorities = aFieldType.VersitProperties().Count(); |
|
61 if (matchPriorities > iMaxMatchPriority) |
|
62 { |
|
63 iMaxMatchPriority = matchPriorities - 1; |
|
64 } |
|
65 |
|
66 User::LeaveIfError(iFieldTypes.Append(&aFieldType)); |
|
67 } |
|
68 |
|
69 // -------------------------------------------------------------------------- |
|
70 // CVPbkFieldTypeRefsList::Remove |
|
71 // -------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C void CVPbkFieldTypeRefsList::Remove(const MVPbkFieldType& aFieldType) |
|
74 { |
|
75 TInt index = iFieldTypes.Find(&aFieldType); |
|
76 if (index != KErrNotFound) |
|
77 { |
|
78 iFieldTypes.Remove(index); |
|
79 iMaxMatchPriority = 0; |
|
80 TInt fieldTypeCount = iFieldTypes.Count(); |
|
81 for (TInt i = 0; i < fieldTypeCount; ++i) |
|
82 { |
|
83 const TInt matchPriorities = FieldTypeAt(i).VersitProperties().Count(); |
|
84 if (matchPriorities > iMaxMatchPriority) |
|
85 { |
|
86 iMaxMatchPriority = matchPriorities - 1; |
|
87 } |
|
88 } |
|
89 } |
|
90 } |
|
91 |
|
92 // -------------------------------------------------------------------------- |
|
93 // CVPbkFieldTypeRefsList::Reset |
|
94 // -------------------------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C void CVPbkFieldTypeRefsList::Reset() |
|
97 { |
|
98 // Reset but don't destroy |
|
99 iFieldTypes.Reset(); |
|
100 } |
|
101 |
|
102 // -------------------------------------------------------------------------- |
|
103 // CVPbkFieldTypeRefsList::FieldTypeCount |
|
104 // -------------------------------------------------------------------------- |
|
105 // |
|
106 TInt CVPbkFieldTypeRefsList::FieldTypeCount() const |
|
107 { |
|
108 return iFieldTypes.Count(); |
|
109 } |
|
110 |
|
111 // -------------------------------------------------------------------------- |
|
112 // CVPbkFieldTypeRefsList::FieldTypeAt |
|
113 // -------------------------------------------------------------------------- |
|
114 // |
|
115 const MVPbkFieldType& CVPbkFieldTypeRefsList::FieldTypeAt(TInt aIndex) const |
|
116 { |
|
117 return *iFieldTypes[aIndex]; |
|
118 } |
|
119 |
|
120 // -------------------------------------------------------------------------- |
|
121 // CVPbkFieldTypeRefsList::ContainsSame |
|
122 // -------------------------------------------------------------------------- |
|
123 // |
|
124 TBool CVPbkFieldTypeRefsList::ContainsSame(const MVPbkFieldType& aFieldType) const |
|
125 { |
|
126 const TInt count = iFieldTypes.Count(); |
|
127 for (TInt i=0; i < count; ++i) |
|
128 { |
|
129 if (iFieldTypes[i]->IsSame(aFieldType)) |
|
130 { |
|
131 return ETrue; |
|
132 } |
|
133 } |
|
134 return EFalse; |
|
135 } |
|
136 |
|
137 // -------------------------------------------------------------------------- |
|
138 // CVPbkFieldTypeRefsList::MaxMatchPriority |
|
139 // -------------------------------------------------------------------------- |
|
140 // |
|
141 TInt CVPbkFieldTypeRefsList::MaxMatchPriority() const |
|
142 { |
|
143 return iMaxMatchPriority; |
|
144 } |
|
145 |
|
146 // -------------------------------------------------------------------------- |
|
147 // CVPbkFieldTypeRefsList::FindMatch |
|
148 // -------------------------------------------------------------------------- |
|
149 // |
|
150 const MVPbkFieldType* CVPbkFieldTypeRefsList::FindMatch |
|
151 (const TVPbkFieldVersitProperty& aMatchProperty, |
|
152 TInt aMatchPriority) const |
|
153 { |
|
154 const TInt count = iFieldTypes.Count(); |
|
155 for (TInt i=0; i < count; ++i) |
|
156 { |
|
157 const MVPbkFieldType& ft = *iFieldTypes[i]; |
|
158 if (ft.Matches(aMatchProperty, aMatchPriority)) |
|
159 { |
|
160 return &ft; |
|
161 } |
|
162 } |
|
163 return NULL; |
|
164 } |
|
165 |
|
166 // -------------------------------------------------------------------------- |
|
167 // CVPbkFieldTypeRefsList::FindMatch |
|
168 // -------------------------------------------------------------------------- |
|
169 // |
|
170 const MVPbkFieldType* CVPbkFieldTypeRefsList::FindMatch |
|
171 (TVPbkNonVersitFieldType aNonVersitType) const |
|
172 { |
|
173 const TInt count = iFieldTypes.Count(); |
|
174 for (TInt i=0; i < count; ++i) |
|
175 { |
|
176 const MVPbkFieldType& ft = *iFieldTypes[i]; |
|
177 if (ft.NonVersitType() == aNonVersitType) |
|
178 { |
|
179 return &ft; |
|
180 } |
|
181 } |
|
182 return NULL; |
|
183 } |
|
184 |
|
185 // -------------------------------------------------------------------------- |
|
186 // CVPbkFieldTypeRefsList::Find |
|
187 // -------------------------------------------------------------------------- |
|
188 // |
|
189 const MVPbkFieldType* CVPbkFieldTypeRefsList::Find( |
|
190 TInt aFieldTypeResId) const |
|
191 { |
|
192 const MVPbkFieldType* fieldType = NULL; |
|
193 const TInt count = iFieldTypes.Count(); |
|
194 for (TInt i = 0; i < count; ++i) |
|
195 { |
|
196 if (iFieldTypes[i]->FieldTypeResId() == aFieldTypeResId) |
|
197 { |
|
198 fieldType = iFieldTypes[i]; |
|
199 break; |
|
200 } |
|
201 } |
|
202 return fieldType; |
|
203 } |
|
204 |
|
205 // end of file |
|
206 |