|
1 /* |
|
2 * Copyright (c) 1997-1999 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32svr.h> |
|
19 |
|
20 #include "resdict.h" |
|
21 #include "resentry.h" |
|
22 |
|
23 // TDictEntry |
|
24 |
|
25 TDictEntry::TDictEntry() |
|
26 { |
|
27 iUses = 0; |
|
28 iRef = 0; |
|
29 iEmbedded = 0; |
|
30 } |
|
31 |
|
32 void TDictEntry::Close() |
|
33 { |
|
34 delete iEmbedded; |
|
35 iEmbedded = NULL; |
|
36 } |
|
37 |
|
38 |
|
39 |
|
40 TDesC8& TDictEntry::Data() |
|
41 { |
|
42 return iData; |
|
43 } |
|
44 |
|
45 TInt TDictEntry::Use() |
|
46 { |
|
47 return ((iUses + iRef - 1) * (Data().Length()-1)); |
|
48 } |
|
49 |
|
50 |
|
51 void TDictEntry::CreateEmbeddedDict(TInt aDictIndex,CDictArray* aDict) |
|
52 { |
|
53 // Create list of embedded dictionary strings |
|
54 iEmbedded = new(ELeave)CResEntry(aDict); |
|
55 iEmbedded->AddPlainDataL((TUint8*)iData.Ptr(), iData.Length()); |
|
56 iEmbedded->MatchDictL(aDictIndex); |
|
57 } |
|
58 |
|
59 |
|
60 // CDictArray |
|
61 |
|
62 CDictArray::CDictArray() |
|
63 :CArrayFixFlat<TDictEntry>(10) |
|
64 { |
|
65 } |
|
66 |
|
67 CDictArray::~CDictArray() |
|
68 { |
|
69 TInt count = Count(); |
|
70 for (TInt ii=0; ii<count; ii++) |
|
71 { |
|
72 At(ii).Close(); |
|
73 } |
|
74 } |
|
75 |
|
76 |
|
77 TInt CDictArray::AddEntryL(TDesC8& aEntry) |
|
78 { |
|
79 TInt size = aEntry.Size(); |
|
80 TInt pos = 0; |
|
81 TInt count = Count(); |
|
82 for (TInt ii=0; ii<count; ii++) |
|
83 { |
|
84 TInt dSize = At(ii).Data().Size(); |
|
85 if (dSize < size) |
|
86 { |
|
87 break; |
|
88 } |
|
89 else |
|
90 { |
|
91 if (At(ii).Data().Compare(aEntry) == 0) |
|
92 { |
|
93 // Already in dict |
|
94 return ii; |
|
95 } |
|
96 pos++; |
|
97 } |
|
98 } |
|
99 TDictEntry entry; |
|
100 entry.iData = aEntry; |
|
101 entry.iUses=0; |
|
102 InsertL(pos, entry); |
|
103 return pos; |
|
104 } |
|
105 |
|
106 |
|
107 void CDictArray::OrderedInsertL(TDictEntry& aEntry) |
|
108 { |
|
109 TInt use = aEntry.Use(); |
|
110 if (use < 1) |
|
111 return; // Don't bother to insert entries that aren't used |
|
112 |
|
113 TInt count = Count(); |
|
114 for (TInt ii=0; ii<count; ii++) |
|
115 { |
|
116 TInt entryUse = At(ii).Use(); |
|
117 if (entryUse < use) |
|
118 { |
|
119 InsertL(ii, aEntry); |
|
120 return; |
|
121 } |
|
122 } |
|
123 AppendL(aEntry); |
|
124 } |
|
125 |
|
126 void CDictArray::SizedInsertL(TDictEntry& aEntry) |
|
127 { |
|
128 TInt len = aEntry.Data().Length(); |
|
129 |
|
130 TInt count = Count(); |
|
131 for (TInt ii=0; ii<count; ii++) |
|
132 { |
|
133 TInt entryLen = At(ii).Data().Length(); |
|
134 if (entryLen < len) |
|
135 { |
|
136 InsertL(ii, aEntry); |
|
137 return; |
|
138 } |
|
139 } |
|
140 AppendL(aEntry); |
|
141 } |
|
142 |
|
143 TInt CDictArray::DictionarySize() |
|
144 { |
|
145 TInt count = Count(); |
|
146 TInt size = 0; |
|
147 for (TInt jj=0; jj<count; jj++) |
|
148 { |
|
149 size += At(jj).iEmbedded->Size(iDictionaryBits); |
|
150 } |
|
151 |
|
152 size = (size + 7) / 8; |
|
153 |
|
154 // Add dictionary index |
|
155 size += (count * 2); |
|
156 |
|
157 // Add dictionary header |
|
158 |
|
159 size += 2; |
|
160 |
|
161 return size; |
|
162 } |
|
163 |
|
164 TInt CDictArray::DictionarySizeWithoutIndex() |
|
165 { |
|
166 TInt count = Count(); |
|
167 TInt size = 0; |
|
168 for (TInt jj=0; jj<count; jj++) |
|
169 { |
|
170 size += At(jj).iEmbedded->Size(iDictionaryBits); |
|
171 } |
|
172 size = (size + 7) / 8; |
|
173 return size; |
|
174 } |
|
175 |
|
176 |
|
177 |
|
178 TInt CDictArray::BitSize(TInt aIndex) |
|
179 { |
|
180 return At(aIndex).iEmbedded->Size(iDictionaryBits); |
|
181 } |
|
182 |
|
183 |
|
184 void CDictArray::WriteBitStreamL(TInt aIndex, TBitWriter& aWriter) |
|
185 { |
|
186 RDebug::Print(_L("Dictionary Entry: %d"), aIndex); |
|
187 At(aIndex).iEmbedded->WriteBitStreamL(aWriter,iDictionaryBits); |
|
188 } |
|
189 |
|
190 |
|
191 |
|
192 CDictArray* CDictArray::DuplicateL() |
|
193 { |
|
194 CDictArray* newDict = new(ELeave)CDictArray(); |
|
195 CleanupStack::PushL(newDict); |
|
196 TInt count = Count(); |
|
197 for (TInt ii=0; ii<count; ii++) |
|
198 { |
|
199 newDict->AppendL(At(ii)); |
|
200 } |
|
201 CleanupStack::Pop(); // newDict; |
|
202 return newDict; |
|
203 } |
|
204 |