Changeset 2728 for trunk/MagicSoft/Mars/mbase/MArgs.cc
- Timestamp:
- 12/20/03 13:46:17 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MArgs.cc
r2529 r2728 30 30 // This is a helper class for executables to parse command line arguments 31 31 // 32 // Arguments beginning with a trailing '-' are called 'options'. 33 // Arguments without a trailing '-' are considered 'arguments' 34 // 32 35 ////////////////////////////////////////////////////////////////////////////// 33 36 #include "MArgs.h" … … 82 85 // -------------------------------------------------------------------------- 83 86 // 84 // Print all arguments parsed. 87 // Print everything parsed. 88 // Using 'options' as option only 'options' are printed. 89 // Using 'arguments' as option only 'arguments' are printed. 85 90 // 86 91 void MArgs::Print(const Option_t *o) const 87 92 { 88 93 gLog << all << underline << fName << ":" << endl; 94 95 const TString str(o); 96 97 if (!str.CompareTo("options", TString::kIgnoreCase)) 98 { 99 TIter Next(fArgv); 100 TString *s = NULL; 101 while ((s=dynamic_cast<TString*>(Next()))) 102 if (s->BeginsWith("-")) 103 gLog << *s << endl; 104 return; 105 } 106 107 if (!str.CompareTo("arguments", TString::kIgnoreCase)) 108 { 109 TIter Next(fArgv); 110 TString *s = NULL; 111 while ((s=dynamic_cast<TString*>(Next()))) 112 if (!s->BeginsWith("-")) 113 gLog << *s << endl; 114 return; 115 } 116 89 117 fArgv->Print(); 90 118 } … … 246 274 // -------------------------------------------------------------------------- 247 275 // 276 // return the number of arguments with a trainling '-' 277 // 278 Int_t MArgs::GetNumOptions() const 279 { 280 Int_t num = 0; 281 282 TIter Next(fArgv); 283 TString *s = NULL; 284 while ((s=dynamic_cast<TString*>(Next()))) 285 if (s->BeginsWith("-")) 286 num++; 287 288 return num; 289 } 290 291 // -------------------------------------------------------------------------- 292 // 293 // return the total number of entries 294 // 295 Int_t MArgs::GetNumEntries() const 296 { 297 return fArgv->GetSize(); 298 } 299 300 // -------------------------------------------------------------------------- 301 // 248 302 // Checks whether an argument beginning with 'n' is existing, eg: 249 303 // executable -value5 … … 259 313 while ((s=dynamic_cast<TString*>(Next()))) 260 314 if (s->BeginsWith(name)) 315 return kTRUE; 316 return kFALSE; 317 } 318 319 // -------------------------------------------------------------------------- 320 // 321 // Checks whether an argument beginning with 'n' is existing, eg: 322 // executable -value5 323 // HasOption("-value") will return false 324 // executable -value 325 // HasOption("-value") will return true 326 // 327 Bool_t MArgs::HasOnly(const TString n) const 328 { 329 const TString name = n.Strip(TString::kBoth); 330 331 TIter Next(fArgv); 332 TString *s = NULL; 333 while ((s=dynamic_cast<TString*>(Next()))) 334 if (*s==name) 261 335 return kTRUE; 262 336 return kFALSE; … … 284 358 return kFALSE; 285 359 } 360 361 // -------------------------------------------------------------------------- 362 // 363 // Checks whether an argument beginning with 'n' is exists and a 364 // corresponding option is available, eg. 365 // executable -value5 366 // HasOption("-value") will return false 367 // but: 368 // executable -value 369 // HasOption("-value") will return true 370 // 371 // The argument is removed from the internal list. 372 // 373 Bool_t MArgs::HasOnlyAndRemove(const TString n) 374 { 375 const TString name = n.Strip(TString::kBoth); 376 377 TIter Next(fArgv); 378 TString *s = NULL; 379 while ((s=dynamic_cast<TString*>(Next()))) 380 if (*s==name) 381 { 382 delete fArgv->Remove(dynamic_cast<TObject*>(s)); 383 return kTRUE; 384 } 385 386 return kFALSE; 387 }
Note:
See TracChangeset
for help on using the changeset viewer.