Ignore:
Timestamp:
05/10/09 12:01:26 (15 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MArgs.cc

    r9141 r9442  
    292292// --------------------------------------------------------------------------
    293293//
     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//
     300MArgsEntry *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//
    294330// Return the TString corresponding to the i-th argument.
    295331// This is ment for enumerations like
     
    299335//
    300336TString 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//
     346Int_t MArgs::GetNumArguments() const
    301347{
    302348    Int_t num = 0;
     
    317363            continue;
    318364
    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() const
    331 {
    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 
    349365        num++;
    350366    }
    351367
    352368    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//
     376Bool_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;
    353385}
    354386
Note: See TracChangeset for help on using the changeset viewer.