MPQC  3.0.0-alpha
GetLongOpt.h
1 /* $Id$ */
2 /* S Manoharan. Advanced Computer Research Institute. Lyon. France */
3 
4 #ifndef _GetLongOpt_h_
5 #define _GetLongOpt_h_
6 
7 #include <iostream>
8 #include <string.h>
9 
10 namespace sc {
11 
14 
16 class GetLongOpt {
17 public:
20  enum OptType {
21  NoValue, OptionalValue, MandatoryValue
22  };
23 private:
24  struct Cell {
25  const char *option; // option name
26  OptType type; // option type
27  const char *description; // a description of option
28  const char *value; // value of option (string)
29  Cell *next; // pointer to the next cell
30 
31  Cell() { option = description = value = 0; next = 0; }
32  };
33 private:
34  Cell *table; // option table
35  const char *ustring; // usage message
36  char *pname; // program basename
37  char optmarker; // option marker
38 
39  int enroll_done; // finished enrolling
40  Cell *last; // last entry in option table
41 
42 private:
43  char *basename(char * const p) const;
44  int setcell(Cell *c, const char *valtoken, const char *nexttoken, const char *p);
45 public:
48  GetLongOpt(const char optmark = '-');
49  ~GetLongOpt();
50 
56  int parse(int argc, char * const *argv);
62  int parse(char * const str, char * const p);
63 
69  int enroll(const char * const opt, const OptType t,
70  const char * const desc, const char * const val);
73  const char *retrieve(const char * const opt) const;
74 
77  void usage(std::ostream &outfile = std::cout) const;
80  void usage(const char *str) { ustring = str; }
81 };
82 
84 // end of addtogroup Init
85 
86 }
87 
88 #endif /* _GetLongOpt_h_ */
sc::GetLongOpt::enroll
int enroll(const char *const opt, const OptType t, const char *const desc, const char *const val)
Enroll an option.
sc::GetLongOpt::retrieve
const char * retrieve(const char *const opt) const
Retrieve an option.
sc::GetLongOpt::usage
void usage(std::ostream &outfile=std::cout) const
Print usage information.
sc::GetLongOpt::parse
int parse(int argc, char *const *argv)
Parse command line options.
sc::GetLongOpt::usage
void usage(const char *str)
Initialize usage synopsis.
Definition: GetLongOpt.h:80
sc::GetLongOpt::OptType
OptType
Used by the enroll member to specify whether or not a value is expected or optional.
Definition: GetLongOpt.h:20
sc::GetLongOpt::GetLongOpt
GetLongOpt(const char optmark='-')
Initialize the object.
sc::GetLongOpt
Parse command line options.
Definition: GetLongOpt.h:16
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:02 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.