tclap 1.6.0
Arg.h
Go to the documentation of this file.
1// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
2
3/******************************************************************************
4 *
5 * file: Arg.h
6 *
7 * Copyright (c) 2003, Michael E. Smoot .
8 * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno .
9 * Copyright (c) 2017 Google Inc.
10 * All rights reserved.
11 *
12 * See the file COPYING in the top directory of this distribution for
13 * more information.
14 *
15 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 *****************************************************************************/
24
25#ifndef TCLAP_ARG_H
26#define TCLAP_ARG_H
27
28#ifdef HAVE_TCLAP_CONFIG_H
29#include <tclap/TCLAPConfig.h>
30#endif
31
32// Define to 1 before including TCLAP to retain the historical truncation of
33// ValueLike input at its first NUL byte. Use one setting across the program.
34#ifndef TCLAP_ALLOW_NUL_TRUNCATION
35#define TCLAP_ALLOW_NUL_TRUNCATION 0
36#endif
37
38#include <tclap/ArgException.h>
39#include <tclap/ArgTraits.h>
42#include <tclap/Visitor.h>
43#include <tclap/sstream.h>
44
45#include <concepts>
46#include <cstdio>
47#include <iomanip>
48#include <iostream>
49#include <list>
50#include <string>
51#include <utility>
52#include <vector>
53
54namespace TCLAP {
55
57struct ArgAlias {
58 std::string flag;
59 std::string name;
60 ArgAlias(std::string f, std::string n)
61 : flag(std::move(f)), name(std::move(n)) {}
62};
63
69class Arg {
70public:
74 Arg(const Arg &rhs) = delete;
75 Arg &operator=(const Arg &rhs) = delete;
76 friend class CmdLine;
77
78private:
79 // nullptr uses the legacy static delimiter for unregistered arguments.
80 const char *_parserDelimiter;
81 std::vector<ArgAlias> _aliases;
82 // Registration validates against the destination parser's conventions.
83 void _validateAliases(char delimiter, const std::string &flagPrefix,
84 const std::string &namePrefix) const;
85 bool _aliasConflictsWithDialect(const ArgAlias &alias, char delimiter,
86 const std::string &flagPrefix,
87 const std::string &namePrefix) const;
88 void _validateAliasToken(const std::string &label,
89 const std::string &prefix,
90 std::vector<std::string> &tokens) const;
91 void _validateAliasLabels(const std::string &flag,
92 const std::string &name) const;
93 bool _matchesDeclaredToken(const std::string &token,
94 const std::string &flagPrefix,
95 const std::string &namePrefix) const;
96 bool _aliasConflictsWith(const Arg &other, const std::string &flagPrefix,
97 const std::string &namePrefix) const;
98
103 static char &delimiterRef() {
104 static char delim = ' ';
105 return delim;
106 }
107
108protected:
109 bool matchesShortFlag(const std::string &flag) const;
110 bool matchesLongName(const std::string &name) const;
119 std::string _flag;
120
128 std::string _name;
129
133 std::string _description;
134
138 const bool _required;
139
144 std::string _requireLabel;
145
152
159
162 std::string _setBy;
163
171
176
178
184
188 void _checkWithVisitor() const;
189
203 Arg(std::string flag, std::string name, std::string desc, bool req,
204 bool valreq, Visitor *v = nullptr);
205
206public:
214 Arg &addAlias(std::string flag, std::string name = {});
215
217 [[nodiscard]] const std::vector<ArgAlias> &aliases() const noexcept { return _aliases; }
218
222 virtual ~Arg() = default;
223
228 virtual void addToList(std::list<Arg *> &argList) const;
229
234 static char delimiter() { return delimiterRef(); }
235
239 char getDelimiter() const {
240 return _parserDelimiter ? *_parserDelimiter : delimiter();
241 }
242
247 static constexpr char blankChar() noexcept { return '\a'; }
248
253#ifndef TCLAP_FLAGSTARTCHAR
254#define TCLAP_FLAGSTARTCHAR '-'
255#endif
256 static constexpr char flagStartChar() noexcept { return TCLAP_FLAGSTARTCHAR; }
257
263#ifndef TCLAP_FLAGSTARTSTRING
264#define TCLAP_FLAGSTARTSTRING "-"
265#endif
266 static std::string flagStartString() { return TCLAP_FLAGSTARTSTRING; }
267
272#ifndef TCLAP_NAMESTARTSTRING
273#define TCLAP_NAMESTARTSTRING "--"
274#endif
275 static std::string nameStartString() { return TCLAP_NAMESTARTSTRING; }
276
280 static std::string ignoreNameString() { return "ignore_rest"; }
281
287 static void setDelimiter(char c) { delimiterRef() = c; }
288
296 virtual bool processArg(int *i, std::vector<std::string> &args) = 0;
297
304 virtual bool operator==(const Arg &a) const;
305
313 [[nodiscard]] bool conflictsWith(const Arg &a) const noexcept;
314
318 [[nodiscard]] const std::string &getFlag() const noexcept;
319
323 [[nodiscard]] const std::string &getName() const noexcept;
324
328 [[nodiscard]] std::string getDescription() const {
330 }
331
335 virtual void setDescription(const std::string &desc) { _description = desc; }
336
343 [[nodiscard]] std::string getDescription(bool required) const {
344 return (required ? "(" + _requireLabel + ") " : "") + _description;
345 }
346
350 [[nodiscard]] virtual bool isRequired() const;
351
355 [[nodiscard]] bool isValueRequired() const noexcept;
356
361 [[nodiscard]] bool isSet() const noexcept;
362
366 [[nodiscard]] const std::string &setBy() const noexcept { return _setBy; }
367
371 [[nodiscard]] bool isIgnoreable() const noexcept;
372
381 [[nodiscard]] virtual bool argMatches(const std::string &s) const;
382
387 [[nodiscard]] virtual std::string toString() const;
388
393 [[nodiscard]] virtual std::string shortID(
394 const std::string &valueId = "val") const;
395
400 [[nodiscard]] virtual std::string longID(
401 const std::string &valueId = "val") const;
402
410 virtual void trimFlag(std::string &flag, std::string &value) const;
411
418 [[nodiscard]] bool _hasBlanks(const std::string &s) const;
419
424 virtual bool allowMore();
425
430 virtual bool acceptsMultipleValues();
431
436 virtual void reset();
437
442 virtual void hideFromHelp(bool hide = true) { _visibleInHelp = !hide; }
443
447 [[nodiscard]] virtual bool visibleInHelp() const { return _visibleInHelp; }
448
449 [[nodiscard]] virtual bool hasLabel() const { return true; }
450};
451
455using ArgListIterator = std::list<Arg *>::const_iterator;
456
460using ArgVectorIterator = std::vector<Arg *>::const_iterator;
461
465using VisitorListIterator = std::list<Visitor *>::const_iterator;
466
467namespace detail {
468// Satisfied iff T can be read from a TCLAP::istringstream via operator>>
469// (the mechanism ExtractValue's ValueLike overload, below, actually uses).
470template <typename T>
471concept StreamExtractable = requires(istringstream &is, T &val) { is >> val; };
472
473// Satisfied iff T is usable as a ValueArg/MultiArg value type: either it can
474// be read with operator>> (the ValueLike path) or it has explicitly opted
475// into the StringLike path (via an ArgTraits<T> specialization or by
476// inheriting StringLikeTrait), in which case it's expected to provide its
477// own SetString/operator=(const std::string&) - that half can't usefully be
478// concept-checked here since the unconstrained default SetString template
479// always matches syntactically regardless of whether its body would
480// actually compile for T.
481template <typename T>
484 std::same_as<typename ArgTraits<T>::ValueCategory, StringLike>;
485} // namespace detail
486
487/*
488 * Extract a value of type T from it's string representation contained
489 * in strVal. The ValueLike parameter used to select the correct
490 * specialization of ExtractValue depending on the value traits of T.
491 * ValueLike traits use operator>> to assign the value from strVal.
492 */
493template <typename T>
494void ExtractValue(T &destVal, const std::string &strVal, ValueLike vl) {
495 static_cast<void>(vl); // Avoid warning about unused vl
496#if !TCLAP_ALLOW_NUL_TRUNCATION
497 if (strVal.find('\0') != std::string::npos)
498 throw ArgParseException("Embedded NUL in argument value");
499#endif
500 istringstream is(strVal.c_str());
501
502 int valuesRead = 0;
503 // Let the extractor decide whether an explicitly empty input is valid.
504 // Built-in numeric extraction fails; a custom extractor may accept it.
505 if (strVal.empty()) {
506 is >> destVal;
507 ++valuesRead;
508 }
509 while (is.good()) {
510 if (is.peek() != EOF)
511#ifdef TCLAP_SETBASE_ZERO
512 is >> std::setbase(0) >> destVal;
513#else
514 is >> destVal;
515#endif
516 else
517 break;
518
519 valuesRead++;
520 }
521
522 if (is.fail())
523 throw(
524 ArgParseException("Couldn't read argument value "
525 "from string '" +
526 strVal + "'"));
527
528 if (valuesRead > 1)
529 throw(
530 ArgParseException("More than one valid value parsed from "
531 "string '" +
532 strVal + "'"));
533}
534
535/*
536 * Extract a value of type T from it's string representation contained
537 * in strVal. The ValueLike parameter used to select the correct
538 * specialization of ExtractValue depending on the value traits of T.
539 * StringLike uses assignment (operator=) to assign from strVal.
540 */
541template <typename T>
542void ExtractValue(T &destVal, const std::string &strVal, StringLike sl) {
543 static_cast<void>(sl); // Avoid warning about unused sl
544 SetString(destVal, strVal);
545}
546
548// BEGIN Arg.cpp
550
551inline Arg::Arg(std::string flag, std::string name, std::string desc,
552 bool req, bool valreq, Visitor *v)
553 : _parserDelimiter(nullptr),
554 _aliases(),
555 _flag(std::move(flag)),
556 _name(std::move(name)),
557 _description(std::move(desc)),
558 _required(req),
559 _requireLabel("required"),
560 _valueRequired(valreq),
561 _alreadySet(false),
562 _setBy(),
563 _visitor(v),
564 _ignoreable(true),
565 _acceptsMultipleValues(false),
566 _visibleInHelp(true) {
567 if (_flag.length() > 1)
569 "Argument flag can only be one character long", Arg::toString()));
570
571 if (_name != ignoreNameString() &&
573 _flag == " "))
575 "Argument flag cannot be either '" + Arg::flagStartString() +
576 "' or '" + Arg::nameStartString() + "' or a space.",
577 Arg::toString()));
578
579 if ((_name.substr(0, Arg::flagStartString().length()) ==
581 (_name.substr(0, Arg::nameStartString().length()) ==
583 (_name.find(" ", 0) != std::string::npos))
584 throw(SpecificationException("Argument name begin with either '" +
585 Arg::flagStartString() + "' or '" +
586 Arg::nameStartString() + "' or space.",
587 Arg::toString()));
588}
589
590inline std::string Arg::shortID(const std::string &valueId) const {
591 std::string id = "";
592
593 if (!_flag.empty())
595 else
597
598 if (_valueRequired) id += std::string(1, getDelimiter()) + valueId;
599
600 return id;
601}
602
603inline std::string Arg::longID(const std::string &valueId) const {
604 std::string id = "";
605
606 if (!_flag.empty()) {
607 id += Arg::flagStartString() + _flag;
608
609 if (_valueRequired) id += std::string(1, getDelimiter()) + valueId;
610
611 id += ", ";
612 }
613
614 id += Arg::nameStartString() + _name;
615
616 if (_valueRequired) id += std::string(1, getDelimiter()) + valueId;
617
618 for (const auto &alias : _aliases) {
619 if (!alias.flag.empty()) {
620 id += ", " + flagStartString() + alias.flag;
621 if (_valueRequired) id += std::string(1, getDelimiter()) + valueId;
622 }
623 if (!alias.name.empty()) {
624 id += ", " + nameStartString() + alias.name;
625 if (_valueRequired) id += std::string(1, getDelimiter()) + valueId;
626 }
627 }
628 return id;
629}
630
631inline bool Arg::_matchesDeclaredToken(const std::string &token,
632 const std::string &flagPrefix,
633 const std::string &namePrefix) const {
634 if ((!_flag.empty() && token == flagPrefix + _flag) ||
635 token == namePrefix + _name)
636 return true;
637 for (const auto &alias : _aliases)
638 if ((!alias.flag.empty() && token == flagPrefix + alias.flag) ||
639 (!alias.name.empty() && token == namePrefix + alias.name))
640 return true;
641 return false;
642}
643
644inline bool Arg::_aliasConflictsWith(const Arg &other,
645 const std::string &flagPrefix,
646 const std::string &namePrefix) const {
647 for (const auto &alias : _aliases)
648 if ((!alias.flag.empty() &&
649 other._matchesDeclaredToken(flagPrefix + alias.flag, flagPrefix,
650 namePrefix)) ||
651 (!alias.name.empty() &&
652 other._matchesDeclaredToken(namePrefix + alias.name, flagPrefix,
653 namePrefix)))
654 return true;
655 return false;
656}
657
658inline void Arg::_validateAliases(char delimiter, const std::string &flagPrefix,
659 const std::string &namePrefix) const {
660 if (_aliases.empty()) return;
661 std::vector<std::string> tokens;
662 if (!_flag.empty()) tokens.push_back(flagPrefix + _flag);
663 tokens.push_back(namePrefix + _name);
664 for (const auto &alias : _aliases) {
665 if (_aliasConflictsWithDialect(alias, delimiter, flagPrefix,
666 namePrefix))
667 throw SpecificationException("Alias conflicts with parser dialect",
668 toString());
669 _validateAliasToken(alias.flag, flagPrefix, tokens);
670 _validateAliasToken(alias.name, namePrefix, tokens);
671 }
672}
673
674inline bool Arg::matchesShortFlag(const std::string &flag) const {
675 if (flag.empty()) return false;
676 if (flag == _flag) return true;
677 for (const auto &alias : _aliases)
678 if (flag == alias.flag) return true;
679 return false;
680}
681
682inline bool Arg::matchesLongName(const std::string &name) const {
683 if (name.empty()) return false;
684 if (name == _name) return true;
685 for (const auto &alias : _aliases)
686 if (name == alias.name) return true;
687 return false;
688}
689
690inline Arg &Arg::addAlias(std::string flag, std::string name) {
691 if (_parserDelimiter)
692 throw SpecificationException("Aliases must be added before registration", toString());
693 if (!hasLabel())
694 throw SpecificationException("Positional arguments cannot have aliases", toString());
695 _validateAliasLabels(flag, name);
696 if (matchesShortFlag(flag) || matchesLongName(name))
697 throw SpecificationException("Duplicate argument alias", toString());
698 _aliases.emplace_back(std::move(flag), std::move(name));
699 return *this;
700}
701
702inline bool Arg::_aliasConflictsWithDialect(
703 const ArgAlias &alias, char delimiter, const std::string &flagPrefix,
704 const std::string &namePrefix) const {
705 return (!alias.flag.empty() &&
706 (alias.flag == flagPrefix || alias.flag == namePrefix)) ||
707 (!alias.name.empty() &&
708 ((!flagPrefix.empty() && alias.name.find(flagPrefix) == 0) ||
709 (!namePrefix.empty() && alias.name.find(namePrefix) == 0))) ||
711 (alias.flag.find(delimiter) != std::string::npos ||
712 alias.name.find(delimiter) != std::string::npos));
713}
714
715inline void Arg::_validateAliasToken(const std::string &label,
716 const std::string &prefix,
717 std::vector<std::string> &tokens) const {
718 if (label.empty()) return;
719 const std::string token = prefix + label;
720 for (const auto &existing : tokens)
721 if (existing == token)
722 throw SpecificationException("Duplicate argument alias token",
723 toString());
724 tokens.push_back(token);
725}
726
727inline void Arg::_validateAliasLabels(const std::string &flag,
728 const std::string &name) const {
729 if ((flag.empty() && name.empty()) || flag.size() > 1 ||
730 flag == flagStartString() || flag == nameStartString() ||
731 flag.find_first_of(" \t\r\n\v\f\a") != std::string::npos ||
732 flag.find('\0') != std::string::npos ||
733 name.find_first_of(" \t\r\n\v\f") != std::string::npos ||
734 name.find('\0') != std::string::npos ||
735 (!name.empty() && (name.find(flagStartString()) == 0 ||
736 name.find(nameStartString()) == 0)))
737 throw SpecificationException("Invalid argument alias", toString());
738 const std::string labels = flag + name;
739 for (unsigned char c : labels)
740 if (c < 0x20 || c == '\x7f')
741 throw SpecificationException("Control byte in argument alias",
742 toString());
743}
744
745inline bool Arg::conflictsWith(const Arg &a) const noexcept {
746 if (this == &a || _name == a._name || matchesLongName(a._name) || matchesShortFlag(a._flag))
747 return true;
748 for (const auto &alias : a._aliases)
749 if (matchesShortFlag(alias.flag) || matchesLongName(alias.name)) return true;
750 return false;
751}
752
753inline bool Arg::operator==(const Arg &a) const {
754 return (!_flag.empty() && _flag == a._flag) || _name == a._name;
755}
756
757inline const std::string &Arg::getFlag() const noexcept { return _flag; }
758
759inline const std::string &Arg::getName() const noexcept { return _name; }
760
761inline bool Arg::isRequired() const { return _required; }
762
763inline bool Arg::isValueRequired() const noexcept { return _valueRequired; }
764
765inline bool Arg::isSet() const noexcept { return _alreadySet; }
766
767inline bool Arg::isIgnoreable() const noexcept { return _ignoreable; }
768
769inline bool Arg::argMatches(const std::string &argFlag) const {
770 const std::string shortPrefix = flagStartString();
771 const std::string longPrefix = nameStartString();
772 return argFlag == longPrefix + _name ||
773 (argFlag.find(shortPrefix) == 0 &&
774 matchesShortFlag(argFlag.substr(shortPrefix.size()))) ||
775 (argFlag.find(longPrefix) == 0 &&
776 matchesLongName(argFlag.substr(longPrefix.size())));
777}
778
779inline std::string Arg::toString() const {
780 std::string s = "";
781
782 if (!_flag.empty()) s += Arg::flagStartString() + _flag + " ";
783
784 s += "(" + Arg::nameStartString() + _name + ")";
785
786 return s;
787}
788
789inline void Arg::_checkWithVisitor() const {
790 if (_visitor != nullptr) _visitor->visit();
791}
792
796inline void Arg::trimFlag(std::string &flag, std::string &value) const {
797 std::string::size_type stop = flag.find(getDelimiter());
798
799 if (stop != std::string::npos && stop > 1) {
800 value = flag.substr(stop + 1);
801 flag = flag.substr(0, stop);
802 }
803}
804
808inline bool Arg::_hasBlanks(const std::string &s) const {
809 return s.find(Arg::blankChar(), 1) != std::string::npos;
810}
811
815inline void Arg::addToList(std::list<Arg *> &argList) const {
816 argList.push_front(const_cast<Arg *>(this));
817}
818
819inline bool Arg::allowMore() { return false; }
820
822
823inline void Arg::reset() { _alreadySet = false; }
824
826// END Arg.cpp
828
829} // namespace TCLAP
830
831#endif // TCLAP_ARG_H
#define TCLAP_FLAGSTARTSTRING
The sting that indicates the beginning of a flag.
Definition Arg.h:264
#define TCLAP_FLAGSTARTCHAR
The char that indicates the beginning of a flag.
Definition Arg.h:254
#define TCLAP_NAMESTARTSTRING
The sting that indicates the beginning of a name.
Definition Arg.h:273
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
A virtual base class that defines the essential data for all arguments.
Definition Arg.h:69
static std::string flagStartString()
Definition Arg.h:266
void _checkWithVisitor() const
Performs the special handling described by the Visitor.
Definition Arg.h:789
bool _acceptsMultipleValues
Definition Arg.h:177
bool isValueRequired() const noexcept
Indicates whether a value must be specified for argument.
Definition Arg.h:763
bool _visibleInHelp
Indicates if the argument is visible in the help output (e.g., when specifying –help).
Definition Arg.h:183
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
Definition Arg.h:603
std::string _setBy
Indicates the value specified to set this flag (like -a or –all).
Definition Arg.h:162
std::string getDescription(bool required) const
Returns the argument description.
Definition Arg.h:343
std::string _requireLabel
Label to be used in usage description.
Definition Arg.h:144
bool _hasBlanks(const std::string &s) const
Checks whether a given string has blank chars, indicating that it is a combined SwitchArg.
Definition Arg.h:808
bool matchesLongName(const std::string &name) const
Definition Arg.h:682
virtual ~Arg()=default
Destructor.
bool conflictsWith(const Arg &a) const noexcept
Checks declared registration conflicts: the same object, the same name, or the same nonempty short fl...
Definition Arg.h:745
static constexpr char blankChar() noexcept
The char used as a place holder when SwitchArgs are combined.
Definition Arg.h:247
static constexpr char flagStartChar() noexcept
Definition Arg.h:256
bool isIgnoreable() const noexcept
Indicates whether the argument can be ignored, if desired.
Definition Arg.h:767
const bool _required
Indicating whether the argument is required.
Definition Arg.h:138
virtual bool processArg(int *i, std::vector< std::string > &args)=0
Pure virtual method meant to handle the parsing and value assignment of the string on the command lin...
Arg(const Arg &rhs)=delete
Prevent accidental copying.
bool _valueRequired
Indicates whether a value is required for the argument.
Definition Arg.h:151
bool _alreadySet
Indicates whether the argument has been set.
Definition Arg.h:158
const std::string & setBy() const noexcept
Returns the value specified to set this flag (like -a or –all).
Definition Arg.h:366
bool _ignoreable
Whether this argument can be ignored, if desired.
Definition Arg.h:175
std::string _description
Description of the argument.
Definition Arg.h:133
virtual void addToList(std::list< Arg * > &argList) const
Adds this to the specified list of Args.
Definition Arg.h:815
virtual bool allowMore()
Used for MultiArgs to determine whether args can still be set.
Definition Arg.h:819
Arg & addAlias(std::string flag, std::string name={})
Add equivalent spellings before registration.
Definition Arg.h:690
Visitor * _visitor
A pointer to a visitor object.
Definition Arg.h:170
virtual void hideFromHelp(bool hide=true)
Hide this argument from the help output (e.g., when specifying the –help flag or on error.
Definition Arg.h:442
static char delimiter()
The delimiter that separates an argument flag/name from the value.
Definition Arg.h:234
std::string getDescription() const
Returns the argument description.
Definition Arg.h:328
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
Definition Arg.h:823
bool matchesShortFlag(const std::string &flag) const
Definition Arg.h:674
std::string _name
A single word namd identifying the argument.
Definition Arg.h:128
virtual bool argMatches(const std::string &s) const
A method that tests whether a string matches this argument.
Definition Arg.h:769
static void setDelimiter(char c)
Sets the legacy delimiter for unregistered arguments and static callers.
Definition Arg.h:287
virtual bool acceptsMultipleValues()
Use by output classes to determine whether an Arg accepts multiple values.
Definition Arg.h:821
const std::string & getName() const noexcept
Returns the argument name.
Definition Arg.h:759
virtual void trimFlag(std::string &flag, std::string &value) const
Trims a value off of the flag.
Definition Arg.h:796
static std::string nameStartString()
Definition Arg.h:275
virtual std::string toString() const
Returns a simple string representation of the argument.
Definition Arg.h:779
bool isSet() const noexcept
Indicates whether the argument has already been set.
Definition Arg.h:765
char getDelimiter() const
Returns this argument's parser delimiter, or the legacy default.
Definition Arg.h:239
static std::string ignoreNameString()
The name used to identify the ignore rest argument.
Definition Arg.h:280
const std::string & getFlag() const noexcept
Returns the argument flag.
Definition Arg.h:757
virtual bool hasLabel() const
Definition Arg.h:449
std::string _flag
The single char flag used to identify the argument.
Definition Arg.h:119
virtual bool visibleInHelp() const
Returns true if this Arg is visible in the help output.
Definition Arg.h:447
virtual bool isRequired() const
Indicates whether the argument is required.
Definition Arg.h:761
const std::vector< ArgAlias > & aliases() const noexcept
Alias spellings in insertion order; no prefixes are stored.
Definition Arg.h:217
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
Definition Arg.h:590
virtual void setDescription(const std::string &desc)
Updates the argument description.
Definition Arg.h:335
virtual bool operator==(const Arg &a) const
Operator ==.
Definition Arg.h:753
Arg & operator=(const Arg &rhs)=delete
The base class that manages the command line definition and passes along the parsing to the appropria...
Definition CmdLine.h:86
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
A base class that defines the interface for visitors.
Definition Visitor.h:32
virtual void visit()=0
This method (to implemented by children) will be called when the visitor is visited.
Definition Arg.h:54
std::istringstream istringstream
Definition sstream.h:37
std::vector< Arg * >::const_iterator ArgVectorIterator
Typedef of an Arg vector iterator.
Definition Arg.h:460
std::list< Visitor * >::const_iterator VisitorListIterator
Typedef of a Visitor list iterator.
Definition Arg.h:465
void SetString(T &dst, const std::string &src)
std::list< Arg * >::const_iterator ArgListIterator
Typedef of an Arg list iterator.
Definition Arg.h:455
void ExtractValue(T &destVal, const std::string &strVal, ValueLike vl)
Definition Arg.h:494
An additional short flag and/or long name for the same argument.
Definition Arg.h:57
std::string name
Definition Arg.h:59
ArgAlias(std::string f, std::string n)
Definition Arg.h:60
std::string flag
Definition Arg.h:58
A string like argument value type is a value that can be set using operator=(string).
Definition ArgTraits.h:49
A value like argument value type is a value that can be set using operator>>.
Definition ArgTraits.h:39