PetaVision  Alpha
PV::CommandLineArguments Class Reference

#include <CommandLineArguments.hpp>

Inheritance diagram for PV::CommandLineArguments:
PV::Arguments

Public Member Functions

 CommandLineArguments (int argc, char const *const *argv, bool allowUnrecognizedArguments)
 
bool const & getBooleanArgument (std::string const &name) const
 
int const & getIntegerArgument (std::string const &name) const
 
Configuration::IntOptional const & getIntOptionalArgument (std::string const &name) const
 
std::string const & getStringArgument (std::string const &name) const
 
Configuration::ConfigurationType getType (std::string const &name) const
 
unsigned int const & getUnsignedIntArgument (std::string const &name) const
 
int printState () const
 
void resetState (int argc, char const *const *argv, bool allowUnrecognizedArguments)
 
void resetState (std::istream &configStream, bool allowUnrecognizedArguments)
 
void resetState ()
 
bool setBooleanArgument (std::string const &name, bool const &value)
 
bool setIntegerArgument (std::string const &name, int const &value)
 
bool setIntOptionalArgument (std::string const &name, Configuration::IntOptional const &value)
 
bool setStringArgument (std::string const &name, std::string const &value)
 
bool setUnsignedIntArgument (std::string const &name, unsigned int const &value)
 

Protected Member Functions

int initialize (std::istream &configStream, bool allowUnrecognizedArguments)
 

Private Member Functions

int initialize (int argc, char const *const *argv, bool allowUnrecognizedArguments)
 
int initialize_base ()
 

Detailed Description

A class for parsing a configuration from command-line arguments and storing the results. It is derived from the Arguments class, and converts the command-line arguments into a stringstream that can be handled by the Arguments::resetState method.

Definition at line 22 of file CommandLineArguments.hpp.

Constructor & Destructor Documentation

PV::CommandLineArguments::CommandLineArguments ( int  argc,
char const *const *  argv,
bool  allowUnrecognizedArguments 
)

The constructor for CommandLineArguments. It calls the initialize method, which calls resetState, which converts the argv array into an input stringstream that gets passed to the ConfigParser class. See resetState(int, char **, bool) for details on how the argv array is interpreted.

Definition at line 18 of file CommandLineArguments.cpp.

Member Function Documentation

bool const& PV::Arguments::getBooleanArgument ( std::string const &  name) const
inlineinherited

Returns the value of the specified Boolean value in the current configuration. Throws an invalid_argument exception if the input argument does not refer to a Boolean.

Definition at line 62 of file Arguments.hpp.

int const& PV::Arguments::getIntegerArgument ( std::string const &  name) const
inlineinherited

Returns the value of the specified integer in the current configuration. Throws an invalid_argument exception if the input argument does not refer to an integer.

Definition at line 71 of file Arguments.hpp.

Configuration::IntOptional const& PV::Arguments::getIntOptionalArgument ( std::string const &  name) const
inlineinherited

Returns the value of the specified optional integer in the current configuration. Throws an invalid_argument exception if the input argument does not refer to an optional integer.

Definition at line 98 of file Arguments.hpp.

std::string const& PV::Arguments::getStringArgument ( std::string const &  name) const
inlineinherited

Returns the value of the specified string in the current configuration. Throws an invalid_argument exception if the input argument does not refer to a string in the configruation.

Definition at line 89 of file Arguments.hpp.

Configuration::ConfigurationType PV::Arguments::getType ( std::string const &  name) const
inlineinherited

Returns the type for the given string: unrecognized, boolean, integer, unsigned, string, or optional integer.

Definition at line 53 of file Arguments.hpp.

unsigned int const& PV::Arguments::getUnsignedIntArgument ( std::string const &  name) const
inlineinherited

Returns the value of the specified unsigned integer in the current configuration. Throws an invalid_argument exception if the input argument does not refer to an unsigned integer.

Definition at line 80 of file Arguments.hpp.

int PV::CommandLineArguments::initialize ( int  argc,
char const *const *  argv,
bool  allowUnrecognizedArguments 
)
private

initialize() is called by the constructor. It calls resetState to set the initial values of the Arguments data members.

Definition at line 28 of file CommandLineArguments.cpp.

int PV::Arguments::initialize ( std::istream &  configStream,
bool  allowUnrecognizedArguments 
)
protectedinherited

initialize() is called by the constructor, and calls the resetState(istream, bool) method to set the data members.

Definition at line 27 of file Arguments.cpp.

int PV::CommandLineArguments::initialize_base ( )
private

