|
2 | 2 | // This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl). |
3 | 3 | // Licensed under the MIT License. See the LICENSE file in the project root for full license information. |
4 | 4 |
|
| 5 | +/// @file gl/constants.hpp |
| 6 | +/// @brief Defines common constant values and types used across the CPP-GL library. |
| 7 | + |
5 | 8 | #pragma once |
6 | 9 |
|
7 | 10 | #include "gl/types/core.hpp" |
|
10 | 13 |
|
11 | 14 | namespace gl { |
12 | 15 |
|
| 16 | +/// @ingroup GL GL-Core |
| 17 | +/// @brief A constant representing the initial ID value of 0 for graph elements. |
| 18 | +/// @tparam IdType The type of the ID, which must satisfy the [**c_id_type**](gl_traits.md#gl-traits-c-id-type) concept. |
| 19 | +/// ### See Also |
| 20 | +/// - [**c_id_type**](gl_traits.md#gl-traits-c-id-type) |
| 21 | +/// - @ref gl::initial_id_t "initial_id_t" |
| 22 | +/// - @ref gl::initial_id "initial_id" |
13 | 23 | template <traits::c_id_type IdType> |
14 | 24 | inline constexpr IdType initial_id_v{0}; |
15 | 25 |
|
| 26 | +/// @ingroup GL GL-Core |
| 27 | +/// @brief A helper type that can be implicitly converted to the initial ID value of 0 for any valid ID type. |
| 28 | +/// ### See Also |
| 29 | +/// - [**c_id_type**](gl_traits.md#gl-traits-c-id-type) |
| 30 | +/// - @ref gl::initial_id_v "initial_id_v" |
| 31 | +/// - @ref gl::initial_id "initial_id" |
16 | 32 | struct initial_id_t { |
| 33 | + /// @brief Implicitly converts to the initial ID value of 0 for any type that satisfies the [**c_id_type**](gl_traits.md#gl-traits-c-id-type) concept. |
17 | 34 | template <traits::c_id_type IdType> |
18 | 35 | [[nodiscard]] constexpr operator IdType() const noexcept { |
19 | 36 | return initial_id_v<IdType>; |
20 | 37 | } |
21 | 38 | }; |
22 | 39 |
|
| 40 | +/// @ingroup GL GL-Core |
| 41 | +/// @brief A constant instance of `initial_id_t` that can be used to represent the initial ID value of 0 for graph elements in a type-safe manner. |
| 42 | +/// |
| 43 | +/// ### Example Usage |
| 44 | +/// ```cpp |
| 45 | +/// using vertex_id_t = std::uint32_t; |
| 46 | +/// vertex_id_t v1 = gl::initial_id; // (1)! |
| 47 | +/// ``` |
| 48 | +/// |
| 49 | +/// 1\. The `initial_id` constant can be implicitly converted to the `v1`'s type (`vertex_id_t`), resulting in `v1` being initialized to the value of 0. |
| 50 | +/// |
| 51 | +/// ### See Also |
| 52 | +/// - [**c_id_type**](gl_traits.md#gl-traits-c-id-type) |
| 53 | +/// - @ref gl::initial_id_v "initial_id_v" |
| 54 | +/// - @ref gl::initial_id_t "initial_id_t" |
23 | 55 | inline constexpr initial_id_t initial_id{}; |
24 | 56 |
|
25 | 57 | // --- invalid id --- |
26 | 58 |
|
| 59 | +/// @ingroup GL GL-Core |
| 60 | +/// @brief A constant representing the invalid ID value for graph elements, defined as the maximum value of the specified ID type. |
| 61 | +/// @tparam IdType The type of the ID, which must satisfy the [**c_id_type**](gl_traits.md#gl-traits-c-id-type) concept. |
| 62 | +/// ### See Also |
| 63 | +/// - [**c_id_type**](gl_traits.md#gl-traits-c-id-type) |
| 64 | +/// - @ref gl::invalid_id_t "invalid_id_t" |
| 65 | +/// - @ref gl::invalid_id "invalid_id" |
27 | 66 | template <traits::c_id_type IdType> |
28 | 67 | inline constexpr IdType invalid_id_v{std::numeric_limits<IdType>::max()}; |
29 | 68 |
|
| 69 | +/// @ingroup GL GL-Core |
| 70 | +/// @brief A helper type that can be implicitly converted to the invalid ID value for any valid ID type. |
| 71 | +/// ### See Also |
| 72 | +/// - [**c_id_type**](gl_traits.md#gl-traits-c-id-type) |
| 73 | +/// - @ref gl::invalid_id_v "invalid_id_v" |
| 74 | +/// - @ref gl::invalid_id "invalid_id" |
30 | 75 | struct invalid_id_t { |
| 76 | + /// @brief Implicitly converts to the invalid ID value for any type that satisfies the [**c_id_type**](gl_traits.md#gl-traits-c-id-type) concept. |
31 | 77 | template <traits::c_id_type IdType> |
32 | 78 | [[nodiscard]] constexpr operator IdType() const noexcept { |
33 | 79 | return invalid_id_v<IdType>; |
34 | 80 | } |
35 | 81 |
|
| 82 | + /// @brief Equality comparison operator to compare an ID value with the invalid ID constant. |
| 83 | + /// |
| 84 | + /// This operator allows for direct comparison between an ID value and the `invalid_id` constant, |
| 85 | + /// enabling easy checking if a given ID is invalid without needing to explicitly reference |
| 86 | + /// the `invalid_id_v` constant for the specific ID type. |
| 87 | + /// |
| 88 | + /// @tparam IdType The type of the ID, which must satisfy the [**c_id_type**](gl_traits.md#gl-traits-c-id-type) concept. |
| 89 | + /// @param lhs The ID value to compare againsyt the invalid ID constant. |
| 90 | + /// @param rhs The `invalid_id` constant (of type `invalid_id_t`) to compare with the ID value. |
| 91 | + /// @return Returns `true` if `lhs` is equal to the invalid ID value for its type, and `false` otherwise. |
36 | 92 | template <traits::c_id_type IdType> |
37 | 93 | [[nodiscard]] friend constexpr bool operator==(const IdType& lhs, invalid_id_t) noexcept { |
38 | 94 | return lhs == invalid_id_v<IdType>; |
39 | 95 | } |
40 | 96 | }; |
41 | 97 |
|
| 98 | +/// @ingroup GL GL-Core |
| 99 | +/// @brief A constant instance of `invalid_id_t` that can be used to represent the invalid ID value for graph elements in a type-safe manner. |
| 100 | +/// |
| 101 | +/// ### Example Usage |
| 102 | +/// ```cpp |
| 103 | +/// using vertex_id_t = std::uint32_t; |
| 104 | +/// vertex_id_t v1 = gl::invalid_id; // (1)! |
| 105 | +/// ``` |
| 106 | +/// |
| 107 | +/// 1\. The `invalid_id` constant can be implicitly converted to the `v1`'s type (`vertex_id_t`), resulting in `v1` being initialized to the maximum value of `vertex_id_t`, which represents an invalid ID. |
| 108 | +/// |
| 109 | +/// ### See Also |
| 110 | +/// - [**c_id_type**](gl_traits.md#gl-traits-c-id-type) |
| 111 | +/// - @ref gl::invalid_id_v "invalid_id_v" |
| 112 | +/// - @ref gl::invalid_id_t "invalid_id_t" |
42 | 113 | inline constexpr invalid_id_t invalid_id{}; |
43 | 114 |
|
44 | 115 | } // namespace gl |
0 commit comments