|
1 /* |
|
2 * Copyright (c) 2009 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: This file contains the header file of the |
|
15 * CStifItemParser. |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifndef STIF_ITEM_PARSER_H |
|
20 #define STIF_ITEM_PARSER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <f32file.h> |
|
24 #include <e32std.h> |
|
25 #include <e32base.h> |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KMaxTag = 256; // A tag maximum length |
|
29 |
|
30 // MACROS |
|
31 // None |
|
32 |
|
33 // DATA TYPES |
|
34 // None |
|
35 |
|
36 // FUNCTION PROTOTYPES |
|
37 // None |
|
38 |
|
39 // FORWARD DECLARATIONS |
|
40 // None |
|
41 |
|
42 // CLASS DECLARATION |
|
43 |
|
44 // DESCRIPTION |
|
45 // CStifItemParser is a STIF Test Framework StifParser class. |
|
46 // Class contains a configuration file parsing operations. |
|
47 |
|
48 class CStifItemParser |
|
49 :public CBase |
|
50 { |
|
51 public: // Enumerations |
|
52 |
|
53 // Parsing type can be given when parsing string(GetString and |
|
54 // GetNextString). This enumeration indicates parsing type. |
|
55 // ENormalParsing: |
|
56 // - Indicates normal parsing without any modifications to |
|
57 // parsed information |
|
58 // EQuoteStyleParsing: |
|
59 // - Indicates special parsing. This style of parsing gives to |
|
60 // quote(" ") characters special meaning. |
|
61 // - Information between quotes is handled as a one string. Quotes |
|
62 // not included to information. |
|
63 enum TParsingType |
|
64 { |
|
65 ENormalParsing, // Mode on(Default) |
|
66 EQuoteStyleParsing, // Mode off |
|
67 }; |
|
68 |
|
69 private: // Enumerations |
|
70 |
|
71 public: // Constructors and destructor |
|
72 |
|
73 /** |
|
74 * Two-phased constructor. |
|
75 */ |
|
76 IMPORT_C static CStifItemParser* NewL( TPtrC aSection, |
|
77 TInt aStartPos, |
|
78 TInt aLength ); |
|
79 |
|
80 /** |
|
81 * Destructor. |
|
82 */ |
|
83 ~CStifItemParser(); |
|
84 |
|
85 public: // New functions |
|
86 |
|
87 /** |
|
88 * Get a string with a tag. |
|
89 * Returns an error code and a reference to the parsed string. |
|
90 *If start tag is empty the first string will be parsed and returned. |
|
91 */ |
|
92 IMPORT_C TInt GetString( const TDesC& aTag, TPtrC& aString ); |
|
93 |
|
94 /** |
|
95 * Get next string. |
|
96 * Returns an error code and a reference to the parsed string. |
|
97 * GetString or GetInt or GetChar must be called before call |
|
98 * GetNextString method. |
|
99 */ |
|
100 IMPORT_C TInt GetNextString( TPtrC& aString ); |
|
101 |
|
102 /** |
|
103 * Get next string with a tag. |
|
104 * Returns an error code and a reference to the parsed string. |
|
105 * If start tag is empty the next string will be parsed and returned. |
|
106 * GetString or GetInt or GetChar must be called before call |
|
107 * GetNextString method. |
|
108 */ |
|
109 IMPORT_C TInt GetNextString( const TDesC& aTag, TPtrC& aString ); |
|
110 |
|
111 /** |
|
112 * Get a integer(TInt) with a tag. |
|
113 * Returns an error code and a reference to the parsed integer. |
|
114 * If start tag is empty the first integer will be parsed and returned. |
|
115 */ |
|
116 IMPORT_C TInt GetInt( const TDesC& aTag, TInt& aInteger ); |
|
117 |
|
118 /** |
|
119 * Get next integer(TInt). |
|
120 * Returns an error code and a reference to the parsed integer. |
|
121 * GetString or GetInt or GetChar must be called before call |
|
122 * GetNextInt method. |
|
123 */ |
|
124 IMPORT_C TInt GetNextInt( TInt& aInteger ); |
|
125 |
|
126 /** |
|
127 * Get next integer(TInt) with a tag. |
|
128 * Returns an error code and a reference to the parsed integer. |
|
129 * If start tag is empty the next integer will be parsed and returned. |
|
130 * GetString or GetInt or GetChar must be called before call |
|
131 * GetNextInt method. |
|
132 */ |
|
133 IMPORT_C TInt GetNextInt( const TDesC& aTag, TInt& aInteger ); |
|
134 |
|
135 /** |
|
136 * Get a integer(TUint) with a tag. |
|
137 * Returns an error code and a reference to the parsed integer. |
|
138 * If start tag is empty the first integer will be parsed and returned. |
|
139 * With TRadix parameter can convert a number into different |
|
140 * presentation(EBinary, EOctal, EDecimal and EHex). |
|
141 */ |
|
142 IMPORT_C TInt GetInt( const TDesC& aTag, |
|
143 TUint& aInteger, |
|
144 TRadix aRadix = EDecimal ); |
|
145 |
|
146 /** |
|
147 * Get next integer(TUint). |
|
148 * Returns an error code and a reference to the parsed integer. |
|
149 * GetString or GetInt or GetChar must be called before call |
|
150 * GetNextInt method. |
|
151 * With TRadix parameter can convert a number into different |
|
152 * presentation(EBinary, EOctal, EDecimal and EHex). |
|
153 */ |
|
154 IMPORT_C TInt GetNextInt( TUint& aInteger, |
|
155 TRadix aRadix = EDecimal ); |
|
156 |
|
157 /** |
|
158 * Get next integer(TUint) with a tag. |
|
159 * Returns an error code and a reference to the parsed integer. |
|
160 * If start tag is empty the next integer will be parsed and returned. |
|
161 * GetString or GetInt or GetChar must be called before call |
|
162 * GetNextInt method. |
|
163 * With TRadix parameter can convert a number into different |
|
164 * presentation(EBinary, EOctal, EDecimal and EHex). |
|
165 */ |
|
166 IMPORT_C TInt GetNextInt( const TDesC& aTag, |
|
167 TUint& aInteger, |
|
168 TRadix aRadix = EDecimal ); |
|
169 |
|
170 /** |
|
171 * Get a character with a tag. |
|
172 * Returns an error code and a reference to the parsed character. |
|
173 * If start tag is empty the first character will be parsed and |
|
174 * returned. |
|
175 */ |
|
176 IMPORT_C TInt GetChar( const TDesC& aTag, TChar& aCharacter ); |
|
177 |
|
178 /** |
|
179 * Get next character. |
|
180 * Returns an error code and a reference to the parsed character. |
|
181 * GetString or GetInt or GetChar must be called before call |
|
182 * GetNextChar method. |
|
183 */ |
|
184 IMPORT_C TInt GetNextChar( TChar& aCharacter ); |
|
185 |
|
186 /** |
|
187 * Get next character with a tag. |
|
188 * Returns an error code and a reference to the parsed character. |
|
189 * If start tag is empty the next character will be parsed and returned. |
|
190 * GetString or GetInt or GetChar must be called before call |
|
191 * GetNextChar method. |
|
192 */ |
|
193 IMPORT_C TInt GetNextChar( const TDesC& aTag, TChar& aCharacter ); |
|
194 |
|
195 |
|
196 /** |
|
197 * Get remaining strings. |
|
198 * Returns an error code and a reference to the remainder of the |
|
199 * parsed line. |
|
200 * Note: This method does not support the quote(TParsingType) feature, |
|
201 * only GetString and GetNextString methods include support. |
|
202 */ |
|
203 IMPORT_C TInt Remainder( TPtrC& aString ); |
|
204 |
|
205 /** |
|
206 * Parsing type can be given when parsing string(GetString and |
|
207 * GetNextString). See TParsingType enumeration for more |
|
208 * inforamtion. |
|
209 */ |
|
210 IMPORT_C TInt SetParsingType( CStifItemParser::TParsingType aType ); |
|
211 |
|
212 /** |
|
213 * Get current parsing type. Please see TParsingType enumeration for |
|
214 * more inforamtion. |
|
215 */ |
|
216 IMPORT_C CStifItemParser::TParsingType ParsingType(); |
|
217 |
|
218 public: // Functions from base classes |
|
219 |
|
220 protected: // New functions |
|
221 |
|
222 protected: // Functions from base classes |
|
223 |
|
224 private: |
|
225 |
|
226 /** |
|
227 * C++ default constructor. |
|
228 */ |
|
229 CStifItemParser( TPtrC aSection, |
|
230 TInt aStartPos, |
|
231 TInt aLength ); |
|
232 |
|
233 /** |
|
234 * By default Symbian OS constructor is private. |
|
235 */ |
|
236 void ConstructL(); |
|
237 |
|
238 /** |
|
239 * Generig start and end position parser for given data. |
|
240 * Returns an error code. |
|
241 */ |
|
242 TInt ParseStartAndEndPos( TPtrC aSection, |
|
243 const TDesC& aStartTag, |
|
244 TInt& aStartPos, |
|
245 TInt& aEndPos, |
|
246 TInt& aLength, |
|
247 TInt& aExtraEndPos ); |
|
248 |
|
249 public: // Data |
|
250 |
|
251 protected: // Data |
|
252 |
|
253 private: // Data |
|
254 |
|
255 /** |
|
256 * Parsed section with GetItemLineL() or GetNextItemLineL() method. |
|
257 */ |
|
258 TPtrC iItemLineSection; |
|
259 |
|
260 /** |
|
261 * Indicates position where start the parsing. |
|
262 */ |
|
263 TInt iItemSkipAndMarkPos; |
|
264 |
|
265 /** |
|
266 * Indicator is GetString(), GetInt() or GetChar() called. |
|
267 */ |
|
268 TBool iGetMethodsIndicator; |
|
269 |
|
270 /** |
|
271 * Parsing type indicator for GetString and GetNextString use. |
|
272 */ |
|
273 CStifItemParser::TParsingType iParsingType; |
|
274 |
|
275 public: // Friend classes |
|
276 |
|
277 /** |
|
278 * For testing operations to get length information. |
|
279 */ |
|
280 friend class CTestParser; |
|
281 |
|
282 protected: // Friend classes |
|
283 |
|
284 private: // Friend classes |
|
285 |
|
286 }; |
|
287 |
|
288 #endif // STIF_ITEM_PARSER_H |
|
289 |
|
290 // End of File |