stif/stif_plat/inc/StifSectionParser.h
branchRCL_3
changeset 59 8ad140f3dd41
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 
       
    15 * CStifSectionParser.
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef STIF_SECTION_PARSER_H
       
    20 #define STIF_SECTION_PARSER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <f32file.h>
       
    24 #include <e32std.h>
       
    25 #include <e32base.h>
       
    26 #include "StifItemParser.h"
       
    27 
       
    28 // CONSTANTS
       
    29 // Indicates is tag included in returned value.
       
    30 enum TTagToReturnValue
       
    31     {
       
    32     ETag,   // Return value includes the tag
       
    33     ENoTag  // Return value include no tag
       
    34     };
       
    35 
       
    36 // MACROS
       
    37 // None
       
    38 
       
    39 // DATA TYPES
       
    40 // None
       
    41 
       
    42 // FUNCTION PROTOTYPES
       
    43 // None
       
    44 
       
    45 // FORWARD DECLARATIONS
       
    46 class CStifItemParser;
       
    47 
       
    48 // CLASS DECLARATION
       
    49 
       
    50 // DESCRIPTION
       
    51 // CStifSectionParser is a STIF Test Framework StifParser class.
       
    52 // Class contains a configuration file parsing operations.
       
    53 
       
    54 class CStifSectionParser 
       
    55         :public CBase
       
    56     {
       
    57     public:     // Enumerations
       
    58 
       
    59     private:    // Enumerations
       
    60 
       
    61     public:     // Constructors and destructor
       
    62 
       
    63         /**
       
    64         * Two-phased constructor.
       
    65         */
       
    66         static CStifSectionParser* NewL( const TInt aLength );
       
    67 
       
    68         /**
       
    69         * Destructor.
       
    70         */
       
    71         ~CStifSectionParser();
       
    72 
       
    73     public:     // New functions
       
    74         
       
    75         /**
       
    76         * Parses a line for items parsing with a tag.
       
    77         * Returns a CStifItemParser object.
       
    78         * If start tag is empty the parsing starts beging of the section.
       
    79         * TTagToReturnValue indicates will also the aTag value (if exist)
       
    80         * include to the returned object(For default the tag will be added).
       
    81         */
       
    82         IMPORT_C CStifItemParser* GetItemLineL( const TDesC& aTag,
       
    83                                 TTagToReturnValue aTagIndicator = ETag );
       
    84 
       
    85         /**
       
    86         * Parses a next line for items parsing.
       
    87         * Returns a CStifItemParser object.
       
    88         */
       
    89         IMPORT_C CStifItemParser* GetNextItemLineL();
       
    90 
       
    91         /**
       
    92         * Parses a next line for items parsing with a tag.
       
    93         * Returns a CStifItemParser object.
       
    94         * If start tag is empty the parsing starts beging of the section.
       
    95         * TTagToReturnValue indicates will also the aTag value (if exist)
       
    96         * include to the returned object(For default the tag will be added).
       
    97         */
       
    98         IMPORT_C CStifItemParser* GetNextItemLineL( const TDesC& aTag,
       
    99                                 TTagToReturnValue aTagIndicator = ETag );
       
   100 
       
   101         /**
       
   102         * Parses a sub sections from the main section with a start and with
       
   103         * a end tag.
       
   104         * Returns a CStifSectionParser object.
       
   105         * If start tag is empty the parsing starts beging of the section.
       
   106         * If end tag is empty the parsing goes end of section.
       
   107         * This method will parse next subsection after the earlier subsection
       
   108         * if aSeeked parameter is not given.
       
   109         * If configuration file includes several subsections with both start
       
   110         * and end tags so aSeeked parameter seeks the required subsection. The
       
   111         * aSeeked parameters indicates subsection that will be parsed.
       
   112         */
       
   113         IMPORT_C CStifSectionParser* SubSectionL( const TDesC& aStartTag,
       
   114                                                     const TDesC& aEndTag,
       
   115                                                     TInt aSeeked = 1 );
       
   116 
       
   117         /**
       
   118         * Parses a next subsections from the main section with a start and with
       
   119         * a end tag.
       
   120         * Returns a CStifSectionParser object.
       
   121         * If start tag is empty the parsing starts beging of the section.
       
   122         * If end tag is empty the parsing goes end of section.
       
   123         * This method will parse next subsection after the earlier subsection
       
   124         * if aSeeked parameter is not given.
       
   125         * If configuration file includes several subsections with both start
       
   126         * and end tags so aSeeked parameter seeks the required subsection. The
       
   127         * aSeeked parameters indicates subsection that will be parsed.
       
   128         */        
       
   129         IMPORT_C CStifSectionParser* NextSubSectionL( const TDesC& aStartTag,
       
   130                                                 const TDesC& aEndTag,
       
   131                                                 TInt aSeeked = 1 );
       
   132 
       
   133         /**
       
   134         * Get a line from section with a tag.
       
   135         * Returns an error code and a reference to the parsed line.
       
   136         * If start tag is empty the parsing starts beging of the section.
       
   137         * TTagToReturnValue indicates will also the aTag value(if exist)
       
   138         * include to the aLine reference(For default the tag will be added).
       
   139         */
       
   140         IMPORT_C TInt GetLine( const TDesC& aTag, TPtrC& aLine, 
       
   141                                 TTagToReturnValue aTagIndicator = ETag );
       
   142 
       
   143         /**
       
   144         * Get next line.
       
   145         * Returns an error code and a reference to the parsed line.
       
   146         */
       
   147         IMPORT_C TInt GetNextLine( TPtrC& aLine );
       
   148 
       
   149         /**
       
   150         * Get next line with tag.
       
   151         * Returns an error code and a reference to the parsed line.
       
   152         * If start tag is empty the parsing starts beging of the section.
       
   153         * TTagToReturnValue indicates will also the aTag value(if exist)
       
   154         * include to the aLine reference(For default the tag will be added).
       
   155         */
       
   156         IMPORT_C TInt GetNextLine( const TDesC& aTag, TPtrC& aLine,
       
   157                                 TTagToReturnValue aTagIndicator = ETag );
       
   158 
       
   159         /**
       
   160         * Get current position.
       
   161         * Returns current parsing position, which
       
   162         * can be used as parameter for SetPosition afterwards to go back
       
   163         * to old parsing position.
       
   164         */
       
   165         IMPORT_C TInt GetPosition();
       
   166         
       
   167         /**
       
   168         * Set position.
       
   169         * Returns a Symbian OS error code. aPos indicates the position to 
       
   170         * which section parser should go.  
       
   171         * SetPosition can be used to set parsing position, e.g. to rewind 
       
   172         * back to some old position retrieved with GetPosition.
       
   173         */
       
   174         IMPORT_C TInt SetPosition( TInt aPos );        
       
   175         
       
   176         /**
       
   177         * Create a section.
       
   178         */
       
   179         void SetData( TPtr aData,
       
   180                         TInt aStartPos, 
       
   181                         TInt aLength );
       
   182 
       
   183         /**
       
   184         * Returns a current section.
       
   185         */
       
   186         const TPtrC Des();
       
   187 
       
   188     public:     // Functions from base classes
       
   189 
       
   190     protected:  // New functions
       
   191 
       
   192     protected:  // Functions from base classes
       
   193 
       
   194     private:
       
   195 
       
   196         /**
       
   197         * C++ default constructor.
       
   198         */
       
   199         CStifSectionParser( const TInt aLength );
       
   200 
       
   201         /**
       
   202         * By default Symbian OS constructor is private.
       
   203         */
       
   204         void ConstructL();
       
   205 
       
   206         /**
       
   207         * Generic start and end position parser for given data.
       
   208         * Returns an error code.
       
   209         */
       
   210         TInt ParseStartAndEndPos(   TPtrC aSection,
       
   211                                     const TDesC& aStartTag,
       
   212                                     TTagToReturnValue aTagIndicator,
       
   213                                     TInt& aStartPos,
       
   214                                     TInt& aEndPos,
       
   215                                     TInt& aLength );
       
   216                                     
       
   217         /**
       
   218         * Generic search for end-of-line.
       
   219         * Returns position before linefeed and 
       
   220         * lex is posotioned to the beginning of next line.
       
   221         */
       
   222         TInt GotoEndOfLine( TLex& lex );                            
       
   223 
       
   224         /**
       
   225         * Substracts line from the begining of selected text.
       
   226         */
       
   227         TPtrC SubstractLine( const TPtrC& aText );
       
   228 		
       
   229 		/**
       
   230 		* Searches for selected tag in a text.
       
   231 		*/		
       
   232         TInt FindTag( const TDesC& aText, const TDesC& aTag, TInt& aStartPos, TInt& aEndPos );
       
   233         
       
   234     public:     // Data
       
   235 
       
   236     protected:  // Data
       
   237 
       
   238     private:    // Data
       
   239 
       
   240         /**
       
   241         * Parsed section with SectionL() or SubSectionL() method.
       
   242         */
       
   243         TPtr                iSection;
       
   244 
       
   245         /**
       
   246         * Section length definitions.
       
   247         */
       
   248         HBufC*              iHBufferSection;
       
   249 
       
   250         /**
       
   251         * Section length
       
   252         */
       
   253         TInt                iLength;
       
   254 
       
   255         /**
       
   256         * Indicates position where start the parsing.
       
   257         */
       
   258         TInt                iSkipAndMarkPos;
       
   259 
       
   260         /**
       
   261         * For line and item line parsing. Indicator is GetLine() or
       
   262         * GetItemLineL() method used.
       
   263         */
       
   264         TBool               iLineIndicator;
       
   265 
       
   266         /**
       
   267         * Indicates position where we are currently(subsection).
       
   268         */
       
   269         TInt                iSubOffset;
       
   270 
       
   271     public:     // Friend classes
       
   272 
       
   273         /**
       
   274         * For testing operations to get length information.
       
   275         */
       
   276         friend class CTestParser;
       
   277 
       
   278     protected:  // Friend classes
       
   279 
       
   280     private:    // Friend classes
       
   281 
       
   282     };
       
   283 
       
   284 #endif      // STIF_SECTION_PARSER_H
       
   285 
       
   286 // End of File