QtRestClient  3.0.0
A library for generic JSON-based REST-APIs, with a mechanism to map JSON to Qt objects
ipaging.h
1 #ifndef QTRESTCLIENT_IPAGING_H
2 #define QTRESTCLIENT_IPAGING_H
3 
4 #include "QtRestClient/qtrestclient_global.h"
5 
6 #include <QtCore/qjsonarray.h>
7 #include <QtCore/qjsonvalue.h>
8 #include <QtCore/qcborvalue.h>
9 #include <QtCore/qcborarray.h>
10 #include <QtCore/qurl.h>
11 #include <QtCore/qvariant.h>
12 
13 #ifndef Q_RESTCLIENT_NO_JSON_SERIALIZER
14 namespace QtJsonSerializer {
15 class SerializerBase;
16 }
17 #endif
18 
19 namespace QtRestClient {
20 
22 class Q_RESTCLIENT_EXPORT IPaging
23 {
24  Q_DISABLE_COPY(IPaging)
25 public:
26  IPaging();
27  virtual ~IPaging();
28 
30  virtual std::variant<QCborArray, QJsonArray> items() const = 0;
31 
33  virtual qint64 total() const;
35  virtual qint64 offset() const;
37  virtual bool hasNext() const = 0;
39  virtual QUrl next() const = 0;
41  virtual bool hasPrevious() const;
43  virtual QUrl previous() const;
45  virtual QVariantMap properties() const = 0;
47  virtual std::variant<QCborValue, QJsonValue> originalData() const = 0;
48 };
49 
51 class Q_RESTCLIENT_EXPORT ICborPaging : public IPaging
52 {
53 public:
55  virtual QCborArray cborItems() const = 0;
57  virtual QCborValue originalCbor() const = 0;
58 
59  std::variant<QCborArray, QJsonArray> items() const final;
60  std::variant<QCborValue, QJsonValue> originalData() const final;
61 };
62 
64 class Q_RESTCLIENT_EXPORT IJsonPaging : public IPaging
65 {
66 public:
68  virtual QJsonArray jsonItems() const = 0;
70  virtual QJsonValue originalJson() const = 0;
71 
72  std::variant<QCborArray, QJsonArray> items() const final;
73  std::variant<QCborValue, QJsonValue> originalData() const final;
74 };
75 
77 class Q_RESTCLIENT_EXPORT IPagingFactory
78 {
79  Q_DISABLE_COPY(IPagingFactory)
80 
81 public:
83  virtual ~IPagingFactory();
84 
86 #ifndef Q_RESTCLIENT_NO_JSON_SERIALIZER
87  virtual IPaging *createPaging(QtJsonSerializer::SerializerBase *serializer, const std::variant<QCborValue, QJsonValue> &data) const = 0;
88 #else
89  virtual IPaging *createPaging(const std::variant<QCborValue, QJsonValue> &data) const = 0;
90 #endif
91 };
92 
93 }
94 
95 Q_DECLARE_METATYPE(QtRestClient::IPaging*)
96 
97 #endif // QTRESTCLIENT_IPAGING_H
QtRestClient::IPaging
Interface to parse generic paging objects and operate on them.
Definition: ipaging.h:22
QtRestClient
The Namespace containing all classes of the QtRestClient module.
Definition: genericrestreply.h:14
QUrl
QtRestClient::IJsonPaging
Interface to parse generic JSON paging objects and operate on them.
Definition: ipaging.h:64
QtJsonSerializer::SerializerBase
QJsonValue
QJsonArray
QCborValue
QCborArray
QtRestClient::ICborPaging
Interface to parse generic CBOR paging objects and operate on them.
Definition: ipaging.h:51
QtRestClient::IPagingFactory
A factory interface to create IPaging instances from raw data.
Definition: ipaging.h:77