VAPOR3 3.9.4
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
41using namespace std;
42
43namespace Wasp {
44
45//
46//
48public:
50 //
56 //
57 typedef struct _OptDescRec {
58 const char *option;
60 const char *value;
61 const char *help;
62 } OptDescRec_T;
63
64 //
65 // structure for returning the value of an option
66 //
67 typedef struct _DPOption {
68 const char *option_name; // the options name
69
70 //
71 // option type converter
72 //
73 int (*type_conv)(const char *from, void *to);
74
75 void *offset; // offset of return address
76 int size; // size of option in bytes
77 } Option_T;
78
79 typedef struct _EnvOpt {
80 const char *option; // option name
81 const char *env_var; // coresponding enviroment var
82 } EnvOpt_T;
83
84 typedef int Boolean_T;
85 typedef struct Dimension2D_ {
86 int nx, ny;
87 } Dimension2D_T;
88
89 typedef struct Dimension3D_ {
90 int nx, ny, nz;
91 } Dimension3D_T;
92
93 // Converter type for CvtToIntRange()
94 //
95 typedef struct IntRange_ {
96 int min, max;
97 } IntRange_T;
98
101
103 //
109 //
111
113 //
123 int ParseOptions(int *argc, char **argv, Option_T *opts);
124 int ParseOptions(const EnvOpt_T *envv, Option_T *opts);
125 void RemoveOptions(std::vector<string> options);
126 void PrintOptionHelp(FILE *fp, int linelimit = 80, bool docopyright = true);
127
128 typedef struct _OptRec {
129 const char *option; // name of option without preceeding '-'
130 const char *value; // current val for the argument
131 const char *default_value; // default val for the argument
132 const char *help; // help string for option
133 int arg_count; // num args expected by option
134 } _OptRec_T;
135
136private:
137 vector<struct _OptRec *> _optTbl;
138
139 _OptRec_T *_get_option(const char *name);
140 int _parse_options(const Option_T *opts);
141
143};
144
145COMMON_API int CvtToInt(const char *from, void *to);
146
147COMMON_API int CvtToFloat(const char *from, void *to);
148
149COMMON_API int CvtToDouble(const char *from, void *to);
150
151COMMON_API int CvtToChar(const char *from, void *to);
152
153COMMON_API int CvtToBoolean(const char *from, void *to);
154
155COMMON_API int CvtToString(const char *from, void *to);
156
157COMMON_API int CvtToCPPStr(const char *from, void *to);
158
159COMMON_API int CvtToDimension2D(const char *from, void *to);
160
161COMMON_API int CvtToDimension3D(const char *from, void *to);
162
163// convert a colon delimited ascii string to vector of C++
164// STL strings: (vector <string> *)
165//
166COMMON_API int CvtToStrVec(const char *from, void *to);
167
168// convert a colon delimited ascii string to vector of C++
169// STL ints: (vector <int> *)
170//
171COMMON_API int CvtToIntVec(const char *from, void *to);
172
173// convert a colon delimited ascii string to vector of C++
174// STL size_t: (vector <size_t> *)
175//
176COMMON_API int CvtToSize_tVec(const char *from, void *to);
177
178// convert a colon delimited ascii string to vector of C++
179// STL ints: (vector <float> *)
180//
181COMMON_API int CvtToFloatVec(const char *from, void *to);
182
183COMMON_API int CvtToDoubleVec(const char *from, void *to);
184
185// Convert a colon-delimited pair of integers to a IntRange_T type
186//
187COMMON_API int CvtToIntRange(const char *from, void *to);
188
189}; // namespace Wasp
190
191#endif
Wasp base class.
Definition: MyBase.h:67
int AppendOptions(const OptDescRec_T *odr)
Append a list of option descriptions.
int ParseOptions(int *argc, char **argv, Option_T *opts)
Parse a command line argument vector.
void PrintOptionHelp(FILE *fp, int linelimit=80, bool docopyright=true)
int ParseOptions(const EnvOpt_T *envv, Option_T *opts)
friend bool opt_cmp(OptionParser::_OptRec_T *a, OptionParser::_OptRec_T *b)
void RemoveOptions(std::vector< string > options)
#define COMMON_API
Definition: common.h:72
Definition: CFuncs.h:31
COMMON_API int CvtToCPPStr(const char *from, void *to)
COMMON_API int CvtToIntRange(const char *from, void *to)
COMMON_API int CvtToFloatVec(const char *from, void *to)
COMMON_API int CvtToChar(const char *from, void *to)
COMMON_API int CvtToStrVec(const char *from, void *to)
COMMON_API int CvtToDoubleVec(const char *from, void *to)
COMMON_API int CvtToFloat(const char *from, void *to)
COMMON_API int CvtToDimension2D(const char *from, void *to)
COMMON_API int CvtToIntVec(const char *from, void *to)
COMMON_API int CvtToDimension3D(const char *from, void *to)
COMMON_API int CvtToString(const char *from, void *to)
COMMON_API int CvtToInt(const char *from, void *to)
COMMON_API int CvtToBoolean(const char *from, void *to)
COMMON_API int CvtToSize_tVec(const char *from, void *to)
COMMON_API int CvtToDouble(const char *from, void *to)
An option description record (odr)
Definition: OptionParser.h:57