bpp-core3  3.0.0
bpp::Table< T > Class Template Reference

This class corresponds to a 'dataset', i.e. a table with data by rows and variable by columns. More...

#include <Bpp/Numeric/Table.h>

+ Inheritance diagram for bpp::Table< T >:
+ Collaboration diagram for bpp::Table< T >:

Public Member Functions

 Table (size_t nRow, size_t nCol)
 Build a new void Table object with nRow rows and nCol columns. More...
 
 Table (const std::vector< std::string > &colNames)
 Build a new void Table object with named columns. More...
 
 Table (const Table &table)
 
 Table (const std::vector< std::vector< T > > &vt)
 
Tableoperator= (const Table &table)
 
Tableoperator= (const std::vector< std::vector< T > > &vt)
 
Tableclone () const
 Create a copy of this object and send a pointer to it. More...
 
virtual ~Table ()
 
const std::vector< std::vector< T > > & getData () const
 
T & operator() (size_t rowIndex, size_t colIndex)
 
const T & operator() (size_t rowIndex, size_t colIndex) const
 
T & operator() (const std::string &rowName, const std::string &colName)
 
const T & operator() (const std::string &rowName, const std::string &colName) const
 
T & operator() (const std::string &rowName, size_t colIndex)
 
const T & operator() (const std::string &rowName, size_t colIndex) const
 
T & operator() (size_t rowIndex, const std::string &colName)
 
const T & operator() (size_t rowIndex, const std::string &colName) const
 
Work on columns.
size_t getNumberOfColumns () const
 
void setColumnNames (const std::vector< std::string > &colNames)
 Set the column names of this table. More...
 
const std::vector< std::string > & getColumnNames () const
 Get the column names of this table. More...
 
std::vector< std::string > & getColumnNames ()
 
std::string getColumnName (size_t index) const
 Get a given column name. More...
 
bool hasColumnNames () const
 
std::vector< T > & getColumn (size_t index)
 
const std::vector< T > & getColumn (size_t index) const
 
std::vector< T > & getColumn (const std::string &colName)
 
const std::vector< T > & getColumn (const std::string &colName) const
 
bool hasColumn (const std::string &colName) const
 Tell is a given column exists. More...
 
void deleteColumn (size_t index)
 Delete the given column. More...
 
void deleteColumn (const std::string &colName)
 Delete the given column. More...
 
void addColumn (const std::vector< T > &newColumn, int pos=-1)
 Add a new column. More...
 
void addColumn (const std::string &colName, const std::vector< T > &newColumn, int pos=-1)
 Add a new column. More...
 
void addColumn (std::string &st, const std::string &sep="\t", int pos=-1, int rowCol=-1)
 Add a new column. More...
 
void setColumn (const std::vector< T > &newColumn, size_t pos)
 Set a new column. More...
 
void setColumn (const std::string &colName, const std::vector< T > &newColumn, size_t pos)
 Set a new column. More...
 
Work on rows.
size_t getNumberOfRows () const
 
void setRowNames (const std::vector< std::string > &rowNames)
 Set the row names of this table. More...
 
std::vector< std::string > getRowNames ()
 Get the row names of this table. More...
 
const std::vector< std::string > & getRowNames () const
 
bool hasRow (const std::string &rowName) const
 Tell is a given row exists. More...
 
std::string getRowName (size_t index) const
 Get a given row name. More...
 
bool hasRowNames () const
 
std::vector< T > getRow (size_t index) const
 
std::vector< T > getRow (const std::string &rowName) const
 
void deleteRow (size_t index)
 Delete the given row. More...
 
void deleteRows (size_t index, size_t len)
 Delete the given rows. More...
 
void deleteRow (const std::string &rowName)
 Delete the given row. More...
 
void addRow (const std::vector< T > &newRow, int pos=-1)
 Add a new row. More...
 
void addRow (const std::string &rowName, const std::vector< T > &newRow, int pos=-1)
 Add a new row at a given position. More...
 
void addRow (std::string &st, const std::string &sep="\t", int pos=-1, int rowCol=-1)
 Add a new row. More...
 

