FEDEM Solver  R8.0
Source code of the dynamics solver
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
FFaCmdLineArg Class Reference

Singleton class for management of command-line options. More...

#include <FFaCmdLineArg.H>

Collaboration diagram for FFaCmdLineArg:
Collaboration graph
[legend]

Public Member Functions

template<class T >
void addOption (const std::string &identifier, const T &value, const std::string &helpText, bool showToAll=true)
 Defines a new command-line option of arbitrary type. More...
 
void addOption (const std::string &identifier, const char *value, const std::string &helpText, bool showToAll=true)
 Defines a new command-line option of string type. More...
 
template<class T >
bool getValue (const std::string &identifier, T &aVal)
 Returns the actual value of the specified command-line option. More...
 
bool setValue (const std::string &identifier, const std::string &value)
 Assigns a new value to the specified command-line option. More...
 
void composeHelpText (std::string &report, bool all=false) const
 Creates a multi-line string with a list of all defined options. More...
 
void composeSingleLineHelpText (std::string &report, bool all=false) const
 Same as composeHelpText(), but with each option as a single line. More...
 
void listOptions (bool noDefaults=false) const
 Prints out all specified command-line options. More...
 
bool isOptionSetOnCmdLine (const std::string &identifier)
 Checks if an option identifier is specified on the command-line. More...
 
bool readOptionsFile (const std::string &fileName)
 Reads command-line option values from the file fileName. More...
 

Static Public Member Functions

static void init (int argc, char **argv)
 Initializes the command-line options singleton object. More...
 
static bool empty ()
 Returns true if no command-line options have been defined. More...
 
static FFaCmdLineArg * instance ()
 Returns the one and only instance of this class. More...
 
static void removeInstance ()
 Deletes the dynamically allocated instance. More...
 

Static Public Attributes

static std::string additionalHelpText
 This text is printed after the option list itself when using "-help". More...
 
static bool mute = false
 If true, error messages are muted. More...
 

Private Types

typedef std::map< std::string, FFaCmdLineEntryBase * > OptionMap
 Data type for the command-line options container. More...
 

Private Member Functions

 FFaCmdLineArg ()
 The default constructor is private to avoid other instances. More...
 
 ~FFaCmdLineArg ()
 The destructor deletes the allocated FFaCmdLineEntry objects. More...
 
void initArgs (int argc, char **argv)
 Copies all command-line arguments into a temporary container. More...
 
void evaluate ()
 Processes the temporary command-line option list myArgs. More...
 

Private Attributes

std::vector< std::string > myArgs
 Temporary command-line option storage. More...
 
OptionMap myOptions
 Command-line options container. More...
 

Static Private Attributes

static FFaCmdLineArg * myInstance = NULL
 The actual instance of this class. More...
 

Detailed Description

Singleton class for management of command-line options.

All options are in the standard form <switch word>[ ]<option>, and each switch word must be prefixed with either '-' or '/'. (only '-' is valid on UNIX)

The command argument parser can be used this way:

int main(int argc, char** argv)
{
FFaCmdLineArg::init(argc,argv);
FFaCmdLineArg::instance()->addOption("f", "untitled.dat", "Input filename");
FFaCmdLineArg::instance()->addOption("debug", false, "Debug mode");
FFaCmdLineArg::instance()->addOption("n32", false, "n32 mode");
FFaCmdLineArg::instance()->addOption("rate", 2.0, "sample rate");
double rate;
std::cout << rate << std::endl;
...
}
static FFaCmdLineArg * instance()
Returns the one and only instance of this class.
Definition: FFaCmdLineArgImplementation.C:89
static void init(int argc, char **argv)
Initializes the command-line options singleton object.
Definition: FFaCmdLineArg.H:135
void addOption(const std::string &identifier, const T &value, const std::string &helpText, bool showToAll=true)
Defines a new command-line option of arbitrary type.
Definition: FFaCmdLineArg.H:148
bool getValue(const std::string &identifier, T &aVal)
Returns the actual value of the specified command-line option.
Definition: FFaCmdLineArg.H:177
int main(int argc, char **argv)
Main program for the FEDEM dynamics solver.
Definition: main.C:38
Author
Jens Lien

Member Typedef Documentation

◆ OptionMap

typedef std::map<std::string,FFaCmdLineEntryBase*> FFaCmdLineArg::OptionMap
private

Data type for the command-line options container.

