Couchbase C++ SDK
1.4.0 (rev. 59aa900)
Toggle main menu visibility
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
18
#include <
couchbase/codec/lenient_json_transcoder.hxx
>
19
20
#include <cstddef>
21
#include <optional>
22
#include <stdexcept>
23
#include <string>
24
#include <vector>
25
26
namespace
couchbase
27
{
28
namespace
core::transactions
29
{
30
class
attempt_context_impl;
31
}
// namespace core::transactions
32
33
namespace
transactions
34
{
35
class
transaction_get_multi_result
36
{
37
public
:
38
transaction_get_multi_result
() =
default
;
39
~transaction_get_multi_result
() =
default
;
40
transaction_get_multi_result
(
const
transaction_get_multi_result
&) =
default
;
41
transaction_get_multi_result
(
transaction_get_multi_result
&&) =
default
;
42
auto
operator=
(
const
transaction_get_multi_result
&) ->
transaction_get_multi_result
& =
default
;
43
auto
operator=
(
transaction_get_multi_result
&&) ->
transaction_get_multi_result
& =
default
;
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
{
56
return
codec::default_lenient_json_transcoder::decode<Document>
(content_at(spec_index));
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
97
private
:
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
couchbase::codec::lenient_json_transcoder< tao_json_serializer >::decode
static auto decode(const encoded_value &encoded) -> Document
Definition
lenient_json_transcoder.hxx:56
couchbase::transactions::transaction_get_multi_result::operator=
auto operator=(const transaction_get_multi_result &) -> transaction_get_multi_result &=default
couchbase::transactions::transaction_get_multi_result::transaction_get_multi_result
transaction_get_multi_result()=default
couchbase::transactions::transaction_get_multi_result::transaction_get_multi_result
transaction_get_multi_result(const transaction_get_multi_result &)=default
couchbase::transactions::transaction_get_multi_result::transaction_get_multi_result
transaction_get_multi_result(transaction_get_multi_result &&)=default
couchbase::transactions::transaction_get_multi_result::content_as
auto content_as(std::size_t spec_index) const -> Document
Content of the document.
Definition
transaction_get_multi_result.hxx:54
couchbase::transactions::transaction_get_multi_result::content_as
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
couchbase::transactions::transaction_get_multi_result::operator=
auto operator=(transaction_get_multi_result &&) -> transaction_get_multi_result &=default
couchbase::transactions::transaction_get_multi_result::content_as
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
couchbase::transactions::transaction_get_multi_result::~transaction_get_multi_result
~transaction_get_multi_result()=default
couchbase::transactions::transaction_get_multi_result::exists
auto exists(std::size_t spec_index) const -> bool
Check if spec returned any content.
Definition
transaction_get_multi_result.hxx:89
lenient_json_transcoder.hxx
couchbase::core::transactions
Definition
transaction_get_multi_options.hxx:23
couchbase::transactions
Definition
transactions.hxx:43
couchbase
Represents a single item from the result of scan().
Definition
allow_querying_search_index_options.hxx:28
couchbase::codec::encoded_value
Definition
encoded_value.hxx:27
couchbase
transactions
transaction_get_multi_result.hxx
Generated by
1.17.0