Static Value-Flow Analysis
Public Types | Public Member Functions | Private Attributes | List of all members
OptionMap< T > Class Template Reference

#include <CommandLine.h>

Inheritance diagram for OptionMap< T >:
OptionBase

Public Types

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

Public Member Functions

 OptionMap (std::string name, std::string description, T init, OptionPossibilities possibilities)
 
virtual bool canSet (void) const override
 Can this option be set? More...
 
virtual bool parseAndSetValue (const std::string s) override
 From a given string, set the value of this option. More...
 
operator() (void) const
 

Private Attributes

bool isExplicitlySet
 
value
 
OptionPossibilities possibilities
 

Additional Inherited Members

- Static Public Member Functions inherited from OptionBase
static std::vector< std::stringparseOptions (int argc, char *argv[], std::string description, std::string callFormat)
 
- Protected Types inherited from OptionBase
typedef std::pair< std::string, std::stringPossibilityDescription
 Name/description pairs. More...
 
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
 
virtual bool isMultiple (void) const
 Whether this option is an OptionMultiple. More...
 
- 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. More...
 

Detailed Description

template<typename T>
class OptionMap< T >

Option allowing a limited range of values, probably corresponding to an enum. Opt() gives the value.

Definition at line 409 of file CommandLine.h.

Member Typedef Documentation

◆ OptionPossibilities

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

Definition at line 412 of file CommandLine.h.

Constructor & Destructor Documentation

◆ OptionMap()

template<typename T >
OptionMap< T >::OptionMap ( std::string  name,
std::string  description,
init,
OptionPossibilities  possibilities 
)
inline

Definition at line 414 of file CommandLine.h.

417  {
418  assert(!name.empty() && "OptionMap: empty option name given");
419  }
static PossibilityDescriptions extractPossibilityDescriptions(const std::vector< OptionPossibility< T >> possibilities)
Definition: CommandLine.h:294
std::string name
Definition: CommandLine.h:316
std::string description
Definition: CommandLine.h:317
OptionBase(std::string name, std::string description)
Definition: CommandLine.h:33
OptionPossibilities possibilities
Definition: CommandLine.h:451
bool isExplicitlySet
Definition: CommandLine.h:449

Member Function Documentation

◆ canSet()

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

Can this option be set?

Implements OptionBase.

Definition at line 421 of file CommandLine.h.

422  {
423  return !isExplicitlySet;
424  }

◆ operator()()

template<typename T >
T OptionMap< T >::operator() ( void  ) const
inline

Definition at line 443 of file CommandLine.h.

444  {
445  return value;
446  }

◆ parseAndSetValue()

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

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

Implements OptionBase.

Definition at line 426 of file CommandLine.h.

427  {
428  for (const OptionPossibility<T> &op : possibilities)
429  {
430  // Check if the given string is a valid one.
431  if (s == std::get<1>(op))
432  {
433  // What that string maps to.
434  value = std::get<0>(op);
435  isExplicitlySet = true;
436  break;
437  }
438  }
439 
440  return isExplicitlySet;
441  }

Member Data Documentation

◆ isExplicitlySet

template<typename T >
bool OptionMap< T >::isExplicitlySet
private

Definition at line 449 of file CommandLine.h.

◆ possibilities

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

Definition at line 451 of file CommandLine.h.

◆ value

template<typename T >
T OptionMap< T >::value
private

Definition at line 450 of file CommandLine.h.


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