|
1 // tregexarg.inl |
|
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_INL_ |
|
37 #define TREGEXARG_INL_ |
|
38 |
|
39 template <class T> |
|
40 class TRegExMatchObject { |
|
41 public: |
|
42 static inline TBool Parse(const TDesC8& aString, TAny* aDestination) { |
|
43 if (aDestination == NULL) return ETrue; |
|
44 T* object = reinterpret_cast<T*>(aDestination); |
|
45 return object->ParseFrom(aString); |
|
46 } |
|
47 }; |
|
48 |
|
49 template <class T> |
|
50 inline TRegExArg::TRegExArg(T* aArg) |
|
51 : iArg(aArg), iParser(TRegExMatchObject<T>::Parse) |
|
52 {} |
|
53 |
|
54 template <TInt S> |
|
55 /*inline TRegExArg::TRegExArg(TBuf8<S>* aArg, Parser aParser) |
|
56 : iArg(aArg), iParser(aParser) |
|
57 {} |
|
58 */ |
|
59 //template <TInt S> |
|
60 inline TRegExArg::TRegExArg(TBuf8<S>* aArg) |
|
61 : iArg(aArg), iParser(ParseNull) |
|
62 {} |
|
63 |
|
64 |
|
65 inline TRegExArg::TRegExArg() : iArg(NULL), iParser(ParseNull) { } |
|
66 |
|
67 inline TRegExArg::TRegExArg(TAny* aArg) : iArg(aArg), iParser(ParseNull) { } |
|
68 |
|
69 inline TBool TRegExArg::Parse(const TDesC8& aString) const |
|
70 { |
|
71 return (*iParser)(aString, iArg); |
|
72 } |
|
73 |
|
74 |
|
75 |
|
76 // This part of the parser, appropriate only for ints, deals with bases |
|
77 #define MAKE_INTEGER_PARSER(type) \ |
|
78 inline TRegExArg Hex(type* aType) { \ |
|
79 return TRegExArg(aType, TRegExArg::Parse ## type ## Hex); } \ |
|
80 inline TRegExArg Octal(type* aType) { \ |
|
81 return TRegExArg(aType, TRegExArg::Parse ## type ## Octal); } |
|
82 |
|
83 MAKE_INTEGER_PARSER(TInt64) |
|
84 MAKE_INTEGER_PARSER(TUint8) |
|
85 MAKE_INTEGER_PARSER(TUint16) |
|
86 MAKE_INTEGER_PARSER(TUint32) |
|
87 MAKE_INTEGER_PARSER(TUint) |
|
88 |
|
89 #undef MAKE_INTEGER_PARSER |
|
90 |
|
91 #endif /* TREGEXARG_INL_ */ |