Couchbase C++ SDK 1.0.4 (rev. 5355b0f)
Loading...
Searching...
No Matches
increment_options.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 2020-Present 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
22#include <couchbase/error.hxx>
23#include <couchbase/expiry.hxx>
24
25#include <chrono>
26#include <functional>
27#include <memory>
28#include <optional>
29
30namespace couchbase
31{
38struct increment_options : public common_durability_options<increment_options> {
45 struct built : public common_durability_options<increment_options>::built {
46 const std::uint32_t expiry;
47 const std::uint64_t delta;
48 const std::optional<std::uint64_t> initial_value;
49 };
50
62 [[nodiscard]] auto build() const -> built
63 {
65 return { base, expiry_, delta_, initial_value_ };
66 }
67
81 auto expiry(std::chrono::seconds duration) -> increment_options&
82 {
83 expiry_ = core::impl::expiry_relative(duration);
84 return self();
85 }
86
97 auto expiry(std::chrono::system_clock::time_point time_point) -> increment_options&
98 {
99 expiry_ = core::impl::expiry_absolute(time_point);
100 return self();
101 }
102
112 auto delta(std::uint64_t delta) -> increment_options&
113 {
114 delta_ = delta;
115 return self();
116 }
117
127 auto initial(std::uint64_t value) -> increment_options&
128 {
129 initial_value_ = value;
130 return self();
131 }
132
133private:
134 std::uint32_t expiry_{ 0 };
135 std::uint64_t delta_{ 1 };
136 std::optional<std::uint64_t> initial_value_{};
137};
138
145using increment_handler = std::function<void(error, counter_result)>;
146} // namespace couchbase
Common options that used by most operations.
Definition common_durability_options.hxx:39
auto build_common_durability_options() const -> built
Definition common_durability_options.hxx:100
auto self() -> increment_options &
Definition common_options.hxx:116
Represents result of counter operations.
Definition counter_result.hxx:35
Definition error.hxx:30
Represents a single item from the result of collection::scan()
Definition allow_querying_search_index_options.hxx:28
std::function< void(error, counter_result)> increment_handler
The signature for the handler of the binary_collection::increment() operation.
Definition increment_options.hxx:145
Immutable value object representing consistent options.
Definition increment_options.hxx:45
const std::optional< std::uint64_t > initial_value
Definition increment_options.hxx:48
const std::uint64_t delta
Definition increment_options.hxx:47
const std::uint32_t expiry
Definition increment_options.hxx:46
Options for binary_collection::increment().
Definition increment_options.hxx:38
auto build() const -> built
Validates options and returns them as an immutable value.
Definition increment_options.hxx:62
auto initial(std::uint64_t value) -> increment_options &
The initial value that should be used if the document has not been created yet.
Definition increment_options.hxx:127
auto delta(std::uint64_t delta) -> increment_options &
The amount of which the document value should be incremented.
Definition increment_options.hxx:112
auto expiry(std::chrono::system_clock::time_point time_point) -> increment_options &
Sets the expiry for the document.
Definition increment_options.hxx:97
auto expiry(std::chrono::seconds duration) -> increment_options &
Sets the expiry for the document.
Definition increment_options.hxx:81