morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::table::PageWindow< Row > Class Template Reference

The pages a server-mode table holds: those around the visible rows, up to a bound, plus the request state and the last error. More...

#include <query.hpp>

Public Member Functions

 PageWindow (std::int64_t pageSize=200, std::size_t maxPages=8)
 An empty window.
std::vector< PageFetch > visible (std::int64_t first, std::int64_t count)
 Declares the visible rows; returns the fetches to send.
bool accept (PageFetch const &fetch, Page< Row > page)
 Stores a reply.
bool fail (PageFetch const &fetch, TableError error)
 Records a failed request; the error is shown until a reply arrives.
void reset ()
 Drops every page, request and error and starts a new query: the sort or filter changed.
std::uint64_t query () const noexcept
 The current query, which reset advances.
Row const * row (std::int64_t index) const
 The row at a view row, when it is held.
std::optional< std::int64_t > total () const noexcept
 The view's total rows, when a reply of this query reported it.
std::optional< TableError > const & error () const noexcept
 The last error, until a reply clears it.
std::size_t pagesHeld () const noexcept
 Pages held, complete or in part.
bool pending () const noexcept
 Whether any request is in flight.

Detailed Description

template<typename Row>
class morph::table::PageWindow< Row >

The pages a server-mode table holds: those around the visible rows, up to a bound, plus the request state and the last error.

The client calls visible as the view scrolls and sends the request of each fetch it returns, then hands the fetch back with its reply to accept (or with its error to fail). A change of sort or filter is a new query: call reset. A reply to a fetch made before the last reset is ignored, so a late page of the old query never shows under the new one.

A server may return fewer rows than a fetch asked for (validate clamps the limit to its maxLimit): the window then fetches the rest of the page from where the reply ended. A page is complete when it is full, reaches the known total, or a reply to it is empty.

Template Parameters
RowThe row type.

Definition at line 696 of file query.hpp.

Constructor & Destructor Documentation

◆ PageWindow()

template<typename Row>
morph::table::PageWindow< Row >::PageWindow ( std::int64_t pageSize = 200,
std::size_t maxPages = 8 )
inlineexplicit

An empty window.

Parameters
pageSizeRows per page (default 200).
maxPagesPages held at most; the farthest from the visible rows go first.

Definition at line 702 of file query.hpp.

Member Function Documentation

◆ visible()

template<typename Row>
std::vector< PageFetch > morph::table::PageWindow< Row >::visible ( std::int64_t first,
std::int64_t count )
inlinenodiscard

Declares the visible rows; returns the fetches to send.

Covers the visible rows and one page either side, skipping complete pages, pages in flight, and pages past a known total. A page held in part is fetched from where it ends. The returned pages are marked in flight.

Parameters
firstFirst visible view row.
countVisible rows.
Returns
The fetches to send.

Definition at line 714 of file query.hpp.

◆ accept()

template<typename Row>
bool morph::table::PageWindow< Row >::accept ( PageFetch const & fetch,
Page< Row > page )
inline

Stores a reply.

Parameters
fetchThe fetch the reply answers, as visible returned it.
pageThe page the server returned.
Returns
false when the reply was ignored: its fetch belongs to an earlier query, or is not awaited.

Definition at line 742 of file query.hpp.

◆ fail()

template<typename Row>
bool morph::table::PageWindow< Row >::fail ( PageFetch const & fetch,
TableError error )
inline

Records a failed request; the error is shown until a reply arrives.

Parameters
fetchThe fetch that failed, as visible returned it.
errorThe server's error.
Returns
false when the failure was ignored: its fetch belongs to an earlier query.

Definition at line 776 of file query.hpp.

◆ reset()

template<typename Row>
void morph::table::PageWindow< Row >::reset ( )
inline

Drops every page, request and error and starts a new query: the sort or filter changed.

Definition at line 787 of file query.hpp.

◆ query()

template<typename Row>
std::uint64_t morph::table::PageWindow< Row >::query ( ) const
inlinenodiscardnoexcept

The current query, which reset advances.

Returns
The query's number.

Definition at line 798 of file query.hpp.

◆ row()

template<typename Row>
Row const * morph::table::PageWindow< Row >::row ( std::int64_t index) const
inlinenodiscard

The row at a view row, when it is held.

Parameters
indexView row.
Returns
The row, or null.

Definition at line 803 of file query.hpp.

◆ total()

template<typename Row>
std::optional< std::int64_t > morph::table::PageWindow< Row >::total ( ) const
inlinenodiscardnoexcept

The view's total rows, when a reply of this query reported it.

Returns
The total.

Definition at line 817 of file query.hpp.

◆ error()

template<typename Row>
std::optional< TableError > const & morph::table::PageWindow< Row >::error ( ) const
inlinenodiscardnoexcept

The last error, until a reply clears it.

Returns
The error, or nothing.

Definition at line 821 of file query.hpp.

◆ pagesHeld()

template<typename Row>
std::size_t morph::table::PageWindow< Row >::pagesHeld ( ) const
inlinenodiscardnoexcept

Pages held, complete or in part.

Returns
Page count.

Definition at line 825 of file query.hpp.

◆ pending()

template<typename Row>
bool morph::table::PageWindow< Row >::pending ( ) const
inlinenodiscardnoexcept

Whether any request is in flight.

Returns
true while a page is awaited.

Definition at line 829 of file query.hpp.


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