1#ifndef KOUTIL_ARGPARSER_ARG_H
2#define KOUTIL_ARGPARSER_ARG_H
24concept is_arg = std::is_same_v<Arg, std::decay_t<T>>;
72 assert(opt !=
'\0' && !
long_name.empty());
105 constexpr Arg(
Type arg_type,
char sname, std::string_view lname, std::string_view desc)
115 [[nodiscard]]
constexpr virtual std::size_t
size()
const = 0;
119 [[nodiscard]]
constexpr virtual const Arg*
find_long(std::string_view name)
const = 0;
120 [[nodiscard]]
constexpr virtual std::span<const Arg>
args()
const = 0;
138 using args_ref_t = std::pair<std::size_t, std::array<std::size_t,
sizeof...(Args)>>;
142 :
m_args({ (std::forward<decltype(args)>(
args))... }) {
156 [[nodiscard]]
constexpr std::size_t
size()
const override {
return sizeof...(Args); }
181 for (
auto i : view) {
182 if (
m_args[i].short_name == name) {
196 [[nodiscard]]
constexpr const Arg*
find_long(std::string_view name)
const override {
199 for (
auto i : view) {
200 if (
m_args[i].long_name == name) {
213 [[nodiscard]]
constexpr std::span<const Arg>
args()
const override {
return m_args; }
221 for (std::size_t i = 0; i <
m_args.size(); ++i) {
224 if (arg.short_name !=
'\0') {
226 }
else if (!arg.long_name.empty()) {
243 std::span view(search.second.begin(), search.first);
245 for (
auto it = view.begin(); it != view.end(); ++it) {
246 const auto& arg =
m_args[*it];
248 for (
auto it2 = it + 1; it2 != view.end(); ++it2) {
249 const auto& other =
m_args[*it2];
251 if (arg.*member == other.*member) {
virtual constexpr std::span< const Arg > args() const =0
virtual constexpr const Arg * find_short(char name) const =0
virtual constexpr std::size_t size() const =0
virtual constexpr const Arg * find_long(std::string_view name) const =0
virtual constexpr std::size_t count_short_args() const =0
virtual constexpr std::size_t count_long_args() const =0
virtual constexpr ~ArgumentsBase()=default
Base class for argument collections.
Definition arg.h:135
constexpr const Arg * find_long(std::string_view name) const override
Finds an argument by its long name.
Definition arg.h:196
args_ref_t m_long_args
Definition arg.h:218
constexpr std::size_t size() const override
Gets the number of arguments.
Definition arg.h:156
args_ref_t m_short_args
Definition arg.h:217
constexpr std::size_t count_long_args() const override
Gets the number of long arguments.
Definition arg.h:170
std::pair< std::size_t, std::array< std::size_t, sizeof...(Args)> > args_ref_t
Definition arg.h:138
~Arguments() override=default
std::array< Arg, sizeof...(Args)> args_t
Definition arg.h:137
constexpr bool contains_duplicates(const args_ref_t &search, Proj member)
Checks if there are duplicate arguments.
Definition arg.h:242
constexpr void create_refs()
Definition arg.h:220
args_t m_args
Definition arg.h:216
constexpr const Arg * find_short(char name) const override
Finds an argument by its short name.
Definition arg.h:178
constexpr Arguments(const Args &... args)
Definition arg.h:141
constexpr std::size_t count_short_args() const override
Gets the number of short arguments.
Definition arg.h:163
constexpr std::span< const Arg > args() const override
Gets a span of all arguments.
Definition arg.h:213
Checks if a type is derived from ArgumentsBase.
Definition arg.h:130
Checks if a type is Arg.
Definition arg.h:24
Base structure representing a subcommand argument.
Definition arg.h:29
constexpr bool operator==(const Arg &other) const
Definition arg.h:88
static constexpr Arg option_value(std::string_view long_name, std::string_view desc)
Constructs an argument of type OPTION_VALUE with a long name and description.
Definition arg.h:83
constexpr bool operator==(char name) const
Definition arg.h:100
const std::string_view long_name
Definition arg.h:36
constexpr Arg(Type arg_type, char sname, std::string_view lname, std::string_view desc)
Definition arg.h:105
constexpr bool operator>(char name) const
Definition arg.h:96
enum koutil::argparser::Arg::Type type
const char short_name
Definition arg.h:35
const std::string_view description
Definition arg.h:37
constexpr bool operator==(std::string_view name) const
Definition arg.h:102
constexpr bool operator>(std::string_view name) const
Definition arg.h:98
static constexpr Arg option_flag(char opt, std::string_view long_name, std::string_view desc)
Constructs an argument of type OPTION_FLAG with both short and long names and a description.
Definition arg.h:71
static constexpr Arg option_flag(std::string_view long_name, std::string_view desc)
Constructs an argument of type OPTION_FLAG with a long name and description.
Definition arg.h:58
constexpr bool operator<(char name) const
Definition arg.h:92
@ OPTION_FLAG
Definition arg.h:31
@ OPTION_VALUE
Definition arg.h:32
constexpr bool operator<(std::string_view name) const
Definition arg.h:94
static constexpr Arg option_flag(char opt, std::string_view desc)
Constructs an argument of type OPTION_FLAG with a short name and description.
Definition arg.h:46