ROSE  0.11.106.0
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 <Rose/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. More...
 
 FormattedTable (size_t nRows, size_t nColumns)
 Construct a table with a certain number of cells. More...
 
const std::string & get (size_t rowIdx, size_t colIdx) const
 Get the data for a table cell. More...
 
void print (std::ostream &) const
 Print a table. More...
 
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 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.

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.

Constructor & Destructor Documentation

Rose::FormattedTable::FormattedTable ( )

Construct an empty table.

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

Construct a table with a certain number of cells.

Member Function Documentation

Format Rose::FormattedTable::format ( ) const

Property: Output format.

How the table is formatted in general.

void Rose::FormattedTable::format ( Format  )

Property: Output format.

How the table is formatted in general.

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.

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.

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.

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.

size_t Rose::FormattedTable::nRows ( ) const

Number of rows or columns of data.

See also, resize.

size_t Rose::FormattedTable::nColumns ( ) const

Number of rows or columns of data.

See also, resize.

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().

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.

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().

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().

const std::string& Rose::FormattedTable::get ( size_t  rowIdx,
size_t  colIdx 
) const

Get the data for a table cell.

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.

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.

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.

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.

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.

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.

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.

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.

void Rose::FormattedTable::print ( std::ostream &  ) const

Print a table.


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