Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
OptionMultiple< T > Class Template Reference

#include <CommandLine.h>

Inheritance diagram for OptionMultiple< T >:
OptionBase

Public Types

typedef std::vector< OptionPossibility< T > > OptionPossibilities
 

Public Member Functions

 OptionMultiple (std::string description, OptionPossibilities possibilities)
 
virtual bool canSet (void) const override
 Can this option be set?
 
virtual bool parseAndSetValue (const std::string s) override
 From a given string, set the value of this option.
 
virtual bool isMultiple (void) const override
 Whether this option is an OptionMultiple.
 
bool nothingSet (void) const
 If the bitset is empty.
 
bool operator() (const T v) const
 Returns whether the value v had been set as an option.
 

Private Attributes

std::unordered_map< T, bool > optionValues
 
OptionPossibilities possibilities
 

Additional Inherited Members

- Static Public Member Functions inherited from OptionBase
static std::vector< std::string > parseOptions (int argc, char *argv[], std::string description, std::string callFormat)
 
- Protected Types inherited from OptionBase
typedef std::pair< std::string, std::string > PossibilityDescription
 Name/description pairs.
 
typedef std::vector< std::pair< std::string, std::string > > PossibilityDescriptions
 
template<typename T >
using OptionPossibility = std::tuple< T, std::string, std::string >
 
- Protected Member Functions inherited from OptionBase
 OptionBase (std::string name, std::string description)
 
 OptionBase (std::string name, std::string description, PossibilityDescriptions possibilityDescriptions)
 
virtual bool isBool (void) const
 
- Static Protected Member Functions inherited from OptionBase
template<typename T >
static PossibilityDescriptions extractPossibilityDescriptions (const std::vector< OptionPossibility< T > > possibilities)
 
static std::map< std::string, OptionBase * > & getOptionsMap (void)
 
- Protected Attributes inherited from OptionBase
std::string name
 
std::string description
 
PossibilityDescriptions possibilityDescriptions
 For when we have possibilities like in an OptionMap.
 

Detailed Description

template<typename T>
class OptionMultiple< T >

Options which form a kind of bit set. There are multiple names and n of them can be set. Opt(v) tests whether v had been set, aborting if v is invalid.

Definition at line 457 of file CommandLine.h.

Member Typedef Documentation

◆ OptionPossibilities

template<typename T >
typedef std::vector<OptionPossibility<T> > OptionMultiple< T >::OptionPossibilities

Definition at line 460 of file CommandLine.h.

Constructor & Destructor Documentation

◆ OptionMultiple()

template<typename T >
OptionMultiple< T >::OptionMultiple ( std::string  description,
OptionPossibilities  possibilities 
)
inline

Definition at line 462 of file CommandLine.h.

464 {
465 for (const OptionPossibility<T> &op : possibilities)
466 {
467 optionValues[std::get<0>(op)] = false;
468 }
469
470 for (const OptionPossibility<T> &op : possibilities)
471 {
472 std::string possibilityName = std::get<1>(op);
473 getOptionsMap()[possibilityName] = this;
474 }
475 }
static PossibilityDescriptions extractPossibilityDescriptions(const std::vector< OptionPossibility< T > > possibilities)
std::string description
static std::map< std::string, OptionBase * > & getOptionsMap(void)
std::unordered_map< T, bool > optionValues
OptionPossibilities possibilities

Member Function Documentation

◆ canSet()

template<typename T >
virtual bool OptionMultiple< T >::canSet ( void  ) const
inlineoverridevirtual

Can this option be set?

Implements OptionBase.

Definition at line 477 of file CommandLine.h.

478 {
479 return true;
480 }

◆ isMultiple()

template<typename T >
virtual bool OptionMultiple< T >::isMultiple ( void  ) const
inlineoverridevirtual

Whether this option is an OptionMultiple.

Reimplemented from OptionBase.

Definition at line 497 of file CommandLine.h.

498 {
499 return true;
500 }

◆ nothingSet()

template<typename T >
bool OptionMultiple< T >::nothingSet ( void  ) const
inline

If the bitset is empty.

Definition at line 503 of file CommandLine.h.

504 {
505 for (const std::pair<T, bool> tb : optionValues)
506 {
507 if (tb.second) return false;
508 }
509
510 return true;
511 }

◆ operator()()

template<typename T >
bool OptionMultiple< T >::operator() ( const T  v) const
inline

Returns whether the value v had been set as an option.

Definition at line 514 of file CommandLine.h.

515 {
516 typename std::unordered_map<T, bool>::const_iterator ovIt = optionValues.find(v);
517 // TODO: disabled as we check for "invalid" values in some places.
518 // assert(ovIt != optionValues.end() && "OptionMultiple: bad value checked");
519 if (ovIt == optionValues.end()) return false;
520 return ovIt->second;
521 }

◆ parseAndSetValue()

template<typename T >
virtual bool OptionMultiple< T >::parseAndSetValue ( const std::string  value)
inlineoverridevirtual

From a given string, set the value of this option.

Implements OptionBase.

Definition at line 482 of file CommandLine.h.

483 {
484 // Like in OptionMap basically, except we can have many values.
485 for (const OptionPossibility<T> &op : possibilities)
486 {
487 if (s == std::get<1>(op))
488 {
489 optionValues[std::get<0>(op)] = true;
490 return true;
491 }
492 }
493
494 return false;
495 }

Member Data Documentation

◆ optionValues

template<typename T >
std::unordered_map<T, bool> OptionMultiple< T >::optionValues
private

Is the option set? Use a map rather than a set because it's now easier in one DS to determine whether something is 1) valid, and 2) set.

Definition at line 526 of file CommandLine.h.

◆ possibilities

template<typename T >
OptionPossibilities OptionMultiple< T >::possibilities
private

Definition at line 527 of file CommandLine.h.


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