OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
ossimArgumentParser Class Reference

#include <ossimArgumentParser.h>

Classes

class  ossimParameter
 

Public Types

enum  ossimErrorSeverity { OSSIM_BENIGN = 0, OSSIM_CRITICAL = 1 }
 
typedef std::map< std::string, ossimErrorSeverityossimErrorMessageMap
 

Public Member Functions

 ossimArgumentParser (int *argc, char **argv)
 
 ossimArgumentParser (const ossimString &commandLine)
 
 ~ossimArgumentParser ()
 
void initialize (int *argc, const char **argv)
 Initialize from command arguments. More...
 
void setApplicationUsage (ossimApplicationUsage *usage)
 
ossimApplicationUsagegetApplicationUsage ()
 
const ossimApplicationUsagegetApplicationUsage () const
 
int & argc ()
 return the argument count. More...
 
char ** argv ()
 return the argument array. More...
 
char * operator[] (int pos)
 return char* argument at specificed position. More...
 
const char * operator[] (int pos) const
 return const char* argument at specificed position. More...
 
std::string getApplicationName () const
 return the application name, as specified by argv[0] More...
 
int find (const std::string &str) const
 return the position of an occurence of a string in the argument list. More...
 
bool isOption (int pos) const
 return return true if specified parameter is an option in the form of -option or –option . More...
 
bool isString (int pos) const
 return return true if specified parameter is an string, which can be any other string apart from an option. More...
 
bool isNumber (int pos) const
 return return true if specified parameter is an number. More...
 
bool containsOptions () const
 
void remove (int pos, int num=1)
 remove one or more arguments from the argv argument list, and decrement the argc respectively. More...
 
void insert (int pos, const ossimString &arg)
 Inserts string into the argv argument list, and increment the argc respectively. More...
 
bool match (int pos, const std::string &str) const
 return true if specified argument matches string. More...
 
bool read (const std::string &str)
 search for an occurance of a string in the argument list, on sucess remove that occurance from the list and return true, otherwise return false. More...
 
bool read (const std::string &str, ossimParameter value1)
 
bool read (const std::string &str, ossimParameter value1, ossimParameter value2)
 
bool read (const std::string &str, ossimParameter value1, ossimParameter value2, ossimParameter value3)
 
bool read (const std::string &str, ossimParameter value1, ossimParameter value2, ossimParameter value3, ossimParameter value4)
 
bool read (const std::string &str, ossimParameter value1, ossimParameter value2, ossimParameter value3, ossimParameter value4, ossimParameter value5)
 
bool read (const std::string &str, ossimParameter value1, ossimParameter value2, ossimParameter value3, ossimParameter value4, ossimParameter value5, ossimParameter value6)
 
bool read (const std::string &str, std::vector< ossimString > &param_list)
 Alternate form for reading variable length arguments (must be comma-separated), e.g.,. More...
 
int numberOfParams (const std::string &str, const ossimParameter value) const
 
bool read (int pos, const std::string &str)
 if the argument value at the position pos matches specified string, and subsequent paramters are also matched then set the paramter values and remove the from the list of arguments. More...
 
bool read (int pos, const std::string &str, ossimParameter value1)
 
bool read (int pos, const std::string &str, ossimParameter value1, ossimParameter value2)
 
bool read (int pos, const std::string &str, ossimParameter value1, ossimParameter value2, ossimParameter value3)
 
bool read (int pos, const std::string &str, ossimParameter value1, ossimParameter value2, ossimParameter value3, ossimParameter value4)
 
bool errors (ossimErrorSeverity severity=OSSIM_BENIGN) const
 
void reportError (const std::string &message, ossimErrorSeverity severity=OSSIM_CRITICAL)
 report an error message by adding to the ErrorMessageMap. More...
 
void reportRemainingOptionsAsUnrecognized (ossimErrorSeverity severity=OSSIM_BENIGN)
 for each remaining option report it as an unrecongnized. More...
 
ossimErrorMessageMapgetErrorMessageMap ()
 
const ossimErrorMessageMapgetErrorMessageMap () const
 
void writeErrorMessages (std::ostream &output, ossimErrorSeverity sevrity=OSSIM_BENIGN)
 write out error messages at an above specified . More...
 

Static Public Member Functions

static bool isOption (const char *str)
 return return true if specified string is an option in the form of -option or –option . More...
 
static bool isString (const char *str)
 return return true if string is any other string apart from an option. More...
 
static bool isNumber (const char *str)
 return return true if specified parameter is an number. More...
 

Protected Attributes

int * theArgc
 
char ** theArgv
 
ossimErrorMessageMap theErrorMessageMap
 
ossimApplicationUsagetheUsage
 
bool theMemAllocated
 

Detailed Description

Definition at line 18 of file ossimArgumentParser.h.

Member Typedef Documentation

◆ ossimErrorMessageMap

