pktools
2.6.7
Processing Kernel for geospatial data
|
#include <Optionpk.h>
Public Member Functions | |
Optionpk () | |
default constructor | |
Optionpk (const std::string &shortName, const std::string &longName, const std::string &helpInfo) | |
constructor for option without default value More... | |
Optionpk (const std::string &shortName, const std::string &longName, const std::string &helpInfo, const T &defaultValue, short hide=0) | |
constructor for option with default value. Option can be hidden for help info More... | |
~Optionpk () | |
default destructor | |
void | setHelp (const std::string &helpInfo) |
set help information | |
void | setHide (short hide) |
hide option from short help -h (1) or make invisible to short and long help –help (2) | |
bool | retrieveOption (int argc, const std::vector< std::string > &argv) |
read option from command line (use for all options!), std::string implementation More... | |
bool | retrieveOption (int argc, char **argv) |
read option from command line (use for all options!) More... | |
void | setAll (const std::string &shortName, const std::string &longName, const std::string &helpInfo) |
set all attributes of the option, except default and hide | |
void | setAll (const std::string &shortName, const std::string &longName, const std::string &helpInfo, const T &defaultValue, short hide) |
set all attributes of the option | |
void | setDefault (const T &defaultValue) |
set a default value for the option | |
std::string | getDefaultValue () const |
void | setShortName (const std::string &shortName) |
set the short name to be used as -shortName | |
void | setLongName (const std::string &longName) |
set the long name to be used as –longName | |
std::string | getShortName () const |
get the short name to be used as -shortName | |
std::string | getLongName () const |
get the long name to be used as –longName | |
std::string | getHelp () const |
get help info stored in m_help | |
std::vector< T >::const_iterator | findSubstring (const T &argument) const |
template<> | |
void | setAll (const std::string &shortName, const std::string &longName, const std::string &helpInfo) |
specialization for bool | |
template<> | |
void | setAll (const std::string &shortName, const std::string &longName, const std::string &helpInfo, const bool &defaultValue, short hide) |
specialization for bool | |
template<> | |
Optionpk (const std::string &shortName, const std::string &longName, const std::string &helpInfo) | |
specialization for bool | |
template<> | |
Optionpk (const std::string &shortName, const std::string &longName, const std::string &helpInfo, const bool &defaultValue, short hide) | |
specialization for bool | |
template<> | |
std::vector< std::string >::const_iterator | findSubstring (const std::string &argument) const |
Static Public Member Functions | |
static std::string | getGPLv3License () |
get license info | |
Friends | |
template<class T1 > | |
std::ostream & | operator<< (std::ostream &os, const Optionpk< T1 > &theOption) |
print values for this option | |
Class to implement command line options. With the constructor you can define an option, in both short -
and long --
format, of a specific type, help information and a default value.
This class inherits from std::vector, so the option variable is a vector, supporting multiple inputs for the same option (e.g., –input file1 [–input file2 ...]. Several command line option formats are supported:
-shortOption value
-shortOption=value
--longOption value
--longOption=value
-shortOption
(no value for boolean options, which are automatically set by invoking the option)--longOption
(no value for boolean options, which are automatically set by invoking the option)Option names should have regular characters and no white space in them. Some names are reserved and can not be used either:
h
or long option help
: shows usagehelp
shows long help infolicense
: shows license infoversion
: shows current version of pktoolsdoxygen
: shows help info in table format, ready to be included in doxygenA call to member function retrieveOption reads the command line arguments and initializes the object (vector). Make sure to call this member function before using the option object in your main program (or a segmentation error due to an un-initialized vector will occur).
All calls to retrieveOption should reside in a try{} block. If one of the reserved options
license
version
is used, an exception of type std::string is thrown. This can be caught with a catch(string predefinedString) right after the try block, where the message can be sent to stdout and the program can be ended.Similarly, if help is invoked with the short option -h
or long option --help
, the main program is informed by the return value false
of retrieveOption (for any option). An example how to use Optionpk is shown in pktestOption.cc
Definition at line 106 of file Optionpk.h.
|
inline |
constructor for option without default value
constructor without default value
shortName is option invoked with -
longName is option invoked with --
helpInfo is the help message that is shown when option -h or –help is invoked
Definition at line 211 of file Optionpk.h.
|
inline |
constructor for option with default value. Option can be hidden for help info
constructor with default value.
shortName is option invoked with -
longName is option invoked with --
helpInfo is the help message that is shown when option -h or –help is invoked
defaultValue is default value of the option (first value of vector: option[0])
hide=0 : option is visible for in both short (-h
). Typical use: mandatory options
hide=1 : option is only visible in long help (--help
). Typical use: expert options
hide=2 : option is hidden for user. Typical use: Easter eggs or options only known to author
Definition at line 227 of file Optionpk.h.
|
inline |
find substring in options of type string (e.g., -co INTERLEAVE=BAND) this template function only makes sense for T=std::string (implemented via a specialization)
Definition at line 162 of file Optionpk.h.
|
inline |
read option from command line (use for all options!), std::string implementation
make sure to call this function first before using the option in main program (or segmentation fault will occur...)
Definition at line 311 of file Optionpk.h.
|
inline |
read option from command line (use for all options!)
make sure to call this function first before using the option in main program (or segmentation fault will occur...)
Definition at line 382 of file Optionpk.h.