41 #ifndef BPP_NUMERIC_DATATABLE_H
42 #define BPP_NUMERIC_DATATABLE_H
45 #include "../Clonable.h"
46 #include "../Text/TextTools.h"
70 std::vector< std::vector<std::string> >
data_;
90 DataTable(
size_t nRow,
const std::vector<std::string>& colNames);
105 DataTable(
const std::vector<std::string>& colNames);
122 std::string&
operator()(
size_t rowIndex,
size_t colIndex);
130 const std::string&
operator()(
size_t rowIndex,
size_t colIndex)
const;
140 std::string&
operator()(
const std::string& rowName,
const std::string& colName);
150 const std::string&
operator()(
const std::string& rowName,
const std::string& colName)
const;
160 std::string&
operator()(
const std::string& rowName,
size_t colIndex);
170 const std::string&
operator()(
const std::string& rowName,
size_t colIndex)
const;
180 std::string&
operator()(
size_t rowIndex,
const std::string& colName);
190 const std::string&
operator()(
size_t rowIndex,
const std::string& colName)
const;
238 std::vector<std::string>&
getColumn(
size_t index);
244 const std::vector<std::string>&
getColumn(
size_t index)
const;
252 std::vector<std::string>&
getColumn(
const std::string& colName);
259 const std::vector<std::string>&
getColumn(
const std::string& colName)
const;
267 bool hasColumn(
const std::string& colName)
const;
293 void addColumn(
const std::vector<std::string>& newColumn);
303 void addColumn(
const std::string& colName,
const std::vector<std::string>& newColumn);
324 void setRowNames(
const std::vector<std::string>& rowNames);
335 void setRowName(
size_t rowIndex,
const std::string& rowName);
351 bool hasRow(
const std::string& rowName)
const;
373 std::vector<std::string>
getRow(
size_t index)
const;
381 std::vector<std::string>
getRow(
const std::string& rowName)
const;
398 void deleteRow(
const std::string& rowName);
407 void addRow(
const std::vector<std::string>& newRow);
419 void addRow(
const std::string& rowName,
const std::vector<std::string>& newRow);
428 void setRow(
const size_t rowIndex,
const std::vector<std::string>& newRow);
449 static DataTable*
read(std::istream& in,
const std::string& sep =
"\t",
bool header =
true,
int rowNames = -1);
459 static void write(
const DataTable& data, std::ostream& out,
const std::string& sep =
"\t",
bool alignHeaders =
false);
The Clonable interface (allow an object to be cloned).
This class corresponds to a 'dataset', i.e. a table with data by rows and variable by columns.
bool hasRow(const std::string &rowName) const
Tell is a given row exists.
std::vector< std::string > * rowNames_
void deleteRow(size_t index)
Delete the given row.
DataTable(size_t nRow, size_t nCol)
Build a new void DataTable object with nRow rows and nCol columns.
void deleteColumn(size_t index)
Delete the given column.
void setRow(const size_t rowIndex, const std::vector< std::string > &newRow)
Sets an existing with a given index.
void addColumn(const std::vector< std::string > &newColumn)
Add a new column.
std::string & operator()(size_t rowIndex, size_t colIndex)
void setRowName(size_t rowIndex, const std::string &rowName)
Set the row name of a row with a given index.
std::vector< std::string > * colNames_
DataTable * clone() const
Create a copy of this object and send a pointer to it.
std::vector< std::vector< std::string > > data_
std::vector< std::string > getRowNames() const
Get the row names of this table.
size_t getNumberOfColumns() const
std::string getColumnName(size_t index) const
Get a given column name.
bool hasColumnNames() const
std::vector< std::string > getColumnNames() const
Get the column names of this table.
std::vector< std::string > getRow(size_t index) const
std::vector< std::string > & getColumn(size_t index)
static DataTable * read(std::istream &in, const std::string &sep="\t", bool header=true, int rowNames=-1)
Read a table form a stream in CSV-like format.
static void write(const DataTable &data, std::ostream &out, const std::string &sep="\t", bool alignHeaders=false)
Write a DataTable object to stream in CVS-like format.
DataTable & operator=(const DataTable &table)
void addRow(const std::vector< std::string > &newRow)
Add a new row.
std::string getRowName(size_t index) const
Get a given row name.
size_t getNumberOfRows() const
void setColumnNames(const std::vector< std::string > &colNames)
Set the column names of this table.
bool hasColumn(const std::string &colName) const
Tell is a given column exists.
void setRowNames(const std::vector< std::string > &rowNames)
Set the row names of this table.