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

#include <ossimApplicationUsage.h>

Public Types

enum  Type { OSSIM_COMMAND_LINE_OPTION = 0x1, OSSIM_ENVIRONMENTAL_VARIABLE = 0x2 }
 
typedef std::map< ossimString, ossimString, ossimStringLtstrUsageMap
 

Public Member Functions

 ossimApplicationUsage ()
 
 ossimApplicationUsage (const ossimString &commandLineUsage)
 
void setApplicationName (const ossimString &name)
 
const ossimStringgetApplicationName () const
 
void setDescription (const ossimString &desc)
 
const ossimStringgetDescription () const
 
void addUsageExplanation (Type type, const ossimString &option, const ossimString &explanation)
 
void setCommandLineUsage (const ossimString &explanation)
 
const ossimStringgetCommandLineUsage () const
 
void addCommandLineOption (const ossimString &option, const ossimString &explanation)
 
const UsageMapgetCommandLineOptions () const
 
void addEnvironmentalVariable (const ossimString &option, const ossimString &explanation)
 
const UsageMapgetEnvironmentalVariables () const
 
void getFormatedString (ossimString &str, const UsageMap &um, unsigned int widthOfOutput=80)
 
void write (std::ostream &output, const UsageMap &um, unsigned int widthOfOutput=80)
 
void write (std::ostream &output, unsigned int type=OSSIM_COMMAND_LINE_OPTION|OSSIM_ENVIRONMENTAL_VARIABLE, unsigned int widthOfOutput=80)
 

Static Public Member Functions

static ossimApplicationUsageinstance ()
 

Protected Attributes

ossimString theApplicationName
 
ossimString theDescription
 
ossimString theCommandLineUsage
 
UsageMap theCommandLineOptions
 
UsageMap theEnvironmentalVariables
 

Detailed Description

Definition at line 15 of file ossimApplicationUsage.h.

Member Typedef Documentation

◆ UsageMap

Definition at line 25 of file ossimApplicationUsage.h.

Member Enumeration Documentation

◆ Type

Enumerator
OSSIM_COMMAND_LINE_OPTION 
OSSIM_ENVIRONMENTAL_VARIABLE 

Definition at line 33 of file ossimApplicationUsage.h.

Constructor & Destructor Documentation

◆ ossimApplicationUsage() [1/2]

ossimApplicationUsage::ossimApplicationUsage ( )
inline

Definition at line 21 of file ossimApplicationUsage.h.

21 {}

◆ ossimApplicationUsage() [2/2]

ossimApplicationUsage::ossimApplicationUsage ( const ossimString commandLineUsage)

Definition at line 13 of file ossimApplicationUsage.cpp.

13  :
14  theCommandLineUsage(commandLineUsage)
15 {
16 }

Member Function Documentation

◆ addCommandLineOption()

void ossimApplicationUsage::addCommandLineOption ( const ossimString option,
const ossimString explanation 
)

◆ addEnvironmentalVariable()

void ossimApplicationUsage::addEnvironmentalVariable ( const ossimString option,
const ossimString explanation 
)

Definition at line 74 of file ossimApplicationUsage.cpp.

References theEnvironmentalVariables.

Referenced by addUsageExplanation().

75 {
76  theEnvironmentalVariables[option]=explanation;
77 }

◆ addUsageExplanation()

void ossimApplicationUsage::addUsageExplanation ( Type  type,
const ossimString option,
const ossimString explanation 
)

Definition at line 42 of file ossimApplicationUsage.cpp.

References addCommandLineOption(), addEnvironmentalVariable(), OSSIM_COMMAND_LINE_OPTION, and OSSIM_ENVIRONMENTAL_VARIABLE.

Referenced by ApplicationUsageProxy::ApplicationUsageProxy().

43 {
44  switch(type)
45  {
47  addCommandLineOption(option,explanation);
48  break;
50  addEnvironmentalVariable(option,explanation);
51  break;
52  }
53 }
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
void addEnvironmentalVariable(const ossimString &option, const ossimString &explanation)

◆ getApplicationName()

const ossimString & ossimApplicationUsage::getApplicationName ( ) const

Definition at line 28 of file ossimApplicationUsage.cpp.

References theApplicationName.

29 {
30  return theApplicationName;
31 }

◆ getCommandLineOptions()

const ossimApplicationUsage::UsageMap & ossimApplicationUsage::getCommandLineOptions ( ) const

◆ getCommandLineUsage()

