67 mutable std::shared_ptr<unsigned int>
m_count;
129 alias(std::move(name));
143 alias(flag, std::move(name));
188 m_names.push_back(std::move(name));
200 m_names.push_back(std::move(name));
245 for (
char self_flag :
m_flags) {
246 if (self_flag == flag) {
261 for (
const std::string& self_name :
m_names) {
262 if (self_name == name) {
273 collector.push_back(
this);
311 throw std::logic_error(
"Cannot set zero minimum");
325 unsigned int min()
const {
344 unsigned int max()
const {
354 unsigned int count()
const override {
370 virtual void set()
const {
396 std::string
usage()
const override;
403 virtual std::string
ident()
const;
408 std::unique_ptr<BaseArgument>
clone() const &
override {
409 return std::unique_ptr<BaseArgument>(
new Argument(*
this));
415 std::unique_ptr<BaseArgument>
clone() &&
override {
416 return std::unique_ptr<BaseArgument>(
new Argument(std::move(*
this)));
446 bool addFlag =
false;
447 bool addName =
false;
449 std::vector<std::string::iterator> specialChars;
461 if (!isalnum(c) && addName) {
478 specialChars.push_back(it);
485 specialChars.push_back(it-1);
489 specialChars.push_back(it);
496 specialChars.push_back(it-1);
501 specialChars.push_back(it);
508 specialChars.push_back(it-1);
514 specialChars.push_back(it);
525 for (
auto it = specialChars.rbegin(); it != specialChars.rend(); it++) {
544 virtual void set(
const std::string& value)
const = 0;
const char skip[]
Define the parsed arg delimiter.
Definition: Tap.h:375
Argument(std::string description, char flag, std::string name)
Create an argument that is identified by both a name and flag.
Definition: Argument.hpp:138
std::shared_ptr< unsigned int > m_count
Actual counted number of occurrences.
Definition: Argument.hpp:67
std::string usage() const override
See BaseArgument::usage()
Argument(std::string description, std::string name)
Create an argument that is identified by a name.
Definition: Argument.hpp:124
bool matches(const std::string &name) const
Returns a pointer to this argument if it matches the given name with any alias, otherwise a null-poin...
Definition: Argument.hpp:260
Argument & min(unsigned int min)
Set the minimum number of required occurrences if set.
Definition: Argument.hpp:309
virtual std::string ident() const
Print a string representation of this argument to the given stream.
Argument & max(unsigned int max)
Set the maximum number of required occurrences.
Definition: Argument.hpp:335
const char nameStart[]
Marker for names (>1 letter arg)
Definition: Tap.h:359
std::unique_ptr< BaseArgument > clone()&&override
See BaseArgument::clone().
Definition: Argument.hpp:415
bool matches(char flag) const
Returns a pointer to this argument if it matches the given flag with any alias, otherwise a null-poin...
Definition: Argument.hpp:244
unsigned int min() const
Returns the minimum number of occurrences of this argument for it to be satisfied if set...
Definition: Argument.hpp:325
Base argument class, used both by actual Argument classes and constraints (ArgumentConstraint).
Definition: BaseArgument.hpp:40
bool matches() const
Returns a pointer to this argument if it matches as a positional argument, otherwise a null-pointer...
Definition: Argument.hpp:230
std::string m_description
Description or help text of argument.
Definition: Argument.hpp:59
Simple argument class.
Definition: Argument.hpp:48
void parse_description()
When TAP_AUTOFLAG is defined, this function finds flag and/or name markers in the description of the ...
Definition: Argument.hpp:444
unsigned int m_max
Maximum number of occurrences.
Definition: Argument.hpp:64
void find_all_arguments(std::vector< const Argument * > &collector) const override
See BaseArgument::find_all_arguments()
Definition: Argument.hpp:272
bool required() const
Returns whether the argument is required.
Definition: BaseArgument.hpp:119
ArgumentCheckFunc m_checkFunc
Callback for check.
Definition: Argument.hpp:70
Interface class for arguments that accept a value when takes_value() is true.
Definition: Argument.hpp:535
std::unique_ptr< BaseArgument > clone() const &override
See BaseArgument::clone().
Definition: Argument.hpp:408
Argument(std::string description)
Create an argument with flag and/or name set by description.
Definition: Argument.hpp:94
const std::string & description() const
Returns the description of this argument.
Definition: Argument.hpp:208
unsigned int max() const
Returns the maximum number of occurrences of this argument.
Definition: Argument.hpp:344
Argument & operator=(const Argument &other)=default
Argument assignment operator.
std::vector< std::string > m_names
Names this argument matches.
Definition: Argument.hpp:53
virtual ~Argument()
Argument destructor.
Definition: Argument.hpp:159
std::function< void(const Argument &)> ArgumentCheckFunc
Function pointer that is used by Argument::check().
Definition: Argument.hpp:36
Argument & alias(char flag)
An a flag alias for the argument.
Definition: Argument.hpp:177
Argument & alias(char flag, std::string name)
An both a flag and name alias for the argument.
Definition: Argument.hpp:198
unsigned int count() const override
See BaseArgument::count()
Definition: Argument.hpp:354
bool m_isPositional
True if used as positional argument.
Definition: Argument.hpp:56
unsigned int m_min
Minimum number of occurrences if argument is set.
Definition: Argument.hpp:62
virtual Argument & check(ArgumentCheckFunc checkFunc)
Set the check function to use.
Definition: Argument.hpp:216
virtual bool takes_value() const
Returns whether or not this argument requires a value when it occurs (see also set()).
Definition: Argument.hpp:380
Argument(std::string description, char flag)
Create an argument that is identified by a flag.
Definition: Argument.hpp:111
Argument & many(bool many=true)
Allow the argument to occur multiple times or not.
Definition: Argument.hpp:289
Argument & alias(std::string name)
An a name alias for the argument.
Definition: Argument.hpp:187
bool can_set() const
Returns whether this argument is still allowed to occur on the command line.
Definition: Argument.hpp:363
void check_valid() const override
See BaseArgument::check_valid()
std::string m_flags
Flags this arguments matches.
Definition: Argument.hpp:51
virtual void set(const std::string &value) const =0
Set the argument (mark as occurred), and assign a value to it.
virtual void check() const
Executes the associated check function.
Definition: Argument.hpp:423
BaseArgument & set_required(bool required=true)
Mark the argument as required or not.
Definition: BaseArgument.hpp:110
virtual void set() const
Set the argument (mark as occurred).
Definition: Argument.hpp:370