azure-core
Loading...
Searching...
No Matches
paged_response.hpp
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
9#pragma once
10
14
15#include <cstdlib>
16#include <string>
17
18namespace Azure { namespace Core {
19
29 template <class T> class PagedResponse {
30 private:
31 // The field used to check when the end of the response is reached. We default it true as the
32 // starting point because all responses from a service will always come with a payload that
33 // represents at least one page. The page might or might not contain elements in the page.
34 // `m_hasPage` is then turned to `false` once `MoveToNextPage` is called on the last page.
35 bool m_hasPage = true;
36
37 protected:
42 PagedResponse() = default;
43
49
55
56 public:
61 virtual ~PagedResponse() = default;
62
67 std::string CurrentPageToken;
68
79
84 std::unique_ptr<Azure::Core::Http::RawResponse> RawResponse;
85
93 bool HasPage() const { return m_hasPage; }
94
103 {
104 static_assert(
105 std::is_base_of<PagedResponse, T>::value,
106 "The template argument \"T\" should derive from PagedResponse<T>.");
107
108 if (!NextPageToken.HasValue() || NextPageToken.Value().empty())
109 {
110 m_hasPage = false;
111 return;
112 }
113
114 // Developer must make sure current page is kept unchanged if OnNextPage()
115 // throws exception.
116 static_cast<T*>(this)->OnNextPage(context);
117 }
118 };
119
120}} // namespace Azure::Core
A context is a node within a unidirectional tree that represents deadlines and key/value pairs.
Definition context.hpp:72
The base type and behavior for a paged response.
Definition paged_response.hpp:29
PagedResponse & operator=(PagedResponse &&)=default
Assigns another instance of PagedResponse by moving it in.
bool HasPage() const
Checks if a page exists.
Definition paged_response.hpp:93
Azure::Nullable< std::string > NextPageToken
The token for getting the next page.
Definition paged_response.hpp:78
void MoveToNextPage(const Azure::Core::Context &context=Azure::Core::Context())
Moves to the next page of the response.
Definition paged_response.hpp:102
std::string CurrentPageToken
The token used to fetch the current page.
Definition paged_response.hpp:67
PagedResponse()=default
Constructs a default instance of PagedResponse.
std::unique_ptr< Azure::Core::Http::RawResponse > RawResponse
The HTTP response returned by the service.
Definition paged_response.hpp:84
PagedResponse(PagedResponse &&)=default
Constructs PagedResponse by moving in another instance.
virtual ~PagedResponse()=default
Destructs PagedResponse.
Manages an optional contained value, i.e. a value that may or may not be present.
Definition nullable.hpp:30
const T & Value() const &noexcept
Get the contained value.
Definition nullable.hpp:236
bool HasValue() const noexcept
Check whether a value is contained.
Definition nullable.hpp:230
Context for canceling long running operations.
Compute the hash value for the input binary data, using SHA256, SHA384 and SHA512.
Definition azure_assert.hpp:57
Manages an optional contained value, i.e. a value that may or may not be present.
Define the HTTP raw response.