Compute Library
 21.05
SimpleOption< T > Class Template Reference

Implementation of an option that accepts a single value. More...

#include <SimpleOption.h>

Collaboration diagram for SimpleOption< T >:
[legend]

Public Member Functions

 SimpleOption (std::string name, T default_value)
 Construct the option with the given default value. More...
 
bool parse (std::string value) override
 Parses the given string. More...
 
std::string help () const override
 Help message for the option. More...
 
const T & value () const
 Get the option value. More...
 
template<>
bool parse (std::string value)
 Parses the given string. More...
 
 Option (std::string name)
 Constructor. More...
 
 Option (std::string name, bool is_required, bool is_set)
 Constructor. More...
 
- Public Member Functions inherited from Option
 Option (std::string name)
 Constructor. More...
 
 Option (std::string name, bool is_required, bool is_set)
 Constructor. More...
 
virtual ~Option ()=default
 Default destructor. More...
 
std::string name () const
 Name of the option. More...
 
void set_required (bool is_required)
 Set whether the option is required. More...
 
void set_help (std::string help)
 Set the help message for the option. More...
 
bool is_required () const
 Is the option required? More...
 
bool is_set () const
 Has a value been assigned to the option? More...
 

Detailed Description

template<typename T>
class arm_compute::utils::SimpleOption< T >

Implementation of an option that accepts a single value.

Definition at line 39 of file SimpleOption.h.

Constructor & Destructor Documentation

◆ SimpleOption()

SimpleOption ( std::string  name,
default_value 
)
inline

Construct the option with the given default value.

Parameters
[in]nameName of the option.
[in]default_valueDefault value.

Definition at line 76 of file SimpleOption.h.

77  : Option{ std::move(name), false, true }, _value{ std::move(default_value) }
78 {
79 }
std::string name() const
Name of the option.
Definition: Option.h:115
Option(std::string name)
Constructor.
Definition: Option.h:105

Member Function Documentation

◆ help()

std::string help ( ) const
inlineoverridevirtual

Help message for the option.

Returns
String representing the help message for the specific subclass.

Implements Option.

Definition at line 106 of file SimpleOption.h.

107 {
108  return "--" + name() + "=VALUE - " + _help;
109 }
std::string name() const
Name of the option.
Definition: Option.h:115

◆ Option() [1/2]

Option
inline

Constructor.

Parameters
[in]nameName of the option.

Definition at line 105 of file Option.h.

106  : _name{ std::move(name) }
107 {
108 }
std::string name() const
Name of the option.
Definition: Option.h:115

◆ Option() [2/2]

Option
inline

Constructor.

Parameters
[in]nameName of the option.
[in]is_requiredIs the option required?
[in]is_setHas a value been assigned to the option?

Definition at line 110 of file Option.h.

111  : _name{ std::move(name) }, _is_required{ is_required }, _is_set{ is_set }
112 {
113 }
std::string name() const
Name of the option.
Definition: Option.h:115
bool is_required() const
Is the option required?
Definition: Option.h:130
bool is_set() const
Has a value been assigned to the option?
Definition: Option.h:135

◆ parse() [1/2]

bool parse ( std::string  value)
overridevirtual

Parses the given string.

Parameters
[in]valueString representation as passed on the command line.
Returns
True if the value could be parsed by the specific subclass.

Implements Option.

Definition at line 82 of file SimpleOption.h.

83 {
84  try
85  {
86  std::stringstream stream{ std::move(value) };
87  stream >> _value;
88  _is_set = !stream.fail();
89  return _is_set;
90  }
91  catch(const std::invalid_argument &)
92  {
93  return false;
94  }
95 }
const T & value() const
Get the option value.
Definition: SimpleOption.h:112

◆ parse() [2/2]

bool parse ( std::string  value)
inlinevirtual

Parses the given string.

Parameters
[in]valueString representation as passed on the command line.
Returns
True if the value could be parsed by the specific subclass.

Implements Option.

Definition at line 98 of file SimpleOption.h.

99 {
100  _value = std::move(value);
101  _is_set = true;
102  return true;
103 }
const T & value() const
Get the option value.
Definition: SimpleOption.h:112

◆ value()

const T & value ( ) const
inline

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