Compute Library
 21.05
EnumListOption< T > Class Template Reference

Implementation of an option that accepts any number of values from a fixed set. More...

#include <EnumListOption.h>

Collaboration diagram for EnumListOption< T >:
[legend]

Public Member Functions

 EnumListOption (std::string name, std::set< T > allowed_values)
 Construct option with allowed values. More...
 
 EnumListOption (std::string name, std::set< T > allowed_values, std::initializer_list< T > &&default_values)
 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 std::vector< T > & value () const
 Get the values of the option. 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::EnumListOption< T >

Implementation of an option that accepts any number of values from a fixed set.

Definition at line 42 of file EnumListOption.h.

Constructor & Destructor Documentation

◆ EnumListOption() [1/2]

EnumListOption ( 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 75 of file EnumListOption.h.

76  : Option{ std::move(name) }, _allowed_values{ std::move(allowed_values) }
77 {
78 }
std::string name() const
Name of the option.
Definition: Option.h:115
Option(std::string name)
Constructor.
Definition: Option.h:105

◆ EnumListOption() [2/2]

EnumListOption ( std::string  name,
std::set< T >  allowed_values,
std::initializer_list< T > &&  default_values 
)
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_valuesDefault values.

Definition at line 81 of file EnumListOption.h.

82  : Option{ std::move(name), false, true }, _values{ std::forward<std::initializer_list<T>>(default_values) }, _allowed_values{ std::move(allowed_values) }
83 {
84 }
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
overridevirtual

Help message for the option.

Returns
String representing the help message for the specific subclass.

Implements Option.

Definition at line 128 of file EnumListOption.h.

129 {
130  std::stringstream msg;
131  msg << "--" + name() + "={";
132 
133  for(const auto &value : _allowed_values)
134  {
135  msg << value << ",";
136  }
137 
138  msg << "}[,{...}[,...]] - " << _help;
139 
140  return msg.str();
141 }
const std::vector< T > & value() const
Get the values of the option.
std::string name() const
Name of the option.
Definition: Option.h:115

◆ 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 87 of file EnumListOption.h.

88 {
89  // Remove default values
90  _values.clear();
91  _is_set = true;
92 
93  std::stringstream stream{ value };
94  std::string item;
95 
96  while(!std::getline(stream, item, ',').fail())
97  {
98  try
99  {
100  std::stringstream item_stream(item);
101  T typed_value{};
102 
103  item_stream >> typed_value;
104 
105  if(!item_stream.fail())
106  {
107  if(_allowed_values.count(typed_value) == 0)
108  {
109  _is_set = false;
110  continue;
111  }
112 
113  _values.emplace_back(typed_value);
114  }
115 
116  _is_set = _is_set && !item_stream.fail();
117  }
118  catch(const std::invalid_argument &)
119  {
120  _is_set = false;
121  }
122  }
123 
124  return _is_set;
125 }
const std::vector< T > & value() const
Get the values of the option.

◆ value()

const std::vector< T > & value ( ) const
inline

Get the values of the option.

Returns
a list of the selected option values.

Definition at line 144 of file EnumListOption.h.

145 {
146  return _values;
147 }

Referenced by main().


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