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::Paging< T > Class Template Reference

A class to access generic paging objects. More...

#include <paging_fwd.h>

Public Member Functions

 Paging ()
 Default Constructor.
 
 Paging (const Paging< T > &other)
 Copy Constructor.
 
 Paging (Paging< T > &&other) noexcept
 Move Constructor.
 
Paging< T > & operator= (const Paging< T > &other)
 Copy assignment operator.
 
Paging< T > & operator= (Paging< T > &&other) noexcept
 Move assignment operator.
 
 Paging (IPaging *iPaging, const QList< T > &data, RestClient *client)
 Constructs a paging from the interface, the data and a client.
 
bool isValid () const
 Returns true, if the current paging object is a valid one.
 
IPagingiPaging () const
 Returns the internally used IPaging instance.
 
QList< T > items () const
 Returns the items of this paging object, i.e. it's data.
 
qint64 total () const
 Returns the total number of objects there are.
 
qint64 offset () const
 Returns the offset this paging begins at.
 
bool hasNext () const
 Returns true, if there is a next paging object.
 
template<typename EO = QObject*>
GenericRestReply< Paging< T >, EO > * next () const
 Performs a request for the next paging object.
 
QUrl nextUrl () const
 Returns the link to the next paging object.
 
bool hasPrevious () const
 Returns true, if there is a previous paging object.
 
template<typename EO = QObject*>
GenericRestReply< Paging< T >, EO > * previous () const
 Performs a request for the previous paging object.
 
QUrl previousUrl () const
 Returns the link to the previous paging object.
 
void iterate (const std::function< bool(T, qint64)> &iterator, qint64 to=-1, qint64 from=0) const
 Iterates over all paging objects. More...
 
void iterate (QObject *scope, const std::function< bool(T, qint64)> &iterator, qint64 to=-1, qint64 from=0) const
 Iterates over all paging objects. More...
 
template<typename EO = QObject*>
void iterate (const std::function< bool(T, qint64)> &iterator, const std::function< void(QString, int, RestReply::Error)> &errorHandler, const std::function< QString(EO, int)> &failureTransformer={}, qint64 to=-1, qint64 from=0) const
 Iterates over all paging objects, with error handling. More...
 
template<typename EO = QObject*>
void iterate (QObject *scope, const std::function< bool(T, qint64)> &iterator, const std::function< void(QString, int, RestReply::Error)> &errorHandler, const std::function< QString(EO, int)> &failureTransformer={}, qint64 to=-1, qint64 from=0) const
 Iterates over all paging objects, with error handling. More...
 
template<typename EO = QObject*>
void iterate (const std::function< bool(T, qint64)> &iterator, const std::function< void(int, EO)> &failureHandler, const std::function< void(QString, int, RestReply::Error)> &errorHandler={}, const std::function< void(QtJsonSerializer::Exception &)> &exceptionHandler={}, qint64 to=-1, qint64 from=0) const
 Iterates over all paging objects, with error handling. More...
 
template<typename EO = QObject*>
void iterate (QObject *scope, const std::function< bool(T, qint64)> &iterator, const std::function< void(int, EO)> &failureHandler, const std::function< void(QString, int, RestReply::Error)> &errorHandler={}, const std::function< void(QtJsonSerializer::Exception &)> &exceptionHandler={}, qint64 to=-1, qint64 from=0) const
 Iterates over all paging objects, with error handling. More...
 
QVariantMap properties () const
 Returns a hash containing all properties of the original JSON.
 
void deleteAllItems () const
 Deletes all items this paging object is holding (QObjects only)
 

Detailed Description

template<typename T>
class QtRestClient::Paging< T >

A class to access generic paging objects.

Template Parameters
TThe type the paging object is wrapping

The paging class is a container class that allows you to access generic paging mechanisms.

Typically, APIs use paging as a method to reduce the size of replies. Instead of returning a complete list of elements, only a small chunck (i.e. 10 Elements) is returned, wrapped into a paging object. The object itself containes links, indexes and more to make it possible to iterate over them, by sending multiple consecutive requests.

While most of these paging objects are very similar, they can have different structures. The Paging class, in combination with the IPaging interface, allows you to access any paging mechanism in an easy manner.

Note
All links in paging objects will be resolved relative to the clients URL. For absolute URLs, this means only stuff like headers or additional query parameters are added. Relative URLs however must be relative to the clients URL. If thats not the case, you can extend the private class StandardPaging to adjust the URLs, or implement your own IPaging.
See also
Paging::iterate, IPaging, PagingFactory

Definition at line 30 of file paging_fwd.h.

Member Function Documentation

◆ iterate() [1/6]

