Skip to content

Commit 7a00d6b

Browse files
committed
wip: gl::io refactor
1 parent c542c38 commit 7a00d6b

6 files changed

Lines changed: 81 additions & 60 deletions

File tree

include/gl/edge_descriptor.hpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "gl/constants.hpp"
88
#include "gl/directional_tags.hpp"
99
#include "gl/io/format.hpp"
10+
#include "gl/io/options.hpp"
1011
#include "gl/types/core.hpp"
1112
#include "gl/vertex_descriptor.hpp"
1213

@@ -166,29 +167,33 @@ class edge_descriptor final {
166167

167168
private:
168169
void _write(std::ostream& os) const {
170+
using io::detail::option_bit;
171+
169172
if constexpr (not traits::c_writable<properties_type>) {
170173
this->_write_no_properties(os);
171174
return;
172175
}
173176
else {
174-
if (not io::is_option_set(os, io::graph_option::with_edge_properties)) {
177+
if (not io::is_option_set(os, option_bit::with_connection_properties)) {
175178
this->_write_no_properties(os);
176179
return;
177180
}
178181

179-
if (io::is_option_set(os, io::graph_option::verbose)) {
182+
// TODO: print ID
183+
if (io::is_option_set(os, option_bit::verbose))
180184
os << "[source: " << this->_vertices.first << ", target: " << this->_vertices.second
181185
<< " | properties: " << this->_properties.get() << "]";
182-
}
183-
else {
186+
else
184187
os << "[" << this->_vertices.first << ", " << this->_vertices.second << " | "
185188
<< this->_properties.get() << "]";
186-
}
187189
}
188190
}
189191

190192
void _write_no_properties(std::ostream& os) const {
191-
if (io::is_option_set(os, io::graph_option::verbose))
193+
using io::detail::option_bit;
194+
195+
// TODO: print ID
196+
if (io::is_option_set(os, option_bit::verbose))
192197
os << "[source: " << this->_vertices.first << ", target: " << this->_vertices.first
193198
<< "]";
194199
else

include/gl/graph.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "gl/constants.hpp"
88
#include "gl/graph_traits.hpp"
99
#include "gl/impl/impl_tags.hpp"
10+
#include "gl/io/options.hpp"
1011
#include "gl/io/stream_options_manipulator.hpp"
1112
#include "gl/util/ranges.hpp"
1213

@@ -630,12 +631,14 @@ class graph final {
630631
// --- stream operators ---
631632

632633
friend std::ostream& operator<<(std::ostream& os, const graph& g) {
633-
if (io::is_option_set(os, io::graph_option::gsf)) {
634+
using io::detail::option_bit;
635+
636+
if (io::is_option_set(os, option_bit::specification_fmt)) {
634637
g._gsf_write(os);
635638
return os;
636639
}
637640

638-
if (io::is_option_set(os, io::graph_option::verbose))
641+
if (io::is_option_set(os, option_bit::verbose))
639642
g._verbose_write(os);
640643
else
641644
g._concise_write(os);
@@ -747,10 +750,12 @@ class graph final {
747750
}
748751

749752
void _gsf_write(std::ostream& os) const {
753+
using io::detail::option_bit;
754+
750755
const bool with_vertex_properties =
751-
io::is_option_set(os, io::graph_option::with_vertex_properties);
756+
io::is_option_set(os, option_bit::with_vertex_properties);
752757
const bool with_edge_properties =
753-
io::is_option_set(os, io::graph_option::with_edge_properties);
758+
io::is_option_set(os, option_bit::with_connection_properties);
754759

755760
// print graph size
756761
os << std::format(

include/gl/io.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "gl/io/format.hpp"
1010
#include "gl/io/stream_options_manipulator.hpp"
1111

12-
#include "gl/io/graph_options.hpp"
12+
#include "gl/io/options.hpp"
1313
#include "gl/io/graph_fio.hpp"
1414

1515
// clang-format on

include/gl/io/graph_options.hpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

include/gl/io/options.hpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2024-2026 Jakub Musiał
2+
// This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl).
3+
// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
4+
5+
#pragma once
6+
7+
#include "gl/io/stream_options_manipulator.hpp"
8+
9+
namespace gl::io {
10+
11+
namespace detail {
12+
13+
enum class option_bit : bit_position_type {
14+
verbose = 0ul,
15+
with_vertex_properties = 1ul,
16+
with_connection_properties = 2ul,
17+
specification_fmt = 3ul
18+
};
19+
20+
} // namespace detail
21+
22+
inline const stream_options_manipulator verbose = set_option(detail::option_bit::verbose);
23+
inline const stream_options_manipulator concise = unset_option(detail::option_bit::verbose);
24+
25+
inline const stream_options_manipulator with_vertex_properties =
26+
set_option(detail::option_bit::with_vertex_properties);
27+
inline const stream_options_manipulator without_vertex_properties =
28+
unset_option(detail::option_bit::with_vertex_properties);
29+
30+
inline const stream_options_manipulator with_edge_properties =
31+
set_option(detail::option_bit::with_connection_properties);
32+
inline const stream_options_manipulator without_edge_properties =
33+
unset_option(detail::option_bit::with_connection_properties);
34+
35+
inline const stream_options_manipulator with_properties = set_options(
36+
{detail::option_bit::with_vertex_properties, detail::option_bit::with_connection_properties}
37+
);
38+
inline const stream_options_manipulator without_properties = unset_options(
39+
{detail::option_bit::with_vertex_properties, detail::option_bit::with_connection_properties}
40+
);
41+
42+
inline const stream_options_manipulator enable_gsf =
43+
set_option(detail::option_bit::specification_fmt);
44+
inline const stream_options_manipulator disable_gsf =
45+
unset_option(detail::option_bit::specification_fmt);
46+
47+
inline const stream_options_manipulator default_options =
48+
unset_options(~static_cast<iword_type>(0));
49+
50+
} // namespace gl::io

include/gl/vertex_descriptor.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "gl/constants.hpp"
88
#include "gl/decl/graph_traits.hpp"
9-
#include "gl/io/graph_options.hpp"
9+
#include "gl/io/options.hpp"
1010
#include "gl/traits.hpp"
1111
#include "gl/types/core.hpp"
1212
#include "gl/types/properties.hpp"
@@ -99,32 +99,32 @@ class vertex_descriptor final {
9999

100100
private:
101101
void _write(std::ostream& os) const {
102+
using io::detail::option_bit;
103+
102104
if constexpr (not traits::c_writable<properties_type>) {
103105
this->_write_no_properties(os);
104106
return;
105107
}
106108
else {
107-
if (not io::is_option_set(os, io::graph_option::with_vertex_properties)) {
109+
if (not io::is_option_set(os, option_bit::with_vertex_properties)) {
108110
this->_write_no_properties(os);
109111
return;
110112
}
111113

112-
if (io::is_option_set(os, io::graph_option::verbose)) {
114+
if (io::is_option_set(os, option_bit::verbose))
113115
os << "[id: " << this->_id << " | properties: " << this->_properties.get() << "]";
114-
}
115-
else {
116+
else
116117
os << "[" << this->_id << " | " << this->_properties.get() << "]";
117-
}
118118
}
119119
}
120120

121121
void _write_no_properties(std::ostream& os) const {
122-
if (io::is_option_set(os, io::graph_option::verbose)) {
122+
using io::detail::option_bit;
123+
124+
if (io::is_option_set(os, option_bit::verbose))
123125
os << std::format("[id: {}]", this->_id);
124-
}
125-
else {
126+
else
126127
os << this->_id;
127-
}
128128
}
129129

130130
id_type _id;

0 commit comments

Comments
 (0)