57 G_EXCEPTION( InvalidSpecification ,
"invalid options specification string" ) ;
71 const std::string & description_ ,
72 const std::string & description_extra_ ,
73 bool v_ ,
const std::string & vd_ ,
unsigned int level_ ) :
74 c(c_) , name(name_) , description(description_) ,
75 description_extra(description_extra_) ,
76 valued(v_) , hidden(description_.empty()||level_==0U) ,
77 value_description(vd_) , level(level_) {}
80 GetOpt(
const Arg & arg ,
const std::string & spec ,
81 char sep_major =
'|' ,
char sep_minor =
'/' ,
char escape =
'\\' ) ;
117 std::string
usageSummary(
const std::string & exe ,
const std::string &
args ,
130 bool level_exact =
false ,
bool extra =
true )
const ;
133 void showUsage( std::ostream & stream ,
const std::string & exe ,
134 const std::string & args ,
const std::string & introducer =
introducerDefault() ,
136 size_type wrap_width =
wrapDefault() ,
bool extra =
true )
const ;
142 void showUsage( std::ostream & stream ,
const std::string & args ,
bool verbose )
const ;
150 void showErrors( std::ostream & stream , std::string prefix_1 ,
151 std::string prefix_2 = std::string(
": ") )
const ;
156 void showErrors( std::ostream & stream )
const ;
159 void show( std::ostream & stream , std::string prefix )
const ;
162 bool contains(
char switch_letter )
const ;
166 bool contains(
const std::string & switch_name )
const ;
170 std::string
value(
const std::string & switch_name )
const ;
176 std::string
value(
char switch_letter )
const ;
183 typedef std::map<std::string,SwitchSpec> SwitchSpecMap ;
184 typedef std::pair<bool,std::string> Value ;
185 typedef std::map<char,Value> SwitchMap ;
187 void operator=(
const GetOpt & ) ;
189 void parseSpec(
const std::string & spec ,
char ,
char ,
char ) ;
190 void addSpec(
const std::string & ,
char c ,
const std::string & ,
191 const std::string & ,
const std::string & ,
bool ,
192 const std::string & ,
unsigned int ) ;
193 size_type parseArgs(
const Arg & args_in ) ;
194 bool isOldSwitch(
const std::string & arg )
const ;
195 bool isNewSwitch(
const std::string & arg )
const ;
196 bool isSwitchSet(
const std::string & arg )
const ;
197 void processSwitch(
char c ) ;
198 void processSwitch(
char c ,
const std::string &
value ) ;
199 void processSwitch(
const std::string & s ) ;
200 void processSwitch(
const std::string & s ,
const std::string &
value ) ;
201 bool valued(
char c )
const ;
202 bool valued(
const std::string & )
const ;
203 void errorNoValue(
char c ) ;
204 void errorNoValue(
const std::string & ) ;
205 void errorUnknownSwitch(
char c ) ;
206 void errorUnknownSwitch(
const std::string & ) ;
207 char key(
const std::string & s )
const ;
208 void remove( size_type n ) ;
209 bool valid(
const std::string & )
const ;
210 bool valid(
char c )
const ;
211 std::string usageSummaryPartOne( Level )
const ;
212 std::string usageSummaryPartTwo( Level )
const ;
213 std::string usageHelpCore(
const std::string & , Level , size_type ,
214 size_type ,
bool ,
bool )
const ;
215 static size_type widthLimit( size_type ) ;
216 static bool visible( SwitchSpecMap::const_iterator , Level ,
bool ) ;
217 static size_type eqPos(
const std::string & ) ;
218 static std::string eqValue(
const std::string & , size_type ) ;
221 SwitchSpecMap m_spec_map ;
bool contains(char switch_letter) const
Returns true if the command line contains the given switch.
void showErrors(std::ostream &stream, std::string prefix_1, std::string prefix_2=std::string(": ")) const
A convenience function which streams out each errorList() item to the given stream, prefixed with the given prefix(es).
Strings errorList() const
Returns the list of errors.
std::string description_extra
std::list< std::string > Strings
A std::list of std::strings.
bool hasErrors() const
Returns true if there are errors.
std::string value_description
std::string::size_type size_type
A std::size_t type.
void show(std::ostream &stream, std::string prefix) const
For debugging.
std::string value(const std::string &switch_name) const
Returns the value related to the given value-based switch.
A private implementation structure used by G::GetOpt.
GetOpt(const Arg &arg, const std::string &spec, char sep_major= '|', char sep_minor= '/', char escape= '\\')
Constructor taking a Arg reference and a specification string.
static size_type tabDefault()
Returns a default tab-stop.
A command line switch parser.
Arg args() const
Returns all the non-switch command-line arguments.
std::string usageHelp(Level level=levelDefault(), size_type tab_stop=tabDefault(), size_type wrap_width=wrapDefault(), bool level_exact=false, bool extra=true) const
Returns a multi-line string giving help on each switch.
SwitchSpec(char c_, const std::string &name_, const std::string &description_, const std::string &description_extra_, bool v_, const std::string &vd_, unsigned int level_)
static size_type wrapDefault()
Returns a default word-wrapping width.
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
static Level levelDefault()
Returns the default level.
A class which holds a represention of the argc/argv command line array, and supports simple command-l...
std::string::size_type size_type
std::string usageSummary(const std::string &exe, const std::string &args, const std::string &introducer=introducerDefault(), Level level=levelDefault(), size_type wrap_width=wrapDefault()) const
Returns a one-line usage summary, as "usage:
".
static std::string introducerDefault()
Returns "usage: ".
Used by G::GetOpt for extra type safety.
std::string usageSummarySwitches(Level level=levelDefault()) const
Returns the one-line summary of switches.
void showUsage(std::ostream &stream, const std::string &exe, const std::string &args, const std::string &introducer=introducerDefault(), Level level=levelDefault(), size_type tab_stop=tabDefault(), size_type wrap_width=wrapDefault(), bool extra=true) const
Streams out multi-line usage text using usageSummary() and usageHelp().