Couchbase C++ SDK 1.4.0 (rev. 59aa900)
Loading...
Searching...
No Matches
transaction_get_multi_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:
44
53 template<typename Document, std::enable_if_t<!codec::is_transcoder_v<Document>, bool> = true>
54 [[nodiscard]] auto content_as(std::size_t spec_index) const -> Document
55 {
57 }
58
64 template<typename Document,
65 typename Transcoder,
66 std::enable_if_t<!codec::is_transcoder_v<Document>, bool> = true,
67 std::enable_if_t<codec::is_transcoder_v<Transcoder>, bool> = true>
68 [[nodiscard]] auto content_as(std::size_t spec_index) const -> Document
69 {
70 return Transcoder::template decode<Document>(content_at(spec_index));
71 }
72
78 template<typename Transcoder, std::enable_if_t<codec::is_transcoder_v<Transcoder>, bool> = true>
79 [[nodiscard]] auto content_as(std::size_t spec_index) const -> typename Transcoder::document_type
80 {
81 return Transcoder::decode(content_at(spec_index));
82 }
83
89 [[nodiscard]] auto exists(std::size_t spec_index) const -> bool
90 {
91 if (spec_index >= content_.size()) {
92 throw std::invalid_argument("spec index " + std::to_string(spec_index) + " is not valid");
93 }
94 return content_[spec_index].has_value();
95 }
96
97private:
98 friend core::transactions::attempt_context_impl;
99
100 explicit transaction_get_multi_result(std::vector<std::optional<codec::encoded_value>> content)
101 : content_{ std::move(content) }
102 {
103 }
104
105 [[nodiscard]] auto content_at(std::size_t spec_index) const -> const codec::encoded_value&;
106
107 std::vector<std::optional<codec::encoded_value>> content_;
108};
109} // namespace transactions
110} // namespace couchbase
static auto decode(const encoded_value &encoded) -> Document
Definition lenient_json_transcoder.hxx:56
auto operator=(const transaction_get_multi_result &) -> transaction_get_multi_result &=default
transaction_get_multi_result(const transaction_get_multi_result &)=default
transaction_get_multi_result(transaction_get_multi_result &&)=default
auto content_as(std::size_t spec_index) const -> Document
Content of the document.
Definition transaction_get_multi_result.hxx:54
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_result.hxx:79
auto operator=(transaction_get_multi_result &&) -> transaction_get_multi_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_result.hxx:68
auto exists(std::size_t spec_index) const -> bool
Check if spec returned any content.
Definition transaction_get_multi_result.hxx:89
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