VAPoR  0.1
OptionParser.h
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 //************************************************************************
5 // *
6 // Copyright (C) 2004 *
7 // University Corporation for Atmospheric Research *
8 // All Rights Reserved *
9 // *
10 //************************************************************************/
11 //
12 // File:
13 //
14 // Author: John Clyne
15 // National Center for Atmospheric Research
16 // PO 3000, Boulder, Colorado
17 //
18 // Date: Wed Oct 6 10:49:44 MDT 2004
19 //
20 // Description: A class for parsing command line options. This
21 // class manages a resource data base of valid command line
22 // options. Valid options may be merged into the data base
23 // at any time and later extracted with their
24 // coresponding values as determined by the command line.
25 //
26 //
27 
28 #ifndef _OptionParser_h_
29 #define _OptionParser_h_
30 
31 #include <string>
32 #include <cmath>
33 #include <vector>
34 #include <vapor/MyBase.h>
35 #include <vapor/common.h>
36 
37 #ifdef WIN32
38 //Silence an annoying and unnecessary compiler warning
39 #pragma warning(disable : 4251)
40 #endif
41 using namespace std;
42 
43 namespace VetsUtil {
44 
45 //
46 //
47 class COMMON_API OptionParser : public MyBase {
48 public:
49 
51  //
57  //
58  typedef struct _OptDescRec {
59  const char *option;
60  int arg_count;
61  const char *value;
62  const char *help;
63  } OptDescRec_T;
64 
65  //
66  // structure for returning the value of an option
67  //
68  typedef struct _DPOption {
69  const char *option_name; // the options name
70 
71  //
72  // option type converter
73  //
74  int (*type_conv)(const char *from, void *to);
75 
76  void *offset; // offset of return address
77  int size; // size of option in bytes
78  } Option_T;
79 
80  typedef struct _EnvOpt {
81  const char *option; // option name
82  const char *env_var; // coresponding enviroment var
83  } EnvOpt_T;
84 
85  typedef int Boolean_T;
86  typedef struct Dimension2D_ {
87  int nx, ny;
88  } Dimension2D_T;
89 
90  typedef struct Dimension3D_ {
91  int nx, ny, nz;
92  } Dimension3D_T;
93 
94  // Converter type for CvtToIntRange()
95  //
96  typedef struct IntRange_ {
97  int min, max;
98  } IntRange_T;
99 
100  OptionParser();
101  ~OptionParser();
102 
104  //
110  //
111  int AppendOptions(const OptDescRec_T *odr);
112 
114  //
124  int ParseOptions(int *argc, char **argv, Option_T *opts);
125  int ParseOptions(const EnvOpt_T *envv, Option_T *opts);
126  void RemoveOptions(std::vector <string> options);
127  void PrintOptionHelp(FILE *fp, int linelimit = 80, bool docopyright = true);
128 
129  typedef struct _OptRec {
130  const char *option; // name of option without preceeding '-'
131  const char *value; // current val for the argument
132  const char *default_value; // default val for the argument
133  const char *help; // help string for option
134  int arg_count; // num args expected by option
135  } _OptRec_T;
136 
137 private:
138 
139  vector<struct _OptRec *> _optTbl;
140 
141  _OptRec_T *_get_option (const char *name);
142  int _parse_options(const Option_T *opts);
143 
144  friend bool opt_cmp(
147  );
148 
149 
150 };
151 
152 
153 
154 COMMON_API int CvtToInt( const char *from, void *to);
155 
156 COMMON_API int CvtToFloat(const char *from, void *to);
157 
158 COMMON_API int CvtToDouble(const char *from, void *to);
159 
160 COMMON_API int CvtToChar(const char *from, void *to);
161 
162 COMMON_API int CvtToBoolean(const char *from, void *to);
163 
164 COMMON_API int CvtToString(const char *from, void *to);
165 
166 COMMON_API int CvtToCPPStr(const char *from, void *to);
167 
168 COMMON_API int CvtToDimension2D(const char *from, void *to);
169 
170 COMMON_API int CvtToDimension3D(const char *from, void *to);
171 
172 // convert a colon delimited ascii string to vector of C++
173 // STL strings: (vector <string> *)
174 //
175 COMMON_API int CvtToStrVec(const char *from, void *to);
176 
177 // convert a colon delimited ascii string to vector of C++
178 // STL ints: (vector <int> *)
179 //
180 COMMON_API int CvtToIntVec(const char *from, void *to);
181 
182 // convert a colon delimited ascii string to vector of C++
183 // STL size_t: (vector <size_t> *)
184 //
185 COMMON_API int CvtToSize_tVec(const char *from, void *to);
186 
187 // convert a colon delimited ascii string to vector of C++
188 // STL ints: (vector <float> *)
189 //
190 COMMON_API int CvtToFloatVec(const char *from, void *to);
191 
192 COMMON_API int CvtToDoubleVec(const char *from, void *to);
193 
194 // Convert a colon-delimited pair of integers to a IntRange_T type
195 //
196 COMMON_API int CvtToIntRange(const char *from, void *to);
197 
198 
199 };
200 
201 #endif
COMMON_API int CvtToDouble(const char *from, void *to)
COMMON_API int CvtToFloat(const char *from, void *to)
Definition: Base64.h:6
COMMON_API int CvtToInt(const char *from, void *to)
COMMON_API int CvtToString(const char *from, void *to)
COMMON_API int CvtToIntRange(const char *from, void *to)
COMMON_API int CvtToChar(const char *from, void *to)
COMMON_API int CvtToFloatVec(const char *from, void *to)
COMMON_API int CvtToDoubleVec(const char *from, void *to)
#define COMMON_API
Definition: common.h:60
COMMON_API int CvtToDimension2D(const char *from, void *to)
An option description record (odr)
Definition: OptionParser.h:58
VetsUtil base class.
Definition: MyBase.h:68
COMMON_API int CvtToDimension3D(const char *from, void *to)
COMMON_API int CvtToBoolean(const char *from, void *to)
COMMON_API int CvtToStrVec(const char *from, void *to)
COMMON_API int CvtToIntVec(const char *from, void *to)
COMMON_API int CvtToSize_tVec(const char *from, void *to)
COMMON_API int CvtToCPPStr(const char *from, void *to)