Couchbase C++ SDK 1.2.0 (rev. c2439a4)
Loading...
Searching...
No Matches
scan_result_item.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 2024. 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
20#include <couchbase/cas.hxx>
24#include <couchbase/result.hxx>
25
26#include <chrono>
27#include <optional>
28#include <string>
29#include <type_traits>
30#include <utility>
31
38namespace couchbase
39{
40#ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
41namespace crypto
42{
43class manager;
44} // namespace crypto
45#endif
46
48{
49public:
56 scan_result_item() = default;
57
69 scan_result_item(std::string id,
72 std::optional<std::chrono::system_clock::time_point> expiry_time,
73 std::shared_ptr<crypto::manager> crypto_manager = {})
74 : result{ cas }
75 , id_{ std::move(id) }
76 , id_only_{ false }
77 , value_{ std::move(value) }
78 , expiry_time_{ expiry_time }
79 , crypto_manager_{ std::move(crypto_manager) }
80 {
81 }
82
91 explicit scan_result_item(std::string id)
92 : id_{ std::move(id) }
93 , id_only_{ true }
94 {
95 }
96
97 bool operator==(const scan_result_item& other) const
98 {
99 return id_ == other.id_ && cas() == other.cas();
100 }
101
110 [[nodiscard]] auto id() const -> const std::string&
111 {
112 return id_;
113 }
114
124 [[nodiscard]] auto id_only() const -> bool
125 {
126 return id_only_;
127 }
128
144 template<typename Document,
145 typename Transcoder = codec::default_json_transcoder,
146 std::enable_if_t<!codec::is_transcoder_v<Document>, bool> = true,
147 std::enable_if_t<codec::is_transcoder_v<Transcoder>, bool> = true>
148 [[nodiscard]] auto content_as() const -> Document
149 {
150 if (id_only_) {
151 return {};
152 }
154 return Transcoder::template decode<Document>(value_, crypto_manager_);
155 } else {
156 return Transcoder::template decode<Document>(value_);
157 }
158 }
159
173 [[nodiscard]] auto expiry_time() const
174 -> const std::optional<std::chrono::system_clock::time_point>&
175 {
176 return expiry_time_;
177 }
178
179private:
180 std::string id_{};
181 bool id_only_{};
182 codec::encoded_value value_{};
183 std::optional<std::chrono::system_clock::time_point> expiry_time_{};
184 std::shared_ptr<crypto::manager> crypto_manager_{};
185};
186} // namespace couchbase
CAS is a special type that represented in protocol using unsigned 64-bit integer, but only equality c...
Definition cas.hxx:34
Base class for operations of data service.
Definition result.hxx:32
auto cas() const -> couchbase::cas
Definition result.hxx:57
scan_result_item()=default
Constructs an empty scan_result_item.
scan_result_item(std::string id, couchbase::cas cas, codec::encoded_value value, std::optional< std::chrono::system_clock::time_point > expiry_time, std::shared_ptr< crypto::manager > crypto_manager={})
Constructs an instance representing a single item from the result of a scan operation.
Definition scan_result_item.hxx:69
auto id() const -> const std::string &
Returns the ID of the document.
Definition scan_result_item.hxx:110
scan_result_item(std::string id)
Constructs an instance representing a single item from the result of an id-only scan operation.
Definition scan_result_item.hxx:91
bool operator==(const scan_result_item &other) const
Definition scan_result_item.hxx:97
auto id_only() const -> bool
Returns whether this scan result item only contains the document ID.
Definition scan_result_item.hxx:124
auto content_as() const -> Document
Decodes the content of the document using given codec.
Definition scan_result_item.hxx:148
auto expiry_time() const -> const std::optional< std::chrono::system_clock::time_point > &
If the document has an expiry, returns the point in time when the loaded document expires.
Definition scan_result_item.hxx:173
constexpr bool is_crypto_transcoder_v
Definition transcoder_traits.hxx:36
json_transcoder< tao_json_serializer > default_json_transcoder
Definition default_json_transcoder.hxx:28
Definition internal.hxx:27
Represents a single item from the result of scan()
Definition allow_querying_search_index_options.hxx:28
Definition encoded_value.hxx:27