morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::table::VectorSource Class Referencefinal

A DataSource over rows held in memory, for tests, servers and sources that cannot share their own storage. More...

#include <data_source.hpp>

Inheritance diagram for morph::table::VectorSource:
morph::table::DataSource morph::table::RowPatcher

Public Member Functions

 VectorSource (std::vector< ColumnInfo > columns)
 Constructs an empty source with columns.
std::span< ColumnInfo const > columns () const override
 The table's columns.
std::shared_ptr< RowSnapshot const > snapshot () const override
 The current rows; a pointer copy.
std::shared_ptr< TableSnapshot const > const & tableSnapshot () const noexcept
 The current rows, typed.
void subscribe (ChangeListener &listener) override
 Registers listener.
void unsubscribe (ChangeListener &listener) override
 Removes listener; safe from inside a notification.
void setRows (std::vector< RowId > ids, std::vector< std::vector< Cell > > rows, std::optional< std::vector< ColumnInfo > > columns=std::nullopt)
 Replaces every row (and optionally the columns), then notifies Reset.
void updateRow (std::size_t row, std::vector< Cell > cells)
 Replaces one row's cells, then notifies Updated.
bool patchRow (RowId const &key, std::vector< Cell > cells) override
 Replaces the cells of the row keyed id, then notifies Updated.
void insertRow (std::size_t row, RowId key, std::vector< Cell > cells)
 Inserts a row before row, then notifies Inserted.
void removeRow (std::size_t row)
 Removes row row, then notifies Removed.
std::optional< std::size_t > indexOf (RowId const &key) const
 The index of the row keyed id.

Detailed Description

A DataSource over rows held in memory, for tests, servers and sources that cannot share their own storage.

Definition at line 811 of file data_source.hpp.

Constructor & Destructor Documentation

◆ VectorSource()

morph::table::VectorSource::VectorSource ( std::vector< ColumnInfo > columns)
inlineexplicit

Constructs an empty source with columns.

Parameters
columnsThe table's columns.

Definition at line 815 of file data_source.hpp.

Member Function Documentation

◆ columns()

std::span< ColumnInfo const > morph::table::VectorSource::columns ( ) const
inlinenodiscardoverridevirtual

The table's columns.

Returns
The columns.

Implements morph::table::DataSource.

Definition at line 820 of file data_source.hpp.

◆ snapshot()

std::shared_ptr< RowSnapshot const > morph::table::VectorSource::snapshot ( ) const
inlinenodiscardoverridevirtual

The current rows; a pointer copy.

Returns
The snapshot.

Implements morph::table::DataSource.

Definition at line 824 of file data_source.hpp.

◆ tableSnapshot()

std::shared_ptr< TableSnapshot const > const & morph::table::VectorSource::tableSnapshot ( ) const
inlinenodiscardnoexcept

The current rows, typed.

Returns
The snapshot.

Definition at line 828 of file data_source.hpp.

◆ subscribe()

void morph::table::VectorSource::subscribe ( ChangeListener & listener)
inlineoverridevirtual

Registers listener.

Parameters
listenerThe listener.

Implements morph::table::DataSource.

Definition at line 832 of file data_source.hpp.

◆ unsubscribe()

void morph::table::VectorSource::unsubscribe ( ChangeListener & listener)
inlineoverridevirtual

Removes listener; safe from inside a notification.

Parameters
listenerThe listener.

Implements morph::table::DataSource.

Definition at line 836 of file data_source.hpp.

◆ setRows()

void morph::table::VectorSource::setRows ( std::vector< RowId > ids,
std::vector< std::vector< Cell > > rows,
std::optional< std::vector< ColumnInfo > > columns = std::nullopt )
inline

Replaces every row (and optionally the columns), then notifies Reset.

Parameters
idsThe rows' keys.
rowsThe rows' cells.
columnsNew columns, or nothing to keep the current ones.

Definition at line 842 of file data_source.hpp.

◆ updateRow()

void morph::table::VectorSource::updateRow ( std::size_t row,
std::vector< Cell > cells )
inline

Replaces one row's cells, then notifies Updated.

Parameters
rowRow index.
cellsThe new cells.

Definition at line 855 of file data_source.hpp.

◆ patchRow()

bool morph::table::VectorSource::patchRow ( RowId const & key,
std::vector< Cell > cells )
inlineoverridevirtual

Replaces the cells of the row keyed id, then notifies Updated.

Parameters
keyThe row's key.
cellsThe new cells.
Returns
false when no row has that key.

Implements morph::table::RowPatcher.

Definition at line 864 of file data_source.hpp.

◆ insertRow()

void morph::table::VectorSource::insertRow ( std::size_t row,
RowId key,
std::vector< Cell > cells )
inline

Inserts a row before row, then notifies Inserted.

Parameters
rowInsert position.
keyThe new row's key.
cellsThe new row's cells.

Definition at line 877 of file data_source.hpp.

◆ removeRow()

void morph::table::VectorSource::removeRow ( std::size_t row)
inline

Removes row row, then notifies Removed.

Parameters
rowRow index.

Definition at line 885 of file data_source.hpp.

◆ indexOf()

std::optional< std::size_t > morph::table::VectorSource::indexOf ( RowId const & key) const
inlinenodiscard

The index of the row keyed id.

Parameters
keyThe key.
Returns
Its row index, or nothing.

Definition at line 894 of file data_source.hpp.


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