MongoDB C++ Driver  mongocxx-3.0.2
write_concern.hpp
1 // Copyright 2014 MongoDB Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <chrono>
18 #include <cstdint>
19 #include <stdexcept>
20 #include <memory>
21 
22 #include <bsoncxx/stdx/optional.hpp>
23 #include <bsoncxx/stdx/string_view.hpp>
24 #include <mongocxx/stdx.hpp>
25 
26 #include <mongocxx/config/prelude.hpp>
27 
28 namespace mongocxx {
29 MONGOCXX_INLINE_NAMESPACE_BEGIN
30 
31 class bulk_write;
32 class client;
33 class collection;
34 class database;
35 class uri;
36 
54 class MONGOCXX_API write_concern {
55  public:
60  enum class level {
61  k_default,
62  k_majority,
63  k_tag,
64  k_unacknowledged,
65  k_unknown,
66  };
67 
71  write_concern();
72 
77 
81  write_concern& operator=(const write_concern&);
82 
86  write_concern(write_concern&&) noexcept;
87 
91  write_concern& operator=(write_concern&&) noexcept;
92 
96  ~write_concern();
97 
106  void journal(bool journal);
107 
123  void nodes(std::int32_t confirm_from);
124 
139  void acknowledge_level(level confirm_level);
140 
150  //
151  void majority(std::chrono::milliseconds timeout);
152 
162  void tag(stdx::string_view tag);
163 
173  void timeout(std::chrono::milliseconds timeout);
174 
180  bool journal() const;
181 
191  stdx::optional<std::int32_t> nodes() const;
192 
202  stdx::optional<level> acknowledge_level() const;
203 
209  stdx::optional<std::string> tag() const;
210 
216  bool majority() const;
217 
223  std::chrono::milliseconds timeout() const;
224 
225  private:
226  friend bulk_write;
227  friend client;
228  friend collection;
229  friend database;
230  friend uri;
231 
232  class MONGOCXX_PRIVATE impl;
233 
234  MONGOCXX_PRIVATE write_concern(std::unique_ptr<impl>&& implementation);
235 
236  std::unique_ptr<impl> _impl;
237 };
238 
239 MONGOCXX_INLINE_NAMESPACE_END
240 } // namespace mongocxx
241 
242 #include <mongocxx/config/postlude.hpp>
Class representing a MongoDB connection string URI.
Definition: uri.hpp:40
Definition: bulk_write.hpp:22
Definition: error_code.hpp:69
Class representing a client connection to MongoDB.
Definition: client.hpp:49
Class representing a MongoDB database.
Definition: database.hpp:43
level
A class to represent the special case values for write_concern::nodes.
Definition: write_concern.hpp:60
Class representing a batch of write operations that can be sent to the server as a group...
Definition: bulk_write.hpp:41
Class representing the server-side requirement for reporting the success of a write operation...
Definition: write_concern.hpp:54
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:74