Definition at line 212 of file ossimArgumentParser.h.

Member Enumeration Documentation

◆ ossimErrorSeverity

Enumerator
OSSIM_BENIGN 
OSSIM_CRITICAL 

Definition at line 206 of file ossimArgumentParser.h.

Constructor & Destructor Documentation

◆ ossimArgumentParser() [1/2]

ossimArgumentParser::ossimArgumentParser ( int *  argc,
char **  argv 
)

Definition at line 169 of file ossimArgumentParser.cpp.

References argv(), ossimApplicationUsage::setApplicationName(), theArgc, and theUsage.

169  :
170  theArgc(argc),
171  theArgv(argv),
173  theMemAllocated(false)
174 {
175  if (theArgc)
177 }
static ossimApplicationUsage * instance()
void setApplicationName(const ossimString &name)
ossimApplicationUsage * theUsage
char ** argv()
return the argument array.
int & argc()
return the argument count.

◆ ossimArgumentParser() [2/2]

ossimArgumentParser::ossimArgumentParser ( const ossimString commandLine)

Definition at line 179 of file ossimArgumentParser.cpp.

References n, ossimApplicationUsage::setApplicationName(), ossimString::split(), theArgc, theArgv, and theUsage.

179  :
180  theArgc(new int),
181  theArgv(0),
183  theMemAllocated(true)
184 {
185  vector<ossimString> args = commandLine.split(" ", true);
186  *theArgc = (int)args.size();
187  if (*theArgc > 0)
188  {
189  theArgv = new char* [*theArgc];
190  for (size_t i=0; i<args.size(); i++)
191  {
192  size_t n = args[i].size();
193  theArgv[i] = new char [n+1];
194  strncpy(theArgv[i], args[i].chars(), n);
195  theArgv[i][n] = '\0';
196  }
198  }
199 }
static ossimApplicationUsage * instance()
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
os2<< "> n<< " > nendobj n
void setApplicationName(const ossimString &name)
ossimApplicationUsage * theUsage

◆ ~ossimArgumentParser()

ossimArgumentParser::~ossimArgumentParser ( )

Definition at line 201 of file ossimArgumentParser.cpp.

References theArgc, theArgv, and theMemAllocated.

202 {
203  if (theMemAllocated)
204  {
205  for (int i=0; i<*theArgc; ++i)
206  delete [] theArgv[i];
207  delete [] theArgv;
208  delete theArgc;
209  }
210 }

Member Function Documentation

◆ argc()

int& ossimArgumentParser::argc ( )
inline

◆ argv()

char** ossimArgumentParser::argv ( )
inline

return the argument array.

Definition at line 112 of file ossimArgumentParser.h.

Referenced by ossimBatchTest::initialize(), initialize(), and ossimArgumentParser().

112 { return theArgv; }

◆ containsOptions()

bool ossimArgumentParser::containsOptions ( ) const

Definition at line 262 of file ossimArgumentParser.cpp.

References isOption(), and theArgc.

263 {
264  for(int pos=1;pos<*theArgc;++pos)
265  {
266  if (isOption(pos)) return true;
267  }
268  return false;
269 }
static bool isOption(const char *str)
return return true if specified string is an option in the form of -option or –option ...

◆ errors()

bool ossimArgumentParser::errors ( ossimErrorSeverity  severity = OSSIM_BENIGN) const
Returns
The error flag, true if an error has occured when reading arguments.

Definition at line 594 of file ossimArgumentParser.cpp.

References theErrorMessageMap.

Referenced by ossimBatchTest::initialize(), and ossimChipProcTool::processRemainingArgs().

595 {
596  for(ossimErrorMessageMap::const_iterator itr=theErrorMessageMap.begin();
597  itr!=theErrorMessageMap.end();
598  ++itr)
599  {
600  if (itr->second>=severity) return true;
601  }
602  return false;
603 }
ossimErrorMessageMap theErrorMessageMap

◆ find()

int ossimArgumentParser::find ( const std::string &  str) const

return the position of an occurence of a string in the argument list.

return -1 when no string is found.

Definition at line 245 of file ossimArgumentParser.cpp.

References theArgc, and theArgv.

Referenced by numberOfParams(), and read().

246 {
247  for(int pos=1;pos<*theArgc;++pos)
248  {
249  if (str==theArgv[pos])
250  {
251  return pos;
252  }
253  }
254  return 0;
255 }

◆ getApplicationName()

std::string ossimArgumentParser::getApplicationName ( ) const

◆ getApplicationUsage() [1/2]

ossimApplicationUsage* ossimArgumentParser::getApplicationUsage ( )
inline

◆ getApplicationUsage() [2/2]

const ossimApplicationUsage* ossimArgumentParser::getApplicationUsage ( ) const
inline

Definition at line 106 of file ossimArgumentParser.h.

