|
1 /* |
|
2 * Copyright (c) 2005,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: Represent string pool for dom strings |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "xndomstringpool.h" |
|
22 |
|
23 |
|
24 // ============================ LOCAL FUNCTIONS ================================ |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CXnDomStringPool::CXnDomStringPool |
|
29 // C++ default constructor can NOT contain any code, that |
|
30 // might leave. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CXnDomStringPool::CXnDomStringPool() |
|
34 { |
|
35 iStringPoolOffsetCurrent = iStringPoolOffsetNext = 0; |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CXnDomStringPool::ConstructL |
|
40 // Symbian 2nd phase constructor can leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 void CXnDomStringPool::ConstructL() |
|
44 { |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CXnDomStringPool::NewL |
|
49 // Two-phased constructor. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CXnDomStringPool* CXnDomStringPool::NewL() |
|
53 { |
|
54 CXnDomStringPool* self = new( ELeave ) CXnDomStringPool; |
|
55 |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(self); |
|
59 |
|
60 return self; |
|
61 } |
|
62 |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CXnDomStringPool::NewL |
|
66 // Two-phased stream constructor. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CXnDomStringPool* CXnDomStringPool::NewL( RReadStream& aStream ) |
|
70 { |
|
71 CXnDomStringPool* self = new( ELeave ) CXnDomStringPool; |
|
72 CleanupStack::PushL( self ); |
|
73 aStream >> *self; |
|
74 CleanupStack::Pop(self); |
|
75 |
|
76 return self; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CXnDomStringPool::~CXnDomStringPool |
|
81 // Destructor |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CXnDomStringPool::~CXnDomStringPool() |
|
85 { |
|
86 iStringPool.ResetAndDestroy(); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CXnDomStringPool::CloneL |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CXnDomStringPool* CXnDomStringPool::CloneL() |
|
94 { |
|
95 CXnDomStringPool* clone = CXnDomStringPool::NewL(); |
|
96 CleanupStack::PushL( clone ); |
|
97 |
|
98 TInt count( iStringPool.Count() ); |
|
99 for ( TInt i=0; i<count; i++ ) |
|
100 { |
|
101 HBufC8* tmp = iStringPool[i]->Des().AllocLC(); |
|
102 clone->iStringPool.AppendL( tmp ); |
|
103 CleanupStack::Pop( tmp ); |
|
104 } |
|
105 CleanupStack::Pop( clone ); |
|
106 return clone; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CXnDomNode::AddStringL |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C TInt CXnDomStringPool::AddStringL( const TDesC8& aString ) |
|
114 { |
|
115 TBool found( EFalse ); |
|
116 TInt index( 0 ); |
|
117 |
|
118 TInt count( iStringPool.Count() ); |
|
119 for (; index < count && !found; ) |
|
120 { |
|
121 if ( iStringPool[ index ]->Des().Compare( aString ) == 0 ) |
|
122 { |
|
123 found = ETrue; |
|
124 } |
|
125 else |
|
126 { |
|
127 index++; |
|
128 } |
|
129 } |
|
130 if ( !found ) |
|
131 { |
|
132 HBufC8* tmp = aString.AllocLC(); |
|
133 iStringPool.AppendL( tmp ); |
|
134 CleanupStack::Pop( tmp ); |
|
135 index = iStringPool.Count()-1; //Last item |
|
136 iStringPoolOffsetNext++; |
|
137 } |
|
138 return index; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CXnDomNode::String |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 const TDesC8& CXnDomStringPool::String( const TInt aStringRef ) |
|
146 { |
|
147 return (*iStringPool[ aStringRef ]); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CXnDomStringPool::Size |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 TInt CXnDomStringPool::Size() const |
|
155 { |
|
156 TInt size( 0 ); |
|
157 |
|
158 TInt count( iStringPool.Count() ); |
|
159 for ( TInt i=0; i<count; i++ ) |
|
160 { |
|
161 size += sizeof(TInt16); //Length |
|
162 size++; //HBufC control mark |
|
163 size++; //HBufC control mark |
|
164 size += iStringPool[i]->Size(); //Buffer sixe in bytes |
|
165 } |
|
166 return size; |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CXnDomStringPool::ExternalizeL |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CXnDomStringPool::ExternalizeL( RWriteStream& aStream ) const |
|
174 { |
|
175 TInt count( iStringPool.Count() ); |
|
176 aStream.WriteInt16L( count ); |
|
177 |
|
178 for ( TInt i=0; i<count; i++ ) |
|
179 { |
|
180 aStream.WriteInt16L( iStringPool[i]->Length() ); |
|
181 aStream << *iStringPool[i]; |
|
182 } |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CXnDomStringPool::InternalizeL |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CXnDomStringPool::InternalizeL( RReadStream& aStream ) |
|
190 { |
|
191 TInt len(0); |
|
192 TInt16 count ( aStream.ReadInt16L() ); |
|
193 |
|
194 iStringPoolOffsetCurrent = iStringPoolOffsetNext; |
|
195 iStringPoolOffsetNext += count; |
|
196 |
|
197 for ( TInt i=0; i<count; i++ ) |
|
198 { |
|
199 len = aStream.ReadInt16L(); |
|
200 HBufC8* tmp = HBufC8::NewLC( aStream, len ); |
|
201 iStringPool.AppendL( tmp ); |
|
202 CleanupStack::Pop( tmp ); |
|
203 } |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CXnDomStringPool::Offset |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 TUint CXnDomStringPool::Offset() const |
|
211 { |
|
212 return iStringPoolOffsetCurrent; |
|
213 } |
|
214 |
|
215 // End of File |