gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool

#include <table_formatter.hpp>

Collaboration diagram for Gambit::table_formatter:

Public Member Functions

template<typename... T>
 table_formatter (const T &...params)
 
template<typename... T>
void new_titles (const T &... in)
 
template<typename... T>
void default_widths (const T &... in)
 
template<typename... T>
void min_widths (const T &... in)
 
void padding (int p)
 
void wrap_around (bool b)
 
void top_line (bool b)
 
void bottom_line (bool b)
 
void capitalize_title (int i)
 
void capitalize_title ()
 
int rows () const
 
int cols () const
 
int row_pos () const
 
int col_pos () const
 
table_formatternew_row (int n=1)
 
template<typename T >
table_formatteroperator<< (const T &in)
 
table_formatterreset_pt_flag (const unsigned char flag, int i, int j)
 
table_formatterreset_row_flag (const unsigned char flag, int i)
 
table_formatterreset_col_flag (const unsigned char flag, int i)
 
table_formatterset_pt_flag (const unsigned char flag, int i, int j)
 
table_formatterset_row_flag (const unsigned char flag, int i)
 
table_formatterset_col_flag (const unsigned char flag, int i)
 
table_formatterreset (int i=-1, int j=-1)
 
table_formatterred (int i=-1, int j=-1)
 
table_formattergreen (int i=-1, int j=-1)
 
table_formatteryellow (int i=-1, int j=-1)
 
table_formatterbold (int i=-1, int j=-1)
 
table_formatterunderline (int i=-1, int j=-1)
 
table_formatterright_justify (int j=-1)
 
table_formattercenter_justify (int j=-1)
 
table_formatterleft_justify (int j=-1)
 
table_formatterno_newline (int j=-1)
 
table_formatternewline (int j=-1)
 
std::vector< std::string > & operator[] (int i)
 
std::string str ()
 

Static Public Attributes

static const unsigned char RESET = 0x00
 
static const unsigned char RED = 0x01
 
static const unsigned char GREEN = 0x02
 
static const unsigned char YELLOW = 0x04
 
static const unsigned char COLOR = 0x07
 
static const unsigned char BOLD = 0x80
 
static const unsigned char JUST_RIGHT = 0x10
 
static const unsigned char JUST_CENTER = 0x20
 
static const unsigned char JUST = 0x30
 
static const unsigned char UNDERLINE = 0x40
 
static const unsigned char WRAP = 0x80
 

Private Member Functions

template<typename U >
void enter_vec (std::vector< U > &)
 
template<typename U , typename V , typename... T>
void enter_vec (std::vector< U > &vec, const V &str, const T &... params)
 

Private Attributes

const int col_num
 
int col
 
int row
 
int pad
 
bool wrap
 
bool top
 
bool bottom
 
std::vector< intdefaultWidths
 
std::vector< intminWidths
 
std::vector< std::vector< std::string > > data
 
std::vector< std::vector< std::string > > titles
 
std::map< std::pair< int, int >, unsigned char > flags
 
std::vector< unsigned char > row_flags
 
std::vector< unsigned char > col_flags
 

Detailed Description

Definition at line 115 of file table_formatter.hpp.

Constructor & Destructor Documentation

◆ table_formatter()

template<typename... T>
Gambit::table_formatter::table_formatter ( const T &...  params)
inline

Definition at line 157 of file table_formatter.hpp.

References enter_vec().

157  : col_num(sizeof...(T)), col(0), row(0), pad(0), wrap(false), top(false), bottom(false), defaultWidths(col_num, 25), minWidths(col_num, -1), titles(1), row_flags(1, 0x00), col_flags(sizeof...(T), 0x00)
158  {
159  enter_vec(titles[0], params...);
160  }
std::vector< int > defaultWidths
std::vector< int > minWidths
std::vector< unsigned char > col_flags
std::vector< unsigned char > row_flags
void enter_vec(std::vector< U > &)
std::vector< std::vector< std::string > > titles
Here is the call graph for this function:

Member Function Documentation

◆ bold()

table_formatter& Gambit::table_formatter::bold ( int  i = -1,
int  j = -1 
)
inline

