stif/Parser/inc/StifFileParser.h
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     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 CStifFileParser.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef STIF_FILE_PARSER_H
       
    19 #define STIF_FILE_PARSER_H
       
    20 
       
    21 //  INCLUDES
       
    22 #include <f32file.h>
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 #include "cstackdeprecated.h"
       
    26 #include <StifTestModule.h>
       
    27 #include "StifParser.h"
       
    28 
       
    29 // CONSTANTS
       
    30 _LIT(KIncludeKeyword, "INCLUDE");
       
    31 
       
    32 // MACROS
       
    33 // None
       
    34 
       
    35 // DATA TYPES
       
    36 // None
       
    37 
       
    38 // FUNCTION PROTOTYPES
       
    39 // None
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 // None
       
    43 
       
    44 // CLASS DECLARATION
       
    45 
       
    46 // DESCRIPTION
       
    47 // CStifFileParser is a STIF Test Framework StifParser class.
       
    48 // Class contains a configuration file parsing operations without loading it into memory.
       
    49 
       
    50 
       
    51 NONSHARABLE_CLASS (CStifFileParser) : public CBase
       
    52 {
       
    53     public:     // Enumerations
       
    54 		// Indication what kind of char sequence is to be found
       
    55         enum TWhatToFind
       
    56       	{
       
    57         	EStart,             // '//' or '/*' or '"' signs
       
    58         	EQuota,             // '"' sign
       
    59         	EEndOfComment       // '*/' sequence
       
    60     	};
       
    61 
       
    62 		// Indication if beginning or end of section is to be found
       
    63         enum TSectionFind
       
    64         {
       
    65         	ESectionStart,
       
    66         	ESectionEnd
       
    67         };
       
    68 
       
    69     private:    // Enumerations
       
    70 
       
    71     public:     // Constructors and destructor
       
    72 
       
    73         /**
       
    74         * Two-phased constructor.
       
    75         * Creating parser with given handle to file. For default all
       
    76         * information will be parsed(ENoComments).
       
    77         */
       
    78         static CStifFileParser* NewL(RFs& aFs,
       
    79                                      RFile &aFile,
       
    80                                      TBool aIsUnicode,
       
    81                                      CStifParser::TCommentType aCommentType = CStifParser::ENoComments);
       
    82 
       
    83         /**
       
    84         * Destructor.
       
    85         */
       
    86         ~CStifFileParser();
       
    87 
       
    88     public:     // New functions
       
    89 
       
    90         /**
       
    91         * Open and read configuration source and parses a required section.
       
    92         * This method will parse next section after the earlier section if
       
    93         * aSeeked parameter is equal 1.
       
    94         * If configuration file includes several sections with both start and
       
    95         * end tags so aSeeked parameter seeks the required section. The aSeeked
       
    96         * parameters indicates section that will be parsed.
       
    97         * If start tag is not given, returned section begins from the beginning of
       
    98         * the file. If end tag is not given, returned sections ends at the end of
       
    99         * the file.
       
   100         * If section is not found and first occurence of section is seeked, function
       
   101         * will return NULL, but if second (or further) occurence is seeked, function
       
   102         * will leave with KErrNotFound (for compability with CStifParser::NextSectionL
       
   103 		* reason).
       
   104         */
       
   105 		HBufC* NextSectionL(const TDesC& aStartTag,
       
   106                             const TDesC& aEndTag,
       
   107                             TInt& aOffset,
       
   108                             TInt aSeeked = 1);
       
   109 
       
   110     public:     // Functions from base classes
       
   111 
       
   112     protected:  // New functions
       
   113 
       
   114     protected:  // Functions from base classes
       
   115 
       
   116     private:
       
   117 
       
   118         /**
       
   119         * C++ default constructor.
       
   120         */
       
   121         CStifFileParser(CStifParser::TCommentType aCommentType);
       
   122 
       
   123         /**
       
   124         * By default Symbian OS constructor is private.
       
   125         */
       
   126         void ConstructL(RFs& aFs,
       
   127                         RFile &aFile,
       
   128                         TBool aIsUnicode);
       
   129 
       
   130         /**
       
   131         * Reads configuration source and returns a complete line.
       
   132         * This method will return also and end of line sequence.
       
   133         */
       
   134 		TBool ReadLineL(TPtr& aLineBuffer,
       
   135 		                TPtr& aEndOfLineBuffer);
       
   136 
       
   137         /**
       
   138         * Parses a given line and removes all c-style comments from it (and #-style comments).
       
   139         * Result is passed in destination buffer.
       
   140         */
       
   141 		void ReplaceCommentsLineL(TPtr& aSrcBufPtr,
       
   142 		                          TPtr& aDstBufPtr,
       
   143 								  TWhatToFind& aFind);
       
   144 
       
   145         /**
       
   146         * Parses a given line and removes all #-style comments.
       
   147         * Result is passed in destination buffer.
       
   148         */
       
   149 	 	void ReplaceHashCommentsLineL(TPtr& aSrcBufPtr,
       
   150  	                                  TPtr& aDstBufPtr);
       
   151 
       
   152         /**
       
   153         * Closes all files on file stack and clears the stack.
       
   154         */
       
   155  	    void ClearFileStack(void);
       
   156 
       
   157         /**
       
   158         * Pops RFile handle from file stack and sets correct current file handle.
       
   159         */
       
   160         void PopFromFileStack(void);
       
   161 
       
   162         /**
       
   163         * Opens file and pushes it to stack.
       
   164         */
       
   165         void PushFileToStackL(const TDesC& aFileName);
       
   166 
       
   167         /**
       
   168         * Deletes all descriptors assigned to array and empties array.
       
   169         */
       
   170         void ClearSectionLinesArray(void);
       
   171 
       
   172     public:     // Data
       
   173 
       
   174     protected:  // Data
       
   175 
       
   176     private:    // Data
       
   177 
       
   178         /**
       
   179         * For file opening.
       
   180         */
       
   181         RFs         iFileServer;
       
   182 
       
   183         /**
       
   184         * For file opening. This is the first (base) file. Later other files may be opened if
       
   185         * they are included to base one.
       
   186         */
       
   187         RFile       iBaseFile;
       
   188 
       
   189         /**
       
   190         * Comment type's indication.
       
   191         */
       
   192         CStifParser::TCommentType iCommentType;
       
   193 
       
   194         /**
       
   195         * Flag indicating if file is unicode.
       
   196         */
       
   197         TBool       iIsUnicode;
       
   198         
       
   199         /**
       
   200         * How many bytes per char in file (2 for unicode, 1 for non-unicode).
       
   201         */
       
   202         TInt 		iBytesPerChar;
       
   203         
       
   204         /**
       
   205         * Handle to file which is currently read.
       
   206         */
       
   207         RFile*      iCurrentFile;
       
   208 
       
   209         /**
       
   210         * Stack of opened files (it does not contain base file).
       
   211         */
       
   212         CStackDeprecated<RFile, EFalse>* iFileStack;
       
   213 
       
   214         /**
       
   215         * Array of lines belonging to seeked section.
       
   216         */
       
   217 		RPointerArray<HBufC> iSectionLines;
       
   218 
       
   219 		/**
       
   220 		* Array of already included files (to avoid loop in includes).
       
   221 		*/
       
   222 		RPointerArray<HBufC> iFileNames;
       
   223 
       
   224 		/**
       
   225 		* Buffer with eol sequence. Filled when include found and used after last line of inlcuded file.
       
   226 		*/
       
   227 		TBuf<2>     iEolBuf;
       
   228 
       
   229     public:     // Friend classes
       
   230 
       
   231     protected:  // Friend classes
       
   232 
       
   233     private:    // Friend classes
       
   234 };
       
   235 
       
   236 #endif      // STIF_FILE_PARSER_H
       
   237 
       
   238 // End of File