Static Public Member Functions

static Table< T > * read (std::istream &in, bool byRow, const std::string &sep="\t", bool header=true, int names=-1)
 Read a table form a stream in CSV-like. More...
 
static void write (const Table &data, std::ostream &out, bool byRow, const std::string &sep="\t", bool alignHeaders=false)
 Write a Table object to stream in CVS-like format. More...
 
static void write (const Table &data, bpp::OutputStream &out, bool byRow, const std::string &sep="\t", bool alignHeaders=false)
 

Protected Attributes

size_t nRow_
 
size_t nCol_
 
std::vector< std::vector< T > > data_
 
std::vector< std::string > rowNames_
 
std::vector< std::string > colNames_
 

Detailed Description

template<class T>
class bpp::Table< T >

This class corresponds to a 'dataset', i.e. a table with data by rows and variable by columns.

Data are stored as T objects, by column.

Definition at line 66 of file Table.h.

Constructor & Destructor Documentation

◆ Table() [1/4]

template<class T >
bpp::Table< T >::Table ( size_t  nRow,
size_t  nCol 
)
inline

Build a new void Table object with nRow rows and nCol columns.

Parameters
nRowThe number of rows of the Table.
nColThe number of columns of the Table.

Definition at line 83 of file Table.h.

References bpp::Table< T >::data_.

Referenced by bpp::Table< T >::clone().

◆ Table() [2/4]

template<class T >
bpp::Table< T >::Table ( const std::vector< std::string > &  colNames)
inline

Build a new void Table object with named columns.

Parameters
colNamesThe names of the columns of the Table.
Exceptions
DuplicatedTableColumnNameExceptionIf colnames contains identical names.

Definition at line 103 of file Table.h.

References bpp::Table< T >::setColumnNames().

◆ Table() [3/4]

template<class T >
bpp::Table< T >::Table ( const Table< T > &  table)
inline

Definition at line 114 of file Table.h.

◆ Table() [4/4]

template<class T >
bpp::Table< T >::Table ( const std::vector< std::vector< T > > &  vt)
inline

Definition at line 122 of file Table.h.

◆ ~Table()

template<class T >
virtual bpp::Table< T >::~Table ( )
inlinevirtual

Definition at line 161 of file Table.h.

Member Function Documentation

◆ addColumn() [1/3]

template<class T >
void bpp::Table< T >::addColumn ( const std::string &  colName,
const std::vector< T > &  newColumn,
int  pos = -1 
)
inline

Add a new column.

Parameters
colNameThe name of the column.
newColumnThe new column values.
posThe position optional (default : -1 for nb columns)
Exceptions
DimensionExceptionIf the number of values does not match the number of rows.
NoTableColumnNamesExceptionIf the table does not have row names.
DuplicatedTableColumnNameExceptionIf colName is already used.

Definition at line 595 of file Table.h.

References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.

◆ addColumn() [2/3]

template<class T >
void bpp::Table< T >::addColumn ( const std::vector< T > &  newColumn,
int  pos = -1 
)
inline

Add a new column.

Parameters
newColumnThe new column values.
posThe position optional (default : -1 for nb columns)
Exceptions
DimensionExceptionIf the number of values does not match the number of rows.
TableColumnNamesExceptionIf the table has row names.

Definition at line 569 of file Table.h.

References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.

Referenced by bpp::Table< T >::read().

◆ addColumn() [3/3]

template<class T >
void bpp::Table< T >::addColumn ( std::string &  st,
const std::string &  sep = "\t",
int  pos = -1,
int  rowCol = -1 
)
inline

Add a new column.

Parameters
stthe input sting
sepThe row delimiter
posThe position optional (default : nb cols)
rowColthe indice of row where colnames are, starting from 0 (default -1 means no such column)

Definition at line 624 of file Table.h.

References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::StringTokenizer::getTokens(), bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.

◆ addRow() [1/3]

template<class T >
void bpp::Table< T >::addRow ( const std::string &  rowName,
const std::vector< T > &  newRow,
int  pos = -1 
)
inline

Add a new row at a given position.

Parameters
rowNameThe name of the row.
newRowThe new row values.
posThe position optional (default : -1 for nb rows)

Definition at line 957 of file Table.h.

References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.

◆ addRow() [2/3]

template<class T >
void bpp::Table< T >::addRow ( const std::vector< T > &  newRow,
int  pos = -1 
)
inline

Add a new row.

Parameters
newRowThe new row values.
posThe position optional (default : -1 for nb rows)

Definition at line 931 of file Table.h.

References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.

Referenced by bpp::Table< T >::read().

◆ addRow() [3/3]

template<class T >
void bpp::Table< T >::addRow ( std::string &  st,
const std::string &  sep = "\t",
int  pos = -1,
int  rowCol = -1 
)
inline

Add a new row.

Parameters
stthe input string
sepThe column delimiter
posThe position optional (default : nb rows)
rowColthe indice of column where rownames are, starting from 0 (default -1 means no such column)

Definition at line 988 of file Table.h.

References bpp::Table< T >::data_, bpp::StringTokenizer::getTokens(), bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.

◆ clone()

template<class T >
Table* bpp::Table< T >::clone ( ) const
inlinevirtual

Create a copy of this object and send a pointer to it.

Returns
A pointer toward the copy object.

Implements bpp::Clonable.

Definition at line 159 of file Table.h.

References bpp::Table< T >::Table().

◆ deleteColumn() [1/2]

template<class T >
void bpp::Table< T >::deleteColumn ( const std::string &  colName)
inline

Delete the given column.

Parameters
colNameThe name of the column.
Exceptions
NoTableColumnNamesExceptionIf no column names are associated to this table.
TableColumnNameNotFoundExceptionIf colName do not match existing column names.

Definition at line 543 of file Table.h.

References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::VectorTools::which().

◆ deleteColumn() [2/2]

template<class T >
void bpp::Table< T >::deleteColumn ( size_t  index)
inline

Delete the given column.

Parameters
indexThe index of the column.
Exceptions
IndexOutOfBoundsExceptionIf index is >= number of columns.

Definition at line 526 of file Table.h.

References bpp::Table< T >::colNames_, bpp::Table< T >::data_, and bpp::Table< T >::nCol_.

◆ deleteRow() [1/2]

template<class T >
void bpp::Table< T >::deleteRow ( const std::string &  rowName)
inline

Delete the given row.

Parameters
rowNameThe name of the row.
Exceptions
NoTableRowNamesExceptionIf no row names are associated to this table.
TableRowNameNotFoundExceptionIf rowName do not match existing column names.

Definition at line 903 of file Table.h.

References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, bpp::Table< T >::rowNames_, and bpp::VectorTools::which().

◆ deleteRow() [2/2]

template<class T >
void bpp::Table< T >::deleteRow ( size_t  index)
inline

Delete the given row.

Parameters
indexThe index of the row.
Exceptions
IndexOutOfBoundsExceptionIf index is >= number of row.

Definition at line 860 of file Table.h.

References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.

◆ deleteRows()

template<class T >
void bpp::Table< T >::deleteRows ( size_t  index,
size_t  len 
)
inline

Delete the given rows.

Parameters
indexThe index of the first row.
lenthe number of rows to delete
Exceptions
IndexOutOfBoundsExceptionIf index is >= number of row.

Definition at line 881 of file Table.h.

References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.

◆ getColumn() [1/4]

template<class T >
std::vector<T>& bpp::Table< T >::getColumn ( const std::string &  colName)
inline
Returns
The values in the given column.
Parameters
colNameThe name of the column.
Exceptions
NoTableColumnNamesExceptionIf no column names are associated to this table.
TableColumnNameNotFoundExceptionIf colName do not match existing column names.

Definition at line 464 of file Table.h.

References bpp::Table< T >::colNames_, bpp::Table< T >::data_, and bpp::VectorTools::which().

◆ getColumn() [2/4]

template<class T >
const std::vector<T>& bpp::Table< T >::getColumn ( const std::string &  colName) const
inline
Returns
The values in the given column.
Parameters
colNameThe name of the column.
Exceptions
NoTableColumnNamesExceptionIf no column names are associated to this table.
TableColumnNameNotFoundExceptionIf colName do not match existing column names.

Definition at line 485 of file Table.h.

References bpp::Table< T >::colNames_, bpp::Table< T >::data_, and bpp::VectorTools::which().

◆ getColumn() [3/4]

template<class T >
std::vector<T>& bpp::Table< T >::getColumn ( size_t  index)
inline
Returns
The values in the given column.
Parameters
indexThe index of the column.
Exceptions
IndexOutOfBoundsExceptionIf index is >= number of columns.

Definition at line 438 of file Table.h.

References bpp::Table< T >::data_, and bpp::Table< T >::nCol_.

◆ getColumn() [4/4]

template<class T >
const std::vector<T>& bpp::Table< T >::getColumn ( size_t  index) const
inline
Returns
The values in the given column.
Parameters
indexThe index of the column.
Exceptions
IndexOutOfBoundsExceptionIf index is >= number of columns.

Definition at line 450 of file Table.h.

References bpp::Table< T >::data_, and bpp::Table< T >::nCol_.

◆ getColumnName()

template<class T >
std::string bpp::Table< T >::getColumnName ( size_t  index) const
inline

Get a given column name.

Parameters
indexThe index of the column.
Returns
The column name associated to the given column.
Exceptions
NoTableColumnNamesExceptionIf no column names are associated to this table.
IndexOutOfBoundsExceptionIf index is >= number of columns.

Definition at line 418 of file Table.h.

References bpp::Table< T >::colNames_, and bpp::Table< T >::nCol_.

Referenced by bpp::Table< T >::write().

◆ getColumnNames() [1/2]

template<class T >
std::vector<std::string>& bpp::Table< T >::getColumnNames ( )
inline

Definition at line 403 of file Table.h.

References bpp::Table< T >::colNames_.

◆ getColumnNames() [2/2]

template<class T >
const std::vector<std::string>& bpp::Table< T >::getColumnNames ( ) const
inline

Get the column names of this table.

Returns
The column names of this table.
Exceptions
NoTableColumnNamesExceptionIf no column names are associated to this table.

Definition at line 396 of file Table.h.

References bpp::Table< T >::colNames_.

Referenced by bpp::Table< T >::write().

◆ getData()

template<class T >
const std::vector< std::vector<T> >& bpp::Table< T >::getData ( ) const
inline
Returns
The data.

Definition at line 168 of file Table.h.

References bpp::Table< T >::data_.

◆ getNumberOfColumns()

template<class T >
size_t bpp::Table< T >::getNumberOfColumns ( ) const
inline
Returns
The number of columns in this table.

Definition at line 370 of file Table.h.

References bpp::Table< T >::nCol_.

Referenced by bpp::Table< T >::write().

◆ getNumberOfRows()

template<class T >
size_t bpp::Table< T >::getNumberOfRows ( ) const
inline
Returns
The number of rows in this table.

Definition at line 722 of file Table.h.

References bpp::Table< T >::nRow_.

Referenced by bpp::Table< T >::write().

◆ getRow() [1/2]

template<class T >
std::vector<T> bpp::Table< T >::getRow ( const std::string &  rowName) const
inline
Returns
A vector which contains a copy in the given row.
Parameters
rowNameThe name of the row.
Exceptions
NoTableRowNamesExceptionIf no row names are associated to this table.
TableRowNameNotFoundExceptionIf rowName do not match existing row names.

Definition at line 833 of file Table.h.

References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::rowNames_, and bpp::VectorTools::which().

◆ getRow() [2/2]

template<class T >
std::vector<T> bpp::Table< T >::getRow ( size_t  index) const
inline
Returns
A vector which contains a copy in the given row.
Parameters
indexThe index of the row.
Exceptions
IndexOutOfBoundsExceptionIf index is >= number of rows.

Definition at line 814 of file Table.h.

References bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.

◆ getRowName()

template<class T >
std::string bpp::Table< T >::getRowName ( size_t  index) const
inline

Get a given row name.

Parameters
indexThe index of the row.
Returns
The row name associated to the given row.
Exceptions
NoTableRowNamesExceptionIf no row names are associated to this table.
IndexOutOfBoundsExceptionIf index is >= number of rows.

Definition at line 794 of file Table.h.

References bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.

Referenced by bpp::Table< T >::write().

◆ getRowNames() [1/2]

template<class T >
std::vector<std::string> bpp::Table< T >::getRowNames ( )
inline

Get the row names of this table.

Returns
The row names of this table.
Exceptions
NoTableRowNamesExceptionIf no row names are associated to this table.

Definition at line 752 of file Table.h.

References bpp::Table< T >::rowNames_.

Referenced by bpp::Table< T >::write().

◆ getRowNames() [2/2]

template<class T >
const std::vector<std::string>& bpp::Table< T >::getRowNames ( ) const
inline

Definition at line 759 of file Table.h.

References bpp::Table< T >::rowNames_.

◆ hasColumn()

template<class T >
bool bpp::Table< T >::hasColumn ( const std::string &  colName) const
inline

Tell is a given column exists.

Parameters
colNameThe name of the column to look for.
Returns
true if the column was found, false if not or if there are no column names.

Definition at line 507 of file Table.h.

References bpp::Table< T >::colNames_.

◆ hasColumnNames()

template<class T >
bool bpp::Table< T >::hasColumnNames ( ) const
inline
Returns
true If column names are associated to this table.

Definition at line 431 of file Table.h.

References bpp::Table< T >::colNames_.

Referenced by bpp::Table< T >::write().

◆ hasRow()

template<class T >
bool bpp::Table< T >::hasRow ( const std::string &  rowName) const
inline

Tell is a given row exists.

Parameters
rowNameThe name of the row to look for.
Returns
true if the row was found, false if not or if there are no row names.

Definition at line 773 of file Table.h.

References bpp::Table< T >::rowNames_.

◆ hasRowNames()

template<class T >
bool bpp::Table< T >::hasRowNames ( ) const
inline
Returns
true If row names are associated to this table.

Definition at line 807 of file Table.h.

References bpp::Table< T >::rowNames_.

Referenced by bpp::Table< T >::write().

◆ operator()() [1/8]

template<class T >
T& bpp::Table< T >::operator() ( const std::string &  rowName,
const std::string &  colName 
)
inline
Returns
The element at a given position.
Parameters
rowNameRow name.
colNameColumn name.
Exceptions
NoTableRowNamesExceptionIf the table does not have names associated to rows.
NoTableColumnNamesExceptionIf the table does not have names associated to columns.
TableNameNotFoundExceptionIf one of rowName or colName do not match existing names.

Definition at line 212 of file Table.h.

References bpp::Table< T >::colNames_, bpp::ElementNotFoundException< T >::getElement(), bpp::Table< T >::rowNames_, and bpp::VectorTools::which().

◆ operator()() [2/8]

template<class T >
const T& bpp::Table< T >::operator() ( const std::string &  rowName,
const std::string &  colName 
) const
inline
Returns
The element at a given position.
Parameters
rowNameRow name.
colNameColumn name.
Exceptions
NoTableRowNamesExceptionIf the table does not have names associated to rows.
NoTableColumnNamesExceptionIf the table does not have names associated to columns.
TableNameNotFoundExceptionIf one of rowName or colName do not match existing names.

Definition at line 239 of file Table.h.

References bpp::Table< T >::colNames_, bpp::ElementNotFoundException< T >::getElement(), bpp::Table< T >::rowNames_, and bpp::VectorTools::which().

◆ operator()() [3/8]

template<class T >
T& bpp::Table< T >::operator() ( const std::string &  rowName,
size_t  colIndex 
)
inline
Returns
The element at a given position.
Parameters
rowNameRow name.
colIndexColumn number.
Exceptions
NoTableRowNamesExceptionIf the table does not have names associated to rows.
IndexOutOfBoundsExceptionIf the index is greater or equal to the number of columns.
TableNameNotFoundExceptionIf rowName do not match existing names.

Definition at line 266 of file Table.h.

References bpp::ElementNotFoundException< T >::getElement(), bpp::Table< T >::nCol_, bpp::Table< T >::rowNames_, and bpp::VectorTools::which().

◆ operator()() [4/8]

template<class T >
const T& bpp::Table< T >::operator() ( const std::string &  rowName,
size_t  colIndex 
) const
inline
Returns
The element at a given position.
Parameters
rowNameRow name.
colIndexColumn number.
Exceptions
NoTableRowNamesExceptionIf the table does not have names associated to rows.
IndexOutOfBoundsExceptionIf the index is greater or equal to the number of columns.
TableNameNotFoundExceptionIf rowName do not match existing names.

Definition at line 292 of file Table.h.

References bpp::ElementNotFoundException< T >::getElement(), bpp::Table< T >::nCol_, bpp::Table< T >::rowNames_, and bpp::VectorTools::which().

◆ operator()() [5/8]

template<class T >
T& bpp::Table< T >::operator() ( size_t  rowIndex,
const std::string &  colName 
)
inline
Returns
The element at a given position.
Parameters
rowIndexRow number.
colNameColumn name.
Exceptions
IndexOutOfBoundsExceptionIf the index is greater or equal to the number of rows.
NoTableColumnNamesExceptionIf the table does not have names associated to columns.
TableNameNotFoundExceptionIf colName do not match existing names.

Definition at line 318 of file Table.h.

References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::ElementNotFoundException< T >::getElement(), and bpp::VectorTools::which().

◆ operator()() [6/8]

template<class T >
const T& bpp::Table< T >::operator() ( size_t  rowIndex,
const std::string &  colName 
) const
inline
Returns
The element at a given position.
Parameters
rowIndexRow number.
colNameColumn name.
Exceptions
IndexOutOfBoundsExceptionIf the index is greater or equal to the number of rows.
NoTableColumnNamesExceptionIf the table does not have names associated to columns.
TableNameNotFoundExceptionIf colName do not match existing names.

Definition at line 344 of file Table.h.

References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::ElementNotFoundException< T >::getElement(), and bpp::VectorTools::which().

◆ operator()() [7/8]

template<class T >
T& bpp::Table< T >::operator() ( size_t  rowIndex,
size_t  colIndex 
)
inline
Returns
The element at a given position.
Parameters
rowIndexRow number.
colIndexColumn number.
Exceptions
IndexOutOfBoundsExceptionIf one of the index is greater or equal to the corresponding number of columns/rows.

Definition at line 180 of file Table.h.

References bpp::Table< T >::data_, and bpp::Table< T >::nCol_.

◆ operator()() [8/8]

template<class T >
const T& bpp::Table< T >::operator() ( size_t  rowIndex,
size_t  colIndex 
) const
inline
Returns
The element at a given position.
Parameters
rowIndexRow number.
colIndexColumn number.
Exceptions
IndexOutOfBoundsExceptionIf one of the index is greater or equal to the corresponding number of columns/rows.

Definition at line 195 of file Table.h.

References bpp::Table< T >::data_, and bpp::Table< T >::nCol_.

◆ operator=() [1/2]

template<class T >
Table& bpp::Table< T >::operator= ( const std::vector< std::vector< T > > &  vt)
inline

◆ operator=() [2/2]

template<class T >
Table& bpp::Table< T >::operator= ( const Table< T > &  table)
inline

◆ read()

template<class T >
static Table<T>* bpp::Table< T >::read ( std::istream &  in,
bool  byRow,
const std::string &  sep = "\t",
bool  header = true,
int  names = -1 
)
inlinestatic

Read a table form a stream in CSV-like.

By default, if the first line as one column less than the second one, the first line is taken as column names, and the first column as row names. Otherwise, no column names and no row names are specified, unless explicitely precised by the user. Note: if byRow=false, exchange row and column roles.

