xrootd
XrdMonArgParser.hh
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* */
3 /* XrdMonArgParser.hh */
4 /* */
5 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Jacek Becla for Stanford University under contract */
8 /* DE-AC02-76SF00515 with the Department of Energy */
9 /*****************************************************************************/
10 
11 // $Id$
12 
13 #ifndef XRDMONARGPARSER_HH
14 #define XRDMONARGPARSER_HH
15 
16 #include <stdio.h>
17 #include <string>
18 #include <vector>
19 using std::string;
20 using std::vector;
21 
23 public:
24  class Arg {
25  public:
26  virtual ~Arg() {}
27  virtual int parseArgs(int argc, char* argv[], int curArg) = 0;
28  virtual void throwIfRequiredButNotSet() = 0;
29  };
30 
31  template <typename T, class C>
32  class ArgImpl : public Arg {
33  public:
34  ArgImpl(const char* theSwitch, // leading "-blablabla"
35  T defaultValue,
36  bool required = false); // required/optional
37  virtual ~ArgImpl() {}
38  virtual int parseArgs(int argc, char* argv[], int curArg);
39  virtual void throwIfRequiredButNotSet();
40  T myVal() { return _value; }
41 
42  private:
43  T _value; // the value of the arg
44  const string _switch; // leading switch
45  bool _done; // arg has been found
46  bool _required; // required/optional
47  };
48 
51 
52  void registerExpectedArg(Arg* arg);
53  void parseArguments(int argc, char* argv[]);
54 
55 private:
56  vector<Arg*> _args;
57 };
58 
60 
61 #endif /* XRDMONARGPARSER_HH */