5 #ifndef BPP_NUMERIC_DATATABLE_H 6 #define BPP_NUMERIC_DATATABLE_H 9 #include "../Clonable.h" 10 #include "../Text/TextTools.h" 34 std::vector< std::vector<std::string>>
data_;
54 DataTable(
size_t nRow,
const std::vector<std::string>& colNames);
69 DataTable(
const std::vector<std::string>& colNames);
86 std::string&
operator()(
size_t rowIndex,
size_t colIndex);
94 const std::string&
operator()(
size_t rowIndex,
size_t colIndex)
const;
104 std::string&
operator()(
const std::string& rowName,
const std::string& colName);
114 const std::string&
operator()(
const std::string& rowName,
const std::string& colName)
const;
124 std::string&
operator()(
const std::string& rowName,
size_t colIndex);
134 const std::string&
operator()(
const std::string& rowName,
size_t colIndex)
const;
144 std::string&
operator()(
size_t rowIndex,
const std::string& colName);
154 const std::string&
operator()(
size_t rowIndex,
const std::string& colName)
const;
202 std::vector<std::string>&
getColumn(
size_t index);
208 const std::vector<std::string>&
getColumn(
size_t index)
const;
216 std::vector<std::string>&
getColumn(
const std::string& colName);
223 const std::vector<std::string>&
getColumn(
const std::string& colName)
const;
231 bool hasColumn(
const std::string& colName)
const;
257 void addColumn(
const std::vector<std::string>& newColumn);
267 void addColumn(
const std::string& colName,
const std::vector<std::string>& newColumn);
288 void setRowNames(
const std::vector<std::string>& rowNames);
299 void setRowName(
size_t rowIndex,
const std::string& rowName);
315 bool hasRow(
const std::string& rowName)
const;
337 std::vector<std::string>
getRow(
size_t index)
const;
345 std::vector<std::string>
getRow(
const std::string& rowName)
const;
362 void deleteRow(
const std::string& rowName);
371 void addRow(
const std::vector<std::string>& newRow);
382 void addRow(
const std::string& rowName,
const std::vector<std::string>& newRow);
390 void setRow(
const size_t rowIndex,
const std::vector<std::string>& newRow);
411 static std::unique_ptr<DataTable>
read(std::istream& in,
const std::string& sep =
"\t",
bool header =
true,
int rowNames = -1);
421 static void write(
const DataTable& data, std::ostream& out,
const std::string& sep =
"\t",
bool alignHeaders =
false);
425 #endif // BPP_NUMERIC_DATATABLE_H std::vector< std::string > rowNames_
std::vector< std::string > getColumnNames() const
Get the column names of this table.
std::string getRowName(size_t index) const
Get a given row name.
This class corresponds to a 'dataset', i.e. a table with data by rows and variable by columns...
void setRowNames(const std::vector< std::string > &rowNames)
Set the row names of this table.
void addColumn(const std::vector< std::string > &newColumn)
Add a new column.
void setColumnNames(const std::vector< std::string > &colNames)
Set the column names of this table.
std::vector< std::vector< std::string > > data_
std::vector< std::string > getRow(size_t index) const
std::vector< std::string > & getColumn(size_t index)
std::string getColumnName(size_t index) const
Get a given column name.
DataTable * clone() const
Create a copy of this object and send a pointer to it.
size_t getNumberOfRows() const
bool hasRow(const std::string &rowName) const
Tell is a given row exists.
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.
void addRow(const std::vector< std::string > &newRow)
Add a new row.
static std::unique_ptr< DataTable > read(std::istream &in, const std::string &sep="\, bool header=true, int rowNames=-1)
Read a table form a stream in CSV-like format.
bool hasColumnNames() const
The Clonable interface (allow an object to be cloned).
DataTable(size_t nRow, size_t nCol)
Build a new void DataTable object with nRow rows and nCol columns.
bool hasColumn(const std::string &colName) const
Tell is a given column exists.
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 deleteRow(size_t index)
Delete the given row.
std::vector< std::string > colNames_
size_t getNumberOfColumns() const
DataTable & operator=(const DataTable &table)
static void write(const DataTable &data, std::ostream &out, const std::string &sep="\, bool alignHeaders=false)
Write a DataTable object to stream in CVS-like format.
std::vector< std::string > getRowNames() const
Get the row names of this table.