9 #ifndef Sawyer_CommandLine_H
10 #define Sawyer_CommandLine_H
12 #include <Sawyer/Assert.h>
13 #include <Sawyer/BitFlags.h>
14 #include <Sawyer/DocumentMarkup.h>
15 #include <Sawyer/IntervalSet.h>
16 #include <Sawyer/Map.h>
17 #include <Sawyer/Message.h>
18 #include <Sawyer/Optional.h>
19 #include <Sawyer/Sawyer.h>
20 #include <Sawyer/Set.h>
21 #include <Sawyer/SharedPointer.h>
23 #include <boost/algorithm/string/case_conv.hpp>
24 #include <boost/any.hpp>
25 #include <boost/cstdint.hpp>
26 #include <boost/foreach.hpp>
27 #include <boost/lexical_cast.hpp>
28 #include <boost/numeric/conversion/cast.hpp>
164 namespace CommandLine {
166 SAWYER_EXPORT
extern const std::string STR_NONE;
225 Location(
size_t idx,
size_t offset): idx(idx), offset(offset) {}
245 SAWYER_EXPORT std::ostream&
operator<<(std::ostream&,
const Location&);
250 SAWYER_EXPORT
extern const Location
NOWHERE;
256 #include <Sawyer/WarningsOff.h>
257 std::vector<std::string> strings_;
259 #include <Sawyer/WarningsRestore.h>
263 Cursor(
const std::vector<std::string> &strings): strings_(strings) { location(
Location()); }
273 const std::vector<std::string>&
strings()
const {
return strings_; }
316 const std::string&
arg()
const {
return arg(loc_); }
317 const std::string& arg(
const Location &location)
const;
325 std::string rest(
const Location &location)
const;
333 std::string
substr(
const Location &limit,
const std::string &separator=
" ")
const {
return substr(loc_, limit, separator); }
334 std::string substr(
const Location &limit1,
const Location &limit2,
const std::string &separator=
" ")
const;
339 void replace(
const std::vector<std::string>&);
344 void consumeChars(
size_t nchars);
351 loc_.
idx = std::min(strings_.size(), loc_.
idx+nargs);
362 size_t linearDistance()
const;
398 virtual void save(
const boost::any&,
const std::string &switchKey) = 0;
410 virtual void save(
const boost::any &value,
const std::string &) {
411 storage_ = boost::any_cast<T>(value);
418 #define SAWYER_COMMANDLINE_SEQUENCE_SAVER(CONTAINER_TEMPLATE, INSERT_METHOD) \
419 template<typename T> \
420 class TypedSaver<CONTAINER_TEMPLATE<T> >: public ValueSaver { \
421 CONTAINER_TEMPLATE<T> &storage_; \
423 TypedSaver(CONTAINER_TEMPLATE<T> &storage): storage_(storage) {} \
425 static Ptr instance(CONTAINER_TEMPLATE<T> &storage) { return Ptr(new TypedSaver(storage)); } \
426 virtual void save(const boost::any &value, const std::string &) { \
427 T typed = boost::any_cast<T>(value); \
428 storage_.INSERT_METHOD(typed); \
436 #define SAWYER_COMMANDLINE_MAP_SAVER(CONTAINER_TEMPLATE, INSERT_METHOD) \
437 template<typename T> \
438 class TypedSaver<CONTAINER_TEMPLATE<std::string, T> >: public ValueSaver { \
439 CONTAINER_TEMPLATE<std::string, T> &storage_; \
441 TypedSaver(CONTAINER_TEMPLATE<std::string, T> &storage): storage_(storage) {} \
443 static Ptr instance(CONTAINER_TEMPLATE<std::string, T> &storage) { return Ptr(new TypedSaver(storage)); } \
444 virtual void save(const boost::any &value, const std::string &switchKey) { \
445 T typed = boost::any_cast<T>(value); \
446 storage_.INSERT_METHOD(switchKey, typed); \
453 #define SAWYER_COMMANDLINE_INTERVALSET_SAVER(CONTAINER_TEMPLATE, INSERT_METHOD) \
454 template<typename Interval> \
455 class TypedSaver<CONTAINER_TEMPLATE<Interval> >: public ValueSaver { \
456 CONTAINER_TEMPLATE<Interval> &storage_; \
458 TypedSaver(CONTAINER_TEMPLATE<Interval> &storage): storage_(storage) {} \
460 static Ptr instance(CONTAINER_TEMPLATE<Interval> &storage) { return Ptr(new TypedSaver(storage)); } \
461 virtual void save(const boost::any &value, const std::string &switchKey) { \
462 Interval typed = boost::any_cast<Interval>(value); \
463 storage_.INSERT_METHOD(typed); \
471 #define SAWYER_COMMANDLINE_MAP_PAIR_SAVER(CONTAINER_TEMPLATE, INSERT_METHOD) \
472 template<typename T> \
473 class TypedSaver<CONTAINER_TEMPLATE<std::string, T> >: public ValueSaver { \
474 CONTAINER_TEMPLATE<std::string, T> &storage_; \
476 TypedSaver(CONTAINER_TEMPLATE<std::string, T> &storage): storage_(storage) {} \
478 static Ptr instance(CONTAINER_TEMPLATE<std::string, T> &storage) { return Ptr(new TypedSaver(storage)); } \
479 virtual void save(const boost::any &value, const std::string &switchKey) { \
480 T typed = boost::any_cast<T>(value); \
481 storage_.INSERT_METHOD(std::make_pair(switchKey, typed)); \
485 SAWYER_COMMANDLINE_SEQUENCE_SAVER(std::vector, push_back);
486 SAWYER_COMMANDLINE_SEQUENCE_SAVER(std::list, push_back);
487 SAWYER_COMMANDLINE_SEQUENCE_SAVER(std::set, insert);
489 SAWYER_COMMANDLINE_SEQUENCE_SAVER(
Optional,
operator=);
491 SAWYER_COMMANDLINE_MAP_PAIR_SAVER(std::map, insert);
506 #include <Sawyer/WarningsOff.h>
509 std::string valueString_;
510 std::string switchKey_;
512 std::string switchString_;
514 size_t switchSequence_;
516 #include <Sawyer/WarningsRestore.h>
532 : value_(value), valueLocation_(loc), valueString_(str), keySequence_(0), switchSequence_(0), valueSaver_(saver) {}
538 switchLocation_ = loc;
545 void sequenceInfo(
size_t keySequence,
size_t switchSequence) {
546 keySequence_ = keySequence;
547 switchSequence_ = switchSequence;
556 const boost::any&
value()
const {
return value_; }
557 void value(
const boost::any &v) { value_ = v; }
568 const std::string &
string()
const {
return valueString_; }
576 unsigned asUnsigned()
const;
578 unsigned long asUnsignedLong()
const;
579 boost::int64_t asInt64()
const;
580 boost::uint64_t asUnsigned64()
const;
581 double asDouble()
const;
582 float asFloat()
const;
584 std::string asString()
const;
589 template<
typename T> T
as()
const {
return boost::any_cast<T>(value_); }
594 const std::string&
switchKey()
const {
return switchKey_; }
628 bool isEmpty()
const {
return value_.empty(); }
631 void print(std::ostream&)
const;
635 SAWYER_EXPORT std::ostream&
operator<<(std::ostream&,
const ParsedValue&);
700 #include <Sawyer/WarningsOff.h>
702 #include <Sawyer/WarningsRestore.h>
755 static T convert(
const std::string &src) {
757 return boost::lexical_cast<T>(src);
758 }
catch (
const boost::bad_lexical_cast &e) {
759 throw std::runtime_error(e.what());
766 static boost::regex convert(
const std::string &src) {
767 return boost::regex(src);
773 static std::regex convert(
const std::string &src) {
774 return std::regex(src);
780 static boost::filesystem::path convert(
const std::string &src) {
781 return boost::filesystem::path(src);
787 static boost::any convert(
const std::string &src) {
794 static T convert(
const std::string &src) {
801 static T convert(
const std::string &src) {
808 static T convert(
const std::string &src) {
815 static T convert(
const std::string &src) {
822 static T convert(
const std::string &src) {
829 static T convert(
const std::string &src) {
836 static T convert(
const std::string &src) {
888 throw std::runtime_error(
"string expected");
890 std::string s = cursor.
rest();
897 template<
typename Target,
typename Source>
899 static Target convert(Source from,
const std::string &parsed) {
901 return boost::numeric_cast<Target>(from);
902 }
catch (
const boost::numeric::positive_overflow&) {
903 std::string bound = boost::lexical_cast<std::string>(boost::numeric::bounds<Target>::highest());
904 throw std::range_error(
"parsed string \""+parsed+
"\" is greater than "+bound);
905 }
catch (
const boost::numeric::negative_overflow&) {
906 std::string bound = boost::lexical_cast<std::string>(boost::numeric::bounds<Target>::lowest());
907 throw std::range_error(
"parsed string \""+parsed+
"\" is less than "+bound);
908 }
catch (
const boost::numeric::bad_numeric_cast&) {
909 throw std::range_error(
"cannot cast \""+parsed+
"\" to destination type");
915 template<
typename Target,
typename Source>
917 static Target convert(Source from,
const std::string &parsed) {
923 template<
typename Target,
typename Source>
925 static Target convert(Source from,
const std::string &parsed) {
931 template<
typename Target,
typename Source>
933 static Target convert(Source from,
const std::string &parsed) {
939 template<
typename Target,
typename Source>
941 static Target convert(Source from,
const std::string &parsed) {
947 template<
typename Target,
typename Source>
949 static Target convert(Source from,
const std::string &parsed) {
955 template<
typename Target,
typename Source>
957 static Target convert(Source from,
const std::string &parsed) {
963 template<
typename Target,
typename Source>
965 static Target convert(Source from,
const std::string &parsed) {
1007 virtual ParsedValue operator()(
const char *input,
const char **rest,
const Location &loc) {
1009 boost::int64_t big =
strtoll(input, (
char**)rest, 0);
1011 throw std::runtime_error(
"integer expected");
1012 while (isspace(**rest)) ++*rest;
1013 std::string parsed(input, *rest-input);
1015 throw std::range_error(
"integer overflow when parsing \""+parsed+
"\"");
1030 template<
typename T>
1052 virtual ParsedValue operator()(
const char *input,
const char **rest,
const Location &loc) {
1054 while (isspace(*input)) ++input;
1055 if (
'+'!=*input && !isdigit(*input))
1056 throw std::runtime_error(
"unsigned integer expected");
1057 boost::uint64_t big =
strtoull(input, (
char**)rest, 0);
1059 throw std::runtime_error(
"unsigned integer expected");
1060 while (isspace(**rest)) ++*rest;
1061 std::string parsed(input, *rest-input);
1063 throw std::range_error(
"integer overflow when parsing \""+parsed+
"\"");
1078 template<
typename T>
1100 virtual ParsedValue operator()(
const char *input,
const char **rest,
const Location &loc) {
1102 while (isspace(*input)) ++input;
1103 if (
'+'!=*input && !isdigit(*input))
1104 throw std::runtime_error(
"positive integer expected");
1105 boost::uint64_t big =
strtoull(input, (
char**)rest, 0);
1106 if (*rest==input || big==0)
1107 throw std::runtime_error(
"positive integer expected");
1108 while (isspace(**rest)) ++*rest;
1109 std::string parsed(input, *rest-input);
1111 throw std::range_error(
"integer overflow when parsing \""+parsed+
"\"");
1125 template<
typename T>
1147 virtual ParsedValue operator()(
const char *input,
const char **rest,
const Location &loc) {
1148 double big = strtod(input, (
char**)rest);
1150 throw std::runtime_error(
"real number expected");
1151 while (isspace(**rest)) ++*rest;
1152 std::string parsed(input, *rest-input);
1163 template<
typename T>
1185 virtual ParsedValue operator()(
const char *input,
const char **rest,
const Location &loc) {
1186 static const char *neg[] = {
"false",
"off",
"no",
"0",
"f",
"n"};
1187 static const char *pos[] = {
"true",
"yes",
"on",
"1",
"t",
"y"};
1188 const char *start = input;
1189 while (isspace(*input)) ++input;
1190 for (
int negpos=0; negpos<2; ++negpos) {
1191 const char **list = 0==negpos ? neg : pos;
1192 size_t listsz = 0==negpos ?
sizeof(neg)/
sizeof(*neg) : sizeof(pos)/sizeof(*pos);
1193 for (
size_t i=0; i<listsz; ++i) {
1194 if (0==my_strncasecmp(list[i], input, strlen(list[i]))) {
1195 *rest = input + strlen(list[i]);
1196 while (isspace(**rest)) ++*rest;
1197 std::string parsed(start, *rest-start);
1198 return ParsedValue(NumericCast<T, bool>::convert(0!=negpos, parsed), loc, parsed,
valueSaver());
1202 throw std::runtime_error(
"Boolean expected");
1206 int my_strncasecmp(
const char *a,
const char *b,
size_t nchars) {
1209 for (
size_t i=0; i<nchars; ++i) {
1211 return a[i] ? 1 : (b[i] ? -1 : 0);
1212 char achar = (char)tolower(a[i]);
1213 char bchar = (char)tolower(b[i]);
1215 return achar < bchar ? -1 : 1;
1230 #include <Sawyer/WarningsOff.h>
1231 std::vector<std::string> strings_;
1232 #include <Sawyer/WarningsRestore.h>
1256 Ptr with(
const std::vector<std::string> sv) {
return with(sv.begin(), sv.end()); }
1257 template<
class InputIterator>
1258 Ptr with(InputIterator begin, InputIterator end) {
1259 strings_.insert(strings_.end(), begin, end);
1275 template<
typename T>
1301 strParser_->with(name);
1302 members_.
insert(name, value);
1320 typedef std::pair<ValueParser::Ptr, std::string> ParserSep;
1321 #include <Sawyer/WarningsOff.h>
1322 std::vector<ParserSep> elements_;
1323 size_t minLength_, maxLength_;
1324 #include <Sawyer/WarningsRestore.h>
1328 : minLength_(1), maxLength_((size_t)-1) {
1329 elements_.push_back(ParserSep(firstElmtType, separatorRe));
1356 elements_.push_back(ParserSep(elmtType, separatorRe));
1357 return sharedFromThis().dynamicCast<
ListParser>();
1366 Ptr limit(
size_t minLength,
size_t maxLength);
1367 Ptr limit(
size_t maxLength) {
return limit(std::min(minLength_, maxLength), maxLength); }
1429 template<
typename T>
1433 template<
typename T>
1439 template<
typename T>
1443 template<
typename T>
1449 template<
typename T>
1453 template<
typename T>
1459 template<
typename T>
1463 template<
typename T>
1469 template<
typename T>
1473 template<
typename T>
1479 template<
typename T>
1483 template<
typename T>
1489 template<
typename T>
1493 template<
typename T>
1497 template<
typename T>
1501 template<
typename T>
1505 template<
typename T>
1536 #include <Sawyer/WarningsOff.h>
1540 #include <Sawyer/WarningsRestore.h>
1545 : name_(name), parser_(parser) {}
1551 : name_(name), parser_(parser), defaultValue_(parser->matchString(defaultValueString)) {
1557 return defaultValue_.
isEmpty();
1563 return !isRequired();
1571 const std::string &
name()
const {
return name_; }
1574 std::string nameAsText()
const;
1578 return defaultValue_;
1585 return defaultValue_.
string();
1628 #include <Sawyer/WarningsOff.h>
1629 std::string versionString_;
1630 #include <Sawyer/WarningsRestore.h>
1633 explicit ShowVersion(
const std::string &versionString): versionString_(versionString) {}
1654 :
ShowVersion(versionString), exitStatus_(exitStatus) {}
1663 static Ptr instance(
const std::string &versionString,
int exitStatus) {
1727 #include <Sawyer/WarningsOff.h>
1728 std::string switchKey_;
1731 #include <Sawyer/WarningsRestore.h>
1735 : switchKey_(switchKey), facilities_(facilities), exitOnHelp_(exitOnHelp) {}
1768 #include <Sawyer/WarningsOff.h>
1770 #include <Sawyer/WarningsRestore.h>
1773 : facilities_(facilities) {
1811 template<
class Functor>
1827 virtual void operator()(
const ParserResult &parserResult) { (functor_)(parserResult); }
1870 template<
class Functor>
1921 template<
typename T>
1937 ASSERT_forbid(newValues.empty());
1939 BOOST_FOREACH (
const ParsedValue &pv, savedValues)
1946 pvals.push_back(pval);
1980 template<
typename T>
1994 #include <Sawyer/WarningsOff.h>
1995 std::vector<std::string> longPrefixes;
1996 bool inheritLongPrefixes;
1997 std::vector<std::string> shortPrefixes;
1998 bool inheritShortPrefixes;
1999 std::vector<std::string> valueSeparators;
2000 bool inheritValueSeparators;
2002 #include <Sawyer/WarningsRestore.h>
2004 : inheritLongPrefixes(
true), inheritShortPrefixes(
true), inheritValueSeparators(
true),
2043 #include <Sawyer/WarningsOff.h>
2044 std::vector<std::string> longNames_;
2045 std::string shortNames_;
2048 std::string synopsis_;
2049 std::string documentation_;
2050 std::string documentationKey_;
2052 std::vector<SwitchArgument> arguments_;
2057 bool explosiveLists_;
2059 #include <Sawyer/WarningsRestore.h>
2074 explicit Switch(
const std::string &longName,
char shortName=
'\0')
2076 explosiveLists_(false), skipping_(
SKIP_NEVER) {
2077 init(longName, shortName);
2085 Switch& longName(
const std::string &name);
2086 const std::string&
longName()
const {
return longNames_.front(); }
2087 const std::vector<std::string>&
longNames()
const {
return longNames_; }
2101 std::string
preferredName()
const {
return longNames_.empty() ? std::string(1, shortNames_[0]) : longNames_[0]; }
2111 Switch&
key(
const std::string &s) { key_ = s;
return *
this; }
2112 const std::string &
key()
const {
return key_; }
2147 std::string synopsis()
const;
2185 Switch&
doc(
const std::string &s) { documentation_ = s;
return *
this; }
2186 const std::string&
doc()
const {
return documentation_; }
2193 Switch&
docKey(
const std::string &s) { documentationKey_ = s;
return *
this; }
2194 const std::string &
docKey()
const {
return documentationKey_; }
2231 Switch& resetLongPrefixes(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2232 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
2233 Switch&
longPrefix(
const std::string &s1) { properties_.longPrefixes.push_back(s1);
return *
this; }
2234 const std::vector<std::string>&
longPrefixes()
const {
return properties_.longPrefixes; }
2248 Switch& resetShortPrefixes(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2249 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
2250 Switch&
shortPrefix(
const std::string &s1) { properties_.shortPrefixes.push_back(s1);
return *
this; }
2251 const std::vector<std::string>&
shortPrefixes()
const {
return properties_.shortPrefixes; }
2270 Switch& resetValueSeparators(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2271 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
2273 const std::vector<std::string>&
valueSeparators()
const {
return properties_.valueSeparators; }
2299 Switch& argument(
const std::string &name,
const ValueParser::Ptr &parser,
const std::string &defaultValue);
2302 const std::vector<SwitchArgument>&
arguments()
const {
return arguments_; }
2310 size_t nRequiredArguments()
const;
2341 template<
typename T>
2351 intrinsicValue_ = p->matchString(text);
2356 intrinsicValue_ =
anyParser()->matchString(text);
2461 friend class Parser;
2462 friend class ParserResult;
2464 void init(
const std::string &longName,
char shortName);
2467 std::runtime_error noSeparator(
const std::string &switchString,
const Cursor&,
const ParsingProperties&)
const;
2470 std::runtime_error extraTextAfterSwitch(
const std::string &switchString,
const Location &endOfSwitch,
const Cursor&,
2474 std::runtime_error extraTextAfterArgument(
const Cursor&,
const ParsedValue &va)
const;
2477 std::runtime_error notEnoughArguments(
const std::string &switchString,
const Cursor&,
size_t nargs)
const;
2480 std::runtime_error missingArgument(
const std::string &switchString,
const Cursor &cursor,
2481 const SwitchArgument &sa,
const std::string &reason)
const;
2484 std::runtime_error malformedArgument(
const std::string &switchString,
const Cursor &cursor,
2485 const SwitchArgument &sa,
const std::string &reason)
const;
2493 size_t matchLongName(Cursor&,
const ParsingProperties &props,
2494 const std::string &optionalPart,
const std::string &requiredPart)
const;
2502 size_t matchShortName(Cursor&,
const ParsingProperties &props, std::string &name)
const;
2511 void matchLongArguments(
const std::string &switchString, Cursor &cursor ,
const ParsingProperties &props,
2517 void matchShortArguments(
const std::string &switchString, Cursor &cursor ,
const ParsingProperties &props,
2527 size_t matchArguments(
const std::string &switchString,
const Location &endOfSwitch, Cursor &cursor ,
2528 const ParsingProperties &props,
ParsedValues &result ,
bool isLongSwitch)
const;
2531 std::string synopsisForArgument(
const SwitchArgument&)
const;
2534 std::string synopsis(
const ParsingProperties &swProps,
const SwitchGroup *
sg,
const std::string &nameSpaceSeparator)
const;
2570 #include <Sawyer/WarningsOff.h>
2571 std::vector<Switch> switches_;
2575 std::string docKey_;
2576 std::string documentation_;
2578 #include <Sawyer/WarningsRestore.h>
2589 explicit SwitchGroup(
const std::string &title,
const std::string &docKey=
"")
2590 : title_(title), docKey_(docKey), switchOrder_(
DOCKEY_ORDER) {}
2597 const std::string&
title()
const {
return title_; }
2611 const std::string&
name()
const {
return name_; }
2627 const std::string&
docKey()
const {
return docKey_; }
2644 const std::string&
doc()
const {
return documentation_; }
2659 SwitchGroup& resetLongPrefixes(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2660 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
2662 const std::vector<std::string>&
longPrefixes()
const {
return properties_.longPrefixes; }
2667 SwitchGroup& resetShortPrefixes(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2668 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
2670 const std::vector<std::string>&
shortPrefixes()
const {
return properties_.shortPrefixes; }
2675 SwitchGroup& resetValueSeparators(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2676 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
2678 const std::vector<std::string>&
valueSeparators()
const {
return properties_.valueSeparators; }
2686 const std::vector<Switch>&
switches()
const {
return switches_; }
2689 bool nameExists(
const std::string &switchName);
2693 const Switch& getByName(
const std::string &switchName);
2696 bool keyExists(
const std::string &switchKey);
2699 const Switch& getByKey(
const std::string &switchKey);
2712 SwitchGroup& removeByName(
const std::string &switchName);
2715 SwitchGroup& removeByKey(
const std::string &switchKey);
2737 friend class Parser;
2738 bool removeByPointer(
const void*);
2757 #include <Sawyer/WarningsOff.h>
2758 std::vector<SwitchGroup> switchGroups_;
2760 std::string groupNameSeparator_;
2761 std::vector<std::string> terminationSwitches_;
2762 bool shortMayNestle_;
2763 std::vector<std::string> inclusionPrefixes_;
2764 bool skipNonSwitches_;
2765 bool skipUnknownSwitches_;
2766 mutable std::string programName_;
2767 std::string purpose_;
2768 std::string versionString_;
2769 mutable std::string dateString_;
2771 std::string chapterName_;
2778 bool reportingAmbiguities_;
2779 std::string environmentVariable_;
2780 #include <Sawyer/WarningsRestore.h>
2786 : groupNameSeparator_(
"-"), shortMayNestle_(true), skipNonSwitches_(false), skipUnknownSwitches_(false),
2787 versionString_(
"alpha"), chapterNumber_(1), chapterName_(
"User Commands"), switchGroupOrder_(
INSERTION_ORDER),
2788 reportingAmbiguities_(true) {
2796 switchGroups_.push_back(
sg);
2800 switchGroups_.push_back(
sg);
2801 switchGroups_.back().docKey(docKey);
2805 switchGroups_.insert(switchGroups_.end(), sgs.begin(), sgs.end());
2809 switchGroups_.push_back(
SwitchGroup().insert(sw));
2814 switchGroups_.push_back(
SwitchGroup().insert(sw));
2823 return switchGroups_;
2826 return switchGroups_;
2833 bool switchGroupExists(
const std::string &name)
const;
2841 const SwitchGroup& switchGroup(
const std::string &name)
const;
2842 SwitchGroup& switchGroup(
const std::string &name);
2849 bool eraseSwitchGroup(
const std::string &name);
2894 Parser& resetLongPrefixes(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2895 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
2896 Parser&
longPrefix(
const std::string &s1) { properties_.longPrefixes.push_back(s1);
return *
this; }
2897 const std::vector<std::string>&
longPrefixes()
const {
return properties_.longPrefixes; }
2904 Parser& resetShortPrefixes(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2905 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
2906 Parser&
shortPrefix(
const std::string &s1) { properties_.shortPrefixes.push_back(s1);
return *
this; }
2907 const std::vector<std::string>&
shortPrefixes()
const {
return properties_.shortPrefixes; }
2916 Parser& resetValueSeparators(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2917 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
2919 const std::vector<std::string>&
valueSeparators()
const {
return properties_.valueSeparators; }
2926 Parser& resetTerminationSwitches(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2927 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
2954 Parser& resetInclusionPrefixes(
const std::string &s1=STR_NONE,
const std::string &s2=STR_NONE,
2955 const std::string &s3=STR_NONE,
const std::string &s4=STR_NONE);
3009 std::string
exitMessage()
const {
return exitMessage_ ? *exitMessage_ : std::string(); }
3033 template<
typename Iterator>
3035 std::vector<std::string> args(begin, end);
3043 static std::vector<std::string> splitLineIntoWords(std::string);
3050 static std::vector<std::string> readArgsFromFile(
const std::string &filename);
3056 static std::vector<std::string> readArgsFromEnvVar(
const std::string &varName);
3062 std::vector<std::string> expandIncludedFiles(
const std::vector<std::string> &args);
3066 DEFAULT_GROUPING = 0,
3067 PROHIBIT_EMPTY_GROUPS = 0x0001,
3068 SPLIT_SINGLE_GROUP = 0x0002
3078 std::vector<std::vector<std::string> >
3079 regroupArgs(
const std::vector<std::string> &args,
3081 unsigned flags = 0 );
3087 const std::string& programName()
const;
3095 const std::string&
purpose()
const {
return purpose_; }
3101 Parser& version(
const std::string &versionString,
const std::string &dateString=
"");
3103 std::pair<std::string, std::string> version()
const;
3121 Parser& chapter(
int chapterNumber,
const std::string &chapterName=
"");
3123 std::pair<int, std::string> chapter()
const;
3164 Parser& doc(
const std::string §ionName,
const std::string &docKey,
const std::string &text);
3165 Parser&
doc(
const std::string §ionName,
const std::string &text) {
return doc(sectionName, sectionName, text); }
3166 std::vector<std::string> docSections()
const;
3167 std::string docForSwitches()
const;
3168 std::string docForSection(
const std::string §ionName)
const;
3175 std::string documentationMarkup()
const;
3180 std::string podDocumentation()
const;
3183 std::string textDocumentation()
const;
3186 void emitDocumentationToPager()
const;
3188 template<
class Grammar>
3189 void emitDocumentationToPager()
const {
3191 initDocGrammar(grammar);
3192 grammar.title(programName(), boost::lexical_cast<std::string>(chapter().first), chapter().second);
3193 grammar.version(version().first, version().second);
3194 grammar.emit(documentationMarkup());
3225 static void printIndex(std::ostream&,
const NamedSwitches&,
const std::string &linePrefix =
"");
3260 ParserResult parseInternal(std::vector<std::string> programArguments);
3267 bool parseOneSwitch(Cursor&,
const NamedSwitches &ambiguities, ParserResult&);
3290 bool apparentSwitch(
const Cursor&)
const;
3297 std::string ambiguityErrorMesg(
const std::string &longSwitchString,
const std::string &optionalPart,
3298 const std::string &longSwitchName,
const NamedSwitches &ambiguities);
3299 std::string ambiguityErrorMesg(
const std::string &shortSwitchString,
const NamedSwitches &ambiguities);
3334 #include <Sawyer/WarningsOff.h>
3352 typedef std::vector<size_t> SkippedIndex;
3353 SkippedIndex skippedIndex_;
3356 SkippedIndex terminators_;
3360 #include <Sawyer/WarningsRestore.h>
3364 ParserResult(
const Parser &parser,
const std::vector<std::string> &argv): parser_(parser), cursor_(argv) {}
3375 size_t have(
const std::string &switchKey)
const {
3397 const ParsedValue& parsed(
const std::string &switchKey,
size_t idx)
const;
3398 ParsedValues parsed(
const std::string &switchKey)
const;
3411 std::vector<std::string> skippedArgs()
const;
3419 std::vector<std::string> unreachedArgs()
const;
3435 std::vector<std::string> unparsedArgs(
bool includeTerminators=
false)
const;
3441 std::vector<std::string> parsedArgs()
const;
3463 Cursor& cursor() {
return cursor_; }
@ SAVE_NONE
The switch is disabled.
Functor to print the Unix man page.
Describes one command-line switch.
Location valueLocation() const
Property: command-line location from whence this value came.
SharedPointer< AnyParser > Ptr
Reference counting pointer for this class.
Wrapper around a user functor.
@ SHOW_GROUP_NONE
Never show the group name.
Switch & intrinsicValue(const std::string &text, const ValueParser::Ptr &p)
Property: value for a switch that has no declared arguments.
static Ptr instance(const ValueParser::Ptr &firstElmtType, const std::string &separatorRe="[,;:]\\s*")
Allocating constructor.
Parser & chapter(const std::pair< int, std::string > &p)
Manual chapter.
Information about a parsed switch value.
Parser & doc(const std::string §ionName, const std::string &text)
Documentation for a section of the manual.
static Ptr instance(const ValueSaver::Ptr &valueSaver)
Allocating constructor.
ConfigureDiagnostics::Ptr configureDiagnostics(const std::string &, Message::Facilities &, bool exitOnHelp=true)
Factory for switch action.
ParsedValue intrinsicValue() const
Property: value for a switch that has no declared arguments.
Functor to print a version string.
@ SAVE_FIRST
Use only the first occurrence and ignore all previous.
const std::vector< std::string > & valueSeparators() const
Property: strings that separate a long switch from its value.
Parser & exitMessage(const std::string &s)
Extra text to print before exit.
SharedPointer< IntegerParser > Ptr
Reference counting pointer for this class.
ConfigureDiagnosticsQuiet::Ptr configureDiagnosticsQuiet(Message::Facilities &)
Factory for switch action.
Holds a value or nothing.
size_t have(const std::string &switchKey) const
Returns the number of values for the specified key.
const SwitchAction::Ptr & action() const
Property: action to occur.
PositiveIntegerParser< T >::Ptr positiveIntegerParser(T &storage)
Factory for value parsers.
SharedPointer< Sum > Ptr
Reference counting pointer for this class.
SwitchGroup & longPrefix(const std::string &s1)
Property: prefixes for long names.
A container holding a set of values.
bool shortMayNestle() const
Indicates whether short switches can nestle together.
Sum< T >::Ptr sum()
Factory for value agumenter.
Switch & intrinsicValue(const std::string &text)
Property: value for a switch that has no declared arguments.
const std::string & defaultValueString() const
The default value string.
void consumeArg()
Advance the cursor to the beginning of the next string.
Switch & valueSeparator(const std::string &s1)
Property: strings that separate a long switch from its value.
SwitchGroup()
Construct an unnamed, untitled group.
Parses a boolean value and converts it to numeric type T.
ParsedValue()
Construct a new empty value.
Switch & action(const SwitchAction::Ptr &f)
Property: action to occur.
Parser & showingGroupNames(ShowGroupName x)
Property: How to show group names in switch documentation.
Parser & with(const Switch &sw)
Add switch declarations.
bool operator<=(const Location &other) const
Less than or equal.
NonNegativeIntegerParser< T >::Ptr nonNegativeIntegerParser(T &storage)
Factory for value parsers.
static Ptr instance(int exitStatus)
Allocating constructor.
Switch & skipping(SwitchSkipping how)
Property: whether to skip over this switch.
Cursor(const std::vector< std::string > &strings)
Construct a cursor from an ordered set of strings.
SharedPointer< PositiveIntegerParser > Ptr
Reference counting pointer for this class.
ShowGroupName
How to show group names in switch synopsis.
Parser & switchGroupOrder(SortOrder order)
Property: How to order switch groups in documentation.
EnumParser< T >::Ptr enumParser(T &storage)
Factory for value parsers.
bool hidden() const
Property: whether this switch appears in documentation.
const std::vector< Switch > & switches() const
List of all declared switches.
const std::vector< std::string > & allArgs() const
The original command line.
Switch(const std::string &longName, char shortName='\0')
Constructs a switch declaration.
Switch & key(const std::string &s)
Property: value storage key.
const std::string & doc() const
Property: Detailed description.
const std::vector< std::string > & longPrefixes() const
Property: prefixes for long names.
@ SKIP_NEVER
Treat the switch normally.
const std::string & key() const
Property: value storage key.
const SortOrder & switchOrder() const
Property: Order of switches in documentation.
const std::string & string() const
String representation.
EnumParser(const ValueSaver::Ptr &valueSaver)
Constructor for derived classes.
SwitchGroup & title(const std::string &title)
Property: Title of the switch group.
SwitchGroup & switchOrder(SortOrder order)
Property: Order of switches in documentation.
Switch & intrinsicValue(const char *value, std::string &storage)
Property: value for a switch that has no declared arguments.
SharedPointer< RealNumberParser > Ptr
Reference counting pointer for this class.
virtual ParsedValues operator()(const ParsedValues &savedValues, const ParsedValues &newValues)
Called when a switch's value is about to be stored into the ParserResult.
ParsedValue(const boost::any value, const Location &loc, const std::string &str, const ValueSaver::Ptr &saver)
Construct a new value.
ValueAugmenter::Ptr valueAugmenter() const
Property: functor to agument values.
Ptr with(const std::string &name, T value)
Adds enum members.
bool isOptional() const
Returns true if this argument is not required.
const std::string & doc() const
Property: detailed description.
IntegerParser(const ValueSaver::Ptr &valueSaver)
Constructor for derived classes.
GroupingFlags
Bit flags for argument grouping.
The parser for a program command line.
ShowHelpAndExit(int exitStatus)
Constructor for derived classes.
bool atArgEnd() const
True when the cursor is at the end of an argument.
Parses a positive integer and converts it to numeric type T.
const std::vector< std::string > & valueSeparators() const
Strings that separate a long switch from its value.
Sum()
Constructor for derived classes.
@ INSERTION_ORDER
Entities appear in the documentation in the same order they are inserted into the container.
ListParser::Ptr listParser(const ValueParser::Ptr &, const std::string &sepRe="[,;:]\\s*")
Factory for value parsers.
Parser & with(Switch sw, const std::string &docKey)
Add switch declarations.
Switch & explosiveLists(bool b)
Property: whether to convert a list value to individual values.
Container::Map< const SwitchGroup *, std::set< const Switch * > > GroupedSwitches
Subset of switches grouped by their switch groups.
static Ptr instance()
Allocating constructor.
@ SHOW_GROUP_REQUIRED
Show name as being required, like "--group-switch".
bool skippingNonSwitches() const
Whether to skip over non-switch arguments when parsing.
Parser & with(const SwitchGroup &sg)
Add switch declarations.
SharedPointer< ShowHelp > Ptr
Reference counting pointer for this class.
Ptr with(InputIterator begin, InputIterator end)
Adds string members.
const ValueSaver::Ptr valueSaver() const
How to save a value at a user-supplied location.
std::string exitMessage() const
Extra text to print before exit.
void consumeChars(size_t nchars)
Advance over characters.
static Ptr instance(const ValueSaver::Ptr &valueSaver)
Allocating constructor.
const Location NOWHERE
Indicates an invalid location.
bool skippingUnknownSwitches() const
Whether to skip over unrecognized switches.
const std::string & arg() const
Return the entire current program argument regardless of where the cursor is in that argument.
const std::vector< std::string > & longNames() const
Property: switch long name.
Container associating values with keys.
Parser & longPrefix(const std::string &s1)
Prefixes to use for long command-line switches.
static Ptr instance()
Allocating constructor.
Canonical
Format of a switch string.
SwitchGroup & name(const std::string &name)
Property: Group name.
Container::Map< std::string, GroupedSwitches > NamedSwitches
Subset of switches indexed by their command-line representation.
const boost::any & value() const
Property: the parsed value.
std::string substr(const Location &limit, const std::string &separator=" ") const
Returns all characters within limits.
IntegerParser()
Constructor for derived classes.
std::vector< ParsedValue > ParsedValues
A vector of parsed values.
RealNumberParser< T >::Ptr realNumberParser(T &storage)
Factory for value parsers.
Switch & synopsis(const std::string &s)
Property: abstract summary of the switch syntax.
const std::string & switchKey() const
Property: switch key.
RealNumberParser()
Constructor for derived classes.
static Ptr instance()
Allocating constructor.
NonNegativeIntegerParser(const ValueSaver::Ptr &valueSaver)
Constructor for derived classes.
bool atEnd(const Location &location) const
Returns true when the cursor is after all arguments.
Switch & shortName(char c)
Property: switch short name.
const std::vector< SwitchArgument > & arguments() const
Property: switch argument.
Parses a real number and converts it to numeric type T.
The result from parsing a command line.
Ptr limit(size_t maxLength)
Specify limits for the number of values parsed.
static Ptr instance(const ValueSaver::Ptr &valueSaver)
Allocating constructor.
Switch & valueAugmenter(const ValueAugmenter::Ptr &f)
Property: functor to agument values.
PositiveIntegerParser(const ValueSaver::Ptr &valueSaver)
Constructor for derived classes.
const std::string & docKey() const
Property: Documentation sort key.
const ParsedValue & defaultValue() const
The parsed default value.
ParsedValue & switchInfo(const std::string &key, const Location &loc, const std::string &str)
Update switch information.
StringSetParser()
Constructor for derived classes.
AnyParser< T >::Ptr anyParser(T &storage)
Factory for value parsers.
SharedPointer< ValueParser > sharedFromThis()
Create a shared pointer from this.
const Location & startingLocation() const
Starting location.
Map & insert(const Key &key, const Value &value)
Insert or update a key/value pair.
Location switchLocation() const
The command-line location of the switch to which this value belongs.
ShowHelp::Ptr showHelp()
Factory for switch action.
ShowVersion::Ptr showVersion(const std::string &versionString)
Factory for switch action.
Parser & version(const std::pair< std::string, std::string > &p)
Program version.
EnumParser()
Constructor for derived classes.
Cursor()
Constructs a not-very-useful cursor to nothing.
Ptr with(const std::vector< std::string > sv)
Adds string members.
size_t nArguments() const
Total number of arguments.
Base class parsing a value from input.
size_t idx
Index into some vector of program argument strings.
static Ptr instance()
Allocating constructor.
const std::string & groupNameSeparator() const
Property: String separating group name from switch name.
const std::string & environmentVariable() const
Name of environment variable holding initial arguments.
Input stream for command line arguments.
SortOrder switchGroupOrder() const
Property: How to order switch groups in documentation.
Parser & skippingUnknownSwitches(bool b)
Whether to skip over unrecognized switches.
ShowHelp()
Constructor for derived classes.
Parser & shortMayNestle(bool b)
Indicates whether short switches can nestle together.
const Value & getOrDefault(const Key &key) const
Lookup and return a value or a default.
Ptr exactly(size_t length)
Specify limits for the number of values parsed.
SwitchSkipping
Whether to skip a switch.
Switch & shortPrefix(const std::string &s1)
Property: prefixes for short names.
Ptr nextMember(const ValueParser::Ptr &elmtType, const std::string &separatorRe="[,;:]\\s*")
Specifies element type and separator.
Parser & programName(const std::string &programName)
Program name for documentation.
const std::vector< std::string > & longPrefixes() const
Prefixes to use for long command-line switches.
bool atEnd() const
Returns true when the cursor is after all arguments.
const std::vector< std::string > & longPrefixes() const
Property: prefixes for long names.
@ DOCKEY_ORDER
Entities are sorted according to their documentation keys.
std::string rest() const
Return the part of an argument at and beyond the cursor location.
SwitchGroup & docKey(const std::string &key)
Property: Documentation sort key.
Parser & purpose(const std::string &purpose)
Program purpose.
Switch & argument(const SwitchArgument &arg)
Property: switch argument.
static Ptr instance(const std::string &versionString)
Allocating constructor.
SharedPointer< StringSetParser > Ptr
Reference counting pointer for this class.
void showingGroupNames(ShowGroupName x)
Property: How to show group name in switch synopsis.
Parses an enumerated constant.
void value(const boost::any &v)
Property: the parsed value.
@ NONCANONICAL
Switch strings that are not CANONICAL.
const Parser & parser() const
That parser that created this result.
ShowVersionAndExit(const std::string &versionString, int exitStatus)
Constructor for derived classes.
const std::vector< std::string > & shortPrefixes() const
Property: prefixes for short names.
SharedPointer< EnumParser > Ptr
Reference counting pointer for this class.
const std::vector< std::string > & terminationSwitches() const
Strings that indicate the end of the argument list.
Collection of facilities.
SharedPointer< SwitchAction > Ptr
Reference counting pointer for this class.
Ptr valueSaver(const ValueSaver::Ptr &f)
Property: functor responsible for saving a parsed value in user storage.
Base class for value agumentors.
const std::string & name() const
Property: Group name.
void run(const ParserResult &parserResult)
Runs the action.
WhichValue whichValue() const
Property: how to handle multiple occurrences.
const std::vector< std::string > & strings() const
All strings for the cursor.
std::list< ParsedValue > ValueList
Value type for list ParsedValue.
bool isRequired() const
Returns true if this argument is required.
SwitchArgument(const std::string &name, const ValueParser::Ptr &parser, const std::string &defaultValueString)
Construct a new switch optional argument.
SharedPointer< ValueAugmenter > Ptr
Reference counting pointer for this class.
ValueParser()
Constructor for derived classes.
Functor to print the Unix man page and exit.
SwitchGroup & valueSeparator(const std::string &s1)
Property: strings that separate a long switch from its value.
ExcursionGuard(Cursor &cursor)
Construct a guard for a cursor.
const std::string & longName() const
Property: switch long name.
std::vector< SwitchGroup > & switchGroups()
List of all switch groups.
Guards a cursor and restores it when the guard is destroyed.
Describes one argument of a command-line switch.
@ SAVE_LAST
Use only the last occurrence and ignore all previous.
SharedPointer< class UserAction > Ptr
Reference counting pointer for this class.
static Ptr instance()
Allocating constructor.
ShowHelpAndExit::Ptr showHelpAndExit(int exitStatus)
Factory for switch action.
UserAction< Functor >::Ptr userAction(const Functor &functor)
Factory for switch action.
Parser & terminationSwitch(const std::string &s1)
Strings that indicate the end of the argument list.
Location(size_t idx, size_t offset)
Constructs a location that points to a particular character of a particular string.
ShowGroupName showingGroupNames() const
Property: How to show group names in switch documentation.
@ SAVE_ALL
Save all values as a vector.
static Ptr instance(const ValueSaver::Ptr &valueSaver)
Allocating constructor.
@ SKIP_WEAK
Process switch normally, but also add to skipped list.
Stores a vector of enum bit flags.
const std::string & switchString() const
The string for the switch that caused this value to be parsed.
SortOrder
The order in which things are sorted in the documentation.
AnyParser()
Constructor for derived classes.
size_t nSwitches() const
Number of switches declared.
SharedPointer< U > dynamicCast() const
Dynamic cast.
Parser & environmentVariable(const std::string &s)
Name of environment variable holding initial arguments.
static Ptr instance(const std::string &versionString, int exitStatus)
Allocating constructor.
Name space for the entire library.
const std::vector< std::string > & shortPrefixes() const
Property: prefixes for short names.
SharedPointer< BooleanParser > Ptr
Reference counting pointer for this class.
SharedPointer< ShowVersionAndExit > Ptr
Reference counting pointer for this class.
@ SKIP_STRONG
Skip switch and its argument(s) without saving any value.
PositiveIntegerParser()
Constructor for derived classes.
const std::string & title() const
Property: Title of the switch group.
StringSetParser(const ValueSaver::Ptr &valueSaver)
Constructor for derived classes.
Sums all previous and current values.
bool operator<(const Location &other) const
Less than.
ValueParser(const ValueSaver::Ptr &valueSaver)
Constructor for derived classes.
BooleanParser()
Constructor for derived classes.
bool reportingAmbiguities() const
Property: Whether to report ambiguities.
Parser & inclusionPrefix(const std::string &s1)
Strings that indicate that arguments are to be read from a file.
Cursor(const std::string &string)
Constructs a cursor for a single string.
static Ptr instance()
Allocating constructor.
static Ptr instance()
Allocating constructor.
bool atArgBegin() const
True when the cursor is at the beginning of an argument.
Parses a non-negative integer and converts it to numeric type T.
const std::vector< std::string > & valueSeparators() const
Property: strings that separate a long switch from its value.
const ValueSaver::Ptr valueSaver() const
Property: functor responsible for saving a parsed value in user storage.
SwitchGroup & doc(const std::string &s)
Property: Detailed description.
SwitchSkipping skipping() const
Property: whether to skip over this switch.
ShowGroupName showingGroupNames() const
Property: How to show group name in switch synopsis.
Parses an integer and converts it to numeric type T.
Location()
Constructs the location of the first character of the first string.
bool initializeLibrary(size_t vmajor=0, size_t vminor=1, size_t vpatch=0, bool withThreads=0)
Explicitly initialize the library.
@ SAVE_ONE
The switch cannot occur more than once.
size_t keySequence() const
How this value relates to others with the same key.
SharedPointer< ShowHelpAndExit > Ptr
Reference counting pointer for this class.
std::string preferredName() const
Name by which switch prefers to be known.
ShowVersionAndExit::Ptr showVersionAndExit(const std::string &versionString, int exitStatus)
Factory for switch action.
boost::uint64_t strtoull(const char *, char **, int)
Portable replacement for strtoull.
const std::string & docKey() const
Property: key to control order of documentation.
This namespace contains template functions that operate on the ROSE AST.
Base class for reference counted objects.
@ CANONICAL
Switch strings that are qualified with the switch group name or which belong to a group that has no n...
Base class for switch actions.
const std::vector< std::string > & inclusionPrefixes() const
Strings that indicate that arguments are to be read from a file.
Creates SharedPointer from this.
size_t offset
Character offset within a program argument string.
SharedPointer< ListParser > Ptr
Reference counting pointer for this class.
static Ptr instance()
Allocating constructor.
std::ostream & operator<<(std::ostream &, const Location &)
Print a location.
const std::string & purpose() const
Program purpose.
Switch & doc(const std::string &s)
Property: detailed description.
IntegerParser< T >::Ptr integerParser(T &storage)
Factory for value parsers.
Switch & whichValue(WhichValue s)
Property: how to handle multiple occurrences.
BooleanParser< T >::Ptr booleanParser(T &storage)
Factory for value parsers.
Position within a command-line.
RealNumberParser(const ValueSaver::Ptr &valueSaver)
Constructor for derived classes.
ListParser(const ValueParser::Ptr &firstElmtType, const std::string &separatorRe)
Constructor for derived classes.
Switch & docKey(const std::string &s)
Property: key to control order of documentation.
ShowVersion(const std::string &versionString)
Constructor for derived classes.
static Ptr instance(const ValueSaver::Ptr &valueSaver)
Allocating constructor.
const std::string & shortNames() const
Property: switch short name.
bool operator==(const Location &other) const
Equality.
SwitchArgument(const std::string &name, const ValueParser::Ptr &parser=anyParser())
Construct a new required argument.
Parser & skippingNonSwitches(bool b)
Whether to skip over non-switch arguments when parsing.
BooleanParser(const ValueSaver::Ptr &valueSaver)
Constructor for derived classes.
const SwitchArgument & argument(size_t idx) const
Property: switch argument.
AnyParser(const ValueSaver::Ptr &valueSaver)
Constructor for derived classes.
@ ALL_STRINGS
The union of CANONICAL and NONCANONICAL.
Parses any argument as plain text.
void cancel()
Cancel the excursion guard.
const std::vector< std::string > & shortPrefixes() const
Prefixes to use for short command-line switches.
NonNegativeIntegerParser()
Constructor for derived classes.
static Ptr instance(const ValueSaver::Ptr &valueSaver)
Allocating constructor.
WhichValue
Describes how to handle switches that occur multiple times.
Parser & shortPrefix(const std::string &s1)
Prefixes to use for short command-line switches.
SharedPointer< NonNegativeIntegerParser > Ptr
Reference counting pointer for this class.
size_t switchSequence() const
How this value relates to others created by the same switch.
SwitchGroup(const std::string &title, const std::string &docKey="")
Construct a titled group.
bool operator!=(const Location &other) const
Inequality.
Switch & hidden(bool b)
Property: whether this switch appears in documentation.
bool explosiveLists() const
Property: whether to convert a list value to individual values.
const ValueParser::Ptr & parser() const
Returns a pointer to the parser.
Ptr with(const std::string &s)
Adds string members.
@ SHOW_GROUP_OPTIONAL
Show name as being optional, like "--[group-]switch".
@ SAVE_AUGMENTED
Save the first value, or modify previously saved value.
@ SHOW_GROUP_INHERIT
Group inherits value from the parser.
const Location & location() const
Property: current position of the cursor.
A collection of related switch declarations.
SharedPointer< ValueParser > Ptr
Reference counting pointer for this class.
static Ptr instance(const ValueSaver::Ptr &valueSaver)
Allocating constructor.
Functor to print a version string and exit.
SharedPointer< ShowVersion > Ptr
Reference counting pointer for this class.
UserAction(Functor &f)
Constructor for derived classes.
static Ptr instance(Functor &f)
Allocating constructor.
void consumeArgs(size_t nargs)
Advance the cursor to the beginning of the next string.
bool isEmpty() const
True if the value is void.
Parser & errorStream(const Message::SProxy &stream)
Specifies a message stream to which errors are sent.
T as() const
Convenient any_cast.
const std::vector< SwitchGroup > & switchGroups() const
List of all switch groups.
Parses any one of a set of strings.
SwitchGroup & shortPrefix(const std::string &s1)
Property: prefixes for short names.
Parser & with(const std::vector< SwitchGroup > &sgs)
Add switch declarations.
static Ptr instance()
Allocating constructor.
static Ptr instance(const ValueSaver::Ptr &valueSaver)
Allocating constructor.
Parser()
Default constructor.
ParsedValue & valueLocation(const Location &loc)
Property: command-line location from whence this value came.
ParsedValue & switchKey(const std::string &s)
Property: switch key.
Switch & intrinsicValue(const T &value, T &storage)
Property: value for a switch that has no declared arguments.
Parser & groupNameSeparator(const std::string &s)
Property: String separating group name from switch name.
Switch & longPrefix(const std::string &s1)
Property: prefixes for long names.
Parser & with(const SwitchGroup &sg, const std::string &docKey)
Add switch declarations.
StringSetParser::Ptr stringSetParser(std::string &storage)
Factory for value parsers.
boost::int64_t strtoll(const char *, char **, int)
Portable replacement for strtoll.
const Message::SProxy & errorStream() const
Specifies a message stream to which errors are sent.
const std::string & name() const
Argument name.
static Ptr instance()
Allocating constructor.
Switch & intrinsicValue(const ParsedValue &value)
Property: value for a switch that has no declared arguments.
Parser & reportingAmbiguities(bool b)
Property: Whether to report ambiguities.
Parser & valueSeparator(const std::string &s1)
Strings that separate a long switch from its value.