106 { return theUsage; }
ossimApplicationUsage * theUsage

◆ getErrorMessageMap() [1/2]

ossimArgumentParser::ossimErrorMessageMap & ossimArgumentParser::getErrorMessageMap ( )
Returns
The error message, if any has occured.

Definition at line 649 of file ossimArgumentParser.cpp.

References theErrorMessageMap.

650 {
651  return theErrorMessageMap;
652 }
ossimErrorMessageMap theErrorMessageMap

◆ getErrorMessageMap() [2/2]

const ossimArgumentParser::ossimErrorMessageMap & ossimArgumentParser::getErrorMessageMap ( ) const
Returns
The error message, if any has occured.

Definition at line 654 of file ossimArgumentParser.cpp.

References theErrorMessageMap.

655 {
656  return theErrorMessageMap;
657 }
ossimErrorMessageMap theErrorMessageMap

◆ initialize()

void ossimArgumentParser::initialize ( int *  argc,
const char **  argv 
)

Initialize from command arguments.

Definition at line 212 of file ossimArgumentParser.cpp.

References argc(), argv(), theArgc, and theArgv.

213 {
214  if(*argc > 0) delete (theArgv);
215  theArgc = argc;
216  theArgv = new char*[*argc];
217  for(int i=0;i<*argc;i++)
218  {
219  theArgv[i] = new char[strlen(argv[i])];
220  strcpy(theArgv[i], argv[i]);
221  }
222 }
char ** argv()
return the argument array.
int & argc()
return the argument count.

◆ insert()

void ossimArgumentParser::insert ( int  pos,
const ossimString arg 
)

Inserts string into the argv argument list, and increment the argc respectively.

If string contains spaces, it will be split up into component simple strings.

Definition at line 299 of file ossimArgumentParser.cpp.

References ossimString::size(), ossimString::split(), theArgc, theArgv, and theMemAllocated.

300 {
301  if (argstr.size()==0)
302  return;
303 
304  // Split arg into components (separated by spaces). Need to reallocate args array to new size:
305  vector<ossimString> components = argstr.split(" ");
306  int new_argc = *theArgc + (int)components.size();
307  char** new_argv = new char*[new_argc];
308 
309  // First copy the original list, leaving space for the new components:
310  int j = 0;
311  for (int i=0; i<*theArgc; ++i)
312  {
313  if (j == pos)
314  j += (int)components.size();
315  new_argv[j] = theArgv[i];
316  ++j;
317  }
318 
319  // Insert new components:
320  for(ossim_uint32 i=0; i<components.size(); ++i)
321  new_argv[pos+i]=components[i].stringDup();
322 
323  // Need to deallocate old arg storage?
324  if (theMemAllocated)
325  delete [] theArgv;
326  theArgv = new_argv;
327  *theArgc = new_argc;
328  theMemAllocated = true;
329 }
unsigned int ossim_uint32

◆ isNumber() [1/2]

bool ossimArgumentParser::isNumber ( const char *  str)
static

return return true if specified parameter is an number.

Definition at line 32 of file ossimArgumentParser.cpp.

Referenced by isNumber().

33 {
34  if (!str) return false;
35 
36  bool hadPlusMinus = false;
37  bool hadDecimalPlace = false;
38  bool hadExponent = false;
39  bool couldBeInt = true;
40  bool couldBeFloat = true;
41  int noZeroToNine = 0;
42 
43  const char* ptr = str;
44 
45  // check if could be a hex number.
46  if (std::strncmp(ptr,"0x",2)==0)
47  {
48  // skip over leading 0x, and then go through rest of string
49  // checking to make sure all values are 0...9 or a..f.
50  ptr+=2;
51  while (
52  *ptr!=0 &&
53  ((*ptr>='0' && *ptr<='9') ||
54  (*ptr>='a' && *ptr<='f') ||
55  (*ptr>='A' && *ptr<='F'))
56  )
57  {
58  ++ptr;
59  }
60 
61  // got to end of string without failure, therefore must be a hex integer.
62  if (*ptr==0) return true;
63  }
64 
65  ptr = str;
66 
67  // check if a float or an int.
68  while (*ptr!=0 && couldBeFloat)
69  {
70  if (*ptr=='+' || *ptr=='-')
71  {
72  if (hadPlusMinus)
73  {
74  couldBeInt = false;
75  couldBeFloat = false;
76  }
77  else
78  {
79  hadPlusMinus = true;
80  }
81  }
82  else if (*ptr>='0' && *ptr<='9')
83  {
84  noZeroToNine++;
85  }
86  else if (*ptr=='.')
87  {
88  if (hadDecimalPlace)
89  {
90  couldBeInt = false;
91  couldBeFloat = false;
92  }
93  else
94  {
95  hadDecimalPlace = true;
96  couldBeInt = false;
97  }
98  }
99  else if (*ptr=='e' || *ptr=='E')
100  {
101  if (hadExponent || noZeroToNine==0)
102  {
103  couldBeInt = false;
104  couldBeFloat = false;
105  }
106  else
107  {
108  hadExponent = true;
109  couldBeInt = false;
110  hadDecimalPlace = false;
111  hadPlusMinus = false;
112  noZeroToNine=0;
113  }
114  }
115  else
116  {
117  couldBeInt = false;
118  couldBeFloat = false;
119  }
120  ++ptr;
121  }
122 
123  if (couldBeInt && noZeroToNine>0) return true;
124  if (couldBeFloat && noZeroToNine>0) return true;
125 
126  return false;
127 
128 }

