Chaste Release::3.1
|
#include <CommandLineArguments.hpp>
Public Member Functions | |
bool | OptionExists (std::string option) |
char * | GetValueCorrespondingToOption (std::string option, int valueNumber=1) |
double | GetDoubleCorrespondingToOption (std::string option, int valueNumber=1) |
int | GetIntCorrespondingToOption (std::string option, int valueNumber=1) |
unsigned | GetUnsignedCorrespondingToOption (std::string option, int valueNumber=1) |
std::string | GetStringCorrespondingToOption (std::string option, int valueNumber=1) |
std::vector< std::string > | GetStringsCorrespondingToOption (std::string option) |
std::vector< double > | GetDoublesCorrespondingToOption (std::string option) |
std::vector< int > | GetIntsCorrespondingToOption (std::string option) |
std::vector< unsigned > | GetUnsignedsCorrespondingToOption (std::string option) |
Static Public Member Functions | |
static CommandLineArguments * | Instance () |
Public Attributes | |
int * | p_argc |
char *** | p_argv |
Private Member Functions | |
CommandLineArguments () | |
int | GetIndexForArgument (std::string argument) |
int | GetNumberOfArgumentsForOption (std::string option) |
void | TestOptionFormat (std::string option) |
Static Private Attributes | |
static CommandLineArguments * | mpInstance = NULL |
A convenient holder for the command line arguments, with helper methods for checking whether an option has been given or getting the value(s) corresponding to a given option.
Options are considered to be any argument starting witha '-' followed by a non-numeric character, in order to distinguish between options and negative numbers. Each option may have zero or more values following it on the command line. Examples:
The cxxtest harness will fill in the member variables when a test is started. They can then be read by PETSc when it is initialised, and by other code as required.
Definition at line 62 of file CommandLineArguments.hpp.
CommandLineArguments::CommandLineArguments | ( | ) | [private] |
Default constructor. Should never be called directly, call CommandLineArguments::Instance() instead.
Definition at line 41 of file CommandLineArguments.cpp.
References mpInstance.
Referenced by Instance().
double CommandLineArguments::GetDoubleCorrespondingToOption | ( | std::string | option, |
int | valueNumber = 1 |
||
) |
Get the double for a given option.
This uses GetValueCorrespondingToOption and converts the char* to a double.
option | the option name as a string. |
valueNumber | the number of the argument following the option definiton (defaults to 1, for 1st argument). |
Definition at line 80 of file CommandLineArguments.cpp.
References GetValueCorrespondingToOption().
Referenced by GetDoublesCorrespondingToOption().
std::vector< double > CommandLineArguments::GetDoublesCorrespondingToOption | ( | std::string | option | ) |
Get a collection of doubles for a given option.
This uses GetDoubleCorrespondingToOption repeatedly.
option | the option name as a string. |
Definition at line 162 of file CommandLineArguments.cpp.
References GetDoubleCorrespondingToOption(), and GetNumberOfArgumentsForOption().
int CommandLineArguments::GetIndexForArgument | ( | std::string | argument | ) | [private] |
Get the index for the given argument. Returns -1 if the argument is not found.
argument | the argument name as a string. |
Definition at line 103 of file CommandLineArguments.cpp.
References p_argc, p_argv, and TestOptionFormat().
Referenced by GetNumberOfArgumentsForOption(), GetValueCorrespondingToOption(), and OptionExists().
int CommandLineArguments::GetIntCorrespondingToOption | ( | std::string | option, |
int | valueNumber = 1 |
||
) |
Get the int for a given option.
This uses GetValueCorrespondingToOption and converts the char* to an int.
option | the option name as a string. |
valueNumber | the number of the argument following the option definiton (defaults to 1, for 1st argument). |
Definition at line 86 of file CommandLineArguments.cpp.
References GetValueCorrespondingToOption().
Referenced by GetIntsCorrespondingToOption().
std::vector< int > CommandLineArguments::GetIntsCorrespondingToOption | ( | std::string | option | ) |
Get a collection of ints for a given option.
This uses GetIntCorrespondingToOption repeatedly.
option | the option name as a string. |
Definition at line 184 of file CommandLineArguments.cpp.
References GetIntCorrespondingToOption(), and GetNumberOfArgumentsForOption().
int CommandLineArguments::GetNumberOfArgumentsForOption | ( | std::string | option | ) | [private] |
Get the number of arguments for a given option. Throws an Exception if the option does not have any following arguments, or the option does not exist. So you can use OptionExists() to avoid Exceptions in your code when using the other public methods.
option | the option name as a string. |
Definition at line 117 of file CommandLineArguments.cpp.
References EXCEPTION, GetIndexForArgument(), p_argc, and p_argv.
Referenced by GetDoublesCorrespondingToOption(), GetIntsCorrespondingToOption(), GetStringsCorrespondingToOption(), GetUnsignedsCorrespondingToOption(), and GetValueCorrespondingToOption().
std::string CommandLineArguments::GetStringCorrespondingToOption | ( | std::string | option, |
int | valueNumber = 1 |
||
) |
Get the string for a given option.
This uses GetValueCorrespondingToOption and converts the char* to a std::string.
option | the option name as a string. |
valueNumber | the number of the argument following the option definiton (defaults to 1, for 1st argument). |
Definition at line 144 of file CommandLineArguments.cpp.
References GetValueCorrespondingToOption().
Referenced by GetStringsCorrespondingToOption().
std::vector< std::string > CommandLineArguments::GetStringsCorrespondingToOption | ( | std::string | option | ) |
Get a collection of strings for a given option (useful for inputting a list of files for example).
This uses GetStringCorrespondingToOption repeatedly.
option | the option name as a string. |
Definition at line 151 of file CommandLineArguments.cpp.
References GetNumberOfArgumentsForOption(), and GetStringCorrespondingToOption().
unsigned CommandLineArguments::GetUnsignedCorrespondingToOption | ( | std::string | option, |
int | valueNumber = 1 |
||
) |
Get the unsigned for a given option.
This uses GetValueCorrespondingToOption and converts the char* to an unsigned. Throws an exception if the option converts to a negative integer.
option | the option name as a string. |
valueNumber | the number of the argument following the option definiton (defaults to 1, for 1st argument). |
Definition at line 92 of file CommandLineArguments.cpp.
References EXCEPTION, and GetValueCorrespondingToOption().
Referenced by GetUnsignedsCorrespondingToOption().
std::vector< unsigned > CommandLineArguments::GetUnsignedsCorrespondingToOption | ( | std::string | option | ) |
Get a collection of unsigneds for a given option.
This uses GetUnsignedCorrespondingToOption repeatedly.
option | the option name as a string. |
Definition at line 173 of file CommandLineArguments.cpp.
References GetNumberOfArgumentsForOption(), and GetUnsignedCorrespondingToOption().
char * CommandLineArguments::GetValueCorrespondingToOption | ( | std::string | option, |
int | valueNumber = 1 |
||
) |
Get the value for a given option, i.e. the argument after the option name in the list of command line arguments. For example, if the following arguments were given ./heart/build/debug/TestMyClassRunner -timestep 0.04 Then calling CommandLineArguments::Instance()->GetValueCorrespondingToOption("-timestep"); will return 0.04 (as a char*). Use atoi or atof to convert the char* to an int or a double(float) respectively, or call one of our convenience methods for common types.
option | the option name as a string. |
valueNumber | the number of the argument following the option definiton (defaults to 1, for 1st argument). |
Definition at line 68 of file CommandLineArguments.cpp.
References EXCEPT_IF_NOT, GetIndexForArgument(), GetNumberOfArgumentsForOption(), p_argv, and TestOptionFormat().
Referenced by GetDoubleCorrespondingToOption(), GetIntCorrespondingToOption(), GetStringCorrespondingToOption(), and GetUnsignedCorrespondingToOption().
CommandLineArguments * CommandLineArguments::Instance | ( | ) | [static] |
Get the single instance of this class.
Definition at line 49 of file CommandLineArguments.cpp.
References CommandLineArguments(), and mpInstance.
Referenced by AbstractContinuumMechanicsSolver< DIM >::AbstractContinuumMechanicsSolver(), AbstractNonlinearElasticitySolver< DIM >::AbstractNonlinearElasticitySolver(), IncompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), CompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), FineCoarseMeshPair< DIM >::ComputeCoarseElementsForFineElementCentroids(), FineCoarseMeshPair< DIM >::ComputeCoarseElementsForFineNodes(), FineCoarseMeshPair< DIM >::ComputeFineElementsAndWeightsForCoarseNodes(), FineCoarseMeshPair< DIM >::ComputeFineElementsAndWeightsForCoarseQuadPoints(), AbstractContinuumMechanicsAssembler< DIM, CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX >::DoAssemble(), ExecutableSupport::InitializePetsc(), PetscSetup::setUpWorld(), and CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Solve().
bool CommandLineArguments::OptionExists | ( | std::string | option | ) |
Check whether a given option exists in the command line arguments.
option | the option name as a string. |
Definition at line 60 of file CommandLineArguments.cpp.
References GetIndexForArgument().
Referenced by AbstractContinuumMechanicsSolver< DIM >::AbstractContinuumMechanicsSolver(), AbstractNonlinearElasticitySolver< DIM >::AbstractNonlinearElasticitySolver(), IncompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), CompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), FineCoarseMeshPair< DIM >::ComputeCoarseElementsForFineElementCentroids(), FineCoarseMeshPair< DIM >::ComputeCoarseElementsForFineNodes(), FineCoarseMeshPair< DIM >::ComputeFineElementsAndWeightsForCoarseNodes(), FineCoarseMeshPair< DIM >::ComputeFineElementsAndWeightsForCoarseQuadPoints(), AbstractContinuumMechanicsAssembler< DIM, CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX >::DoAssemble(), and CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Solve().
void CommandLineArguments::TestOptionFormat | ( | std::string | option | ) | [private] |
Throw an exception if the option is not of the required form: '-' followed by a non-numeric character.
option | the option name to check the format of. |
Definition at line 195 of file CommandLineArguments.cpp.
References EXCEPTION.
Referenced by GetIndexForArgument(), and GetValueCorrespondingToOption().
CommandLineArguments * CommandLineArguments::mpInstance = NULL [static, private] |
The single instance of the class.
Definition at line 70 of file CommandLineArguments.hpp.
Referenced by CommandLineArguments(), and Instance().
The number of command line arguments.
Definition at line 100 of file CommandLineArguments.hpp.
Referenced by GetIndexForArgument(), GetNumberOfArgumentsForOption(), ExecutableSupport::InitializePetsc(), and PetscSetup::setUpWorld().
char*** CommandLineArguments::p_argv |
The arguments themselves.
Definition at line 103 of file CommandLineArguments.hpp.
Referenced by GetIndexForArgument(), GetNumberOfArgumentsForOption(), GetValueCorrespondingToOption(), ExecutableSupport::InitializePetsc(), and PetscSetup::setUpWorld().