|
1 /* |
|
2 * Copyright (c) 2006 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: MXIMPFeatureInfo API object implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "ximpfeatureinfoimp.h" |
|
19 #include "ximprbufhelpers.h" |
|
20 |
|
21 |
|
22 const TInt KXIMPFeatureInfoGranularity = 5; |
|
23 |
|
24 // ============================ MEMBER FUNCTIONS ============================= |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // CXIMPFeatureInfoImp::NewLC() |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 EXPORT_C CXIMPFeatureInfoImp* CXIMPFeatureInfoImp::NewLC() |
|
31 { |
|
32 CXIMPFeatureInfoImp* self = new( ELeave ) CXIMPFeatureInfoImp; |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CXIMPFeatureInfoImp::NewLC() |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 EXPORT_C CXIMPFeatureInfoImp* CXIMPFeatureInfoImp::NewL() |
|
44 { |
|
45 CXIMPFeatureInfoImp* self = CXIMPFeatureInfoImp::NewLC(); |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CXIMPFeatureInfoImp::~CXIMPFeatureInfoImp() |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CXIMPFeatureInfoImp::~CXIMPFeatureInfoImp() |
|
57 { |
|
58 if ( iFeatures ) |
|
59 { |
|
60 iFeatures->Reset(); |
|
61 } |
|
62 delete iFeatures; |
|
63 } |
|
64 |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CXIMPFeatureInfoImp::CXIMPFeatureInfoImp() |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CXIMPFeatureInfoImp::CXIMPFeatureInfoImp() |
|
71 { |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CXIMPFeatureInfoImp::ConstructL() |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void CXIMPFeatureInfoImp::ConstructL() |
|
80 { |
|
81 iFeatures = new ( ELeave ) CDesC8ArraySeg( KXIMPFeatureInfoGranularity ); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CXIMPFeatureInfoImp::NewFromStreamLC() |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 XIMPIMP_IMPLEMENT_DATAOBJ_NEWFROMSTREAM( CXIMPFeatureInfoImp ) |
|
89 |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // Implement supported interface access. |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 XIMPIMP_IF_BASE_GET_INTERFACE_BEGIN( CXIMPFeatureInfoImp, |
|
96 MXIMPFeatureInfo ) |
|
97 XIMPIMP_IF_BASE_GET_INTERFACE_END() |
|
98 |
|
99 XIMPIMP_IF_BASE_GET_CONST_INTERFACE_BEGIN( CXIMPFeatureInfoImp, |
|
100 MXIMPFeatureInfo ) |
|
101 XIMPIMP_IF_BASE_GET_INTERFACE_END() |
|
102 |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CXIMPFeatureInfoImp::FeatureIds() |
|
106 // --------------------------------------------------------------------------- |
|
107 const MDesC8Array& CXIMPFeatureInfoImp::FeatureIds() const |
|
108 { |
|
109 return *iFeatures; |
|
110 } |
|
111 |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CXIMPFeatureInfoImp::HasFeatureId() |
|
115 // --------------------------------------------------------------------------- |
|
116 TInt CXIMPFeatureInfoImp::HasFeatureId( const TDesC8& aFeatureId ) |
|
117 { |
|
118 TInt index(0); |
|
119 return FindFeature( aFeatureId, index ); |
|
120 } |
|
121 |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CXIMPFeatureInfoImp::AddFeatureL() |
|
125 // --------------------------------------------------------------------------- |
|
126 EXPORT_C TInt CXIMPFeatureInfoImp::AddFeatureL( const TDesC8& aFeature ) |
|
127 { |
|
128 // First check if the feature already exists |
|
129 TInt index( 0 ); |
|
130 if ( FindFeature( aFeature, index ) == 0 ) |
|
131 { |
|
132 return KErrAlreadyExists; |
|
133 } |
|
134 |
|
135 // Add to features |
|
136 iFeatures->InsertIsqL( aFeature ); |
|
137 return KErrNone; |
|
138 } |
|
139 |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // CXIMPFeatureInfoImp::FindFeature() |
|
143 // --------------------------------------------------------------------------- |
|
144 TInt CXIMPFeatureInfoImp::FindFeature( const TDesC8& aFeature, TInt& aIndex ) |
|
145 { |
|
146 if ( iFeatures->FindIsq( aFeature, aIndex ) != 0 ) |
|
147 { |
|
148 return KErrNotFound; |
|
149 } |
|
150 |
|
151 return KErrNone; |
|
152 } |
|
153 |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CXIMPFeatureInfoImp::ExternalizeL() |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CXIMPFeatureInfoImp::ExternalizeL( RWriteStream& aStream ) const |
|
160 { |
|
161 const TInt featureCount = iFeatures->MdcaCount(); |
|
162 aStream.WriteInt32L( featureCount ); |
|
163 |
|
164 for ( TInt count = 0; count < featureCount; count++ ) |
|
165 { |
|
166 TPtrC8 temp (iFeatures->MdcaPoint( count ) ); |
|
167 aStream.WriteInt32L( temp.Length() ); |
|
168 aStream.WriteL( temp ); |
|
169 } |
|
170 } |
|
171 |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CXIMPFeatureInfoImp::InternalizeL() |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 EXPORT_C void CXIMPFeatureInfoImp::InternalizeL( RReadStream& aStream ) |
|
178 { |
|
179 iFeatures->Reset(); |
|
180 |
|
181 const TInt featureCount = aStream.ReadInt32L(); |
|
182 |
|
183 RBuf8 temp; |
|
184 CleanupClosePushL( temp ); |
|
185 |
|
186 for ( TInt count( 0 ); count < featureCount; count++ ) |
|
187 { |
|
188 const TInt length = aStream.ReadInt32L(); |
|
189 XIMPRBuf8Helper::GrowIfNeededL( temp, length ); |
|
190 aStream.ReadL( temp, length ); |
|
191 |
|
192 // Fine to simply append new entries, since we are internalizing |
|
193 // data which has been already validated and ordered |
|
194 iFeatures->AppendL( temp ); |
|
195 } |
|
196 |
|
197 CleanupStack::PopAndDestroy(); // temp |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // CXIMPFeatureInfoImp::EqualsContent() |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 TBool CXIMPFeatureInfoImp::EqualsContent( |
|
205 const CXIMPApiDataObjBase& aOtherInstance ) const |
|
206 { |
|
207 const CXIMPFeatureInfoImp* tmp = |
|
208 TXIMPGetImpClassOrPanic< const CXIMPFeatureInfoImp >::From( aOtherInstance.Base() ); |
|
209 |
|
210 TBool same = ETrue; |
|
211 TBool x; |
|
212 |
|
213 x = iFeatures->MdcaCount() == tmp->iFeatures->MdcaCount(); |
|
214 same &= x; |
|
215 |
|
216 if ( ! same ) |
|
217 { |
|
218 // early-out if lengths mismatch to avoid costly array |
|
219 // comparison |
|
220 return EFalse; |
|
221 } |
|
222 |
|
223 // arrays must be in same order with same content. |
|
224 for ( TInt i = 0; i < iFeatures->Count(); i++ ) |
|
225 { |
|
226 x = 0 == iFeatures->MdcaPoint( i ).Compare( tmp->iFeatures->MdcaPoint( i ) ); |
|
227 same &= x; |
|
228 } |
|
229 |
|
230 return same; |
|
231 } |
|
232 |
|
233 // End of file |