◆ isNumber() [2/2]

bool ossimArgumentParser::isNumber ( int  pos) const

return return true if specified parameter is an number.

Definition at line 240 of file ossimArgumentParser.cpp.

References isNumber(), theArgc, and theArgv.

241 {
242  return pos < *theArgc && isNumber(theArgv[pos]);
243 }
static bool isNumber(const char *str)
return return true if specified parameter is an number.

◆ isOption() [1/2]

bool ossimArgumentParser::isOption ( const char *  str)
static

return return true if specified string is an option in the form of -option or –option .

Definition at line 19 of file ossimArgumentParser.cpp.

Referenced by containsOptions(), isOption(), and reportRemainingOptionsAsUnrecognized().

20 {
21  return str && str[0]=='-';
22 }

◆ isOption() [2/2]

bool ossimArgumentParser::isOption ( int  pos) const

return return true if specified parameter is an option in the form of -option or –option .

Definition at line 230 of file ossimArgumentParser.cpp.

References isOption(), theArgc, and theArgv.

231 {
232  return pos<*theArgc && isOption(theArgv[pos]);
233 }
static bool isOption(const char *str)
return return true if specified string is an option in the form of -option or –option ...

◆ isString() [1/2]

bool ossimArgumentParser::isString ( const char *  str)
static

return return true if string is any other string apart from an option.

Definition at line 24 of file ossimArgumentParser.cpp.

Referenced by isString().

25 {
26  if (!str) return false;
27 
28  return true;
29 // return !isOption(str);
30 }

◆ isString() [2/2]

bool ossimArgumentParser::isString ( int  pos) const

return return true if specified parameter is an string, which can be any other string apart from an option.

Definition at line 235 of file ossimArgumentParser.cpp.

References isString(), theArgc, and theArgv.

236 {
237  return pos < *theArgc && isString(theArgv[pos]);
238 }
static bool isString(const char *str)
return return true if string is any other string apart from an option.

◆ match()

bool ossimArgumentParser::match ( int  pos,
const std::string &  str 
) const

return true if specified argument matches string.

Definition at line 257 of file ossimArgumentParser.cpp.

References theArgc, and theArgv.

Referenced by read().

258 {
259  return pos<*theArgc && str==theArgv[pos];
260 }

◆ numberOfParams()

int ossimArgumentParser::numberOfParams ( const std::string &  str,
const ossimParameter  value 
) const
Returns
The number of parameters of type value associated with specified option, or -1 if option not found

Definition at line 271 of file ossimArgumentParser.cpp.

References find(), theArgv, and ossimArgumentParser::ossimParameter::valid().

272 {
273  int pos=find(str);
274  if (pos<=0)
275  return -1;
276 
277  ++pos;
278  int num_params = 0;
279  while (param.valid(theArgv[pos+num_params]))
280  ++num_params;
281  return num_params;
282 }
int find(const std::string &str) const
return the position of an occurence of a string in the argument list.

◆ operator[]() [1/2]

char* ossimArgumentParser::operator[] ( int  pos)
inline

return char* argument at specificed position.

Definition at line 115 of file ossimArgumentParser.h.

115 { return theArgv[pos]; }

◆ operator[]() [2/2]

const char* ossimArgumentParser::operator[] ( int  pos) const
inline

return const char* argument at specificed position.

Definition at line 118 of file ossimArgumentParser.h.

118 { return theArgv[pos]; }

◆ read() [1/13]

bool ossimArgumentParser::read ( const std::string &  str)

search for an occurance of a string in the argument list, on sucess remove that occurance from the list and return true, otherwise return false.

Definition at line 331 of file ossimArgumentParser.cpp.

References find().

Referenced by ossimEquationUtil::execute(), ossimVerticesFinderTool::initialize(), ossimBandMergeTool::initialize(), ossimRegTool::initialize(), ossimPotraceTool::initialize(), ATP::ossimAtpTool::initialize(), ossimDemTool::initialize(), ossimPointCloudTool::initialize(), ossimTool::initialize(), ossimHlzTool::initialize(), ossimViewshedTool::initialize(), ossimSubImageTool::initialize(), ossimHdf5Tool::initialize(), ossimHillshadeTool::initialize(), ossimShorelineTool::initialize(), ossimBatchTest::initialize(), ossimChipProcTool::initialize(), ossimInit::parseEnvOptions(), ossimInit::parseNotifyOption(), and ossimChipProcTool::processRemainingArgs().

