Skip to content

Commit 452f9f5

Browse files
committed
wip: io docs
1 parent da9996d commit 452f9f5

4 files changed

Lines changed: 291 additions & 5 deletions

File tree

include/gl/io/options.hpp

Lines changed: 34 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 gl/io/options.hpp
6+
/// @brief Pre-defined stream manipulators for configuring graph I/O formatting.
7+
58
#pragma once
69

710
#include "gl/io/options_manip.hpp"
@@ -22,31 +25,62 @@ inline constexpr iword_type layout_options_mask =
2225

2326
} // namespace detail
2427

28+
/// @ingroup GL GL-IO
29+
/// @brief @ref gl::io::options_manip "Stream manipulator" to enable concise graph formatting.
30+
///
31+
/// Clears all layout-specific flags to default back to a compact representation.
2532
inline constexpr options_manip concise{0ul, detail::layout_options_mask};
33+
34+
/// @ingroup GL GL-IO
35+
/// @brief @ref gl::io::options_manip "Stream manipulator" to enable verbose graph formatting.
36+
///
37+
/// Modifies the stream state to output detailed structural information.
2638
inline constexpr options_manip verbose{
2739
detail::build_mask(detail::option_bit::verbose), detail::layout_options_mask
2840
};
41+
42+
/// @ingroup GL GL-IO
43+
/// @brief @ref gl::io::options_manip "Stream manipulator" to enable the Graph Specification Format (GSF).
44+
///
45+
/// Modifies the stream to output or expect data matching the precise internal parsing format used for serialization and deserialization.
2946
inline constexpr options_manip spec_fmt{
3047
detail::build_mask(detail::option_bit::spec_fmt), detail::layout_options_mask
3148
};
3249

50+
/// @ingroup GL GL-IO
51+
/// @brief @ref gl::io::options_manip "Stream manipulator" to enable the processing of vertex properties.
3352
inline constexpr options_manip with_vertex_properties =
3453
set_options(detail::option_bit::with_vertex_properties);
54+
55+
/// @ingroup GL GL-IO
56+
/// @brief @ref gl::io::options_manip "Stream manipulator" to disable the processing of vertex properties.
3557
inline constexpr options_manip without_vertex_properties =
3658
clear_options(detail::option_bit::with_vertex_properties);
3759

60+
/// @ingroup GL GL-IO
61+
/// @brief @ref gl::io::options_manip "Stream manipulator" to enable the processing of edge properties.
3862
inline constexpr options_manip with_edge_properties =
3963
set_options(detail::option_bit::with_connection_properties);
64+
65+
/// @ingroup GL GL-IO
66+
/// @brief @ref gl::io::options_manip "Stream manipulator" to disable the processing of edge properties.
4067
inline constexpr options_manip without_edge_properties =
4168
clear_options(detail::option_bit::with_connection_properties);
4269

70+
/// @ingroup GL GL-IO
71+
/// @brief @ref gl::io::options_manip "Stream manipulator" to enable the processing of both vertex and edge properties simultaneously.
4372
inline constexpr options_manip with_properties = set_options(
4473
detail::option_bit::with_vertex_properties, detail::option_bit::with_connection_properties
4574
);
75+
76+
/// @ingroup GL GL-IO
77+
/// @brief @ref gl::io::options_manip "Stream manipulator" to disable the processing of both vertex and edge properties simultaneously.
4678
inline constexpr options_manip without_properties = clear_options(
4779
detail::option_bit::with_vertex_properties, detail::option_bit::with_connection_properties
4880
);
4981

82+
/// @ingroup GL GL-IO
83+
/// @brief @ref gl::io::options_manip "Stream manipulator" to reset all custom graph formatting flags back to their default states.
5084
inline constexpr options_manip default_options{0ul, ~static_cast<iword_type>(0)};
5185

5286
} // namespace gl::io

include/gl/io/options_manip.hpp

Lines changed: 90 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 gl/io/options_manip.hpp
6+
/// @brief Defines custom I/O stream manipulators for configuring serialization and deserialization options.
7+
58
#pragma once
69

710
#include "gl/attributes/force_inline.hpp"
@@ -12,43 +15,83 @@
1215

