CPP-AP 3.0.1
Command-line argument parser for C++20
Loading...
Searching...
No Matches
argument_group.hpp
Go to the documentation of this file.
1// Copyright (c) 2023-2025 Jakub MusiaƂ
2// This file is part of the CPP-AP project (https://github.com/SpectraL519/cpp-ap).
3// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
4
6
7#pragma once
8
10
11#include <memory>
12
13namespace ap {
14
42public:
43 argument_group() = delete;
44
55 argument_group& required(const bool r = true) noexcept {
56 this->_required = r;
57 return *this;
58 }
59
70 argument_group& mutually_exclusive(const bool me = true) noexcept {
71 this->_mutually_exclusive = me;
72 return *this;
73 }
74
75 friend class argument_parser;
76
77private:
78 using arg_ptr_t = std::shared_ptr<detail::argument_base>;
79 using arg_ptr_vec_t = std::vector<arg_ptr_t>;
80
86 static std::unique_ptr<argument_group> create(argument_parser& parser, std::string_view name) {
87 return std::unique_ptr<argument_group>(new argument_group(parser, name));
88 }
89
91 argument_group(argument_parser& parser, const std::string_view name)
92 : _parser(&parser), _name(name) {}
93
95 void _add_argument(arg_ptr_t arg) noexcept {
96 this->_arguments.emplace_back(std::move(arg));
97 }
98
100 std::string _name;
102
103 bool _required : 1 = false;
105 false;
106};
107
108} // namespace ap
Defines the base argument class and common utility.
Represents a group of arguments.
std::shared_ptr< detail::argument_base > arg_ptr_t
The argument pointer type alias.
arg_ptr_vec_t _arguments
A list of arguments that belong to this group.
std::string _name
Name of the group (used in help output).
argument_group & mutually_exclusive(const bool me=true) noexcept
Set the mutually_exclusive attribute of the group.
argument_group & required(const bool r=true) noexcept
Set the required attribute of the group.
void _add_argument(arg_ptr_t arg) noexcept
Add a new argument to this group (called internally by parser).
argument_parser * _parser
Pointer to the owning parser.
static std::unique_ptr< argument_group > create(argument_parser &parser, std::string_view name)
Factory method to create an argument group.
bool _mutually_exclusive
The mutually exclusive attribute value (default: false).
argument_group(argument_parser &parser, const std::string_view name)
Construct a new argument group with the given name.
argument_group()=delete
bool _required
The required attribute value (default: false).
std::vector< arg_ptr_t > arg_ptr_vec_t
The argument pointer list type alias.
The main argument parser class.