Skip to content

Commit 65b7311

Browse files
committed
io docs
1 parent f90082d commit 65b7311

6 files changed

Lines changed: 188 additions & 42 deletions

File tree

include/gl/io/graph_fio.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ requires(std::same_as<Mode, append>)
118118
/// Saves the graph topology and optionally its properties using the Graph Specification Format (GSF).
119119
/// The function strictly respects the @ref gl::io::write "write" and @ref gl::io::append "append" safety guards.
120120
///
121-
/// @tparam GraphType The underlying type of the graph being saved.
121+
/// @tparam GraphType The concrete type of the graph being saved. Must satisfy [**c_graph**](gl_concepts.md#hgl-traits-c-graph).
122122
/// @tparam Mode The save behavior tag (@ref gl::io::write "write" or @ref gl::io::append "append"). Defaults to `write`.
123123
/// @param graph The graph instance to serialize.
124124
/// @param path The filesystem path where the graph will be saved. Defaults to `"graph.gsf"`.
@@ -146,14 +146,14 @@ void save(
146146
///
147147
/// Instantiates a new graph populated with the topology and properties read from the target GSF file.
148148
///
149-
/// @tparam GraphType The target graph type to construct. Must match the directional nature of the saved file.
150-
/// @param path The filesystem path from which to load the graph. Defaults to `"graph.gsf"`.
149+
/// @tparam GraphType The target graph type to construct. Must match the directional nature of the saved graph.
150+
/// @param path The filesystem path from which to load the graph.
151151
/// @return A newly constructed graph populated with the file's data.
152152
///
153153
/// @throws std::filesystem::filesystem_error If the file does not exist or is not a standard file.
154154
/// @throws std::ios_base::failure If the file cannot be opened or if the GSF directional discriminator mismatches `GraphType`.
155155
template <traits::c_graph GraphType>
156-
[[nodiscard]] GraphType load(const std::filesystem::path& path = "graph.gsf") {
156+
[[nodiscard]] GraphType load(const std::filesystem::path& path) {
157157
std::ifstream file = detail::open_infile(path);
158158

159159
file >> spec_fmt;

include/hgl/io.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl).
33
// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
44

5+
/// @file hgl/io.hpp
6+
/// @brief Includes all I/O-related headers for hypergraph file operations.
7+
58
#pragma once
69

710
#include "hgl/io/core.hpp"

include/hgl/io/core.hpp

Lines changed: 101 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl).
33
// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
44

5+
/// @file hgl/io/core.hpp
6+
/// @brief Core I/O utilities, stream manipulators, and range formatters for hypergraphs.
7+
58
#pragma once
69

710
#include "gl/io/options.hpp"
@@ -13,16 +16,56 @@
1316

1417
namespace hgl::io {
1518

19+
/// @ingroup HGL-IO
20+
/// @copybrief gl::io::range_formatter
21+
/// @see gl::io::range_formatter
22+
template <std::ranges::range R>
23+
using range_formatter = gl::io::range_formatter<R>;
24+
25+
/// @ingroup HGL-IO
26+
/// @copybrief gl::io::implicit_range
27+
/// @see gl::io::implicit_range
1628
using gl::io::implicit_range;
17-
using gl::io::implicit_range_formatter;
18-
using gl::io::multiline_set_formatter;
19-
using gl::io::range_formatter;
29+
30+
/// @ingroup HGL-IO
31+
/// @copybrief gl::io::implicit_range_formatter
32+
/// @see gl::io::implicit_range_formatter
33+
template <std::integral T>
34+
using implicit_range_formatter = gl::io::implicit_range_formatter<T>;
35+
36+
/// @ingroup HGL-IO
37+
/// @copybrief gl::io::set_formatter
38+
/// @see gl::io::set_formatter
2039
using gl::io::set_formatter;
2140

41+
/// @ingroup HGL-IO
42+
/// @copybrief gl::io::multiline_set_formatter
43+
/// @see gl::io::multiline_set_formatter
44+
using gl::io::multiline_set_formatter;
45+
46+
/// @ingroup HGL-IO
47+
/// @copybrief gl::io::are_options_set
48+
/// @see gl::io::are_options_set
2249
using gl::io::are_options_set;
50+
51+
/// @ingroup HGL-IO
52+
/// @copybrief gl::io::clear_options
53+
/// @see gl::io::clear_options
2354
using gl::io::clear_options;
55+
56+
/// @ingroup HGL-IO
57+
/// @copybrief gl::io::is_option_set
58+
/// @see gl::io::is_option_set
2459
using gl::io::is_option_set;
25-
using gl::io::options_manip;
60+
61+
/// @ingroup HGL-IO
62+
/// @copybrief gl::io::options_manip
63+
/// @see gl::io::options_manip
64+
using options_manip = gl::io::options_manip;
65+
66+
/// @ingroup HGL-IO
67+
/// @copybrief gl::io::set_options
68+
/// @see gl::io::set_options
2669
using gl::io::set_options;
2770

2871
namespace detail {
@@ -32,21 +75,65 @@ using gl::io::detail::option_bit;
3275

3376
} // namespace detail
3477

35-
using gl::io::concise;
36-
using gl::io::spec_fmt;
37-
using gl::io::verbose;
78+
/// @ingroup HGL-IO
79+
/// @brief @ref hgl::io::options_manip "Stream manipulator" to enable concise hypergraph formatting.
80+
///
81+
/// Clears all layout-specific flags to default back to a compact representation.
82+
///
83+
/// @hideinitializer
84+
inline constexpr options_manip concise = gl::io::concise;
85+
86+
/// @ingroup HGL-IO
87+
/// @brief @ref hgl::io::options_manip "Stream manipulator" to enable verbose hypergraph formatting.
88+
///
89+
/// Modifies the stream state to output detailed structural information.
90+
///
91+
/// @hideinitializer
92+
inline constexpr options_manip spec_fmt = gl::io::spec_fmt;
3893

39-
using gl::io::with_vertex_properties;
40-
using gl::io::without_vertex_properties;
94+
/// @ingroup HGL-IO
95+
/// @brief @ref hgl::io::options_manip "Stream manipulator" to enable the Hypergraph Specification Format (HGSF).
96+
///
97+
/// Modifies the stream to output or expect data matching the precise internal parsing format used for serialization and deserialization.
98+
///
99+
/// @hideinitializer
100+
inline constexpr options_manip verbose = gl::io::verbose;
41101

42-
inline const options_manip with_hyperedge_properties =
102+
/// @ingroup HGL-IO
103+
/// @brief @ref hgl::io::options_manip "Stream manipulator" to enable the processing of vertex properties.
104+
/// @hideinitializer
105+
inline constexpr options_manip with_vertex_properties = gl::io::with_vertex_properties;
106+
107+
/// @ingroup HGL-IO
108+
/// @brief @ref hgl::io::options_manip "Stream manipulator" to disable the processing of vertex properties.
109+
/// @hideinitializer
110+
inline constexpr options_manip without_vertex_properties = gl::io::without_vertex_properties;
111+
112+
/// @ingroup HGL-IO
113+
/// @brief @ref hgl::io::options_manip "Stream manipulator" to enable the processing of hyperedge properties.
114+
/// @hideinitializer
115+
inline constexpr options_manip with_hyperedge_properties =
43116
set_options(detail::option_bit::with_connection_properties);
44-
inline const options_manip without_hyperedge_properties =
117+
118+
/// @ingroup HGL-IO
119+
/// @brief @ref hgl::io::options_manip "Stream manipulator" to disable the processing of hyperedge properties.
120+
/// @hideinitializer
121+
inline constexpr options_manip without_hyperedge_properties =
45122
clear_options(detail::option_bit::with_connection_properties);
46123

47-
using gl::io::with_properties;
48-
using gl::io::without_properties;
124+
/// @ingroup HGL-IO
125+
/// @brief @ref hgl::io::options_manip "Stream manipulator" to enable the processing of both vertex and hyperedge properties simultaneously.
126+
/// @hideinitializer
127+
inline constexpr options_manip with_properties = gl::io::with_properties;
128+
129+
/// @ingroup HGL-IO
130+
/// @brief @ref hgl::io::options_manip "Stream manipulator" to disable the processing of both vertex and hyperedge properties simultaneously.
131+
/// @hideinitializer
132+
inline constexpr options_manip without_properties = gl::io::without_properties;
49133

50-
using gl::io::default_options;
134+
/// @ingroup HGL-IO
135+
/// @brief @ref hgl::io::options_manip "Stream manipulator" to reset all custom graph formatting flags back to their default states.
136+
/// @hideinitializer
137+
inline constexpr options_manip default_options = gl::io::default_options;
51138

52139
} // namespace hgl::io

include/hgl/io/hypergraph_fio.hpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl).
33
// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
44

