XrdOucArgs.hh

Go to the documentation of this file.
00001 #ifndef __XRDOUCARGS_HH__
00002 #define __XRDOUCARGS_HH__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                         X r d O u c A r g s . h h                          */
00006 /*                                                                            */
00007 /* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /******************************************************************************/
00012 
00013 //         $Id: XrdOucArgs.hh 28902 2009-06-11 12:36:21Z ganis $
00014 
00015 #include <stdlib.h>
00016 #include <string.h>
00017 
00018 #include "XrdOuc/XrdOucTokenizer.hh"
00019 
00020 class XrdOucArgsXO;
00021 class XrdSysError;
00022   
00023 class XrdOucArgs
00024 {
00025 public:
00026 
00027 // getarg() returns arguments, if any, one at a time. It should be called after
00028 //          exhausting the option list via getopt() (i.e., it returns args after
00029 //          the last '-' option in the input). Null is returned if no more
00030 //          arguments remain.
00031 //
00032 char *getarg();
00033 
00034 // getopt() works almost exactly like the standard C-library getopt(). Some
00035 //          extensions have been implemented see the constructor. In short:
00036 //          ? -> Invalid option or missing option argument (see below).
00037 //          : -> Missing option arg only when StdOpts starts with a colon.
00038 //          -1-> End of option list (can try getarg() now if so wanted).
00039 //
00040 char  getopt();
00041 
00042 // Set()    tells this XrdOucArgs where the options and arguments come from.
00043 //          They may come from a character string or from argument array. This
00044 //          simplifies having a command/interactive tool as a single program.
00045 //          You must call Set() prior to getxxx(). You may use the same object
00046 //          over again by simply calling Set() again.
00047 //
00048 void  Set(char *arglist);
00049 
00050 void  Set(int argc, char **argv);
00051 
00052 // The StdOpts (which may be null) consist repeated single letters each
00053 // optionally followed by a colon (indicating an argument value is needed)
00054 // or a period, indicating an argument value is optional. If neither then the
00055 // single letter option does not have an argument value. The extended options
00056 // map multiple character words to the single letter equivalent (as above).
00057 
00058 // Note that this class is not an exact implementation of getopt(), as follows:
00059 // 1) Single letter streams are not supported. That is, each single letter
00060 //    option must be preceeded by a '-' (i.e., -a -b is NOT equivalent to -ab).
00061 // 2) Multi-character options may be preceeded by a single dash. Most other
00062 //    implementation require a double dash. You can simulate this here by just
00063 //    making all your multi-character options start with a dash.
00064 //
00065       XrdOucArgs(XrdSysError *erp,      // -> Error Message Object (0->silence)
00066                  const char  *etxt,     // The error text prefix
00067                  const char  *StdOpts,  // List of standard 1-character options
00068                  const char  *optw=0,   // Extended option name (0->end of list)
00069               // int          minl,     // Minimum abbreviation length
00070               // const char  *optmap,   // Equivalence with 1-character option
00071                               ...);     // Repeat last 3 args, as desired.
00072 
00073 // Example:
00074 // XrdOucArgs myArgs(0, "", "ab:c.e",
00075 //                          "debug", 1, "d",  // -d, -de, -deb, -debu, -debug
00076 //                          "force", 5, "F",  // -force is valid only!
00077 //                          0);               // No more extended options
00078 
00079 // Note: getopt() returns the single letter equivalent for long options. So,
00080 //       'd' is returned when -debug is encountered and 'F' for -force.
00081 
00082      ~XrdOucArgs();
00083 
00084 char *argval;
00085 
00086 private:
00087 
00088 XrdOucTokenizer  arg_stream;
00089 XrdSysError     *eDest;
00090 char            *epfx;
00091 XrdOucArgsXO    *optp;
00092 char            *vopts;
00093 char            *curopt;
00094 int              inStream;
00095 int              endopts;
00096 int              Argc;
00097 int              Aloc;
00098 char           **Argv;
00099 char             missarg;
00100 };
00101 #endif

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