ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnc::cli::Option< T > Class Template Referencefinal

this class describes command line option More...

#include <CommandLine.h>

Collaboration diagram for nnc::cli::Option< T >:

Public Types

using option_checker_t = void(*)(const Option< T > &)
 function type for option verification
 
- Public Types inherited from nnc::cli::IOption
enum class  Group { none = 0 , caffe2 = 1 , onnx = 2 }
 

Public Member Functions

 Option (const std::vector< std::string > &optnames, const std::string &descr, const T &default_val=T(), bool is_optional=false, const std::vector< std::string > &vals=std::vector< std::string >(), option_checker_t checker=nullptr, const std::vector< char > &seps=std::vector< char >(), bool enabled=true, IOption::Group group=IOption::Group::none)
 construct an option
 
 Option (const Option &)=delete
 
Optionoperator= (const Option &)=delete
 
template<typename Tval >
T & operator= (const Tval &val)
 overload assignment operator for type
 
void setValue (const std::string &val) override
 set option value
 
const std::vector< std::string > & getNames () const override
 get all names of option
 
const std::string & getOverview () const override
 get description of option
 
bool isOptional () const override
 may option be optional?
 
const std::vector< std::string > & getValidVals () const override
 get valid values for given option
 
void runCheckerFunc () override
 function for option verification
 
const std::vector< char > & getSeparators () const override
 get separators for option
 
bool isDisabled () const override
 is option disabled?
 
bool canHaveSeveralVals () const override
 can option have several values?
 
bool isGrouped () const override
 
IOption::Group getGroup () const override
 
std::string getGroupName () const override
 name of option group
 
void setValue (const std::string &val)
 set option value
 
void setValue (const std::string &val)
 set option value
 
void setValue (const std::string &val)
 set option value
 
void setValue (const std::string &val)
 set option value
 
void setValue (const std::string &val)
 set option value
 
void setValue (const std::string &val)
 set option value
 
void setValue (const std::string &val)
 set option value
 
void setValue (const std::string &val)
 set option value
 
void setValue (const std::string &val)
 set option value
 
void setValue (const std::string &val)
 set option value
 
void setValue (const std::string &val)
 set option value
 
- Public Member Functions inherited from nnc::cli::OptionType< T, std::is_class< T >::value >
 OptionType ()=default
 

Additional Inherited Members

- Static Protected Attributes inherited from nnc::cli::IOption
static constexpr const char *const _groupNames [] = {nullptr, "caffe2", "onnx"}
 

Detailed Description

template<typename T>
class nnc::cli::Option< T >

this class describes command line option

Template Parameters
T- type of option

Definition at line 215 of file CommandLine.h.

Member Typedef Documentation

◆ option_checker_t

template<typename T >
using nnc::cli::Option< T >::option_checker_t = void (*)(const Option<T> &)

function type for option verification

Definition at line 221 of file CommandLine.h.

Constructor & Destructor Documentation

◆ Option() [1/2]

template<typename T >
nnc::cli::Option< T >::Option ( const std::vector< std::string > &  optnames,
const std::string &  descr,
const T &  default_val = T(),
bool  is_optional = false,
const std::vector< std::string > &  vals = std::vector<std::string>(),
option_checker_t  checker = nullptr,
const std::vector< char > &  seps = std::vector<char>(),
bool  enabled = true,
IOption< T >::Group  group = IOption< T >::Group::none 
)
explicit

construct an option

Template Parameters
T- type of an option
Parameters
optnames- names of option
descr- overview of option
default_val- option value accepted by default
is_optional- is option optional?
vals- valid values for option. Other values are interpreted as invalid
checker- function verifies option
seps- symbols that separates name option from value (by default is spaces)
enabled- if this option is set to false then it won't be shown for users
group- all options can be splitted into groups so this param sets group for option

Definition at line 496 of file CommandLine.h.

