XrdMonArgParser.hh

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*                                                                           */
00003 /*                            XrdMonArgParser.hh                             */
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.hh 22437 2008-03-04 14:35:16Z rdm $
00012 
00013 #ifndef XRDMONARGPARSER_HH
00014 #define XRDMONARGPARSER_HH
00015 
00016 #include <stdio.h>
00017 #include <string>
00018 #include <vector>
00019 using std::string;
00020 using std::vector;
00021 
00022 class XrdMonArgParser {
00023 public:
00024     class Arg {
00025     public:
00026         virtual ~Arg() {}
00027         virtual int parseArgs(int argc, char* argv[], int curArg) = 0;
00028         virtual void throwIfRequiredButNotSet() = 0;
00029     };
00030 
00031     template <typename T, class C>
00032     class ArgImpl : public Arg {
00033     public:
00034         ArgImpl(const char* theSwitch,    // leading "-blablabla"
00035                 T defaultValue,
00036                 bool required = false);   // required/optional
00037         virtual ~ArgImpl() {}
00038         virtual int parseArgs(int argc, char* argv[], int curArg);
00039         virtual void throwIfRequiredButNotSet();
00040         T myVal() { return _value; }
00041 
00042     private:
00043         T            _value;    // the value of the arg
00044         const string _switch;   // leading switch
00045         bool         _done;     // arg has been found
00046         bool         _required; // required/optional
00047     };
00048 
00049     XrdMonArgParser();
00050     ~XrdMonArgParser();
00051     
00052     void registerExpectedArg(Arg* arg);
00053     void parseArguments(int argc, char* argv[]);
00054 
00055 private:
00056     vector<Arg*> _args;
00057 };
00058 
00059 #include "XrdMon/XrdMonArgParser.icc"
00060 
00061 #endif /* XRDMONARGPARSER_HH */

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