Workspace 6.21.5
Public Member Functions | Protected Member Functions | List of all members
DataTable Class Reference

This class defines the DataTable data type. A DataTable is a table that contains a set of columns and a collection of data records (i.e. rows). More...

#include <Workspace/DataExecution/DataObjects/datatable.h>

Inheritance diagram for DataTable:
[legend]

Public Member Functions

 DataTable ()
 
 DataTable (const DataTable &other)
 
 ~DataTable () override
 
template<typename T >
void addColumn (const QString &name, const QString &longName, const QStringList &units=QStringList())
 
template<typename T >
void addColumn (const QString &name, const QStringList &units=QStringList())
 
int appendRecord ()
 
bool canSerialize () const override
 
void clear ()
 
void clearData ()
 
DataTableColumn column (const QString &name) const
 
template<typename T >
T & data (int index, const QString &name)
 
template<typename T >
const T & data (int index, const QString &name) const
 
template<typename T >
T & defaultData (const QString &name)
 
template<typename T >
const T & defaultData (const QString &name) const
 
QStringList getColumnsName () const
 
DataObjectgetDataObject (int index, const QString &name)
 
const DataObjectgetDataObject (int index, const QString &name) const
 
void insertRecord (int index)
 
bool load (const SerializedItem &item) override
 
int numRecords () const
 
DataTableoperator= (const DataTable &other)
 
void removeColumn (const QString &name)
 
void removeRecord (int index)
 
bool save (SerializedItem &item) const override
 
void swapRecords (int index1, int index2)
 
- Public Member Functions inherited from Serialize
virtual ~Serialize ()=default
 
virtual bool canSerialize () const =0
 
virtual bool load (const SerializedItem &item)=0
 
virtual bool save (SerializedItem &item) const =0
 

Protected Member Functions

void addColumn (const DataFactory &factory, const QString &name, const QString &longName, const QStringList &units)
 

Detailed Description

Each record in the collection of data records contains actual data indexed by the column's names. DataTable supports XML serialisation. The primary intention of this class is to support table-like structure of Workspace-supported data types. The underlying data entries are therefore stored in DataObject and may not be optimised for memory when it is used to store large data sets of simple types such as numbers and strings. For those simpler but large data sets, the users might want to consider using ArrayNd.

Constructor & Destructor Documentation

◆ DataTable() [1/2]

DataTable ( )

Default constructor.

◆ DataTable() [2/2]

DataTable ( const DataTable other)
Parameters
otherThe other DataTable to be created from.

Create a DataTable from other and perform a shallow copy of data. The data records will be shared between the newly created DataTable and other.

◆ ~DataTable()

~DataTable ( )
overridedefault

Member Function Documentation

◆ addColumn() [1/3]

void addColumn ( const DataFactory factory,
const QString &  name,
const QString &  longName,
const QStringList units 
)
protected

◆ addColumn() [2/3]

void addColumn ( const QString &  name,
const QString &  longName,
const QStringList units = QStringList() 
)
inline
Parameters
nameThe column name.
longNameThe column long name.
unitsOptional. The list of units associated with this column.

This is an overloaded function.

◆ addColumn() [3/3]

void addColumn ( const QString &  name,
const QStringList units = QStringList() 
)
inline
Parameters
nameThe column name.
unitsOptional. The list of units associated with this column.

Add a column to the DataTable. This function throws an exception if there is any error, for example: a column with name name already exists.

See also
appendRecord(), insertRecord(), removeRecords(), numRecords().

◆ appendRecord()

int appendRecord ( )

Append a record to the end of the data records.

Returns
The index of the newly appended record.
See also
insertRecord(), removeRecord(), swapRecords(), numRecords(), data().

◆ canSerialize()

bool canSerialize ( ) const
overridevirtual
Returns
This function always returns true to indicate that DataTable supports serialisation.

Implements Serialize.

◆ clear()

void clear ( )