template<typename T >
template<typename EO >
QtRestClient::Paging< T >::iterate ( const std::function< bool(T, qint64)> &  iterator,
const std::function< void(int, EO)> &  failureHandler,
const std::function< void(QString, int, RestReply::Error)> &  errorHandler = {},
const std::function< void(QtJsonSerializer::Exception &)> &  exceptionHandler = {},
qint64  to = -1,
qint64  from = 0 
) const

Iterates over all paging objects, with error handling.

Template Parameters
EOThe type of the negative result
Parameters
failureHandlerWill be passed to GenericRestReply::onFailed for all replies
errorHandlerWill be passed to GenericRestReply::onError for all replies
exceptionHandlerWill be passed to GenericRestReply::onSerializeException for all replies
iteratorThe iterator to be be called for every element iterated over
toThe upper limit of how far the iteration should go (-1 means no limit)
fromThe lower limit from where the iteration should start

The paging object will iterate over all it's elements and then automatically call next(), and perform an iteration on the result of that reply as well. This continues until no next element is available anymore or the iterator returns false to cancel early.

By setting to, you can specify a limit. As soon as the iteration reaches the element with an index that equals the limit, the iteration is canceled. The element at the to index will not** be passed to the iterator.

By setting from, you can specify an offset. The iteration will skip all elements, until the index reaches the offset. The element with the from index is the first to be passed to the iterator. Please note, that from must not be smaller then Paging::offset. If thats the case, this function will assert.

Note
Not all pagings support indexes. In that case, to and from will have no effect.

The iterators parameters are:

  • One element of the deserialized Content of the paging replies (DataClassType)
  • The index of the current element or -1 if not supported (int)
  • returns: true if the iteration should continue, false to cancel it prematurely

Definition at line 221 of file paging.h.

◆ iterate() [2/6]

template<typename T >
template<typename EO >
QtRestClient::Paging< T >::iterate ( const std::function< bool(T, qint64)> &  iterator,
const std::function< void(QString, int, RestReply::Error)> &  errorHandler,
const std::function< QString(EO, int)> &  failureTransformer = {},
qint64  to = -1,
qint64  from = 0 
) const

Iterates over all paging objects, with error handling.

Template Parameters
EOThe type of the negative result
Parameters
errorHandlerWill be passed to GenericRestReply::onAllErrors for all replies
failureTransformerWill be passed to GenericRestReply::onAllErrors for all replies
iteratorThe iterator to be be called for every element iterated over
toThe upper limit of how far the iteration should go (-1 means no limit)
fromThe lower limit from where the iteration should start

The paging object will iterate over all it's elements and then automatically call next(), and perform an iteration on the result of that reply as well. This continues until no next element is available anymore or the iterator returns false to cancel early.

By setting to, you can specify a limit. As soon as the iteration reaches the element with an index that equals the limit, the iteration is canceled. The element at the to index will not** be passed to the iterator.

By setting from, you can specify an offset. The iteration will skip all elements, until the index reaches the offset. The element with the from index is the first to be passed to the iterator. Please note, that from must not be smaller then Paging::offset. If thats the case, this function will assert.

Note
Not all pagings support indexes. In that case, to and from will have no effect.

The iterators parameters are:

  • One element of the deserialized Content of the paging replies (DataClassType)
  • The index of the current element or -1 if not supported (int)
  • returns: true if the iteration should continue, false to cancel it prematurely

Definition at line 175 of file paging.h.

◆ iterate() [3/6]

template<typename T >
QtRestClient::Paging< T >::iterate ( const std::function< bool(T, qint64)> &  iterator,
qint64  to = -1,
qint64  from = 0 
) const

Iterates over all paging objects.

Parameters
iteratorThe iterator to be be called for every element iterated over
toThe upper limit of how far the iteration should go (-1 means no limit)
fromThe lower limit from where the iteration should start

The paging object will iterate over all it's elements and then automatically call next(), and perform an iteration on the result of that reply as well. This continues until no next element is available anymore or the iterator returns false to cancel early.

By setting to, you can specify a limit. As soon as the iteration reaches the element with an index that equals the limit, the iteration is canceled. The element at the to index will not** be passed to the iterator.

By setting from, you can specify an offset. The iteration will skip all elements, until the index reaches the offset. The element with the from index is the first to be passed to the iterator. Please note, that from must not be smaller then Paging::offset. If thats the case, this function will assert.

Note
Not all pagings support indexes. In that case, to and from will have no effect.

The iterators parameters are:

  • One element of the deserialized Content of the paging replies (DataClassType)
  • The index of the current element or -1 if not supported (int)
  • returns: true if the iteration should continue, false to cancel it prematurely

Definition at line 132 of file paging.h.

◆ iterate() [4/6]

