ewmscp  ..
OptionsRegex.h
Go to the documentation of this file.
1 #ifndef __OptionsRegex_H__
2 #define __OptionsRegex_H__
3 
4 #include <regex>
5 #include <Options.h>
6 
7 namespace options {
8  template <> class single<std::regex>:
9  public std::regex,
10  public internal::typed_base<std::regex, true>,
11  public originalStringKeeper {
12  typedef std::string rangeValueType;
13  std::regex::flag_type regexOption;
14  public:
15  single(char aShortName, const std::string& aLongName, const std::string& aExplanation, const std::string& aDefault = "", std::regex::flag_type aRegexOption = std::regex::ECMAScript) :
16  internal::typed_base<std::regex, true>(aShortName, aLongName, aExplanation, 1),
17  regexOption(aRegexOption) {
18  if (! aDefault.empty() ) {
19  assign(aDefault, std::regex::optimize | regexOption);
20  }
21  lOriginalString = aDefault;
22  }
23  void fSetMe(std::istream& aStream, const internal::sourceItem& aSource) override {
24  using escapedIO::operator>>;
25  aStream >> lOriginalString;
26  assign(lOriginalString, std::regex::optimize | regexOption);
27  fSetSource(aSource);
28  }
29  void fCheckRange() const override {
30  return;
31  }
32  void fAddDefaultFromStream(std::istream& aStream) override {
33  std::getline(aStream, lOriginalString);
34  assign(lOriginalString);
35  }
36  void fWriteValue(std::ostream& aStream) const override {
37  aStream << lOriginalString;
38  }
39  };
40 
41 }
42 
43 #endif
options::single
generic option class with any type that can be used with std::istream and std::ostream
Definition: Options.h:533
options::single< std::regex >::fAddDefaultFromStream
void fAddDefaultFromStream(std::istream &aStream) override
special for use in the shellScriptOptionParser
Definition: OptionsRegex.h:32
options::originalStringKeeper
interface class that is used for options where the original string rather than the streamed value is ...
Definition: Options.h:864
options::single< std::regex >::fSetMe
void fSetMe(std::istream &aStream, const internal::sourceItem &aSource) override
function to set the value from a string, remembering the source
Definition: OptionsRegex.h:23
options::single< std::regex >::regexOption
std::regex::flag_type regexOption
Definition: OptionsRegex.h:13
options::single< std::regex >::fCheckRange
void fCheckRange() const override
Definition: OptionsRegex.h:29
options::internal::typed_base
Definition: Options.h:445
options::single< std::regex >::single
single(char aShortName, const std::string &aLongName, const std::string &aExplanation, const std::string &aDefault="", std::regex::flag_type aRegexOption=std::regex::ECMAScript)
Definition: OptionsRegex.h:15
options::internal::typed_base< T >::typed_base
typed_base(Types ... args)
Definition: Options.h:454
options
Definition: Options.h:33
Options.h
options::internal::sourceItem
class to remember from which line (or item) of a file/line an option was set from
Definition: Options.h:53
options::single< std::regex >::rangeValueType
std::string rangeValueType
Definition: OptionsRegex.h:12
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
options::single< std::regex >::fWriteValue
void fWriteValue(std::ostream &aStream) const override
write textual representation of value to a std::ostream
Definition: OptionsRegex.h:36