Clear the data and the structure of the table (its columns and meta data).

◆ clearData()

void clearData ( )

Clear the data but preserve the structure of the table (its columns and meta data).

◆ column()

DataTableColumn column ( const QString &  name) const
Parameters
nameThe name of the column.
Returns
A copy of the column name. This function throws an exception if there is an error, for example: the column name does not exist.
See also
getColumnsName(), addColumn(), removeColumn().

◆ data() [1/2]

T & data ( int  index,
const QString &  name 
)
inline
Parameters
indexThe record index.
nameThe column name.

This function provides access to the data entry located at record index index and at column name. This function throws an exception if there is any error, for example: out-of-ranged index, inexisting column, etc.

Returns
Reference to the raw data at that entry.

◆ data() [2/2]

const T & data ( int  index,
const QString &  name 
) const
inline
Parameters
indexThe record index.
nameThe column name.

This is an overloaded function.

◆ defaultData() [1/2]

T & defaultData ( const QString &  name)
inline
Parameters
nameThe column name.

This function provides access to the default data for column name. This function throws an exception if there is any error, for example: out-of-ranged index, inexisting column, etc.

Returns
Reference to the raw data of the default data for that column.

◆ defaultData() [2/2]

const T & defaultData ( const QString &  name) const
inline
Parameters
nameThe column name.

This is an overloaded function.

◆ getColumnsName()

QStringList getColumnsName ( ) const
Returns
A list of all columns name.
See also
column(), addColumn(), removeColumn().

◆ getDataObject() [1/2]

DataObject & getDataObject ( int  index,
const QString &  name 
)
Parameters
indexThe record index.
nameThe column name.

This function provides access to the data entry located at record index index and at column name. This function throws an exception if there is any error, for example: out-of-ranged index, inexisting column, etc.

Returns
Reference to the DataObject at that entry.

◆ getDataObject() [2/2]

const DataObject & getDataObject ( int  index,
const QString &  name 
) const
Parameters
indexThe record index.
nameThe column name.

This is an overloaded function.

◆ insertRecord()

void insertRecord ( int  index)
Parameters
indexThe position at which the new record will be inserted.

Insert a new record at position index. This function throws an exception if there is any error, for example: out-of-ranged index.

See also
appendRecord(), removeRecord(), swapRecords(), numRecords(), data().

◆ load()

bool load ( const SerializedItem item)
overridevirtual
Parameters
itemThe SerializedItem to read from.

Read item into DataTable.

Returns
true if serialisation succeeds. Otherwise return false.

Implements Serialize.

◆ numRecords()

int numRecords ( ) const
Returns
The number of records in the DataTable.
See also
appendRecord(), insertRecord(), removeRecords(), data().

◆ operator=()

DataTable & operator= ( const DataTable other)

Assignment operation. Shallow copy of data.

◆ removeColumn()

void removeColumn ( const QString &  name)
Parameters
nameThe name of the column to remove.

Remove a column from the DataTable. This function throws an exception if there an error, for example when user tries to remove an inexisting column.

See also
addColumn(), getColumnsName(), column().

◆ removeRecord()

void removeRecord ( int  index)
Parameters
indexThe position at which the record will be deleted.

Delete a record at position index. This function throws an exception if there is any error, for example: out-of-ranged index.

See also
appendRecord(), insertRecord(), swapRecords(), numRecords(), data().

◆ save()

bool save ( SerializedItem item) const
overridevirtual
Parameters
itemThe SerializedItem to write into.

Write the content of DataTable to item.

Returns
true if serialisation succeeds. Otherwise return false.

Implements Serialize.

◆ swapRecords()

void swapRecords ( int  index1,
int  index2 
)
Parameters
index1The position of one record to be swapped.
index2The position of another record to be swapped with.

Swap the records at positions index1 and index2. This function throws an exception if there is any error, for example: out-of-ranged indices.

See also
appendRecord(), insertRecord(), removeRecord(), numRecords().