testexecfw/stf/api/api_platform/inc/StifItemParser.h
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     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         /**
       
   219          * Get key-value pair. 
       
   220          * 
       
   221          */
       
   222         IMPORT_C  TInt GetValueOf(const TDesC& aKey, TDes& aValue);
       
   223 
       
   224     public:     // Functions from base classes
       
   225 
       
   226     protected:  // New functions
       
   227 
       
   228     protected:  // Functions from base classes
       
   229 
       
   230     private:
       
   231 
       
   232         /**
       
   233         * C++ default constructor.
       
   234         */
       
   235         CStifItemParser( TPtrC aSection,
       
   236                             TInt aStartPos,
       
   237                             TInt aLength );
       
   238 
       
   239         /**
       
   240         * By default Symbian OS constructor is private.
       
   241         */
       
   242         void ConstructL();
       
   243 
       
   244         /**
       
   245         * Generig start and end position parser for given data.
       
   246         * Returns an error code.
       
   247         */
       
   248         TInt ParseStartAndEndPos( TPtrC aSection,
       
   249                                     const TDesC& aStartTag,
       
   250                                     TInt& aStartPos,
       
   251                                     TInt& aEndPos,
       
   252                                     TInt& aLength,
       
   253                                     TInt& aExtraEndPos );
       
   254 
       
   255     public:     // Data
       
   256 
       
   257     protected:  // Data
       
   258 
       
   259     private:    // Data
       
   260 
       
   261         /**
       
   262         * Parsed section with GetItemLineL() or GetNextItemLineL() method.
       
   263         */
       
   264         TPtrC                           iItemLineSection;
       
   265 
       
   266         /**
       
   267         * Indicates position where start the parsing.
       
   268         */
       
   269         TInt                            iItemSkipAndMarkPos;
       
   270 
       
   271         /**
       
   272         * Indicator is GetString(), GetInt() or GetChar() called.
       
   273         */
       
   274         TBool                           iGetMethodsIndicator;
       
   275 
       
   276         /**
       
   277         * Parsing type indicator for GetString and GetNextString use.
       
   278         */
       
   279         CStifItemParser::TParsingType   iParsingType;
       
   280 
       
   281     public:     // Friend classes
       
   282 
       
   283         /**
       
   284         * For testing operations to get length information.
       
   285         */
       
   286         friend class CTestParser;
       
   287 
       
   288     protected:  // Friend classes
       
   289 
       
   290     private:    // Friend classes
       
   291 
       
   292     };
       
   293 
       
   294 #endif      // STIF_ITEM_PARSER_H
       
   295 
       
   296 // End of File