ewmscp  ..
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
options::base Class Referenceabstract

base class for options More...

#include <Options.h>

Inheritance diagram for options::base:
[legend]
Collaboration diagram for options::base:
[legend]

Public Member Functions

 base (char aShortName, const std::string &aLongName, const std::string &aExplanation, short aNargs)
 construct an object of type base More...
 
virtual ~base ()
 
virtual void fAddToRangeFromStream (std::istream &aStream)=0
 special for use in the shellScriptOptionParser More...
 
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 Member Functions

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
 
virtual void fWriteRange (std::ostream &) 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

static std::map< std::string, base * > & fGetOptionMap ()
 
static std::map< char, base * > & fGetShortOptionMap ()
 

Protected Attributes

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
 

Private Member Functions

virtual void fHandleOption (int argc, const char *argv[], int *i)
 

Friends

class parser
 

Detailed Description

base class for options

Only the templated classes that derive from this base class can contain values. This base class only contains members that are generally usable and do not depend on the type of the option.

Definition at line 193 of file Options.h.

Constructor & Destructor Documentation

◆ base()

options::base::base ( char  aShortName,
const std::string &  aLongName,
const std::string &  aExplanation,
short  aNargs 
)

construct an object of type base

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.

Definition at line 529 of file Options.cpp.

529  :
530  lShortName(aShortName),
531  lLongName(aLongName),
532  lExplanation(aExplanation),
533  lNargs(aNargs) {
534 
535  {
536  auto p = parser::fGetInstance();
537  if (p != nullptr) {
538  if (p->fIsParsingDone()) {
539  throw std::logic_error(internal::conCat(lLongName, " construction after parsing is done"));
540  }
541  }
542  }
543 
544  if (fGetOptionMap().emplace(lLongName, this).second == false) {
545  throw std::logic_error(internal::conCat(lLongName, " already registered"));
546  }
547  if (lShortName != '\0') {
548  if (fGetShortOptionMap().emplace(lShortName, this).second == false) {
549  throw std::logic_error(internal::conCat(lLongName, ": short name '", lShortName, " already registered"));
550  }
551  }
552  lPreserveWorthyStuff = nullptr;
553  }

References options::internal::conCat(), options::parser::fGetInstance(), fGetOptionMap(), fGetShortOptionMap(), lLongName, lPreserveWorthyStuff, and lShortName.

Here is the call graph for this function:

◆ ~base()

options::base::~base ( )
virtual

Definition at line 554 of file Options.cpp.

554  {
555  fGetOptionMap().clear();
556  fGetShortOptionMap().clear();
557  delete lPreserveWorthyStuff;
558  }

References fGetOptionMap(), fGetShortOptionMap(), and lPreserveWorthyStuff.

Here is the call graph for this function:

Member Function Documentation

◆ fAddDefaultFromStream()

virtual void options::base::fAddDefaultFromStream ( std::istream &  aStream)
pure virtual

◆ fAddToRangeFromStream()

virtual void options::base::fAddToRangeFromStream ( std::istream &  aStream)
pure virtual

◆ fCheckRange()

virtual void options::base::fCheckRange ( ) const
protectedpure virtual

Implemented in options::container< T, Container >, options::map< T, Container >, options::single< bool >, options::single< T >, options::single< std::chrono::duration< Rep, Period > >, options::single< std::chrono::system_clock::time_point >, options::ForeignOption, and options::single< std::regex >.

Referenced by fHandleOption().

Here is the caller graph for this function:

◆ fDisable()

void options::base::fDisable ( )
protected

disable option by removing it from the maps

Definition at line 605 of file Options.cpp.

605  {
606  fHide(); // needed to hide forbidden options
607  fGetOptionMap().erase(lLongName);
609  }

References fGetOptionMap(), fGetShortOptionMap(), fHide(), lLongName, and lShortName.

Here is the call graph for this function:

◆ fForbid() [1/3]

void options::base::fForbid ( const base aOtherOption)
virtual

forbid aOtherOption when this option is set

Definition at line 617 of file Options.cpp.

617  {
618  lForbiddenOptions.push_back(aOtherOption);
619  }

References lForbiddenOptions.

Referenced by davixCfgX509::davixCfgX509(), dCapCfgPar< T >::fForbid(), fForbid(), and baseTest::setUpOptions().

Here is the caller graph for this function:

◆ fForbid() [2/3]

template<typename InputIt >
void options::base::fForbid ( InputIt  aBegin,
InputIt  aEnd 
)
inline

add all options from the pair of iterators [aBegin,aEnd) to the list of forbidden options

Definition at line 257 of file Options.h.

257  {
258  for (auto it = aBegin; it != aEnd; ++it) {
259  fForbid(*it);
260  }
261  }

