Changeset 9442 for trunk


Ignore:
Timestamp:
05/10/09 12:01:26 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r9441 r9442  
    2626   * mbase/MDirIter.[h,cc]:
    2727     - added AddFile member function
     28
     29   * mbase/MArgs.[h,cc]:
     30     - added member function to remove an argument from the list
    2831
    2932   * mgeom/MGeomPix.h:
  • 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
  • trunk/MagicSoft/Mars/mbase/MArgs.h

    r9141 r9442  
    2929    Int_t fArgc; //!
    3030    TList fArgv; //!
     31
     32    MArgsEntry *GetArgument(Int_t i) const;
    3133
    3234public:
     
    6668    Int_t    GetNumEntries() const;
    6769
     70    Bool_t   RemoveArgument(Int_t i);
     71
    6872    ClassDef(MArgs, 0)  //Class to parse command line arguments
    6973};
Note: See TracChangeset for help on using the changeset viewer.