![]() |
Chaste Commit::357af77f3d8b47aa179dbebbdde04c89ce3f2aca
|
#include <CommandLineArguments.hpp>
Inheritance diagram for CommandLineArguments:
Collaboration diagram for CommandLineArguments:Public Member Functions | |
| bool | OptionExists (const std::string &rOption) |
| int | GetNumberOfArgumentsForOption (const std::string &rOption, bool throwIfNone=false) |
| char * | GetValueCorrespondingToOption (const std::string &rOption, int valueNumber=1) |
| double | GetDoubleCorrespondingToOption (const std::string &rOption, int valueNumber=1) |
| int | GetIntCorrespondingToOption (const std::string &rOption, int valueNumber=1) |
| unsigned | GetUnsignedCorrespondingToOption (const std::string &rOption, int valueNumber=1) |
| std::string | GetStringCorrespondingToOption (const std::string &rOption, int valueNumber=1) |
| std::vector< std::string > | GetStringsCorrespondingToOption (const std::string &rOption) |
| std::vector< double > | GetDoublesCorrespondingToOption (const std::string &rOption) |
| std::vector< int > | GetIntsCorrespondingToOption (const std::string &rOption) |
| std::vector< unsigned > | GetUnsignedsCorrespondingToOption (const std::string &rOption) |
| bool | GetBoolCorrespondingToOption (const std::string &rOption) |
| std::vector< std::string > | GetUnusedOptions () |
Static Public Member Functions | |
| static CommandLineArguments * | Instance () |
Public Attributes | |
| int * | p_argc |
| char *** | p_argv |
Private Member Functions | |
| CommandLineArguments () | |
| void | MarkOptionUsed (const std::string &rOption) |
| int | GetIndexForArgument (std::string rOption) |
| void | TestOptionFormat (const std::string &rOption) |
Private Attributes | |
| std::set< std::string > | mUsedOptions |
Static Private Attributes | |
| static CommandLineArguments * | mpInstance = nullptr |
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 with a '-' 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.
Every option that is looked up and found is recorded as used. If PETSc is initialised at the time, the option is also marked as used in PETSc's options database, so that PETSc's report of unused options at PetscFinalize (on by default in debug builds of PETSc, or with -options_left) only lists options that neither Chaste nor PETSc has read. GetUnusedOptions() gives the same information on demand.
Definition at line 70 of file CommandLineArguments.hpp.
|
private |
Default constructor. Should never be called directly, call CommandLineArguments::Instance() instead.
Definition at line 46 of file CommandLineArguments.cpp.
References mpInstance.
Referenced by Instance().
| bool CommandLineArguments::GetBoolCorrespondingToOption | ( | const std::string & | rOption | ) |
Read bools from the command line. This accepts 0 or 1, and also true/True/TRUE and false/False/FALSE.
| rOption | The option name as a string. |
Definition at line 258 of file CommandLineArguments.cpp.
References EXCEPTION, and GetStringCorrespondingToOption().
| double CommandLineArguments::GetDoubleCorrespondingToOption | ( | const std::string & | rOption, |
| int | valueNumber = 1 |
||
| ) |
This uses GetValueCorrespondingToOption and converts the char* to a double.
| rOption | the option name as a string. |
| valueNumber | the number of the argument following the option definition (defaults to 1, for 1st argument). |
Definition at line 95 of file CommandLineArguments.cpp.
References GetValueCorrespondingToOption().
Referenced by GetDoublesCorrespondingToOption().
| std::vector< double > CommandLineArguments::GetDoublesCorrespondingToOption | ( | const std::string & | rOption | ) |
This uses GetDoubleCorrespondingToOption repeatedly.
| rOption | the option name as a string. |
Definition at line 225 of file CommandLineArguments.cpp.
References GetDoubleCorrespondingToOption(), and GetNumberOfArgumentsForOption().
|
private |
| rOption | the argument name as a string. |
Definition at line 118 of file CommandLineArguments.cpp.
References EXCEPTION, MarkOptionUsed(), p_argc, p_argv, and TestOptionFormat().
Referenced by GetNumberOfArgumentsForOption(), GetValueCorrespondingToOption(), and OptionExists().
| int CommandLineArguments::GetIntCorrespondingToOption | ( | const std::string & | rOption, |
| int | valueNumber = 1 |
||
| ) |
This uses GetValueCorrespondingToOption and converts the char* to an int.
| rOption | the option name as a string. |
| valueNumber | the number of the argument following the option definition (defaults to 1, for 1st argument). |
Definition at line 101 of file CommandLineArguments.cpp.
References GetValueCorrespondingToOption().
Referenced by GetIntsCorrespondingToOption().
| std::vector< int > CommandLineArguments::GetIntsCorrespondingToOption | ( | const std::string & | rOption | ) |
This uses GetIntCorrespondingToOption repeatedly.
| rOption | the option name as a string. |
Definition at line 247 of file CommandLineArguments.cpp.
References GetIntCorrespondingToOption(), and GetNumberOfArgumentsForOption().
| int CommandLineArguments::GetNumberOfArgumentsForOption | ( | const std::string & | rOption, |
| bool | throwIfNone = false |
||
| ) |
| rOption | the option name as a string. |
| throwIfNone | Whether to give an exception if there are no arguments for this rOption (defaults to false). |
Definition at line 177 of file CommandLineArguments.cpp.
References EXCEPTION, GetIndexForArgument(), p_argc, and p_argv.
Referenced by GetDoublesCorrespondingToOption(), GetIntsCorrespondingToOption(), GetStringsCorrespondingToOption(), GetUnsignedsCorrespondingToOption(), GetValueCorrespondingToOption(), and Citations::Print().
| std::string CommandLineArguments::GetStringCorrespondingToOption | ( | const std::string & | rOption, |
| int | valueNumber = 1 |
||
| ) |
This uses GetValueCorrespondingToOption and converts the char* to a std::string.
| rOption | the option name as a string. |
| valueNumber | the number of the argument following the option definition (defaults to 1, for 1st argument). |
Definition at line 207 of file CommandLineArguments.cpp.
References GetValueCorrespondingToOption().
Referenced by GetBoolCorrespondingToOption(), GetStringsCorrespondingToOption(), and Citations::Print().
| std::vector< std::string > CommandLineArguments::GetStringsCorrespondingToOption | ( | const std::string & | rOption | ) |
This uses GetStringCorrespondingToOption repeatedly.
| rOption | the option name as a string. |
Definition at line 214 of file CommandLineArguments.cpp.
References GetNumberOfArgumentsForOption(), and GetStringCorrespondingToOption().
| unsigned CommandLineArguments::GetUnsignedCorrespondingToOption | ( | const std::string & | rOption, |
| int | valueNumber = 1 |
||
| ) |
This uses GetValueCorrespondingToOption and converts the char* to an unsigned. Throws an exception if the option converts to a negative integer.
| rOption | the option name as a string. |
| valueNumber | the number of the argument following the option definition (defaults to 1, for 1st argument). |
Definition at line 107 of file CommandLineArguments.cpp.
References EXCEPTION, and GetValueCorrespondingToOption().
Referenced by GetUnsignedsCorrespondingToOption().
| std::vector< unsigned > CommandLineArguments::GetUnsignedsCorrespondingToOption | ( | const std::string & | rOption | ) |
This uses GetUnsignedCorrespondingToOption repeatedly.
| rOption | the option name as a string. |
Definition at line 236 of file CommandLineArguments.cpp.
References GetNumberOfArgumentsForOption(), and GetUnsignedCorrespondingToOption().
| std::vector< std::string > CommandLineArguments::GetUnusedOptions | ( | ) |
Definition at line 148 of file CommandLineArguments.cpp.
References PetscTools::IsInitialised(), mUsedOptions, p_argc, and p_argv.
| char * CommandLineArguments::GetValueCorrespondingToOption | ( | const std::string & | rOption, |
| int | valueNumber = 1 |
||
| ) |
| rOption | the option name as a string. |
| valueNumber | the number of the argument following the option definition (defaults to 1, for 1st argument). |
Definition at line 78 of file CommandLineArguments.cpp.
References EXCEPT_IF_NOT, EXCEPTION, GetIndexForArgument(), GetNumberOfArgumentsForOption(), p_argv, and TestOptionFormat().
Referenced by GetDoubleCorrespondingToOption(), GetIntCorrespondingToOption(), GetStringCorrespondingToOption(), and GetUnsignedCorrespondingToOption().
|
static |
Definition at line 54 of file CommandLineArguments.cpp.
References CommandLineArguments(), and mpInstance.
Referenced by AbstractContinuumMechanicsSolver< DIM >::AbstractContinuumMechanicsSolver(), AbstractNonlinearElasticitySolver< DIM >::AbstractNonlinearElasticitySolver(), CommandLineArgumentsMocker::CommandLineArgumentsMocker(), CommandLineArgumentsMocker::~CommandLineArgumentsMocker(), CompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), IncompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), FineCoarseMeshPair< DIM >::ComputeCoarseElementsForFineElementCentroids(), FineCoarseMeshPair< DIM >::ComputeCoarseElementsForFineNodes(), FineCoarseMeshPair< DIM >::ComputeFineElementsAndWeightsForCoarseNodes(), FineCoarseMeshPair< DIM >::ComputeFineElementsAndWeightsForCoarseQuadPoints(), AbstractContinuumMechanicsAssembler< DIM, CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX >::DoAssemble(), PetscSetupUtils::InitialisePetsc(), ExecutableSupport::InitializePetsc(), Citations::Print(), and CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Solve().
|
private |
Record that an option has been used, and tell PETSc so it is not reported as unused.
| rOption | the option name. |
Definition at line 133 of file CommandLineArguments.cpp.
References PetscTools::IsInitialised(), and mUsedOptions.
Referenced by GetIndexForArgument().
| bool CommandLineArguments::OptionExists | ( | const std::string & | rOption | ) |
| rOption | the option name as a string. |
Definition at line 65 of file CommandLineArguments.cpp.
References GetIndexForArgument(), and TestOptionFormat().
Referenced by AbstractContinuumMechanicsSolver< DIM >::AbstractContinuumMechanicsSolver(), AbstractNonlinearElasticitySolver< DIM >::AbstractNonlinearElasticitySolver(), CompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), IncompressibleNonlinearElasticitySolver< DIM >::AssembleSystem(), AbstractContinuumMechanicsAssembler< DIM, CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX >::DoAssemble(), and CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Solve().
|
private |
Throw an exception if the option is not of the required form: '-' followed by a non-numeric character.
| rOption | the option name to check the format of. |
Definition at line 283 of file CommandLineArguments.cpp.
References EXCEPTION.
Referenced by GetIndexForArgument(), GetValueCorrespondingToOption(), and OptionExists().
|
staticprivate |
The single instance of the class.
Definition at line 78 of file CommandLineArguments.hpp.
Referenced by CommandLineArguments(), and Instance().
|
private |
The options that have been looked up and found.
Definition at line 81 of file CommandLineArguments.hpp.
Referenced by GetUnusedOptions(), and MarkOptionUsed().
| int* CommandLineArguments::p_argc |
The number of command line arguments.
Definition at line 108 of file CommandLineArguments.hpp.
Referenced by CommandLineArgumentsMocker::CommandLineArgumentsMocker(), CommandLineArgumentsMocker::~CommandLineArgumentsMocker(), GetIndexForArgument(), GetNumberOfArgumentsForOption(), GetUnusedOptions(), PetscSetupUtils::InitialisePetsc(), and ExecutableSupport::InitializePetsc().
| char*** CommandLineArguments::p_argv |
The arguments themselves.
Definition at line 111 of file CommandLineArguments.hpp.
Referenced by CommandLineArgumentsMocker::CommandLineArgumentsMocker(), CommandLineArgumentsMocker::~CommandLineArgumentsMocker(), GetIndexForArgument(), GetNumberOfArgumentsForOption(), GetUnusedOptions(), GetValueCorrespondingToOption(), PetscSetupUtils::InitialisePetsc(), and ExecutableSupport::InitializePetsc().