OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimArgumentParser.h
Go to the documentation of this file.
1 //-------------------------------------------------------------------------
2 //
3 // This code was taken from Open Scene Graph and incorporated from into
4 // OSSIM.
5 //
6 //-------------------------------------------------------------------------
7 // $Id: ossimArgumentParser.h 22491 2013-11-26 18:17:29Z dburken $
8 #ifndef ossimArgumentParser_HEADER
9 #define ossimArgumentParser_HEADER 1
11 #include <ossim/base/ossimString.h>
12 #include <map>
13 #include <string>
14 #include <iosfwd>
15 
17 
19 {
20 public:
21 
23  {
24  public:
26  {
32  };
33 
35  {
36  float* theFloat;
37  double* theDouble;
38  int* theInt;
39  unsigned int* theUint;
40  std::string* theString;
41  };
42 
43  ossimParameter(float& value)
44  {
45  theType = OSSIM_FLOAT_PARAMETER; theValue.theFloat = &value;
46  }
47 
48  ossimParameter(double& value)
49  {
50  theType = OSSIM_DOUBLE_PARAMETER; theValue.theDouble = &value;
51  }
52 
53  ossimParameter(int& value)
54  {
55  theType = OSSIM_INT_PARAMETER; theValue.theInt = &value;
56  }
57 
58  ossimParameter(unsigned int& value)
59  {
60  theType = OSSIM_UNSIGNED_INT_PARAMETER; theValue.theUint = &value;
61  }
62 
63  ossimParameter(std::string& value)
64  {
65  theType = OSSIM_STRING_PARAMETER; theValue.theString = &value;
66  }
67 
69  {
70  theType = OSSIM_STRING_PARAMETER; theValue.theString =
71  &(value.string());
72  }
73 
74  bool valid(const char* str) const;
75  bool assign(const char* str);
76 
77  protected:
78 
81  };
82 
86  static bool isOption(const char* str);
87 
89  static bool isString(const char* str);
90 
92  static bool isNumber(const char* str);
93 
94 public:
95 
96  ossimArgumentParser(int* argc,char **argv);
97  ossimArgumentParser(const ossimString& commandLine);
98 
100 
102  void initialize(int* argc, const char **argv);
103 
106  const ossimApplicationUsage* getApplicationUsage() const { return theUsage; }
107 
109  int& argc() { return *theArgc; }
110 
112  char** argv() { return theArgv; }
113 
115  char* operator [] (int pos) { return theArgv[pos]; }
116 
118  const char* operator [] (int pos) const { return theArgv[pos]; }
119 
121  std::string getApplicationName() const;
122 
125  int find(const std::string& str) const;
126 
128  bool isOption(int pos) const;
129 
131  bool isString(int pos) const;
132 
134  bool isNumber(int pos) const;
135 
136  bool containsOptions() const;
137 
139  void remove(int pos,int num=1);
140 
143  void insert(int pos, const ossimString& arg);
144 
146  bool match(int pos, const std::string& str) const;
147 
153  bool read(const std::string& str);
154  bool read(const std::string& str, ossimParameter value1);
155  bool read(const std::string& str, ossimParameter value1,
156  ossimParameter value2);
157  bool read(const std::string& str, ossimParameter value1,
158  ossimParameter value2, ossimParameter value3);
159  bool read(const std::string& str, ossimParameter value1,
160  ossimParameter value2, ossimParameter value3,
161  ossimParameter value4);
162  bool read(const std::string& str, ossimParameter value1,
163  ossimParameter value2, ossimParameter value3,
164  ossimParameter value4, ossimParameter value5);
165  bool read(const std::string& str, ossimParameter value1,
166  ossimParameter value2, ossimParameter value3,
167  ossimParameter value4, ossimParameter value5,
168  ossimParameter value6);
169 
181  bool read(const std::string& str, std::vector<ossimString>& param_list);
182 
187  int numberOfParams(const std::string& str,
188  const ossimParameter value) const;
189 
195  bool read(int pos, const std::string& str);
196  bool read(int pos, const std::string& str, ossimParameter value1);
197  bool read(int pos, const std::string& str, ossimParameter value1,
198  ossimParameter value2);
199  bool read(int pos, const std::string& str, ossimParameter value1,
200  ossimParameter value2, ossimParameter value3);
201  bool read(int pos, const std::string& str, ossimParameter value1,
202  ossimParameter value2, ossimParameter value3,
203  ossimParameter value4);
204 
205 
207  {
208  OSSIM_BENIGN = 0,
209  OSSIM_CRITICAL = 1
210  };
211 
212  typedef std::map<std::string,ossimErrorSeverity> ossimErrorMessageMap;
213 
218  bool errors(ossimErrorSeverity severity=OSSIM_BENIGN) const;
219 
221  void reportError(const std::string& message,
222  ossimErrorSeverity severity=OSSIM_CRITICAL);
223 
225  void reportRemainingOptionsAsUnrecognized(
226  ossimErrorSeverity severity=OSSIM_BENIGN);
227 
229  ossimErrorMessageMap& getErrorMessageMap();
230 
232  const ossimErrorMessageMap& getErrorMessageMap() const;
233 
235  void writeErrorMessages(std::ostream& output,
236  ossimErrorSeverity sevrity=OSSIM_BENIGN);
237 
238 
239 protected:
240 
241  int* theArgc;
242  char** theArgv;
246 
247 };
248 
249 #endif
void usage()
#define OSSIMDLLEXPORT
ossimApplicationUsage * getApplicationUsage()
std::map< std::string, ossimErrorSeverity > ossimErrorMessageMap
ossimApplicationUsage * theUsage
ossimErrorMessageMap theErrorMessageMap
const ossimApplicationUsage * getApplicationUsage() const
char ** argv()
return the argument array.
void setApplicationUsage(ossimApplicationUsage *usage)
int & argc()
return the argument count.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
const std::string & string() const
Definition: ossimString.h:414