332 {
333  int pos=find(str);
334  if (pos<=0) return false;
335  remove(pos);
336  return true;
337 }
int find(const std::string &str) const
return the position of an occurence of a string in the argument list.

◆ read() [2/13]

bool ossimArgumentParser::read ( const std::string &  str,
ossimParameter  value1 
)

Definition at line 339 of file ossimArgumentParser.cpp.

References ossimArgumentParser::ossimParameter::assign(), find(), reportError(), theArgv, and ossimArgumentParser::ossimParameter::valid().

340 {
341  int pos=find(str);
342  if (pos<=0) return false;
343  if (!value1.valid(theArgv[pos+1]))
344  {
345  reportError("argument to `"+str+"` is missing");
346  return false;
347  }
348  value1.assign(theArgv[pos+1]);
349  remove(pos,2);
350  return true;
351 }
int find(const std::string &str) const
return the position of an occurence of a string in the argument list.
void reportError(const std::string &message, ossimErrorSeverity severity=OSSIM_CRITICAL)
report an error message by adding to the ErrorMessageMap.

◆ read() [3/13]

bool ossimArgumentParser::read ( const std::string &  str,
ossimParameter  value1,
ossimParameter  value2 
)

Definition at line 353 of file ossimArgumentParser.cpp.

References ossimArgumentParser::ossimParameter::assign(), find(), reportError(), theArgv, and ossimArgumentParser::ossimParameter::valid().

355 {
356  int pos=find(str);
357  if (pos<=0) return false;
358  if (!value1.valid(theArgv[pos+1]) ||
359  !value2.valid(theArgv[pos+2]))
360  {
361  reportError("argument to `"+str+"` is missing");
362  return false;
363  }
364  value1.assign(theArgv[pos+1]);
365  value2.assign(theArgv[pos+2]);
366  remove(pos,3);
367  return true;
368 }
int find(const std::string &str) const
return the position of an occurence of a string in the argument list.
void reportError(const std::string &message, ossimErrorSeverity severity=OSSIM_CRITICAL)
report an error message by adding to the ErrorMessageMap.

◆ read() [4/13]

bool ossimArgumentParser::read ( const std::string &  str,
ossimParameter  value1,
ossimParameter  value2,
ossimParameter  value3 
)

Definition at line 370 of file ossimArgumentParser.cpp.

References ossimArgumentParser::ossimParameter::assign(), find(), reportError(), theArgv, and ossimArgumentParser::ossimParameter::valid().

372 {
373  int pos=find(str);
374  if (pos<=0) return false;
375  if (!value1.valid(theArgv[pos+1]) ||
376  !value2.valid(theArgv[pos+2]) ||
377  !value3.valid(theArgv[pos+3]))
378  {
379  reportError("argument to `"+str+"` is missing");
380  return false;
381  }
382  value1.assign(theArgv[pos+1]);
383  value2.assign(theArgv[pos+2]);
384  value3.assign(theArgv[pos+3]);
385  remove(pos,4);
386  return true;
387 }
int find(const std::string &str) const
return the position of an occurence of a string in the argument list.
void reportError(const std::string &message, ossimErrorSeverity severity=OSSIM_CRITICAL)
report an error message by adding to the ErrorMessageMap.

◆ read() [5/13]

bool ossimArgumentParser::read ( const std::string &  str,
ossimParameter  value1,
ossimParameter  value2,
ossimParameter  value3,
ossimParameter  value4 
)

Definition at line 389 of file ossimArgumentParser.cpp.

References ossimArgumentParser::ossimParameter::assign(), find(), reportError(), theArgv, and ossimArgumentParser::ossimParameter::valid().

392 {
393  int pos=find(str);
394  if (pos<=0) return false;
395  if (!value1.valid(theArgv[pos+1]) ||
396  !value2.valid(theArgv[pos+2]) ||
397  !value3.valid(theArgv[pos+3]) ||
398  !value4.valid(theArgv[pos+4]))
399  {
400  reportError("argument to `"+str+"` is missing");
401  return false;
402  }
403  value1.assign(theArgv[pos+1]);
404  value2.assign(theArgv[pos+2]);
405  value3.assign(theArgv[pos+3]);
406  value4.assign(theArgv[pos+4]);
407  remove(pos,5);
408  return true;
409 }
int find(const std::string &str) const
return the position of an occurence of a string in the argument list.
void reportError(const std::string &message, ossimErrorSeverity severity=OSSIM_CRITICAL)
report an error message by adding to the ErrorMessageMap.

◆ read() [6/13]

