Skip to content

Commit aebd272

Browse files
committed
Remove centering facet from benchmark stream utilities
BasicString::format now supports center alignment for string types, so this feature may be used instead of the custom centering facet.
1 parent 0ed6f1c commit aebd272

File tree

2 files changed

+2
-75
lines changed

2 files changed

+2
-75
lines changed

bench/util/stream_util.hpp

-73
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,6 @@
88

99
namespace fly::benchmark {
1010

11-
/**
12-
* Helper class to center text within a specified width within a steam.
13-
*
14-
* @author Timothy Flynn ([email protected])
15-
* @version Decmber 12, 2020
16-
*/
17-
template <typename StringType>
18-
class Center
19-
{
20-
public:
21-
/**
22-
* Constructor.
23-
*
24-
* @param width The width to center the text within.
25-
* @param value The text to be centered.
26-
*/
27-
Center(std::size_t width, const StringType &value);
28-
29-
/**
30-
* Print the centered text.
31-
*
32-
* @param stream The stream to print the text into.
33-
* @param center The instance holding the centering data.
34-
*
35-
* @return The same stream object.
36-
*/
37-
friend std::ostream &operator<<(std::ostream &stream, const Center &center)
38-
{
39-
center.print(stream);
40-
return stream;
41-
}
42-
43-
private:
44-
/**
45-
* Print the centered text.
46-
*
47-
* @param stream The stream to print the text into.
48-
*/
49-
void print(std::ostream &stream) const;
50-
51-
const std::streamsize m_width;
52-
const StringType &m_value;
53-
};
54-
5511
/**
5612
* Locale facet to format numbers with comma separators.
5713
*
@@ -72,33 +28,4 @@ class CommaPunctuation final : public std::numpunct<std::ios::char_type>
7228
std::string do_grouping() const override;
7329
};
7430

75-
//==================================================================================================
76-
template <typename StringType>
77-
Center<StringType>::Center(std::size_t width, const StringType &value) :
78-
m_width(static_cast<std::streamsize>(width)),
79-
m_value(value)
80-
{
81-
}
82-
83-
//==================================================================================================
84-
template <typename StringType>
85-
void Center<StringType>::print(std::ostream &stream) const
86-
{
87-
const std::streamsize length = static_cast<std::streamsize>(m_value.size());
88-
89-
if (m_width > length)
90-
{
91-
const std::streamsize left = (m_width + length) / 2;
92-
93-
fly::detail::BasicStreamModifiers<std::string> scoped_modifiers(stream);
94-
stream << std::right;
95-
stream << std::setw(left) << m_value;
96-
stream << std::setw(m_width - left) << "";
97-
}
98-
else
99-
{
100-
stream << m_value;
101-
}
102-
}
103-
10431
} // namespace fly::benchmark

bench/util/table.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void Table<Args...>::print_title(std::ostream &stream, std::size_t table_width)
264264
const std::size_t title_width = table_width - 4;
265265

266266
auto title = std::string_view(m_title).substr(0, title_width);
267-
stream << style << fly::String::format(" {} ", Center(title_width, title));
267+
stream << style << fly::String::format(" {:^{}} ", title, title_width);
268268

269269
print_column_separator(stream, s_border_style) << '\n';
270270
print_row_separator(stream, table_width);
@@ -281,7 +281,7 @@ void Table<Args...>::print_headers(std::ostream &stream, std::size_t table_width
281281
const auto style = fly::Styler(s_header_style, s_header_color);
282282
stream << style;
283283

284-
stream << fly::String::format(" {} ", Center(m_column_widths[index], m_headers[index]));
284+
stream << fly::String::format(" {:^{}} ", m_headers[index], m_column_widths[index]);
285285
}
286286

287287
print_column_separator(stream, s_border_style) << '\n';

0 commit comments

Comments
 (0)