|
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: Flyweigth pattern implementation for dom strings. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef XN_DOM_STRING_POOL_H |
|
19 #define XN_DOM_STRING_POOL_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <s32strm.h> |
|
24 #include "xndomstringpooloptimizer.h" |
|
25 |
|
26 // CLASS DECLARATION |
|
27 |
|
28 /** |
|
29 * @ingroup group_domdocument |
|
30 * Class utilize flyweight pattern. Dom strings are stored once |
|
31 * and referred with index. Class can be serialized. |
|
32 * |
|
33 * @lib xndomdocument.lib |
|
34 * @since Series 60 3.1 |
|
35 */ |
|
36 class CXnDomStringPool : public CBase |
|
37 { |
|
38 public: // Constructors and destructor |
|
39 |
|
40 /** |
|
41 * Two-phased constructor. |
|
42 * |
|
43 * @param aAllowDuplicates ETrue if duplicates are to be allowed. |
|
44 * Supported for legacy reasons. |
|
45 */ |
|
46 static CXnDomStringPool* NewL( const TBool aAllowDuplicates = EFalse ); |
|
47 |
|
48 /** |
|
49 * Two-phased stream constructor. |
|
50 * |
|
51 * @param aStream Stream where string pool is internalized. |
|
52 * @param aAllowDuplicates ETrue if duplicates are to be allowed. |
|
53 * Supported for legacy reasons. |
|
54 */ |
|
55 static CXnDomStringPool* NewL( RReadStream& aStream, |
|
56 const TBool aAllowDuplicates = EFalse ); |
|
57 |
|
58 /** |
|
59 * Destructor. |
|
60 */ |
|
61 virtual ~CXnDomStringPool(); |
|
62 |
|
63 public: |
|
64 /** |
|
65 * Make a copy from original StringPool. |
|
66 * @since Series 60 3.1 |
|
67 * @return Pointer to a string pool. Ownership is transferred to a caller. |
|
68 */ |
|
69 CXnDomStringPool* CloneL(); |
|
70 |
|
71 public: //Adding |
|
72 |
|
73 /** |
|
74 * Set dom string into string pool. |
|
75 * |
|
76 * @param aString String to add to string pool |
|
77 * @return Index (reference) to string pool |
|
78 */ |
|
79 TInt AddStringL( const TDesC8& aString ); |
|
80 |
|
81 /** |
|
82 * Set dom string into string pool. |
|
83 * |
|
84 * @param aString String to add to string pool. OWNERSHIP TRANSFERRED! |
|
85 * @return Index (reference) to string pool |
|
86 */ |
|
87 TInt AddStringL( HBufC8* aString ); |
|
88 |
|
89 /** |
|
90 * Add all string from another string pool. |
|
91 * |
|
92 * @param aStringPool Source string pool. |
|
93 */ |
|
94 void AddAllL( CXnDomStringPool& aStringPool ); |
|
95 |
|
96 public: //Accessing |
|
97 /** |
|
98 * Get reference to string. |
|
99 * |
|
100 * @param aMap Map object which has index to name string |
|
101 * @return Pointer to the name |
|
102 */ |
|
103 const TDesC8& String( const TInt aStringRef ); |
|
104 |
|
105 /** |
|
106 * Get object's data size in bytes. |
|
107 * |
|
108 * @return Data size in bytes |
|
109 */ |
|
110 TInt Size() const; |
|
111 |
|
112 /** |
|
113 * Get amount of strings. |
|
114 */ |
|
115 TInt Count() const; |
|
116 |
|
117 /** |
|
118 * Externalize object. |
|
119 * |
|
120 * @param aStream Output stream |
|
121 */ |
|
122 void ExternalizeL( RWriteStream& aStream ) const; |
|
123 |
|
124 /** |
|
125 * Internalize object. |
|
126 * |
|
127 * @param aStream Input stream |
|
128 */ |
|
129 void InternalizeL( RReadStream& aStream ); |
|
130 |
|
131 private: |
|
132 |
|
133 /** |
|
134 * C++ default constructor. |
|
135 * |
|
136 * @param aAllowDuplicates ETrue if duplicates are to be allowed. |
|
137 * Supported for legacy reasons. |
|
138 */ |
|
139 CXnDomStringPool( const TBool aAllowDuplicates ); |
|
140 |
|
141 /** |
|
142 * By default Symbian 2nd phase constructor is private. |
|
143 */ |
|
144 void ConstructL(); |
|
145 |
|
146 /** |
|
147 * Add string to string pool and to optimizer also. |
|
148 * |
|
149 * @param aNewString String to be added. OWNERSHIP TRANSFERRED. |
|
150 * @param TInt Index to added string. |
|
151 */ |
|
152 TInt DoAddStringL( HBufC8* aNewString ) ; |
|
153 |
|
154 private: |
|
155 //String pool |
|
156 RPointerArray<HBufC8> iStringPool; |
|
157 |
|
158 /** |
|
159 * String pool optimizer. |
|
160 */ |
|
161 TXnDomStringPoolOptimizer iStringPoolOptimizer; |
|
162 |
|
163 /** |
|
164 * ETrue if string pool can contain duplicate entries. Must |
|
165 * be supported for legacy reasons while loading xuikon odts. |
|
166 */ |
|
167 TBool iAllowDuplicates; |
|
168 }; |
|
169 |
|
170 #endif // XN_DOM_STRING_POOL_H |
|
171 |
|
172 // End of File |