Compute Library
 23.08
EnumOption< T > Class Template Reference

Implementation of a simple option that accepts a value from a fixed set. More...

#include <EnumOption.h>

Collaboration diagram for EnumOption< T >:
[legend]

Public Member Functions

 EnumOption (std::string name, std::set< T > allowed_values)
 Construct option with allowed values. More...
 
 EnumOption (std::string name, std::set< T > allowed_values, T default_value)
 Construct option with allowed values, a fixed number of accepted values and default values for the option. 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 selected value. More...
 
- Public Member Functions inherited from SimpleOption< T >
 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...
 
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::EnumOption< T >

Implementation of a simple option that accepts a value from a fixed set.

Definition at line 40 of file EnumOption.h.

Constructor & Destructor Documentation

◆ EnumOption() [1/2]

EnumOption ( std::string  name,
std::set< T >  allowed_values 
)
inline

Construct option with allowed values.

Parameters
[in]nameName of the option.
[in]allowed_valuesSet of allowed values for the option.

Definition at line 72 of file EnumOption.h.

73  : SimpleOption<T>{ std::move(name) }, _allowed_values{ std::move(allowed_values) }
74 {
75 }

◆ EnumOption() [2/2]

EnumOption ( std::string  name,
std::set< T >  allowed_values,
default_value 
)
inline

Construct option with allowed values, a fixed number of accepted values and default values for the option.

Parameters
[in]nameName of the option.
[in]allowed_valuesSet of allowed values for the option.
[in]default_valueDefault value.

Definition at line 78 of file EnumOption.h.

79  : SimpleOption<T>{ std::move(name), std::move(default_value) }, _allowed_values{ std::move(allowed_values) }
80 {
81 }

Member Function Documentation

◆ help()

std::string help ( ) const
overridevirtual

Help message for the option.

Returns
String representing the help message for the specific subclass.

Implements Option.

Definition at line 114 of file EnumOption.h.

115 {
116  std::stringstream msg;
117  msg << "--" + this->name() + "={";
118 
119  for(const auto &value : _allowed_values)
120  {
121  msg << value << ",";
122  }
123 
124  msg << "} - " << this->_help;
125 
126  return msg.str();
127 }

◆ parse()

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 84 of file EnumOption.h.

85 {
86  try
87  {
88  std::stringstream stream{ value };
89  T typed_value{};
90 
91  stream >> typed_value;
92 
93  if(!stream.fail())
94  {
95  if(_allowed_values.count(typed_value) == 0)
96  {
97  return false;
98  }
99 
100  this->_value = std::move(typed_value);
101  this->_is_set = true;
102  return true;
103  }
104 
105  return false;
106  }
107  catch(const std::invalid_argument &)
108  {
109  return false;
110  }
111 }

◆ value()

const T & value
inline

Get the selected value.

Returns
get the selected enum value.

Definition at line 130 of file EnumOption.h.

131 {
132  return this->_value;
133 }

Referenced by gemm_tuner::consume_common_gemm_example_parameters(), arm_compute::utils::consume_common_graph_parameters(), CommonGraphValidateOptions::consume_common_parameters(), CommonOptions::create_printers(), and main().


The documentation for this class was generated from the following file:
arm_compute::utils::Option::name
std::string name() const
Name of the option.
Definition: Option.h:115
arm_compute::utils::EnumOption::value
const T & value() const
Get the selected value.
Definition: EnumOption.h:130