Skip to content

Commit 65da6c7

Browse files
committed
vertex and edge ostream operator refinement
1 parent 7a00d6b commit 65da6c7

3 files changed

Lines changed: 75 additions & 39 deletions

File tree

include/gl/edge_descriptor.hpp

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#pragma once
66

7+
#include "gl/attributes/force_inline.hpp"
78
#include "gl/constants.hpp"
89
#include "gl/directional_tags.hpp"
910
#include "gl/io/format.hpp"
@@ -160,44 +161,80 @@ class edge_descriptor final {
160161
return this->_properties.get();
161162
}
162163

163-
friend inline std::ostream& operator<<(std::ostream& os, const edge_descriptor& edge) {
164-
edge._write(os);
165-
return os;
164+
friend gl_attr_force_inline std::ostream& operator<<(
165+
std::ostream& os, const edge_descriptor& edge
166+
) {
167+
return edge._write(os);
166168
}
167169

168170
private:
169-
void _write(std::ostream& os) const {
171+
std::ostream& _write(std::ostream& os) const
172+
requires std::same_as<directional_tag, undirected_t>
173+
{
170174
using io::detail::option_bit;
171175

172176
if constexpr (not traits::c_writable<properties_type>) {
173-
this->_write_no_properties(os);
174-
return;
177+
return this->_write_no_properties(os);
175178
}
176179
else {
177-
if (not io::is_option_set(os, option_bit::with_connection_properties)) {
178-
this->_write_no_properties(os);
179-
return;
180-
}
180+
if (not io::is_option_set(os, option_bit::with_connection_properties))
181+
return this->_write_no_properties(os);
181182

182-
// TODO: print ID
183183
if (io::is_option_set(os, option_bit::verbose))
184-
os << "[source: " << this->_vertices.first << ", target: " << this->_vertices.second
185-
<< " | properties: " << this->_properties.get() << "]";
184+
return os
185+
<< "[id: " << this->_id << " | endpoints: {" << this->_vertices.first << ", "
186+
<< this->_vertices.second << "} | " << this->_properties.get() << ']';
186187
else
187-
os << "[" << this->_vertices.first << ", " << this->_vertices.second << " | "
188-
<< this->_properties.get() << "]";
188+
return os << '{' << this->_vertices.first << ", " << this->_vertices.second << "}["
189+
<< this->_properties.get() << ']';
189190
}
190191
}
191192

192-
void _write_no_properties(std::ostream& os) const {
193+
std::ostream& _write_no_properties(std::ostream& os) const
194+
requires std::same_as<directional_tag, undirected_t>
195+
{
196+
using io::detail::option_bit;
197+
198+
if (io::is_option_set(os, option_bit::verbose))
199+
return os << "[id: " << this->_id << " | endpoints: {" << this->_vertices.first << ", "
200+
<< this->_vertices.second << "}]";
201+
else
202+
return os << '{' << this->_vertices.first << ", " << this->_vertices.second << '}';
203+
}
204+
205+
std::ostream& _write(std::ostream& os) const
206+
requires std::same_as<directional_tag, directed_t>
207+
{
208+
using io::detail::option_bit;
209+
210+
if constexpr (not traits::c_writable<properties_type>) {
211+
return this->_write_no_properties(os);
212+
}
213+
else {
214+
if (not io::is_option_set(os, option_bit::with_connection_properties))
215+
return this->_write_no_properties(os);
216+
217+
if (io::is_option_set(os, option_bit::verbose))
218+
return os
219+
<< "[id: " << this->_id << " | source: " << this->_vertices.first
220+
<< ", target: " << this->_vertices.second << " | " << this->_properties.get()
221+
<< ']';
222+
else
223+
return os << '(' << this->_vertices.first << ", " << this->_vertices.second << ")["
224+
<< this->_properties.get() << ']';
225+
}
226+
}
227+
228+
std::ostream& _write_no_properties(std::ostream& os) const
229+
requires std::same_as<directional_tag, directed_t>
230+
{
193231
using io::detail::option_bit;
194232

195-
// TODO: print ID
196233
if (io::is_option_set(os, option_bit::verbose))
197-
os << "[source: " << this->_vertices.first << ", target: " << this->_vertices.first
198-
<< "]";
234+
return os << "[id: " << this->_id << " | source: " << this->_vertices.first
235+
<< ", target: " << this->_vertices.second << ']';
199236
else
200-
os << "[" << this->_vertices.first << ", " << this->_vertices.second << "]";
237+
return os << '(' << this->_vertices.first << ", " << this->_vertices.second << ')';
201238
}
202239

203240
id_type _id;

include/gl/io/options.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ namespace gl::io {
1111
namespace detail {
1212

1313
enum class option_bit : bit_position_type {
14-
verbose = 0ul,
15-
with_vertex_properties = 1ul,
16-
with_connection_properties = 2ul,
17-
specification_fmt = 3ul
14+
verbose = 0u,
15+
with_vertex_properties = 1u,
16+
with_connection_properties = 2u,
17+
specification_fmt = 3u
1818
};
1919

2020
} // namespace detail

include/gl/vertex_descriptor.hpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#pragma once
66

7+
#include "gl/attributes/force_inline.hpp"
78
#include "gl/constants.hpp"
89
#include "gl/decl/graph_traits.hpp"
910
#include "gl/io/options.hpp"
@@ -92,39 +93,37 @@ class vertex_descriptor final {
9293
return this->_properties.get();
9394
}
9495

95-
friend inline std::ostream& operator<<(std::ostream& os, const vertex_descriptor& vertex) {
96-
vertex._write(os);
97-
return os;
96+
friend gl_attr_force_inline std::ostream& operator<<(
97+
std::ostream& os, const vertex_descriptor& vertex
98+
) {
99+
return vertex._write(os);
98100
}
99101

100102
private:
101-
void _write(std::ostream& os) const {
103+
std::ostream& _write(std::ostream& os) const {
102104
using io::detail::option_bit;
103105

104106
if constexpr (not traits::c_writable<properties_type>) {
105-
this->_write_no_properties(os);
106-
return;
107+
return this->_write_no_properties(os);
107108
}
108109
else {
109-
if (not io::is_option_set(os, option_bit::with_vertex_properties)) {
110-
this->_write_no_properties(os);
111-
return;
112-
}
110+
if (not io::is_option_set(os, option_bit::with_vertex_properties))
111+
return this->_write_no_properties(os);
113112

114113
if (io::is_option_set(os, option_bit::verbose))
115-
os << "[id: " << this->_id << " | properties: " << this->_properties.get() << "]";
114+
return os << "[id: " << this->_id << " | " << this->_properties.get() << ']';
116115
else
117-
os << "[" << this->_id << " | " << this->_properties.get() << "]";
116+
return os << this->_id << '[' << this->_properties.get() << ']';
118117
}
119118
}
120119

121-
void _write_no_properties(std::ostream& os) const {
120+
std::ostream& _write_no_properties(std::ostream& os) const {
122121
using io::detail::option_bit;
123122

124123
if (io::is_option_set(os, option_bit::verbose))
125-
os << std::format("[id: {}]", this->_id);
124+
return os << std::format("[id: {}]", this->_id);
126125
else
127-
os << this->_id;
126+
return os << this->_id;
128127
}
129128

130129
id_type _id;

0 commit comments

Comments
 (0)