PIDUINO
Loading...
Searching...
No Matches
Piduino::Implicit< T >

Value option with implicit default value. More...

#include <popl.h>

Inheritance diagram for Piduino::Implicit< T >:
Collaboration diagram for Piduino::Implicit< T >:

Public Member Functions

 Implicit (const std::string &short_name, const std::string &long_name, const std::string &description, const T &implicit_val, T *assign_to=nullptr)
 Implicit implementation /////////////////////////////////.
 
Argument argument_type () const override
 
size_t count () const override
 
bool is_set () const override
 
void assign_to (T *var)
 
void set_value (const T &value)
 
value (size_t idx=0) const
 
void set_default (const T &value)
 
bool has_default () const
 
get_default () const
 
bool get_default (std::ostream &out) const override
 
char short_name () const
 
std::string long_name () const
 
std::string name (OptionName what_name, bool with_hypen=false) const
 
std::string description () const
 
void set_attribute (const Attribute &attribute)
 
Attribute attribute () const
 

Protected Member Functions

void parse (OptionName what_name, const char *value) override
 
virtual void update_reference ()
 
virtual void add_value (const T &value)
 
void clear () override
 Clear the internal data structure.
 

Protected Attributes

std::unique_ptr< T > default_
 
T * assign_to_
 
std::vector< T > values_
 
std::string short_name_
 
std::string long_name_
 
std::string description_
 
Attribute attribute_
 

Detailed Description

template<class T>
class Piduino::Implicit< T >

Value option with implicit default value.

Value option with implicit default value If set, an argument is optional -without argument it carries the implicit default value -with argument it carries the explicit value

Definition at line 251 of file popl.h.

Constructor & Destructor Documentation

◆ Implicit()

template<class T >
Piduino::Implicit< T >::Implicit ( const std::string &  short_name,
const std::string &  long_name,
const std::string &  description,
const T &  implicit_val,
T *  assign_to = nullptr 
)
inline

Implicit implementation /////////////////////////////////.

Definition at line 737 of file popl.h.

Member Function Documentation

◆ add_value()

template<class T >
void Piduino::Value< T >::add_value ( const T &  value)
inlineprotectedvirtualinherited

Definition at line 720 of file popl.h.

◆ argument_type()

template<class T >
Argument Piduino::Implicit< T >::argument_type ( ) const
inlineoverridevirtual

Get the Option's argument type

Returns
argument type (no, required, optional)

Implements Piduino::Option.

Definition at line 743 of file popl.h.

References Piduino::optional.

◆ assign_to()

template<class T >
void Piduino::Value< T >::assign_to ( T *  var)
inlineinherited

Assign the last parsed command line value to "var"

Parameters
varpointer to the variable where is value is written to

Definition at line 579 of file popl.h.

Referenced by Piduino::Value< T >::Value().

◆ attribute()

Attribute Piduino::Option::attribute ( ) const
inlineinherited

Get the Option's attribute

Returns
the Options's attribute

Definition at line 542 of file popl.h.

References Piduino::Option::attribute_.

Referenced by Piduino::Option::set_attribute().

◆ clear()

template<class T >
void Piduino::Value< T >::clear ( )
inlineoverrideprotectedvirtualinherited

Clear the internal data structure.

Implements Piduino::Option.

Definition at line 727 of file popl.h.

◆ count()

template<class T >
size_t Piduino::Value< T >::count ( ) const
inlineoverridevirtualinherited

Check how often the Option is set on command line

Returns
the Option's count on command line

Implements Piduino::Option.

Definition at line 567 of file popl.h.

◆ description()

std::string Piduino::Option::description ( ) const
inlineinherited

Get the Option's description

Returns
the description

Definition at line 532 of file popl.h.

References Piduino::Option::description_.

◆ get_default() [1/2]

template<class T >
T Piduino::Value< T >::get_default ( ) const
inlineinherited

Get the Option's default value. Will throw if no default is set.

Returns
the Option's default value

Definition at line 638 of file popl.h.

◆ get_default() [2/2]

template<class T >
bool Piduino::Value< T >::get_default ( std::ostream &  out) const
inlineoverridevirtualinherited

Get the Option's default value

Parameters
outstream to write the default value to
Returns
true if a default value is available, false if not

Implements Piduino::Option.

Definition at line 647 of file popl.h.

◆ has_default()

template<class T >
bool Piduino::Value< T >::has_default ( ) const
inlineinherited

