Class auto_format (o2scl_auto_format)¶
-
class auto_format¶
Automatically format output.
This class is a wrapper around output streams which performs automatic spacing and table formatting. Only scientific formatting for floating-point numbers is supported at present.
Todo
In class auto_format:
Allow user-specified table alignments
switch to columnify::add_spaces() and add more complicated table line specifications
Implement row_max
Future:
Create a replacement for std::flush
Finish automatic table detection
For automatic table detection: allow user to change the number of rows which must have the same number of ‘words’ to verify a table.
Make internal algorithm more efficient.
Note
Experimental.
This class caches each line before sending to cout, so issuing
cout << std::flush
in the middle of a line will not output the buffer to the screen.The attach() function stores a pointer to the output stream, so the user must take care to make sure this pointer is valid.
For now, this class is in its own namespace,
o2scl_auto_format
.Standard buffer
-
std::vector<std::string> lines¶
Output line buffer.
-
size_t precision_¶
The output precision for floating-point numbers.
Table mode
-
bool auto_tables¶
If true, try to automatically detect tables (default true)
-
size_t n_headers¶
The number of table header rows.
-
std::vector<std::vector<std::string>> headers¶
Headers for table mode.
-
bool inside_table¶
If true, we are currently inside a table.
-
std::vector<std::vector<std::string>> columns¶
Columns for table mode.
-
size_t next_column¶
Index of next column.
-
size_t row_max¶
Maximum number of table rows (default 1000)
-
std::vector<int> aligns¶
Alignment specifications for table columns.
-
std::ostream *outs¶
Pointer to the output stream.
-
bool align_matrices¶
If true, align the output of matrices (default true)
-
int verbose¶
Verbosity parameter (default 0)
-
int table_lines¶
Parameter for table line output.
-
friend auto_format &operator<<(auto_format &at, double d)¶
-
friend auto_format &operator<<(auto_format &at, long double d)¶
-
friend auto_format &operator<<(auto_format &at, const cpp_dec_float_35 &d)¶
-
friend auto_format &operator<<(auto_format &at, const cpp_dec_float_50 &d)¶
-
friend auto_format &operator<<(auto_format &at, const cpp_dec_float_100 &d)¶
-
template<class data_t>
friend auto_format &operator<<(auto_format &at, const boost::numeric::ublas::matrix<data_t> &vu)¶ Output a ublas matrix.
If o2scl_auto_format::auto_format::align_matrices is true, then the output is organized into a table.
-
template<class data_t>
friend auto_format &operator<<(auto_format &at, const std::vector<std::vector<data_t>> &vv)¶ Output a vector of vectors.
If o2scl_auto_format::auto_format::align_matrices is true and all of the vectors in the list have the same length, then the output is organized into a table.
-
auto_format()¶
-
void attach(std::ostream &out)¶
Attach an ostream, so that all future output goes there.
-
void unattach()¶
Clear the buffer and put all future output to
std::cout
.
-
void add_string(std::string s)¶
Add a string to the output buffer.
-
void precision(size_t p)¶
Set the precision of floating-point values.
-
void off()¶
Disable formatting and send all output directly to
cout
.
-
void on()¶
Turn on automatic formatting (on by default)
-
void endline()¶
Add an endline.
-
void done()¶
Flush all buffered output to the screen.
-
void start_table()¶
Start a table.
-
void debug_table()¶
Debug the table.
-
void end_table()¶
End a table.
Protected Attributes
-
bool enabled¶
If true, automatic formatting is enabled (default true)