ewmscp  ..
Public Types | Public Member Functions | List of all members
options::single< T > Class Template Reference

generic option class with any type that can be used with std::istream and std::ostream More...

#include <Options.h>

Inheritance diagram for options::single< T >:
[legend]
Collaboration diagram for options::single< T >:
[legend]

Public Types

typedef std::conditional< std::is_fundamental< T >::value||std::is_same< T, const char * >::value, fundamental_wrapper< T >, T >::type deriveFromType
 
- Public Types inherited from options::internal::typed_base< T >
typedef T valueType
 
typedef std::conditional< std::is_same< T, const char * >::value||false, std::string, T >::type rangeValueType
 
typedef std::conditional< false, std::string, T >::type compareValueType
 

Public Member Functions

 single (char aShortName, const std::string &aLongName, const std::string &aExplanation, T aDefault, const std::vector< T > &aRange={})
 construct an object of single<T> More...
 
 single (char aShortName, const std::string &aLongName, const std::string &aExplanation)
 
 single (const single &)=delete
 
operator= (const T &aValue)
 
void fAddDefaultFromStream (std::istream &aStream) override
 special for use in the shellScriptOptionParser More...
 
void fWriteValue (std::ostream &aStream) const override
 write textual representation of value to a std::ostream More...
 
void fCheckRange () const override
 
void fSetMe (std::istream &aStream, const internal::sourceItem &aSource) override
 function to set the value from a string, remembering the source More...
 
const T & fGetValue () const
 
- Public Member Functions inherited from options::internal::typed_base< T >
 typed_base (Types ... args)
 
virtual void fAddToRange (rangeValueType aValue)
 add a value to the range of allowed values More...
 
std::enable_if<(!std::is_same< rangeValueType, std::string >::value) &&std::is_same< TT, std::string >::value, void >::type fAddToRange (const TT &aString)
 
void fAddToRange (InputIt aBegin, InputIt aEnd)
 add values from the iterator range [aBegin,aEnd) to the range of allowed values More...
 
void fAddToRange (const std::vector< TT > &aRange)
 add values from a vector (may be given as initializer list) to the range of allowed values More...
 
void fAddToRangeFromStream (std::istream &aStream) override
 
void fWriteRange (std::ostream &aStream) const override
 
virtual void fCheckValueForRange (const compareValueType &aValue) const
 
- Public Member Functions inherited from options::base
 base (char aShortName, const std::string &aLongName, const std::string &aExplanation, short aNargs)
 construct an object of type base More...
 
virtual ~base ()
 
virtual void fRequire (const base *aOtherOption)
 require aOtherOption when this option is set More...
 
virtual void fRequire (std::vector< const base * > aOtherOptions)
 add vector of other options, particlularly nice for use with initializer list More...
 
template<typename InputIt >
void fRequire (InputIt aBegin, InputIt aEnd)
 add all options from the pair of iterators [aBegin,aEnd) to the list of required options More...
 
virtual void fForbid (const base *aOtherOption)
 forbid aOtherOption when this option is set More...
 
virtual void fForbid (std::vector< const base * > aOtherOptions)
 add vector of other options, particlularly nice for use with initializer list More...
 
template<typename InputIt >
void fForbid (InputIt aBegin, InputIt aEnd)
 add all options from the pair of iterators [aBegin,aEnd) to the list of forbidden options More...
 
virtual bool fIsSet () const
 check if this option was set, regardless of from command line or config file More...
 
virtual bool fIsContainer () const
 
const std::string & fGetLongName () const
 returns long name of option, usually only for internal use. More...
 

Additional Inherited Members

- Protected Member Functions inherited from options::base
virtual void fSetMeNoarg (const internal::sourceItem &)
 
virtual void fSetSource (const internal::sourceItem &aSource)
 remember the source that provided the value, e.g. commandline or a config file More...
 
virtual void fWriteCfgLines (std::ostream &aStream, const char *aPrefix) const
 
void fSetPreserveWorthyStuff (std::vector< std::string > *aStuff)
 
void fHide ()
 hide option, will be respected by help More...
 
bool fIsHidden () const
 
void fDisable ()
 disable option by removing it from the maps More...
 
- Static Protected Member Functions inherited from options::base
static std::map< std::string, base * > & fGetOptionMap ()
 
static std::map< char, base * > & fGetShortOptionMap ()
 
- Protected Attributes inherited from options::internal::typed_base< T >
std::multiset< rangeValueTypelRange
 
- Protected Attributes inherited from options::base
char lShortName
 
const std::string lLongName
 
const std::string lExplanation
 
internal::sourceItem lSource
 
short lNargs
 
bool lHidden
 
std::vector< std::string > * lPreserveWorthyStuff
 
std::vector< const base * > lRequiredOptions
 
std::vector< const base * > lForbiddenOptions
 

Detailed Description

template<typename T>
class options::single< T >

generic option class with any type that can be used with std::istream and std::ostream

It is called 'single' because it's meant for single values as opposed to containers as it may contain strings (via specialisations) it's not limited to scalar tyes.

