ewmscp  ..
Public Types | Public Member Functions | Protected Attributes | List of all members
options::internal::typed_base< T, forceRangeValueTypeString > Class Template Reference

#include <Options.h>

Inheritance diagram for options::internal::typed_base< T, forceRangeValueTypeString >:
[legend]
Collaboration diagram for options::internal::typed_base< T, forceRangeValueTypeString >:
[legend]

Public Types

typedef T valueType
 
typedef std::conditional< std::is_same< T, const char * >::value||forceRangeValueTypeString, std::string, T >::type rangeValueType
 
typedef std::conditional< forceRangeValueTypeString, std::string, T >::type compareValueType
 

Public Member Functions

template<class ... Types>
 typed_base (Types ... args)
 
virtual void fAddToRange (rangeValueType aValue)
 add a value to the range of allowed values More...
 
template<typename TT = std::string>
std::enable_if<(!std::is_same< rangeValueType, std::string >::value) &&std::is_same< TT, std::string >::value, void >::type fAddToRange (const TT &aString)
 
template<typename InputIt >
void fAddToRange (InputIt aBegin, InputIt aEnd)
 add values from the iterator range [aBegin,aEnd) to the range of allowed values More...
 
template<typename TT >
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 fAddDefaultFromStream (std::istream &aStream)=0
 special for use in the shellScriptOptionParser More...
 
virtual void fWriteValue (std::ostream &aStream) const =0
 write textual representation of value to a std::ostream More...
 
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...
 

Protected Attributes

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
 

Additional Inherited Members

- Protected Member Functions inherited from options::base
virtual void fSetMe (std::istream &aStream, const internal::sourceItem &aSource)=0
 function to set the value from a string, remembering the source More...
 
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
 
virtual void fCheckRange () const =0
 
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 ()
 

Detailed Description

template<typename T, bool forceRangeValueTypeString = false>
class options::internal::typed_base< T, forceRangeValueTypeString >

Definition at line 445 of file Options.h.

Member Typedef Documentation

◆ compareValueType

template<typename T , bool forceRangeValueTypeString = false>
typedef std::conditional<forceRangeValueTypeString, std::string, T>::type options::internal::typed_base< T, forceRangeValueTypeString >::compareValueType

Definition at line 449 of file Options.h.

◆ rangeValueType

template<typename T , bool forceRangeValueTypeString = false>
typedef std::conditional< std::is_same<T, const char *>::value || forceRangeValueTypeString, std::string, T >::type options::internal::typed_base< T, forceRangeValueTypeString >::rangeValueType

Definition at line 448 of file Options.h.

◆ valueType

template<typename T , bool forceRangeValueTypeString = false>
typedef T options::internal::typed_base< T, forceRangeValueTypeString >::valueType

Definition at line 447 of file Options.h.

Constructor & Destructor Documentation

◆ typed_base()

template<typename T , bool forceRangeValueTypeString = false>
template<class ... Types>
options::internal::typed_base< T, forceRangeValueTypeString >::typed_base ( Types ...  args)
inline

Definition at line 454 of file Options.h.

454  :
455  base(args...) {
456  };

Member Function Documentation

◆ fAddToRange() [1/4]

template<typename T , bool forceRangeValueTypeString = false>
template<typename TT >
void options::internal::typed_base< T, forceRangeValueTypeString >::fAddToRange ( const std::vector< TT > &  aRange)
inline

add values from a vector (may be given as initializer list) to the range of allowed values

Definition at line 476 of file Options.h.

476  {
477  fAddToRange(aRange.cbegin(), aRange.cend());
478  }

◆ fAddToRange() [2/4]

template<typename T , bool forceRangeValueTypeString = false>
template<typename TT = std::string>
std::enable_if< (!std::is_same<rangeValueType, std::string>::value) && std::is_same<TT, std::string>::value, void >::type options::internal::typed_base< T, forceRangeValueTypeString >::fAddToRange ( const TT &  aString)
inline

Definition at line 461 of file Options.h.

461  {
462  std::stringstream buf(aString);
463  rangeValueType value;
464  buf >> std::setbase(0);
465  using escapedIO::operator>>;
466  buf >> value;
467  fAddToRange(value);
468  };

◆ fAddToRange() [3/4]

