Command  0.3
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
command::Option< ParameterType > Class Template Reference

#include <option.h>

Inheritance diagram for command::Option< ParameterType >:
[legend]
Collaboration diagram for command::Option< ParameterType >:
[legend]

Public Types

typedef std::string OptionName
 
- Public Types inherited from command::Parameter
typedef class Parameter Type
 

Public Member Functions

 Option (const std::string &name, const std::string &description, std::function< void(ParameterType)> function)
 
virtual void handle ()
 
virtual bool understand (const std::string &argv)
 
virtual unsigned int valuePosition (const std::string &value)
 
- Public Member Functions inherited from command::Parameter
 Parameter (const std::string &description)
 
virtual void handle ()=0
 
virtual bool understand (const std::string &)=0
 
virtual bool isRequired ()
 
virtual bool isUsed ()
 
virtual bool hungryForValue ()
 
virtual unsigned int valuePosition (const std::string &)=0
 
- Public Member Functions inherited from command::Descriptive
 Descriptive (const std::string &description)
 
const std::string & describe ()
 
- Public Member Functions inherited from command::Callable< ParameterType >
 Callable (std::function< void(ParameterType)> function)
 

Protected Member Functions

bool hasName (const std::string &argv)
 
- Protected Member Functions inherited from command::Callable< ParameterType >
void call (ParameterType value)
 

Protected Attributes

const OptionName name
 
ParameterType value
 
- Protected Attributes inherited from command::Parameter
bool used = false
 
- Protected Attributes inherited from command::Callable< ParameterType >
std::function< void(ParameterType)> func
 

Detailed Description

template<typename ParameterType>
class command::Option< ParameterType >

Class responsible for handling commandline options. Options are named parameters of program.

Example:

Constructor & Destructor Documentation

◆ Option()

template<typename ParameterType >
command::Option< ParameterType >::Option ( const std::string &  name,
const std::string &  description,
std::function< void(ParameterType)>  function 
)
inline

Default constructor.

Parameters
nameName of the current Option
descriptionDescription of current Option
functionFunction used to handle current Option.

Member Function Documentation

◆ handle()

template<typename ParameterType >
virtual void command::Option< ParameterType >::handle ( )
inlinevirtual

Method used for handling method calls linked with this Parameter

Implements command::Parameter.

◆ understand()

template<typename ParameterType >
virtual bool command::Option< ParameterType >::understand ( const std::string &  argv)
inlinevirtual

Method used for checking if Option understands given user value. If so current Option is flagged as used and no more checks against it will be done in future.

Passed value should be in form of: OptionName=OptionValue

If no equal sign is after OptionName part, std::invalid_argument exception with appropriate message is thrown

If conversion of OptionValue part to ParameterType failed, std::invalid_argument exception with appropriate message is thrown

Parameters
argvcommand line value against which test will be made. User value should be in format: OptionName=OptionValue.
Returns
If passed argv succesfully detected OptionName part as a current option and its OptionValue part has been succesfully converted to ParameterType, returns true and Option is set as used one. Otherwise returns false and can be used to check against next value.
Exceptions
MissingOptionValuewhen OptionValue part is missing after equal sign
OptionFailedConversionwhen OptionValue part failed conversion to ParameterType

Implements command::Parameter.

◆ valuePosition()

template<typename ParameterType >
virtual unsigned int command::Option< ParameterType >::valuePosition ( const std::string &  value)
inlinevirtual

Returns
position where value starts in passed string

Implements command::Parameter.

Member Data Documentation

◆ name

template<typename ParameterType >
const OptionName command::Option< ParameterType >::name
protected

Current Option name

◆ value

template<typename ParameterType >
ParameterType command::Option< ParameterType >::value
protected

Current Option value


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