bool ossimArgumentParser::read ( const std::string &  str,
ossimParameter  value1,
ossimParameter  value2,
ossimParameter  value3,
ossimParameter  value4,
ossimParameter  value5 
)

Definition at line 411 of file ossimArgumentParser.cpp.

References ossimArgumentParser::ossimParameter::assign(), find(), reportError(), theArgv, and ossimArgumentParser::ossimParameter::valid().

414 {
415  int pos=find(str);
416  if (pos<=0) return false;
417  if (!value1.valid(theArgv[pos+1]) ||
418  !value2.valid(theArgv[pos+2]) ||
419  !value3.valid(theArgv[pos+3]) ||
420  !value4.valid(theArgv[pos+4]) ||
421  !value5.valid(theArgv[pos+5]))
422  {
423  reportError("argument to `"+str+"` is missing");
424  return false;
425  }
426  value1.assign(theArgv[pos+1]);
427  value2.assign(theArgv[pos+2]);
428  value3.assign(theArgv[pos+3]);
429  value4.assign(theArgv[pos+4]);
430  value5.assign(theArgv[pos+5]);
431  remove(pos,6);
432  return true;
433 }
int find(const std::string &str) const
return the position of an occurence of a string in the argument list.
void reportError(const std::string &message, ossimErrorSeverity severity=OSSIM_CRITICAL)
report an error message by adding to the ErrorMessageMap.

◆ read() [7/13]

bool ossimArgumentParser::read ( const std::string &  str,
ossimParameter  value1,
ossimParameter  value2,
ossimParameter  value3,
ossimParameter  value4,
ossimParameter  value5,
ossimParameter  value6 
)

Definition at line 435 of file ossimArgumentParser.cpp.

References ossimArgumentParser::ossimParameter::assign(), find(), reportError(), theArgv, and ossimArgumentParser::ossimParameter::valid().

439 {
440  int pos=find(str);
441  if (pos<=0) return false;
442  if (!value1.valid(theArgv[pos+1]) ||
443  !value2.valid(theArgv[pos+2]) ||
444  !value3.valid(theArgv[pos+3]) ||
445  !value4.valid(theArgv[pos+4]) ||
446  !value5.valid(theArgv[pos+5]) ||
447  !value6.valid(theArgv[pos+6]))
448  {
449  reportError("argument to `"+str+"` is missing");
450  return false;
451  }
452  value1.assign(theArgv[pos+1]);
453  value2.assign(theArgv[pos+2]);
454  value3.assign(theArgv[pos+3]);
455  value4.assign(theArgv[pos+4]);
456  value5.assign(theArgv[pos+5]);
457  value6.assign(theArgv[pos+6]);
458  remove(pos,7);
459  return true;
460 }
int find(const std::string &str) const
return the position of an occurence of a string in the argument list.
void reportError(const std::string &message, ossimErrorSeverity severity=OSSIM_CRITICAL)
report an error message by adding to the ErrorMessageMap.

◆ read() [8/13]

bool ossimArgumentParser::read ( const std::string &  str,
std::vector< ossimString > &  param_list 
)

Alternate form for reading variable length arguments (must be comma-separated), e.g.,.

–input_files file1, file2, file3,file4 next_arg

Note that spaces between arguments are optional. The next_arg entry will not be considered part of the list since there's no comma separator and will be left on the argument array.

Parameters
strThe option string (with "-" or "--")
param_listVector to contain results as strings. Always cleared before populating
Returns
True if option found (param_list may be empty f no args followed).

Definition at line 462 of file ossimArgumentParser.cpp.

References find(), ossimString::length(), ossimString::split(), ossimString::string(), theArgc, and theArgv.

463 {
464  // This method reads a comma-separated list.
465  param_list.clear();
466 
467  int pos=find(str);
468  if (pos<=0)
469  return false;
470 
471  // Option is removed even if no values found:
472  remove(pos, 1);
473  bool includeNextItem = true;
474  while (pos < *theArgc)
475  {
476  // Check for occurence of next option:
477  if (theArgv[pos][0] == '-')
478  break;
479 
480  // Skip a comma surrounded by spaces:
481  ossimString arg = theArgv[pos];
482  if (arg == ",")
483  {
484  remove(pos, 1);
485  includeNextItem = true;
486  continue;
487  }
488 
489  if (!includeNextItem && (arg.string()[0] != ','))
490  break;
491 
492  // Handle comma separated with no spaces (i.e., multiple args reflected as one in theArgv):
493  vector<ossimString> sub_args = arg.split(",", true);
494  for (ossim_uint32 i=0; i<sub_args.size(); ++i)
495  param_list.push_back(sub_args[i]);
496 
497  // If current item ends with comma, the list continues:
498  if (arg[arg.length()-1] != ',')
499  includeNextItem = false;
500 
501  remove(pos, 1);
502  }
503 
504  return true;
505 }
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
int find(const std::string &str) const
return the position of an occurence of a string in the argument list.
std::string::size_type length() const
Definition: ossimString.h:408
unsigned int ossim_uint32
const std::string & string() const
Definition: ossimString.h:414