template<typename T , bool forceRangeValueTypeString = false>
template<typename InputIt >
void options::internal::typed_base< T, forceRangeValueTypeString >::fAddToRange ( InputIt  aBegin,
InputIt  aEnd 
)
inline

add values from the iterator range [aBegin,aEnd) to the range of allowed values

Definition at line 470 of file Options.h.

470  {
471  for (auto it = aBegin; it != aEnd; ++it) {
472  fAddToRange(*it);
473  }
474  };

◆ fAddToRange() [4/4]

template<typename T , bool forceRangeValueTypeString = false>
virtual void options::internal::typed_base< T, forceRangeValueTypeString >::fAddToRange ( rangeValueType  aValue)
inlinevirtual

add a value to the range of allowed values

Definition at line 458 of file Options.h.

458  {
459  lRange.emplace(aValue);
460  };

Referenced by escapism::addAllowedNamesToOption(), requestProvider::addAllowedNamesToOption(), maskName::addToRange(), davixCfgEnum< const Davix::RequestProtocol::Protocol >::davixCfgEnum(), options::internal::typed_base< std::chrono::seconds >::fAddToRange(), options::internal::typed_base< std::chrono::seconds >::fAddToRangeFromStream(), and libsshCommon::sshOptions::sshOptions().

Here is the caller graph for this function:

◆ fAddToRangeFromStream()

template<typename T , bool forceRangeValueTypeString = false>
void options::internal::typed_base< T, forceRangeValueTypeString >::fAddToRangeFromStream ( std::istream &  aStream)
inlineoverridevirtual

read a line from aStream and then add as many values as can be read from that line to the list of allowed values

Implements options::base.

Definition at line 480 of file Options.h.

480  {
481  std::string buf;
482  std::getline(aStream, buf);
483  std::stringstream sbuf(buf);
484  while (!sbuf.eof()) {
485  rangeValueType value;
486  using escapedIO::operator>>;
487  sbuf >> std::setbase(0) >> value;
488  fAddToRange(value);
489  }
490  };

◆ fCheckValueForRange()

template<typename T , bool forceRangeValueTypeString = false>
virtual void options::internal::typed_base< T, forceRangeValueTypeString >::fCheckValueForRange ( const compareValueType aValue) const
inlinevirtual

Definition at line 506 of file Options.h.

506  {
507  using escapedIO::operator<<;
508  if (lRange.empty()) {
509  return;
510  } else if (lRange.size() == 2) {
511  if (*(lRange.cbegin()) <= aValue && aValue <= *(lRange.crbegin())) {
512  return;
513  } else {
514  throw typedRangeError<compareValueType>(this, aValue);
515  }
516  } else {
517  for (const auto& it : lRange) {
518  if (it == aValue) {
519  return;
520  }
521  }
522  throw typedRangeError<compareValueType>(this, aValue);
523  }
524  }

◆ fWriteRange()

template<typename T , bool forceRangeValueTypeString = false>
void options::internal::typed_base< T, forceRangeValueTypeString >::fWriteRange ( std::ostream &  aStream) const
inlineoverridevirtual

Reimplemented from options::base.

Definition at line 491 of file Options.h.

491  {
492  using escapedIO::operator<<;
493  if (! lRange.empty()) {
494  aStream << "# allowed range is";
495  if (lRange.size() == 2) {
496  aStream << " [" << *(lRange.cbegin()) << "," << *(lRange.crbegin()) << "]\n";
497  } else {
498  aStream << ":";
499  for (const auto& it : lRange) {
500  aStream << " " << it;
501  }
502  aStream << "\n";
503  }
504  }
505  };

Member Data Documentation

◆ lRange

template<typename T , bool forceRangeValueTypeString = false>
std::multiset<rangeValueType> options::internal::typed_base< T, forceRangeValueTypeString >::lRange
protected

The documentation for this class was generated from the following file:
options::internal::typed_base::fAddToRange
virtual void fAddToRange(rangeValueType aValue)
add a value to the range of allowed values
Definition: Options.h:458
options::internal::typed_base::rangeValueType
std::conditional< std::is_same< T, const char * >::value||forceRangeValueTypeString, std::string, T >::type rangeValueType
Definition: Options.h:448
options::base::base
base(char aShortName, const std::string &aLongName, const std::string &aExplanation, short aNargs)
construct an object of type base
Definition: Options.cpp:529
options::internal::typed_base::lRange
std::multiset< rangeValueType > lRange
Definition: Options.h:451