5+
/// @file hgl/io/hypergraph_fio.hpp
6+
/// @brief File I/O utilities for safely saving and loading hypergraphs to and from files.
7+
58
#pragma once
69

710
#include "gl/io/graph_fio.hpp"
@@ -15,8 +18,15 @@
1518

1619
namespace hgl::io {
1720

18-
using gl::io::append;
19-
using gl::io::write;
21+
/// @ingroup HGL-IO
22+
/// @copybrief gl::io::append
23+
/// @copydetails gl::io::append
24+
using append = gl::io::append;
25+
26+
/// @ingroup HGL-IO
27+
/// @copybrief gl::io::write
28+
/// @copydetails gl::io::write
29+
using write = gl::io::write;
2030

2131
namespace detail {
2232

@@ -25,6 +35,19 @@ using gl::io::detail::open_outfile;
2535

2636
} // namespace detail
2737

38+
/// @ingroup HGL-IO
39+
/// @brief Serializes and saves a hypergraph to a file.
40+
///
41+
/// Writes the topology and optionally the properties of the hypergraph to the specified file using the Hypergraph Specification Format (HGSF). By default,
42+
/// The function strictly respects the @ref hgl::io::write "write" and @ref hgl::io::append "append" safety guards.
43+
///
44+
/// @tparam HypergraphType The concrete type of the hypergraph being saved. Must satisfy [**c_hypergraph**](hgl_concepts.md#hgl-traits-c-hypergraph).
45+
/// @tparam Mode The file access mode (e.g., @ref hgl::io::write "write" or @ref hgl::io::append "append").
46+
/// @param hypergraph The hypergraph instance to serialize.
47+
/// @param path The filesystem path where the hypergraph will be saved. Defaults to `"hypergraph.hgsf"`.
48+
/// @param options An optional initializer list of stream manipulators to configure the output (e.g., `{hgl::io::with_properties}`).
49+
/// @throws std::filesystem::filesystem_error If file safety checks fail (e.g., overwriting an existing file in `write` mode).
50+
/// @throws std::ios_base::failure If the underlying file stream cannot be opened.
2851
template <traits::c_hypergraph HypergraphType, traits::c_io_save_mode Mode = write>
2952
void save(
3053
const HypergraphType& hypergraph,
@@ -40,8 +63,19 @@ void save(
4063
file << hypergraph;
4164
}
4265

66+
/// @ingroup HGL-IO
67+
/// @brief Deserializes and loads a hypergraph from a file.
68+
///
69+
/// Instantiates a new hypergraph populated with the topology and properties read from the target HGSF file.
70+
///
71+
/// @tparam HypergraphType The target hypergraph type to construct. Must match the directional nature of the saved hypergraph.
72+
/// @param path The filesystem path from which to load the hypergraph.
73+
/// @return A newly constructed hypergraph populated with the file's data.
74+
///
75+
/// @throws std::filesystem::filesystem_error If the file does not exist or is not a regular file.
76+
/// @throws std::ios_base::failure If the file cannot be opened or if the HGSF directional discriminator mismatches `HypergraphType`.
4377
template <traits::c_hypergraph HypergraphType>
44-
[[nodiscard]] HypergraphType load(const std::filesystem::path& path = "hypergraph.hgsf") {
78+
[[nodiscard]] HypergraphType load(const std::filesystem::path& path) {
4579
std::ifstream file = detail::open_infile(path);
4680

4781
file >> gl::io::spec_fmt;

include/hgl/traits.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ namespace hgl {
1919
/// and metaprogramming utilities from `gl::traits`. Because hypergraphs share the same underlying
2020
/// implementation design and mechanisms as standard graphs, they seamlessly reuse the same
2121
/// fundamental C++20 concepts.
22+
///
23+
/// > [!NOTE]
24+
/// >
25+
/// > To get a detailed overview of these shared utilities, please refer to the GL module's @ref GL-Traits documentation page.
2226
namespace traits {
2327

2428
using namespace gl::traits;

include/hgl/util.hpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,54 @@
99

1010
#include "gl/util/ranges.hpp"
1111

12-
namespace hgl::util {
12+
namespace hgl {
1313

1414
/// @ingroup HGL-Util
15-
/// @brief @copybrief gl::util::range_size
16-
/// @see gl::util::range_size
17-
using gl::util::range_size;
18-
19-
/// @ingroup HGL-Util
20-
/// @brief @copybrief gl::util::is_constant
21-
/// @see gl::util::is_constant
22-
using gl::util::is_constant;
15+
/// @brief General utilities, ranges, and helpers for the HGL module (originating in the GL module).
16+
///
17+
/// This namespace pulls in practical, domain-agnostic C++ **range** utilities from `gl::util`.
18+
/// Because hypergraphs share the same underlying memory models and algorithmic requirements as
19+
/// standard graphs, they seamlessly reuse the same fundamental C++20 range utilities and helpers.
20+
///
21+
/// > [!NOTE]
22+
/// >
23+
/// > To get a detailed overview of these shared utilities, please refer to the GL module's @ref GL-Util documentation page.
24+
namespace util {
2325

24-
/// @ingroup HGL-Util
25-
/// @brief @copybrief gl::util::all_equal
26-
/// @see gl::util::all_equal
2726
using gl::util::all_equal;
27+
using gl::util::is_constant;
28+
using gl::util::range_size;
2829

2930
/// @ingroup HGL-Util
3031
/// @brief @copybrief gl::util::concat_view
31-
/// @see gl::util::concat_view
32-
using gl::util::concat_view;
32+
/// @see gl::util::concat_view for the full type definition
33+
template <std::ranges::view V1, std::ranges::view V2>
34+
using concat_view = gl::util::concat_view<V1, V2>;
3335

3436
/// @ingroup HGL-Util
3537
/// @brief @copybrief gl::util::concat_fn
36-
/// @see gl::util::concat_fn
37-
using gl::util::concat_fn;
38+
/// @see gl::util::concat_fn for the full type definition
39+
using concat_fn = gl::util::concat_fn;
3840

3941
/// @ingroup HGL-Util
40-
/// @brief @copybrief gl::util::concat
41-
/// @see gl::util::concat
42-
using gl::util::concat;
43-
44-
} // namespace hgl::util
42+
/// @brief Concatenates two viewable ranges into a `concat_view`.
43+
///
44+
/// ### Example usage
45+
/// ```cpp
46+
/// std::vector<int> v1 = {1, 2, 3};
47+
/// std::vector<int> v2 = {4, 5, 6};
48+
/// auto concatenated = gl::util::concat(v1, v2);
49+
/// for (int x : concatenated)
50+
/// std::cout << x << " "; // Output: 1 2 3 4 5 6
51+
/// ```
52+
///
53+
/// @param r1 First range to concatenate.
54+
/// @param r2 Second range to concatenate.
55+
/// @todo Replace with `std::views::concat` (C++26).
56+
/// ### See Also
57+
/// - @ref hgl::util::concat_view "concat_view": The view type that represents the concatenation of two ranges.
58+
/// - @ref hgl::util::concat_fn "concat_fn": A helper compile-time constant function object for creating `concat_view` instances.
59+
inline constexpr concat_fn concat{};
60+
61+
} // namespace util
62+
} // namespace hgl

0 commit comments

Comments
 (0)