Constructor & Destructor Documentation

◆ FFaCmdLineArg()

FFaCmdLineArg::FFaCmdLineArg ( )
private

The default constructor is private to avoid other instances.

◆ ~FFaCmdLineArg()

FFaCmdLineArg::~FFaCmdLineArg ( )
private

The destructor deletes the allocated FFaCmdLineEntry objects.

Member Function Documentation

◆ addOption() [1/2]

void FFaCmdLineArg::addOption ( const std::string &  identifier,
const char *  value,
const std::string &  helpText,
bool  showToAll = true 
)
inline

Defines a new command-line option of string type.

Parameters
[in]identifierThe actual option is "-<identifier>"
[in]valueDefault value of this option
[in]helpTextTextual decription printed via the option "-help"
[in]showToAlltrue if this option is public

◆ addOption() [2/2]

template<class T >
void FFaCmdLineArg::addOption ( const std::string &  identifier,
const T &  value,
const std::string &  helpText,
bool  showToAll = true 
)
inline

Defines a new command-line option of arbitrary type.

Parameters
[in]identifierThe actual option is "-<identifier>"
[in]valueDefault value of this option
[in]helpTextTextual decription printed via the option "-help"
[in]showToAlltrue if this option is public

◆ composeHelpText()

void FFaCmdLineArg::composeHelpText ( std::string &  report,
bool  all = false 
) const

Creates a multi-line string with a list of all defined options.

Parameters
[out]reportA report with option descriptions and default values
[in]allIf true, include also private (normally hidden) options

◆ composeSingleLineHelpText()

void FFaCmdLineArg::composeSingleLineHelpText ( std::string &  report,
bool  all = false 
) const

Same as composeHelpText(), but with each option as a single line.

◆ empty()

bool FFaCmdLineArg::empty ( )
static

Returns true if no command-line options have been defined.

◆ evaluate()

void FFaCmdLineArg::evaluate ( )
private

Processes the temporary command-line option list myArgs.

◆ getValue()

template<class T >
bool FFaCmdLineArg::getValue ( const std::string &  identifier,
T &  aVal 
)
inline

Returns the actual value of the specified command-line option.

Parameters
[in]identifierThe option to return the value for
[out]aValThe actual value of the command-line option
Returns
true if the specified option was defined, otherwise false

◆ init()

static void FFaCmdLineArg::init ( int  argc,
char **  argv 
)
inlinestatic

Initializes the command-line options singleton object.

◆ initArgs()

void FFaCmdLineArg::initArgs ( int  argc,
char **  argv 
)
private

Copies all command-line arguments into a temporary container.

◆ instance()

FFaCmdLineArg * FFaCmdLineArg::instance ( )
static

Returns the one and only instance of this class.

◆ isOptionSetOnCmdLine()

bool FFaCmdLineArg::isOptionSetOnCmdLine ( const std::string &  identifier)

Checks if an option identifier is specified on the command-line.

Returns true if the option is specified, and false if it is not set. If the option is undefined, return false and print a warning to std::cerr.

◆ listOptions()

void FFaCmdLineArg::listOptions ( bool  noDefaults = false) const

Prints out all specified command-line options.

Parameters
[in]noDefaultsIf true, print out all defined options

◆ readOptionsFile()

bool FFaCmdLineArg::readOptionsFile ( const std::string &  fileName)

Reads command-line option values from the file fileName.

◆ removeInstance()

void FFaCmdLineArg::removeInstance ( )
static

Deletes the dynamically allocated instance.

◆ setValue()

bool FFaCmdLineArg::setValue ( const std::string &  identifier,
const std::string &  value 
)

Assigns a new value to the specified command-line option.

Parameters
[in]identifierThe option to assign new value for
[in]valueNew value of this option
Returns
true if the specified option was defined, otherwise false

Member Data Documentation

◆ additionalHelpText

std::string FFaCmdLineArg::additionalHelpText
static

This text is printed after the option list itself when using "-help".

◆ mute

bool FFaCmdLineArg::mute = false
static

If true, error messages are muted.

◆ myArgs

std::vector<std::string> FFaCmdLineArg::myArgs
private

Temporary command-line option storage.

◆ myInstance

FFaCmdLineArg * FFaCmdLineArg::myInstance = NULL
staticprivate

The actual instance of this class.

◆ myOptions

OptionMap FFaCmdLineArg::myOptions
private

Command-line options container.


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