References fForbid().

Here is the call graph for this function:

◆ fForbid() [3/3]

void options::base::fForbid ( std::vector< const base * >  aOtherOptions)
virtual

add vector of other options, particlularly nice for use with initializer list

Definition at line 620 of file Options.cpp.

620  {
621  lForbiddenOptions.insert(lForbiddenOptions.end(), aOtherOptions.cbegin(), aOtherOptions.cend());
622  }

References lForbiddenOptions.

◆ fGetLongName()

const std::string& options::base::fGetLongName ( ) const
inline

returns long name of option, usually only for internal use.

Definition at line 273 of file Options.h.

273  {
274  return lLongName;
275  };

References lLongName.

Referenced by options::parser::fParse(), options::parser::fPrintOptionHelp(), and mapOption< T >::fWriteValue().

Here is the caller graph for this function:

◆ fGetOptionMap()

static std::map<std::string, base*>& options::base::fGetOptionMap ( )
inlinestaticprotected

Definition at line 196 of file Options.h.

196  {
197  static std::map<std::string, base*> gOptions;
198  return gOptions;
199  };

Referenced by base(), options::parser::fCheckConsistency(), fDisable(), options::parser::fHelp(), options::parser::fParse(), options::parser::fReadCfgFile(), options::parser::fWriteCfgFile(), and ~base().

Here is the caller graph for this function:

◆ fGetShortOptionMap()

static std::map<char, base*>& options::base::fGetShortOptionMap ( )
inlinestaticprotected

Definition at line 200 of file Options.h.

200  {
201  static std::map<char, base*> gShortOptions;
202  return gShortOptions;
203  };

Referenced by base(), fDisable(), options::parser::fParse(), and ~base().

Here is the caller graph for this function:

◆ fHandleOption()

void options::base::fHandleOption ( int  argc,
const char *  argv[],
int *  i 
)
privatevirtual

Definition at line 566 of file Options.cpp.

566  {
567  if (*i + lNargs >= argc) {
568  throw internal::optionError(this, internal::conCat(lNargs, " args needed, but only ", argc - *i - 1 , " remain."));
569  }
570  if (lNargs == 0) {
571  fSetMeNoarg(internal::sourceItem(&internal::sourceFile::gCmdLine, *i));
572  } else if (lNargs == 1) {
573  std::stringstream sbuf(argv[*i + 1]);
574  fSetMe(sbuf, internal::sourceItem(&internal::sourceFile::gCmdLine, *i));
575  *i += lNargs;
576  }
577  fCheckRange();
578  }

References options::internal::conCat(), fCheckRange(), fSetMe(), fSetMeNoarg(), options::internal::sourceFile::gCmdLine, and lNargs.

Here is the call graph for this function:

◆ fHide()

void options::base::fHide ( )
protected

hide option, will be respected by help

Definition at line 596 of file Options.cpp.

596  {
597  lHidden = true;
598  }

References lHidden.

Referenced by fDisable().

Here is the caller graph for this function:

◆ fIsContainer()

virtual bool options::base::fIsContainer ( ) const
inlinevirtual

Reimplemented in options::internal::baseForContainer< T >, and options::internal::baseForMap< T >.

Definition at line 267 of file Options.h.

267  {
268  return false;
269  };

Referenced by options::internal::positional_base::positional_base().

Here is the caller graph for this function:

◆ fIsHidden()

bool options::base::fIsHidden ( ) const
protected

Definition at line 600 of file Options.cpp.

600  {
601  return lHidden;
602  }

References lHidden.

Referenced by options::parser::fPrintOptionHelp().

Here is the caller graph for this function:

◆ fIsSet()

virtual bool options::base::fIsSet ( ) const
inlinevirtual

check if this option was set, regardless of from command line or config file

Reimplemented in options::internal::baseForContainer< T >, and options::internal::baseForMap< T >.

Definition at line 263 of file Options.h.

263  {
264  return ! lSource.fIsUnset();
265  };

References options::internal::sourceItem::fIsUnset(), and lSource.

Referenced by dCapCfgTimePar< T >::applySingle(), davixCfgPar< struct timespec * >::applySingle(), davixCfgEnum< const Davix::RequestProtocol::Protocol >::applySingle(), davixCfgX509::applySingle(), followJsonRequestProvider::followStream(), messageQueue::kafka::init(), main(), libsshCommon::openSessions(), cmdLineRequestProvider::prepareMappings(), and followJsonRequestProvider::processJson().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fRequire() [1/3]

void options::base::fRequire ( const base aOtherOption)
virtual

require aOtherOption when this option is set

Definition at line 611 of file Options.cpp.

611  {
612  lRequiredOptions.push_back(aOtherOption);
613  }

