|
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: Implementation of CNcdKeyValuePair |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32strm.h> |
|
20 #include <s32mem.h> |
|
21 |
|
22 #include "ncdutils.h" |
|
23 #include "catalogsutils.h" |
|
24 #include "catalogsdebug.h" |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // NewL |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 EXPORT_C CNcdKeyValuePair* CNcdKeyValuePair::NewL( const TDesC& aKey, |
|
31 const TDesC& aValue ) |
|
32 { |
|
33 CNcdKeyValuePair* self = CNcdKeyValuePair::NewLC( aKey, aValue ); |
|
34 CleanupStack::Pop(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // NewLC |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 EXPORT_C CNcdKeyValuePair* CNcdKeyValuePair::NewLC( const TDesC& aKey, |
|
44 const TDesC& aValue ) |
|
45 { |
|
46 CNcdKeyValuePair* self = new( ELeave ) CNcdKeyValuePair; |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL( aKey, aValue ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Copy creator |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C CNcdKeyValuePair* CNcdKeyValuePair::NewL( |
|
58 const MNcdKeyValuePair& aOther ) |
|
59 { |
|
60 // Using normal constructor |
|
61 CNcdKeyValuePair* self = CNcdKeyValuePair::NewLC( aOther ); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Copy creator |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 EXPORT_C CNcdKeyValuePair* CNcdKeyValuePair::NewLC( |
|
71 const MNcdKeyValuePair& aOther ) |
|
72 { |
|
73 // Using normal constructor |
|
74 CNcdKeyValuePair* self = new ( ELeave ) CNcdKeyValuePair(); |
|
75 CleanupStack::PushL( self ); |
|
76 self->ConstructL( aOther.Key(), aOther.Value() ); |
|
77 return self; |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // NewL |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 EXPORT_C CNcdKeyValuePair* CNcdKeyValuePair::NewL( RReadStream& aStream ) |
|
86 { |
|
87 CNcdKeyValuePair* self = CNcdKeyValuePair::NewLC( aStream ); |
|
88 CleanupStack::Pop(); |
|
89 return self; |
|
90 } |
|
91 |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // NewLC |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 EXPORT_C CNcdKeyValuePair* CNcdKeyValuePair::NewLC( RReadStream& aStream ) |
|
98 { |
|
99 CNcdKeyValuePair* self = new( ELeave ) CNcdKeyValuePair; |
|
100 CleanupStack::PushL( self ); |
|
101 self->InternalizeL( aStream ); |
|
102 return self; |
|
103 } |
|
104 |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // Destructor |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 CNcdKeyValuePair::~CNcdKeyValuePair() |
|
111 { |
|
112 delete iKey; |
|
113 delete iValue; |
|
114 } |
|
115 |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // Key |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 const TDesC& CNcdKeyValuePair::Key() const |
|
122 { |
|
123 DASSERT( iKey ); |
|
124 return *iKey; |
|
125 } |
|
126 |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // SetKeyL |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 EXPORT_C void CNcdKeyValuePair::SetKeyL( const TDesC& aKey ) |
|
133 { |
|
134 if ( !aKey.Length() ) |
|
135 { |
|
136 User::Leave( KErrArgument ); |
|
137 } |
|
138 |
|
139 HBufC* temp = aKey.AllocL(); |
|
140 delete iKey; |
|
141 iKey = temp; |
|
142 } |
|
143 |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // Value |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 const TDesC& CNcdKeyValuePair::Value() const |
|
150 { |
|
151 DASSERT( iValue ); |
|
152 return *iValue; |
|
153 } |
|
154 |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // SetValueL |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 EXPORT_C void CNcdKeyValuePair::SetValueL( const TDesC& aValue ) |
|
161 { |
|
162 HBufC* temp = aValue.AllocL(); |
|
163 delete iValue; |
|
164 iValue = temp; |
|
165 } |
|
166 |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // Matcher |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 EXPORT_C TBool CNcdKeyValuePair::MatchByKey( const CNcdKeyValuePair& aFirst, |
|
173 const CNcdKeyValuePair& aSecond ) |
|
174 { |
|
175 return ( aFirst.Key().Compare( aSecond.Key() ) == 0 ); |
|
176 } |
|
177 |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // ExternalizeL |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 EXPORT_C void CNcdKeyValuePair::ExternalizeL( RWriteStream& aStream ) const |
|
184 { |
|
185 ExternalizeDesL( *iKey, aStream ); |
|
186 ExternalizeDesL( *iValue, aStream ); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // ExternalizeL |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 EXPORT_C HBufC8* CNcdKeyValuePair::ExternalizeToDesLC() const |
|
194 { |
|
195 HBufC8* ext = HBufC8::NewLC( 2 * ( sizeof(TInt) + iKey->Length() + |
|
196 iValue->Length() ) ); |
|
197 TPtr8 ptr( ext->Des() ); |
|
198 RDesWriteStream stream( ptr ); |
|
199 CleanupClosePushL( stream ); |
|
200 ExternalizeDesL( *iKey, stream ); |
|
201 ExternalizeDesL( *iValue, stream ); |
|
202 CleanupStack::PopAndDestroy( &stream ); |
|
203 |
|
204 return ext; |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // InternalizeL |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 EXPORT_C void CNcdKeyValuePair::InternalizeL( RReadStream& aStream ) |
|
212 { |
|
213 InternalizeDesL( iKey, aStream ); |
|
214 InternalizeDesL( iValue, aStream ); |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // ConstructL |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CNcdKeyValuePair::ConstructL( const TDesC& aKey, const TDesC& aValue ) |
|
222 { |
|
223 if ( !aKey.Length() ) |
|
224 { |
|
225 User::Leave( KErrArgument ); |
|
226 } |
|
227 |
|
228 iKey = aKey.AllocL(); |
|
229 iValue = aValue.AllocL(); |
|
230 } |
|
231 |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // Constructor |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 CNcdKeyValuePair::CNcdKeyValuePair() |
|
238 { |
|
239 } |
|
240 |
|
241 |
|
242 |