CommandLineArguments Class Reference

#include <CommandLineArguments.hpp>

Collaboration diagram for CommandLineArguments:

Collaboration graph
[legend]

List of all members.

Public Member Functions

bool OptionExists (std::string option)
char * GetValueCorrespondingToOption (std::string option)
double GetDoubleCorrespondingToOption (std::string option)
int GetIntCorrespondingToOption (std::string option)
unsigned GetUnsignedCorrespondingToOption (std::string option)

Static Public Member Functions

static CommandLineArgumentsInstance ()

Public Attributes

int * p_argc
char *** p_argv

Private Member Functions

 CommandLineArguments ()
 CommandLineArguments (const CommandLineArguments &)
CommandLineArgumentsoperator= (const CommandLineArguments &)
int GetIndexForArgument (std::string argument)

Static Private Attributes

static CommandLineArgumentsmpInstance = NULL


Detailed Description

A convenient holder for the command line arguments, with a couple of helper methods for checking whether an option has been given or getting the value corresponding to a given option.

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.

Definition at line 42 of file CommandLineArguments.hpp.


Constructor & Destructor Documentation

CommandLineArguments::CommandLineArguments (  )  [private]

Default constructor. Should never be called directly, call CommandLineArguments::Instance() instead.

Definition at line 34 of file CommandLineArguments.cpp.

References mpInstance.

CommandLineArguments::CommandLineArguments ( const CommandLineArguments  )  [private]

Copy constructor.


Member Function Documentation

CommandLineArguments& CommandLineArguments::operator= ( const CommandLineArguments  )  [private]

Overloaded assignment operator.

int CommandLineArguments::GetIndexForArgument ( std::string  argument  )  [private]

Get the index for the given argument. Returns -1 if the argument is not found.

Parameters:
argument The argument as a string. This should start with "-", for example "-my_arg" "-timestep" etc.

Definition at line 100 of file CommandLineArguments.cpp.

References p_argc, and p_argv.

Referenced by GetValueCorrespondingToOption(), and OptionExists().

CommandLineArguments * CommandLineArguments::Instance (  )  [static]

Get the single instance of this class.

Definition at line 42 of file CommandLineArguments.cpp.

References mpInstance.

Referenced by ExecutableSupport::InitializePetsc(), and PetscSetup::setUpWorld().

bool CommandLineArguments::OptionExists ( std::string  option  ) 

Check whether a given option exists in the command line arguments.

Parameters:
option The option as a string. This should start with "-", for example "-implicit_scheme" "-no_output" etc.

Definition at line 53 of file CommandLineArguments.cpp.

References GetIndexForArgument().

char * CommandLineArguments::GetValueCorrespondingToOption ( std::string  option  ) 

Get the value for a given option, ie 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.

Parameters:
option The option as a string. This should start with "-", for example "-my_param" "-timestep" etc.

Definition at line 61 of file CommandLineArguments.cpp.

References EXCEPTION, GetIndexForArgument(), p_argc, and p_argv.

Referenced by GetDoubleCorrespondingToOption(), GetIntCorrespondingToOption(), and GetUnsignedCorrespondingToOption().

double CommandLineArguments::GetDoubleCorrespondingToOption ( std::string  option  ) 

Get the double for a given option.

This uses GetValueCorrespondingToOption and converts the char* to a double.

Parameters:
option The option as a string. This should start with "-", for example "-my_param", "-timestep" etc.

Definition at line 77 of file CommandLineArguments.cpp.

References GetValueCorrespondingToOption().

int CommandLineArguments::GetIntCorrespondingToOption ( std::string  option  ) 

Get the int for a given option.

This uses GetValueCorrespondingToOption and converts the char* to an int.

Parameters:
option The option as a string. This should start with "-", for example "-my_param", "-timestep" etc.

Definition at line 83 of file CommandLineArguments.cpp.

References GetValueCorrespondingToOption().

unsigned CommandLineArguments::GetUnsignedCorrespondingToOption ( std::string  option  ) 

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.

Parameters:
option The option as a string. This should start with "-", for example "-my_param", "-timestep" etc.

Definition at line 89 of file CommandLineArguments.cpp.

References EXCEPTION, and GetValueCorrespondingToOption().


Member Data Documentation

The single instance of the class.

Definition at line 55 of file CommandLineArguments.hpp.

Referenced by CommandLineArguments(), and Instance().

The number of command line arguments.

Definition at line 67 of file CommandLineArguments.hpp.

Referenced by GetIndexForArgument(), GetValueCorrespondingToOption(), ExecutableSupport::InitializePetsc(), and PetscSetup::setUpWorld().


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

Generated on Tue May 31 14:33:06 2011 for Chaste by  doxygen 1.5.5