libraries/spcre/inc/tregexarg.h
changeset 0 7f656887cf89
child 9 257450419d10
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // tregexarg.h
       
     2 //
       
     3 // Copyright (c) 2005 - 2006, Google Inc.
       
     4 // All rights reserved.
       
     5 //
       
     6 // Redistribution and use in source and binary forms, with or without
       
     7 // modification, are permitted provided that the following conditions are
       
     8 // met:
       
     9 //
       
    10 //     * Redistributions of source code must retain the above copyright
       
    11 // notice, this list of conditions and the following disclaimer.
       
    12 //     * Redistributions in binary form must reproduce the above
       
    13 // copyright notice, this list of conditions and the following disclaimer
       
    14 // in the documentation and/or other materials provided with the
       
    15 // distribution.
       
    16 //     * Neither the name of Google Inc. nor the names of its
       
    17 // contributors may be used to endorse or promote products derived from
       
    18 // this software without specific prior written permission.
       
    19 //
       
    20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    31 //
       
    32 // Author: Sanjay Ghemawat
       
    33 //
       
    34 // Heavily refactored for Symbian OS by Accenture.
       
    35 
       
    36 #ifndef TREGEXARG_H_
       
    37 #define TREGEXARG_H_
       
    38 
       
    39 #include <e32base.h>
       
    40 
       
    41 class TRegExArg
       
    42 	{
       
    43  public:
       
    44 	 // Empty constructor so we can declare arrays of TRegExArg
       
    45 	  TRegExArg();
       
    46 
       
    47 	 // Constructor specially designed for NULL arguments
       
    48 	 inline TRegExArg(TAny*);
       
    49 
       
    50 	 typedef TBool (*Parser)(const TDesC8& aString, TAny* aDestination);
       
    51 	 
       
    52 // Type-specific parsers
       
    53 #define PCRE_MAKE_PARSER(type,name)															\
       
    54 	IMPORT_C TRegExArg(type* aType) : iArg(aType), iParser(name) { }						\
       
    55 	IMPORT_C TRegExArg(type* aType, Parser aParser) : iArg(aType), iParser(aParser) { }	
       
    56 	
       
    57 	PCRE_MAKE_PARSER(TChar,				ParseTChar)
       
    58 	PCRE_MAKE_PARSER(TInt8,				ParseTInt8)
       
    59 	PCRE_MAKE_PARSER(TInt16,			ParseTInt16)
       
    60 	PCRE_MAKE_PARSER(TInt32,			ParseTInt32)
       
    61 	PCRE_MAKE_PARSER(TInt64,			ParseTInt64)
       
    62 	PCRE_MAKE_PARSER(TInt,				ParseTInt)
       
    63 	PCRE_MAKE_PARSER(TUint8,			ParseTUint8)
       
    64 	PCRE_MAKE_PARSER(TUint16,			ParseTUint16)
       
    65 	PCRE_MAKE_PARSER(TUint32,			ParseTUint32)
       
    66 	PCRE_MAKE_PARSER(TUint,				ParseTUint)
       
    67 	PCRE_MAKE_PARSER(TReal32,			ParseTReal32)
       
    68 	PCRE_MAKE_PARSER(TReal64,			ParseTReal64)
       
    69 	PCRE_MAKE_PARSER(TDes8,				ParseTDes8)
       
    70 	PCRE_MAKE_PARSER(TPtrC8,			ParseTPtrC8)
       
    71 	
       
    72 	#undef PCRE_MAKE_PARSER
       
    73 
       
    74 	// Generic constructors
       
    75 	template <class T> inline TRegExArg(T*, Parser aParser);
       
    76 	template <class T> inline TRegExArg(T* aArg);	
       
    77 	
       
    78 	// TBuf constructors - cannot seem to nest the template parameters
       
    79 	template <TInt S>
       
    80 	inline TRegExArg(TBuf8<S>* aArg, Parser aParser);
       
    81 	template <TInt S>
       
    82 	inline TRegExArg(TBuf8<S>* aArg);
       
    83 	
       
    84 	// Parse the data
       
    85 	inline TBool Parse(const TDesC8& aString) const;
       
    86 
       
    87 private:
       
    88 	TAny*         iArg;
       
    89 	Parser        iParser; // Pointer to parsing function
       
    90 	
       
    91 	IMPORT_C static TBool ParseNull			(const TDesC8& aString, TAny* aDestination);
       
    92 	IMPORT_C static TBool ParseTChar		(const TDesC8& aString, TAny* aDestination);
       
    93 	IMPORT_C static TBool ParseTInt8		(const TDesC8& aString, TAny* aDestination);
       
    94 	IMPORT_C static TBool ParseTInt16		(const TDesC8& aString, TAny* aDestination);
       
    95 	IMPORT_C static TBool ParseTInt32		(const TDesC8& aString, TAny* aDestination);
       
    96 	IMPORT_C static TBool ParseTInt			(const TDesC8& aString, TAny* aDestination);
       
    97 	IMPORT_C static TBool ParseTReal32		(const TDesC8& aString, TAny* aDestination);
       
    98 	IMPORT_C static TBool ParseTReal64		(const TDesC8& aString, TAny* aDestination); 
       
    99 	IMPORT_C static TBool ParseTDes8		(const TDesC8& aString, TAny* aDestination);
       
   100 	IMPORT_C static TBool ParseTDes16		(const TDesC8& aString, TAny* aDestination);
       
   101 	IMPORT_C static TBool ParseTPtrC8		(const TDesC8& aString, TAny* aDestination);
       
   102 
       
   103 #define PCRE_DECLARE_INTEGER_PARSER(name)															\
       
   104 private:																							\
       
   105 	IMPORT_C static TBool Parse ## name(const TDesC8& aString, TAny* aDestination);					\
       
   106 	IMPORT_C static TBool Parse ## name ## Radix(													\
       
   107 				const TDesC8& aString, TAny* aDestination, TRadix aRadix);							\
       
   108 public:																								\
       
   109 	IMPORT_C static TBool Parse ## name ## Hex(const TDesC8& aString, TAny* aDestination);			\
       
   110 	IMPORT_C static TBool Parse ## name ## Octal(const TDesC8& aString, TAny* aDestination);		\
       
   111 
       
   112 	PCRE_DECLARE_INTEGER_PARSER(TInt64)
       
   113 	PCRE_DECLARE_INTEGER_PARSER(TUint8)
       
   114 	PCRE_DECLARE_INTEGER_PARSER(TUint16)
       
   115 	PCRE_DECLARE_INTEGER_PARSER(TUint32)
       
   116 	PCRE_DECLARE_INTEGER_PARSER(TUint)	
       
   117 
       
   118 #undef PCRE_DECLARE_INTEGER_PARSER
       
   119 	};
       
   120 
       
   121 #include "tregexarg.inl"
       
   122 
       
   123 #endif /* TREGEXARG_H_ */