Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
DataTable< TAB > Class Template Reference

#include "lib/stat/data.hpp"

Description

template<class TAB>
class lib::stat::DataTable< TAB >

Table with data values, stored persistently as CSV file.

Each row within the table represents a data record, holding a sequence of values. Values are statically typed per column, i.e. one column may hold strings, while the next column holds doubles. For actual usage it is thus necessary to define the column layout, through a sequence of column Descriptors.

Usage

Actually those Column objects serve as descriptors, but also as accessors — and they hold the actual data storage for each column, which is a std::vector<VAL> of value type VAL. There is always a current record — corresponding to the actual data value and the newest data row. For persistent storage, the sequence of rows is reversed, so the newest data appears at the top of the CSV file.

Template Parameters
TABa struct comprised of several Column objects, which hold the data and provide access to values of this specific column. Moreover, this type must define a function allColumns() to return a tuple with references to these column fields; the order of fields within this tuple also defines the order of columns within the table and persistent CSV storage.

Definition at line 185 of file data.hpp.

Static Public Attributes

static constexpr size_t columnCnt = std::tuple_size_v<decltype(std::declval<TAB>().allColumns())>
 

Public Member Functions

 DataTable (fs::path csvFile="")
 
 DataTable (CSVData const &csv)
 
bool empty () const
 
size_t size () const
 
CSVData renderCSV () const
 
void newRow ()
 
void dupRow ()
 
void dropLastRow ()
 
void reserve (size_t expectedCapacity)
 
void clear ()
 
void appendFrom (CSVData const &csv)
 
void save (size_t lineLimit=std::numeric_limits< size_t >::max(), bool backupOld=false)
 
void saveAs (fs::path newStorage, size_t lineLimit=std::numeric_limits< size_t >::max())
 

Private Member Functions

template<class OP >
void forAllColumns (OP &&doIt) const
 apply a generic Lambda to all columns
 
void loadData ()
 
void saveData (std::ofstream &csvFile, size_t lineLimit)
 
void verifyHeaderSpec (string headerLine)
 
CSVLine generateHeaderSpec () const
 
void appendRowFromCSV (string line)
 
CSVLine formatCSVRow (size_t rownum) const
 
- Private Member Functions inherited from MoveOnly
 ~MoveOnly ()=default
 
 MoveOnly ()=default
 
 MoveOnly (MoveOnly &&)=default
 
 MoveOnly (MoveOnly const &)=delete
 
MoveOnlyoperator= (MoveOnly &&)=delete
 
MoveOnlyoperator= (MoveOnly const &)=delete
 

Private Attributes

fs::path filename_
 

Constructor & Destructor Documentation

◆ DataTable() [1/2]

template<class TAB >
DataTable ( fs::path  csvFile = "")
inline

Definition at line 192 of file data.hpp.

References DataTable< TAB >::loadData().

+ Here is the call graph for this function:

◆ DataTable() [2/2]

template<class TAB >
DataTable ( CSVData const &  csv)
inline

Definition at line 198 of file data.hpp.

References DataTable< TAB >::appendFrom().

+ Here is the call graph for this function:

Member Function Documentation

◆ empty()

template<class TAB >
bool empty ( ) const
inline

Definition at line 210 of file data.hpp.

References DataTable< TAB >::size().

Referenced by DataTable< TAB >::dropLastRow(), DataTable< TAB >::dupRow(), and DataTable< TAB >::saveData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

template<class TAB >
size_t size ( ) const
inline

Definition at line 216 of file data.hpp.

References DataTable< TAB >::forAllColumns().

Referenced by DataTable< TAB >::empty(), DataTable< TAB >::newRow(), DataTable< TAB >::renderCSV(), and DataTable< TAB >::saveData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderCSV()

template<class TAB >
CSVData renderCSV ( ) const
inline

Definition at line 229 of file data.hpp.

References DataTable< TAB >::formatCSVRow(), DataTable< TAB >::generateHeaderSpec(), and DataTable< TAB >::size().

+ Here is the call graph for this function:

◆ newRow()

template<class TAB >
void newRow ( )
inline

Definition at line 246 of file data.hpp.

References DataTable< TAB >::forAllColumns(), and DataTable< TAB >::size().

Referenced by DataTable< TAB >::dupRow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dupRow()

template<class TAB >
void dupRow ( )
inline

Definition at line 257 of file data.hpp.

References DataTable< TAB >::empty(), DataTable< TAB >::forAllColumns(), and DataTable< TAB >::newRow().

+ Here is the call graph for this function:

◆ dropLastRow()

template<class TAB >
void dropLastRow ( )
inline

