Couchbase C++ SDK 1.0.1 (rev. 58d46d7)
Loading...
Searching...
No Matches
decrement_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/expiry.hxx>
23
24#include <chrono>
25#include <functional>
26#include <memory>
27#include <optional>
28
29namespace couchbase
30{
37struct decrement_options : public common_durability_options<decrement_options> {
44 struct built : public common_durability_options<decrement_options>::built {
45 const std::uint32_t expiry;
46 const std::uint64_t delta;
47 const std::optional<std::uint64_t> initial_value;
48 };
49
61 [[nodiscard]] auto build() const -> built
62 {
64 return { base, expiry_, delta_, initial_value_ };
65 }
66
80 auto expiry(std::chrono::seconds duration) -> decrement_options&
81 {
82 expiry_ = core::impl::expiry_relative(duration);
83 return self();
84 }
85
96 auto expiry(std::chrono::system_clock::time_point time_point) -> decrement_options&
97 {
98 expiry_ = core::impl::expiry_absolute(time_point);
99 return self();
100 }
101
111 auto delta(std::uint64_t delta) -> decrement_options&
112 {
113 delta_ = delta;
114 return self();
115 }
116
126 auto initial(std::uint64_t value) -> decrement_options&
127 {
128 initial_value_ = value;
129 return self();
130 }
131
132private:
133 std::uint32_t expiry_{ 0 };
134 std::uint64_t delta_{ 1 };
135 std::optional<std::uint64_t> initial_value_{};
136};
137
144using decrement_handler = std::function<void(error, counter_result)>;
145} // 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() -> derived_class &
Allows to return the right options builder instance for child implementations.
Definition common_options.hxx:102
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)> decrement_handler
The signature for the handler of the binary_collection::decrement() operation.
Definition decrement_options.hxx:144
Immutable value object representing consistent options.
Definition decrement_options.hxx:44
const std::optional< std::uint64_t > initial_value
Definition decrement_options.hxx:47
const std::uint64_t delta
Definition decrement_options.hxx:46
const std::uint32_t expiry
Definition decrement_options.hxx:45
Options for collection::decrement().
Definition decrement_options.hxx:37
auto initial(std::uint64_t value) -> decrement_options &
The initial value that should be used if the document has not been created yet.
Definition decrement_options.hxx:126
auto expiry(std::chrono::system_clock::time_point time_point) -> decrement_options &
Sets the expiry for the document.
Definition decrement_options.hxx:96
auto build() const -> built
Validates options and returns them as an immutable value.
Definition decrement_options.hxx:61
auto expiry(std::chrono::seconds duration) -> decrement_options &
Sets the expiry for the document.
Definition decrement_options.hxx:80
auto delta(std::uint64_t delta) -> decrement_options &
The amount of which the document value should be decremented.
Definition decrement_options.hxx:111