Nymph  v1.5.2
Flow-Based Data Processing Framework
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Attributes | Static Private Attributes | Friends | List of all members
KTCommandLineHandler Class Reference

Parses and stores command-line options. More...

#include <KTCommandLineHandler.hh>

Inheritance diagram for KTCommandLineHandler:
Inheritance graph

Public Member Functions

const std::string & GetExecutableName () const
 
const std::string & GetPackageString () const
 
bool ProcessCommandLine (int argC, char **argV)
 
bool TakeArguments (int argC, char **argV)
 
bool GetArgumentsTaken ()
 
int GetNArgs ()
 
char ** GetArgV ()
 
OptDescMapIt CreateNewOptionGroup (const std::string &aTitle)
 Makes a new option group available for command line options. More...
 
bool AddOption (const std::string &aTitle, const std::string &aHelpMsg, const std::string &aLongOpt, char aShortOpt, bool aWarnOnDuplicate=true)
 Simple option adding function, with short option (flag only; no values allowed) More...
 
bool AddOption (const std::string &aTitle, const std::string &aHelpMsg, const std::string &aLongOpt, bool aWarnOnDuplicate=true)
 Simple option adding function, without short option (flag only; no values allowed) More...
 
template<class XValueType >
bool AddOption (const std::string &aTitle, const std::string &aHelpMsg, const std::string &aLongOpt, char aShortOpt, bool aWarnOnDuplicate=true)
 Option-with-value adding function with short option. More...
 
template<class XValueType >
bool AddOption (const std::string &aTitle, const std::string &aHelpMsg, const std::string &aLongOpt, bool aWarnOnDuplicate=true)
 Option-with-value adding function without short option. More...
 
po::options_description * GetOptionsDescription (const std::string &aKey)
 Request access to the options description object for more freedom (and responsibility!) in adding options. More...
 
bool FinalizeNewOptionGroups ()
 Adds the groups of options to the set of usable options groups (note: this must be called to make the options in the groups usable) More...
 
void InitialCommandLineProcessing ()
 Parses the general options and stores the remaining options available for later parsing. More...
 