Check if the Option has a default value

Returns
true if the Option has a default value

Definition at line 632 of file popl.h.

◆ is_set()

template<class T >
bool Piduino::Value< T >::is_set ( ) const
inlineoverridevirtualinherited

Check if the Option is set

Returns
true if set at least once

Implements Piduino::Option.

Definition at line 573 of file popl.h.

◆ long_name()

std::string Piduino::Option::long_name ( ) const
inlineinherited

Get the Option's long name

Returns
the long name of the Option. Empty string if no long name is defined

Definition at line 516 of file popl.h.

References Piduino::Option::long_name_.

Referenced by Piduino::Option::Option().

◆ name()

std::string Piduino::Option::name ( OptionName  what_name,
bool  with_hypen = false 
) const
inlineinherited

Get the Option's long or short name

Parameters
what_namethe option's name to return
what_hyphenpreced the returned name with (double-)hypen
Returns
the requested name of the Option. Empty string if not defined.

Definition at line 521 of file popl.h.

References Piduino::long_name, Piduino::Option::long_name_, Piduino::short_name, and Piduino::Option::short_name_.

◆ parse()

template<class T >
void Piduino::Implicit< T >::parse ( OptionName  what_name,
const char *  value 
)
inlineoverrideprotectedvirtual

Parse the command line option and fill the internal data structure

Parameters
what_nameshort or long option name
valuethe value as given on command line

Implements Piduino::Option.

Definition at line 749 of file popl.h.

References Piduino::Value< T >::parse().

Here is the call graph for this function:

◆ set_attribute()

void Piduino::Option::set_attribute ( const Attribute attribute)
inlineinherited

Set the Option's attribute

Parameters
attribute

Definition at line 537 of file popl.h.

References Piduino::Option::attribute(), and Piduino::Option::attribute_.

Here is the call graph for this function:

◆ set_default()

template<class T >
void Piduino::Value< T >::set_default ( const T &  value)
inlineinherited

Set the Option's default value

Parameters
valuethe default value if not specified on command line

Definition at line 624 of file popl.h.

Referenced by Piduino::Value< T >::Value().

◆ set_value()

template<class T >
void Piduino::Value< T >::set_value ( const T &  value)
inlineinherited

Manually set the Option's value. Deletes current value(s)

Parameters
valuethe new value of the option

Definition at line 586 of file popl.h.

◆ short_name()

char Piduino::Option::short_name ( ) const
inlineinherited

Get the Option's short name

Returns
character of the options's short name or 0 if no short name is defined

Definition at line 508 of file popl.h.

References Piduino::Option::short_name_.

Referenced by Piduino::Option::Option().

◆ update_reference()

template<class T >
void Piduino::Value< T >::update_reference ( )
inlineprotectedvirtualinherited

Definition at line 710 of file popl.h.

◆ value()

template<class T >
T Piduino::Value< T >::value ( size_t  idx = 0) const
inlineinherited

Get the Option's value. Will throw if option at index idx is not available

Parameters
idxthe zero based index of the value (if set multiple times)
Returns
the Option's value at index "idx"

Definition at line 593 of file popl.h.

References Piduino::long_name, and Piduino::short_name.

Member Data Documentation

◆ assign_to_

template<class T >
T* Piduino::Value< T >::assign_to_
protectedinherited

Definition at line 236 of file popl.h.

Referenced by Piduino::Value< T >::Value().

◆ attribute_

Attribute Piduino::Option::attribute_
protectedinherited

Definition at line 169 of file popl.h.

Referenced by Piduino::Option::attribute(), and Piduino::Option::set_attribute().

◆ default_

template<class T >
std::unique_ptr<T> Piduino::Value< T >::default_
protectedinherited

Definition at line 230 of file popl.h.

◆ description_

std::string Piduino::Option::description_
protectedinherited

Definition at line 168 of file popl.h.

Referenced by Piduino::Option::description().

◆ long_name_

std::string Piduino::Option::long_name_
protectedinherited

Definition at line 167 of file popl.h.

Referenced by Piduino::Option::long_name(), and Piduino::Option::name().

◆ short_name_

std::string Piduino::Option::short_name_
protectedinherited

Definition at line 166 of file popl.h.

Referenced by Piduino::Option::name(), and Piduino::Option::short_name().

◆ values_

template<class T >
std::vector<T> Piduino::Value< T >::values_
protectedinherited

Definition at line 237 of file popl.h.