QtRestClient  3.0.0
A library for generic JSON-based REST-APIs, with a mechanism to map JSON to Qt objects
Public Member Functions | List of all members
QtRestClient::IPaging Class Referenceabstract

Interface to parse generic paging objects and operate on them. More...

#include <ipaging.h>

+ Inheritance diagram for QtRestClient::IPaging:

Public Member Functions

virtual std::variant< QCborArray, QJsonArrayitems () const =0
 Returns the items of this paging object, i.e. it's data.
 
virtual qint64 total () const
 Returns the total number of objects there are. More...
 
virtual qint64 offset () const
 Returns the offset this paging begins at. More...
 
virtual bool hasNext () const =0
 Returns true, if there is a next paging object.
 
virtual QUrl next () const =0
 Returns the link to the next paging object.
 
virtual bool hasPrevious () const
 Returns true, if there is a previous paging object.
 
virtual QUrl previous () const
 Returns the link to the previous paging object.
 
virtual QVariantMap properties () const =0
 Returns a hash containing all properties of the original JSON.
 
virtual std::variant< QCborValue, QJsonValueoriginalData () const =0
 Returns the original JSON element parsed.
 

Detailed Description

Interface to parse generic paging objects and operate on them.

Implement this interface, as well as a custom IPagingFactory, if you need to parse a non standard paging object. You should implement all of the methods correctly. However, you can still use the paging if you can't provide all of them. Simply return default values in that case. However, if you want to use the iterate functionality of the paging, you will have to implement all of them.

The standard implementation expects CBOR or JSON data of the following format and will return either a ICborPaging or a IJsonPaging object:

{
"total": int,
"offset": int,
"limit": int,
"previous": url|null,
"next": url|null,
"items": array
}

Additional fields will be ignored, but are still a valid paging objects. Missing fields or incompatibale types are not allowed, but wont create an error here. Validation is done by IPagingFactory::createPaging

See also
ICborPaging, IJsonPaging, IPagingFactory, Paging

Definition at line 22 of file ipaging.h.

Member Function Documentation

◆ offset()

QtRestClient::IPaging::offset ( ) const
virtual

Returns the offset this paging begins at.

Returns
The offset of the first item in the paging, or -1 if not available

Typically, pagings have indexes. However, since next() alone is sufficient to use a paging, not all may support it. Indexes means, that any item in a paging has a logical index, to identify it idependently of the paging object it is in. It's the real item index on the server. To do so, the offset of the first item in the paging must be known.

If your paging does support indexes, you must implement the offset() method to return the offset of the first element in the paging.

◆ total()

QtRestClient::IPaging::total ( ) const
virtual

Returns the total number of objects there are.

Returns
The total amount of items for this request, or std::numeric_limits<qint64>::max() if not available

If you implement total, please note that total means total independently of the paging, and not the number of elements in the paging. It's the maximum number of items that exist for this request on the server.


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