3#include <CesiumAsync/AsyncSystem.h>
4#include <CesiumAsync/Future.h>
5#include <CesiumUtility/JsonHelpers.h>
6#include <CesiumUtility/Result.h>
8#include <rapidjson/document.h>
44 rapidjson::Document& doc,
45 std::vector<T>&& items,
47 : _operation(
std::move(operation)), _items(
std::move(items)) {
48 const auto& linksMember = doc.FindMember(
"_links");
49 if (linksMember != doc.MemberEnd() && linksMember->value.IsObject()) {
50 const auto& selfMember = linksMember->value.FindMember(
"self");
51 if (selfMember != doc.MemberEnd() && selfMember->value.IsObject()) {
52 this->_selfUrl = CesiumUtility::JsonHelpers::getStringOrDefault(
58 const auto& nextMember = linksMember->value.FindMember(
"next");
59 if (nextMember != doc.MemberEnd() && nextMember->value.IsObject()) {
60 this->_nextUrl = CesiumUtility::JsonHelpers::getStringOrDefault(
66 const auto& prevMember = linksMember->value.FindMember(
"prev");
67 if (prevMember != doc.MemberEnd() && prevMember->value.IsObject()) {
68 this->_prevUrl = CesiumUtility::JsonHelpers::getStringOrDefault(
84 const T&
operator[](
size_t index)
const {
return _items[index]; }
89 size_t size()
const {
return _items.size(); }
94 auto begin() {
return _items.begin(); }
98 auto begin()
const {
return _items.begin(); }
103 auto end() {
return _items.end(); }
107 auto end()
const {
return _items.end(); }
113 bool hasNextUrl()
const {
return this->_nextUrl.has_value(); }
119 bool hasPrevUrl()
const {
return this->_prevUrl.has_value(); }
130 if (!this->_nextUrl.has_value()) {
135 return _operation(connection, *this->_nextUrl);
147 if (!this->_prevUrl.has_value()) {
152 return _operation(connection, *this->_prevUrl);
156 PageOperation _operation;
157 std::vector<T> _items;
158 std::optional<std::string> _selfUrl = std::nullopt;
159 std::optional<std::string> _nextUrl = std::nullopt;
160 std::optional<std::string> _prevUrl = std::nullopt;
A system for managing asynchronous requests and tasks.
Future< T > createResolvedFuture(T &&value) const
Creates a future that is already resolved.
A value that will be available in the future, as produced by AsyncSystem.
Represents a connection to the Bentley iTwin API.
T & operator[](size_t index)
Returns the contained item at index.
const T & operator[](size_t index) const
Returns the contained item at index.
auto begin() const
The begin iterator of the underlying vector.
std::function< CesiumAsync::Future< CesiumUtility::Result< PagedList< T > > >(Connection &, const std::string &)> PageOperation
Callback used to obtain a page of results from a URL.
CesiumAsync::Future< CesiumUtility::Result< PagedList< T > > > next(CesiumAsync::AsyncSystem &asyncSystem, Connection &connection) const
Returns a future that will return the next page of items.
auto end()
The end iterator of the underlying vector.
CesiumAsync::Future< CesiumUtility::Result< PagedList< T > > > prev(CesiumAsync::AsyncSystem &asyncSystem, Connection &connection) const
Returns a future that will return the previous page of items.
auto begin()
The begin iterator of the underlying vector.
bool hasPrevUrl() const
Checks whether this PagedList contains a URL to a previous page that can be fetched.
size_t size() const
Returns the number of contained items.
PagedList(rapidjson::Document &doc, std::vector< T > &&items, PageOperation &&operation)
Creates a new PagedList from a set of items, an iTwin API response, and a callback to retrieve more i...
auto end() const
The end iterator of the underlying vector.
bool hasNextUrl() const
Checks whether this PagedList contains a URL to another page that can be fetched.
Classes for interacting with the iTwin API.
Holds the result of an operation. If the operation succeeds, it will provide a value....