500{
501 // save all names
502 for (const auto &n : optnames)
503 {
504 _names.push_back(n);
505
506 assert(n[0] == '-' && "option name must start with `-`");
507 }
508
509 _descr = descr;
510 _is_optional = is_optional;
511 _valid_vals = vals;
512 _seps = seps;
513
514 this->setRawValue(default_val);
515
516#ifndef NDEBUG
517 // check that separators are valid symbols
518 for (const auto &s : _seps)
519 {
520 assert((s == '=' || s == ':') && "invalid option separators");
521 }
522#endif // NDEBUG
523
524 // save checker
525 _checker = checker;
526
527 _is_enabled = enabled;
528 assert((_is_enabled || _is_optional || group != IOption::Group::none) &&
529 "disabled non-group option can't be required");
530
531 _group = group;
532
533 _can_have_several_vals =
534 std::is_same<T, std::vector<std::string>>::value || std::is_same<T, std::vector<int>>::value;
535 assert(!(_can_have_several_vals && !_seps.empty()) &&
536 "option with several values can't have separators");
537
538 // register new option for parser
540
541} // Option
void registerOption(IOption *opt)
register option for parser
static CommandLine * getParser()
singleton method

References nnc::cli::CommandLine::getParser(), nnc::cli::IOption::none, and nnc::cli::CommandLine::registerOption().

◆ Option() [2/2]

template<typename T >
nnc::cli::Option< T >::Option ( const Option< T > &  )
delete

Member Function Documentation

◆ canHaveSeveralVals()

template<typename T >
bool nnc::cli::Option< T >::canHaveSeveralVals ( ) const
inlineoverridevirtual

can option have several values?

Implements nnc::cli::IOption.

Definition at line 280 of file CommandLine.h.

280{ return _can_have_several_vals; }

◆ getGroup()

template<typename T >
IOption::Group nnc::cli::Option< T >::getGroup ( ) const
inlineoverridevirtual
Returns
group in which option is put

Implements nnc::cli::IOption.

Definition at line 284 of file CommandLine.h.

284{ return _group; }

◆ getGroupName()

template<typename T >
std::string nnc::cli::Option< T >::getGroupName ( ) const
inlineoverridevirtual

name of option group

Implements nnc::cli::IOption.

Definition at line 286 of file CommandLine.h.

286{ return _groupNames[static_cast<size_t>(_group)]; }
static constexpr const char *const _groupNames[]

References nnc::cli::IOption::_groupNames.

◆ getNames()

template<typename T >
const std::vector< std::string > & nnc::cli::Option< T >::getNames ( ) const
inlineoverridevirtual

get all names of option

Implements nnc::cli::IOption.

Definition at line 260 of file CommandLine.h.

260{ return _names; }

◆ getOverview()

template<typename T >
const std::string & nnc::cli::Option< T >::getOverview ( ) const
inlineoverridevirtual

get description of option

Implements nnc::cli::IOption.

Definition at line 262 of file CommandLine.h.

262{ return _descr; }

◆ getSeparators()

template<typename T >
const std::vector< char > & nnc::cli::Option< T >::getSeparators ( ) const
inlineoverridevirtual

get separators for option

Implements nnc::cli::IOption.

Definition at line 276 of file CommandLine.h.

276{ return _seps; }

◆ getValidVals()

template<typename T >
const std::vector< std::string > & nnc::cli::Option< T >::getValidVals ( ) const
inlineoverridevirtual

get valid values for given option

Implements nnc::cli::IOption.

Definition at line 266 of file CommandLine.h.

266{ return _valid_vals; }

◆ isDisabled()

template<typename T >
bool nnc::cli::Option< T >::isDisabled ( ) const
inlineoverridevirtual

is option disabled?

Implements nnc::cli::IOption.

Definition at line 278 of file CommandLine.h.

278{ return !_is_enabled; }

◆ isGrouped()

template<typename T >
bool nnc::cli::Option< T >::isGrouped ( ) const
inlineoverridevirtual
Returns
true if option is in group

Implements nnc::cli::IOption.