bool DelayedCommandLineProcessing ()
 Parses the remaining command line options (those that weren't parsed during the InitialCommandLineProcessing. More...
 
bool IsCommandLineOptSet (const std::string &aCLOption)
 Check if a command line option was set. More...
 
template<class XReturnType >
XReturnType GetCommandLineValue (const std::string &aCLOption)
 Return the value of a command line option; throws an exception if the value was not set. More...
 
template<class XReturnType >
XReturnType GetCommandLineValue (const std::string &aCLOption, XReturnType defaultValue)
 Return the value of a command line option; returns the default if the value was not set. More...
 
bool GetPrintHelpMessageFlag () const
 
bool GetPrintHelpMessageAfterConfigFlag () const
 
bool GetPrintVersionMessage () const
 
const std::string & GetConfigFilename () const
 Return the file name provided by the user on the command line for the config file. More...
 
const std::string & GetCommandLineJSON () const
 Return the string of json provided by the user on the command line. More...
 
const po::parsed_options * GetParsedOptions () const
 
const po::variables_map * GetVariablesMap () const
 
const scarab::param_node * GetConfigOverride () const
 
virtual void PrintHelpMessage ()
 
virtual void PrintVersionMessage ()
 

Protected Types

typedef std::map< std::string, po::options_description *> OptDescMap
 
typedef OptDescMap::iterator OptDescMapIt
 
typedef OptDescMap::const_iterator OptDescMapCIt
 

Protected Member Functions

 KTCommandLineHandler ()
 
virtual ~KTCommandLineHandler ()
 
bool AddCommandLineOptions (const po::options_description &aSetOfOpts)
 Adds a set of command line options. More...
 

Protected Attributes

OptDescMap fProposedGroups
 
std::set< std::string > fAllGroupKeys
 
std::set< std::string > fAllOptionsLong
 
std::set< char > fAllOptionsShort
 
po::options_description fCommandLineOptions
 
po::options_description fPrintHelpOptions
 

Private Attributes

std::string fExecutableName
 
std::string fPackageString
 
int fNArgs
 
char ** fArgV
 
bool fArgumentsTaken
 
std::vector< std::string > fCommandLineParseLater
 
po::parsed_options fParsedOptions
 
po::variables_map fCommandLineVarMap
 
scarab::param_node fConfigOverrideValues
 
bool fPrintHelpMessage
 
bool fPrintHelpMessageAfterConfig
 
bool fPrintVersionMessage
 
std::string fConfigFilename
 
std::string fCommandLineJSON
 

Static Private Attributes

static const char fDash = '-'
 
static const char fSeparator = '='
 
static const char fNodeSeparator = '.'
 

Friends

class scarab::singleton< KTCommandLineHandler >
 
class scarab::destroyer< KTCommandLineHandler >
 

Detailed Description

Parses and stores command-line options.

Author
N. S. Oblath

The basic format for the command line arguments are as follows:

The configuration file will be automatically extracted from the command line. If –help (-h) or –version (-v) were given, those will be handled immediately, and the program will exit.

Definition at line 57 of file KTCommandLineHandler.hh.

Member Typedef Documentation

◆ OptDescMap

typedef std::map< std::string, po::options_description* > OptDescMap
protected

Definition at line 60 of file KTCommandLineHandler.hh.

◆ OptDescMapCIt

typedef OptDescMap::const_iterator OptDescMapCIt
protected

Definition at line 62 of file KTCommandLineHandler.hh.

◆ OptDescMapIt

typedef OptDescMap::iterator OptDescMapIt
protected

Definition at line 61 of file KTCommandLineHandler.hh.

Constructor & Destructor Documentation

◆ KTCommandLineHandler()

KTCommandLineHandler ( )
protected

Definition at line 33 of file KTCommandLineHandler.cc.

◆ ~KTCommandLineHandler()

~KTCommandLineHandler ( )
protectedvirtual

Definition at line 53 of file KTCommandLineHandler.cc.

Member Function Documentation

◆ AddCommandLineOptions()

bool AddCommandLineOptions ( const po::options_description &  aSetOfOpts)
protected

Adds a set of command line options.

Definition at line 204 of file KTCommandLineHandler.cc.

◆ AddOption() [1/4]

bool AddOption ( const std::string &  aTitle,
const std::string &  aHelpMsg,
const std::string &  aLongOpt,
char  aShortOpt,
bool  aWarnOnDuplicate = true 
)

Simple option adding function, with short option (flag only; no values allowed)

Definition at line 115 of file KTCommandLineHandler.cc.

◆ AddOption() [2/4]

bool AddOption ( const std::string &  aTitle,
const std::string &  aHelpMsg,
const std::string &  aLongOpt,
bool  aWarnOnDuplicate = true 
)

Simple option adding function, without short option (flag only; no values allowed)

Definition at line 153 of file KTCommandLineHandler.cc.

◆ AddOption() [3/4]

bool AddOption ( const std::string &  aTitle,
const std::string &  aHelpMsg,
const std::string &  aLongOpt,
char  aShortOpt,
bool  aWarnOnDuplicate = true 
)

Option-with-value adding function with short option.

Definition at line 222 of file KTCommandLineHandler.hh.

◆ AddOption() [4/4]

bool AddOption ( const std::string &  aTitle,
const std::string &  aHelpMsg,
const std::string &  aLongOpt,
bool  aWarnOnDuplicate = true 
)

Option-with-value adding function without short option.

Definition at line 257 of file KTCommandLineHandler.hh.

◆ CreateNewOptionGroup()

KTCommandLineHandler::OptDescMapIt CreateNewOptionGroup ( const std::string &  aTitle)

Makes a new option group available for command line options.

Definition at line 102 of file KTCommandLineHandler.cc.

◆ DelayedCommandLineProcessing()

bool DelayedCommandLineProcessing ( )

Parses the remaining command line options (those that weren't parsed during the InitialCommandLineProcessing.

Definition at line 233 of file KTCommandLineHandler.cc.

◆ FinalizeNewOptionGroups()

bool FinalizeNewOptionGroups ( )

Adds the groups of options to the set of usable options groups (note: this must be called to make the options in the groups usable)

Definition at line 189 of file KTCommandLineHandler.cc.

◆ GetArgumentsTaken()

bool GetArgumentsTaken ( )

Definition at line 85 of file KTCommandLineHandler.cc.

◆ GetArgV()

char ** GetArgV ( )

Definition at line 95 of file KTCommandLineHandler.cc.

◆ GetCommandLineJSON()

const std::string & GetCommandLineJSON ( ) const
inline

Return the string of json provided by the user on the command line.

Definition at line 310 of file KTCommandLineHandler.hh.

◆ GetCommandLineValue() [1/2]

XReturnType GetCommandLineValue ( const std::string &  aCLOption)

Return the value of a command line option; throws an exception if the value was not set.

Definition at line 284 of file KTCommandLineHandler.hh.

◆ GetCommandLineValue() [2/2]

XReturnType GetCommandLineValue ( const std::string &  aCLOption,
XReturnType  defaultValue 
)

Return the value of a command line option; returns the default if the value was not set.

Definition at line 296 of file KTCommandLineHandler.hh.

◆ GetConfigFilename()

const std::string & GetConfigFilename ( ) const
inline

Return the file name provided by the user on the command line for the config file.

Definition at line 305 of file KTCommandLineHandler.hh.

◆ GetConfigOverride()

const scarab::param_node * GetConfigOverride ( ) const
inline

Definition at line 340 of file KTCommandLineHandler.hh.

◆ GetExecutableName()

const std::string & GetExecutableName ( ) const
inline

Definition at line 212 of file KTCommandLineHandler.hh.

◆ GetNArgs()

int GetNArgs ( )

Definition at line 90 of file KTCommandLineHandler.cc.

◆ GetOptionsDescription()

po::options_description * GetOptionsDescription ( const std::string &  aKey)

Request access to the options description object for more freedom (and responsibility!) in adding options.

Definition at line 176 of file KTCommandLineHandler.cc.

◆ GetPackageString()

const std::string & GetPackageString ( ) const
inline

Definition at line 216 of file KTCommandLineHandler.hh.

◆ GetParsedOptions()

const po::parsed_options * GetParsedOptions ( ) const
inline

Definition at line 330 of file KTCommandLineHandler.hh.

◆ GetPrintHelpMessageAfterConfigFlag()

bool GetPrintHelpMessageAfterConfigFlag ( ) const
inline

Definition at line 325 of file KTCommandLineHandler.hh.

◆ GetPrintHelpMessageFlag()

bool GetPrintHelpMessageFlag ( ) const
inline

Definition at line 320 of file KTCommandLineHandler.hh.

◆ GetPrintVersionMessage()

bool GetPrintVersionMessage ( ) const
inline

Definition at line 315 of file KTCommandLineHandler.hh.

◆ GetVariablesMap()

const po::variables_map * GetVariablesMap ( ) const
inline

Definition at line 335 of file KTCommandLineHandler.hh.

◆ InitialCommandLineProcessing()

void InitialCommandLineProcessing ( )

Parses the general options and stores the remaining options available for later parsing.

Definition at line 312 of file KTCommandLineHandler.cc.

◆ IsCommandLineOptSet()

bool IsCommandLineOptSet ( const std::string &  aCLOption)

Check if a command line option was set.

Definition at line 226 of file KTCommandLineHandler.cc.

◆ PrintHelpMessage()

void PrintHelpMessage ( )
virtual

Definition at line 435 of file KTCommandLineHandler.cc.

◆ PrintVersionMessage()

void PrintVersionMessage ( )
virtual

Definition at line 444 of file KTCommandLineHandler.cc.

◆ ProcessCommandLine()

bool ProcessCommandLine ( int  argC,
char **  argV 
)

Definition at line 74 of file KTCommandLineHandler.cc.

◆ TakeArguments()

bool TakeArguments ( int  argC,
char **  argV 
)

Definition at line 63 of file KTCommandLineHandler.cc.

Friends And Related Function Documentation

◆ scarab::destroyer< KTCommandLineHandler >

friend class scarab::destroyer< KTCommandLineHandler >
friend

Definition at line 70 of file KTCommandLineHandler.hh.

◆ scarab::singleton< KTCommandLineHandler >

friend class scarab::singleton< KTCommandLineHandler >
friend

Definition at line 69 of file KTCommandLineHandler.hh.

Member Data Documentation

◆ fAllGroupKeys

std::set< std::string > fAllGroupKeys
protected

Definition at line 131 of file KTCommandLineHandler.hh.

◆ fAllOptionsLong

std::set< std::string > fAllOptionsLong
protected

Definition at line 132 of file KTCommandLineHandler.hh.

◆ fAllOptionsShort

std::set< char > fAllOptionsShort
protected

Definition at line 133 of file KTCommandLineHandler.hh.

◆ fArgumentsTaken

bool fArgumentsTaken
private

Definition at line 101 of file KTCommandLineHandler.hh.

◆ fArgV

char** fArgV
private

Definition at line 100 of file KTCommandLineHandler.hh.

◆ fCommandLineJSON

std::string fCommandLineJSON
private

Definition at line 201 of file KTCommandLineHandler.hh.

◆ fCommandLineOptions

po::options_description fCommandLineOptions
protected

Definition at line 135 of file KTCommandLineHandler.hh.

◆ fCommandLineParseLater

std::vector< std::string > fCommandLineParseLater
private

Definition at line 154 of file KTCommandLineHandler.hh.

◆ fCommandLineVarMap

po::variables_map fCommandLineVarMap
private

Definition at line 189 of file KTCommandLineHandler.hh.

◆ fConfigFilename

std::string fConfigFilename
private

Definition at line 200 of file KTCommandLineHandler.hh.

◆ fConfigOverrideValues

scarab::param_node fConfigOverrideValues
private

Definition at line 191 of file KTCommandLineHandler.hh.

◆ fDash

const char fDash = '-'
staticprivate

Definition at line 192 of file KTCommandLineHandler.hh.

◆ fExecutableName

std::string fExecutableName
private

Definition at line 83 of file KTCommandLineHandler.hh.

◆ fNArgs

int fNArgs
private

Definition at line 99 of file KTCommandLineHandler.hh.

◆ fNodeSeparator

const char fNodeSeparator = '.'
staticprivate

Definition at line 194 of file KTCommandLineHandler.hh.

◆ fPackageString

std::string fPackageString
private

Definition at line 84 of file KTCommandLineHandler.hh.

◆ fParsedOptions

po::parsed_options fParsedOptions
private

Definition at line 188 of file KTCommandLineHandler.hh.

◆ fPrintHelpMessage

bool fPrintHelpMessage
private

Definition at line 196 of file KTCommandLineHandler.hh.

◆ fPrintHelpMessageAfterConfig

bool fPrintHelpMessageAfterConfig
private

Definition at line 197 of file KTCommandLineHandler.hh.

◆ fPrintHelpOptions

po::options_description fPrintHelpOptions
protected

Definition at line 136 of file KTCommandLineHandler.hh.

◆ fPrintVersionMessage

bool fPrintVersionMessage
private

Definition at line 198 of file KTCommandLineHandler.hh.

◆ fProposedGroups

OptDescMap fProposedGroups
protected

Definition at line 130 of file KTCommandLineHandler.hh.

◆ fSeparator

const char fSeparator = '='
staticprivate

Definition at line 193 of file KTCommandLineHandler.hh.


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