References lRequiredOptions.

Referenced by davixCfgX509::davixCfgX509(), fRequire(), and main().

Here is the caller graph for this function:

◆ fRequire() [2/3]

template<typename InputIt >
void options::base::fRequire ( InputIt  aBegin,
InputIt  aEnd 
)
inline

add all options from the pair of iterators [aBegin,aEnd) to the list of required options

Definition at line 247 of file Options.h.

247  {
248  for (auto it = aBegin; it != aEnd; ++it) {
249  fRequire(*it);
250  }
251  }

References fRequire().

Here is the call graph for this function:

◆ fRequire() [3/3]

void options::base::fRequire ( std::vector< const base * >  aOtherOptions)
virtual

add vector of other options, particlularly nice for use with initializer list

Definition at line 614 of file Options.cpp.

614  {
615  lRequiredOptions.insert(lRequiredOptions.end(), aOtherOptions.cbegin(), aOtherOptions.cend());
616  }

References lRequiredOptions.

◆ fSetMe()

virtual void options::base::fSetMe ( std::istream &  aStream,
const internal::sourceItem aSource 
)
protectedpure virtual

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

Implemented in options::internal::OptionReadCfgFile< mayBeMissing >, options::internal::OptionWriteCfgFile, options::withAction< options::single< std::string > >, options::withAction< options::single< bool > >, options::container< T, Container >, options::container< std::string >, options::container< unsigned int >, options::container< T >, options::map< T, Container >, options::map< std::string, pathMapType >, options::map< std::string >, options::map< std::string, std::map< int, std::string > >, options::map< T >, options::single< bool >, options::single< T >, options::single< std::chrono::nanoseconds >, options::single< unsigned long >, options::single< std::chrono::duration< double > >, options::single< double >, options::single< std::string >, options::single< int >, options::single< unsigned int >, options::single< U >, options::single< options::postFixedNumber< size_t > >, options::single< copyRequest::clock_type::duration >, options::single< size_t >, options::single< unsigned >, options::single< std::chrono::seconds >, options::single< std::chrono::duration< Rep, Period > >, options::single< std::chrono::system_clock::time_point >, options::single< std::regex >, options::ForeignOption, and options::internal::OptionHelp.

Referenced by options::internal::baseForMap< std::string >::fAddDefaultFromStream(), options::internal::baseForContainer< unsigned int >::fAddDefaultFromStream(), and fHandleOption().

Here is the caller graph for this function:

◆ fSetMeNoarg()

virtual void options::base::fSetMeNoarg ( const internal::sourceItem )
inlineprotectedvirtual

Reimplemented in options::internal::OptionHelp, options::withAction< options::single< std::string > >, options::withAction< options::single< bool > >, options::single< bool >, and options::ForeignOption.

Definition at line 218 of file Options.h.

218 {};

Referenced by fHandleOption().

Here is the caller graph for this function:

◆ fSetPreserveWorthyStuff()

void options::base::fSetPreserveWorthyStuff ( std::vector< std::string > *  aStuff)
protected

Definition at line 591 of file Options.cpp.

591  {
592  lPreserveWorthyStuff = aStuff;
593  }

References lPreserveWorthyStuff.

◆ fSetSource()

void options::base::fSetSource ( const internal::sourceItem aSource)
protectedvirtual

remember the source that provided the value, e.g. commandline or a config file

Definition at line 561 of file Options.cpp.

561  {
562  lSource = aSource;
563  }

References lSource.

Referenced by options::single< std::regex >::fSetMe(), options::ForeignOption::fSetMe(), options::single< std::chrono::system_clock::time_point >::fSetMe(), options::single< std::chrono::duration< Rep, Period > >::fSetMe(), options::single< std::chrono::seconds >::fSetMe(), options::single< bool >::fSetMe(), options::ForeignOption::fSetMeNoarg(), and options::single< bool >::fSetMeNoarg().

Here is the caller graph for this function:

◆ fWriteCfgLines()

void options::base::fWriteCfgLines ( std::ostream &  aStream,
const char *  aPrefix 
) const
protectedvirtual

Reimplemented in options::container< T, Container >, options::container< std::string >, options::container< unsigned int >, options::container< T >, options::map< T, Container >, options::map< std::string, pathMapType >, options::map< std::string >, options::map< std::string, std::map< int, std::string > >, options::map< T >, options::internal::OptionReadCfgFile< mayBeMissing >, options::internal::supressed< T >, options::internal::supressed< std::string >, and options::internal::supressed< bool >.

Definition at line 580 of file Options.cpp.

