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

template for map-based options. More...

#include <Options.h>

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

Public Member Functions

 map (char aShortName, const std::string &aLongName, const std::string &aExplanation, std::initializer_list< typename Container::value_type > aDefault={})
 
 map (const map &)=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...
 
template<typename C = Container>
std::enable_if< std::is_same< std::map< typename std::remove_const< typename Container::value_type::first_type >::type, typename Container::value_type::second_type >, C >::value, typename C::iterator >::type insertOrUpdate (typename C::value_type aPair)
 
template<typename C = Container>
std::enable_if< !std::is_same< std::map< typename std::remove_const< typename Container::value_type::first_type >::type, typename Container::value_type::second_type >, C >::value, typename Container::iterator >::type insertOrUpdate (typename C::value_type aPair)
 
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
 
std::add_rvalue_reference< std::add_const< Container > >::type fGetValue () const
 
- Public Member Functions inherited from options::internal::baseForMap< T >
 baseForMap (char aShortName, std::string aLongName, std::string aExplanation, short aNargs)
 
void fAddSource (const T *aValueLocation, const internal::sourceItem &aSource)
 
const internal::sourceItem fGetSource (const T *aValueLocation) const
 
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::baseForMap< T >
std::map< const T *, const 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::map<std::string, T>>
class options::map< T, Container >

template for map-based options.

The map key is always a std::string but the mapped value is arbitrary. the container is by defalt a std::map. It is assumed that the container always contains std::pairs of a std::string as first and the value type T as second, e.g. a std::list<std::pair<std::string,int>> which, in contrast to the map would preserve the order in which the items were specified.

Definition at line 671 of file Options.h.

Constructor & Destructor Documentation

◆ map() [1/2]

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

Definition at line 673 of file Options.h.

674  {}) :
675  internal::baseForMap<T>(aShortName, aLongName, aExplanation, 1) {
676  for (const auto& defaultValue : aDefault) {
677  this->insert(this->end(), defaultValue);
678  }
679  }

◆ map() [2/2]

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

Member Function Documentation

◆ fCheckRange()

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

Implements options::base.

Definition at line 751 of file Options.h.

751  {
752  for (const auto& pair : *this) {
753  this->fCheckValueForRange(pair.second);
754  }
755  };

◆ fGetValue()

template<typename T , typename Container = std::map<std::string, T>>
std::add_rvalue_reference<std::add_const<Container> >::type options::map< T, Container >::fGetValue ( ) const
inline

Definition at line 757 of file Options.h.

757  {
758  return *static_cast<typename std::add_pointer<std::add_const<Container>>::type>(this);
759  }

◆ fSetMe()

template<typename T , typename Container = std::map<std::string, T>>
void options::map< 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 726 of file Options.h.

726  {
727  std::string name;
728  std::getline(aStream, name, parser::fGetInstance()->fGetSecondaryAssignment());
729  if (aStream.eof()) { // not found, complain!
730  throw internal::optionError(this, internal::conCat(" a '", parser::fGetInstance()->fGetSecondaryAssignment(), "' separator is required, none given"));
731  }
732  T value;
733  using escapedIO::operator>>;
734  aStream >> std::setbase(0) >> value;
735  if (aStream.fail()) {
736  std::string arg;
737  aStream.clear();
738  aStream >> arg;
739  throw internal::conversionError(this, arg, typeid(value));
740  }
741  typename std::remove_const<typename Container::value_type::first_type>::type key;
742  std::istringstream conversionStream(name);
743  conversionStream >> key;
744  if (conversionStream.fail()) {
745  throw internal::conversionError(this, name, typeid(key));
746  }
747  auto result = (*this).insertOrUpdate(std::make_pair(key, value));
748  this->fAddSource(&(result->second), aSource);
749  };

◆ fWriteCfgLines()

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

Reimplemented from options::base.

Definition at line 681 of file Options.h.

681  {
682  if (this->empty()) {
683  aStream << aPrefix << this->lLongName << "=key" << parser::fGetInstance()->fGetSecondaryAssignment() << "value\n";
684  }
685  for (const auto& it : *this) {
686  auto source = this->fGetSource(&(it.second));
687  aStream << (source.fIsUnset() ? aPrefix : "") << this->lLongName << "=" << it.first << parser::fGetInstance()->fGetSecondaryAssignment();
688  {
689  using escapedIO::operator<<;
690  aStream << it.second << "\n";
691  }
692  if (!source.fIsUnset()) {
693  aStream << "# set from " << source << "\n";
694  }
695  }
696  }

◆ fWriteValue()

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

write textual representation of value to a std::ostream

Implements options::base.

Definition at line 698 of file Options.h.

698  {
699  using escapedIO::operator<<;
700  if (this->empty()) {
701  aStream << "\"\"";
702  } else {
703  for (const auto& it : *this) {
704  aStream << it.first << parser::fGetInstance()->fGetSecondaryAssignment() << it.second << " ";
705  }
706  }
707  }

◆ insertOrUpdate() [1/2]

template<typename T , typename Container = std::map<std::string, T>>
template<typename C = Container>
std::enable_if<std::is_same<std::map<typename std::remove_const<typename Container::value_type::first_type>::type, typename Container::value_type::second_type>, C>::value, typename C::iterator>::type options::map< T, Container >::insertOrUpdate ( typename C::value_type  aPair)
inline

Definition at line 713 of file Options.h.

713  {
714  (*this)[aPair.first] = aPair.second;
715  return this->find(aPair.first);
716  }

◆ insertOrUpdate() [2/2]

template<typename T , typename Container = std::map<std::string, T>>
template<typename C = Container>
std::enable_if< !std::is_same<std::map<typename std::remove_const<typename Container::value_type::first_type>::type, typename Container::value_type::second_type>, C>::value, typename Container::iterator >::type options::map< T, Container >::insertOrUpdate ( typename C::value_type  aPair)
inline

Definition at line 722 of file Options.h.

722  {
723  return this->insert(this->end(), aPair);
724  }

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::parser::fGetSecondaryAssignment
char fGetSecondaryAssignment() const
Definition: Options.h:403
options::internal::baseForMap::fGetSource
const internal::sourceItem fGetSource(const T *aValueLocation) const
Definition: Options.h:642
options::internal::conCat
std::string conCat(const Args &... args)
Definition: Options.h:338
options::parser::fGetInstance
static parser * fGetInstance()
get the only allwed instance of the option parser.
Definition: Options.cpp:144
options::internal::baseForMap::fAddSource
void fAddSource(const T *aValueLocation, const internal::sourceItem &aSource)
Definition: Options.h:639