|
1 /* |
|
2 * Copyright (c) 2002 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: Argument parser |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CARGS_H |
|
21 #define CARGS_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 |
|
26 // CONSTANTS |
|
27 const TInt KMaxArgs = 100; |
|
28 |
|
29 // MACROS |
|
30 // none |
|
31 |
|
32 // DATA TYPES |
|
33 enum TParseType |
|
34 { |
|
35 // class.method (arg1, arg2, ...) |
|
36 // functionname (arg1, arg2, ...) |
|
37 // |
|
38 // classname is always found from StrArg(1) (if only funcname provided, "") |
|
39 // method/functonname is always found from StrArg(2) |
|
40 // |
|
41 EParseFunction, |
|
42 |
|
43 // // comment here |
|
44 // |
|
45 EParseComment |
|
46 }; |
|
47 |
|
48 enum TArgType |
|
49 { |
|
50 EArgNotSpecified, |
|
51 EArgNum, |
|
52 EArgStr |
|
53 }; |
|
54 |
|
55 // FUNCTION PROTOTYPES |
|
56 // none |
|
57 |
|
58 // FORWARD DECLARATIONS |
|
59 // none |
|
60 |
|
61 // CLASS DECLARATION |
|
62 |
|
63 /** |
|
64 * CArgs is used to parse parameters from a data file |
|
65 * |
|
66 * @lib commonutils.lib |
|
67 * @since |
|
68 */ |
|
69 class CArgs : public CBase |
|
70 { |
|
71 public: // Constructors and destructor |
|
72 |
|
73 /** |
|
74 * C++ default constructor. |
|
75 */ |
|
76 IMPORT_C CArgs(); |
|
77 |
|
78 /** |
|
79 * Destructor. |
|
80 */ |
|
81 IMPORT_C ~CArgs(); |
|
82 |
|
83 public: // New functions |
|
84 |
|
85 /** |
|
86 * Returns count of parsed arguments. |
|
87 * @since |
|
88 * @return Count of parsed arguments |
|
89 */ |
|
90 IMPORT_C TInt ArgCount() const; |
|
91 |
|
92 /** |
|
93 * Returns type of argument (string/numeric). |
|
94 * @since |
|
95 * @param aArgIndex Index of argument |
|
96 * @return Type of argument |
|
97 */ |
|
98 IMPORT_C TArgType ArgType( const TInt aArgIndex ) const; |
|
99 |
|
100 /** |
|
101 * Returns argument value as TInt |
|
102 * @since |
|
103 * @param aArgIndex Index of argument |
|
104 * @return Integer value of argument |
|
105 */ |
|
106 IMPORT_C TInt NumArg( const TInt aArgIndex ) const; |
|
107 |
|
108 /** |
|
109 * Returns argument value as String |
|
110 * @since |
|
111 * @param aArgIndex Index of argument |
|
112 * @return Argument as String |
|
113 */ |
|
114 IMPORT_C const TDesC& StrArg( const TInt aArgIndex ) const; |
|
115 |
|
116 /** |
|
117 * Parses arguments from a string |
|
118 * @since |
|
119 * @param aType Type of argument |
|
120 * @param aLine Line to parse |
|
121 * @return Errorcode |
|
122 */ |
|
123 IMPORT_C TInt ParseLineL( const TParseType aType, const TDes& aLine ); |
|
124 |
|
125 public: // Functions from base classes |
|
126 // none |
|
127 |
|
128 protected: // New functions |
|
129 // none |
|
130 |
|
131 protected: // Functions from base classes |
|
132 // none |
|
133 |
|
134 private: |
|
135 |
|
136 /** |
|
137 * Clears all parsed arguments and frees allocated memory |
|
138 * @since |
|
139 */ |
|
140 void ClearArgs(); |
|
141 |
|
142 public: // Data |
|
143 // none |
|
144 |
|
145 protected: // Data |
|
146 // none |
|
147 |
|
148 private: // Data |
|
149 |
|
150 // Argument count |
|
151 TInt iArgCount; |
|
152 |
|
153 // Array for arguments revealing the type of argument |
|
154 TArgType iArgType[KMaxArgs]; |
|
155 |
|
156 // Array for numeric arguments |
|
157 TInt iNumArg[KMaxArgs]; |
|
158 |
|
159 // Array for string arguments |
|
160 HBufC* iStrArg[KMaxArgs]; |
|
161 |
|
162 public: // Friend classes |
|
163 // none |
|
164 |
|
165 protected: // Friend classes |
|
166 // none |
|
167 |
|
168 private: // Friend classes |
|
169 // none |
|
170 |
|
171 }; |
|
172 |
|
173 #endif // CARGS_H |
|
174 |
|
175 // End of File |