Changeset 9442 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 05/10/09 12:01:26 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MArgs.cc
r9141 r9442 292 292 // -------------------------------------------------------------------------- 293 293 // 294 // Return a pointer to the MArgsEntry of the i-th argument 295 // This is ment for enumerations like 296 // executable file1 file2 file3 297 // GetArgumentStr(1) will return "file2" 298 // Only arguments without a trailing '-' are considered 299 // 300 MArgsEntry *MArgs::GetArgument(Int_t i) const 301 { 302 Int_t num = 0; 303 304 Bool_t allarg = kFALSE; 305 306 TIter Next(&fArgv); 307 MArgsEntry *e = NULL; 308 while ((e=static_cast<MArgsEntry*>(Next()))) 309 { 310 const TString &s=*dynamic_cast<TString*>(e); 311 312 if (s=="--") 313 { 314 allarg = kTRUE; 315 continue; 316 } 317 318 if (s.BeginsWith("-") && !allarg) 319 continue; 320 321 if (i==num++) 322 return e; 323 } 324 325 return 0; 326 } 327 328 // -------------------------------------------------------------------------- 329 // 294 330 // Return the TString corresponding to the i-th argument. 295 331 // This is ment for enumerations like … … 299 335 // 300 336 TString MArgs::GetArgumentStr(Int_t i) const 337 { 338 const MArgsEntry *e = GetArgument(i); 339 return e==0 ? "" : dynamic_cast<const TString&>(*e); 340 } 341 342 // -------------------------------------------------------------------------- 343 // 344 // return the number of arguments without a trainling '-' 345 // 346 Int_t MArgs::GetNumArguments() const 301 347 { 302 348 Int_t num = 0; … … 317 363 continue; 318 364 319 if (i==num++)320 return *s;321 }322 323 return "";324 }325 326 // --------------------------------------------------------------------------327 //328 // return the number of arguments without a trainling '-'329 //330 Int_t MArgs::GetNumArguments() const331 {332 Int_t num = 0;333 334 Bool_t allarg = kFALSE;335 336 TIter Next(&fArgv);337 TString *s = NULL;338 while ((s=dynamic_cast<TString*>(Next())))339 {340 if (*s=="--")341 {342 allarg = kTRUE;343 continue;344 }345 346 if (s->BeginsWith("-") && !allarg)347 continue;348 349 365 num++; 350 366 } 351 367 352 368 return num; 369 } 370 371 // -------------------------------------------------------------------------- 372 // 373 // Remove the i-th argument from the list. Return kTRUE in case of sucess 374 // kFALSE otherwise 375 // 376 Bool_t MArgs::RemoveArgument(Int_t i) 377 { 378 MArgsEntry *e = GetArgument(i); 379 if (!e) 380 return kFALSE; 381 382 delete fArgv.Remove(e); 383 384 return kTRUE; 353 385 } 354 386 -
trunk/MagicSoft/Mars/mbase/MArgs.h
r9141 r9442 29 29 Int_t fArgc; //! 30 30 TList fArgv; //! 31 32 MArgsEntry *GetArgument(Int_t i) const; 31 33 32 34 public: … … 66 68 Int_t GetNumEntries() const; 67 69 70 Bool_t RemoveArgument(Int_t i); 71 68 72 ClassDef(MArgs, 0) //Class to parse command line arguments 69 73 };
Note:
See TracChangeset
for help on using the changeset viewer.