◆ read() [9/13]

bool ossimArgumentParser::read ( int  pos,
const std::string &  str 
)

if the argument value at the position pos matches specified string, and subsequent paramters are also matched then set the paramter values and remove the from the list of arguments.

if the argument value at the posotion pos matches specified string, and subsequent parameters are also matched then set the paramter values and remove the from the list of arguments.

Definition at line 509 of file ossimArgumentParser.cpp.

References match().

510 {
511  if (match(pos,str))
512  {
513  remove(pos,1);
514  return true;
515  }
516  else
517  {
518  return false;
519  }
520 }
bool match(int pos, const std::string &str) const
return true if specified argument matches string.

◆ read() [10/13]

bool ossimArgumentParser::read ( int  pos,
const std::string &  str,
ossimParameter  value1 
)

Definition at line 522 of file ossimArgumentParser.cpp.

References ossimArgumentParser::ossimParameter::assign(), match(), theArgv, and ossimArgumentParser::ossimParameter::valid().

523 {
524  if (match(pos,str) &&
525  value1.valid(theArgv[pos+1]))
526  {
527  value1.assign(theArgv[pos+1]);
528  remove(pos,2);
529  return true;
530  }
531  else
532  {
533  return false;
534  }
535 }
bool match(int pos, const std::string &str) const
return true if specified argument matches string.

◆ read() [11/13]

bool ossimArgumentParser::read ( int  pos,
const std::string &  str,
ossimParameter  value1,
ossimParameter  value2 
)

Definition at line 537 of file ossimArgumentParser.cpp.

References ossimArgumentParser::ossimParameter::assign(), match(), theArgv, and ossimArgumentParser::ossimParameter::valid().

538 {
539  if (match(pos,str) &&
540  value1.valid(theArgv[pos+1]) &&
541  value2.valid(theArgv[pos+2]))
542  {
543  value1.assign(theArgv[pos+1]);
544  value2.assign(theArgv[pos+2]);
545  remove(pos,3);
546  return true;
547  }
548  else
549  {
550  return false;
551  }
552 }
bool match(int pos, const std::string &str) const
return true if specified argument matches string.

◆ read() [12/13]

bool ossimArgumentParser::read ( int  pos,
const std::string &  str,
ossimParameter  value1,
ossimParameter  value2,
ossimParameter  value3 
)

Definition at line 554 of file ossimArgumentParser.cpp.

References ossimArgumentParser::ossimParameter::assign(), match(), theArgv, and ossimArgumentParser::ossimParameter::valid().

555 {
556  if (match(pos,str) &&
557  value1.valid(theArgv[pos+1]) &&
558  value2.valid(theArgv[pos+2]) &&
559  value3.valid(theArgv[pos+3]))
560  {
561  value1.assign(theArgv[pos+1]);
562  value2.assign(theArgv[pos+2]);
563  value3.assign(theArgv[pos+3]);
564  remove(pos,4);
565  return true;
566  }
567  else
568  {
569  return false;
570  }
571 }
bool match(int pos, const std::string &str) const
return true if specified argument matches string.

◆ read() [13/13]

bool ossimArgumentParser::read ( int  pos,
const std::string &  str,
ossimParameter  value1,
ossimParameter  value2,
ossimParameter  value3,
ossimParameter  value4 
)

Definition at line 573 of file ossimArgumentParser.cpp.

References ossimArgumentParser::ossimParameter::assign(), match(), theArgv, and ossimArgumentParser::ossimParameter::valid().

574 {
575  if (match(pos,str) &&
576  value1.valid(theArgv[pos+1]) &&
577  value2.valid(theArgv[pos+2]) &&
578  value3.valid(theArgv[pos+3]) &&
579  value4.valid(theArgv[pos+4]))
580  {
581  value1.assign(theArgv[pos+1]);
582  value2.assign(theArgv[pos+2]);
583  value3.assign(theArgv[pos+3]);
584  value4.assign(theArgv[pos+4]);
585  remove(pos,5);
586  return true;
587  }
588  else
589  {
590  return false;
591  }
592 }
bool match(int pos, const std::string &str) const
return true if specified argument matches string.

◆ remove()

void ossimArgumentParser::remove ( int  pos,
int  num = 1 
)

remove one or more arguments from the argv argument list, and decrement the argc respectively.

Definition at line 284 of file ossimArgumentParser.cpp.

References theArgc, and theArgv.

Referenced by ossimVerticesFinderTool::initialize().

