44 std::optional<std::string>
primary,
45 std::optional<std::string>
secondary = std::nullopt,
46 std::optional<char>
flag_char = std::nullopt
51 if (not (this->primary or this->
secondary))
52 throw std::logic_error(
"An argument name cannot be empty! At least one of "
53 "primary/secondary must be specified");
65 return this->
primary == other.primary and this->
secondary == other.secondary;
80 return this->
primary == arg_name;
82 return this->secondary == arg_name;
97 if (arg_name.primary and this->match(arg_name.primary.value()))
100 if (arg_name.secondary)
101 return this->
match(arg_name.secondary.value());
110 [[nodiscard]] std::string
str() const noexcept {
112 const std::string fc(this->
flag_char.has_value(), this->flag_char.value_or(
char()));
114 std::string primary_str =
115 this->
primary ? std::format(
"{}{}{}", fc, fc, this->
primary.value()) :
"";
117 std::string secondary_str =
120 return std::format(
"{}{}{}", primary_str, separator, secondary_str);
130 os << arg_name.str();
argument_name_discriminator
Argument name member discriminator.
@ n_secondary
Represents the secondary name (used with a short flag prefix –).
@ n_primary
Represents the primary name (used with a long flag prefix –).
Structure holding the argument's name.
argument_name & operator=(const argument_name &)=delete
std::string str() const noexcept
Get a string representation of the argument_name.
bool match(const argument_name &arg_name, const match_type m_type=m_any) const noexcept
Matches the given argument name to the argument_name instance.
const std::optional< char > flag_char
The flag character (used for optional argument names).
bool operator==(const argument_name &other) const noexcept
Equality comparison operator.
argument_name(std::optional< std::string > primary, std::optional< std::string > secondary=std::nullopt, std::optional< char > flag_char=std::nullopt)
Primary and secondary name constructor.
const std::optional< std::string > secondary
The optional (short) name of the argument.
match_type
Specifies the type of argument name match.
@ m_any
Matches either the primary or the secondary name.
@ m_primary
Matches only the primary name.
@ m_secondary
Matches only the secondary name.
~argument_name()=default
Class destructor.
argument_name & operator=(argument_name &&)=delete
const std::optional< std::string > primary
The primary name of the argument.
argument_name(argument_name &&)=default
bool match(std::string_view arg_name, const match_type m_type=m_any) const noexcept
Matches the given string to the argument_name instance.
argument_name(const argument_name &)=default
friend std::ostream & operator<<(std::ostream &os, const argument_name &arg_name) noexcept
Stream insertion operator for argument names.