CPP-ARGON 4.0.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-2026 Jakub Musiał
2// This file is part of the CPP-ARGON project (https://github.com/SpectraL519/cpp-argon).
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 <cstdint>
12#include <memory>
13#include <string>
14#include <vector>
15
16namespace argon::detail {
17
20 using arg_ptr_t = std::shared_ptr<detail::argument_base>;
21 using arg_ptr_vec_t = std::vector<arg_ptr_t>;
22
24 enum class token_type : std::uint8_t {
25 t_value,
29 };
30 using enum token_type;
31
37 bool operator==(const argument_token& other) const noexcept {
38 return this->type == other.type and this->value == other.value;
39 }
40
49 [[nodiscard]] bool is_flag_token() const noexcept {
50 switch (this->type) {
51 case t_flag_primary:
52 [[fallthrough]];
54 [[fallthrough]];
55 case t_flag_compound:
56 return true;
57 default:
58 return false;
59 }
60 }
61
71 [[nodiscard]] bool is_valid_flag_token() const noexcept {
72 return this->is_flag_token() and not this->args.empty();
73 }
74
76 std::string value;
78};
79
80} // namespace argon::detail
Defines the base argument class and common utility.
Structure representing a single command-line argument token.
std::shared_ptr< detail::argument_base > arg_ptr_t
Argument pointer type alias.
std::vector< arg_ptr_t > arg_ptr_vec_t
arg_ptr_vec_t args
The corresponding argument.
bool operator==(const argument_token &other) const noexcept
Equality operator for comparing argument_token instances.
token_type
The token type discriminator.
@ t_flag_compound
Represents a compound flag argument (secondary flag matching multiple arguments).
@ t_value
Represents a value argument.
@ t_flag_secondary
Represents a secondary (-) flag argument.
@ t_flag_primary
Represents a primary (–) flag argument.
bool is_valid_flag_token() const noexcept
Checks whether the token represents a valid flag.
bool is_flag_token() const noexcept
Checks whether the type member is a flag token type.
token_type type
The token's type discrimiator value.
std::string value
The actual token's value.