Class columnify (o2scl)¶
-
class
o2scl
::
columnify
¶ Create nicely formatted columns from a table of strings.
This is a brute-force approach of order \( \mathrm{ncols} \times \mathrm{nrows} \). The column widths and spacings of are computed by exhaustively examining all strings in every column.
- Idea for Future:
Create a single column version of add_spaces().
- Idea for Future:
Create a function which accepts delimited strings (e.g. like csv) instead of vector<vector<string>>.
- Idea for Future:
Move the screenify() functionality from misc.h into this class?
- Idea for Future:
It might be better to allow the string table to be specified with iterators.
- Idea for Future:
Consider a function which takes a o2scl::table object as input?
Public Functions
-
columnify
()¶
-
template<class
mat_string_t
, classvec_string_t
, classvec_int_t
>
intalign
(const mat_string_t &table, size_t ncols, size_t nrows, vec_string_t &ctable, vec_int_t &align_spec)¶ Take
table
and create a new objectctable
with appropriately formatted columns.The table of strings should be stored in
table
in “column-major” order (table[ncols][nrows]
), so thattable
has the interpretation of a set of columns to be aligned. Before calling align(),ctable
should be allocated so that at least the firstnrows
entries can be assigned, andalign_spec
should containncols
entries specifying the style of alignment for each column.The first argument can be any type which is accessible using two applications of
operator[]
, such asstring **
,vector<string>[]
, orvector<vector<string> >
-
template<class
mat_string_t
, classvec_int_t
>
intadd_spaces
(const mat_string_t &table_in, size_t ncols, size_t nrows, vec_int_t &align_spec, mat_string_t &table_out)¶ Add enough spaces to ensure all columns have the same width.
Public Members
-
int
table_lines
¶ Specification for table lines (experimental)
Public Static Attributes
-
const int
align_left
= 1¶ Align the left-hand sides.
-
const int
align_right
= 2¶ Align the right-hand sides.
-
const int
align_lmid
= 3¶ Center, slightly to the left if spacing is uneven.
-
const int
align_rmid
= 4¶ Center, slightly to the right if spacing is uneven.
-
const int
align_dp
= 5¶ Align with decimal points.
-
const int
align_lnum
= 6¶ Align negative numbers to the left and use a space for positive numbers.