Definition at line 533 of file Options.h.

Member Typedef Documentation

◆ deriveFromType

template<typename T >
typedef std::conditional< std::is_fundamental<T>::value || std::is_same<T, const char*>::value, fundamental_wrapper<T>, T >::type options::single< T >::deriveFromType

Definition at line 541 of file Options.h.

Constructor & Destructor Documentation

◆ single() [1/3]

template<typename T >
options::single< T >::single ( char  aShortName,
const std::string &  aLongName,
const std::string &  aExplanation,
aDefault,
const std::vector< T > &  aRange = {} 
)
inline

construct an object of single<T>

The newly created object is inserted into the maps sorted by long name and by short name, (short name only if it is not '\0') If a clash wopuld occur, i.e. either long or short name is already taken an exception is thrown.

Parameters
[in]aShortNameshort option without the -, use '\0' to have only a long form
[in]aLongNamelong option without the –, must always be given
[in]aExplanationexplanation for help output
[in]aNargsnumber of arguments/parameters. May be 0 ot 1. This generic case always demands one parameter for the option!
[in]aDefaultdefault value that the option has if not set otherwise
[in]aRangerange of allowes values, can be given as initializer list. If only two values are given then [first,last] is the allowd interval.

Definition at line 546 of file Options.h.

546  {}) :
547  deriveFromType(aDefault),
548  internal::typed_base<T>(aShortName, aLongName, aExplanation, 1) {
549  if (!aRange.empty()) {
550  this->fAddToRange(aRange);
551  }
552  };

◆ single() [2/3]

template<typename T >
options::single< T >::single ( char  aShortName,
const std::string &  aLongName,
const std::string &  aExplanation 
)
inline

Definition at line 553 of file Options.h.

553  :
554  internal::typed_base<T>(aShortName, aLongName, aExplanation, 1) {
555  };

◆ single() [3/3]

template<typename T >
options::single< T >::single ( const single< T > &  )
delete

Member Function Documentation

◆ fAddDefaultFromStream()

template<typename T >
void options::single< T >::fAddDefaultFromStream ( std::istream &  aStream)
inlineoverridevirtual

special for use in the shellScriptOptionParser

read a value from aStram and set that as default

Implements options::base.

Definition at line 564 of file Options.h.

564  {
565  using escapedIO::operator>>;
566  aStream >> std::setbase(0) >> *this;
567  }

◆ fCheckRange()

template<typename T >
void options::single< T >::fCheckRange ( ) const
inlineoverridevirtual

Implements options::base.

Definition at line 573 of file Options.h.

573  {
574  this->fCheckValueForRange(*this);
575  }

◆ fGetValue()

template<typename T >
const T& options::single< T >::fGetValue ( ) const
inline

Definition at line 589 of file Options.h.

589  {
590  return *this;
591  }

Referenced by copyRequest::base::hashCalculator::hashCalculator(), and main().

Here is the caller graph for this function:

◆ fSetMe()

template<typename T >
void options::single< T >::fSetMe ( std::istream &  aStream,
const internal::sourceItem aSource 
)
inlineoverridevirtual

function to set the value from a string, remembering the source

Implements options::base.

Reimplemented in options::withAction< options::single< std::string > >.

Definition at line 578 of file Options.h.

578  {
579  using escapedIO::operator>>;
580  aStream >> std::setbase(0) >> std::noskipws >> *this;
581  if (aStream.fail()) {
582  std::string arg;
583  aStream.clear();
584  aStream >> arg;
585  throw internal::conversionError(this, arg, typeid(T));
586  }
587  this->fSetSource(aSource);
588  }

Referenced by options::internal::OptionReadCfgFile< mayBeMissing >::fSetMe().

Here is the caller graph for this function:

◆ fWriteValue()

template<typename T >
void options::single< T >::fWriteValue ( std::ostream &  aStream) const
inlineoverridevirtual

write textual representation of value to a std::ostream

Implements options::base.

Definition at line 569 of file Options.h.

569  {
570  using escapedIO::operator<<;
571  aStream << *this;
572  }

Referenced by main().

Here is the caller graph for this function:

◆ operator=()

template<typename T >
T options::single< T >::operator= ( const T &  aValue)
inline

Definition at line 558 of file Options.h.

558  {
559  T& thisAsReference(*this);
560  return thisAsReference = aValue;
561  }

The documentation for this class was generated from the following file:
options::internal::typed_base< T >::fAddToRange
virtual void fAddToRange(rangeValueType aValue)
add a value to the range of allowed values
Definition: Options.h:458
options::internal::typed_base< T >::fCheckValueForRange
virtual void fCheckValueForRange(const compareValueType &aValue) const
Definition: Options.h:506
options::single::deriveFromType
std::conditional< std::is_fundamental< T >::value||std::is_same< T, const char * >::value, fundamental_wrapper< T >, T >::type deriveFromType
Definition: Options.h:541
options::base::fSetSource
virtual void fSetSource(const internal::sourceItem &aSource)
remember the source that provided the value, e.g. commandline or a config file
Definition: Options.cpp:561