template<typename T >
template<typename EO >
QtRestClient::Paging< T >::iterate ( QObject scope,
const std::function< bool(T, qint64)> &  iterator,
const std::function< void(int, EO)> &  failureHandler,
const std::function< void(QString, int, RestReply::Error)> &  errorHandler = {},
const std::function< void(QtJsonSerializer::Exception &)> &  exceptionHandler = {},
qint64  to = -1,
qint64  from = 0 
) const

Iterates over all paging objects, with error handling.

Parameters
scopeA scope to limit the callback to
Template Parameters
EOThe type of the negative result
Parameters
failureHandlerWill be passed to GenericRestReply::onFailed for all replies
errorHandlerWill be passed to GenericRestReply::onError for all replies
exceptionHandlerWill be passed to GenericRestReply::onSerializeException for all replies
iteratorThe iterator to be be called for every element iterated over
toThe upper limit of how far the iteration should go (-1 means no limit)
fromThe lower limit from where the iteration should start

The paging object will iterate over all it's elements and then automatically call next(), and perform an iteration on the result of that reply as well. This continues until no next element is available anymore or the iterator returns false to cancel early.

By setting to, you can specify a limit. As soon as the iteration reaches the element with an index that equals the limit, the iteration is canceled. The element at the to index will not** be passed to the iterator.

By setting from, you can specify an offset. The iteration will skip all elements, until the index reaches the offset. The element with the from index is the first to be passed to the iterator. Please note, that from must not be smaller then Paging::offset. If thats the case, this function will assert.

Note
Not all pagings support indexes. In that case, to and from will have no effect.

The iterators parameters are:

  • One element of the deserialized Content of the paging replies (DataClassType)
  • The index of the current element or -1 if not supported (int)
  • returns: true if the iteration should continue, false to cancel it prematurely

Definition at line 246 of file paging.h.

◆ iterate() [5/6]

template<typename T >
template<typename EO >
QtRestClient::Paging< T >::iterate ( QObject scope,
const std::function< bool(T, qint64)> &  iterator,
const std::function< void(QString, int, RestReply::Error)> &  errorHandler,
const std::function< QString(EO, int)> &  failureTransformer = {},
qint64  to = -1,
qint64  from = 0 
) const

Iterates over all paging objects, with error handling.

Parameters
scopeA scope to limit the callback to
Template Parameters
EOThe type of the negative result
Parameters
errorHandlerWill be passed to GenericRestReply::onAllErrors for all replies
failureTransformerWill be passed to GenericRestReply::onAllErrors for all replies
iteratorThe iterator to be be called for every element iterated over
toThe upper limit of how far the iteration should go (-1 means no limit)
fromThe lower limit from where the iteration should start

The paging object will iterate over all it's elements and then automatically call next(), and perform an iteration on the result of that reply as well. This continues until no next element is available anymore or the iterator returns false to cancel early.

By setting to, you can specify a limit. As soon as the iteration reaches the element with an index that equals the limit, the iteration is canceled. The element at the to index will not** be passed to the iterator.

By setting from, you can specify an offset. The iteration will skip all elements, until the index reaches the offset. The element with the from index is the first to be passed to the iterator. Please note, that from must not be smaller then Paging::offset. If thats the case, this function will assert.

Note
Not all pagings support indexes. In that case, to and from will have no effect.

The iterators parameters are:

  • One element of the deserialized Content of the paging replies (DataClassType)
  • The index of the current element or -1 if not supported (int)
  • returns: true if the iteration should continue, false to cancel it prematurely

Definition at line 198 of file paging.h.

◆ iterate() [6/6]

template<typename T >
QtRestClient::Paging< T >::iterate ( QObject scope,
const std::function< bool(T, qint64)> &  iterator,
qint64  to = -1,
qint64  from = 0 
) const

Iterates over all paging objects.

Parameters
scopeA scope to limit the callback to
iteratorThe iterator to be be called for every element iterated over
toThe upper limit of how far the iteration should go (-1 means no limit)
fromThe lower limit from where the iteration should start

The paging object will iterate over all it's elements and then automatically call next(), and perform an iteration on the result of that reply as well. This continues until no next element is available anymore or the iterator returns false to cancel early.

By setting to, you can specify a limit. As soon as the iteration reaches the element with an index that equals the limit, the iteration is canceled. The element at the to index will not** be passed to the iterator.

By setting from, you can specify an offset. The iteration will skip all elements, until the index reaches the offset. The element with the from index is the first to be passed to the iterator. Please note, that from must not be smaller then Paging::offset. If thats the case, this function will assert.

Note
Not all pagings support indexes. In that case, to and from will have no effect.

The iterators parameters are:

  • One element of the deserialized Content of the paging replies (DataClassType)
  • The index of the current element or -1 if not supported (int)
  • returns: true if the iteration should continue, false to cancel it prematurely

Definition at line 153 of file paging.h.


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