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 214 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 220 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 495 of file CommandLine.h.

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

279{ 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 283 of file CommandLine.h.

283{ 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 285 of file CommandLine.h.

285{ 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 259 of file CommandLine.h.

259{ 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 261 of file CommandLine.h.

261{ 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 275 of file CommandLine.h.

275{ 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 265 of file CommandLine.h.

265{ 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 277 of file CommandLine.h.

277{ 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 281 of file CommandLine.h.

281{ 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 263 of file CommandLine.h.

263{ 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 250 of file CommandLine.h.

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

◆ 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 267 of file CommandLine.h.

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

◆ 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: