Skip to content

Commit e4a3642

Browse files
committed
wip: cfg refinement
1 parent bb70df5 commit e4a3642

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

include/gl/vertex_descriptor.hpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,33 @@ namespace gl {
2525
///
2626
/// **Module:** Part of the @ref GL-Core "Core Graph Components" group.
2727
///
28-
/// The vertex_descriptor class provides a type-safe and efficient way to represent
28+
/// The `vertex_descriptor` class provides a type-safe and efficient way to represent
2929
/// vertices in graph structures. It acts as a lightweight wrapper that combines
3030
/// a unique identifier with optional property data, ensuring safe access and
3131
/// comparison operations.
32+
///
33+
/// > [!WARNING] This class is not intended to be instantiated directly.
34+
/// >
35+
/// > Instead, `vertex_descriptor` objects should be retrieved from the @ref gl::graph class instance that owns the given vertex.
36+
///
37+
/// ### Example Usage
38+
/// The following example demonstrates how to iterate over vertices in a graph,
39+
/// accessing both their structural IDs and their underlying custom properties:
40+
/// ```cpp
41+
/// for (auto v : graph.vertices()) {
42+
/// // Access the underlying structural ID
43+
/// std::cout << "Node ID: " << v.id() << " | ";
44+
///
45+
/// // Use the arrow operator to access/modify custom property fields
46+
/// if (v->parent == gl::invalid_id)
47+
/// std::cout << "ROOT | Level: " << v->level << "\n";
48+
/// else
49+
/// std::cout << "Parent: " << v->parent << " | Level: " << v->level << "\n";
50+
/// }
51+
/// ```
52+
///
53+
/// @tparam Properties The type of property data attached to the vertex. Defaults to `empty_properties`.
54+
/// @tparam IdType The underlying integer type used for the vertex ID. Defaults to `default_id_type`.
3255
template <
3356
traits::c_properties Properties = empty_properties,
3457
traits::c_id_type IdType = default_id_type>
@@ -47,23 +70,28 @@ class vertex_descriptor final {
4770
}
4871

4972
/// @brief Constructs a vertex descriptor with the given ID (for empty properties).
73+
/// @param id The unique identifier for the vertex.
5074
explicit vertex_descriptor(const id_type id)
5175
requires(traits::c_empty_properties<properties_type>)
5276
: _id(id) {}
5377

5478
/// @brief Constructs a vertex descriptor with the given ID and properties.
79+
/// @param id The unique identifier for the vertex.
80+
/// @param properties A reference to the property data to associate with this vertex.
5581
explicit vertex_descriptor(const id_type id, properties_type& properties)
5682
requires(traits::c_non_empty_properties<properties_type>)
5783
: _id(id), _properties(properties) {}
5884

5985
/// @brief Returns an invalid vertex descriptor (for empty properties).
86+
/// @return A `vertex_descriptor` holding the `invalid_id`.
6087
[[nodiscard]] gl_attr_force_inline static vertex_descriptor invalid() noexcept
6188
requires(traits::c_empty_properties<properties_type>)
6289
{
6390
return vertex_descriptor(invalid_id);
6491
}
6592

6693
/// @brief Returns an invalid vertex descriptor (for non-empty properties).
94+
/// @return A `vertex_descriptor` holding the `invalid_id` and empty properties.
6795
[[nodiscard]] gl_attr_force_inline static vertex_descriptor invalid() noexcept
6896
requires(traits::c_non_empty_properties<properties_type>)
6997
{
@@ -85,34 +113,43 @@ class vertex_descriptor final {
85113
~vertex_descriptor() = default;
86114

87115
/// @brief Equality comparison operator.
116+
/// @param other The vertex descriptor to compare against.
117+
/// @return `true` if both descriptors hold the same ID, `false` otherwise.
88118
[[nodiscard]] gl_attr_force_inline bool operator==(const vertex_descriptor& other
89119
) const noexcept {
90120
return this->_id == other._id;
91121
}
92122

93123
/// @brief Three-way comparison operator.
124+
/// @param other The vertex descriptor to compare against.
125+
/// @return The strong ordering result based on the underlying IDs.
94126
[[nodiscard]] gl_attr_force_inline std::strong_ordering operator<=>(
95127
const vertex_descriptor& other
96128
) const noexcept {
97129
return this->_id <=> other._id;
98130
}
99131

100-
/// @brief Boolean conversion operator, returns true if the vertex is valid.
132+
/// @brief Boolean conversion operator.
133+
/// @return `true` if the vertex is valid.
101134
[[nodiscard]] gl_attr_force_inline operator bool() const noexcept {
102135
return this->is_valid();
103136
}
104137

105138
/// @brief Checks if the vertex descriptor is valid.
139+
/// @return `true` if the ID is not equal to `invalid_id`.
106140
[[nodiscard]] gl_attr_force_inline bool is_valid() const noexcept {
107141
return this->_id != invalid_id;
108142
}
109143

110144
/// @brief Returns the vertex ID.
145+
/// @return The underlying integer ID of the vertex.
111146
[[nodiscard]] gl_attr_force_inline id_type id() const noexcept {
112147
return this->_id;
113148
}
114149

115150
/// @brief Returns a reference to the vertex properties.
151+
/// @return A reference to the associated `properties_type`.
152+
/// @throws std::logic_error If the vertex descriptor is invalid.
116153
[[nodiscard]] gl_attr_force_inline properties_type& properties() const
117154
requires(traits::c_non_empty_properties<properties_type>)
118155
{
@@ -121,6 +158,8 @@ class vertex_descriptor final {
121158
}
122159

123160
/// @brief Arrow operator for accessing properties.
161+
/// @return A pointer to the associated `properties_type`.
162+
/// @throws std::logic_error If the vertex descriptor is invalid.
124163
[[nodiscard]] gl_attr_force_inline properties_type* operator->() const
125164
requires(traits::c_non_empty_properties<properties_type>)
126165
{
@@ -129,6 +168,8 @@ class vertex_descriptor final {
129168
}
130169

131170
/// @brief Dereference operator for accessing properties.
171+
/// @return A reference to the associated `properties_type`.
172+
/// @throws std::logic_error If the vertex descriptor is invalid.
132173
[[nodiscard]] gl_attr_force_inline properties_type& operator*() const
133174
requires(traits::c_non_empty_properties<properties_type>)
134175
{
@@ -137,6 +178,9 @@ class vertex_descriptor final {
137178
}
138179

139180
/// @brief Output stream operator for vertex descriptors.
181+
/// @param os The output stream.
182+
/// @param vertex The vertex descriptor to write.
183+
/// @return A reference to the output stream.
140184
friend std::ostream& operator<<(std::ostream& os, const vertex_descriptor& vertex) {
141185
using enum io::detail::option_bit;
142186

mkdocs.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ nav:
1818
# - Overview: cpp-gl/group__hgl.md
1919
# - Algorithms: cpp-gl/group__hgl__alg.md
2020
- API Index:
21+
- Modules: cpp-gl/modules.md
2122
- Namespaces: cpp-gl/namespaces.md
2223
- Classes & Structs: cpp-gl/annotated.md
24+
- Class Hierarchy: cpp-gl/hierarchy.md
25+
# - Concepts: cpp-gl/concepts.md
2326
- Files: cpp-gl/files.md
24-
# TODO: Other sections (constants, functions, modules, etc...)
27+
- Todo List: cpp-gl/todo.md
28+
# - Bug List: cpp-gl/bug.md
29+
# - Deprecated: cpp-gl/deprecated.md
2530

2631
theme:
2732
name: material
@@ -33,6 +38,8 @@ theme:
3338
- navigation.expand
3439
- search.suggest
3540
- content.code.copy
41+
- content.code.select # TODO: use in example
42+
- content.code.annotate # TODO: use in example
3643
palette:
3744
- media: "(prefers-color-scheme: light)"
3845
scheme: default

0 commit comments

Comments
 (0)