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.
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
.Todo
In class auto_format:
Allow user-specified table alignments
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.
Other variables (protected)
-
bool enabled¶
If true, automatic formatting is enabled (default true)
-
std::vector<std::string> lines¶
Output line buffer.
-
size_t precision_¶
The output precision for floating-point numbers.
Table mode (protected)
-
bool auto_tables¶
If true, try to automatically detect tables (default true)
-
size_t n_headers¶
The number of table header rows (default 0)
-
std::ostream *outs¶
Pointer to the output stream.
-
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.
Settings
-
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.
This parameter is used for o2scl::columnify::table_lines.
-
bool auto_space¶
If true, automatically add spaces between outputs (default true)
-
void precision(size_t p)¶
Set the precision of floating-point values.
Friend operators
-
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_25 &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.
Basic usage
-
auto_format()¶
Constructor.
-
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 off()¶
Disable formatting and send all output directly to
cout
.
-
void on()¶
Turn on automatic formatting (on by default)
-
void start_table()¶
Start a table.
-
void end_table()¶
End a table.
-
void done()¶
Flush all buffered output to the screen.
Other functions
-
void endline()¶
Add an endline.
-
void debug_table()¶
Debug the table by outputting detailed table information to the attached stream.
This function is useful just before end_table() is called.
-
void add_string(std::string s)¶
Add a string to the output buffer.