initialize_base() is called by the constructor to initialize the internal state before initialize() is called.

Definition at line 26 of file CommandLineArguments.cpp.

int PV::Arguments::printState ( ) const
inherited

Prints the effective command line based on the arguments used in instantiation, and any set-methods used since then.

Definition at line 40 of file Arguments.cpp.

void PV::CommandLineArguments::resetState ( int  argc,
char const *const *  argv,
bool  allowUnrecognizedArguments 
)

Reinitializes the object's state based on the given argv array. The argv array is scanned to create a configuration stream that is then used as if passed to the constructor of the Arguments class. The strings argv[0], argv[1], ..., argv[argc-1] are processed as follows: argv[0] (the program name) is ignored. argv[1] through argv[argc-1] are scanned for an exact match with each of the following: "-c": the next argument is used as the CheckpointReadDirectory string. "-d": the next argument is used as the GpuDevices string. "-l": the next argument is used as the LogFile string. "-o": the next argument is used as the OutputPath string. "-p": the next argument is used as the ParamsFile string. "-r": the Restart flag is set to true. "-s": the next argument is parsed as an unsigned integer and used as the RandomSeed setting. "-t": if the next argument is a nonnegative integer, it is used as the NumThreads setting and the UseDefaultNumThreads is set to false. If the next argument is not a nonnegative argument or if "-t" is the last argument, UseDefaultNumThreads is set to true and NumThreads is set to -1 (although NumThreads should not be used if UseDefaultNumThreads is true). "-w": the next argument is used as the WorkingDirectory string. "-rows": the next argument is parsed as an integer and used as the NumRows setting. "-columns": the next argument is parsed as an integer and used as the NumColumns setting. "-batchwidth": the next argument is parsed as an integer and used as the BatchWidth setting. "-n": the DryRun flag is set to true. "--require-return": the RequireReturn flag is set to true. It is an error to have both the -r and -c options.

Note that all arguments have a single hyphen, except for "--require-return".

If an option depends on the next argument but there is no next argument, the corresponding internal variable is not set, with the exception of "-t", as noted above.

If an option occurs more than once, later occurrences supersede earlier occurrences.

If allowUnrecognizedArguments is set to false, the constructor fails if any string in the argv array is not recoginzed.

Definition at line 36 of file CommandLineArguments.cpp.

void PV::Arguments::resetState ( std::istream &  configStream,
bool  allowUnrecognizedArguments 
)
inherited

Sets the object's state based on the given input stream. The allowUnrecognizedArguments flag has the same effect as in the constructor.

This method creates a ConfigParser object from its arguments, and sets the Arguments data members according to the ConfigParser's get-methods. See ConfigParser::initialize() for a description of how the configuration stream is parsed.

Definition at line 32 of file Arguments.cpp.

void PV::Arguments::resetState ( )
inherited

Resets all member variables to their state at the time the object was instantiated or reinitialized using resetState(istream, bool). That is, the arguments are retrieved from the ConfigParser arguments, and the effect of any set-method that had been called since then is discarded.

Definition at line 38 of file Arguments.cpp.

bool PV::Arguments::setBooleanArgument ( std::string const &  name,
bool const &  value 
)
inlineinherited

Sets the indicated Boolean value in the current configuration to the indicated value. If the configuration does not have a Boolean with the indicated name, the method does nothing.

Definition at line 107 of file Arguments.hpp.

bool PV::Arguments::setIntegerArgument ( std::string const &  name,
int const &  value 
)
inlineinherited

Sets the indicated integer in the current configuration to the indicated value. If the configuration does not have an integer with the indicated name, the method does nothing.

Definition at line 116 of file Arguments.hpp.

bool PV::Arguments::setIntOptionalArgument ( std::string const &  name,
Configuration::IntOptional const &  value 
)
inlineinherited

Sets the indicated optional integer in the current configuration to the indicated value. If the configuration does not have an optional integer with the indicated name, the method does nothing.

Definition at line 143 of file Arguments.hpp.

bool PV::Arguments::setStringArgument ( std::string const &  name,
std::string const &  value 
)
inlineinherited

Sets the indicated string in the current configuration to the indicated value. If the configuration does not have a string with the indicated name, the method does nothing.

Definition at line 134 of file Arguments.hpp.

bool PV::Arguments::setUnsignedIntArgument ( std::string const &  name,
unsigned int const &  value 
)
inlineinherited

Sets the indicated unsigned integer in the current configuration to the indicated value. If the configuration does not have an unsigned integer with the indicated name, the method does nothing.

Definition at line 125 of file Arguments.hpp.


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