285 {
286  if (num==0) return;
287 
288  for(;pos+num<*theArgc;++pos)
289  {
290  theArgv[pos]=theArgv[pos+num];
291  }
292  for(;pos<*theArgc;++pos)
293  {
294  theArgv[pos]=0;
295  }
296  *theArgc-=num;
297 }

◆ reportError()

void ossimArgumentParser::reportError ( const std::string &  message,
ossimErrorSeverity  severity = OSSIM_CRITICAL 
)

report an error message by adding to the ErrorMessageMap.

Definition at line 605 of file ossimArgumentParser.cpp.

References theErrorMessageMap.

Referenced by read(), and reportRemainingOptionsAsUnrecognized().

606 {
607  theErrorMessageMap[message]=severity;
608 }
ossimErrorMessageMap theErrorMessageMap

◆ reportRemainingOptionsAsUnrecognized()

void ossimArgumentParser::reportRemainingOptionsAsUnrecognized ( ossimErrorSeverity  severity = OSSIM_BENIGN)

for each remaining option report it as an unrecongnized.

Definition at line 610 of file ossimArgumentParser.cpp.

References argc(), getApplicationName(), ossimApplicationUsage::getCommandLineOptions(), isOption(), reportError(), theArgv, and theUsage.

Referenced by ossimBatchTest::initialize(), and ossimChipProcTool::processRemainingArgs().

611 {
612  std::set<std::string> options;
613  if (theUsage)
614  {
615  // parse the usage options to get all the option that the application can potential handle.
616  for(ossimApplicationUsage::UsageMap::const_iterator itr=theUsage->getCommandLineOptions().begin();
617  itr!=theUsage->getCommandLineOptions().end();
618  ++itr)
619  {
620  const std::string& option = itr->first;
621  std::string::size_type prevpos = 0, pos = 0;
622  while ((pos=option.find(' ',prevpos))!=std::string::npos)
623  {
624  if (option[prevpos]=='-')
625  {
626  options.insert(std::string(option,prevpos,pos-prevpos));
627  }
628  prevpos=pos+1;
629  }
630  if (option[prevpos]=='-')
631  {
632 
633  options.insert(std::string(option,prevpos,std::string::npos));
634  }
635  }
636 
637  }
638 
639  for(int pos=1;pos<argc();++pos)
640  {
641  // if an option and havn't been previous querried for report as unrecognized.
642  if (isOption(pos) && options.find(theArgv[pos])==options.end())
643  {
644  reportError(getApplicationName() +": unrecognized option "+theArgv[pos],severity);
645  }
646  }
647 }
std::string getApplicationName() const
return the application name, as specified by argv[0]
const UsageMap & getCommandLineOptions() const
ossimApplicationUsage * theUsage
void reportError(const std::string &message, ossimErrorSeverity severity=OSSIM_CRITICAL)
report an error message by adding to the ErrorMessageMap.
static bool isOption(const char *str)
return return true if specified string is an option in the form of -option or –option ...
int & argc()
return the argument count.

◆ setApplicationUsage()

void ossimArgumentParser::setApplicationUsage ( ossimApplicationUsage usage)
inline

Definition at line 104 of file ossimArgumentParser.h.

References usage().

104 { theUsage = usage; }
void usage()
ossimApplicationUsage * theUsage

◆ writeErrorMessages()

void ossimArgumentParser::writeErrorMessages ( std::ostream &  output,
ossimErrorSeverity  sevrity = OSSIM_BENIGN 
)

write out error messages at an above specified .

Definition at line 659 of file ossimArgumentParser.cpp.

References getApplicationName(), and theErrorMessageMap.

Referenced by ossimBatchTest::initialize(), ossimChipProcTool::initialize(), and ossimChipProcTool::processRemainingArgs().

660 {
661  for(ossimErrorMessageMap::iterator itr=theErrorMessageMap.begin();
662  itr!=theErrorMessageMap.end();
663  ++itr)
664  {
665  if (itr->second>=severity)
666  {
667  output<< getApplicationName() << ": " << itr->first << std::endl;
668  }
669  }
670 }
std::string getApplicationName() const
return the application name, as specified by argv[0]
ossimErrorMessageMap theErrorMessageMap

Member Data Documentation

◆ theArgc

int* ossimArgumentParser::theArgc
protected

◆ theArgv

char** ossimArgumentParser::theArgv
protected

◆ theErrorMessageMap

ossimErrorMessageMap ossimArgumentParser::theErrorMessageMap
protected

Definition at line 243 of file ossimArgumentParser.h.

Referenced by errors(), getErrorMessageMap(), reportError(), and writeErrorMessages().

◆ theMemAllocated

bool ossimArgumentParser::theMemAllocated
protected

Definition at line 245 of file ossimArgumentParser.h.

Referenced by insert(), and ~ossimArgumentParser().

◆ theUsage

ossimApplicationUsage* ossimArgumentParser::theUsage
protected

The documentation for this class was generated from the following files: