MongoDB C++ Driver  mongocxx-3.10.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 <memory>
20 #include <stdexcept>
21 
22 #include <mongocxx/bulk_write-fwd.hpp>
23 #include <mongocxx/client-fwd.hpp>
24 #include <mongocxx/collection-fwd.hpp>
25 #include <mongocxx/database-fwd.hpp>
26 #include <mongocxx/options/transaction-fwd.hpp>
27 #include <mongocxx/uri-fwd.hpp>
28 #include <mongocxx/write_concern-fwd.hpp>
29 
30 #include <bsoncxx/document/value.hpp>
31 #include <bsoncxx/stdx/optional.hpp>
32 #include <bsoncxx/stdx/string_view.hpp>
33 #include <mongocxx/options/transaction.hpp>
34 #include <mongocxx/stdx.hpp>
35 
36 #include <mongocxx/config/prelude.hpp>
37 
38 namespace mongocxx {
39 namespace v_noabi {
40 
59  public:
64  enum class level { k_default, k_majority, k_tag, k_unacknowledged, k_acknowledged };
65 
70 
75 
80 
85 
89  write_concern& operator=(write_concern&&) noexcept;
90 
95 
104  void journal(bool journal);
105 
121  void nodes(std::int32_t confirm_from);
122 
146  void acknowledge_level(level confirm_level);
147 
158  void majority(std::chrono::milliseconds timeout);
159 
169  void tag(stdx::string_view tag);
170 
181  void timeout(std::chrono::milliseconds timeout);
182 
188  bool journal() const;
189 
200  stdx::optional<std::int32_t> nodes() const;
201 
210 
216  stdx::optional<std::string> tag() const;
217 
223  bool majority() const;
224 
230  std::chrono::milliseconds timeout() const;
231 
237  bool is_acknowledged() const;
238 
245  bsoncxx::v_noabi::document::value to_document() const;
246 
247  private:
248  friend ::mongocxx::v_noabi::bulk_write;
249  friend ::mongocxx::v_noabi::client;
250  friend ::mongocxx::v_noabi::collection;
251  friend ::mongocxx::v_noabi::database;
252  friend ::mongocxx::v_noabi::options::transaction;
253  friend ::mongocxx::v_noabi::uri;
254 
262  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const write_concern&, const write_concern&);
263  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const write_concern&, const write_concern&);
267 
268  class MONGOCXX_PRIVATE impl;
269 
270  MONGOCXX_PRIVATE write_concern(std::unique_ptr<impl>&& implementation);
271 
272  std::unique_ptr<impl> _impl;
273 };
274 
275 } // namespace v_noabi
276 } // namespace mongocxx
277 
278 #include <mongocxx/config/postlude.hpp>
Class representing a batch of write operations that can be sent to the server as a group.
Definition: bulk_write.hpp:44
Class representing a client connection to MongoDB.
Definition: client.hpp:61
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:86
Class representing a MongoDB database.
Definition: database.hpp:46
Class representing a MongoDB connection string URI.
Definition: uri.hpp:47
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:58
level acknowledge_level() const
Gets the current acknowledgment level.
bool is_acknowledged() const
Gets whether this write_concern requires an acknowledged write.
write_concern & operator=(const write_concern &)
Copy assigns a write_concern.
write_concern(const write_concern &)
Copy constructs a write_concern.
std::chrono::milliseconds timeout() const
Gets the current timeout for this write_concern.
bool journal() const
Gets the current status of the journal parameter.
stdx::optional< std::int32_t > nodes() const
Gets the current number of nodes that this write_concern requires operations to reach.
level
A class to represent the special case values for write_concern::nodes.
Definition: write_concern.hpp:64
bsoncxx::v_noabi::document::value to_document() const
Gets the document form of this write_concern.
bool majority() const
Gets whether the majority of nodes is currently required by this write_concern.
write_concern(write_concern &&) noexcept
Move constructs a write_concern.
write_concern()
Constructs a new write_concern.
stdx::optional< std::string > tag() const
Gets the current getLastErrorMode that is required by this write_concern.
The top-level namespace for bsoncxx library entities.
Definition: element-fwd.hpp:19
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19