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

Value option with optional default value. More...

#include <popl.h>

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

Public Member Functions

 Value (const std::string &short_name, const std::string &long_name, const std::string &description)
 Value implementation /////////////////////////////////.
 
 Value (const std::string &short_name, const std::string &long_name, const std::string &description, const T &default_val, T *assign_to=nullptr)
 
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
 
Argument argument_type () 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.
 
void parse (OptionName what_name, const char *value)
 

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::Value< T >

Value option with optional default value.

Value option with optional default value If set, it requires an argument

Definition at line 181 of file popl.h.

Constructor & Destructor Documentation

◆ Value() [1/2]

template<class T >
Piduino::Value< T >::Value ( const std::string &  short_name,
const std::string &  long_name,
const std::string &  description 
)
inline

Value implementation /////////////////////////////////.

Construct an Value Option

Parameters
short_namethe option's short name. Must be empty or one character.
long_namethe option's long name. Can be empty.
descriptionthe Option's description that will be shown in the help message

Definition at line 552 of file popl.h.

◆ Value() [2/2]

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

Construct an Value Option

Parameters
short_namethe option's short name. Must be empty or one character.
long_namethe option's long name. Can be empty.
descriptionthe Option's description that will be shown in the help message
default_valthe Option's default value
assign_topointer to a variable to assign the parsed command line value to

Definition at line 559 of file popl.h.

References Piduino::Value< T >::assign_to(), Piduino::Value< T >::assign_to_, and Piduino::Value< T >::set_default().

Here is the call graph for this function:

Member Function Documentation

◆ add_value()

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

Definition at line 720 of file popl.h.

◆ argument_type()

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

Get the Option's argument type

Returns
argument type (no, required, optional)

Implements Piduino::Option.

Definition at line 657 of file popl.h.

References Piduino::required.

◆ assign_to()

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

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 ( )
inlineoverrideprotectedvirtual

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
inlineoverridevirtual

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
inline

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
inlineoverridevirtual

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
inline

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
inlineoverridevirtual

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() [1/2]

void Piduino::Value< std::string >::parse ( OptionName  what_name,
const char *  value 
)
inlineprotectedvirtual

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 663 of file popl.h.

References Piduino::invalid_option::missing_argument.

◆ parse() [2/2]

template<class T >
void Piduino::Value< 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 673 of file popl.h.

References Piduino::invalid_option::invalid_argument, Piduino::invalid_option::missing_argument, and Piduino::invalid_option::too_many_arguments.

Referenced by Piduino::Implicit< T >::parse().

◆ 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)
inline

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)
inline

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 ( )
inlineprotectedvirtual

Definition at line 710 of file popl.h.

◆ value()

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

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_
protected

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_
protected

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_
protected

Definition at line 237 of file popl.h.