XrdMonArgParser.cc

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*                                                                           */
00003 /*                            XrdMonArgParser.cc                             */
00004 /*                                                                           */
00005 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
00006 /*                            All Rights Reserved                            */
00007 /*       Produced by Jacek Becla for Stanford University under contract      */
00008 /*              DE-AC02-76SF00515 with the Department of Energy              */
00009 /*****************************************************************************/
00010 
00011 // $Id: XrdMonArgParser.cc 22437 2008-03-04 14:35:16Z rdm $
00012 
00013 #include "XrdMon/XrdMonArgParser.hh"
00014 #include "XrdMon/XrdMonErrors.hh"
00015 #include "XrdMon/XrdMonException.hh"
00016 
00017 XrdMonArgParser::XrdMonArgParser()
00018 {}
00019 
00020 XrdMonArgParser::~XrdMonArgParser()
00021 {}
00022 
00023 void
00024 XrdMonArgParser::registerExpectedArg(Arg* arg)
00025 {
00026     _args.push_back(arg);
00027 }
00028 
00029 void
00030 XrdMonArgParser::parseArguments(int argc, char* argv[])
00031 {
00032     int curArg = 1; // skip the first (program name)
00033     int i, argSize = _args.size();
00034     
00035     while ( curArg < argc ) {
00036         bool claimed = false;
00037         for ( i=0 ; i<argSize ; ++i) {
00038             int x = _args[i]->parseArgs(argc, argv, curArg);
00039             if ( x > 0 ) {
00040                 curArg += x;
00041                 claimed = true;
00042                 break;
00043             }
00044         }
00045         if ( ! claimed ) {
00046             string ss("Unexpected argument ");
00047             ss += argv[curArg];
00048             throw XrdMonException(ERR_INVALIDARG, ss);
00049         }
00050     }
00051 
00052     // now make sure that all the arguments that are 
00053     // required has been set
00054     for ( i=0 ; i<argSize ; ++i) {
00055         _args[i]->throwIfRequiredButNotSet();
00056     }    
00057 }
00058 

Generated on Tue Jul 5 14:46:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1