CPP-AP 3.0.1
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
11#include <cstdint>
12#include <string>
13#include <vector>
14
15namespace ap::detail {
16
19 using arg_ptr_t = std::shared_ptr<detail::argument_base>;
20 using arg_ptr_vec_t = std::vector<arg_ptr_t>;
21
23 enum class token_type : std::uint8_t {
24 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
48 [[nodiscard]] bool is_flag_token() const noexcept {
49 switch (this->type) {
50 case t_flag_primary:
51 [[fallthrough]];
53 [[fallthrough]];
54 case t_flag_compound:
55 return true;
56 default:
57 return false;
58 }
59 }
60
70 [[nodiscard]] bool is_valid_flag_token() const noexcept {
71 return this->is_flag_token() and not this->args.empty();
72 }
73
75 std::string value;
77};
78
79} // namespace ap::detail
Defines the base argument class and common utility.
Structure representing a single command-line argument token.
std::vector< arg_ptr_t > arg_ptr_vec_t
arg_ptr_vec_t args
The corresponding argument.
std::shared_ptr< detail::argument_base > arg_ptr_t
Argument pointer type alias.
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.
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_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.