GEOS
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Attributes | List of all members
geos::TableTextFormatter Class Reference

Class to format data in a formatted text format (for log output typically, expecting fixed character size). More...

#include <TableFormatter.hpp>

Inheritance diagram for geos::TableTextFormatter:
Inheritance graph
[legend]

Public Member Functions

 TableTextFormatter ()
 Construct a default Table Formatter without layout specification (to only insert data in it, without any column / title). Feature is not tested.
 
 TableTextFormatter (TableLayout const &tableLayout)
 Construct a new TableFormatter from a tableLayout. More...
 
string toString () const
 
template<typename DATASOURCE >
string toString (DATASOURCE const &tableData) const
 Convert a data source to a table string. More...
 
void toStream (std::ostream &outputStream) const
 Output the formatted data to a stream. Adds appropriate messages to the error list when the operation fails. More...
 
template<typename DATASOURCE >
void toStream (std::ostream &outputStream, DATASOURCE const &tableData) const
 Output the formatted data to a stream. Adds appropriate messages to the error list when the operation fails. More...
 
template<>
string toString (TableData const &tableData) const
 Convert a TableData to a table string. More...
 
template<>
string toString (TableFunction const &tableData) const
 Template specialisation to convert a TableFunction to a CSV string. More...
 
- Public Member Functions inherited from geos::TableFormatter
TableErrorListinggetErrorsList () const
 

Protected Types

using ColumnWidthModifier = std::function< void(stdVector< size_t > &) >
 A functor which allow to customize the columns width after their computation.
 

Protected Member Functions

void initalizeTableGrids (PreparedTableLayout const &tableLayout, TableData const &tableData, CellLayoutRows &dataCellsLayout, CellLayoutRows &headerCellsLayout, CellLayoutRows &errorCellsLayout, size_t &tableTotalWidth, ColumnWidthModifier columnWidthModifier) const
 Initializes the table layout with the given table data and prepares necessary layouts for headers and data cells. More...
 
void outputTableHeader (std::ostream &tableOutput, PreparedTableLayout const &tableLayout, CellLayoutRows const &headerCellsLayout, string_view separatorLine) const
 Outputs the top part of the formatted table to the provided output stream. More...
 
void outputTableData (std::ostream &tableOutput, PreparedTableLayout const &tableLayout, CellLayoutRows const &dataCellsLayout) const
 Outputs the data part of the formatted table to the provided output stream. More...
 
void outputTableFooter (std::ostream &tableOutput, PreparedTableLayout const &tableLayout, CellLayoutRows &errorCellsLayout, string_view separatorLine, bool hasData) const
 Outputs the bottom part of the formatted table to the provided output stream. More...
 
- Protected Member Functions inherited from geos::TableFormatter
 TableFormatter ()
 Construct a default Table Formatter without layout specification (to only insert data in it, without any column / title). Feature is not tested.
 
 TableFormatter (TableLayout const &tableLayout)
 Construct a new Table Formatter from a tableLayout. More...
 
void toStreamImpl (std::ostream &outputStream, string_view content) const
 Implements the actual writing of content to an output stream. Adds appropriate messages to the error list when the operation fails. More...
 

Static Protected Attributes

static constexpr char m_verticalLine = '|'
 symbol for separator construction
 
static constexpr char m_horizontalLine = '-'
 for the extremity of a row
 

Additional Inherited Members

- Public Types inherited from geos::TableFormatter
using RowsCellInput = stdVector< stdVector< TableData::CellData > >
 Represent the TableData values.
 
using CellLayoutRows = stdVector< CellLayoutRow >
 Represent a table section (title + header or values) layout: view on the data and its layout settings.
 
- Protected Attributes inherited from geos::TableFormatter
PreparedTableLayout const m_tableLayout
 Layout for a table.
 
std::unique_ptr< geos::TableErrorListingm_errors = std::make_unique< geos::TableErrorListing >()
 Class used for listing all errors that may have occured during table generation.
 

Detailed Description

Class to format data in a formatted text format (for log output typically, expecting fixed character size).

Definition at line 195 of file TableFormatter.hpp.

Constructor & Destructor Documentation

◆ TableTextFormatter()

geos::TableTextFormatter::TableTextFormatter ( TableLayout const &  tableLayout)

Construct a new TableFormatter from a tableLayout.

Parameters
tableLayoutContain all tableColumnData names and optionnaly the table title

Member Function Documentation

◆ initalizeTableGrids()

void geos::TableTextFormatter::initalizeTableGrids ( PreparedTableLayout const &  tableLayout,
TableData const &  tableData,
CellLayoutRows dataCellsLayout,
CellLayoutRows headerCellsLayout,
CellLayoutRows errorCellsLayout,
size_t tableTotalWidth,
ColumnWidthModifier  columnWidthModifier 
) const
protected

Initializes the table layout with the given table data and prepares necessary layouts for headers and data cells.

Parameters
tableLayoutA reference to the TableLayout object.
tableDataA constant reference to the TableData object, which contains the actual data for the table.
headerCellsLayoutA reference to a CellLayoutRows where the header cells will be populated.
dataCellsLayoutA reference to a CellLayoutRows where the data cells will be populated.
errorCellsLayoutA reference to a CellLayoutRows where the error cells will be populated.
tableTotalWidthA string that will be used as the table separator line
columnWidthModifierA functor which allow to customize the columns width after their computation.

◆ outputTableData()

void geos::TableTextFormatter::outputTableData ( std::ostream &  tableOutput,
PreparedTableLayout const &  tableLayout,
CellLayoutRows const &  dataCellsLayout 
) const
protected

Outputs the data part of the formatted table to the provided output stream.

Parameters
tableOutputA reference to an std::ostream where the formatted table will be written.
tableLayoutThe layout of the table
dataCellsLayoutThe data rows in a grid layout

◆ outputTableFooter()

void geos::TableTextFormatter::outputTableFooter ( std::ostream &  tableOutput,
PreparedTableLayout const &  tableLayout,
CellLayoutRows errorCellsLayout,
string_view  separatorLine,
bool  hasData 
) const
protected

Outputs the bottom part of the formatted table to the provided output stream.

Parameters
tableOutputA reference to an std::ostream where the formatted table will be written.
tableLayoutThe layout of the table
separatorLineA string that will be used as the table separator line
errorCellsLayoutThe layout of the error rows
hasDataIndicates whether there is data in the table TableData.

◆ outputTableHeader()

void geos::TableTextFormatter::outputTableHeader ( std::ostream &  tableOutput,
PreparedTableLayout const &  tableLayout,
CellLayoutRows const &  headerCellsLayout,
string_view  separatorLine 
) const
protected

Outputs the top part of the formatted table to the provided output stream.

Parameters
tableOutputA reference to an std::ostream where the formatted table will be written.
tableLayoutThe layout of the table
headerCellsLayoutThe header rows in a grid layout
separatorLineA string that will be used as the table separator line

◆ toStream() [1/2]

void geos::TableTextFormatter::toStream ( std::ostream &  outputStream) const
inline

Output the formatted data to a stream. Adds appropriate messages to the error list when the operation fails.

See also
toString()
Parameters
outputStreamThe stream to write the content to.

Definition at line 233 of file TableFormatter.hpp.

◆ toStream() [2/2]

template<typename DATASOURCE >
void geos::TableTextFormatter::toStream ( std::ostream &  outputStream,
DATASOURCE const &  tableData 
) const
inline

Output the formatted data to a stream. Adds appropriate messages to the error list when the operation fails.

See also
toString( DATASOURCE const & tableData )
Template Parameters
DATASOURCEThe type of the source to convert
Parameters
tableDataThe data source to convert.
outputStreamThe stream to write the content to.

Definition at line 244 of file TableFormatter.hpp.

◆ toString() [1/4]

string geos::TableTextFormatter::toString ( ) const
Returns
A TableLayout string representation, The TableTextFormatter receives hasn't received any data, so only the header part is returned.

◆ toString() [2/4]

template<typename DATASOURCE >
string geos::TableTextFormatter::toString ( DATASOURCE const &  tableData) const

Convert a data source to a table string.

Template Parameters
DATASOURCEThe type of the source to convert
Parameters
tableDataThe data source to convert.
Returns
The table string representation of the TableData.

◆ toString() [3/4]

template<>
string geos::TableTextFormatter::toString ( TableData const &  tableData) const

Convert a TableData to a table string.

Parameters
tableDataThe TableData to convert.
Returns
The table string representation of the TableData.

◆ toString() [4/4]

template<>
string geos::TableTextFormatter::toString ( TableFunction const &  tableData) const

Template specialisation to convert a TableFunction to a CSV string.

Parameters
tableDataThe TableFunction object to convert.
Returns
The CSV string representation of the TableFunction.

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