Compute Library
 21.08
ListOption< T > Class Template Reference

Implementation of an option that accepts any number of values. More...

#include <ListOption.h>

Collaboration diagram for ListOption< T >:
[legend]

Public Member Functions

 ListOption (std::string name, std::initializer_list< T > &&default_values)
 Construct the option with the given default values. 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 list of option values. 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::ListOption< T >

Implementation of an option that accepts any number of values.

Definition at line 41 of file ListOption.h.

Constructor & Destructor Documentation

◆ ListOption()

ListOption ( std::string  name,
std::initializer_list< T > &&  default_values 
)
inline

Construct the option with the given default values.

Parameters
[in]nameName of the option.
[in]default_valuesDefault values.

Definition at line 67 of file ListOption.h.

68  : Option{ std::move(name), false, true }, _values{ std::forward<std::initializer_list<T>>(default_values) }
69 {
70 }
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 ListOption.h.

References Option::name().

107 {
108  return "--" + name() + "=VALUE[,VALUE[,...]] - " + _help;
109 }
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 73 of file ListOption.h.

74 {
75  _is_set = true;
76 
77  try
78  {
79  std::stringstream stream{ value };
80  std::string item;
81 
82  while(!std::getline(stream, item, ',').fail())
83  {
84  std::stringstream item_stream(item);
85  T typed_value{};
86 
87  item_stream >> typed_value;
88 
89  if(!item_stream.fail())
90  {
91  _values.emplace_back(typed_value);
92  }
93 
94  _is_set = _is_set && !item_stream.fail();
95  }
96 
97  return _is_set;
98  }
99  catch(const std::invalid_argument &)
100  {
101  return false;
102  }
103 }
const std::vector< T > & value() const
Get the list of option values.
Definition: ListOption.h:112

◆ value()

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

Get the list of option values.

Returns
get the list of option values.

Definition at line 112 of file ListOption.h.

113 {
114  return _values;
115 }

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