Definition at line 357 of file table_formatter.hpp.

References set_pt_flag().

358  {
359  return set_pt_flag(BOLD, (i == -1 ? row : i) , (j == -1 ? col : j));
360  }
static const unsigned char BOLD
table_formatter & set_pt_flag(const unsigned char flag, int i, int j)
Here is the call graph for this function:

◆ bottom_line()

void Gambit::table_formatter::bottom_line ( bool  b)
inline

Definition at line 199 of file table_formatter.hpp.

References b.

Referenced by Gambit::gambit_core::ff_backend_diagnostic(), and Gambit::Scanner::Plugins::Plugin_Loader::print_priors().

199 {bottom = b;}
START_MODEL b
Definition: demo.hpp:235
Here is the caller graph for this function:

◆ capitalize_title() [1/2]

void Gambit::table_formatter::capitalize_title ( int  i)
inline

Definition at line 201 of file table_formatter.hpp.

Referenced by Gambit::gambit_core::backend_diagnostic(), Gambit::gambit_core::capability_diagnostic(), Gambit::gambit_core::ff_backend_diagnostic(), Gambit::gambit_core::ff_module_diagnostic(), Gambit::gambit_core::model_diagnostic(), Gambit::gambit_core::module_diagnostic(), and Gambit::Scanner::Plugins::print_plugins().

202  {
203  for (auto it = titles[i].begin(), end = titles[i].end(); it != end; ++it)
204  {
205  for(auto s_it = it->begin(), s_end = it->end(); s_it != s_end; ++s_it)
206  {
207  *s_it = std::toupper(*s_it);
208  }
209  }
210  }
std::vector< std::vector< std::string > > titles
Here is the caller graph for this function:

◆ capitalize_title() [2/2]

void Gambit::table_formatter::capitalize_title ( )
inline

Definition at line 212 of file table_formatter.hpp.

213  {
214  for (auto it = titles.begin(), end = titles.end(); it != end; ++it)
215  {
216  for (auto t_it = it->begin(), t_end = it->end(); t_it != t_end; ++t_it)
217  {
218  for(auto s_it = t_it->begin(), s_end = t_it->end(); s_it != s_end; ++s_it)
219  {
220  *s_it = std::toupper(*s_it);
221  }
222  }
223  }
224  }
std::vector< std::vector< std::string > > titles

◆ center_justify()

table_formatter& Gambit::table_formatter::center_justify ( int  j = -1)
inline

Definition at line 372 of file table_formatter.hpp.

References set_col_flag().

373  {
374  return set_col_flag(JUST_CENTER, (j == -1 ? col : j));
375  }
static const unsigned char JUST_CENTER
table_formatter & set_col_flag(const unsigned char flag, int i)
Here is the call graph for this function:

◆ col_pos()

int Gambit::table_formatter::col_pos ( ) const
inline

Definition at line 229 of file table_formatter.hpp.

References col.

229 {return col;}

◆ cols()

int Gambit::table_formatter::cols ( ) const
inline

Definition at line 227 of file table_formatter.hpp.

References col_num.

227 {return col_num;}

◆ default_widths()

template<typename... T>
void Gambit::table_formatter::default_widths ( const T &...  in)
inline

Definition at line 174 of file table_formatter.hpp.

References enter_vec().

Referenced by Gambit::gambit_core::backend_diagnostic(), Gambit::gambit_core::capability_diagnostic(), Gambit::gambit_core::ff_backend_diagnostic(), Gambit::gambit_core::ff_module_diagnostic(), Gambit::gambit_core::model_diagnostic(), and Gambit::gambit_core::module_diagnostic().

175  {
176  if (sizeof...(T) == col_num)
177  {
178  std::vector<int> temp;
179  enter_vec(temp, in...);
180  defaultWidths = temp;
181  }
182  }
std::vector< int > defaultWidths
void enter_vec(std::vector< U > &)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enter_vec() [1/2]

template<typename U >
void Gambit::table_formatter::enter_vec ( std::vector< U > &  )
inlineprivate

Definition at line 134 of file table_formatter.hpp.