Definition at line 282 of file CommandLine.h.

282{ return _group != IOption::Group::none; }

References nnc::cli::IOption::none.

◆ isOptional()

template<typename T >
bool nnc::cli::Option< T >::isOptional ( ) const
inlineoverridevirtual

may option be optional?

Implements nnc::cli::IOption.

Definition at line 264 of file CommandLine.h.

264{ return _is_optional; }

◆ operator=() [1/2]

template<typename T >
Option & nnc::cli::Option< T >::operator= ( const Option< T > &  )
delete

◆ operator=() [2/2]

template<typename T >
template<typename Tval >
T & nnc::cli::Option< T >::operator= ( const Tval &  val)
inline

overload assignment operator for type

Definition at line 251 of file CommandLine.h.

252 { // NOLINT(cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator)
253 setRawValue(val);
254 return this->getRawValue(); // If not using `this` it won't work
255 }

◆ runCheckerFunc()

template<typename T >
void nnc::cli::Option< T >::runCheckerFunc ( )
inlineoverridevirtual

function for option verification

Exceptions
thisfunction throws exception of BadOption type if verification is not passed

Implements nnc::cli::IOption.

Definition at line 268 of file CommandLine.h.

269 {
270 if (_checker)
271 {
272 _checker(*this);
273 }
274 }

◆ setValue() [1/12]

void nnc::cli::Option< std::string >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 561 of file CommandLine.cpp.

562{
563 if (!val.empty())
564 this->setRawValue(val);
565}

◆ setValue() [2/12]

void nnc::cli::Option< std::vector< std::string > >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 568 of file CommandLine.cpp.

569{
570 if (!val.empty())
571 this->push_back(val);
572}

◆ setValue() [3/12]

void nnc::cli::Option< std::vector< int > >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 575 of file CommandLine.cpp.

576{
577 if (!val.empty())
578 this->push_back(stoi(val));
579}

◆ setValue() [4/12]

void nnc::cli::Option< bool >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 582 of file CommandLine.cpp.

583{
584 this->setRawValue(this->convToBool(val));
585}

◆ setValue() [5/12]

void nnc::cli::Option< char >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 588 of file CommandLine.cpp.

589{
590 if (!val.empty())
591 this->setRawValue(this->convToChar(val));
592}

◆ setValue() [6/12]

void nnc::cli::Option< int8_t >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 595 of file CommandLine.cpp.

596{
597 if (!val.empty())
598 this->setRawValue(this->template convToNum<int64_t>(val));
599}

◆ setValue() [7/12]

void nnc::cli::Option< int16_t >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 602 of file CommandLine.cpp.

603{
604 if (!val.empty())
605 this->setRawValue(this->template convToNum<int64_t>(val));
606}

◆ setValue() [8/12]

void nnc::cli::Option< int32_t >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 609 of file CommandLine.cpp.

610{
611 if (!val.empty())
612 this->setRawValue(this->template convToNum<int64_t>(val));
613}

◆ setValue() [9/12]

void nnc::cli::Option< uint8_t >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 616 of file CommandLine.cpp.

617{
618 if (!val.empty())
619 this->setRawValue(this->template convToNum<uint64_t>(val));
620}

◆ setValue() [10/12]

void nnc::cli::Option< uint16_t >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 623 of file CommandLine.cpp.

624{
625 if (!val.empty())
626 this->setRawValue(this->template convToNum<uint64_t>(val));
627}

◆ setValue() [11/12]

void nnc::cli::Option< uint32_t >::setValue ( const std::string &  val)
virtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.

Definition at line 630 of file CommandLine.cpp.

631{
632 if (!val.empty())
633 this->setRawValue(this->template convToNum<uint64_t>(val));
634}

◆ setValue() [12/12]

template<typename T >
void nnc::cli::Option< T >::setValue ( const std::string &  val)
overridevirtual

set option value

Parameters
val- value of option in string format

Implements nnc::cli::IOption.


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