Couchbase C++ SDK 1.4.0 (rev. 59aa900)
Loading...
Searching...
No Matches
transaction_get_multi_replicas_from_preferred_server_group_result.hxx
Go to the documentation of this file.
1/*
2 * Copyright 2021-Present Couchbase, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
19
20#include <cstddef>
21#include <optional>
22#include <stdexcept>
23#include <string>
24#include <vector>
25
26namespace couchbase
27{
28namespace core::transactions
29{
30class attempt_context_impl;
31} // namespace core::transactions
32
33namespace transactions
34{
36{
37public:
47
56 template<typename Document, std::enable_if_t<!codec::is_transcoder_v<Document>, bool> = true>
57 [[nodiscard]] auto content_as(std::size_t spec_index) const -> Document
58 {
60 }
61
67 template<typename Document,
68 typename Transcoder,
69 std::enable_if_t<!codec::is_transcoder_v<Document>, bool> = true,
70 std::enable_if_t<codec::is_transcoder_v<Transcoder>, bool> = true>
71 [[nodiscard]] auto content_as(std::size_t spec_index) const -> Document
72 {
73 return Transcoder::template decode<Document>(content_at(spec_index));
74 }
75
81 template<typename Transcoder, std::enable_if_t<codec::is_transcoder_v<Transcoder>, bool> = true>
82 [[nodiscard]] auto content_as(std::size_t spec_index) const -> typename Transcoder::document_type
83 {
84 return Transcoder::decode(content_at(spec_index));
85 }
86
92 [[nodiscard]] auto exists(std::size_t spec_index) const -> bool
93 {
94 if (spec_index >= content_.size()) {
95 throw std::invalid_argument("spec index " + std::to_string(spec_index) + " is not valid");
96 }
97 return content_[spec_index].has_value();
98 }
99
100private:
101 friend core::transactions::attempt_context_impl;
102
104 std::vector<std::optional<codec::encoded_value>> content)
105 : content_{ std::move(content) }
106 {
107 }
108
109 [[nodiscard]] auto content_at(std::size_t spec_index) const -> const codec::encoded_value&;
110
111 std::vector<std::optional<codec::encoded_value>> content_;
112};
113} // namespace transactions
114} // namespace couchbase
static auto decode(const encoded_value &encoded) -> Document
Definition lenient_json_transcoder.hxx:56
auto content_as(std::size_t spec_index) const -> Document
Content of the document.
Definition transaction_get_multi_replicas_from_preferred_server_group_result.hxx:57
auto content_as(std::size_t spec_index) const -> typename Transcoder::document_type
Content of the document, decoded with the given transcoder.
Definition transaction_get_multi_replicas_from_preferred_server_group_result.hxx:82
auto operator=(transaction_get_multi_replicas_from_preferred_server_group_result &&) -> transaction_get_multi_replicas_from_preferred_server_group_result &=default
transaction_get_multi_replicas_from_preferred_server_group_result(transaction_get_multi_replicas_from_preferred_server_group_result &&)=default
transaction_get_multi_replicas_from_preferred_server_group_result(const transaction_get_multi_replicas_from_preferred_server_group_result &)=default
auto content_as(std::size_t spec_index) const -> Document
Content of the document, decoded with the given transcoder.
Definition transaction_get_multi_replicas_from_preferred_server_group_result.hxx:71
auto exists(std::size_t spec_index) const -> bool
Check if spec returned any content.
Definition transaction_get_multi_replicas_from_preferred_server_group_result.hxx:92
auto operator=(const transaction_get_multi_replicas_from_preferred_server_group_result &) -> transaction_get_multi_replicas_from_preferred_server_group_result &=default
Definition transaction_get_multi_options.hxx:23
Definition transactions.hxx:43
Represents a single item from the result of scan().
Definition allow_querying_search_index_options.hxx:28
Definition encoded_value.hxx:27