Table

class Table

Class to store several rows of data values. Each Row will contain value objects that are mapped to the Columns defined in this Table.

Public Functions

Table()

Empty Table constructor

Table(const Table &other)

Copy constructor

Table(Table &&other)

Move constructor

Table &operator=(const Table &other)

Assign operators

Table(const std::vector<Column> &columns)

Table constructor based on input columns

~Table()

Destructor for Table

void clear()

Clear all columns and rows

size_t getSize() const

Return the number of rows in the Table

bool isEmpty() const

Return true if the number of rows is 0

size_t getIndex(size_t colId)

Return the index of the column with this ID

size_t getIndex(const std::string &colName)

Return the index of the column with this NAME.

const Table::Column &getColumn(size_t colId)

Return the column with this column ID.

const Table::Column &getColumn(const std::string &colName)

Return the column with this NAME

const Column &getColumnByIndex(size_t index)

Return the column in the given INDEX

size_t getColumnsSize() const

Return number of columns in the table

size_t addColumn(const Column &col)

Add a column when the table does not contain any row. If there are rows, the other function should be used where a default value should be provided.

Parameters

size_t addColumn(const Column &col, const Object &defaultValue)

Add a new column when the table already contains some rows.

size_t insertColumn(const Column &col, size_t pos)

Insert a new column at a given position

void removeColumn(size_t colId)

Remove an existing column from the Table

void moveColumn(size_t colId, size_t pos)

Change the position of a column

Table::const_col_iterator cbegin_cols() const

Return column iterator at the beginning

Table::const_col_iterator cend_cols() const

Return column iterator at the end

const Table::Row &operator[](size_t pos) const

Return the row at this position

Table::Row createRow() const

Create a new row with the columns defined in this Table.

bool addRow(const Row &row)

Add a new row to the set

bool insertRow(const Row &row, size_t pos)

Insert a new row in a given position

bool deleteRow(const Row &row)

Delete a given row

size_t deleteRows(const std::string &queryStr)

Delete all rows that match a query string

Return

The number of deleted rows.

bool updateRow(const Row &row)

Update a given row

size_t updateRows(const std::string &operation, const std::string &queryStr)

Update many rows at once. Apply the operation string to all rows that match the query string.

Return

The number of updated rows.

void sort(const StringVector &columnName)

Sort the table by a given column name.

void read(const std::string &tableName, const std::string &path)

Shortcut function to read a table from file without the need to explicitly instantiating a TableFile object. After calling this function, the current table will be populated.

Parameters
  • tableName: Name of the table that will be read

  • path: Path to the table file, the type of reader will be inferred from the filename extension

void read(const std::string &path)

Shortcut function to read a table from file without the need to explicitly instantiating a TableFile object. After calling this function, the current table will be populated.

Parameters
  • path: Path to the table file, the type of reader will be inferred from the filename extension

class Column

Class defining the properties of a given column in a Row or Table. Each column should have an integer ID and a string NAME (both of which should be unique among a given set of Columns). Additionally, a Column should have a Type and could have a description of its meaning.

Public Functions

Column(size_t id, const std::string &name, const Type &type, const std::string &description = "")

Constructor of a Column given the ID

Column(const std::string &name, const Type &type, const std::string &description = "")

Constructor of a Column without ID

size_t getId() const

Return the ID of this Column

std::string getName() const

Return the NAME of this Column

const Type &getType() const

Return the Type of this Column

std::string getDescription() const

Return the description of this Column

class Impl

Public Functions

void updateIndexes(ColumnVector::iterator firstToUpdate, int updateFactor)

Update the indexes of some columns when new columns are added or existing one are deleted.

Parameters
  • firstToUpdate: This is the position (iterator) of the first element to update

  • updateFactor: This will be 1 if a new column is inserted and -1 if a column was deleted.

class Row

Class to hold key-value pairs. Keys will be either string or integer representing a given column. Values are instances of class Object that can hold values of different types. The Type of a given object in the Row should be of the same type of the Column’s Type.

Public Functions

Row()

Empty constructor

Row(const Row &other)

Copy constructor and assignment

Row(Row &&other)

Move constructor

~Row()

Row Dtor

const Object &operator[](size_t colId) const

Return the index of the column specified by colId.

const Object &operator[](const std::string &colName) const

Return the index of the column specified by colName.

class Impl

Public Functions

Impl()

Default empty constructor

Impl(const Table *parent)

Constructor of RowImpl. Receives the parent Table pointer.