input_argument.hΒΆ
A header file containing the code objects for describing the input parameters; parameters are templated and may be any type, some special cases exist for string and bool types.
- class BaseInputArgument
- #include <input_argument.h>
Base virtual class upon which GeneralInputArgument template and all specialisations are built. Common base class exists to allow for use of base class pointers in arrays to loop over all arguments
Public Functions
- virtual const char * description() const = 0
- virtual const char * flag() const = 0
- virtual bool file_argument() const = 0
- virtual bool terminal_argument() const = 0
- virtual bool found_in_terminal() const = 0
- virtual void set_found_in_terminal(bool) = 0
- virtual void set_target_variable(std::string val_string) = 0
- virtual void set_target_variable() = 0
- virtual ~BaseInputArgument()
- template <typename T>
- class GeneralInputArgument
- #include <input_argument.h>
Class containing all information relating to an individual code parameter; whether it may be found on the command line, via the parameter file or both, as well as holding pointers to target variables in the code and any default values.
Public Functions
- GeneralInputArgument(const char * desc, const char * flag, T * p, T default_value = NULL, bool in_pfile = true, bool c_val = true)
Constructor for defining code argument by parameters.
- See
- GeneralInputArgument(GeneralInputArgument const& arg)
- Parameters
- desc -
description of code argument/variable (displayed on terminal help screen)
- flag -
string to be searched for on command line as flag
- p -
pointer to the variable where inputted values will be stored
- default_value=NULL -
default value for the variable if not defined by parameter file or terminal
- in_pfile=true -
True, argument is searched for in parameter file
- c_val=true -
if True, argument is searched for in terminal input
- desc -
- GeneralInputArgument(GeneralInputArgument const & arg)
Copy constructor.
- See
- GeneralInputArgument(const char* desc, const char* flag, T* p, T default_value=NULL, bool in_pfile=true, bool c_val=true)
- Parameters
- arg -
existing code argument GeneralInputArgument object
- arg -
- ~GeneralInputArgument()
Default destructor.
- virtual const char * description() const
Access function.
- Return
- argument description
- virtual const char * flag() const
Access function.
- Return
- argument command line flag
- virtual bool file_argument() const
Access function.
- Return
- if argument is to be searched for in the parameter file
- virtual bool terminal_argument() const
Access function.
- Return
- if argument is to be searched for on the command line
- virtual bool found_in_terminal() const
Access function.
- Return
- if the argument/flag was found in the command line input
- virtual void set_found_in_terminal(bool found)
Access function, sets the argument state to store if it was in the command line input.
- Parameters
- found -
if the argumet/flag was found in the command line input
- found -
- virtual void set_target_variable(std::string val_string)
Access function, sets the argument’s corresponding variable value; virtual function.
- See
- set_target_variable()
- Parameters
- val_string -
input string to convert to target type
- val_string -
- virtual void set_target_variable()
Access function, sets the argument’s corresponding variable value in case where no inputted value is necessary; virtual function.
- T * target_variable() const
Access function.
- Return
- a pointer to the argument variable in memory
- template <>
- virtual void set_target_variable(std::string val_string)
Access function specialisation for int, sets the argument’s corresponding variable value
- See
- set_target_variable(std::string val_string)
- Parameters
- val_string -
input string to convert to int
- val_string -
- template <>
- virtual void set_target_variable(std::string val_string)
Access function specialisation for float, sets the argument’s corresponding variable value
- See
- set_target_variable(std::string val_string)
- Parameters
- val_string -
input string to convert to float
- val_string -
- template <>
- virtual void set_target_variable(std::string val_string)
Access function specialisation for double, sets the argument’s corresponding variable value
- See
- set_target_variable(std::string val_string)
- Parameters
- val_string -
input string to convert to double
- val_string -
- template <>
- virtual void set_target_variable(std::string val_string)
Access function specialisation for string, sets the argument’s corresponding variable value
- See
- set_target_variable(std::string val_string)
- Parameters
- val_string -
input string to save as string
- val_string -
- template <>
- virtual void set_target_variable(std::string val_string)
Access function specialisation for bool, sets the argument’s corresponding variable value
- See
- set_target_variable(std::string val_string)
- Parameters
- val_string -
input string to convert to bool
- val_string -
- template <>
- virtual void set_target_variable()
Access function specialisation for bool with no input value, presence of flag indicates True
- See
- set_target_variable()
- Parameters
- val_string -
input string to convert to int
- val_string -
Private Members
- const char * description_
description of code argument/variable (displayed on terminal help screen)
- const char * flag_
string to be searched for on command line as flag
- T * target_variable_
pointer to the variable where inputted values will be stored
- bool file_argument_
if True, argument is searched for in parameter file
- bool terminal_argument_
if True, argument is searched for in terminal input
- bool found_in_terminal_
if True, flag GeneralInputArgument.flag_ was found in terminal input
- class ArgumentList
- #include <input_argument.h>
Class for containing and accessing a list of code input arguments of different fundamental variable types though the use of base class pointers and the vector class
Public Functions
- ArgumentList()
Default constructor, initialises empty list with length 0.
- const int Length(void) const
Access function.
- Return
- list length (number of member objects)
- template <typename T>
- void AppendArgument(GeneralInputArgument< T > arg)
Appends a copy of and input argument object to the list.
- Parameters
- arg -
the input argument to be appended
- arg -
- BaseInputArgument *& operator[](int i)
Overloaded access operator to give array-like interface.
- Return
- reference to argument pointer at target index
- Parameters
- i -
target index
- i -
- std::vector< BaseInputArgument * >::iterator Begin()
Access iterator for member vector.
- Return
- member vector iterator for begin
- std::vector< BaseInputArgument * >::iterator End()
Access iterator for member vector.
- Return
- member vector iterator for end
- ~ArgumentList()
Default destructor iterates over list deleting member objects.
Private Members
- std::vector< BaseInputArgument * > list_
vector of base class pointers to hold argument addresses
- int length_
number of members in the argument list