ewmscp  ..
Public Member Functions | List of all members
options::container< T, Container > Class Template Reference

template for container-based options. More...

#include <Options.h>

Inheritance diagram for options::container< T, Container >:
[legend]
Collaboration diagram for options::container< T, Container >:
[legend]

Public Member Functions

 container (char aShortName, const std::string &aLongName, const std::string &aExplanation, std::initializer_list< typename Container::value_type > aDefault={})
 
 container (const container &)=delete
 
void fWriteCfgLines (std::ostream &aStream, const char *aPrefix) const override
 
void fWriteValue (std::ostream &aStream) const override
 write textual representation of value to a std::ostream More...
 
void fSetMe (std::istream &aStream, const internal::sourceItem &aSource) override
 function to set the value from a string, remembering the source More...
 
void fCheckRange () const override
 
- Public Member Functions inherited from options::internal::baseForContainer< T >
 baseForContainer (char aShortName, std::string aLongName, std::string aExplanation, short aNargs)
 
bool fIsSet () const override
 check if this option was set, regardless of from command line or config file More...
 
bool fIsContainer () const override
 
void fAddDefaultFromStream (std::istream &aStream) override
 special for use in the shellScriptOptionParser More...
 
- 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...
 
const std::string & fGetLongName () const
 returns long name of option, usually only for internal use. More...
 

Additional Inherited Members

- 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
 
- 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...
 
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::baseForContainer< T >
std::vector< internal::sourceItemlSources
 
- 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, typename Container = std::vector<T>>
class options::container< T, Container >

template for container-based options.

the container is by defalt a std::vector. If a non-vector container is used it needs to have a push_back.

Definition at line 789 of file Options.h.

Constructor & Destructor Documentation

◆ container() [1/2]

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

Definition at line 791 of file Options.h.

792  {}) :
793  internal::baseForContainer<T>(aShortName, aLongName, aExplanation, 1) {
794  for (const auto& defaultValue : aDefault) {
795  this->push_back(defaultValue);
796  }
797  }

◆ container() [2/2]

template<typename T , typename Container = std::vector<T>>
options::container< T, Container >::container ( const container< T, Container > &  )
delete

Member Function Documentation

◆ fCheckRange()

template<typename T , typename Container = std::vector<T>>
void options::container< T, Container >::fCheckRange ( ) const
inlineoverridevirtual

Implements options::base.

Definition at line 846 of file Options.h.

846  {
847  for (const auto& value : *this) {
848  this->fCheckValueForRange(value);
849  }
850  };

Referenced by options::withAction< options::single< bool > >::fSetMe(), and options::withAction< options::single< bool > >::fSetMeNoarg().

Here is the caller graph for this function:

◆ fSetMe()

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

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

Implements options::base.

Definition at line 829 of file Options.h.

829  {
830  T value;
831  aStream >> std::setbase(0);
832  {
833  using namespace escapedIO;
834  aStream >> value;
835  }
836  if (aStream.fail()) {
837  std::string arg;
838  aStream.clear();
839  aStream >> arg;
840  throw internal::conversionError(this, arg, typeid(value));
841  }
842  this->push_back(value);
843  this->lSources.push_back(aSource);
844  }

◆ fWriteCfgLines()

template<typename T , typename Container = std::vector<T>>
void options::container< T, Container >::fWriteCfgLines ( std::ostream &  aStream,
const char *  aPrefix 
) const
inlineoverridevirtual

Reimplemented from options::base.

Definition at line 799 of file Options.h.

799  {
800  if (this->empty()) {
801  aStream << aPrefix << this->lLongName << "=value\n";
802  }
803  auto it2 = this->lSources.begin();
804  for (auto it = this->begin(); it != this->end(); ++it, ++it2) {
805  aStream << (it2->fIsUnset() ? aPrefix : "") << this->lLongName << "=";
806  {
807  using escapedIO::operator<<;
808  aStream << *it << "\n";
809  }
810  if (!it2->fIsUnset()) {
811  aStream << "# set from " << *it2 << "\n";
812  }
813  }
814  }

◆ fWriteValue()

template<typename T , typename Container = std::vector<T>>
void options::container< T, Container >::fWriteValue ( std::ostream &  aStream) const
inlineoverridevirtual

write textual representation of value to a std::ostream

Implements options::base.

Definition at line 817 of file Options.h.

817  {
818  if (this->empty()) {
819  aStream << "\"\"";
820  } else {
821  aStream << "\"";
822  for (auto it = this->begin(); it != this->end(); ++it) {
823  using escapedIO::operator<<;
824  aStream << *it << " ";
825  }
826  aStream << "\"";
827  }
828  }

The documentation for this class was generated from the following file:
options::internal::typed_base< T >::fCheckValueForRange
virtual void fCheckValueForRange(const compareValueType &aValue) const
Definition: Options.h:506
options::base::lLongName
const std::string lLongName
Definition: Options.h:206
options::internal::baseForContainer::lSources
std::vector< internal::sourceItem > lSources
Definition: Options.h:768