const ossimString & ossimApplicationUsage::getCommandLineUsage ( ) const

Definition at line 59 of file ossimApplicationUsage.cpp.

References theCommandLineUsage.

Referenced by write().

60 {
61  return theCommandLineUsage;
62 }

◆ getDescription()

const ossimString & ossimApplicationUsage::getDescription ( ) const

Definition at line 37 of file ossimApplicationUsage.cpp.

References theDescription.

38 {
39  return theDescription;
40 }

◆ getEnvironmentalVariables()

const ossimApplicationUsage::UsageMap & ossimApplicationUsage::getEnvironmentalVariables ( ) const

Definition at line 78 of file ossimApplicationUsage.cpp.

References theEnvironmentalVariables.

Referenced by write().

79 {
81 }

◆ getFormatedString()

void ossimApplicationUsage::getFormatedString ( ossimString str,
const UsageMap um,
unsigned int  widthOfOutput = 80 
)

Definition at line 83 of file ossimApplicationUsage.cpp.

References ossimString::assign(), ossimString::begin(), ossimString::find(), ossimString::length(), ossim::max(), ossim::min(), and ossimString::replace().

Referenced by write().

84 {
85 
86  unsigned int maxNumCharsInOptions = 0;
87  ossimApplicationUsage::UsageMap::const_iterator citr;
88  for(citr=um.begin();
89  citr!=um.end();
90  ++citr)
91  {
92  maxNumCharsInOptions = ossim::max(maxNumCharsInOptions,(unsigned int)citr->first.length());
93  }
94 
95  unsigned int fullWidth = widthOfOutput;
96  unsigned int optionPos = 2;
97  unsigned int explanationPos = 2+maxNumCharsInOptions+2;
98  unsigned int explanationWidth = fullWidth-explanationPos;
99 
100  ossimString line;
101 
102  for(citr=um.begin();
103  citr!=um.end();
104  ++citr)
105  {
106  line.assign(fullWidth,' ');
107  line.replace(optionPos,citr->first.length(),citr->first);
108 
109  const ossimString& explanation = citr->second;
110  std::string::size_type pos = 0;
111  std::string::size_type offset = 0;
112  bool firstInLine = true;
113  while (pos<explanation.length())
114  {
115  if (firstInLine) offset = 0;
116 
117  // skip any leading white space.
118  while (pos<explanation.length() && *(explanation.begin()+pos)==' ')
119  {
120  if (firstInLine) ++offset;
121  ++pos;
122  }
123 
124  firstInLine = false;
125 
126  std::string::size_type width = ossim::min((ossim_int64)(explanation.length()-pos),
127  (ossim_int64)(explanationWidth-offset));
128  std::string::size_type slashn_pos = explanation.find('\n',pos);
129 
130  unsigned int extraSkip = 0;
131  bool concatinated = false;
132  if (slashn_pos!=std::string::npos)
133  {
134  if (slashn_pos<pos+width)
135  {
136  width = slashn_pos-pos;
137  ++extraSkip;
138  firstInLine = true;
139  }
140  else if (slashn_pos==pos+width)
141  {
142  ++extraSkip;
143  firstInLine = true;
144  }
145  }
146 
147  if (pos+width<explanation.length())
148  {
149  // now reduce width until we get a space or a return
150  // so that we ensure that whole words are printed.
151  while (width>0 &&
152  *(explanation.begin()+(pos+width))!=' ' &&
153  *(explanation.begin()+(pos+width))!='\n') --width;
154 
155  if (width==0)
156  {
157  // word must be longer than a whole line so will need
158  // to concatinate it.
159  width = explanationWidth-1;
160  concatinated = true;
161  }
162  }
163 
164  line.replace(explanationPos+offset,explanationWidth, explanation, pos, width);
165 
166  if (concatinated) { str += line; str += "-\n"; }
167  else { str += line; str += "\n"; }
168 
169  // move to the next line of output.
170  line.assign(fullWidth,' ');
171 
172  pos += width+extraSkip;
173 
174 
175  }
176 
177  }
178 }
T max(T a, T b)
Definition: ossimCommon.h:236
std::string::size_type length() const
Definition: ossimString.h:408
std::string::iterator begin()
Definition: ossimString.h:420
T min(T a, T b)
Definition: ossimCommon.h:203
std::string & replace(std::string::size_type pos, std::string::size_type n, const std::string &s)
Replaces a substring of *this with the string s.
Definition: ossimString.h:870
long long ossim_int64
std::string & assign(std::string::size_type n, char c)
Erases the existing characters and replaces them by n copies of c.
Definition: ossimString.h:865
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
Definition: ossimString.h:753

