Couchbase C++ SDK 1.4.0 (rev. 59aa900)
Loading...
Searching...
No Matches
analytics_stream_result.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2026. Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
23#include <couchbase/error.hxx>
24
25#include <functional>
26#include <future>
27#include <memory>
28#include <optional>
29#include <utility>
30
31namespace couchbase
32{
33#ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
34class internal_analytics_stream_result;
35#endif
36
43using analytics_row_handler = std::function<void(error, std::optional<analytics_row>)>;
44
68{
69public:
77
86 explicit analytics_stream_result(std::shared_ptr<internal_analytics_stream_result> internal);
87
101 void next(analytics_row_handler&& handler) const;
102
113 [[nodiscard]] auto next() const -> std::future<std::pair<error, std::optional<analytics_row>>>;
114
128 [[nodiscard]] auto signature() const -> std::optional<codec::binary>;
129
143 [[nodiscard]] auto meta_data() const -> std::future<std::pair<error, analytics_meta_data>>;
144
156 void cancel() const;
157
167 };
168
188 {
189 public:
190 auto operator*() const -> std::pair<error, analytics_row>;
191 auto operator++() -> iterator&;
192
199 explicit iterator(std::shared_ptr<internal_analytics_stream_result> internal);
200
208 friend auto operator==(const iterator& it, end_sentinel /* end */) -> bool
209 {
210 return it.terminal_;
211 }
212 friend auto operator==(end_sentinel end, const iterator& it) -> bool
213 {
214 return it == end;
215 }
216 friend auto operator!=(const iterator& it, end_sentinel end) -> bool
217 {
218 return !(it == end);
219 }
220 friend auto operator!=(end_sentinel end, const iterator& it) -> bool
221 {
222 return !(it == end);
223 }
224
225 // Intentionally no std::iterator_traits typedefs (notably no iterator_category). This is a
226 // deliberately minimal single-pass iterator for range-based for and `while (it !=
227 // result.end())` loops only (see the class doc); it omits post-increment and operator->.
228 // Declaring an input_iterator_tag while omitting those would falsely advertise
229 // LegacyInputIterator / std::input_iterator conformance and could break generic code that
230 // trusts iterator_traits. Range-based for needs none of these typedefs.
231
232 private:
233 void fetch_item();
234
235 std::shared_ptr<internal_analytics_stream_result> internal_{};
236 std::pair<error, analytics_row> item_{};
237 bool terminal_{ false };
238 // Set when fetch_item() lands on a terminal error: the error element is delivered once (the
239 // iterator is not yet equal to end()), and the next increment advances to true end.
240 bool error_pending_{ false };
241 };
242
251 [[nodiscard]] auto begin() const -> iterator;
252
261 [[nodiscard]] auto end() const -> end_sentinel;
262
263private:
264 std::shared_ptr<internal_analytics_stream_result> internal_{};
265};
266} // namespace couchbase
Stores any non-rows results related to the execution of a particular Analytics query.
Definition analytics_meta_data.hxx:40
Represents a single row of a streaming analytics result.
Definition analytics_row.hxx:41
A single-pass input iterator that synchronously fetches rows one at a time.
Definition analytics_stream_result.hxx:188
friend auto operator==(end_sentinel end, const iterator &it) -> bool
Definition analytics_stream_result.hxx:212
auto operator*() const -> std::pair< error, analytics_row >
friend auto operator!=(const iterator &it, end_sentinel end) -> bool
Definition analytics_stream_result.hxx:216
friend auto operator!=(end_sentinel end, const iterator &it) -> bool
Definition analytics_stream_result.hxx:220
iterator(std::shared_ptr< internal_analytics_stream_result > internal)
Constructs an iterator over an internal result; prefer begin().
auto signature() const -> std::optional< codec::binary >
Returns the analytics signature captured from the response metadata, if present.
analytics_stream_result(std::shared_ptr< internal_analytics_stream_result > internal)
Constructs an analytics stream result from an internal result.
auto next() const -> std::future< std::pair< error, std::optional< analytics_row > > >
Fetches the next row, returning a future.
auto meta_data() const -> std::future< std::pair< error, analytics_meta_data > >
Returns the analytics metadata.
analytics_stream_result()=default
Constructs an empty (no-op) result handle.
void cancel() const
Cancels the stream and closes the underlying HTTP connection.
auto begin() const -> iterator
Returns an iterator to the beginning.
void next(analytics_row_handler &&handler) const
Fetches the next row asynchronously, invoking the handler when ready.
auto end() const -> end_sentinel
Returns the end sentinel.
Definition error.hxx:31
Definition analytics_options.hxx:36
Represents a single item from the result of scan().
Definition allow_querying_search_index_options.hxx:28
std::function< void(error, std::optional< analytics_row >)> analytics_row_handler
The signature for the handler of the next() operation.
Definition analytics_stream_result.hxx:43
Sentinel returned by end().
Definition analytics_stream_result.hxx:166