ROSE  0.11.96.11
Classes | Public Types | Public Member Functions | List of all members
Rose::FormattedTable Class Reference

Description

Class for printing nicely formattated tables.

A table is a two-dimensional grid containing cells. A FormattedTable object holds information about how to format cells, functions to populate the cells, and functions to print the table.

Definition at line 15 of file FormattedTable.h.

#include <FormattedTable.h>

Classes

class  CellProperties
 Properties for a particular cell. More...
 

Public Types

enum  Format {
  Format::PLAIN,
  Format::HTML,
  Format::CSV,
  Format::SHELL
}
 Format when generating output. More...
 
enum  Alignment {
  Alignment::LEFT,
  Alignment::RIGHT,
  Alignment::CENTER
}
 How text is aligned in a table cell. More...
 

Public Member Functions

 FormattedTable ()
 Construct an empty table.
 
 FormattedTable (size_t nRows, size_t nColumns)
 Construct a table with a certain number of cells.
 
const std::string & get (size_t rowIdx, size_t colIdx) const
 Get the data for a table cell.
 
void print (std::ostream &) const
 Print a table.
 
Format format () const
 Property: Output format. More...
 
void format (Format)
 Property: Output format. More...
 
const std::string & indentation () const
 Property: Indentation. More...
 
void indentation (const std::string &)
 Property: Indentation. More...
 
void resize (size_t nRows, size_t nColumns)
 Resize the table data. More...
 
void resize (size_t nRows)
 Resize the table data. More...
 
size_t nRows () const
 Number of rows or columns of data. More...
 
size_t nColumns () const
 Number of rows or columns of data. More...
 
void insert (size_t rowIdx, size_t columnIdx, const std::string &repr)
 Insert data into a table. More...
 
void insert (size_t rowIdx, size_t columnIdx, const std::string &repr, const CellProperties &)
 Insert data into a table. More...
 
template<typename T >
void insert (size_t rowIdx, size_t columnIdx, const T &value)
 Insert data into a table. More...
 
template<typename T >
void insert (size_t rowIdx, size_t columnIdx, const T &value, const CellProperties &prop)
 Insert data into a table. More...
 
const CellPropertiescellProperties (size_t rowIdx, size_t columnIdx) const
 Properties for a data cell. More...
 
void cellProperties (size_t rowIdx, size_t columnIdx, const CellProperties &)
 Properties for a data cell. More...
 
size_t nColumnHeaderRows () const
 Property: Number of column header rows. More...
 
void nColumnHeaderRows (size_t)
 Property: Number of column header rows. More...
 
const std::string & columnHeader (size_t rowIdx, size_t columnIdx) const
 Property: Name for column headers. More...
 
void columnHeader (size_t rowIdx, size_t columnIdx, const std::string &title)
 Property: Name for column headers. More...
 
const CellPropertiescolumnHeaderProperties (size_t rowIdx, size_t columnIdx) const
 Properties for column headers. More...
 
void columnHeaderProperties (size_t rowIdx, size_t columnIdx, const CellProperties &)
 Properties for column headers. More...
 

Member Enumeration Documentation

◆ Format

Format when generating output.

Enumerator
PLAIN 

Use ASCII-art to draw the table borders.

HTML 

Generate HTML output.

CSV 

Comma separated values, RFC 4180.

SHELL 

A format friendly for shell scripts.

No header columns. Lines are separated by ASCII line feed characters (not carriage returns). Values are separated by horizontal tab characters. Line feeds and tabs are escaped in the values. Shell $" style escaping is used (C-like) in addition to escaped tabs and linefeeds.

Definition at line 22 of file FormattedTable.h.

◆ Alignment

How text is aligned in a table cell.

Enumerator
LEFT 

Text is aligned to the left edge of the cell.

RIGHT 

Text is aligned to the right edge of the cell.

CENTER 

Text is centered in the cell.

Definition at line 35 of file FormattedTable.h.

Member Function Documentation

◆ format() [1/2]

Format Rose::FormattedTable::format ( ) const

Property: Output format.

How the table is formatted in general.

◆ format() [2/2]

void Rose::FormattedTable::format ( Format  )

Property: Output format.

How the table is formatted in general.

◆ indentation() [1/2]

const std::string& Rose::FormattedTable::indentation ( ) const

Property: Indentation.

This property holds a string that is printed at the beginning of every line of output. This used for the plain-text format; it's ignored for HTML output.

◆ indentation() [2/2]

void Rose::FormattedTable::indentation ( const std::string &  )

Property: Indentation.

This property holds a string that is printed at the beginning of every line of output. This used for the plain-text format; it's ignored for HTML output.

◆ resize() [1/2]

void Rose::FormattedTable::resize ( size_t  nRows,
size_t  nColumns 
)

Resize the table data.

Making a table smaller will remove data cells but not row and column properties. Making a table larger will insert cells with empty data, and if necessary create default row and column properties.

◆ resize() [2/2]

void Rose::FormattedTable::resize ( size_t  nRows)

Resize the table data.

Making a table smaller will remove data cells but not row and column properties. Making a table larger will insert cells with empty data, and if necessary create default row and column properties.

◆ nRows()

size_t Rose::FormattedTable::nRows ( ) const

Number of rows or columns of data.

See also, resize.

◆ nColumns()

size_t Rose::FormattedTable::nColumns ( ) const

Number of rows or columns of data.

See also, resize.

◆ insert() [1/4]

void Rose::FormattedTable::insert ( size_t  rowIdx,
size_t  columnIdx,
const std::string &  repr 
)

Insert data into a table.

If the row and/or column number is outside the current size of the table, then the table is automatically resized, but it's more efficient to resize the table before adding data.

Referenced by insert().

Here is the caller graph for this function:

◆ insert() [2/4]

void Rose::FormattedTable::insert ( size_t  rowIdx,
size_t  columnIdx,
const std::string &  repr,
const CellProperties  
)

Insert data into a table.

If the row and/or column number is outside the current size of the table, then the table is automatically resized, but it's more efficient to resize the table before adding data.

◆ insert() [3/4]

template<typename T >
void Rose::FormattedTable::insert ( size_t  rowIdx,
size_t  columnIdx,
const T &  value 
)
inline

Insert data into a table.

If the row and/or column number is outside the current size of the table, then the table is automatically resized, but it's more efficient to resize the table before adding data.

Definition at line 160 of file FormattedTable.h.

References insert().

Here is the call graph for this function:

◆ insert() [4/4]

template<typename T >
void Rose::FormattedTable::insert ( size_t  rowIdx,
size_t  columnIdx,
const T &  value,
const CellProperties prop 
)
inline

Insert data into a table.

If the row and/or column number is outside the current size of the table, then the table is automatically resized, but it's more efficient to resize the table before adding data.

Definition at line 163 of file FormattedTable.h.

References insert().

Here is the call graph for this function:

◆ cellProperties() [1/2]

const CellProperties& Rose::FormattedTable::cellProperties ( size_t  rowIdx,
size_t  columnIdx 
) const

Properties for a data cell.

When inserting properties, the table is automatically extended.

◆ cellProperties() [2/2]

void Rose::FormattedTable::cellProperties ( size_t  rowIdx,
size_t  columnIdx,
const CellProperties  
)

Properties for a data cell.

When inserting properties, the table is automatically extended.

◆ nColumnHeaderRows() [1/2]

size_t Rose::FormattedTable::nColumnHeaderRows ( ) const

Property: Number of column header rows.

Column headers appear above the data and the number of column header rows is independent of the number of data rows that's returned by nRows. When the number of column header rows is decreased, the affected column header names are deleted; when the number of rows is increased, the new titles are set to empty strings.

◆ nColumnHeaderRows() [2/2]

void Rose::FormattedTable::nColumnHeaderRows ( size_t  )

Property: Number of column header rows.

Column headers appear above the data and the number of column header rows is independent of the number of data rows that's returned by nRows. When the number of column header rows is decreased, the affected column header names are deleted; when the number of rows is increased, the new titles are set to empty strings.

◆ columnHeader() [1/2]

const std::string& Rose::FormattedTable::columnHeader ( size_t  rowIdx,
size_t  columnIdx 
) const

Property: Name for column headers.

Column headers occupy one or more rows, but the rows do not count as data. Column information is extended as necessary when new column headers are added. When querying a column header that doesn't exist, an empty string is returned.

◆ columnHeader() [2/2]

void Rose::FormattedTable::columnHeader ( size_t  rowIdx,
size_t  columnIdx,
const std::string &  title 
)

Property: Name for column headers.

Column headers occupy one or more rows, but the rows do not count as data. Column information is extended as necessary when new column headers are added. When querying a column header that doesn't exist, an empty string is returned.

◆ columnHeaderProperties() [1/2]

const CellProperties& Rose::FormattedTable::columnHeaderProperties ( size_t  rowIdx,
size_t  columnIdx 
) const

Properties for column headers.

These are the properties for formatting column header cells. Column header row indices are indpendent of the data cell indices.

◆ columnHeaderProperties() [2/2]

void Rose::FormattedTable::columnHeaderProperties ( size_t  rowIdx,
size_t  columnIdx,
const CellProperties  
)

Properties for column headers.

These are the properties for formatting column header cells. Column header row indices are indpendent of the data cell indices.


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