Loading...
Searching...
No Matches
write.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <mongocxx/model/write-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/bulk_write.hpp> // IWYU pragma: export
#include <cstdint> // IWYU pragma: keep: backward compatibility, to be removed.
#include <utility>
#include <bsoncxx/stdx/optional.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/model/delete_many.hpp>
#include <mongocxx/model/delete_one.hpp>
#include <mongocxx/model/insert_one.hpp>
#include <mongocxx/model/replace_one.hpp>
#include <mongocxx/model/update_many.hpp>
#include <mongocxx/model/update_one.hpp>
#include <mongocxx/write_type.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
namespace model {
class write {
public:
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() write(v1::bulk_write::single op);
explicit MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() operator v1::bulk_write::single() &&;
explicit MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() operator v1::bulk_write::single() const&;
write(insert_one value) : _type{v_noabi::write_type::k_insert_one}, _insert_one{std::move(value)} {}
write(update_one value) : _type{v_noabi::write_type::k_update_one}, _update_one{std::move(value)} {}
write(update_many value) : _type{v_noabi::write_type::k_update_many}, _update_many{std::move(value)} {}
write(delete_one value) : _type{v_noabi::write_type::k_delete_one}, _delete_one{std::move(value)} {}
write(delete_many value) : _type{v_noabi::write_type::k_delete_many}, _delete_many{std::move(value)} {}
write(replace_one value) : _type{v_noabi::write_type::k_replace_one}, _replace_one{std::move(value)} {}
write(write&& rhs) noexcept : _type{rhs._type} {
switch (rhs._type) {
case write_type::k_insert_one:
new (&_insert_one) insert_one(std::move(rhs._insert_one));
break;
case write_type::k_update_one:
new (&_update_one) update_one(std::move(rhs._update_one));
break;
case write_type::k_update_many:
new (&_update_many) update_many(std::move(rhs._update_many));
break;
case write_type::k_delete_one:
new (&_delete_one) delete_one(std::move(rhs._delete_one));
break;
case write_type::k_delete_many:
new (&_delete_many) delete_many(std::move(rhs._delete_many));
break;
case write_type::k_replace_one:
new (&_replace_one) replace_one(std::move(rhs._replace_one));
break;
}
}
write& operator=(write&& rhs) noexcept {
if (this != &rhs) {
this->destroy_member();
switch (rhs._type) {
case write_type::k_insert_one:
new (&_insert_one) insert_one(std::move(rhs._insert_one));
break;
case write_type::k_update_one:
new (&_update_one) update_one(std::move(rhs._update_one));
break;
case write_type::k_update_many:
new (&_update_many) update_many(std::move(rhs._update_many));
break;
case write_type::k_delete_one:
new (&_delete_one) delete_one(std::move(rhs._delete_one));
break;
case write_type::k_delete_many:
new (&_delete_many) delete_many(std::move(rhs._delete_many));
break;
case write_type::k_replace_one:
new (&_replace_one) replace_one(std::move(rhs._replace_one));
break;
}
_type = rhs._type;
}
return *this;
}
write(write const& rhs) = delete;
write& operator=(write const& rhs) = delete;
~write() {
this->destroy_member();
}
write_type type() const {
return _type;
}
insert_one const& get_insert_one() const {
return _insert_one;
}
update_one const& get_update_one() const {
return _update_one;
}
update_many const& get_update_many() const {
return _update_many;
}
delete_one const& get_delete_one() const {
return _delete_one;
}
delete_many const& get_delete_many() const {
return _delete_many;
}
replace_one const& get_replace_one() const {
return _replace_one;
}
private:
void destroy_member() noexcept {
switch (_type) {
case write_type::k_insert_one:
_insert_one.~insert_one();
break;
case write_type::k_update_one:
_update_one.~update_one();
break;
case write_type::k_update_many:
_update_many.~update_many();
break;
case write_type::k_delete_one:
_delete_one.~delete_one();
break;
case write_type::k_delete_many:
_delete_many.~delete_many();
break;
case write_type::k_replace_one:
_replace_one.~replace_one();
break;
}
}
write_type _type;
union {
insert_one _insert_one;
update_one _update_one;
update_many _update_many;
delete_one _delete_one;
delete_many _delete_many;
replace_one _replace_one;
};
};
} // namespace model
} // namespace v_noabi
} // namespace mongocxx
namespace mongocxx {
namespace v_noabi {
inline v_noabi::model::write from_v1(v1::bulk_write::single v) {
return {std::move(v)};
}
inline v1::bulk_write::single to_v1(v_noabi::model::write const& v) {
return v1::bulk_write::single{v};
}
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
mongocxx::model::write::write
write(v1::bulk_write::single op)
Construct with the mongocxx::v1 equivalent.
mongocxx::v1::bulk_write::single
A single write operation.
Definition bulk_write.hpp:746
mongocxx::v_noabi::bulk_write
A batch of write operations that can be sent to the server as a group.
Definition bulk_write.hpp:54
mongocxx::v_noabi::model::delete_many
A MongoDB delete operation that removes multiple documents.
Definition delete_many.hpp:42
mongocxx::v_noabi::model::delete_one
A MongoDB delete operation that removes a single document.
Definition delete_one.hpp:42
mongocxx::v_noabi::model::insert_one
A MongoDB insert operation that creates a single document.
Definition insert_one.hpp:40
mongocxx::v_noabi::model::replace_one
A MongoDB update operation that replaces a single document.
Definition replace_one.hpp:42
mongocxx::v_noabi::model::update_many
A MongoDB update operation that modifies multiple documents.
Definition update_many.hpp:47
mongocxx::v_noabi::model::update_one
A MongoDB update operation that modifies a single document.
Definition update_one.hpp:47
mongocxx::v_noabi::model::write
A single write operation for use with mongocxx::v_noabi::bulk_write.
Definition write.hpp:45
mongocxx::v_noabi::model::write::write
write(write &&rhs) noexcept
Move constructs a write.
Definition write.hpp:100
mongocxx::v_noabi::model::write::~write
~write()
Destroys a write.
Definition write.hpp:163
mongocxx::v_noabi::model::write::write
write(replace_one value)
Constructs a write from a model::replace_one.
Definition write.hpp:95
mongocxx::v_noabi::model::write::write
write(update_many value)
Constructs a write from a model::update_many.
Definition write.hpp:80
mongocxx::v_noabi::model::write::get_update_one
update_one const & get_update_one() const
Accesses the write as an model::update_one. It is illegal to call this method if the return of type()...
Definition write.hpp:188
mongocxx::v_noabi::model::write::get_delete_one
delete_one const & get_delete_one() const
Accesses the write as a model::delete_one. It is illegal to call this method if the return of type() ...
Definition write.hpp:206
mongocxx::v_noabi::model::write::get_replace_one
replace_one const & get_replace_one() const
Accesses the write as a model::replace_one. It is illegal to call this method if the return of type()...
Definition write.hpp:224
mongocxx::v_noabi::model::write::write
write(delete_many value)
Constructs a write from a model::delete_many.
Definition write.hpp:90
mongocxx::v_noabi::model::write::get_delete_many
delete_many const & get_delete_many() const
Accesses the write as a model::delete_many. It is illegal to call this method if the return of type()...
Definition write.hpp:215
mongocxx::v_noabi::model::write::write
write(delete_one value)
Constructs a write from a model::delete_one.
Definition write.hpp:85
mongocxx::v_noabi::model::write::single
operator v1::bulk_write::single() &&
Convert to the mongocxx::v1 equivalent.
mongocxx::v_noabi::model::write::write
write(v1::bulk_write::single op)
Construct with the mongocxx::v1 equivalent.
mongocxx::v_noabi::model::write::operator=
write & operator=(write &&rhs) noexcept
Move assigns a write.
Definition write.hpp:126
mongocxx::v_noabi::model::write::get_update_many
update_many const & get_update_many() const
Accesses the write as an model::update_many. It is illegal to call this method if the return of type(...
Definition write.hpp:197
mongocxx::v_noabi::model::write::type
write_type type() const
Returns the current type of this write.
Definition write.hpp:170
mongocxx::v_noabi::model::write::get_insert_one
insert_one const & get_insert_one() const
Accesses the write as a model::insert_one. It is illegal to call this method if the return of type() ...
Definition write.hpp:179
mongocxx::v_noabi::model::write::write
write(update_one value)
Constructs a write from a model::update_one.
Definition write.hpp:75
delete_many.hpp
Provides mongocxx::v_noabi::model::delete_many.
delete_one.hpp
Provides mongocxx::v_noabi::model::delete_one.
insert_one.hpp
Provides mongocxx::v_noabi::model::insert_one.
replace_one.hpp
Provides mongocxx::v_noabi::model::replace_one.
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
mongocxx::v_noabi::model
Declares entities representing bulk write operations.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx::v_noabi::write_type
write_type
Used by mongocxx::v_noabi::model::write.
Definition write_type.hpp:31
mongocxx::v_noabi::write_type::k_delete_one
@ k_delete_one
Deleting a single document from a collection.
Definition write_type.hpp:36
mongocxx::v_noabi::write_type::k_insert_one
@ k_insert_one
Inserting a single document into a collection.
Definition write_type.hpp:33
mongocxx::v_noabi::write_type::k_update_many
@ k_update_many
Update one or more documents in a collection.
Definition write_type.hpp:45
mongocxx::v_noabi::write_type::k_update_one
@ k_update_one
Update a single document in a collection.
Definition write_type.hpp:42
mongocxx::v_noabi::write_type::k_delete_many
@ k_delete_many
Delete one or more documents from a collection.
Definition write_type.hpp:39
mongocxx::v_noabi::write_type::k_replace_one
@ k_replace_one
Replace a single document in a collection with a new one.
Definition write_type.hpp:48
mongocxx::v_noabi::to_v1
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
mongocxx::v_noabi::from_v1
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
update_many.hpp
Provides mongocxx::v_noabi::model::update_many.
update_one.hpp
Provides mongocxx::v_noabi::model::update_one.
bulk_write.hpp
Provides entities related to write operations.
optional.hpp
Provides std::optional-related polyfills for library API usage.
write-fwd.hpp
Declares mongocxx::v_noabi::model::write.
write_type.hpp
Provides mongocxx::v_noabi::write_type.