Public Member Functions | Static Public Attributes | List of all members
o2scl::columnify Class Reference

Create nicely formatted columns from a table of strings. More...

#include <columnify.h>

Public Member Functions

template<class mat_string_t , class vec_string_t , class vec_int_t >
int align (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 object ctable with appropriately formatted columns. More...
 

Static Public Attributes

static const int align_left =1
 Align the left-hand sides.
 
static const int align_right =2
 Align the right-hand sides.
 
static const int align_lmid =3
 Center, slightly to the left if spacing is uneven.
 
static const int align_rmid =4
 Center, slightly to the right if spacing is uneven.
 
static const int align_dp =5
 Align with decimal points.
 
static const int align_lnum =6
 Align negative numbers to the left and use a space for positive numbers.
 

Detailed Description

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:

Move the screenify() functionality from misc.h into this class?

It might be better to allow the string table to be specified with iterators.

Consider a function which takes a o2scl::table object as input?

Definition at line 57 of file columnify.h.

Member Function Documentation

◆ align()

template<class mat_string_t , class vec_string_t , class vec_int_t >
int o2scl::columnify::align ( const mat_string_t &  table,
size_t  ncols,
size_t  nrows,
vec_string_t &  ctable,
vec_int_t &  align_spec 
)
inline

The table of strings should be stored in table in "column-major" order (table[ncols][nrows]), so that table has the interpretation of a set of columns to be aligned. Before calling align(), ctable should be allocated so that at least the first nrows entries can be assigned, and align_spec should contain ncols 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 as string **, vector<string>[], or vector<vector<string> >

Definition at line 96 of file columnify.h.


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

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).