XBotInterface  2.4.1
XBotInterface provides a generic API to model and control a robot.
table_printer.tpp.h
Go to the documentation of this file.
1 #if defined(USE_BOOST_KARMA)
2 #include <boost/spirit/include/karma.hpp>
3 namespace karma = boost::spirit::karma;
4 #endif
5 
6 namespace bprinter{
7 #if defined(USE_BOOST_KARMA)
8 template<typename T> void TablePrinter::OutputDecimalNumber(T input){
9  *out_stream_ << karma::format(
10  karma::maxwidth(column_widths_.at(j_))[
11  karma::right_align(column_widths_.at(j_))[
12  karma::double_
13  ]
14  ], input
15  );
16 
17  if (j_ == get_num_columns()-1){
18  *out_stream_ << "|\n";
19  i_ = i_ + 1;
20  j_ = 0;
21  } else {
22  *out_stream_ << separator_;
23  j_ = j_ + 1;
24  }
25 }
26 #else
27 template<typename T> void TablePrinter::OutputDecimalNumber(T input){
28  // If we cannot handle this number, indicate so
29  if (input < 10*(column_widths_.at(j_)-1) || input > 10*column_widths_.at(j_)){
30  std::stringstream string_out;
31  string_out << std::setiosflags(std::ios::fixed)
32  << std::setprecision(column_widths_.at(j_))
33  << std::setw(column_widths_.at(j_))
34  << input;
35 
36  std::string string_rep_of_number = string_out.str();
37 
38 // string_rep_of_number[column_widths_.at(j_)-1] = '*';
39  std::string string_to_print = string_rep_of_number.substr(0, column_widths_.at(j_));
40  *out_stream_ << string_to_print;
41  } else {
42 
43  // determine what precision we need
44  int precision = column_widths_.at(j_) - 1; // leave room for the decimal point
45  if (input < 0)
46  --precision; // leave room for the minus sign
47 
48  // leave room for digits before the decimal?
49  if (input < -1 || input > 1){
50  int num_digits_before_decimal = 1 + (int)log10(std::abs(input));
51  precision -= num_digits_before_decimal;
52  }
53  else
54  precision --; // e.g. 0.12345 or -0.1234
55 
56  if (precision < 0)
57  precision = 0; // don't go negative with precision
58 
59  *out_stream_ << std::setiosflags(std::ios::fixed)
60  << std::setprecision(precision)
61  << std::setw(column_widths_.at(j_))
62  << input;
63  }
64 
65  if (j_ == get_num_columns()-1){
66  *out_stream_ << "|\n";
67  i_ = i_ + 1;
68  j_ = 0;
69  } else {
70  *out_stream_ << separator_;
71  j_ = j_ + 1;
72  }
73 }
74 #endif //USE_BOOST_KARMA
75 }
bprinter::TablePrinter::get_num_columns
int get_num_columns() const
Definition: table_printer.cpp:20
bprinter
Definition: table_printer.tpp.h:6