Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
options.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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 
17 #pragma once
18 #include <boost/logic/tribool.hpp>
19 #include <boost/optional.hpp>
20 #include <boost/optional/optional_io.hpp>
21 #include <chrono>
22 #include <couchbase/support.hxx>
23 
28 namespace couchbase
29 {
30 
38 enum class durability_level {
39  none,
40  majority,
41  majority_and_persist_to_active,
42  persist_to_majority
43 };
44 
52  upsert,
53  insert,
54  replace
55 };
56 
62 template<typename T>
64 {
65  private:
66  boost::optional<std::chrono::microseconds> timeout_;
67 
68  public:
76  CB_NODISCARD boost::optional<std::chrono::microseconds> timeout() const
77  {
78  return timeout_;
79  }
86  template<typename R>
88  {
89  timeout_ = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
90  return *static_cast<T*>(this);
91  }
92 };
93 
97 template<typename T>
99 {
100  private:
101  boost::optional<uint64_t> cas_;
102  boost::optional<durability_level> durability_;
103 
104  public:
110  CB_NODISCARD boost::optional<uint64_t> cas() const
111  {
112  return cas_;
113  }
122  T& cas(uint64_t cas)
123  {
124  cas_ = cas;
125  return *static_cast<T*>(this);
126  }
127 
133  CB_NODISCARD boost::optional<durability_level> durability() const
134  {
135  return durability_;
136  }
144  {
145  durability_ = level;
146  return *static_cast<T*>(this);
147  }
148 };
149 
153 class get_options : public common_options<get_options>
154 {
155  private:
156  // TODO: ponder a clearer way to set expiry. Perhaps a duration _or_ time point?
157  boost::optional<uint32_t> expiry_;
158 
159  public:
165  CB_NODISCARD boost::optional<uint32_t> expiry() const
166  {
167  return expiry_;
168  }
182  get_options& expiry(uint32_t expiry)
183  {
184  expiry_ = expiry;
185  return *this;
186  }
187 };
188 
192 class exists_options : public common_options<exists_options>
193 {
194 };
195 
199 class upsert_options : public common_mutate_options<upsert_options>
200 {
201 };
202 
206 class replace_options : public common_mutate_options<replace_options>
207 {
208 };
209 
213 class remove_options : public common_mutate_options<remove_options>
214 {
215 };
216 
220 class insert_options : public common_mutate_options<insert_options>
221 {
222 };
223 
227 class lookup_in_options : public common_options<lookup_in_options>
228 {
229  private:
230  boost::tribool access_deleted_;
231 
232  public:
241  CB_NODISCARD boost::tribool access_deleted() const
242  {
243  return access_deleted_;
244  }
254  {
255  access_deleted_ = access_deleted;
256  return *this;
257  }
258 };
259 
263 class mutate_in_options : public common_mutate_options<mutate_in_options>
264 {
265  private:
266  boost::tribool create_as_deleted_;
267  boost::tribool access_deleted_;
268  boost::optional<subdoc_store_semantics> store_semantics_;
269 
270  public:
276  CB_NODISCARD boost::tribool create_as_deleted() const
277  {
278  return create_as_deleted_;
279  }
290  {
291  create_as_deleted_ = create_as_deleted;
292  return *this;
293  }
302  CB_NODISCARD boost::tribool access_deleted() const
303  {
304  return access_deleted_;
305  }
314  {
315  access_deleted_ = access_deleted;
316  return *this;
317  }
326  CB_NODISCARD boost::optional<subdoc_store_semantics> store_semantics() const
327  {
328  return store_semantics_;
329  }
343  {
344  store_semantics_ = semantics;
345  return *this;
346  }
347 };
348 
349 }; // namespace couchbase
CB_NODISCARD boost::optional< uint64_t > cas() const
Get cas.
Definition: options.hxx:110
CB_NODISCARD boost::tribool access_deleted() const
Get access deleted flag.
Definition: options.hxx:304
Options common to mutation operations.
Definition: options.hxx:98
Options for collection::insert()
Definition: options.hxx:222
Definition: bucket.hxx:33
mutate_in_options & access_deleted(boost::tribool access_deleted)
Set access_deleted flag.
Definition: options.hxx:315
Options for collection::remove()
Definition: options.hxx:215
CB_NODISCARD boost::tribool create_as_deleted() const
Get create_as_deleted flag.
Definition: options.hxx:278
T & durability(durability_level level)
Set durability.
Definition: options.hxx:143
CB_NODISCARD boost::optional< subdoc_store_semantics > store_semantics() const
Get store semantics.
Definition: options.hxx:328
Options for collection::upsert()
Definition: options.hxx:201
T & cas(uint64_t cas)
Set current CAS.
Definition: options.hxx:122
Options for collection::get()
Definition: options.hxx:153
CB_NODISCARD boost::tribool access_deleted() const
Get access deleted flag.
Definition: options.hxx:243
Options for collection::lookup_in()
Definition: options.hxx:229
get_options & expiry(uint32_t expiry)
Set expiry.
Definition: options.hxx:184
durability_level
KV Write Durability.
Definition: options.hxx:38
lookup_in_options & access_deleted(boost::tribool access_deleted)
Set access_deleted flag.
Definition: options.hxx:255
CB_NODISCARD boost::optional< std::chrono::microseconds > timeout() const
get timeout
Definition: options.hxx:76
Options for collection::replace()
Definition: options.hxx:208
mutate_in_options & create_as_deleted(boost::tribool create_as_deleted)
Set create_as_deleted.
Definition: options.hxx:291
CB_NODISCARD boost::optional< uint32_t > expiry() const
Get expiry.
Definition: options.hxx:166
Options for collection::mutate_in()
Definition: options.hxx:265
base class for all options
Definition: options.hxx:63
subdoc_store_semantics
store semantics for subdoc mutations
Definition: options.hxx:51
CB_NODISCARD boost::optional< durability_level > durability() const
Get Durability.
Definition: options.hxx:133
T & timeout(R timeout)
Set timeout.
Definition: options.hxx:87