ui-utilcpp  1.8.3
Public Member Functions | Protected Attributes
UI::Util::CLOption Class Reference

Most general class for a command line option. Use this class for a option without argument. More...

#include <GetOpt.hpp>

Inheritance diagram for UI::Util::CLOption:
Inheritance graph
Collaboration diagram for UI::Util::CLOption:
Collaboration graph

Public Member Functions

 CLOption (std::string const &nameLong, char nameShort, std::string const &doc="No documentation for this option.", std::string const &defaultArg="")
 Standard constructor. Normally, you would not use this directly, but rather use GetOpt::set. More...
 
std::string getNameLong () const
 Get the long name. More...
 
char getNameShort () const
 Get the short name. More...
 
std::string getDoc () const
 Get the documentation. More...
 
bool isGiven () const
 Check if this option was given. More...
 
std::string getArg () const
 Get argument given with this option. More...
 
virtual void printUsage () const
 Print usage information for this option.
 
virtual option * getCOptLong (option *opt) const
 Get GNU getopt_long(3) represention of this option. More...
 
virtual std::string getCOptShort () const
 Get GNU getopt(3) represention of this option. More...
 
virtual void setGiven (std::string const &arg="")
 Mark this option as "given", and optionally set the argument. More...
 

Protected Attributes

std::string const defaultArg_
 

Detailed Description

Most general class for a command line option. Use this class for a option without argument.

Deprecated:
Leagcy - don't use this for new code – use boost::program_options instead.

Constructor & Destructor Documentation

UI::Util::CLOption::CLOption ( std::string const &  nameLong,
char  nameShort,
std::string const &  doc = "No documentation for this option.",
std::string const &  defaultArg = "" 
)

Standard constructor. Normally, you would not use this directly, but rather use GetOpt::set.

Parameters
nameLongLong name of the option; e.g. "version".
nameShortShort name (one character) of the option; e.g. 'v'.
docDocumentation string for this option; e.g. "Show version information".
defaultArgDefault value for that option.

Member Function Documentation

std::string UI::Util::CLOption::getArg ( ) const

Get argument given with this option.

Returns
Argument, if any; zero-length string for none. This must be set manually via setGiven() (GetOpt automates this).
Examples:
GetOpt.cpp.

References defaultArg_, and isGiven().

option * UI::Util::CLOption::getCOptLong ( option *  opt) const
virtual

Get GNU getopt_long(3) represention of this option.

Returns
Corresponding option struct for GNU getopt_long(3).

Reimplemented in UI::Util::CLOptionOptArg, and UI::Util::CLOptionArg.

Referenced by UI::Util::CLOptionArg::getCOptLong(), and UI::Util::CLOptionOptArg::getCOptLong().

std::string UI::Util::CLOption::getCOptShort ( ) const
virtual

Get GNU getopt(3) represention of this option.

Returns
Corresponding "optstr" for getopt(3).

Reimplemented in UI::Util::CLOptionOptArg, and UI::Util::CLOptionArg.

std::string UI::Util::CLOption::getDoc ( ) const

Get the documentation.

Returns
Documentation string of this option.

Referenced by UI::Util::CLOptionArg::printUsage(), and UI::Util::CLOptionOptArg::printUsage().

std::string UI::Util::CLOption::getNameLong ( ) const

Get the long name.

Returns
Long name of this option.

Referenced by UI::Util::GetOpt::get(), UI::Util::CLOptionArg::printUsage(), and UI::Util::CLOptionOptArg::printUsage().

char UI::Util::CLOption::getNameShort ( ) const
bool UI::Util::CLOption::isGiven ( ) const

Check if this option was given.

Returns
true, if argument was given, else false. This must be set manually via setGiven() (GetOpt automates this).
Examples:
GetOpt.cpp.

Referenced by getArg().

void UI::Util::CLOption::setGiven ( std::string const &  arg = "")
virtual

Mark this option as "given", and optionally set the argument.

Parameters
argArgument string to set this option to.

Field Documentation

std::string const UI::Util::CLOption::defaultArg_
protected

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