◆ instance()

ossimApplicationUsage * ossimApplicationUsage::instance ( )
static

Definition at line 18 of file ossimApplicationUsage.cpp.

Referenced by ApplicationUsageProxy::ApplicationUsageProxy().

19 {
20  static ossimApplicationUsage theApplicationUsage;
21  return &theApplicationUsage;
22 }

◆ setApplicationName()

void ossimApplicationUsage::setApplicationName ( const ossimString name)

◆ setCommandLineUsage()

void ossimApplicationUsage::setCommandLineUsage ( const ossimString explanation)

◆ setDescription()

void ossimApplicationUsage::setDescription ( const ossimString desc)

◆ write() [1/2]

void ossimApplicationUsage::write ( std::ostream &  output,
const UsageMap um,
unsigned int  widthOfOutput = 80 
)

Definition at line 180 of file ossimApplicationUsage.cpp.

References getFormatedString().

Referenced by ossimEquationUtil::execute(), ossimTool::initialize(), ossimPointCloudTool::usage(), ossimBatchTest::usage(), ossimAutRegUtil::usage(), ossimImageUtil::usage(), ossimChipperUtil::usage(), and write().

181 {
182  ossimString str;
183  getFormatedString(str, um, widthOfOutput);
184  output << str << std::endl;
185 }
void getFormatedString(ossimString &str, const UsageMap &um, unsigned int widthOfOutput=80)

◆ write() [2/2]

void ossimApplicationUsage::write ( std::ostream &  output,
unsigned int  type = OSSIM_COMMAND_LINE_OPTION|OSSIM_ENVIRONMENTAL_VARIABLE,
unsigned int  widthOfOutput = 80 
)

Definition at line 187 of file ossimApplicationUsage.cpp.

References ossimString::c_str(), getCommandLineOptions(), getCommandLineUsage(), getEnvironmentalVariables(), OSSIM_COMMAND_LINE_OPTION, OSSIM_ENVIRONMENTAL_VARIABLE, ossimString::size(), theDescription, and write().

188 {
189 
190  output << "Usage: "<<getCommandLineUsage()<<std::endl;
191  if(theDescription.size()>0)
192  {
193  // TODO: take into account "widthOfOutput"
194  output << "\nDescription:\n" << theDescription.c_str() << "\n"
195  << std::endl;
196  }
197 
198  bool needspace = false;
199  if ((type&OSSIM_COMMAND_LINE_OPTION) && !getCommandLineOptions().empty())
200  {
201  // if (needspace) output << std::endl;
202  output << "Options:"<<std::endl;
203  write(output,getCommandLineOptions(),widthOfOutput);
204  needspace = true;
205  }
206 
208  {
209  if (needspace) output << std::endl;
210  output << "Environmental Variables:"<<std::endl;
211  write(output,getEnvironmentalVariables(),widthOfOutput);
212  needspace = true;
213  }
214 
215 }
void write(std::ostream &output, const UsageMap &um, unsigned int widthOfOutput=80)
const UsageMap & getEnvironmentalVariables() const
const UsageMap & getCommandLineOptions() const
std::string::size_type size() const
Definition: ossimString.h:405
const ossimString & getCommandLineUsage() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396

Member Data Documentation

◆ theApplicationName

ossimString ossimApplicationUsage::theApplicationName
protected

Definition at line 63 of file ossimApplicationUsage.h.

Referenced by getApplicationName(), and setApplicationName().

◆ theCommandLineOptions

UsageMap ossimApplicationUsage::theCommandLineOptions
protected

Definition at line 66 of file ossimApplicationUsage.h.

Referenced by addCommandLineOption(), and getCommandLineOptions().

◆ theCommandLineUsage

ossimString ossimApplicationUsage::theCommandLineUsage
protected

Definition at line 65 of file ossimApplicationUsage.h.

Referenced by getCommandLineUsage(), and setCommandLineUsage().

◆ theDescription

ossimString ossimApplicationUsage::theDescription
protected

Definition at line 64 of file ossimApplicationUsage.h.

Referenced by getDescription(), setDescription(), and write().

◆ theEnvironmentalVariables

UsageMap ossimApplicationUsage::theEnvironmentalVariables
protected

Definition at line 67 of file ossimApplicationUsage.h.

Referenced by addEnvironmentalVariable(), and getEnvironmentalVariables().


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