00001 // ============================================================================ 00027 // ============================================================================ 00028 #ifndef CLDAQ__TARGUMENT_HH 00029 #define CLDAQ__TARGUMENT_HH 00030 00031 #include "Tglobals.h" 00032 #include "TOptionTable.hh" 00033 #include "TOptionMap.hh" 00034 00035 00063 class TArgument 00064 { 00065 00066 private: 00067 Tint theNumberOfOriginalArguments; 00068 Tchar** theOriginalArguments; 00069 TOptionTable theOptionTable; 00070 TOptionMap theOptionMap; 00071 Tstring theProgramName; 00072 Tstring theDirectoryName; 00073 TstringList theElements; 00074 Tint theNumberOfElements; 00075 Tstring theUsage; 00076 00077 public: 00078 TArgument( Tint argc, Tchar** argv, const Tstring& usage = "" ); 00079 TArgument( Tint argc, Tchar** argv, const TOptionTable& table, const Tstring& usage = "" ); 00080 ~TArgument(); 00081 00082 public: 00083 Tvoid Analyse(); 00084 Tvoid ShowUsage() const; 00085 Tvoid ShowVersion() const; 00086 Tvoid ShowHelp() const; 00087 00088 public: 00089 Tstring operator[]( Tint index ) const; 00090 Tstring operator[]( const TOption& option ) const; 00091 Tstring operator[]( const Tstring& optionname ) const; 00092 00093 public: 00094 friend Tostream& operator<<( Tostream& tos, const TArgument& right ); 00095 00096 public: 00097 Tint GetNumberOfOriginalArguments() const; 00098 Tchar** GetOriginalArguments() const; 00099 const TOptionTable& GetOptionTable() const; 00100 const TOptionMap& GetOptionMap() const; 00101 const Tstring& GetProgramName() const; 00102 const Tstring& GetDirectoryName() const; 00103 const TstringList& GetElements() const; 00104 Tint GetNumberOfElements() const; 00105 const Tstring& GetUsage() const; 00106 Tvoid SetUsage( const Tstring& usage ); 00107 00108 public: 00109 Tbool HasOption( const TOption& option ) const; 00110 Tbool HasOption( const Tstring& optionname ) const; 00111 Tstring GetParameter( Tint index ) const; 00112 Tstring GetParameter( const Tstring& optionname ) const; 00113 Tstring GetParameter( const TOption& option ) const; 00114 Tint GetIntegerParameter( Tint index ) const; 00115 Tint GetIntegerParameter( const Tstring& optionname ) const; 00116 Tint GetIntegerParameter( const TOption& option ) const; 00117 Tdouble GetDoubleParameter( Tint index ) const; 00118 Tdouble GetDoubleParameter( const Tstring& optionname ) const; 00119 Tdouble GetDoubleParameter( const TOption& option ) const; 00120 TintList GetIntegerElements() const; 00121 TdoubleList GetDoubleElements() const; 00122 Tstring GetElement( Tint index ) const; 00123 Tint GetIntegerElement( Tint index ) const; 00124 Tdouble GetDoubleElement( Tint index ) const; 00125 00126 }; 00127 00128 inline Tint TArgument::GetNumberOfOriginalArguments() const 00129 { 00130 return theNumberOfOriginalArguments; 00131 } 00132 00133 inline Tchar** TArgument::GetOriginalArguments() const 00134 { 00135 return theOriginalArguments; 00136 } 00137 00138 inline const TOptionTable& TArgument::GetOptionTable() const 00139 { 00140 return theOptionTable; 00141 } 00142 00143 inline const TOptionMap& TArgument::GetOptionMap() const 00144 { 00145 return theOptionMap; 00146 } 00147 00148 inline const Tstring& TArgument::GetProgramName() const 00149 { 00150 return theProgramName; 00151 } 00152 00153 inline const Tstring& TArgument::GetDirectoryName() const 00154 { 00155 return theDirectoryName; 00156 } 00157 00158 inline const TstringList& TArgument::GetElements() const 00159 { 00160 return theElements; 00161 } 00162 00163 inline Tint TArgument::GetNumberOfElements() const 00164 { 00165 return theNumberOfElements; 00166 } 00167 00168 inline Tbool TArgument::HasOption( const TOption& option ) const 00169 { 00170 return theOptionMap.HasOption( option ); 00171 } 00172 00173 inline Tbool TArgument::HasOption( const Tstring& optionname ) const 00174 { 00175 return theOptionMap.HasOption( optionname ); 00176 } 00177 00178 inline Tstring TArgument::GetParameter( Tint index ) const 00179 { 00180 return theOptionMap.GetParameter( index ); 00181 } 00182 00183 inline Tstring TArgument::GetParameter( const Tstring& optionname ) const 00184 { 00185 return theOptionMap.GetParameter( optionname ); 00186 } 00187 00188 inline Tstring TArgument::GetParameter( const TOption& option ) const 00189 { 00190 return theOptionMap.GetParameter( option ); 00191 } 00192 00193 inline Tint TArgument::GetIntegerParameter( Tint index ) const 00194 { 00195 return strtoi( GetParameter( index ) ); 00196 } 00197 00198 inline Tint TArgument::GetIntegerParameter( const Tstring& optionname ) const 00199 { 00200 return strtoi( GetParameter( optionname ) ); 00201 } 00202 00203 inline Tint TArgument::GetIntegerParameter( const TOption& option ) const 00204 { 00205 return strtoi( GetParameter( option ) ); 00206 } 00207 00208 inline Tdouble TArgument::GetDoubleParameter( Tint index ) const 00209 { 00210 return strtod( GetParameter( index ) ); 00211 } 00212 00213 inline Tdouble TArgument::GetDoubleParameter( const Tstring& optionname ) const 00214 { 00215 return strtod( GetParameter( optionname ) ); 00216 } 00217 00218 inline Tdouble TArgument::GetDoubleParameter( const TOption& option ) const 00219 { 00220 return strtod( GetParameter( option ) ); 00221 } 00222 00223 inline TintList TArgument::GetIntegerElements() const 00224 { 00225 TintList retval; 00226 for ( Tint i = 0; i < theNumberOfElements; i ++ ) { 00227 retval.push_back( strtoi( theElements[ i ] ) ); 00228 } 00229 return retval; 00230 } 00231 00232 inline TdoubleList TArgument::GetDoubleElements() const 00233 { 00234 TdoubleList retval; 00235 for ( Tint i = 0; i < theNumberOfElements; i ++ ) { 00236 retval.push_back( strtod( theElements[ i ] ) ); 00237 } 00238 return retval; 00239 } 00240 00241 inline Tstring TArgument::GetElement( Tint index ) const 00242 { 00243 Tstring retval = ""; 00244 Tint listlen = (Tint)theElements.size(); 00245 if ( index >= 0 && index < listlen && !theElements.empty() ) { 00246 retval = theElements[ index ]; 00247 } 00248 return retval; 00249 } 00250 00251 inline Tint TArgument::GetIntegerElement( Tint index ) const 00252 { 00253 return strtoi( GetElement( index ) ); 00254 } 00255 00256 inline Tdouble TArgument::GetDoubleElement( Tint index ) const 00257 { 00258 return strtod( GetElement( index ) ); 00259 } 00260 00261 inline Tstring TArgument::operator[]( Tint index ) const 00262 { 00263 return GetElement( index ); 00264 } 00265 00266 inline Tstring TArgument::operator[]( const TOption& option ) const 00267 { 00268 return GetParameter( option ); 00269 } 00270 00271 inline Tstring TArgument::operator[]( const Tstring& optionname ) const 00272 { 00273 return GetParameter( optionname ); 00274 } 00275 00276 inline const Tstring& TArgument::GetUsage() const 00277 { 00278 return theUsage; 00279 } 00280 00281 inline Tvoid TArgument::SetUsage( const Tstring& usage ) 00282 { 00283 theUsage = usage; 00284 return; 00285 } 00286 00287 #endif