Referenced by default_widths(), enter_vec(), min_widths(), new_titles(), and table_formatter().

134 {}
Here is the caller graph for this function:

◆ enter_vec() [2/2]

template<typename U , typename V , typename... T>
void Gambit::table_formatter::enter_vec ( std::vector< U > &  vec,
const V &  str,
const T &...  params 
)
inlineprivate

Definition at line 137 of file table_formatter.hpp.

References enter_vec().

138  {
139  vec.push_back(str);
140  enter_vec(vec, params...);
141  }
void enter_vec(std::vector< U > &)
Here is the call graph for this function:

◆ green()

table_formatter& Gambit::table_formatter::green ( int  i = -1,
int  j = -1 
)
inline

Definition at line 347 of file table_formatter.hpp.

References set_pt_flag().

Referenced by Gambit::gambit_core::backend_diagnostic(), Gambit::gambit_core::ff_backend_diagnostic(), and Gambit::Scanner::Plugins::print_plugins().

348  {
349  return set_pt_flag(GREEN, (i == -1 ? row : i) , (j == -1 ? col : j));
350  }
static const unsigned char GREEN
table_formatter & set_pt_flag(const unsigned char flag, int i, int j)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ left_justify()

table_formatter& Gambit::table_formatter::left_justify ( int  j = -1)
inline

Definition at line 377 of file table_formatter.hpp.

References reset_col_flag().

378  {
379  return reset_col_flag(RESET, (j == -1 ? col : j));
380  }
table_formatter & reset_col_flag(const unsigned char flag, int i)
static const unsigned char RESET
Here is the call graph for this function:

◆ min_widths()

template<typename... T>
void Gambit::table_formatter::min_widths ( const T &...  in)
inline

Definition at line 185 of file table_formatter.hpp.

References enter_vec().

186  {
187  if (sizeof...(T) == col_num)
188  {
189  wrap = true;
190  std::vector<int> temp;
191  enter_vec(temp, in...);
192  minWidths = temp;
193  }
194  }
std::vector< int > minWidths
void enter_vec(std::vector< U > &)
Here is the call graph for this function:

◆ new_row()

table_formatter& Gambit::table_formatter::new_row ( int  n = 1)
inline

Definition at line 231 of file table_formatter.hpp.

232  {
233  for (int i = 0; i < n; i++)
234  {
235  data.push_back(std::vector<std::string>(col_num));
236  row_flags.push_back(0x00);
237  }
238 
239  col = 0;
240  row += n;
241 
242  return *this;
243  }
std::vector< std::vector< std::string > > data
std::vector< unsigned char > row_flags

◆ new_titles()

template<typename... T>
void Gambit::table_formatter::new_titles ( const T &...  in)
inline

Definition at line 163 of file table_formatter.hpp.

References enter_vec().

Referenced by Gambit::gambit_core::ff_module_diagnostic().

164  {
165  if (sizeof...(T) == col_num)
166  {
167  std::vector<std::string> temp;
168  enter_vec(temp, in...);
169  titles.push_back(temp);
170  }
171  }
void enter_vec(std::vector< U > &)
std::vector< std::vector< std::string > > titles
Here is the call graph for this function:
Here is the caller graph for this function:

◆ newline()

table_formatter& Gambit::table_formatter::newline ( int  j = -1)
inline

Definition at line 387 of file table_formatter.hpp.

References reset_row_flag().

Referenced by Gambit::gambit_core::ff_module_diagnostic().

388  {
389  return reset_row_flag(RESET, (j == -1 ? row : j));
390  }
table_formatter & reset_row_flag(const unsigned char flag, int i)
static const unsigned char RESET
Here is the call graph for this function:
Here is the caller graph for this function:

◆ no_newline()

table_formatter& Gambit::table_formatter::no_newline ( int  j = -1)
inline

Definition at line 382 of file table_formatter.hpp.

References set_row_flag().

Referenced by Gambit::gambit_core::ff_module_diagnostic(), and Gambit::Scanner::Plugins::Plugin_Loader::print_priors().

383  {
384  return set_row_flag(WRAP, (j == -1 ? row : j));
385  }
static const unsigned char WRAP
table_formatter & set_row_flag(const unsigned char flag, int i)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<()

template<typename T >
table_formatter& Gambit::table_formatter::operator<< ( const T &  in)
inline

Definition at line 246 of file table_formatter.hpp.

References col, and row.

247  {
248  std::stringstream ss;
249  ss << in;
250  if (col == 0)
251  {
252  data.push_back(std::vector<std::string>(col_num));
253  row_flags.push_back(0x00);
254  }
255  data[row][col] = ss.str();
256  col++;
257  if (col == col_num)
258  {
259  col = 0;
260  row++;
261  }
262 
263  return *this;
264  }
std::vector< std::vector< std::string > > data
std::vector< unsigned char > row_flags

◆ operator[]()

std::vector<std::string>& Gambit::table_formatter::operator[] ( int  i)
inline

Definition at line 392 of file table_formatter.hpp.

References str().

393  {
394  return data[i];
395  }
std::vector< std::vector< std::string > > data
Here is the call graph for this function:

◆ padding()

◆ red()

table_formatter& Gambit::table_formatter::red ( int  i = -1,
int  j = -1 
)
inline

Definition at line 342 of file table_formatter.hpp.

References set_pt_flag().

Referenced by Gambit::gambit_core::backend_diagnostic(), Gambit::gambit_core::ff_backend_diagnostic(), and Gambit::Scanner::Plugins::print_plugins().

343  {
344  return set_pt_flag(RED, (i == -1 ? row : i) , (j == -1 ? col : j));
345  }
table_formatter & set_pt_flag(const unsigned char flag, int i, int j)
static const unsigned char RED
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

table_formatter& Gambit::table_formatter::reset ( int  i = -1,
int  j = -1 
)
inline

Definition at line 337 of file table_formatter.hpp.

References reset_pt_flag().

338  {
339  return reset_pt_flag(RESET, (i == -1 ? row : i) , (j == -1 ? col : j));
340  }
table_formatter & reset_pt_flag(const unsigned char flag, int i, int j)
static const unsigned char RESET
Here is the call graph for this function:

◆ reset_col_flag()

table_formatter& Gambit::table_formatter::reset_col_flag ( const unsigned char  flag,
int  i 
)
inline

Definition at line 282 of file table_formatter.hpp.

Referenced by left_justify().

283  {
284  if (i < (int)col_flags.size())
285  col_flags[i] = flag;
286 
287  return *this;
288  }
std::vector< unsigned char > col_flags
Here is the caller graph for this function:

◆ reset_pt_flag()

table_formatter& Gambit::table_formatter::reset_pt_flag ( const unsigned char  flag,
int  i,
int  j 
)
inline

Definition at line 266 of file table_formatter.hpp.

Referenced by reset().

267  {
268  std::pair<int, int> key(i, j);
269  flags[key] = flag;
270 
271  return *this;
272  }
std::map< std::pair< int, int >, unsigned char > flags
Here is the caller graph for this function:

◆ reset_row_flag()

table_formatter& Gambit::table_formatter::reset_row_flag ( const unsigned char  flag,
int  i 
)
inline

Definition at line 274 of file table_formatter.hpp.

Referenced by newline().

275  {
276  if (i < (int)row_flags.size())
277  row_flags[i] = flag;
278 
279  return *this;
280  }
std::vector< unsigned char > row_flags
Here is the caller graph for this function:

◆ right_justify()

table_formatter& Gambit::table_formatter::right_justify ( int  j = -1)
inline

Definition at line 367 of file table_formatter.hpp.

References set_col_flag().

368  {
369  return set_col_flag(JUST_RIGHT, (j == -1 ? col : j));
370  }
table_formatter & set_col_flag(const unsigned char flag, int i)
static const unsigned char JUST_RIGHT
Here is the call graph for this function:

◆ row_pos()

int Gambit::table_formatter::row_pos ( ) const
inline

Definition at line 228 of file table_formatter.hpp.

References row.

Referenced by Gambit::gambit_core::ff_module_diagnostic().

228 {return row;}
Here is the caller graph for this function:

◆ rows()

int Gambit::table_formatter::rows ( ) const
inline

Definition at line 226 of file table_formatter.hpp.

Referenced by Gambit::gambit_core::ff_backend_diagnostic().

226 {return data.size();}
std::vector< std::vector< std::string > > data
Here is the caller graph for this function:

◆ set_col_flag()

table_formatter& Gambit::table_formatter::set_col_flag ( const unsigned char  flag,
int  i 
)
inline

Definition at line 322 of file table_formatter.hpp.

Referenced by center_justify(), and right_justify().

323  {
324  if (i < (int)col_flags.size())
325  {
326  if (bool(col_flags[i] & JUST) && bool(flag & JUST))
327  {
328  col_flags[i] &= ~JUST;
329  }
330 
331  col_flags[i] |= flag;
332  }
333 
334  return *this;
335  }
std::vector< unsigned char > col_flags
static const unsigned char JUST
Here is the caller graph for this function:

◆ set_pt_flag()

table_formatter& Gambit::table_formatter::set_pt_flag ( const unsigned char  flag,
int  i,
int  j 
)
inline

Definition at line 291 of file table_formatter.hpp.

Referenced by bold(), green(), red(), underline(), and yellow().

292  {
293  std::pair<int, int> key(i, j);
294  if (flags.find(key) == flags.end())
295  {
296  flags[key] = flag;
297  }
298  else
299  {
300  if (bool(flags[key] & COLOR) && bool(flag & COLOR))
301  {
302  flags[key] &= ~COLOR;
303  }
304  if (bool(flags[key] & JUST) && bool(flag & JUST))
305  {
306  flags[key] &= ~JUST;
307  }
308  flags[key] |= flag;
309  }
310 
311  return *this;
312  }
std::map< std::pair< int, int >, unsigned char > flags
static const unsigned char JUST
static const unsigned char COLOR
Here is the caller graph for this function:

◆ set_row_flag()

table_formatter& Gambit::table_formatter::set_row_flag ( const unsigned char  flag,
int  i 
)
inline

Definition at line 314 of file table_formatter.hpp.

Referenced by no_newline().

315  {
316  if (i < (int)row_flags.size())
317  row_flags[i] |= flag;
318 
319  return *this;
320  }
std::vector< unsigned char > row_flags
Here is the caller graph for this function:

◆ str()

std::string Gambit::table_formatter::str ( )

Definition at line 90 of file table_formatter.cpp.

References BOLD, bottom, col_flags, col_num, data, defaultWidths, flags, Gambit::get_screen_cols(), GREEN, int, JUST_CENTER, JUST_RIGHT, minWidths, pad, RED, row_flags, titles, top, UNDERLINE, wrap, WRAP, Gambit::wrap_lines(), and YELLOW.

Referenced by Gambit::gambit_core::backend_diagnostic(), Gambit::gambit_core::capability_diagnostic(), Gambit::gambit_core::ff_backend_diagnostic(), Gambit::gambit_core::ff_module_diagnostic(), Gambit::gambit_core::model_diagnostic(), Gambit::gambit_core::module_diagnostic(), operator[](), Gambit::Scanner::Plugins::print_plugins(), and Gambit::Scanner::Plugins::Plugin_Loader::print_priors().

91  {
92  int cols_screen = get_screen_cols();
93  int cols_tot = 0;
94  int row_num = data.size();
95  int col_last = col_num - 1;
96  int row_last = row_num - 1;
97  std::vector<int> col_sizes;
98  std::stringstream out;
99  bool overflow = false;
100 
101  if (cols_screen > 0)
102  {
103  col_sizes = std::vector<int>(col_num, (cols_screen)/col_num);
104  col_sizes[col_last] += cols_screen%col_num;
105  }
106  else
107  {
108  col_sizes = defaultWidths;
109  }
110 
111  if (wrap)
112  {
113  wrap_lines (data, col_sizes, minWidths, pad, &row_flags);
114  wrap_lines (titles, col_sizes, minWidths, pad);
115  }
116 
117  std::vector<int> max_col(col_num, 0);
118 
119  for (auto it = titles.begin(), end = titles.end(); it != end; ++it)
120  {
121  for (int i = 0; i < col_num; i++)
122  {
123  if ((unsigned int)max_col[i] < (*it)[i].length())
124  max_col[i] = (*it)[i].length();
125  }
126  }
127 
128  for (auto it = data.begin(), end = data.end(); it != end; ++it)
129  {
130  for (int i = 0; i < col_num; i++)
131  {
132  if ((*it)[i].length() > (unsigned int)(max_col[i]))
133  max_col[i] = (*it)[i].length();
134 
135  }
136  }
137 
138  if (pad > 0) for (int i = 0; i < col_last; i++)
139  {
140  max_col[i] += pad;
141  }
142 
143  for (int i = 0; i < col_last; i++)
144  {
145  if (col_sizes[i] < max_col[i])
146  {
147  col_sizes[i+1] -= (max_col[i] - col_sizes[i]);
148  col_sizes[i] = max_col[i];
149  }
150  }
151 
152  if (col_num > 1)
153  {
154  if (col_sizes[col_last] < max_col[col_last])
155  {
156  int diff = max_col[col_last] - col_sizes[col_last];
157  bool changed = true;
158  while (diff > 0 && changed)
159  {
160  changed = false;
161  for (int i = 0; i < col_last; i++)
162  {
163  if (col_sizes[i] > max_col[i] && diff > 0)
164  {
165  col_sizes[col_last]++;
166  col_sizes[i]--;
167  diff--;
168  changed = true;
169  }
170  }
171  }
172 
173  if (diff > 0)
174  {
175  col_sizes[col_last] = max_col[col_last];
176  overflow = true;
177  }
178  }
179  }
180 
181  std::string spaces(pad, ' ');
182 
183  std::vector<std::ios_base::fmtflags> ff(col_num);
184  for (int i = 0; i < col_num; i++)
185  {
186  if (col_flags[i] & JUST_RIGHT)
187  {
188  ff[i] = std::ios::right;
189  }
190  else if (col_flags[i] & JUST_CENTER)
191  {
192  ff[i] = std::ios::left;
193  }
194  else
195  {
196  ff[i] = std::ios::left;
197  }
198 
199  cols_tot += col_sizes[i];
200  }
201 
202  if (pad > 0) for (int i = 0; i < col_last; i++)
203  {
204  col_sizes[i] -= pad;
205  }
206 
207  if (overflow && cols_screen > 0)
208  out << "\x1b[33;01m" << std::setw(cols_screen) << ">>> more here >>>" << "\x1b[0m" << std::endl;
209 
210  if(top)
211  {
212  out << "\x1b[01m\x1b[04m" << std::setw(cols_tot) << "" << "\x1b[0m";
213  }
214  out << std::endl;
215 
216  for (auto it = titles.begin(), end = titles.end(); it != end; ++it)
217  {
218  if (it == end - 1)
219  {
220  out << "\x1b[01m\x1b[04m";
221  }
222  else
223  {
224  out << "\x1b[01m";
225  }
226  for (int i = 0; i < col_num; i++)
227  {
228  out << std::setiosflags(ff[i]);
229  if (col_flags[i] & JUST_CENTER)
230  out << std::setw(col_sizes[i]) << std::string((col_sizes[i]-it->size())/2, ' ') + (*it)[i];
231  else
232  out << std::setw(col_sizes[i]) << (*it)[i];
233  out << std::resetiosflags(ff[i]);
234 
235  if (i < col_last)
236  out << spaces;
237  }
238  out << "\x1b[0m" << std::endl;
239  }
240 
241  out << std::endl;
242 
243  for (int i = 0; i < row_num; i++)
244  {
245  if (bottom && i == row_last && bool(row_flags[i] & WRAP))
246  {
247  out << "\x1b[01m\x1b[04m";
248  }
249  else
250  {
251  out << "\x1b[0m";
252  }
253 
254  for (int j = 0; j < col_num; j++)
255  {
256  std::pair<int, int> key(i, j);
257  if (flags.find(key) == flags.end())
258  {
259  out << std::setiosflags(ff[j]);
260  if (col_flags[j] & JUST_CENTER)
261  out << std::setw(col_sizes[j]) << std::string((col_sizes[j]-data[i][j].size())/2, ' ') + data[i][j];
262  else
263  out << std::setw(col_sizes[j]) << data[i][j];
264  out << std::resetiosflags(ff[j]);
265  }
266  else
267  {
268  out << std::setiosflags(ff[j]);
269  if (flags[key] & RED)
270  {
271  out << "\x1b[31;01m";
272  }
273  if (flags[key] & GREEN)
274  {
275  out << "\x1b[32;01m";
276  }
277  if (flags[key] & YELLOW)
278  {
279  out << "\x1b[33;01m";
280  }
281  if (flags[key] & BOLD)
282  {
283  out << "\x1b[01m";
284  }
285  if (flags[key] & UNDERLINE)
286  {
287  out << "\x1b[04m";
288  }
289  if (col_flags[j] & JUST_CENTER)
290  {
291  out << std::setw(col_sizes[j]) << std::string((col_sizes[j]-data[i][j].size())/2, ' ') + data[i][j];
292  }
293  else
294  {
295  out << std::setw(col_sizes[j]) << data[i][j];
296  }
297  out << "\x1b[0m";
298  out << std::resetiosflags(ff[j]);
299  }
300 
301  if (j < col_last)
302  out << spaces;
303  }
304 
305  if (bool(row_flags[i] & WRAP))
306  {
307  if (bottom && i == row_last)
308  {
309  out << "\x1b[0m";
310  }
311  out << std::endl;
312  }
313  else
314  {
315  out << "\n";
316  if (bottom && i == row_last)
317  {
318  out << "\x1b[01m\x1b[04m" << std::setw(cols_tot) << "" << "\x1b[0m";
319  }
320  out << std::endl;
321  }
322  }
323 
324  out << std::flush;
325 
326  return out.str();
327  }
std::map< std::pair< int, int >, unsigned char > flags
static const unsigned char UNDERLINE
static const unsigned char GREEN
int get_screen_cols()
static const unsigned char JUST_CENTER
std::vector< int > defaultWidths
void wrap_lines(std::vector< std::vector< std::string >> &data_in, const std::vector< int > &widths, const std::vector< int > &minWidths, double pad, std::vector< unsigned char > *row_flags=0)
static const unsigned char BOLD
static const unsigned char JUST_RIGHT
static const unsigned char RED
std::vector< std::vector< std::string > > data
DS5_MSPCTM DS_INTDOF int
std::vector< int > minWidths
std::vector< unsigned char > col_flags
static const unsigned char WRAP
std::vector< unsigned char > row_flags
static const unsigned char YELLOW
std::vector< std::vector< std::string > > titles
Here is the call graph for this function:
Here is the caller graph for this function:

◆ top_line()

void Gambit::table_formatter::top_line ( bool  b)
inline

Definition at line 198 of file table_formatter.hpp.

References b.

Referenced by Gambit::gambit_core::ff_backend_diagnostic().

198 {top = b;}
START_MODEL b
Definition: demo.hpp:235
Here is the caller graph for this function:

◆ underline()

table_formatter& Gambit::table_formatter::underline ( int  i = -1,
int  j = -1 
)
inline

Definition at line 362 of file table_formatter.hpp.

References set_pt_flag().

363  {
364  return set_pt_flag(UNDERLINE, (i == -1 ? row : i) , (j == -1 ? col : j));
365  }
static const unsigned char UNDERLINE
table_formatter & set_pt_flag(const unsigned char flag, int i, int j)
Here is the call graph for this function:

◆ wrap_around()

void Gambit::table_formatter::wrap_around ( bool  b)
inline

Definition at line 197 of file table_formatter.hpp.

References b.

197 {wrap = b;}
START_MODEL b
Definition: demo.hpp:235

◆ yellow()

table_formatter& Gambit::table_formatter::yellow ( int  i = -1,
int  j = -1 
)
inline

Definition at line 352 of file table_formatter.hpp.

References set_pt_flag().

353  {
354  return set_pt_flag(YELLOW, (i == -1 ? row : i) , (j == -1 ? col : j));
355  }
table_formatter & set_pt_flag(const unsigned char flag, int i, int j)
static const unsigned char YELLOW
Here is the call graph for this function:

Member Data Documentation

◆ BOLD

const unsigned char Gambit::table_formatter::BOLD = 0x80
static

Definition at line 149 of file table_formatter.hpp.

Referenced by str().

◆ bottom

bool Gambit::table_formatter::bottom
private

Definition at line 124 of file table_formatter.hpp.

Referenced by str().

◆ col

int Gambit::table_formatter::col
private

Definition at line 119 of file table_formatter.hpp.

Referenced by col_pos(), and operator<<().

◆ col_flags

std::vector<unsigned char> Gambit::table_formatter::col_flags
private

Definition at line 131 of file table_formatter.hpp.

Referenced by str().

◆ col_num

const int Gambit::table_formatter::col_num
private

Definition at line 118 of file table_formatter.hpp.

Referenced by cols(), and str().

◆ COLOR

const unsigned char Gambit::table_formatter::COLOR = 0x07
static

Definition at line 148 of file table_formatter.hpp.

◆ data

std::vector<std::vector<std::string> > Gambit::table_formatter::data
private

Definition at line 127 of file table_formatter.hpp.

Referenced by str().

◆ defaultWidths

std::vector<int> Gambit::table_formatter::defaultWidths
private

Definition at line 125 of file table_formatter.hpp.

Referenced by str().

◆ flags

std::map<std::pair<int, int>, unsigned char> Gambit::table_formatter::flags
private

Definition at line 129 of file table_formatter.hpp.

Referenced by str().

◆ GREEN

const unsigned char Gambit::table_formatter::GREEN = 0x02
static

Definition at line 146 of file table_formatter.hpp.

Referenced by str().

◆ JUST

const unsigned char Gambit::table_formatter::JUST = 0x30
static

Definition at line 152 of file table_formatter.hpp.

◆ JUST_CENTER

const unsigned char Gambit::table_formatter::JUST_CENTER = 0x20
static

Definition at line 151 of file table_formatter.hpp.

Referenced by str().

◆ JUST_RIGHT

const unsigned char Gambit::table_formatter::JUST_RIGHT = 0x10
static

Definition at line 150 of file table_formatter.hpp.

Referenced by str().

◆ minWidths

std::vector<int> Gambit::table_formatter::minWidths
private

Definition at line 126 of file table_formatter.hpp.

Referenced by str().

◆ pad

int Gambit::table_formatter::pad
private

Definition at line 121 of file table_formatter.hpp.

Referenced by str().

◆ RED

const unsigned char Gambit::table_formatter::RED = 0x01
static

Definition at line 145 of file table_formatter.hpp.

Referenced by str().

◆ RESET

const unsigned char Gambit::table_formatter::RESET = 0x00
static

Definition at line 144 of file table_formatter.hpp.

◆ row

int Gambit::table_formatter::row
private

Definition at line 120 of file table_formatter.hpp.

Referenced by operator<<(), and row_pos().

◆ row_flags

std::vector<unsigned char> Gambit::table_formatter::row_flags
private

Definition at line 130 of file table_formatter.hpp.

Referenced by str().

◆ titles

std::vector<std::vector<std::string> > Gambit::table_formatter::titles
private

Definition at line 128 of file table_formatter.hpp.

Referenced by str().

◆ top

bool Gambit::table_formatter::top
private

Definition at line 123 of file table_formatter.hpp.

Referenced by str().

◆ UNDERLINE

const unsigned char Gambit::table_formatter::UNDERLINE = 0x40
static

Definition at line 153 of file table_formatter.hpp.

Referenced by str().

◆ wrap

bool Gambit::table_formatter::wrap
private

Definition at line 122 of file table_formatter.hpp.

Referenced by str().

◆ WRAP

const unsigned char Gambit::table_formatter::WRAP = 0x80
static

Definition at line 154 of file table_formatter.hpp.

Referenced by str().

◆ YELLOW

const unsigned char Gambit::table_formatter::YELLOW = 0x04
static

Definition at line 147 of file table_formatter.hpp.

Referenced by str().


The documentation for this class was generated from the following files: