ImFusion SDK 4.3
Table Class Reference

#include <ImFusion/Base/Table.h>

A 2D table with named columns, containing strings and numbers. More...

Detailed Description

A 2D table with named columns, containing strings and numbers.

The main purpose of this class is to support seamless creation of arbitrary statistics, and then export the results as a text or CSV file. The data is added row-by-row; if add is called with the same name, a new row is started. Strings and numerical data can be mixed in a named column, all numerical values per column can be separately queried, and will also be converted to strings upon insertion with a call to add.

Public Types

using ValueType = std::variant<std::string, double>
 

Public Member Functions

 Table (bool useComma=false, bool fillRows=true)
 Constructor with optional flag to use comma as decimal separator.
 
 Table (const Table &)
 
Tableoperator= (const Table &)
 
void add (const std::string &name, const std::string &value)
 Add a string value to a column.
 
void add (const std::string &name, double value)
 Add a number to a column.
 
bool write (const std::string &filename, bool append=false, char delimiter=';') const
 Export as CSV, optionally appending values to an existing file.
 
bool read (const std::string &filename, const std::vector< std::string > &columns={})
 Imports from CSV.
 
int rows () const
 Return the number of data rows in the table (excluding the header)
 
int cols () const
 Return the number of columns in the table.
 
std::string colName (int which) const
 Return the name of a column.
 
std::vector< double > numData (const std::string &name) const
 Return numerical data for a column if available.
 
std::vector< std::stringstrData (const std::string &name) const
 Return string data for a column if available.
 
std::unordered_map< std::string, ValueTyperow (int which) const
 Return data for a row of the Table.
 

Constructor & Destructor Documentation

◆ Table()

Table ( bool useComma = false,
bool fillRows = true )

Constructor with optional flag to use comma as decimal separator.

If the useComma flag is set true, German locale is imbued, otherwise the internally used stringstream instances are not modified. The fillRows flag allows to omit certain columns, results are always added in the last available row (useful for logging applications).

Member Function Documentation

◆ write()

bool write ( const std::string & filename,
bool append = false,
char delimiter = ';' ) const

Export as CSV, optionally appending values to an existing file.

The append flag will check whether the file exists, and in that case only write the data rows, not the header. It is not checked whether the header columns are matching. A different column delimiter character may be provided to this method (semicolon is default). True is returned upon successful writing.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close