Parameters
inThe input stream.
byRowTell if the table is filled by rows
sepThe line delimiter.
headerTell if the first line must be used for names, otherwise use default.
namesUse a column as rowNames (or a row as columnNames). If positive, use the specified column to compute rownames, otherwise use default;
Returns
A pointer toward a new Table object.

Definition at line 1046 of file Table.h.

References bpp::Table< T >::addColumn(), bpp::Table< T >::addRow(), bpp::FileTools::getNextLine(), bpp::StringTokenizer::getTokens(), bpp::TextTools::isEmpty(), bpp::Table< T >::setColumnNames(), and bpp::Table< T >::setRowNames().

◆ setColumn() [1/2]

template<class T >
void bpp::Table< T >::setColumn ( const std::string &  colName,
const std::vector< T > &  newColumn,
size_t  pos 
)
inline

Set a new column.

Parameters
colNameThe name of the column.
newColumnThe new column values.
posThe position
Exceptions
DimensionExceptionIf the number of values does not match the number of rows.
NoTableColumnNamesExceptionIf the table does not have row names.
DuplicatedTableColumnNameExceptionIf colName is already used.

Definition at line 692 of file Table.h.

References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.

◆ setColumn() [2/2]

template<class T >
void bpp::Table< T >::setColumn ( const std::vector< T > &  newColumn,
size_t  pos 
)
inline

Set a new column.

Parameters
newColumnThe new column values.
posThe position
Exceptions
DimensionExceptionIf the number of values does not match the number of rows.
TableColumnNamesExceptionIf the table has row names.

Definition at line 671 of file Table.h.

References bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.

◆ setColumnNames()

template<class T >
void bpp::Table< T >::setColumnNames ( const std::vector< std::string > &  colNames)
inline

Set the column names of this table.

Parameters
colNamesThe row names.
Exceptions
DimensionExceptionIf the number of names do not match the number of columns in the table.
DuplicatedTableColumnNameExceptionIf names are not unique.

Definition at line 379 of file Table.h.

References bpp::Table< T >::colNames_, bpp::VectorTools::isUnique(), and bpp::Table< T >::nCol_.

Referenced by bpp::Table< T >::read(), and bpp::Table< T >::Table().

◆ setRowNames()

template<class T >
void bpp::Table< T >::setRowNames ( const std::vector< std::string > &  rowNames)
inline

Set the row names of this table.

Parameters
rowNamesThe row names.
Exceptions
DimensionExceptionIf the number of names do not match the number of rows in the table.
DuplicatedTableRowNameExceptionIf names are not unique.

Definition at line 731 of file Table.h.

References bpp::VectorTools::isUnique(), bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.

Referenced by bpp::Table< T >::read().

◆ write() [1/2]

template<class T >
static void bpp::Table< T >::write ( const Table< T > &  data,
bpp::OutputStream out,
bool  byRow,
const std::string &  sep = "\t",
bool  alignHeaders = false 
)
inlinestatic

◆ write() [2/2]

template<class T >
static void bpp::Table< T >::write ( const Table< T > &  data,
std::ostream &  out,
bool  byRow,
const std::string &  sep = "\t",
bool  alignHeaders = false 
)
inlinestatic

Write a Table object to stream in CVS-like format.

Parameters
dataThe table to write.
outThe output stream.
byRowTell if the table is written by rows.
sepThe column delimiter.
alignHeadersIf true, add a delimiter before the first column header if there is row names.

Definition at line 1107 of file Table.h.

References bpp::Table< T >::getColumnName(), bpp::Table< T >::getColumnNames(), bpp::Table< T >::getNumberOfColumns(), bpp::Table< T >::getNumberOfRows(), bpp::Table< T >::getRowName(), bpp::Table< T >::getRowNames(), bpp::Table< T >::hasColumnNames(), and bpp::Table< T >::hasRowNames().

Member Data Documentation

◆ colNames_

◆ data_

◆ nCol_

◆ nRow_

◆ rowNames_


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