fix8  version 1.4.0
Open Source C++ FIX Framework
UsageMan Class Reference

Convenient program help/usage wrapper. Generates a standardised usage message. More...

#include <usage.hpp>

Public Member Functions

 UsageMan (const std::string &prognm, const std::string &argstr, const std::string &params, int splen=3, int argoptlen=23)
 
virtual ~UsageMan ()
 Dtor. More...
 
bool add (const char sw, const std::string &lsw, const std::string &help)
 
void add (const std::string &xtr)
 
void setdesc (const std::string &desc)
 
void print (std::ostream &os) const
 

Private Types

using OPTEL = std::map< const char, const std::pair< const std::string, const std::string >>
 

Private Attributes

const std::string prognm_
 
const std::string params_
 
std::string argstr_
 
std::string description_
 
OPTEL optels_
 
std::list< std::string > xtrlines_
 
const int splen_
 
const int argoptlen_
 

Detailed Description

Convenient program help/usage wrapper. Generates a standardised usage message.

Definition at line 42 of file usage.hpp.

Member Typedef Documentation

using UsageMan::OPTEL = std::map<const char, const std::pair<const std::string, const std::string>>
private

Definition at line 46 of file usage.hpp.

Constructor & Destructor Documentation

UsageMan::UsageMan ( const std::string &  prognm,
const std::string &  argstr,
const std::string &  params,
int  splen = 3,
int  argoptlen = 23 
)
inline

Ctor.

Parameters
prognmprogram name
argstrprogram arguments string
paramsprogram non-switched arguments string
splentab width
argoptlenoption argument width

Definition at line 58 of file usage.hpp.

60  : prognm_(prognm), params_(params), argstr_(argstr), splen_(splen), argoptlen_(argoptlen)
61  {
62  std::sort(argstr_.begin(), argstr_.end());
63  }
std::string argstr_
Definition: usage.hpp:45
const int splen_
Definition: usage.hpp:49
const std::string prognm_
Definition: usage.hpp:44
const int argoptlen_
Definition: usage.hpp:49
const std::string params_
Definition: usage.hpp:44
virtual UsageMan::~UsageMan ( )
inlinevirtual

Dtor.

Definition at line 66 of file usage.hpp.

66 {}

Member Function Documentation

bool UsageMan::add ( const char  sw,
const std::string &  lsw,
const std::string &  help 
)
inline

Add a command line option.

Parameters
swthe single character switch
lswthe string switch (long version)
helpthe associated help string
Returns
true on success

Definition at line 73 of file usage.hpp.

Referenced by print_usage().

74  {
75  return optels_.insert({sw, std::pair<const std::string, const std::string>(lsw, help)}).second;
76  }
OPTEL optels_
Definition: usage.hpp:47
void UsageMan::add ( const std::string &  xtr)
inline

Add an extra help line. Lines prefixed with '@' are indented one tabstop.

Parameters
xtrthe extra help line

Definition at line 80 of file usage.hpp.

81  {
82  std::string topush(xtr);
83  std::string::size_type spos;
84  while ((spos = topush.find_first_of('@')) != std::string::npos)
85  topush.replace(spos, 1, std::string(splen_, ' '));
86  xtrlines_.push_back(topush);
87  }
std::list< std::string > xtrlines_
Definition: usage.hpp:48
const int splen_
Definition: usage.hpp:49
void UsageMan::print ( std::ostream &  os) const
inline

Insert the formatted usage into the given output stream.

Parameters
osthe stream to insert to

Definition at line 95 of file usage.hpp.

References spacer.

Referenced by print_usage().

96  {
97  if (!description_.empty())
98  os << description_ << std::endl << std::endl;
99  os << "Usage: " << prognm_ << " [-";
100  for (std::string::const_iterator itr(argstr_.begin()); itr != argstr_.end(); ++itr)
101  if (*itr != ':')
102  os << *itr;
103  os << "] " << params_ << std::endl;
104  const std::string spacer(splen_, ' ');
105  for (OPTEL::const_iterator itr(optels_.begin()); itr != optels_.end(); ++itr)
106  {
107  std::ostringstream ostr;
108  ostr << '-' << itr->first << ",--" << itr->second.first;
109  os << spacer << std::left << std::setw(argoptlen_) << ostr.str()
110  << ' ' << itr->second.second << std::endl;
111  }
112  for (std::list<std::string>::const_iterator itr(xtrlines_.begin()); itr != xtrlines_.end(); ++itr)
113  os << *itr << std::endl;
114  }
std::string argstr_
Definition: usage.hpp:45
std::list< std::string > xtrlines_
Definition: usage.hpp:48
const int splen_
Definition: usage.hpp:49
OPTEL optels_
Definition: usage.hpp:47
const std::string prognm_
Definition: usage.hpp:44
string spacer
Definition: f8c.cpp:96
const int argoptlen_
Definition: usage.hpp:49
std::string description_
Definition: usage.hpp:45
const std::string params_
Definition: usage.hpp:44
void UsageMan::setdesc ( const std::string &  desc)
inline

Set the usage description string.

Parameters
descthe description string

Definition at line 91 of file usage.hpp.

Referenced by print_usage().

91 { description_ = desc; }
std::string description_
Definition: usage.hpp:45

Member Data Documentation

const int UsageMan::argoptlen_
private

Definition at line 49 of file usage.hpp.

std::string UsageMan::argstr_
private

Definition at line 45 of file usage.hpp.

std::string UsageMan::description_
private

Definition at line 45 of file usage.hpp.

OPTEL UsageMan::optels_
private

Definition at line 47 of file usage.hpp.

const std::string UsageMan::params_
private

Definition at line 44 of file usage.hpp.

const std::string UsageMan::prognm_
private

Definition at line 44 of file usage.hpp.

const int UsageMan::splen_
private

Definition at line 49 of file usage.hpp.

std::list<std::string> UsageMan::xtrlines_
private

Definition at line 48 of file usage.hpp.


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