My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
Program.h
1 #ifndef GCP_PROGRAM_PROGRAM_H
2 #define GCP_PROGRAM_PROGRAM_H
3 
11 #include <string>
12 
13 #define END_OF_KEYWORDS "end_of_keywords"
14 
15 namespace gcp {
16  namespace program {
17 
22  struct KeyTabEntry {
23  const char *key; // keyword (name used on commad line)
24  const char *val; // default value for keyword
25  const char *type; // type of value - could be 'f', 'd', 'b', 's'
26  const char *help; // help string - used to provide detailed
27  };
28 
35  struct Keyword {
36  std::string keyValue; // pointer to original R/O [not used]
37  char option; // short option [not used]
38  std::string key; // keyword (same as long option)
39  std::string val; // value
40  std::string help; // help
41  int count; // update/reference count; 0=original default
42  int upd; // 0=read 1=unread original 2=unread updated
43  int system; // system keyword ? (0=no 1=yes)
44  };
45 
46  class Program {
47  public:
48 
52  static KeyTabEntry keywords[]; // key,val,type,help string
53  // tuples for program keys
54 
58  virtual ~Program();
59 
63  void show(void);
64 
70  std::string getParameter(std::string key);
71 
76  double getdParameter(std::string key);
77 
82  int getiParameter(std::string key);
83 
88  bool getbParameter(std::string key);
89 
94  bool hasValue(std::string key);
95 
102  bool isDefault(std::string key);
103 
108  int count(std::string key);
109 
113  int run(int argc, char* argv[]);
114 
129  static Program* getProgram(); // get singleton instance of Program
130 
131  private:
132 
133  static KeyTabEntry system_[]; // key,val,type,help string
134  // tuples for system keys
135  static std::string version_; // N.M date author (and/or CVS id's)
136  static std::string usage; // one line usage
137  static std::string description; // a longer multi-line description
138 
139  std::string progName_; // short program name without path
140 
141  int argc_; // (from main) argument count
142  char **argv_; // (from main) array of CL strings
143  int ddLoc_; // location of argv "--" (0 means
144  // absent)
145 
146  int nkeys_; // total number of keywords + 1
147  // (argv0, prog, sys)
148  int npkeys_; // number of program keywords
149  int nskeys_; // number of system keywords
150  Keyword* keys_; // 0=not used 1=first keyword etc.
151 
152  // Private methods
153 
159  int main(void);
160  void initializeUsage();
161 
168  Program();
169 
175  int initialize();
176 
177  void printGreeting();
178  std::string fillLine(unsigned char c, unsigned length);
179  std::string formatLine(std::string line,
180  unsigned leftPad, unsigned rightPad, unsigned length);
181 
186  void terminate();
187 
191  std::string getProgname(void);
192 
196  int getArgc(void);
197 
201  char **getArgv(void);
202 
206  void addKey(int i, KeyTabEntry &kt, int system=0);
207 
211  int findKey(const std::string);
212 
213  }; // End class Program
214 
215  } // End namespace program
216 } // End namespace gcp
217 
218 
219 
220 #endif // End #ifndef GCP_PROGRAM_PROGRAM_H
Definition: Program.h:46
static KeyTabEntry keywords[]
Definition: Program.h:52
Definition: Program.h:22
double getdParameter(std::string key)
get double value of a parameter
Definition: Program.cc:475
int getiParameter(std::string key)
get int value of a parameter
Definition: Program.cc:466
int run(int argc, char *argv[])
Definition: Program.cc:304
std::string getParameter(std::string key)
get string value of a parameter
Definition: Program.cc:450
bool hasValue(std::string key)
does keyword have a value
Definition: Program.cc:420
bool isDefault(std::string key)
Definition: Program.cc:435
virtual ~Program()
Definition: Program.cc:49
Definition: Program.h:35
void show(void)
Definition: Program.cc:344
int count(std::string key)
usage count of a keyword
Definition: Program.cc:502
bool getbParameter(std::string key)
get boolean value of a parameter
Definition: Program.cc:484
static Program * getProgram()
Class global method to get the process-wide singleton instance of Program.
Definition: Program.cc:613