8
8
9
9
namespace fly ::benchmark {
10
10
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 ¢er)
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
-
55
11
/* *
56
12
* Locale facet to format numbers with comma separators.
57
13
*
@@ -72,33 +28,4 @@ class CommaPunctuation final : public std::numpunct<std::ios::char_type>
72
28
std::string do_grouping () const override ;
73
29
};
74
30
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
-
104
31
} // namespace fly::benchmark
0 commit comments