169 uint32_t table_width = 7;
170 uint32_t reg_column_width = 0;
171 uint32_t val_column_width = 3;
172 std::stringstream table_stream;
174 for (
auto it = data.begin(); it != data.end(); ++it) {
175 reg_column_width = reg_column_width > it->first.size() ? reg_column_width : it->first.size();
181 reg_column_width = reg_column_width > headers.at(0).size() ? reg_column_width : headers.at(0).size();
182 val_column_width = val_column_width > headers.at(1).size() ? val_column_width : headers.at(1).size();
184 table_width = table_width + reg_column_width + val_column_width;
187 table_stream << boost::format(
"%=s\n") % boost::io::group(std::setw(table_width), std::setfill(
'-'), title);
189 if (headers.at(0).size() || headers.at(1).size()) {
190 table_stream << boost::format(
"+-%=s-+-%=s-+\n") %
191 boost::io::group(std::setw(reg_column_width), std::setfill(
'-'),
"") %
192 boost::io::group(std::setw(val_column_width), std::setfill(
'-'),
"");
193 table_stream << boost::format(
"| %=s | %=s |\n") % boost::io::group(std::setw(reg_column_width), headers.at(0)) %
194 boost::io::group(std::setw(val_column_width), headers.at(1));
197 table_stream << boost::format(
"+-%=s-+-%=s-+\n") %
198 boost::io::group(std::setw(reg_column_width), std::setfill(
'-'),
"") %
199 boost::io::group(std::setw(val_column_width), std::setfill(
'-'),
"");
201 for (
auto it = data.begin(); it != data.end(); ++it) {
202 table_stream << boost::format(
"| %=s | %=s |\n") % boost::io::group(std::setw(reg_column_width), it->first) %
203 boost::io::group(std::setw(val_column_width),
format_reg_value(it->second));
205 table_stream << boost::format(
"+-%=s-+-%=s-+\n") %
206 boost::io::group(std::setw(reg_column_width), std::setfill(
'-'),
"") %
207 boost::io::group(std::setw(val_column_width), std::setfill(
'-'),
"");
209 return table_stream.str();
217 std::vector<std::string> counter_node_titles,
218 std::string table_title,
219 std::vector<std::string> counter_labels,
220 std::string counter_labels_header)
223 uint32_t counter_nodes_number = counter_nodes.size();
224 uint32_t table_width = 4 + (counter_nodes_number * 3);
226 std::vector<std::string> counter_node_titles_to_use;
228 if (!counter_node_titles.size()) {
229 for (uint32_t i = 0; i < counter_nodes.size(); ++i) {
230 counter_node_titles_to_use.push_back(
"Counters");
232 }
else if (counter_nodes.size() != counter_node_titles.size()) {
233 throw FormatCountersTableNodesTitlesMismatch(
ERS_HERE);
235 counter_node_titles_to_use = counter_node_titles;
238 uint32_t counter_number;
239 uint32_t counter_label_column_width = 0;
241 std::stringstream table_stream;
242 counter_number = counter_labels.size();
244 for (
auto it = counter_labels.begin(); it != counter_labels.end(); ++it) {
245 counter_label_column_width = counter_label_column_width > it->size() ? counter_label_column_width : it->size();
247 counter_label_column_width =
248 counter_label_column_width > counter_labels_header.size() ? counter_label_column_width : counter_labels_header.size();
250 typedef std::vector<std::pair<std::string, std::string>> CounterValuesContainer;
252 std::vector<CounterValuesContainer> counter_value_containers;
253 std::vector<std::pair<uint32_t, uint32_t>> counter_value_column_widths;
255 for (
auto node_iter = counter_nodes.begin(); node_iter != counter_nodes.end(); ++node_iter) {
257 CounterValuesContainer counter_values;
259 uint32_t counter_value_dec_column_width = 5;
260 uint32_t counter_value_hex_column_width = 5;
262 for (
auto counter_iter = node_iter->begin(); counter_iter != node_iter->end(); ++counter_iter) {
267 counter_value_dec_column_width =
268 counter_value_dec_column_width > counter_value_dec.size() ? counter_value_dec_column_width : counter_value_dec.size();
269 counter_value_hex_column_width =
270 counter_value_hex_column_width > counter_value_hex.size() ? counter_value_hex_column_width : counter_value_hex.size();
272 counter_values.push_back(std::make_pair(counter_value_dec, counter_value_hex));
275 counter_value_containers.push_back(counter_values);
276 counter_value_column_widths.push_back(std::make_pair(counter_value_dec_column_width, counter_value_hex_column_width));
279 std::vector<uint32_t> counter_node_title_sizes;
281 std::stringstream counter_titles_row;
282 counter_titles_row << boost::format(
"| %=s |") % boost::io::group(std::setw(counter_label_column_width),
"");
283 table_width = table_width + counter_label_column_width;
284 for (uint32_t i = 0; i < counter_nodes_number; ++i) {
285 uint32_t dec_width = counter_value_column_widths.at(i).first;
286 uint32_t hex_width = counter_value_column_widths.at(i).second;
288 uint32_t counter_title_size = counter_node_titles_to_use.at(i).size();
290 if (counter_title_size > (dec_width + hex_width + 3)) {
292 if ((counter_title_size - 3) % 2)
293 ++counter_title_size;
295 counter_value_column_widths.at(i).first = (counter_title_size - 3) / 2;
296 counter_value_column_widths.at(i).second = (counter_title_size - 3) / 2;
299 counter_title_size = (dec_width + hex_width + 3);
301 counter_titles_row << boost::format(
" %=s |") %
302 boost::io::group(std::setw(counter_title_size), counter_node_titles_to_use.at(i));
303 counter_node_title_sizes.push_back(counter_title_size);
304 table_width = table_width + counter_title_size;
306 counter_titles_row << std::endl;
308 std::stringstream title_row_border;
309 title_row_border << boost::format(
"+-%=s-+") %
310 boost::io::group(std::setw(counter_label_column_width), std::setfill(
'-'),
"");
311 for (uint32_t i = 0; i < counter_nodes_number; ++i) {
312 title_row_border << boost::format(
"-%=s-+") %
313 boost::io::group(std::setw(counter_node_title_sizes.at(i)), std::setfill(
'-'),
"");
315 title_row_border << std::endl;
317 if (table_title.size())
318 table_stream << boost::format(
"%=s\n") % boost::io::group(std::setw(table_width), std::setfill(
'-'), table_title);
320 table_stream << title_row_border.str();
321 table_stream << counter_titles_row.str();
322 table_stream << title_row_border.str();
326 std::stringstream counter_headers;
327 counter_headers << boost::format(
"| %=s |") %
328 boost::io::group(std::setw(counter_label_column_width), counter_labels_header);
329 for (uint32_t j = 0; j < counter_nodes_number; ++j) {
330 uint32_t dec_width = counter_value_column_widths.at(j).first;
331 uint32_t hex_width = counter_value_column_widths.at(j).second;
332 counter_headers << boost::format(
" %=s | %=s |") % boost::io::group(std::setw(dec_width),
"cnts") %
333 boost::io::group(std::setw(hex_width),
"hex");
335 table_stream << counter_headers.str() << std::endl;
339 std::stringstream row_border;
340 row_border << boost::format(
"+-%=s-+") % boost::io::group(std::setw(counter_label_column_width), std::setfill(
'-'),
"");
341 for (uint32_t j = 0; j < counter_nodes_number; ++j) {
342 uint32_t dec_width = counter_value_column_widths.at(j).first;
343 uint32_t hex_width = counter_value_column_widths.at(j).second;
344 row_border << boost::format(
"-%=s-+-%=s-+") % boost::io::group(std::setw(dec_width), std::setfill(
'-'),
"") %
345 boost::io::group(std::setw(hex_width), std::setfill(
'-'),
"");
347 row_border << std::endl;
348 table_stream << row_border.str();
352 for (uint32_t i = 0; i < counter_number; ++i) {
353 std::stringstream table_row_stream;
355 table_row_stream << boost::format(
"| %=s |") %
356 boost::io::group(std::setw(counter_label_column_width), counter_labels.at(i));
358 for (uint32_t j = 0; j < counter_nodes_number; ++j) {
359 uint32_t dec_width = counter_value_column_widths.at(j).first;
360 uint32_t hex_width = counter_value_column_widths.at(j).second;
362 std::string dec_value = counter_value_containers.at(j).at(i).first;
363 std::string hex_value = counter_value_containers.at(j).at(i).second;
365 table_row_stream << boost::format(
" %=s | %=s |") % boost::io::group(std::setw(dec_width), dec_value) %
366 boost::io::group(std::setw(hex_width), hex_value);
368 table_stream << table_row_stream.str() << std::endl;
373 table_stream << row_border.str();
375 return table_stream.str();