|
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 * CStifParser. |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifndef STIF_PARSER_H |
|
20 #define STIF_PARSER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <f32file.h> |
|
24 #include <e32std.h> |
|
25 #include <e32base.h> |
|
26 #include "StifSectionParser.h" |
|
27 #include "StifItemParser.h" |
|
28 |
|
29 // CONSTANTS |
|
30 // None |
|
31 |
|
32 // MACROS |
|
33 // None |
|
34 |
|
35 // DATA TYPES |
|
36 // None |
|
37 |
|
38 // FUNCTION PROTOTYPES |
|
39 // None |
|
40 |
|
41 // FORWARD DECLARATIONS |
|
42 class CStifSectionParser; |
|
43 class CStifFileParser; |
|
44 |
|
45 // CLASS DECLARATION |
|
46 |
|
47 // DESCRIPTION |
|
48 // CStifParser is a STIF Test Framework StifParser class. |
|
49 // Class contains a configuration file parsing operations. |
|
50 |
|
51 class CStifParser |
|
52 :public CBase |
|
53 { |
|
54 public: // Enumerations |
|
55 |
|
56 // Indication which type of comments are in use |
|
57 enum TCommentType |
|
58 { |
|
59 ENoComments, // No comments type given, parse all |
|
60 ECStyleComments, // C-style comments( // and /*...*/ ) are |
|
61 // removed |
|
62 }; |
|
63 |
|
64 private: // Enumerations |
|
65 |
|
66 // Indication which mode of parsing are in use |
|
67 enum TParsingMode |
|
68 { |
|
69 EFileParsing, // Indication for file parsing. |
|
70 EBufferParsing, // Indication for buffer parsing. |
|
71 }; |
|
72 |
|
73 public: // Constructors and destructor |
|
74 |
|
75 /** |
|
76 * Two-phased constructor. |
|
77 * Creating parser with path and file information. For default all |
|
78 * information will be parsed(ENoComments). |
|
79 */ |
|
80 IMPORT_C static CStifParser* NewL( const TDesC& aPath, |
|
81 const TDesC& aConfig, |
|
82 TCommentType = ENoComments); |
|
83 |
|
84 /** |
|
85 * Two-phased constructor. |
|
86 * Creating parser with buffer information. For default all |
|
87 * information will be parsed(ENoComments). |
|
88 */ |
|
89 IMPORT_C static CStifParser* NewL( const TDesC& aBuffer, |
|
90 TCommentType = ENoComments ); |
|
91 |
|
92 /** |
|
93 * Destructor. |
|
94 */ |
|
95 IMPORT_C ~CStifParser(); |
|
96 |
|
97 public: // New functions |
|
98 |
|
99 /** |
|
100 * Open and read configuration source and parses a required section. |
|
101 * If start tag is empty the parsing starts beging of the configuration |
|
102 * file. |
|
103 * If end tag is empty the parsing goes end of configuration file. |
|
104 * This method starts always from beginning of configuration file and |
|
105 * parses first section if aSeeked parameters is not given. |
|
106 * If configuration file includes several sections with both start and |
|
107 * end tags so aSeeked parameter seeks the required section. The aSeeked |
|
108 * parameters indicates section that will be parsed. |
|
109 */ |
|
110 IMPORT_C CStifSectionParser* SectionL( const TDesC& aStartTag, |
|
111 const TDesC& aEndTag, |
|
112 TInt aSeeked = 1 ); |
|
113 |
|
114 /** |
|
115 * Open and read configuration source and parses a required section. |
|
116 * If start tag is empty the parsing starts beging of the configuration |
|
117 * file. |
|
118 * If end tag is empty the parsing goes end of configuration file. |
|
119 * This method will parse next section after the earlier section if |
|
120 * aSeeked parameter is not given. |
|
121 * If configuration file includes several sections with both start and |
|
122 * end tags so aSeeked parameter seeks the required section. The aSeeked |
|
123 * parameters indicates section that will be parsed. |
|
124 */ |
|
125 IMPORT_C CStifSectionParser* NextSectionL( const TDesC& aStartTag, |
|
126 const TDesC& aEndTag, |
|
127 TInt aSeeked = 1 ); |
|
128 |
|
129 public: // Functions from base classes |
|
130 |
|
131 protected: // New functions |
|
132 |
|
133 protected: // Functions from base classes |
|
134 |
|
135 private: |
|
136 |
|
137 /** |
|
138 * C++ default constructor. |
|
139 */ |
|
140 CStifParser( TCommentType aCommentType ); |
|
141 |
|
142 /** |
|
143 * By default Symbian OS constructor is private. |
|
144 */ |
|
145 void ConstructL( const TDesC& aPath, |
|
146 const TDesC& aConfig, |
|
147 const TDesC& aContent = KNullDesC ); |
|
148 |
|
149 /** |
|
150 * Convert a section without comments. |
|
151 */ |
|
152 void ParseCommentsOff( TPtr& aBuf ); |
|
153 |
|
154 // |
|
155 // Handles special marks.( '\/\/', '\/\*' and '*/\/' ). This |
|
156 // is used when ECStyleComments comment type is used. |
|
157 // |
|
158 void HandleSpecialMarks( TPtr& aBuf ); |
|
159 |
|
160 /** |
|
161 * Open and read configuration source and parses a required section. |
|
162 * If start tag is empty the parsing starts beging of the configuration |
|
163 * file. |
|
164 * If end tag is empty the parsing goes end of configuration file. |
|
165 * This method will parse next section after the earlier section if |
|
166 * aSeeked parameter is not given. |
|
167 * If configuration file includes several sections with both start and |
|
168 * end tags so aSeeked parameter seeks the required section. The aSeeked |
|
169 * parameters indicates section that will be parsed. |
|
170 */ |
|
171 CStifSectionParser *NextSectionMemoryL( const TDesC& aStartTag, |
|
172 const TDesC& aEndTag, |
|
173 TInt aSeeked ); |
|
174 |
|
175 /** |
|
176 * Open and read configuration source and parses a required section. |
|
177 * If start tag is empty the parsing starts beging of the configuration |
|
178 * file. |
|
179 * If end tag is empty the parsing goes end of configuration file. |
|
180 * This method will parse next section after the earlier section if |
|
181 * aSeeked parameter is not given. |
|
182 * If configuration file includes several sections with both start and |
|
183 * end tags so aSeeked parameter seeks the required section. The aSeeked |
|
184 * parameters indicates section that will be parsed. |
|
185 */ |
|
186 CStifSectionParser *NextSectionFileL( const TDesC& aStartTag, |
|
187 const TDesC& aEndTag, |
|
188 TInt aSeeked ); |
|
189 public: // Data |
|
190 |
|
191 protected: // Data |
|
192 |
|
193 private: // Data |
|
194 |
|
195 /** |
|
196 * For file opening. |
|
197 */ |
|
198 RFs iFileServer; |
|
199 |
|
200 /** |
|
201 * For file opening. |
|
202 */ |
|
203 RFile iFile; |
|
204 |
|
205 /** |
|
206 * Indicates position where we are currently. |
|
207 */ |
|
208 TInt iOffset; |
|
209 |
|
210 /** |
|
211 * Comment type's indication. |
|
212 */ |
|
213 TCommentType iCommentType; |
|
214 |
|
215 /** |
|
216 * Indication which mode of parsing are in use. |
|
217 */ |
|
218 TParsingMode iParsingMode; |
|
219 |
|
220 /** |
|
221 * For buffer parsing. |
|
222 */ |
|
223 HBufC* iBufferTmp; |
|
224 TPtr iBuffer; |
|
225 |
|
226 /** |
|
227 * Flag indicating if file is unicode. |
|
228 */ |
|
229 TBool iIsUnicode; |
|
230 |
|
231 /** |
|
232 * Pointer to file parser. |
|
233 */ |
|
234 CStifFileParser* iFileParser; |
|
235 |
|
236 public: // Friend classes |
|
237 |
|
238 protected: // Friend classes |
|
239 |
|
240 private: // Friend classes |
|
241 |
|
242 }; |
|
243 |
|
244 #endif // STIF_PARSER_H |
|
245 |
|
246 // End of File |