CPP-AP 2.7.0
Command-line argument parser for C++20
Loading...
Searching...
No Matches
argument_token.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
9#include "argument_base.hpp"
10#include "typing_utility.hpp"
11
12#include <cstdint>
13#include <functional>
14#include <optional>
15#include <string>
16
17namespace ap::detail {
18
22
24 enum class token_type : std::uint8_t {
27 t_value
28 };
29 using enum token_type;
30
36 bool operator==(const argument_token& other) const noexcept {
37 return this->type == other.type and this->value == other.value;
38 }
39
45 return this->type == t_flag_primary or this->type == t_flag_secondary;
46 }
47
58 return this->is_flag_token() and this->arg.has_value();
59 }
60
62 std::string value;
63 arg_ptr_opt_t arg = std::nullopt;
64};
65
66} // namespace ap::detail
Defines the base argument class and common utility.
std::optional< std::reference_wrapper< std::unique_ptr< T > > > uptr_opt_t
Structure representing a single command-line argument token.
token_type type
The token's type discrimiator value.
bool is_flag_token() const noexcept
Checks whether the type member is a flag token type.
arg_ptr_opt_t arg
The corresponding argument.
bool operator==(const argument_token &other) const noexcept
Equality operator for comparing argument_token instances.
std::string value
The actual token's value.
bool is_valid_flag_token() const noexcept
Checks whether the token represents a valid flag.
token_type
The token type discriminator.
@ t_value
Represents a value argument.
@ t_flag_secondary
Represents the secondary (-) flag argument.
@ t_flag_primary
Represents the primary (–) flag argument.
uptr_opt_t< detail::argument_base > arg_ptr_opt_t