580  {
581  aStream << aPrefix << lLongName << "=";
582  auto asOriginalStringKeeper = dynamic_cast<const originalStringKeeper*>(this);
583  if (asOriginalStringKeeper) {
584  asOriginalStringKeeper->fWriteOriginalString(aStream);
585  } else {
586  fWriteValue(aStream);
587  }
588  aStream << "\n";
589  }

References options::originalStringKeeper::fWriteOriginalString(), fWriteValue(), and lLongName.

Referenced by options::internal::supressed< bool >::fWriteCfgLines(), and options::internal::OptionReadCfgFile< mayBeMissing >::fWriteCfgLines().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fWriteRange()

virtual void options::base::fWriteRange ( std::ostream &  ) const
inlineprotectedvirtual

◆ fWriteValue()

virtual void options::base::fWriteValue ( std::ostream &  aStream) const
pure virtual

Friends And Related Function Documentation

◆ parser

friend class parser
friend

Definition at line 194 of file Options.h.

Member Data Documentation

◆ lExplanation

const std::string options::base::lExplanation
protected

Definition at line 207 of file Options.h.

Referenced by options::parser::fPrintOptionHelp().

◆ lForbiddenOptions

std::vector<const base*> options::base::lForbiddenOptions
protected

Definition at line 214 of file Options.h.

Referenced by fForbid(), and options::parser::fPrintOptionHelp().

◆ lHidden

bool options::base::lHidden
protected

Definition at line 210 of file Options.h.

Referenced by fHide(), and fIsHidden().

◆ lLongName

const std::string options::base::lLongName
protected

◆ lNargs

short options::base::lNargs
protected

Definition at line 209 of file Options.h.

Referenced by options::ForeignOption::fAddArgs(), and fHandleOption().

◆ lPreserveWorthyStuff

std::vector<std::string>* options::base::lPreserveWorthyStuff
protected

Definition at line 211 of file Options.h.

Referenced by base(), fSetPreserveWorthyStuff(), and ~base().

◆ lRequiredOptions

std::vector<const base*> options::base::lRequiredOptions
protected

Definition at line 213 of file Options.h.

Referenced by options::parser::fPrintOptionHelp(), and fRequire().

◆ lShortName

char options::base::lShortName
protected

Definition at line 203 of file Options.h.

Referenced by base(), fDisable(), and options::parser::fPrintOptionHelp().

◆ lSource

internal::sourceItem options::base::lSource
protected

Definition at line 208 of file Options.h.

Referenced by fIsSet(), and fSetSource().


The documentation for this class was generated from the following files:
options::base::fSetMeNoarg
virtual void fSetMeNoarg(const internal::sourceItem &)
Definition: Options.h:218
options::base::lLongName
const std::string lLongName
Definition: Options.h:206
options::base::lPreserveWorthyStuff
std::vector< std::string > * lPreserveWorthyStuff
Definition: Options.h:211
options::base::lSource
internal::sourceItem lSource
Definition: Options.h:208
options::base::fForbid
virtual void fForbid(const base *aOtherOption)
forbid aOtherOption when this option is set
Definition: Options.cpp:617
options::base::fHide
void fHide()
hide option, will be respected by help
Definition: Options.cpp:596
options::base::lRequiredOptions
std::vector< const base * > lRequiredOptions
Definition: Options.h:213
options::base::fRequire
virtual void fRequire(const base *aOtherOption)
require aOtherOption when this option is set
Definition: Options.cpp:611
options::base::lExplanation
const std::string lExplanation
Definition: Options.h:207
options::internal::sourceFile::gCmdLine
static const sourceFile gCmdLine
Definition: Options.h:42
options::base::fWriteValue
virtual void fWriteValue(std::ostream &aStream) const =0
write textual representation of value to a std::ostream
options::base::fSetMe
virtual void fSetMe(std::istream &aStream, const internal::sourceItem &aSource)=0
function to set the value from a string, remembering the source
options::base::lShortName
char lShortName
Definition: Options.h:203
options::internal::conCat
std::string conCat(const Args &... args)
Definition: Options.h:338
options::base::fGetOptionMap
static std::map< std::string, base * > & fGetOptionMap()
Definition: Options.h:196
options::parser::fGetInstance
static parser * fGetInstance()
get the only allwed instance of the option parser.
Definition: Options.cpp:144
options::internal::sourceItem::fIsUnset
bool fIsUnset() const
Definition: Options.h:70
options::base::fGetShortOptionMap
static std::map< char, base * > & fGetShortOptionMap()
Definition: Options.h:200
options::base::fCheckRange
virtual void fCheckRange() const =0
options::base::lNargs
short lNargs
Definition: Options.h:209
options::base::lForbiddenOptions
std::vector< const base * > lForbiddenOptions
Definition: Options.h:214
options::base::lHidden
bool lHidden
Definition: Options.h:210