QtRestClient  3.0.0
A library for generic JSON-based REST-APIs, with a mechanism to map JSON to Qt objects
paging_fwd.h
1 #ifndef QTRESTCLIENT_PAGING_FWD_H
2 #define QTRESTCLIENT_PAGING_FWD_H
3 
4 #include "QtRestClient/qtrestclient_global.h"
5 
6 #include "QtRestClient/ipaging.h"
7 #include "QtRestClient/restclient.h"
8 #include "QtRestClient/restreply.h"
9 #include "QtRestClient/metacomponent.h"
10 
11 #include <functional>
12 
13 #include <QtCore/qshareddata.h>
14 #include <QtCore/qloggingcategory.h>
15 
16 #include <QtJsonSerializer/exception.h>
17 
18 namespace QtRestClient {
19 
20 template<typename DO, typename EO>
21 class GenericRestReply;
22 
23 namespace __private {
24 template<typename T>
25 class PagingData;
26 }
27 
29 template<typename T>
30 class Paging
31 {
32 public:
34  Paging();
36  Paging(const Paging<T> &other);
38  Paging(Paging<T> &&other) noexcept;
40  Paging<T> &operator=(const Paging<T> &other);
42  Paging<T> &operator=(Paging<T> &&other) noexcept;
44  Paging(IPaging *iPaging, const QList<T> &data, RestClient *client);
45 
47  bool isValid() const;
49  IPaging *iPaging() const;
50 
52  QList<T> items() const;
53 
55  qint64 total() const;
57  qint64 offset() const;
58 
60  bool hasNext() const;
62  template<typename EO = QObject*>
63  GenericRestReply<Paging<T>, EO> *next() const;
65  QUrl nextUrl() const;
66 
68  bool hasPrevious() const;
70  template<typename EO = QObject*>
73  QUrl previousUrl() const;
74 
76  void iterate(const std::function<bool(T, qint64)> &iterator,
77  qint64 to = -1,
78  qint64 from = 0) const;
80  void iterate(QObject *scope,
81  const std::function<bool(T, qint64)> &iterator,
82  qint64 to = -1,
83  qint64 from = 0) const;
85  template<typename EO = QObject*>
86  void iterate(const std::function<bool(T, qint64)> &iterator,
87  const std::function<void(QString, int, RestReply::Error)> &errorHandler,
88  const std::function<QString(EO, int)> &failureTransformer = {},
89  qint64 to = -1,
90  qint64 from = 0) const;
92  template<typename EO = QObject*>
93  void iterate(QObject *scope,
94  const std::function<bool(T, qint64)> &iterator,
95  const std::function<void(QString, int, RestReply::Error)> &errorHandler,
96  const std::function<QString(EO, int)> &failureTransformer = {},
97  qint64 to = -1,
98  qint64 from = 0) const;
100  template<typename EO = QObject*>
101  void iterate(const std::function<bool(T, qint64)> &iterator,
102  const std::function<void(int, EO)> &failureHandler,
103  const std::function<void(QString, int, RestReply::Error)> &errorHandler = {},
104  const std::function<void(QtJsonSerializer::Exception &)> &exceptionHandler = {},
105  qint64 to = -1,
106  qint64 from = 0) const;
108  template<typename EO = QObject*>
109  void iterate(QObject *scope,
110  const std::function<bool(T, qint64)> &iterator,
111  const std::function<void(int, EO)> &failureHandler,
112  const std::function<void(QString, int, RestReply::Error)> &errorHandler = {},
113  const std::function<void(QtJsonSerializer::Exception &)> &exceptionHandler = {},
114  qint64 to = -1,
115  qint64 from = 0) const;
116 
118  QVariantMap properties() const;
119 
121  void deleteAllItems() const;
122 
123 private:
125 
126  qint64 internalIterate(const std::function<bool(T, qint64)> &iterator, qint64 to, qint64 from) const;
127  qint64 calcMax(qint64 to) const;
128 };
129 
130 Q_RESTCLIENT_EXPORT Q_DECLARE_LOGGING_CATEGORY(logPaging)
131 
132 }
133 
134 #endif // QTRESTCLIENT_PAGING_FWD_H
QtRestClient::IPaging
Interface to parse generic paging objects and operate on them.
Definition: ipaging.h:22
QtRestClient::Paging::previous
GenericRestReply< Paging< T >, EO > * previous() const
Performs a request for the previous paging object.
Definition: paging.h:117
QtRestClient
The Namespace containing all classes of the QtRestClient module.
Definition: genericrestreply.h:14
QUrl
QtRestClient::RestReply::Error
Error
Defines the different possible error types.
Definition: restreply.h:45
QtRestClient::Paging::iterate
void iterate(const std::function< bool(T, qint64)> &iterator, qint64 to=-1, qint64 from=0) const
Iterates over all paging objects.
Definition: paging.h:132
QtRestClient::Paging::isValid
bool isValid() const
Returns true, if the current paging object is a valid one.
Definition: paging.h:58
QSharedDataPointer
QtRestClient::Paging::hasPrevious
bool hasPrevious() const
Returns true, if there is a previous paging object.
Definition: paging.h:110
QtRestClient::Paging::nextUrl
QUrl nextUrl() const
Returns the link to the next paging object.
Definition: paging.h:104
QtRestClient::Paging::total
qint64 total() const
Returns the total number of objects there are.
Definition: paging.h:76
QList
QtRestClient::Paging::hasNext
bool hasNext() const
Returns true, if there is a next paging object.
Definition: paging.h:88
QString
QtRestClient::Paging::Paging
Paging()
Default Constructor.
Definition: paging.h:32
QtRestClient::Paging::previousUrl
QUrl previousUrl() const
Returns the link to the previous paging object.
Definition: paging.h:126
QtRestClient::GenericRestReply
A class to handle generic replies for generic requests.
Definition: genericrestreply.h:20
QtRestClient::Paging::items
QList< T > items() const
Returns the items of this paging object, i.e. it's data.
Definition: paging.h:70
QtRestClient::Paging::iPaging
IPaging * iPaging() const
Returns the internally used IPaging instance.
Definition: paging.h:64
QtRestClient::Paging
A class to access generic paging objects.
Definition: paging_fwd.h:30
QtRestClient::Paging::deleteAllItems
void deleteAllItems() const
Deletes all items this paging object is holding (QObjects only)
Definition: paging.h:276
QtRestClient::Paging::next
GenericRestReply< Paging< T >, EO > * next() const
Performs a request for the next paging object.
Definition: paging.h:95
QtJsonSerializer::Exception
QtRestClient::Paging::offset
qint64 offset() const
Returns the offset this paging begins at.
Definition: paging.h:82
QtRestClient::Paging::properties
QVariantMap properties() const
Returns a hash containing all properties of the original JSON.
Definition: paging.h:270
QObject
QtRestClient::RestClient
A class to define access to an API, with general settings.
Definition: restclient.h:30
QtRestClient::Paging::operator=
Paging< T > & operator=(const Paging< T > &other)
Copy assignment operator.