1316
namespace gl::io {
1417

18+
/// @ingroup GL GL-IO
19+
/// @brief Type used for standard I/O stream custom index allocation (`std::ios_base::xalloc`).
1520
using index_type = int;
21+
22+
/// @ingroup GL GL-IO
23+
/// @brief Type used for storing custom option flags within standard I/O streams.
1624
using iword_type = long;
25+
26+
/// @ingroup GL GL-IO
27+
/// @brief Type representing the zero-indexed position of a specific option bit.
1728
using bit_position_type = unsigned;
1829

30+
/// @ingroup GL GL-IO
31+
/// @brief Base bit representing the first position in an `iword` flag map.
1932
inline constexpr iword_type iword_bit = 1ul;
2033

34+
/// @ingroup GL GL-IO
35+
/// @brief A custom stream manipulator for modifying formatting options on standard I/O streams.
36+
///
37+
/// Utilizing `std::ios_base::xalloc` and the `iword` map, this class safely injects custom formatting
38+
/// state directly into C++ standard streams. It acts as an intermediate proxy object produced by
39+
/// functions like @ref gl::io::set_options "set_options" and @ref gl::io::clear_options "clear_options".
2140
class options_manip {
2241
public:
42+
/// @brief Default constructor is disabled.
2343
options_manip() = delete;
2444

45+
/// @brief Constructs a manipulator with specific state masks.
46+
/// @param set_mask The bitmask of options to enable.
47+
/// @param clear_mask The bitmask of options to disable (defaults to 0).
2548
constexpr explicit options_manip(iword_type set_mask, iword_type clear_mask = 0ul)
2649
: _set_mask(set_mask), _clear_mask(clear_mask) {}
2750

51+
/// @brief Applies the manipulator's formatting masks to an output stream.
52+
/// @param os The target output stream.
53+
/// @param manip The manipulator containing the masks to apply.
54+
/// @return The stream reference for chaining.
2855
friend std::ostream& operator<<(std::ostream& os, const options_manip& manip) {
2956
os.iword(_iostream_property_map_index()) &= ~manip._clear_mask;
3057
os.iword(_iostream_property_map_index()) |= manip._set_mask;
3158
return os;
3259
}
3360

61+
/// @brief Applies the manipulator's formatting masks to an input stream.
62+
/// @param is The target input stream.
63+
/// @param manip The manipulator containing the masks to apply.
64+
/// @return The stream reference for chaining.
3465
friend std::istream& operator>>(std::istream& is, const options_manip& manip) {
3566
is.iword(_iostream_property_map_index()) &= ~manip._clear_mask;
3667
is.iword(_iostream_property_map_index()) |= manip._set_mask;
3768
return is;
3869
}
3970

71+
/// @brief Checks if a specific option bit is currently enabled on the given stream.
72+
/// @param stream The stream to check.
73+
/// @param bit_position The numeric position of the bit to verify.
74+
/// @return `true` if the specified bit is set, `false` otherwise.
4075
[[nodiscard]] gl_attr_force_inline static bool is_option_set(
4176
std::ios_base& stream, bit_position_type bit_position
4277
) {
4378
return (stream.iword(_iostream_property_map_index()) & (iword_bit << bit_position)) != 0;
4479
}
4580

81+
/// @brief Checks if a specific enum-based option is currently enabled on the given stream.
82+
/// @param stream The stream to check.
83+
/// @param bit The scoped enum value representing the bit to verify.
84+
/// @return `true` if the specified bit is set, `false` otherwise.
4685
[[nodiscard]] gl_attr_force_inline static bool is_option_set(
4786
std::ios_base& stream, traits::c_enum auto bit
4887
) {
4988
return is_option_set(stream, static_cast<bit_position_type>(bit));
5089
}
5190

91+
/// @brief Checks if a specific sequence of bits matches the exact stream state.
92+
/// @param stream The stream to check.
93+
/// @param bitmask The bitmask to verify against the stream's state.
94+
/// @return `true` if all bits within the mask are strictly set, `false` otherwise.
5295
[[nodiscard]] gl_attr_force_inline static bool are_options_set(
5396
std::ios_base& stream, iword_type bitmask
5497
) {
@@ -86,47 +129,94 @@ template <typename T>
86129

87130
} // namespace detail
88131

132+
/// @ingroup GL GL-IO
133+
/// @brief Creates a stream manipulator that enables the specified option bits.
134+
/// @tparam Args Variadic template arguments representing the bits to set.
135+
/// @param bits The specific options/bits to enable.
136+
/// @return An @ref gl::io::options_manip "options_manip" object ready to be piped into a stream.
89137
template <typename... Args>
90138
[[nodiscard]] constexpr options_manip set_options(Args... bits) {
91139
return options_manip{detail::build_mask(bits...), 0ul};
92140
}
93141

142+
/// @ingroup GL GL-IO
143+
/// @brief Creates a stream manipulator that enables the specified option bits from a list.
144+
/// @tparam T The type of the bits.
145+
/// @param bits An initializer list containing the options/bits to enable.
146+
/// @return An @ref gl::io::options_manip "options_manip" object ready to be piped into a stream.
94147
template <typename T>
95148
[[nodiscard]] constexpr options_manip set_options(std::initializer_list<T> bits) {
96149
return options_manip{detail::build_mask_from(bits), 0ul};
97150
}
98151

152+
/// @ingroup GL GL-IO
153+
/// @brief Creates a stream manipulator that disables the specified option bits.
154+
/// @tparam Args Variadic template arguments representing the bits to clear.
155+
/// @param bits The specific options/bits to disable.
156+
/// @return An @ref gl::io::options_manip "options_manip" object ready to be piped into a stream.
99157
template <typename... Args>
100158
[[nodiscard]] constexpr options_manip clear_options(Args... bits) {
101159
return options_manip{0ul, detail::build_mask(bits...)};
102160
}
103161

162+
/// @ingroup GL GL-IO
163+
/// @brief Creates a stream manipulator that disables the specified option bits from a list.
164+
/// @tparam T The type of the bits.
165+
/// @param bits An initializer list containing the options/bits to disable.
166+
/// @return An @ref gl::io::options_manip "options_manip" object ready to be piped into a stream.
104167
template <typename T>
105168
[[nodiscard]] constexpr options_manip clear_options(std::initializer_list<T> bits) {
106169
return options_manip{0ul, detail::build_mask_from(bits)};
107170
}
108171

172+
/// @ingroup GL GL-IO
173+
/// @brief Convenience wrapper to check if a specific option bit is set on the stream.
174+
/// @param stream The stream to check.
175+
/// @param bit_position The numeric position of the bit to verify.
176+
/// @return `true` if the specified bit is set, `false` otherwise.
109177
[[nodiscard]] gl_attr_force_inline bool is_option_set(
110178
std::ios_base& stream, bit_position_type bit_position
111179
) {
112180
return options_manip::is_option_set(stream, bit_position);
113181
}
114182

183+
/// @ingroup GL GL-IO
184+
/// @brief Convenience wrapper to check if a specific enum-based option is set on the stream.
185+
/// @param stream The stream to check.
186+
/// @param bit The scoped enum value representing the bit to verify.
187+
/// @return `true` if the specified bit is set, `false` otherwise.
115188
[[nodiscard]] gl_attr_force_inline bool is_option_set(
116189
std::ios_base& stream, traits::c_enum auto bit
117190
) {
118191
return options_manip::is_option_set(stream, bit);
119192
}
120193

194+
/// @ingroup GL GL-IO
195+
/// @brief Convenience wrapper to check if a combined bitmask of options is set on the stream.
196+
/// @param stream The stream to check.
197+
/// @param bitmask The exact bitmask to verify.
198+
/// @return `true` if all bits within the mask are strictly set, `false` otherwise.
121199
[[nodiscard]] gl_attr_force_inline bool are_options_set(std::ios_base& stream, iword_type bitmask) {
122200
return options_manip::are_options_set(stream, bitmask);
123201
}
124202

203+
/// @ingroup GL GL-IO
204+
/// @brief Convenience wrapper to check if multiple specific options are simultaneously set.
205+
/// @tparam Args Variadic template arguments representing the bits.
206+
/// @param stream The stream to check.
207+
/// @param bits The specific options/bits to verify.
208+
/// @return `true` if all specified bits are set, `false` otherwise.
125209
template <typename... Args>
126210
[[nodiscard]] gl_attr_force_inline bool are_options_set(std::ios_base& stream, Args... bits) {
127211
return options_manip::are_options_set(stream, detail::build_mask(bits...));
128212
}
129213

214+
/// @ingroup GL GL-IO
215+
/// @brief Convenience wrapper to check if multiple specific options from a list are simultaneously set.
216+
/// @tparam T The type of the elements in the initializer list.
217+
/// @param stream The stream to check.
218+
/// @param bits An initializer list containing the options/bits to verify.
219+
/// @return `true` if all specified bits are set, `false` otherwise.
130220
template <typename T>
131221
[[nodiscard]] gl_attr_force_inline bool are_options_set(
132222
std::ios_base& stream, std::initializer_list<T> bits

0 commit comments

Comments
 (0)