AWS SDK for C++

AWS SDK for C++ Version 1.11.759

Loading...
Searching...
No Matches
Paginator.h
1
6#pragma once
7
8#include <iterator>
9#include <cstddef>
10#include <memory>
11
12namespace Aws
13{
14namespace Utils
15{
16namespace Pagination
17{
18
19template <class ServiceClient, class OperationRequest, class OperationTraits>
21{
22public:
23 using OutcomeType = typename OperationTraits::OutcomeType;
24 using ResultType = typename OperationTraits::ResultType;
25
27 {
28 public:
29 using iterator_category = std::input_iterator_tag;
31 using difference_type = std::ptrdiff_t;
32 using pointer = const OutcomeType*;
33 using reference = const OutcomeType&;
34
35 Iterator(ServiceClient* client, const OperationRequest& firstReq)
36 : m_client(client), m_request(firstReq), m_currentOutcome{OperationTraits::Invoke(m_client, m_request)} {}
37
38 const OutcomeType& operator*() const { return m_currentOutcome; }
39
41 {
42 if (m_atEnd) return *this;
43
44 if (!m_currentOutcome.IsSuccess())
45 {
46 m_atEnd = true;
47 return *this;
48 }
49
50 if (!OperationTraits::HasMoreResults(m_currentOutcome.GetResult()))
51 {
52 m_atEnd = true;
53 return *this;
54 }
55
56 OperationTraits::SetNextRequest(m_currentOutcome.GetResult(), m_request);
57 Fetch();
58 return *this;
59 }
60
61 friend bool operator==(const Iterator& lhs, const Iterator& rhs) {
62 if (rhs.m_isSentinel) {
63 return lhs.m_atEnd;
64 }
65 return false;
66 }
67
68 friend bool operator!=(const Iterator& lhs, const Iterator& rhs) { return !(lhs == rhs); }
69 static Iterator constructSentinel() {return Iterator{};}
70
71 private:
72 Iterator() : m_isSentinel{true} {};
73
74 void Fetch() { m_currentOutcome = OperationTraits::Invoke(m_client, m_request); }
75
76
77 ServiceClient* m_client;
78 OperationRequest m_request{};
79 OutcomeType m_currentOutcome{};
80 bool m_atEnd{false};
81 bool m_isSentinel{false};
82 };
83
84 Paginator(ServiceClient* client, const OperationRequest& firstReq) : m_client(client), m_firstRequest(firstReq) {}
85
86 Iterator begin() const { return Iterator(m_client, m_firstRequest); }
88
89 private:
90 ServiceClient* m_client;
91 OperationRequest m_firstRequest{};
92};
93
94} // namespace Pagination
95} // namespace Utils
96} // namespace Aws
const OutcomeType & operator*() const
Definition Paginator.h:38
Iterator(ServiceClient *client, const OperationRequest &firstReq)
Definition Paginator.h:35
friend bool operator==(const Iterator &lhs, const Iterator &rhs)
Definition Paginator.h:61
friend bool operator!=(const Iterator &lhs, const Iterator &rhs)
Definition Paginator.h:68
std::input_iterator_tag iterator_category
Definition Paginator.h:29
typename OperationTraits::ResultType ResultType
Definition Paginator.h:24
Paginator(ServiceClient *client, const OperationRequest &firstReq)
Definition Paginator.h:84
typename OperationTraits::OutcomeType OutcomeType
Definition Paginator.h:23