Definition at line 270 of file data.hpp.

References DataTable< TAB >::empty(), and DataTable< TAB >::forAllColumns().

+ Here is the call graph for this function:

◆ reserve()

template<class TAB >
void reserve ( size_t  expectedCapacity)
inline

Definition at line 282 of file data.hpp.

References DataTable< TAB >::forAllColumns().

Referenced by DataTable< TAB >::loadData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

template<class TAB >
void clear ( )
inline

Definition at line 292 of file data.hpp.

References DataTable< TAB >::forAllColumns().

+ Here is the call graph for this function:

◆ appendFrom()

template<class TAB >
void appendFrom ( CSVData const &  csv)
inline

Definition at line 302 of file data.hpp.

References DataTable< TAB >::appendRowFromCSV(), and DataTable< TAB >::verifyHeaderSpec().

Referenced by DataTable< TAB >::DataTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

template<class TAB >
void save ( size_t  lineLimit = std::numeric_limits<size_t>::max(),
bool  backupOld = false 
)
inline
Parameters
lineLimitnumber of rows to retain, back from the newest

Definition at line 315 of file data.hpp.

References std::filesystem::consolidated(), DataTable< TAB >::filename_, and DataTable< TAB >::saveData().

Referenced by DataTable< TAB >::saveAs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveAs()

template<class TAB >
void saveAs ( fs::path  newStorage,
size_t  lineLimit = std::numeric_limits<size_t>::max() 
)
inline

Definition at line 343 of file data.hpp.

References std::filesystem::consolidated(), DataTable< TAB >::filename_, and DataTable< TAB >::save().

+ Here is the call graph for this function:

◆ forAllColumns()

template<class TAB >
template<class OP >
void forAllColumns ( OP &&  doIt) const
inlineprivate

apply a generic Lambda to all columns

Definition at line 364 of file data.hpp.

References lib::meta::forEach().

Referenced by DataTable< TAB >::clear(), DataTable< TAB >::dropLastRow(), DataTable< TAB >::dupRow(), DataTable< TAB >::newRow(), DataTable< TAB >::reserve(), DataTable< TAB >::size(), and DataTable< TAB >::verifyHeaderSpec().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadData()

template<class TAB >
void loadData ( )
inlineprivate

Definition at line 371 of file data.hpp.

References DataTable< TAB >::appendRowFromCSV(), DataTable< TAB >::filename_, DataTable< TAB >::reserve(), and DataTable< TAB >::verifyHeaderSpec().

Referenced by DataTable< TAB >::DataTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveData()

template<class TAB >
void saveData ( std::ofstream &  csvFile,
size_t  lineLimit 
)
inlineprivate

Definition at line 402 of file data.hpp.

References DataTable< TAB >::empty(), DataTable< TAB >::formatCSVRow(), DataTable< TAB >::generateHeaderSpec(), and DataTable< TAB >::size().

Referenced by DataTable< TAB >::save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ verifyHeaderSpec()

template<class TAB >
void verifyHeaderSpec ( string  headerLine)
inlineprivate

Definition at line 415 of file data.hpp.

References DataTable< TAB >::filename_, and DataTable< TAB >::forAllColumns().

Referenced by DataTable< TAB >::appendFrom(), and DataTable< TAB >::loadData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generateHeaderSpec()

template<class TAB >
CSVLine generateHeaderSpec ( ) const
inlineprivate

Definition at line 430 of file data.hpp.

Referenced by DataTable< TAB >::renderCSV(), and DataTable< TAB >::saveData().

+ Here is the caller graph for this function:

◆ appendRowFromCSV()

template<class TAB >
void appendRowFromCSV ( string  line)
inlineprivate

Definition at line 443 of file data.hpp.

Referenced by DataTable< TAB >::appendFrom(), and DataTable< TAB >::loadData().

+ Here is the caller graph for this function:

◆ formatCSVRow()

template<class TAB >
CSVLine formatCSVRow ( size_t  rownum) const
inlineprivate

Definition at line 470 of file data.hpp.

Referenced by DataTable< TAB >::renderCSV(), and DataTable< TAB >::saveData().

+ Here is the caller graph for this function:

Member Data Documentation

◆ filename_

template<class TAB >
fs::path filename_
private

◆ columnCnt

template<class TAB >
constexpr size_t columnCnt = std::tuple_size_v<decltype(std::declval<TAB>().allColumns())>
staticconstexpr

Definition at line 207 of file data.hpp.

+ Inheritance diagram for DataTable< TAB >:
+ Collaboration diagram for DataTable< TAB >:

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